1 of 23

������CSO 101 Computer Programming��Lecture 1�

IIT (BHU) CSE

2 of 23

Administrative Details

  • Lectures, Tutorials and Lab
  • Assignments – Lab, Theory
  • Mid-Sem and End-Sem Exams
  • Programs can be run online or in desktop, smartphones
  • Online – Use GNU compiler – For example look at - https://www.onlinegdb.com/online_c_compiler
  • Desktop – Install gcc compiler
  • Smartphone Apps – Coding C

3 of 23

Some History

  • Computer technology made immense progress in last 70 years - Cost of a computer in 1985 was 1 million dollars!!!
  • In 1960’s computers were stored in multiple rooms with operators overseeing their support – Used for business data processing and large-scale scientific computing
  • Microprocessors came in 1970’s
  • Desktop based microprocessors in 1980’s
  • Emergence of Internet and World Wide Web in 1990’s
  • Cellphones/smartphones (embedded computer) from 2000’s

4 of 23

5 of 23

Computer Architecture

  • Input Devices – Keyboard, Mouse
  • Output Devices – Monitor, Printer
  • Central Processing Unit (CPU)
  • Memory – Main, Secondary

CPU

Input Devices

Output Devices

Memory

6 of 23

Central Processing Unit (CPU)

  • Brains of the Computer - E.g., Intel i7
  • Decisions are made, computations are performed
  • Contains three components
  • Arithmetic Logic Unit (ALU) – Arithmetic and logical operations are performed (in binary system)
  • Control Unit (CU) – Decodes and executes the instructions
  • Register Set – Store pointers, counters, return address and other temporary data

7 of 23

Memory Unit

  • Stores program and data processed by computer
  • Types – Main, Secondary, Cache
  • Main memory – Random Access Memory (RAM)/Read Only Memory (ROM) - Temporary/Permanent – Fast access
  • Secondary memory – Hard disk, USB pen, DVD – Permanent – Slower access
  • Cache memory (Not to be confused with browser cache) – Temporary – Very fast access – Expensive
  • Note temporary/volatile means data is available only till the power is on.

8 of 23

Operating System

  • The software which runs the computer hardware

Computer hardware

Operating system

Application programs

User

9 of 23

More About Operating Systems (OS)

  • Hides the hardware architecture and instruction set
  • Provides with standard instructions to work with irrespective of the hardware
  • Acts as a resource manager – allocation and management of resources to programs
  • Core of the OS is called kernel
  • On top of this is a command line interpreter (CLI) also called shell
  • Some application programs like text editor also come together with OS

10 of 23

More About OS

  • Note application programs can directly access kernel services through system calls
  • Common system calls – read, write, open, close, wait, exec, fork, kill
  • read, write, open, close: are for files – wait: process waits for other process to complete – exec: execution of process – fork: creates a copy of itself – kill: sends termination signal to a process
  • Also provides security – kernel mode/user mode
  • Control over system performance

11 of 23

Examples of OS

  • Some examples – UNIX/Linux, Windows –
  • We also have other types like embedded OS and real-time OS
  • UNIX is a powerful multitasking, multiuser operating system – 90% of world’s fastest supercomputers
  • Closely associated with C language
  • Linux is open source (GNU), UNIX like
  • Android has Linux kernel !!

12 of 23

Operating System Functions

  • Process management

  • Memory management

  • File system management

  • Device management

13 of 23

Process Management

  • Program in execution is called process
  • Each process has an address space (a list of memory locations) used to store executable program, its data and stack
  • Scheduling of process – allocation of the processor
  • Deadlock avoidance – deadlocks are situations when two or more processes get into stalemate situation
  • OS also provides mechanism for inter-process communication

14 of 23

Memory Management

  • Deals with the main memory which has to be shared between OS and application programs
  • Keeps programs from the programs in interfering with one another
  • Management of programs address space (recall what is present in an address space?)
  • Concept of virtual memory – OS keeps part of the address space in main memory and part in secondary memory – Shuttles it back and forth as needed
  • Can you guess the need for virtual memory?

15 of 23

File system management

  • Files systems are abstract organized collection of files
  • Provides system calls to create, read, write, close, open, remove files
  • Concept of directories where files are grouped together – system calls to manage these
  • Concept of pipes related to both process and file management
  • pipe is a pseudofile that connects two processes - one can send data to another by writing into this pseudofile

16 of 23

I/O Device Management

  • Computer receives information through input and ouput devices
  • Processes access devices these using system calls
  • Some part of it is device independent and others device dependent called device drivers
  • Device driver controls/operates a particular device like keyboard or monitor – It’s’ a software interface to OS and application programs to use the device without knowing details about hardware
  • Devices are efficiently shared among requiring them
  • In UNIX I/O devices are also viewed as files!!

17 of 23

High-Level Programming Language

  • Provides strong abstraction from the details of the computer
  • Easier to use, or may automate or hide significant areas of computing systems (e.g. memory management)
  • Makes the process of developing a program simpler and more understandable relative to a lower-level language
  • Structured – code can be divided into smaller units or blocks
  • Unstructured – single continuous or unbroken block

18 of 23

Assembly Code

  • Assembly Language – Mnemonics and memory addresses
  • How it looks like?

LD Acc, #12836 ;

ADD [37846] ;

STO Acc, 45632 ;

:loop ;

19 of 23

Machine Code

Instructions are sequences of binary numbers

0010011010011001

1101010011100101

1100010101001010

0100101101010010

20 of 23

Compiler and Interpreter

  • Compiler: Translates source code from a high-level programming language to a lower level language (e.g., assembly language, object code, or machine code)

  • Interpreter:
  • It’s a computer program that directly executes
  • Performs, instructions written in a programming or scripting language without previously compiling into a machine language program

Source file Hello.c

Compiler

Executable file:

Hello.exe

21 of 23

Integrated Development Environment (IDE)

  • IDE - Software application that provides comprehensive facilities to computer programmers for software development.

  • IDE typically consists of a source code editor, build automation tools (compiler) and a debugger.

  • For C language : Code::Blocks,Visual Studio

22 of 23

Screenshot of an IDE

23 of 23

Some References for the course

  • For C Language:
  • Programming in ANSI C – Balagurusamy
  • Let Us C – Kanetkar
  • C Programming Language – Kernighan and Ritchie,
  • C in Hindi – Kuldeep Chand
  • For basics to be covered this week:
  • Online resources like geeksforgeeks, tutorialspoint and several youtube channels