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

问题描述

我有代码

    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是静态字节(变量)?该数据存在于程序的整个生命周期中。

解决方法

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

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

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