ANSIC????KeilC51????????
?????? ??????
(
???????????????????? ??? 300071 ??
??????????????ANSIC?????????KeilC51????????????????????????????KeilC51??д?????????????????????????洢??????????????????????????????RAM??????ζ?λ?????????á????????NULL????????????????????????????????????洢?????????????????????????Ч???????????????????????ν??и?Ч??????????????????????????ucosii?????KeilC51??С?????????????????????????裬????????????????Ч?????ANSIC????KeilC51???ο???
??????ANSI C???? ??? KeilC
1 ????
C????????ú?????????????????????к????????????????д?????????????????????????????????????????Ч???????????????????????C???????????????????C????????????????????????????????????X8086??CPU??д??C?????????????????ù?????????????????????KeilC51??51??е????????????C???????????KeilC????????????д???????Ч??C51????
2 ????洢????????????С??????
KeilC?е???????????????????????????????????洢????(Memory type)????????????????data??idata??pdata??xdata?????洢????????????????????????????????RAM??????????RAM????R0??R1??????RAM????DPTR??????RAM??KeilC??????????洢??(memory
model)??С????????????????????????£???????????????洢????????????data??pdata??xdata?洢?????????洢?????????????ν?????????????????????
????C?????н????????????????ANSI?????KeilC????????????洢???????????????????????????????????????????????С???±?????????????????????????С??????????xdata??????????????????е??????????????xdata????pdata???????????????洢????????????????С???±???
3 ???????????洢????????(memory-specific
pointer)???????????(generic pointer)
????????????????????????е????????????????????????????????????????洢?????????????????Ч?????????1????
????????????????????????????????????洢?????????????????????????????????洢???????????????????????????????1??????????????????????
?????????á???????????????????????????C?CLDPTR?????????C??CLDPTR?и???????????????洢?????????????RAM??????????á?????洢??????????????????????RAM?????????????????????????????????ж?????????????????Ч????
??????洢?????????????????????????????洢????????????3???????????????????????棬??KeilC?д?????????????????????????????????飬???е??????????????xdata????pdata??????????????洢???????????????е?????????????????????洢??????????
4 ????????????reentrant?????
X8086CPU?????е?Dos??Windows?????е?????????????????????????Ч???KeilC??????????ü?????????????????????????????????????????????????????????????????ANSI?????????KeilC????????????????????????????????н?????????????????????????????????????reentrant?????(1)??
?????????????????????????????????????????????????????????????????????????????????????reentrant????KeilC?±?????????????о??檔????????recursive
call to non-reentrant function?????????????????????????????????multiple call to segment?????????????????????ж????????ж???????????????????????????????????????reentrant??????????????????÷??????????????????????к???????????????????????(call
tree)??????????????????????????и?????????????????ú??????????????????????????ucosii??????????????????????л??????KeilC?????????????????????????????????ж????????
????ж??????????????鷳????β??????е???????????reentrant??????????????????????????????reentrant????????????????????
??????????????KeilC?????????(simulated
stack)??????????SP?????????????(hardware stack)????????????????С???·?????????????XDATA??PDATA??IDATA????С????????????????????????????????????????????????????????????????洢??????????????C_XBP??
?C_PBP?? ?C_IBP??1??????????????ú?Dos???????μ?????????????????????????????????????????????У?
??? |
???????? |
?????? |
??????????????????????????? |
??????????δ??? |
???????????? |
??????????? |
???????????????????? |
????????????????? |
????????? |
|
??????????? |
X0886CPU?????????mov eax, dword ptr [esp+20]?????????????????????????51???????ж????????????????????????????????????????????????????????????????????????????????????????ò??????????reentrant?????
5?????????RAM?????????ζ?λ??????????
?????????????RAM?32K????KeilC?????????????RAM?64K????????????????????32K??RAM?????????????????????????н??????????磬????????????????RAM??Χ?????0x8000-0xFFFF?????????????KeilC?????Χ??
????xdata?ζ?λ?????????????RAM???????0x0000-0x4000??0xC000-0xFFFF???????з???????BL51?????XDATA(2)??BL51 MyProgram.obj
XDATA(0x0000-0x4000,0xC000-0xFFFF)????KeilC????????????У???????project????option for
target1????BL51 location????Xdata???????????0x0000-0x4000,0xC000-0xFFFF??
????pdata?ζ?λ????????????pdata???0x8000-0x80FF??????RAM?????????з???????BL51?????PDATA(2)??BL51 MyProgram.obj PDATA(0x8000)???????????????£???????project????option
for target1????BL51 location????Pdata???????????0x8000??????0x8000????pdata????????????????Startup.a51????????£?
?? ????Startup.a51?????????KeilC\C51\LIB\Startup.a51?????????????????£???????????????С??? ???startup.a51?е?
PPAGEENABLE EQU0 ;
set to 1 if pdata object are used.
PPAGE EQU0 ;
define PPAGE number.
??????
PPAGEENABLE EQU1 ;
set to 1 if pdata object are used.
PPAGE EQU80H;
define PPAGE number.
????????PPAGE???????赥???P2?????????????????????MOVX
A,@R0?????8λ???????PPAGE????????pdata??????????????????????????????????P2??????????
?????????÷??????????????·??????xdata????????RAM?????Χ??0x0000??0x8000????????????????0x8000?????????μ?(0xFFFF+1
)????????????????÷???????? ????startup.a51???? ???startup.a51?е???????????′???
XBPSTACK EQU1 ;
set to 1 if large reentrant is used.
XBPSTACKTOP EQU7FFFH+1; set top of stack to highest
location+1..
??????????÷??????????????????0xFF+1???????Щ????????????????????pdata???б??????0x80????????????????????0x80????xdata?????????????????????pdata??????0-0x007F??xdata???0x0080-0x00FF?????????????????0x00FF??????xdata???????????????????????pdata?ζ?λ??xdata?ε???棬????????pdata??????????λ??0x100??
6 KeilC?е???????
?????????????????????????????????????????????????(3)????????????????????????(overlay)????????С???±????C51????????????????data????У???????????data???KeilC??????overlay??????????????к????????????γ??????????????????(call
tree)??????????????????????????????????????????????????????????????????????á?KeilC???????????????????????????????????ú??????????????????????
????????????????????????????KeilC???????????????????????????????? ??ú????????ú????????KeilC?????????????????????ú?????????????????????????е?????????????????????????????????????????????????????
??????????????????BL51??OVERLAY?????????????????(3)???? ??????????????????????????reentrant?????????reentrant?????????????????У????????????????????
ANSIC?У????????????????????????????????????????KeilC??????????????3??????(3)???????KeilC????????????????????????ú???????????Σ?????????????????δ???????????????????????????????????????????????????????????????????????
???ú??????reentarnt??????? ?????????????????????????????д????
7 NULL???????
C???????漲?κα???????????????0????檔??????????xdata????0????????????????????????????????????????亯??malloc(int
size)??malloc????????????????0??????????棬????????0??????????????????NULL????????????????????????????????????????????????????????
Char xdata NULLAddr _at_ 0
?????????KeilC??_at_?????????????NULLAddr?????0?????????????????????????0?????
8 ??????(byte
order)
X8086??CPU????????????????????????????????????????KeilC51?????????????????????????????????????????????TCP/IP?????е?htons()??????????????????????????????????X8086??KeilC51???htons()???????????
9 ??????
?????????????????д??????51??????????C??????????????KeilC?????????????????????(1)????????????????????overlay????????????д??????????(1)??????????????????????C??????????????????????е????????????????????C??????????????(1)??
10 ?????
pdata??data??KeilC?????????ANSIC????????????????????????????
11 ?????Ucosii??KeilCС???μ????
Ucosii??????????????KeilC???????(4)?????????????????С???????????????????£?
(1)?????е????????????xdata?????????
(2)???????????*?????????????????????????*???????xdata??
(3)?????е??????????????reentrant????????Ucosii???????????????????ж???Щ??????????????????????????????????
(4)????????????????RAM??????????xdata?ε???????????????彲????????С???·????????á?
??С???·??????????????????RAM???????0xFF??????????????KeilC???????????????????????KeilC????????е?data????????????????SP??????data??????????????????????????????????????????????KeilC????????????棬??????????????????
Ucosii????????????????????????????????????????? ????????????RAM?е??????????Dos??????????浱??????????????????
?????KeilC????????????????????????????????????(5)???? ?????KeilCС???£????????????????????????????????????????????????????
?????C_IBP????????????????????RAM?????????μ?????????ó????????(4)??????????????????′???
?STACK SEGMENT IDATA
RSEG
?STACK
StkBottom:
???StkBottom?????????????????????????С?????????????????????????RAM????????е???????????????KeilC??????ж???????????????????μ?????ж?????????????????ucosii???????
(5)???????????Ucosii???????л???KeilC??????????????????????????main???????????????(????Task1)????????????OSTaskCreate??????KeilC?????main??????????Task1??????????????е???????????reentrant???????????б?????????????????????????????????
(6)NULL???????????????????????????NULL???????
(7)??????Ucosii?????????????????51??????
(8)??????Ucosii?????pdata??data????????????????Щ??????(4)??
?ο??????
[1]?1?KeilC??? ??Cx51 Compiler??http://www.keil.com 2001??5?? P103-P108??P126,P155-P158
[2]?1?KeilC??? ??Macro Assembler and
Utilities for 8051 and Variants??http://www.keil.com 2000??7?? p325,p317
[3)?1?KeilC??? ??Function Pointers in C51??http://www.keil.com/appnotes/files/apnt_129.pdf 1999??4??27
[4]???? ??uCOS51 ?????á?http://www.zlgmcu.com/philips/philips-embedsys.asp
2002??10??3 P3,P3
[5]???? ??uCOS51?????????????http://www.zlgmcu.com/philips/philips-embedsys.asp
2002??10??9
??????TCP/IP????????/products_serial_server.htm
What I learned from Porting of ANSI C program to KeilC51
Li Zhanglin Zhang Limin
(.College of
Information Technology Science,
ABSTRACT??The thesis introduces what should be
noted when porting an ANSI C program to KeilC51. It explains memory type,
pointer type, reentrant function, segment locating and simulated stack setting
based on your target system, function pointer, NULL pointer issue, byte order,
cross assembly and so on about notation when porting, based on summary of the
author's programming and porting with KeilC51. The thesis gives a analysis in how memory type, pointer type,
reentrant function affect efficiency of program and give a direction on
efficient porting. Finally it illustrates porting of ucosii to KeilC small
model as a example.
Key word??ANSI C program porting KeilC