Explaining the code: now exit

Now let’s look at this piece of code:

POP IP, RB[RS]
LD A, *(IP)
INC IP
JMP *(A)

Before we start this sequence, the situation looks like this:

     A ---> 0x15: 0x0016
             …       …
    PC ---> 0x16: 0xB372    POP IP, RB[RS]
            0x17: 0x2043    LD A, *(IP)
            0x18: 0x7003    INC IP
            0x19: 0x2004    JMP *(A)
             …       …
    IP ---> 0x32: 0x0007    LIT
            0x33: 0x0003    0x0003
            0x34: 0x002D    SQ
            0x35: 0x0020    DOT
            0x36: 0x0037    STOP
             …       …
            0x3C: 0x0035
RB[RS] ---> 0x3D: 0x9999
            0x3E: 0x9999

Now, remember when we put the return address on the return stack previously? We are now coming back from the level below and need to reestablish the sequence on the higher level again. Therefore, POP IP, RB[RS] gets the return value from the stack into the instruction pointer.

     A ---> 0x15: 0x0016
             …       …
            0x16: 0xB372    POP IP, RB[RS]
    PC ---> 0x17: 0x2043    LD A, *(IP)
            0x18: 0x7003    INC IP
            0x19: 0x2004    JMP *(A)
             …       …
            0x32: 0x0007    LIT
            0x33: 0x0003    0x0003
            0x34: 0x002D    SQ
    IP ---> 0x35: 0x0020    DOT
            0x36: 0x0037    STOP
             …       …
RB[RS] ---> 0x3C: 0x0035
            0x3D: 0x9999
            0x3E: 0x9999

What now follows is the sequence of instructions implementing the NEXT word which was already described yesterday.

The whole sequence is called EXIT or SEMI (;) in a Forth system.