EmbeddedRelated.com
Forums

Help on alignment with GNU Assembler and H8S/2117 (2600 Family)

Started by Unknown February 5, 2009
Hello,

It's the first time that I use an H8 microprocessor.
I'm writing a program in H8 assembler (no C code at all) and I'm
using  GNU h8300-elf-as and h8300-elf-ld.

This processor needs alignment on even addresses for targets of jumps,
branches, and for moving words and dwords.

Aligning data seems to be very easy: I put a ".balign 2" directive
just before any word or dword data, to be sure they are aligned to an
even address.

For the assembler code, should I manually put ".balign 2" directives
just before every label definition?
It's a bit crasy, don't you think?
Is there a way to ask the assembler/linker to automatically align all
the branch targets to even addresses?

Thank you in advance

Panino
In article <1054d12b-0deb-460c-9852-
bd2862352457@l33g2000pri.googlegroups.com>, paninocolsalame@hotmail.com 
says...
> Hello, > > It's the first time that I use an H8 microprocessor. > I'm writing a program in H8 assembler (no C code at all) and I'm > using GNU h8300-elf-as and h8300-elf-ld. > > This processor needs alignment on even addresses for targets of jumps, > branches, and for moving words and dwords. > > Aligning data seems to be very easy: I put a ".balign 2" directive > just before any word or dword data, to be sure they are aligned to an > even address.
No define the data/bss sections on even boundarys, use definitions of types (.byte, .word, .long) to reserve the space as in any assembler.
> For the assembler code, should I manually put ".balign 2" directives > just before every label definition? > It's a bit crasy, don't you think?
Yes.
> Is there a way to ask the assembler/linker to automatically align all > the branch targets to even addresses?
Look at example code modules, you must have seen something. You might find my sig links helpful.
> Thank you in advance > > Panino >
-- Paul Carpenter | paul@pcserviceselectronics.co.uk <http://www.pcserviceselectronics.co.uk/> PC Services <http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font <http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny <http://www.badweb.org.uk/> For those web sites you hate
paninocolsalame@hotmail.com wrote:
> Hello, > > It's the first time that I use an H8 microprocessor. > I'm writing a program in H8 assembler (no C code at all) and I'm > using GNU h8300-elf-as and h8300-elf-ld. > > This processor needs alignment on even addresses for targets of jumps, > branches, and for moving words and dwords. > > Aligning data seems to be very easy: I put a ".balign 2" directive > just before any word or dword data, to be sure they are aligned to an > even address.
Sounds like the safe thing to do. Of course, if you have several words/dwords in sequence, there is no need to use .balign more than once, at the start.
> For the assembler code, should I manually put ".balign 2" directives > just before every label definition?
This is not necessary. Since all instructions are 16 or 32 bits, if your code (subroutine) starts on an even address, all following instructions and labels will have an even address.
> It's a bit crasy, don't you think?
And not needed, see above. Only if you use assembler directives to insert an odd number of (data) octets in between instructions could you get an odd code address. And I expect the assembler will report this error (haven't tried it, though). HTH, -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .
On 5 Feb, 21:54, Niklas Holsti <niklas.hol...@tidorum.invalid> wrote:
> This is not necessary. Since all instructions are 16 or 32 bits, if > your code (subroutine) starts on an even address, all following > instructions and labels will have an even address. >
Thank you Niklas. This is the information that I need! My main problem was how to have code alignment under control. I'm porting a big assembler file containing constant data between the code. So all constants require an .align after them, not only just before them. Thank you even to Paul: I'll take a look at the links you wrote. I'll take the liberty to disturb you again on this newsgroup, in case I have other questions. Thank you again Panino