# Instruction (Machine Language)

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

## 3 - Type

Instruction that involves a memory address:

• branch instruction

## 4 - 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

## 6 - List

### 6.2 - 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).

## 7 - Implementation

Each instruction is implemented via a circuit.

You can see them as function name.

## 9 - Pointer

The instruction pointer holds the location of the next instruction, and increments itself after every instruction.

## 10 - Example

### 10.1 - Basic

Read the contents of memory at location X into register Y

### 10.2 - 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

### 10.3 - x86 architecture

Example on the x86 ISA architecture:

• the pattern 10100000 means add two numbers,
• the pattern 000000101 means halt a computer