根据我对这些链接(first link、second link和third link)的理解,堆栈块将在有方法时创建。然而,让我感到困惑的是操作和int。它们会不会在堆栈的顶部,因为我也从这个web site中读到了关于int add操作的内容。该网站声明"value1和value2必须是int类型。从操作数栈中弹出值。int结果是value1 + value2。结果被推送到操作数栈上。“
假设我有这种类型的代码:
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( )方法堆栈块会弹出吗?请纠正我。谢谢。
发布于 2017-11-21 08:02:17
这些值将进入堆栈。运算符在指令流中。如下所示:
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 Yhttps://stackoverflow.com/questions/47403107
复制相似问题