# fpustacktest.s .section .data value1: .int 40 value2: .float 92.4405 value3: .double 221.440321 .section .bss .lcomm int1, 4 .lcomm control, 2 .lcomm status, 2 .lcomm result, 4 .section .text //.globl _start //_start: nop finit # instruction to initialize the FPU fstcw control # FPU control (word) is copied to memory locations fstsw status # status (word) registers is copied to memory locations filds value1 # loads a doubleword integer value into the FPU register stack # fists int1 #value is retrieved from the FPU register stack and placed in memory, #automatically converted back to a doubleword integer #because the S character is specified on the FIST mnemonic # rembering that previously the value was converted to the double-extended floating-point data type when it was stored in the FPU register. # flds value2 # instruction to load a SINGLE-precision floating-point value located in the value2 memory location # fldl value3 # instruction to load a DOUBLE-precision floating-point value located in the value3 memory location //Now there are three values loaded into the FPU register stack. //As each value is loaded, the preceding values shift down the stack, relative to the top of the stack ST0=R7 # fst %st(4) # instruction to move data from the ST0 register to another FPU register //format used to specify the fifth FPU register from the top of the stack //GAs uses the percent sign to indicate a register value, and the FPU register reference number must be enclosed in parentheses # fxch %st(1) # instruction used to exchange the value of the ST0 register with another FPU register, in this case, ST1 # //FST and FSTP instructions can also be used to move data from an FPU register to a memory location //The FST instruction copies data from the ST0 FTP register to a memory location (or another FPU register) //but keeping the original value in the ST0 register. //The FSTP instruction also copies the ST0 FPU register value, but then POPs it from the FPU register stack //This shifts all of the FPU stack values up one place in the stack. //we must add the data size character to the end of the FST and FSTP mnemonics to specify the proper size of the resulting data value fstps result # instruction used to create a singleprecision floating-point value stored in 4 bytes (32 bits) of memory #from the value in the ST0 FPU stack #after the FSTPS instruction, we retrieved the value from the stack (top = st00) , #and the other values were “shifted” up one position # movl $1, %eax movl $0, %ebx //int $0x80 int $0x21