Question: What information does a computer instruction have to contain ?
From the last webpage, an instruction must provide the following information:
|
The required information needed by a computer instruction are stored (= represented) together in a sequence of bytes
Example:
Format of one (= 1) computer instruction: 4 bytes (= 32 bits) <-------------------------------------------------------------> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <-----------> <-------------> <---------------> <--------------> opcode dest source1 source2 |
To encode (=represent) the operation, each computer operation is represented by a unqiue operation code (it's called opcode for short)
Example:
Operation Opcode ------------- -------- Move 0000000 Add 0000001 Subtract 0000010 Multiply 0000011 Divide 0000100 ... ... (and so on) |
For example: the binary code 0000001 represents an add operation:
4 bytes (= 32 bits) <-------------------------------------------------------------> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0|0|0|0|0|0|1| | | | | | | | | | | | | | | | | | | | | | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <-----------> <-------------> <---------------> <--------------> opcode dest source1 source2 |
Note: the source1, source2 and dest fields will encode the source and destination register operands
Note: each computer manufacturer has its own way to encode instructions !!!
This represents an add operation that uses the value in the register #1 as the first source operand:
4 bytes (= 32 bits) <-------------------------------------------------------------> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0|0|0|0|0|0|1| | | | | | | | |0|0|0|0|0|0|0|0|1| | | | | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <-----------> <-------------> <---------------> <--------------> opcode dest source1 source2 |
Note: the source1, source2 and dest fields will encode the source and destination register operands
Note: each computer manufacturer has its own way to encode instructions !!!
This represents an add operation that uses the values in register #1 and #3 as the source operands:
4 bytes (= 32 bits) <-------------------------------------------------------------> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0|0|0|0|0|0|1| | | | | | | | |0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|1|1| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <-----------> <-------------> <---------------> <--------------> opcode dest source1 source2 |
Note: the source1, source2 and dest fields will encode the source and destination register operands
Note: each computer manufacturer has its own way to encode instructions !!!
This represents the instruction add the values in regs #1 and #3 and store result in reg #4:
4 bytes (= 32 bits) <-------------------------------------------------------------> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|1|1| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <-----------> <-------------> <---------------> <--------------> opcode dest source1 source2 |
In assembler programming,, this instruction may be represented by the nmemonic: add R4, R1, R3
Note: each computer manufacturer has its own way to define assembler nmemonics too !!!