Answered step by step
Verified Expert Solution
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 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 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
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, ie 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 mainint m int md
Initialization of p m md registers
int p ; Product initialized to
int signp ;
negate the operands if negative
if m and md or m and md
signp ;
if m
m m;
if md
md md;
p recursionp md m; bit unsigned multiplication recursion times
if signp
p p; negate if one of the operands is negative
int recursionint p int md int m int n
if n
returnp;
else
int m m & ; th or least significant bit of multiplier
if m
p p md;
m m ;
md md ;
p recursionp md m n; updated values of p md and m arguments
Registers Variables
$s product
$s multiplicand
$s multiplier
Example Test: If the values of $s and $s are initialized in the simulator as:
Use the button under the Registers display to initialize register values for $s $s
Registers Data
$s
$s
$s
The resultant registers are:
Registers Data
$s
$s
$s
This is what I have, but I get an error saying Line : Unrecognized syntax near: data# Register Usage:
# $s: Product p
# $s: Multiplicand md
# $s: Multiplier m
# $a: Iteration Counter n
# $t: Temporary register for intermediate values
data
align
negFlag: word
text
globl main
main:
li $s
li $s
li $s
li $t
bltz $s negatem
j continue
negatem:
negu $s $s
xor $t $tx
continue:
bltz $s negatemd
j multiplication
negatemd:
negu $s $s
xor $t $tx
multiplication:
sw $t negFlag
li $a
jal recursion
lw $t negFlag
bnez $t makenegative
j end
makenegative:
negu $s $s
end:
# The final result is in $s
recursion:
beqz $a exitrecursion
addi $a $a
andi $t $sx
beqz shift
add $s $s $s
shift:
srl $s $s
sll $s $s
jal recursion
exitrecursion:
jr $ra
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started