Simple Stack Machine

Fri, 8 September, 2000
atze at uu dot nl
Machine Model

Introduction

Download
Machine model

Instructionset

User Interface
All topics from SSM
Example Code

 

 
 

Atze Dijkstra.

 

Memory and Registers

The SSM machine model contains memory and registers, see figure below. Memory contains code at its lower address range, starting at 0. The stack immediately follows thereafter.

Memory consists of an array of 32 bit words. Each word is addressed by an integer index value, its address. Memory starts at address 0.

Four registers are available, the Program Counter (PC), pointing to the current next instruction, the Stack Pointer (SP), pointing to the top of the stack, the Mark Pointer (MP), pointing to the current stackframe and a Return Register (RR) for holding return values.

Initially, when starting with the execution of code, the Program Counter equals 0. The Stack Pointer and Mark Pointer are set to a location after the loaded code. The Stack Pointer always points to the topmost element and grows from low to high addresses.

Instruction execution

The value of PC is used as the address to fetch the next instruction from. The loop executed by SSM thus looks like:

while ...
{
instr = M[PC] ;
PC += sizeof( instr + args ) ;
execute( instr ) ;
}