Вы находитесь на странице: 1из 42

UNIT I

SYSTEMS PROGRAMMING
Systems programs includes use of system software's which

were developed to make computers better adapted to the needs of the users. SP introduces the more formal aspects of computer science including the presentation of formal systems & their application to programming languages. System software contains a variety of programs that support the operation of computer. Some of the system programs are Compilers, Loaders, macros processors, assemblers and OS. The 2 important concepts in SP are:: 1) Learn procedure for the design of software systems. 2) Provide a basis for judgment in the design of software.

PEOPLE
APPLICATION PROGRAMMING MACRO ASSEMBLER COMPILERS PROCESSOR S S TEXT DEBUGGIN SEARCHING LOADERS EDITORS G AIDS & SORTING I/O PROG
FILE SYSTEM S SCHEDU LAR DEVICE LIBRA MEMORY MANAGEMEN RIES MANAGEMENT T

FIG:: - FOUNDATIONS OF SYSTEMS PROGRAMMING.


3

COMPUTERS & SOFTWARE TYPES


Application software is designed to solve a

specific problem with the help of computer users. 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 application software. Provides the mechanisms for application software to share the hardware in an orderly fashion.
4

The following represents the need for the System

Need of System Software

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 for development of programs. 5) To interact between user & computer hardware. 6) To make effective utilization of resources. Some of the system programs are : 1) ASSEMBLER 2) COMPILER 3) LOADER 4) MACRO PROCESSOR.
5

The assembly language program must be translated into machine language program by a separate program called as ASSEMBLER. The following diagram represents the working of a Assembler as:
SOURCE CODE

ASSEMBLER

ASSEMBLER

OBJECT CODE

LINKER
EXECUTABLE CODE

DATABASE S

LOADER
6

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.
7

ASSEMBLER DIRECTIVES
Assembler directives instruct the assembler to

perform certain actions during assembly of a program. They can be used to declare variables, create storage space for results, & to declare constants. The following are the assembler directives used in program:: START, END, BYTE, WORD.

COMPILER
Compiler is a system software that accepts source program a high-level language & produces a corresponding object code Compiler replaces single-level statement with a series of machine language instructions. Compiler resides on a disk or on other storage media. When a program is to be compiled, its compiler is loaded into the main memory. During the time of translation, the compiler reads the source program & checks Syntax(grammatical) errors. If any error is found, the compiler generates an error message. Once the program has been compiled, the resulting machine code is saved separately, and can run on its own at any time.
9

Language translation is achieved using Compilers, Interpreters and etc COMPILER


TARGET LANGUAGE PROGRAM. HIGH-LEVEL (MACHINE OBJECT PROGRAM COMPILER CODE) (SOURCE ERROR CODE) MESSAGES FIG: WORKING OF A COMPILER

10

INTERPRETER
The following diagram represents the working of an interpreter.
RESULT OF THE EXECUTED STATEMENTS.

HIGH-LEVEL PROGRAM (SOURCE CODE)

INTERPRETER

ERROR MESSAGES FIG: WORKING OF A INTERPRETER

An Interpreter is a Language Translator, that translates high level language program into machine language program.
11

COMPILER -- Vs -- INTERPRETOR
BASIS
OBJECT CODE

COMPILER
SEPARATE OBJECT PROGRAM

INTERPRETER
NO PERMAMENTLY SAVED OBJECT CODE FILE. LINE BY- LINE TRANSLATION. DEBUGGING BECOMES EASIER & FAST.

TRANSLATION CONVERTS ENTIRE PROGRAM PROCESS INTO MACHINE LANGUAGE AT ONE GO. DEBUGGING ERASE IMPLEMENTATION REMOVAL OF ERRORS (DEBUGGING) IS SLOW.

COMPLEX PROGRAMS. LESS COMPLEX. REQUIRES REQUIRES MORE MEMORY TO LESS MEMORY TO EXECUTE A EXECUTE A PROGRAM. PROGRAM. FAST & EACH STMT. IS SLOWER & EACH STMT IS TRANSLATED ONLY ONCE & TRANSLATED EVERY TIME IT SAVED IN OBJ FILE, WHICH IS EXECUTED FROM THE CAN BE EXECUTED AGAIN SOURCE PROGRAM. WITHOUT TRANSLATING
12 12

EXECUTION TIME

LOADER
Loaders are part of OS that brings an executable file residing on disk into memory and starts running. A loader is a system program that performs the function of a linker and then immediately schedules the executables for execution, without creating the executable file as an output. There are 4 Functions of a Loader as: 1. ALLOCATION:- allocates memory space for prgs. 2. LINKING:- Resolve symbolic references between object code. 3. RELOCATION:- execute program from its storage area. 4. LOADING:- place data, machine instructions into memory 13

Loader loads the program into memory using the

LOADING SCHEMES

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

MACROS
To relieve programmers of the need to repeat identical parts of their programs, OS provides a macro-processing facility. Macros permits the programmer to define an abbreviation for a part of his program and to use this abbreviation in the program. The macro-processor treats the identical parts of the program defined by the abbreviations as a macro-definitions & saves them. The macro-processor then substitutes the definition for all occurrences of the macro call in the program. Macro facilities have been used as a general text handlers & for specializing OS to individual computer installations. In system generation, the entire OS is written as a 15 series of macro-definitions.

An operating system is a collection of system programs that together controls the operation of a computer system. It acts as an interface between the user and a computer hardware. 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 can communicate with the hardware. Most common OS are 1)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

OPERATING SYSTEM

1.Managing Computers Hardware


A COMPUTER SYSTEM

OPERATING SYSTEM I/O MEMOR CONTROLLE Y R HARD DISK PROCESSO R

I/O DEVICES

Fig: Operating System managing hardware resources.


17

2.Providing an Interface

END USER

APPLICATION PROGRAMS UTILITIES OPERATING SYSTEM COMPUTERS HARDWARE Fig: Computer System Components
18

TYPES OF OPERATING SYSTEMS


OS can be classified into 6 broad categories:

1. 2. 3. 4. 5. 6.

Batch-Processing OS. Time-Sharing (or) Multi user OS. Multi Tasking OS. Real Time OS. (or) RTOS. Multi Processor OS. Embedded OS.

19

FUNCTIONS OF OPERATING SYSTEM The 6 main functions of an OS are:


1. 2. 3. 4. 5. 6. 7.

Resource Allocation Process Management. Memory Management. Device Management. Security Management. Error handling. I/O programming.

20

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 called rules 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 programming languages.
21

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

UNIT I ( PART 2) ASSEMBLER


23

STRUCTURE OF AN ASSEMBLER
DATA STRUCTURES Sourc e PASS - I

Target PASS - II

Intermediate code Data access Control Transfer Fig:: Overview of two pass assembly.

24

STRUCTURE OF AN ASSEMBLER (Cont..)


1) TWO-PASS TRANSLATION

Can handle forward references easily. LC processing is performed in the first pass & symbols

defined in the program are entered in the symbol table. 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 representation contains 2 main components:: Data structures.

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


25

STRUCTURE OF AN ASSEMBLER (Cont..)


2) SINGLE PASS TRANSLATION LC processing & construction of Symbol table as 2pass. 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 address of the forward referenced symbol is put into the field when its definition is encountered.

26

FIRST PASS OF THE ASSEMBLER.

27

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 up the Symbol table. Memory allocation is done using LC. LC points to the next memory word in target code even when machine instructions have variable lengths.
28

BASIC FUNCTION OF THE ASSEMBLER.


2. Synthesis phase
For performing synthesis operation on machine code

we need ::1) Address of memory word. (depends on source pgm.) 2) Machine Op-code corresponding to mnemonics. (assembly language) The data-structures used during synthesis are::1) Symbol Table 2) Mnemonics table. The following diagram represents these data structures as :

29

DATA STRUCTURE OF AN ASSEMBLER.


Mnemonic ADD SUB Op code 01 02 Length 1 1

Sourc e Analysis Phase

Mnemonics Table

Target

Synthesis Phase Symbol Table


AGAIN N 104 113

Data access Control


30

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 reference symbols 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.


Sr. No 1 2 3 4 5 6 7 8 9 11 BACK: M N ADD SUB ADD JMP END PROGRAM LC VALUE 1000 1001 1002 08,[1002] 1003 01,[1001] 1004 05,[ ------] 1005 02,[1000] 1006 07,[------] 1007 01,[1000] 1008 04,[1003] 1009 09,[1001] 1010
32

TARGET LISTING

DB DB N M M

1 2 M

LOAD

JNE FORWARD JZ FORWARD BACK

10 FORWARD: STORE N

EXAMPLE:: - SINGLE PASS ASSEMBLER.


The FRT/TII table will look as :: SYMBOL NAME FORWARD ATTRIBUTE ADDRESS OF DEFINATION L 1009 USAGE ADDRESS 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 external storage is slow or inconvenient to use.
33

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
ASSEMBLY LANGUAGE CODE FOR MACHINE A CROSS ASSEMBLER MACHINE LANGUAGE CODE OF MACHINE A

MACHINE B

Fig:: - CROSS ASSEMBLER


It Generates machine language for a different computer than the one in which the assembler is running in. Used to develop programs for computers on a chip or micro-processor used in specialized applications.

35

ASSEMBLER
The following steps should be followed by the

designer:: 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.


SOURCE PROGRAM RAM START 0 USING *, 15 L 1, FIVE A 1,FOUR ST 1, TEMP FOUR DC F4 FIVE DC F5 TEMP DS 1F END FIRST PASS SECOND PASS

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

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

FIG :: - Intermediate steps in Assembling a Program. FIRST PASS defines the symbols. SECOND PASS Generates instructions & addresses.37

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 & assign addresses. 2) Process Pseudo-ops.

38

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.


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 READ LABE L ON CARD YES NO SEARCH PSEUDO-OP FOUND TABLE (POT) POTGET NOT FOUND SEARCH MACHINE-OP TABLE (MOT) MOTGET GET LENGTH OF INSTRUCTION
FIG: PASS

STORE LABEL IN ST WITH LC VALUE STSTO

USING DROP END GOTO PASS

TYPE ? DS DC DETERMINE LENGTH OF DATA SPACE REQUIRED

PROCESS LITERALS LITSTO

UPDATE LOCATION COUNTER


41

OVERVIEW: DEFINE SYMBOLS

INITIALIZE READ POTGET NOT FOUND MOTGET GET LENGTH ON LENGTH, TYPE & BINARY CODE STGET ASSEMBLE TOGETHER PARTS OF INSTRUCTION

FIG: PASS

EVALUATE FIELDS & GENERATE CODE.

FOUND CONVERT & O/P CONSTANTS.

TYPE ?

DS USING

END CLEAN UP & EXIT

DETERMINE LENGTH OF DATA SPACE

INDICATE AVAILABLE BASE REGISTER (BT) INDICATE UNAVAILABLE BASE REGISTER (BT)

UPDATE LOCATION COUNTER

DROP

42

Вам также может понравиться