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