2012-03-03 14 views
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: 

EDIT

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] 
+0

どのように仕事ができますか?あなたはバッファのためのスペースを予約していません。 –

+0

はい私は、最大20文字の長い文字列を読んだ後にecxの代わりに8をスタックにプッシュし、プログラムを実行して「Benjamin」と入力するとしましょう。それから "Benjamin"を出力します。 – Benjamin

答えて

1

2つのこと: は、ここでは、コードです

あなたが唯一の4つのバイトを割り当てている - 2つの文字のためのスペースを作る - などスタック上の最後に割り当てられたdwordへの入力を読み込んでいます:

ebp-12 [undefined] 
ebp-8: [input length] 
ebp-4: [input buffer] 
ebp: 

は、あなたはそれが出力したバイトの膨大な数を試し作り、それを逆参照するのではなくポインタとして入力文字列の長さを与え、そして失敗している:

lea ecx, [ebp - 8] 
push ecx <- address, not value 
関連する問題