11computer Science - Boolean Logic and Insight Into Program Execution-Notes
11computer Science - Boolean Logic and Insight Into Program Execution-Notes
COMPUTER SCIENCE
BOOLEAN LOGIC
AND
INSIGHT INTO PROGRAM EXECUTION
NOTES
BOOLEAN ALGEBRA
Introduction
X NOT Y OR Z
Y AND Z OR X
Logical Operations
– Before proceeding for Operations, we will get to know some features of
logic statements. For ex -
Statement– 1: I want to have tea
Statement – 2: Tea is ready.
now, develop a table with all its aspects.
X Y R
1 1 1
1 0 0
0 1 0
0 0 0
Logical Operators (NOT)
NOT operator is represented by applying ( ‘ ) or ( ¯ ) on an expression. For ex-
X’ or X. This is a unary operator also known as complementation operator.
- 0’ = 1 and 1’ = 0
- Truth table and Venn Diagram for NOT operator is as under-
X X’
0 1
1 0
X Y X.Y
0 0 0
0 1 0
1 0 0
1 1 1
Logical Operators (OR)
X Y X+Y
0 0 0
0 1 1
1 0 1
1 1 1
X X’
Low High
High Low
X X’
0 1
1 0
OR Gate
X Y X+Y
Low Low Low
Low High High
High Low High
High High High
X Y X+Y
0 0 0
0 1 1
1 0 1
1 1 1
AND Gate
– AND gate takes two or more inputs and produces one output.
– Its output is logical multiplication of passed inputs.
– It produces low voltage output on any of the input signal as low voltage
input. It produces high voltage output only when all the inputs are of
high voltage.
– AND Gate Truth table and diagram are as under-
X Y X .Y
Low Low Low
Low High Low
High Low Low
High High High
X Y X.Y
0 0 0
0 1 0
1 0 0
1 1 1
Boolean logic Basic Postulates
– Boolean algebra is a kind of mathematical system because of which
it is based on some fundamental laws which are known as basic
postulates. Which are as follows- -
I. If X ≠ 0 then X = 1 and if X ≠ 1 then X = 0
II. OR Relations (logical addition)
0+0=0
0+1=1
1+0=1
1+1=1
III. AND Relations (logical multiplication)
0.0=0
0.1=0
1.0=0
1.1=1
IV. Complementary Rules:
0’ = 1
1’ = 0
X Y F
0 0 1
0 1 0
1 0 0
1 1 0
NAND Gate
There is two or more input signals and one output signal in NAND gate.if all
input signals are 1 (high) then output signal will be 0 (low). It is also known as
universal gate because fundamental gates can be retrieved with its help
X Y F
0 0 1
0 1 1
1 0 1
1 1 0
XOR Gate
XOR Gate produces 1 (high) when inputs are not at equal logic level. It is also
known as universal gate because fundamental gates can be retrieved with its
help.
No of X Y F
1’s
Even 0 0 0
Odd 0 1 1
Odd 1 0 1
Even 1 1 0
XNOR Gate
XNOR Gate produces 1 (high) when the inputs are identical (both 1’s or
both 0’s).
No of X Y F
1’s
Even 0 0 1
Odd 0 1 0
Odd 1 0 0
Even 1 1 1
Introduction
–As we know that computer works on machine level language which is not
understandable to a programmer, similarly programmer works with a language
which is not understandable by a computer system. When a programmer writes
a program in any high-level language it is called source code.
–Programmer uses a specific language to write a program like – C, C++, Java
etc. These languages are not directly understandable by computer system.
–Therefore, it is required to convert the instructions written in programmer’s
language into machine level language.
–In this chapter, we will have a look of internal processing of a program code,
how a program reaches to execution state and what are the contributions of an
operating system in all these processes.
Compilation
Compiler takes source code and, in few stages, generates low- level-code.
Compilation process stages are-
1. Processing
2. Compilation
I. Analysis [ front end phase]
II. Synthesis [ back end phase]
3. Assembly
4. Linking
5. Loader
1. Processing
This stage removes code other than source code like comments and adds the
code which is necessary for the execution of a program.
2. Compilation
Compilation phase has two sub stages-
1. Analysis [ front end phase]
I. Synthesis [ back end phase]
(i) Analysis Phase: Analysis phase develops a symbol table by all the tokens
of source code.
(ii) Synthesis Phase: This phase creates a syntax tree after parsing the source
code. A syntax tree is a syntactic tree of source code.
For ex- syntax tree of 4 * 5 + 9 will be like as -
3. Assembly Phase
This phase develops object code with the help of instructions received from
assembly level, an object code is a kind of machine code.
4. Linking
This code generated from this phase is actually binary code but still computer is
not able to execute the code because the important libraries required for
execution are still not linked with the code. This work is carried out by linker.
In this phase, operating system resolves all memory references and develops
executable (.exe file) file.
5. Loader
– Loader is a part of compiler which loads an executable file in memory.
– Now computer can run this executable file without the help of any
additional software.
Input It takes the whole program for It takes one line as input.
input.
Output It develops a middle object code It does not create middle object
of the program. code.
Memory This process requires much This process does not require much
memory. memory.
Errors It shows all errors together with It continues by showing error from
line number. one line at a time.
Always After sucessful compilation of a For every run of the prgram
Required program, compiler is not further interpreter is needed even after
needed. successful interpretation.
Workload It decreases workload because It’s continues requirement increases
compiler is not needed again workload.
and again for a program.
OS as a Resource Manager
– A program, in its static state is known as a program and in running state it
is known as process.
• Process Management
• Process Scheduling
• Memory Management
• I/O Management