In: Computer Science
3 – Write the following sequence of code into the RISC-V assembler. Assume that x, y, and z are stored in registers x18, x19, and x20 respectively.
z = x - 2;
x = z +4 - y;
Given assumption is that x, y, and z are stored in registers x18, x19, and x20 respectively.
z = x - 2;
x = z +4 - y;
The code in RISC-V has been given below:
addi x20, x18, -2 // z=x-2
addi x20, x20, 4 // z=z+4
sub x18, x20, x19 // x= z-y;
HLT
Output:
An output with online RISC-V interpreter with x18=15 and x19=6 has been shown below. The final register contents are: x18=11, x19=6, x20=17.