Exchange of blocks in Z-80


In this section we will see how we can use the Zilog Z-80 Microprocessor to Exchange the contents of each element from two different blocks.

The number of items in each block are given at location 5000H, and the blocks are at position 5050H and 5070H.

So before swapping the items in the memory is looking like this

AddressValue
5000H04H

.
.
.
5050H89H
5051H7AH
5052H2FH
5053H56H

.
.
.
5070HAFH
5071HA9H
5072HFBH
5073H21H

.
.
.

Now, we are writing a program at location 8000H to exchange the block contents.

Program

AddressHex CodesLabelsMnemonicsComments
800021 00 50
LD HL, 5000HLoad the HL pair with 5000H
8003DD 21 50 50
LD IX, 5050HSet the index register with 5050H
8007DD 7E 00
LD A, (IX+00H)Load Acc with IX + 00H
800ADD 46 20
LD B, (IX+20H)Load B with IX + 20H
800DDD 70 00LOOPLD (IX+00H), BLoad B register content at IX + 00H
8010DD 77 20
LD (IX+20H), ALoad Acc content at IX + 20H
8013DD 23
INC IXIncrease the IX register
801535
DEC (HL)Decrease the memory content, pointer by HL pair
8016C2 07 80
JP NZ, LOOPJump to Loop, when zero flag is off
801976
HALTStop the program

Output

AddressValue
5000H04H

.
.
.
5050HAFH
5051HA9H
5052HFBH
5053H21H

.
.
.
5070H89H
5071H7AH
5072H2FH
5073H56H

.
.
.

Updated on: 30-Jul-2019

137 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements