x86 AX 寄存器是否获得不同的值?



我想将 ax 与 5 进行比较,如果值大于 5,它将显示一个错误框。如果没有,它只会打印数字。但它总是显示即使我输入 5 该值也大于 1。问题从何而来?

.386 
.model flat,stdcall 
option casemap:none 
include c:masm32includewindows.inc
include masm32includekernel32.inc 
includelib masm32libkernel32.lib 
include masm32includemasm32.inc
includelib masm32libmasm32.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

MASM32附带了一个帮助文件:masm32helpmasmlib.chm。它说:

StdIn 从控制台接收文本输入并将其放置在缓冲区中 必需作为参数。当 Enter 为 压。

我标记了相关的单词"文本"。因此,您将获得一个 ASCII 字符串,而不是适合AX的数字。您必须先将其转换为"整数",然后才能将其与cmp进行比较。您可以使用 MASM32 功能atol

.386
.model flat,stdcall
option casemap:none
include c:masm32includewindows.inc
include masm32includekernel32.inc
includelib masm32libkernel32.lib
include masm32includemasm32.inc
includelib masm32libmasm32.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

尝试使用

mov ax, input

而不是

lea ax, input

Lea 加载指向您要寻址的项目的指针(类似于 0x12345678(,而 mov 在该地址加载实际值。

最新更新