资源描述:
《微机原理ch04arthimeticandlogicalinstructionsandprograms》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、4ARTHIMETICANDLOGICALINSTRUCTIONSANDPROGRAMS4.1USINGADDITIONANDSUBTRATION4.1.1AdditionofunsignednumbersTheformoftheADD/ADCinstructionis:adddest,source;dest=dest+sourceadcdest,source;dest=dest+source+CFTheinstructionsADDandADCareusedtoaddtwooperands.Thedestinationoper
2、andcanbe:laregisterlinmemoryThesourceoperandcanbe:laregisterlinmemory,orlimmediateRememberthatmemory-to-memoryoperationareNEVERallowedin80x86assemblylanguage.TheinstructioncouldchangeanyoftheZF,SF,AF,CF,orPFbitoftheflagregister,dependingontheoperandsinvolved.Example:
3、Showhowtheflagregisterisaffectedby:moval,0f5haddal,0bhSolution:F511110101+0B00001011---------------100000000004-48Aftertheaddition,theALregister(destination)contains00Handtheflagsareasfollows:CF=1,sincethereisacarryoutfromd7SF=0,thestatusofd7oftheresultPF=1,thenumber
4、of1siszero(zeroisanevennumber)AF=1,thereisacarryoutfromd3tod4ZF=1,theresultoftheadditioniszero(for8bits)4.1.1.1Case1:AdditionofindividualbyteandworddataExample1:Writeaprogramtocalculatethetotalof5bytesofdata.Thedecimaldataisasfollow:125,235,197,91,and48.titleprog3-1A
5、adding5bytes.modelsmall.stack64;----------------------------------.datacountequ05data1db125,235,197,91,48org0008hsumdw?;----------------------------------.codemainprocfarmovax,@datamovds,axmovcx,count;CXistheloopcountermovsi,offsetdata1;SIisthedatapointermovax,00;AXw
6、illbeholdthesumback:addal,[si];addthenextbytetoALjncover;ifnocarry,continueincah;elseaccumulatethecarryinAHover:incsi;incrementthedatapointerdeccx;decrementtheloopcounterjnzback;ifnotfinished,goaddnextbytemovsum,ax;storesummovah,4chint21h;gobacktoDOSmainendpendmain4-
7、48Codesegment4-48DatasegmentandstacksegmentExample2:Writeaprogramtocalculatethetotalsumof5wordsofdata.Thedecimaldataisasfollow:27345,28521,28533,30105,and32375titleprog3-1Badding5words.modelsmall.stack64;----------------------------------.datacountequ05data2dw27345,2
8、8521,28533,30105,32375org0010hsumdw2dup(?);----------------------------------.codemainprocfarmovax,@datamovds,axclc;clearcarrybefor