Writing my own assembler

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
rainwarrior
Posts: 7639
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Writing my own assembler

Post by rainwarrior » Wed Oct 31, 2018 1:38 am

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.

User avatar
pubby
Posts: 536
Joined: Thu Mar 31, 2016 11:15 am

Re: Writing my own assembler

Post by pubby » Wed Oct 31, 2018 1:54 am

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:

Code: Select all

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

Post Reply