Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given below is a very simple C code and it s RISCV instruction sequence ( written manually ) . int x , y , m
Given below is a very simple C code and its RISCV instruction sequence written
manually
int xymc;
m ;
x ;
c ;
y mx c;
Assembly for rars
data
m:
word
x:
word
c:
word
y:
word # random initial value
text
# Initialize m x c and y
# m in t x in t c in t y in t
#addi t x
lui thim
addi t tlom
lw tt
#addi t x
lui thix
addi t tlox
lw tt
#addi t x
lui thic
addi t tloc
lw tt
add t x x
# Multiply without mul instruction
mulmx:
beq t x done
add t t t
addi t t
jal x mulmx
done :
add t t t
lui thiy
addi t tloy
sw tt
Question:
a
The code given for Q assumes t m is always
We do not handle the case when t m is less than
Please correct the given assembly code to handle positive and negative values for all m x and c
The test it with
m x c
m x c
m x c
m x c
m x c
For each case, please feel free to use registers as you need within the ABI rules but store the
final result in t
b
Please write the above code using a function. Pass m x and c to the function and the function
must calculate the results and return, then the main assembly code puts the result in tif not
already there and exits.
Please test it with
m x c
m x c
m x c
m x c
m x c
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