Can';t通过0x80在Linux中打开文件
我试图在GAS中实现一个简单的测试程序,它打开一个文件,写入一些文本并退出。但是,对“open”的系统调用一直返回“-14”(“EFAULT-bad address”,如果我理解正确的话)。程序代码如下所示:Can';t通过0x80在Linux中打开文件,linux,assembly,x86,gnu-assembler,Linux,Assembly,X86,Gnu Assembler,我试图在GAS中实现一个简单的测试程序,它打开一个文件,写入一些文本并退出。但是,对“open”的系统调用一直返回“-14”(“EFAULT-bad address”,如果我理解正确的话)。程序代码如下所示: .intel_syntax noprefix .section .data textoutput: .asciz "Hello world!" pstr_end: .set lentext, pstr_end - textoutput filetoopen: .
.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
.intel\u语法noprefix
.第节.数据
文本输出:
.asciz“你好,世界!”
pstr_端:
.设置lentext,pstr\U结束-文本输出
文件打开:
.asciz“/tmp/tsttxt”
.第节.正文
格洛博梅因酒店
.func main
主要内容:
mov eax,5开
mov ebx,filetoopen#filname
mov ecx,2个标志:读和写
mov edx,0700#模式
int 0x80
mov ebx,eax 35;在英特尔语法中,您需要使用mov ebx,offset filetoopen
。
如果查看组装的实际指令,您可以看到它是一个内存负载:
80483e1: 8b 1d 2d 96 04 08 mov ebx,DWORD PTR ds:0x804962d
那当然错了,你需要这里的地址。这也适用于另外两种这种模式的出现。我会考虑使用YASM或NASM,如果您要使用英特尔语法来进行纯汇编编程。他们的英特尔语法“更好”。@Jonathon我喜欢GAS,可以使用Eclipse来处理汇编程序(语法突出显示、调试等),谢谢。”在这种情况下,“lea”似乎是正确的指示。