utcguy
February 27th, 2005, 04:11 PM
I am trying to get this program to work but all i get is a blank result and would like to know what I am doing wrong. Can you please point out what is wrong with it? Any help would be greatly appreciated.
i have created these subroutines to find the min & max elements in an array. i am not sure if it is correct.
include pcmac.inc
.model small
.586
.code
public amax
amax proc
push ebx
push ecx
mov eax, [ebx]; the first one
mx:
cmp eax, [ebx]; compare it with the current
jge cont ; its not the maximum
mov eax, [ebx] ; its a new maximum value
cont:
add ebx, 4 ; go to next element
dec ecx ; subtract 1 from count
jnz mx ; continue if its not zero
pop ecx
pop ebx
ret
amax endp
public amin
amin proc
push ebx
push ecx
mov eax, [ebx]; first one in array
mn:
cmp eax,[ebx]; compare with current min value
jle cont2; its not the minimum value
mov eax, [ebx]; its the new minimum value
cont2:
add ebx, 4 ; go to next element
dec ecx ; subtract 1 from count
jnz mn ; continue if its not zero
pop ecx
pop ebx
ret
amin endp
end
this is the main program that i created to utilize the subroutines, again I dont know if it is correct.
include pcmac.inc
.model small
.586
.stack 200h
.data
list dd -100, 7565, 380, -9866, 452, 1295, 626, -1128, 459
dd -762, 4722, 1369, 489, 8988, -23321, 6675, 4239
dd 5677, -999, 24863
lsize dd 20
arrmax dd ?
arrmin dd ?
maxmsg db 'Maximum element is: $'
minmsg db 'Minimum element is: $'
.code
extrn getddec:near, putddec:near
extrn amax:near, amin:near
lab6 proc
_begin
mov ebx, [list]
mov ecx, lsize
call amax
mov arrmax, eax
call amin
mov arrmin, eax
_putstr maxmsg
mov eax, arrmax
call putddec
_putch 13,10
_putstr minmsg
mov eax, arrmin
call putddec
_putch 13,10
lab6 endp
end lab6
i have created these subroutines to find the min & max elements in an array. i am not sure if it is correct.
include pcmac.inc
.model small
.586
.code
public amax
amax proc
push ebx
push ecx
mov eax, [ebx]; the first one
mx:
cmp eax, [ebx]; compare it with the current
jge cont ; its not the maximum
mov eax, [ebx] ; its a new maximum value
cont:
add ebx, 4 ; go to next element
dec ecx ; subtract 1 from count
jnz mx ; continue if its not zero
pop ecx
pop ebx
ret
amax endp
public amin
amin proc
push ebx
push ecx
mov eax, [ebx]; first one in array
mn:
cmp eax,[ebx]; compare with current min value
jle cont2; its not the minimum value
mov eax, [ebx]; its the new minimum value
cont2:
add ebx, 4 ; go to next element
dec ecx ; subtract 1 from count
jnz mn ; continue if its not zero
pop ecx
pop ebx
ret
amin endp
end
this is the main program that i created to utilize the subroutines, again I dont know if it is correct.
include pcmac.inc
.model small
.586
.stack 200h
.data
list dd -100, 7565, 380, -9866, 452, 1295, 626, -1128, 459
dd -762, 4722, 1369, 489, 8988, -23321, 6675, 4239
dd 5677, -999, 24863
lsize dd 20
arrmax dd ?
arrmin dd ?
maxmsg db 'Maximum element is: $'
minmsg db 'Minimum element is: $'
.code
extrn getddec:near, putddec:near
extrn amax:near, amin:near
lab6 proc
_begin
mov ebx, [list]
mov ecx, lsize
call amax
mov arrmax, eax
call amin
mov arrmin, eax
_putstr maxmsg
mov eax, arrmax
call putddec
_putch 13,10
_putstr minmsg
mov eax, arrmin
call putddec
_putch 13,10
lab6 endp
end lab6