参考计组实验测试指令 - 简书,添加了一些细节。
1.添加 bne指令
修改 ctrl.v
![](https://upload-images.jianshu.io/upload_images/16981913-5dbd096f0c9701ee.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-10425525cb619ab1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-a041c7b2969f149f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
之后修改mipstestloopjal_sim.asm,mars dump 为 bnetest.dat
![](https://upload-images.jianshu.io/upload_images/16981913-e8a8b93c24036842.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
修改sccomp_tb
![](https://upload-images.jianshu.io/upload_images/16981913-cbad5aeeaa81c498.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
modelsim编译,模拟。信号添加sccomp_tb: u_ctrl -> i_bne ,npc, pc
![](https://upload-images.jianshu.io/upload_images/16981913-d9f5d06360e536a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
可见i_bne控制信号为1时,npc变为44。添加bne成功
2.添加jr指令
先看其格式。
![](https://upload-images.jianshu.io/upload_images/16981913-4bbe8a82e2690d2b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
R型指令。
故在ctrl.v如下修改。
![](https://upload-images.jianshu.io/upload_images/16981913-2c5fe78b0389a97d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
ctrl.v又两处修改
![](https://upload-images.jianshu.io/upload_images/16981913-1c36611a856be759.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后在NPC.v修改。注意添加参数和input
![](https://upload-images.jianshu.io/upload_images/16981913-8a08890a5cf330b6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-ff96ae7973e8ccfb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-866ab12a6d89c258.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
=RD1的原因可见sccpu.v
![](https://upload-images.jianshu.io/upload_images/16981913-0c68014e7778e171.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
在ctrl_encode_def 定义NPC_JR
![](https://upload-images.jianshu.io/upload_images/16981913-6847dac83444bf6e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
在sccpu.v添加参数 .RD1
![](https://upload-images.jianshu.io/upload_images/16981913-45af771054a650c1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后写测试程序
$ra先赋值为4.这样应该会不断循环。
导出测试
![](https://upload-images.jianshu.io/upload_images/16981913-d997ac74862395a2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
勿忘修改sccomp_tb
![](https://upload-images.jianshu.io/upload_images/16981913-c09ffb380511f73a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
波形图可见PC从1c变到设定的4。添加成功
![](https://upload-images.jianshu.io/upload_images/16981913-404e6418b2ea828b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3.添加JALR
![](https://upload-images.jianshu.io/upload_images/16981913-08a94bdd969f7be7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
ctrl.v
![](https://upload-images.jianshu.io/upload_images/16981913-7ba1c2acb354d1d0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-40beca4555fa613c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-9019971f473893cb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-ebe93ad82168bf01.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-d01ad6957270ad42.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
无条件跳转到由寄存器rs指定的指令,并将下一条指令的地址保存到寄存器$ra中
测试代码
![](https://upload-images.jianshu.io/upload_images/16981913-92de8307a49f9a25.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
可见从14跳到4,
![](https://upload-images.jianshu.io/upload_images/16981913-4de2ac4c2ac1ab67.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
并且$ra 记录 18
![](https://upload-images.jianshu.io/upload_images/16981913-24c485ee6d7a1a57.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4.添加NOR指令
![](https://upload-images.jianshu.io/upload_images/16981913-b8f19f5806ad454c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-9ace6fa3d1d63dda.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-1e5cb7be9564bb19.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
在alu.v中
![](https://upload-images.jianshu.io/upload_images/16981913-868a274fbc0b8237.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
测试代码
![](https://upload-images.jianshu.io/upload_images/16981913-fbb5da85f77b339f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
波形:
![](https://upload-images.jianshu.io/upload_images/16981913-98be662a8dd70fdd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
寄存器:
![](https://upload-images.jianshu.io/upload_images/16981913-08b671d96f59f09d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
5.添加sll & sra & srl指令
注意这里做了扩展
![](https://upload-images.jianshu.io/upload_images/16981913-c13aad390bd33333.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
注意同时修改了input ALUOp的宽度
![](https://upload-images.jianshu.io/upload_images/16981913-25665beb495f5476.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
然后在ctrl.v中
写寄存器
注意只改了RegWrite,下面的RD没改
![](https://upload-images.jianshu.io/upload_images/16981913-74f0de51ac5b4fd8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-533c3c401a84b570.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
添加输出
![](https://upload-images.jianshu.io/upload_images/16981913-542b75683ff022bd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-27211c5b92a078a2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-53118d01a29dcb77.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-ae4deece20faf04a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
在sccpu.v中
![](https://upload-images.jianshu.io/upload_images/16981913-dbd721757ee67649.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-f84c3a5eb73ef8fd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-734380ae17bca740.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-c1c4f80389d81999.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-a9d1d13df832b490.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
测试代码:
![](https://upload-images.jianshu.io/upload_images/16981913-a0ddfe0bf85983bb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
波形:可以看到ALUop对应 sll,srl,sra的1000,1001,1010
![](https://upload-images.jianshu.io/upload_images/16981913-36c83ce1a14c9935.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
寄存器值:
![](https://upload-images.jianshu.io/upload_images/16981913-ce098e43bf0d3718.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
6.sllv和srlv
这里sllv使用的是rs低五位 自己动手写CPU之第五阶段(3)——MIPS指令集中的逻辑、移位与空指令 - yxwkaifa - 博客园
sllv $t1,$t2,$t3。
则t1值为t2左移t3的低五位
但是这里不太懂,没搞明白是怎么实现的逻辑左右移,位数可变
这里犯了一次错误。复制粘贴后忘了改数字了
![](https://upload-images.jianshu.io/upload_images/16981913-08888d4a65cdb766.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-ec6fc780a2faed0b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-e2efe7ae9fb78945.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-c1ebcc6c92c4c207.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-22e0c2ce42cd9f63.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-c28a37dc182bc9e9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
测试代码:
![](https://upload-images.jianshu.io/upload_images/16981913-f017afdd9492ce83.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
波形:
![](https://upload-images.jianshu.io/upload_images/16981913-49ed414e8c2c7f6a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
寄存器变化
![](https://upload-images.jianshu.io/upload_images/16981913-1d3bdcb0d238fca1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
7.stli指令
小于则置一
![](https://upload-images.jianshu.io/upload_images/16981913-01af07481de4ea97.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-8fac3a3ae75f1f50.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-b2cd1ec2ef18715e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-88dc35707b5d8b87.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
测试代码:
![](https://upload-images.jianshu.io/upload_images/16981913-c09df020b30c6029.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
波形:
![](https://upload-images.jianshu.io/upload_images/16981913-3d2a37c059e2da79.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
寄存器值:
![](https://upload-images.jianshu.io/upload_images/16981913-6ce050c3b132dc5b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
8.lui指令
取高十六位
![](https://upload-images.jianshu.io/upload_images/16981913-494776578dedf2e7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-26c3e270296995bd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-24f32513626af6f1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-b30a954d45a3d004.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-54085d846b315306.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-69054f222b15aad4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-d7aeb0d23327c22e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
测试代码:
![](https://upload-images.jianshu.io/upload_images/16981913-ce81a49adf063fa3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
波形图:
![](https://upload-images.jianshu.io/upload_images/16981913-db844baae5f45382.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
寄存器值:
![](https://upload-images.jianshu.io/upload_images/16981913-ff222398404d4519.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
9.andi指令
![](https://upload-images.jianshu.io/upload_images/16981913-8b71e91047921c51.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-186018558401bd94.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
别忘了RT
![](https://upload-images.jianshu.io/upload_images/16981913-f3bb44896b7a9ff4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/16981913-04e0dd57865556e9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
aluop同and
![](https://upload-images.jianshu.io/upload_images/16981913-0af7eb50474c60a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
测试代码:
![](https://upload-images.jianshu.io/upload_images/16981913-4c0a4f8a2517fb0d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
波形图:
![](https://upload-images.jianshu.io/upload_images/16981913-787cf1763dbe4f38.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
寄存器:
![](https://upload-images.jianshu.io/upload_images/16981913-fd17a3abc06ccaa3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
以上。nice!
学号后八位排序
01510029
lui 0x0151
ori 0x0029
![](https://upload-images.jianshu.io/upload_images/16981913-5aed719b8f9539df.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
记得改sccomp_tb
![](https://upload-images.jianshu.io/upload_images/16981913-75cf4af7f3db0d1d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
跑完看result.txt
![](https://upload-images.jianshu.io/upload_images/16981913-67fea67c46ac1768.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
大概是完成了排序。