寄存器打印中的值为不同的数字



所以我今年春天在大学参加计算机课程,我们没有任何适当的帮助。

我有一个程序,该程序使用添加偏移方法乘以两个二进制值,该方法适用于任何符号的少量,但是我需要它与分配的B部分一起使用2个某些数字。

在调试时,我发现该代码在寄存器中存储了正确的产品,但是在打印后,显示的数字与寄存器中的数字不同。

对不起,如果我发布了太多代码或没有发布足够的信息,请告诉我是否应该更改有关帖子的任何内容。

该代码都是通过连接到Linux上运行的学校服务器的Putty完成的。

这是调试器显示寄存器x3(该寄存器格式的产品参数(在打印语句之前立即保持正确的数字

(gdb) i r x3
x3             0x1850505038     104426655800

这是在打印声明之后打印错误的数字

(gdb) next
50              bl      printf
(gdb) next
522133279 times 200 equals 1347440696

这是程序

        define(multiplicand, w19)
        define(multiplier, w20)
        define(product, w21)
        define(i, w22)
        define(temp3, w23)
        define(result, x24)
        define(temp1, x25)
        define(temp2, x26)
fmt:    .string "Multiplicand: %d nMultiplier: %dn"
msg:    .asciz "%d times %d equals %dn"
        .balign 4
        .global main
main:   stp     x29, x30, [sp, -16]!
        mov     x29, sp
        mov     multiplicand, 0b11111000111110001111100011111
        mov     multiplier, 0b11001000
        adrp    x0, fmt
        add     x0, x0, :lo12:fmt
        mov     w1, multiplicand
        mov     w2, multiplier
        bl      printf
        mov     i, 0
        mov     temp3, 1
loop:
        cmp     i, 32
        b.eq    print
        tst     multiplier, temp3
        b.eq    count
        uxtw    temp1, multiplicand
        uxtw    temp2, i
        lsl     temp1, temp1, temp2
        add     result, result, temp1
count:
        add     i, i, 1
        lsl     temp3, temp3, 1
        b       loop
print:
        ldr     x0, =msg
        mov     w1, multiplicand
        mov     w2, multiplier
        mov     x3, result
        bl      printf
        mov     w0, 0
        ldp     x29, x30, [sp], 16
        ret

没有错误消息

我要计算的表达是:

522133279 * 200 = 104 426 655 800

打印的值为1 347 440 696,但该值来自在打印语句之前立即存储正确值的寄存器

  1. 十六进制的1347440696是0x50505038
  2. 十六进制的104426655800是0x1850505038

您看到问题了吗?

确保格式字符串(请参阅注释(匹配您实际馈送到printf

的数据

最新更新