Lecture 2. How does the computer work? - PowerPoint PPT Presentation

1 / 67
About This Presentation
Title:

Lecture 2. How does the computer work?

Description:

Lecture 2. How does the computer work? Prof. Sin-Min Lee Department of Computer Science so a k is... k in computing is short for kb or kilobyte where kilo means the ... – PowerPoint PPT presentation

Number of Views:137
Avg rating:3.0/5.0
Slides: 68
Provided by: Lee149
Category:

less

Transcript and Presenter's Notes

Title: Lecture 2. How does the computer work?


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

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
3
  • Card Punch
  • Early programmers were well-paid (compared to
    loom operators)

4
Computer Architecture Instruction Set
Architecture Machine Organization
5
(No Transcript)
6
(No Transcript)
7
(No Transcript)
8
(No Transcript)
9
Aug. 31, 2004, 1205AMBig gain in small
package Intel test chip boasts technology to add
to speed
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.
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 byteshow 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 metremega in our measurement
system means one million, 1 000 000 or a
thousand thousand, so a megabyte is a thousand
kilobytes or one million byteshow 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
(No Transcript)
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
(No Transcript)
16
(No Transcript)
17
(No Transcript)
18
Typical Machine Layout
  • Two cycles
  • Fetch cycle - get instruction
  • Execute cycle - do operation

19
Typical Machine Translation
Instruction format Opcode register, index,
offset load R1, R2, 24
  • 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

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
(No Transcript)
22
(No Transcript)
23
(No Transcript)
24
Von Neumann Model of Execution
Obtain instruction from program storage
Determine required actions and instruction size
Locate and obtain operand data
Almost all Modern Computers are Von
Neumann machines
Compute result value or status
Deposit results in storage for later use
Determine successor instruction
25
(No Transcript)
26
(No Transcript)
27
(No Transcript)
28
(No Transcript)
29
(No Transcript)
30
(No Transcript)
31
(No Transcript)
32
(No Transcript)
33
(No Transcript)
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
Exercises
  1. Convert the binary number 10011 to decimal.
  2. Convert the binary number 1110101 to decimal.

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 102) (6 x 101) (2 x 100) (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 23) (1 x 22) (0 x 21) (1 x 20) (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.37510 10100010.0112

48
Why does this work?
162 / 10 16 rem 2 16 / 10 1 rem 6 1 /
10 0 rem 1
  • 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.

0.375 x 10 3.750 0.750 x 10 7.500 0.500 x 10
5.000
49
Exercises
  • Convert the decimal number 35 to binary.
  • 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
  • Organize the stream of binary digits into groups
    of two.
  • Find the base 4 value for each group of 2 bits.
  • 11110010
  • 11 11 00 10
  • 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 )
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
  • Organize the stream of binary digits into groups
    of three.
  • Find the octal value for each group of 3 bits.
  • 111100101
  • 111 100 101
  • 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
  • Show the octal equivalent of the bit pattern
    101110010.
  • Show the octal equivalent of the bit pattern
    100010.
  • 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 24, one hexadecimal digit is
    equivalent to 4 binary digits.
  • Its 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
  • Organize the stream of binary digits into groups
    of four.
  • Find the hexadecimal value for each group of 4
    bits.
  • 10010010111000011010
  • 1001 0010 1110 0001 1010
  • 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
Exercises
  • Show the hexadecimal equivalent of the bit
    pattern 1100 1110 0010.
  • Show the hexadecimal equivalent of the bit
    pattern 0011100010.
  • What is the bit pattern for 2675 base 16?
  • What is the bit pattern for B51E base 16?

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.3516 2 6 1 . 3 516
0010 0110 0001 . 0011 01012
10110100.0010112 1011 0100 . 0010 11002 B
4 . 2 C16
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 82 2 81 3 160 1
    64 2 8 3 1 64 16 3
    83
  • Base 13
  • 123 1 132 2 131 3 130
    1 169 2 13 3 1 169 26
    3 198
Write a Comment
User Comments (0)
About PowerShow.com