Sie sind auf Seite 1von 3

91

Chapter10
8051instructionsetandprogramming
SolutionstoProgrammingExercises
1. Writeaprogramtomultiplytwo8bitnumbersintheinternalRAMandstoretheresult
intheexternalRAM.[Hint:UseMOVXinstructiontoaccessexternalmemory]
MOVDPTR,#8000H ;LoadthedatapointerwithexternalRAMaddress
MOVA,30H ;getthedatafrom30HtotheAccumulator.
MOVF0H,31H ;getthenextdatatoBregisterF0HSFR.
MULAB ;multiplythetwonumbers
MOVX@DPTR,A ;movethelower8bitstoexternalRAM
INCDPTR ;PointtonextexternalRAM
MOVA,F0H ;bringnextdatatoAregister
MOVX@DPTR,A ;movethehigher8bitresulttoexternalRAM
LOOP:SJMPLOOP

2. WriteaprogramtodivideanumberintheinternalRAMlocation40Hbythenumberin
thelocation41H.Storethequotientin50Handtheremainderin51H.
MOVA,40H ;LoadthedividendtoAregister
MOVF0H,41H ;LoadthedivisortoBregister
DIVAB ;divide
MOV50H,A ;storethequotientto50H
MOV51H,F0H ;storetheremainderfromBregisterto51H
LOOP:SJMPLOOP
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
92
3. WriteaprogramtosearchforaparticulardatainablockofinternalRAM.Identifyand
storethememorylocationofthatdata.
MOVR0,#30H ;initializeR0withstartingaddressofRAM
MOVR1,#60H ;initializeR1withaddresstostorethememoryaddress
LOOP:MOVA,@R0 ;getthedatafromtheRAMtoAregister
CJNEA,#DATA,NEXT;comparethesearchdataandifnotequal,jump
MOVA,R0 ;BringtheaddresstoAregisterand
MOV@R1,A ;storetheaddresstomemorylocation
INCR1 ;pointtonextstorageaddress
NEXT:INCR0 ;incrementthesourcepointerinR0.
CJNER0,#COUNT,LOOP;checkwhetheralldatasearchedandloop.
HERE:SJMPHERE ;stophere
4. Writeaprogramtoarrangeablockofbinarynumbersinascendingorder.

SolutionstoThinkandAnswerExercises
1. FindthephysicaljumpingaddressaftertheexecutionoftheinstructionSJMPF0H,ifitis
storedintheaddress8811H.
AfterthefetchingoftheSJMPinstruction,thePCcontentis8813H.TheSJMP
instructionwilladdthe2scomplementofF0withthe8813H.So,thePCcontentwillbe
8803H.
2. Findtheshortjumpinstructionwhichisusedtojumptothesameinstructionwherethis
instructionisstored.
LOOP:SJMPFEH.ThisinstructionwilljumptothesameaddressLOOP.
3. Explainthedifferencebetweenthefollowinginstructions:
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011
93
JB 30H, 4EH
JBC 30H, 4EH
JBinstructionwilljumpifthebitaddress30Hcontentissettotherelative
address.
JBCinstructionwilljumptotherelativeaddressifthecontentof30Hissetand
itwillalsoresetthecorrespondingcontentofthebitaddress.
Microprocessors and Microcontrollers Kumar, Saravanan & Jeevananthan
Oxford University Press 2011

Das könnte Ihnen auch gefallen