1

私はアセンブラーの学習を始めたばかりで、最初の段階で立ち往生しています.単純な関数を呼び出そうとしています. おそらく、経験豊富な誰かがこのコードの何が問題なのかを指摘することができます:

.code32
SYSEXIT = 1
.data
.text
.globl _start
_start:
        push $28  #just some random argument
        push $33 
        call myfunc
        mov $SYSEXIT, %eax
        #exit code is stored in ebx after calling  function
        int $0x80
.type myfunc, @function
myfunc:
        push %ebp #save old base pointer on a stack
        movl %esp, %ebp
        movl 8(%ebp), %ebx #first argument to ebx
        movl 12(%ebp), %ecx #second argument to ecx
        addl %ecx, %ebx  #add arguments together - store them in ebx
        movl %ebp, %esp
        pop %ebp
        ret
4

1 に答える 1

2

関数は引数が long (32 ビット) であることを想定しているため、.pushlではなく でプッシュする必要がありpushます。

また、関数が戻った後にスタックのバランスをとることを確認する必要があります。つまり、次のようなものです。

pushl $28
pushl $33
call myfunc
addl $8,%esp  # "removes" two 32-bit arguments off the stack
于 2013-03-22T08:57:34.840 に答える