CSC167 ยท 2079 ยท 10 marks
Write an assembly language program to find the largest number of an array using 8 bit microprocessor. (Assume appropriate array data and address where minimum array size of 15 should be considered)
Write an assembly language program to find the largest number of an array using 8 bit microprocessor. (Assume appropriate array data and address where minimum array size of 15 should be considered)[10]
MicroprocessorChapter 4: Assembly Language ProgrammingSimple sequence programsNumerical: 8085 largest number program
Assembly Language Program to Find the Largest Number in an Array (8085 Microprocessor)
Given Data (Extracted)
The question specifies no fixed numeric values, so standard exam assumptions are made:
| Item | Assumed Value |
|---|---|
| Array length stored at | 2200H |
| Array data starts at | 2201H |
| Array size (minimum required) | 15 elements (0FH) |
| Result location | 2300H |
| Data type | Unsigned 8-bit numbers |
Sample Array (15 elements)
| Address | Data |
|---|---|
| 2200H | 0FH (count = 15) |
| 2201H | 45H |
| 2202H | 78H |
| 2203H | 12H |
| 2204H | 9AH |
| 2205H | 33H |
| 2206H | FFH |
| 2207H | 56H |
| 2208H | 02H |
| 2209H | 88H |
| 220AH | 67H |
| 220BH | 1CH |
| 220CH | 99H |
| 220DH | 44H |
| 220EH | 7BH |
| 220FH | 3EH |
Algorithm
- Load count from
2200Hinto register C. - Point HL to first data element (
2201H). - Move first element to A (assume it is the largest).
- Decrement C (first element already read).
- Increment HL to next element.
- Compare current element M with A.
- If M > A, update A โ M.
- Increment HL, decrement C.
- If C โ 0, repeat from step 6.
- Store A at
2300H; HALT.
8085 Assembly Program
;-----------------------------------------------
; Find Largest Number in an Array
; Length at 2200H, Data from 2201H, Result at 2300H
;-----------------------------------------------
LDA 2200H ; A <- array length (count)
MOV C, A ; C <- count (loop counter)
LXI H, 2201H ; HL -> start of array
MOV A, M ; A <- first element (assume largest)
DCR C ; one element already read
INX H ; HL -> next element
LOOP: MOV B, M ; B <- current element
CMP B ; A - B ; if A < B, Carry = 1
JNC SKIP ; if A >= B, keep A
MOV A, B ; else A <- larger value B
SKIP: INX H ; next element
DCR C ; decrement counter
JNZ LOOP ; repeat until C = 0
STA 2300H ; store largest number
HLT ; stop
Dry Run (with Sample Data)
| Element | B | A (largest) | A < B? | Action |
|---|---|---|---|---|
| 1st (2201H) | - | 45H | - | A = 45H |
| 2202H | 78H | 45H | Yes | A = 78H |
| 2203H | 12H | 78H | No | A = 78H |
| 2204H | 9AH | 78H | Yes | A = 9AH |
| 2205H | 33H | 9AH | No | A = 9AH |
| 2206H | FFH | 9AH | Yes | A = FFH |
| 2207H | 56H | FFH | No | A = FFH |
| 2208H..220FH | โค FFH | FFH | No | A = FFH |
Final Result at 2300H = FFH (255 decimal): the largest element.
Registers Used
| Register | Purpose |
|---|---|
| A | Current largest value |
| B | Current element for comparison |
| C | Loop counter |
| HL | Memory pointer |
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.