ARM:浮点(VFP)指令在推入堆栈时不起作用

时间:2016-07-08 05:16:09

标签: assembly floating-point arm libc

我正在尝试在ARM Assembly中打印一些浮点值。只要我不将东西推入堆栈,就会正确打印值。如果我推送它只是打印0.

此代码有效,因为它不会将内容推送到堆栈中。

    .global main
    .func main

main:
  LDR R0, value_address @ Get address of value
  VLDR S14, [R0]        @ Move value into single precision S14 register
  VCVT.F64.F32 D0, S14  @ Convert single precision to double precision for printf

  LDR R0, =string       @ Give R0 the address of the string
  VMOV R2, R3, D0       @ Get the double precision value stored in registers
  BL printf             @ call printf

  MOV R7, #1            @ Exit syscall
  SWI 0

value_address:  .word value

.data
value:  .float 3.141592
string: .asciz "Floating point value is: %f\n"

我得到以下输出:

pi@raspberrypi:~/aal $ gcc -o printfp printfp.s
pi@raspberrypi:~/aal $ ./printfp
Floating point value is: 3.141592

然后我修改它以使用堆栈保存LR并且它无法正常工作。我之前没有使用VFP指令就完成了它并且它可以工作。

    .global main
    .func main

main:
    PUSH {LR}

    LDR R0, value_address   @ Get address of value
    VLDR S14, [R0]          @ Move value into single precision S14 register
    VCVT.F64.F32 D0, S14    @ Convert single precision to double precision for printf

    LDR R0, =string         @ Give R0 the address of the string
    VMOV R2, R3, D0         @ Get the double precision value stored in registers
    BL printf               @ call printf

    POP {PC}
    BX LR

value_address:  .word value

.data
value:  .float 3.141592
string: .asciz "Floating point value is: %f\n"

现在我得到了这个值:

pi@raspberrypi:~/aal $ gcc -o printfp printfp.s
pi@raspberrypi:~/aal $ ./printfp
Floating point value is: 0.000000

所以我不确定我做错了什么。有人可以帮我吗?

0 个答案:

没有答案
相关问题