アセンブラの関数をC言語から実行する
アセンブラの関数をC言語から実行する。
Procedure
.intel_syntax noprefix .global asm3 asm3: push ebp mov ebp,esp xor eax,eax mov ah,BYTE PTR [ebp+0x8] shl ax,0x10 sub al,BYTE PTR [ebp+0xe] add ah,BYTE PTR [ebp+0xc] xor ax,WORD PTR [ebp+0x10] nop pop ebp ret
- 関数を呼ぶメインを準備(main.c)
#include <stdio.h> int asm3(int, int, int); int main(int argc, char* argv[]) { printf("0x%x\n", asm3(0xcdc485c1,0xd6bd5e88,0xe4c1548d)); return 0; }
- コンパイルする
"-m32"で32bitを指定
$ gcc -m32 -c main.c -o main.o
$ gcc -masm=intel -m32 -c test.S -o test.o
実行ファイルをコンパイル、実行
$gcc -m32 test.o main.o -o main $ ./main 0xdcce