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?
Behavior of rel. branch instructions with integer operands
Behavior of rel. branch instructions with integer operands
Last edited by furrykef on Thu Jan 05, 2012 2:58 pm, edited 1 time in total.
-
teamtempest
- Posts: 443
- Joined: 08 Nov 2009
- Location: Minnesota
- Contact:
- BitWise
- In Memoriam
- Posts: 996
- Joined: 02 Mar 2004
- Location: Berkshire, UK
- Contact:
My 6502/65816 assembler treats the operand to a relative branch as a absolute address and derives the relative offset from it.
I don't think I've ever come across an assembler for any processor with relative branches that works differently from this.
I don't think I've ever come across an assembler for any processor with relative branches that works differently from this.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact: