CS 2630 Computer...

16
CS 2630 Computer Organization Meeting 2: Bits, bytes, and memory Brandon Myers University of Iowa

Transcript of CS 2630 Computer...

Page 1: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

CS2630ComputerOrganization

Meeting2:Bits,bytes,andmemoryBrandonMyers

UniversityofIowa

Page 2: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

Arithmeticonnumbers

StoringnumbersNumbertotrackthecurrentlineintheprogram

Page 3: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

Caveat…wewillbuildeverythingfromswitches(onoroff)• Abinarydigit(or,bit) hastwopossiblevalues0or1• Justlikeadecimaldigithas10possiblevalues0-9

Hundreds|tens|ones19310 =193

fours|twos|ones1012 =101

digitisapowerof10

digitisapowerof2

Page 4: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

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

Page 5: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

Peerinstruction

• Howmanybitsareneededtorepresentthenumberπ?a) 1bitb) infinitebitsc) 3bitsd) 8 bitse) Can’tbedone

Page 6: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

CountingwithNbits(N=3)000

001

010

011

100101

110

111

Page 7: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

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!

Page 8: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

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

Page 9: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

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)

Page 10: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

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

… …

Page 11: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

Anoteonconventions

• Sometimesweindicateabinarynumberwithprefix0b• 101012 or 0b10101

• Sometimesweindicateahexnumberwithprefix0x• FA4116 or 0xFA41

Page 12: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

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

Page 13: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

Arithmeticonnumbers

StoringnumbersNumbertotrackthecurrentlineintheprogram

Page 14: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

Instructionmemory

Executionengine

Datamemory

Arithmeticonnumbers

StoringnumbersNumbertotrackthecurrentlineintheprogram

Page 15: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

Instructionmemory

Executionengine

Datamemory

organizesitsbitsasbytes andwords

candobitwiseoperations(andotherstuff)

Page 16: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/lectures/lectur… · CS 2630 Computer Organization Meeting 2: Bits, bytes ... •Binary coded decimalrepresents

Whattodonow?

• Readings• HW1• Quiz1• PrepforLab1