# lecture 2. how does the computer work? prof. sin-min lee department of computer science

Post on 22-Dec-2015

216 views

Embed Size (px)

TRANSCRIPT

- Slide 1
- Lecture 2. How does the computer work? Prof. Sin-Min Lee Department of Computer Science
- Slide 2
- Computer of the day Jacquard loom late 1700s for weaving silk Program on punch cards Microcode: each hole lifts a set of threads Or gate: thread lifted if any controlling hole punched
- Slide 3
- Card Punch Early programmers were well-paid (compared to loom operators)
- Slide 4
- Computer Architecture = Instruction Set Architecture + Machine Organization +
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Intel, the world's biggest semiconductor maker, said Monday it built a test chip with a new process that creates faster circuits by packing 10 million transistors into an area the size of the tip of a ballpoint pen. Intel, based in Santa Clara, Calif., has made the first working memory chip that uses so-called 65-nanometer technology to shrink the circuits inside chips, Intel researcher Mark Bohr said during a conference call. Aug. 31, 2004, 12:05AM Big gain in small package Intel test chip boasts technology to add to speed
- Slide 10
- Bit
- Slide 11
- so a k is... k in computing is short for kb or kilobyte where kilo means the same as anywhere else in our measurement system: 1000 so a k is 1000 bytes how about Mb? b for byte again, and M for mega: megabyte big M for mega, small m means milli, or one thousandth, 1/ 1000 as in mm, thousandths of a metre mega in our measurement system means one million, 1 000 000 or a thousand thousand, so a megabyte is a thousand kilobytes or one million bytes how about GB? you can now buy hard disk drives in Gb, gigabytes, thousands of Mb or thousands of millions of bytes, so a 5Gb HDD holds 5000 Mb of data with some large computers storing up to Tb, terabytes... yup, thousands of Gb... so one terabyte (Tb) = 1000 gigabytes (Gb) = 1000 000 megabytes (Mb) = 1000 000 000 kilobytes (kb) = 1 000 000 000 000 bytes or one thousand billion bytes of information
- Slide 12
- Slide 13
- What is a Computer? Data Primitive Operations Sequence Control Data Access Storage Management Operating Environment May be actual hardware computer or software- simulated computer. Most computers a combination of the two.
- Slide 14
- In mathematics you don't understand things. You just get used to them. John von Neumann
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Typical Machine Layout Two cycles: Fetch cycle - get instruction Execute cycle - do operation
- Slide 19
- Typical Machine Translation For example: As we see later, memory for data in blocks of storage pointed to by a register: X = Y + Z could be translated as: load R1, R2, 28[Location of Y] add R1, R2, 40 [Location of Z] store R1, R2, 24[Location of X] Instruction format: Opcoderegister, index, offset load R1, R2, 24
- Slide 20
- Ways to Construct a Computer Hardware Realization Any precisely defined algorithm or data structure may be realized in hardware. Firmware Realization Microprogramming or emulation Virtual Machine Provided by a language environment Combination
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Von Neumann Model of Execution Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Obtain instruction from program storage Determine required actions and instruction size Locate and obtain operand data Compute result value or status Deposit results in storage for later use Determine successor instruction Almost all Modern Computers are Von Neumann machines
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Data Representation Data comes in different forms such as numbers, text, images, audio, video, How does the computer handle all the different data types? The most efficient solution is to use a uniform representation of data. All data from outside a computer are transformed into this uniform representation. The universal format is called a bit pattern (a sequence of bits).
- Slide 35
- Computer Memory Memory is comprised of a large collection of bi-state (off/on) electrical devices called bits (binary digits) A single bit can assume the value 0 or 1. A single bit is not sufficient to represent all data ; therefore, it is necessary to use a sequence of bits.
- Slide 36
- Basic Addressable Unit of Memory A byte is the basic addressable unit of memory. In virtually all modern computers, a byte consists of 8 bits. As indicated on the previous slide, an 8-bit byte can encode 256 distinct values.
- Slide 37
- Binary integer arithmetic Integers are stored in a computer using a fixed number of binary digits to encode each value.
- Slide 38
- Decimal system
- Slide 39
- Binary system The binary system is based on 2. There are only two digits: 0 and 1 We convert a number from binary to decimal by multiplying each binary digit by its corresponding power of 2. i.e. Multiply the bit at position n (n = 0, 1, 2, ) by
- Slide 40
- Binary system Binary to Decimal Conversion Binary number
- Slide 41
- 1.Convert the binary number 10011 to decimal. 2.Convert the binary number 1110101 to decimal. Exercises
- Slide 42
- Decimal review Numbers consist of a bunch of digits, each with a weight: The weights are all powers of the base, which is 10. We can rewrite the weights like this: To find the decimal value of a number, multiply each digit by its weight and sum the products. (1 x 10 2 ) + (6 x 10 1 ) + (2 x 10 0 ) + (3 x 10 -1 ) + (7 x 10 -2 ) + (5 x 10 -3 ) = 162.375
- Slide 43
- Decimal to Binary Conversion To convert a decimal to a binary number, use repetitive division. Divide the number by 2. Write the remainder as the least significant digit (rightmost digit). The quotient becomes the dividend in the next stage. Continue to divide by 2 until the quotient is zero, writing each remainder from right to left.
- Slide 44
- Decimal to binary conversion
- Slide 45
- Decimal to Binary Conversion Example: Write 18 in base 2. 18 / 2 = 9 r 0 9 / 2 = 4 r 1 4 / 2 = 2 r 0 2 / 2 = 1 r 0 1 / 2 = 0 r 1 18 base 10 = 10010 base 2
- Slide 46
- Converting binary to decimal We can use the same trick to convert binary, or base 2, numbers to decimal. The only difference is that the weights are powers of 2. For example, here is 1101.01 in binary: The decimal value is: (1 x 2 3 ) + (1 x 2 2 ) + (0 x 2 1 ) + (1 x 2 0 ) + (0 x 2 -1 ) + (1 x 2 -2 ) = 8+ 4+ 0+ 1+ 0+ 0.25= 13.25
- Slide 47
- Converting decimal to binary To convert a decimal integer into binary, keep dividing by 2 until the quotient is 0. Collect the remainders in reverse order. To convert a fraction, keep multiplying the fractional part by 2 until it becomes 0. Collect the integer parts in forward order. Example: 162.375: So, 162.375 10 = 10100010.011 2 162 / 2= 81rem 0 81 / 2= 40rem 1 40 / 2= 20rem 0 20 / 2= 10rem 0 10 / 2= 5rem 0 5 / 2= 2rem 1 2 / 2= 1rem 0 1 / 2= 0rem 1 0.375 x 2 = 0.750 0.750 x 2 = 1.500 0.500 x 2 = 1.000
- Slide 48
- Why does this work? This works for converting from decimal to any base Why? Think about converting 162.375 from decimal to decimal. Each division strips off the rightmost digit (the remainder). The quotient represents the remaining digits in the number. Similarly, to convert fractions, each multiplication strips off the leftmost digit (the integer part). The fraction represents the remaining digits. 162 / 10= 16rem 2 16 / 10= 1rem 6 1 / 10= 0rem 1 0.375 x 10 = 3.750 0.750 x 10 = 7.500 0.500 x 10 = 5.000
- Slide 49
- Exercises 1.Convert the decimal number 35 to binary. 2.Convert the decimal number 327 to binary.
- Slide 50
- Bases other than 2 and 10 Any positive integer can be used as a base. For base 5 The digits are {0, 1, 2, 3, 4} In a number, such as 1203, each digit is implicitly multiplied by a positional power of 3. 1203 base 5 is
- Slide 51
- Bases that are Powers of 2 Bit patterns are designed to represent data when stored inside a computer. People find it difficult to manipulate bit patterns. Writing a long stream of 0s and 1s is tedious and error- prone. Bases which are powers of 2 are useful in simplifying notation.
- Slide 52
- Bases that are Powers of 2 A single digit of a base system represents exactly n bits of a base 2 system. Base Number of bits 4 2 8 3 16 4
- Slide 53
- Converting from base 2 to base 4 Valid digits in base 4 are 0, 1, 2, 3 To convert from base 2 to base 4 1. Organize the stream of binary digits into groups of two. 2. Find the base 4 value for each group of 2 bits. 11110010 3 3 0 2
- Slide 54
- Converting from base 4 to base 2 To convert from base 4 to base 2 Convert