OSDev.org

The Place to Start for Operating System Developers
It is currently Mon May 06, 2024 10:57 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: mov command with GAS?
PostPosted: Tue Mar 25, 2008 2:52 am 
Offline
Member
Member

Joined: Wed Jan 23, 2008 8:55 pm
Posts: 63
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 2:58 am 
Offline
Member
Member
User avatar

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

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 1:29 am 
Offline
Member
Member

Joined: Wed Jan 23, 2008 8:55 pm
Posts: 63
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 2:46 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
Ah yes, quite.

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

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group