大会的Linux系统调用分段错误 [英] Assembly linux syscall segmentation fault

查看:178
本文介绍了大会的Linux系统调用分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试,并具有以下组件code,它工作得非常好,但我得到一个分段故障(核心转储)的消息我的程序结束前的:

I was experimenting and have the following assembly code, which works very well, except that I get a "Segmentation fault (core dumped)" message right before my program ends:

GLOBAL _start

%define ___STDIN 0
%define ___STDOUT 1
%define ___SYSCALL_WRITE 0x04

segment .data
segment .rodata
    L1 db "hello World", 10, 0
segment .bss
segment .text
_start:
    mov eax, ___SYSCALL_WRITE
    mov ebx, ___STDOUT
    mov ecx, L1
    mov edx, 13
    int 0x80

不要紧与否我有 RET 末;我仍然得到消息。

这是什么问题?

我使用的x86和NASM。

I'm using x86 and nasm.

推荐答案

由于N.M.在评论中说,问题是,你是不是在退出程序,因此执行逃跑进入垃圾code,你会得到一个段错误。

As n.m. said in the comments, the issue is that you aren't exiting the program, so execution runs off into garbage code and you get a segfault.

您需要的是:

%define ___SYSCALL_EXIT 1

// ... at the end of _start:
    mov eax, ___SYSCALL_EXIT
    mov ebx, 0
    int 0x80

这篇关于大会的Linux系统调用分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆