【发布时间】:2012-05-21 02:36:12
【问题描述】:
我创建了这个程序,它接受两个输入并将它们打印出来(很简单,是的,但它是为了练习)。它编译并运行良好,但它没有达到我的预期。这是我的代码:
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
num1 db "Enter a number:", 0
num2 db "Enter another number:", 0
.data?
buffer1 dd 100 dup(?)
buffer2 dd 100 dup(?)
.code
start:
lea eax, num1
push eax
call StdOut
lea ebx, buffer1
push ebx
call StdIn
hlt
lea eax, num2
push eax
call StdOut
lea edx, buffer2
push edx
call StdIn
xor eax, eax
xor ebx, ebx
xor edx, edx
lea eax, buffer1
push eax
call StdOut
lea ebx, buffer2
push ebx
call StdOut
push 0
call ExitProcess
end start
它显示这个输出:
Enter a number: Enter another number:
应该这样做:
Enter a number:
; wait for input.
Enter another number:
; wait for input.
; continue with program.
为什么打印在一行上?我尝试将halt 放在那里以停止该过程,但Windows 停止了程序运行,并说the program is not responding。
编辑:
这是我说要编辑的代码:
xor eax, eax
xor ebx, ebx
xor edx, edx
lea eax, buffer1
push eax
call StdOut
lea ebx, buffer2
push ebx
call StdOut
当我使用之前的代码运行它时,它显示"This program is not responding." 这是为什么?
任何帮助将不胜感激。
问候,
程序
【问题讨论】:
-
为什么不能全部打印在一行上?这就是它的作用,您必须在文本后添加 13、10。除非你真的想要一个 400 字节的缓冲区,否则你保存文本的缓冲区应该是 db 而不是 dd。
-
这将它转移到另一行,谢谢。但它仍然不等待输入,它同时显示 num1 和 num2 然后不等待输入。为什么?
标签: assembly input x86 masm masm32