pushram, push - where does the stored data go, is anything else impacted?

matherp

Senior Member
I'm starting to get to grips with PE6 and key nice new features are the push and pushram, pop and popram commands.


However, from the online help it is unclear to me where the data goes and if it has any effect on any other user accessible memory (peek, poke etc.). Please could this be clarified?
Also, push states that there is a 32 byte stack, but pushram seems to indicate there are 4 * 16 bytes available - is this correct? Do they share the same stack? Can I pop data I have pushram'ed?
I assume that in nested subroutines I can push as I go down the hierarchy and pop as I come back up and as long as I stay within the 32 or 64 byte limit I will be OK - is my understanding correct?
Is the depth of subroutines (8 on X2 parts) influenced by the use of push etc.?

Thanks

Peter
 
Last edited:

Technical

Technical Support
Staff member
push, pop are for single bytes and and have a unique dedicated 32 byte stack.

pushram/popram are for b0-b15 and have a (completely separate) 4 deep stack. This is primarily designed to instantly free up 16 'local' byte variables to use within a procedure/macro.

Code:
sub:
pushram clear
...use b0-b15 as you wish during calculations...
popram
return
You can't mix and match between the two sets of commands as they are separate stacks e.g. pop from pushram.

Depth of subroutines is separate again, so not related to either of the above.
 

Technical

Technical Support
Staff member
These new commands are also fully simulated in PE6, so if in doubt try a simulation out!
 

Goeytex

Senior Member
Below is a program I did to test PE6 Pushram / Popram. It demos using all 4 levels of "Pushram".
Code:
[color=Navy]#terminal 9600 
#no_data[/color]
[color=Blue]pause [/color][color=Navy]4000      [/color][color=Green]'// Let terminal open [/color]

[color=Blue]Sertxd ([/color][color=Red]"Test Pushram / PopRam"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf) 

    for [/color][color=Purple]Bptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]15
        [/color][color=Purple]@bptr [/color][color=DarkCyan]= [/color][color=Purple]bptr [/color][color=Green]' 0 to 15
    [/color][color=Blue]next
    pushram [/color][color=DarkCyan]Clear [/color][color=Green]; Push to ram 
      

    [/color][color=Blue]for [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]15
        [/color][color=Purple]@bptr [/color][color=DarkCyan]= [/color][color=Purple]bptr [/color][color=DarkCyan]+ [/color][color=Navy]16
    [/color][color=Blue]next      
    Pushram [/color][color=DarkCyan]Clear [/color][color=Green]; Push to Ram  (Previous Data shifted 1 Level)        
    

    [/color][color=Blue]For [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]15
        [/color][color=Purple]@bptr [/color][color=DarkCyan]= [/color][color=Purple]bptr [/color][color=DarkCyan]+ [/color][color=Navy]32  [/color][color=Green]'( 32 to 47)
    [/color][color=Blue]next      
    Pushram [/color][color=DarkCyan]Clear [/color][color=Green]; Push to ram (Previous data shifted 1 Level) 

    [/color][color=Blue]For [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]15
        [/color][color=Purple]@bptr [/color][color=DarkCyan]= [/color][color=Purple]bptr [/color][color=DarkCyan]+ [/color][color=Navy]48  [/color][color=Green]'( 48 to 63)
    [/color][color=Blue]next      
    Pushram [/color][color=DarkCyan]Clear [/color][color=Green]; Push to Ram (Previous Data shifted  1 Level) 
    
    
    [/color][color=Blue]For [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]15
        [/color][color=Purple]@bptr [/color][color=DarkCyan]= [/color][color=Navy]255  [/color][color=Green]'fill B0 to b15 with '255"   
    [/color][color=Blue]next 
    
    sertxd ([/color][color=Red]"Current B0 - B15"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf) [/color][color=Green]'Verify 255 in all varibles
    [/color][color=Blue]for [/color][color=Purple]Bptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]15
      [/color][color=Blue]sertxd([/color][color=Black]#[/color][color=Purple]@bptr[/color][color=Black],[/color][color=Red]" "[/color][color=Blue])
    next
    sertxd (cr[/color][color=Black],[/color][color=Blue]lf[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)
    
    [/color][color=Green]'Now retreive stored data from RAM 
    [/color][color=Black]Retreive_data:
     [/color][color=Green]'Retreive from all 4 levels  (Last in first out)
    [/color][color=Blue]for [/color][color=Purple]b55 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]8   
        [/color][color=Blue]Popram    
        sertxd([/color][color=Red]"Loop "[/color][color=Black],#[/color][color=Purple]b55[/color][color=Black],[/color][color=Red]" (B0 - B15)"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)
        [/color][color=Purple]Bptr [/color][color=DarkCyan]= [/color][color=Navy]0
        [/color][color=Blue]do while [/color][color=Purple]bptr [/color][color=DarkCyan]< [/color][color=Navy]16 
            [/color][color=Blue]sertxd ([/color][color=Black]#[/color][color=Purple]@Bptrinc[/color][color=Black],[/color][color=Red]" "[/color][color=Blue])
        loop  
        sertxd (Cr[/color][color=Black],[/color][color=Blue]lf[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)
    next 
  stop[/color]
 

lbenson

Senior Member
I tried running the above program in the simulator, with at 28X2, and got "RAMstack overflow".

Would Popram work 8 times in the loop?
 

Goeytex

Senior Member
Would Popram work 8 times in the loop?
No, It does not, and that was a point in the demo and why I used 8 loops instead of 4. While the simulator gives a stack overflow, there is no problem on the silicon. It compiles and runs ok. The Picaxe does not reset or hang after loop 5. However after loop 5, B0 - B15 are all reset to zero. This means that extra care must be taken to keep track when using pushram and popram.

Here's the Terminal output when run on a real chip. (20X2)
=====================================
Test Pushram / PopRam

Current B0 - B15
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255

Loop 1 (B0 - B15)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

Loop 2 (B0 - B15)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

Loop 3 (B0 - B15)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Loop 4 (B0 - B15)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Loop 5 (B0 - B15)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Loop 6 (B0 - B15)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Loop 7 (B0 - B15)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Loop 8 (B0 - B15)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

DONE
=====================================
 
Top