我想要将argv[0]
存储到一个寄存器中,然后将其打印出来,但是当我运行我的汇编程序时,出现了段错误。
跟踪:
$ nasm -f macho -o scriptname.o --prefix _ scriptname.asm
$ ld -o scriptname scriptname.o -arch i386 -lc -macosx_version_min 10.6 -e _start -no_pie
$ ./scriptname
Segmentation fault: 11
scriptname.asm:
[bits 32]
section .data
program: db "Program: %s", 0
section .text
global start
extern printf
extern exit
start:
; skip argc
add esp, 4
; ebx := argv[0]
pop ebx
push ebx
push program
call printf
add esp, 8
push 0
call exit
技术规格:
- ld 64-134.9
- nasm 0.98.40
- Xcode 4.5
- Mac OS X 10.8.2
- MacBook Pro 2009