Motorola dsp assembler Reference Manual



Yüklə 4,8 Kb.
Pdf görüntüsü
səhifə23/91
tarix08.10.2017
ölçüsü4,8 Kb.
#3546
1   ...   19   20   21   22   23   24   25   26   ...   91

Software Project Management
Example 2: Overlays
4-16
DSP ASSEMBLER REFERENCE MANUAL
MOTOROLA
formation on relocation and linking. One other Assembler directive that should be men-
tioned (although not shown in the previous example) is the MACLIB directive which allows
sections to share a common macro library. The MACLIB directive is discussed more fully
in Chapter 5.
4.7
  EXAMPLE 2: OVERLAYS
An overlay is a transfer of code or data from one memory space or address to another
memory space or address at runtime.  Often the transfer involves copying different blocks
of code or data over a common storage area as runtime circumstances dictate; hence the
name overlay.  Overlays are useful for moving code into internal program memory from
an external memory source such as EPROM.  They are also effective when implementing
large programs with multiple segments which do not need to be accessed concurrently.
Consider the following program fragment contained in a file called OVER1.ASM:
SECTION_OVERLAY1_XREF_OVLBASE_XDEF_OVL1,O1SIZE_ORG_X:_OVL1_ORG'>SECTION
OVERLAY1
XREF
OVLBASE
XDEF
OVL1,O1SIZE
ORG
X:
OVL1
ORG
P:OVLBASE,X:
START
.
.

.
.
END
O1SIZE
EQU
END-START
ENDSEC_This_is_a_sample_of_overlay_code_bounded_by_a_SECTION'>ENDSEC
This is a sample of overlay code bounded by a SECTION directive. The overlay base, or
the place to which this block of code will be moved for execution, is declared external at
OVLBASE (OVLBASE is actually defined elsewhere). The label OVL1 is XDEFed to pro-
vide a handle for moving the block at runtime, and O1SIZE is also XDEFed so that the
overlay management code knows how many words to move. Note that the OVL1 label is
placed before the ORG for the overlay so that it remains a valid address in X memory dur-
ing execution. The overlay ORG directive insures that subsequent addresses will be
based from OVLBASE at runtime. The size of the overlay block (O1SIZE) is computed by
subtracting the START label value from the END label address. Assume for purposes of
discussion that there are other files containing similar overlay code with names
OVER2.ASM and OVER3.ASM.


Software Project Management
Example 2: Overlays
MOTOROLA
DSP ASSEMBLER REFERENCE MANUAL
4-17
4.7.1
  Absolute Mode Implementation
In order to avoid binding addresses within the individual overlay modules, the programmer
could devise a preamble file called OVLPROJ.ASM which sets the appropriate counters
and establishes the overlay base address.  Note that the following code assumes a
DSP96000, but similar instructions would apply for other target processors:
SECTION
OVLPROJECT
XDEF
OVLBASE
XREF
OVL1,O1SIZE
XREF
OVL2,O2SIZE
XREF
OVL3,O3SIZE
ORG
XE:$100 ; set absolute base for overlay sections
ORG
PI:$200
; set absolute base address for overlay
OVLBASE DS
$400
; reserve space for overlay area
MOVEOV1
; code to move first overlay segment
MOVE
#OVL1,R0; load overlay code address
MOVE
#OVLBASE,R1; load overlay base address
MOVE
#O1SIZE,D1.M; load overlay code size
DO
D1.M,_ENDLOOP; loop to move data words into P memory
MOVE
X:(R0)+,D0.M; get word of overlay from data memory
MOVE
D0.M,P:(R1)+; store word of overlay into P memory
_ENDLOOP
.
.
.
ENDSEC
The overlay base address OVLBASE is made global with the XDEF statement.  The over-
lay segments and their sizes are made visible to the project section by using the XREF
directive.  The first ORG establishes where the overlay segments will be placed in mem-
ory contiguously at load time.  The second ORG sets up the absolute base address for
the overlay area common to all of the overlay segments.  Uninitialized space is allocated
for the overlay area, immediately followed by code to move the overlay segments into the
common area at runtime.  The following Assembler command line will process the header
file and all overlay segments:
ASM96000 -A -B -L OVLPROJ OVER1 OVER2 OVER3 START
The Assembler is invoked in absolute mode (-A option), and generates an executable and
listing file.  All files on the command line are processed as a single assembly run and all
are used to produce the output.  OVLPROJ.ASM is read first and sets up the appropriate
absolute addresses for later sections.  Then each overlay file is read and loaded one after
the other at external X memory address 100 hexadecimal.  However, since each overlay


Software Project Management
Example 2: Overlays
4-18
DSP ASSEMBLER REFERENCE MANUAL
MOTOROLA
module was intended to run starting at OVLBASE in P memory, all labels and jumps to
those labels within the overlay code will be relative to the overlay base address.  This
means that the code in each of the overlay modules, when loaded by the overlay manage-
ment code in the OVLPROJECT section, will start executing at internal P memory address
200 hexadecimal.  The file START.ASM contains an END directive which indicates the
program start address after loading.
4.7.2
  Relative Mode Implementation
In relative mode each of the overlay files is assembled separately to create individual ob-
ject files. The object files are combined to build a single executable file. A preamble file
OVLPROJ.ASM containing overlay management code might appear as follows. Note that
this code assumes a DSP96000, but similar instructions would apply for other target pro-
cessors:
SECTION OVLPROJECT
XDEF
OVLBASE
XREF
OVL1,O1SIZE
XREF
OVL2,O2SIZE
XREF
OVL3,O3SIZE
ORG
PI:
; set base address for overlay
MOVEOV1
; code to move first overlay seg-
ment
MOVE
#OVL1,R0
; load overlay code address
MOVE
#OVLBASE,R1
; load overlay base address
MOVE
#O1SIZE,D1.M
; load overlay code size
DO
D1.M,_ENDLOOP
; loop to move data words into P
memory
MOVE
X:(R0)+,D0.M
; get word of overlay from data
memory
MOVE
D0.M,P:(R1)+
; store one word of overlay into P
memory
_ENDLOOP
.
.
.
OVLBASE
DS
$400
; reserve space for overlay area
ENDSEC


Yüklə 4,8 Kb.

Dostları ilə paylaş:
1   ...   19   20   21   22   23   24   25   26   ...   91




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə