Mail Archives: djgpp/1996/08/13/21:45:30
Kevin Baca wrote:
>
> > Ok, I'm starting to get the hang of inline ASM, but I just can't
> > find a good reference on how to access variables via inline ASM.
> > I've heard that you must declare everything globally, but this can't
> > be the best solution. Does anyone know a better way, or a place
> > where I could read up on the subject? If I declare a variable
> > within a function, how can I use that variable in my inline ASM
> > routine? If the function is recursive, how will that affect things?
> > Thanks!
> >
> > -David :)
>
> The following function adds 3 ints and returns the result. You can
> see how it accesses local variables. The "rm" means the variable
> could either be in a register or in memory. Check out the info
> section of gcc on inline assembly for more of this kind of stuff.
>
> int add3(int i, int j, int k)
> {
> int ret;
>
> __asm__("
> movl %1,%%eax
> addl %2,%%eax
> addl %3,%%eax"
> : "=a" ret
> : "rm" (i),"rm" (j),"rm" (k)
> : "eax");
>
> return ret;
> }
>
> -Kevin
Go to http://remus.rutgers.edu/~avly/djasm.html
It has the official tutorial to inline assembler, it gives alot of
information about how to deal with inputs, outputs, and handling
modified registers.
- Raw text -