Question: C to RISC - V assembly conversion. Consider each of the following high - level ( C ) code snippets. Convert them to RISC -
C to RISCV assembly conversion. Consider each of the
following highlevel C code snippets. Convert them to RISCV assembly. Translate the
code directly as it is do not rewrite the highlevel code
For this problem only, do not use the stack you will correct this ie use the stack in the
next problem.
Function calls:
a C code:
int main
int y subtract; y is in s
int subtractint x int w
int result; result is in s
result x w;
return result;
b C code:
same code as above, except main makes function calls
int main
int y subtract; y is in s
int w subtract; w is in s
int subtractint x int w
int result; result is in s
result x w;
return result;
pts total, pts each C to RISCV assembly conversion. Consider each of the following highlevel C code snippets. Convert them to RISCV assembly. Translate the code directly as it is do not rewrite the highlevel code
For this problem only, do not use the stack you will correct this ie use the stack in the next problem.
Function calls:
amathbfC code:
int main
int y subtract; y is in s
int subtractint x int w
int result; result is in s
result x w;
return result;
bmathbfC code:
same code as above, except main makes function calls
int main
int y subtract; y is in s
int w subtract; w is in s
int subtractint x int w
int result; result is in s
result x w;
return result;
pts total, pts each Functions and the stack saving preserved registers on the stack. Rewrite the RISCV assembly code from problem but this time use the stack as needed to save and restore registers. This is the correct way to write a function.
pts total Saving preserved and nonpreserved registers on the stack. Consider the following two function calls. Notice that func uses one of its arguments bie a after it makes a function call to func
amathbfmathbf~ p t s What value does func return when it is called as: func
b pts Perform the following steps to convert this highlevel code to assembly.
Write the code without worrying about the stack or registers that get overwritten.
Now, modify the code to use the stack to saverestore registers in the code.
int funcint a int b
int val ; val is in s
if val a
val val funcb a;
val val b;
return val;
int funcint x int w
int result; result is in s
result x w;
return result;
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
