This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

Re: Calculation of displacement of a variable.


C Jaiprakash, Noida wrote:
But the problem is h/w accesses memory as nth byte ot nth word so ( Base Reg
+ 1 ) if accessed in byte access mode will read 1st byte.
For ex byte at 0001h if BASE REG = 0000h
and it will access 1st word if memory is accessed in word mode. i.e a word
from memory location 0002h.

This is a common feature on targets that require strict alignment of memory accesses. If a word access must always be aligned, then there is no point in storing the low order bit of the offset in the instruction because it will always be zero.


The most common way to deal with this is in the assembler. You define the assembly language so that it uses byte-offsets for all instructions. This makes it easy to read and write assembly language. When the assembler encodes the byte-offsets into the object code, it does a shift right by 1 bit for an offset used in a word/long sized memory accesses. If you look at binutils, you can find many examples of this.

It would be confusing to have the assembly language use the actual size-dependent offset instead of a byte offset, but if your assembly language does this, then you can pretty easily handle it in your back end when you print out assembly instructions. Just divide the offsets by 2 before you print them. You can define a print operand code to make this easier.

In the RTL, offsets are always in units (bytes for most targets). It would be a serious mistake to try to change this.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



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