Assembly Language and Machine Code
Assembly Language and Machine Code
Assembly Language:
• Assembly language was developed to simplify the process.
• It uses mnemonics (e.g., `LDD`, `ADD`, `STO`) instead of binary, but it
closely mirrors machine code.
• Each assembly language instruction consists of:
• Opcode: Identifies the operation to be carried out by the CPU.
• Operand: Contains the data or address for the operation.
Stages of Assembly
Assembler Functionality
• The assembler translates each mnemonic into its corresponding machine
code instruction.
• It also checks the syntax and ensures only valid instructions are used,
speeding up development by catching errors early.
Types of Assemblers
1. Single-pass assembler:
• Translates code in a single pass.
• Produces a machine code program ready to be executed, but doesn't
handle labels used before their memory addresses are known.
2. Two-pass assembler
- Passes through the code twice.
- In the first pass, it stores labels and memory addresses.
- In the second pass, it generates the final machine code, including handling
labels that refer to forward instructions.
Pass 1:
- Reads the assembly program line by line.
- Ignores unneeded elements like comments.
- Allocates memory addresses to each line.
- Verifies the opcode.
- Adds labels to a symbol table with memory addresses.
Pass 2:
- Re-reads the program.
- Generates the object code with opcodes and operands based on the symbol
table.
- Saves and executes the program.
Example:
If a label is used before it’s defined (a forward reference), it is handled in the
second pass. For example, `Found` might refer to an instruction yet to be
defined.
A symbol table stores labels and their memory addresses. In the example
provided:
- `Notfound` is at memory address 100.
- `Found` is at memory address 104.