Question

In: Computer Science

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, x3

mulhsu x6, x3, x4

Code 4.

addi x7, x7, 45

addi x4, x4, 3

div x5, x7, x4

div x6, x4, x7

Code 5.

addi x7, x7, -46

addi x4, x4, 3

div x5, x7, x4

rem x8, x7, x4

Code 6.

addi x7, x7, -46

addi x4, x4, 3

divu x5, x7, x4

Solutions

Expert Solution

Code 1

  • The contents of x3 is added with 1 and the result is placed in x3 //x3=x3+1
  • Shifting left by immediate and store in X3   // x3=x3<<62
  • The contents of x4 is added with 7 and the result is placed in x4 //x4=x4+7
  • The contents of x4 is multiplied by the contents of x3 and the result is placed in x5 // x5=x4*x3
  • The contents of x4 is multiplied by the contents of x3 . The result is stored in x6. Also x6 will be having the most significat half. The operands x4,x3 and the results x6 will be of unsigned values// x6 = HighBits(x4*x3)

Code 2

  • The contents of x3 is added with 1 and the result is placed in x3 //x3=x3+1
  • Shifting left by immediate and store in X3   // x3=x3<<63
  • The contents of x4 is added with 1 and the result is placed in x4 //x4=x4+1
  • The contents of x4 is multiplied by the contents of x3 and the result is placed in x5 // x5=x4*x3
  • The contents of x4 is multiplied by the contents of x3 . The result is stored in x6. Also x6 will be having the most significat half. Of x4 and x3, one will be signed and other will be unsigned and the result will be signed value // x6 = HighBits(x4*x3)

Code 3

  • The contents of x3 is added with 1 and the result is placed in x3 //x3=x3+1
  • Shifting left by immediate and store in X3   // x3=x3<<63
  • The contents of x4 is added with 1 and the result is placed in x4 //x4=x4+1
  • The contents of x4 is multiplied by the contents of x3 and the result is placed in x5 // x5=x4*x3
  • The contents of x3 is multiplied by the contents of x4 . The result is stored in x6. Also x6 will be having the most significat half. Of x3 and x4, one will be signed and other will be unsigned and the result will be signed value // x6 = HighBits(x3*x4)

Code 4

  • The contents of x7 is added with 45 and the result is placed in x7 //x7=x7+45
  • The contents of x4 is added with 3 and the result is placed in x4 //x4=x4+3
  • The contents of x7 is divided by the contents of x4 and the quotient is placed in x5. Both x7,x4 and the result are signed values.// x5= x7 DIV x4
  • The contents of x4 is divided by the contents of x7 and the quotient is placed in x6. Both x4 ,x7 and the result are signed values.// x6= x4 DIV x7

Code 5.

  • The contents of x7 is subtracted with 46 and the result is placed in x7 //x7=x7- 46
  • The contents of x4 is added with 3 and the result is placed in x4 //x4=x4+3
  • The contents of x7 is divided by the contents of x4 and the quotient is placed in x5. Both x7,x4 and the result are signed values.// x5= x7 DIV x4
  • The contents of x7 is divided by the contents of x4 and the remainder is placed in x8. Both x7,x4 and the result are signed values.// x8= x7 REM x4

Code 6

  • The contents of x7 is subtracted with 46 and the result is placed in x7 //x7=x7- 46
  • The contents of x4 is added with 3 and the result is placed in x4 //x4=x4+3
  • The contents of x7 is divided by the contents of x4 and the quotient is placed in x5. Both x7,x4 and the result are unsigned values.// x5= x7 DIV x4

Related Solutions

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...
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; }
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;
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...
1.a. RISC-V has several addressing modes. Describe 4 addressing modes. For each, describe what it does...
1.a. RISC-V has several addressing modes. Describe 4 addressing modes. For each, describe what it does and give an example assembly instruction that uses that addressing mode. b. Starting with a C source code file, describe the steps that must occur in order to actually begin executing the program on your computer.
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); }...
The following code will generate a Decision Tree. You need to run the code and explain...
The following code will generate a Decision Tree. You need to run the code and explain the tree. After you get the Tree. You need to explain how does it draw like that. install.packages("rpart.plot") # install package rpart.plot ########################################## # section 7.1.1 Overview of a Decision Tree ########################################## library("rpart") library("rpart.plot") # Read the data setwd("c:/data/") banktrain <- read.table("bank-sample-test.csv",header=TRUE,sep=",") ## drop a few columns to simplify the tree drops<-c("age", "balance", "day", "campaign", "pdays", "previous", "month") banktrain <- banktrain [,!(names(banktrain) %in% drops)]...
1. Explain and show (separately) on a graph how each of the following would affect the...
1. Explain and show (separately) on a graph how each of the following would affect the demand for calculators: a. Cell phones now have a calculator function included b. Every course begins to require use of a calculator c. The price for a calculator falls from $20 to $7 d. Consumers’ incomes increase, and calculators are a normal good
Name and explain the exact types of the following strategies: (you can explain each one separately)...
Name and explain the exact types of the following strategies: (you can explain each one separately) 1. The toy retailer developed a new Wi-Fi tablet computer for children. 2. Retailer IKEA is opening a chain of motels in Europe. 3. Callaway Golf cut 12 percent of its workforce.
4. Consider each of the following activities separately, how much does it contribute to US GDP?...
4. Consider each of the following activities separately, how much does it contribute to US GDP? (a) Company X in the US bought steel from another US company, which costs $50,000. Company X used the steel to make cars, and sold them for $150,000 this year. (b) Your kid mows the lawn for your neighbor, and your neighbor gives him $50 for his work. (c) This year, you sold your house for $500,000, which was built 100 years ago. Your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT