Posted: Sun Dec 21, 2014 6:04 pm Post subject: difference of gosub and call a function
Hi
what is difference of gosub and call a function or subrotine?
i think difference is between saved register in software stack and hardware stack but i dont know what happen to stack in 2 different way.
also i want to know about software stack.
a gosub is old style basic. i would recommend to use a SUB and the optional CALL.
Use config submode=new and write the implementation like :
Code:
sub Mylabel() print"mylabel" gosub abc
exitsub
abc: print"abc" return endsub
mylabel 'the same as line below call mylabel
without parameters, using a sub and gosub is exact the same. And, you can embed labels/gosub inside a SUB. My recommendation would be to forget about gosub. But like said, when not passing parameters, gosub and call are the same. the both generate the same binary code. _________________ Mark
when an interrupt occurs the processor saves the next address pointer on the HW stack, then it uses a CALL to jump to the interrupt address. The lower the address, the higher the priority.
This is a fixed memory location starting after the reset address 0. bascom inserts either a RETI (return from interrupt) or a JMP to an interrupt routine. When the interrupt routine ends, the RETURN/END SUB will create a RETI instead of a RET used for normal labels/subs. Since the processor saved the program counter on the stack, the RETI will pop the right address and the process continues.
Since the interrupt will interrupt any ongoing process and it is likely that the interrupt code will trash these registers, bascom saves and restores registers.
So executing an interrupt routine should only be done by the interrupt from the processor. _________________ Mark
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum