Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux ASM HelloWorld程序_Linux_Assembly_X86_Nasm - Fatal编程技术网

Linux ASM HelloWorld程序

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

我正在尝试编写我的第一个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
分段错误

试试这个:

.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语法。