[Coco] lbsr and rts
Wayne Campbell
asa.rand at yahoo.com
Wed Sep 16 13:46:30 EDT 2009
I may be missing something, but I thought calls to subroutines required a rts instruction. In Basic09, there has to be a RETURN statement for any given GOSUB, but not necessarily one-for-one. I can, for example, have a series of subroutine calls, where there are multiple entry points for the subroutine, and one RETURN statement, like:
code
GOSUB 20
more code
GOSUB 30
more code
END
20 code
more code
30 even more code
still more code
RETURN
It will not generate any errors, and as long as the code is written correctly, it will work.
I have found, in the assembly code generated by disasm, that there are labels in the declarations (all those fcb's) that are being addressed in the code using lbsr op codes. Yet, there is no rts instruction anywhere in those fcb's. Can someone explain how this works? An example is:
* The L010A label is addressed twice in the program code.
L010A fcb $9D
fcb $1E
fcb $04
* The L010D label is addressed ten times in the program code.
L010D fcb $9D
fcb $1E
fcb $02
this series continues until:
L013A fcb $9D
fcb $2A *
fcb $00
fcb $00
fcb $72 r
fcb $02
In the code, the following statements address these labels:
Both occurrences of the L010A label, and one of the L010D labels, occur in this routine:
L08F8 ldx $02,s
lda #$80
lbsr L010A
bne L090F
lbsr L010D
beq L0915
leax $03,x
lda #$20
lbsr L010A
beq L0915
I just don't understand.
Wayne
More information about the Coco
mailing list