絕對尋址
CSEG, BIT BSEG, DSEG, ISEG, XSEG 使用
1. CSEG 定義ROM區程序或數據保存的開始地址
CSEG AT 3800H
UCTABLHALLGS_TAB:
DB 07
DB 05
DB 04
DB 00
DB 02
DB 03
2. BIT
DATA_SEG SEGMENT DATA BITADDRESSABLE
RSEG DATA_SEG ; Relocatable
; bit-addressable
; segment
BITS: DS 1 ; A 1-byte
; bit-addressable
; variable
ALARM BIT BITS.0 ; Bit 0 in BITS
D1_OPEN BIT ALARM+1 ; Bit 1 in BITS
D2_OPEN BIT ALARM+2 ; Bit 2 in BITS
P1_2 BIT 90h.2 ; SFR P1.2
3. DSEG
DSEG AT 0x40 ; absolute DATA segment at 40H
TMP_A: DS 2 ; absolute data word variable
; named TMP_A
TEM_B: DS 4 ; absolute data dword (32-bit)
; variable named TMP_B
4. ISEG
ISEG AT 0xC0 ; absolute IDATA segment
; at 0C0H
TMP_IA: DS 2 ; absolute idata word variable
; named TMP_IA
TEM_IB: DS 4 ; absolute idata dword (32-bit)
; variable named TMP_IB
5. XSEG
XSEG AT 1000H ; absolute XDATA segment
; at 0x1000
OEM_NAME: DS 25 ; 25 bytes space
; for variable OEM_NAME
PRD_NAME: DS 25 ; 25 bytes space
; for variable PRD_NAME
VERSION: DS 25 ; 25 bytes space
; for variable VERSION
C 使用 at 絕對定位
The _at_ keyword allows you to specify the address for uninitialized variables in your C source files.
struct link {
struct link idata *next;
char code *test;
};
struct link idata list _at_ 0x40; /* list at idata 0x40 */
char xdata text[256] _at_ 0xE000; /* array at xdata 0xE000 */
int xdata i1 _at_ 0x8000; /* int at xdata 0x8000 */
char far ftext[256] _at_ 0x02E000; /* array at xdata 0x03E000 */
void main ( void ) {
link.next = (void *) 0;
i1 = 0x1234;
text [0] = 'a';
ftext[0] = 'f';
}
重複字符可以使用 REPT 宏定義,參考如下
$NOMOD51
NNOP MACRO N
REPT N
NOP
ENDM
ENDM
OUTPUTPIN BIT P1.5
ORG 0000H
LJMP START
ORG 0100H
START:
MOV CLKCON,#00H;
LOOP:
CPL OUTPUTPIN ; 3
NNOP 42
LJMP LOOP; 5
LOOP1:
SJMP $
END