RESB:声明和填充未初始化的数据

时间:2020-08-16 12:36:33

标签: arrays assembly nasm

我有此代码:

    extern  printf      ; the C function, to be called

SECTION .bss
    array resb 10

SECTION .data       ; Data section, initialized variables

    data times 10 db 0
    a:   dd 5       ; int a=5;
    fmt: db "a=%d, eax=%d", 10, 0 ; The printf format, "\n",'0'


SECTION .text                   ; Code section.

global main     ; the standard gcc entry point

    mov eax, 0
    mov ebx, 0

print:
    push    ebp     ; set up stack frame
    mov     ebp,esp
    inc ebx
    mov     eax, [array + ebx]  ; put a from store into register
    ;add     eax, 1
    push    eax     ; value of a+2 FIRST
    push    dword [a]   ; value of variable a SECOND
    push    dword fmt   ; address of ctrl string
    call    printf      ; Call C function
    add     esp, 12     ; pop stack 3 push times 4 bytes

    mov     esp, ebp    ; takedown stack frame
    pop     ebp     ; same as "leave" op

    mov     eax,0       ;  normal, no error, return value

    ret         ; return

main:               ; the program label for the entry point

    call print
    ret

我需要为10个字节创建一个array。然后,我想填补这个记忆,我尝试做这样的事情:

int array[10];
for(int i = 0; i < 10; i++)
    array[i] = i;

我是否正确理解resb是静态字节(变量)?该数据存在于程序的整个生命周期中。

0 个答案:

没有答案