如何用CAST7定位绝对代码段?本人跪地求救!!!!!!
虽然用C(COSMIC C for ST7)编程可大大缩短编程时间,提高代码的可移植性。但有时还是不得已使用 汇编。比如在用C51编程时,LCD 字库,热启动代码,无用空间填充,这些用汇编程序还是要方便很多。因 为用C 不方便生成绝对代码段,也就是不方便将程序定位于某一地址。
以下编译环境是ST7 Visual Develop 中的COSMIC C 我在汇编程序中如下写: TITLE "speed_table.s" #INCLUDE "io72324.s" ; st72311 registers and memory mapping file
;#define OCF1 6 ; Timer status register Output compare flag 1 position. switch .text xdef table table: dc.b 1,2,3
end
在c主程序中如下写: extern unsigned char table[3]; void main(void) {unsigned char temp; while(1)temp=table[0]; }
编译时报错: #error clnk Debugstepmotor.lkf:1 symbol _table not defined (Debugmain_asm.o ) 查看.map文件
Debugmain_asm.o: start 0000e072 end 0000e078 length 6 section .text start 00000000 end 000000d0 length 208 section .debug
Debugspeed_table.o: start ******** end ******** length 0 section .text *** removed *** start 000000d0 end 00000126 length 86 section .debug
发现speed_table文件没有生成任何代码
如在主程序中如下写: extern unsigned char table[3]; void main(void) {unsigned char temp; while(1);//temp=table[0]; } 即取消调用,则编译可通过,但查看.map文件 Debugmain_asm.o: start 0000e072 end 0000e074 length 2 section .text start 00000000 end 000000b2 length 178 section .debug
Debugspeed_table.o: start ******** end ******** length 0 section .text *** removed *** start 000000b2 end 00000108 length 86 section .debug
发现speed_table文件仍然没有生成任何代码
我反复试了其它指令 XDEF XFER ORG OFFSET 发现均不管用 不知如何才能简洁明了地实现汇编与C的连接??????????????????????? 就如下面C51中的那样!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 请高手赐教,本人跪地感谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
×××××××××××××××××××××××××××××××××××××××××× ××××××××××××××以下请高手略过,免得浪费您时间××××××××××××× ××××××××××××××××××××××××××××××××××××××××××
在keil C51的汇编程序中可用如下代码将汉字GB码定位于ROM的指定地址(1ECCH) ;=========================================================================================== PUBLIC HZ_INDEX ;PUBLIC HZDOT
CSEG AT 1ECCH ;XXXXH tempararily dec the weldpara size=16 ;one hanzi zimo(16*16) occupy 32 bytes(in EEPROM) add the index table 2 byte(in CPU) ;the index table chief address is calculated as follow:2000H(8192)-CHAR_NUM-2*HZ_NUM ;view the asc.a51 and get the CHAR_NUM
;HZ_NUM EQU 139
HZ_INDEX: DB 0A1H,0FDH,0B0H,0E3H,0B0H,0EBH,0B1H,0B8H DB 0B1H,0DFH,0B1H,0E0H,0B2H,0BBH,0B2H,0C4H DB 0B2H,0CEH,0B3H,0A4H,0B3H,0C9H,0B3H,0D8H DB 0B3H,0E5H,0B4H,0A2H,0B4H,0ABH,0B4H,0D3H DB 0B4H,0E6H,0B4H,0EDH,0B4H,0EFH,0B5H,0C2H DB 0B5H,0E7H,0B5H,0F7H,0B6H,0A8H,0B6H,0AFH DB 0B6H,0C1H,0B6H,0C8H,0B7H,0B4H,0B7H,0B5H DB 0B7H,0BDH,0B7H,0D6H,0B7H,0FBH,0B8H,0CBH DB 0B8H,0D6H,0B8H,0DFH,0B8H,0F4H,0B8H,0F6H DB 0B9H,0A4H,0B9H,0A6H,0B9H,0A9H,0B9H,0B2H DB 0B9H,0E2H,0B9H,0FAH,0BAH,0B8H,0BBH,0D8H DB 0BBH,0FAH,0BCH,0A4H,0BCH,0ABH,0BCH,0CAH DB 0BCH,0D0H,0BCH,0D2H,0BCH,0E4H,0BDH,0C7H DB 0BDH,0D3H,0BDH,0E2H,0BDH,0F8H,0BEH,0ABH DB 0BEH,0B6H,0BEH,0DFH,0BEH,0E0H,0BFH,0C7H DB 0BFH,0D5H,0BFH,0D8H,0BFH,0ECH,0BFH,0EDH DB 0C1H,0AAH,0C1H,0C1H,0C2H,0B7H,0C2H,0C1H DB 0C2H,0CAH,0C2H,0DDH,0C2H,0EBH,0C2H,0EDH DB 0C2H,0F6H,0C3H,0A6H,0C3H,0DCH,0C4H,0A3H DB 0C4H,0DCH,0C5H,0E4H,0C6H,0B5H,0C6H,0F7H DB 0C7H,0EBH,0C7H,0FDH,0C8H,0A1H,0C8H,0B7H DB 0C8H,0CFH,0C8H,0EBH,0C9H,0CCH,0C9H,0CFH DB 0C9H,0E8H,0CAH,0B1H,0CAH,0BDH,0CAH,0D4H DB 0CAH,0D6H,0CAH,0DCH,0CAH,0E2H,0CAH,0E4H DB 0CAH,0FDH,0CBH,0ABH,0CBH,0BFH,0CBH,0D9H DB 0CBH,0F8H,0CCH,0D8H,0CCH,0E5H,0CDH,0A8H DB 0CDH,0B3H,0CDH,0EAH,0CEH,0A2H,0CEH,0BBH DB 0CEH,0F3H,0CFH,0B5H,0CFH,0C2H,0CFH,0DEH DB 0CFH,0F2H,0CFH,0FBH,0D0H,0C5H,0D0H,0CDH DB 0D0H,0CEH,0D0H,0D4H,0D1H,0A1H,0D1H,0D3H DB 0D1H,0F4H,0D2H,0BAH,0D2H,0BBH,0D2H,0D5H DB 0D2H,0F5H,0D3H,0A6H,0D3H,0EBH,0D4H,0B2H DB 0D5H,0E6H,0D5H,0FDH,0D6H,0C3H,0D6H,0C6H DB 0D6H,0C7H,0D6H,0CAH,0D6H,0D8H,0D7H,0A2H DB 0D7H,0A8H,0D7H,0AAH,0D7H,0D4H END ;==========================================================================================
在对应的C程序中通过如下说明即可实现C程序调用汇编中的GB码
extern uint code HZ_INDEX[];
在C程序中可直接取出汇编中的GB码如用以下语句: uint temp; temp=HZ_INDEX[1]; 则temp=0xB0E3; //BOE3是“般”的GB码 若temp=HZ_INDEX[5]; 则temp=0xB1E0; //B1E0是“编”的GB码 这样调用起来非常方便直观。
对于不用的中断,可用如下的汇编将其地址填充(当然若用ST7就不用这样麻烦了)
;=========================================================================================== AUXR1 EQU 0A2H
guide_fill:
cseg at 0003H ;external int0 NOP NOP NOP ORL AUXR1, #0x08 NOP NOP
cseg at 0013H ;external int1 NOP NOP NOP ORL AUXR1, #0x08 NOP NOP
;cseg at 0023H ; ;NOP ;NOP ;NOP ;ORL AUXR1, #0x08 ;NOP ;NOP
cseg at 002BH ;power down NOP NOP NOP ORL AUXR1, #0x08 NOP NOP cseg at 0053H ;WDT NOP NOP NOP ORL AUXR1, #0x08 NOP NOP
cseg at 0033H ;I2C NOP NOP NOP ORL AUXR1, #0x08 NOP NOP cseg at 0043H ; NOP NOP NOP ORL AUXR1, #0x08 NOP NOP
cseg at 006BH ; NOP NOP NOP ORL AUXR1, #0x08 NOP NOP END ;===========================================================================================
上面程序中 ORL AUXR1, #0x08 的作用是软件复位(philips lpcxxx单片机的软件复位指令)
不用的代码空间可填充如下拦截指令
;public lanjie cseg at 0E10h lanjie:
db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h db 00h,00h,00h,43h,0a2h,08h,00h,00h,00h,00h,00h,43h,0a2h,08h,00h,00h
END
在ST7 COSMIC CAST7中,如何实现以上类似功能呢?
|
|