开发者

Direction of stack higher memory address to lower memory address

开发者 https://www.devze.com 2023-03-23 09:47 出处:网络
Direction of stack (higher memory address to lower memory address or from lowe开发者_运维技巧r memory address to higher memory address) is dependent on machine architecture

Direction of stack (higher memory address to lower memory address or from lowe开发者_运维技巧r memory address to higher memory address) is dependent on machine architecture Example Intel : higher memory address to lower memory address SPARC : lower memory address to higher memory address

Is there any way by which we can change the direction of stack memory allocation using code.

Thanks.


In general, management of the stack is performed by the compiler (assuming we're talking about something like C or C++ here). However, the ISA may offer assistance, for instance push and pop instructions on x86.

There is no way to do this from C or C++, unless your compiler offers a non-portable language extension or a command-line option to control this (I can't see why it would, because changing this would make your program/library incompatible with all other programs/libraries!)


Stack is used on machine-instruction level. You cannot change processing unit behavior with code. The only thing one can do is to create program emulation level.


Some processors include explicit circuitry which pushes things onto a stack and pops them in various circumstances. Other processors do not include any such circuitry for a 'big' stack, but just provide a limited number of hardware registers or circuits that are used to store things like return addresses, and possibly a means by which software can copy the addresses stored in those registers or circuits to other parts of memory.

On processors whose hardware doesn't explicitly manipulate a stack in memory, one could use whatever pattern one wanted if one had control over all the code the processor would execute. Generally, however, there will be a pattern that the processor manufacturer recommends for implementing a stack, and code generated by compilers or by other people will most likely expect to use a stack implemented in that fashion.

0

精彩评论

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

关注公众号