Behavior of rel. branch instructions with integer operands
Posted: Thu Jan 05, 2012 2:50 am
I'm developing a 65816 assembler, and I've noticed an oddity with at least some other assemblers. Suppose we have this code:
bra $12
...what does it mean? Is the $12 relative or absolute? To me it makes sense that $12 is taken as an absolute address and so, assuming a PC of 0 (for the sake of example), this will emit 80 10 (since the absolute address $12 gets converted to the relative address $10). That way labels can simply resolve to absolute addresses as they do in every other context and it should just work. But the assemblers xkas and WLA don't see it that way; they output the operand verbatim, producing 80 12. Thus they behave differently depending on whether the operand is an integer literal or a label. (bass, a later 65816 assembler by the same author as xkas -- rewritten from scratch I believe -- does emit 80 10.)
Is there any 'right' way for this to behave? Or is it just an implementation detail, since (as far as I know) proper assembly code should never need to pass an integer literal to a relative branch instruction anyway?
bra $12
...what does it mean? Is the $12 relative or absolute? To me it makes sense that $12 is taken as an absolute address and so, assuming a PC of 0 (for the sake of example), this will emit 80 10 (since the absolute address $12 gets converted to the relative address $10). That way labels can simply resolve to absolute addresses as they do in every other context and it should just work. But the assemblers xkas and WLA don't see it that way; they output the operand verbatim, producing 80 12. Thus they behave differently depending on whether the operand is an integer literal or a label. (bass, a later 65816 assembler by the same author as xkas -- rewritten from scratch I believe -- does emit 80 10.)
Is there any 'right' way for this to behave? Or is it just an implementation detail, since (as far as I know) proper assembly code should never need to pass an integer literal to a relative branch instruction anyway?