I am kind of a noob in assembler. I am trying to initialise variables from the stack (ie. in a practical case their values are pushed to the stack by a third party). The code is similar to this:
.data
b:
.long 0
a:
.long 0
.global main
.text
main:
push $2
pop b
push $1
pop a
Anyway, what I would expect would be to have 1 in a and 2 in b. Instead, I have 1 in a and cruft in b (though it is static between executions). What am I doing wrong?
Thank you very much in advance.
You are doing wrong 2 things:
The code is working as-is:
(gdb) p a
$1 = 1
(gdb) p b
$2 = 2