mov command with GAS?

Programming, for all ages and all languages.
Post Reply
junkoi
Member
Member
Posts: 63
Joined: Wed Jan 23, 2008 8:55 pm

mov command with GAS?

Post by junkoi »

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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Hi,

Code: Select all

movl var, %ecx


Actually means "take the address of the label 'var', and move it into %ecx."

Code: Select all

movl $0xf1234, %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

Code: Select all

movl 0(var), %ecx


Hope this helps.

James
junkoi
Member
Member
Posts: 63
Joined: Wed Jan 23, 2008 8:55 pm

Post by junkoi »

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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Ah yes, quite.

I suggest you put your 'var' variable in the .data section to avoid having to change segment selector.
Post Reply