# Machine Code

Learn about machine code, the native language of a computer, with an example.

We'll cover the following

## Machine code

Now that we have circuits that can perform some basic operations on numbers, and we have data in the form of numbers, we can start to write programs that will perform operations on the data. We can do that with the only thing the computer understands: machine code. Because numbers can represent everything, the instructions we give to the computer will be, yes, thatâ€™s right, just numbers.

### Instruction set and assembly code

Each processor type has a specific set of instructions. A program written for a Mac canâ€™t run on a PC running Windows. So, the instructions can be machine code. Machine code has several operations, called opcodes. The operations can be defined as AND, OR, ADD, and so on. Each opcode has a unique number. For example, AND could have an opcode value of 1, and OR could have an opcode value of 9.

The processor will also have several registers. A register is a small area, sometimes referred to as a data holding place, where the processor can store data itâ€™s currently working with. Before executing an operation, weâ€™ll need to move the data we want as input to the operation (from memory) into some of these registers. The result of the operation, the output, is also stored in a register. In reality, things are a bit more complicated than this, but we donâ€™t need to go into all the details here.

We can now recall the image of the four operations that were common for all computers: input, storage, process, and output. We first get an input, and it will go to the computerâ€™s memory for storage. The processor will then retrieve it from its register(s) and perform operations on it, which is the process part. When we have the result of the operations, it will go back into the memory so that it can later be sent to the output.

One way to write these instructions is to use something called an assembly. An assembly is a way of writing a program where we use three-letter abbreviations for the opcodes and have names for the registers. By doing this, it will be easier to read and understand the instructions we give. We can then use a program that can translate the assembly code into machine code.

Get hands-on with 1200+ tech skills courses.