A51 MACRO ASSEMBLER  L51_BANK                                                             02/14/2007 13:36:03 PAGE     1


MACRO ASSEMBLER A51 V8.00b
OBJECT MODULE PLACED IN L51_bank.OBJ
ASSEMBLER INVOKED BY: C:\Keil\C51\BIN\A51.EXE L51_bank.a51 SET(SMALL) DEBUG EP

LOC  OBJ            LINE     SOURCE

                       1     $nomod51  NOLINES
                       2     $nocond 
                       3     ;------------------------------------------------------------------------------
                       4     ;  This file is part of the BL51 / LX51 Banked Linker/Locater package
                       5     ;  Copyright (c) 1988 - 2005 Keil Elektronik GmbH and Keil Software, Inc.
                       6     ;  Version 2.21 (Code and Variable Banking for Classic 8051 Derivatives)
                       7     ;------------------------------------------------------------------------------
                       8     ;************************ Configuration Section *******************************
  0004                 9     ?B_NBANKS       EQU  4    ; Define maximum Number of Banks                    *
                      10     ;                         ; following values are allowed: 2, 4, 8, 16, 32, 64 *
                      11     ;                         ; for BL51 the maximum value for ?B_BANKS is 32     *
                      12     ;                         ; for LX51 the maximum value for ?B_BANKS is 64     *
                      13     ;                                                                             *
  0001                14     ?B_MODE         EQU  1    ; 0 for Bank-Switching via 8051 Port                *
                      15     ;                         ; 1 for Bank-Switching via XDATA Port               *
                      16     ;                         ; 4 for user-provided bank switch code              *
                      17     ;                                                                             *
  0000                18     ?B_RTX          EQU  0    ; 0 for applications without real-time OS           *
                      19     ;                         ; 1 for applications using the RTX-51 real-time OS  *
                      20     ;                                                                             *
  0000                21     ?B_VAR_BANKING  EQU  0    ; Variable Banking via L51_BANK (far memory support)*
                      22     ;                         ; 0 Variable Banking does not use L51_BANK.A51      *
                      23     ;                         ; 1 Variable Banking uses this L51_BANK.A51 module  *
                      24     ; Notes: ?B_VAR_BANKING uses the 'far' and 'far const' C51 memory types to    *
                      25     ;        extent the space for variables in RAM and/or ROM of classic 8051     *
                      26     ;        device.  The same hardware as for code banking is used.  Program     *
                      27     ;        code banking and variable banking share the same hardware I/O pins.  *
                      28     ;        The C51 Compiler must be used with the VARBANKING directive.         *
                      29     ;        Variable Banking is only supported with the LX51 linker/locater.     *
                      30     ;                                                                             *
  00FF                31     ?B_RST_BANK     EQU  0xFF ; specifies the active code bank number after CPU   *
                      32     ;                         ; Reset.  Used to reduce the entries in the         *
                      33     ;                         ; INTERBANK CALL TABLE.  The value 0xFF disables    *
                      34     ;                         ; this LX51 linker/locater optimization.            *
                      35     ; Note:  Interbank Call Table optimization is only possible with LX51.        *
                      36     ;                                                                             *
                      37     ;-----------------------------------------------------------------------------*
                      38     ;                                                                             *
                             ENDIF;                                                                        *
                      50     ;                                                                             *
                      51     IF  ?B_MODE = 1;                                                              *
                      52     ;-----------------------------------------------------------------------------*
                      53     ; if ?BANK?MODE is 1 define the following values                              *
                      54     ; For Bank-Switching via XDATA Port define XDATA Port Address / Bits          *
  FFFF                55     ?B_XDATAPORT    EQU     0FFFFH   ; default is XDATA Port Address 0FFFFH       *
  0000                56     ?B_FIRSTBIT     EQU     0        ; default is Bit 0                           *
                      57     ;-----------------------------------------------------------------------------*
                      58     ENDIF;                                                                        *
                      59     ;                                                                             *
                             ENDIF;                                                                        *
                     118     ;                                                                             *
                             ENDIF;                                                                        *
                     139     ;                                                                             *
                     140     ;******************************************************************************
                     141     ;                                                                             *
                     142     ; THEORY OF OPERATION                                                         *
                     143     ; -------------------                                                         *
                     144     ; The section below describes the code generated by BL51 or LX51 and the      *
A51 MACRO ASSEMBLER  L51_BANK                                                             02/14/2007 13:36:03 PAGE     2

                     145     ; operation of the L51_BANK.A51 module.  BL51/LX51 generates for each         *
                     146     ; function that is located in a code memory bank and called from the common   *
                     147     ; area or a different code bank and entry into the INTRABANK CALL TABLE.  The *
                     148     ; INTRABANK CALL TABLE is located in the SEGMENT ?BANK?SELECT and listed in   *
                     149     ; the Linker MAP file. The entries in that TABLE have the following format:   *
                     150     ;                                                                             *
                     151     ;   ?FCT?1:  MOV  DPTR,#FCT     ; Load Address of target FCT                  *
                     152     ;            JMP  ?B_BANKn      ; Switch to Bank and Jump to Target Code      *
                     153     ;                                                                             *
                     154     ; Instead of directly calling the function FCT, the Linker changes the entry  *
                     155     ; to ?FCT?1.  This entry selects the bank where the function FCT is located   *
                     156     ; and calls that function via the routines defined in this L51_BANK.A51 file. *
                     157     ; The L51_BANK.A51 file contains two sets of functions for each bank:         *
                     158     ;                                                                             *
                     159     ; ?B_BANKn    is a routine which saves the entry of the ?B_SWITCHn function   *
                     160     ;             for the current active bank on the STACK and switches to the    *
                     161     ;             bank 'n'.  Then it jumps to the address specified by the DPTR   *
                     162     ;             register.  It is allowed to modify the following registers in   *
                     163     ;             the ?B_BANKn routine:  A, B, R0, DPTR, PSW                      *
                     164     ;                                                                             *
                     165     ; ?B_SWITCHn  is a function which selects the bank 'n'.  This function is     *
                     166     ;             used at the end of a user function to return to the calling     *
                     167     ;             code bank.  Only the following registers may be altered in the  *
                     168     ;             ?B_SWITCHn function:  R0, DPTR                                  *
                     169     ;                                                                             *
                     170     ; The current active bank is stored in ?B_CURRENTBANK.  RTX-51 uses this      *
                     171     ; variable to restore the code bank after a task switch.  To get correct      *
                     172     ; results, ?B_CURRENTBANK must be set to the code bank before the hardware    *
                     173     ; switch is done, or the code banking sequences must be interrupt protected.  *
                     174     ;******************************************************************************
                     175     
                     176                     NAME    ?BANK?SWITCHING
                     177     
                     178                     PUBLIC  ?B_NBANKS, ?B_MODE, ?B_CURRENTBANK, ?B_MASK
                     179                     PUBLIC  ?B_FACTOR, ?B_RST_BANK
                             ENDIF
                     183     
                     184     ; Standard SFR Symbols required in L51_BANK.A51
  00E0               185     ACC     DATA    0E0H
  00F0               186     B       DATA    0F0H
  0082               187     DPL     DATA    82H
  0083               188     DPH     DATA    83H
  00A8               189     IE      DATA    0A8H
  00AF               190     EA      BIT     IE.7
                     191     
                     192     
                     193     ; generate Mask and Bank Number Information
                             ELSEIF  ?B_NBANKS <= 4
  0003               197       MASK          EQU     00000011B
                             ENDIF     
                     207     
                             ENDIF  ; close block IF ?B_MODE = 0 *******************************************
                     455     
                     456     
                     457     IF ?B_MODE = 1 ;***************************************************************
                     458     
  0001               459     ?B_FACTOR       EQU     1 SHL ?B_FIRSTBIT
                     460     
  0003               461     ?B_MASK         EQU     MASK SHL ?B_FIRSTBIT
                     462     
                     463     BANKN           MACRO   N
                     464     BANK&N           EQU     N SHL ?B_FIRSTBIT
                     465                     ENDM
                     466     
  0000               467     CNT             SET     0
                     468     
A51 MACRO ASSEMBLER  L51_BANK                                                             02/14/2007 13:36:03 PAGE     3

                     469                     REPT    ?B_NBANKS
                     470                     BANKN   %CNT
                     471     CNT             SET     CNT+1
                     472                     ENDM
                     473+1                   BANKN   %CNT
                     476+1                   BANKN   %CNT
                     479+1                   BANKN   %CNT
                     482+1                   BANKN   %CNT
                     485     
                     486     
                     487     ?C_INITSEG      SEGMENT   CODE          ; Segment for Variable Initialization
----                 488                     RSEG    ?C_INITSEG
0000 01              489                     DB      01H             ; IData
0001 00       F      490                     DB      ?B_CURRENTBANK  ; Init Current Bank
0002 00              491                     DB      0               ; Set to Zero
0003 41              492                     DB      41H             ; XData
0004 FFFF            493                     DW      ?B_XDATAPORT    ; Init XDATA Port
0006 00              494                     DB      0               ; Set to Zero
                     495     
                     496                     PUBLIC  ?B_XDATAPORT
                     497     
                     498     ?BANK?DATA      SEGMENT DATA
----                 499                     RSEG    ?BANK?DATA
0000                 500     ?B_CURRENTBANK: DS      1
                     501     
                     502     
                             ENDIF
                     579     
                     580     
                     581     IF ?B_NBANKS <= 16
                     582       ; Convert Bank No in Accu to Address * 16
                     583       IF  ?B_FIRSTBIT = 0
                     584       CONVBANKNO    MACRO
                     585                     SWAP    A
                     586                     ENDM
                     587       ENDIF
                     588     
                               ENDIF
                     595     
                               ENDIF
                     602     
                               ENDIF
                     608     
                               ENDIF
                     613     
                               ENDIF
                     619     
                               ENDIF
                     626     
                               ENDIF
                     633     
                     634       SWITCH        MACRO   N
                     635                     ORG     N * 16
                     636                     PUBLIC  ?B_SWITCH&N
                     637       ?B_SWITCH&N:
                     638                     MOV     R0,A
                     639                     MOV     A,#BANK&N
                     640                     MOV     DPTR,#?B_XDATAPORT
                     641                     MOV     ?B_CURRENTBANK,A
                     642                     MOVX    @DPTR,A
                     643                     MOV     A,R0
                     644                     RET
                     645                     ENDM
                     646       
                     647     ENDIF
                     648     
A51 MACRO ASSEMBLER  L51_BANK                                                             02/14/2007 13:36:03 PAGE     4

                     649     
                     650     SELECT          MACRO   N
                     651     LOCAL           XLABEL, YLABEL
                     652     
                     653                     PUBLIC  ?B_BANK&N
                     654     ?B_BANK&N:      
                     655                     MOV     A,?B_CURRENTBANK
                     656                     ANL     A,#?B_MASK
                     657                     CONVBANKNO         ; Convert Bank Number to Address
                     658                     PUSH    ACC
                     659                     MOV     A,#HIGH ?BANK?SWITCH
                     660                     PUSH    ACC
                     661                     PUSH    DPL
                     662                     PUSH    DPH
                     663                     LJMP    ?B_SWITCH&N
                     664     
                     665                     ENDM
                     666     
                     667     
                     668     ?BANK?SELECT    SEGMENT  CODE
                     669     
----                 670                     RSEG    ?BANK?SELECT
  0000               671     CNT             SET     0
                     672     
                     673                     REPT    ?B_NBANKS
                     674                     SELECT  %CNT
                     675     CNT             SET     CNT+1
                     676     
                     677                     ENDM
                     678+1                   SELECT  %CNT
                     695+1                   SELECT  %CNT
                     712+1                   SELECT  %CNT
                     729+1                   SELECT  %CNT
                     746     
                     747     
                     748     
                     749     ?BANK?SWITCH    SEGMENT  CODE  PAGE
                     750     
----                 751                     RSEG    ?BANK?SWITCH
  0000               752     CNT             SET     0
                     753     
                     754                     REPT    ?B_NBANKS
                     755                     SWITCH  %CNT
                     756     
                     757     CNT             SET     CNT+1
                     758                     ENDM
                     759+1                   SWITCH  %CNT
                     772+1                   SWITCH  %CNT
                     785+1                   SWITCH  %CNT
                     798+1                   SWITCH  %CNT
                     811     
                               ENDIF
                     820     
                               ENDIF
                     828     
                     829     ENDIF  ; close block IF ?B_MODE = 1 *******************************************
                     830     
                     831     
                             ENDIF  ; close block IF ?B_MODE = 4 *******************************************
                     904     
----                 905                     RSEG    ?BANK?SELECT
                     906     
                     907     ;************************  SWITCHBANK FUNCTION  *******************************
                     908     ;                                                                             *
                     909     ; SWITCHBANK allows use of bank-switching for C programs                      *
                     910     ;                                                                             *
A51 MACRO ASSEMBLER  L51_BANK                                                             02/14/2007 13:36:03 PAGE     5

                     911     ; prototype:   extern switchbank (unsigned char bank_number);                 *
                     912     ;                                                                             *
                     913     ;******************************************************************************
                     914                     PUBLIC  _SWITCHBANK, ?B_SWITCHBANK_A
                     915     
0048 EF              916     _SWITCHBANK:    MOV     A,R7
                     917     
                             ENDIF  ; close block IF ?B_MODE = 0 *******************************************
                     934     
                     935     IF ?B_MODE = 1 ;***************************************************************
                     936     
0049                 937     ?B_SWITCHBANK_A:
                             ENDIF
                     942     
                     943     IF ?B_NBANKS <= 16
0049 C4              944                     SWAP    A
                     945     ENDIF
004A 900000   F      946                     MOV     DPTR,#?BANK?SWITCH
004D 73              947                     JMP     @A+DPTR
                     948     
                     949     ENDIF  ; close block IF ?B_MODE = 1 *******************************************
                     950     
                             ENDIF  ; close block IF ?B_MODE = 4 *******************************************
                     980     
                     981     
                             ENDIF  ; close block IF ?B_VAR_BANKING ****************************************
                    1394     
A51 MACRO ASSEMBLER  L51_BANK                                                             02/14/2007 13:36:03 PAGE     6

SYMBOL TABLE LISTING
------ ----- -------


N A M E             T Y P E  V A L U E   ATTRIBUTES

?BANK?DATA . . . .  D SEG    0001H       REL=UNIT
?BANK?SELECT . . .  C SEG    004EH       REL=UNIT
?BANK?SWITCH . . .  C SEG    003BH       REL=PAGE
?BANK?SWITCHING. .  N NUMB   -----       
?B_BANK0 . . . . .  C ADDR   0000H   R   SEG=?BANK?SELECT
?B_BANK1 . . . . .  C ADDR   0012H   R   SEG=?BANK?SELECT
?B_BANK2 . . . . .  C ADDR   0024H   R   SEG=?BANK?SELECT
?B_BANK3 . . . . .  C ADDR   0036H   R   SEG=?BANK?SELECT
?B_CURRENTBANK . .  D ADDR   0000H   R   SEG=?BANK?DATA
?B_FACTOR. . . . .  N NUMB   0001H   A   
?B_FIRSTBIT. . . .  N NUMB   0000H   A   
?B_MASK. . . . . .  N NUMB   0003H   A   
?B_MODE. . . . . .  N NUMB   0001H   A   
?B_NBANKS. . . . .  N NUMB   0004H   A   
?B_RST_BANK. . . .  N NUMB   00FFH   A   
?B_RTX . . . . . .  N NUMB   0000H   A   
?B_SWITCH0 . . . .  C ADDR   0000H   R   SEG=?BANK?SWITCH
?B_SWITCH1 . . . .  C ADDR   0010H   R   SEG=?BANK?SWITCH
?B_SWITCH2 . . . .  C ADDR   0020H   R   SEG=?BANK?SWITCH
?B_SWITCH3 . . . .  C ADDR   0030H   R   SEG=?BANK?SWITCH
?B_SWITCHBANK_A. .  C ADDR   0049H   R   SEG=?BANK?SELECT
?B_VAR_BANKING . .  N NUMB   0000H   A   
?B_XDATAPORT . . .  N NUMB   FFFFH   A   
?C_INITSEG . . . .  C SEG    0007H       REL=UNIT
ACC. . . . . . . .  D ADDR   00E0H   A   
B. . . . . . . . .  D ADDR   00F0H   A   
BANK0. . . . . . .  N NUMB   0000H   A   
BANK1. . . . . . .  N NUMB   0001H   A   
BANK2. . . . . . .  N NUMB   0002H   A   
BANK3. . . . . . .  N NUMB   0003H   A   
B_SWITCH_SIZE. . .    ----   -----       
CNT. . . . . . . .  N NUMB   0004H   A   
DPH. . . . . . . .  D ADDR   0083H   A   
DPL. . . . . . . .  D ADDR   0082H   A   
EA . . . . . . . .  B ADDR   00A8H.7 A   
IE . . . . . . . .  D ADDR   00A8H   A   
LONG_MACRO . . . .    ----   -----       
MASK . . . . . . .  N NUMB   0003H   A   
N. . . . . . . . .    ----   -----       
SAVEA. . . . . . .    ----   -----       
_SWITCHBANK. . . .  C ADDR   0048H   R   SEG=?BANK?SELECT


REGISTER BANK(S) USED: 0 


ASSEMBLY COMPLETE.  0 WARNING(S), 0 ERROR(S)
