将数组的值分配给eax时出现分段错误(AT& T语法) [英] segmentation fault when assigning value of an array to eax (AT&T syntax)

查看:55
本文介绍了将数组的值分配给eax时出现分段错误(AT& T语法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想将myarray[0]的值加载到eax:

I'm just trying to load the value of myarray[0] to eax:

        .text
        .data

        # define an array of 3 words
array_words:     .word 1, 2, 3

        .globl main

main:
        # assign array_words[0] to eax
        mov $0, %edi
        lea array_words(,%edi,4), %eax

但是当我运行此命令时,我会不断出现段错误. 有人可以指出我在这里做错了什么吗?

But when I run this, I keep getting seg fault. Could someone please point out what I did wrong here?

推荐答案

标签main似乎在.data部分中.

如果系统不允许执行.data部分中的代码,则应导致分段错误.

It should lead to segmentation fault if the system doesn't allow to execute codes in .data section.

程序代码应位于.text部分.

这篇关于将数组的值分配给eax时出现分段错误(AT& T语法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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