W6 Programming in 8085 Module 5
W6 Programming in 8085 Module 5
W6 Programming in 8085 Module 5
Programming in 8085
Programming in 8085
The memory addresses given in the program are for a particular
microprocessor kit. These addresses can be changed to suit the
microprocessor kit available in your system.
Course Module
[Microprocessor] 2
Programming in 8085
Program
1. LXI H, 2501H : "Get address of first number in H-L pair. Now H-
L points to 2501H"
2. MOV A, M : "Get first operand in accumulator"
3. INX H : "Increment content of H-L pair. Now, H-L points 2502H"
4. ADD M : "Add first and second operand"
5. INX H : "H-L points 4002H"
6. MOV M, A : "Store result at 2503H"
7. HLT : "Stop"
Subtract two 8-bit numbers
Example
(2501 H) = 49H
(2502 H) = 32H
Result (2503 H) = 49H - 32H = 17H
Program
1. LXI H, 2501H : "Get address of first number in H-L pair. Now H-
L points to 2501H"
2. MOV A, M : "Get first operand in accumulator"
3. INX H : "Increment content of H-L pair. Now, H-L points 2502H"
4. SUB M : "Subtract first to second operand"
5. INX H : "H-L points 4002H"
6. MOV M, A : "Store result at 2503H"
7. HLT : "Stop"
Course Module
[Microprocessor] 3
Programming in 8085
(2503H) = B7H
(2504H) = 5AH
(2505H) = CCH
(2506H) = 76H
Program
Add two 16-bits number with ADD and ADC instruction
1. LHLD 2501H : "Get 1st 16-bit number in H-L pair"
2. XCHG : "Save 1st 16-bit number in DE"
3. LHLD 2503H : "Get 2nd 16-bit number in H-L pair"
4. MOV A, E : "Get lower byte of the 1st number"
5. ADD L : "Add lower byte of the 2nd number"
6. MOV L, A : "Store result in L-register"
7. MOV A, D : "Get higher byte of the 1st number"
8. ADC H : "Add higher byte of the 2nd number with CARRY"
9. MOV H, A : "Store result in H-register"
10. SHLD 4004H : "Store 16-
bit result in memory locations 2505H and 2506H"
11. HLT : "Stop"
Course Module
[Microprocessor] 4
Programming in 8085
Course Module
[Microprocessor] 5
Programming in 8085
Program
1. LXI H, 2500H : "HL Points 2500H"
2. MOV A, M : "Get first operand"
3. INX H : "HL Points 2501H"
4. ADD M : "Add second operand"
5. INX H : "HL Points 2502H"
6. MOV M, A : "Store the lower byte of result at 2502H"
7. MVIA, 00 : "Initialize higher byte result with 00H"
8. ADC A : "Add carry in the high byte result"
9. INX H : "HL Points 2503H"
10. MOV M, A : "Store the higher byte of result at 2503H"
11. HLT : "Terminate program execution"
Course Module
[Microprocessor] 6
Programming in 8085
Course Module
[Microprocessor] 7
Programming in 8085
4. BACK: RAR
5. JNC SKIP
6. INR B
7. SKIP: DCR C
8. JNZ BACK
9. HLT
Course Module
[Microprocessor] 8
Programming in 8085
Program
The first number 84H is placed in the memory location 2501 H.
The second number 99H is placed in the memory location 2502H.
The result is stored in the memory location 2503 H.
LXI H, 2501H : "Address of first number in H-L pair"
MOV A, M : "1stt number in accumulator"
INX H : "Address of 2nd number in H-L pair"
CMP M : "compare 2nd number with 1st number"
JC AHEAD : "Yes, smaller number is in accumulator. Go to AHEAD"
MOV A, M : "No, get 2nd number in the accumulator"
STA 2503 H : "Store smaller number in 2503H"
HLT : "Stop"
Calculate the sum of series of even numbers
Example
2500 H = 4H
2501 H = 20H
2502 H = 15H
2503 H = 13H
2504 H = 22H
Result = 2505 H = 20+22= 42H
Program
The numbers are placed in the memory locations 2501 to 2504H.
The sum is to be stored in the memory location 2450H.
As there are 4 numbers in the series, count = 04
The initial value of the sum is made 00. The even number of the series are
taken one by one and added to the sum.
1. LDA 2500H
2. MOV C, A : "Initialize counter"
3. MVI B, 00H : "sum = 0"
4. LXI H, 2501H : "Initialize pointer"
5. BACK: MOV A, M : "Get the number"
Course Module
[Microprocessor] 9
Programming in 8085
Course Module