I've been writing a lot of 68K assembly language, recently, and I've noticed a pattern, roughly the following:
do_something:
movem.l d2-d5/a2-a3,-(sp)
...
jsr xxx
tst.l d0
beq open_error
...
jsr yyy
tst.l d0
bmi read_error
...
move.l #ERR_OKAY,d0
bra exit
open_error:
move.l #ERR_OPEN,d0
bra exit
read_error:
move.l #ERR_READ,d0
exit:
movem.l (sp)+,d2-d5/a2-a3
rts
That is, I have a lot of branches to instructions that just set a return code then branch to some clean-up instructions.
Is there some clever way to do this more efficiently, or am I just doing what needs to be done?
The only optimization I've been able to come up with is to save a branch on the most-common (no error) path:
...
move.l #ERR_OKAY,d0
exit:
movem.l (sp)+,d2-d5/a2-a3
rts
open_error:
move.l #ERR_OPEN,d0
bra exit
read_error:
move.l #ERR_READ,d0
bra exit