The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Other Programming Languages
|
Just find max & min in 8086
Discuss Just find max & min in 8086 in the Other Programming Languages forum on Dev Shed. Just find max & min in 8086 A place for discussing programming languages not covered in specific forums such as Assembler, COBOL, etc. - you get the idea.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 21st, 2012, 09:23 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 9
Time spent in forums: 3 h 49 m 50 sec
Reputation 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
|

January 16th, 2013, 04:41 AM
|
|
Still Learning
|
|
Join Date: Dec 2012
Location: Montreal, Canada
|
|
|
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.
|

January 16th, 2013, 08:55 AM
|
 |
Contributing User
|
|
|
|
|
To find the minimum start big. 0 isn't big.
mov min,0
__________________
[code] Code tags[/code] are essential for python code!
|

January 16th, 2013, 01:07 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
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
|

January 16th, 2013, 01:09 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|