You are on page 1of 10

presents

Pass ONE

FSP for Programming 1


Pass ONE

By : Shiref Saleh (37) && Mahmoud fayyaz (73)

TA’s Notes :

FSP for Programming 2


• Intro 1
• Index 2
• Problem Statement 3
• Overall System 4
• Basic Idea 4
• Input format 4
• Output format 4
• System under the microscope 5
• Main Data structures 5
• Main Algorithms 6
• Secondary Algorithms 7
• Sample runs 8

FSP for Programming 3


The term project is to implement a (cross) assembler for (a subset of) SIC/XE
assembler, written in C/C++, producing code for the absolute loader used in the
SIC programming assignments.
In phase 1 of the project, it is required to implement Pass1 of the assembler. The
output of this phase should be used as input for subsequent phases. You can
work in groups of 3-4 members.
Specifications
a) The pass1 is to execute by entering Pass1 <source-file-name>
b) The source file for the main program for this phase is to be named pass1.c
c) You should build a parser that is capable of handling source lines that are
instructions, storage declaratives, comments, and assembler directives (a
directive that is not implemented should be ignored possibly with a warning)
1. For instructions, the parser is to minimally be capable of decoding 2, 3 and 4-
byte instructions as follows:
a. 2-byte with 1 or 2 symbolic register reference (e.g., TIXR A, ADDR S,A)
b. RSUB (ignoring any operand or perhaps issuing a warning)
c. 3-byte PC-relative with symbolic operand to include immediate, indirect, and
indexed addressing
d. 3-byte absolute with non-symbolic operand to include immediate, indirect,
and indexed addressing
e. 4-byte absolute with symbolic or non-symbolic operand to include
immediate, indirect, and indexed addressing
2. The parser is to handle all storage directives (BYTE, WORD, RESW, and RESB).
d) The output of this phase should contain (at least):
1. The symbol table.
2. The source program in a format similar to the listing file described in your text
book except that the object code is not generated as shown below. A meaningful
error message is printed below the line in which the error occurred.

FSP for Programming 4


• Basic Idea
It is all about help the user to write a error free code
from the start, and to do so .We depended on two main ideas
1) The input will be line by line
2) Assembler on the fly
So now the idea is to get a line of code from the user directly ,
Assemble it if it is correct or notify the user immediately that
is error and ask for a line again .
• Input format
Is Free format line of code not more that 100
character length .
• Output format
Is symbol table , constant table and the code which
will given to pass two to get the object code
after each line the program notify the user with
some data about the state of the assembler after that line and
some information about the line inserted.

FSP for Programming 5


• Main Data Structures
• Sets
• Registers
• Two Registers
• Commands format 1
• Commands format 2 one registered
• Commands format 2 two registered
• Commands format 3 or 4
• Directives
• Maps
• Symbol table
• Constant table
• Enums
• States
EMPTY = 0 ,LABELED = 1 ,
COMMAND= 2,DIRECTIVE= 4,
FORMATE_ONE= 8,FORMATE_TWO= 16,
FORMATE_THREE= 131072,FORMATE_FOUR= 32,
TWO_REGESTERED= 64,ONE_REGESTERED= 128,
EXPERATION_ABSOLUTE = 256 ,
EXPERATION_RELATIVE = 512 ,
EXPERATION_CONSTANT_CHAR = 1024 ,
EXPERATION_CONSTANT_HEXA = 2048,
EXPERATION_INDIRECT = 4096,
EXPERATION_IMDIATE = 8192,
EXPERATION_INDEXED = 16384,
EXPERATION_TWO_PARA = 32768,ERROR = 65536,
FSP for Programming 6
• Main Algorithms

FSP for Programming 7


• Secondary Algorithms
• IsCharConst => to check weather it can be constant
• IsHexaConst => to check weather it can be constant
• IsAbs => to check weather the string is valid integer
• Getvalue => get the value of the absolute
• Ishexa => to check weather it can be hexa absolute
• Islabel => to check weather it can be alabel
• Experation => to validate the experation
• Solve => to solve the experation

FSP for Programming 8


enter your commands enter your commands
myprog start 0 alpha resw 1
pc 0 pc 15
Labeled myprog Labeled alpha
================================== ==================================
enter your commands enter your commands
first lda beta beta word 100
pc 0 pc 18
Labeled first Labeled beta
Command lda ==================================
format three with data beta enter your commands
flags : Relative data , gamma word 2
================================== pc 21
enter your commands Labeled gamma
mul gamma ==================================
pc 3 enter your commands
Command mul end
format three with data gamma pc 21
flags : Relative data , ==================================
================================= Sym Table
enter your commands alpha 12
sta alpha beta 15
pc 6 first 0
Command sta gamma 18
format three with data alpha myprog 0
flags : Relative data , Const Table
==================================
enter your commands
j*
pc 9
Command j
format three with data *
flags : Relative data ,
==================================

FSP for Programming 9


enter your commands enter your commands
myprog start 0 first lda
pc 0 =c'qqqqqqqqqqqqqqqqqqqqqqqqqqqqq'
Labeled myprog pc 0
================================== error
enter your commands ==================================
myprog lda alpha enter your commands
pc 0 first lda =x'123'
error pc 0
================================== error
enter your commands ==================================
my!prog lda alpha enter your commands
pc 0 lda
error pc 0
================================== error
enter your commands ==================================
first lada alpha enter your commands
pc 0 addr a
error pc 0
================================== error
enter your commands ==================================
first lda #@alpha enter your commands
pc 0 end
error pc 0
================================== ==================================
enter your commands ========================
first lda A!lpha Sym Table
pc 0 myprog 0
error Const Table
==================================

FSP for Programming 10