Glulx @stkroll opcode with negative roll

I’m looking at the specification for Glulx. Section 2.5 The Stack specifies the @stkroll opcode:

stkroll L1 L2

Rotate the top L1 values on the stack. They are rotated up or down L2 places, with positive values meaning up and
negative meaning down. The current stack-count must be at least L1. If either L1 or L2 is zero, nothing happens. (If L1
and/or L2 use the stack pop mode, the roll occurs after they are popped.)

An example of two stkrolls, starting with nine values on the stack:
8 7 6 5 4 3 2 1 0  <top>

stkroll 5 1
8 7 6 5 0 4 3 2 1  <top>

stkroll 9 -3
5 0 4 3 2 1 8 7 6  <top>

The result of the first instruction makes sense to me, but not the second. Since all 9 values on the stack are included, then assuming that the operands are constants I would have thought that the result would be:

5 4 3 2 1 0 8 7 6  <top>

Why does the zero get out of expected order?

1 Like

This example seems to be applying both of the instructions in order. The second instruction starts from the result of the first, not from the original stack.

Ah, OK. I didn’t get that these were to be considered as consecutively applied.

I can’t seem to mark your answer as a solution, but thank you!