Unit 1
Unit 1
com 1
Chapter-1
Introduction
Software
Software is as set of instructions or programs written to carry out certain task on digital
computers
Types of software
1. System software
2. Application software
System software
System software consists of a variety of programs that support the operation of a
computer
Ex:OS,compiler,loader linker ,assembler,macroprocessor
System software acts as an intermediary between the users and the hardware. It creates a
virtual environment for the user that hides the actual computer architecture.
Virtual machine is a set of services and resources created by the system software and
seen by the user.
Application software
An application is a program, or group of programs, that is designed for the end user.
The special purpose programs are also know as packages
Ex. database programs, word processors, Web browsers and spreadsheets, library
management system.
srizanaryal.blogspot.com 2
Difference between system software and application program
System software Application software
1. It is used in the operation of the computer. 1.it is used to perform some user task
2. it is machine dependent software 2.it is machine independent software
3.the programmer should know the architecture 3.not necessary to know the
of the computer architecture of the computer
4. System software is not meant to be run by 4. Application software can be run by
the end user. the end user.
5.inventory, payroll preparation,
5.ex compiler,loader,os,assembler etc. banking system etc
srizanaryal.blogspot.com 3
Macro processor is a program that substitutes and specializes macro definitions for macro
calls.
Compilers:
The programs that translate the high level language program (source code) into machine
language program (object code)
Operating system
It contains programs which manage and it is concerned with allocation of resources and
services such as memory, processor, devices and information.
Machine structure
Memory
Memory is the device where information is stored and retrieved.
Information is stored in the form of 1‟s and 0‟s.
Each 1/0 is a separate binary digit called bit.
Bits are grouped into words, characters or bytes.
o Nibble 4bits
o Byte 8bits
o Half word 16bits
o Word 32bits
o Double word 64bits
Basic unit of memory is a byte
the content of memory are
o DATA- values to be operated on
o INSTRUCTIONS-operation to be performed
Instructions and data shares the same memory or storage medium
srizanaryal.blogspot.com 4
Processor
Processor is a device that performs a sequence of operations specified by instructions in
memory.
There are two types of processors,
1. Central processing units
2. Input and output processors
Central processing units
It is the brain of the computer
It controls all internal and external devices, performs arithmetic and logic operations
It also carries out the instructions of a computer program
It is concerned with manipulations of data stored in memory
Input and output processors
Input and output processors transfers data between memory and peripheral devices such
as disks, drums, printers etc.
An I/O processor executes these instructions which are activated by a command from the
CPU.
Programming the I/O processor is called as I/O programming
srizanaryal.blogspot.com 5
Evolution of the components of a programming
system Assembler
In the earlier stages the computer programmers are used to write programs using 0‟s and
1‟s.programmers found difficult in writing programs using machine language
Assembly language is a low level programming language that allows a user to write
programs using letters and symbols (mnemonic) which are more easily remembered.
Assembler is a system program supplied by the computer manufacturer
Assemblers are the programs that translate the assembly language program(source code)
into machine language program(object code)
Loaders
The purpose of a loader is to assure that object programs are placed in memory in an
executable .the assembler itself could place the object program directly in memory and
transfer control to it, then that machine level language program is executed. But there are
two disadvantages
1. Wastage of memory-assembler itself occupies more space in memory during
execution.
2. Wasting translation time-need of retranslation of the program with each
execution.inorder to avoid this the new system software called loader is introduced
If the program size is very large then subdivide the program into smaller routines called
sub-routines
There are two different types Subroutines
srizanaryal.blogspot.com 6
1. Closed subroutines
2. Open subroutines
The task of adjusting programs, so that they may be placed in arbitrary memory locations
is called relocation
srizanaryal.blogspot.com 7
Relocating loader perform four functions
1. Allocate space in memory for the programs (allocation)
2. Resolve symbolic references between object decks(linking)
3. Adjust all address dependent locations(relocation)
4. Physically place the machine instructions and data into memory(loading)
Based on the loading function the loader is divided into different types they are
1. Compile and go
2. Absolute loader
3. Relocating loader
4. Direct linking
5. Dynamic loading and linking
Macros
To eliminate the need of repeating identical parts of the program, operating systems
provide a macro processing facility
Macro permits to define an abbreviation for a part of program and use the abbreviation in
anywhere in a program. The macro processor treats the identical parts of program defined
by the abbreviation as a macro definition.
The macro processor substitutes the definition for all occurrences of the abbreviation in
the program
Compiler
As the user started concentrating problems into areas such as scientific, business, statistica l
areas. High level languages were developed to express certain problems more easily.
COBOL,FORTRAN,PASCAL,ALGOL ,C etc are high level languages, which is
processed by compilers and interpreters
srizanaryal.blogspot.com 8
Formal systems
A formal system is an uninterrupted calculus. It consist of
o An alphabet
o A set of words called axioms and
o A finite set of relations called rules of inference
Examples of formal systems are set theory,boolean algebra, post systems
Uses of formal systems
o Used in the design, implementation and study of programming language s
o Used to specify the syntax and the semantics of programming languages
o Used in syntax directed compilation, compiler verification and complexity studies of
languages
Operating system
OS is a program that controls the execution of an application program and acts as an
interface between user and computer hardware.
srizanaryal.blogspot.com 9
The main functions of operating system are
o Job sequencing
o Job scheduling
o Input/output programming
o Secondary storage management
o User interface
o Error-handling
srizanaryal.blogspot.com 10
Chapter-2
Machine structure, machine language and assembler language
srizanaryal.blogspot.com 11
Instruction interpreter
It is a group of electrical circuits that performs the purpose of the instructions fetched
from the memory.
It is like a decoder that decodes the type of the instruction.
It is also known as program counter or instruction counter which holds the location of the
current instructions being executed
It is hardware that transfers data between the MBR and the core memory location the
address of which in the MAR
I/O channels
It may be through of as separate computers which interpret special instructions for
inputting and outputting information from the memory.
srizanaryal.blogspot.com 12
Address=value of an offset + contents of a base register + contents of an index register
Registers
Types of register are
Name of the register number size
General purpose registers 16 32bits each
Floating point registers 4 64bits each
Program status word 1 64bits
901 - offset
2 - Index register
15 - Base register
The total number of bits for an add instruction would be 32
srizanaryal.blogspot.com 13
i.e., if base register is not used 40 bits is required for each instruction which leads to an addition
of bits and thus wastage of memory.
Data formats
The different types of data formats present in IBM system 360 are
1. Short form fixed point numbers
2. Long form fixed point numbers
3. Packed decimal numbers
4. Unpacked decimal numbers.
5. Short form floating point number
Example: The byte address starting from 1016 it occupies four locations
4 bytes =32bits
0 000 0000 0000 0000 0000 0001 0000 1011
S(+) 1016 1017 1018 1019
Byte address
3. Packed decimal numbers
srizanaryal.blogspot.com 14
The numbers are represented in binary coded decimal format
Sign bit contains the BCD of hexadecimal digits A,B,C,D,E & F
The hex digits C,A,F,E indicates a +ve numbers
While D & B indicates a –ve numbers
Example:-021 is represented as
2bytes
0000 0010 0001 1101
The last 1byte (4+4 bits) is reserved for sign and data.
In between the BCD of each numbers a 4 bit zone code/padding bit/internibble bit is
introduced which contains 0/1.
The hex digits C,A,F,E indicates a +ve numbers
While D & B indicates a –ve numbers
5. Short form floating point number
Example:-118.625e5
4byts(32bits)
1bit 7bits 24bits
1 1000010 0111 0110 1010 0000 0000 0000
S Exponent Fraction
srizanaryal.blogspot.com 15
1bit-sign bit(-ve)
7bits represent exponent-in this example 5 is the exponent the range of the 7bit is 127.so
add 127+5=132 then 132 is convert to binary(2) by division method
24bits represents fraction- in this example 0.625 is the fractional part then convert 0.625
to binary by repeated multiplication by 2
6. Long form floating point numbers
It is same as short form floating point numbers but in Long form floating point numbers
consists of 64bits (8 bytes) are allocated for the floating point number which contains the
exponential and fractional part
srizanaryal.blogspot.com 16
Register operands
Register operands refer to data stored in one of the 16 general purpose registers, which
are addressed by 4 bit field in the instruction.
Storage operands
Storage operand refers to data stored in core memory. The length of the operand depends
upon the specific data type.
Immediate operand
Immediate operands are single byte of data and are stored as part of the instruction.
RR instruction:
RR instruction denotes register to register operation.i.e, both the operands are register.
The length of RR instruction is 2 bytes (16 bits)
The general format of RR
Example: the instruction is Add 3, 4
RX instruction:
RX instruction denotes a register and indexed storage operation
The length of RX instruction is 4 bytes (32 bits)
The general format of RX instruction is
Indexed storage operand refers to the data stored in core memory. The address of the
storage operand is calculated as follows
srizanaryal.blogspot.com 17
Address=value of an offset or displacement + contents of a base register + contents of an
index register
=C(B2)+C(X2)+D2
Example: ADD 3,16(0,5)
4 BYTES
OP R1 X2 B2 D2
0101010 0011 0000 0101 0000 0001 0000
RS instructions
RS instruction denotes register and storage operation
The length of RS type instruction is 4 bytes (32 bits).
The general format of RS instruction is
4bytes
OP R1 R3 B2 D2
1001 1000 0001 0011 0101 0000 0001 0000
Load multiple
register 1 3 5 16
Address =C (B2) + D2
= C(5)+16
=1000+16
=1016
The load instruction loads register 1 and 3 with the contents of location 1016
srizanaryal.blogspot.com 18
SI instruction
SI instruction denotes storage and immediate operand operation
Immediate operands are single byte of data and stored as part of the instruction
srizanaryal.blogspot.com 19
In SS format, the length is always on less than the data moved.i.e. 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)]
Instruction set
The various categories of instructions are
1. load-store registers instructions
2. Fixed point arithmetic
3. Logical instructions
4. Transfer instructions
5. Miscellaneous instructions
srizanaryal.blogspot.com 20
2. Fixed point arithmetic
3. Logical instructions
srizanaryal.blogspot.com 21
4. Transfer instructions
5. Miscellaneous instructions
srizanaryal.blogspot.com 22
Machine language make efficient use of storage
Disadvantages
Machine languages are machine dependent
Machine language is difficult to program, since the programmers has to know the
architecture of the system.
Writing, reading, correcting or modifying a machine language program is difficult.
Example program:
Write a program that will add the number 49 to the contents of 10 adjacent full words
(32bits or 4 bytes) in memory with the following assumptions:
1. The 10 numbers are contiguous full words beginning at absolute location 952.
2. The program is in core memory starting at absolute location 48.
3. The number 49 is a full word at absolute location 948.
4. Register 1 contains a 48.
srizanaryal.blogspot.com 23
L 2,904(0, 1)
Load the first number into register 2
Address of the storage operand =904+contents of base
register1 =904+48 =952
Contents of register 2=contents of memory location 952=Data1
A 2,900(0, 1)
Add 49 with data1
Address of the storage operand =900+contents of base
register1 =900+48 =948
Contents of register 2 =contents of register2+contents of memory location 948
=Data1+49
ST 2,904(0, 1)
Address of storage operand =904+contenet of register1
=904+48
=952
Content of register 2 =content of base register2
=Data1+49
L and ST are RX type instruction. Whose size is 4 bytes. Therefore absolute and relative
address is incremented by 4.
Advantages
Implementation is easy.
Disadvantages
Instructions are repeated for all the data items
srizanaryal.blogspot.com 24
It is impossible to access both the first data item and the last data item using register 1 as
the base
Wastage of memory
Need of relocation.
Instruction would overlap data in the core.
In this approach the problem consisting only of those 3 instructions followed by a the
sequence of commands that would change offset of the load and store instruction by
adding 4 to them.
srizanaryal.blogspot.com 25
In addition to the 4 assumptions given in the problem statement, we are going to make
one more assumptions.
Assumption 5: relative location 896 contains a 4.
Here instruction is treated as data. Therefore adding 4 to an instruction will update its
offset.
For example, if location 48 contains the instruction L 2,904(0, 1)
The instruction is stored as follows from byte number 48
Now when we add 4 to this instruction, the offset present in the 4 th byte is treated as data
and is incremented by 4.
L+4=904+4
=908
srizanaryal.blogspot.com 26
Advantages
Saves memory
Address is modified easily using the instruction.
Disadvantages
Treating instructions as data is not a good programming practice
Separate instructions are used for increasing the displacement(offset) of load and store
srizanaryal.blogspot.com 27
SR 4, 4
Clear register 4 by subtracting the contents of register 4 from register 4.
The contents of register 4=0
L 2,904(4,1)
Load data element of array
Address of the storage operand=904+contents of index register 4+contents of base
register 1
=904+0+48
=952
Content of register 2 =contents of memory location
952 =data1.
A 2,900(0, 1)
Add 49
Address of the storage operand =900+contents of base register 1
=900+48
=948
Contents of register 2 =contents of register 2+contents of
memory =Data1+49
ST 2,904(4, 1)
Replace data element
srizanaryal.blogspot.com 28
ST is RX type instruction, whose length is 4 bytes
Contents of index register 4 will be 4,8,12 etc during the subsequent passes
Advantages
Easy to understand
Saves memory
4. Looping
L 3,892(0, 1)
Load data into register 3
Address of the storage operand =892+C(B 1)
=892+48
=940.
Content of register 3 =contents of memory location
940 =10
S 3,888(0, 1)
Subtract 1
Address of the storage operand =888+contents of register 1
=888+48
=936
srizanaryal.blogspot.com 29
C(R3) =C(R3) -contents of memory location936
=10-1
=9
ST 3,892(0, 1)
Store temp
Address of the storage operand =892+C(R1)
=892+48
=940
Content of memory location 940 =contents of regis ter 3
=9
BC 2, 2(0,1)
Branch if result is positive.
Assembly language
Definition
Assembly language is a low level programming language that allows and uses to write
programs using mnemonics (symbols)
srizanaryal.blogspot.com 30
Advantages
1. It is mnemonic
2. Reading is easier
3. Addresses are symbolic
4. Introduction of data to program is easier
5. It can be easily modified than machine language programs.
Disadvantages
1. An assembly language is required to translate source program into object program
2. It is machine dependent.
3. Lack of portability of programs between computers of different makes.
Pseudo opcodes
Pseudo opcode is an assembly language instruction that specifies an operation of the
assembler.
USING
Using is a pseudo opcode that indicates to the assemble which General Purpose
Register to use as a base register and what value it contained at execution time
Syntax
USING <content of base register><GPR to be used as base register>
Ex:
USING * 5
START:
Start is a pseudo opcode that tells the assembler where the beginning of the program
is and allows the user to give a name to the program
Ex:
START sum
Or
sum START
END:
End is a pseudo opcode that tells the assembler that the last statement of the program
has been reached
Ex:
END
EQU:
EQU is the pseudo opcode which allows the program to define variables
Ex:
BASE EQU 15
srizanaryal.blogspot.com 31
DC (data constant)/(define constant):
DC is a declarative pseudo opcode used to create a memory area to hold a constant
value
Syntax:
<Label>DC „constants‟
Ex:
FOUR DC „F4‟
DS (data storage)
DS is the pseudo opcode that reserves storage for the data and gives them a name
Syntax
<Label> DS „size‟
Ex:
FOUR A DS 1F
DROP:
Drop is a pseudo opcode which indicates an unavailable base register and its contents
Syntax:
DROP<BS register number>
Ex:
DROP 15
LTORG:
LTORG is a pseudo opcode which tells the assembler to place the encountered literals
at an earlier location
Machine opcodes
BALR:
BALR is a branch and link instruction. It is an instruction to the computer to load a
register with the next address and branch to the address specified in the second field.
BALR loads the base register and it is not an executable statement it is an RR type
instruction whose length is 2 bytes.
Ex: BALR 15,0
BR:
BR is a machine opcode indicating branch to the location whose address is in general
register
Ex: BR 14
BCT:
BCT indicates branch and count it is a RX type instruction whose size is 4
bytes. Ex: BCT 3, loop
Decrements register 3 by 1 if result is not 0 branch back to loo
srizanaryal.blogspot.com 32