1.14k likes | 1.73k Views
305171 Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University. Introduction to Computer. What is computer?. A COMPUTER is an electronic device that can: Receive information Perform processes
E N D
305171 Computer Programming RattapoomWaranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University Introduction to Computer
What is computer? • A COMPUTER is an electronic device that can: • Receive information • Perform processes • Produce output • Store info for future use.
Computer around us • Personal computers (PC)
Computer around us • Mobile devices
Computer around us • Game consoles
Computer around us • Servers
Computer around us • Mainframe computers IBM zEnterprise
Computer around us • Super computers Fujitsu’s K - Computer
Computer around us • Embedded systems
Computer around us • Robots
Overview of computer system Hardware Software OS Applications Firmware Content Etc. PC Mainframe Mobile Etc. Peopleware Programmer System Analyst User Administrator Etc.
Information Processing cycle Feedback Output (Output Devices) Input (Input Devices) Process (CPU) Storage (Memory)
Central Processing Unit (CPU) • Arithmetic and logic unit (ALU) • performs arithmetic and logical operations • Control unit • controls the flow of data through the processor, and coordinates the activities of the other units within it • Registers • small amount of storage available on the CPU whose contents can be accessed more quickly than storage available elsewhere
Memory Unit • Main (primary) memory • Stores programs and data while computer is running. Main memory is fast and limited in capacity. The CPU can only directly access information in main memory. • Random Access Memory (RAM) • Read-Only Memory (ROM)
1 0 1 1 1 0 0 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 0 0 1 0 0 1 0 0 Memory Unit Memory mapping Address Values 0000 0001 0002 .. .. .. .. FFFF • Size : • Kilobyte KB 210 ~103 • Megabyte MB 220 ~106 • Gigabyte GB 230 ~109 • Terabyte TB 240 ~1012 • Petabyte PB 250 ~1015 • Exabyte EB 260 ~1018 • Zettabyte ZB 270 ~1021 • Yottabyte YB 280 ~1024
Memory Unit • External (secondary) memory • Holds information too large for storage in main memory. • Information on external memory can only be accessed by the CPU if it is first transferred to main memory. • It retains information when the computer is switched off.
System Bus CPU Main Memory ALU VDO controller CU Registers Clock BUS I/O ports Disk controller
System Clock • A clock signal is a signal generated by quartz crystal circuit that oscillates between a high and a low state and is utilized to coordinate actions of circuits. • Clock rate is measured in cycles/sec (Hertz ).
Multi-Level Machine Model User Problem oriented language level Level 5 Translation (compiler) Assembly Language Level 4 Translation (assembler) Operating System Level 3 Partial interpretation (operating system) Instruction Set Architecture Level 2 Interpretation (microprogram) or direct execution Micro-architecture level Level 1 Hardware Digital Logic Level Level 0 Circuits
Level 0 – Digital Logic • The interesting objects at this level are gates; • Each gate has one or more digital inputs (signals representing a 0 or 1) and computes as output some simple function of these inputs, such as AND or OR; • A small number of gates can be combined to form a 1-bit memory, which can store a 0 or 1; • The 1-bit memories can be combined in groups of, for example, 16, 32 or 64 to form registers.
Level 1 - Microarchitecture • A collection of 8-32 registers that form a local memory and ALU • The registers are connected to the ALU to form a data path over which the data flow; • The operation of the data path may be controlled by a microprogram, directly by hardware, or even by software.
Level 2 - Instruction Set Architecture (ISA) • The ISA level is defined by the machine’s instruction set • This is a set of instructions carried out interpretively by the microprogram or hardware execution sets; • Machine languages • Strings of numbers giving machine specific instructions
Level 3 - Operating System Machine • The Operating System Machine (OSM) level is a complete set of instructions available to application programmers. This includes all ISA level instructions and a new set of instructions that the operating system adds called system calls. • The OSM level is always interpreted. For instance, if reading data from file, the operating system carries it out step by step.
Level 4 – Assembly Language • This level is really a symbolic form. • This level provides a method for people to write programs for levels 1, 2 and 3 in a form that is more readable. • Programs in assembly language are first translated to level 1, 2 or 3 language and then interpreted by the appropriate virtual or actual machine. • The program that performs the translation is called an assembler. • Example: LOAD R1, #FFFF ADD R2,R1 MOV R3,R2
Level 5 - Problem-Oriented Language • This level usually consists of languages designed to be used by applications programmers. • These languages are generally called higher level languages, for examples: C, C++, Java, BASIC, LISP, Prolog, Pascal, FORTRAN, COBOL, etc. • Programs written in these languages are generally translated to Level 3 or 4 by translators known as compilers, although • occasionally they are interpreted instead.
Number Systems • Computers use binary numbers internally because storage devices like memory and disk are made to store 0s and 1s. A number or a text inside a computer is stored as a sequence of 0s and 1s. Each 0 and 1 is called a bit, short for binary digit. The binary number system has two digits, 0 and 1. • Binary numbers are not intuitive. When you write a number like 20 in a program, it is assumed to be a decimal number. Internally, computer software is used to convert decimal numbers into binary numbers, and vice versa.
Number Systems • The digits in the decimal number system are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The value that each digit in the sequence represents depends on its position. A position in a sequence has a value that is an integral power of 10. • We say that 10 is the base or radix of the decimal number system. Similarly, the base of the binary number system is 2 since the binary number system has two digits and the base of the hex number system is 16 since the hex number system has sixteen digits. 5892 = 5 x 103 + 8 x 102 + 9 x 101 + 2 x 100
Binary Number System • A positional number system • Has only 2 symbols (0 and 1), so that base = 2 • The maximum value of a single digit is 1 (base – 1) • The maximum value of N digits is 2N-1 • Used mostly in computer system
Binary Number System • 5 digits binary can store number up to 25-1 = 32-1 = 31 • Example 101012 = (1x24) + (0x23) + (1x22) + (0x21) + (1x20) = 16 + 0 + 4 + 0 + 1 = 2110
OCtal Number System • A positional number system • Has only 8 symbols (0, 1, 2, 3, 4, 5, 6, 7), so that base = 8 • The maximum value of a single digit is 7 (base – 1) • The maximum value of N digits is 8N-1 • Used mostly in computer system
Octal Number System • Example 20578 = (2x83) + (0x82) + (5x81) + (7x80) = 1024 + 0 + 40 + 7 = 107110
Hexadecimal Number System • A positional number system • Has only 16 symbols (0-9, A, B, C, D, E, F), so that its base = 16 • The maximum value of a single digit is 15 (F) (base – 1) • The maximum value of N digits is 16N-1 • Used mostly in computer system
Hexadecimal Number System • Example 1AF16 = (1x162) + (10x161) + (15x160) = 256 + 160 + 15 = 43110
Converting n-Base to Decimal • Method • Determine the column (positional) value of each digit. • Multiply the obtained column values by the digits in the corresponding columns. • Calculate the sum of these products.
Converting Decimal to n-Base • Division-Remainder Method • Divide the decimal number by the value of the new base. • Record the remainder from step 1 as the right most digit of the new base number • Divide the quotient of the previous divide by the value of the new base. • Record the remainder from step 3 as the next digit (to the left) of the new base number. • Repeat step 3 and 4 until the quotient become 0, the last remainder will be the most significant digit of the new base number.
Converting Decimal to n-Base • Example 95210 = ?8 Solution 8 )952 Remainders )119 0 )14 7 )1 6 0 1 Hence, 95210 = 016708
Converting Decimal to n-Base • Example 95210 = ?16 Solution 16)952 Remainders )59 8 )3 11 0 3 Hence, 95210 = 3B816
Converting N-Base to M-Base • Method • Convert the original number to a decimal number • Convert the decimal number that obtained on in step 1 to the new base number
Convert binary no. to octal no. • Method • Divide the digits into groups of three starting from the right. • Convert each group of three binary digits to one octal digit using the method of binary to decimal conversion.
Convert binary no. to octal no. • Example 11010102 = ?8 Solution • Divide the binary into groups of three digits 001 101 010 • Convert each group into one octal digit 0012 = 0x22 + 0x21 + 1x20 = 1 1012 = 1x22 + 0x21 + 1x20 = 5 0102 = 0x22 + 1x21 + 0x20 = 2 Hence, 11010102 = 1528
Convert Octal no. to Binary no. • Method • Convert each octal digit to 3 binary digits. • Combine all the resulting binary groups into a single binary number.
Convert Octal no. to Binary no. • Example 5628 = ?2 Solution • Convert each octal digit to 3 binary digits. 58 = 1012 68 = 1102 28 = 0102 • Combine all the resulting binary groups into a single binary number. 5628 = 101 110 010 2 Hence, 5628 = 1011100102
Convert binary no. to Hex no. • Method • Divide the digits into groups of four starting from the right. • Convert each group of four binary digits to one hexadecimal digit using the method of binary to decimal conversion.
Convert binary no. to Hex no. • Example 1111012 = ?16 Solution • Divide the binary into groups of four digits 0011 1101 • Convert each group into one hexadecimal digit 00112 = 0x23 + 0x22 + 1x21 + 1x20 = 3 11012 = 1x23 + 1x22 + 0x21 + 1x20 = 13 = D Hence, 1111012 = 3D16
Convert Hex no. to Binary no. • Method • Convert each hexadecimal digit to 4 binary digits. • Combine all the resulting binary groups into a single binary number.
Convert Hex no. to Binary no. • Example 2AB16 = ?2 Solution • Convert each hex digit to 4 binary digits. 216 = 00102 A16 = 10102 B16 = 10112 • Combine all the resulting binary groups into a single binary number. 2AB16 = 0010 1010 1011 2 Hence, 2AB16 = 0010101010112
Data Representation • All information that is processed by computers is converted in one way or another into a sequence of numbers. This includes • numeric information • textual information and • Pictures, sound, video, etc. • Therefore, if we can derive a way to store and retrieve numbers electronically this method can be used by computers to store and retrieve any type of information.