I am trying to create a linear search in assembly, and I want it to print the lowest value of the array. What I have prints the answer as 1 which is correct but if I change the arrays lowest value from 1 to 3, it wont show 3 as the lowest value.
The program declares an array of 20 elements initialized with different integer values. Then calls procedure findmin which computes the smallest element in the array in stores it in variable min. This is the code...
.model small
.stack 32
.data
arr DB 1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,21
arr_len EQU $-arr
minimum DB ?
.code
MAIN PROC FAR
mov AX, @data
mov DS, AX
call Findmin
mov AX, 4C00H
int 21H
MAIN endp
Findmin proc NEAR
mov cx, arr_len
mov bx, OFFSET arr
Search:
mov al, [bx]
cmp al, [minimum]
jnb NoSwap
mov [minimum], al
NoSwap:
inc bx
loop Search
mov al, minimum
mov ax, 4C00h
int 21h
Findmin endp
end MAIN
I'd appreciate any help. Thank you