# What is machine code and how do we make the leap from transistors to machine code?

284 views

What is machine code and how do we make the leap from transistors to machine code?

In: Technology

there are multiple intermediate jumps between transistors to machine code. You use transistors to make gates, use gates to build more complex components like a register, an adder, a counter, memory, etc, then you make control logic so that a part of the processor does a specific operation when it reads a specific number from memory. That number in memory is the machine code.

https://nandgame.com/

Machine instructions have 3-ish parts: an operation, a register, and a value/address. The operation is like add, load, store, test, or jump. Each operation pattern of bits causes same register in the computer to change; add changes a data register; jump changes the register that stores the address of the next instruction; …

Transistors in a flip-flop configuration make up each bit of each register. Transistors in and/or logic formulas make the decoder structures that decode the operation. Transistors also make the buffers and controls for busses that connect to memory and I/O.

Transistors are circuit components that take in two voltages and give out a certain voltage based on those inputs. For example, you can have a transistor that outputs a high voltage if both of its inputs are high and a low voltage if not; or you can have one that outputs high if either one or both of the inputs are high and outputs low if both inputs are low.

The operation of those two transistors I described is identical to the Boolean Logic operations AND and OR. A Boolean AND operation evaluates to true if both operands are true, an OR evaluates to true if at least one operand is true. So, in this way we can use transistors to recreate logical operations by equating voltages with truth values, namely by treating a high voltage as meaning “true” and a low voltage as meaning “false”.

As it happens, Boolean operations can be combined to do arithmetic if we equate truth values to numbers (true↔1 and false↔0), and of course we can use that equivalency to relate digits to voltages and use transistors to do arithmetic.

Your CPU is made up of things called arithmetic logic units, which are bundles of transistors set up to do all of the basic mathematical and logic operations a computer needs. This is where machine code comes in. Machine code is essentially a list of operations (represented as numbers called opcodes) and their inputs, and it is what any program eventually gets turned into to run it. When running a program, its machine code gets loaded into RAM, the CPU gets pointed to where the program starts, and then as it runs through the program it will pull each line of machine code and decode the opcode (using Boolean logic) to figure out where in the arithmetic logic unit the operands need to go.

* Transistors are used to build [logic gates](https://en.wikipedia.org/wiki/Logic_gate).
* Logic gates are used to build logic blocks which can be used to build things like: