所以今年春天我在大学学习计算机机械课程,我们在作业方面没有得到任何体面的帮助。
我有一个程序,它使用 add-shift 方法将两个二进制值相乘,该方法适用于任何符号的少量数字,但我需要它与分配的 B 部分的 2 个特定数字一起工作。
在调试时,我发现代码在寄存器中存储了正确的产品,但打印后显示的数字与寄存器中的数字不同。
抱歉,如果我发布了太多代码或没有发布足够的信息,请告诉我是否应该更改帖子的任何内容。
代码都是通过腻子连接到在Linux上运行的学校服务器完成的。
这是调试器显示寄存器 x3(存储 printf 格式的产品参数)在 print 语句之前立即保存正确数字的地方
(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: %d\n"
msg: .asciz "%d times %d equals %d\n"
.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,但该值来自在打印语句之前存储了正确值的寄存器