0
我有一个汇编程序在这里应该打印一个字符串,允许用户输入一些文本,再次打印完全相同的文本,然后等待按键终止程序,只使用Win32本机功能。
问题是,除了打印用户输入的字符串,似乎一切正常。它只是打印一个空白的新行。 下面的代码:无法打印回输入的文本在x86程序集
global _main
extern [email protected]
extern [email protected]
extern [email protected]
extern [email protected]
section .text
_main:
mov ebp, esp
sub esp, 12
push -11
call [email protected]
mov ebx, eax
push 0
push dword [ebp - 12]
lea ecx, [_msg_end - _msg]
push ecx
lea edx, [_msg]
push edx
push ebx
call [email protected]
push -10
call [email protected]
mov ebx, eax
push 0
lea ecx, [ebp - 8]
push ecx
push 20
lea edx, [ebp - 4]
push edx
push ebx
call [email protected]
push -11
call [email protected]
mov ebx, eax
push 0
push dword [ebp - 12]
lea ecx, [ebp - 8]
push ecx
lea edx, [ebp - 4]
push edx
push ebx
call [email protected]
push -10
call [email protected]
mov ebx, eax
push 0
lea ecx, [ebp - 8]
push ecx
push 1
lea edx, [ebp - 4]
push edx
push ebx
call [email protected]
push 0
call [email protected]
_msg:
db "Hello, world!", 10
_msg_end:
编辑 - 这里的工作代码:
global _main
extern [email protected]
extern [email protected]
extern [email protected]
extern [email protected]
section .bss
_input_buf: resb 20
section .text
_main:
mov ebp, esp
sub esp, 8
push -10
call [email protected]
mov ebx, eax
push 0
lea ecx, [ebp - 4]
push ecx
push 20
lea eax, [_input_buf]
push eax
push ebx
call [email protected]
push -11
call [email protected]
mov ebx, eax
push 0
lea ecx, [ebp - 8]
push ecx
mov edx, [ebp - 4]
push edx
lea eax, [_input_buf]
push eax
push ebx
call [email protected]
push 0
call [email protected]
怎么能工作的?您不保留缓冲区的任何空间。 – 2012-03-03 11:06:36
是的,我是...比方说,在阅读最多20个字符的字符串后,我将8推入堆栈而不是ecx,然后运行该程序并键入“Benjamin”。然后它会输出“Benjamin”。 – Benjamin 2012-03-03 11:13:21