| Thread overview | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 16, 2005 Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
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
| ||||
March 16, 2005 Re: Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trevor | 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
| |||
March 16, 2005 Re: Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | 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 | |||
March 16, 2005 Re: Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trevor | 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/ | |||
March 17, 2005 Re: Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trevor | "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. | |||
March 17, 2005 Re: Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trevor | "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. | |||
March 17, 2005 Re: Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trevor | 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 | |||
April 27, 2008 Re: Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter | 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
| |||
April 27, 2008 Re: Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sascha Katzner | 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. | |||
April 27, 2008 Re: Inline ASM in D | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Frits van Bommel | 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
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply