www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Inline ASM in D

reply Trevor <Trevor_member pathlink.com> writes:
OK, I gave up on getting NASM to work with DMD for now. I think it's my own
fault, but I am trying something else now.

Inline assebler. I have the ASM code in a 

asm
{
.. asm code here ...
}

at the top of my kernel.d file. Is the what I should do to use the inline
assembler instead of compiling the ASM code and linking seperate.

will this work for a kernel?

Right now i get errors.

dmd -c Source\Kernel.d -odObjects\
Source\Core.d(6): Declaration expected, not 'asm'

It was giving me errors when i used ; comment lines too...

Any help as to how I can get this working, would be very much appriciated. This
forum has been helpful thus far.

Thanks again,
Trevor Parscal
www.trevorparscal.com
Mar 16 2005
next sibling parent reply "Carlos Santander B." <csantander619 gmail.com> writes:
Trevor wrote:
 OK, I gave up on getting NASM to work with DMD for now. I think it's my own
 fault, but I am trying something else now.
 
 Inline assebler. I have the ASM code in a 
 
 asm
 {
 ... asm code here ...
 }
 
 at the top of my kernel.d file. Is the what I should do to use the inline
 assembler instead of compiling the ASM code and linking seperate.
 
 will this work for a kernel?
 
 Right now i get errors.
 
 dmd -c Source\Kernel.d -odObjects\
 Source\Core.d(6): Declaration expected, not 'asm'
 
 It was giving me errors when i used ; comment lines too...
 
 Any help as to how I can get this working, would be very much appriciated. This
 forum has been helpful thus far.
 
 Thanks again,
 Trevor Parscal
 www.trevorparscal.com
Make sure your asm block is inside a function. _______________________ Carlos Santander Bernal
Mar 16 2005
parent reply Trevor <Trevor_member pathlink.com> writes:
In article <d1ad2r$2aer$1 digitaldaemon.com>, Carlos Santander B. says...
Trevor wrote:
 OK, I gave up on getting NASM to work with DMD for now. I think it's my own
 fault, but I am trying something else now.
 
 Inline assebler. I have the ASM code in a 
 
 asm
 {
 ... asm code here ...
 }
 
 at the top of my kernel.d file. Is the what I should do to use the inline
 assembler instead of compiling the ASM code and linking seperate.
 
 will this work for a kernel?
 
 Right now i get errors.
 
 dmd -c Source\Kernel.d -odObjects\
 Source\Core.d(6): Declaration expected, not 'asm'
 
 It was giving me errors when i used ; comment lines too...
 
 Any help as to how I can get this working, would be very much appriciated. This
 forum has been helpful thus far.
 
 Thanks again,
 Trevor Parscal
 www.trevorparscal.com
Make sure your asm block is inside a function. _______________________ Carlos Santander Bernal
What function do i put it in... I tride it in it's own, and also in the kernel_main() but dmd seems to complain allot about x86 asm. I am just using the standard multiboot header stuff for grub. Thanks Trevor Parscal
Mar 16 2005
next sibling parent J C Calvarese <jcc7 cox.net> writes:
Trevor wrote:
...
 What function do i put it in... I tride it in it's own, and also in the
 kernel_main() but dmd seems to complain allot about x86 asm. I am just using
the
 standard multiboot header stuff for grub.
 
 Thanks
 Trevor Parscal
If you haven't seen http://www.prowiki.org/wiki4d/wiki.cgi?KernelWithD yet, I'd recommend you check it out. Several people have looked into creating a kernel with D before. It might help you out. (As mentioned in http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/19480) -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Mar 16 2005
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"Trevor" <Trevor_member pathlink.com> wrote in message
news:d1aetn$2c7h$1 digitaldaemon.com...
Make sure your asm block is inside a function.
What function do i put it in... I tride it in it's own, and also in the kernel_main() but dmd seems to complain allot about x86 asm. I am just
using the
 standard multiboot header stuff for grub.
Look at the library functions in \dmd\src\phobos\std\math.d for some examples of inline assembler.
Mar 16 2005
prev sibling next sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Trevor" <Trevor_member pathlink.com> wrote in message
news:d1aaic$27sd$1 digitaldaemon.com...
 OK, I gave up on getting NASM to work with DMD for now. I think it's my
own
 fault, but I am trying something else now.

 Inline assebler. I have the ASM code in a

 asm
 {
 .. asm code here ...
 }

 at the top of my kernel.d file. Is the what I should do to use the inline
 assembler instead of compiling the ASM code and linking seperate.

 will this work for a kernel?

 Right now i get errors.

 dmd -c Source\Kernel.d -odObjects\
 Source\Core.d(6): Declaration expected, not 'asm'
Inline assembler can only appear within functions.
Mar 16 2005
parent reply Sascha Katzner <sorry.no spam.invalid> writes:
Walter wrote:
 Inline assembler can only appear within functions.
Is there any chance that you re-(think/work) this in the future? I've just written: uint reverseUint(void* source) { asm { naked; mov EAX, [EAX]; bswap EAX; ret; } } ...and it strike me, that it would be *really* nice if the compiler would inline functions like that, either manually or automatically. LLAP, Sascha
Apr 27 2008
parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Sascha Katzner wrote:
 Walter wrote:
 Inline assembler can only appear within functions.
Is there any chance that you re-(think/work) this in the future? I've just written: uint reverseUint(void* source) { asm { naked; mov EAX, [EAX]; bswap EAX; ret; } } ...and it strike me, that it would be *really* nice if the compiler would inline functions like that, either manually or automatically.
That would be why both Phobos and Tango have "uint bswap(uint)" (Phobos in std.intrinsic, Tango in tango.core.BitManip). It's a compiler intrinsic, meaning it should compile down to the 'bswap' asm instruction on x86. And it does, at least on DMD. Unfortunately GDC appears to only provide a portable implementation with bitwise operators, not using the raw instruction. Though on GDC it *should* be possible to get the same effect by using the "Extended Assembler" syntax, which according to the documentation[1] doesn't prevent inlining. [1]: See <http://dgcc.sourceforge.net/gdc/manual.html>, about halfway through.
Apr 27 2008
parent reply Sascha Katzner <sorry.no spam.invalid> writes:
Frits van Bommel wrote:
 That would be why both Phobos and Tango have "uint bswap(uint)" (Phobos 
 in std.intrinsic, Tango in tango.core.BitManip). It's a compiler 
 intrinsic, meaning it should compile down to the 'bswap' asm instruction 
 on x86.
Nice, I've completely overlooked this module until now, thanks! :-) ...but nevertheless I'm missing a way to build inline asm functions by myself. There are *A LOT* intrinsics that I'm missing. LLAP, Sascha
Apr 27 2008
parent BCS <ao pathlink.com> writes:
Reply to Sascha,

 Frits van Bommel wrote:
 
 That would be why both Phobos and Tango have "uint bswap(uint)"
 (Phobos in std.intrinsic, Tango in tango.core.BitManip). It's a
 compiler intrinsic, meaning it should compile down to the 'bswap' asm
 instruction on x86.
 
Nice, I've completely overlooked this module until now, thanks! :-) ...but nevertheless I'm missing a way to build inline asm functions by myself. There are *A LOT* intrinsics that I'm missing. LLAP, Sascha
one option would be to have a "mixin function" that would be used something like this: mixin(SomthingInASM!(op1.stringof,op2.stringof))); it would expand to a sting with some static type checking if's and a block of asm. not clean but it would work.
Apr 27 2008
prev sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
Trevor wrote:
 OK, I gave up on getting NASM to work with DMD for now. I think it's my own
 fault, but I am trying something else now.
No, it's probably not. Consult this here: http://www.digitalmars.com/drn-bin/wwwnews?D/13150 -eye
Mar 17 2005