获取符号而不是 int
当我要求用户输入 rown
& 时,我得到的是符号而不是 int。 coln
之后是 readint
和 writestring
。如何让输入的 int 显示出来?
.686
.MODEL FLAT, STDCALL
.STACK
INCLUDE Irvine32.inc
.Data
txt1 byte "ENTER NUM OF ROWS:",0dh,0ah,0
txt2 byte "ENTER NUM OF COLUMNS:",0dh,0ah,0
txt3 byte "ENTER AN ARRAY OF"
rown byte 0,"x" ;rows number
coln byte 0,":",0dh,0ah,0 ;columns number
.CODE
main PROC
mov edx,offset txt1
call writestring ;asks the user to enter the rows number
call readint
mov rown,al
mov edx,offset txt2
call writestring
call readint ;asks the user to enter the columns number
mov coln,al
mov edx, offset txt3
call writestring ;;;;; here is the problem !!!!!
call waitmsg
exit
main ENDP
END main
I'm getting symbols instead of int when I ask the user to enter the rown
& coln
with the readint
and writestring
afterward. How can I get the int entered to show up?
.686
.MODEL FLAT, STDCALL
.STACK
INCLUDE Irvine32.inc
.Data
txt1 byte "ENTER NUM OF ROWS:",0dh,0ah,0
txt2 byte "ENTER NUM OF COLUMNS:",0dh,0ah,0
txt3 byte "ENTER AN ARRAY OF"
rown byte 0,"x" ;rows number
coln byte 0,":",0dh,0ah,0 ;columns number
.CODE
main PROC
mov edx,offset txt1
call writestring ;asks the user to enter the rows number
call readint
mov rown,al
mov edx,offset txt2
call writestring
call readint ;asks the user to enter the columns number
mov coln,al
mov edx, offset txt3
call writestring ;;;;; here is the problem !!!!!
call waitmsg
exit
main ENDP
END main
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是猜测,因为代码的重要部分丢失了。
由于
readInt
读取并返回一个数字,因此您可能应该在写入之前将其重新转换为字符串。为了确定起见,请尝试输入
97
(十进制)作为列数和行数。如果我没记错的话,输出消息将是“ENTER AN ARRAY OF axa:”
I'm juts guessing since the important part of the code is missing.
Since
readInt
read and returns a number, you should probably re-convert it to a string before writing.Just to be sure, try to enter
97
(decimal) as the number of columns and rows. If I am not mistaken, the output message will be"ENTER AN ARRAY OF axa:"
欧文的
ReadInt
< /a> 将输入的数字转换为 CPU 内部格式“DWORD”。要将其写入 ASCII (WriteString
),必须对其进行转换。由于在发布的程序中仅为每个数字保留一个字节并且仅存储AL
,因此我假设仅需要转换范围 0..9。因此,只需将一个数字转换为一个 ASCII 字符。转换表如下所示:Tl;dr:只需将 48 添加到
AL
:一些注意事项:
1) Irvine 的
ReadInt
"读取 32 位有符号十进制整数”。因此,EAX
中的数字可能超出 0..9 范围,而AL
中的数字则不是有效数字。要转换 EAX 中的整个值,请查看 `在这里。2)
rown
和coln
现在是 ASCII 字符。在进一步处理之前,它们最终必须转换为整数。3) 导致两位或更多十进制数字的 DWORD 转换稍微复杂一些。必须通过重复除以 10 来隔离单个数字并存储余数。
Irvine's
ReadInt
converts the inputted number into the CPU internal format "DWORD". To write it as ASCII (WriteString
) it must be converted. Since in the posted program is reserved only one byte for each number and only storedAL
, I assume that only the range 0..9 has to be converted. Hence, just one number has to be converted to one ASCII character. A conversion table looks like this:Tl;dr: Just add 48 to
AL
:Some caveats:
1) Irvine's
ReadInt
"reads a 32-bit signed decimal integer". Thus, the number inEAX
can be out of the range 0..9 and inAL
is anything else than a valid number. To convert the whole value inEAX
take a look `here.2) At
rown
andcoln
are now ASCII characters. They eventually have to be converted to integer before further processing.3) A conversion of a DWORD that would lead to two decimal digits or more is a little bit more complicated.The single digits must be isolated by repeatedly divide by 10 and store the remainder.