I've usually just ensured that branches don't cross a page with small pieces of aligned code, but I thought it might be useful to have an assert to verify it. Here's code that should do it:
This seems to work fine, but I'd appreciate a second set of eyes on it, just to be sure. Does this look correct to you? Is *+2 before a branch instruction the right value to test against the label?
Edit: Later on I decided to just put the assert immediately after the branch instruction rather than before, which eliminates the need for +2.
Code:
.macro assert_branch_page label_
.assert >(label_) = >(*+2), error, "Page crossing detected!"
.endmacro
test:
assert_branch_page :+
beq :+ ; .assert should happen if this would cross a page
nop
:
rts
.assert >(label_) = >(*+2), error, "Page crossing detected!"
.endmacro
test:
assert_branch_page :+
beq :+ ; .assert should happen if this would cross a page
nop
:
rts
This seems to work fine, but I'd appreciate a second set of eyes on it, just to be sure. Does this look correct to you? Is *+2 before a branch instruction the right value to test against the label?
Edit: Later on I decided to just put the assert immediately after the branch instruction rather than before, which eliminates the need for +2.