I am trying to use Mips Mars to create assembly code that uses bit shifting and a loop to multiply any number up to 32 bits. But it is only iterating twice if that.
I have already gotten the multiplier and multiplicand earlier in the program.
$t0 = multiplicand
$t1 = Multiplier
#Multiply operation
li $t3 0 #Counter
li $t4 0 #result
li $t6 0x80000000
myLoop:
bgt $t3, 31, showMessage
addi $t3, $t3, 1 #Keep track of counter $t3
andi $t7, $t1, 1 #Find lsb of multiplier
andi $t8, $t6, 1 #Find LSB $t6
and $t5, $t8, $t7 #And LSB of multiplier and lsb $t6
sll $t6, $t6, 1 #shift $t6 right 1
srl $t1, $t1, 1 #Shift multiplier right 1
blez $t7, myLoop
add $t4, $t0,0 #Result
sll $t0, $t0, 1 #Shift multiplicand left one
j myLoop
I expect the output of 4*3 to be 12 but it is 8.
User contributions licensed under CC BY-SA 3.0