Simple 8085 Programs

8085 Assembly Language Programs - For Exam

1. 8-bit Addition

Instruction Explanation
LDA 2000H Load first number into A
MOV B,A Store in B
LDA 2001H Load second number
ADD B A = A + B
STA 2002H Store result into memory
HLT Stop execution

2. 16-bit Addition

Instruction Explanation
LHLD 2000H Load first 16-bit number into HL register pair
XCHG Exchange HL with DE (store first number in DE)
LHLD 2002H Load second 16-bit number into HL
DAD D Add DE to HL (HL = HL + DE)
SHLD 2004H Store result from HL into memory
HLT Stop execution
Fig: 8-bit and 16-bit Addition in 8085 Assembly Language

3. Subtraction (8-bit)

Instruction Explanation
LDA 2000H Load first number into accumulator
MOV B,A Copy first number into register B
LDA 2001H Load second number into accumulator
SUB B Subtract B from A (A = A - B)
STA 2002H Store result in memory
HLT Stop execution

4. Multiplication

Instruction Explanation
MVI B,05H Load multiplier into register B
MVI C,03H Load multiplicand into register C
MVI A,00H Clear accumulator
LOOP: ADD C Add multiplicand to accumulator
DCR B Decrement counter
JNZ LOOP Repeat until B becomes zero
STA 2000H Store result
HLT Stop execution

5. Division

Instruction Explanation
MVI B,03H Load divisor into register B
LDA 2000H Load dividend into accumulator
MVI C,00H Initialize quotient to zero
LOOP: CMP B Compare A with divisor
JC END If A < B, jump to END
SUB B Subtract divisor from A
INR C Increment quotient
JMP LOOP Repeat loop
END: STA 2001H Store remainder
MOV A,C Move quotient to accumulator
STA 2002H Store quotient
HLT Stop execution

6. Largest Number

Instruction Explanation
LXI H,2000H Load address of array
MOV C,M Load count into register C
INX H Point to first element
MOV A,M Assume first element as largest
LOOP: INX H Move to next element
CMP M Compare with current largest
JNC SKIP If A ≥ M skip update
MOV A,M Update largest value
SKIP: DCR C Decrease counter
JNZ LOOP Repeat loop
STA 2100H Store result
HLT Stop execution

7. Smallest Number

Instruction Explanation
LXI H,2000H Load array address
MOV C,M Load count
INX H Point to first element
MOV A,M Assume smallest
LOOP: INX H Next element
CMP M Compare values
JC SKIP If A < M skip
MOV A,M Update smallest
SKIP: DCR C Decrease count
JNZ LOOP Repeat
STA 2100H Store result
HLT Stop execution

8. BCD → ASCII

Instruction Explanation
LDA 2000H Load BCD value
ANI 0FH Mask upper bits
ADI 30H Add ASCII offset
STA 2001H Store ASCII result
HLT Stop execution

9. ASCII → BCD

Instruction Explanation
LDA 2000H Load ASCII value
SUI 30H Subtract ASCII offset
STA 2001H Store BCD result
HLT Stop execution