计算机组成原理课程设计(桂林电子科技大学)(共24页).doc
精选优质文档-倾情为你奉上 计算机组成原理课程设计说明书题 目: 设计一台嵌入式CISC模型计算机 院 (系): 计算机科学与工程学院 专 业: 网络工程 学生姓名: 唐波 学 号: 指导教师: 陈智勇 一、课设题目:设计一台嵌入式CISC模型计算机(采用定长CPU周期、联合控制方式),并运行能完成一定功能的机器语言程序进行验证,实现方法可从以下4类中任选一个: 连续输入5个有符号整数(8位二进制补码表示,用十六进制数输入),求最小的负数的绝对值并输出显示。 说明:5个有符号数从外部输入; 一定要使用符号标志位(比如说SF),并且要使用为负的时候转移(比如JS)或不为负的时候转移(比如JNS)指令。二CISC模型机系统总体设计三操作控制器的逻辑框图指令寄存器IR操作码微地址寄存器地址译码控制存储器地址转移逻辑状态条件微命令寄存器P字段操作控制字段微命令信号说明:在T4内形成微指令的微地址,并访问控制存储器,在T2的上边沿到来时,将读出的微指令打入微指令寄存器,即图中的微命令寄存器和微地址寄存器。四模型机的指令系统和所有指令的指令格式由此可见,本模型机中的指令系统中共有8条基本指令,下表9列出了每条指令的格式、汇编符号和指令功能。指令助记符指令格式功能15-1211 109 87-0IN1 Rd0101××Rd××××××××(Rd)+1Rd,锁存标志位MOV Rd,im0001××Rdim立即数RdCMP Rs,Rd0011RsRd××××××××Rs,Rd比较,INC Rd0010××Rd××××××××输入设备RdJNS addr0100××××addr若大于,则addrPCJMP addr0110××××addraddrPCOUT1 Rs1001Rs××××××××××(Rs)输出设备MOV1 Rs,Rd1000RsRd××××××××(Rs)RdNOT Rd0111××Rd××××××××Data取反指令格式:(1)I/O指令(单字节)I说明:对Rs和Rd的规定:Rs或Rd选定的寄存器0 0R00 1R11 0R2 1 1R3 五所有机器指令的微程序流程图00PCABUS(I)RD ROMIBUSIRPC+100P(1)MOV1OUT1IN1MOVNOTJMPJNSCMPINC030209080107O60504RsX-XRs锁存CF,ZFRsXRdY锁存CF,ZFRdYY+1Rd锁存CF,ZFIR(I)RdRsLEDRsXXRdIR(A)PCSWRd200000P(2)00000000000000 CF=1ZF=1CF=0ZF=010ROMBUSBUSPC0000设计操作控制器单元(即微程序控制器) (1)设计微指令格式和微指令代码表CISC模型机系统使用的微指令采用全水平型微指令,字长为25位,其中微命令字段为17位,P字段为2位,后继微地址为6位,其格式如下: 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0LOAD LDPC LDAR LDIR LDRi RD_B RS_B S2 S1 S0 ALU_B SW_B LED_B RD_D CS_D RAM_B CS_I ADDR_B P1 P2 后继微地址由微指令格式和微程序流程图编写的微指令代码表如下所示,在微指令的代码表中微命令字段从左边到右代表的微命令信号依次为:LOAD LDPC LDAR LDIR LDRi RD_B RS_B S2 S1 S0 ALU_B SW_B LED_B RD_D CS_D RAM_B CS_I ADDR_B微地址微命令字段P1P2后继微地址00110100100011111101100110001010001111111000021000111010011111110003100001100111111111000410000010001101111101051000101000101111110006010000100011111110000710001111000111111100081000101101011111110009100000000011011111001001000010001111111000 (2)设计地址转移逻辑电路地址转移逻辑电路是根据微程序流程图3-2中的棱形框部分及多个分支微地址,利用微地址寄存器的异步置“1”端,实现微地址的多路转移。由于微地址寄存器中的触发器异步置“1”端低电平有效,与µA4µA0对应的异步置“1”控制信号SE5SE1的逻辑表达式为:(µA5的异步置“1”端SE6实际未使用)SE5= FS·P(2)·T4SE4=I7·P(1)·T4SE3=I6·P(1)·T4SE2=I5·P(1)·T4SE1=I4·P(1)·T4六嵌入式CISC模型计算机的顶层电路图CROM:AA;七汇编代码:MOV R0,00H 功能:将0赋给R0MOV R1,FFH 将FF赋给R1MOV R2,05H 将05赋给R2L0:INC R0 计数加1 CMP R0,R2 R0与R2比较,是否输入五个数JNS L3 是跳转L2输出 IN1 R3 输入一个数到R3CMP R3,R1 R3和R1比较,锁存CF,ZFJNS L2 跳转L2输出JMP L1 跳转L1L1:MOV1 R1,R3 (R3)(R1)JMP L0 跳转L0L2: NOT R1 R1取反INC R1 R1加1OUT1 R1 输出R1 八机器语言源程序地址(十六进制)汇编语言源程序 机器语言源程序 代码00 MOV R0,00H 0001 0000 0000 0000 100001 MOV R1,FFH 0001 0001 1111 1111 11FF02 MOV R2,05H 0001 0010 0000 0101 102503 L0:INC R0 0010 0000 0000 0000 2000 04 CMP R0,R2 0011 1000 0000 0000 3800 05 JNS L3 0100 0000 0000 1100400C 06 IN1 R3 0101 0011 0000 0000 5300 07 CMP R3,R1 0011 1101 0000 0000 3D00 08 JNS L2 0100 0000 0000 1010400A09 JMP L1 0110 0000 0000 0011 60030A L1:MOV1 R1,R3 1000 1101 0000 0000 8D000B JMP L0 0110 0000 0000 0011 60030C L2: NOT R1 0111 0001 0000 0000 71000D INC R1 0010 0001 0000 0000 21000E OUT1 R1 1001 0100 0000 0000 9400九机器语言源程序的功能仿真波形图及结果分析1.MOV R0,00H 2.MOV R1,FFH 3.MOV R2,05H 4.CMP R2,R0 5.IN1 R3(F4存到R3)6MOV1 R3,R1(F4存入R1) 7.IN1 R3(02存到R3) 802是大于F4的正数,不跳到L1存R1,直接跳回L0。9.IN1 R3(F1存到R3)。10F1是小于于F4的负数,跳到L1,MOV1 R3,R1(F1存入R1)11FNOT R1, INC R1(F1取反加1存入R1)。 12。OUT1 R1(输出R1,最终结果是0F)十故障现象和故障分析故障一:在进行仿真的时候,当输入一个正数存进R3之后,执行CMP R3,R1之后,没有执行JNS L0,而是错将正数也存入R1。查看之后发现是ALU里“CMP”运算代码有问题。故障二:计数(R0)一直加,到5时不会跳转输出,检查机器指令发现JNS L2的地址写成了06故障三:,输出结果时,取反都变成FB,检查很久之后发现原本应该对AC里的数取反的,结果弄成了DR的.故障N:汇编程序出错、连线错误、微指令错误、修改器件没有重新编译等。十一.心得体会刚开始去上老师的课时,听得一头雾水,因为发现好多地方自己同不懂。然后我就去看课本,同时问老师一些问题,当看到其他同学也问老师问题时,自己也跑过去凑热闹,因为这样可以了解更多的知识。直到后来才发现,原来除了设计自己的指令外,我们需要写MCOMMAND,写CONTROM来解析我们写的指令,这或许可以算得上一个极简单的CPU模型了吧。就是有了微程序控制器,计算机才认识我们自己设计的指令,才知道当读取到什么指令时该执行什么操作。听得多了,看得多了,就渐渐的明白了一些课设的相关知识,然后画指令流程图,设计指令,写程序完成任务,这些几乎都是水到渠成的工作了,很多都可以依葫芦画瓢来完成。本次课设,由于汇编学的很差,期汇编代码是和班级同学的相同,但是自己重新设计了指令周期流程图,经过调试得出的结果其实只要把最基本的原理搞明白了,后续工作开展是非常快的。但在没明白原理前,千万不要畏惧困难,慢慢的一点一点学习,特别是仿真软件的学习和使用,需要花费相当的时间。只要认真了,就有可能实现。十二.软件清单AA里的MMM:LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY MMM IS PORT( SE:IN STD_LOGIC; CLK:IN STD_LOGIC; D:IN STD_LOGIC; CLR:IN STD_LOGIC; UA:OUT STD_LOGIC );END MMM;ARCHITECTURE A OF MMM ISBEGIN PROCESS(CLR,SE,CLK) BEGIN IF(CLR='0') THEN UA<='0' ELSIF(SE='0')THEN UA<='1' ELSIF(CLK'EVENT AND CLK='1') THEN UA<=D; END IF; END PROCESS;END A;CROM的:ADDRLIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY ADDR IS PORT( I15,I14,I13,I12:IN STD_LOGIC; ZF,CF,T4,P1,P2:IN STD_LOGIC; SE5,SE4,SE3,SE2,SE1,SE0:OUT STD_LOGIC);END ADDR;ARCHITECTURE A OF ADDR ISBEGIN SE5<='1' -预留给JB或JAE指令使用 SE4<=NOT(NOT ZF AND CF)AND P2 AND T4); SE3<=NOT(I15 AND P1 AND T4); SE2<=NOT(I14 AND P1 AND T4); SE1<=NOT(I13 AND P1 AND T4); SE0<=NOT(I12 AND P1 AND T4);END A;LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY F1 IS PORT( UA5,UA4,UA3,UA2,UA1,UA0: IN STD_LOGIC; D:OUT STD_LOGIC_VECTOR(5 DOWNTO 0);END F1;ARCHITECTURE A OF F1 ISBEGIN D(5)<=UA5; D(4)<=UA4; D(3)<=UA3; D(2)<=UA2; D(1)<=UA1; D(0)<=UA0;END A;LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY F2 IS PORT( D:IN STD_LOGIC_VECTOR(5 DOWNTO 0); UA5,UA4,UA3,UA2,UA1,UA0: OUT STD_LOGIC );END F2;ARCHITECTURE A OF F2 ISBEGIN UA5<=D(5); UA4<=D(4); UA3<=D(3); UA2<=D(2); UA1<=D(1); UA0<=D(0);END A;LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY CONTROM ISPORT(ADDR: IN STD_LOGIC_VECTOR(5 DOWNTO 0); UA:OUT STD_LOGIC_VECTOR(5 DOWNTO 0); O:OUT STD_LOGIC_VECTOR(19 DOWNTO 0) );END CONTROM;ARCHITECTURE A OF CONTROM ISSIGNAL DATAOUT: STD_LOGIC_VECTOR(25 DOWNTO 0);BEGIN PROCESS BEGIN CASE ADDR IS WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN "" => DATAOUT<="0000" WHEN OTHERS => DATAOUT<="0000" END CASE; UA(5 DOWNTO 0)<=DATAOUT(5 DOWNTO 0); O(19 DOWNTO 0)<=DATAOUT(25 DOWNTO 6); END PROCESS;END A;LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY F3 IS PORT( D:IN STD_LOGIC_VECTOR(3 DOWNTO 0); UA3,UA2,UA1,UA0: OUT STD_LOGIC );END F3;ARCHITECTURE A OF F3 ISBEGIN UA3<=D(3); UA2<=D(2); UA1<=D(1); UA0<=D(0);END A;LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY MCOMMAND ISPORT( T2,T3,T4:IN STD_LOGIC; D:IN STD_LOGIC_VECTOR(19 DOWNTO 0); LOAD,LDPC,LDAR,LDIR,LDRI,LDPSW,RS_B,S2,S1,S0:OUT STD_LOGIC; ALU_B,SW_B,LED_B,RD_D,CS_D,RAM_B,CS_I,ADDR_B,P1,P2:OUT STD_LOGIC );END MCOMMAND;ARCHITECTURE A OF MCOMMAND ISSIGNAL DATAOUT:STD_LOGIC_VECTOR(19 DOWNTO 0);BEGIN PROCESS(T2) BEGIN IF(T2'EVENT AND T2='1') THEN DATAOUT(19 DOWNTO 0)<=D(19 DOWNTO 0); END IF; LOAD<=DATAOUT(19); LDPC<=DATAOUT(18) AND T4; LDAR<=DATAOUT(17) AND T3; LDIR<=DATAOUT(16) AND T3; LDRI<=DATAOUT(15) AND T4; LDPSW<=DATAOUT(14) AND T4; RS_B<=DATAOUT(13); S2<=DATAOUT(12); S1<=DATAOUT(11); S0<=DATAOUT(10); ALU_B<=DATAOUT(9); SW_B<=DATAOUT(8); LED_B<=DATAOUT(7); RD_D<=NOT(NOT DATAOUT(6) AND (T2 OR T3); CS_D<=NOT(NOT DATAOUT(5) AND T3); RAM_B<=DATAOUT(4); CS_I<=DATAOUT(3); ADDR_B<=DATAOUT(2); P1<=DATAOUT(1); P2<=DATAOUT(0); END PROCESS;END A; Top顶层图的:MUX3功能表输入 输出SW-B CS ID7.0 N17.0 N27.0 EW7.00 X X X X IN7.01 0 X X X N27.01 1 X X X N17.0LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY MUX3 ISPORT(ID:IN STD_LOGIC_VECTOR(7 DOWNTO 0);SW_B,CS:IN STD_LOGIC;N1,N2:IN STD_LOGIC_VECTOR(7 DOWNTO 0);EW:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);END MUX3;ARCHITECTURE A OF MUX3 ISBEGIN PROCESS(SW_B,CS) BEGIN IF(SW_B='0') THEN EW<=ID; ELSIF(CS='0')THEN EW<=N2; ELSEEW<=N1;END IF; END PROCESS;END A;ROM功能CS=1,不选择CS=0,读LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY ROM IS PORT(DOUT:OUT STD_LOGIC_VECTOR(15 DOWNTO 0);ADDR:IN STD_LOGIC_VECTOR(7 DOWNTO 0);CS_I:IN STD_LOGIC);END ROM;ARCHITECTURE A OF ROM ISBEGINDOUT<="00000" WHEN ADDR="" AND CS_I='0' ELSE "11111" WHEN ADDR="" AND CS_I='0' ELSE "00101" WHEN ADDR="" AND CS_I='0' ELSE "00000" WHEN ADDR="" AND CS_I='0' ELSE "00000" WHEN ADDR="" AND CS_I='0' ELSE "01100" WHEN ADDR="" AND CS_I='0' ELSE "00000" WHEN ADDR="" AND CS_I='0' ELSE "00000" WHEN ADDR="" AND CS_I='0' ELSE "01010" WHEN ADDR="" AND CS_I='0' ELSE "00011" WHEN ADDR="" AND CS_I='0' ELSE "00000" WHEN ADDR="" AND CS_I='0' ELSE "00011" WHEN ADDR="" AND CS_I='0' ELSE "00000" WHEN ADDR="" AND CS_I='0' ELSE "00000" WHEN ADDR="" AND CS_I='0' ELSE "00000" WHEN ADDR="" AND CS_I='0' ELSE "00000"END A;LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY COUNTER ISPORT( CLK,CLR: IN STD_LOGIC; T2,T3,T4: OUT STD_LOGIC );END COUNTER;ARCHITECTURE A OF COUNTER ISSIGNAL X:STD_LOGIC_VECTOR(1 DOWNTO 0):="00"BEGIN PROCESS(CLK,CLR) BEGIN IF(CLR='0') THEN T2<='0' T3<='0' T4<='0' X<="00" ELSIF(CLK'EVENT AND CLK='1') THEN X<=X+1; T2<=(NOT X(1)AND X(0); T3<=X(1) AND(NOT X(0); T4<=X(1) AND X(0); END IF; END PROCESS;END A;LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY LS273 ISPORT( D: IN STD_LOGIC_VECTOR(7 DOWNTO 0); CLK: IN STD_LOGIC; Q: OUT STD_LOGIC_VECTOR(7 DOWNTO 0) );END LS273; ARCHITECTURE A OF LS273 ISBEGIN PROCESS(CLK) BEGIN IF(CLK'EVENT AND CLK='1') THEN Q<=D; END IF; END PROCESS;END A;ALU功能表S2 S1 S0 功能0 0 0 ADD,锁存CF,ZF0 1 1 CMP(比较指令)0 1 0 INC(加1指令)1 1 0 NOT(取反指令)1 0 1 MOV1 (Rs) (Rd)LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.all;ENTITY ALU ISPORT( X: IN STD_LOGIC_VECTOR(7 DOWNTO 0); Y: IN STD_LOGIC_VECTOR(7 DOWNTO 0); S2,S1,S0: IN STD_LOGIC; ALUOUT: OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ; CF,ZF: OUT STD_LOGIC );END ALU;ARCHITECTURE A OF ALU ISSIGNAL AA,BB,TEMP:STD_LOGIC_VECTOR(8 DOWNTO 0);SIGNAL TEMP1:STD_LOGIC_VECTOR(7 DOWNTO 0);BEGIN PROCESSBEGIN IF(S2='0' AND S1='0' AND S0='0') THEN-ADD AA<='0'&X; BB<='0'&Y; TEMP<=AA+BB;ALUOUT<=TEMP(7 DOWNTO 0); CF<=TEMP(8); IF (TEMP="" OR TEMP="") THEN ZF<='1' ELSE ZF<='0' END IF;ELSIF(S2='0' AND S1='0' AND S0='1') THEN -CMP(SUB) AA<='0'&X; BB<='0'&Y; TEMP<=AA-BB;ALUOUT<=TEMP(7 DOWNTO 0);TEMP1<=TEMP(7 DOWNTO 0); CF<=TEMP1(7); IF (TEMP1="") THEN ZF<='1' ELSE ZF<='0' END IF; ELSIF(S2='0' AND S1='1' AND S0='0') THEN -INC AA<='0'&Y; TEMP<=AA+1; ALUOUT<=TEMP(7 DOWNTO 0); CF<=TEMP(8); IF (TEMP="") THEN ZF<='1' ELSE ZF<='0' END IF; ELSIF(S2='0' AND S1='1' AND S0='1') THEN -DEC AA<='0'&Y; TEMP<=AA-1; ALUOUT<=TEMP(7 DOWNTO 0); CF<=TEMP(8); IF (TEMP="") THEN ZF<='1' ELSE ZF<='0' END IF; ELSIF(S2='1' AND S1='0' AND S0='0') THEN -NOT TEMP1<=NOT Y; ALUOUT<=TEMP1; ELSIF(S2='1' AND S1='0' AND S0='1') THEN