PUSH
Push a value onto the top of the SP stack.
| Opcode | Bytes | Cycles | Form | Example |
|---|---|---|---|---|
| $29 | 2 | 2 | PUSH BYTE {BYTE} | PUSH BYTE 123 |
| $2A | 2 | 2 | PUSH PAIR {S_BYTE} | PUSH PAIR 123 |
| $6E | 3 | 2 | PUSH PAIR {PAIR} | PUSH PAIR 12345 |
| $2B | 2 | 2 | PUSH INT {S_BYTE} | PUSH INT 123 |
| $6F | 3 | 2 | PUSH INT {S_PAIR} | PUSH INT 12345 |
| $CD | 4 | 2 | PUSH INT {U_TRIO} | PUSH INT $12_3ABC |
| $FC | 5 | 2 | PUSH INT {INT} | PUSH INT $1234_ABCD |
| $2C | 2 | 3 | PUSH B:_ | PUSH B:1 |
| $2D | 2 | 3 | PUSH P:_ | PUSH P:2 |
| $2E | 2 | 3 | PUSH I:_ | PUSH I:4 |
| $16 | 1 | 2 | PUSH FP | PUSH FP |
| $17 | 1 | 2 | PUSH GP | PUSH GP |
| $18 | 1 | 2 | PUSH RETURN IP | PUSH RETURN IP |
| $19 | 1 | 2 | PUSH FLAGS | PUSH FLAGS |
Notes
-
The SP stack is commonly used to store local variables and return addresses for function calls.
-
The SP stack grows forwards (pushing increases the
SPregister), whereas the GP stack grows backwards. (The "top" of the GP stack is actually the lowest memory address.) -
For example, the effect of
PUSH P:6is write three bytes to the memory address indicated bySP.P:6is aPAIRregister consuming two bytes. Afterwards, 2 is added to theSPregister. -
For example,
PUSH PAIR 123works similarly except that the value pushed is the number 123. We must include thePAIRtype specifier (two bytes), because by itself 123 doesn't indicate how many bytes to write. -
PUSH RETURN IPandPOP IPare used to call subroutines such as Hybrix function calls.PUSH RETURN IPpushes the address of the instruction following the next instruction, which is presumed to be a JUMP instruction. Consider the example below:PUSH RETURN IPwill push$00C0_0A16, because that is where control should return after theJUMP NEARsubroutine has completed.C0_0A0F: 16 PUSH FP
C0_0A10: 14 MOVE FP, SP
C0_0A11: 2B 01 PUSH INT 1
C0_0A13: 29 02 PUSH BYTE 2
C0_0A15: 18 PUSH RETURN IP
C0_0A16: 3C 0A JUMP NEAR $C0_0A20
C0_0A18: 3B FB ADD SP, -5
C0_0A1A: 1A POP FP
C0_0A1B: 1C POP IP
C0_0A1C: 00 --- -
PUSH FLAGSpushes the CPU flags as a single byte. -
If
IO::STACK_GUARDis 1, thenPUSHwill trigger a stack fault event if theSPregister becomes larger than theGPregister. -
POP undoes the action of
PUSH. -
POP IPundoes the action ofPUSH RETURN IP. -
This instruction does not affect the CPU condition flags.