logisim实验 中国地质大学信息工程学院.doc_第1页
logisim实验 中国地质大学信息工程学院.doc_第2页
logisim实验 中国地质大学信息工程学院.doc_第3页
logisim实验 中国地质大学信息工程学院.doc_第4页
logisim实验 中国地质大学信息工程学院.doc_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Logisim实验Logisim实验中国地质大学信息工程学院2010-3-26修订历史记录日期版本号修改说明修改人核准人2009-4-2初稿陈亮2009-4-20增加fsm部分陈亮2010-4-27修改fsm部分陈亮2011-3-26补充部分中文缺失的地方,增加中文翻译陈亮2011-3-31补充子电路和分解器的说明陈亮2012-10-21删减部分实验(触发器)陈亮2013-9-21修改部分ALU的内容(不自己做这个部件)陈亮目 录1熟悉环境41.1基本功能:41.2练习二(ToolBar主要功能)41.3练习子电路51.4练习分解器Splitter51.5练习(传说中的选择器啊)51.6练习61.7练习61.8练习62FSM62.1基础:根据真值表设计电路62.2看电路,分析功能72.3看功能,分析电路(分析伯克利实验八的第一个实验的电路)82.4伯克利实验十的Part (A): Advanced Logisim的Exercise A.1: Storing State83ALU114CPU(2次实验课,伯克利prj3)111 熟悉环境学习使用logisim,熟悉基本功能。1.1 基本功能: 学会使用toolbar上的功能。 学会增加子电路,并能够将子电路放到main电路中或者其他电路中使用 学会使用时钟 学会使用splitter,理解带宽的含义。这部分需要实现一个8位带宽的输入,其中2位输入到一个与门,中间3位输入到一个3输入的或门,剩下三位输入到其他已有的门电路。1.2 练习二(ToolBar主要功能)我们将通过创建一个非常简单的电路来感受一下如何放置门和电线。1、 首先,单击“AND gate” 按钮。这时鼠标附近会出现一个与门的图标,在主电路图窗口任意位置单击鼠标以放置与门。2、 单击“Input Pin” 按钮。在你的与门左侧放置两个输入(input pin)。3、 单击“Onput Pin” 按钮。在你的与门右侧放置一个输出(output pin)。这时你的电路图看上去可能如下图所示:4、 单击“Wire tool”按钮。单击并拖动它,以便将输入端和与门的左边相连。如果你只画垂直电线和水平电线的话,这一步可以分成几步。首先画一条水平电线,放开鼠标,单击并拖动电线的末端画一条垂直电线。你可以把电线连接到与门左边的任意一条腿上。重复这一过程,把与门的输出和LED相连。这时你的电路图看上去可能如下图所示:5、 最后,单击“Poke”按钮,试着单击电路图中的输入,看看会发生什么。这和你想象中的与门的功能相符么?1.3 练习子电路正如C程序可以包含帮助函数一样,一个电路图中也可以含有子电路。在这部分中,我们会创建几个子电路,并示范一下他们的使用。1、 新建一个电路图(FileNew)。2、 新建一个子电路(ProjectAdd Circuit),并命名为NAND。3、 在新电路图窗口中,你可以看见你刚创建的含有两个输入一个输出NAND电路。4、 在屏幕左侧电路选择板中双击“main”以返回主电路图。这时,最初的空白电路图会显示出来,而NAND电路图则被保存。5、 单击列表中的“NAND”,告诉Logisim你想吧“NAND”电路添加到主电路中。6、 试着把“NAND”电路放到主电路图中。如果你正确地做到了,你会看到一个左边含两个输入右边含一个输出的门。试着把输入输出相连,看看它是否和想象中一样工作。7、 重复这些步骤,创建其他几个子电路:NOR,XOR,2 to 1 MUX,和 4 to 1 MUX。除了AND,OR和NOT外,不要使用其他内置门。但是,一旦你创建了一个子电路,你可以使用它来创建其他电路。提示:不熟练者可以查看讲义学习如何创建。你可能需要使用一些你定制的电路来设计其他电路。1.4 练习分解器Splitter它是你这次课上需要使用的最基本的工具之一。为了示范如何使用它,你需要创建一个当最高有效位和最低有效位为1时输出1的电路。1、 创建一个名为“Exer2”的子电路。2、 在该电路中添加一个8位输入。3、 在该电路中添加一个1位输入。4、 选择“Splitter”电路,这个电路可以将一根电线分解成几根小电线。5、 在放置“Splitter”电路前,将“Bit Width In”属性改为8,“Fan Out”属性改为3。这时如果将鼠标移到电路图上,光标看上去就像6、 现在,选择哪些位输出到输入的哪一部分。最低有效位为第0位,最高有效位为第7位。改变第1、2、6位输出到输入1。或者,选择“None”,使得第1、2、6位不输出到任一个输入。7、 配置完分解器后就可以把它放置在电路中。再添加一个与门,该电路就完成了。1.5 选择器(可不做)实现一个二路的复用器的子电路。问题:如果信号是一位,而备选的两个输入时32bit,电路怎么做?1.6 练习锁存器(可不做)实现如上子电路。1.7 练习触发器(可不做)实现一个一位的触发器,注意要用时钟。用logisim的时钟实验一下结果,看看Q是否存储值。用这个子电路实现一个32位的寄存器。1.8 练习(可不做)实现一个3-8译码器。2 FSM2.1 基础:根据真值表设计电路上课时,你只是看到了真值表。在这次实验中,通过Logisim,你有足够的工具来实现真值表。假定真值表如下图所示,完成以下任务。in1in0|out1out000|0101|1010|1111|001、 从上面的真值表中推导出out1和out0的规范的SOP布尔表达式。2、 根据布尔代数中的公式简化布尔表达式(看讲义或者google来复习这部分内容)。得到最简式后,你可以检查一下该等式是否满足众所周知的那些门的模式。3、 在Logisim的主电路图中实现该最简式。可以随意使用你之前设计的那些子电路。务必使用“Text” 工具来注记你的输入输出。选择“Text” 工具工具,在电路图上单击,并输入文本即可。如果输错了,你可以通过selection 工具来选中文本对象,编辑位于属性电路浏览器下侧的属性列表中的“Text”属性。2.2 看电路,分析功能下面的FSM电路,假设初始状态Register 1 =1; register 2=0 理解下面fsm的功能,绘出波形图(参考ppt) 写出前5个周期两个寄存器的值2.3 看功能,分析电路(分析伯克利实验八的第一个实验的电路, 可不做)Consider the design of a finite state machine (FSM) with two 1-bit inputs (clk and CE), and one 2-bit output (X). clk is the clock signal and CE is the count enable signal. While CE=1, the FSM behaves as a binary counter, i.e. its output cycles through the pattern 00, 01, 10 11, 00, moving from one output value to the next on each positive edge of clk. If CE = 0 the output value remains unchanged.Note that FSM has no reset input signal. You can assume that it starts up in any legal state.Sketch the state transition diagram that represents the behavior of this FSM in the style of the lecture notes.考虑设计一个FSM,有2个1位的输入(clk和CE),还有一个2位的输出(X)。clk是时钟信号,CE是“计数使能”信号。当CE=1的时候,FSM的行为就是一个二进制计数器,它的输出一直就是按照00,01,10,11,00状态进行变化,在每个上升沿时钟将状态转换到下一状态。当CE=0的时候,输出值不变。注意FSM没有复位信号,你可以以任何合法的状态开始。根据上面描述,绘制状态转移图分析FSM,并考虑一下实现的问题(只考虑,不实现)。2.4 伯克利实验十的Part (A): Advanced Logisim的Exercise A.1: Storing State(可以不做)以下是网络上下载的A.1Lets implement the circuit you worked on in Lab 8. The difference between this circuit and the circuits youve built for lab so far is that you need some registers. The following will show you how to add registers to your circuit. 我们现在开始考虑实现2.1和2.2中的那个FSM,这2个电路和我们以前实现的电路最大的区别在于现在我们需要用到寄存器。(即现在的电路不再是单纯的组合逻辑电路)。下面的提示可以告诉你如何在自己的电路中使用软件内置的寄存器。1. Create a new subcircuit (Project-Add Circuit). Name this new subcircuit, Fib8. 创建一个新的子电路,假设名字叫fib82. Load in the Arithmetic Library (Go to Project-Load Library-Built in Library and select Arithmetic). This library contains elements that will perform basic mathematical operations. When you load a library, the circuit browser at left will have a new Arithmetic folder. 菜单“Project”-“Load Library”-“Built In Library”,选择“Arithmetic”,这个库包含一些基本的算术操作电路。当你load一个库的时候,左边的电路列表就会显示出一个“Arithmetic”文件夹。其他的你自己试试看?3. Select the adder subcircuit from the Arithmetic library and place the adder into your Fib8 subcircuit选择Arithmetic中的一个加法器子电路.,将它放在Fib8电路中4. Load in the Memory Library (Go to Project-Load Library-Built in Library and select Memory). This library contains memory elements used to keep state in a circuit. A new Memory folder will appear in the circuit browser. 按照上面类似的方法加载“Memory”库,这个库包含一些存储电路。加载成功后,你在左边列表中会看到“Memory”文件夹。5. Select the register from the Memory folder and place two registers into your subcircuit. Below is an image diagraming the parts of a register. 从“Memory”库中选择寄存器,增加两个寄存器到我们的子电路中来。寄存器应该是下面这个样子。注意reset和时钟很近,别弄混了。6. Connect a clock to your register. You can find the clock circuit element in the Base folder in the circuit browser. 为寄存器连接上时钟。时钟电路在“base”节点下寻找,你懂的。7. Connect the two registers and adder together based on the diagram in Lab 8. 两个寄存器和加法器连接起来,实现2.1和2.2的电路。You may notice that when you connect the adder to a register, you will get a Incompatible widths error. This means that your wire is trying to connect two pins together with different bit widths. If you click on one the adder with the Selection tool, you will notice that in the box below circuit browser will have a field called Data Bit Width. This field controls the number of bits the the adder will add. Change this field to 8 and the Incompatible widths error should now go away. In general, the box below the circuit browser will list the properties of a given circuit element. Other circuit elements will have other properties. 你可能已经注意到当你连接加法器到寄存器的时候,可能遇到“Incompatible widths”错误(请回顾试验1的1.1的)。在logisim软件中,连线两端的带宽必须是相同的8. Add three output pins to your circuit so that you may monitor what comes out of the adder and both registers. Thus, by the end, your circuit should look like as follows: 增加三个输出到你的电路,检测加法器和寄存器的值。最后,你的电路可能做成如下这个样子(这是2.2的电路)Now lets see if you built your circuit correctly. 好,我们现在可以测试一下你的电路是否正确。如果正确,你也可以来实现以下2.2的FSM的电路。电路有了时钟后,大家是不是不知道如何测试了呢?下面这段步骤,是告诉你如何使用你的子电路,并用软件功能模拟时钟,来检测电路实现的,大家自己看看。1. Go back to the main subcircuit by double clicking on main in the circuit browser. 2. Change the Facing property to another direction. Any circuit with the Facing property can be rotated to accomodate wires as you need them. This will definately be useful when you do your project. 3. Place your Fib8 subcircuit into the main subcircuit. 4. Select the Fib8 subcircuit you just placed into main. 5. Connect output pins to the Fib8 subcircuit. Output pins are ordered top to bottom, left to right. Thus, if you followed the schematic above, then the top pin on the right side outputs the value one of the top register, the middle pin is the output of adder, and the bottom pin is the output of the bottom register. 6. Right click on your Fib8 subcircuit, and select View Fib8. This is the ONLY method to preserving state. Double-clicking on the circuit at the circuit browser at left makes logisim think you want to edit the circuit instead of just checking what state the circuit has. Note: You can use Simulate-Go In To State-*Circuit Name*, but that allows you go into the first circuit of that type. If you placed two Fib8 circuits down, it only takes you to the first Fib8 circuit to put down. 7. Initialize the register values to 1. You can do this by first, click on the register value with the poke tool. Then, type the hex value in. 8. To return to the main circuit while preserving state, go to Simulate-Go Out To State-main. Alternatively, you can hold Control key and press Up-Arrow. 9. Now start running your circuit by going to Simulate-Ticks Enabled. Your circuit should now be outputting the fibonachi numbers in binary form. 10. If you want to run your circuit faster, you can change the tick frequency in Simulate-Tick Frequency. 3 ALU实现hw5对应的8位ALU,可以不实现溢出。注意参考附录B中相关章节。要求实现加、减、或,判等 四种操作。说明:为了支持第四部分的内容,仅仅要求实现add、sub、or,要求能够支持equal信号输出4 CPU(2次实验课,伯克利prj3)为了考虑大家体力有限,我们不实现32位的CPU。(也可以参考/cs61c/sp11/projects/04/)实现prj3对应的8位CPU。这是体力活和脑力活的结合体,体会一下一个能够自动绘制电路软件的必要性吧:)4.1 指令设计一共支持7个指令:lw,sw,add,sub,ori,beq,jmp留给寄存器的位数只有1位,所以只有2个通用寄存器不支持移位操作。I类型指令中立即数位数为3,J类型指令地址5位具体指令编码如下指令OpcodeRsRtRdFunc76543210Add00000Sub00001指令OpcodeRsRtIMM/AddrOri001Lw010Sw011Beq100指令OpcodeTarget AddrJmp1014.2 设计2个8位寄存器的寄存器堆因为是2个寄存器(如果是4个寄存器,就需要2个bit的寄存器位,这样指令位很难控制在8位以下,难度会大大增大,所以还是2个寄存器这么奇葩的好),所以这个寄存器堆的端口号都是1位,2个一位的读端口,1个1位的写端口,1位的写使能信号。另外,因为是状态单元,需要一个时钟。输出是两个,2个8位的读数据情况。上图的dq触发器是直接使用的自带的子电路。看一看,能理解这个电路吗。这个电路,读端口1对应读数据1,读端口2对应读数据2;写端口和写数据共同决定改变哪个寄存器的值。下面做一个实验:上面这个例子是使用刚才制作的寄存器堆得测试电路,可以按ctrl+T来模拟时钟,可以看到,数据可以写入对应的端口,并显示在读数据端口。至此,一个包含2个8位寄存器的寄存器堆就完成了。4.3 支持add、sub、or的ALU(加法器可以先用现成的组件,而不自己实现;当然自己实现是最好的)上图用一种很直观也很粗暴的方法实现了ALU。既然能实现3个功能:add、sub、or,那么就用加法器、减法器、或门电路直接运算,然后用一个选择器选择,因为是3选1,所以信号是2位。(选择器也是选择的系统自带的电路)特殊一点的是equal信号,做减法的时候,equal信号为1表示两个操作数相等,0表示不相等。方法是吧输出的8位剥除来或,然后求非。(想想是不是这样,做减法的时候如果相等,equal就等于1?)实验看看效果:4.4 扩展器(3位的立即数扩展到8位),两种扩展方式这里需要实现符号扩展和0扩展,看下图:看看上面两个图的实验,是不是0的时候0扩展,1的时候符号扩展?4.5 PC的两种特殊扩展方式这里先实现beq的扩展,jump暂时不考虑分析一下beq扩展的需要,我们会发现能够得到一个非常奇葩的结论。在32位指令中,立即数位16位,扩展到32位的时候,需要后面补两个0,因为指令每个市4个字节,所以指令地址都是4的倍数,后面会一直有两个0.因为要充分利用那16位立即数,mips约定这两个0不记录,用的时候补上。然后在符号扩展。那么8位的指令呢?每个指令地址是几的倍数?是1的倍数,所以不存在补0去0的问题,所以pc对于8位的扩展其实就是符号扩展。太好了,省了点事情。4.6 Ram的试用试验在cpu的实验中,需要用到2个内存结构。一个是指令,一个是数据。这个内存我们使用ram来处理。这个ram怎么用呢?Logisim RAM modules can be found in the built-in memory library.这个ram电路模块可以在内建电路库中找到。Because the RAM module doesnt look like the idealized memory we saw in lecture, you may feel confused about where to begin. The picture above shows a good way to wire up a circuit to use RAM. Here are a few things to know before you get started. 因为ram和我们授课中的理想的内存不太一样,你可能不明白怎么开始使用它。上图是一个典型的链接方法,你可以揣摩一下。 sel determines whether or not the RAM module is active. We will probably not run into any cases where we need to turn our RAM off, so you can wire a constant 1 to this. Sel信号表示ram是否是激活的。因为我们没啥理由需要把ram关闭,所以给他一个常数1就ok了。 A chooses which address will be accessed. A:表示访问的地址 The clock input provides synchronization for memory writes. Be sure to use the same clock here as you do for your reg file. Ram需要时钟来同步内存写操作,因此和寄存器堆用同一个时钟吧。 ld determines whether we are reading or writing to memory. If out is high, then D will be driven with the contents of memory at address A. Ld决定我们现在是读内存还是写内存。假如out(就是ld)信号为1,D位置的数据就是A地址的内容。 clr will instantly set all contents of memory to 0 if high. You should wire a manual switch so you can clear out memory whenever you want to restart a test. 如果Clr=1,可以将内存所有数据设置为零。有时候有用。 D acts as both data in and data out for this module. This means you have to be careful not to drive this line from two conflicting sources, which in this case are DataIn and the output of the memory. You can solve this by using a controlled buffer (aka a tri-state buffer) on the D port of the RAM module. By wiring logic to the out port and the valve port of the controlled buffer together so that they are always opposite values (as in the picture above), we can prevent conflicts between data being driven in and the contents of memory coming out. D这里很特殊,它既是输入端口也是输出端口。(这也是为什么ram需要单独说明的原因

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论