Hello,
I am writing a simple ASM code with GNU GAS. I am having some problems with mov data. Please could anybody tell me why 2 lines (*) and (**) are not equivalent?? (currently my code works as expected with (**), but not with (*)
(program is in 16bit mode)
---
var:
.long 0xf1234
...
.code16gcc
movl var, %ecx // (*)
movl $0xf1234, %ecx // (**)
Many thanks,
J
mov command with GAS?
Hi,
Actually means "take the address of the label 'var', and move it into %ecx."
Actually means "take the constant 0xf1234, and move it into %ecx."
To make the first equivalent to the second, you really want a dereference, so
Hope this helps.
James
Code: Select all
movl var, %ecx
Code: Select all
movl $0xf1234, %ecx
To make the first equivalent to the second, you really want a dereference, so
Code: Select all
movl 0(var), %ecx
James
Hi james,
Unfortunately your code is incorrect here, because with GAS
"movl var, %ecx" and "movl (var), %ecx"
do absolutely the same thing, that is copy the value in var into %ecx.
I found the error in my code: that is "var" should be referred to using %cs, not %ds by default. So I fixed my code to smt like this:
movl %cs:var, %ecx
and it works.
Many thanks,
J
Unfortunately your code is incorrect here, because with GAS
"movl var, %ecx" and "movl (var), %ecx"
do absolutely the same thing, that is copy the value in var into %ecx.
I found the error in my code: that is "var" should be referred to using %cs, not %ds by default. So I fixed my code to smt like this:
movl %cs:var, %ecx
and it works.
Many thanks,
J