存储当前指令位置
有什么方法可以存储当前指令的位置,以便我可以在将来的某个时候分支回它。
我正在尝试实现一些类似 GOSUB 的功能。
现在,分支指令采用一个参数,表示相对于要跳转到的当前位置的字节数。将标签存储到我想去的地方然后分支到它很容易。如果我可以在分支之前存储当前位置,那么当涉及到返回时,我可以采用新的当前位置 - 存储的位置并将其传递给分支..
但我不知道如何.. 有什么想法吗?
Is there any way I can store the position of the current instruction so that I can branch back to it at some point in the future.
I am trying to implement some GOSUB like functionality.
Now the Branch instruction takes an argument representing the number of bytes relative to the current position to jump to. Its easy enough to store a label to where I want to go to and then branch to it. If I could store the current position just before branching, when it comes to the return I could take the new current position - the stored position and pass that to Branch..
But I can't work out how.. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Afaik(我已经做了很多 IL),不,这是不可能的,即使是这样,它几乎肯定会导致无法验证的 IL(不好),因为有无法证明堆栈是平衡的。另请记住,偏移量是 IL 指令的一部分,而不是堆栈 - 因此您无法将其存储在本地(或堆栈上)并重新加载它等。
只需更清晰地构造代码即可;在必要时使用调用来调用子方法,也许还可以使用跳转表(本质上是“切换”)。
Afaik (and I've done a good amount of IL), no this isn't possible as presented, and even if it were it would almost certainly lead to unverifiable IL (not good), as there would be no way to prove the stack is balanced. Also remember that the offset is part of the IL instruction, not the stack - so you couldn't store it in a local (or on the stack) and reload it etc.
Just structure the code more cleanly; use calls where necessary to call into sub methods, and maybe a jump-table ("switch" essentially).