In: Computer Science
Convert the following C program into the RISC-V assembly code. You should look up a table to convert the lines manually and you can use "ecall" when appropriate (Don't make it too complicated than it needs to be):
#include
int main()
{
int x = 30, y = 17;
printf("x * y = ");
printf("%d\n", x*y);
return 0;
}
the above mentioned c program is converted into RISC - V assembly code as follows :
.LC0:
.string "x * y = "
.LC1:
.string "%d\n"
main:
addi sp,sp,-32
sd ra,24(sp)
sd s0,16(sp)
addi s0,sp,32
li a5,30
sw a5,-20(s0)
li a5,17
sw a5,-24(s0)
lui a5,%hi(.LC0)
addi a0,a5,%lo(.LC0)
call printf
lw a4,-20(s0)
lw a5,-24(s0)
mulw a5,a4,a5
sext.w a5,a5
mv a1,a5
lui a5,%hi(.LC1)
addi a0,a5,%lo(.LC1)
call printf
li a5,0
mv a0,a5
ld ra,24(sp)
ld s0,16(sp)
addi sp,sp,32
jr ra