CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer...

41
CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa

Transcript of CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer...

Page 1: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

CS2630ComputerOrganization

IntrotosynchronousdigitalsystemsBrandonMyers

UniversityofIowa

Page 2: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Wherewearegoing

Instructionsetarchitecture(e.g.,MIPS)

Compiler

Memorysystem I/OsystemProcessor

Datapath&Control

Digitallogic

translatingsourcecode(CorJava)ProgramstoassemblylanguageAndlinkingyourcodetoLibrarycode

HowthesoftwaretalksTothehardware

HowaprocessorrunsMIPSPrograms!

Howswitches(1or0)canbeusedtobuildInterestingfunctions:fromintegerarithmetictoprogrammablecomputers

..thenthisisnext!!

awordonextralayersinJava

Page 3: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

A“secret”aboutJava…

Page 4: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

lw $t0, 4($r0)addi $t0, $t0, 10sw $t0, 8($r0)

MIPSAssembler

100011100000100000000000000001000010000100001000000000000000101010101110000010000000000000001000

CCompiler(gcc)

helloworld.c

MIPSprocessorexecutesthebinary

helloworld.java

JavaCompiler(javac)

https://en.wikipedia.org/wiki/Java_bytecode

Javabytecode(.classfiles)

JavaVirtualMachine(JVM)interprets thebytecode

TheJVMitselfistheexecutablefile(whichyoudownloadedfromOracle’swebsite)thatrunsontheprocessor

assemblycode(.sor.asm files)

machinecode(.exefiles)

CompilingandrunningCvs.Java(shownforonlyasinglesourcefile,i.e.ignoringthelinkingstep)

Page 5: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

AnotherdetailaboutJava• InterpretingJavabytecodeismuchslowerthanexecutingmachinecode• TheJVMisfancy:for“hot”methods(methodsthatrunmanytimes),theJVMcompiles&assemblesthemintomachinecode• TheJVMonlyknowswhatcodeis“hot”oncetheprogramhasbeenrunningforawhile,sotheJVM’scompilerisknownasaJIT(“just-in-time”)compiler

helloworld.java

JavaCompiler(javac)

Javabytecode(.classfiles)

JavaVirtualMachine(JVM)interprets thebytecode

TheJVMitselfistheexecutablefile(whichyoudownloadedfromOracle’swebsite)thatrunsontheprocessor

Page 6: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Administrivia• HW3duetoday• HW4availablesoon• Lab4:CombinationallogicinLogisim thisweek

Page 7: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Wherewearegoing

Instructionsetarchitecture(e.g.,MIPS)

Compiler

Memorysystem I/OsystemProcessor

Datapath&Control

Digitallogic

translatingsourcecode(CorJava)ProgramstoassemblylanguageAndlinkingyourcodetoLibrarycode

HowthesoftwaretalksTothehardware

HowaprocessorrunsMIPSPrograms!

Howswitches(1or0)canbeusedtobuildInterestingfunctions:fromintegerarithmetictoprogrammablecomputers

done

Page 8: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Conceptmapping• Purpose:illustratethecurrentstructureofCS2630conceptsinyourhead,formnewconceptrelationships

• Groupsof3,findaboardspaceanywhere

• Buildaconceptmap(incomputerscientistspeak,itisagraphnotamap)• eachterm(onthesheet)goesinavertex• connectrelatedtermswithanedge;labeltheedgetodescribetherelationship

• After~10minutes,wewillstopsoyoucantourothergroups’conceptmaps

Page 9: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

“Synchronousdigitalsystems”• We’llbedesigningcircuitsusingtwoveryconvenientabstractions ofelectricalcircuits• digital:voltageisquantizedintotwovalues:0and1,allowingustocombinecomponentswithoutincreasingcomplexity• synchronous:timeisdiscrete,thatis,timeadvancesindistinctstepsandthevaluesonallthewireschangesatthesesteps

Page 10: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Digitalabstraction• Composecircuitswithoutthemaffectingeachother• Why?outputsare“perfect”highandlowvoltages

NANDNAND

01

11

1

Page 11: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Synchronousabstraction• timeisdiscrete• timeadvancesindistinctstepsandthevaluesonallthewireschangesatthesesteps

Page 12: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

“Synchronousdigitalsystems”• We’llbedesigningcircuitsusingtwoveryconvenientabstractions ofelectricalcircuits• digital:voltageisquantizedintotwovalues:0and1,allowingustocombinecomponentswithoutincreasingcomplexity• synchronous:timeisdiscrete,thatis,timeadvancesindistinctstepsandthevaluesonallthewireschangesatthesesteps

• Twopartstosynchronousdigitalsystems1. combinationallogic(ignoretimeandjustthinkaboutinputs

andoutputs)• e.g.,bitwiseoperationsandarithmeticonbinarynumbers

2. synchronouslogic(we’llincorporatestate,whichwillchangeastimeadvances)• e.g.,memoryandregisters

Page 13: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Combinationallogicrepresentaninputusingaboolean variable

• boolean:domainis{false,true},orthinkofitas{0,1}threebasicoperations:AND,OR,NOT

notation:𝐴 " 𝐵means“trueiff Aistrueand Bistrue”𝐴 + 𝐵 means“trueiff Aistrueor Bistrue”�̅�means“trueifAisnot true”

Combineoperationstogethertobuildmorecomplexexpressions

forexample,readthisexpression:(𝐴 " 𝐵) + (𝐴 " 𝐶)

Page 14: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Truthtables

A B C0 0 00 1 01 0 01 1 1

A B C0 0 0

0 1 11 0 11 1 1

A C0 11 0

A B C D0 0 0 10 0 1 10 1 0 10 1 1 11 0 0 11 0 1 01 1 0 11 1 1 1

𝐶 = 𝐴 " 𝐵

𝐶 = 𝐴 + 𝐵

𝐶 = �̅� 𝐷 = (𝐴 " 𝐵) + (𝐴 " 𝐶)

definesalogicalfunctionbyenumeratingallinputsandthecorrespondingoutput

Page 15: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Anexample:buildacircuitandrunit• Rulesdefinealogiccircuitsymbolically• “If(IgogroceryshoppingandIcook)orIordertake-outthenIeatdinner”

• Declareavariableforeachboolean input• Gistrueiff “Igogroceryshopping”• Cistrueiff “Icook”• Tistrueiff “Iordertake-out”• Eistrueiff “Ieatdinner”

• WritewhetherIeatdinnerintermsoflogicequation• 𝐸 = 𝐺 " 𝐶 + 𝑇

• Now,ifIsettheinputs,Icanevaluatetherightsidetogetananswer• SupposeIwentgroceryshopping,Ididnotcook,andIorderedtake-out• 𝐸 = 𝑡𝑟𝑢𝑒 " 𝑓𝑎𝑙𝑠𝑒 + 𝑡𝑟𝑢𝑒 = false + true = true

Page 16: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Peerinstruction• Whichlogicequationdescribesthistruthtable?

a) 𝐶 = 𝐴 " 𝐵b) 𝐶 = �̅� " 𝐵@c) 𝐶 = 𝐴 + 𝐵d) 𝐶 = 𝐴 " 𝐵

A B C

0 0 1

0 1 1

1 0 1

1 1 0

Page 17: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Thebasiccomponent:aswitch

Currentflowsfromthebatterywhenthereisacompletecircuit

Whentheswitchisclosed(connectsthecircuit),thecurrentflowstothelight

Whentheswitchisopen(disconnectsthecircuit),thecurrentdoesnotflowtothelight

0 10

0 10

AB

Page 18: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Buildinglogicfromswitches

Twoswitchesconnectedinparallel.Atleastonemustbeclosedforthebulbtoturnon

Twoswitchesconnectedinseries.Bothmustbeclosedforthebulbtoturnon

Page 19: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

LogicgatesA

B

AB C

C

AB

C

A B

C

Thestateoftheswitchistheinputtothecircuit

Page 20: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

PeerinstructionWhatisthetruthtableforthiscircuit?

a

b

c

d

a b c d

Page 21: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Controllingtheswitches• Tocomposetwogates,weneedtobeabletochangethestateoftheswitchesofthesecondgatewiththeoutputofthefirstgate

A

B

C

DE

A

B

C

C DE

(output)

(input)

Page 22: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.
Page 23: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

CS2630ComputerOrganization

Transistors,combinationallogicBrandonMyers

UniversityofIowa

Page 24: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Controllingtheswitches• Tocomposetwogates,weneedtobeabletochangethestateoftheswitchesofthesecondgatewiththeoutputofthefirstgate

A

B

C

DE

A

B

C

C DE

(output)

(input)

Page 25: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Transistors(MOSFET)

pMOS

nMOS

gate

gate

drain

drain

source

source

gate=0Volts gate=1Volt

s

d

s

d

s

d

s

d

off

off on

on

Page 26: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

HowdoesnMOS transistorwork?

Madeofasubstrateofp-typematerial(positivebiased).Drainandsourcearen-typematerial(negativebiased).a) gateisgiven0volts:diodesbetweensource/substrateanddrain/substrateare

reversebiasedsonocurrentflows(transistorisOFF)b) gateisgiven1volt:causesanegativechargeinthesubstratenearthegate;thisarea

ofnegativechargeiscalledthechannel.Nowcurrentflowsfromsourcetodrain(transistorisON)

Page 27: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Controllingtheswitches• Youcoulddoitthisway,BUTitturnsoutthatnMOS arebadatpassinghighvoltageandpMOS arebadatpassinglowvoltage

A

B

C

DE

A

B C

C DE

C D

Page 28: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

CMOStotherescue• complimentaryMOS

1. everylogicgateismadefrompMOS transistorsconnectedto1(VDD)andoutput,aswellasnMOS transistorsconnectedto0(ground)andoutput

2. pMOS sideisintendedtoproduce1byconnectingoutputtoVDDandnMOS sideisintendedtoproduce0byconnectingoutputtoground.

3. whenpMOS sideisoff,nMOS sideshouldbeon;whenpMOSsideison,nMOS sideshouldbeoff

• CMOSlet’susbuildlargecomplexcircuitsoutofgatesbecausetheoutputisa“perfect”1or0eveniftheinputatthegatesis”imperfect”(i.e.avoltageinbetween)

Page 29: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Peerinstruction

inputA inputB output

fillinthetruthtable

Onclicker,enteradescriptionofwhatitdoes.

Page 30: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Exampleofcomposingmanygates

CMOSlet’susbuildlargecomplexcircuitsoutofgatesbecausetheoutputisa“perfect”1or0eveniftheinputatthegatesis”imperfect”(i.e.avoltageinbetween)

Page 31: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Nowthatweknowhowtoarrangetransistorsinawaythatwecansafelycomposelogicgatestogether,let’sbuildbiggercircuits!

Page 32: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Ingredientsforaprocessor• Combinationallogic• arithmeticandbitwiseoperations• multiplexors(pick1outofofNinputs)• controllogic• branchcalculation• addresscalculation

• Synchronouslogic(we’llgettotheselater)• registers• programcounter,orPC• datamemory• instructionmemory

startlearninghowtobuildthesecombinationallogiccircuits

Page 33: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

• Selectbit=0meanspassfirstinputtooutput

• Selectbit=1meanspasssecondinputtooutput

Multiplexor(MUX)picksbetweentwoinputs

select

inputdata output

data

shownareMUXswithadatawidthof3bits

YoucanbuildaMUXwithanydatawidth

Page 34: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

HowdowebuildaMUXfromlogicgates?(with1-bitdatawidth)

In0 In1 Select Out0 0 0 00 0 1 00 1 0 00 1 1 11 0 0 11 0 1 01 1 0 11 1 1 1

𝐼𝑛0 " 𝐼𝑛1 ⋅ 𝑆𝑒𝑙𝑒𝑐𝑡 + 𝐼𝑛0 "

Page 35: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Truthtabletogates1. Foreach1intheoutput,writeaproductclause(AND).

Connectthemwithsums(OR).

2.Simplifytheexpressionusingalgebraiclaws

𝑠𝑒𝑙𝑒𝑐𝑡 ⋅ 𝐼𝑛0 ⋅ 𝐼𝑛1 + 𝐼𝑛0 ⋅ 𝐼𝑛1 + 𝑠𝑒𝑙𝑒𝑐𝑡 ⋅ (𝐼𝑛0 ⋅ 𝐼𝑛1 + 𝐼𝑛0 ⋅ 𝐼𝑛1)

𝑠𝑒𝑙𝑒𝑐𝑡 ⋅ 𝐼𝑛1 + 𝑠𝑒𝑙𝑒𝑐𝑡 ⋅ 𝐼𝑛0

𝐼𝑛0 " 𝐼𝑛1 ⋅ 𝑆𝑒𝑙𝑒𝑐𝑡 +𝐼𝑛0 " 𝐼𝑛1 ⋅ 𝑆𝑒𝑙𝑒𝑐𝑡 +𝐼𝑛0 ⋅ 𝐼𝑛1 ⋅ 𝑆𝑒𝑙𝑒𝑐𝑡 +𝐼𝑛0 ⋅ 𝐼𝑛1 ⋅ 𝑆𝑒𝑙𝑒𝑐𝑡

In0 In1 Select Out

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 1

1 0 0 1

1 0 1 0

1 1 0 1

1 1 1 1

Page 36: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Reminder:threebasicgates

Page 37: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Truthtabletogates(cont.)

2.𝑠𝑒𝑙𝑒𝑐𝑡 ⋅ 𝐼𝑛1 + 𝑠𝑒𝑙𝑒𝑐𝑡 ⋅ 𝐼𝑛0 (frompreviousslide)3.DrawanANDgateforeachconjunction,usingNOTfor

bars

4. DrawanORgatetocombinetheresultsoftheANDs

Page 38: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Peerinstruction• Drawthecircuitforthefollowingtruthtable(thisonehas2inputs,2outputs)

In0 In1 Out0 Out1

0 0 0 0

0 1 1 0

1 0 1 0

1 1 0 1

Answerthenumberoflogicgatesusedwhenfinished;workin3’s

Page 39: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Howdoweaddtwonumbersaddu $t0,$t1,$t2

Weknow:Thenumbersarephysicallystoredinregistersasbits

Thesumoftwonumbersisafunctionwecanimplementusingcombinationallogic

Page 40: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

Startwitha1-bitadder

+SumCarry

AB

Carryin

Page 41: CS 2630 Computer Organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...CS 2630 Computer Organization Intro to synchronous digital systems Brandon Myers University of Iowa.

2-bitadder

+

Sum0

A0B0

Carryin+

A1B1

Sum1

Carry0 Carry1