Quick viewing(Text Mode)

Addressing Modes: Indirect with Displacement, Index

Addressing Modes: Indirect with Displacement, Index

Addressing Modes

1. Immediate # or Imm  data is part of the instruction

2. Register Direct Dn or An  data is in a register  the address of the data is the register number

3. Memory Direct (xxx).W or (xxx).L  data is in a memory location  the address of the data is the address of the memory location

4. Address Register Indirect (An) 5. Postincrement (An)+  the address of the data is in the address register 6. Predecrement -(An)  the address of the data is the contents of the address register minus the decrement Address Register Indirect … variations

7. Address register indirect with displacement d(An)  operand is written as d(An) where d = 16 displacement  the address of the data is the sum of the address register and the displacement instruction registers memory d An

address data

displacement Address Register Indirect w/ displacement Rows EQU 3 Cols EQU 4 … LEA Table,A0 Loop MOVE.B 3(A0),D0 … ADDA.L #Cols,A0 CMPA.L #Table+Rows*Cols,A0 BNE Loop … Table DC.B 15,14,13,12 DC.B 9,8,7,6 DC.B 4,3,2,1 Address Register Indirect … variations

8. Address register indirect with indexing d(An,Rn)  operand is written as d(An,Ri{.W|.L}) where d = 8 bit displacement and Ri is an (W or L)  the address of the data is the sum of the address register, the index register, and the displacement instruction registers memory d Ri An address data index

displacement Address Register Indirect w/ indexing Rows EQU 3 Cols EQU 4 … LEA Table,A0 MOVE.W #0,D1 Loop MOVE.B 3(A0,D1.W),D0 … ADDI.W #Cols,D1 CMPI.W #Rows*Cols,D1 BNE Loop … Table DC.B 15,14,13,12 DC.B 9,8,7,6 DC.B 4,3,2,1 SOURCE ONLY – except for BTST, branches, jumps

Program Relative … variations

9. relative w/ displacement d(PC)  operand is written as d(PC) where d = 16 bit displacement  the address of the data is the sum of the program counter and the displacement instruction registers memory d PC address data

displacement Program Counter Relative … variations

9. Program counter relative w/ displacement d(PC)  operand is written as label(PC) where label refers to a label in the program  when reading code, treat as if (PC) not there  the use of a label reference causes the assembler to calculate an offset to the PC instruction registers memory label PC instruction data label - PC address = offset Program Counter Relative … examples e.g. MOVE.W $50(PC),D2 If instruction located at $2050, then = $2052+$50 =$20A2 Move contents from memory location $20A2 to D2. e.g. MOVEA.L WK(PC),A0 If instruction located at $1000 and WK located at $1508, then … offset = $1508 - $1002 = $0506 WK DC.L WK_CASE = $1002 + $0506 = $1508 Move address WK_CASE to A0. e.g. JMP NEXT(PC) If instruction located at $3000 and … NEXT located at $3052, then NEXT MOVEQ.B #1,D0 offset = $3052 - $3002 = $0050 = $3002 + $0050 = $3052 Jump to NEXT. Program Counter Relative … variations

10. Program counter relative w/ indexing d(PC,Rn)  operand is written as d(PC,Ri{.W|.L}) where d = 8 bit displacement  the address of the data is the sum of the PC, the index register, and the displacement

instruction registers memory d Ri PC PC data Ri

displacement Program Counter Relative … variations

10. Program counter relative w/ indexing d(PC,Rn)  operand is written as label(PC,Ri{.W|.L}) where label refers to a label in the program  the use of a label reference causes the assembler to calculate an offset to the PC

instruction registers memory label PC Ri Ri PC data label - PC = offset Program Counter Relative … example e.g. print an appropriate error msg from a return code in D0 …. D0 is 2 … LSL.W #2,D0 MOVEA.L CASES(PC,D0.W),A0 JMP (A0) … * CASEx are the names of code segments to the various situations CASES DC.L CASE0 DC.L CASE1 DC.L CASE2 DC.L CASE3 Position Independent Code

 code can be loaded and executed from any starting address in memory after it has been assembled; address assigned at run time  static → after assembly, e.g. shared library, ROM based program

 dynamic → can be moved after it has started execution, e.g. system Position Independent Code

 no absolute addresses except for hardware device addresses  PC-relative addressing is used wherever possible for branches within modules  where PC-relative addressing cannot be used, indirect addressing through a linkage table is used for accesses to global variables, for inter- module procedure calls, for branches and literal accesses  The dynamic loader fills in procedure and data linkage tables with the absolute virtual addresses of the routines and data in a shared library at run time (known as binding) . Relocatable vs NonRelocatable Code

 Relocatable Code  code can be moved to different starting address but requires reassembly  code contains symbols but no explicit addresses (except hardware)  addresses assigned at link time

 NonRelocatable Code  code requires reprogramming to be moved to a different memory location  code contains actual addresses  addresses assigned during programming What is the code type?

For the following examples, TABLE DS.B 100 is at address $100E e.g. MOVEA.L #$100E,A0 e.g. MOVEA.L #TABLE,A0 e.g. LEA TABLE(PC),A0 e.g. START LEA *+0,A0 ADDA.L #(TABLE-START),A0 Reading:  M68000 [92p; N. Znotinas]  review operation of address register instructions: CMPA, ADDA, SUBA, MOVEA, LEA

 Addressing Modes [© Stephen J Kuyath, UNCC, 2007] - has good single step animations for the various addressing modes - best way to use the animations is to (1) look at the instruction he is executing, (2) figure out the actions, (3) determine the final result, and (4) then single step through the animation to verify - for PC relative, he is showing the PC after the instruction fetch

 Position Independent Code from “Assembly Language and Systems Programming for the M68000 Family” William Ford, William R. Topp - many good examples, some later examples use the M68020 program counter memory indirect addressing mode which has a scale (multiplication) factor and some additional fields; in M68000, you have to shift (multiply) the index explicitly

Expectations:  I do not expect you to be able to write code using program relative addressing modes but you should be able to read code that contains program relative addressing modes  you should be able to use all of the address register indirect variations  you should be able to classify the code type for a given sample of code