0% found this document useful (0 votes)
17 views12 pages

Unit 3

This document discusses additional assembly programming techniques including looping, additional data transfer instructions, additional arithmetic operations, and advanced logical operations. It covers continuous and conditional looping, 16-bit data transfer to register pairs, data transfer between memory and the microprocessor, arithmetic operations related to memory and 16-bits, and rotate and compare logical operations. The objectives are to understand these programming techniques and examples of implementing them in assembly language programs.

Uploaded by

kaavya shruthi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
17 views12 pages

Unit 3

This document discusses additional assembly programming techniques including looping, additional data transfer instructions, additional arithmetic operations, and advanced logical operations. It covers continuous and conditional looping, 16-bit data transfer to register pairs, data transfer between memory and the microprocessor, arithmetic operations related to memory and 16-bits, and rotate and compare logical operations. The objectives are to understand these programming techniques and examples of implementing them in assembly language programs.

Uploaded by

kaavya shruthi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 12

Unit 3: Assembly programming with additional instruction

CONTENTS
Objectives

Introduction

10.1 Looping, Counting and Indexing

10.1.1 Continuous Loop

10.1.2 Conditional Loop

10.2 Additional Data Transfer Instructions

10.2.1 16-bit Data Transfer to Registers Pairs

10.2.2 Data Transfer between Memory and Microprocessor

10.3 Additional Arithmetic Operations

10.3.1 Related to Memory

10.3.2 Related to 16-bits (Register Pairs)

10.4 Advanced Logical Operations

10.4.1 Rotate

10.4.2 Compare

10.5 Summary

10.6 Keywords

10.7 Self-Assessment Questions

10.8 Review Questions

10.9 Further Reading


Objectives

After studying this unit, you will able to understand the following:

• Discuss about the looping, counting and indexing

• Explain about the additional data transfer instruction

• Explain about the additional arithmetic operations

• Explain about the additional logical operations

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.

10.1 Looping, Counting and Indexing

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:

1. Continuous loop-repeats the tasks continuously.

2. Conditional loop-repeats the task until certain data conditions are met.

10.1.1 Continuous Loop


A continuous loop is setup by using the unconditional jump instructions. The unconditional jump instruction creates a
continuous loop which can be stopped only by the resetting of the system.

Figure 10.1: Flowchart of Continuous Loop.

10.1.2 Conditional Loop


A conditional loop is setup by the conditional jump instructions. 'These instruction check flags: zero, carry, sign etc. and
repeat the specific tasks if the conditions are satisfied. These loop usually include counting and indexing.
The conditional loops are executed in the following steps:
Step 1: Counter is setup by loading appropriate value in the register.
Step 2: Counting can be performed either by incrementing or decrementing the counter.
Step 3: Loops are setup by a conditional jump instructions.
Step 4: Flag denotes the end of counting.
It is easier to count down to zero than to count up. In counting down, the zero flag is set when the register value becomes
zero. In counting up requires the compare instruction.
These loops are executed in the following steps:
Step 1: Counter is setup by loading appropriate value in the register.
Step 2: An index or a memory pointer is required to locate where data bytes are stored. Step 3: Data should be
transferred from memory location to the microprocessor (ALU).
Step 4: Perform all data manipulation using ALU.
Step 5: The partial results should be temporarily stored in the register
Step 6: Decision making step, it decides whether the task is-completed or not indicated by a flag check.
Step 7: The result should be stored or send to an output port.
These steps can be converted into a flowchart as shown in Fig. 10.2. It is a generalized flowchart which can be used to
solve many problems. Some steps or blocks can be expanded with additional loops or some blocks may need to be
interchanged in their positions.
Key points to remembers:
1. Computer is best in repeating tasks.
2. It is fast and accurate.
3. Loops are setup by using the looping technique along with counting and indexing.
4. The computer is a versatile and powerful tools.
5. setting of loops are capable in making the decision which are based on data conditions.
1. Planning stage: In this step setting up is done. It is most difficult step as initial setup depends on the requirement of the
following step.
2. Data are generally stored in memory or read from the input port. In this step the data is brought into the microprocessor
for operations.
3. All data manipulations are carried out in this step.
4. Storage of partial results in registers is done in this step.
5. The microprocessor does not know whether it has completed all the operations. Before it can repeat the task, it needs to
get ready for the next operations.
6. This is a decision-making step. It decides whether to change the sequence of execution and repeat or to go to the next
instruction.
7. This step involves either sending the result to an output port or storing in the memory.

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

11 LXI D, 405AH ; Index for data

Contd. ...
5A ; destination, Starting

40 ; at last location

06 MVI B, 06H ; Byte counter

06

7E NEXT: MOV A, M ; Get data byte


12 STAX D ; Store data byte

23 INX H ; Next location

1B DCX D

05 DCR B ; Next count

C2 JNZ NEXT ; If counter is not 0, go

X ; back to transfer next byte

X
76. HLT ; End of program.
10.2 Additional Data Transfer Instructions

Additional data transfer instructions are between the microprocessor and memory.

10.2.1 16-bit Data Transfer to Registers Pairs


This is done with LXI mnemonic of assembly language. LXI is similar to MVI instruction except LXI loads 16-bit data in
register pairs and the stack pointer register. No flags are affected by these instructions. LXI is a 3-byte instruction where as
MVI is a 2-byte instruction.

Table 10.1 List of Instructions of 16-bit Data Transfer to Register Pairs (LXI).

Opcode Operand Description

LXI R, 16-bit Load Register Pair Immediate

LXI B, 16-bit (a) It is a 3-byte instruction

LXI D, 16-bit (b) Second byte is loaded in the low-order register


of the register pair

LXI H, 16-bit (c) Third byte is loaded in the high-order register


of the register pair.

LXI SP, 16-bit (d) The operands B, D, H, represents BC, DE, HL


registers and SP represents the stack pointer
register.

The basic difference between MVI and LXI are:

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.

10.2.2 Data Transfer between Memory and Microprocessor


The 8085 instruction set includes instructions having data transfer:

1. From memory to the microprocessor.

2. From microprocessor to the memory or directly into the memory.

(1) From Memory to the Microprocessor

The 8085 instruction set includes three types of memory transfer instructions. These instructions do not affect the flags.

Table 10.2: List of Instructions of Data Transfer from Memory to the


Microprocessor.
Opcode Operand Remark
s s
MOV R, M Move data from memory to register

(a) It is a 1-byte instruction

(b) Copies data from memory location into a


register

LDAX B/D (c) (HL) register specifies the memory location

LDAX B (d) Indirect addressing mode is used

LDAX D Load accumulator indirect

(a) It is a 1-byte instruction

(b) Copies data from memory location into the


Accumulator

(c) (BC) or (DE) register contents specifies the


memory location.

16-bit (d) Indirect addressing mode is used.

Load accumulator direct.

LDA (a) It is a 3-byte instruction

(b) Copies data from memory location specified


by the 16-bit address in the second and third
byte.

(c) Second byte is a line number and third byte


is a page number.

(d) Direct addressing mode is used.

Take care of basic difference between MVI and LXI.

R can be A, B, C, D, E, H, L any of the register.


In the above stated three instructions, it is observed that indirect addressing mode requires more 1 byte as compared to the
direct addressing mode when data to be transfer is only one byte then LDA proves to be more efficient as compared to
LDAX and MOV R, M. But for a block of memory transfer, the instruction LDA (three bytes) will have to be repeated for
each memory. On the other hand, a loop can be set up with two other instructions and the contents of a register pair can be
incremented or decremented.
(2) From Microprocessor to Memory or Directly into Memory

The instructions belonging to this category are listed in Table 10.3.

Table 10.3: List of Instructions Related to Data Transfer from Microprocessor to


Memory.
Opcod Operand Descriptio
e s n
MOV M, R Move data from register to memory
(a) It is a 1-byte instruction
(b) Copies the data from a register R, into the
memory location specified by the contents of
HL register pair
(c) Uses indirect addressing mode.
STAX B/D Store Accumulator indirect
(a) It is a 1-byte instruction
(b) Copies data from the Accumulator into the
memory location specified by the contents of
either BC or DE registers.
(c) Uses indirect addressing mode
STA 16-bit Store Accumulator direct
(a) It is a 3-byte instruction
(b) Copies data from the Accumulator into the
memory location specified by the 16-bit
operand.
(c) Uses direct addressing mode.
MVI M, 8-bit Load 8-bit data is memory
(a) It is a 2-byte instruction
(b) Second byte specifies 8-bit data
(c) Memory location is specified by the contents
of the HL register.
(d) Uses immediate addressing mode.

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

(b) Machine code Opcode Operands


11 LXI D, 8000H 00
80
78 MOV A, B

12 STAX D

10.3 Additional Arithmetic Operations

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.

10.3.1 Related to Memory


ADD and SUB instructions implicitly assume that one of the operand is register A i.e., Accumulator. After an operation, the
previous contents of the Accumulator are replaced by the result. All the flags are modified according to the result.

Table 10.4: List of Memory Related Arithmetic Operations.

Opcode Operands Description

ADD M Add memory contents


(a) It is a 1-byte instruction.
(b) Adds (M) to (A) and stores result in A.
(c) Contents of HL register specifies the memory
location.
SUB Subtract memory
(a) It is a 1-byte instruction.
(b) Subtract (M) from (A) and stores the result in
A
(c) Contents of HL register specifies the memory
location.
INR M Increments memory contents
(a) It is a 1-byte instruction
(b) Increments the contents of memory by 1, not
the memory address
(c) (HL) register specifies the memory location.

Contd....

DCR M Decrements memory contents


(a) It is a 1-byte instruction
(b) Decrements the contents of memory by 1, not
the memory address
(c) (HL) register specifies the memory location.

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.

Table 10.5: List of Arithmetic Operations Related to 16-bit.

Opcode Operands Description


INX R Increments register pairs
INX B (a) It is a 1-byte instruction.
INX D (b) Assumes the contents of two registers as one
INX H 16-bit number
INX SP (c) Increments the contents by 1

DCX R Decrements register pairs


DCX B (a) It is a 1-byte instruction
DCX D (b) Assumes the contents of two registers as one
DCX H 16-bit number.
DCX SP (c) Decreases the contents of registers pair by 1

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

10.4 Advanced Logical Operations

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.

Table 10.6: List of Rotate Instructions.

Opcode Description

RLC Rotate Accumulator left


(a) Each bit is shifted to the adjacent left position
(b) Bit D, becomes Do
(c) CY flag is modifed according to bit D7

RAL Rotate Accumulator left through carry


(a) Each bit is shifted to the adjacent left position
(b) D7 becomes the carry bit .
(c) Carry bit is shifted into Do

RRC Rotate Accumulator right


(a) Each bit is shifted right to the adjacent position
Contd. ...

(b) Bit Do becomes D,


(c) CY flag is modified according to bit Do

RAR Rotate Accumulator right through carry


(a) Each bit is shifted right to the adjacent position
(b) Do bit becomes carry bit
(c) Carry bit is shifted into D
7

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.

Give the code for rotated instruction with example.

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.

Table 10.7: List of Compare Operations.

Opcode Operands Description


CMP R/M Compare register or memory contents with contents of
Accumulator
(a) It is a 1-byte instruction.
(b) If (A) <(R/M), CY is set and zero flag is reset
(c) If (A) _(R/M), zero flag is set, CY flag is reset
(d) If (A) >(R/M), CY and zero flag are reset
(e) If memory is operand, its address is specified
by (HL)
(f) No contents are modified
(g) All remaining flags i.e., S, P, AC are affected
according to the result of subtraction.
Contd. ...

CPI 8-bit Compare immediate with Accumulator


(a) It.is 2-byte instruction
(b) Second type is 8-bit data
(c) Compares second byte with (A)
(d) If (A) < 8-bit data, CY flag is set and zero flag
is reset
(e) If (A) = 8-bit data, zero flag is set and CY flag
is reset
(f) If (A) > 8-bit data, CY and zero flags are reset
(g) No contents are modified
(h) All remaining flags i.e., S, P, AC are affected
according to the result of subtraction.

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.

10.7 Self-Assessment Questions

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.

(a) continue (b) repeat

(c) stop (d) None of these

4. A conditional loop is setup by the conditional ………. instructions

(a) jump (b) break

(c) end (d) None of these

5. ……….. is defined as a pointer or reference to an object with sequential numbers.


(a) Looping (b) Repeating
(c) Indexing (d) None of these

10.8 Review Questions


What do you mean by counting and indexing?
Explain looping with the help of example.
Explain the need of software timers.
Describe different types of loops.
Distinguish between MVI and LXI.
What are arithmetic operations?
Explain the features of arithmetic operations related to 16-bit.
What are logical operations?
How compare operation works?
How a data can be transfer between memory and microprocessor?

Answers for Self-Assessment Questions


1. (c) 2. (a) 3. (b) 4. (a) 5. (c)

You might also like