System programming (or systems programming) is the activity of programmingsystem software. The primary distinguishing characteristic of systems programming when compared to application programming is that application programming aims to produce software which provides services to the user (e.g. word processor), whereas systems programming aims to produce software which provides services to the computer hardware (e.g. disk defragmenter). It also requires a greater degree of hardware awareness.
In system programming more specifically:
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)
usually a low-level programming language or programming language dialect is used that:
allows for direct and "raw" control over memory access and control flow
lets the programmer write parts of the program directly in assembly language
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.
Systems programming is sufficiently different from application programming that programmers tend to specialize in one or the other.
In system programming, often limited programming facilities are available. The use of automatic garbage collection is not common and debugging is sometimes hard to do. The runtime library, if available at all, is usually far less powerful, and does less error checking. Because of those limitations, monitoring and logging are often used; operating systems may have extremely elaborate logging subsystems.
Implementing certain parts in operating system and networking requires systems programming (for example implementing Paging (Virtual Memory) or a device driver for an operating system).
A utility program called an assembler is used to translate assembly language statements into the target computer's machine code. The assembler performs a more or less isomorphic translation (a one-to-one mapping) from mnemonic statements into machine instructions and data. (This is in contrast with high-level languages, in which a single statement generally results in many machine instructions.)
Many sophisticated assemblers offer additional mechanisms to facilitate program development, control the assembly process, and aid debugging. In particular, most modern assemblers (although many have been available for more than 40 years already) include a macro facility (described below), and are called macro assemblers.
Typically a modern assembler creates object code by translating assembly instruction mnemonics into opcodes, and by resolving symbolic names for memory locations and other entities.[1] The use of symbolic references is a key feature of assemblers, saving tedious calculations and manual address updates after program modifications. Most assemblers also include macro facilities for performing textual substitution—e.g., to generate common short sequences of instructions to run inline, instead of in a subroutine.
High-level procedure/function declarations and invocations
High-level abstract data types, including structures/records, unions, classes, and sets
Sophisticated macro processing
Object-Oriented features such as encapsulation, polymorphism, inheritance, interfaces
Current usage
There have always been debates over the usefulness and performance of assembly language relative to high-level languages. Assembly language has specific niche uses where it is important; see below. But in general, modern optimizing compilers are claimed to render high-level languages into code that can run as fast as hand-written assembly, despite some counter-examples that can be created. The complexity of modern processors makes effective hand-optimization increasingly difficult.[6] Moreover, and to the dismay of efficiency lovers, increasing processor performance has meant that most CPUs sit idle most of the time, with delays caused by predictable bottlenecks such as I/O operations and paging. This has made raw code execution speed a non-issue for most programmers.
Here are some situations in which practitioners might choose to use assembly language:
When a stand-alone binary executable is required, i.e. one that must execute without recourse to the run-time components or libraries associated with a high-level language; this is perhaps the most common situation. These are embedded programs that store only a small amount of memory and the device is intended to do single purpose tasks. Such examples consist of telephones, automobile fuel and ignition systems, air-conditioning control systems, security systems, and sensors.
When interacting directly with the hardware, for example in device drivers.
When using processor-specific instructions not exploited by or available to the compiler. A common example is the bitwise rotation instruction at the core of many encryption algorithms.
When extreme optimization is required, e.g., in an inner loop in a processor-intensive algorithm. Some game programmers are experts at writing code that takes advantage of the capabilities of hardware features in systems enabling the games to run faster.
When a system with severe resource constraints (e.g., an embedded system) must be hand-coded to maximize the use of limited resources; but this is becoming less common as processor price/performance improves
When no high-level language exists, e.g., on a new or specialized processor
Real-time programs that need precise timing and responses, such as simulations, flight navigation systems, and medical equipment. (For example, in a fly-by-wire system, telemetry must be interpreted and acted upon within strict time constraints. Such systems must eliminate sources of unpredictable delays – such as may be created by interpreted languages, automatic garbage collection, paging operations, or preemptive multitasking. Some higher-level languages incorporate run-time components and operating system interfaces that can introduce such delays. Choosing assembly or lower-level languages for such systems gives the programmer greater visibility and control over processing details.)
When complete control over the environment is required (for example in extremely high security situations, where nothing can be taken for granted).
When reverse-engineering existing binaries, which may or may not have originally been written in a high-level language, for example when cracking copy protection of proprietary software.
Reverse engineering and modification of video games (known as ROM Hacking), commonly done to games for Nintendo hardware such as the SNES and NES, is possible with a range of techniques, of which the most widely employed is altering the program code at the assembly language level.
Assembly language lends itself well to applications requiring Self modifying code.
Finally, compiler writers usually write software that generates assembly code, and should therefore be expert assembly language programmers themselves.
Nevertheless, assembly language is still taught in most Computer Science and Electronic Engineering programs. Although few programmers today regularly work with assembly language as a tool, the underlying concepts remain very important. Such fundamental topics as binary arithmetic, memory allocation, stack processing, character set encoding, interrupt processing, and compiler design would be hard to study in detail without a grasp of how a computer operates at the hardware level. Since a computer's behavior is fundamentally defined by its instruction set, the logical way to learn such concepts is to study an assembly language. Most modern computers have similar instruction sets. Therefore, studying a single assembly language is sufficient to learn: i) The basic concepts; ii) To recognize situations where the use of assembly language might be appropriate; and iii) To see how efficient executable code can be created from high-level languages.
Typical applications
Hard-coded assembly language is typically used in a system's boot ROM (BIOS on IBM-compatible PC systems). This low-level code is used, among other things, to initialize and test the system hardware prior to booting the OS, and is stored in ROM. Once a certain level of hardware initialization has taken place, execution transfers to other code, typically written in higher level languages; but the code running immediately after power is applied is usually written in assembly language. The same is true of most boot loaders.
Many compilers render high-level languages into assembly first before fully compiling, allowing the assembly code to be viewed for debugging and optimization purposes. Relatively low-level languages, such as C, often provide special syntax to embed assembly language directly in the source code. Programs using such facilities, such as the Linux kernel, can then construct abstractions utilizing different assembly language on each hardware platform. The system's portable code can then utilize these processor-specific components through a uniform interface.
Assembly language is also valuable in reverse engineering, since many programs are distributed only in machine code form, and machine code is usually easy to translate into assembly language and carefully examine in this form, but very difficult to translate into a higher-level language. Tools such as the Interactive Disassembler make extensive use of disassembly for such a purpose.
A particular niche that makes use of assembly language is the demoscene. Certain competitions require the contestants to restrict their creations to a very small size (e.g. 256B, 1KB, 4KB or 64 KB), and assembly language is the language of choice to achieve this goal.[9] When resources, particularly CPU-processing constrained systems, like the earlier Amiga models, and the Commodore 64, are a concern, assembler coding is a must: optimized assembler code is written "by hand" and instructions are sequenced manually by the coders in an attempt to minimize the number of CPU cycles used; the CPU constraints are so great that every CPU cycle counts. However, using such techniques has enabled systems like the Commodore 64 to produce real-time 3D graphics with advanced effects, a feat which might be considered unlikely or even impossible for a system with a 0.99MHz processor.
Q1. Explain the flowchart of pass-2 of a two pass assembler.
Q7) Design a two pass assembler with the help of neat flowcharts.
Q8) Minimize the following switching functions : (a) What is conditional macro-expansion? Explain. (b) What is the difference betwen binders and overlays? Define dynamic loading.
Q9) Differentiate between the following : (a) Interpreter and compiler. (b) Top down and bottom down parsing. (c) Single pass anf two pass assemblers
Dec 2007 Punjab Technical University B.Tech Information Technology SYSTEM PROGRAMMING (CS210),Information and technology Question paper
Information and technology B.TECH (SEMESTER – 4TH ) SYSTEM PROGRAMMING (CS210)
Time: 03 Hours Max marks: 60 Instruction to candidates: 1) Section –A is compulsory. 2)Attempt any four question from section-B 3) Attempt any two questions from section-C
Section -A Q1) (marks 10*2=20) a) What is window editor? b) What is vi editor? c) What is Bug? d) What is code generation? e) Define time sharing. f) What is meaning of finite automata? g) What are sub routines? h) What is lexical analysis? i) What is assembly language? j) What is booting?
Section-B(marks 4*5=20)
Q2) What is the difference between the lexical analysis and syntax analysis? Q3) Explain intermediate code generation. Q4) Explain code optimization technique. Q5) Explain different types of compilers
. Q6) explain case study of linker in x86 machines
Section-C (marks 2*10=20)
Q7) Explain various debugging techniques. Q8) What is linking? What is the use of linking explain briefly? Q9) What is operating systems
? Explain various operating systems briefly. a) What is protocol? b) Hat is error diction? c) What is subnet?
SYSTEM PROGRAMMING CS 210 4th Sem May 2k5
Max Marks 60
Note: Section A is compulsory. Attempt any Four questions from Section B and 2 from Section C.
Section A Marks 2 each
1. (a) What data structure is used for assembler pass one? (b) Illustrate the problems of two pass assembly. (c) What are the features of machine-independent macro processor? (d) Explain the purpose of the Segment index field in an LEDATA record. (e) How does Dynamic Linking work for Subroutine? (f) What fare the Debugging Functions and Capabilities? (g) Compare structure editors and screen editors. (h) Which are the tow ways of Code Optimization? Explain. (i) Compare code generation actions and code generation routine. (j) Can swapping be used in multiprogramming systems? Explain.
Section B Marks 5 each
2. Develop complete program for the passes of two pass assemblers indicating: (a) Inputs (files and tables) for every pass (b) Outputs (files and tables) for every pass.
3. On some systems, control sections can be composed of several different parts just as program blocks can. What problems does this pose for the assembler? How might these problems be solved?
4. Suppose we want macro definition to appear as a part of the assembly listing. How could the macro processor and the assembler accomplish this?
5. Define binary object format for SICF and write an absolute loader to load program in this format.
6. consider the following possibilities for the storage, linking and execution of a user’s program: (a) Store the source and object versions of the program, use linking loader each time the program is to be executed. (b) Solve the source program and linked version with all externals references resolved. Use a relocating loader each time the program is to be executed.
Section C
7. (a) What kind of source program errors would be detected using Lexical analysis? (b) What kind of source program errors would be detected during Syntactic analysis?
8. Select a high level programming language with which you are familiar and write a lexical scanner for it.
9. (a) Is memory-protection hardware necessary of a machine that uses demand-paged memory management? Justify your answer. (b) How might the operating system detect that a deadlock has occurred? Write the methods to prevent deadlock situation.
A compiler is a computer program (or set of programs) that transforms source code written in a computer language (the source language) into another computer language (the target language, often having a binary form known as object code). The most common reason for wanting to transform source code is to create an executable program.
The Basic Structure of a Compiler
The five stages of a compiler combine to translate a high level language to a low level language, generally closer to that of the target computer. Each stage, or sub-process, fulfills a single task and has one or more classic techniques for implementation.
Component
Purpose
Techniques
Lexical Analyzer
Analyzes the Source Code
Removes "white space" and comments Formats it for easy access (creates tokens)
Tags language elements with type information
Begins to fill in information in the SYMBOL TABLE **
Analyzes the Parsed Code for meaning
Fills in assumed or missing information
Tags groups with meaning information
Attribute Grammars
Ad hoc analyzers
Code Generator
Linearizes the Qualified Code and produces the equivalent Object Code
Generally completed by hand-written code
Optimizer
Examines the Object Code to determine whether there are more efficient means of execution
Common-subexpression elimination
Loop unrolling
Operator reduction
etc.
** The Symbol Table is the data structure that all elements of the compiler use to collect and share information about symbols and groups of symbols in the program being translated.
*Alternative* Answer:-
Question -How does a language compiler work?For example, what is
the mechanism behind the compiling process of a program in a specific
language?
The question was about compilers, so I will explain how a compiler works,
rather than the process of converting a source program into an executable
program.The first question involves only a compiler, while in the second
process, a compiler is only one of the programs involved.
A compiler for a language generally has several different stages as it
processes the input.
These are:
1. Preprocessing
2. Lexical analysis
3. Syntactical analysis
4. Semantical analysis
5. Intermediate code generation
6. Code optimization
7. Code generation
Most of theses stages occur during a single pass or reading of the source
files.In other words, for example, the preprocessing stage is usually
reads only slightly ahead of the lexical analysis stage, which is usually
one world ahead of the syntactical analysis stage.
1.Preprocessing
During the preprocessing stage, comments, macros, and directives are
processed.
Comments are removed from the source file.This greatly simplifies the
later stages.
If the language supports macros, the macros are replaced with the equivalent
text.
For example, C and C++ support macros using the #define directive.So if a
macro were defined for pi as:
#define PI 3.1415927
Any time the preprocessor encountered the word PI, it would replace PI with
3.1415927 and process the resulting text.
The preprocessor also handles preprocessor directives.These are most often
include statements.In C and C++, an include statement looks like either:
#include
#include "file"
These lines are replaced by the actual file and the resulting text
processed.
The preprocessor may also replace special strings with other characters.In
C and C++, the preprocessor recognizes the \ character as an escape code,
and will replace the escape sequence with a special character.For example
\t is the escape code for a tab, so \t would be replaced at this stage with
a tab character.
2.Lexical analysis is the process of breaking down the source files into
key words, constants, identifiers, operators and other simple tokens.A
token is the smallest piece of text that the language defines.
A. Key words are words the language defines, and which always have specific
meaning in the language.In C and C++ some of these key words are:
if
else
int
char
do
while
for
struct
return
B. Constants are the literal valued items that the language can recognize.
Often these are numbers, strings, and characters:
i. Numbers are the types of numbers that may be used in expressions:3.14,
5, 12, 0.But, usually negative numbers (-17) are processes as an operator
(-) and a number (17)
ii. Strings are text items the language can recognize.In C or C++ a string
is enclosed by double quotes:"This is a string"
iii. Characters are single letters.In C or C++, a character is enclosed by
single quotes: 'c'
C. Identifiers are names the programmer has given to something.These
include variables, functions, classes, enumerations, etc.Each language has
rules for specifying how these names can be written.
D. Operators are the mathematical, logical, and other operators that the
language can recognize.Each language generally has the standard operators
+, -, *, /, and often defines many other operators as well.For example
some of the additional C and C++ define are:
% modulo
-- decrement
++ increment
E. Other tokens are things not covered by any of the above items.Often
these will produce errors, but depending on the compiler, things like
{ ( ) } may be valid in the language, but not treated as a key word or
operator.
3. Syntactical analysis is the process of combining the tokens into
well-formed expressions, statements, and programs.Each language has
specific rules about the structure of a program--called the grammar or
syntax.Just like English grammar, it specifies how things may be put
together.In English, a simple sentence is: subject, verb, predicate.
In C or C++ an if statement is:
if ( expression ) statement
The syntactical analysis checks that the syntax is correct, but doesn't
enforce that it makes sense.In English, a subject could be:Pants,the
verb: are, the predicate: a kind of car.This would yield: Pants are a kind
of car.Which is a sentence, but doesn't make much sense.
In C or C++, a constant can be used in an expression: so the expression:
float x = "This is red"++
Is syntactically valid, but doesn't make sense because a float number can
not have string assigned to it, and a string can not be incremented.
4. Semantic analysis is the process of examining the types and values of the
statements used to make sure they make sense.During the semantic
analysis, the types, values, and other required information about statements
are recorded, checked, and transformed as appropriate to make sure the
program makes sense.
For C/C++ in the line:
float x = "This is red"++
The semantic analysis would reveal the types do not match and can not be
made to match, so the statement would be rejected and an error reported.
While in the statement:
float y = 5 + 3.0;
The semantical analysis would reveal that 5 is an integer, and 3.0 is a
double, and also that the rules for the language allow 5 to be converted to
a double, so the addition could be done, so the expression would then be
transformed to a double and the addition performed.Then, the compiler
would recognize y as a float, and perform another conversion from the double
8.0 to a float and process the assignment.
5. Intermediate code generation
Depending on the compiler, this step may be skipped, and instead the program
may be translated directly into the target language (usually machine object
code).If this step is implemented, the compiler designers also design a
machine independent language of there own that is close to machine language
and easily translated into machine language for any number of different
computers.
The purpose of this step is to allow the compiler writers to support
different target computers and different languages with a minimum of effort.
The part of the compiler which deals with processing the source files,
analyzing the language and generating the intermediate code is called the
front end, while the process of optimizing and converting the intermediate
code into the target language is called the back end.
6. Code optimization
During this process the code generated is analyzed and improved for
efficiency.The compiler analyzes the code to see if improvements can be
made to the intermediate code that couldn't be made earlier.For example,
some languages like Pascal do not allow pointers, while all machine
languages do.When accessing arrays, it is more efficient to use pointers,
so the code optimizer may detect this case and internally use pointers.
7. Code generation
Finally, after the intermediate code has been generated and optimized, the
compiler will generated code for the specific target language.Almost
always this is machine code for a particular target machine.
Also, it us usually not the final machine code, but is instead object code,
which contains all the instructions, but not all of the final memory
addresses have been determined.
A subsequent program, called a linker is used to combine several different
object code files into the final executable program.