lets say i have the following assembly lines
movl $-1, %edi
movl $1, %edx
What exactly am I storing into %edi/%edx registers.
B
There are four ways to load something into a register:
Immediate value - in AT&T assembler, that's using a $number
, and it loads that particular value (number) into the register. Note that number
doesn't have to be a numeric value, it could be, for example, movl $printf, %eax
- this would load the address of the function printf
into register eax
.
From another register, movl %eax, %edx
- we now have eax
value copied into edx
.
From a fixed memory location, movl myvar, %eax
- the contents of myvar
is in eax
.
From a memory location in another register, movl (%eax), %edx
- now, edx
has whatever 32-bit value is at the address in eax
. Of course, assuming it's actually a "good" memory location - if not, we have a segfault.
If this was C code, the code may loook a bit like this:
1)
int x = 42;
int (*printfunc)(const char *fmt, ...) = printf;
2)
int x = 1;
int y = 2;
...,
x = y; // movl %eax, %edx
3)
int x = myvar;
4)
int x = *myptr;
Edit:
Almost everything that is a "source" for a move instruction can also be a source for arithmetic operations, such as add $3, %eax
will be the equivalent in C of x += 3;
.