Search code examples
ijvmmic-1

IJVM is IRETURN equal to HALT ? Because both stopps the interpreter?


I think IRETURN and HALT are the same commend in IJVM. Because I tried both and both stopped the interpreter.


Solution

  • They are not the same (what would be the point of having two instructions doing the same thing?).

    See the description in https://en.wikipedia.org/wiki/IJVM:

    HALT is described as "Halt the simulator"

    IRETURN is described as "Return from method with integer value"

    If your code is running the top level method they may appear to have the same effect.

    If you your top level method calls other methods you will see the distinction if the instructions are placed within the called methods:

    • HALT will still halt the simulator, thereby aborting any ongoing calculations
    • IRETURN will return from the called method to the caller