Linux ASM HelloWorld程序
我正在尝试编写我的第一个asm程序。这是我的程序到目前为止的代码Linux ASM HelloWorld程序,linux,assembly,x86,nasm,Linux,Assembly,X86,Nasm,我正在尝试编写我的第一个asm程序。这是我的程序到目前为止的代码 .data hello: .string "Hello World!!!!\n" format: .string "%s\n" .text .global _start _start: push hello push format call printf movl $1, %eax #exit movl $0, %ebx int $0x80
.data
hello: .string "Hello World!!!!\n"
format: .string "%s\n"
.text
.global _start
_start:
push hello
push format
call printf
movl $1, %eax #exit
movl $0, %ebx
int $0x80
分段错误
试试这个:
.att_syntax
.global main
.section .data
txt: .asciz "Hello World"
.section .text
mov $4, %eax
mov $1, %ebx
mov $txt, %ecx
mov $11, %edx
int $0x80
ret
试试这个:
.att_syntax
.global main
.section .data
txt: .asciz "Hello World"
.section .text
mov $4, %eax
mov $1, %ebx
mov $txt, %ecx
mov $11, %edx
int $0x80
ret
您应该在
printf
返回后弹出参数(例如使用add esp,8
)。add%esp,8
没有帮助。push$hello
和push$format
应该可以解决问题。@FrankKotler,谢谢!这些代码甚至可以汇编吗?您混合了Intel和AT&T语法。您应该在printf
返回后弹出参数(例如使用add esp,8
)。add%esp,8
没有帮助。push$hello
和push$format
应该可以解决问题。@FrankKotler,谢谢!这些代码甚至可以汇编吗?您混合了Intel和AT&T语法。