用linux汇编语言创建目录

Jay*_*ane 1 c linux directory assembly

我正在尝试创建一个小型汇编程序来创建一个文件夹.我查找了系统调用以在此页面上创建目录.它说它是在27h之前确定的.我将如何实施mkdir somename组装?

我知道该程序应该将27变为eax,但我不确定下一步该去哪里.我搜索了相当多的内容,似乎没有人在网上发布过关于此问题的内容.

这是我目前的代码(我不知道在哪个寄存器中放置文件名等):

section .data

section .text
global _start

mov eax, 27
mov ????????
....
int 80h
Run Code Online (Sandbox Code Playgroud)

谢谢

kar*_*lip 5

找出的一种方法是使用GCC翻译以下C代码:

#include <stdio.h>
#include <sys/stat.h>

int main()
{
    if (mkdir("testdir", 0777) != 0)
    {
        return -1;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

装配,用: gcc mkdir.c -S

    .file   "mkdir.c"
    .section    .rodata
.LC0:
    .string "testdir"
    .text
.globl main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    andl    $-16, %esp
    subl    $16, %esp
    movl    $511, 4(%esp)
    movl    $.LC0, (%esp)
    call    mkdir           ; interesting call
    testl   %eax, %eax
    setne   %al
    testb   %al, %al
    je  .L2
    movl    $-1, %eax
    jmp .L3
.L2:
    movl    $0, %eax
.L3:
    leave
    .cfi_restore 5
    .cfi_def_cfa 4, 4
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .ident  "GCC: (GNU) 4.5.1 20100924 (Red Hat 4.5.1-4)"
    .section    .note.GNU-stack,"",@progbits
Run Code Online (Sandbox Code Playgroud)

无论如何,ProgrammingGroundUp第272页列出了重要的系统调用,包括mkdir:

%eax   Name    %ebx                 %ecx       %edx    Notes
------------------------------------------------------------------
39     mkdir   NULL terminated    Permission           Creates the given
               directory name                          directory. Assumes all 
                                                       directories leading up 
                                                       to it already exist.
Run Code Online (Sandbox Code Playgroud)