Two stacks implementing a queue in shared RAM #
Two disjoint reserved blocks hold bottom-first stack arrays. Enqueue pushes onto the rear; dequeue transfers the rear into an empty front before popping. All address arithmetic, memory accesses, loop tests and operation dispatch are machine instructions. Empty live prefixes do not require clearing the reserved memory.
Main definitions #
Rep: the bounded shared-memory representation of the two top-first lists.program: one fixed operation dispatcher.implementation: its argument and result conventions.initializeCode: six charged writes installing an empty representation.
Main results #
execute: exact instruction execution, observations, representation and memory frame.initialize_exec: initialization from arbitrary bounded machine data without clearing memory.
References #
Operation tag: enqueue zero, dequeue one.
Instances For
Front stack length.
Instances For
Front block base.
Instances For
Returned presence flag.
Instances For
Both stack arrays live in one bounded memory, with one common capacity bound.
- bounded : Data.Bounded w x
Instances For
The fixed reserved region, including currently unused cells.
Instances For
Enqueue writes the next rear cell and advances the rear length.
Instances For
Move the top rear word onto the front stack.
Instances For
Reverse the rear stack onto the front, testing each iteration on machine registers.
Instances For
Pop the front, distinguishing the empty queue from a returned zero.
Instances For
Transfer only when the front is empty.
Instances For
One fixed dispatcher, independent of queue contents, capacity, and operation arguments.
Instances For
Register calling convention for the fixed queue dispatcher.
Instances For
Enqueue body correctness with an exact four-instruction execution.
Exact instruction count of a dispatched operation, excluding the final halt.
Instances For
Every valid operation executes the fixed dispatcher with its exact instruction count, implements the two-stack transition, and preserves every cell outside the reserved region.
Install an empty queue using six register instructions, with no writes to reserved memory.
Instances For
Initialization accepts arbitrary bounded registers and memory. Only the six representation registers change; both reserved live prefixes are empty, so memory remains untouched.