Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

EED 3018 LABORATORY

EXPERIMENT 4:

PROGRAM LOOPS
LD C,3H
XOR A
LD HL, DATA
LD D,A
XX
ADD A,(HL)
INC HL
JR NC,YY
INC D
YY
DEC C
JR NZ,XX
LD E,A
HALT
ORG 0020H
DATA DB 75H;
DB 0ABH;
DB 32H;

Preliminary Work
Read page 9 and 10 (Branch Instructions and
Program Loops section) in the Laboratory
programming guide.
Exercise : Examine the following program.
Which register is the loop counter in the
program? What value is loaded into the loop
counter at the beginning?
Explain what the program does and find out
where the result is stored.

Laboratory Work

1. Run the program given in the exercise of the preliminary work in the simulator step by step and write the contents of registers C, A,
DE, HL , memory (HL), zero flag Z and carry flag CY in the following table after the specified instruction is executed.

Instruction

ADD A,(HL)

03
02
01

ADD A,(HL)
ADD A,(HL)

DE

HL

(HL)

CY

HALT

2. Write below a program with a loop that multiplies five 8-bit unsigned numbers in memory locations 0040H-0044H by 2 and stores the
results in the same memory locations. If any result exceeds 8-bit, your program must store an FFH byte in the memory. Test your
program in the simulator with the following 8-bit numbers pre-stored in the memory: 05H, 56H, 83H, 7FH, 0F0H. Use the same method
as in the program given in the exercise above to pre-store the numbers in the memory. Write the results in the following table.

memory address 
contents (before)

0040H

0041H

0042H

0043H

0044H

05H

56H

83H

7FH

F0H

contents (after)

LD B,5
; loop counter=5
LD HL,DATA ; HL=address of the 1st 8-bit number

You might also like