Activity 1 (40points): RISC-V programming RISC project: Using the RISC-V interpreter available at https://www.cs.cornell

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Activity 1 (40points): RISC-V programming RISC project: Using the RISC-V interpreter available at https://www.cs.cornell

Post by answerhappygod »

Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 1
Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 1 (53.99 KiB) Viewed 27 times
Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 2
Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 2 (41.47 KiB) Viewed 27 times
Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 3
Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 3 (76.64 KiB) Viewed 27 times
Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 4
Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 4 (37.2 KiB) Viewed 27 times
Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 5
Activity 1 40points Risc V Programming Risc Project Using The Risc V Interpreter Available At Https Www Cs Cornell 5 (74.95 KiB) Viewed 27 times
Activity 1 (40points): RISC-V programming RISC project: Using the RISC-V interpreter available at https://www.cs.cornell.edu/courses/cs34 ... terpreter/ The webpage includes four major components: • A sub-window for entering assembly code Contents of the 32 CPU registers . • List of supported RISC instructions Data memory contents (at bottom of page) RISC processor has 32 registers of width 32 bits. Data memory locations are 8-bits in width and are displayed 4 bytes at a time. 1. Practice: The following practice refers to the text file 'RISC-V practice examples.txt' that includes programming examples: a. Programs 1, 2-register loading and memory storage examples. b. Program 3-branch example c. Program 4- this shows how to write simple loop d. Program 5- running sum of an array containing 5 elements 2. Consider the following pseudo-code: n=7 x=75 do n times: output x mod 2 x=floor(x/2) a. Work this pseudo-code by hand for the following values of x and n i. n=7, x=75 ii. n=4, x=5 iii. n=4, x=10 b. What is this algorithm doing?
3. Consider the following RISC-V pseudo-code: Initial register x0 is assumed set equal to zero Set x15=7 (Add immediate value of 7 to x0 and place in x15) Set x16=75 (Add immediate value of 75 to x0 and place in x16) Add immediate value of 1 to x0 and place in x12 Add immediate value of 0 to x0 and place in x18 Loop: If x15 is equal to 0, branch to Done Logical and x12 with x16 and place result in x17 Logical or x17 with x18 and place result in x18 Logical shift left immediate x12 by 1 and place result in x12 Subtract immediate value of 1 from x15 and place result in x15 Jump unconditional to Loop Done: • Implement this pseudo-code using the RISC-V interpreter and compare the result contained in x18 with your result from question 2. • Create a text file named 'Activity1.txt' that contains your RISC-V code along with comments containing your answers to question 2. Make sure you save your code.
#Program 1. Study data memory #logical shift left. addi x5,x0, 0xla slli x12, x5,24 addi x5, x0, 0xff slli x11,x5,16 add x12,x12,x11 addi x5,x0,0x52 slli x11,x5,8 add x12,x12,x11 addi x12, x12, 0x08 addi x7,x0,4 #store 32-bit word contained in sw x12,0 (x7) x12 to memory #location pointed to by x7+offset #load 32-bit word contained in 1w x4,0 (x7) memory #location pointed to by x5+offset into register x4 #= #Program 2. Study data memory #x5 will be used to point to data memory location 0 add x5, x0, x0 addi x11,x0, 0x8f5 #add hexadecimal 8f5 to x0, place in x11 sw x11,0 (x5) #store 32-bit word contained in x11 to memory location pointed to by x5+offset lb x12,0 (x5) #load byte contained memory location pointed to by x5+offset into register x12 lb x12,1(x5) #load byte contained memory location pointed to by x5+offset into register x12 lb x12,2 (x5) #load byte contained memory location pointed to by x5+offset into register x12 lb x12,3(x5) #load byte contained memory location pointed to by x5+offset into register x12
#Program 3: branching instruction #addi x13, x0,3 bne x13,x14,12 add x10, x11,x12 jal x0,8 sub x10, x11,x12 addi x13,x0,3 #= #Program 4. Loop example add x11, x0, x0 # i=0 addi x12, x0,7 # x12=number of times to iterate bge x11, x12, 12 addi x11, x11, 1 # i++ jal x0, -8 # Iterate add x15,x11, x0 11 || || II || 11 II || 11
#Program 5. Sum the elements of an array #x8 holds pointer to the array A addi x8, x0, 0x00 #starting array at data memory location 0 #fill array with data #store data pointed x8+offset #clear x7 register. #load x7 with data xor x7,x7,x7 #clear x7 register addi x7,x0,4 #load x7 with data sw x7,0 (x8) xor x7,x7,x7 addi x7,x0,5 sw x7,4 (x8) xor x7,x7,x7 addi x7,x0,3 sw x7,8(x8) xor x7,x7,x7 addi x7,x0,2 sw x7, 12(x8) #store data pointed x8+offset #clear x7 register. #load x7 with data #store data pointed x8+offset #clear x7 register #load x7 with data #store data pointed x8+offset #Assign x10=sum, x11=i add x10, x0, x0 # sum=0 add x11, x0, x0 # i=0 addi x12, x0,4 bge x11, x12, 28 # x12=number of elements in array slli x13, x11, 2 #i* 4 add x13, x13, x8 # & of A + i # * (A + i) 1w x13, 0(x13) add x10, x10, x13 # increment sum addi x11, x11, 1 # i++ jal x0, -24 # Iterate
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply