Inline assembler for Dummies
Mike
vertex at gmx.at
Sun Dec 2 12:34:57 PST 2007
Thanks to you both. I did that:
long var;
long *pvar = &var;
asm
{
mov EAX, pvar
push EAX
}
for now to find out if at least the concept works :)
So ... the code pushes the pointer to var on the stack and later calls a function which fills var with the (correct) value. Works. Interestingly "mov EAX, [pvar]" does the same thing, although it shouldn't ... it should - as I understand it - push the content of var (which is 0) to the stack, the function should then try to write to address 0 and fail with an access violation. Or shouldn't it? Does [] only dereference registers, not values?
Jarrett: go work on MiniD, you're just answering my questions all day long, you've got better things to do :)
-Mike
Jarrett Billingsley Wrote:
> "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