Answer Model Cs303 Systemsoftware November2018
Answer Model Cs303 Systemsoftware November2018
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
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
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
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
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
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
secname CSECT
Instructions in one control section may need to refer to instructions or data located in
another section
1.External definition
2. External reference
ORG Directive
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
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.)
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
• 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
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
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.
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:
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
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.
• For a two pass assembler, forward references in symbol definition are not allowed:
ALPHA EQU BETA
DELTA RESW 1
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.
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
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
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 *
Begin
begin
begin
begin
if found then
begin
begin
if found then
else
begin
end
else
begin
end
End {Pass 2}
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).
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
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
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.
M00000405+RDREC
M00000705+COPY
22. Elaborate the design options of One pass Assemblers with suitable examples.
One-pass assemblers are used when
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.)
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
– 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
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