Presentation is loading. Please wait.

Presentation is loading. Please wait.

Addressing Modes Immediate #<data> or Imm

Similar presentations


Presentation on theme: "Addressing Modes Immediate #<data> or Imm"— Presentation transcript:

1 Addressing Modes Immediate #<data> or Imm
data is part of the instruction Register Direct Dn or An data is in a register the address of the data is the register number 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 Address Register Indirect (An) Postincrement (An)+ the address of the data is in the address register Predecrement (An) the address of the data is the contents of the address register minus the decrement

2 Address Register Indirect … variations
Address register indirect with displacement d(An) operand is written as d(An) where d = 16 bit displacement the address of the data is the sum of the address register and the displacement instruction registers memory d An address data displacement

3 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

4 Address Register Indirect … variations
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 index register (W or L) the address of the data is the sum of the address register, the index register, and the displacement instruction registers memory data d Ri An address index displacement

5 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

6 Program Counter Relative … variations
SOURCE ONLY – except for BTST, branches, jumps Program Counter Relative … variations Program counter 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

7 Program Counter Relative … variations
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 address data label - PC = offset

8 Program Counter Relative … examples
e.g. MOVE.W $50(PC),D2 e.g. MOVEA.L WK(PC),A0 WK DC.L WK_CASE e.g. JMP NEXT(PC) NEXT MOVEQ.B #1,D0 If instruction located at $2050, then <ea> = $2052+$50 =$20A2 Move contents from memory location $20A2 to D2. If instruction located at $1000 and WK located at $1508, then offset = $ $1002 = $0506 <ea> = $ $0506 = $1508 Move address WK_CASE to A0. If instruction located at $3000 and NEXT located at $3052, then offset = $ $3002 = $0050 <ea> = $ $0050 = $3052 Jump to NEXT.

9 Program Counter Relative … variations
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 registers instruction memory d Ri PC PC data Ri displacement

10 Program Counter Relative … variations
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 registers instruction memory label PC Ri Ri PC data label - PC = offset

11 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 handle the various situations CASES DC.L CASE0 DC.L CASE1 DC.L CASE2 DC.L CASE3

12 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. virtual memory system

13 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) .

14 Relocatable vs NonRelocatable 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

15 What is the code type? START LEA *+0,A0 ADDA.L #(TABLE-START),A0
For the following examples, TABLE DS.B 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

16 Reading: Expectations: M68000 Assembly Language [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


Download ppt "Addressing Modes Immediate #<data> or Imm"

Similar presentations


Ads by Google