Understanding Opcodes and Operands
Machine code is handled by the CPU during the operation of the fetch execute cycle. - All sets of instructions which make up the code of a program are translated from source code to machine code assembly code.
- Machine code is called object code after it has been translated.
- Object code is simply a string of bits.
- Each character is represented by a byte (a group of eight bits)
Software instructions are executed or carried out by the CPU. - Machine code needs to tell the processor how and what to process.
- Each instruction will be made up of one or more bytes.
- Because there are many different types of processors this can be a very complicated process.
Machine language programs are made of strings of instructions and data. - They are just a string of bits.
100100100000000111011101110000001 - To understand this we can divide the 32 bit string into bytes
- (remember the machine does not divide a string of bit into bytes).
10010010 00000011 10111011 10000001
- This string is actually an instruction for a certain type of processor. The instruction is to copy a byte into memory area.
- The way in which the bytes in the instruction are organised is very important. The instructions are made up of three parts, one opcode and two operands.
- The processor read the opcode value as an instruction telling the processor that a byte must be copied.
- It also tells the processor that there are two operands that are needed to successfully execute the copy process and the first operand (two bytes) is the memory address and the second operand is the data.
- The instruction could be written in English as:
- copy to memory location specified the byte of data represented by 10000001
Fetch execute cycle The execution of a machine language instruction can be very complicated but there are some basics that are simple to understand. During the execution of any instruction the fetch execute cycle of the CPU come into operation. This cycle provides the means by which a high-level language instruction and data are converted into machine language. The fetch-execute cycle follows the steps of fetch, decode, execute and store. The control unit acts as the overall controller for each of these operations. - FETCH: the CPU needs to know where to go. The instruction is fetched from main memory
- DECODE: The CPU needs to know what to do. The type of instruction to be carried out has to be decodes and this is done in the CPU. Decoding involves separating the opcode from the data.
- EXECUTE: the CPU needs to carry out the instruction. The instruction or opcode in the instruction register is sent to and then executed by the ALU.
- STORE: the CPU needs to copy the result to memory. During the execution of the instruction, the results of the data being processed are stored in the accumulator.
- The CPU is ready for the next instruction. The fetch execute cycle starts again.
The stack is a special register that keeps record of where the CPU is up to in the specific operation it is carrying out. It is actually part of main memory and is kept for the use of the CPU. - The stack is important to the CPU as it keeps track of what process the CPU is up to in the instructions.
- As the program counter is one step ahead of the stack, if the program counter has changed and the CPU needs to check the memory address of where it is going, the program counter is not useful as it has already moved on to the next address.
- The stack holds the memory address of the current operation and so the CPU can make a quick check.
Fetch Execute Decode Cycle Animation
|
|