please see “portrait orientation” powerpoint file for chapter 3 figure 3.3. examples of arm...

Post on 04-Jan-2016

224 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Figure 3.1. ARM register structure.

31 29 7 0

Program counter

R0

R1

31 0

R14

31 0

Status28

R15 (PC)

30 6 4CPSR

N - NegativeZ - Zero

C - CarryV- Overflow

Condition code flags

Processor mode bits

register

Interrupt disable bits

Generalpurposeregisters

15

Figure 3.2. ARM instruction format.

Condition

31

OP code

28 27 20 19 16 15 12 11 4 3 0

Rn Rd Other info Rm

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 LoadaddressLOC into R0.LDRB R1,[R0] Load ASCI I charactersLDRB R2,[R0,#1] into R1 and R2.AND R2,R2,#&F Clearhigh-order28bitsofR2.ORR R2,R2,R1,LSL#4 Or [R1]shifted left into [R2].STRB R2,PACKED Storepacked BCDdigits

intoPACKED.

Figure 3.5. An ARM program for packing two 4-bit decimal digits into a byte.

Figure 3.6. ARM branch instructions.

Condition

31

OP code

28 27

Offset

24 23 0

(a) Instruction format

1000

LOCATION = 1100

BEQ LOCATION

(b) Determination of a branch target address

Branch target instruction

1004

updated [PC] = 1008

Offset = 92

LDR R1,N Loadcount into R1.LDR R2,POINTER LoadaddressNUM1 into R2.MOV R0,#0 Clearaccumulator R0.

LOOP LDR R3,[R2],#4 Loadnextnumber into R3.ADD R0,R0,R3 Add numberinto R0.SUBS R1,R1,#1 Decrement loopcounterR1.BGT LOOP Branchback ifnotdone.STR R0,SUM Storesum.

Figure 3.7. An ARM program for adding numbers.

Memory Addressingaddress or datalabel Operation information

Assemblerdirectives AREA CODEENTRY

Statementsthat LDR R1,Ngenerate LDR R2,POINTER

machine MOV R0,#0instructions LOOP LDR R3,[R2],#4

ADD R0,R0,R3SUBS R1,R1,#1BGT LOOPSTR R0,SUM

Assemblerdirectives AREA DATASUM DCD 0N DCD 5POINTER DCD NUM1NUM1 DCD 3, 17,27, 12,322

END

Figure 3.8. ARM assembly language source program for the program in Figure 3.7.

READ LDR R3,[R1] Load[INSTATUS] andTST R3,#8 wait forcharacter.BEQ READLDRB R3,[R1,#4] Readthecharacter andSTRB R3,[R0],#1 storeit inmemory.

ECHO LDR R4,[R2] Load[OUTSTATUS] andTST R4,#8 wait fordisplayBEQ ECHO to beready.STRB R3,[R2,#4] Sendcharactertodisplay.TEQ R3,#CR If notcarriagereturn,BNE READ readmorecharacters.

Figure 3.9. An ARM program that reads a line of characters and displays it.

Callingprogram

LDR R1,NLDR R2,POINTERBL LISTADDSTR R0,SUM...

Subroutine

LISTADD STMFD R13!,{ R3,R14} Save R3andreturnaddressinR14onstack,usingR13as thestack pointer.

MOV R0,#0LOOP LDR R3,[R2],#4

ADD R0,R0,R3SUBS R1,R1,#1BGT LOOPLDMFD R13!,{ R3,R15} RestoreR3and loadreturnaddress

intoPC(R15).

Figure 3.10. Program of Figure 3.7 written as an ARM subroutine; parameters passed through registers.

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.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.12. Nested subroutines in ARM assembly language.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.13. ARM stack frames for Figure 3.12.

ADR R1,AVEC R1 pointstovectorA.ADR R2,BVEC R2 pointstovectorB.LDR R3,N R3 is theloopcounter.MOV R0,#0 R0accumulatesthedotproduct.

LOOP LDR R4,[R1],#4 LoadA component.LDR R5,[R2],#4 LoadBcomponent.MLA R0,R4,R5,R0 Multiplycomponentsand

accumulateinto R0.SUBS R3,R3,#1 Decrementthecounter.BNE LOOP Branchback ifnotdone.STR R0,DOTPROD Storedot product.

Figure 3.14. An ARM dot-product program.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.15. An ARM byte-sorting program.

Subroutine

INSERTION CMP RHEAD,#0 Check if listempty.MOVEQ RHEAD,RNEWREC Ifempty,insertnewMOVEQ PC,R14 recordashead.LDR R0,[RHEAD] Ifnotempty, check ifLDR R1,[RNEWREC] newrecordbecomesCMP R0,R1 newhead,andSTRGT RHEAD,[RNEWREC,#4] insert if yes.MOVGT RHEAD,RNEWRECMOVGT PC,R14MOV RCURRENT,RHEAD Ifnewrecordgoesafter

LOOP LDR RNEXT,[RCURRENT,#4] currenthead,CMP RNEXT,#0 findwhere.STREQ RNEWREC,[RCURRENT,#4] Newrecordbecomesnewtail.MOVEQ PC,R14LDR R0,[RNEXT] Gofurther?CMP R0,R1MOVLT RCURRENT,RNEXT Yes,then loopback.BLT LOOPSTR RNEXT,[RNEWREC,#4] Otherwise,insertnewrecordSTR RNEWREC,[RCURRENT,#4] betweencurrent andMOV PC,R14 nextrecords.

Figure3.16.An ARMsubroutineforinsertinganewrecordinto alinkedlist.

Subroutine

DELETION LDR R0,[RHEAD] Check ifrecordtobeCMP R0,RIDNUM deletedisthehead.LDREQ RHEAD,[RHEAD,#4] If yes,deleteMOVEQ PC,R14 andreturn.MOV R CURRENT,RHEAD Otherwise,continuesearch.

LOOP LDR RNEXT,[RCURRENT,#4] Is nextrecordtheoneLDR R0,[RNEXT] tobedeleted?CMP R0,RIDNUMLDREQ R0,[RNEXT,#4] If yes,deleteSTREQ R0,[RCURRENT,#4] andreturn.MOVEQ PC,R14MOV R CURRENT,RNEXT Otherwise,loopbackB LOOP tocontinuesearch.

Figure 3.17. An ARM subroutine for deleting a record from a linked list.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.18. The 68000 register structure.

Figure 3.19. Map of addressable locations in the 68000.

ContentsaddressesWord

byte 0

byte 2

byte i

byte i+2

byte 1

byte 3

byte i+1

byte i+3

0

2

i

i+2

Long word 0

Long word i

224

1-byte224

2-byte224

2-

A1

Array

6

6 = index

100 = offset

1002

1000

Extension word

OP-code word

1108

1106

1104

1102

Operand

Figure 3.20. An example of 68000 full relative mode for the instruction ADD 100(PC,A1),D0.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.21. The 68000 instruction ADD #9, DD3.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.22. A 68000 route for A [A] + [B].

Memory Addressingaddress or datalabel Operation information

Assemblerdirectives C EQU $202200ORG $201150

A DC.W 639B DC.W 215

ORG $201200Statementsthat MOVE A,D0

generatemachine ADD B,D0instructions MOVE D0,C

Assemblerdirective END

Figure 3.23. 68000 assembly language representation for the routine in Figure 3.22.

(b) Example of using a branch instruction in the loop of Figure 2.16

[PC] = 1006 when branch address is computed

Figure 3.24. 68000 short-offset branch instructions.

(a) Short-offset branch instruction format

LOOP 1000

SUBQ.W

ADD.W

LOOP

#1,D1

(A2)+,D0

OP code

OP-code word

OP-code word

BGT

LOOP

OP code Offset

15 8 7 0

Branch address = [updated PC] + offset

Branch address

Assembly languageversion of loop

Appearance of loop in memory

1002

1004

1006

6-

1006 6 1000=-=

MOVE.L N,D1 N contains n,the number ofentriesto beadded,and D1 isusedasacounter thatdetermineshowmanytimestoexecutethe loop.

MOVEA.L #NUM1,A2 A2 isusedas a pointertothe listentries.It isinitializedto NUM1, theaddressofthefirstentry.

CLR.L D0 D0 isusedtoaccumulate thesum.LOOP ADD.W (A2)+,D0 Successive numbersareadded inD0.

SUBQ.L #1,D1 Decrement thecounter.BGT LOOP If [D1]0,executethe loopagain.MOVE.L D0,SUM Storethesumin SUM.

Figure 3.25. A 68000 program for the addition program in Figure 2.16.

MOVE.L N,D1 Put n 1 intotheSUBQ.L #1,D1 counterregisterD1.MOVEA.L #NUM1,A2CLR.L D0

LOOP ADD.W (A2)+,D0DBRA D1,LOOP Loopbackuntil [D1]=–1.MOVE.L D0,SUM

Figure 3.26. An alternative 68000 program for the program in Figure 3.25.

MOVEA.L #LOC,A1 Initializepointerregister A1tocontaintheaddressofthefirst locationinmemorywherethe charactersaretobestored.

READ BTST.W #3,INSTATUS Wait fora characterto beenteredBEQ READ inthe keyboardbuffer DATAINMOVE.B DATAIN,(A1) TransferthecharacterfromDATAIN into

thememory(thisclearsSIN to0).ECHO BTST.W #3,OUTSTATUS Wait forthedisplay to becomeready.

BEQ ECHOMOVE.B (A1),DATAOUT Movethe characterjustreadtotheoutput

bufferregister(thisclearsSOUT to 0).CMPI.B #CR,(A1)+ Check ifthe characterjustreadis CR

(carriagereturn). If it isnot CR, thenBNE READ branch backandreadanothercharacter.

Also,increment thepointertostorethenextcharacter.

Figure 3.27. A 68000 program that reads a line of characters and displays it.

Callingprogram

MOVEA.L #NUM1,A2 Put theaddressNUM1 in A2.MOVE.L N,D1 Put the number ofentries n in D1.BSR LISTADD CallsubroutineLIST ADD.MOVE.L D0,SUM Storethesum in SUM.nextinstruction...

SubroutineLISTADD SUBQ.L #1,D1 Adjustcount to n 1.

CLR.L D0LOOP ADD.W (A2)+,D0 Accumulatesum in D0.

DBRA D1,LOOPRTS

Figure 3.28. Program of Figure 3.26 written as a 68000 subroutine; parameters passed through registers.

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.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.30. Nested subroutines in 68000 assembly language.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.31. 68000 stack frames for Figure 3.30.

MOVEA.L #LOC,A0 A0 points todata.MOVE.B (A0)+,D0 Loadfirst byte into D0.LSL.B #4,D0 Shift left by 4 bitpositions.MOVE.B (A0),D1 Loadsecondbyte into D1.ANDI.B #$F,D1 Clearhigh-order4bits tozero.OR.B D0,D1 Concatenatethedigits.MOVE.B D1,PACKED Storetheresult.

Figure 3.32. Use of 68000 logic instructions in packing BCD digits.

MOVEA.L #AVEC,A1 Addressoffirst vector.MOVEA.L #BVEC,A2 Addressofsecondvector.MOVE N,D0 Number ofelements.SUBQ #1,D0 Adjustcount touseDBRA.CLR D1 UseD1asaccumulator.

LOOP MOVE (A1)+,D2 Getelement fromvectorA.MULS (A2)+,D2 MultiplyelementfromvectorB.ADD D2,D1 Accumulateproduct.DBRA D0,LOOPMOVE D1,DOTPROD

Figure 3.33. A 68000 program for computing the dot product of two vectors.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.34. A 68000 byte-sorting program.

Subroutine

INSERTION CMPA.L #0,A0 A0 is RHEAD.BGT HEADMOVEA.L A1,A0 A1 isRNEWREC.RTS

HEAD CMP.L (A0),(A1) CompareID ofnewrecordtohead.BGT SEARCHMOVE.L A0,4(A1) Newrecordbecomeshead.MOVEA.L A1,A0RTS

SEARCH MOVEA.L A0,A2 A2 is RCURRENT.LOOP MOVEA.L 4(A2),A3 A3 is RNEXT.

CMPA.L #0,A3BEQ TAILCMP.L (A3),(A1)BLT INSERTMOVEA.L A3,A2 Go tonextrecord.BRA LOOP

INSERT MOVE.L A2,4(A1)TAIL MOVE.L A1,4(A2)

RTS

Figure 3.35. A 68000 subroutine to insert a record in a linked list.

Subroutine

DELETION CMP.L (A0),D1 D1 is RIDNUM.BGT SEARCHMOVEA.L 4(A0),A0 Deleteheadrecord.RTS

SEARCH MOVEA.L A0,A2 A2 is RCURRENT.LOOP MOVEA.L 4(A2),A3 A3 is RNEXT.

CMP.L (A3),D1BEQ DELETEMOVEA.L A3,A2BRA LOOP

DELETE MOVE.L 4(A3),D2 D2 is RTEMP.MOVE.L D2,4(A2)RTS

Figure 3.36. A 68000 subroutine to delete a record from a linked list.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.37. IA-32 register structure.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.38. Compatibility of the IA-32 register structure with earlier Intelprocessor register structures.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.39. Examples of addressing modes in the IA-32 architecture.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.40. IA-32 program for adding numbers.

Figure 3.41. IA-32 instruction format.

ImmediateDisplacementAddressing

OP code mode

1 or 2bytes

1 or 2bytes

1 or 4bytes

1 or 4bytes

Assemblerdirectives

.dataNUM1 DD 17, 3,51,242, 113N DD 5SUM DD 0

.code

Statementsthatgeneratemachineinstructions

MAIN : LEA EBX ,NUM1SUB EBX ,4MOV ECX ,NMOV EAX , 0

STARTADD : ADD EAX , [EBX+ECX 4]LOOP STARTADDMOV SUM,EAX

Assemblerdirective END MAIN

Figure 3.42. Complete IA-32 assembly language representation for the program in Figure 3.40b.

*

LEA EBP,LOC EBP points tofirst byte.MOV AL,[EBP] Loadfirst byte intoAL.SHL AL,4 Shiftleft by 4 bit positions.MOV BL,[EBP+1] Loadsecondbyte into BL.AND BL,0FH Clearhigh-order4bitstozero.OR AL,BL Concatenatethe BCDdigits.MOV PACKED,AL Storetheresult.

Figure 3.43. An IA-32 routine to pack two BCD digits into a byte.

LEA EBP,LOC EBP points tomemoryarea.READ: BT INSTATUS,3 Wait forcharacterto be

JNC READ entered into DATAIN.MOV AL,DATAIN Transfercharacterinto AL.MOV [EBP],AL Storethe characterinmemoryINC EBP andincrementpointer.

ECHO: BT OUTSTATUS,3 Wait fordisplay toJNC ECHO beready.MOV DATAOUT,AL Sendcharactertodisplay.CMP AL,CR If notcarriagereturn,JNE READ readmorecharacters.

Figure 3.44. An IA-32 program that reads a line of characters and displays it.

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.

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.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.47. Nested subroutines in IA-32 assembly language.

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.48. IA-32 stack frames for Figure 3.47.

LEA EBP,AVEC EBP points to vectorA.LEA EBX,BVEC EBX points to vectorB.MOV ECX,N ECX isthe loopcounter.MOV EAX,0 EAXaccumulatesthedotproduct.MOV EDI,0 EDI isanindexregister.

LOOPSTART: MOV EDX,[EBP+EDI 4] ComputetheproductIMUL EDX,[EBX+EDI 4] ofnextcomponents.INC EDI Incrementindex.ADD EAX,EDX Addtoprevioussum.LOOP LOOPSTART Branchback ifnotdone.MOV DOTPROD,EAX Storedotproductinmemory.

Figure 3.49. IA-32 dot product program.

**

Please see “portrait orientation” PowerPoint file for Chapter 3

Figure 3.50. An IA-32 byte-sorting program using straight-selection sort.

Subroutine

INSERTION: MOV RNEWID,[RNEWREC]CMP RHEAD,0 Check if listempty.JG HEADMOV RHEAD,RNEWREC If yes,newrecordbecomesRET one-entry list.

HEAD: CMP RNEWID,[RHEAD] Check ifnewrecordbecomeshead.

JG SEARCHMOV [RNEWREC+4],RHEAD If yes,make newrecordMOV RHEAD,RNEWREC thehead.RET

SEARCH: MOV RCURRENT,RHEAD Otherwise,useLOOPSTART: MOV RNEXT,[RCURRENT+4] RCURRENT

CMP RNEXT,0 and RNEXTJE TAIL tomovethroughCMP RNEWID,[RNEXT] the list to findJL INSERT theinsertionpoint.MOV RCURRENT,RNEXTJMP LOOPSTART

INSERT: MOV [RNEWREC+4],RNEXTTAIL: MOV [RCURRENT+4],RNEWREC

RET

Figure 3.51. An IA-32 subroutine for inserting a new record into a linked list.

Subroutine

DELETION: CMP RIDNUM,[RHEAD] Check if head.JGT SEARCHMOV RHEAD,[RHEAD+4] If yes,remove.RET

SEARCH: MOV RCURRENT,RHEAD Otherwise,LOOPSTART: MOV RNEXT,[RCURRENT+4] useRCURRENT

CMP RIDNUM,[RNEXT] andRNEXTJEQ DELETE tomove throughMOV RCURRENT,RNEXT the list toJMP LOOPSTART findtherecord.

DELETE: MOV RTEMP,[RNEXT+4]MOV [RCURRENT+4],RTEMPRET

Figure 3.52. An IA-32 subroutine for deleting a record from a linked list.

Program1 Program2

CLR.L D0 MOVE.W #$FFFF,D0MOVEA.L #LIST,A0 MOVEA.L #LIST,A0

LOOP MOVE.W (A0)+,D1 LOOP LSL.W (A0)+BGE LOOP BCC LOOPADDQ.L #1,D0 LSL.W #1,D0CMPI #17,D0 BCS LOOPBLT LOOP MOVE.W 2(A0),RSLTMOVE.W 2(A0),RSLT

Figure P3.1. Two 68000 programs for Problem 3.29.

––

Please see “portrait orientation” PowerPoint file for Chapter 3

Table 3.1. ARM index addressing modes

Please see “portrait orientation” PowerPoint file for Chapter 3

Table 3.2. 68000 addressing modes.

Please see “portrait orientation” PowerPoint file for Chapter 3

Table 3.3. IA-32 addressing modes

top related