In the past, you have come across programs in which either we have found out the largest or the smallest number.

So basically the output will display both the smallest and the largest number.

Input:

For this program, we are going to use four successive memory locations starting from 2000H to 2003H. In 2000H and 2001H ML, we are going to store EFH and E9H 8-bit hexadecimal numbers and 2002H and 2003H will be kept reserved to store the smallest and the largest number.

Program:

LXI H, 2000H //using LXI we will load the content of 2000H ML in HL register pair

MOV A, H // the content of 2000H ML pointed by HL register will get copied to the accumulator

INX H //HL register pair will be incremented by one

CMP M //the content of the accumulator will be compared with the content of 2001H ML

JNC Label1 //JNC instruction is used in case the value stored accumulator is larger then it will get stored in 2003H memory location

MOV A, M //the content of 2001H ML will be copied to the accumulator

Label STA 2002// the content of accumulator will be copied to 2002H memory location

JC Label2 // if the carry flag is set then the JC jump instruction will work

MOV A, M //content of 2001H will get copied to the accumulator

Label2 STA 2003 //the content of accumulator gets copied to 2003 memory location

HLT

Programming Details
Memory Location OPCODE Operand Label Hex Code
2004 LXI H, 2000H 21H
2005 00H
2006 20H
2007 MOV A,M 7EH
2008 INX H 23H
2009 CMP M BEH
200A JNC Label D2H
200B 0EH
200C 20H
200D MOV A,M 7EH
200E STA 2002 Label 32H
200F 02H
2010 20H
2011 JC Label1 DA
2012 15H
2013 20H
2014 MOV A,M 7EH
2015 STA 2003H Label1 32H
2016 03H
2017 20H
2018 HLT 76H