IEEE.754在手臂上,组装算法给出意外结果

问题描述 投票:0回答:0
。预期的结果是R0寄存器在击中

BX lr

时为

0x40000000,这是该程序的终结。我现在得到的结果是令人失望的0x40800000.

I编译:
-arm-non-eabi-as -g -o float.ofloat.s

Arm-None-EABI-LID -0 floatfloat.o

然后我和Qemu

一起跑步

Qemu -arm -G 30005./part5

与GDB
一起走

GDB-Multiarch文件./float Target遥控器:30005

与GDB
一样正常

.section .data @ Constants exponent_mask: .word 0x7F800000 @ The two numbers we want to add num1: .word 0x3f800000 num2: .word 0x3f800000 .section .text .global main main: @ Load numbers directly LDR r0, =num1 LDR r0, [r0] LDR r1, =num2 LDR r1, [r1] @ Load constant for exponent extraction just once LDR r12, =exponent_mask LDR r12, [r12] @ Extract exponents AND r2, r0, r12 AND r3, r1, r12 LSR r2, r2, #23 LSR r3, r3, #23 @ Clear the exponent parts BIC r4, r0, r12 BIC r5, r1, r12 @ Add the implicit 1 to the fractions ORR r4, r4, #0x00800000 ORR r5, r5, #0x00800000 @ Align exponents and adjust fractions CMP r2, r3 BGT largerExponent @ r3 has larger exponent SUB r6, r3, r2 LSR r4, r4, r6 MOV r2, r3 B fractionsAligned largerExponent: SUB r6, r2, r3 LSR r5, r5, r6 fractionsAligned: ADD r4, r4, r5 @ Add aligned fractions @ Normalize if needed TST r4, #0x01000000 BEQ doneNormalize LSR r4, r4, #1 ADD r2, r2, #1 doneNormalize: @ Construct the final number LSL r2, r2, #23 ORR r0, r4, r2 BX lr

在程序的末尾,寄存器值看起来像这样:

REG值

    

添加和归一化后,您的代码不会删除领先的1位。

assembly floating-point arm gdb
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.