套准打印中的值使用其他数字

时间:2019-05-27 02:33:02

标签: assembly armv8

所以我今年春天正在上大学的计算机科学课程,我们在作业方面得不到任何体面的帮助。

我有一个程序,使用加法移位法将两个二进制值相乘,该方法对任何符号的小数都适用,但是我需要在赋值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 = 104426655800

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

1 个答案:

答案 0 :(得分:0)

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

您看到问题了吗?

确保格式字符串(请参阅注释)与您实际向printf馈送的数据相匹配

相关问题