assembly - x86 ax 寄存器得到不同的值?
问题描述
我想将 ax 与 5 进行比较,如果值大于 5,它将显示一个错误框。如果没有,它只会打印数字。但是即使我输入1,它总是显示值大于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
解决方案
MASM32 附带一个帮助文件:\masm32\help\masmlib.chm
. 它说:
StdIn 从控制台接收文本输入并将其作为参数放入所需的缓冲区中。该函数在按下 Enter 时终止。
我标记了相关的单词“文本”。所以,你会得到一个 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
推荐阅读
- svelte - 来自父组件的样式槽元素
- python - Django 模型的表不包含给定的字段
- javascript - Razor 中的 JavaScript 断点在 Visual Studio 2019 中不起作用
- javascript - 用于更新未在 JavaScript 中调用的 PHP 变量的 PHP 函数
- javascript - JavaScript - 将空格分隔的文本文件读入数组并用作查找表
- generics - Kotlin:可变参数(自动推断)类型参数可能吗?
- scala - 如何在 Slick 中参数化表名
- python - QueryDict 不包含隐藏的表单字段,给出 MultiValueDictKeyError
- c# - 在列表中查找缺失的必需值
- r - tikzDevice 在 RMarkdown 文档中使用时不使用 LaTeX 前导码