Skip to main content
Engineering LibreTexts

18.4: Integer / Floating-Point Conversion Instructions

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

    If integer values are required during floating-point calculations, the integers must be converted into floating-point values. If single precision and double precision floating-point values are required for a series of calculations, they must be converted to single or double so that the operations are performed on a consistent size/type.

    Refer to Chapter 3 for a more detailed explanation of the representation details for floating-point values. It is assumed the reader understands the representation details and recognizes the requirement to ensure consistent formats before performing floating operations.

    This basic data conversion operations are performed with the convert instruction. The floating-point conversion instructions are summarized as follows:

    Instruction

    Explanation

    cvtss2sd   <RXdest>, <src>
    

    Convert 32-bit floating-point source operand to the 64-bit floating-point destination operand. Note 1, destination operand must be floating- point register.

    Note 2, source operand cannot be an immediate.

    Examples:

    cvtss2sd    xmm0, dword [fltSVar]
    cvtss2sd    xmm3, eax
    cvtss2sd    xmm3, xmm2
    
    cvtsd2ss   <RXdest>, <src>
    

    Convert 64-bit floating-point source operand to the 32-bit floating-point destination operand. Note 1, destination operand must be floating- point register.

    Note 2, source operand cannot be an immediate.

    Examples:

    cvtsd2ss    xmm0, qword [fltDVar]
    cvtsd2ss    xmm1, rax
    cvtsd2ss    xmm3, xmm2
    
    cvtss2si   <reg>, <src>
    

    Convert 32-bit floating-point source operand to the 32-bit integer destination operand.
    Note 1, destination operand must be register. Note 2, source operand cannot be an immediate.

    Examples:

    cvtss2si    xmm1, xmm0
    cvtss2si    eax, xmm0
    cvtss2si    eax, dword [fltSVar]
    
    cvtsd2si   <reg>, <src>
    

    Convert 64-bit floating-point source operand to the 32-bit integer destination operand.
    Note 1, destination operand must be register. Note 2, source operand cannot be an immediate.

    Examples:

    cvtsd2si    xmm1, xmm0
    cvtsd2si    eax, xmm0
    cvtsd2si    eax, qword [fltDVar]
    
    cvtsi2ss   <RXdest>, <src>
    

    Convert 32-bit integer source operand to the 32-bit floating-point destination operand. Note 1, destination operand must be floating- point register.

    Note 2, source operand cannot be an immediate.

    Examples:

    cvtsi2ss   xmm0, eax
    cvtsi2ss   xmm0, dword [fltDVar]
    
    cvtsi2sd   <RXdest>, <src>
    

    Convert 32-bit integer source operand to the 64-bit floating-point destination operand. Note 1, destination operand must be floating- point register.

    Note 2, source operand cannot be an immediate.

    Examples:

    cvtsi2sd   xmm0, eax
    cvtsi2sd   xmm0, dword [fltDVar]
    

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


    This page titled 18.4: Integer / Floating-Point Conversion Instructions is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Ed Jorgensen.

    • Was this article helpful?