Chapter 3 FM
Chapter 3 FM
• Operating system
• Firmware,
• Programming tools such as compilers, assemblers,
• I/O routines
• Interpreters
• Scheduler
• Loaders
• Linkers
• Runtime libraries of the computer programming languages.
Component of
System Software
Project analysis slide 2
If we think of the computer system as a layered model, the system software is the interface between the hardware and user
applications
Components are :
• Text editors
• Loaders
• Assemblers
• Macro processors
• Compilers
• Debuggers
• Machine Structure
• Machine language and Assembly Language.
Component of
System Software
Project analysis slide 2
i. Text Editor :
A text editor is a type of program used for editing plain text files. Such programs are sometimes known as "notepad"
software, following the Microsoft Notepad.
ii. Loaders :
• A loader is the part of an operating system that is responsible for loading programs and libraries.
• It is one of the essential stages in the process of starting a program, as it places programs into memory and prepares
them for execution.
• Loading a program involves reading the contents of the executable file containing the program instructions into
memory, and then
• carrying out other required preparatory tasks to prepare the executable for running.
• Once loading is complete, the operating system starts the program by passing control to the loaded program code.
Component of
System Software
Project analysis slide 2
iii. Linkers :
Linker is a program that takes one or more objects generated by a compiler and combines them into a
single executable program.
iv. Assembler :
Assembler is a computer program which is used to translate program written in Assembly Language in to
machine language.
The translated program is called as object program.
Assembler checks each instruction for its correctness and generates diagnostic messages, if there are mistakes
in the program.
• A macro processor is a program that copies a stream of text from one place to another, making a systematic set of
replacements as it does so.
• Macro processors are often embedded in other programs, such as assemblers and compilers.
• Sometimes they are standalone programs that can be used to process any kind of text.
Debugger :
• A debugger is a computer program used by programmers to test and debug a target program.
• Debuggers may use instruction-set simulators, rather than running a program directly on the processor to achieve a
1. Instruction interpreter
2. Location counter
3. Instruction register
4. Working register
5. General register
Component of
System Software
Project analysis slide 2
Machine structure
• The Instruction Interpreter Hardware is basically a group of circuits that perform the operation specified by the
instructions fetched from the memory.
• The Location Counter can also be called as Program/Instruction Counter simply points to the current instruction being
executed.
• The working registers are often called as the "scratch pads" because they are used to store temporary values while
calculation is in progress.
Specification Gap
• It is the gap between the application domain and the programming
language domain.
• This gap describes the gap between two different specifications describing
the same task.
• However, the semantic gap has to be bridged by the software designer.
Execution Gap
• It is a gap between the programming language domain and the execution
domain.
• This gap is between the two programs written in different programming
languages.
• Where one of the programs is in the languages closer to machine language.
• The language processor, such as a compiler or interpreter, bridges the
execution gap.
What is a
Semantic Gap?
Project analysis slide 2
Different types of domains between which these gaps exist.
•Application Domain – The specification language here is just a language convenient to the user.
•Programming Language Domain – The specification language here is any programming language.
Application PL Execution
Domain Domain Domain
11/06/2023 14
Procedure Oriented Language
PL Execution
Application
Domain Domain
Domain
11/06/2023 15
Language Processor
1.Translation Bridge: Language processors act as a bridge between human-readable programming languages and
machine-executable code, enabling effective communication between programmers and computers.
2.Error Identification: They are equipped with error-checking mechanisms that identify and report errors in the
source code, helping programmers correct their mistakes and produce reliable software.
3.Multiple Types: Language processors come in various types, including compilers, interpreters, and assemblers,
each with a specific role in converting high-level code into machine code or a close variant.
4.Semantic Gap Reduction: They reduce the semantic gap between user intent (expressed in high-level languages)
and computer execution (in machine language), ensuring that the computer correctly interprets the programmer's
instructions.
5.Fundamental Phases: Language processors typically involve two fundamental phases: analysis, where source
code is examined for validity, and synthesis, where valid source code is transformed into target language code
while preserving meaning.
Levels of Languages
Project analysis
Machine language example: slide 2
Below is an example of machine language (binary) for the text "Hello World".
01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010
01101100 01100100
Below is another example of machine language (non-binary), which will print the letter "A" 1000 times to the computer
screen.
169 1 160 0 153 0 128 153 0 129 153 130 153 0 131 200 208 241 96
Assembly Language
Project analysis
• Each personal slide 2that manages the computer's arithmetical, logical, and control activities.
computer has a microprocessor
• Each family of processors has its own set of instructions for handling various operations such as getting input from
keyboard, displaying information on screen and performing various other jobs.
• These set of instructions are called 'machine language instructions'.
• A processor understands only machine language instructions, which are strings of 1's and 0’s.
• However, machine language is too obscure and complex for using in software development.
• So, the low-level assembly language is designed for a specific family of processors that represents various instructions
in symbolic code and a more understandable form.
• It is most suitable for writing interrupt service routines and other memory resident programs.
Language Translators
A Language Translator is the program which converts a users program written in some language to
another language.
• The language in which the users program is written is called the source language.
• The language to which the source language is converted is called the target language.
Language
Translators
Project
Assembler :analysis slide 2
Language
Translators
An assembler is a program that takes basic computer
instructions and converts them into a pattern of bits that
Assembler Compiler Interpreter
the computer's processor can use to perform its basic
operations
Characteristics of Assembler :
Project
Compiler : analysis slide 2
Language
Translators
Target
Source Code
Compiler Program/Object/Exe
(HLL)
Cpde
HLL Features :
Project
Interpreter analysis
: slide 2 Language
Translators
Interpreter Features :
Error correction is quite easy for the interpreter as the interpreter provides a line-by-
line error.
Source programs are compiled before time and stored as machine-independent code,
which is then linked at run-time and executed by an interpreter.
Assemblers
1. Performance issues
For some applications, speed and size of the code are critical.
An expert assembly language programmer can often produce code that is much smaller and much faster
than a high level programmer can.
Example – embedded applications such as the code on a smart card, the code in a cellular telephone,
BIOS routines, inner loops of performance critical applications etc.
2. Access to the machine
Some procedures need complete access to the hardware, something which is impossible in high level
languages.
Example – Low levels interrupts and traps handlers in an operating system etc.
* The trap is a signal raised by a user program instructing the operating system to perform some functionality immediately. In contrast, the interrupt is a signal to the CPU
emitted by hardware that indicates an event that requires immediate attention.
Assemblers
Linker :
A large program can be splitted up into many modules. All these modules have to be connected logically
and linked to form a single program.
Assemblers
Mnemonic operation code / Mnemonic Opcodes for machine instruction eliminates the need to
memorize numeric operation codes. It enables assembler to provide helpful error diagnostics. Such as
indication of misspelt operation codes.
2. Symbolic Operands :
Symbolic names can be associated with data or instructions. These symbolic names can be used
as operands in assembly statements. The assembler performs memory binding to these names; the
programmer need not know any details of the memory bindings performed by the assembler.
3. Data declarations :
Data can be declared in a variety of notations, including the decimal notation. This avoids manual conversion
of constants into their internal machine representation.
Assemblers
1.LXI H, 2501H : "Get address of first number in H-L pair. Now H-L points to 2501H"
2.MOV A, M : "Get first operand in accumulator"
3.INX H : "Increment content of H-L pair. Now, H-L points 2502H"
4.ADD M : "Add first and second operand"
5.INX H : "H-L points 4002H"
6.MOV M, A : "Store result at 2503H"
7.HLT : "Stop"
Assemblers
1.LXI H, 2501H : "Get address of first number in H-L pair. Now H-L points to 2501H"
2.MOV A, M : "Get first operand in accumulator"
3.INX H : "Increment content of H-L pair. Now, H-L points 2502H"
4.SUB M : "Subtract first to second operand"
5.INX H : "H-L points 4002H"
6.MOV M, A : "Store result at 2503H"
7.HLT : "Stop"
Assemblers
Project analysis
Mnemonic Operation Codes :
slide 2
Instruction Format :
Assemblers
Project analysis
An Assembly slide
and equivalent machine 2 program :
language
Assemblers
Project analysis
An Assembly slide
and equivalent machine 2 program :
language
Assemblers
Project
Assemblyanalysis slide
Language Statements : 2 Assembly
language
Statements
a) Imperative Statements : It indicates an action to be performed during the execution of the assembled
program. Each imperative statement typically translates into one machine instruction.
Eg. MOV, ADD, MULT
Assemblers
Project
Assemblyanalysis slide
Language Statements : 2 Assembly
language
Statements
[Lable] DS <Constant>
[Label] DC <Value>
The DS (Declare Storage) statement reserves areas of memory and associates names with them.
E.g. A DS 1
B DS 150
First statement reserves a memory of 1 word and associates the name of the memory as A.
Second statement reserves a memory of 150 word and associates the name of the memory as B.
Assemblers
Project
Assemblyanalysis slide
Language Statements : 2 Assembly
language
Statements
[Lable] DS <Constant>
[Label] DC <Value>
The DC (Declare Constant) Statement constructs memory word containing constants
e.g. ONE DC ‘1’
Associates the name ONE with a memory word containing the value ‘1’ . The
programmer can declare constants in decimal, binary, hexadecimal forms etc., These
values are not protected by the assembler. In the above assembly language program the
value of ONE Can be changed by executing an instruction
MOVEM BREG,ONE
Assemblers
Project
Assemblyanalysis slide
Language Statements : 2 Assembly
language
Statements
c) Assembler Directives: Assembler directives instruct the assembler to perform certain actions during
the assembly of a program. Some Assembler directives are described in the following
START <Constant>
Indicates that the first word of the target program generated by the assembler
should be placed in the memory word with address <Constant>
END [ <operand spec>]
It Indicates the end of the source program
Assemblers
Project
Assemblyanalysis slide
Language Statements : 2 Assembly
language
Statements
c) Assembler Directives: Assembler directives instruct the assembler to perform certain actions during
the assembly of a program. Some Assembler directives are described in the following
START <Constant>
Indicates that the first word of the target program generated by the assembler
should be placed in the memory word with address <Constant>
END [ <operand spec>]
It Indicates the end of the source program
Machine Dependent and Machine
Independent features of Assembler
• M/C Dependent Features
• A] Instruction format & addr. mode:-
• B] Program Relocation
• Machine Independent Assembler Features
• 1) Literals
• 2) Symbol defining statements
• 3) Expressions
Immediate Addressing Mode:
MVI B 45 (move the data 45H immediately to register B)
LXI H 3050 (load the H-L pair with the operand 3050H immediately)
11/06/2023 43
Assembly Lang to M/C lang Program
1. Find address of variables and labels.
2. Replace Symbolic addr by numeric addr.
3. Replace Symbolic opcodes by machine opcode.
4. Reserve storage for data.
Opcode Register Memory
START 101 LC
READ X 101 operand
+ 09 0 108
READ Y 102 + 09 0 109
MOVER AREG, X 103 + 04 1 108
ADD AREG, Y 104 + 01 1 109
MOVEM AREG, RESULT 105 + 05 0 110
PRINT RESULT 106 + 10 0 110
STOP 107 + 00 0 000
X DS 1 108
Y DS 1 109
RESULT DS 1 110
END
Variable Address
Opcode Register Memory
X 108
START 101 LC
READ X 101 operand
+ 09 0 108 Y 109
READ Y 102 + 09 0 109
MOVER AREG, X 103 + 04 1 108 RESULT 110
ADD AREG, Y 104 + 01 1 109
MOVEM AREG, RESULT 105 + 05 0 110
PRINT RESULT 106 + 10 0 110
STOP 107 Figure: After LC Processing
+ 00 0 000
X DS 1 108
Y DS 1 109
RESULT DS 1 110
END
Required M/C Code
LC Opcode Register Address
101 09 0 108
102 09 0 109
START 101 LC Opcode Register
READ X 101 + 09 0 108 103 04 1 108
READ Y 102 + 09 0 109 104 01 1 109
MOVER AREG, X 103 + 04 1 108
ADD AREG, Y 104 105 05 0 110
+ 01 1 109
MOVEM AREG, RESULT 105 + 05 0 110 106 10 0 110
PRINT RESULT 106 + 10 0 110 107 00 0 000
STOP 107 + 00 0 000
X DS 1 108 Memory
108
operand
Y DS 1 109 109
RESULT DS 1 110 110
END
111
Analysis Phase
• Primary function of the Analysis phase is to build the symbol
table.
• It must determine the addresses with which the symbolic names
used in a program are associated
• It is possible to determine some addresses directly like the address
of first instruction in the program (ie.,start)
• Other addresses must be inferred
• To determine the addresses of the symbolic names we need to fix
the addresses of all program elements preceding it through
Memory Allocation.
• To implement memory allocation a data structure called
location counter is introduced.
11/06/2023 48
Synthesis Phase: Example
Consider the following statement:
MOVER BREG, ONE
The following info is needed to synthesize machine instruction
for this stmt:
1. Address of the memory word with which name ONE is
associated [depends on the source program, hence made
available by the Analysis phase].
11/06/2023 50
Example
START 100
MOVER BREG, N LC = 100 (1 byte)
MULT BREG, N LC = 101 (1 byte)
STOP LC = 102 (1 byte)
N DS 5 LC = 103
Symbol Address
N 103
11/06/2023 51
• Since there the instructions take different amount of
memory, it is also stored in the mnemonic table in
the “length” field
11/06/2023 52
Data structures of an assembler
During analysis and
Synthesis phases Mnemonic Opcode length
ADD 01 1
SUB 02 1
Mnemonic Table
Symbol Address
Data Access
N 104 -- > Control
Access
Symbol Table
11/06/2023 53
A simple Assembly Scheme
Design Specification of an assembler
There are four steps involved to design the specification of an
assembler:
• Identify information necessary to perform a task.
• Design a suitable data structure to record info.
• Determine processing necessary to obtain and maintain the
info.
• Determine processing necessary to perform the task
11/06/2023 54
Tasks Performed : Analysis Phase
• Isolate the labels, mnemonic, opcode and operand fields of a statement.
11/06/2023 55
Tasks Performed : Synthesis Phase
11/06/2023 56
Forward Reference
• It is a reference to the entity which precedes its
definition in the program.
percent_profit := (profit * 100) / cost_price;
……..
……..
long profit;
11/06/2023 57
Difficulties: Forward Reference
• Forward reference: reference to a label that is defined later in the
program.
11/06/2023 58
Single Pass Translation
• The problem of forward reference can be handled using a
technique called as back patching.
START 100
MOVER AREG, X
L1 ADD BREG, ONE
ADD CREG, TEN
STOP
X DC ‘5’
ONE DC ‘1’
DC ‘10’
TEN END
START 100
MOVER AREG, X 100 04 1 ___
L1 ADD BREG, ONE 101 01 2 ___
ADD CREG, TEN 102 06 3 ___
STOP 103 00 0 000
X DC ‘5’ 104
ONE DC ‘1’ 105
TEN DC ‘10’ 106
END
100 1 104
101 2 105
102 3 106
00 0 000
Backpatching
• The problem of forward references is handled using a
process called backpatching.
• Initially, the operand field of an instruction containing a forward
reference is left blank
• Ex: MOVER BREG, ONE can be only partially synthesized since
ONE is a forward reference
• The instruction opcode and address of BREG will be assembled
to reside in location 101
• To insert the second operand’s address later, an entry is added
as Table of Incomplete Instructions (TII)
• The entry TII is a pair (<instruction address>, <symbol>) which
is (101, ONE) here
11/06/2023 63
Backpatching
• When END statement is processed, the symbol table would
contain the addresses of all symbols defined in the source
program
• So TII would contain information of all forward references
• Now each entry in TII is processed to complete the instruction
• Ex: the entry (101, ONE) would be processed by obtaining the
address of ONE from symbol table and inserting it in the
operand field of the instruction with assembled address 101.
• Alternatively, when definition of some symbol L is encountered,
all forward references to L can be processed
11/06/2023 64
Two Pass Translation
• Handles forward references easily.
• Requires 2 scans of the source program.
• LC processing is performed in the 1st pass and symbols are
stored in the symbol table.
• Second pass synthesis Target Program.
Two Pass Assembler
• Read from input line
• LABEL, OPCODE, OPERAND
Source
program
Intermediate Object
Pass 1 Pass 2
file codes
11/06/2023 66
General Design Procedure of Two Pass
Assembler
1. Specify the problem
2. Specify data structures
3. Define format of data structures
4. Specify algorithm
5. Look for modularity [capability of one program to be subdivided
into independent programming units.]
6. Repeat 1 through 5 on modules.
Pass structure of assembler
Data Structures
Source Target
Program Pass I Pass II Program
Intermediate Code
=‘2’ -----
BC LT, BACK 209
START 200 LC
MOVER AREG, =‘5’ 200 Symbol Address Literal Address Pool Table
MOVEM AREG, X 201
L1 MOVER BREG, =‘2’ 202 X ---- =‘5’ 205 0
ORIGIN L1+3
L1 202 =‘2’ 206 2
LTORG 205
206 NEXT 207 =‘1’ ----
NEXT ADD AREG,=‘1’ 207
SUB BREG,=‘2’ 208 BACK ---- =‘2’ ----
BC LT, BACK 209
LTORG 210 LTOR 210
211 G 211
BACK EQU L1 212
Symbol Address Literal Address Pool Table
ORIGIN NEXT+5
MULT CREG,=‘4’ 212 X ---- =‘5’ 205 0
STOP 213
X DS 1 214 L1 202 =‘2’ 206 2
END
NEXT 207 =‘1’ 210 4
=‘2’ 211
BACK EQU L1 212
=‘4’ ----
X DS 1 214
Symbol Address Literal Address
Pool Table
START 200 LC X 214 =‘5’ 205
MOVER AREG, =‘5’ 200 0
MOVEM AREG, X 201 L1 202 =‘2’ 206
L1 MOVER BREG, =‘2’ 202
2
NEXT 207 =‘1’ 210
ORIGIN L1+3 4
LTORG 205 BACK 202 =‘2’ 211
206
NEXT ADD AREG,=‘1’ 207 =‘4’ ----
SUB BREG,=‘2’ 208
BC LT, BACK 209 END
LTORG 210
Literal Address
211 Symbol Address Pool Table
BACK EQU L1 212 =‘5’ 205
ORIGIN NEXT+5 X 214 0
MULT CREG,=‘4’ 212 =‘2’ 206
L1 202 2
STOP 213
=‘1’ 210
X DS 1 214 4
NEXT 207
END =‘2’ 211
BACK 202 5
=‘4’ 215
Specify the problem
Pass1: Define symbols & literals.
1) Determine length of m/c instruction [MOTGET1]
2) Keep track of Location Counter [LC]
3) Remember values of symbols [STSTO]
4) Process some pseudo ops[EQU,DS etc] [POTGET1]
5) Remember Literals [LITSTO]
Pass2: Generate object program
1) Look up value of symbols [STGET]
2) Generate instruction [MOTGET2]
3) Generate data (for DS, DC & literals)
4) Process pseudo ops [POTGET2]
Step 2. Data structure:-
Pass1: Databases
• Input source program
• “LC” location counter used to keep track of each
instructions addr.
• M/c operation table (MOT) [Symbolic mnemonic &
length]
• Pseudo operation table [POT], [Symbolic mnemonic
& action]
• Symbol Table (ST) to store each lable & it’s value.
• Literal Table (LT), to store each literal (variable) & it’s
location.
• Copy of input to used later by PASS-2.
Step 2. Data structure:-
• Pass2: Databases
• Copy of source program input to Pass1.
• Location Counter (LC)
• MOT [Mnemonic, length, binary m/c op code, etc.]
• POT [Mnemonic & action to be taken in Pass2
• ST [prepared by Pass1, label & value]
• Base Table [or register table] indicates which registers are currently
specified using ‘USING’ pseudo op & what are contents.
• Literal table prepared by Pass1. [Lit name & value].