Summarize System Programming Note
Summarize System Programming Note
services to the user (e.g. word processor, Spreadsheets, databases, Accounting packages)
Systems programming aims at producing software which provides services to the computer
It also requires a greater degree of hardware awareness that is to say it is machine dependent and
the programmer needs to know the hardware within which the software will operate
• The programmer will make assumptions about the hardware and other properties of the
system that the program runs on, and will often exploit those properties (for example by
using an algorithm that is known to be efficient when used with specific hardware)
Allows for direct and "raw" control over memory access and control flow
Let the programmer write parts of the program directly in assembly language
1
• Debugging can be difficult if it is not possible to run the program in a debugger due to resource
constraints. Running the program in a simulated environment can be used to reduce this problem.
communicate directly with a computer’s hardware. Unlike machine language, which consists of
binary and hexadecimal characters, assembly languages are designed to be readable by humans.
Today, assemble languages are rarely written directly, although they are still used in some niche
Assembler translates or compiles assembly language code into machine code for execution
Types of Assemblers
1) A One-pass Assembler: One that performs all its functions by reading the source files
once.
assembler resides in ROM, is very simple (supports only a few directives and no macros),
2
4) A Macro-Assembler: One that supports macros
5) A Cross-Assembler: An assembler that runs on one computer and assembles programs for
portable. They run on a large machine and produce object code for a small machine.
The assembly language requires an A high-level language conversion requires the use of
assembler to convert. an interpreter or compiler.
It is closely related to hardware and is thus It has no hardware interactions and is only used to
used to write hardware programs. write software application programs.
Operating system
An operating system (commonly abbreviated computer system that is responsible for the
management and coordination of activities and the sharing of the limited resources of the
computer. The operating system acts as a host for applications that are run on the machine.
3
Functions of an Operating System
Following are the five services provided by an operating systems to the convenience of the users.
Program Execution
The purpose of computer systems is to allow the user to execute programs. So the operating
systems provide an environment where the user can conveniently run programs. The user does
not have to worry about the memory allocation or multitasking or anything. These things are
Running a program involves the allocating and de-allocating memory, CPU scheduling in case of
4
multi-process. These functions cannot be given to the user-level programs. So user-level
programs cannot help the user to run programs independently without the help from operating
systems.
I/O Operations
Each program requires an input and produces output. This involves the use of I/O. The operating
systems hides the user the details of underlying hardware for the I/O. All the user sees is that the
I/O has been performed without any details. So the operating systems by providing I/O makes it
convenient for the users to run programs. For efficiently and protection users cannot control I/O
The output of a program may need to be written into new files or input taken from some files.
The operating systems provide this service. The user does not have to worry about secondary
storage management. User gives a command for reading or writing to a file and sees his her task
accomplished. Thus operating systems make it easier for user programs to accomplish their task.
Memory Management
i. Keeping track of which parts of memory are currently being used and by whom.
ii. Deciding which processes and data to move into and out of memory.
5
Process - a program in execution. A program loaded in the memory which is currently in
OS processes execute system code while user processes execute user codes. A process is made
Process State
Process state is the current activity of such a process. A process may be in any of the following
states:
3) Waiting: process is waiting for some events to occur (such as I/O completion or reception of
signal)
6
Scheduler
A scheduler is software that helps schedule the processes in an operating system. It helps to keep
all computer resources busy and allows multiple users to share system resources effectively
Long-Term Scheduler or Job Scheduler. The job scheduler is another name for Long-
Short-Term Scheduler or CPU Scheduler. CPU scheduler is another name for Short-Term
scheduler. ...
7
Medium-Term Scheduler. The switched-out processes are handled by the Medium-Term
scheduler.
Interrupt
An interrupt is a signal emitted by a device attached to a computer or from a program within the
computer. It requires the operating system (OS) to stop and figure out what to do next. An
An interrupt is a hardware-provided or software feature which causes the currently running task
Thread
A thread is unit of execution in a process, with its own program counter that keeps track of
which instruction to execute next, system registers which hold its current working variables and
stack which contains the execution history. Each thread belongs to exactly one process and no
thread can exist outside a process. Each thread represents a separate flow of control.
Stages of Translation
1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
4. Intermediate code generation
5. Code Optimization
6. Code generation
Lexical analysis
This is the initial part of reading and analysing the program text: The text is read and divided into
tokens, each of which corresponds to a symbol in the programming language, e.g., a variable
8
name, keyword or number.
Syntax analysis
It processes the tokens, synthesized by the lexical analyzer, to determine the syntactic structure
of an input statement. This process is known as parsing. Output of the parsing step is a
representation in the form of syntax tree.
Semantic analysis
This phase checks the source program for semantic errors and gathers type of information for the
subsequent phase.
After syntax and semantic analysis, some compilers generate an explicit intermediate
representation of the source program. It can have a variety of forms. This form called three-
address code. It consists of sequence of instructions, each of which has at most three operands.
Code Optimization
The next phase does code optimization of the intermediate code. Optimization can be assumed as
something that removes unnecessary code lines, and arranges the sequence of statements in order
to speed up the program execution without wasting resources (CPU, memory).
9
Utility Software
The Utility Software is system software that helps to maintain the proper and smooth functioning
of a Computer System. It assists the Operating System to manage, organize, maintain, and
Utility Software performs certain tasks like virus detection, installation, and uninstallation, data
backup, deletion of unwanted files, etc. Some examples are antivirus software, file management
Antivirus.
Compression tools.
Disk Defragmenter.
Backup utility.
Kernel is responsible for maintaining all the important abstractions of the operating system,
10
System libraries define a standard set of functions through which applications can interact with
the kernel, and which implement much of the operating system functionality that does not need
System utilities are programs that perform individual, specialized management tasks
ASSEMBLER DIRECTIVES
Assembler directives are pseudo instructions, they provide instructions to the assembler itself
and they are not translated into machine operation codes. Example for SIC assembler directive
• BYTE,
• WORD,
• RESB,
• RESW
11
Sample Assembly Code
FUNCTIONS INCLUDE:
Processor Registers
There are ten 32-bit and six 16-bit processor registers in IA-32 architecture. The registers are
grouped into three categories −
12
General registers,
Control registers, and
Segment registers.
The general registers are further divided into the following groups −
Data registers,
Pointer registers, and
Index registers.
1. Data Registers
Four 32-bit data registers are used for arithmetic, logical, and other operations. These 32-
bit registers can be used in three ways −
CX is known as the count register, as the ECX, CX registers store the loop count in
iterative operations.
2. Pointer Registers
The pointer registers are 32-bit EIP, ESP, and EBP registers and corresponding 16-bit
right portions IP, SP, and BP. There are three categories of pointer registers −
13
Instruction Pointer (IP) − The 16-bit IP register stores the offset address of the
next instruction to be executed. IP in association with the CS register (as CS:IP)
gives the complete address of the current instruction in the code segment.
Stack Pointer (SP) − The 16-bit SP register provides the offset value within the
program stack. SP in association with the SS register (SS:SP) refers to be current
position of data or address within the program stack.
Base Pointer (BP) − The 16-bit BP register mainly helps in referencing the
parameter variables passed to a subroutine. The address in SS register is
combined with the offset in BP to get the location of the parameter. BP can also
be combined with DI and SI as base register for special addressing.
3. Index Registers
The 32-bit index registers, ESI and EDI, and their 16-bit rightmost portions. SI and DI,
are used for indexed addressing and sometimes used in addition and subtraction. There
are two sets of index pointers −
4. Control Registers
The 32-bit instruction pointer register and the 32-bit flags register combined are
considered as the control registers.
Many instructions involve comparisons and mathematical calculations and change the
status of the flags and some other conditional instructions test the value of these status
flags to take the control flow to other location.
Overflow Flag (OF) − It indicates the overflow of a high-order bit (leftmost bit)
of data after a signed arithmetic operation.
Direction Flag (DF) − It determines left or right direction for moving or
comparing string data. When the DF value is 0, the string operation takes left-to-
right direction and when the value is set to 1, the string operation takes right-to-
left direction.
Interrupt Flag (IF) − It determines whether the external interrupts like keyboard
entry, etc., are to be ignored or processed. It disables the external interrupt when
the value is 0 and enables interrupts when set to 1.
14
Trap Flag (TF) − It allows setting the operation of the processor in single-step
mode. The DEBUG program we used sets the trap flag, so we could step through
the execution one instruction at a time.
Sign Flag (SF) − It shows the sign of the result of an arithmetic operation. This
flag is set according to the sign of a data item following the arithmetic operation.
The sign is indicated by the high-order of leftmost bit. A positive result clears the
value of SF to 0 and negative result sets it to 1.
Zero Flag (ZF) − It indicates the result of an arithmetic or comparison operation.
A nonzero result clears the zero flag to 0, and a zero result sets it to 1.
Auxiliary Carry Flag (AF) − It contains the carry from bit 3 to bit 4 following
an arithmetic operation; used for specialized arithmetic. The AF is set when a 1-
byte arithmetic operation causes a carry from bit 3 into bit 4.
Parity Flag (PF) − It indicates the total number of 1-bits in the result obtained
from an arithmetic operation. An even number of 1-bits clears the parity flag to 0
and an odd number of 1-bits sets the parity flag to 1.
Carry Flag (CF) − It contains the carry of 0 or 1 from a high-order bit (leftmost)
after an arithmetic operation. It also stores the contents of last bit of a shift or
rotate operation.
Syntax
When writing any code in any program language, there is an observable, specific order of rules
that must be followed to allow a compiler to execute the code without error. These rules are
defined as the syntax, and they contain criteria such as the maximum number of allowable
characters, what characters code lines must start with, or what certain symbols "i.e. a semi-
colon" means.
Label
A label is a symbol that represents the address where an instruction or data is stored. It's purpose
is to act as the destination when referenced in a statement. Labels can be used anywhere an
address can be used in assembly languages. A symbolic label consists of an identifier followed
by a colon, while numeric labels consist of a single digital followed by a colon.
15
Operators
Also referred to as commands, operators are logical expressions that occur after the label field. In
addition, it must be preceded by at least one white-space character. Operators can either be
opcode or directive. Opcode correspond directly to machine instructions, and the operation code
includes any register name associated with the instruction. Alternatively, directive operation
codes are instructions known by the assembler.
Registers:
The processor can operate on numeric values (numbers) but must first save somewhere. The data
is now kept in memory, inside the instruction opcode, or in special on-chip memory placed
directly in the processor, known as registers. To work with a value, users don’t need to address it
by address; instead, special mnemonic “names” such as ax on x86, A on Z80, or r0 on ARM are
in use
Directive
Directives are instructions to the assembler that tell what actions must take place during the
assembly process. Directives have the importance of declaring or reserving memory for
variables; these variables can be recalled later in processes to perform more dynamic functions.
Directives are also used to break programs into different sections.
16
Here is the list of the op codes we will be using to construct assembly language programs.
17
BATCH PROCESSING
BATCH Processing can be defined as executing a series of non interactive jobs all at one time.
The term originated in the days when users entered programs on punch cards. They would give a
batch of these programmed cards to the system operator, who would feed them into the
computer. Batch jobs can be stored up during working hours and then executed during the
evening or whenever the computer is idle. Batch processing is particularly useful for operations
that require the computer or a peripheral device for an extended period of time. Once a batch job
begins, it continues until it is done or until an error occurs. Note that batch processing implies
that there is no interaction with the user while the program is being executed. An example of
batch processing is the way that credit card companies process billing or Power Holding
Company processes their bills . The customer does not receive a bill for each separate credit card
purchase or meter reading but one monthly bill for all of that month. The bill is created through
batch processing, where all of the data are collected and held until the bill is processed as a batch
at the end of the billing cycle. The opposite of batch processing is transaction processing or
interactive processing. In interactive processing, the application responds to commands as soon
as you enter them.
18
TIME SHARING This involves the CPU allocating individual slices of time to a number of users
on the computer system. As the number of users increases the response time for each terminal
declines. The speed of the CPU compared to that of the VDU and terminal is so much faster that
it gives the user the impression that they are the sole user of the system
MULTIPROGRAMMING MULTITASKING AND MULTIPROCESSING SYSTEMS
Multiprograming: In multiprogramming systems, the running task keeps running until it
performs an operation that requires waiting for an external event (e.g. reading from a tape) or
until the computer's scheduler forcibly swaps the running task out of the CPU.
Multiprogramming systems are designed to maximize CPU usage. Multitasking: In computing,
multitasking is a method by which multiple tasks, also known as processes, share common
processing resources such as a CPU. In the case of a computer with a single CPU, only one task
is said to be running at any point in time, meaning that the CPU is actively executing instructions
for that task. Multitasking solves the problem by scheduling which task may be the one running
at any given time, and when another waiting task gets a turn. The act of reassigning a CPU from
Multiprocessing: Multiprocessing is a generic term for the use of two or more central processing
units (CPUs) within a single computer system. There are many variations on this basic theme,
and the definition of multiprocessing can vary with context, mostly as a function of how CPUs
are defined (multiple cores on one die, multiple chips in one package, multiple packages in one
system unit, etc.). Multiprocessing sometimes refers to the execution of multiple concurrent
software processes in a system as opposed to a single process at any one instant. one task to
another one is called a context switch.
19
typically use specialized scheduling algorithms in order to provide the real-time developer with
the tools necessary to produce deterministic behavior in the final system. An RTOS is valued
more for how quickly and/or predictably it can respond to a particular event than for the given
amount of work it can perform over time. Key factors in an RTOS are therefore minimal
interrupt latency and a minimal thread switching latency. An early example of a large-scale real-
time operating system can be identified in the some Airline reservation operating in Nigeria and
overseas such as Transaction Processing Facility developed by American Airlines and IBM for
the Sabre Airline Reservations System. Others may be found in some communication companies
20