Jump to LABEL command in propeller Spin
at_jay
Posts: 16
Hello,
My question is quite basic and is regarding the JUMP (JMP) command as we normally use to jump to some LABEL. Is there any similar command or routine exist for propeller spin? or some one have already had some implementation/object of similar kind?
Please also post if there any and its limitations e.g. we can use quit and next command only in repeat loop etc.
Thanks for your support
Cheers
Jay
My question is quite basic and is regarding the JUMP (JMP) command as we normally use to jump to some LABEL. Is there any similar command or routine exist for propeller spin? or some one have already had some implementation/object of similar kind?
Please also post if there any and its limitations e.g. we can use quit and next command only in repeat loop etc.
Thanks for your support
Cheers
Jay
Comments
You might have a look at the code for ABORT -- that may support what you're wanting to do.
Pub main
'Do something here
othermethod
Pub othermethod
'Do something different here
Once the othermethod has executed it's last instruction, program control will return to the method that called it and continue from there...C and other languages refer to this useage as "Functions". BASIC refers to it as a subroutine.
1. To skip some code: Use an if statement
2. To branch into some code maybe depending on a variable: Use the switch statement
3. To call a subroutine: Make it a function and call it
4. To create loops: use repeat
In the end no-jump code is easier to read and maintain (and believe me ... I have seen some goto driven code 20 years ago) because you are forced to structure your code. With Jump driven code you can create labels wherever you want and create wild pathes through your code, where only the programmer knows what happens exactly.
Spin is compiled to Spin bytecodes, which does contain a jump instruction. However, there's no direct way to generate this jump instruction. You could use the bytecode() primitive in BST to insert a jump instruction, but then you would need to determine the number of instruction bytes to jump over, which would be difficult.
So the only way to do the equivalent of a jump in Spin is to set a flag to avoid downstream processing or use the abort instruction.
Dave
Structured programming means pack each part of the code that belongs to a senseful unit into its own subroutine.
And equal important each subroutine should do only one thing.
extremly contrary examples: a subrotine for entering a number for rpm should not do the details of creating stepperpulses to drive the steppermotor. These are two complete different things which should be coded each in its own subroutine.
So the main thing that changes is
instead of writing label "MyName" and somewhere a "goto MyName"
you write
PUB MyName
and instead of "goto MyName" you write simply
"MyName"
Subroutines mean you have a basic set of commands and are able to expand the available commands through defining subroutines
keep the questions coming
best regards
Stefan