程序集x86使用系统调用动态分配结构数组

时间:2019-05-09 19:11:37

标签: assembly x86 system-calls brk

我需要帮助,以在家庭作业项目中通过系统调用分配内存。 我从命令行参数中得到一个数字“ x”,我需要分配包括两个dword字段的“ x”结构数组。

我尝试使用brk系统调用来做到这一点,但我认为我不太了解,这是我的尝试:

    mov eax, SYS_BRK                 ;using brk system call
    mov ebx, 0
    int 0x80
    mov [CORS], eax                  ;CORS-the array of the structs
    mov [initialallocated], eax

    mov ecx, [dronesNumber]          
    shl ecx, 3                      ;8 bytes * numberOfDrones
    mov eax, SYS_BRK
    mov ebx, [CORS]
    add ebx, ecx
    int 0x80
    mov [CORS], eax

    mov ecx, dronesNumber
    here:
    .myLoop:
            mov eax, SYS_BRK                
            mov ebx, 0
            int 0x80
            mov [CORS + 8*ecx], eax        ;segmentation fault here
            mov eax, SYS_BRK
            mov ebx, [CORS + 4*ecx]
            add ebx, ecx
            int 0x80
            mov [CORS + 4*ecx], eax

        loop .myLoop, ecx

0 个答案:

没有答案
相关问题