Clear also clears the stack [til/spectrum]

It should be obvious from the title, but I thought that the CLEAR routine cleared out memory – obviously not fully understanding it.
This seemingly benign routine kept complaining that there was NO DEFPROC – i.e. an ENDPROC was called but currently the state wasn’t in a routine.
Here’s a sample of the code:
10 PROC init()
20 REPEAT : PRINT AT 0,0;”o”: REPEAT UNTIL 0 :; never makes it here
30 DEFPROC init()
40 CLEAR %65267
50 %a=%65268
60 POKE %a,1,0,3,33,0,61,17,0,250,237,176,201
70 %a=% USR a
80 PRINT %a
90 ENDPROC :; but blows up here

It was because I had a CLEAR in my procedure. As well as setting the ramtop location, this clears all variables and the return stack (the return stack is what’s causing the ENDPROC to fail, because the record of where it came from has been erased).
Solution: put CLEAR at the start of the program instead.


This content originally appeared on remy sharp's b:log and was authored by remy sharp's b:log

It should be obvious from the title, but I thought that the CLEAR routine cleared out memory - obviously not fully understanding it.

This seemingly benign routine kept complaining that there was NO DEFPROC - i.e. an ENDPROC was called but currently the state wasn't in a routine.

Here's a sample of the code:

10 PROC init()
20 REPEAT : PRINT AT 0,0;"o": REPEAT UNTIL 0 :; never makes it here
30 DEFPROC init()
40   CLEAR %65267
50   %a=%65268
60   POKE %a,1,0,3,33,0,61,17,0,250,237,176,201
70   %a=% USR a
80   PRINT %a
90 ENDPROC :; but blows up here

It was because I had a CLEAR in my procedure. As well as setting the ramtop location, this clears all variables and the return stack (the return stack is what's causing the ENDPROC to fail, because the record of where it came from has been erased).

Solution: put CLEAR at the start of the program instead.

Originally published on Remy Sharp's b:log


This content originally appeared on remy sharp's b:log and was authored by remy sharp's b:log


Print Share Comment Cite Upload Translate Updates
APA

remy sharp's b:log | Sciencx (2020-08-31T19:33:06+00:00) Clear also clears the stack [til/spectrum]. Retrieved from https://www.scien.cx/2020/08/31/clear-also-clears-the-stack-til-spectrum/

MLA
" » Clear also clears the stack [til/spectrum]." remy sharp's b:log | Sciencx - Monday August 31, 2020, https://www.scien.cx/2020/08/31/clear-also-clears-the-stack-til-spectrum/
HARVARD
remy sharp's b:log | Sciencx Monday August 31, 2020 » Clear also clears the stack [til/spectrum]., viewed ,<https://www.scien.cx/2020/08/31/clear-also-clears-the-stack-til-spectrum/>
VANCOUVER
remy sharp's b:log | Sciencx - » Clear also clears the stack [til/spectrum]. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/08/31/clear-also-clears-the-stack-til-spectrum/
CHICAGO
" » Clear also clears the stack [til/spectrum]." remy sharp's b:log | Sciencx - Accessed . https://www.scien.cx/2020/08/31/clear-also-clears-the-stack-til-spectrum/
IEEE
" » Clear also clears the stack [til/spectrum]." remy sharp's b:log | Sciencx [Online]. Available: https://www.scien.cx/2020/08/31/clear-also-clears-the-stack-til-spectrum/. [Accessed: ]
rf:citation
» Clear also clears the stack [til/spectrum] | remy sharp's b:log | Sciencx | https://www.scien.cx/2020/08/31/clear-also-clears-the-stack-til-spectrum/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.