'{$STAMP BS2pe} '{$PBASIC 2.5} ' (c) 2003 Tracy Allen, http://www.emesystems.com ' explores the PBASIC 2.5 commands ' ON x GOTO label ' and ' ON x GOSUB label ' ' to use this program as a study guide, ' Enter alternative program cases after #DEFINE below ' then look at tokens using CTRL-M memory map window ' Scroll to the bottom of the window to the red area. #DEFINE example=10 ' 10 ON x GOTO ' 11 same tokens as 10, but using BRANCH in old PBASIC ' 20 ON x GOSUB ' 21 same numberof tokens as 20 using GOSUB/BRANCH in old PBASIC ' 22 a particulary inefficient way to accomplish the same thing as 20 #SELECT example ' --- ON X GOTO --- ' under the hood this is exactly the same as BRANCH, see #CASE 11 ' but note that the ON x GOTO does not require [] brackets #CASE 10 x VAR Byte ON x GOTO lab0,lab1,lab2 lab0: ' statements A lab1: ' statements B lab2: ' statements C END #CASE 11 x VAR Byte BRANCH x,[lab0,lab1,lab2] lab0: ' statements A lab1: ' statements B lab2: ' statements C END ' --- ON X GOSUB --- ' This is apparently the only PBASIC 2.5 control structure that ' can NOT have an exact match in PBASIC 2.0 ' Token coding for ON X GOSUB puts ' the RETURN target for the GOSUB after the ' BRANCH command, ' whereas in old PBASIC the return target is always ' the instruction right after the GOSUB. ' This difference is very minor and both old and new ' PBASIC can produce exactly the same length program. ' ' The ON x GOSUB instruction is very code-efficient ' It only uses one return target. #CASE 20 x VAR Byte ON x GOSUB lab0,lab1,lab2 END lab0: ' statements A RETURN lab1: ' statements B RETURN lab2: ' statements C RETURN END #CASE 21 ' like case 20, same program length tokenized ' minor microcoding differences x VAR Byte GOSUB lab END lab: BRANCH x,[lab0,lab1,lab2] RETURN lab0: ' statements A RETURN lab1: ' statements B RETURN lab2: ' statements C RETURN END #CASE 22 ' this is a very *inefficient* implementation ' note that BRANCH comes first with separate GOSUB ' then each GOSUB requires a RETURN target ' and also a GOTO in order to exit the structure x VAR Byte BRANCH x,[lab0p,lab1p,lab2p] GOTO lab9 lab0p: GOSUB lab0 GOTO lab9 lab1p: GOSUB lab1 GOTO lab9 lab2p: GOSUB lab2 lab9: END lab0: RETURN lab1: RETURN lab2: RETURN #ENDSELECT