Machine code consists of binary instructions that a CPU can understand and execute directly. It is the lowest level of programming language, directly linked to the hardware and logic of the CPU, making it efficient but difficult for humans to read, write, and port to different hardware.
Assembly language, created to address the difficulties of reading and writing machine code, uses mnemonics to represent binary instructions. Each mnemonic corresponds to a specific machine code instruction, making it easier to write and understand. An assembler translates these mnemonics into machine code. Assembly language is memory-efficient but not portable across different systems and remains more complex than higher-level languages.
An Instruction Set is all of the instructions a CPU can execute.
Instructions are stored in memory (RAM) as machine code - they are binary patterns. These are the instructions that are fetched, decoded and executed by the CPU.
Instruction Sets are linked to specific CPUs and a program written in machine code using one instruction set will not be compatible with a CPU that uses a different or updated instruction set.
Machine Code are the binary instructions that CPUs can understand.
Each instruction is a binary number that represents a specific instruction the CPU can carry out. These instructions are stored in memory before being transferred to the CPU in the Fetch Decode Execute cycles
Machine code is the lowest level language a computer can be programmed in as each instruction is directly linked to hardware and logic built into the CPU.
Advantages of Machine Code
Disadvantages of Machine Code
Due to the difficulties humans have reading and writing machine code in binary, we created Assmebly Language.
Assembly Language uses mnemonics - commonly 3 letter abbreviations of English words. Each mnemonic is directly linked to one machine code instruction.
When a program is written in Assembly Langauge, the mnemonics are converted to their binary machine code equivalents to be ran on the CPU. This translation is done by an Assembler.
Advantages of Assembly Languages
Disadvantages of Assembly Language
Over time we produced easier to use languages which are much closer to plain English, and therefore much easier to write, read and understand. We refer to these languages as being "High Level".
High level languages include: Python, JavaScript, C, C#, Swift and Java.
Each high level language uses keywords, for example: print, input, if, else, while.
Unlike a mnemonic, a keyword does not directly link to machine code and will need to be translated to machine code. When translating a keyword to a machine code instruction one keyword may produce many machine code instructions.
Due to not being linked directly to one instruction set, high level languages can be portable between different hardware configurations. For example an application written in C# can be ran on a variety of different types of CPUs and hardware platforms.
Advantages of High Level Languages
Disadvantages of High Level Languages
CPUs can only understand Machine Code, therefore any program written in another language must be translated to Machine Code so that the CPU can execute its instructions.
There are three types of translators:
An interpreter reads source code and translates it one line at a time into machine code to be executed on the CPU. Once the machine code instructions have been executed, the next line of source code is then translated, and so on.
To run a program that is written in an interpreted language the computer it runs on must have the interpreter installed.
interpretered Langauges include: Python, JavaScript, PHP, and Ruby.
In order for a user to run an interpreted program the user must have the source code. This means that the user will have access to change the source code and could copy it.
Interpreted Langauges tend to be highly portable, and can be ran on a computer system providing the interpreter is available for the specific hardware.
Due to interpreter programs being translated like by line, the programs tend to be less performant and are not used in applications which require higher performance.
Interpreted Langauges are easier to debug because the program will crash as they are translated at the line of source code where there is an error.
A Compiler translates all the source code for a program into machine code before it is executed. This process is carried out by the developer when they are ready to ship their program.
A compiler produces an executable which contains the machine code instructions which allows it to run its instructions on a CPU. This can be ran without the source code or the compiler being installed. Due to being converted into machine code ahead of time compiled programs tend to be more performant.
Executables cannot be shared between different types of CPU. A different executable must be compiled for each type of CPU or platform it needs to run on. If download a program off the internet you may find various versions of an executable, for example x86, x86_64 and ARM64.
Some larger programs are broken into modules to make them more manageable. At compilation, each module is compiled into an object file and a linker is used to combine them into a single executable file.