You are on page 1of 34

Chapter 1: Introduction

In this chapter you will learn about:
Overview of PC components
The different types of language
Natural Language
Formal Language
Functional / Imperative Language
Programming Languages

C as an imperative language
C program at a glance

Principles of Programming - NI July 2005


Computer Hardware

Components of a PC

Principles of Programming - NI July 2005


What is computer hardware?
Computer devices in physical form
Comprised of 4 components:
Input devices
Central Processing Unit (CPU)
Output devices

Chapter 2

Introduction (cont’d) Processor Control Control Unit Unit Arithmetic Arithmetic Logic Unit (ALU) Logic Unit (ALU) Instructions Data Information Input Devices Data Memory Instructions Data Information Storage Devices Chapter 2 Information Output Devices .

Input Device What is input?  Data or instructions entered into memory of computer  Input device is any hardware component that allows users to enter data and instructions Chapter 2 .

numbers.Input Device (cont’d) Two types of input:  Data  Unprocessed text. images. audio. and video  Instructions  Programs  Commands  User responses Chapter 2 .

Input Device (cont’d) Keyboard allows the computer user to enter Words  Numbers  Punctuation  symbols and  special function commands into the computer’s memory  Chapter 2 .

Output Device What is output?  Data that has been processed into a useful form.  Chapter 2 Output device is any hardware component that can convey information to user .

Output Devices (cont’d) Display device   Output device that visually conveys information  Information on display device sometimes called soft copy Monitor houses display device as separate peripheral Chapter 2 .

Tablet PC.Output Devices (cont’d) Display device  LCD monitor    Uses liquid crystal display Have a small footprint Mobile devices that contain LCD displays include  Notebook computer. and Smart Phone Chapter 2 . PDA.

Input / Output Devices Input Devices Accepts information from the user and transforms it to digital codes that the computer can process Example: keyboard. scanner Output Devices An interface by which the computer conveys the output to the user Example: monitor. mouse.NI July 2005 11 . printer Principles of Programming .

NI July 2005 12 . Principles of Programming . 2 types ROM (Read Only Memory) Contains information that is necessary for the computer to boot up The information stays there permanently even when the computer is turned off. RAM (Random Access Memory) Contains instruction or data needed for a program to run Got erased when the computer is turned off.Main Memory A semiconductor device which stores the information necessary for a program to run.

CPU What is the central processing unit (CPU)?  Also called the processor  Interprets and carries out basic instructions that operate a computer  Control unit directs and coordinates operations in computer  Arithmetic logic unit (ALU) performs arithmetic. and logical operations Chapter 2 Processor Control Control Unit Unit Arithmetic Arithmetic Logic Unit (ALU) (ALU) Logic Unit . comparison.

CPU (cont’d) Register  Temporary high-speed storage area that holds data and instructions Stores location from where instruction was fetched Stores data Stores instruction while it is while ALU being decoded computes it Stores results of calculation Chapter 2 .

Central Processing Unit (CPU) Does most of the work in executing a program The CPU inside a PC is usually the microprocessor 3 main parts: Control Unit Fetch instructions from main memory and put them in the instruction register ALU (Arithmetic Logic Unit) Execute arithmetic operations Registers Temporarily store instructions or data fetched from memory Principles of Programming .NI July 2005 15 .

Store the software components or data needed for the computer to execute its tasks. Example: Hard drive. CD ROM. floppy disks Principles of Programming . Could be “read only” or “writable”.NI July 2005 16 .Storage Devices A magnetic device used to store a large amount of information.

Ethernet card Principles of Programming . Example: modem.Network Devices Connect a computer to the other computers.NI July 2005 17 . Enable the users to access data or execute programs remotely.

spoken and written Not 100% needed to understand: “Do you want to buy this computer ?” remains comprehensible Principles of Programming .Natural language Our everyday-language.NI July 2005 18 .

NI July 2005 19 . In natural languages it is often possible to assemble a sentence in more than one correct ways. Principles of Programming .Syntax are the rules to join words together in forming a correct expression or phrase.Semantics and Syntax Semantics – the meaning of the language within a given context Syntax .

Principles of Programming . to instruct a computer. defined.Formal Language Language with limited.NI July 2005 20 . our commands must be 100% clear and correct. correct syntax. Often there is only a single. words Each concatenation of words ('phrase') has a single. clearly defined meaning no (miss-)interpretation possible Sometimes called “Context Free Language” To 'talk' to a computer.

then add the next number to the sum.. but not how: sum [1.NI July 2005 21 .Functional / Imperative Language Functional Language: Tell what to do.10] Imperative Language: Tell what to do. but mainly how: “Take number 1 and add the next number to it.. until you have reached 10 as number to be added. Then print the sum of all numbers” Principles of Programming . and so on.

Conceptual: It is a framework within which we organize our ideas about things and processes.representing 'objects' we want to manipulate Procedures -'descriptions' or 'rules' that define how to manipulate data. In programming.What is Programming? Programming is instructing a computer to do something for you with the help of a programming language The two roles of a programming language: Technical: It instructs the computer to perform tasks. we deal with two kind of things: Data . Principles of Programming .NI July 2005 22 .

NI July 2005 23 . A programming language contains instructions for the computer to perform a specific action or a specific task: 'Calculate the sum of the numbers from 1 to 10‘ 'Print “I like programming”‘ 'Output the current time' Principles of Programming .Programming Language Formal Language used to communicate to a computer.

Special-purpose : is design for a particular type of application Structured Query Language (SQL) General-purpose : can be used to obtain solutions for many types of problems Machine Languages Assembly Languages High-Level Languages Principles of Programming .NI July 2005 24 .Programming Language Can be classified into as a special-purpose and general-purpose programming languages.

Processor and Architecture dependent Principles of Programming .NI July 2005 25 . Programming in machine code is difficult and slow since it is difficult to memorize all the instructions. Mistakes can happen very easily.Machine Language The only language that the processor actually 'understands‘ Consists of binary codes: 0 and 1 Example: 00010101 11010001 01001100 Each of the lines above corresponds to a specific task to be done by the processor.

Processor and Architecture dependent Principles of Programming . C STORE A. compared to machine code but still quite difficult to use. Example of a program in assembler language: LOAD A. 9999 LOAD B.Assembly Language Enables machine code to be represented in words and numbers.NI July 2005 26 . 8282 SUB B MOV C. A LOAD C. 7002 Easier to understand and memorize (called Mnemonics). #0002 DIV A.

Pascal. They try to resemble English sentences. Cobol. it is easier to program in these languages. The programming structure is problem oriented . Examples: Basic. Processor independent .High-Level Language Use more English words. Fortran.does not need to know how the computer actually executes the instructions. C++. Principles of Programming .the same code can be run on different processors. C. Therefore.NI July 2005 27 . Java A high level language needs to be analyzed by the compiler and then compiled into machine code so that it can be executed by the processor.

so that almost everyone had his own perception of it. developed at Bell Laboratories Developed by Dennis Ritchie at Bell Laboratories in the 1960s In cooperation with Ken Thomson it was used for Unix systems The C Language was only vaguely defined. to such an extend that an urgent need for a standard code was creeping up Principles of Programming .NI July 2005 28 .C Programming Language Why 'C' ? Because based on 'B'. not standardized.

but there is no compiler yet Principles of Programming .NI July 2005 29 . This standard was updated in 1999.C Programming Language cont… In 1983. which is now the global standard for C. a Technical Committee to draft a proposal for the ANSI standard. which was approved in 1989 and referred to as the ANSI/ISO 9899 : 1990 or simply the ANSI C. the American National Standards Institute (ANSI) set up X3J11.

in short: everything and anything… Hint: Observe the syntax in the next slide Principles of Programming .C – An Imperative Language C is a highly imperative language We must tell it exactly how to do what.NI July 2005 30 . which libraries to use. when an instruction is finished. the means and functions to use. when to add a new line.

NI July 2005 31 .\n").h> main() { printf("I like programming in C. } Principles of Programming .A Simple Program in C #include <stdio.

Insert a new line } End of statement End of Segment Principles of Programming .explanation #include <stdio. input-output. header-file Begin of program main() { Start of Segment Function for printing text printf("I like programming in C.NI July 2005 32 .\n").A Simple Program in C .h> standard Library.

NI July 2005 33 . Principles of Programming .C Output I like programming in C.

Summary We have looked at some underlying hardware We have seen some different types of languages. We have observed the detail necessary in an imperative language to instruct a computer properly. the relevance of semantics and syntax. Principles of Programming .NI July 2005 34 . we examined the syntax to print a line of text to the screen of our computer. Finally.