MODULE 1
1. Differentiate between Application Software and System Software
2. What are Basic Functions of Assembler? What is ASSEMBLER DIRECTIVES?
• Pseudo
instructions. Provide instruction to assembler itself
• They are not translated in to machine operation code.
• SIC and SIC/XE has following assemble directives:
START- Specify name and starting address of the program
END- Indicate end of the source program and specify first executable statement in
program BYTE- Generate character or hexadecimal constant.
WORD- Generate one word integer constant.
RESB- Reserves the indicated number of bytes for data area.
RESW- Reserve the indicated number of words for data area
3. Describe the use of n,i,x,b,p and e bits in the SIC/XE instruction format. Write the
binary combination for these bits such that the resultant target address would be as
below and also state what would be the addressing modes for each.
i. (PC) + disp ii. (B) + disp iii. (PC) + disp + (X) iv. (B) + disp + (X)
Formats 3 & 4 introduce addressing mode flag bits:
n=0 & i=1
Immediate addressing - TA is used as an operand value (no memory reference)
n=1 & i=0
Indirect addressing - word at TA (in memory) is fetched & used as an address to fetch
the operand from
n=0 & i=0
Simple addressing TA is the location of the operand
n=1 & i=1
Simple addressing same as n=0 & i=0
Flag x:
x=1 Indexed addressing add contents of X register to TA calculation
Flag b & p (Format 3 only):
b=0 & p=0
Direct addressing displacement/address field containsTA (Format 4 always uses direct
addressing)
b=0 & p=1
PC relative addressing - TA=(PC)+disp (-2048<=disp<=2047)*
b=1 & p=0
Base relative addressing - TA=(B)+disp (0<=disp<=4095)**
* note - in PC relative, disp is interpreted as a 12 bit signed integer in 2's
complement ** note - in Base relative, disp is interpreted as a 12 bit unsigned integer
Flag e:
e=0 use Format 3
e=1 use Format 4
[Link] short note on SIC Machine Architecture:
• Memory:
• It consists of bytes(8 bits) ,words (24 bits which are consecutive 3 bytes)addressed by the
location of their lowest numbered byte. All SIC addresses are byte addresses. There are totally
32,768 (2^15 )bytes in memory.
• Registers:
There are 5 registers all of which have special uses. Each register is 24 bits in
length • Data formats:
• Integers are stored as 24-bit binary numbers
• 2’s complement representation is used for negative values
• Characters are stored using their 8 bit ASCII codes.
• They do not support floating – point data items.
• Instruction formats
All machine instructions are of 24-bits wide. The flag bit x is used to indicate indexed addressing
mode.
• Addressing modes:
Two types of addressing are available namely,
1. Direct addressing mode
2. Indexed addressing mode
• Parantheses are used to indicate the contents of a register or a memory
location. • For example (x) represents the contents of the index register X.
• Instruction set
It includes instructions like:
1. Data movement instruction
Ex: LDA, LDX, STA, STX.
2. Arithmetic operating instructions
Ex: ADD, SUB, MUL, DIV.
All arithmetic operations involve register A and a word in memory, with the result being
left in the register.
3. Comparison instruction
Ex: COMP – the value in the register A is compared with a word in memory.
This instruction sets a condition code (CC) flag to indicate the result ( <, >, =)
[Link] jump instructions
Ex: JLT, JEQ, JGT.
5. Subroutine linkage instructions
Ex: JSUB, RSUB.
JSUB – Jumps to the subroutine, placing the return address in register
L. RSUB – Returns by jumping to the address contained in register L
• Input and Output:
• I/O is performed by transferring one byte at a time to or from the rightmost 8 bitsof
register A.
• Each device is assigned a unique 8-bit code.
• There are 3 I/O instructions each of which specifies the device code as an operand. 1) The
Test Device (TD) - instructions tests whether the addressed device is ready to send or
receive a byte of data.
Condition code is set to indicate the result of this test.
Setting of ‘<’ indicates the device is set to send or receive.
Setting of ‘= ‘ indicates the device is not ready
2) RD – Read Data
3) WD – Write Data
A program must wait until the device is ready, and then execute a ReadData (RD) or Write
Data (WD. The sequence must be repeated for each byte of data to be read or written.
5. With a simple example describe what is meant by forward reference and how is it
handled in one pass assembler
A. The scenario in which a label is referenced in an instruction before it is defined is known
as forward reference.
In one pass assembler it is handled by including a link field in the SYMTAB, which stores the
links to the instructions which uses the label so that once the label address is obtained the
corresponding instructions object code can be modified.
MODULE 2
1. Outline in detail the function and algorithm for the pass two of the two
pass assembler.
Functions
Algorithm
2. Outline in detail the function and algorithm for pass one of a two pass assembler.
Functions
Algorithm
3. Outline in detail the the Data structures used in Assembler and what is happening to
these data structures in the pass one and pass 2 of Two pass assembler.
4. What is program relocation? Explain with Example.
5. Illustrate the use and structure of three records used in object program?
MODULE 3
1. Define Control Section. With an example illustrate how a control section is declared
within an assembly program and what are the constituents of the object code program
of a control section.
Ans. Definition of control section – A control section is a part of the program that maintains
its identity after assembly; each control section can be loaded and relocated independently of
the others. The programmer can assemble, load, and manipulate each of these control sections
separately.
*
*
*
Control sections are defined using assembler directive such as CSECT.
The syntax
secname CSECT
EXTDEF (external Definition): It is the statement in a control section, names symbols that
are defined in this section but may be used by other control sections. Control section names
do not need to be named in the EXTREF as they are automatically considered as external
symbols.
EXTREF (external Reference): It names symbols that are used in this section but are defined
in some other control section. The order in which these symbols are listed is not significant.
The assembler must include proper information about the external references in the object
program that will cause the loader to insert the proper value where they are required. Object
code program for each control sections have the records such as header, Define, Refer, text,
Modification and End.
Define record (EXTDEF)
Col. 1 D
Col. 2-7 Name of external symbol defined in this control section
Col. 8-13 Relative address within this control section (hexadecimal)
Col.14-73 Repeat information in Col. 2-13 for other external
symbols Refer record (EXTREF)
Col. 1 R
Col. 2-7 Name of external symbol referred to in this control section
Col. 8-73 Name of other external reference symbols
Modification record
Col. 1 M
Col. 2-7 Starting address of the field to be modified (hexadecimal)
Col. 8-9 Length of the field to be modified, in half-bytes (hexadecimal) Col.11-16
External symbol whose value is to be added to or subtracted from the indicated field
[Link] how the concepts of segments are handled in MASM assembler for 8086.
Also compare near and far jump concept and its handling in MASM. Segments are
handled using the assembler directives such as CODE, STACK, CONST, DATA and USE.
CODE: CS is set to the segment containing the starting label specified in the END statement.
STACK: SS is set to the last stack segment processed by the loader.
DATA: DS, ES,FS,GS
Can be specified by programmers in their programs. Otherwise, one of them is selected by
assembler.
DS is the data segment register by default, Can be changed and set by: ASSUME
ES:DATASEG2
Any reference to the labels defined in DATASEG2 will be assembled based on ES
An instruction jump within the current code segment is known as near jump while if the
destination address of the jump is outside the current code segment it is known as far jump. It
is handled in MASM by explicitly specifying that a jump is near or far by using assembler
directives FAR and SHORT along with the JNP instruction.
3. Define Program Blocks. With an example and diagram demonstrate how the different
program blocks within an assembly program are organised within the memory. Also
mention how the object code program for a program block is organised. Segments of
code that are rearranged within a single object program unit. Assembler directive: USE
USE [block name]
At the beginning, statements are assumed to be part of the unnamed (default) block If no USE
statements are included, the entire program belongs to this single block The USE statement
may also indicate a continuation of a previously begun block. Each program block may
actually contain several separate segments of the source program The assembler
will(logically) rearrange these statements to gather together the pieces of each block.
These blocks will then be assigned addresses in the object program with the blocks appearing
in the same order in which they first begun in the source program.
At the beginning, statements are assumed to be part of the unnamed (default) block. If no
USE
statements are included, the entire program belongs to this single block. Each program block
may actually contain several separate segments of the source program. Assemblers rearrange
these segments to gather together the pieces of each block and assign address. Separate the
program into blocks in a particular [Link] buffer area is moved to the end of the object
program. Program readability is betterif data areas are placed in the source program close to
the statements that reference them. In the example below three blocks are used : Default:
executable instructions
CDATA: all data areas that are less in length
CBLKS: all data areas that consists of larger blocks of memory
How the assembler handles program blocks –
Pass 1
– A separate location counter for each block is maintained.
– The location counter for a block is initialized to zero when the block is first started.
– The current value of the location counter is saved when switching to another block.
– The saved value is continued when resuming previous block.
– After pass 1 the symbol table will be having labels with block no along with address.(For
absolute symbol there is no block number.)
– At the end of pass 1 latest value of location counter or each block gives the length of that
block.
– Assembler constructs a block table that contains starting addresses and lengths of all blocks
Pass 2
– Code generation during pass2 the assembler needs the address relative to the start of the
program. (not the start of the individual program block). Assembler adds the label address
with
its block starting address.
4. Explain any two Assembler Design Option.
One-Pass Assembler
The main problem in designing the assembler using single pass was to resolve forward
references. We can avoid to some extent the forward references by:
• Eliminating forward reference to data items, by defining all the storage reservation
statements at the beginning of the program rather at the end.
• Unfortunately, forward reference to labels on the instructions cannot be avoided.
(forward jumping)
• To provide some provision for handling forward references by prohibiting forward
references to data items.
There are two types of one-pass assemblers:
• One that produces object code directly in memory for immediate execution (Load-
and-go assemblers).
• The other type produces the usual kind of object code for later
execution. Load-and-Go Assembler
• Load-and-go assembler generates their object code in memory for immediate
execution.
• No object program is written out, no loader is needed.
• It is useful in a system with frequent program development and testing o The efficiency of
the assembly process is an important consideration. • Programs are re-assembled nearly every
time they are run; efficiency of the assembly process
is an important consideration.
MultiPass Assembler
• For a two pass assembler, in EQU assembler directive we required that any symbol on
the right hand side be defined previously in the program. This is because o the two [Link]
multipass is possible this restriction can be avoided. Eg:
ALPHA EQU BETA
BETA EQU DELTA
DELTA RESW 1
Working of Multipass Assembler:
• A multipass assembler can make as many passes as needed to process the definition of
symbols.
• For a forward reference in symbol definition, we store in the SYMTAB:
o The symbol name
o The defining expression
o The number of undefined symbols in the defining expression
• The undefined symbol (marked with a flag *) associated with a list of symbols depend on
this undefined symbol.
• When a symbol is defined, we can recursively evaluate the symbol expressions
depending on the newly defined symbol.
5. Explain any two Machine-Independent function of Assembler.
These are the features which do not depend on the architecture of the machine. Such
features are more
related to software than to machine architecture. These are:
▪ Literals
▪ Symbol defining statements
▪ Expressions
▪ Program blocks
▪ Control sections
MODULE -4
1. Give the algorithm for the pass two of a two pass linker loader.
2. Define Absolute loader and outline the algorithm for it.
No linking and program relocation is needed
For a simple absolute loader, all functions are accomplished in a single pass as
follows:
The Header record of object programs is checked to verify that the correct program
has been presented for loading.
As each Text record is read, the object code it contains is moved to the indicated
address in [Link] the End record is encountered, the loader jumps to the
specified address to begin execution of the loaded program.
Algorithm for Absolute Loader
3. Write the algorithm for the pass one of a two pass linker loader.
4. List the different machine dependent and machine independent features of a
loader. Explain any two machine independent features.
Machine dependent features -Relocation , Program Linking
machine independent features- Automatic Library Search , Loader Options
Automatic Library Search
This feature allows a programmer to use standard subroutines without explicitly including
them in the program to be loaded. The routines are automatically retrieved from a library as
they are needed during linking. This allows programmer to use subroutines from one or more
libraries. The subroutines called by the program being loaded are automatically fetched from
the library, linked with the main program and loaded. The loader searches the library or
libraries specified for routines that contain the definitions of these symbols in the main
program
Loader Options
Loader options allow the user to specify options that modify the standard processing. The
options may be specified in three different ways. They are, specified using a command
language, specified as a part of job control language that is processed by the operating
system, and an be specified using loader control statements in the source program.
Here are the some examples of how option can be specified.
INCLUDE program-name (library-name) - read the designated object program from a library
DELETE csect-name – delete the named control section from the set of programs being
loaded
CHANGE name1, name2 - external symbol name1 to be changed to name2 wherever it
appears in the object programs
LIBRARY MYLIB – search MYLIB library before standard libraries
NOCALL STDDEV, PLOT, CORREL – no loading and linking of unneeded routines Here is
one more example giving, how commands can be specified as a part of object file, and the
respective changes are carried out by the loader.
LIBRARY UTLIB
INCLUDE READ (UTLIB)
INCLUDE WRITE (UTLIB)
DELETE RDREC, WRREC
CHANGE RDREC, READ
CHANGE WRREC, WRITE
NOCALL SQRT, PLOT
The commands are, use UTLIB ( say utility library), include READ and WRITE control
sections from the library, delete the control sections RDREC and WRREC from the load, the
change command causes all external references to the symbol RDREC to be changed to the
symbol READ, similarly references to WRREC is changed to WRITE, finally, no call to the
functions SQRT, PLOT, if they are used in the program.
4. Give the structure and purpose of Modification record and Define record. A.
Modification record is used to list the object code fields which need to be modified as part of
the loading and linking process.
Define record is used to list the labels of the control sections which would be referenced by
some external control section.
[Link] about different Loader Design Options
Different types of Loaders are
▪ Linkage editor- links the program stores it in a file and later loads.
▪ Linking loader- linking during load time
▪ Dynamic linking- linking during execurion time
▪ Bootstrap loader- loads the first program/OS
Dynamic linking
• In dynamic linking the linking function is done at execution time. That is a subroutine is
loaded and linked to the rest of the program when it is first called.
• Dynamic linking is often used to allow several executing programs to share one copy of a
subroutine or library. For eg: in C such fuctions are stored in dynamic linking library.. A
single copy of the routines in this library could be loaded into memory and all programs
share this.
• In object oriented program dynamic linking is often used for references to software
objects..
Bootstrap loader
• Consider how the loader itself is loaded into memory. OS loads the loader. How the OS
gets loaded.
• In an idle system if we specify the absolute address the program can be loaded at that
location. that is a mechanism of absolute loader is required.
• One solution to this is to have a built in hardware function that reads a fixed length
record from some device into memory at some fixed location. This device can be
selected via console switches. After the read operation is complete the control is
automatically transferred to the address in memory where the record was stored. This
record contains machine instructions that load the absolute program that follows.
• If the loading process requires more instructions than can be read in a single record this first
record causes the reading of others and in turn other records . Hence the name Bootstrap.
MODULE -5
[Link] the algorithm for a one pass macro processor.
[Link] a neat diagram outline the structure of a text editor.
1)The command language processor accepts input from the user’s input devices and analyses
the tokens and syntactic structure of the commands. That is, it function like lexical and
syntactic phases of a compiler. It invokes the semantic routines directly. The command
language processor also produces an intermediate representation of the desired editing
operations. This representation is decoded by an interpreter that invokes the appropriate
semantic routines.
2)Editing Component - In editing a document, the start of the area to be edited is determined
by the current editing pointer maintained by the editing component. Editing component is a
collection of modules dealing with editing tasks. Current editing pointer can be set or reset
due to next paragraph, next screen, cut paragraph, paste paragraph etc..,.
3) Travelling component – performs the setting of the current editing and viewing pointers
and thus determines the point at which the viewing/editing filtering begins.
4) Editing filter- When the user issues an editing command the editing component invokes
the editing filter. This component filters the document to generate a new editing buffer based
on the current editing pointer as well as on the editing filter parameters.
5) Filtering consists of selection of continuous characters beginning at the current point. 6)
Viewing component- thee start of the area to be viewed is determined by the viewing
[Link] pointer is maintained by the viewing component. When the display need to be
updated the viewing component invokes the viewing filter. This component filters the
document to generate a new viewing buffer.
7) Display component- The viewing buffer is then passed to the display component which
produces a display by mapping the buffer to a rectangular subset of the screen called window.
3. Distinguish between character and block device driver.
Block device drivers Character device drivers
communicate with the OS through a Can handle I/O requests of arbitrary size
collection of fixed sized buffers. and can be used to support almost any type
of device.
Character drivers are used for devices that
either deal with data a byte at a time (such
as line printers)
while user processes interact with block drivers only indirectly through the buffer cache,
their relationship with character drivers is very direct.
A Block ('b') Device is one with which the A Character ('c') Device is one with which
Driver communicates by sending entire the Driver communicates by sending and
blocks of data. receiving single characters (bytes, octets).
Examples for Block Devices: hard disks, Examples for Character Devices: serial
USB cameras, Disk-On-Key ports, parallel ports, sounds cards.
Character Device Vs. Block Device
A Character ('c') Device is one with which the Driver communicates by sending and receiving
single characters (bytes, octets).
A Block ('b') Device is one with which the Driver communicates by sending entire blocks of
data. Examples for Character Devices: serial ports, parallel ports, sounds cards.
Examples for Block Devices: hard disks, USB cameras, Disk-On-Key.
A device driver is a set of entry points(routines) that can be called by the OS.
A driver also contain : data structures private to the driver, references to kernel data structures
external to the driver and routines private to the driver.
Most device drivers are written as a single source file.
The initial part of the driver is called prologue.
4. Compare induction and backtracking mode of debugging.
Debugging by Induction Debugging by Back Tracking
In induction one proceeds from the particulars For small programs the method of
to the whole. ie, By starting with the backtracking is more effective to locate
symptoms of errors.
the error in the result of one or more test cases
and looking for relationships among the
symptoms.
To use this method start at the place in the
program where an incorrect result was
produced and go backwards in the program
one step at a time. That is executing the
program in reverse order to derive the values
of all variables in the previous step. Then the
error can be localized.
5. Explain any 3 Machine Dependent microprocessor feature.
Machine independent macro processor features are extended features that are not directly
related to architecture of computer for which the macro processor is written. 1.
Concatenation of Macro Parameters
Most Macro Processor allows parameters to be concatenated with other character strings.
A program contains a set of series of variables:
XA1, XA2, XA3,…
XB1, XB2, XB3,…
If similar processing is to be performed on each series of variables, the programmer might
want to incorporate this processing into a macro instruction.
The parameter to such a macro instruction could specify the series of variables to be
operated on (A, B, C …).
The macro processor constructs the symbols by concatenating X, (A, B, …), and
(1,2,3,…) in the macro expansion.
Suppose such parameter is named &ID, the macro body may contain a statement:
LDA X&ID1,
in which &ID is concatenated after the string “X” and before the string “1”.
LDA XA1 (&ID=A)
LDA XB1 (&ID=B)
Ambiguity problem:
E.g., X&ID1 may mean
“X” + &ID + “1”
“X” + &ID1
This problem occurs because the end of the parameter is not
marked. Solution to this ambiguity problem:
Use a special concatenation operator “ ” to specify the end of the parameter. Thus the
above statement can be written as:
LDA X&ID 1
So that the end of parameter &ID is clearly identified.
2 Generation of Unique Labels
Labels in the macro body may cause “duplicate labels” problem if the macro is invocated
and expanded multiple times.
Use of relative addressing at the source statement level is very inconvenient, error-prone,
and difficult to read.
It is highly desirable to
1. Let the programmer use label in the macro body
· Labels used within the macro body begin with $.
2. Let the macro processor generate unique labels for each macro invocation and
expansion.
During macro expansion, the $ will be replaced with $xx, where xx is a two-character
alphanumeric counter of the number of macro instructions expanded. XX=AA, AB,
AC …….
Unique labels are generated within macro expansion.
Each symbol beginning with $ has been modified by replacing $ with $AA. The
character $ will be replaced by $xx, where xx is a two-character alphanumeric
counter of the number of macro instructions expanded.
For the first macro expansion in a program, xx will have the value AA.
For succeeding macro expansions, xx will be set to AB, AC etc.
3. Keyword Macro Parameters - Positional parameters
Parameters and arguments are associated according to their positions in the macro
prototype and invocation.
The programmer must specify the arguments in proper order.
If an argument is to be omitted, a null argument should be used to maintain the proper
order in macro invocation statement.
For example: Suppose a macro instruction GENER has 10 possible parameters, but in a
particular invocation of the macro only the 3rd and 9th parameters are to be specified.
The statement is GENER ,,DIRECT,,,,,,3.
It is not suitable if a macro has a large number of parameters, and only a few of these are
given values in a typical invocation.
Keyword parameters
o Each argument value is written with a keyword that names the corresponding
parameter.
o Arguments may appear in any order.
o Null arguments no longer need to be used.
o If the 3rd parameter is named &TYPE and 9th parameter is named &CHANNEL, the
macro invocation would be
GENER TYPE=DIRECT,CHANNEL=3.
o It is easier to read and much less error-prone than the positional method.
Consider the example
Here each parameter name is followed by equal sign, which identifies a keyword
parameter and a default value is specified for some of the parameters.