[SOLVED] VE370 Homework 1

30.00 $

Category: Tags: ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon HW1-2nvkal.zip (267.1 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
šŸ”’ Securely Powered by:
Secure Checkout
5/5 - (1 vote)
  1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C variables f, g, and h, have already been placed in registers x28, x29, and x30 respectively. Use a minimal number of RISC-V assembly instructions.f = g + (h āˆ’ 9);
  2. Ā Translate the following C code to RISC-V. Assume that the variables f, g, h, i, and j are assigned to registers x5, x6, x7, x28, and x29, respectively. Assume that the base address of the arrays A and B are in registers x10 and x11, respectively. Assume that the elements of the arrays A and B are 4-byte words:
         B[8] = A[i] + A[j];
    
  3. Ā Translate the following loop into C. Assume that the C-level integer i is held in register x5, x6 holds the C-level integer called result, and x10 holds the base address of the integer MemArray.addi x6, x0, 0
               addi x29, x0, 100
         LOOP: lw   x7, 0(x10)
               add  x5, x5, x7
    
               addi x10, x10, 4
               addi x6, x6, 1
               blt  x6, x29, LOOP
    
  4. Ā Show how the value 0x12345678 would be arranged in memory of a little- endian and a big-endian machine. Assume the data are stored starting at word address 0.
  5. Ā Assume the following register contents:
         x5 = 0x0000AAAA, x6 = 0x12345678
    

a. For the register values shown above, what is the value of x7 for the following sequence of instructions?

slli x7, x5, 4

or x7, x7, x6

b. For the register values shown above, what is the value of x7 for the following sequence of instructions?

     srli   x7, x5, 3
     andi   x7, x7, 0xFEF
  1. Ā Assume x5 holds the value 0x01010000. What is the value of x6 after the following instructions?
             bge x5, x0, ELSE
    
             jal x0, DONE
      ELSE: ori x6, x0, 2
    

    DONE: ……

  2. Consider the following RISC-V loop:
      LOOP: beq x6, x0, DONE
            addi x6, x6, -1
    

    addi x5, x5, 2

            jal x0, LOOP
      DONE: ......
    
    1. (1)Ā  Ā Assume that the register x6 is initialized to the value 10. What is the final value in register x5 assuming the x5 is initially zero?
    2. (2)Ā  Ā For the loop above, write the equivalent C code. Assume that the registers x5 and x6 are integers acc and i, respectively.
    3. (3)Ā  For the loop written in RISC-V assembly above, assume that the register x6 is initialized to the value N. How many RISC-V instructions are executed?
    4. (4)Ā  For the loop written in RISC-V assembly above, replace the instruction ā€œbeq x6, x0, DONEā€ with the instruction ā€œblt x6, x0, DONEā€ and write the equivalent C code.
  3. Translate the following C code to RISC-V assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers x5, x6, x7, and x29, respectively. Also, assume that register x10 holds the base address of the array D.
          for(i=0; i<a; i++)
             for(j=0; j<b; j++)
    

    D[4āˆ—j] = i + j;

  • HW1-2nvkal.zip