Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CS II-Program 7

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

Program 7:

Aim: Write a program to find how many times ADH appears in memory block starting from
2030H and length of block is at 202f H store the count in 3000H.

Algorithm:
1. Initialize C register with zero and A register with ADH.
2. Compare data in memory location is equal to ADH. If yes increment counter by
one if no increment memory location.
3. Repeat the comparison unless ptr is equal to zero.
4. Store the result at memory location 3000H.
5. Stop program execution.

Flowchart
PROGRAM
Mnemonics
Address Label Opcode Operand Hexacode Comment
2000 START MVI C, 00 0E Move 00 to C register
2001 00 _
2002 MVI A, ADH 3E Move AD data to A register
2003 ADH _
2004 LXI H, 202FH 21 Initialize HL with 202fH
2005 2F Lower address byte
2006 20 Upper address byte
2007 MOV B, M 46 Move memory data to B register
2008 INX H 23 Increament HL by 1

2009 BACK CMP M BE Compare accumulator with memory data


200A JNZ 200E C2 If zero flag is not set , go to label NEXT
200B 0E Lower address byte
200C 20 Upper address byte
200D INR C 0C Increament counter by 1

200E NEXT INR H 23 Increament HL register pair by 1


200F DCR B 05 Decreament HL by 1

2010 JNZ 2009 C2 If zero flag is not set go to label BACK


2011 09 Lower address byte
2012 20 Upper address byte

2013 MOV A, C 79 Move memory data to A register

2014 STA 3000H 32 Store accumulator data to memory


2015 00 Lower address byte
2016 30 Upper address byte
2017 STOP RST 1 CF Stop program execution

OUTPUT
Before execution After Execution
Memory
location Memory
Data loaction Data
202F 04 202F 04
2030 12 2030 12
2031 AD 2031 AD
2032 34 2032 34
2033 AD 2033 AD
3000 02

You might also like