8051 Program to find smallest number in block

8051-programs
8051-programs

8051 Program to find smallest number in block:

In this article we will be designing 8051 Program to find smallest number in block.

MOV DPTR,#5000H
CLR C
MOV R2,#09H
MOVX A,@DPTR
MOV 30H,A
UP: INC DPTR
MOVX A,@DPTR
CJNE A,30H,DN
SJMP NEXT
DN: JNC NEXT
MOV 30H,A
NEXT: DJNZ R2,UP
INC DPTR
MOV A,30H
MOVX @DPTR,A
RET 

8051 Program Logic to find smallest number in a block of numbers:

Block of numbers is stored at location 5000H, block contains 10 numbers stored from location 5000-5009H.

Register R2 is set as a counter for 10 numbers, it is set to 09 as two numbers are fetched during first execution.

First number is stored in Accumulator and preserved in location 30H.

Second number is then fetched and stored in accumulator, if this number is smaller than number stored at 30H it gets transferred to 30H and next number is fetched.

Next number is fetched in Accumulator and compared with number at 30H, if number is small than one stored at 30H it gets stored there else contents of 30H are preserved and next number is fetched.

It continues till count tends to 0. Once count is 0, program stops and smallest number is available at 30H and location just after the number block ends.

LEAVE A REPLY

Please enter your comment!
Please enter your name here