System Programming Unit 1-2
System Programming Unit 1-2
Introduction:
Operating system consists of several programs such as assembler, loader, macros and
compilers. In a package they are called as system software. The programs are named as system
programs.
To say it very clearly, the heart of the computer is a processor – CPU. It functions with
binary information ‘0’ and ‘1’ only. Various combinations of 0’s and 1’s makes specific meaning
called as machine code.
Normal user cannot write instruction in machine code. So the instructions are written in
high level language, which follows the familiar format, Eg. A = A+B. The system software
converts it into machine language and executes it. If anyone wants to develop a new operating
system, first he must understand the machine structure and its functions.
Background:
The background of a system deals with the machine structure and the instruction
format.
Machine Structure:
Instruction Interpreter
Location Counter
1
Instruction Register
General Registers
Working Registers
Basically the function of the CPU is to fetch the instructions (opcodes), stored in the
memory and executes it. If the data is needed, it may be retrieved from the memory or from
the I/O devices.
Location counter also called as Instruction pointer or program counter contains the next
address of the Instruction to be executed.
A copy of the instruction is available in Instruction register. After this, the instruction is
decoded and executed.
The I/O channel also called as I/O processor is used for data transfer between the CPU
and the I/O devices. It may be act as a separate computer and handle the I/O operations only.
Memory:
The fundamental unit of memory is byte, A byte contains 8 bits of information (bit may
be either 0 or 1). Memory consists of memory cells. These cells are identified by the addresses.
The address and the data (content of memory cell) are binary information uses Hexadecimal
controls. If the unit of memory is half byte, it is called as Nibble. The addressing of memory may
consist of three components. The real address is equal to the sum of the value of an offset, the
content of a base register and the index register value.
Example:
2
Real Address = 00900+06000+00030 = 06930
The communication between the memory and CPU are made through these registers.
The address of the information required by the CPU is stored in MAR.
MBR stores the information temporarily, before it is transferred to or from the desired memory
location denoted by MAR.
Memory controller:
It controls the traffic between CPU and memory. It is a hardware, which manages the
calling raised by I/O channels and the CPU to access the memory in order.
Working Registers:
These registers are used by the Instruction Interpreter to perform the necessary
calculations denoted by the instructions. The information can be stored temporarily and
retrieved from the working registers.
General Registers:
These registers are used by the programmers to store values for immediate accessing.
Software
System software.
System software is a program that converts source programs into object programs
Source program.
A program written in a high level language (or) Assembly language is known as source
program.
3
Object program (or) Target program
A source program which is translated into machine language is called object program.
1. Operating system.
3. Communications software.
4. Utility programs.
The main functions are to translate the source program into object program.
Communication software enables transfer of data and programs from one computer to
another.
Utility programs are a set of programs which help users in system maintenance tasks.
The main functions are to translate the source program to object program.
4
Differences between compiler and interpreter.
Compiler Interpreter
Translates the whole program into Translates and executes one statement of
machine code at a time. a program at a time.
Errors in the whole program will be Only a single error can be detected at a
detected at a time. time.
Compiler :-
Interpreter:-
Interpreter is a program which translates high level language program into machine language
line by line.
Assembler :-
The process of translating an assembly language program into its equivalent machine
language program is called assembler.
1. Machine language
2. Assembly language
3. High level language
5
1. Machine language
A program written in the form of 0’s and 1’s are called a machine language
program.
2. Assembly language:-
Examples:-
- programming is difficult
- Not portable
- Time consuming
- Program is longer and it needs translation.
6
Functions
ASSEMBLY LANGUAGE
An assembly language is the machine dependent language very close to the hardware
and restricted by the capabilities of the hardware. There are four main advantages in assembly
language compared to machine language.
1. It can be written as mnemonic codes. Instead of writing 0’s and 1’s we can write
letters as codes.
But to use the assembly language we need assembler, to convert source code into machine
code.
Pseudo-Ops:-
It instructs the assembler to set the register 15 to the address of the, start of the
program. Using is a Pseudo Operands that indicates the assembler which general register is
used as a base register and what its content will be.
Machine-Ops:-
ASSEMBLERS
Function of an assembler:-
DATABASES
8
General Design Procedure:-
To convert an assembly language program into machine language program the following
steps are followed by the designer.
5. Checking the modularity: Modularity is the capability of breaking down the design of
a program into individual components (modules) that can be tested independently.
Following the above steps we can design loaders, assemblers and compilers.
Most assemblers will divide the processing of the program into two passes. The first
pass is only to define the symbols. The second pass can then generate the Instruction and
addresses. An assembler must
Generate instructions.
Evaluate the mnemonic in the field to produce its machine code. Evaluate the sub fields to find
the value of each symbol, process and assign address.
These tasks are grouped into two passes or sequential scans over input codes, associated with
each task one or more assemblers modules.
The purpose of the pass1 is to assign a location to each instruction and data defining
pseudo instruction. Also to define the values for the symbols appearing in the label fields of the
source program.
3. Remember the values of symbol until the pass 2 symbol table is created (STO)
The operation code of the first instruction in the program is read by the Assembler.
The POT is checked, if it is not available it will check for information MOT.
From the matched entry the information about length, binary equivalent and the
type of instruction are determined.
Then the operand field is examined. According to the type of the instruction the
operand may be varied. If it is literal the location may not be known to assembler at
this time, so an entry is made in the literal table for later processing. The label field
of the source program is examined for the presence of the symbol. If there is label,
the symbol is saved in the symbol table along with the current value of the location
counter.
Finally the current value of the location counter is incremented by the length of the
instruction and a copy of source is saved for use by Pass2.
Pass 2:
MACRO PROCESSORS
10
Macros: Concept; Definition
Macro instructions are single line instructions that can execute a block of instructions. In
assembly language, macro is a pre written subroutine that is called within the program. For
every occurrence of the macro instruction, the macro processor will substitute the entire block.
The macro instruction is also called as macro call. Macro processor is a software that creates
and executes macros. This substitutes the macro subroutines for the macro calls.
Many computer manufacturers use macro instructions to automate the writing of
operating systems in a process called systems generation. Macro instructions are usually
considered as an extension of the basic assembler algorithm.
The Pseudo Operands MACRO and MEND are used to define macro in a program.
MACRO identifies the name of the MACRO. It is also called as macro instruction.
Simple Macro
Example Program
A 0,FIVE
A 1,FIVE
A 2,FIVE
-----------------
-----------------
-----------------
A 0,FIVE
A 1,FIVE
A 2,FIVE
FIVE DC F’5’
11
The above statements are the program segment of an assembly language program. We
can understand that the first three lines are repeated twice. With the help of macro instruction
it is possible to group all these instructions in a pack and assign a name to it called as defining
the macro.
Whenever the macro calls exists, the macro processor substitutes the instructions
defined for the particular macro name in the memory.
The MACRO is a pseudo-op, used to define the macro and identify the next line as a
name of the macro. The sequence of instructions follows the macro name is considered as the
abbreviated instructions. The macro definition terminated with the MEND pseudo – op. After
the macro is defined, the macro name is considered as the mnemonic which takes the
operation of replacing the group of instructions defined in the macro. Using macro the above
example can be rewritten as shown below.
The name of the MACRO is ALTER.
12
Source Expanded op-codes by macro processor
MACRO
ALTER
A 0,FIVE
A 1,FIVE
A 2,FIVE
MEND
………..
………..
………… A 0,FIVE
ALTER
A 1,FIVE
………
………. A 2,FIVE
………
A 0,FIVE
ALTER
……… A 1,FIVE
……….
A 2,FIVE
……….
FIVE DC F’5’ FIVE DC F’5’
In the above example ALTER is used as a macro call, it is treated as the operation mnemonic. It
replaces the macro defined instructions instead of the macro call. This process is called as
expanding.
13
Source Expanded op-codes by macro processor
MACRO
ALTER &VALU
A 0, &VALU
A 1, &VALU
A 2, &VALU
MEND
………..
………..
…………
A 0,FIVE
ALTER FIVE
……… A 1,FIVE
……….
A 2,FIVE
………
ALTER TEN A 0, TEN
………
A 1, TEN
……….
………. A 2, TEN
FIVE DC F’5’
FIVE DC F’5’
TEN DC F’10’
TEN DC F’10’
In the above example, only one argument is passed to the macro. &VALU is called as
dummy argument. During the macro call ALTER FIVE will pass the value 5 for the macro. The
macro processor substitutes the value FIVE for the first call. Similarly for second macro call
ALTER TEN, the macro processor substitutes the dummy argument with TEN. It is also possible
to pass more than one parameter to the macro.
14
Example:
MACRO
ALTER &VAL1,&VAL2,&VAL3,&SAN
&SAN A 0, &VAL1
A 1, &VAL2
A 2, &VAL3
MEND
………..
………..
………… A 0,FIVE
ALTER FIVE,TEN,SIX,LOOP1
LOOP1 A 1,TEN
………. A 2,SIX
………
ALTER FIVE,SIX,TEN,LOOP2 A 0, FIVE
LOOP2 A 1, SIX
……….
………. A 2, TEN
FIVE DC F’5’ FIVE DC F’5’
TEN DC F’10’
SIX DC F’6’ TEN DC F’10’
SIX DC F’6’
The above program uses &VAL1, &VAL2, &VAL3 as dummy arguments. The dummy
arguments are replaced by the original values of FIVE, TEN and SIX during the macro call as
ALTER FIVE,TEN, SIX. &SAN is the label argument. The label argument is to identify the dummy
arguments order as in the macro call.
15
The macro calls are specified in two ways, first is called as positioned argument and the
second is keyword argument. In the positioned argument type, the dummy arguments are
replaced by the original arguments as in the order followed in the macro call.
Example, ALTER &VAL!, &VAL2, &VAL3 is in the macro definition and ALTER FIVE, TEN, SIX in the
macro call. The dummy valuen&VAL1 is replaced by FIVE, &VAL2 is by TEN and &VAL3 is
replaced by SIX as in the order of calling.
In the keyword arguments the dummy arguments are referred by the name as well as
by position. Example, ALTER &VAL1=FIVE, &VAL2=SIX, &VAL3=TEN. This can be used to avoid
writing the label field in the macro definition and macro call.
CONDITIONAL MACRO
It is possible to call the macro as per the condition. If the condition is satisfied the macro
will be called otherwise not. The macro processor pseudo-ops AIF and AGO provides the facility
for conditional macros.
Example: LOOP1 A 0, FIVE
A 1, SIX
A 2, TEN
LOOP2 A 0, TEN
A 1, SIX
FIVE DC F’5’
TEN DC F’10
SIX DC F’6’
Using conditional macro procedure we can write this as follows.
16
MACRO
&SAN CON1 &CHK, &VAL1,&VAL2,&VAL3
&SAN A 0, &VAL1
AIF (&CHK EQ 1) .CLOS
A 1, &VAL2
AIF (&CHK EQ 2) .CLOS
A 2, &VAL3
.CLOS MEND
………..
……….. LOOP1 A 0,FIVE
LOOP1 CON1 3,FIVE,SIX,TEN
………. A 1, SIX
………. A 2, TEN
LOOP2 CON1 2, TEN, SIX
……….. LOOP2 A 0, TEN
……….. A 1, SIX
FIVE DC F’5’
TEN DC F’10’ FIVE DC F’5’
SIX DC F’6’ TEN DC F’10’
SIX DC F’6’
In the above program the label starts with (.) is used in macro definition indicates name
of the macro label (.CLOS). The statement AIF (&CHK EQ 1) .CLOS directs the control to check
for the value of CHK passed with macro call. If the macro call is CON1 1,TEN , the value of CHK
is 1 the first instruction A 0, &VAL1 is encountered as A 0, TEN. Here the condition AIF (&CHK
EQ 1) is satisfied, so the control jumped to .CLOS. Similarly for the macro call CON1 2, TEN, SIX,
the value of CHK is 3, so the instruction A 0, TEN and A 1, SIX are encountered.
NESTED MACROS:
Sometimes it is needed to use a macro in another macro and it is called as nested macro
or nesting of macros.
MACRO
17
CAL1 &VAL1
A 2, &VAL1
A 2, F’2’
MEND
MACRO
ALTER &VAL1, &VAL2
CAL1 &VAL1
CAL1 &VAL2
MEND
In this above example there two macros CAL1 and ALTER are used. The macro definition for
ALTER includes the macro CAL1. This macro is called as nested macro. This can be explained as,
MACRO
CAL1 &VAL1
A 2, &VAL1
A 2, F’2’
MEND
MACRO
ALTER &VAL1, &VAL2
CAL1 &VAL1
CAL1 &VAL2
MEND
………..
……….. ALTER
ALTER FIVE,TEN CAL1 FIVE
……….
……… CAL2 TEN
A 2,FIVE
FIVE DC F’5’ A 2,F’2’
TEN DC F’10’ A 2,TEN
SIX DC F’6’ A 2,F’2’
The macro call ALTER invokes the macro CAL1 with the arguments FIVE and TEN. First
the macro CAL1 passes with FIVE and then passed with argument TEN. The register 2 is loaded
with the value 5 and added wit 2 and then again for second call it adds the content of register 2
with the value 10 and incremented by 19 by using this macro.
18
MACROPROCESSOR:
Macro processor is a software that creates and executes macros. It identifies the macro
calling and substitutes the abbreviated instructions defined in the relevant macro.
PASS 1 DATABASES
1. The input macro source desk
2. The output macro source desk copy for use by pass2
3. The Macro Definition Table (MDT), used to store the body of the macro definitions.
4. The Macro Name Table (MNT), used to store the names of defined macros.
5. The Macro Definition Table Counter (MDTC), use to indicate the next available
entry in the MDT.
6. The Macro Name Table Counter (MDTC), use to indicate the next available entry in
the MNT.
7. The Argument List Array (ALA), used to substitute index markers for dummy
arguments before storing a macro definition.
PASS 2 DATABASES
1. The copy of the input macro source desk.
2. The output expanded source deck to be used to the assembler.
3. The Macro Definition Table (MDT) created by pass1.
19
4. The Macro Name Table (MNT) created by pass1.
5. Definition Table Pointer (MDTP), used to indicate the next line of text to be used
during macro expansion.
6. The Argument List Array (ALA), used to substitute macro call arguments for the
index markers in the stored macro definition.
SPECIFICATION OF DATABASE FORMAT
The only databases with non retrieval format are the Macro Definition Table (MDT),
the Macro Name Table (MNT) and the Argument List Array (ALA).
During Pass2, it is necessary to substitute macro call arguments for the index markers stored in
the macro definition.
20
3 “DATA3bbb”
The list would be used only during the expansion of this particular call.
LOADER
The assembler translates the assembly language program into machine language
program and save it in a object file. To execute it, during the time of execution, the program
has to be brought from the disk and loaded in the available memory area. This is done by a
system software called Loader.
Because of this loading process the address of the program instruction may be changed.
For example, the loaded location starts with the address 2000, the starting address of the
program may be changed to 2000 instead of starting from 0. Likewise every instruction’s
address also altered according to the loaded location. This process is known as relocation. This
is also done by loaders.
Loaded
Program
DATA BASES
Main Memory
LOADER SCHEMES
To perform the four functions of loader, various loading schemes are used. They are,
(1) Compile and Go loader Scheme (2) General Loader Scheme (3) Absolute Loaders.
Loaded
Program
Compile& Go Assembler
SOURCE PROGRAM Translator
DATA BASES
Main Memory
The instructions are assembled directly by assigning the available memory addresses where the
program will be stored. The disadvantage of this scheme is that the assembler occupies
additional memory.
In this scheme instead of an assembler, another software called loader is used. The
memory occupied by the loader is smaller than the assembler. The loader transfers the object
files in machine code (data and other information available in object form) from the disk to the
main memory in an executable form. In this scheme, reassembly is not necessary since the
loader the core memory addresses for the instructions in the object file. The loader is able to
allocate compatible memory addresses to the various object programs in the form of
22
subroutines. It makes the facility of using various modules available in different languages,
SOURCE PROGRAM2 ASSEMBLER OBJECT2
because the source program in any language is compiled or assembled to the machine codes.
This is called as linking.
Main memory
ABSOLUTE LOADERS
It is the simplest loader scheme. In this scheme, the assembler output of the program is
in the machine code form as in the compile and go scheme. But the data is placed in the
separate file form. The loader accepts the object file and places them directly in the memory
location prescribed by the assembler. In this scheme the additional memory occupied by the
assembler is avoided.
MAIN PROGRAM
Loaded
Program
ABSOLUTE
TRANSLATOR
SIMP (subroutine)
Main Memory
23