Sunteți pe pagina 1din 6

SIMULATION OF A SIMPLE CPU DESIGN AND ITS USE AS AN INSTRUCTIONAL TOOL IN A COMPUTER ORGANIZATION COURSE John Phillips Computer

Information Science Department Mansfield University of Pennsylvania Mansfield, PA 16933 (570) 662-4554 jphillip@mansfield.edu ABSTRACT This paper describes a bottom up approach to teaching a Computer Organization course centered on the logic gate-based design of a simple central processing unit (CPU). The CPU is built and simulated using freeware MultiMedia Logic software. Students learn to program the CPU using assembly language that they hand assemble into machine code. INTRODUCTION The Computer Organization course at Mansfield University of Pennsylvania primarily serves Computer Science majors and Information Systems majors. In the past, the course had been taught using a conventional textbook. Students struggled with the material and had difficulty relating to the concepts presented. They studied many different electronic circuits but the circuits had never been brought together into a cohesive unit that did something really useful and interesting. Three changes were made to the course to increase interest and to improve understanding of the material. First, the book CODE: The Hidden Language of Computer Hardware and Software by Charles Petzold [2] was adopted as the primary textbook. This book takes a very bottom-up approach to designing a CPU and does so in a way the lay reader can understand. Petzold uses switches and then electromechanical relays in circuits to demonstrate how basic logic gates can be constructed. He then uses logic gates to construct more advanced circuits that eventually get worked into a programmable adding machine and finally into a partially completed CPU design. The second change was to incorporate a more hands-on approach to the electronics material. Students would now use a digital logic simulator to construct and explore many of the circuits being studied. The third change was to complete the CPU design described by the Petzold book. Building this complex device gives the students a major goal and a sense of accomplishment when it is achieved. This paper will describe the design and simulation of this CPU and discuss how it is used as the central focus of a Computer Organization course. MMLOGIC CPU DESIGN A freeware digital logic simulator named Multimedia Logic (MMLogic) from SoftTronics Corporation [4] was selected for the implementation of the CPU design. This program lets the user place logic gates, flip flops, switches, LEDs, and other electronic devices on the screen and then connect the inputs and outputs as desired using lines

representing wire. MMLogic is a very intuitive and easy to use program as the screen looks similar to the actual schematic drawing of the circuit. The MMLogic program limits each circuit to a screen area about the size of a printed piece of paper. Multiple pages are available to support larger designs and special sender and receiver devices are used to pass signals between the circuit pages. Figure 1 shows a typical circuit that students construct using this software.

Figure 1 A full adder circuit constructed using MMLogic A few changes were made in adapting Petzolds CPU to the MMLogic simulator. The main change was to convert the design from a 16-bit address bus to an 8-bit address bus. This means that only 256 bytes of RAM are supported. It turns out that this is more than enough memory for the programs students will be writing. This change helps simplify the design several ways. The program counter is now only 8-bits wide. All instructions will now be 2 bytes long instead of three bytes longa one byte opcode followed by a one byte operand. Other changes include replacing the adder circuit with the MMLogic ALU device and replacing the flip-flop based RAM circuits with the 256 byte MMLogic RAM device. Figure 2 shows a block diagram of the revised 8-bit single register CPU design. Each block of the diagram typically corresponds to one page of circuitry in the MMLogic simulator. The entire CPU consists of 13 pages (including two blank pages for student expansion projects).

Figure 2 Block diagram of the CPU To complete the CPU design a clock / timer circuit was developed that would control the instruction cycle step-by-step. All of the instructions had to be decoded and then signals sent out to control the various other parts of the CPU. The same instructions and opcodes that Petzold described in his book are used. This makes it easier for students to convert the programs they study in the book into actual working programs on the MMLogic CPU. Figure 3 shows the front panel of the MMLogic CPU running a program. The complete MMLogic CPU circuit, sample programs, and design guide can be downloaded from the authors web site [3].

Figure 3 Front panel of simulated CPU running a program INCORPORATING THE CPU INTO THE COURSE The course takes a bottom up approach in covering the material using Petzolds CODE book as the primary textbook. It is supplemented with David Tarnoffs Computer Organization and Design Fundamentals [5] and C N Bauers Microprocessor and CPU Architecture Documentation [1] and various course notes and web links. Students start out learning binary, octal, and hexadecimal number conversions. Next basic circuits are covered. Students learn about logic gates, truth tables, and representing logic circuits using Boolean algebra expressions. They learn to build a halfadder, a full adder, and then an 8-bit adding machine. Along the way they learn to add binary numbers and to subtract those using twos complement addition. They build an RS flip-flop using 2 NOR gates and then gradually build more complex flip-flops. Finally, a logic gate design for a D-type edge triggered flip-flop with preset and clear is given. This one is important as it is the basis for much of the CPU circuit. The students also build an 8x1 RAM circuit using flip-flops for storage and then they try to imagine what a 64K RAM circuit might look like. This work lays the foundation for building a working computer. The students now have built a clock / timer circuit, an 8-bit 2-to-1 selector, a 3-to-8 decoder, an 8-bit adder, an 8-bit accumulator, a 4-bit ripple counter, and a one byte RAM circuit. All that is left to

do is to expand the ripple counter into an 8-bit program counter, decode the instructions placed in the instruction register, and tie everything together via the carefully sequenced clock / timer circuit. As it takes a good deal of time and patience to wire these pieces together, the students are provided with the completed MMLogic CPU circuit. A couple of programming assignments are given to get them used to writing out assembly language code. The code must be hand-assembled into machine code which can then be executed by our CPU. Hand-assembly is a bit tedious, even for these small programs, leading to a discussion of how to write an assembler program in a high-level language. To better understand the CPU the students need to modify it. They add an output port that is connected to some LEDs. A new OUT instruction is created and a new opcode is assigned. The students write an assembly language program that counts in binary using the new output port. Then they write a program that counts down from 20 making use of a JNZ (jump not zero) instruction. Next each student adds an MMLogic ASCII display device and programs the CPU to print out his or her initials.

Figure 4 Example of the output port students add to the CPU. This ends the use of the MMLogic CPU in class. We move on working through Bauers 8086 CPU simulator tutorial. However, the students are encouraged to base their final projects on the MMLogic CPU. This gives them an opportunity to understand the design at a much deeper level. Some interesting final projects have included:

drawing the complete CPU schematic using AUTOCAD and printing it out on large format paper adding multiply, divide, compare, and new jump instructions to the CPU adding additional I/O ports and peripherals to the CPU converting the 8-bit address bus to 16-bits, updating the program counter to 16bits, and increasing RAM to 64K bytes networking together two MMLogic CPUs running on two different computers implementing a portion of the CPU in real hardware writing an assembler for the CPU in a high-level language writing a software emulator for the CPU in a high-level language

CONCLUSION Developing this simulated CPU was a great deal of fun. The students seem to learn from the bottom-up building process as covered in the textbook. They are able to use MMLogic to build each of the circuit pieces without problem. However, putting the pieces together to create a working CPU leaves some of the students a bit mystifiedin part, because the instructor does that step for them. In the future, more time will be spent on the final design of the CPU. Students will construct the complete CPU circuit themselves instead of using the instructor supplied circuit. Student responses on an anonymous course survey appear to support this course modification. One question asked if it was interesting ending up with a working CPU circuit that could be programmed. Out of 18 students, 10 strongly agreed, 6 agreed, 2 somewhat disagreed, and zero strongly disagreed. When asked if we should spend more class time modifying the CPU to better understand how it works, 8 strongly agreed, 8 agreed, 1 somewhat disagreed, and 1 strongly disagreed. Therefore, it seems that 16 out of 18 students in this class liked the CPU project and wanted to spend more time working on it to understand it better. REFERENCES [1] Bauers, C. N., Microprocessor Simulator for Students, 2006, http://www.softwareforeducation.com/sms32v50/index.php, retrieved November 17, 2006. [2] Petzold, C., CODE: The Hidden Language of Computer Hardware and Software, Redmond, WA: Microsoft Press, 2000. [3] Phillips, J. E., MU CPU Home Page, 2007, http://faculty.mansfield.edu/jphillip/documents/mucpu/mucpu.htm, retrieved January 30, 2007. [4] Softronics, Inc., Welcome to MultiMedia Logic, 2004, http://www.softronix.com/logic.html, retrieved November 17, 2006. [5] Tarnoff, D., Computer Organization and Design Fundamentals, USA: Lulu, 2005. Also available as a free PDF download from http://www.lulu.com/content/138292, retrieved November 17, 2006.

S-ar putea să vă placă și