如何在 MASM(使用 Irvine 库)中读取一行中的两个整数?
How can I read two integers on single line in MASM (with Irvine lib)?
Include Irvine32.inc
.data
prompt BYTE "Input two integers: ", 0
intA DWORD ?
intB DWORD ?
.code
MAIN PROC
mov edx, OFFSEt prompt
call WriteString
call ReadDec
mov intA, eax
call ReadDec
mov intB, eax
add eax, intA
call WriteDec
exit
MAIN ENDP
END MAIN
当我依次输入“1 -> enter -> 2”时,程序运行良好。
但是当我依次输入“1 -> space bar -> 2 -> enter”时,程序输出 1
我该如何解决?
Reads a 32-bit unsigned decimal integer from standard input, stopping
when the Enter key is pressed. All valid digits occurring before a
non-numeric character are converted to the integer value. Leading
spaces are ignored.
因此根据 ReadDec
.
的定义,输入 "1 2<enter>"
应该 return 整数值 1
如果你想像那样处理输入,你必须将其作为字符串读取,自行将其解析为单独的小字符串(每个数字),然后你可以调用 Irvine lib ParseDecimal32
(或 ParseInteger32
),或创建您自己的字符串-> 数字转换。
Include Irvine32.inc
.data
prompt BYTE "Input two integers: ", 0
intA DWORD ?
intB DWORD ?
.code
MAIN PROC
mov edx, OFFSEt prompt
call WriteString
call ReadDec
mov intA, eax
call ReadDec
mov intB, eax
add eax, intA
call WriteDec
exit
MAIN ENDP
END MAIN
当我依次输入“1 -> enter -> 2”时,程序运行良好。 但是当我依次输入“1 -> space bar -> 2 -> enter”时,程序输出 1 我该如何解决?
Reads a 32-bit unsigned decimal integer from standard input, stopping when the Enter key is pressed. All valid digits occurring before a non-numeric character are converted to the integer value. Leading spaces are ignored.
因此根据 ReadDec
.
"1 2<enter>"
应该 return 整数值 1
如果你想像那样处理输入,你必须将其作为字符串读取,自行将其解析为单独的小字符串(每个数字),然后你可以调用 Irvine lib ParseDecimal32
(或 ParseInteger32
),或创建您自己的字符串-> 数字转换。