So I am taking computing machinery course in university this spring and we don't get any kind of decent assistance with assignments.
I have a program that multiplies two binary values using add-shift method which works fine for small numbers of any sign, but I need it to work with 2 certain numbers for part B of the assignment.
While debugging I have discovered that the code has the right product stored in the register but after printing the number shown is not the same as the number in the register.
Sorry if I posted too much code or didn't post enough information, please let me know if I should change anything about the post.
The code is all done through putty connecting to the school's server which is run on linux.
This is where the debugger shows that register x3 (which stores the product argument for the printf formatting) holds the right number immediately before the print statement
(gdb) i r x3
x3 0x1850505038 104426655800
This is after the print statement where it prints the wrong number
(gdb) next
50 bl printf
(gdb) next
522133279 times 200 equals 1347440696
Here is the program
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
There were no error messages
The expression i'm trying to compute is:
522133279 * 200 = 104 426 655 800
The value that printed was 1 347 440 696, but this value came from the register that had the correct value stored immediately before the print statement