1 / 56

Please see “ portrait orientation ” PowerPoint file for Chapter 3

Please see “ portrait orientation ” PowerPoint file for Chapter 3. Figure 3.3 . Examples of ARM memory addressing mode. Please see “ portrait orientation ” PowerPoint file for Chapter 3. Figure 3.4. ARM memory addressing modes involving writeback. LDR. R0,POINTER. Load. address. LOC. in.

paytah
Télécharger la présentation

Please see “ portrait orientation ” PowerPoint file for Chapter 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. LDR R0,POINTER Load address LOC in to R0. LDRB R1,[R0] Load ASCI I c haracters LDRB R2,[R0,#1] in to R1 and R2. AND R2,R2,#&F Clear high-order 28 bits of R2. ORR R2,R2,R1,LSL #4 Or [R1] shifted left in to [R2]. STRB R2,P A CKED Store pac k ed BCD digits in to P A CKED. Figure 3.5. An ARM program for packing two 4-bit decimal digits into a byte.

  4. LDR R1,N Load coun t in to R1. LDR R2,POINTER Load address NUM1 in to R2. MOV R0,#0 Clear accum ulator R0. LOOP LDR R3,[R2],#4 Load next n um b er in to R3. ADD R0,R0,R3 Add n umber in to R0. SUBS R1,R1,#1 Decremen t lo op coun ter R1. BGT LOOP Branc h back if not done. STR R0,SUM Store sum. Figure 3.7. An ARM program for adding numbers.

  5. Memory Addressing address or data lab el Operation information Assembler directives AREA CODE ENTR Y Statements that LDR R1,N generate LDR R2,POINTER mac hine MO V R0,#0 instructions LOOP LDR R3,[R2],#4 ADD R0,R0,R3 SUBS R1,R1,#1 BGT LOOP STR R0,SUM Assembler directives AREA D A T A SUM DCD 0 N DCD 5 POINTER DCD NUM1   NUM1 DCD 3, 17,27, 12,322 END Figure 3.8. ARM assembly language source program for the program in Figure 3.7.

  6. READ LDR R3,[R1] Load [INST A TUS] and TST R3,#8 w ait for c haracter. BEQ READ LDRB R3,[R1,#4] Read the c haracter and STRB R3,[R0],#1 store it in memory . ECHO LDR R4,[R2] Load [OUTST A TUS] and TST R4,#8 w ait for displa y BEQ ECHO to b e ready . STRB R3,[R2,#4] Send c haracter to displa y . TEQ R3,#CR If not carriage return, BNE READ read more c haracters. Figure 3.9. An ARM program that reads a line of characters and displays it.

  7. Calling program LDR R1,N LDR R2,POINTER BL LIST ADD STR R0,SUM . . . Subroutine LIST ADD STMFD R13!, { R3,R14 } Sa v e R3 and return address in R14 on stac k, using R13 as the stac k p oin ter. MO V R0,#0 LOOP LDR R3,[R2],#4 ADD R0,R0,R3 SUBS R1,R1,#1 BGT LOOP LDMFD R13!, { R3,R15 } Restore R3 and load return address in to PC (R15). Figure 3.10. Program of Figure 3.7 written as an ARM subroutine; parameters passed through registers.

  8. 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.

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

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

  11. ADR R1,A VEC R1 p oin ts to v ector A. ADR R2,BVEC R2 p oin ts to v ector B. LDR R3,N R3 is the lo op coun ter. MO V R0,#0 R0 accum ulates the dot pro duct. LOOP LDR R4,[R1],#4 Load A comp onent. LDR R5,[R2],#4 Load B comp onent. MLA R0,R4,R5,R0 Multiply comp onen ts and accum ulate in to R0. SUBS R3,R3,#1 Decrement the coun ter. BNE LOOP Branch back if not done. STR R0,DOTPR OD Store dot pro duct. Figure 3.14. An ARM dot-product program.

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

  13. Figure 3.16. An ARM subroutine for inserting a new record in to a link ed list. Subroutine INSER TION CMP RHEAD,#0 Chec k if list empt y . MO VEQ RHEAD,RNEWREC If empt y , insert new MO VEQ PC,R14 record as head. LDR R0,[RHEAD] If not empt y , c hec k if LDR R1,[RNEWREC] new record b ecomes CMP R0,R1 new head, and STR GT RHEAD,[RNEWREC,#4] insert if y es. MO V GT RHEAD,RNEWREC MO V GT PC,R14 MO V R CURRENT,RHEAD If new record go es after LOOP LDR RNEXT,[R CURRENT,#4] curren t head, CMP RNEXT,#0 find where. STREQ RNEWREC,[R CURRENT,#4] New record b ecomes new tail. MO VEQ PC,R14 LDR R0,[RNEXT] Go further? CMP R0,R1 MO VL T R CURRENT,RNEXT Y es, then lo op bac k. BL T LOOP STR RNEXT,[RNEWREC,#4] Otherwise, insert new record STR RNEWREC,[R CURRENT,#4] b et w een curren t and MO V PC,R14 next records.

  14. Subroutine DELETION LDR R0,[RHEAD] Chec k if record to b e CMP R0,RIDNUM deleted is the head. LDREQ RHEAD,[RHEAD,#4] If y es, delete MO VEQ PC,R14 and return. MO V R CURRENT,RHEAD Otherwise, con tin ue searc h. LOOP LDR RNEXT,[RCURRENT,#4] Is next record the one LDR R0,[RNEXT] to b e deleted? CMP R0,RIDNUM LDREQ R0,[RNEXT,#4] If y es, delete STREQ R0,[R CURRENT,#4] and return. MO VEQ PC,R14 MO V R CURRENT,RNEXT Otherwise, lo op bac k B LOOP to con tin ue searc h. Figure 3.17. An ARM subroutine for deleting a record from a linked list.

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

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

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

  18. Memory Addressing address or data lab el Op eration information Assem bler directiv es C EQU $202200 OR G $201150 A DC.W 639 – B DC.W 215 OR G $201200 Statemen ts that MO VE A,D0 generate mac hine ADD B,D0 instructions MO VE D0,C Assembler directiv e END Figure 3.23. 68000 assembly language representation for the routine in Figure 3.22.

  19. MO VE.L N,D1 N con tains n , the n um b er of en tries to b e added, and D1 is used as a coun ter that determines ho w many times to execute the lo op. MO VEA.L #NUM1,A2 A2 is used as a p oin ter to the list en tries. It is initialized to NUM1, the address of the first en try . CLR.L D0 D0 is used to accum ulate the sum. LOOP ADD.W (A2)+,D0 Successiv e n um b ers are added in D0. SUBQ.L #1,D1 Decremen t the coun ter. BGT LOOP If [D1]  0, execute the lo op again. MO VE.L D0,SUM Store the sum in SUM. Figure 3.25. A 68000 program for the addition program in Figure 2.16.

  20. MO VE.L N,D1 Put n 1 in to the SUBQ.L #1,D1 coun ter register D1. MO VEA.L #NUM1,A2 CLR.L D0 LOOP ADD.W (A2)+,D0 –1. DBRA D1,LOOP Loop bac k un til [D1]= MO VE.L D0,SUM Figure 3.26. An alternative 68000 program for the program in Figure 3.25.

  21. MO VEA.L #LOC,A1 Initialize p oin ter register A1 to con tain the address of the first lo cation in memory where the c haracters are to b e stored. READ BTST.W #3, INST A TUS W ait for a c haracter to b e en tered BEQ READ in the k eyb oard buffer DATAIN MO VE.B D A T AIN,(A1) T ransfer the c haracter from D A T AIN in to the memory (this clears SIN to 0). ECHO BTST.W #3,OUTST A TUS W ait for the displa y to b ecome ready . BEQ ECHO MO VE.B (A1),D A T A OUT Mo v e the c haracter just read to the output buffer register (this clears SOUT to 0). CMPI.B #CR,(A1)+ Chec k if the c haracter just read is CR (carriage return). If it is not CR, then BNE READ branc h bac k and read another c haracter. Also, incremen t the p oin ter to store the next c haracter. Figure 3.27. A 68000 program that reads a line of characters and displays it.

  22. Calling program MO VEA.L #NUM1,A2 Put the address NUM1 in A2. MO VE.L N,D1 Put the n um b er of en tries n in D1. BSR LIST ADD Call subroutine LIST ADD. MO VE.L D0,SUM Store the sum in SUM. next instruction . . . Subroutine – LIST ADD SUBQ.L #1,D1 Adjust coun t to n 1. CLR.L D0 LOOP ADD.W (A2)+,D0 Accum ulate sum in D0. DBRA D1,LOOP R TS Figure 3.28. Program of Figure 3.26 written as a 68000 subroutine; parameters passed through registers.

  23. 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.

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

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

  26. MO VEA.L #LOC,A0 A0 p oin ts to data. MO VE.B (A0)+,D0 Load first b yte in to D0. LSL.B #4,D0 Shift left b y 4 bit p ositions. MO VE.B (A0),D1 Load second b yte in to D1. ANDI.B #$F,D1 Clear high-order 4 bits to zero. OR.B D0,D1 Concatenate the digits. MO VE.B D1,P A CKED Store the result. Figure 3.32. Use of 68000 logic instructions in packing BCD digits.

  27. MO VEA.L #A VEC,A1 Address of first v ector. MO VEA.L #BVEC,A2 Address of second v ector. MO VE N,D0 Num b er of elemen ts. SUBQ #1,D0 Adjust coun t to use DBRA. CLR D1 Use D1 as accum ulator. LOOP MO VE (A1)+,D2 Get elemen t from v ector A. MULS (A2)+,D2 Multiply elemen t from v ector B. ADD D2,D1 Accum ulate pro duct. DBRA D0,LOOP MO VE D1,DOTPR OD Figure 3.33. A 68000 program for computing the dot product of two vectors.

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

  29. Subroutine INSER TION CMP A.L #0,A0 A0 is RHEAD. BGT HEAD MO VEA.L A1,A0 A1 is RNEWREC. R TS HEAD CMP .L (A0),(A1) Compare ID of new record to head. BGT SEAR CH MO VE.L A0,4(A1) New record b ecomes head. MO VEA.L A1,A0 R TS SEAR CH MO VEA.L A0,A2 A2 is R CURRENT. LOOP MO VEA.L 4(A2),A3 A3 is RNEXT. CMP A.L #0,A3 BEQ T AIL CMP .L (A3),(A1) BL T INSER T MO VEA.L A3,A2 Go to next record. BRA LOOP INSER T MO VE.L A2,4(A1) T AIL MO VE.L A1,4(A2) R TS Figure 3.35. A 68000 subroutine to insert a record in a linked list.

  30. Subroutine DELETION CMP .L (A0),D1 D1 is RIDNUM. BGT SEAR CH MO VEA.L 4(A0),A0 Delete head record. R TS SEAR CH MO VEA.L A0,A2 A2 is R CURRENT. LOOP MO VEA.L 4(A2),A3 A3 is RNEXT. CMP .L (A3),D1 BEQ DELETE MO VEA.L A3,A2 BRA LOOP DELETE MO VE.L 4(A3),D2 D2 is R TEMP . MO VE.L D2,4(A2) R TS Figure 3.36. A 68000 subroutine to delete a record from a linked list.

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

  32. 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.

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

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

  35. .data NUM1 DD 17 , 3 , 51 , 242 ,  113 N DD 5 Assem bler directiv es SUM DD 0 .co de MAIN : LEA EBX , NUM1 SUB EBX , 4 MO V ECX , N Statemen ts that generate MO V EAX , 0 mac hine instructions * STARTADD : ADD EAX , [EBX +ECX 4] LOOP ST AR T ADD MO V SUM , EAX Assem bler directiv e END MAIN Figure 3.42. Complete IA-32 assembly language representation for the program in Figure 3.40b.

  36. LEA EBP ,LOC EBP p oin ts to first b yte. MO V AL,[EBP] Load first b yte in to AL. SHL AL,4 Shift left b y 4 bit p ositions. MO V BL,[EBP+1] Load second b yte in to BL. AND BL,0FH Clear high-order 4 bits to zero. OR AL,BL Concatenate the BCD digits. MO V P A CKED,AL Store the result. Figure 3.43. An IA-32 routine to pack two BCD digits into a byte.

  37. LEA EBP ,LOC EBP p oin ts to memory area. READ: BT INST A TUS,3 W ait for c haracter to b e JNC READ en tered in to D A T AIN. MO V AL,DATAIN T ransfer c haracter in to AL. MO V [EBP],AL Store the c haracter in memory INC EBP and incremen t pointer. ECHO: BT OUTST A TUS,3 W ait for displa y to JNC ECHO b e ready . MO V D A T A OUT,AL Send c haracter to displa y . CMP AL,CR If not carriage return, JNE READ read more c haracters. Figure 3.44. An IA-32 program that reads a line of characters and displays it.

  38. 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.

  39. 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.

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

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

  42. LEA EBP ,A VEC EBP p oin ts to v ector A. LEA EBX,BVEC EBX p oin ts to v ector B. MO V ECX,N ECX is the lo op coun ter. MO V EAX,0 EAX accum ulates the dot pro duct. MO V EDI,0 EDI is an index register. * LOOPST AR T: MO V ED X,[EBP+EDI 4] Compute the pro duct * IMUL ED X,[EBX+EDI 4] of next comp onen ts. INC EDI Incremen t index. ADD EAX,ED X Add to previous sum. LOOP LOOPST AR T Branc h bac k if not done. MO V DOTPR OD,EAX Store dot pro duct in memory . Figure 3.49. IA-32 dot product program.

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

More Related