Fao1
May 4th, 2006, 09:13 PM
I am a newbie.
I have an assignment for school which I am stuck on.
I need to find the minimum value that has been stored in an array.
The problem I am having is that "ArrayMin PROC" does not output anything.
If anyone out here can help I would really appreciate it.
Here is the code I have so far:
INCLUDE Irvine32.inc
INCLUDE Macros.inc
IntegerCount = 5 ; array size
.data
prompt1 sbyte "Enter a signed integer: ",0
prompt2 sbyte "The MIN of the integers is: ",0
array sWORD IntegerCount DUP(?)
.code
main PROC
call Clrscr
mov esi,OFFSET array
mov ecx,IntegerCount
call PromptForIntegers
call ArrayMin
call DisplayMin
exit
main ENDP
;-----------------------------------------------------
PromptForIntegers PROC
;
; Prompts the user for an array of integers, and fills
; the array with the user's input.
; Receives: ESI points to the array, ECX = array size
; Returns: nothing
;-----------------------------------------------------
pushad ; save all registers
mov edx,OFFSET prompt1 ; address of the prompt
L1:
call WriteString ; display string
call ReadInt ; read integer into EAX
call Crlf ; go to next output line
mov [esi],eax ; store in array
cmp esi,4 ; next integer
loop L1
L2:
popad ; restore all registers
ret
PromptForIntegers ENDP
;-----------------------------------------------------
ArrayMin PROC
;
; Calculates the min of an array of 32-bit integers.
; Receives: ESI points to the array, ECX = array size
; Returns: EAX = MIN of the array elements
;-----------------------------------------------------
push esi ; save ESI, ECX
push ecx
mov eax,0 ; set the min to zero
L1:
cmp eax,[esi]
cmp esi,4
loop L1
pop ecx ; restore ECX, ESI
pop esi
ret ; min is in EAX
ArrayMin ENDP
;-----------------------------------------------------
DisplayMin PROC
;
; Displays the min on the screen
; Recevies: EBX = the min
; Returns: nothing
;-----------------------------------------------------
;mWrite MACRO string
push edx
mov edx,OFFSET prompt2 ; display message
call WriteString
call WriteInt ; display EBX
call Crlf
pop edx
ret
DisplayMin ENDP
END main
I have an assignment for school which I am stuck on.
I need to find the minimum value that has been stored in an array.
The problem I am having is that "ArrayMin PROC" does not output anything.
If anyone out here can help I would really appreciate it.
Here is the code I have so far:
INCLUDE Irvine32.inc
INCLUDE Macros.inc
IntegerCount = 5 ; array size
.data
prompt1 sbyte "Enter a signed integer: ",0
prompt2 sbyte "The MIN of the integers is: ",0
array sWORD IntegerCount DUP(?)
.code
main PROC
call Clrscr
mov esi,OFFSET array
mov ecx,IntegerCount
call PromptForIntegers
call ArrayMin
call DisplayMin
exit
main ENDP
;-----------------------------------------------------
PromptForIntegers PROC
;
; Prompts the user for an array of integers, and fills
; the array with the user's input.
; Receives: ESI points to the array, ECX = array size
; Returns: nothing
;-----------------------------------------------------
pushad ; save all registers
mov edx,OFFSET prompt1 ; address of the prompt
L1:
call WriteString ; display string
call ReadInt ; read integer into EAX
call Crlf ; go to next output line
mov [esi],eax ; store in array
cmp esi,4 ; next integer
loop L1
L2:
popad ; restore all registers
ret
PromptForIntegers ENDP
;-----------------------------------------------------
ArrayMin PROC
;
; Calculates the min of an array of 32-bit integers.
; Receives: ESI points to the array, ECX = array size
; Returns: EAX = MIN of the array elements
;-----------------------------------------------------
push esi ; save ESI, ECX
push ecx
mov eax,0 ; set the min to zero
L1:
cmp eax,[esi]
cmp esi,4
loop L1
pop ecx ; restore ECX, ESI
pop esi
ret ; min is in EAX
ArrayMin ENDP
;-----------------------------------------------------
DisplayMin PROC
;
; Displays the min on the screen
; Recevies: EBX = the min
; Returns: nothing
;-----------------------------------------------------
;mWrite MACRO string
push edx
mov edx,OFFSET prompt2 ; display message
call WriteString
call WriteInt ; display EBX
call Crlf
pop edx
ret
DisplayMin ENDP
END main