OSDev.org
https://forum.osdev.org/

mov command with GAS?
https://forum.osdev.org/viewtopic.php?f=13&t=16605
Page 1 of 1

Author:  junkoi [ Tue Mar 25, 2008 2:52 am ]
Post subject:  mov command with GAS?

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

Author:  JamesM [ Tue Mar 25, 2008 2:58 am ]
Post subject: 

Hi,

Code:
movl var, %ecx


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

Code:
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:
movl 0(var), %ecx


Hope this helps.

James

Author:  junkoi [ Wed Mar 26, 2008 1:29 am ]
Post subject: 

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

Author:  JamesM [ Wed Mar 26, 2008 2:46 am ]
Post subject: 

Ah yes, quite.

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/