-
Notifications
You must be signed in to change notification settings - Fork 0
Instruction 11 NDUP_N
This will DUP (aka duplicate) the last N1 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, N2 times.
We start by checking the value N2. We then POP the top N1 elements from the stack. We then push to the top of the stack, the popped objects, N2 times.
N1: Number of elements from the stack to duplicate N2: Number of times to duplicate
Example N1:
Stack before:
NDUP_N <
Stack after:
Value duplicated:
In the example above, since N1 was 1 and N2 was 2, this happens in order:
- Stack:
[ A, B, C, D ]
-
pop (N1=1):
D
- Stack:
[ A, B, C ]
-
push (N2=2):
D
D
- Stack:
[ A, B, C, D, D ]