Skip to main content

PUSH

Push a value onto the top of the SP stack.

OpcodeBytesCyclesFormExample
$2922PUSH BYTE {BYTE}PUSH BYTE 123
$2A22PUSH PAIR {S_BYTE}PUSH PAIR 123
$6E32PUSH PAIR {PAIR}PUSH PAIR 12345
$2B22PUSH INT {S_BYTE}PUSH INT 123
$6F32PUSH INT {S_PAIR}PUSH INT 12345
$CD42PUSH INT {U_TRIO}PUSH INT $12_3ABC
$FC52PUSH INT {INT}PUSH INT $1234_ABCD
$2C23PUSH B:_PUSH B:1
$2D23PUSH P:_PUSH P:2
$2E23PUSH I:_PUSH I:4
$1612PUSH FPPUSH FP
$1712PUSH GPPUSH GP
$1812PUSH RETURN IPPUSH RETURN IP
$1912PUSH FLAGSPUSH 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 SP register), 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:6 is write three bytes to the memory address indicated by SP. P:6 is a PAIR register consuming two bytes. Afterwards, 2 is added to the SP register.

  • For example, PUSH PAIR 123 works similarly except that the value pushed is the number 123. We must include the PAIR type specifier (two bytes), because by itself 123 doesn't indicate how many bytes to write.

  • PUSH RETURN IP and POP IP are used to call subroutines such as Hybrix function calls. PUSH RETURN IP pushes the address of the instruction following the next instruction, which is presumed to be a JUMP instruction. Consider the example below: PUSH RETURN IP will push $00C0_0A16, because that is where control should return after the JUMP NEAR subroutine 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 FLAGS pushes the CPU flags as a single byte.

  • If IO::STACK_GUARD is 1, then PUSH will trigger a stack fault event if the SP register becomes larger than the GP register.

  • POP undoes the action of PUSH.

  • POP IP undoes the action of PUSH RETURN IP.

  • This instruction does not affect the CPU condition flags.