8085 Assembly Language Programming Guide
8085 Assembly Language Programming Guide
Programming in 8085
Microprocessor
A comprehensive guide to data handling, transfer operations, and
arithmetic functions in the 8085 microprocessor assembly language
programming.
Introduction to 8085 Assembly Language
The Intel 8085 is an 8-bit microprocessor that was introduced in
1976 as a successor to the popular 8080 chip. Assembly language
programming for the 8085 provides direct control over hardware
resources through simple mnemonic instructions.
Special Registers
The Accumulator (A) is the primary register for arithmetic and logical
operations. The Flag register contains status bits that reflect the results
of operations.
8085 Registers and Register Pairs
Individual Registers (8-bit) Register Pairs (16-bit)
Flags are stored in the Flag register and are automatically modified by arithmetic and logical instructions. They provide essential
information about the result of an operation and can be tested by conditional jump instructions.
Addressing Modes in 8085
Immediate Addressing
Register Addressing
Operand is in a register
Direct Addressing
Indirect Addressing
Implicit Addressing
Examples: MOV r1, r2; MOV r, M; MOV M, r Examples: LDA addr; LDAX rp; LXI rp, data16
Data transfer instructions are the workhorses of assembly programming, facilitating the movement of information through the
system. They typically do not affect flag bits (with some exceptions) and are foundational for implementing algorithms.
MOV Instruction
Syntax Examples
MOV destination, source MOV B, C ; Copy content of register C to BMOV A, M ; Copy content from memory
location ; pointed by HL to accumulatorMOV M, D ; Copy content of
The MOV instruction transfers 8-bit data from a source operand to a destination operand. register D to memory ; location pointed by HL
Characteristics
MVI r, dataMVI M, data MVI B, 32H ; Load 32H into register BMVI M, 0FFH ; Load FFH into memory location
; pointed by HLMVI A, 00H ; Clear accumulator by loading 00H
The MVI (Move Immediate) instruction loads an immediate 8-bit value into a register or memory location.
Characteristics
LDA 2050H; Load accumulator with contents of ; memory location STA 3050H; Store accumulator contents to ; memory location 3050H
2050H
3-byte instruction: opcode + 16-bit address 3-byte instruction: opcode + 16-bit address
Both LDA and STA provide direct memory access without using register pairs as pointers, making them efficient for single-value transfers to specific memory locations.
LXI Instruction
Syntax Examples
LXI rp, data16 LXI H, 2050H ; Load HL pair with 2050H ; H gets 20H, L gets 50HLXI
B, 0000H ; Clear BC pairLXI SP, 8FFFH ; Initialize stack pointer
Where rp is a register pair (B, D, H or SP) and data16 is a 16-bit immediate value.
Characteristics
XCHG (Exchange D & E with H & L) XTHL (Exchange H & L with Stack)
Exchanges the contents of the HL register pair with the DE register pair. Exchanges the contents of the HL register pair with the top two bytes of the stack.
XCHG; Before: H=25H, L=36H, D=47H, E=58H; After: H=47H, L=58H, XTHL; If stack top contains 2B3CH and HL=47A9H; After: HL=2B3CH,
D=25H, E=36H stack top=47A9H
1-byte instruction, 4 T-states, no flags affected 1-byte instruction, 16 T-states, no flags affected
These exchange instructions provide efficient ways to swap data without using temporary storage, optimizing both code size and execution speed.
Practical Data Handling Example
Scenario: Move Data Between Locations
Let's examine how to move an 8-bit value from memory location 2050H to register B, manipulate
it, and then store the result at location 3050H.
LDA 2050H ; Load value from 2050H to AMOV B, A ; Copy value from A to BADD
B ; Add B to A (doubles the value)STA 3050H ; Store result to 3050H
This sequence demonstrates the combined use of direct and register addressing to process data efficiently.
Execution Steps
Steps in Writing an Assembly Program
Problem Analysis
Understand the requirements, identify inputs and outputs, and determine the processing needed.
Algorithm Development
Design the step-by-step solution approach, breaking complex problems into smaller, manageable tasks.
Flowchart Creation
Create a visual representation of the program logic to identify process flow, loops, and decision points.
Instruction Writing
Translate the algorithm into assembly language instructions, considering registers and memory usage.
The processor:
2 STA 3050H
Stores the content of the accumulator into memory location 3050H.
The processor:
3 HLT
Halts the processor until a reset or interrupt occurs.
The processor:
Embedded Systems
Resource-constrained devices rely on efficient data handling to process sensor
inputs, manage displays, and control actuators with minimal overhead.
Real-time Control
Applications requiring precise timing use assembly for predictable data transfers
between memory, I/O ports, and processing units.
Bootloaders
System initialization code uses data transfer instructions to set up hardware
configurations and load operating systems into memory.
Introduction to Arithmetic Operations
Arithmetic operations form the computational core of assembly
language programming, enabling mathematical processing of data.
The 8085 provides a variety of instructions for performing
calculations on 8-bit and 16-bit values.
Add registers, memory, or immediate values to the Subtract registers, memory, or immediate values from
accumulator, with or without considering the carry flag. the accumulator, with or without considering the borrow
(carry flag).
Increase the value of a register, memory location (INR), Decrease the value of a register, memory location (DCR),
or register pair (INX) by one. or register pair (DCX) by one.
ADD Instruction
Syntax Examples
ADD r ; Add register to accumulatorADD M ; Add memory to accumulator ADD B ; A = A + BADD M ; A = A + [HL]; Example with values:; If A = 3CH, B = 2AH; After ADD
B:; A = 66H; CY = 0, Z = 0, S = 0, P = 1, AC = 1
The ADD instruction adds the content of a register or memory location to the accumulator and stores the result in the
accumulator.
Characteristics
ADI data ; Add immediate data to accumulator ADI 57H ; A = A + 57HADI 0FFH ; A = A + FFH (max value)ADI 00H ; No change to A, may affect
flags; Example with values:; If A = 78H; After ADI 95H:; A = 0DH; CY = 1, Z = 0, S = 0, P = 0, AC =
The ADI (Add Immediate) instruction adds an immediate 8-bit value to the accumulator and stores the result in the accumulator. 1
Characteristics
ADC r ; Add register and carry to AADC M ACI data ; Add immediate data and carry to A
; Add memory and carry to A
Adds an immediate 8-bit value and the carry flag to the
Adds the content of a register or memory location and the accumulator.
carry flag to the accumulator.
Operation: A ← A + data + CY
Operation: A ← A + r/M + CY
Example: If A=95H, CY=1, then after ACI 6AH: A=00H, CY=1
Example: If A=95H, B=6AH, CY=1, then after ADC B: A=00H, CY=1
ADC and ACI instructions are essential for multi-byte addition operations where the carry from a lower byte addition must be
included when adding higher bytes.
SUB and SUI Instructions
SUB (Subtract) SUI (Subtract Immediate)
SUB r ; Subtract register from ASUB M ; SUI data ; Subtract immediate data from A
Subtract memory from A
Subtracts an immediate 8-bit value from the accumulator.
Subtracts the content of a register or memory location from
Operation: A ← A - data
the accumulator.
Example: If A=95H, then after SUI 6AH: A=2BH, CY=0
Operation: A ← A - r/M
In 8085, the carry flag acts as a borrow flag for subtraction. It is set (1) if no borrow is required and reset (0) if a borrow is needed.
This is the opposite of how many modern processors handle borrow.
INR and DCR Instructions
INR (Increment) DCR (Decrement)
Increases the content of a register or memory location by 1. Decreases the content of a register or memory location by 1.
Affects all flags except carry flag (CY) Affects all flags except carry flag (CY)
Example: If B=FFH, after INR B: B=00H, Z=1, CY unchanged Example: If B=00H, after DCR B: B=FFH, S=1, Z=0, CY unchanged
INR and DCR are commonly used for loop control and counter operations. Their unique characteristic of not affecting the carry flag
allows them to be used within multi-byte arithmetic operations without disrupting the carry propagation.
INX and DCX Instructions
INX (Increment Register Pair) DCX (Decrement Register Pair)
Result Storage
Flag Update
The result is stored in the destination
Based on the operation result, the
operand, typically the accumulator
processor updates the appropriate
(except for INR/DCR which modify the
status flags in the flag register.
operand directly).
Flags Affected by Arithmetic
ADD/ADI Yes Yes Yes Yes Yes
INX/DCX No No No No No
Understanding how instructions affect flags is critical for conditional branching and error detection in assembly programs. For
example, the Z flag can be tested after arithmetic to check if a result is zero, while the CY flag indicates overflow in addition or
underflow in subtraction.
ALP: Add Two 8-bit Numbers
Problem Statement Assembly Program
Add two 8-bit numbers stored in registers D and E, then store the result in register C.
; Program to add two 8-bit numbers MVI D, 99H ; Load first number MVI
Algorithm E, 39H ; Load second number MOV A, D ; Move first number to A ADD E
; Add second number to A MOV C, A ; Store result in C HLT ;
1. Load the first number into register D Halt the program
2. Load the second number into register E
; Program to demonstrate INR and DCR MVI B, 7FH ; Load test value into B
INR B ; Increment B (7FH + 1 = 80H) MVI C, 00H ; Load test value into C
DCR C ; Decrement C (00H - 1 = FFH) HLT ; Halt the program
After execution:
Special Cases
ALP: Adding Multiple Numbers
Problem Statement
Add three 8-bit numbers stored in registers B, C, and D, then store the result in register E.
Assembly Program
Execution Flow
Multi-Byte Addition Example
Problem Statement
Add two 16-bit numbers stored in BC and DE register pairs, then store the result in HL pair.
Assembly Program
Result Analysis
Initial values:
Looping and Counters in ALP
Process Data
Initialize Counter
Execute the operations needed for
Load an initial count value into a register. each iteration.
Example: MVI B, 0AH (Set counter to 10) Example: Data manipulation, memory
access, calculations
Copy a block of 10 bytes from a source memory location starting at 2050H to a destination starting at 3050H.
Assembly Program
Program Operation
ALP: Block Sum Calculation
Problem Statement
Calculate the sum of 8 bytes stored in consecutive memory locations starting at 2050H and store the result at 3050H.
Assembly Program
; Block sum calculation program LXI H, 2050H ; Initialize memory pointer MVI
B, 08H ; Set counter to 8 bytes MVI A, 00H ; Initialize sum to zero LOOP: ADD
M ; Add memory content to sum INX H ; Increment memory pointer DCR B
; Decrement counter JNZ LOOP ; Repeat until counter = 0 STA 3050H
; Store final sum HLT ; Halt when done
Program Operation
Debugging Techniques
• Single-step execution to observe instruction effects
• Breakpoints at critical program locations
• Register and memory monitoring during execution
• Flag status checking after arithmetic operations
• Program trace logs to track execution flow
Modern 8085 simulators like GNUSim8085, 8085sim, and Visual 8085 provide
valuable debugging features including register visualization, memory dumps, and
execution tracing to help identify and resolve programming errors.
Best Practices for Writing 8085 ALP
Code Organization
• Use consistent indentation and formatting
• Group related instructions into logical blocks
• Use meaningful labels for program sections
• Maintain a clear separation between code and data
Documentation
• Add comments explaining non-obvious operations
• Document register usage and purpose
• Include algorithm explanation at the beginning
• Note any critical timing or memory constraints
Optimization
• Minimize memory access when possible
• Use register operations instead of memory when feasible
• Reduce instruction count in critical loops
• Consider execution time for time-sensitive applications
Robustness
• Check for boundary conditions and edge cases
• Handle overflow/underflow appropriately
• Consider input validation for external data
• Test with diverse data sets to ensure reliability
Applications of 8085 Arithmetic/Data Handling
The 8085 remains an excellent platform for teaching fundamental computer architecture concepts:
Many computer science and engineering programs still use 8085 assembly programming to introduce low-
level system concepts before moving to modern architectures.
Additional Learning Resources
1 2
Textbooks Simulators
• "Microprocessor Architecture, • GNUSim8085: Open-source 8085
Programming and Applications with simulator with GUI
the 8085" by Ramesh Gaonkar • [Link]: Online browser-
• "The 8085 Microprocessor: based simulator
Fundamentals and Applications" by • Virtual 8085: Windows-based
K. Udaya Kumar simulator with visualization
• "Digital Computer Electronics" by • emulator8085: Mobile app for on-
Albert P. Malvino the-go practice
Practice Exercises
• Implement basic calculator functions
• Create sorting and searching algorithms
• Develop simple data encryption/decryption routines
• Build binary to BCD conversion utilities
Conclusion
Assembly language programming for the 8085 microprocessor provides a fundamental understanding of
how computers operate at the lowest level. Mastering data handling and arithmetic operations forms
the foundation for all higher-level programming concepts.
• The 8085's register architecture and instruction set provide a complete platform for learning
assembly fundamentals
• Data transfer instructions enable efficient movement of information throughout the system
• Arithmetic operations form the computational core of any program
• Proper understanding of flags and addressing modes is critical for effective programming
While modern programming typically occurs at higher levels of abstraction, the principles learned