〔リスト1〕ATTの文法で生成されたアセンブラ・ソース(test236_att.s)
|
.file "test236.c"
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $1, -4(%ebp)
movl $1, -8(%ebp)
movl $0, -12(%ebp)
movl $2, -4(%ebp)
movl $3, -4(%ebp)
movl $4, -4(%ebp)
.L2:
cmpl $99, -12(%ebp)
jle .L4
jmp .L3
.L4:
cmpl $19, -8(%ebp)
jg .L5
movl -4(%ebp), %eax
movl %eax, -8(%ebp)
leal -12(%ebp), %eax
incl (%eax)
jmp .L2
.L5:
movl -12(%ebp), %eax
movl %eax, -8(%ebp)
leal -12(%ebp), %eax
addl $2, (%eax)
jmp .L2
.L3:
subl $8, %esp
pushl -8(%ebp)
pushl $.LC0
call printf
addl $16, %esp
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
〔リスト2〕Intelの文法で生成されたアセンブラ・ソース(test236_intel.s)
|
.file "test236.c"
.intel_syntax
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
push %ebp
mov %ebp, %esp
sub %esp, 24
and %esp, -16
mov %eax, 0
sub %esp, %eax
mov DWORD PTR [%ebp-4], 1
mov DWORD PTR [%ebp-8], 1
mov DWORD PTR [%ebp-12], 0
mov DWORD PTR [%ebp-4], 2
mov DWORD PTR [%ebp-4], 3
mov DWORD PTR [%ebp-4], 4
.L2:
cmp DWORD PTR [%ebp-12], 99
jle .L4
jmp .L3
.L4:
cmp DWORD PTR [%ebp-8], 19
jg .L5
mov %eax, DWORD PTR [%ebp-4]
mov DWORD PTR [%ebp-8], %eax
lea %eax, [%ebp-12]
inc DWORD PTR [%eax]
jmp .L2
.L5:
mov %eax, DWORD PTR [%ebp-12]
mov DWORD PTR [%ebp-8], %eax
lea %eax, [%ebp-12]
add DWORD PTR [%eax], 2
jmp .L2
.L3:
sub %esp, 8
push DWORD PTR [%ebp-8]
push OFFSET FLAT:.LC0
call printf
add %esp, 16
leave
ret
.size main, .-main
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
〔リスト3〕元のCソース(test236.c)
|
#include <stdio.h>
int main ()
{
int i;
int j;
int k;
i = 1;
j = 1;
k = 0;
i = 2;
i = 3;
i = 4;
while (k < 100)
{
if (j < 20)
{
j = i;
k = k + 1;
}
else
{
j = k;
k = k + 2;
}
}
printf("%d\n",j);
}
|
|
〔リスト4〕引き数をスタックで渡す方法で生成されたアセンブラ・ソース(test238a.s)
|
.file "test238.c"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
subl $4, %esp
pushl $3
pushl $2
pushl $1
call test
addl $16, %esp
leave
ret
.size main, .-main
.globl test
.type test, @function
test:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl 12(%ebp), %eax
addl 8(%ebp), %eax
addl 16(%ebp), %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
leave
ret
.size test, .-test
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
〔リスト5〕引き数をレジスタで渡す方法で生成されたアセンブラ・ソース(test238.s)
|
.file "test238.c"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $3, %ecx
movl $2, %edx
movl $1, %eax
call test
leave
ret
.size main, .-main
.globl test
.type test, @function
test:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl %eax, -4(%ebp)
movl %edx, -8(%ebp)
movl %ecx, -12(%ebp)
movl -8(%ebp), %eax
addl -4(%ebp), %eax
addl -12(%ebp), %eax
movl %eax, -16(%ebp)
movl -16(%ebp), %eax
leave
ret
.size test, .-test
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)"
|
|
〔リスト6〕元のCソース(test238.c)
|
#include <stdio.h>
int test(int a,int b,int c);
int main(void)
{
return test(1,2,3);
}
int test(int a,int b,int c)
{
int aa;
aa = a + b + c;
return aa;
}
|
|
 記事内インデックス 連載インデックスはこちら Interfaceのトップ |
|
|
Copyright 2005 岸 哲夫
Copyright 1997-2005 CQ Publishing Co.,Ltd.
|