Sei sulla pagina 1di 52

INTRODUCTION TO 8085 INSTRUCTION SET

INTRODUCTION

 A microcomputer performs a task by reading and executing the


set of instructions written in its memory.
 This set of instructions, written in a sequence, is called a
program.
 Each instruction in the program is a command, in binary, to the
microprocessor to perform an operation.
DATA TRANSFER OPERATIONS

 The data transfer instructions ‘copy’ data from a source


into a destination without modifying the contents of the
source.
 The previous contents of the destination are replaced by
the contents of the source.
DATA TRANSFER OPERATIONS
MACHINE CONTROL OPERATIONS
EXAMPLE 1

 Load the accumulator A with the data byte 82H (the letter
H indicates hexadecimal number), and save the data in
register B.
Instructions: MVI A, 82H,
 MOV B,A
The first instruction is a 2-byte instruction that loads the
accumulator with the data byte 82H, and the second
instruction MOV B,A copies the contents of the
accumulator in register B without changing the contents
of the accumulator.
EXAMPLES

Get a data to accumulator and then move it to register B.


Load the content of memory location 200H directly to the
accumulator, then transfer it to the register B.
Get a data to accumulator and then move it to register B.
 MVI A,05(data)
 MOV B,A
Load the content of memory location 200H directly to the
accumulator, then transfer it to the register B.
 LDA 2000H
 MOV B,A
ARITHMETIC AND LOGIC INSTRUCTIONS
ARITHMETIC OPERATIONS
Addition,
Subtraction,
Increment,
Decrement.
ARITHMETIC OPERATIONS
ARITHMETIC OPERATIONS
ARITHMETIC OPERATIONS
ADDITION
Addition takes several forms in the 8085
microprocessor like 8-bit binary, 16-bit binary etc
ADDITION
The contents of the accumulator are 93H and
contents of a register C is B7 H. Add both the
contents.
ADDITION
Add the number 35H to directly to the sum in the
previous example when the CY flag is set.
ADDITION
Write a program to perform the following functions,
 Load the number 8BH in register D.
 Load the number 6FH in register C.
 Increment the contents of register C by one.
 Add the contents of register C and D and display the sum at the
output PORT1.
MVI D,8DH
MVI C,6FH
INR C
MOV A,C
ADD D
OUT PORT1
HLT
Subtraction
 The 8085 supports 8-bit binary subtraction and decrement.
 It also supports a subtraction instruction that allows a borrow to be
propagated through additional bytes of a number.
 The subtract-with-borrow instruction aids in the subtraction of
multiple-byte numbers. .
Subtraction
The 8085 performs subtraction by using the method
of 2’s complement.
Subtraction can be performed by using either:
 the instruction SUB to subtract contents of a source register or
 the instruction SUI to subtract an 8-bit number from contents
of the accumulator.
 In either case, the accumulator contents are regarded as
minuend (the number from which to subtract).
Subtraction
Subtraction
The 8085 performs the following steps internally to execute
the instruction SUB (or SUI):
 Step1:Converts subtrahend (the number to be subtracted)
into its 1’s complement.
 Step2:Adds 1 to 1’s complement to obtain 2’s complement
of the subtrahend.
 Step3:Add 2’s complement to the minuend (the contents of
the accumulator).
 Step4:Complements the Carry flag:

 The programmer can check whether the result


indicates the true magnitude by checking the CY flag.
If CY flag is reset the result is positive and if CY flag
is set, the result is expressed in 2’s complement.
Illustrative Program: Subtraction of Two Numbers

PROBLEM STATEMENT
 Write a program to do the following:
Load the number 30H in register B and 39H in register C.
Subtract 39H from 30H.
Display the answer at PORT I.
Illustrative Program: Subtraction of Two Numbers
Illustrative Program: Subtraction of Two Numbers

PROGRAM DESCRIPTION
 Registers B and C are loaded with 30H and 39H, respectively.
 The instruction MOV A,B copies 30H into the accumulator
(shown as register contents).
Illustrative Program: Subtraction of Two Numbers
To execute the instruction SUB C the microprocessor
performs the following steps internally:
Illustrative Program: Subtraction of Two Numbers

PROGRAM DESCRIPTION
 The number F7H is a 2’s complement of the magnitude (39H-
30H)=09H.
This ‘Cy’ flag is set, indicating the answer is in 2’s complement.
 The instruction OUT displays F7 at PORT1.

NOT
 The CMA instruction (2FH in machine language), one’s-
complements the contents of the accumulator.

 This operation, which affects none of the flag bits, causes


each bit of the accumulator to be inverted (changed from
1 to 0 or 0 to 1).

 The CMA instruction causes the accumulator to appear as


eight inverters (or NOT).
LOGIC INSTRUCTIONS

Four basic logic functions:


 NOT
 AND
 OR and
 Exclusive-OR.
The AND Operation
The AND Operation
The OR Operation
 Has two separate functions in a microprocessor-based
system:
 It selectively sets bits of the accumulator or

 Replaces discrete OR gates.

 The inclusive-OR instruction functions as eight


independent two-input OR gates.

 This instruction replaces two 7432 two-input OR gates.


The OR Operation
The OR Operation
Illustrative Program: ORing Data from Two Input
Ports

PROBLEM STATEMENT
 Two input port with eight switches (each port) at address
00H and OIH (Figure 6.9) is connected to the
microcomputer to control the same appliances and lights
from the bedroom as well as from the kitchen.

 Write instructions to turn on the devices from any of the


input ports.
Illustrative Program: ORing Data from Two Input
Ports
Illustrative Program: ORing Data from Two Input
Ports

PROBLEM ANALYSIS
 To turn on the appliances from any one of the input ports, the
microprocessor needs to read the switches at both ports and logically
OR the switch positions.
 Assume that the switch positions in one input port (located in the
bedroom) correspond to the data byte 9lH and the switch positions
in the second port (located in the kitchen) correspond to the data
byte A8H.
 The person in the bedroom wants to turn on the air conditioner, the
radio, and the bedroom light; and the person in the kitchen wants to
turn on the air-conditioner, the coffeepot, and the kitchen light.
 By ORing these two data bytes, the MPU can turn ON the necessary
appliances.
Illustrative Program: ORing Data from Two Input
Ports
Exclusive OR (XOR)
ROTATE INSTRUCTIONS
SUMMARY

 Most arithmetic and logic instructions affect the flag bits,


whereas the data transfer instructions did not affect the
flags.
 Many arithmetic and logic instructions gate the result into
the accumulator.
 The arithmetic and logic instructions use register,
immediate, and register indirect addressing.
 Addition is available as add 1 to any register or register pair,
8- and 16-bit binary, 8-bit binary with carry, and binary-
coded decimal (BCD).
SUMMARY

 Subtraction is available as subtract 1 from any register or


register pair, 8-bit binary, 8-bit binary with borrow, and as
a compare, which is a form of subtraction.
 The logic operations are AND, OR, exclusive-OR, and
invert.
 The logic instructions are ideal for control because AND
clears bits, OR sets bits, and exclusive-OR complements
bits. This gives the programmer complete control over each
bit of a number.
 Programmed logic replaces discrete logic circuits at a
substantial cost advantage.
SUMMARY

 Some 8085 instructions have hidden functions: ADD A


shifts the accumulator left, and DAD H shifts HL left.
 Both ANA A and ORA A test the accumulator, and SUB A
and XRA A clear the accumulator.
 The rotate commands create the shift-right functions:
logical and arithmetic shift right.
Subtraction

P= 0 Odd parity
Subtract with Borrow
Subtract with Borrow
Example
Suppose that the number in the DE pair must be subtracted from
the BC pair. The least significant is operated on first. Once the
difference of C and E is found, the D register is subtracted from
the B register with a borrow. The subtraction with borrow
effectively propagates the borrow through the most significant
byte of the result.

Potrebbero piacerti anche