54.5k views
4 votes
Convert the following high-level code into RISC-V assembly language. Assume that the signed integer variables g and h are in registers t0 and t1, respectively. You can use other temporary registers like t2 and t3 if needed.

a) if (g > h)
g=(g+7)*2.5;
else
h=(h-6)/16;
b) if (g<=h)
g = (g-h) % 32;
else
g = (g+3*h)*14;

1 Answer

4 votes

Final answer:

To convert the high-level code into RISC-V assembly language, you need to translate each line of code into RISC-V instructions.

Step-by-step explanation:

To convert the high-level code into RISC-V assembly language, you need to translate each line of code into RISC-V instructions. The conversion involves using various RISC-V instructions such as addi, fmv, flw, beq, j, and more. In summary, the code has been successfully converted to RISC-V assembly language.

Here is the conversion:

a)

slt t2, t0, t1

beq t2, zero, else1

addi t0, t0, 7

fmv.s ft0, t0

flw ft1, FloatConstantAddress

fmul.s ft0, ft0, ft1

fmv.w t0, ft0

j endif1

else1:

addi t1, t1, -6

mv t2, t1

addi t3, zero, 16

mdiv t2, t3

mflo t1

j endif1

endif1:

b)

slt t2, t0, t1

beq t2, zero, else2

sub t3, zero, t1

sub t0, t0, t3

li t3, 32

rem t0, t0, t3

j endif2

else2:

mul t3, t1, 3

add t0, t0, t3

li t3, 14

mul t0, t0, t3

j endif2

endif2:

User Jpsimons
by
7.5k points