0

I'm doing a small program where i input an array and then get the maximum and minimum number in it . I've succeeded in getting the minimum number but there is a problem in having the maximum number any help what's the problem
my code :

INCLUDE Irvine32.inc
Arr_size equ 5
.data
Arr1 SDword Arr_size dup(0)
minVal SDwORD 7fffffffh
maxVal SDwORD 000000000
strprompt Byte 'Enter integer Array items: ',0
strMsg    byte 'the Min value an Max value is ', 0



.code
main PROC
mov edx , offset strprompt
call writestring

mov ecx, LENGTHOF Arr1
mov edi, offset Arr1

L1:
call readint
mov [edi],eax

add edi, Type Arr1


cmp eax,minVal

jge Loop_stat

mov minval,eax
cmp eax, maxVal
jnge lop_state
mov maxval,eax


Loop_stat:
loop L1
mov edx, offset strMsg
call writestring
mov eax, minval
call writeint
call crlf

lop_state:
loop L1
mov eax, maxVal
call writeint
call crlf
exit
main ENDP

END main
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by untio
0

You need to realize that in this code:

cmp eax,minVal

jge Loop_stat

a greater than minVal will cause a jump to Loop_stat and it will never be compared with maxVal.

Cheers.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.