Chapter_Four
Chapter_Four
1
Outline
Instruction Formats: Single Byte, Two Bytes & Three Bytes Instructions
Opcode Format
Looping, Counting and Indexing Counter and Timing delays Stack and
Subroutines
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 and 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
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:
1. rp data16
2. LDA addr
10
11
Cntd…
12
Arithmetic instructions in 8085
Arithmetic Instructions are the instructions which perform basic
microprocessor
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
Logical instructions are the instructions which perform basic logical
microprocessor
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
Branching instructions refer to the act of switching execution to a
microprocessor
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. 19
Cntd…
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.
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
26
MOV A, B
Cntd…
3A. Write an assembly program to add two numbers
3B. Write an assembly program to
Program add two numbers 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 27
HLT
Cntd…
5. Subtract the contents of memory location 4001H from the
memory location 4000H and place the result in memory
PROGRM
location 4002H.
LXI H,4000H
(4000H) = 51H
MOV A, M
(4001H) = 19H
INX H
Result = 51H - 19H = 38H
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 PROGRM
out carry)
1 PROGRM 2
(4000H) = 14H LXI H,4000H LXI H,4000H
(4001H) = 89H MOV A, M MOV A, M
Result = 14H + 89H = 9DH
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 PROGRM
carry) 1 SKIP: INX H
(4000H) = 14H LXI H,4000H MOV M, A
(4001H) = 89H MOV A, M INX HL
Result = 14H + 89H = 9DH
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
PROGRM
significant byte in memory location 4005H.
LHLD 4000H
(4000H) = 15H
XCHG
(4001H) = 1CH
LHLD 4002H
(4002H) = B7H
DAD D
(4003H) = 5AH
SHLD 4004H
Result = 1C15 + 5AB7 = 76CCH
HLT
(4004H) = CCH
31
(4005H) = 76H
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
PROGRM
significant byte in memory location 4005H.
LHLD 4000H
(4000H) = 19H XCHG
LHLD 4002H
(400IH) = 6AH MOV A, E
SUB L
(4002H) = I5H
MOV L, A
(4003H) = 5CH MOV A, D
SBB H
Result = 6A19H – 5C15H = OE04H MOV H, A
(4004H) = 04H SHLD 4004H
HLT
32
(4005H) = OEH
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 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
34
Note: there is a carry flag c=1
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
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
NEXT: DCR C
HLT
JNZ BACK
MOV A,D
STA 2211
HLT 42
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
NEXT: DCR C
JNZ BACK
MOV A,B
STA 2210
HLT 43
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
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
HLT 47
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
HLT ;Terminate Program 48
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
50
the larger value applied when the condition is met.
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
57