I have translated the code fragment to IJVM, but not sure if it works or not. Tell me whether I am doing it right or not. Or how can I check whether the code works or not. Here is the code.
a = 0 sum = x
while( a<= x){
sum += a;
a++;
}
Here is the IJVM code which I did: //folowing 3 lines set 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: