Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
