Answer to Question #255862 in Assembler for rahi

Question #255862

Write a NEAR subroutine using 8086 assembly Language (with proper comments) that returns the smallest byte value in a byte array of length 5-bytes. The array is declared in the calling program and the base address of the array is passed to the subroutine in the stack. You should write both the calling program and subroutine.


1
Expert's answer
2021-10-26T15:09:44-0400
; 8086 assembly Language
; DosBox
org 100h
    .model small
    .stack 200h
    .data   
 array   DB 10,3,2,5,9     ; a byte array of length 5-bytes
    .code   
 start:
    mov  ax,@data     ;set segment DATA
    mov  ds,ax
    mov  es,ax

; the base address of the array is passed
; to the subroutine in the stack
    mov dx, offset array       
      PUSH DX
     CALL My_PROC
    NOP
    
    mov ah, 4ch
    int 21h        ; exit

;************************************************
; PROC My_PROC
; Input: array address in stack
; Output: AL  Smallest byte value
;************************************************
My_PROC PROC NEAR
     
   ADD SP, 2
   POP SI            ; array address
     
    MOV AL, [SI]     ; Smallest = array[0]
    MOV CX, 4        ; counter

L1:
    INC SI            ; address of next byte
    MOV AH, [SI]    ; AH = array[i]
    CMP AH,AL        ; compare Smallest and array[i]
    JNC NEXT        ; IF array[i] > Smallest goto NEXT
    MOV AL, AH        ; ELSE AL = new Smallest
NEXT:    
      LOOP L1            ; next loop
     PUSH AX            ; AL = Smallest
    SUB SP, 2         ; restore stack
    
END_PROC:
    RET
My_PROC ENDP

end start




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS