Assembly Language Basics
Labels, mnemonics, operands.
Writing programs directly in machine language means dealing with binary opcodes and memory addresses, which is error-prone and difficult to understand. Assembly language solves this by providing human-readable symbolic representations for each machine instruction. For the 8085 microprocessor, assembly language forms the foundation of all programming, and understanding its structure, specifically labels, mnemonics, and operands, is essential before writing even a simple program.
Core Concept Explanation
An assembly language program is a sequence of statements, each corresponding to one machine instruction or an assembler directive. Every statement can have up to four fields: a label, a mnemonic, an operand, and a comment. Not all fields are required in every statement, but the mnemonic field is almost always present since it defines the operation.
A label is a symbolic name assigned to the memory address of the current instruction. It must begin with a letter and is followed by a colon. Labels are used as targets for jump and call instructions. For example, if a loop body starts at an instruction labeled BACK:, a conditional jump like JNZ BACK will cause program control to return to that instruction.
A mnemonic is the symbolic name of an instruction. Each mnemonic maps directly to one or more opcodes in the 8085 instruction set. For instance, MVI stands for Move Immediate, MOV stands for Move Register, and ADD stands for Add. The assembler software translates these mnemonics into the binary machine code that the CPU actually executes.
An operand specifies the data or location the instruction works on. The 8085 instruction set uses three types of operands: register operands (like A, B, H, L), immediate data (like 05H or 25D), and memory addresses (like 2050H). Some instructions require two operands separated by a comma, such as MVI A, 05H, while others like HLT require none.
Mathematical Expression
Assembly language itself is not described by a single formula, but the assembler translation process follows a defined mapping. Each mnemonic corresponds to a fixed opcode. For example, MVI A, data produces a two-byte machine code: the first byte is the opcode 3EH and the second byte is the immediate data value. The assembler replaces symbolic labels with their actual 16-bit memory addresses during the assembly process, a step called symbol resolution.
Practical Understanding
Labels are critical for structured programs. When writing a counting loop, the label marks the start of the loop body so that the conditional jump at the end can refer back to it. Without labels, the programmer would need to calculate exact jump distances in bytes, which is impractical and fragile if the code is modified.
Mnemonics must be written exactly as defined in the 8085 instruction set. The assembler does not accept spelling variations. Operands must also match the instruction format. For instance, ADD B is valid because ADD takes a register operand, but ADD 05H is not a valid ADD instruction in 8085 (the correct instruction for adding immediate data is ADI).
Given:
A program that adds two numbers 04H and 03H stored in memory.
Why this applies:
MVI loads immediate data, ADD adds register to accumulator, HLT stops execution.
Formula:
Result = Operand1 + Operand2 loaded into A via MVI and ADD
Assembly Statements:
MVI A, 04H ; Load 04H into accumulator (mnemonic: MVI, operand: A, 04H)
MVI B, 03H ; Load 03H into register B (mnemonic: MVI, operand: B, 03H)
ADD B ; A = A + B = 04H + 03H (mnemonic: ADD, operand: B)
HLT ; Stop execution (mnemonic: HLT, no operand)
Calculation:
04H + 03H = 07H
Final Answer:
Accumulator A = 07H after executionExam Tip: Labels in 8085 assembly must end with a colon in the source code but are referenced without a colon in operand fields. A common error is writing JNZ BACK: instead of JNZ BACK. Also remember that comments begin with a semicolon and are completely ignored by the assembler.
Key Structural Points
- A label must start at the beginning of a line, begin with an alphabetic character, and be followed by a colon. It is optional in any given statement.
- The mnemonic field tells the assembler which instruction to generate. It is the core of every executable statement.
- Operands follow the mnemonic and are separated from it by a space. When two operands are used, they are comma-separated.
- Comments begin with a semicolon and extend to the end of the line. They improve readability and are stripped during assembly.
- The assembler performs two passes: the first pass builds the symbol table from labels, and the second pass generates machine code with resolved addresses.
Quick Revision
- Assembly language uses symbolic mnemonics for CPU instructions. Each mnemonic maps to one opcode or a short opcode sequence.
- Four fields per statement: Label (optional), Mnemonic (required for executable lines), Operand (instruction-dependent), Comment (optional, after semicolon).
- Labels end with colon in definition but are written without colon when referenced as operands in JMP, CALL, and conditional jump instructions.
- Three operand types: register (A, B, H, L, etc.), immediate data (05H, 10D), memory address (2050H).
- Assembler builds a symbol table in first pass and generates machine code in second pass.
- Common trap: ADI is used for immediate addition, not ADD. ADD only takes a register operand in 8085.
Assembly Language Basics Quiz
Test your understanding of labels, mnemonics, and operand fields in 8085 assembly language programs.
Q1.In an 8085 assembly language statement, what does a label represent?
Related Articles
BCD Arithmetic
DAA instruction usage.
6 min read
Code Conversion
BCD to Binary, Binary to BCD, ASCII.
9 min read
Stack and Subroutines
PUSH, POP, CALL, RET instructions.
12 min read
Time Delay Loops
Calculating delay using T-states.
11 min read
Looping and Indexing
Counters, pointers, array processing.
11 min read