# An example of the FRNDINT instruction (舍入到最近的整数)
#
# FRNDINT 把ST0中的值舍入到最近的整数
#
.section .data
value1:
.float 3.65
rdown:
.byte 0x7f, 0x07
rup:
.byte 0x7f, 0x0b
### rdown and rup : 使用它们改变FPU控制寄存器中的舍入位。
### 因为其他值不需要改变,可以使用一个静态值完成这个工作。
### 为了把舍入方向设置向下,舍入位被设置为二进制01,这使控制寄存器的值为0x77F.
### 为了把舍入方向设置向上,舍入位被设置为二进制10,这使控制寄存器的值为0xB7F.
.section .bss
.lcomm result1, 4
.lcomm result2, 4
.lcomm result3, 4
.section .text
.globl main
main:
nop
finit
flds value1
frndint
fists result1
fldcw rdown
flds value1
frndint
fists result2
fldcw rup
flds value1
frndint
fists result3
movl $1, %eax
movl $0, %ebx
int $0x80
# gcc -g -o 06 06-frndint.s -m32
#
# st0 4 (raw 0x40018000000000000000)
# st1 3 (raw 0x4000c000000000000000)
# st2 4 (raw 0x40018000000000000000)
# st3 0 (raw 0x00000000000000000000)
# st4 0 (raw 0x00000000000000000000)
# st5 0 (raw 0x00000000000000000000)
# st6 0 (raw 0x00000000000000000000)
# st7 0 (raw 0x00000000000000000000)