Lesson 13
The kernel's stack of numbers
Every language in these lessons runs on one kernel, a stack machine. Read without rules, a program is a list of kernel tokens.
The lesson
A number pushes itself. EMIT prints the top as a byte and READ pushes the next input byte, -1 at the end. DUP, DROP, SWAP, OVER, ADD, SUB, MUL, DIV and MOD work on the stack.
Unknown words are skipped, so lowercase notes are comments.
This kernel is the machine under Shibboleth, the language that writes itself. The kernel reference in the Docs lists every instruction. The example's Step button runs it in the Studio one instruction at a time.
Example
Output
Exercise 1
Read one byte and print it three times.
Run tries your program on the input below. Check runs it on every test.
| Input | Expected output |
|---|---|
a | aaa |
Z | ZZZ |
! | !!! |
Output
A hint
DUP copies the top of the stack.
One answer
Answer: Read one byte and print it three times.
Expected output
aaa
| Input | Expected output |
|---|---|
a | aaa |
Z | ZZZ |
! | !!! |
Output
Exercise 2
Read two bytes and print them swapped.
Run tries your program on the input below. Check runs it on every test.
| Input | Expected output |
|---|---|
ab | ba |
Hi | iH |
12 | 21 |
Output
A hint
The stack already reverses them; last in, first out.
One answer
Answer: Read two bytes and print them swapped.
Expected output
ba
| Input | Expected output |
|---|---|
ab | ba |
Hi | iH |
12 | 21 |
Output