1、格式2:立即数寻址方式 I格式3:无操作数寻址方式格式4:直接寻址方式 Addr内存(2的11次方)四模型机的指令系统CPU的指令集:操作码OPIR(15.12)指令格式指 令 的 助 记 符指 令 的 内 容000003Idle无操作 PC=PC+1000012Load DataR0 I 立即数操作000101Move Rx RyRx (Ry) PC=PC+100011Add Rx RyRx (Rx)+(Ry) PC=PC+100100Sub Rx RyRx (Rx)-(Ry) PC=PC+100101AND Rx RyRx (Rx) AND(Ry) PC=PC+100110OR Rx Ry
2、Rx (Rx) OR (Ry) PC=PC+100111XOR Rx RyRx (Rx) XOR (Ry) PC=PC+101000NAND Rx RyRx (Rx)NAND(Ry) PC=PC+101001NOT Rx Rx NOT (Rx) PC=PC+101010 1SHR Rx Ry逻辑循环右移PC=PC+101011SHL Rx Ry 逻辑循环左移PC=PC+1 01100 SWAP Rx RyA (Ry) Ry (Rx) Rx (A) PC=PC+1 01101 4JMP AddrPC Addr PC=PC+1 01110JZ AddrIf (R0)=0 then PC Addr
3、else PC=PC+1 01111READR0 (Addr) PC=PC+1 10000WRITEAddr (R0) PC=PC+1 10001 3STOP无操作 PC保持不变五处理器的状态跳转操作过程:(一)、模型机每一状态下的操作及状态跳转当前状态执行操作次态与读下一条指令的有关的操作St_0取指令IR(15.0) M_data_in(15.0)St_1Write-Read 0 PC=PC+1IF OP=Load THENR0 ”000000000000”|IR(10.7)MAR PCIF(OP=Stop)THENELSE St_2END IFIF OP=Move THEN Rx (Ry
4、)IF OP= Shr THEN Rx (Ry) 逻辑循环右移IF OP= Shl THEN Rx (Ry) 逻辑循环左移IF OP= Add THEN A (Ry)IF OP= Sub THEN A (Ry)IF OP=NAND THEN A (Ry)IF OP=OR THEN A (Ry)IF OP= AND THEN A (Ry)IF OP=NOT THEN A (Ry)IF OP= XOR THEN A (Ry)IF OP= Swap THEN A (Ry)IF OP=Stop THEN NULLIF OP=Idle THEN NULLIF OP=Jmp THEN NULLIF OP=
5、Jz THEN NULLIF OP=Read THEN NULLIF OP=Write THEN NULLSt_2IF OP= Load OR OP=Move OR OP=Shr OR OP=Shl OR OP=Idle THEN NULLWrite-Read 0IF OP= Add THEN Rx (Rx)+AIF OP= Sub THEN Rx (Rx)-AIF OP= AND THEN Rx (Rx)ANDAIF OP= NOT THEN Rx (Rx) NOT AIF OP= NAND THEN Rx (Rx)NANDAIF OP= OR THEN Rx (Rx)ORAIF OP= X
6、OR THEN Rx (Rx) XORAIF OP= Swap THEN Ry (Rx)St_3IF (OP= Jmp OR OP=Jz) THENNULLIF( OP=ReadOROP=Write ) THEN NULL IF OP= Swap THEN Ry (Rx)IF OPE= Read OR OPE= Write OR OPE=Jump OR OPE=Jz) THEN IR Data_in St_4PC:=PC+1;IF OP= Jz THENIF (R0)=0 THEN(PC IR(10.0) MAR IR(10.0)ELSE MAR PCSt_5IF OP= Jmp THENIF
7、 OP= Read THEN MAR IR(10.0)IF OP= Write THEN MAR IR(10.0) MDA R0IF(OPE=Jump)OR(OPE=Jz)St_0;MAR PC;IF(OPE=Read)St_6;St_6IF OP=ReadTHEN R0=M_data_in;Write-Read 16. CPU的代码module cpu(reset, clock, Write_Read, M_address, M_data_in, M_data_out, overflow); input reset; input clock; output Write_Read; outpu
8、t 10:0 M_address; input 15:0 M_data_in; output 15:0 M_data_out; output overflow; reg overflow; reg 15:0 IR;0 MDR; reg 10:0 MAR; reg 2:0 status; parameter 4:0 Idle=5d0, load=5d1, move=5d2, addp=5d3, subp=5d4, andp=5d5, orp=5d6, xorp=5d7, nandp=5d8, notp=5d9, shrp=5d10, shlp=5d11, swap=5d12, jmp=5d13,
9、 jz=5d14, read=5d15, write=5d16, stop=5d17; always (negedge reset or negedge clock ) begin: status_change if (reset = 1b0) status = 0; else case (status) 0 := 1; 1 : if (IR15:11 = stop) else= 2; 2 : case (IR15:11) swap, jmp, jz, read, write,nandp,notp:= 3; default : endcase 3 :11 = swap)= 4; 4 := 5;
10、 5 : read, write := 6; 6 : status=0; end always (negedge reset or negedge clock) seq0 PC;0 R0;0 R1;0 R2;0 R3;0 A; reg 16:0 temp; begin IR = 161b0; PC = 111 R0 = 161 R1 = 161 R2 = 161 R3 = 161 A = 161 MAR = 111 MDR overflow = 1b0;= M_data_in ; PC = PC + 1b1;= PC; load : R0 = 121b0, IR10:7; move : cas
11、e (IR10:7) 4b0001 : R0 = R1;b0010 : R0 = R2;b0011 : R0 = R3;b0100 : R1 = R0;b0110 : R1 = R2;b0111 : R1 = R3;b1000 : R2 = R0;b1001 : R2 = R1;b1011 : R2 = R3;b1100 : R3 = R0;b1101 : R3 = R1;b1110 : R3 = R2; ; shrp :9) 2b00 : R0 = 1b0, R015:1;b01 : R1 = 1b0, R115:b10 : R2 = 1b0, R215: R3 = 1b0, R315: s
12、hlp : R0 = R014:0, 1b0; R1 = R114: R2 = R214: R3 = R314: addp, subp, andp, orp, nandp,notp,xorp, swap : case (IR8: A = R0; A = R1; A = R2; A = R3; addp : temp = (R015, R015:0) + (A15, A15:0); R0 = temp15:0;= temp16 temp15; temp = (R115, R115: R1 = temp15: temp = (R215, R215: R2 = temp15: temp = (R31
13、5, R315: R3 = temp15: subp :0) + (A15, A15:0) + 1 temp = (R17, R115: andp : R0 = R0 & A; R1 = R1 & R2 = R2 & R3 = R3 & orp : R0 = R0 | A; R1 = R1 | A; R2 = R2 | A; R3 = R3 | A; xorp : R0 = R0 A; R1 = R1 A; R2 = R2 A; R3 = R3 A; nandp : R0=(R0 & A); R1=(R1 & R2=(R2 &b11 : R3=(R3 & notp : R0= A; R1= A
14、; R2= A; R3= A; swap : R0 = A; R1 = A; R2 = A; R3 = A; jmp : PC = IR10:= IR10: jz : if (R0 = 16b0000000000000000) read : write := R0; R0 = M_data_in; assign M_address = MAR; assign M_data_out = MDR; assign Write_Read = (reset = 1b1 & status = 5 & IR15:11 = write) ? 1b1 :endmodule七 模型机在Quartus II环境下的
15、应用:步骤:1.建立工程:工程名cpu 。2.编写cpu的verilog代码,将其添加到工程,仿真保存。3.再建立computer文件,链接虚拟电路。4.建立内存数据的mif2文件。5.建立computer的Block1进行编译。6.对computer进行功能模拟。7.调出并分析仿真波形。八仿真波形:九课程设计的总结:因为这次课程设计时间和期末考试有一些冲突,所以要分出一些精力复习其他科目,以至于最后不得不在学姐的程序基础上进行修改才得以完成本次课设。总体来说对自己不是很满意吧,考试要复习虽然是原因但不能作为借口,因为有些同学还是凭借自己的能力完成了课设,可以说要成为一个合格的IC从业者我还有很长的路要走。但是这次课设也不是完全的没有意义,虽然结果不尽人意,但是从中也学到了很多东西,看到了自己的不足,在今后的学习中我会努力完善自己,争取下次更好!
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1