Instruction (Machine Language)
About
A machine instruction is a unique bit string that a device can identify and execute.
An Instruction refers generally to the words of the language understood by the CPU but other device (such as the GPU or printer) has also one. See Device - Programmable Device
The CPU requires a fixed number of clock ticks (or clock cycles) to execute each instruction. See Instruction - Cycle
Articles Related
Type
Instruction that involves a memory address:
- branch instruction
- loading/saving data
Syntax
An instruction:
- is a fixed-size series of bits.
- has a length that may varies.
- shares the same structure (see below)
The instruction format is device dependent but show always this structure:
- an opcode - an single digit that identify a unique operation (function)
- and zero or more operands (the argument of the opcode)
There is no grammar that defines what is a valid sequence of machine instructions. The CPU reads the instruction bytes, and if it is a valid machine instruction, it will be executed. Otherwise, typically an “invalid instruction” hardware exception will be generated.
Instructions are usually written in assembly with the help of mnemonic. See Assembly - Instruction
Example
List
Type
General-purpose
This group of instructions are general-purpose instructions that perform:
- basic data movement,
- arithmetic:
- binary integer,
- decimal
- logic operations,
- shift and rotate,
- bit and byte operations,
- program control (program flow)
- string,
- flag control,
- segment register operations,
- and miscellaneous subgroups.
They operate on:
- data contained in memory, in the general-purpose registers (EAX, EBX, ECX, EDX, EDI, ESI, EBP, and ESP) and in the EFLAGS register.
- address information contained in memory, the general-purpose registers, and the segment registers (CS, DS, SS, ES, FS, and GS).
Implementation
Each instruction is implemented via a circuit.
You can see them as function name.
Execution
Pointer
The instruction pointer holds the location of the next instruction, and increments itself after every instruction.
Example
Basic
Read the contents of memory at location X into register Y
Math
With logic gates, it's possible to build a machine that perform the following instructions when the following code input are received.
Instruction Code
"add a number to another number" 00000001
"subtract a number from another number" 00000010
x86 architecture
Example on the x86 ISA architecture:
- the pattern 10100000 means add two numbers,
- the pattern 000000101 means halt a computer