Lecture 6 - Fundamentals of Computing
Lecture 6 - Fundamentals of Computing
Computer Programming
Lecture #6
Fundamentals of Computing
Monsoon 2024
Amit Praseed, Saleena N, Santosh Kumar Behera
CSED NITC
Outline
• Fundamentals
• Hardware
• Software
• Logical Units
• Program
• Programming Languages
• Programming
• Program execution
2
Hardware
3
Software - Programs
• Word Processor
• Browser
• Search Engine
• Operating System
• ………
4
Software contd.
5
Logical Units
Logical Units
• Input Unit
• Output Unit
• Memory Unit
• Central Processing Unit (CPU)
• Secondary Storage Unit
7
Logical Units
• Input Unit
• Input data and programs
• keyboard, mouse, touch screens, devices for audio/ video, image inputs …
• Output Unit
• Output the processed information
• screen, printer, audio/video output …
8
Logical Units contd.
• Memory Unit
• Stores program and data
• Primary memory / Main Memory
• RAM (Random Access Memory)
• volatile
• read / write
• ROM (Read Only Memory)
9
Logical Units contd.
10
Logical Units contd.
11
Program
Program
13
Program
14
Instruction
15
Programming Languages
• Low level languages
• Machine dependent
• Machine Language
• Assembly language
• High-level language
• Machine independent
• C, C++, Java, Python …
16
Programming
Programming
• Writing
• Compiling
• Executing (running)
• Testing
• Debugging
18
Programming
• Writing
• Typing a program using an editor
• Compiling
• Translating the program to object code (the code that machine can
understand)
• Executing (running)
• Performing the operation specified in each instruction of the program
19
Programming
• Testing
• Checking if the program does what it is supposed to do
• Debugging
• Resolving bugs (errors) in the program
20
Program Execution
Program Execution
• Memory contains
• set of instructions in the program
• data items
• Operation specified in each instruction is performed
22
Runtime Memory Layout
Program Area
Data Area
23
Runtime Memory Layout
Instruction 1
Program Area
Instruction 2
........
Data1
Data2 Data Area
………
24
Programming Languages
• Low-Level languages – machine dependent
• Machine Language
• elementary operations represented by bit strings (strings of 1s and 0s)
• Assembly language
• elementary operations represented by mnemonics (like load, add, store)
• Assembler – a program to translate assembly code to equivalent code in machine
language
• High-level language – machine independent
• Examples - C, C++, Java, Python …
• Compiled / Interpreted
25
Compiled vs. Interpreted
• Compiler
• translates HLL program (source code) to machine language code (target code)
• often to assembly language code
• different compilers for different machines
• Interpreter
• executes HLL programs directly
• converts the program to some intermediate representation
26
HLL program translation
a = b + c;
Meaning: add together values in the memory locations b and c, store the result in
location a
Primitive operations
• Load value from location b to register1
• Load value from location c to register2
• Add values in register1, register2
• Store the result in location a
Note: Registers are storage units in CPU for holding the operands and results of operation being executed
27
Code Generated (hypothetical machine)
a = b + c; load R1, b
load R2, c
add R1, R2
store a, R1
28
C Programming - phases
C Programming - phases
• Writing a program
• Preprocessing and Compiling
• Linking
• Loading
• Execution
• Testing
• Debugging
30
Programming
• Write a program
•Type in the program using an editor
• Store (save) the program as a file
• file name with extension .c (example: sample.c)
• Compile the program
• translate the program to machine understandable form
• Execute (run) the program
31
Writing a C program
• Editing a program in an editor
• some popular editors used in Linux - vi, emacs, gedit
• Integrated Development Environments (IDEs) like eclipse provide editor and
other tools required for compilation, debugging etc.
• Store (save) the program (source code) as a file in a secondary storage
device
• file name with extension .c (sample.c)
32
Programming in the Linux environment
• text editors - vi, emacs, gedit …
33
Preprocessing and Compiling
• Compiler translates C program to machine code (also known as object
code)
• Compilation command invokes a preprocessor before translation
begins
• Preprocessor acts based on the preprocessor directives
• e.g.: #include <stdio.h>
• Does modifications in the source code, like inserting contents from other files
• The preprocessed source code is translated to object code
• Compiler detects and reports some of the errors
• Syntax errors like missing semicolon – compile time errors
34
Linking
• Linker
• program that links together multiple object files to create an executable
in Linux, the executable is named a.out (by default)
• C programs typically use functions defined in other files
• standard library functions - e.g. printf(), scanf()
• Command gcc compiles and links
35
Loading
• Loader
• loads the executable from secondary storage to memory
• in Linux, ./a.out loads and executes the program
36
Errors
• Compile time errors
• Compiler detects and reports some of the errors
• Syntax errors like missing semicolon
• variables used without declaration
37
Historical Developments
Historical Developments
• Early developments
• mechanical devices for automating arithmetic computations
• Charles Babbage’s designs
• 1820s - Difference Engine
• 1830s - Analytical Engine
• Similar in design to a modern computer
• Couldn’t complete a working model
39
Historical Developments contd.
• Early Computers
• programmed externally using wires, connectors and plug boards
• memory unit stored only data, not instructions
• The stored program computer
• Model proposed by John Von Neumann in 1946
• Von Neumann Architecture- instructions encoded in binary, stored in memory along with
data
• invented programming
• EDVAC (1949) – one of the first stored program computer
• 1950s
• computers built for sale - UNIVAC I, IBM 701
• first High level programming languages - FORTRAN, COBOL
40
Historical Developments contd.
• Early computers
• bulky, expensive, slow and unreliable
• vacuum tubes for processing and storage, punched cards for I/O
• Technology changes caused reduction in size and cost, and increase in processing
speed
• Late 1950s - transistors replaced vacuum tubes
• 1965-75 - Integrated circuits – several electronic components etched onto a
piece of silicon
• minicomputers
• 1975-85 - complete computer system on a single circuit board
• microcomputers – desktop machines
41
Historical Developments - self study
• Developments during World War II
• Contributions of Alan Turing
• ENIAC
42
C programming Language
• Originally developed in the Bell Labs for the UNIX operating system by
Dennis Ritchie in the early 1970s
• the OS, the C compiler, and UNIX applications were written in C
• Standard C (1989) / ANSI C
• approved by ANSI (American National Standards Institute) and ISO
(International Standards Organization)
• revisions – C99, C11, C17, C23 (expected to be published in 2024)
• Popular
• second most popular language as per TIOBE index (Aug ‘24)
43