cs 2630 computer organizationhomepage.cs.uiowa.edu/~bdmyers/cs2630_su17/public/...cs 2630 computer...
TRANSCRIPT
CS2630ComputerOrganization
IntrotosynchronousdigitalsystemsBrandonMyers
UniversityofIowa
Wherewearegoing
Instructionsetarchitecture(e.g.,MIPS)
Compiler
Memorysystem I/OsystemProcessor
Datapath&Control
Digitallogic
translatingsourcecode(CorJava)ProgramstoassemblylanguageAndlinkingyourcodetoLibrarycode
HowthesoftwaretalksTothehardware
HowaprocessorrunsMIPSPrograms!
Howswitches(1or0)canbeusedtobuildInterestingfunctions:fromintegerarithmetictoprogrammablecomputers
..thenthisisnext!!
awordonextralayersinJava
A“secret”aboutJava…
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)
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
Administrivia• HW3duetoday• HW4availablesoon• Lab4:CombinationallogicinLogisim thisweek
Wherewearegoing
Instructionsetarchitecture(e.g.,MIPS)
Compiler
Memorysystem I/OsystemProcessor
Datapath&Control
Digitallogic
translatingsourcecode(CorJava)ProgramstoassemblylanguageAndlinkingyourcodetoLibrarycode
HowthesoftwaretalksTothehardware
HowaprocessorrunsMIPSPrograms!
Howswitches(1or0)canbeusedtobuildInterestingfunctions:fromintegerarithmetictoprogrammablecomputers
done
Conceptmapping• Purpose:illustratethecurrentstructureofCS2630conceptsinyourhead,formnewconceptrelationships
• Groupsof3,findaboardspaceanywhere
• Buildaconceptmap(incomputerscientistspeak,itisagraphnotamap)• eachterm(onthesheet)goesinavertex• connectrelatedtermswithanedge;labeltheedgetodescribetherelationship
• After~10minutes,wewillstopsoyoucantourothergroups’conceptmaps
“Synchronousdigitalsystems”• We’llbedesigningcircuitsusingtwoveryconvenientabstractions ofelectricalcircuits• digital:voltageisquantizedintotwovalues:0and1,allowingustocombinecomponentswithoutincreasingcomplexity• synchronous:timeisdiscrete,thatis,timeadvancesindistinctstepsandthevaluesonallthewireschangesatthesesteps
Digitalabstraction• Composecircuitswithoutthemaffectingeachother• Why?outputsare“perfect”highandlowvoltages
NANDNAND
01
11
1
Synchronousabstraction• timeisdiscrete• timeadvancesindistinctstepsandthevaluesonallthewireschangesatthesesteps
“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
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:(𝐴 " 𝐵) + (𝐴 " 𝐶)
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
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
Peerinstruction• Whichlogicequationdescribesthistruthtable?
a) 𝐶 = 𝐴 " 𝐵b) 𝐶 = �̅� " 𝐵@c) 𝐶 = 𝐴 + 𝐵d) 𝐶 = 𝐴 " 𝐵
A B C
0 0 1
0 1 1
1 0 1
1 1 0
Thebasiccomponent:aswitch
Currentflowsfromthebatterywhenthereisacompletecircuit
Whentheswitchisclosed(connectsthecircuit),thecurrentflowstothelight
Whentheswitchisopen(disconnectsthecircuit),thecurrentdoesnotflowtothelight
0 10
0 10
AB
Buildinglogicfromswitches
Twoswitchesconnectedinparallel.Atleastonemustbeclosedforthebulbtoturnon
Twoswitchesconnectedinseries.Bothmustbeclosedforthebulbtoturnon
LogicgatesA
B
AB C
C
AB
C
A B
C
Thestateoftheswitchistheinputtothecircuit
PeerinstructionWhatisthetruthtableforthiscircuit?
a
b
c
d
a b c d
Controllingtheswitches• Tocomposetwogates,weneedtobeabletochangethestateoftheswitchesofthesecondgatewiththeoutputofthefirstgate
A
B
C
DE
A
B
C
C DE
(output)
(input)
CS2630ComputerOrganization
Transistors,combinationallogicBrandonMyers
UniversityofIowa
Controllingtheswitches• Tocomposetwogates,weneedtobeabletochangethestateoftheswitchesofthesecondgatewiththeoutputofthefirstgate
A
B
C
DE
A
B
C
C DE
(output)
(input)
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
HowdoesnMOS transistorwork?
Madeofasubstrateofp-typematerial(positivebiased).Drainandsourcearen-typematerial(negativebiased).a) gateisgiven0volts:diodesbetweensource/substrateanddrain/substrateare
reversebiasedsonocurrentflows(transistorisOFF)b) gateisgiven1volt:causesanegativechargeinthesubstratenearthegate;thisarea
ofnegativechargeiscalledthechannel.Nowcurrentflowsfromsourcetodrain(transistorisON)
Controllingtheswitches• Youcoulddoitthisway,BUTitturnsoutthatnMOS arebadatpassinghighvoltageandpMOS arebadatpassinglowvoltage
A
B
C
DE
A
B C
C DE
C D
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)
Peerinstruction
inputA inputB output
fillinthetruthtable
Onclicker,enteradescriptionofwhatitdoes.
Exampleofcomposingmanygates
CMOSlet’susbuildlargecomplexcircuitsoutofgatesbecausetheoutputisa“perfect”1or0eveniftheinputatthegatesis”imperfect”(i.e.avoltageinbetween)
Nowthatweknowhowtoarrangetransistorsinawaythatwecansafelycomposelogicgatestogether,let’sbuildbiggercircuits!
Ingredientsforaprocessor• Combinationallogic• arithmeticandbitwiseoperations• multiplexors(pick1outofofNinputs)• controllogic• branchcalculation• addresscalculation
• Synchronouslogic(we’llgettotheselater)• registers• programcounter,orPC• datamemory• instructionmemory
startlearninghowtobuildthesecombinationallogiccircuits
• Selectbit=0meanspassfirstinputtooutput
• Selectbit=1meanspasssecondinputtooutput
Multiplexor(MUX)picksbetweentwoinputs
select
inputdata output
data
shownareMUXswithadatawidthof3bits
YoucanbuildaMUXwithanydatawidth
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 "
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
Reminder:threebasicgates
Truthtabletogates(cont.)
2.𝑠𝑒𝑙𝑒𝑐𝑡 ⋅ 𝐼𝑛1 + 𝑠𝑒𝑙𝑒𝑐𝑡 ⋅ 𝐼𝑛0 (frompreviousslide)3.DrawanANDgateforeachconjunction,usingNOTfor
bars
4. DrawanORgatetocombinetheresultsoftheANDs
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
Howdoweaddtwonumbersaddu $t0,$t1,$t2
Weknow:Thenumbersarephysicallystoredinregistersasbits
Thesumoftwonumbersisafunctionwecanimplementusingcombinationallogic
Startwitha1-bitadder
+SumCarry
AB
Carryin
2-bitadder
+
Sum0
A0B0
Carryin+
A1B1
Sum1
Carry0 Carry1