0% found this document useful (0 votes)
303 views3 pages

354 39 Solutions Instructor Manual 10 8051 Instruction Set Programming Chapter 10

The document provides solutions to programming exercises for the 8051 instruction set. It includes programs to multiply two numbers in RAM and store in external RAM, divide a number in RAM by another and store the result in two locations, search a block of RAM for a data and store its address, and arrange a block of binary numbers in ascending order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
303 views3 pages

354 39 Solutions Instructor Manual 10 8051 Instruction Set Programming Chapter 10

The document provides solutions to programming exercises for the 8051 instruction set. It includes programs to multiply two numbers in RAM and store in external RAM, divide a number in RAM by another and store the result in two locations, search a block of RAM for a data and store its address, and arrange a block of binary numbers in ascending order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like