You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FASM中如何为int数组分配动态内存?

Win32控制台动态int数组的FASM实现需求与现有代码

我正在用FASM编写一款简单的Win32控制台程序,目标是创建动态int数组并实现求和等操作。需要为数组分配内存,让寄存器esi指向这块已分配的内存区域,后续通过[esi+n]的方式读写数组元素。

当前我的代码如下:

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'

另外,training.inc中的print_eax实现如下:

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

print_eax:
    pushad      ; 保存所有寄存器

; 跳过数据段:
    jmp     .print_eax_after_data
    .print_eax_fmt   db          "%x",10,13,0
.print_eax_after_data:

    push    eax     ; 传入参数
    push    .print_eax_fmt
    call    [printf]
    add     esp,8
    popad           ; 恢复所有寄存器
    ret

内容的提问来源于stack exchange,提问作者Davide

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 11:57:09