I'd like to write a simple program to find the minimum value in an array. I'm using Intel 8086 architecture (if I'm right?). The problem is that I am totally new to Assembly language and well, I just cannot figure out what am I doing wrong in my code, I'm stuck.
At the end (before exiting) my ax
register does not contain my result.
I'm afraid it doesn't even place it there (I check registers' values with Turbo Debugger tool).
.MODEL TINY
Data SEGMENT
arr_len EQU 5
arr DB 07h, 02h, 03h, 10h, 12h
minimum DB 255
Data ENDS
Code SEGMENT
ORG 100h
ASSUME CS:Code, DS:Data, SS:Code
Start:
mov ax, SEG Data
mov ds, ax ;load data to ds reg
mov cx, arr_len ;arr_length to counter
mov bx, OFFSET arr ;load first elem.
Search:
inc bx
cmp bl, [minimum] ;compare loaded elem with min
jb Swap ;if bl<minimum
Swap:
mov minimum, bl
loop Search
mov al, minimum ;result here?
mov ax, 4C00h
int 21h
Code ENDS
END Start
Could anyone give me advices what is wrong here? Thanks in advance.
inc
before looping only.Here's a version that can work:
Search:
mov al, [bx]
cmp al, [minimum] ;compare loaded elem with min
jnb NoSwap ;if al>=minimum
mov [minimum], al ;New minimum
NoSwap:
inc bx
loop Search