0

我需要在家庭作业项目中通过系统调用分配内存的帮助。我从命令行参数中得到一个数字“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

4

0 回答 0