;Asm program to compare an array to find minimal and maximum number
;maximal no. is stored in ah and minimal in al at the end of program
org 100h
; add your code here
Lea bx, ar ;load address of array
mov cx, 1 ;start counter
mov al, [bx] ;load first no. in al
mov ah, [bx] ;load first no. in ah too
repeat:
cmp cx, 6 ;check counter for end of array
je endit ;if yes then goto endit label
inc cx ;increase counter by 1
inc bx ;increase pointer move to next no. in array
mov dl, [bx] ;load next no. in dl
cmp al, dl ;compare previous and next no. in al and dl
jl skip1 ;if al < dl then goto skip1 label
mov al, dl ;else load value of dl into al
jmp repeat ;continue to next no.
skip1:
cmp ah, dl ;compare ah and dl
jg repeat ;if ah > dl then continue to next no.
mov ah, dl ;else load value of dl into ah
jmp repeat ;continue to next no.
endit:
ret
ar db 15,4,25,64,9,12 ;array
No comments:
Post a Comment