在元神操作系统中获取动态内存

1. 背景

很多应用程序中都会动态申请内存用于存储中间数据、文件数据等。在元神操作系统中可以通过API调用来申请动态内存,获取可用的内存起始地址和内存大小。

2. 方法

(1)编写程序

本例通过调用API_ALLOC_MEMORY这个API来获取可用内存的起始地址和内存大小,代码如下所示:

use32

START:
	pusha
	
	call demo_mem_alloc
	
	popa
	iret

include 'api_def.inc'

OS_API equ 0x00030C16
API_PARAM equ 0x03000000
cursor_x equ 0x02004B10
cursor_y equ 0x02004B12

demo_mem_alloc:
	pusha
	
	mov edi, API_PARAM
	mov dword [fs:edi], API_ALLOC_MEMORY
	mov dword [fs:edi+4], 0
	call pword [fs:OS_API]
	
	mov eax, [fs:edi+8]
	movzx ebx, word [fs:cursor_y]
	movzx ecx, word [fs:cursor_x]
	call print_dword		;print start address of memory for allocation
	
	mov eax, [fs:edi+12]
	add ecx, 10
	call print_dword		;print memory size for allocation
	
	add word [fs:cursor_y], 1
	
	popa
	ret
	
;print dword value
;input:
;	eax: value to print
;	ebx: y position to print
;	ecx: x position to print
print_dword:
	pusha
	
	imul edi, ebx, 80*2
	add edi, ecx
	add edi, ecx
	add edi, 14
	mov ecx,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

De-Chang Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值