Difference between revisions of "PicoCPU"
Line 6: | Line 6: | ||
* '''Control Unit (CU):''' Reads the instructions, advances the program counter and controls the work of the rest of the CPU | * '''Control Unit (CU):''' Reads the instructions, advances the program counter and controls the work of the rest of the CPU | ||
* '''Data Path Unit (DPU):''' Does all the calculations and other data manipulation operations | * '''Data Path Unit (DPU):''' Does all the calculations and other data manipulation operations | ||
− | * ''' | + | * '''Program Memory (PM):''' A ROM that contains the program data. In picoCPU, it is emulated by the testbench. |
* '''Data memory (DM):''' The data memory is implemented as a RAM. It contains the temporary data that are needed by the currently running program. | * '''Data memory (DM):''' The data memory is implemented as a RAM. It contains the temporary data that are needed by the currently running program. | ||
Line 14: | Line 14: | ||
[[File:Control Unit.png|thumbnail|right|Diagram of the control unit for picoCPU]] | [[File:Control Unit.png|thumbnail|right|Diagram of the control unit for picoCPU]] | ||
The most important part of the CU is the control FSM, that has four states: | The most important part of the CU is the control FSM, that has four states: | ||
− | # '''Fetch:''' fetches the data from the | + | # '''Fetch:''' fetches the data from the program memory and stores it in the instruction register. |
# '''Decode:''' Seperates operand from instruction | # '''Decode:''' Seperates operand from instruction | ||
# '''Execute:''' Executes the instruction | # '''Execute:''' Executes the instruction | ||
# '''Write back:''' Writes execution result to the destination register or memory address, advances the program counter. | # '''Write back:''' Writes execution result to the destination register or memory address, advances the program counter. | ||
− | The program counter (PC) is a pointer to the | + | The program counter (PC) is a pointer to the program memory address of the currently executed instruction. The program counter's value directly specifies the memory address for reading the program memory. Usually, the program counter is increased by one after the current instruction is loaded (next address of the program memory is chosen). However, it is also possible to change the PC's value to an arbitrary one, for example to implement branching in the code. |
== Data Path Unit == | == Data Path Unit == | ||
[[File:DPU.png|thumbnail|right|Diagram of the DPU's architecture for the picoCPU]] | [[File:DPU.png|thumbnail|right|Diagram of the DPU's architecture for the picoCPU]] | ||
=== ALU === | === ALU === | ||
− | The central part of the DPU is the Arithmetic and Logic Unit (ALU). ALU's task is to execute all the arithmetical and logical calculations. It has many functions and the correct one is chosen by the CU, based on the currently executed instruction. Every calculation result always ends up in the accumulator register. The first input of the ALU can be multiplexed between a register and the operand from the operand from the | + | The central part of the DPU is the Arithmetic and Logic Unit (ALU). ALU's task is to execute all the arithmetical and logical calculations. It has many functions and the correct one is chosen by the CU, based on the currently executed instruction. Every calculation result always ends up in the accumulator register. The first input of the ALU can be multiplexed between a register and the operand from the operand from the program memory and the contents of a register (the multiplexer can be controlled be specific instructions). The second input is always the contents of the accumulator. |
=== Memory operations === | === Memory operations === | ||
Line 37: | Line 37: | ||
== Impementation == | == Impementation == | ||
+ | [[File:PicoCPU testbench.png|thumbnail|right|Diagram showing implementation of picoCPU]] | ||
+ | Each main component of picoCPU is implemented as a separate entity. The structure of the connections can be seen in the figure on the right. | ||
+ | |||
+ | In case of picoCPU, the program memory is emulated be the testbench. Its contents are read from a text file. This enables easy reprogramming of picoCPU for simulation purposes. | ||
+ | |||
+ | === Program Memory Data format === | ||
+ | [[File:Instruction.png|thumbnail|right|Description of the instruction format for picoCPU]] | ||
+ | As it can be seen in the figure on the right, each instruction for the picoCPU consists of 16 bits. The three highest bits are reserved and not currently used, so they should be given the values '0'. The next 5 bits (bits 12 - 8) | ||
+ | specify the opcode. Finally the lowest 8 bits (bits 7-0) specify the operand. It has to be noted, that picoCPU accepts only one operand in an instruction. In case no operand is needed for the instruction, the operand bits are ignored. | ||
+ | |||
+ | === Program memory file format === | ||
+ | As mentioned above, the program memory in picoCPU is emulated by the tesbench and its contents are read from a text file. The format of the text file is quite simple: each line represents one memory address, line 1 mapping to memory address 0x0, line 2 to address 0x1 and so on. Each line contains 16 bits in a format mentioned above. | ||
+ | |||
+ | The execution of the program starts from memory address 0x0 and the address is normally increased by one after executing of every line, except branching instructions, that can cause the program execution to jump to other addresses. | ||
+ | |||
+ | === Instruction set === |
Revision as of 14:04, 24 November 2015
The picoCPU was built as a course work during the Digital Systems Modelling and Synthesis course. Its goal is to provide very simple and minimal, but still functional, general purpose CPU design for educational purposes.
Contents
Architecture
PicoCPU is divided into four main components (seen in the figure on the right):
- Control Unit (CU): Reads the instructions, advances the program counter and controls the work of the rest of the CPU
- Data Path Unit (DPU): Does all the calculations and other data manipulation operations
- Program Memory (PM): A ROM that contains the program data. In picoCPU, it is emulated by the testbench.
- Data memory (DM): The data memory is implemented as a RAM. It contains the temporary data that are needed by the currently running program.
PicoCPU is designed to have a generic design and it's bitwidth is scalable to satisfy the user's preference, being 8-bit by default. All the data are always treated as signed values.
Control Unit
The most important part of the CU is the control FSM, that has four states:
- Fetch: fetches the data from the program memory and stores it in the instruction register.
- Decode: Seperates operand from instruction
- Execute: Executes the instruction
- Write back: Writes execution result to the destination register or memory address, advances the program counter.
The program counter (PC) is a pointer to the program memory address of the currently executed instruction. The program counter's value directly specifies the memory address for reading the program memory. Usually, the program counter is increased by one after the current instruction is loaded (next address of the program memory is chosen). However, it is also possible to change the PC's value to an arbitrary one, for example to implement branching in the code.
Data Path Unit
ALU
The central part of the DPU is the Arithmetic and Logic Unit (ALU). ALU's task is to execute all the arithmetical and logical calculations. It has many functions and the correct one is chosen by the CU, based on the currently executed instruction. Every calculation result always ends up in the accumulator register. The first input of the ALU can be multiplexed between a register and the operand from the operand from the program memory and the contents of a register (the multiplexer can be controlled be specific instructions). The second input is always the contents of the accumulator.
Memory operations
Writing to and reading from the data memory always involves the accumulator - all data read from the memory always ends up in the accumulator. It is also only possible to write into the memory data that is stored in the accumulator.
For writing into the register, the file data to be written has to be already in the accumulator. Then, a special instruction is used for doing the writing. Reading from the register can be done only through the ALU, using the regular ALU-related instructions, just the MUX has to be configured to take its input from the register. Due to the fact that it is possible to access the register only through the ALU, the value of the register can only be retrieved by running an arithmetic or logic operation on it. If just retreaving of the value is desired, a neutral operation, that does not change the value can be performed, like adding or subtracting 0 to/from the register or AND-ing the value with 1-s.
Flags
The picoCPU features two flags: zero (Z) and overflow(OV)
The zero flag indicates that the value in the accumulator is equal to 0 and OV flag indicates that the last operation caused an overflow in the accumulator. User can access the values of these flags using some conditional branching functions (BranchIfZero, etc.). The flags are only held up as long as the condition for a flag is true (i.e. the accumulator is zero) and are, thus, usually available only to the next isntruction (except some neutral instructions like NOP, that are not data-related).
Impementation
Each main component of picoCPU is implemented as a separate entity. The structure of the connections can be seen in the figure on the right.
In case of picoCPU, the program memory is emulated be the testbench. Its contents are read from a text file. This enables easy reprogramming of picoCPU for simulation purposes.
Program Memory Data format
As it can be seen in the figure on the right, each instruction for the picoCPU consists of 16 bits. The three highest bits are reserved and not currently used, so they should be given the values '0'. The next 5 bits (bits 12 - 8) specify the opcode. Finally the lowest 8 bits (bits 7-0) specify the operand. It has to be noted, that picoCPU accepts only one operand in an instruction. In case no operand is needed for the instruction, the operand bits are ignored.
Program memory file format
As mentioned above, the program memory in picoCPU is emulated by the tesbench and its contents are read from a text file. The format of the text file is quite simple: each line represents one memory address, line 1 mapping to memory address 0x0, line 2 to address 0x1 and so on. Each line contains 16 bits in a format mentioned above.
The execution of the program starts from memory address 0x0 and the address is normally increased by one after executing of every line, except branching instructions, that can cause the program execution to jump to other addresses.