19
USN PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science And Engineering SOLUTION MANUAL FOR INTERNAL ASSESSMENT TEST – 3 Date : 09/11/2016 Max Marks : 50 Subject & Code : System Software & 10CS52 Section : A, B and C Name of faculty : Dr. Sarasvathi V & Ms. Shanthala P T Time : 11:30-1:00 PM 1. a With suitable example explain the use of LTORG assembler directive. To place literals into a pool at someother location in the object program We introduce the assembler directive LTORG.When the assembler encounters a LTORG statement it creates a pool that contains all of the literal operands used since the previous LTROG.This literal pool is placed in the object program at the location where the LTROG directive was encountered.ofcourse, literals placed in a pool at the end of the program. If we had not used the LTORG statement on line 93,the literal=C'EOF' would be placed in the pool at the end of the program.This literal pool would begin at address 1073.This means that the literal operand would be placed too far away from the instruction referencing it to allow program-counter relative addressing. The problem,ofcourse is the large amount of storage reserved for BUFFER.By placing the literal pool before this buffer,we avoid having to use extended format instructions when referring to the literals.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. 3 B.E/V Sem 1 P E

Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

Embed Size (px)

Citation preview

Page 1: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

SOLUTION MANUAL FOR INTERNAL ASSESSMENT TEST – 3Date : 09/11/2016 Max Marks : 50Subject & Code : System Software & 10CS52 Section : A, B and CName of faculty : Dr. Sarasvathi V & Ms. Shanthala P T Time : 11:30-1:00 PM

1. a With suitable example explain the use of LTORG assembler directive.

To place literals into a pool at someother location in the object program We introduce the assembler directive LTORG.When the assembler encounters a LTORG statement it creates a pool that contains all of the literal operands used since the previous LTROG.This literal pool is placed in the object program at the location where the LTROG directive was encountered.ofcourse, literals placed in a pool at the end of the program.

If we had not used the LTORG statement on line 93,the literal=C'EOF' would be placed in the pool at the end of the program.This literal pool would begin at address 1073.This means that the literal operand would be placed too far away from the instruction referencing it to allow program-counter relative addressing. The problem,ofcourse is the large amount of storage reserved for BUFFER.By placing the literal pool before this buffer,we avoid having to use extended format instructions when referring to the literals.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.

3

b Explain program blocks with block diagram

Programs assembled was treated as a unit. The source programs logically contained subroutines, data areas, etc. However, they were handled by the assembler as one entity, resulting in a

single block of object code. Some machines generate instructions and data to appear in the object

program in a different order from source statements. Other machines results in creation of several independent parts of the

object program. These parts maintain their identity and are handled separately by the

loader.

Although the source program logically contains subroutines, data area, etc, they were assembled into a single block of object code in which the machine instructions and data appeared in the same order as they were in the source

7

B.E/V Sem

1 P E

Page 2: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

program.

To provide flexibility: Program blocks

Segments of code that are rearranged within a single object program unit

Control sections Segments of code that are translated into independent object

program units As an example, 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

The assembler directive USE indicates which portions of the source program belong to the various blocks.

Each program block may actually contain several separate segments of the source program.

The assembler will logically rearrange these segments to gather together the pieces of each block.

The result is the same as if the programmer had physically rearranged the source statements to group together all the source lines belonging to each block.

Pass 1 Maintain a separate LOCCTR for each program block

initialized to 0 when the block is first begun saved when switching to another block restored when resuming a previous block

Assign to each label an address relative to the start of the block that contains it

Store the block name or number in the SYMTAB along with the assigned relative address of the label

Indicate the block length as the latest value of LOCCTR for each block at the end of Pass1

Assign to each block a starting address in the object program by concatenating the program blocks in a particular order

Pass 2 Calculate the address for each symbol relative to the start of the object

B.E/V Sem

1 P E

Page 3: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

program by adding the location of the symbol relative to the start of its block the assigned starting address of this block

2. a What are control sections? Explain how linking is performed between control sections.

A control section is a part of the program that maintains its identity after assembly; each such control section can be loaded and relocated independently of the others. Different control sections are most often used for subroutines or other logical subdivisions of a program. The programmer can assemble, load, manipulate each of these control sections separately. The resulting flexibility is a major benefit of using control sections.

When control sections form logically related parts of a program, it is necessary to provide some

6

B.E/V Sem

1 P E

Page 4: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

means for linking them together. For example, instructions in one control section might need to refer to instructions or data located in another section. Because control sections are independently loaded and relocated, the assembler generates information for each external reference that will allow the loader to perform the required linking. In this section describe how external references are handled by our assembler.

Consider a program where there are 3 control sections: one for the main program and one for each subroutine. The START statement identifies the beginning of the assemble and gives a name (COPY) to the first control section. The first section continues until the CSECT statement. This assembler directive signals the start of anew control section named RDREC. Similarly, the CSECT statement begins the control section named WRREC. The assembler establishes a separate location counter for each control section, just as it does for program blocks.

Control sections differ from program blocks in that they are handled separately by the assembler. Symbols that are defined in one control section may not be used directly by another control section; they must be identified as external references for the l9ader to handle. 2 assembler directives to identify such references are: EXTDEF (external definition) and EXTREF (external reference). The EXTDEF statement in a control section names symbols, called external symbols, which are defined in the control section and may be used by other sections. Control section names de not need to be named in an EXTDEF statement because they are automatically considered to be external symbols. The EXTREF statement names symbols that are used in this control section and are defined elsewhere. The order in which symbols are listed in the EXTDEF and EXTREF statements is not significant.

The operand (RDREC) is named in the EXTREF statement for the control section, so this is an external reference. The assembler has no idea where the control section containing RDREC will be loaded, so it cannot assemble the address for this instruction. Instead the assembler inserts an address of zero and passes information to the loader, which will cause the proper address to be inserted at load time. The address of RDRED will have no predictable relationship to anything in this control section; therefore relative addressing is not possible. Thus an extended format instruction must be used to provide room for that actual address to be inserted. This is true of any instruction who0se operand involves an external reference.

The two new record types are Define and Refer. A Define record gives information about external symbols that are defined in his control section this is, symbols named by EXTDEF. A Refer record li8sts symbols that are used as external references by the control section- that is, symbol named by EXTREF. The formats of these records are as follows.

B.E/V Sem

1 P E

Page 5: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

Define record:Col. 1 DCol. 2-7 Name of external symbol defined in this control sectionCol. 8-13 Relative address of symbol within this control section (hexadecimal)Col. 14-73 Repeat information in Col. 2-13 for other external symbols

Refer record:

Col. 1 RCol. 2-7 Name of external symbol referred to in this control sectionCol. 8-73 Names of other external reference symbols

Modification record (revised):

Col.1 MCol.2-7 Starting address of the field to be modified, relative to the beginning of the control section (hexadecimal)Col. 8-9 Length of the field to be modified, in half-bytes (hexa-decimal)Col. 10 Modification flag (+ or -)Col. 11-16 External symbol whose value is to be added to or subtracted from the Indicated field.

b Explain how multipass assembler handles the following forward reference. 1 NUMB EQU MAXLEN/2 2 MAXLEN EQU BUFEND-BUFFER 3 PREVBT EQU BUFFER-1 4 BUFFER RESB 4096 5 BUFFEND EQU *Assume that, when assembler goes to line 4,location counter contains 1034(hex)

4

B.E/V Sem

1 P E

Page 6: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

3. a. With a neat diagram, Explain the structure of text editor.

The command language processor accepts input from the user’s input devices and

7

B.E/V Sem

1 P E

Page 7: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

analyzes the tokens and syntactic structure of the commands.Command language Processor

accepts command uses semantic routines

semantic routines performs functions such as editing and viewing.The semantic routines involve traveling, editing, viewing and display functions.The command language processor may produce an intermediate representation of the desired editing operations.The intermediate representaion is decoded by an interpreter that invokes appropriate semantic routines.Editing operations are specified explicitly by the user and display operations are specified implicitly by the other three categories of operations.Traveling and viewing operations may be invoked either explicitly by the user or implicitly by the editing operations.The start of the area to be edited is determined by the current editing pointer maintained by the editing componentEditing component is a collection of modules dealing with editing tasksCurrent editing pointer can be set or reset explicitly by the user with the traveling commands such as next paragraph, next screen or implicitly by system editing operation such as delete paragraph.

B Explain the overview of editing processSelect the part of the target document to be viewed and manipulatedDetermine how to format this view on-line and how to display itSpecify and execute operations that modify the target document

Update the view appropriately

3

4. a What are the basic function of macroprocessor. Explain various data structures used in the implementation of one-pass macro processor .The various functions of macro processor are:

1-> Macro definition and expansion:Each macro has a macro definition, a macro expansion and a macro invocation.Macro definition contains the macro name followed by the parameters, each parameter begins by an & which facilitates the substitution of parameters during macro expansion. The macro name and parameters define the macro definition or the macro prototype the instructions used by the programmerMacro invocation statement involves the macro name being called and the arguments too

6

B.E/V Sem

1 P E

Page 8: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

be used in expanding the macro. This is often known as macro callWhen a macro invocation statement is encountered it is replaced by the macro body, with the macro invocation substituted for the parameters in the macro prototype

2-> Macro processor algorithm and data structures:Macro definitions are processed in the first pass and all macro invocations are expanded during the second pass. The definition of a macro must appear in the source program before any statements that invoke that macro. Three data structures are used in macro processor.DEFTABNAMTABARGTAB

Most macro processor allow the definitions of commonly used macro instructions to appear in a standard system library rather than in the source program.

There are three main data structures(tables) involved in our macro processor.(i) DEFTAB(Definition Table):-

The macro definitions are stored in DEFTAB.DEFTAB contains the macro prototype and statements that make up the macro body.Comment lines from the macro definition are not entered in DEFTAB as they are not the part of macro expansion.References to the macro instruction parameter are connected to a positional notation for efficiency in substituting arguments.

(ii) NAMTAB(Name Table):-The macro names are entered into NAMTAB, which serves as an index to DEFTABFor each macro instruction defined, NAMTAB contains pointers to the beginning and end of the definition in DEFTAB.

(iii) ARGTAB(Argument Table):-ARGTAB is used during the expansion of macro invocations.When macro invocation statement is recognized, the arguments are stored in ARGTAB according to their position in the argument list.As the macro is expanded, arguments from ARGTAB are substituted for the corresponding parameters in the macro body.

Figure below shows portions of the contents of these tables during the processing of some program.

B.E/V Sem

1 P E

Page 9: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

b Write a short note on “keyword macro parameters”Using a different forms of parameter specification is called keyword macro parameters. If a macro has a large number of parameters, and only a few of these are given values in a typical invocation, a different form of parameter specification is more useful.FORM 1:Suppose that a certain macro instruction GENDER has 10 possible parameters, but in a particular invocation of the macro, only the third and ninth parameters are to be specified. If positional parameters were used, the macro invocation will be,GENDER ,,DIRECT,,,,,,3.USING a different form of parameter specification, called “keyword parameter” each argument value is written with a keyword that names the corresponding parameter. arguments may appear in any order.GENER TYPE=DIRECT, CHANNEL=3.In the below example, each parameter name is followed by an equal sign(=), which identifies the keyword parameter.The parameter is assumed to have this default value if its name does not appear in the macro invocation.RDBUFF MACRO &INDEV=F1,etc.RDBUFF MACRO &INDEV=F1, &BUFADR=, &RECLTH=, &EOR=04, &MAXLTH=4096…..

4

B.E/V Sem

1 P E

Page 10: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

5. a Using the following definition, expand the following macro calls, called in sequence.i). LABEL RDBUFF F2, BUFFER, LENGTH,(04,12)ii). RDBUFF OE, BUFF,RLENG, ,2048 RDBUFF MACRO &INDEV, &BUFADR, &RECLTH, &EOR, &MAXLTH &EORCT SET %NITEMS(&EOR) CLEAR X CLEAR A IF (&MAXLTH EQ ‘ ‘) +LDT #4096 ELSE +LDT #&MAXLTH ENDIF $LOOP TD =X’&INDEV’ JEQ $LOOP RD =X ‘&INDEV’ &CTR SET 1 WHILE (&CTR LE &EORCT) COMP =X’0000 &EOR[&CTR]’ JEQ $EXIT &CTR SET &CTR+1 ENDW STCH &BUFADR, X TIXR T JLT $LOOP$EXIT STX &RECLTH MEND

SOLUTION:i). LABEL RDBUFF F2, BUFFER, LENGTH,(04,12) CLEAR X CLEAR A +LDT #4096 $AALOOP TD =X’F2’ JEQ $AALOOP RD =X ‘F2’ COMP =X’000004’ JEQ $AAEXIT COMP =X’000012’

07

B.E/V Sem

1 P E

Page 11: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

JEQ $AAEXIT

STCH BUFFER, X TIXR T JLT $AALOOP$AAEXIT STX LENGTH

ii). RDBUFF OE, BUFF,RLENG, ,2048 CLEAR X CLEAR A +LDT #2048 $ABLOOP TD =X’0E’ JEQ $ABLOOP RD =X ‘&0E’ STCH BUFF, X TIXR T JLT $ABLOOP$AAEXIT STX RLENG MEND

b Write a note on MASM macro processorThe macro processor of MASM is integrated with pass 1 of the assembler. It

supports all the main macro processor functions including the definition and invocation of macro instructions within macros. MASM macro processor calls conditional macro expansion statements as conditional assembly statements. Fig 1 illustrates

1 ABSDIF MACRO OP1,OP2,SIZE2 LOCAL EXIT3 IFNB <SIZE> ;; IF SIZE IS NOT BLANK4 IFDIF <SIZE>,<E> ;; THEN IT MUST BE E5 ; ERROR – SIZE MUST BE E OR BLANK6 .ERR7 EXITM

03

B.E/V Sem

1 P E

Page 12: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

8 ENDIF ;;END OD IFDIF9 ENDIF ;;END OF IFNB10 MOV SIZE&AX,OP1 ;;COMPUTE ABSOLUTE DIFFERENCE 11 SUB SIZE&AX,OP2 ;;SUBTRACT OP2 FROM OP112 JNS EXIT ;;EXIT IF RESULT GE 013 NEG SIZE&AX ;; OTHERWISE CHANGE SIGN14 EXIT:15 ENDM (a)ABSDIF J,K...MOV AX,JSUB AX,KJNS ??0000NEG AX??0000: (b)

ABSDIF M,N,E...MOV EAX,MSUB EAX,NJNS ??0001NEG EAX??0001: (C)

ABSDIF P,Q,X...

B.E/V Sem

1 P E

Page 13: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/2016/cs/ss 3RD TEST solution.doc · Web viewThe assembler has no idea where the control section containing RDREC will be

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

; ERROR -- SIZE MUST BE S OR BLANK (d)

The macro defined in fig1 computes the absolute difference between the values of its first two parameters. These parameters may be either words or double words. If they are double words, the third parameter has the value E and the calculation uses the double word register EAX. If the first two parameters are words, the third parameter is omitted. When the macro is expanded, each label is replaced by a unique name. MASM generates these unique names in the form of ??n, where n is a hexadecimal number in the range 0000 to FFFF. EXITM directs the MASM to terminate the expansion of the macro. The line which begins with ;; , is a macro comment. It serves only as documentation for the macro definition. And the line which begins with ;, is an ordinary assembler language comment. It is included as a part of macro expansion.

* * * * * * * *

B.E/V Sem

1 P E