Reputation: 3
Can someone explain to me what this program does and how things change in it
.data
x: .long 15
.text
.global main
main:
movl $0, %eax
movl %eax, x
movl x, %ebx
mov $1, %eax
mov $0, %ebx
int $0x80
when I run it in the terminal it gives this
eax 0x5655618d 1448436109
ecx 0x33def597 870249879
edx 0xffffd100 -12032
ebx 0xf7fa4000 -134594560
esp 0xffffd0dc 0xffffd0dc
ebp 0xf7ffd020 0xf7ffd020 <_rtld_global>
esi 0xffffd194 -11884
edi 0xf7ffcb80 -134231168
eip 0x5655618d 0x5655618d <main>
eflags 0x246 [ PF ZF IF ]
cs 0x23 35
ss 0x2b 43
ds 0x2b 43
es 0x2b 43
fs 0x0 0
gs 0x63 99
I don't rly understand how values change when using the mov function.
Upvotes: -1
Views: 42
Reputation: 1688
mov
copies the value from the register or memory address on the left to the register or memory address on the right. For example:
movl $5,%eax
movl %eax,%ebx
After this sequence of instructions, both %eax
and %ebx
contain 5.
For a labeled address like x
in your example, since you have 15 at that address, that's the value that you'll load from there:
.data
x: .long 15
.text
.global main
main:
movl x,%eax // %eax now contains 15
addl $5,%eax // add 5 to the value of %eax, it now contains 20
movl %eax,x // store the value of %eax into the address pointed to by x.
// x now contains 20, the 15 that used to be there is now gone.
mov $1, %eax
mov $0, %ebx
int $0x80 // exit
Upvotes: 0