Presentation is loading. Please wait.

Presentation is loading. Please wait.

Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.3. Examples of ARM memory addressing mode.

Similar presentations


Presentation on theme: "Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.3. Examples of ARM memory addressing mode."— Presentation transcript:

1

2

3 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.3. Examples of ARM memory addressing mode.

4 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.4. ARM memory addressing modes involving writeback.

5 LDRR0,POINTERLoadaddressLOCintoR0. LDRBR1,[R0]LoadASCIIcharacters LDRBR2,[R0,#1]intoR1andR2. ANDR2,R2,#&FClearhigh-order28bitsofR2. ORRR2,R2,R1,LSL#4Or[R1]shiftedleftinto[R2]. STRBR2,PACKEDStorepackedBCDdigits intoPACKED. Figure 3.5. An ARM program for packing two 4-bit decimal digits into a byte.

6

7 LDRR1,NLoadcountintoR1. LDRR2,POINTERLoadaddressNUM1intoR2. MOVR0,#0ClearaccumulatorR0. LOOPLDRR3,[R2],#4LoadnextnumberintoR3. ADDR0,R0,R3AddnumberintoR0. SUBSR1,R1,#1DecrementloopcounterR1. BGTLOOPBranchbackifnotdone. STRR0,SUMStoresum. Figure 3.7. An ARM program for adding numbers.

8 MemoryAddressing addressordata labelOperationinformation AssemblerdirectivesAREACODE ENTRY StatementsthatLDRR1,N generateLDRR2,POINTER machineMOVR0,#0 instructionsLOOPLDRR3,[R2],#4 ADDR0,R0,R3 SUBSR1,R1,#1 BGTLOOP STRR0,SUM AssemblerdirectivesAREADATA SUMDCD0 N 5 POINTERDCDNUM1 DCD3,17,27,12,322 END Figure 3.8. ARM assembly language source program for the program in Figure 3.7.  

9 READLDRR3,[R1]Load[INSTATUS]and TSTR3,#8waitforcharacter. BEQREAD LDRBR3,[R1,#4]Readthecharacterand STRBR3,[R0],#1storeitinmemory. ECHOLDRR4,[R2]Load[OUTSTATUS]and TSTR4,#8waitfordisplay BEQECHOtobeready. STRBR3,[R2,#4]Sendcharactertodisplay. TEQR3,#CRIfnotcarriagereturn, BNEREADreadmorecharacters. Figure 3.9. An ARM program that reads a line of characters and displays it.

10 Callingprogram LDRR1,N LDRR2,POINTER BLLISTADD STRR0,SUM... Subroutine LISTADDSTMFDR13!,{R3,R14}SaveR3andreturnaddressinR14on stack,usingR13asthestackpointer. MOVR0,#0 LOOPLDRR3,[R2],#4 ADDR0,R0,R3 SUBSR1,R1,#1 BGTLOOP LDMFDR13!,{R3,R15 } RestoreR3andloadreturnaddress intoPC(R15). Figure 3.10. Program of Figure 3.7 written as an ARM subroutine; parameters passed through registers.

11 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.11. Program of Figure 3.7 written as an ARM subroutine; parameters passed on the stack.

12 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.12. Nested subroutines in ARM assembly language.

13 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.13. ARM stack frames for Figure 3.12.

14 ADRR1,AVECR1pointstovectorA. ADRR2,BVECR2pointstovectorB. LDRR3,NR3istheloopcounter. MOVR0,#0R0accumulatesthedotproduct. LOOPLDRR4,[R1],#4LoadAcomponent. LDRR5,[R2],#4LoadBcomponent. MLAR0,R4,R5,R0Multiplycomponentsand accumulateintoR0. SUBSR3,R3,#1Decrementthecounter. BNELOOPBranchbackifnotdone. STRR0,DOTPRODStoredotproduct. Figure 3.14. An ARM dot-product program.

15 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.15. An ARM byte-sorting program.

16 Subroutine INSERTIONCMPRHEAD,#0Checkiflistempty. MOVEQRHEAD,RNEWRECIfempty,insertnew MOVEQPC,R14recordashead. LDRR0,[RHEAD]Ifnotempty,checkif LDRR1,[RNEWREC]newrecordbecomes CMPR0,R1newhead,and STRGTRHEAD,[RNEWREC,#4]insertifyes. MOVGTRHEAD,RNEWREC MOVGTPC,R14 MOVRCURRENT,RHEADIfnewrecordgoesafter LOOPLDRRNEXT,[RCURRENT,#4]currenthead, CMPRNEXT,#0findwhere. STREQRNEWREC,[RCURRENT,#4]Newrecordbecomesnewtail. MOVEQPC,R14 LDRR0,[RNEXT]Gofurther? CMPR0,R1 MOVLTRCURRENT,RNEXTYes,thenloopback. BLTLOOP STRRNEXT,[RNEWREC,#4]Otherwise,insertnewrecord STRRNEWREC,[RCURRENT,#4]betweencurrentand MOVPC,R14nextrecords. Figure3.16.AnARMsubroutineforinsertinganewrecordintoalinkedlist.

17 Subroutine DELETIONLDRR0,[RHEAD]Checkifrecordtobe CMPR0,RIDNUMdeletedisthehead. LDREQRHEAD,[RHEAD,#4]Ifyes,delete MOVEQPC,R14andreturn. MOVRCURRENT,RHEADOtherwise,continuesearch. LOOPLDRRNEXT,[RCURRENT,#4]Isnextrecordtheone LDRR0,[RNEXT]tobedeleted? CMPR0,RIDNUM LDREQR0,[RNEXT,#4]Ifyes,delete STREQR0,[RCURRENT,#4]andreturn. MOVEQPC,R14 MOVRCURRENT,RNEXTOtherwise,loopback BLOOPtocontinuesearch. Figure 3.17. An ARM subroutine for deleting a record from a linked list.

18 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.18. The 68000 register structure.

19

20

21 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.21. The 68000 instruction ADD #9, DD3.

22 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.22. A 68000 route for A  [A] + [B].

23 MemoryAddressing addressordata labelOperationinformation AssemblerdirectivesCEQU$202200 ORG$201150 ADC.W639 BDC.W215 ORG$201200 StatementsthatMOVEA,D0 generatemachineADDB,D0 instructionsMOVED0,C AssemblerdirectiveEND Figure 3.23. 68000 assembly language representation for the routine in Figure 3.22. –

24

25 MOVE.LN,D1Ncontainsn,thenumberofentries tobeadded,andD1isusedas acounterthatdetermineshow manytimestoexecutetheloop. MOVEA.L#NUM1,A2A2isusedasapointertothelistentries. ItisinitializedtoNUM1,theaddress ofthefirstentry. CLR.LD0 isusedtoaccumulatethesum. LOOPADD.W(A2)+,D0SuccessivenumbersareaddedinD0. SUBQ.L#1,D1Decrementthecounter. BGTLOOPIf[D1]  0,executetheloopagain. MOVE.LD0,SUMStorethesuminSUM. Figure 3.25. A 68000 program for the addition program in Figure 2.16.

26 MOVE.LN,D1Putn1intothe SUBQ.L#1,D1counterregisterD1. MOVEA.L#NUM1,A2 CLR.LD0 LOOPADD.W(A2)+,D0 DBRAD1,LOOPLoopbackuntil[D1]= –1. MOVE.LD0,SUM Figure 3.26. An alternative 68000 program for the program in Figure 3.25. –

27 MOVEA.L#LOC,A1Initializepointerregister A1tocontainthe addressofthefirstlocationinmemory wherethecharactersaretobestored. READBTST.W#3,INSTATUSWaitforacharactertobeentered BEQREADinthekeyboardbufferDATAIN MOVE.BDATAIN,(A1)TransferthecharacterfromDATAINinto thememory(thisclearsSINto0). ECHOBTST.W#3,OUTSTATUSWaitforthedisplaytobecomeready. BEQECHO MOVE.B(A1),DATAOUTMovethecharacterjustreadtotheoutput bufferregister(thisclearsSOUTto0). CMPI.B#CR,(A1)+CheckifthecharacterjustreadisCR (carriagereturn).IfitisnotCR,then BNEREADbranchbackandreadanothercharacter. Also,incrementthepointertostorethe nextcharacter. Figure 3.27. A 68000 program that reads a line of characters and displays it.

28 Callingprogram MOVEA.L#NUM1,A2PuttheaddressNUM1inA2. MOVE.LN,D1PutthenumberofentriesninD1. BSRLISTADDCallsubroutineLISTADD. MOVE.LD0,SUMStorethesuminSUM. nextinstruction... Subroutin e LISTADDSUBQ.L#1,D1Adjustcountton1. CLR.LD0 LOOPADD.W(A2)+,D0AccumulatesuminD0. DBRAD1,LOOP RTS Figure 3.28. Program of Figure 3.26 written as a 68000 subroutine; parameters passed through registers. –

29 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.29. Program of Figure 3.26 written as a 68000 subroutine, parameters passed on the stack.

30 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.30. Nested subroutines in 68000 assembly language.

31 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.31. 68000 stack frames for Figure 3.30.

32 MOVEA.L#LOC,A0A0pointstodata. MOVE.B(A0)+,D0LoadfirstbyteintoD0. LSL.B#4,D0Shiftleftby4bitpositions. MOVE.B(A0),D1LoadsecondbyteintoD1. ANDI.B#$F,D1Clearhigh-order4bitstozero. OR.BD0,D1Concatenatethedigits. MOVE.BD1,PACKEDStoretheresult. Figure 3.32. Use of 68000 logic instructions in packing BCD digits.

33 MOVEA.L#AVEC,A1Addressoffirstvector. MOVEA.L#BVEC,A2Addressofsecondvector. MOVEN,D0Numberofelements. SUBQ#1,D0AdjustcounttouseDBRA. CLRD1UseD1asaccumulator. LOOPMOVE(A1)+,D2GetelementfromvectorA. MULS(A2)+,D2MultiplyelementfromvectorB. ADDD2,D1Accumulateproduct. DBRAD0,LOOP MOVED1,DOTPROD Figure 3.33. A 68000 program for computing the dot product of two vectors.

34 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.34. A 68000 byte-sorting program.

35 Subroutine INSERTIONCMPA.L#0,A0A0isRHEAD. BGTHEAD MOVEA.LA1,A0A1isRNEWREC. RTS HEADCMP.L(A0),(A1)CompareIDofnewrecordtohead. BGTSEARCH MOVE.LA0,4(A1)Newrecordbecomeshead. MOVEA.LA1,A0 RTS SEARCHMOVEA.LA0,A2A2isRCURRENT. LOOPMOVEA.L4(A2),A3A3isRNEXT. CMPA.L#0,A3 BEQTAIL CMP.L(A3),(A1) BLTINSERT MOVEA.LA3,A2Gotonextrecord. BRALOOP INSERTMOVE.LA2,4(A1) TAILMOVE.LA1,4(A2) RTS Figure 3.35. A 68000 subroutine to insert a record in a linked list.

36 Subroutine DELETIONCMP.L(A0),D1D1isRIDNUM. BGTSEARCH MOVEA.L4(A0),A0Deleteheadrecord. RTS SEARCHMOVEA.LA0,A2A2isRCURRENT. LOOPMOVEA.L4(A2),A3A3isRNEXT. CMP.L(A3),D1 BEQDELETE MOVEA.LA3,A2 BRALOOP DELETEMOVE.L4(A3),D2D2isRTEMP. MOVE.LD2,4(A2) RTS Figure 3.36. A 68000 subroutine to delete a record from a linked list.

37 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.37. IA-32 register structure.

38 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.38. Compatibility of the IA-32 register structure with earlier Intel processor register structures.

39 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.39. Examples of addressing modes in the IA-32 architecture.

40 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.40. IA-32 program for adding numbers.

41

42 Assemblerdirectives.data NUM1DD17,3,  51,242, 113 NDD5 SUMDD0.code Statementsthatgenerate machineinstructions MAIN:LEAEBX,NUM1 SUBEBX,4 MOVECX,N MOVEAX,0 STARTADD :ADDEAX,[EBX+ECX4] LOOPSTARTADD MOVSUM,EAX AssemblerdirectiveENDMAIN Figure 3.42. Complete IA-32 assembly language representation for the program in Figure 3.40b. * 

43 LEAEBP,LOCEBPpointstofirstbyte. MOVAL,[EBP]LoadfirstbyteintoAL. SHLAL,4Shiftleftby4bitpositions. MOVBL,[EBP+1]LoadsecondbyteintoBL. ANDBL,0FHClearhigh-order4bitstozero. ORAL,BLConcatenatetheBCDdigits. MOVPACKED,ALStoretheresult. Figure 3.43. An IA-32 routine to pack two BCD digits into a byte.

44 LEAEBP,LOCEBPpointstomemoryarea. READ:BTINSTATUS,3Waitforcharactertobe JNCREADenteredintoDATAIN. MOVAL,DATAINTransfercharacterintoAL. MOV[EBP],ALStorethecharacterinmemory INCEBPandincrementpointer. ECHO:BTOUTSTATUS,3Waitfordisplayto JNCECHObeready. MOVDATAOUT,ALSendcharactertodisplay. CMPAL,CRIfnotcarriagereturn, JNEREADreadmorecharacters. Figure 3.44. An IA-32 program that reads a line of characters and displays it.

45 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.45.Program of Figure 3.40a written as an IA-32 subroutine; parameters passed through registers.

46 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.46.Program of Figure 3.40a written as an IA-32 subroutine; parameters passed on the stack.

47 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.47. Nested subroutines in IA-32 assembly language.

48 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.48. IA-32 stack frames for Figure 3.47.

49 LEAEBP,AVECEBPpointstovectorA. LEAEBX,BVECEBXpointstovectorB. MOVECX,NECXistheloopcounter. MOVEAX,0EAXaccumulatesthedotproduct. MOVEDI,0EDIisanindexregister. LOOPSTART:MOVEDX,[EBP+EDI4]Computetheproduct IMULEDX,[EBX+EDI4]ofnextcomponents. INCEDIIncrementindex. ADDEAX,EDXAddtoprevioussum. LOOPLOOPSTARTBranchbackifnotdone. MOVDOTPROD,EAXStoredotproductinmemory. Figure 3.49. IA-32 dot product program. * *

50 Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.50. An IA-32 byte-sorting program using straight-selection sort.

51 Subroutine INSERTION:MOVRNEWID,[RNEWREC] CMPRHEAD,0Checkiflistempty. JGHEAD MOVRHEAD,RNEWRECIfyes,newrecordbecomes RETone-entrylist. HEAD:CMPRNEWID,[RHEAD]Checkifnewrecord becomeshead. JGSEARCH MOV[RNEWREC+4],RHEADIfyes,makenewrecord MOVRHEAD,RNEWRECthehead. RET SEARCH:MOVRCURRENT,RHEADOtherwise,use LOOPSTART:MOVRNEXT,[RCURRENT+4]RCURRENT CMPRNEXT,0andRNEXT JETAILtomovethrough CMPRNEWID,[RNEXT]thelisttofind JLINSERTtheinsertionpoint. MOVRCURRENT,RNEXT JMPLOOPSTART INSERT:MOV[RNEWREC+4],RNEXT TAIL:MOV[RCURRENT+4],RNEWREC RET Figure 3.51. An IA-32 subroutine for inserting a new record into a linked list.

52 Subroutine DELETION:CMPRIDNUM,[RHEAD]Checkifhead. JGTSEARCH MOVRHEAD,[RHEAD+4]Ifyes,remove. RET SEARCH:MOVRCURRENT,RHEADOtherwise, LOOPSTART:MOVRNEXT,[RCURRENT+4]useRCURRENT CMPRIDNUM,[RNEXT]andRNEXT JEQDELETEtomovethrough MOVRCURRENT,RNEXTthelistto JMPLOOPSTARTfindtherecord. DELETE:MOVRTEMP,[RNEXT+4] MOV[RCURRENT+4],RTEMP RET Figure 3.52. An IA-32 subroutine for deleting a record from a linked list.

53 Program1 2 CLR.LD0MOVE.W#$FFFF,D0 MOVEA.L#LIST,A0MOVEA.L#LIST,A0 LOOPMOVE.W(A0)+,D1LOOPLSL.W(A0)+ BGELOOPBCCLOOP ADDQ.L#1,D0LSL.W#1,D0 CMPI#17,D0BCSLOOP BLTLOOPMOVE.W2(A0),RSLT MOVE.W2(A0),RSLT Figure P3.1. Two 68000 programs for Problem 3.29. – –

54 Please see “portrait orientation” PowerPoint file for Chapter 3 Table 3.1. ARM index addressing modes

55 Please see “portrait orientation” PowerPoint file for Chapter 3 Table 3.2. 68000 addressing modes.

56 Please see “portrait orientation” PowerPoint file for Chapter 3 Table 3.3. IA-32 addressing modes


Download ppt "Please see “portrait orientation” PowerPoint file for Chapter 3 Figure 3.3. Examples of ARM memory addressing mode."

Similar presentations


Ads by Google