Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Problem with "mov" in GNU GAS
Hello everybody,

I am writing a simple ASM code with GNU GAS. I am having some problems
with mov command. Please could anybody tell me why 2 lines (*) and
(**) are not equivalent?? (currently my code works as expected with
(**), but not with (*)

(My program is in 16bit mode)

---
var:
.long 0xf1234

.code16gcc
movl var, %ecx                                // (*)
movl $0xf1234, %ecx                      // (**)


Many thanks,
J
Many thanks,


Report this thread to moderator Post Follow-up to this message
Old Post
junkoi
03-26-08 12:01 AM


Re: Problem with "mov" in GNU GAS
junkoi  <spamtrap@crayne.org> writes:
> Hello everybody,
>
> I am writing a simple ASM code with GNU GAS. I am having some problems
> with mov command. Please could anybody tell me why 2 lines (*) and
> (**) are not equivalent?? (currently my code works as expected with
> (**), but not with (*)
>
> (My program is in 16bit mode)
>
> ---
> var:
>        .long 0xf1234

So var is an address. At that address is reserved space for a
long, which is to be initialised to 0xf1234.

> .code16gcc
> movl var, %ecx                                // (*)

Here ecx now holds the address where the 0xf1234 above is stored.

> movl $0xf1234, %ecx                      // (**)

But here ecx is set to the constant value 0xf1234.

Phil
--
Dear aunt, let's set so double the killer delete select all.
-- Microsoft voice recognition live demonstration


Report this thread to moderator Post Follow-up to this message
Old Post
Phil Carmody
03-26-08 12:01 AM


Re: Problem with "mov" in GNU GAS
"junkoi" <spamtrap@crayne.org> wrote in message
news:94d18289-183c-4a52-9770-48fa230d2943@i12g2000prf.googlegroups.com...
> Hello everybody,
>
> I am writing a simple ASM code with GNU GAS. I am having some problems
> with mov command. Please could anybody tell me why 2 lines (*) and
> (**) are not equivalent?? (currently my code works as expected with
> (**), but not with (*)
>
> (My program is in 16bit mode)
>
> ---
> var:
>        .long 0xf1234
>
> .code16gcc
> movl var, %ecx                                // (*)
> movl $0xf1234, %ecx                      // (**)
>

I don't think it's critical, but I'm assuming the var is in a ".data"
section.

Yes, they are functionally equivalent.  "movl var,ecx" will mov the value at
var's address into ecx, i.e., 0xf1234.  If you wanted to mov the address of
var into ecx [like another responder claimed you were doing...], that'd be
"movl $var,ecx".

Are you linking the .o file?  If not, a zero (0) value placeholder for the
memory address will be in the .o code for "movl var, %ecx".  The placeholder
is not filled in with the address of var until linked using "ld".  Then, the
code should be functionally equivalent.  Is this the problem?  Typically, ld
is used like this, after assembled with AS or GCC:

ld --oformat binary --Ttext 0x7C00 -o mybootcode.bin mybootcode.o

Although very unlikely, you might need to adjust the address size or
segment:

addr32 movl var, %ecx
movl %es:var, %ecx

You can use these for mixed code:

.code16gcc
.code16
.code32
.code64
.data
.text
.att_syntax
.intel_syntax
data16  - operand size override
data32  - operand size override
addr16  - address size override
addr32  - address size override

Let us know...


Rod Pemberton


Report this thread to moderator Post Follow-up to this message
Old Post
Rod Pemberton
03-26-08 03:00 AM


Re: Problem with "mov" in GNU GAS
In message <87abkmra5y.fsf@nonospaz.fatphil.org>, Phil Carmody
<thefatphil_demunged@yahoo.co.uk> wrote:

> junkoi  <spamtrap@crayne.org> writes: 
>
> So var is an address. At that address is reserved space for a
> long, which is to be initialised to 0xf1234.
> 
>
> Here ecx now holds the address where the 0xf1234 above is stored.

No that loads 0xf1234 or whatever happens to be at var into %ecx. THe bug
must be elsewhere.



Report this thread to moderator Post Follow-up to this message
Old Post
Timothy Baldwin
03-26-08 03:00 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

A86 Assembler archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:32 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.