VHDL-8位CPU设计-包含程序.doc

上传人:xin****828 文档编号:6706244 上传时间:2020-03-02 格式:DOC 页数:16 大小:322KB
返回 下载 相关 举报
VHDL-8位CPU设计-包含程序.doc_第1页
第1页 / 共16页
VHDL-8位CPU设计-包含程序.doc_第2页
第2页 / 共16页
VHDL-8位CPU设计-包含程序.doc_第3页
第3页 / 共16页
点击查看更多>>
资源描述
Computer Organization and ArchitectureCourse DesignThe Experiment Report OfCPUI . PurposeThe purpose of this project is to design a simple CPU (Central Processing Unit). This CPU has basic instruction set, and we will utilize its instruction set to generate a very simple program to verify its performance. For simplicity, we will only consider the relationship among the CPU, registers, memory and instruction set. That is to say we only need consider the following items: Read/Write Registers, Read/Write Memory and Execute the instructions.At least four parts constitute a simple CPU: the control unit, the internal registers, the ALU and instruction set, which are the main aspects of our project design and will be studied.II . Instruction SetSingle-address instruction format is used in our simple CPU design. The instruction word contains two sections: the operation code (opcode), which defines the function of instructions (addition, subtraction, logic operations, etc.); the address part, in most instructions, the address part contains the memory location of the datum to be operated, we called it direct addressing. In some instructions, the address part is the operand, which is called immediate addressing.For simplicity, the size of memory is 256 16 in the computer. The instruction word has 16 bits. The opcode part has 8 bits and address part has 8 bits. The instruction word format can be expressed in Figure 1:OPCODE15.0ADDRESS7.0Figure 1 the instruction formatThe opcode of the relevant instructions are listed in Table 1.In Table 1, the notation x represents the contents of the location x in the memory. For example, the instruction word 00000011101110012 (03B916) means that the CPU adds word at location B916 in memory into the accumulator (ACC); the instruction word 00000101000001112 (050716) means if the sign bit of the ACC (ACC 15) is 0, the CPU will use the address part of the instruction as the address of next instruction, if the sign bit is 1, the CPU will increase the program counter (PC) and use its content as the address of the next instruction.Table 1 List of opcode of the relevant instructionsINSTRUCTIONOPCODECOMMENTSSTORE X01HACCXLOAD X02HXACCADD X03HACC+XACCSUB X04HACC-XACCJMPGZ X05HIF ACC0 THEN XPC ELSE PC+1PCAND X06HACC and XACCOR X07HACC or XACCNOT X08HNot XACCSHIFTR X09HSHIFL ACC to RIGHT 1 bit, Logic ShiftSHIFTL X0AHSHIFT ACC to LEFT 1 bit, Logic ShiftMPY X 0BHACCXACCHALT0CHHALT A PROGRAMA program is designed to test these instructions:Calculate the sum of all integers from 1 to 100.(1), programming with C language:sum=0;temp=100;loop :sum=sum+temp;temp=temp-1;if temp=0 goto loop;end(2), Assume in the RAM_DQ:sum is stored at location A4,temp is stored at location A3,the contents of location A0 is 0,the contents of location A1 is 1,the contents of location A2 is 10010=6416.We can translate the above C language program with the instructions listed in Table 1 into the instruction program as shown in Table 2.Table 2 Example of a program to sum from 1 to 100Program with CProgram withinstructionsContents of RAM_DQ in HEXAddressContentssum=0;LOAD A00002A0STORE A40101A4temp=100LOAD A20202A2STORE A30301A3loop:sum=sum+temp;LOOP:LOAD A40402A4ADD A30503A3STORE A40601A4temp=temp-1;LOAD A30702A3SUB A10804A1STORE A30901A3if temp0 goto loop;JMPGZ LOOP0A0504end;HALT0B0C000CA00000A10001A20064A3A4III. Internal Registers and MemoryMAR (Memory Address Register) MAR contains the memory location of the word to be read from the memory or written into the memory. Here, READ operation is denoted as the CPU reads from memory, and WRITE operation is denoted as the CPU writes to memory. In our design, MAR has 8 bits to access one of 256 addresses of the memory.MBR (Memory Buffer Register)MBR contains the value to be stored in memory or the last value read from memory. MBR is connected to the address lines of the system bus. In our design, MBR has 16 Bits.PC (Program Counter)PC keeps track of the instructions to be used in the program. In our design, PC has 8 bits.IR (Instruction Register)IR contains the opcode part of an instruction. In our design, IR has 8 bits.BR (Buffer Register)BR is used as an input of ALU, it holds other operand for ALU. In our design, BR has16 bits.LPM_RAM_DQLPM_RAM_DQ is a RAM with separate input and output ports. It works as a memory, and its size is 25616. Although its not an internal register of CPU, we need it to simulate and test the performance of CPU.LPM_ROMLPM_ROM is a ROM with one address input port and one data output port, and its size of data is 32bits which contains control signals to execute micro-operations.IV.ALUALU (Arithmetic Logic Unit) is a calculation unit which accomplishes basic arithmetic and logic operations. In our design, some operations must be supported which are listed as follows:Table 3 ALU OperationsALU control signalOperationsExplanations3HADDACCACC+BR4HSUBACCACC- BR6HANDACCACC and BR7HORACCACC or BR8HNOTACCnot ACC9HSHIFTRACCShift ACC to Right 1 bit0AHSHIFTLACCShift ACC to Left 1 bitV. Micro-programmed Control UnitIn the Microprogrammed control, the microprogram consists of some microinstruction and the microprogram is stored in control memory that generates all the control signals required to execute the instruction set correctly. The microinstruction contains some micro-operations which are executed at the same time.Figure 2 shows the key elements of such an implementation.The set of microinstructions is stored in the control memory. The control address register contains the address of the next microinstructions to be read. When a microinstruction is read from the control memory, it is transferred to a control buffer register. The register connects to the control lines emanating from the control unit. Thus, reading a microinstruction from the control memory is the same as executing that microinstruction. The third element shown in the figure is a sequencing unit that loads the control address register and issues a read command.Figure 2 Control Unit Micro-architecture(I)Total control signals for instructions are listed as follows:Table 4 Control signals for the micro-operationsBits in Control MemoryMicro-operationMeaningC0C7/Branch AddressesC8PC0Clear PCC9PCPC+1Increment PCC10PCMBR7.0MBR7.0 to PCC11ACC0Clear ACCC12-C15ALU CONTROLControl operations of ALUC16RRead data from Memory to MBRC17WWrite data to MemoryC18MARMBR7.0MBR7.0 to MAR as addressC19MARPCPC value to MARC20MBRACCACC value to MBRC21IRMBR15.8MBR15.8 to IR as opcodeC22BRMBRCopy MBR to BRC23CARCAR+1Increment CARC24CARC0C7C7C0 to CAR C25CAROPCODE+CARAdd OP to CARC26CAR0Reset CARC27-C31Not use-(II)The contents in rom.mif and the corresponding microprograms are listed as follows:0:00810000; R1, CARCAR+11:00A00000; OPMBR15.8,CARCAR+12:02000000; CARCAR+OP3:01000014; CAR14H4:01000019; CAR19H5:0100001E; CAR1EH6:01000023; CAR23H7:01000041; CAR41H8:01000028; CAR28H9:0100002D; CAR2DHa:01000032; CAR32Hb:01000037; CAR37Hc:0100003C; CAR3CHd:01000046; CAR46He:0100004B; CAR4Hf:00000000; 14:00840000; MARMBR7.0, CARCAR+1 -STORE15:00920200; MBRACC, PCPC+1,W1,CARCAR+116:04080000; CAR017:00000000;18:00000000;19:00840000; MARMBR7.0, CARCAR+1 -LOAD1a:00810A00; PCPC+1,R1,ACC0,CARCAR+11b:00C03000; BRMBR,ACCACC+BR, CARCAR+11c:04080000; CAR01d:00000000;1e:00840000; MARMBR7.0, CARCAR+1 -ADD1f:00810200; PCPC+1,R1,CARCAR+120:00C03000; BRMBR,ACCACC+BR, CARCAR+121:04080000; CAR022:00000000;23:00840000; MARMBR7.0, CARCAR+1 -SUB24:00810200; PCPC+1,R1,CARCAR+125:00C04000; BRMBR,ACCACC-BR, CARCAR+126:04080000; CAR027:00000000;28:00840000; MARMBR7.0, CARCAR+1 -AND29:00810200; PCPC+1,R1,CARCAR+12a:00C06000; BRMBR,ACCACC AND BR,CARCAR+12b:04080000; CAR02c:00000000;2d:00840000; MARMBR7.0, CARCAR+1 -OR2e:00810200; PCPC+1,R1,CARCAR+12f:00C07000; BRMBR,ACCACC OR BR, CARCAR+130:04080000; CAR031:00000000;32:00840000; MARMBR7.0, CARCAR+1 -NOT33:00808200; PCPC+1, ACCNOT ACC,CARCAR+134:04080000; CAR035:00000000;36:00000000;37:00840000; MARMBR7.0, CARCAR+1 -SHIFTR38:08092000; PCPC+1, ACCSHIFT ACC to Right 1 bit,CARCAR+139:04080000; CAR03a:00000000;3b:00000000;3c:00840000; MARMBR7.0, CARCAR+1 -SHIFTL3d:0080A200; PCPC+1, ACCSHIFT ACC to Left 1 bit,CARCAR+13e:04080000; CAR03f:00000000;40:00000000;41:00840000; MARMBR7.0, CARCAR+1 -JMPGEZ42:00805000; CARCAR+1,43:04080000; CAR044:00000000;45:00000000;46:00840000; MARMBR7.0, CARCAR+1 -MPY47:00810200; PCPC+1,R1,CARCAR+148:00C0B000; BRMBR,ACCACC*BR, CARCAR+149:04080000; CAR04a:00000000;4b:0100004B; CAR4BH -HALT4c:00000000;(III)The simulation waveforms of some operates1, load, add, store, halt (22+10)The contents in RAM: 0:022A; Load 2A1:032B; ADD 2B2:012C; Store 2C3:0C00; Halt2a:0016;2b:000A;The content in RAM addressed of 2b is 0020(H).The waveform of the operate:2, load, SUB, store, halt (22-10)The contents in RAM:0:022A; Load 2A1:042B; SUB 2B2:012C; Store 2C3:0C00; Halt2a:0016;2b:000A;The content in RAM addressed of 2c is 000C(H).The waveform of the operate:3, load, mpy, add, store, halt (13*10+22)The contents in RAM:0:022A; Load 2A1:0B2B; MPY 2B2:032C; ADD 2C3:012D; Store 2D4:0C00; Halt2a:000D;2b:000A;2c:0016;The content in RAM addressed of 2d is 0098(H).The waveform of the operate:4, Sum from 1 to 100The contents in RAM are shown in table2.The content in RAM addressed of A4 is 13BA(H).The waveform of the operate:The clock cycle of CAR is 400 ns.From the waveform, it takes 2.314ms to execute the operate. So the number of the executing cycles is 2.134/0.0004=5335.VI. Appendix:(I)The GDF of CPU:(II) The code of the CPU program:1, MBR (Memory Buffer Register)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity MBR isport( clk, reset, MBR_OPc, ACC_MBRc,R,W:in std_logic; ACC_MBR :in std_logic_vector(15 downto 0); RAM_MBR :in std_logic_vector(15 downto 0); MBR_RAM :out std_logic_vector(15 downto 0); MBR_BR :out std_logic_vector(15 downto 0); MBR_OP :out std_logic_vector(7 downto 0); MBR_MAR :out std_logic_vector(7 downto 0); MBR_PC :out std_logic_vector(7 downto 0);end MBR;architecture behave of MBR isbegin process(clk) variable temp:std_logic_vector(15 downto 0); begin if(clkevent and clk=0)then if reset=1 then if ACC_MBRc=1 then temp:=ACC_MBR; end if; if R=1 then MBR_BR=RAM_MBR; end if; if W=1 then MBR_RAM=temp; end if; MBR_MAR=RAM_MBR(7 downto 0); MBR_PC=RAM_MBR(7 downto 0); if MBR_OPc=1 then MBR_OP=RAM_MBR(15 downto 8); end if; else MBR_BR=x0000; MBR_MAR=00000000; MBR_OP=00000000; MBR_PC=00000000; end if; end if; end process;end behave;2, BR (Buffer Register)library ieee;use ieee.std_logic_1164.all;entity BR isport( MBR_BRc:in std_logic; MBR_BR:in std_logic_vector(15 downto 0); BRout:out std_logic_vector(15 downto 0);end BR;architecture behave of BR isbegin process begin if MBR_BRc=1 then BRout=MBR_BR; end if; end process;end behave;3, MAR (Memory Address Register)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity MAR isport( clk,PC_MARc,MBR_MARc:in std_logic; PC,MBR_MAR:in std_logic_vector(7 downto 0); MARout:out std_logic_vector(7 downto 0);end MAR;architecture behave of MAR isbegin process(clk) begin if(clkevent and clk=1)then if PC_MARc=1 then MARout=PC; end if; if MBR_MARc=1 then MARout=MBR_MAR; end if; end if; end process;end behave;4, PC (Program Counter)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity PC isport( clk,PCjmp,PCc1,PCinc,PCc3,reset:in std_logic; CONTRalu :in std_logic_vector(3 downto 0); MBR_PC :in std_logic_vector(7 downto 0); PCout :buffer std_logic_vector(7 downto 0);end PC;architecture behave of PC isbegin process(clk) begin if(clkevent and clk=0)then if reset=1 then if CONTRalu=0101 then if PCjmp=1 then PCout=MBR_PC; elsif PCjmp=0 then PCout=PCout+1; end if; end if; if PCc1=1 then PCout=00000000; end if; if PCinc=1 then PCout=PCout+1; end if; if PCc3=1 then PCout=MBR_PC; end if; else PCout=00000000; end if; end if; end process;end behave;5, IR (Instruction Register)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity IR isport( opcode :in std_logic_vector(7 downto 0); IRout :out std_logic_vector(7 downto 0);end IR;architecture behave of IR isbegin IRout=opcode;end behave;6, CAR (Control Address Register)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity CAR isport( clk,reset :in std_logic; CARc :in std_logic_vector(3 downto 0); CAR,OP :in std_logic_vector(7 downto 0); CARout:buffer std_logic_vector(7 downto 0);end CAR;architecture behave of CAR isbegin process(clk) begin if(clkevent and clk=1)then if reset=1 then if CARc=1000 then CARout=00000000; end if; if CARc=0100 then CARout=OP+CARout; end if; if CARc=0010 then CARout=CAR; end if; if CARc=0001 then CARout=CARout+1; end if; else CARout=00000000; end if; end if; end process;end behave;7, CONTRALR (Control Buffer Register)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity CONTROLR isport( control :in std_logic_vector(31 downto 0); R,W, RW, PCc1,PCinc,PCc3:out std_logic; ACCclear,MBR_MARc,PC_MARc:out std_logic; ACC_MBRc,MBR_OPc,MBR_BRc:out std_logic; CONTRout:out std_logic_vector(3 downto 0); CARc :out std_logic_vector(3 downto 0); CAR :out std_logic_vector(7 downto 0);end CONTROLR;architecture behave of CONTROLR isbegin process begin CAR=control(7 downto 0); PCc1=control(8); PCinc=control(9); PCc3=control(10); ACCclear=control(11); CONTRout=control(15 downto 12); R=control(16); W=control(17); MBR_MARc=control(18); PC_MARc=control(19); ACC_MBRc=control(20); MBR_OPc=control(21); MBR_BRc=control(22); CARc=control(26 downto 23); RW=control(17);end process;end behave;8, ALU (Arithmetic Logic Unit)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity ALU isport( clk,reset,ACCclear:in std_logic; aluCONTR :in std_logic_vector(3 downto 0); BR :in std_logic_vector(15 downto 0); PCjmp :out std_logic; ACC :buffer std_logic_vector(15 downto 0);end ALU;architecture behave of ALU isbegin process(clk) begin if(clkevent and clk=0)then if reset=0 then ACC=x0000; else if ACCclear=1 then ACC=x0000; end if; if aluCONTR=0011 then ACC=BR+ACC; end if; -ADD if aluCONTR=0100 then ACC=ACC-BR; end if; -SUB if aluCONTR=0110 then ACC=ACC and BR; end if; -AND if aluCONTR=0111 then ACC=ACC or BR; end if; -OR if aluCONTR=1000 then ACC=not ACC; end if; -NOT if aluCONTR=1001 then -SRR ACC(14 downto 0)=ACC(15 downto 1); ACC(15)=0; end if; if aluCONTR=1010 then -SRL ACC(15 downto 1)=ACC(14 downto 0); ACC(0)=0; end if; if aluCONTR=1011 then ACC0 then PCjmp=1; else PCjmp=0; end if; end process;end behave;
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 图纸专区 > 中学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!