Adapting Absolute Assembly File Created by Wizard

Modify the absolute assembly file main.asm as the following listing displays.

The ORG directives must specify the absolute memory areas for ROM and RAM. The following listing shows an adaptation of the main.asm file produced previously by the Wizard. This file may be used by the Assembler build tool or IDE to directly generate an ABS file.

Listing: Example Source File - main.asm
;********************************************************************
;* This stationery serves as the framework for a user               *

;* application. For a more comprehensive program that               *

;* demonstrates the more advanced functionality of this             *

;* processor, please see the demonstration applications             *

;* located in the examples subdirectory of CodeWarrior for          *

;* Microcontrollers V10.x program directory.                         *

;********************************************************************

; application entry point

             ABSENTRY  _Startup

; export symbols

            XDEF _Startup, main

            ; we use '_Startup' as an export symbol. This allows

            ; us to reference '_Startup' either in the linker

            ; *.prm file or from C/C++ later on.

            ; Include derivative-specific definitions

            INCLUDE 'derivative.inc'

; variable/data section

            ORG   $0040

Counter:    DS.B  1

FiboRes:    DS.B  1

; initial value for SP

initStack:  EQU   $023E

; code section

            ORG   $8000

main:

_Startup:

            LDHX  #initStack        ; initialize the stack pointer

            TXS

            CLI                     ; enable interrupts

mainLoop:

            CLRA                    ; A contains a counter.

cntLoop:    INCA

            CBEQA #14,mainLoop      ; Larger values cause overflow.

            feed_watchdog           ; 

            STA   Counter           ; update global

            BSR   CalcFibo

            STA   FiboRes           ; store result

            LDA   Counter

            BRA   cntLoop           ; next round

CalcFibo: ; Function to compute Fibonacci numbers. Argument is in A.

            DBNZA fiboDo            ; fiboDo

            INCA

            RTS

fiboDo:

            PSHA                    ; the counter

            CLRX                    ; second last = 0

            LDA   #$01              ; last = 1

FiboLoop:   PSHA                    ; push last

            TXA

            ADD   1,SP

            PULX

            DBNZ  1,SP,FiboLoop

FiboDone:   PULH                    ; release counter

            RTS                     ; Result in A

;**************************************************************

;* spurious - Spurious Interrupt Service Routine.             *

;*             (unwanted interrupt)                           *

;**************************************************************

spurious:                           ; Put here so the security 

            NOP                     ; value does not change    

            RTI                     ; all the time.            

;**************************************************************

;*                Interrupt Vectors                           *

;**************************************************************

            ORG   $FFFA

            DC.W  spurious          ;

            DC.W  spurious          ; SWI

            DC.W  _Startup          ; Reset

The following listing is a similar example for RS08.

Listing: Example Source File abstest_rs08.asm
ABSENTRY entry; Specifies the application Entry point
XDEF entry ; Make the symbol entry visible (needed for debugging)

        ORG $20 ; Define an absolute constant section

var1: DC.B 5 ; Assign 5 to the symbol var1

        ORG $40 ; Define an absolute data section

data: DS.B 1 ; Define one byte variable in RAM at $80

        ORG $3C00 ; Define an absolute code section

entry:

        LDA var1

main:

        INCA

        STA data

        BRA main

When writing your assembly source file for direct absolute file generation, pay special attention to the following points:

The ABSENTRY directive is used to write the address of the application entry point in the generated absolute file. To set the entry point of the application on the _Startup label in the absolute file, the following code is needed.

Listing: Using ABSENTRY to enter the entry-point address
          ABSENTRY _Startup
CAUTION:
We strongly recommend that you use separate sections for code, (variable) data, and constants. All sections used in the assembler application must be absolute and defined using the ORG directive. The addresses for constant or code sections have to be located in the ROM memory area, while the data sections have to be located in a RAM area (according to the hardware that you intend to use). The programmer is responsible for making sure that no section overlaps occur.