Countervaluecanbesetdependingontheresultofsomethinginthestatusflagsregister, sowecanusethistobranchandwe'llseeanexampleofthatlaterononfinallyusuallyhave a sectionofimportantoutputorcommunication.
SothisishowwegetdataintoanoutoftheCPU.
Thepurposeandsophisticationof a CPUdependsonwhatparthasgotinside.
TheseareupcodesonDhe, thefirstopera, andisgoingtobetheRegister, whichweretargetingwiththeadditiononthesecond, ourfriendisgoingtobe a valueorregister, andthefourthinstructionisgoingtobe a jumpandthefirstoperaandisgoingtobetheconditiononwhichwejumpandsecondoffbrandwillbethelocationofwherewe'regoingtojumpto.
Thiswillbecome a bitmoreclearwhenwestartwritingsomecodelateron.
RCPcouldonlymovestuffatstuffs, obstructstuffonjobto a differentlocation.
Sothefirstoperaandhereisour A, whichwesawinourCPUmeansregister a secondopera I'veputinsquarebracketsandthismeanswewantthesourceofthemovetobefrommemoryaddressnumberthree.
Unlikethisonehere, where I havenotusedthesquarebracketsarewhat I'm implyingbythisthing.
Thisuparoundisthatwewanttomovethevaluezerointoregister, see, sowecanloadin a constantvalueorwecanreadfrommemory.
Sowe'vedone a successfulmultiplyonthisprogramdemonstrateswhatistypicallyassumedbymostpeopledon't reallyknowassemblyline, whichisthattheythinkitishardmustbecausewedidn't have a multiplyinstructiontohelpusout.
Sowehavetodoitthelongwayaround.
IfourlittleCPUdidhave a multiplyinstruction, we'd onlyneedtocallittheonce.
Wewouldn't needtosetup a loop.
Wewouldn't needtomanagetheregistersasmuch.
Let's nowconsider a slightlymorerealworldexample.
So I'm usingofthevisualstudioenvironmentheretolookatsome X 86 compiledassemblylanguage.
So I wouldliketohighlightthelineandpresscontrolin F 10 on.
What I'vesetuphereinthedebugwindowisif I getittoshowfirstofallthedisassembly, itgoes a bitsmall, and I can't zoominunfortunately, visualstudio.
Soyou'llhavetobearwithmeonthatonintheregisters.
I'vegotthewell, I'vegottheregisterwindowviewingatthebottomheresowecanseethatinthe X 86.
Andit's mostsimplelevel.
Wehavesomeregisters.
E x p b x e c x e d x.
Thesearelike a R a, R, B, r, C and R D thatwehadbefore, andwe'vealsogotsomeflags.
Well, let's have a lookatthecodethatitproducedsowecanseefrommylineof C codeheretheend A equals 10.
Westoredthevalue 10 intheaddresspointedtobuy a using a movecommandjustaswedidbefore.
Soit's obviouslyinHexidecimalhere.
Thesamegoesfor B wasstoringthevaluethreeatthelocationpointedtobuythevariable B.
Let's have a lookathowithandlestheinstruction, sothefirstthingisdoingisloadingfromthememorywerevariable a start.
It's loadingitinto E a X, andwecanseeheredownhereintheregisterwindow.
That X hasnowbeensetto 10 inhex, ofcourse, whichis a The X 86 doeshave a multiplyinstruction, andwecanseeitusesthe E X Register, whichispreloadedwiththevalue 10 onitsusingdirectlyformemory, thevaluestoredwhereverthevariable B is.
Let's have a lookatsomedifferencesbetweentheCPUarchitecture, Soif I choosetooperateinthefloatingpointdomainnowinsteadoftheinterview, howdoesitresolvethis?
Let's take a look, andwhenwelookatthis, westarttoseewhyAssemblylanguagehas a bitof a reputationforbeingtough.
Whatisgoingonhere?
Well, let's justhave a lookatthecommandsthatarebeingusedfirst.
Sothefirstthingwecouldseethereis a movecommand.
Itis a slightlydifferentmovecommandtobefore, butit's stillthesamethings.
Theprincipleisthesame, andwecouldsee.
Actually, thereis a multiplycommandsdownhere, buteverythingelselooks a lotmorecomplicated.
Whyisthis?
The X 86 processorhassomeextensionspecificallyfordealingwithfloatingpointon.
Eventhoughthislookshorrific, wecandisablesomeofthesecompile a settingssowecanusesimpler.
AndalthoughextensionsoftheCPU.
Soif I gointotheprojectpropertiesforthisprogramandgotothecodegeneration, I canspecifywhichsetsofextensionsareaccusedforfloatingpointcalculations, so I'm goingtodisablethementirely.
It's notuncommontosee a systemarounddecreasebygig.
Becauseit's Matt.
That's addressspaceovertothegraphicscount.
I willemphasizethatwhatwe'reseeingtodayis a verysimplifiedviewofassemblylanguage, althoughitshouldgiveyou a tasteofhowusefulitcouldbe, youmightthink, Whywould I everneedtoprogramlikethis?
Thisisn't coderelated, and I'm notgoingtogetintothehabitofwearingmypersonalviewsbuttherecenteventsinManchesterhavehit a littletooclosetohomeformetoignore.
Untilrecently, I livedandworkedinManchesterCityCentrefor 12 yearsandstillhavemanycloseconnectionstothecity.