Professional Documents
Culture Documents
SP Unit-1
SP Unit-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.
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
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
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
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
1. Closed subroutines
2. Open subroutines
• The task of adjusting programs, so that they may be placed in arbitrary memory locations
is called relocation.
• 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, statistical
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
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 languages
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.
• 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
Chapter-2
Machine structure, Machine language and Assembly language
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
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
6. Long form floating point numbers
7. Logical or character data
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
• 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
Example:-118.625e5
4byts(32bits)
1bit 7bits 24bits
1 1000010 0111 0110 1010 0000 0000 0000
S Exponent Fraction
• 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
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.
The different instruction formats are
o RR format
o RX format
o RS format
o SI format
o SS format
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
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
• 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)
• Assume base register 5 contains the number 1000
• The address of the storage operand= C(B2)+C(X2)+D2
=C(5)+0+16
=1000+0+16
=1016
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
SI instruction
• SI instruction denotes storage and immediate operand operation
• Immediate operands are single byte of data and stored as part of the instruction
• The length of SI type instruction is 4 bytes (32 bits).
• The general format of SI instruction is
SS instruction
• SS instruction denotes a storage to storage operation
• The length of SS instruction is 6 bytes(48 bits)
• The general format is
4. Transfer instructions
5. Miscellaneous instructions
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.
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
• 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 sequence
of commands that would change the offset of the load and store instruction by adding 4 to
them
• 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 4th byte is treated as data
and is incremented by 4.
L+4=904+4
=908
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
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
• Address of the storage operand =904+contents of index register 4+contents of base
register1
=904+0+48
=952
• Contents of memory location 952 =contents of register2
=Data1+49
A 4,896(0,1)
• Add 4 to index register
• Address of the storage operand =896+contents of base register1
=896+48
=944
• Contents of index register 4 = Contents of index register 4+contents of memory
location944
=0+4=4
Note
• SR is RR type instruction, whose length is 2 bytes
• L is RX type instruction, whose length is 4 bytes
• A is RX type instruction, whose length is 4 bytes
• 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
The additional assumptions made for this method are
• Assumption 6: relative location 892 contains a 10
• Assumption 7: relative location 888 contains a 1.
s
L 3,892(0, 1)
• Load data into register 3
• Address of the storage operand =892+C(B1)
=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
• 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 register 3
=9
BC 2, 2(0,1)
• Branch if result is positive.
• 2 denotes a condition code
• Address of the storage operand =2+C(B1)
=2+48
=50
Assembly language
Definition
Assembly language is a low level programming language that allows and uses to write programs
using mnemonics (symbols)
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
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 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 loop