CS402

No Comments
org 0x0100]

jmp start ; unconditionally jump over data

myarr: dw 20, 15, 203, 1004, 250, 91, 52, 666, 840, 1018
min: dw 0
max: dw 0

start:


mov bx, 0 ; initialize array index to zero
mov ax, 0 ; initialize min to zero



mov ax, [myarr+bx] ; minimum number to ax
mov cx,10


minfind: cmp ax, [myarr+bx]

jle incr1

mov ax,[myarr+bx] ;ax contains the minimum number


incr1:

add bx, 2 ; advance bx to next index

loop minfind


mov [min], ax ; write back minimum in memory



;This is the code for searching maximum number in array

mov bx, 0 ; initialize array index to zero

mov ax, 0 ; initialize max to zero

mov ax, [myarr+bx] ; maximum number to ax

mov cx,10



maxfind: cmp ax, [myarr+bx] ; are we find the maximum number

jge incr2 ; if greater or equal number

mov ax,[myarr+bx] ;ax contains the maximum number



incr2:

add bx, 2 ; incrementing the bx

loop maxfind



mov [max], ax ; writing max in memory


mov ax, 0x4c00 ; terminate program

int 0x21
Next PostNewer Post Previous PostOlder Post Home

0 comments

Post a Comment