Assembly - Reserve array space during program?

瘦欲@ 提交于 2019-12-11 18:08:08

问题


I am in the middle of an assembly program and I want to declare an array. I have the array size in a register and I know the type of the elements (i.e. how many bytes each element is) - how can I reserve space in the heap for this array (and then access particular elements)? Do I need to call malloc?


回答1:


"malloc()" is a creature of the C runtime library.

You can certainly call "malloc()" from assembly ... provided you initialize the C runtime system first.

C and C++ both do this automatically for you; before "main()" gets invoked.

For example, here's one link for how to do it on an ARM-bassed platform:

  • http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3730.html

Here's a link from Microsoft about what standard C functions to beware of on Windows:

  • http://msdn.microsoft.com/en-us/library/xwhcs5z6%28v=vs.80%29.aspx



回答2:


I think the best way is to indeed call malloc. Consider this code for FASM:

 include 'win32a.inc' 
 ...
 invoke  malloc,eax
 mov     [myHeap],eax 

Check out: http://www.delorie.com/djgpp/doc/ug/asm/calling.html



来源:https://stackoverflow.com/questions/8496633/assembly-reserve-array-space-during-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!