Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2. How does the computer work? Prof. Sin-Min Lee Department of Computer Science.

Similar presentations


Presentation on theme: "Lecture 2. How does the computer work? Prof. Sin-Min Lee Department of Computer Science."— Presentation transcript:

1 Lecture 2. How does the computer work? Prof. Sin-Min Lee Department of Computer Science

2 ‘Computer” of the day Jacquard loom late 1700’s for weaving silk “Program” on punch cards “Microcode”: each hole lifts a set of threads “Or gate”: thread lifted if any controlling hole punched

3 Card Punch Early “programmers” were well-paid (compared to loom operators)

4 Computer Architecture = Instruction Set Architecture + Machine Organization + …

5

6

7

8

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

10 Bit

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

12

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.

14 In mathematics you don't understand things. You just get used to them. John von Neumann

15

16

17

18 Typical Machine Layout Two cycles: Fetch cycle - get instruction Execute cycle - do operation

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

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

21

22

23

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

25

26

27

28

29

30

31

32

33

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).

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.

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.

37 Binary integer arithmetic Integers are stored in a computer using a fixed number of binary digits to encode each value.

38 Decimal system

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

40 Binary system Binary to Decimal Conversion Binary number

41 1.Convert the binary number 10011 to decimal. 2.Convert the binary number 1110101 to decimal. Exercises

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

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.

44 Decimal to binary conversion

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

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

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

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

49 Exercises 1.Convert the decimal number 35 to binary. 2.Convert the decimal number 327 to binary.

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

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.

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

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

54 Converting from base 4 to base 2 To convert from base 4 to base 2 Convert each digit to its 2-bit equivalent. 3 3 0 2 11 11 00 10 3302 base 4 is 11110010 base 2

55 Base 8 (Octal ) Bit Pattern Bit Pattern ------------ 000 001 010 011 Octal Digit Octal Digit ------------ 0 1 2 3 100 101 110 111 45674567 Valid digits: 0, 1, 2, 3, 4, 5, 6, 7

56 Converting from base 2 to base 8 To convert from base 2 to base 8 1. Organize the stream of binary digits into groups of three. 2. Find the octal value for each group of 3 bits. 111100101 7 4 5 111100101 base 2 is 745 base 8

57 Converting from octal to binary To convert from octal to binary Convert each digit to its 3-bit equivalent. 3 5 7 011 101 111 357 base 8 is 011101111 base 2

58 Binary to octal and octal to binary transformation

59 Exercises 1.Show the octal equivalent of the bit pattern 101110010. 2.Show the octal equivalent of the bit pattern 100010. 3.What is the bit pattern for 24 base 8?

60 Base 16 is useful too The hexadecimal system uses 16 digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F You can convert between base 10 and base 16 using techniques like the ones we just showed for converting between decimal and binary. For our purposes, base 16 is most useful as a “shorthand” notation for binary numbers. –Since 16 = 2 4, one hexadecimal digit is equivalent to 4 binary digits. –It’s often easier to work with a number like B4 instead of 10110100. Hex is frequently used to specify things like 32-bit IP addresses and 24-bit colors.

61 Converting from base 2 to hexadecimal To convert from base 2 to hexadecimal 1. Organize the stream of binary digits into groups of four. 2. Find the hexadecimal value for each group of 4 bits. 10010010111000011010 9 2 E 1 A

62 Converting from hexadecimal to base 2 To convert from hexadecimal (base 16) to base 2 Convert each digit to its 4-bit equivalent. 9 2 E 1 A 1001 0010 1110 0001 1010

63 Binary to hexadecimal and hexadecimal to binary transformation

64 1.Show the hexadecimal equivalent of the bit pattern 1100 1110 0010. 2.Show the hexadecimal equivalent of the bit pattern 0011100010. 3.What is the bit pattern for 2675 base 16? 4.What is the bit pattern for B51E base 16? Exercises

65 Binary and hexadecimal conversions Converting from hexadecimal to binary is easy: just replace each hex digit with its equivalent 4-bit binary sequence. To convert from binary to hex, make groups of 4 bits, starting from the binary point. Add 0s to the ends of the number if needed. Then, just convert each bit group to its corresponding hex digit. 261.35 16 = 2 6 1. 3 5 16 =001001100001.00110101 2 10110100.001011 2 =10110100.00101100 2 = B 4. 2 C 16

66 Class Exercise 1.Bin to dec: 1001 0011 2.Dec to bin: 105 3.Bin to hex: 0010 1110 1000 1011 4.Hex to bin: 0xFEDC 5.Hex to dec: 0x10A 6.Dec to hex: 165

67 Other Bases Base 8 (octal number system) –123 = 1 * 8 2 + 2 * 8 1 + 3 * 16 0 = 1 * 64 + 2 * 8 + 3 * 1 = 64 + 16 + 3 = 83 Base 13 –123 = 1 * 13 2 + 2 * 13 1 + 3 * 13 0 = 1 * 169 + 2 * 13 + 3 * 1 = 169 + 26 + 3 = 198

68

69

70

71 Algebraic System Binary operations: +,* Unary operation: ‘

72

73

74

75 Properties of Boolean Algebra


Download ppt "Lecture 2. How does the computer work? Prof. Sin-Min Lee Department of Computer Science."

Similar presentations


Ads by Google