computer system & binary review. memory model what memory is supposed to look like
TRANSCRIPT
Computer System & Binary Review
Memory Model
• What memory is supposed tolook like
Memory Model
• What each process actually has:
The Instruction
• Machine Instruction:00000001000010010101000000100000
Assembly
• Assembly– Equivalent to instructions
from levels 1, 2, 3
1 bit = 2 patterns 2 bits = 4 patterns 3 bits = 8 patterns
Bits And Bit Patterns
• N bits gives 2n possible patterns
Metric Units
• Standard metric units
Explaining Size
• What the hell MS?
Bi units
• Metric prefixes– May refer to powers of
2 or 10– Roughly equivalent
GB GB 109 = 1000000000 ~ 1073741824 = 230
Bi units
• Memory measured in powers of 2• Network / Processor in powers of 10• Disk
– manufactures powers of 10– OS powers of 2
2 TB = 2 * 1012 2 * 1012 / 240 = 1.819 GiB
Bytes
• 8 bits = 1 byte
• How long does a 10 Meg/sec internet connection take to download a 10 Meg file?
Bytes
• How long does a 10 Meg/sec internet connection take to download a 10 Meg file?– Networks measured in bits using powers of 10– Files in bytes using powers of 2
10Mbit internet = 10,000,000 bits per second
= 1,250,000 bytes per second
10MB file = 10 * 220 = 10,485,760 bytes
10,485,760 / 1,250,000 = 8.39 seconds
Bases
• Place based number representations:
thirty-twos
25
sixteens24
eights23
fours22
twos21
ones20
1 0 1 1 0 1
ten thousand
s104
thousands
103
hundreds102
tens101
ones100
1 2 0 5 9
Specifying Base
• Specify base as subscript:610 = 1102
Binary Number Conversions
• Table Method:
64 + 32 + 8 + 1 = 105
011010012 = 10510
128 64 32 16 8 4 2 1
0 1 1 0 1 0 0 1
Divide Method1. Write out the Decimal number.2. Is it odd or even? If ODD, write a
'1'. If EVEN, write a '0'.3. Divide the Decimal number by 2,
and ignore the remainder (e.g., 105 / 2 = 52.5, ignore the remainder = 52).
4. Go back to step 2, always building the Binary number from right to left.
5. When you get to 0, you're done. Add enough zeros to the left of the Binary number to make 8 digits.
105 odd 1
÷ 2 52 even 01
÷ 2 26 even 001
÷ 2 13 odd 1001
÷ 2 6 even 01001
÷ 2 3 odd 101001
÷ 2 1 odd 1101001
÷ 2 0 done 01101001
Multiply Method
Current number First Digit Old Total x 2 Total
01101001 0 0 0
1101001 1 0 1
101001 1 2 3
01001 0 6 6
1001 1 12 13
001 0 26 26
01 0 52 52
1 1 104 105
Hex
• Hexdecimal = base 16– 4 bits = 1 hex digit
Hex Numbers
• 1A316 =
1 * 256 + 10 * 16 + 3 * 1256 + 160 + 3 = 41910
OR
1 A 3
= 0001 1010 00112
4096 256 16 1
1 A 3
Decimal Binary Hex 0 0 0 1 1 1 2 10 2 3 11 3 4 100 4 5 101 5 6 110 6 7 111 7
8 1000 8 9 1001 9
10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F
Hex Conversion
• Convert with division 41916 to base 10
Number Quotient Remainder
÷ 16 419 26 3 3
÷ 16 26 1 10 (A) A3
÷ 16 1 0 1 1A3
Specifying Bases
• Leading 0 Octal (base 8)• Leading 0x Hex (base 16)
ASCII
• Maps a byte ofmemory to chars/control symbols
Unsigned Binary Addition
• Adding base 2:• 1 = 1• 2 = 10 = keep 0 and carry 1• 3 = 11 = keep 1 carry 1
1 1 10 1 0 10 1 1 11 1 0 0
Unsigned Addition
• Overflow : Carry out of highest bit– Error!
• 13 + 7 = 4?
1 1 1 11 1 0 10 1 1 10 1 0 0
Signed numbers
• 2's complement system:– Positive numbers normal, but
must have a 0 in left bit– Negative numbers:
• Start with 1• Value defined as inverse of
– Flip all bits then add 1
Signed numbers
What is 1001? 1001 Negative number
0110 reverse
6 As decimal
7 Add one
-7 = 1001
Signed numbers
Make -3 0011 start with 3
1100 reverse bits
1101 + 1
1101 Two’s complement -3
2’s complement
1 + (-2)
00011110------
1111
2’s complement
7 + 7
01110111------
1110 = -2??? Overflow switches
sign
4 bits
• Biggest positive: 7
• -1 :
• Lowest negative: -8
0 1 1 1
1 0 0 00 1 1 1 Flip (7)
+1 = 8
1 1 1 1
2’s complement
• Cary into final column and no extra carry– Positive overflow!– Ex: 4 + 6 (sign bits are blue)
0 1 0 00 1 0 00 1 1 01 0 1 0
2’s complement
• Extra carry and no carry in final column– Negative overflow!– Ex: -4 + -6 (sign bits are blue)
1 0 0 01 1 0 01 0 1 00 1 1 0
2’s complement
• No final column carry & no extra carry– Success
0 0 0 00 1 0 00 0 1 00 1 1 0
2’s complement
• Final column carry & extra carry– Success – ignore extra carry
1 1 0 01 1 0 11 1 1 01 0 1 1
2’s complement
• Pros– One zero– Easy to switch sign– Consistent direction
• Cons– Break : - above +
Signed - Excess Notation
• Excess Notation : start counting from a negative number– Used in some situation
• Pros:– Values are properly ordered
• Cons:– Harder to read
• Need to know starting point
– Normal math does not work
Binary Value
000 -4
001 -3
010 -2
011 -1
100 0
101 1
110 2
111 3