Professional Documents
Culture Documents
8085 - Part II PDF
8085 - Part II PDF
The various formats of specifying the operands in instructions are called the addressing
modes.
The 8085 instruction set has the following addressing modes.
The classification of the addressing modes is unimportant, except that it provides some
clues in understanding mnemonics.
For e.g., in the case of the MVI opcode, the letter I suggests the second byte is data and not
a register.
Data Transfer (COPY) Operations (4)
Illustrative Program: Data Transfer – From Register to Output Port – (1)
This program assumes that one output port is available on your microcomputer systems.
If the program is properly entered and executed, the data byte 37H will be displayed at the
output port.
Data Transfer (COPY) Operations (7)
Illustrative Program: Data Transfer to Control Output Devices – (1)
Problem Analysis
The output port here is a latch (D flip-flop).
When the data bits are sent to the output port they are
latched by the D flip-flop.
A data bit at logic 1 supplies approximately 5V as output
and can turn on solid-state relays.
It is your responsibility to
interpret the use of flags.
The program will display F7H as the output which is 2’s complement of 09H which is
indicated by CY = 1.
The answer should not be considered as a 9-bit positive sum as the instruction used is SUB.
Logic Operations – (1)
A microprocessor is basically a programmable logic chip. It can perform all the logic
functions of the hard-wired logic through its instruction set.
All logic operations are performed in relation to the contents of the accumulator.
Logic Operations – (2)
Logic Operations – (3)
Logic AND
The ANA instruction simulates eight AND gates as shown below for the example
instruction ‘ANA B’ with B = 77H and A = 01H.
Each bit of register B is independently ANDed with each bit of the accumulator and the
result 01H is placed in accumulator replacing the previous contents.
The microprocessor is a sequential machine; it executes machine codes from one memory
location to the next.
Branch instructions instruct the microprocessor to go to a different memory location, and the
microprocessor continues executing machine codes from the new location.
The address of the new memory location is either specified explicitly or supplied by the
microprocessor or by extra hardware.
The branch instruction are classified in three categories: 1. Jump Instructions 2. Call and Return
Instructions 3. Restart Instructions
The Jump instructions specify the memory location explicitly. The Jump instructions can transfer
program execution ahead of the sequence (Jump Forward) or behind the sequence (Jump
Backward).
They are 3-byte instructions: 1-Byte for the operation code, followed by a 16-bit memory address.
Jump Instructions: Unconditional Jump & Conditional Jump
The Call and Return instructions are associated with the subroutine technique and Restart
instructions are associated with the interrupt technique.
The branch instructions do not affect the flags.
Branch Operations – (2)
Unconditional Jump
The 8085 instruction set includes one unconditional Jump instruction. The unconditional
Jump instruction enables the programmer to set up continuous loops.
The 16-bit memory address of the jump location is entered in the reverse order, the low-
order byte (00H) first, followed by the high-order byte (20H).
The 8085 is designed for such a reverse sequence.
In example 6.2, the program reads switch position once and then stops.
Therefore, if you want to turn on/off different appliances, you have to reset the system and
start all over again which is impractical in real-life situations.
The unconditional Jump instruction, in place of the HLT instruction, will allow the
microcomputer to monitor the switch positions continuously.
The program includes one more column called label. The memory location 2000H is
defined with the label START; therefore, the operand of the Jump instruction can be
specified by the label START.
Branch Operations – (4)
Conditional Jumps
Conditional Jump instructions allow the microprocessor to make decisions based on certain
conditions indicated by the flags (Carry, Zero, Sign, Parity).
After logic and arithmetic operations, flip-flops (flags) are set or reset to reflect data
conditions.
Two Jump instructions are associated with each flag.
All conditional Jump instructions in the 8085 are 3-byte instructions; the second byte
specifies the low-order (line number) memory address, and the third byte specifies the high-
order (page number) memory address.
Branch Operations – (5)
Illustrative program: Testing of the Carry Flag
Branch Operations – (6)
Illustrative program: Testing of the Carry Flag
Assuming your R/W memory begins at 2000H, the preceding assembly language program
can be translated as follow:
The flowchart will be as shown to the left and it shows that the
program sequence is changed if there is a carry.
This flowchart has two end points; thus it will require a few
more instructions than that with the case of using JNC
instruction.
When a Jump instruction is fetched, its second and third bytes (a new memory location) are
placed in the W and Z registers of the microprocessor.
After the execution of the Jump instruction, the contents of the W and Z registers are placed
on the address bus to fetch the instruction from a new memory location, and the program
counter is loaded by updating the contents of the W and Z registers.
Programming Techniques with Additional Instructions
Programming Techniques: Looping, Counting & Indexing – (1)
The computer surpasses manual efficiency when tasks must be repeated, such as adding a
hundred numbers or transferring a thousand bytes of data. It is fast and accurate.
The programming technique used to instruct the microprocessor to repeat tasks is called
looping.
A loop is set up by instructing the microprocessor to change the sequence of execution and
perform the task again.
A continuous loop repeats a task continuously and can be set up using the unconditional
Jump instruction.
A conditional loop is set up by the conditional Jump instructions and repeats a task until
certain data conditions are met.
{In a library, books are arranged according to numbers, and they are referred to or sorted by
numbers. This is called Indexing.}
Indirect
Addressing mode
Indirect Addressing
mode
Registers BC and DE
can be used as
restricted memory
pointers
Direct
Addressing mode
Additional Data Transfer and 16-Bit Arithmetic Instructions – (3)
Data Transfer (Copy) from Memory to the Microprocessor
The indirect
addressing
mode takes four
bytes and the
direct
addressing
mode takes
three bytes.
The instruction
INX B views
2050H as one 16-
bit number and
increases the
number to 2051H
On the other hand, the
instructions INR B and INR C
will increase B and C
separately and the contents of
the BC register pair will be
2151H.
Additional Data Transfer and 16-Bit Arithmetic Instructions – (7)
Illustrative Program: Block Transfer of Data Bytes
Additional Data Transfer and 16-Bit Arithmetic Instructions – (8)
Illustrative Program: Block Transfer of Data Bytes
Arithmetic operations related to Memory – (1)
Instructions
Arithmetic operations related to Memory – (2)
Arithmetic operations related to Memory – (3)
Arithmetic operations
related to Memory – (4)
Illustrative program:
Addition with Carry
Six bytes of data are
stored in memory
locations starting at
XX50H. Add all the data
bytes. Use register B to
save any carries
generated, while adding
the data bytes. Display
the entire sum at two
output ports, or store the
sum at two consecutive
memory locations,
XX70H and XX71H.
Bubble Sort
Compare two bytes and place them in a
proper sequence.
Compare the first two bytes, and if the first
byte is larger than the second byte, exchange
their memory locations to arrange them in
ascending order, else don’t exchange.
Follow same procedure for second and third
byte.
N – 1 comparisons will be needed in a
‘single pass’ for N data bytes.
The ASCII (American Standard Code for Information Interchange) keyboard is commonly
used input device for disk-based microcomputer systems.
Similarly, alphanumeric characters (letters and numbers) are displayed on a CRT (cathode
ray tube) terminal using the ASCII code.
The programming techniques used for code conversion fall into four general categories:
1. Conversion based on the position of a digit in a number (BCD to binary and vice versa)
2. Conversion based on hardware consideration (binary to seven-segment code using table
look-up procedure)
3. Conversion based on sequential order of digits (binary to ASCII and vice versa)
4. Decimal adjustment in BCD arithmetic operations (This is an adjustment rather than a
code conversion)
BCD-to-Binary conversion – (1)
In most microprocessor-based products, data are entered and displayed in decimal numbers.
For e.g., in an instrumentation laboratory, readings such as voltage and current are
maintained in decimal numbers, and data are entered through a decimal keyboard.
The system-monitor program of the instrument converts each key into an equivalent 4-bit
binary number and store two BCD numbers in an 8-bit register or a memory location.
Even if data are entered in decimal digits, it is inefficient to process data in BCD numbers
because, in each 4-bit combination, digits A through F are unused. Hence, BCD numbers
are generally converted into binary numbers for data processing.
The conversion of a BCD number into its binary equivalent employs the principle of
positional weighting in a given number:
For example: 7210 = 7 × 10 + 2
The digit 7 represents 70, based on its second position from the right.
Therefore, converting 72BCD into its binary equivalent requires multiplying the second digit
by 10 and adding the first digit.
BCD-to-Binary conversion – (2)
Converting a 2-digit BCD number into its binary equivalent requires the following steps:
The subroutine saves the contents of the BC and DE registers because these registers are used in the subroutine. Even
if this particular main program does not use the DE registers, the subroutine may be called by some other program in
which the DE registers are being used.
Binary-to-BCD conversion – (1)
Therefore, to display a BCD digit at a seven-segment LED, the table look-up technique is
used.
In the table look-up technique, the codes of the digits to be displayed are stored sequentially
in memory.
The conversion program locates the code of a digit based on its magnitude and transfers the
code to the MPU to send out to display port.
Illustrative Program: BCD-to-Common-Cathode-LED Code Conversion
BCD-TO-SEVEN-SEGMENT-LED CODE CONVERSION – (2)
BINARY-TO-ASCII AND ASCII-TO-BINARY CODE CONVERSION – (1)
The American Standard Code for Information Interchange (ASCII) is used commonly in data
communication.
It is a seven-bit code, and its 128 (27) combinations are assigned different alphanumeric characters.
For example, the hexadecimal numbers 30H to 39H represent 0 to 9 ASCII decimal numbers, and 41H
to 5AH represent capital letters A through Z; in this code, bit D7 is zero.
In serial data communication, bit D7 can be used for parity checking.
The ASCII keyboard is a standard input device for entering programs in a microcomputer.
When an ASCII character is entered, the microprocessor receives the binary equivalent of the ASCII
Hex number.
For example, when the ASCII key for digit 9 is pressed, the microprocessor receives the binary
equivalent of 39H, which must be converted to the binary 1001 for arithmetic operations.
Similarly, to display digit 9 at the terminal, the microprocessor must send out the ASCII Hex code
(39H). These conversions are done through software.
Illustrative Program: Binary-to-ASCII Hex Code Conversion
BINARY-TO-ASCII AND ASCII-TO-BINARY CODE CONVERSION – (2)
BINARY-TO-ASCII AND ASCII-TO-BINARY CODE CONVERSION – (3)
Illustrative Program: ASCII Hex-to-Binary Conversion
BCD ADDITION – (1)
BCD ADDITION – (2)
BCD ADDITION – (3)
Illustrative Program: Addition of Unsigned BCD numbers
BCD ADDITION – (4)
Illustrative Program: Addition of Unsigned BCD numbers
BCD SUBTRACTION – (1)
When subtracting two BCD numbers, the instruction DAA cannot be used to decimal adjust
the result of two packed BCD numbers; the instruction applies only to addition.
Two BCD numbers can be subtracted by using the procedure of 100’s complement (also
known as 10’s complement), similar to 2’s complement.
8085 architecture allows specific combinations of two 8-bit registers to form 16-bit
registers.
16-Bit Data Transfer (Copy) and Data Exchange Group
Introduction to Advanced Instructions and Applications – (2)
Introduction to Advanced Instructions and Applications – (3)
Arithmetic
Group
Introduction to Advanced Instructions and Applications – (4)
Arithmetic
Group
Introduction to Advanced Instructions and Applications – (5)
Instructions related to the Stack Pointer and the Program Counter
Introduction to Advanced Instructions and Applications – (6)
Instructions related to the Stack Pointer and the Program Counter
Miscellaneous Instruction
MULTIPLICATION – (1)
Multiplication can be performed by repeated addition; It is, however, an inefficient
technique for a large multiplier.
A more efficient technique can be devised by following the model of manual multiplication
of decimal numbers. For example,
In this example, the multiplier multiplies each digit of the multiplicand, starting from the
farthest right, and adds the product by shifting to the left.
Illustrative Program: Multiplication of Two 8-bit unsigned numbers
MULTIPLICATION – (2)
Subtraction With Carry – (1)
Illustrative Program: 16-bit Subtraction