Computer Basics Computer system hardware software Hardware the
Computer Basics • Computer system: hardware + software • Hardware: the physical components – Central Processing Unit (CPU) – Memory – Input/Output devices • Software: the instructions that tell the hardware what to do – Operating Systems – Application Software – User programs 1
Common Hardware Components • • • Processor (CPU) Memory Input device(s) Output device(s) CPU and memory are physically housed together Memory Input Devices Processor Output Devices 2
CPU and Memory • The CPU is the “brain” of the computer – Understands and executes computer programs • Memory is the storage unit – Holds computer programs to be executed and their data – Main and auxiliary memory 3
Inside the CPU Control Unit To main memory, and input / output devices Arithmetic / Logic Unit Registers This is the CPU’s internal memory 4
Kinds of Memory • Main – Often referred to as Random-Access Memory (RAM) – Temporarily stores program and data (while program is executing) – Requires power to retain its contents • Auxiliary – Additional storage capacity – Permanent (more or less) – Saves program and results – Includes floppy & hard disk drives, CDs, flash memory sticks, etc. 5
Main Memory Organization • Comparable to a collection of numbered mailboxes. Address Contents 3021 11110000 3022 1100 • Each memory cell has two important attributes – Address or location – Contents or values, represented digitally as a binary number 3023 1010 3024 11001110 3025 11000000 3026 0000 3027 1111 3028 10110101 3029 11001110 6
Main Memory Organization • Bit = Binary dig. IT – A binary digit can have only one of two values: 0 or 1 • Byte = 8 bits – Also called “octet” • Main memory is a list of numbered locations that contain one byte of data in each location • Number of bytes per data item may vary Address Contents 3021 3022 11110000 Item 1: 1100 2 octets 3023 1010 3024 11001110 3025 11000000 3026 0000 3027 1111 3028 10110101 Item 5: 11001110 2 octets 3029 Item 2: 1 octet Item 3: 3 octets Item 4: 1 octet 7
Binary Numbers • Decimal: × 100 × 22 × 21 × 23 × 24 × 25 × 26 1 6 5 × 27 • Binary: × 101 × 102 • Internally, computers store values as binary (base 2) numbers, rather than decimal (base 10) numbers 1 0 0 1 27 +25 +22 +20 128 +32 +4 +1 = 165 8
Decimal to Binary Conversion • Convert 106 to binary by repeatedly dividing by 2. Use the remainders as the binary digits, with the first remainder being the right-most digit 106 53 26 13 6 3 1 Result: / / / / 2 2 2 2 = 53, = 26, = 13, = 6, = 3, = 1, = 0, 106 = remainder remainder 11010102 0 1 0 1 1 indicates a binary number 9
Storage of character data • Once again, we have only 0 and 1 digits to work with. • Each character is assigned its own numeric code: – ASCII character set (ASCII = American Standard Code for Information Interchange) • 128 characters • most common character set (if you speak American English ) • used in older languages and computers – UNICODE character set • over 64, 000 characters (international) • includes ASCII as a subset • used in Java 10
Unicode • In the computer, every character is stored using a numeric code. – The most commonly used characters in Java have codes in the range 0 through 127. – For these characters the UNICODE code is the same as the ASCII code. • Examples: character a b A B (space) 0 ? UNICODE value 97 98 65 66 32 48 63 • Character codes are chosen so that ordering the numeric codes equates to alphabetical order. – Note that while order is preserved among upper case and among lower case characters, the two cases have different codes. 11
Storage of Floating-point Data • How would 3. 14159265358979323846 be stored? • One approach: – Adjust all numbers so that they are of the form Z x 10 E, where -1 < Z < 1 – Use 1 bit to store the sign (+ or -) of the digits – Use 23 bits to store the digits – Use 1 bit to store the sign of the exponent – Use 7 bits to store the value of E SDDDDDDDDDDDDSEEEEEEE – Approximate decimal equivalent: 0. ddddddd x 10 ee 12
Range and Precision • Range represents the scope of values that can be stored: – Using the format from the previous slide: • Most positive number: ~ +3 x 1038 • Most negative number: ~ -3 x 1038 • Positive number closest to zero: ~ +1. 5 x 10 -45 • Precision represents how many significant digits are stored – In the format from the previous slide, six digits are generally the maximum that can be reliably stored. 13
Effects of Range • Exceeding the range of legal values results in OVERFLOW – number greater than most positive, or less than most negative • A number that is too close to zero to be properly stored results in UNDERFLOW • Suppose that we can store numbers between -99 and +99, with one decimal place allowed. -98 - 98 (overflow) 15 / 0. 1 (overflow) 0. 5 × 0. 1 (underflow) 14
Effects of precision • Suppose we were using decimal digits, and we had only three digits for storage 1 / 3 = 0. 3333… • “Nearest” value that can be stored: 0. 333 • What about (1 / 3) x 3 ? 0. 999 • What about 222 + 4. 44 ? 0. 226 E 3 • This is called “round-off” error 15
Auxiliary Memory Organization “root” or “home” directory Directory File File Directory File 16
Running a Program—a set of instructions for a computer to follow Program Data / Events (input for the program) Computer Output 17
Input/Output Devices • Communication between computers and the outside world. • Transforming information form different non-digital forms into digital form, and vice versa. 18
Input/Output Devices • Common input devices – Keyboards (converts each key or key combination to digital code) – Pointing devices (mouse, track balls, touch pads, etc. ) – Scanner (converts an image to a grid of pixels) • Common output devices – Monitors – Printers – Speakers for audio output • Some devices do both: 19
Types of Programs • Operating System (OS) – Windows (98, Me, NT, 2000, XP), Mac. OS, UNIX / LINUX, etc. • Application Software – word-processor/editor – web browser – compiler or assembler • User Software 20
Functions of the Operating System • Software responsible for directing all computer operations, and managing all computer resources. – Manages allocation of memory, processing time, etc. – Collects input from the input devices and provides this information to the currently running program – Conveys program output to the screen, printer, etc. – Reads/writes data to/from auxiliary storage – Security management 21
Application Software • Software used for a specific task such as word processing, database management, environments for developing user programs, spreadsheets, etc. • Runs on top of the OS using its services; therefore, must be compatible with it 22
User Programs • Developed by the user with the help of specialized application software. • Runs on top of the OS. • We will be developing many user programs during the next four months. 23
Types of User Interfaces • Command-line – All functions performed by typing commands on keyboard. – Text-only display. – Examples: • DOS, UNIX • GUI (Graphical User Interface) – Icons, Menus, Buttons on graphical display. – Typically uses additional input devices as well as keyboard: mouse, pointer, … – Also called “event-driven” – Examples: • Mac. OS, Windows 24
Programming Language Hierarchy High-Level Language (HLL) Assembly Language Machine Language Hardware 25
Machine Language (low level) • A collection of binary instructions understood by a specific type of CPU chip. • Non-standard; low-level of detail related to the given hardware • Very hard to understand by human programmers • Hardware dependent • in order to be executed, any program must have been previously translated into machine language 26
Assembly Language (middle level) • A (supposedly ) human readable version of machine language • Words, abbreviations, letters and numbers replace 0 s and 1 s • Easily translated from human readable to machine executable code (that is, from assembly language to machine language) • Like machine code, assembly language is hardware dependent. 27
High-Level Languages • “Closer” to the human way of expression, using higher -level of abstraction concepts from the application area for which it is intended. • Mostly standardized, thus independent of a given hardware. • Computers do NOT understand high-level languages • Need a compiler (a translation program) to convert programs written in high-level languages into machine language. 28
High-level languages Language When invented Typical uses FORTRAN 1956 Scientific computation LISP 1958 Expert systems COBOL 1960 Business APL 1962 Mathematics, statistics Basic 1971 Teaching, business C 1972 Operating system creation C++ 1984 General purpose, communications Java 1993 General purpose, internet applications 29
Other languages Language When invented Known for… Pascal 1971 Teaching Smalltalk 1972 Object-oriented Prolog 1972 Logic, expert systems Ada 1979 US Defence Dept. software standard language *SQL = Structured Query Language 1979 Databases *HTML = Hyper. Text Markup Language 1992 Web page formatting *XML = e. Xtensible Markup Language 1996 Internet data exchange C# 2002 Microsoft’s answer to Java * Special-purpose languages: not for general programming. 30
Getting from Source to Machine Code • Source code: – Input to a translation program. – Examples: • The program you write • Intermediate-level code that needs further translation. – Must (eventually) be translated to machine code. • Object code: – Output from a translation program – Object code is usually machine code or a lower level language. 31
Getting from Source to Machine Code • Compiler – A program that translates from source code to object code. • Source code in this case is normally a high-level language • Object code could be machine code, an intermediate language, or assembly language. • Assembler – Specific name for a compiler of the assembly language for particular hardware. – Output is always machine code. • Interpreter: – A program that does both program translation and execution – Interpreter translates one statement at a time, and then executes the translated statement. – Source code can be either a high-level language, or an intermediate language. 32
Example of language levels • Suppose that we want to add two numbers. 33
Low-level problem steps (1) • Suppose that we want to add two numbers. – Where is the first number? – Where is the second number? – What should we do with the two numbers? – Where should the result be put? 34
Low-level problem steps (2) • Suppose that we want to add two numbers. – Where is the first number? • Location 0201 – Where is the second number? • Location 0202 – What should we do with the numbers? • Add them – Where should the result be put? • Location 0203 35
Low-level problem steps (3) • Suppose that we want to add two numbers. – Step 1 • Fetch a copy of the contents of memory location 0201 and bring the value to the CPU register 0 – Step 2 • Fetch a copy of the contents of memory location 0202 and bring the value to the CPU register 1 – Step 3 • Add contents of CPU register 1 to CPU register 0. – Step 4 • Move the value from CPU register 0 to memory location 0203 (which replaces the value currently stored there!) 36
In Machine Code Command 00110011 01100010 11000011 Operands (data) 11001001 0000 11001010 00000001 00000000 11001011 Each CPU type has a set of commands, each of which has a given arbitrary code number. 37
In Assembly Language (1) Command Load Add Store Operands (data) $0201, R 0 $0202, R 1 R 0, $0203 • There is a direct correspondence between the machine codes of the previous page, and the elements of the assembly language. – example: Load 0011 38
In Assembly Language (2) Command Operands (data) Load Add Store A, R 0 B, R 1 R 0, C • The assembler will need a symbol table to know the actual locations of A, B, and C. Symbol Actual location A B C $0201 $0202 $0203 • This version is easier to move around in the computer’s main memory: just change the locations in the symbol table. 39
In a High-Level Language C = A + B • The computer will still need a symbol table, but this is produced as part of compiling the program. The compiler will ask the operating system for suitable locations in memory. Symbol Actual location A B C $0201 $0202 $0203 40
The highs and lows of programming languages. . . • High-Level Language (HLL) – closest to natural language – words, numbers, and math symbols – not directly understood by hardware – “portable” source code (hardware independent) • Machine Language (lowest level) – least natural language for humans, most natural language for hardware – just 0 s and 1 s – directly understood by hardware – not portable (hardware dependent) 41
The important point • Everything stored in a computer – data, program instructions, etc. – eventually has to be stored as a collection of 0 s and 1 s. – Programs have to be converted to 0 s and 1 s using a compiler or interpreter. – Data of any type also has to be stored using 0 s and 1 s. – Files essentially consist of a long set of 0 s and 1 s. – Internet communication is based on sending and receiving 0 s and 1 s. • Humans don’t work well with long collections of 0 s and 1 s, and so we need translation of programs, and (re-)formatting of data. 42
- Slides: 42