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;
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
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...
Sample Code and Models Run each of the models below and explain the code function and...
Sample Code and Models Run each of the models below and explain the code function and your findings for each system, do they agree/disagree with what you understand and why ?? Matlab Code % Winter 2018 Control Engineering % Lab No.3 - Root Locus problems % Mark Clarke clear s = tf('s') K = 1150; %Proportional Controller Gain, May need to be altered? % Enter Model 1 % This is a model of a simple 2nd order with no zeros...
4. Explain what is happening on each line of the following AVR assembly code. If you...
4. Explain what is happening on each line of the following AVR assembly code. If you were to execute this code what would be the final decimal values in R20, R21 and SREG registers? BCLR 0 BCLR 1 BCLR 2 BCLR 3 BCLR 4 BCLR 5 BCLR 6 BCLR 7 LDI ​R19, 0x02 LDI​R20, 0x74 LDI​R21, 0x04 LDI​R22, 0x22 ADD​R20, R22 SUB​R22, R21 ADD​R20, R21 MOV​R20, R21 JMP​DONE ADD​R21, R20 SUB​R21, R22 DONE:​SUB​R20, R21 -embedded system-
Run the following code and explain the results (expectation of the array). Test it on the...
Run the following code and explain the results (expectation of the array). Test it on the following arrays: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] [1.0, 4.0, 6.0,2.0 , 3.0, 5.0] [5.0, 3.0, 2.0, 6.0, 4.0, 1.0] [6.0, 5.0, 4.0, 3.0, 2.0, 1.0] // Java code to calculate expected // value of an array import java.io.*; class GFG { // Function to calculate expectation static float calc_Expectation(float a[], float n) { // Variable prb is for probability of each // element...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT