sp-i(new)

42
UNIT I

Upload: mb4u

Post on 07-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 1/42

UNIT I

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 2/42

SYSTEMS PROGRAMMINGSYSTEMS PROGRAMMINGSystems programs includes use of system software's which

were developed to make computers better adapted to theneeds of the users.

SP introduces the more formal aspects of computer scienceincluding the presentation of formal systems & theirapplication to programming languages.

System software contains a variety of programs that supportthe operation of computer.

Some of the system programs are Compilers, Loaders,macros processors, assemblers and OS. The 2 importantconcepts in SP are:: -

1) Learn procedure for the design of software systems.

2) Provide a basis for judgment in the design of software.

2

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 3/42

3

I/OPROG

FILESYSTEM

S

DEVICEMANAGEMEN

T

LIBRARIES

MEMORY MANAGEMENT

SCHEDULAR

LOADERSTEXT

EDITORS

SEARCHING

& SORTING

DEBUGGIN

G AIDS

COMPILERS ASSEMBLERS

MACRO -PROCESSORS

APPLICATION PROGRAMMING

PEOPLE

FIG:: - FOUNDATIONS OF SYSTEMS PROGRAMMING.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 4/42

4

COMPUTERS & SOFTWARE TYPES

Application software is designed to solve a

specific problem with the help of computerusers.

Developed by experts or software developer.

System software provides a general

programming environment to the user. Operating system is a subset of the system

software.

Provide functions used by the applicationsoftware.

Provides the mechanisms for applicationsoftware to share the hardware in an orderly

fashion.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 5/42

Need of System Software  The following represents the need for the System

software:

1) To achieve efficient performance of system.

2) To make effective execution of general user program.

3) To make effective utilization of human resource.

4)  To make available new & better facilities fordevelopment of programs.

5) To interact between user & computer hardware.

6) To make effective utilization of resources.

Some of the system programs are :

1)ASSEMBLER2)COMPILER

3)LOADER

4)MACRO – PROCESSOR.

5

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 6/42

6

 ASSEMBLER The assembly language program must be translatedinto machine language program by a separate

program called as “ASSEMBLER”.  The following diagram represents the working of aAssembler as:

ASSEMBLER

SOURCECODE

OBJECT CODE LINKER

LOADER

EXECUTABLECODE

DATABASES

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 7/427

FUNCTIONS OF AN ASSEMBLER There are seven functions of an Assembler as:

1)Allows programmer to use mnemonics while writing

source code & translate them into machine lang.2)Convert symbolic operands to their machine

locations.

3)  Translates mnemonic operation codes to machine

language.4)Checks the syntax of assembly program and

generates diagnostic messages on syntax screen.

5)Assembles all the instructions in main memory for

execution.6)In case of larger assembly programs, it also provides

linking facility among the sub-routines.

7)Facilitates generation of output on required output

medium.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 8/42

 ASSEMBLER DIRECTIVES

Assembler directives instruct the assembler toperform certain actions during assembly of a

program. They can be used to declare variables,create storage space for results, & to declareconstants.

  The following are the assembler directives used

in program:: - START, END, BYTE, WORD.

8

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 9/429

COMPILER

Compiler is a system software that accepts sourceprogram “a high-level language” & produces a

corresponding object codeCompiler replaces single-level statement with a seriesof machine language instructions.

Compiler resides on a disk or on other storage media.

When a program is to be compiled, its compiler isloaded into the main memory.

During the time of translation, the compiler reads thesource program & checks Syntax(grammatical) errors.

If any error is found, the compiler generates an errormessage. Once the program has been compiled, theresulting machine code is saved separately, and canrun on its own at any time.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 10/4210

Language translation is achieved using Compilers,

Interpreters and etc…COMPILER

COMPILERHIGH-LEVELPROGRAM(SOURCE

CODE) ERRORMESSAGES

TARGETLANGUAGE

PROGRAM.(MACHINE OBJECTCODE)

FIG: WORKING OF A COMPILER

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 11/4211

INTERPRETER

HIGH-LEVELPROGRAM(SOURCE

CODE) ERRORMESSAGES

RESULT OF THEEXECUTED

STATEMENTS.

FIG: WORKING OF A INTERPRETER

INTERPRETER

An Interpreter is a Language Translator, thattranslates high level language program into machinelanguage program.

The following diagram represents the working of an

interpreter.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 12/4212

COMPILER -- Vs -- INTERPRETORBASIS COMPILER INTERPRETER

OBJECTCODE

SEPARATE OBJECT PROGRAM NO PERMAMENTLY SAVEDOBJECT CODE FILE.

 TRANSLATIONPROCESS

CONVERTS ENTIRE PROGRAMINTO MACHINE LANGUAGE AT

ONE GO.

LINE –BY- LINE TRANSLATION.

DEBUGGINGERASE

REMOVAL OF ERRORS(DEBUGGING) IS SLOW.

DEBUGGING BECOMESEASIER & FAST.

IMPLEMEN- TATION

COMPLEX PROGRAMS.REQUIRES MORE MEMORY TO

EXECUTE A PROGRAM.

LESS COMPLEX. REQUIRESLESS MEMORY TO EXECUTE A

PROGRAM.

EXECUTION TIME

FAST & EACH STMT. IS TRANSLATED ONLY ONCE &SAVED IN OBJ FILE, WHICHCAN BE EXECUTED AGAINWITHOUT TRANSLATING

SLOWER & EACH STMT IS TRANSLATED EVERY TIME IT

IS EXECUTED FROM THESOURCE PROGRAM.

12

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 13/42

13

LOADER

Loaders are part of OS that brings an executable fileresiding on disk into memory and starts running.

A loader is a system program that performs thefunction of a linker and then immediately schedulesthe executables for execution, without creating theexecutable file as an output.

 There are 4 Functions of a Loader as:1. ALLOCATION:- allocates memory space for prgs.

2. LINKING:- Resolve symbolic references betweenobject

code.3. RELOCATION:- execute program from its storage

area.

4. LOADING:- place data, machine instructions into

memory

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 14/42

LOADING SCHEMESLoader loads the program into memory using the

following loading schemes: -

1)“ Compile-And-Go” loaders.2)General Loading scheme.

3)Absolute Loader.

4)Subroutine – Linkages.

5)Relocating Loaders.

6)Direct – Linking loaders.

Other loading Schemes contains ::

1)Binders.2)Linking loaders.

3)Overlays.

4)Dynamic Binders. 14

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 15/42

MACROS  To relieve programmers of the need to repeatidentical parts of their programs, OS provides a

macro-processing facility.Macros permits the programmer to define anabbreviation for a part of his program and to usethis abbreviation in the program.

  The macro-processor treats the identical parts of the program defined by the abbreviations as amacro-definitions & saves them.

 The macro-processor then substitutes the definitionfor all occurrences of the macro call in the program.

Macro facilities have been used as a general texthandlers & for specializing OS to individualcomputer installations.

In system generation, the entire OS is written as aseries of macro-definitions. 15

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 16/42

16

OPERATING SYSTEM“An operating system is a collection of system programsthat together controls the operation of a computersystem”.

It acts as an interface between the user and a computerhardware.

It has two objectives:

1. It controls computer hardware.2. To provide an interactive interface to the user and

interpret commands so that the user cancommunicate with the hardware.

Most common OS are1)Windows family of OS developed by Microsoft.

2)Macintosh operating systems developed by Apple.

3)UNIX family of operating systems &

4) LINUX family of operating system. 16

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 17/42

17

1.Managing Computer’s Hardware

A COMPUTER SYSTEM

MEMOR Y 

HARD

DISK 

I/OCONTROLLE

R

PROCESSO

R

I/ODEVICES

OPERATING SYSTEM

Fig: Operating System managing hardware

resources.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 18/42

18

2.Providing an Interface

COMPUTER’S HARDWARE

OPERATING SYSTEM

UTILITIES

APPLICATIONPROGRAMS

END USER

Fig: Computer System Components

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 19/42

19

TYPES OF OPERATING SYSTEMSOS can be classified into 6 broad categories:

1. Batch-Processing OS.

2. Time-Sharing (or) Multi – user OS.

3. Multi – Tasking OS.

4. Real – Time OS. (or) RTOS.5. Multi – Processor OS.

6. Embedded OS.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 20/42

20

FUNCTIONS OF OPERATINGSYSTEM The 6 main functions of an OS are:

1. Resource Allocation2. Process Management.

3. Memory Management.

4. Device Management.

5. Security Management.

6. Error handling.

7. I/O programming.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 21/42

FORMAL SYSTEMS

A formal system is an un-interpreted calculus

which consists of an alphabet, a set of axioms(words) & a finite set of relations calledrules of interference.

Ex:: - Set theory, Boolean algebra etc.

Formal systems are used to specify the syntax& semantics of the programming languages.

  They have been used in syntax-directed

compilations, compiler verification &complexities studies of programminglanguages.

21

T l t & T

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 22/42

Translator & Types  Translators are the system programs that

translates the source language into machine

understandable code. There are 2 types of translators::-

1) Single pass translator.

2) Multi pass translator.

22

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 23/42

UNIT – I ( PART

2)ASSEMBLER

23

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 24/42

STRUCTURE OF AN ASSEMBLER

24

PASS - I

DATASTRUCTURES

PASS - II

Intermediate code

Fig:: Overview of two pass assembly.

Sourc

e

Targe

Data access

Control

Transfer

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 25/42

STRUCTURE OF AN ASSEMBLER (Cont..)1) TWO-PASS TRANSLATION

Can handle forward references easily.

LC processing is performed in the first pass & symbolsdefined in the program are entered in the symboltable.

 The Second pass synthesizes the target program using

the address information in Symbol table.First pass performs analysis of source program &

Second pass performs synthesis of target program.

First pass builds an intermediate representation (IR) of 

source, that can be used in Pass 2. This representationcontains 2 main components::-

Data structures. Ex – Symbol table.

Processes form of source program(i.e. Target code)

25

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 26/42

STRUCTURE OF AN ASSEMBLER (Cont..)

2) SINGLE PASS TRANSLATION

LC processing & construction of Symbol table as 2-

pass.Problem of forward reference is tackled using a

process called as “Back-Patching”.

  The Operand field of an instruction containing a

forward reference is left blank initially, & the addressof the forward referenced symbol is put into the fieldwhen it’s definition is encountered.

26

FIRST PASS OF THE ASSEMBLER

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 27/42

FIRST PASS OF THE ASSEMBLER.

27

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 28/42

BASIC FUNCTION OF THE ASSEMBLER.

 Translation is done in 2 phases::-

1. Analysis phase.

2. Synthesis phase.

1. Analysis phase:-

Determine address of symbol names & build upthe Symbol table.

Memory allocation is done using LC.

LC points to the next memory word in targetcode even when machine instructions havevariable lengths.

28

BASIC FUNCTION OF THE ASSEMBLER

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 29/42

BASIC FUNCTION OF THE ASSEMBLER.

2. Synthesis phaseFor performing synthesis operation on machine code

we need ::-

1) Address of memory word. (depends on sourcepgm.)

2) Machine Op-code corresponding to mnemonic’s.

(assembly language) The data-structures used during synthesis are::-

1) Symbol Table

2) Mnemonics table.

  The following diagram represents these datastructures as :

29

DATA STRUCTURE OF AN ASSEMBLER

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 30/42

DATA STRUCTURE OF AN ASSEMBLER.

30

AnalysisPhase SynthesisPhase

Sourc

e

Targe

Data access

Control

Mnemonic Op code Length

ADD 01 1

SUB 02 1

Mnemonics Table

AGAIN 104N 113

Symbol Table

ASSEMBLER TYPES

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 31/42

ASSEMBLER TYPES

1) Single pass assembler.

2) Multi-pass assembler.

3) Cross pass assembler.

SINGLE PASS ASSEMBLER. Sequential scan over input.

 Translation is done in single pass.

Main problem faced here is “Forward reference”.

Solution ::- User can put all forward referencesymbols in a separate table called as “Forward

Reference Table/ Table of Incomplete Instructions(FRT/TII)”.

Creating this table eliminates the usage of Pass-2.

31

EXAMPLE:: SINGLE PASS ASSEMBLER

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 32/42

EXAMPLE:: - SINGLE PASS ASSEMBLER.Sr.No

PROGRAM LCVALUE

TARGETLISTING

1 M DB 1 1000

2 N DB 2 1001

3 LOAD M 1002 08,[1002]

4 BACK: ADD N 1003 01,[1001]

5 JNE FORWARD 1004 05,[ ------]

6 SUB M 1005 02,[1000]

7 JZ FORWARD 1006 07,[------]8 ADD M 1007 01,[1000]

9 JMP BACK 1008 04,[1003]

10 FORWARD: STORE N 1009 09,[1001]

11 END 1010 32

EXAMPLE:: - SINGLE PASS ASSEMBLER

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 33/42

EXAMPLE:: - SINGLE PASS ASSEMBLER. The FRT/TII table will look as :: -

33

SYMBOLNAME

ATTRIBUTE ADDRESS OFDEFINATION

USAGEADDRESS

FORWARD L 1009 1004

1006 NULL

  This technique of handling Forward references is

called as “Back-patching”. APPLICATION OF ONE-PASS ASSEMBLER

One pass assemblers are useful where externalstorage is slow or inconvenient to use.

MULTI PASS ASSEMBLER

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 34/42

MULTI-PASS ASSEMBLER

Multi-pass assembler is a solution to problem of 

forward reference.Example: : -

ALPHA EQU BETA

BETA EQU DELTA

DELTA EQU 1

Can perform multiple passes.(usually 2 passes).Allows to use forward references in ORIGIN

statement tools.

34

CROSS PASS ASSEMBLER

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 35/42

CROSS-PASS ASSEMBLER

It Generates machine language for a different computerthan the one in which the assembler is running in.

Used to develop programs for computers on a chip ormicro-processor used in specialized applications.

35

CROSSASSEMBLER

ASSEMBLY LANGUAGE

CODE FORMACHINE A

MACHINELANGUAGE

CODE OFMACHINE A

MACHINE B

Fig:: - CROSS ASSEMBLER

ASSEMBLER

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 36/42

ASSEMBLER

  The following steps should be followed by thedesigner:: -

1)Specify the problem.

2)Specify the data structures.

3)Define format of Data-structures.

4)Specify Algorithm.5)Look for modularity (i.e. capability of 1 prg, to be

subdivided into independent programming units)

6)Repeat steps 1 through 5 on modules.

36

1. SPECIFICATION OF THE PROBLEM.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 37/42

1. SPECIFICATION OF THE PROBLEM.

SOURCEPROGRAM

FIRST PASS SECOND PASS

RAM START 0USING *, 15L 1, FIVEA 1,FOURST 1, TEMP

FOUR DC F’4’FIVE DC F’5’

  TEMP DS 1FEND

 

0 L 1,_(0,15)4 A 1,_(0,15)8 ST 1,_(0,15)

12 416 520 --

0 L 1, 16(0,15)4 A 1, 12(0,15)8 ST 1, 20(0,15)

12 416 520 --

37

FIG :: - Intermediate steps in Assembling aProgram.

  FIRST PASS – defines the symbols.

SECOND PASS – Generates instructions & addresses.

1 SPECIFICATION OF THE PROBLEM

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 38/42

1. SPECIFICATION OF THE PROBLEM.

Assembler must perform following steps::-

1) Generate instructions.a)Evaluate mnemonics in operation field to

produce its machine code.

b)Evaluate the sub-fields. – find values of each symbol, process literals & assignaddresses.

2) Process Pseudo-ops.

38

1 SPECIFICATION OF THE PROBLEM

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 39/42

1. SPECIFICATION OF THE PROBLEM.

PASS-I:- Purpose define symbols & literals.

1) Determine length of machine instructions

(MOTGET 1).

2) Keep track of Location Counter (LC).

3) Remember values of symbols until Pass-2

(STSTO).

4) Process some pseudo-ops. Ex:- EQU, DS.

(POTGET1).

5) Remember Literals (LITSTO).

39

1. SPECIFICATION OF THE PROBLEM.

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 40/42

1. SPECIFICATION OF THE PROBLEM.

PASS-II:- Generation of Object Program.

1)Look-up value of symbols(STGET)

2)Generate Instructions (MOTGET2)

3)Generate data (for DS,DC & Literals)

4)Process Pseudo-ops (POTGET2).

40

INITIALIZE

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 41/42

FIG: PASS 1 OVERVIEW: DEFINE SYMBOLS 41

INITIALIZE

POTGET

SEARCH

PSEUDO-OPTABLE (POT)

READ

LABEL ONCARD

MOTGET

SEARCHMACHINE-OP

TABLE (MOT)

LITSTO

PROCESSLITERALS

STSTO

STORE LABEL IN

ST WITH LCVALUE

UPDATELOCATIONCOUNTER

GET LENGTHOF

INSTRUCTION

DETERMINELENGTH OF DATASPACE REQUIRED

TYPE ?GOTO PASS

2

USINGDROP

END

FOUND

 YESNO

NOT FOUND

DSDC

FIG: PASS EVALUATE FIELDS & GENERATE CODE.INITIALIZE

8/6/2019 SP-I(NEW)

http://slidepdf.com/reader/full/sp-inew 42/42

INITIALIZE

POTGET

READ

MOTGET

UPDATELOCATION

GET LENGTHON LENGTH,

TYPE & BINARY CODE

TYPE ?

END

FOUND

NOT FOUND

STGET

ASSEMBLETOGETHER

PARTS OFINSTRUCTION INDICATE UNAVAILABLE

BASE REGISTER (BT)

INDICATE AVAILABLEBASE REGISTER (BT)

DETERMINE LENGTHOF DATA SPACE

CONVERT & O/PCONSTANTS.

CLEANUP &EXIT

      D      S 

      U       S       I      N      G 

      D      R      O       P