Unit 3
Unit 3
CONTENTS
Objectives
Introduction
10.4.1 Rotate
10.4.2 Compare
10.5 Summary
10.6 Keywords
After studying this unit, you will able to understand the following:
Introduction
In this unit, we are going to study how to implement programming techniques and some programming examples using
them. Before going to implement these techniques, we get conversant with these techniques and understand the use of
them.
When repetitive task are considered, computers are more efficient than human beings fast and accurate, when have to add
hundreds numbers or transferring a thousand bytes of data.
Looping is the programming technique used to instruct the microprocessor to repeat tasks. A loop is the procedure which
asks the microprocessor to change the sequence of execution and perform the task repeatedly. These set of instructions also
include counting i.e., how many times the task should be repeated and indexing is use to keep track of the sequential
execution after the jump. Counting is technique allows programmer to count how many times the instruction/set of
instructions are executed. Indexing allows programmer to point or refer the data stored in sequential memory locations one
by one.
Loops can be classified into two jumps:
2. Conditional loop-repeats the task until certain data conditions are met.
Example: The following block of data is stored in the memory locations from 2050H to 2055H. Transfer the data to
the location 4055H to 405AH in the reverse order.
Data (H): 22, B4, 1A, 27, 78, 99
Solution: The assembly language program for the above stated problem is as follows:
Memory Label Opcode Operands Remarks
21 START: LXI H, 2050H ; Index for data source
50
Contd. ...
5A ; destination, Starting
40 ; at last location
06
1B DCX D
X
76. HLT ; End of program.
10.2 Additional Data Transfer Instructions
Additional data transfer instructions are between the microprocessor and memory.
Table 10.1 List of Instructions of 16-bit Data Transfer to Register Pairs (LXI).
1. LXI can load 16-bit data in register pairs and stack pointer register where as MOV can copy data from source register
to destination register and MVI can load 8-bit data into the specified register.
2. LXI is a 3-byte instruction whereas MVI and MOV are 2-byte and 1-byte instructions.
3. When data is loaded using LXI instruction then low-order byte first followed by the highorder byte where as in MVI
high-order byte first followed by the low-order byte.
The 8085 instruction set includes three types of memory transfer instructions. These instructions do not affect the flags.
Example:Register B contains 48H. Use memory location 8000H for indirect addressing
mode for instructions MOV, STAX, MVI. Also use direct addressing mode for STA instruction.
Solution: In MOV instructions, the byte 48H is copied from register B into memory location 8000H by using the HL as a
memory pointer. In STAX instructions, DE register is used as a memory pointer, the byte 48H must be copied from B into
the Accumulator first as the STAX instruction copies only from the Accumulator.
The STA instruction copies 48H from the Accumulator into the memory location 8000H.
The memory address is specified as the operand. The MVI instruction, load a byte directly in memory location by using the
HL as a memory pointer.
(a) Machine code Opcode Operands
21 LXI H, 8000H
00
80
70 MOV M, B
12 STAX D
Simple arithmetic operations describe the operations between numbers or contents of the microprocessor register. The
advanced arithmetic operations include memory as one of its operand. The arithmetic instructions referenced to memory
perform two tasks:
(a) Copy a byte from a memory location to the microprocessor.
(b) Perform arithmetic operation.
Contd....
INR and DCR instructions affect all the flags except the carry (CY) flag. As all these instructions involve a memory
location and a register and so uses register indirect addressing more.
Example: Write instructions to add the contents of the memory location 8000H to (A) and subtract the contents of the
memory 8001H from the first sum. Assume the Accumulator has 68H the memory location 8000H has 30H, and the
location 8001H has 7FH.
Solution: The contents of HL pair 8000H specify the memory location. The instruction ADD M adds 30H the contents of
memory location 8000H, to the contents of the Accumulator (68H) the instruction INX H points to the next memory
location 8001H and the instruction SUB M subtracts the contents (7FH) of memory location 8001 from the previous sum.
The assembly language program is as follows:
Machine code Opcode Operands
(Hex)
21 LXI H, 8000H
00
80
86 ADD M
23 INX H
96 SUB M
10.3.2 Related to 16-bits (Register Pairs)
The instructions related to incrementing/ decrementing 16-bit contents in a register pair are listed in Table 10.5. These
instructions do not affect any of the status of flags.
Example: Write instructions to load the number 3040H in the register pair BC. Increment the number using the
instruction INX B.
Solution: The assembly language program for the above stated problem is as follows:
Machine code Opcode Operands (Hex)
01 LXI B, 3040H 40
30
03 INX B
Example: Write instructions to load the number 2054H in the register pair BC. Decrement the number using the DCX
B.
Solution: The assembly language program for the above stated problem is as follows:
Machine code Opcode Operands (Hex)
01 LXI B, 2054H
54
20
OB DCX B
The advanced logical operations include rotate and compare instructions. The rotate instruction is related to rotating the
Accumulator bits. The compare instruction compares the data byte or register/memory contents with the contents of the
Accumulator.
10.4.1 Rotate
Rotate instructions rotate the Accumulator bits. This group includes four instructions. Two for rotating left and two are for
rotating right.
Opcode Description
Example:If contents of Accumulator are 24H then rotate left by one bit and rotate right by
one bit.
Solution: The solution to, above stated problem is as follows:
Binary value of 24H = 0 010 010 0 (a) Rotate 24H by 1-bit right
0001 0010=12H
This is equivalent to dividing by 2 (b) Rotate 24H by 1-bit left 0100 1000=48H
This is equivalent to multiplying by 2.
10.4.2 Compare
Compare instructions compares a data byte or register/memory contents with the contents of the Accumulator by
subtracting the data byte from contents of A denoted by (A). It indicates whether the data byte is greater than equal to ≥ or
less than equal to (5) by modifying the flags. The contents of Accumulator are not modified. These are two types of
compare operations listed in Table 10.7.
10.5 Summary
A loop is the procedure which asks the microprocessor to change the sequence of execution and perform the task
repeatedly.
Counting is technique allows programmer to count how many times the instruction/set of instructions are
executed.
The unconditional jump instruction creates a continuous loop which can be stopped only by the resetting of the
system.
ADD and SUB instructions implicitly assume that one of the operand is register.
10.6 Keywords
Counting: Counting is technique allows programmer to count how many times the instruction/ set of instructions are
executed.
Looping: Looping is the programming technique used to instruct the microprocessor to repeat tasks.
Machine code: Machine code or machine language is a system of instructions and data executed directly by a computer's
central processing unit.
Registers: A register, among other definitions, is a record in writing. As a verb it is to record or to be recorded in an official
list.
Rotate instructions: Rotate instructions rotate the Accumulator bits. This group includes four
instructions.
1. Explain the machine code with example.
2. Give the code for looping instruction. Explain.
1. Simple arithmetic operations describes the operations between number or contents of the microprocessor ………
(a) instruction (b) repeater
(c) register (d) None of these
2. The rotate instruction is related to rotating the bits ………
(a) accumulator (b) register
(c) instruction (d) None of these
3. Looping is the programming technique used to instruct the microprocessor to ……. tasks.