public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* short displacement in AT&T syntax
@ 2004-11-09  1:11 Thomas R. Dean
  2004-11-09  2:46 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas R. Dean @ 2004-11-09  1:11 UTC (permalink / raw)
  To: binutils

I'm not sure if this is the right place to ask. I've checked the docs,
been through the archives, searched the web  but have not able to find
any mention of this issue.  I've been working on this on and off for
several days now. If this is not the right place, please point me in
the right direction.

I teach an OS class and I use linux (x86) to teach it. For the next
lab, I want to use the gnu assembler, but I am running into a slight
problem.  I need to be able restrict the displacement to a single byte,
for example:

    movl %eax,0x23(%edi)

This works fine (generates 89 47 23). But if the displacement contains
any expression with a reference to a forward label, the assembler
generates a 2 byte displacement (89 87 23 00) even if the value will
fit into a single byte displacement:

   move %eax,(L2-L1)(%edi)
...
L1: .asci "......"
...
L2: .asci "....."

where edi happens to point to L1, and the distance between L1 and L2 is less
than 127 bytes.  In MASM, you can restrict the size of the displacement as
follows:

  mov [byte edi+L2-L1],eax

And you will get an error if the displacement does not fit.  The gnu
assembler seems to be able to optimize jumps automatically (you have
to use "jmp short label" manually to get the same optimization in MASM). Is
there an option or directive that will optimize the displacements as well?

I would prefer to use AT&T syntax, and the students have only seen 
accumulator assembly
languages until now (68HC11).  While test solving the assignment myself, 
I have done
a two pass approach where I assemble the code with a list file, look at 
the list for the
values of the offsets, and hand replace the expressions with the values 
to get the short
displacements. This would not be an acceptable approach to use in class. 
 I have to
finish writing up and the assignment to hand out next tuesday. If 
necessary, I will rework the
assignment to use Intel Syntax, but as I said I would prefer to use AT&T 
syntax.

Thanks in advance for any help the list can give me.

Tom.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: short displacement in AT&T syntax
  2004-11-09  1:11 short displacement in AT&T syntax Thomas R. Dean
@ 2004-11-09  2:46 ` Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2004-11-09  2:46 UTC (permalink / raw)
  To: Thomas R. Dean; +Cc: binutils

On Mon, Nov 08, 2004 at 08:17:01PM -0500, Thomas R. Dean wrote:
> And you will get an error if the displacement does not fit.  The gnu
> assembler seems to be able to optimize jumps automatically (you have
> to use "jmp short label" manually to get the same optimization in MASM). Is
> there an option or directive that will optimize the displacements as well?

No.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-11-09  2:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-09  1:11 short displacement in AT&T syntax Thomas R. Dean
2004-11-09  2:46 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).