PassOne Module Client Specifications
Purpose
The Pass1 module is a function, called by the main program module, to perform pass 1 of a
two-pass assembler. During Pass 1, the assembler constructs a symbol table which contains
addresses for labels that appears in the source code. The addresses for labels are determined by
using a location counter, which is incremented whenever memory is needed for data or
instructions.
Client Data Model
SymTab is the data type of the symbol table linked list. Each node, SymNode, in this list contains
three fields of information:
Field |
Comments |
name |
name of symbol, a string of
characters |
address |
integer address value of
symbol |
next |
reference to next SymNode |
SymTab is created in CreateSymTab(), each SymNode is added to SymTab by calling
InsertNode(). Before inserting symbols to SymTab, SearchSymTab() is called to check for
symbol duplication.
Error handling policy
All symbols are compared with the list of directives, labels, and opcodes to assure no duplicates,
and non-use of reserved words. If any error occurs during pass 1, at the end of pass 1 the
program prints out all error messages and resets SymTab pointer to NULL.
Importing Information
Use of the functions listed in the Client Data Model, requires the following :
#include "header.h" - contains definition of symbol table, token
structure etc.
#include <stdio.h> - contains c standard functions
#include <stdlib.h> - contains c standard functions
#include <string.h> - contains c string functions
Public Data Types
- SymTab - SymTab is a linked list of nodes which include label name, address of label, and
address of next node.
Public Functions
Pass One
- SymTab pass1(tokenStruct *tokenStruct, FILE *file_ptr)
pass1(tokenStruct, file_ptr) is called by main program, and returns the symbol table to main
program which calls pass 2.
SymbolTable Creation
- SymTab createSymTab(st)
createSymTab() creates a new SymTab pointer, which points to NULL.
Data Retrieval and Modification
- int insertNode(SymTab st, TokenStruct *TokenStruct_ptr, int LC)
insertNode() inserts label field of the structure and address (from LC) into st.
- int searchSymTab(SymbolTable st, TokenStruct *TokenStruct_ptr)
searchSymTab(st, TokenStruct_ptr) checks whether the label is in st. It returns true if found,
false if not found.
Page URL: http://geocities.datacellar.net/sunsetstrip/frontrow/3153/Programs/pass1client.html
Page Author: Team 4