2079 3

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:

ItemAssumed Value
Array length stored at2200H
Array data starts at2201H
Array size (minimum required)15 elements (0FH)
Result location2300H
Data typeUnsigned 8-bit numbers

Sample Array (15 elements)

AddressData
2200H0FH (count = 15)
2201H45H
2202H78H
2203H12H
2204H9AH
2205H33H
2206HFFH
2207H56H
2208H02H
2209H88H
220AH67H
220BH1CH
220CH99H
220DH44H
220EH7BH
220FH3EH

Algorithm

  1. Load count from 2200H into register C.
  2. Point HL to first data element (2201H).
  3. Move first element to A (assume it is the largest).
  4. Decrement C (first element already read).
  5. Increment HL to next element.
  6. Compare current element M with A.
  7. If M > A, update A โ† M.
  8. Increment HL, decrement C.
  9. If C โ‰  0, repeat from step 6.
  10. 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)

ElementBA (largest)A < B?Action
1st (2201H)-45H-A = 45H
2202H78H45HYesA = 78H
2203H12H78HNoA = 78H
2204H9AH78HYesA = 9AH
2205H33H9AHNoA = 9AH
2206HFFH9AHYesA = FFH
2207H56HFFHNoA = FFH
2208H..220FHโ‰ค FFHFFHNoA = FFH

Final Result at 2300H = FFH (255 decimal): the largest element.


Registers Used

RegisterPurpose
ACurrent largest value
BCurrent element for comparison
CLoop counter
HLMemory pointer

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.