[go: up one dir, main page]

0% found this document useful (0 votes)
13K views43 pages

Answer Model Cs303 Systemsoftware November2018

The document discusses system software concepts related to assemblers. It provides examples of: 1) The three blocks (default, CDATA, CBLKS) used in program blocks and how the assembler rearranges code segments. 2) The implementation of the Microsoft Macro Assembler (MASM), including its segments, assume directive, and ends directive. 3) The format of a modification record with an example.

Uploaded by

Nova Dileep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13K views43 pages

Answer Model Cs303 Systemsoftware November2018

The document discusses system software concepts related to assemblers. It provides examples of: 1) The three blocks (default, CDATA, CBLKS) used in program blocks and how the assembler rearranges code segments. 2) The implementation of the Microsoft Macro Assembler (MASM), including its segments, assume directive, and ends directive. 3) The format of a modification record with an example.

Uploaded by

Nova Dileep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

CS 303: SYSTEM SOFTWARE

Module 3 & 4 Question Bank with Answers

1. Identify the three blocks used in Program Blocks.

Program blocks Refer to segments of code that are rearranged within a single object
program unit. Assembler directive USE is used to denote Program blocks.
o USE [blockname]
 If no USE statements are included, the entire program belongs to this single block
 At the beginning, statements are assumed to be part of the unnamed (default) block
 If no USE statements are included, the entire program belongs to this single block
 Each program block may actually contain several separate segments of the source
program
 Three blocks are used
 default: executable instructions
 CDATA: all data areas that are less in length
 CBLKS: all data areas that consists of larger blocks of memory
Assembler rearranges these segments to gather together the pieces of each block and
assign address

2. Discuss the implementation of MASM Assembler

The Microsoft Macro Assembler (MASM) is an assembler for the x86 family of
microprocessors, originally produced Microsoft MS-DOS operating system. The 8086
family of processors have a set of 16-bit registers. They are AX,BX,CX,DX (General
purpose registers) segment registers like ,SS.CS.DS.ES and pointer registers like SP,BP and
Index registers like DI and SI etc…MASM assembler language program is written as a
collection of segments. Each segment is defined as belonging to a particular class .Common
segments are
 CODE Segment
 DATA Segment
 CONST Segment
 STACK Segment

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


Every program written only in MASM has one main module, where program execution
begins. Main module can contain code, data, or stack segments defined with all of the
simplified segment directives. Any additional modules should contain only code and data
segments. Every module that uses simplified segments must begin with the .MODEL
directive. When you specify a segment in your program, not only must you tell the CPU that
a segment is a data segment, but you must also tell the assembler where and when that
segment is a data (or code/stack/extra/F/G) segment. The assume directive provides this
information to the assembler.

The assume directive takes the following form:


ASSUME ES:DATASEG2
tells the assembler to assume that register ES indicates the segment DATASEG2.
ASSUME tells MASM the contents of a segment register, the programmer must provide
instructions to load this register when the program is executed.
ASSUME DS : DATA
tells the assembler that for any program instruction which refers to the data segment ,it
should use the logical segment called DATA.
ENDS-End Segment: This directive is used with the name of the segment to indicate the end
of that logical segment.
Ex: CODE SEGMENT : Start of logical segment containing code
CODE ENDS : End of the segment named CODE.

Near jump

A jump to an instruction within the current code segment (the segment currently
pointed to by the CS register), sometimes referred to as an intrasegment jump.Near
jump occupies 2 or 3 bytes.
Short jump
A near jump where the jump range is limited to -128 to +127 from the current EIP
value.
Far jump

A jump to an instruction located in a different segment than the current code segment,
sometimes referred to as an intersegment jump. Far jump occupies 5 bytes. Consider a
jump instruction
JMP TARGET
If the definition of the label TARGET occurs in the program before the JMP
instruction, the assembler can tell whether this is a near jump or a far jump, If this is a
forward reference to TARGET the assembler does not know how many bytes to

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


reserve for instruction. By default MASM assumes that a forward jump is a near
jump. If the jump address is within 128 bytes of the current instruction, the
programmer can specify the shorter (2 byte )near jump by writing
JMP SHORT TARGET
If JMP to TARGET is a far jump and the programmer does not specify FAR PTR a
problem occurs.
Segments in an MASM source program can be written in more than one part .If a
SEGMENT directive specifies the same name as a previously defined segment it is
considered to be a continuation of that segment.
External References and External Definition in MASM is handled using the directive
EXTRN and PUBLIC .PUBLIC has same function as EXTDEF in SIC/XE and
EXTRN has same function as EXTREF in SIC/XE.

3. Assess the format of Modification record with example

Modification record


Col. 1 M

Col. 2-7 Starting address of the field to be modified (hexiadecimal)

Col. 8-9 Length of the field to be modified, in half-bytes (hexadeccimal)

Col.11-16 External symbol whose value is to be added to or subtracted from
the indicated field
 Note: control section name is automatically an external symbol, i.e. it is
available for use in Modification records.
Example

 M00000405+RDREC
 M00000705+COPY

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


4. Differentiate the define and refer record types used in Assemblers with suitable
examples.

The assembler must include information in the object program that will cause the loader to
insert proper values where they are required

Define record

 Col. 1 D
 Col. 2-7 Name of external symbol defined in this control section
 Col. 8-13 Relative address within this control section (hexadeccimal)
 Col.14-73 Repeat information in Col. 2-13 for other external symbols
Refer record

 Col. 1 D
 Col. 2-7 Name of external symbol referred to in this control section
Col. 8-73 Name of other external reference symbols

5. Compare Program Blocks and Control Sections

Program blocks
 Program blocks Refer to segments of code that are rearranged within a single object
program unit. Assembler directive USE is used to denote Program blocks.
o USE [blockname]
 If no USE statements are included, the entire program belongs to this single block
 At the beginning, statements are assumed to be part of the unnamed (default) block
 If no USE statements are included, the entire program belongs to this single block
 Each program block may actually contain several separate segments of the source
program
 Three blocks are used
 default: executable instructions
 CDATA: all data areas that are less in length
 CBLKS: all data areas that consists of larger blocks of memory
Assembler rearranges these segments to gather together the pieces of each block and
assign address

 Separate the program into blocks in a particular order


 Large buffer area is moved to the end of the object program
 Program readability is better if data areas are placed in the source program close to the
statements that reference them.

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


Control sections
 can be loaded and relocated independently of the others
 are most often used for subroutines or other logical subdivisions of a program
 the programmer can assemble, load, and manipulate each of these control
sections separately
 because of this, there should be some means for linking control sections
together
Assembler Directive : CSECT

 secname CSECT
Instructions in one control section may need to refer to instructions or data located in
another section

1.External definition

 EXTDEF name [, name]


 EXTDEF names symbols that are defined in this control section and may be
used by other sections
Ex: EXTDEF BUFFER, BUFEND, LENGTH

2. External reference

 EXTREF name [,name]

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


 EXTREF names symbols that are used in this control section and are defined
elsewhere
Ex: EXTREF RDREC, WRREC

6. Describe the working of ORG Assembler Directive

ORG Directive

This can be used to indirectly assign values to symbols.


When this statement is encountered during assembly of a program, the assembler
resets its location counter to the specified value.
The ORG statement will thus affect the values of all labels defined until the next ORG.
Normally when an ORG without specified value is encounter, the previously saved
location counter value is restored,
Suppose that we have the following data structure and want to access its fields:

SYMBOL: 6 bytes
VALUE: 3 bytes (one word)
FLAGS: 2 bytes
We want to refer to every field of each entry
If EQU statements are used

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


For EQU and ORG, all symbols used on the right hand side of the statement must have
been defined previously in the program.
This is because in the two-pass assembler, we require that all symbols must be defined
in pass 1.

7. How Forward references are handled in one pass assembler?


One-pass assemblers are used when

a. it is necessary or desirable to avoid a second pass over the source


program
b. the external storage for the intermediate file between two passes is
slow or is inconvenient to use
Main problem: forward references to both data and instructions

One simple way to eliminate this problem: require that all areas be defined
before they are referenced.( will be placing all storage reservation statements
before they are referenced.)

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


here all storage reservations are given at the starting .

8. List out the uses of EXTDEF and EXTREF


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 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
9. Write the Subroutine in SIC to read record into Buffer

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


10. Describe the Literal and immediate operand.

• Immediate addressing
– The operand value is assembled as part of the machine instruction.
e.g. 55 0020 LDA #3 010003

• Literal
– The assembler generates the specified value as a constant at some other
memory location.
– The address of this generated constant is used as the target address for the
machine instruction.
– The effect of using a literal is exactly the same as if the programming had
defined the constant explicitly and used the label assigned to the constant as
the instruction operand.
e.g. 45 001A ENDFIL LDA =C’EOF’ 032010

Literal Pool

• All of 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.
• Sometimes, it is desirable to place literals into a pool at some other location in the
object program.
– LTORG directive is introduced for this purpose.
– When the assembler encounters a LTORG, it creates a pool that contains all of
the literals used since the previous LTORG.

11. Explain with suitable examples, how the different expressions are handled
during assembling

Expressions consist of

 Operator
 +,-,*,/ (division is usually defined to produce an integer result)
 Individual terms
 Constants
 User-defined symbols
 Special terms, e.g., *, the current value of LOCCTR
Regarding program relocation, a symbol’s value can be classified as

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


Relative

 Its value is relative to the beginning of the object program, and thus
its value is dependent of program location.
 E.g., labels or reference to location counter (*)
Absolute

 Its value is independent of program location


 E.g., a constant.
None of the relative terms may enter into a multiplication or division operation

 Errors:
o BUFEND+BUFFER
o 100-BUFFER
o 3*BUFFER
The type of an expression keep track of the types of all symbols defined in the program.
Therefore, we need a flag in the symbol table to indicate type of value (absolute or relative)
in addition to the value itself.

12. Summarize the features of Symbol Defining Statements used in assemblers.

EQU directive is used to define a symbol’s value.

The value assigned to a symbol may be a constant, or any expression involving


constants and previously defined symbols.

E.g., +LDT #4096 can be changed to :


MAXLEN EQU 4096
+LDT #MAXLEN
• When the assembler encounters the EQU statement, it enters MAXLEN into
SYMTAB (with value 4096).

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


• During assembly of the LDT instruction, the assembler searches SYMTAB for the
symbol MAXLEN, using its value as the operand in the instruction.
 Define mnemonic names for registers

ex: RMO A,X

13. Compute the considerations to be done by the assembler while using literals in
operands independent of Assemblers.

Duplicate literals are the same literal used in more than one place in the program

• For duplicate literals, we should store only one copy of the specified data value to
save space.
• Most assembler can recognize duplicate literals.
– E.g., There are two uses of =X’05’ on lines 215 and 230 respectively.
– However, just one copy is generated on line 1076.

A literal table LITTAB is needed for literal processing. For each literal used, the table
contains:

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


 Literal name.
 The operand value and length.
 The address assigned to the operand when it is placed in a literal pool.
 LITTAB is often organized as a hash table, using the literal name or value as the key

Implementation of Literals

Pass 1

 Build LITTAB with literal name, operand value and length, leaving the address
unassigned
 When LTORG or END statement is encountered, assign an address to each literal not
yet assigned an address
 The location counter is updated to reflect the number of bytes occupied by each literal
Pass 2

 Search LITTAB for each literal operand encountered


 Generate data values using BYTE or WORD statements
 Generate Modification record for literals that represent an address
in the program

14. Write the SIC/XE Program explaining the input and output operations using
two subroutines to read record into buffer and to write record from buffer.
Comment every statement with explanation for the same.

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


15. Design the Bootstrap loader for SIC /XE.
A Simple Bootstrap Loader

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


16. Discuss the design options of Multi pass Assemblers illustrating the symbol table
entry at each level of passing

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


A multi-pass assembler that can make as many passes as are needed to process the
definitions of symbols.Only the portions of the program that involve forward references in
symbol definition are saved for multi-pass reading.

• For a two pass assembler, forward references in symbol definition are not allowed:
ALPHA EQU BETA

BETA EQU DELTA

DELTA RESW 1

• Reason: symbol definition must be completed in pass 1.


• Motivation for using a multi-pass assembler
– DELTA can be defined in pass 1
– BETA can be defined in pass 2
– ALPHA can be defined in pass 3
• A symbol table is used
– to store symbol definitions that involve forward references
– to indicate which symbols are dependant on the values of others
– to facilitate symbol evaluation
• For a forward reference in symbol definition, we store in the SYMTAB:
– the symbol name
– the defining expression
– the number of undefined symbols in the defining expression
– the undefined symbol (marked with a flag *) associated with a list of
symbols depend on this undefined symbol.
• When a symbol is defined, we can recursively evaluate the symbol expressions
depending on the newly defined symbol.

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


After Pass 1

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC
17. Explain the algorithm for an absolute loader

The operation of absolute loader is very simple. The object code is loaded to
specified locations in the memory. At the end the loader jumps to the specified
address to begin execution of the loaded program. The algorithm for this type of
loader is given here. The object program and, the object program loaded into
memory by the absolute loader are also shown. Each byte of assembled code is
given using its hexadecimal representation in character form. Easy to read by human
beings. Each byte of object code is stored as a single byte. Most machine store object
programs in a binary form, and we must be sure that our file and device conventions
do not cause some of the program bytes to be interpreted as control
characters.

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


18. Analyse the Program linking operations in Machine Dependent Loader features.

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 used by other sections.

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


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

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


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 areexternal 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. These sample programs given here are used to illustrate linking and
relocation.
0000 PROGA START 0
EXTDE LISTA, ENDA
F LISTB, ENDB, LISTC, ENDC
EXTRE
F
………..
……….
0020 REF1 LDA LISTA 03201D
0023 REF2 +LDT LISTB+4 77100004
0027 REF3 LDX #ENDA-LISTA 050014
.
.
0040 LISTA EQU *

0054 ENDA EQU *


0054 REF4 WORD ENDA-LISTA+LISTC 000014
0057 REF5 WORD ENDC-LISTC-10 FFFFF6
005A REF6 WORD ENDC-LISTC+LISTA-1 00003F
005D REF7 WORD ENDA-LISTA-(ENDB-LISTB)
000014
0060 REF8 WORD LISTB-LISTA FFFFC0
END REF1

CONTROL SECTION- PROGB

0000 PROGB START 0 External


EXTDE LISTB, ENDB definition
F LISTA, ENDA, LISTC, ENDC and
EXTREF References
………..
……….

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


0036 REF1 +LDA LISTA 03100000
003A REF2 LDT LISTB+4 772027
003D REF3 +LDX #ENDA-LISTA 05100000
.
.
0060 LISTB EQU *

0070 ENDB EQU *


0070 REF4 WORD ENDA-LISTA+LISTC 000000
0073 REF5 WORD ENDC-LISTC-10 FFFFF6
0076 REF6 WORD ENDC-LISTC+LISTA-1 FFFFFF
0079 REF7 WORD ENDA-LISTA-(ENDB- FFFFF0
LISTB)
007C REF8 WORD LISTB-LISTA 000060
END

0000 PROGC START 0 External


EXTDE LISTC, ENDC definition
F LISTA, ENDA, LISTB, ENDB and
EXTRE Reference
F s
………..
………..
0018 REF1 +LDA LISTA 03100000
001C REF2 +LDT LISTB+4 77100004
0020 REF3 +LDX #ENDA-LISTA 05100000
.
.
0030 LISTC EQU *

0042 ENDC EQU *


0042 REF4 WORD ENDA-LISTA+LISTC 000030
0045 REF5 WORD ENDC-LISTC-10 000008
0045 REF6 WORD ENDC-LISTC+LISTA-1 000011
004B REF7 WORD ENDA-LISTA-(ENDB- 000000
LISTB)
004E REF8 WORD LISTB-LISTA 000000
END

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC
Two Passes Logic
Pass 1: assign addresses to all external symbols
Pass 2: perform the actual loading, relocation, and linking
Consider the case in which the program is loaded in the memory location 4000
.Then the control section PROGA is loaded in 4000 and PROGB is loaded at
4063(4000+ 63(length of program A))

Load address for control sections


» PROGA 004000 63
» PROGB 004063 7F
» PROGC 0040E2 51

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


Load address for symbols
» LISTA: PROGA+0040=4040
» LISTB: PROGB+0060=40C3
» LISTC: PROGC+0030=4112
REF4 in PROGA
» ENDA-LISTA+LISTC=14+4112=4126
» T0000540F000014FFFFF600003F000014FFFFC0
» M00005406+LISTC
»

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


After these control sections are linked, relocated, and loaded
19. Judge the concept of relocation used in Loader independent of Machine.
The relocation bit method is used for simple machines.
This is specified in the columns 10 -12 of text record (T), the format of text record,
along with relocation bits is as follows
Relocation bit
0: no modification is necessary
1: modification is needed
Twelve-bit mask is used in each Text record since each text record contains
less than 12 words unused words are set to 0

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


20. Evaluate the PASS 2 Algorithm of a two pass SIC assembler.

The Algorithm for Pass 2:

Begin

read 1st 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 1st Text record

while OPCODE != ‘END’ do

begin

if this is not comment line then

begin

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


search OPTAB for OPCODE

if found then

begin

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

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


if object code doesn’t fit into current Text record then

begin

Write text record to object code

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.

End {Pass 2}

Explanation – PASS II Algorithm

 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 1).

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


 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.
Design and Implementation Issues

Some of the features in the program depend on the architecture of the machine. If the
program is for SIC machine, then we have only limited instruction formats and hence
limited addressing modes. We have only single operand instructions. The operand is
always a memory reference. Anything to be fetched from memory requires more time.
Hence the improved version of SIC/XE machine provides more instruction formats and
hence more addressing modes. The moment we change the machine architecture the
availability of number of instruction formats and the addressing modes changes.
Therefore the design usually requires considering two things: Machine-dependent
features and Machine-independent features

21. Briefly explain the Machine independent Assembler features: (i)Program Blocks
and (ii )Use of control sections in detail with a programming example .Discuss
the generation of objet code in both the cases

1. Program blocks

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


 Program blocks Refer to segments of code that are rearranged within a single
object program unit. Assembler directive USE is used to denote Program blocks.
o USE [blockname]
 If no USE statements are included, the entire program belongs to this single block
 At the beginning, statements are assumed to be part of the unnamed (default)
block
 If no USE statements are included, the entire program belongs to this single block
 Each program block may actually contain several separate segments of the source
program
 Three blocks are used
 default: executable instructions
 CDATA: all data areas that are less in length
 CBLKS: all data areas that consists of larger blocks of memory
Assembler rearranges these segments to gather together the pieces of each block and
assign address

 Separate the program into blocks in a particular order


 Large buffer area is moved to the end of the object program
 Program readability is better if data areas are placed in the source program close to
the statements that reference them.

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC
 It is not necessary to physically rearrange the generated code in the object
program
 The assembler just simply insert the proper load address in each Text record.
 The loader will load these codes into correct places

2. Control sections
 can be loaded and relocated independently of the others
 are most often used for subroutines or other logical subdivisions of a
program
 the programmer can assemble, load, and manipulate each of these control
sections separately
 because of this, there should be some means for linking control sections
together
Assembler Directive : CSECT

 secname CSECT

Instructions in one control section may need to refer to instructions or data located in
another section

1.External definition

 EXTDEF name [, name]


 EXTDEF names symbols that are defined in this control section and may be
used by other sections
Ex: EXTDEF BUFFER, BUFEND, LENGTH

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC



2. External reference

 EXTREF name [,name]


 EXTREF names symbols that are used in this control section and are defined
elsewhere
Ex: EXTREF RDREC, WRREC

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


The assembler must include information in the object program that will cause the
loader to insert proper values where they are required

Define record

 Col. 1 D
 Col. 2-7 Name of external symbol defined in this control section
 Col. 8-13 Relative address within this control section (hexadeccimal)
 Col.14-73 Repeat information in Col. 2-13 for other external symbols
Refer record

 Col. 1 D
 Col. 2-7 Name of external symbol referred to in this control section
 Col. 8-73 Name of other external reference symbols
Modification record

 Col. 1 M
 Col. 2-7 Starting address of the field to be modified (hexiadecimal)
 Col. 8-9 Length of the field to be modified, in half-bytes
(hexadeccimal)
 Col.11-16 External symbol whose value is to be added to or subtracted
from the indicated field
 Note: control section name is automatically an external symbol, i.e. it is
available for use in Modification records.

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


Example

 M00000405+RDREC
 M00000705+COPY

22. Elaborate the design options of One pass Assemblers with suitable examples.
One-pass assemblers are used when

c. it is necessary or desirable to avoid a second pass over the source


program
d. the external storage for the intermediate file between two passes is
slow or is inconvenient to use
Main problem: forward references to both data and instructions

One simple way to eliminate this problem: require that all areas be defined
before they are referenced.( will be placing all storage reservation statements
before they are referenced.)

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


here all storage reservations are given at the starting .

Types of one-pass assembler

 Type 1: Load-and-go
‒ Produces object code directly in memory for immediate execution
 Type 2:
‒ Produces usual kind of object code for later execution

Type 1:Load-and-go

• Load-and-go assembler generates their object code in memory for immediate


execution.
• For a load-and-go assembler, the actual address must be known at assembly time
• No object program is written out, no loader is needed.
Assembler operations:

– 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

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


– Scans the reference list and inserts the address when the definition for the
symbol is encountered.
– Reports the error if there are still SYMTAB entries indicated undefined
symbols at the end of the program
– Search SYMTAB for the symbol named in the END statement and jumps to
this location to begin execution if there is no error

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


Type 2: Assembler

 Will produce object code


 Assembler operations:
 Instruction referencing are written into object file as a Text record, even
with incorrect addresses
• 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.
• When loaded, the incorrect address 0 will be updated by the latter Text record
containing the symbol definition.

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


23. Analyze the Algorithm and Data structures for a linking loader

Linking Loader uses two-passes logic. ESTAB (external symbol table) is the main data
structure for a linking loader. Input is a set of object programs, i.e., control sections.A linking
loader usually makes two passes over its input, just as an assembler does

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 Symbol Address Length


Progam A 4000 63
CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC
LISTA 4040
ENDA 4054
Pass 1 Program Logic

Assign addresses to all external symbols


 Loader is concerned only with Header and
Define records in the control sections
To build up ESTAB
 Add control section name into ESTAB
 Add all external symbols in the Define record into ESTAB
Pass 2 Program Logic
 Perform the actual loading, relocation, and linking
 When Text record is encountered

 Read into the specified address (+CSADDR)

 When Modification record is encountered


 Lookup the symbol in ESTAB
 This value is then added to or subtracted from the indicated location in
memory
 When the End record is encountered
 Transfer control to the loaded program to begin execution
24. Discuss the algorithms of pass 1 and pass2 for linking and relocating
loader.Evaluate the algorithms for pass 2 and pass1 for a linking loader

CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC


CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC
CS 303 System Software Ms Divya M.Menon, AP- CSE ,JECC

You might also like