In this program we will see how to search an element in a block of bytes using 8085.
Write 8085 Assembly language program to search a key value in a block of data using linear search technique.
In this program the data are stored at location 8002H to 8007H. The 8000H is containing the size of the block, and 8001H is holding the key value to search.After executing this program, it will return the address of the data where the item is found and store the address at location 9000H and9001H. If the item is not found, it will return FFFFH.
If the data is present in the memory at FFFFH, then also it will store FFFFH, so it is ambiguous condition. We are assuming that the data are not stored atFFFFH, so we have chosen that value to indicate the data is not present.
|F000||21, 00, 80||LXI H,8000H||Point to get array size|
|F003||4E||MOV C, M||Get the size of array|
|F004||23||INX H||Point to next location|
|F005||46||MOV B, M||Get the key value to search|
|F006||78||MOV A, B||Take the key into acc|
|F007||23||LOOP||INX H||Point to next location|
|F008||BE||CMP M||Compare memory element with Acc|
|F009||CA, 19, F0||JZ FOUND||When Z flag is set, go to FOUND|
|F00C||0D||DCR C||Decrease C by1|
|F00D||C2, 07, F0||JNZ LOOP||When Count is not 0, jump to LOOP|
|F010||21, FF, FF||LXI H, FFFF||Load FFFFHinto HL pair|
|F013||22, 00, 90||SHLD 9000H||Store at9000H|
|F016||C3, 1C, F0||JMP DONE||Jump to DONE|
|F019||22, 00, 90||FOUND||SHLD 9000H||Store at9000H|
|F01C||76||DONE||HLT||Terminate the program|