” ECS 50编程设计 辅导、Python编程 写作ECS 50: Programming Assignment #5Spring 2021Contents1 Changelog 12 General Submission Details 13 Grading Breakdown 14 Submitting on Gradescope 15 Programming Problems 25.1 General Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25.2 Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25.3 Part #1: Get Max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25.4 Part #2: Sum Other . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35.5 Part #3: Transpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 ChangelogYou should always refer to the latest version of this document. v.1: Initial version.2 General Submission DetailsPartnering on this assignment is prohibited. If you have not already, you should read the section onacademic misconduct in the syllabus.This assignment is due the Night of Tuesday, 05/25. Gradescope will say 12:30 AM on Wednesday, 05/26, due to thegrace period (as described in the syllabus). Be careful about relying on the grace period for extra time; this could be risky.3 Grading BreakdownAs stated in the updated syllabus, this assignment is worth 9% of your final grade (which is pretty inflated, but I dontwant there to be too much weight at the very end of the course). Each of the three parts is worth 3%.4 Submitting on GradescopeFiles to submit: max.s sum_other.s transpose.sThis content is protected and may not be shared, uploaded, or distributed.1Do not submit the input code files, e.g. call_max.s. You may be penalized for submitting unnecessary files.There is no autograder for this assignment, at least not one that you get to interact with before thedeadline. You must simply submit your code to Gradescope, and after the deadline I will use a script to grade thesubmissions. (Make sure your file names are correct!) I will do this on the CSIF, so the CSIF is still the reference environment.Your output must match mine exactly.5 Programming ProblemsFor this assignment, you will implement three functions using the 64-bit RISC-V assembly language, i.e. the one thatwe have talked about during lecture. There are hardly any RISC-V computers out there now, so I dont expect any of youto have any. The CSIF computers have x64 (i.e. x86-64) chips. Instead, we will use a simulator and associated compilationtools that are already installed on the CSIF. In case you are curious, the tools are listed below; you do not need to installthese tools yourself, since they are already on most of the computers on the CSIF. (If you do install them on yourend, just know that the process may take a few hours and is a bit complicated.) You can find a list of the CSIF computersthat have the tools installed here. The RISC-V GNU toolchain here. I Did the Newlib installation (riscv64-unknown-elf-gcc), not the Linux one, becausespike requires the former. The Spike RISC-V ISA simulator here. RISC-V Proxy Kernel and Boot loader here.In the examples below, I show how to use the RISC-V GNU toolchain on the CSIF to compile code.5.1 General RequirementsThe requirements mentioned here apply to all three parts.In this assignment, all code that you write must be RISC-V assembly code. You must write this assemblycode yourself. As an example of what you cannot do, you cannot write C++ code (or code in any otherhigh-level language) and then use some tool to compile that C++ code into assembly code to submit; we willnot accept that, and we will easily be able to tell if you submitted compiler-generated assembly code.Each of the three required functions that you write for this assignment must preserve the value of any register that ituses except for: The registers used for the arguments required by the function. (For example, since the function max() that you willwrite for part #1 takes two arguments, the registers a0 and a1 need not be preserved.) a0, if it is used for a return value.In real-world RISC-V assembly code, you would of course obey the appropriate calling convention and not preserve thevalues of volatile registers. Here, to give you practice preserving registers, we disregard this common calling convention.5.2 TipsNote that you have access to Common library functions such as printf(), due to the way in which you will compile yourcode. This may be helpful as you debug your code.If you call printf() in any of your functions, make sure to preserve the values of any volatile registers that you are usingfirst, including most notably the ra register.5.3 Part #1: Get MaxIn this part, you will write a function called max() that takes two arguments in the a0 and a1 registers both 32-bit integers and returns (in the a0 register) whichever of the two arguments is higher.Below is an example of how your code should behave. You can find call_max.s on Canvas. I intentionally show a fewlines of max.s, in order to help you get started1. Note that if you copy from this PDF directly, spaces may be inserted inunexpected locations; keep that in mind if you copy the commands in order to paste them into a terminal. Also note thatthe bbl loader part of the output is always there, no matter what you do; that is from the Spike emulator.1You must make max a global symbol with the .global directive, so that the symbol can be seen from within call_max.s. (I think that .globland .global are exactly the same.)21 $ cat call_max . s2 . data34 format_str : . string Max : %d\ n56 . text7 . globl main8 main :9 li a0 , 510 li a1 , 1311 jal max12 mv a1 , a013 lui a0 , % hi ( format_str )14 addi a0 , a0 , % lo ( format_str )15 call printf16 # Perform exit () system call .17 # Source : httpss :// www . robalni . org / riscv / linux – syscalls -64. html18 li a7 , 9319 li a0 , 020 ecall21 $ cat max .s22 . global max23 max :24 … ( removed by Aaron ) …25 jalr x0 , 0( x1 )26 $ / opt / riscv / bin / riscv64 – unknown – elf – gcc max .s call_max .s -o max27 $ / opt / riscv / bin / spike / opt / riscv / riscv64 – unknown – elf / bin / pk max28 bbl loader29 Max : 135.4 Part #2: Sum OtherIn this part, you will write a Function called sum_other() that takes two arguments in the a0 and a1 registers:1. First argument: the (potentially 64-bit) starting address of an array of 32-bit integers.2. Second argument: length of this array (a 32-bit value).The function should return (in a0) the sum of every other value in the array (i.e. the sum of the first value, third value,fifth value, etc.).Below is an example of how your code should behave.1 $ cat call_sum_other .s2 . data34 format_str : . string Sum : %d\ n56 arr :7 . long 58 . long 209 . long 1310 . long 1811 . long 2712 . long 421314 . text15 . globl main16 main :17 lui a0 , % hi ( arr )18 addi a0 , a0 , % lo ( arr )19 li a1 , 620 jal sum_other21 mv a1 , a022 lui a0 , % hi ( format_str )23 addi a0 , a0 , % lo ( format_str )24 call printf25 # Perform exit () system call .26 li a7 , 9327 li a0 , 028 ecall29 $ cat sum_other .s30 . global sum_other31 sum_other :332 … ( removed by Aaron ) …33 jalr x0 , 0( x1 )34 $ / opt / riscv / bin / riscv64 – unknown – elf – gcc sum_other .s call_sum_other . s -o sum_other35 $ / opt / riscv / bin / spike / opt / riscv / riscv64 – unknown – elf / bin / pk sum_other36 bbl loader37 Sum : 455.5 Part #3: TransposeIn this part, you will implement the Transpose() function that you previously implemented in part #5 of the previousprogramming assignment. You should consult prog_hw4.pdf if you do not remember all of the details of that function. In theversion on the previous assignment, all four arguments were passed on the stack. For this current assignment, this will notbe the case; instead, the four arguments will be passed through the registers a0 through a3. This function does not returnany value, and it is not allowed to modify the original matrix. Note that both the input matrix and the output matrix aretwo-dimensional arrays of 32-bit integers, and their dimensions are 32-bit values. However, the starting addresses of thesematrices are potentially 64-bit values.Hint: Multiplication is supported by our tools. For instance, you can do mul a0, a1, a2 to store the product of a1 and a2in a0. (There does not seem to be a version that has an immediate operand as the third operand.)Below is an example of what calling the function would look like. You should yourself add a nested loop for printing outthe values of the output array.1 $ cat call_transpose .s2 . data34 input :5 . word 16 . word 27 . word 38 . word 49 . word 510 . word 61112 output :13 . rept 614 . word -115 . endr1617 . text18 . globl main19 main :20 lui a0 , % hi ( input )21 addi a0 , a0 , % lo ( input )22 li a1 , 323 li a2 , 224 lui a3 , % hi ( output )25 addi a3 , a3 , % lo ( output )26 jal transpose27 # Perform exit () system call .28 li a7 , 9329 li a0 , 030 ecall31 $ cat transpose .s32 . global transpose33 transpose :34 … ( removed by Aaron ) …35 jalr x0 , 0( x1 )请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。