Jump to content
  • 0

POP from Applesoft BASIC


Posted (edited)

There is a flow control command in Applesoft BASIC that might be good to have in X16 BASIC:

Removes one address from the return stack, i.e. converts last GOSUB into a GOTO.

POP could be useful in more advanced BASIC programs. Maybe this could be solved using POKE, but it would be easier with a BASIC command, and then more old Applesoft BASIC programs could run on Commander X16. I did find two programs that uses POP:


Edited by mobluse

Share this post

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I just looked at the code for pacman you linked.  Frankly, it seems to me that POP wasn't really crucial and in fact was used in some convoluted branching choices that could have been avoided.  There's a half dozen other ways to do the same thing without converting a gosub to a goto.    

Glancing at "Mapping the C64" book from the 'golden days' I was able to confirm that  Basic 2.0 actually uses the 6510 HARDWARE STACK in the processor as the BASIC stack, and there are a ton of kernel and basic routines that are tinkering with the stack and moving the SP around to do housekeeping etc.    

Being practical, look at it this way:    In like 8 versions of Commodore BASIC, from the several variations in the 1970s CBM PET, to the VIC20, to the C64; then onto the PLUS4/C16, the C128 and even the unreleased C65, the Commodore folks never added anything resembling the Applesoft  POP to the Commodore BASIC.   

My guess is that to some significant extent, this would been because of both the risks inherent in messing with the Jenga Tower of stack management  and the perception that the command addresses a largely avoidable coding choice.     

Just my two cents.  

  • Like 1

Share this post

Link to post
Share on other sites
  • 0

While I am not suggesting any particular enhancement, I wrote a scripting language for PCBoard almost 30 years ago. It had a "compiler" that generated tokenized / crunched form of the source, then the run time executed the tokens, directly inspired by BASIC.

Anyway, it didn't have lots of fancy control structures, as I intended for it to be familiar to those who would have some background with BASIC and batch file programming, but I did include a "variable stack" that could be accessed with push and pop. The idea was to support the sort of "low level" mechanisms in a high level language so that later versions of the compiler could generate higher level constructs (such as while loops and user defined functions) using just the low level features already available, thus the compiler would be able to generate code that could run on older versions of the run time.

I never realized that Apple BASIC had a POP, even though it isn't directly comparable to what I did with my push and pop which worked on a software stack, not the processor stack. Still, I think something like that as an extension to BASIC could be useful to synthesize parameter passing that is currently missing from 8-bit forms of BASIC.

Of course, one could easily create their own stack via dim, then using an variable to index the top of stack...

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

Please review our Terms of Use