|
想用汇编实现printf的调用,用如下命令行编译
gcc -c test.s
gcc -o test test.o
执行test时会出现Segmentation Fault.请大家帮帮忙
test.s代码如下
[code:1]
# standard Curry preamble
.section .data
_IntStyle: .asciz "%d"
_DoubleStyle: .asciz "%f"
_True: .asciz "TRUE"
_False: .asciz "FALSE"
.text
.globl main
.type main, @function
main:
# BeginMainFunc 4
pushl %ebp
movl %esp, %ebp
subl $4, %esp # decrement sp to make space for locals/temps
andl $-16, %esp # align the stack pointer for performance reasons
# the next two instruction is generated to initialize the accumulator,
# and also to reset the condition flags
movl $0, %eax
subl %eax, %esp
# the body of main follows
# _tmp0 = 2
movl $2, %eax # load constant value 2 into %eax
# PushParam _tmp0
pushl %eax # copy param value to stack
# LCall _PrintInt
# (save modified registers before flow of control change)
movl %eax, 4(%ebp) # spill _tmp0 from %eax to %ebp+4
movl %esp, %esi # save %esp in %esi
pushl $_IntStyle
call printf
movl %esi, %esp # restore %esp
# PopParams 4
addl $4, %esp # pop params off stack
# EndFunc
# (below handles reaching end of fn body with no explicit return)
leave
ret
[/code:1] |
|