CPU must have two inputs:
-instructions
-data.
Instructions tell the CPU what actions need to be performed on the data. We represent instructions with binary codes just like data.
The both inputs to the CPU are stored in memory.
CPU functions by following a cycle
1.0 fetching an instruction
2.0 decoding it
3.0 and executing it.
This process is known as the fetch-decode-execute cycle.
The cycle begins when an instruction is transferred from memory to the IR along the data bus. In the IR, the unique bit patterns that make up the machine-language are extracted and sent to the Decoder.
-instructions
-data.
Instructions tell the CPU what actions need to be performed on the data. We represent instructions with binary codes just like data.
The both inputs to the CPU are stored in memory.
CPU functions by following a cycle
1.0 fetching an instruction
2.0 decoding it
3.0 and executing it.
This process is known as the fetch-decode-execute cycle.
The cycle begins when an instruction is transferred from memory to the IR along the data bus. In the IR, the unique bit patterns that make up the machine-language are extracted and sent to the Decoder.
IR
IR is responsible for the second step of the cycle, that is, recognizing which operation the bit pattern represents and activating the correct circuitry to perform the operation. Sometimes this involves reading data from memory, storing data in memory, or activating the ALU to perform a mathematical operation.
Program Counter
Once the operation is performed, the cycle begins again with the next instruction. The CPU always knows where to find the next instruction because the Program Counter holds the address of the current instruction. Each time an instruction is completed, the program counter is advanced by one memory location.
Each machine instruction is composed of two parts: the op-code and the operand.
The first three bits represent the op-code and the final six bits represent the operand.
The middle bit distinguishes between operands that are memory addresses and operands that are numbers. When the bit is set to '1', the operand represents a number.
A simple set of machine instructions for our CPU are listed in the table below.
Together these mnemonics are called an assembly language. Programs written in assembly language must be converted to their binary representation before the CPU can understand them. This usually done by another program called an assembler.
IR is responsible for the second step of the cycle, that is, recognizing which operation the bit pattern represents and activating the correct circuitry to perform the operation. Sometimes this involves reading data from memory, storing data in memory, or activating the ALU to perform a mathematical operation.
Program Counter
Once the operation is performed, the cycle begins again with the next instruction. The CPU always knows where to find the next instruction because the Program Counter holds the address of the current instruction. Each time an instruction is completed, the program counter is advanced by one memory location.
Each machine instruction is composed of two parts: the op-code and the operand.
The first three bits represent the op-code and the final six bits represent the operand.
The middle bit distinguishes between operands that are memory addresses and operands that are numbers. When the bit is set to '1', the operand represents a number.
A simple set of machine instructions for our CPU are listed in the table below.
Op-code | Mnemonic | Function | Example |
001 | LOAD | Load the value of the operand into the Accumulator |
LOAD 10 |
010 | STORE | Store the value of the Accumulator at the address specified by the operand | STORE 8 |
ADD | Add the value of the operand to the Accumulator | ADD #5 | |
100 | SUB | Subtract the value of the operand from the Accumulator | SUB #1 |
101 | EQUAL | If the value of the operand equals the value of the Accumulator, skip the next instruction | EQUAL #20 |
110 | JUMP | Jump to a specified instruction by setting the Program Counter to the value of the operand | JUMP 6 |
111 | HALT | Stop execution | HALT |
Together these mnemonics are called an assembly language. Programs written in assembly language must be converted to their binary representation before the CPU can understand them. This usually done by another program called an assembler.