Skip to main content
Engineering LibreTexts

18.3: Data Movement

  • Page ID
    19976
  • \( \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}}\)

    Typically, data must be moved into a CPU floating-point register in order to be operated upon. Once the calculations are completed, the result may be copied from the register and placed into a variable. There are a number of simple formulas in the example program that perform these steps. This basic data movement operations are performed with the move instruction.

    The general form of the move instruction is:

        movss     <dest>, <src> 
        movsd     <dest>, <src> 

    For the movss instruction, a single 32-bit source operand is copied into the destination operand. For the movsd instruction, a single 64-bit source operand is copied into the destination operand. The value of the source operand is unchanged. The destination and source operand must be of the correct size for the instruction (32 or 64-bits). Neither operand can be an immediate value. Both operands, cannot be memory, however one can be. If a memory to memory operation is required, two instructions must be used.

    The move instruction loads one value, using the lower 32 or 64-bits, into or out of the register. Other move instructions are required to load multiple values.

    The floating-point move instructions are summarized as follows:

    Instruction

    Explanation

    movss   <dest>, <src>
    

    Copy 32-bit source operand to the 32-bit destination operand.
    Note 1, both operands cannot be memory. Note 2, operands cannot be an immediate.

    Examples:

    movss    xmm0, dword [x]
    movss    dword [fltSVar], xmm1
    movss    xmm3, xmm2
    
    movsd   <dest>, <src>
    

    Copy 64-bit source operand to the 64-bit destination operand.
    Note 1, both operands cannot be memory. Note 2, operands cannot be an immediate.

    Examples:

    movsd    xmm0, qword [y]
    movsd    qword [fltDVar], xmm1
    movsd    xmm3, xmm2
    

    A more complete list of the instructions is located in Appendix B. For example, assuming the following data declarations:

        fSVar1    dd    3.14
        fSVar2    dd    0.0    
        fDVar1    dq    6.28
        fDVar2    dq    0.0
    

    To perform the basic operations of:

        fSVar2 = fSVar2        ; single precision variables
        fDVar2 = fDVar1        ; double precision variables
    

    The following instructions could be used:

        movss        xmm0, dword [fSVar1]
        movss        dword [fSVar2], xmm0    ; fSVar2 = fSVar1
    
        movsd        xmm1, qword [fDVar1]
        movsd        qword [fDVar2], xmm1    ; fDVar2 = fDVar1
    
        movss        xmm2, xmm0              ; xmm2 = xmm0 (32-bit)
        movsd        xmm3, xmm1              ; xmm3 = xmm1 (64-bit)
    

    For some instructions, including those above, the explicit type specification (e.g., byte, word, dword, qword) can be omitted as the other operand will clearly define the size. It is included for consistency and good programming practices.


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

    • Was this article helpful?