明儿就是 Computer Organization and Design 的考试了,然而我复习不下去惹。
不如来写点东西
这次介绍的是单周期 CPU 的设计,使用的 ISA 是 MIPS 。关于详细信息:
Reference:
http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html
本次文章为 Computer Organization and Design 课程的实验2总结,同时也包括部分章节知识。本次实验的所有知识来自网络和书本 Computer Organization And Design MIPS Edition。
今后还有 多周期 CPU 、 流水线 CPU 的实验记录,欢迎持续关注。
目标:实现7条 Instruction
- addu
- subu
- ori
- lw
- sw
- beq
- jal
在介绍指令之前,我们来了解一下 MIPS ISA (Instruction Set Architecture) 的格式。
MIPS ISA format
本次实验中,我们将指令简单分为三种类型
- R-Type (Register type)
- I-Type (Immediate type)
- J-Type (Jump)
R-Type
- [31:26] OP
- [25:21] Rs
- [20:16] Rt
- [15:11] Rd
- [10:6] shamt
- [5:0] funct
I-Type
- [31:26] OP
- [25:21] Rs
- [20:16] Rt
- [15:0] Immediate
J-Type
- [31:26] OP
- [25:0] Address Offset
R-Type 指令用于处理从 Reg 中读取两个数的操作,I-Type 指令用于处理一个从 Reg 中读取,另一个为立即数(Immediate)的操作,J-Type 则用于处理跳转指令。
OP & funct
以下是这些指令的 OP 和 funct 表
Instr | op | funct | desc |
---|---|---|---|
addu | 6'b000000 | 6'b100001 | add unsigned |
subu | 6'b000000 | 6'b100011 | sub unsigned |
ori | 6'b001101 | Immediate | or immediate |
lw | 6'b100011 | Immediate | load word |
sw | 6'b101011 | Immediate | save word |
beq | 6'b000100 | Immediate | branch equal |
jal | 6'b000011 | Immediate | jump and link |
不难看出,addu 和 subu 为 R-Type ,jal 为 J-Type ,其余指令则为 I-Type。