-4

I want to search the maximum for a list. This program does not display anything.

.586
.model flat,stdcall
option casemap:none

include WINDOWS.INC
include user32.inc
includelib USER32.LIB
include kernel32.inc
includelib KERNEL32.LIB
include masm32.inc
includelib masm32.lib

.data 

Liste dw 100,24,326,-7,4,8
titlem db "le maximun:",0

.data?

Max dw ?

findmax proto :dword,:dword

.code 

start:

xor eax,eax
xor ebx,ebx
xor esi,esi

invoke findmax,addr Liste,6
invoke dwtoa,eax,addr Max
invoke MessageBox,NULL, addr Max,addr titlem,MB_OK
invoke ExitProcess,0

findmax proc list:dword,N:dword
xor ebx,ebx
mov ebx,offset Liste
xor ax,ax

;ax <- Max
xor esi,esi
mov ax,[ebx]

.while esi<N
.if ax>[ebx]
    mov ax,[ebx]
.endif
    inc ebx
    inc ebx
    inc esi
.endw
findmax endp

end start
Martin G
  • 17,357
  • 9
  • 82
  • 98
dfkmmQKDS
  • 1
  • 1

1 Answers1

1

There are a number of problems with your code:

  • You've declared Max as a word (2 bytes), which isn't enough to hold the string generated by dwtoa in most cases. You should make it at least 4 bytes, 8 would be even better:

    Max db 8 dup(?)

  • The operand order in your if statement is wrong, and you're also doing an unsigned comparison. You should change that to:

    .if SWORD PTR [ebx]>ax ; the SWORD PTR specifier makes this a signed comparison

  • You need to have a ret instruction at the end of your findmax procedure.

Michael
  • 57,169
  • 9
  • 80
  • 125