在Linux的x86_64程序集中创建新文件

问题描述

我正在尝试在Linux中使用open系统调用,在手册页中它包含3个参数,分别为pathnameflags文件mode。我尝试使用程序集x86_64(Linux)来实现它,但是它没有创建文件。顺便说一句,此系统调用的返回值存储在哪里? open()的返回值是该文件文件描述符,然后我要写入该文件

section .text
    global _start

section .data
    pathname db "/home/user/Desktop/myfile.txt"

_start:
    mov rax,2 ; syscall open
    mov rbx,pathname ; absolute path
    mov rcx,"O_CREAT" ; flag (create)
    mov rdx,"w" ; write (create file if not exists)
    syscall
    
    mov rax,60
    mov rbx,0
    syscall

重复文件似乎对我不起作用,它不会创建文件。而且我的路径是有效的。

section .text
    global _start

section .data
    pathname db "/home/user/Desktop/myfile.txt"

_start:
    mov rax,2
    mov rdi,pathname
    mov rsi,0x441   ; O_CREAT| O _WRONLY | O_APPEND
    syscall
    
    mov r8,rax      ; save the file handle
    
    mov rax,60 ; exit syscall
    mov rbx,0 ; 0 successful
    syscall

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)