asar
asar copied to clipboard
SPC700 branch instructions don't support over-/underflowing PC
trafficstars
arch spc700
norom
org $0000
base $0000
foo: bra bar
base $FFF0
bar: bra foo
This prints two Erelative_branch_out_of_bounds errors, for values 65518 and -65522 respectively. The S-SMP, however, supports over- and underflowing of the PC, i.e. I expect an output of 2F EE 2F 0E. Note that this behaviour is also present for all conditional branches, including dbnz, cbne, bbc and bbs.
I have not tested Asar 2.0, but a quick look through the code suggests that the behaviour is the same there.
I've written a workaround macro in the meantime:
MACRO RelativeAddressOffsetByte(dst)
!__dst = ((<dst>)-(pc()+1))
!__x = (!__dst+(less(!__dst, -$80)*$10000)-(greaterequal(!__dst, $80)*$10000))
ASSERT !__x >= -$80 && !__x < $80, "Label out of range for branch."
DB !__x&$FF
UNDEF "__x"
UNDEF "__dst"
ENDMACRO
MACRO BRA(dst)
DB $2F
% RelativeAddressOffsetByte(<dst>)
ENDMACRO
MACRO CBNE(check, dst)
ASSERT <check>&~$FF == 0
DB $2E
DB <check>
% RelativeAddressOffsetByte(<dst>)
ENDMACRO
; etc...
(less and greaterequal instead of if because of non-static labels.)