我已将代码片段翻译为 IJVM,但不确定它是否有效。告诉我我做得对不对。或者我如何检查代码是否有效。这是代码。
a = 0 sum = x
while( a<= x){
sum += a;
a++;
}
这是我所做的 IJVM 代码://以下 3 行设置 a = 0
ILOAD a
BIPUSH 0
ISTORE a
//following 2 lines set sum = x
ILOAD x
ISTORE sum
//checking the condition of the loop
L1: ILOAD a
ILOAD x
ISUB
IFEQ L2 //GO TO BODY OF WHILE LOOP
ILOAD x
ILOAD a
ISUB
IFLT L3 //GO OUT OF WHILE LOOP
GOTO L1
//L2 IS THE BODY OF WHILE LOOP
L2: ILOAD sum
ILOAD a
IADD
ISTORE sum
ILOAD a
IPUSH 1
IADD
ISTORE a
GOTO L1 //AGAIN GO BACK TO CHECK THE CONDITION OF WHILE LOOP
L3: