Simple 8085 Programs

8085 Assembly Language Programs - For Exam

1. 8-bit Addition

InstructionExplanation
LDA 2000HLoad first number into A
MOV B,AStore in B
LDA 2001HLoad second number
ADD BA = A + B
STA 2002HStore result into memory
HLTStop execution

2. 16-bit Addition

InstructionExplanation
LHLD 2000HLoad first 16-bit number into HL register pair
XCHGExchange HL with DE (store first number in DE)
LHLD 2002HLoad second 16-bit number into HL
DAD DAdd DE to HL (HL = HL + DE)
SHLD 2004HStore result from HL into memory
HLTStop execution

3. Subtraction (8-bit)

InstructionExplanation
LDA 2000HLoad first number into accumulator
MOV B,ACopy first number into register B
LDA 2001HLoad second number into accumulator
SUB BSubtract B from A (A = A - B)
STA 2002HStore result in memory
HLTStop execution

4. Multiplication

InstructionExplanation
MVI B,05HLoad multiplier into register B
MVI C,03HLoad multiplicand into register C
MVI A,00HClear accumulator
LOOP: ADD CAdd multiplicand to accumulator
DCR BDecrement counter
JNZ LOOPRepeat until B becomes zero
STA 2000HStore result
HLTStop execution

5. Division

InstructionExplanation
MVI B,03HLoad divisor into register B
LDA 2000HLoad dividend into accumulator
MVI C,00HInitialize quotient to zero
LOOP: CMP BCompare A with divisor
JC ENDIf A < B, jump to END
SUB BSubtract divisor from A
INR CIncrement quotient
JMP LOOPRepeat loop
END: STA 2001HStore remainder
MOV A,CMove quotient to accumulator
STA 2002HStore quotient
HLTStop execution

6. Largest Number

InstructionExplanation
LXI H,2000HLoad address of array
MOV C,MLoad count into register C
INX HPoint to first element
MOV A,MAssume first element as largest
LOOP: INX HMove to next element
CMP MCompare with current largest
JNC SKIPIf A ≥ M skip update
MOV A,MUpdate largest value
SKIP: DCR CDecrease counter
JNZ LOOPRepeat loop
STA 2100HStore result
HLTStop execution

7. Smallest Number

InstructionExplanation
LXI H,2000HLoad array address
MOV C,MLoad count
INX HPoint to first element
MOV A,MAssume smallest
LOOP: INX HNext element
CMP MCompare values
JC SKIPIf A < M skip
MOV A,MUpdate smallest
SKIP: DCR CDecrease count
JNZ LOOPRepeat
STA 2100HStore result
HLTStop execution

8. BCD → ASCII

InstructionExplanation
LDA 2000HLoad BCD value
ANI 0FHMask upper bits
ADI 30HAdd ASCII offset
STA 2001HStore ASCII result
HLTStop execution

9. ASCII → BCD

InstructionExplanation
LDA 2000HLoad ASCII value
SUI 30HSubtract ASCII offset
STA 2001HStore BCD result
HLTStop execution