Sunteți pe pagina 1din 87

Francis Xavier Engineering College, Department of Computer Science and Engineering

CS2304
SYSTEM SOFTWARE
QUESTION BANK

PREPARED BY
S.GOMATHI AP/CSE
S.N. ANANTHI AP/CSE

http://www.francisxavier.ac.in

Page 1

Francis Xavier Engineering College, Department of Computer Science and Engineering

UNIT 1 Introduction
System software and machine architecture The Simplified Instructional Computer
(SIC) - Machine architecture - Data and instruction formats - addressing modes instruction sets - I/O and programming.
PART A:
1. What is the purpose of test device instruction? (May06)
The test device instruction tests whether the addressed device is ready to send or
receive a byte of data. The condition code is set to indicate the result of this test.
2. How is a floating point value represented using exponent in SIC? (May06)
There is no floating-point hardware on the standard version of SIC.
3. What is the need of Assembler directive? (May06)
Assembler directives are not translated into machine instructions; instead they provide
instructions to the assembler itself.
Eg: BYTE and WORD, which directs the assembler to generate constants as part of the object
program. RESW and RESB, which instruct the assembler to reserve memory locations
without generating data values.
4. What is the use of location counter? (May06)
LOCCTR is a variable that is used to help in the assignment of addresses. LOCCTR is
initialized to the beginning address specified in the START stmt. After each source stmt 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 associated with that label.
5. What are the registers used in SIC? (Nov06)
Mnemonic

Number

Special use
Accumulator, used for arithmetic
Operations

X
L

1
2

Index register, used for addressing


Linkage register, JSUB Stores the
Return address in this register

PC

Program counter, address of the next


instruction to be fetched for execution

SW

Status word, contains a variety of


Information including a cc (condition code)

http://www.francisxavier.ac.in

Page 2

Francis Xavier Engineering College, Department of Computer Science and Engineering

6. What is base relative addressing? (May06)


o The target address is calculated as
TA=(B) + disp where (B)- contents of base register, disp- displacement
o Base relative also sets the flags b=1 and p=0
7. Define upward compatibility in systems. (May07)
An object program of lower version of machine will also execute properly on higher
version of machine. This property is called as upward compatibility.
8. Distinguish between direct addressing and indirect addressing. (May07)
Mode

Indication

Target address calculation

Direct

x=0

TA=address Eg: JSUB RDREC

Indexed

x=1

TA=address+(X) Eg: J @RETADR

9. What is the use of SVC instruction in SIC? (Nov05)


Executing supervisor call (SVC) generates an interrupt that can be used for
communication with the operating systems.
10. What are the additional registers provided in SIC/XE than SIC? (Nov05)

Mnemonic

Number

Special use

Base register

General working register

General working register

Floating-point accumulator (48 bits)

11. Define system software. Give Examples.


System software consists of variety of programs that support the operations of a
computer. The examples are as follows
Text editor

Debugger

Compiler

Operating systems

Linker

Assembler

Loader

Macro processor

http://www.francisxavier.ac.in

Page 3

Francis Xavier Engineering College, Department of Computer Science and Engineering

12. Compare assembler and compiler.


Assembler

Compiler

It converts assembly language program

It converts high-level language into

into machine language

machine language

13. Write about the memory in SIC architecture.


In SIC, memory consists of 8-bit bytes. 3 consecutive bytes form a word. All addresses
of SIC are byte addresses. There are totally 32,768 bytes in the computer memory.
14. Write about instruction formats and addressing modes on SIC.(NOV 08)
Instruction format:
All machine instructions on the standard version of SIC have 24-bit format as follows.
opcode

address

The flag bit x is used to indicate indexed addressing mode.


Addressing modes:
There are two addressing modes available by setting the X bit of the instruction. They
are,
Mode

Indication

Target address calculation

Direct

x=0

TA=address Eg: JSUB RDREC

Indexed

x=1

TA=address+(X) Eg: J @RETADR

15. What are the I/O instructions available in SIC/XE?


I/O instructions of SIC standard version are also available on SIC/XE. In addition
there are I/O channels that can be used to perform the i/o while the CPU is executing other
instructions.The instructions are:
o SIO: Start the operations on I/O channels
o TIO: Test the operations on I/O channels
o HIO: Halt the operations on I/O channels
16. Define immediate, indirect and simple addressing modes in SIC/XE.
SIC/XE provides different kinds of addressing modes by setting the flags bits n, i, x, b
and p. The different addressing modes, indication and their target address calculation is given
as,

http://www.francisxavier.ac.in

Page 4

Francis Xavier Engineering College, Department of Computer Science and Engineering

Modes

Indications

Target address

Immediate

i=1,n=0

TA= operand value

Indirect

i=0,n=1

TA= Value contained in the word

Simple

i=1.n=1 or I=0,n=0

TA= Location of the operand

17. Write a sequence of instructions for SIC/XE to set ALPHA equal to 4*BETA-9.
LDA

#4

MUL BETA
LDS

#9

SUBR A, S
STA

ALPHA

18. What is purpose of CC in SIC?


There is an instruction in SIC (COMP) that compares the value in register with a word
in memory. This instruction sets condition code CC to indicate the result (<, or >). The test
device instruction tests whether the addressed device is ready to send or receive a byte of data.
The condition code is set to indicate the result of this test.
19. Differentiate system software and application software.
System software

Application software

It supports the operation and use of the It concerns with solution of some problem
computer
It is related to the architecture of machine Its focus is on the application not on the
on which they run

computing system.

20. What is addressing mode?


Addressing mode is the method of specifying an operand.
21. Name two SIC instructions that are provided for subroutine linkage.
Subroutine linkage instruction:
JSUB: jumps to subroutine, placing the return address in register L
RSUB: returns by jumping to the address contained in register L.
22. Define system software and system program.(NOV 07)
System Software: It supports the operation and use of the computer. It is related to
the architecture of machine on which they run
Application Software: It concerns with solution of some problem. Its focus is on
the application not on the computing system.
System program: system program are intended to support the operation and use
of the computer itself rather than any particular application
http://www.francisxavier.ac.in

Page 5

Francis Xavier Engineering College, Department of Computer Science and Engineering

23. What is the purpose of TIX and TIXR?


TIX: (used in SIC)

It performs two functions.


o First it adds 1 to the value in register X and then it compares the new
value of X to the value of the operand
o The condition code is set to indicate the result of this comparison

TIXR: (used in SIC / XE)

TIXR is used in place of TIX in SIC/XE.

It works exactly like TIX, except that the value used for comparison is taken
from another register not from memory
PART B:

1. With a neat diagram, explain the machine architecture of SIC (May06)


The Simplified Instructional Computer (SIC)
SIC is a hypothetical computer that includes the hardware features most often found
on real machines

Two versions of SIC


o standard model
o XE version

Memory
o 8-bit bytes
o 3 consecutive bytes form a word
o 215 bytes in the computer memory

Registers:

Mnemonic
A
X
L
PC
SW

Number
0
1
2
8
9

Special use
Accumulator; used for arithmetic operations
Index register; used for addressing
Linkage register; JSUB
Program counter
Status word, including CC

Data Formats
o Integers are stored as 24-bit binary numbers; 2s complement
representation is used for negative values
o No floating-point hardware

http://www.francisxavier.ac.in

Page 6

Francis Xavier Engineering College, Department of Computer Science and Engineering

Instruction Formats
opcode

address

o The flag bit x is used to indicate indexed-addressing mode

Addressing modes
o Two addressing modes
o Indicated by the x bit in the instruction

Mode

Indication

Target address calculation

Direct

x=0

TA=address

Indexed

x=1

TA=address+(X)

Instruction set:
o Load/store registers: LDA, LDX, STA, STX
o Integer arithmetic: ADD, SUB, MUL, DIV
All involve register A and a word in memory, result stored in register A
o COMP
Compare value in register A with a word in memory
Set a condition code CC (<, =, or >)
o Conditional jump instructions: JLT, JEQ, JGT: test CC and jump
o Subroutine linkage : JSUB, RSUB: return address in register L
JSUB jumps to the subroutine, placing the return address in
register L
RSUB returns by jumping to the address contained in register L
o Input and output
Performed by transferring 1 byte at a time to or from the
rightmost 8 bits of register A
Each device is assigned a unique 8-bit code, as an operand of
I/O instructions
Test Device (TD): < (ready), = (not ready)
Read Data (RD), Write Data (WD)

http://www.francisxavier.ac.in

Page 7

Francis Xavier Engineering College, Department of Computer Science and Engineering

2. Write short notes on:


a) Data and instruction formats of SIC/XE
b) Addressing modes of SIC/XE
c) Instruction set SIC/XE
d) Input and output SIC/XE
a) Data and instruction formats
Memory
o Maximum memory available on a SIC/XE system is 1 megabyte (2 20 bytes)
o An address (20 bits) cannot be fitted into a 15-bit field as in SIC Standard
o Must change instruction formats and addressing modes
Registers
o Additional registers are provided by SIC/XE
Mnemonic

Number

Special use

Base register

General working register

General working register

Floating-point accumulator (48 bits)

Data Format
o There is a 48-bit floating-point data type
fraction is a value between 0 and 1
exponent is an unsigned binary number between 0 and 2047
zero is represented as all 0

http://www.francisxavier.ac.in

Page 8

Francis Xavier Engineering College, Department of Computer Science and Engineering

Instruction formats

b) Addressing modes of SIC/XE


Base Relative Addressing Mode
n

opcode

e
disp

(0disp 4095)

b=1, p=0, TA=(B)+disp

Program-Counter Relative Addressing Mode


n

opcode

b=0, p=1, TA=(PC)+disp

e
disp
(-2048disp 2047)

Direct Addressing Mode


n

opcode

opcode

e
disp

(0disp 4095)

b=0, p=0, TA=disp


n

e
disp

b=0, p=0, TA=(X)+disp (with index addressing mode)

http://www.francisxavier.ac.in

Page 9

Francis Xavier Engineering College, Department of Computer Science and Engineering

Immediate Addressing Mode

opcode

e
disp

n=0, i=1, x=0, operand=disp


Indirect Addressing Mode

opcode

e
disp

n=1, i=0, x=0, TA=(disp)


Simple Addressing Mode

opcode

e
disp

i=0, n=0, TA=bpe+disp (SIC standard)


opcode+n+i = SIC standard opcode (8-bit)

opcode

e
disp

i=1, n=1, TA=disp (SIC/XE standard)


c) Instruction set:
o Load and store the new registers: LDB, STB, etc.
o Floating-point arithmetic operations: ADDF, SUBF, MULF, DIVF
o Register move: RMO
o Register-to-register arithmetic operations : ADDR, SUBR, MULR, DIVR
o Supervisor call: SVC
d) Input and output:
o I/O channels to perform I/O while CPU is executing other instructions: SIO,
TIO, HIO

http://www.francisxavier.ac.in

Page 10

Francis Xavier Engineering College, Department of Computer Science and Engineering

3. Write a sequence of instructions for SIC to set. Illustrate how the same
calculation could be performed on SIC/XE: (NOV 07)
VAL1=VAL2 + INCR 2; VAL3= VAL4 + INCR 2
SIC:
LDA

VAL2

...

ADD

INCR

ONE

WORD 1

one-word constant

SUB

TWO

VAL2

RESW 1

one-word variables

STA

VAL1

VAL1

RESW 1

LDA

VAL4

VAL4

RESW 1

ADD

INCR

VAL3

RESW 1

SUB

TWO

INCR

STA

VAL3

RESW 1

SIC / XE:
LDS

INCR

LDA

VAL2

VAL1=VAL2+INCR-2

ADDR S,A
SUB

#2

STA

VAL1

LDA

VAL4

VAL3=VAL4+INCR-2

ADDR S,A
SUB

#2

STA

VAL3

...
VAL2
VAL1

RESW 1
RESW 1

VAL4

RESW 1

VAL3

RESW 1

INCR

one-word variables

RESW 1

4. Explain Input and Output Programming of SIC and SIC/XE.


SIC Input and Output Programming:
TD test device is ready to send/receive data

CC of < means device is ready

CC of = means device is not ready

RD read data, when the device is ready


WD write data, when device is ready
Transfers 1 byte at a time to or from the rightmost 8 bits of register A.
Each device has a unique 8-bit code as an operand.
http://www.francisxavier.ac.in

Page 11

Francis Xavier Engineering College, Department of Computer Science and Engineering

WORD/BYTE -- Reserve one word/byte of storage


RESW/RESB -- Reserve one or more words/bytes of storage

Fig : Sample SIC program to illustrate I/O operation in SIC


SIC / XE Input and Output Programming:

There are I/O channels that can be used to perform input and output while the
CPU is executing other instructions

Allows overlap of computing and I/O, resulting in more efficient system operation.

Transfers 1 byte at a time to or from the rightmost 8 bits of register A.

Each device has a unique 8-bit code as an operand.

The instructions SIO, TIO, and HIO are used to start test and halt the operation of I/O
channels.

5. Explain SIC assembler language programming with suitable example. (May11)


SIC Data Movement Operation:
WORD/BYTE -- Reserve one word/byte of storage
RESW/RESB -- Reserve one or more words/bytes of storage
Since SIC does not support immediate addressing operands should be
taken from the memory location specified by the label

http://www.francisxavier.ac.in

Page 12

Francis Xavier Engineering College, Department of Computer Science and Engineering

Fig: Sequence of instruction for SIC machine to move a word and character to different
locations
SIC Arithmetic Operation:

Fig : Sequence of instruction to find BETA=ALPHA + INCR 1; DELTA= GAMMA + INCR 2

http://www.francisxavier.ac.in

Page 13

Francis Xavier Engineering College, Department of Computer Science and Engineering

SIC Looping and Indexing:

TIX: (used in SIC)

It performs two functions.


o First it adds 1 to the value in register X and then it compares the new
value of X to the value of the operand
o The condition code is set to indicate the result of this comparison

Fig: Sequence of instruction to add elements in ALPHA & BETA arrays and store it in

GAMMA

http://www.francisxavier.ac.in

Page 14

Francis Xavier Engineering College, Department of Computer Science and Engineering

SIC subroutine call and I/O operation:

Fig: Sequence of instruction to copy 100 record from device F1 using subroutine

http://www.francisxavier.ac.in

Page 15

Francis Xavier Engineering College, Department of Computer Science and Engineering

UNIT II
ASSEMBLER

Basic assembler functions - A simple SIC assembler Assembler algorithm and


data structures - Machine dependent assembler features - Instruction formats and
addressing modes program relocation - Machine independent assembler features
- Literals Symbol-defining statements Expressions - One pass assemblers and
Multi pass assemblers - Implementation example - MASM assembler.

1. What do you mean by assembler directives?


In addition to the machine instructions of the source program, assembler must process
statement called assembler directives. These instructions are not translated into machine
instructions instead they provide instructions to assembler itself.
1. Define the basic functions of assembler.

Translating mnemonic operation codes to their machine language equivalents.

Assigning machine addresses to symbolic labels used by the programmer.

2. Mention the assembler directive in SIC.


The assembly language contains the following assembler directives
START - Specify name and starting address of the program
END

- Indicate the end of the source program and specify the first executable

instruction in the program.


BYTE

- Generate character and hexadecimal constant, occupying as manybytes

needed to represent the constant.


WORD - Generate one word integer constant
RESB - Reserve the indicated no of bytes for a data area.
RESW - Reserve the indicated no of words for a data area.
3. What are the functions of Pass1 of assembler?
Pass1 does the following things.
a. Assign addresses to all statements in the program.
b. Save the addresses assigned to all labels for use in Pass2.
c. Perform some processing of assembler directives. (Determining the length of
data areas defined by BYTE, RESW etc.)
4. What are the functions of pass2 of assembler?
Pass2 does the following things.
a. Assemble instructions (Translating Opcode and Looking up addresses)
http://www.francisxavier.ac.in

Page 16

Francis Xavier Engineering College, Department of Computer Science and Engineering

b. Generate data values defined by BYTE, WORD etc.


c. Perform processing of assembler directives not done during Pass1.
d. Write the object program and the assembly listing.
5. What is relocation?
Sometimes the starting address of the source program is not known until load time.
Hence the relocatable program helps in loading the program into memory wherever there is
room for it. The movement of object code from one location to another at load time is called
relocation.
6. Define forward reference.
Forward reference is a reference to a label that is defined later in the program.
Eg:
Loc

Label

Operator

Operand

1000

FIRST

STL

RETADR

1003

CLOOP

JSUB

RDREC

CLOOP

RESW

1012

1033

RETADR

7. Differentiate program counter and location counter.


LOCCTR is a variable that is used to help in the assignment of addresses. LOCCTR
is initialized to the beginning address specified in the START stmt. After each source stmt is
processed the length of the assembled instruction or data area to be generated is added to
LOCCTR.
Program Counter is a register, which holds the address of next executable
instruction.
8. What is the object program format of simple assembler?
The assembler must write the generated object code into object program. This object
program will later be loaded into memory for execution. It contains three types of records.
The format of each record is shown below.
Header Record:
Col 1

:H

Col 2-7 : Program name


http://www.francisxavier.ac.in

Page 17

Francis Xavier Engineering College, Department of Computer Science and Engineering

Col 8-13: Starting address of the object program (Hex)


Col 14-19: Length of the object program in bytes (hex)
Text Record:
Col

:T

Col 2-7: Starting address of the object code in this record (hex)
Col 8-9: Length of the object code in this record in bytes (hex)
Col 10-69: Object code (hex)
End Record:
Col 1

:E

Col 2-7 : Address o9f the first executable instruction(hex)


9. What is the purpose of modification record?
The modification record is used in program relocation. The program relocation can be
solved in the following ways:

When the assembler generates the object code for the instruction, it will insert
the address of the operand relative to the start of the program.

The assembler will also produce a command for the loader, instructing it to
add the beginning address of the program to the address field in the instruction
at load time.

The command for the loader must also be a part of the object program. This is
accomplished with a modification record.

10. What is a symbol table? How is it useful? (Nov 06)


Symbol table is data structure used to store all the labels or symbols present in the
assembly language program along with the value assigned to that symbol. During pass1 of
assembler, symbol table is used to store the values of the symbols and during pass2; it is used
to translate the instruction by obtaining the address of the symbol.
11. How jump instructions are assembled? (Nov 06)
In case of SIC standard version Jump instructions are assembled by translating the
mnemonic into its machine representation and write the address of the operand.
Eg: JSUB

VALUE

.
.

=> 48 1006

.
1006

VALUE

RESW 1

http://www.francisxavier.ac.in

Page 18

Francis Xavier Engineering College, Department of Computer Science and Engineering

In SIC/XE, Jump instructions are assembled using program counter or base relative
addressing mode by finding the dispalcement. If the displacement is not fit into 12-bits, the
instruction will be assembled using format-4 type using 20-bit address field.
12. Consider the following sequence
X

EQU Y

EQU Z

RESW 1

Is a two pass assembler can resolve such a sequence of definition? Justify your
answer. (May 07)
No.
Reason: Y cannot be assigned a value during the first pass because Z has not been
defined at that time. So X cannot be evaluated during the second pass. In this case two passes
over the source program cannot resolve such a sequence.
13. What is a data structure used to organize the symbol table and operation code
table in a simple assembler? Why it is preferred? (May 07)
Hash function based data structures are used to organize the symbol table. Hash
function is used to perform well with random keys. Division of the entire key by a prime
table length gives good results.
14. Describe how assembler handles literals.
It is convenient for the programmer to write the value of a constant operand as a part
of the instruction that uses it. If we have the constant operand as a part of the instruction,
avoids confusion of defining it elsewhere. Literal is identified with a prefix = followed by
value.
Eg:

001A ENDFIL

LDA = CEOF

1062

TD = X05

WLOOP

15. What is meant by literal pool?


All the literal operands used in the program are gathered together into one or more
literal pools. Normally literals are placed into a pool at the end of the program. It is desirable
to place literals into a pool at some other location using the assembler directive LTORG.
16. What is load-and go assembler?
Assembler produces object code directly in memory for execution. It does not
generate any object program and hence no loader is needed. This is called as load-and-go
assembler.

http://www.francisxavier.ac.in

Page 19

Francis Xavier Engineering College, Department of Computer Science and Engineering

17. Write the difference between near and far jump statements of MASM.
Near Jump

Far Jump

A near jump is a jump to a target in the A far jump is a jump to a target in a


same segment and it is assembled by using different code segment and it is assembled
a current code segment CS.
by using different segment registers

18. What is an object program?


An object program contains translated instructions and data values from the source
program and specifies address in memory where these items are to be loaded.
19. What is MASM Assembler?
MASM Assembler is a translator that converts an X86 assembly language program
into machine language program. It is a Pentium (X86) family assembler, developed by
Microsoft.
20. How are forward references handled in one pass assembler?
It is easy to eliminate forward references to data items by defining them in the source
program before they are referenced. Programmer can place all storage reservation statements
at the start of the program rather than at the end. But forward references to labels on
instructions cannot be eliminated.
21. Give the use of LTORG.
It is desirable to place literals into a pool at some other location using the assembler
directive LTORG. When the assembler encounters a LTORG statement, it creates a literal
pool that contains all the literal operands used from the previous LTORG (or beginning of
the program).
22. What is meant by external references?
Assembler program can be divided into many sections known as control sections and each
control section can be loaded and relocated independently of the others. If the instruction in one
control section needs to refer instruction or data in another control section the assembler is unable
to process these references in normal way. Such references between controls are called external
references.

23. What is the difference between the assembler directive EXTREF and EXTDEF?
EXTDEF names external symbols that are defined in a particular control section and may
be used in other sections.
EXTREF names external symbols that are referred in a particular control section and
defined in another control section.

http://www.francisxavier.ac.in

Page 20

Francis Xavier Engineering College, Department of Computer Science and Engineering

24. Give the general format of define record.


This record gives information about external symbols that are defined in a particular
control section. The format is
Col 1

Col 2-7

name of external symbol defined in this control section

Col 8-13

relative address of the symbol with in this control section

Col 14-73

name and relative address for other external symbols.

25. Define modification record and give its format.


This record contains the information about the modification in the object code during
program relocation. The general format is
Col 1

Col 2-7

Starting location of the address field to be modified relative to the


beginning of the program

Col 8-9

length of the address field to be modified in half bytes.

26. What is the use of base register table in AIX assembler?


A base register table is used to remember which of the general purpose registers are
currently available as base registers and also the base addresses they contain. USING statement
causes entry to the table and .DROP statement removes the corresponding table entry.

27. Differentiate absolute expression and relative expression.


Absolute Expression
If the result of the expression is an absolute value (constant) then it is known as absolute
expression. Eg: BUFEND BUFFER
Relative Expression
If the result of the expression is relative to the beginning of the program then it is known
as relative expression. Label on instructions and data areas and references to the location counter
values are relative terms. Eg: BUFEND + BUFFER
28. Write the steps required to translate the source program to object program.

Convert mnemonic operation codes to their machine language equivalents.

Convert symbolic operands to their equivalent machine addresses

Build the machine instruction in the proper format.

Convert the data constants specified in the source program into their internal
machine representation

Write the object program and assembly listing.

http://www.francisxavier.ac.in

Page 21

Francis Xavier Engineering College, Department of Computer Science and Engineering

29. Write down the pass numbers (PASS 1/ PASS 2) of the following activities that occur
in a two pass assembler: a. Object code generation b. Literals added to literal table
c. Listing printed d. Address location of local symbols
Answer:
a. Object code generation - PASS 2
b. Literals added to literal table PASS 1
c. Listing printed PASS2
d. Address location of local symbols PASS1

30. How the register to register instructions are translated in assembler?


In the case of register to register instructions the operand field contains the register name.
During the translation first the object code is converted into its corresponding machine language
equivalent with the help of OPTAB. Then the SYMTAB is searched for the numeric equivalent
of register and that value is inserted into the operand field

31. What is the need of OPTAB (operation code table) in assembler?


The operation code table contains the mnemonic operation code and its machine language
equivalent. Some assemblers it may also contain information about instruction format and length.
OPTAB is usually organized as a hash table, with mnemonic operation code as the key.

32. What are the three different records used in object program?
The header record, text record and the end record are the three different records used in
object program.

The header record contains the program name, starting address and length of the
program.

Text record contains the translated instructions and data of the program.

End record marks the end of the object program and specifies the address in the
program where execution is to begin.

http://www.francisxavier.ac.in

Page 22

Francis Xavier Engineering College, Department of Computer Science and Engineering

PART B:
1. What are the functions performed in pass 1 and pass 2 of a two pass assembler?
Pass 1
Assign addresses to all statements in the program
Save the values assigned to all labels for use in Pass 2
Perform some processing of assembler directives
Pass 2
Assemble instructions
Generate data values defined by BYTE, WORD
Perform processing of assembler directives not done in Pass 1
Write the object program and the assembly listing
2. List the tables and data structures used in a two pass assembler. Explain briefly.
Assembler uses two major internal data structures:
a. Operation Code Table (OPTAB) : Used to lookup mnemonic
operation codes and translate them into their machine language equivalents
b. Symbol Table (SYMTAB): Used to store values (Addresses) assigned to
labels.
Location Counter (LOCCTR) :
Variable used to help in the assignment of addresses.
It is initialized to the beginning address specified in the START statement.
After each source statement is processed, the length of the assembled instructionor
data area is added to LOCCTR.
Whenever a label is reached in the source program, the current value of
LOCCTR gives the address to be associated with that label.
Operation Code Table (OPTAB):
Contains the mnemonic operation and its machine language equivalent.
Also contains information about instruction format and length.
In Pass 1, OPTAB is used to lookup and validate operat ion codes in the
source program.
In Pass 2, it is used to translate the operation codes to machine language program.
During Pass 2, the information in OPTAB tells which instruction format to use in
assembling the instruction and any peculiarities of the object code instruction.
http://www.francisxavier.ac.in

Page 23

Francis Xavier Engineering College, Department of Computer Science and Engineering

Symbol Table (SYMTAB):


Includes the name and value for each label in the source program and
flags to indicate error conditions.
Dur ing P ass 1 o f t he a sse mb le r,

l a be l s

a r e e nt e r e d

i nt o

S Y M T A B a s t he y a r e encountered in the source program along with their


assigned addresses.
During Pass 2, symbols used as operands are looked up in SYMTAB to obtain the
addresses to be inserted in the assembled instructions. Pass 1 usually writes an
intermediate file that contains each source statement together with it s
assigned address, error indicators. This file is used as the input to
Pass 2. This copy of the source program can also be used to retain the results of
certain operations that may be performed during Pass 1 such as scanning
the operand field for symbols and addressing flags, so these need not be
performed again during Pass 2.
3. State and explain the PASS1 algorithm of an Assembler. (Nov 05/ May 06)
Working of Pass 1
Assign addresses to all statements in the program
Save the values assigned to all labels for use in Pass 2
Perform some processing of assembler directives
Algorithm for Pass 1:
read first input line
if OPCODE=START then
begin
save #[OPERAND] as starting address
initialize LOCCTR to starting address
write line to intermediate file
read next input line
end
else
initialize LOCCTR to 0
while OPCODEEND do
begin
if this is not a comment line then
http://www.francisxavier.ac.in

Page 24

Francis Xavier Engineering College, Department of Computer Science and Engineering

begin
if there is a symbol in the LABEL field then
begin
search SYMTAB for LABEL
if found then
set error flag (duplicate symbol)
else
insert (LABEL, LOCCTR) into SYMTAB
end {if symbol}
search OPTAB for OPCODE
if found then
add 3 {instruction length} to LOCCTR
else if OPCODE=WORD then
add 3 to LOCCTR
else if OPCODE=RESW then
add 3 * #[OPERAND] to LOCCTR
else if OPCODE=RESB then
add #[OPERAND] to LOCCTR
else if OPCODE=BYTE then
begin
find length of constant in bytes
add length to LOCCTR
end {if BYTE}
else
set error flag (invalid operation code)
end {if not a comment}
write line to intermediate file
read next input line
end {while not END}
Write last line to intermediate file
Save (LOCCTR-starting address) as program length
The algorithm scans the first statement START and saves the operand field (the address)
as the starting address of the program. Initializes the LOCCTR value to this address. This line
is written to the intermediate line. If no operand is mentioned the LOCCTR is initialized to
http://www.francisxavier.ac.in

Page 25

Francis Xavier Engineering College, Department of Computer Science and Engineering

zero. If a label is encountered, the symbol has to be entered in the symbol table along with its
associated address value. If the symbol already exists that indicates an entry of the same
symbol already exists. So an error flag is set indicating a duplication of the symbol. It next
checks for the mnemonic code, it searches for this code in the OPTAB. If found then the
length of the instruction is added to the LOCCTR to make it point to the next instruction. If
the opcode is the directive WORD it adds a value 3 to the LOCCTR. If it is RESW, it needs
to add the number of data word to the LOCCTR. If it is BYTE it adds a value one to the
LOCCTR, if RESB it adds number of bytes. If it is END directive then it is the end of the
program it finds the length of the program by evaluating current LOCCTR the starting
address mentioned in the operand field of the END directive. Each processed line is written to
the intermediate file.
4. Explain the algorithm for pass 2 of the assembler. (May11)
Working of Pass 2:
Assemble instructions
Generate data values defined by BYTE, WORD
Perform processing of assembler directives not done in Pass 1
Write the object program and the assembly listing
Algorithm for Pass 2:
read first input line (from intermediate file)
If OPCODE=START then
begin
write listing line
read next input line
end {if START}
Write Header record to object program
Initialize first Text record
While OPCODE END do
begin
if this is not a comment line then
begin
search OPTAB for OPCODE
if found then
begin
http://www.francisxavier.ac.in

Page 26

Francis Xavier Engineering College, Department of Computer Science and Engineering

if there is a symbol in OPERAND field then


begin
search SYMTAB for OPERAND
if found then
store symbol value as operand address
else
begin
store 0 as operand address
set error flag (undefined symbol)
end
end {if symbol}
else
store 0 as operand address
assemble the object code instruction
end {if opcode found}
else if OPCODE=BYTE or WORD then
convert constant to object code
if object code will not fit into the current Text record then
begin
write Text record to object program
initialize new Text record
end
add object code to Text record
end {if not comment}
write listing line
read next input line
end {while not END}
write last Text record to object program
Write End record to object program
Write last listing line
Here the first input line is read from the intermediate file. If the opcode is START,
then this line is directly written to the list file. A header record is written in the object
program which gives the starting address and the length of the program (which is calculated
during pass
http://www.francisxavier.ac.in

Page 27

Francis Xavier Engineering College, Department of Computer Science and Engineering

Then the first text record is initialized. Comment lines are ignored. In the instruction,
for the opcode the OPTAB is searched to find the object code. If a symbol is there in the
operand field, the symbol table is searched to get the address value for this which gets added
to the object code of the opcode. If the address not found then zero value is stored as
operands address. An error flag is set indicating it as undefined. If symbol itself is not found
then store 0 as operand address and the object code instruction is assembled.
If the opcode is BYTE or WORD, then the constant value is converted to its equivalent
object code (for example, for character EOF, its equivalent hexadecimal value 454f46 is
stored). If the object code cannot fit into the current text record, a new text record is created
and the rest of the instructions object code is listed. The text records are written to the object
program. Once the whole program is assembled and when the END directive is encountered,
the End record is written.
5. With an example, explain the concept of program relocation. (Nov05, May06,
Nov 06)
Sometimes it is required to load and run several programs at the same time. The
system must be able to load these programs wherever there is place in the memory. Therefore
the exact starting is not known until the load time.
Absolute Program
In this the address is mentioned during assembling itself. This is called Absolute
Assembly. Consider the instruction:
55

101B

LDA

THREE

00102D

This statement says that the register A is loaded with the value stored at location
102D. Suppose it is decided to load and execute the program at location 2000 instead of
location 1000. Then at address 102D the required value which needs to be loaded in the
register A is no more available. The address also gets changed relative to the displacement of
the program. Hence we need to make some changes in the address portion of the instruction
so that we can load and execute the program at location 2000. Apart from the instruction
which will undergo a change in their operand address value as the program load address
changes. There exist some parts in the program which will remain same regardless of where
the program is being loaded.

http://www.francisxavier.ac.in

Page 28

Francis Xavier Engineering College, Department of Computer Science and Engineering

Since assembler will not know actual location where the program will get loaded, it cannot
make the necessary changes in the addresses used in the program. However, the assembler
identifies for the loader those parts of the program which need modification. An object
program that has the information necessary to perform this kind of modification is called the

relocatable program.
The above diagram shows the concept of relocation. Initially the program is loaded at
location 0000. The instruction JSUB is loaded at location 0006. The address field of this
instruction contains 01036, which is the address of the instruction labeled RDREC. The
second figure shows that if the program is to be loaded at new location 5000. The address of
the instruction JSUB gets modified to new location 6036. Likewise the third figure shows
that if the program is relocated at location 7420, the JSUB instruction would need to be
changed to 4B108456 that correspond to the new address of RDREC.
The only parts of the program that require modification at load time are those that specify
direct addresses. The rest of the instructions need not be modified. The instructions which
doesnt require modification are the ones that is not a memory address (immediate
addressing) and PC-relative, Base-relative instructions. From the object program, it is not
possible to distinguish the address and constant. The assembler must keep some information
to tell the loader. The object program that contains the modification record is called a
relocatable program. For an address label, its address is assigned relative to the start of the
program (START 0). The assembler produces a Modification record to store the starting
location and the length of the address field to be modified. The command for the loader must
also be a part of the object program. The Modification has the following format:
http://www.francisxavier.ac.in

Page 29

Francis Xavier Engineering College, Department of Computer Science and Engineering

Modification record
Col. 1

Col. 2-7

Starting location of the address field to be modified, relative to the

beginning of the program (Hex)


Col. 8-9

Length of the address field to be modified, in half-bytes (Hex)

One modification record is created for each address to be modified The length is stored in
half-bytes (4 bits) The starting location is the location of the byte containing the leftmost bits
of the address field to be modified. If the field contains an odd number of half-bytes, the
starting location begins in the middle of the first byte
6. Explain in detail about the machine independent features of assembler. (May 06)

Machine-Independent features: These are the features which do not depend on the
architecture of the machine. These are:

Literals

Expressions

Literals: A literal is defined with a prefix = followed by a specification of the literal value.
Example:
e.g. 45

001A ENDFIL

=CEOF

LDA

032010

.
93

LTORG
=CEOF

002D *

454F46

The example above shows a 3-byte operand whose value is a character string EOF. The object
code for the instruction is also mentioned. It shows the relative displacement value of the location
where this value is stored. In the example the value is at location (002D) and hence the displacement
value is (010).

e.g. 215

1062

WLOOP

TD

=X05

E32011

As another example the given statement above shows a 1-byte literal with the hexadecimal
value 05.
Literals vs. Immediate Operands: It is important to understand the difference between a constant
defined as a literal and a constant defined as an immediate operand.
In case of literals the assembler generates the specified value as a constant at some other
memory location.
e.g. 45 001A

ENDFIL

LDA

=CEOF

032010

In immediate mode the operand value is assembled as part of the instruction itself. Example

e.g.

55

http://www.francisxavier.ac.in

0020

LDA #3

010003
Page 30

Francis Xavier Engineering College, Department of Computer Science and Engineering

Literal Pool: All the literal operands used in a program are gathered together into one or more
literal pools. This is usually placed at the end of the program. The assembly listing of a program
containing literals usually includes a listing of this literal pool, which shows the assigned addresses
and the generated data values. In some cases it is placed at some other location in the object program.
LTORG assembler directives: An assembler directive LTORG is used. Whenever the LTORG is
encountered, it creates a literal pool that contains all the literal operands used since the beginning of
the program. The literal pool definition is done after LTORG is encountered. It is better to place the
literals close to the instructions.
Literal Table: A literal table is created for the literals which are used in the program. The literal table
contains the literal name, operand value and length. The literal table is usually created as a hash table
on the literal name.
Implementation of Literals:
During Pass-1:

The literal encountered is searched in the literal table.


o

If the literal already exists, no action is taken;

if it is not present, the literal is added to the LITTAB and for the address value it
waits till it encounters LTORG for literal definition.

When Pass 1 encounters a LTORG statement or the end of the program, the assembler makes
a scan of the literal table.

At this time each literal currently in the table is assigned an address.

As addresses are assigned, the location counter is updated to reflect the number of bytes
occupied by each literal.

During Pass-2:

The assembler searches the LITTAB for each literal encountered in the instruction and
replaces it with its equivalent value as if these values are generated by BYTE or WORD.

If a literal represents an address in the program, the assembler must generate a modification
relocation for, if it all it gets affected due to relocation.

The following figure shows the difference between the SYMTAB and LITTAB

http://www.francisxavier.ac.in

Page 31

Francis Xavier Engineering College, Department of Computer Science and Engineering

Symbol-Defining Statements:
EQU Statement: Most assemblers provide an assembler directive that allows the programmer to
define symbols and specify their values. The directive used for this EQU (Equate). The general form
of the statement is:
Symbol

EQU

value

where value can be: constant, other symbol, expression


This statement defines the given symbol (i.e., entering in the SYMTAB) and assigning to it the value
specified. One common usage is to define symbolic names that can be used to improve readability in
place of numeric values and there wont be any forward reference
+LDT #4096
This loads the register T with immediate value 4096; this does not clearly what exactly this
value indicates.
If a statement is included as:
MAXLEN

EQU 4096

+LDT

#MAXLEN

and then

Then it clearly indicates that the value of MAXLEN is some maximum length value. When
the assembler encounters EQU statement, it enters the symbol MAXLEN along with its value in the
symbol table. During LDT the assembler searches the SYMTAB for its entry and its equivalent value
as the operand in the instruction. The object code generated is the same for both the options discussed,
but is easier to understand.
Another common usage of EQU statement is for defining values for the general-purpose
registers. The assembler can use the mnemonics for register usage like a-register A, X index register
and so on. But there are some instructions which require numbers in place of names in the
instructions. For example in the instruction RMO 0, 1 instead of RMO A, X. The programmer can
assign the numerical values to these registers using EQU directive.
A

EQU

EQU

1 and so on

http://www.francisxavier.ac.in

Page 32

Francis Xavier Engineering College, Department of Computer Science and Engineering

These statements will cause the symbols A, X, L to be entered into the symbol table with
their respective values. An instruction RMO A, X would then be allowed.
As another usage if in a machine that has many general purpose registers named as R1, R2,,
some may be used as base register, some may be used as accumulator. Their usage may change from
one program to another. In this case we can define these requirement using EQU statements.
BASE

EQU

R1

COUNT

EQU

R2

INDEX

EQU

R3

One restriction with the usage of EQU is whatever symbol occurs in the right hand side of the
EQU should be predefined. For example, the following statement is not valid:
BETA

EQU

ALPHA

ALPHA

RESW 1

As the symbol ALPHA is assigned to BETA before it is defined. The value of ALPHA is not
known.
ORG Statement: This directive can be used to indirectly assign values to the symbols. The directive
is usually called ORG (for origin). Its general format is:
ORG

value

where value is a constant or an expression involving constants and previously defined symbols. When
this statement is encountered during assembly of a program, the assembler resets its location counter
(LOCCTR) to the specified value. Since the values of symbols used as labels are taken from
LOCCTR, the ORG statement will affect the values of all labels defined until the next ORG is
encountered. ORG is used to control assignment storage in the object program. Sometimes altering
the values may result in incorrect assembly.
ORG can be useful in label definition. Suppose there is a need to define a symbol table with the
following structure:

SYMBOL

6 Bytes

VALUE

3 Bytes

FLAG

2 Bytes.

The table looks like the one given below.

SYMBOL

VALUE

FLAGS

.
.
.

.
.
.

.
.
.

STAB
(100 entries)

http://www.francisxavier.ac.in

Page 33

Francis Xavier Engineering College, Department of Computer Science and Engineering

The symbol field contains a 6-byte user-defined symbol; VALUE is a one-word


representation of the value assigned to the symbol; FLAG is a 2-byte field specifies symbol type and
other information. The space for the table can be reserved by the statement:
STAB

RESB

1100

The table entries can be referred using indexed addressing, place the offset value of the
desired entry from the beginning of the table in the index register. To refer to the fields SYMBOL,
VALUE, and FLAGS individually, the values should be assigned first as shown below:
SYMBOL EQU

STAB

VALUE

EQU

STAB+6

FLAG

EQU

STAB+9

To retrieve the VALUE field from the table indicated by register X, we can write a statement:
LDA

VALUE, X

The same thing can also be done using ORG statement in the following way:
STAB

RESB

1100

ORG

STAB

SYMBOL

RESB

VALUE

RESW

FLAG

RESB

ORG

STAB+1100

The first statement allocates 1100 bytes of memory assigned to label STAB. In the second
statement the ORG statement initializes the location counter to the value of STAB. Now the LOCCTR
points to STAB. The next three lines assign appropriate memory storage to each of SYMBOL,
VALUE and FLAG symbols. The last ORG statement reinitializes the LOCCTR to a new value after
skipping the required number of memory for the table STAB (i.e., STAB+1100).
While using ORG, the symbol occurring in the statement should be predefined as is required
in EQU statement. For example for the sequence of statements below:
ORG ALPHA
BYTE1 RESB

BYTE2 RESB

BYTE3 RESB

1
ORG

ALPHA

RESB 1

The sequence could not be processed as the symbol used to assign the new location counter
value is not defined. In first pass, as the assembler would not know what value to assign to ALPHA,
the other symbol in the next lines also could not be defined in the symbol table. This is a kind of
problem of the forward reference.

http://www.francisxavier.ac.in

Page 34

Francis Xavier Engineering College, Department of Computer Science and Engineering

EXPRESSIONS: Assemblers also allow use of expressions in place of operands in the instruction.
Each such expression must be evaluated to generate a single operand value or address. Assemblers
generally arithmetic expressions formed according to the normal rules using arithmetic operators +, *, /. Division is usually defined to produce an integer result. Individual terms may be constants, userdefined symbols, or special terms. The only special term used is * ( the current value of location
counter) which indicates the value of the next unassigned memory location. Thus the statement:
BUFFEND

EQU

Assigns a value to BUFFEND, which is the address of the next byte following the buffer area.
Some values in the object program are relative to the beginning of the program and some are absolute
(independent of the program location, like constants). Hence, expressions are classified as either
absolute expression or relative expressions depending on the type of value they produce.
Absolute Expressions: The expression that uses only absolute terms is absolute expression. Absolute
expression may contain relative term provided the relative terms occur in pairs with opposite signs for
each pair. Example:

MAXLEN

EQU

BUFEND-BUFFER

In the above instruction the difference in the expression gives a value that does not depend on
the location of the program and hence gives an absolute immaterial of the relocation of the program.
The expression can have only absolute terms:

MAXLEN

EQU

1000

Relative Expressions: All the relative terms except one can be paired as described in absolute. The
remaining unpaired relative term must have a positive sign. Example:
STAB

EQU

OPTAB + (BUFEND BUFFER)

Handling the type of expressions: to find the type of expression, we must keep track the type
of symbols used. This can be achieved by defining the type in the symbol table against each of the
symbol as shown in the table below:

Symbol
RETADR
BUFFER
BUFEND
MAXLEN

Type
R
R
R
A

Value
30
36
1036
1000

7. Describe the design of one pass assembler. (Nov 06 /May 07)


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.

http://www.francisxavier.ac.in

Page 35

Francis Xavier Engineering College, Department of Computer Science and Engineering

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.


Forward Reference in One-Pass Assemblers: In load-and-Go assemblers when a forward reference
is encountered:

Omits the operand address if the symbol has not yet been defined
Enters this undefined symbol into SYMTAB and indicates that it is undefined
Adds the address of this operand address to a list of forward references associated
with the SYMTAB entry
When the definition for the symbol is encountered, scans the reference list and
inserts the address.
At the end of the program, reports the error if there are still SYMTAB entries
indicated undefined symbols.
For Load-and-Go assembler
Search SYMTAB for the symbol named in the END statement and jumps to
this location to begin execution if there is no error
After scanning line 40 of the program:
40

2021

CLOOP

302012

The status is that upto this point the symbol RREC is referred once at location 2013,
ENDFIL at 201F and WRREC at location 201C. None of these symbols are defined. The
figure shows that how the pending definitions along with their addresses are included in the
symbol table.
If One-Pass needs to generate object code:
If the operand contains an undefined symbol, use 0 as the address and write the Text
record to the object program.
Forward references are entered into lists as in the load-and-go assembler.
When the definition of a symbol is encountered, the assembler generates another Text
record with the correct operand address of each entry in the reference list.
http://www.francisxavier.ac.in

Page 36

Francis Xavier Engineering College, Department of Computer Science and Engineering

When loaded, the incorrect address 0 will be updated by the latter Text record
containing the symbol definition.
Algorithm for One pass Assembler
Begin
read first input line
if OPCODE = START then
begin
save #[Operand] as starting addr
initialize LOCCTR to starting address
write line to intermediate file
read next input line
end( if START)
else
initialize LOCCTR to 0
While OPCODE != END do
begin
if this is not a comment line then
begin
if there is a symbol in the LABEL field then
begin
search SYMTAB for LABEL
if found then
begin
if symbol value as null
set symbol value as LOCCTR and search the
linked list with the corresponding operand
PTR addresses and generates operand
addresses as corresponding symbol values
set symbol value as LOCCTR in symbol table and
delete the linked list
end
else
insert (LABEL, LOCCTR) into STMTAB
end
http://www.francisxavier.ac.in

Page 37

Francis Xavier Engineering College, Department of Computer Science and Engineering

search OPTAB for OPCODE


if found then
begin
search SYMTAB for OPERND address
if found then
if symbol value not equal to null then
store symbol value as operand address
else
insert at the end of the linked list with a node with address as
LOCCTR
else
insert ( symbol name, null)
add 3 (instr length) to LOCCTR
end
else if OPCODE = WORD then
add 3 to LOCCTR
else if OPCODE = RESW then
add 3 * #[OPERAND] to LOCCTR
else if OPCODE = RESB then
add #[OPERAND] to LOCCTR
else if OPCODE = BYTE then
begin
find length of constant in bytes
add length to LOCCTR
convert constant to object code
end
if object code doesnt fit into current Text record then
begin
Write text record to object program
initialize new Text record
end
add object code to Text record
end {if not comment}
write listing line
http://www.francisxavier.ac.in

Page 38

Francis Xavier Engineering College, Department of Computer Science and Engineering

read next input line


end
write last text record to object pgm
write end record to object pgm
Write last listing line
end
8. Explain in detail about the machine dependent features of assembler. (May 07)
MACHINE-DEPENDENT FEATURES:
a) Instruction formats and addressing modes
b) Program relocation
1. Instruction formats and Addressing Modes: The instruction formats depend on the
memory organization and the size of the memory. In SIC machine the memory is byte
addressable. Word size is 3 bytes. So the size of the memory is 2 12 bytes. Accordingly
it supports only one instruction format. It has only two registers: register A and Index
register. Therefore the addressing modes supported by this architecture are direct,
indirect, and indexed. Whereas the memory of a SIC/XE machine is 2 20 bytes (1 MB).
This supports four different types of instruction types, they are:
1 byte instruction
2 byte instruction
3 byte instruction
4 byte instruction
Instructions can be:
Instructions involving register to register
Instructions with one operand in memory, the other in Accumulator (Single
operand instruction)
Extended instruction format
Addressing Modes are:
Index Addressing(SIC): Opcode m, x
Indirect Addressing: Opcode @m
PC-relative: Opcode m
Base relative: Opcode m
Immediate addressing: Opcode #c
Translations for the Instruction involving Register-Register addressing mode:

http://www.francisxavier.ac.in

Page 39

Francis Xavier Engineering College, Department of Computer Science and Engineering

During pass 1 the registers can be entered as part of the symbol table itself. The
value for these registers is their equivalent numeric codes.
During pass 2, these values are assembled along with the mnemonics object code.
If required a separate table can be created with the register names and their
equivalent numeric values.
Translation involving Register-Memory instructions:
In SIC/XE machine there are four instruction formats and five addressing modes. For
formats and addressing modes refer chapter 1. Among the instruction formats, format -3 and
format-4 instructions are Register-Memory type of instruction. One of the operand is always
in a register and the other operand is in the memory. The addressing mode tells us the way in
which the operand from the memory is to be fetched.
There are two ways: Program-counter relative and Base-relative. This addressing
mode can be represented by either using format-3 type or format-4 type of instruction format.
In format-3, the instruction has the opcode followed by a 12-bit displacement value in the
address field. Where as in format-4 the instruction contains the mnemonic code followed by a 20-bit
displacement value in the address field.
Program-Counter Relative: In this usually format-3 instruction format is used. The instruction
contains the opcode followed by a 12-bit displacement value. The range of displacement values are
from 0 -2048. This displacement (should be small enough to fit in a 12-bit field) value is added to the
current contents of the program counter to get the target address of the operand required by the
instruction. This is relative way of calculating the address of the operand relative to the program
counter. Hence the displacement of the operand is relative to the current program counter value. The
following example shows how the address is calculated:

http://www.francisxavier.ac.in

Page 40

Francis Xavier Engineering College, Department of Computer Science and Engineering

Base-Relative Addressing Mode: In this mode the base register is used to mention the displacement
value. Therefore the target address is TA = (base) + displacement value This addressing mode is used
when the range of displacement value is not sufficient. Hence the operand is not relative to the
instruction as in PC-relative addressing mode. Whenever this mode is used it is indicated by using a
directive BASE. The moment the assembler encounters this directive the next instruction uses baserelative addressing mode to calculate the target address of the operand.
When NOBASE directive is used then it indicates the base register is no more used to
calculate the target address of the operand. Assembler first chooses PC-relative, when the
displacement field is not enough it uses Base-relative.
LDB #LENGTH (instruction)
BASE LENGTH (directive)
:
NOBASE
For example:
12

0003

13

LDB

#LENGTH

BASE

LENGTH

69202D

::
100

0033

LENGTH

RESW

105

0036

BUFFER

RESB

4096

160

104E

STCH

BUFFER,

165

1051

TIXR

B850

::
57C003

In the above example the use of directive BASE indicates that Base-relative addressing mode
is to be used to calculate the target address. PC-relative is no longer used. The value of the LENGTH
is stored in the base register. If PC-relative is used then the target address calculated is:

http://www.francisxavier.ac.in

Page 41

Francis Xavier Engineering College, Department of Computer Science and Engineering

The LDB instruction loads the value of length in the base register which 0033. BASE
directive explicitly tells the assembler that it has the value of LENGTH.
BUFFER is at location (0036)16
(B) = (0033)16

disp = 0036 0033 = (0003)16


20

000A

LDA

LENGTH

032026

STX

LENGTH

134000

::
175

1056

EXIT

Consider Line 175. If we use PC-relative


Disp = TA (PC) = 0033 1059 = EFDA
PC relative is no longer applicable, so we try to use BASE relative addressing mode.
Immediate Addressing Mode: In this mode no memory reference is involved. If immediate mode is
used the target address is the operand itself.

If the symbol is referred in the instruction as the immediate operand then it is immediate with PCrelative mode as shown in the example below:

Indirect and PC-relative mode: In this type of instruction the symbol used in the instruction
is the address of the location which contains the address of the operand. The address of this is
found using PC-relative addressing mode. For example:

http://www.francisxavier.ac.in

Page 42

Francis Xavier Engineering College, Department of Computer Science and Engineering

The instruction jumps the control to the address location RETADR which in turn has the address
of the operand. If address of RETADR is 0030, the target address is then 0003 as calculated above.

2. Program relocation:
Sometimes it is required to load and run several programs at the same time. The
system must be able to load these programs wherever there is place in the memory. Therefore
the exact starting is not known until the load time.
Absolute Program: In this the address is mentioned during assembling itself. This is
called Absolute Assembly. Consider the instruction:
55

101B

LDA

THREE

00102D

This statement says that the register A is loaded with the value stored at location
102D. Suppose it is decided to load and execute the program at location 2000 instead of
location 1000. Then at address 102D the required value which needs to be loaded in the
register A is no more available. The address also gets changed relative to the displacement of
the program. Hence we need to make some changes in the address portion of the instruction
so that we can load and execute the program at location 2000. Apart from the instruction
which will undergo a change in their operand address value as the program load address
changes. There exist some parts in the program which will remain same regardless of where
the program is being loaded.

http://www.francisxavier.ac.in

Page 43

Francis Xavier Engineering College, Department of Computer Science and Engineering

Since assembler will not know actual location where the program will get loaded, it
cannot make the necessary changes in the addresses used in the program. However, the
assembler identifies for the loader those parts of the program which need modification. An
object program that has the information necessary to perform this kind of modification is

called the relocatable program.


The above diagram shows the concept of relocation. Initially the program is loaded at
location 0000. The instruction JSUB is loaded at location 0006. The address field of this
instruction contains 01036, which is the address of the instruction labeled RDREC. The
second figure shows that if the program is to be loaded at new location 5000. The address of
the instruction JSUB gets modified to new location 6036. Likewise the third figure shows
that if the program is relocated at location 7420, the JSUB instruction would need to be
changed to 4B108456 that correspond to the new address of RDREC.
The only parts of the program that require modification at load time are those that
specify direct addresses. The rest of the instructions need not be modified. The instructions
which doesnt require modification are the ones that is not a memory address (immediate
addressing) and PC-relative, Base-relative instructions. From the object program, it is not
possible to distinguish the address and constant. The assembler must keep some information
to tell the loader. The object program that contains the modification record is called a
relocatable program. For an address label, its address is assigned relative to the start of the
program (START 0). The assembler produces a Modification record to store the starting

http://www.francisxavier.ac.in

Page 44

Francis Xavier Engineering College, Department of Computer Science and Engineering

location and the length of the address field to be modified. The command for the loader must
also be a part of the object program. The Modification has the following format:
Modification record
Col. 1

Col. 2-7

Starting location of the address field to be modified, relative to the

beginning of the program (Hex)


Col. 8-9

Length of the address field to be modified, in half-bytes (Hex)

One modification record is created for each address to be modified The length is
stored in half-bytes (4 bits) The starting location is the location of the byte containing the
leftmost bits of the address field to be modified. If the field contains an odd number of halfbytes, the starting location begins in the middle of the first byte
9. Explain the necessity of multi pass assembler. (May 07)
Multi Pass Assembler:

If we use a two-pass assembler, the following symbol definition cannot be allowed.


ALPHA

EQU BETA

BETA

EQU DELTA

DELTA

RESW 1

This is because ALPHA and BETA cannot be defined in pass 1. Actually, if we allow
multi-pass processing, DELTA is defined in pass 1, BETA is defined in pass 2, and
ALPHA is defined in pass 3, and the above definitions can be allowed.

This is the motivation for using a multi-pass assembler.

It is unnecessary for a multi-pass assembler to make more than two passes over the
entire program.

Instead, only the parts of the program involving forward references need to be
processed in multiple passes.

The method presented here can be used to process any kind of forward references.

Multi-Pass Assembler Implementation:

Use a symbol table to store symbols that are not totally defined yet.

For a undefined symbol, in its entry,

We store the names and the number of undefined symbols which contribute to
the calculation of its value.

We also keep a list of symbols whose values depend on the defined value of
this symbol.

http://www.francisxavier.ac.in

Page 45

Francis Xavier Engineering College, Department of Computer Science and Engineering

When a symbol becomes defined, we use its value to reevaluate the values of all of
the symbols that are kept in this list.

The above step is performed recursively.

Forward Reference Example:

Forward Reference Processing:

http://www.francisxavier.ac.in

Page 46

Francis Xavier Engineering College, Department of Computer Science and Engineering

http://www.francisxavier.ac.in

Page 47

Francis Xavier Engineering College, Department of Computer Science and Engineering

http://www.francisxavier.ac.in

Page 48

Francis Xavier Engineering College, Department of Computer Science and Engineering

10. Explain in detail about MASM Assembler.

A collection of segments.
Each segment belongs to a specific class

Common classes: CODE, DATA, CONST, STACK

Segments are addressed by segment registers:

Segment registers are automatically set by loader.

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
Must be loaded by program before they can be used.
MOV AX,DATASEG2
MOV ES, AX
ASSUME is somewhat similar with BASE in SIC,
programmer must provide instructions to load the value to
registers.

Collect several segments into a group and use ASSUME to link a


register with the group.

Parts of a segment can be separated and assembler arranges them


together, like program blocks in SIC/XE
JMP is a main specific issue:
Near JMP: 2 to 3 bytes, same segment, using current CS
Far JMP: 5 bytes, different segment, using a different segment register, as the
instruction prefix.
Forward JMP: e.g., JMP TARGET,

http://www.francisxavier.ac.in

Page 49

Francis Xavier Engineering College, Department of Computer Science and Engineering

Assembler does not know whether it is a near jump or far jump, so not
sure how many bytes to reserve for the instruction.

By default, assembler assumes a forward jump is near jump.


Otherwise,

JMP FAR PTR TARGET , indicate a jump to a different segment


Without FAR PTR, error will occur.
Similar to SIC/EX extended format instructions.

JMP SHORT TARGET, indicate a within-128 offset jump.

Other situations that the length of an instruction depends on operands. So more


complicate than SIC/EX
Must analyze operands, in addition to opcode
Opcode table is more complex.

References between segments that are assembled together can be processed by


assembler

Otherwise, it must be processed by loader.


PUBLIC is similar to EXTDEF
EXTRN is similar to EXTREF

Object programs from MASM can have different formats.

MASM can also generate an instruction timing list.

http://www.francisxavier.ac.in

Page 50

Francis Xavier Engineering College, Department of Computer Science and Engineering

UNIT III
LOADERS AND LINKERS:

Basic loader functions - Design of an Absolute Loader A Simple Bootstrap Loader Machine dependent loader features - Relocation Program Linking Algorithm and
Data Structures for Linking Loader - Machine-independent loader features
Automatic Library Search Loader Options - Loader design options - Linkage
Editors Dynamic Linking Bootstrap Loaders - Implementation example - MSDOS
linker
PART-A:

1. Define loader.
Loading brings the object program into memory for execution. A loader is a system
program that performs the loading function. Many loaders also support relocation and linking.
2. What is a bootstrap Loader? (Nov/Dec 2005)
When a computer is turned on or restarted, a special type of absolute loader, called a
bootstrap loader is executed. This bootstrap loader in-turn loads the operating system. The
operating system then calls the loader to load the executable programs that is ready for
execution into memory and executes them.
3. What is the use of linkage editor? (Nov/Dec 2005)

Linkage editor can be used to replace old version of subroutine by new subroutine
without affecting the original version of all the other subroutine.

It simply prepares an object program for execution

Linkage editor can also be used to build packages old subroutines or other control
sections that are generally bused together. This can useful in dealing with subroutine
libraries that support high-level programming language.

4. What is the function of MS-DOS LINK? (May/June 2006)


MS-DOS LINK is a linkage editor that combines one or more object modules to
produce a complete executable program. This executable program has the file name extension
.Exe. MS-DOS Link can also combine the translated programs with other modules from
object code libraries.
5. Mention the use of FIXUPP records. (Nov/Dec 2006)
FIXUPP records are used to resolve external references, and to carry out address
modifications that are associated with relocation and grouping of segments within the
program. This is similar to the function performed by the SIC/XE modification records.

http://www.francisxavier.ac.in

Page 51

Francis Xavier Engineering College, Department of Computer Science and Engineering

6. What are the advantages of dynamic linking? (May/June 2007)


i)

Dynamic linking allows several programs to share one copy of subroutine or


library.

ii)

Dynamic linking avoids necessity of loading the entire library for each
execution.

iii)

In an object oriented system, dynamic linking is often used for reference of


software objects

iv)

Dynamic linking provides the ability to load the routines only when they are
needed.

7. What is the function of Pass2 of loader? (May/June 2007)


Pass2 of loader extracts the translated instructions and data from the object modules
and builds an image of the executable program. It performs the actual loading, relocation and
linking of the program.
8. What is the function of a linkage editor? (May/June 2006)
Linkage editor performs linking prior to load time and some relocation. Linkage
editor produces a linked version of the program often called a load module or an executable
image, which is written to a file or library for later execution.
9. Define the processes allocation, loading, linking, and relocation.
Allocation: Allocate space in memory for the programs.
Loading: Physically place the machine instructions and data into memory.
Linking: Combines two or more separate object programs and resolves symbolic
references between them.
Relocation: Modifies all address dependent locations in the object program so that it
can be loaded at the allocated space.
10. Define program relocation.
It is the task of adjusting programs so that they may be placed in arbitrary memory
locations. Relocation Modifies all address dependent locations in the object program so that it
can be loaded at the allocated space.
11. Define absolute loader.
Absolute loader is the simple loader, which simply accepts the machine instructions,
data and other information present in the object program and places them into memory at the
location prescribed by the assembler.

http://www.francisxavier.ac.in

Page 52

Francis Xavier Engineering College, Department of Computer Science and Engineering

12. What are program block and control section?

A program block is the term that refers to segments that are rearranged
within single object program unit.

Control section refers to segments that are translated into independent object
program units.

13. Define relative loader / relocating loader.


Loader that allow for program relocation is called a relative loader or relocating
loader. Relocation modifies all address dependent locations in the object program so that it
can be loaded at the allocated space.
14. What is the use of EXTDEF and EXTREF?
These are the two Assembler directives to handle external references.

EXTDEF (External definition):


It names symbols called external symbols that are defined in this section and

may be used by other section.

EXTREF (External reference):


It names symbols that are used in this control section that are defined

elsewhere.
15. What are the differences between linking loader, linkage editor and dynamic
linking?
Linkage editor:
Perform linking operations before the program is loaded for execution
Linking loaders:
Perform linking operations at load time
Dynamic Linking:
Perform linking at execution time.
16. What is meant by automatic library search?
Many linking loaders can automatically incorporate routines from a subprogram
library into program being loaded. (Eg: Standard system library). The subroutines being
called by the program that is being loaded are automatically fetched from library, linked with
main routine and loaded.
The programmer will only specify the subroutine name as external references in the
source program. This feature is termed as automatic library call or library search.

http://www.francisxavier.ac.in

Page 53

Francis Xavier Engineering College, Department of Computer Science and Engineering

17. Define load on call / dynamic loading. (May11)


Static linking generates an exact image at link time; almost no work is left for load
time where as dynamic linking performs linking at execution time. This type of function is
otherwise called as dynamic loading or load on call.
18. What is meant by define and refer records?
These are the two records used by the assembler to provide the information to the
loader to handle external symbols.
Define record:
Give information about the external symbols of the control section using EXTDEF.
Refer record:
Lists symbols that are used as external references by control section using EXTREF.
19. Define Linker.
Linker is a system program, which combines no. of object programs into one program
and supplies the information needed to allow references between them.
20. What is the difference between the following codes?
i) LDA

LENGTH

SUB

#1
LENGTH 1

ii) LDA
0033

LENGTH

WORD

(The value of LENGTH is 5)


Ans:
i) A is loaded with value 5 and subtracted by 1,thus giving the result 4.
ii) A is loaded with value defined in location 0032.
21. What are the data structures used by the linking loader?
External symbol table ESTAB
PROAGADDR (Program load address)
CSADDR (Control section address)
22. What is the use of ESTAB?
ESTAB is analogous to SYMTAB in assembler and it stores control section name,
external symbols used in this section, address of each external symbol and length of each
control section.

http://www.francisxavier.ac.in

Page 54

Francis Xavier Engineering College, Department of Computer Science and Engineering

23. What is a Bootstrap loader?


When the system is turned on or restarted, a special type of loader called a bootstrap
loader is executed. This Bootstrap loader in turn loads operating system. The operating
system then calls the loader to load the executable programs that is ready for execution into
memory and executes them.

24. What are the disadvantages of absolute loader or machine dependent loader?
i) The program has to specify the actual address (i.e.) at which the object code will be
loaded into memory.
ii) The starting address of the program should be known in advance. On larger and
more advanced machines this is not easy.
25. List outs the various design options of a loader.
Linking loader
Linkage editors
Dynamic Linking
Bootstrap loaders
26. What is a load map?
Many loaders include an option to print, which is called as a load map. The Load map
values are same as ESTAB.
27. Define PROADDR and CSADDR.

PROGADDR denotes the starting address at which the program is loaded.

CSADDR denotes the starting address assigned to the control section currently
being scanned by the loader.

28. Define MS-DOS Linker.


MS-DOS Linker is a linkage editor that combines one or more object modules to
produce a complete executable program.
29. Define dynamic linking.
A scheme that postpones the linking until execution time; a subroutine is loaded and
linked to the rest of the program when it is first called. This type of function is usually called
dynamic linking, dynamic loading, or load on call.
30. What are the differences between linking loader and linkage editor? (May 11)

A linking loader performs all linking and relocation operations including automatic
library search and loads the linked program directly into memory for immediate

http://www.francisxavier.ac.in

Page 55

Francis Xavier Engineering College, Department of Computer Science and Engineering

execution. Linking loader can be preferred when a program is to be executed several


times with each time reassembled.

A linkage editor stores the linked version of the program in a file or library for later
execution. At the time of execution, a relocatable loader is used to load the linked
program into memory. Linkage editor can be preferred when a program is to be
executed several times without being reassembled.

31. What is the purpose of relocation bits in object programs for relocatable loader?
On a machine like SIC that primarily uses direct addressing, most of the instructions
have to be modified during program relocation. Thus it is not possible to write modification
record for each instruction. Therefore we use the relocation bits in the text record which help
to identify the instructions that require modification.
32. What is the advantage of reference-number mechanism in the refer and
modification records?
The reference-number mechanism assigns a reference number to each external symbol
referred to in a control section. This reference number is used in modification records. The
advantage of this mechanism is that it avoids multiple searches of ESTAB for the same
symbol during the loading of a control section. An external reference symbol can be looked
up in ESTAB once for each control section that uses it. The values for code modification can
be obtained by simply indexing into an array of these values.
33. What are the different ways in which relocation is implemented by a relocation
loader in SIC & SIC/XE architecture?
In SIC architecture, since most of the instructions use direct addresses and need
modification during program relocation, relocation bits are used by the relocation loader.
Whereas, in SIC/XE architecture, since only a few instructions require modification as the
others use relative addresses modification records are used by the relocation loader.
34. List the disadvantages of absolute loader:
For an absolute loader, the address at which the program is to be loaded must be
specified beforehand. Also, it is not possible to load just the required subroutines alone. Thus
it is disadvantageous as it is inefficient in terms of both space and execution time.

http://www.francisxavier.ac.in

Page 56

Francis Xavier Engineering College, Department of Computer Science and Engineering

PART B:
1. With examples, explain the machine independent features of a loader. (Nov/Dec
2005)
Machine-independent Loader Features
Some loader features that are not directly related to machine architecture and design
are as follows:

a) Automatic Library Search and


b) Loader Options
a) 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.
The programmer does not need to take any action beyond mentioning the subroutine names as
external references
Solution

Enter the symbols from each Refer record into ESTAB

When the definition is encountered (Define record), the address is assigned

At the end of Pass 1, the symbols in ESTAB that remain undefined represent
unresolved external references

The loader searches the libraries specified (or standard) for undefined symbols or
subroutines

The library search process may be repeated

Since the subroutines fetched from a library may themselves contain external
references

Programmer defined subroutines have higher priority

The programmer can override the standard subroutines in the library by supplying
their own routines

Library structures

Assembled or compiled versions of the subroutines in a library can be structured


using a directory that gives the name of each routine and a pointer to its address
within the library

http://www.francisxavier.ac.in

Page 57

Francis Xavier Engineering College, Department of Computer Science and Engineering

b) 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 pf 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, and 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.

2. With diagrams, explain how loading and calling of a subroutine is done using
dynamic linking. (Nov/Dec 2005)

Dynamic Linking refers to postponing the linking function until execution


time.
o A subroutine is loaded and linked to the rest of the program when it is
first called (Dynamic linking, dynamic loading, or load on call)

Allow several executing programs to share one copy of a subroutine or library

In object-oriented system, it allows the implementation of the object and its


methods to be determined at the time the program is run

http://www.francisxavier.ac.in

Page 58

Francis Xavier Engineering College, Department of Computer Science and Engineering

Dynamic linking provides the ability to load the routines only when they are needed

Dynamically loaded must be called via an operating system service request


o dynamic loader is one part of the OS
o Instead of executing a JSUB instruction that refers to an external
symbol, the program makes a load-and-call service request to the OS

Load-and-call service
o OS examines its internal tables to determine whether or not the routine
is already loaded
o Routine is loaded from library
o Control is passed from OS to the called subroutine
o Subroutine is finished
o Calling to a subroutine which is already in memory

http://www.francisxavier.ac.in

Page 59

Francis Xavier Engineering College, Department of Computer Science and Engineering

Dynamic Linking: Binding of the name to an actual address is delayed from


load time until execution time.

3. Explain the design of relocating loader with an example. (May/June 2006)


Motivation

efficient sharing of the machine with larger memory and when several
independent programs are to be run together

support the use of subroutine libraries efficiently

Two methods for specifying relocation


a) modification record
b) relocation bit
i. each instruction is associated with one relocation bit
ii. these relocation bits in a Text record is gathered into bit masks
1. Modification record
col 1: M
col 2-7: relocation address
col 8-9: length (halfbyte)
col 10: flag (+/-)
col 11-17: segment name
E.g M^000007^05
Pass the address modification information to the relocatable loader
Beginning address of the program is to be added to a field that begins at addr ox000007
and is 5 bytes in length.
2. relocation bit

For simple machines

Relocation bit
o 0: no modification is necessary
o 1: modification is needed

Twelve-bit mask is used in each Text record

http://www.francisxavier.ac.in

Page 60

Francis Xavier Engineering College, Department of Computer Science and Engineering

o since each text record contains less than 12 words


o unused words are set to 0
o any value that is to be modified during relocation must coincide with
one of these 3-byte segments
4. Write short notes on (May/June 2006)
i)

Linkage editor

A linking loader performs

All linking and relocation operations

Automatic library search

Loads the linked program directly into memory for execution

A linkage editor

Produces a linked version of program (often called a load module or an


executable image), which is written to a file or library for later execution

A simple relocating loader can be used to load the linked version of


program into memory
o The loading can be accomplished in one pass with no external
symbol table required

Resolution of external references and library searching are only


performed once

In the linked version of programs


o All external references are resolved, and relocation is indicated
by some mechanism such as modification records or a bit mask

http://www.francisxavier.ac.in

Page 61

Francis Xavier Engineering College, Department of Computer Science and Engineering

External references is often retained in the linked program


o To allow subsequent relinking of the program to replace control
sections, modify external references, etc.

5. Explain the different machine dependent loader features in detail. (Nov/Dec


2006)
Machine-Dependent Loader Features
Absolute loader is simple and efficient, but the scheme has potential disadvantages
.One of the most disadvantage is the programmer has to specify the actual starting address,
from where the program to be loaded. This does not create difficulty, if one program to run,
but not for several programs. Further it is difficult to use subroutine libraries efficiently.
This needs the design and implementation of a more complex loader. The loader must
provide program relocation and linking, as well as simple loading functions
Relocation:
The concept of program relocation is, the execution of the object program using any
part of the available and sufficient memory. The object program is loaded into memory
wherever there is room for it. The actual starting address of the object program is not known
until load time. Relocation provides the efficient sharing of the machine with larger memory
and when several independent programs are to be run together. It also supports the use of
subroutine libraries efficiently. Loaders that allow for program relocation are called
relocating loaders or relative loaders.
Methods for specifying relocation

Use of modification record and,

Use of relocation bit, are the methods available for specifying


relocation.

Modification Record:
In the case of modification record, a modification record M is used in the object
program to specify any relocation. Modification records are used in complex machines and
are also called Relocation and Linkage Directory (RLD) specification. The format of the
modification record (M) is as follows. The object program with relocation by Modification
records is also shown here.
Modification record
col 1: M
col 2-7: relocation address
col 8-9: length (halfbyte)
http://www.francisxavier.ac.in

Page 62

Francis Xavier Engineering College, Department of Computer Science and Engineering

col 10: flag (+/-)


col 11-17: segment name
E.g M^000007^05
Pass the address modification information to the relocatable loader
Beginning address of the program is to be added to a field that begins at addr
ox000007 and is 5 bytes in length
Relocation Bit:

In the case of use of relocation bit, each instruction is associated with one relocation
bit and, these relocation bits in a Text record is gathered into bit masks.

The relocation bit method is used for simple machines.

Relocation bit is
o 0: no modification is necessary, and
o 1: modification is needed.

This is specified in the columns 10-12 of text record (T), the format of text record,
along with relocation bits is as follows.
Text record
col 1: T
col 2-7: starting address
col 8-9: length (byte)
col 10-12: relocation bits
col 13-72: object code

Twelve-bit mask is used in each Text record (col:10-12 relocation bits), since each
text record contains less than 12 words, unused words are set to 0, and, any value that
is to be modified during relocation must coincide with one of these 3-byte segments.

For absolute loader, there are no relocation bits column 10-69 contains object code.

The object program with relocation by bit mask is as shown below.

Observe FFC - means all ten words are to be modified and, E00 - means first three
records are to be modified.

Program Linking:
The Goal of program linking is to resolve the problems with external references
(EXTREF) and external definitions (EXTDEF) from different control sections.
EXTDEF (external definition) - The EXTDEF statement in a control section names
symbols, called external symbols, that are defined in this (present) control section and may be
http://www.francisxavier.ac.in

Page 63

Francis Xavier Engineering College, Department of Computer Science and Engineering

used by other sections. ex: EXTDEF BUFFER, BUFFEND, LENGTH EXTDEF LISTA,
ENDA
EXTREF (external reference) - The EXTREF statement names symbols used in this
(present) control section and are defined elsewhere.
ex: EXTREF RDREC, WRREC
EXTREF LISTB, ENDB, LISTC, ENDC
How to implement EXTDEF and EXTREF
The assembler must include information in the object program that will cause the loader
to insert proper values where they are required in the form of Define record (D) and, Refer
record(R).
Define record: The format of the Define record (D) along with examples is as shown
here.
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
Example records
D LISTA 000040 ENDA 000054
D LISTB 000060 ENDB 000070
Refer record: The format of the Refer record (R) along with examples is as shown here.
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
Example records
R LISTB ENDB LISTC ENDC
R LISTA ENDA LISTC ENDC
R LISTA ENDA LISTB ENDB
Here are the three programs named as PROGA, PROGB and PROGC, which are separately
assembled and each of which consists of a single control section. LISTA, ENDA in PROGA, LISTB,
ENDB in PROGB and LISTC, ENDC in PROGC are external definitions in each of the control
sections. Similarly LISTB, ENDB, LISTC, ENDC in PROGA, LISTA, ENDA, LISTC, ENDC in
PROGB, and LISTA, ENDA, LISTB, ENDB in PROGC, are external references.

6. Explain the algorithm and data structures for a linking loader.


Algorithm and Data structures for a Linking Loader The algorithm for a linking loader is
considerably more complicated than the absolute loader program, which is already given. The concept

http://www.francisxavier.ac.in

Page 64

Francis Xavier Engineering College, Department of Computer Science and Engineering

given in the program linking section is used for developing the algorithm for linking loader. The
modification records are used for relocation so that the linking and relocation functions are performed
using the same mechanism.
Linking Loader uses two-passes logic. ESTAB (external symbol table) is the main data structure
for a linking loader.
Pass 1: Assign addresses to all external symbols
Pass 2: Perform the actual loading, relocation, and linking
ESTAB - ESTAB for the example (refer three programs PROGA PROGB and PROGC) given is
as shown below. The ESTAB has four entries in it; they are name of the control section, the symbol
appearing in the control section, its address and length of the control section.
Control section
Progam A

Symbol

Address
4000
LISTA

4040

ENDA

4054

Program B

4063
LISTB

40C3

ENDB

40D3

Program C

40E2
LISTC
ENDC

Length
63

7F

51

4112
4124

Program Logic for Pass 1:


Pass 1 assign addresses to all external symbols. The variables & Data structures used during pass
1 are, PROGADDR (program load address) from OS, CSADDR (control section address), CSLTH
(control section length) and ESTAB. The pass 1 processes the Define Record. The algorithm for Pass
1 of Linking Loader is given below.

http://www.francisxavier.ac.in

Page 65

Francis Xavier Engineering College, Department of Computer Science and Engineering

Program Logic for Pass 2: Pass 2 of linking loader perform the actual loading, relocation, and
linking. It uses modification record and lookup the symbol in ESTAB to obtain its addres. Finally it
uses end record of a main program to obtain transfer address, which is a starting address needed for
the execution of the program. The pass 2 process Text record and Modification record

http://www.francisxavier.ac.in

Page 66

Francis Xavier Engineering College, Department of Computer Science and Engineering

7. Write notes in MS-DOS Linker. (Nov/Dec 2006)


MS-DOS Linker This explains some of the features of Microsoft MS-DOS linker, which is a
linker for Pentium and other x86 systems. Most MS-DOS compilers and assemblers (MASM)
produce object modules, and they are stored in .OBJ files. MS-DOS LINK is a linkage editor that
combines one or more object modules to produce a complete executable program - .EXE file; this file
is later executed for results.
The following table illustrates the typical MS-DOS object module

THEADER

similar to Header record in SIC/XE

MODEND

similar to End record in SIC/XE

TYPDEF

data type

PUBDEF

similar to Define record in SIC/XE

EXTDEF

similar to Reference record in SIC/XE

LNAMES

contain a list of segments and class names

SEGDEF

segment define

http://www.francisxavier.ac.in

Page 67

Francis Xavier Engineering College, Department of Computer Science and Engineering

GRPDEF

specify how segments are grouped

LEDATA

similar to Text Record in SIC/XE

LIDATA

specify repeated instructions

FIXUPP

similar to Modification record in SIC/XE

THEADR specifies the name of the object module. MODEND specifies the end of the
module. PUBDEF contains list of the external symbols (called public names). EXTDEF contains list
of external symbols referred in this module, but defined elsewhere. TYPDEF the data types are
defined here. SEGDEF describes segments in the object module ( includes name, length, and
alignment). GRPDEF includes how segments are combined into groups. LNAMES contains all
segment and class names. LEDATA contains translated instructions and data. LIDATA has above in
repeating pattern. Finally, FIXUPP is used to resolve external references.

Suppose that the SIC assembler language is changed to include a new form of the
RESB statement, such as
RESB nc
which reserves n bytes of memory and initializes all of these bytes to the character c.
For example
BUFFER

RESB 4096

This feature could be implemented by simply generating the required number of bytes
in Text records. However, this could lead to a large increase in the size of the object
program.
Pass 1

compute a starting address for each segment in the program

segment from different object modules that have the same segment
name and class are combined

segments with the same class, but different names are concatenated

a segments starting address is updated as these combinations and


concatenations are performed

Pass 2

extract the translated instructions from the object modules

build an image of the executable program in memory

write it to the executable (.EXE) file

http://www.francisxavier.ac.in

Page 68

Francis Xavier Engineering College, Department of Computer Science and Engineering

8. Write short notes on Bootstrap loader.

When a computer is first turned on or restarted, a special type of absolute loader


must be executed (stored in ROM on a PC).

The bootstrap loader loads the first program to be run by the computer usually
the operating system, from the boot disk (e.g., a hard disk or a floppy disk)

It then jumps to the just loaded program to execute it.

Normally, the just loaded program is very small (e.g., a disk sectors size, 512
bytes) and is a loader itself.

The just loaded loader will continue to load another larger loader and jump to it.

This process repeats another the entire large operating system is loaded.

The algorithm for the bootstrap loader is as follows

Begin
X=0x80 (the address of the next memory location to be loaded
Loop
AGETC (and convert it from the ASCII character code to the value of the
hexadecimal digit)
save the value in the high-order 4 bits of S
AGETC
combine the value to form one byte A (A+S)
store the value (in A) to the address in register X
XX+1
End

It uses a subroutine GETC, which is


GETC Aread one character
if A=0x04 then jump to 0x80
if A<48 then GETC
A A-48 (0x30)
if A<10 then return
A A-7 return

http://www.francisxavier.ac.in

Page 69

Francis Xavier Engineering College, Department of Computer Science and Engineering

9. Write short notes on absolute loader.


Characteristics of absolute loader:
o No linking and relocation needed
o Records in object program perform

Header record: Check the Header record for program name, starting
address, and length (available memory)

Text record: Bring the object program contained in the Text record to
the indicated address

End record: Transfer control to the address specified in the End record

Algorithm for absolute loader:


Begin
read Header record
verify program name and length
read first Text record
while record type is not E do
begin
{if object code is in character form, convert into internal representation}
move object code to specified location in memory
read next object program record
end
jump to address specified in End record
end
Advantage
o Simple and efficient
Disadvantage
o the need for programmer to specify the actual address difficult to use
subroutine libraries

http://www.francisxavier.ac.in

Page 70

Francis Xavier Engineering College, Department of Computer Science and Engineering

UNIT IV
MACRO PROCESSORS
Basic macro processor functions - Macro Definition and Expansion Macro
Processor Algorithm and data structures - Machine-independent macro processor
features - Concatenation of Macro Parameters Generation of Unique Labels
Conditional Macro Expansion Keyword Macro Parameters-Macro within MacroImplementation example - MASM Macro Processor ANSI C Macro language.
1. What is Macro processor?
A Macro processor is a system program that replaces each macro instruction with the
corresponding group of source language statements and the process is called expanding the
macros.
2. Define Macro definition and expansion.
A Macro definition starts with an assembler directive MACRO and ends with another
assembler directive MEND. The statements inside these directives are called a Macro body.
The structure of macro definition is
Macro name

MACRO
Stmt 1
Stmt 2
.
.
.
Stmt n
MEND

Parameters

Macro body

A Macro call leads to Macro expansion. A macro is called by specifying the macro
name in the mnemonic field of an assembly statement. The macro call has the syntax
<Macro name> [actual parameters]
During macro expansion the macro call statement is replaced by a sequence of
assembly statements given in the body of the macro with the arguments of the call substituted
for the parameters in the macro prototype.
3. List the statements present in a macro definition. (Nov/Dec 2005)
The structure of macro definition is
Macro name
MACRO
Parameters
Two assembler directives (MACRO and MEND) are used in macro
definitions.
http://www.francisxavier.ac.in

Page 71

Francis Xavier Engineering College, Department of Computer Science and Engineering

The first MACRO statement identifies the beginning of macro definition.

Symbol in the label field is the name of the macro.

Entries in the operand field identify the parameters of the macro instruction.

The MEND assembler directive marks the end of the macro definition.

4. Define Macro call / Macro invocation statement.


A Macro call leads to Macro expansion. A macro is called by specifying the
macro name in the mnemonic field of an assembly statement. The macro call has the
syntax
<Macro name> [actual parameters]
Eg: RDBUFF F1, BUFFER, LENGTH
During macro expansion the macro call statement is replaced by a sequence of
assembly statements given in the body of the macro with the arguments of the call
substituted for the parameters in the macro prototype.
5. Give the difference between macro invocation and subroutine call?
Macro:

The statements that form the expansion of the macro are generated each
time the macro is invoked.

The generated assembly code size is increased due to duplication of macro


statements during expansion.

Occupies more space in memory.

Sequential execution of statements

Subroutine:

Statements in a subroutine appears only once regardless of how many


times the subroutine is called

Occupies less space in memory.

Incurs more cost due to context switching

6. Compare one pass and two pass macro processor.


Two-pass macro processor
Pass1: process all macro definitions
Pass2: expand all macro invocation statements
Problem
Does not allow nested macro definitions
One-pass macro processor
Every macro must be defined before it is called
One-pass processor can alternate between macrodefinition and
macro expansion
Nested macro definitions are allowed

http://www.francisxavier.ac.in

Page 72

Francis Xavier Engineering College, Department of Computer Science and Engineering

7. What is a nested macro call? How is it expanded? (Nov/Dec 2005)


Macro call within another macro definition is called nested macro call. In the
expansion of the macro, the ARGTAB is filled with the macro parameters. If you
encounter a nested macro call, the nested macro is expanded by replacing the previous
contents of ARGTAB by new macro parameters. Whenever the nested macro
encounters a MEND stmt, all the macro expansions are abruptly terminated.
To overcome this, if the language supports recursion, the compiler will save
the return address otherwise use the stack to store the return address.
8. What is the necessity of a Macro? (May/June 2006)
A macro represents a commonly used group of statements in the source
programming language. Macroinstructions allow the programmer to write a shorthand
version of a program.
9. Write the significance of concatenation operator.
Macro processors allow parameters to be concatenated with other characters.
The macro processor uses concatenation operator -> to represent the symbol.
For eg, the following macro does the addition of 5 numbers
SUM MACRO &ID
LDA X&ID->1
LDA X&ID->2
LDA X&ID->3
LDA X&ID->4
LDA X&ID->5
MEND
10. How do macro processors avoid the problem of longer jumps spanning several
instructions?
To avoid the problem of longer jumps spanning several instructions,
macro processor allows the generation of unique labels within macros.
The labels within macro begins with $ and is replaced by $XX where XX is a
two character alphanumeric counter of the no of macro instructions expanded. For 3
invocations, the labels generated will be AA, AB, AC
11. What is meant by macro time variable?
A symbol that begin with & and that is not a macro parameter is assumed to
be macro time variable. Macro time variable often called set statement or set symbol
is used to store working values during the macro expansion.

http://www.francisxavier.ac.in

Page 73

Francis Xavier Engineering College, Department of Computer Science and Engineering

12. How does Macro affect program development? (May/June 2006)


The object program obtained from source program has the repeated programming
statement because macro substituted the code where it is called instead of dumping to
location.
13. Explain the term conditional macro expansion.
Macro processor allows the programmers to modify the sequence of
statements generated for a macro expansion depending on the arguments supplied in
the macro invocation statement. The IF-ELSE-ENDIF, macro time variable, SET
statement are used to do this facility. These statements are not related to assembler or
assembly language programming. For this reason it is called as conditional macro
expansion.
14. How are Macro defined? (Nov/Dec 2006)
Macros are defined using two assembler directives MACRO and MEND. The
statements inside these directives are called a Macro body. The structure of macro
definition is
Macro name

MACRO

Parameters

Stmt 1
Stmt 2
.
.
Macro body
.
Stmt n
MEND
15. What are positional parameters? How do they differ from keyword parameters?
(Nov/Dec 2006)
Positional parameters are the one that are supplied with MACRO directive in
the macro definition. Here the parameters and arguments (given in macro call) were
associated with each other according to their positions in the macro prototype and the
macro invocation statement.
Eg: Positional parameters:
i) STRG DATA1, DATA2, DATA3
ii) GENDER,, DIRECT ,, ,, 3
In the keyword parameter, the argument value is written with a key word that
names the corresponding parameter. Arguments may be in any order here.
Eg: Keyword parameters:
i) STRG a3=DATA1, a2=DATA2, a1=DATA3
http://www.francisxavier.ac.in

Page 74

Francis Xavier Engineering College, Department of Computer Science and Engineering

ii) GENDER TYPE= DIRECT, CHANNEL = 3


16. Name the data structures used by the macro processor.
There are three main data structures used by macro processors. They are

DEFTAB (Definition table)

NAMTAB

ARGTAB (Argument table)

17. What is the use of DEFTAB, NAMTAB & ARGTAB in a Macro processor?
(May/June 07)

DEFTAB: Macro definitions are stored in a definition table.

NAMTAB: serves as an index to DEFTAB. It contains pointers to the beginning and


end of the definition.

ARGTAB: During the expansion of the macro invocation, arguments are substituted
for the corresponding parameters.

18. What is a line-by-line macro processor?


Line by line macro processor is an alternate of macro processor of SIC
machine. Using this macro processor reads the source program statements and
performs all of its function. However the output lines are passed to the language
translator as they are generated instead of being written to an expanded source file.
19. What are preprocessors?
In the ANSI C language definitions and invocations of macros are handled by
a preprocessor. Its operation is similar to macro processor. The preprocessor also
performs a number of other functions.
20. Differentiate conditional IF and COMPR assembly instructions.

Conditional IF statements correspond to options that might have been selected by the
programmer in writing the source code.
COMPR statements test data values during program execution.

21. What are conditional assembly statements?


In MASM macro processor, the conditional macro statements are termed as
conditional assembly statements.
Eg:

ABSDIF

MACRO

OP1, OP2, SIZE

IFNB

<SIZE>

. ERR
ENDIF
ENDM

http://www.francisxavier.ac.in

Page 75

Francis Xavier Engineering College, Department of Computer Science and Engineering

22. What is the purpose of conditional compilation statement in ANSI C


preprocessor? (May/June 2007)
Conditional compilation statements can be used to be sure that a macro is defined
at least once.
Eg:

#ifndef Buffer-size
#define Buffer-size 1024
#endif

The #define will be processed only if Buffer-size has not already been defined.
PART B:
1. Explain in detail about the basic Macro Processor functions.

Macro Definition

Macro expansion

Algorithm

Data Structures

2. Discuss in detail about the Machine-independent macro processor features.


Concatenation of Macro parameters

Most macro processors allow parameters to be concatenated with other character


strings.

A program contains one series of variables named by the symbols XA1, XA2, XA3,
, another series named by XB1, XB2, XB3, , etc.

The body of the macro definition might contain a statement like


SUM Macro &ID
LDA X&ID1
LDA X&ID2
LDA X&ID3
LDA X&IDS

The beginning of the macro parameter is identified by the starting symbol &;
however, the end of the parameter is not marked.

The problem is that the end of the parameter is not marked. Thus X&ID1 may mean
X + ID + 1 or X + ID1.

In which the parameter &ID is concatenated after the character string X and before
the character string 1.

Most macro processors deal with this problem by providing a special concatenation
operator

http://www.francisxavier.ac.in

Page 76

Francis Xavier Engineering College, Department of Computer Science and Engineering

In SIC or SIC/XE, -> is used


SUM MACRO

&ID

LDA

X&ID 1

LDA

X&ID 2

LDA

X&ID 3

LDA

X&ID S

MEND
Generation of unique labels

It is in general not possible for the body of a macro instruction to contain labels of
usual kind. If such kind of macro is called twice problem of duplication occurs.

The figure below illustrates one technique for generating unique labels within a macro
expansion.

Labels used within the macro body begin with the special character $.

Each symbol beginning with $ has been modified by replacing $ with $AA.

http://www.francisxavier.ac.in

Page 77

Francis Xavier Engineering College, Department of Computer Science and Engineering

conditional macro Expansion

Keyword macro parameters

3. Explain about Macro Processor Design options

Recursive Macro Expansion

General purpose Macro Processors

Macro processing within Language Translators

4. Explain in detail about MASM Macro Processor

Conditional assembly statements

MASM macro

Conditional statements

5. State and explain the algorithm for one pass macro processor.
One-Pass Macro Processor:

A one-pass macro processor that alternate between macro definition and


macro expansion in a recursive way is able to handle recursive macro definition.
Restriction

The definition of a macro must appear in the source program before any
statements that invoke that macro.

This restriction does not create any real inconvenience.

The design considered is for one-pass assembler. The data structures required are:
http://www.francisxavier.ac.in

Page 78

Francis Xavier Engineering College, Department of Computer Science and Engineering

DEFTAB (Definition Table)

Stores the macro definition including macro prototype and macro body

Comment lines are omitted.

References to the macro instruction parameters are converted to a positional


notation for efficiency in substituting arguments.

Pointers to the beginning and the end of the macro definition (DEFTAB)

NAMTAB (Name Table)

Stores macro names

Serves as an index to DEFTAB

ARGTAB (Argument Table)

Stores the arguments according to their positions in the argument list.

As the macro is expanded the arguments from the Argument table are substituted
for the corresponding parameters in the macro body.

The figure below shows the different data structures described and their
relationship

http://www.francisxavier.ac.in

Page 79

Francis Xavier Engineering College, Department of Computer Science and Engineering

Algorithm:

http://www.francisxavier.ac.in

Page 80

Francis Xavier Engineering College, Department of Computer Science and Engineering

6. Explain the functions of two pass macro processor.


Two-pass macro processor
o Two-pass macro processor
o Pass1: process all macro definitions
o Pass2: expand all macro invocation statements
o Problem

Does not allow nested macro definitions

o Nested macro definitions


o The body of a macro contains definitions of other macros

Because all macros would have to be defined during the

first pass before any macro invocations were expanded

o Solution

One-pass macro processor

7. Explain in detail about ANSI C macro Language

Macro definitions with parenthesis


Nested macro invocation.
Macro expansion with parenthesis
Conditional compilation statements

http://www.francisxavier.ac.in

Page 81

Francis Xavier Engineering College, Department of Computer Science and Engineering

UNIT V:
SYSTEM SOFTWARE TOOLS
Text editors - Overview of the Editing Process - User Interface Editor Structure. Interactive debugging systems - Debugging functions and capabilities Relationship
withother parts of the system User-Interface Criteria.
PART A:
1. What is an interactive editor?
An interactive editor is a computer program that allows a user to create and
revise a target document.
2. What is filtering?
Traveling specifies where the area of interest is, filtering controls the selection
of what is to be viewed and manipulated there. Filtering extracts the relevant subset of
target document at the point of interest, such as the next screen full of text or the next
statement.
3. What is the purpose of formatting?
Formatting determines how the result of the filtering will be seen as a visible
representation on a display screen or other device.
4. What is a placeholder? (Nov/Dec 2005)
A placeholder is a term, sign or some other thing which generally stands in the place
of content which is unknown or not identified. The placeholder concept is represented by free
variables and bound variables.
5. What is a command language processor?
The command language processor accepts input from the users input device and
analyses the tokens and syntactic structures of the commands. They may also invoke
semantic routines directly. In a text editor they perform the functions such as editing and
viewing.
6. What are the roles of a dialog manager? (Nov/Dec 2005)

Sentence generation from concept representation concerning the dialog


context.
Topic identification for spoken dialog understanding
The dialog manager in the interface has roles of determining the surface
sentence of the output message taking account of the dialog context.
7. What is the important of user interface? (May/June 2006)

It is interface where great deal of information can be displayed


Information can be changed easily and quickly
With menus and full screen editors, the user has far less information to enter
and remember
8. What is a window?
The viewing buffer is passed to the display component which produces a
display by mapping the buffer to a rectangular subset of the screen usually called a
window.
http://www.francisxavier.ac.in

Page 82

Francis Xavier Engineering College, Department of Computer Science and Engineering

9. What are the various functions of a debugger? (May/June 2006)


Break points
Gaits
Tracing
Trace back
10. What is a terminal control database?
Instead of having explicitly terminal control sequences in display routine, these
editors simply call terminal independent library routines. These library routines use the
terminal control database to look up the appropriate control sequences for a particular
terminal.
11. What is an interactive debugging system?
An interactive debugging system provides programmers with facilities that aid
in testing and debugging of programs.
12. What are editor paging routines?
Editor page routines are one that read one or more logical portions of a document into
memory as needed. Such portions are termed as pages.
13. Write the tasks accomplished by the document editing process. (Nov/Dec 2006)
There are four tasks.
Select the part of the target document to be viewed and manipulated
Determine how to format this view on-line and how to display it.
Specify and execute operations that modify the target document
Update the view approximately
14. What are gaits?
The programmer can define conditional expressions that are continually
evaluated during the debugging session. Program execution is suspended if any of
these conditions become true. Given a good graphical representation of the program
process, it may be even useful to run the program at various speeds, called gaits.
15. What do you mean by tracing? (Nov/Dec 2006)
Tracing is a function provided by a debugging system that can be used to track the
flow of execution at different levels of details, procedures, branch, individual instructions
and so on.
16. What are the input devices and how are they divided?
Input devices are used to enter elements of text being edited, to enter commands
to designate editable elements.
Input devices are divided into three categories.
Text devices
Button devices
Locator devices
Voice input devices
17. What is the purpose of voice input device?
It is a type of input device. It translates spoken words to their textual equivalents.

http://www.francisxavier.ac.in

Page 83

Francis Xavier Engineering College, Department of Computer Science and Engineering

18. What are the main features that highlight the relationship of the debugger with
other parts of the system?
A debugger
Must communicate and co-operate with other parts of OS such as interactive
sub systems
Must support debugging at any instance during the runtime
Must be consistent with the security and integrity of the system
Must be subject to normal authorization mechanisms and leave audit trials
Must co-ordinate its activities with the present generation compilers and
interpreters and as well as future language compilers
19. What must be the features of command language?
It must be flexible, clear, logical and simple syntax
Must contain very few parameters
Must contain default for parameters
20. How the mapping of view buffer to a window is done? (May/June 2006)
The mapping of view buffer to a window is done with two components.
They are

Viewing component formulates as ideal view


Display component maps to the physical output device.
PART B:

1. With neat block diagram, explain the different components of an editor


structure.

(Nov/Dec 2005)
Editing
component

Editing
buffer

Editing
filter
Main
memory

Traveling
component
input

Command
language
processor

Viewing
component

Viewing
buffer

Viewing
filter

Paging
Routines

Output
devices

Display
component

File
system

Control
Data

Typical Editor Structure

http://www.francisxavier.ac.in

Page 84

Francis Xavier Engineering College, Department of Computer Science and Engineering

The command Language Processor


Editing Component
Traveling Component
Viewing Component
Display Component
Editing Filter
Editing Buffer
Viewing Filter
Viewing Buffer
2. Discuss about an interactive debugging system. (Nov/Dec 2005)
Debugging Functions and Capabilities
Relationship with Other Parts of the System
3. Explain the various types of user interfaces. (May/June 2006)

The Screen-editor
line editors
Input Devices :
a. Text devices
b. Button devices
c. Locator devices
Output devices
Interaction Language
a. The typing oriented or text command-oriented method
b. Menu oriented interfaces
c. Function key interfaces :

4. Discuss the nature of the user interface for an interactive debugger. (May/June
2006)
Execution sequencing: It is the observation and control of the flow of program execution.
For example, the program may be halted after a fixed number of instructions are executed.
Breakpoints The programmer may define break points which cause execution to be
suspended, when a specified point in the program is reached. After execution is suspended,
the debugging command is used to analyze the progress of the program and to diagnose errors
detected. Execution of the program can then be removed.
Conditional Expressions Programmers can define some conditional expressions, evaluated
during the debugging session, program execution is suspended, when conditions are met,
analysis is made, later execution is resumed
Gaits- Given a good graphical representation of program progress may even be useful in
running the program in various speeds called gaits. A Debugging system should also provide
functions such as tracing and traceback.
Tracing can be used to track the flow of execution logic and data modifications. The control
flow can be traced at different levels of detail procedure, branch, individual instruction, and
so on

http://www.francisxavier.ac.in

Page 85

Francis Xavier Engineering College, Department of Computer Science and Engineering

Traceback can show the path by which the current statement in the program was reached. It
can also show which statements have modified a given variable or parameter. The statements
are displayed rather than as hexadecimal displacements.
Program-display Capabilities It is also important for a debugging system to have good
program display capabilities. It must be possible to display the program being debugged,
complete with statement numbers.
Multilingual Capability A debugging system should consider the language in which the
program being debugged is written. Most user environments and many applications systems
involve the use of different programming languages. A single debugging tool should be
available to multilingual situations.
Context Effects The context being used has many different effects on the debugging
interaction.
For example.
The statements are different depending on the language
COBOL - MOVE 6.5 TO X
FORTRAN - X = 6.5
Likewise conditional statements should use the notation of the source language
COBOL - IF A NOT EQUAL TO B
FORTRAN - IF (A .NE. B)
Similar differences exist with respect to the form of statement labels, keywords and so on.
Display of source code: The language translator may provide the source code or source
listing tagged in some standard way so that the debugger has a uniform method of navigating
about it.
Optimization: It is also important that a debugging system be able to deal with optimized
code. Many optimizations involve the rearrangement of segments of code in the program.

For eg.
- invariant expressions can be removed from loop
- separate loops can be combined into a single loop
- redundant expression may be eliminated
- elimination of unnecessary branch instructions
The debugging of optimized code requires a substantial amount of cooperation from
the optimizing compiler.
5. Explain in detail about the editing process.
An interactive editor is a computer program that allows a user to create and revise a
target document. The term document includes objects such as computer
programs,texts,equations,tables,diagrams,line arts and photographs-anything that one
http://www.francisxavier.ac.in

Page 86

Francis Xavier Engineering College, Department of Computer Science and Engineering

might find on a printed page.Text editor is one in which the primary elements being
edited are character strings of the target text.
The document editing process is an interactive user-computer dialogue designed to
accomplish four task:
1) Select the part of the target document to be viewed and manipulated
2) Determine how to format this view on-line and how to display it.
3) Specify and execute operations that modify the target document.
4) Update the view appropriately.
Traveling Selection of the part of the document to be viewed and edited. It involves
first

traveling through the document to locate the area of interest such as next

screenful,bottom,and find patternTraveling specifies where the area of interest is;


Filtering : The selection of what is to be viewed and manipulated is controlled by
filtering.Filtering extracts the relevant subset of the target document at the point of
interest,such as next screenful of text or next statement.
Formatting : Formatting then determines how the result of filtering will be seen as a
visible representation(the view) on a display screen or other device.
Editing : In the actual editing phase ,the target document is created or altered with a set
of operations such as insert,delete,replace,move or copy.Manuscript oriented editors
operate

on

elements

such

as

single

characters,words,lines,sentences,and

paragraphs;Program-oriented editors operates on elements such as identifiers,key words


and statements

http://www.francisxavier.ac.in

Page 87

S-ar putea să vă placă și