Chapter 6: Runtime System

100: MOVE #600, SP 300: action-4
108: action-1 320: ADD #qsize, SP
128: ADD #ssize, SP 328: MOVE 344, *SP
136: MOVE 152, *SP 336: GOTO 200
144: GOTO 300 344: SUB #qsize, SP
152: SUB #ssize, SP 352: action-5
160: action-2 372 ADD #qsize, SP
180: HALT 380: MOVE 396, *SP
. . . 388: GOTO 300
  396 SUB #qsize, SP
200: action-3 404: action-6
220: GOTO *0(SP) 424: ADD #qsize, SP
. . . 432: MOVE 448, *SP
  440: GOTO 300
  448: SUB #qsize, SP
  456: GOTO *0(SP)

We assume here that:

The code for s starts at 100.

The code for p starts at 200.

The code for q starts at 300.

The stack area starts at 600.

Code for 'action' takes 20 bytes.

At the beginning, we push 600 to SP so that it points to the start of the stack area. We simplify the strategy outlined earlier. Here we note that 136+16 is 152 (in line 136) and so on in all the MOV instructions at address x, we have written MOV x+16, *SP.