This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

short displacement in AT&T syntax

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

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]