Simple Stack Machine |
||||||||||||||||||||||||
|
Instructions
|
|||||||||||||||||||||||
|
SSM instructions are loaded in a textual form, called assembler notation. Internally instructions are encoded in code part of the memory by integer values. SyntaxThe syntax (in EBNF) of the assembler language is rather straightforward, in order not to complicate parsing: AssemblySource ::= Line *
Spaces between the lexical elements are allowed, except between the minus sign '-' and the following Number. Comment begins with ";" or "//" and ends at the end of the line EOL. A Label is defined when it occurs as part of a Line, before the colon. A Label may be used as an argument of an instruction. Depending on the semantics of the instruction a specific integer value is substituted at load time of the source code. InstructionsSSM instructions fall into the following groups:
Copying instructionsInstructions of which the textual representation starts with "ld" load values onto the stack, i.e. they are pushed on top of the stack. The counterparts of the load instructions are the store instructions, starting with "st", which take 1 or more values from the stack (popping them) and storing a popped value in a memory location.
Some of the above instructions also come in multiple load/store variations, indicated by an additional 'm' in the mnemonic. Convenience instructions (for the stack)Not really necessary but handy.
Arithmetic instructionsArithmetic instructions take (pop) 2 (1 for neg and not) values from the stack, perform some calculation on these values and push the result back on the stack.
Control instructionsControl instructions change the value of the PC, and consequently change the location where code is fetched from. All branch instructions use their argument value to add to the PC.
Other instructionsMeta instructions, not producing code.
Instruction DetailA full overview and detail can be found in the per topic overview, also part of the helpsystem of SSM itself. |