Programming The 8085
Programming The 8085
UNIT 2
programming the 8085
(Date: 16-09-20 TO 21-10-20)
By:
ATIFA AQUEEL
Guest Teacher
Electronics Engg. Section
University Women’s Polytechnic, AMU
Syllabus
I. INTRODUCTION TO THE INTEL 8085
• Definition of microprocessor, generations and types of microprocessors,
most popular microprocessors.
• Architecture of 8085, brief description of ALU, register section, data &
address buses. Bus time sharing 8085 CPU pins and associated signal.
II. PROGRAMMING THE 8085
• Instruction, Group of instruction, Addressing modes of Instruction, 8085
instruction set. Machine Language, Assembly Language comparison,
Assembly Language programming (Simple Problems).
III. TIMING INSTRUCTION & EXECUTION
• Machine, Instruction, Fetch, Read, Write(IO/MEM) cycle timing diagram,
Interruption: Types of 8085 interrupt system, 8085 SID and SOD lines.
• For e.g.
1. MOV A,B : Move the content of reg B to reg A
2. MVI A, 25H : Move 25H to accumulator (Reg A)
3. LDA 2000H : Load the accumulator with the content present in memory
location 2000H.
4. LXI B, 2020H: Load the register pair BC with the content present in
memory location 2020H and 2021H. (X: Reg pair …16 bits)
21-10-2020 By: Atifa Aqueel 6
Arithmetic Group
• For e.g.
1. ADD B:
2. SUB C:
3. INR A:
4. DCR C:
• Note: These instructions may seem to be too many. But you can simply
remember them as “The instructions ending with the letter I, which stands
for immediate, are the instructions for immediate addressing mode” with
one exception though: the JMP instruction.
Q.3: Load the content of memory location 4050 directly to the accumulator
and transfer it to register B. The content of memory location 4050H is 25H.
Q.4: Move the content of memory location 2010H in register B indirectly, the
content of memory location 2010H is 1AH.
Q.5: Place 05H in accumulator. Increment it by one and store the result in
memory location 2400H.
ADD B
ADD M
ADC B
ADC M
ADI 20H
21-10-2020 By: Atifa Aqueel 32
ADI 20H
ACI 20H
DAD B
SUB B
SUB M
SBB r/SBB M
SBB B
/SBB M
SUI 55H
SBI 25H
INR M
DCR B
DCR M
INX B
DCX B
Q.1: ADD 96D and 69D, 84D and 92D, 98D and 99D
• 96D: 1001 0110 (BCD)
• 69D: 0110 1001 (BCD)
• 165D: 1111 1111 (FF IN HEX)
• DAA : 0110 0110 (+6 correction to LSBs AND +6 correction to MSBs)
01,65: 1, 0110 0101 (BCD)
21-10-2020 By: Atifa Aqueel 37
Examples
Q.1: Multiply 1245H by 2 .
Ans: LXI H, 1245H
DAD H
HLT
RLC
RAL
RRC
RAR
• Take a binary number. 0100. That’s 4 in decimal. Shift the ‘1’ towards left
by one position. You get 1000. That’s 8. There you go, you just multiplied
it by 2. Shift the ‘1’ in 0100 towards the right, and you get 2.
• In this instruction, the second and third byte instruction byte give the
address of the label where the program jumps.
• Address of the label is the address of the next instruction to be executed.
The program jumps to that location unconditionally.
2004 LDA 2501H Load the content of 2501H (i.e. one operand) to Accumulator
2008 LDA 2502H Load the content of 2501H (i.e. other operand) to Accumulator
200B ADD B Add the content of A and B and store the result in A
200D AHEAD: SHLD 2505H Store the value of HL pair (Result) in 2505H and
2506H.
2010 STA 2507H Store the carry (Accumulator content) in 2507H
2013 HLT Stop the program
21-10-2020 By: Atifa Aqueel 57
CALL Instruction
200DH
21-10-2020
HLT stop
By: Atifa Aqueel 67
PROGRAM 8
Ques: WAP to find the largest number in a data array. Assume the numbers are
98H, 75H, 88H, 99H stored in the memory locations 2501H to 2504H and
store the result in 2505H.
Address Label Mnemonics & Comments
Operands
2000 MVI C,04H Take count in Reg C
2002 MVI A,00H Get 00H in accumulator
2004 LXI H 2501H Address of 1st no in HL pair (M=98H)
2007 LOOP: CMP M Compare the no present in memory with the no present
in accumulator. Is A>M ?
2008 JNC AHEAD Yes, large no is in accumulator, goto ahead
200B MOV A,M No, get second no in accumulator
200C AHEAD: INX H Get address of 2nd no in HL pair
200D DCR C Decrement Count (C=C - 1)
200E JNZ LOOP If C ≠ 0, Jump to LOOP
2011 STA 2505H If C = 0, Store the result in 2505
201421-10-2020 HLT By: Atifa
StopAqueel 68
PROGRAM (H.W)
Ques: WAP to find the smallest number in a data array. Assume the numbers
are 98H, 75H, 88H, 99H stored in the memory locations 2501H to 2504H and
store the result in 2505H.
00 0 1 0 1 0 0 0 1 0 07
01 1 0 1 0 0 0 1 0 1 06
01 0 1 0 0 0 1 0 1 0 05
02 1 0 0 0 1 0 1 0 0 04
02 0 0 0 1 0 1 0 0 1 03
02 0 0 1 0 1 0 0 1 0 02
02 0 1 0 1 0 0 1 0 0 01
03 1 0 1 0 0 1 0 0 0 00
21-10-2020 By: Atifa Aqueel 70
Solution
Address Label Mnemonics Comments
& Operands
2000H MVI D,00H Initialize reg D for storing the result (D=00H)
2002H MVI C, 08H Take count in Reg C (C=08H)
2004H LDA 2501H Load the 8 bit number in accumulator from [2501H]
2007H LOOP: RAL Rotate the content of accumulator left with carry
2008H JNC AHEAD Check carry flag. If CY=0, goto AHEAD
200BH INR D If CY=1, Increment register D by 1
200CH AHEAD DCR C Decrement the count (Register C) by 1
:
200DH JNZ LOOP If C ≠ 0, Jump to LOOP
2010H MOV A,D If C = 0, Move the result (content of Reg D) to Accumulator
2011H STA 2502H Store the result in 2502H
2014H HLT Stop the program
LDA 2501 Load the content of 2501H (i.e. one operand) to Accumulator
LDA 2502H Load the content of 2501H (i.e. other operand) to Accumulator
LOOP: ADD D Add the content of A and D and store the result in A