-op_17_xrot: ; Rotate: ( a b c -- b c a )
- mov ebx, [es:edi] ; ebx = c (top of stack)
- mov ecx, [es:edi+4] ; ecx = b (second on stack)
- mov edx, [es:edi+8] ; edx = a (third on stack)
- mov [es:edi+8], ecx ; third slot = b
- mov [es:edi+4], ebx ; second slot = c
- mov [es:edi], edx ; top slot = a
+; =============================================================================
+; Opcode 16: (Unused)
+; =============================================================================
+; Opcode 16 is reserved for future use. Currently it acts as nop.
+
+; =============================================================================
+; Opcode 17: rot (Rotate Three Elements)
+; =============================================================================
+; Stack effect: ( n1 n2 n3 -- n2 n3 n1 )
+;
+; Rotates the top three values on the data stack. The third item from the
+; top moves to the top, while the top two items shift down.
+;
+; Visual representation:
+; Before: [ ... n1 n2 n3 ] (n3 is on top)
+; After: [ ... n2 n3 n1 ] (n1 is now on top)
+;
+; When to use:
+; - Reordering stack items for complex operations
+; - Accessing values buried deeper on the stack
+; - Implementing Forth control structures
+; - Swapping values in multi-item calculations
+;
+; Example:
+; 03 01 00 00 00 ; num 1 - push n1
+; 03 02 00 00 00 ; num 2 - push n2
+; 03 03 00 00 00 ; num 3 - push n3
+; 11 ; rot - rotate
+; ; Result: stack contains 2, 3, 1 (with 1 on top)
+;
+; Note: Requires at least three items on the data stack.
+; Rotating with fewer items causes undefined behavior.
+;
+op_17_xrot:
+ mov ebx, [es:edi] ; ebx = n3 (top of stack)
+ mov ecx, [es:edi+4] ; ecx = n2 (second on stack)
+ mov edx, [es:edi+8] ; edx = n1 (third on stack)
+ mov [es:edi+8], ecx ; third slot = n2
+ mov [es:edi+4], ebx ; second slot = n3
+ mov [es:edi], edx ; top slot = n1