0% found this document useful (0 votes)
86 views

System Programming Unit 1-2

The document discusses system programming and operating systems. It describes how [1] operating systems manage computer resources and allow users to interact with hardware through high-level languages rather than machine code. It then [2] explains the basic structure of a CPU, including components like the instruction interpreter, registers, and memory. Finally, it [3] discusses different types of computer languages from machine code to assembly to high-level languages, and how language translators like compilers, assemblers, and interpreters are used to translate between these levels.

Uploaded by

mojbar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

System Programming Unit 1-2

The document discusses system programming and operating systems. It describes how [1] operating systems manage computer resources and allow users to interact with hardware through high-level languages rather than machine code. It then [2] explains the basic structure of a CPU, including components like the instruction interpreter, registers, and memory. Finally, it [3] discusses different types of computer languages from machine code to assembly to high-level languages, and how language translators like compilers, assemblers, and interpreters are used to translate between these levels.

Uploaded by

mojbar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

SYSTEM PROGRAMMING

Introduction:

Operating system is a set of software, which provides the

 File handling function like edit, copy, save etc.,


 Manages and controls the resources like memory, processors, I/O devices etc.

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:

The machine structure of the mainframe IBM360/370 is given in the figure.

The CPU of the IBM 360 consists of the following parts.

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

Instruction Interpreter is a hardware made up of an electronic circuit. It fetch the


information stored in the memory.

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:

Real Address =Base register + Index register + Offset

(Offset is the content of the location counter)

2
Real Address = 00900+06000+00030 = 06930

MAR (Memory Address Register) and MBR (Memory Buffer Register)

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

A set of programs written for a task is known as 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.

The most commonly known types of system software used

1. Operating system.

2. Programming language translators.

3. Communications software.

4. Utility programs.

(i) Operating system.

Operating system is a system software consisting of a set of programs used to control


and manage the operation entire hardware.

(ii) Programming language translators.

Translator includes compiler, Assembler and Interpreter.

The main functions are to translate the source program into object program.

(iii) Communications software.

Communication software enables transfer of data and programs from one computer to
another.

(iv) Utility programs.

Utility programs are a set of programs which help users in system maintenance tasks.

Programming language translators and its functions.

(a) compiler (b) Assembler (c) Interpreter

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.

Less execution time Larger execution time

Requires more memory space Requires less memory space.

Explain language processors

Compiler :-

Compiler is a program which translates high-level-language into an equivalent low-level


language program.

Source program COMPILER Object Program

(high level language) ( low level language)

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.

Explain computer languages.

Computer languages can be broadly classified into

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.

The demerits of machine language program

- Program writing is difficult


- Difficult to understand or debug a program
- Programs are long.

2. Assembly language:-

A program written in mnemonics is known as assembly language program.

Examples:-

READ A - it reads the value of A

ADD B - The value of B is added with B.'

The disadvantages of using assembly language:-

- programming is difficult
- Not portable
- Time consuming
- Program is longer and it needs translation.

3. High Level Language:-


Languages resembling in English and Mathematics are known as high level languages.

- These languages are portable


- Program written in one computer can generally run on another computer
Machine independent

CPU processor and its operations:

A microprocessor is a digital device working with binary numbers 0 and 1. It contains,

(i) ALU ( arithmetic Logic Unit)


(ii) Control Unit
(iii) Memory ( a small amount)

6
Functions

(i) Fetches instruction from memory


(ii) Decodes the instruction
(iii) Reads the required operands (data/address) from memory or input devices
(iv) Executes the instruction (performs arithmetic and logic or data transfer
operations as per the instruction)
(v) Stores the results in storage unit or sends the result to output devices.
(vi) Controls all the devices connected to the microprocessor.

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.

E.g. to write 0001 1010, we can write 1A to add Register.

2. Address are symbolic not absolute.

3. Very easy to read.

4. The data can be introduced very easily in the program.

But to use the assembly language we need assembler, to convert source code into machine
code.

MACHINE- OPS AND PSEUDO- OPS

Pseudo-Ops:-

A Pseudo-ops is an assembly language instruction that specifies an operation to the


assembler. It is an intermediate code generated from source code, but not yet executable. It
has to be interpreted or compiled into machine codes for execution.
7
E.g., USING BEGIN +2, 15

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.

DS Define Storage instruction

E.g., DATA DS 2000F This statement is used to store 2000.

DC Define Constant instruction

Machine-Ops:-

A machine operands is an instruction which informs the machine operation to the


assembler.

E.g., L for LOAD, A for ADD.

ASSEMBLERS

An assembler is a program that converts an assembly language program into machine


language codes. The assembler also provides the other information for the loader to use.

Function of an assembler:-

Assembly language program ASSEMBLER Machine Language

DATABASES

8
General Design Procedure:-

To convert an assembly language program into machine language program the following
steps are followed by the designer.

1. First specify the problem

2. Specifying the data structure

3. Defining the format of the data structure

4. Designing the algorithm

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.

6. Repeat the above five steps for all modules.

Following the above steps we can design loaders, assemblers and compilers.

PASS 1 AND PASS 2 ASSEMBLER WITH FLOWCHART

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.

 Process pseudo operations.

These tasks are grouped into two passes or sequential scans over input codes, associated with
each task one or more assemblers modules.

Pass1: (Purpose is to define symbols and literals)

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.

1. Determine the length of machine instruction (MOTGET1)


9
2. Keep track of location counter (LC)

3. Remember the values of symbol until the pass 2 symbol table is created (STO)

4. Process some pseudo-ops. Eg, EQU, DS (POTGET 1)

5. Remember literals- Literal table is created

Algorithm for Pass1:

 The location counter is set to the first location in the program.

 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:

Purpose is to generate object program

1. Look up values of symbols (STGET)


2. Generate instructions (MOTGE 2)
3. Generate data (For DS, DC and literals)
4. Process pseudo ops (POTGET 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.

Macro Instructions and Macro Call

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.

Defining the MACRO:

MACRO - Start of the Macro


[ ] - Macro name
______
______ - Body of the Macro contains the repeated sequence of instructions
______
______
MEND - End of Definition

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.

MACRO CALL WITH ARGUMENT


The macro provides another facility to handle with the argument. In the above example
program, the values of the registers are always incremented with the value of FIVE. This value
can be changed using arguments or parameters.
Arguments are the values passed to the macros to implement the various values of
literals in the program as required. These arguments must be supplied with the macro call.
The above example can be rewritten using arguments as follows.

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:

Source Expanded op-codes by macro processor

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.

Source Expanded op-codes by macro processor

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.

The AGO is another pseudo-op used in conditional macro. It is used to create


unconditional branching.

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,

Source Expanded op-codes by macro processor

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.

The tasks of the Macro Processor are,


1. Recognize macro definitions: It must recognize the macro
2. Save the definitions.
3. Recognize the calls
4. Expand the calls and substitute the arguments.

A Two Pass Algorithm (flow chart not included)


The macro processor scans and process the lines of a program. It’s algorithm will make
two syntactic passes.
The first pass examines every operation code and saves all macro definition in a macro
definition table and a copy of the input program without macro definition in a object file for the
use of second pass.
The second pass will then examines the every operation mnemonic and replaces the
macro call with macro definitions.

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

ARGUMENT LIST ARRAY


The Argument List Array (ALA) is used during both Pass1 and Pass2. During Pass1, the
dummy arguments in the macro definition are replaced with positional indicators. The i th
dummy argument on the macro name instruction is represented in the body of the macro. It is
represented by the index marker symbol #, where # is the symbol reserved for the use of the
macro processor. ( ie., not available to the programmers)
Example:
Macro Definition Table MDT
………………………….
…………………………….
&LAB INCR &ARG1, &ARG2, &ARG3
#0 A 1, #1
A 2, #2
A 3, #3
MEND

During Pass2, it is necessary to substitute macro call arguments for the index markers stored in
the macro definition.

LOOP INCR DATA1, DATA2, DATA3

The macro call expander would prepare an argument list array.

Argument List Array Index 8 Bytes entry argument


0 “LOOP1bbb”
1 “DATA1bbb”
2 “DATA2bbb”

20
3 “DATA3bbb”
The list would be used only during the expansion of this particular call.

MACRO DEFINITION TABLE


The Macro Definition Table (MDT) is a table of text lines. If input line is in 80 characters
long, the MDT can be a table with 80 bytes strings as entries. Every line of each macro
definition, except the MACRO line, is stored in the MDT. The MEND is stored in the table to
indicate the end of definition.

MACRO NAME TABLE (MNT)


The macro name table serves a function very similar to that of the assembler’s machine-
op table(MOT) and Pseudo-op table (POT). Each MNT entry consists of a character string and a
pointer to the entry in the MDT that corresponds to the beginning of the macro definition.

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.

The loader performs four functions.


1. Allocating memory for the assembled program.
2. With the help of databases, perform the symbolic reference-linking between the
object files of different modules.
3. Performs the relocation for all address dependent instructions.
4. Transfer the machine code and data required from the secondary memory to main
memory

Loaded
Program

OBJECT PROGRAM LOADER


21

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.

COMPILE AND GO LOADER SCHEME


Compile and go loader scheme is also called as assemble and go. In this scheme the
assembler is also loaded in the memory.

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.

2. GENERAL LOADER SCHEME

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

SOURCE PROGRAM1 ASSEMBLER OBJECT1 Loaded


Loader
Loader
Translator

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

You might also like