/avatar.jpg
|

Lec3-Control

Control div in Python 1 2 3 4 5 6 7 from opertor import truediv, floordiv a = 10 b = 3 c = a / b d = a // b print(c) # 3.3333333333333335 print(d) # 3 doctest in Python

Lec4-Higher-Order Functions

Higher Order Functions Control Statements vs Functions all params will be evaluated before the function is called ! 不存在跳过参数的情况 Assertions in Python 1 assert condition, message Returning a Function from a Function 带参数的修饰器 😮 1 2 3 4 5 6 7 8 def make_adder(n): def adder(x): return x + n return adder # Example usage add_three = make_adder(3) print(add_three(4)) # Output: 7, WHY? functions in Python are first-class values!

Lec12-RISC-V Instruction Formats II

RISC-V Instruction Formats II B-Format Layout branch/分支 ==> if-else, while, for encode Label: PC寻址, 用imm field来表示偏移量 实际上 RV compressed instruction format! 16bit 压缩指令格式,偏移量不再是4的倍数,而是2的倍数(所以imm 二进制结尾一定是0) 理论layout 解释一下如何从指令解析出立即数的数值 B-type “|” 意思是专门分出一块区域来存一位数字 Long Immediate, U-Format Layout I, B, S imm的12位扩展到long,找个地方放下剩下的20位 注意这里不直接使用branch指令跳转,而是采用jump直接来做 地方来了:同时来了两个新的指令lui & auipc Corner case 有符号扩展带过来的,1开头的符号扩展 用+1来避免这个问题 补充 auipc 指令 J-Format Layout 只有jal,因为jalr是I-type的 使用示例 jalr 使用示例 留一个reference