Name:
pop
Syntax:

POP variable { , variable, variable ... }

Variable - receives the data byte read from the stack.

Description:

Receives a byte variable value from the stack.

The last value on the byte stack is copied into the variable. The stack is 32 bytes deep and is separate to the stack used by pushram and popram commands.

Pushing and popping order

Note that variables need to be popped in the reverse order to which they are pushed on to the stack. If b1 is pushed before b2, then b2 needs to be popped before b1.

When b1 and b2 are pushed in a single command, the order of those variables need to be reversed in the corresponding pop command -

    push b1, b2
    gosub myroutine
    pop b2, b1

This is the same as -

    push b1
    push b2
    gosub myroutine
    pop b2
    pop b1

Word variables

Note the stack is byte sized so care must be taken when using word variables. When a word variable is pushed only its least significant byte will be pushed, and when a word variable is popped it will only receive a byte value result.

To push a word variable the two component byte parts of that variable must be pushed. For example, the component byte variable parts of 'w2' are 'b5' (MSB) and 'b4' (LSB). Popping a word variable must also be done using the component byte variable parts, and note that the order of those parts will be reversed in the pop than in the push. For example to push and then pop 'w2' the following should be used -

    push b4   ; push 'w2'
    push b5
 
    pop b5    ; pop 'w2'
    pop b4

Applies To:
20X2, 28X2, 40X2
See Also:
Related Create:
    Share:
    Print:

    Simple push and pop

    This example shows how a variable (b0 here) can be pushed to the stack, have its value changed, then have its original value restored after a pop.

    Code Example:
    main:	b0 = 0
    	sertxd( "Before push, b0=", #b0, cr, lf )
    	push b0
    	sertxd( "After push, b0=", #b0, cr, lf )
    	b0 = 99
    	sertxd( "After change, b0=", #b0, cr, lf )
    	pop b0
    	sertxd( "After pop, b0=", #b0, cr, lf )
    	end
    Copy Code Submit an Example

    Pushing and popping multiple variables

    Note that variables must be popped in the reverse order to which they are pushed on to the stack. Here b1 is pushed before b2, therefore b2 needs to be popped before b1.

    Code Example:
    main:	b1 = 11
    	b2 = 22
    	push b1
    	push b2
    	b1 = 99
    	b2 = 99
    	pop b2
    	pop b1
    	sertxd( "b1=", #b1, " b2=", #b2, cr, lf )
    	end
    Copy Code Submit an Example

    Pushing and popping multiple variables in same command

    Note that variables must be popped in the reverse order to which they are pushed on to the stack. Here b1 is pushed before b2, therefore b2 needs to be popped before b1. When b1 and b2 are pushed in a single command, the order of those variables need to be reversed in the corresponding pop command.

    Code Example:
    main:	b1 = 11
    	b2 = 22
    	push b1, b2
    	b1 = 99
    	b2 = 99
    	pop b2, b1
    	sertxd( "b1=", #b1, " b2=", #b2, cr, lf )
    	end
    Copy Code Submit an Example

    Submit Your Own Code!

    You must be logged in to submit code examples. Login now.

    Comments

    • Login to leave a comment.