Computer Programming (66111) An-Najah N. University Computer Engineering Department Luai Malhis, Ph.D, Introduction To Computer System 1Luai M. Malhis
Computer System Definition of a computer The computer is an electronic machine that performs the following four general operations: 1.Input 2.Storage 3.Processing 4.Output. 2Luai M. Malhis
Computer Components A computer consists of two main components : Hardware the mechanical, magnetic, electronic, and electrical components making up a computer system Software: which are written programs pertaining to the operation of a computer system and that are stored in read/write memory. Following is an overview of the main hardware and software components in a computer 3Luai M. Malhis
Computer Hardware Input devices System unit Output devices Storage devices Processing Unit: The CPU and Main Memory 4Luai M. Malhis
Input Devices Enter data to be processed – Keyboard – Scanners – Mouse – Trackball – Touch screen – Microphone – Game Controller – Digital camera 5 The rain in Spain ABCD Luai M. Malhis
System Unit Cabinet that houses all components Motherboard CPU Memory modules 6 System Unit CPU Motherboard Memory Module Luai M. Malhis
Output Devices Enable us to see or hear the processed information – Monitor – Speakers – Printers 7Luai M. Malhis
Storage Devices Enable us to store data or information to be accessed again 8 Hard Disk DriveCD / DVD DriveFloppy Disk Flash Drive Luai M. Malhis
The Central processing Unit The CPU contains three parts: Arithmetic Logic Unit - ALU is where the "intelligence" of the computer is located. It performs all arithmetic operations such as addition, subtraction, multiplication and division. The ALU performs logical operations i.e. makes decisions by determining if a number is greater, less, or equal to the other number. An operation completes in nanoseconds, which is a billionth of a second. Registers: which are small storage devices holds instructions and operands needed by the ALU during operation execution. 3. Control Unit - This is the part of the unit, which directs information to the proper places in your computer, such as calculation of information by the ALU unit or to store and print material. 9 The CPU contains three parts: Arithmetic Logic Unit - ALU is where the "intelligence" of the computer is located. It performs all arithmetic operations such as addition, subtraction, multiplication and division. The ALU performs logical operations i.e. makes decisions by determining if a number is greater, less, or equal to the other number. An operation completes in nanoseconds, which is a billionth of a second. Registers: which are small storage devices holds instructions and operands needed by the ALU during operation execution. 3. Control Unit - This is the part of the unit, which directs information to the proper places in your computer, such as calculation of information by the ALU unit or to store and print material. Luai M. Malhis
The Memory Unit The Main Memory: Two types of memory contained on a chip are ROM (Read Only Memory) or RAM (Random Access Memory). ROM memory is installed on a computer by the manufacturer and can not be altered. ROM is the memory that determines all the basic functions of the operation of rge computer such as startup, shut down, and placing a character on the screen. RAM is temporary memory, which stores programs during execution and also hold all information displayed on the monitor. RAM is read/write memory and it is much larger in size than ROM. Data disappears from the RAM when the computer is turned off or power is off. 10Luai M. Malhis
Computer Software Software - programs that enable the hardware to perform different tasks Application software – Tools for getting things done 11Luai M. Malhis
Computer Software System software – Essential for platform operation and support 12Luai M. Malhis
Computer Platforms: PCs and Macs PC CPU – Intel, AMD Operating system – Microsoft Windows Mac CPU – Motorola Operating system – Apple Mac OS 13Luai M. Malhis
Application Software Used to accomplish specific tasks other than just running the computer system. May consist of a single program, such as an image viewer; A small collection of programs (often called a software package) that work closely together to accomplish a task. Independent programs and packages that have a common user interface or shared data format, such as Microsoft Office. 14Luai M. Malhis
Programming languages The machine language, which is the only languages understood by CPU. While easily understood by the CPU, the machine language is almost impossible for humans to use because they consist entirely of 0s and 1s. A assembly language contains the same instructions as a machine language, but the instructions and variables have names instead of being just 0s and 1s. High Level language Closely resemble human language Examples of high level languages are : Pascal, Fortran, Basic, Java, and C/C++. Programs written in high-level languages are translated into machine language by a compiler. 15Luai M. Malhis
C/C++ Programming Lnaguage History of C – Evolved from two other programming languages BCPL and B – Typeless languages – Dennis Ritchie (Bell Laboratories) Added data typing, other features – Hardware independent Portable programs – 1989: ANSI standard – The C Lnaguage is Then developed to contain classes and other object Oriented features and named as C++. – Many Other Lnaguages currently developed that uses a synatx and symantics like C. – C/C++ is traditionally the first language a programmer learns. Luai M. Malhis16
How C++ Works Luai M. Malhis17
What is a program A program is a set of instructions that a computer follows. Example: computing the Area of Rectangle Get base Get Height Area = 0.5 * base * height Steps to writing a program: Step 1. Think! (This is not optional.) Step 2. Organize your thoughts Step 3. Write them down in English Step 4. Translate them into C++ Luai M. Malhis18
Program Construction Text Editor This is used to create the program in C++ form. Since this is the start or source of the other forms this is called a source file. (Source files end with.cpp. -- also used C and.cc.) Compiler This translates the source file into a machine dependent file called an object file. The object file contains the instructions in a way that the machine can understand. The source file is in the C++ language (high level code) while the object file is in machine language (low level code.) Link This is used to associate the object file with other necessary files to generate an EXE file Which contains the machine language. Luai M. Malhis19
Data vs. Information Data vs. Information: – Data is a representation of a fact or idea Number Word Picture Sound – Information is data that has been organized or presented in a meaningful fashion. 20Luai M. Malhis
Computers are Data Processing Devices Four major functions: – Input data – Process data – Output information – Store data and information 21 DATA IN INFORMATION OUT Luai M. Malhis
Bits and Bytes: The Language of Computers Bit – Binary digit – 0 or 1 Byte – Eight bits ASCII – Each byte represents a letter, number or special character 22 OFF 0 ON 1 Microchip Switch = = A 0 Luai M. Malhis
How Much is a Byte? NAMEABBREVIATIONNUMBER OF BYTES RELATIVE SIZE ByteB 1 byteCan hold one character of data. KilobyteKB 1,024 bytesCan hold 1,024 characters or about half of a typewritten page double-spaced. MegabyteMB 1,048,576 bytesA floppy disk holds approximately 1.4 MB of data, or approximately 768 pages of typed text. GigabyteGB 1,073,741,824 bytesApproximately 786,432 pages of text. Since 500 sheets of paper is approximately 2 inches, this represents a stack of paper 262 feet high. TerabyteTB 1,099,511,627,776 bytesThis represents a stack of typewritten pages almost 51 miles high. PetabytePB 1,125,899,906,842,624 bytes The stack of pages is now 52,000 miles high, or about one-fourth the distance from the Earth to the moon. 23Luai M. Malhis
Binary Language Computers work in binary language Consists of two numbers: 0 and 1 Everything a computer does is broken down into a series of 0s and 1s Switches: Devices inside the computer that can be flipped between these two states: 1 or 0, on or off 24Luai M. Malhis
Switches Non-mechanical devices in computers that open and close circuits Types of electronic switches: – Vacuum tubes – Transistors: Semiconductors – Integrated circuits Vacuum Tube Transistors Integrated Circuits 25Luai M. Malhis
Switches Representing Data The on/off state of a switch represents one bit of data Bit (binary digit) – On = 1 – Off = 0 OFF 0 ON 1 01 OR = 1 bit 26Luai M. Malhis
The Binary Number System Describes a number as powers of 2 Also referred to as base 2 numbering system Used to represent every piece of data stored in a computer: all of the numbers, letters, and instructions 27Luai M. Malhis
The Binary Number System Number systems are organized ways to represent numbers Each number in one system has a corresponding number in another x x x x8 82x4 42x2 22x1 1 Binary Base = = 89 Binary Base 10 Luai M. Malhis
Understanding Decimal Numbers Decimal numbers are made of decimal digits: (0,1,2,3,4,5,6,7,8,9) But how many items does a decimal number represent? – 8653 = 8x x x x10 0 What about fractions? – = 9x x x x x x x10 -2 – In formal notation -> ( ) 10 Why do we use 10 digits, anyway?
Understanding Binary Numbers Binary numbers are made of binary digits (bits): – 0 and 1 How many items does an binary number represent? – (1011) 2 = 1x x x x2 0 = (11) 10 – ( ) = = (82) 10 – ( ) = = (273) 10
Convert from Decimal to binary 1.Divide decimal number by the base (e.g. 2) 2.The remainder is the lowest-order digit 3.Repeat first two steps until no divisor remains. For each digit position: Example for (13) 10: Integer Quotient 13/2 = 6 + ½ a 0 = 1 6/2 = a 1 = 0 3/2 = 1 + ½ a 2 = 1 1/2 = 0 + ½ a 3 = 1 RemainderCoefficient Answer (13) 10 = (a 3 a 2 a 1 a 0 ) 2 = (1101) 2
The Growth of Binary Numbers N is the number of bits in the binary number n2n2n 02 0 = = = = = = = =128 n2n2n 82 8 = = = = = =1M =1G =1T Mega Giga Tera
Understanding Octal Numbers Octal numbers are made of octal digits: (0,1,2,3,4,5,6,7) How many items does an octal number represent? – (4536) 8 = 4x x x x8 0 = (1362) 10 What about fractions? – (465.27) 8 = 4x x x x x8 -2 Octal numbers dont use digits 8 or 9 Luai M. Malhis33
Convert an Integer from Decimal to Octal 1.Divide decimal number by the base (8) 2.The remainder is the lowest-order digit 3.Repeat first two steps until no divisor remains. For each digit position: Example for (175) 10: Integer Quotient 175/8 = /8 a 0 = 7 21/8 = 2 + 5/8 a 1 = 5 2/8 = 0 + 2/8 a 2 = 2 RemainderCoefficient Answer (175) 10 = (a 2 a 1 a 0 ) 2 = (257) 8
Understanding Hexadecimal Numbers Hexadecimal numbers are made of 16 digits: – (0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F) How many items does an hex number represent? – (3A9F) 16 = 3x x x x16 0 = What about fractions? – (2D3.5) 16 = 2x x x x16 -1 = Note that each hexadecimal digit can be represented with four bits. – (1110) 2 = (E) 16
Converting Between Base 16 and Base 2 °Conversion is easy! Determine 4-bit value for each hex digit °Note that there are 2 4 = 16 different values of four bits °Easier to read and write in hexadecimal. °Representations are equivalent! 3A9F 16 = A9F
Converting Between Base 16 and Base 8 Convert from Base 8 to Base 2 1.Regroup bits into groups of three starting from right 2.Ignore leading zeros 3.Each group of three bits forms an octal digit = A9F 16 = A9F
Number System Conversion Table DecBinOctHex A B C D E F 38Luai M. Malhis
Representing Letters and Symbols There are codes that dictate how to represent characters in binary format. Most of todays computers use the American Standard Code for Information Interchange (ASCII code) to represent each letter or character as an 8-bit (or 1-byte) binary code. The ASCII code represents the 26 uppercase letters and 26 lowercase letters used in the English language, along with a number of punctuation symbols and other special characters, using 8 bits. Eight bits is the standard length upon which computers are built. In the ASCII The representation for A is 41H (65), B is 42H (66), a is 61H (97) and b is 62h (98). The Complete table is shown next slide 39Luai M. Malhis
ASCII Chart 40Luai M. Malhis