【发布时间】:2016-02-03 23:15:07
【问题描述】:
我正在尝试在 GAS 中实现一个简单的测试程序,该程序打开一个文件,向其中写入一些文本并退出。但是,“打开”的系统调用不断返回“-14”(“EFAULT - 错误地址”,如果我理解正确的话)。程序代码如下:
.intel_syntax noprefix
.section .data
textoutput:
.asciz "Hello world!"
pstr_end:
.set lentext, pstr_end - textoutput
filetoopen:
.asciz "/tmp/tsttxt"
.section .text
.globl main
.func main
main:
mov eax, 5 # open
mov ebx, filetoopen # filname
mov ecx, 2 # flags: read and write
mov edx, 0700 # mode
int 0x80
mov ebx, eax # <<< !!! eax here contains -14
mov eax, 4
mov ecx, textoutput
mov edx, lentext
int 0x80
mov eax, 1
mov ebx, 0
int 0x80
问题似乎出在filetoopen 字符串上(open 的联机帮助页说 EFAULT 表示pathname points outside your accessible address space。)filetoopen 是否在程序代码中正确声明?此错误的原因可能是什么?
谢谢。
【问题讨论】:
-
如果您打算使用英特尔语法进行纯汇编编程,我会考虑使用 YASM 或 NASM。他们的英特尔语法“更好”。
-
@Jonathon 我喜欢 GAS,可以使用 Eclipse 来处理汇编程序(语法高亮、调试等)
标签: linux assembly x86 gnu-assembler