#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Just find max & min in 8086


    ;please help me why this program not work?

    dseg segment
    ;-------------------------------
    n equ 4
    arr dw 6,5,7,1
    min dw ?
    max dw ?
    ;-------------------------------
    dseg ends

    sseg segment stack
    dw 100h dup(?)
    sseg ends

    cseg segment
    assume ds:dseg,cs:cseg,ss:sseg
    start: mov ax,dseg
    mov ds,ax
    ;------------------------------
    mov si,0
    mov cl,n
    mov max,0
    mov min,0
    l1: mov ax,arr[si]
    cmp ax,max
    ja big
    jb small
    big: mov max,ax
    inc si
    dec cl
    jnz l1
    small: cmp ax,min
    jbe l2
    l2: mov min,ax
    inc si
    dec cl
    jnz l1
    ;------------------------------
    sof: mov ah,4ch
    int 21h
    cseg ends
    end start
  2. #2
  3. No Profile Picture
    Still Learning
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Montreal, Canada
    Posts
    55
    Rep Power
    39
    You do not handle the min test properly.

    On the line after the small lable you conditionally jump to lable l2 which is the next line in the program.

    This question may be in the wrong category.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    To find the minimum start big. 0 isn't big.

    mov min,0
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Thread moved to Other Programming Languages.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Code:
    mov max,0
    mov min,0
    You probably want to set this to min and max 16-bit values (e.g.)
    Code:
    mov max, -32768
    mov min, 32767
    The logic here is flawed:
    Code:
    small: cmp ax,min
    jbe l2
    l2: mov min,ax
    inc si
    dec cl
    jnz l1
    Since l2 is directly below the jbe line, the code will execute whether ax is smaller than min or not. You need to put another jmp instruction after jbe l2 to handle the case where ax >= min.
    Last edited by Scorpions4ever; January 16th, 2013 at 01:12 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo