Understand that assembly language uses mnemonics and requires an assembler

Resources | Subject Notes | Computer Science

Types of Programming Languages: Assembly Language

This section focuses on understanding assembly language, its characteristics, and the role of an assembler.

What is Assembly Language?

Assembly language is a low-level programming language. This means it is very close to the machine's instruction set. It uses mnemonic codes to represent machine instructions.

Unlike high-level languages like Python or Java, assembly language is not easily readable or portable across different computer architectures.

Mnemonic Codes

Assembly language uses mnemonics – short, easy-to-remember abbreviations – to represent machine instructions. For example, instead of a binary code representing "add two numbers," assembly might use a mnemonic like ADD.

Here's a simple example:


  ADD  R1, R2  ; Add the contents of register R2 to register R1 and store the result in R1

In this example, ADD is the mnemonic, and R1 and R2 represent registers within the processor.

The Role of an Assembler

Because assembly language uses mnemonics, a special program called an assembler is required to translate the assembly code into machine code. This process is called assembly or translation.

The assembler reads the assembly code, interprets the mnemonics, and converts them into the binary instructions that the computer's processor can directly execute.

How an Assembler Works

  1. Reads the Assembly Code: The assembler reads the source code written in assembly language.
  2. Interprets Mnemonics: It identifies the mnemonics and their corresponding machine instructions.
  3. Translates to Machine Code: It converts the mnemonics and any symbolic addresses (labels) into their equivalent binary machine code.
  4. Creates an Object File: The output is an object file containing the machine code instructions.
  5. Linking (Optional): If the program uses external libraries, a linker combines the object file with the necessary library code to create an executable file.

Example of Assembly Code and its Translation

Assembly Code Mnemonic Meaning Machine Code (Example)
MOV R1, #10 MOV Move the immediate value 10 into register R1. 10101010 (This is a simplified example; actual machine code varies)
ADD R3, R1 ADD Add the contents of register R1 to register R3 and store the result in R3. 00000011 00000001 00000010 (Simplified example)
JMP label JMP Jump to the instruction labeled "label". 10110000 00000001 (Simplified example)

Figure: Suggested diagram: A diagram showing the flow of assembly language through an assembler, from source code to machine code.

Suggested diagram: A diagram showing the flow of assembly language through an assembler, from source code to machine code.

Advantages and Disadvantages of Assembly Language

  • Advantages:
  • Direct control over hardware.
  • Can be very efficient in terms of speed and memory usage.
  • Disadvantages:
  • Difficult to read and write.
  • Time-consuming to develop.
  • Not portable across different architectures.

When is Assembly Language Used?

Assembly language is typically used in situations where:

  • Performance is critical (e.g., embedded systems, device drivers).
  • Direct hardware control is required.
  • Memory constraints are severe.