Whitespace Examples
- Hello, World!
-
Here is the ubiquitous Hello World program. Note how the characters are
converted to a binary encoding. The subroutine for writing out a string
is also interesting.
- Hello, user!
-
Slightly extended from the previous program, this program asks the user
their name before saying hello to them. The subroutine for reading in a string
is particularly interesting. Note how the input is duplicated twice, since we
need to use it multiple times.
- Calculator
-
To demonstrate a bit of arithmetic. Fairly straightforward, but again notice
that the majority of the work is in stack manipulation to keep track of the
local variables.
- Factorial
-
This program demonstrates how we can handle arbitrarily big numbers and
recursion. Note the definition of the factorial function quite happily calls
itself since the only storage it uses is on the stack.
- Towers of Hanoi
-
This program works out a solution for the towers of hanoi problem, recursively,
and shows the use of stack frames for local variables in recursive functions.
- Fibonacci
-
Written by Chris Morris, this is the other canonical way of showing how
recursion works.
- [Fact|Tut]orial
-
A version of the tutorial which, when executed,
does the same as the factorial program above.
eb@dcs.st-and.ac.uk
Released April 1st, 2003
Last Updated May 4th, 2004
Hosted by Durham University Computing
Society
|