DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
CST 305 – System Software
Prof. Sarju S
16 July 2025
Module 1
► SIC/XE Programming, Basic Functions of Assembler, Assembler Output
Format – Header, Text and End Records. Assembler Data Structures, Two
Pass Assembler Algorithm, Hand Assembly of SIC/XE Programs.
Page 2 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Programming Examples –SIC/XE
Page 3
Program 1: Data Movement
Page 4 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Program 2: Arithmetic Operation
Page 5 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Program 3: Looping and Indexing
Page 6 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler
Page 7
Overview
Page 8 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Basic Assembler functions
► Translating mnemonic operation codes to their machine language
equivalents
► Assigning machine addresses to symbolic labels used by the
programmers
Page 9 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Directive
► Assembler directives are pseudo instructions
► They provide instructions to the assembler itself
► They are not translated into machine operation codes
► START, END, BYTE, WORD, RESW, RESB are some of the assembler
directives
Page 10 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Directive
► There are four different ways of defining storage for data items in the
SIC Assembler language.
► BYTE : Generate character or hexadecimal constant, occupying as many
bytes as needed to represent the constant
► Eg: CHARZ BYTE C’Z’
► WORD : Generate one-word integer constant
► Eg: FIVE WORD 5
Page 11 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
SIC Assembler Language Program - Example
Page 12 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
SIC Assembler Language Program - Example
► Figure shows an assembler language program for the basic version of
SIC
► Line numbers are given only for reference and are not the part of the
program
► Then there are labels defined by the programmer
► Then mnemonic instructions (opcode) eg: STL, JSUB, ….
Page 13 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
SIC Assembler Language Program - Example
► Indexing addressing is indicated by adding modifier “X” (line 160)
► Then comments are represented by “.”
► The program contains a main routine that reads records from an input
device, identified by device code F 1 and copies them to an output
device 05
► Main routine calls subroutine RDREC to read a record into buffer and
another subroutine WRREC to write the record from the buffer to the
output device
Page 14 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
1. Convert mnemonic operation codes to their machine language
equivalents (eg: STL to 14)
2. Convert symbolic operands to their equivalent machine addresses (eg:
RETADR to 1033)
3. Build the machine instructions in the proper format
4. Convert the data constants specified in the source program into their
internal machine representations (eg: EOF to 454F46)
5. Write the object program and the assembly listing
Page 15 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
1. Convert mnemonic operation codes to their machine language
equivalents (eg: STL to 14)
2. Convert symbolic operands to their equivalent machine addresses (eg:
RETADR to 1033)
3. Build the machine instructions in the proper format
4. Convert the data constants specified in the source program into their
internal machine representations (eg: EOF to 454F46)
5. Write the object program and the assembly listing
Page 16 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
► All these functions except number 2 can be easily be accomplished by
sequential processing of the source programme
► Convert symbolic operands to their equivalent machine addresses (eg:
RETADR to 1033)
► This cannot be achieved in the sequential processing of the source program, one
line at a time
► This poses a problem : Forward Reference
Page 17 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Forward Reference
Page 18 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
► Forward Reference – a reference to label (RETADR) that is defined later in
the program
► If we attempt to translate the program line by line, we will unable to
process this statement because we do not know the address that will be
assigned to RETADR
► Because of this, most assemblers make two passes over the source
program
Page 19 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
Assemblers make two passes over the source program
► PASS 1: Scan the source program for label definitions and assign
addresses (such as the Loc column)
► PASS 2: Performs the actual translation
Page 20 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
Page 21 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
24 bit instruction
1000 Opcode --14
1001 Operand 10
1002 Operand 33
1003
Page 22 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
► In addition to translating instructions to the source programme, the
assembler must process statements called assembler directives.
► These statements are not translated to machine code, instead they
provide instructions to the assembler itself.
► Example : BYTE, WORD which direct assembler to generate constants as part of the
object program
► START specifies the starting memory address of the object program, and END, which
Page 23 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
► Finally, the assembler must write the generated object code onto some
output device.
► The object program will later be loaded into memory for execution.
► The simple object program format uses 3 types of records: Header, Text
and End.
Page 24 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
► Header record contains the program name, starting address and
length.
► Text records contain the translated (ie., machine code) instructions and
data of the program, together with an indication of the addresses
where these are to be loaded.
► End record marks the end of the object program and specifies the
address in the program where execution is to begin.
Page 25 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
► Header
Col. 1 H
Col. 2~7 Program name
Col. 8~13 Starting address (hex)
Col. 14-19 Length of object program in bytes (hex)
► Text
Col.1 T
Col.2~7 Starting address in this record (hex)
Col. 8~9 Length of object code in this record in bytes (hex)
Col. 10~69 Object code (69-10+1)/6=10 records
► End
Col.1 E
Col.2~7 Address of first executable instruction (hex)
Page 26 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
Page 27 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Functions
► “^” used to separate fields visually and is not present in the actual object
program
► Note there is no object code corresponding to the addresses 1033- 2038
this storage is simply reserved by the loader for use by the program during
execution.
Page 28 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Passes of Assembler
► A Pass is defined as the processing activity of every single statement in the
source code to perform a set of language processing functions.
► Pass can also be defined as the activity of scanning the assembly language
programming.
Page 29 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Passes of Assembler
► Single pass Assembler: The assembler scans the entire source program
(assembly language program) once and convert into an object code.
► Multi-pass Assembler: The translation of assembly language program into
object code requiring many passes.
► The breaking of the entire assembly process into passes makes design
simpler and enables better control over the subtasks and intermediate
operations.
Page 30 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Functions of Two Passes of Assembler
► PASS 1 (Define symbols)
► Assign addresses to all statements in the program
► Save the values (addresses) assigned to all labels for use in Pass 2
► Perform some processing of assembler directives.
► (This includes processing that affects address assignment, such as
determining the length of data areas defined by BYTE, RESW, etc.)
Page 31 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Functions of Two Passes of Assembler
► PASS 2 (Assemble instructions and generate object program)
► Assemble instructions (translating operation codes and looking up
addresses)
► Generate data values defined by BYTE, WORD, etc.
► Perform processing of assembler directives not done during Pass 1
► Write the object program and assembly listing
Page 32 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Assembler Data Structures (internal tables required by the assembler)
► Simple Assembler uses two major internal data structures:
► Operation Code Table (OPTAB)
► Symbol Table (SYMTAB)
► Also need a variable Location Counter (LOCCTR)
Page 33 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
OPTAB
► OPTAB is used to look up mnemonic
operation codes and translate them to
machine language equivalents
► This must contain at least mnemonic
operation code and its machine language
equivalent
► In more complex assemblers, this table
also contains information about
instruction format and length.
Page 34 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
OPTAB
► During Pass 1 OPTAB is used to look up and
validate operation codes in the source
program
► In Pass 2, it is used to translate the operation
codes to machine language
Page 35 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
OPTAB
► In case of SIC/XE machine that has instruction of different length.
► We must search OPTAB in the first pass to find the instruction length for
incrementing LOCCTR.
► In second pass, the information from OPTAB tell us which instruction format
to use in assembling the instruction, and any peculiarities of the object code
instructions
Page 36 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
OPTAB
► OPTAB is usually organised as a hash table, with mnemonic operation code
as the key
► This information in OPTAB is predefined when the assembler itself is written,
rather than being loaded into the table at the execution time.
► This hash table organisation provides fast retrieval with a minimum of
searching
Page 37 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
OPTAB
► OPTAB is usually organised as a hash table, with mnemonic operation code
as the key
► This information in OPTAB is predefined when the assembler itself is written,
rather than being loaded into the table at the execution time.
► This hash table organisation provides fast retrieval with a minimum of
searching
► OPTAB is static table – entries are not normally added to or deleted from it.
Page 38 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
LOCCTR
► After each source statement is processed, the length of the assembled
instruction or data area to be generated is added to LOCCTR
► Thus whenever we reach a label in the source program, the current value of
LOCCTR gives the address to be associated with that label
Page 39 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
SYMTAB
► SYMTAB is used to store values(address) assigned to labels
► SYMTAB includes the name and value(address) for each label in the source
program, together with flags to indicate error conditions(eg: a symbol
defined in two different places)
Page 40 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
SYMTAB
Page 41 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
SYMTAB
► During Pass 1 , the labels are entered into SYMTAB as they are encountered
in the source program, along with their assigned addresses (from LOCCTR).
► During Pass 2, symbols used as operands are looked up in SYMTAB to
obtain the addresses to be inserted in the assembled instructions
► SYMTAB is usually organised as hash table for efficiency in insertion and
retrieval.
► Entries are rarely deleted from this table
Page 42 Prof. Sarju S, Department of Computer Science and Engineering, SJCET Palai
Thank You
Prof. Sarju S
Department of Computer Science and Engineering
St. Joseph’s College of Engineering and Technology, Palai
[email protected]
Page 43 Disclaimer - This document contains images/texts from various internet sources. Copyright belongs to the respective content creators.
Document is compiled exclusively for study purpose and shall not be used for commercial purpose.