-
Notifications
You must be signed in to change notification settings - Fork 0
Instruction 12 NDUP_ALL
This will DUP (aka duplicate) all elements (the top/the right-most/the last added element) on the stack, and add a copy of them to the top of the stack, N times.
We start by checking the value N. We then POP all elements from the stack. We then push to the top of the stack, the popped objects, N times.
Example N:
Stack before:
NDUP_ALL <
Stack after:
Values duplicated:
In the example above, since N1 was 1 and N2 was 2, this happens in order:
- Stack:
[ A, B, C, D ]
-
pop (ALL=4):
[ A, B, C, D ]
- Stack:
[ ]
-
push (N=2):
[ A, B, C, D ]
[ A, B, C, D ]
- Stack:
[ A, B, C, D, A, B, C, D ]