Modular assembly programming  - MC9S08AW60.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Modular assembly programming  - MC9S08AW60.

2,113 Views
Onemars
Contributor II
Hello, I'm using Codewarrior 5.9.0 and a MC9S08AW60.
I wanted a modular assembly program, easy to interconnect. I choosed a relocatable assembly, but to make it work without errors I had to make the "NoXref" workaround to exclude the XREF definitions.
 
See the code below, it does nothing, but it works: the main program imports and uses a library routine (lib_do). Is there a better method to do modular and clean assembly programming?
 
Another question, to make a disassembly list with addresses and source comments I have tried the decoder with the ELF abs file, but it's a mess, any other ways?
 
And another question, in the code below the var "zvar1" is at address $0070, if I write:
          ORG $0070
varx    DS.B 1
The linker doesn't throw any error. Why?
 
Kind regards.
 
Added part number to the subject.

 
Code:
;============= PRM FILE =============NAMES ENDSEGMENTS    Z_RAM       =  READ_WRITE   0x0070 TO 0x00FF;    RAM         =  READ_WRITE   0x0100 TO 0x07FF;    STK         =  READ_WRITE   0x0800 TO 0x086F;    ROM1        =  READ_ONLY    0x0870 TO 0x17FF;    ROM         =  READ_ONLY    0x1860 TO 0xFFAF;    ROM2        =  READ_ONLY    0xFFC0 TO 0xFFCB;    INT_VECTS   =  READ_ONLY    0xFFCC TO 0xFFFF;ENDPLACEMENT    SEC_ZRAM        INTO Z_RAM;    DEFAULT_RAM     INTO RAM;    SEC_RAM         INTO RAM;    SSTACK          INTO STK;    DEFAULT_ROM     INTO ROM;    SEC_ROM         INTO ROM;ENDINIT _ResetVECTOR 0 _Reset;============= LIB.INC FILE =============; Import external symbols            IF  NoXref == 0                 XREF    zvar2                XREF    lib_do            ENDIF            ; Define constantsCPU_VERSION:    equ   $AB;============= LIB.ASM FILE =============            NOLIST            ; Include equates but do NOT import its symbols            NoXref: SET 1                   INCLUDE 'lib.inc'            LIST; Exported symbols                        XDEF    zvar2            XDEF    lib_do;--------------------------------------SEC_ZRAM:   SECTION SHORT;--------------------------------------zvar2       DS.B 1;--------------------------------------SEC_ROM:    SECTION;--------------------------------------lib_do:            LDA     #CPU_VERSION    ; Defined in lib.inc            AND     #$0F            STA     zvar2           ; Ouput var            RTS           ;============= MAIN.ASM FILE =============            NOLIST            ; Include derivative specific macros                INCLUDE 'MC9S08AW60.inc'            ; Include library equates and import its symbols            NoXref: SET 0                INCLUDE 'lib.inc'            LIST            XDEF _Reset            XREF __SEG_END_SSTACK;--------------------------------------SEC_ZRAM:   SECTION SHORT;--------------------------------------zvar1       DS.B 1                ;--------------------------------------SEC_RAM:    SECTION;--------------------------------------var1        DS.B 1  ;--------------------------------------DEFAULT_ROM:SECTION;--------------------------------------_Reset:            LDHX   #__SEG_END_SSTACK            TXS            CLImainLoop:            CLRA            STA     zvar1            JSR     lib_do ; call the library routine            LDA     zvar2 ; get the result            STA     var1            BRA    mainLoop

 


Message Edited by NLFSJ on 2007-11-28 06:24 AM
Labels (1)
0 Kudos
5 Replies

502 Views
bigmac
Specialist III
Hello, and welcome to the forum.
 
Another possibility, might be as follows -
 
LIB.INC file:
 
   IFNDEF  zvars2
   XREF    zvars2
   ENDIF
   IFNDEF  lib_do
   XREF    lib_do
   ENDIF
 
LIB.ASM file:
 
   XDEF    zvars2
   XDEF    lib_do
   INCLUDE 'lib.inc"
 
This seems similar to an approach used in C programming.  The INCLUDE should occur following the XDEFs.
 
The presence of ORG  $0070 directive suggests to the linker you are using absolute assembly for that section of code.  I presume this is why the linker does not complain.
 
Regards,
Mac
 
0 Kudos

502 Views
Onemars
Contributor II
Thanks. Much cleaner.
 
You're very right. Absolute by absolute and section by section overlapping are reported, but not section by absolute or viceversa. My problem is this: an absolute code section followed by a relocatable section, I wanted the linker report if the first overlaps the second.
I guess there is no option to setup, so I have to switch to all relocatable.
Thanks again.
0 Kudos

502 Views
CompilerGuru
NXP Employee
NXP Employee
I think all cases of overlapping are reported, but some of the issued linker diagnostics
are disabled in some projects.
Basically I get this error:


Code:
Link Error   : L1100: Segments Z_RAM (0x70) and .absSeg0 (0x70) overlapLink Error   : Link failed

 
when I do not add any linker error remapping options.
See in the Linker for HC08 settings if any messages are remaped, wizard generated projects do contain such options for some derivatives (all? not sure).

Daniel
0 Kudos

502 Views
Onemars
Contributor II
Mac, otherwise I can put the macro in LIB.INC.
 
Daniel, the L1100 error was what I needed: "Standard Settings" >> "Linker" >> "Messages" and
here move L1110 from Disabled to Error. The "Factory Settings" does the job too.
For me, it is disabled by default in a new relocatable assembly project with the standard project wizard.
 
Thank you all,
Gabriele
0 Kudos

502 Views
bigmac
Specialist III
Hello,
 
In the case of absolute assembly, I guess the onus has always been on the programmer to ensure that the code doesn't overlap into areas it shouldn't.
 
Incidently, the conditional approach previously outlined does not seem to work with a macro name, for a conditional macro definition.  I do not know why this is so - it does not seem to be documented in the assembler manual.  The work-around is to define a separate label for the conditional test.
 
For example, the following does not seem to work if the label XGHX is tested.
 
  IFNDEF  _XGHX
_XGHX:    ; EXCHANGE H-REG & X-REG
XGHX:     MACRO
          PSHH
          PSHX
          PULH
          PULX
          ENDM
  ENDIF
 
Regards,
Mac
 
0 Kudos