Chapter 1
Chapter 1
Application Program:
It is designed to help the user to perform some specific task related to real time
task and real time application.
Eg: Accounting software and Game software etc.
System program:
It is designed to operate and control the computer hardware and also provides a
platform for running the application.
Eg: Compiler, assembler, macros, interpreter etc.
System Programming can be defined as the act of building Systems
Software using System Programming Languages.
Some of the System Programs are simply user interfaces, others are
complex.
1. Memory:
For example
2. Processor:
It is a device that perform a sequence of operation specified by instructions in
memory.
Sequence of instructions are called as program or procedure.
Two types of processors and they are listed below:
• CPU
• Input Output Processor
Central processing unit processor:
Input/output processor:
Processor Procedure
Device that performs sequence of operations IT is a set of instruction required to
specified by the instructions in memory. perform a particular task.
It is a hardware device It is a software program
It performs the operations based on a procedure IT is executed using a processor.
Procedure Program
Course of action taken for the solution Set of instruction which directs a computer
of a problem to perform specific tasks and produce
certain results.
Procedure are not executable files. Programs are executable files.
Processor retrieves and store the data I/O channels act as a inter mediator between
through I/0 Channels. I/0 devices and the CPU.
Evolution of the components of a programming system:
1. Assembler
2. Loaders
3. Macros
4. Compilers
5. Formal System
6. Operating System
1.Assembler:
Computer programmers are usually written using 0’s and 1’s (machine
language), place them into memory and press a button, then the computer
would start to interpret them as instruction.
It is difficult for the programmers to write and read programs using machine
language so they use assembly level language.
In assembly level language they use mnemonic symbol for each machine
instruction.
In assembly level language they use mnemonic symbol for each machine
instruction.
Assembly level language are low level programming language that allows user
to write programs Using letters and symbols that is easy for the programmer to
remember.
A program in assembly language is converted into an equivalent machine
language to be executed on the system. IT is known as assembler.
Programs named as assemblers are written to translate assembly language
into machine language.
Input to the assembler is source program (assemble language) and the output
of the assembler is object program (Machine language).
Design of the assembler depends on the machine architecture as language
used is mnemonics.
Assembler is a system software which is used to convert an assembly language
program to its equivalent object code.
Translation/Loading/Execution Process:
Loader:
Loader is the part of an operating system that loads the object programs
into memory and prepares them for execution.
The purpose of the loader is to assure that object programs are placed in
memory in an executable form.
Loader is responsible for the execution process.
Program must be placed into memory and gets executed after the
assembler produces the object program.
If the assembler places the program into memory it leads to
Wastage of memory as the assembler occupies more space in memory
than loader during execution.
Wasting translation time as re-translation of the program with each
execution.
Open subroutine
It is one whose code is inserted into the main program.
It performs only one task ie insert a macro.
If it is called four times the macro definition would appear in four
different places in the calling program.
If an open subroutine was called four different times the macro
definition would appear in four different places in the calling program.
Closed Subroutine:
Closed Subroutine will be stored outside the OS or macro definition is one whose code
main routine and there is a transfer in will be inserted at the point of function call
control to the subroutine for processing it. within the main function.
Large size macros can be executed any If the macro definition is very large and if
number of times. you call these functions frequently shortage
of memory may occur.
Performs two tasks that is transfer of control Performs only one task ie insert a macro.
and transfer of data.
Closed Subroutines are loaded into memory Open subroutine are loaded into memory
at a specific location. at different memory location ie based on
the location of calling macro.
Relocation:
Loader is divided into different types based on the four loading functions
• Compile and go loader
• Absolute loader
• Re-locating loader
• Direct linking loader
• Dynamic loading
• Dynamic linking
Execution Time: Period of execution of a user’s program.
Assembly or compile time: Period of translating a user’s source program to
object program.
Load Time: The period of loading and preparing an object program for execution
Macros:
Operating system introduced Macros to eliminate the need of repeating
identical parts of the program.
Macro processor substitutes the definition for all occurrences of the
abbreviation in the program.
Macro processor treats the identical parts of the program as macro definition
and saves the definition.
Macro facilities is used as general text handlers.
Entire operating system is written as a series of macro definition and to
specialize the operating system a series of macro calls are written.
The compilation process consists of first loading the computer with the compiler
and then inputting the source program through a suitable device.
Program that converts a high level language into machine language is called a
translator.
There are 2 types of translator and they are compilers and interpreters.
Cobol, Fortran, pascal, Algol and pl/1 are high level languages which are
processed by compilers and interpreters.
It is a program that accepts a program written in high level language and converts
it to an object program.
The compiler produces an object program which is saved on the storage device.
Assembler performs the same job as compiler but the basic difference between the
assembler and compiler is assembler converts the assembly language to machine
language but the compiler converts high level language into an machine level
language.
Compiler occupies more storage space and takes more processing time than an
assembler.
Interpreter:
Translator to convert high level language into machine code but the translation
takes place line by line.
Interpreter:
It is another type of translator used for translating program in high level language
into machine code.
It interprets the instruction line by line.
It takes one statement of a high level language and translates it into machine
instruction which is immediately executed.
The compiler takes a large amount of An interpreter takes less amount of time
time to analyze the entire source code to analyze the source code but the
but the overall execution time of the overall execution time of the program is
program is comparatively faster. slower.
No Security for the source code Security for the source code.
Ideal for testing and debugging Not suitable for testing and debugging
Compiler interpreter
Compiler scans the whole program in one Translates program one statement at a
go. time.
As it scans the code in one go, the errors Considering it scans code one line at a
(if any) are shown at the end together. time, errors are shown line by line.
It converts the source code into object It does not convert source code into
code. object code instead it scans it line by line
Examples of formal systems are set theory, Boolean-Algebra, post systems and
Backup normal form.
Each process needs two types of system time: CPU time and IO time.
This partitioned memory has some holes or unused portions of memory as it is too
small to hold the program is called as Fragmentations.
In Time-sharing operating system, we assign some time to each job so that all the jobs
work efficiently and smoothly.
The time taken by each job to execute the job is known as quantum.
After the interval of time is over, the operating system moves to the next task.
Time sharing is sharing the processors time with multiple users simultaneously.
There are many instances in which programs need to exchange with one another.
Distributed database system is an example of this.
Real Time Operating System
It is defined as an operating system known to give maximum time for each of the critical
operations that it performs, like OS calls and interrupt handling.
The Real-Time Operating system which guarantees the maximum time for critical operations
and complete them on time are referred to as Hard Real-Time Operating Systems.
While the real-time operating systems that can only guarantee a maximum of the time, i.e.
the critical task will get priority over other tasks, but no asurity of completing it in a defined
time. These systems are referred to as Soft Real-Time Operating Systems.
Firm Real Time firm real-time task even after the passing of deadline, system does not fail.
The Real-time operating system gives the response very fast and quick.
Example of the real-time operating system: Medical imaging systems, Industrial system,
Nuclear reactors control scientific experiments, Traffic controlling signal, Military software
system, Airline resolution system, Networked multimedia systems, Internet telephony, etc.
Real Time Operating System
.
General Machine Structure:
A. CPU consist of
1. Instruction interpreter:
It interprets the instruction to be executed.
It also generates the appropriate signal for the instruction.
It is like a decoder that decodes the types of instruction.
2. Location Counter:
It is also known as program counter or instruction counter.
It is a hardware memory device which holds the location of the current instruction being
executed.
3. Instruction Register:
It contains the copy of the current instruction to be executed. Register which stores the
instructions.
4. Working Register:
These registers are used by the processor for the calculations.
5. General Purpose Register:
It is used by the programmer as storage locations and for special functions.
B. Memory:
Primary interface between memory and cpu is via the memory address register and memory
buffer register.
Memory address register (MAR):
Contains the address of memory location to be read from or to be stored into.
Memory buffer register (MBR):
MBR contains the contents whose address is specified by MAR.
Contains the copy of the designated memory location specified by MAR after a read
operation or new contents of the memory location prior to the write operation.
Memory Controller (MC):
Hardware that transfers the data or the instruction between the MBR and the core memory
location whose address is present in MAR.
It controls all the memory related activities.
C. I/O channels:
It is a separate computers that interpreters special instructions for inputting and outputting
information from memory.
It is a separate unit for input output operation.
To illustrate how these components of the machine structure interact let us consider an Add
instruction as follows.
ADD 2,176
The Sequence of hardware operations to execute the instruction is given in the flowchart.
Step 1: Move the address of the current instruction which is present in LC to MAR.
Step 2: Read the instruction from the memory whose address is specified in MAR and
move it to MBR.
Step 3:Put the instruction into Instruction Register.
Step 4: Find the type of instruction specified in IR.
If the instruction type =“ADD” perform the following steps.
Step 5: Move the address field in the instruction present in IR (ie 176) to MAR.
Step 6: Read the data present at 176 and move it to MBR.
Step 7: Move the general register value present in IR (ie 2) to WR.
Step 8: Add the contents of WR and MBR and store the result in WR.
Step 9: Move the contents of WR into the general register field of IR.
Step 10: Increment IC (instruction counter) to the location of the next instruction.
Machine Structure of IBM 360:
1. Memory
2. Registers
3. Instructions
1. Memory:
It is a device where information can be stored and retrieved.
Information is stored as 0’s and 1’s. Each 1 or 0 is a separate binary digit
called a bit.
Basic unit of memory is a byte. Each addressable position in memory
contain 8 bit of information.
Nibble is a unit of memory consisting of 4 bits.
Size of the IBM 360 memory is upto 2 bytes.
Address:
• Memory location are specified by addresses where each address identifies a specific byte
or word.
• The contents of it are data (values to be operated on) or instruction (operations to be
performed).
• Both instruction and data share the same storage medium.
Offset /distance/displacement is a number that tells how far from a starting point a
particular item is located.
Consider the following address 2003, Main Street, K .S layout.
Base is 2000 and offset is 3.
That is the 3rd house from the beginning of block 2000 in main street, K.S layout.
Base Register is a register used for addressing that contains the base address.
Index register is a special CPU register or simply a register in a register file.
Usually the value of an index register is 0.
2. Registers:
IBM 360 machine has 16 general register consisting of 32 bits each 4 floating point registers
consisting of 64 bits each and one program status word of 64 bits.
<----------------------------------------------40 bits-----------------------
Opcode Argument Reg Index Reg Address
Data:
Since the size of the long form fixed point numbers is 4 bytes the number (+257) is stored in 4
consecutive memory locations 1016, 1017,1018 and 1019.
Instead of specifying the all the four location we say that number is located in location 1016.
--BCD of 021------
Sign Bit(-)-D
0 4 8 12 16 Sign bit
( 4 bit)
Zone Code True Form binary
(4 bits) Coded decimal digit
(4 bits)
.
5. Short Form Floating Point Numbers:
In Short form floating point numbers 32 bits(4 bytes) are allocated out of which 1
bit is reserved for sign (+ or -1).
The floating point number is divided into exponential and fractional part.
In long form floating point numbers 64 bits (8 bytes) are allocated for the floating
point numbers which contains the exponential and fractional part.
Long length of the fractional part gives upto 17 decimal pieces of precision thus
eliminating most requirement for double precision arithmetic.
Register Operands:
It refers to the data stored in one of the 16 general purpose register which
are addressed by a 4 bit field in the instruction.
Storage Operands:
It refers to the data stored in the core memory.
Length of the operand depends on its specific data type.
Immediate Operands:
It is a single byte of data and is stored as part of the instruction.
Different instruction formats are
1. RR Format
2. RX Format
3. RS Format
4. SI Format
5. SS Format
0 78 11 12 15
-------------------------Register Operands----
The length of it is 2 bytes (16 bits) out of which 1 byte is used for OP code
next 4 bits for R1 and next 4 bits for R2.
Example 1:
OP R1 R2
Rx Format:
It denotes a register and indexed storage operation. One operand is a register and another one
is storage operand.
Length of Rx type instruction is 4 bytes (32 bits)
Storage operand refers to the data stored in core memory. Address of storage operand is
calculated as follows.
-------------------4 bytes-----------------------------------
OP R1 X2 B2 D2
0 7 8 11 12 15 16 19 20 31
-----------------------------------------------------
Registered Operand1 Storage Operand2
Example 1:
-------------------4 bytes--------------------------------------------------
Op R1 X2 B2 D2
0101 1010 0011 0000 0101 0000000010000
--------------- 3 0 5 16
Add from storage
to register
Assume base register 5 contains the number 1000.
Address of storage operand= C(B2)+C(x2)+D2
=C(5)+0+16
=1000+0+16
=1016
Add instruction add the word (32 bits) located at address 1016 with the contents
of general register 3 and store the result in general register 3.
RS Instruction:
It denotes register and storage operation. General format of instruction is
Length of Rs instruction is 4 bytes.
Address= contents of base register + displacement.
=C(B2)+D2
Example 1:
LM 1,3 16(5)
-------------------4 bytes----------------------------------------------------------------
OP R1 R3 B2 D2
Load multiple 1 3 5 16
register
----------------------------- --------------------------
Register Operands Storage Operand
Register
Address of storage operand= C(B2)+D2
=C(5)+16
=1000+16
=1016
Load instruction loads register 1 and 3 with the contents of memory location 1016.
SI Instruction:
It denotes a storage and immediate operand operation.
-------------------4 bytes------------------------------------------------
Op 12 B1 D1
0 78 15 16 19 20 31
--------------- -----------------------------------
Immediate Storage Operand
Operand
Length of SI instruction is 4 bytes (32 bits).
Immediate operands are single bytes of data and are stored as part of the
instruction.
Address of the storage operand=contents of base register + displacement
= c(B1)+D1
Example 1:
OP I2 B1 D1
1001 0010 0100 0000 0101 0000 0000 0100
In operand 1
Address of storage operand= C(B1)+D1
=C(5)+4
=1000+4
=1004
Move instruction will move the code of character blank into memory location
1004.
SS Instruction:
It denotes a storage to storage operation.
Length of ss instruction is 6 bytes (48 bits). IT has got storage operands and a length
field.
Address of storage operand 1= C(B1)+D1
Address of storage operand 2=c(B2)+D2
Example 1:
Binary Representation of a load instruction:
OP R1 X2 B2 D2
Example:
Write a program that will add the number 49 to the contents of 10 adjacent full
words in memory under the following set of assumption.
1)10 numbers to be added to are in contiguous full words beginning at absolute
core location 952.
2)Program is in core starting at absolute Location 48.
3)Number 49 is a full word at absolute location 948.
4)Register 1 contains a 48.
Program can be written using three different ways.
Long way, No Looping
Address Modification using instruction as data
Address Modification using Index register
Looping
Long way, No Looping: The straight forward approach without any looping
statement is given below.
L2,904(0,1)
Load the first number into register 2.
Address of the storage operand= offset + content of the base register.
Address of the storage Operand= 904+contents of base register 1.
= 904+48 (register1 contains 48)
= 952
Contents of register 2 = Contents of memory location 952= Data1
L is RX Type instruction whose size is 4 bytes.
Therefore Absolute and relative address is increment by 4.
Merits:
Implementation is easy.
De-Merits:
Instructions are repeated for all the data items.
Wastage of memory.
Instruction would overlap data in the core.
Suppose you wanted to process 300 data items(instead of 10) then the storage
needed for the instructions.
=Instruction * number of data Instruction * size of the instruction
=3*300*4
=3600 bytes
Address Modification using Instructions as data:
In the straight forward approach we used only 3 instruction ie load, store, add and
store which was repeated.
Only change is in the offset of load and store instructions.
Bit
0 7 8 11 12 15 16 19 20 23 31
Number
Byte
Number 48 49 50 51
Now we add 4 to this instruction the offset present in the 4 th byte is treated as
data and is increased by 4.
L+4=908
Absolute Relative Instruction Comments
Address Address
64 16 A2, 896(0,1)
896+c(1)=896+48=944
C(R2)=L2, 904(0,1)+4
=L2,908(0,1)
Absolute Relative Instruction Comments
Address Address
68 20 ST 2,0(0,1) 0+c(1)=48
Store back contents of R2 to location 48.
80 32 ST 2,8(0,1) =8+c(1)=8+48=56
944 896 4
948 900 49
952 904 Number
Advantage:
Saves memory.
Address is modified easily using the instruction.
Disadvantage:
Separate instruction should be used for increasing the displacement of load
and store instructions.
944 896 4
948 900 49
952 904 number
SR 4, 4:
Clear register 4 by subtracting the contents of register 4 from register 4.
Contents of register 4=0
SR is RR type instruction whose length is 2 bytes. Therefore absolute and
relative address is incremented by 2.
L2, 904(4,1):
Load data element of array.
Address of storage operand= 904+ Contents of index register 4+ contents of
base register 1=904 +48=948.
Contents of register 2= contents of memory location 952=Data1
L is Rx type instruction whose size is 4 bytes. Absolute and relative address is
incremented by 4.
A2, 900(0,1): Goal: Add 49 to content of register2.
Add 49.
Address of storage operand=900+Contents of base register 1
=Contents of register2+ Contents of memory location 948
= Data1+49
L is RX type instruction whose size is 4 bytes therefore absolute and relative
address is incremented by 4.
ST2, 904(4,1): Goal: Store the contents of register 2 to location 904(4,1)
Replace data element.
Address of storage operand= 904+ content of index register 4 and contents of base
register 1
=904+0+48=952.
Contents of memory location 952= Contents of register 2=Data1+49.
ST is LX type instruction whose size is 4 bytes. Absolute and relative address is
incremented by 4.
A4, 896(0,1): Goal: Increment index register by 4.
Add 4 to index register.
Address of the storage operand=896+Contents of base register1.
=896+48=944.
Advantage:
Easy to understand
Saves memory
Looping:
Additional assumptions made for this method are
Assumption 6: Relative location 892 contains 10 (temp).
Assumption 7:Relative location 888 contains a 1.
70 22 S 3,888(0,1) Subtract 1
74 26 ST 3,892(0,1) Store temp
78 30 BC 2,2(0,1) Branch if result is positive
(2 denotes a condition code)
Absolute Relative Instruction Comments
Address Address
936 888 1
940 892 (initially 10 decremented by 1 after each loop)
944 896 4
948 900 49
952 904 numbers
L3,892(0,1)
Load temp into R3.
Address of storage operand= 892+contents of base register 1
= 892+48=940
Contents of register 3=Contents of memory location 940=10
S3, 888(0,1):
• Subtract 1.
• Address of storage operand= 888+contents of register 1.
o =888+48=936.
• Content of register 3= contents of register 3 –contents of memory location 936=
10-1=9.
• S is Rx type instruction whose size is 4 bytes. Absolute and relative address is
incremented by 4.
ST 3, 892(0, 1):
Store temp.
Address of storage operand= 892+contents of base register 1
= 892+48=940.
Contents of memory location 940=contents of register 3 =9.
BC 2,2(0,1)
Branch if result is positive.
2 denotes a condition code.
Address of storage operand= 2 + contents of base register 1.
=2+48=50.
Branch to location 50 if result is positive.
BC is RX type instruction whose length is 4 bytes. Absolute and relative address is
incremented by 4.
R3 register for temporary storage and R4 register for index register.
Assembly Language:
It is the most independent language used by programmer today.
Features of Assembly language.
Mnemonic Operation Codes: it is written using mnemonic operation codes. Programmer need
not memorize the numeric operation code and it enable the assembler to provide helpful
diagnostics like indication of misspelt operation codes.
Symbolic Operands: It can be associated with data or instructions and can be used with
operands in assembly statements.
It performs memory bindings to these names.
Data Declarations: IT can be declared in a variety of notation including the decimal notation
thereby avoiding the manual conversion of constants into their internal machine representation.
Advantages of Assembly language:
1. It is mnemonic.
2. Addresses is symbolic not absolute.
3. Reading is easier.
4. Introduction of data to program is easier.
5. It is not required to keep track of memory locations.
6. It can be easily modified than machine language programmers
The operand field of DC must be constant The operand field of EQU can be a constant
value. or any sort of valid arithmetic expression.
3.BCT: It indicates the branch on count. It is an RX type instruction whose size is 4 bytes.
BCT 3, Loop
This decrements register 3 by 1 and if result is not zero branches back to loop.
BALR USING
BALR is a machine op Using is a pseudo op
IT is a instruction to the computer to load Using indicates to the assembler which
a register with the next address and general register to use as a base register
branch to the address in the second field. and what to do with the contents will be.
BALR loads the base register Using informs the assembler what is in
the base register.
Sets the register with the next address Only provides the information to the
assembler.
Assembly Language Program:
Assembly language program for the previous addition problem is given in figure 2.10.
All the assumptions made while writing the machine language program are
eliminated in assembly language program.
Programmer will not know into which location the program will be loaded.
Programmer will know the location of the program only at execution time where in
memory the loader will load the program.
BALR is used for this.