Write an assembly program to multiply two 31 bit binary numb
Write an assembly program to multiply two 31 bit binary numbers (A & B), using the “shift and add” algorithm, which historically is used in computers. The numbers A and B are read through the keyboard and are saved into $t0 and $t1 registers. The MIPS processor will store these numbers in binary automatically. Then, you will then need to use AND, ADD, Shift logical instructions to implement the multiplication of these two numbers. The final result of the multiplication is saved into $t2 and $t3 registers representing (C and D). Your program will print out the values of $t2 and $t3 registers (in decimal - You do not need to convert the result to decimal since MIPS automatically does that for you).
Sample input A: 1143330295 (Decimal)
Sample input B: 999999223 (Decimal)
Do not use the mult or multU instruction.
Do not use any other multiplication algorithm.
Solution
main:
stwu 1,-48(1)
mflr 0
stw 0,52(1)
stw 31,44(1)
mr 31,1
lis 9,0x4425
ori 9,9,54775
stw 9,24(31)
lis 9,0x3b9a
ori 9,9,50935
stw 9,28(31)
lwz 10,24(31)
lwz 9,28(31)
mullw 9,10,9
lis 10,std::cout@ha
la 3,std::cout@l(10)
mr 4,9
bl std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
li 9,0
mr 3,9
addi 11,31,48
lwz 0,4(11)
mtlr 0
lwz 31,-4(11)
mr 1,11
blr
__static_initialization_and_destruction_0(int, int):
stwu 1,-32(1)
mflr 0
stw 0,36(1)
stw 31,28(1)
mr 31,1
stw 3,12(31)
stw 4,8(31)
lwz 9,12(31)
cmpwi 7,9,1
bne 7,.L3
lwz 10,8(31)
li 9,0
ori 9,9,65535
cmpw 7,10,9
bne 7,.L3
lis 9,std::__ioinit@ha
la 3,std::__ioinit@l(9)
bl std::ios_base::Init::Init()
lis 9,std::ios_base::Init::~Init()@ha
la 3,std::ios_base::Init::~Init()@l(9)
lis 9,std::__ioinit@ha
la 4,std::__ioinit@l(9)
lis 9,__dso_handle@ha
la 5,__dso_handle@l(9)
bl __cxa_atexit
.L3:
addi 11,31,32
lwz 0,4(11)
mtlr 0
lwz 31,-4(11)
mr 1,11
blr
stwu 1,-32(1)
mflr 0
stw 0,36(1)
stw 31,28(1)
mr 31,1
li 3,1
li 9,0
ori 4,9,65535
bl __static_initialization_and_destruction_0(int, int)
addi 11,31,32
lwz 0,4(11)
mtlr 0
lwz 31,-4(11)
mr 1,11
blr


