本文介绍了堆栈增长方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我们有什么方法可以确定筹码的方向

增长(来自

较高地址到较低地址或从较低地址到较高地址

地址)?

我知道这个问题是特定于实现的,这可能不是

正确的地方

问这个。但任何提示都会对我有所帮助。


我想到了以下方式(假设实现使用

堆栈来

保存局部变量,例如在m68k处理器中)。

在函数f1()中,声明一个局部变量(local1)。

保存其地址。从f1调用另一个函数f2(),在f2()中调用
声明另一个本地

变量(local2)并将其地址返回给f1()。现在,比较local1

和local2的

地址,以确定堆栈增长的方向。


这是正确的方法这样做?我们可以比较

本地变量的地址

local1和local?如果没有,这样做的权利是什么?

此外,一些实现不使用堆栈来存储本地

变量。他们将寄存器中的本地变量存储为
。在那些实现中,如果我尝试使用
打印局部变量的地址(使用& local1),会发生什么?b $ b?我问这个,

因为当地的

变量可能没有在堆栈或某些内存位置上分配。

编译器

可能已经使用了一些通用寄存器。在这种情况下,

如果我们打印一个局部变量的地址,我们将获得什么输出?b / b
Thanx任何帮助/提示。 ...

解决方案




没有可移植的方法来做到这一点。在给定的实现中,

问题甚至可能毫无意义。 (考虑在

a Lispy机器上的C实现,其中堆栈帧是从堆中分配的。)


无论如何,你为什么要知道?


-

Chris" not a Tuvela" Dollin

要说人类是这样的,所以几乎总是自动撒谎。




没有可移植的方法来执行此操作。在给定的实现中,
问题甚至可能毫无意义。 (考虑一个Lispy机器上的C实现,其中堆栈帧是从堆中分配的。)

为什么你想知道呢?




我知道,这不可能是便携式的。但是,你能否建议一些特定的实施方式(例如摩托罗拉的68k处理器)?





您可以合法地获取任何对象的地址'没有用注册声明

关键词。如果实现选择将对象存储在寄存器中,它还必须将它存储在内存中,如果你把它的地址拿到它的b $ b。 (最有可能的是,取一个对象的地址会导致编译器*而不是*将*存储在寄存器中。)


-

Keith Thompson(The_Other_Keith)< http://www.ghoti.net / ~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Hi all,

Is there any way by which we mat determine the direction of stack
growth (from
higher address to lower address Or from lower address to higher
address) ?
I know this question is implementation specific and this may not be the
correct place
to ask this. But any hints would help me a lot.

I thought of the following way (assuming that the implementation uses
stack to
save the local variables as for instance in m68k processor).
In a function f1(), declare a local variable (local1).
save its address. Call another function f2() from f1 and in f2()
declare another local
variable (local2) and return its address to f1(). Now, compare the
addresses of local1
and local2 to determine the direction of stack growth.

Is this the right way of doing it ? Can we compare the adresses of the
local variables
local1 and local ? If not, what is the right of doing it ?
Also, some of the implementations don''t use stack to store the local
variables. They store
the local varaibles in registers. In those implementations what would
happen if I try
to print address of local variable (using &local1) ? I am asking this,
as the local
variable may not have been allocated on stack or some memory location.
The compiler
might have used some general purpose register for that. In that case,
what output
we will get if we print the address of a local variable ?
Thanx for any help/hint ....

解决方案



There is no portable way to do this. On an given implementation, the
question might even be meaningless. (Consider a C implementation on
a Lispy machine where stack frames are allocated from the heap.)

Why do you want to know, anyway?

--
Chris "not a Tuvela" Dollin
"To say that the human is thus and so is almost always to lie automatically."




There is no portable way to do this. On an given implementation, the
question might even be meaningless. (Consider a C implementation on
a Lispy machine where stack frames are allocated from the heap.)

Why do you want to know, anyway?



I know, this cannot be done portably. But, can you suggest some way for
a
specific implementation (as for instance motorola''s 68k processor) ?




You can legally take the address of any object that''s not declared
with the "register" keyword. If the implementation chooses to store
the object in a register, it must also store it in memory if you take
its address. (Most likely, taking the address of an object will cause
the compiler *not* to store it in a register.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于堆栈增长方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:02