Systems Programming
Systems Software
Introduction
Software
is a set of instructions or programs written to carry out
certain task on digital computers.
It is classified into
system software
application software.
System software consists of a variety of programs that
support the operation of a computer.
Application software focuses on an application or problem
to be solved.
- it is a solution to a problem.
Differences between System
software and Application software
System software Application software
1. It is used in the operation of 1. It is used to perform some
the computer. user task.
2. It is machine dependent 2. It is machine independent
software. software.
3. The programmer should 3. Not necessary to know the
know the architecture of the architecture of the system.
computer. 4. Examples consist of
4. Examples consist of inventory, payroll
compiler, loader, operating preparation, banking system
system, assembler etc. etc.
System software
is responsible for the working of the computers
It were developed to make computers better adapted to the
needs of their users.
Components of SS / Systems Programs
> Compiler
> Assembler
> Loader
> Operating system
> Macro processor
These software’s make it possible for the user to focus on an
application or other problem to be solved, without needing to
know the details of how the machine works internally.
Compiler
A compiler is a program that accepts a
source program in a high level language &
produces a corresponding object program
Differences between an interpreter and a compiler.
Interpreter Compiler
1)Translates and executes the source 1)Translates the entire program at once.
code line by line. 2)Re-translation required only when you
2)Re-execution requires re-translation modify the source code. The compile
as the translated code is not saved. code will be stored and used for re-
3)No separate stages such as execution.
compilation and execution stage. At 3)Compilation and execution is two
runtime itself the source code is separate stages in case of compiled
translated and executed. languages.
4)Ideal for testing and debugging. 4)Not suitable for testing and debugging.
5)Takes less main memory because 5)Takes more main memory.
interpreted languages are simple. 6)All syntax errors would have been
6)Execution of a program stops removed at compilation time itself.
abruptly in presence of errors. At the Hence the chances of program failure at
runtime itself both logical and syntax runtime are very less.
errors will come into surface. 7)Examples of compilers are C, C++,
7)Examples of interpreted languages COBOL, FORTRAN etc.
are BASIC, LOGO etc. 8)Security for the source code.
8)No security for the source code.
Assembler
Assembler is system software which is used to convert an
assembly language program to its equivalent object code.
The input to the assembler is a source program written in
assembly language (using mnemonics) and the output is
the object program (Machine Language).
The design of an assembler depends upon the machine
architecture as the language used is mnemonic language.
LOADERS
A loader is a routine that loads an object
program into memory & prepares it for
execution
Once the assembler produces an object
program, that program must be placed
into memory & executed
The loader loads this object programs into
memory & prepares it for execution
Macro Processor
Allows the programmer to define an
abbreviation for a part of his program & to
use the abbreviation in his program.
Macro Definition
Is a sequence of code that has a name.
Macro Call
Is an abbreviation/name for some code
Macro Processor
Program that substitutes the definition for all
occurrences of the macro call in the program
Subroutine
is a body of computer instructions designed to
be used by other routines to accomplish a
task.
Types
Open Subroutine / macro definition
is one whose code is inserted into the main program.
Closed Subroutine
can be stored outside the main routine, and control
transfers to the subroutine.
Differences between closed & open subroutine
Closed Subroutine Open Subroutine
1. Stored outside the 1. Code is inserted at the
main routine & control point of function call
is transferred to the within the main definition.
subroutine for
processing it.
2. If the macro definition is
2. Large size macros can
very large & if you call
be executed any
these functions frequently
number of times.
shortage of memory may
occur.
3. There is an overhead of 3. Saves time because there
transferring the control is no overhead of program
to the function & control transfer & return.
returning back which
takes time.
4. Performs two tasks 4. Performs only one
that is transfer of task, that is insert a
control & transfer of macro.
data.
5. Saves memory 5. Wastage of memory
6. Closed subroutines [Link] into memory
are loaded into at different memory
memory at a specific locations.
address.
Operating systems
Is concerned with the allocation of
resources & services , such as memory,
processors, devices & information.
It allows flexible storing & retrieval of
information
All the previous process was done by
interacting with the OS.
Formal Systems
Is an uninterpreted calculus
It consists of
an alphabet,
a set of words called axioms, &
a finite set of relations called rules of inference
Eg: Set theory
Boolean Algebra
Backus Normal Form
Uses
In the design, implementation & study of programming
languages
To specify the syntax & the semantics of programming
languages
In syntax directed compilation, compiler verification &
complexity studies of languages
Computing Machine
Application (Netscape)
Operating
Compiler System
(Windows XX) Instruction Set
Software Assembler Architecture
Hardware Processor Memory I/O system
Datapath & Control
Digital Design
Circuit Design
transistors
Levels of Representation
High Level Language temp = v[k];
Program (e.g., C) v[k] = v[k+1];
v[k+1] = temp;
Compiler
Assembly Language
Program
Assembler
0000 1001 1100 0110 1010 1111 0101 1000
Machine Language 1010 1111 0101 1000 0000 1001 1100 0110
Program 1100 0110 1010 1111 0101 1000 0000 1001
0101 1000 0000 1001 1100 0110 1010 1111
°
°
Machine Structure
Memory
Device where information can be stored &
retrieved
Information is stored in the form of 1’s & 0’s
Each 1/0 is a separate binary digit called a bit
Bits are grouped into words, characters or bytes
Nibble - 4 bits
Byte - 8 bits
Half word - 16 bits
Word - 32 bits
Double word - 64 bits
Basic unit of memory is a Byte
Memory locations are specified by addresses ,
where each address identifies a specific byte or
word
The contents of it may be
DATA – Values to be operated on
Or INSTRUCTIONS – Operations to be performed
ie instructions & data share the same storage medium
Processor
is a device that performs a sequence of
operations specified by instructions in
memory
Types
Central Processing Units
Concerned with manipulations of data stored in
memory
Input/Output Processors
Transfers data between memory & peripheral devices
such as disks , drums, printers etc.
Executes I/O instructions that are stored in memory;
Which are activated by a command from the CPU
Execution Time
Period of execution of a user’s program
Assembly/Compile Time
Period of translating a user’s source program
Load Time
Period of loading & preparing an object
program for execution
PROCEDURE PROCESSOR
is a set of instructions is a device that performs
in order to perform a a sequence of
particular task operations specified
by instructions in
memory
it is a S/W program it is a H/W device
Procedure is executed Processor performs the
using a processor operation based on a
procedure
PROCEDURE PROGRAM
is a course of action a set of instructions
taken for the solution directs a computer to
of a program perform specific tasks
& produce certain
results
are not executable are executable files
files
are general solution of interrelated with
a problem computer H/W & S/w
Machine Structure
Memory Controller
is a H/W that transfers
MARdata between the MBR
& the core memory
contains the
location,
address theofaddress
the
of
I/Owhich
memory
Channelsis in the MAR
location ie
MBRto be read from or
may thought of
contains a copy
into of the
asstored
separate
memory location
computer’s which
specified by the MAR
interpret special
after a read, or the new
instructions for
contents of the memory
Location Counter
inputting & device
location prior
is a H/W memoryto a write
outputting
Workingwhich denotes the location
Registers
of the current instruction
information
being executedfrom
are memory
Instruction
the Register
memory
devices
Contains a copy that of serve
the
current instruction
as scratch pads for
the instruction
Instruction Interpreter
isinterpreter
a group of electrical
circuits, that performs the
General
purpose Registers
of instructions
fetched from memory
used by the
programmer as
storage locations &
for special
functions
CPU
Instruction Interpreter
is a group of electrical circuits, that performs the purpose of instructions
fetched from memory. It is like a decoder that decodes the type of the
instruction.
Location Counter /Instruction Counter/Program Counter
is a H/W memory device which denotes the location of the current
instruction being executed
Instruction Register
Contains a copy of the current instruction
Working Registers
are memory devices that serve as scratch pads for the instruction
interpreter
General Registers
used by the programmer as storage locations & for special functions
Memory
MAR
contains the address of the memory location ie to
be read from or stored into
MBR
contains a copy of the memory location specified
by the MAR after a read, or the new contents of
the memory location prior to a write
Memory Controller
is a H/W that transfers data between the MBR &
the core memory location, the address of which is
in the MAR
I/O Channels
may be thought of as separate
computer’s which interpret special
instructions for inputting & outputting
information from the memory
eg:
The basic instruction format is as follows
Operation Register Memory
code No Location
ADD 2, 176
ADD 2, 176
MACHINE STRUCTURE
IBM 360 &370
Basic Unit
MEMORY Size
is a device where information can be
Addressing Scheme
stored & retrieved
Information is stored in the form of 1’s &
0’s
Each 1/0 is a separate binary digit called a
bit
BASIC UNIT
BYTE………… 8 bits
ie each addressable position in memory can contain 8 bits of information
Units of memory
Nibble - 4 bits
Byte - 8 bits (1 Byte)
Half word -16 bits (2 Bytes)
Word - 32 bits (4Bytes)
Double word - 64 bits (8 Bytes)
SIZE
Upto 224 bytes (about 16 million)
Address
Memory locations are specified by addresses ,
where each address identifies a specific byte or word
The contents of it may be
DATA – Values to be operated on
Or INSTRUCTIONS – Operations to be performed
ie instructions & data share the same storage medium
Addressing Scheme
Value of an address = value of an offset +
contents of a base register +
contents of an index register
Notes
Offset/distance/displacement
-a no that tells how far from a starting point (base address) a
particular item is located.
Base register
-is used for effective addressing
-is used for relocation of a program
ie an entire program may be moved from one location to
another by changing the contents of a base register
Index Register
-Special CPU register or simply a register in a register file
-usually value of index register is 0
NOTES
Relative address
a location in computers memory ie specified in terms
of its distance (offset) from a starting point (base
address)
Rel addr = offset + base addr
eg: 2001, 1st Main
here base – 2000
offset – 1
Indexed address
Here content of an index register is added to the
address part of the instruction to obtain the effective
address
REGISTERS no. of registers used
their size & functions
Name of Registers Number Size
General Purpose Registers 16 32 bits each
Floating Point Registers 4 64 bits each
Program Status Word 1 64 bits
Program Status Word
Only 1 PSW
The size of it is 8 bytes (64 bits).
contains the
value of the location counter,
protection information &
interrupt status
ie. It contains information required for proper execution
of a given program.
note : Interrupts are used by the processor to
communicate with the other components
General Purpose Registers
The IBM 360 machine supports 16 GPR’s from
R0 to R15.
The size of each registers is 4 bytes (32 bits).
Used for various arithmetic & logical operations
& as base registers
When used for arithmetic & logical
operations these registers acts as scratch
pads to which numbers are added, subtracted,
compared etc.
When used as base registers they aid in the
formation of the address
Eg:
A 1, 901 ( 2, 15 )
Add(opcode) offset index reg base reg
reg no(argument reg)
--- a no should be added to the contents of reg 1
--- location of the no = 901 + contents of reg 2
+ contents of reg 15
The instruction is stored in the following format
opcode arg index base offset
reg reg
8 bits 4 bits 4 bits 4 bits 12 bits
Total = 32 bits
since we use the base register the complexity
of the address formation increases
but it helps in efficient addressing of the core
If we were not using the base register,
To address all the 224 bytes locations,
we need 24 bits for every address
whose format would be
opcode arg index address Address of the
reg reg no. we wish to
add
8 bits 4 bits 4 bits 24 bits
Total = 40 bits
Types of data that can
DATA be handled by the
computer
Data Formats & how it is stored
ie groups of data stored in memory are interpreted in the
following ways :
Short form fixed point numbers.
Long form fixed point numbers.
Packed decimal numbers.
Unpacked decimal numbers
Short form floating point numbers.
Long form floating point numbers.
Logical data (character data).
Short form fixed point
numbers
size : 16 bits ( 2 bytes)
First 1 bit is reserved for sign (+ or -).
The machine interprets the contents of two bytes
as an integer.
ie. it interprets the first bit as sign and the
remaining 15 bits as a binary number.
Eg : take the decimal no +541
0000 0010 0001 1101
binary equivalent
Long Form fixed point numbers
size : 32 bits ( 4 bytes) (1 word)
First 1 bit is reserved for sign (+ or -).
The machine interprets the contents of four bytes as an integer.
ie. it interprets the first bit as sign and the remaining 31 bits as a binary
number.
Eg: +267
Byte address
The number is stored in locations 1016, 1017, 1018, 1019
& we say that the number is located at address 1016
Packed Decimal Numbers
Decimal digits, packed two to a byte, appear in fields of variable length
(from 1 to 16 bytes) and are accompanied by a sign in the rightmost
four bits of the low-order byte.
Instead of representing the binary number, numbers are
represented in Binary Coded Decimal
The hex digits C, A, F, and E
eg: indicate the number is positive
-021 while D and B indicate a
0000 0010 0001 1101 negative number.
Useful in BDP
Packing of digits leads to efficient use of storage, increased arithmetic
performance, and improved rates of data transmission.
Unpacked decimal numbers
Zone code / Padding Bit / Internibble bit
contains 0 /1
Short form floating point
numbers
size : 32 bits ( 4 bytes) (1 word)
Represents floating point numbers
Long form floating point numbers
size : 64 bits ( 8 bytes) (2 words)
Represents floating point numbers
Logical data (Characters)
Variable length (1 to 256 bytes)
each character will be stored in 8 bits.
Instructions Types of instructions
their formats
& how they are stored
A program is a set of instructions.
Instructions may be of the following
types
1) Arithmetic instructions.
2) Logical instructions.
3) Control or transfer instructions.
4) Special Interrupt instructions.
Instruction formats
1) RR format
2) RX format
3) RS format
4) SI format
5) SS format.
they differ in the types of operands they
use
If the operands are registers then data is stored
in any one of the 16 general purpose registers.
The length of each register is 4 bytes (32 bits).
In all the instructions the first byte contains the
operation code
RR (denotes register-to-register operation )
Length : 2 Bytes
1 byte for op,
4 bits for R1,
and next 4 bits for R2.
E.g. AR 3, 4
RX (denotes a register and indexed-storage
operation)
Storage operands refer to the data stored in memory.
The address of the storage operand is calculated as
follows:
Address = contents of base register
+ contents of index register
+ displacement
ie. C(B2)+C(X2)+D2
RX
Eg: A 3, 16(0, 5)
Assume
Base register 5 contains the no 1000
Then
address = c(B2) + c(x2) + D2
= c(5) + 0 + 16
= 1000 + 0 + 16
= 1016
RS (denotes register and storage operation)
The address of the storage operand is calculated as follows:
Address = contents of base register + displacement
ie. C(B2)+D2
Eg:
LM 1, 3 , 16(5)
Load multiple registers 1 & 3 with c(16 + c(5))
SI (denotes a storage and immediate-operand
operation
Immediate Operands are a single byte of data & are
stored as part of the instruction
Eg: MVI 4(5), 64
Assume
Base register 5 contains the no 1000
Then the MOVE instruction will move the code for character blank
in to location 1004
SS (denotes a storage-to-storage operation)
It is a 6 byte instruction which has got 2 storage operands
& a length field
Eg: MVC 32(79, 5), 300(5) SS
Assume ,
Base register 5 contains the no 1000
Note : Length is always one less than the data moved
ie if L = 0 , move 1 byte
Here L = 79 , therefore move 80 bytes
from location 1032 till 1111 (1032 + 79)
to 1300 till 1379 (1300 + 79)
Machine Language
Machine code or machine language is a system of instructions
and data executed directly by a computer's central processing
unit.
Machine code may be regarded as a primitive (and cumbersome)
programming language or as the lowest-level representation of a
compiled and/or assembled computer program
MNEMONIC - A name given to a particular microprocessor instruction for use in
assembly languages.
Distance from a starting point
There are different ways of writing this program i.e
1) Long way, No looping .
2) Address modification using instructions as
data
3) Address modification using index registers.
4) Looping
Program –Straightforward Approach
Long way , No looping
Absolute Relative Instructions Comments
Addr Addr
48 0 L 2, 904(0,1) 904+c(1)= 904+48=952 , c(R2)=Data1
L is RX type whose size is 4 bytes
52 4 A 2, 900(0,1) 900+c(1)=900+48=948, c(R2)=Data1+49
56 8 ST 2, 904(0,1) 904+c(1)= 904+48=952
store back contents of R2 to locn 952
60 12 L 2, 908(0,1) load next data
908+c(1)= 908+48=956, c(R2)= Data2
64 16 A 2, 900(0,1) 900+c(1)=900+48=948 , c(R2)= Data2+49
68 20 ST 2, 908(0,1) 908+c(1)= 908+48=956
: : : store back contents of R2 to locn 956
: : :
948 900 49
952 904 :
:
Drawbacks of no looping:
If we wanted to process 300 data items rather than just 10
the storage needed for the instructions would be
Instruction *number of data instruction*size of instruction
=3*300*4
=900*4
=3600 bytes
Thus the instructions would overlap our data in the core.
Even if we manage this situation we won’t be able to reach
the data beyond 4095 bytes from program beginning.
Program - Address Modification Using Instruction as
Data
Assumption 5: Relative Location 896 contains a 4
In this case we will be writing the three
instructions load, add, & store for adding 49 to a
number.
This is followed by a sequence of commands
that would change the offset of load and store
instructions by adding 4 to them.
Now loop back to re-execute the set of 3
instructions with different offset (ie now it refers
to different data item)
Program - Address Modification Using Instruction as Data
Assumption 5: Relative Location 896 contains a 4
Absolut Relativ Instructions Comments
e Addr e Addr
Add 49 to a number
48 0 L 2, 904(0,1)
904+c(1)= 904+48=952, c(R2)= Data1
52 4 A 2, 900(0,1) 900+c(1)=900+48=948 , c(R2)= Data1+49
56 8 ST 2, 904(0,1) 904+c(1)= 904+48=952
store back contents of R2 to locn 952
60 12 L 2, 0(0,1) Increase displacement of load instrn by 4
64 16 A 2, 896(0,1) 0+c(1)=48 , c(R2)= L 2, 904(0,1)
68 20 ST 2, 0(0,1) 896+c(1)=896+48=944 , c(R2)= L 2, 904(0,1) +4
0+c(1)= 48 L 2, 908(0,1)
72 24 L 2, 8(0,1) store back contents of R2 to locn 48
Increase displacement of store instrn by 4
76 28 A 2, 896(0,1)
8+c(1)=8+48=56 , c(R2)= ST 2, 904(0,1)
80 32 ST 2, 8(0,1)
896+c(1)=896+48=944,c(R2)=ST 2, 904(0,1)+4
Branch to relative 8+c(1)= 8+48=56 ST 2, 908(0,1)
locn 0 ,9 times
store back contents of R2 to locn 56
: : :
: : :
944 896 4
948 900 49
952 904 numbers
: : :
Treating instruction as a data is not a good
programming technique
because in maintaining a program over a
period of time, it becomes difficult to
understand what the original programmer
was actually trying to do.
Program - Address Modification Using Index Regesters
Absolu Relati Instructions Comments
te ve
Addr Addr
48 0 SR 4, 4 Clear register 4
Subtract c(R4) from c(R4) , c(R4) = 0
SR is RR type whose length is 2 bytes
50 2 L 2, 904(4,1)
54 6 A 2, 900(0,1) Add 49 to a number
58 10 ST 2, 904(4,1)
62 14 A 4,896(0,1) add 4 to index register
Branch to relative 896+c(1)=896+48=944 , c(R4)= 0+4
locn 2 ,9 times
: : :
: : :
944 896 4
948 900 49
952 904 numbers
: : :
Program - Using Looping
Assumption 6 : Relative location 892 contains a 10, Assumption 7 : Relative location 888 contains a 1
Absolute Relativ Instructions Comments
Addr e Addr
48 0 SR 4, 4 Clear register 4
50 2 L 2, 904(4,1)
54 6 A 2, 900(0,1) Add 49 to a number
58 10 ST 2, 904(4,1)
62 14 A 4,896(0,1) Add 4 to index register, c(R4)=0+ 4
66 18 L 3,892(0,1) Load temp into register 3
892+c(1)=892+48=940, R3=10
70 22 S 3, 888(0,1) Subtract 1, 888+c(1)=888+48=936, R3=10-1=9
74 26 ST 3,892(0,1) Store temp, 892+c(1)=892+48=940, c(940)=9
78 30 BC 2,2(0,1) Branch if result is +ve, 2 is a condn code, 2+c(1)
: : : = 2+48=50, i.e. Branch to 50
: : :
936 888 1
940 892 (initially 10
decremented by 1
after each loop)
944 896 4
948 900 49
952 904 numbers
: : :
Another version using looping
Assembly Language
Most machine dependent language
used by programmers today
Advantages of M/C lang over Assembly
lang
It is mnemonic
Addresses are symbolic, (such as
PLACE1) not absolute
Reading is easier
Introduction of data to program is
easier
Disadvantage
An assembler is required to translate
a source program into object
program.
Pseudo – op
is an assembly language instruction that specifies an operation of the assembler
Machine – op
machine instruction to the assembler
Types of pseudo – op’s
Declarative statement:
There are two types in declarative statement i.e.
a) DC (Define Constant).
is a pseudo op to create a memory area to hold a
constant value.
Syntax: <label> DC ‘constant’
e.g.: TEN DC F‘10’
b) DS (Define Storage):
is a pseudo op to reserve memory area.
Syntax: <label> DS SIZE
e.g.: BLOCK DS 100F
Note:
A DC statement reserves and initializes memory .
The DS statement reserves memory without initialization.
START:
is a pseudo-op that tells the assembler where the beginning of the program is.
& allows the user to give a name to the program.
Eg : TEST START
END:
is a pseudo-op that tells the assembler that the last statement of the program
has been reached.
USING:
is a pseudo-op that indicates the assembler which general purpose register
should be used as base register and what its contents will be.
In order for the Assembler to convert addresses to base-displacement
format, you must tell the Assembler what register to use as a base register,and
what value the register will contain at execution time. This information is
provided with the USING instruction.
Syntax: USING <what the contentsof BR will be> <GPR to be used as BR>
E.g.: USING BEGIN + 2, 15
You must also include machine instructions in your program, to load the proper value
into the base register at execution time
BALR:
is an instruction to the computer to load a register with the next address
and then branch to the address specified in the second field.
When the second operand is register 0, execution proceeds with the next
instruction.
Eg. BALR 15, 0
BALR USING
is a machine-op is a pseudo-op
loads the base register informs the assembler what is in
the base register.
BALR : Loads the
0 base reg & Branch to
to the addr in the 2nd
field.
USING : Tells which
2
register to use as a
base register & what
its contents will be
Assembly language program using
Literals
Literals
You may use a shorthand notation in place of a label
for the source memory operand in many instructions.
A literal looks like a DC operand but is preceded by an
"=" sign.
While using literals , the assembler creates data areas
for the programmer, containing constants he requests
Examples:
L R1,=F'123' *loads R1 with 123
Literal Table : All the constants that have been specified
through the literals will be placed in this table
& usually it is placed at the end of the program.
LTORG : is a pseudo op which tells the
assembler to place the encountered literals
at an earlier locn.
Functions of LTORG Instruction
Used when the program is very long.
To avoid addressability problems in
multimodular programs, you should code a
LTORG instruction as the last instruction of
each control section in the program.
So, each CSECT will have
its own literal pool at the end of the
module.
EQU is a pseudo op which allows the programmer to define
variables .
Differences between DC and EQU
DC EQU
1)DC is a declarative 1)EQU is a pseudo-op
pseudo op.
e.g.: TEN DC F‘10’ e.g.: BASE EQU 15
2) The operand field of DC 2) The operand of EQU
statement must be a statement can be a constant or
constant value any sort of valid arithmetic
expression
3) Location counter 3)No LC processing.
processing will be there.
4)DC will create a memory 4)Symbol will be everywhere
word initialized to constant evaluated to value.
value.
Assembly language program using
Literals
=F’10’ : Literal , which will create data
0 area containing a 10
In the instruction the address part
2
4
points to a full word containing the
8 value 10
12 =F’49’ : Literal , which will create data
16 area containing a 49
20 =F’4’ : Literal , which will create data
24 area containing a 4
*-16 : means the addr of the present
LTORG
instrn: is a pseudo
minus op which
16 locations ie tells
24-16the= 8
assembler
ie branch to place the encountered literals
to LOOP
at an earlier locn.
EQU is a pseudo op which allows the
programmer to define variables .
Here BASE will have a value 15