Inline assembler for Dummies

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Dec 2 11:44:14 PST 2007


"Mike" <vertex at gmx.at> wrote in message news:fiut5k$8c8$1 at digitalmars.com...
> From COM to assembler ... I've got a lot of questions today ... need 
> assembler but my knowledge is somehow limited. That means I've got a lot 
> of nice access violations :)
>
> Anyway: what's the difference between EAX and [EAX]? I suspect it's value 
> vs. pointer dereferencing, but I'm not sure.

Right.  EAX gets you the value in EAX, [EAX] gets you the value in memory at 
the address held in EAX.

>And: how do you get the address of a variable in assembler anyway? I tried 
>"&var", but that doesn't compile (obvisously), "[var]" crashes.

Use lea with just the name of the var:

int x = 5;

asm
{
    lea EAX, x;
    mov [EAX], 3; // save 3 to the memory location in EAX
}

writefln(x);

This prints 3. 




More information about the Digitalmars-d-learn mailing list