Upload
voxuyen
View
220
Download
0
Embed Size (px)
Citation preview
CS2630ComputerOrganization
Meeting2:Bits,bytes,andmemoryBrandonMyers
UniversityofIowa
Arithmeticonnumbers
StoringnumbersNumbertotrackthecurrentlineintheprogram
Caveat…wewillbuildeverythingfromswitches(onoroff)• Abinarydigit(or,bit) hastwopossiblevalues0or1• Justlikeadecimaldigithas10possiblevalues0-9
Hundreds|tens|ones19310 =193
fours|twos|ones1012 =101
digitisapowerof10
digitisapowerof2
Bits:formorethanjustnumbersBitscanbeusedtoencode(represent)ANYkindofdata,yesanydata
https://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Microphone.svg/2000px-Microphone.svg.png
http://www.billboard.com/charts/hot-100
https://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Desktop_computer_clipart_-_Yellow_theme.svg/2000px-Desktop_computer_clipart_-_Yellow_theme.svg.png
Sampleanalogsignal(displacementofmicrophonediaphragm)onceevery23us(44.1KHz)– storeitdigitally asan8-bitnumber
Peerinstruction
• Howmanybitsareneededtorepresentthenumberπ?a) 1bitb) infinitebitsc) 3bitsd) 8 bitse) Can’tbedone
CountingwithNbits(N=3)000
001
010
011
100101
110
111
Whataboutnegativeintegers?
000001
010
011
100101
110
111
Positiveintegersonly(“unsigned”)
01
2
345
6
7
000001
010
011
100101
110
111
Positive&negativeintegers(“signed”)
01
2
3-4-3
-2
-1
Makesomespaceforthem!
Two’scomplementjustworks!
• 11001=(-1)*16+(1)*8+(0)*4+(0)*2+1*1=-16+9=-7
• 1001=(-1)*8+(0)*4+(0)*2+1*1=-7
Ortheinvertandadd1trick-7=11001->00110->00111=7
invert +1
Broaderperspective• Two’scomplement(−x = �̅� + 1) isbynomeanstheonlywaycomputershaveencodedintegers!!
• Signandmagnitude usestheleftmostbitasthesign(downsideistwozeroes100...00and000...00)
• Onescomplementdefinestheinverse–x=�̅� (downsidesincludetwozeroes0000...00and1111...11)
• Binarycodeddecimal representseachdigitofadecimalnumberusingbits.E.g.,thenumber91inbinarycodeddecimal
Decimal:91Binary:10010001
(downsidesincludewastingsomestoragespacesincethemaxdigitvalueis1001)
Anothercommonbase:16Binary(2) Decimal(10) Hexadecimal (16)
00000 0 0
00001 1 1
00010 2 2
00011 3 3
00100 4 4
00101 5 5
00110 6 6
00111 7 7
01000 8 8
01001 9 9
01010 10 A
01011 11 B
01100 12 C
01101 13 D
01110 14 E
01111 15 F
10000 16 10
10001 17 11
… …
Anoteonconventions
• Sometimesweindicateabinarynumberwithprefix0b• 101012 or 0b10101
• Sometimesweindicateahexnumberwithprefix0x• FA4116 or 0xFA41
WherewearegoingnextBitsstorewhateveryouwant,includingintegers.Howdowemanipulatesequencesofbits?
Q:Howdowearrangebitsinthememoryofthecomputer?(whydowecare?wewantthecomputertostoremanyindividualnumbers)A:bytes andwords
Q:Howdowenameorrefertoallthoseindividualnumbersinmemory?A:addresses andpointers
10110000
10110000 00001110 01000010 11110001
10110000 00001110 01000010 11110001
0 1 2 3
Arithmeticonnumbers
StoringnumbersNumbertotrackthecurrentlineintheprogram
Instructionmemory
Executionengine
Datamemory
Arithmeticonnumbers
StoringnumbersNumbertotrackthecurrentlineintheprogram
Instructionmemory
Executionengine
Datamemory
organizesitsbitsasbytes andwords
candobitwiseoperations(andotherstuff)
Whattodonow?
• Readings• HW1• Quiz1• PrepforLab1