FASM - Set some memory for an array of int

240 Views Asked by At

Hello I'm doing a simple program in FASM where I set a dynamic array and I calculate the sum or other things. I need to allocate the memory for the array, how can I do that?

Like I want that "esi" points to a allocated memory to store the array data, so next I can do [esi+n] to save and get the values in the array.

format PE console
entry start

include 'include/WIN32A.INC'

; ====================================================================================
section '.data' data readable writeable

    insert_array_len    db  "Insert Array Size: ",0
    insert_val_str   db  "Insert Value: ",0

; ====================================================================================
section '.text' code readable executable

start:
    
    push ebp
    mov ebp,esp

    xor edi,edi

    mov esi,insert_array_len
    call print_str
    call read_hex
    mov edx,eax
    mov ecx,eax
    jz finish

set_values:
    mov esi,insert_val_str
    call print_str
    call read_hex

    mov [ebp+8+edi], eax
    inc edi
    loop set_values
    
    mov ecx,edx
    xor edi,edi

print_values:
    mov eax,[ebp+8+edi]
    inc edi
    call print_eax
    loop print_values

finish:
    call [ExitProcess]


include 'training.inc'

print_eax inside "training.inc":

; ================[print_eax]====================
; Prints eax to console:

print_eax:
    pushad      ; Keep all registers.

; Skip over the data:
    jmp     .print_eax_after_data
    .print_eax_fmt   db          "%x",10,13,0
.print_eax_after_data:

    push    eax     ; The argument.
    push    .print_eax_fmt
    call    [printf]
    add     esp,8
    popad           ; Restore all registers.
    ret
0

There are 0 best solutions below