Re: [問題] 發生 Segmentation fault

作者: descent (「雄辯是銀,沉默是金」)   2015-04-10 09:39:15
.section .data
a:
.long 10
b:
.long 20
.section .text
.globl main
.type main,@function #別忘了這句,因為main彙編函數也是被crt0.s調用的,
main本質上也是個函數
main:
mov $a, %esi
mov $b, %edi
call swapint #不要寫成 _swapint
movl $1,%eax
movl $0,%ebx
int $0x80
[descent@asm]$ gcc -o m m.s f.c
[descent@asm]$ ./m
success!!
end!
output??
[descent@asm]$ file m
m: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked
(uses shared libs), for GNU/Linux 2.6.32,
BuildID[sha1]=0xe20028448ed677fa683eef8db006b324c4421c6e, not stripped
x64 使用 register 和 stack 來傳遞變數。
※ 引述《yshihyu (yshihyu)》之銘言:
: http://blog.csdn.net/mirage1993/article/details/39759003
: 我想測試Linux彙編GAS調用C語言函數實例照上面網址代碼步驟做
: 在32bit主機可以正常編譯過 , 但是在64bit 會發生Segmentation fault (core dumped)
: 我使用 gdb ./a.out core 去看發現是是死在
: Program terminated with signal SIGSEGV, Segmentation fault.
: #0 0x00000000004005b6 in swapint (a=0x1, b=0x7fffcc70fb68) at pro.c:6
: 6 c=*a;
: 想請問一下發生SIGSEGV原因是什麼?
: 謝謝

Links booklink

Contact Us: admin [ a t ] ucptt.com