-
Notifications
You must be signed in to change notification settings - Fork 0
Instruction 8 NDUP
HoverCatz edited this page Feb 21, 2024
·
4 revisions
This will DUP (aka duplicate) the last element (the top/the right-most/the last added element) on the stack, and add a copy of it to the top of the stack, N times.
We start by checking the value N. We then POP the top element alone from the stack. We then push to the top of the stack, the popped object, N times.
Example N:
Stack before:
NDUP
Stack after:
Value duplicated:
In the example above, since N was 2, this happens in order:
- Stack:
[ A, B ]
-
pop() =
B
- Stack:
[ A ]
-
push (N=2):
B
B
- Stack:
[ A, B, B ]