Addressing Modes 1 Immediate n 2 Register Direct

  • Slides: 16
Download presentation
Addressing Modes 1. Immediate n 2. Register Direct n n 3. 5. 6. (An)+

Addressing Modes 1. Immediate n 2. Register Direct n n 3. 5. 6. (An)+ the address of the data is in the address register Predecrement n (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 Postincrement n Dn or An data is in a register the address of the data is the register number Memory Direct n n 4. data is part of the instruction #<data> or Imm -(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

Address Register Indirect … variations 7. 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 registers instruction memory d An address displacement data

Address Register Indirect w/ displacement Rows Cols Loop Table EQU … LEA MOVE. B

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

Address Register Indirect … variations 8. Address register indirect with indexing d(An, Rn) ¨

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 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 address data d Ri An index displacement

Address Register Indirect w/ indexing Rows Cols EQU 3 4 … Loop LEA Table,

Address Register Indirect w/ indexing Rows Cols EQU 3 4 … Loop LEA Table, A 0 MOVE. W #0, D 1 MOVE. B 3(A 0, D 1. W), D 0 … ADDI. W #Cols, D 1 CMPI. W #Rows*Cols, D 1 BNE Loop Table … DC. B 15, 14, 13, 12 9, 8, 7, 6 4, 3, 2, 1

SOURCE ONLY – except for BTST, branches, jumps Program Counter Relative … variations 9.

SOURCE ONLY – except for BTST, branches, jumps Program Counter Relative … variations 9. 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 d PC registers memory address data displacement

Program Counter Relative … variations 9. Program counter relative w/ displacement d(PC) ¨ operand

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 label PC label - PC = offset registers instruction address memory data

Program Counter Relative … examples e. g. MOVE. W $50(PC), D 2 e. g.

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

Program Counter Relative … variations 10. Program counter relative w/ indexing d(PC, Rn) ¨

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 d Ri PC registers memory PC data Ri displacement

Program Counter Relative … variations 10. Program counter relative w/ indexing d(PC, Rn) ¨

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 label PC Ri registers Ri PC label - PC = offset memory data

Program Counter Relative … example e. g. print an appropriate error msg from a

Program Counter Relative … example e. g. print an appropriate error msg from a return code in D 0 …. D 0 is 2 … LSL. W #2, D 0 MOVEA. L CASES(PC, D 0. W), A 0 JMP (A 0) … * CASEx are the names of code segments to handle the various situations CASES DC. L CASE 0 CASE 1 CASE 2 CASE 3

Position Independent Code n code can be loaded and executed from any starting address

Position Independent Code n 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

Position Independent Code n no absolute addresses except for hardware device addresses PC-relative addressing

Position Independent Code n 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 intermodule 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 Non. Relocatable Code n Relocatable Code ¨ code can be moved to

Relocatable vs Non. Relocatable Code n 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 n Non. Relocatable 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

What is the code type? For the following examples, TABLE DS. B 100 is at address $100 E e. g. MOVEA. L #$100 E, A 0 e. g. MOVEA. L #TABLE, A 0 e. g. LEA e. g. START TABLE(PC), A 0 LEA *+0, A 0 ADDA. L #(TABLE-START), A 0

Reading: n M 68000 Assembly Language [92 p; N. Znotinas] ¨ review operation of

Reading: n M 68000 Assembly Language [92 p; N. Znotinas] ¨ review operation of address register instructions: CMPA, ADDA, SUBA, MOVEA, LEA n 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 n Position Independent Code from “Assembly Language and Systems Programming for the M 68000 Family” William Ford, William R. Topp - many good examples, some later examples use the M 68020 program counter memory indirect addressing mode which has a scale (multiplication) factor and some additional fields; in M 68000, you have to shift (multiply) the index explicitly Expectations: n n n 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