Where are we? - University of...

49
Where are we? Instruction set architecture (e.g., MIPS) Compiler Memory system I/O system Processor Datapath & Control Digital logic translating source code (C or Java) Programs to assembly language And linking your code to Library code How the software talks To the hardware How a processor runs MIPS Programs! How switches (1 or 0) can be used to build Interesting functions: from integer arithmetic to programmable computers

Transcript of Where are we? - University of...

Wherearewe?

Instructionsetarchitecture(e.g.,MIPS)

Compiler

Memorysystem I/OsystemProcessor

Datapath &Control

Digitallogic

translatingsourcecode(CorJava)ProgramstoassemblylanguageAndlinkingyourcodetoLibrarycode

HowthesoftwaretalksTothehardware

HowaprocessorrunsMIPSPrograms!

Howswitches(1or0)canbeusedtobuildInterestingfunctions:fromintegerarithmetictoprogrammablecomputers

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

Peerinstruction

• Translatethefollowingbinarynumberstodecimal• 102 =____10• 1112=____10• 101012=____10

• Bonus,translatethisfractionalnumber• 11.012

Bits:formorethanjustnumbers

Bitscanbeusedtoencode(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

Howmanyuniquevaluescanyourepresentwith3bits?

Peerinstruction

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

CountingwithNbits(N=3)

000001

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

Peerinstructions:Two’scomplementandHex

1. Whatis-1110 inbinary(usingtwo’scomplementencodingforintegers)?

2. A116 =____10

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)

Backtobitssoon,butfirst…memory!

Organizingbits

• Byte:aunitofdata• IntheMIPSarchitecture,bytesare8-bitslongandarethesmallestunitofdatathearchitecturegivesanameto (moreonnamessoon)• Trueofmostothermodernarchitectures,too

00011010 1byte,perhapsstoringtheinteger2610

1A Wealsoliketowritethevalueofabyteastwohexdigits

Memoryorganization

1A …

Wethinkofmemoryasonebigarrayofbytes

AnalogyinJava?byte[] memory = new byte[NUM_BYTES];

• Justlikeeveryelementinanarrayhasanindex,everybyteinmemoryhasanindex,calleditsaddress.

• Usetheaddresstofindthebytetoreadorwriteit

1A …

http://www.publicdomainpictures.net/view-image.php?image=2759

Whattodonow

• HW1andQuiz1• Newreadingsareup• Buyyourclickerlicense(ifyoudon’tyethaveone)andgothroughgettingstarteddoc• linkedfromthesyllabus• We’lltryitMonday/WedandstartkeepingtrackFriday

• Takealookatsyllabusforofficehours/DebugYourBrain

Organizebytesintomachinewords

1A

0000000100020003000400050006000700080009000A000B000C000D000E000F

(noteaddressinhex)

32-bitwords 64-bitwords

PeerInstruction

1A

0000000100020003000400050006000700080009000A000B000C000D000E000F

(noteaddressinhex)

32-bitwords 64-bitwords

MIPShas32-bitaddresses

WhatisthelargestnumberofbytesthememoryofaMIPScomputercanhave?

Lookingatmemoryaswords000000040008000C001000140018001C002000240028

Storingvalues

• storethevalue integer1510 ataddress 0x0008 00 00 00 0F

000000040008000C001000140018001C002000240028

Storingvalues

• storethevalue integer1510 ataddress 0x0014• storethevalue integer2010ataddress 0x0000

00 00 00 14

00 00 00 0F

000000040008000C001000140018001C002000240028

Addressescanbevalues,too!

• storethevalue integer1510 ataddress 0x0014• storethevalue integer2010 ataddress 0x0000• storethevalue address0x0014 ataddress 0x001C

00 00 00 14

00 00 00 0F

00 00 00 14

000000040008000C001000140018001C002000240028

Addressescanbevalues,too!• storethevalue integer1510 ataddress 0x0014• storethevalue integer2010 ataddress 0x0000• storethevalue address0x0014 ataddress 0x001C• wesaythewordataddress0x001Cisapointertotheintegerataddress0x0014

00 00 00 14

00 00 00 0F

00 00 00 14

000000040008000C001000140018001C002000240028

Addressescanbevalues,too!• storethevalue integer1510 ataddress 0x0014• storethevalue integer2010 ataddress 0x0000• storethevalue address0x0014 ataddress 0x001C• wesaythewordataddress0x001Cisapointertotheintegerataddress0x0014

• storethevalue address0x001C ataddress 0x0028• wesaythewordataddress0x0028 isapointer toapointer toaninteger

00 00 00 14

00 00 00 0F

00 00 00 14

00 00 00 1C

000000040008000C001000140018001C002000240028

int[] arr = new int[3];

Howarrayslookinmemory000000040008000C001000140018001C002000240028

int[] arr = new int[3];arr[0] = 13;

Howarrayslookinmemory

00 00 00 0D

000000040008000C001000140018001C002000240028

int[] arr = new int[3];arr[0] = 13;arr[1] = 10;

Howarrayslookinmemory

00 00 00 0D00 00 00 0A

000000040008000C001000140018001C002000240028

int[] arr = new int[3];arr[0] = 13;arr[1] = 10;arr[2] = 16;

Howarrayslookinmemory

00 00 00 0D00 00 00 0A00 00 00 10

000000040008000C001000140018001C002000240028

Peerinstruction• Supposeweallocatethisarray:int[] arr = new int[7];andJavadecidedtoputthefirstbyteofthearray(firstbyteofarr[0])ataddress0x04

Whatistheaddressofarr[5]?a. 0x04b. 0x14c. 0x09d. 0x54e. 0x05f. 0x18

address=baseaddress+index*element_size

Sizeofdatatypes(inbytes)Javadatatype sizein32-bit

architecturesizein64-bitarchitecture

boolean 1 1byte 1 1short 2 2int 4 4long 8 8float(later!) 4 4reference (storesamemoryaddress)

4 8

slideinspiredbyUWCSE351

Administrivia:Moreofficehours!

• Xin’sofficehoursnowscheduled!• Monday4:30pm- 6:00• Friday9:30am– 11• 101NinMacleanHall(MLH)

Aside:namingpowersoftwo• Oneofourfavoriteformulas:howmanyuniquethingscanyourepresentwithNbits?2Nthings• NamingconventionsN =? name Close (butnotequal!)to

powerof10

10 Kibi (Ki) 103 orKilo (K)20 Mebi (Mi) 106orMega (M)30 Gibi (Gi) 109orGiga (G)40 Tebi (Ti) 1012orTera (T)50 Pebi (Pi) 1015orPeta (P)60 Exbi (Ei) 1018orExa (E)

Namethesenumbersofbytes:

211 bytes=_____

232 bytes=_____

259 bytes=_____

Wherewearegoing(today)Bitsstorewhateveryouwant,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

DONE(fornow)

DONE(fornow)

NEXT

Changingthenumberofbits• Oftenweneedtochangethenumberofbitsweareusingtostoreanumber(why?)

• 1210 using4bitsis11002• Ifwestoreitin8bits:000011002

• -510 using4bitsis:1011• Ifwestoreitin8bits:____________2

Wecallthisoperationsignextension: copytheleftmostbitin4-bitnumbertothenew4leftmostbitsinthe8-bitnumber

Representingsetswithbits• 4-bitvectorrepresentssubsetsof{3,2,1,0}• 1meansintheset,0meansnotintheset

• Aistheset{1,0},encodedas0011• Bistheset{2,0},encodedas0101

• Setoperationsusingbitwiseoperators• A&BIntersection0001(1iff bothare1)• A|BUnion0111(1iff atleastone1)• A^Bsymmetricdifference0110(1iff exactlyone1)• ~Bcomplement1010(1iff 0)

slideinspiredbyUWCSE351

Shift

• shift:movebitsleftorright

• Leftshift:5<<2

• Rightshift:5>>1

0 0 1 0 1

1 0 1 0 0

0 0 1 0 1

0 0 0 1 0

PeerinstructionWhatistheintegerresultfromevaluatingthisexpression?(assumeintegersare32bits)

(7<<2)&15

Let’splayacardgame

• Comeupwithabinaryencodingfora52-carddeck

SlideinspiredbyCSE351Spring2016

Operationsonapairofcards

• Wewantthefollowingoperationstobeeasytoimplement• Comparetwocards,whichishighervalue?• Comparetwocards,aretheythesamesuit?

Whereweareheadednext

Instructionmemory

Executionengine

Datamemory

organizesitsbitsasbytes andwords

Storesprograms!

candobitwiseoperations(andotherstuff)

Whattodonow

• HW1isouttoday:duenextThursday• Buyyourclickerlicense(ifyoudon’tyethaveone)andgothroughgettingstarteddoc• VoteonDebugYourBrainavailabilityifyouhaven’tyet• <30postsonthe“Introduceyourself…”discussionthread;godoit