开发者

How do I implement a datatype, like a stack, in assembly?

开发者 https://www.devze.com 2023-04-09 21:13 出处:网络
I need to implement a custom data structure in assembly. Preferably, it needs to be dynamic. Something like a linked list in C++/Java where each element points to the next element. 开发者_开发知识库Pl

I need to implement a custom data structure in assembly. Preferably, it needs to be dynamic. Something like a linked list in C++/Java where each element points to the next element. 开发者_开发知识库Please note that the size of each element may vary.

How can I do this?


The same you would in C. Assembly has functions and address spaces. Start with the basics: what functions does your stack need to have? Put the actual datastructures aside and focus on the big picture.

All you need is a function to push() and a function to pop(), a place to stick these items in the memory, and a counter to tell you how much of that space you've used up.

Oh, you should probably review your data structures before starting, as in neither C++ nor Java (or any other language, as a matter of fact) does an object pushed onto a stack point to the next object on the stack. That's called a linked list.


Try implementing your data structure using C and then look at the assembly generated. For your memory needs, however, it might require some more careful considerations (such as using non-volatile vs. volatile memory for storage for the varying sized elements).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号