Uniit 1
Uniit 1
Secondary
Data Storage
Input Unit Information
Output Unit
Primary
Storage
Control Unit
Arithmatic
Data Flow
&Logical
Unit (ALU)
Control Flow
A compiler is a program that converts the entire source code of An interpreter takes a source program and runs it line by line,
a programming language into executable machine code for a CPU. translating each line as it comes to it.
The compiler takes a large amount of time to analyze the entire source
An interpreter takes less amount of time to analyze the source code but
code but the overall execution time of the program is comparatively
the overall execution time of the program is slower.
faster.
The compiler generates the error message only after scanning the
Its Debugging is easier as it continues translating the program until the
whole program, so debugging is comparatively hard as the error can be
error is met.
present anywhere in the program.
For Security purpose compiler is more useful. The interpreter is a little vulnerable in case of security.
It generates executable files of a source file. It loads executable files to the main memory.
The linker takes input of object code generated by And the loader takes input of executable files generated by
compiler/assembler. linker.
Linking can be defined as process of combining various Loading can be defined as process of loading executable
pieces of codes and source code to obtain executable code. codes to main memory for further execution.
Another use of linker is to combine all object modules. It helps in allocating the address to executable codes/files.
Linker is also responsible for arranging objects in program’s Loader is also responsible for adjusting references which are
address space. used within the program.
Algorithm
• A set of finite rules or instructions to be followed in calculations or
other problem-solving operations
Characteristics of Algorithm
Cont..
• Unambiguous: The algorithm should be unambiguous and clear. Each
of its steps should be clear in all aspects and must lead to only one
meaning.
• Inputs: It should have 0 or more well-defined inputs.
• Outputs: An algorithm should have 1 or more well defined outputs
and should match the desired output.
• Finite-ness: The algorithm must be finite, i.e. it should terminate after
a finite time.
• Feasible: The algorithm must be simple, generic, and practical, such
that it can be executed with the available resources.
• Language Independent: An algorithm should have step by step
directions , which should be independent of any programming
language.
Algorithm to add 3 numbers and print their
sum
1.START
2.Declare 3 integer variables num1, num2, and num3.
3.Take the three numbers, to be added, as inputs in variables num1, num2,
and num3 respectively.
4.Declare an integer variable sum to store the resultant sum of the 3 numbers.
5.Add the 3 numbers and store the result in the variable sum.
6.Print the value of the variable sum
7.END
Flowchart
• A flowchart is a graphical representation of an algorithm.
• Advantages
• It shows the logic of the system.
• It provides the blueprint of the program.
• It helps in the debugging process.
• It helps in analyzing the program.
• It provides better documentation.
• Easy to trace errors in the software.
• Easy to understand.
Disadvantage
• It is difficult to draw flowcharts for large and complex programs.
• There is no standard to determine the amount of detail.
• Difficult to reproduce the flowcharts.
• It is difficult to modify the flowchart.
• Making a flowchart is costly.
• It makes software processes slow.
• If changes are done in software, then the flowchart must be redrawn
Input two numbers from the user and display the largest of two numbers
Difference
Algorithm Flowchart
In the algorithm, plain text is used. In the flowchart, symbols/shapes are used.
The algorithm does not follow any rules. The flowchart follows rules to be constructed.
The algorithm is the pseudo-code for the program. A flowchart is just a graphical representation of that logic.
Pseudocode
• A Pseudocode is defined as a step-by-step description of an algorithm.
• It does not use any programming language instead it uses the simple
English language text as it is intended for human understanding rather
than machine reading.
• It is the intermediate state between an idea and its
implementation(code) in a high-level language.
Source Code
• It is the original code written by developers using a programming
language.
• Readable by humans, written in high-level programming languages,
requires translation into machine code.
• Primary form of code created by developers.
Assignment
Q1. Write the difference between RAM and ROM.
Q2. Write the difference between SRAM and DRAM.
Q3. Write the difference between Primary memory and Secondary
memory.
Q4. Write the difference between object code and executable code.
Q5. Write an algorithm that takes two input x and y from the user and if
x>y then find the product of the numbers or else find the sum of the
numbers and display the output.