首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否会在堆栈顶部创建操作和变量?

是否会在堆栈顶部创建操作和变量?
EN

Stack Overflow用户
提问于 2017-11-21 07:57:11
回答 1查看 44关注 0票数 2

根据我对这些链接(first linksecond linkthird link)的理解,堆栈块将在有方法时创建。然而,让我感到困惑的是操作和int。它们会不会在堆栈的顶部,因为我也从这个web site中读到了关于int add操作的内容。该网站声明"value1和value2必须是int类型。从操作数栈中弹出值。int结果是value1 + value2。结果被推送到操作数栈上。“

假设我有这种类型的代码:

代码语言:javascript
复制
public static int bar (int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15, int x16, int x17, int x18, int x19, int x20){
int y = x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11+x12+x13+x14+x15+x16+x17+x18+x19+x20; 
return y;
}

这是否意味着bar( )堆栈块将被创建为下面的最大值,然后19个add操作以及20个整数都位于堆栈的顶部?当我返回"y“变量时,bar( )方法堆栈块会弹出吗?请纠正我。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-11-21 08:02:17

这些值将进入堆栈。运算符在指令流中。如下所示:

代码语言:javascript
复制
PUSH x1
PUSH X2
; ADD adds the two top items on the stack, pops them, and pushes the result
ADD    ; now x1+x2 is on top of the stack
PUSH X3
ADD    ; now x1+x2+x2 is on top of the stack.
; etcetera
POP Y ; Stores the final sum into Y
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47403107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档