cs61c-lab03
Lab 3: RISCV Assembly
cs61c - Great Ideas in Computer Architecture (Machine Structures) lab 笔记第三篇
lab3 熟悉编写 RISC-V 并使用 Venus 模拟器 Venus reference,先硬着头皮做的proj2A,被折磨了两天,现在在写这些基础的确实觉得很简单,不过先写了lab3应该对proj2有些帮助,可以说是前置。
Exercise 0: Connecting your files to Venus
注意lab03好像默认是没有tools/venus.jar 这个文件的,可以从sp22的proj2复制一个
将文件链接到_Venus_, 在lab文件下
1 |
|
Exercise 1: Familiarizing yourself with Venus
- What do the
.data
,.word
,.text
directives mean (i.e. what do you use them for)? Hint: think about the 4 sections of memory.
1 |
|
- Run the program to completion. What number did the program output? What does this number represent?
1 |
|
- At what address is
n
stored in memory? Hint: Look at the contents of the registers.
1 |
|
- Without actually editing the code (i.e. without going into the “Editor” tab), have the program calculate the 13th fib number (0-indexed) by manually modifying the value of a register. You may find it helpful to first step through the code. If you prefer to look at decimal values, change the “Display Settings” option at the bottom.
1 |
|
Exercise 2: Translating from C to RISC-V
ex2.c
1 |
|
ex2.s
1 |
|
- The register representing the variable
k
.
1 |
|
- The register representing the variable
sum
1 |
|
- The registers acting as pointers to the
source
anddest
arrays.
1 |
|
- The assembly code for the loop found in the C code
1 |
|
- How the pointers are manipulated in the assembly code.
1 |
|
Exercise 3: Factorial
递归:
factorial.c
1 |
|
factorial.s
1 |
|
迭代:
factoria.c
1 |
|
factoria.s
1 |
|
显然迭代貌似更好写
Exercise 4: Calling Convention Checker
修复约定检查器检测出的违规行为
1 |
|
添加了些存储sp
1 |
|
Exercise 5: RISC-V function calling with map
finish
cs61c-lab03
https://2333monster.github.io/2023/08/16/cs61c-lab03/