0% found this document useful (0 votes)
6 views

Array Program COA(1)

Uploaded by

kalpmevada1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Array Program COA(1)

Uploaded by

kalpmevada1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program for storing Data into an Array

MVI C,05H

LXI H,0008H

MVI A,01H

STORE: MOV M,A

INX H

INR A

DCR C

JNZ STORE

HLT

Program for Adding All Elements in an Array

LXI H, 8000H ; HL points to the base address of the array

MVI C, 05H ; Set count (number of elements)

MVI A, 00H ; Clear the accumulator for summation

ADD_LOOP: MOV B, M ; Load array element intoB

ADD B ; Add the element to the accumulator

INX H ; Move to the next array element

DCR C ; Decrement count


JNZ ADD_LOOP ; Repeat until count becomes zero

STA 9000H ; Store the result at 9000H

HLT ; Halt the program

Program for Searching for a Specific Value in an Array

LXI H, 8000H ; HL points to the base address of the array

MVI C, 05H ; Set count (number of elements)

MVI A, 03H ; Search value

SEARCH:

CMP M ; Compare memory value with A

JZ FOUND ; If equal, jump to FOUND

INX H ; Move to the next array element

DCR C ; Decrement count

JNZ SEARCH ; Repeat until count becomes zero

JMP NOT_FOUND ; If not found, jump to NOT_FOUND

FOUND:LXI H, 9000H ; HL points to 9000H

MOV M, A ; Store the found value


HLT ; Halt the program

NOT_FOUND: HLT ; Halt the program

You might also like