Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

any help would be appreciated, tia! Write a MIPS program to compute the product of two 1 6 - bit signed numbers using * recursive

any help would be appreciated, tia!
Write a MIPS program to compute the product of two 16-bit signed numbers using *recursive procedure calls. *Note:* You CANNOT use the mult or mul instructions.
Given the multiplicand (md) and multiplier (m) as inputs, write the main and recursion functions to compute the product (p) using the shift and add recursive algorithm for multiplication.
Write the following functions in MIPS.
main
task: initialize product, multiplicand and multiplier registers and call the recursion function with iteration number equal to the size of numbers (16-bit).
Note: If numbers are negative, convert to positive numbers and then multiply. Add sign separately at the end. Do not convert the original input registers, only convert the argument registers sent to the recursion function.
recursion
inputs: product (p), multiplicand (md) and multiplier (m) registers and the iteration number (n).
task: compute the nth iterative step of multiplication, call recursion function by decrementing n and return if n =0.
outputs: updated product (p).
Refer to the binary shift and add multiplication algorithm discussed in class. While writing the code,
Following is a sample C code segment. You may modify the code for the functions, but the task performed should not be changed, i.e., you should use recursive procedure calls.
// multiplier and multiplicand are inputs (For compilable C code, you should use argc and argv for command line inputs)
int main(int m, int md){
// Initialization of p, m, md registers
int p =0; // Product initialized to 0
int sign_p =0;
// negate the operands if negative
if (m <0 and md >0) or (m >0 and md <0)
sign_p =1;
if (m <0)
m =-m;
if (md <0)
md =-md;
p = recursion(p, md, m,16); //16-bit unsigned multiplication => recursion 16 times
if (sign_p ==1)
p =- p; // negate if one of the operands is negative
}
int recursion(int p, int md, int m, int n){
if (n ==0)
return(p);
else {
int m_0= m & 1; //0th or least significant bit of multiplier
if (m_0==1)
p = p + md;
m = m >>1;
md = md <<1;
p = recursion(p, md, m, n-1); // updated values of p, md and m - arguments
}
}
Registers Variables
$s0 product
$s1 multiplicand
$s2 multiplier
Example Test: If the values of $s1 and $s2 are initialized in the simulator as:
(Use the '+' button under the Registers display to initialize register values for $s1, $s2.)
Registers Data
$s00
$s18000
$s215000
The resultant registers are:
Registers Data
$s0120000000
$s18000
$s215000
This is what I have, but I get an error saying Line 12: Unrecognized syntax near: .data# Register Usage:
# $s0: Product (p)
# $s1: Multiplicand (md)
# $s2: Multiplier (m)
# $a0: Iteration Counter (n)
# $t0: Temporary register for intermediate values
.data
.align 2
negFlag: .word 0
.text
.globl main
main:
li $s0,0
li $s1,8000
li $s2,15000
li $t0,0
bltz $s2, negate_m
j continue
negate_m:
negu $s2, $s2
xor $t0, $t0,0x1
continue:
bltz $s1, negate_md
j multiplication
negate_md:
negu $s1, $s1
xor $t0, $t0,0x1
multiplication:
sw $t0, negFlag
li $a0,16
jal recursion
lw $t0, negFlag
bnez $t0, make_negative
j end
make_negative:
negu $s0, $s0
end:
# The final result is in $s0
recursion:
beqz $a0, exit_recursion
addi $a0, $a0,-1
andi $t0, $s2,0x1
beqz shift
add $s0, $s0, $s1
shift:
srl $s2, $s2,1
sll $s1, $s1,1
jal recursion
exit_recursion:
jr $ra

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

How do point estimators and interval estimators differ?

Answered: 1 week ago

Question

=+How does a software project manager select the set of soft-

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago