For my assignment I have a MIPS program that does multiplication by addition, via checking the rightmost bit. If it’s a 1, I add. If it’s a 0, I simply do nothing. Afterward, I shift the multiplicand to the left, and the multiplier to the right, and restart the loop until the index is 0 (the index starts at N bits for display). I can get the initial line printed and set up, however afterwards I simply get no output. As a side note, I do use macros established in another file for the sake of easy printing. I also have a separate file as a test method that loads the registers with values.
My main question is: why is it not properly printing the operation, and is my algorithm correct?
The output I was expecting was :
***********************************************************
A=50 B=10 N=6
************************************************************
Step Action Multiplier Multiplicand Product
0 Initial Vals 001010 000000110010 000000000000
1 lsb=0, no op 001010 000000110010 000000000000
1 Lshift Mcand 001010 000001100100 000000000000
1 Rshift Mplier 000101 000001100100 000000000000
2 Prod=Prod+Mcand 000101 000001100100 000001100100
2 Lshift Mcand 000101 000011001000 000001100100
2 Rshift Mplier 000010 000011001000 000001100100
3 lsb=0, no op 000010 000011001000 000001100100
3 Lshift Mcand 000010 000110010000 000001100100
3 Rshift Mplier 000001 000110010000 000001100100
4 Prod=Prod+Mcand 000001 000110010000 000111110100
4 Lshift Mcand 000001 001100100000 000111110100
4 Rshift Mplier 000000 001100100000 000111110100
5 lsb=0, no op 000000 001100100000 000111110100
5 Lshift Mcand 000000 011001000000 000111110100
5 Rshift Mplier 000000 011001000000 000111110100
6 lsb=0, no op 000000 011001000000 000111110100
6 Lshift Mcand 000000 110010000000 000111110100
6 Rshift Mplier 000000 110010000000 000111110100
Result of A*B by iterative addition --> 500
The output I received was:
************************************************************
A=50 B=10 N=6
************************************************************
STEP ACTION MULTIPLICAND PRODUCT/MULTIPLIER
0 Initial Vals 000000 001010
My source code in MIPS:
.include "./cs47.macro.asm"
.globl ex.3.12
.text
li $a0, 6
li $a1, 7
li $a2, 4
jal ex.3.12
print_reg ($s4)
exit
ex.3.12: #
addi $sp, $sp, -24
sw $ra, ($sp)
sw $s0, 4($sp)
sw $s1, 8($sp)
sw $s2, 12($sp)
sw $s3, 16($sp)
sw $s4, 20($sp)
jal display.title # xxx
print_str_literal ("Step Action Multiplier Mutiplicand Productn")
move $s0, $a0 # A = multiplicand
move $s1, $a1 # B = multiplier
move $s2, $a2 # N = # bits for display, assume N <= 16
li $s4, 0 # product
# xxx print out the initial vals
print_str_literal ("0 Inital Vals " )
print_triple ($s1, $s0, $s4) # xxx print multiplier multiplicand product
loop:
beq $s2, $0, done # if index $s2==0 quit loop
# xxx print out step numbers
sub $t0, $a2, $s2 # xxx t0 (step number) = N - s2 (index)
addi $t0, $t0, 1 # xxx t0 --
print_reg ($t0) # xxx t0 (step number) = N - 1 - s2 (index)
andi $s3, $s1, 1 # s3 = right most bit of multiplier s1.
beq $s3, 0, ZERO # if s3 == 0, then jump to ZERO
beq $s3 1, ONE
ONE: # addition happens
addu $s4, $s4, $s0 # if s3 == 1, s4 += s0 (multiplicand)
print_str_literal (" Prod=Prod+Mcand ")
j ABC
ZERO : # no addition
print_str_literal (" lsb=0, no op " )
print_triple($s1, $s0, $s4)
j ABC
ABC:
print_newline () # xxx
sll $s0, $s0, 1 # shift A (multiplicand) 1 bit to the left
print_reg ($t0)
print_str_literal(" Lshift Mcand ")
print_triple($s1, $s0, $s4)
srl $s1, $s1, 1 # shift B (multiplier) 1 bit to the right
print_reg ($t0)
print_str_literal(" Rshift Mplier ")
print_triple($s1, $s0, $s4)
addi $s2, $s2 -1
j loop
done:
lw $ra, ($sp)
lw $s0, 4($sp)
lw $s1, 8($sp)
lw $s2, 12($sp)
lw $s3, 16($sp)
lw $s4, 20($sp)
addi $sp, $sp, 24
jr $ra