0

ユーザーが値を入力して印刷できるようにする簡単なアセンブリプログラムを作成しようとしています。これまでのところ、次のようなものがあります。プログラムを実行すると、エラーが発生します:セグメンテーションエラー。誰か助けてくれませんか?

    .text
    STRING: .asciz "test\n"

    input: .long

    .global main
    inout:
    pushl %ebp # Prolog: push the base pointer.
    movl %esp, %ebp # and copy stack pointer to EBP.

    formatstr: .asciz "%d"

    subl $4, %esp # Reserve stack space for variable
    leal -4(%ebp), %eax # Load address of stack var in eax
    pushl $input # Push second argument of scanf
    pushl $formatstr # Push first argument of scanf
    call scanf # Call scanf

    movl $8, %esp # Clear local variables from stack.

    pushl $input
    call printf

    movl $0, %eax
    movl %ebp, %esp
    popl %ebp # Restore caller's base pointer.
    ret # Return

    main:
    pushl $STRING #push the format string printing
    call printf # print the number
    call inout

    add $4, %esp
    pushl $0
    call exit
4

1 に答える 1

2

でデータを実行したときに爆発しなかった場合

 formatstr: .asciz "%d"

おそらく、スタックを不安定なスタックポインタで使用しようとするとセグメンテーション違反が発生します。

movl $8, %esp # Clear local variables from stack.

pushl $input

おそらくあなたは

addl $8, %esp
于 2012-06-01T17:35:54.903 に答える