Você está na página 1de 19

Unit-I Introduction

1.Define System Software.

System software consists of a variety of programs that support the operating


system of a computer. This software makes it possible for the user to focus on an
application or other problem to be solved, without needing to know the details of how
the machine works internally. Ex: Assembler, Loader, Macro processors.

2.Differentiate System Software from Application Software.

System Software Application Software


System software are intended to support An Application software is primarily
the operation and use of the computer concerned with solution of some problem
itself, rather than doing any particular using computer as a tool.
application. so, they are usually related
to architecture of machine on which they
are to run .

3.Differentiate Operating systems and system software.


Operating systems are directly concerned with the management of nearly all of
the resources of a computing system; where as some aspects of system software do not
directly depend upon the computing system being supported .

4.What is the purpose of program counter?


Program counter, contains the address of the next instruction to be fetched for
execution. PC is the register used for this purpose in SIC Machine Architecture.

5.What are the functions of A,X,L registers in SIC.


A Accumulator used for arithmetic operation.
X Index register, used for addressing.
L Linkage register, the jump to subroutine( JSUB) instruction stores the return
address in this register.

6.Give the Instruction format of SIC.


In Standard SIC, all the machine instructions have 24 bit format.
8 1 15
OPCODE X ADDRESS

The flag bit X is used to indicate indexed-addressing mode.

7.How many addressing modes are available in SIC , Explain.


There are two addressing modes available, indicated by the setting of the x bit in
the instruction.
Mode Indication Target address
Direct X=0 TA=address
Indexe X=1 TA=address + (X)
d
8.What is the purpose of TD instruction.
The Test Device(TD) 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.
A setting of < means the device is ready and = means not ready. A program needing to
transfer data must wait until the device is ready, then execute a Read Data(RD) or Write
Data(WD).

9.What are the additional registers provided by SIC/XE .


The following are additional registers provided by SIC/XE
B Base Register, used for addressing.
S General working Register-no special use.
T General working Register-no special use.
F Floating point accumulator(48 bits).

10. Explain Data format of SIC/XE.


1. Integer format: 24 bit binary numbers, 2’s complement representation is
used for negative values.
2. Character format: 8 bit ASCII code.
3. Floating Point format: 48 bit data type with following format.
1 11 36
S Exponent Fraction
If the fraction has value f, and exponent has value e, the absolute value of the number
Represented is
f*2(e-1024)
For normalized floating point numbers, the high-order bit of the fraction must be 1.
The exponent is interpreted as an unsigned binary number between 0 and 2047 .The sign
of the floating point number is indicated by the value of s(0=positive,1=negative).

11. How many types of Instruction formats are available in SIC/XE.


There are 4 different types of Instruction format in SIC/XE. They are
1. Format 1(1 byte).
8
Opcode
2. Format 2(2 byte).
8 4 4
0pcode R1 R2

3. Format 3(3 byte).


6 1 1 1 1 1 1 12
Opcode n i x b p e Displacement

4. Format 4(4 byte).


6 1 1 1 1 1 1 20
Opcode n i x b p e address

12. Compare base relative and program counter relative addressing.


The Base relative and Program Counter relative are addressing
modes used in Format 3 instruction.

Base relative b=1,p=0 TA=(B) + disp, (0<=disp<=4096)


Program counter relative b=0,p=1 TA=(PC) + disp, (-2048<=disp<=2047)

For base relative, the displacement field in a Format 3 instruction is


interpreted as a 12-bit unsigned integer. For program counter relative, this field is
interpreted as a 12-bit signed integer, with negative values represented in 2’s
complement notation.

13. What is Direct Addressing.


If bits b and p are both set to 0, the disp field from the format 3
instruction is taken to be the target address.. For a format 4 instruction , bits b and p
are normally set to 0, and the target address is taken from the address field of the
instruction, which is called as direct addressing.

14. Compare immediate addressing and indirect addressing mode in SIC/XE.


Immediate Addressing:
Bits i and n in Format 3 and 4 are used to specify how the target address is
used. If bit i = 1 and n = 0, the target address itself is used as the operand value; no
memory reference is performed. This is called immediate addressing.
Indirect Addressing:
If bit i = 0 and n = 1, the word at the location given by the target address is
fetched; the value contained in this word is then taken as the address of the operand
value. This is called indirect addressing.

15. Explain implied addressing.


In the implied addressing neither address nor value is specified in the
operand field. Address is implicitly specified depending on the instruction
Opcode. This is also called as implicit addressing.
Ex: RSUB

16. Explain SIO,TIO,HIO instructions in SIC/XE.


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

17. Explain SVC instruction.


A special supervisor call instruction(SVC) is provided in SIC/XE.
Executing this instruction generates an interrupt that can be used for
communication with the operating system.
18. Give one example program for Data Movement operation in SIC/XE.
LDA #5
STA ALPHA
LDA #90
STCH C1
ALPHA RESW 1
C1 RESB 1

19. Compare Instruction set of SIC/XE and SIC.


Instruction set of SIC:
SIC provides a basic set of instructions, which include
1. Load and store registers-LDA,LDX,STA,STX.etc.
2. Integer Arithmetic Operations-ADD,SUB,MUL,DIV-all arithmetic
operations involve register A and a word in memory, with the result being
left in the register A.
3. There is an instruction COMP that compares the value in register A with a
word in memory;this instruction sets condition code CC to indicate the
result(<,=,or >).
4. Conditional jump instructions-JLT,JEQ,JGT can test the setting of CC, and
jump accordingly.
5. JSUB-jumps to the subroutine,placing the return address in L.
RSUB-returns by jumping to address contained in L.
Instruction set of SIC/XE:
SIC/XE along with above instruction set also provides the
following instructions.
1. Load and store the new registers-LDB,STB,etc.
2. Floating point arithmetic operations:ADDF,SUBF,MULF,DIVF
3. Register move instructions-RMO.
4. Register to Register arithmetic operations-ADDR,SUBR,MULR,DIVR
5. Supervisor call instruction-SVC.

20.What is the purpose of CC in SIC.


There is an instruction in SIC (COMP) that compares the value in
register A with a word in memory;this instruction sets condition code CC to
indicate the result(<,=,or >). The Test Device(TD) instruction tests whether the
addressed device is ready to send or receive a byte of data. The condition code
CC is set to indicate the result of this test. A setting of < means the device is
ready and = means not ready.

In Numeric Format, represents numeric values with one digit per byte. In
this format, the sign may appear either in the last byte, or as a separate byte
preceding the first digit. These two variations are called trailing numeric and
leading separate numeric.

21. Give some advantages of assembly language over machine language.


1. It is mnemonic; we write LDA instead of the bit configuration.
2. Addresses are symbolic, not absolute.
3. Reading is easier.
4. Introduction of data to program is easier.

Unit –2 Assemblers
1. What are the fundamental functions of Assemblers?
The fundamental functions of Assemblers are,
1. Translating mnemonic operation codes to their machine language
equivalents.
2. Assigning machine addresses to symbolic labels used by the
programmer.

2. Differentiate Assembler directives from mnemonic machine instructions.


The Mnemonic machine instructions are translated in machine
instructions. Example: ADD is translated to18 in object program.
The Assembler directives are not translated into machine instructions;
instead they provide instructions to the assembler itself. Examples are
statements like
1.BYTE and WORD, which direct the assembler to generate constants as
part of the object program.
2.RESB and RESW, which instruct the assembler to reserve memory
locations without generating data values.
3.START, which specifies the starting memory address for the object
program.
4.END, which marks the end of the program.

3. What are the general functions of Simple SIC Assembler?


The translation of source program to object code requires the following
functions.
1. Convert mnemonic operation codes to their machine language
equivalents.
2. Convert symbolic operands to their equivalent machine addresses.
3. Build the machine instructions in the proper format.
4. Write the object program and the assembly listing.

4.Explain forward references with example.


Forward references is a reference to a label that is defined later in the
program.
1000 LDA sum
1003 JEQ loop
-
-
1010 loop STA sum
-
-
101C sum WORD 5
The above example, sum is reference variable which is defined later in the
program, loop is forward loop defined later.

5. What is the object program format of Simple Assembler?


The Simple object program format contains the following three types of
record.
1. Header Record: contains program name, starting address and
length.
2. Text Record : contains the translated instructions and data of the
program, together with the indication of the addresses where these
are to be loaded.
3. End Record : marks the end of the object program and specifies
the address in the program where execution is to begin.

6. What are the internal Data structures for Simple Assembler.


The Simple Assembler uses two major internal data structures ; the
operation code table(OPTAB) and the symbol table(SYMTAB).
OPTAB;is needed to look up mnemonic operation codes and
translate them to their machine language equivalents.
SYMTAB;is used to store values(addresses) assigned to labels.
LOCCTR;Loctaion Counter is a variable that is used to help in
assignment of addresses.

7. Differentiate Location counter and program counter.


Location counter is a variable that holds the address of currently translated
instruction. It is initialized to the beginning address specified in the START
statement. After each source statement is processed, the length of the assembled
instruction or data area to be generated is added to Location counter.
Program counter is a register which holds the address of next executable
instruction.

8.Explain intermediate file in two pass assembler.


There are certain information like location counter values,error flags for
statements,etc that should be communicated between two passes.For this reason
pass 1 usually writes an Intermediate file that contains each source statements
together with its assigned address,error indicators ,etc .This file is used as input to
pass 2.This working 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 be
perfomed again pass 2 .Similarly pointers into OPTAB and SYMTAB may be
retained for each operation code and symbol used.This avoids the need to repeat
many of the table searching operations.

9.What do you understand by machine dependant assembler features.


In machine dependant assembler features extended hardware effect the
structure and functions of assembler.Some of these features are
1.instruction formats and addressing modes.
2.Program relocation

10.Give some of the advantages of SIC/XE features when compared with SIC.
The advantages of SIC/XE architectures are
1. Improves the execution speed of the program :register to register instruction
faster because they do not require another memory reference.Likewise ,
when using immediate addressing the operand is already present as part of
the instruction,and need not be fetched from anywhere.
2. The use of indirect addressing often avoids the need for another instruction.

11.What are the different types of notations used prefix to operand and mnemonic
code.
1.Immediate addressing - #
2.Indirect addressing - @
3.Format 4 - +

12.Explain BASE as an assembler directive.


In the following statement ,
BASE LENGTH
BASE informs the assembler that the base register will contain the address of
LENGTH .The assembler assumes for addressing purposes that the register B
contains this address until it encounters another BASE statement.

13.When do loader relocate the program into memory.


It is often desirable to have more than one program at a time sharing the
memory and other resources of the machine.If it is known in advance exactly
which programs were to be executed concurrently in this way,we could assign
address when the programs were assembled so that they would fit together
without overlap or wasted space.Most of the time however,it is not practical to
plan program execution in this way.Because of this it is desirable to be able to
relocate the program into memory wherever there is a room for it.

14.Explain Modification record.


There is one modification record for each address field that needs to be
changed when the program is relocated.We can accomplish this with a
Modification record having the following the format,
Column 1 M
Column 2-7 Starting location of the address field to be modified,
relative to the beginning of the program.(hex).
Column 8-9 Length of the address field to be modified, in half
bytes(hex).

15.Explain LTORG instruction .


All of the literal operand used in the program are gathered together in one
or more literal pools. Normally literals are placed into a pool at the end of the
program. Such a literal pool listing is immediately following the END statement.
In some cases, however it is desirable to place literals into a pool at some other
location in the object program. To allow this we introduce the assembler directive
LTORG. when the assembler encounters a LTORG statement, it creates literal
pool that contains all of the literal operands used since the previous LTORG.
Literals placed in a pool by LTORG will not be repeated in the pool at the end of
the program. The need for an assembler directive such as LTORG usually arises
when it is desirable to keep the literal operand close to the instruction that uses it.

16.What are symbol defining statements .


Most of the assemblers provide an assembler directives that allows
the programmer to define symbols and specify their values.The assembler
directives generally used for this is EQU and ORG.The general form of these
statements are
Symbol EQU Value
ORG Value
The value may be given as a constant or as any expression involving constants
and previously defined symbols.

17.Differentiate literal and immediate operand.


In immediate addressing ,the operand value is assembled as part of
machine instructions whereas in literal ,the assembler generates the specified
values as constants at some other memory location .The address of this generated
constant is used as target address for the machine instruction.The effect of using a
literal is exactly same as if the programmer had defined the constant explicitly
and used the label assigned to the constant as the instruction operand.

18. Describe how literals are handled by assembler.


]The basic data structure needed is a literal table LITTAB.For each literal
used this table contains the literal name,the operand value and length, and the
address assigned to the operand when it is placed in a literal pool.LITAB is often
organized as a hash table,using the literal name or value as the key.
As each literal operand is organized during Pass 1,the assembler searched
LITTAB for the specified literal name (or value) .If the literal is already present in
the table,no action is needed ;if it is not present ,the literal is added to
LITTAB(leaving the address unassigned). 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(unless
such an address has already been filled in).As these address are assigned ,the
location counter is updated to reflect the number of bytes occupied by each literal.

19. Differentiate absolute and relative expression.


Expressions are classified as either absolute expression or relative
expression depending upon the type of the value they produce.An expression that
contains only absolute terms is,of course,an absolute expression.however absolute
expression may also caontain relativwe terms provided occur in pairs and the
terms in each such pairs have opposite signs.It is not necessary that paired terms
be adjacent to each other in expression;however all relative terms may be capable
of being paired in this way.none of the relative terms may enter into a
multiplication or division operation.
A relative expression is one in which all of the relative terms except one
can be paired as described above;the remaining unpaired relative terms must have
a positive sign.As before no relative term may enter into a multiplication or
division operation.Expressions athat do not meet the conditions given for either
absolute or relative expression should be flagged by the assemblers as errors.

20.What are limitations in using EQU and ORG statements.


In the case of EQU,all symbols used on the right side of the statements
must have been defined previously in the program.consider the sequence
BETA EQU ALPHA
ALPHA RESW 1
Where BETA cannot be assigned the value when it is encountered during
pass 1 of the assembly, in two pass assembler design it requires all symbols be
defined during pass 1.
A Similar restriction also applies to ORG. Consider the following
statements,
ORG ALPHA
BYTE1 RESB 1
BYTE2 RESB 1
BYTE3 RESB 1
ORG
ALPHA RESB 1

In this case the assembler would not know what value to assign to the
location counter in response to the first ORG statement .AS a result the symbols
BYTE 1, BYTE 2 and BYTE 3 could not be assigned the addresses during pass 1.
21.Give one example for calculation of target address with respect to B and P bits in
instruction format.
Consider the following instruction
0000 STL RETADR –17202D
Opcode ni xbpe
Opcode of STL is 172, in Binary 0001 0111 0010
In this E bit is 0, so it is in Format 3.
P bit is 1, so it is Program counter relative.
Program counter value is 0003.Address of RETADR is 00030.
Therefore opcode of RETADR is 0030-0003,which is equal to 002D.

Consider the following instruction


104E STCH BUFFER,X 57C003
Opcode ni xbpe
opcode of STCH is 57C, in Binary 0101 0111 1100
In this E bit is 0 ,so it is format 3.
B bit is 1,so it is base relative.
Base register value is 0033
The address of buffer is 0036.Therefore opcode of Buffer is 0036-0033,which is
equal to 3.

22.Give two examples for different instruction formats of SIC/XE.


Format 1 - FIX , FLOAT
Format 2 -CLEAR r1 , RMO r1 , r2
Format 3 -ADD m , STA m
Format 4 -+ ADD m , +STA m

23.Explain Program Blocks and Control sections.


The term Program blocks refer to segments of code that are rearranged within a
single object program units.These segments are dependent to each other and so they are
assembled together,whereas control sections refer to segments that are translated into
independent object program units.Control section is a part of program that maintains its
identity after assembly;Each such control sections can be loaded and relocated
independently of others.

24.Explain EXTDEF and EXTREF statements.


As the control sections are independently loaded, assembler has no idea where
any other control section will be located at execution time.Such references between
contron sections are called external references.
The EXTDEF statement in a control sections names symbols,called External
symbols;that are defined in this control sections and may be used by other sections.
The EXTREF statements names symbols that are used in this contron sections and
are defined elsewhere.
25.In one pass assembler how forward references can be avoided.
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 as easily. The logic of the program often
requires a forward jump - for example, in escaping from a loop after testing some
condition

26.What is the necessity for multipass assembler.

Consider the sequence


ALPHA EQU BETA
BETA EQU DELTA
DELTA RESW 1

The symbol BETA cannot be assigned a value when it is encountered during the
first pass because DELTA has not yet been defined. As a result, ALPHA cannot be
evaluated during the second pass. This means that any assembler that makes only two
sequential passes over the source program cannot resolve such a sequence of definitions.
The General solution for this is a multipass assembler that can make as many passes as
are needed to process the definition of symbols.

27.What is purpose of assembler directives ASSUME.


The data segment in MASM are normally addressed using DS,ES,FS or GS. This
segment register to be used can be specified explicitly by the programmer . If the
programmer does not specify a segment register , one is selected by the assembler . By
default , the assembler assumes that all references to data segments use register DS. This
assumption can be changed by the assembler directive ASSUME . For example the
directive
ASSUME ES:DATASEG2
tells the assembler to assume that register ES indicates the segment DATASEG2. Thus
any references to labels that are defined in DATASEG2 will be assembled using register
ES.

28.Explain Jump instruction in MASM.


Jump instructions are assembled in two different ways.
A Near jump is a jump to a target in the same code segment, A far jump is a jump
to a target in a different code segment. The assembled machine instruction for a near
jump occupies two or three bytes, for far jump require five bytes.
For example consider a jump instruction like
JMP TARGET (reserves 3 bytes)
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 far jump. If this is a forward refernce
to TARGET, the assembler does not know how many bits to reserve for the instruction.
By default , MASM assumes that a forward jump is a near jump If the target of the jump
is in another code segment, the programmer must warn the assembler by writing
JMP FAR PTR TARGET (reserves 5 bytes)
The programmer can specify shorter near jump by writing
JMP SHORT TARGET (reserves 2 bytes)

29.What is the difference between following sequence of statements.


a) LDA LENGTH
SUB #1
b)LDA LENGTH-1

If LENGTH is defined at address 0033 with the value 5. The result of the
given statements are
a. A is loaded with value 5 and subtracted by 1, thus giving the result 4.
b. A is loaded with value defined in location 0032.

Unit-3 Loaders and Linkers

1. What is an object program.


An object program contains translated instructions and data values from
the source program, and specifies addresses in memory where these items are to
be loaded.

2. What are the three main processes of Linking loader.


The following are the main process of loader,
1. Loading, which brings the object program into memory for execution.
2. Relocation, which modifies the object program so that it can be loaded at an
address different from the location originally specified.
3. Linking, which combines two or more separate object programs and supplies
the information needed to allow references between them.

3. Define absolute loader.


Absolute Loader is a simple loader, which loads the object program into
memory at the specified address. This loader does not perform functions like
linking and program relocation; therefore its operation is simple. All functions are
accomplished in a single pass.
1. Header record is checked to verify that the correct program has been
presented for loading.
2. Then each Text record is read, the object code it contains is moved
to the indicated address in memory.
3. When End record is encountered, the loader jumps to the specified
address to begin the execution of the loaded program.

4. What are the functions of simple Bootstrap loader.


When a computer is first turned on or restarted, a special type of absolute
loader, called a bootstrap loader, is executed. This bootstrap loader loads the first
program to be run by the computer-usually operating system. The bootstrap itself
begins at address 0 in the memory of the machine. It loads the operating system
starting at address 80. Mostly it is a permanent program resident in ROM. When
some hardware signal occurs, the machine begins to execute this ROM program.
On some computers, the program is directly executed in ROM; on others, the
program is copied from ROM to main memory and executed there.

5. Explain how ASCII character code is converted into hexadecimal value.


The ASCII code for the character “0” is converted to the numeric value
0.Likewise, the ASCII codes for “1” through “9” are converted to the
numeric values 1 through 9, and the codes for “A” through “F” are
converted into values 10 through 15.
The conversion involves following steps,
1. Subtract decimal 48(hex 30) from input character code.

2. if the result is less than 10, then it is the resultant hexadecimal value,
otherwise from the resultant value subtract decimal 7 which is the resultant
hexadecimal value of the given input.

6. What are machine dependent loader features.


The machine dependent loader features are ,
1. Program Relocation.
a. using modification records.
b. using relocation bit mask.
2. Program Linking.

7. Explain relocation bit and bit mask in object program.


On a machine that primarily uses direct addressing and has a fixed
instruction format, it is not efficient to use the technique modification record. The
efficient way to specify relocation is using a technique of relocation bit. The text
record are same as before except that there is a relocation bit associated with each
word of the object code, this means there is one relocation bit for one instruction.
The relocation bits are gathered together into a bit mask following the length
indicator in each text record.

8. What is a Linking loader.


Linking loader combines two or more separate object programs and
supplies the information needed to allow references between them. Also it loads
the object program into memory at the address different from specified address.
Thus as an assembler Linking loader also makes two passes over its input.
1. Pass 1 assigns addresses to all external symbols.
2. Pass 2 performs the actual loading, relocation and linking.
9. Explain ESTAB.
The main data structure needed for linking loader is an external symbol
table ESTAB. This table is used to sore the name and address of each external
symbol in the set of control section being loaded. The table also defines in which
control section the symbol is defined. The hashed organization is typically used
for this table.

10. What is automatic library search?


Many Linking loaders can automatically incorporate routines from a
subprogram library into the program being loaded. Standard libraries are used in
this way; other libraries are specified by control statements or by parameters to
loader. The subroutines called by the program being loaded are automatically
fetched from the library, linked with the main program, and loaded. The
programmer needed not explicitly mention this subroutines in external reference.
This feature is referred as automatic library call or search.

11. Give example for loader commands.

INCLUDE program-name(library-name)
-directs the loader to read the designated object program from a library and treat it
as if it were part of the primarily loader input.
DELETE csect-name
-instruct the loader to delete the named control section(s) from the set of programs
being loaded.
CHANGE name1,name2
-cause the external symbol name1 to changed to name2 wherever it appears in the
object program.

12. What are the other Loader design options other than Linking Loader.
The other Loader design options are,
1. Linkage editor performs linking and some relocation; however, the linked
program is written to a file or library instead of being immediately loaded
into memory.
2. Dynamic Linking, which uses the facilities of an operating system to load and
link subprograms at the time they are first called.

13. Explain Load on call.


Dynamic Linking postpones the linking function until execution time; a
subroutine is loaded and linked to the rest of the program when it is first called, this
function is otherwise called as dynamic loading or Load on call.

14. Differentiate Linking Loader and Linkage Editor.


Linking Loader performs all linking and relocation at load time whereas Linkage
editor performs linking and some relocation; however, the linked program is written to a
file or library instead of being immediately loaded into memory, which reduces the
overhead when the program is executed and all that is required during load time is a very
simple form of relocation.

15. Differentiate Linkage editor and Dynamic Linking.


Linking Loader performs all linking and relocation at load time whereas Dynamic
Linking postpones the linking function until execution time; a subroutine is loaded and
linked to the rest of the program when it is first called, this function is otherwise called as
dynamic loading or Load on call. By delaying the linking process in this way, additional
flexibility can be achieved but this approach usually involves more overheads than does a
linking loader.

16. Explain Dynamic Link Library.


Dynamic linking is often used to allow several executing programs to share one
copy of a subroutine or library. Run time support routines for a high level language
could be stored in a dynamic link library. A single copy of the routines in this library
could be loaded into the memory of the computer. All the programs currently in
execution could be linked to the one copy, instead of linking a separate copy into each
object program.

17. Describe the object module of MS-DOS.


The object module of MS-DOS has following record types.
1. THEADR - Translator header.
2. TYPDEF,PUBDEF,EXTDEF - External symbols and
references
3. LNAMES,SEGDEF,GRPDEF - Segment definition and
grouping
4. LEDATA,LIDATA - Translated instructions and data
5. FIXUPP - Relocation and linking information
6. MODEND - End of object module

18. Explain .OBJ and .EXE files in MS-DOS.


MS-DOS compilers and Assemblers produce object modules, not executable
machine language programs. These object modules have a file name extension .OBJ,
Which contains a binary image of the translated instructions and data of the program.
MS-DOS LINK is a linkage editor that combines one or more object modules to
produce a complete executable program, which has a file name extension .EXE.

UNIT-4 Macroprocessors

1. Define a macroinstruction.
The macroinstructions allow the programmer to write a shorthand version
of a program. A macro represents a commonly used group of statements in the
source programming language. These macros are expanded by the macro
processor in the source program and then fed as input to assembler.
2. Compare macro with subprogram.
1. It is necessary to save contents of all registers individually before calling a
subprogram, whereas the registers are saved in macro using single
instruction SAVEREGS. Also LOADREGS could be used to reload the
register contents after returning from the subprogram.
2. When subprogram is called control is transferred from calling instruction
address to called instruction address, thus it is necessary to save the return
address in the linkage register, whereas the macros on invocation are
expanded at the invoked location so there is no need to save the return
address.
3. What are the functions of macro processor or preprocessor?
The functions of a macro processor or preprocessor are substitution of one group of
characters or lines for another. A macro invocation statement gives the name of the
macroinstruction being invoked and arguments to be used in expanding the macro.
On macro invocation the macro processor expands the macro definition in the
source program and this expanded program is fed as input to the assembler.

4.Why body of macro should not contains labels?


When the macro is invoked more than once, the body of the macro also expanded
so many times in the invoked program. This causes duplication of label in the expanded
program. When this program is input to assembler, it creates confusion in creation of
symbol table during pass1 .So the body of macro should not contain labels, instead of
labels relative addressing is used in the source statement.

5.What are the main data structures involved in macro processor?


There are three main data structures involved in macro processor:
They are,
1.DEFTAB: Macro definitions are stored in definition table.
2.NAMTAB : Macro names are entered into this table and also contains pointers
to beginning and end of the definitions in DEFTAB.
3.ARGTAB : When a macro invocation statement is recognized, the arguments
are stored in ARGTAB according to their position in the arguments list.

6.Give some of the machine independent macro processor features?


Some of the machine independent macro processor features are
1.concatenation of macro parameter.
2.generation of unique labels.
3.conditional macro expansion.
4.keyword macro parameters.

7.How can we avoid duplication of label when macro is invoked more than once?
Labels used within the macro body begin with special character ‘$’. Each symbol
beginning with ‘$’ will be replaced by “$xx”, where xx is a two character alphanumeric
counter of the number of macroinstructions expanded. For the first macro expansion on a
program,” xx “ will have the value “AA” .For succeeding macro expansions, xx will be
set to AB ,AC etc.. This results in the generation of unique labels for each expansion of a
macroinstruction.

8.What is macro time variable?


A macro time variable also often called a set symbol is a symbol, which can be
used to store working values during the macro expansion. Any symbol that begins with
character & and that is not a macroinstruction parameter is assumed to be a macro time
variable. All such variables are initialized to a value of zero. This variable can be set to
any other value using SET statement; otherwise it retains its default value of 0.

9.Explain concatenation of macro parameters?


Macro processors allow parameters to be concatenated with other character
strings.For example a program contains one series of variables named by the symbols
XA1,XA2,XA3….and another series and named by XB1,XB2,XB3…etc.If similar
perocessing is to be performed on each series of variables the programmer might want to
incorporate this processing into a macro instruction.The parameter to sucha macro
instruction could specify a series of variables to be operated on (A,B,..etc).In SIC
concatenation operator used is -> .For example
LDA X&ID->1 where &ID is the parameter concatenated with character strings
X and 1.

10.Explain line by line Macro prcessor?


In line by line Macro processsor the output lines are passed to the language
translator as they are generrated, instead of being written to a expanded source file.Thus
macro processor operates as a sort of input routine for the assembler or complier.This
avoids making an extra pass over the source program .The operations such as scanning
input lines ,searching tables ,and converting numeric values from external to internal
representations are used by both language translator and macro processor .Line by line
macro processor also makes it easier to give diagnostic messages that are related to the
source statement conatining the error.

11.Explain integrated macro processor ?


An integrated macro processor use any information about the source program that
is extracted by the language translator.The macro procssor use the results of translator
operations such as scanning for symbols, constants ,etc.For example in fortran
DO 100 I=1,20
Where DO is recognised as a key word ,100 as a statement number ,I as a variable
name.Also blanks are not significant in fortran statements .Thus the statement
DO 100 I =1
Has a different meaning.This is an assignment statement that gives the value 1 to the
variable DO100I.A fortran compiler must be able to recognise and handle situation like
this .So integrated macro processor has a closer degree of co operation with compiler or
assembler.Examble MASM macro processor

12.Define a general purpose macro processor.?


General purpose macro processors are not dependent on any paritcualr
programming language like special purpose macro processor ,but can be used with
variety of different languages.The advantages of this approach is ,programmer does not
need to learn about different macro facility for each compiler or assembler language,so
much of time and expense involved in training are eliminated.Though cost involved in
producing General purpose macro processor is greater ,this expense does not need to be
repeated for each language; The result is substantial overall saving in software
development cost.Example ,ELENA macro processor.

13. What do you understand by term recurrence with reference to macro expansion?
On invocation of one macro inside another macro, after expansion of
invoked macro the expand flag is set as false, thus the control does not return to invoking
macro. This will make incomplete expansion of invoking macro, in order to solve this
problem recursive macro expansion has to be done. So that expansion is complete for
both invoking and invoked macro.

14. State how posititional parameters and arguments are related in a macroprocessor.
When a macro invocation statement is recognized, the arguments are stored in
ARGTAB according to their position in the argument list. The positional notation is used
for the parameters, i.e for first parameter is converted to ?1, for second ?2,
correspondingly for all parameters in the DEFTAB. As the macro body is expanded,
arguments from ARGTAB are supplied to corresponding index in DEFTAB and
substituted for the corresponding parameters in the macro body.

Você também pode gostar