How to implement CALL in LMM ?
Bean
Posts: 8,129
I've just been playing around with LMM and was trying to figure out how to implement CALL #label.
Here is what I've come up with, but it seems like alot of instructions. And requires 2 temp variables.
Is there an easier way ?
I'm not concerned about handling a CALL in PASM. I'll just generate whatever code is needed to replace CALL.
Bean
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
Here is what I've come up with, but it seems like alot of instructions. And requires 2 temp variables.
Is there an easier way ?
CALL #label -> rdlong temp,pc ' temp = address of "LONG 0-0" LONG @label_RET mov temp2,pc ' pc=next instruction add temp2,#16 ' add 4 instructions wrlong pc,temp ' set return address rdlong pc,pc ' jump to label LONG @label ... label ... RET -> rdlong pc,pc ' jump back to caller label_RET LONG 0-0
I'm not concerned about handling a CALL in PASM. I'll just generate whatever code is needed to replace CALL.
Bean
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
I don't see how nested subroutines would be handled ? Is there something I'm missing ?
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.mikronauts.com E-mail: mikronauts _at_ gmail _dot_ com 5.0" VGA LCD in stock!
Morpheus dual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory/IO kit $89.95, both kits $189.95 SerPlug $9.95
Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
Las - Large model assembler Largos - upcoming nano operating system
As Bill mentioned, you need a call stack - here is how Catalina does it (the stack is in hub RAM and only requires one or two additonal instructions to manage):
Then a call and a return might look like:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina