0% found this document useful (0 votes)
10 views65 pages

Unit 2

Uploaded by

zufishan66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views65 pages

Unit 2

Uploaded by

zufishan66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

FUNDAMENTALS OF MICROPROCESSOR

UNIT 2
PROGRAMMING THE 8085
(DATE: 02-12-21:16-12-2021)
By:
ATIFA AQUEEL
Guest Teacher
Electronics Engg. Section
University Women’s Polytechnic, AMU
INSTRUCTION

16‐12‐2021 By: Atifa Aqueel 4


Opcodes and Operands

16‐12‐2021 By: Atifa Aqueel 5


Data Transfer Group

• 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)
16‐12‐2021 By: Atifa Aqueel 6
Arithmetic Group

• For e.g.
1. ADD B:
2. SUB C:
3. INR A:
4. DCR C:

16‐12‐2021 By: Atifa Aqueel 7


Other 3 Groups

16‐12‐2021 By: Atifa Aqueel 8


Instruction Word Size

16‐12‐2021 By: Atifa Aqueel 9


One Byte Instruction
• The instruction which has only one part i.e. opcodes is known as one byte
instruction. In other words one byte instructions include the opcode and
operand in the same byte and it is stored in only one memory location.

16‐12‐2021 By: Atifa Aqueel 10


Two-Byte Instruction
• In two byte instruction , the first byte is in its operand and the second byte
is either 8-bit data or address. For Example:

16‐12‐2021 By: Atifa Aqueel 11


Three Byte Instruction

16‐12‐2021 By: Atifa Aqueel 12


Q: Write the size of the following
instructions
1. SUB B
2. INR B
3. MVI B,25H
4. LXI D, 2500H
5. MOV M, A
6. SBI 38H
7. INX H
8. DCR D
9. CMA
10. RAL
11. LHLD 3000H

16‐12‐2021 By: Atifa Aqueel 13


Instruction and Data Formats
• The various techniques to specify data for instructions are:
1. 8-bit or 16-bit data may be directly given in the instruction itself.
2. The address of the memory location, I/O port or I/O device, where data
resides, may be given in the instruction itself.
3. In some instructions, only one register is specified. The content of the
specified register is one of the operands.
4. Some instructions specify two registers. The contents of the registers are
the required data.
5. In some instructions, data is implied. The most instructions of this type
operate on the content of the accumulator.
• Due to different ways of specifying data for instructions, the machine codes
of all instructions are not of the same length. It may 1-byte, 2-byte or 3-
byte instruction.

16‐12‐2021 By: Atifa Aqueel 14


8085 Addressing Modes
• Each instruction requires certain data on which it has to operate.
• The different technique by which the microprocessor specifies the operand
in an instruction is known as addressing mode.
• Intel 8085 supports the following addressing modes:

1. Immediate Addressing Modes


2. Register Addressing Modes
3. Direct Addressing Modes
4. Indirect Addressing Modes
5. Implicit Addressing Modes

16‐12‐2021 By: Atifa Aqueel 15


Immediate Addressing Mode
• In this mode, the 8/16-bit operand (data/address) is specified in the
instruction itself as one of its operand.
• In this mode, the number directly given by the programmer is moved into
the location specified. This location could be a register or an address in the
memory.
• In other words, we can understand the Immediate Addressing Mode as a
mode in which an immediate value is given to operate on.
• For Example:
1. MVI A, 25H ; Save 25H into the Accumulator
2. MVI C, 62H ; Save 62H into the C register
3. LXI B, 3050H ;Load B-C pair with value 3050H.
4. ADI 20H ;The value 20H is added to the contents of the accumulator.
5. SUI 22H ;The value 22H is subtracted from the contents of the
accumulator
16‐12‐2021 By: Atifa Aqueel 16
Immediate Addressing Mode
• Some other examples are:
1. LXI H, 3050H ;Load H-L pair with value 3050H. Higher byte 30H goes
in H while lower byte 50H goes in L
2. LXI SP, 4050H ;Load value 4050H in stack pointer register
3. JMP 9000H ;Jump to address 9000H.

• 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.

16‐12‐2021 By: Atifa Aqueel 17


Register Addressing Mode
• In register addressing mode the operand is in one of the general purpose
registers.
• The opcode specifies the address of the register in addition to the operation
to be performed.
• In this mode, the data to be accessed and operated upon is present in a
register and is accessed by specifying the name of the register.
• For Example:
1. MOV A, B ;Save contents of B in Accumulator
• This command moves the contents stored inside the B register to the
Accumulator.
2. ADD B ;Adds the value stored in B to the value in Accum.
3. SUB E ;Subtracts the value stored in E to that in Accum.
4. INR C ;Increments the contents of register C by 1
5. INX B ;Increments the contents of register pair BC by 1

16‐12‐2021 By: Atifa Aqueel 18


Direct Addressing Mode
• In this mode, the address of the operand is specified in the instruction itself.
• For example LDA 3000H: means the data at address 3000H is copied to
register A.
• In other words, we access the data stored in a memory location using its
address. Consider the example
1. LDA 2034H ;Load the content at memory location 2034H into the
Accumulator
2. LHLD 2040H ;Load the content at 2040H into register L and contents at
the next location 2041H into register H
3. STA 3030H ;Load the content at memory location 3030H into the
Accumulator
4. SHLD 2040H ;Load the contents of the register L into memory location
with address 2040H and load the ;contents of register H at the next
memory location 2041H
16‐12‐2021 By: Atifa Aqueel 19
Program 1
• Write a program to add two numbers present in memory locations 2000H
and 2001H and add 25H to the result and store the final result in memory
location 4000H.
Memory
Address Data
2000H 20H
2001H 30H


4000H ……………..

16‐12‐2021 By: Atifa Aqueel 20


Memory Label Mnemonics/ Opcode Comments
Address Opcodes
2000 MVI C, 00H 0E, 00 Clear Register C
2002 MVI A, 98H 3E, 98 Move 99H in Accumulator
2004 MVI B, 98H 06, 98 Move 98H in Register B
2006 ADD B 80 Add the content of A and B and store
the result in A
2007 JNC 200B D2, 0B, 20 Jump to AHEAD if CY = 0
200A INRC 0C If CY=1, increment Reg C by 1, C=1
200B AHEAD: STA 2503H 32, 03,25 Store the result (Accum) in 2503H
200E MOV A,C 79 Move content of C (i.e. Carry) in
Accum.
200F STA 2504H 32, 04, 25 Store the Carry (Accum) in 2504H
2012 RST 5 EF End the program

16‐12‐2021 By: Atifa Aqueel 21


Solution
• LDA 2000H : Load Acc with the content of mem location
2000H (A = 20H)
• MOV B,A (B=A=20H)
• LDA 2001H (A=30H)
• ADD B (A+B) AND RESULT WILL BE STORED IN ACC
• ADI, 25H (A+25)
• STA 4000H ( 4000H= A)
• HLT

16‐12‐2021 By: Atifa Aqueel 22


Register Indirect Addressing Mode
• In this mode, the register(s) holds the address of the location from which
data is to be retrieved.
• Here the address of the operand is specified in a register pair, Hence this
type of instructions indirectly point to the operand.
• MOV A, M ;move contents of the memory location whose address is held
by HL pair into the Accumulator.

16‐12‐2021 By: Atifa Aqueel 23


Example
• Consider the following lines of instructions.
• Suppose it is known that the number 25H is stored at memory location with
address 2030H and the programmer wants to transfer that data to
accumulator.
• MVI H, 20H
OR LXI H, 2030H
• MVI L, 30H
• MOV A, M ;M stands for memory (i.e HL pair)
• MVI M, 92H
• After running the above code, register A will hold the value 25H.

16‐12‐2021 By: Atifa Aqueel 24


Explanation
1. After the execution of the first line, register H will have value 20H stored in it.
2. After the execution of the second line, register L will have value 30H stored in
it. So, now we have 2030H stored in register pair HL.
3. The instruction in the third line tells the microprocessor to look at the address
(in the memory) given by the HL pair which is now 2030H. So, the
microprocessor looks at the location with address 2030H and loads the content
stored there into the accumulator. As we assumed, the memory location with
address 2030H had the number 25H stored in it. So, the microprocessor will
copy it and paste it in the accumulator. And hence, the accumulator will
contain 25H.
4. In the fourth line of instruction, we tell the microprocessor to move the value
given by us, i.e. 92H to the memory location. And the address of the memory
location is read from the HL register pair. HL pair still holds the value 2030H.
So, the microprocessor will store 25H at the memory location with address
2030H.
5. So, in the end, the Accumulator will hold the value 25H and the memory
location with address 2030H will hold the value 92H.
16‐12‐2021 By: Atifa Aqueel 25
Register Indirect Addressing Mode
• A very important point to note here is that the address of a memory location
is of 16-bit size but the data stored in a single memory location is 8 bits.
• Some more instructions which use this mode of addressing.
1. ADD M ;Add contents of the memory location whose address is held by HL
pair to the contents of theAccumulator
2. INR M ;Add contents of the memory location whose address is held by HL
pair is incremented by 1
3. CMP M ;16 bit number from HL pair is picked up. Then, contents at the
address given by picked up number is ;compared with those of the
accumulator.
• The result of the comparison is shown by setting the flags of ;the PSW as
follows: ;
• * if (A) < (reg/mem): carry flag is set ;
• * if (A) = (reg/mem): zero flag is set ;
• * if (A) > (reg/mem): carry and zero flags are reset

16‐12‐2021 By: Atifa Aqueel 26


Implied Addressing Mode
• In this mode of addressing, the microprocessor already knows the location
of data to process and the programmer does not need to define it explicitly.
That information is already contained in the opcode.
• For example,
1. CMA ; Each bit of the 8 bit number stored in Accumulator is
complemented. Note that in this case, it is implied ; that the data to be
processed is in the accumulator and we don't need to specify it.
2. RLC ; the 8 bits of the number stored in the Accumulator are manipulated
in such a way that each bit is moved ; left by 1 place and the most
significant bit is moved to the least significant position.
3. CMC ; The carry flag is complemented
4. STA ; The carry flag is set to 1
• The address of data to be manipulated is the register A which is not stated
in the instruction. It is already understood by the microprocessor when such
instructions (instructions with implied addressing mode) are used.

16‐12‐2021 By: Atifa Aqueel 27


Symbols and Abbreviations
• The symbols and abbreviation used in INTEL 8085 programming are:

16‐12‐2021 By: Atifa Aqueel 28


Symbols and Abbreviations

16‐12‐2021 By: Atifa Aqueel 29


DATA TRANSFER GROUP
• Instructions which are used to transfer the data from a register to another
register from memory to register or register to memory come under this
group.

16‐12‐2021 By: Atifa Aqueel 30


16‐12‐2021 By: Atifa Aqueel 31
Examples
Q.1: Place 28H in register C.

Q.2: Place 05H in accumulator and transfer it in register C.

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.

16‐12‐2021 By: Atifa Aqueel 32


Arithmetic Group
• The instructions of this group perform arithmetic operations such as
addition, subtraction, increment or decrement of the content of a register or
a memory.

ADD B

ADD M

ADC B

ADC M

ADI 20H
16‐12‐2021 By: Atifa Aqueel 33
ADI 20H

ACI 20H

DAD B

SUB B

SUB M

SBB r/SBB M
SBB B
/SBB M

SUI 55H

SBI 25H

16‐12‐2021 By: Atifa Aqueel 34


INR B

INR M

DCR B

DCR M

INX B

DCX B

16‐12‐2021 By: Atifa Aqueel 35


DAA Instruction
• DAA: Decimal Adjust Accumulator
• The instruction DAA is used in the program after ADD, ADC, ADI, ACI
etc.
• After ADD, ADC etc. the result is in hexadecimal form and it is placed in
accumulator.
• The DAA instruction operates on this result and gives the final result in
decimal system.
• It uses carry and auxiliary carry for decimal adjustment.
• When the sum lies between 10 to 15 (or A to F hexadecimal) a correction of
+6 is made by DAA instruction. 6 is added to both LSBs and MSBs.
• 6 is added to 4 LSBs of the content of accumulator if the values lie in
between A and F or the auxiliary carry flag is set to 1.
• Similarly,6 is added to 4 MSBs of the content of accumulator if the values
lie in between A and F or the carry flag is set to 1.
• Thus DAA instruction checks whether there is a carry, auxiliary flag or the
sum lies between A to F and makes corrections accordingly.
16‐12‐2021 By: Atifa Aqueel 36
Example
• Let us consider we want to add two decimal numbers 38 and 45. They will
be represented in BCD as 0011 1000 and 0100 0101. The addition results in
0111 1101. But the answer will be incorrect if we want to interpret this
result as a BCD number. The result will be not only incorrect but also
illegal as 1101, which we obtained as the last nibble in the answer is not a
valid BCD number. Here, in such situations, we can use DAA to have the
BCD sum as outcome. All that is required to be done is to add the BCD
numbers and store the result in A, and then execute the DAA instruction.

16‐12‐2021 By: Atifa Aqueel 37


• The illustra on of the remedial ac ons against the previous example −

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)
16‐12‐2021 By: Atifa Aqueel 38
Examples
Q.1: Multiply 1245H by 2 .
Ans: LXI H, 1245H
DAD H
HLT

Q.2: ADD 1245H & 1345H using DAD instruction.


Ans: LXI H, 1245H
LXI B, 1345H
DAD B
HLT
Q.3: ADD two numbers present in memory locations 2501H and 2502H
respectively and store the 8-bit result in 2503H (Use indirect addressing
mode)

16‐12‐2021 By: Atifa Aqueel 39


Indirect Addressing

16‐12‐2021 By: Atifa Aqueel 40


Logical Group
• The instructions in this group perform logical operation such as AND, OR,
compare, rotate, etc.

16‐12‐2021 By: Atifa Aqueel 41


16‐12‐2021 By: Atifa Aqueel 42
CS A7 A6 A5 A4 A3 A2 A1 A0

16‐12‐2021 By: Atifa Aqueel 43


RLC AND RAL

RLC

RAL

16‐12‐2021 By: Atifa Aqueel 44


RRC AND RAR

RRC

RAR

16‐12‐2021 By: Atifa Aqueel 45


Application of Rotate Instructions
• The rotate instructions can also be used for quick multiplication and
division. The 8085 does not have special instructions for multiply and
divide.

• 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.

• To check whether the number is positive or negative.

• To check whether the number is even or odd.

• To find the number of 1’s and 0’s in a given number.

16‐12‐2021 By: Atifa Aqueel 46


PROGRAMS
1. WAP to find one’s complement of an 8-bit number present in memory
location 2501H and store the result in 2502H.
2. WAP to mask off the least significant 4 bits of an 8-bit number. Assume
the no is present in memory location 2504H.
3. WAP to set the lower nibble without affecting the higher nibble.
4. WAP to complement the higher nibble without affecting the lower nibble.

16‐12‐2021 By: Atifa Aqueel 47


Solutions
1. LDA 2501H 3. LDA 2504H
• CMA • ORI 0FH
• STA 2502H • STA 2505H
• HLT • HLT

2. LDA 2504H 4. LDA 2504H


• ANI 0FH • XRI F0H
• STA 2505H • STA 2505H
• HLT • HLT

16‐12‐2021 By: Atifa Aqueel 48


Branch and Control Group
• The instructions of this group change the normal sequence of programs.
• There are two types of branch instructions:
• Conditional and Unconditional branch.
• The conditional branch instructions transfer the program to the specified
label or memory location when certain conditions are satisfied.
• The unconditional branch instructions transfer the program
unconditionally to the specified label or memory location.

16‐12‐2021 By: Atifa Aqueel 49


Unconditional Jump

• 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.

16‐12‐2021 By: Atifa Aqueel 50


Conditional Jump
• After the execution of conditional jump instruction the
program jumps to the instruction specified by the addresses or
label if the specified conditions are true.
• The program proceeds further in normal sequence if the
specified condition is not fulfilled.

16‐12‐2021 By: Atifa Aqueel 51


16‐12‐2021 By: Atifa Aqueel 52
Program 5
Q: Write an assembly language program to perform addition of two
hexadecimal numbers (99H and 98H) by immediate addressing mode. Store
the result and carry in memory locations 2503H and 2504H respectively.
Memory Label Mnemonics/ Comments
Address Opcodes
2000H MVI C, 00H Clear Register C
2002H MVI A, 99H Move 99H in Accumulator
2004H MVI B, 98H Move 98H in Register B
2006H ADD B Add the content of A and B and store the
result in A
2007H JNC AHEAD Jump to AHEAD if CY = 0
200AH INRC If CY=1, increment Reg C by 1, C=1
200BH AHEAD: STA 2503H Store the result (Accum) in 2503H
200EH MOV A,C Move content of C (i.e. Carry) in Accum.
200FH STA 2504H Store the Carry (Accum) in 2504H
2012H HLT End the program
16‐12‐2021 By: Atifa Aqueel 53
Q: Write an assembly language programs to perform addition of two hexadecimal
numbers stored at memory location 2501H and 2502H by direct addressing mode.
Store the result and carry in memory locations 2503H and 2504H respectively.
Memory Label Mnemonics/ Comments
Address Opcodes
2000 LDA 2500H Load the content of 2500H (i.e. 00H) to Accumulator

2003 MOV C,A Move Accumulator content (i.e. 00H) to reg C


2004 LDA 2501H Load the content of 2501H (i.e. one operand) to Accumulator

2007 MOV B,A Move Accumulator content (i.eone operand) to reg B

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

200C JNC AHEAD Jump to AHEAD if CY = 0


200F INRC If CY=1, increment Reg C by 1, C=1

2010 AHEAD: STA 2503H Store the result (Accum) in 2503H


2013 MOV A,C Move content of C (i.e. Carry) in Accum.

2014 STA 2504H Store the Carry (Accum) in 2504H


201716‐12‐2021 HLT EndBy:the program
Atifa Aqueel 54
Addition (Indirect Addressing)
Memory Label Mnemonics/ Comments
Address Opcodes
2000 LXI H, Load the value 2500H in HL pair (HL =2500H)
2500H
2003 MOV C,M Move the content of memory location whose address is in HL
pair to register C. (C=00H)
2004 INX H Increment HL pair by 1 (i.e, HL=2501H)
2005 MOV A,M The value of 2501H will be moved to Accumulator
2006 INX H Increment HL pair by 1 (i.e, HL=2502H)
2007 ADD M [A] [A] + [[H-L]]
2008 JNC AHEAD Jump to AHEAD if CY = 0
200B INR C If CY=1, increment Reg C by 1, C=1
200C AHEAD: INX H Increment HL pair by 1 (i.e, HL=2503H)
200D MOV M,A Move the value of Acc (Result) to memory location2503H
200E INX H Increment HL pair by 1 (i.e, HL=2504H)
200F MOV M, C Move the value of Reg C(carry) to memory location2504H
2010
16‐12‐2021 HLT Stop By:
theAtifa
program
Aqueel 55
Program 6
Q. WAP to Add the 16-bit number in memory locations 2501H and 2502H to
the 16-bit number in memory locations 2503H and 2504H. Store the result in
memory locations 2505H and 2506H with the most significant byte in memory
location 2506H.

16‐12‐2021 By: Atifa Aqueel 56


Solution (without carry)

16‐12‐2021 By: Atifa Aqueel 57


Solution (with carry)
Memory Label Mnemonics/ Comments
Address Opcodes

2000H XRA A Clear the accumulator by xoring its value. A=00H


2001H LHLD 2501H Load HL pair with the value of 2501H AND 2502h
2004 XCHG Exchange HL pair with DE pair
2005 LHLD 2503H Load HL pair with the value of 2503H AND 2504h
2008 DAD D Add HL and DE pair and store the result in HL pair
2009 JNC AHEAD Jump to AHEAD if CY = 0

200C INR A If CY=1, increment Reg A by 1, A=1

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
16‐12‐2021 By: Atifa Aqueel 58
CALL Instruction

16‐12‐2021 By: Atifa Aqueel 59


16‐12‐2021 By: Atifa Aqueel 60
RETURN Instruction

16‐12‐2021 By: Atifa Aqueel 61


16‐12‐2021 By: Atifa Aqueel 62
RESTART Instruction

16‐12‐2021 By: Atifa Aqueel 63


16‐12‐2021 By: Atifa Aqueel 64
Stack, I/O and Machine Control Group
• This group contains the instructions for input/output ports, stack and
machine control.

16‐12‐2021 By: Atifa Aqueel 65


16‐12‐2021 By: Atifa Aqueel 66
16‐12‐2021 By: Atifa Aqueel 67

You might also like