0% found this document useful (0 votes)
3 views

Chapter_Four

8086 instruction set

Uploaded by

amanuel
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)
3 views

Chapter_Four

8086 instruction set

Uploaded by

amanuel
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/ 57

Chapter Four

Instruction Set
and
Programming Techniques

1
Outline
 Instruction Formats: Single Byte, Two Bytes & Three Bytes Instructions

Opcode Format

 DATA Transfer Operations, Arithmetic Operations, Logic Operations,

Branch Operations, Stack, I/O& Machine Control Instructions.

 Looping, Counting and Indexing Counter and Timing delays Stack and

Subroutines

 Code conversion, BCD Arithmetic operations and 16 Bit data operations

 How to write an assemble language program & execute a simple program

 Instruction Timings & Operation Status


2
Instruction Format
 An instruction is a command to the microprocessor to perform a given task on a
specified data.
 Each instruction has two parts: one is task to be performed, called the operation code
(opcode), and the second is the data to be operated on, called the operand.
 The operand (or data) can be specified in various ways. It may include 8-bit (or 16-bit)
data, an internal register, a memory location, or 8-bit (or 16-bit) address.
 In some instructions, the operand is implicit.
 Instruction word size: The 8085 instruction set is classified into the following three
groups according to word size:
✓One-word or 1-byte instructions
✓Two-word or 2-byte instructions
✓Three-word or 3-byte instructions 3
Cntd…
 In the 8085, "byte" and "word" are synonymous because it is an 8-bit microprocessor.

 However, instructions are commonly referred to in terms of bytes rather than words

1. One-Byte Instructions:
 A 1-byte instruction includes the opcode and operand in the same byte.
 Operand(s) are internal register and are coded into the instruction

4
Cntd…
 These instructions are 1-byte instructions performing three different tasks.
 In the first instruction, both operand registers are specified.
 In the second instruction, the operand B is specified and the accumulator is assumed.
 Similarly, in the third instruction, the accumulator is assumed to be the implicit operand.
 These instructions are stored in 8- bit binary format in memory; each requires one memory
location.
MOV rd, rs
rd  rs copies contents of rs into rd.
1. Example: MOV A,B
Coded as 01111000 = 78H = 170 octal (octal was used extensively in instruction design of such
processors).
ADD r
AA+r
5
Cntd…
2.Two-Byte Instructions: In a two-byte instruction, the first byte specifies the operation code
and the second byte specifies the operand. Source operand is a data byte immediately following the
opcode. For example:

The instruction would require two memory locations to store in memory.


MVI r, data
r data
Example: MVI A,30H coded as 3EH 30H as two contiguous bytes.
This is an example of immediate addressing.
ADI data
A  A + data 6
Cntd…
3. Three-Byte Instructions: the first byte specifies the opcode, and the following two bytes
specify the 16-bit address.
 Note that the second byte is the low-order address and the third byte is the high-order address.
 opcode + data byte + data byte

 This instruction would require three memory locations to store in memory.


 Three byte instructions - opcode + data byte + data byte
e.g., LXI rp, data16
 rp is one of the pairs of registers BC, DE, HL used as 16-bit registers.
 The two data bytes are 16-bit data in L H order of significance.
7
Cntd…

1. rp data16

LXI H,0520H coded as 21H 20H 50H in three bytes.

This is also immediate addressing.

2. LDA addr

A  (addr) Addr is a 16-bit address in L H order.

Example: LDA 2134H coded as 3AH 34H 21H.

This is also an example of direct addressing.


8
Addressing Modes in 8085
 These are the instructions used to transfer the data from one register to another register, from
the memory to the register, and from the register to the memory without any alteration in the
content. Addressing modes in 8085 is classified into 5 groups:
1. Immediate addressing mode: In this mode, the 8/16-bit data is specified in the instruction itself as
one of its operand. For example: MVI K, 20: means 20F is copied into register K.
2. Register addressing mode: In this mode, the data is copied from one register to another.
For example: MOV K, B: means data in register B is copied to register K.
3. Direct addressing mode: In this mode, the data is directly copied from the given address to the
register. For example: LDA 5000K: means the data at address 5000K is copied to register A.
4. Indirect addressing mode: In this mode, the data is transferred from one register to another by
using the address pointed by the register. For example: MOV K, B: means data is transferred
from the memory address pointed by the register to the register K.
5. Implied addressing mode: This mode doesn’t require any operand; the data is specified by the
9
opcode itself. For example: CMA.
Data transfer instructions in 8085 microprocessor
 Data transfer instructions are the instructions which transfers data in the microprocessor.
 They are also called copy instructions. Following is the table showing the list of logical
instructions:
 In the table, R stands for register
M stands for memory
r.p. stands for register pair

10
Cntd…

11
Cntd…

12
Arithmetic instructions in 8085 microprocessor
 Arithmetic Instructions are the instructions which perform basic arithmetic operations such as
addition, subtraction and a few more.
 In 8085 microprocessor, the destination operand is generally the accumulator.
 Following is the table showing the list of arithmetic instructions:

13
Cntd…

14
Cntd…

15
Logical instructions in 8085 microprocessor
 Logical instructions are the instructions which perform basic logical operations such as AND,
OR, etc.
 In 8085 microprocessor, the destination operand is always the accumulator.
 Here logical operation works on a bitwise level.
 Following is the table showing the list of logical instructions:

16
Cntd…

17
Cntd…

In the table,

1. R stands for register

2. M stands for memory

3. Mc stands for memory contents

18
Branching instructions in 8085 microprocessor
 Branching instructions refer to the act of switching execution to a different instruction sequence
as a result of executing a branch instruction.

The three types of branching instructions are:

1. Jump (unconditional and conditional)

2. Call (unconditional and conditional)

3. Return (unconditional and conditional)


1. Jump Instructions – The jump instruction transfers the program sequence to the memory
address given in the operand based on the specified flag.
Jump instructions are 2 types: Unconditional Jump Instructions and Conditional Jump
Instructions.
(a) Unconditional Jump Instructions: Transfers the program sequence to the described memory
address. 19
Cntd…

b) Conditional Jump Instructions: Transfers the program sequence to the described memory address
only if the condition in satisfied.

20
Cntd…
2. Call Instructions – The call instruction transfers the program sequence to the memory address
given in the operand.

Before transferring, the address of the next instruction after CALL is pushed onto the stack. Call
instructions are 2 types:

Unconditional Call Instructions and Conditional Call Instructions.

(a) Unconditional Call Instructions: It transfers the program sequence to the memory address given
in the operand.

21
Cntd…
(b) Conditional Call Instructions: Only if the condition is satisfied, the instructions executes.

22
Cntd…
3. Return Instructions – The return instruction transfers the program sequence from the subroutine
to the calling program.
Return instructions are 2 types: Unconditional Jump Instructions and Conditional Jump
Instructions.
a) Unconditional Return Instruction: The program sequence is transferred unconditionally from

the subroutine to the calling program.

(b) Conditional Return Instruction: The program sequence is transferred unconditionally from

the subroutine to the calling program only is the condition is satisfied.


23
Cntd…

24
Stack I/O, and Machine Control Instructions:
The following instructions affect the Stack and/or Stack Pointer:
PUSH - Push Two bytes of Data onto the Stack
POP - Pop Two Bytes of Data off the Stack
XTHL - Exchange Top of Stack with H & L
SPHL - Move content of H & L to Stack Pointer
The I/0 instructions are as follows:
IN - Initiate Input Operation
OUT - Initiate Output Operation
The Machine Control instructions are as follows:
EI - Enable Interrupt System
DI - Disable Interrupt System
HLT - Halt
NOP - No Operation
25
Cntd…
1. Program 1. Store the data byte 32H into memory location 4000H.

MVI A, 32H

STA 4000H

HLT

2. Exchange the contents of memory locations 2000H and 4000H

LDA 2000H

MOV B, A

LDA 4000H

STA 2000H

MOV A, B

STA 4000H
26
Cntd…
3A. Write an assembly program to add two numbers
3B. Write an assembly program to add two numbers
Program with carry
MVI D, 99H
MVI D, 8BH
MVI E, 99H
MVI C, 6FH
MOV A, D
MOV A, C ADD E
ADD D MOV C, A
HLT JNC END
MVI B,01H
INR B
END: HLT
4. Write an assembly program to multiply a number by 8 Program
MVI D, 8BH
MVI C, 6FH
MOV A, C
MUL D
HLT 27
Cntd…
5. Subtract the contents of memory location 4001H from the memory location 4000H and place the
result in memory location 4002H.

(4000H) = 51H
PROGRM
(4001H) = 19H
LXI H,4000H
Result = 51H - 19H = 38H
MOV A, M

INX H

SUB M

INX H

MOV M, A

HLT
28
Cntd…
6. Add the contents of memory location 4000H from the memory location 4001H and place the result
in memory location 4002H. ( with out carry)

(4000H) = 14H PROGRM 1 PROGRM 2


(4001H) = 89H LXI H,4000H LXI H,4000H
Result = 14H + 89H = 9DH MOV A, M MOV A, M

INX H INX H

MOV B, M ADD M

ADD B INX H

INX H MOV M, A

MOV M, A HLT

HLT
29
Cntd…
6. Add the contents of memory location 4000H from the memory location 4001H and place the result
in memory location 4002H. ( with carry)

(4000H) = 14H PROGRM 1 SKIP: INX H


(4001H) = 89H LXI H,4000H MOV M, A
Result = 14H + 89H = 9DH MOV A, M INX HL

INX H MOV M,C

MOV B, M HLT

MVI C,00H

ADD B

JNC SKIP

INR C
30
Cntd…
7. Add the 16-bit number in memory locations 4000H and 4001H to the 16-bit number in memory
locations 4002H and 4003H.

Store the result in memory locations 4004H and 4005H with the most significant byte in memory
location 4005H.
PROGRM
(4000H) = 15H
LHLD 4000H
(4001H) = 1CH
XCHG
(4002H) = B7H
LHLD 4002H
(4003H) = 5AH
DAD D
Result = 1C15 + 5AB7 = 76CCH
SHLD 4004H
(4004H) = CCH
HLT
(4005H) = 76H
31
Cntd…
8. Subtract the 16-bit number in memory locations 4002H and 4003H from the 16-bit number in
memory locations 4000H and 4001H.

Store the result in memory locations 4004H and 4005H with the most significant byte in memory
location 4005H.
PROGRM
(4000H) = 19H LHLD 4000H
XCHG
(400IH) = 6AH
LHLD 4002H
(4002H) = I5H MOV A, E
SUB L
(4003H) = 5CH
MOV L, A
Result = 6A19H – 5C15H = OE04H MOV A, D
SBB H
(4004H) = 04H MOV H, A
(4005H) = OEH SHLD 4004H
HLT 32
Cntd…
9. Find the l's complement of the number stored at memory location 4400H and store the
complemented number at memory location 4300H.(8bit)
(4400H) = 55H
Result = (4300H) = AAH
Solution
LDA 4400H
CMA
STA 4300H
HLT
10. 1st complement of 16bit
LHLD 8100
MOV A, L
CMA
MOV L, A
MOV A, H
CMA
MOV H, A 33
Cntd…
11. Write a program to shift an eight bit data four bits right. Assume that data is in register C.

MVI C, 0FH

MOV A, C

RRC

RRC

RRC

RRC

MOV C, A

HLT

Note: there is a carry flag c=1


34
Cntd…
12. Write a program to shift an eight bit data four bits right with Carry. Assume that data is in
register C.

MVI C, 0FH

MOV A, C

RAR

RAR

RAR

RAR

MOV C, A

HLT

RAR
Cntd…
12. Write an assembly program to find greatest between two numbers
Program
MVI B, 30H
MVI C, 40H
MOV A, B
CMP C
JZ EQU
JC GRT
HLT

EQU: MVI A, 01H


HLT
GRT: MOV A, C
HLT

36
Cntd…
13. Subtraction of two 8bit numbers, Manually store 1st no in the memory location C050,
Manually store 2nd no in the memory location C051, // Result is stored in C053
LXI H,C050

MOV A,M

INX H

SUB M

INX H

MOV M,A

HLT

# ORG C050

# DB 95H,65H

37
Looping, Counting and Indexing Counter and Timing delays Stack and Subroutines

1. LOOPING – in-order to run certain set of instructions repeatedly to execute a particular task for
certain number of time
2. COUNTING – used to count as how many times the instruction/set of instructions are executed
3. INDEXING – allows programmer to point or refer the data stored in sequential memory location
one by one
 Loops Have Four Sections
1. Initialization Section ,
2. Processing Section,
3. Loop Control,
4. Result Section

38
Cntd…
1. Initialization section initializes
Loop counters for counting how many times loop is executed
Address registers for indexing which give pointers to memory locations and other variables
2. Processing section:
The actual data manipulation occurs in the processing sections. This section does the work
3. Loop control section updates counters, indices(pointers) for the next iteration
4. Result section analyses and stores the results
1. Calculate The Sum Of Series Of Numbers

39
Cntd…
1. Assembly program to find the product of two 8 bit (4x5)

Program:
MVI C,04
SUB A
MVI B,05
BACK: ADD B
DCR C
JNZ BACK
STA 2300
HLT

40
Cntd…
2. The sum of 1 up 10 addition 8 bit

Program:

MVI A, 00

MVI B, 01

MVI C, A

LOOP: ADD B

INR B

DCR C

JNZ LOOP

HLT

41
Cntd…
3.The sum of odd number from 1 up 10(8 bit)
Program 1. MVI A,00
MVI D,00 program 2:
MVI B,00 MVI A,00
MVI C,0A
MVI B,01
BACK: MOV A,C MVI C,05
ANI 01
JNZ ODD LOOP: ADD B
JMP NEXT
INR B
ODD: MOV A,C INR B
ADD D DCR C
MOV D,A JNZ LOOP
HLT
NEXT: DCR C
JNZ BACK
MOV A,D
STA 2211
42
HLT
Cntd…
4.The sum of even number from 1 up 10(8 bit)
MVI A,00
MVI D,00
MVI B,00
MVI C,0A

BACK: MOV A,C


ANI 01
JNZ NEXT
MOV A,C
ADD B
MOV B,A

NEXT: DCR C
JNZ BACK
MOV A,B
STA 2210
43
HLT
Cntd…
5.The sum of Odd and even a number from 1 up 10(8 bit)
MVI A,00
MVI D,00
MVI B,00
MVI C,0A

BACK: MOV A,C


ANI 01
JNZ ODD
MOV A,C
ADD B
MOV B,A
JMP NEXT

ODD: MOV A,C


ADD D
MOV D,A

NEXT: DCR C
JNZ BACK

MOV A,B
STA 2210
MOV A,D
STA 2211
HLT 44
Cntd…
6.Take N numbers from memory 2200 and sum even and odd number and store the result (8 bit)
LDA 2200H
MOV C,A
MVI D,0
MVI B,0
LXI H,2201
BACK:MOV A,M
ANI 01
JNZ ODD
MOV A,B
ADD M
MOV B,A
JMP NEXT
ODD: MOV A,D
ADD M
MOV D,A
NEXT: INX H
DCR C
JNZ BACK

MOV A,B
STA 2210
MOV A,D
STA 2211
HLT

45
Cntd…
7.8085 program to find maximum and minimum of 10 numbers
LXI H,2050
MOV B,M ;MAXIMUM
MOV C,M ;MIMIMUM
MVI D,05 ;COUNTER
LOOP: MOV A,M
CMP B
JC MIN
MOV B,A
MIN: CMP C
JNC SKIP
MOV C,A
SKIP: INX H
DCR D
JNZ LOOP

LXI H,2060
MOV M,B
INX H
MOV M,C
HLT 46
Cntd…
8. Arrange an numbers in Ascending Order
LXI H,5000 // Set pointer for array
MOV C,M // Load the Count
DCR C // Decrement Count
REPEAT: MOV D,C
LXI H,5001 // Load starting address of data
LOOP: MOV A,M // copy content of memory location to Accumulator
INX H
CMP M
JC SKIP // Jump to skip if carry not generated
MOV B,M // copy content of memory location to B - Register
MOV M,A // copy content of A - Register to memory location
DCX H // Decrement content of HL pair of registers
MOV M,B
INX H // Increment content of HL pair of registers
SKIP: DCR D
JNZ LOOP // Jump to LOOP if not Zero
DCR C
JNZ REPEAT // Jump to REPEAT if not Zero
47
HLT
Cntd…
9. Arrange an numbers in Descending Order
LXI H,5000 ;Set pointer for array
MOV C,M ;Load the Count
DCR C ;Decrement Count
REPEAT: MOV D,C
LXI H,5001 ;Load starting address of data array
LOOP: MOV A,M ;copy content of memory location to Accumulator
INX H
CMP M
JNC SKIP ;Jump to skip if carry not generated
MOV B,M ;copy content of memory location to B - Register
MOV M,A ;copy content of A - Register to memory location
DCX H ;Decrement content of HL pair of registers
MOV M,B
INX H ;Increment content of HL pair of registers
SKIP: DCR D
JNZ LOOP ;Jump to LOOP if not Zero
DCR C ;Decrement Count
JNZ REPEAT ;Jump to REPEAT if not Zero
48
HLT ;Terminate Program
Timer Delay
Timer delay using nop instruction
 Each NOP instruction takes 4T states of the processor time to execute.
 So by executing NOP instruction in between two instructions we can get delay of 4T states

49
Cntd…
Timer delay using 8 bit counters
 Counting can create time delays. Since the execution times of the instructions used in a counting
routine are known, the initial value of the counter, required to get specific time delays can be
determined.
 In this program the instruction DCR C and JNZ BACK execute number of times equal to count
stored in the C registered. The time taken by this program for execution can be calculated with
the helps of T state.
 The column to the right of the comments indicates the number of T state in the instruction cycle
of each instructions.
 Two values are specified for the number of T state for JNZ instructions.
 The smaller value is applied when the condition is not met and the larger value applied when the
condition is met.
 The first instruction MVI C count executed only once and it requires 7 T state. There are count -
1 passes through the loop (DCR C).
50
Cntd…
The number of T states elapse while C is not zero are (count-1) X (4x10).

On the last pass through the loop the condition is not met and the loop is terminated.

The number of T state that elapse in this pass are 4+7.

51
Using 16bit counter

in this program, the instruction DEX B, MOVA,C ,ORA B, and JNZ BACK execute number of
times equal to count stored in BC register pair. The instruction LXI B, count is executed only once.

It requires 10T-state.

The number of T-state required for one loop=6+4+4+10=24 T-state

the number of T state required for last loop. =6+4+1+7=24 T-state. Total state required for
execution of a given program.
52
Cntd…

53
Cntd…
Maximum delay possible with 16 bit count

1. The maximum count that can be loaded in the 16 bit register pair is FFFFH(65535)

2. So the maximum delay possible with 8 bit count, assume operating frequency 2MHZ

=10(10+(65535-1)X(24+(21))X0.5Nsec

=0.786425 second

If the application requires the delay more than this then the nested loop technique is used to
implement the delays.

54
Timer delay using Nested Loop

T-state required for execution of inner loop


Tinner=7+(delay count-1)X14+11
T-state required for execution of a given program
=(multiplier count -1)X (Tinner +14)+11
For delay count =65H(101)and multiplier count 51H(81)
Tinner =7+(101-1)X14+11
=1418
Total time required to execute a given program is
Operating frequency is 2MHz)=(81-1)X(1418+14)+11)X0.5
=57.2855msec. 55
Code conversion, BCD Arithmetic operations and 16 Bit data operations

Code conversion allows users to translate a number that is represented using one code to coding
system.

The code conversion involves operations like:

1. Binary to BCD

2. BCD to binary

3. BCD to Hex

4. Hex to BCD

5. BCD to Seven Segment

6. Binary to ASCII

7. ASCII to binary

Reading Assignment
56
End of Chapter Four
???

57

You might also like