PUSH and POP

techElder

Well-known member
So, since PUSH and POP came up in a recent thread ...

Is this the beginning to creating easy-to-use library functions for PICAXE (along with #INCLUDE?)

I can see writing certain ubiquitous routines using variables without worrying about whether those variables have been used elsewhere.

Of course, I know there are limits, but 32 bytes might not be limiting in a lot of cases.

Where does the 32 bytes come from?
 

inglewoodpete

Senior Member
The 28X2 is based on the PIC18F25K22 which has 1536 bytes of static RAM.

The main PICAXE "RAM" area takes 256 bytes: this includes 56 bytes shared with b0 to b55 (w0 to w27). It also has a 1024-byte scratchpad. That totals 1280 bytes, leaving 256 more bytes which is hidden from the user but looks after the internal workings of the PICAXE's operating system. My guess is there are a few bytes spare in this area.

The first place that I'll be using PUSH and POP is in the interrupt routine. I use interrupts a lot....
 
Last edited:

hippy

Technical Support
Staff member
As new PICmicro devices come along they usually offer more RAM and firmware optimisations may free some up, so it really is a case of what there is, what the firmware requires, and what the left over can be used for.

PUSH and POP are mostly useful for preserving variables for re-use in routines, in macros, interrupts and elsewhere, and can avoid having to use PEEK and POKE, PUT and GET, stores and restores.

They certainly can be used for #INCLUDE library routines, even normal subroutines, which need to use local variables without stepping on variables used elsewhere in the program. I am sure we will see them being put to some clever uses as people become more used to using them.
 

Technical

Technical Support
Staff member
The first place that I'll be using PUSH and POP is in the interrupt routine. I use interrupts a lot....
popram and pushram are often better in #macro or in the interrupt, as they immediately free up 16 bytes instead of just 1. These 64 bytes (16 x 4 levels) are completely separate from the 32 byte push/pop stack.
 

Technical

Technical Support
Staff member
It simply means you can nest the pushram command up to 4 times, ie 4 pushrams inside each other.
 

techElder

Well-known member
Ok, so between #INCLUDE, #MACRO, PUSH, POP, PUSHRAM, POPRAM ... we have ... PICAXE functions and libraries! (I must have been asleep these last months ...)
 

inglewoodpete

Senior Member
Don't worry I'm still asleep. What I mean to say is I have a lot more reading to do.

Which reminds me: must get some sleep. It's midnight here.
 

lbenson

Senior Member
Not to resurrect the dead, but here we are nearly 15 months later, and push, pop, pushram, popram work with PE6, but are not in the manual. When might we hope to see an update?
 

eggdweather

Senior Member
Some might say a completely off the wall comment, but it's an interesting observation that HP calculators using reverse polish notion (RPN) have a stack that is 4-levels deep and with which one can work out the most complicated of equations without ever having to write down an intermediate result. That shows the power of push and pop but in another guise :)
 

eggdweather

Senior Member
Thank you for the link. The more I study these commands the more powerful I can see they will be when variable space becomes a premium. In-fact if programme space is not an issue, using these commands can make nearly all subroutines independent of the main programme from a variable viewpoint, I have just never spottted them in the manual and will now start to use them much more.
 

lbenson

Senior Member
The online manual points out that PUSH and POP take byte arguments. I often want to push and pop bptr and ptr, and to do so takes contortions--move it to a scratch word, then push the bytes, reverse to pop. Could the WORD argument be added so that the command would be more like put/get, write/read, poke/peek?
 

BESQUEUT

Senior Member
Thank you for the link. The more I study these commands the more powerful I can see they will be when variable space becomes a premium. In-fact if programme space is not an issue, using these commands can make nearly all subroutines independent of the main programme from a variable viewpoint, I have just never spottted them in the manual and will now start to use them much more.
With
#MACRO label(param1, param2...)
and
PUSH/POP
this will be very like a Visual Basic "Sub"

But, be aware :
1)stack depth is very limited,
2)code is in fact duplicated each time you use #MACRO...

So (if program space is limited), do not write all your code in the #MACRO
but use a GOSUB within the MACRO.
 
Last edited:

BESQUEUT

Senior Member
The online manual points out that PUSH and POP take byte arguments. I often want to push and pop bptr and ptr, and to do so takes contortions--move it to a scratch word, then push the bytes, reverse to pop. Could the WORD argument be added so that the command would be more like put/get, write/read, poke/peek?
+1 !
idem for math with word variables...
 

edmunds

Senior Member
I have now been programming PICAXE for three years and this thread is full of keywords I never heard before. I've just started reading up, but this already sounds very interesting and useful. Is there some sort of mailing list to join not to miss future updates? :)

Edmunds
 

edmunds

Senior Member
I'm looking at #macro command now here.

The example code does not compile for me and thus I was interested where the suggestion to seek for more information in the PICAXE MANUAL 2 would take me. I have a version 7.9.1 from 10/2013 of the manual and I cannot find anything about #macro command in it. Further, there is no information on any of the compiler commands (or how should I call the # commands). Is there any later version of the manual or some special appendix about these?


Thank you for your time,

Edmunds
 

edmunds

Senior Member
Thank you, this explains quite a lot.
It would be fair to note then also in the online reference what instructions are only available for windows and not for mac os users. The new set of instructions just does not work in MacAxepad. For understandable reasons. Is MacAxepad getting a facelift any time soon? Is it worth sending in a wish list for new features? ;)

Edmunds
 

techElder

Well-known member
edmunds, I gave up a couple of years ago and bought a new PC just for programming. I haven't heard or read anything encouraging from RevEd about software for Apple products; let alone anything "special."

However, I am not complaining, because PE6 is super! Also, it is nice to have a computer JUST for programming.
 

edmunds

Senior Member
edmunds, I gave up a couple of years ago and bought a new PC just for programming. I haven't heard or read anything encouraging from RevEd about software for Apple products; let alone anything "special."

However, I am not complaining, because PE6 is super! Also, it is nice to have a computer JUST for programming.
Risking starting an off-topic discussion here, I don't mind PE6 as much as I have looked at it, but I find it overwhelming. I like simple stuff and MacAxepad is basically good enough. My wishlist would be things like true mac os shortcuts (not F3 for Find Next, ok?! :)), possibility to select and search with a single keystroke without opening the Find window and similar. I love not having any buttons on top of my screen to be honest :).

Edmunds
 

lbenson

Senior Member
Risking starting an off-topic discussion here, I don't mind PE6 as much as I have looked at it, but I find it overwhelming. I like simple stuff and MacAxepad is basically good enough. My wishlist would be things like true mac os shortcuts (not F3 for Find Next, ok?! :)), possibility to select and search with a single keystroke without opening the Find window and similar. I love not having any buttons on top of my screen to be honest :).

Edmunds
Perhaps the place to post your wish list is in this forum: AXEpad and Compiler Support
 
Top