Skip to main content
Engineering LibreTexts

9.2: Stack Instructions

  • Page ID
    19912
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    A push operation puts things onto the stack, and a pop operation takes things off the stack. The format for these commands is:

        push     <operand64> 
        pop      <operand64>

    The operand can be a register or memory, but an immediate is not allowed. In general, push and pop operations will push the architecture size. Since the architecture is 64-bit, we will push and pop quadwords.

    The stack is implemented in reverse in memory. Refer to the following sections for a detailed explanation of why.

    Instruction

    Explanation

    push  <op64>

    Push the 64-bit operand on the stack.
    First, adjusts rsp accordingly (rsp-8) and then copy the operand to [rsp]. The operand may not be an immediate value. Operand is not changed.

    Examples:

    push rax
    push qword [qVal]
    ; value push qVal ; address

    pop  <op64>
    

    Pop the 64-bit operand from the stack. Adjusts rsp accordingly (rsp+8). The operand may not be an immediate value. Operand is overwritten.

    Examples:

    pop  rax
    pop  qword [qVal]
    pop  rsi
    

    If more than 64-bits must be pushed, multiple push operations would be required. While it is possible to push and pop operands less than 64-bits, it is not recommended.

    A more complete list of the instructions is located in Appendix B.


    This page titled 9.2: Stack Instructions is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Ed Jorgensen.

    • Was this article helpful?