# 8086 program to determine largest number in an array of n numbers

**Problem –** Write a program in 8086 microprocessor to find out the largest among 8-bit n numbers, where size “n” is stored at memory address 2000 : 500 and the numbers are stored from memory address 2000 : 501 and store the result (largest number) into memory address 2000 : 600.

**Example –**

**Algorithm –**

- Load data from offset 500 to register CL and set register CH to 00 (for count).
- Load first number(value) from next offset (i.e 501) to register AL and decrease count by 1.
- Now compare value of register AL from data(value) at next offset, if that data is greater than value of register AL then update value of register AL to that data else no change, and increase offset value for next comparison and decrease count by 1 and continue this till count (value of register CX) becomes 0.
- Store the result (value of register AL ) to memory address 2000 : 600.

**Program –**

MEMORY ADDRESS | MNEMONICS | COMMENT |
---|---|---|

400 | MOV SI, 500 | SI<-500 |

403 | MOV CL, [SI] | CL<-[SI] |

405 | MOV CH, 00 | CH<-00 |

407 | INC SI | SI<-SI+1 |

408 | MOV AL, [SI] | AL<-[SI] |

40A | DEC CL | CL<-CL-1 |

40C | INC SI | SI<-SI+1 |

40D | CMP AL, [SI] | AL-[SI] |

40F | JNC 413 | JUMP TO 413 IF CY=0 |

411 | MOV AL, [SI] | AL<-[SI] |

413 | INC SI | SI<-SI+1 |

414 | LOOP 40D | CX<-CX-1 & JUMP TO 40D IF CX NOT 0 |

416 | MOV [600], AL | AL->[600] |

41A | HLT | END |

**Explanation –**

**MOV SI, 500**: set the value of SI to 500**MOV CL, [SI]**: load data from offset SI to register CL**MOV CH, 00**: set value of register CH to 00**INC SI**: increase value of SI by 1.**MOV AL, [SI]**: load value from offset SI to register AL**DEC CL**: decrease value of register CL by 1**INC SI**: increase value of SI by 1**CMP AL, [SI]**: compares value of register AL and [SI] (AL-[SI])**JNC 413**: jump to address 413 if carry not generated**MOV AL, [SI]**: transfer data at offset SI to register AL**INC SI**: increase value of SI by 1**LOOP 40C**: decrease value of register CX by 1 and jump to address 40D if value of register CX is not zero**MOV [600], AL**: store the value of register AL to offset 600**HLT**: stop

## Recommended Posts:

- 8086 program to determine cubes of numbers in an array of n numbers
- 8086 program to determine squares of numbers in an array of n numbers
- 8086 program to determine product of corresponding elements of two array elements
- 8086 program to determine modulus of first array elements corresponding to another array elements
- 8086 program to determine sum of corresponding elements of two arrays
- 8086 program to determine subtraction of corresponding elements of two arrays
- 8086 program to add two 8 bit BCD numbers
- 8086 program to subtract two 8 bit BCD numbers
- 8086 program to multiply two 8 bit numbers
- 8086 program to add two 16-bit numbers with or without carry
- 8086 program to multiply two 16-bit numbers
- 8086 program to add two 16 bit BCD numbers with carry
- 8086 program to subtract two 16 bit BCD numbers
- 8086 program to generate AP series of n numbers
- 8086 program to find average of n numbers

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.