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); }...
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:" <<...
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;
Run the following RISC-V codes separately and explain what each code does and how you interpret...
Run the following RISC-V codes separately and explain what each code does and how you interpret the register results: Code 1. addi x3, x3, 1 slli x3, x3, 62 addi x4, x4, 7 mul x5, x4, x3 mulh x6, x4, x3 Code 2. addi x3, x3, 1 slli x3, x3, 63 addi x4, x4, 1 mul x5, x4, x3 mulhsu x6, x4, x3 Code 3. addi x3, x3, 1 slli x3, x3, 63 addi x4, x4, 1 mul x5, x4,...
Convert the following C++ statements to an ARM assembly language program: const int size = 10;...
Convert the following C++ statements to an ARM assembly language program: const int size = 10; int x[size] = {8, 2, 9, 6, 7, 0, 1, 3, 5, 4}; int y[size] = {399, -87, 12, 0, 42, -367, 57, 92, -1000, 25}; for i = 0; i < size; i++) if (x([ i ] > y[ i ]) z[ i ] = 0 else z[ i ] = 1;
4 – The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly...
4 – The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly instruction. What is the RISC-V instruction format and specific assembly language instruction? 0x00156A33
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT