













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














Prepared from the supplied COM 212 System Programming handout Course Code: COM 212 Course Title: System Programming Level: ND/HND Computer Science (adaptable)
HOW TO USE THIS NOTE This lecture note explains the major topics in the supplied 50-page handout using clearer language, short explanations, examples and comparison tables. It is arranged for classroom learning and examination revision. The order follows the handout’s broad progression: system programming, assembly language, program translation, libraries and utilities, and operating systems. Important: Examples and explanations have been simplified for learning. Where a concept in the source handout is described briefly, this note explains only the point supported by that material and does not introduce unrelated advanced topics. COURSE OUTLINE Meaning, features and types of system programming software System programming and application programming Assembly language: meaning, syntax, instruction format and instruction groups Data movement, arithmetic/logic and control-flow instructions Assembler directives and the assembly process Program translation: assembler, interpreter and compiler Phases of a compiler, errors and types of compilers Programming libraries: static and dynamic libraries Utility software: functions and types Operating systems: meaning, command interface and major functions Types of operating systems CHAPTER ONE: INTRODUCTION TO SYSTEM PROGRAMMING
System programming is the activity of developing software that controls, coordinates and supports the operation of computer hardware. It provides the link that allows hardware, other software and the user to work together. In simple terms, system programming produces the software that helps a computer operate properly. Examples include operating systems, device drivers, firmware, language translators and utility programs.
The programmer needs a good understanding of the computer hardware and the system on which the program will run. System programs often use low-level languages because they need close control over hardware resources. They are designed to work efficiently, sometimes in environments with limited memory or processing resources. They may access memory and control program execution directly. Some parts may be written in assembly language where direct hardware control or high performance is required. Debugging may be difficult because system programs interact closely with hardware and operating-system functions. Logging and monitoring are useful because they help identify problems during operation.
Enterprise software Supporting the activities and information needs of an organization. Graphics software Creating and editing images, illustrations and visual designs. Communication software Exchanging text, audio, video and other messages. Educational software Providing learning materials, lessons and educational support. CHAPTER TWO: ASSEMBLY LANGUAGE
Assembly language is a low-level programming language whose instructions closely correspond to the machine instructions of a particular processor. It uses short symbolic names called mnemonics instead of requiring the programmer to write every instruction as binary digits. For example, the mnemonic MOV represents a data-movement operation, while ADD represents addition. Since assembly language depends on a processor’s instruction set, assembly code written for one architecture may not work on another architecture without changes.
It gives the programmer close control over processor instructions and registers. It can be useful where high performance or direct hardware interaction is required. It can be used for small sections of a larger program written in a high-level language. It helps programmers understand how the processor carries out instructions.
Assembly language uses mnemonics to represent operations. It may also use registers, labels, constants, operands, directives and comments. An instruction normally contains an operation code and the data on which the operation works.
The handout describes an x86 instruction statement as having up to four parts: Part Meaning Status Label A symbolic name identifying a location in the program. Optional Instruction / opcode The operation the processor should perform, such as MOV or ADD. Required Operands The register, memory location or constant used by the instruction. Depends on instruction Comment A note explaining what the instruction does; commonly begins with a semicolon in the examples. Optional DONE: CMP AX, BX ; Compare the values in AX and BX
In this example, CMP is the opcode, AX and BX are operands, the comment explains the operation, and DONE would be a label if placed at the beginning of a statement.
Notation Meaning Any 32-bit register, such as EAX, EBX, ECX or EDX. Any 16-bit register, such as AX, BX, CX or DX. Any 8-bit register, such as AH, AL, BH or BL. Any suitable register. A memory address or memory operand. A 32-bit constant value. A 16-bit constant value. An 8-bit constant value. A constant value of an allowed size.
The handout groups machine instructions into three broad categories: data movement, arithmetic/logic and control flow.
MOV copies data from a source operand to a destination operand. The original source value remains unchanged. A direct memory-to-memory move is not allowed in the instruction forms described in the handout; data may first be moved into a register. MOV EBX, EAX ; Copy the value in EAX into EBX
PUSH places an operand on top of the stack. In the 32-bit x86 explanation in the handout, the stack pointer (ESP) is decreased by four bytes before the value is stored. PUSH EAX ; Place the value in EAX on the stack
POP takes the value at the top of the stack and places it in the specified register or memory location. The stack pointer is then increased. POP EDI ; Remove the top stack value into EDI
LEA calculates the address represented by its source operand and places that address in the destination register. It loads the address, not the data stored at that address. LEA EDI, [EBX + ESI + 8]
JG Jump if greater than. JGE Jump if greater than or equal to. JL Jump if less than. JLE Jump if less than or equal to.
CMP compares two operands by performing a subtraction for the purpose of setting condition flags. It does not keep the subtraction result. A later conditional jump can use the flags. CMP EAX, EBX JLE DONE The example means: compare EAX with EBX; if EAX is less than or equal to EBX, jump to DONE.
Assembler directives are instructions to the assembler rather than instructions for the processor to execute. They guide the assembly process and are not translated into machine operation codes. START: identifies a program name or starting point in the handout’s examples. END: marks the end of the source program and may identify the first instruction to execute. BYTE and WORD: are examples of directives used to define data sizes.
A label gives a name to a program location. It allows a programmer to refer to an instruction without manually calculating its memory address. A comment explains the purpose of a statement and makes the program easier to understand and maintain.
Assembly language is low-level and processor-dependent. Mnemonics represent machine operations. Operands identify the data or locations used by instructions. Instructions are commonly grouped into data movement, arithmetic/logic and control flow. Labels identify locations, while comments explain code. Assembler directives guide the assembler and are not ordinary processor instructions. CHAPTER THREE: PROGRAM TRANSLATION AND TRANSLATORS
Program translation is the conversion of instructions written in one programming language or representation into another form that a computer can process. In the handout, the main concern is converting source code into machine code or another suitable target representation.
Translator Meaning Typical role
Assembler Converts assembly-language instructions into machine code or object code. Translates mnemonics and symbolic operands. Interpreter Executes or translates source instructions in a way that allows execution during interpretation. Processes statements during program execution. Compiler Translates a program, usually a high- level program, into target code before the program runs. Produces target or machine code and reports translation errors.
An assembler is a translator that converts assembly language into machine language. It changes mnemonics and symbolic references into their corresponding machine representations. The output commonly includes object code.
A one-pass assembler reads and translates the source program in one pass. It is generally quick, but forward references—where a label is used before it is defined—can create a problem. The handout explains that unresolved references may require later correction or back-patching.
A two-pass assembler reads the source program twice. During the first pass, it identifies labels and builds a symbol table containing their addresses. During the second pass, it uses the symbol and mnemonic information to generate machine instructions and resolve references. One-pass assembler Two-pass assembler Reads and translates in one pass. Reads the source in two passes. Forward references may require back-patching. Forward references are resolved using information collected in pass one. Usually faster in the handout’s comparison. Usually takes more time than a one-pass assembler. May require additional handling structures for unresolved references. Uses tables such as the symbol table and mnemonic table.
Separates the label, mnemonic/opcode and operand fields of each statement. Records labels and their addresses in a symbol table. Checks whether the mnemonic is valid using the mnemonic table. Uses a location counter (LC) to track the address of the next instruction or data item.
Syntax analysis checks whether the tokens follow the grammar rules of the programming language. It builds a hierarchical structure called a parse tree or syntax tree. If the arrangement of tokens is invalid, a syntax error is reported. For example, a missing closing parenthesis or a misplaced operator may cause a syntax error.
Semantic analysis checks whether a syntactically correct program also makes sense according to the language rules. It checks matters such as data types, declared variables, function arguments and compatible operands. For example, a program may have correct punctuation and structure but still try to use an undeclared variable or combine incompatible data types.
After semantic analysis, the compiler may produce an intermediate representation (IR), which is a middle-level form between the source language and the target machine language. It makes the program easier to translate to the target machine. total = count + rate * 5 A simplified sequence of intermediate steps could be: t1 := convert 5 to the required numeric type t2 := rate * t t3 := count + t total := t
Code optimization improves the intermediate code so that the final program can run more efficiently or use less space. It may remove unnecessary statements, unused variables and unreachable code, and simplify expressions without changing the intended result.
Code generation is the final compiler phase. It converts the optimized intermediate representation into target instructions or machine code. It also selects registers and memory locations needed by the generated instructions. MOV AL, B ADD AL, 60 MOV A, AL
Compiler component Example of error Lexical analyser Misspelled or invalid token. Syntax analyser Missing parenthesis or incorrect statement structure. Semantic analyser Incompatible function arguments, undeclared variable or type mismatch. Intermediate-code generator Operands that do not match the requirements of an operation. Code optimizer Unreachable or unnecessary statements may be identified.
Code generator Insufficient memory or unavailable suitable registers. Symbol table Repeated or conflicting identifier declarations.
A one-pass compiler moves through the compiler stages once, processing the program and producing the expected output. It can be simpler and faster, but may have less information available for advanced optimization.
A two-pass compiler is divided into a front end and a back end. The front end analyses the source program and produces an intermediate representation. The back end converts that representation into code for the target machine. Front end Back end Lexical analysis, syntax analysis, semantic analysis and intermediate-code generation. Code optimization and code generation. Generally concerned with the source language and analysis. Concerned with the target machine and final code.
A multi-pass compiler processes the source program or an intermediate representation several times. Each pass uses the result of the previous pass. This can improve code quality and optimization, but may require more compilation time and memory.
Cross compiler: runs on one machine but produces target code for another machine. Load-and-go compiler: produces code that is prepared for immediate execution, with compilation and loading closely connected.
Compiler Interpreter Translates the program before execution. Processes or executes the program during interpretation. Typically produces target or executable code. Typically does not produce a separate executable in the same manner. Compiled code generally runs faster after compilation. Execution may be slower because interpretation work occurs at run time. Can analyse a wider portion of the program before execution. Often reports errors as the relevant statements are processed. Can perform broader optimization using information about the program. Usually has less opportunity for whole-program optimization.
Utility software is designed to maintain, manage, protect or improve the performance of a computer system. It supports the operating system and the applications installed on the computer.
Improves system performance. Manages storage space. Organizes files and data. Helps customize the computer interface. Removes unnecessary files. Protects the computer and its information. Helps recover files after data loss.
Utility Function Antivirus Scans for malicious software and blocks or removes detected threats. Access-control software Allows or denies access to computer resources. Debugger Helps examine and modify program instructions or data while investigating faults. Diagnostic program Checks and reports the condition of hardware or software. Network utility Checks network connectivity, settings and data-transfer activity. Package manager Installs, updates and manages software packages. System monitor Displays resource usage and system performance. System profiler Provides information about installed hardware and software.
Utility Function Backup software Creates copies of files or disks so data can be restored after loss or damage. Disk checker Checks a storage device for file-system or physical errors. Disk compression Reduces the space occupied by data. Disk defragmenter Reorganizes scattered file fragments into more continuous storage areas. Disk formatter Prepares a storage device for use and may erase existing data. Partition editor Divides a physical drive into logical sections. Disk-space analyser Shows how storage space is used by files and folders.
Utility Function Archiver Combines files into an archive; may also support compression or encryption. Cryptographic utility Encrypts and decrypts files or data streams. Data-compression utility Reduces the size of files or data streams. Data-conversion utility Changes data from one file format to another. Data-recovery utility Attempts to recover useful data from damaged or corrupted files. File-synchronization utility Keeps files consistent across two or more locations. Revision-control utility Helps manage changes made to files by one or more users. Disk cleaner Finds unnecessary files that take up storage space. CHAPTER FIVE: OPERATING SYSTEMS
An operating system (OS) is system software that manages the computer’s hardware and provides services for application programs and users. It coordinates the activities of the processor, memory, files, storage devices and input/output devices. The operating system acts as an intermediary between users or application programs and the computer hardware.
In a command-based environment, the user types instructions or commands to request an operation. The handout uses DOS as an example. DOS commands can be used to format disks, list files, copy files and erase files.
A graphical user interface presents items such as windows, icons and menus. Users interact with these items mainly by pointing and clicking. Microsoft Windows is used in the handout as an example. The handout also explains multitasking: an operating system can keep several programs active and switch processor attention among them so users can work with more than one program.
The OS loads programs into memory and starts their execution. It also creates and deletes processes, suspends and resumes them, and provides ways for processes to communicate and synchronize. Loads a program into memory. Executes the program.
The handout identifies possible benefits such as faster computation, greater data availability and improved reliability.
Protection controls how users and processes access system resources. It distinguishes authorized access from unauthorized access, defines the controls to be applied and provides a way to enforce those controls.
The handout explains that I/O operations should be controlled so that ordinary user programs cannot perform restricted operations directly. A program requests an I/O service through the operating system. This request can cause a trap, after which the OS handles the request and returns control to the program.
The OS must prevent one process from accessing or overwriting memory belonging to another process or protected parts of the operating system. The handout describes base and limit registers as a simple protection technique: the base register identifies the starting legal address, while the limit register specifies the size of the permitted range.
A timer can prevent one process from occupying the CPU indefinitely. When the allotted time expires, an interrupt allows the operating system to regain control and decide which process should run next.
The handout distinguishes user mode from kernel (privileged or supervisor) mode. User programs operate with limited privileges. The operating system uses kernel mode to perform protected tasks such as controlling devices, managing memory structures and handling interrupts. User mode Kernel mode Restricted execution mode for ordinary applications. Privileged mode used by the operating system. Cannot directly perform certain protected operations. Can perform privileged operations such as device control and memory management. Requests protected services through the OS. Handles those requests and manages system resources.
Mainframe systems are designed to handle large volumes of data and processing for large organizations. The handout gives examples of use in banking, finance, healthcare, insurance, government and other large enterprises.
A batch operating system groups similar jobs and processes them as a batch. Users normally submit jobs and do not interact directly with the computer while each job is running. Jobs may be processed in submission order, such as first-come, first-served.
Time-sharing allows multiple users or programs to share processor time. The CPU switches rapidly between tasks, giving each task a short time interval. Because switching is frequent, users can interact with programs while they are running.
Multiprogramming keeps several jobs in memory so that the CPU can switch to another job when the current one is waiting, for example for an input/output operation. Its main goal is to keep the processor busy and improve CPU utilization.
A multiprocessor operating system manages a computer with more than one processor. The processors may share memory and other resources and can work on different tasks at the same time. The handout identifies three advantages: Increased throughput: more work can be completed in a given time. Economy of scale: processors can share resources such as storage and peripherals. Increased reliability: the system may continue operating at a reduced level if one processor fails. The handout also identifies symmetric multiprocessing, where processors run equivalent copies of the operating system, and asymmetric multiprocessing, where a master processor controls other processors.
A distributed operating system coordinates work across multiple connected computers or processors. The computers communicate through network links and may have their own local memory. Tasks can be shared among the processors.
A real-time operating system is designed to respond to events within specified time limits. The time taken to respond is important, not just the correctness of the result. Examples in the handout include industrial control, medical imaging, robotics and air-traffic control. Hard real-time system Soft real-time system Critical tasks must meet their deadlines; missing a deadline can mean system failure. Important tasks receive priority, but occasional deadline misses may be tolerated. Used where strict timing guarantees are essential. Used where timely response is important but less rigid.
These operating systems are designed for personal computer use, with emphasis on convenience and responsiveness. The handout mentions Microsoft Windows and Apple Macintosh systems.
Intermediate representation A middle-level representation used during translation. Optimization Improving code efficiency without changing its intended result. Library Reusable routines that programs can call. Utility software Software that maintains, manages or protects a computer. Operating system Software that manages hardware resources and provides services to programs.
1. Which of the following is system software? A. Spreadsheet B. Operating system
C. Presentation slide D. Photo album
2. Which assembly mnemonic is commonly used to copy data? A. MOV B. ADD C. CMP D. JMP 3. Which instruction places data on the stack? A. POP B. PUSH C. LEA D. SUB 4. Which translator converts assembly language to machine code? A. Compiler B. Interpreter C. Assembler D. Debugger 5. Which compiler phase identifies tokens? A. Semantic analysis B. Lexical analysis C. Code generation D. Optimization 6. Which phase checks whether code follows grammar rules? A. Syntax analysis B. Code generation C. Optimization D. Linking 7. Which library is incorporated into a program during linking? A. Dynamic B. Static C. Network D. Remote 8. Which utility helps restore data after loss? A. Backup utility B. Disk formatter C. Screen saver D. Calculator 9. Which OS function manages allocation of main memory? A. File management B. Memory management