0% found this document useful (0 votes)
2 views19 pages

SPCC Notes

An assembler is system software that translates assembly language into machine language, functioning as a translator between human-readable code and hardware. There are three types of assemblers: single pass, two pass, and multi pass, each differing in speed and handling of forward references. A linker combines object programs into a single executable, resolving external references and performing address binding, while system programs manage hardware and provide essential services for application execution.

Uploaded by

patilashwara170
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)
2 views19 pages

SPCC Notes

An assembler is system software that translates assembly language into machine language, functioning as a translator between human-readable code and hardware. There are three types of assemblers: single pass, two pass, and multi pass, each differing in speed and handling of forward references. A linker combines object programs into a single executable, resolving external references and performing address binding, while system programs manage hardware and provide essential services for application execution.

Uploaded by

patilashwara170
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

What is an Assembler?

An Assembler is a system software that converts Assembly Language program into Machine
Language.
• Assembly language → uses mnemonics (ADD, MOV, SUB)
• Machine language → binary (0s and 1s) understood by CPU
• Assembler acts as a translator between human-readable code and hardware reality
In short:
Assembler = Assembly Language ➜ Machine Code

Types of Assembler
Based on number of passes over source code.

1️⃣ Single Pass Assembler


Assembler scans the source code only once.
Working
• Reads line by line
• Generates machine code immediately
Features
• Faster
• Less memory
• Difficult to handle forward references
Limitation
Forward references are hard
(example: using a label before it is defined)
Use Case
• Simple systems
• Limited memory environments

2️⃣ Two Pass Assembler


Assembler scans the program twice.
Pass 1
• Assign addresses
• Build Symbol Table
• Handle labels
Pass 2
• Generate machine code
• Replace symbols with actual addresses
Features
• Easy handling of forward references
• More accurate
• Widely used
Limitation
• Slightly slower than single pass
Use Case
• Most real-world assemblers

3️⃣ Multi Pass Assembler


Assembler scans the program more than two times.
Working
• Each pass performs a specific task
• Used for complex instruction sets
Features
• Highly flexible
• Very accurate
Limitation
• Slow
• More memory required
Use Case
• Complex architectures
• Advanced system software

Comparison Table (🔥 Exam Saver)


Assembler Type Passes Speed Forward Reference
Single Pass 1 Fast Difficult
Two Pass 2 Moderate Easy
Multi Pass >2 Slow Very Easy

Final One-Line Conclusion (Write this 🔥)


An assembler converts assembly language into machine language and can be classified as single
pass, two pass, or multi pass assembler based on the number of scans over the source program.

Define Linker
A Linker is a system software that combines one or more object programs into a single
executable program and resolves external references.
Simple words:
Linker = Object files + Libraries → Executable file

Why Linker is Needed


• Large programs are written in multiple modules
• Each module is compiled separately
• Linker connects them into one runnable program

Functions of a Linker
The main functions of a linker are listed and explained below:
1️⃣ Linking (Combining Object Modules)
• Combines multiple object files into one program
• Example:
o [Link]
o [Link]
o [Link] → becomes single executable
Helps in modular programming

2️⃣ Symbol Resolution


• Resolves external symbols (functions or variables defined in other modules)
• Matches symbol references with their definitions
Example:
extern int total;
Linker finds where total is defined.

3️⃣ Address Binding (Relocation)


• Assigns final memory addresses to instructions and data
• Adjusts addresses when program is loaded into memory
Makes program location-independent

4️⃣ Relocation
• Modifies address references after loading
• Ensures correct memory access
Example:
• If program moves from address 1000 to 3000, linker updates addresses

5️⃣ Library Linking


• Links required library routines
• Two types:
o Static linking → library code copied
o Dynamic linking → linked at runtime
Reduces programmer effort

6️⃣ Error Detection


• Detects unresolved symbols
• Reports multiple definitions
• Stops execution if linking errors exist

7️⃣ Creation of Executable File


• Generates final executable file (.exe, .out)
• Ready to be loaded and executed
One-Line Exam Conclusion
A linker is system software that combines object programs, resolves external symbols, performs
relocation, and generates an executable program.

Define System Program (System Software)


A System Program is a collection of programs that control, manage, and coordinate
computer hardware and provide essential services for the execution of application programs.
Straight exam line:
System programs act as an interface between the hardware and the user/application software.

Examples of System Programs


• Operating System (Windows, Linux, Android)
• Assembler
• Compiler
• Linker
• Loader
• Device Drivers
• File Management System

Difference Between System Software and Application Software


( Extended Table – Examiner-Proof)
No. System Software Application Software
1 Manages hardware resources Performs specific user tasks
2 Controls CPU, memory, I/O devices Uses system resources
3 Runs in background Runs in foreground
4 Essential for system operation Not essential for booting
5 Starts automatically at boot time Started by user
6 Written in low-level languages (C, Assembly) Written in high-level languages
7 Difficult for end users to understand Easy and user-friendly
8 Hardware-oriented User-oriented
9 Provides platform for applications Requires platform to run
10 Highly complex Comparatively simple
11 Generally closer to hardware Far from hardware
12 One-time installation Installed as per user need
13 Errors may crash system Errors affect only the application
14 Examples: OS, Compiler, Driver Examples: Word, Excel, Browser

No system software → Computer dead


No application software → Computer alive, just boring

Macro and Two-Pass Macro Processor (Detailed Explanation)


1. What is a Macro?
A Macro is a user-defined set of assembly language instructions that can be expanded inline
wherever the macro is invoked.
Definition (Write this in exam)
A macro is a sequence of instructions that is defined once and expanded at the time of assembly
whenever it is called.
Key Idea
• Macro is expanded during assembly time
• No function call or jump
• Results in faster execution

2. Need / Advantages of Macro


• Avoids repetitive code
• Reduces programming effort
• Improves readability
• No runtime overhead
• Easy modification (change once, affects everywhere)
Limitation:
• Increases program size due to expansion

3. Macro Example
Macro Definition
INCR &X
LOAD AREG, &X
ADD AREG, =1
STORE AREG, &X
MEND
Macro Call
INCR COUNT
Expanded Code
LOAD AREG, COUNT
ADD AREG, =1
STORE AREG, COUNT

4. Two-Pass Macro Processor


A Two-Pass Macro Processor processes macros in two scans (passes) of the source program.

5. Role of Each Pass


🔹 Pass-1 (Macro Definition Processing)
• Identifies macro definitions
• Stores macro information in tables
• Replaces formal parameters with positional notation
• No macro expansion occurs
🔹 Pass-2 (Macro Expansion)
• Detects macro calls
• Performs parameter substitution
• Expands macros
• Produces final expanded source program

6. Databases Used in Two-Pass Macro Processor


These databases are created in Pass-1 and used in Pass-2.

6.1 Macro Name Table (MNT)


Purpose
• Stores macro names
• Points to macro definition in MDT
Used in
• Pass-2 to identify macro calls
Format
Index Macro Name MDT Pointer
1 INCR 5
2 SWAP 12
MDT Pointer → Starting index of macro body in MDT

6.2 Macro Definition Table (MDT)


Purpose
• Stores macro body
• Each instruction stored line by line
• Formal parameters replaced by positional form
Created in
• Pass-1
Used in
• Pass-2 for expansion
Format
MDT Index Instruction
5 LOAD AREG, (P,1)
6 ADD AREG, =1
7 STORE AREG, (P,1)
8 MEND
(P,1) → First positional parameter

6.3 Argument List Array (ALA)


Purpose
• Stores actual arguments from macro call
• Used for parameter substitution
Created in
• Pass-2 (for each macro call)
Format
Parameter No. Actual Argument
1 COUNT

6.4 Keyword Parameter Default Table (KPDTAB)


Purpose
• Stores keyword parameters and their default values
• Used when keyword arguments are optional
Created in
• Pass-1
Format
Param No. Parameter Name Default Value
1 &REG AREG
2 &VAL 1

7. Working of Two-Pass Macro Processor

🔹 Pass-1 Working (Step-by-Step)


1. Read source program line by line
2. When MACRO encountered:
o Enter macro name in MNT
o Note MDT starting index
3. Store macro body in MDT
4. Replace formal parameters with (P,n)
5. Store keyword parameters in KPDTAB
6. Stop processing at MEND
Output of Pass-1 → MNT, MDT, KPDTAB

🔹 Pass-2 Working (Step-by-Step)


1. Read source program again
2. If statement is not macro call → copy as it is
3. If macro call found:
o Search macro name in MNT
o Create ALA from actual arguments
o Fetch macro body from MDT
o Replace (P,n) using ALA
4. Output expanded code
Output of Pass-2 → Expanded Assembly Program
10. Final Exam Conclusion
A macro allows a sequence of instructions to be defined once and expanded multiple times. A
two-pass macro processor uses Pass-1 to create macro databases and Pass-2 to expand macro
calls using tables such as MNT, MDT, ALA, and KPDTAB.

Flowchart for Pass-2 of Two-Pass Macro Processor

Pass-2 of Two-Pass Macro Processor (Point-wise)


1. Pass-2 starts after macro tables (MNT, MDT, KPDTAB) are created in Pass-1.
2. The next source statement is read from the intermediate file.
3. The operation code is searched in the Macro Name Table (MNT).
4. If no macro name is found, the statement is copied to the expanded source file.
5. If a macro call is found, the MDT pointer (MDTP) is obtained from MNT.
6. An Argument List Array (ALA) is created using actual parameters.
7. Macro instructions are fetched from MDT one by one.
8. Positional parameters are replaced using ALA values.
9. Expanded instructions are written to the output file until MEND is found.
10. Steps repeat until the END statement is encountered.

Features of Macro Facility (with Examples)


A Macro Facility allows programmers to define a sequence of instructions once and reuse them
multiple times. It supports various types of macros to improve flexibility and productivity.
i) Simple Macro
Explanation
• A Simple Macro has no parameters.
• Same set of instructions is expanded every time the macro is called.
• Used when instructions are repeated without change.
Example
Macro Definition
MACRO
INCR &X
ADD &X, =1
MEND

Macro Call
CLEAR
Expanded Code
MOV AREG, =0
MOV BREG, =0
Feature Highlight
• Easy to use
• No argument passing
• Reduces repetitive code

ii) Parameterized Macro


Explanation
• A Parameterized Macro accepts parameters.
• Actual values are passed during macro call.
• Same macro can work with different variables.
Example
Macro Definition
MACRO
INCR &X
ADD &X, =1
MEND
Macro Call
INCR COUNT
Expanded Code
ADD COUNT, =1
Feature Highlight
• Flexible
• Supports code reuse
• Uses formal and actual parameters

iii) Conditional Macro


Explanation
• A Conditional Macro uses conditional statements.
• Expansion depends on conditions.
• Assembler directives like IF, ELSE, ENDIF are used.
Example
Macro Definition
MACRO
CHECK &X
IF &X GT 0
MOV AREG, &X
ENDIF
MEND
Macro Call
CHECK 5
Expanded Code
MOV AREG, 5
Feature Highlight
• Supports decision making
• Conditional expansion
• More powerful macros

iv) Nested Macro


Explanation
• A Nested Macro is a macro called inside another macro.
• Inner macro is expanded first.
• Improves modularity.
Example
Macro Definition
MACRO
INC &X
ADD &X, =1
MEND

MACRO
INC2 &Y
INC &Y
INC &Y
MEND
Macro Call
INC2 TOTAL
Expanded Code
ADD TOTAL, =1
ADD TOTAL, =1
Feature Highlight
• Supports hierarchy
• Improves readability
• Reduces complexity
Final Exam Conclusion
The macro facility supports simple, parameterized, conditional, and nested macros to reduce
code repetition, improve flexibility, and enhance modularity in assembly language programming.

Single Pass Assembler (for x86 Processor)


What is a Single Pass Assembler?
A Single Pass Assembler scans the assembly program only once and simultaneously:
• builds symbol information
• generates machine code
For x86, it translates instructions like MOV, ADD, JMP into x86 machine code in one scan.

Key Idea (Tell it like it is)


• One pass = fast
• But forward references are a pain
• Uses backpatching to handle them

Design of Single Pass Assembler (x86)


Main Data Structures Used
1. OPTAB (Opcode Table)
Stores x86 mnemonics and opcodes
Example:
2. MOV → 89
3. ADD → 01
4. JMP → EB
5. SYMTAB (Symbol Table)
Stores labels and addresses
6. LC (Location Counter)
Tracks memory address
7. Forward Reference List Used when label is used before definition

Working of Single Pass Assembler (x86)


Step-by-step Flow
1. Initialize LC = starting address
2. Read source code line by line
3. If label found:
o Enter label with LC in SYMTAB
o Backpatch if forward reference exists
4. If opcode found:
o Search in OPTAB
o Generate x86 machine code
5. If operand is label:
o If defined → use address
o If not defined → mark forward reference
6. Update LC
7. Continue until END

Flow Diagram (Conceptual)

Suitable Example (x86 Assembly)


Source Program
START 1000
JMP NEXT
MOV AX, BX
NEXT: ADD AX, CX
END

Pass (Single Scan Execution)


Line 1: START 1000
• LC = 1000
Line 2: JMP NEXT
• NEXT not yet defined
• Forward reference created
• Machine code generated with dummy address
Line 3: MOV AX, BX
• Opcode found in OPTAB
• Machine code generated
• LC updated
Line 4: NEXT: ADD AX, CX
• NEXT defined → address = current LC
• Backpatch JMP instruction with correct address
Line 5: END
• Assembly stops

Symbol Table (After Assembly)


Symbol Address
NEXT 1004

Output (Conceptual x86 Machine Code)


JMP 1004
MOV AX, BX
ADD AX, CX

Advantages
• Faster assembly
• Less memory usage
• Simple design
Limitations
• Forward references complicated
• Backpatching required
• Not suitable for complex programs

Final Exam Conclusion (Strong Line 🔥)


A single pass assembler for x86 translates assembly code into machine code in one scan using
symbol tables and backpatching to handle forward references, resulting in faster but less flexible
assembly.

🔷 Flowchart for Pass-1 of Assembler


Flowchart for Pass-1 (Assembler)
Explanation of tables with examples
• (a) MOT & POT
• (b) ST & LT

How to draw in exam (structure ✍️)


START
|

Read Next Statement
|

Is START Statement?
/ \
YES NO
| |
Set LC |
| ↓
| Is Label Present?
| / \
| YES NO
| | |
| Enter in ST |
| ↓
| Is Opcode in MOT?
| / \
| YES NO
| | |
| Update LC Check POT
| |
| Update LC
| |
←←← Read Next Statement
|

END
🔷 Pass-1 of Assembler (One-line role)
Pass-1 scans the source program, assigns addresses, and creates tables like MOT, POT, ST, and
LT without generating machine code.

(a) MOT & POT


🔹 MOT – Machine Opcode Table
Meaning
MOT stores machine instructions, their opcode, and instruction length.
Purpose
• Used to identify imperative statements
• Helps update Location Counter (LC)
Example MOT
Mnemonic Opcode Length
ADD 01 1
SUB 02 1
MOV 04 1
JMP 05 1
Example use:
ADD AREG, B
Assembler finds ADD in MOT → opcode known → LC incremented.

🔹 POT – Pseudo Opcode Table


Meaning
POT stores assembler directives (pseudo-ops).
Purpose
• No machine code generation
• Helps control assembler actions
Example POT
Pseudo Opcode Function
START Initialize LC
END Stop assembly
DS Define Storage
DC Define Constant
LTORG Process literals
Example use:
DS 5
→ Reserve 5 memory locations → LC increased by 5.
(b) ST & LT
🔹 ST – Symbol Table
Meaning
ST stores labels (symbols) and their addresses.
Purpose
• Used for address resolution
• Helps in jump and branch instructions
Example ST
Symbol Address
LOOP 205
NEXT 210
Example:
LOOP: ADD AREG, B
LOOP entered into ST with current LC.

🔹 LT – Literal Table
Meaning
LT stores literals (constants written as =value).
Purpose
• Assigns memory to literals
• Used during LTORG or END
Example LT
Literal Address
=5 300
=1 301
Example:
ADD AREG, =5
Literal =5 entered into LT and assigned address later.

🔷 Summary Table (Quick Revision)


Table Used For
MOT Machine instructions
POT Assembler directives
ST Labels and addresses
LT Literal constants
🔥 Final Exam Conclusion
In Pass-1 of an assembler, the source program is scanned to build MOT, POT, Symbol Table,
and Literal Table while assigning addresses using the location counter, without generating
machine code.

Question:
Construct the necessary data structures after compiling the following code by Pass-1 of a Two-
Pass Macro Processor:
MACRO
COMPUTE &x, &a, &p
MOVER &a, &x
MULT &a, =4
MOVEM &a, &p
MEND

MACRO
CALC &g, &k, &r
MOVER &r, &k
SUB &r, =4
MEND

Answer:
In Pass-1 of a two-pass macro processor, macro definitions are processed and required tables
are constructed. No macro expansion is performed in this pass. The following data structures are
generated:
• Macro Name Table (MNT)
• Parameter Name Table (PNTAB)
• Macro Definition Table (MDT)
Formal parameters are replaced by positional notation (P,n).

1. Macro Name Table (MNT)


The Macro Name Table stores the macro name and the starting index of its definition in the
MDT.
Index Macro Name MDT Pointer
1 COMPUTE 1
2 CALC 5

2. Parameter Name Table (PNTAB)


A separate PNTAB is created for each macro to store its formal parameters.
PNTAB for COMPUTE
Parameter No. Parameter Name
1 &x
2 &a
Parameter No. Parameter Name
3 &p

PNTAB for CALC


Parameter No. Parameter Name
1 &g
2 &k
3 &r

3. Macro Definition Table (MDT)


The MDT stores the macro body. Formal parameters are replaced by positional parameters.
MDT Index Macro Instruction
1 MOVER (P,2), (P,1)
2 MULT (P,2), =4
3 MOVEM (P,2), (P,3)
4 MEND
5 MOVER (P,3), (P,2)
6 SUB (P,3), =4
7 MEND

Explanation
• In the macro COMPUTE, parameters &x, &a, and &p are replaced by (P,1), (P,2),
and (P,3) respectively.
• In the macro CALC, parameters &g, &k, and &r are replaced by positional
parameters.
• The MDT pointer in MNT indicates where each macro definition begins in the MDT.
• No macro calls are expanded during Pass-1.

Assignment 1

Types of System Programming


Definition of System Programming
System programming refers to the development of programs that control, manage, and support
the operation of a computer system. These programs work close to the hardware and provide a
platform for application software.
1. Assembler
• Converts assembly language programs into machine language.
• Produces object code that can be executed by the processor.
• Used when high performance and hardware control are required.
Example: Assembly language assembler for x86 processors.

2. Compiler
• Translates high-level language programs into machine code in one go.
• Detects syntax and semantic errors during compilation.
• Generates fast executable programs.
Example: C, C++ compiler.

3. Interpreter
• Translates and executes programs line by line.
• Errors are detected at the time of execution.
• Execution speed is slower compared to compiled programs.
Example: Python interpreter.

4. Linker
• Combines multiple object modules into a single executable file.
• Resolves external references and symbols.
• Produces the final executable program.

5. Loader
• Loads the executable program into main memory.
• Performs address binding and memory allocation.
• Starts program execution.

6. Macro Processor
• Replaces macro calls with corresponding macro definitions.
• Reduces repetitive code.
• Used mainly in assembly language programs.

7. Operating System
If you want, I can also give:
• Short Acts as an interface between user and hardware.
• Manages CPU, memory, files, and I/O devices.
• Controls execution of programs.
Example: Windows, Linux, UNIX.
8. Device Drivers
• Enable communication between the operating system and hardware devices.
• Control specific hardware components.
Example: Printer driver, display driver.

You might also like