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 thatnumber
doesn't have to be a numeric value, it could be, for example,movl $printf, %eax
- this would load the address of the functionprintf
into registereax
.From another register,
movl %eax, %edx
- we now haveeax
value copied intoedx
.From a fixed memory location,
movl myvar, %eax
- the contents ofmyvar
is ineax
.From a memory location in another register,
movl (%eax), %edx
- now,edx
has whatever 32-bit value is at the address ineax
. 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;
.