Architecture: Stacks

The stacks are contiguous blocks of byte-addressable read-write memory which hold temporary program state.

Bedrock uses two stacks, the working stack and the return stack.

Memory

A stack is 256 bytes in length. The initial value of each byte of stack memory is implementation defined.

Each byte of stack memory is uniquely identified by an 8-bit memory address.

Systems with fewer than 256 bytes of memory per stack are partially supported, but these systems will be unable to correctly evaluate any program which makes use of the full stack length. The stack memory length will not change during runtime.

Stack pointer

A stack pointer is an 8-bit register which contains the memory address of the next free byte of stack memory, equal to the number of bytes currently stored on the stack. The initial value of each stack pointer is zero.

The behaviour when the stack pointer overflows or underflows is implementation defined.

Operations

Each stack supports two operations, push and pop.

Push

Pushing a byte to a stack will write the byte to the memory address referenced by the stack pointer, and then will increment the stack pointer by 1.

Pushing a double to a stack will push the high byte of the double to the stack, and then will push the low byte of the double to the stack.

Pop

Popping a byte from a stack will decrement the stack pointer by 1, and then will return the value stored at the memory address referenced by the stack pointer.

Popping a double from a stack will pop the low byte of the double from the stack, and then will pop the high byte of the double from the stack.