Writing my own assembler
Page 6 of 6

Author:  rainwarrior [ Wed Oct 31, 2018 1:38 am ]
Post subject:  Re: Writing my own assembler

tokumaru wrote:
rainwarrior wrote:
that's separately guaranteed for me with either .align directives or segment alignment (or both).

Doesn't that result in wasted ROM space?

Not really... at least I've never found it significant. However, your proposed alternative is just setting the address with .org, right? Doesn't this have the exact same padding problem?

.align will create padding, but only as much as needed. You can always rearrange stuff around the code to take up that padding. (In general I don't actually start worrying about the small amount of bytes lost to padding until I actually run out of space, though.)

If you have a short routine, you can use .align 32, or .align 16, etc. to get the guarantee you need with less potential padding.

You can also put all your alignment requiring routines in one segment (or after one .align). Like the real problem is just branch crossings, right? Guarantee those with an assert, and you can put as many pages worth of code as you want after a single guaranteed page alignment, and just manually stick a few bytes in between your routines whenever one of those asserts triggers.

Sort of an extension of that idea, you can use generally asserts instead of .align to guarantee it for compilation without any implicit padding, and just add it as needed.

Author:  pubby [ Wed Oct 31, 2018 1:54 am ]
Post subject:  Re: Writing my own assembler

Yeah I use asserts too a lot and never had an issue with alignment.

You can use this macro instead of .align to verify you're not wasting too much space:

.macro align size max_segmentation
  .local label
  .align size
  .if (* - label) > (max_segmentation)
    .error ".align creates excess segmentation."

Page 6 of 6 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group