Thanks Maarten,

I think I understand the cause of the misordering in the linker now.  The object file containing the main routine was brought in from a library file instead of listed on the link command line.  I have it working now by listing the main on the link command. 

 I am using a commerical programmer called flashpro-cc.  I will contact their support to find out if they can handle the unsorted/extended intel hex files.

Maarten Brock wrote:
Hi Anthony,

It seems bankswitching is broken. And you also found why 
already: the startup routine should be at 0x0000 and 
__sdcc_banked_call at some higher address. Does it help 
if you put the .rel which contains main() as the first 
object to link?

Programmers that cannot handle unsorted hex-files are 
too restrictive. There is nothing about sorting in the 
definition of the standard.

Parameter passing should be taken care of correctly.

Sorry for the late reply. I had a busy weekend.

Based on the lack of responses, and the branches of sdcc with 
modifications to fix bank switching, I believe the banking in the 
official version is broken.  The documentation should be updated to 
indicate this so future users don't waste their time trying to use it.

The branched version are not keeping up with the latest sdcc releases, 
they only support 2.7.0 and 2.8.0.

If you are curious you should look at this sdcc branch, modified "with 

If there is any way to make the bank switching work in the mainline 
code, I am willing to help test and document it.


Anthony Asterisk wrote:
Hello SDCC-users,

  From reading the sdcc documentation, bank switching for the mcs51 is 
supported through the sdcc specific keyword __banked, a codeseg 
command line switch (or inline pragma) and the trampoline calls 
__sdcc_banked_call  and __sdcc_banked_ret.  The cc2430 chip that I am 
using provides a bank switching SFR called FMAP that is functionally 
similar to the crtbank.asm examples PSBANK, therefore I expect the 
crtbank.asm trampoline should work with no changes.  However when I 
mark any routine as banked, even if it is in the HOME bank, the code 
does not work...
Changes that I notice when using banking:

The trampoline functions get added to final map file (

Area                               Addr   Size   Decimal Bytes 
--------------------------------   ----   ----   ------- ----- 
HOME                               0000   00AC =    172. bytes 

      Value  Global
   --------  --------------------------------
  0C:0000    __sdcc_banked_call
  0C:0016    __sdcc_banked_ret
  0C:009F    __sdcc_program_startup
  0C:00A4    __sdcc_call_dptr
  0C:00A6    _hello_world

** Is the location of __sdcc_banked_call at address 0000 in the HOME 
segment a problem?  I expected the start up routines would normally go 
at 0000.

** From discussions with some other users of the cc2430/sdcc, it seems 
the banked mode does not work as described in the documentation.  
Specifically, I have been informed of some undocumented requirements...
  - generated hex file is in an unusual format that is not compatible 
with "commercial" programmers and must converted somehow
  - all code must be assigned to a bank, it will not work if any code 
is unassigned
  - all banks must have some code assigned to it

** Does anyone have the documented approach to bank switching 
working?  Is there some source code online that I can study?

** If the documented method does not work, I would be willing to help 
update the documentation if someone can explain the current  
requirements and implementation.

Here are the bank switching assembly routines...

       .area HOME    (CODE)

        push    _PSBANK         ;save return bank
        xch     a,r0            ;save Acc in r0, do not assume any 
register bank
        push    acc             ;push LSB address
        mov     a,r1
        push    acc             ;push MSB address
        mov     a,r2            ;get new bank
        anl     a,#0x0F         ;remove storage class indicator
        anl     _PSBANK,#0xF0
        orl     _PSBANK,a       ;select bank
        xch     a,r0            ;restore Acc
        ret                     ;make the call

        pop     _PSBANK         ;restore bank
        ret                     ;return to caller

Generated assembly code for a banked call:

;       demo.c:82: abc=hello_world();
        mov     r0,#_hello_world
        mov     r1,#(_hello_world >> 8)
        mov     r2,#(_hello_world >> 16)
        lcall   __sdcc_banked_call
        mov     r2,dpl
        mov     r3,dph

;       hello_world.c:15: return 123;
        mov     dptr,#0x007B
        ljmp    __sdcc_banked_ret


  - the parameters passed on the stack to banked routine would come 
before _PSBANK.  Will the banked routine skip over the stored _PSBANK 
to reach them?  So far I have only attempted to routines without 
Return on Information:
Google Enterprise Search pays you back
Get the facts.
Sdcc-user mailing list


Return on Information:
Google Enterprise Search pays you back
Get the facts.
Sdcc-user mailing list