Macos OSX上的GNU程序集问题-引用字符串
在完成本教程之后,我遇到了一个问题- 一些可能的问题:Macos OSX上的GNU程序集问题-引用字符串,macos,assembly,gnu,Macos,Assembly,Gnu,在完成本教程之后,我遇到了一个问题- 一些可能的问题: 看起来处理器架构和操作系统可能与我正在研究的有很大不同。在视频中,它似乎是一个i386linux机器,我正在一台x64osx机器上工作 当注释掉helloWorldStr引用时,它会再次开始工作 使用32位指令在64位机器上组装 下面贴的是破译的代码,任何帮助都将不胜感激 # Hello World Program: .data HelloWorldStr: .ascii "Hello World" .text .g
- 看起来处理器架构和操作系统可能与我正在研究的有很大不同。在视频中,它似乎是一个i386linux机器,我正在一台x64osx机器上工作
- 当注释掉helloWorldStr引用时,它会再次开始工作
- 使用32位指令在64位机器上组装
# Hello World Program:
.data
HelloWorldStr:
.ascii "Hello World"
.text
.globl start
start:
# Load all the arguments for write():
# write(output, string, string_size)
movl $4, %eax # Load write()
movl $1, %ebx # Arg Output of write() :: STDOUT
movl $HelloWorldStr, %ecx # Referencing the Memory Loc. of the String
movl $11, %edx # Byte length of the String "Hello World"
int $0x80
# Call Exit:
movl $1, %eax
movl $0, %ebx
int $0x80
此外,还出现了一些错误:
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
因此,我将_start更改为_main,然后传递到下一个错误:
gcc HelloWorldProgram.s -m32
ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _main from /var/folders/8t/7639_vls58lgd1nnwx4dpbh40000gn/T//cc3wDW8K.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
你可以退房。用户也在使用MacOSX,并遵循使用Linux教授的类似教程
下面是一个示例hello world,它是使用比链接到答案的编译器稍新的编译器生成的(它仍然非常类似)
你好,s
.section __TEXT,__cstring,cstring_literals
L_.str:
.asciz "Hello world!\n"
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl $L_.str, (%esp)
call _puts
xorl %eax, %eax
addl $8, %esp
popl %ebp
ret
.subsections_via_symbols