Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
45 views95 pages

SPOS - Unit 1 (Introduction)

The document outlines the fundamentals of system programming, focusing on system software and its components, including assemblers, loaders, compilers, and interpreters. It discusses the roles of system software in hardware management, application support, and network management, as well as the structure and features of assembly language. Additionally, it covers various programming tools and concepts essential for effective system programming.

Uploaded by

Tanishka Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views95 pages

SPOS - Unit 1 (Introduction)

The document outlines the fundamentals of system programming, focusing on system software and its components, including assemblers, loaders, compilers, and interpreters. It discusses the roles of system software in hardware management, application support, and network management, as well as the structure and features of assembly language. Additionally, it covers various programming tools and concepts essential for effective system programming.

Uploaded by

Tanishka Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 95

SPOS

Course Outcome
Unit- I

To analyze & synthesize various


system software & understand the
design of two pass assemblers.
SPOS
Introduction
Unit- I

● System is Collection of Component. e.g.College

● Programming is way to instruct the computer to perform various task.

● system programming is an art of designing and implementing system


Programs
SPOS
Outline
Unit- I

Introduction Assemblers

Software
SPOS
System introduction
system programming is an art of designing and implementing system Programs. Unit- I

Programming
is
System
is Way to

Collection
instruct

Component of To perform
compute
College the
eg.

Various Task
SPOS
Software Hierarchy
Unit- I

Software
Software

is

System Application
Collection
Software Software
of
assist general software developed
Many user application for the specific goal
Programs
Operating System Media player

Assembler Adobe Reader


Foundation of system Programming
General Machine Structure
Need Of System Software
Hardware Management:

● System software, particularly the operating system (OS), acts as an intermediary between
the hardware and the user. It manages hardware resources such as the CPU, memory,
storage devices, and input/output devices.
● It ensures efficient and fair allocation of resources among various applications.

Application Support:

● Provides a platform for running application software.


● Offers necessary services and libraries required by applications to function correctly.

Network Management:

● Facilitates networking capabilities, enabling communication between computers and other


devices.
● Manages network connections, data transmission, and network security.
Need Of System Software
Device Drivers:

● Includes device drivers that facilitate communication between the OS and hardware devices.
● Ensures proper functioning and compatibility of peripheral devices like printers, scanners, and
network adapters.

Software Updates and Maintenance:

● Handles software updates, patches, and maintenance tasks to keep the system secure and
up-to-date.
● Ensures that the system software remains compatible with new hardware and applications.

File Management:

● Organizes and manages files on storage devices.


● Provides functionalities like file creation, deletion, reading, writing, and permissions
management.
SPOS
System introduction
Unit- I

System Program
are System Programming

Required Is an art of
for

Effective Execution designing and implementing


system programs
of

General user Programs


on

Computer System
Components of Systems SPOS

Programming: Unit- I

● Text Editors,
● Loader and Linker
● Assembler,
● Compiler,
● Macros,
● Debugger,
● Interpreter,
● Device Drivers,
● Operating System.
SPOS
System Software
Unit- I

Text Editor
With the help
is

program

Used for
of
Editing plain Text Editor
text files
You can Example
Write Your C | Java
Program Prog.
SPOS
System Software
Unit- I
Example
Text Editor Notepad

Text Editor
Editor
is
is
Program
Computer
Program
In which
That allows Character
Primary
to String
A user Elements
create and revise a
document
being Edited are
SPOS
System Software
Unit- I

Loders

is

Program Them for


As input Prepares Execution
That takes

Object Code
and Initiates

Execution
it
SPOS
System Software
Unit- I

Loders Functions

Allocation
Linking

Relocation Loading
SPOS
System Software
Unit- I

Loders Functions

Allocation
Loader allocates space for programs in main
memory.
SPOS
System Software
Unit- I

Loders Functions

● Adjusting all address dependent location.

Relocation ● E.g. If we have two Programs Program A and Program B.

● Program A is saved at location 100.

● And user wants to save Program B on same location.


That is physically not possible.

● So loader relocates program B to some another free


location
SPOS
System Software
Unit- I

Loders Functions

Linking
● If we have different modules of our
program.

● Loader links object modules with each


other.
SPOS
System Software
Unit- I

Loders Functions

Loading
Physically loading the machine instructions and
data into main memory.
SPOS
Assembler
Unit- I

Assembly Lang.
Program Assembler Machine Lang.

Translate
SPOS
Macro Processor
Unit- I

Macro

Allows

Defined @ once
Referred many times

To be

Sequence
of Source Lang. Code
SPOS
Macro Processor
Unit- I

Syntax

Macro Macro name [ set of parameters ]

// macro body
★ A macro processor takes a source with
Mend macro definition and macro calls and
replaces each macro call with its body
SPOS
5. Macro Processor
Unit- I

● It allows the programmer to write shorthand version of a program .

● Macro allows a sequence of source language code to be defined once and then
referred to by name each time it is to be referred.

● Each time this name Occurs in a program, the sequence of codes is
substituted at that point.
Unit-1
Macro code -- Example

Source Expanded source


MACRO STRG

{
.
STADATA1 . STA DATA1
STBDATA2 STBDATA2
STX DATA3
STXDATA3
MEND
.

{
.
STA DATA1
STRG
. STBDATA2
STRG STXDATA3
. .
.
SPOS
Compiler
Unit- I

High Level Lang.


Compiler Low Level Lang.

Converts
SPOS
Compiler
Unit- I

Benefits of writing a program in a high level language

Increases productivity Machine Independence

It is very easy to write a program in a A program written in a high level language is


high level language machine independent.
SPOS
Debugger
Unit- I

Debugging tool helps programmer for testing and debugging programs

It provides some facilities:

•Setting breakpoints.

•Displaying values of variables.


Unit-1
7. Interpreter

● A Interpreter reads the source code one instruction or line at a this


line into machine code or some intermediate form and executes it.

Machine
Program
Interpreter language
statement
statement
Statement
execution
Fig.: Interpreter
8. Operating system (OS)

● An operating system (OS) is system software that


manages computer hardware, software resources, and
provides common services for computer programs.
9. Device driver (OS)
● Device driver is a computer program that
operates or controls a particular type of device
that is attached to a computer .
Assembly Language
SPOS
Assembly Language
Unit- I

● Assembly language is middle level language.

● An assembly language is machine dependent.

● It differs from computer to computer.

● Writing programs in assembly language is very easy as compared to


machine(binary) language
● Assembly lang. a symbolic representation of machine language.
● uses a mnemonic to represent each low-level machine instruction or
operation.
● Assemblers with different syntax for a particular CPU or instruction
set architecture.
● Example:- An instruction to add memory data to
a register
x86-family processor: add eax,[ebx],
whereas this would be written addl (%ebx),%eax
in the AT&T syntax used by the GNU Assembler.
SPOS
Assembly Language
Unit- I

Assembly language programming Terms


(LC)
Location Counter points to the next instruction

Literals Constant Values


SPOS
Assembly Language
Unit- I

Assembly language programming Terms

Symbols Name of variables and labels

Procedures Methods | Function


Unit-1

Elements of assembly language programs:


A. Basic features
B. Statement format
C. Operation code
Unit-1
A.Basic features
• Assembly lang. Provides 3 basic features:
1. Mnemonic Operation Codes(Opcodes)
Ex: MOVER or MOVEM

2. Symbolic Operand:
Ex: DS – Declare as storage
DC – Declare as Constant

3. Data Declaration:
Ex: X DC ‘-10.5’ Sytem Programming
Unit-1
B.Statement Format
Statement Format:
[Label] <opcode> <operand1> [ <operand2>..]

Label-Optional
Opcode- it contain symbolic operation code
Operand- Operand can also be a CPU register: AREG,
BREG,CREG.
Example-
LOOP : MOVER AREG, ‘=5’
Unit-1
Machine supports 11 Different Operations
Symbolic opcode Remark
STOP Stop Excecution
ADD Operand 🡺 Oper1+Oper2
SUB Operand 🡺 Oper1- Oper2
MULT Operand 🡺Oper1*Oper2
MOVER CPU Register🡺Memory move
MOVEM Memory operand🡺CPU register
COMP Set condition code
Comparison instruction sets a condition code
The condition code can be tested by BC
BC Branch on condition
Format for BC : BC <condition code spec.>, <Memory address>
1. LT-Less than
2. LE-Less or equal
3. EQ-Equal
4. GT-Greater than
5. GE-Greater or equal
6. ANY-Implies unconditional transfer of control
Unit-1
Machine supports 11 Different Operations
Symbolic Remark
opcode
DIV Operand 🡺Oper1/Oper2
READ Operand2🡺 input value
PRINT Output🡺operand2

First operand is always a CPU register


Second operand is always a memory operand
SPOS
Assembly Language
Unit- I

Assembly language Statements:

Imperative
Statements

Declarative/Declaration
Statements

Assembler Directive
SPOS
Assembly Language
Unit- I

❏ Imperative means mnemonics

❏ These are executable statements.


Imperative
Statements
❏ Each imperative statement indicates an
action to be taken during execution of the
program
SPOS
Assembly Language
Unit- I

Declarative/Declaration Types
Statements

❏ Declaration statements are for


reserving memory for variables. DS DC

Declare Storage Declare Constant


❏ We can specify the initial value of
a variable.
SPOS
Assembly Language
Unit- I

Declare Storage

Syntax

[ Label ] DS < Constraint Specifying size >

Example
X DS 1
SPOS
Assembly Language
Unit- I

Declare Constant

Syntax

[ Label ] DC < Constraint Specifying values >

Example

X DC ‘5’
Unit-1

3.Assembler Directive
Instructs the assembler to perform certain actions
during assembly of a program.
A directive is a direction for the assembler
A directive is also known as pseudo instruction
machine code is not generated for AD.
Unit-1

3.Assembler Directive…
START <Constant>
It indicates that the first word of the m/c code
should be placed in the memory word with the
address <CONSTANT>
Unit-1

3.Assembler Directive…
END [<OPERAND SPECIFICATION>]

Optional, indicates address of the instruction where


the address of program should begin.
By default, execution begins from the first instruction.
It indicates the end of the source program.
Class:AD
Advanced Assembler Directives
These directive include:
1. ORIGIN
2. EQU
3. LTORG
ORIGIN
Useful when m/c code is not stored in consecutive memory
location.
ORIGIN <address specification>

Operand or constant or expression containing an operand


and a constant.

Sets LC to the address given by <address specification>


LC processing in a relative rather than absolute manner
ORGIN…..Example
Sr.N Assembly Program LC Remark
o
1 START 100 ORGIN LOOP+5,
2 MOVER BREG,’=2’ 100 Set LC to the value 106
(101+5=106)
3 LOOP MOVER AREG,N 101 Here, LOOP associated with address 101
4 ADD BREG,’=1’ 102
5 ORGIN LOOP+5
6 NEXT BC ANY,LOOP 106
ORGIN NEXT+2
7 ORGIN NEXT+2
Sets LC to the value 108
8 LAST STOP 108 (106+2=108)
9 N DC ‘5’ 109 Here, NEXT associated with address 106
10 END
EQU
Syntax:
<symbol> EQU <address specification>
Where,
<address specification> :can be operand specification or a
constant
<symbol>: EQU Associates symbol with the <address
specification>
Ex. BACK EQU LOOP
The symbol BACK is set to the address of LOOP
LTORG
Permits a programmer to specify where literal (for information
about literal then click on )should be placed.
If the LTORG statement not present, literal are present at the
END statement
At every LTORG Statement, memory is allocated to the literal
of the current pool of literals. Sytem Programming

The pool contains all literal used in the program since the start
of the program or since the last LTORG statement.
Unit-1
Literal and Constant
● A literal is an immediate operand
● A literal is an operand with constant value.
In the c-statement
int z=5;
x=y+5;
The constant value is ‘5’ known as literal.
● Literal can not be change during program execution
● They are specified using immediate addressing.
Unit-1
Literal and Constant…
● Literal in assembly language:
● Assembly instruction for 8086 with immediate operand

● MOV AX 15 (8086 instruction)

● But Hypothetical machine does not support immediate operand.


Unit-1
Literal and Constant…
● Handling a literal by our machine is as follows:

ADD AREG, X
ADD AREG,=‘6’ ----------------
-----------------
X DC ‘6’

Fig.: Handling of literal


SPOS
Assembly Language
Unit- I

Sample Assembly language Code

1. START 100
2. MOVER A REG, X
3. MOVER B REG, Y
4. ADD A REG, Y
5. MOVEM A REG, X
6. X DC ‘10’
7. Y DS 1
8. END
SPOS
Assembly Language
Code Unit- I
Identify types of statement 1. START 100

Sr. No IS DS AD 2. MOVER B REG, Y

1. 3. MOVER B REG, Y

2. 4. ADD A REG, Y

3.

4.
SPOS
Assembly Language
Code Unit- I
Identify types of statement 5. MOVEM A REG, X

Sr. No IS DS AD 6. X DC ‘10’

5. 7. Y DS 1

6. 8. End

7.

8.
Unit-1
Types of Assembler
● 3 Types of Assemblers
1. Load and Go-Assembler
2. One-pass Assembler
3. Two-pass Assembler
Unit-1
1.Load and Go-Assembler
Simplest form of assembler
It produces machine language as output which
are loaded directly in main memory and executed
The ability to design code and test the different
program components in parallel
Unit-1
2.One Pass Assembler
Normally , it does not allow forward referencing.
An assembler cannot generate m/c code for an
assembly instruction with FR.
Machine code is generated ,after the address of
variable used in the instruction is known.
Symbol table is used to record the address of the
variables.
Assembler SPOS

Unit- I

Dr. Mahesh R. Sanghavi


Assembler SPOS

Unit- I

Output of Pass 1 | Pass 2 Assembler

Pass 1 Pass 2

Generates Generates

Intermediate Code Machine Code

Dr. Mahesh R. Sanghavi


Assembler SPOS

Unit- I

Two Pass
Assembler

Pass 1
Assembler Pass 2
Assembler
Labels
Determine Storage Generate the
Separate
Mnemonic Opcode Requirement machine code

Operand Fields Build the Symbol


Table
Working of pass I
Data structures required:
MOT-use to search the opcode
Symbol table-use to search the symbol
Literal table
Pool table : starting literal number of each pool.
Unit-1
Mnemonic Opcode Table(MOT)
Mnemonic opcode m/c code for opcode Class Size of instructions
STOP 00 IS 1
ADD 01 IS 1
SUB 02 IS 1
MULT 03 IS 1
MOVER 04 IS 1
MOVEM 05 IS 1
COMP 06 IS 1
BC 07 IS 1
DIV 08 IS 1
READ 09 IS 1
PRINT 10 IS 1
Unit-1
Mnemonic Opcode Table(MOT)…
Mnemonic opcode m/c code for opcode Class Size of instructions

START 01 AD -----
END 02 AD -------
ORIGIN 03 AD -----
EQU 04 AD -------
LTROG 05 AD -----
DS 01 DL -------
DC 02 DL 1
AREG 01 RG -----
BREG 02 RG -------
CREG 03 RG -----
Pass 1 Assembler SPOS

Unit- I

Enhanced Machine Opcode Table


Symbol Table
It contains:
1. Name of variable or a label or symbol
2. Its address
3. Its size in number of words SYMBOL TABLE
4. Example- Index Symbol address
0 X 214 Sytem Programming

1 L1 202

2 NXT 207

3 BACK 202
Literal Table
It contains:
1. Value of the literal
2. Address of the memory location associated with
LITERAL TABLE
the literal. Literal address
Index
Example- 0 5 205
Sytem Programming
1 2 206
2 1 210
3 2 211
4 4 215
POOL Table
This table contains the literal number of the starting
literal of each literal pool.
POOL TABLE
Index
0 0
1 2
Sytem Programming
2 4
Intermediate Code
Is equivalent representation of source program.
Pass-I of the assembler involve scanning of the source file.
Every opcode is searched in MOT

Every operand is searched in symbol table.


Sytem Programming

It helps in avoiding:
1. Scanning of source file in PASS-II
2. Searching MOT and ST in PASS-II
Format of Intermediate Code
Each Mnemonic opcode field is represented as:
( Statement class , Machine code )

IS MOT entry of opcode


AD
DL
Ex.: MOVER 🡺 (IS,04)
LTORG 🡺 (AD, 05)
START🡺(AD,01)
Operand
( Operand Class, reference )

C: constant for a symbol or


S: symbol literal , reference
L: literal(variable) field contains the
RG: register index of the operand’s
CC:condition code entry in the symbol
table or literal table
Steps for Two Pass Assembler
Two Pass assembler: Pass1 and Pass2
Steps for Pass1:
1.Read source program
2.Add Location Count
3.Prepared Symbol table,Literal Table,Pool Table
4.Prepared Intermediate code using MOT table,Symbol table
and Literal Table
Steps for Pass2:
1.It generate Machine code from Intermediate code
Example 1 SPOS

Pass 1 Assembler Unit- I

Observe code

Apply LC
Pass 1 Assembler SPOS

Unit- I

Symbol Table
Construct
Pass 1 Assembler SPOS

Unit- I

Literal Table
Construct
Pass 1 Assembler SPOS

Unit- I

Pool Table

Pool table contains starting


literal(index ) of each pool.
SPOS

Intermediate code Unit- I


SPOS
Example 2 Unit- I

Assignment
Pass 2 Assembler SPOS

Unit- I

Pass 2 Assembler
❏ Processes the intermediate representation (IR) to
synthesize the target program.

Pass 2 Assembler

Intermediate code Machine Code

Dr. Mahesh R. Sanghavi


SPOS

Intermediate code Unit- I

Dr. Mahesh R. Sanghavi


SPOS
Example 2 Unit- I

Assignment

Dr. Mahesh R. Sanghavi


START 200
MOVER AREG, ‘=5’…………. 200
MOVEM AREG, X ………… 201
L1 MOVER BREG, ‘=2’…………. 202
ORIGIN L1+3 202+3=205
LTORG ………… 205,206 for literal
NEXT ADD AREG, ‘= 1’ ………… 207
SUB BREG,’=2’ ………… 208
BC LT, BACK …………. 209
LTORG 210, 211…. for literal
BACK EQU L1 ………… 202
ORIGIN NEXT+5 207+5=212
MULT AREG,’=4’ …………212
STOP……………………………213
X DS ‘5’………………………. 214
END ………..219 for literal (214+5=219)
SYMBOL TABLE

Index Symbol address


POOL TABLE
0 X 214 Index
0 0
1 L1 202
1 2
2 NEXT 207
3 BACK 202 2 4

LITERAL TABLE

Index Literal address


0 5 205
1 2 206
2 1 210
3 2 211
4 4 219
Assembly Program LC Intermediate Code
START 200 ………..(AD,01) (C,200)
MOVER AREG, ‘=5’….. 200 ….(IS,04) (RG,01) (L,0)
MOVEM AREG, X…… 201….(IS,05) (RG,01) (S,0)
L1 MOVER BREG, ‘=2’….. 202 ….(IS,04) (RG,02) (L,1)
ORIGIN L1+3 (AD,03) (C,205)
LTORG 205……(DL,02) (C,5)
206 ……(DL,02) (C,2)
NEXT ADD AREG, ‘= 1’……. 207 ….(IS,01) (RG,01) (L,2)
SUB BREG,’=2’ ……… 208 ….(IS,02) (RG,02) (L,3)
BC LT, BACK…………. 209 ….(IS,07) (CC,02) (S,3)
LTORG ……….. 210, ……(DL,02) (C,1)
211 ……(DL,02) (C,2)
BACK EQU L1 ……….. 202 ………..(AD,01) (C,202)
ORIGIN NEXT+5 ………..(AD,01) (C,212)
MULT AREG,’=4’…….. 212 ….(IS,03) (RG,03) (L,4)
STOP…………………… 213 ….(IS,00)
X DS ‘5’……………. 214 ……(DL,01) (C,1)
END -------(AD,02)
219 ………(DL,02) (C,4)
Assembly Program LC Intermediate Code
START 200 machine code
MOVER AREG, ‘=5’….. 200 … 04 01 205
MOVEM AREG, X……201…. 05 01 214
L1 MOVER BREG, ‘=2’….. 202 ….04 02 206
ORIGIN L1+3
LTORG 205……00 00 05
206 ……00 00 02
NEXT ADD AREG, ‘= 1’……. 207 ….01 01 210
SUB BREG,’=2’ ……… 208 ….(IS,02) (RG,02) (L,3)
BC LT, BACK…………. 209 ….(IS,07) (CC,02) (S,3)
LTORG ……….. 210, ……(DL,02) (C,1)
211 ……(DL,02) (C,2)
BACK EQU L1 ……….. 202 ………..(AD,01) (C,202)
ORIGIN NEXT+5 ………..(AD,01) (C,212)
MULT AREG,’=4’…….. 212 ….(IS,03) (RG,03) (L,4)
STOP…………………… 213 ….(IS,00)
X DS ‘5’……………. 214 ……(DL,01) (C,1)
END -------(AD,02)
219………(DL,02) (C,4)
Solved Example of Assembler

View

You might also like