/avatar.jpg

Lec11-RISC-V Instruction Formats I

RISC-V Instruction Formats I 事实上已经来到下一个层级(二进制)了,但是看标题似乎还是RISC-V 🤔 Background and Consequences 1. addressing modes everything has a memory address, so branches and jumps can use them PC (program counter, again 😄) is a register that holds the address of the next instruction to be executed 2. 二进制兼容否?如何表示指令? 一个指令用1个word(32bits)来装绰绰有余 divide instruction into “fields” 😋 R-Format Layout 算数逻辑指令 funct3: 功能码,决定指令的操作类型 funct7: 扩展功能码,用于一些复杂的指令 opcode: 操作码,决定指令的类别 具体查表 new one: slt and sltu – set less than, when rs1 < rs2, then set the destination register to 1, otherwise 0.

Lec10-RISC-V Procedures

RISC-V Procedures 调用函数的时候有一些无关的主进程变量的value需要存储,but where? 栈帧 / Stack Frame 存放了什么? 注意stack 从上往下增长,push sp–, pop sp++ 序言prologue & 结尾epilogue 1 2 3 4 5 int Leaf (int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } 1 2 3 4 5 6 7 8 9 10 11 12 13 Leaf: # 序言prologue addi sp, sp, -8 # 保存之前的栈指针 sw s1, 4(sp) # 保存参数 sw s2, 0(sp) # 计算 .

Lec9-RISC-V Decisions II

RISC-V Decisions II Logical Instruction and, andi, not 2种对应变体 and: and x5, x6, x7 # x5 = x6 & x7 andi: andi x5, x6, 0x7 # x5 = x6 & 0x7 # for masking 😋 or: or x5, x6, x7 # x5 = x6 | x7 xor: xor x5, x6, x7 # x5 = x6 ^ x7 Not not, xor with 111111…1111即可 shift instructions logical shift arithmetic shift A bit about machine programming PC: program counter (special register), 程序计数器 指向下一条指令的地址(next 4 byte / 1 word away)