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.
;******************************************************************** ;* 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.
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:
ORG $FFFA DC.W spurious ; DC.W spurious ; SWI DC.W _Startup ; Reset
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.
ABSENTRY _Startup