Skip to content
Dmitry-Ustyugov edited this page Jun 3, 2012 · 15 revisions

Table of Contents

Overview

StAr is a tagged stack architecture with RISC instruction set and variable instruction length. It is stack-only machine and has no random-access memory(but it has ability to address stack relative to current frame pointer). Instructions are fetched from a kind of pipeline and at this moment there is no support for control flow constructions.

Tagging

Tagging is an architecture feature that allows dynamic type checking, array bound checking, procedure mechanism support and other useful features. Despite the fact that tag represents high-level concept of data types this functionality is not exposed to programmer.

Initial tagging is being performed automatically with first access to stack entry by instruction. Once tagged value can be checked while performing operations.

Tag is 4bit field with 3 meaning parts:

3 2 1 0
F A D
  • F - this stack entry is marked as frame start
  • A - this stack entry is marked as array beginning and its value is array size
  • D - data type of stored value.
    • U(0) - undefined
    • I(1) - integer
    • D(2) - float
    • A(3) - address

Encoding

Instructions are byte-aligned and has different size depending on its complexity:

Type Size Byte Byte Byte
Simple instruction 1 Opcode  
Integer instruction 2 Opcode Operand
Float instruction 3 Opcode Operand
Address instruction 3 Opcode Operand

Floating point number format

Float in StAr is half-precision floating number. It is encoded in 16 bit according to following format:

  • 1bit - sign
  • 5bit - exponent
  • 10bit - fraction

Instruction set reference

All operations could be roughly divided into five groups:

LD/ST

Here instructions may be represented with I or D postfix, which denotes operand type integer and float correspondingly.

LDC - Load a constant.

Opcode Instruction Description
0x01 LDCI const Load integer const constant into top of stack.
0x02 LDCD const Load float const constant into top of stack.

LD - load value at constant address.

Opcode Instruction Description
0x05 LDI shift Load integer value at shift into top of stack.
0x06 LDD shift Load float value at shift into top of stack.

Load a value from relative address inside stack frame into the top of the stack.

LDS - load value at dynamic address.

Opcode Instruction Description
0x09 LDSI Load integer value at address in top of stack on top of stack.
0x0A LDSD Load float value at address in top of stack on top of stack.

Load a value from relative address inside stack frame specified by top stack value into the top of the stack. Previous value in top of stack is rewritten.

ST - store value at dynamic address

Opcode Instruction Description
0x0D STI Store integer value from second topmost stack entry by address in top of stack.
0x0E STD Store float value from second topmost stack entry by address in top of stack.

Store a second from top value by relative address inside stack frame specified by top stack value. Top of stack remain unchanged. Previous values in top of stack are rewritten.

Stack frame direct modification

ALLOC - allocate frame

Opcode Instruction Description
0x20 ALLOC size Allocate size bytes in top of stack

Allocate frame in the top of the stack with given size. All allocated stack entries have U tag.

SCR - drop the top value

Opcode Instruction Description
0x24 SCR drop the top of stack value.

MA - mark array head

Opcode Instruction Description
0x29 MAI Mark a memory unit to be an integers array head.
0x2A MAD Mark a memory unit to be a floating point numbers array head.

There must be an adress at the top of the stack, and an integer below. The instruction pulls address, then pulls the length, and then it marks the corresponding memory unit to be a head of a certain type array with given length.

Address calculation

LDA - load address

Opcode Instruction Description
0x43 LDA shift load shift relative address into top of stack.

Load an address into top of the stack. Address is a shift relative to current frame.

INDEX - produce array element address

Opcode Instruction Description
0x47 INDEX load relative address of array element into top of stack.

Produce an array element address by its base and index. Base address is obtained by LDA command and is located with index value on the top of the stack. Also this instruction performs array bounds checking. Previous values in top of stack are rewritten.

Ariphmetic

ADD

Opcode Instruction Description
0x81 ADDI summarize two topmost stack integer values and replace them with result.
0x82 ADDD summarize two topmost stack float values and replace them with result.

SUB

Opcode Instruction Description
0x85 SUBI subtract second topmost stack integer value from first and replace them with result.
0x86 SUBD subtract second topmost stack float value from first and replace them with result.

MUL

Opcode Instruction Description
0x89 MULI multiply two topmost stack integer values and replace them with result.
0x8A MULD multiply two topmost stack float values and replace them with result.

DIV

Opcode Instruction Description
0x8D DIVI divide first topmost stack integer value on second and place result into top of stack.
0x8E DIVD divide first topmost stack float value on second and place result into top of stack.

Perform integer division if both arguments are integer and replace them with result. Otherwise division result is float.

REM

Opcode Instruction Description
0x91 REM compute remainder of integer division of first topmost stack value on second and replace them with result.

CHS

Opcode Instruction Description
0x95 CHSI change sing of top integer value of stack.
0x96 CHSD change sing of top float value of stack.

FI2D

Opcode Instruction Description
0x98 FI2D change type of top value of stack from integer to float.

Change the type of the top element from integer to float.

FD2I

Opcode Instruction Description
0x9C FD2I change type of top value of stack from float to integer.

Change the type of the top element from integer to float.

Procedure invocation

MS

Opcode Instruction Description
0x60 MS mark top of stack as start of procedure arguments.

Prepare to enter to a procedure. Mark stack by pushing to it a special element, designating a separate area of arguments.

CALL

Opcode Instruction Description
0x64 CALL call predefined procedure.

Call a system hard-coded function, such as print, sin, cos etc.

call 0 sin(x)
call 1 cos(x)
call 2 print all params before MS