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.
data segment
array db 10,2,3,4,7
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
lea si, array
push si ; stack = address of array
call minArray
mov ax, 4c00h ; exit to operating system.
int 21h
ends
; subroutine minArray
; to returns the smallest byte value in a byte array of length 5-bytes
; input parameters:
; stack = address of array
; output: al = the smallest byte
minArray proc near
push bp
mov bp,sp
add sp,4
pop si
mov al, [si] ; begining min
inc si
mov cx, 4 ; counter
loopMin:
mov ah, [si]
cmp al, ah
jc next
mov al, ah
next:
inc si
loop loopMin
mov sp,bp
pop bp
ret
minArray endp
end start ; set entry point and stop the assembler.
Comments
Leave a comment