This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:asm:cpu_simulator [2011/05/01 03:05] – [Memory and Flip-flop integration] jhammo13 | notes:asm:cpu_simulator [2011/05/18 19:30] (current) – [Project Implementation] jhammo13 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | As you break a computer down it is nothing more than a device composed of certain components to control the flow of electricity as it passes through it. This flow of electricity is in a major part manipulated by the CPU which is going to be the major focus of this project. This documentation will basically be. However, as you get more technical the electricity represents or stands for different things. As you work your way from the ground up the computer will become more complex in that the different states of electricity will stand for different things. these states will also start to create output. this output could be something like displaying something in the monitor. We will work from the ground up in our understanding. This will begin with a general breakdown of a CPU before venturing into the project implementation. | ||
+ | |||
+ | ====== Boolean Logic and Boolean Gates ====== | ||
+ | Let's begin this topic with a summation of what's to come. All a computer does is manipulate electricity with gates. Gets have 2 inputs and 1 output. The inputs are either high voltage or low voltage. The output is either high or low voltage. High voltage is commonly referred to as 1 and low voltage is commonly referred to as 0. Boolean logic is the logic inside the gates. Now we'll get a little more detailed. | ||
+ | |||
+ | **__Boolean logic__** is a very simple form of logic consisting of two variables. There are only 2 because a computer can only understand two states. These two states can have mathematical operations ( addition, multiplication) performed on them. The only difference is instead of multiplication the term __AND__ is used. Instead of addition the term __OR__ is used. There is also a __NOT__ that will inverse any output. ( 0 to 1 and 1 to 0 ) | ||
+ | |||
+ | The only operations the CPU understands are these 0's and 1's, this is how it makes all of its calculations | ||
+ | ^ Logic 0 ^ Logic 1 ^ | ||
+ | ^ False ^ True ^ | ||
+ | ^ Off ^ On ^ | ||
+ | ^ Low ^ High ^ | ||
+ | ^ No ^ Yes ^ | ||
+ | ^ Open Switch ^ Closed Switch ^ | ||
+ | |||
+ | The above table show some different variables that a 0 and a 1 could stand for | ||
+ | |||
+ | |||
+ | ===== Gates/ | ||
+ | **Logic** Pre-determined instructions that manipulate input | ||
+ | |||
+ | |||
+ | **Gate** | ||
+ | |||
+ | **Circuits** 2 or more connected gates | ||
+ | |||
+ | More or Less: A circuit breaks down in to gates, gates break down in to logic and logic breaks down in to the following tables. | ||
+ | |||
+ | *AND | ||
+ | |||
+ | < | ||
+ | ^ AND Logic ^^^ | ||
+ | ^ Input ^^ Output ^ | ||
+ | ^ x ^ y ^ xy ^ | ||
+ | ^ 0 ^ 0 ^ 0 ^ | ||
+ | ^ 0 ^ 1 ^ 0 ^ | ||
+ | ^ 1 ^ 0 ^ 0 ^ | ||
+ | ^ 1 ^ 1 ^ 1 ^ | ||
+ | The only time an AND gate has an output of 1 is when the inputs are both 1 | ||
+ | It literally needs both x ' | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | |||
+ | *OR | ||
+ | |||
+ | < | ||
+ | ^ OR Logic ^^^ | ||
+ | ^ Input ^^ Output ^ | ||
+ | ^ x ^ y ^ x+y ^ | ||
+ | ^ 0 ^ 0 ^ 0 ^ | ||
+ | ^ 0 ^ 1 ^ 1 ^ | ||
+ | ^ 1 ^ 0 ^ 1 ^ | ||
+ | ^ 1 ^ 1 ^ 1 ^ | ||
+ | An OR gate has an output of 1 when x ' | ||
+ | < | ||
+ | |||
+ | *Not | ||
+ | |||
+ | < | ||
+ | ^NOT Logic^^ | ||
+ | ^Input^Output^ | ||
+ | ^x^x^ | ||
+ | ^0^1^ | ||
+ | ^1^0^ | ||
+ | The NOT gate takes a single input and simply inverses it. If a 0 is inputted it turns to a 1 and if a 1 is inputted it turns to a 0 | ||
+ | |||
+ | The NOT gate can also be placed at the end of the AND, OR gates to create NAND, NOR gates | ||
+ | |||
+ | In diagrams the actual NOT gate is not showed seperately if it is after another gate, it is represented by a circle at the end of the other gate | ||
+ | < | ||
+ | |||
+ | *NAND | ||
+ | |||
+ | < | ||
+ | ^ NAND Logic ^^^ | ||
+ | ^ Input ^^ Output ^ | ||
+ | ^ x ^ y ^ xy ^ | ||
+ | ^ 0 ^ 0 ^ 1 ^ | ||
+ | ^ 0 ^ 1 ^ 1 ^ | ||
+ | ^ 1 ^ 0 ^ 1 ^ | ||
+ | ^ 1 ^ 1 ^ 0 ^ | ||
+ | |||
+ | The Nand gate is the not and, it is the inverse of a and gate and is always 1 unless both inputs are 1 | ||
+ | |||
+ | |||
+ | |||
+ | When these gates are combined together they create circuits. These circuits are what make up the ALU and CU of the CPU | ||
+ | |||
+ | | ||
+ | ======Central Processing Unit (CPU) and its Components====== | ||
+ | |||
+ | The CPU's job is to manipulate inputted data and output it. Simple, right? It takes electricity which is the input and has it's way with it and outputs it in its new state. | ||
+ | |||
+ | **CPU Major Components** | ||
+ | |||
+ | * ALU: (Arithmetic Logic Unit) Processes data | ||
+ | * RA: (Register Array) Inventory of hardware registers, which are used for local on-CPU storage of data | ||
+ | |||
+ | **General Requirements of the CPU** | ||
+ | |||
+ | |||
+ | *1.) Fetch instruction: | ||
+ | *2.) Interpret instruction: | ||
+ | *3.) Fetch data: The execution of an instruction may require reading data from memory or an I/O module | ||
+ | *4.) Process data: The execution of an instruction may require performing some arithmetic or logical operation on data | ||
+ | *5.) Write data: The results of an execution may require writing data to memory or an I/O module | ||
+ | |||
+ | When broken down to the physical components the CPU is nothing but more than a bunch of **logic gates** that when combined create circuits. A logic gate is simply a physical something that takes 2 inputs and gives one output. The given output is different based on what type of gate is being used. | ||
+ | |||
+ | |||
+ | |||
+ | ===== Memory Circuit ===== | ||
+ | |||
+ | |||
+ | In order to accomplish the above 5 tasks it is necessary for the CPU to temporarily store some data. The CPU needs to remember where the last instruction came from so that it can take know where to get the next instruction from. The CPU needs internal memory for this. These areas of internal memory are called **registers.** | ||
+ | |||
+ | ==== Memory and Flip-flop integration ==== | ||
+ | A flip-flop is just a specific type of circuit designed for memory. | ||
+ | |||
+ | **Complicated text book explanation**An obvious component to any computer is memory.. or for our project, simulated memory. Without memory there can be no computers as we know them. To create a simple 1-bit memory you need a circuit that can " | ||
+ | **__SR flip-flop__** | ||
+ | |||
+ | **Simple version** A flip-flop is a circuit (series of 2 or more gates) of 2 NOR gates where 1 input from each is the other output. It simply creates a loop where the electricity doesn' | ||
+ | |||
+ | **Register** provide internal storage for the CPU. It is where the CPU may temporarily store data because it can read this data much quicker than anywhere else on the computer. | ||
+ | |||
+ | ====== Project Implementation ====== | ||
+ | |||
+ | This project is being created from the ground up. It is beginning with programming for the Boolean logic. Then the gates code is working off the logic code. Then the circuit code is working off the gate code. Remember gates are built of logic and circuits are created from gates. The code for the project works in the same exact way. Coding for this project is actually simpler than it sounds, don't over complicate things as you'll see below. | ||
+ | |||
+ | |||
+ | **Gate Code:** The basic gates or ' | ||
+ | |||
+ | *Example of AND gate. Keep in mind the input does not matter. The only thing that matters is that there are two arbitrary inputs. Their names or format are not important right now. | ||
+ | |||
+ | |||
+ | if ((input1 == true) && (input2 == true)) | ||
+ | { | ||
+ | result = true; | ||
+ | } | ||
+ | | ||
+ | This file can now be added to a library and be called by another function of the simulator any time it needs an AND gate. | ||
+ | There are also a few circuits in this folder? Probably shouldn' | ||
+ | **Adder Circuits** The adder circuits work by taking the basic gates that were created and calling them in order as the actual physical circuit is designed. The outputs are then given a name that can be called later by the other functions in the project. | ||
+ | |||
+ | This code is also how the flip-flop circuits will be created. The flip flop is a compilation of gates.. so if you create a file that calls the gates in the order they would be called in a flip-flop.. then you have coded for your flip flop circuit. | ||
+ | |||
+ | Now the register code is built up of the rest of the code. **For example.** | ||
+ | |||
+ | 6502 register/ | ||
+ | |||
+ | g8sr.h -> ffnor.h, and.h | ||
+ | |||
+ | ffnor.h -> nor.h | ||
+ | |||
+ | nor.h -> NOR class | ||
+ | |||
+ | and.h -> class AND | ||
+ | |||
+ | and.h -> class AND | ||
+ | |||
+ | nor.h -> class NOR | ||
+ | |||
+ | |||
+ | |||
+ | Above is an example of how one of the registers breaks down in to all of the called files in the project. Each file is linked to another file until you get down in to the basic classes which is where the project began. | ||
+ | ====== FAQ ====== | ||
+ | |||
+ | 1. How to connect a previous code into the register when the instruction are being set. | ||
+ | |||
+ | The registers are instantiated in cpu/ | ||
+ | |||
+ | accum, prgcnt, status, indexx, indexy, stack | ||
+ | |||
+ | Note these are defined globally, and because we're dealing with a multi-file | ||
+ | project, the instruction-specific functions are a part of the interpreter | ||
+ | code, and WILL be able to see and use these globally instantiated registers. | ||
+ | |||
+ | Any public member functions of the reg6502 are possible on any of these | ||
+ | instantiated registers (accum, status, etc.)... so you use the specific | ||
+ | registers by name in the instruction functions (ADC, ADD, etc.). | ||
+ | |||
+ | 2. Opcodes. All the list of them are instruction set for the register but how to properly code them so they perform operations i.e. ADC (add / carry) I seem on the 6502 of all the opcodes there but none of them make sense nor workable. could it be because it is not impented into the register yet? how to fix it? | ||
+ | |||
+ | In cpu/ | ||
+ | accumulator instruction (6502 hex code 0x29). Notice how it makes use of the | ||
+ | " | ||
+ | defined in this file, instead you can find them | ||
+ | defined in: cpu/ | ||
+ | |||
+ | The interpreter.cc file is currently where everything is coming together-- | ||
+ | interactions with the user, figuring out exactly what needs to be done | ||
+ | (ie which instruction to run), and resulting actions taking place on our CPU. | ||
+ | |||
+ | 3. Shift circuits...when shifting circuits like examples in 8085 are different from 6502 because of the structure but why it is shift instead of clear? | ||
+ | |||
+ | Shift instead of clear? I do not follow. Both processors will likely perform | ||
+ | shifts in similar ways... but the resulting instructions will likely have | ||
+ | very different hex codes, and have different registers. | ||
+ | |||
+ | When you shift, bits that go off the end are lost (they do not get recycled). | ||
+ | |||
+ | If you were to shift an 8-bit register 8 times to the right, the register | ||
+ | would effectively be cleared... is that what you were asking? |