You are on page 1of 18

TK2633:

MICROPROCESSOR &
INTERFACING

Programming Techniques

LECTURER: DR MASRI AYOB

Dr. Masri Ayob: TK2633


LOOPING

 The programming technique used to instruct the MPU to


repeat task.
 Continuous loop

 Conditional loop

 Repeat task until certain conditions are met.

 Some loop include indexing along with counter.


 Indexing: pointing or referencing objects with

sequential numbers, i.e. data in memory are


accessed by referencing to their memory
locations.

Dr. Masri Ayob: TK2633


COUNTER

 Counter.
 Counter is constructed by

loading a number to any


register.
 Then use INR or DCR to

increment or decrement the


number respectively.
 Loop is used to update counter

value and every iteration the


number is inspected to check
whether the number is at
maximum or minimum.

Dr. Masri Ayob: TK2633


Rajah 1
BLOCK DATA TRANSFERS

 In many systems, blocks of information are


transferred from one place to another in the
microprocessor’s memory.
 Transferring Blocks of Bytes.
 Transferring Blocks of Words.

Dr. Masri Ayob: TK2633


Rajah 1
BLOCK DATA TRANSFERS

 Suppose that a block of 10 bytes of data,


beginning at memory location 2080H, is
transferred to a block of memory beginning at
location 2090H.
 The simplest method, is to use the LDA and STA
instruction to transfer each byte.
 Long program

 A more efficient way to transfer a block of data


uses the programmed-loop and counter.

Dr. Masri Ayob: TK2633


Rajah 1
Flowchart

 Flowchart required
to transfer a block
of bytes from one
area of memory to
another .

Dr. Masri Ayob: TK2633


Transfer 10 bytes of data

Dr. Masri Ayob: TK2633


BLOCK DATA TRANSFERS

 The program uses:


 the HL register pair to indirectly address the source block of
data.
 The DE register pair to indirectly address the destination
block.
 Transfers use the MOV A,M instruction to load the
accumulator from a source block memory location.
 Next, the STAX D instruction stores the accumulator data into
a destination block memory location.

The B register functions as a counter in this example.

Dr. Masri Ayob: TK2633


Rajah 1
BLOCK DATA TRANSFERS

 Large- byte block transfer >256 (FF) bytes?


 Program requires a register pair as the counter.

 Example:

 A block of bytes beginning at location 01OOH

is transferred to a block beginning at location


2800H.
 The length of this block is 300 (12CH) bytes.

Dr. Masri Ayob: TK2633


BLOCK DATA TRANSFERS

Dr. Masri Ayob: TK2633


Transferring Blocks
of Words

 In certain
applications,
16-bit words of
data must be
transferred.

Dr. Masri Ayob: TK2633


Transferring Blocks of Words

Main Program
Dr. Masri Ayob: TK2633
Transferring Blocks of Words

Dr. Masri Ayob: TK2633


BLOCK EXCHANGES

 Block exchanges are similar to block transfers


except that the data are taken from one block of
memory and exchanged with the data in a
second block of memory.
 Their main application is in sorting character
strings and numeric data.

Dr. Masri Ayob: TK2633


Byte Block Exchanges
 Suppose that we
must exchange the
80H bytes of
memory beginning
at location 2800H
with the 80H bytes
of memory
beginning at
location 2880H.

Dr. Masri Ayob: TK2633


Byte Block Exchanges

Dr. Masri Ayob: TK2633


Word Block Exchanges: Exercise

 Suppose that we must exchange the


500H words of memory beginning at
location 9000H with the 500H words
of memory beginning at location
9100H.

Dr. Masri Ayob: TK2633


Thank you
Q&A

Dr. Masri Ayob: TK2633

You might also like