-- var1.c -- #include <stdio.h> int sum(int, int); // sum 함수 선언 int main() { int i = 3; int hap; hap = sum(i, 5); // sum 함수 호출 printf("hap = %d \n", hap); return 0; } int sum(int a, int b) // sum 함수 정의 { int res; res = a + b; return res; } -- var1.c -- -- 실행결과 -- # gcc -o var1-att.s -S var1.c # gcc -o var1-att var1-att.s # ./var1-att hap = 8 -- 실행결과 -- -- var1-att.s -- .LC0: .string "hap = %d \n" .globl main main: pushl %ebp movl %esp, %ebp subl $16, %esp movl $3, -8(%ebp) movl $5, 4(%esp) movl -8(%ebp), %eax movl %eax, (%esp) call sum movl %eax, -4(%ebp) movl -4(%ebp), %eax movl %eax, 4(%esp) movl $.LC0, (%esp) call printf movl $0, %eax leave ret .globl sum sum: pushl %ebp movl %esp, %ebp subl $4, %esp movl 12(%ebp), %eax addl 8(%ebp), %eax movl %eax, -4(%ebp) movl -4(%ebp), %eax leave ret -- var1-att.s -- -- if1.c -- #include <stdio.h> int main() { int i; i = 10; if(i == 10) printf("i = %d\n", i); return 0; } -- if1.c -- -- ksw_if1.s -- .abc: .string "i = %d\n" .globl main main: pushl %ebp movl %esp, %ebp subl $12, %esp movl $10, -4(%ebp) cmpl $10, -4(%ebp) jne .L2 movl -4(%ebp), %eax movl %eax, -8(%ebp) #movl %eax, 4(%esp) movl $.abc, -12(%ebp) #movl $.abc, (%esp) call printf .L2: movl $0, %eax leave ret -- ksw_if1.s -- -- 실행결과 -- # gcc -o ksw_if1-att ksw_if1.s # ./ksw_if1-att i = 10 -- 실행결과 -- -- 소스분석 -- # gcc -g -o if1 if1.c # ./if1 i = 10 # objdump -S if1 | grep -A 30 main.: 080483a4 <main>: #include <stdio.h> int main() { 80483a4: 55 push %ebp 80483a5: 89 e5 mov %esp,%ebp 80483a7: 83 ec 0c sub $0xc,%esp int i; i = 10; 80483aa: c7 45 fc 0a 00 00 00 movl $0xa,0xfffffffc(%ebp) if(i == 10) 80483b1: 83 7d fc 0a cmpl $0xa,0xfffffffc(%ebp) 80483b5: 75 13 jne 80483ca <main+0x26> printf("i = %d\n", i); 80483b7: 8b 45 fc mov 0xfffffffc(%ebp),%eax 80483ba: 89 44 24 04 mov %eax,0x4(%esp) 80483be: c7 04 24 b0 84 04 08 movl $0x80484b0,(%esp) 80483c5: e8 ee fe ff ff call 80482b8 <printf@plt> return 0; 80483ca: b8 00 00 00 00 mov $0x0,%eax } 80483cf: c9 leave 80483d0: c3 ret -- 소스분석 --
Linux/기타