📄 sdccman.txt
字号:
The inline assembler code can contain any valid code understoodby the assembler, this includes any assembler directivesand comment lines. The compiler does not do any validationof the code within the _asm ... _endasm; keyword pair. Inline assembler code cannot reference any C-Labels, howeverit can reference labels defined by the inline assembler,e.g.:foo() { /* some c code */ _asm ; some assembler code ljmp $0003 _endasm; /* some more c code */ clabel: /* inline assembler cannot referencethis label */ _asm $0003: ;label (can be reference by inline assembleronly) _endasm ; /* some more c code */}In other words inline assembly code can access labels definedin inline assembly within the scope of the funtion. The same goes the other way, ie. labels defines in inlineassembly CANNOT be accessed by C statements. int(16 bit) and long (32 bit) SupportFor signed & unsigned int (16 bit) and long (32 bit) variables,division, multiplication and modulus operations are implementedby support routines. These support routines are all developedin ANSI-C to facilitate porting to other MCUs, althoughsome model specific assembler optimations are used. Thefollowing files contain the described routine, all of themcan be found in <installdir>/share/sdcc/lib.<pending: tabularise this>_mulsint.c - signed 16 bit multiplication (calls _muluint)_muluint.c - unsigned 16 bit multiplication_divsint.c - signed 16 bit division (calls _divuint)_divuint.c - unsigned 16 bit division_modsint.c - signed 16 bit modulus (call _moduint)_moduint.c - unsigned 16 bit modulus_mulslong.c - signed 32 bit multiplication (calls _mululong)_mululong.c - unsigned32 bit multiplication_divslong.c - signed 32 division (calls _divulong)_divulong.c - unsigned 32 division_modslong.c - signed 32 bit modulus (calls _modulong)_modulong.c - unsigned 32 bit modulus Since they are compiled as non-reentrant, interrupt serviceroutines should not do any of the above operations. If thisis unavoidable then the above routines will need to be compiledwith the --stack-auto option, after which the source programwill have to be compiled with --int-long-rent option. Floating Point SupportSDCC supports IEEE (single precision 4bytes) floating pointnumbers.The floating point support routines are derivedfrom gcc's floatlib.c and consists of the following routines:<pending: tabularise this>_fsadd.c - add floating point numbers_fssub.c - subtract floating point numbers_fsdiv.c - divide floating point numbers_fsmul.c - multiply floating point numbers_fs2uchar.c - convert floating point to unsigned char_fs2char.c - convert floating point to signed char_fs2uint.c - convert floating point to unsigned int_fs2int.c - convert floating point to signed int_fs2ulong.c - convert floating point to unsigned long_fs2long.c - convert floating point to signed long_uchar2fs.c - convert unsigned char to floating point_char2fs.c - convert char to floating point number_uint2fs.c - convert unsigned int to floating point_int2fs.c - convert int to floating point numbers_ulong2fs.c - convert unsigned long to floating point number_long2fs.c - convert long to floating point numberNote if all these routines are used simultaneously the dataspace might overflow. For serious floating point usage itis strongly recommended that the large model be used. MCS51 Memory ModelsSDCC allows two memory models for MCS51 code, small and large.Modules compiled with different memory models should neverbe combined together or the results would be unpredictable.The library routines supplied with the compiler are compiledas both small and large. The compiled library modules arecontained in seperate directories as small and large sothat you can link to either set. When the large model is used all variables declared withouta storage class will be allocated into the external ram,this includes all parameters and local variables (for non-reentrantfunctions). When the small model is used variables withoutstorage class are allocated in the internal ram.Judicious usage of the processor specific storage classesand the 'reentrant' function type will yield much more efficientcode, than using the large model. Several optimizationsare disabled when the program is compiled using the largemodel, it is therefore strongly recommdended that the smallmodel be used unless absolutely required. DS390 Memory ModelsThe only model supported is Flat 24. This generates codefor the 24 bit contiguous addressing mode of the DallasDS80C390 part. In this mode, up to four meg of externalRAM or code space can be directly addressed. See the datasheets at www.dalsemi.com for further information on thispart.In older versions of the compiler, this option was used withthe MCS51 code generator (-mmcs51). Now, however, the '390has it's own code generator, selected by the -mds390 switch.Note that the compiler does not generate any code to placethe processor into 24 bitmode (although tinibios in theds390 libraries will do that for you). If you don't usetinibios, the boot loader or similar code must ensure thatthe processor is in 24 bit contiguous addressing mode beforecalling the SDCC startup code.Like the --model-large option, variables will by defaultbe placed into the XDATA segment. Segments may be placed anywhere in the 4 meg address spaceusing the usual --*-loc options. Note that if any segmentsare located above 64K, the -r flag must be passed to thelinker to generate the proper segment relocations, and theIntel HEX output format must be used. The -r flag can bepassed to the linker by using the option -Wl-r on the sdcccommand line. However, currently the linker can not handlecode segments > 64k. Defines Created by the CompilerThe compiler creates the following #defines. SDCC - this Symbol is always defined. SDCC_mcs51 or SDCC_ds390 or SDCC_z80, etc - depending on the model used (e.g.: -mds390) __mcs51 or __ds390 or __z80, etc - depending on the model used (e.g. -mz80) SDCC_STACK_AUTO - this symbol is defined when --stack-auto option is used. SDCC_MODEL_SMALL - when --model-small is used. SDCC_MODEL_LARGE - when --model-large is used. SDCC_USE_XSTACK - when --xstack option is used. SDCC_STACK_TENBIT - when -mds390 is used SDCC_MODEL_FLAT24 - when -mds390 is used SDCC Technical Data OptimizationsSDCC performs a host of standard optimizations in additionto some MCU specific optimizations. Sub-expression EliminationThe compiler does local and global common subexpression elimination,e.g.: i = x + y + 1; j = x + y;will be translated toiTemp = x + y i = iTemp + 1 j = iTempSome subexpressions are not as obvious as the above example,e.g.:a->b[i].c = 10; a->b[i].d = 11;In this case the address arithmetic a->b[i] will be computedonly once; the equivalent code in C would be.iTemp = a->b[i]; iTemp.c = 10; iTemp.d = 11;The compiler will try to keep these temporary variables inregisters. Dead-Code Eliminationint global; void f () { int i; i = 1; /* dead store */ global = 1; /* dead store */ global = 2; return; global = 3; /* unreachable */ }will be changed toint global; void f () { global = 2; return; } Copy-Propagationint f() { int i, j; i = 10; j = i; return j; }will be changed to int f() { int i,j; i = 10; j = 10; return 10; }Note: the dead stores created by this copy propagation willbe eliminated by dead-code elimination. Loop OptimizationsTwo types of loop optimizations are done by SDCC loop invariantlifting and strength reduction of loop induction variables.In addition to the strength reduction the optimizer marksthe induction variables and the register allocator triesto keep the induction variables in registers for the durationof the loop. Because of this preference of the registerallocator, loop induction optimization causes an increasein register pressure, which may cause unwanted spillingof other temporary variables into the stack / data space.The compiler will generate a warning message when it isforced to allocate extra space either on the stack or dataspace. If this extra space allocation is undesirable theninduction optimization can be eliminated either for theentire source file (with --noinduction option) or for agiven function only using #pragma NOINDUCTION.Loop Invariant:for (i = 0 ; i < 100 ; i ++) f += k + l;changed toitemp = k + l; for (i = 0; i < 100; i++) f += itemp;As mentioned previously some loop invariants are not as apparent,all static address computations are also moved out of theloop.Strength Reduction, this optimization substitutes an expressionby a cheaper expression:for (i=0;i < 100; i++) ar[i*5] = i*3;changed toitemp1 = 0; itemp2 = 0; for (i=0;i< 100;i++) { ar[itemp1] = itemp2; itemp1 += 5; itemp2 += 3; }The more expensive multiplication is changed to a less expensiveaddition. Loop ReversingThis optimization is done to reduce the overhead of checkingloop boundaries for every iteration. Some simple loops canbe reversed and implemented using a "decrementand jump if not zero" instruction. SDCCchecks for the following criterion to determine if a loopis reversible (note: more sophisticated compilers use data-dependencyanalysis to make this determination, SDCC uses a more simpleminded analysis). The 'for' loop is of the form for (<symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ | <sym> += 1]) <for body> The <for body> does not contain "continue" or 'break". All goto's are contained within the loop. No function calls within the loop. The loop control variable <sym> is not assigned any value within the loop The loop control variable does NOT participate in any arithmetic operation within the loop. There are NO switch statements in the loop.Note djnz instruction can be used for 8-bit values only,therefore it is advantageous to declare loop control symbolsas char. Ofcourse this may not be possible on all situations. Algebraic SimplificationsSDCC does numerous algebraic simplifications, the followingis a small sub-set of these optimizations.i = j + 0 ; /* changed to */ i = j; i /= 2; /* changed to */ i >>= 1; i = j - j ; /* changed to */ i = 0; i = j / 1 ; /* changed to */ i = j;Note the subexpressions given above are generally introducedby macro expansions or as a result of copy/constant propagation. 'switch' StatementsSDCC changes switch statements to jump tables when the followingconditions are true. The case labels are in numerical sequence, the labels need not be in order, and the starting number need not be one or zero. switch(i) { switch (i) { case 4:... case 1: ... case 5:... case 2: ... case 3:... case 3: ... case 6:... case 4: ... } } Both
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -