i'd write simple program find minimum value in array. i'm using intel 8086 architecture (if i'm right?). problem totally new assembly language , well, cannot figure out doing wrong in code, i'm stuck.
at end (before exiting) ax
register not contain result.
i'm afraid doesn't place there (i check registers' values 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 ds reg mov cx, arr_len ;arr_length counter mov bx, offset arr ;load first elem. search: inc bx cmp bl, [minimum] ;compare loaded elem 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 give me advices wrong here? in advance.
- the tiny model doesn't need setting ds explicitly. (cs=ds=es=ss)
- since bx points @ array first time, should not increment it!
inc
before looping only. - you didn't compare array element rather low byte of address iterate array.
- there's no sense in putting result in al if directly afterwards exit putting 4c00h in ax. viewing al using debugger work though.
here's version can work:
search: mov al, [bx] cmp al, [minimum] ;compare loaded elem min jnb noswap ;if al>=minimum mov [minimum], al ;new minimum noswap: inc bx loop search
Comments
Post a Comment