0% found this document useful (0 votes)
5 views11 pages

System Programming Note

This document provides an overview of system programming and operating systems, detailing the concepts, objectives, and types of system programs such as assemblers, compilers, and interpreters. It also covers the compilation process, the historical development of operating systems, and the concept of interrupts and traps. Key differences between system and application programs, as well as various operating system types, are discussed.

Uploaded by

saleemyoungarmy6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

System Programming Note

This document provides an overview of system programming and operating systems, detailing the concepts, objectives, and types of system programs such as assemblers, compilers, and interpreters. It also covers the compilation process, the historical development of operating systems, and the concept of interrupts and traps. Key differences between system and application programs, as well as various operating system types, are discussed.

Uploaded by

saleemyoungarmy6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

LECTURE NOTE ON SYSTEM

PROGRAMMING & OPERATING SYSTEMS

1.0 SYSTEM PROGRAMMING


1.1 Concept of System Programming
System programming refers to the design and development of system software that provides the
interface between the hardware and the application programs.
System programs control, manage, and coordinate the operations of computer hardware.
Examples of system programs: Operating systems, compilers, assemblers, linkers, loaders, device
drivers, utility programs.

1.2 Objectives of System Programming


The major objectives include:
1. Efficiency:
System programs aim to make the best use of hardware resources such as CPU, memory, I/O
devices.
2. Convenience:
Provide a friendly platform for application programmers and users.
3. Abstraction:
Hide hardware complexities and provide simpler interfaces.
4. Control:
Provide mechanisms to monitor programs, security, and resource allocation.
5. Compatibility:
Ensure software can run across different systems.
6. Performance Improvement:
By optimizing resource utilization, scheduling, and data handling.
7. Automation:
Handle routine tasks like memory management, job scheduling, error detection.

1.3 System Programs vs Application Programs


System Programs Application Programs
Manage hardware and system resources. Designed to help users perform specific tasks.
System Programs Application Programs
Examples: OS, compilers, assemblers, device drivers. Examples: MS Word, Calculator, Browser.
Required for system operation. Optional depending on user needs.
Run in privileged (kernel) mode. Run in user mode.
Provide platform for applications. Depend on system software to run.

2.0 TYPES AND FUNCTIONS OF SYSTEM PROGRAMS


2.1 Assembler
An assembler translates assembly language (mnemonics) into machine language (binary).
Example: ADD R1, R2 → 101000110010.

Functions:
 Symbol table creation
 Address calculation
 Instruction translation
 Error detection

2.2 Compiler
A compiler translates high-level languages (C, Java) into machine code.
It processes the whole program at once.
Functions:
 Lexical analysis
 Syntax & semantic analysis
 Optimization
 Code generation
 Error reporting

2.3 Interpreter
An interpreter executes programs line-by-line without producing machine code output files.
Examples: Python Interpreter, JavaScript engine.
Functions:
 Reads one instruction at a time
 Executes immediately
 Handles runtime errors
 Suitable for debugging
2.4 Loaders and Linkers
Linker
A linker combines different object modules into a single executable program.
Roles:
 Combine object files
 Resolve external references
 Allocate memory for modules

Loader
A loader places the executable into main memory for execution.
Roles:
 Load programs into memory
 Relocate addresses
 Pass control to the program

3.0 ASSEMBLY LANGUAGE PROGRAMMING (DETAILED


EXPLANATION)
Assembly language is a low-level programming language that uses symbolic names (words) instead
of raw binary numbers to communicate with the computer.

Why Students Need to Understand Assembly Language


 It shows how a computer really works internally.
 It explains how high-level languages translate into machine code.
 It helps students understand compiler, loader, linker, CPU registers, and memory addresses.

3.1 General Format of an Assembly Language Statement (Full


Explanation)
Every assembly instruction usually contains up to four fields, arranged like this:
LABEL OPCODE OPERAND(S) COMMENT

Let us study each field:

1. LABEL (Optional)
A label is a user-defined name that marks a position in memory.
 Think of it like a “bookmark” or a “reference point”.
 The assembler replaces the label with the actual memory address later.
Example:
START: MOV AX, BX

Here, START: is not an instruction. It simply marks this line with a name so the program can jump
back to it.
Why Labels Are Important
 Used in loops
 Used in conditional branching
 Avoids writing raw memory addresses like 0050H, 0060H, etc.

2. OPCODE (Operation Code)


This is the instruction telling the CPU what to do.
Examples:
 MOV → move data

 ADD → add values

 SUB → subtract

 JMP → jump to another location

 LOAD → load from memory

 STORE → store to memory

The CPU has a fixed set of available opcodes (instruction set architecture).

3. OPERANDS (Data or Addresses)


Operands tell the CPU where to get the input data or where to store the result.
They can be:
 Registers (e.g., AX, R1, R2)
 Memory locations (e.g., NUM1, 200H)
 Immediate values (e.g., 5, #10)
Examples:
MOV R1, R2 ; move content of R2 into R1
ADD R1, #5 ; add 5 to R1
STORE R3, 1000H ; store R3 value in memory address 1000H

4. COMMENTS (Optional)
Comments start with ; and are ignored by the assembler.

They help explain what the instruction is doing.


Example:
ADD R1, R2 ; Add R2 to R1

Putting It Together – Full Sample Instruction


LOOP: ADD R1, R2 ; Add content of R2 to R1

Breakdown:

Field Meaning
LOOP: Label (marks this line in memory)
ADD Opcode (operation: addition)
R1, R2 Operands (data sources)
;… Comment explaining the instruction

3.2 One-Pass vs Two-Pass Assemblers (Expanded Explanation)


This topic usually confuses students, so here is a simple and clear explanation.

One-Pass Assembler (Explained Simply)


A one-pass assembler reads the program once from top to bottom.
It tries to:
 Translate instructions
 Build symbol table
 Assign addresses
all at the same time.

Problem: Forward References


A forward reference happens when you use a label that has not appeared yet.
Example:
JMP LOOP
...
LOOP: ADD R1, R2

In a one-pass assembler:
 When it encounters JMP LOOP, the assembler does not yet know where LOOP is located.

 This makes translation difficult.


Conclusion:
One-pass assemblers struggle with forward references.
Advantage: Fast
Disadvantage: Cannot handle complex programs well

Two-Pass Assembler (Explained Simply)


A two-pass assembler reads the program twice.

PASS 1: Build Symbol Table


The assembler:
 Reads labels
 Records memory addresses
 Does NOT translate instructions yet
Example symbol table after pass 1:

Label Address
START 0000H
LOOP 0005H

PASS 2: Generate Machine Code


Now that all labels have known addresses, the assembler translates instructions.
Example:
JMP LOOP → converted in pass 2 using LOOP’s address (0005H)

Why Two-Pass Assemblers Are Better


 Fully resolve forward references
 More accurate and reliable
 Used for larger, more realistic assembly programs
Short Comparison Table
Feature One-Pass Assembler Two-Pass Assembler
Number of scans One Two
Forward references Difficult to handle Easily handled
Speed Faster Slower
Complexity Simple More complex
Usefulness Small/simple programs Large/complex programs

Illustration: A Simple Assembly Program With Passes


Sample Program
JMP START
DATA: DW 10
START: MOV AX, DATA

Pass 1 Output (symbol table)


Label Address
DATA 0001H
START 0003H

Pass 2 Output (final machine code)


The assembler now knows:
 Where DATA is stored

 Where START is

 So it correctly generates instructions

Why Students Must Understand Passes


 Shows how assemblers resolve addresses
 Helps understand linkers and loaders later
 Forms the foundation of how compilers work internally
 Useful for embedded systems, OS design, device drivers

4.0 COMPILATION PROCESS


4.1 Stages of Compilation
1. Lexical Analysis – breaks source code into tokens.
2. Syntax Analysis – checks grammar (parsing).
3. Semantic Analysis – ensures logical correctness.
4. Intermediate Code Generation – platform-independent code.
5. Optimization – improves performance.
6. Code Generation – converts to machine code.
7. Error Handling – detects and reports errors.

4.2 Translation vs Compilation vs Interpretation


Concept Meaning Example
Converting source code to another form (assembly or object
Translation Assembler, compiler.
code).
Full translation of high-level code to machine code before C, C++, Java
Compilation
execution. (partially).
Executes program line-by-line without generating machine
Interpretation Python, PHP.
code file.

4.3 Code Generation and Code Optimization


Code Generation
The compiler produces target machine code from intermediate code.
Tasks:
 Register allocation
 Instruction selection
 Memory addressing

Code Optimization
Improves the efficiency of generated code.
Types:
 Local optimization (within a block)
 Global optimization (whole program)
Examples:
 Removing redundant instructions
 Loop optimization
 Dead code elimination
5.0 OPERATING SYSTEMS (OS)
5.1 Definition of an OS
An Operating System is a system program that acts as an interface between the user and computer
hardware.
It manages resources such as CPU, memory, files, and I/O devices.

5.2 Historical Development of Operating Systems


1. First Generation (1940s–50s):
 No OS; programs wired on boards.
2. Second Generation (1950s–60s):
 Batch processing systems.
 Magnetic tapes used to submit jobs.
3. Third Generation (1960s–70s):
 Multiprogramming.
 Time-sharing systems introduced.
4. Fourth Generation (1980s–Present):
 Personal computers.
 Graphical user interfaces.
 Modern OS (Windows, Linux, macOS).

5.3 Types of Operating Systems


i. Batch Processing Systems
 Jobs are collected and processed in batches.
 No interaction with the user during execution.
Example: Early IBM systems.

ii. Time-Sharing Systems


 CPU time is divided among multiple users.
 Users interact with the system simultaneously.
Examples: UNIX, multi-user Linux.

iii. Multiprogramming Systems


 Multiple programs reside in memory and share the CPU.
 OS switches between tasks.
Example: Modern Windows & Linux.

iv. Real-Time Operating Systems (RTOS)


 Responds to events within strict time constraints.
 Used in critical applications.
Examples:
 Medical devices
 Airplane control systems
 Embedded systems

6.0 INTERRUPTS AND TRAPS


6.1 Concept of Interrupts
An interrupt is a mechanism where the CPU is alerted by hardware to stop current execution and
handle an urgent event.
Examples:
 Keyboard input
 Mouse click
 Disk I/O completion

6.2 Concept of Traps


A trap is a software-generated interrupt, usually due to:
 Errors (divide by zero)
 System calls
 Debugging events
Traps are synchronous with program execution.

6.3 Interrupt Handling vs Polling


Polling
 CPU repeatedly checks the status of a device.
 Wastes CPU time.
 Slower and inefficient.
Interrupt Handling
 Device sends a signal when it needs service.
 CPU stops current task and handles request.
 More efficient and faster.
Key Differences:

Polling Interrupt Handling


CPU constantly checks Device signals the CPU
Wastes CPU time Saves CPU time
Used in simple systems Used in modern systems
Slower Faster and efficient

You might also like