Memo

メモ > 技術 > プログラミング言語: Assembly > C言語で書いたソースコードをアセンブリ言語に変換

■C言語で書いたソースコードをアセンブリ言語に変換
$ vi test.c … C言語ソースファイルを作成
#include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
$ gcc -S test.c … アセンブリ言語ファイルを作成(test.s が作成される) $ cat test.s … アセンブリ言語ファイルの内容を確認 .file "test.c" .section .rodata .LC0: .string "Hello, world!" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $.LC0, %edi call puts movl $0, %eax leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .ident "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-16)" .section .note.GNU-stack,"",@progbits $ as -o test.o test.s … アセンブリ言語ファイルからオブジェクトファイルを作成(test.o が作成される) $ gcc -o test test.o … リンクして実行ファイルを作成(test が作成される) $ ./test … プログラムを実行 Hello, world!

Advertisement