View
235
Download
3
Tags:
Embed Size (px)
Citation preview
‘Computer” of the day
Jacquard loomlate 1700’sfor weaving silk
“Program” on punch cards
“Microcode”: each holelifts a set of threads
“Or gate”: thread lifted if any controlling hole punched
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:05AMBig gain in small package
Intel test chip boasts technology to add to
speed
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 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 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
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.
Typical Machine Translation
For example: As we see later, memory for data in blocks of storage pointed to by a register:
X = Y + Zcould 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: Opcode register, index, offsetload R1, R2, 24
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
Von Neumann Model of ExecutionInstruction
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 ModernComputers areVon Neumannmachines
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).
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.
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.
Binary integer arithmetic
• Integers are stored in a computer using a fixed number of binary digits to encode each value.
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
n2
1. Convert the binary number 10011 to decimal.
2. Convert the binary number 1110101 to decimal.
Exercises
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 6 2 . 3 7 5 Digits100 10 1 1/ 10 1/ 100 1/ 1000 Weights
1 6 2 . 3 7 5 Digits102 101 100 10-1 10-2 10-3 Weights
(1 x 102) + (6 x 101) + (2 x 100) + (3 x 10-1) + (7 x 10-2) + (5 x 10-3) = 162.375
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.
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
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 1 0 1 . 0 1 Binary digits, or bits23 22 21 20 2-1 2-2 Weights (in base 10)
(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 Powers of 2:
20 = 1 24 = 16 28 = 25621 = 2 25 = 32 29 = 51222 = 4 26 = 64 210 = 102423 = 8 27 = 128
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
162 / 2 = 81 rem 0 81 / 2 = 40 rem 1 40 / 2 = 20 rem 0 20 / 2 = 10 rem 0 10 / 2 = 5 rem 0 5 / 2 = 2 rem 1 2 / 2 = 1 rem 0 1 / 2 = 0 rem 1
0.375 x 2 = 0.7500.750 x 2 = 1.5000.500 x 2 = 1.000
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 = 16 rem 2 16 / 10 = 1 rem 6 1 / 10 = 0 rem 1
0.375 x 10 = 3.7500.750 x 10 = 7.5000.500 x 10 = 5.000
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
101785*35*05*25*1 0123 base
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.
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
n2
Converting from base 2 to base 4
• Valid digits in base 4 are 0, 1, 2, 3
• To convert from base 2 to base 41. Organize the stream of binary digits into groups of two.
2. Find the base 4 value for each group of 2 bits.11110010
11 11 00 10
3 3 0 2
Converting from base 4 to base 2
• To convert from base 4 to base 2Convert each digit to its 2-bit equivalent.
3 3 0 2
11 11 00 10
3302 base 4 is 11110010 base 2
Base 8 (Octal )Base 8 (Octal )
Bit PatternBit Pattern------------
000001010011
Octal DigitOctal Digit------------
0123
100101110111
4567
Valid digits: 0, 1, 2, 3, 4, 5, 6, 7
Converting from base 2 to base 8
• To convert from base 2 to base 81. Organize the stream of binary digits into groups of three.2. Find the octal value for each group of 3 bits.
111100101111 100 101 7 4 5111100101 base 2 is 745 base 8
Converting from octal to binary
• To convert from octal to binaryConvert each digit to its 3-bit equivalent.
3 5 7
011 101 111
357 base 8 is 011101111 base 2
ExercisesExercises
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?
Decimal Binary Hex0 0000 01 0001 12 0010 23 0011 34 0100 45 0101 56 0110 67 0111 78 1000 89 1001 910 1010 A11 1011 B12 1100 C13 1101 D14 1110 E15 1111 F
Decimal Binary Hex0 0000 01 0001 12 0010 23 0011 34 0100 45 0101 56 0110 67 0111 78 1000 89 1001 910 1010 A11 1011 B12 1100 C13 1101 D14 1110 E15 1111 F
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.
– 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.
Converting from base 2 to hexadecimal
• To convert from base 2 to hexadecimal1. Organize the stream of binary digits into groups of four.
2. Find the hexadecimal value for each group of 4 bits.10010010111000011010
1001 0010 1110 0001 1010
9 2 E 1 A
Converting from hexadecimal to base 2
• To convert from hexadecimal (base 16) to base 2Convert each digit to its 4-bit equivalent.
9 2 E 1 A
1001 0010 1110 0001 1010
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?
ExercisesExercises
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
1111F1011B0111700113
1110E1010A0110600102
1101D100190101500011
1100C100080100400000
BinaryHexBinaryHexBinaryHexBinaryHex
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
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