4. To find the largest and smallest number in an array of data using 8085 instruction set.

 ORG 0000h    ; Starting address of the program


MVI B, 10h    ; Set the length of the array to 16 (10h)


; Initialize the array with random data

LXI H, 3000h  ; Load the starting address of the array in HL

MOV C, B      ; Copy the length of the array to register C

INITLOOP:

MOV A, M      ; Load the current array element in A

INR A         ; Increment the value of the current array element by 1

MOV M, A      ; Store the updated value of the current array element

INX H         ; Move to the next array element

DCR C         ; Decrement the counter

JNZ INITLOOP  ; Jump back to INITLOOP if counter is not zero


; Find the largest and smallest number in the array

LXI H, 3000h  ; Load the starting address of the array in HL

MOV A, M      ; Load the first element in A

MOV B, A      ; Copy the first element to B for comparison

MOV C, A      ; Copy the first element to C for comparison

INX H         ; Move to the next element

DCR B         ; Decrement the counter

LOOP:

MOV A, M      ; Load the current element in A

CMP B         ; Compare the current element with B

JC NOTMAX     ; Jump to NOTMAX if current element is not greater than B

MOV B, A      ; Copy the current element to B if it is greater

NOTMAX:

CMP C         ; Compare the current element with C

JNC NOTMIN    ; Jump to NOTMIN if current element is not less than C

MOV C, A      ; Copy the current element to C if it is less

NOTMIN:

INX H         ; Move to the next element

DCR B         ; Decrement the counter

JNZ LOOP      ; Jump back to LOOP if counter is not zero


; Display the results

LXI H, 4000h  ; Load the starting address of the result buffer in HL

MOV A, B      ; Copy the largest number to A

MOV M, A      ; Store the largest number in the result buffer

INX H         ; Move to the next result buffer location

MOV A, C      ; Copy the smallest number to A

MOV M, A      ; Store the smallest number in the result buffer

HLT          ; End of program


; Data section

; Reserve memory for the array and result buffer

ORG 3000h

DB 01h, 03h, 07h, 05h, 02h, 0Ah, 0Fh, 08h, 06h, 09h, 0Dh, 04h, 0Bh, 00h, 0Ch, 0Eh

ORG 4000h

DB 00h, 00h