【问题标题】:Find and display the maximum value in an array查找并显示数组中的最大值
【发布时间】:2023-03-10 13:10:02
【问题描述】:

我想搜索列表的最大值。 该程序不显示任何内容。

.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

【问题讨论】:

  • 您的代码格式需要解决,而您的问题非常不清楚。

标签: assembly masm masm32


【解决方案1】:

您的代码存在许多问题:

  • 您已将Max 声明为一个字(2 个字节),这在大多数情况下不足以容纳dwtoa 生成的字符串。你应该让它至少 4 个字节,8 会更好:

    Max db 8 dup(?)

  • if 语句中的操作数顺序错误,并且您还在进行无符号比较。您应该将其更改为:

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

  • 您需要在您的findmax 过程的末尾有一个ret 指令。

【讨论】:

    猜你喜欢
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 2019-11-26
    • 2015-09-20
    • 1970-01-01
    相关资源
    最近更新 更多