Jump to page: 1 2
Thread overview
Inline ASM in D
Mar 16, 2005
Trevor
Mar 16, 2005
Trevor
Mar 16, 2005
J C Calvarese
Mar 17, 2005
Walter
Mar 17, 2005
Walter
Apr 27, 2008
Sascha Katzner
Apr 27, 2008
Frits van Bommel
Apr 27, 2008
Sascha Katzner
Apr 27, 2008
BCS
Mar 17, 2005
Ilya Minkov
March 16, 2005
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
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
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
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
"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
"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
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
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
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
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
« First   ‹ Prev
1 2