INET_Quiz_1

.pdf

School

New York University *

*We aren’t endorsed by this school

Course

6913

Subject

English

Date

Jan 9, 2024

Type

pdf

Pages

8

Uploaded by LieutenantElectron12238

NYU Tandon School of Engineering Fall 2023, ECE 6913 INET Quiz 1 1. Write down the RISC V code for the following tasks: Assume Base address of arrays A, B, C are in registers x5, x6, x7 Assume variables f, g, i are in registers x8, x9, x10 Implement in RISC V these line of code in C: (i) f = g - A[B[C[64]]] lw x7, 256(x7) # C[64] slli x7, x7, 2 add x6, x6, x7 # &B[C[64]] lw x6, 0(x6) # B[C[64]] slli x6, x6, 2 add x5, x5, x6 # &A[B[C[64]]] lw x5, 0(x5) # A[B[C[64]]] sub x8, x9, x5 # f = g A[B[C[64]]] (ii) f = g - A[C[16] + B[32]] lw x6, 128(x6) # B[32] lw x7, 64(x7) # C[16] add x6, x6, x7 # B[32] + C[16] slli x6, x6, 2 add x5, x5, x6 # &A[B[32] + C[16]] lw x5, 0(x5) # A[B[32] + C[16]] sub x8, x9, x5 # f = g - A[B[32] + C[16]]
(iii) A[i] = 4B[8i-81] + 4C[32i+32] slli x11, x10, 5 # 32i addi x11, x11, 32 # 32i+32 slli x11, x11, 2 add x7, x7, x11 # &C[32i+32] lw x7, 0(x7) # C[32i+32] slli x7, x7, 2 # 4C[32i+32] slli x12, x10, 3 # 8i addi x12, x12, -81 # 8i-81 slli x12, x12, 2 add x6, x6, x12 # &B[8i-81] lw x6, 0(x6) # B[8i-81] slli x6, x6, 2 # 4B[8i-81] add x6, x6, x7 # 4C[32i+32] + 4B[8i-81] slli x13, x10, 2 add x5, x5, x13 # &A[i] sw x6, 0(x5) # A[i] = 4B[8i-81] + 4C[32i+32] 2 . Write a sequence of RISC V instructions that swap byte 4 (bits 31:24) with byte 1 (bits 7:0) in a 4 byte (32b) long word Assume the 4 byte word is stored in x5 andi x6, x5, 0xFF000000 # extract byte 4 srli x6, x6, 24 # shift extracted byte 4 to bits 7:0 andi x7, x5, 0x000000FF # extract byte 1 slli x7, x7, 24 # shift extracted byte 2 to bits 31:24 or x8, x6, x7 # combine swapped byte 1 and 4 andi x5, x5, 0x00FFFF00 # Zero out bits 31:24 and 7:0 in original register
or x5, x5, x8 # Load swapped byte 1 and 4 in original register 3. One possible performance enhancement is to do a shift and add instead of an actual multiplication. Since 9×6 , for example, can be written (2×2×2+1×6 , we can calculate 9×6 by shifting 6 to the left three times and then adding 6 to that result. Show the best way to calculate 0x 3A hex × 0x 5F hex using shifts and adds/subtracts. Assume both inputs are 8- bit unsigned integers. 0x3A 16 = 0011 1010 = 58 10 0x5F 16 = 0101 1111 = 95 10 58 x 95 = 5510 10 = 0x1586 16 0x3A 16 = 00111010 2 = 58 10 , and 58 = 32+16+8+2 = 2 5 + 2 4 + 2 3 + 2 1 So, We can shift 0x5F left 5 places = 0 1011 1110 0000 = 3040 10 = 0xBE0 16 then add 0x5F left shifted 4 places = 0101 1111 0000 = 1520 10 = 0x5F0 16 then add 0x5F left shifted 3 places = 0010 1111 1000 = 760 10 = 0x2F8 16 then add 0x5F left shifted 1 place = 1011 1110 = 190 10 = 0xBE 16 Adding 3040+1520+760+190 = 5510 = 0x1586 16 . So, we can use 4 shifts and 3 adds instead of actual multiplication. 4. Assume a 10-bit floating point representation format where the Exponent Field has 4 bits and the Fraction Field has 5 bits and the sign bit field uses 1 bit a. What is the representation of -8.80158 x 10 -2 in this Format [assume: Exponent Field: 4 bits Fraction Field: 5 bits S
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help