4 Bit Cpu Report
4 Bit Cpu Report
4 Bit Cpu Report
LAB REPORT
4 BIT CPU
By Group 12
Chander Prakash Garg (03010108) Vikrant Chahar (03010132) Vinay Kumar Tibrewal (03010134)
Date of Completion: 19th April, 2005 Date of Submission: 21st April, 2005
DESIGN CHARACTERISTICS
Hardwired control unit. 15 control signals. 4 bit data bus. 8 bit address bus. 14 instructions are supported. 256 bytes of usable memory to store the opcodes. 4 general purpose internal registers. 4 bit ALU. One internal register is used as memory buffer register (MBR). This register is also the default register for ALU operations. Only Load and Store operations access the memory. All ALU operations are register based. Out of 14 instructions, 8 require two clock pulses and remaining 6 require five clock pulses to be executed completely. An 8 bit register is used as program stack for use in Call and Return instructions.
INSTRUCTION SET
The CPU has an instruction set containing 14 instructions. So the opcode is of four bits. Following are the instructions along with their opcodes: INSTRUCTION NOT OR AND ADD SUB MOV JUMP JZERO LOAD STORE CALL HALT SET RET OPCODE 0000 0001 0010 0011 0100 0101 1000 1001 1010 1011 1100 1101 1110 1111
BLOCK DIAGRAM
HARDWARE DESIGN
1. CONTROL UNIT
The CPU has a hardwired control unit. The design is based on the sequence counter method. The control unit generates signals for synchronization of both the internal and external data buses. It also generates signals like gate control of tristate buffers, load signal for appropriate register, function selects for the ALU, increment signal for program counter etc. Inputs to the control unit are the opcode, operand and the master clock. The control unit uses a counter with synchronous clear along with these inputs to generate the sequence of controls.
2. ALU DESIGN
The ALU consists of a 74LS181 chip. All arithmetic / logical operation are done by this chip. 74181 is a 24 pin IC which acts as a 4-bit ALU. This chip has 6 control inputs which define the operation to be performed. These select inputs are generated by the control unit according to the opcode by the help of a combinational circuit. The ALU takes two operands. One of them comes from the default register and another can come from any of the four internal registers. The output of the ALU operation is stored back to the default register. A tristate buffer is provided between ALU output and register inputs to avoid bus contention at the time of LOAD operation. ALU is used for the following six operations: NOT, AND, OR, ADD, SUB and MOV. In all other cases the ALU remains unused.
3. PROGRAM STORE
There are two ways to execute instructions. One way is to load one instruction directly into the opcode and the operand register. When the CPU is used in this mode some operations like CALL, RET, JUMP and JZERO cease to have any relevance. The other way in which instruction can be executed is by placing them in a semiconductor storage medium such as RAM or EPROM which has at least a word length of 4-bits. The length of such medium is no constraint but the program counter can access only 255 locations. The program to be executed has to be stored in the chip and the CPU will start executing it starting with the instruction stored in the address #0000 and will continue execution until it encounters a HALT instruction.
4. MAIN MEMORY
The Main Memory consists of the RAM chip 2114. The actual size of the memory is 1024 x 4 bits. But in this architecture only 8 address lines are used so only 256 memory locations are accessed. The data bus is used for LOAD as well as STORE operations. Tristate buffers are used so that the same bus can be used for both read and write operations.
5. INTERNAL REGISTERS
Four internal registers have been used. They are designated as A, B, C and D. The registers have following addresses: A 00 B 01 C 10 D 11 The register A acts as accumulator for ALU operations and as MBR for LOAD and STORE operations. The results of ALU operations are stored back in the register A. Also value is loaded from or stored in memory from register A. The other three registers (B, C, D) are general purpose internal registers.
2. OR (0001)
This is another logical ALU operation. Its format is: Opcode: 0001 Operand: 00ab This performs bitwise OR operation on the contents of the accumulator (00) and the register specified by ab part of operand and stores the result of the operation back in the accumulator.
3. AND (0010)
This is another logical ALU operation. Its format is: Opcode: 0010 Operand: 00ab This performs bitwise AND operation on the contents of the accumulator (00) and the register specified by ab part of operand and stores the result of the operation back in the accumulator.
4. ADD (0011)
This is arithmetic ALU operation. Its format is: Opcode: 0011 Operand: 00ab This performs arithmetic addition operation on the contents of the accumulator (00) and the register specified by ab part of operand and stores the result of the operation back in the accumulator. The carry bit generated is not handled in this architecture. It is simply ignored.
5. SUB (0100)
This is arithmetic ALU operation. Its format is: Opcode: 0011 Operand: 00ab This performs arithmetic subtraction operation on the contents of the accumulator (00) and the register specified by ab part of operand and stores the result of the operation back in the accumulator. In other words it performs A X where X is any internal register. The carry bit generated is not handled in this architecture. For these five ALU operations various steps of execution process are shown in the following figure:
Thus it is clear that these ALU operations take two clock cycles to be executed.
6. MOV (0101)
This instruction is used to move the contents of one internal register to other. The contents are moved through the ALU. Format of this instruction is: Opcode: 0101 Operand: abxy where ab is the address of the destination register and xy is the address of the source register. The data is piped through the input B of ALU and is stored in required register. For this operation various steps of execution process are shown in the following figure:
Thus it is clear that this ALU operation also takes two clock cycles to be executed.
7. JUMP (1000)
This is the unconditional jump instruction. It is used to set the program counter to a value other than the succeeding location. Its format is: Opcode: 1000 Operand: abcd efgh where abcd is the lower nibble of destination address and efgh is the higher nibble. After opcode fetch, abch is fetched and stored in MARs lower four bits. Then efgh is stored in MARs higher four bits. Then these 8 bits are loaded in the program counter so that execution starts from desired location. For this operation various steps of execution process are shown in the following figure. This operation takes five clock cycles.
8. JZERO (1001)
This is the conditional jump instruction. It is used to set the program counter to a value other than the succeeding location on the condition that the contents of accumulator are zero. Its format is: Opcode: 1001 Operand: abcd efgh where abcd is the lower nibble of destination address and efgh is the higher nibble. After opcode fetch, abcd is fetched and stored in MARs lower four bits. Then efgh is stored in MARs higher four bits. Then these 8 bits are loaded in the program counter when the jump condition is satisfied so that execution starts from desired location. A four bit comparator 74LS85 chip has been used to compare the value of accumulator. For this operation various steps of execution process are nearly similar to that of JUMP instruction. It also takes five clock cycles to be executed.
9. LOAD (1010)
This is one of the two memory access instructions. This is used to bring the contents of a memory location into the registers of the CPU. Its format is: Opcode: 1000 Operand: abcd efgh where abcd is the lower nibble of address of memory location and efgh is the higher nibble. After opcode fetch, abcd is fetched and stored in MARs lower four bits. Then efgh is stored in MARs higher four bits. Then these 8 bits are then used to select the memory location from where the loading is to be done. The fetched value gets loaded in the accumulator cum MBR (register 00). For this operation various steps of execution process are shown in the following figure. This operation takes five clock cycles.
For this operation various steps of execution process are shown in the following figure. This operation takes five clock cycles.
For this operation various steps of execution process are shown in the following figure. This operation takes two clock cycles.
IMPLEMENTATION
REGISTER ORGANIZATION
The registers in the architecture can be broadly divided into two categories, special registers and general purpose registers. This classification is by no means mutually exclusive and some registers seem to have characteristics of both especially the accumulator.
SPECIAL REGISTERS
1. Instruction Register
This actually consists of two registers one opcode register and the other called operand register. Opcode register is used to store the operation code of the instruction that is currently being executed. This forms the input for the instruction decoder. It is also because of this arrangement that it is possible to execute instructions one after the other by directly entering the opcode into the register. Operand register holds the operands of the instruction currently being executed. The output of this register is used for all ALU related instructions. The value stored here is send to two decoders which select appropriate internal registers for read and write operations. The two MSB are used to write enable accumulator (or some other register in case of MOV) and two LSB are used to read enable a register.
3. Accumulator
This can be considered to be a general purpose register cum MBR. This is a register that is available to the programmer space. This is the register where all the results of all ALU operations are stored. This is also the only register which can interact with the RAM memory by means of LOAD and STORE. Assignment operation can also take place only into this register. This register is referred to by the code 00. Accumulator can perform all the functions that can be performed by all other registers and can be used for all manipulations by the programmer.
SUBROUTINE SUPPORT
The architecture has built in support for function call. A programmer may make a subroutine call to any location in the program store, execute instructions there and then jump back to the initial location. He is not required to handle to which location he has to jump back to. This is handled by the architecture. Only one level of subroutine call is supported. Thus recursion is not supported. At the heart of the subroutine call support is the program stack register. This register stores the value of the program counter whenever a function call takes place. Also in this case the incremented value of program counter is stored in the stack. This value is set back into the program counter whenever a return statement is encountered.
JUMP SUPPORT
The architecture supports two kinds of jump statements. In both cases the appropriate value as specified in the operands is set in the program counter. There are two types of jumps. An unconditional jump where the jump always takes place and a conditional jump in which case the jump takes place only if the contents of the accumulator are zero. For conditional jump a comparator is used. A flag register was not maintained thus ALU output could not be used for a jump.
2. HALT MECHANISM
Halt is the only instruction that is executed single clock cycle. When this instruction is executed the clock to the whole CPU is stopped. This is done by ANDing the output of the appropriate pin of the negative high instruction decoder with the clock. When a HALT instruction (#1101) is selected then the output of the decoder becomes 0 and this instruction cannot change as even for the instruction to change a clock pulse is required.
3. SEQUENCE COUNTER
The control unit uses a 4 bit counter with synchronous clear to keep track of number of cycles elapsed after opcode fetch. This counter is a 74LS163 chip which has synchronous clear facility. At the start this counter is initialized to 0000. The control unit is so designed that when output of this counter is 0000 then opcode fetch will take place on negative going edge of clock pulse. When the opcode corresponds to instructions being executed in two clock cycles, this counter is synchronously cleared at 0001. In other cases it is cleared at 0100. Thus next opcode is fetched either after two clock cycles or after five clock cycles. In this way execution takes place until a HALT is encountered.
ICs USED
Following chips have been used for realizing above the CPU design. Sr. No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Chip No. 7404 7408 7432 7475 7485 7495 74153 74154 74155 74157 74161 74163 74181 74194 74367 2114 Description No. of chips used Hex Inverter 8 Quad 2 input AND 8 Quad 2 input OR 6 Quad latch 4 4 bit comparator 1 4 bit PIPO register 5 Dual 4 to 1 MUX 2 4 to 16 Decoder 2 Dual 2 to 4 decoder 3 Quad 2 to 1 MUX 3 4 bit counter 2 4 bit counter 1 4 bit ALU 1 4 bit register with clear 1 Hex tristate buffer 8 1K x 4 bit RAM 1
SAMPLE PROGRAM
The program given to us was swap the contents of two locations in the main memory. Following program was written for this: Memory Address 0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 0000 0101 0000 0110 0000 0111 0000 1000 0000 1001 0000 1010 0000 1011 0000 1100 0000 1101 0000 1110 0000 1111 0001 0000 0001 0001 0001 0010 Contents (Program) 1010 0001 0001 0101 1100 1010 0010 0001 1011 0001 0001 0101 0011 1011 0010 0001 1101 1111 1001 Description * LOAD into A from first memory location * MOVE contents of A to D * LOAD into A from second memory location * STORE contents of A into first memory location * MOVE contents of D to A * STORE contents of A into second memory location * HALT * First memory location * Second memory location
The program was loaded in RAM. The program executed successfully. At the end of execution the contents of memory were: Memory Address 0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 0000 0101 0000 0110 0000 0111 0000 1000 0000 1001 0000 1010 0000 1011 0000 1100 0000 1101 0000 1110 0000 1111 0001 0000 0001 0001 0001 0010 Contents (Program) 1010 0001 0001 0101 1100 1010 0010 0001 1011 0001 0001 0101 0011 1011 0010 0001 1101 1001 1111 Description
Thus the swapping took place and was demonstrated to the invigilator.
DEMERITS
1. 2. 3. 4. Upgradeability is poor and difficult to achieve No support for multiple successive calls. Lengthy design and implementation time. Large number of ICs used to make control unit.