int accum = 0;
int sum(int x, int y)
{
int t = x + y;
accum += t;
return t;
}
.globl _accum
.bss
.align 4
_accum:
.space 4
.text
.globl _sum
.def _sum; .scl 2; .type 32; .endef
_sum:
pushl %ebp
movl %esp, %ebp
subl $4, %esp # 为局部变量t在栈帧上分配空间
movl 12(%ebp), %eax # %eax <- y
addl 8(%ebp), %eax # %eax <- x + y
movl %eax, -4(%ebp) # t <- x +y
movl -4(%ebp), %eax # %eax <- t
addl %eax, _accum # _accum <- t + _accum
movl -4(%ebp), %eax # %eax <- t
leave # 平衡堆栈: %esp <- %ebp , popl %ebp
ret
.globl _accum
.bss
.align 4
_accum:
.space 4
.text
.p2align 4,,15 # 使下一条指令的地址从16的倍数处开始,
.globl _sum # 最多浪费15个字节
.def _sum; .scl 2; .type 32; .endef
_sum:
pushl %ebp # 保存原%ebp
movl %esp, %ebp
movl 12(%ebp), %eax # %eax <- y
movl 8(%ebp), %edx # %edx <- x
popl %ebp # 恢复原%ebp
addl %edx, %eax # %eax <- x + y
addl %eax, _accum # _accum <- _accum + x + y
ret
401050: 55 push %ebp
401051: 89 e5 mov %esp,%ebp
401053: 8b 45 0c mov 0xc(%ebp),%eax
401056: 8b 55 08 mov 0x8(%ebp),%edx
401059: 5d pop %ebp
40105a: 01 d0 add %edx,%eax
40105c: 01 05 10 20 40 00 add %eax,0x402010
401062: c3 ret
int accum = 0;
int sum(int x, int y)
{
int t = x + y;
accum += t;
return t;
}
.globl _accum
.bss
.align 4
_accum:
.space 4
.text
.globl _sum
.def _sum; .scl 2; .type 32; .endef
_sum:
pushl %ebp
movl %esp, %ebp
subl $4, %esp # 为局部变量t在栈帧上分配空间
movl 12(%ebp), %eax # %eax <- y
addl 8(%ebp), %eax # %eax <- x + y
movl %eax, -4(%ebp) # t <- x +y
movl -4(%ebp), %eax # %eax <- t
addl %eax, _accum # _accum <- t + _accum
movl -4(%ebp), %eax # %eax <- t
leave # 平衡堆栈: %esp <- %ebp , popl %ebp
ret
.globl _accum
.bss
.align 4
_accum:
.space 4
.text
.p2align 4,,15 # 使下一条指令的地址从16的倍数处开始,
.globl _sum # 最多浪费15个字节
.def _sum; .scl 2; .type 32; .endef
_sum:
pushl %ebp # 保存原%ebp
movl %esp, %ebp
movl 12(%ebp), %eax # %eax <- y
movl 8(%ebp), %edx # %edx <- x
popl %ebp # 恢复原%ebp
addl %edx, %eax # %eax <- x + y
addl %eax, _accum # _accum <- _accum + x + y
ret
401050: 55 push %ebp
401051: 89 e5 mov %esp,%ebp
401053: 8b 45 0c mov 0xc(%ebp),%eax
401056: 8b 55 08 mov 0x8(%ebp),%edx
401059: 5d pop %ebp
40105a: 01 d0 add %edx,%eax
40105c: 01 05 10 20 40 00 add %eax,0x402010
401062: c3 ret