我想将ax与5进行比较,如果该值大于5,则会显示错误框。如果没有,它只会打印该号码。但即使我输入,它总是表明该值大于5.问题来自哪里?
.386
.model flat,stdcall
option casemap:none
include c:\masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib
.data
msg db "Enter Number", 0
msg1 db "The value is too large", 0
.data?
input db 150 dup(?)
output db 150 dup(?)
.code
start:
push offset msg
call StdOut
push 100
push offset input
call StdIn
lea ax, input
cmp ax, 5
jg Toolarge
exit:
push 0
call ExitProcess
Toolarge:
push offset msg1
call StdOut
jmp start
end start
答案 0 :(得分:1)
MASM32附带一个帮助文件:\masm32\help\masmlib.chm
。它说:
StdIn从控制台接收 text 输入并将其放入缓冲区 作为参数需要。当Enter为时,该函数终止 按压。
我标记了相关的单词" text"。因此,您将获得ASCII字符串,而不是适合AX
的数字。您首先要将其转换为"整数"在将其与cmp
进行比较之前。您可以使用MASM32函数atol
:
.386
.model flat,stdcall
option casemap:none
include c:\masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib
.data
msg db "Enter Number", 0
msg1 db "The value is too large", 0
.data?
input db 150 dup(?)
output db 150 dup(?)
.code
start:
push offset msg
call StdOut
push 100
push offset input
call StdIn
push offset input
call atol
cmp eax, 5
jg Toolarge
exit:
push 0
call ExitProcess
Toolarge:
push offset msg1
call StdOut
jmp start
end start
答案 1 :(得分:0)
尝试使用
mov ax, input
而不是
lea ax, input
Lea加载指向您正在寻址的项目的指针(类似于0x12345678),而mov会加载该地址的实际值。