Question: Part 2 ( 6 5 points ) You are required to write a RISC - V program that has at least six functions: main, do
Part points
You are required to write a RISCV program that has at least six functions: main,
domath, doadd, dosubtract, atoi, itoa. You are allowed to define
additional functions as needed.
The main function does the following:
Print the following prompt message:
Please enter an integer:
Read an integer from user.
Print the following prompt message:
Please enter an operator :
Read a character from user.
Print the following prompt message:
Please enter an integer:
Read an integer from user.
Call domath. Pass the two integers and the operator using registers.
Return from main using jr do not use the 'exit' syscall
The domath function takes as argument three registers and does the following:
If the operator register contains call doadd passing the two integers in
registers and receiving the return values in two registers.
Otherwise, if the operator register contains call dosubtract passing the
two integers in registers and receiving the return values in two registers.
Otherwise, print the following error message, replacing OP with the character
stored in the operator register, and exit the program.
Error: invalid arithmetic operation OP
Print the following message:
X OP Y Z
Where Z is the arithmetical result of the operation OP conducted on the two
integers input from the user, X and Y
If the operation results in an integer overflow, you should print the message:
Error: arithmetic overflow.
The doadd function takes as argument two integers in registers and does the following:
Add the two integers without using the 'add or 'sub RISCV instruction. This
restriction applies to any functions that doadd calls. You may use addi to adjust
the stack pointer if necessary for making function calls. You will likely need to
use the or 'and', 'xor', sll and srl instructions.
Return the result in a register. If there is an arithmetic overflow, return an error
condition identifying that an overflow occurred in another register.
The dosub function takes as argument two integers in registers and does the following:
Subtract the second integer from the first without using the 'sub or 'add RISC
V instructions. You may however use addi to adjust the stack pointer. You should
take the s complement of the second integer, and then call doadd. Note: to take
the s complement you should use 'nor', 'ori', and a call to doadd, thus there will
be two calls to doadd!
Return the result in a register. If there is an arithmetic overflow, return an error
condition identifying that an overflow occurred in another register.
The atoi function converts the initial part of the given string into an integer value. It
has the prototype:
int atoiconst char nptr;
It returns the integer value.
The itoa function converts the given integer to a string in base It has the prototype
char itoaint num, char ptr;
It returns the resulting nullterminated string identical to ptr
Part points
Test cases to validate the program in Part You need to create unit tests for each
function that validate its behavior independent from main. You need to create integration
tests that validate the behavior of the entire program. Be sure to test for correct inputs,
corner cases, and invalid inputs
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
