Skip to content

Stack Manipulation

AmazingMech2418 edited this page Jun 30, 2021 · 1 revision

Stack Manipulation

ScratchForth also borrows some functions from Forth for stack manipulation.

Here they are.

dup duplicates the last item of the stack

Before: 1 2 3 4

After: 1 2 3 4 4

swap swaps the last two items of the stack

Before: 1 2 3 4

After: 1 2 4 3

over duplicates the second to last item of the stack

Before: 1 2 3 4

After: 1 2 3 4 3

drop removes the last item of the stack

Before: 1 2 3 4

After: 1 2 3

rot rotates the last 3 items of the stack

Before: 1 2 3 4

After: 1 3 4 2

Clone this wiki locally