P
ROLL NO. - 520791371
ASSIGNMENT 2
SUBJECT - MC0073
SYSTEM PROGRAMMING
Ans:
When a program needs to be executed, the OS first extracts all relevant file
information (usually from the file header), and carries out any necessary actions before
putting it into memory; in other words the OS simply decodes the object file into an
understandable form in memory.
program.
Computer program that transfers data from offline memory into internal storage.
This is the definition of Loader.
An operating system utility that copies programs from a storage device to main
memory, where they can be executed.
memory, the loader can also replace virtual addresses with physical addresses. Most
loaders are transparent, i.e., we cannot directly execute them, but the operating system
uses them when necessary.
A binary object file is either an executable file that runs on a particular machine or
a file containing object code that needs to be linked. The object code or executable
code is generated by a compiler or by an assembler.
A) Design of an Absolute Loader:
As the example loader does not need to perform functions such as linking and
program relocation, its operation is very simple. All functions are accomplished in a
single pass. The Header record is checked to verify that the correct program has been
presented for loading (and that it will fit into the available memory). As each Text record
is read, the object code it contains moved to the indicted address in memory. When the
End record is encountered, the loader jumps to the specified address to begin execution
of the loaded program.
Each pair of bytes from the object program record must be packed together into
one byte during loading.
program record. On the other had, each printed character represents one hexadecimal
digit in memory ie, a half byte.
with each byte of object code stored as a single byte in the object program.
Program:
Begin
Read Header record
Verify program name and length
Read first Text record
While record type <> E do
Begin
(if the object code is in character form, convert into internal representation)
Move object code to specified memory
Read next object program record
End
Jumps to address specified in End record
end
B) A Simple Bootstrap Loader
A very small program (usually residing in ROM) which reads a fixed location on a
disk (ex. The MBR) and passes control over to it.
location is, in general, slightly bigger and more sophisticated,a nd it then takes
responsibility for loading the actual operating system and passing control to it.
Source
Program
Compiler
Target
Program
Error
Messages
There are 6 phases a typical compiler will implement. The major reason
why separate a compiler into 6 phases is probably simplicity.
Compiler design is thus full of ``Divide and Conquer'' strategy,
component-level design, reusabililty and performance optimization.
Lexical Analysis
Syntax Analysis
Error Recovery
Scope Analysis
Type Analysis
Out
Target
Program
into
subsequences
called
tokens. The syntax analysis phase, called parser, reads tokens and validates them in
accordance with a grammar. Vocabulary, i.e., a set of predefined tokens, is composed of
word symbols (reserved words), names (identifiers), numerals (constants), and special
symbols (operators). During compilation, a compiler will find errors such as lexical,
syntax, semantic, and logical errors. If a token is found not belonging to the vocabulary,
it is an lexical error. A grammar dictates the syntax of a language. If a sentence does not
follow the syntax, it is called a syntax error. Semantic errors is like assigning an integer
to a double vaiable! Logical errors simply refer to the program logic is not correct, even
though it is syntactically and semantically correct!
B) Editors
C) Debuggers
D) Interpreters
A) Compilers
A compiler is a computer program (or set of programs) that transforms source code
written in a programming 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 name "compiler" is primarily used for programs that translate source code from a
high-level programming language to a lower level language (e.g., assembly language or
machine code). A program that translates from a low level language to a higher level one
is a decompiler. A program that translates between high-level languages is usually called
a language translator, source to source translator, or language converter. A language
rewriter is usually a program that translates the form of expressions without a change of
language.
A compiler is likely to perform many or all of the following operations: lexical analysis,
preprocessing, parsing, semantic analysis, code generation, and code optimization.
Program faults caused by incorrect compiler behavior can be very difficult to track down
and work around and compiler implementors invest a lot of time ensuring the
correctness of their software.
The term compiler-compiler is sometimes used to refer to a parser generator, a tool
often used to help create the lexer and parser.
Structure of compiler
Compilers bridges source programs in high-level languages with the underlying
hardwares. A compiler requires 1) to recognize legitimacy of programs, 2) to generate
correct and efficient code, 3) run-time organization, 4) to format output according to
assembler or linker conventions. A compiler consists of three main parts: frontend,
middle-end, and backend.
Frontend checks whether the program is correctly written in terms of the programming
language syntax and semantics. Here legal and illegal programs are recognized. Errors
are reported, if any, in a useful way. Type checking is also performed by collecting type
information. Frontend generates IR (intermediate representation) for the middle-end.
Optimization of this part is almost complete so much are already automated. There are
efficient algorithms typically in O(n) or O(nlog n).
Middle-end is where the optimizations for performance take place. Typical
transformations for optimization are 1) removal of useless or unreachable code, 2)
discovering and propagating constant values, 3) relocation of computation to a less
frequently executed place (e.g., out of a loop), 3) specializing a computation based on
the context. Middle-end generates IR for the following backend. Most optimization efforts
are focused on this part.
Backend is responsible for translation of IR into the target assembly code. The target
instruction(s) are chosen for each IR instruction. Variables are also selected for the
registers. Backend utilizes the hardware by figuring out how to keep parallel FUs busy,
filling delay slots, and so on. Although most algorithms for optimization are in NP,
heuristic techniques are well-developed.
10
somewhat slower than executing the code directly on the appropriate (or the same)
processor. Some debuggers offer two modes of operation - full or partial simulation, to
limit this impact.
When the program "crashes" or reaches a preset condition, the debugger typically
shows the position in the original code if it is a source-level debugger or symbolic
debugger, commonly now seen in integrated development environments. If it is a lowlevel debugger or a machine-language debugger it shows the line in the disassembly
(unless it also has online access to the original source code and can display the
appropriate section of code from the assembly or compilation).(A "crash" happens when
the program cannot normally continue because of a programming bug. For example, the
program might have tried to use an instruction not available on the current version of the
CPU or attempted to access unavailable or protected memory.)
Typically, debuggers also offer more sophisticated functions such as running a program
step by step (single-stepping or program animation), stopping (breaking) (pausing the
program to examine the current state) at some event or specified instruction by means of
a breakpoint, and tracking the values of some variables. Some debuggers have the
ability to modify the state of the program while it is running, rather than merely to
observe it. It may also be possible to continue execution at a different location in the
program to bypass a crash or logical error.
Hardware support for debugging
Most modern microprocessors have at least one of these features in their CPU design to
make debugging easier:
An instruction set that meets the Popek and Goldberg virtualization requirements
makes it easier to write debugger software that runs on the same CPU as the
software being debugged; such a CPU can execute the inner loops of the
program under test at full speed, and still remain under the control of the
debugger.
11
Hardware support for code and data breakpoints, such as address comparators
and data value comparators or, with considerably more work involved, page fault
hardware
Microcontrollers with as few as six pins need to use low pin-count substitutes for
JTAG, such as BDM, Spy-Bi-Wire, or DebugWire on the Atmel AVR. DebugWire,
for example, uses bidirectional signaling on the RESET pin.
List of debuggers
12
Parasoft Insure++
iSYSTEM In circuit debugger for Embedded Systems
Interactive Disassembler (IDA Pro)
Java Platform Debugger Architecture
Jinx, a whole-system debugger for heisenbugs. It works transparently as a
device driver.
JSwat open-source Java debugger
MacsBug
Nemiver graphical C/C++ Debugger for the GNOME desktop environment
OLIVER (CICS interactive test/debug) - a GUI equipped instruction set simulator
(ISS)
OllyDbg
Omniscient Debugger (Forward and backward debugger for Java)
pydbg
IBM Rational Purify
RealView Debugger - Commercial debugger produced for and designed by ARM
sdb
SIMMON (Simulation Monitor)
SIMON (Batch Interactive test/debug) - a GUI equipped instruction set simulator
(ISS) for batch
SoftICE
Software Diagnostics Developer Edition
TotalView
Turbo Debugger
Ups C, Fortran source level debugger
Valgrind
VB Watch Debugger debugger for Visual Basic 6.0
Microsoft Visual Studio Debugger
WinDbg
WinGDB - Debugging with GDB under Visual Studio. Remote Linux (via SSH),
MinGW, Cygwin, embedded systems.
Xdebug PHP debugger and profiler.
Zeta Debugger: Debugging with Visual Studio and Borland.
D) Interpreters
A program that executes instructions written in a high-level language. There are two
ways to run programs written in a high-level language. The most common is to compile
the program; the other method is to pass the program through an interpreter.
An interpreter translates high-level instructions into an intermediate form, which it then
executes. In contrast, a compiler translates high-level instructions directly into machine
language. Compiled programs generally run faster than interpreted programs. The
advantage of an interpreter, however, is that it does not need to go through the
compilation stage during which machine instructions are generated. This process can be
13
time-consuming if the program is long. The interpreter, on the other hand, can
immediately execute high-level programs. For this reason, interpreters are sometimes
used during the development of a program, when a programmer wants to add small
sections at a time and test them quickly. In addition, interpreters are often used in
education because they allow students to program interactively.
Both interpreters and compilers are available for most high-level languages. However,
BASIC and LISP are especially designed to be executed by an interpreter. In addition,
page description languages, such as PostScript, use an interpreter. Every PostScript
printer, for example, has a built-in interpreter that executes PostScript instructions.
Advantages and disadvantages of using interpreters
Programmers usually write programs in high level code which the CPU cannot execute.
So this source code has to be converted into machine code. This conversion is done by
a compiler or an interpreter. A compiler makes the conversion just once, while an
interpreter typically converts it every time a program is executed (or in some languages
like early versions of BASIC, every time a single instruction is executed).
Development cycle
During programs development the programmer makes frequent changes to source code.
A compiler needs to make a compilation of the altered source files, and link the whole
binary code before the program can be executed. An interpreter usually just needs to
translate to an intermediate representation or not translate at all, thus requiring less time
before the changes can be tested.
Distribution
An interpreted program can be distributed as source code. It needs to be translated in
each final machine, which takes more time but makes the program distribution
independent to the machine's architecture.
14
Execution environment
An interpreter will make source translations during runtime. This means every line has to
be converted each time the program runs. This process slows down the program
execution and is a major disadvantage of interpreters over compilers. Another main
disadvantage of interpreter is that it must be present on the machine as additional
software to run the program
Structure
3. Explain wiht suitable numerical examples the concepts of Moore Machine and
Mealay Machine
ANS:
Mealay Machine
In the theory of computation, a Mealy machine is a finite state transducer that generates
an output based on its current state and input. This means that the state diagram will
include both an input and output signal for each transition edge. In contrast, the output of
a Moore finite state machine depends only on the machine's current state; transitions
are not directly dependent upon input.
15
The name Mealy machine comes from that of the concept's promoter, George H. Mealy,
a state-machine pioneer who wrote "A Method for Synthesizing Sequential Circuits" in
1955.[1]
Mealy machines provide a rudimentary mathematical model for cipher machines.
Considering the input and output alphabet the Latin alphabet, for example, then a Mealy
machine can be designed that given a string of letters (a sequence of inputs) can
process it into a ciphered string (a sequence of outputs). However, although you could
use a Mealy model to describe the Enigma, the state diagram would be too complex to
provide feasible means of designing complex ciphering machines
16
Moore Machine
In the theory of computation, a Moore machine is a finite state transducer where the
outputs are determined by the current state alone (and do not depend directly on the
input). The state diagram for a Moore machine will include an output signal for each
state. Compare with a Mealy machine, which maps transitions in the machine to outputs
The number of states in a Moore machine will be greater than or equal to the number of
states in the corresponding Mealy machine. This is due to the fact that each transition in
a Mealy machine can be associated with a corresponding, additional state mapping the
transition to a single output, hence turning a possibly partial machine into a complete
machine.
17
18