13695_hw2 cap318

20
CAP318 (SYSTEM SOFTWARE) HOME WORK – II Course Instructor: MANDEEP KAUR_____________________ Student’s Roll No. A15_____________________ Section No. : D3804_________________________ Declaration: I declare that this assignment is my individual work. I have not copied from any other student’s work or from any other source except where due acknowledgment is made explicitly in the text, nor has any part been written for me by another person. Student’s Signature : SURENDRA Evaluator’s comments: _____________________________________________________________________ Marks obtained : ___________ out of ______________________

Upload: sud3200

Post on 08-Apr-2015

177 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 13695_HW2 CAP318

CAP318 (SYSTEM SOFTWARE)HOME WORK – II

Course Instructor: MANDEEP KAUR_____________________

Student’s Roll No. A15_____________________ Section No. : D3804_________________________ Declaration: I declare that this assignment is my individual work. I have not copied from any other student’s work or from any other source except where due acknowledgment is made explicitly in the text, nor has any part been written for me by another person.

Student’s Signature : SURENDRA

Evaluator’s comments: _____________________________________________________________________ Marks obtained : ___________ out of ______________________

Page 2: 13695_HW2 CAP318

Part AQ 1. Discuss design specification of a assembler with diagram?ANSWER: The following steps are commonly to develop specification for an assembler.

1. Specify the problem.

2. Specify data structures

3. Define format of data structures

4. Specify algorithm

5. Look for modularity

6. Repeat all five modules

Page 3: 13695_HW2 CAP318

Synthesis phase: -

There are two data structures which are used in assemblers.1. Symbol table2.Mneomonics table

Analysis phase:-

The function performed by the analysis phase is the building of the symbol table.For this purpose it must determine the addresses with which the sym-bolic names use in a program are associated memory allocation

• The design of assembler can be to perform the following:

1. Scanning (tokenizing)2. Parsing (validating the instructions)3. Creating the symbol table 4. Resolving the forward references5. Converting into the machine language

Page 4: 13695_HW2 CAP318

The place of assembler in a system .The above diagram shows the place of assembler in a complete system.

Page 5: 13695_HW2 CAP318

Q 2. How a assembler converts mnemonic code in to machine understandable form? Explain?ANSWER: Typically a modern assembler creates object code by translating assembly instruction mnemonics into opcodes, and by resolving symbolic names for memory locations and other entities. The use of symbolic references is a key feature of assemblers, saving tedious calculations and manual address updates after program modifications. Most assemblers also include macro facilities for performing textual substitution—e.g., to generate common short sequences of instructions as inline, instead of called subroutines, or even generate entire programs or program suites.

The assembler

The assembler works in two passes:   pass1     input scanning, collect symbols, generate token list   pass2     generate object code from the token list

OPTAB: operation code table

SYMTAB: symbol table

LOCCTR: location counter

It consists of three web pages, the first page of which shows how the textual program input from a key-board is converted into ASCII-code and stored in the memory in binary form. The second page shows the scanning of the source assembly code to create the address symbol table. This is necessary to provide numerical values to the user defined-variables. The last page shows the operation of several table lookup procedures to convert assembly language statement into binary machinecode.

Conversion of text strings into ASCII-format

Page 6: 13695_HW2 CAP318

For easy access for humans characters are coded into positional format in a keyboard. Punching the keys humans describe a problem to be solved in a formal language (assembly language is used in this presentation). The description is made up of statements, which describe the algorithm to be executed. Statements consist of short text strings, items to represent actions to be taken and objects to be acted upon.

First pass of the assembler program

Structure of the assembly language: instruction set, commands, addressing modes etc. are completely defined by the designer. The user is tied up to these decisions. However, the user has complete freedom to give names to the variables s/he needs when describing the algorithm to be executed. During the first pass of the assembly process, a variable symbol table is created to store all the user variable names and associate a definite numerical address to be referenced during the second pass of the process.

Second pass of the assembler program

A two pass assembler does two passes over the source file (the second pass can be over a file generated in the first pass). In the first pass all it does is looks for label definitions and introduces them in the symbol table. In the second pass, after the symbol ta-ble is complete, it does the actual assembly by translating the op-erations and so on.

Page 7: 13695_HW2 CAP318

Q 3. What are various types of assemblers which can be developed?

ANSWER: 1Rudimentary two-pass Assembler

assume all opcodes and operands are one byte

assume all arguments are symbolic - translated to addresses

Two-Pass Assembler - additional considerations

❍Additional considerations

●symbolic names can be used for additional pur-pose as specification of addressing modes

●symbolic addresses can be used in expressions

●storage can be reserved for multiple arguments (as for an array). Storage can be differentiated for byte, word, etc. Alignment must be considered.

●Immediate values

❍immediate mode vs. literal pools

❍protect from changes

●numeric constants can be written as integers, decimals, etc. All must be converted to internal repre-sentation specific to the computer.

●address counter may start at 0. Alternatively, it may be reset multiple number of times using ORIGIN. Increasing the counter causes space allocation in the code

Page 8: 13695_HW2 CAP318

●Symbols may be scoped globally, locally in a module, or locally within a module. Global symbols and modular development requires extern-symbol-tables for linker.

3One-Pass Assembler●Except for forward references, all could be done in

a single pass.

●Forward references can be handled by creating links of references to fill: fill at end or when attributes become known.

4Load-and-go Assembler●it must run in a fixed location.

●it cannot be combined with other modules.

●there must be enough memory for the assembler and the code (the code must be in main storage to fa-cilitate filling backward the links)

5One-pass Module Assembler●usually, loader/linker will resolve internal forward and external references. For that, tables must be made available to it.

Q 4. Assembler can perform operations of search and sort? Give your comments?ANSWER: SORTING:-The following kinds(common) of searching algorithm are used in assemblers

Page 9: 13695_HW2 CAP318

1. Sorting algorithms: a. Simple exchange sort b. Classic bubble sort c. Simple insertion sort d. Recursive quick sort

We can implement several standard sorting algorithms in assembler. To make things a bit easier (subscripting), the items to sort are restricted to 1 byte numbers. In addition, we restrict to a 1-byte length on the ar-ray. This is not a restriction to the sorting. Much of the work is done in subprograms. The major subprograms are

1. PRINT a list of numbers with a choice of heading 2. Standard calls to INT 21H for I/O placed in subprograms 3. COPY an array of numbers into a second array of numbers 4. ATOI (ascii to integer) conversion for 1-byte quantities 5. ITOA (integer to ascii) conversion for 1-byte quantities

Searching

If an insulated application specifies an assembly dependency, side-by-side first searches for the assembly among the shared assemblies in the WinSxS folder. If the required assembly is not found, side-by-side then searches for a private assembly installed in a folder of the application's directory structure.

Assemblies may be arranged in the following locations in the applica-tion's directory structure:

In a language-specific subfolder in the application's folder. The name of the subfolder is a string of DHTML language codes indic-ating a language-culture or language

In the application's folder. Typically, this is the folder containing the application's executable file.

In a subfolder in the application's folder. The subfolder must have the same name as the assembly.

Page 10: 13695_HW2 CAP318

In a subfolder of a language-specific subfolder in the application's folder. The name of the higher subfolder is a string of DHTML lan-guage codes indicating a language-culture or language. The deeper subfolder has the same name as the assembly.

Part BQ1. What is the need for relocation of the program? With an example explain how relocation can be done.ANSWER:

There are some reasons for relocation of the program:1. Allocate space in memory for the programs.2. Resolve symbolic preference between object deck.3. Adjust all address-dependent location, such as address constants, to

correspond to the allocated space.4. Physically place the machine instructions and data into memory.

Example- How a program is loaded, beginning at address 0000.JSUB instruction is loaded at address 0006. Consider that the address field of this instruction contains 01036, which is the address of the instruction labeled RDREC. Now suppose we want to load this program beginning at address 5000 as shown in fig 2. The address of this instruction labeled RDREC is then 6036. Thus the JSUB instruction must be modified as shown to contain this newAddress. Likewise, if we loaded the program beginning at address 7420(Fig 3), the JSUB instruction would need to be changed to 4b108456 toCorrespond to the new address of RDREC.1. When the assembler generates the opcode for JSUB, we are considering, it will insert the address RDREC relative to the start of the program.2. The assembler will also produce a command for the loader, instructing it to add the beginning address of the program to the address field in the JSUB instruction at the load time.

(+JSUB RDREC) (+JSUB RDREC)

0000..0006..1036...1076

.

.

4B101036..B410...

5000..5006..6036..6076

.

.

4B101036. .B410

Page 11: 13695_HW2 CAP318

RDREC RDREC

Fig (1) Fig (2) (+JSUB RDREC)

RDREC

Q2. Enlist the various assembler features that are machine dependent and machine independent. Explain any one of them from each.ANSWER:

Machine dependent assembler features:

1) Instruction format 2) addressing modes3) Relocation

Instruction format and addressing mode:1. PC-relative or Base-relative addressing

Ex. op m

7420 ...7426..8456...8496

. ..4B101036..B410....

Page 12: 13695_HW2 CAP318

2. Indirect addressingEx. op @m

3. Immediate addressingEx. op #c

4. Extended format Ex. +op m

5. Index addressingEx. op m, x

6. Register-to-register instructions

Machine independent assembler features:1. Program blocks2. Control Session 3. Linking4. Literals

5. Symbol defining statements

6. Expressions7.

Control Section

• 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. (Main advantage)

• Different control sections are often used for subroutines or other logical subdivisions of a program.

• The programmer can assemble, load, and manipulate each of these control sections separately.

Program Linking

Page 13: 13695_HW2 CAP318

• Instructions in one control section may need to refer to instructions or data located in another control section. (Like external variables used in C language)

• Thus, program (actually, control section) linking is necessary.

• Because control sections are independently loaded and relocated, the assembler is unable to know a symbol’s address at assembly time. This job can only be delayed and performed by the loader.

• We call the references that are between control sections “external references”.

• The assembler generates information for each external reference that will allow the loader to perform the required linking.

Q3. What are the basic functions of a loader? Develop an algorithm for a bootstrap loader.Answer:

FUNCTIONS OF LOADER: -1. bringing an object program into memory2. starting its execution3. The loader is capable of loading modules in a range of object

formats, and knowledge of these formats is built in to the loader. 4. Knowledge of new object formats can be added to the loader in a

straightforward manner. This makes it possible to provide OS-independent modules (for a given CPU architecture type).

5. The loader is capable of loading modules in a range of object formats.

a. The knowledge of these formats is built in to the loader.

b. The knowledge of new object formats can be added to the loader in a straightforward manner.

6. This makes it possible to provide OS-independent modules (for a given CPU architecture type).

Page 14: 13695_HW2 CAP318

7. In addition to this, the loader can load modules via the OS-pro-vided dlopen (3) service where available. Such modules are not platform independent, and the semantics of dlopen () on most systems results in significant limitations in the use of modules of this type. Support for dlopen () modules in the loader is primarily for experimental and development purposes.

8. Special registration functions of loader are:

a. The loader contains some functions for registering some classes of modules. These may be moved out of the loader at some point.

b. Void Load Extension (Extension Module *ext)

c. This registers the entry points for the extension identified by ext.This registers the entry points for the font rasteriser module identified by font.

ALGORITHM FOR BOOTSTRAP LOADER: -

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

Page 15: 13695_HW2 CAP318

GETC A? Read one character If A=0x04 then jump to 0x80 If A<48 then GETC A? A-48 (0x30) If A<10 then return A? A-7 Return

Q4. What is machine dependent loader? Explain its features.ANSWER; Absolute Loader – Simple and efficient

Disadvantage is – programmer has to specify the starting address

One program to run – no problem – not for several

Difficult to use subroutine libraries efficiently

Program Linking Goal - Resolve the problems with EXTREF and EXTDEF from different control sections Use modification records for both relocation and linking - Address constant

- External reference