Home
  Contact
  Short Vita
  Research
  Teaching
  LSDIS Lab
  Links

UGAVAC Computer Description

Table of Contents

1. Short Description of the UGAVAC Computer

2. UGAVAC Assembly Language

2.1. Comments

2.2. Labels

2.3. Instructions

2.3.1. Basic Instruction Set

2.3.2. Floating Point Instructions

2.3.3. Input / Output Library

Examples

Micro-C Code patterns


1. Short Description of the UGAVAC Computer

The UGAVAC (UGA Virtual Automatic Computer) is composed of the following:

  1. 65536 (= 64K) words of word-addressable memory partition for data, called Stack,
  2. 65536 (= 64K) words of word-addressable memory partition for program, called Code,
  3. three special purpose registers:
    PC-Program Counter register
    SP-Stack Pointer register
    FP-Frame Pointer register
  4. ALU, capable of performing various stack operations
  5. I/O unit, capable of reading/printing.

The memory partition (Code) contains a program (the byte code of a program written in UGAVAC Assembly Language). The memory partition (Stack) is used for storing data and other necessary information.

2. UGAVAC Assembly Language

Each line of an UGAVAC Assembly Language program must contain either a comment, a label definition, or an instruction.

2.1. Comments

A comment begins with a number sign (#) in the first column and extends until the end of line. Comments are ignored. Also, any characters following a properly formatted instruction (to the end of the line) are treated as a comment.

2.2. Labels

A label is an identifier (letter|"$")(letter|digit)*. Only the first ten (10) characters are used to distinguish among labels. A label starting in the first column of a line is regarded as the definition of that label. There must be exactly one definition of every referenced label in an UGAVAC Assembly Language program. The label 'main' is reserved and indicates the main entry point. Note, that a label in the UGAVAC Assembly Language may begin with a $ (dollar) character. For example, $12 is a legal label.

There are two predefined labels (which are entry points to the standrad IO library routines): $scanf, $printf. These routines are defined in the pre-loaded UGAVAC library Iolib.u.The library is explained below.

2.3. Instructions

An instruction is composed of an instruction name (mnemonic), optionally followed by one or two operands. The mnemonic and operands (if they are present) are separated by space(s) and/or tab(s). An instruction must begin in a column higher than 1, otherwise the mnemonic is treated as a label definition. A short description of the available UGAVAC Assembly instructions is given below:

In what follows:

CI represents an integer constant ([+|-]digit+),
CR represents a floating point constant, ([+|-]digit+"."digit+),
CS represents a string constant (sequence of chars within single quotes "'"),
L represents a label; &L represents the label's address,
O represents a memory offset (used in addressing),
N is an integer constant.

Basic Instruction Set

OpcodeName ArgAction

0 pushcICI SP := SP + 1; Stack[SP] := CI;
1pushI OSP := SP + 1; Stack[SP] := Stack[FP+O];
2popIOStack[FP+O] := Stack[SP]; SP := SP - 1;
3 pushgI N, OSP := SP + 1; Stack[SP] := Stack[base(N)+O];
4popgIN, OStack[base(N)+O] := Stack[SP]; SP := SP - 1;
5 fetchI Stack[SP] := Stack[Stack[SP]];
6 popiIStack[Stack[SP-1]] := Stack[SP]; SP := SP - 2;
7pusha O SP := SP + 1; Stack[SP] := FP+O;
8 pushga N, O SP := SP + 1; Stack[SP] := base(N)+O;
33 pushs CS SP := SP + 1; Stack[SP] := &CS;
39 storeIStack[Stack[SP-1]] := Stack[SP]; Stack[SP-1] := Stack[SP]; SP := SP - 1;

9addI Stack[SP-1] := Stack[SP-1] + Stack[SP]; SP := SP - 1;
10subI Stack[SP-1] := Stack[SP-1] - Stack[SP]; SP := SP - 1;
11mulI Stack[SP-1] := Stack[SP-1] * Stack[SP]; SP := SP - 1;
12 divI Stack[SP-1] := Stack[SP-1] div Stack[SP]; SP := SP - 1;
13 negIStack[SP] := - Stack[SP]

16eqI Stack[SP-1] := ord(Stack[SP-1] = Stack[SP]); SP := SP - 1;
17neIStack[SP-1] := ord(Stack[SP-1] < > Stack[SP]); SP := SP - 1;
18 ltI Stack[SP-1] := ord(Stack[SP-1] < Stack[SP]); SP := SP - 1;
19 leI Stack[SP-1] := ord(Stack[SP-1] <= Stack[SP]); SP := SP - 1;
20gtI Stack[SP-1] := ord(Stack[SP-1] > Stack[SP]); SP := SP - 1;
21 geI Stack[SP-1] := ord(Stack[SP-1] >= Stack[SP]); SP := SP - 1;

22 jumpz L if Stack[SP] = 0 then PC := &L; SP := SP - 1;
23jumpnzL if Stack[SP] < > 0 then PC := &L; SP := SP - 1;
24jumpL PC := &L;

25enterNStack[SP+1] := base(N); Stack[SP+2] := FP; SP := SP + 3;
26allocN SP := SP + N;

36setrvIStack[FP] := Stack[SP]; SP := SP - 1;
27returnSP := FP - 1; PC := Stack[FP+2]; FP := Stack[FP+1];
35returnfSP := FP; PC := Stack[FP+2]; FP := Stack[FP+1];
28callL, NFP := SP - (N+2); Stack[FP+2] := PC; PC := &L;

14 intStack[SP] := trunc(Stack[SP]);
15intbStack[SP-1] := trunc(Stack[SP-1]);
142flt Stack[SP] := float(Stack[SP]);
143fltbStack[SP-1] := float(Stack[SP-1])

The function base(N) returns the address of the activation record N static levels down.

2.3.2. Floating Point Instructions

Floating point instructions are obtained by replacing the last letter 'I' with 'R'. For example, 'pushR' corresponds to 'pushI'. Opcodes of the floating point instructions are always greater by 128 than the opcodes of the corresponding integer instructions. For example, the opcode of 'pushR' is 129 (pushI opcode, 1, plus 128). The only additional instructions are 'int' (convert to integer representation), 'intb' (convert to integer below SP), 'flt' (convert to floating point representation), and 'ftlb' (convert to float below SP).

2.3.3. Input/Output Library

The input/output library, called iolib.u, is loaded before the execution of any UGAVAC program begins. The library supports basic I/O operations, such as reading and writing of fixed point numbers, floating point numbers, and strings, depending on the format conversion. The I/O library provides two I/O routines: $scanf and $printf. Both functions require two parameters. The first parameter is a format string containing at most one conversion request. $scanf's format must be either "%d" or "%f", while $printf's format may contain other printable characters, including \\, \n, and %%, as defined in the Micro-C language handout. $scanf requires an additional argument, which must be the address of a stack location, while $printf requires a numeric value. Note that if the format string in printf contains no conversion request, the second parameter is simply ignored (you should push a zero constant to supply a "place holder" argument). Calling sequences are described below:

$scanf -- formatted input

enter 1
<push the format string>
<push the address of a numeric variable>
call $scanf, 2

$printf -- formatted output

enter 1
<push the format string>
<push the value of a numeric expression>
call $printf, 2

Examples of UGAVAC programs are also available.

UGAVAC intermediate code generation should be handled according to the Micro-C code patterns.

For instructions on how to invoke the UGAVAC interpreter view its manual page.