In the last couple of programs, we saw how we can find out the larger and smaller number among two 8-bit numbers.
Fast forward, in this program, we are going to learn how we can find out the largest number from an array of 8-bit hexadecimal numbers.
For this program, we are going to use a total of seven memory locations, starting from 2000H.
In the 2000H memory location, we will store 06 which is the number of 8-bit numbers we will be using as a counter.
Next, from the 2001H memory location to 2006H memory locations we are going to store the 8-bit hexadecimal numbers.
The 8-bit hexadecimal numbers are CFH, 92H, EEH, F9H, A8H, and 99H.
LXI H, 2000H //using LXI we are going load HL register pair with 2000H memory location
MOV C, M // using MOV instruction, we will copy the content of 2000H ML to C register
INX H //using INX we will increment the HL register pair
MOV A, M // using MOV instruction we will copy the content of 2001H ML to the accumulator
Label2 DCR C //using DCR we will decrement the content of C register by 1
INX H //using INX we will increment the HL register pair to point the next successive memory location i.e. 20002H
CMP M //using CMP we will compare the content of the accumulator with the content of 2002H memory location
JNC Label1 //we will use JNC jump instruction to jump to DCR instruction when no carry is generated
MOV A, M //using MOV the content of memory location pointed by HL register pair will get copied to the accumulator
Label1 DCR C // using DCR we will decrement the content of C register by 1
JNZ Label2 //Jump No Zero instruction will keep on reducing DCR C until the content of C register becomes 0
STA 2007H// the result will be stored at 2007H memory location
|Memory Location||OPCODE||Operand||Label||Hex Code|