Docsity

Introduction-Programming Concepts-Lecture Slides, Slides of Computer Programming

Partial preview of the text

Download Introduction-Programming Concepts-Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

PROGRAMMING IN C

CS

Department of Electrical Engineering

What Is a Computer?

Computer  Performs computations and makes logical decisions  Millions / billions times faster than human beings  Computer programs  Sets of instructions for which computer processes data  Hardware  Physical devices of computer system  Software  Programs that run on computers

COMPUTER ORGANIZATION

Computer Organization

 Logical units in every computer:

 Input unit  Obtains information from input devices (keyboard, mouse)  Output unit  Outputs information (to screen, to printer, speakers)  Memory unit  Rapid access, low capacity, stores input information  Secondary storage unit  Cheap, long-term, high-capacity storage  Stores inactive programs (Hard drives, floppy drives)

Computer Organization

Computer Memory

 Main Memory

 Long list of memory locations  Each contains zeros and ones  Can change during program execution  Binary Digit or Bit  A digit that can only be zero or one  Byte  Each memory location has eight bits  Address  Number that identifies a memory location

Larger Data Items

 Some data is too large for a single byte

 Most integers and real numbers are too large

 Address refers to the first byte

 Next few consecutive bytes can store the additional bits for larger data.

Secondary Memory

 Main memory stores instructions and

data while a program is running.

 Secondary memory

 Stores instructions and data between sessions  A file stores data or instructions in secondary memory

Memory Access

 Random Access

 Usually called RAM  Computer can directly access any memory location

 Sequential Access

 Data is generally found by searching through other items first  More common in secondary memory

The Processor

 Typically called the CPU

 Central Processing Unit  Follows program instructions  Typical capabilities of CPU include:

add subtract multiply divide move data from location to location

MEMORY ORGANIZATION

MEMORY

CPU

DATA

INSTRUCTION

DATA

PROGRAM

docsity.com

Generation of Languages

 1GL  Machine language

 2GL  Assembly Language

 3GL  High Level Languages ( C, C++, Java)

 4GL  Closer to natural languages than 3GL. Languages for accessing databases are expressed as 4GL.

 5GL  Artificial Intelligence and neural networks.

LOW AND HIGH LEVEL PROGRAMMING

 Next lowest level: Assembler

 Mnemonics directly represent machine

 code, Symbolic,

 Example

LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

 Human readable, slow to create, fast to

run, processor specific.

LOW AND HIGH LEVEL PROGRAMMING

High level: Pascal, ‘C’, Fortran, ‘C++’/Java  One statement is equivalent of many  machine code operations. ans = a/(b*24);  Human understandable, fast to write,  inefficient (?) in terms of code size and run  Must be translated to zeros and ones for the CPU to execute a program  portable between processors.

 Example: grossPay = basePay + overTimePay