• Aucun résultat trouvé

Advantages of A2-A5 Relative Addressing

A2-A5 relative addressing is useful when:

• Accessing statically allocated data areas. Accessing statically allocated data areas with A2-A5 relative addressing is as efficient as using the absolute short addressing mode with the additional benefit of being able to locate the data area (up to 64K bytes long) anywhere in memory.

• Accessing dynamically allocated data areas which are independent of the code that accesses them.

Accessing Statically Allocated Areas

The 68000/20 model address register indirect with displacement addressing modes (for example, those modes generated for syntaxes such as "< exp> (An)"

or "(< exp> ,An,R n)", etc.) are often the fastest and most efficient ways to access code or data locations; this is especially true when accessing code or data in high memory where the alternative would be to use absolute long addressing (see figure 2-1). Notice that the address register indirect mode is coded in two fewer bytes than the absolute long mode.

A2-A5 Relative Addressing

The address register indirect mode is useful because you can access locations anywhere in memory with the same number of bytes of code generated. Also, with a signed 16-bit displacement, you can access up to 64K bytes (+ /- 32K) relative to the contents of the address register.

HPB3641-19300 A.02.00 27Apr93 Copr. HP 1988 Page 1 Wed Apr 28 15:21:21 1993

Command line: as68k -L modes.s Line Address

1 SECT DATA 2 00000000 WORD1 DS.W 1

3 00000002 DS.B 0FFFEH

4 ; Address Mode Generated:

5 SECT CODE ;---6 00000000 3039 0000 0000 R MOVE WORD1,D0 ; Absolute Long.

7 00000006 302A 0000 R MOVE WORD1(A2),D0 ; Address Reg. Indirect 8 ; with Displacement.

9 END

HPB3641-19300 A.02.00 27Apr93 Copr. HP 1988 Page 2 Wed Apr 28 15:21:21 1993

Symbol Table Label Value

WORD1 DATA:00000000

Figure 4-1. Absolute and Indirect Address Modes A2-A5 Relative Addressing

Accessing Dynamically Allocated Areas

Dynamic memory allocation routines are typically passed the size of some element (for which memory is to be allocated) and return the address of the data area which has been allocated (in other words, a pointer to the allocated block of memory). At link-time, the linker/loader does not know what the address of the dynamically allocated area will be, but it does know the kind of element that memory is to be allocated for. With this knowledge, and with the help of the INDEX command, displacements can be calculated for A2-A5 relative addressing instructions. At run-time, the address of the dynamically allocated area is placed in the appropriate address register, and the

dynamically allocated area can be accessed via A2-A5 relative addressing.

Example

The following is a simple example of A2-A5 relative addressing and how to use the INDEX command. A listing of the assembly language source file is shown in figure 2-2. The linker/loader listing in figure 2-3 shows the INDEX

command used with an offset. The linker/loader listing in figure 2-4 shows the INDEX command used without an offset. Comments are included in the assembly source file and in the linker command files to explain the instructions and commands in detail.

A2-A5 Relative Addressing

HPB3641-19300 A.02.00 27Apr93 Copr. HP 1988 Page 1 Wed Apr 28 15:20:07 1993

Command line: as68k -L example.s Line Address

Figure 4-2. A2-A5 Relative Addressing Example A2-A5 Relative Addressing

HPB3641-19300 A.02.00 27Apr93 Copr. HP 1988 Wed Apr 28 15:21:01 1993 Page 1

Command line: ld68k -c lnk_cmd.k -L NAME lnk_cmd

LIST C ; Include a cross-reference listing on the output.

INDEX ?A2,DATA,8000H ; The run-time value of A2 equals the ; load address of the DATA section plus

; The displacement calculated for the "CLR VAR(A2)" instruction is

; the effective address of VAR (0FF0000 + 6000H) minus the run-time

; value of (0FF8000H):

;

; Displacement = 0FF6000H - 0FF8000H = -2000H = 0E000H.

;

; At run-time, the "MOVE.L #?A2,A2" instruction initializes A2

; with 0FF8000H. The "CLR VAR(A2)" instruction clears the location

; indexed by A2 plus the displacement, which equals:

;

OUTPUT MODULE NAME: lnk_cmd OUTPUT MODULE FORMAT: IEEE

Figure 4-3. Using the INDEX Command with Offset

A2-A5 Relative Addressing

SECTION SUMMARY

---SECTION ATTRIBUTE START END LENGTH ALIGN PROG NORMAL CODE 00001000 00001009 0000000A 2 (WORD) DATA NORMAL DATA 00FF0000 00FFFFFE 0000FFFF 2 (WORD) MODULE SUMMARY

---MODULE SECTION:START SECTION:END FILE

example DATA:00FF0000 DATA:00FFFFFE /users/merff/asm68k/example.o PROG:00001000 PROG:00001009

CROSS REFERENCE TABLE

---SYMBOL SECTION ADDRESS MODULE

?A2 00FF8000 -$$

example VAR DATA 00FF6000 -example START ADDRESS: 00000000

Link Completed

Figure 4-3. Using INDEX with Offset (Cont’d) A2-A5 Relative Addressing

HPB3641-19300 A.02.00 27Apr93 Copr. HP 1988 Wed Apr 28 15:21:13 1993 Page 1

Command line: ld68k -c lnk_cmd2.k -L NAME lnk_cmd

LIST C ; Include a cross-reference listing on the output.

INDEX ?A2,DATA,0 ; The run-time value of A2 equals the ; load address of the DATA section.

SECT DATA=0FF0000H ; Run-time of A2 is 0FF0000H.

; The displacement calculated for the "CLR VAR(A2)" instruction is

; the effective address of VAR (0FF0000 + 6000H) minus the run-time

; value of (0FF0000H):

;

; Displacement = 0FF6000H - 0FF0000H = 6000H.

;

; At run-time, the "MOVE.L #?A2,A2" instruction initializes A2

; with 0FF0000H. The "CLR VAR(A2)" instruction clears the location

; indexed by A2 plus the displacement, which equals:

;

; 0FF0000H + 6000H = 0FF6000H.

SECT PROG=1000H LOAD example.o END

HPB3641-19300 A.02.00 27Apr93 Copr. HP 1988 Wed Apr 28 15:21:13 1993 Page 2

OUTPUT MODULE NAME: lnk_cmd OUTPUT MODULE FORMAT: IEEE

Figure 4-4. Using INDEX without Offset

A2-A5 Relative Addressing

SECTION SUMMARY

---SECTION ATTRIBUTE START END LENGTH ALIGN PROG NORMAL CODE 00001000 00001009 0000000A 2 (WORD) DATA NORMAL DATA 00FF0000 00FFFFFE 0000FFFF 2 (WORD) MODULE SUMMARY

---MODULE SECTION:START SECTION:END FILE

example DATA:00FF0000 DATA:00FFFFFE /users/merff/asm68k/example.o PROG:00001000 PROG:00001009

CROSS REFERENCE TABLE

---SYMBOL SECTION ADDRESS MODULE

?A2 00FF0000 -$$

example VAR DATA 00FF6000 -example START ADDRESS: 00000000

Link Completed

Figure 4-4. Using INDEX without Offset (Cont’d) A2-A5 Relative Addressing

5

Relocation

This chapter explains relocatable programming and section attributes.

The object module produced by the assembler is in a relocatable format, which allows you to write programs whose final addresses will be adjusted by the linking loader. The relocatable format also allows individual program modules to be changed without reassembling the complete program. Separate object modules can be linked together into a final program.

R elocatable programming provides the following advantages:

• Actual memory addresses are of no concern until the final load time.

• Large programs may be easily separated into smaller pieces, developed separately, and linked together.

• If one piece contains an error, only that one need be modified and reassembled.

• Once developed, a library of routines may be used by many users.

• The linker will adjust addresses to meet program requirements.

Documents relatifs