Analyzing Project Files

We will analyze the default main.asm file that was generated when the project was created with the New Bareboard Project wizard. The following listing shows the assembler source code for the Fibonacci program.

Listing: main.asm 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 the "Freescale CodeWarrior for HC08" program    *

;* directory.                                                      *

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

; Include derivative-specific definitions

            INCLUDE 'derivative.inc'

            

; export symbols

            XDEF _Startup, main

            ; we export both '_Startup' and 'main' as symbols. Either 
can

            ; be referenced in the linker .prm file or from C/C++ later 
on

            XREF __SEG_END_SSTACK   ; symbol defined by the linker for 
the end of the stack

; variable/data section

MY_ZEROPAGE: SECTION  SHORT         ; Insert here your data definition

; code section

MyCode:     SECTION

main:

_Startup:

            LDHX   #__SEG_END_SSTACK ; initialize the stack pointer

            TXS 

            CLI; enable interrupts

mainLoop:

            ; Insert your code here

            NOP

            feed_watchdog

            BRA    mainLoop

Since the RS08 memory map is different from the HC08 memory map (and so is the instruction set), The following listing shows a similar example for RS08.

Note: In order to assemble files for the RS08 derivative, pass the -Crs08 option to the assembler. To pass the -Crs08 option to the assembler, click the Code Generation tab in the HC08 Assembler Option Settings dialog box. Check the Derivative Family checkbox. From the option buttons that are displayed, select RS08 Derivative Family.
Listing: Contents of Source File for RS08 Derivative
;*******************************************************************
;* 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 the "Freescale CodeWarrior for HC08" program    *

;* directory.                                                      *

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

; export symbols

             XDEF _Startup, main

            ; we export both '_Startup' and 'main' as symbols. Either 
can

            ; be referenced in the linker .prm file or from C/C++ later 
on

; Include derivative-specific definitions

            INCLUDE 'derivative.inc'

;$$IF CLI                                  ; enable interrupts

;$$// we should include here MCUInit.inc. Unfortunately, the one that 
Unis generates does not assemble -> fix this when the fixed it.

;$$//; Include device initialization code

;$$//            INCLUDE 'MCUInit.inc'

;            XREF MCU_init

;$$ENDIF

; variable/data section

TINY_RAM_VARS: SECTION  RS08_SHORT         ; Insert here your data 
definition

Counter:    DS.B   1

FiboRes:    DS.B   1

tmpCounter: DS.B   1

tmp:        DS.B   1

; code section

MyCode:     SECTION

main:

_Startup:

;$$IF CLI                                           ; enable 
interrupts

            ; Call generated Device Initialization function

;            JSR    MCU_init

;$$ENDIF

mainLoop:

            CLRA                    ; A contains counter

cntLoop:    INCA

            CBEQA  #14,mainLoop     ; larger values cause overflow.

            

            MOV    #HIGH_6_13(SRS),PAGESEL

            STA    MAP_ADDR_6(SRS)  ; feed the watchdog

            STA    Counter          ; update global.

            BSR    CalcFibo

            STA    FiboRes          ; store result

            LDA    Counter

            BRA    cntLoop          ; next round.

CalcFibo:  ; Function to calculate fibonacci numbers. Argument is in A.

            DBNZA  fiboDo           ; fiboDo

            INCA

            RTS

fiboDo:            

            STA    tmpCounter       ; the counter

            CLRX                    ; second last = 0

            LDA    #$01             ; last = 1

FiboLoop:   STA    tmp              ; store last

            ADDX

            LDX    tmp

            DBNZ   tmpCounter,FiboLoop

FiboDone:

            RTS                     ; result in A

When writing your assembly source code, pay special attention to the following: