KEMBAR78
Chapter 1 | PDF | Assembly Language | Computer Program
0% found this document useful (0 votes)
25 views90 pages

Chapter 1

The document outlines the distinctions between application and system programs, emphasizing that system programming involves creating software that operates computer hardware and supports application execution. It details the components of machine structure, including memory, CPU, and I/O processors, and explains the roles of assemblers, loaders, compilers, and interpreters in program translation and execution. Additionally, it discusses the evolution of operating systems and their functions, highlighting the importance of efficient resource management and user interaction.

Uploaded by

abhishes39561
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)
25 views90 pages

Chapter 1

The document outlines the distinctions between application and system programs, emphasizing that system programming involves creating software that operates computer hardware and supports application execution. It details the components of machine structure, including memory, CPU, and I/O processors, and explains the roles of assemblers, loaders, compilers, and interpreters in program translation and execution. Additionally, it discusses the evolution of operating systems and their functions, highlighting the importance of efficient resource management and user interaction.

Uploaded by

abhishes39561
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/ 90

System programming

Computer Programs are of two types


 Application Program
 System Program

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.

 It traditionally lies between the user interface and system calls.

 System programs include the operating system and firmware,


programming tools such as compilers, assemblers, I/O routines,
interpreters, scheduler, loaders and linkers as well as the runtime
libraries of the computer programming languages.

 Systems programming covers data and program management,


including operating systems, control programs, network software,
and database management system.
Machine Structure:

 Machine structure consist of Memory, Cpu and I/O Processor.

1. Memory:

 It 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 a bit.
 Bits are grouped into words, characters or bytes.

Group of bits are called as follows.


 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 location is specified by addresses where each address identifies a
specific byte or word.
 Contents of it may be
 Data-values to be operated on.
 Instructions: Operations to be performed.

A code is a set of rules for interpreting the group of bits.

For example

• BCD(Binary Coded Decimal) represents decimal digits.


• EBCIDIC(extended binary-coded decimal interchange code) represents characters.
• Specific Processor operation codes is used for representing instructions.

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:

• It is the brain of the computer.


• It is responsible for all the events inside the system.
• It controls all internal and external devices, perform arithmetic and logic
operations.
• It carries out each instruction of the program in sequence and is concerned
with manipulation of data stored in memory.

Input/output processor:

• Transfers data between memory and peripheral devices such as disks,


drums, printers etc.
• I/o instructions are stored in memory.
• 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.
• I/o instruction set is different from that of CPU and executed asynchronously
with cpu operation.
• Asynchronous operation of I/o channel and cpu is known as multiprocessing.
• Multiprocessing means multiple processors operating on system.
• A system with multiple processors is called as multiprocessing.
• Coordination between the processors and process is done by the traffic
controller.

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.

Procedures are general solution of a Program are interrelated with computer


problem hardware and computer software.
Difference between Processor and I/O channel:

Processor I/O Channel


Device that performs a sequence of I/O channels need processor in order to
operations specified by instructions in execute I/O instructions that are stored in
memory. memory.

IT is the internal components of the It is the external components of the system.


system.

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.

To overcome the above drawbacks of assembler the loaders were used.


Loaders is a program that loads object program into memory and prepares
them for execution.
Memory is not wasted since the size of the loader is smaller compared to
assembler.
Retranslation is not required in the case of loader since the translation program is
already in secondary storage.
Subroutine:
 If the program size is large it is divided into smaller routine called
subroutines.
 Subroutine is a set of computer instructions designed to be used by
other routines to accomplish a task.

There are 2 types of subroutines and they are


 Closed subroutine and
 Open subroutine

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:

 It is stored outside in the main routine and during a subroutine call


control is transferred to it.
 Associated with closed subroutine the main program performs two tasks
that it transfers of control and transfer of data.
 Initially Closed subroutine has to be loaded into memory at a specific
address.
 Task of adjusting programs so that they may be placed in arbitrary
memory locations is called relocation.
 The "arbitrary addresses" are places in the main memory.
 These "arbitrary addresses" refer to the memory of the local system.
 The arbitrary means any random address.
 An EXE file can access memory that is actually intended for another
program.
Closed Subroutine Open 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.

Saves Memory Wastage of memory.

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:

It is the task of adjusting programs so that they may be placed in arbitrary


memory locations.
Relocating loaders performs the following four functions:
a) Allocation: Allocates space in the memory for the programs.
b) Linking: Resolve symbolic references between object desks.
 Modules are called for the different pieces of code, which are written in programming
languages.
 Linking is a process that helps to gather and maintain a different piece of code into an
executable file or single file.
 Usually, computer programs are made up of various modules in which all being a
compiled computer programs and span separate object files.
 The whole program refers to these different compiled modules with the help of using
symbols. These separate files are combined by linker into a single executable file.
c) Relocation: Relocation is the process of connecting symbolic references with
symbolic definitions.
For example, when a program calls a function, the associated call instruction
must transfer control to the proper destination address at execution.
d) Loading: Physically place the machine instructions and data into the memory.

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.

Macro definition: It is a sequence of code that has a name.


Macro: single line abbreviation/name for some group of instructions.
Macro call: it is the occurrence of the macro name in the source program as an
operation mnemonic to be expanded.
Macro processor: Program that substitutes for all occurrence of the macro call in
the program.
Compilers:
.
It is a program that accepts a program written in high level language and convert
into an object program.

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.

Compilation process consist of


 First loading the computer with the compiler
 Inputting the source program through a suitable device.
Compilers:
.

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.

Interpretation cycle consist of below mentioned steps


Step-1: Fetch the statement.
Step-2: Analyze the statement and determining its meaning.
Step-3: Execute the meaning of the statement.
Compiler Assembler
Compiler converts the source code written Assembler converts the assembly code into
by the programmer to a machine level the machine code.
language.
Compiler input source code Assembler input assembly language code.
The compilation phases are lexical analyzer, Assembler makes two phases over the given
syntax analyzer, semantic analyzer, input, first phase and the second phase.
intermediate code generated, a code
optimizer, code generator, and error handler
The output of compiler is a mnemonic The output of assembler is binary code.
version of machine code.
C, C++, Java, and C# are examples of GAS, GNU is an example of an assembler.
compiled languages.
Compiler Interpreter
Compiler converts the entire source An interpreter takes a source program
code into executable machine code. and runs it line by line translating each
line as it comes to it.

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.

The compiler generates the error Its Debugging is easier as it continues


message only after scanning the whole translating the program until the error is
program, so debugging is comparatively met.
hard as the error can be present
anywhere in the program.

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.

Main advantage of compilers is it’s Due to interpreters being slow in


execution time. executing the object code, it is preferred
less.

It converts the source code into object It does not convert source code into
code. object code instead it scans it line by line

Takes less main memory because Takes more main memory


interpreted languages is simple

Eg: C, C++, C# etc. Python, Ruby, Perl, SNOBOL, MATLAB,


etc.
Formal System:
 It is an uninterrupted calculus ( a method of computation or calculation in a
special notation (as of logic or symbolic logic)).
It consist of
• An alphabet
• A set of words called axioms and
• A finite set of relations called rules of inference.

Examples of formal systems are set theory, Boolean-Algebra, post systems and
Backup normal form.

Uses of Formal Systems:

 Used in design, implementation and study of programming languages.


 Used to specify the syntax and the semantics of programming languages.
 Used in Syntax directed compilation, compiler verification and complexity
studies of languages.
Operating System:

Program that controls the execution of an application program and


acts as an interface between the user of a computer and computer
hardware.
 Convenience:
OS makes the computer more convenient to use.
 Efficiency:
OS allows the computer system resources to be used in an
efficient manner.
 Ability to evolve:
OS should be constructed in such a way as to permit the
effective development, testing and introduction of new system
functions without interfering with current services.
Operating System:

 Program that acts as an interface between hardware and user programs.


 The purpose of an OS is to provide an environment in which a user can
execute programs in a convenient and efficient manner.
 OS is similar to our government ie it is a resource allocator and a control
program.
Following are some of important functions of an operating System.
 Memory Management
 Processor Management
 Device Management
 File Management
 Security
 Control over system performance
 Job accounting
 Error detecting aids
 Coordination between other software and users
Evolution of Operating System:
1. Simple Batch System
2. Mutiprogrammed Batch System
3. Time Sharing system
4. Distributed Systems
5. Real Time Operating System.

1. Simple Batch System:


 In this type of system, there is no direct interaction between user and the
computer.
 Jobs with similar needs were batched together and were run as a group.
 The user has to submit a job (written on cards or tape) to a computer
operator.
 Then computer operator creates a batch of several jobs on an input device.
 Jobs are batched together by type of languages and requirement.
 After the jobs are created a special program monitors and manages the
execution of each program in the batch.
Examples: Bank statement, payroll system etc.
Multiprogramming Batch Systems:

 Multiprogramming is an extension to batch processing where the CPU is


always kept busy.

 It allows multiple programs to reside in separate areas of core at the same


time.

 Multiprogramming increases cpu utilization by organizing jobs such that


cpu always has a job to execute.

 Each process needs two types of system time: CPU time and IO time.

 In a multiprogramming environment, when a process does its I/O, the CPU


can start the execution of other processes.

 When one program needs Input/output from disk it is suspended and


another program whose data is already in main memory is taken for
execution.
Multiprogramming Batch Systems:

 In a simple batch operating system, sometimes CPU is idle and doesn’t


perform any task, but in the multiprogramming batch operating system, CPU is
busy and will never sit idle and always keeps on processing.
 Multiple programs runs on CPU.

 This partitioned memory has some holes or unused portions of memory as it is too
small to hold the program is called as Fragmentations.

 Fragmentation is reduced by means of relocating partitions and paging.

 Relocating partitions allows the unused portions to be condensed into one


continues part of memory.

 Paging is process of memory allocation by which program is subdivided into equal


portions or pages and memory is divided into equal portions or blocks.
Multiprogramming Batch Systems:
 If several jobs are ready to run at the same time, then the system
chooses which one to run through the process of CPU
Scheduling.

 In Non-multiprogrammed system, there are moments when CPU


sits idle and does not do any work.

 In Multiprogramming system, CPU will never be idle and keeps


on processing.

 Multiprogramming allows multiple programs to reside in separate


areas of core at the same time.

 Multiprogramming increases the cpu utilization by organizing


jobs such that the cpu always has a job to execute.
Time Sharing Systems:

 Time Sharing Systems are also called as Multitasking system.

 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.

 The major difference between Time-sharing operating system and Multiprogramming


batch operating system is that the time-sharing operating system aims to minimize the
response time, whereas the Multiprogramming batch operating system is to increase the
use of the processor ie increases the cpu utilization.

Examples of Time-Sharing OSs are: Multics, Unix, etc.


3. Distributed Operating System –
 Distributed operating system is also known as loosely coupled systems.
 Independent systems possess their own memory unit and CPU. These are referred to
as loosely coupled systems or distributed systems. These system’s processors differ in size
and function.
 multiple central processors are used to serve multiple real-time applications and multiple
users.
 The processor communicate with one another using communication lines such as
Ethernet.

Reasons for building distributed systems are


1. Resource Sharing: if number of different sites are connected to one another then user at
one site may be able to use the resources available at the other.
2. Computation Speed up:
If a particular computations can be partitioned into a number of sub computations that can
run concurrently then a distributed system may allow user to distribute computation among
the various sites to run them concurrently.
3. Reliability: if one site fails in a distributed system the remaining sites can continue
operations.
4. Communications:

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

Where Add is the operation code,


2 is the register number and
176 is the memory location.
This instruction means add the contents of general register 2 with the data stored in
memory location 176 and store the result in register 2.

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.

Address = offset + contents of base register + contents of index register.

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.

Name of the register Numbers Size

General Purpose Registers 16 32 bits each

Floating point registers 4 64 bits each

Program status word 1 64 bits


General Purpose Register:

 IBM 360 has 16 general purpose registers denoted by R0 through R15.


 Length of each register is 32 bits. It is used for various arithmetic and logical
operations and as base registers.
 Registers is a scratch pads to which the number are added , subtracted , compared
when used for arithmetic or logical operations.

Consider the following instruction


A1,901(2,15)
Where A is the Add opcode
1 is the Argument register number
901 is the offset
2 is the index register
15 is the base register
This Instruction means add the contents of register 1 with a number.
The Location of the number is 901 plus the contents of index register 2 plus the contents
of base register 15.
The total number of bits for an add instruction could be 32 and the instruction is stored
the following format.
<------------------------------------------------------32 bits---------------------------------------
Opcode Argument Reg Index Reg Base Offset

8 bits 4 bits 4 bits 4 bits 12 bits


As we use base register the complexity of address formation increases but it helps in
efficient addressing.
If we are not using base register to address all the 224 bytes locations we would have
needed 24 bits for every address whose format would be

<----------------------------------------------40 bits-----------------------
Opcode Argument Reg Index Reg Address

8 bits 4 bits 4 bits 24 bits


If base register is not used 40 bits is required for each instruction which leads to a addition
of 8 bits and thus wastage of memory.

Advantages of Base Register:

1. It helps in the process of relocation of a program.


2. Entire program may be moved from one series of locations to another by changing the
contents of the base register.
3. Saves 8 bits per address reference.

Drawback of Base Register:


1. Overhead associated with the formation of the address during execution.
Floating point Register:
 Registers used to store the real numbers.
 There are 4 floating point registers and size of each is 64 bits.

Program Status Word(PSW):


 PSW contains the information required for proper execution of a given
program.
 It contains the value of the location counter, protection information and
interrupt status.
 The size of the PSW is 8 bytes (64 bits).

Data:

It is stored in memory as group of bits. Group of bits can be characters, number


or special characters.
Different data format present in IBM 360 are
 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.

Short form fixed point number:


 In short form fixed point number 16 bits are allocated to represent an
integer number out of this the first 1 bit is used for the sign.
(0 for + and 1 for –).
 Machine interprets the contents of this 2 bytes as an integer first bit as
an sign and the remaining 15 bits as a binary number.
S Integer
0 1 15

Decimal +257 is represented as


<----------------------------16 bits-------------------------------------
0 000 0001 0000 0001

sign bit Binary equivalent of 257

Long Form fixed point numbers:


 In long form fixed point 32 bits (4 bytes) are allocated, out of this first one bit
is reserved for sign (+ or -).
 Contents of this four bytes are interpreted as an integer.
 It interprets the first bit as sign and the remaining 31 bits as a binary number.
S Integer
0 sign bit 1 31
Decimal number +257 is represented as
0 0000 0000 0000 0000 0000 0001 0000 0001

Sign bit(+) 1016 1017 1018 1019

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.

3. Packed Decimal Numbers:

 Decimal digits packed 2 to a byte appear in field of variable length and


accompanied by a sign in the right most four bits.
 Numbers are represented in binary coded decimal format instead of binary
numbers.
 Packing of digits leads to efficient use of storage , increased arithmetic
performance and improved rates of data transmission which is useful in
business data processing.
Decimal Number
-021 is represented as
<---------------------2 bytes--------------------
0000 0010 0001 1101

--BCD of 021------
Sign Bit(-)-D

Note: Sign bit contains BCD of hexadecimal digits A, B, C, D, E and F.


The hex digits C, A, F and E indicates the positive number while D and B indicates a
negative number.

4.Unpacked Decimal Numbers:


 Size of unpacked decimal number varies from 1 to 16 bytes out of which the
last 1 byte is reserved for sign and data.
 Instead of representing the binary numbers, the numbers are represented in
binary coded decimal.
 In between the BCD of each number 4 bit zone code bit/inter nibble bit is
introduced which contains 0/1.
1 to 16 bytes
Z D Z D S 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.

Decimal Number -118.625 is represented as


<---------------------4 bytes------------------------------------------------------
1 1000010 01110110101010000000000000

Sign bit (-) Exponent (1 byte) Fraction(3 byte)

6. Long Form Floating Point numbers:

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.

7. Logical (character data):


Characters are stored as 8 bits Ascii code, each character occupies 1 byte (8 bits).
A is represented in IBM 360 as ------1 byte------------->
11000001
Instruction Format:
Program is a set of instructions.
It is simply sequence of bits (0 or 1) contained in machine instruction .
Machine instruction contains the number of bits and these bits are grouped
together called fields.

Instruction may be of the following types


 Arithmetic Instruction
 Logical Instruction
 Control or transfer Instructions
 Special Interrupt instructions

 An instruction includes an opcode, specifying the operation to be


performed such as “add contents of memory to register” and zero or
more operands which may specify registers, memory locations or literal
data.
 The Size or length of an instruction varies from 2 bytes to 6 bytes
depending on the instruction formats.
Instruction Formats:
IBM 360 uses different instruction formats and these instructions differ in the
type of operands they use. The different types of operands are
 Register Operands
 Storage Operands
 Immediate Operand.

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

RR instruction: It denotes register to register operation.


Both the operands are registers. General format of RR instruction is
-------------------------2
OP bytes----------------------------------------------------
R1 R2

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

0001 1010 0011 0100


--------------------------------------------------------------------------
Add Register 3 4
Add instruction add the contents of general register 3 with the contents of general register 4
and store the result back in general register 3.

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.

Address= Contents of base register + contents of index register + displacement


= C(B2)+C(X2)+D2

-------------------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

10001 1000 0001 0011 0101 0000 0001 0000

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

----------------- <----------------- --------------- -----------------


move Immediate 64 5 4
byte to operand1 (code for character
blank)

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: MVC 32(79,5),300(5)


Address of storage operand 1 address= C(B1) + D1
=C(5)+D1
=1000+32=1032
Address of storage operand 2 address=C(B2)+D2
=C(5)+D2
=1000+300
=1300
Length is always one less than the data moved.
If L=0 move 1 byte .
If L=79 so move 80 bytes from location 1032 (till 1111(1032+79))
To 1300 (till 1379 (1300 + 79)
Example 1:
MVC 32(79, 5), 300(5)
OP L B1 D1 B2 D2
1101 0010 0100 1111 0101 0000 0010 0000 0101 0001 0010 1100

<----------------> <--------> <-----> <---------> <------> <-------------------->


Move bytes 79 5 32 5 300
From operand 2
to operand 1
Summary of instruction Formats:
Machine Language:
Computer understands only 0’s and 1’s. language of the computer is called
machine language.
Machine language is one of the most primitive and cumbersome programming
language and it is the lowest level representation of a compiled or assembled
computer program.

Example 1:
Binary Representation of a load instruction:

0101 1000 0010 0000 0001 0011 1001 1100

OP R1 X2 B2 D2

Mnemonic Form of load instruction:


L 2, 924(0,1)
OP R1, D2(x2, B2)
Merits:
 Instruction of a machine language program are immediately executed and
require no compilation or translation.
 It make efficient use of storage.
De-Merits:
 It is machine dependent.
 It is difficult to program since the programmer should know the architecture
of the system.
 Writing , reading ,correcting or modifying a machine language program is
difficult.

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.

A2, 900 (0,1)


Add 49 to Data1.
Address of the storage operand = 900+Contents of base register 1.
= 900+48
=948
Content of register 2 = Contents of register 2 + contents of memory
location 948.
= Data1+49
A is Rx type instruction whose size is 4 bytes. Absolute and relative
address is incremented by 4.
ST 2, 904(0,1)
Store back.
Address of storage operand=904+contents of register 1
=904+48
=952
Contents of memory location 952= Contents of base register 2
= Data1+49
ST is RX type instruction whose size is 4 bytes therefor absolute and relative
address is incremented by 4.
L2, 908 (0,1)
Load Next data.
Address of storage operand= 908+Contents of base register1
= 908+48
= 956
Contents of register 2 = Contents of memory location 956 = Data 2
A2,900(0,1)
Add 49
Address of storage operand= 900+contents of base register 1
=900+48
=948
Contents of register 2=contents of register 2+ contents of memory location 948
= Data2+49
St 2, 908 (0,1)
Store Back.
Address of storage operand= 908 + Contents of register1=908+48=956
Contents of memory location 956= Contents of register 2=Data 2+49.

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.

Another approach is write a program consisting only of those 3 instruction 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 assumption given to the problem statement we are going to make
one more assumption.
Assumption 5: Relative location 896 contains a 4. The instruction is stored as follows
from byte no 48

8 bits 4 bits each 8 bits


<----------> <----------> <----------> <----------> <----------------------->
L 2 0 1 904

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

48 0 L2,904(0,1) Storage Operand=


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 the contents of R2 to location 952

60 12 L2,0(0,1) Increase displacement of load instruction by 4.


Storage Operand= 0+c(1)=48, c(R2)=L2,904(0,1)

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.

72 24 L2,8(0,1) Increase displacement of store instruction by 4


Storage Operand=
8+c(1)=8+48=56,c(R2)=ST 2,904(0,1)

76 28 A2,896(0,1) =896+c(1)=896+48=944,c(R2)=ST 2, 904(0,1)+4


=ST 2,908(0,1)

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.

Address Modification using index register:


We use same 3 instructions ADD, Load and Store.
We simply loop through 3 instructions updating the storage operands of Load and
store instructions by adding 4 to the contents of the index register during each
pass.

Register 4 is used as an index register.


Absolute Relative Instructions Comments
Address address
The program for the addition problem using index register is given below
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) Load data element of array


54 6 A 2,900(0,1) Add 49 to a number
58 10 ST 2,904(4,1) Replace data element

62 14 A 4,896(0,1) Add 4 to index register


896+c(R1)=896+48=944,c(R4)=0+4

Branch back to relative


location 2,9 times

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.

Contents of index register 4= Contents of index register 4+ contents of memory location


944=0+4=4.
Now the content of register 4 will be 4,8, 12 during the subsequent passes.

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.

The program for addition problem using looping is given below.

Absolute Relative Instruction Comments


Address Address
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


66 18 L 3,892(0,1) Load temp into register 3.

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

Disadvantages of Assembly Language:

1. An assembler 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,
4. Programs take longer to code because of more complex nature of the
language.
. Pseudo-Op:
It is an assembly language instruction that specifies an operation of the assembler. It is also said
be as Assembler directive.
1. Using:
It is a pseudo-op that indicates to the assembler which general purpose register to use as a
base register and what its contents will be in order to convert the addresses to base-
displacement format.
Syntax:
USING <Contents of Base register> <GPR to be used in base register>
Example 1:
USING *5
Indicates to the assembler that register 5 is sued as the base register and at execution time will
contain the address of the first instruction of the program.
2. START: it tells the assembler where the beginning of the program is and allows the user to
give a name to the program.
Example 1:
TEST START
Test is the name of the program.
3. END: It tells the assembler that the last statement of the program has been reached.
END.
4. EQU:
It is a pseudo-op which allows the programmer to define variables. Operand of the EQU
statement can be any constants or valid arithmetic operation.
Example 1:
BASE EQU 15
5. DC (Define Constants):
It is a declarative pseudo-op used to create a memory area to hold a constant value.
Syntax:
<label> DC ‘Constant’
Example:
FOUR DC F’4’
It associates the name FOUR with one full word in memory containing the value 4.
6. DS (Define Storage):
It is a declarative pseudo-op that reserves some storage for the data and give them a
name
Syntax:
<label>DS Size
Example:
BLOCK DS 100F
It causes the assembler to set aside 100 full words for BLOCK.
7. DROP:
It indicates the unavailable base register.
DROP <BR number>
Example:
DROP 15
Register 15 is no longer available as base register.
8.LTORG: It is the pseudo-op to place the encountered literal at an earlier location.
.DC EQU

DC is a declarative pseudo-op EQU is a pseudo op for defining variables


Eg: Ten Dc F’10 Eg: BASE EQU 15

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.

Location counter processing will be there No location counter processing

DC will create a memory word initialized to Everywhere symbol will be evaluated to


constant value. value.
Machine-OP:
Machine instruction should be included in the program to load the proper value into the base
register at execution time.
Different Machine-ops are
1.BALR: It is a branch and link instruction.
•It is an instruction to the computers to load a register with the next address and
branch to the address specified in the second field.
•If the second operand is register 0 then execution proceeds with the next
instruction.
•It loads the base register and is not an executable statement.
•it is an RR type instruction whose length is 2 bytes.
Example 1:
BALR 15,0
Set register 15 to the address of the next instruction.
2.BR:
It is a machine-op indicating branch to the location whose address is in general register.
Calling programs leaves their return address in the corresponding general register.
Example:
BR 14.

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.

Assembly language Program using Literals:


Literals: It look like a DC operand but it is preceded by a “=” sign. While using literals the
assembler creates data areas containing the constants.
For example:
L 3, TEN
TEN DC F’10’
Can be be replaced by
1 3, =F’10’
Where =F’10’ is a literal table and a data area whose size is 1 full word containing the
value 10 Is created.
Literal Table:
 All the constants that have been specified through literals will be placed in a table called
literal table.
 It is placed at the end of the program. LTOR’S is a pseudo-op which tells assembler to
place the encountered literals at an earlier locations.
 LTORG instruction coded as the last instruction of each control section in the program so
each control section in the program will have its own literal pool at the end of the
module.

You might also like