Show understanding of the relationship between assembly language and machine code

Resources | Subject Notes | Computer Science

Assembly Language and Machine Code - A-Level Computer Science

4.2 Assembly Language and Machine Code

This section explores the fundamental relationship between assembly language and machine code, highlighting how human-readable instructions are translated into the binary form understood by a computer's processor.

What is Machine Code?

Machine code is the lowest-level programming language. It consists of binary instructions – sequences of 0s and 1s – that the computer's central processing unit (CPU) can directly execute. Each instruction typically performs a very basic operation, such as adding two numbers or moving data between memory locations.

What is Assembly Language?

Assembly language is a symbolic representation of machine code. It uses mnemonic codes (short, easy-to-remember abbreviations) to represent machine instructions. For example, instead of using a binary code for "add," assembly language might use the mnemonic "ADD."

The Relationship: Translation Process

The process of converting assembly language into machine code is called assembly. This is typically done by a program called an assembler.

The assembler reads the assembly code and translates each mnemonic instruction into its corresponding binary machine code equivalent. The resulting machine code is often stored in an object file, which can then be linked with other object files to create an executable program.

Example

Consider a simple assembly instruction to add two numbers, say 5 and 3, and store the result in a register.

Assembly Code: ADD R1, 5 ADD R1, 3

Corresponding Machine Code (example - architecture dependent):

Assembly Instruction Machine Code Explanation
ADD R1, 5 00001010 00000101 Adds the immediate value 5 to the contents of register R1.
ADD R1, 3 00001010 00000011 Adds the immediate value 3 to the contents of register R1.

Note that the actual machine code will vary depending on the processor architecture (e.g., x86, ARM).

Key Differences

| Feature | Assembly Language | Machine Code |

Feature Assembly Language Machine Code
Readability Human-readable (uses mnemonics) Binary (0s and 1s) - not directly readable by humans
Portability Less portable (architecture-specific) Highly architecture-specific
Complexity More complex to write and understand Simple, direct instructions for the CPU
Translation Requires an assembler for translation Directly executable by the CPU

In summary, assembly language provides a more manageable and understandable way to program at a low level, while machine code is the fundamental language directly executed by the computer's hardware.