Question

In: Computer Science

Convert the following C program into the RISC-V assembly code. You should look up a table...

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;

}

Solutions

Expert Solution

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


Related Solutions

Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main()...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main() { int i = 2, j = 2 + i, k; k = i * j; printf("%d\n", k + j); return 0; } 2) #include <stdio.h> int main() { int i = 2, j = 2 + i, k = j / 2; if (k == 1) { printf("%d\n", j) k = k * 2; if ( k == j) { printf("%d\n|, j); }...
1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C...
1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C variables a, b, and c, have already been placed in registers x10, x11, and x12 respectively. Use a minimal number of RISC-V assembly instructions. a = b + (c − 2); 2. Write a single C statement that corresponds to the two RISC-V assembly instructions below. add e, f, g add e, h, e 3. Assume that registers x5 and x6 hold the values...
Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative...
Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative integer decimal string to an integer. ‘+’ and ‘-’ will appear optionally. And once they appear, they will only appear once in the first byte. If a non-digit character appears in the string, your program should stop and return -1.
convert following C++ code into MIPS assembly: int main() {                                 &
convert following C++ code into MIPS assembly: int main() {                                         int x[10], occur, count = 0;                                                              cout << "Type in array numbers:" << endl; for (int i=0; i<10; i++) // reading in integers                               { cin >> x[i];        } cout << "Type in occurrence value:" << endl;                                 cin >> occur;                                                 // Finding and printing out occurrence indexes in the array                                  cout << "Occurrences indices are:" <<...
Program 1-100 integer accumulation using RISC-V assembly. Note: RARS only simulates 320-bit instructions of RISC-V, so...
Program 1-100 integer accumulation using RISC-V assembly. Note: RARS only simulates 320-bit instructions of RISC-V, so make sure you use the instruction that operate work-size data type (mostly with `w` as the last character of the instruction mnemonic)
Convert the following pep/9 machine language program into an assembly code. Determine the output of this...
Convert the following pep/9 machine language program into an assembly code. Determine the output of this program if the input is ‘tab’. The left column is the memory address of the first byte on the line: 0000 D1FC15 0003 F1001F 0006 D1FC15 0009 F10020 000C D1FC15 000F F10021 0012 D10020 0015 F1FC16 0018 D1001F 001B F1FC16 001E 00
Convert this C++ program exactly as you see it into x86 assembly language: // Use the...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the Irvine library for the print function #include <iostream> // The string that needs to be printed char word[] = "Golf\0"; // Pointer to a specific character in the string char * character = word; //NOTE: This main() function is not portable outside of Visual Studio void main() { // Set up a LOOP - See the while loop's conditional expression below int ecx =...
write a assembly language program to convert GRAY to BCD code in 8051
write a assembly language program to convert GRAY to BCD code in 8051
What does the RISC-V code below do? Write the C equivalent. Assume that i is in...
What does the RISC-V code below do? Write the C equivalent. Assume that i is in register x5 and that the base address of array A that holds doubleword integers is in x20. addi x5, x0, 0 addi x6, x0, 50 addi x28, x20, 0 loop: bge x5, x6, end ld x7, 0(x28) bge x7, x0, next sub x7, x0, x7 sd x7, 0(x28) next: addi x5, x5, 1 addi x28, x28, 8 jal x0, loop end: Can you rewrite...
3 – Write the following sequence of code into the RISC-V assembler. Assume that x, y,...
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;
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT