* src/SDCC.lex, src/SDCCmain.c, sdc/SDCCglobl.h, doc/sdccman.lyx:
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass book
4 \begin_preamble
5 \pdfoptionpdfminorversion=3
6 \usepackage[
7   pdftitle={SDCC Compiler User Guide},
8   pdfauthor={SDCC development team},
9   pdfsubject={installation, user manual},
10   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
11   pdfpagemode=UseOutlines,
12   colorlinks=true,
13   linkcolor=blue] {hyperref}
14 %
15 \sloppy
16 \tolerance=500          
17 \emergencystretch=30pt 
18 %
19 \date{}
20 \end_preamble
21 \language english
22 \inputencoding default
23 \fontscheme pslatex
24 \graphics default
25 \paperfontsize default
26 \spacing single 
27 \papersize letterpaper
28 \paperpackage a4
29 \use_geometry 1
30 \use_amsmath 0
31 \use_natbib 0
32 \use_numerical_citations 0
33 \paperorientation portrait
34 \leftmargin 30mm
35 \topmargin 20mm
36 \rightmargin 25mm
37 \bottommargin 20mm
38 \secnumdepth 3
39 \tocdepth 3
40 \paragraph_separation indent
41 \defskip medskip
42 \quotes_language swedish
43 \quotes_times 2
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47
48 \layout Comment
49
50 Please note: double dashed longoptions (e.g.
51  --version) are written this way: -
52 \begin_inset ERT
53 status Collapsed
54
55 \layout Standard
56
57 \backslash 
58 /
59 \end_inset 
60
61 -
62 \layout Comment
63
64 Two resp.
65  three consecutive dashes simply result in a long resp.
66  extra long dash.
67 \layout Comment
68
69 Architecture specific stuff (like memory models, code examples) should maybe
70  later go
71 \layout Comment
72
73 into seperate sections/chapters/appendices (it is hard to document PIC or
74  Z80 in 
75 \layout Comment
76
77 a 8051 centered document) - for now simply add.
78 \layout Title
79
80 SDCC Compiler User Guide
81 \layout Date
82
83
84 \size normal 
85 SDCC 2.6.4
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by Subversion
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
132  
133 \series bold 
134 Sandeep Dutta
135 \series default 
136  designed for 8 bit Microprocessors.
137  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
138  8051, 8052
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
140
141 \end_inset 
142
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144  Zilog Z80 based MCUs.
145  It can be retargeted for other microprocessors, support for Microchip PIC,
146  Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargetable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Standard
206
207
208 \begin_inset  Tabular
209 <lyxtabular version="3" rows="8" columns="5">
210 <features>
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
216 <row topline="true" bottomline="true">
217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
218 \begin_inset Text
219
220 \layout Standard
221
222 type
223 \end_inset 
224 </cell>
225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
226 \begin_inset Text
227
228 \layout Standard
229
230 width
231 \end_inset 
232 </cell>
233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
234 \begin_inset Text
235
236 \layout Standard
237
238 default
239 \end_inset 
240 </cell>
241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
242 \begin_inset Text
243
244 \layout Standard
245
246 signed range
247 \end_inset 
248 </cell>
249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
250 \begin_inset Text
251
252 \layout Standard
253
254 unsigned range
255 \end_inset 
256 </cell>
257 </row>
258 <row topline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \layout Standard
263
264 bool
265 \end_inset 
266 </cell>
267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
268 \begin_inset Text
269
270 \layout Standard
271
272 1 bit
273 \end_inset 
274 </cell>
275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
276 \begin_inset Text
277
278 \layout Standard
279
280 unsigned
281 \end_inset 
282 </cell>
283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_inset Text
285
286 \layout Standard
287
288 -
289 \end_inset 
290 </cell>
291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
292 \begin_inset Text
293
294 \layout Standard
295
296 0, 1
297 \end_inset 
298 </cell>
299 </row>
300 <row topline="true">
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_inset Text
303
304 \layout Standard
305
306 char
307 \end_inset 
308 </cell>
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
310 \begin_inset Text
311
312 \layout Standard
313
314 8 bits, 1 byte
315 \end_inset 
316 </cell>
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_inset Text
319
320 \layout Standard
321
322 signed
323 \end_inset 
324 </cell>
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
326 \begin_inset Text
327
328 \layout Standard
329
330 -128, +127
331 \end_inset 
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
334 \begin_inset Text
335
336 \layout Standard
337
338 0, +255
339 \end_inset 
340 </cell>
341 </row>
342 <row topline="true">
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
344 \begin_inset Text
345
346 \layout Standard
347
348 short
349 \end_inset 
350 </cell>
351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
352 \begin_inset Text
353
354 \layout Standard
355
356 16 bits, 2 bytes
357 \end_inset 
358 </cell>
359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
360 \begin_inset Text
361
362 \layout Standard
363
364 signed
365 \end_inset 
366 </cell>
367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
368 \begin_inset Text
369
370 \layout Standard
371
372 -32.768, +32.767
373 \end_inset 
374 </cell>
375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
376 \begin_inset Text
377
378 \layout Standard
379
380 0, +65.535
381 \end_inset 
382 </cell>
383 </row>
384 <row topline="true">
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
386 \begin_inset Text
387
388 \layout Standard
389
390 int
391 \end_inset 
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
394 \begin_inset Text
395
396 \layout Standard
397
398 16 bits, 2 bytes
399 \end_inset 
400 </cell>
401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
402 \begin_inset Text
403
404 \layout Standard
405
406 signed
407 \end_inset 
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \layout Standard
413
414 -32.768, +32.767
415 \end_inset 
416 </cell>
417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
418 \begin_inset Text
419
420 \layout Standard
421
422 0, +65.535
423 \end_inset 
424 </cell>
425 </row>
426 <row topline="true" bottomline="true">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \layout Standard
431
432 long
433 \end_inset 
434 </cell>
435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
436 \begin_inset Text
437
438 \layout Standard
439
440 32 bits, 4 bytes
441 \end_inset 
442 </cell>
443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
444 \begin_inset Text
445
446 \layout Standard
447
448 signed
449 \end_inset 
450 </cell>
451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
452 \begin_inset Text
453
454 \layout Standard
455
456 -2.147.483.648, +2.147.483.647
457 \end_inset 
458 </cell>
459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
460 \begin_inset Text
461
462 \layout Standard
463
464 0, +4.294.967.295
465 \end_inset 
466 </cell>
467 </row>
468 <row topline="true" bottomline="true">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \layout Standard
473
474 float
475 \end_inset 
476 </cell>
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
478 \begin_inset Text
479
480 \layout Standard
481
482 4 bytes IEEE 754
483 \end_inset 
484 </cell>
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
486 \begin_inset Text
487
488 \layout Standard
489
490 signed
491 \end_inset 
492 </cell>
493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
494 \begin_inset Text
495
496 \layout Standard
497
498 \end_inset 
499 </cell>
500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
501 \begin_inset Text
502
503 \layout Standard
504
505 1.175494351E-38, 
506 \family roman 
507 \series medium 
508 \shape up 
509 \size normal 
510 \emph off 
511 \bar no 
512 \noun off 
513 \color none
514 3.402823466E+38
515 \end_inset 
516 </cell>
517 </row>
518 <row topline="true" bottomline="true">
519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
520 \begin_inset Text
521
522 \layout Standard
523
524 pointer
525 \end_inset 
526 </cell>
527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
528 \begin_inset Text
529
530 \layout Standard
531
532 1, 2, 3 or 4 bytes
533 \end_inset 
534 </cell>
535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
536 \begin_inset Text
537
538 \layout Standard
539
540 generic
541 \end_inset 
542 </cell>
543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_inset Text
545
546 \layout Standard
547
548 \end_inset 
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
551 \begin_inset Text
552
553 \layout Standard
554
555 \end_inset 
556 </cell>
557 </row>
558 </lyxtabular>
559
560 \end_inset 
561
562
563 \newline 
564 The compiler also allows 
565 \emph on 
566 inline assembler code
567 \emph default 
568  to be embedded anywhere in a function.
569  In addition, routines developed in assembly can also be called.
570 \newline 
571
572 \newline 
573 SDCC also provides an option (-
574 \begin_inset ERT
575 status Collapsed
576
577 \layout Standard
578
579 \backslash 
580 /
581 \end_inset 
582
583 -cyclomatic) to report the relative complexity of a function.
584  These functions can then be further optimized, or hand coded in assembly
585  if needed.
586  
587 \newline 
588
589 \newline 
590 SDCC also comes with a companion source level debugger SDCDB, the debugger
591  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
592 \newline 
593
594 \newline 
595 The latest version can be downloaded from 
596 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
597
598 \end_inset 
599
600 .
601
602 \series bold 
603  
604 \series default 
605 \emph on 
606 Please note: the compiler will probably always be some steps ahead of this
607  documentation
608 \series bold 
609 \emph default 
610
611 \begin_inset LatexCommand \index{Status of documentation}
612
613 \end_inset 
614
615
616 \begin_inset Foot
617 collapsed false
618
619 \layout Standard
620
621 Obviously this has pros and cons
622 \end_inset 
623
624 .
625 \layout Section
626
627 Open Source
628 \layout Standard
629
630 All packages used in this compiler system are 
631 \emph on 
632 open source
633 \emph default 
634  and 
635 \emph on 
636 freeware
637 \emph default 
638 ; source code for all the sub-packages (pre-processor, assemblers, linkers
639  etc) is distributed with the package.
640  This documentation is maintained using a freeware word processor (LyX).
641 \newline 
642 This program is free software; you can redistribute it and/or modify it
643  under the terms of the GNU General Public License
644 \begin_inset LatexCommand \index{GNU General Public License, GPL}
645
646 \end_inset 
647
648  as published by the Free Software Foundation; either version 2, or (at
649  your option) any later version.
650  This program is distributed in the hope that it will be useful, but WITHOUT
651  ANY WARRANTY; without even the implied warranty
652 \begin_inset LatexCommand \index{warranty}
653
654 \end_inset 
655
656  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
657  See the GNU General Public License for more details.
658  You should have received a copy of the GNU General Public License along
659  with this program; if not, write to the Free Software Foundation, 59 Temple
660  Place - Suite 330, Boston, MA 02111-1307, USA.
661  In other words, you are welcome to use, share and improve this program.
662  You are forbidden to forbid anyone else to use, share and improve what
663  you give them.
664  Help stamp out software-hoarding! 
665 \layout Section
666
667 Typographic conventions
668 \begin_inset LatexCommand \index{Typographic conventions}
669
670 \end_inset 
671
672
673 \layout Standard
674
675 Throughout this manual, we will use the following convention.
676  Commands you have to type in are printed in 
677 \family sans 
678 \series bold 
679 "sans serif"
680 \series default 
681 .
682
683 \family default 
684  Code samples are printed in 
685 \family typewriter 
686 typewriter font.
687
688 \family default 
689  Interesting items and new terms are printed in 
690 \emph on 
691 italic.
692 \layout Section
693
694 Compatibility
695 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
696
697 \end_inset 
698
699  with previous versions
700 \begin_inset LatexCommand \index{Compatibility with previous versions}
701
702 \end_inset 
703
704
705 \layout Standard
706
707 This version has numerous bug fixes compared with the previous version.
708  But we also introduced some incompatibilities with older versions.
709  Not just for the fun of it, but to make the compiler more stable, efficient
710  and ANSI compliant
711 \begin_inset LatexCommand \index{ANSI-compliance}
712
713 \end_inset 
714
715  (see section 
716 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
717
718 \end_inset 
719
720  for ANSI-Compliance).
721  
722 \newline 
723
724 \layout Itemize
725
726 short is now equivalent to int (16 bits), it used to be equivalent to char
727  (8 bits) which is not ANSI compliant.
728 \layout Itemize
729
730 the default directory for gcc-builds where include, library and documentation
731  files are stored is now in /usr/local/share.
732 \layout Itemize
733
734 char type parameters to vararg
735 \begin_inset LatexCommand \index{vararg, va\_arg}
736
737 \end_inset 
738
739  functions are casted to int unless explicitly casted
740 \begin_inset Marginal
741 collapsed true
742
743 \layout Standard
744
745
746 \series bold 
747 \SpecialChar ~
748 !
749 \end_inset 
750
751 , e.g.: 
752 \newline 
753
754 \family typewriter 
755 \SpecialChar ~
756 \SpecialChar ~
757 char a=3;
758 \newline 
759 \SpecialChar ~
760 \SpecialChar ~
761 printf ("%d %c
762 \backslash 
763 n", a, (char)a);
764 \family default 
765
766 \newline 
767  will push a as an int and as a char resp.
768 \layout Itemize
769
770 option -
771 \begin_inset ERT
772 status Collapsed
773
774 \layout Standard
775
776 \backslash 
777 /
778 \end_inset 
779
780 -regextend has been removed.
781 \layout Itemize
782
783 option -
784 \begin_inset ERT
785 status Collapsed
786
787 \layout Standard
788
789 \backslash 
790 /
791 \end_inset 
792
793 -noregparms has been removed.
794 \layout Itemize
795
796 option -
797 \begin_inset ERT
798 status Collapsed
799
800 \layout Standard
801
802 \backslash 
803 /
804 \end_inset 
805
806 -stack-after-data has been removed.
807 \layout Itemize
808
809 bit
810 \begin_inset LatexCommand \index{bit}
811
812 \end_inset 
813
814  and sbit
815 \begin_inset LatexCommand \index{sbit}
816
817 \end_inset 
818
819
820 \begin_inset LatexCommand \index{\_\_sbit}
821
822 \end_inset 
823
824  types now consistently behave like the C99 _Bool type with respect to type
825  conversion
826 \begin_inset LatexCommand \index{type conversion}
827
828 \end_inset 
829
830
831 \begin_inset LatexCommand \index{type promotion}
832
833 \end_inset 
834
835 .
836  The most common incompatibility resulting from this change is related to
837  bit toggling
838 \begin_inset LatexCommand \index{Bit toggling}
839
840 \end_inset 
841
842  idioms, e.g.:
843 \newline 
844
845 \family typewriter 
846 \SpecialChar ~
847 \SpecialChar ~
848 bit b;
849 \newline 
850 \SpecialChar ~
851 \SpecialChar ~
852 b = ~
853 \begin_inset LatexCommand \index{\~\/ Operator}
854
855 \end_inset 
856
857 b; /* equivalent to b=1 instead of toggling b */
858 \begin_inset Marginal
859 collapsed true
860
861 \layout Standard
862
863
864 \series bold 
865 \SpecialChar ~
866 !
867 \end_inset 
868
869
870 \newline 
871 \SpecialChar ~
872 \SpecialChar ~
873 b = !b; /* toggles b */
874 \newline 
875
876 \family default 
877 In previous versions, both forms would have toggled the bit.
878 \layout Standard
879
880
881 \emph on 
882 <pending: more incompatibilities?>
883 \layout Section
884
885 System Requirements
886 \layout Standard
887
888 What do you need before you start installation of SDCC? A computer, and
889  a desire to compute.
890  The preferred method of installation is to compile SDCC from source using
891  GNU gcc and make.
892  For Windows some pre-compiled binary distributions are available for your
893  convenience.
894  You should have some experience with command line tools and compiler use.
895 \layout Section
896
897 Other Resources
898 \layout Standard
899
900 The SDCC home page at 
901 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
902
903 \end_inset 
904
905  is a great place to find distribution sets.
906  You can also find links to the user mailing lists that offer help or discuss
907  SDCC with other SDCC users.
908  Web links to other SDCC related sites can also be found here.
909  This document can be found in the DOC directory of the source package as
910  a text or HTML file.
911  A pdf version of this document is available at 
912 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
913
914 \end_inset 
915
916 .
917  Some of the other tools (simulator and assembler) included with SDCC contain
918  their own documentation and can be found in the source distribution.
919  If you want the latest unreleased software, the complete source package
920  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
921 /trunk/sdcc.
922 \layout Section
923
924 Wishes for the future
925 \layout Standard
926
927 There are (and always will be) some things that could be done.
928  Here are some I can think of:
929 \newline 
930
931 \layout Standard
932
933
934 \family typewriter 
935 char KernelFunction3(char p) at 0x340;
936 \newline 
937
938 \layout Standard
939
940
941 \family typewriter 
942 better code banking
943 \begin_inset LatexCommand \index{code banking (limited support)}
944
945 \end_inset 
946
947  support for mcs51
948 \newline 
949
950 \newline 
951
952 \family default 
953 If you can think of some more, please see the section 
954 \begin_inset LatexCommand \ref{sub:Requesting-Features}
955
956 \end_inset 
957
958  about filing feature requests
959 \begin_inset LatexCommand \index{Requesting features}
960
961 \end_inset 
962
963
964 \begin_inset LatexCommand \index{Feature request}
965
966 \end_inset 
967
968 .
969 \newline 
970
971 \layout Chapter
972
973 Installing SDCC
974 \begin_inset LatexCommand \index{Installation}
975
976 \end_inset 
977
978
979 \layout Standard
980
981 For most users it is sufficient to skip to either section 
982 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
983
984 \end_inset 
985
986  (Unix) or section 
987 \begin_inset LatexCommand \ref{sub:Windows-Install}
988
989 \end_inset 
990
991  (Windows).
992  More detailed instructions follow below.
993 \layout Section
994
995 Configure Options
996 \begin_inset LatexCommand \index{Options SDCC configuration}
997
998 \end_inset 
999
1000
1001 \layout Standard
1002
1003 The install paths, search paths and other options are defined when running
1004  'configure'.
1005  The defaults can be overridden by:
1006 \layout List
1007 \labelwidthstring 00.00.0000
1008
1009 -
1010 \begin_inset ERT
1011 status Collapsed
1012
1013 \layout Standard
1014
1015 \backslash 
1016 /
1017 \end_inset 
1018
1019 -prefix see table below
1020 \layout List
1021 \labelwidthstring 00.00.0000
1022
1023 -
1024 \begin_inset ERT
1025 status Collapsed
1026
1027 \layout Standard
1028
1029 \backslash 
1030 /
1031 \end_inset 
1032
1033 -exec_prefix see table below
1034 \layout List
1035 \labelwidthstring 00.00.0000
1036
1037 -
1038 \begin_inset ERT
1039 status Collapsed
1040
1041 \layout Standard
1042
1043 \backslash 
1044 /
1045 \end_inset 
1046
1047 -bindir see table below
1048 \layout List
1049 \labelwidthstring 00.00.0000
1050
1051 -
1052 \begin_inset ERT
1053 status Collapsed
1054
1055 \layout Standard
1056
1057 \backslash 
1058 /
1059 \end_inset 
1060
1061 -datadir see table below
1062 \layout List
1063 \labelwidthstring 00.00.0000
1064
1065 -
1066 \begin_inset ERT
1067 status Collapsed
1068
1069 \layout Standard
1070
1071 \backslash 
1072 /
1073 \end_inset 
1074
1075 -datarootdir see table below
1076 \newline 
1077
1078 \layout List
1079 \labelwidthstring 00.00.0000
1080
1081 \SpecialChar ~
1082 \SpecialChar ~
1083 docdir environment variable, see table below
1084 \layout List
1085 \labelwidthstring 00.00.0000
1086
1087 \SpecialChar ~
1088 \SpecialChar ~
1089 include_dir_suffix environment variable, see table below
1090 \layout List
1091 \labelwidthstring 00.00.0000
1092
1093 \SpecialChar ~
1094 \SpecialChar ~
1095 lib_dir_suffix environment variable, see table below
1096 \layout List
1097 \labelwidthstring 00.00.0000
1098
1099 \SpecialChar ~
1100 \SpecialChar ~
1101 sdccconf_h_dir_separator environment variable, either / or 
1102 \backslash 
1103
1104 \backslash 
1105  makes sense here.
1106  This character will only be used in sdccconf.h; don't forget it's a C-header,
1107  therefore a double-backslash is needed there.
1108 \newline 
1109
1110 \layout List
1111 \labelwidthstring 00.00.0000
1112
1113 -
1114 \begin_inset ERT
1115 status Collapsed
1116
1117 \layout Standard
1118
1119 \backslash 
1120 /
1121 \end_inset 
1122
1123 -disable-mcs51-port Excludes the Intel mcs51 port
1124 \layout List
1125 \labelwidthstring 00.00.0000
1126
1127 -
1128 \begin_inset ERT
1129 status Collapsed
1130
1131 \layout Standard
1132
1133 \backslash 
1134 /
1135 \end_inset 
1136
1137 -disable-gbz80-port Excludes the Gameboy gbz80 port
1138 \layout List
1139 \labelwidthstring 00.00.0000
1140
1141 -
1142 \begin_inset ERT
1143 status Collapsed
1144
1145 \layout Standard
1146
1147 \backslash 
1148 /
1149 \end_inset 
1150
1151 -disable-z80-port Excludes the z80 port
1152 \layout List
1153 \labelwidthstring 00.00.0000
1154
1155 -
1156 \begin_inset ERT
1157 status Collapsed
1158
1159 \layout Standard
1160
1161 \backslash 
1162 /
1163 \end_inset 
1164
1165 -disable-avr-port Excludes the AVR port
1166 \layout List
1167 \labelwidthstring 00.00.0000
1168
1169 -
1170 \begin_inset ERT
1171 status Collapsed
1172
1173 \layout Standard
1174
1175 \backslash 
1176 /
1177 \end_inset 
1178
1179 -disable-ds390-port Excludes the DS390 port
1180 \layout List
1181 \labelwidthstring 00.00.0000
1182
1183 -
1184 \begin_inset ERT
1185 status Collapsed
1186
1187 \layout Standard
1188
1189 \backslash 
1190 /
1191 \end_inset 
1192
1193 -disable-hc08-port Excludes the HC08 port
1194 \layout List
1195 \labelwidthstring 00.00.0000
1196
1197 -
1198 \begin_inset ERT
1199 status Collapsed
1200
1201 \layout Standard
1202
1203 \backslash 
1204 /
1205 \end_inset 
1206
1207 -disable-pic-port Excludes the PIC port
1208 \layout List
1209 \labelwidthstring 00.00.0000
1210
1211 -
1212 \begin_inset ERT
1213 status Collapsed
1214
1215 \layout Standard
1216
1217 \backslash 
1218 /
1219 \end_inset 
1220
1221 -disable-xa51-port Excludes the XA51 port
1222 \layout List
1223 \labelwidthstring 00.00.0000
1224
1225 -
1226 \begin_inset ERT
1227 status Collapsed
1228
1229 \layout Standard
1230
1231 \backslash 
1232 /
1233 \end_inset 
1234
1235 -disable-ucsim Disables configuring and building of ucsim
1236 \layout List
1237 \labelwidthstring 00.00.0000
1238
1239 -
1240 \begin_inset ERT
1241 status Collapsed
1242
1243 \layout Standard
1244
1245 \backslash 
1246 /
1247 \end_inset 
1248
1249 -disable-device-lib Disables automatically building device libraries
1250 \layout List
1251 \labelwidthstring 00.00.0000
1252
1253 -
1254 \begin_inset ERT
1255 status Collapsed
1256
1257 \layout Standard
1258
1259 \backslash 
1260 /
1261 \end_inset 
1262
1263 -disable-packihx Disables building packihx
1264 \newline 
1265
1266 \layout List
1267 \labelwidthstring 00.00.0000
1268
1269 -
1270 \begin_inset ERT
1271 status Collapsed
1272
1273 \layout Standard
1274
1275 \backslash 
1276 /
1277 \end_inset 
1278
1279 -enable-doc Build pdf, html and txt files from the lyx sources
1280 \layout List
1281 \labelwidthstring 00.00.0000
1282
1283 -
1284 \begin_inset ERT
1285 status Collapsed
1286
1287 \layout Standard
1288
1289 \backslash 
1290 /
1291 \end_inset 
1292
1293 -enable-libgc Use the Bohem memory allocator.
1294  Lower runtime footprint.
1295 \layout Standard
1296
1297 Furthermore the environment variables CC, CFLAGS, ...
1298  the tools and their arguments can be influenced.
1299  Please see `configure -
1300 \begin_inset ERT
1301 status Collapsed
1302
1303 \layout Standard
1304
1305 \backslash 
1306 /
1307 \end_inset 
1308
1309 -help` and the man/info pages of `configure` for details.
1310 \newline 
1311
1312 \newline 
1313 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1314  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1315 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1316  At the moment it's not possible to change the default settings (it was
1317  simply never required).
1318 \newline 
1319
1320 \newline 
1321 These configure options are compiled into the binaries, and can only be
1322  changed by rerunning 'configure' and recompiling SDCC.
1323  The configure options are written in 
1324 \emph on 
1325 italics
1326 \emph default 
1327  to distinguish them from run time environment variables (see section search
1328  paths).
1329 \newline 
1330
1331 \newline 
1332 The settings for 
1333 \begin_inset Quotes sld
1334 \end_inset 
1335
1336 Win32 builds
1337 \begin_inset Quotes srd
1338 \end_inset 
1339
1340  are used by the SDCC team to build the official Win32 binaries.
1341  The SDCC team uses Mingw32 to build the official Windows binaries, because
1342  it's
1343 \layout Enumerate
1344
1345 open source, 
1346 \layout Enumerate
1347
1348 a gcc compiler and last but not least
1349 \layout Enumerate
1350
1351 the binaries can be built by cross compiling on Sourceforge's compile farm.
1352 \layout Standard
1353
1354 See the examples, how to pass the Win32 settings to 'configure'.
1355  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1356  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1357  for Win32.
1358 \newline 
1359
1360 \newline 
1361 These defaults are:
1362 \newline 
1363
1364 \layout Standard
1365 \align center 
1366
1367 \begin_inset  Tabular
1368 <lyxtabular version="3" rows="9" columns="3">
1369 <features>
1370 <column alignment="block" valignment="top" leftline="true" width="0in">
1371 <column alignment="block" valignment="top" leftline="true" width="0in">
1372 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1373 <row topline="true" bottomline="true">
1374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1375 \begin_inset Text
1376
1377 \layout Standard
1378
1379 Variable
1380 \end_inset 
1381 </cell>
1382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1383 \begin_inset Text
1384
1385 \layout Standard
1386
1387 default
1388 \end_inset 
1389 </cell>
1390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1391 \begin_inset Text
1392
1393 \layout Standard
1394
1395 Win32 builds
1396 \end_inset 
1397 </cell>
1398 </row>
1399 <row topline="true">
1400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1401 \begin_inset Text
1402
1403 \layout Standard
1404
1405
1406 \emph on 
1407 PREFIX
1408 \end_inset 
1409 </cell>
1410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1411 \begin_inset Text
1412
1413 \layout Standard
1414
1415 /usr/local
1416 \end_inset 
1417 </cell>
1418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1419 \begin_inset Text
1420
1421 \layout Standard
1422
1423
1424 \backslash 
1425 sdcc
1426 \end_inset 
1427 </cell>
1428 </row>
1429 <row topline="true">
1430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1431 \begin_inset Text
1432
1433 \layout Standard
1434
1435
1436 \emph on 
1437 EXEC_PREFIX
1438 \end_inset 
1439 </cell>
1440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1441 \begin_inset Text
1442
1443 \layout Standard
1444
1445
1446 \emph on 
1447 $PREFIX
1448 \end_inset 
1449 </cell>
1450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1451 \begin_inset Text
1452
1453 \layout Standard
1454
1455
1456 \emph on 
1457 $PREFIX
1458 \end_inset 
1459 </cell>
1460 </row>
1461 <row topline="true">
1462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1463 \begin_inset Text
1464
1465 \layout Standard
1466
1467
1468 \emph on 
1469 BINDIR
1470 \end_inset 
1471 </cell>
1472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1473 \begin_inset Text
1474
1475 \layout Standard
1476
1477
1478 \emph on 
1479 $EXEC_PREFIX
1480 \emph default 
1481 /bin
1482 \end_inset 
1483 </cell>
1484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1485 \begin_inset Text
1486
1487 \layout Standard
1488
1489
1490 \emph on 
1491 $EXEC_PREFIX
1492 \emph default 
1493
1494 \backslash 
1495 bin
1496 \end_inset 
1497 </cell>
1498 </row>
1499 <row topline="true">
1500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1501 \begin_inset Text
1502
1503 \layout Standard
1504
1505
1506 \emph on 
1507 DATADIR
1508 \end_inset 
1509 </cell>
1510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1511 \begin_inset Text
1512
1513 \layout Standard
1514
1515
1516 \emph on 
1517 $DATAROOTDIR
1518 \end_inset 
1519 </cell>
1520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1521 \begin_inset Text
1522
1523 \layout Standard
1524
1525
1526 \emph on 
1527 $DATAROOTDIR
1528 \end_inset 
1529 </cell>
1530 </row>
1531 <row topline="true">
1532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1533 \begin_inset Text
1534
1535 \layout Standard
1536
1537
1538 \emph on 
1539 DATAROOTDIR
1540 \end_inset 
1541 </cell>
1542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1543 \begin_inset Text
1544
1545 \layout Standard
1546
1547
1548 \emph on 
1549 $PREFIX
1550 \emph default 
1551 /share
1552 \end_inset 
1553 </cell>
1554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1555 \begin_inset Text
1556
1557 \layout Standard
1558
1559
1560 \emph on 
1561 $PREFIX
1562 \end_inset 
1563 </cell>
1564 </row>
1565 <row topline="true">
1566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1567 \begin_inset Text
1568
1569 \layout Standard
1570
1571
1572 \emph on 
1573 DOCDIR
1574 \end_inset 
1575 </cell>
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1577 \begin_inset Text
1578
1579 \layout Standard
1580
1581
1582 \emph on 
1583 $DATAROOTDIR
1584 \emph default 
1585 /sdcc/doc
1586 \end_inset 
1587 </cell>
1588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1589 \begin_inset Text
1590
1591 \layout Standard
1592
1593
1594 \emph on 
1595 $DATAROOTDIR
1596 \emph default 
1597
1598 \backslash 
1599 doc
1600 \end_inset 
1601 </cell>
1602 </row>
1603 <row topline="true">
1604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1605 \begin_inset Text
1606
1607 \layout Standard
1608
1609
1610 \emph on 
1611 INCLUDE_DIR_SUFFIX
1612 \end_inset 
1613 </cell>
1614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1615 \begin_inset Text
1616
1617 \layout Standard
1618
1619 sdcc/include
1620 \end_inset 
1621 </cell>
1622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1623 \begin_inset Text
1624
1625 \layout Standard
1626
1627 include
1628 \end_inset 
1629 </cell>
1630 </row>
1631 <row topline="true" bottomline="true">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1633 \begin_inset Text
1634
1635 \layout Standard
1636
1637
1638 \emph on 
1639 LIB_DIR_SUFFIX
1640 \end_inset 
1641 </cell>
1642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1643 \begin_inset Text
1644
1645 \layout Standard
1646
1647 sdcc/lib
1648 \end_inset 
1649 </cell>
1650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1651 \begin_inset Text
1652
1653 \layout Standard
1654
1655 lib
1656 \end_inset 
1657 </cell>
1658 </row>
1659 </lyxtabular>
1660
1661 \end_inset 
1662
1663
1664 \newline 
1665
1666 \layout Standard
1667 \noindent 
1668 'configure' also computes relative paths.
1669  This is needed for full relocatability of a binary package and to complete
1670  search paths (see section search paths below):
1671 \newline 
1672  
1673 \layout Standard
1674 \align center 
1675
1676 \begin_inset  Tabular
1677 <lyxtabular version="3" rows="4" columns="3">
1678 <features>
1679 <column alignment="block" valignment="top" leftline="true" width="0in">
1680 <column alignment="block" valignment="top" leftline="true" width="0in">
1681 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1682 <row topline="true" bottomline="true">
1683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1684 \begin_inset Text
1685
1686 \layout Standard
1687
1688 Variable (computed)
1689 \end_inset 
1690 </cell>
1691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1692 \begin_inset Text
1693
1694 \layout Standard
1695
1696 default
1697 \end_inset 
1698 </cell>
1699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1700 \begin_inset Text
1701
1702 \layout Standard
1703
1704 Win32 builds
1705 \end_inset 
1706 </cell>
1707 </row>
1708 <row topline="true" bottomline="true">
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1710 \begin_inset Text
1711
1712 \layout Standard
1713
1714
1715 \emph on 
1716 BIN2DATA_DIR
1717 \end_inset 
1718 </cell>
1719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1720 \begin_inset Text
1721
1722 \layout Standard
1723
1724 ../share
1725 \end_inset 
1726 </cell>
1727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1728 \begin_inset Text
1729
1730 \layout Standard
1731
1732 ..
1733 \end_inset 
1734 </cell>
1735 </row>
1736 <row bottomline="true">
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1738 \begin_inset Text
1739
1740 \layout Standard
1741
1742
1743 \emph on 
1744 PREFIX2BIN_DIR
1745 \end_inset 
1746 </cell>
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1748 \begin_inset Text
1749
1750 \layout Standard
1751
1752 bin
1753 \end_inset 
1754 </cell>
1755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1756 \begin_inset Text
1757
1758 \layout Standard
1759
1760 bin
1761 \end_inset 
1762 </cell>
1763 </row>
1764 <row bottomline="true">
1765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1766 \begin_inset Text
1767
1768 \layout Standard
1769
1770
1771 \emph on 
1772 PREFIX2DATA_DIR
1773 \end_inset 
1774 </cell>
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1776 \begin_inset Text
1777
1778 \layout Standard
1779
1780 share/sdcc
1781 \end_inset 
1782 </cell>
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1784 \begin_inset Text
1785
1786 \layout Standard
1787
1788 \end_inset 
1789 </cell>
1790 </row>
1791 </lyxtabular>
1792
1793 \end_inset 
1794
1795
1796 \newline 
1797
1798 \layout Standard
1799 \noindent 
1800 Examples:
1801 \layout LyX-Code
1802
1803 ./configure
1804 \newline 
1805 ./configure -
1806 \begin_inset ERT
1807 status Collapsed
1808
1809 \layout Standard
1810
1811 \backslash 
1812 /
1813 \end_inset 
1814
1815 -prefix=
1816 \begin_inset Quotes srd
1817 \end_inset 
1818
1819 /usr/bin
1820 \begin_inset Quotes srd
1821 \end_inset 
1822
1823  -
1824 \begin_inset ERT
1825 status Collapsed
1826
1827 \layout Standard
1828
1829 \backslash 
1830 /
1831 \end_inset 
1832
1833 -datarootdir=
1834 \begin_inset Quotes srd
1835 \end_inset 
1836
1837 /usr/share
1838 \begin_inset Quotes srd
1839 \end_inset 
1840
1841
1842 \newline 
1843 ./configure -
1844 \begin_inset ERT
1845 status Collapsed
1846
1847 \layout Standard
1848
1849 \backslash 
1850 /
1851 \end_inset 
1852
1853 -disable-avr-port -
1854 \begin_inset ERT
1855 status Collapsed
1856
1857 \layout Standard
1858
1859 \backslash 
1860 /
1861 \end_inset 
1862
1863 -disable-xa51-port
1864 \layout Standard
1865
1866 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1867 32'):
1868 \layout LyX-Code
1869
1870 ./configure 
1871 \backslash 
1872
1873 \newline 
1874 CC=
1875 \begin_inset Quotes srd
1876 \end_inset 
1877
1878 i586-mingw32msvc-gcc
1879 \begin_inset Quotes srd
1880 \end_inset 
1881
1882  CXX=
1883 \begin_inset Quotes srd
1884 \end_inset 
1885
1886 i586-mingw32msvc-g++
1887 \begin_inset Quotes srd
1888 \end_inset 
1889
1890  
1891 \backslash 
1892  
1893 \newline 
1894 RANLIB=
1895 \begin_inset Quotes srd
1896 \end_inset 
1897
1898 i586-mingw32msvc-ranlib
1899 \begin_inset Quotes srd
1900 \end_inset 
1901
1902  
1903 \backslash 
1904
1905 \newline 
1906 STRIP=
1907 \begin_inset Quotes srd
1908 \end_inset 
1909
1910 i586-mingw32msvc-strip
1911 \begin_inset Quotes srd
1912 \end_inset 
1913
1914  
1915 \backslash 
1916
1917 \newline 
1918 -
1919 \begin_inset ERT
1920 status Collapsed
1921
1922 \layout Standard
1923
1924 \backslash 
1925 /
1926 \end_inset 
1927
1928 -prefix=
1929 \begin_inset Quotes srd
1930 \end_inset 
1931
1932 /sdcc
1933 \begin_inset Quotes srd
1934 \end_inset 
1935
1936  
1937 \backslash 
1938
1939 \newline 
1940 -
1941 \begin_inset ERT
1942 status Collapsed
1943
1944 \layout Standard
1945
1946 \backslash 
1947 /
1948 \end_inset 
1949
1950 -datarootdir=
1951 \begin_inset Quotes srd
1952 \end_inset 
1953
1954 /sdcc
1955 \begin_inset Quotes srd
1956 \end_inset 
1957
1958  
1959 \backslash 
1960
1961 \newline 
1962 docdir=
1963 \begin_inset Quotes srd
1964 \end_inset 
1965
1966
1967 \backslash 
1968 ${datarootdir}/doc
1969 \begin_inset Quotes srd
1970 \end_inset 
1971
1972  
1973 \backslash 
1974
1975 \newline 
1976 include_dir_suffix=
1977 \begin_inset Quotes srd
1978 \end_inset 
1979
1980 include
1981 \begin_inset Quotes srd
1982 \end_inset 
1983
1984  
1985 \backslash 
1986
1987 \newline 
1988 lib_dir_suffix=
1989 \begin_inset Quotes srd
1990 \end_inset 
1991
1992 lib
1993 \begin_inset Quotes srd
1994 \end_inset 
1995
1996  
1997 \backslash 
1998
1999 \newline 
2000 sdccconf_h_dir_separator=
2001 \begin_inset Quotes srd
2002 \end_inset 
2003
2004
2005 \backslash 
2006
2007 \backslash 
2008
2009 \backslash 
2010
2011 \backslash 
2012
2013 \begin_inset Quotes srd
2014 \end_inset 
2015
2016  
2017 \backslash 
2018
2019 \newline 
2020 -
2021 \begin_inset ERT
2022 status Collapsed
2023
2024 \layout Standard
2025
2026 \backslash 
2027 /
2028 \end_inset 
2029
2030 -disable-device-lib
2031 \backslash 
2032
2033 \newline 
2034 -
2035 \begin_inset ERT
2036 status Collapsed
2037
2038 \layout Standard
2039
2040 \backslash 
2041 /
2042 \end_inset 
2043
2044 -host=i586-mingw32msvc
2045 \backslash 
2046
2047 \newline 
2048 -
2049 \begin_inset ERT
2050 status Collapsed
2051
2052 \layout Standard
2053
2054 \backslash 
2055 /
2056 \end_inset 
2057
2058 -build=unknown-unknown-linux-gnu
2059 \layout Standard
2060
2061 To 
2062 \begin_inset Quotes sld
2063 \end_inset 
2064
2065 cross
2066 \begin_inset Quotes srd
2067 \end_inset 
2068
2069 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2070 ):
2071 \layout LyX-Code
2072
2073 ./configure -C 
2074 \backslash 
2075
2076 \newline 
2077 -
2078 \begin_inset ERT
2079 status Collapsed
2080
2081 \layout Standard
2082
2083 \backslash 
2084 /
2085 \end_inset 
2086
2087 -prefix=
2088 \begin_inset Quotes srd
2089 \end_inset 
2090
2091 /sdcc
2092 \begin_inset Quotes srd
2093 \end_inset 
2094
2095  
2096 \backslash 
2097
2098 \newline 
2099 -
2100 \begin_inset ERT
2101 status Collapsed
2102
2103 \layout Standard
2104
2105 \backslash 
2106 /
2107 \end_inset 
2108
2109 -datarootdir=
2110 \begin_inset Quotes srd
2111 \end_inset 
2112
2113 /sdcc
2114 \begin_inset Quotes srd
2115 \end_inset 
2116
2117  
2118 \backslash 
2119
2120 \newline 
2121 docdir=
2122 \begin_inset Quotes srd
2123 \end_inset 
2124
2125
2126 \backslash 
2127 ${datarootdir}/doc
2128 \begin_inset Quotes srd
2129 \end_inset 
2130
2131  
2132 \backslash 
2133  
2134 \newline 
2135 include_dir_suffix=
2136 \begin_inset Quotes srd
2137 \end_inset 
2138
2139 include
2140 \begin_inset Quotes srd
2141 \end_inset 
2142
2143  
2144 \backslash 
2145
2146 \newline 
2147 lib_dir_suffix=
2148 \begin_inset Quotes srd
2149 \end_inset 
2150
2151 lib
2152 \begin_inset Quotes srd
2153 \end_inset 
2154
2155  
2156 \backslash 
2157
2158 \newline 
2159 sdccconf_h_dir_separator=
2160 \begin_inset Quotes srd
2161 \end_inset 
2162
2163
2164 \backslash 
2165
2166 \backslash 
2167
2168 \backslash 
2169
2170 \backslash 
2171
2172 \begin_inset Quotes srd
2173 \end_inset 
2174
2175  
2176 \backslash 
2177
2178 \newline 
2179 CC=
2180 \begin_inset Quotes srd
2181 \end_inset 
2182
2183 gcc -mno-cygwin
2184 \begin_inset Quotes srd
2185 \end_inset 
2186
2187  
2188 \backslash 
2189
2190 \newline 
2191 CXX=
2192 \begin_inset Quotes srd
2193 \end_inset 
2194
2195 g++ -mno-cygwin
2196 \begin_inset Quotes srd
2197 \end_inset 
2198
2199  
2200 \layout Standard
2201
2202 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2203  The option '-
2204 \begin_inset ERT
2205 status Collapsed
2206
2207 \layout Standard
2208
2209 \backslash 
2210 /
2211 \end_inset 
2212
2213 -C' turns on caching, which gives a little bit extra speed.
2214  However if options are changed, it can be necessary to delete the config.cache
2215  file.
2216 \layout Section
2217
2218 Install paths
2219 \begin_inset LatexCommand \label{sub:Install-paths}
2220
2221 \end_inset 
2222
2223
2224 \begin_inset LatexCommand \index{Install paths}
2225
2226 \end_inset 
2227
2228
2229 \layout Standard
2230 \added_space_top medskip \align center 
2231
2232 \begin_inset  Tabular
2233 <lyxtabular version="3" rows="5" columns="4">
2234 <features>
2235 <column alignment="left" valignment="top" leftline="true" width="0">
2236 <column alignment="left" valignment="top" leftline="true" width="0">
2237 <column alignment="left" valignment="top" leftline="true" width="0">
2238 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2239 <row topline="true" bottomline="true">
2240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2241 \begin_inset Text
2242
2243 \layout Standard
2244
2245
2246 \series bold 
2247 Description
2248 \end_inset 
2249 </cell>
2250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2251 \begin_inset Text
2252
2253 \layout Standard
2254
2255
2256 \series bold 
2257 Path
2258 \end_inset 
2259 </cell>
2260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2261 \begin_inset Text
2262
2263 \layout Standard
2264
2265
2266 \series bold 
2267 Default
2268 \end_inset 
2269 </cell>
2270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2271 \begin_inset Text
2272
2273 \layout Standard
2274
2275
2276 \series bold 
2277 Win32 builds
2278 \end_inset 
2279 </cell>
2280 </row>
2281 <row topline="true">
2282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2283 \begin_inset Text
2284
2285 \layout Standard
2286
2287 Binary files*
2288 \end_inset 
2289 </cell>
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_inset Text
2292
2293 \layout Standard
2294
2295
2296 \emph on 
2297 $EXEC_PREFIX
2298 \end_inset 
2299 </cell>
2300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2301 \begin_inset Text
2302
2303 \layout Standard
2304
2305 /usr/local/bin
2306 \end_inset 
2307 </cell>
2308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2309 \begin_inset Text
2310
2311 \layout Standard
2312
2313
2314 \backslash 
2315 sdcc
2316 \backslash 
2317 bin
2318 \end_inset 
2319 </cell>
2320 </row>
2321 <row topline="true">
2322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2323 \begin_inset Text
2324
2325 \layout Standard
2326
2327 Include files
2328 \end_inset 
2329 </cell>
2330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2331 \begin_inset Text
2332
2333 \layout Standard
2334
2335
2336 \emph on 
2337 $DATADIR/ $INCLUDE_DIR_SUFFIX
2338 \end_inset 
2339 </cell>
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2341 \begin_inset Text
2342
2343 \layout Standard
2344
2345 /usr/local/share/sdcc/include
2346 \end_inset 
2347 </cell>
2348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2349 \begin_inset Text
2350
2351 \layout Standard
2352
2353
2354 \backslash 
2355 sdcc
2356 \backslash 
2357 include
2358 \end_inset 
2359 </cell>
2360 </row>
2361 <row topline="true">
2362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2363 \begin_inset Text
2364
2365 \layout Standard
2366
2367 Library file**
2368 \end_inset 
2369 </cell>
2370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2371 \begin_inset Text
2372
2373 \layout Standard
2374
2375
2376 \emph on 
2377 $DATADIR/$LIB_DIR_SUFFIX
2378 \end_inset 
2379 </cell>
2380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2381 \begin_inset Text
2382
2383 \layout Standard
2384
2385 /usr/local/share/sdcc/lib
2386 \end_inset 
2387 </cell>
2388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2389 \begin_inset Text
2390
2391 \layout Standard
2392
2393
2394 \backslash 
2395 sdcc
2396 \backslash 
2397 lib
2398 \end_inset 
2399 </cell>
2400 </row>
2401 <row topline="true" bottomline="true">
2402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2403 \begin_inset Text
2404
2405 \layout Standard
2406
2407 Documentation
2408 \end_inset 
2409 </cell>
2410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2411 \begin_inset Text
2412
2413 \layout Standard
2414
2415
2416 \emph on 
2417 $DOCDIR
2418 \end_inset 
2419 </cell>
2420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2421 \begin_inset Text
2422
2423 \layout Standard
2424
2425 /usr/local/share/sdcc/doc
2426 \end_inset 
2427 </cell>
2428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2429 \begin_inset Text
2430
2431 \layout Standard
2432
2433
2434 \backslash 
2435 sdcc
2436 \backslash 
2437 doc
2438 \end_inset 
2439 </cell>
2440 </row>
2441 </lyxtabular>
2442
2443 \end_inset 
2444
2445
2446 \layout Verse
2447
2448
2449 \size footnotesize 
2450 *compiler, preprocessor, assembler, and linker
2451 \newline 
2452 **the 
2453 \shape italic 
2454 model
2455 \shape default 
2456  is auto-appended by the compiler, e.g.
2457  small, large, z80, ds390 etc
2458 \layout Standard
2459 \noindent 
2460 The install paths can still be changed during `make install` with e.g.:
2461 \layout LyX-Code
2462
2463 make install prefix=$(HOME)/local/sdcc
2464 \layout Standard
2465
2466 Of course this doesn't change the search paths compiled into the binaries.
2467 \newline 
2468
2469 \newline 
2470 Moreover the install path can be changed by defining DESTDIR
2471 \begin_inset LatexCommand \index{DESTDIR}
2472
2473 \end_inset 
2474
2475 :
2476 \layout LyX-Code
2477
2478 make install DESTDIR=$(HOME)/sdcc.rpm/
2479 \layout Standard
2480
2481 Please note that DESTDIR must have a trailing slash!
2482 \layout Section
2483
2484 Search Paths
2485 \begin_inset LatexCommand \label{sub:Search-Paths}
2486
2487 \end_inset 
2488
2489
2490 \begin_inset LatexCommand \index{Search path}
2491
2492 \end_inset 
2493
2494
2495 \layout Standard
2496
2497 Some search paths or parts of them are determined by configure variables
2498  (in 
2499 \emph on 
2500 italics
2501 \emph default 
2502 , see section above).
2503  Further search paths are determined by environment variables during runtime.
2504  
2505 \newline 
2506 The paths searched when running the compiler are as follows (the first catch
2507  wins):
2508 \newline 
2509
2510 \newline 
2511 1.
2512  Binary files (preprocessor, assembler and linker)
2513 \newline 
2514
2515 \layout Standard
2516 \align center 
2517
2518 \begin_inset  Tabular
2519 <lyxtabular version="3" rows="4" columns="3">
2520 <features>
2521 <column alignment="block" valignment="top" leftline="true" width="0in">
2522 <column alignment="block" valignment="top" leftline="true" width="0in">
2523 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2524 <row topline="true" bottomline="true">
2525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2526 \begin_inset Text
2527
2528 \layout Standard
2529
2530 Search path
2531 \end_inset 
2532 </cell>
2533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2534 \begin_inset Text
2535
2536 \layout Standard
2537
2538 default
2539 \end_inset 
2540 </cell>
2541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2542 \begin_inset Text
2543
2544 \layout Standard
2545
2546 Win32 builds
2547 \end_inset 
2548 </cell>
2549 </row>
2550 <row topline="true">
2551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2552 \begin_inset Text
2553
2554 \layout Standard
2555
2556 $SDCC_HOME/
2557 \emph on 
2558 $PPREFIX2BIN_DIR
2559 \end_inset 
2560 </cell>
2561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2562 \begin_inset Text
2563
2564 \layout Standard
2565
2566 $SDCC_HOME/bin
2567 \end_inset 
2568 </cell>
2569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2570 \begin_inset Text
2571
2572 \layout Standard
2573
2574 $SDCC_HOME
2575 \backslash 
2576 bin
2577 \end_inset 
2578 </cell>
2579 </row>
2580 <row topline="true">
2581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2582 \begin_inset Text
2583
2584 \layout Standard
2585
2586 Path of argv[0] (if available)
2587 \end_inset 
2588 </cell>
2589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2590 \begin_inset Text
2591
2592 \layout Standard
2593
2594 Path of argv[0]
2595 \end_inset 
2596 </cell>
2597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2598 \begin_inset Text
2599
2600 \layout Standard
2601
2602 Path of argv[0]
2603 \end_inset 
2604 </cell>
2605 </row>
2606 <row topline="true" bottomline="true">
2607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2608 \begin_inset Text
2609
2610 \layout Standard
2611
2612 $PATH
2613 \end_inset 
2614 </cell>
2615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2616 \begin_inset Text
2617
2618 \layout Standard
2619
2620 $PATH
2621 \end_inset 
2622 </cell>
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2624 \begin_inset Text
2625
2626 \layout Standard
2627
2628 $PATH
2629 \end_inset 
2630 </cell>
2631 </row>
2632 </lyxtabular>
2633
2634 \end_inset 
2635
2636  
2637 \newline 
2638
2639 \layout Standard
2640 \noindent 
2641 2.
2642  Include files
2643 \newline 
2644
2645 \layout Standard
2646 \align center 
2647
2648 \begin_inset  Tabular
2649 <lyxtabular version="3" rows="6" columns="3">
2650 <features>
2651 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2652 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2653 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2654 <row topline="true" bottomline="true">
2655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2656 \begin_inset Text
2657
2658 \layout Standard
2659
2660 Search path
2661 \end_inset 
2662 </cell>
2663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2664 \begin_inset Text
2665
2666 \layout Standard
2667
2668 default
2669 \end_inset 
2670 </cell>
2671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2672 \begin_inset Text
2673
2674 \layout Standard
2675
2676 Win32 builds
2677 \end_inset 
2678 </cell>
2679 </row>
2680 <row topline="true">
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 \begin_inset Text
2683
2684 \layout Standard
2685
2686 -
2687 \begin_inset ERT
2688 status Collapsed
2689
2690 \layout Standard
2691
2692 \backslash 
2693 /
2694 \end_inset 
2695
2696 -I dir
2697 \end_inset 
2698 </cell>
2699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2700 \begin_inset Text
2701
2702 \layout Standard
2703
2704 -
2705 \begin_inset ERT
2706 status Collapsed
2707
2708 \layout Standard
2709
2710 \backslash 
2711 /
2712 \end_inset 
2713
2714 -I dir
2715 \end_inset 
2716 </cell>
2717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2718 \begin_inset Text
2719
2720 \layout Standard
2721
2722 -
2723 \begin_inset ERT
2724 status Collapsed
2725
2726 \layout Standard
2727
2728 \backslash 
2729 /
2730 \end_inset 
2731
2732 -I dir
2733 \end_inset 
2734 </cell>
2735 </row>
2736 <row topline="true">
2737 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_inset Text
2739
2740 \layout Standard
2741
2742 $SDCC_INCLUDE
2743 \end_inset 
2744 </cell>
2745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2746 \begin_inset Text
2747
2748 \layout Standard
2749
2750 $SDCC_INCLUDE
2751 \end_inset 
2752 </cell>
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2754 \begin_inset Text
2755
2756 \layout Standard
2757
2758 $SDCC_INCLUDE
2759 \end_inset 
2760 </cell>
2761 </row>
2762 <row topline="true">
2763 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2764 \begin_inset Text
2765
2766 \layout Standard
2767
2768 $SDCC_HOME/
2769 \newline 
2770
2771 \emph on 
2772 $PREFIX2DATA_DIR/
2773 \newline 
2774 $INCLUDE_DIR_SUFFIX
2775 \end_inset 
2776 </cell>
2777 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2778 \begin_inset Text
2779
2780 \layout Standard
2781
2782 $SDCC_ HOME/
2783 \newline 
2784 share/sdcc/
2785 \newline 
2786 include
2787 \end_inset 
2788 </cell>
2789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2790 \begin_inset Text
2791
2792 \layout Standard
2793
2794 $SDCC_HOME
2795 \backslash 
2796 include
2797 \end_inset 
2798 </cell>
2799 </row>
2800 <row topline="true">
2801 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_inset Text
2803
2804 \layout Standard
2805
2806 path(argv[0])/
2807 \newline 
2808
2809 \emph on 
2810 $BIN2DATADIR/
2811 \emph default 
2812
2813 \newline 
2814
2815 \emph on 
2816 $INCLUDE_DIR_SUFFIX
2817 \end_inset 
2818 </cell>
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2820 \begin_inset Text
2821
2822 \layout Standard
2823
2824 path(argv[0])/
2825 \newline 
2826 ../sdcc/include
2827 \newline 
2828 \SpecialChar ~
2829 \SpecialChar ~
2830 \SpecialChar ~
2831 \SpecialChar ~
2832 \SpecialChar ~
2833 \SpecialChar ~
2834 \SpecialChar ~
2835 \SpecialChar ~
2836 \SpecialChar ~
2837 \SpecialChar ~
2838 \SpecialChar ~
2839 \SpecialChar ~
2840 \SpecialChar ~
2841 \SpecialChar ~
2842 \SpecialChar ~
2843 \SpecialChar ~
2844 \SpecialChar ~
2845 \SpecialChar ~
2846 \SpecialChar ~
2847 \SpecialChar ~
2848 \SpecialChar ~
2849 \SpecialChar ~
2850 \SpecialChar ~
2851 \SpecialChar ~
2852 \SpecialChar ~
2853 \SpecialChar ~
2854 \SpecialChar ~
2855 \SpecialChar ~
2856 \SpecialChar ~
2857 \SpecialChar ~
2858 \SpecialChar ~
2859 \SpecialChar ~
2860 \SpecialChar ~
2861 \SpecialChar ~
2862 \SpecialChar ~
2863 \SpecialChar ~
2864 \SpecialChar ~
2865 \SpecialChar ~
2866
2867 \end_inset 
2868 </cell>
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2870 \begin_inset Text
2871
2872 \layout Standard
2873
2874 path(argv[0])
2875 \backslash 
2876 ..
2877 \backslash 
2878 include
2879 \end_inset 
2880 </cell>
2881 </row>
2882 <row topline="true" bottomline="true">
2883 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2884 \begin_inset Text
2885
2886 \layout Standard
2887
2888
2889 \emph on 
2890 $DATADIR/
2891 \emph default 
2892
2893 \newline 
2894
2895 \emph on 
2896 $INCLUDE_DIR_SUFFIX
2897 \end_inset 
2898 </cell>
2899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2900 \begin_inset Text
2901
2902 \layout Standard
2903
2904 /usr/local/share/sdcc/
2905 \newline 
2906 include
2907 \end_inset 
2908 </cell>
2909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2910 \begin_inset Text
2911
2912 \layout Standard
2913
2914 (not on Win32)
2915 \end_inset 
2916 </cell>
2917 </row>
2918 </lyxtabular>
2919
2920 \end_inset 
2921
2922  
2923 \newline 
2924
2925 \layout Standard
2926 \noindent 
2927 The option -
2928 \begin_inset ERT
2929 status Collapsed
2930
2931 \layout Standard
2932
2933 \backslash 
2934 /
2935 \end_inset 
2936
2937 -nostdinc disables the last two search paths.
2938 \newline 
2939
2940 \newline 
2941 3.
2942  Library files 
2943 \newline 
2944
2945 \layout Standard
2946
2947 With the exception of 
2948 \begin_inset Quotes sld
2949 \end_inset 
2950
2951 -
2952 \begin_inset ERT
2953 status Collapsed
2954
2955 \layout Standard
2956
2957 \backslash 
2958 /
2959 \end_inset 
2960
2961 -L dir
2962 \begin_inset Quotes srd
2963 \end_inset 
2964
2965  the 
2966 \shape italic 
2967 model
2968 \shape default 
2969  is auto-appended by the compiler (e.g.
2970  small, large, z80, ds390 etc.).
2971  
2972 \newline 
2973
2974 \layout Standard
2975 \align center 
2976
2977 \begin_inset  Tabular
2978 <lyxtabular version="3" rows="6" columns="3">
2979 <features>
2980 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2981 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2982 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2983 <row topline="true" bottomline="true">
2984 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2985 \begin_inset Text
2986
2987 \layout Standard
2988
2989 Search path
2990 \end_inset 
2991 </cell>
2992 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2993 \begin_inset Text
2994
2995 \layout Standard
2996
2997 default
2998 \end_inset 
2999 </cell>
3000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3001 \begin_inset Text
3002
3003 \layout Standard
3004
3005 Win32 builds
3006 \end_inset 
3007 </cell>
3008 </row>
3009 <row topline="true">
3010 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3011 \begin_inset Text
3012
3013 \layout Standard
3014
3015 -
3016 \begin_inset ERT
3017 status Collapsed
3018
3019 \layout Standard
3020
3021 \backslash 
3022 /
3023 \end_inset 
3024
3025 -L dir
3026 \end_inset 
3027 </cell>
3028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3029 \begin_inset Text
3030
3031 \layout Standard
3032
3033 -
3034 \begin_inset ERT
3035 status Collapsed
3036
3037 \layout Standard
3038
3039 \backslash 
3040 /
3041 \end_inset 
3042
3043 -L dir
3044 \end_inset 
3045 </cell>
3046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3047 \begin_inset Text
3048
3049 \layout Standard
3050
3051 -
3052 \begin_inset ERT
3053 status Collapsed
3054
3055 \layout Standard
3056
3057 \backslash 
3058 /
3059 \end_inset 
3060
3061 -L dir
3062 \end_inset 
3063 </cell>
3064 </row>
3065 <row topline="true">
3066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3067 \begin_inset Text
3068
3069 \layout Standard
3070
3071 $SDCC_LIB/
3072 \newline 
3073
3074 \emph on 
3075 <model>
3076 \end_inset 
3077 </cell>
3078 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3079 \begin_inset Text
3080
3081 \layout Standard
3082
3083 $SDCC_LIB/
3084 \newline 
3085
3086 \emph on 
3087 <model>
3088 \end_inset 
3089 </cell>
3090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3091 \begin_inset Text
3092
3093 \layout Standard
3094
3095 $SDCC_LIB
3096 \backslash 
3097
3098 \newline 
3099
3100 \emph on 
3101 <model>
3102 \end_inset 
3103 </cell>
3104 </row>
3105 <row topline="true">
3106 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3107 \begin_inset Text
3108
3109 \layout Standard
3110
3111 $SDCC_HOME/
3112 \newline 
3113
3114 \emph on 
3115 $PREFIX2DATA_DIR/
3116 \newline 
3117 $LIB_DIR_SUFFIX/<model>
3118 \end_inset 
3119 </cell>
3120 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3121 \begin_inset Text
3122
3123 \layout Standard
3124
3125 $SDCC_HOME/
3126 \newline 
3127 share/sdcc/
3128 \newline 
3129 lib/
3130 \emph on 
3131 <model>
3132 \end_inset 
3133 </cell>
3134 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3135 \begin_inset Text
3136
3137 \layout Standard
3138
3139 $SDCC_HOME
3140 \backslash 
3141 lib
3142 \backslash 
3143
3144 \emph on 
3145
3146 \newline 
3147 <model>
3148 \end_inset 
3149 </cell>
3150 </row>
3151 <row topline="true">
3152 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3153 \begin_inset Text
3154
3155 \layout Standard
3156
3157 path(argv[0])/
3158 \newline 
3159
3160 \emph on 
3161 $BIN2DATADIR/
3162 \emph default 
3163
3164 \newline 
3165
3166 \emph on 
3167 $LIB_DIR_SUFFIX/<model>
3168 \end_inset 
3169 </cell>
3170 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_inset Text
3172
3173 \layout Standard
3174
3175 path(argv[0])/
3176 \newline 
3177 ../sdcc/lib/
3178 \emph on 
3179 <model>
3180 \newline 
3181 \SpecialChar ~
3182 \SpecialChar ~
3183 \SpecialChar ~
3184 \SpecialChar ~
3185 \SpecialChar ~
3186 \SpecialChar ~
3187 \SpecialChar ~
3188 \SpecialChar ~
3189 \SpecialChar ~
3190 \SpecialChar ~
3191 \SpecialChar ~
3192 \SpecialChar ~
3193 \SpecialChar ~
3194 \SpecialChar ~
3195 \SpecialChar ~
3196 \SpecialChar ~
3197 \SpecialChar ~
3198 \SpecialChar ~
3199 \SpecialChar ~
3200 \SpecialChar ~
3201 \SpecialChar ~
3202 \SpecialChar ~
3203 \SpecialChar ~
3204 \SpecialChar ~
3205 \SpecialChar ~
3206 \SpecialChar ~
3207 \SpecialChar ~
3208 \SpecialChar ~
3209 \SpecialChar ~
3210 \SpecialChar ~
3211 \SpecialChar ~
3212 \SpecialChar ~
3213 \SpecialChar ~
3214 \SpecialChar ~
3215 \SpecialChar ~
3216 \SpecialChar ~
3217 \SpecialChar ~
3218 \SpecialChar ~
3219 \SpecialChar ~
3220
3221 \end_inset 
3222 </cell>
3223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3224 \begin_inset Text
3225
3226 \layout Standard
3227
3228 path(argv[0])
3229 \backslash 
3230
3231 \newline 
3232 ..
3233 \backslash 
3234 lib
3235 \backslash 
3236
3237 \emph on 
3238 <model>
3239 \newline 
3240 \SpecialChar ~
3241 \SpecialChar ~
3242 \SpecialChar ~
3243 \SpecialChar ~
3244 \SpecialChar ~
3245 \SpecialChar ~
3246 \SpecialChar ~
3247 \SpecialChar ~
3248 \SpecialChar ~
3249 \SpecialChar ~
3250 \SpecialChar ~
3251 \SpecialChar ~
3252 \SpecialChar ~
3253 \SpecialChar ~
3254 \SpecialChar ~
3255 \SpecialChar ~
3256 \SpecialChar ~
3257 \SpecialChar ~
3258 \SpecialChar ~
3259 \SpecialChar ~
3260 \SpecialChar ~
3261 \SpecialChar ~
3262 \SpecialChar ~
3263 \SpecialChar ~
3264 \SpecialChar ~
3265 \SpecialChar ~
3266 \SpecialChar ~
3267 \SpecialChar ~
3268 \SpecialChar ~
3269 \SpecialChar ~
3270 \SpecialChar ~
3271 \SpecialChar ~
3272 \SpecialChar ~
3273 \SpecialChar ~
3274 \SpecialChar ~
3275
3276 \end_inset 
3277 </cell>
3278 </row>
3279 <row topline="true" bottomline="true">
3280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3281 \begin_inset Text
3282
3283 \layout Standard
3284
3285
3286 \emph on 
3287 $DATADIR/
3288 \newline 
3289 $LIB_DIR_SUFFIX/<model>
3290 \end_inset 
3291 </cell>
3292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3293 \begin_inset Text
3294
3295 \layout Standard
3296
3297 /usr/local/share/sdcc/
3298 \newline 
3299 lib/
3300 \emph on 
3301 <model>
3302 \end_inset 
3303 </cell>
3304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3305 \begin_inset Text
3306
3307 \layout Standard
3308
3309 (not on Win32)
3310 \end_inset 
3311 </cell>
3312 </row>
3313 </lyxtabular>
3314
3315 \end_inset 
3316
3317
3318 \newline 
3319
3320 \layout Comment
3321
3322 Don't delete any of the stray spaces in the table above without checking
3323  the HTML output (last line)!
3324 \layout Standard
3325
3326 \SpecialChar ~
3327
3328 \newline 
3329 The option -
3330 \begin_inset ERT
3331 status Collapsed
3332
3333 \layout Standard
3334
3335 \backslash 
3336 /
3337 \end_inset 
3338
3339 -nostdlib disables the last two search paths.
3340 \layout Section
3341
3342 Building SDCC
3343 \begin_inset LatexCommand \index{Building SDCC}
3344
3345 \end_inset 
3346
3347
3348 \layout Subsection
3349
3350 Building SDCC on Linux
3351 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3352
3353 \end_inset 
3354
3355
3356 \layout Enumerate
3357
3358
3359 \series medium 
3360 Download the source package
3361 \series default 
3362  either from the SDCC Subversion repository or from the nightly snapshots
3363 \series medium 
3364 , it will be named something like sdcc
3365 \series default 
3366 .src
3367 \series medium 
3368 .t
3369 \series default 
3370 ar.
3371 \series medium 
3372 gz
3373 \series default 
3374  
3375 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3376
3377 \end_inset 
3378
3379 .
3380 \layout Enumerate
3381
3382
3383 \series medium 
3384 Bring up a command line terminal, such as xterm.
3385 \layout Enumerate
3386
3387
3388 \series medium 
3389 Unpack the file using a command like: 
3390 \family sans 
3391 \series bold 
3392 "tar -xvzf sdcc.src.tar.gz
3393 \family default 
3394 \series default 
3395 "
3396 \series medium 
3397 , this will create a sub-directory called sdcc with all of the sources.
3398 \layout Enumerate
3399
3400 Change directory into the main SDCC directory, for example type: 
3401 \family sans 
3402 \series bold 
3403 "cd sdcc
3404 \series default 
3405 ".
3406 \layout Enumerate
3407
3408
3409 \series medium 
3410 Type 
3411 \family sans 
3412 \series bold 
3413 "./configure
3414 \family default 
3415 \series default 
3416 ".
3417  This configures the package for compilation on your system.
3418 \layout Enumerate
3419
3420
3421 \series medium 
3422 Type 
3423 \family sans 
3424 \series bold 
3425 "make
3426 \family default 
3427 \series default 
3428 "
3429 \series medium 
3430 .
3431
3432 \series default 
3433  All of the source packages will compile, this can take a while.
3434 \layout Enumerate
3435
3436
3437 \series medium 
3438 Type 
3439 \family sans 
3440 \series bold 
3441 "make install"
3442 \family default 
3443 \series default 
3444  as root
3445 \series medium 
3446 .
3447
3448 \series default 
3449  This copies the binary executables, the include files, the libraries and
3450  the documentation to the install directories.
3451  Proceed with section 
3452 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3453
3454 \end_inset 
3455
3456 .
3457 \layout Subsection
3458
3459 Building SDCC on OSX 2.x
3460 \layout Standard
3461
3462 Follow the instruction for Linux.
3463 \newline 
3464
3465 \newline 
3466 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3467 )) fails to compile SDCC.
3468  Fortunately there's also gcc 2.9.x installed, which works fine.
3469  This compiler can be selected by running 'configure' with:
3470 \layout LyX-Code
3471
3472 ./configure CC=gcc2 CXX=g++2
3473 \layout Subsection
3474
3475 Cross compiling SDCC on Linux for Windows
3476 \layout Standard
3477
3478 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3479  See section 'Configure Options'.
3480 \layout Subsection
3481
3482 Building SDCC using Cygwin and Mingw32
3483 \layout Standard
3484
3485 For building and installing a Cygwin executable follow the instructions
3486  for Linux.
3487 \newline 
3488
3489 \newline 
3490 On Cygwin a 
3491 \begin_inset Quotes sld
3492 \end_inset 
3493
3494 native
3495 \begin_inset Quotes srd
3496 \end_inset 
3497
3498  Win32-binary can be built, which will not need the Cygwin-DLL.
3499  For the necessary 'configure' options see section 'configure options' or
3500  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3501 \newline 
3502
3503 \newline 
3504 In order to install Cygwin on Windows download setup.exe from 
3505 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3506
3507 \end_inset 
3508
3509 .
3510  Run it, set the 
3511 \begin_inset Quotes sld
3512 \end_inset 
3513
3514 default text file type
3515 \begin_inset Quotes srd
3516 \end_inset 
3517
3518  to 
3519 \begin_inset Quotes sld
3520 \end_inset 
3521
3522 unix
3523 \begin_inset Quotes srd
3524 \end_inset 
3525
3526  and download/install at least the following packages.
3527  Some packages are selected by default, others will be automatically selected
3528  because of dependencies with the manually selected packages.
3529  Never deselect these packages!
3530 \layout Itemize
3531
3532 flex
3533 \layout Itemize
3534
3535 bison
3536 \layout Itemize
3537
3538 gcc ; version 3.x is fine, no need to use the old 2.9x
3539 \layout Itemize
3540
3541 binutils ; selected with gcc
3542 \layout Itemize
3543
3544 make
3545 \layout Itemize
3546
3547 rxvt ; a nice console, which makes life much easier under windoze (see below)
3548 \layout Itemize
3549
3550 man ; not really needed for building SDCC, but you'll miss it sooner or
3551  later
3552 \layout Itemize
3553
3554 less ; not really needed for building SDCC, but you'll miss it sooner or
3555  later
3556 \layout Itemize
3557
3558 svn ; only if you use Subversion access
3559 \layout Standard
3560
3561 If you want to develop something you'll need:
3562 \layout Itemize
3563
3564 python ; for the regression tests
3565 \layout Itemize
3566
3567 gdb ; the gnu debugger, together with the nice GUI 
3568 \begin_inset Quotes sld
3569 \end_inset 
3570
3571 insight
3572 \begin_inset Quotes srd
3573 \end_inset 
3574
3575
3576 \layout Itemize
3577
3578 openssh ; to access the CF or commit changes
3579 \layout Itemize
3580
3581 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3582  use autoconf-stable!
3583 \layout Standard
3584
3585 rxvt is a nice console with history.
3586  Replace in your cygwin.bat the line
3587 \layout LyX-Code
3588
3589 bash -
3590 \begin_inset ERT
3591 status Collapsed
3592
3593 \layout Standard
3594
3595 \backslash 
3596 /
3597 \end_inset 
3598
3599 -login -i 
3600 \layout Standard
3601
3602 with (one line):
3603 \layout LyX-Code
3604
3605 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3606 \layout LyX-Code
3607
3608      -bg black -fg white -geometry 100x65 -e bash -
3609 \begin_inset ERT
3610 status Collapsed
3611
3612 \layout Standard
3613
3614 \backslash 
3615 /
3616 \end_inset 
3617
3618 -login
3619 \layout Standard
3620
3621 Text selected with the mouse is automatically copied to the clipboard, pasting
3622  works with shift-insert.
3623 \newline 
3624
3625 \newline 
3626 The other good tip is to make sure you have no //c/-style paths anywhere,
3627  use /cygdrive/c/ instead.
3628  Using // invokes a network lookup which is very slow.
3629  If you think 
3630 \begin_inset Quotes sld
3631 \end_inset 
3632
3633 cygdrive
3634 \begin_inset Quotes srd
3635 \end_inset 
3636
3637  is too long, you can change it with e.g.
3638 \layout LyX-Code
3639
3640 mount -s -u -c /mnt
3641 \layout Standard
3642
3643 SDCC sources use the unix line ending LF.
3644  Life is much easier, if you store the source tree on a drive which is mounted
3645  in binary mode.
3646  And use an editor which can handle LF-only line endings.
3647  Make sure not to commit files with windows line endings.
3648  The tabulator spacing
3649 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3650
3651 \end_inset 
3652
3653  used in the project is 8.
3654  Although a tabulator spacing of 8 is a sensible choice for programmers
3655  (it's a power of 2 and allows to display 8/16 bit signed variables without
3656  loosing columns) the plan is to move towards using only spaces in the source.
3657 \layout Subsection
3658
3659 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3660 \layout Standard
3661
3662
3663 \series medium 
3664 Download the source package
3665 \series default 
3666  either from the SDCC Subversion repository or from the 
3667 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3668
3669 \end_inset 
3670
3671
3672 \series medium 
3673 , it will be named something like sdcc
3674 \series default 
3675 .src
3676 \series medium 
3677 .tgz.
3678
3679 \series default 
3680  SDCC is distributed with all the projects, workspaces, and files you need
3681  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3682  The workspace name is 'sdcc.dsw'.
3683  Please note that as it is now, all the executables are created in a folder
3684  called sdcc
3685 \backslash 
3686 bin_vc.
3687  Once built you need to copy the executables from sdcc
3688 \backslash 
3689 bin_vc to sdcc
3690 \backslash 
3691 bin before running SDCC.
3692  
3693 \newline 
3694
3695 \newline 
3696 WARNING: Visual studio is very picky with line terminations; it expects
3697  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3698  When using the Subversion repository it's easiest to configure the svn
3699  client to convert automatically for you.
3700  If however you are getting a message such as "This makefile was not generated
3701  by Developer Studio etc.
3702  etc.
3703 \begin_inset Quotes srd
3704 \end_inset 
3705
3706  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3707  need to convert the Unix style line endings to DOS style line endings.
3708  To do so you can use the 
3709 \begin_inset Quotes sld
3710 \end_inset 
3711
3712 unix2dos
3713 \begin_inset Quotes srd
3714 \end_inset 
3715
3716  utility freely available on the internet.
3717  Doug Hawkins reported in the sdcc-user list that this works:
3718 \newline 
3719
3720 \newline 
3721 C:
3722 \backslash 
3723 Programming
3724 \backslash 
3725 SDCC> unix2dos sdcc.dsw
3726 \newline 
3727 C:
3728 \backslash 
3729 Programming
3730 \backslash 
3731 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3732 \newline 
3733
3734 \newline 
3735 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3736  flex.exe, and gawk.exe.
3737  One good place to get them is 
3738 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3739
3740 \end_inset 
3741
3742
3743 \newline 
3744
3745 \newline 
3746 Download the file UnxUtils
3747 \begin_inset LatexCommand \index{UnxUtils}
3748
3749 \end_inset 
3750
3751 .zip.
3752  Now you have to install the utilities and setup MSVC so it can locate the
3753  required programs.
3754  Here there are two alternatives (choose one!):
3755 \layout Enumerate
3756
3757 The easy way:
3758 \newline 
3759
3760 \newline 
3761 a) Extract UnxUtils.zip to your C:
3762 \backslash 
3763  hard disk PRESERVING the original paths, otherwise bison won't work.
3764  (If you are using WinZip make certain that 'Use folder names' is selected)
3765 \newline 
3766
3767 \newline 
3768 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3769  in 'Show directories for:' select 'Executable files', and in the directories
3770  window add a new path: 'C:
3771 \backslash 
3772 user
3773 \backslash 
3774 local
3775 \backslash 
3776 wbin', click ok.
3777 \newline 
3778
3779 \newline 
3780 (As a side effect, you get a bunch of Unix utilities that could be useful,
3781  such as diff and patch.)
3782 \layout Enumerate
3783
3784 A more compact way:
3785 \newline 
3786
3787 \newline 
3788 This one avoids extracting a bunch of files you may not use, but requires
3789  some extra work:
3790 \newline 
3791
3792 \newline 
3793 a) Create a directory were to put the tools needed, or use a directory already
3794  present.
3795  Say for example 'C:
3796 \backslash 
3797 util'.
3798 \newline 
3799
3800 \newline 
3801 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3802  to such directory WITHOUT preserving the original paths.
3803  (If you are using WinZip make certain that 'Use folder names' is not selected)
3804 \newline 
3805
3806 \newline 
3807 c) Rename bison.exe to '_bison.exe'.
3808 \newline 
3809
3810 \newline 
3811 d) Create a batch file 'bison.bat' in 'C:
3812 \backslash 
3813 util
3814 \backslash 
3815 ' and add these lines: 
3816 \newline 
3817 \SpecialChar ~
3818 \SpecialChar ~
3819 set BISON_SIMPLE=C:
3820 \backslash 
3821 util
3822 \backslash 
3823 bison.simple 
3824 \newline 
3825 \SpecialChar ~
3826 \SpecialChar ~
3827 set BISON_HAIRY=C:
3828 \backslash 
3829 util
3830 \backslash 
3831 bison.hairy
3832 \newline 
3833 \SpecialChar ~
3834 \SpecialChar ~
3835 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3836 \newline 
3837
3838 \newline 
3839 Steps 'c' and 'd' are needed because bison requires by default that the
3840  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3841  '/usr/local/share/' I think.
3842  So it is necessary to tell bison where those files are located if they
3843  are not in such directory.
3844  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3845 \newline 
3846
3847 \newline 
3848 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3849  in 'Show directories for:' select 'Executable files', and in the directories
3850  window add a new path: 'c:
3851 \backslash 
3852 util', click ok.
3853  Note that you can use any other path instead of 'c:
3854 \backslash 
3855 util', even the path where the Visual C++ tools are, probably: 'C:
3856 \backslash 
3857 Program Files
3858 \backslash 
3859 Microsoft Visual Studio
3860 \backslash 
3861 Common
3862 \backslash 
3863 Tools'.
3864  So you don't have to execute step 'e' :)
3865 \layout Standard
3866
3867 That is it.
3868  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3869  the executables from sdcc
3870 \backslash 
3871 bin_vc to sdcc
3872 \backslash 
3873 bin, and you can compile using SDCC.
3874 \layout Subsection
3875
3876 Building SDCC Using Borland
3877 \layout Enumerate
3878
3879 From the sdcc directory, run the command "make -f Makefile.bcc".
3880  This should regenerate all the .exe files in the bin directory except for
3881  SDCDB and ucSim.
3882 \layout Enumerate
3883
3884 If you modify any source files and need to rebuild, be aware that the dependenci
3885 es may not be correctly calculated.
3886  The safest option is to delete all .obj files and run the build again.
3887  From a Cygwin BASH prompt, this can easily be done with the command (be
3888  sure you are in the sdcc directory):
3889 \newline 
3890
3891 \newline 
3892
3893 \family sans 
3894 \series bold 
3895 find .
3896  
3897 \backslash 
3898 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3899 \backslash 
3900 ) -print -exec rm {} 
3901 \backslash 
3902 ;
3903 \family default 
3904 \series default 
3905
3906 \newline 
3907
3908 \newline 
3909 or on Windows NT/2000/XP from the command prompt with the command:
3910 \newline 
3911
3912 \family sans 
3913 \series bold 
3914
3915 \newline 
3916 del /s *.obj *.lib *.rul
3917 \family default 
3918 \series default 
3919  from the sdcc directory.
3920 \layout Subsection
3921
3922 Windows Install Using a ZIP Package
3923 \layout Enumerate
3924
3925 Download the binary zip package from 
3926 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3927
3928 \end_inset 
3929
3930  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3931  This should unpack to a group of sub-directories.
3932  An example directory structure after unpacking the mingw32 package is:
3933  c:
3934 \backslash 
3935 sdcc
3936 \backslash 
3937 bin for the executables, c:
3938 \backslash 
3939 sdcc
3940 \backslash 
3941 include and c:
3942 \backslash 
3943 sdcc
3944 \backslash 
3945 lib for the include and libraries.
3946 \layout Enumerate
3947
3948 Adjust your environment variable PATH to include the location of the bin
3949  directory or start sdcc using the full path.
3950 \layout Subsection
3951
3952 Windows Install Using the Setup Program
3953 \begin_inset LatexCommand \label{sub:Windows-Install}
3954
3955 \end_inset 
3956
3957
3958 \layout Standard
3959
3960 Download the setup program 
3961 \emph on 
3962 sdcc-x.y.z-setup.exe
3963 \emph default 
3964  for an official release from 
3965 \newline 
3966
3967 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3968
3969 \end_inset 
3970
3971  or a setup program for one of the snapshots 
3972 \emph on 
3973 sdcc-yyyymmdd-xxxx-setup.exe
3974 \emph default 
3975  from 
3976 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3977
3978 \end_inset 
3979
3980  and execute it.
3981  A windows typical installer will guide you through the installation process.
3982 \layout Subsection
3983
3984 VPATH
3985 \begin_inset LatexCommand \index{VPATH}
3986
3987 \end_inset 
3988
3989  feature
3990 \layout Standard
3991
3992 SDCC supports the VPATH feature provided by configure and make.
3993  It allows to separate the source and build trees.
3994  Here's an example:
3995 \layout Standard
3996
3997
3998 \family typewriter 
3999 cd ~\SpecialChar ~
4000 \SpecialChar ~
4001 \SpecialChar ~
4002 \SpecialChar ~
4003 \SpecialChar ~
4004 \SpecialChar ~
4005 \SpecialChar ~
4006 \SpecialChar ~
4007 \SpecialChar ~
4008 \SpecialChar ~
4009 \SpecialChar ~
4010 \SpecialChar ~
4011 \SpecialChar ~
4012 \SpecialChar ~
4013 \SpecialChar ~
4014 \SpecialChar ~
4015 \SpecialChar ~
4016 \SpecialChar ~
4017 \SpecialChar ~
4018 \SpecialChar ~
4019 \SpecialChar ~
4020 # cd $HOME
4021 \layout Standard
4022
4023
4024 \family typewriter 
4025 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4026 # extract source to directory sdcc
4027 \layout Standard
4028
4029
4030 \family typewriter 
4031 mkdir sdcc.build\SpecialChar ~
4032 \SpecialChar ~
4033 \SpecialChar ~
4034 \SpecialChar ~
4035 \SpecialChar ~
4036 \SpecialChar ~
4037 \SpecialChar ~
4038 \SpecialChar ~
4039 \SpecialChar ~
4040 # put output in sdcc.build
4041 \layout Standard
4042
4043
4044 \family typewriter 
4045 cd sdcc.build
4046 \layout Standard
4047
4048
4049 \family typewriter 
4050 ../sdcc/configure\SpecialChar ~
4051 \SpecialChar ~
4052 \SpecialChar ~
4053 \SpecialChar ~
4054 \SpecialChar ~
4055 \SpecialChar ~
4056 \SpecialChar ~
4057 \SpecialChar ~
4058 # configure is doing all the magic!
4059 \layout Standard
4060
4061
4062 \family typewriter 
4063 make
4064 \layout Standard
4065 \noindent 
4066 That's it! 
4067 \series bold 
4068 configure
4069 \series default 
4070  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4071  It automagically computes the variables srcdir, top_srcdir and top_buildir
4072  for each directory.
4073  After running 
4074 \series bold 
4075 make
4076 \series default 
4077  the generated files will be in ~/sdcc.build, while the source files stay
4078  in ~/sdcc.
4079 \newline 
4080 This is not only usefull for building different binaries, e.g.
4081  when cross compiling.
4082  It also gives you a much better overview in the source tree when all the
4083  generated files are not scattered between the source files.
4084  And the best thing is: if you want to change a file you can leave the original
4085  file untouched in the source directory.
4086  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4087  Makefile.dep` and `make`.
4088  
4089 \series bold 
4090 make
4091 \series default 
4092  will do the rest for you!
4093 \layout Section
4094
4095 Building the Documentation
4096 \layout Standard
4097
4098 Add -
4099 \begin_inset ERT
4100 status Collapsed
4101
4102 \layout Standard
4103
4104 \backslash 
4105 /
4106 \end_inset 
4107
4108 -enable-doc to the configure arguments to build the documentation together
4109  with all the other stuff.
4110  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4111  dvips and makeindex) to get the job done.
4112  Another possibility is to change to the doc directory and to type 
4113 \family sans 
4114 \series bold 
4115
4116 \begin_inset Quotes srd
4117 \end_inset 
4118
4119 make
4120 \begin_inset Quotes srd
4121 \end_inset 
4122
4123
4124 \family default 
4125 \series default 
4126  there.
4127  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4128 x).
4129  Using LyX 
4130 \begin_inset LatexCommand \url{http://www.lyx.org}
4131
4132 \end_inset 
4133
4134  as editor is straightforward.
4135  Prebuilt documentation in html and pdf format is available from 
4136 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4137
4138 \end_inset 
4139
4140 .
4141 \layout Section
4142
4143 Reading the Documentation
4144 \begin_inset LatexCommand \index{Documentation}
4145
4146 \end_inset 
4147
4148
4149 \layout Standard
4150
4151 Currently reading the document in pdf format is recommended, as for unknown
4152  reason the hyperlinks are working there whereas in the html version they
4153  are not
4154 \begin_inset Foot
4155 collapsed false
4156
4157 \layout Standard
4158
4159 If you should know why please drop us a note
4160 \end_inset 
4161
4162 .
4163  
4164 \newline 
4165 You'll find the pdf version
4166 \begin_inset LatexCommand \index{PDF version of this document}
4167
4168 \end_inset 
4169
4170  at 
4171 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4172
4173 \end_inset 
4174
4175 .
4176  
4177 \newline 
4178 A html version
4179 \begin_inset LatexCommand \index{HTML version of this document}
4180
4181 \end_inset 
4182
4183  should be online at 
4184 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4185
4186 \end_inset 
4187
4188 .
4189 \newline 
4190 This documentation is in some aspects different from a commercial documentation:
4191  
4192 \layout Itemize
4193
4194 It tries to document SDCC for several processor architectures in one document
4195  (commercially these probably would be separate documents/products).
4196  This document
4197 \begin_inset LatexCommand \index{Status of documentation}
4198
4199 \end_inset 
4200
4201  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4202 on about f.e.
4203  Z80, PIC14, PIC16 and HC08.
4204 \layout Itemize
4205
4206 There are many references pointing away from this documentation.
4207  Don't let this distract you.
4208  If there f.e.
4209  was a reference like 
4210 \begin_inset LatexCommand \url{http://www.opencores.org}
4211
4212 \end_inset 
4213
4214  together with a statement 
4215 \begin_inset Quotes sld
4216 \end_inset 
4217
4218 some processors which are targetted by SDCC can be implemented in a 
4219 \emph on 
4220 f
4221 \emph default 
4222 ield 
4223 \emph on 
4224 p
4225 \emph default 
4226 rogrammable 
4227 \emph on 
4228 g
4229 \emph default 
4230 ate 
4231 \emph on 
4232 a
4233 \emph default 
4234 rray
4235 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4236
4237 \end_inset 
4238
4239
4240 \begin_inset Quotes srd
4241 \end_inset 
4242
4243  or 
4244 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4245
4246 \end_inset 
4247
4248
4249 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4250
4251 \end_inset 
4252
4253  
4254 \begin_inset Quotes sld
4255 \end_inset 
4256
4257 have you ever heard of an open source compiler that compiles a subset of
4258  C for an FPGA?
4259 \begin_inset Quotes srd
4260 \end_inset 
4261
4262  we expect you to have a quick look there and come back.
4263  If you read this you are on the right track.
4264 \layout Itemize
4265
4266 Some sections attribute more space to problems, restrictions and warnings
4267  than to the solution.
4268 \layout Itemize
4269
4270 The installation section and the section about the debugger is intimidating.
4271 \layout Itemize
4272
4273 There are still lots of typos and there are more different writing styles
4274  than pictures.
4275 \layout Section
4276
4277 Testing the SDCC Compiler
4278 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4279
4280 \end_inset 
4281
4282
4283 \layout Standard
4284
4285 The first thing you should do after installing your SDCC compiler is to
4286  see if it runs.
4287  Type 
4288 \family sans 
4289 \series bold 
4290 "sdcc -
4291 \begin_inset ERT
4292 status Collapsed
4293
4294 \layout Standard
4295
4296 \backslash 
4297 /
4298 \end_inset 
4299
4300 -version"
4301 \begin_inset LatexCommand \index{version}
4302
4303 \end_inset 
4304
4305
4306 \family default 
4307 \series default 
4308  at the prompt, and the program should run and output its version like:
4309  
4310 \newline 
4311
4312 \family typewriter 
4313 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4314  (UNIX)
4315 \layout Standard
4316
4317 If it doesn't run, or gives a message about not finding sdcc program, then
4318  you need to check over your installation.
4319  Make sure that the sdcc bin directory is in your executable search path
4320  defined by the PATH environment setting (
4321 \series medium 
4322 see 
4323 \series default 
4324 section 
4325 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4326
4327 \end_inset 
4328
4329 \SpecialChar ~
4330
4331 \series medium 
4332 Install trouble-shooting for suggestions
4333 \series default 
4334 ).
4335  Make sure that the sdcc program is in the bin folder, if not perhaps something
4336  did not install correctly.
4337 \newline 
4338
4339 \newline 
4340
4341 \series medium 
4342 SDCC 
4343 \series default 
4344 is commonly installed as described in section 
4345 \begin_inset Quotes sld
4346 \end_inset 
4347
4348 Install and search paths
4349 \begin_inset Quotes srd
4350 \end_inset 
4351
4352 .
4353 \newline 
4354
4355 \newline 
4356
4357 \series medium 
4358 Make sure the compiler works on a very simple example.
4359  Type in the following test.c program using your favorite 
4360 \series default 
4361 ASCII 
4362 \series medium 
4363 editor:
4364 \layout Verse
4365
4366
4367 \family typewriter 
4368 char test;
4369 \newline 
4370
4371 \newline 
4372 void main(void) {
4373 \newline 
4374 \SpecialChar ~
4375 \SpecialChar ~
4376 \SpecialChar ~
4377 \SpecialChar ~
4378 test=0;
4379 \newline 
4380 }
4381 \layout Standard
4382
4383
4384 \series medium 
4385 Compile this using the following command: 
4386 \family sans 
4387 \series bold 
4388 "sdcc -c test.c".
4389
4390 \family default 
4391 \series default 
4392  
4393 \series medium 
4394 If all goes well, the compiler will generate a test.asm and test.rel file.
4395  Congratulations, you've just compiled your first program with SDCC.
4396  We used the -c option to tell SDCC not to link the generated code, just
4397  to keep things simple for this step.
4398 \series default 
4399
4400 \newline 
4401
4402 \newline 
4403
4404 \series medium 
4405 The next step is to try it with the linker.
4406  Type in 
4407 \family sans 
4408 \series bold 
4409 "sdcc test.c
4410 \family default 
4411 \series default 
4412 "
4413 \series medium 
4414 .
4415  If all goes well the compiler will link with the libraries and produce
4416  a test.ihx output file.
4417  If this step fails
4418 \series default 
4419  
4420 \series medium 
4421 (no test.ihx, and the linker generates warnings), then the problem is most
4422  likely that 
4423 \series default 
4424 SDCC
4425 \series medium 
4426  cannot find the 
4427 \series default 
4428 /
4429 \series medium 
4430 usr/local/share/sdcc/lib directory
4431 \series default 
4432  
4433 \series medium 
4434 (see 
4435 \series default 
4436 section 
4437 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4438
4439 \end_inset 
4440
4441 \SpecialChar ~
4442
4443 \series medium 
4444 Install trouble-shooting for suggestions).
4445 \series default 
4446
4447 \newline 
4448
4449 \newline 
4450
4451 \series medium 
4452 The final test is to ensure 
4453 \series default 
4454 SDCC
4455 \series medium 
4456  can use the 
4457 \series default 
4458 standard
4459 \series medium 
4460  header files and libraries.
4461  Edit test.c and change it to the following:
4462 \layout Verse
4463
4464
4465 \family typewriter 
4466 #include <string.h>
4467 \newline 
4468
4469 \newline 
4470 char str1[10];
4471 \newline 
4472
4473 \newline 
4474 void main(void) {
4475 \newline 
4476 \SpecialChar ~
4477 \SpecialChar ~
4478 strcpy(str1, "testing");
4479 \newline 
4480 }
4481 \layout Standard
4482
4483
4484 \series medium 
4485 Compile this by typing 
4486 \family sans 
4487 \series bold 
4488 "sdcc test.c"
4489 \family default 
4490 \series medium 
4491 .
4492  This should generate a test.ihx output file, and it should give no warnings
4493  such as not finding the string.h file.
4494  If it cannot find the string.h file, then the problem is that 
4495 \series default 
4496 SDCC
4497 \series medium 
4498  cannot find the /usr/local/share/sdcc/include directory
4499 \series default 
4500  
4501 \series medium 
4502 (see the 
4503 \series default 
4504 section 
4505 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4506
4507 \end_inset 
4508
4509 \SpecialChar ~
4510
4511 \series medium 
4512 Install trouble-shooting section for suggestions).
4513
4514 \series default 
4515  Use option 
4516 \series bold 
4517 -
4518 \begin_inset ERT
4519 status Collapsed
4520
4521 \layout Standard
4522
4523 \backslash 
4524 /
4525 \end_inset 
4526
4527 -print-search-dirs
4528 \series default 
4529
4530 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4531
4532 \end_inset 
4533
4534  to find exactly where SDCC is looking for the include and lib files.
4535 \layout Section
4536
4537 Install Trouble-shooting
4538 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4539
4540 \end_inset 
4541
4542
4543 \begin_inset LatexCommand \index{Install trouble-shooting}
4544
4545 \end_inset 
4546
4547
4548 \layout Subsection
4549
4550 If SDCC does not build correctly
4551 \layout Standard
4552
4553 A thing to try is starting from scratch by unpacking the .tgz source package
4554  again in an empty directory.
4555  Configure it like:
4556 \newline 
4557
4558 \newline 
4559
4560 \family sans 
4561 \series bold 
4562 ./configure 2>&1 | tee configure.log
4563 \family default 
4564 \series default 
4565
4566 \newline 
4567
4568 \newline 
4569 and build it like:
4570 \newline 
4571
4572 \newline 
4573
4574 \family sans 
4575 \series bold 
4576 make 2>&1 | tee make.log
4577 \family default 
4578 \series default 
4579
4580 \newline 
4581
4582 \newline 
4583 If anything goes wrong, you can review the log files to locate the problem.
4584  Or a relevant part of this can be attached to an email that could be helpful
4585  when requesting help from the mailing list.
4586 \layout Subsection
4587
4588 What the 
4589 \begin_inset Quotes sld
4590 \end_inset 
4591
4592 ./configure
4593 \begin_inset Quotes srd
4594 \end_inset 
4595
4596  does
4597 \layout Standard
4598
4599 The 
4600 \begin_inset Quotes sld
4601 \end_inset 
4602
4603 ./configure
4604 \begin_inset Quotes srd
4605 \end_inset 
4606
4607  command is a script that analyzes your system and performs some configuration
4608  to ensure the source package compiles on your system.
4609  It will take a few minutes to run, and will compile a few tests to determine
4610  what compiler features are installed.
4611 \layout Subsection
4612
4613 What the 
4614 \begin_inset Quotes sld
4615 \end_inset 
4616
4617 make
4618 \begin_inset Quotes srd
4619 \end_inset 
4620
4621  does
4622 \layout Standard
4623
4624 This runs the GNU make tool, which automatically compiles all the source
4625  packages into the final installed binary executables.
4626 \layout Subsection
4627
4628 What the 
4629 \begin_inset Quotes sld
4630 \end_inset 
4631
4632 make install
4633 \begin_inset Quotes erd
4634 \end_inset 
4635
4636  command does.
4637 \layout Standard
4638
4639 This will install the compiler, other executables libraries and include
4640  files into the appropriate directories.
4641  See sections 
4642 \begin_inset LatexCommand \ref{sub:Install-paths}
4643
4644 \end_inset 
4645
4646 ,\SpecialChar ~
4647
4648 \begin_inset LatexCommand \ref{sub:Search-Paths}
4649
4650 \end_inset 
4651
4652 \SpecialChar ~
4653 about install and search paths.
4654 \newline 
4655 On most systems you will need super-user privileges to do this.
4656 \layout Section
4657
4658 Components of SDCC
4659 \layout Standard
4660
4661 SDCC is not just a compiler, but a collection of tools by various developers.
4662  These include linkers, assemblers, simulators and other components.
4663  Here is a summary of some of the components.
4664  Note that the included simulator and assembler have separate documentation
4665  which you can find in the source package in their respective directories.
4666  As SDCC grows to include support for other processors, other packages from
4667  various developers are included and may have their own sets of documentation.
4668 \newline 
4669
4670 \newline 
4671 You might want to look at the files which are installed in <installdir>.
4672  At the time of this writing, we find the following programs for gcc-builds:
4673 \newline 
4674  
4675 \newline 
4676 In <installdir>/bin:
4677 \layout Itemize
4678
4679 sdcc - The compiler.
4680 \layout Itemize
4681
4682 sdcpp - The C preprocessor.
4683 \layout Itemize
4684
4685 asx8051 - The assembler for 8051 type processors.
4686 \layout Itemize
4687
4688 as-z80
4689 \series bold 
4690
4691 \series default 
4692 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4693 \layout Itemize
4694
4695 aslink -The linker for 8051 type processors.
4696 \layout Itemize
4697
4698 link-z80
4699 \series bold 
4700
4701 \series default 
4702 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4703 \layout Itemize
4704
4705 s51 - The ucSim 8051 simulator.
4706 \layout Itemize
4707
4708 sdcdb - The source debugger.
4709 \layout Itemize
4710
4711 packihx - A tool to pack (compress) Intel hex files.
4712 \layout Standard
4713
4714 In <installdir>/share/sdcc/include
4715 \layout Itemize
4716
4717 the include files
4718 \layout Standard
4719
4720 In <installdir>/share/sdcc/lib
4721 \layout Itemize
4722
4723 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4724  relocatables.
4725 \layout Standard
4726
4727 In <installdir>/share/sdcc/doc
4728 \layout Itemize
4729
4730 the documentation
4731 \layout Standard
4732
4733 As development for other processors proceeds, this list will expand to include
4734  executables to support processors like AVR, PIC, etc.
4735 \layout Subsection
4736
4737 sdcc - The Compiler
4738 \layout Standard
4739
4740 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4741  the assembler and linkage editor.
4742 \layout Subsection
4743
4744 sdcpp - The C-Preprocessor
4745 \layout Standard
4746
4747 The preprocessor
4748 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4749
4750 \end_inset 
4751
4752  is a modified version of the GNU cpp
4753 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4754
4755 \end_inset 
4756
4757  preprocessor 
4758 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4759
4760 \end_inset 
4761
4762 .
4763  The C preprocessor is used to pull in #include sources, process #ifdef
4764  statements, #defines and so on.
4765 \layout Subsection
4766
4767 as
4768 \emph on 
4769 xxxx
4770 \emph default 
4771 , aslink, link-
4772 \emph on 
4773 xxx
4774 \emph default 
4775  - The Assemblers and Linkage Editors
4776 \layout Standard
4777
4778 This is retargettable assembler & linkage editor, it was developed by Alan
4779  Baldwin.
4780  John Hartman created the version for 8051, and I (Sandeep) have made some
4781  enhancements and bug fixes for it to work properly with SDCC.
4782 \layout Subsection
4783
4784 s51 - The Simulator
4785 \layout Standard
4786
4787 S51
4788 \begin_inset LatexCommand \index{s51}
4789
4790 \end_inset 
4791
4792  is a freeware, opensource simulator developed by Daniel Drotos.
4793  The simulator is built as part of the build process.
4794  For more information visit Daniel's web site at: 
4795 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4796
4797 \end_inset 
4798
4799 .
4800  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4801  XA51 family.
4802 \layout Subsection
4803
4804 sdcdb - Source Level Debugger
4805 \layout Standard
4806
4807 SDCDB
4808 \begin_inset LatexCommand \index{SDCDB (debugger)}
4809
4810 \end_inset 
4811
4812  is the companion source level debugger.
4813  More about SDCDB in section 
4814 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4815
4816 \end_inset 
4817
4818 .
4819  The current version of the debugger uses Daniel's Simulator S51
4820 \begin_inset LatexCommand \index{s51}
4821
4822 \end_inset 
4823
4824 , but can be easily changed to use other simulators.
4825 \layout Chapter
4826
4827 Using SDCC
4828 \layout Section
4829
4830 Compiling
4831 \layout Subsection
4832
4833 Single Source File Projects
4834 \layout Standard
4835
4836 For single source file 8051 projects the process is very simple.
4837  Compile your programs with the following command 
4838 \family sans 
4839 \series bold 
4840 "sdcc sourcefile.c".
4841
4842 \family default 
4843 \series default 
4844  This will compile, assemble and link your source file.
4845  Output files are as follows:
4846 \layout Itemize
4847
4848 sourcefile.asm
4849 \begin_inset LatexCommand \index{<file>.asm}
4850
4851 \end_inset 
4852
4853  - Assembler source
4854 \begin_inset LatexCommand \index{Assembler source}
4855
4856 \end_inset 
4857
4858  file created by the compiler
4859 \layout Itemize
4860
4861 sourcefile.lst
4862 \begin_inset LatexCommand \index{<file>.lst}
4863
4864 \end_inset 
4865
4866  - Assembler listing
4867 \begin_inset LatexCommand \index{Assembler listing}
4868
4869 \end_inset 
4870
4871  file created by the Assembler
4872 \layout Itemize
4873
4874 sourcefile.rst
4875 \begin_inset LatexCommand \index{<file>.rst}
4876
4877 \end_inset 
4878
4879  - Assembler listing
4880 \begin_inset LatexCommand \index{Assembler listing}
4881
4882 \end_inset 
4883
4884  file updated with linkedit information, created by linkage editor
4885 \layout Itemize
4886
4887 sourcefile.sym
4888 \begin_inset LatexCommand \index{<file>.sym}
4889
4890 \end_inset 
4891
4892  - symbol listing
4893 \begin_inset LatexCommand \index{Symbol listing}
4894
4895 \end_inset 
4896
4897  for the sourcefile, created by the assembler
4898 \layout Itemize
4899
4900 sourcefile.rel
4901 \begin_inset LatexCommand \index{<file>.rel}
4902
4903 \end_inset 
4904
4905  or sourcefile.o
4906 \begin_inset LatexCommand \index{<file>.o}
4907
4908 \end_inset 
4909
4910  - Object file
4911 \begin_inset LatexCommand \index{Object file}
4912
4913 \end_inset 
4914
4915  created by the assembler, input to Linkage editor
4916 \layout Itemize
4917
4918 sourcefile.map
4919 \begin_inset LatexCommand \index{<file>.map}
4920
4921 \end_inset 
4922
4923  - The memory map
4924 \begin_inset LatexCommand \index{Memory map}
4925
4926 \end_inset 
4927
4928  for the load module, created by the Linker
4929 \layout Itemize
4930
4931 sourcefile.mem
4932 \begin_inset LatexCommand \index{<file>.mem}
4933
4934 \end_inset 
4935
4936  - A file with a summary of the memory usage
4937 \layout Itemize
4938
4939 sourcefile.ihx
4940 \begin_inset LatexCommand \index{<file>.ihx}
4941
4942 \end_inset 
4943
4944  - The load module in Intel hex format
4945 \begin_inset LatexCommand \index{Intel hex format}
4946
4947 \end_inset 
4948
4949  (you can select the Motorola S19 format
4950 \begin_inset LatexCommand \index{Motorola S19 format}
4951
4952 \end_inset 
4953
4954  with -
4955 \begin_inset ERT
4956 status Collapsed
4957
4958 \layout Standard
4959
4960 \backslash 
4961 /
4962 \end_inset 
4963
4964 -out-fmt-s19
4965 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4966
4967 \end_inset 
4968
4969 .
4970  If you need another format you might want to use 
4971 \family sans 
4972 \shape italic 
4973 objdump
4974 \family default 
4975 \shape default 
4976
4977 \begin_inset LatexCommand \index{objdump (tool)}
4978
4979 \end_inset 
4980
4981  or
4982 \family sans 
4983 \shape italic 
4984  srecord
4985 \family default 
4986 \shape default 
4987
4988 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4989
4990 \end_inset 
4991
4992 ).
4993  Both formats are documented in the documentation of srecord
4994 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4995
4996 \end_inset 
4997
4998
4999 \layout Itemize
5000
5001 sourcefile.adb
5002 \begin_inset LatexCommand \index{<file>.adb}
5003
5004 \end_inset 
5005
5006  - An intermediate file containing debug information needed to create the
5007  .cdb file (with -
5008 \begin_inset ERT
5009 status Collapsed
5010
5011 \layout Standard
5012
5013 \backslash 
5014 /
5015 \end_inset 
5016
5017 -debug
5018 \begin_inset LatexCommand \index{-\/-debug}
5019
5020 \end_inset 
5021
5022
5023 \layout Itemize
5024
5025 sourcefile.cdb
5026 \begin_inset LatexCommand \index{<file>.cdb}
5027
5028 \end_inset 
5029
5030  - An optional file (with -
5031 \begin_inset ERT
5032 status Collapsed
5033
5034 \layout Standard
5035
5036 \backslash 
5037 /
5038 \end_inset 
5039
5040 -debug) containing debug information.
5041  The format is documented in cdbfileformat.pdf
5042 \layout Itemize
5043
5044 sourcefile.
5045  - (no extension)
5046 \begin_inset LatexCommand \index{<file> (no extension)}
5047
5048 \end_inset 
5049
5050  An optional AOMF or AOMF51
5051 \begin_inset LatexCommand \index{AOMF, AOMF51}
5052
5053 \end_inset 
5054
5055  
5056 \begin_inset LatexCommand \label{OMF file}
5057
5058 \end_inset 
5059
5060 file containing debug information (generated with option -
5061 \begin_inset ERT
5062 status Collapsed
5063
5064 \layout Standard
5065
5066 \backslash 
5067 /
5068 \end_inset 
5069
5070 -debug).
5071  The (Intel)
5072 \emph on 
5073  a
5074 \emph default 
5075 bsolute 
5076 \emph on 
5077 o
5078 \emph default 
5079 bject 
5080 \emph on 
5081 m
5082 \emph default 
5083 odule 
5084 \emph on 
5085 f
5086 \emph default 
5087 ormat is commonly used by third party tools (debuggers
5088 \begin_inset LatexCommand \index{Debugger}
5089
5090 \end_inset 
5091
5092 , simulators, emulators)
5093 \layout Itemize
5094
5095 sourcefile.dump*
5096 \begin_inset LatexCommand \index{<file>.dump*}
5097
5098 \end_inset 
5099
5100  - Dump file to debug the compiler it self (generated with option -
5101 \begin_inset ERT
5102 status Collapsed
5103
5104 \layout Standard
5105
5106 \backslash 
5107 /
5108 \end_inset 
5109
5110 -dumpall) (see section 
5111 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5112
5113 \end_inset 
5114
5115 \SpecialChar ~
5116  and section 
5117 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5118
5119 \end_inset 
5120
5121 \SpecialChar ~
5122
5123 \begin_inset Quotes sld
5124 \end_inset 
5125
5126 Anatomy of the compiler
5127 \begin_inset Quotes srd
5128 \end_inset 
5129
5130 ).
5131 \layout Subsection
5132
5133 Postprocessing the Intel Hex
5134 \begin_inset LatexCommand \index{Intel hex format}
5135
5136 \end_inset 
5137
5138  file
5139 \layout Standard
5140
5141 In most cases this won't be needed but the Intel Hex file
5142 \begin_inset LatexCommand \index{<file>.ihx}
5143
5144 \end_inset 
5145
5146  which is generated by SDCC might include lines of varying length and the
5147  addresses within the file are not guaranteed to be strictly ascending.
5148  If your toolchain or a bootloader does not like this you can use the tool
5149  
5150 \family typewriter 
5151 packihx
5152 \family default 
5153
5154 \begin_inset LatexCommand \index{packihx (tool)}
5155
5156 \end_inset 
5157
5158  which is part of the SDCC distribution: 
5159 \newline 
5160
5161 \newline 
5162
5163 \family sans 
5164 \series bold 
5165  packihx sourcefile.ihx >sourcefile.hex
5166 \family default 
5167 \series default 
5168
5169 \newline 
5170
5171 \newline 
5172 The separately available
5173 \emph on 
5174  srecord
5175 \emph default 
5176
5177 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5178
5179 \end_inset 
5180
5181  package additionally allows to set undefined locations to a predefined
5182  value, to insert checksums
5183 \begin_inset LatexCommand \index{checksum}
5184
5185 \end_inset 
5186
5187  of various flavours (crc, add, xor) and to perform other manipulations
5188  (convert, split, crop, offset, ...).
5189  
5190 \newline 
5191
5192 \newline 
5193
5194 \family sans 
5195 \series bold 
5196 srec_cat\SpecialChar ~
5197 \SpecialChar ~
5198 sourcefile.ihx -intel\SpecialChar ~
5199 \SpecialChar ~
5200 -o sourcefile.hex -intel
5201 \newline 
5202
5203 \newline 
5204
5205 \family default 
5206 \series default 
5207 An example for a more complex command line
5208 \begin_inset Foot
5209 collapsed false
5210
5211 \layout Standard
5212
5213 the command backfills
5214 \begin_inset LatexCommand \index{backfill unused memory}
5215
5216 \end_inset 
5217
5218  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5219  block is zero.
5220  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5221  will be interpreted as an 
5222 \family typewriter 
5223 lcall
5224 \family default 
5225  to address 
5226 \family typewriter 
5227 0x1212
5228 \family default 
5229  (where an emergency routine could sit).
5230 \end_inset 
5231
5232  could look like:
5233 \newline 
5234
5235 \newline 
5236
5237 \family sans 
5238 \series bold 
5239 \size footnotesize 
5240 srec_cat\SpecialChar ~
5241 sourcefile.ihx -intel\SpecialChar ~
5242 \SpecialChar ~
5243 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5244 -little-endian-checksum-nega
5245 tive 0xfffe 0x02 0x02\SpecialChar ~
5246 \SpecialChar ~
5247 -o sourcefile.hex -intel
5248 \size default 
5249
5250 \newline 
5251
5252 \newline 
5253
5254 \family default 
5255 \series default 
5256 The srecord package is available at 
5257 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5258
5259 \end_inset 
5260
5261  .
5262 \layout Subsection
5263
5264 Projects with Multiple Source Files
5265 \layout Standard
5266
5267 SDCC can compile only ONE file at a time.
5268  Let us for example assume that you have a project containing the following
5269  files:
5270 \newline 
5271
5272 \newline 
5273 foo1.c (contains some functions)
5274 \newline 
5275 foo2.c (contains some more functions)
5276 \newline 
5277 foomain.c (contains more functions and the function main)
5278 \newline 
5279
5280 \size footnotesize 
5281
5282 \newline 
5283
5284 \size default 
5285 The first two files will need to be compiled separately with the commands:
5286 \size footnotesize 
5287  
5288 \size default 
5289
5290 \newline 
5291
5292 \newline 
5293
5294 \family sans 
5295 \series bold 
5296 sdcc\SpecialChar ~
5297 -c\SpecialChar ~
5298 foo1.c
5299 \family default 
5300 \series default 
5301 \size footnotesize 
5302
5303 \newline 
5304
5305 \family sans 
5306 \series bold 
5307 \size default 
5308 sdcc\SpecialChar ~
5309 -c\SpecialChar ~
5310 foo2.c
5311 \family default 
5312 \series default 
5313
5314 \newline 
5315
5316 \newline 
5317 Then compile the source file containing the 
5318 \emph on 
5319 main()
5320 \emph default 
5321  function and link
5322 \begin_inset LatexCommand \index{Linker}
5323
5324 \end_inset 
5325
5326  the files together with the following command: 
5327 \newline 
5328
5329 \newline 
5330
5331 \family sans 
5332 \series bold 
5333 sdcc\SpecialChar ~
5334 foomain.c\SpecialChar ~
5335 foo1.rel\SpecialChar ~
5336 foo2.rel
5337 \family default 
5338 \series default 
5339
5340 \begin_inset LatexCommand \index{<file>.rel}
5341
5342 \end_inset 
5343
5344
5345 \newline 
5346
5347 \newline 
5348 Alternatively, 
5349 \emph on 
5350 foomain.c 
5351 \emph default 
5352 can be separately compiled as well: 
5353 \family sans 
5354 \series bold 
5355
5356 \newline 
5357
5358 \newline 
5359 sdcc\SpecialChar ~
5360 -c\SpecialChar ~
5361 foomain.c
5362 \newline 
5363 sdcc foomain.rel foo1.rel foo2.rel
5364 \newline 
5365
5366 \newline 
5367
5368 \family default 
5369 \series default 
5370 The file containing the 
5371 \emph on 
5372 main()
5373 \emph default 
5374  function
5375 \emph on 
5376  
5377 \emph default 
5378 \noun on 
5379 must
5380 \noun default 
5381  be the 
5382 \noun on 
5383 first
5384 \noun default 
5385  file specified in the command line, since the linkage editor processes
5386  file in the order they are presented to it.
5387  The linker is invoked from SDCC using a script file with extension .lnk
5388 \begin_inset LatexCommand \index{<file>.lnk}
5389
5390 \end_inset 
5391
5392 .
5393  You can view this file to troubleshoot linking problems such as those arising
5394  from missing libraries.
5395 \layout Subsection
5396
5397 Projects with Additional Libraries
5398 \begin_inset LatexCommand \index{Libraries}
5399
5400 \end_inset 
5401
5402
5403 \layout Standard
5404
5405 Some reusable routines may be compiled into a library, see the documentation
5406  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5407  for how to create a 
5408 \emph on 
5409 .lib
5410 \begin_inset LatexCommand \index{<file>.lib}
5411
5412 \end_inset 
5413
5414
5415 \emph default 
5416  library file.
5417  Libraries created in this manner can be included in the command line.
5418  Make sure you include the -L <library-path> option to tell the linker where
5419  to look for these files if they are not in the current directory.
5420  Here is an example, assuming you have the source file 
5421 \emph on 
5422 foomain.c
5423 \emph default 
5424  and a library
5425 \emph on 
5426  foolib.lib
5427 \emph default 
5428  in the directory 
5429 \emph on 
5430 mylib
5431 \emph default 
5432  (if that is not the same as your current project):
5433 \newline 
5434
5435 \newline 
5436
5437 \family sans 
5438 \series bold 
5439 sdcc foomain.c foolib.lib -L mylib
5440 \newline 
5441
5442 \newline 
5443
5444 \family default 
5445 \series default 
5446 Note here that
5447 \emph on 
5448  mylib
5449 \emph default 
5450  must be an absolute path name.
5451 \newline 
5452
5453 \newline 
5454 The most efficient way to use libraries is to keep separate modules in separate
5455  source files.
5456  The lib file now should name all the modules.rel
5457 \begin_inset LatexCommand \index{<file>.rel}
5458
5459 \end_inset 
5460
5461  files.
5462  For an example see the standard library file 
5463 \emph on 
5464 libsdcc.lib
5465 \emph default 
5466  in the directory <installdir>/share/lib/small.
5467 \layout Subsection
5468
5469 Using sdcclib to Create and Manage Libraries
5470 \begin_inset LatexCommand \index{sdcclib}
5471
5472 \end_inset 
5473
5474
5475 \layout Standard
5476
5477 Alternatively, instead of having a .rel file for each entry on the library
5478  file as described in the preceding section, sdcclib can be used to embed
5479  all the modules belonging to such library in the library file itself.
5480  This results in a larger library file, but it greatly reduces the number
5481  of disk files accessed by the linker.
5482   Additionally, the packed library file contains an index of all include
5483  modules and symbols that significantly speeds up the linking process.
5484  To display a list of options supported by sdcclib type:
5485 \newline 
5486
5487 \layout Standard
5488
5489
5490 \family sans 
5491 \series bold 
5492 sdcclib -?
5493 \begin_inset LatexCommand \index{sdcclib}
5494
5495 \end_inset 
5496
5497
5498 \newline 
5499
5500 \newline 
5501
5502 \family default 
5503 \series default 
5504 To create a new library file, start by compiling all the required modules.
5505  For example:
5506 \newline 
5507
5508 \layout Standard
5509
5510
5511 \family sans 
5512 \series bold 
5513 sdcc -c _divsint.c
5514 \layout Standard
5515
5516
5517 \family sans 
5518 \series bold 
5519 sdcc -c _divuint.c
5520 \layout Standard
5521
5522
5523 \family sans 
5524 \series bold 
5525 sdcc -c _modsint.c
5526 \layout Standard
5527
5528
5529 \family sans 
5530 \series bold 
5531 sdcc -c _moduint.c
5532 \layout Standard
5533
5534
5535 \family sans 
5536 \series bold 
5537 sdcc -c _mulint.c
5538 \newline 
5539
5540 \layout Standard
5541
5542 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5543  and _mulint.rel.
5544  The next step is to add the .rel files to the library file:
5545 \newline 
5546
5547 \layout Standard
5548
5549
5550 \family sans 
5551 \series bold 
5552 sdcclib libint.lib _divsint.rel
5553 \family default 
5554
5555 \begin_inset LatexCommand \index{sdcclib}
5556
5557 \end_inset 
5558
5559
5560 \layout Standard
5561
5562
5563 \family sans 
5564 \series bold 
5565 sdcclib libint.lib _divuint.rel
5566 \layout Standard
5567
5568
5569 \family sans 
5570 \series bold 
5571 sdcclib libint.lib _modsint.rel
5572 \layout Standard
5573
5574
5575 \family sans 
5576 \series bold 
5577 sdcclib libint.lib _moduint.rel
5578 \layout Standard
5579
5580
5581 \family sans 
5582 \series bold 
5583 sdcclib libint.lib _mulint.rel
5584 \series default 
5585
5586 \newline 
5587
5588 \layout Standard
5589
5590 If the file already exists in the library, it will be replaced.
5591  To see what modules and symbols are included in the library, options -s
5592  and -m are available.
5593  For example:
5594 \newline 
5595
5596 \newline 
5597
5598 \family sans 
5599 \series bold 
5600 sdcclib -s libint.lib
5601 \family default 
5602
5603 \begin_inset LatexCommand \index{sdcclib}
5604
5605 \end_inset 
5606
5607
5608 \newline 
5609
5610 \family typewriter 
5611 \series default 
5612 _divsint.rel:
5613 \layout Standard
5614
5615
5616 \family typewriter 
5617 __divsint_a_1_1
5618 \layout Standard
5619
5620
5621 \family typewriter 
5622 __divsint_PARM_2
5623 \layout Standard
5624
5625
5626 \family typewriter 
5627 __divsint
5628 \newline 
5629 _divuint.rel:
5630 \layout Standard
5631
5632
5633 \family typewriter 
5634 __divuint_a_1_1
5635 \layout Standard
5636
5637
5638 \family typewriter 
5639 __divuint_PARM_2
5640 \layout Standard
5641
5642
5643 \family typewriter 
5644 __divuint_reste_1_1
5645 \layout Standard
5646
5647
5648 \family typewriter 
5649 __divuint_count_1_1
5650 \layout Standard
5651
5652
5653 \family typewriter 
5654 __divuint
5655 \newline 
5656 _modsint.rel:
5657 \layout Standard
5658
5659
5660 \family typewriter 
5661 __modsint_a_1_1
5662 \layout Standard
5663
5664
5665 \family typewriter 
5666 __modsint_PARM_2
5667 \layout Standard
5668
5669
5670 \family typewriter 
5671 __modsint
5672 \newline 
5673 _moduint.rel:
5674 \layout Standard
5675
5676
5677 \family typewriter 
5678 __moduint_a_1_1
5679 \layout Standard
5680
5681
5682 \family typewriter 
5683 __moduint_PARM_2
5684 \layout Standard
5685
5686
5687 \family typewriter 
5688 __moduint_count_1_1
5689 \layout Standard
5690
5691
5692 \family typewriter 
5693 __moduint
5694 \newline 
5695 _mulint.rel:
5696 \layout Standard
5697
5698
5699 \family typewriter 
5700 __mulint_PARM_2
5701 \layout Standard
5702
5703
5704 \family typewriter 
5705 __mulint
5706 \family default 
5707 \series bold 
5708
5709 \newline 
5710
5711 \layout Standard
5712 \added_space_bottom bigskip 
5713 If the source files are compiled using -
5714 \begin_inset ERT
5715 status Collapsed
5716
5717 \layout Standard
5718
5719 \backslash 
5720 /
5721 \end_inset 
5722
5723 -debug
5724 \begin_inset LatexCommand \index{-\/-debug}
5725
5726 \end_inset 
5727
5728 , the corresponding debug information file .adb will be include in the library
5729  file as well.
5730  The library files created with sdcclib are plain text files, so they can
5731  be viewed with a text editor.
5732  It is not recomended to modify a library file created with sdcclib using
5733  a text editor, as there are file indexes numbers located accross the file
5734  used by the linker to quickly locate the required module to link.
5735  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5736  it can be safely deleted, since all the information required for linking
5737  is embedded in the library file itself.
5738  Library files created using sdcclib are used as described in the preceding
5739  sections.
5740 \layout Section
5741
5742 Command Line Options
5743 \begin_inset LatexCommand \index{Command Line Options}
5744
5745 \end_inset 
5746
5747
5748 \layout Subsection
5749
5750 Processor Selection Options
5751 \begin_inset LatexCommand \index{Options processor selection}
5752
5753 \end_inset 
5754
5755
5756 \begin_inset LatexCommand \index{Processor selection options}
5757
5758 \end_inset 
5759
5760
5761 \layout List
5762 \labelwidthstring 00.00.0000
5763
5764
5765 \series bold 
5766 -mmcs51
5767 \begin_inset LatexCommand \index{-mmcs51}
5768
5769 \end_inset 
5770
5771
5772 \series default 
5773  Generate code for the Intel MCS51
5774 \begin_inset LatexCommand \index{MCS51}
5775
5776 \end_inset 
5777
5778  family of processors.
5779  This is the default processor target.
5780 \layout List
5781 \labelwidthstring 00.00.0000
5782
5783
5784 \series bold 
5785 -mds390
5786 \begin_inset LatexCommand \index{-mds390}
5787
5788 \end_inset 
5789
5790
5791 \series default 
5792  Generate code for the Dallas DS80C390
5793 \begin_inset LatexCommand \index{DS80C390}
5794
5795 \end_inset 
5796
5797  processor.
5798 \layout List
5799 \labelwidthstring 00.00.0000
5800
5801
5802 \series bold 
5803 -mds400
5804 \begin_inset LatexCommand \index{-mds400}
5805
5806 \end_inset 
5807
5808
5809 \series default 
5810  Generate code for the Dallas DS80C400
5811 \begin_inset LatexCommand \index{DS80C400}
5812
5813 \end_inset 
5814
5815  processor.
5816 \layout List
5817 \labelwidthstring 00.00.0000
5818
5819
5820 \series bold 
5821 -mhc08
5822 \begin_inset LatexCommand \index{-mhc08}
5823
5824 \end_inset 
5825
5826
5827 \series default 
5828  Generate code for the Freescale/Motorola HC08
5829 \begin_inset LatexCommand \index{HC08}
5830
5831 \end_inset 
5832
5833  family of processors.
5834 \layout List
5835 \labelwidthstring 00.00.0000
5836
5837
5838 \series bold 
5839 -mz80
5840 \begin_inset LatexCommand \index{-mz80}
5841
5842 \end_inset 
5843
5844
5845 \series default 
5846  Generate code for the Zilog Z80
5847 \begin_inset LatexCommand \index{Z80}
5848
5849 \end_inset 
5850
5851  family of processors.
5852 \layout List
5853 \labelwidthstring 00.00.0000
5854
5855
5856 \series bold 
5857 -mgbz80
5858 \begin_inset LatexCommand \index{-mgbz80}
5859
5860 \end_inset 
5861
5862
5863 \series default 
5864  Generate code for the GameBoy Z80
5865 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5866
5867 \end_inset 
5868
5869  processor (Not actively maintained).
5870 \layout List
5871 \labelwidthstring 00.00.0000
5872
5873
5874 \series bold 
5875 -mavr
5876 \begin_inset LatexCommand \index{-mavr}
5877
5878 \end_inset 
5879
5880
5881 \series default 
5882  Generate code for the Atmel AVR
5883 \begin_inset LatexCommand \index{AVR}
5884
5885 \end_inset 
5886
5887  processor (Not maintained, not complete).
5888  AVR users should probably have a look at winavr 
5889 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5890
5891 \end_inset 
5892
5893  or 
5894 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5895
5896 \end_inset 
5897
5898 .
5899 \layout Comment
5900
5901 I think it is fair to direct users there for now.
5902  Open source is also about avoiding unnecessary work .
5903  But I didn't find the 'official' link.
5904 \layout List
5905 \labelwidthstring 00.00.0000
5906
5907
5908 \series bold 
5909 -mpic14
5910 \begin_inset LatexCommand \index{-mpic14}
5911
5912 \end_inset 
5913
5914
5915 \series default 
5916  Generate code for the Microchip PIC 14
5917 \begin_inset LatexCommand \index{PIC14}
5918
5919 \end_inset 
5920
5921 -bit processors (p16f84 and variants.
5922  In development, not complete).
5923 \layout Comment
5924
5925 p16f627 p16f628 p16f84 p16f873 p16f877?
5926 \layout List
5927 \labelwidthstring 00.00.0000
5928
5929
5930 \series bold 
5931 -mpic16
5932 \begin_inset LatexCommand \index{-mpic16}
5933
5934 \end_inset 
5935
5936
5937 \series default 
5938  Generate code for the Microchip PIC 16
5939 \begin_inset LatexCommand \index{PIC16}
5940
5941 \end_inset 
5942
5943 -bit processors (p18f452 and variants.
5944  In development, not complete).
5945 \layout List
5946 \labelwidthstring 00.00.0000
5947
5948
5949 \series bold 
5950 -mtlcs900h
5951 \series default 
5952  Generate code for the Toshiba TLCS-900H
5953 \begin_inset LatexCommand \index{TLCS-900H}
5954
5955 \end_inset 
5956
5957  processor (Not maintained, not complete).
5958 \layout List
5959 \added_space_bottom bigskip \labelwidthstring 00.00.0000
5960
5961
5962 \series bold 
5963 -mxa51
5964 \begin_inset LatexCommand \index{-mxa51}
5965
5966 \end_inset 
5967
5968
5969 \series default 
5970  Generate code for the Phillips XA51
5971 \begin_inset LatexCommand \index{XA51}
5972
5973 \end_inset 
5974
5975  processor (Not maintained, not complete).
5976 \layout Subsection
5977
5978 Preprocessor Options
5979 \begin_inset LatexCommand \index{Options preprocessor}
5980
5981 \end_inset 
5982
5983
5984 \begin_inset LatexCommand \index{Preprocessor options}
5985
5986 \end_inset 
5987
5988
5989 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5990
5991 \end_inset 
5992
5993
5994 \layout List
5995 \labelwidthstring 00.00.0000
5996
5997
5998 \series bold 
5999 -I<path>
6000 \begin_inset LatexCommand \index{-I<path>}
6001
6002 \end_inset 
6003
6004
6005 \series default 
6006  The additional location where the pre processor will look for <..h> or 
6007 \begin_inset Quotes eld
6008 \end_inset 
6009
6010 ..h
6011 \begin_inset Quotes erd
6012 \end_inset 
6013
6014  files.
6015 \layout List
6016 \labelwidthstring 00.00.0000
6017
6018
6019 \series bold 
6020 -D<macro[=value]>
6021 \begin_inset LatexCommand \index{-D<macro[=value]>}
6022
6023 \end_inset 
6024
6025
6026 \series default 
6027  Command line definition of macros.
6028  Passed to the preprocessor.
6029 \layout List
6030 \labelwidthstring 00.00.0000
6031
6032
6033 \series bold 
6034 -M
6035 \begin_inset LatexCommand \index{-M}
6036
6037 \end_inset 
6038
6039
6040 \series default 
6041  Tell the preprocessor to output a rule suitable for make describing the
6042  dependencies of each object file.
6043  For each source file, the preprocessor outputs one make-rule whose target
6044  is the object file name for that source file and whose dependencies are
6045  all the files `#include'd in it.
6046  This rule may be a single line or may be continued with `
6047 \backslash 
6048 '-newline if it is long.
6049  The list of rules is printed on standard output instead of the preprocessed
6050  C program.
6051  `-M' implies `-E
6052 \begin_inset LatexCommand \index{-E}
6053
6054 \end_inset 
6055
6056 '.
6057 \layout List
6058 \labelwidthstring 00.00.0000
6059
6060
6061 \series bold 
6062 -C
6063 \begin_inset LatexCommand \index{-C}
6064
6065 \end_inset 
6066
6067
6068 \series default 
6069  Tell the preprocessor not to discard comments.
6070  Used with the `-E' option.
6071 \layout List
6072 \labelwidthstring 00.00.0000
6073
6074
6075 \series bold 
6076 -MM
6077 \begin_inset LatexCommand \index{-MM}
6078
6079 \end_inset 
6080
6081
6082 \size large 
6083 \bar under 
6084  
6085 \series default 
6086 \size default 
6087 \bar default 
6088 Like `-M' but the output mentions only the user header files included with
6089  `#include 
6090 \begin_inset Quotes eld
6091 \end_inset 
6092
6093 file"'.
6094  System header files included with `#include <file>' are omitted.
6095 \layout List
6096 \labelwidthstring 00.00.0000
6097
6098
6099 \series bold 
6100 -Aquestion(answer)
6101 \begin_inset LatexCommand \index{-Aquestion(answer)}
6102
6103 \end_inset 
6104
6105
6106 \series default 
6107  Assert the answer answer for question, in case it is tested with a preprocessor
6108  conditional such as `#if #question(answer)'.
6109  `-A-' disables the standard assertions that normally describe the target
6110  machine.
6111 \layout List
6112 \labelwidthstring 00.00.0000
6113
6114
6115 \series bold 
6116 -Umacro
6117 \begin_inset LatexCommand \index{-Umacro}
6118
6119 \end_inset 
6120
6121
6122 \series default 
6123  Undefine macro macro.
6124  `-U' options are evaluated after all `-D' options, but before any `-include'
6125  and `-imacros' options.
6126 \layout List
6127 \labelwidthstring 00.00.0000
6128
6129
6130 \series bold 
6131 -dM
6132 \begin_inset LatexCommand \index{-dM}
6133
6134 \end_inset 
6135
6136
6137 \series default 
6138  Tell the preprocessor to output only a list of the macro definitions that
6139  are in effect at the end of preprocessing.
6140  Used with the `-E' option.
6141 \layout List
6142 \labelwidthstring 00.00.0000
6143
6144
6145 \series bold 
6146 -dD
6147 \begin_inset LatexCommand \index{-dD}
6148
6149 \end_inset 
6150
6151
6152 \series default 
6153  Tell the preprocessor to pass all macro definitions into the output, in
6154  their proper sequence in the rest of the output.
6155 \layout List
6156 \labelwidthstring 00.00.0000
6157
6158
6159 \series bold 
6160 -dN
6161 \begin_inset LatexCommand \index{-dN}
6162
6163 \end_inset 
6164
6165
6166 \size large 
6167 \bar under 
6168  
6169 \series default 
6170 \size default 
6171 \bar default 
6172 Like `-dD' except that the macro arguments and contents are omitted.
6173  Only `#define name' is included in the output.
6174 \layout List
6175 \labelwidthstring 00.00.0000
6176
6177
6178 \series bold 
6179 -pedantic-parse-number
6180 \begin_inset LatexCommand \index{-pedantic-parse-number}
6181
6182 \end_inset 
6183
6184
6185 \size large 
6186 \bar under 
6187  
6188 \series default 
6189 \size default 
6190 \bar default 
6191 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6192  and the macro LO_B(3) gets expanded.
6193  See also #pragma pedantic_parse_number in section
6194 \begin_inset LatexCommand \ref{sec:Pragmas}
6195
6196 \end_inset 
6197
6198  
6199 \emph on 
6200 Note: this functionality is not in conformance with standard!
6201 \layout List
6202 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6203
6204
6205 \series bold 
6206 -Wp\SpecialChar ~
6207 preprocessorOption[,preprocessorOption]
6208 \series default 
6209
6210 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6211
6212 \end_inset 
6213
6214 ...
6215  Pass the preprocessorOption to the preprocessor 
6216 \family typewriter 
6217 sdcpp
6218 \family default 
6219
6220 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6221
6222 \end_inset 
6223
6224 .
6225  SDCC uses an adapted version of the preprocessor 
6226 \emph on 
6227 cpp
6228 \emph default 
6229  of the GNU Compiler Collection
6230 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6231
6232 \end_inset 
6233
6234  (
6235 \emph on 
6236 gcc
6237 \emph default 
6238  
6239 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6240
6241 \end_inset 
6242
6243 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6244 4.1.1\SpecialChar ~
6245 CPP\SpecialChar ~
6246 Manual
6247  at 
6248 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6249
6250 \end_inset 
6251
6252 .
6253 \layout Subsection
6254
6255 Linker Options
6256 \begin_inset LatexCommand \index{Options linker}
6257
6258 \end_inset 
6259
6260
6261 \begin_inset LatexCommand \index{Linker options}
6262
6263 \end_inset 
6264
6265
6266 \layout List
6267 \labelwidthstring 00.00.0000
6268
6269
6270 \series bold 
6271 -L\SpecialChar ~
6272 -
6273 \series default 
6274
6275 \begin_inset ERT
6276 status Collapsed
6277
6278 \layout Standard
6279
6280 \backslash 
6281 /
6282 \end_inset 
6283
6284
6285 \series bold 
6286 -lib-path
6287 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6288
6289 \end_inset 
6290
6291
6292 \begin_inset LatexCommand \index{-L -\/-lib-path}
6293
6294 \end_inset 
6295
6296
6297 \series default 
6298 \SpecialChar ~
6299 <absolute path to additional libraries> This option is passed to the linkage
6300  editor's additional libraries
6301 \begin_inset LatexCommand \index{Libraries}
6302
6303 \end_inset 
6304
6305  search path.
6306  The path name must be absolute.
6307  Additional library files may be specified in the command line.
6308  See section Compiling programs for more details.
6309 \layout List
6310 \labelwidthstring 00.00.0000
6311
6312
6313 \series bold 
6314 -
6315 \begin_inset ERT
6316 status Collapsed
6317
6318 \layout Standard
6319
6320 \backslash 
6321 /
6322 \end_inset 
6323
6324 -xram-loc
6325 \series default 
6326
6327 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6328
6329 \end_inset 
6330
6331 \SpecialChar ~
6332 <Value> The start location of the external ram
6333 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6334
6335 \end_inset 
6336
6337 , default value is 0.
6338  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6339 \begin_inset ERT
6340 status Collapsed
6341
6342 \layout Standard
6343
6344 \backslash 
6345 /
6346 \end_inset 
6347
6348 -xram-loc 0x8000 or -
6349 \begin_inset ERT
6350 status Collapsed
6351
6352 \layout Standard
6353
6354 \backslash 
6355 /
6356 \end_inset 
6357
6358 -xram-loc 32768.
6359 \layout List
6360 \labelwidthstring 00.00.0000
6361
6362
6363 \series bold 
6364 -
6365 \begin_inset ERT
6366 status Collapsed
6367
6368 \layout Standard
6369
6370 \backslash 
6371 /
6372 \end_inset 
6373
6374 -code-loc
6375 \series default 
6376
6377 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6378
6379 \end_inset 
6380
6381 \SpecialChar ~
6382 <Value> The start location of the code
6383 \begin_inset LatexCommand \index{code}
6384
6385 \end_inset 
6386
6387  segment, default value 0.
6388  Note when this option is used the interrupt vector table
6389 \begin_inset LatexCommand \index{interrupt vector table}
6390
6391 \end_inset 
6392
6393  is also relocated to the given address.
6394  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6395 \begin_inset ERT
6396 status Collapsed
6397
6398 \layout Standard
6399
6400 \backslash 
6401 /
6402 \end_inset 
6403
6404 -code-loc 0x8000 or -
6405 \begin_inset ERT
6406 status Collapsed
6407
6408 \layout Standard
6409
6410 \backslash 
6411 /
6412 \end_inset 
6413
6414 -code-loc 32768.
6415 \layout List
6416 \labelwidthstring 00.00.0000
6417
6418
6419 \series bold 
6420 -
6421 \begin_inset ERT
6422 status Collapsed
6423
6424 \layout Standard
6425
6426 \backslash 
6427 /
6428 \end_inset 
6429
6430 -stack-loc
6431 \series default 
6432
6433 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6434
6435 \end_inset 
6436
6437 \SpecialChar ~
6438 <Value> By default the stack
6439 \begin_inset LatexCommand \index{stack}
6440
6441 \end_inset 
6442
6443  is placed after the data segment.
6444  Using this option the stack can be placed anywhere in the internal memory
6445  space of the 8051.
6446  The value entered can be in Hexadecimal or Decimal format, e.g.
6447  -
6448 \begin_inset ERT
6449 status Collapsed
6450
6451 \layout Standard
6452
6453 \backslash 
6454 /
6455 \end_inset 
6456
6457 -stack-loc 0x20 or -
6458 \begin_inset ERT
6459 status Collapsed
6460
6461 \layout Standard
6462
6463 \backslash 
6464 /
6465 \end_inset 
6466
6467 -stack-loc 32.
6468  Since the sp register is incremented before a push or call, the initial
6469  sp will be set to one byte prior the provided value.
6470  The provided value should not overlap any other memory areas such as used
6471  register banks or the data segment and with enough space for the current
6472  application.
6473  The 
6474 \series bold 
6475 -
6476 \begin_inset ERT
6477 status Collapsed
6478
6479 \layout Standard
6480
6481 \backslash 
6482 /
6483 \end_inset 
6484
6485 -pack-iram
6486 \series default 
6487 \SpecialChar ~
6488
6489 \begin_inset LatexCommand \index{-\/-pack-iram}
6490
6491 \end_inset 
6492
6493  option (which is now a default setting) will override this setting, so
6494  you should also specify the 
6495 \series bold 
6496 -
6497 \begin_inset ERT
6498 status Collapsed
6499
6500 \layout Standard
6501
6502 \backslash 
6503 /
6504 \end_inset 
6505
6506 -no-pack-iram
6507 \series default 
6508 \SpecialChar ~
6509
6510 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6511
6512 \end_inset 
6513
6514  option if you need to manually place the stack.
6515 \layout List
6516 \labelwidthstring 00.00.0000
6517
6518
6519 \series bold 
6520 -
6521 \begin_inset ERT
6522 status Collapsed
6523
6524 \layout Standard
6525
6526 \backslash 
6527 /
6528 \end_inset 
6529
6530 -xstack-loc
6531 \series default 
6532
6533 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6534
6535 \end_inset 
6536
6537 \SpecialChar ~
6538 <Value> By default the external stack
6539 \begin_inset LatexCommand \index{xstack}
6540
6541 \end_inset 
6542
6543  is placed after the pdata
6544 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6545
6546 \end_inset 
6547
6548  segment.
6549  Using this option the xstack can be placed anywhere in the external memory
6550  space of the 8051.
6551  The value entered can be in Hexadecimal or Decimal format, e.g.
6552  -
6553 \begin_inset ERT
6554 status Collapsed
6555
6556 \layout Standard
6557
6558 \backslash 
6559 /
6560 \end_inset 
6561
6562 -xstack-loc 0x8000 or -
6563 \begin_inset ERT
6564 status Collapsed
6565
6566 \layout Standard
6567
6568 \backslash 
6569 /
6570 \end_inset 
6571
6572 -stack-loc 32768.
6573  The provided value should not overlap any other memory areas such as the
6574  pdata or xdata segment and with enough space for the current application.
6575 \layout List
6576 \labelwidthstring 00.00.0000
6577
6578
6579 \series bold 
6580 -
6581 \begin_inset ERT
6582 status Collapsed
6583
6584 \layout Standard
6585
6586 \backslash 
6587 /
6588 \end_inset 
6589
6590 -data-loc
6591 \series default 
6592
6593 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6594
6595 \end_inset 
6596
6597 \SpecialChar ~
6598 <Value> The start location of the internal ram data
6599 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6600
6601 \end_inset 
6602
6603  segment.
6604  The value entered can be in Hexadecimal or Decimal format, eg.
6605  -
6606 \begin_inset ERT
6607 status Collapsed
6608
6609 \layout Standard
6610
6611 \backslash 
6612 /
6613 \end_inset 
6614
6615 -data-loc 0x20 or -
6616 \begin_inset ERT
6617 status Collapsed
6618
6619 \layout Standard
6620
6621 \backslash 
6622 /
6623 \end_inset 
6624
6625 -data-loc 32.
6626  (By default, the start location of the internal ram data segment  is set
6627  as low as possible in memory, taking into account the used register banks
6628  and the bit segment at address 0x20.
6629  For example if register banks 0 and 1 are used without bit variables, the
6630  data segment will be set, if -
6631 \begin_inset ERT
6632 status Collapsed
6633
6634 \layout Standard
6635
6636 \backslash 
6637 /
6638 \end_inset 
6639
6640 -data-loc is not used, to location 0x10.)
6641 \layout List
6642 \labelwidthstring 00.00.0000
6643
6644
6645 \series bold 
6646 -
6647 \begin_inset ERT
6648 status Collapsed
6649
6650 \layout Standard
6651
6652 \backslash 
6653 /
6654 \end_inset 
6655
6656 -idata-loc
6657 \series default 
6658
6659 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6660
6661 \end_inset 
6662
6663 \SpecialChar ~
6664 <Value> The start location of the indirectly addressable internal ram
6665 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6666
6667 \end_inset 
6668
6669  of the 8051, default value is 0x80.
6670  The value entered can be in Hexadecimal or Decimal format, eg.
6671  -
6672 \begin_inset ERT
6673 status Collapsed
6674
6675 \layout Standard
6676
6677 \backslash 
6678 /
6679 \end_inset 
6680
6681 -idata-loc 0x88 or -
6682 \begin_inset ERT
6683 status Collapsed
6684
6685 \layout Standard
6686
6687 \backslash 
6688 /
6689 \end_inset 
6690
6691 -idata-loc 136.
6692 \layout List
6693 \labelwidthstring 00.00.0000
6694
6695
6696 \series bold 
6697 -
6698 \begin_inset ERT
6699 status Collapsed
6700
6701 \layout Standard
6702
6703 \backslash 
6704 /
6705 \end_inset 
6706
6707 -bit-loc
6708 \series default 
6709 \SpecialChar ~
6710 <Value> The start location of the bit
6711 \begin_inset LatexCommand \index{bit}
6712
6713 \end_inset 
6714
6715  addressable internal ram of the 8051.
6716  This is 
6717 \emph on 
6718 not
6719 \emph default 
6720  implemented yet.
6721  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6722 -bBSEG=<Value>.
6723 \layout List
6724 \labelwidthstring 00.00.0000
6725
6726
6727 \series bold 
6728 -
6729 \begin_inset ERT
6730 status Collapsed
6731
6732 \layout Standard
6733
6734 \backslash 
6735 /
6736 \end_inset 
6737
6738 -out-fmt-ihx
6739 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6740
6741 \end_inset 
6742
6743
6744 \bar under 
6745  
6746 \series default 
6747 \bar default 
6748 The linker output (final object code) is in Intel Hex format.
6749 \begin_inset LatexCommand \index{Intel hex format}
6750
6751 \end_inset 
6752
6753  This is the default option.
6754  The format itself is documented in the documentation of srecord
6755 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6756
6757 \end_inset 
6758
6759 .
6760 \layout List
6761 \labelwidthstring 00.00.0000
6762
6763
6764 \series bold 
6765 -
6766 \begin_inset ERT
6767 status Collapsed
6768
6769 \layout Standard
6770
6771 \backslash 
6772 /
6773 \end_inset 
6774
6775 -out-fmt-s19
6776 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6777
6778 \end_inset 
6779
6780
6781 \bar under 
6782  
6783 \series default 
6784 \bar default 
6785 The linker output (final object code) is in Motorola S19 format
6786 \begin_inset LatexCommand \index{Motorola S19 format}
6787
6788 \end_inset 
6789
6790 .
6791  The format itself is documented in the documentation of srecord.
6792 \layout List
6793 \labelwidthstring 00.00.0000
6794
6795
6796 \series bold 
6797 -
6798 \begin_inset ERT
6799 status Collapsed
6800
6801 \layout Standard
6802
6803 \backslash 
6804 /
6805 \end_inset 
6806
6807 -out-fmt-elf
6808 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6809
6810 \end_inset 
6811
6812
6813 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6814
6815 \end_inset 
6816
6817
6818 \bar under 
6819  
6820 \series default 
6821 \bar default 
6822 The linker output (final object code) is in ELF format
6823 \begin_inset LatexCommand \index{ELF format}
6824
6825 \end_inset 
6826
6827 .
6828  (Currently only supported for the HC08
6829 \begin_inset LatexCommand \index{HC08}
6830
6831 \end_inset 
6832
6833  processors)
6834 \layout List
6835 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6836
6837
6838 \series bold 
6839 -Wl\SpecialChar ~
6840 linkOption[,linkOption]
6841 \series default 
6842
6843 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6844
6845 \end_inset 
6846
6847 ...
6848  Pass the linkOption to the linker.
6849  If a bootloader is used an option like 
6850 \begin_inset Quotes sld
6851 \end_inset 
6852
6853 -Wl\SpecialChar ~
6854 -bCSEG=0x1000
6855 \begin_inset Quotes srd
6856 \end_inset 
6857
6858  would be typical to set the start of the code segment.
6859  See also #pragma constseg and #pragma codeseg in section 
6860 \begin_inset LatexCommand \ref{sec:Pragmas}
6861
6862 \end_inset 
6863
6864  .
6865  File sdcc/as/doc/asxhtm.html has more on linker options.
6866 \layout Subsection
6867
6868 MCS51 Options
6869 \begin_inset LatexCommand \index{Options MCS51}
6870
6871 \end_inset 
6872
6873
6874 \begin_inset LatexCommand \index{MCS51 options}
6875
6876 \end_inset 
6877
6878
6879 \layout List
6880 \labelwidthstring 00.00.0000
6881
6882
6883 \series bold 
6884 -
6885 \begin_inset ERT
6886 status Collapsed
6887
6888 \layout Standard
6889
6890 \backslash 
6891 /
6892 \end_inset 
6893
6894 -model-small
6895 \begin_inset LatexCommand \index{-\/-model-small}
6896
6897 \end_inset 
6898
6899
6900 \series default 
6901 \size large 
6902 \emph on 
6903  
6904 \size default 
6905 \emph default 
6906 Generate code for Small Model programs, see section Memory Models for more
6907  details.
6908  This is the default model.
6909 \layout List
6910 \labelwidthstring 00.00.0000
6911
6912
6913 \series bold 
6914 -
6915 \begin_inset ERT
6916 status Collapsed
6917
6918 \layout Standard
6919
6920 \backslash 
6921 /
6922 \end_inset 
6923
6924 -model-medium
6925 \begin_inset LatexCommand \index{-\/-model-medium}
6926
6927 \end_inset 
6928
6929
6930 \series default 
6931  Generate code for Medium model programs, see section Memory Models for
6932  more details.
6933  If this option is used all source files in the project have to be compiled
6934  with this option.
6935  It must also be used when invoking the linker.
6936 \layout List
6937 \labelwidthstring 00.00.0000
6938
6939
6940 \series bold 
6941 -
6942 \begin_inset ERT
6943 status Collapsed
6944
6945 \layout Standard
6946
6947 \backslash 
6948 /
6949 \end_inset 
6950
6951 -model-large
6952 \begin_inset LatexCommand \index{-\/-model-large}
6953
6954 \end_inset 
6955
6956
6957 \series default 
6958  Generate code for Large model programs, see section Memory Models for more
6959  details.
6960  If this option is used all source files in the project have to be compiled
6961  with this option.
6962  It must also be used when invoking the linker.
6963 \layout List
6964 \labelwidthstring 00.00.0000
6965
6966
6967 \series bold 
6968 -
6969 \begin_inset ERT
6970 status Collapsed
6971
6972 \layout Standard
6973
6974 \backslash 
6975 /
6976 \end_inset 
6977
6978 -xstack
6979 \begin_inset LatexCommand \index{-\/-xstack}
6980
6981 \end_inset 
6982
6983
6984 \series default 
6985  Uses a pseudo stack in the pdata
6986 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6987
6988 \end_inset 
6989
6990  area (usually the first 256 bytes in the external ram) for allocating variables
6991  and passing parameters.
6992  See section 
6993 \begin_inset LatexCommand \ref{sub:External-Stack}
6994
6995 \end_inset 
6996
6997 \SpecialChar ~
6998  External Stack for more details.
6999 \layout List
7000 \labelwidthstring 00.00.0000
7001
7002
7003 \series bold 
7004 -
7005 \begin_inset ERT
7006 status Collapsed
7007
7008 \layout Standard
7009
7010 \backslash 
7011 /
7012 \end_inset 
7013
7014 -iram-size
7015 \series default 
7016 \SpecialChar ~
7017 <Value>
7018 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7019
7020 \end_inset 
7021
7022  Causes the linker to check if the internal ram usage is within limits of
7023  the given value.
7024 \layout List
7025 \labelwidthstring 00.00.0000
7026
7027
7028 \series bold 
7029 -
7030 \begin_inset ERT
7031 status Collapsed
7032
7033 \layout Standard
7034
7035 \backslash 
7036 /
7037 \end_inset 
7038
7039 -xram-size
7040 \series default 
7041 \SpecialChar ~
7042 <Value>
7043 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7044
7045 \end_inset 
7046
7047  Causes the linker to check if the external ram usage is within limits of
7048  the given value.
7049 \layout List
7050 \labelwidthstring 00.00.0000
7051
7052
7053 \series bold 
7054 -
7055 \begin_inset ERT
7056 status Collapsed
7057
7058 \layout Standard
7059
7060 \backslash 
7061 /
7062 \end_inset 
7063
7064 -code-size
7065 \series default 
7066 \SpecialChar ~
7067 <Value>
7068 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7069
7070 \end_inset 
7071
7072  Causes the linker to check if the code memory usage is within limits of
7073  the given value.
7074 \layout List
7075 \labelwidthstring 00.00.0000
7076
7077
7078 \series bold 
7079 -
7080 \begin_inset ERT
7081 status Collapsed
7082
7083 \layout Standard
7084
7085 \backslash 
7086 /
7087 \end_inset 
7088
7089 -stack-size
7090 \series default 
7091 \SpecialChar ~
7092 <Value>
7093 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7094
7095 \end_inset 
7096
7097  Causes the linker to check if there is at minimum <Value> bytes for stack.
7098 \layout List
7099 \labelwidthstring 00.00.0000
7100
7101
7102 \series bold 
7103 -
7104 \begin_inset ERT
7105 status Collapsed
7106
7107 \layout Standard
7108
7109 \backslash 
7110 /
7111 \end_inset 
7112
7113 -pack-iram
7114 \series default 
7115 \SpecialChar ~
7116
7117 \begin_inset LatexCommand \index{-\/-pack-iram}
7118
7119 \end_inset 
7120
7121  Causes the linker to use unused register banks for data variables and pack
7122  data, idata and stack together.
7123  This is the default now.
7124 \layout List
7125 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7126
7127
7128 \series bold 
7129 -
7130 \begin_inset ERT
7131 status Collapsed
7132
7133 \layout Standard
7134
7135 \backslash 
7136 /
7137 \end_inset 
7138
7139 -no-pack-iram
7140 \series default 
7141 \SpecialChar ~
7142
7143 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7144
7145 \end_inset 
7146
7147  Causes the linker to use old style for allocating memory areas.
7148 \layout Subsection
7149
7150 DS390 / DS400 Options
7151 \begin_inset LatexCommand \index{Options DS390}
7152
7153 \end_inset 
7154
7155
7156 \begin_inset LatexCommand \index{DS390}
7157
7158 \end_inset 
7159
7160
7161 \layout List
7162 \labelwidthstring 00.00.0000
7163
7164
7165 \series bold 
7166 -
7167 \begin_inset ERT
7168 status Collapsed
7169
7170 \layout Standard
7171
7172 \backslash 
7173 /
7174 \end_inset 
7175
7176 -model-flat24
7177 \series default 
7178
7179 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7180
7181 \end_inset 
7182
7183
7184 \size large 
7185 \emph on 
7186  
7187 \size default 
7188 \emph default 
7189 Generate 24-bit flat mode code.
7190  This is the one and only that the ds390 code generator supports right now
7191  and is default when using 
7192 \emph on 
7193 -mds390
7194 \emph default 
7195 .
7196  See section Memory Models for more details.
7197 \layout List
7198 \labelwidthstring 00.00.0000
7199
7200
7201 \series bold 
7202 -
7203 \begin_inset ERT
7204 status Collapsed
7205
7206 \layout Standard
7207
7208 \backslash 
7209 /
7210 \end_inset 
7211
7212 -protect-sp-update
7213 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7214
7215 \end_inset 
7216
7217
7218 \series default 
7219  disable interrupts during ESP:SP updates.
7220 \layout List
7221 \labelwidthstring 00.00.0000
7222
7223
7224 \series bold 
7225 -
7226 \begin_inset ERT
7227 status Collapsed
7228
7229 \layout Standard
7230
7231 \backslash 
7232 /
7233 \end_inset 
7234
7235 -stack-10bit
7236 \series default 
7237
7238 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7239
7240 \end_inset 
7241
7242  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7243  This is the one and only that the ds390 code generator supports right now
7244  and is default when using 
7245 \emph on 
7246 -mds390
7247 \emph default 
7248 .
7249  In this mode, the stack is located in the lower 1K of the internal RAM,
7250  which is mapped to 0x400000.
7251  Note that the support is incomplete, since it still uses a single byte
7252  as the stack pointer.
7253  This means that only the lower 256 bytes of the potential 1K stack space
7254  will actually be used.
7255  However, this does allow you to reclaim the precious 256 bytes of low RAM
7256  for use for the DATA and IDATA segments.
7257  The compiler will not generate any code to put the processor into 10 bit
7258  stack mode.
7259  It is important to ensure that the processor is in this mode before calling
7260  any re-entrant functions compiled with this option.
7261  In principle, this should work with the 
7262 \emph on 
7263 -
7264 \begin_inset ERT
7265 status Collapsed
7266
7267 \layout Standard
7268
7269 \backslash 
7270 /
7271 \end_inset 
7272
7273 -stack-auto
7274 \begin_inset LatexCommand \index{-\/-stack-auto}
7275
7276 \end_inset 
7277
7278
7279 \emph default 
7280  option, but that has not been tested.
7281  It is incompatible with the 
7282 \emph on 
7283 -
7284 \begin_inset ERT
7285 status Collapsed
7286
7287 \layout Standard
7288
7289 \backslash 
7290 /
7291 \end_inset 
7292
7293 -xstack
7294 \begin_inset LatexCommand \index{-\/-xstack}
7295
7296 \end_inset 
7297
7298
7299 \emph default 
7300  option.
7301  It also only makes sense if the processor is in 24 bit contiguous addressing
7302  mode (see the 
7303 \emph on 
7304 -
7305 \begin_inset ERT
7306 status Collapsed
7307
7308 \layout Standard
7309
7310 \backslash 
7311 /
7312 \end_inset 
7313
7314 -model-flat24 option
7315 \emph default 
7316 ).
7317 \layout List
7318 \labelwidthstring 00.00.0000
7319
7320
7321 \series bold 
7322 -
7323 \begin_inset ERT
7324 status Collapsed
7325
7326 \layout Standard
7327
7328 \backslash 
7329 /
7330 \end_inset 
7331
7332 -stack-probe
7333 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7334
7335 \end_inset 
7336
7337
7338 \series default 
7339  insert call to function __stack_probe at each function prologue.
7340 \layout List
7341 \labelwidthstring 00.00.0000
7342
7343
7344 \series bold 
7345 -
7346 \begin_inset ERT
7347 status Collapsed
7348
7349 \layout Standard
7350
7351 \backslash 
7352 /
7353 \end_inset 
7354
7355 -tini-libid
7356 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7357
7358 \end_inset 
7359
7360
7361 \series default 
7362  <nnnn> LibraryID used in -mTININative.
7363  
7364 \layout List
7365 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7366
7367
7368 \series bold 
7369 -
7370 \begin_inset ERT
7371 status Collapsed
7372
7373 \layout Standard
7374
7375 \backslash 
7376 /
7377 \end_inset 
7378
7379 -use-accelerator
7380 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7381
7382 \end_inset 
7383
7384
7385 \series default 
7386  generate code for DS390 Arithmetic Accelerator.
7387  
7388 \layout Subsection
7389
7390 Z80 Options
7391 \begin_inset LatexCommand \index{Options Z80}
7392
7393 \end_inset 
7394
7395
7396 \begin_inset LatexCommand \index{Z80}
7397
7398 \end_inset 
7399
7400
7401 \layout List
7402 \labelwidthstring 00.00.0000
7403
7404
7405 \series bold 
7406 -
7407 \begin_inset ERT
7408 status Collapsed
7409
7410 \layout Standard
7411
7412 \backslash 
7413 /
7414 \end_inset 
7415
7416 -callee-saves-bc
7417 \series default 
7418
7419 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7420
7421 \end_inset 
7422
7423
7424 \size large 
7425 \emph on 
7426  
7427 \size default 
7428 \emph default 
7429 Force a called function to always save BC.
7430 \layout List
7431 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7432
7433
7434 \series bold 
7435 -
7436 \begin_inset ERT
7437 status Collapsed
7438
7439 \layout Standard
7440
7441 \backslash 
7442 /
7443 \end_inset 
7444
7445 -no-std-crt0
7446 \series default 
7447
7448 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7449
7450 \end_inset 
7451
7452  When linking, skip the standard crt0.o object file.
7453  You must provide your own crt0.o for your system when linking.
7454  
7455 \layout Subsection
7456
7457 Optimization Options
7458 \begin_inset LatexCommand \index{Options optimization}
7459
7460 \end_inset 
7461
7462
7463 \begin_inset LatexCommand \index{Optimization options}
7464
7465 \end_inset 
7466
7467
7468 \layout List
7469 \labelwidthstring 00.00.0000
7470
7471
7472 \series bold 
7473 -
7474 \begin_inset ERT
7475 status Collapsed
7476
7477 \layout Standard
7478
7479 \backslash 
7480 /
7481 \end_inset 
7482
7483 -nogcse
7484 \begin_inset LatexCommand \index{-\/-nogcse}
7485
7486 \end_inset 
7487
7488
7489 \series default 
7490  Will not do global subexpression elimination, this option may be used when
7491  the compiler creates undesirably large stack/data spaces to store compiler
7492  temporaries (
7493 \emph on 
7494 s
7495 \emph default 
7496 pill 
7497 \emph on 
7498 loc
7499 \emph default 
7500 ations, sloc
7501 \begin_inset LatexCommand \index{sloc (spill location)}
7502
7503 \end_inset 
7504
7505 ).
7506  A warning message will be generated when this happens and the compiler
7507  will indicate the number of extra bytes it allocated.
7508  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7509 nogcse
7510 \begin_inset LatexCommand \index{\#pragma nogcse}
7511
7512 \end_inset 
7513
7514  can be used to turn off global subexpression elimination
7515 \begin_inset LatexCommand \index{Subexpression elimination}
7516
7517 \end_inset 
7518
7519  for a given function only.
7520 \layout List
7521 \labelwidthstring 00.00.0000
7522
7523
7524 \series bold 
7525 -
7526 \begin_inset ERT
7527 status Collapsed
7528
7529 \layout Standard
7530
7531 \backslash 
7532 /
7533 \end_inset 
7534
7535 -noinvariant
7536 \begin_inset LatexCommand \index{-\/-noinvariant}
7537
7538 \end_inset 
7539
7540
7541 \series default 
7542  Will not do loop invariant optimizations, this may be turned off for reasons
7543  explained for the previous option.
7544  For more details of loop optimizations performed see Loop Invariants in
7545  section 
7546 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7547
7548 \end_inset 
7549
7550 .
7551  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7552 noinvariant
7553 \begin_inset LatexCommand \index{\#pragma noinvariant}
7554
7555 \end_inset 
7556
7557  can be used to turn off invariant optimizations for a given function only.
7558 \layout List
7559 \labelwidthstring 00.00.0000
7560
7561
7562 \series bold 
7563 -
7564 \begin_inset ERT
7565 status Collapsed
7566
7567 \layout Standard
7568
7569 \backslash 
7570 /
7571 \end_inset 
7572
7573 -noinduction
7574 \begin_inset LatexCommand \index{-\/-noinduction}
7575
7576 \end_inset 
7577
7578
7579 \series default 
7580  Will not do loop induction optimizations, see section strength reduction
7581  for more details.
7582  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7583 noinduction
7584 \begin_inset LatexCommand \index{\#pragma noinduction}
7585
7586 \end_inset 
7587
7588  can be used to turn off induction optimizations for a given function only.
7589 \layout List
7590 \labelwidthstring 00.00.0000
7591
7592
7593 \series bold 
7594 -
7595 \begin_inset ERT
7596 status Collapsed
7597
7598 \layout Standard
7599
7600 \backslash 
7601 /
7602 \end_inset 
7603
7604 -nojtbound
7605 \begin_inset LatexCommand \index{-\/-nojtbound}
7606
7607 \end_inset 
7608
7609
7610 \size large 
7611 \bar under 
7612  
7613 \series default 
7614 \size default 
7615 \bar default 
7616  Will not generate boundary condition check when switch statements
7617 \begin_inset LatexCommand \index{switch statement}
7618
7619 \end_inset 
7620
7621  are implemented using jump-tables.
7622  See section 
7623 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7624
7625 \end_inset 
7626
7627 \SpecialChar ~
7628 Switch Statements for more details.
7629  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7630 nojtbound
7631 \begin_inset LatexCommand \index{\#pragma nojtbound}
7632
7633 \end_inset 
7634
7635  can be used to turn off boundary checking for jump tables for a given function
7636  only.
7637 \layout List
7638 \labelwidthstring 00.00.0000
7639
7640
7641 \series bold 
7642 -
7643 \begin_inset ERT
7644 status Collapsed
7645
7646 \layout Standard
7647
7648 \backslash 
7649 /
7650 \end_inset 
7651
7652 -noloopreverse
7653 \begin_inset LatexCommand \index{-\/-noloopreverse}
7654
7655 \end_inset 
7656
7657
7658 \series default 
7659 \size large 
7660  
7661 \size default 
7662 Will not do loop reversal 
7663 \begin_inset LatexCommand \index{Loop reversing}
7664
7665 \end_inset 
7666
7667 optimization.
7668 \layout List
7669 \labelwidthstring 00.00.0000
7670
7671 -
7672 \begin_inset ERT
7673 status Collapsed
7674
7675 \layout Standard
7676
7677 \backslash 
7678 /
7679 \end_inset 
7680
7681 -
7682 \series bold 
7683 nolabelopt
7684 \series default 
7685  
7686 \begin_inset LatexCommand \index{-\/-nolabelopt }
7687
7688 \end_inset 
7689
7690 Will not optimize labels (makes the dumpfiles more readable).
7691 \layout List
7692 \labelwidthstring 00.00.0000
7693
7694
7695 \series bold 
7696 -
7697 \begin_inset ERT
7698 status Collapsed
7699
7700 \layout Standard
7701
7702 \backslash 
7703 /
7704 \end_inset 
7705
7706 -no-xinit-opt
7707 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7708
7709 \end_inset 
7710
7711
7712 \series default 
7713  Will not memcpy initialized data from code space into xdata space.
7714  This saves a few bytes in code space if you don't have initialized data
7715 \begin_inset LatexCommand \index{Variable initialization}
7716
7717 \end_inset 
7718
7719 .
7720 \layout List
7721 \labelwidthstring 00.00.0000
7722
7723
7724 \series bold 
7725 -
7726 \begin_inset ERT
7727 status Collapsed
7728
7729 \layout Standard
7730
7731 \backslash 
7732 /
7733 \end_inset 
7734
7735 -nooverlay
7736 \begin_inset LatexCommand \index{-\/-nooverlay}
7737
7738 \end_inset 
7739
7740
7741 \series default 
7742   The compiler will not overlay parameters and local variables of any function,
7743  see section Parameters and local variables for more details.
7744 \layout List
7745 \labelwidthstring 00.00.0000
7746
7747
7748 \series bold 
7749 -
7750 \begin_inset ERT
7751 status Collapsed
7752
7753 \layout Standard
7754
7755 \backslash 
7756 /
7757 \end_inset 
7758
7759 -no-peep
7760 \begin_inset LatexCommand \index{-\/-no-peep}
7761
7762 \end_inset 
7763
7764
7765 \series default 
7766  Disable peep-hole optimization with built-in rules.
7767 \layout List
7768 \labelwidthstring 00.00.0000
7769
7770
7771 \series bold 
7772 -
7773 \begin_inset ERT
7774 status Collapsed
7775
7776 \layout Standard
7777
7778 \backslash 
7779 /
7780 \end_inset 
7781
7782 -peep-file
7783 \series default 
7784
7785 \begin_inset LatexCommand \index{-\/-peep-file}
7786
7787 \end_inset 
7788
7789 \SpecialChar ~
7790 <filename> This option can be used to use additional rules to be used by
7791  the peep hole optimizer.
7792  See section 
7793 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7794
7795 \end_inset 
7796
7797 \SpecialChar ~
7798 Peep Hole optimizations for details on how to write these rules.
7799 \layout List
7800 \labelwidthstring 00.00.0000
7801
7802
7803 \series bold 
7804 -
7805 \begin_inset ERT
7806 status Collapsed
7807
7808 \layout Standard
7809
7810 \backslash 
7811 /
7812 \end_inset 
7813
7814 -peep-asm
7815 \begin_inset LatexCommand \index{-\/-peep-asm}
7816
7817 \end_inset 
7818
7819
7820 \series default 
7821  Pass the inline assembler code through the peep hole optimizer.
7822  This can cause unexpected changes to inline assembler code, please go through
7823  the peephole optimizer
7824 \begin_inset LatexCommand \index{Peephole optimizer}
7825
7826 \end_inset 
7827
7828  rules defined in the source file tree '<target>/peeph.def' before using
7829  this option.
7830 \layout List
7831 \labelwidthstring 00.00.0000
7832
7833
7834 \series bold 
7835 -
7836 \begin_inset ERT
7837 status Collapsed
7838
7839 \layout Standard
7840
7841 \backslash 
7842 /
7843 \end_inset 
7844
7845 -opt-code-speed
7846 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7847
7848 \end_inset 
7849
7850
7851 \series default 
7852  The compiler will optimize code generation towards fast code, possibly
7853  at the expense of code size.
7854 \layout List
7855 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7856
7857
7858 \series bold 
7859 -
7860 \begin_inset ERT
7861 status Collapsed
7862
7863 \layout Standard
7864
7865 \backslash 
7866 /
7867 \end_inset 
7868
7869 -opt-code-size
7870 \begin_inset LatexCommand \index{-\/-opt-code-size}
7871
7872 \end_inset 
7873
7874
7875 \series default 
7876  The compiler will optimize code generation towards compact code, possibly
7877  at the expense of code speed.
7878 \layout Subsection
7879
7880 Other Options
7881 \begin_inset LatexCommand \index{Options other}
7882
7883 \end_inset 
7884
7885
7886 \layout List
7887 \labelwidthstring 00.00.0000
7888
7889
7890 \series bold 
7891 -c\SpecialChar ~
7892 -
7893 \begin_inset ERT
7894 status Collapsed
7895
7896 \layout Standard
7897
7898 \backslash 
7899 /
7900 \end_inset 
7901
7902 -compile-only
7903 \begin_inset LatexCommand \index{-\/-compile-only}
7904
7905 \end_inset 
7906
7907
7908 \begin_inset LatexCommand \index{-c -\/-compile-only}
7909
7910 \end_inset 
7911
7912
7913 \series default 
7914  will compile and assemble the source, but will not call the linkage editor.
7915 \layout List
7916 \labelwidthstring 00.00.0000
7917
7918
7919 \series bold 
7920 -
7921 \series default 
7922
7923 \begin_inset ERT
7924 status Collapsed
7925
7926 \layout Standard
7927
7928 \backslash 
7929 /
7930 \end_inset 
7931
7932
7933 \series bold 
7934 -c1mode
7935 \begin_inset LatexCommand \index{-\/-c1mode}
7936
7937 \end_inset 
7938
7939
7940 \series default 
7941  reads the preprocessed source from standard input and compiles it.
7942  The file name for the assembler output must be specified using the -o option.
7943 \layout List
7944 \labelwidthstring 00.00.0000
7945
7946
7947 \series bold 
7948 -E
7949 \begin_inset LatexCommand \index{-E}
7950
7951 \end_inset 
7952
7953
7954 \series default 
7955  Run only the C preprocessor.
7956  Preprocess all the C source files specified and output the results to standard
7957  output.
7958 \layout List
7959 \labelwidthstring 00.00.0000
7960
7961
7962 \series bold 
7963 -o\SpecialChar ~
7964 <path/file>
7965 \begin_inset LatexCommand \index{-o <path/file>}
7966
7967 \end_inset 
7968
7969  
7970 \series default 
7971 The output path resp.
7972  file where everything will be placed.
7973  If the parameter is a path, it must have a trailing slash (or backslash
7974  for the Windows binaries) to be recognized as a path.
7975  
7976 \layout List
7977 \labelwidthstring 00.00.0000
7978
7979
7980 \series bold 
7981 -
7982 \begin_inset ERT
7983 status Collapsed
7984
7985 \layout Standard
7986
7987 \backslash 
7988 /
7989 \end_inset 
7990
7991 -stack-auto
7992 \begin_inset LatexCommand \index{-\/-stack-auto}
7993
7994 \end_inset 
7995
7996
7997 \series default 
7998 \size large 
7999 \emph on 
8000  
8001 \size default 
8002 \emph default 
8003 All functions in the source file will be compiled as 
8004 \emph on 
8005 reentrant
8006 \emph default 
8007
8008 \begin_inset LatexCommand \index{reentrant}
8009
8010 \end_inset 
8011
8012 , i.e.
8013  the parameters and local variables will be allocated on the stack
8014 \begin_inset LatexCommand \index{stack}
8015
8016 \end_inset 
8017
8018 .
8019  See section 
8020 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8021
8022 \end_inset 
8023
8024  Parameters and Local Variables for more details.
8025  If this option is used all source files in the project should be compiled
8026  with this option.
8027  It automatically implies --int-long-reent and --float-reent.
8028  
8029 \layout List
8030 \labelwidthstring 00.00.0000
8031
8032
8033 \series bold 
8034 -
8035 \begin_inset ERT
8036 status Collapsed
8037
8038 \layout Standard
8039
8040 \backslash 
8041 /
8042 \end_inset 
8043
8044 -callee-saves
8045 \begin_inset LatexCommand \index{-\/-callee-saves}
8046
8047 \end_inset 
8048
8049  function1[,function2][,function3]....
8050
8051 \series default 
8052  The compiler by default uses a caller saves convention for register saving
8053  across function calls, however this can cause unnecessary register pushing
8054  & popping when calling small functions from larger functions.
8055  This option can be used to switch the register saving convention for the
8056  function names specified.
8057  The compiler will not save registers when calling these functions, no extra
8058  code will be generated at the entry & exit (function prologue
8059 \series bold 
8060
8061 \begin_inset LatexCommand \index{function prologue}
8062
8063 \end_inset 
8064
8065
8066 \series default 
8067  & epilogue
8068 \series bold 
8069
8070 \begin_inset LatexCommand \index{function epilogue}
8071
8072 \end_inset 
8073
8074
8075 \series default 
8076 ) for these functions to save & restore the registers used by these functions,
8077  this can SUBSTANTIALLY reduce code & improve run time performance of the
8078  generated code.
8079  In the future the compiler (with inter procedural analysis) will be able
8080  to determine the appropriate scheme to use for each function call.
8081  DO NOT use this option for built-in functions such as _mulint..., if this
8082  option is used for a library function the appropriate library function
8083  needs to be recompiled with the same option.
8084  If the project consists of multiple source files then all the source file
8085  should be compiled with the same -
8086 \begin_inset ERT
8087 status Collapsed
8088
8089 \layout Standard
8090
8091 \backslash 
8092 /
8093 \end_inset 
8094
8095 -callee-saves option string.
8096  Also see #pragma\SpecialChar ~
8097 callee_saves
8098 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8099
8100 \end_inset 
8101
8102 .
8103 \layout List
8104 \labelwidthstring 00.00.0000
8105
8106
8107 \series bold 
8108 -
8109 \begin_inset ERT
8110 status Collapsed
8111
8112 \layout Standard
8113
8114 \backslash 
8115 /
8116 \end_inset 
8117
8118 -debug
8119 \begin_inset LatexCommand \index{-\/-debug}
8120
8121 \end_inset 
8122
8123
8124 \bar under 
8125  
8126 \series default 
8127 \bar default 
8128 When this option is used the compiler will generate debug information.
8129  The debug information collected in a file with .cdb extension can be used
8130  with the SDCDB.
8131  For more information see documentation for SDCDB.
8132  Another file with no extension contains debug information in AOMF or AOMF51
8133 \begin_inset LatexCommand \index{AOMF, AOMF51}
8134
8135 \end_inset 
8136
8137  format which is commonly used by third party tools.
8138 \layout List
8139 \labelwidthstring 00.00.0000
8140
8141
8142 \series bold 
8143 -S
8144 \begin_inset LatexCommand \index{-S}
8145
8146 \end_inset 
8147
8148
8149 \size large 
8150 \bar under 
8151  
8152 \series default 
8153 \size default 
8154 \bar default 
8155 Stop after the stage of compilation proper; do not assemble.
8156  The output is an assembler code file for the input file specified.
8157 \layout List
8158 \labelwidthstring 00.00.0000
8159
8160
8161 \series bold 
8162 -
8163 \begin_inset ERT
8164 status Collapsed
8165
8166 \layout Standard
8167
8168 \backslash 
8169 /
8170 \end_inset 
8171
8172 -int-long-reent
8173 \begin_inset LatexCommand \index{-\/-int-long-reent}
8174
8175 \end_inset 
8176
8177
8178 \series default 
8179  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8180  Note by default these libraries are compiled as non-reentrant.
8181  See section Installation for more details.
8182 \layout List
8183 \labelwidthstring 00.00.0000
8184
8185
8186 \series bold 
8187 -
8188 \begin_inset ERT
8189 status Collapsed
8190
8191 \layout Standard
8192
8193 \backslash 
8194 /
8195 \end_inset 
8196
8197 -cyclomatic
8198 \begin_inset LatexCommand \index{-\/-cyclomatic}
8199
8200 \end_inset 
8201
8202
8203 \bar under 
8204  
8205 \series default 
8206 \bar default 
8207 This option will cause the compiler to generate an information message for
8208  each function in the source file.
8209  The message contains some 
8210 \emph on 
8211 important
8212 \emph default 
8213  information about the function.
8214  The number of edges and nodes the compiler detected in the control flow
8215  graph of the function, and most importantly the 
8216 \emph on 
8217 cyclomatic complexity
8218 \begin_inset LatexCommand \index{Cyclomatic complexity}
8219
8220 \end_inset 
8221
8222
8223 \emph default 
8224  see section on Cyclomatic Complexity for more details.
8225 \layout List
8226 \labelwidthstring 00.00.0000
8227
8228
8229 \series bold 
8230 -
8231 \begin_inset ERT
8232 status Collapsed
8233
8234 \layout Standard
8235
8236 \backslash 
8237 /
8238 \end_inset 
8239
8240 -float-reent
8241 \begin_inset LatexCommand \index{-\/-float-reent}
8242
8243 \end_inset 
8244
8245
8246 \series default 
8247  Floating point library is compiled as reentrant
8248 \begin_inset LatexCommand \index{reentrant}
8249
8250 \end_inset 
8251
8252 .
8253  See section Installation for more details.
8254 \layout List
8255 \labelwidthstring 00.00.0000
8256
8257
8258 \series bold 
8259 -
8260 \begin_inset ERT
8261 status Collapsed
8262
8263 \layout Standard
8264
8265 \backslash 
8266 /
8267 \end_inset 
8268
8269 -main-return
8270 \begin_inset LatexCommand \index{-\/-main-return}
8271
8272 \end_inset 
8273
8274
8275 \series default 
8276  This option can be used if the code generated is called by a monitor program
8277  or if the main routine includes an endless loop.
8278  This option results in slightly smaller code and saves two bytes of stack
8279  space.
8280  The return from the 'main'
8281 \begin_inset LatexCommand \index{main return}
8282
8283 \end_inset 
8284
8285  function will return to the function calling main.
8286  The default setting is to lock up i.e.
8287  generate a '
8288 \family typewriter 
8289 sjmp .
8290 \family default 
8291 '.
8292 \layout List
8293 \labelwidthstring 00.00.0000
8294
8295
8296 \series bold 
8297 -
8298 \begin_inset ERT
8299 status Collapsed
8300
8301 \layout Standard
8302
8303 \backslash 
8304 /
8305 \end_inset 
8306
8307 -nostdinc
8308 \begin_inset LatexCommand \index{-\/-nostdinc}
8309
8310 \end_inset 
8311
8312
8313 \series default 
8314  This will prevent the compiler from passing on the default include path
8315  to the preprocessor.
8316 \layout List
8317 \labelwidthstring 00.00.0000
8318
8319
8320 \series bold 
8321 -
8322 \begin_inset ERT
8323 status Collapsed
8324
8325 \layout Standard
8326
8327 \backslash 
8328 /
8329 \end_inset 
8330
8331 -nostdlib
8332 \begin_inset LatexCommand \index{-\/-nostdlib}
8333
8334 \end_inset 
8335
8336
8337 \series default 
8338  This will prevent the compiler from passing on the default library
8339 \begin_inset LatexCommand \index{Libraries}
8340
8341 \end_inset 
8342
8343  path to the linker.
8344 \layout List
8345 \labelwidthstring 00.00.0000
8346
8347
8348 \series bold 
8349 -
8350 \begin_inset ERT
8351 status Collapsed
8352
8353 \layout Standard
8354
8355 \backslash 
8356 /
8357 \end_inset 
8358
8359 -verbose
8360 \begin_inset LatexCommand \index{-\/-verbose}
8361
8362 \end_inset 
8363
8364
8365 \series default 
8366  Shows the various actions the compiler is performing.
8367 \layout List
8368 \labelwidthstring 00.00.0000
8369
8370
8371 \series bold 
8372 -V
8373 \begin_inset LatexCommand \index{-V}
8374
8375 \end_inset 
8376
8377
8378 \series default 
8379  Shows the actual commands the compiler is executing.
8380 \layout List
8381 \labelwidthstring 00.00.0000
8382
8383
8384 \series bold 
8385 -
8386 \begin_inset ERT
8387 status Collapsed
8388
8389 \layout Standard
8390
8391 \backslash 
8392 /
8393 \end_inset 
8394
8395 -no-c-code-in-asm
8396 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8397
8398 \end_inset 
8399
8400
8401 \series default 
8402  Hides your ugly and inefficient c-code from the asm file, so you can always
8403  blame the compiler :)
8404 \layout List
8405 \labelwidthstring 00.00.0000
8406
8407
8408 \series bold 
8409 -
8410 \begin_inset ERT
8411 status Collapsed
8412
8413 \layout Standard
8414
8415 \backslash 
8416 /
8417 \end_inset 
8418
8419 -no-peep-comments
8420 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8421
8422 \end_inset 
8423
8424
8425 \series default 
8426  Will not include peep-hole comments in the generated files.
8427 \layout List
8428 \labelwidthstring 00.00.0000
8429
8430
8431 \series bold 
8432 -
8433 \begin_inset ERT
8434 status Collapsed
8435
8436 \layout Standard
8437
8438 \backslash 
8439 /
8440 \end_inset 
8441
8442 -i-code-in-asm
8443 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8444
8445 \end_inset 
8446
8447
8448 \series default 
8449  Include i-codes in the asm file.
8450  Sounds like noise but is most helpful for debugging the compiler itself.
8451 \layout List
8452 \labelwidthstring 00.00.0000
8453
8454
8455 \series bold 
8456 -
8457 \begin_inset ERT
8458 status Collapsed
8459
8460 \layout Standard
8461
8462 \backslash 
8463 /
8464 \end_inset 
8465
8466 -less-pedantic
8467 \begin_inset LatexCommand \index{-\/-less-pedantic}
8468
8469 \end_inset 
8470
8471
8472 \series default 
8473  Disable some of the more pedantic warnings
8474 \begin_inset LatexCommand \index{Warnings}
8475
8476 \end_inset 
8477
8478  (jwk burps: please be more specific here, please!).
8479 \layout List
8480 \labelwidthstring 00.00.0000
8481
8482
8483 \series bold 
8484 -
8485 \begin_inset ERT
8486 status Collapsed
8487
8488 \layout Standard
8489
8490 \backslash 
8491 /
8492 \end_inset 
8493
8494 -disable-warning\SpecialChar ~
8495 <nnnn>
8496 \begin_inset LatexCommand \index{-\/-disable-warning}
8497
8498 \end_inset 
8499
8500
8501 \series default 
8502  Disable specific warning with number <nnnn>.
8503 \layout List
8504 \labelwidthstring 00.00.0000
8505
8506
8507 \series bold 
8508 -
8509 \begin_inset ERT
8510 status Collapsed
8511
8512 \layout Standard
8513
8514 \backslash 
8515 /
8516 \end_inset 
8517
8518 -print-search-dirs
8519 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8520
8521 \end_inset 
8522
8523
8524 \series default 
8525  Display the directories in the compiler's search path
8526 \layout List
8527 \labelwidthstring 00.00.0000
8528
8529
8530 \series bold 
8531 -
8532 \begin_inset ERT
8533 status Collapsed
8534
8535 \layout Standard
8536
8537 \backslash 
8538 /
8539 \end_inset 
8540
8541 -vc
8542 \begin_inset LatexCommand \index{-\/-vc}
8543
8544 \end_inset 
8545
8546
8547 \series default 
8548  Display errors and warnings using MSVC style, so you can use SDCC with
8549  the visual studio IDE
8550 \begin_inset LatexCommand \index{IDE}
8551
8552 \end_inset 
8553
8554 .
8555  With SDCC both offering a GCC-like (the default) and a MSVC-like
8556 \begin_inset LatexCommand \index{MSVC output style}
8557
8558 \end_inset 
8559
8560  output style, integration into most programming editors should be straightforwa
8561 rd.
8562 \layout List
8563 \labelwidthstring 00.00.0000
8564
8565
8566 \series bold 
8567 -
8568 \begin_inset ERT
8569 status Collapsed
8570
8571 \layout Standard
8572
8573 \backslash 
8574 /
8575 \end_inset 
8576
8577 -use-stdout
8578 \begin_inset LatexCommand \index{-\/-use-stdout}
8579
8580 \end_inset 
8581
8582
8583 \series default 
8584  Send errors and warnings to stdout instead of stderr.
8585 \layout List
8586 \labelwidthstring 00.00.0000
8587
8588
8589 \series bold 
8590 -Wa\SpecialChar ~
8591 asmOption[,asmOption]
8592 \series default 
8593
8594 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8595
8596 \end_inset 
8597
8598 ...
8599  Pass the asmOption to the assembler
8600 \begin_inset LatexCommand \index{Options assembler}
8601
8602 \end_inset 
8603
8604
8605 \begin_inset LatexCommand \index{Assembler options}
8606
8607 \end_inset 
8608
8609 .
8610  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8611 \layout List
8612 \labelwidthstring 00.00.0000
8613
8614
8615 \series bold 
8616 -
8617 \begin_inset ERT
8618 status Collapsed
8619
8620 \layout Standard
8621
8622 \backslash 
8623 /
8624 \end_inset 
8625
8626 -std-sdcc89
8627 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8628
8629 \end_inset 
8630
8631
8632 \series default 
8633  Generally follow the C89 standard, but allow SDCC features that conflict
8634  with the standard (default).
8635 \layout List
8636 \labelwidthstring 00.00.0000
8637
8638
8639 \series bold 
8640 -
8641 \begin_inset ERT
8642 status Collapsed
8643
8644 \layout Standard
8645
8646 \backslash 
8647 /
8648 \end_inset 
8649
8650 -std-c89
8651 \begin_inset LatexCommand \index{-\/-std-c89}
8652
8653 \end_inset 
8654
8655
8656 \series default 
8657  Follow the C89 standard and disable SDCC features that conflict with the
8658  standard.
8659 \layout List
8660 \labelwidthstring 00.00.0000
8661
8662
8663 \series bold 
8664 -
8665 \begin_inset ERT
8666 status Collapsed
8667
8668 \layout Standard
8669
8670 \backslash 
8671 /
8672 \end_inset 
8673
8674 -std-sdcc99
8675 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8676
8677 \end_inset 
8678
8679
8680 \series default 
8681  Generally follow the C99 standard, but allow SDCC features that conflict
8682  with the standard (incomplete support).
8683 \layout List
8684 \labelwidthstring 00.00.0000
8685
8686
8687 \series bold 
8688 -
8689 \begin_inset ERT
8690 status Collapsed
8691
8692 \layout Standard
8693
8694 \backslash 
8695 /
8696 \end_inset 
8697
8698 -std-c99
8699 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8700
8701 \end_inset 
8702
8703
8704 \series default 
8705  Follow the C99 standard and disable SDCC features that conflict with the
8706  standard (incomplete support).
8707 \layout List
8708 \labelwidthstring 00.00.0000
8709
8710
8711 \series bold 
8712 -
8713 \begin_inset ERT
8714 status Collapsed
8715
8716 \layout Standard
8717
8718 \backslash 
8719 /
8720 \end_inset 
8721
8722 -codeseg
8723 \series default 
8724
8725 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8726
8727 \end_inset 
8728
8729 \SpecialChar ~
8730 <Name> The name to be used for the code
8731 \begin_inset LatexCommand \index{code}
8732
8733 \end_inset 
8734
8735  segment, default CSEG.
8736  This is useful if you need to tell the compiler to put the code in a special
8737  segment so you can later on tell the linker to put this segment in a special
8738  place in memory.
8739  Can be used for instance when using bank switching to put the code in a
8740  bank.
8741 \layout List
8742 \labelwidthstring 00.00.0000
8743
8744
8745 \series bold 
8746 -
8747 \begin_inset ERT
8748 status Collapsed
8749
8750 \layout Standard
8751
8752 \backslash 
8753 /
8754 \end_inset 
8755
8756 -constseg
8757 \series default 
8758
8759 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8760
8761 \end_inset 
8762
8763 \SpecialChar ~
8764 <Name> The name to be used for the const
8765 \begin_inset LatexCommand \index{code}
8766
8767 \end_inset 
8768
8769  segment, default CONST.
8770  This is useful if you need to tell the compiler to put the const data in
8771  a special segment so you can later on tell the linker to put this segment
8772  in a special place in memory.
8773  Can be used for instance when using bank switching to put the const data
8774  in a bank.
8775 \layout List
8776 \labelwidthstring 00.00.0000
8777
8778
8779 \series bold 
8780 -
8781 \begin_inset ERT
8782 status Collapsed
8783
8784 \layout Standard
8785
8786 \backslash 
8787 /
8788 \end_inset 
8789
8790 -fdollars-in-identifiers
8791 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
8792
8793 \end_inset 
8794
8795
8796 \series default 
8797  Permit '$' as an identifier character
8798 \layout List
8799 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8800
8801
8802 \series bold 
8803 more-pedantic
8804 \series default 
8805  Actually this is 
8806 \series bold 
8807 \emph on 
8808 not
8809 \series default 
8810 \emph default 
8811  a SDCC compiler option but if you want 
8812 \emph on 
8813 more
8814 \emph default 
8815  warnings you can use a separate tool dedicated to syntax checking like
8816  splint
8817 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8818
8819 \end_inset 
8820
8821
8822 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8823
8824 \end_inset 
8825
8826  
8827 \begin_inset LatexCommand \url{http://www.splint.org}
8828
8829 \end_inset 
8830
8831 .
8832  To make your source files parseable by splint you will have to include
8833  
8834 \family sans 
8835 lint.h
8836 \family default 
8837
8838 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8839
8840 \end_inset 
8841
8842  in your source file and add brackets around extended keywords (like 
8843 \family sans 
8844
8845 \begin_inset Quotes sld
8846 \end_inset 
8847
8848 __at\SpecialChar ~
8849
8850 \series bold 
8851 (
8852 \series default 
8853 0xab
8854 \series bold 
8855 )
8856 \series default 
8857
8858 \begin_inset Quotes srd
8859 \end_inset 
8860
8861
8862 \family default 
8863  and 
8864 \family sans 
8865
8866 \begin_inset Quotes sld
8867 \end_inset 
8868
8869 __interrupt\SpecialChar ~
8870 (2)
8871 \begin_inset Quotes srd
8872 \end_inset 
8873
8874
8875 \family default 
8876 ).
8877  
8878 \newline 
8879 Splint has an excellent on line manual at 
8880 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8881
8882 \end_inset 
8883
8884  and it's capabilities go beyond pure syntax checking.
8885  You'll need to tell splint the location of SDCC's include files so a typical
8886  command line could look like this: 
8887 \newline 
8888
8889 \family sans 
8890 splint\SpecialChar ~
8891 -I\SpecialChar ~
8892 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8893 \SpecialChar ~
8894 myprogram.c
8895 \layout Subsection
8896
8897 Intermediate Dump Options
8898 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8899
8900 \end_inset 
8901
8902
8903 \begin_inset LatexCommand \index{Options intermediate dump}
8904
8905 \end_inset 
8906
8907
8908 \begin_inset LatexCommand \index{Intermediate dump options}
8909
8910 \end_inset 
8911
8912
8913 \layout Standard
8914
8915 The following options are provided for the purpose of retargetting and debugging
8916  the compiler.
8917  They provide a means to dump the intermediate code (iCode
8918 \begin_inset LatexCommand \index{iCode}
8919
8920 \end_inset 
8921
8922 ) generated by the compiler in human readable form at various stages of
8923  the compilation process.
8924  More on iCodes see chapter 
8925 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8926
8927 \end_inset 
8928
8929  
8930 \begin_inset Quotes srd
8931 \end_inset 
8932
8933 The anatomy of the compiler
8934 \begin_inset Quotes srd
8935 \end_inset 
8936
8937 .
8938 \layout List
8939 \labelwidthstring 00.00.0000
8940
8941
8942 \series bold 
8943 -
8944 \begin_inset ERT
8945 status Collapsed
8946
8947 \layout Standard
8948
8949 \backslash 
8950 /
8951 \end_inset 
8952
8953 -dumpraw
8954 \begin_inset LatexCommand \index{-\/-dumpraw}
8955
8956 \end_inset 
8957
8958
8959 \series default 
8960  This option will cause the compiler to dump the intermediate code into
8961  a file of named 
8962 \emph on 
8963 <source filename>.dumpraw
8964 \emph default 
8965  just after the intermediate code has been generated for a function, i.e.
8966  before any optimizations are done.
8967  The basic blocks
8968 \begin_inset LatexCommand \index{Basic blocks}
8969
8970 \end_inset 
8971
8972  at this stage ordered in the depth first number, so they may not be in
8973  sequence of execution.
8974 \layout List
8975 \labelwidthstring 00.00.0000
8976
8977
8978 \series bold 
8979 -
8980 \begin_inset ERT
8981 status Collapsed
8982
8983 \layout Standard
8984
8985 \backslash 
8986 /
8987 \end_inset 
8988
8989 -dumpgcse
8990 \begin_inset LatexCommand \index{-\/-dumpgcse}
8991
8992 \end_inset 
8993
8994
8995 \series default 
8996  Will create a dump of iCode's, after global subexpression elimination
8997 \begin_inset LatexCommand \index{Global subexpression elimination}
8998
8999 \end_inset 
9000
9001 , into a file named 
9002 \emph on 
9003 <source filename>.dumpgcse.
9004 \layout List
9005 \labelwidthstring 00.00.0000
9006
9007
9008 \series bold 
9009 -
9010 \begin_inset ERT
9011 status Collapsed
9012
9013 \layout Standard
9014
9015 \backslash 
9016 /
9017 \end_inset 
9018
9019 -dumpdeadcode
9020 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9021
9022 \end_inset 
9023
9024
9025 \series default 
9026  Will create a dump of iCode's, after deadcode elimination
9027 \begin_inset LatexCommand \index{Dead-code elimination}
9028
9029 \end_inset 
9030
9031 , into a file named 
9032 \emph on 
9033 <source filename>.dumpdeadcode.
9034 \layout List
9035 \labelwidthstring 00.00.0000
9036
9037
9038 \series bold 
9039 -
9040 \begin_inset ERT
9041 status Collapsed
9042
9043 \layout Standard
9044
9045 \backslash 
9046 /
9047 \end_inset 
9048
9049 -dumploop
9050 \begin_inset LatexCommand \index{-\/-dumploop}
9051
9052 \end_inset 
9053
9054
9055 \series default 
9056 \size large 
9057  
9058 \size default 
9059 Will create a dump of iCode's, after loop optimizations
9060 \begin_inset LatexCommand \index{Loop optimization}
9061
9062 \end_inset 
9063
9064 , into a file named 
9065 \emph on 
9066 <source filename>.dumploop.
9067 \layout List
9068 \labelwidthstring 00.00.0000
9069
9070
9071 \series bold 
9072 -
9073 \begin_inset ERT
9074 status Collapsed
9075
9076 \layout Standard
9077
9078 \backslash 
9079 /
9080 \end_inset 
9081
9082 -dumprange
9083 \begin_inset LatexCommand \index{-\/-dumprange}
9084
9085 \end_inset 
9086
9087
9088 \series default 
9089 \size large 
9090  
9091 \size default 
9092 Will create a dump of iCode's, after live range analysis
9093 \begin_inset LatexCommand \index{Live range analysis}
9094
9095 \end_inset 
9096
9097 , into a file named 
9098 \emph on 
9099 <source filename>.dumprange.
9100 \layout List
9101 \labelwidthstring 00.00.0000
9102
9103
9104 \series bold 
9105 -
9106 \begin_inset ERT
9107 status Collapsed
9108
9109 \layout Standard
9110
9111 \backslash 
9112 /
9113 \end_inset 
9114
9115 -dumlrange
9116 \begin_inset LatexCommand \index{-\/-dumlrange}
9117
9118 \end_inset 
9119
9120
9121 \series default 
9122  Will dump the life ranges
9123 \begin_inset LatexCommand \index{Live range analysis}
9124
9125 \end_inset 
9126
9127  for all symbols.
9128 \layout List
9129 \labelwidthstring 00.00.0000
9130
9131
9132 \series bold 
9133 -
9134 \begin_inset ERT
9135 status Collapsed
9136
9137 \layout Standard
9138
9139 \backslash 
9140 /
9141 \end_inset 
9142
9143 -dumpregassign
9144 \begin_inset LatexCommand \index{-\/-dumpregassign}
9145
9146 \end_inset 
9147
9148
9149 \bar under 
9150  
9151 \series default 
9152 \bar default 
9153 Will create a dump of iCode's, after register assignment
9154 \begin_inset LatexCommand \index{Register assignment}
9155
9156 \end_inset 
9157
9158 , into a file named 
9159 \emph on 
9160 <source filename>.dumprassgn.
9161 \layout List
9162 \labelwidthstring 00.00.0000
9163
9164
9165 \series bold 
9166 -
9167 \begin_inset ERT
9168 status Collapsed
9169
9170 \layout Standard
9171
9172 \backslash 
9173 /
9174 \end_inset 
9175
9176 -dumplrange
9177 \begin_inset LatexCommand \index{-\/-dumplrange}
9178
9179 \end_inset 
9180
9181
9182 \series default 
9183  Will create a dump of the live ranges of iTemp's
9184 \layout List
9185 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9186
9187
9188 \series bold 
9189 -
9190 \begin_inset ERT
9191 status Collapsed
9192
9193 \layout Standard
9194
9195 \backslash 
9196 /
9197 \end_inset 
9198
9199 -dumpall
9200 \begin_inset LatexCommand \index{-\/-dumpall}
9201
9202 \end_inset 
9203
9204
9205 \size large 
9206 \bar under 
9207  
9208 \series default 
9209 \size default 
9210 \bar default 
9211 Will cause all the above mentioned dumps to be created.
9212 \layout Subsection
9213
9214 Redirecting output on Windows Shells
9215 \layout Standard
9216 \added_space_bottom bigskip 
9217 By default SDCC writes it's error messages to 
9218 \begin_inset Quotes sld
9219 \end_inset 
9220
9221 standard error
9222 \begin_inset Quotes srd
9223 \end_inset 
9224
9225 .
9226  To force all messages to 
9227 \begin_inset Quotes sld
9228 \end_inset 
9229
9230 standard output
9231 \begin_inset Quotes srd
9232 \end_inset 
9233
9234  use 
9235 \series bold 
9236 -
9237 \series default 
9238 \emph on 
9239
9240 \begin_inset ERT
9241 status Collapsed
9242
9243 \layout Standard
9244
9245 \backslash 
9246 /
9247 \end_inset 
9248
9249
9250 \series bold 
9251 \emph default 
9252 -
9253 \series default 
9254 use-stdout
9255 \begin_inset LatexCommand \index{-\/-use-stdout}
9256
9257 \end_inset 
9258
9259 .
9260  Additionally, if you happen to have visual studio installed in your windows
9261  machine, you can use it to compile your sources using a custom build and
9262  the SDCC -
9263 \emph on 
9264
9265 \begin_inset ERT
9266 status Collapsed
9267
9268 \layout Standard
9269
9270 \backslash 
9271 /
9272 \end_inset 
9273
9274
9275 \emph default 
9276 -vc
9277 \begin_inset LatexCommand \index{-\/-vc}
9278
9279 \end_inset 
9280
9281  option.
9282  Something like this should work:
9283 \newline 
9284
9285 \newline 
9286
9287 \series bold 
9288 c:
9289 \backslash 
9290 sdcc
9291 \backslash 
9292 bin
9293 \backslash 
9294 sdcc.exe -
9295 \series default 
9296 \emph on 
9297
9298 \begin_inset ERT
9299 status Collapsed
9300
9301 \layout Standard
9302
9303 \backslash 
9304 /
9305 \end_inset 
9306
9307
9308 \series bold 
9309 \emph default 
9310 -vc -
9311 \series default 
9312 \emph on 
9313
9314 \begin_inset ERT
9315 status Collapsed
9316
9317 \layout Standard
9318
9319 \backslash 
9320 /
9321 \end_inset 
9322
9323
9324 \series bold 
9325 \emph default 
9326 -model-large -c $(InputPath)
9327 \layout Section
9328
9329 Environment variables
9330 \begin_inset LatexCommand \index{Environment variables}
9331
9332 \end_inset 
9333
9334
9335 \layout Standard
9336
9337 SDCC recognizes the following environment variables:
9338 \layout List
9339 \labelwidthstring 00.00.0000
9340
9341
9342 \series bold 
9343 SDCC_LEAVE_SIGNALS
9344 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9345
9346 \end_inset 
9347
9348
9349 \series default 
9350  SDCC installs a signal handler
9351 \begin_inset LatexCommand \index{signal handler}
9352
9353 \end_inset 
9354
9355  to be able to delete temporary files after an user break (^C) or an exception.
9356  If this environment variable is set, SDCC won't install the signal handler
9357  in order to be able to debug SDCC.
9358 \layout List
9359 \labelwidthstring 00.00.0000
9360
9361
9362 \series bold 
9363 TMP,\SpecialChar ~
9364 TEMP,\SpecialChar ~
9365 TMPDIR
9366 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9367
9368 \end_inset 
9369
9370
9371 \series default 
9372  Path, where temporary files will be created.
9373  The order of the variables is the search order.
9374  In a standard *nix environment these variables are not set, and there's
9375  no need to set them.
9376  On Windows it's recommended to set one of them.
9377 \layout List
9378 \labelwidthstring 00.00.0000
9379
9380
9381 \series bold 
9382 SDCC_HOME
9383 \begin_inset LatexCommand \index{SDCC\_HOME}
9384
9385 \end_inset 
9386
9387
9388 \series default 
9389  Path, see section 
9390 \begin_inset LatexCommand \ref{sub:Install-paths}
9391
9392 \end_inset 
9393
9394 \SpecialChar ~
9395
9396 \begin_inset Quotes sld
9397 \end_inset 
9398
9399  Install Paths
9400 \begin_inset Quotes srd
9401 \end_inset 
9402
9403 .
9404 \layout List
9405 \labelwidthstring 00.00.0000
9406
9407
9408 \series bold 
9409 SDCC_INCLUDE
9410 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9411
9412 \end_inset 
9413
9414
9415 \series default 
9416  Path, see section 
9417 \begin_inset LatexCommand \ref{sub:Search-Paths}
9418
9419 \end_inset 
9420
9421 \SpecialChar ~
9422
9423 \begin_inset Quotes sld
9424 \end_inset 
9425
9426 Search Paths
9427 \begin_inset Quotes srd
9428 \end_inset 
9429
9430 .
9431 \layout List
9432 \labelwidthstring 00.00.0000
9433
9434
9435 \series bold 
9436 SDCC_LIB
9437 \begin_inset LatexCommand \index{SDCC\_LIB}
9438
9439 \end_inset 
9440
9441
9442 \series default 
9443  Path, see section 
9444 \begin_inset LatexCommand \ref{sub:Search-Paths}
9445
9446 \end_inset 
9447
9448 \SpecialChar ~
9449
9450 \begin_inset Quotes sld
9451 \end_inset 
9452
9453 Search Paths
9454 \begin_inset Quotes srd
9455 \end_inset 
9456
9457 ..
9458 \layout Standard
9459 \added_space_bottom bigskip 
9460 There are some more environment variables recognized by SDCC, but these
9461  are solely used for debugging purposes.
9462  They can change or disappear very quickly, and will never be documented.
9463 \layout Section
9464
9465 Storage Class Language Extensions
9466 \layout Subsection
9467
9468 MCS51/DS390 Storage Class
9469 \begin_inset LatexCommand \index{Storage class}
9470
9471 \end_inset 
9472
9473  Language Extensions
9474 \layout Standard
9475
9476 In addition to the ANSI storage classes SDCC allows the following MCS51
9477  specific storage classes:
9478 \layout Subsubsection
9479
9480 data
9481 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9482
9483 \end_inset 
9484
9485
9486 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9487
9488 \end_inset 
9489
9490  / near
9491 \begin_inset LatexCommand \index{near (storage class)}
9492
9493 \end_inset 
9494
9495
9496 \begin_inset LatexCommand \index{\_\_near (storage class)}
9497
9498 \end_inset 
9499
9500
9501 \layout Standard
9502
9503 This is the 
9504 \series bold 
9505 default
9506 \series default 
9507  storage class for the Small Memory model (
9508 \emph on 
9509 data
9510 \emph default 
9511  and 
9512 \emph on 
9513 near
9514 \emph default 
9515  or the more ANSI-C compliant forms 
9516 \emph on 
9517 __data
9518 \emph default 
9519  and 
9520 \emph on 
9521 __near
9522 \emph default 
9523  can be used synonymously).
9524  Variables declared with this storage class will be allocated in the directly
9525  addressable portion of the internal RAM of a 8051, e.g.:
9526 \layout Verse
9527
9528
9529 \family typewriter 
9530 __data unsigned char test_data;
9531 \layout Standard
9532
9533 Writing 0x01 to this variable generates the assembly code:
9534 \layout Verse
9535
9536
9537 \family typewriter 
9538 75*00 01\SpecialChar ~
9539 \SpecialChar ~
9540 \SpecialChar ~
9541 mov\SpecialChar ~
9542 \SpecialChar ~
9543 _test_data,#0x01
9544 \layout Subsubsection
9545
9546 xdata
9547 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9548
9549 \end_inset 
9550
9551
9552 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9553
9554 \end_inset 
9555
9556  / far
9557 \begin_inset LatexCommand \index{far (storage class)}
9558
9559 \end_inset 
9560
9561
9562 \begin_inset LatexCommand \index{\_\_far (storage class)}
9563
9564 \end_inset 
9565
9566
9567 \layout Standard
9568
9569 Variables declared with this storage class will be placed in the external
9570  RAM.
9571  This is the 
9572 \series bold 
9573 default
9574 \series default 
9575  storage class for the Large Memory model, e.g.:
9576 \layout Verse
9577
9578
9579 \family typewriter 
9580 __xdata unsigned char test_xdata;
9581 \layout Standard
9582
9583 Writing 0x01 to this variable generates the assembly code:
9584 \layout Verse
9585
9586
9587 \family typewriter 
9588 90s00r00\SpecialChar ~
9589 \SpecialChar ~
9590 \SpecialChar ~
9591 mov\SpecialChar ~
9592 \SpecialChar ~
9593 dptr,#_test_xdata 
9594 \newline 
9595 74\SpecialChar ~
9596 01\SpecialChar ~
9597 \SpecialChar ~
9598 \SpecialChar ~
9599 \SpecialChar ~
9600 \SpecialChar ~
9601 \SpecialChar ~
9602 mov\SpecialChar ~
9603 \SpecialChar ~
9604 a,#0x01 
9605 \newline 
9606 F0\SpecialChar ~
9607 \SpecialChar ~
9608 \SpecialChar ~
9609 \SpecialChar ~
9610 \SpecialChar ~
9611 \SpecialChar ~
9612 \SpecialChar ~
9613 \SpecialChar ~
9614 \SpecialChar ~
9615 movx\SpecialChar ~
9616 @dptr,a 
9617 \layout Subsubsection
9618
9619 idata
9620 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9621
9622 \end_inset 
9623
9624
9625 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9626
9627 \end_inset 
9628
9629
9630 \layout Standard
9631
9632 Variables declared with this storage class will be allocated into the indirectly
9633  addressable portion of the internal ram of a 8051, e.g.:
9634 \layout Verse
9635
9636
9637 \family typewriter 
9638 __idata unsigned char test_idata;
9639 \layout Standard
9640
9641 Writing 0x01 to this variable generates the assembly code:
9642 \layout Verse
9643
9644
9645 \family typewriter 
9646 78r00\SpecialChar ~
9647 \SpecialChar ~
9648 \SpecialChar ~
9649 \SpecialChar ~
9650 \SpecialChar ~
9651 \SpecialChar ~
9652 \SpecialChar ~
9653 mov\SpecialChar ~
9654 \SpecialChar ~
9655 r0,#_test_idata
9656 \newline 
9657 76\SpecialChar ~
9658 01\SpecialChar ~
9659 \SpecialChar ~
9660 \SpecialChar ~
9661 \SpecialChar ~
9662 \SpecialChar ~
9663 \SpecialChar ~
9664 \SpecialChar ~
9665 mov\SpecialChar ~
9666 \SpecialChar ~
9667 @r0,#0x01
9668 \layout Standard
9669
9670 Please note, the first 128 byte of idata physically access the same RAM
9671  as the data memory.
9672  The original 8051 had 128 byte idata memory, nowadays most devices have
9673  256 byte idata memory.
9674  The stack
9675 \begin_inset LatexCommand \index{stack}
9676
9677 \end_inset 
9678
9679  is located in idata memory.
9680 \layout Subsubsection
9681
9682 pdata
9683 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9684
9685 \end_inset 
9686
9687
9688 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9689
9690 \end_inset 
9691
9692
9693 \layout Standard
9694
9695 Paged xdata access is just as straightforward as using the other addressing
9696  modes of a 8051.
9697  It is typically located at the start of xdata and has a maximum size of
9698  256 bytes.
9699  The following example writes 0x01 to the pdata variable.
9700  Please note, pdata access physically accesses xdata memory.
9701  The high byte of the address is determined by port P2 
9702 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9703
9704 \end_inset 
9705
9706 (or in case of some 8051 variants by a separate Special Function Register,
9707  see section 
9708 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9709
9710 \end_inset 
9711
9712 ).
9713  This is the 
9714 \series bold 
9715 default
9716 \series default 
9717  storage class for the Medium Memory model, e.g.:
9718 \layout Verse
9719
9720
9721 \family typewriter 
9722 __pdata unsigned char test_pdata;
9723 \layout Standard
9724
9725 Writing 0x01 to this variable generates the assembly code:
9726 \layout Verse
9727
9728
9729 \family typewriter 
9730 78r00\SpecialChar ~
9731 \SpecialChar ~
9732 \SpecialChar ~
9733 \SpecialChar ~
9734 \SpecialChar ~
9735 \SpecialChar ~
9736 mov r0,#_test_pdata
9737 \newline 
9738 74 01\SpecialChar ~
9739 \SpecialChar ~
9740 \SpecialChar ~
9741 \SpecialChar ~
9742 \SpecialChar ~
9743 \SpecialChar ~
9744 mov a,#0x01 
9745 \newline 
9746 F2\SpecialChar ~
9747 \SpecialChar ~
9748 \SpecialChar ~
9749 \SpecialChar ~
9750 \SpecialChar ~
9751 \SpecialChar ~
9752 \SpecialChar ~
9753 \SpecialChar ~
9754 \SpecialChar ~
9755 movx @r0,a
9756 \layout Standard
9757
9758 If the -
9759 \begin_inset ERT
9760 status Collapsed
9761
9762 \layout Standard
9763
9764 \backslash 
9765 /
9766 \end_inset 
9767
9768 -xstack
9769 \begin_inset LatexCommand \index{-\/-xstack}
9770
9771 \end_inset 
9772
9773  option is used the pdata memory area is followed by the xstack memory area
9774  and the sum of their sizes is limited to 256 bytes.
9775 \layout Subsubsection
9776
9777 code
9778 \begin_inset LatexCommand \index{code}
9779
9780 \end_inset 
9781
9782
9783 \begin_inset LatexCommand \index{\_\_code}
9784
9785 \end_inset 
9786
9787
9788 \layout Standard
9789
9790 'Variables' declared with this storage class will be placed in the code
9791  memory:
9792 \layout Verse
9793
9794
9795 \family typewriter 
9796 __code unsigned char test_code;
9797 \layout Standard
9798
9799 Read access to this variable generates the assembly code:
9800 \layout Verse
9801
9802
9803 \family typewriter 
9804 90s00r6F\SpecialChar ~
9805 \SpecialChar ~
9806 \SpecialChar ~
9807 mov dptr,#_test_code
9808 \newline 
9809 E4\SpecialChar ~
9810 \SpecialChar ~
9811 \SpecialChar ~
9812 \SpecialChar ~
9813 \SpecialChar ~
9814 \SpecialChar ~
9815 \SpecialChar ~
9816 \SpecialChar ~
9817 \SpecialChar ~
9818 clr a
9819 \newline 
9820 93\SpecialChar ~
9821 \SpecialChar ~
9822 \SpecialChar ~
9823 \SpecialChar ~
9824 \SpecialChar ~
9825 \SpecialChar ~
9826 \SpecialChar ~
9827 \SpecialChar ~
9828 \SpecialChar ~
9829 movc a,@a+dptr 
9830 \layout Standard
9831
9832
9833 \family typewriter 
9834 char
9835 \family default 
9836  indexed arrays of characters in code memory can be accessed efficiently:
9837 \layout Verse
9838
9839
9840 \family typewriter 
9841 __code char test_array[] = {'c','h','e','a','p'}; 
9842 \layout Standard
9843
9844 Read access to this array using an 8-bit unsigned index generates the assembly
9845  code:
9846 \layout Verse
9847
9848
9849 \family typewriter 
9850 E5*00\SpecialChar ~
9851 \SpecialChar ~
9852 \SpecialChar ~
9853 \SpecialChar ~
9854 \SpecialChar ~
9855 \SpecialChar ~
9856 mov a,_index 
9857 \layout Verse
9858
9859
9860 \family typewriter 
9861 90s00r41\SpecialChar ~
9862 \SpecialChar ~
9863 \SpecialChar ~
9864 mov dptr,#_test_array
9865 \layout Verse
9866
9867
9868 \family typewriter 
9869 93\SpecialChar ~
9870 \SpecialChar ~
9871 \SpecialChar ~
9872 \SpecialChar ~
9873 \SpecialChar ~
9874 \SpecialChar ~
9875 \SpecialChar ~
9876 \SpecialChar ~
9877 \SpecialChar ~
9878 movc a,@a+dptr 
9879 \layout Subsubsection
9880
9881 bit
9882 \begin_inset LatexCommand \index{bit}
9883
9884 \end_inset 
9885
9886
9887 \begin_inset LatexCommand \index{\_\_bit}
9888
9889 \end_inset 
9890
9891
9892 \layout Standard
9893
9894 This is a data-type and a storage class specifier.
9895  When a variable is declared as a bit, it is allocated into the bit addressable
9896  memory of 8051, e.g.:
9897 \layout Verse
9898
9899
9900 \family typewriter 
9901 __bit test_bit;
9902 \layout Standard
9903
9904 Writing 1 to this variable generates the assembly code:
9905 \layout Verse
9906
9907
9908 \family typewriter 
9909 D2*00\SpecialChar ~
9910 \SpecialChar ~
9911 \SpecialChar ~
9912 \SpecialChar ~
9913 \SpecialChar ~
9914 \SpecialChar ~
9915 \SpecialChar ~
9916 setb\SpecialChar ~
9917 _test_bit
9918 \layout Standard
9919
9920 The bit addressable memory consists of 128 bits which are located from 0x20
9921  to 0x2f in data memory.
9922  
9923 \newline 
9924 Apart from this 8051 specific storage class most architectures support ANSI-C
9925  bitfields
9926 \begin_inset LatexCommand \index{bitfields}
9927
9928 \end_inset 
9929
9930
9931 \begin_inset Foot
9932 collapsed false
9933
9934 \layout Standard
9935
9936 Not really meant as examples, but nevertheless showing what bitfields are
9937  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9938 \end_inset 
9939
9940 .
9941  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9942  signed modifier are implemented as unsigned.
9943 \layout Subsubsection
9944
9945 sfr
9946 \begin_inset LatexCommand \index{sfr}
9947
9948 \end_inset 
9949
9950
9951 \begin_inset LatexCommand \index{\_\_sfr}
9952
9953 \end_inset 
9954
9955  / sfr16
9956 \begin_inset LatexCommand \index{sfr16}
9957
9958 \end_inset 
9959
9960
9961 \begin_inset LatexCommand \index{\_\_sfr16}
9962
9963 \end_inset 
9964
9965  / sfr32
9966 \begin_inset LatexCommand \index{sfr32}
9967
9968 \end_inset 
9969
9970
9971 \begin_inset LatexCommand \index{\_\_sfr32}
9972
9973 \end_inset 
9974
9975  / sbit
9976 \begin_inset LatexCommand \index{\_\_sbit}
9977
9978 \end_inset 
9979
9980
9981 \begin_inset LatexCommand \index{sbit}
9982
9983 \end_inset 
9984
9985
9986 \layout Standard
9987
9988 Like the bit keyword, 
9989 \emph on 
9990 sfr / sfr16 / sfr32 / sbit 
9991 \emph default 
9992 signify both a data-type and storage class, they are used to describe the
9993  
9994 \emph on 
9995 s
9996 \emph default 
9997 pecial 
9998 \emph on 
9999 f
10000 \emph default 
10001 unction 
10002 \emph on 
10003 r
10004 \emph default 
10005 egisters and 
10006 \emph on 
10007 s
10008 \emph default 
10009 pecial 
10010 \emph on 
10011 bit
10012 \emph default 
10013  variables of a 8051, eg:
10014 \layout Verse
10015
10016
10017 \family typewriter 
10018 __sfr __at
10019 \begin_inset LatexCommand \index{at}
10020
10021 \end_inset 
10022
10023
10024 \begin_inset LatexCommand \index{\_\_at}
10025
10026 \end_inset 
10027
10028  (0x80) P0;\SpecialChar ~
10029  /* special function register P0 at location 0x80 */
10030 \newline 
10031
10032 \newline 
10033 /* 16 bit special function register combination for timer 0
10034 \newline 
10035 \SpecialChar ~
10036 \SpecialChar ~
10037  with the high byte at location 0x8C and the low byte at location 0x8A */
10038 \newline 
10039 __sfr16 __at (0x8C8A) TMR0;
10040 \newline 
10041
10042 \newline 
10043 __sbit __at
10044 \begin_inset LatexCommand \index{at}
10045
10046 \end_inset 
10047
10048
10049 \begin_inset LatexCommand \index{\_\_at}
10050
10051 \end_inset 
10052
10053  (0xd7) CY;\SpecialChar ~
10054  /* CY (Carry Flag
10055 \begin_inset LatexCommand \index{Flags}
10056
10057 \end_inset 
10058
10059
10060 \begin_inset LatexCommand \index{Carry flag}
10061
10062 \end_inset 
10063
10064 ) */
10065 \layout Standard
10066
10067 Special function registers which are located on an address dividable by
10068  8 are bit-addressable, an
10069 \emph on 
10070  sbit
10071 \emph default 
10072  addresses a specific bit within these sfr.
10073 \newline 
10074 16 Bit and 32 bit special function register combinations which require a
10075  certain access order are better not declared using 
10076 \emph on 
10077 sfr16
10078 \emph default 
10079  or 
10080 \emph on 
10081 sfr32.
10082
10083 \emph default 
10084  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10085  this is not guaranteed.
10086 \newline 
10087
10088 \layout Standard
10089
10090 Please note, if you use a header file which was written for another compiler
10091  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10092  likely be 
10093 \emph on 
10094 not 
10095 \emph default 
10096 compatible.
10097  Specifically the syntax 
10098 \family typewriter 
10099 \SpecialChar ~
10100 sfr P0 = 0x80;\SpecialChar ~
10101
10102 \family default 
10103  is compiled 
10104 \emph on 
10105 without warning
10106 \emph default 
10107  by SDCC to an assignment of 0x80 to a variable called P0 
10108 \family typewriter 
10109
10110 \begin_inset Marginal
10111 collapsed true
10112
10113 \layout Standard
10114
10115
10116 \series bold 
10117 \SpecialChar ~
10118 !
10119 \end_inset 
10120
10121 .
10122  
10123 \family default 
10124 Nevertheless it is possible to write header files
10125 \begin_inset LatexCommand \index{Header files}
10126
10127 \end_inset 
10128
10129
10130 \begin_inset LatexCommand \index{Include files}
10131
10132 \end_inset 
10133
10134  which can be shared among different compilers (see section 
10135 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10136
10137 \end_inset 
10138
10139 ).
10140  
10141 \layout Subsubsection
10142
10143 Pointers
10144 \begin_inset LatexCommand \index{Pointer}
10145
10146 \end_inset 
10147
10148  to MCS51/DS390 specific memory spaces
10149 \layout Standard
10150
10151 SDCC allows (via language extensions) pointers to explicitly point to any
10152  of the memory spaces
10153 \begin_inset LatexCommand \index{Memory model}
10154
10155 \end_inset 
10156
10157  of the 8051.
10158  In addition to the explicit pointers, the compiler uses (by default) generic
10159  pointers which can be used to point to any of the memory spaces.
10160 \newline 
10161
10162 \newline 
10163 Pointer declaration examples:
10164 \layout Verse
10165
10166
10167 \family typewriter 
10168 /* pointer physically in internal ram pointing to object in external ram
10169  */ 
10170 \newline 
10171 __xdata unsigned char * __data p;
10172 \newline 
10173
10174 \newline 
10175 /* pointer physically in external ram pointing to object in internal ram
10176  */ 
10177 \newline 
10178 __data unsigned char * __xdata p;
10179 \newline 
10180
10181 \newline 
10182 /* pointer physically in code rom pointing to data in xdata space */ 
10183 \newline 
10184 __xdata unsigned char * __code p;
10185 \newline 
10186
10187 \newline 
10188 /* pointer physically in code space pointing to data in code space */ 
10189 \newline 
10190 __code unsigned char * __code p;
10191 \newline 
10192
10193 \newline 
10194 /* generic pointer physically located in xdata space */
10195 \newline 
10196 unsigned char * __xdata p;
10197 \newline 
10198
10199 \newline 
10200 /* generic pointer physically located in default memory space */
10201 \newline 
10202 unsigned char * p;
10203 \newline 
10204
10205 \newline 
10206 /* the following is a function pointer
10207 \begin_inset LatexCommand \index{function pointer}
10208
10209 \end_inset 
10210
10211  physically located in data space */
10212 \newline 
10213 char (* __data fp)(void);
10214 \layout Standard
10215
10216 Well you get the idea.
10217  
10218 \newline 
10219
10220 \newline 
10221 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10222 \emph on 
10223 generic
10224 \emph default 
10225  pointers.
10226  
10227 \size small 
10228
10229 \newline 
10230
10231 \newline 
10232
10233 \size default 
10234 The highest order byte of the 
10235 \emph on 
10236 generic
10237 \emph default 
10238  pointers contains the data space information.
10239  Assembler support routines are called whenever data is stored or retrieved
10240  using 
10241 \emph on 
10242 generic
10243 \emph default 
10244  pointers.
10245  These are useful for developing reusable library
10246 \begin_inset LatexCommand \index{Libraries}
10247
10248 \end_inset 
10249
10250  routines.
10251  Explicitly specifying the pointer
10252 \begin_inset LatexCommand \index{pointer}
10253
10254 \end_inset 
10255
10256  type will generate the most efficient code.
10257 \layout Subsubsection
10258
10259 Notes on MCS51 memory
10260 \begin_inset LatexCommand \index{MCS51 memory}
10261
10262 \end_inset 
10263
10264  layout
10265 \layout Standard
10266
10267 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10268  RAM memory which is structured as follows:
10269 \newline 
10270
10271 \newline 
10272 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10273  
10274 \newline 
10275 - Bytes 20-2F - 16 bytes to hold 128 bit
10276 \begin_inset LatexCommand \index{bit}
10277
10278 \end_inset 
10279
10280  variables and, 
10281 \newline 
10282 - Bytes 30-7F - 80 bytes for general purpose use.
10283 \newline 
10284
10285 \layout Standard
10286
10287 Additionally some members of the MCS51 family may have up to 128 bytes of
10288  additional, indirectly addressable, internal RAM memory (
10289 \emph on 
10290 idata
10291 \emph default 
10292
10293 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10294
10295 \end_inset 
10296
10297
10298 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10299
10300 \end_inset 
10301
10302 ).
10303  Furthermore, some chips may have some built in external memory (
10304 \emph on 
10305 xdata
10306 \emph default 
10307
10308 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10309
10310 \end_inset 
10311
10312
10313 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10314
10315 \end_inset 
10316
10317 ) which should not be confused with the internal, directly addressable RAM
10318  memory (
10319 \emph on 
10320 data
10321 \emph default 
10322
10323 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10324
10325 \end_inset 
10326
10327
10328 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10329
10330 \end_inset 
10331
10332 ).
10333  Sometimes this built in 
10334 \emph on 
10335 xdata
10336 \emph default 
10337  memory has to be activated before using it (you can probably find this
10338  information on the datasheet of the microcontroller your are using, see
10339  also section 
10340 \begin_inset LatexCommand \ref{sub:Startup-Code}
10341
10342 \end_inset 
10343
10344 \SpecialChar ~
10345 Startup-Code).
10346 \layout Standard
10347
10348 Normally SDCC will only use the first bank
10349 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10350
10351 \end_inset 
10352
10353  of registers (register bank 0), but it is possible to specify that other
10354  banks of registers (keyword 
10355 \emph on 
10356 using
10357 \emph default 
10358  
10359 \emph on 
10360
10361 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10362
10363 \end_inset 
10364
10365
10366 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10367
10368 \end_inset 
10369
10370
10371 \emph default 
10372 ) should be used in interrupt
10373 \begin_inset LatexCommand \index{interrupt}
10374
10375 \end_inset 
10376
10377
10378 \begin_inset LatexCommand \index{\_\_interrupt}
10379
10380 \end_inset 
10381
10382  routines.
10383  By default, the compiler will place the stack after the last byte of allocated
10384  memory for variables.
10385  For example, if the first 2 banks of registers are used, and only four
10386  bytes are used for 
10387 \emph on 
10388 data
10389 \emph default 
10390  variables, it will position the base of the internal stack at address 20
10391  (0x14).
10392  This implies that as the stack
10393 \begin_inset LatexCommand \index{stack}
10394
10395 \end_inset 
10396
10397  grows, it will use up the remaining register banks, and the 16 bytes used
10398  by the 128 bit variables, and 80 bytes for general purpose use.
10399  If any bit variables are used, the data variables will be placed in unused
10400  register banks and after the byte holding the last bit variable.
10401  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10402  (two bytes used), 
10403 \emph on 
10404 data
10405 \emph default 
10406  variables will be placed starting from address 0x10 to 0x20 and continue
10407  at address 0x22.
10408  You can also use -
10409 \begin_inset ERT
10410 status Collapsed
10411
10412 \layout Standard
10413
10414 \backslash 
10415 /
10416 \end_inset 
10417
10418 -data-loc
10419 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10420
10421 \end_inset 
10422
10423  to specify the start address of the 
10424 \emph on 
10425 data
10426 \emph default 
10427  and -
10428 \begin_inset ERT
10429 status Collapsed
10430
10431 \layout Standard
10432
10433 \backslash 
10434 /
10435 \end_inset 
10436
10437 -iram-size
10438 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10439
10440 \end_inset 
10441
10442  to specify the size of the total internal RAM (
10443 \emph on 
10444 data
10445 \emph default 
10446 +
10447 \emph on 
10448 idata
10449 \emph default 
10450 ).
10451  
10452 \newline 
10453
10454 \layout Standard
10455
10456 By default the 8051 linker will place the stack after the last byte of (i)data
10457  variables.
10458  Option -
10459 \begin_inset ERT
10460 status Collapsed
10461
10462 \layout Standard
10463
10464 \backslash 
10465 /
10466 \end_inset 
10467
10468 -stack-loc
10469 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10470
10471 \end_inset 
10472
10473  allows you to specify the start of the stack, i.e.
10474  you could start it after any data in the general purpose area.
10475  If your microcontroller has additional indirectly addressable internal
10476  RAM (
10477 \emph on 
10478 idata
10479 \emph default 
10480 ) you can place the stack on it.
10481  You may also need to use -
10482 \begin_inset ERT
10483 status Collapsed
10484
10485 \layout Standard
10486
10487 \backslash 
10488 /
10489 \end_inset 
10490
10491 -xdata-loc
10492 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10493
10494 \end_inset 
10495
10496  to set the start address of the external RAM (
10497 \emph on 
10498 xdata
10499 \emph default 
10500 ) and -
10501 \begin_inset ERT
10502 status Collapsed
10503
10504 \layout Standard
10505
10506 \backslash 
10507 /
10508 \end_inset 
10509
10510 -xram-size
10511 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10512
10513 \end_inset 
10514
10515  to specify its size.
10516  Same goes for the code memory, using -
10517 \begin_inset ERT
10518 status Collapsed
10519
10520 \layout Standard
10521
10522 \backslash 
10523 /
10524 \end_inset 
10525
10526 -code-loc
10527 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10528
10529 \end_inset 
10530
10531  and -
10532 \begin_inset ERT
10533 status Collapsed
10534
10535 \layout Standard
10536
10537 \backslash 
10538 /
10539 \end_inset 
10540
10541 -code-size
10542 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10543
10544 \end_inset 
10545
10546 .
10547  If in doubt, don't specify any options and see if the resulting memory
10548  layout is appropriate, then you can adjust it.
10549 \layout Standard
10550 \added_space_bottom bigskip 
10551 The linker generates two files with memory allocation information.
10552  The first, with extension .map
10553 \begin_inset LatexCommand \index{<file>.map}
10554
10555 \end_inset 
10556
10557  shows all the variables and segments.
10558  The second with extension .mem
10559 \begin_inset LatexCommand \index{<file>.mem}
10560
10561 \end_inset 
10562
10563  shows the final memory layout.
10564  The linker will complain either if memory segments overlap, there is not
10565  enough memory, or there is not enough space for stack.
10566  If you get any linking warnings and/or errors related to stack or segments
10567  allocation, take a look at either the .map or .mem files to find out what
10568  the problem is.
10569  The .mem file may even suggest a solution to the problem.
10570 \layout Subsection
10571
10572 Z80/Z180 Storage Class
10573 \begin_inset LatexCommand \index{Z80!Storage class}
10574
10575 \end_inset 
10576
10577  Language Extensions
10578 \layout Subsubsection
10579
10580 sfr
10581 \begin_inset LatexCommand \index{sfr}
10582
10583 \end_inset 
10584
10585
10586 \begin_inset LatexCommand \index{\_\_sfr}
10587
10588 \end_inset 
10589
10590  (in/out to 8-bit addresses)
10591 \layout Standard
10592
10593 The Z80
10594 \begin_inset LatexCommand \index{Z80}
10595
10596 \end_inset 
10597
10598  family has separate address spaces for memory and 
10599 \emph on 
10600 i
10601 \emph default 
10602 nput/
10603 \emph on 
10604 o
10605 \emph default 
10606 utput memory.
10607  I/O memory
10608 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10609
10610 \end_inset 
10611
10612
10613 \begin_inset LatexCommand \index{Z80!I/O memory}
10614
10615 \end_inset 
10616
10617
10618 \begin_inset LatexCommand \index{Z180!I/O memory}
10619
10620 \end_inset 
10621
10622  is accessed with special instructions, e.g.:
10623 \layout Verse
10624
10625
10626 \family typewriter 
10627 sfr at 0x78 IoPort;\SpecialChar ~
10628 \SpecialChar ~
10629 /* define a var in I/O space at 78h called IoPort */
10630  
10631 \layout Standard
10632
10633 Writing 0x01 to this variable generates the assembly code:
10634 \layout Verse
10635
10636
10637 \family typewriter 
10638 3E 01\SpecialChar ~
10639 \SpecialChar ~
10640 \SpecialChar ~
10641 \SpecialChar ~
10642 \SpecialChar ~
10643 \SpecialChar ~
10644 ld a,#0x01
10645 \newline 
10646 D3 78\SpecialChar ~
10647 \SpecialChar ~
10648 \SpecialChar ~
10649 \SpecialChar ~
10650 \SpecialChar ~
10651 \SpecialChar ~
10652 out (_IoPort),a 
10653 \layout Subsubsection
10654
10655 banked sfr
10656 \begin_inset LatexCommand \index{sfr}
10657
10658 \end_inset 
10659
10660
10661 \begin_inset LatexCommand \index{\_\_sfr}
10662
10663 \end_inset 
10664
10665  (in/out to 16-bit addresses)
10666 \layout Standard
10667
10668 The keyword 
10669 \emph on 
10670 banked
10671 \emph default 
10672  is used to support 16 bit addresses in I/O memory e.g.:
10673 \layout Verse
10674
10675
10676 \family typewriter 
10677 sfr banked at
10678 \begin_inset LatexCommand \index{at}
10679
10680 \end_inset 
10681
10682
10683 \begin_inset LatexCommand \index{\_\_at}
10684
10685 \end_inset 
10686
10687  0x123 IoPort; 
10688 \layout Standard
10689
10690 Writing 0x01 to this variable generates the assembly code:
10691 \layout Verse
10692
10693
10694 \family typewriter 
10695 01 23 01\SpecialChar ~
10696 \SpecialChar ~
10697 \SpecialChar ~
10698 ld bc,#_IoPort
10699 \newline 
10700 3E 01\SpecialChar ~
10701 \SpecialChar ~
10702 \SpecialChar ~
10703 \SpecialChar ~
10704 \SpecialChar ~
10705 \SpecialChar ~
10706 ld a,#0x01 
10707 \newline 
10708 ED 79\SpecialChar ~
10709 \SpecialChar ~
10710 \SpecialChar ~
10711 \SpecialChar ~
10712 \SpecialChar ~
10713 \SpecialChar ~
10714 out (c),a 
10715 \layout Subsubsection
10716
10717 sfr
10718 \begin_inset LatexCommand \index{sfr}
10719
10720 \end_inset 
10721
10722
10723 \begin_inset LatexCommand \index{\_\_sfr}
10724
10725 \end_inset 
10726
10727  (in0/out0 to 8 bit addresses on Z180
10728 \begin_inset LatexCommand \index{Z180}
10729
10730 \end_inset 
10731
10732 /HD64180
10733 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10734
10735 \end_inset 
10736
10737 )
10738 \layout Standard
10739 \added_space_bottom bigskip 
10740 The compiler option -
10741 \begin_inset ERT
10742 status Collapsed
10743
10744 \layout Standard
10745
10746 \backslash 
10747 /
10748 \end_inset 
10749
10750 -portmode
10751 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10752
10753 \end_inset 
10754
10755 =180 (80) and a compiler #pragma\SpecialChar ~
10756 portmode
10757 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10758
10759 \end_inset 
10760
10761  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10762 ns 
10763 \family typewriter 
10764 in0/out0
10765 \family default 
10766  instead of 
10767 \family typewriter 
10768 in/out
10769 \family default 
10770 .
10771  If you include the file z180.h this will be set automatically.
10772 \layout Subsection
10773
10774 HC08 Storage Class
10775 \begin_inset LatexCommand \index{HC08!Storage class}
10776
10777 \end_inset 
10778
10779  Language Extensions
10780 \layout Subsubsection
10781
10782 data
10783 \begin_inset LatexCommand \index{data (hc08 storage class)}
10784
10785 \end_inset 
10786
10787
10788 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10789
10790 \end_inset 
10791
10792  
10793 \layout Standard
10794
10795 The data storage class declares a variable that resides in the first 256
10796  bytes of memory (the direct page).
10797  The HC08
10798 \begin_inset LatexCommand \index{HC08}
10799
10800 \end_inset 
10801
10802  is most efficient at accessing variables (especially pointers) stored here.
10803 \layout Subsubsection
10804
10805 xdata
10806 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10807
10808 \end_inset 
10809
10810
10811 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10812
10813 \end_inset 
10814
10815  
10816 \layout Standard
10817 \added_space_bottom bigskip 
10818 The xdata storage class declares a variable that can reside anywhere in
10819  memory.
10820  This is the default if no storage class is specified.
10821  
10822 \layout Section
10823
10824 Absolute Addressing
10825 \begin_inset LatexCommand \index{Absolute addressing}
10826
10827 \end_inset 
10828
10829
10830 \layout Standard
10831
10832 Data items can be assigned an absolute address with the 
10833 \emph on 
10834 at
10835 \begin_inset LatexCommand \index{at}
10836
10837 \end_inset 
10838
10839
10840 \begin_inset LatexCommand \index{\_\_at}
10841
10842 \end_inset 
10843
10844  <address>
10845 \emph default 
10846  keyword, in addition to a storage class, e.g.:
10847 \layout Verse
10848
10849
10850 \family typewriter 
10851 xdata
10852 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10853
10854 \end_inset 
10855
10856
10857 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10858
10859 \end_inset 
10860
10861  at
10862 \begin_inset LatexCommand \index{at}
10863
10864 \end_inset 
10865
10866
10867 \begin_inset LatexCommand \index{\_\_at}
10868
10869 \end_inset 
10870
10871  0x7ffe unsigned int chksum;
10872 \layout Standard
10873
10874 or, better conforming to ISO/IEC 9899 C:
10875 \layout Verse
10876
10877
10878 \family typewriter 
10879 __xdata __at (0x7ffe) unsigned int chksum;
10880 \layout Standard
10881
10882 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10883  of the external ram.
10884  The compiler does 
10885 \emph on 
10886 not
10887 \emph default 
10888  reserve any space for variables declared in this way
10889 \begin_inset Marginal
10890 collapsed true
10891
10892 \layout Standard
10893
10894
10895 \series bold 
10896 \SpecialChar ~
10897 !
10898 \end_inset 
10899
10900  (they are implemented with an equate in the assembler).
10901  Thus it is left to the programmer to make sure there are no overlaps with
10902  other variables that are declared without the absolute address.
10903  The assembler listing file (.lst
10904 \begin_inset LatexCommand \index{<file>.lst}
10905
10906 \end_inset 
10907
10908 ) and the linker output files (.rst
10909 \begin_inset LatexCommand \index{<file>.rst}
10910
10911 \end_inset 
10912
10913 ) and (.map
10914 \begin_inset LatexCommand \index{<file>.map}
10915
10916 \end_inset 
10917
10918 ) are good places to look for such overlaps.
10919  Variables with an absolute address are 
10920 \emph on 
10921 not
10922 \begin_inset Marginal
10923 collapsed true
10924
10925 \layout Standard
10926
10927
10928 \series bold 
10929 \SpecialChar ~
10930 !
10931 \end_inset 
10932
10933
10934 \emph default 
10935  initialized
10936 \begin_inset LatexCommand \index{Variable initialization}
10937
10938 \end_inset 
10939
10940 .
10941 \layout Standard
10942
10943 In case of memory mapped I/O devices the keyword 
10944 \emph on 
10945 volatile
10946 \emph default 
10947  has to be used to tell the compiler that accesses might not be removed:
10948 \layout Verse
10949
10950
10951 \family typewriter 
10952 volatile
10953 \begin_inset LatexCommand \index{volatile}
10954
10955 \end_inset 
10956
10957  __xdata
10958 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10959
10960 \end_inset 
10961
10962  __at
10963 \begin_inset LatexCommand \index{at}
10964
10965 \end_inset 
10966
10967  (0x8000) unsigned char PORTA_8255;
10968 \layout Standard
10969
10970 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10971 r) array
10972 \family typewriter 
10973 \size footnotesize 
10974
10975 \begin_inset LatexCommand \index{Aligned array}
10976
10977 \end_inset 
10978
10979
10980 \family default 
10981 \size default 
10982  starts at a block (256 byte) boundary
10983 \begin_inset LatexCommand \index{block boundary}
10984
10985 \end_inset 
10986
10987  (section 
10988 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10989
10990 \end_inset 
10991
10992  has an example).
10993 \newline 
10994 Absolute addresses can be specified for variables in all storage classes,
10995  e.g.:
10996 \layout Verse
10997
10998
10999 \family typewriter 
11000 __bit
11001 \begin_inset LatexCommand \index{bit}
11002
11003 \end_inset 
11004
11005  __at
11006 \begin_inset LatexCommand \index{at}
11007
11008 \end_inset 
11009
11010  (0x02) bvar;
11011 \layout Standard
11012
11013 The above example will allocate the variable at offset 0x02 in the bit-addressab
11014 le space.
11015  There is no real advantage to assigning absolute addresses to variables
11016  in this manner, unless you want strict control over all the variables allocated.
11017  One possible use would be to write hardware portable code.
11018  For example, if you have a routine that uses one or more of the microcontroller
11019  I/O pins, and such pins are different for two different hardwares, you
11020  can declare the I/O pins in your routine using:
11021 \layout Verse
11022
11023
11024 \family typewriter 
11025 extern volatile
11026 \begin_inset LatexCommand \index{volatile}
11027
11028 \end_inset 
11029
11030  __bit MOSI;\SpecialChar ~
11031 \SpecialChar ~
11032 \SpecialChar ~
11033 \SpecialChar ~
11034 /* master out, slave in */
11035 \newline 
11036 extern volatile __bit MISO;\SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 /* master in, slave out */
11041 \newline 
11042 extern volatile __bit MCLK;\SpecialChar ~
11043 \SpecialChar ~
11044 \SpecialChar ~
11045 \SpecialChar ~
11046 /* master clock */
11047 \newline 
11048
11049 \newline 
11050 /* Input and Output of a byte on a 3-wire serial bus.
11051 \newline 
11052 \SpecialChar ~
11053 \SpecialChar ~
11054 \SpecialChar ~
11055 If needed adapt polarity of clock, polarity of data and bit order
11056 \newline 
11057 \SpecialChar ~
11058 */
11059 \newline 
11060 unsigned char spi_io(unsigned char out_byte) 
11061 \newline 
11062
11063 \newline 
11064 \SpecialChar ~
11065 \SpecialChar ~
11066 \SpecialChar ~
11067 \SpecialChar ~
11068 unsigned char i=8;
11069 \newline 
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 do { 
11075 \newline 
11076 \SpecialChar ~
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 MOSI = out_byte & 0x80; 
11085 \newline 
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 \SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 \SpecialChar ~
11093 \SpecialChar ~
11094 out_byte <<= 1;
11095 \newline 
11096 \SpecialChar ~
11097 \SpecialChar ~
11098 \SpecialChar ~
11099 \SpecialChar ~
11100 \SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 MCLK = 1; 
11105 \newline 
11106 \SpecialChar ~
11107 \SpecialChar ~
11108 \SpecialChar ~
11109 \SpecialChar ~
11110 \SpecialChar ~
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 /* _asm nop _endasm; */\SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 /* for slow peripherals */
11123 \newline 
11124 \SpecialChar ~
11125 \SpecialChar ~
11126 \SpecialChar ~
11127 \SpecialChar ~
11128 \SpecialChar ~
11129 \SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 if(MISO) 
11133 \newline 
11134 \SpecialChar ~
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 \SpecialChar ~
11139 \SpecialChar ~
11140 \SpecialChar ~
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 out_byte += 1; 
11147 \newline 
11148 \SpecialChar ~
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 \SpecialChar ~
11154 \SpecialChar ~
11155 \SpecialChar ~
11156 MCLK = 0; 
11157 \newline 
11158 \SpecialChar ~
11159 \SpecialChar ~
11160 \SpecialChar ~
11161 \SpecialChar ~
11162 } while(--i);
11163 \newline 
11164 \SpecialChar ~
11165 \SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 return out_byte; 
11169 \newline 
11170 }
11171 \layout Standard
11172
11173 Then, someplace in the code for the first hardware you would use
11174 \layout Verse
11175
11176
11177 \family typewriter 
11178 __bit __at
11179 \begin_inset LatexCommand \index{at}
11180
11181 \end_inset 
11182
11183
11184 \begin_inset LatexCommand \index{\_\_at}
11185
11186 \end_inset 
11187
11188  (0x80) MOSI;\SpecialChar ~
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 \SpecialChar ~
11192 /* I/O port 0, bit 0 */
11193 \newline 
11194 __bit __at (0x81) MISO;\SpecialChar ~
11195 \SpecialChar ~
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 /* I/O port 0, bit 1 */
11199 \newline 
11200 __bit __at (0x82) MCLK;\SpecialChar ~
11201 \SpecialChar ~
11202 \SpecialChar ~
11203 \SpecialChar ~
11204 /* I/O port 0, bit 2 */
11205 \layout Standard
11206
11207 Similarly, for the second hardware you would use
11208 \layout Verse
11209
11210
11211 \family typewriter 
11212 __bit __at (0x83) MOSI;\SpecialChar ~
11213 \SpecialChar ~
11214 \SpecialChar ~
11215 \SpecialChar ~
11216 /* I/O port 0, bit 3 */
11217 \newline 
11218 __bit __at (0x91) MISO;\SpecialChar ~
11219 \SpecialChar ~
11220 \SpecialChar ~
11221 \SpecialChar ~
11222 /* I/O port 1, bit 1 */
11223 \newline 
11224 __bit
11225 \begin_inset LatexCommand \index{bit}
11226
11227 \end_inset 
11228
11229  __at (0x92) MCLK;\SpecialChar ~
11230 \SpecialChar ~
11231 \SpecialChar ~
11232 \SpecialChar ~
11233 /* I/O port 1, bit 2 */
11234 \layout Standard
11235 \added_space_bottom bigskip 
11236 and you can use the same hardware dependent routine without changes, as
11237  for example in a library.
11238  This is somehow similar to sbit, but only one absolute address has to be
11239  specified in the whole project.
11240 \layout Section
11241
11242 Parameters
11243 \begin_inset LatexCommand \index{Parameters}
11244
11245 \end_inset 
11246
11247
11248 \begin_inset LatexCommand \index{function parameter}
11249
11250 \end_inset 
11251
11252  & Local Variables
11253 \begin_inset LatexCommand \index{local variables}
11254
11255 \end_inset 
11256
11257
11258 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11259
11260 \end_inset 
11261
11262
11263 \layout Standard
11264
11265 Automatic (local) variables and parameters to functions can either be placed
11266  on the stack or in data-space.
11267  The default action of the compiler is to place these variables in the internal
11268  RAM (for small model) or external RAM (for large model).
11269  This in fact makes them similar to 
11270 \emph on 
11271 static
11272 \begin_inset LatexCommand \index{static}
11273
11274 \end_inset 
11275
11276
11277 \emph default 
11278  so by default functions are non-reentrant
11279 \begin_inset LatexCommand \index{reentrant}
11280
11281 \end_inset 
11282
11283 .
11284  
11285 \newline 
11286
11287 \newline 
11288 They can be placed on the stack
11289 \begin_inset LatexCommand \index{stack}
11290
11291 \end_inset 
11292
11293  by using the
11294 \emph on 
11295  -
11296 \begin_inset ERT
11297 status Collapsed
11298
11299 \layout Standard
11300
11301 \backslash 
11302 /
11303 \end_inset 
11304
11305 -stack-auto
11306 \begin_inset LatexCommand \index{-\/-stack-auto}
11307
11308 \end_inset 
11309
11310
11311 \emph default 
11312  option, by using 
11313 \emph on 
11314 #pragma\SpecialChar ~
11315 stackauto
11316 \emph default 
11317
11318 \begin_inset LatexCommand \index{\#pragma stackauto}
11319
11320 \end_inset 
11321
11322  or by using the 
11323 \emph on 
11324 reentrant
11325 \begin_inset LatexCommand \index{reentrant}
11326
11327 \end_inset 
11328
11329
11330 \emph default 
11331  keyword in the function declaration, e.g.:
11332 \layout Verse
11333
11334
11335 \family typewriter 
11336 unsigned char foo(char i) __reentrant 
11337 \newline 
11338
11339 \newline 
11340 \SpecialChar ~
11341 \SpecialChar ~
11342 \SpecialChar ~
11343 \SpecialChar ~
11344 ...
11345  
11346 \newline 
11347 }
11348 \layout Standard
11349
11350 Since stack space on 8051 is limited, the 
11351 \emph on 
11352 reentrant 
11353 \emph default 
11354 keyword or the
11355 \emph on 
11356  -
11357 \begin_inset ERT
11358 status Collapsed
11359
11360 \layout Standard
11361
11362 \backslash 
11363 /
11364 \end_inset 
11365
11366 -stack-auto
11367 \emph default 
11368  option should be used sparingly.
11369  Note that the reentrant keyword just means that the parameters & local
11370  variables will be allocated to the stack, it 
11371 \emph on 
11372 does not
11373 \emph default 
11374  mean that the function is register bank
11375 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11376
11377 \end_inset 
11378
11379  independent.
11380 \newline 
11381
11382 \newline 
11383 Local variables
11384 \begin_inset LatexCommand \index{local variables}
11385
11386 \end_inset 
11387
11388  can be assigned storage classes and absolute
11389 \begin_inset LatexCommand \index{Absolute addressing}
11390
11391 \end_inset 
11392
11393  addresses, e.g.: 
11394 \layout Verse
11395
11396
11397 \family typewriter 
11398 unsigned char foo() 
11399 \newline 
11400 {
11401 \newline 
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 \SpecialChar ~
11405 \SpecialChar ~
11406 __xdata unsigned char i;
11407 \newline 
11408 \SpecialChar ~
11409 \SpecialChar ~
11410 \SpecialChar ~
11411 \SpecialChar ~
11412 __bit bvar;
11413 \newline 
11414 \SpecialChar ~
11415 \SpecialChar ~
11416 \SpecialChar ~
11417 \SpecialChar ~
11418 __data __at
11419 \begin_inset LatexCommand \index{at}
11420
11421 \end_inset 
11422
11423  (0x31) unsigned char j;
11424 \newline 
11425 \SpecialChar ~
11426 \SpecialChar ~
11427 \SpecialChar ~
11428 \SpecialChar ~
11429 ...
11430  
11431 \newline 
11432 }
11433 \layout Standard
11434
11435 In the above example the variable 
11436 \emph on 
11437 i
11438 \emph default 
11439  will be allocated in the external ram, 
11440 \emph on 
11441 bvar
11442 \emph default 
11443  in bit addressable space and
11444 \emph on 
11445  j
11446 \emph default 
11447  in internal ram.
11448  When compiled with 
11449 \emph on 
11450 -
11451 \begin_inset ERT
11452 status Collapsed
11453
11454 \layout Standard
11455
11456 \backslash 
11457 /
11458 \end_inset 
11459
11460 -stack-auto
11461 \emph default 
11462  or when a function is declared as 
11463 \emph on 
11464 reentrant
11465 \emph default 
11466  this should only be done for static variables.
11467 \layout Standard
11468
11469 Parameters
11470 \begin_inset LatexCommand \index{function parameter}
11471
11472 \end_inset 
11473
11474  however are not allowed any storage class
11475 \begin_inset LatexCommand \index{Storage class}
11476
11477 \end_inset 
11478
11479 , (storage classes for parameters will be ignored), their allocation is
11480  governed by the memory model in use, and the reentrancy options.
11481 \layout Standard
11482
11483 It is however allowed to use bit parameters in reentrant functions and also
11484  non-static local bit variables are supported.
11485  Efficient use is limited to 8 semi-bitregisters in bit space.
11486  They are pushed and popped to stack
11487 \begin_inset LatexCommand \index{stack}
11488
11489 \end_inset 
11490
11491  as a single byte just like the normal registers.
11492 \layout Section
11493
11494 Overlaying
11495 \begin_inset LatexCommand \label{sub:Overlaying}
11496
11497 \end_inset 
11498
11499
11500 \begin_inset LatexCommand \index{Overlaying}
11501
11502 \end_inset 
11503
11504
11505 \layout Standard
11506
11507 For non-reentrant
11508 \begin_inset LatexCommand \index{reentrant}
11509
11510 \end_inset 
11511
11512  functions SDCC will try to reduce internal ram space usage by overlaying
11513  parameters and local variables of a function (if possible).
11514  Parameters and local variables
11515 \begin_inset LatexCommand \index{local variables}
11516
11517 \end_inset 
11518
11519  of a function will be allocated to an overlayable segment if the function
11520  has 
11521 \emph on 
11522 no other function calls and the function is non-reentrant and the memory
11523  model
11524 \begin_inset LatexCommand \index{Memory model}
11525
11526 \end_inset 
11527
11528  is small.
11529
11530 \emph default 
11531  If an explicit storage class
11532 \begin_inset LatexCommand \index{Storage class}
11533
11534 \end_inset 
11535
11536  is specified for a local variable, it will NOT be overlayed.
11537 \layout Standard
11538
11539 Note that the compiler (not the linkage editor) makes the decision for overlayin
11540 g the data items.
11541  Functions that are called from an interrupt service routine
11542 \begin_inset Marginal
11543 collapsed true
11544
11545 \layout Standard
11546
11547
11548 \series bold 
11549 !
11550 \end_inset 
11551
11552  should be preceded by a #pragma\SpecialChar ~
11553 nooverlay
11554 \begin_inset LatexCommand \index{\#pragma nooverlay}
11555
11556 \end_inset 
11557
11558  if they are not reentrant.
11559 \layout Standard
11560
11561 Also note that the compiler does not do any processing of inline assembler
11562  code, so the compiler might incorrectly assign local variables and parameters
11563  of a function into the overlay segment if the inline assembler code calls
11564  other c-functions that might use the overlay.
11565  In that case the #pragma\SpecialChar ~
11566 nooverlay should be used.
11567 \layout Standard
11568
11569 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11570 tion
11571 \begin_inset LatexCommand \index{Multiplication}
11572
11573 \end_inset 
11574
11575  or division
11576 \begin_inset LatexCommand \index{Division}
11577
11578 \end_inset 
11579
11580  will NOT be overlayed since these are implemented using external functions,
11581  e.g.:
11582 \layout Verse
11583
11584
11585 \family typewriter 
11586 #pragma save 
11587 \newline 
11588 #pragma nooverlay
11589 \begin_inset LatexCommand \index{\#pragma nooverlay}
11590
11591 \end_inset 
11592
11593  
11594 \newline 
11595 void set_error(unsigned char errcd) 
11596 \newline 
11597 {
11598 \newline 
11599 \SpecialChar ~
11600 \SpecialChar ~
11601 \SpecialChar ~
11602 \SpecialChar ~
11603 P3 = errcd;
11604 \newline 
11605
11606 \newline 
11607 #pragma restore 
11608 \newline 
11609
11610 \newline 
11611 void some_isr () __interrupt
11612 \begin_inset LatexCommand \index{interrupt}
11613
11614 \end_inset 
11615
11616  (2)
11617 \newline 
11618 {
11619 \newline 
11620 \SpecialChar ~
11621 \SpecialChar ~
11622 \SpecialChar ~
11623 \SpecialChar ~
11624 ...
11625 \newline 
11626 \SpecialChar ~
11627 \SpecialChar ~
11628 \SpecialChar ~
11629 \SpecialChar ~
11630 set_error(10);
11631 \newline 
11632 \SpecialChar ~
11633 \SpecialChar ~
11634 \SpecialChar ~
11635 \SpecialChar ~
11636 ...
11637  
11638 \newline 
11639 }
11640 \layout Standard
11641 \added_space_bottom bigskip 
11642 In the above example the parameter 
11643 \emph on 
11644 errcd
11645 \emph default 
11646  for the function 
11647 \emph on 
11648 set_error
11649 \emph default 
11650  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11651 nooverlay was
11652  not present, this could cause unpredictable runtime behavior when called
11653  from an interrupt service routine.
11654  The #pragma\SpecialChar ~
11655 nooverlay ensures that the parameters and local variables for
11656  the function are NOT overlayed.
11657 \layout Section
11658
11659 Interrupt Service Routines
11660 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11661
11662 \end_inset 
11663
11664
11665 \layout Subsection
11666
11667 General Information
11668 \layout Standard
11669
11670 SDCC allows 
11671 \emph on 
11672 i
11673 \emph default 
11674 nterrupt 
11675 \emph on 
11676 s
11677 \emph default 
11678 ervice 
11679 \emph on 
11680 r
11681 \emph default 
11682 outines to be coded in C, with some extended keywords.
11683 \layout Verse
11684
11685
11686 \family typewriter 
11687 void timer_isr (void) __interrupt (1) __using (1) 
11688 \newline 
11689
11690 \newline 
11691 \SpecialChar ~
11692 \SpecialChar ~
11693 \SpecialChar ~
11694 \SpecialChar ~
11695 ...
11696  
11697 \newline 
11698 }
11699 \layout Standard
11700
11701 The optional number following the 
11702 \emph on 
11703 interrupt
11704 \begin_inset LatexCommand \index{interrupt}
11705
11706 \end_inset 
11707
11708
11709 \begin_inset LatexCommand \index{\_\_interrupt}
11710
11711 \end_inset 
11712
11713
11714 \emph default 
11715  keyword is the interrupt number this routine will service.
11716  When present, the compiler will insert a call to this routine in the interrupt
11717  vector table
11718 \begin_inset LatexCommand \index{interrupt vector table}
11719
11720 \end_inset 
11721
11722  for the interrupt number specified.
11723  If you have multiple source files in your project, interrupt service routines
11724  can be present in any of them, but a prototype of the isr MUST be present
11725  or included in the file that contains the function 
11726 \emph on 
11727 main
11728 \emph default 
11729 .
11730  The optional (8051 specific) keyword 
11731 \emph on 
11732 using
11733 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11734
11735 \end_inset 
11736
11737
11738 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11739
11740 \end_inset 
11741
11742
11743 \emph default 
11744  can be used to tell the compiler to use the specified register bank when
11745  generating code for this function.
11746  
11747 \newline 
11748 Interrupt service routines open the door for some very interesting bugs:
11749 \layout Subsubsection
11750
11751
11752 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11753
11754 \end_inset 
11755
11756 Common interrupt pitfall: variable not declared 
11757 \emph on 
11758 volatile
11759 \layout Standard
11760
11761 If an interrupt service routine changes variables which are accessed by
11762  other functions these variables have to be declared 
11763 \emph on 
11764 volatile
11765 \emph default 
11766
11767 \begin_inset LatexCommand \index{volatile}
11768
11769 \end_inset 
11770
11771 .
11772  See 
11773 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11774
11775 \end_inset 
11776
11777  .
11778 \layout Subsubsection
11779
11780
11781 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11782
11783 \end_inset 
11784
11785 Common interrupt pitfall: 
11786 \emph on 
11787 non-atomic access
11788 \layout Standard
11789
11790 If the access to these variables is not 
11791 \emph on 
11792 atomic
11793 \begin_inset LatexCommand \index{atomic}
11794
11795 \end_inset 
11796
11797
11798 \emph default 
11799  (i.e.
11800  the processor needs more than one instruction for the access and could
11801  be interrupted while accessing the variable) the interrupt must be disabled
11802  during the access to avoid inconsistent data.
11803  
11804 \newline 
11805 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11806  should be protected by disabling interrupts.
11807  You're not automatically on the safe side if you use 8 bit variables though.
11808  We need an example here: f.e.
11809  on the 8051 the harmless looking 
11810 \begin_inset Quotes srd
11811 \end_inset 
11812
11813
11814 \family typewriter 
11815 flags\SpecialChar ~
11816 |=\SpecialChar ~
11817 0x80;
11818 \family default 
11819
11820 \begin_inset Quotes sld
11821 \end_inset 
11822
11823  is not atomic if 
11824 \family typewriter 
11825 flags
11826 \family default 
11827  resides in xdata.
11828  Setting 
11829 \begin_inset Quotes srd
11830 \end_inset 
11831
11832
11833 \family typewriter 
11834 flags\SpecialChar ~
11835 |=\SpecialChar ~
11836 0x40;
11837 \family default 
11838
11839 \begin_inset Quotes sld
11840 \end_inset 
11841
11842  from within an interrupt routine might get lost if the interrupt occurs
11843  at the wrong time.
11844  
11845 \begin_inset Quotes sld
11846 \end_inset 
11847
11848
11849 \family typewriter 
11850 counter\SpecialChar ~
11851 +=\SpecialChar ~
11852 8;
11853 \family default 
11854
11855 \begin_inset Quotes srd
11856 \end_inset 
11857
11858  is not atomic on the 8051 even if 
11859 \family typewriter 
11860 counter
11861 \family default 
11862  is located in data memory.
11863 \newline 
11864 Bugs like these are hard to reproduce and can cause a lot of trouble.
11865  
11866 \layout Subsubsection
11867
11868
11869 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11870
11871 \end_inset 
11872
11873 Common interrupt pitfall: 
11874 \emph on 
11875 stack overflow
11876 \layout Standard
11877
11878 The return address and the registers used in the interrupt service routine
11879  are saved on the stack
11880 \begin_inset LatexCommand \index{stack}
11881
11882 \end_inset 
11883
11884  so there must be sufficient stack space.
11885  If there isn't variables or registers (or even the return address itself)
11886  will be corrupted.
11887  This 
11888 \emph on 
11889 stack overflow
11890 \emph default 
11891
11892 \begin_inset LatexCommand \index{stack overflow}
11893
11894 \end_inset 
11895
11896  is most likely to happen if the interrupt occurs during the 
11897 \begin_inset Quotes sld
11898 \end_inset 
11899
11900 deepest
11901 \begin_inset Quotes srd
11902 \end_inset 
11903
11904  subroutine when the stack is already in use for f.e.
11905  many return addresses.
11906 \layout Subsubsection
11907
11908
11909 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11910
11911 \end_inset 
11912
11913 Common interrupt pitfall: 
11914 \emph on 
11915 use of non-reentrant functions
11916 \layout Standard
11917
11918 A special note here, int (16 bit) and long (32 bit) integer division
11919 \begin_inset LatexCommand \index{Division}
11920
11921 \end_inset 
11922
11923 , multiplication
11924 \begin_inset LatexCommand \index{Multiplication}
11925
11926 \end_inset 
11927
11928  & modulus
11929 \begin_inset LatexCommand \index{Modulus}
11930
11931 \end_inset 
11932
11933  and floating-point
11934 \begin_inset LatexCommand \index{Floating point support}
11935
11936 \end_inset 
11937
11938  operations are implemented using external support routines.
11939  If an interrupt service routine needs to do any of these operations then
11940  the support routines (as mentioned in a following section) will have to
11941  be recompiled using the
11942 \emph on 
11943  -
11944 \begin_inset ERT
11945 status Collapsed
11946
11947 \layout Standard
11948
11949 \backslash 
11950 /
11951 \end_inset 
11952
11953 -stack-auto
11954 \begin_inset LatexCommand \index{-\/-stack-auto}
11955
11956 \end_inset 
11957
11958
11959 \emph default 
11960  option and the source file will need to be compiled using the 
11961 \emph on 
11962 -
11963 \begin_inset ERT
11964 status Collapsed
11965
11966 \layout Standard
11967
11968 \backslash 
11969 /
11970 \end_inset 
11971
11972 -int-long-reent
11973 \emph default 
11974
11975 \begin_inset LatexCommand \index{-\/-int-long-reent}
11976
11977 \end_inset 
11978
11979  compiler option.
11980  
11981 \newline 
11982 Note, the type promotion
11983 \begin_inset LatexCommand \index{type promotion}
11984
11985 \end_inset 
11986
11987  required by ANSI C can cause 16 bit routines to be used
11988 \begin_inset Marginal
11989 collapsed true
11990
11991 \layout Standard
11992
11993
11994 \series bold 
11995 \SpecialChar ~
11996 !
11997 \end_inset 
11998
11999  without the programmer being aware of it.
12000  See f.e.
12001  the cast 
12002 \family typewriter 
12003 (unsigned char)(tail-1)
12004 \family default 
12005  within the if clause in section 
12006 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12007
12008 \end_inset 
12009
12010 .
12011 \layout Standard
12012 \added_space_bottom bigskip 
12013 Calling other functions from an interrupt service routine is not recommended,
12014  avoid it if possible.
12015  Note that when some function is called from an interrupt service routine
12016  it should be preceded by a #pragma\SpecialChar ~
12017 nooverlay
12018 \begin_inset LatexCommand \index{\#pragma nooverlay}
12019
12020 \end_inset 
12021
12022  if it is not reentrant.
12023  Furthermore nonreentrant functions should not be called from the main program
12024  while the interrupt service routine might be active.
12025  They also must not be called from low priority interrupt service routines
12026  while a high priority interrupt service routine might be active.
12027  You could use semaphores or make the function
12028 \emph on 
12029  critical
12030 \emph default 
12031  if all parameters are passed in registers.
12032 \newline 
12033  Also see section 
12034 \begin_inset LatexCommand \ref{sub:Overlaying}
12035
12036 \end_inset 
12037
12038 \SpecialChar ~
12039 about Overlaying and section 
12040 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12041
12042 \end_inset 
12043
12044 \SpecialChar ~
12045 about Functions using private register banks.
12046 \layout Subsection
12047
12048 MCS51/DS390 Interrupt Service Routines
12049 \layout Standard
12050
12051 Interrupt
12052 \begin_inset LatexCommand \index{interrupt}
12053
12054 \end_inset 
12055
12056  numbers and the corresponding address & descriptions for the Standard 8051/8052
12057  are listed below.
12058  SDCC will automatically adjust the 
12059 \begin_inset LatexCommand \index{interrupt vector table}
12060
12061 \end_inset 
12062
12063  to the maximum interrupt number specified.
12064 \newline 
12065
12066 \layout Standard
12067 \align center 
12068
12069 \begin_inset  Tabular
12070 <lyxtabular version="3" rows="9" columns="3">
12071 <features>
12072 <column alignment="center" valignment="top" leftline="true" width="0in">
12073 <column alignment="left" valignment="top" leftline="true" width="0in">
12074 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12075 <row topline="true" bottomline="true">
12076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12077 \begin_inset Text
12078
12079 \layout Standard
12080
12081 Interrupt #
12082 \end_inset 
12083 </cell>
12084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12085 \begin_inset Text
12086
12087 \layout Standard
12088
12089 Description
12090 \end_inset 
12091 </cell>
12092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12093 \begin_inset Text
12094
12095 \layout Standard
12096
12097 Vector Address
12098 \end_inset 
12099 </cell>
12100 </row>
12101 <row topline="true">
12102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12103 \begin_inset Text
12104
12105 \layout Standard
12106
12107 0
12108 \end_inset 
12109 </cell>
12110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12111 \begin_inset Text
12112
12113 \layout Standard
12114
12115 External 0
12116 \end_inset 
12117 </cell>
12118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12119 \begin_inset Text
12120
12121 \layout Standard
12122
12123 0x0003
12124 \end_inset 
12125 </cell>
12126 </row>
12127 <row topline="true">
12128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12129 \begin_inset Text
12130
12131 \layout Standard
12132
12133 1
12134 \end_inset 
12135 </cell>
12136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12137 \begin_inset Text
12138
12139 \layout Standard
12140
12141 Timer 0
12142 \end_inset 
12143 </cell>
12144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12145 \begin_inset Text
12146
12147 \layout Standard
12148
12149 0x000b
12150 \end_inset 
12151 </cell>
12152 </row>
12153 <row topline="true">
12154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12155 \begin_inset Text
12156
12157 \layout Standard
12158
12159 2
12160 \end_inset 
12161 </cell>
12162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12163 \begin_inset Text
12164
12165 \layout Standard
12166
12167 External 1
12168 \end_inset 
12169 </cell>
12170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12171 \begin_inset Text
12172
12173 \layout Standard
12174
12175 0x0013
12176 \end_inset 
12177 </cell>
12178 </row>
12179 <row topline="true">
12180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12181 \begin_inset Text
12182
12183 \layout Standard
12184
12185 3
12186 \end_inset 
12187 </cell>
12188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12189 \begin_inset Text
12190
12191 \layout Standard
12192
12193 Timer 1
12194 \end_inset 
12195 </cell>
12196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12197 \begin_inset Text
12198
12199 \layout Standard
12200
12201 0x001b
12202 \end_inset 
12203 </cell>
12204 </row>
12205 <row topline="true">
12206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12207 \begin_inset Text
12208
12209 \layout Standard
12210
12211 4
12212 \end_inset 
12213 </cell>
12214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12215 \begin_inset Text
12216
12217 \layout Standard
12218
12219 Serial
12220 \end_inset 
12221 </cell>
12222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12223 \begin_inset Text
12224
12225 \layout Standard
12226
12227 0x0023
12228 \end_inset 
12229 </cell>
12230 </row>
12231 <row topline="true">
12232 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12233 \begin_inset Text
12234
12235 \layout Standard
12236
12237 5
12238 \end_inset 
12239 </cell>
12240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12241 \begin_inset Text
12242
12243 \layout Standard
12244
12245 Timer 2 (8052)
12246 \end_inset 
12247 </cell>
12248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12249 \begin_inset Text
12250
12251 \layout Standard
12252
12253 0x002b
12254 \end_inset 
12255 </cell>
12256 </row>
12257 <row topline="true">
12258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12259 \begin_inset Text
12260
12261 \layout Standard
12262
12263 ...
12264 \end_inset 
12265 </cell>
12266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12267 \begin_inset Text
12268
12269 \layout Standard
12270
12271 \end_inset 
12272 </cell>
12273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12274 \begin_inset Text
12275
12276 \layout Standard
12277
12278 ...
12279 \end_inset 
12280 </cell>
12281 </row>
12282 <row topline="true" bottomline="true">
12283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12284 \begin_inset Text
12285
12286 \layout Standard
12287
12288 n
12289 \end_inset 
12290 </cell>
12291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12292 \begin_inset Text
12293
12294 \layout Standard
12295
12296 \end_inset 
12297 </cell>
12298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12299 \begin_inset Text
12300
12301 \layout Standard
12302
12303 0x0003 + 8*n
12304 \end_inset 
12305 </cell>
12306 </row>
12307 </lyxtabular>
12308
12309 \end_inset 
12310
12311
12312 \newline 
12313
12314 \layout Standard
12315
12316 If the interrupt service routine is defined without 
12317 \emph on 
12318 using
12319 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12320
12321 \end_inset 
12322
12323
12324 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12325
12326 \end_inset 
12327
12328
12329 \emph default 
12330  a register bank or with register bank 0 (
12331 \emph on 
12332 using
12333 \emph default 
12334  0), the compiler will save the registers used by itself on the stack upon
12335  entry and restore them at exit, however if such an interrupt service routine
12336  calls another function then the entire register bank will be saved on the
12337  stack.
12338  This scheme may be advantageous for small interrupt service routines which
12339  have low register usage.
12340 \layout Standard
12341 \added_space_bottom bigskip 
12342 If the interrupt service routine is defined to be using a specific register
12343  bank then only 
12344 \emph on 
12345 a, b, dptr
12346 \emph default 
12347  & psw are saved and restored, if such an interrupt service routine calls
12348  another function (using another register bank) then the entire register
12349  bank of the called function will be saved on the stack
12350 \begin_inset LatexCommand \index{stack}
12351
12352 \end_inset 
12353
12354 .
12355  This scheme is recommended for larger interrupt service routines.
12356 \layout Subsection
12357
12358 HC08
12359 \begin_inset LatexCommand \index{HC08}
12360
12361 \end_inset 
12362
12363  Interrupt Service Routines
12364 \layout Standard
12365 \added_space_bottom bigskip 
12366 Since the number of interrupts
12367 \begin_inset LatexCommand \index{HC08!interrupt}
12368
12369 \end_inset 
12370
12371  available is chip specific and the interrupt vector table always ends at
12372  the last byte of memory, the interrupt numbers corresponds to the interrupt
12373  vectors in reverse order of address.
12374  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12375  2 will use the interrupt vector at 0xfffa, and so on.
12376  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12377  this way; instead see section 
12378 \begin_inset LatexCommand \ref{sub:Startup-Code}
12379
12380 \end_inset 
12381
12382  for details on customizing startup.
12383 \layout Subsection
12384
12385 Z80 Interrupt Service Routines
12386 \layout Standard
12387
12388 The Z80
12389 \begin_inset LatexCommand \index{Z80}
12390
12391 \end_inset 
12392
12393  uses several different methods for determining the correct interrupt
12394 \begin_inset LatexCommand \index{Z80!interrupt}
12395
12396 \end_inset 
12397
12398  vector depending on the hardware implementation.
12399  Therefore, SDCC ignores the optional interrupt number and does not attempt
12400  to generate an interrupt vector table.
12401 \layout Standard
12402
12403 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12404  instruction to return from the interrupt.
12405  To write an interrupt handler for the non-maskable interrupt, which needs
12406  a RETN instruction instead, add the 
12407 \emph on 
12408 critical
12409 \emph default 
12410  keyword:
12411 \layout Verse
12412
12413
12414 \family typewriter 
12415 void nmi_isr (void) critical interrupt
12416 \newline 
12417
12418 \newline 
12419 \SpecialChar ~
12420 \SpecialChar ~
12421 \SpecialChar ~
12422 \SpecialChar ~
12423 ...
12424  
12425 \newline 
12426 }
12427 \layout Standard
12428 \added_space_bottom bigskip 
12429 However if you need to create a non-interruptable interrupt service routine
12430  you would also require the 
12431 \emph on 
12432 critical
12433 \emph default 
12434  keyword.
12435  To distinguish between this and an nmi_isr you must provide an interrupt
12436  number.
12437 \layout Section
12438
12439 Enabling and Disabling Interrupts
12440 \layout Subsection
12441
12442 Critical Functions and Critical Statements
12443 \layout Standard
12444
12445 A special keyword may be associated with a block or a function declaring
12446  it as 
12447 \emph on 
12448 critical
12449 \emph default 
12450 .
12451  SDCC will generate code to disable all interrupts
12452 \begin_inset LatexCommand \index{interrupt}
12453
12454 \end_inset 
12455
12456  upon entry to a critical function and restore the interrupt enable to the
12457  previous state before returning.
12458  Nesting critical functions will need one additional byte on the stack
12459 \begin_inset LatexCommand \index{stack}
12460
12461 \end_inset 
12462
12463  for each call.
12464 \layout Verse
12465
12466
12467 \family typewriter 
12468 int foo () __critical
12469 \begin_inset LatexCommand \index{critical}
12470
12471 \end_inset 
12472
12473
12474 \begin_inset LatexCommand \index{\_\_critical}
12475
12476 \end_inset 
12477
12478  
12479 \newline 
12480
12481 \newline 
12482 \SpecialChar ~
12483 \SpecialChar ~
12484 \SpecialChar ~
12485 \SpecialChar ~
12486 ...
12487  
12488 \newline 
12489 \SpecialChar ~
12490 \SpecialChar ~
12491 \SpecialChar ~
12492 \SpecialChar ~
12493 ...
12494  
12495 \newline 
12496 }
12497 \layout Standard
12498
12499 The critical attribute maybe used with other attributes like 
12500 \emph on 
12501 reentrant.
12502 \emph default 
12503
12504 \newline 
12505 The keyword 
12506 \emph on 
12507 critical
12508 \emph default 
12509  may also be used to disable interrupts more locally:
12510 \layout Verse
12511
12512
12513 \family typewriter 
12514 __critical{ i++; }
12515 \layout Standard
12516
12517 More than one statement could have been included in the block.
12518 \layout Subsection
12519
12520 Enabling and Disabling Interrupts directly
12521 \layout Standard
12522
12523 Interrupts
12524 \begin_inset LatexCommand \index{interrupt}
12525
12526 \end_inset 
12527
12528  can also be disabled and enabled directly (8051):
12529 \layout Verse
12530
12531
12532 \family typewriter 
12533 EA = 0;\SpecialChar ~
12534 \SpecialChar ~
12535 \SpecialChar ~
12536 \SpecialChar ~
12537 \SpecialChar ~
12538 \SpecialChar ~
12539 \SpecialChar ~
12540 \SpecialChar ~
12541 \SpecialChar ~
12542 \SpecialChar ~
12543 \SpecialChar ~
12544 \SpecialChar ~
12545 or:\SpecialChar ~
12546 \SpecialChar ~
12547 \SpecialChar ~
12548 \SpecialChar ~
12549 \SpecialChar ~
12550 \SpecialChar ~
12551 \SpecialChar ~
12552 \SpecialChar ~
12553 \SpecialChar ~
12554 \SpecialChar ~
12555 \SpecialChar ~
12556 EA_SAVE = EA;
12557 \layout Verse
12558
12559
12560 \family typewriter 
12561 ...\SpecialChar ~
12562 \SpecialChar ~
12563 \SpecialChar ~
12564 \SpecialChar ~
12565 \SpecialChar ~
12566 \SpecialChar ~
12567 \SpecialChar ~
12568 \SpecialChar ~
12569 \SpecialChar ~
12570 \SpecialChar ~
12571 \SpecialChar ~
12572 \SpecialChar ~
12573 \SpecialChar ~
12574 \SpecialChar ~
12575 \SpecialChar ~
12576 \SpecialChar ~
12577 \SpecialChar ~
12578 \SpecialChar ~
12579 \SpecialChar ~
12580 \SpecialChar ~
12581 \SpecialChar ~
12582 \SpecialChar ~
12583 \SpecialChar ~
12584 \SpecialChar ~
12585 \SpecialChar ~
12586 \SpecialChar ~
12587 \SpecialChar ~
12588 \SpecialChar ~
12589 \SpecialChar ~
12590 \SpecialChar ~
12591 EA = 0;
12592 \layout Verse
12593
12594
12595 \family typewriter 
12596 EA = 1;\SpecialChar ~
12597 \SpecialChar ~
12598 \SpecialChar ~
12599 \SpecialChar ~
12600 \SpecialChar ~
12601 \SpecialChar ~
12602 \SpecialChar ~
12603 \SpecialChar ~
12604 \SpecialChar ~
12605 \SpecialChar ~
12606 \SpecialChar ~
12607 \SpecialChar ~
12608 \SpecialChar ~
12609 \SpecialChar ~
12610 \SpecialChar ~
12611 \SpecialChar ~
12612 \SpecialChar ~
12613 \SpecialChar ~
12614 \SpecialChar ~
12615 \SpecialChar ~
12616 \SpecialChar ~
12617 \SpecialChar ~
12618 \SpecialChar ~
12619 \SpecialChar ~
12620 \SpecialChar ~
12621 \SpecialChar ~
12622 ...
12623 \layout Verse
12624
12625
12626 \family typewriter 
12627 \SpecialChar ~
12628 \SpecialChar ~
12629 \SpecialChar ~
12630 \SpecialChar ~
12631 \SpecialChar ~
12632 \SpecialChar ~
12633 \SpecialChar ~
12634 \SpecialChar ~
12635 \SpecialChar ~
12636 \SpecialChar ~
12637 \SpecialChar ~
12638 \SpecialChar ~
12639 \SpecialChar ~
12640 \SpecialChar ~
12641 \SpecialChar ~
12642 \SpecialChar ~
12643 \SpecialChar ~
12644 \SpecialChar ~
12645 \SpecialChar ~
12646 \SpecialChar ~
12647 \SpecialChar ~
12648 \SpecialChar ~
12649 \SpecialChar ~
12650 \SpecialChar ~
12651 \SpecialChar ~
12652 \SpecialChar ~
12653 \SpecialChar ~
12654 \SpecialChar ~
12655 \SpecialChar ~
12656 \SpecialChar ~
12657 \SpecialChar ~
12658 \SpecialChar ~
12659 \SpecialChar ~
12660 EA = EA_SAVE;
12661 \layout Standard
12662
12663 On other architectures which have seperate opcodes for enabling and disabling
12664  interrupts you might want to make use of defines with inline assembly
12665 \begin_inset LatexCommand \index{Assembler routines}
12666
12667 \end_inset 
12668
12669  (HC08
12670 \begin_inset LatexCommand \index{HC08!interrupt}
12671
12672 \end_inset 
12673
12674 ):
12675 \layout Verse
12676
12677
12678 \family typewriter 
12679 #define CLI _asm
12680 \begin_inset LatexCommand \index{\_asm}
12681
12682 \end_inset 
12683
12684 \SpecialChar ~
12685 \SpecialChar ~
12686 cli\SpecialChar ~
12687 \SpecialChar ~
12688 _endasm
12689 \begin_inset LatexCommand \index{\_endasm}
12690
12691 \end_inset 
12692
12693
12694 \layout Verse
12695
12696
12697 \family typewriter 
12698 #define SEI _asm\SpecialChar ~
12699 \SpecialChar ~
12700 sei\SpecialChar ~
12701 \SpecialChar ~
12702 _endasm; 
12703 \layout Verse
12704
12705
12706 \family typewriter 
12707 ...
12708 \layout Standard
12709
12710 Note: it is sometimes sufficient to disable only a specific interrupt source
12711  like f.e.
12712  a timer or serial interrupt by manipulating an 
12713 \emph on 
12714 interrupt mask
12715 \begin_inset LatexCommand \index{interrupt mask}
12716
12717 \end_inset 
12718
12719
12720 \emph default 
12721  register.
12722  
12723 \layout Standard
12724
12725 Usually the time during which interrupts are disabled should be kept as
12726  short as possible.
12727  This minimizes both 
12728 \emph on 
12729 interrupt latency
12730 \emph default 
12731
12732 \begin_inset LatexCommand \index{interrupt latency}
12733
12734 \end_inset 
12735
12736  (the time between the occurrence of the interrupt and the execution of
12737  the first code in the interrupt routine) and 
12738 \emph on 
12739 interrupt jitter
12740 \emph default 
12741
12742 \begin_inset LatexCommand \index{interrupt jitter}
12743
12744 \end_inset 
12745
12746  (the difference between the shortest and the longest interrupt latency).
12747  These really are something different, f.e.
12748  a serial interrupt has to be served before its buffer overruns so it cares
12749  for the maximum interrupt latency, whereas it does not care about jitter.
12750  On a loudspeaker driven via a digital to analog converter which is fed
12751  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12752  a much smaller jitter will be very audible.
12753 \layout Standard
12754
12755 You can reenable interrupts within an interrupt routine and on some architecture
12756 s you can make use of two (or more) levels of 
12757 \emph on 
12758 interrupt priorities
12759 \emph default 
12760
12761 \begin_inset LatexCommand \index{interrupt priority}
12762
12763 \end_inset 
12764
12765 .
12766  On some architectures which don't support interrupt priorities these can
12767  be implemented by manipulating the interrupt mask and reenabling interrupts
12768  within the interrupt routine.
12769  Check there is sufficient space on the stack
12770 \begin_inset LatexCommand \index{stack}
12771
12772 \end_inset 
12773
12774  and don't add complexity unless you have to.
12775  
12776 \layout Subsection
12777
12778 Semaphore
12779 \begin_inset LatexCommand \index{semaphore}
12780
12781 \end_inset 
12782
12783  locking (mcs51/ds390)
12784 \layout Standard
12785
12786 Some architectures (mcs51/ds390) have an atomic
12787 \begin_inset LatexCommand \index{atomic}
12788
12789 \end_inset 
12790
12791  bit test and
12792 \emph on 
12793  
12794 \emph default 
12795 clear
12796 \emph on 
12797  
12798 \emph default 
12799 instruction.
12800  These type of instructions are typically used in preemptive multitasking
12801  systems, where a routine f.e.
12802  claims the use of a data structure ('acquires a lock
12803 \begin_inset LatexCommand \index{lock}
12804
12805 \end_inset 
12806
12807  on it'), makes some modifications and then releases the lock when the data
12808  structure is consistent again.
12809  The instruction may also be used if interrupt and non-interrupt code have
12810  to compete for a resource.
12811  With the atomic bit test and clear instruction interrupts
12812 \begin_inset LatexCommand \index{interrupt}
12813
12814 \end_inset 
12815
12816  don't have to be disabled for the locking operation.
12817  
12818 \layout Standard
12819
12820 SDCC generates this instruction if the source follows this pattern:
12821 \layout Verse
12822
12823
12824 \family typewriter 
12825 volatile
12826 \begin_inset LatexCommand \index{volatile}
12827
12828 \end_inset 
12829
12830  bit resource_is_free; 
12831 \newline 
12832
12833 \newline 
12834 if (resource_is_free) 
12835 \newline 
12836 \SpecialChar ~
12837 \SpecialChar ~
12838
12839 \newline 
12840 \SpecialChar ~
12841 \SpecialChar ~
12842 \SpecialChar ~
12843 \SpecialChar ~
12844 resource_is_free=0; 
12845 \newline 
12846 \SpecialChar ~
12847 \SpecialChar ~
12848 \SpecialChar ~
12849 \SpecialChar ~
12850 ...
12851  
12852 \newline 
12853 \SpecialChar ~
12854 \SpecialChar ~
12855 \SpecialChar ~
12856 \SpecialChar ~
12857 resource_is_free=1;
12858 \newline 
12859 \SpecialChar ~
12860 \SpecialChar ~
12861
12862 \layout Standard
12863
12864 Note, mcs51 and ds390 support only an atomic
12865 \begin_inset LatexCommand \index{atomic}
12866
12867 \end_inset 
12868
12869  bit test and 
12870 \emph on 
12871 clear
12872 \emph default 
12873  instruction (as opposed to atomic bit test and 
12874 \emph on 
12875 set).
12876 \layout Section
12877
12878 Functions using private register banks
12879 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12880
12881 \end_inset 
12882
12883  (mcs51/ds390)
12884 \layout Standard
12885
12886 Some architectures have support for quickly changing register sets.
12887  SDCC supports this feature with the 
12888 \emph on 
12889 using
12890 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12891
12892 \end_inset 
12893
12894
12895 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12896
12897 \end_inset 
12898
12899
12900 \emph default 
12901  attribute (which tells the compiler to use a register bank
12902 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12903
12904 \end_inset 
12905
12906  other than the default bank zero).
12907  It should only be applied to 
12908 \emph on 
12909 interrupt
12910 \begin_inset LatexCommand \index{interrupt}
12911
12912 \end_inset 
12913
12914
12915 \emph default 
12916  functions (see footnote below).
12917  This will in most circumstances make the generated ISR code more efficient
12918  since it will not have to save registers on the stack.
12919 \layout Standard
12920
12921 The 
12922 \emph on 
12923 using
12924 \emph default 
12925  attribute will have no effect on the generated code for a 
12926 \emph on 
12927 non-interrupt
12928 \emph default 
12929  function (but may occasionally be useful anyway
12930 \begin_inset Foot
12931 collapsed false
12932
12933 \layout Standard
12934
12935 possible exception: if a function is called ONLY from 'interrupt' functions
12936  using a particular bank, it can be declared with the same 'using' attribute
12937  as the calling 'interrupt' functions.
12938  For instance, if you have several ISRs using bank one, and all of them
12939  call memcpy(), it might make sense to create a specialized version of memcpy()
12940  'using 1', since this would prevent the ISR from having to save bank zero
12941  to the stack on entry and switch to bank zero before calling the function
12942 \end_inset 
12943
12944 ).
12945 \newline 
12946
12947 \emph on 
12948 (pending: Note, nowadays the 
12949 \emph default 
12950 using
12951 \emph on 
12952  attribute has an effect on
12953 \emph default 
12954  
12955 \emph on 
12956 the generated code for a 
12957 \emph default 
12958 non-interrupt
12959 \emph on 
12960  function
12961 \emph default 
12962 .
12963 \emph on 
12964 )
12965 \layout Standard
12966
12967 An 
12968 \emph on 
12969 interrupt
12970 \emph default 
12971  function using a non-zero bank will assume that it can trash that register
12972  bank, and will not save it.
12973  Since high-priority interrupts
12974 \begin_inset LatexCommand \index{interrupts}
12975
12976 \end_inset 
12977
12978
12979 \begin_inset LatexCommand \index{interrupt priority}
12980
12981 \end_inset 
12982
12983  can interrupt low-priority ones on the 8051 and friends, this means that
12984  if a high-priority ISR 
12985 \emph on 
12986 using
12987 \emph default 
12988  a particular bank occurs while processing a low-priority ISR 
12989 \emph on 
12990 using
12991 \emph default 
12992  the same bank, terrible and bad things can happen.
12993  To prevent this, no single register bank should be 
12994 \emph on 
12995 used
12996 \emph default 
12997  by both a high priority and a low priority ISR.
12998  This is probably most easily done by having all high priority ISRs use
12999  one bank and all low priority ISRs use another.
13000  If you have an ISR which can change priority at runtime, you're on your
13001  own: I suggest using the default bank zero and taking the small performance
13002  hit.
13003 \layout Standard
13004 \added_space_bottom bigskip 
13005 It is most efficient if your ISR calls no other functions.
13006  If your ISR must call other functions, it is most efficient if those functions
13007  use the same bank as the ISR (see note 1 below); the next best is if the
13008  called functions use bank zero.
13009  It is very inefficient to call a function using a different, non-zero bank
13010  from an ISR.
13011  
13012 \layout Section
13013
13014 Startup Code
13015 \begin_inset LatexCommand \label{sub:Startup-Code}
13016
13017 \end_inset 
13018
13019
13020 \begin_inset LatexCommand \index{Startup code}
13021
13022 \end_inset 
13023
13024
13025 \layout Subsection
13026
13027 MCS51/DS390 Startup Code
13028 \layout Standard
13029
13030 The compiler inserts a call to the C routine 
13031 \emph on 
13032 _sdcc_external_startup()
13033 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13034
13035 \end_inset 
13036
13037
13038 \series bold 
13039 \emph default 
13040  
13041 \series default 
13042 at the start of the CODE area.
13043  This routine is in the runtime library
13044 \begin_inset LatexCommand \index{Runtime library}
13045
13046 \end_inset 
13047
13048 .
13049  By default this routine returns 0, if this routine returns a non-zero value,
13050  the static & global variable initialization will be skipped and the function
13051  main will be invoked.
13052  Otherwise static & global variables will be initialized before the function
13053  main is invoked.
13054  You could add a 
13055 \emph on 
13056 _sdcc_external_startup()
13057 \emph default 
13058  routine to your program to override the default if you need to setup hardware
13059  or perform some other critical operation prior to static & global variable
13060  initialization
13061 \begin_inset LatexCommand \index{Variable initialization}
13062
13063 \end_inset 
13064
13065 .
13066  On some mcs51 variants xdata
13067 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13068
13069 \end_inset 
13070
13071  memory has to be explicitly enabled before it can be accessed or if the
13072  watchdog
13073 \begin_inset LatexCommand \index{watchdog}
13074
13075 \end_inset 
13076
13077  needs to be disabled, this is the place to do it.
13078  The startup code clears all internal data memory, 256 bytes by default,
13079  but from 0 to n-1 if 
13080 \emph on 
13081 -
13082 \begin_inset ERT
13083 status Collapsed
13084
13085 \layout Standard
13086
13087 \backslash 
13088 /
13089 \end_inset 
13090
13091 -iram-size
13092 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13093
13094 \end_inset 
13095
13096 n
13097 \emph default 
13098  is used.
13099  (recommended for Chipcon CC1010).
13100 \layout Standard
13101 \added_space_bottom bigskip 
13102 See also the compiler options 
13103 \emph on 
13104 -
13105 \begin_inset ERT
13106 status Collapsed
13107
13108 \layout Standard
13109
13110 \backslash 
13111 /
13112 \end_inset 
13113
13114 -no-xinit
13115 \emph default 
13116 -
13117 \emph on 
13118 opt
13119 \emph default 
13120
13121 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13122
13123 \end_inset 
13124
13125
13126 \emph on 
13127 -
13128 \begin_inset ERT
13129 status Collapsed
13130
13131 \layout Standard
13132
13133 \backslash 
13134 /
13135 \end_inset 
13136
13137 -main-return
13138 \emph default 
13139
13140 \begin_inset LatexCommand \index{-\/-main-return}
13141
13142 \end_inset 
13143
13144  and section 
13145 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13146
13147 \end_inset 
13148
13149  about MCS51-variants.
13150 \layout Subsection
13151
13152 HC08 Startup Code
13153 \layout Standard
13154 \added_space_bottom bigskip 
13155 The HC08
13156 \begin_inset LatexCommand \index{HC08}
13157
13158 \end_inset 
13159
13160  startup code follows the same scheme as the MCS51 startup code.
13161 \layout Subsection
13162
13163 Z80 Startup Code
13164 \layout Standard
13165 \added_space_bottom bigskip 
13166 On the Z80
13167 \begin_inset LatexCommand \index{Z80}
13168
13169 \end_inset 
13170
13171  the startup code is inserted by linking with crt0.o which is generated from
13172  sdcc/device/lib/z80/crt0.s.
13173  If you need a different startup code you can use the compiler option 
13174 \emph on 
13175 -
13176 \series bold 
13177 \emph default 
13178
13179 \begin_inset ERT
13180 status Collapsed
13181
13182 \layout Standard
13183
13184 \backslash 
13185 /
13186 \end_inset 
13187
13188
13189 \series default 
13190 \emph on 
13191 -no-std-crt0
13192 \emph default 
13193
13194 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13195
13196 \end_inset 
13197
13198  and provide your own crt0.o.
13199  
13200 \layout Section
13201
13202 Inline Assembler Code
13203 \begin_inset LatexCommand \index{Assembler routines}
13204
13205 \end_inset 
13206
13207
13208 \layout Subsection
13209
13210 A Step by Step Introduction
13211 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13212
13213 \end_inset 
13214
13215
13216 \layout Standard
13217
13218 Starting from a small snippet of c-code this example shows for the MCS51
13219  how to use inline assembly, access variables, a function parameter and
13220  an array in xdata memory.
13221  The example uses an MCS51 here but is easily adapted for other architectures.
13222  This is a buffer routine which should be optimized:
13223 \layout Verse
13224
13225
13226 \family typewriter 
13227 \size footnotesize 
13228 unsigned char __far
13229 \begin_inset LatexCommand \index{far (storage class)}
13230
13231 \end_inset 
13232
13233
13234 \begin_inset LatexCommand \index{\_\_far (storage class)}
13235
13236 \end_inset 
13237
13238  __at
13239 \begin_inset LatexCommand \index{at}
13240
13241 \end_inset 
13242
13243
13244 \begin_inset LatexCommand \index{\_\_at}
13245
13246 \end_inset 
13247
13248 (0x7f00) buf[0x100];
13249 \begin_inset LatexCommand \index{Aligned array}
13250
13251 \end_inset 
13252
13253
13254 \newline 
13255 unsigned char head, tail;\SpecialChar ~
13256 \SpecialChar ~
13257 \SpecialChar ~
13258 \SpecialChar ~
13259 \SpecialChar ~
13260 \SpecialChar ~
13261 \SpecialChar ~
13262 \SpecialChar ~
13263 \SpecialChar ~
13264 \SpecialChar ~
13265 \SpecialChar ~
13266 \SpecialChar ~
13267 \SpecialChar ~
13268 \SpecialChar ~
13269 \SpecialChar ~
13270 \SpecialChar ~
13271 \SpecialChar ~
13272 /* if interrupts
13273 \begin_inset LatexCommand \index{interrupt}
13274
13275 \end_inset 
13276
13277  are involved see
13278 \newline 
13279 \SpecialChar ~
13280 \SpecialChar ~
13281 \SpecialChar ~
13282 \SpecialChar ~
13283 \SpecialChar ~
13284 \SpecialChar ~
13285 \SpecialChar ~
13286 \SpecialChar ~
13287 \SpecialChar ~
13288 \SpecialChar ~
13289 \SpecialChar ~
13290 \SpecialChar ~
13291 \SpecialChar ~
13292 \SpecialChar ~
13293 \SpecialChar ~
13294 \SpecialChar ~
13295 \SpecialChar ~
13296 \SpecialChar ~
13297 \SpecialChar ~
13298 \SpecialChar ~
13299 \SpecialChar ~
13300 \SpecialChar ~
13301 \SpecialChar ~
13302 \SpecialChar ~
13303 \SpecialChar ~
13304 \SpecialChar ~
13305 \SpecialChar ~
13306 \SpecialChar ~
13307 \SpecialChar ~
13308 \SpecialChar ~
13309 \SpecialChar ~
13310 \SpecialChar ~
13311 \SpecialChar ~
13312 \SpecialChar ~
13313 \SpecialChar ~
13314 \SpecialChar ~
13315 \SpecialChar ~
13316 \SpecialChar ~
13317 \SpecialChar ~
13318 \SpecialChar ~
13319 \SpecialChar ~
13320 \SpecialChar ~
13321 \SpecialChar ~
13322 \SpecialChar ~
13323 \SpecialChar ~
13324 section 
13325 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13326
13327 \end_inset 
13328
13329  about
13330 \series bold 
13331  volatile
13332 \series default 
13333  */
13334 \newline 
13335
13336 \newline 
13337 void to_buffer( unsigned char c ) 
13338 \newline 
13339 {
13340 \newline 
13341 \SpecialChar ~
13342 \SpecialChar ~
13343 \SpecialChar ~
13344 \SpecialChar ~
13345 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13346 /* cast 
13347 \series bold 
13348 needed
13349 \series default 
13350  to avoid promotion
13351 \begin_inset LatexCommand \index{promotion to signed int}
13352
13353 \end_inset 
13354
13355
13356 \begin_inset LatexCommand \index{type promotion}
13357
13358 \end_inset 
13359
13360  to integer */
13361 \begin_inset Marginal
13362 collapsed true
13363
13364 \layout Standard
13365
13366
13367 \series bold 
13368 \SpecialChar ~
13369 !
13370 \end_inset 
13371
13372
13373 \newline 
13374 \SpecialChar ~
13375 \SpecialChar ~
13376 \SpecialChar ~
13377 \SpecialChar ~
13378 \SpecialChar ~
13379 \SpecialChar ~
13380 \SpecialChar ~
13381 \SpecialChar ~
13382 buf[ head++ ] = c;\SpecialChar ~
13383 \SpecialChar ~
13384 \SpecialChar ~
13385 \SpecialChar ~
13386 \SpecialChar ~
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 \SpecialChar ~
13390 \SpecialChar ~
13391 \SpecialChar ~
13392 \SpecialChar ~
13393 \SpecialChar ~
13394 \SpecialChar ~
13395 \SpecialChar ~
13396 \SpecialChar ~
13397 \SpecialChar ~
13398 /* access to a 256 byte aligned array */
13399 \newline 
13400
13401 \layout Standard
13402
13403 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13404  then a corresponding buffer.asm file is generated.
13405  We define a new function 
13406 \family typewriter 
13407 to_buffer_asm()
13408 \family default 
13409  in file buffer.c in which we cut and paste the generated code, removing
13410  unwanted comments and some ':'.
13411  Then add 
13412 \begin_inset Quotes sld
13413 \end_inset 
13414
13415 _asm
13416 \begin_inset Quotes srd
13417 \end_inset 
13418
13419  and 
13420 \begin_inset Quotes sld
13421 \end_inset 
13422
13423 _endasm;
13424 \begin_inset Quotes srd
13425 \end_inset 
13426
13427  to the beginning and the end of the function body:
13428 \layout Verse
13429
13430
13431 \family typewriter 
13432 \size footnotesize 
13433 /* With a cut and paste from the .asm file, we have something to start with.
13434 \newline 
13435 \SpecialChar ~
13436 \SpecialChar ~
13437 \SpecialChar ~
13438 The function is not yet OK! (registers aren't saved) */ 
13439 \newline 
13440 void to_buffer_asm( unsigned char c ) 
13441 \newline 
13442
13443 \newline 
13444 \SpecialChar ~
13445 \SpecialChar ~
13446 \SpecialChar ~
13447 \SpecialChar ~
13448 _asm
13449 \begin_inset LatexCommand \index{\_asm}
13450
13451 \end_inset 
13452
13453
13454 \begin_inset LatexCommand \index{\_\_asm}
13455
13456 \end_inset 
13457
13458
13459 \newline 
13460 \SpecialChar ~
13461 \SpecialChar ~
13462 \SpecialChar ~
13463 \SpecialChar ~
13464 mov\SpecialChar ~
13465 \SpecialChar ~
13466 r2,dpl 
13467 \newline 
13468 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13469 /* cast 
13470 \series bold 
13471 needed
13472 \series default 
13473  to avoid promotion
13474 \begin_inset LatexCommand \index{promotion to signed int}
13475
13476 \end_inset 
13477
13478
13479 \begin_inset LatexCommand \index{type promotion}
13480
13481 \end_inset 
13482
13483  to integer */
13484 \newline 
13485 \SpecialChar ~
13486 \SpecialChar ~
13487 \SpecialChar ~
13488 \SpecialChar ~
13489 mov\SpecialChar ~
13490 \SpecialChar ~
13491 a,_tail 
13492 \newline 
13493 \SpecialChar ~
13494 \SpecialChar ~
13495 \SpecialChar ~
13496 \SpecialChar ~
13497 dec\SpecialChar ~
13498 \SpecialChar ~
13499
13500 \newline 
13501 \SpecialChar ~
13502 \SpecialChar ~
13503 \SpecialChar ~
13504 \SpecialChar ~
13505 mov\SpecialChar ~
13506 \SpecialChar ~
13507 r3,a 
13508 \newline 
13509 \SpecialChar ~
13510 \SpecialChar ~
13511 \SpecialChar ~
13512 \SpecialChar ~
13513 mov\SpecialChar ~
13514 \SpecialChar ~
13515 a,_head 
13516 \newline 
13517 \SpecialChar ~
13518 \SpecialChar ~
13519 \SpecialChar ~
13520 \SpecialChar ~
13521 cjne a,ar3,00106$ 
13522 \newline 
13523 \SpecialChar ~
13524 \SpecialChar ~
13525 \SpecialChar ~
13526 \SpecialChar ~
13527 ret
13528 \newline 
13529 00106$: 
13530 \newline 
13531 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13532 \begin_inset LatexCommand \index{Aligned array}
13533
13534 \end_inset 
13535
13536
13537 \newline 
13538 \SpecialChar ~
13539 \SpecialChar ~
13540 \SpecialChar ~
13541 \SpecialChar ~
13542 mov\SpecialChar ~
13543 \SpecialChar ~
13544 r3,_head 
13545 \newline 
13546 \SpecialChar ~
13547 \SpecialChar ~
13548 \SpecialChar ~
13549 \SpecialChar ~
13550 inc\SpecialChar ~
13551 \SpecialChar ~
13552 _head 
13553 \newline 
13554 \SpecialChar ~
13555 \SpecialChar ~
13556 \SpecialChar ~
13557 \SpecialChar ~
13558 mov\SpecialChar ~
13559 \SpecialChar ~
13560 dpl,r3 
13561 \newline 
13562 \SpecialChar ~
13563 \SpecialChar ~
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 mov\SpecialChar ~
13567 \SpecialChar ~
13568 dph,#(_buf >> 8) 
13569 \newline 
13570 \SpecialChar ~
13571 \SpecialChar ~
13572 \SpecialChar ~
13573 \SpecialChar ~
13574 mov\SpecialChar ~
13575 \SpecialChar ~
13576 a,r2 
13577 \newline 
13578 \SpecialChar ~
13579 \SpecialChar ~
13580 \SpecialChar ~
13581 \SpecialChar ~
13582 movx @dptr,a 
13583 \newline 
13584 00103$: 
13585 \newline 
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 \SpecialChar ~
13589 \SpecialChar ~
13590 ret
13591 \newline 
13592 \SpecialChar ~
13593 \SpecialChar ~
13594 \SpecialChar ~
13595 \SpecialChar ~
13596 _endasm
13597 \begin_inset LatexCommand \index{\_endasm}
13598
13599 \end_inset 
13600
13601
13602 \begin_inset LatexCommand \index{\_\_endasm}
13603
13604 \end_inset 
13605
13606 ;
13607 \newline 
13608
13609 \layout Standard
13610
13611 The new file buffer.c should compile with only one warning about the unreferenced
13612  function argument 'c'.
13613  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13614  (1) and finally have:
13615 \layout Verse
13616
13617
13618 \family typewriter 
13619 \size footnotesize 
13620 unsigned char __far __at(0x7f00) buf[0x100];
13621 \newline 
13622 unsigned char head, tail;
13623 \newline 
13624 #define USE_ASSEMBLY (1)
13625 \newline 
13626
13627 \newline 
13628 #if !USE_ASSEMBLY
13629 \newline 
13630
13631 \newline 
13632 void to_buffer( unsigned char c )
13633 \newline 
13634 {
13635 \newline 
13636 \SpecialChar ~
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 if( head != (unsigned char)(tail-1) )
13641 \newline 
13642 \SpecialChar ~
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 \SpecialChar ~
13646 \SpecialChar ~
13647 \SpecialChar ~
13648 \SpecialChar ~
13649 \SpecialChar ~
13650 buf[ head++ ] = c;
13651 \newline 
13652 }
13653 \newline 
13654
13655 \newline 
13656 #else
13657 \newline 
13658
13659 \newline 
13660 void to_buffer( unsigned char c )
13661 \newline 
13662 {
13663 \newline 
13664 \SpecialChar ~
13665 \SpecialChar ~
13666 \SpecialChar ~
13667 \SpecialChar ~
13668 c; // to avoid warning: unreferenced function argument
13669 \newline 
13670 \SpecialChar ~
13671 \SpecialChar ~
13672 \SpecialChar ~
13673 \SpecialChar ~
13674 _asm
13675 \begin_inset LatexCommand \index{\_asm}
13676
13677 \end_inset 
13678
13679
13680 \begin_inset LatexCommand \index{\_\_asm}
13681
13682 \end_inset 
13683
13684
13685 \newline 
13686 \SpecialChar ~
13687 \SpecialChar ~
13688 \SpecialChar ~
13689 \SpecialChar ~
13690 \SpecialChar ~
13691 \SpecialChar ~
13692 \SpecialChar ~
13693 \SpecialChar ~
13694 ; save used registers here.
13695  
13696 \newline 
13697 \SpecialChar ~
13698 \SpecialChar ~
13699 \SpecialChar ~
13700 \SpecialChar ~
13701 \SpecialChar ~
13702 \SpecialChar ~
13703 \SpecialChar ~
13704 \SpecialChar ~
13705 ; If we were still using r2,r3 we would have to push them here.
13706  
13707 \newline 
13708 ; if( head != (unsigned char)(tail-1) )
13709 \newline 
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 \SpecialChar ~
13713 \SpecialChar ~
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 \SpecialChar ~
13718 mov\SpecialChar ~
13719  a,_tail
13720 \newline 
13721 \SpecialChar ~
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 \SpecialChar ~
13728 \SpecialChar ~
13729 dec\SpecialChar ~
13730  a
13731 \newline 
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 \SpecialChar ~
13739 \SpecialChar ~
13740 xrl\SpecialChar ~
13741  a,_head
13742 \newline 
13743 \SpecialChar ~
13744 \SpecialChar ~
13745 \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 \SpecialChar ~
13750 \SpecialChar ~
13751 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13752 \newline 
13753 \SpecialChar ~
13754 \SpecialChar ~
13755 \SpecialChar ~
13756 \SpecialChar ~
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 jz\SpecialChar ~
13762 \SpecialChar ~
13763  t_b_end$
13764 \newline 
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 \SpecialChar ~
13768 \SpecialChar ~
13769 \SpecialChar ~
13770 \SpecialChar ~
13771 \SpecialChar ~
13772 \SpecialChar ~
13773 ;
13774 \newline 
13775 ; buf[ head++ ] = c;
13776 \newline 
13777 \SpecialChar ~
13778 \SpecialChar ~
13779 \SpecialChar ~
13780 \SpecialChar ~
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 mov\SpecialChar ~
13786  a,dpl \SpecialChar ~
13787 \SpecialChar ~
13788 \SpecialChar ~
13789 \SpecialChar ~
13790 \SpecialChar ~
13791 \SpecialChar ~
13792 \SpecialChar ~
13793 ; dpl holds lower byte of function argument
13794 \newline 
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 \SpecialChar ~
13798 \SpecialChar ~
13799 \SpecialChar ~
13800 \SpecialChar ~
13801 \SpecialChar ~
13802 \SpecialChar ~
13803 mov\SpecialChar ~
13804  dpl,_head \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 ; buf is 0x100 byte aligned so head can be used directly
13808 \newline 
13809 \SpecialChar ~
13810 \SpecialChar ~
13811 \SpecialChar ~
13812 \SpecialChar ~
13813 \SpecialChar ~
13814 \SpecialChar ~
13815 \SpecialChar ~
13816 \SpecialChar ~
13817 mov\SpecialChar ~
13818  dph,#(_buf>>8)
13819 \newline 
13820 \SpecialChar ~
13821 \SpecialChar ~
13822 \SpecialChar ~
13823 \SpecialChar ~
13824 \SpecialChar ~
13825 \SpecialChar ~
13826 \SpecialChar ~
13827 \SpecialChar ~
13828 movx @dptr,a
13829 \newline 
13830 \SpecialChar ~
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 \SpecialChar ~
13835 \SpecialChar ~
13836 \SpecialChar ~
13837 \SpecialChar ~
13838 inc \SpecialChar ~
13839 _head
13840 \newline 
13841 \SpecialChar ~
13842 \SpecialChar ~
13843 \SpecialChar ~
13844 \SpecialChar ~
13845 \SpecialChar ~
13846 \SpecialChar ~
13847 \SpecialChar ~
13848 \SpecialChar ~
13849 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13850 \newline 
13851 t_b_end$:
13852 \newline 
13853 \SpecialChar ~
13854 \SpecialChar ~
13855 \SpecialChar ~
13856 \SpecialChar ~
13857 \SpecialChar ~
13858 \SpecialChar ~
13859 \SpecialChar ~
13860 \SpecialChar ~
13861 ; restore used registers here 
13862 \newline 
13863 \SpecialChar ~
13864 \SpecialChar ~
13865 \SpecialChar ~
13866 \SpecialChar ~
13867 _endasm
13868 \begin_inset LatexCommand \index{\_endasm}
13869
13870 \end_inset 
13871
13872
13873 \begin_inset LatexCommand \index{\_\_endasm}
13874
13875 \end_inset 
13876
13877 ;
13878 \newline 
13879 }
13880 \newline 
13881 #endif
13882 \layout Standard
13883
13884 The inline assembler code can contain any valid code understood by the assembler
13885 , this includes any assembler directives and comment lines.
13886  The assembler does not like some characters like ':' or ''' in comments.
13887  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13888 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13889
13890 \end_inset 
13891
13892
13893 \begin_inset LatexCommand \index{Assembler documentation}
13894
13895 \end_inset 
13896
13897  or online at 
13898 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13899
13900 \end_inset 
13901
13902 \SpecialChar ~
13903 .
13904 \layout Standard
13905
13906 The compiler does not do any validation of the code within the 
13907 \family typewriter 
13908 _asm
13909 \begin_inset LatexCommand \index{\_asm}
13910
13911 \end_inset 
13912
13913
13914 \begin_inset LatexCommand \index{\_\_asm}
13915
13916 \end_inset 
13917
13918  ...
13919  _endasm
13920 \size footnotesize 
13921
13922 \begin_inset LatexCommand \index{\_endasm}
13923
13924 \end_inset 
13925
13926
13927 \begin_inset LatexCommand \index{\_\_endasm}
13928
13929 \end_inset 
13930
13931
13932 \size default 
13933 ;
13934 \family default 
13935  keyword pair.
13936  Specifically it will not know which registers are used and thus register
13937  pushing/popping
13938 \begin_inset LatexCommand \index{push/pop}
13939
13940 \end_inset 
13941
13942  has to be done manually.
13943  
13944 \layout Standard
13945
13946 It is recommended that each assembly instruction (including labels) be placed
13947  in a separate line (as the example shows).
13948  When the -
13949 \begin_inset ERT
13950 status Collapsed
13951
13952 \layout Standard
13953
13954 \backslash 
13955 /
13956 \end_inset 
13957
13958 -
13959 \emph on 
13960 peep-asm
13961 \begin_inset LatexCommand \index{-\/-peep-asm}
13962
13963 \end_inset 
13964
13965
13966 \emph default 
13967  command line option is used, the inline assembler code will be passed through
13968  the peephole optimizer
13969 \begin_inset LatexCommand \index{Peephole optimizer}
13970
13971 \end_inset 
13972
13973 .
13974  There are only a few (if any) cases where this option makes sense, it might
13975  cause some unexpected changes in the inline assembler code.
13976  Please go through the peephole optimizer rules defined in file 
13977 \emph on 
13978 SDCCpeeph.def
13979 \emph default 
13980  before using this option.
13981 \layout Subsection
13982
13983 Naked Functions
13984 \begin_inset LatexCommand \label{sub:Naked-Functions}
13985
13986 \end_inset 
13987
13988
13989 \begin_inset LatexCommand \index{Naked functions}
13990
13991 \end_inset 
13992
13993
13994 \layout Standard
13995
13996 A special keyword may be associated with a function declaring it as 
13997 \emph on 
13998 _naked
13999 \begin_inset LatexCommand \index{\_naked}
14000
14001 \end_inset 
14002
14003
14004 \begin_inset LatexCommand \index{\_\_naked}
14005
14006 \end_inset 
14007
14008 .
14009  
14010 \emph default 
14011 The 
14012 \emph on 
14013 _naked
14014 \emph default 
14015  function modifier attribute prevents the compiler from generating prologue
14016 \begin_inset LatexCommand \index{function prologue}
14017
14018 \end_inset 
14019
14020  and epilogue
14021 \begin_inset LatexCommand \index{function epilogue}
14022
14023 \end_inset 
14024
14025  code for that function.
14026  This means that the user is entirely responsible for such things as saving
14027  any registers that may need to be preserved, selecting the proper register
14028  bank, generating the 
14029 \emph on 
14030 return
14031 \emph default 
14032  instruction at the end, etc.
14033  Practically, this means that the contents of the function must be written
14034  in inline assembler.
14035  This is particularly useful for interrupt functions, which can have a large
14036  (and often unnecessary) prologue/epilogue.
14037  For example, compare the code generated by these two functions:
14038 \layout Verse
14039
14040
14041 \family typewriter 
14042 volatile
14043 \begin_inset LatexCommand \index{volatile}
14044
14045 \end_inset 
14046
14047  data unsigned char counter;
14048 \newline 
14049
14050 \newline 
14051 void simpleInterrupt(void) __interrupt
14052 \begin_inset LatexCommand \index{interrupt}
14053
14054 \end_inset 
14055
14056
14057 \begin_inset LatexCommand \index{\_\_interrupt}
14058
14059 \end_inset 
14060
14061  (1)
14062 \newline 
14063 {
14064 \newline 
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 \SpecialChar ~
14068 \SpecialChar ~
14069 counter++;
14070 \newline 
14071 }
14072 \newline 
14073
14074 \newline 
14075 void nakedInterrupt(void) __interrupt (2) __naked
14076 \newline 
14077 {
14078 \newline 
14079 \SpecialChar ~
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 _asm
14084 \begin_inset LatexCommand \index{\_asm}
14085
14086 \end_inset 
14087
14088
14089 \begin_inset LatexCommand \index{\_\_asm}
14090
14091 \end_inset 
14092
14093
14094 \newline 
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 \SpecialChar ~
14099 \SpecialChar ~
14100 \SpecialChar ~
14101 inc\SpecialChar ~
14102 \SpecialChar ~
14103 \SpecialChar ~
14104 \SpecialChar ~
14105 \SpecialChar ~
14106 _counter ; does not change flags, no need to save psw
14107 \newline 
14108 \SpecialChar ~
14109 \SpecialChar ~
14110 \SpecialChar ~
14111 \SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 reti\SpecialChar ~
14115 \SpecialChar ~
14116 \SpecialChar ~
14117 \SpecialChar ~
14118 ; MUST explicitly include ret or reti in _naked function.
14119 \newline 
14120 \SpecialChar ~
14121 \SpecialChar ~
14122 \SpecialChar ~
14123 \SpecialChar ~
14124 _endasm
14125 \begin_inset LatexCommand \index{\_endasm}
14126
14127 \end_inset 
14128
14129
14130 \begin_inset LatexCommand \index{\_\_endasm}
14131
14132 \end_inset 
14133
14134 ;
14135 \newline 
14136 }
14137 \layout Standard
14138
14139 For an 8051 target, the generated simpleInterrupt looks like:
14140 \layout Verse
14141
14142
14143 \family typewriter 
14144 Note, this is an 
14145 \emph on 
14146 outdated
14147 \emph default 
14148  example, recent versions of SDCC generate
14149 \newline 
14150 the 
14151 \emph on 
14152 same
14153 \emph default 
14154  code for simpleInterrupt() and nakedInterrupt()!
14155 \newline 
14156
14157 \newline 
14158 _simpleInterrupt:
14159 \newline 
14160 \SpecialChar ~
14161 \SpecialChar ~
14162 \SpecialChar ~
14163 \SpecialChar ~
14164 push\SpecialChar ~
14165 \SpecialChar ~
14166 \SpecialChar ~
14167 \SpecialChar ~
14168 acc
14169 \newline 
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 push\SpecialChar ~
14175 \SpecialChar ~
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 b
14179 \newline 
14180 \SpecialChar ~
14181 \SpecialChar ~
14182 \SpecialChar ~
14183 \SpecialChar ~
14184 push\SpecialChar ~
14185 \SpecialChar ~
14186 \SpecialChar ~
14187 \SpecialChar ~
14188 dpl
14189 \newline 
14190 \SpecialChar ~
14191 \SpecialChar ~
14192 \SpecialChar ~
14193 \SpecialChar ~
14194 push\SpecialChar ~
14195 \SpecialChar ~
14196 \SpecialChar ~
14197 \SpecialChar ~
14198 dph
14199 \newline 
14200 \SpecialChar ~
14201 \SpecialChar ~
14202 \SpecialChar ~
14203 \SpecialChar ~
14204 push\SpecialChar ~
14205 \SpecialChar ~
14206 \SpecialChar ~
14207 \SpecialChar ~
14208 psw
14209 \newline 
14210 \SpecialChar ~
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 \SpecialChar ~
14214 mov\SpecialChar ~
14215 \SpecialChar ~
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 \SpecialChar ~
14219 psw,#0x00
14220 \newline 
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 \SpecialChar ~
14224 \SpecialChar ~
14225 inc\SpecialChar ~
14226 \SpecialChar ~
14227 \SpecialChar ~
14228 \SpecialChar ~
14229 \SpecialChar ~
14230 _counter
14231 \newline 
14232 \SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 \SpecialChar ~
14236 pop\SpecialChar ~
14237 \SpecialChar ~
14238 \SpecialChar ~
14239 \SpecialChar ~
14240 \SpecialChar ~
14241 psw
14242 \newline 
14243 \SpecialChar ~
14244 \SpecialChar ~
14245 \SpecialChar ~
14246 \SpecialChar ~
14247 pop\SpecialChar ~
14248 \SpecialChar ~
14249 \SpecialChar ~
14250 \SpecialChar ~
14251 \SpecialChar ~
14252 dph
14253 \newline 
14254 \SpecialChar ~
14255 \SpecialChar ~
14256 \SpecialChar ~
14257 \SpecialChar ~
14258 pop\SpecialChar ~
14259 \SpecialChar ~
14260 \SpecialChar ~
14261 \SpecialChar ~
14262 \SpecialChar ~
14263 dpl
14264 \newline 
14265 \SpecialChar ~
14266 \SpecialChar ~
14267 \SpecialChar ~
14268 \SpecialChar ~
14269 pop\SpecialChar ~
14270 \SpecialChar ~
14271 \SpecialChar ~
14272 \SpecialChar ~
14273 \SpecialChar ~
14274 b
14275 \newline 
14276 \SpecialChar ~
14277 \SpecialChar ~
14278 \SpecialChar ~
14279 \SpecialChar ~
14280 pop\SpecialChar ~
14281 \SpecialChar ~
14282 \SpecialChar ~
14283 \SpecialChar ~
14284 \SpecialChar ~
14285 acc
14286 \newline 
14287 \SpecialChar ~
14288 \SpecialChar ~
14289 \SpecialChar ~
14290 \SpecialChar ~
14291 reti
14292 \layout Standard
14293
14294 whereas nakedInterrupt looks like:
14295 \layout Verse
14296
14297
14298 \family typewriter 
14299 _nakedInterrupt:
14300 \newline 
14301 \SpecialChar ~
14302 \SpecialChar ~
14303 \SpecialChar ~
14304 \SpecialChar ~
14305 inc\SpecialChar ~
14306 \SpecialChar ~
14307 \SpecialChar ~
14308 \SpecialChar ~
14309 _counter ; does not change flags, no need to save psw
14310 \newline 
14311 \SpecialChar ~
14312 \SpecialChar ~
14313 \SpecialChar ~
14314 \SpecialChar ~
14315 reti\SpecialChar ~
14316 \SpecialChar ~
14317 \SpecialChar ~
14318 \SpecialChar ~
14319 \SpecialChar ~
14320 \SpecialChar ~
14321 \SpecialChar ~
14322 \SpecialChar ~
14323 \SpecialChar ~
14324 \SpecialChar ~
14325 \SpecialChar ~
14326 \SpecialChar ~
14327 ; MUST explicitly include ret or reti in _naked function
14328 \layout Standard
14329
14330 The related directive #pragma exclude
14331 \begin_inset LatexCommand \index{\#pragma exclude}
14332
14333 \end_inset 
14334
14335  allows a more fine grained control over pushing & popping
14336 \begin_inset LatexCommand \index{push/pop}
14337
14338 \end_inset 
14339
14340  the registers.
14341 \layout Standard
14342
14343 While there is nothing preventing you from writing C code inside a 
14344 \family typewriter 
14345 _naked
14346 \family default 
14347  function, there are many ways to shoot yourself in the foot doing this,
14348  and it is recommended that you stick to inline assembler.
14349 \layout Subsection
14350
14351 Use of Labels within Inline Assembler
14352 \layout Standard
14353
14354 SDCC allows the use of in-line assembler with a few restrictions regarding
14355  labels.
14356  In older versions of the compiler all labels defined within inline assembler
14357  code 
14358 \emph on 
14359 had to be
14360 \emph default 
14361  of the form 
14362 \emph on 
14363 nnnnn$
14364 \emph default 
14365  where nnnn is a number less than 100 (which implies a limit of utmost 100
14366  inline assembler labels 
14367 \emph on 
14368 per function
14369 \emph default 
14370 \noun on 
14371 )
14372 \noun default 
14373 .
14374  
14375 \layout Verse
14376
14377
14378 \family typewriter 
14379 _asm
14380 \begin_inset LatexCommand \index{\_asm}
14381
14382 \end_inset 
14383
14384
14385 \begin_inset LatexCommand \index{\_\_asm}
14386
14387 \end_inset 
14388
14389  
14390 \newline 
14391 \SpecialChar ~
14392 \SpecialChar ~
14393 \SpecialChar ~
14394 \SpecialChar ~
14395 mov\SpecialChar ~
14396 \SpecialChar ~
14397 \SpecialChar ~
14398 \SpecialChar ~
14399 \SpecialChar ~
14400 b,#10 
14401 \newline 
14402 00001$: 
14403 \newline 
14404 \SpecialChar ~
14405 \SpecialChar ~
14406 \SpecialChar ~
14407 \SpecialChar ~
14408 djnz\SpecialChar ~
14409 \SpecialChar ~
14410 \SpecialChar ~
14411 \SpecialChar ~
14412 b,00001$ 
14413 \newline 
14414 _endasm
14415 \begin_inset LatexCommand \index{\_endasm}
14416
14417 \end_inset 
14418
14419
14420 \begin_inset LatexCommand \index{\_\_endasm}
14421
14422 \end_inset 
14423
14424  ;
14425 \layout Standard
14426
14427 Inline assembler code cannot reference any C-Labels, however it can reference
14428  labels
14429 \begin_inset LatexCommand \index{Labels}
14430
14431 \end_inset 
14432
14433  defined by the inline assembler, e.g.:
14434 \layout Verse
14435
14436
14437 \family typewriter 
14438 foo() { 
14439 \newline 
14440 \SpecialChar ~
14441 \SpecialChar ~
14442 \SpecialChar ~
14443 \SpecialChar ~
14444 /* some c code */ 
14445 \newline 
14446 \SpecialChar ~
14447 \SpecialChar ~
14448 \SpecialChar ~
14449 \SpecialChar ~
14450 _asm 
14451 \newline 
14452 \SpecialChar ~
14453 \SpecialChar ~
14454 \SpecialChar ~
14455 \SpecialChar ~
14456 \SpecialChar ~
14457 \SpecialChar ~
14458 ; some assembler code 
14459 \newline 
14460 \SpecialChar ~
14461 \SpecialChar ~
14462 \SpecialChar ~
14463 \SpecialChar ~
14464 \SpecialChar ~
14465 \SpecialChar ~
14466 ljmp $0003 
14467 \newline 
14468 \SpecialChar ~
14469 \SpecialChar ~
14470 \SpecialChar ~
14471 \SpecialChar ~
14472 _endasm; 
14473 \newline 
14474 \SpecialChar ~
14475 \SpecialChar ~
14476 \SpecialChar ~
14477 \SpecialChar ~
14478 /* some more c code */ 
14479 \newline 
14480 clabel:\SpecialChar ~
14481 \SpecialChar ~
14482 /* inline assembler cannot reference this label */ 
14483 \newline 
14484 \SpecialChar ~
14485 \SpecialChar ~
14486 \SpecialChar ~
14487 \SpecialChar ~
14488 _asm
14489 \newline 
14490 \SpecialChar ~
14491 \SpecialChar ~
14492 \SpecialChar ~
14493 \SpecialChar ~
14494 $0003: ;label (can be referenced by inline assembler only) 
14495 \newline 
14496 \SpecialChar ~
14497 \SpecialChar ~
14498 \SpecialChar ~
14499 \SpecialChar ~
14500 _endasm
14501 \begin_inset LatexCommand \index{\_endasm}
14502
14503 \end_inset 
14504
14505
14506 \begin_inset LatexCommand \index{\_\_endasm}
14507
14508 \end_inset 
14509
14510  ; 
14511 \newline 
14512 \SpecialChar ~
14513 \SpecialChar ~
14514 \SpecialChar ~
14515 \SpecialChar ~
14516 /* some more c code */
14517 \newline 
14518 }
14519 \layout Standard
14520
14521 In other words inline assembly code can access labels defined in inline
14522  assembly within the scope of the function.
14523  The same goes the other way, i.e.
14524  labels defines in inline assembly can not be accessed by C statements.
14525 \layout Section
14526
14527 Interfacing with Assembler Code
14528 \begin_inset LatexCommand \index{Assembler routines}
14529
14530 \end_inset 
14531
14532
14533 \layout Subsection
14534
14535 Global Registers used for Parameter Passing
14536 \begin_inset LatexCommand \index{Parameter passing}
14537
14538 \end_inset 
14539
14540
14541 \layout Standard
14542
14543 The compiler always uses the global registers 
14544 \emph on 
14545 DPL, DPH
14546 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14547
14548 \end_inset 
14549
14550
14551 \begin_inset LatexCommand \index{DPTR}
14552
14553 \end_inset 
14554
14555 , B
14556 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14557
14558 \end_inset 
14559
14560  
14561 \emph default 
14562 and
14563 \emph on 
14564  ACC
14565 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14566
14567 \end_inset 
14568
14569
14570 \emph default 
14571  to pass the first parameter to a routine.
14572  The second parameter onwards is either allocated on the stack (for reentrant
14573  routines or if -
14574 \begin_inset ERT
14575 status Collapsed
14576
14577 \layout Standard
14578
14579 \backslash 
14580 /
14581 \end_inset 
14582
14583 -stack-auto is used) or in data / xdata memory (depending on the memory
14584  model).
14585  
14586 \layout Subsection
14587
14588 Assembler Routine (non-reentrant)
14589 \layout Standard
14590
14591 In the following example
14592 \begin_inset LatexCommand \index{reentrant}
14593
14594 \end_inset 
14595
14596
14597 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14598
14599 \end_inset 
14600
14601  the function c_func calls an assembler routine asm_func, which takes two
14602  parameters
14603 \begin_inset LatexCommand \index{function parameter}
14604
14605 \end_inset 
14606
14607 .
14608 \layout Verse
14609
14610
14611 \family typewriter 
14612 extern int asm_func(unsigned char, unsigned char);
14613 \newline 
14614
14615 \newline 
14616 int c_func (unsigned char i, unsigned char j)
14617 \newline 
14618 {
14619 \newline 
14620 \SpecialChar ~
14621 \SpecialChar ~
14622 \SpecialChar ~
14623 \SpecialChar ~
14624 return asm_func(i,j);
14625 \newline 
14626 }
14627 \newline 
14628
14629 \newline 
14630 int main()
14631 \newline 
14632 {
14633 \newline 
14634 \SpecialChar ~
14635 \SpecialChar ~
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 return c_func(10,9);
14639 \newline 
14640 }
14641 \layout Standard
14642
14643 The corresponding assembler function is:
14644 \layout Verse
14645
14646
14647 \family typewriter 
14648 .globl _asm_func_PARM_2 
14649 \newline 
14650 \SpecialChar ~
14651 \SpecialChar ~
14652 \SpecialChar ~
14653 \SpecialChar ~
14654 \SpecialChar ~
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 \SpecialChar ~
14658 .globl _asm_func 
14659 \newline 
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 \SpecialChar ~
14664 \SpecialChar ~
14665 \SpecialChar ~
14666 \SpecialChar ~
14667 \SpecialChar ~
14668 .area OSEG 
14669 \newline 
14670 _asm_func_PARM_2:
14671 \newline 
14672 \SpecialChar ~
14673 \SpecialChar ~
14674 \SpecialChar ~
14675 \SpecialChar ~
14676 \SpecialChar ~
14677 \SpecialChar ~
14678 \SpecialChar ~
14679 \SpecialChar ~
14680 .ds    1 
14681 \newline 
14682 \SpecialChar ~
14683 \SpecialChar ~
14684 \SpecialChar ~
14685 \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 \SpecialChar ~
14689 \SpecialChar ~
14690 .area CSEG 
14691 \newline 
14692 _asm_func: 
14693 \newline 
14694 \SpecialChar ~
14695 \SpecialChar ~
14696 \SpecialChar ~
14697 \SpecialChar ~
14698 \SpecialChar ~
14699 \SpecialChar ~
14700 \SpecialChar ~
14701 \SpecialChar ~
14702 mov\SpecialChar ~
14703 \SpecialChar ~
14704 \SpecialChar ~
14705 \SpecialChar ~
14706 a,dpl 
14707 \newline 
14708 \SpecialChar ~
14709 \SpecialChar ~
14710 \SpecialChar ~
14711 \SpecialChar ~
14712 \SpecialChar ~
14713 \SpecialChar ~
14714 \SpecialChar ~
14715 \SpecialChar ~
14716 add\SpecialChar ~
14717 \SpecialChar ~
14718 \SpecialChar ~
14719 \SpecialChar ~
14720 a,_asm_func_PARM_2 
14721 \newline 
14722 \SpecialChar ~
14723 \SpecialChar ~
14724 \SpecialChar ~
14725 \SpecialChar ~
14726 \SpecialChar ~
14727 \SpecialChar ~
14728 \SpecialChar ~
14729 \SpecialChar ~
14730 mov\SpecialChar ~
14731 \SpecialChar ~
14732 \SpecialChar ~
14733 \SpecialChar ~
14734 dpl,a 
14735 \newline 
14736 \SpecialChar ~
14737 \SpecialChar ~
14738 \SpecialChar ~
14739 \SpecialChar ~
14740 \SpecialChar ~
14741 \SpecialChar ~
14742 \SpecialChar ~
14743 \SpecialChar ~
14744 mov\SpecialChar ~
14745 \SpecialChar ~
14746 \SpecialChar ~
14747 \SpecialChar ~
14748 dph
14749 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14750
14751 \end_inset 
14752
14753 ,#0x00 
14754 \newline 
14755 \SpecialChar ~
14756 \SpecialChar ~
14757 \SpecialChar ~
14758 \SpecialChar ~
14759 \SpecialChar ~
14760 \SpecialChar ~
14761 \SpecialChar ~
14762 \SpecialChar ~
14763 ret
14764 \layout Standard
14765
14766 Note here that the return values
14767 \begin_inset LatexCommand \index{return value}
14768
14769 \end_inset 
14770
14771  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14772  two byte values.
14773  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14774 b' & 'acc' for four byte values.
14775 \layout Standard
14776
14777 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14778  the parameter number starting from 1, and counting from the left.
14779  The first parameter is passed in 
14780 \begin_inset Quotes eld
14781 \end_inset 
14782
14783 dpl
14784 \begin_inset Quotes erd
14785 \end_inset 
14786
14787  for a one byte parameter, 
14788 \begin_inset Quotes eld
14789 \end_inset 
14790
14791 dptr
14792 \begin_inset Quotes erd
14793 \end_inset 
14794
14795  for two bytes, 
14796 \begin_inset Quotes eld
14797 \end_inset 
14798
14799 b,dptr
14800 \begin_inset Quotes erd
14801 \end_inset 
14802
14803  for three bytes and 
14804 \begin_inset Quotes eld
14805 \end_inset 
14806
14807 acc,b,dptr
14808 \begin_inset Quotes erd
14809 \end_inset 
14810
14811  for a four bytes parameter.
14812  The variable name for the second parameter will be _<function_name>_PARM_2.
14813 \newline 
14814
14815 \newline 
14816 Assemble the assembler routine with the following command:
14817 \newline 
14818
14819 \newline 
14820
14821 \family sans 
14822 \series bold 
14823 asx8051 -losg asmfunc.asm
14824 \newline 
14825
14826 \newline 
14827
14828 \family default 
14829 \series default 
14830 Then compile and link the assembler routine to the C source file with the
14831  following command:
14832 \newline 
14833
14834 \newline 
14835
14836 \family sans 
14837 \series bold 
14838 sdcc cfunc.c asmfunc.rel
14839 \layout Subsection
14840
14841 Assembler Routine (reentrant)
14842 \layout Standard
14843
14844 In this case
14845 \begin_inset LatexCommand \index{reentrant}
14846
14847 \end_inset 
14848
14849
14850 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14851
14852 \end_inset 
14853
14854  the second parameter
14855 \begin_inset LatexCommand \index{function parameter}
14856
14857 \end_inset 
14858
14859  onwards will be passed on the stack, the parameters are pushed from right
14860  to left i.e.
14861  after the call the leftmost parameter will be on the top of the stack.
14862  Here is an example:
14863 \layout Verse
14864
14865
14866 \family typewriter 
14867 extern int asm_func(unsigned char, unsigned char);
14868 \newline 
14869
14870 \newline 
14871 int c_func (unsigned char i, unsigned char j) reentrant 
14872 \newline 
14873
14874 \newline 
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 \SpecialChar ~
14878 \SpecialChar ~
14879 return asm_func(i,j); 
14880 \newline 
14881
14882 \newline 
14883
14884 \newline 
14885 int main() 
14886 \newline 
14887
14888 \newline 
14889 \SpecialChar ~
14890 \SpecialChar ~
14891 \SpecialChar ~
14892 \SpecialChar ~
14893 return c_func(10,9); 
14894 \newline 
14895 }
14896 \layout Standard
14897
14898 The corresponding assembler routine is:
14899 \layout Verse
14900
14901
14902 \family typewriter 
14903 .globl _asm_func 
14904 \newline 
14905 _asm_func: 
14906 \newline 
14907 \SpecialChar ~
14908 \SpecialChar ~
14909 \SpecialChar ~
14910 \SpecialChar ~
14911 push  _bp 
14912 \newline 
14913 \SpecialChar ~
14914 \SpecialChar ~
14915 \SpecialChar ~
14916 \SpecialChar ~
14917 mov _bp,sp 
14918 \newline 
14919 \SpecialChar ~
14920 \SpecialChar ~
14921 \SpecialChar ~
14922 \SpecialChar ~
14923 mov r2,dpl
14924 \newline 
14925 \SpecialChar ~
14926 \SpecialChar ~
14927 \SpecialChar ~
14928 \SpecialChar ~
14929 mov a,_bp 
14930 \newline 
14931 \SpecialChar ~
14932 \SpecialChar ~
14933 \SpecialChar ~
14934 \SpecialChar ~
14935 add a,#0xfd 
14936 \newline 
14937 \SpecialChar ~
14938 \SpecialChar ~
14939 \SpecialChar ~
14940 \SpecialChar ~
14941 mov r0,a 
14942 \newline 
14943 \SpecialChar ~
14944 \SpecialChar ~
14945 \SpecialChar ~
14946 \SpecialChar ~
14947 add  a,#0xfc ;?
14948 \newline 
14949 \SpecialChar ~
14950 \SpecialChar ~
14951 \SpecialChar ~
14952 \SpecialChar ~
14953 mov  r1,a 
14954 \newline 
14955 \SpecialChar ~
14956 \SpecialChar ~
14957 \SpecialChar ~
14958 \SpecialChar ~
14959 mov  a,@r0 
14960 \newline 
14961 \SpecialChar ~
14962 \SpecialChar ~
14963 \SpecialChar ~
14964 \SpecialChar ~
14965 add  a,r2 ;?
14966 \newline 
14967 \SpecialChar ~
14968 \SpecialChar ~
14969 \SpecialChar ~
14970 \SpecialChar ~
14971 mov  dpl,a 
14972 \newline 
14973 \SpecialChar ~
14974 \SpecialChar ~
14975 \SpecialChar ~
14976 \SpecialChar ~
14977 mov  dph,#0x00 
14978 \newline 
14979 \SpecialChar ~
14980 \SpecialChar ~
14981 \SpecialChar ~
14982 \SpecialChar ~
14983 mov  sp,_bp 
14984 \newline 
14985 \SpecialChar ~
14986 \SpecialChar ~
14987 \SpecialChar ~
14988 \SpecialChar ~
14989 pop  _bp 
14990 \newline 
14991 \SpecialChar ~
14992 \SpecialChar ~
14993 \SpecialChar ~
14994 \SpecialChar ~
14995 ret
14996 \layout Standard
14997 \added_space_bottom bigskip 
14998 The compiling and linking procedure remains the same, however note the extra
14999  entry & exit linkage required for the assembler code, _bp is the stack
15000  frame pointer and is used to compute the offset into the stack for parameters
15001  and local variables.
15002 \layout Section
15003
15004 int (16 bit)
15005 \begin_inset LatexCommand \index{int (16 bit)}
15006
15007 \end_inset 
15008
15009  and long (32 bit)
15010 \begin_inset LatexCommand \index{long (32 bit)}
15011
15012 \end_inset 
15013
15014  Support
15015 \layout Standard
15016
15017 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
15018  multiplication and modulus operations are implemented by support routines.
15019  These support routines are all developed in ANSI-C to facilitate porting
15020  to other MCUs, although some model specific assembler optimizations are
15021  used.
15022  The following files contain the described routines, all of them can be
15023  found in <installdir>/share/sdcc/lib.
15024 \newline 
15025
15026 \layout Standard
15027 \align center 
15028
15029 \begin_inset  Tabular
15030 <lyxtabular version="3" rows="11" columns="2">
15031 <features>
15032 <column alignment="left" valignment="top" leftline="true" width="0">
15033 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15034 <row topline="true" bottomline="true">
15035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15036 \begin_inset Text
15037
15038 \layout Standard
15039
15040
15041 \series bold 
15042 Function
15043 \end_inset 
15044 </cell>
15045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15046 \begin_inset Text
15047
15048 \layout Standard
15049
15050
15051 \series bold 
15052 Description
15053 \end_inset 
15054 </cell>
15055 </row>
15056 <row topline="true">
15057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15058 \begin_inset Text
15059
15060 \layout Standard
15061
15062 _mulint.c 
15063 \end_inset 
15064 </cell>
15065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15066 \begin_inset Text
15067
15068 \layout Standard
15069
15070 16 bit multiplication
15071 \end_inset 
15072 </cell>
15073 </row>
15074 <row topline="true">
15075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15076 \begin_inset Text
15077
15078 \layout Standard
15079
15080 _divsint.c 
15081 \end_inset 
15082 </cell>
15083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15084 \begin_inset Text
15085
15086 \layout Standard
15087
15088  signed 16 bit division (calls _divuint)
15089 \end_inset 
15090 </cell>
15091 </row>
15092 <row topline="true">
15093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15094 \begin_inset Text
15095
15096 \layout Standard
15097
15098 _divuint.c 
15099 \end_inset 
15100 </cell>
15101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15102 \begin_inset Text
15103
15104 \layout Standard
15105
15106  unsigned 16 bit division
15107 \end_inset 
15108 </cell>
15109 </row>
15110 <row topline="true">
15111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15112 \begin_inset Text
15113
15114 \layout Standard
15115
15116 _modsint.c
15117 \end_inset 
15118 </cell>
15119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15120 \begin_inset Text
15121
15122 \layout Standard
15123
15124 signed 16 bit modulus (calls _moduint)
15125 \end_inset 
15126 </cell>
15127 </row>
15128 <row topline="true">
15129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15130 \begin_inset Text
15131
15132 \layout Standard
15133
15134 _moduint.c
15135 \end_inset 
15136 </cell>
15137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15138 \begin_inset Text
15139
15140 \layout Standard
15141
15142 unsigned 16 bit modulus
15143 \end_inset 
15144 </cell>
15145 </row>
15146 <row topline="true">
15147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15148 \begin_inset Text
15149
15150 \layout Standard
15151
15152 _mullong.c
15153 \end_inset 
15154 </cell>
15155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15156 \begin_inset Text
15157
15158 \layout Standard
15159
15160 32 bit multiplication
15161 \end_inset 
15162 </cell>
15163 </row>
15164 <row topline="true">
15165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15166 \begin_inset Text
15167
15168 \layout Standard
15169
15170 _divslong.c 
15171 \end_inset 
15172 </cell>
15173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15174 \begin_inset Text
15175
15176 \layout Standard
15177
15178  signed 32 division (calls _divulong)
15179 \end_inset 
15180 </cell>
15181 </row>
15182 <row topline="true">
15183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15184 \begin_inset Text
15185
15186 \layout Standard
15187
15188 _divulong.c 
15189 \end_inset 
15190 </cell>
15191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15192 \begin_inset Text
15193
15194 \layout Standard
15195
15196 unsigned 32 division
15197 \end_inset 
15198 </cell>
15199 </row>
15200 <row topline="true">
15201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15202 \begin_inset Text
15203
15204 \layout Standard
15205
15206 _modslong.c
15207 \end_inset 
15208 </cell>
15209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15210 \begin_inset Text
15211
15212 \layout Standard
15213
15214  signed 32 bit modulus (calls _modulong)
15215 \end_inset 
15216 </cell>
15217 </row>
15218 <row topline="true" bottomline="true">
15219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15220 \begin_inset Text
15221
15222 \layout Standard
15223
15224 _modulong.c
15225 \end_inset 
15226 </cell>
15227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15228 \begin_inset Text
15229
15230 \layout Standard
15231
15232 unsigned 32 bit modulus
15233 \end_inset 
15234 </cell>
15235 </row>
15236 </lyxtabular>
15237
15238 \end_inset 
15239
15240
15241 \newline 
15242
15243 \layout Standard
15244
15245 Since they are compiled as 
15246 \emph on 
15247 non-reentrant
15248 \emph default 
15249
15250 \begin_inset LatexCommand \index{reentrant}
15251
15252 \end_inset 
15253
15254 , interrupt
15255 \begin_inset LatexCommand \index{interrupt}
15256
15257 \end_inset 
15258
15259  service routines should not do any of the above operations.
15260  If this is unavoidable then the above routines will need to be compiled
15261  with the 
15262 \emph on 
15263 -
15264 \begin_inset ERT
15265 status Collapsed
15266
15267 \layout Standard
15268
15269 \backslash 
15270 /
15271 \end_inset 
15272
15273 -stack-auto
15274 \begin_inset LatexCommand \index{-\/-stack-auto}
15275
15276 \end_inset 
15277
15278
15279 \emph default 
15280  option, after which the source program will have to be compiled with 
15281 \emph on 
15282 -
15283 \begin_inset ERT
15284 status Collapsed
15285
15286 \layout Standard
15287
15288 \backslash 
15289 /
15290 \end_inset 
15291
15292 -int-long-reent
15293 \begin_inset LatexCommand \index{-\/-int-long-reent}
15294
15295 \end_inset 
15296
15297
15298 \emph default 
15299  option.
15300  Notice that you don't have to call these routines directly.
15301  The compiler will use them automatically every time an integer operation
15302  is required.
15303 \layout Section
15304
15305 Floating Point Support
15306 \begin_inset LatexCommand \index{Floating point support}
15307
15308 \end_inset 
15309
15310
15311 \layout Standard
15312
15313 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15314  The floating point support routines are derived from gcc's floatlib.c and
15315  consist of the following routines:
15316 \newline 
15317
15318 \layout Standard
15319 \align center 
15320
15321 \size footnotesize 
15322
15323 \begin_inset  Tabular
15324 <lyxtabular version="3" rows="17" columns="2">
15325 <features>
15326 <column alignment="left" valignment="top" leftline="true" width="0">
15327 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15328 <row topline="true" bottomline="true">
15329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15330 \begin_inset Text
15331
15332 \layout Standard
15333
15334
15335 \family roman 
15336 \series medium 
15337 \shape up 
15338 \size normal 
15339 \emph off 
15340 \bar no 
15341 \noun off 
15342 \color none
15343 Function 
15344 \end_inset 
15345 </cell>
15346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15347 \begin_inset Text
15348
15349 \layout Standard
15350
15351 Description
15352 \end_inset 
15353 </cell>
15354 </row>
15355 <row topline="true">
15356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15357 \begin_inset Text
15358
15359 \layout Standard
15360
15361
15362 \family roman 
15363 \series medium 
15364 \shape up 
15365 \size normal 
15366 \emph off 
15367 \bar no 
15368 \noun off 
15369 \color none
15370 _fsadd.c
15371 \end_inset 
15372 </cell>
15373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15374 \begin_inset Text
15375
15376 \layout Standard
15377
15378
15379 \family roman 
15380 \series medium 
15381 \shape up 
15382 \size normal 
15383 \emph off 
15384 \bar no 
15385 \noun off 
15386 \color none
15387 add floating point numbers
15388 \end_inset 
15389 </cell>
15390 </row>
15391 <row topline="true">
15392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15393 \begin_inset Text
15394
15395 \layout Standard
15396
15397
15398 \family roman 
15399 \series medium 
15400 \shape up 
15401 \size normal 
15402 \emph off 
15403 \bar no 
15404 \noun off 
15405 \color none
15406 _fssub.c 
15407 \end_inset 
15408 </cell>
15409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15410 \begin_inset Text
15411
15412 \layout Standard
15413
15414
15415 \family roman 
15416 \series medium 
15417 \shape up 
15418 \size normal 
15419 \emph off 
15420 \bar no 
15421 \noun off 
15422 \color none
15423 subtract floating point numbers 
15424 \end_inset 
15425 </cell>
15426 </row>
15427 <row topline="true">
15428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15429 \begin_inset Text
15430
15431 \layout Standard
15432
15433
15434 \family roman 
15435 \series medium 
15436 \shape up 
15437 \size normal 
15438 \emph off 
15439 \bar no 
15440 \noun off 
15441 \color none
15442 _fsdiv.c 
15443 \end_inset 
15444 </cell>
15445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15446 \begin_inset Text
15447
15448 \layout Standard
15449
15450
15451 \family roman 
15452 \series medium 
15453 \shape up 
15454 \size normal 
15455 \emph off 
15456 \bar no 
15457 \noun off 
15458 \color none
15459 divide floating point numbers 
15460 \end_inset 
15461 </cell>
15462 </row>
15463 <row topline="true">
15464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15465 \begin_inset Text
15466
15467 \layout Standard
15468
15469
15470 \family roman 
15471 \series medium 
15472 \shape up 
15473 \size normal 
15474 \emph off 
15475 \bar no 
15476 \noun off 
15477 \color none
15478 _fsmul.c 
15479 \end_inset 
15480 </cell>
15481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15482 \begin_inset Text
15483
15484 \layout Standard
15485
15486
15487 \family roman 
15488 \series medium 
15489 \shape up 
15490 \size normal 
15491 \emph off 
15492 \bar no 
15493 \noun off 
15494 \color none
15495 multiply floating point numbers 
15496 \end_inset 
15497 </cell>
15498 </row>
15499 <row topline="true">
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15501 \begin_inset Text
15502
15503 \layout Standard
15504
15505
15506 \family roman 
15507 \series medium 
15508 \shape up 
15509 \size normal 
15510 \emph off 
15511 \bar no 
15512 \noun off 
15513 \color none
15514 _fs2uchar.c
15515 \end_inset 
15516 </cell>
15517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15518 \begin_inset Text
15519
15520 \layout Standard
15521
15522
15523 \family roman 
15524 \series medium 
15525 \shape up 
15526 \size normal 
15527 \emph off 
15528 \bar no 
15529 \noun off 
15530 \color none
15531 convert floating point to unsigned char
15532 \end_inset 
15533 </cell>
15534 </row>
15535 <row topline="true">
15536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15537 \begin_inset Text
15538
15539 \layout Standard
15540
15541
15542 \family roman 
15543 \series medium 
15544 \shape up 
15545 \size normal 
15546 \emph off 
15547 \bar no 
15548 \noun off 
15549 \color none
15550 _fs2char.c
15551 \end_inset 
15552 </cell>
15553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15554 \begin_inset Text
15555
15556 \layout Standard
15557
15558
15559 \family roman 
15560 \series medium 
15561 \shape up 
15562 \size normal 
15563 \emph off 
15564 \bar no 
15565 \noun off 
15566 \color none
15567 convert floating point to signed char
15568 \end_inset 
15569 </cell>
15570 </row>
15571 <row topline="true">
15572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15573 \begin_inset Text
15574
15575 \layout Standard
15576
15577
15578 \family roman 
15579 \series medium 
15580 \shape up 
15581 \size normal 
15582 \emph off 
15583 \bar no 
15584 \noun off 
15585 \color none
15586 _fs2uint.c
15587 \end_inset 
15588 </cell>
15589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15590 \begin_inset Text
15591
15592 \layout Standard
15593
15594
15595 \family roman 
15596 \series medium 
15597 \shape up 
15598 \size normal 
15599 \emph off 
15600 \bar no 
15601 \noun off 
15602 \color none
15603 convert floating point to unsigned int
15604 \end_inset 
15605 </cell>
15606 </row>
15607 <row topline="true">
15608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15609 \begin_inset Text
15610
15611 \layout Standard
15612
15613
15614 \family roman 
15615 \series medium 
15616 \shape up 
15617 \size normal 
15618 \emph off 
15619 \bar no 
15620 \noun off 
15621 \color none
15622 _fs2int.c
15623 \end_inset 
15624 </cell>
15625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15626 \begin_inset Text
15627
15628 \layout Standard
15629
15630
15631 \family roman 
15632 \series medium 
15633 \shape up 
15634 \size normal 
15635 \emph off 
15636 \bar no 
15637 \noun off 
15638 \color none
15639 convert floating point to signed int
15640 \end_inset 
15641 </cell>
15642 </row>
15643 <row topline="true">
15644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15645 \begin_inset Text
15646
15647 \layout Standard
15648
15649
15650 \family roman 
15651 \series medium 
15652 \shape up 
15653 \size normal 
15654 \emph off 
15655 \bar no 
15656 \noun off 
15657 \color none
15658 _fs2ulong.
15659 \family default 
15660 \series default 
15661 \shape default 
15662 \size default 
15663 \emph default 
15664 \bar default 
15665 \noun default 
15666 \color default
15667 c
15668 \end_inset 
15669 </cell>
15670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15671 \begin_inset Text
15672
15673 \layout Standard
15674
15675
15676 \family roman 
15677 \series medium 
15678 \shape up 
15679 \size normal 
15680 \emph off 
15681 \bar no 
15682 \noun off 
15683 \color none
15684 convert floating point to unsigned long
15685 \end_inset 
15686 </cell>
15687 </row>
15688 <row topline="true">
15689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15690 \begin_inset Text
15691
15692 \layout Standard
15693
15694
15695 \family roman 
15696 \series medium 
15697 \shape up 
15698 \size normal 
15699 \emph off 
15700 \bar no 
15701 \noun off 
15702 \color none
15703 _fs2long.c
15704 \end_inset 
15705 </cell>
15706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15707 \begin_inset Text
15708
15709 \layout Standard
15710
15711
15712 \family roman 
15713 \series medium 
15714 \shape up 
15715 \size normal 
15716 \emph off 
15717 \bar no 
15718 \noun off 
15719 \color none
15720 convert floating point to signed long
15721 \end_inset 
15722 </cell>
15723 </row>
15724 <row topline="true">
15725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15726 \begin_inset Text
15727
15728 \layout Standard
15729
15730
15731 \family roman 
15732 \series medium 
15733 \shape up 
15734 \size normal 
15735 \emph off 
15736 \bar no 
15737 \noun off 
15738 \color none
15739 _uchar2fs.c
15740 \end_inset 
15741 </cell>
15742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15743 \begin_inset Text
15744
15745 \layout Standard
15746
15747
15748 \family roman 
15749 \series medium 
15750 \shape up 
15751 \size normal 
15752 \emph off 
15753 \bar no 
15754 \noun off 
15755 \color none
15756 convert unsigned char to floating point
15757 \end_inset 
15758 </cell>
15759 </row>
15760 <row topline="true">
15761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15762 \begin_inset Text
15763
15764 \layout Standard
15765
15766
15767 \family roman 
15768 \series medium 
15769 \shape up 
15770 \size normal 
15771 \emph off 
15772 \bar no 
15773 \noun off 
15774 \color none
15775 _char2fs.c
15776 \end_inset 
15777 </cell>
15778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15779 \begin_inset Text
15780
15781 \layout Standard
15782
15783
15784 \family roman 
15785 \series medium 
15786 \shape up 
15787 \size normal 
15788 \emph off 
15789 \bar no 
15790 \noun off 
15791 \color none
15792 convert char to floating point number
15793 \end_inset 
15794 </cell>
15795 </row>
15796 <row topline="true">
15797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15798 \begin_inset Text
15799
15800 \layout Standard
15801
15802
15803 \family roman 
15804 \series medium 
15805 \shape up 
15806 \size normal 
15807 \emph off 
15808 \bar no 
15809 \noun off 
15810 \color none
15811 _uint2fs.c
15812 \end_inset 
15813 </cell>
15814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15815 \begin_inset Text
15816
15817 \layout Standard
15818
15819
15820 \family roman 
15821 \series medium 
15822 \shape up 
15823 \size normal 
15824 \emph off 
15825 \bar no 
15826 \noun off 
15827 \color none
15828 convert unsigned int to floating point
15829 \end_inset 
15830 </cell>
15831 </row>
15832 <row topline="true">
15833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15834 \begin_inset Text
15835
15836 \layout Standard
15837
15838
15839 \family roman 
15840 \series medium 
15841 \shape up 
15842 \size normal 
15843 \emph off 
15844 \bar no 
15845 \noun off 
15846 \color none
15847 _int2fs.c
15848 \end_inset 
15849 </cell>
15850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15851 \begin_inset Text
15852
15853 \layout Standard
15854
15855
15856 \family roman 
15857 \series medium 
15858 \shape up 
15859 \size normal 
15860 \emph off 
15861 \bar no 
15862 \noun off 
15863 \color none
15864 convert int to floating point numbers
15865 \end_inset 
15866 </cell>
15867 </row>
15868 <row topline="true">
15869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15870 \begin_inset Text
15871
15872 \layout Standard
15873
15874
15875 \family roman 
15876 \series medium 
15877 \shape up 
15878 \size normal 
15879 \emph off 
15880 \bar no 
15881 \noun off 
15882 \color none
15883 _ulong2fs.c
15884 \end_inset 
15885 </cell>
15886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15887 \begin_inset Text
15888
15889 \layout Standard
15890
15891
15892 \family roman 
15893 \series medium 
15894 \shape up 
15895 \size normal 
15896 \emph off 
15897 \bar no 
15898 \noun off 
15899 \color none
15900 convert unsigned long to floating point number
15901 \end_inset 
15902 </cell>
15903 </row>
15904 <row topline="true" bottomline="true">
15905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15906 \begin_inset Text
15907
15908 \layout Standard
15909
15910
15911 \family roman 
15912 \series medium 
15913 \shape up 
15914 \size normal 
15915 \emph off 
15916 \bar no 
15917 \noun off 
15918 \color none
15919 _long2fs.c
15920 \end_inset 
15921 </cell>
15922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15923 \begin_inset Text
15924
15925 \layout Standard
15926
15927
15928 \family roman 
15929 \series medium 
15930 \shape up 
15931 \size normal 
15932 \emph off 
15933 \bar no 
15934 \noun off 
15935 \color none
15936 convert long to floating point number
15937 \end_inset 
15938 </cell>
15939 </row>
15940 </lyxtabular>
15941
15942 \end_inset 
15943
15944
15945 \newline 
15946
15947 \layout Standard
15948 \added_space_bottom bigskip 
15949 These support routines are developed in ANSI-C so there is room for space
15950  and speed improvement
15951 \begin_inset Foot
15952 collapsed false
15953
15954 \layout Standard
15955
15956 These floating point routines (
15957 \emph on 
15958 not
15959 \emph default 
15960  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15961  
15962 \end_inset 
15963
15964 .
15965  Note if all these routines are used simultaneously the data space might
15966  overflow.
15967  For serious floating point usage the large model might be needed.
15968  Also notice that you don't have to call this routines directly.
15969  The compiler will use them automatically every time a floating point operation
15970  is required.
15971 \layout Section
15972
15973 Library Routines
15974 \begin_inset LatexCommand \index{Libraries}
15975
15976 \end_inset 
15977
15978
15979 \layout Standard
15980
15981
15982 \emph on 
15983 <pending: this is messy and incomplete - a little more information is in
15984  sdcc/doc/libdoc.txt
15985 \emph default 
15986  >
15987 \layout Subsection
15988
15989 Compiler support routines (_gptrget, _mulint etc.)
15990 \layout Subsection
15991
15992 Stdclib functions (puts, printf, strcat etc.)
15993 \layout Subsubsection
15994
15995 <stdio.h>
15996 \layout Standard
15997
15998
15999 \begin_inset LatexCommand \index{<stdio.h>}
16000
16001 \end_inset 
16002
16003 As usual on embedded systems you have to provide your own 
16004 \family typewriter 
16005 getchar()
16006 \begin_inset LatexCommand \index{getchar()}
16007
16008 \end_inset 
16009
16010  
16011 \family default 
16012 and 
16013 \family typewriter 
16014 putchar()
16015 \begin_inset LatexCommand \index{putchar()}
16016
16017 \end_inset 
16018
16019
16020 \family default 
16021  routines.
16022  SDCC does not know whether the system connects to a serial line with or
16023  without handshake, LCD, keyboard or other device.
16024  And whether a 
16025 \family typewriter 
16026 lf
16027 \family default 
16028  to 
16029 \family typewriter 
16030 crlf
16031 \family default 
16032  conversion within 
16033 \family typewriter 
16034 putchar()
16035 \family default 
16036  is intended.
16037  You'll find examples for serial routines f.e.
16038  in sdcc/device/lib.
16039 \layout Standard
16040
16041 The default
16042 \family typewriter 
16043  printf()
16044 \begin_inset LatexCommand \index{printf()}
16045
16046 \end_inset 
16047
16048
16049 \family default 
16050 implementation in
16051 \family typewriter 
16052  printf_large.c
16053 \family default 
16054  does not support float (except on ds390).
16055  To enable this recompile it with the option 
16056 \emph on 
16057 -
16058 \begin_inset ERT
16059 status Collapsed
16060
16061 \layout Standard
16062
16063 \backslash 
16064 /
16065 \end_inset 
16066
16067 DUSE_FLOATS=1
16068 \begin_inset LatexCommand \index{USE\_FLOATS}
16069
16070 \end_inset 
16071
16072
16073 \emph default 
16074  on the command line.
16075  Use
16076 \emph on 
16077  -
16078 \begin_inset ERT
16079 status Collapsed
16080
16081 \layout Standard
16082
16083 \backslash 
16084 /
16085 \end_inset 
16086
16087 -model-large
16088 \begin_inset LatexCommand \index{-\/-model-large}
16089
16090 \end_inset 
16091
16092
16093 \emph default 
16094  for the mcs51 port, since this uses a lot of memory.
16095 \layout Standard
16096
16097 If you're short on memory you might want to use 
16098 \family typewriter 
16099 printf_small()
16100 \begin_inset LatexCommand \index{printf\_small()}
16101
16102 \end_inset 
16103
16104
16105 \family default 
16106  
16107 \emph on 
16108 instead
16109 \emph default 
16110  of
16111 \family typewriter 
16112  printf().
16113
16114 \family default 
16115  For the mcs51 there additionally are assembly versions 
16116 \family typewriter 
16117 printf_tiny()
16118 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16119
16120 \end_inset 
16121
16122
16123 \family default 
16124  (subset of printf using less than 270 bytes) and 
16125 \family typewriter 
16126 printf_fast()
16127 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16128
16129 \end_inset 
16130
16131  
16132 \family default 
16133 and
16134 \family typewriter 
16135  printf_fast_f()
16136 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16137
16138 \end_inset 
16139
16140
16141 \family default 
16142  (floating-point aware version of printf_fast) which should fit the requirements
16143  of many embedded systems (printf_fast() can be customized by unsetting
16144  #defines to 
16145 \emph on 
16146 not
16147 \emph default 
16148  support long variables and field widths).
16149 \layout Subsubsection
16150
16151 <malloc.h>
16152 \begin_inset LatexCommand \index{malloc.h}
16153
16154 \end_inset 
16155
16156
16157 \layout Standard
16158
16159 As of SDCC 2.6.2 you no longer need to call an initialization routine before
16160  using dynamic memory allocation
16161 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
16162
16163 \end_inset 
16164
16165  and a default heap
16166 \begin_inset LatexCommand \index{heap (malloc)}
16167
16168 \end_inset 
16169
16170  space of 1024 bytes is provided for malloc to allocate memory from.
16171  If you need a different heap size you need to recompile _heap.c with the
16172  required size defined in HEAP_SIZE.
16173  It is recommended to make a copy of this file into your project directory
16174  and compile it there with:
16175 \layout Verse
16176
16177
16178 \family typewriter 
16179 sdcc -c _heap.c -D HEAD_SIZE=2048
16180 \newline 
16181
16182 \family default 
16183 And then link it with:
16184 \layout Verse
16185
16186
16187 \family typewriter 
16188 sdcc main.rel _heap.rel
16189 \newline 
16190
16191 \layout Subsection
16192
16193 Math functions (sinf, powf, sqrtf etc.)
16194 \layout Subsubsection
16195
16196 <math.h>
16197 \layout Standard
16198
16199 See definitions in file <math.h>.
16200 \layout Subsection
16201
16202 Other libraries
16203 \layout Standard
16204
16205 Libraries
16206 \begin_inset LatexCommand \index{Libraries}
16207
16208 \end_inset 
16209
16210  included in SDCC should have a license at least as liberal as the GNU Lesser
16211  General Public License
16212 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16213
16214 \end_inset 
16215
16216  
16217 \emph on 
16218 LGPL
16219 \emph default 
16220 .
16221 \layout Comment
16222
16223 license statements for the libraries are missing.
16224  sdcc/device/lib/ser_ir.c
16225 \layout Comment
16226
16227 or _decdptr f.e.
16228  come with a GPL (as opposed to LGPL) License - this will not be liberal
16229  enough for many embedded programmers.
16230 \layout Standard
16231
16232 If you have ported some library or want to share experience about some code
16233  which f.e.
16234  falls into any of these categories Busses (I
16235 \begin_inset Formula $^{\textrm{2}}$
16236 \end_inset 
16237
16238 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16239  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16240  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
16241 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16242
16243 \end_inset 
16244
16245 \SpecialChar ~
16246 would certainly like to hear about it.
16247 \layout Standard
16248 \added_space_bottom bigskip 
16249 Programmers coding for embedded systems are not especially famous for being
16250  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16251 e these references are very valuable.
16252  Let's help to create a climate where information is shared.
16253 \layout Section
16254
16255 Memory Models
16256 \layout Subsection
16257
16258 MCS51 Memory Models
16259 \begin_inset LatexCommand \index{Memory model}
16260
16261 \end_inset 
16262
16263
16264 \begin_inset LatexCommand \index{MCS51 memory model}
16265
16266 \end_inset 
16267
16268
16269 \layout Subsubsection
16270
16271 Small, Medium and Large
16272 \layout Standard
16273
16274 SDCC allows three memory models for MCS51 code, 
16275 \shape slanted 
16276 small, medium
16277 \shape default 
16278  and 
16279 \shape slanted 
16280 large
16281 \shape default 
16282 .
16283  Modules compiled with different memory models should 
16284 \emph on 
16285 never
16286 \emph default 
16287  be combined together or the results would be unpredictable.
16288  The library routines supplied with the compiler are compiled as small,
16289  medium and large.
16290  The compiled library modules are contained in separate directories as small,
16291  medium and large so that you can link to the appropriate set.
16292 \layout Standard
16293
16294 When the medium or large model is used all variables declared without a
16295  storage class will be allocated into the external ram, this includes all
16296  parameters and local variables (for non-reentrant
16297 \begin_inset LatexCommand \index{reentrant}
16298
16299 \end_inset 
16300
16301  functions).
16302  When the small model is used variables without storage class are allocated
16303  in the internal ram.
16304 \layout Standard
16305
16306 Judicious usage of the processor specific storage classes
16307 \begin_inset LatexCommand \index{Storage class}
16308
16309 \end_inset 
16310
16311  and the 'reentrant' function type will yield much more efficient code,
16312  than using the large model.
16313  Several optimizations are disabled when the program is compiled using the
16314  large model, it is therefore recommended that the small model be used unless
16315  absolutely required.
16316 \layout Subsubsection
16317
16318 External Stack
16319 \begin_inset LatexCommand \label{sub:External-Stack}
16320
16321 \end_inset 
16322
16323
16324 \begin_inset LatexCommand \index{stack}
16325
16326 \end_inset 
16327
16328
16329 \begin_inset LatexCommand \index{External stack (mcs51)}
16330
16331 \end_inset 
16332
16333
16334 \layout Standard
16335
16336 The external stack (-
16337 \begin_inset ERT
16338 status Collapsed
16339
16340 \layout Standard
16341
16342 \backslash 
16343 /
16344 \end_inset 
16345
16346 -xstack option
16347 \begin_inset LatexCommand \index{-\/-xstack}
16348
16349 \end_inset 
16350
16351 ) is located in pdata
16352 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16353
16354 \end_inset 
16355
16356  memory (usually at the start of the external ram segment) and uses all
16357  unused space in pdata (max.
16358  256 bytes).
16359  When -
16360 \begin_inset ERT
16361 status Collapsed
16362
16363 \layout Standard
16364
16365 \backslash 
16366 /
16367 \end_inset 
16368
16369 -xstack option is used to compile the program, the parameters and local
16370  variables
16371 \begin_inset LatexCommand \index{local variables}
16372
16373 \end_inset 
16374
16375  of all reentrant functions are allocated in this area.
16376  This option is provided for programs with large stack space requirements.
16377  When used with the -
16378 \begin_inset ERT
16379 status Collapsed
16380
16381 \layout Standard
16382
16383 \backslash 
16384 /
16385 \end_inset 
16386
16387 -stack-auto
16388 \begin_inset LatexCommand \index{-\/-stack-auto}
16389
16390 \end_inset 
16391
16392  option, all parameters and local variables are allocated on the external
16393  stack (note: support libraries will need to be recompiled with the same
16394  options.
16395  There is a predefined target in the library makefile).
16396 \layout Standard
16397
16398 The compiler outputs the higher order address byte of the external ram segment
16399  into port P2
16400 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16401
16402 \end_inset 
16403
16404  (see also section 
16405 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16406
16407 \end_inset 
16408
16409 ), therefore when using the External Stack option, this port 
16410 \emph on 
16411 may not
16412 \emph default 
16413  be used by the application program.
16414 \layout Subsection
16415
16416 DS390 Memory Model
16417 \begin_inset LatexCommand \index{Memory model}
16418
16419 \end_inset 
16420
16421
16422 \begin_inset LatexCommand \index{DS390 memory model}
16423
16424 \end_inset 
16425
16426
16427 \layout Standard
16428
16429 The only model supported is Flat 24
16430 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
16431
16432 \end_inset 
16433
16434 .
16435  This generates code for the 24 bit contiguous addressing mode of the Dallas
16436  DS80C390 part.
16437  In this mode, up to four meg of external RAM or code space can be directly
16438  addressed.
16439  See the data sheets at www.dalsemi.com for further information on this part.
16440 \newline 
16441
16442 \newline 
16443 Note that the compiler does not generate any code to place the processor
16444  into 24 bitmode (although 
16445 \emph on 
16446 tinibios
16447 \emph default 
16448  in the ds390 libraries will do that for you).
16449  If you don't use 
16450 \emph on 
16451 tinibios
16452 \emph default 
16453
16454 \begin_inset LatexCommand \index{Tinibios (DS390)}
16455
16456 \end_inset 
16457
16458 , the boot loader or similar code must ensure that the processor is in 24
16459  bit contiguous addressing mode before calling the SDCC startup code.
16460 \newline 
16461
16462 \newline 
16463 Like the 
16464 \emph on 
16465 -
16466 \begin_inset ERT
16467 status Collapsed
16468
16469 \layout Standard
16470
16471 \backslash 
16472 /
16473 \end_inset 
16474
16475 -model-large
16476 \emph default 
16477  option, variables will by default be placed into the XDATA segment.
16478  
16479 \newline 
16480
16481 \newline 
16482 Segments may be placed anywhere in the 4 meg address space using the usual
16483  -
16484 \begin_inset ERT
16485 status Collapsed
16486
16487 \layout Standard
16488
16489 \backslash 
16490 /
16491 \end_inset 
16492
16493 -*-loc options.
16494  Note that if any segments are located above 64K, the -r flag must be passed
16495  to the linker to generate the proper segment relocations, and the Intel
16496  HEX output format must be used.
16497  The -r flag can be passed to the linker by using the option 
16498 \emph on 
16499 -Wl-r
16500 \emph default 
16501  on the SDCC command line.
16502  However, currently the linker can not handle code segments > 64k.
16503 \layout Section
16504
16505 Pragmas
16506 \begin_inset LatexCommand \label{sec:Pragmas}
16507
16508 \end_inset 
16509
16510
16511 \begin_inset LatexCommand \index{Pragmas}
16512
16513 \end_inset 
16514
16515
16516 \layout Standard
16517
16518 SDCC supports the following #pragma directives:
16519 \layout Itemize
16520
16521
16522 \series bold 
16523 save
16524 \series default 
16525
16526 \begin_inset LatexCommand \index{\#pragma save}
16527
16528 \end_inset 
16529
16530  - this will save most current options to the save/restore stack.
16531  See #pragma\SpecialChar ~
16532 restore.
16533 \layout Itemize
16534
16535
16536 \series bold 
16537 restore
16538 \series default 
16539
16540 \begin_inset LatexCommand \index{\#pragma restore}
16541
16542 \end_inset 
16543
16544  - will restore saved options from the last save.
16545  saves & restores can be nested.
16546  SDCC uses a save/restore stack: save pushes current options to the stack,
16547  restore pulls current options from the stack.
16548  See #pragma\SpecialChar ~
16549 save.
16550 \newline 
16551
16552 \layout Itemize
16553
16554
16555 \series bold 
16556 callee_saves
16557 \series default 
16558
16559 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16560
16561 \end_inset 
16562
16563
16564 \begin_inset LatexCommand \index{function prologue}
16565
16566 \end_inset 
16567
16568  function1[,function2[,function3...]] - The compiler by default uses a caller
16569  saves convention for register saving across function calls, however this
16570  can cause unnecessary register pushing & popping
16571 \begin_inset LatexCommand \index{push/pop}
16572
16573 \end_inset 
16574
16575  when calling small functions from larger functions.
16576  This option can be used to switch off the register saving convention for
16577  the function names specified.
16578  The compiler will not save registers when calling these functions, extra
16579  code need to be manually inserted at the entry & exit for these functions
16580  to save & restore the registers used by these functions, this can SUBSTANTIALLY
16581  reduce code & improve run time performance of the generated code.
16582  In the future the compiler (with inter procedural analysis) may be able
16583  to determine the appropriate scheme to use for each function call.
16584  If -
16585 \begin_inset ERT
16586 status Collapsed
16587
16588 \layout Standard
16589
16590 \backslash 
16591 /
16592 \end_inset 
16593
16594 -callee-saves command line option is used, the function names specified
16595  in #pragma\SpecialChar ~
16596 callee_saves
16597 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16598
16599 \end_inset 
16600
16601  is appended to the list of functions specified in the command line.
16602 \layout Itemize
16603
16604
16605 \series bold 
16606 exclude
16607 \series default 
16608
16609 \begin_inset LatexCommand \index{\#pragma exclude}
16610
16611 \end_inset 
16612
16613  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
16614  of pairs of push/pop
16615 \begin_inset LatexCommand \index{push/pop}
16616
16617 \end_inset 
16618
16619  instructions in 
16620 \emph on 
16621 I
16622 \emph default 
16623 nterrupt
16624 \begin_inset LatexCommand \index{interrupt}
16625
16626 \end_inset 
16627
16628  
16629 \emph on 
16630 S
16631 \emph default 
16632 ervice 
16633 \emph on 
16634 R
16635 \emph default 
16636 outines.
16637  The directive should be placed immediately before the ISR function definition
16638  and it affects ALL ISR functions following it.
16639  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
16640 exclude\SpecialChar ~
16641 none
16642 \begin_inset LatexCommand \index{\#pragma exclude}
16643
16644 \end_inset 
16645
16646 .
16647  See also the related keyword _naked
16648 \begin_inset LatexCommand \index{\_naked}
16649
16650 \end_inset 
16651
16652
16653 \begin_inset LatexCommand \index{\_\_naked}
16654
16655 \end_inset 
16656
16657 .
16658 \layout Itemize
16659
16660
16661 \series bold 
16662 less_pedantic
16663 \series default 
16664
16665 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16666
16667 \end_inset 
16668
16669  - the compiler will not warn you anymore for obvious mistakes, you'r on
16670  your own now ;-(
16671 \layout Itemize
16672
16673
16674 \series bold 
16675 disable_warning
16676 \series default 
16677  <nnnn>
16678 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16679
16680 \end_inset 
16681
16682  - the compiler will not warn you anymore about warning number <nnnn>.
16683 \layout Itemize
16684
16685
16686 \series bold 
16687 nogcse
16688 \series default 
16689
16690 \begin_inset LatexCommand \index{\#pragma nogcse}
16691
16692 \end_inset 
16693
16694  - will stop global common subexpression elimination.
16695 \layout Itemize
16696
16697
16698 \series bold 
16699 noinduction
16700 \series default 
16701
16702 \begin_inset LatexCommand \index{\#pragma noinduction}
16703
16704 \end_inset 
16705
16706  - will stop loop induction optimizations.
16707 \layout Itemize
16708
16709
16710 \series bold 
16711 noinvariant
16712 \series default 
16713
16714 \begin_inset LatexCommand \index{\#pragma noinvariant}
16715
16716 \end_inset 
16717
16718  - will not do loop invariant optimizations.
16719  For more details see Loop Invariants in section
16720 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16721
16722 \end_inset 
16723
16724 .
16725 \layout Itemize
16726
16727
16728 \series bold 
16729 noiv
16730 \series default 
16731
16732 \begin_inset LatexCommand \index{\#pragma noiv}
16733
16734 \end_inset 
16735
16736  - Do not generate interrupt
16737 \begin_inset LatexCommand \index{interrupt}
16738
16739 \end_inset 
16740
16741  vector table
16742 \begin_inset LatexCommand \index{interrupt vector table}
16743
16744 \end_inset 
16745
16746  entries for all ISR functions defined after the pragma.
16747  This is useful in cases where the interrupt vector table must be defined
16748  manually, or when there is a secondary, manually defined interrupt vector
16749  table (e.g.
16750  for the autovector feature of the Cypress EZ-USB FX2).
16751  More elegantly this can be achieved by obmitting the optional interrupt
16752  number after the interrupt keyword, see section 
16753 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16754
16755 \end_inset 
16756
16757 \SpecialChar ~
16758 about interrupts.
16759 \layout Itemize
16760
16761
16762 \series bold 
16763 nojtbound
16764 \series default 
16765
16766 \begin_inset LatexCommand \index{\#pragma nojtbound}
16767
16768 \end_inset 
16769
16770  - will not generate code for boundary value checking, when switch statements
16771  are turned into jump-tables (dangerous).
16772  For more details see section 
16773 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16774
16775 \end_inset 
16776
16777 .
16778 \layout Itemize
16779
16780
16781 \series bold 
16782 noloopreverse
16783 \series default 
16784
16785 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16786
16787 \end_inset 
16788
16789  - Will not do loop reversal optimization
16790 \layout Itemize
16791
16792
16793 \series bold 
16794 nooverlay
16795 \series default 
16796
16797 \begin_inset LatexCommand \index{\#pragma nooverlay}
16798
16799 \end_inset 
16800
16801  - the compiler will not overlay the parameters and local variables of a
16802  function.
16803 \layout Itemize
16804
16805
16806 \series bold 
16807 stackauto
16808 \series default 
16809
16810 \begin_inset LatexCommand \index{\#pragma stackauto}
16811
16812 \end_inset 
16813
16814 - See option -
16815 \begin_inset ERT
16816 status Collapsed
16817
16818 \layout Standard
16819
16820 \backslash 
16821 /
16822 \end_inset 
16823
16824 -stack-auto
16825 \begin_inset LatexCommand \index{-\/-stack-auto}
16826
16827 \end_inset 
16828
16829  and section 
16830 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16831
16832 \end_inset 
16833
16834  Parameters and Local Variables.
16835 \layout Itemize
16836
16837
16838 \series bold 
16839 opt_code_speed
16840 \series default 
16841  
16842 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16843
16844 \end_inset 
16845
16846 - The compiler will optimize code generation towards fast code, possibly
16847  at the expense of code size.
16848  Currently this has little effect.
16849 \layout Itemize
16850
16851
16852 \series bold 
16853 opt_code_size
16854 \series default 
16855  
16856 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16857
16858 \end_inset 
16859
16860 - The compiler will optimize code generation towards compact code, possibly
16861  at the expense of code speed.
16862  Currently this has little effect.
16863 \layout Itemize
16864
16865
16866 \series bold 
16867 opt_code_balanced
16868 \series default 
16869  
16870 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16871
16872 \end_inset 
16873
16874 - The compiler will attempt to generate code that is both compact and fast,
16875  as long as meeting one goal is not a detriment to the other (this is the
16876  default).
16877  
16878 \layout Itemize
16879
16880
16881 \series bold 
16882 std_sdcc89
16883 \series default 
16884  
16885 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16886
16887 \end_inset 
16888
16889 - Generally follow the C89 standard, but allow SDCC features that conflict
16890  with the standard (default).
16891 \layout Itemize
16892
16893
16894 \series bold 
16895 std_c89
16896 \series default 
16897  
16898 \begin_inset LatexCommand \index{\#pragma std\_c89}
16899
16900 \end_inset 
16901
16902 - Follow the C89 standard and disable SDCC features that conflict with the
16903  standard.
16904 \layout Itemize
16905
16906
16907 \series bold 
16908 std_sdcc99
16909 \series default 
16910  
16911 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16912
16913 \end_inset 
16914
16915 - Generally follow the C99 standard, but allow SDCC features that conflict
16916  with the standard (incomplete support).
16917 \layout Itemize
16918
16919
16920 \series bold 
16921 std_c99
16922 \series default 
16923  
16924 \begin_inset LatexCommand \index{\#pragma std\_c99}
16925
16926 \end_inset 
16927
16928 - Follow the C99 standard and disable SDCC features that conflict with the
16929  standard (incomplete support).
16930 \layout Itemize
16931
16932
16933 \series bold 
16934 codeseg
16935 \series default 
16936  <name>
16937 \begin_inset LatexCommand \index{\#pragma codeseg}
16938
16939 \end_inset 
16940
16941 - Use this name (max.
16942  8 characters) for the code segment.
16943  See option -
16944 \begin_inset ERT
16945 status Collapsed
16946
16947 \layout Standard
16948
16949 \backslash 
16950 /
16951 \end_inset 
16952
16953 -codeseg.
16954 \layout Itemize
16955
16956
16957 \series bold 
16958 constseg
16959 \series default 
16960  <name>
16961 \begin_inset LatexCommand \index{\#pragma constseg}
16962
16963 \end_inset 
16964
16965 - Use this name (max.
16966  8 characters) for the const segment.
16967  See option -
16968 \begin_inset ERT
16969 status Collapsed
16970
16971 \layout Standard
16972
16973 \backslash 
16974 /
16975 \end_inset 
16976
16977 -constseg.
16978 \layout Standard
16979
16980 The preprocessor SDCPP
16981 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
16982
16983 \end_inset 
16984
16985  supports the following #pragma directives:
16986 \layout Itemize
16987
16988
16989 \series bold 
16990 pedantic_parse_number
16991 \series default 
16992
16993 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
16994
16995 \end_inset 
16996
16997  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
16998  parsed properly and the macro LO_B(3) gets expanded.
16999  Default is off.
17000  Below is an example on how to use this pragma.
17001
17002 \emph on 
17003  Note: this functionality is not in conformance with standard!
17004 \layout Verse
17005
17006
17007 \family typewriter 
17008 #pragma pedantic_parse_number +
17009 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
17010
17011 \end_inset 
17012
17013
17014 \newline 
17015
17016 \newline 
17017 #define LO_B(x) ((x) & 0xff)
17018 \newline 
17019
17020 \newline 
17021 unsigned char foo(void)
17022 \newline 
17023 {
17024 \newline 
17025 \SpecialChar ~
17026 \SpecialChar ~
17027 \SpecialChar ~
17028 unsigned char c=0xfe-LO_B(3);
17029 \newline 
17030
17031 \newline 
17032 \SpecialChar ~
17033 \SpecialChar ~
17034 \SpecialChar ~
17035 return c;
17036 \newline 
17037 }
17038 \newline 
17039
17040 \layout Itemize
17041
17042
17043 \series bold 
17044 preproc_asm
17045 \series default 
17046
17047 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
17048
17049 \end_inset 
17050
17051  (+ | -) - switch _asm _endasm block preprocessing on / off.
17052  Default is on.
17053  You use this prama to define multilines of assembly code.
17054  This will prevent the preprocessor from changing the formating required
17055  by assembly code.
17056  Below is an example on how to use this pragma.
17057 \layout Verse
17058
17059
17060 \family typewriter 
17061 #pragma preproc_asm -
17062 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
17063
17064 \end_inset 
17065
17066
17067 \newline 
17068 #define MYDELAY _asm
17069 \newline 
17070 \SpecialChar ~
17071 \SpecialChar ~
17072 \SpecialChar ~
17073 nop ;my assembly comment...
17074 \newline 
17075 \SpecialChar ~
17076 \SpecialChar ~
17077 \SpecialChar ~
17078 nop
17079 \newline 
17080 \SpecialChar ~
17081 \SpecialChar ~
17082 \SpecialChar ~
17083 nop
17084 \newline 
17085 _endasm
17086 \newline 
17087 #pragma preproc_asm +
17088 \newline 
17089
17090 \newline 
17091 void foo (void) 
17092 \newline 
17093
17094 \newline 
17095 \SpecialChar ~
17096 \SpecialChar ~
17097 \SpecialChar ~
17098  ...
17099  
17100 \newline 
17101 \SpecialChar ~
17102 \SpecialChar ~
17103 \SpecialChar ~
17104  MYDELAY;
17105 \newline 
17106 \SpecialChar ~
17107 \SpecialChar ~
17108 \SpecialChar ~
17109  ...
17110  
17111 \newline 
17112
17113 \newline 
17114
17115 \layout Itemize
17116
17117
17118 \series bold 
17119 sdcc_hash
17120 \series default 
17121
17122 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17123
17124 \end_inset 
17125
17126  (+ | -) - Allow "naked" hash in macro definition, for example:
17127 \newline 
17128
17129 \family typewriter 
17130 #define DIR_LO(x) #(x & 0xff)
17131 \family default 
17132
17133 \newline 
17134 Default is off.
17135  Below is an example on how to use this pragma.
17136 \layout Verse
17137
17138
17139 \family typewriter 
17140 #pragma preproc_asm +
17141 \newline 
17142 #pragma sdcc_hash +
17143 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17144
17145 \end_inset 
17146
17147
17148 \newline 
17149
17150 \newline 
17151 #define ROMCALL(x) 
17152 \backslash 
17153
17154 \newline 
17155 \SpecialChar ~
17156 \SpecialChar ~
17157 \SpecialChar ~
17158 mov R6_B3, #(x & 0xff) 
17159 \backslash 
17160
17161 \newline 
17162 \SpecialChar ~
17163 \SpecialChar ~
17164 \SpecialChar ~
17165 mov R7_B3, #((x >> 8) & 0xff) 
17166 \backslash 
17167
17168 \newline 
17169 \SpecialChar ~
17170 \SpecialChar ~
17171 \SpecialChar ~
17172 lcall __romcall
17173 \newline 
17174
17175 \newline 
17176 ...
17177 \newline 
17178 _asm
17179 \newline 
17180 ROMCALL(72)
17181 \newline 
17182 _endasm;
17183 \newline 
17184 ...
17185 \newline 
17186
17187 \layout Standard
17188
17189 The pragma's are intended to be used to turn-on or off certain optimizations
17190  which might cause the compiler to generate extra stack / data space to
17191  store compiler generated temporary variables.
17192  This usually happens in large functions.
17193  Pragma directives should be used as shown in the following example, they
17194  are used to control options & optimizations for a given function; pragmas
17195  should be placed before and/or after a function, placing pragma's inside
17196  a function body could have unpredictable results.
17197 \layout Verse
17198
17199
17200 \family typewriter 
17201 #pragma save
17202 \begin_inset LatexCommand \index{\#pragma save}
17203
17204 \end_inset 
17205
17206  \SpecialChar ~
17207 \SpecialChar ~
17208 \SpecialChar ~
17209 \SpecialChar ~
17210 \SpecialChar ~
17211 \SpecialChar ~
17212 \SpecialChar ~
17213 /* save the current settings */ 
17214 \newline 
17215 #pragma nogcse
17216 \begin_inset LatexCommand \index{\#pragma nogcse}
17217
17218 \end_inset 
17219
17220  \SpecialChar ~
17221 \SpecialChar ~
17222 \SpecialChar ~
17223 \SpecialChar ~
17224 \SpecialChar ~
17225 /* turnoff global subexpression elimination */ 
17226 \newline 
17227 #pragma noinduction
17228 \begin_inset LatexCommand \index{\#pragma noinduction}
17229
17230 \end_inset 
17231
17232  /* turn off induction optimizations */ 
17233 \newline 
17234 int foo () 
17235 \newline 
17236
17237 \newline 
17238 \SpecialChar ~
17239  \SpecialChar ~
17240  ...
17241  
17242 \newline 
17243 \SpecialChar ~
17244  \SpecialChar ~
17245  /* large code */ 
17246 \newline 
17247 \SpecialChar ~
17248  \SpecialChar ~
17249  ...
17250  
17251 \newline 
17252
17253 \newline 
17254 #pragma restore
17255 \begin_inset LatexCommand \index{\#pragma restore}
17256
17257 \end_inset 
17258
17259  /* turn the optimizations back on */
17260 \layout Standard
17261
17262 The compiler will generate a warning message when extra space is allocated.
17263  It is strongly recommended that the save and restore pragma's be used when
17264  changing options for a function.
17265 \newline 
17266
17267 \newline 
17268
17269 \newline 
17270
17271 \layout Section
17272
17273 Defines Created by the Compiler
17274 \layout Standard
17275
17276 The compiler creates the following #defines
17277 \begin_inset LatexCommand \index{\#defines}
17278
17279 \end_inset 
17280
17281
17282 \begin_inset LatexCommand \index{Defines created by the compiler}
17283
17284 \end_inset 
17285
17286 :
17287 \newline 
17288
17289 \layout Standard
17290
17291
17292 \begin_inset  Tabular
17293 <lyxtabular version="3" rows="11" columns="2">
17294 <features>
17295 <column alignment="left" valignment="top" leftline="true" width="3in">
17296 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
17297 <row topline="true" bottomline="true">
17298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17299 \begin_inset Text
17300
17301 \layout Standard
17302
17303
17304 \series bold 
17305 #define
17306 \end_inset 
17307 </cell>
17308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17309 \begin_inset Text
17310
17311 \layout Standard
17312
17313
17314 \series bold 
17315 Description
17316 \end_inset 
17317 </cell>
17318 </row>
17319 <row topline="true">
17320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17321 \begin_inset Text
17322
17323 \layout Standard
17324
17325 SDCC
17326 \begin_inset LatexCommand \index{SDCC}
17327
17328 \end_inset 
17329
17330  
17331 \end_inset 
17332 </cell>
17333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17334 \begin_inset Text
17335
17336 \layout Standard
17337
17338 Always defined.
17339  Since version 2.5.6 the version number as an int (ex.
17340  256)
17341 \end_inset 
17342 </cell>
17343 </row>
17344 <row topline="true">
17345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17346 \begin_inset Text
17347
17348 \layout Standard
17349
17350 SDCC_mcs51
17351 \begin_inset LatexCommand \index{SDCC\_mcs51}
17352
17353 \end_inset 
17354
17355  or SDCC_ds390
17356 \begin_inset LatexCommand \index{SDCC\_ds390}
17357
17358 \end_inset 
17359
17360  or SDCC_z80
17361 \begin_inset LatexCommand \index{SDCC\_z80}
17362
17363 \end_inset 
17364
17365 , etc.
17366 \end_inset 
17367 </cell>
17368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17369 \begin_inset Text
17370
17371 \layout Standard
17372
17373 depending on the model used (e.g.: -mds390)
17374 \end_inset 
17375 </cell>
17376 </row>
17377 <row topline="true">
17378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17379 \begin_inset Text
17380
17381 \layout Standard
17382
17383 __mcs51
17384 \begin_inset LatexCommand \index{\_\_mcs51}
17385
17386 \end_inset 
17387
17388 , __ds390
17389 \begin_inset LatexCommand \index{\_\_ds390}
17390
17391 \end_inset 
17392
17393 , __hc08
17394 \begin_inset LatexCommand \index{\_\_hc08}
17395
17396 \end_inset 
17397
17398 , __z80
17399 \begin_inset LatexCommand \index{\_\_z80}
17400
17401 \end_inset 
17402
17403 , etc
17404 \end_inset 
17405 </cell>
17406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17407 \begin_inset Text
17408
17409 \layout Standard
17410
17411 depending on the model used (e.g.
17412  -mz80)
17413 \end_inset 
17414 </cell>
17415 </row>
17416 <row topline="true">
17417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17418 \begin_inset Text
17419
17420 \layout Standard
17421
17422 SDCC_STACK_AUTO
17423 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
17424
17425 \end_inset 
17426
17427
17428 \end_inset 
17429 </cell>
17430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17431 \begin_inset Text
17432
17433 \layout Standard
17434
17435 when 
17436 \emph on 
17437 -
17438 \begin_inset ERT
17439 status Collapsed
17440
17441 \layout Standard
17442
17443 \backslash 
17444 /
17445 \end_inset 
17446
17447 -stack-auto
17448 \emph default 
17449  option is used
17450 \end_inset 
17451 </cell>
17452 </row>
17453 <row topline="true">
17454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17455 \begin_inset Text
17456
17457 \layout Standard
17458
17459 SDCC_MODEL_SMALL
17460 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
17461
17462 \end_inset 
17463
17464
17465 \end_inset 
17466 </cell>
17467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17468 \begin_inset Text
17469
17470 \layout Standard
17471
17472 when 
17473 \emph on 
17474 -
17475 \begin_inset ERT
17476 status Collapsed
17477
17478 \layout Standard
17479
17480 \backslash 
17481 /
17482 \end_inset 
17483
17484 -model-small
17485 \emph default 
17486  is used
17487 \end_inset 
17488 </cell>
17489 </row>
17490 <row topline="true">
17491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17492 \begin_inset Text
17493
17494 \layout Standard
17495
17496 SDCC_MODEL_MEDIUM
17497 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
17498
17499 \end_inset 
17500
17501
17502 \end_inset 
17503 </cell>
17504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17505 \begin_inset Text
17506
17507 \layout Standard
17508
17509 when 
17510 \emph on 
17511 -
17512 \begin_inset ERT
17513 status Collapsed
17514
17515 \layout Standard
17516
17517 \backslash 
17518 /
17519 \end_inset 
17520
17521 -model-medium
17522 \emph default 
17523  is used
17524 \end_inset 
17525 </cell>
17526 </row>
17527 <row topline="true">
17528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17529 \begin_inset Text
17530
17531 \layout Standard
17532
17533 SDCC_MODEL_LARGE
17534 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
17535
17536 \end_inset 
17537
17538
17539 \end_inset 
17540 </cell>
17541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17542 \begin_inset Text
17543
17544 \layout Standard
17545
17546 when 
17547 \emph on 
17548 -
17549 \begin_inset ERT
17550 status Collapsed
17551
17552 \layout Standard
17553
17554 \backslash 
17555 /
17556 \end_inset 
17557
17558 -model-large
17559 \emph default 
17560  is used
17561 \end_inset 
17562 </cell>
17563 </row>
17564 <row topline="true">
17565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17566 \begin_inset Text
17567
17568 \layout Standard
17569
17570 SDCC_USE_XSTACK
17571 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
17572
17573 \end_inset 
17574
17575
17576 \end_inset 
17577 </cell>
17578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17579 \begin_inset Text
17580
17581 \layout Standard
17582
17583 when 
17584 \emph on 
17585 -
17586 \begin_inset ERT
17587 status Collapsed
17588
17589 \layout Standard
17590
17591 \backslash 
17592 /
17593 \end_inset 
17594
17595 -xstack
17596 \emph default 
17597  option is used
17598 \end_inset 
17599 </cell>
17600 </row>
17601 <row topline="true">
17602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17603 \begin_inset Text
17604
17605 \layout Standard
17606
17607 SDCC_STACK_TENBIT
17608 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
17609
17610 \end_inset 
17611
17612  
17613 \end_inset 
17614 </cell>
17615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17616 \begin_inset Text
17617
17618 \layout Standard
17619
17620 when 
17621 \emph on 
17622 -mds390
17623 \emph default 
17624  is used
17625 \end_inset 
17626 </cell>
17627 </row>
17628 <row topline="true" bottomline="true">
17629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17630 \begin_inset Text
17631
17632 \layout Standard
17633
17634 SDCC_MODEL_FLAT24
17635 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
17636
17637 \end_inset 
17638
17639
17640 \end_inset 
17641 </cell>
17642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17643 \begin_inset Text
17644
17645 \layout Standard
17646
17647 when 
17648 \emph on 
17649 -mds390
17650 \emph default 
17651  is used
17652 \end_inset 
17653 </cell>
17654 </row>
17655 </lyxtabular>
17656
17657 \end_inset 
17658
17659
17660 \layout Chapter
17661
17662 Notes on supported Processors
17663 \layout Section
17664
17665 MCS51 variants
17666 \begin_inset LatexCommand \label{sub:MCS51-variants}
17667
17668 \end_inset 
17669
17670
17671 \begin_inset LatexCommand \index{MCS51 variants}
17672
17673 \end_inset 
17674
17675
17676 \layout Standard
17677
17678 MCS51 processors are available from many vendors and come in many different
17679  flavours.
17680  While they might differ considerably in respect to Special Function Registers
17681  the core MCS51 is usually not modified or is kept compatible.
17682  
17683 \layout Subsection
17684
17685 pdata access by SFR 
17686 \layout Standard
17687
17688 With the upcome of devices with internal xdata and flash memory devices
17689  using port P2
17690 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17691
17692 \end_inset 
17693
17694  as dedicated I/O port is becoming more popular.
17695  Switching the high byte for pdata
17696 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17697
17698 \end_inset 
17699
17700  access which was formerly done by port P2 is then achieved by a Special
17701  Function Register
17702 \begin_inset LatexCommand \index{sfr}
17703
17704 \end_inset 
17705
17706 .
17707  In well-established MCS51 tradition the address of this 
17708 \emph on 
17709 sfr
17710 \emph default 
17711  is where the chip designers decided to put it.
17712  Needless to say that they didn't agree on a common name either.
17713  So that the startup code can correctly initialize xdata variables, you
17714  should define an sfr with the name _XPAGE
17715 \family typewriter 
17716
17717 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
17718
17719 \end_inset 
17720
17721
17722 \family default 
17723  at the appropriate location if the default, port P2, is not used for this.
17724  Some examples are:
17725 \layout Verse
17726
17727
17728 \family typewriter 
17729 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
17730 \layout Verse
17731
17732
17733 \family typewriter 
17734 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17735 \layout Verse
17736
17737
17738 \family typewriter 
17739 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17740 \layout Standard
17741
17742 For more exotic implementations further customizations may be needed.
17743  See section 
17744 \begin_inset LatexCommand \ref{sub:Startup-Code}
17745
17746 \end_inset 
17747
17748  for other possibilities.
17749 \layout Subsection
17750
17751 Other Features available by SFR
17752 \layout Standard
17753 \added_space_bottom bigskip 
17754 Some MCS51 variants offer features like Double DPTR
17755 \begin_inset LatexCommand \index{DPTR}
17756
17757 \end_inset 
17758
17759 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17760  These are currently not used for the MCS51 port.
17761  If you absolutely need them you can fall back to inline assembly or submit
17762  a patch to SDCC.
17763 \layout Section
17764
17765 DS400 port
17766 \layout Standard
17767 \added_space_bottom bigskip 
17768 The DS80C400
17769 \begin_inset LatexCommand \index{DS80C400}
17770
17771 \end_inset 
17772
17773
17774 \begin_inset LatexCommand \index{DS400}
17775
17776 \end_inset 
17777
17778  microcontroller has a rich set of peripherals.
17779  In its built-in ROM library it includes functions to access some of the
17780  features, among them is a TCP stack with IP4 and IP6 support.
17781  Library headers (currently in beta status) and other files are provided
17782  at 
17783 \size footnotesize 
17784
17785 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
17786
17787 \end_inset 
17788
17789 .
17790  
17791 \layout Section
17792
17793 The Z80 and gbz80 port
17794 \layout Standard
17795
17796 SDCC can target both the Zilog Z80
17797 \begin_inset LatexCommand \index{Z80}
17798
17799 \end_inset 
17800
17801  and the Nintendo Gameboy's Z80-like gbz80
17802 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17803
17804 \end_inset 
17805
17806 .
17807  The Z80 port is passed through the same 
17808 \emph on 
17809 regressions tests
17810 \begin_inset LatexCommand \index{Regression test}
17811
17812 \end_inset 
17813
17814
17815 \emph default 
17816  (see section 
17817 \begin_inset LatexCommand \ref{sec:Quality-control}
17818
17819 \end_inset 
17820
17821 ) as the MCS51 and DS390 ports, so floating point support, support for long
17822  variables and bitfield support is fine.
17823  See mailing lists and forums about interrupt routines.
17824 \layout Standard
17825 \added_space_bottom bigskip 
17826 As always, the code is the authoritative reference - see z80/ralloc.c and
17827  z80/gen.c.
17828  The stack
17829 \begin_inset LatexCommand \index{Z80!stack}
17830
17831 \end_inset 
17832
17833  frame is similar to that generated by the IAR Z80 compiler.
17834  IX is used as the base pointer, HL and IY are used as a temporary registers,
17835  and BC and DE are available for holding variables.
17836  Return values
17837 \begin_inset LatexCommand \index{Z80!return value}
17838
17839 \end_inset 
17840
17841  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
17842  bytes).
17843  The gbz80 port use the same set of registers for the return values, but
17844  in a different order of significance: E (one byte), DE (two bytes), or
17845  HLDE (four bytes).
17846 \layout Section
17847
17848 The HC08 port
17849 \layout Standard
17850
17851 The port to the Freescale/Motorola HC08
17852 \begin_inset LatexCommand \index{HC08}
17853
17854 \end_inset 
17855
17856  family has been added in October 2003, and is still undergoing some basic
17857  development.
17858  The code generator is complete, but the register allocation is still quite
17859  unoptimized.
17860  Some of the SDCC's standard C library functions have embedded non-HC08
17861  inline assembly and so are not yet usable.
17862 \layout Standard
17863 \added_space_bottom bigskip 
17864 The HC08 port passes the regression test suite (see section 
17865 \begin_inset LatexCommand \ref{sec:Quality-control}
17866
17867 \end_inset 
17868
17869 ).
17870 \layout Section
17871 \pagebreak_top 
17872 The PIC14 port
17873 \layout Standard
17874
17875 The 14bit PIC
17876 \begin_inset LatexCommand \index{PIC14}
17877
17878 \end_inset 
17879
17880  port still requires a major effort from the development community.
17881  However it can work for simple code.
17882  It passes its (smaller set of) regression tests
17883 \begin_inset LatexCommand \index{Regression test (PIC14)}
17884
17885 \end_inset 
17886
17887  in the directory 
17888 \shape italic 
17889 sdcc/src/regression
17890 \shape default 
17891 .
17892 \layout Subsection
17893
17894 C code and 14bit PIC code page
17895 \begin_inset LatexCommand \index{code page (pic14)}
17896
17897 \end_inset 
17898
17899  and RAM banks
17900 \begin_inset LatexCommand \index{RAM bank (pic14)}
17901
17902 \end_inset 
17903
17904
17905 \layout Standard
17906
17907 The linker organizes allocation for the code page and RAM banks.
17908  It does not have intimate knowledge of the code flow.
17909  It will put all the code section of a single asm file into a single code
17910  page.
17911  In order to make use of multiple code pages, separate asm files must be
17912  used.
17913  The compiler treats all functions of a single C file as being in the same
17914  code page unless it is non static.
17915 \newline 
17916
17917 \newline 
17918 To get the best follow these guide lines:
17919 \layout Enumerate
17920
17921 Make local functions static, as non static functions require code page selection
17922  overhead.
17923 \layout Enumerate
17924
17925 For devices that have multiple code pages it is more efficient to use the
17926  same number of files as pages, i.e.
17927  for the 16F877 use 4 separate files and i.e.
17928  for the 16F874 use 2 separate files.
17929  This way the linker can put the code for each file into different code
17930  pages and there's less page selection overhead.
17931 \layout Enumerate
17932
17933  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17934  instruction set), use 'unsigned char' whereever possible instead of 'int'.
17935 \layout Subsection
17936
17937 Creating a device include file 
17938 \layout Standard
17939
17940 For generating a device include file
17941 \begin_inset LatexCommand \index{PIC14!Header files}
17942
17943 \end_inset 
17944
17945  use the support perl script inc2h.pl kept in directory support/script.
17946 \layout Subsection
17947
17948 Interrupt code
17949 \layout Standard
17950
17951 For the interrupt function, use the keyword '__interrupt'
17952 \begin_inset LatexCommand \index{PIC14!interrupt}
17953
17954 \end_inset 
17955
17956  with level number of 0 (PIC14 only has 1 interrupt so this number is only
17957  there to avoid a syntax error - it ought to be fixed).
17958  E.g.:
17959 \layout Verse
17960
17961
17962 \family typewriter 
17963 void Intr(void) __interrupt 0
17964 \newline 
17965 {
17966 \newline 
17967 \SpecialChar ~
17968 \SpecialChar ~
17969 T0IF = 0; /* Clear timer interrupt */
17970 \newline 
17971 }
17972 \layout Subsection
17973
17974 Linking and assembling
17975 \layout Standard
17976
17977 For assembling you can use either GPUTILS'
17978 \begin_inset LatexCommand \index{gputils (pic tools)}
17979
17980 \end_inset 
17981
17982  gpasm.exe or MPLAB's mpasmwin.exe.
17983  GPUTILS is available from 
17984 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17985
17986 \end_inset 
17987
17988 .
17989  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17990  If you use MPLAB and an interrupt function then the linker script file
17991  vectors section will need to be enlarged to link with mplink.
17992 \newline 
17993
17994 \newline 
17995 Here is a 
17996 \family typewriter 
17997 Makefile
17998 \family default 
17999  using GPUTILS:
18000 \layout Verse
18001
18002
18003 \family typewriter 
18004 .c.o:
18005 \newline 
18006 \SpecialChar ~
18007 \SpecialChar ~
18008 \SpecialChar ~
18009 \SpecialChar ~
18010 \SpecialChar ~
18011 \SpecialChar ~
18012 \SpecialChar ~
18013 \SpecialChar ~
18014 sdcc -S -V -mpic14 -p16F877 $< 
18015 \newline 
18016 \SpecialChar ~
18017 \SpecialChar ~
18018 \SpecialChar ~
18019 \SpecialChar ~
18020 \SpecialChar ~
18021 \SpecialChar ~
18022 \SpecialChar ~
18023 \SpecialChar ~
18024 gpasm -c $*.asm
18025 \newline 
18026
18027 \newline 
18028 $(PRJ).hex: $(OBJS) 
18029 \newline 
18030 \SpecialChar ~
18031 \SpecialChar ~
18032 \SpecialChar ~
18033 \SpecialChar ~
18034 \SpecialChar ~
18035 \SpecialChar ~
18036 \SpecialChar ~
18037 \SpecialChar ~
18038 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
18039 \layout Standard
18040
18041 Here is a 
18042 \family typewriter 
18043 Makefile
18044 \family default 
18045  using MPLAB:
18046 \layout Verse
18047
18048
18049 \family typewriter 
18050 .c.o: 
18051 \newline 
18052 \SpecialChar ~
18053 \SpecialChar ~
18054 \SpecialChar ~
18055 \SpecialChar ~
18056 \SpecialChar ~
18057 \SpecialChar ~
18058 \SpecialChar ~
18059 \SpecialChar ~
18060 sdcc -S -V -mpic14 -p16F877 $< 
18061 \newline 
18062 \SpecialChar ~
18063 \SpecialChar ~
18064 \SpecialChar ~
18065 \SpecialChar ~
18066 \SpecialChar ~
18067 \SpecialChar ~
18068 \SpecialChar ~
18069 \SpecialChar ~
18070 mpasmwin /q /o $*.asm
18071 \newline 
18072
18073 \newline 
18074 $(PRJ).hex: $(OBJS) 
18075 \newline 
18076 \SpecialChar ~
18077 \SpecialChar ~
18078 \SpecialChar ~
18079 \SpecialChar ~
18080 \SpecialChar ~
18081 \SpecialChar ~
18082 \SpecialChar ~
18083 \SpecialChar ~
18084 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
18085 \layout Standard
18086
18087 Please note that indentations within a
18088 \family typewriter 
18089  Makefile
18090 \family default 
18091  have to be done with a tabulator character.
18092 \layout Subsection
18093
18094 Command-line options
18095 \layout Standard
18096
18097 Besides the switches common to all SDCC backends, the PIC14 port accepts
18098  the following options (for an updated list see sdcc -
18099 \begin_inset ERT
18100 status Collapsed
18101
18102 \layout Standard
18103
18104 \backslash 
18105 /
18106 \end_inset 
18107
18108 -help):
18109 \layout List
18110 \labelwidthstring 00.00.0000
18111
18112 -
18113 \begin_inset ERT
18114 status Collapsed
18115
18116 \layout Standard
18117
18118 \backslash 
18119 /
18120 \end_inset 
18121
18122 -debug-extra
18123 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
18124
18125 \end_inset 
18126
18127  emit debug info in assembly output
18128 \layout List
18129 \labelwidthstring 00.00.0000
18130
18131 -
18132 \begin_inset ERT
18133 status Collapsed
18134
18135 \layout Standard
18136
18137 \backslash 
18138 /
18139 \end_inset 
18140
18141 -no-pcode-opt
18142 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
18143
18144 \end_inset 
18145
18146  disable (slightly faulty) optimization on pCode
18147 \layout List
18148 \labelwidthstring 00.00.0000
18149
18150 -
18151 \begin_inset ERT
18152 status Collapsed
18153
18154 \layout Standard
18155
18156 \backslash 
18157 /
18158 \end_inset 
18159
18160 -stack-loc
18161 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
18162
18163 \end_inset 
18164
18165  sets the lowest address of the argument passing stack (defaults to a suitably
18166  large shared databank to reduce BANKSEL overhead)
18167 \layout List
18168 \labelwidthstring 00.00.0000
18169
18170 -
18171 \begin_inset ERT
18172 status Collapsed
18173
18174 \layout Standard
18175
18176 \backslash 
18177 /
18178 \end_inset 
18179
18180 -stack-size
18181 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
18182
18183 \end_inset 
18184
18185  sets the size if the argument passing stack (default: 16, minimum: 4)
18186 \layout Subsection
18187
18188 The library
18189 \layout Subsubsection
18190
18191 error: missing definition for symbol 
18192 \begin_inset Quotes sld
18193 \end_inset 
18194
18195 __gptrget1
18196 \begin_inset Quotes srd
18197 \end_inset 
18198
18199
18200 \layout Standard
18201
18202 The PIC14 port uses library routines to provide more complex operations
18203  like multiplication, division/modulus and (generic) pointer dereferencing.
18204  In order to add these routines to your project, you must link with PIC14's
18205  
18206 \family typewriter 
18207 libsdcc.lib
18208 \family default 
18209 .
18210  For single source file projects this is done automatically, more complex
18211  projects must add 
18212 \family typewriter 
18213 libsdcc.lib
18214 \family default 
18215  to the linker's arguments.
18216  Make sure you also add an include path for the library (using the -I switch
18217  to the linker)!
18218 \layout Subsubsection
18219
18220 Processor mismatch in file 
18221 \begin_inset Quotes sld
18222 \end_inset 
18223
18224 XXX
18225 \begin_inset Quotes srd
18226 \end_inset 
18227
18228 .
18229 \layout Standard
18230
18231 This warning can usually be ignored due to the very good compatibility amongst
18232  14 bit PIC
18233 \begin_inset LatexCommand \index{PIC14}
18234
18235 \end_inset 
18236
18237  devices.
18238 \layout Standard
18239
18240 You might also consider recompiling the library for your specific device
18241  by changing the ARCH=p16f877 (default target) entry in 
18242 \family typewriter 
18243 device/lib/pic/Makefile.in
18244 \family default 
18245  and 
18246 \family typewriter 
18247 device/lib/pic/Makefile
18248 \family default 
18249  to reflect your device.
18250  This might even improve performance for smaller devices as unneccesary
18251  BANKSELs migth be removed.
18252 \layout Subsection
18253
18254 Known bugs
18255 \layout Subsubsection
18256
18257 initialized data
18258 \layout Standard
18259
18260 Currently, data can only be initialized if it resides in the source file
18261  together with 
18262 \emph on 
18263 main()
18264 \emph default 
18265 .
18266  Data in other source files will silently 
18267 \series bold 
18268 not
18269 \series default 
18270  be initialized.
18271 \family typewriter 
18272 \size footnotesize 
18273
18274 \begin_inset Marginal
18275 collapsed true
18276
18277 \layout Standard
18278
18279
18280 \series bold 
18281 \SpecialChar ~
18282 !
18283 \end_inset 
18284
18285
18286 \layout Section
18287 \pagebreak_top 
18288 The PIC16
18289 \begin_inset LatexCommand \index{PIC16}
18290
18291 \end_inset 
18292
18293  port
18294 \layout Standard
18295
18296 The PIC16
18297 \begin_inset LatexCommand \index{PIC16}
18298
18299 \end_inset 
18300
18301  port is the portion of SDCC that is responsible to produce code for the
18302  Microchip
18303 \begin_inset LatexCommand \index{Microchip}
18304
18305 \end_inset 
18306
18307 (TM) microcontrollers with 16 bit core.
18308  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
18309  Currently supported devices are:
18310 \layout Standard
18311 \align center 
18312
18313 \begin_inset  Tabular
18314 <lyxtabular version="3" rows="4" columns="6">
18315 <features>
18316 <column alignment="center" valignment="top" leftline="true" width="0">
18317 <column alignment="center" valignment="top" leftline="true" width="0">
18318 <column alignment="center" valignment="top" leftline="true" width="0">
18319 <column alignment="center" valignment="top" leftline="true" width="0">
18320 <column alignment="center" valignment="top" leftline="true" width="0">
18321 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18322 <row topline="true">
18323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18324 \begin_inset Text
18325
18326 \layout Standard
18327
18328 18F242
18329 \end_inset 
18330 </cell>
18331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18332 \begin_inset Text
18333
18334 \layout Standard
18335
18336 18F248
18337 \end_inset 
18338 </cell>
18339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18340 \begin_inset Text
18341
18342 \layout Standard
18343
18344 18F252
18345 \end_inset 
18346 </cell>
18347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18348 \begin_inset Text
18349
18350 \layout Standard
18351
18352 18F258
18353 \end_inset 
18354 </cell>
18355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18356 \begin_inset Text
18357
18358 \layout Standard
18359
18360 18F442
18361 \end_inset 
18362 </cell>
18363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18364 \begin_inset Text
18365
18366 \layout Standard
18367
18368 18F448
18369 \end_inset 
18370 </cell>
18371 </row>
18372 <row topline="true">
18373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18374 \begin_inset Text
18375
18376 \layout Standard
18377
18378 18F452
18379 \end_inset 
18380 </cell>
18381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18382 \begin_inset Text
18383
18384 \layout Standard
18385
18386 18F458
18387 \end_inset 
18388 </cell>
18389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18390 \begin_inset Text
18391
18392 \layout Standard
18393
18394 18F1220
18395 \end_inset 
18396 </cell>
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18398 \begin_inset Text
18399
18400 \layout Standard
18401
18402 18F2220
18403 \end_inset 
18404 </cell>
18405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18406 \begin_inset Text
18407
18408 \layout Standard
18409
18410 18F2550
18411 \end_inset 
18412 </cell>
18413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18414 \begin_inset Text
18415
18416 \layout Standard
18417
18418 18F4331
18419 \end_inset 
18420 </cell>
18421 </row>
18422 <row topline="true">
18423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18424 \begin_inset Text
18425
18426 \layout Standard
18427
18428 18F4455
18429 \end_inset 
18430 </cell>
18431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18432 \begin_inset Text
18433
18434 \layout Standard
18435
18436 18F6520
18437 \end_inset 
18438 </cell>
18439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18440 \begin_inset Text
18441
18442 \layout Standard
18443
18444 18F6620
18445 \end_inset 
18446 </cell>
18447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18448 \begin_inset Text
18449
18450 \layout Standard
18451
18452 18F6680
18453 \end_inset 
18454 </cell>
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18456 \begin_inset Text
18457
18458 \layout Standard
18459
18460 18F6720
18461 \end_inset 
18462 </cell>
18463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18464 \begin_inset Text
18465
18466 \layout Standard
18467
18468 18F8520
18469 \end_inset 
18470 </cell>
18471 </row>
18472 <row topline="true" bottomline="true">
18473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18474 \begin_inset Text
18475
18476 \layout Standard
18477
18478 18F8620
18479 \end_inset 
18480 </cell>
18481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18482 \begin_inset Text
18483
18484 \layout Standard
18485
18486 18F8680
18487 \end_inset 
18488 </cell>
18489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18490 \begin_inset Text
18491
18492 \layout Standard
18493
18494 18F8720
18495 \end_inset 
18496 </cell>
18497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18498 \begin_inset Text
18499
18500 \layout Standard
18501
18502 \end_inset 
18503 </cell>
18504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18505 \begin_inset Text
18506
18507 \layout Standard
18508
18509 \end_inset 
18510 </cell>
18511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18512 \begin_inset Text
18513
18514 \layout Standard
18515
18516 \end_inset 
18517 </cell>
18518 </row>
18519 </lyxtabular>
18520
18521 \end_inset 
18522
18523
18524 \layout Subsection
18525
18526 Global Options
18527 \layout Standard
18528
18529 PIC16 port supports the standard command line arguments as supposed, with
18530  the exception of certain cases that will be mentioned in the following
18531  list:
18532 \layout List
18533 \labelwidthstring 00.00.0000
18534
18535 -
18536 \begin_inset ERT
18537 status Collapsed
18538
18539 \layout Standard
18540
18541 \backslash 
18542 /
18543 \end_inset 
18544
18545 -callee-saves
18546 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
18547
18548 \end_inset 
18549
18550  See -
18551 \begin_inset ERT
18552 status Collapsed
18553
18554 \layout Standard
18555
18556 \backslash 
18557 /
18558 \end_inset 
18559
18560 -all-callee-saves
18561 \layout List
18562 \labelwidthstring 00.00.0000
18563
18564 -
18565 \begin_inset ERT
18566 status Collapsed
18567
18568 \layout Standard
18569
18570 \backslash 
18571 /
18572 \end_inset 
18573
18574 -all-callee-saves
18575 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
18576
18577 \end_inset 
18578
18579  All function arguments are passed on stack by default.
18580  
18581 \emph on 
18582 There is no need to specify this in the command line.
18583 \layout List
18584 \labelwidthstring 00.00.0000
18585
18586 -
18587 \begin_inset ERT
18588 status Collapsed
18589
18590 \layout Standard
18591
18592 \backslash 
18593 /
18594 \end_inset 
18595
18596 -fommit-frame-pointer
18597 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
18598
18599 \end_inset 
18600
18601  Frame pointer will be omitted when the function uses no local variables.
18602 \layout Subsection
18603
18604 Port Specific Options
18605 \begin_inset LatexCommand \index{Options PIC16}
18606
18607 \end_inset 
18608
18609
18610 \layout Standard
18611
18612 The port specific options appear after the global options in the sdcc --help
18613  output.
18614 \layout Subsubsection
18615
18616 General Options
18617 \layout Standard
18618
18619 General options enable certain port features and optimizations.
18620 \layout List
18621 \labelwidthstring 00.00.0000
18622
18623 -
18624 \begin_inset ERT
18625 status Collapsed
18626
18627 \layout Standard
18628
18629 \backslash 
18630 /
18631 \end_inset 
18632
18633 -pstack-model=[model] Used in conjuction with the command above.
18634  Defines the stack model to be used, valid stack models are : 
18635 \begin_deeper 
18636 \layout List
18637 \labelwidthstring 00.00.0000
18638
18639
18640 \emph on 
18641 small
18642 \emph default 
18643  Selects small stack model.
18644  8 bit stack and frame pointers.
18645  Supports 256 bytes stack size.
18646 \layout List
18647 \labelwidthstring 00.00.0000
18648
18649
18650 \emph on 
18651 large
18652 \emph default 
18653  Selects large stack model.
18654  16 bit stack and frame pointers.
18655  Supports 65536 bytes stack size.
18656 \end_deeper 
18657 \layout List
18658 \labelwidthstring 00.00.0000
18659
18660 -
18661 \begin_inset ERT
18662 status Collapsed
18663
18664 \layout Standard
18665
18666 \backslash 
18667 /
18668 \end_inset 
18669
18670 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
18671  unitialized data variables with [kword].
18672  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
18673 \layout List
18674 \labelwidthstring 00.00.0000
18675
18676 -
18677 \begin_inset ERT
18678 status Collapsed
18679
18680 \layout Standard
18681
18682 \backslash 
18683 /
18684 \end_inset 
18685
18686 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
18687  Useful for bootloaders.
18688 \layout List
18689 \labelwidthstring 00.00.0000
18690
18691 -
18692 \begin_inset ERT
18693 status Collapsed
18694
18695 \layout Standard
18696
18697 \backslash 
18698 /
18699 \end_inset 
18700
18701 -asm= sets the full path and name of an external assembler to call.
18702 \layout List
18703 \labelwidthstring 00.00.0000
18704
18705 -
18706 \begin_inset ERT
18707 status Collapsed
18708
18709 \layout Standard
18710
18711 \backslash 
18712 /
18713 \end_inset 
18714
18715 -link= sets the full path and name of an external linker to call.
18716 \layout List
18717 \labelwidthstring 00.00.0000
18718
18719 -
18720 \begin_inset ERT
18721 status Collapsed
18722
18723 \layout Standard
18724
18725 \backslash 
18726 /
18727 \end_inset 
18728
18729 -mplab-comp MPLAB
18730 \begin_inset LatexCommand \index{PIC16!MPLAB}
18731
18732 \end_inset 
18733
18734  compatibility option.
18735  Currently only suppresses special gpasm directives.
18736 \layout Subsubsection
18737
18738 Optimization Options
18739 \layout List
18740 \labelwidthstring 00.00.0000
18741
18742 -
18743 \begin_inset ERT
18744 status Collapsed
18745
18746 \layout Standard
18747
18748 \backslash 
18749 /
18750 \end_inset 
18751
18752 -optimize-goto Try to use (conditional) BRA instead of GOTO
18753 \layout List
18754 \labelwidthstring 00.00.0000
18755
18756 -
18757 \begin_inset ERT
18758 status Collapsed
18759
18760 \layout Standard
18761
18762 \backslash 
18763 /
18764 \end_inset 
18765
18766 -optimize-cmp Try to optimize some compares.
18767 \layout List
18768 \labelwidthstring 00.00.0000
18769
18770 -
18771 \begin_inset ERT
18772 status Collapsed
18773
18774 \layout Standard
18775
18776 \backslash 
18777 /
18778 \end_inset 
18779
18780 -optimize-df Analyze the dataflow of the generated code and improve it.
18781 \layout List
18782 \labelwidthstring 00.00.0000
18783
18784 -
18785 \begin_inset ERT
18786 status Collapsed
18787
18788 \layout Standard
18789
18790 \backslash 
18791 /
18792 \end_inset 
18793
18794 -obanksel=nn Set optimization level for inserting BANKSELs.
18795 \newline 
18796
18797 \begin_deeper 
18798 \layout List
18799 \labelwidthstring 00.00.0000
18800
18801 0 no optimization
18802 \layout List
18803 \labelwidthstring 00.00.0000
18804
18805 1 checks previous used register and if it is the same then does not emit
18806  BANKSEL, accounts only for labels.
18807 \layout List
18808 \labelwidthstring 00.00.0000
18809
18810 2 tries to check the location of (even different) symbols and removes BANKSELs
18811  if they are in the same bank.
18812  
18813 \newline 
18814
18815 \emph on 
18816 Important: There might be problems if the linker script has data sections
18817  across bank borders!
18818 \end_deeper 
18819 \layout Subsubsection
18820
18821 Linking Options
18822 \layout List
18823 \labelwidthstring 00.00.0000
18824
18825 -
18826 \begin_inset ERT
18827 status Collapsed
18828
18829 \layout Standard
18830
18831 \backslash 
18832 /
18833 \end_inset 
18834
18835 -nodefaultlibs do not link default libraries when linking
18836 \layout List
18837 \labelwidthstring 00.00.0000
18838
18839 -
18840 \begin_inset ERT
18841 status Collapsed
18842
18843 \layout Standard
18844
18845 \backslash 
18846 /
18847 \end_inset 
18848
18849 -no-crt Don't link the default run-time modules
18850 \layout List
18851 \labelwidthstring 00.00.0000
18852
18853 -
18854 \begin_inset ERT
18855 status Collapsed
18856
18857 \layout Standard
18858
18859 \backslash 
18860 /
18861 \end_inset 
18862
18863 -use-crt= Use a custom run-time module instead of the defaults.
18864 \layout Subsubsection
18865
18866 Debugging Options
18867 \layout Standard
18868
18869 Debugging options enable extra debugging information in the output files.
18870 \layout List
18871 \labelwidthstring 00.00.0000
18872
18873 -
18874 \begin_inset ERT
18875 status Collapsed
18876
18877 \layout Standard
18878
18879 \backslash 
18880 /
18881 \end_inset 
18882
18883 -debug-xtra Similar to -
18884 \begin_inset ERT
18885 status Collapsed
18886
18887 \layout Standard
18888
18889 \backslash 
18890 /
18891 \end_inset 
18892
18893 -debug
18894 \begin_inset LatexCommand \index{-\/-debug}
18895
18896 \end_inset 
18897
18898 , but dumps more information.
18899 \layout List
18900 \labelwidthstring 00.00.0000
18901
18902 -
18903 \begin_inset ERT
18904 status Collapsed
18905
18906 \layout Standard
18907
18908 \backslash 
18909 /
18910 \end_inset 
18911
18912 -debug-ralloc Force register allocator to dump <source>.d file with debugging
18913  information.
18914  <source> is the name of the file compiled.
18915 \layout List
18916 \labelwidthstring 00.00.0000
18917
18918 -
18919 \begin_inset ERT
18920 status Collapsed
18921
18922 \layout Standard
18923
18924 \backslash 
18925 /
18926 \end_inset 
18927
18928 -pcode-verbose Enable pcode debugging information in translation.
18929 \layout List
18930 \labelwidthstring 00.00.0000
18931
18932 -
18933 \begin_inset ERT
18934 status Collapsed
18935
18936 \layout Standard
18937
18938 \backslash 
18939 /
18940 \end_inset 
18941
18942 -denable-peeps Force the usage of peepholes.
18943  Use with care.
18944 \layout List
18945 \labelwidthstring 00.00.0000
18946
18947 -
18948 \begin_inset ERT
18949 status Collapsed
18950
18951 \layout Standard
18952
18953 \backslash 
18954 /
18955 \end_inset 
18956
18957 -gstack Trace push/pops for stack pointer overflow
18958 \layout List
18959 \labelwidthstring 00.00.0000
18960
18961 -
18962 \begin_inset ERT
18963 status Collapsed
18964
18965 \layout Standard
18966
18967 \backslash 
18968 /
18969 \end_inset 
18970
18971 -call-tree dump call tree in .calltree file
18972 \layout Subsection
18973
18974 Enviromental Variables
18975 \layout Standard
18976
18977 There is a number of enviromental variables that can be used when running
18978  SDCC to enable certain optimizations or force a specific program behaviour.
18979  these variables are primarily for debugging purposes so they can be enabled/dis
18980 abled at will.
18981 \layout Standard
18982
18983 Currently there is only two such variables available:
18984 \layout List
18985 \labelwidthstring 00.00.0000
18986
18987 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18988  bitfields is optimized by directly loading FSR0 with the address of the
18989  bitfield structure.
18990  Normally SDCC will cast the bitfield structure to a bitfield pointer and
18991  then load FSR0.
18992  This step saves data ram and code space for functions that perform heavy
18993  use of bitfields.
18994  (ie.
18995  80 bytes of code space are saved when compiling malloc.c with this option).
18996  
18997 \layout List
18998 \labelwidthstring 00.00.0000
18999
19000 NO_REG_OPT do not perform pCode registers optimization.
19001  This should be used for debugging purposes.
19002  In some where bugs in the pcode optimizer are found, users can benefit
19003  from temporarily disabling the optimizer until the bug is fixed.
19004 \layout Subsection
19005
19006 Preprocessor Macros
19007 \layout Standard
19008
19009 PIC16
19010 \begin_inset LatexCommand \index{PIC16}
19011
19012 \end_inset 
19013
19014  port defines the following preprocessor macros while translating a source.
19015 \layout Standard
19016 \align center 
19017
19018 \begin_inset  Tabular
19019 <lyxtabular version="3" rows="6" columns="2">
19020 <features>
19021 <column alignment="center" valignment="top" leftline="true" width="0">
19022 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19023 <row topline="true" bottomline="true">
19024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19025 \begin_inset Text
19026
19027 \layout Standard
19028
19029 Macro
19030 \end_inset 
19031 </cell>
19032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19033 \begin_inset Text
19034
19035 \layout Standard
19036
19037 Description
19038 \end_inset 
19039 </cell>
19040 </row>
19041 <row topline="true">
19042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19043 \begin_inset Text
19044
19045 \layout Standard
19046
19047 SDCC_pic16
19048 \end_inset 
19049 </cell>
19050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19051 \begin_inset Text
19052
19053 \layout Standard
19054
19055 Port identification
19056 \end_inset 
19057 </cell>
19058 </row>
19059 <row topline="true">
19060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19061 \begin_inset Text
19062
19063 \layout Standard
19064
19065 _
19066 \begin_inset ERT
19067 status Collapsed
19068
19069 \layout Standard
19070
19071 \backslash 
19072 /
19073 \end_inset 
19074
19075 _pic16
19076 \end_inset 
19077 </cell>
19078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19079 \begin_inset Text
19080
19081 \layout Standard
19082
19083 Port identification (same as above)
19084 \end_inset 
19085 </cell>
19086 </row>
19087 <row topline="true">
19088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19089 \begin_inset Text
19090
19091 \layout Standard
19092
19093 pic18fxxxx
19094 \end_inset 
19095 </cell>
19096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19097 \begin_inset Text
19098
19099 \layout Standard
19100
19101 MCU Identification.
19102  
19103 \emph on 
19104 xxxx
19105 \emph default 
19106  is the microcontrol identification number, i.e.
19107  452, 6620, etc
19108 \end_inset 
19109 </cell>
19110 </row>
19111 <row topline="true">
19112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19113 \begin_inset Text
19114
19115 \layout Standard
19116
19117 _
19118 \begin_inset ERT
19119 status Collapsed
19120
19121 \layout Standard
19122
19123 \backslash 
19124 /
19125 \end_inset 
19126
19127 _18Fxxxx
19128 \end_inset 
19129 </cell>
19130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19131 \begin_inset Text
19132
19133 \layout Standard
19134
19135 MCU Identification (same as above)
19136 \end_inset 
19137 </cell>
19138 </row>
19139 <row topline="true" bottomline="true">
19140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19141 \begin_inset Text
19142
19143 \layout Standard
19144
19145 STACK_MODEL_nnn
19146 \end_inset 
19147 </cell>
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19149 \begin_inset Text
19150
19151 \layout Standard
19152
19153 nnn = SMALL or LARGE respectively according to the stack model used
19154 \end_inset 
19155 </cell>
19156 </row>
19157 </lyxtabular>
19158
19159 \end_inset 
19160
19161
19162 \layout Standard
19163
19164 In addition the following macros are defined when calling assembler:
19165 \layout Standard
19166 \align center 
19167
19168 \begin_inset  Tabular
19169 <lyxtabular version="3" rows="4" columns="2">
19170 <features>
19171 <column alignment="center" valignment="top" leftline="true" width="0">
19172 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19173 <row topline="true" bottomline="true">
19174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19175 \begin_inset Text
19176
19177 \layout Standard
19178
19179 Macro
19180 \end_inset 
19181 </cell>
19182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19183 \begin_inset Text
19184
19185 \layout Standard
19186
19187 Description
19188 \end_inset 
19189 </cell>
19190 </row>
19191 <row topline="true">
19192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19193 \begin_inset Text
19194
19195 \layout Standard
19196
19197 __18Fxxxx
19198 \end_inset 
19199 </cell>
19200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19201 \begin_inset Text
19202
19203 \layout Standard
19204
19205 MCU Identification.
19206  
19207 \emph on 
19208 xxxx
19209 \emph default 
19210  is the microcontrol identification number, i.e.
19211  452, 6620, etc
19212 \end_inset 
19213 </cell>
19214 </row>
19215 <row topline="true">
19216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19217 \begin_inset Text
19218
19219 \layout Standard
19220
19221 SDCC_MODEL_nnn
19222 \end_inset 
19223 </cell>
19224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19225 \begin_inset Text
19226
19227 \layout Standard
19228
19229 nnn = SMALL or LARGE respectively according to the memory model used for
19230  SDCC
19231 \end_inset 
19232 </cell>
19233 </row>
19234 <row topline="true" bottomline="true">
19235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19236 \begin_inset Text
19237
19238 \layout Standard
19239
19240 STACK_MODEL_nnn
19241 \end_inset 
19242 </cell>
19243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19244 \begin_inset Text
19245
19246 \layout Standard
19247
19248 nnn = SMALL or LARGE respectively according to the stack model used
19249 \end_inset 
19250 </cell>
19251 </row>
19252 </lyxtabular>
19253
19254 \end_inset 
19255
19256
19257 \layout Subsection
19258
19259 Directories
19260 \layout Standard
19261
19262 PIC16
19263 \begin_inset LatexCommand \index{PIC16}
19264
19265 \end_inset 
19266
19267  port uses the following directories for searching header files and libraries.
19268 \layout Standard
19269 \align center 
19270
19271 \begin_inset  Tabular
19272 <lyxtabular version="3" rows="3" columns="4">
19273 <features>
19274 <column alignment="center" valignment="top" leftline="true" width="0">
19275 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19276 <column alignment="center" valignment="top" width="0">
19277 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19278 <row topline="true" bottomline="true">
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19280 \begin_inset Text
19281
19282 \layout Standard
19283
19284 Directory
19285 \end_inset 
19286 </cell>
19287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19288 \begin_inset Text
19289
19290 \layout Standard
19291
19292 Description
19293 \end_inset 
19294 </cell>
19295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19296 \begin_inset Text
19297
19298 \layout Standard
19299
19300 Target
19301 \end_inset 
19302 </cell>
19303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19304 \begin_inset Text
19305
19306 \layout Standard
19307
19308 Command prefix
19309 \end_inset 
19310 </cell>
19311 </row>
19312 <row topline="true">
19313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19314 \begin_inset Text
19315
19316 \layout Standard
19317
19318 PREFIX/sdcc/include/pic16
19319 \end_inset 
19320 </cell>
19321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19322 \begin_inset Text
19323
19324 \layout Standard
19325
19326 PIC16 specific headers
19327 \end_inset 
19328 </cell>
19329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19330 \begin_inset Text
19331
19332 \layout Standard
19333
19334 Compiler
19335 \end_inset 
19336 </cell>
19337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19338 \begin_inset Text
19339
19340 \layout Standard
19341
19342 -I
19343 \end_inset 
19344 </cell>
19345 </row>
19346 <row topline="true" bottomline="true">
19347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19348 \begin_inset Text
19349
19350 \layout Standard
19351
19352 PREFIX/sdcc/lib/pic16
19353 \end_inset 
19354 </cell>
19355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19356 \begin_inset Text
19357
19358 \layout Standard
19359
19360 PIC16 specific libraries
19361 \end_inset 
19362 </cell>
19363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19364 \begin_inset Text
19365
19366 \layout Standard
19367
19368 Linker
19369 \end_inset 
19370 </cell>
19371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19372 \begin_inset Text
19373
19374 \layout Standard
19375
19376 -L
19377 \end_inset 
19378 </cell>
19379 </row>
19380 </lyxtabular>
19381
19382 \end_inset 
19383
19384
19385 \layout Subsection
19386
19387 Pragmas
19388 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
19389
19390 \end_inset 
19391
19392
19393 \layout Standard
19394
19395 PIC16
19396 \begin_inset LatexCommand \index{PIC16}
19397
19398 \end_inset 
19399
19400  port currently supports the following pragmas:
19401 \layout List
19402 \labelwidthstring 00.00.0000
19403
19404 stack
19405 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
19406
19407 \end_inset 
19408
19409  pragma stack
19410 \begin_inset LatexCommand \index{PIC16!stack}
19411
19412 \end_inset 
19413
19414  forces the code generator to initialize the stack & frame pointers at a
19415  specific address.
19416  This is an adhoc solution for cases where no STACK directive is available
19417  in the linker script or gplink is not instructed to create a stack section.
19418 \newline 
19419 The stack pragma should be used only once in a project.
19420  Multiple pragmas may result in indeterminate behaviour of the program.
19421 \begin_inset Foot
19422 collapsed false
19423
19424 \layout Standard
19425
19426 The old format (ie.
19427  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
19428  cross page boundaries (or even exceed the available data RAM) and crash
19429  the program.
19430  Make sure that stack does not cross page boundaries when using the SMALL
19431  stack model.
19432 \end_inset 
19433
19434
19435 \newline 
19436 The format is as follows:
19437 \layout LyX-Code
19438
19439 #pragma stack bottom_address [stack_size]
19440 \layout Standard
19441
19442
19443 \emph on 
19444 bottom_address
19445 \emph default 
19446  is the lower bound of the stack section.
19447  The stack pointer initially will point at address (bottom_address+stack_size-1).
19448 \layout LyX-Code
19449
19450 Example:
19451 \layout LyX-Code
19452
19453 \layout LyX-Code
19454
19455 /* initializes stack of 100 bytes at RAM address 0x200 */
19456 \layout LyX-Code
19457
19458 #pragma stack 0x200 100
19459 \layout Standard
19460
19461 If the stack_size field is omitted then a stack is created with the default
19462  size of 64.
19463  This size might be enough for most programs, but its not enough for operations
19464  with deep function nesting or excessive stack usage.
19465 \layout List
19466 \labelwidthstring 00.00.0000
19467
19468 code
19469 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
19470
19471 \end_inset 
19472
19473  place a function symbol at static FLASH address
19474 \layout LyX-Code
19475
19476 Example:
19477 \layout LyX-Code
19478
19479 \layout LyX-Code
19480
19481 /* place function test_func at 0x4000 */
19482 \layout LyX-Code
19483
19484 #pragma code test_func 0x4000
19485 \layout LyX-Code
19486
19487 \layout List
19488 \labelwidthstring 00.00.0000
19489
19490 library instructs the linker to use a library module.
19491 \newline 
19492 Usage:
19493 \layout LyX-Code
19494
19495 #pragma library module_name
19496 \layout Standard
19497
19498
19499 \emph on 
19500 module_name
19501 \emph default 
19502  can be any library or object file (including its path).
19503  Note that there are four reserved keywords which have special meaning.
19504  These are:
19505 \layout Standard
19506 \align center 
19507
19508 \begin_inset  Tabular
19509 <lyxtabular version="3" rows="6" columns="3">
19510 <features>
19511 <column alignment="center" valignment="top" leftline="true" width="0">
19512 <column alignment="block" valignment="top" leftline="true" width="20page%">
19513 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19514 <row topline="true" bottomline="true">
19515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19516 \begin_inset Text
19517
19518 \layout Standard
19519
19520 Keyword
19521 \end_inset 
19522 </cell>
19523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19524 \begin_inset Text
19525
19526 \layout Standard
19527
19528 Description
19529 \end_inset 
19530 </cell>
19531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19532 \begin_inset Text
19533
19534 \layout Standard
19535
19536 Module to link
19537 \end_inset 
19538 </cell>
19539 </row>
19540 <row topline="true">
19541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19542 \begin_inset Text
19543
19544 \layout Standard
19545
19546
19547 \series bold 
19548 ignore
19549 \end_inset 
19550 </cell>
19551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19552 \begin_inset Text
19553
19554 \layout Standard
19555
19556 ignore all library pragmas
19557 \end_inset 
19558 </cell>
19559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19560 \begin_inset Text
19561
19562 \layout Standard
19563
19564
19565 \emph on 
19566 (none)
19567 \end_inset 
19568 </cell>
19569 </row>
19570 <row topline="true">
19571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19572 \begin_inset Text
19573
19574 \layout Standard
19575
19576
19577 \series bold 
19578 c
19579 \end_inset 
19580 </cell>
19581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19582 \begin_inset Text
19583
19584 \layout Standard
19585
19586 link the C library
19587 \end_inset 
19588 </cell>
19589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19590 \begin_inset Text
19591
19592 \layout Standard
19593
19594
19595 \emph on 
19596 libc18f
19597 \emph default 
19598 .lib
19599 \end_inset 
19600 </cell>
19601 </row>
19602 <row topline="true">
19603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19604 \begin_inset Text
19605
19606 \layout Standard
19607
19608
19609 \series bold 
19610 math
19611 \end_inset 
19612 </cell>
19613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19614 \begin_inset Text
19615
19616 \layout Standard
19617
19618 link the Math libarary
19619 \end_inset 
19620 </cell>
19621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19622 \begin_inset Text
19623
19624 \layout Standard
19625
19626
19627 \emph on 
19628 libm18f
19629 \emph default 
19630 .lib
19631 \end_inset 
19632 </cell>
19633 </row>
19634 <row topline="true">
19635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19636 \begin_inset Text
19637
19638 \layout Standard
19639
19640
19641 \series bold 
19642 io
19643 \end_inset 
19644 </cell>
19645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19646 \begin_inset Text
19647
19648 \layout Standard
19649
19650 link the I/O library
19651 \end_inset 
19652 </cell>
19653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19654 \begin_inset Text
19655
19656 \layout Standard
19657
19658
19659 \emph on 
19660 libio18f*
19661 \emph default 
19662 .lib
19663 \end_inset 
19664 </cell>
19665 </row>
19666 <row topline="true" bottomline="true">
19667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19668 \begin_inset Text
19669
19670 \layout Standard
19671
19672
19673 \series bold 
19674 debug
19675 \end_inset 
19676 </cell>
19677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19678 \begin_inset Text
19679
19680 \layout Standard
19681
19682 link the debug library
19683 \end_inset 
19684 </cell>
19685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19686 \begin_inset Text
19687
19688 \layout Standard
19689
19690
19691 \emph on 
19692 libdebug
19693 \emph default 
19694 .lib
19695 \end_inset 
19696 </cell>
19697 </row>
19698 </lyxtabular>
19699
19700 \end_inset 
19701
19702
19703 \newline 
19704 * is the device number, i.e.
19705  452 for PIC18F452 MCU.
19706 \layout Standard
19707
19708 This feature allows for linking with specific libraries withoug having to
19709  explicit name them in the command line.
19710  Note that the 
19711 \noun on 
19712 ignore
19713 \noun default 
19714  keyword will reject all modules specified by the library pragma.
19715 \layout List
19716 \labelwidthstring 00.00.0000
19717
19718 udata pragma udata instructs the compiler to emit code so that linker will
19719  place a variable at a specific memory bank
19720 \layout LyX-Code
19721
19722 Example:
19723 \layout LyX-Code
19724
19725 \layout LyX-Code
19726
19727 /* places variable foo at bank2 */
19728 \layout LyX-Code
19729
19730 #pragma udata bank2 foo
19731 \layout LyX-Code
19732
19733 char foo;
19734 \layout Standard
19735
19736 In order for this pragma to work extra SECTION directives should be added
19737  in the .lkr script.
19738  In the following example a sample .lkr file is shown:
19739 \layout LyX-Code
19740
19741 \layout LyX-Code
19742
19743 // Sample linker script for the PIC18F452 processor
19744 \layout LyX-Code
19745
19746 LIBPATH .
19747 \layout LyX-Code
19748
19749 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
19750 \layout LyX-Code
19751
19752 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
19753 \layout LyX-Code
19754
19755 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
19756 \layout LyX-Code
19757
19758 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
19759 \layout LyX-Code
19760
19761 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
19762 \layout LyX-Code
19763
19764 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
19765 \layout LyX-Code
19766
19767 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
19768 \layout LyX-Code
19769
19770 \layout LyX-Code
19771
19772 DATABANK   NAME=gpr0       START=0x80           END=0xFF
19773 \layout LyX-Code
19774
19775 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
19776 \layout LyX-Code
19777
19778 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
19779 \layout LyX-Code
19780
19781 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
19782 \layout LyX-Code
19783
19784 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
19785 \layout LyX-Code
19786
19787 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
19788 \layout LyX-Code
19789
19790 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
19791 \layout LyX-Code
19792
19793 \layout LyX-Code
19794
19795 SECTION    NAME=CONFIG     ROM=config
19796 \layout LyX-Code
19797
19798 \layout LyX-Code
19799
19800 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
19801 \layout LyX-Code
19802
19803 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
19804 \layout LyX-Code
19805
19806 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
19807 \layout LyX-Code
19808
19809 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
19810 \layout LyX-Code
19811
19812 SECTION    NAME=bank4      RAM=gpr4
19813 \layout LyX-Code
19814
19815 SECTION    NAME=bank5      RAM=gpr5
19816 \layout Standard
19817
19818 The linker will recognise the section name set in the pragma statement and
19819  will position the variable at the memory bank set with the RAM field at
19820  the SECTION line in the linker script file.
19821 \layout Subsection
19822
19823 Header Files
19824 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19825
19826 \end_inset 
19827
19828
19829 \layout Standard
19830
19831 There is one main header file
19832 \begin_inset LatexCommand \index{PIC16!Header files}
19833
19834 \end_inset 
19835
19836  that can be included to the source files using the pic16
19837 \begin_inset LatexCommand \index{PIC16}
19838
19839 \end_inset 
19840
19841  port.
19842  That file is the 
19843 \series bold 
19844 pic18fregs.h
19845 \series default 
19846 .
19847  This header file contains the definitions for the processor special registers,
19848  so it is necessary if the source accesses them.
19849  It can be included by adding the following line in the beginning of the
19850  file:
19851 \layout LyX-Code
19852
19853 #include <pic18fregs.h>
19854 \layout Standard
19855
19856 The specific microcontroller is selected within the pic18fregs.h automatically,
19857  so the same source can be used with a variety of devices.
19858 \layout Subsection
19859
19860 Libraries
19861 \layout Standard
19862
19863 The libraries
19864 \begin_inset LatexCommand \index{PIC16!Libraries}
19865
19866 \end_inset 
19867
19868  that PIC16
19869 \begin_inset LatexCommand \index{PIC16}
19870
19871 \end_inset 
19872
19873  port depends on are the microcontroller device libraries which contain
19874  the symbol definitions for the microcontroller special function registers.
19875  These libraries have the format pic18fxxxx.lib, where 
19876 \emph on 
19877 xxxx
19878 \emph default 
19879  is the microcontroller identification number.
19880  The specific library is selected automatically by the compiler at link
19881  stage according to the selected device.
19882 \layout Standard
19883
19884 Libraries are created with gplib which is part of the gputils package 
19885 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19886
19887 \end_inset 
19888
19889 .
19890 \layout Subsubsection*
19891
19892 Building the libraries
19893 \layout Standard
19894
19895 Before using SDCC/pic16 there are some libraries that need to be compiled.
19896  This process is not done automatically by SDCC since not all users use
19897  SDCC for pic16 projects.
19898  So each user should compile the libraries separately.
19899 \layout Standard
19900
19901 The steps to compile the pic16 libraries under Linux are:
19902 \layout LyX-Code
19903
19904 cd device/lib/pic16
19905 \layout LyX-Code
19906
19907 ./configure
19908 \layout LyX-Code
19909
19910 make
19911 \layout LyX-Code
19912
19913 cd ..
19914 \layout LyX-Code
19915
19916 make model-pic16
19917 \layout LyX-Code
19918
19919 su -c 'make install'     # install the libraries, you need the root password
19920 \layout Standard
19921
19922 If you need to install the headers too, do:
19923 \layout LyX-Code
19924
19925 cd device/include
19926 \layout LyX-Code
19927
19928 su -c 'make install'     # install the headers, you need the root password
19929 \layout Standard
19930
19931 There exist a special target to build the I/O libraries.
19932  This target is not automatically build because it will build the I/O library
19933  for 
19934 \emph on 
19935 every
19936 \emph default 
19937  supported device.
19938  This way building will take quite a lot of time.
19939  Users are advised to edit the 
19940 \series bold 
19941 device/lib/pic16/pics.build
19942 \series default 
19943  file and then execute:
19944 \layout LyX-Code
19945
19946 make lib-io
19947 \layout Subsection
19948
19949 Memory Models
19950 \layout Standard
19951
19952 The following memory models are supported by the PIC16 port:
19953 \layout Itemize
19954
19955 small model
19956 \layout Itemize
19957
19958 large model
19959 \layout Standard
19960
19961 Memory model affects the default size of pointers within the source.
19962  The sizes are shown in the next table:
19963 \layout Standard
19964 \align center 
19965
19966 \begin_inset  Tabular
19967 <lyxtabular version="3" rows="3" columns="3">
19968 <features>
19969 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19970 <column alignment="center" valignment="top" leftline="true" width="0">
19971 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19972 <row topline="true" bottomline="true">
19973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19974 \begin_inset Text
19975
19976 \layout Standard
19977
19978 Pointer sizes according to memory model
19979 \end_inset 
19980 </cell>
19981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19982 \begin_inset Text
19983
19984 \layout Standard
19985
19986 small model
19987 \end_inset 
19988 </cell>
19989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19990 \begin_inset Text
19991
19992 \layout Standard
19993
19994 large model
19995 \end_inset 
19996 </cell>
19997 </row>
19998 <row topline="true" bottomline="true">
19999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20000 \begin_inset Text
20001
20002 \layout Standard
20003
20004 code pointers
20005 \end_inset 
20006 </cell>
20007 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20008 \begin_inset Text
20009
20010 \layout Standard
20011
20012 16-bits
20013 \end_inset 
20014 </cell>
20015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20016 \begin_inset Text
20017
20018 \layout Standard
20019
20020 24-bits
20021 \end_inset 
20022 </cell>
20023 </row>
20024 <row topline="true" bottomline="true">
20025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20026 \begin_inset Text
20027
20028 \layout Standard
20029
20030 data pointers
20031 \end_inset 
20032 </cell>
20033 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
20034 \begin_inset Text
20035
20036 \layout Standard
20037
20038 16-bits
20039 \end_inset 
20040 </cell>
20041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20042 \begin_inset Text
20043
20044 \layout Standard
20045
20046 16-bits
20047 \end_inset 
20048 </cell>
20049 </row>
20050 </lyxtabular>
20051
20052 \end_inset 
20053
20054
20055 \layout Standard
20056
20057 It is advisable that all sources within a project are compiled with the
20058  same memory model.
20059  If one wants to override the default memory model, this can be done by
20060  declaring a pointer as 
20061 \series bold 
20062 far
20063 \series default 
20064  or 
20065 \series bold 
20066 near
20067 \series default 
20068 .
20069  Far selects large memory model's pointers, while near selects small memory
20070  model's pointers.
20071 \layout Standard
20072
20073 The standard device libraries (see 
20074 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
20075
20076 \end_inset 
20077
20078 ) contain no reference to pointers, so they can be used with both memory
20079  models.
20080 \layout Subsection
20081
20082 Stack
20083 \layout Standard
20084
20085 The stack
20086 \begin_inset LatexCommand \index{PIC16!stack}
20087
20088 \end_inset 
20089
20090  implementation for the PIC16 port uses two indirect registers, FSR1 and
20091  FSR2.
20092 \layout List
20093 \labelwidthstring 00.00.0000
20094
20095 FSR1 is assigned as stack pointer
20096 \layout List
20097 \labelwidthstring 00.00.0000
20098
20099 FSR2 is assigned as frame pointer
20100 \layout Standard
20101
20102 The following stack models are supported by the PIC16 port
20103 \layout Itemize
20104
20105
20106 \noun on 
20107 small
20108 \noun default 
20109  model
20110 \layout Itemize
20111
20112
20113 \noun on 
20114 large
20115 \noun default 
20116  model
20117 \layout Standard
20118
20119
20120 \noun on 
20121 Small
20122 \noun default 
20123  model means that only the FSRxL byte is used to access stack and frame,
20124  while 
20125 \emph on 
20126 \noun on 
20127 large
20128 \emph default 
20129 \noun default 
20130  uses both FSRxL and FSRxH registers.
20131  The following table shows the stack/frame pointers sizes according to stack
20132  model and the maximum space they can address:
20133 \layout Standard
20134 \align center 
20135
20136 \begin_inset  Tabular
20137 <lyxtabular version="3" rows="3" columns="3">
20138 <features>
20139 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20140 <column alignment="center" valignment="top" leftline="true" width="0">
20141 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20142 <row topline="true" bottomline="true">
20143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20144 \begin_inset Text
20145
20146 \layout Standard
20147
20148 Stack & Frame pointer sizes according to stack model
20149 \end_inset 
20150 </cell>
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20152 \begin_inset Text
20153
20154 \layout Standard
20155
20156 small
20157 \end_inset 
20158 </cell>
20159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20160 \begin_inset Text
20161
20162 \layout Standard
20163
20164 large
20165 \end_inset 
20166 </cell>
20167 </row>
20168 <row topline="true">
20169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20170 \begin_inset Text
20171
20172 \layout Standard
20173
20174 Stack pointer FSR1
20175 \end_inset 
20176 </cell>
20177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20178 \begin_inset Text
20179
20180 \layout Standard
20181
20182 8-bits
20183 \end_inset 
20184 </cell>
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20186 \begin_inset Text
20187
20188 \layout Standard
20189
20190 16-bits
20191 \end_inset 
20192 </cell>
20193 </row>
20194 <row topline="true" bottomline="true">
20195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20196 \begin_inset Text
20197
20198 \layout Standard
20199
20200 Frame pointer FSR2
20201 \end_inset 
20202 </cell>
20203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20204 \begin_inset Text
20205
20206 \layout Standard
20207
20208 8-bits
20209 \end_inset 
20210 </cell>
20211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20212 \begin_inset Text
20213
20214 \layout Standard
20215
20216 16-bits
20217 \end_inset 
20218 </cell>
20219 </row>
20220 </lyxtabular>
20221
20222 \end_inset 
20223
20224
20225 \layout Standard
20226
20227
20228 \noun on 
20229 Large 
20230 \noun default 
20231 stack model is currently not working properly throughout the code generator.
20232  So its use is not advised.
20233  Also there are some other points that need special care:
20234 \newline 
20235
20236 \layout Enumerate
20237
20238 Do not create stack sections with size more than one physical bank (that
20239  is 256 bytes)
20240 \layout Enumerate
20241
20242 Stack sections should no cross physical bank limits (i.e.
20243  #pragma stack 0x50 0x100)
20244 \layout Standard
20245
20246 These limitations are caused by the fact that only FSRxL is modified when
20247  using SMALL stack model, so no more than 256 bytes of stack can be used.
20248  This problem will disappear after LARGE model is fully implemented.
20249 \layout Subsection
20250
20251 Functions
20252 \layout Standard
20253
20254 In addition to the standard SDCC function keywords, PIC16
20255 \begin_inset LatexCommand \index{PIC16}
20256
20257 \end_inset 
20258
20259  port makes available two more:
20260 \layout List
20261 \labelwidthstring 00.00.0000
20262
20263 wparam
20264 \begin_inset LatexCommand \index{PIC16!wparam}
20265
20266 \end_inset 
20267
20268  Use the WREG to pass one byte of the first function argument.
20269  This improves speed but you may not use this for functions with arguments
20270  that are called via function pointers, otherwise the first byte of the
20271  first parameter will get lost.
20272  Usage:
20273 \layout LyX-Code
20274
20275 void func_wparam(int a) wparam
20276 \layout LyX-Code
20277
20278 {
20279 \layout LyX-Code
20280
20281     /* WREG hold the lower part of a */
20282 \layout LyX-Code
20283
20284     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
20285  */
20286 \layout LyX-Code
20287
20288 ...
20289 \layout LyX-Code
20290
20291 }
20292 \layout List
20293 \labelwidthstring 00.00.0000
20294
20295 shadowregs
20296 \begin_inset LatexCommand \index{PIC16!shadowregs}
20297
20298 \end_inset 
20299
20300  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
20301  hardware shadow registers which hold the values of WREG, STATUS and BSR
20302  registers.
20303  This can be done by adding the keyword 
20304 \emph on 
20305 shadowregs
20306 \emph default 
20307  before the 
20308 \emph on 
20309 interrupt
20310 \emph default 
20311  keyword in the function's header.
20312 \layout LyX-Code
20313
20314 void isr_shadow(void) shadowregs interrupt 1
20315 \layout LyX-Code
20316
20317 {
20318 \layout LyX-Code
20319
20320 ...
20321 \layout LyX-Code
20322
20323 }
20324 \layout Standard
20325
20326
20327 \emph on 
20328 shadowregs
20329 \emph default 
20330  instructs the code generator not to store/restore WREG, STATUS, BSR when
20331  entering/exiting the ISR.
20332 \layout Subsection
20333
20334 Function return values
20335 \layout Standard
20336
20337 Return values from functions are placed to the appropriate registers following
20338  a modified Microchip policy optimized for SDCC.
20339  The following table shows these registers:
20340 \layout Standard
20341 \align center 
20342
20343 \begin_inset  Tabular
20344 <lyxtabular version="3" rows="6" columns="2">
20345 <features>
20346 <column alignment="center" valignment="top" leftline="true" width="0">
20347 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20348 <row topline="true" bottomline="true">
20349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20350 \begin_inset Text
20351
20352 \layout Standard
20353
20354 size
20355 \end_inset 
20356 </cell>
20357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20358 \begin_inset Text
20359
20360 \layout Standard
20361
20362 destination register
20363 \end_inset 
20364 </cell>
20365 </row>
20366 <row topline="true">
20367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20368 \begin_inset Text
20369
20370 \layout Standard
20371
20372 8 bits
20373 \end_inset 
20374 </cell>
20375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20376 \begin_inset Text
20377
20378 \layout Standard
20379
20380 WREG
20381 \end_inset 
20382 </cell>
20383 </row>
20384 <row topline="true">
20385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20386 \begin_inset Text
20387
20388 \layout Standard
20389
20390 16 bits
20391 \end_inset 
20392 </cell>
20393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20394 \begin_inset Text
20395
20396 \layout Standard
20397
20398 PRODL:WREG
20399 \end_inset 
20400 </cell>
20401 </row>
20402 <row topline="true">
20403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20404 \begin_inset Text
20405
20406 \layout Standard
20407
20408 24 bits
20409 \end_inset 
20410 </cell>
20411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20412 \begin_inset Text
20413
20414 \layout Standard
20415
20416 PRODH:PRODL:WREG
20417 \end_inset 
20418 </cell>
20419 </row>
20420 <row topline="true">
20421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20422 \begin_inset Text
20423
20424 \layout Standard
20425
20426 32 bits
20427 \end_inset 
20428 </cell>
20429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20430 \begin_inset Text
20431
20432 \layout Standard
20433
20434 FSR0L:PRODH:PRODL:WREG
20435 \end_inset 
20436 </cell>
20437 </row>
20438 <row topline="true" bottomline="true">
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20440 \begin_inset Text
20441
20442 \layout Standard
20443
20444 >32 bits
20445 \end_inset 
20446 </cell>
20447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20448 \begin_inset Text
20449
20450 \layout Standard
20451
20452 on stack, FSR0 points to the beginning
20453 \end_inset 
20454 </cell>
20455 </row>
20456 </lyxtabular>
20457
20458 \end_inset 
20459
20460
20461 \layout Subsection
20462
20463 Interrupts
20464 \layout Standard
20465
20466 An interrupt
20467 \begin_inset LatexCommand \index{PIC16!interrupt}
20468
20469 \end_inset 
20470
20471  service routine (ISR) is declared using the 
20472 \emph on 
20473 interrupt
20474 \emph default 
20475  keyword.
20476 \layout LyX-Code
20477
20478 void isr(void) interrupt 
20479 \emph on 
20480 n
20481 \layout LyX-Code
20482
20483 {
20484 \layout LyX-Code
20485
20486 ...
20487 \layout LyX-Code
20488
20489 }
20490 \layout Standard
20491
20492
20493 \emph on 
20494 n
20495 \emph default 
20496  is the interrupt number, which for PIC18F devices can be:
20497 \layout Standard
20498 \align center 
20499
20500 \begin_inset  Tabular
20501 <lyxtabular version="3" rows="4" columns="3">
20502 <features>
20503 <column alignment="center" valignment="top" leftline="true" width="0">
20504 <column alignment="center" valignment="top" leftline="true" width="0">
20505 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20506 <row topline="true" bottomline="true">
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20508 \begin_inset Text
20509
20510 \layout Standard
20511
20512
20513 \emph on 
20514 n
20515 \end_inset 
20516 </cell>
20517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20518 \begin_inset Text
20519
20520 \layout Standard
20521
20522 Interrupt Vector
20523 \end_inset 
20524 </cell>
20525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20526 \begin_inset Text
20527
20528 \layout Standard
20529
20530 Interrupt Vector Address
20531 \end_inset 
20532 </cell>
20533 </row>
20534 <row topline="true">
20535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20536 \begin_inset Text
20537
20538 \layout Standard
20539
20540 0
20541 \end_inset 
20542 </cell>
20543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20544 \begin_inset Text
20545
20546 \layout Standard
20547
20548 RESET vector
20549 \end_inset 
20550 </cell>
20551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20552 \begin_inset Text
20553
20554 \layout Standard
20555
20556 0x000000
20557 \end_inset 
20558 </cell>
20559 </row>
20560 <row topline="true">
20561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20562 \begin_inset Text
20563
20564 \layout Standard
20565
20566
20567 \family roman 
20568 \series medium 
20569 \shape up 
20570 \size normal 
20571 \emph off 
20572 \bar no 
20573 \noun off 
20574 \color none
20575 1
20576 \end_inset 
20577 </cell>
20578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20579 \begin_inset Text
20580
20581 \layout Standard
20582
20583
20584 \family roman 
20585 \series medium 
20586 \shape up 
20587 \size normal 
20588 \emph off 
20589 \bar no 
20590 \noun off 
20591 \color none
20592 HIGH priority interrupts
20593 \end_inset 
20594 </cell>
20595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20596 \begin_inset Text
20597
20598 \layout Standard
20599
20600 0x000008
20601 \end_inset 
20602 </cell>
20603 </row>
20604 <row topline="true" bottomline="true">
20605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20606 \begin_inset Text
20607
20608 \layout Standard
20609
20610 2
20611 \end_inset 
20612 </cell>
20613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20614 \begin_inset Text
20615
20616 \layout Standard
20617
20618 LOW priority interrupts
20619 \end_inset 
20620 </cell>
20621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20622 \begin_inset Text
20623
20624 \layout Standard
20625
20626 0x000018
20627 \end_inset 
20628 </cell>
20629 </row>
20630 </lyxtabular>
20631
20632 \end_inset 
20633
20634
20635 \layout Standard
20636
20637 When generating assembly code for ISR the code generator places a 
20638 \noun on 
20639 goto 
20640 \noun default 
20641 instruction at the 
20642 \emph on 
20643 Interrupt Vector Address
20644 \emph default 
20645  which points at the genetated ISR.
20646  This single GOTO instruction is part of an automatically generated 
20647 \emph on 
20648 interrupt entry point
20649 \emph default 
20650  function.
20651  The actuall ISR code is placed as normally would in the code space.
20652  Upon interrupt request, the GOTO instruction is executed which jumps to
20653  the ISR code.
20654  When declaring interrupt functions as _naked this GOTO instruction is 
20655 \series bold 
20656 not
20657 \series default 
20658  generated.
20659  The whole interrupt functions is therefore placed at the Interrupt Vector
20660  Address of the specific interrupt.
20661  This is not a problem for the LOW priority interrupts, but it is a problem
20662  for the RESET and the HIGH priority interrupts because code may be written
20663  at the next interrupt´s vector address and cause undeterminate program
20664  behaviour if that interrupt is raised.
20665 \begin_inset Foot
20666 collapsed false
20667
20668 \layout Standard
20669
20670 This is not a problem when
20671 \layout Enumerate
20672
20673 this is a HIGH interrupt ISR and LOW interrupts are 
20674 \emph on 
20675 disabled
20676 \emph default 
20677  or not used.
20678 \layout Enumerate
20679
20680 when the ISR is small enough not to reach the next interrupt´s vector address.
20681 \end_inset 
20682
20683
20684 \layout Standard
20685
20686
20687 \emph on 
20688 n
20689 \emph default 
20690  is possible to be omitted.
20691  This way a function is generated similar to an ISR, but it is not assigned
20692  to any interrupt.
20693 \layout Standard
20694
20695 When entering an interrupt, currently the PIC16
20696 \begin_inset LatexCommand \index{PIC16}
20697
20698 \end_inset 
20699
20700  port automatically saves the following registers:
20701 \layout Itemize
20702
20703 WREG
20704 \layout Itemize
20705
20706 STATUS
20707 \layout Itemize
20708
20709 BSR
20710 \layout Itemize
20711
20712 PROD (PRODL and PRODH)
20713 \layout Itemize
20714
20715 FSR0 (FSR0L and FSR0H)
20716 \layout Standard
20717
20718 These registers are restored upon return from the interrupt routine.
20719 \begin_inset Foot
20720 collapsed false
20721
20722 \layout Standard
20723
20724 NOTE that when the _naked attribute is specified for an interrupt routine,
20725  then NO registers are stored or restored.
20726 \end_inset 
20727
20728
20729 \layout Subsection
20730
20731 Generic Pointers
20732 \layout Standard
20733
20734 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20735  There are 3 types of generic pointers currently implemented data, code
20736  and eeprom pointers.
20737  They are differentiated by the value of the 7th and 6th bits of the upper
20738  byte:
20739 \layout Standard
20740 \align center 
20741
20742 \begin_inset  Tabular
20743 <lyxtabular version="3" rows="5" columns="5">
20744 <features>
20745 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20746 <column alignment="center" valignment="top" width="0">
20747 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20748 <column alignment="center" valignment="top" width="0">
20749 <column alignment="left" valignment="top" rightline="true" width="0">
20750 <row topline="true" bottomline="true">
20751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20752 \begin_inset Text
20753
20754 \layout Standard
20755
20756 pointer type
20757 \end_inset 
20758 </cell>
20759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20760 \begin_inset Text
20761
20762 \layout Standard
20763
20764 7th bit
20765 \end_inset 
20766 </cell>
20767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20768 \begin_inset Text
20769
20770 \layout Standard
20771
20772 6th bit
20773 \end_inset 
20774 </cell>
20775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20776 \begin_inset Text
20777
20778 \layout Standard
20779
20780 rest of the pointer
20781 \end_inset 
20782 </cell>
20783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20784 \begin_inset Text
20785
20786 \layout Standard
20787
20788 description
20789 \end_inset 
20790 </cell>
20791 </row>
20792 <row topline="true" bottomline="true">
20793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20794 \begin_inset Text
20795
20796 \layout Standard
20797
20798 data 
20799 \end_inset 
20800 </cell>
20801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20802 \begin_inset Text
20803
20804 \layout Standard
20805
20806 1
20807 \end_inset 
20808 </cell>
20809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20810 \begin_inset Text
20811
20812 \layout Standard
20813
20814 0
20815 \end_inset 
20816 </cell>
20817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20818 \begin_inset Text
20819
20820 \layout Standard
20821
20822
20823 \family typewriter 
20824 \shape slanted 
20825 \emph on 
20826 uuuuuu uuuuxxxx xxxxxxxx
20827 \end_inset 
20828 </cell>
20829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20830 \begin_inset Text
20831
20832 \layout Standard
20833
20834 a 12-bit data pointer in data RAM memory
20835 \end_inset 
20836 </cell>
20837 </row>
20838 <row bottomline="true">
20839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20840 \begin_inset Text
20841
20842 \layout Standard
20843
20844 code
20845 \end_inset 
20846 </cell>
20847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20848 \begin_inset Text
20849
20850 \layout Standard
20851
20852 0
20853 \end_inset 
20854 </cell>
20855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20856 \begin_inset Text
20857
20858 \layout Standard
20859
20860 0
20861 \end_inset 
20862 </cell>
20863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20864 \begin_inset Text
20865
20866 \layout Standard
20867
20868
20869 \family typewriter 
20870 \shape slanted 
20871 \emph on 
20872 uxxxxx xxxxxxxx xxxxxxxx
20873 \end_inset 
20874 </cell>
20875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20876 \begin_inset Text
20877
20878 \layout Standard
20879
20880 a 21-bit code pointer in FLASH memory
20881 \end_inset 
20882 </cell>
20883 </row>
20884 <row bottomline="true">
20885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20886 \begin_inset Text
20887
20888 \layout Standard
20889
20890 eeprom
20891 \end_inset 
20892 </cell>
20893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20894 \begin_inset Text
20895
20896 \layout Standard
20897
20898 0
20899 \end_inset 
20900 </cell>
20901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20902 \begin_inset Text
20903
20904 \layout Standard
20905
20906 1
20907 \end_inset 
20908 </cell>
20909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20910 \begin_inset Text
20911
20912 \layout Standard
20913
20914
20915 \family typewriter 
20916 \shape slanted 
20917 \emph on 
20918 uuuuuu uuuuuuxx xxxxxxxx
20919 \end_inset 
20920 </cell>
20921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20922 \begin_inset Text
20923
20924 \layout Standard
20925
20926 a 10-bit eeprom pointer in EEPROM memory
20927 \end_inset 
20928 </cell>
20929 </row>
20930 <row bottomline="true">
20931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20932 \begin_inset Text
20933
20934 \layout Standard
20935
20936 (unimplemented)
20937 \end_inset 
20938 </cell>
20939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20940 \begin_inset Text
20941
20942 \layout Standard
20943
20944 1
20945 \end_inset 
20946 </cell>
20947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20948 \begin_inset Text
20949
20950 \layout Standard
20951
20952 1
20953 \end_inset 
20954 </cell>
20955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20956 \begin_inset Text
20957
20958 \layout Standard
20959
20960
20961 \family typewriter 
20962 \shape slanted 
20963 \emph on 
20964 xxxxxx xxxxxxxx xxxxxxxx
20965 \end_inset 
20966 </cell>
20967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20968 \begin_inset Text
20969
20970 \layout Standard
20971
20972 unimplemented pointer type
20973 \end_inset 
20974 </cell>
20975 </row>
20976 </lyxtabular>
20977
20978 \end_inset 
20979
20980
20981 \layout Standard
20982
20983 Generic pointer are read and written with a set of library functions which
20984  read/write 1, 2, 3, 4 bytes.
20985 \layout Subsection
20986
20987 PIC16 C Libraries
20988 \layout Subsubsection
20989
20990 Standard I/O Streams
20991 \layout Standard
20992
20993 In the 
20994 \emph on 
20995 stdio.h
20996 \emph default 
20997  the type FILE is defined as:
20998 \layout LyX-Code
20999
21000 typedef char * FILE;
21001 \layout Standard
21002
21003 This type is the stream type implemented I/O in the PIC18F devices.
21004  Also the standard input and output streams are declared in stdio.h:
21005 \layout LyX-Code
21006
21007 extern FILE * stdin;
21008 \layout LyX-Code
21009
21010 extern FILE * stdout;
21011 \layout Standard
21012
21013 The FILE type is actually a generic pointer which defines one more type
21014  of generic pointers, the 
21015 \emph on 
21016 stream 
21017 \emph default 
21018 pointer.
21019  This new type has the format:
21020 \layout Standard
21021 \align center 
21022
21023 \begin_inset  Tabular
21024 <lyxtabular version="3" rows="2" columns="7">
21025 <features>
21026 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21027 <column alignment="center" valignment="top" width="0">
21028 <column alignment="center" valignment="top" leftline="true" width="0">
21029 <column alignment="center" valignment="top" leftline="true" width="0">
21030 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21031 <column alignment="center" valignment="top" width="0">
21032 <column alignment="left" valignment="top" rightline="true" width="0">
21033 <row topline="true" bottomline="true">
21034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21035 \begin_inset Text
21036
21037 \layout Standard
21038
21039 pointer type
21040 \end_inset 
21041 </cell>
21042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21043 \begin_inset Text
21044
21045 \layout Standard
21046
21047 <7:6>
21048 \end_inset 
21049 </cell>
21050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21051 \begin_inset Text
21052
21053 \layout Standard
21054
21055 <5>
21056 \end_inset 
21057 </cell>
21058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21059 \begin_inset Text
21060
21061 \layout Standard
21062
21063 <4>
21064 \end_inset 
21065 </cell>
21066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21067 \begin_inset Text
21068
21069 \layout Standard
21070
21071 <3:0>
21072 \end_inset 
21073 </cell>
21074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21075 \begin_inset Text
21076
21077 \layout Standard
21078
21079 rest of the pointer
21080 \end_inset 
21081 </cell>
21082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21083 \begin_inset Text
21084
21085 \layout Standard
21086
21087 descrption
21088 \end_inset 
21089 </cell>
21090 </row>
21091 <row topline="true" bottomline="true">
21092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21093 \begin_inset Text
21094
21095 \layout Standard
21096
21097 stream
21098 \end_inset 
21099 </cell>
21100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21101 \begin_inset Text
21102
21103 \layout Standard
21104
21105 00
21106 \end_inset 
21107 </cell>
21108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21109 \begin_inset Text
21110
21111 \layout Standard
21112
21113 1
21114 \end_inset 
21115 </cell>
21116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21117 \begin_inset Text
21118
21119 \layout Standard
21120
21121 0
21122 \end_inset 
21123 </cell>
21124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21125 \begin_inset Text
21126
21127 \layout Standard
21128
21129 nnnn
21130 \end_inset 
21131 </cell>
21132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21133 \begin_inset Text
21134
21135 \layout Standard
21136
21137
21138 \family typewriter 
21139 \shape slanted 
21140 \emph on 
21141 uuuuuuuu uuuuuuuu
21142 \end_inset 
21143 </cell>
21144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21145 \begin_inset Text
21146
21147 \layout Standard
21148
21149 upper byte high nubble is 0x2n, the rest are zeroes
21150 \end_inset 
21151 </cell>
21152 </row>
21153 </lyxtabular>
21154
21155 \end_inset 
21156
21157
21158 \layout Standard
21159
21160 Currently implemented there are 3 types of streams defined:
21161 \layout Standard
21162 \align center 
21163
21164 \begin_inset  Tabular
21165 <lyxtabular version="3" rows="4" columns="4">
21166 <features>
21167 <column alignment="center" valignment="top" leftline="true" width="0">
21168 <column alignment="center" valignment="top" leftline="true" width="0">
21169 <column alignment="center" valignment="top" leftline="true" width="0">
21170 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21171 <row topline="true" bottomline="true">
21172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21173 \begin_inset Text
21174
21175 \layout Standard
21176
21177 stream type
21178 \end_inset 
21179 </cell>
21180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21181 \begin_inset Text
21182
21183 \layout Standard
21184
21185 value
21186 \end_inset 
21187 </cell>
21188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21189 \begin_inset Text
21190
21191 \layout Standard
21192
21193 module
21194 \end_inset 
21195 </cell>
21196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21197 \begin_inset Text
21198
21199 \layout Standard
21200
21201 description
21202 \end_inset 
21203 </cell>
21204 </row>
21205 <row topline="true">
21206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21207 \begin_inset Text
21208
21209 \layout Standard
21210
21211 STREAM_USART
21212 \end_inset 
21213 </cell>
21214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21215 \begin_inset Text
21216
21217 \layout Standard
21218
21219
21220 \family typewriter 
21221 0x200000UL
21222 \end_inset 
21223 </cell>
21224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21225 \begin_inset Text
21226
21227 \layout Standard
21228
21229 USART
21230 \end_inset 
21231 </cell>
21232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21233 \begin_inset Text
21234
21235 \layout Standard
21236
21237 Writes/Reads characters via the USART peripheral
21238 \end_inset 
21239 </cell>
21240 </row>
21241 <row topline="true">
21242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21243 \begin_inset Text
21244
21245 \layout Standard
21246
21247 STREAM_MSSP
21248 \end_inset 
21249 </cell>
21250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21251 \begin_inset Text
21252
21253 \layout Standard
21254
21255
21256 \family typewriter 
21257 0x210000UL
21258 \end_inset 
21259 </cell>
21260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21261 \begin_inset Text
21262
21263 \layout Standard
21264
21265 MSSP
21266 \end_inset 
21267 </cell>
21268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21269 \begin_inset Text
21270
21271 \layout Standard
21272
21273 Writes/Reads characters via the MSSP peripheral
21274 \end_inset 
21275 </cell>
21276 </row>
21277 <row topline="true" bottomline="true">
21278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21279 \begin_inset Text
21280
21281 \layout Standard
21282
21283 STREAM_USER
21284 \end_inset 
21285 </cell>
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21287 \begin_inset Text
21288
21289 \layout Standard
21290
21291
21292 \family typewriter 
21293 0x2f0000UL
21294 \end_inset 
21295 </cell>
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21297 \begin_inset Text
21298
21299 \layout Standard
21300
21301 (none)
21302 \end_inset 
21303 </cell>
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21305 \begin_inset Text
21306
21307 \layout Standard
21308
21309 Writes/Reads characters via used defined functions
21310 \end_inset 
21311 </cell>
21312 </row>
21313 </lyxtabular>
21314
21315 \end_inset 
21316
21317
21318 \layout Standard
21319
21320 The stream identifiers are declared as macros in the stdio.h header.
21321 \layout Standard
21322
21323 In the libc library there exist the functions that are used to write to
21324  each of the above streams.
21325  These are
21326 \layout List
21327 \labelwidthstring 00.00.0000
21328
21329 _
21330 \begin_inset ERT
21331 status Collapsed
21332
21333 \layout Standard
21334
21335 \backslash 
21336 /
21337 \end_inset 
21338
21339 _stream_usart_putchar writes a character at the USART stream
21340 \layout List
21341 \labelwidthstring 00.00.0000
21342
21343 _
21344 \begin_inset ERT
21345 status Collapsed
21346
21347 \layout Standard
21348
21349 \backslash 
21350 /
21351 \end_inset 
21352
21353 _stream_mssp_putchar writes a character at the MSSP stream
21354 \layout List
21355 \labelwidthstring 00.00.0000
21356
21357 putchar dummy function.
21358  This writes a character to a user specified manner.
21359 \layout Standard
21360
21361 In order to increase performance 
21362 \emph on 
21363 putchar 
21364 \emph default 
21365 is declared in stdio.h as having its parameter in WREG (it has the wparam
21366  keyword).
21367  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
21368  in a user-friendly way.
21369  
21370 \emph on 
21371 arg
21372 \emph default 
21373  is the name of the variable that holds the character to print.
21374  An example follows:
21375 \layout LyX-Code
21376
21377 #include <pic18fregs.h>
21378 \newline 
21379 #include <stdio.h>
21380 \newline 
21381
21382 \newline 
21383 PUTCHAR( c )
21384 \layout LyX-Code
21385
21386 {
21387 \layout LyX-Code
21388
21389     PORTA = c;    /* dump character c to PORTA */
21390 \layout LyX-Code
21391
21392
21393 \newline 
21394
21395 \newline 
21396 void main(void)
21397 \layout LyX-Code
21398
21399 {
21400 \layout LyX-Code
21401
21402     stdout = STREAM_USER;    /* this is not necessary, since stdout points
21403 \layout LyX-Code
21404
21405                               * by default to STREAM_USER */
21406 \layout LyX-Code
21407
21408     printf (¨This is a printf test
21409 \backslash 
21410 n¨);
21411 \layout LyX-Code
21412
21413 }
21414 \layout LyX-Code
21415
21416 \layout Subsubsection
21417
21418 Printing functions
21419 \layout Standard
21420
21421 PIC16 contains an implementation of the printf-family of functions.
21422  There exist the following functions:
21423 \layout LyX-Code
21424
21425 extern unsigned int sprintf(char *buf, char *fmt, ...);
21426 \layout LyX-Code
21427
21428 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
21429 \layout LyX-Code
21430
21431 \layout LyX-Code
21432
21433 extern unsigned int printf(char *fmt, ...);
21434 \layout LyX-Code
21435
21436 extern unsigned int vprintf(char *fmt, va_lista ap);
21437 \layout LyX-Code
21438
21439 \layout LyX-Code
21440
21441 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
21442 \layout LyX-Code
21443
21444 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
21445 \layout Standard
21446
21447 For sprintf and vsprintf 
21448 \emph on 
21449 buf 
21450 \emph default 
21451 should normally be a data pointer where the resulting string will be placed.
21452  No range checking is done so the user should allocate the necessery buffer.
21453  For fprintf and vfprintf 
21454 \emph on 
21455 fp
21456 \emph default 
21457  should be a stream pointer (i.e.
21458  stdout, STREAM_MSSP, etc...).
21459 \layout Subsubsection
21460
21461 Signals
21462 \layout Standard
21463
21464 The PIC18F family of microcontrollers supports a number of interrupt sources.
21465  A list of these interrupts is shown in the following table:
21466 \layout Standard
21467 \align center 
21468
21469 \begin_inset  Tabular
21470 <lyxtabular version="3" rows="11" columns="4">
21471 <features>
21472 <column alignment="left" valignment="top" leftline="true" width="0">
21473 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21474 <column alignment="left" valignment="top" leftline="true" width="0">
21475 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21476 <row topline="true" bottomline="true">
21477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21478 \begin_inset Text
21479
21480 \layout Standard
21481
21482 signal name
21483 \end_inset 
21484 </cell>
21485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21486 \begin_inset Text
21487
21488 \layout Standard
21489
21490 description
21491 \end_inset 
21492 </cell>
21493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21494 \begin_inset Text
21495
21496 \layout Standard
21497
21498 signal name
21499 \end_inset 
21500 </cell>
21501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21502 \begin_inset Text
21503
21504 \layout Standard
21505
21506 descritpion
21507 \end_inset 
21508 </cell>
21509 </row>
21510 <row topline="true">
21511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21512 \begin_inset Text
21513
21514 \layout Standard
21515
21516 SIG_RB
21517 \end_inset 
21518 </cell>
21519 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21520 \begin_inset Text
21521
21522 \layout Standard
21523
21524 PORTB change interrupt
21525 \end_inset 
21526 </cell>
21527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21528 \begin_inset Text
21529
21530 \layout Standard
21531
21532 SIG_EE
21533 \end_inset 
21534 </cell>
21535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21536 \begin_inset Text
21537
21538 \layout Standard
21539
21540 EEPROM/FLASH write complete interrupt
21541 \end_inset 
21542 </cell>
21543 </row>
21544 <row topline="true">
21545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21546 \begin_inset Text
21547
21548 \layout Standard
21549
21550 SIG_INT0
21551 \end_inset 
21552 </cell>
21553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21554 \begin_inset Text
21555
21556 \layout Standard
21557
21558 INT0 external interrupt
21559 \end_inset 
21560 </cell>
21561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21562 \begin_inset Text
21563
21564 \layout Standard
21565
21566 SIG_BCOL
21567 \end_inset 
21568 </cell>
21569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21570 \begin_inset Text
21571
21572 \layout Standard
21573
21574 Bus collision interrupt
21575 \end_inset 
21576 </cell>
21577 </row>
21578 <row topline="true">
21579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21580 \begin_inset Text
21581
21582 \layout Standard
21583
21584 SIG_INT1
21585 \end_inset 
21586 </cell>
21587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21588 \begin_inset Text
21589
21590 \layout Standard
21591
21592 INT1 external interrupt
21593 \end_inset 
21594 </cell>
21595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21596 \begin_inset Text
21597
21598 \layout Standard
21599
21600 SIG_LVD
21601 \end_inset 
21602 </cell>
21603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21604 \begin_inset Text
21605
21606 \layout Standard
21607
21608 Low voltage detect interrupt
21609 \end_inset 
21610 </cell>
21611 </row>
21612 <row topline="true">
21613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21614 \begin_inset Text
21615
21616 \layout Standard
21617
21618 SIG_INT2
21619 \end_inset 
21620 </cell>
21621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21622 \begin_inset Text
21623
21624 \layout Standard
21625
21626 INT2 external interrupt
21627 \end_inset 
21628 </cell>
21629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21630 \begin_inset Text
21631
21632 \layout Standard
21633
21634 SIG_PSP
21635 \end_inset 
21636 </cell>
21637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21638 \begin_inset Text
21639
21640 \layout Standard
21641
21642 Parallel slave port interrupt
21643 \end_inset 
21644 </cell>
21645 </row>
21646 <row topline="true">
21647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21648 \begin_inset Text
21649
21650 \layout Standard
21651
21652 SIG_CCP1
21653 \end_inset 
21654 </cell>
21655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21656 \begin_inset Text
21657
21658 \layout Standard
21659
21660 CCP1 module interrupt
21661 \end_inset 
21662 </cell>
21663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21664 \begin_inset Text
21665
21666 \layout Standard
21667
21668 SIG_AD
21669 \end_inset 
21670 </cell>
21671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21672 \begin_inset Text
21673
21674 \layout Standard
21675
21676 AD convertion complete interrupt
21677 \end_inset 
21678 </cell>
21679 </row>
21680 <row topline="true">
21681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21682 \begin_inset Text
21683
21684 \layout Standard
21685
21686 SIG_CCP2
21687 \end_inset 
21688 </cell>
21689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21690 \begin_inset Text
21691
21692 \layout Standard
21693
21694 CCP2 module interrupt
21695 \end_inset 
21696 </cell>
21697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21698 \begin_inset Text
21699
21700 \layout Standard
21701
21702 SIG_RC
21703 \end_inset 
21704 </cell>
21705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21706 \begin_inset Text
21707
21708 \layout Standard
21709
21710 USART receive interrupt
21711 \end_inset 
21712 </cell>
21713 </row>
21714 <row topline="true">
21715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21716 \begin_inset Text
21717
21718 \layout Standard
21719
21720 SIG_TMR0
21721 \end_inset 
21722 </cell>
21723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21724 \begin_inset Text
21725
21726 \layout Standard
21727
21728 TMR0 overflow interrupt
21729 \end_inset 
21730 </cell>
21731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21732 \begin_inset Text
21733
21734 \layout Standard
21735
21736 SIG_TX
21737 \end_inset 
21738 </cell>
21739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21740 \begin_inset Text
21741
21742 \layout Standard
21743
21744 USART transmit interrupt
21745 \end_inset 
21746 </cell>
21747 </row>
21748 <row topline="true">
21749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21750 \begin_inset Text
21751
21752 \layout Standard
21753
21754 SIG_TMR1
21755 \end_inset 
21756 </cell>
21757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21758 \begin_inset Text
21759
21760 \layout Standard
21761
21762 TMR1 overflow interrupt
21763 \end_inset 
21764 </cell>
21765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21766 \begin_inset Text
21767
21768 \layout Standard
21769
21770 SIG_MSSP
21771 \end_inset 
21772 </cell>
21773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21774 \begin_inset Text
21775
21776 \layout Standard
21777
21778 SSP receive/transmit interrupt
21779 \end_inset 
21780 </cell>
21781 </row>
21782 <row topline="true">
21783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21784 \begin_inset Text
21785
21786 \layout Standard
21787
21788 SIG_TMR2
21789 \end_inset 
21790 </cell>
21791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21792 \begin_inset Text
21793
21794 \layout Standard
21795
21796 TMR2 matches PR2 interrupt
21797 \end_inset 
21798 </cell>
21799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21800 \begin_inset Text
21801
21802 \layout Standard
21803
21804 \end_inset 
21805 </cell>
21806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21807 \begin_inset Text
21808
21809 \layout Standard
21810
21811 \end_inset 
21812 </cell>
21813 </row>
21814 <row topline="true" bottomline="true">
21815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21816 \begin_inset Text
21817
21818 \layout Standard
21819
21820 SIG_TMR3
21821 \end_inset 
21822 </cell>
21823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21824 \begin_inset Text
21825
21826 \layout Standard
21827
21828 TMR3 overflow interrupt
21829 \end_inset 
21830 </cell>
21831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21832 \begin_inset Text
21833
21834 \layout Standard
21835
21836 \end_inset 
21837 </cell>
21838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21839 \begin_inset Text
21840
21841 \layout Standard
21842
21843 \end_inset 
21844 </cell>
21845 </row>
21846 </lyxtabular>
21847
21848 \end_inset 
21849
21850
21851 \layout Standard
21852
21853 The prototypes for these names are defined in the header file 
21854 \emph on 
21855 signal.h
21856 \emph default 
21857  .
21858 \layout Standard
21859
21860 In order to simplify signal handling, a number of macros is provided:
21861 \layout List
21862 \labelwidthstring 00.00.0000
21863
21864 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21865  high priority interrupts.
21866  
21867 \emph on 
21868 name
21869 \emph default 
21870  is the function name to use.
21871 \layout List
21872 \labelwidthstring 00.00.0000
21873
21874 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21875  low priority interrupt.
21876  
21877 \emph on 
21878 name
21879 \emph default 
21880  is the function name to use.
21881 \layout List
21882 \labelwidthstring 00.00.0000
21883
21884 DEF_HANDLER(sig,handler) define a handler for signal 
21885 \emph on 
21886 sig.
21887 \layout List
21888 \labelwidthstring 00.00.0000
21889
21890 END_DEF end the declaration of the dispatch table.
21891 \layout Standard
21892
21893 Additionally there are two more macros to simplify the declaration of the
21894  signal handler:
21895 \layout List
21896 \labelwidthstring 00.00.0000
21897
21898
21899 \series medium 
21900 SIGHANDLER(handler) 
21901 \series default 
21902 this declares the function prototype for the 
21903 \emph on 
21904 handler
21905 \emph default 
21906  function.
21907 \layout List
21908 \labelwidthstring 00.00.0000
21909
21910 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21911 \layout Standard
21912
21913 An example of using the macros above is shown below:
21914 \layout LyX-Code
21915
21916 #include <pic18fregs.h>
21917 \layout LyX-Code
21918
21919 #include <signal.h>
21920 \newline 
21921
21922 \newline 
21923 DEF_INTHIGH(high_int)
21924 \layout LyX-Code
21925
21926 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21927 \layout LyX-Code
21928
21929 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21930 \layout LyX-Code
21931
21932 END_DEF
21933 \newline 
21934
21935 \newline 
21936 SIGHANDLER(_tmr0_handler)
21937 \layout LyX-Code
21938
21939 {
21940 \layout LyX-Code
21941
21942   /* action to be taken when timer 0 overflows */
21943 \layout LyX-Code
21944
21945 }
21946 \newline 
21947
21948 \newline 
21949 SIGHANDLERNAKED(_bcol_handler)
21950 \layout LyX-Code
21951
21952 {
21953 \layout LyX-Code
21954
21955   _asm
21956 \layout LyX-Code
21957
21958     /* action to be taken when bus collision occurs */
21959 \layout LyX-Code
21960
21961     retfie
21962 \layout LyX-Code
21963
21964  _endasm;
21965 \layout LyX-Code
21966
21967 }
21968 \layout Standard
21969
21970
21971 \series bold 
21972 NOTES:
21973 \series default 
21974  Special care should be taken when using the above scheme:
21975 \layout Itemize
21976
21977 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21978 \layout Itemize
21979
21980 when declaring SIGHANDLERNAKED handler never forget to use 
21981 \emph on 
21982 retfie
21983 \emph default 
21984  for proper returning.
21985 \layout Subsection
21986
21987 PIC16 Port -- Tips
21988 \layout Standard
21989
21990 Here you can find some general tips for compiling programs with SDCC/pic16.
21991 \layout Subsubsection
21992
21993 Stack size
21994 \layout Standard
21995
21996 The default stack
21997 \begin_inset LatexCommand \index{PIC16!stack}
21998
21999 \end_inset 
22000
22001  size (that is 64 bytes) probably is enough for many programs.
22002  One must take care that when there are many levels of function nesting,
22003  or there is excessive usage of stack, its size should be extended.
22004  An example of such a case is the printf/sprintf family of functions.
22005  If you encounter problems like not being able to print integers, then you
22006  need to set the stack size around the maximum (256 for small stack model).
22007  The following diagram shows what happens when calling printf to print an
22008  integer:
22009 \layout LyX-Code
22010
22011 printf () --> ltoa () --> ultoa () --> divschar ()
22012 \layout Standard
22013
22014 It is should be understood that stack is easily consumed when calling complicate
22015 d functions.
22016  Using command line arguments like -
22017 \begin_inset ERT
22018 status Collapsed
22019
22020 \layout Standard
22021
22022 \backslash 
22023 /
22024 \end_inset 
22025
22026 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
22027  stack frames.
22028  Other ways to reduce stack usage may exist.
22029 \layout Subsection
22030
22031 Known bugs
22032 \layout Standard
22033
22034 The PIC16 Port currently does not pass SDCC's regression test
22035 \begin_inset LatexCommand \index{Regression test (PIC16)}
22036
22037 \end_inset 
22038
22039  suite (see section 
22040 \begin_inset LatexCommand \ref{sec:Quality-control}
22041
22042 \end_inset 
22043
22044 ) and thus the nightly regression tests for the PIC16 target are currently
22045  disabled for all hosts except for 
22046 \emph on 
22047 Linux on Opteron.
22048
22049 \emph default 
22050  This means you can see the result of the PIC16 regression tests f.e.
22051  by checking the log files in 
22052 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
22053
22054 \end_inset 
22055
22056  (pick the most up to date file there, scroll down, lend a hand).
22057 \layout Chapter
22058
22059 Debugging
22060 \layout Standard
22061
22062 There are several approaches to debugging your code.
22063  This chapter is meant to show your options and to give detail on some of
22064  them:
22065 \newline 
22066
22067 \newline 
22068 When writing your code:
22069 \layout Itemize
22070
22071 write your code with debugging in mind (avoid duplicating code, put conceptually
22072  similar variables into structs, use structured code, have strategic points
22073  within your code where all variables are consistent, ...)
22074 \layout Itemize
22075
22076 run a syntax-checking tool like splint
22077 \begin_inset LatexCommand \index{splint (syntax checking tool)}
22078
22079 \end_inset 
22080
22081
22082 \begin_inset LatexCommand \index{lint (syntax checking tool)}
22083
22084 \end_inset 
22085
22086  (see -
22087 \begin_inset ERT
22088 status Collapsed
22089
22090 \layout Standard
22091
22092 \backslash 
22093 /
22094 \end_inset 
22095
22096 -more-pedantic 
22097 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22098
22099 \end_inset 
22100
22101 ) over the code.
22102 \layout Itemize
22103
22104 for the high level code use a C-compiler (like f.e.
22105  GCC) to compile run and debug the code on your host.
22106  See (see -
22107 \begin_inset ERT
22108 status Collapsed
22109
22110 \layout Standard
22111
22112 \backslash 
22113 /
22114 \end_inset 
22115
22116 -more-pedantic 
22117 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22118
22119 \end_inset 
22120
22121  ) on howto handle syntax extensions like __xdata, __at(), ...
22122  
22123 \layout Itemize
22124
22125 use another C-compiler to compile code for your target.
22126  Always an option but not recommended:) And not very likely to help you.
22127  If you seriously consider walking this path you should at least occasionally
22128  check portability of your code.
22129  Most commercial compiler vendors will offer an evaluation version so you
22130  can test compile your code or snippets of your code.
22131 \layout Standard
22132
22133 Debugging on a simulator:
22134 \layout Itemize
22135
22136 there is a separate section about SDCDB (section 
22137 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
22138
22139 \end_inset 
22140
22141 ) below.
22142 \layout Itemize
22143
22144 or (8051 specific) use a freeware/commercial simulator which interfaces
22145  to the AOMF
22146 \begin_inset LatexCommand \index{AOMF, AOMF51}
22147
22148 \end_inset 
22149
22150  file (see 
22151 \begin_inset LatexCommand \ref{OMF file}
22152
22153 \end_inset 
22154
22155 ) optionally generated by SDCC.
22156 \layout Standard
22157
22158 Debugging On-target: 
22159 \layout Itemize
22160
22161 use a MCU port pin to serially output debug data to the RS232 port of your
22162  host.
22163  You'll probably want some level shifting device typically involving a MAX232
22164  or similar IC.
22165  If the hardware serial port of the MCU is not available search for 'Software
22166  UART' in your favourite search machine.
22167 \layout Itemize
22168
22169 use an on-target monitor.
22170  In this context a monitor is a small program which usually accepts commands
22171  via a serial line and allows to set program counter, to single step through
22172  a program and read/write memory locations.
22173  For the 8051 good examples of monitors are paulmon and cmon51 (see section
22174  
22175 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
22176
22177 \end_inset 
22178
22179 ).
22180 \layout Itemize
22181
22182 toggle MCU port pins at strategic points within your code and use an oscilloscop
22183 e.
22184  A 
22185 \emph on 
22186 digital oscilloscope
22187 \emph default 
22188
22189 \begin_inset LatexCommand \index{Oscilloscope}
22190
22191 \end_inset 
22192
22193  with deep trace memory is really helpful especially if you have to debug
22194  a realtime application.
22195  If you need to monitor more pins than your oscilloscope provides you can
22196  sometimes get away with a small R-2R network.
22197  On a single channel oscilloscope you could f.e.
22198  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
22199 k
22200 \begin_inset Formula $\Omega$
22201 \end_inset 
22202
22203  resistor and the other one by a 5\SpecialChar ~
22204 k
22205 \begin_inset Formula $\Omega$
22206 \end_inset 
22207
22208  resistor to the oscilloscope probe (check output drive capability of the
22209  pins you want to monitor).
22210  If you need to monitor many more pins a 
22211 \emph on 
22212 logic analyzer
22213 \emph default 
22214  will be handy.
22215 \layout Itemize
22216
22217 use an ICE (
22218 \emph on 
22219 i
22220 \emph default 
22221
22222 \emph on 
22223 c
22224 \emph default 
22225 ircuit 
22226 \emph on 
22227 e
22228 \emph default 
22229 mulator
22230 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
22231
22232 \end_inset 
22233
22234 ).
22235  Usually very expensive.
22236  And very nice to have too.
22237  And usually locks you (for years...) to the devices the ICE can emulate.
22238  
22239 \layout Itemize
22240
22241 use a remote debugger.
22242  In most 8-bit systems the symbol information is not available on the target,
22243  and a complete debugger is too bulky for the target system.
22244  Therefore usually a debugger on the host system connects to an on-target
22245  debugging stub which accepts only primitive commands.
22246  
22247 \newline 
22248 Terms to enter into your favourite search engine could be 'remote debugging',
22249  'gdb stub' or 'inferior debugger'.
22250  (is there one?)
22251 \layout Itemize
22252
22253 use an on target hardware debugger.
22254  Some of the more modern MCUs include hardware support for setting break
22255  points and monitoring/changing variables by using dedicated hardware pins.
22256  This facility doesn't require additional code to run on the target and
22257  
22258 \emph on 
22259 usually
22260 \emph default 
22261  doesn't affect runtime behaviour until a breakpoint is hit.
22262  For the mcs51 most hardware debuggers use the AOMF
22263 \begin_inset LatexCommand \index{AOMF, AOMF51}
22264
22265 \end_inset 
22266
22267  file (see 
22268 \begin_inset LatexCommand \ref{OMF file}
22269
22270 \end_inset 
22271
22272 ) as input file.
22273  
22274 \layout Standard
22275
22276 Last not least:
22277 \layout Itemize
22278
22279 if you are not familiar with any of the following terms you're likely to
22280  run into problems rather sooner than later: 
22281 \emph on 
22282 volatile
22283 \emph default 
22284
22285 \emph on 
22286 atomic
22287 \emph default 
22288
22289 \emph on 
22290 memory map
22291 \emph default 
22292
22293 \emph on 
22294 overlay
22295 \emph default 
22296 .
22297  As an embedded programmer you 
22298 \emph on 
22299 have
22300 \emph default 
22301  to know them so why not look them up 
22302 \emph on 
22303 before
22304 \emph default 
22305  you have problems?)
22306 \layout Itemize
22307
22308 tell someone else about your problem (actually this is a surprisingly effective
22309  means to hunt down the bug even if the listener is not familiar with your
22310  environment).
22311  As 'failure to communicate' is probably one of the job-induced deformations
22312  of an embedded programmer this is highly encouraged.
22313 \layout Section
22314
22315 Debugging with SDCDB
22316 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
22317
22318 \end_inset 
22319
22320
22321 \begin_inset LatexCommand \index{SDCDB (debugger)}
22322
22323 \end_inset 
22324
22325  
22326 \layout Standard
22327
22328 SDCC is distributed with a source level debugger
22329 \begin_inset LatexCommand \index{Debugger}
22330
22331 \end_inset 
22332
22333 .
22334  The debugger uses a command line interface, the command repertoire of the
22335  debugger has been kept as close to gdb
22336 \begin_inset LatexCommand \index{gdb}
22337
22338 \end_inset 
22339
22340  (the GNU debugger) as possible.
22341  The configuration and build process is part of the standard compiler installati
22342 on, which also builds and installs the debugger in the target directory
22343  specified during configuration.
22344  The debugger allows you debug BOTH at the C source and at the ASM source
22345  level.
22346 \layout Subsection
22347
22348 Compiling for Debugging
22349 \layout Standard
22350
22351 The -
22352 \begin_inset ERT
22353 status Collapsed
22354
22355 \layout Standard
22356
22357 \backslash 
22358 /
22359 \end_inset 
22360
22361 -debug
22362 \begin_inset LatexCommand \index{-\/-debug}
22363
22364 \end_inset 
22365
22366  option must be specified for all files for which debug information is to
22367  be generated.
22368  The compiler generates a .adb file for each of these files.
22369  The linker creates the .cdb
22370 \begin_inset LatexCommand \index{<file>.cdb}
22371
22372 \end_inset 
22373
22374  file from the .adb
22375 \begin_inset LatexCommand \index{<file>.adb}
22376
22377 \end_inset 
22378
22379  files and the address information.
22380  This .cdb is used by the debugger.
22381 \layout Subsection
22382
22383 How the Debugger Works
22384 \layout Standard
22385
22386 When the -
22387 \begin_inset ERT
22388 status Collapsed
22389
22390 \layout Standard
22391
22392 \backslash 
22393 /
22394 \end_inset 
22395
22396 -debug option is specified the compiler generates extra symbol information
22397  some of which are put into the assembler source and some are put into the
22398  .adb file.
22399  Then the linker creates the .cdb file from the individual .adb files with
22400  the address information for the symbols.
22401  The debugger reads the symbolic information generated by the compiler &
22402  the address information generated by the linker.
22403  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
22404  execution is controlled by the debugger.
22405  When a command is issued for the debugger, it translates it into appropriate
22406  commands for the simulator.
22407  (Currently SDCDM only connects to the simulator but 
22408 \emph on 
22409 newcdb
22410 \emph default 
22411  at 
22412 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
22413
22414 \end_inset 
22415
22416  is an effort to connect directly to the hardware.) 
22417 \layout Subsection
22418
22419 Starting the Debugger SDCDB
22420 \layout Standard
22421
22422 The debugger can be started using the following command line.
22423  (Assume the file you are debugging has the file name foo).
22424 \newline 
22425
22426 \newline 
22427
22428 \family sans 
22429 \series bold 
22430 sdcdb foo
22431 \newline 
22432
22433 \family default 
22434 \series default 
22435
22436 \newline 
22437 The debugger will look for the following files.
22438 \layout Itemize
22439
22440 foo.c - the source file.
22441 \layout Itemize
22442
22443 foo.cdb - the debugger symbol information file.
22444 \layout Itemize
22445
22446 foo.ihx - the Intel hex format
22447 \begin_inset LatexCommand \index{Intel hex format}
22448
22449 \end_inset 
22450
22451  object file.
22452 \layout Subsection
22453
22454 SDCDB Command Line Options
22455 \layout Itemize
22456
22457 -
22458 \begin_inset ERT
22459 status Collapsed
22460
22461 \layout Standard
22462
22463 \backslash 
22464 /
22465 \end_inset 
22466
22467 -directory=<source file directory> this option can used to specify the directory
22468  search list.
22469  The debugger will look into the directory list specified for source, cdb
22470  & ihx files.
22471  The items in the directory list must be separated by ':', e.g.
22472  if the source files can be in the directories /home/src1 and /home/src2,
22473  the -
22474 \begin_inset ERT
22475 status Collapsed
22476
22477 \layout Standard
22478
22479 \backslash 
22480 /
22481 \end_inset 
22482
22483 -directory option should be -
22484 \begin_inset ERT
22485 status Collapsed
22486
22487 \layout Standard
22488
22489 \backslash 
22490 /
22491 \end_inset 
22492
22493 -directory=/home/src1:/home/src2.
22494  Note there can be no spaces in the option.
22495  
22496 \layout Itemize
22497
22498 -cd <directory> - change to the <directory>.
22499 \layout Itemize
22500
22501 -fullname - used by GUI front ends.
22502 \layout Itemize
22503
22504 -cpu <cpu-type> - this argument is passed to the simulator please see the
22505  simulator docs for details.
22506 \layout Itemize
22507
22508 -X <Clock frequency > this options is passed to the simulator please see
22509  the simulator docs for details.
22510 \layout Itemize
22511
22512 -s <serial port file> passed to simulator see the simulator docs for details.
22513 \layout Itemize
22514
22515 -S <serial in,out> passed to simulator see the simulator docs for details.
22516 \layout Itemize
22517
22518 -k <port number> passed to simulator see the simulator docs for details.
22519 \layout Subsection
22520
22521 SDCDB Debugger Commands
22522 \layout Standard
22523
22524 As mentioned earlier the command interface for the debugger has been deliberatel
22525 y kept as close the GNU debugger gdb, as possible.
22526  This will help the integration with existing graphical user interfaces
22527  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
22528  If you use a graphical user interface for the debugger you can skip this
22529  section.
22530 \layout Subsubsection*
22531
22532 break [line | file:line | function | file:function]
22533 \layout Standard
22534
22535 Set breakpoint at specified line or function:
22536 \newline 
22537
22538 \newline 
22539
22540 \family sans 
22541 \series bold 
22542 sdcdb>break 100 
22543 \newline 
22544 sdcdb>break foo.c:100
22545 \newline 
22546 sdcdb>break funcfoo
22547 \newline 
22548 sdcdb>break foo.c:funcfoo
22549 \layout Subsubsection*
22550
22551 clear [line | file:line | function | file:function ]
22552 \layout Standard
22553
22554 Clear breakpoint at specified line or function:
22555 \newline 
22556
22557 \newline 
22558
22559 \family sans 
22560 \series bold 
22561 sdcdb>clear 100
22562 \newline 
22563 sdcdb>clear foo.c:100
22564 \newline 
22565 sdcdb>clear funcfoo
22566 \newline 
22567 sdcdb>clear foo.c:funcfoo
22568 \layout Subsubsection*
22569
22570 continue
22571 \layout Standard
22572
22573 Continue program being debugged, after breakpoint.
22574 \layout Subsubsection*
22575
22576 finish
22577 \layout Standard
22578
22579 Execute till the end of the current function.
22580 \layout Subsubsection*
22581
22582 delete [n]
22583 \layout Standard
22584
22585 Delete breakpoint number 'n'.
22586  If used without any option clear ALL user defined break points.
22587 \layout Subsubsection*
22588
22589 info [break | stack | frame | registers ]
22590 \layout Itemize
22591
22592 info break - list all breakpoints
22593 \layout Itemize
22594
22595 info stack - show the function call stack.
22596 \layout Itemize
22597
22598 info frame - show information about the current execution frame.
22599 \layout Itemize
22600
22601 info registers - show content of all registers.
22602 \layout Subsubsection*
22603
22604 step
22605 \layout Standard
22606
22607 Step program until it reaches a different source line.
22608  Note: pressing <return> repeats the last command.
22609 \layout Subsubsection*
22610
22611 next
22612 \layout Standard
22613
22614 Step program, proceeding through subroutine calls.
22615 \layout Subsubsection*
22616
22617 run
22618 \layout Standard
22619
22620 Start debugged program.
22621 \layout Subsubsection*
22622
22623 ptype variable 
22624 \layout Standard
22625
22626 Print type information of the variable.
22627 \layout Subsubsection*
22628
22629 print variable
22630 \layout Standard
22631
22632 print value of variable.
22633 \layout Subsubsection*
22634
22635 file filename
22636 \layout Standard
22637
22638 load the given file name.
22639  Note this is an alternate method of loading file for debugging.
22640 \layout Subsubsection*
22641
22642 frame
22643 \layout Standard
22644
22645 print information about current frame.
22646 \layout Subsubsection*
22647
22648 set srcmode
22649 \layout Standard
22650
22651 Toggle between C source & assembly source.
22652 \layout Subsubsection*
22653
22654 ! simulator command
22655 \layout Standard
22656
22657 Send the string following '!' to the simulator, the simulator response is
22658  displayed.
22659  Note the debugger does not interpret the command being sent to the simulator,
22660  so if a command like 'go' is sent the debugger can loose its execution
22661  context and may display incorrect values.
22662 \layout Subsubsection*
22663
22664 quit
22665 \layout Standard
22666
22667 "Watch me now.
22668  Iam going Down.
22669  My name is Bobby Brown"
22670 \layout Subsection
22671
22672 Interfacing SDCDB with DDD
22673 \layout Comment
22674
22675 The screenshot was converted from png to eps with: 
22676 \begin_inset Quotes sld
22677 \end_inset 
22678
22679 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22680 \begin_inset Quotes srd
22681 \end_inset 
22682
22683  which produces a pretty compact eps file which is free from compression
22684  artifacts.
22685 \layout Comment
22686
22687 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22688  as this broke the build system on Sourceforge (pdf-file was broken.
22689  pdflatex does not accept eps files).
22690 \layout Standard
22691
22692 The 
22693 \emph on 
22694 p
22695 \emph default 
22696 ortable 
22697 \emph on 
22698 n
22699 \emph default 
22700 etwork 
22701 \emph on 
22702 g
22703 \emph default 
22704 raphics File 
22705 \size footnotesize 
22706
22707 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22708
22709 \end_inset 
22710
22711
22712 \size default 
22713  shows a screenshot of a debugging session with DDD
22714 \begin_inset LatexCommand \index{DDD (debugger)}
22715
22716 \end_inset 
22717
22718  (Unix only) on a simulated 8032.
22719  The debugging session might not run as smoothly as the screenshot suggests.
22720  The debugger allows setting of breakpoints, displaying and changing variables,
22721  single stepping through C and assembler code.
22722  
22723 \newline 
22724 The source was compiled with 
22725 \family sans 
22726 \series bold 
22727
22728 \newline 
22729
22730 \newline 
22731 sdcc -
22732 \family default 
22733 \series default 
22734
22735 \begin_inset ERT
22736 status Collapsed
22737
22738 \layout Standard
22739
22740 \backslash 
22741 /
22742 \end_inset 
22743
22744
22745 \family sans 
22746 \series bold 
22747 -debug ddd_example.c
22748 \family default 
22749 \series default 
22750  
22751 \family sans 
22752 \series bold 
22753
22754 \newline 
22755
22756 \family default 
22757 \series default 
22758
22759 \newline 
22760 and DDD was invoked with 
22761 \family sans 
22762 \series bold 
22763
22764 \newline 
22765
22766 \newline 
22767 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22768 \layout Subsection
22769
22770 Interfacing SDCDB with XEmacs
22771 \begin_inset LatexCommand \index{XEmacs}
22772
22773 \end_inset 
22774
22775
22776 \begin_inset LatexCommand \index{Emacs}
22777
22778 \end_inset 
22779
22780
22781 \layout Standard
22782
22783 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22784  sdcdb.el and sdcdbsrc.el.
22785  These two files can be found in the $(prefix)/bin directory after the installat
22786 ion is complete.
22787  These files need to be loaded into XEmacs for the interface to work.
22788  This can be done at XEmacs startup time by inserting the following into
22789  your '.xemacs' file (which can be found in your HOME directory): 
22790 \newline 
22791
22792 \newline 
22793
22794 \family typewriter 
22795 (load-file sdcdbsrc.el) 
22796 \family default 
22797
22798 \newline 
22799
22800 \newline 
22801 .xemacs is a lisp file so the () around the command is REQUIRED.
22802  The files can also be loaded dynamically while XEmacs is running, set the
22803  environment variable 'EMACSLOADPATH' to the installation bin directory
22804  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22805  To start the interface enter the following command: 
22806 \newline 
22807
22808 \newline 
22809
22810 \family sans 
22811 \series bold 
22812 ESC-x sdcdbsrc
22813 \family default 
22814 \series default 
22815
22816 \newline 
22817
22818 \newline 
22819 You will prompted to enter the file name to be debugged.
22820  
22821 \newline 
22822
22823 \newline 
22824 The command line options that are passed to the simulator directly are bound
22825  to default values in the file sdcdbsrc.el.
22826  The variables are listed below, these values maybe changed as required.
22827 \layout Itemize
22828
22829 sdcdbsrc-cpu-type '51
22830 \layout Itemize
22831
22832 sdcdbsrc-frequency '11059200
22833 \layout Itemize
22834
22835 sdcdbsrc-serial nil
22836 \layout Standard
22837
22838 The following is a list of key mapping for the debugger interface.
22839 \layout Standard
22840
22841 \SpecialChar ~
22842
22843 \family typewriter 
22844
22845 \newline 
22846 ;;\SpecialChar ~
22847 Current Listing :: 
22848 \newline 
22849 ;;key\SpecialChar ~
22850 \SpecialChar ~
22851 \SpecialChar ~
22852 \SpecialChar ~
22853 \SpecialChar ~
22854 \SpecialChar ~
22855 \SpecialChar ~
22856 \SpecialChar ~
22857 \SpecialChar ~
22858 \SpecialChar ~
22859 \SpecialChar ~
22860 \SpecialChar ~
22861 \SpecialChar ~
22862 \SpecialChar ~
22863 binding\SpecialChar ~
22864 \SpecialChar ~
22865 \SpecialChar ~
22866 \SpecialChar ~
22867 \SpecialChar ~
22868 \SpecialChar ~
22869 \SpecialChar ~
22870 \SpecialChar ~
22871 \SpecialChar ~
22872 \SpecialChar ~
22873 \SpecialChar ~
22874 \SpecialChar ~
22875 \SpecialChar ~
22876 \SpecialChar ~
22877 \SpecialChar ~
22878 \SpecialChar ~
22879 \SpecialChar ~
22880 \SpecialChar ~
22881 \SpecialChar ~
22882 \SpecialChar ~
22883 \SpecialChar ~
22884 \SpecialChar ~
22885 Comment 
22886 \newline 
22887 ;;---\SpecialChar ~
22888 \SpecialChar ~
22889 \SpecialChar ~
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 \SpecialChar ~
22893 \SpecialChar ~
22894 \SpecialChar ~
22895 \SpecialChar ~
22896 \SpecialChar ~
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 \SpecialChar ~
22900 \SpecialChar ~
22901 -------\SpecialChar ~
22902 \SpecialChar ~
22903 \SpecialChar ~
22904 \SpecialChar ~
22905 \SpecialChar ~
22906 \SpecialChar ~
22907 \SpecialChar ~
22908 \SpecialChar ~
22909 \SpecialChar ~
22910 \SpecialChar ~
22911 \SpecialChar ~
22912 \SpecialChar ~
22913 \SpecialChar ~
22914 \SpecialChar ~
22915 \SpecialChar ~
22916 \SpecialChar ~
22917 \SpecialChar ~
22918 \SpecialChar ~
22919 \SpecialChar ~
22920 \SpecialChar ~
22921 \SpecialChar ~
22922 \SpecialChar ~
22923 -------
22924 \newline 
22925 ;; 
22926 \newline 
22927 ;;\SpecialChar ~
22928 n\SpecialChar ~
22929 \SpecialChar ~
22930 \SpecialChar ~
22931 \SpecialChar ~
22932 \SpecialChar ~
22933 \SpecialChar ~
22934 \SpecialChar ~
22935 \SpecialChar ~
22936 \SpecialChar ~
22937 \SpecialChar ~
22938 \SpecialChar ~
22939 \SpecialChar ~
22940 \SpecialChar ~
22941 \SpecialChar ~
22942 \SpecialChar ~
22943 sdcdb-next-from-src\SpecialChar ~
22944 \SpecialChar ~
22945 \SpecialChar ~
22946 \SpecialChar ~
22947 \SpecialChar ~
22948 \SpecialChar ~
22949 \SpecialChar ~
22950 \SpecialChar ~
22951 \SpecialChar ~
22952 \SpecialChar ~
22953 SDCDB next command 
22954 \newline 
22955 ;;\SpecialChar ~
22956 b\SpecialChar ~
22957 \SpecialChar ~
22958 \SpecialChar ~
22959 \SpecialChar ~
22960 \SpecialChar ~
22961 \SpecialChar ~
22962 \SpecialChar ~
22963 \SpecialChar ~
22964 \SpecialChar ~
22965 \SpecialChar ~
22966 \SpecialChar ~
22967 \SpecialChar ~
22968 \SpecialChar ~
22969 \SpecialChar ~
22970 \SpecialChar ~
22971 sdcdb-back-from-src\SpecialChar ~
22972 \SpecialChar ~
22973 \SpecialChar ~
22974 \SpecialChar ~
22975 \SpecialChar ~
22976 \SpecialChar ~
22977 \SpecialChar ~
22978 \SpecialChar ~
22979 \SpecialChar ~
22980 \SpecialChar ~
22981 SDCDB back command 
22982 \newline 
22983 ;;\SpecialChar ~
22984 c\SpecialChar ~
22985 \SpecialChar ~
22986 \SpecialChar ~
22987 \SpecialChar ~
22988 \SpecialChar ~
22989 \SpecialChar ~
22990 \SpecialChar ~
22991 \SpecialChar ~
22992 \SpecialChar ~
22993 \SpecialChar ~
22994 \SpecialChar ~
22995 \SpecialChar ~
22996 \SpecialChar ~
22997 \SpecialChar ~
22998 \SpecialChar ~
22999 sdcdb-cont-from-src\SpecialChar ~
23000 \SpecialChar ~
23001 \SpecialChar ~
23002 \SpecialChar ~
23003 \SpecialChar ~
23004 \SpecialChar ~
23005 \SpecialChar ~
23006 \SpecialChar ~
23007 \SpecialChar ~
23008 \SpecialChar ~
23009 SDCDB continue command
23010 \newline 
23011 ;;\SpecialChar ~
23012 s\SpecialChar ~
23013 \SpecialChar ~
23014 \SpecialChar ~
23015 \SpecialChar ~
23016 \SpecialChar ~
23017 \SpecialChar ~
23018 \SpecialChar ~
23019 \SpecialChar ~
23020 \SpecialChar ~
23021 \SpecialChar ~
23022 \SpecialChar ~
23023 \SpecialChar ~
23024 \SpecialChar ~
23025 \SpecialChar ~
23026 \SpecialChar ~
23027 sdcdb-step-from-src\SpecialChar ~
23028 \SpecialChar ~
23029 \SpecialChar ~
23030 \SpecialChar ~
23031 \SpecialChar ~
23032 \SpecialChar ~
23033 \SpecialChar ~
23034 \SpecialChar ~
23035 \SpecialChar ~
23036 \SpecialChar ~
23037 SDCDB step command 
23038 \newline 
23039 ;;\SpecialChar ~
23040 ?\SpecialChar ~
23041 \SpecialChar ~
23042 \SpecialChar ~
23043 \SpecialChar ~
23044 \SpecialChar ~
23045 \SpecialChar ~
23046 \SpecialChar ~
23047 \SpecialChar ~
23048 \SpecialChar ~
23049 \SpecialChar ~
23050 \SpecialChar ~
23051 \SpecialChar ~
23052 \SpecialChar ~
23053 \SpecialChar ~
23054 \SpecialChar ~
23055 sdcdb-whatis-c-sexp\SpecialChar ~
23056 \SpecialChar ~
23057 \SpecialChar ~
23058 \SpecialChar ~
23059 \SpecialChar ~
23060 \SpecialChar ~
23061 \SpecialChar ~
23062 \SpecialChar ~
23063 \SpecialChar ~
23064 \SpecialChar ~
23065 SDCDB ptypecommand for data at 
23066 \newline 
23067 ;;\SpecialChar ~
23068 \SpecialChar ~
23069 \SpecialChar ~
23070 \SpecialChar ~
23071 \SpecialChar ~
23072 \SpecialChar ~
23073 \SpecialChar ~
23074 \SpecialChar ~
23075 \SpecialChar ~
23076 \SpecialChar ~
23077 \SpecialChar ~
23078 \SpecialChar ~
23079 \SpecialChar ~
23080 \SpecialChar ~
23081 \SpecialChar ~
23082 \SpecialChar ~
23083 \SpecialChar ~
23084 \SpecialChar ~
23085 \SpecialChar ~
23086 \SpecialChar ~
23087 \SpecialChar ~
23088 \SpecialChar ~
23089 \SpecialChar ~
23090 \SpecialChar ~
23091 \SpecialChar ~
23092 \SpecialChar ~
23093 \SpecialChar ~
23094 \SpecialChar ~
23095 \SpecialChar ~
23096 \SpecialChar ~
23097 \SpecialChar ~
23098 \SpecialChar ~
23099 \SpecialChar ~
23100 \SpecialChar ~
23101 \SpecialChar ~
23102 \SpecialChar ~
23103 \SpecialChar ~
23104 \SpecialChar ~
23105 \SpecialChar ~
23106 \SpecialChar ~
23107 \SpecialChar ~
23108 \SpecialChar ~
23109 \SpecialChar ~
23110 \SpecialChar ~
23111 \SpecialChar ~
23112 \SpecialChar ~
23113 \SpecialChar ~
23114 buffer point 
23115 \newline 
23116 ;;\SpecialChar ~
23117 x\SpecialChar ~
23118 \SpecialChar ~
23119 \SpecialChar ~
23120 \SpecialChar ~
23121 \SpecialChar ~
23122 \SpecialChar ~
23123 \SpecialChar ~
23124 \SpecialChar ~
23125 \SpecialChar ~
23126 \SpecialChar ~
23127 \SpecialChar ~
23128 \SpecialChar ~
23129 \SpecialChar ~
23130 \SpecialChar ~
23131 \SpecialChar ~
23132 sdcdbsrc-delete\SpecialChar ~
23133 \SpecialChar ~
23134 \SpecialChar ~
23135 \SpecialChar ~
23136 \SpecialChar ~
23137 \SpecialChar ~
23138 \SpecialChar ~
23139 \SpecialChar ~
23140 \SpecialChar ~
23141 \SpecialChar ~
23142 \SpecialChar ~
23143 \SpecialChar ~
23144 \SpecialChar ~
23145 \SpecialChar ~
23146 SDCDB Delete all breakpoints if no arg 
23147 \newline 
23148 ;;\SpecialChar ~
23149 \SpecialChar ~
23150 \SpecialChar ~
23151 \SpecialChar ~
23152 \SpecialChar ~
23153 \SpecialChar ~
23154 \SpecialChar ~
23155 \SpecialChar ~
23156 \SpecialChar ~
23157 \SpecialChar ~
23158 \SpecialChar ~
23159 \SpecialChar ~
23160 \SpecialChar ~
23161 \SpecialChar ~
23162 \SpecialChar ~
23163 \SpecialChar ~
23164 \SpecialChar ~
23165 \SpecialChar ~
23166 \SpecialChar ~
23167 \SpecialChar ~
23168 \SpecialChar ~
23169 \SpecialChar ~
23170 \SpecialChar ~
23171 \SpecialChar ~
23172 \SpecialChar ~
23173 \SpecialChar ~
23174 \SpecialChar ~
23175 \SpecialChar ~
23176 \SpecialChar ~
23177 \SpecialChar ~
23178 \SpecialChar ~
23179 \SpecialChar ~
23180 \SpecialChar ~
23181 \SpecialChar ~
23182 \SpecialChar ~
23183 \SpecialChar ~
23184 \SpecialChar ~
23185 \SpecialChar ~
23186 \SpecialChar ~
23187 \SpecialChar ~
23188 \SpecialChar ~
23189 \SpecialChar ~
23190 \SpecialChar ~
23191 \SpecialChar ~
23192 \SpecialChar ~
23193 \SpecialChar ~
23194 \SpecialChar ~
23195 given or delete arg (C-u arg x) 
23196 \newline 
23197 ;;\SpecialChar ~
23198 m\SpecialChar ~
23199 \SpecialChar ~
23200 \SpecialChar ~
23201 \SpecialChar ~
23202 \SpecialChar ~
23203 \SpecialChar ~
23204 \SpecialChar ~
23205 \SpecialChar ~
23206 \SpecialChar ~
23207 \SpecialChar ~
23208 \SpecialChar ~
23209 \SpecialChar ~
23210 \SpecialChar ~
23211 \SpecialChar ~
23212 \SpecialChar ~
23213 sdcdbsrc-frame\SpecialChar ~
23214 \SpecialChar ~
23215 \SpecialChar ~
23216 \SpecialChar ~
23217 \SpecialChar ~
23218 \SpecialChar ~
23219 \SpecialChar ~
23220 \SpecialChar ~
23221 \SpecialChar ~
23222 \SpecialChar ~
23223 \SpecialChar ~
23224 \SpecialChar ~
23225 \SpecialChar ~
23226 \SpecialChar ~
23227 \SpecialChar ~
23228 SDCDB Display current frame if no arg, 
23229 \newline 
23230 ;;\SpecialChar ~
23231 \SpecialChar ~
23232 \SpecialChar ~
23233 \SpecialChar ~
23234 \SpecialChar ~
23235 \SpecialChar ~
23236 \SpecialChar ~
23237 \SpecialChar ~
23238 \SpecialChar ~
23239 \SpecialChar ~
23240 \SpecialChar ~
23241 \SpecialChar ~
23242 \SpecialChar ~
23243 \SpecialChar ~
23244 \SpecialChar ~
23245 \SpecialChar ~
23246 \SpecialChar ~
23247 \SpecialChar ~
23248 \SpecialChar ~
23249 \SpecialChar ~
23250 \SpecialChar ~
23251 \SpecialChar ~
23252 \SpecialChar ~
23253 \SpecialChar ~
23254 \SpecialChar ~
23255 \SpecialChar ~
23256 \SpecialChar ~
23257 \SpecialChar ~
23258 \SpecialChar ~
23259 \SpecialChar ~
23260 \SpecialChar ~
23261 \SpecialChar ~
23262 \SpecialChar ~
23263 \SpecialChar ~
23264 \SpecialChar ~
23265 \SpecialChar ~
23266 \SpecialChar ~
23267 \SpecialChar ~
23268 \SpecialChar ~
23269 \SpecialChar ~
23270 \SpecialChar ~
23271 \SpecialChar ~
23272 \SpecialChar ~
23273 \SpecialChar ~
23274 \SpecialChar ~
23275 \SpecialChar ~
23276 \SpecialChar ~
23277 given or display frame arg 
23278 \newline 
23279 ;;\SpecialChar ~
23280 \SpecialChar ~
23281 \SpecialChar ~
23282 \SpecialChar ~
23283 \SpecialChar ~
23284 \SpecialChar ~
23285 \SpecialChar ~
23286 \SpecialChar ~
23287 \SpecialChar ~
23288 \SpecialChar ~
23289 \SpecialChar ~
23290 \SpecialChar ~
23291 \SpecialChar ~
23292 \SpecialChar ~
23293 \SpecialChar ~
23294 \SpecialChar ~
23295 \SpecialChar ~
23296 \SpecialChar ~
23297 \SpecialChar ~
23298 \SpecialChar ~
23299 \SpecialChar ~
23300 \SpecialChar ~
23301 \SpecialChar ~
23302 \SpecialChar ~
23303 \SpecialChar ~
23304 \SpecialChar ~
23305 \SpecialChar ~
23306 \SpecialChar ~
23307 \SpecialChar ~
23308 \SpecialChar ~
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 \SpecialChar ~
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 \SpecialChar ~
23315 \SpecialChar ~
23316 \SpecialChar ~
23317 \SpecialChar ~
23318 \SpecialChar ~
23319 \SpecialChar ~
23320 \SpecialChar ~
23321 \SpecialChar ~
23322 \SpecialChar ~
23323 \SpecialChar ~
23324 \SpecialChar ~
23325 \SpecialChar ~
23326 buffer point 
23327 \newline 
23328 ;;\SpecialChar ~
23329 !\SpecialChar ~
23330 \SpecialChar ~
23331 \SpecialChar ~
23332 \SpecialChar ~
23333 \SpecialChar ~
23334 \SpecialChar ~
23335 \SpecialChar ~
23336 \SpecialChar ~
23337 \SpecialChar ~
23338 \SpecialChar ~
23339 \SpecialChar ~
23340 \SpecialChar ~
23341 \SpecialChar ~
23342 \SpecialChar ~
23343 \SpecialChar ~
23344 sdcdbsrc-goto-sdcdb\SpecialChar ~
23345 \SpecialChar ~
23346 \SpecialChar ~
23347 \SpecialChar ~
23348 \SpecialChar ~
23349 \SpecialChar ~
23350 \SpecialChar ~
23351 \SpecialChar ~
23352 \SpecialChar ~
23353 \SpecialChar ~
23354 Goto the SDCDB output buffer 
23355 \newline 
23356 ;;\SpecialChar ~
23357 p\SpecialChar ~
23358 \SpecialChar ~
23359 \SpecialChar ~
23360 \SpecialChar ~
23361 \SpecialChar ~
23362 \SpecialChar ~
23363 \SpecialChar ~
23364 \SpecialChar ~
23365 \SpecialChar ~
23366 \SpecialChar ~
23367 \SpecialChar ~
23368 \SpecialChar ~
23369 \SpecialChar ~
23370 \SpecialChar ~
23371 \SpecialChar ~
23372 sdcdb-print-c-sexp\SpecialChar ~
23373 \SpecialChar ~
23374 \SpecialChar ~
23375 \SpecialChar ~
23376 \SpecialChar ~
23377 \SpecialChar ~
23378 \SpecialChar ~
23379 \SpecialChar ~
23380 \SpecialChar ~
23381 \SpecialChar ~
23382 \SpecialChar ~
23383 SDCDB print command for data at 
23384 \newline 
23385 ;;\SpecialChar ~
23386 \SpecialChar ~
23387 \SpecialChar ~
23388 \SpecialChar ~
23389 \SpecialChar ~
23390 \SpecialChar ~
23391 \SpecialChar ~
23392 \SpecialChar ~
23393 \SpecialChar ~
23394 \SpecialChar ~
23395 \SpecialChar ~
23396 \SpecialChar ~
23397 \SpecialChar ~
23398 \SpecialChar ~
23399 \SpecialChar ~
23400 \SpecialChar ~
23401 \SpecialChar ~
23402 \SpecialChar ~
23403 \SpecialChar ~
23404 \SpecialChar ~
23405 \SpecialChar ~
23406 \SpecialChar ~
23407 \SpecialChar ~
23408 \SpecialChar ~
23409 \SpecialChar ~
23410 \SpecialChar ~
23411 \SpecialChar ~
23412 \SpecialChar ~
23413 \SpecialChar ~
23414 \SpecialChar ~
23415 \SpecialChar ~
23416 \SpecialChar ~
23417 \SpecialChar ~
23418 \SpecialChar ~
23419 \SpecialChar ~
23420 \SpecialChar ~
23421 \SpecialChar ~
23422 \SpecialChar ~
23423 \SpecialChar ~
23424 \SpecialChar ~
23425 \SpecialChar ~
23426 \SpecialChar ~
23427 \SpecialChar ~
23428 \SpecialChar ~
23429 \SpecialChar ~
23430 \SpecialChar ~
23431 \SpecialChar ~
23432 buffer point 
23433 \newline 
23434 ;;\SpecialChar ~
23435 g\SpecialChar ~
23436 \SpecialChar ~
23437 \SpecialChar ~
23438 \SpecialChar ~
23439 \SpecialChar ~
23440 \SpecialChar ~
23441 \SpecialChar ~
23442 \SpecialChar ~
23443 \SpecialChar ~
23444 \SpecialChar ~
23445 \SpecialChar ~
23446 \SpecialChar ~
23447 \SpecialChar ~
23448 \SpecialChar ~
23449 \SpecialChar ~
23450 sdcdbsrc-goto-sdcdb\SpecialChar ~
23451 \SpecialChar ~
23452 \SpecialChar ~
23453 \SpecialChar ~
23454 \SpecialChar ~
23455 \SpecialChar ~
23456 \SpecialChar ~
23457 \SpecialChar ~
23458 \SpecialChar ~
23459 \SpecialChar ~
23460 Goto the SDCDB output buffer 
23461 \newline 
23462 ;;\SpecialChar ~
23463 t\SpecialChar ~
23464 \SpecialChar ~
23465 \SpecialChar ~
23466 \SpecialChar ~
23467 \SpecialChar ~
23468 \SpecialChar ~
23469 \SpecialChar ~
23470 \SpecialChar ~
23471 \SpecialChar ~
23472 \SpecialChar ~
23473 \SpecialChar ~
23474 \SpecialChar ~
23475 \SpecialChar ~
23476 \SpecialChar ~
23477 \SpecialChar ~
23478 sdcdbsrc-mode\SpecialChar ~
23479 \SpecialChar ~
23480 \SpecialChar ~
23481 \SpecialChar ~
23482 \SpecialChar ~
23483 \SpecialChar ~
23484 \SpecialChar ~
23485 \SpecialChar ~
23486 \SpecialChar ~
23487 \SpecialChar ~
23488 \SpecialChar ~
23489 \SpecialChar ~
23490 \SpecialChar ~
23491 \SpecialChar ~
23492 \SpecialChar ~
23493 \SpecialChar ~
23494 Toggles Sdcdbsrc mode (turns it off) 
23495 \newline 
23496 ;; 
23497 \newline 
23498 ;;\SpecialChar ~
23499 C-c\SpecialChar ~
23500 C-f\SpecialChar ~
23501 \SpecialChar ~
23502 \SpecialChar ~
23503 \SpecialChar ~
23504 \SpecialChar ~
23505 \SpecialChar ~
23506 \SpecialChar ~
23507 \SpecialChar ~
23508 \SpecialChar ~
23509 sdcdb-finish-from-src\SpecialChar ~
23510 \SpecialChar ~
23511 \SpecialChar ~
23512 \SpecialChar ~
23513 \SpecialChar ~
23514 \SpecialChar ~
23515 \SpecialChar ~
23516 \SpecialChar ~
23517 SDCDB finish command 
23518 \newline 
23519 ;; 
23520 \newline 
23521 ;;\SpecialChar ~
23522 C-x\SpecialChar ~
23523 SPC\SpecialChar ~
23524 \SpecialChar ~
23525 \SpecialChar ~
23526 \SpecialChar ~
23527 \SpecialChar ~
23528 \SpecialChar ~
23529 \SpecialChar ~
23530 \SpecialChar ~
23531 \SpecialChar ~
23532 sdcdb-break\SpecialChar ~
23533 \SpecialChar ~
23534 \SpecialChar ~
23535 \SpecialChar ~
23536 \SpecialChar ~
23537 \SpecialChar ~
23538 \SpecialChar ~
23539 \SpecialChar ~
23540 \SpecialChar ~
23541 \SpecialChar ~
23542 \SpecialChar ~
23543 \SpecialChar ~
23544 \SpecialChar ~
23545 \SpecialChar ~
23546 \SpecialChar ~
23547 \SpecialChar ~
23548 \SpecialChar ~
23549 \SpecialChar ~
23550 Set break for line with point 
23551 \newline 
23552 ;;\SpecialChar ~
23553 ESC\SpecialChar ~
23554 t\SpecialChar ~
23555 \SpecialChar ~
23556 \SpecialChar ~
23557 \SpecialChar ~
23558 \SpecialChar ~
23559 \SpecialChar ~
23560 \SpecialChar ~
23561 \SpecialChar ~
23562 \SpecialChar ~
23563 \SpecialChar ~
23564 \SpecialChar ~
23565 sdcdbsrc-mode\SpecialChar ~
23566 \SpecialChar ~
23567 \SpecialChar ~
23568 \SpecialChar ~
23569 \SpecialChar ~
23570 \SpecialChar ~
23571 \SpecialChar ~
23572 \SpecialChar ~
23573 \SpecialChar ~
23574 \SpecialChar ~
23575 \SpecialChar ~
23576 \SpecialChar ~
23577 \SpecialChar ~
23578 \SpecialChar ~
23579 \SpecialChar ~
23580 \SpecialChar ~
23581 Toggle Sdcdbsrc mode 
23582 \newline 
23583 ;;\SpecialChar ~
23584 ESC\SpecialChar ~
23585 m\SpecialChar ~
23586 \SpecialChar ~
23587 \SpecialChar ~
23588 \SpecialChar ~
23589 \SpecialChar ~
23590 \SpecialChar ~
23591 \SpecialChar ~
23592 \SpecialChar ~
23593 \SpecialChar ~
23594 \SpecialChar ~
23595 \SpecialChar ~
23596 sdcdbsrc-srcmode\SpecialChar ~
23597 \SpecialChar ~
23598 \SpecialChar ~
23599 \SpecialChar ~
23600 \SpecialChar ~
23601 \SpecialChar ~
23602 \SpecialChar ~
23603 \SpecialChar ~
23604 \SpecialChar ~
23605 \SpecialChar ~
23606 \SpecialChar ~
23607 \SpecialChar ~
23608 \SpecialChar ~
23609 Toggle list mode 
23610 \newline 
23611 ;; 
23612 \newline 
23613
23614 \layout Chapter
23615 \pagebreak_top 
23616 TIPS
23617 \layout Standard
23618
23619 Here are a few guidelines that will help the compiler generate more efficient
23620  code, some of the tips are specific to this compiler others are generally
23621  good programming practice.
23622 \layout Itemize
23623
23624 Use the smallest data type to represent your data-value.
23625  If it is known in advance that the value is going to be less than 256 then
23626  use an 'unsigned char' instead of a 'short' or 'int'.
23627  Please note, that ANSI C requires both signed and unsigned chars to be
23628  promoted to 'signed int'
23629 \begin_inset LatexCommand \index{promotion to signed int}
23630
23631 \end_inset 
23632
23633
23634 \begin_inset Marginal
23635 collapsed true
23636
23637 \layout Standard
23638
23639
23640 \series bold 
23641 \SpecialChar ~
23642 !
23643 \end_inset 
23644
23645  before doing any operation.
23646  This promotion
23647 \begin_inset LatexCommand \index{type promotion}
23648
23649 \end_inset 
23650
23651
23652 \begin_inset LatexCommand \label{type promotion}
23653
23654 \end_inset 
23655
23656  can be omitted, if the result is the same.
23657  The effect of the promotion rules together with the sign-extension is often
23658  surprising:
23659 \begin_deeper 
23660 \layout Verse
23661
23662
23663 \family typewriter 
23664 unsigned char uc = 0xfe;
23665 \newline 
23666 if (uc * uc < 0) /* this is true! */
23667 \newline 
23668 {
23669 \newline 
23670 \SpecialChar ~
23671 \SpecialChar ~
23672 \SpecialChar ~
23673 \SpecialChar ~
23674 ....
23675 \newline 
23676 }
23677 \layout Standard
23678
23679
23680 \family typewriter 
23681 uc * uc
23682 \family default 
23683  is evaluated as 
23684 \family typewriter 
23685 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23686 \family default 
23687 .
23688  
23689 \newline 
23690 Another one:
23691 \layout Verse
23692
23693
23694 \family typewriter 
23695 (unsigned char) -12 / (signed char) -3 = ...
23696 \layout Standard
23697
23698 No, the result is not 4:
23699 \layout Verse
23700
23701
23702 \family typewriter 
23703 (int) (unsigned char) -12 / (int) (signed char) -3 =
23704 \newline 
23705 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23706 \newline 
23707 (int) 0x00f4 / (int) 0xfffd =
23708 \newline 
23709 (int) 0x00f4 / (int) 0xfffd =
23710 \newline 
23711 (int) 244 / (int) -3 =
23712 \newline 
23713 (int) -81 = (int) 0xffaf;
23714 \layout Standard
23715
23716 Don't complain, that gcc gives you a different result.
23717  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23718  Therefore the results are different.
23719 \newline 
23720 From 
23721 \begin_inset Quotes sld
23722 \end_inset 
23723
23724 comp.lang.c FAQ
23725 \begin_inset Quotes srd
23726 \end_inset 
23727
23728 :
23729 \layout Quote
23730
23731
23732 \emph on 
23733 If well-defined overflow characteristics are important and negative values
23734  are not, or if you want to steer clear of sign-extension problems when
23735  manipulating bits or bytes, use one of the corresponding unsigned types.
23736  (Beware when mixing signed and unsigned values in expressions, though.)
23737 \newline 
23738 Although character types (especially unsigned char) can be used as "tiny"
23739  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23740 ble sign extension and increased code size.
23741 \end_deeper 
23742 \layout Itemize
23743
23744 Use unsigned when it is known in advance that the value is not going to
23745  be negative.
23746  This helps especially if you are doing division or multiplication, bit-shifting
23747  or are using an array index.
23748 \layout Itemize
23749
23750 NEVER jump into a LOOP.
23751 \layout Itemize
23752
23753 Declare the variables to be local
23754 \begin_inset LatexCommand \index{local variables}
23755
23756 \end_inset 
23757
23758  whenever possible, especially loop control variables (induction).
23759 \layout Itemize
23760
23761 Have a look at the assembly listing to get a 
23762 \begin_inset Quotes sld
23763 \end_inset 
23764
23765 feeling
23766 \begin_inset Quotes srd
23767 \end_inset 
23768
23769  for the code generation.
23770 \layout Section
23771
23772 Porting code from or to other compilers
23773 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23774
23775 \end_inset 
23776
23777
23778 \layout Itemize
23779
23780 check whether endianness of the compilers differs and adapt where needed.
23781 \layout Itemize
23782
23783 check the device specific header files
23784 \begin_inset LatexCommand \index{Header files}
23785
23786 \end_inset 
23787
23788
23789 \begin_inset LatexCommand \index{Include files}
23790
23791 \end_inset 
23792
23793  for compiler specific syntax.
23794  Eventually include the file <compiler.h
23795 \begin_inset LatexCommand \index{compiler.h (include file)}
23796
23797 \end_inset 
23798
23799
23800 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
23801
23802 \end_inset 
23803
23804  to allow using common header files.
23805  (see f.e.
23806  cc2510fx.h 
23807 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
23808
23809 \end_inset 
23810
23811 ).
23812 \layout Itemize
23813
23814 check whether the startup code contains the correct initialization (watchdog,
23815  peripherals).
23816 \layout Itemize
23817
23818 check whether the sizes of short, int, long match.
23819 \layout Itemize
23820
23821 check if some 16 or 32 bit hardware registers require a specific addressing
23822  order (least significant or most significant byte first) and adapt if needed
23823  (
23824 \emph on 
23825 first
23826 \emph default 
23827  and 
23828 \emph on 
23829 last
23830 \emph default 
23831  relate to time and not to lower/upper memory location here, so this is
23832  
23833 \emph on 
23834 not
23835 \emph default 
23836  the same as endianness).
23837 \layout Itemize
23838
23839 check whether the keyword 
23840 \emph on 
23841 volatile
23842 \emph default 
23843  is used where needed.
23844  The compilers might differ in their optimization characteristics (as different
23845  versions of the same compiler might also use more clever optimizations
23846  this is good idea anyway).
23847  See section 
23848 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
23849
23850 \end_inset 
23851
23852 .
23853 \layout Itemize
23854
23855 check that the compilers are not told to supress warnings.
23856 \layout Itemize
23857
23858 check and convert compiler specific extensions (interrupts, memory areas,
23859  pragmas etc.).
23860 \layout Itemize
23861
23862 check for differences in type promotion.
23863  Especially check for math operations on 
23864 \family typewriter 
23865 char
23866 \family default 
23867  or 
23868 \family typewriter 
23869 unsigned char
23870 \family default 
23871  variables.
23872  For the sake of C99 compatibility SDCC will probably promote these to 
23873 \family typewriter 
23874 int
23875 \family default 
23876  more often than other compilers.
23877  Eventually insert explicit casts to 
23878 \family typewriter 
23879 (char) 
23880 \family default 
23881 or
23882 \family typewriter 
23883  (unsigned char)
23884 \family default 
23885 .
23886  Also check that the ~\SpecialChar ~
23887 operator
23888 \begin_inset LatexCommand \index{\~\/ Operator}
23889
23890 \end_inset 
23891
23892  is not used on 
23893 \family typewriter 
23894 bit
23895 \begin_inset LatexCommand \index{bit}
23896
23897 \end_inset 
23898
23899
23900 \family default 
23901  variables, use the !\SpecialChar ~
23902 operator instead.
23903  See sections 
23904 \begin_inset LatexCommand \ref{type promotion}
23905
23906 \end_inset 
23907
23908  and 
23909 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23910
23911 \end_inset 
23912
23913 .
23914 \layout Itemize
23915
23916 check the assembly code generated for interrupt routines (f.e.
23917  for calls to possibly non-reentrant library functions).
23918 \layout Itemize
23919
23920 check whether timing loops result in proper timing (or preferably consider
23921  a rewrite of the code with timer based delays instead).
23922 \layout Itemize
23923
23924 check for differences in printf parameters (some compilers push (va_arg
23925 \begin_inset LatexCommand \index{vararg, va\_arg}
23926
23927 \end_inset 
23928
23929 ) char variables as 
23930 \family typewriter 
23931 int
23932 \family default 
23933  others push them as 
23934 \family typewriter 
23935 char
23936 \family default 
23937 .
23938  See section 
23939 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23940
23941 \end_inset 
23942
23943 ).
23944 \layout Itemize
23945
23946 check the resulting memory map
23947 \begin_inset LatexCommand \index{Memory map}
23948
23949 \end_inset 
23950
23951 .
23952  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23953 ly idata, pdata, xdata).
23954  Eventually check if unexpected library functions are included.
23955 \layout Section
23956
23957 Tools
23958 \begin_inset LatexCommand \index{Tools}
23959
23960 \end_inset 
23961
23962  included in the distribution
23963 \layout Standard
23964 \align left 
23965
23966 \begin_inset  Tabular
23967 <lyxtabular version="3" rows="12" columns="3">
23968 <features>
23969 <column alignment="left" valignment="top" leftline="true" width="0pt">
23970 <column alignment="left" valignment="top" leftline="true" width="0pt">
23971 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23972 <row topline="true" bottomline="true">
23973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23974 \begin_inset Text
23975
23976 \layout Standard
23977
23978
23979 \series bold 
23980 Name
23981 \end_inset 
23982 </cell>
23983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23984 \begin_inset Text
23985
23986 \layout Standard
23987
23988
23989 \series bold 
23990 Purpose
23991 \end_inset 
23992 </cell>
23993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23994 \begin_inset Text
23995
23996 \layout Standard
23997
23998
23999 \series bold 
24000 Directory
24001 \end_inset 
24002 </cell>
24003 </row>
24004 <row topline="true">
24005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24006 \begin_inset Text
24007
24008 \layout Standard
24009
24010 ucSsim
24011 \end_inset 
24012 </cell>
24013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24014 \begin_inset Text
24015
24016 \layout Standard
24017
24018 Simulator for various architectures
24019 \end_inset 
24020 </cell>
24021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24022 \begin_inset Text
24023
24024 \layout Standard
24025
24026 sdcc/sim/ucsim
24027 \end_inset 
24028 </cell>
24029 </row>
24030 <row topline="true">
24031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24032 \begin_inset Text
24033
24034 \layout Standard
24035
24036 keil2sdcc.pl
24037 \end_inset 
24038 </cell>
24039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24040 \begin_inset Text
24041
24042 \layout Standard
24043
24044 header file
24045 \begin_inset LatexCommand \index{Header files}
24046
24047 \end_inset 
24048
24049
24050 \begin_inset LatexCommand \index{Include files}
24051
24052 \end_inset 
24053
24054  conversion
24055 \end_inset 
24056 </cell>
24057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24058 \begin_inset Text
24059
24060 \layout Standard
24061
24062 sdcc/support/scripts
24063 \end_inset 
24064 </cell>
24065 </row>
24066 <row topline="true">
24067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24068 \begin_inset Text
24069
24070 \layout Standard
24071
24072 mh2h.c
24073 \end_inset 
24074 </cell>
24075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24076 \begin_inset Text
24077
24078 \layout Standard
24079
24080 header file conversion
24081 \end_inset 
24082 </cell>
24083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24084 \begin_inset Text
24085
24086 \layout Standard
24087
24088 sdcc/support/scripts
24089 \end_inset 
24090 </cell>
24091 </row>
24092 <row topline="true">
24093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24094 \begin_inset Text
24095
24096 \layout Standard
24097
24098 as-gbz80
24099 \end_inset 
24100 </cell>
24101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24102 \begin_inset Text
24103
24104 \layout Standard
24105
24106 Assembler
24107 \end_inset 
24108 </cell>
24109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24110 \begin_inset Text
24111
24112 \layout Standard
24113
24114
24115 \family roman 
24116 \series medium 
24117 \shape up 
24118 \size normal 
24119 \emph off 
24120 \bar no 
24121 \noun off 
24122 \color none
24123 sdcc/bin
24124 \end_inset 
24125 </cell>
24126 </row>
24127 <row topline="true">
24128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24129 \begin_inset Text
24130
24131 \layout Standard
24132
24133 as-z80
24134 \end_inset 
24135 </cell>
24136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24137 \begin_inset Text
24138
24139 \layout Standard
24140
24141 Assembler
24142 \end_inset 
24143 </cell>
24144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24145 \begin_inset Text
24146
24147 \layout Standard
24148
24149
24150 \family roman 
24151 \series medium 
24152 \shape up 
24153 \size normal 
24154 \emph off 
24155 \bar no 
24156 \noun off 
24157 \color none
24158 sdcc/bin
24159 \end_inset 
24160 </cell>
24161 </row>
24162 <row topline="true">
24163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24164 \begin_inset Text
24165
24166 \layout Standard
24167
24168 asx8051
24169 \end_inset 
24170 </cell>
24171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24172 \begin_inset Text
24173
24174 \layout Standard
24175
24176 Assembler
24177 \end_inset 
24178 </cell>
24179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24180 \begin_inset Text
24181
24182 \layout Standard
24183
24184
24185 \family roman 
24186 \series medium 
24187 \shape up 
24188 \size normal 
24189 \emph off 
24190 \bar no 
24191 \noun off 
24192 \color none
24193 sdcc/bin
24194 \end_inset 
24195 </cell>
24196 </row>
24197 <row topline="true">
24198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24199 \begin_inset Text
24200
24201 \layout Standard
24202
24203 SDCDB
24204 \end_inset 
24205 </cell>
24206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24207 \begin_inset Text
24208
24209 \layout Standard
24210
24211 Simulator
24212 \end_inset 
24213 </cell>
24214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24215 \begin_inset Text
24216
24217 \layout Standard
24218
24219
24220 \family roman 
24221 \series medium 
24222 \shape up 
24223 \size normal 
24224 \emph off 
24225 \bar no 
24226 \noun off 
24227 \color none
24228 sdcc/bin
24229 \end_inset 
24230 </cell>
24231 </row>
24232 <row topline="true">
24233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24234 \begin_inset Text
24235
24236 \layout Standard
24237
24238 aslink
24239 \end_inset 
24240 </cell>
24241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24242 \begin_inset Text
24243
24244 \layout Standard
24245
24246 Linker
24247 \end_inset 
24248 </cell>
24249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24250 \begin_inset Text
24251
24252 \layout Standard
24253
24254
24255 \family roman 
24256 \series medium 
24257 \shape up 
24258 \size normal 
24259 \emph off 
24260 \bar no 
24261 \noun off 
24262 \color none
24263 sdcc/bin
24264 \end_inset 
24265 </cell>
24266 </row>
24267 <row topline="true">
24268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24269 \begin_inset Text
24270
24271 \layout Standard
24272
24273 link-z80
24274 \end_inset 
24275 </cell>
24276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24277 \begin_inset Text
24278
24279 \layout Standard
24280
24281 Linker
24282 \end_inset 
24283 </cell>
24284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24285 \begin_inset Text
24286
24287 \layout Standard
24288
24289
24290 \family roman 
24291 \series medium 
24292 \shape up 
24293 \size normal 
24294 \emph off 
24295 \bar no 
24296 \noun off 
24297 \color none
24298 sdcc/bin
24299 \end_inset 
24300 </cell>
24301 </row>
24302 <row topline="true">
24303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24304 \begin_inset Text
24305
24306 \layout Standard
24307
24308 link-gbz80
24309 \end_inset 
24310 </cell>
24311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24312 \begin_inset Text
24313
24314 \layout Standard
24315
24316 Linker
24317 \end_inset 
24318 </cell>
24319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24320 \begin_inset Text
24321
24322 \layout Standard
24323
24324
24325 \family roman 
24326 \series medium 
24327 \shape up 
24328 \size normal 
24329 \emph off 
24330 \bar no 
24331 \noun off 
24332 \color none
24333 sdcc/bin
24334 \end_inset 
24335 </cell>
24336 </row>
24337 <row topline="true" bottomline="true">
24338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24339 \begin_inset Text
24340
24341 \layout Standard
24342
24343 packihx
24344 \end_inset 
24345 </cell>
24346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24347 \begin_inset Text
24348
24349 \layout Standard
24350
24351 Intel Hex packer 
24352 \begin_inset LatexCommand \index{packihx (tool)}
24353
24354 \end_inset 
24355
24356
24357 \end_inset 
24358 </cell>
24359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24360 \begin_inset Text
24361
24362 \layout Standard
24363
24364
24365 \family roman 
24366 \series medium 
24367 \shape up 
24368 \size normal 
24369 \emph off 
24370 \bar no 
24371 \noun off 
24372 \color none
24373 sdcc/bin
24374 \end_inset 
24375 </cell>
24376 </row>
24377 </lyxtabular>
24378
24379 \end_inset 
24380
24381
24382 \newline 
24383
24384 \layout Section
24385
24386 Documentation
24387 \begin_inset LatexCommand \index{Documentation}
24388
24389 \end_inset 
24390
24391  included in the distribution
24392 \layout Standard
24393 \align left 
24394
24395 \begin_inset  Tabular
24396 <lyxtabular version="3" rows="10" columns="2">
24397 <features>
24398 <column alignment="block" valignment="top" leftline="true" width="40col%">
24399 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
24400 <row topline="true" bottomline="true" endhead="true">
24401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24402 \begin_inset Text
24403
24404 \layout Standard
24405
24406
24407 \series bold 
24408 Subject / Title
24409 \end_inset 
24410 </cell>
24411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24412 \begin_inset Text
24413
24414 \layout Standard
24415
24416
24417 \series bold 
24418 Filename / Where to get
24419 \end_inset 
24420 </cell>
24421 </row>
24422 <row topline="true">
24423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24424 \begin_inset Text
24425
24426 \layout Standard
24427
24428 SDCC Compiler User Guide
24429 \end_inset 
24430 </cell>
24431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24432 \begin_inset Text
24433
24434 \layout Standard
24435
24436 You're reading it right now
24437 \emph on 
24438  \SpecialChar ~
24439 \SpecialChar ~
24440 \SpecialChar ~
24441
24442 \hfill 
24443 online at:
24444 \emph default 
24445
24446 \newline 
24447
24448 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
24449
24450 \end_inset 
24451
24452
24453 \end_inset 
24454 </cell>
24455 </row>
24456 <row topline="true">
24457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24458 \begin_inset Text
24459
24460 \layout Standard
24461
24462 Changelog of SDCC
24463 \end_inset 
24464 </cell>
24465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24466 \begin_inset Text
24467
24468 \layout Standard
24469
24470 sdcc/Changelog
24471 \emph on 
24472  \SpecialChar ~
24473 \SpecialChar ~
24474 \SpecialChar ~
24475
24476 \hfill 
24477 online at:
24478 \emph default 
24479
24480 \newline 
24481
24482 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
24483
24484 \end_inset 
24485
24486
24487 \end_inset 
24488 </cell>
24489 </row>
24490 <row topline="true">
24491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24492 \begin_inset Text
24493
24494 \layout Standard
24495
24496 ASXXXX
24497 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
24498
24499 \end_inset 
24500
24501
24502 \begin_inset LatexCommand \index{Assembler documentation}
24503
24504 \end_inset 
24505
24506  Assemblers and
24507 \newline 
24508 ASLINK
24509 \begin_inset LatexCommand \index{aslink}
24510
24511 \end_inset 
24512
24513
24514 \begin_inset LatexCommand \index{Linker documentation}
24515
24516 \end_inset 
24517
24518  Relocating Linker
24519 \end_inset 
24520 </cell>
24521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24522 \begin_inset Text
24523
24524 \layout Standard
24525
24526 sdcc/as/doc/asxhtm.html 
24527 \emph on 
24528 \SpecialChar ~
24529 \SpecialChar ~
24530 \SpecialChar ~
24531
24532 \hfill 
24533 online at:
24534 \emph default 
24535
24536 \newline 
24537
24538 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
24539
24540 \end_inset 
24541
24542
24543 \end_inset 
24544 </cell>
24545 </row>
24546 <row topline="true">
24547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24548 \begin_inset Text
24549
24550 \layout Standard
24551
24552 SDCC regression test
24553 \begin_inset LatexCommand \index{Regression test}
24554
24555 \end_inset 
24556
24557
24558 \end_inset 
24559 </cell>
24560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24561 \begin_inset Text
24562
24563 \layout Standard
24564
24565 sdcc/doc/test_suite_spec.pdf 
24566 \emph on 
24567 \SpecialChar ~
24568 \SpecialChar ~
24569 \SpecialChar ~
24570
24571 \hfill 
24572 online at:
24573 \emph default 
24574
24575 \newline 
24576
24577 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
24578
24579 \end_inset 
24580
24581
24582 \end_inset 
24583 </cell>
24584 </row>
24585 <row topline="true">
24586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24587 \begin_inset Text
24588
24589 \layout Standard
24590
24591 Various notes
24592 \end_inset 
24593 </cell>
24594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24595 \begin_inset Text
24596
24597 \layout Standard
24598
24599 sdcc/doc/* 
24600 \emph on 
24601 \SpecialChar ~
24602 \SpecialChar ~
24603 \SpecialChar ~
24604
24605 \hfill 
24606 online at:
24607 \emph default 
24608
24609 \newline 
24610
24611 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
24612
24613 \end_inset 
24614
24615
24616 \end_inset 
24617 </cell>
24618 </row>
24619 <row topline="true">
24620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24621 \begin_inset Text
24622
24623 \layout Standard
24624
24625 Notes on debugging with SDCDB
24626 \begin_inset LatexCommand \index{SDCDB (debugger)}
24627
24628 \end_inset 
24629
24630
24631 \end_inset 
24632 </cell>
24633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24634 \begin_inset Text
24635
24636 \layout Standard
24637
24638 sdcc/debugger/README 
24639 \emph on 
24640 \SpecialChar ~
24641 \SpecialChar ~
24642 \SpecialChar ~
24643
24644 \hfill 
24645 online at
24646 \emph default 
24647 :
24648 \newline 
24649
24650 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
24651
24652 \end_inset 
24653
24654
24655 \end_inset 
24656 </cell>
24657 </row>
24658 <row topline="true">
24659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24660 \begin_inset Text
24661
24662 \layout Standard
24663
24664 Software simulator for microcontrollers
24665 \end_inset 
24666 </cell>
24667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24668 \begin_inset Text
24669
24670 \layout Standard
24671
24672
24673 \family roman 
24674 \series medium 
24675 \shape up 
24676 \size normal 
24677 \emph off 
24678 \bar no 
24679 \noun off 
24680 \color none
24681 sdcc/sim/ucsim/doc
24682 \family default 
24683 \series default 
24684 \shape default 
24685 \size default 
24686 \emph default 
24687 \bar default 
24688 \noun default 
24689 \color default
24690 /index.html 
24691 \emph on 
24692 \SpecialChar ~
24693 \SpecialChar ~
24694 \SpecialChar ~
24695
24696 \hfill 
24697 online at:
24698 \emph default 
24699
24700 \newline 
24701
24702 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
24703
24704 \end_inset 
24705
24706
24707 \end_inset 
24708 </cell>
24709 </row>
24710 <row topline="true">
24711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24712 \begin_inset Text
24713
24714 \layout Standard
24715
24716 Temporary notes on the pic16
24717 \begin_inset LatexCommand \index{PIC16}
24718
24719 \end_inset 
24720
24721  port
24722 \end_inset 
24723 </cell>
24724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24725 \begin_inset Text
24726
24727 \layout Standard
24728
24729 sdcc/src/pic16/NOTES 
24730 \emph on 
24731 \SpecialChar ~
24732 \SpecialChar ~
24733 \SpecialChar ~
24734
24735 \hfill 
24736 online at:
24737 \newline 
24738
24739 \emph default 
24740
24741 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
24742
24743 \end_inset 
24744
24745
24746 \end_inset 
24747 </cell>
24748 </row>
24749 <row topline="true" bottomline="true">
24750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24751 \begin_inset Text
24752
24753 \layout Standard
24754
24755 SDCC internal documentation (debugging file format)
24756 \end_inset 
24757 </cell>
24758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24759 \begin_inset Text
24760
24761 \layout Standard
24762
24763 sdcc/doc/
24764 \family roman 
24765 \series medium 
24766 \shape up 
24767 \size normal 
24768 \emph off 
24769 \bar no 
24770 \noun off 
24771 \color none
24772 cdbfileformat.pd
24773 \family default 
24774 \series default 
24775 \shape default 
24776 \size default 
24777 \emph default 
24778 \bar default 
24779 \noun default 
24780 \color default
24781 f
24782 \emph on 
24783  \SpecialChar ~
24784 \SpecialChar ~
24785 \SpecialChar ~
24786
24787 \hfill 
24788 online at:
24789 \emph default 
24790
24791 \newline 
24792
24793 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
24794
24795 \end_inset 
24796
24797
24798 \end_inset 
24799 </cell>
24800 </row>
24801 </lyxtabular>
24802
24803 \end_inset 
24804
24805
24806 \newline 
24807
24808 \layout Section
24809
24810 Related open source tools
24811 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24812
24813 \end_inset 
24814
24815
24816 \begin_inset LatexCommand \index{Related tools}
24817
24818 \end_inset 
24819
24820
24821 \layout Standard
24822 \align left 
24823
24824 \begin_inset  Tabular
24825 <lyxtabular version="3" rows="14" columns="3">
24826 <features>
24827 <column alignment="left" valignment="top" leftline="true" width="0pt">
24828 <column alignment="block" valignment="top" leftline="true" width="30line%">
24829 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24830 <row topline="true" bottomline="true">
24831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24832 \begin_inset Text
24833
24834 \layout Standard
24835
24836
24837 \series bold 
24838 Name
24839 \end_inset 
24840 </cell>
24841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24842 \begin_inset Text
24843
24844 \layout Standard
24845
24846
24847 \series bold 
24848 Purpose
24849 \end_inset 
24850 </cell>
24851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24852 \begin_inset Text
24853
24854 \layout Standard
24855
24856
24857 \series bold 
24858 Where to get
24859 \end_inset 
24860 </cell>
24861 </row>
24862 <row topline="true">
24863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24864 \begin_inset Text
24865
24866 \layout Standard
24867
24868 gpsim
24869 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24870
24871 \end_inset 
24872
24873
24874 \end_inset 
24875 </cell>
24876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24877 \begin_inset Text
24878
24879 \layout Standard
24880
24881 PIC simulator
24882 \end_inset 
24883 </cell>
24884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24885 \begin_inset Text
24886
24887 \layout Standard
24888
24889
24890 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24891
24892 \end_inset 
24893
24894
24895 \end_inset 
24896 </cell>
24897 </row>
24898 <row topline="true">
24899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24900 \begin_inset Text
24901
24902 \layout Standard
24903
24904 gputils
24905 \begin_inset LatexCommand \index{gputils (pic tools)}
24906
24907 \end_inset 
24908
24909
24910 \end_inset 
24911 </cell>
24912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24913 \begin_inset Text
24914
24915 \layout Standard
24916
24917 GNU PIC utilities
24918 \end_inset 
24919 </cell>
24920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24921 \begin_inset Text
24922
24923 \layout Standard
24924
24925
24926 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24927
24928 \end_inset 
24929
24930
24931 \end_inset 
24932 </cell>
24933 </row>
24934 <row topline="true">
24935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24936 \begin_inset Text
24937
24938 \layout Standard
24939
24940 flP5
24941 \end_inset 
24942 </cell>
24943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24944 \begin_inset Text
24945
24946 \layout Standard
24947
24948 PIC programmer
24949 \end_inset 
24950 </cell>
24951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24952 \begin_inset Text
24953
24954 \layout Standard
24955
24956
24957 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24958
24959 \end_inset 
24960
24961
24962 \end_inset 
24963 </cell>
24964 </row>
24965 <row topline="true">
24966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24967 \begin_inset Text
24968
24969 \layout Standard
24970
24971 ec2drv/newcdb
24972 \end_inset 
24973 </cell>
24974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24975 \begin_inset Text
24976
24977 \layout Standard
24978
24979 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24980  (Unix only)
24981 \end_inset 
24982 </cell>
24983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24984 \begin_inset Text
24985
24986 \layout Standard
24987
24988
24989 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24990
24991 \end_inset 
24992
24993
24994 \end_inset 
24995 </cell>
24996 </row>
24997 <row topline="true">
24998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24999 \begin_inset Text
25000
25001 \layout Standard
25002
25003 indent
25004 \begin_inset LatexCommand \index{indent (source formatting tool)}
25005
25006 \end_inset 
25007
25008
25009 \end_inset 
25010 </cell>
25011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25012 \begin_inset Text
25013
25014 \layout Standard
25015
25016 Formats C source - Master of the white spaces
25017 \end_inset 
25018 </cell>
25019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25020 \begin_inset Text
25021
25022 \layout Standard
25023
25024
25025 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
25026
25027 \end_inset 
25028
25029
25030 \end_inset 
25031 </cell>
25032 </row>
25033 <row topline="true">
25034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25035 \begin_inset Text
25036
25037 \layout Standard
25038
25039 srecord
25040 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
25041
25042 \end_inset 
25043
25044
25045 \end_inset 
25046 </cell>
25047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25048 \begin_inset Text
25049
25050 \layout Standard
25051
25052 Object file conversion, checksumming, ...
25053 \end_inset 
25054 </cell>
25055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25056 \begin_inset Text
25057
25058 \layout Standard
25059
25060
25061 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
25062
25063 \end_inset 
25064
25065
25066 \end_inset 
25067 </cell>
25068 </row>
25069 <row topline="true">
25070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25071 \begin_inset Text
25072
25073 \layout Standard
25074
25075 objdump
25076 \begin_inset LatexCommand \index{objdump (tool)}
25077
25078 \end_inset 
25079
25080
25081 \end_inset 
25082 </cell>
25083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25084 \begin_inset Text
25085
25086 \layout Standard
25087
25088 Object file conversion, ...
25089 \end_inset 
25090 </cell>
25091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25092 \begin_inset Text
25093
25094 \layout Standard
25095
25096 Part of binutils (should be there anyway)
25097 \end_inset 
25098 </cell>
25099 </row>
25100 <row topline="true">
25101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25102 \begin_inset Text
25103
25104 \layout Standard
25105
25106 cmon51
25107 \end_inset 
25108 </cell>
25109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25110 \begin_inset Text
25111
25112 \layout Standard
25113
25114 8051 monitor (hex up-/download, single step, disassemble)
25115 \end_inset 
25116 </cell>
25117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25118 \begin_inset Text
25119
25120 \layout Standard
25121
25122
25123 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
25124
25125 \end_inset 
25126
25127
25128 \end_inset 
25129 </cell>
25130 </row>
25131 <row topline="true">
25132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25133 \begin_inset Text
25134
25135 \layout Standard
25136
25137 doxygen
25138 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
25139
25140 \end_inset 
25141
25142
25143 \end_inset 
25144 </cell>
25145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25146 \begin_inset Text
25147
25148 \layout Standard
25149
25150 Source code documentation system
25151 \end_inset 
25152 </cell>
25153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25154 \begin_inset Text
25155
25156 \layout Standard
25157
25158
25159 \begin_inset LatexCommand \url{http://www.doxygen.org}
25160
25161 \end_inset 
25162
25163
25164 \end_inset 
25165 </cell>
25166 </row>
25167 <row topline="true">
25168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25169 \begin_inset Text
25170
25171 \layout Standard
25172
25173 kdevelop
25174 \end_inset 
25175 </cell>
25176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25177 \begin_inset Text
25178
25179 \layout Standard
25180
25181 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
25182 \end_inset 
25183 </cell>
25184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25185 \begin_inset Text
25186
25187 \layout Standard
25188
25189
25190 \begin_inset LatexCommand \url{http://www.kdevelop.org}
25191
25192 \end_inset 
25193
25194
25195 \end_inset 
25196 </cell>
25197 </row>
25198 <row topline="true">
25199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25200 \begin_inset Text
25201
25202 \layout Standard
25203
25204 paulmon
25205 \end_inset 
25206 </cell>
25207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25208 \begin_inset Text
25209
25210 \layout Standard
25211
25212 8051 monitor (hex up-/download, single step, disassemble)
25213 \end_inset 
25214 </cell>
25215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25216 \begin_inset Text
25217
25218 \layout Standard
25219
25220
25221 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
25222
25223 \end_inset 
25224
25225
25226 \end_inset 
25227 </cell>
25228 </row>
25229 <row topline="true">
25230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25231 \begin_inset Text
25232
25233 \layout Standard
25234
25235 splint
25236 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25237
25238 \end_inset 
25239
25240
25241 \end_inset 
25242 </cell>
25243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25244 \begin_inset Text
25245
25246 \layout Standard
25247
25248 Statically checks c sources (see 
25249 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25250
25251 \end_inset 
25252
25253 )
25254 \end_inset 
25255 </cell>
25256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25257 \begin_inset Text
25258
25259 \layout Standard
25260
25261
25262 \begin_inset LatexCommand \url{http://www.splint.org}
25263
25264 \end_inset 
25265
25266
25267 \end_inset 
25268 </cell>
25269 </row>
25270 <row topline="true" bottomline="true">
25271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25272 \begin_inset Text
25273
25274 \layout Standard
25275
25276 ddd
25277 \begin_inset LatexCommand \index{DDD (debugger)}
25278
25279 \end_inset 
25280
25281
25282 \end_inset 
25283 </cell>
25284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25285 \begin_inset Text
25286
25287 \layout Standard
25288
25289 Debugger, serves nicely as GUI to SDCDB
25290 \begin_inset LatexCommand \index{SDCDB (debugger)}
25291
25292 \end_inset 
25293
25294  (Unix only)
25295 \end_inset 
25296 </cell>
25297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25298 \begin_inset Text
25299
25300 \layout Standard
25301
25302
25303 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
25304
25305 \end_inset 
25306
25307
25308 \end_inset 
25309 </cell>
25310 </row>
25311 </lyxtabular>
25312
25313 \end_inset 
25314
25315
25316 \newline 
25317
25318 \layout Section
25319
25320 Related documentation / recommended reading
25321 \layout Standard
25322 \align left 
25323
25324 \begin_inset  Tabular
25325 <lyxtabular version="3" rows="7" columns="3">
25326 <features>
25327 <column alignment="left" valignment="top" leftline="true" width="0pt">
25328 <column alignment="left" valignment="top" leftline="true" width="0">
25329 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25330 <row topline="true" bottomline="true">
25331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25332 \begin_inset Text
25333
25334 \layout Standard
25335
25336
25337 \series bold 
25338 Name
25339 \end_inset 
25340 </cell>
25341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25342 \begin_inset Text
25343
25344 \layout Standard
25345
25346
25347 \series bold 
25348 Subject / Title
25349 \end_inset 
25350 </cell>
25351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25352 \begin_inset Text
25353
25354 \layout Standard
25355
25356
25357 \series bold 
25358 Where to get
25359 \end_inset 
25360 </cell>
25361 </row>
25362 <row topline="true">
25363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25364 \begin_inset Text
25365
25366 \layout Standard
25367
25368
25369 \family roman 
25370 \series medium 
25371 \shape up 
25372 \size normal 
25373 \emph off 
25374 \bar no 
25375 \noun off 
25376 \color none
25377 c-refcard.pdf
25378 \end_inset 
25379 </cell>
25380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25381 \begin_inset Text
25382
25383 \layout Standard
25384
25385 C Reference Card
25386 \begin_inset LatexCommand \index{C Reference card}
25387
25388 \end_inset 
25389
25390 , 2 pages
25391 \end_inset 
25392 </cell>
25393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25394 \begin_inset Text
25395
25396 \layout Standard
25397
25398
25399 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
25400
25401 \end_inset 
25402
25403
25404 \end_inset 
25405 </cell>
25406 </row>
25407 <row topline="true">
25408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25409 \begin_inset Text
25410
25411 \layout Standard
25412
25413 c-faq
25414 \end_inset 
25415 </cell>
25416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25417 \begin_inset Text
25418
25419 \layout Standard
25420
25421 C-FAQ
25422 \begin_inset LatexCommand \index{C FAQ}
25423
25424 \end_inset 
25425
25426
25427 \end_inset 
25428 </cell>
25429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25430 \begin_inset Text
25431
25432 \layout Standard
25433
25434
25435 \begin_inset LatexCommand \url{http://www.c-faq.com}
25436
25437 \end_inset 
25438
25439
25440 \end_inset 
25441 </cell>
25442 </row>
25443 <row topline="true">
25444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25445 \begin_inset Text
25446
25447 \layout Standard
25448
25449 ISO/IEC 9899:TC2
25450 \end_inset 
25451 </cell>
25452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25453 \begin_inset Text
25454
25455 \layout Standard
25456
25457
25458 \begin_inset Quotes sld
25459 \end_inset 
25460
25461 C-Standard
25462 \begin_inset Quotes srd
25463 \end_inset 
25464
25465
25466 \end_inset 
25467 </cell>
25468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25469 \begin_inset Text
25470
25471 \layout Standard
25472
25473
25474 \size footnotesize 
25475
25476 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
25477
25478 \end_inset 
25479
25480
25481 \end_inset 
25482 </cell>
25483 </row>
25484 <row topline="true">
25485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25486 \begin_inset Text
25487
25488 \layout Standard
25489
25490 ISO/IEC DTR 18037
25491 \end_inset 
25492 </cell>
25493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25494 \begin_inset Text
25495
25496 \layout Standard
25497
25498
25499 \begin_inset Quotes sld
25500 \end_inset 
25501
25502 Extensions for Embedded C
25503 \begin_inset Quotes srd
25504 \end_inset 
25505
25506
25507 \end_inset 
25508 </cell>
25509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25510 \begin_inset Text
25511
25512 \layout Standard
25513
25514
25515 \size footnotesize 
25516
25517 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
25518
25519 \end_inset 
25520
25521
25522 \end_inset 
25523 </cell>
25524 </row>
25525 <row topline="true">
25526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25527 \begin_inset Text
25528
25529 \layout Standard
25530
25531 \end_inset 
25532 </cell>
25533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25534 \begin_inset Text
25535
25536 \layout Standard
25537
25538 Latest datasheet of target CPU
25539 \end_inset 
25540 </cell>
25541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25542 \begin_inset Text
25543
25544 \layout Standard
25545
25546 vendor
25547 \end_inset 
25548 </cell>
25549 </row>
25550 <row topline="true" bottomline="true">
25551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25552 \begin_inset Text
25553
25554 \layout Standard
25555
25556 \end_inset 
25557 </cell>
25558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25559 \begin_inset Text
25560
25561 \layout Standard
25562
25563 Revision history of datasheet
25564 \end_inset 
25565 </cell>
25566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25567 \begin_inset Text
25568
25569 \layout Standard
25570
25571 vendor
25572 \end_inset 
25573 </cell>
25574 </row>
25575 </lyxtabular>
25576
25577 \end_inset 
25578
25579
25580 \newline 
25581
25582 \layout Section
25583
25584 Application notes specifically for SDCC
25585 \layout Standard
25586
25587 SDCC makes no claims about the completeness of this list and about up-to-datenes
25588 s or correctness of the application notes
25589 \begin_inset LatexCommand \index{Application notes}
25590
25591 \end_inset 
25592
25593 .
25594 \layout Standard
25595 \align left 
25596
25597 \size footnotesize 
25598
25599 \begin_inset  Tabular
25600 <lyxtabular version="3" rows="7" columns="3">
25601 <features>
25602 <column alignment="block" valignment="top" leftline="true" width="17col%">
25603 <column alignment="block" valignment="top" leftline="true" width="27col%">
25604 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
25605 <row topline="true" bottomline="true">
25606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25607 \begin_inset Text
25608
25609 \layout Standard
25610
25611
25612 \series bold 
25613 \size footnotesize 
25614 Vendor
25615 \end_inset 
25616 </cell>
25617 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25618 \begin_inset Text
25619
25620 \layout Standard
25621
25622
25623 \series bold 
25624 \size footnotesize 
25625 Subject / Title
25626 \end_inset 
25627 </cell>
25628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25629 \begin_inset Text
25630
25631 \layout Standard
25632
25633
25634 \series bold 
25635 \size footnotesize 
25636 Where to get
25637 \end_inset 
25638 </cell>
25639 </row>
25640 <row topline="true">
25641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25642 \begin_inset Text
25643
25644 \layout Standard
25645
25646
25647 \size footnotesize 
25648 Maxim / Dallas
25649 \end_inset 
25650 </cell>
25651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25652 \begin_inset Text
25653
25654 \layout Standard
25655
25656
25657 \size footnotesize 
25658 Using the SDCC Compiler for the DS80C400
25659 \begin_inset LatexCommand \index{DS80C400}
25660
25661 \end_inset 
25662
25663
25664 \end_inset 
25665 </cell>
25666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25667 \begin_inset Text
25668
25669 \layout Standard
25670
25671
25672 \size footnotesize 
25673
25674 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25675
25676 \end_inset 
25677
25678
25679 \end_inset 
25680 </cell>
25681 </row>
25682 <row topline="true">
25683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25684 \begin_inset Text
25685
25686 \layout Standard
25687
25688
25689 \size footnotesize 
25690 Maxim / Dallas
25691 \end_inset 
25692 </cell>
25693 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25694 \begin_inset Text
25695
25696 \layout Standard
25697
25698
25699 \size footnotesize 
25700 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25701 \begin_inset LatexCommand \index{DS89C4x0}
25702
25703 \end_inset 
25704
25705  Family of Microcontrollers
25706 \end_inset 
25707 </cell>
25708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25709 \begin_inset Text
25710
25711 \layout Standard
25712
25713
25714 \size footnotesize 
25715
25716 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25717
25718 \end_inset 
25719
25720
25721 \end_inset 
25722 </cell>
25723 </row>
25724 <row topline="true">
25725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25726 \begin_inset Text
25727
25728 \layout Standard
25729
25730
25731 \size footnotesize 
25732 Silicon Laboratories / Cygnal
25733 \end_inset 
25734 </cell>
25735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25736 \begin_inset Text
25737
25738 \layout Standard
25739
25740
25741 \size footnotesize 
25742 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25743 \begin_inset LatexCommand \index{IDE}
25744
25745 \end_inset 
25746
25747
25748 \end_inset 
25749 </cell>
25750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25751 \begin_inset Text
25752
25753 \layout Standard
25754
25755
25756 \size footnotesize 
25757
25758 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
25759
25760 \end_inset 
25761
25762
25763 \end_inset 
25764 </cell>
25765 </row>
25766 <row topline="true">
25767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25768 \begin_inset Text
25769
25770 \layout Standard
25771
25772
25773 \size footnotesize 
25774 Ramtron / Goal Semiconductor
25775 \end_inset 
25776 </cell>
25777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25778 \begin_inset Text
25779
25780 \layout Standard
25781
25782
25783 \size footnotesize 
25784 Interfacing SDCC to Syn and Textpad
25785 \end_inset 
25786 </cell>
25787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25788 \begin_inset Text
25789
25790 \layout Standard
25791
25792
25793 \size footnotesize 
25794
25795 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25796
25797 \end_inset 
25798
25799
25800 \end_inset 
25801 </cell>
25802 </row>
25803 <row topline="true">
25804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25805 \begin_inset Text
25806
25807 \layout Standard
25808
25809
25810 \size footnotesize 
25811 Ramtron / Goal Semiconductor
25812 \end_inset 
25813 </cell>
25814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25815 \begin_inset Text
25816
25817 \layout Standard
25818
25819
25820 \size footnotesize 
25821 Installing and Configuring SDCC and Crimson Editor 
25822 \end_inset 
25823 </cell>
25824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25825 \begin_inset Text
25826
25827 \layout Standard
25828
25829
25830 \size footnotesize 
25831
25832 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25833
25834 \end_inset 
25835
25836
25837 \end_inset 
25838 </cell>
25839 </row>
25840 <row topline="true" bottomline="true">
25841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25842 \begin_inset Text
25843
25844 \layout Standard
25845
25846
25847 \size footnotesize 
25848 Texas Instruments
25849 \end_inset 
25850 </cell>
25851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25852 \begin_inset Text
25853
25854 \layout Standard
25855
25856
25857 \size footnotesize 
25858 MSC12xx Programming with SDCC
25859 \end_inset 
25860 </cell>
25861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25862 \begin_inset Text
25863
25864 \layout Standard
25865
25866
25867 \size footnotesize 
25868
25869 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25870
25871 \end_inset 
25872
25873
25874 \end_inset 
25875 </cell>
25876 </row>
25877 </lyxtabular>
25878
25879 \end_inset 
25880
25881
25882 \layout Section
25883
25884 Some Questions
25885 \layout Standard
25886
25887 Some questions answered, some pointers given - it might be time to in turn
25888  ask 
25889 \emph on 
25890 you
25891 \emph default 
25892  some questions: 
25893 \layout Itemize
25894
25895 can you solve your project with the selected microcontroller? Would you
25896  find out early or rather late that your target is too small/slow/whatever?
25897  Can you switch to a slightly better device if it doesn't fit?
25898 \layout Itemize
25899
25900 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25901  and/or another programming language be more adequate? Would an operating
25902  system on the target device help?
25903 \layout Itemize
25904
25905 if you solved the problem, will the marketing department be happy?
25906 \layout Itemize
25907
25908 if the marketing department is happy, will customers be happy?
25909 \layout Itemize
25910
25911 if you're the project manager, marketing department and maybe even the customer
25912  in one person, have you tried to see the project from the outside?
25913 \layout Itemize
25914
25915 is the project done if you think it is done? Or is just that other interface/pro
25916 tocol/feature/configuration/option missing? How about website, manual(s),
25917  internationali(z|s)ation, packaging, labels, 2nd source for components,
25918  electromagnetic compatability/interference, documentation for production,
25919  production test software, update mechanism, patent issues?
25920 \layout Itemize
25921
25922 is your project adequately positioned in that magic triangle: fame, fortune,
25923  fun?
25924 \layout Standard
25925
25926 Maybe not all answers to these questions are known and some answers may
25927  even be 
25928 \emph on 
25929 no
25930 \emph default 
25931 , nevertheless knowing these questions may help you to avoid burnout
25932 \begin_inset Foot
25933 collapsed false
25934
25935 \layout Standard
25936
25937 burnout is bad for electronic devices, programmers and motorcycle tyres
25938 \end_inset 
25939
25940 .
25941  Chances are you didn't want to hear some of them...
25942 \layout Chapter
25943
25944 Support
25945 \begin_inset LatexCommand \index{Support}
25946
25947 \end_inset 
25948
25949
25950 \layout Standard
25951
25952 SDCC has grown to be a large project.
25953  The compiler alone (without the preprocessor, assembler and linker) is
25954  well over 150,000 lines of code (blank stripped).
25955  The open source nature of this project is a key to its continued growth
25956  and support.
25957  You gain the benefit and support of many active software developers and
25958  end users.
25959  Is SDCC perfect? No, that's why we need your help.
25960  The developers take pride in fixing reported bugs.
25961  You can help by reporting the bugs and helping other SDCC users.
25962  There are lots of ways to contribute, and we encourage you to take part
25963  in making SDCC a great software package.
25964  
25965 \layout Standard
25966
25967 The SDCC project is hosted on the SDCC sourceforge site at 
25968 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25969
25970 \end_inset 
25971
25972 .
25973  You'll find the complete set of mailing lists
25974 \begin_inset LatexCommand \index{Mailing list(s)}
25975
25976 \end_inset 
25977
25978 , forums, bug reporting system, patch submission
25979 \begin_inset LatexCommand \index{Patch submission}
25980
25981 \end_inset 
25982
25983  system, download
25984 \begin_inset LatexCommand \index{download}
25985
25986 \end_inset 
25987
25988  area and Subversion code repository
25989 \begin_inset LatexCommand \index{Subversion code repository}
25990
25991 \end_inset 
25992
25993  there.
25994 \layout Section
25995
25996 Reporting Bugs
25997 \begin_inset LatexCommand \index{Bug reporting}
25998
25999 \end_inset 
26000
26001
26002 \begin_inset LatexCommand \index{Reporting bugs}
26003
26004 \end_inset 
26005
26006
26007 \layout Standard
26008
26009 The recommended way of reporting bugs is using the infrastructure of the
26010  sourceforge site.
26011  You can follow the status of bug reports there and have an overview about
26012  the known bugs.
26013 \layout Standard
26014
26015 Bug reports are automatically forwarded to the developer mailing list and
26016  will be fixed ASAP.
26017  When reporting a bug, it is very useful to include a small test program
26018  (the smaller the better) which reproduces the problem.
26019  If you can isolate the problem by looking at the generated assembly code,
26020  this can be very helpful.
26021  Compiling your program with the -
26022 \begin_inset ERT
26023 status Collapsed
26024
26025 \layout Standard
26026
26027 \backslash 
26028 /
26029 \end_inset 
26030
26031 -dumpall
26032 \begin_inset LatexCommand \index{-\/-dumpall}
26033
26034 \end_inset 
26035
26036  option can sometimes be useful in locating optimization problems.
26037  When reporting a bug please make sure you:
26038 \layout Enumerate
26039
26040 Attach the code you are compiling with SDCC.
26041  
26042 \layout Enumerate
26043
26044 Specify the exact command you use to run SDCC, or attach your Makefile.
26045  
26046 \layout Enumerate
26047
26048 Specify the SDCC version (type "
26049 \family sans 
26050 \series bold 
26051 sdcc -v
26052 \family default 
26053 \series default 
26054 "), your platform, and operating system.
26055  
26056 \layout Enumerate
26057
26058 Provide an exact copy of any error message or incorrect output.
26059  
26060 \layout Enumerate
26061
26062 Put something meaningful in the subject of your message.
26063 \layout Standard
26064
26065 Please attempt to include these 5 important parts, as applicable, in all
26066  requests for support or when reporting any problems or bugs with SDCC.
26067  Though this will make your message lengthy, it will greatly improve your
26068  chance that SDCC users and developers will be able to help you.
26069  Some SDCC developers are frustrated by bug reports without code provided
26070  that they can use to reproduce and ultimately fix the problem, so please
26071  be sure to provide sample code if you are reporting a bug! 
26072 \layout Standard
26073
26074 Please have a short check that you are using a recent version of SDCC and
26075  the bug is not yet known.
26076  This is the link for reporting bugs: 
26077 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
26078
26079 \end_inset 
26080
26081 .
26082  With SDCC on average having more than 200 downloads
26083 \begin_inset LatexCommand \index{download}
26084
26085 \end_inset 
26086
26087  on sourceforge per day
26088 \begin_inset Foot
26089 collapsed false
26090
26091 \layout Standard
26092
26093 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
26094  between 2002 and 2005.
26095  This does not include other methods of distribution.
26096 \end_inset 
26097
26098  there must be some users.
26099  So it's not exactly easy to find a new bug.
26100  If you find one we need it: 
26101 \emph on 
26102 reporting bugs is good
26103 \emph default 
26104 .
26105 \layout Section
26106
26107 Requesting Features
26108 \begin_inset LatexCommand \label{sub:Requesting-Features}
26109
26110 \end_inset 
26111
26112
26113 \begin_inset LatexCommand \index{Feature request}
26114
26115 \end_inset 
26116
26117
26118 \begin_inset LatexCommand \index{Requesting features}
26119
26120 \end_inset 
26121
26122
26123 \layout Standard
26124
26125 Like bug reports feature requests are forwarded to the developer mailing
26126  list.
26127  This is the link for requesting features: 
26128 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26129
26130 \end_inset 
26131
26132 .
26133 \layout Section
26134
26135 Submitting patches
26136 \layout Standard
26137
26138 Like bug reports contributed patches are forwarded to the developer mailing
26139  list.
26140  This is the link for submitting patches
26141 \begin_inset LatexCommand \index{Patch submission}
26142
26143 \end_inset 
26144
26145
26146 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
26147
26148 \end_inset 
26149
26150 .
26151 \layout Standard
26152
26153 You need to specify some parameters to the 
26154 \family typewriter 
26155 diff
26156 \family default 
26157  command for the patches to be useful.
26158  If you modified more than one file a patch created f.e.
26159  with 
26160 \family sans 
26161 \series bold 
26162
26163 \begin_inset Quotes sld
26164 \end_inset 
26165
26166 diff -Naur unmodified_directory modified_directory >my_changes.patch
26167 \begin_inset Quotes srd
26168 \end_inset 
26169
26170
26171 \family default 
26172 \series default 
26173  will be fine, otherwise 
26174 \family sans 
26175 \series bold 
26176
26177 \begin_inset Quotes sld
26178 \end_inset 
26179
26180 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
26181 \begin_inset Quotes srd
26182 \end_inset 
26183
26184
26185 \series default 
26186  
26187 \family default 
26188 will do.
26189 \layout Section
26190
26191 Getting Help
26192 \layout Standard
26193
26194 These links should take you directly to the 
26195 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
26196
26197 \end_inset 
26198
26199
26200 \begin_inset Foot
26201 collapsed false
26202
26203 \layout Standard
26204
26205 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
26206  automated messages (mid 2003)
26207 \end_inset 
26208
26209  and the 
26210 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
26211
26212 \end_inset 
26213
26214 , lists
26215 \begin_inset LatexCommand \index{Mailing list(s)}
26216
26217 \end_inset 
26218
26219  and forums are archived and searchable so if you are lucky someone already
26220  had a similar problem.
26221  While mails to the lists themselves are delivered promptly their web front
26222  end on sourceforge sometimes shows a severe time lag (up to several weeks),
26223  if you're seriously using SDCC please consider subscribing to the lists.
26224 \layout Section
26225
26226 ChangeLog
26227 \layout Standard
26228
26229 You can follow the status of the Subversion version
26230 \begin_inset LatexCommand \index{version}
26231
26232 \end_inset 
26233
26234  of SDCC by watching the Changelog
26235 \begin_inset LatexCommand \index{Changelog}
26236
26237 \end_inset 
26238
26239  in the Subversion repository
26240 \size footnotesize 
26241  
26242 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26243
26244 \end_inset 
26245
26246 .
26247 \layout Section
26248
26249 Subversion Source Code Repository
26250 \layout Standard
26251
26252 The output of 
26253 \family sans 
26254 \series bold 
26255 sdcc --version
26256 \family default 
26257 \series default 
26258  or the filenames of the snapshot versions of SDCC include date and its
26259  Subversion
26260 \begin_inset LatexCommand \index{Subversion code repository}
26261
26262 \end_inset 
26263
26264  number.
26265  Subversion allows to download the source of recent or previous versions
26266  
26267 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
26268
26269 \end_inset 
26270
26271  (by number or by date).
26272  An on-line source code browser and detailled instructions are also available
26273  there.
26274  SDCC versions starting from 1999 up to now are available (currently the
26275  versions prior to the conversion from cvs
26276 \begin_inset LatexCommand \index{cvs|see{Subversion}}
26277
26278 \end_inset 
26279
26280  to Subversion (April 2006) are either by accessible by Subversion or by
26281  cvs).
26282 \layout Section
26283
26284 Release policy
26285 \begin_inset LatexCommand \index{Release policy}
26286
26287 \end_inset 
26288
26289
26290 \layout Standard
26291
26292 Historically there often were long delays between official releases and
26293  the sourceforge download area tends to get not updated at all.
26294  Excuses in the past might have referred to problems with live range analysis,
26295  but as this was fixed a while ago, the current problem is that another
26296  excuse has to be found.
26297  Kidding aside, we have to get better there! On the other hand there are
26298  daily snapshots available at 
26299 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
26300
26301 \end_inset 
26302
26303 , and you can always build the very last version (hopefully with many bugs
26304  fixed, and features added) from the source code available at 
26305 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
26306
26307 \end_inset 
26308
26309 .
26310  A release wiki
26311 \begin_inset LatexCommand \index{wiki}
26312
26313 \end_inset 
26314
26315
26316 \begin_inset LatexCommand \index{Release wiki}
26317
26318 \end_inset 
26319
26320  at 
26321 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
26322
26323 \end_inset 
26324
26325  also holds some information about past and future releases.
26326 \layout Section
26327
26328 Examples
26329 \begin_inset LatexCommand \index{Examples}
26330
26331 \end_inset 
26332
26333
26334 \layout Standard
26335
26336 You'll find some small examples in the directory 
26337 \emph on 
26338 sdcc/device/examples/.
26339  
26340 \emph default 
26341 More examples and libraries are available at
26342 \emph on 
26343  The SDCC Open Knowledge Resource 
26344 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
26345
26346 \end_inset 
26347
26348  
26349 \emph default 
26350 web site or at 
26351 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
26352
26353 \end_inset 
26354
26355 .
26356 \layout Comment
26357
26358 I did insert a reference to Paul's web site here although it seems rather
26359  dedicated to a specific 8032 board (I think it's okay because it f.e.
26360  shows LCD/Harddisc interface and has a free 8051 monitor.
26361  Independent 8032 board vendors face hard competition of heavily subsidized
26362  development boards anyway).
26363 \layout Comment
26364
26365 Maybe we should include some links to real world applications.
26366  Preferably pointer to pointers (one for each architecture) so this stays
26367  manageable here?
26368 \layout Section
26369
26370 Quality control
26371 \begin_inset LatexCommand \label{sec:Quality-control}
26372
26373 \end_inset 
26374
26375
26376 \begin_inset LatexCommand \index{Quality control}
26377
26378 \end_inset 
26379
26380
26381 \layout Standard
26382
26383 The compiler is passed through nightly compile and build checks.
26384  The so called 
26385 \shape italic 
26386 regression tests
26387 \shape default 
26388
26389 \begin_inset LatexCommand \index{Regression test}
26390
26391 \end_inset 
26392
26393  check that SDCC itself compiles flawlessly on several host platforms (i386,
26394  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
26395  the quality of the code generated by SDCC by running the code for several
26396  target platforms through simulators.
26397  The regression test suite comprises more than 100 files which expand to
26398  more than 500 test cases which include more than 4500 tests.
26399  The results of these tests are published daily on SDCC's snapshot page
26400  (click on the red or green symbols on the right side of 
26401 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
26402
26403 \end_inset 
26404
26405 ).
26406 \layout Standard
26407
26408 There is a separate document 
26409 \shape italic 
26410 test_suite.pdf 
26411 \begin_inset LatexCommand \index{Test suite}
26412
26413 \end_inset 
26414
26415
26416 \shape default 
26417  
26418 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26419
26420 \end_inset 
26421
26422  about the regression test suite.
26423 \layout Standard
26424
26425 You'll find the test code in the directory 
26426 \shape italic 
26427 sdcc/support/regression
26428 \shape default 
26429 .
26430  You can run these tests manually by running 
26431 \family sans 
26432 make
26433 \family default 
26434  in this directory (or f.e.
26435  
26436 \family sans 
26437 \series bold 
26438
26439 \begin_inset Quotes sld
26440 \end_inset 
26441
26442 make test-mcs51
26443 \begin_inset Quotes srd
26444 \end_inset 
26445
26446
26447 \family default 
26448 \series default 
26449  if you don't want to run the complete tests).
26450  The test code might also be interesting if you want to look for examples
26451 \begin_inset LatexCommand \index{Examples}
26452
26453 \end_inset 
26454
26455  checking corner cases of SDCC or if you plan to submit patches
26456 \begin_inset LatexCommand \index{Patch submission}
26457
26458 \end_inset 
26459
26460 .
26461 \layout Standard
26462
26463 The 14bit pic port uses a different set of regression tests 
26464 \begin_inset LatexCommand \index{Regression test (PIC14)}
26465
26466 \end_inset 
26467
26468 , you'll find them in the directory 
26469 \shape italic 
26470 sdcc/src/regression
26471 \shape default 
26472 .
26473 \layout Section
26474
26475 Use of SDCC in Education
26476 \layout Standard
26477
26478 In short: 
26479 \emph on 
26480 highly
26481 \emph default 
26482  encouraged
26483 \begin_inset Foot
26484 collapsed false
26485
26486 \layout Standard
26487
26488 the phrase "use in education" might evoke the association "
26489 \emph on 
26490 only
26491 \emph default 
26492  fit for use in education".
26493  This connotation is not intended but nevertheless risked as the licensing
26494  of SDCC makes it difficult to offer educational discounts
26495 \end_inset 
26496
26497 .
26498  If your rationales are to:
26499 \layout Enumerate
26500
26501 give students a chance to understand the 
26502 \emph on 
26503 complete
26504 \emph default 
26505  steps of code generation
26506 \layout Enumerate
26507
26508 have a curriculum that can be extended for years.
26509  Then you could use an fpga board as target and your curriculum will seamlessly
26510  extend from logic synthesis (
26511 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
26512
26513 \end_inset 
26514
26515
26516 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
26517
26518 \end_inset 
26519
26520 ), over assembly programming, to C to FPGA compilers (
26521 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
26522
26523 \end_inset 
26524
26525 ) and to C.
26526 \layout Enumerate
26527
26528 be able to insert excursions about skills like using a revision control
26529  system, submitting/applying patches, using a type-setting (as opposed to
26530  word-processing) engine LyX/LaTeX, using 
26531 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
26532
26533 \end_inset 
26534
26535 , following some 
26536 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
26537
26538 \end_inset 
26539
26540 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
26541  Source Software, CPU simulation, compiler regression tests
26542 \begin_inset LatexCommand \index{Regression test}
26543
26544 \end_inset 
26545
26546 .
26547  
26548 \newline 
26549 And if there should be a shortage of ideas then you can always point students
26550  to the ever-growing feature request list 
26551 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26552
26553 \end_inset 
26554
26555 .
26556 \layout Enumerate
26557
26558 not tie students to a specific host platform and instead allow them to use
26559  a host platform of 
26560 \emph on 
26561 their
26562 \emph default 
26563  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
26564  eventually 
26565 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
26566
26567 \end_inset 
26568
26569 )
26570 \layout Enumerate
26571
26572 not encourage students to use illegal copies of educational software
26573 \layout Enumerate
26574
26575 be immune to licensing/availability/price changes of the chosen tool chain
26576 \layout Enumerate
26577
26578 be able to change to a new target platform without having to adopt a new
26579  tool chain
26580 \layout Enumerate
26581
26582 have complete control over and insight into the tool chain
26583 \layout Enumerate
26584
26585 make your students aware about the pros and cons of open source software
26586  development
26587 \layout Enumerate
26588
26589 give back to the public as you are probably at least partially publically
26590  funded
26591 \layout Enumerate
26592
26593 give students a chance to publically prove their skills and to possibly
26594  see a world wide impact
26595 \layout Standard
26596
26597 then SDCC is probably among the first choices.
26598  Well, probably SDCC might be the only choice.
26599 \layout Chapter
26600 \pagebreak_top 
26601 SDCC Technical Data
26602 \layout Section
26603
26604 Optimizations
26605 \begin_inset LatexCommand \index{Optimizations}
26606
26607 \end_inset 
26608
26609
26610 \layout Standard
26611
26612 SDCC performs a host of standard optimizations in addition to some MCU specific
26613  optimizations.
26614  
26615 \layout Subsection
26616
26617 Sub-expression Elimination
26618 \begin_inset LatexCommand \index{Subexpression elimination}
26619
26620 \end_inset 
26621
26622
26623 \layout Standard
26624
26625 The compiler does local and 
26626 \emph on 
26627 g
26628 \emph default 
26629 lobal 
26630 \emph on 
26631 c
26632 \emph default 
26633 ommon 
26634 \emph on 
26635 s
26636 \emph default 
26637 ubexpression 
26638 \emph on 
26639 e
26640 \emph default 
26641 limination, e.g.: 
26642 \layout Verse
26643
26644
26645 \family typewriter 
26646 i = x + y + 1; 
26647 \newline 
26648 j = x + y;
26649 \layout Standard
26650
26651 will be translated to
26652 \layout Verse
26653
26654
26655 \family typewriter 
26656 iTemp = x + y; 
26657 \newline 
26658 i = iTemp + 1; 
26659 \newline 
26660 j = iTemp;
26661 \layout Standard
26662
26663 Some subexpressions are not as obvious as the above example, e.g.:
26664 \layout Verse
26665
26666
26667 \family typewriter 
26668 a->b[i].c = 10; 
26669 \newline 
26670 a->b[i].d = 11;
26671 \layout Standard
26672
26673 In this case the address arithmetic a->b[i] will be computed only once;
26674  the equivalent code in C would be.
26675 \layout Verse
26676
26677
26678 \family typewriter 
26679 iTemp = a->b[i]; 
26680 \newline 
26681 iTemp.c = 10; 
26682 \newline 
26683 iTemp.d = 11;
26684 \layout Standard
26685
26686 The compiler will try to keep these temporary variables in registers.
26687 \layout Subsection
26688
26689 Dead-Code Elimination
26690 \begin_inset LatexCommand \index{Dead-code elimination}
26691
26692 \end_inset 
26693
26694
26695 \layout Verse
26696
26697
26698 \family typewriter 
26699 int global;
26700 \newline 
26701
26702 \newline 
26703 void f () { 
26704 \newline 
26705 \SpecialChar ~
26706 \SpecialChar ~
26707 int i; 
26708 \newline 
26709 \SpecialChar ~
26710 \SpecialChar ~
26711 i = 1; \SpecialChar ~
26712 \SpecialChar ~
26713 \SpecialChar ~
26714 \SpecialChar ~
26715 \SpecialChar ~
26716 /* dead store */ 
26717 \newline 
26718 \SpecialChar ~
26719 \SpecialChar ~
26720 global = 1;\SpecialChar ~
26721 /* dead store */ 
26722 \newline 
26723 \SpecialChar ~
26724 \SpecialChar ~
26725 global = 2; 
26726 \newline 
26727 \SpecialChar ~
26728 \SpecialChar ~
26729 return; 
26730 \newline 
26731 \SpecialChar ~
26732 \SpecialChar ~
26733 global = 3;\SpecialChar ~
26734 /* unreachable */ 
26735 \newline 
26736 }
26737 \layout Standard
26738
26739 will be changed to
26740 \layout Verse
26741
26742
26743 \family typewriter 
26744 int global;
26745 \newline 
26746
26747 \newline 
26748 void f () {
26749 \newline 
26750 \SpecialChar ~
26751 \SpecialChar ~
26752 global = 2; 
26753 \newline 
26754 }
26755 \layout Subsection
26756
26757 Copy-Propagation
26758 \begin_inset LatexCommand \index{Copy propagation}
26759
26760 \end_inset 
26761
26762
26763 \layout Verse
26764
26765
26766 \family typewriter 
26767 int f() { 
26768 \newline 
26769 \SpecialChar ~
26770 \SpecialChar ~
26771 int i, j; 
26772 \newline 
26773 \SpecialChar ~
26774 \SpecialChar ~
26775 i = 10; 
26776 \newline 
26777 \SpecialChar ~
26778 \SpecialChar ~
26779 j = i; 
26780 \newline 
26781 \SpecialChar ~
26782 \SpecialChar ~
26783 return j; 
26784 \newline 
26785 }
26786 \layout Standard
26787
26788 will be changed to 
26789 \layout Verse
26790
26791
26792 \family typewriter 
26793 int f() { 
26794 \newline 
26795 \SpecialChar ~
26796 \SpecialChar ~
26797 int i, j; 
26798 \newline 
26799 \SpecialChar ~
26800 \SpecialChar ~
26801 i = 10; 
26802 \newline 
26803 \SpecialChar ~
26804 \SpecialChar ~
26805 j = 10; 
26806 \newline 
26807 \SpecialChar ~
26808 \SpecialChar ~
26809 return 10; 
26810 \newline 
26811 }
26812 \layout Standard
26813
26814 Note: the dead stores created by this copy propagation will be eliminated
26815  by dead-code elimination.
26816 \layout Subsection
26817
26818 Loop Optimizations
26819 \begin_inset LatexCommand \index{Loop optimization}
26820
26821 \end_inset 
26822
26823
26824 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26825
26826 \end_inset 
26827
26828
26829 \layout Standard
26830
26831 Two types of loop optimizations are done by SDCC 
26832 \emph on 
26833 loop invariant
26834 \emph default 
26835  lifting and
26836 \emph on 
26837  strength reduction
26838 \emph default 
26839  of loop induction variables.
26840  In addition to the strength reduction the optimizer marks the induction
26841  variables and the register allocator tries to keep the induction variables
26842  in registers for the duration of the loop.
26843  Because of this preference of the register allocator
26844 \begin_inset LatexCommand \index{Register allocation}
26845
26846 \end_inset 
26847
26848 , loop induction optimization causes an increase in register pressure, which
26849  may cause unwanted spilling of other temporary variables into the stack
26850 \begin_inset LatexCommand \index{stack}
26851
26852 \end_inset 
26853
26854  / data space.
26855  The compiler will generate a warning message when it is forced to allocate
26856  extra space either on the stack or data space.
26857  If this extra space allocation is undesirable then induction optimization
26858  can be eliminated either for the entire source file (with -
26859 \begin_inset ERT
26860 status Collapsed
26861
26862 \layout Standard
26863
26864 \backslash 
26865 /
26866 \end_inset 
26867
26868 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26869 noinduction
26870 \begin_inset LatexCommand \index{\#pragma noinduction}
26871
26872 \end_inset 
26873
26874 .
26875 \newline 
26876
26877 \newline 
26878 Loop Invariant:
26879 \layout Verse
26880
26881
26882 \family typewriter 
26883 for (i = 0 ; i < 100 ; i ++) 
26884 \newline 
26885 \SpecialChar ~
26886 \SpecialChar ~
26887 \SpecialChar ~
26888 \SpecialChar ~
26889 f += k + l;
26890 \layout Standard
26891
26892 changed to
26893 \layout Verse
26894
26895
26896 \family typewriter 
26897 itemp = k + l; 
26898 \newline 
26899 for (i = 0; i < 100; i++) 
26900 \newline 
26901 \SpecialChar ~
26902 \SpecialChar ~
26903 \SpecialChar ~
26904 \SpecialChar ~
26905 f += itemp;
26906 \layout Standard
26907
26908 As mentioned previously some loop invariants are not as apparent, all static
26909  address computations are also moved out of the loop.
26910 \newline 
26911
26912 \newline 
26913 Strength Reduction
26914 \begin_inset LatexCommand \index{Strength reduction}
26915
26916 \end_inset 
26917
26918 , this optimization substitutes an expression by a cheaper expression:
26919 \layout Verse
26920
26921
26922 \family typewriter 
26923 for (i=0;i < 100; i++)
26924 \newline 
26925 \SpecialChar ~
26926 \SpecialChar ~
26927 \SpecialChar ~
26928 \SpecialChar ~
26929 ar[i*5] = i*3;
26930 \layout Standard
26931
26932 changed to
26933 \layout Verse
26934
26935
26936 \family typewriter 
26937 itemp1 = 0; 
26938 \newline 
26939 itemp2 = 0; 
26940 \newline 
26941 for (i=0;i< 100;i++) { 
26942 \newline 
26943 \SpecialChar ~
26944 \SpecialChar ~
26945 \SpecialChar ~
26946 \SpecialChar ~
26947 ar[itemp1] = itemp2; 
26948 \newline 
26949 \SpecialChar ~
26950 \SpecialChar ~
26951 \SpecialChar ~
26952 \SpecialChar ~
26953 itemp1 += 5; 
26954 \newline 
26955 \SpecialChar ~
26956 \SpecialChar ~
26957 \SpecialChar ~
26958 \SpecialChar ~
26959 itemp2 += 3; 
26960 \newline 
26961 }
26962 \layout Standard
26963
26964 The more expensive multiplication
26965 \begin_inset LatexCommand \index{Multiplication}
26966
26967 \end_inset 
26968
26969  is changed to a less expensive addition.
26970 \layout Subsection
26971
26972 Loop Reversing
26973 \begin_inset LatexCommand \index{Loop reversing}
26974
26975 \end_inset 
26976
26977
26978 \layout Standard
26979
26980 This optimization is done to reduce the overhead of checking loop boundaries
26981  for every iteration.
26982  Some simple loops can be reversed and implemented using a 
26983 \begin_inset Quotes eld
26984 \end_inset 
26985
26986 decrement and jump if not zero
26987 \begin_inset Quotes erd
26988 \end_inset 
26989
26990  instruction.
26991  SDCC checks for the following criterion to determine if a loop is reversible
26992  (note: more sophisticated compilers use data-dependency analysis to make
26993  this determination, SDCC uses a more simple minded analysis).
26994 \layout Itemize
26995
26996 The 'for' loop is of the form 
26997 \newline 
26998
26999 \newline 
27000
27001 \family typewriter 
27002 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
27003  += 1])
27004 \newline 
27005 \SpecialChar ~
27006 \SpecialChar ~
27007 \SpecialChar ~
27008 \SpecialChar ~
27009 <for body>
27010 \layout Itemize
27011
27012 The <for body> does not contain 
27013 \begin_inset Quotes eld
27014 \end_inset 
27015
27016 continue
27017 \begin_inset Quotes erd
27018 \end_inset 
27019
27020  or 'break
27021 \begin_inset Quotes erd
27022 \end_inset 
27023
27024 .
27025 \layout Itemize
27026
27027 All goto's are contained within the loop.
27028 \layout Itemize
27029
27030 No function calls within the loop.
27031 \layout Itemize
27032
27033 The loop control variable <sym> is not assigned any value within the loop
27034 \layout Itemize
27035
27036 The loop control variable does NOT participate in any arithmetic operation
27037  within the loop.
27038 \layout Itemize
27039
27040 There are NO switch statements in the loop.
27041 \layout Subsection
27042
27043 Algebraic Simplifications
27044 \layout Standard
27045
27046 SDCC does numerous algebraic simplifications, the following is a small sub-set
27047  of these optimizations.
27048 \layout Verse
27049
27050
27051 \family typewriter 
27052 i = j + 0;\SpecialChar ~
27053 \SpecialChar ~
27054 \SpecialChar ~
27055 \SpecialChar ~
27056  /* changed to: */\SpecialChar ~
27057 \SpecialChar ~
27058 \SpecialChar ~
27059 \SpecialChar ~
27060  i = j; 
27061 \newline 
27062 i /= 2;\SpecialChar ~
27063 \SpecialChar ~
27064 \SpecialChar ~
27065 \SpecialChar ~
27066 \SpecialChar ~
27067 \SpecialChar ~
27068 \SpecialChar ~
27069  /* changed to: */\SpecialChar ~
27070 \SpecialChar ~
27071 \SpecialChar ~
27072 \SpecialChar ~
27073  i >>= 1; 
27074 \newline 
27075 i = j - j;\SpecialChar ~
27076 \SpecialChar ~
27077 \SpecialChar ~
27078 \SpecialChar ~
27079  /* changed to: */\SpecialChar ~
27080 \SpecialChar ~
27081 \SpecialChar ~
27082 \SpecialChar ~
27083  i = 0; 
27084 \newline 
27085 i = j / 1;\SpecialChar ~
27086 \SpecialChar ~
27087 \SpecialChar ~
27088 \SpecialChar ~
27089  /* changed to: */\SpecialChar ~
27090 \SpecialChar ~
27091 \SpecialChar ~
27092 \SpecialChar ~
27093  i = j;
27094 \layout Standard
27095
27096 Note the subexpressions
27097 \begin_inset LatexCommand \index{Subexpression}
27098
27099 \end_inset 
27100
27101  given above are generally introduced by macro expansions or as a result
27102  of copy/constant propagation.
27103 \layout Subsection
27104
27105 'switch' Statements
27106 \begin_inset LatexCommand \label{sub:'switch'-Statements}
27107
27108 \end_inset 
27109
27110
27111 \begin_inset LatexCommand \index{switch statement}
27112
27113 \end_inset 
27114
27115
27116 \layout Standard
27117
27118 SDCC can optimize switch statements to jump tables
27119 \begin_inset LatexCommand \index{jump tables}
27120
27121 \end_inset 
27122
27123 .
27124  It makes the decision based on an estimate of the generated code size.
27125  SDCC is quite liberal in the requirements for jump table generation: 
27126 \layout Itemize
27127
27128 The labels need not be in order, and the starting number need not be one
27129  or zero, the case labels are in numerical sequence or not too many case
27130  labels are missing.
27131 \begin_deeper 
27132 \layout Verse
27133
27134
27135 \family typewriter 
27136 switch(i) {\SpecialChar ~
27137 \SpecialChar ~
27138 \SpecialChar ~
27139 \SpecialChar ~
27140 \SpecialChar ~
27141 \SpecialChar ~
27142 \SpecialChar ~
27143 \SpecialChar ~
27144 \SpecialChar ~
27145 \SpecialChar ~
27146 \SpecialChar ~
27147 \SpecialChar ~
27148 \SpecialChar ~
27149 \SpecialChar ~
27150 \SpecialChar ~
27151 \SpecialChar ~
27152 \SpecialChar ~
27153 \SpecialChar ~
27154 \SpecialChar ~
27155 \SpecialChar ~
27156 \SpecialChar ~
27157 \SpecialChar ~
27158 \SpecialChar ~
27159 \SpecialChar ~
27160 \SpecialChar ~
27161 \SpecialChar ~
27162 switch (i) { 
27163 \newline 
27164 \SpecialChar ~
27165 \SpecialChar ~
27166 \SpecialChar ~
27167 case 4: ...\SpecialChar ~
27168 \SpecialChar ~
27169 \SpecialChar ~
27170 \SpecialChar ~
27171 \SpecialChar ~
27172 \SpecialChar ~
27173 \SpecialChar ~
27174 \SpecialChar ~
27175 \SpecialChar ~
27176 \SpecialChar ~
27177 \SpecialChar ~
27178 \SpecialChar ~
27179 \SpecialChar ~
27180 \SpecialChar ~
27181 \SpecialChar ~
27182 \SpecialChar ~
27183 \SpecialChar ~
27184 \SpecialChar ~
27185 \SpecialChar ~
27186 \SpecialChar ~
27187 \SpecialChar ~
27188 \SpecialChar ~
27189 \SpecialChar ~
27190 \SpecialChar ~
27191 \SpecialChar ~
27192 \SpecialChar ~
27193 case 0: ...
27194  
27195 \newline 
27196 \SpecialChar ~
27197 \SpecialChar ~
27198 \SpecialChar ~
27199 case 5: ...\SpecialChar ~
27200 \SpecialChar ~
27201 \SpecialChar ~
27202 \SpecialChar ~
27203 \SpecialChar ~
27204 \SpecialChar ~
27205 \SpecialChar ~
27206 \SpecialChar ~
27207 \SpecialChar ~
27208 \SpecialChar ~
27209 \SpecialChar ~
27210 \SpecialChar ~
27211 \SpecialChar ~
27212 \SpecialChar ~
27213 \SpecialChar ~
27214 \SpecialChar ~
27215 \SpecialChar ~
27216 \SpecialChar ~
27217 \SpecialChar ~
27218 \SpecialChar ~
27219 \SpecialChar ~
27220 \SpecialChar ~
27221 \SpecialChar ~
27222 \SpecialChar ~
27223 \SpecialChar ~
27224 \SpecialChar ~
27225 case 1: ...
27226  
27227 \newline 
27228 \SpecialChar ~
27229 \SpecialChar ~
27230 \SpecialChar ~
27231 case 3: ...\SpecialChar ~
27232 \SpecialChar ~
27233 \SpecialChar ~
27234 \SpecialChar ~
27235 \SpecialChar ~
27236 \SpecialChar ~
27237 \SpecialChar ~
27238 \SpecialChar ~
27239 \SpecialChar ~
27240 \SpecialChar ~
27241 \SpecialChar ~
27242 \SpecialChar ~
27243 \SpecialChar ~
27244 \SpecialChar ~
27245 \SpecialChar ~
27246 \SpecialChar ~
27247 \SpecialChar ~
27248 \SpecialChar ~
27249 \SpecialChar ~
27250 \SpecialChar ~
27251 \SpecialChar ~
27252 \SpecialChar ~
27253 \SpecialChar ~
27254 \SpecialChar ~
27255 \SpecialChar ~
27256 \SpecialChar ~
27257
27258 \newline 
27259 \SpecialChar ~
27260 \SpecialChar ~
27261 \SpecialChar ~
27262 case 6: ...\SpecialChar ~
27263 \SpecialChar ~
27264 \SpecialChar ~
27265 \SpecialChar ~
27266 \SpecialChar ~
27267 \SpecialChar ~
27268 \SpecialChar ~
27269 \SpecialChar ~
27270 \SpecialChar ~
27271 \SpecialChar ~
27272 \SpecialChar ~
27273 \SpecialChar ~
27274 \SpecialChar ~
27275 \SpecialChar ~
27276 \SpecialChar ~
27277 \SpecialChar ~
27278 \SpecialChar ~
27279 \SpecialChar ~
27280 \SpecialChar ~
27281 \SpecialChar ~
27282 \SpecialChar ~
27283 \SpecialChar ~
27284 \SpecialChar ~
27285 \SpecialChar ~
27286 \SpecialChar ~
27287 \SpecialChar ~
27288 case 3: ...
27289  
27290 \newline 
27291 \SpecialChar ~
27292 \SpecialChar ~
27293 \SpecialChar ~
27294 case 7: ...\SpecialChar ~
27295 \SpecialChar ~
27296 \SpecialChar ~
27297 \SpecialChar ~
27298 \SpecialChar ~
27299 \SpecialChar ~
27300 \SpecialChar ~
27301 \SpecialChar ~
27302 \SpecialChar ~
27303 \SpecialChar ~
27304 \SpecialChar ~
27305 \SpecialChar ~
27306 \SpecialChar ~
27307 \SpecialChar ~
27308 \SpecialChar ~
27309 \SpecialChar ~
27310 \SpecialChar ~
27311 \SpecialChar ~
27312 \SpecialChar ~
27313 \SpecialChar ~
27314 \SpecialChar ~
27315 \SpecialChar ~
27316 \SpecialChar ~
27317 \SpecialChar ~
27318 \SpecialChar ~
27319 \SpecialChar ~
27320 case 4: ...
27321  
27322 \newline 
27323 \SpecialChar ~
27324 \SpecialChar ~
27325 \SpecialChar ~
27326 case 8: ...\SpecialChar ~
27327 \SpecialChar ~
27328 \SpecialChar ~
27329 \SpecialChar ~
27330 \SpecialChar ~
27331 \SpecialChar ~
27332 \SpecialChar ~
27333 \SpecialChar ~
27334 \SpecialChar ~
27335 \SpecialChar ~
27336 \SpecialChar ~
27337 \SpecialChar ~
27338 \SpecialChar ~
27339 \SpecialChar ~
27340 \SpecialChar ~
27341 \SpecialChar ~
27342 \SpecialChar ~
27343 \SpecialChar ~
27344 \SpecialChar ~
27345 \SpecialChar ~
27346 \SpecialChar ~
27347 \SpecialChar ~
27348 \SpecialChar ~
27349 \SpecialChar ~
27350 \SpecialChar ~
27351 \SpecialChar ~
27352 case 5: ...
27353  
27354 \newline 
27355 \SpecialChar ~
27356 \SpecialChar ~
27357 \SpecialChar ~
27358 case 9: ...\SpecialChar ~
27359 \SpecialChar ~
27360 \SpecialChar ~
27361 \SpecialChar ~
27362 \SpecialChar ~
27363 \SpecialChar ~
27364 \SpecialChar ~
27365 \SpecialChar ~
27366 \SpecialChar ~
27367 \SpecialChar ~
27368 \SpecialChar ~
27369 \SpecialChar ~
27370 \SpecialChar ~
27371 \SpecialChar ~
27372 \SpecialChar ~
27373 \SpecialChar ~
27374 \SpecialChar ~
27375 \SpecialChar ~
27376 \SpecialChar ~
27377 \SpecialChar ~
27378 \SpecialChar ~
27379 \SpecialChar ~
27380 \SpecialChar ~
27381 \SpecialChar ~
27382 \SpecialChar ~
27383 \SpecialChar ~
27384 case 6: ...
27385  
27386 \newline 
27387 \SpecialChar ~
27388 \SpecialChar ~
27389 \SpecialChar ~
27390 case 10: ...\SpecialChar ~
27391 \SpecialChar ~
27392 \SpecialChar ~
27393 \SpecialChar ~
27394 \SpecialChar ~
27395 \SpecialChar ~
27396 \SpecialChar ~
27397 \SpecialChar ~
27398 \SpecialChar ~
27399 \SpecialChar ~
27400 \SpecialChar ~
27401 \SpecialChar ~
27402 \SpecialChar ~
27403 \SpecialChar ~
27404 \SpecialChar ~
27405 \SpecialChar ~
27406 \SpecialChar ~
27407 \SpecialChar ~
27408 \SpecialChar ~
27409 \SpecialChar ~
27410 \SpecialChar ~
27411 \SpecialChar ~
27412 \SpecialChar ~
27413 \SpecialChar ~
27414 \SpecialChar ~
27415 case 7: ...
27416  
27417 \newline 
27418 \SpecialChar ~
27419 \SpecialChar ~
27420 \SpecialChar ~
27421 case 11: ...\SpecialChar ~
27422 \SpecialChar ~
27423 \SpecialChar ~
27424 \SpecialChar ~
27425 \SpecialChar ~
27426 \SpecialChar ~
27427 \SpecialChar ~
27428 \SpecialChar ~
27429 \SpecialChar ~
27430 \SpecialChar ~
27431 \SpecialChar ~
27432 \SpecialChar ~
27433 \SpecialChar ~
27434 \SpecialChar ~
27435 \SpecialChar ~
27436 \SpecialChar ~
27437 \SpecialChar ~
27438 \SpecialChar ~
27439 \SpecialChar ~
27440 \SpecialChar ~
27441 \SpecialChar ~
27442 \SpecialChar ~
27443 \SpecialChar ~
27444 \SpecialChar ~
27445 \SpecialChar ~
27446 case 8: ...
27447  
27448 \newline 
27449 }\SpecialChar ~
27450 \SpecialChar ~
27451 \SpecialChar ~
27452 \SpecialChar ~
27453 \SpecialChar ~
27454 \SpecialChar ~
27455 \SpecialChar ~
27456 \SpecialChar ~
27457 \SpecialChar ~
27458 \SpecialChar ~
27459 \SpecialChar ~
27460 \SpecialChar ~
27461 \SpecialChar ~
27462 \SpecialChar ~
27463 \SpecialChar ~
27464 \SpecialChar ~
27465 \SpecialChar ~
27466 \SpecialChar ~
27467 \SpecialChar ~
27468 \SpecialChar ~
27469 \SpecialChar ~
27470 \SpecialChar ~
27471 \SpecialChar ~
27472 \SpecialChar ~
27473 \SpecialChar ~
27474 \SpecialChar ~
27475 \SpecialChar ~
27476 \SpecialChar ~
27477 \SpecialChar ~
27478 \SpecialChar ~
27479 \SpecialChar ~
27480 \SpecialChar ~
27481 \SpecialChar ~
27482 \SpecialChar ~
27483 \SpecialChar ~
27484 \SpecialChar ~
27485 }
27486 \layout Standard
27487
27488 Both the above switch statements will be implemented using a jump-table.
27489  The example to the right side is slightly more efficient as the check for
27490  the lower boundary of the jump-table is not needed.
27491 \end_deeper 
27492 \layout Itemize
27493
27494 The number of case labels is not larger than supported by the target architectur
27495 e.
27496 \layout Itemize
27497
27498 If the case labels are not in numerical sequence ('gaps' between cases)
27499  SDCC checks whether a jump table with additionally inserted dummy cases
27500  is still attractive.
27501  
27502 \layout Itemize
27503
27504 If the starting number is not zero and a check for the lower boundary of
27505  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
27506  ...
27507  .
27508 \layout Standard
27509
27510 Switch statements which have large gaps in the numeric sequence or those
27511  that have too many case labels can be split into more than one switch statement
27512  for efficient code generation, e.g.:
27513 \layout Verse
27514
27515
27516 \family typewriter 
27517 switch (i) { 
27518 \newline 
27519 \SpecialChar ~
27520 \SpecialChar ~
27521 case 1: ...
27522  
27523 \newline 
27524 \SpecialChar ~
27525 \SpecialChar ~
27526 case 2: ...
27527  
27528 \newline 
27529 \SpecialChar ~
27530 \SpecialChar ~
27531 case 3: ...
27532  
27533 \newline 
27534 \SpecialChar ~
27535 \SpecialChar ~
27536 case 4: ...
27537  
27538 \newline 
27539 \SpecialChar ~
27540 \SpecialChar ~
27541 case 5: ...
27542  
27543 \newline 
27544 \SpecialChar ~
27545 \SpecialChar ~
27546 case 6: ...
27547  
27548 \newline 
27549 \SpecialChar ~
27550 \SpecialChar ~
27551 case 7: ...
27552  
27553 \newline 
27554 \SpecialChar ~
27555 \SpecialChar ~
27556 case 101: ...
27557  
27558 \newline 
27559 \SpecialChar ~
27560 \SpecialChar ~
27561 case 102: ...
27562  
27563 \newline 
27564 \SpecialChar ~
27565 \SpecialChar ~
27566 case 103: ...
27567  
27568 \newline 
27569 \SpecialChar ~
27570 \SpecialChar ~
27571 case 104: ...
27572  
27573 \newline 
27574 \SpecialChar ~
27575 \SpecialChar ~
27576 case 105: ...
27577  
27578 \newline 
27579 \SpecialChar ~
27580 \SpecialChar ~
27581 case 106: ...
27582  
27583 \newline 
27584 \SpecialChar ~
27585 \SpecialChar ~
27586 case 107: ...
27587  
27588 \newline 
27589 }
27590 \layout Standard
27591
27592 If the above switch statement is broken down into two switch statements
27593 \layout Verse
27594
27595
27596 \family typewriter 
27597 switch (i) { 
27598 \newline 
27599 \SpecialChar ~
27600 \SpecialChar ~
27601 case 1: ...
27602  
27603 \newline 
27604 \SpecialChar ~
27605 \SpecialChar ~
27606 case 2: ...
27607  
27608 \newline 
27609 \SpecialChar ~
27610 \SpecialChar ~
27611 case 3: ...
27612  
27613 \newline 
27614 \SpecialChar ~
27615 \SpecialChar ~
27616 case 4: ...
27617  
27618 \newline 
27619 \SpecialChar ~
27620 \SpecialChar ~
27621 case 5: ...
27622  
27623 \newline 
27624 \SpecialChar ~
27625 \SpecialChar ~
27626 case 6: ...
27627  
27628 \newline 
27629 \SpecialChar ~
27630 \SpecialChar ~
27631 case 7: ...
27632  
27633 \newline 
27634 }
27635 \layout Standard
27636
27637 and
27638 \layout Verse
27639
27640
27641 \family typewriter 
27642 switch (i) { 
27643 \newline 
27644 \SpecialChar ~
27645 \SpecialChar ~
27646 case 101: ...
27647  
27648 \newline 
27649 \SpecialChar ~
27650 \SpecialChar ~
27651 case 102: ...
27652  
27653 \newline 
27654 \SpecialChar ~
27655 \SpecialChar ~
27656 case 103: ...
27657  
27658 \newline 
27659 \SpecialChar ~
27660 \SpecialChar ~
27661 case 104: ...
27662  
27663 \newline 
27664 \SpecialChar ~
27665 \SpecialChar ~
27666 case 105: ...
27667  
27668 \newline 
27669 \SpecialChar ~
27670 \SpecialChar ~
27671 case 106: ...
27672  
27673 \newline 
27674 \SpecialChar ~
27675 \SpecialChar ~
27676 case 107: ...
27677  
27678 \newline 
27679 }
27680 \layout Standard
27681
27682 then both the switch statements will be implemented using jump-tables whereas
27683  the unmodified switch statement will not be.
27684 \layout Comment
27685
27686 There might be reasons which SDCC cannot know about to either favour or
27687  not favour jump tables.
27688  If the target system has to be as quick for the last switch case as for
27689  the first (pro jump table), or if the switch argument is known to be zero
27690  in the majority of the cases (contra jump table).
27691 \layout Standard
27692
27693 The pragma nojtbound
27694 \begin_inset LatexCommand \index{\#pragma nojtbound}
27695
27696 \end_inset 
27697
27698  can be used to turn off checking the 
27699 \emph on 
27700 j
27701 \emph default 
27702 ump 
27703 \emph on 
27704 t
27705 \emph default 
27706 able 
27707 \emph on 
27708 bound
27709 \emph default 
27710 aries.
27711  It has no effect if a default label is supplied.
27712  Use of this pragma is dangerous: if the switch
27713 \begin_inset LatexCommand \index{switch statement}
27714
27715 \end_inset 
27716
27717  argument is not matched by a case statement the processor will happily
27718  jump into Nirvana.
27719 \layout Subsection
27720
27721 Bit-shifting Operations
27722 \begin_inset LatexCommand \index{Bit shifting}
27723
27724 \end_inset 
27725
27726 .
27727 \layout Standard
27728
27729 Bit shifting is one of the most frequently used operation in embedded programmin
27730 g.
27731  SDCC tries to implement bit-shift operations in the most efficient way
27732  possible, e.g.:
27733 \layout Verse
27734
27735
27736 \family typewriter 
27737 unsigned char i;
27738 \newline 
27739 ...
27740  
27741 \newline 
27742 i >>= 4; 
27743 \newline 
27744 ...
27745 \layout Standard
27746
27747 generates the following code:
27748 \layout Verse
27749
27750
27751 \family typewriter 
27752 mov\SpecialChar ~
27753  a,_i 
27754 \newline 
27755 swap a 
27756 \newline 
27757 anl\SpecialChar ~
27758  a,#0x0f 
27759 \newline 
27760 mov\SpecialChar ~
27761  _i,a
27762 \layout Standard
27763
27764 In general SDCC will never setup a loop if the shift count is known.
27765  Another example:
27766 \layout Verse
27767
27768
27769 \family typewriter 
27770 unsigned int i; 
27771 \newline 
27772 ...
27773  
27774 \newline 
27775 i >>= 9; 
27776 \newline 
27777 ...
27778 \layout Standard
27779
27780 will generate:
27781 \layout Verse
27782
27783
27784 \family typewriter 
27785 mov\SpecialChar ~
27786 \SpecialChar ~
27787 a,(_i + 1) 
27788 \newline 
27789 mov\SpecialChar ~
27790 \SpecialChar ~
27791 (_i + 1),#0x00 
27792 \newline 
27793 clr\SpecialChar ~
27794 \SpecialChar ~
27795
27796 \newline 
27797 rrc\SpecialChar ~
27798 \SpecialChar ~
27799
27800 \newline 
27801 mov\SpecialChar ~
27802 \SpecialChar ~
27803 _i,a
27804 \layout Subsection
27805
27806 Bit-rotation
27807 \begin_inset LatexCommand \index{Bit rotation}
27808
27809 \end_inset 
27810
27811
27812 \layout Standard
27813
27814 A special case of the bit-shift operation is bit rotation
27815 \begin_inset LatexCommand \index{rotating bits}
27816
27817 \end_inset 
27818
27819 , SDCC recognizes the following expression to be a left bit-rotation:
27820 \layout Verse
27821
27822
27823 \family typewriter 
27824 \series bold 
27825 unsigned
27826 \series default 
27827 \SpecialChar ~
27828 \SpecialChar ~
27829 char i;\SpecialChar ~
27830 \SpecialChar ~
27831 \SpecialChar ~
27832 \SpecialChar ~
27833 \SpecialChar ~
27834 \SpecialChar ~
27835 \SpecialChar ~
27836 \SpecialChar ~
27837 \SpecialChar ~
27838 \SpecialChar ~
27839 \SpecialChar ~
27840 /* unsigned is needed for rotation */ 
27841 \newline 
27842 ...
27843  
27844 \newline 
27845 i = ((i << 1) | (i >> 7)); 
27846 \family default 
27847
27848 \newline 
27849
27850 \family typewriter 
27851 ...
27852 \layout Standard
27853
27854 will generate the following code:
27855 \layout Verse
27856
27857
27858 \family typewriter 
27859 mov\SpecialChar ~
27860 \SpecialChar ~
27861 a,_i 
27862 \newline 
27863 rl\SpecialChar ~
27864 \SpecialChar ~
27865 \SpecialChar ~
27866
27867 \newline 
27868 mov\SpecialChar ~
27869 \SpecialChar ~
27870 _i,a
27871 \layout Standard
27872
27873 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27874 ns of this case will also be recognized as bit-rotation, i.e.: 
27875 \layout Verse
27876
27877
27878 \family typewriter 
27879 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27880 \layout Subsection
27881
27882 Nibble and Byte Swapping
27883 \layout Standard
27884
27885 Other special cases of the bit-shift operations are nibble or byte swapping
27886 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27887
27888 \end_inset 
27889
27890 , SDCC recognizes the following expressions:
27891 \layout Verse
27892
27893
27894 \family typewriter 
27895 \series bold 
27896 unsigned
27897 \series default 
27898 \SpecialChar ~
27899 \SpecialChar ~
27900 char i; 
27901 \newline 
27902
27903 \series bold 
27904 unsigned
27905 \series default 
27906 \SpecialChar ~
27907 \SpecialChar ~
27908 int j; 
27909 \newline 
27910 ...
27911  
27912 \newline 
27913 i = ((i << 4) | (i >> 4)); 
27914 \family default 
27915
27916 \newline 
27917
27918 \family typewriter 
27919 j = ((j << 8) | (j >> 8)); 
27920 \layout Standard
27921
27922 and generates a swap instruction for the nibble swapping
27923 \begin_inset LatexCommand \index{Nibble swapping}
27924
27925 \end_inset 
27926
27927  or move instructions for the byte swapping
27928 \begin_inset LatexCommand \index{Byte swapping}
27929
27930 \end_inset 
27931
27932 .
27933  The 
27934 \begin_inset Quotes sld
27935 \end_inset 
27936
27937 j
27938 \begin_inset Quotes srd
27939 \end_inset 
27940
27941  example can be used to convert from little to big-endian or vice versa.
27942  If you want to change the endianness of a 
27943 \emph on 
27944 signed
27945 \emph default 
27946  integer you have to cast to 
27947 \family typewriter 
27948 (unsigned int)
27949 \family default 
27950  first.
27951 \layout Standard
27952
27953 Note that SDCC stores numbers in little-endian
27954 \begin_inset Foot
27955 collapsed false
27956
27957 \layout Standard
27958
27959 Usually 8-bit processors don't care much about endianness.
27960  This is not the case for the standard 8051 which only has an instruction
27961  to increment its 
27962 \emph on 
27963 dptr
27964 \emph default 
27965
27966 \begin_inset LatexCommand \index{DPTR}
27967
27968 \end_inset 
27969
27970 -datapointer
27971 \emph on 
27972  
27973 \emph default 
27974 so little-endian is the more efficient byte order.
27975 \end_inset 
27976
27977
27978 \begin_inset LatexCommand \index{little-endian}
27979
27980 \end_inset 
27981
27982
27983 \begin_inset LatexCommand \index{Endianness}
27984
27985 \end_inset 
27986
27987  format (i.e.
27988  lowest order first).
27989 \layout Subsection
27990
27991 Highest Order Bit
27992 \begin_inset LatexCommand \index{Highest Order Bit}
27993
27994 \end_inset 
27995
27996  / Any Order Bit
27997 \begin_inset LatexCommand \index{Any Order Bit}
27998
27999 \end_inset 
28000
28001
28002 \layout Standard
28003
28004 It is frequently required to obtain the highest order bit of an integral
28005  type (long, int, short or char types).
28006  Also obtaining any other order bit is not uncommon.
28007  SDCC recognizes the following expressions to yield the highest order bit
28008  and generates optimized code for it, e.g.:
28009 \layout Verse
28010
28011
28012 \family typewriter 
28013 unsigned int gint; 
28014 \newline 
28015
28016 \newline 
28017 foo () { 
28018 \newline 
28019 \SpecialChar ~
28020 \SpecialChar ~
28021 unsigned char hob1, aob1; 
28022 \newline 
28023 \SpecialChar ~
28024 \SpecialChar ~
28025 bit hob2, hob3, aob2, aob3; 
28026 \newline 
28027 \SpecialChar ~
28028 \SpecialChar ~
28029 ...
28030  
28031 \newline 
28032 \SpecialChar ~
28033 \SpecialChar ~
28034 hob1 = (gint >> 15) & 1; 
28035 \newline 
28036 \SpecialChar ~
28037 \SpecialChar ~
28038 hob2 = (gint >> 15) & 1; 
28039 \newline 
28040 \SpecialChar ~
28041 \SpecialChar ~
28042 hob3 = gint & 0x8000; 
28043 \newline 
28044 \SpecialChar ~
28045 \SpecialChar ~
28046 aob1 = (gint >> 9) & 1; 
28047 \newline 
28048 \SpecialChar ~
28049 \SpecialChar ~
28050 aob2 = (gint >> 8) & 1; 
28051 \newline 
28052 \SpecialChar ~
28053 \SpecialChar ~
28054 aob3 = gint & 0x0800; 
28055 \newline 
28056 \SpecialChar ~
28057 \SpecialChar ~
28058 ..
28059  
28060 \newline 
28061 }
28062 \layout Standard
28063
28064 will generate the following code:
28065 \layout Verse
28066
28067
28068 \family typewriter 
28069 \SpecialChar ~
28070 \SpecialChar ~
28071 \SpecialChar ~
28072 \SpecialChar ~
28073 \SpecialChar ~
28074 \SpecialChar ~
28075 \SpecialChar ~
28076 \SpecialChar ~
28077 \SpecialChar ~
28078 \SpecialChar ~
28079 \SpecialChar ~
28080 \SpecialChar ~
28081 \SpecialChar ~
28082 \SpecialChar ~
28083 \SpecialChar ~
28084 \SpecialChar ~
28085 \SpecialChar ~
28086 \SpecialChar ~
28087 \SpecialChar ~
28088 \SpecialChar ~
28089 \SpecialChar ~
28090 \SpecialChar ~
28091 \SpecialChar ~
28092 \SpecialChar ~
28093 \SpecialChar ~
28094  61 ;\SpecialChar ~
28095  hob.c 7 
28096 \newline 
28097 000A E5*01\SpecialChar ~
28098 \SpecialChar ~
28099 \SpecialChar ~
28100 \SpecialChar ~
28101 \SpecialChar ~
28102 \SpecialChar ~
28103 \SpecialChar ~
28104 \SpecialChar ~
28105 \SpecialChar ~
28106 \SpecialChar ~
28107 \SpecialChar ~
28108 \SpecialChar ~
28109 \SpecialChar ~
28110 \SpecialChar ~
28111 \SpecialChar ~
28112  62\SpecialChar ~
28113 \SpecialChar ~
28114 \SpecialChar ~
28115 \SpecialChar ~
28116 \SpecialChar ~
28117 \SpecialChar ~
28118 \SpecialChar ~
28119 \SpecialChar ~
28120  mov\SpecialChar ~
28121 \SpecialChar ~
28122  a,(_gint + 1) 
28123 \newline 
28124 000C 23\SpecialChar ~
28125 \SpecialChar ~
28126 \SpecialChar ~
28127 \SpecialChar ~
28128 \SpecialChar ~
28129 \SpecialChar ~
28130 \SpecialChar ~
28131 \SpecialChar ~
28132 \SpecialChar ~
28133 \SpecialChar ~
28134 \SpecialChar ~
28135 \SpecialChar ~
28136 \SpecialChar ~
28137 \SpecialChar ~
28138 \SpecialChar ~
28139 \SpecialChar ~
28140 \SpecialChar ~
28141 \SpecialChar ~
28142  63\SpecialChar ~
28143 \SpecialChar ~
28144 \SpecialChar ~
28145 \SpecialChar ~
28146 \SpecialChar ~
28147 \SpecialChar ~
28148 \SpecialChar ~
28149 \SpecialChar ~
28150  rl\SpecialChar ~
28151 \SpecialChar ~
28152 \SpecialChar ~
28153  a 
28154 \newline 
28155 000D 54 01\SpecialChar ~
28156 \SpecialChar ~
28157 \SpecialChar ~
28158 \SpecialChar ~
28159 \SpecialChar ~
28160 \SpecialChar ~
28161 \SpecialChar ~
28162 \SpecialChar ~
28163 \SpecialChar ~
28164 \SpecialChar ~
28165 \SpecialChar ~
28166 \SpecialChar ~
28167 \SpecialChar ~
28168 \SpecialChar ~
28169 \SpecialChar ~
28170  64\SpecialChar ~
28171 \SpecialChar ~
28172 \SpecialChar ~
28173 \SpecialChar ~
28174 \SpecialChar ~
28175 \SpecialChar ~
28176 \SpecialChar ~
28177 \SpecialChar ~
28178  anl\SpecialChar ~
28179 \SpecialChar ~
28180  a,#0x01 
28181 \newline 
28182 000F F5*02\SpecialChar ~
28183 \SpecialChar ~
28184 \SpecialChar ~
28185 \SpecialChar ~
28186 \SpecialChar ~
28187 \SpecialChar ~
28188 \SpecialChar ~
28189 \SpecialChar ~
28190 \SpecialChar ~
28191 \SpecialChar ~
28192 \SpecialChar ~
28193 \SpecialChar ~
28194 \SpecialChar ~
28195 \SpecialChar ~
28196 \SpecialChar ~
28197  65\SpecialChar ~
28198 \SpecialChar ~
28199 \SpecialChar ~
28200 \SpecialChar ~
28201 \SpecialChar ~
28202 \SpecialChar ~
28203 \SpecialChar ~
28204 \SpecialChar ~
28205  mov\SpecialChar ~
28206 \SpecialChar ~
28207  _foo_hob1_1_1,a 
28208 \newline 
28209 \SpecialChar ~
28210 \SpecialChar ~
28211 \SpecialChar ~
28212 \SpecialChar ~
28213 \SpecialChar ~
28214 \SpecialChar ~
28215 \SpecialChar ~
28216 \SpecialChar ~
28217 \SpecialChar ~
28218 \SpecialChar ~
28219 \SpecialChar ~
28220 \SpecialChar ~
28221 \SpecialChar ~
28222 \SpecialChar ~
28223 \SpecialChar ~
28224 \SpecialChar ~
28225 \SpecialChar ~
28226 \SpecialChar ~
28227 \SpecialChar ~
28228 \SpecialChar ~
28229 \SpecialChar ~
28230 \SpecialChar ~
28231 \SpecialChar ~
28232 \SpecialChar ~
28233 \SpecialChar ~
28234  66 ;\SpecialChar ~
28235  hob.c 8 
28236 \newline 
28237 0011 E5*01\SpecialChar ~
28238 \SpecialChar ~
28239 \SpecialChar ~
28240 \SpecialChar ~
28241 \SpecialChar ~
28242 \SpecialChar ~
28243 \SpecialChar ~
28244 \SpecialChar ~
28245 \SpecialChar ~
28246 \SpecialChar ~
28247 \SpecialChar ~
28248 \SpecialChar ~
28249 \SpecialChar ~
28250 \SpecialChar ~
28251 \SpecialChar ~
28252  67\SpecialChar ~
28253 \SpecialChar ~
28254 \SpecialChar ~
28255 \SpecialChar ~
28256 \SpecialChar ~
28257 \SpecialChar ~
28258 \SpecialChar ~
28259 \SpecialChar ~
28260  mov\SpecialChar ~
28261 \SpecialChar ~
28262  a,(_gint + 1) 
28263 \newline 
28264 0013 33\SpecialChar ~
28265 \SpecialChar ~
28266 \SpecialChar ~
28267 \SpecialChar ~
28268 \SpecialChar ~
28269 \SpecialChar ~
28270 \SpecialChar ~
28271 \SpecialChar ~
28272 \SpecialChar ~
28273 \SpecialChar ~
28274 \SpecialChar ~
28275 \SpecialChar ~
28276 \SpecialChar ~
28277 \SpecialChar ~
28278 \SpecialChar ~
28279 \SpecialChar ~
28280 \SpecialChar ~
28281 \SpecialChar ~
28282  68\SpecialChar ~
28283 \SpecialChar ~
28284 \SpecialChar ~
28285 \SpecialChar ~
28286 \SpecialChar ~
28287 \SpecialChar ~
28288 \SpecialChar ~
28289 \SpecialChar ~
28290  rlc\SpecialChar ~
28291 \SpecialChar ~
28292  a 
28293 \newline 
28294 0014 92*00\SpecialChar ~
28295 \SpecialChar ~
28296 \SpecialChar ~
28297 \SpecialChar ~
28298 \SpecialChar ~
28299 \SpecialChar ~
28300 \SpecialChar ~
28301 \SpecialChar ~
28302 \SpecialChar ~
28303 \SpecialChar ~
28304 \SpecialChar ~
28305 \SpecialChar ~
28306 \SpecialChar ~
28307 \SpecialChar ~
28308 \SpecialChar ~
28309  69\SpecialChar ~
28310 \SpecialChar ~
28311 \SpecialChar ~
28312 \SpecialChar ~
28313 \SpecialChar ~
28314 \SpecialChar ~
28315 \SpecialChar ~
28316 \SpecialChar ~
28317  mov\SpecialChar ~
28318 \SpecialChar ~
28319  _foo_hob2_1_1,c 
28320 \newline 
28321 \SpecialChar ~
28322 \SpecialChar ~
28323 \SpecialChar ~
28324 \SpecialChar ~
28325 \SpecialChar ~
28326 \SpecialChar ~
28327 \SpecialChar ~
28328 \SpecialChar ~
28329 \SpecialChar ~
28330 \SpecialChar ~
28331 \SpecialChar ~
28332 \SpecialChar ~
28333 \SpecialChar ~
28334 \SpecialChar ~
28335 \SpecialChar ~
28336 \SpecialChar ~
28337 \SpecialChar ~
28338 \SpecialChar ~
28339 \SpecialChar ~
28340 \SpecialChar ~
28341 \SpecialChar ~
28342 \SpecialChar ~
28343 \SpecialChar ~
28344 \SpecialChar ~
28345 \SpecialChar ~
28346  66 ;\SpecialChar ~
28347  hob.c 9 
28348 \newline 
28349 0016 E5*01\SpecialChar ~
28350 \SpecialChar ~
28351 \SpecialChar ~
28352 \SpecialChar ~
28353 \SpecialChar ~
28354 \SpecialChar ~
28355 \SpecialChar ~
28356 \SpecialChar ~
28357 \SpecialChar ~
28358 \SpecialChar ~
28359 \SpecialChar ~
28360 \SpecialChar ~
28361 \SpecialChar ~
28362 \SpecialChar ~
28363 \SpecialChar ~
28364  67\SpecialChar ~
28365 \SpecialChar ~
28366 \SpecialChar ~
28367 \SpecialChar ~
28368 \SpecialChar ~
28369 \SpecialChar ~
28370 \SpecialChar ~
28371 \SpecialChar ~
28372  mov\SpecialChar ~
28373 \SpecialChar ~
28374  a,(_gint + 1) 
28375 \newline 
28376 0018 33\SpecialChar ~
28377 \SpecialChar ~
28378 \SpecialChar ~
28379 \SpecialChar ~
28380 \SpecialChar ~
28381 \SpecialChar ~
28382 \SpecialChar ~
28383 \SpecialChar ~
28384 \SpecialChar ~
28385 \SpecialChar ~
28386 \SpecialChar ~
28387 \SpecialChar ~
28388 \SpecialChar ~
28389 \SpecialChar ~
28390 \SpecialChar ~
28391 \SpecialChar ~
28392 \SpecialChar ~
28393 \SpecialChar ~
28394  68\SpecialChar ~
28395 \SpecialChar ~
28396 \SpecialChar ~
28397 \SpecialChar ~
28398 \SpecialChar ~
28399 \SpecialChar ~
28400 \SpecialChar ~
28401 \SpecialChar ~
28402  rlc\SpecialChar ~
28403 \SpecialChar ~
28404  a 
28405 \newline 
28406 0019 92*01\SpecialChar ~
28407 \SpecialChar ~
28408 \SpecialChar ~
28409 \SpecialChar ~
28410 \SpecialChar ~
28411 \SpecialChar ~
28412 \SpecialChar ~
28413 \SpecialChar ~
28414 \SpecialChar ~
28415 \SpecialChar ~
28416 \SpecialChar ~
28417 \SpecialChar ~
28418 \SpecialChar ~
28419 \SpecialChar ~
28420 \SpecialChar ~
28421  69\SpecialChar ~
28422 \SpecialChar ~
28423 \SpecialChar ~
28424 \SpecialChar ~
28425 \SpecialChar ~
28426 \SpecialChar ~
28427 \SpecialChar ~
28428 \SpecialChar ~
28429  mov\SpecialChar ~
28430 \SpecialChar ~
28431  _foo_hob3_1_1,c 
28432 \newline 
28433 \SpecialChar ~
28434 \SpecialChar ~
28435 \SpecialChar ~
28436 \SpecialChar ~
28437 \SpecialChar ~
28438 \SpecialChar ~
28439 \SpecialChar ~
28440 \SpecialChar ~
28441 \SpecialChar ~
28442 \SpecialChar ~
28443 \SpecialChar ~
28444 \SpecialChar ~
28445 \SpecialChar ~
28446 \SpecialChar ~
28447 \SpecialChar ~
28448 \SpecialChar ~
28449 \SpecialChar ~
28450 \SpecialChar ~
28451 \SpecialChar ~
28452 \SpecialChar ~
28453 \SpecialChar ~
28454 \SpecialChar ~
28455 \SpecialChar ~
28456 \SpecialChar ~
28457 \SpecialChar ~
28458  70 ;\SpecialChar ~
28459  hob.c 10 
28460 \newline 
28461 001B E5*01\SpecialChar ~
28462 \SpecialChar ~
28463 \SpecialChar ~
28464 \SpecialChar ~
28465 \SpecialChar ~
28466 \SpecialChar ~
28467 \SpecialChar ~
28468 \SpecialChar ~
28469 \SpecialChar ~
28470 \SpecialChar ~
28471 \SpecialChar ~
28472 \SpecialChar ~
28473 \SpecialChar ~
28474 \SpecialChar ~
28475 \SpecialChar ~
28476  71\SpecialChar ~
28477 \SpecialChar ~
28478 \SpecialChar ~
28479 \SpecialChar ~
28480 \SpecialChar ~
28481 \SpecialChar ~
28482 \SpecialChar ~
28483 \SpecialChar ~
28484  mov\SpecialChar ~
28485 \SpecialChar ~
28486  a,(_gint + 1) 
28487 \newline 
28488 001D 03\SpecialChar ~
28489 \SpecialChar ~
28490 \SpecialChar ~
28491 \SpecialChar ~
28492 \SpecialChar ~
28493 \SpecialChar ~
28494 \SpecialChar ~
28495 \SpecialChar ~
28496 \SpecialChar ~
28497 \SpecialChar ~
28498 \SpecialChar ~
28499 \SpecialChar ~
28500 \SpecialChar ~
28501 \SpecialChar ~
28502 \SpecialChar ~
28503 \SpecialChar ~
28504 \SpecialChar ~
28505 \SpecialChar ~
28506  72\SpecialChar ~
28507 \SpecialChar ~
28508 \SpecialChar ~
28509 \SpecialChar ~
28510 \SpecialChar ~
28511 \SpecialChar ~
28512 \SpecialChar ~
28513 \SpecialChar ~
28514  rr\SpecialChar ~
28515 \SpecialChar ~
28516 \SpecialChar ~
28517  a 
28518 \newline 
28519 001E 54 01\SpecialChar ~
28520 \SpecialChar ~
28521 \SpecialChar ~
28522 \SpecialChar ~
28523 \SpecialChar ~
28524 \SpecialChar ~
28525 \SpecialChar ~
28526 \SpecialChar ~
28527 \SpecialChar ~
28528 \SpecialChar ~
28529 \SpecialChar ~
28530 \SpecialChar ~
28531 \SpecialChar ~
28532 \SpecialChar ~
28533 \SpecialChar ~
28534  73\SpecialChar ~
28535 \SpecialChar ~
28536 \SpecialChar ~
28537 \SpecialChar ~
28538 \SpecialChar ~
28539 \SpecialChar ~
28540 \SpecialChar ~
28541 \SpecialChar ~
28542  anl\SpecialChar ~
28543 \SpecialChar ~
28544  a,#0x01 
28545 \newline 
28546 0020 F5*03\SpecialChar ~
28547 \SpecialChar ~
28548 \SpecialChar ~
28549 \SpecialChar ~
28550 \SpecialChar ~
28551 \SpecialChar ~
28552 \SpecialChar ~
28553 \SpecialChar ~
28554 \SpecialChar ~
28555 \SpecialChar ~
28556 \SpecialChar ~
28557 \SpecialChar ~
28558 \SpecialChar ~
28559 \SpecialChar ~
28560 \SpecialChar ~
28561  74\SpecialChar ~
28562 \SpecialChar ~
28563 \SpecialChar ~
28564 \SpecialChar ~
28565 \SpecialChar ~
28566 \SpecialChar ~
28567 \SpecialChar ~
28568 \SpecialChar ~
28569  mov\SpecialChar ~
28570 \SpecialChar ~
28571  _foo_aob1_1_1,a 
28572 \newline 
28573 \SpecialChar ~
28574 \SpecialChar ~
28575 \SpecialChar ~
28576 \SpecialChar ~
28577 \SpecialChar ~
28578 \SpecialChar ~
28579 \SpecialChar ~
28580 \SpecialChar ~
28581 \SpecialChar ~
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 \SpecialChar ~
28585 \SpecialChar ~
28586 \SpecialChar ~
28587 \SpecialChar ~
28588 \SpecialChar ~
28589 \SpecialChar ~
28590 \SpecialChar ~
28591 \SpecialChar ~
28592 \SpecialChar ~
28593 \SpecialChar ~
28594 \SpecialChar ~
28595 \SpecialChar ~
28596 \SpecialChar ~
28597 \SpecialChar ~
28598  75 ;\SpecialChar ~
28599  hob.c 11 
28600 \newline 
28601 0022 E5*01\SpecialChar ~
28602 \SpecialChar ~
28603 \SpecialChar ~
28604 \SpecialChar ~
28605 \SpecialChar ~
28606 \SpecialChar ~
28607 \SpecialChar ~
28608 \SpecialChar ~
28609 \SpecialChar ~
28610 \SpecialChar ~
28611 \SpecialChar ~
28612 \SpecialChar ~
28613 \SpecialChar ~
28614 \SpecialChar ~
28615 \SpecialChar ~
28616  76\SpecialChar ~
28617 \SpecialChar ~
28618 \SpecialChar ~
28619 \SpecialChar ~
28620 \SpecialChar ~
28621 \SpecialChar ~
28622 \SpecialChar ~
28623 \SpecialChar ~
28624  mov\SpecialChar ~
28625 \SpecialChar ~
28626  a,(_gint + 1) 
28627 \newline 
28628 0024 13\SpecialChar ~
28629 \SpecialChar ~
28630 \SpecialChar ~
28631 \SpecialChar ~
28632 \SpecialChar ~
28633 \SpecialChar ~
28634 \SpecialChar ~
28635 \SpecialChar ~
28636 \SpecialChar ~
28637 \SpecialChar ~
28638 \SpecialChar ~
28639 \SpecialChar ~
28640 \SpecialChar ~
28641 \SpecialChar ~
28642 \SpecialChar ~
28643 \SpecialChar ~
28644 \SpecialChar ~
28645 \SpecialChar ~
28646  77\SpecialChar ~
28647 \SpecialChar ~
28648 \SpecialChar ~
28649 \SpecialChar ~
28650 \SpecialChar ~
28651 \SpecialChar ~
28652 \SpecialChar ~
28653 \SpecialChar ~
28654  rrc\SpecialChar ~
28655 \SpecialChar ~
28656  a 
28657 \newline 
28658 0025 92*02\SpecialChar ~
28659 \SpecialChar ~
28660 \SpecialChar ~
28661 \SpecialChar ~
28662 \SpecialChar ~
28663 \SpecialChar ~
28664 \SpecialChar ~
28665 \SpecialChar ~
28666 \SpecialChar ~
28667 \SpecialChar ~
28668 \SpecialChar ~
28669 \SpecialChar ~
28670 \SpecialChar ~
28671 \SpecialChar ~
28672 \SpecialChar ~
28673  78\SpecialChar ~
28674 \SpecialChar ~
28675 \SpecialChar ~
28676 \SpecialChar ~
28677 \SpecialChar ~
28678 \SpecialChar ~
28679 \SpecialChar ~
28680 \SpecialChar ~
28681  mov\SpecialChar ~
28682 \SpecialChar ~
28683  _foo_aob2_1_1,c 
28684 \newline 
28685 \SpecialChar ~
28686 \SpecialChar ~
28687 \SpecialChar ~
28688 \SpecialChar ~
28689 \SpecialChar ~
28690 \SpecialChar ~
28691 \SpecialChar ~
28692 \SpecialChar ~
28693 \SpecialChar ~
28694 \SpecialChar ~
28695 \SpecialChar ~
28696 \SpecialChar ~
28697 \SpecialChar ~
28698 \SpecialChar ~
28699 \SpecialChar ~
28700 \SpecialChar ~
28701 \SpecialChar ~
28702 \SpecialChar ~
28703 \SpecialChar ~
28704 \SpecialChar ~
28705 \SpecialChar ~
28706 \SpecialChar ~
28707 \SpecialChar ~
28708 \SpecialChar ~
28709 \SpecialChar ~
28710  79 ;\SpecialChar ~
28711  hob.c 12 
28712 \newline 
28713 0027 E5*01\SpecialChar ~
28714 \SpecialChar ~
28715 \SpecialChar ~
28716 \SpecialChar ~
28717 \SpecialChar ~
28718 \SpecialChar ~
28719 \SpecialChar ~
28720 \SpecialChar ~
28721 \SpecialChar ~
28722 \SpecialChar ~
28723 \SpecialChar ~
28724 \SpecialChar ~
28725 \SpecialChar ~
28726 \SpecialChar ~
28727 \SpecialChar ~
28728  80\SpecialChar ~
28729 \SpecialChar ~
28730 \SpecialChar ~
28731 \SpecialChar ~
28732 \SpecialChar ~
28733 \SpecialChar ~
28734 \SpecialChar ~
28735 \SpecialChar ~
28736  mov\SpecialChar ~
28737 \SpecialChar ~
28738  a,(_gint + 1) 
28739 \newline 
28740 0029 A2 E3\SpecialChar ~
28741 \SpecialChar ~
28742 \SpecialChar ~
28743 \SpecialChar ~
28744 \SpecialChar ~
28745 \SpecialChar ~
28746 \SpecialChar ~
28747 \SpecialChar ~
28748 \SpecialChar ~
28749 \SpecialChar ~
28750 \SpecialChar ~
28751 \SpecialChar ~
28752 \SpecialChar ~
28753 \SpecialChar ~
28754 \SpecialChar ~
28755  81\SpecialChar ~
28756 \SpecialChar ~
28757 \SpecialChar ~
28758 \SpecialChar ~
28759 \SpecialChar ~
28760 \SpecialChar ~
28761 \SpecialChar ~
28762 \SpecialChar ~
28763  mov\SpecialChar ~
28764 \SpecialChar ~
28765  c,acc[3] 
28766 \newline 
28767 002B 92*03\SpecialChar ~
28768 \SpecialChar ~
28769 \SpecialChar ~
28770 \SpecialChar ~
28771 \SpecialChar ~
28772 \SpecialChar ~
28773 \SpecialChar ~
28774 \SpecialChar ~
28775 \SpecialChar ~
28776 \SpecialChar ~
28777 \SpecialChar ~
28778 \SpecialChar ~
28779 \SpecialChar ~
28780 \SpecialChar ~
28781 \SpecialChar ~
28782  82\SpecialChar ~
28783 \SpecialChar ~
28784 \SpecialChar ~
28785 \SpecialChar ~
28786 \SpecialChar ~
28787 \SpecialChar ~
28788 \SpecialChar ~
28789 \SpecialChar ~
28790  mov\SpecialChar ~
28791 \SpecialChar ~
28792  _foo_aob3_1_1,c 
28793 \layout Standard
28794
28795 Other variations of these cases however will 
28796 \emph on 
28797 not
28798 \emph default 
28799  be recognized.
28800  They are standard C expressions, so I heartily recommend these be the only
28801  way to get the highest order bit, (it is portable).
28802  Of course it will be recognized even if it is embedded in other expressions,
28803  e.g.:
28804 \layout Verse
28805
28806
28807 \family typewriter 
28808 xyz = gint + ((gint >> 15) & 1);
28809 \layout Standard
28810
28811 will still be recognized.
28812 \layout Subsection
28813
28814 Higher Order Byte
28815 \begin_inset LatexCommand \index{Higher Order Byte}
28816
28817 \end_inset 
28818
28819  / Higher Order Word
28820 \begin_inset LatexCommand \index{Higher Order Word}
28821
28822 \end_inset 
28823
28824
28825 \layout Standard
28826
28827 It is also frequently required to obtain a higher order byte or word of
28828  a larger integral type (long, int or short types).
28829  SDCC recognizes the following expressions to yield the higher order byte
28830  or word and generates optimized code for it, e.g.:
28831 \layout Verse
28832
28833
28834 \family typewriter 
28835 unsigned int gint; 
28836 \newline 
28837 unsigned long int glong; 
28838 \newline 
28839
28840 \newline 
28841 foo () { 
28842 \newline 
28843 \SpecialChar ~
28844 \SpecialChar ~
28845 unsigned char hob1, hob2; 
28846 \newline 
28847 \SpecialChar ~
28848 \SpecialChar ~
28849 unsigned int how1, how2; 
28850 \newline 
28851 \SpecialChar ~
28852 \SpecialChar ~
28853 ...
28854  
28855 \newline 
28856 \SpecialChar ~
28857 \SpecialChar ~
28858 hob1 = (gint >> 8) & 0xFF; 
28859 \newline 
28860 \SpecialChar ~
28861 \SpecialChar ~
28862 hob2 = glong >> 24; 
28863 \newline 
28864 \SpecialChar ~
28865 \SpecialChar ~
28866 how1 = (glong >> 16) & 0xFFFF; 
28867 \newline 
28868 \SpecialChar ~
28869 \SpecialChar ~
28870 how2 = glong >> 8; 
28871 \newline 
28872 \SpecialChar ~
28873 \SpecialChar ~
28874 ..
28875  
28876 \newline 
28877 }
28878 \layout Standard
28879
28880 will generate the following code:
28881 \layout Verse
28882
28883
28884 \family typewriter 
28885 \SpecialChar ~
28886 \SpecialChar ~
28887 \SpecialChar ~
28888 \SpecialChar ~
28889 \SpecialChar ~
28890 \SpecialChar ~
28891 \SpecialChar ~
28892 \SpecialChar ~
28893 \SpecialChar ~
28894 \SpecialChar ~
28895 \SpecialChar ~
28896 \SpecialChar ~
28897 \SpecialChar ~
28898 \SpecialChar ~
28899 \SpecialChar ~
28900 \SpecialChar ~
28901 \SpecialChar ~
28902 \SpecialChar ~
28903 \SpecialChar ~
28904 \SpecialChar ~
28905 \SpecialChar ~
28906 \SpecialChar ~
28907 \SpecialChar ~
28908 \SpecialChar ~
28909 \SpecialChar ~
28910  91 ;\SpecialChar ~
28911  hob.c 15 
28912 \newline 
28913 0037 85*01*06\SpecialChar ~
28914 \SpecialChar ~
28915 \SpecialChar ~
28916 \SpecialChar ~
28917 \SpecialChar ~
28918 \SpecialChar ~
28919 \SpecialChar ~
28920 \SpecialChar ~
28921 \SpecialChar ~
28922 \SpecialChar ~
28923 \SpecialChar ~
28924 \SpecialChar ~
28925  92\SpecialChar ~
28926 \SpecialChar ~
28927 \SpecialChar ~
28928 \SpecialChar ~
28929 \SpecialChar ~
28930 \SpecialChar ~
28931 \SpecialChar ~
28932 \SpecialChar ~
28933  mov\SpecialChar ~
28934 \SpecialChar ~
28935  _foo_hob1_1_1,(_gint + 1) 
28936 \newline 
28937 \SpecialChar ~
28938 \SpecialChar ~
28939 \SpecialChar ~
28940 \SpecialChar ~
28941 \SpecialChar ~
28942 \SpecialChar ~
28943 \SpecialChar ~
28944 \SpecialChar ~
28945 \SpecialChar ~
28946 \SpecialChar ~
28947 \SpecialChar ~
28948 \SpecialChar ~
28949 \SpecialChar ~
28950 \SpecialChar ~
28951 \SpecialChar ~
28952 \SpecialChar ~
28953 \SpecialChar ~
28954 \SpecialChar ~
28955 \SpecialChar ~
28956 \SpecialChar ~
28957 \SpecialChar ~
28958 \SpecialChar ~
28959 \SpecialChar ~
28960 \SpecialChar ~
28961 \SpecialChar ~
28962  93 ;\SpecialChar ~
28963  hob.c 16 
28964 \newline 
28965 003A 85*05*07\SpecialChar ~
28966 \SpecialChar ~
28967 \SpecialChar ~
28968 \SpecialChar ~
28969 \SpecialChar ~
28970 \SpecialChar ~
28971 \SpecialChar ~
28972 \SpecialChar ~
28973 \SpecialChar ~
28974 \SpecialChar ~
28975 \SpecialChar ~
28976 \SpecialChar ~
28977  94\SpecialChar ~
28978 \SpecialChar ~
28979 \SpecialChar ~
28980 \SpecialChar ~
28981 \SpecialChar ~
28982 \SpecialChar ~
28983 \SpecialChar ~
28984 \SpecialChar ~
28985  mov\SpecialChar ~
28986 \SpecialChar ~
28987  _foo_hob2_1_1,(_glong + 3) 
28988 \newline 
28989 \SpecialChar ~
28990 \SpecialChar ~
28991 \SpecialChar ~
28992 \SpecialChar ~
28993 \SpecialChar ~
28994 \SpecialChar ~
28995 \SpecialChar ~
28996 \SpecialChar ~
28997 \SpecialChar ~
28998 \SpecialChar ~
28999 \SpecialChar ~
29000 \SpecialChar ~
29001 \SpecialChar ~
29002 \SpecialChar ~
29003 \SpecialChar ~
29004 \SpecialChar ~
29005 \SpecialChar ~
29006 \SpecialChar ~
29007 \SpecialChar ~
29008 \SpecialChar ~
29009 \SpecialChar ~
29010 \SpecialChar ~
29011 \SpecialChar ~
29012 \SpecialChar ~
29013 \SpecialChar ~
29014  95 ;\SpecialChar ~
29015  hob.c 17 
29016 \newline 
29017 003D 85*04*08\SpecialChar ~
29018 \SpecialChar ~
29019 \SpecialChar ~
29020 \SpecialChar ~
29021 \SpecialChar ~
29022 \SpecialChar ~
29023 \SpecialChar ~
29024 \SpecialChar ~
29025 \SpecialChar ~
29026 \SpecialChar ~
29027 \SpecialChar ~
29028 \SpecialChar ~
29029  96\SpecialChar ~
29030 \SpecialChar ~
29031 \SpecialChar ~
29032 \SpecialChar ~
29033 \SpecialChar ~
29034 \SpecialChar ~
29035 \SpecialChar ~
29036 \SpecialChar ~
29037  mov\SpecialChar ~
29038 \SpecialChar ~
29039  _foo_how1_1_1,(_glong + 2) 
29040 \newline 
29041 0040 85*05*09\SpecialChar ~
29042 \SpecialChar ~
29043 \SpecialChar ~
29044 \SpecialChar ~
29045 \SpecialChar ~
29046 \SpecialChar ~
29047 \SpecialChar ~
29048 \SpecialChar ~
29049 \SpecialChar ~
29050 \SpecialChar ~
29051 \SpecialChar ~
29052 \SpecialChar ~
29053  97\SpecialChar ~
29054 \SpecialChar ~
29055 \SpecialChar ~
29056 \SpecialChar ~
29057 \SpecialChar ~
29058 \SpecialChar ~
29059 \SpecialChar ~
29060 \SpecialChar ~
29061  mov\SpecialChar ~
29062 \SpecialChar ~
29063  (_foo_how1_1_1 + 1),(_glong + 3) 
29064 \newline 
29065 0043 85*03*0A\SpecialChar ~
29066 \SpecialChar ~
29067 \SpecialChar ~
29068 \SpecialChar ~
29069 \SpecialChar ~
29070 \SpecialChar ~
29071 \SpecialChar ~
29072 \SpecialChar ~
29073 \SpecialChar ~
29074 \SpecialChar ~
29075 \SpecialChar ~
29076 \SpecialChar ~
29077  98\SpecialChar ~
29078 \SpecialChar ~
29079 \SpecialChar ~
29080 \SpecialChar ~
29081 \SpecialChar ~
29082 \SpecialChar ~
29083 \SpecialChar ~
29084 \SpecialChar ~
29085  mov\SpecialChar ~
29086 \SpecialChar ~
29087  _foo_how2_1_1,(_glong + 1) 
29088 \newline 
29089 0046 85*04*0B\SpecialChar ~
29090 \SpecialChar ~
29091 \SpecialChar ~
29092 \SpecialChar ~
29093 \SpecialChar ~
29094 \SpecialChar ~
29095 \SpecialChar ~
29096 \SpecialChar ~
29097 \SpecialChar ~
29098 \SpecialChar ~
29099 \SpecialChar ~
29100 \SpecialChar ~
29101  99\SpecialChar ~
29102 \SpecialChar ~
29103 \SpecialChar ~
29104 \SpecialChar ~
29105 \SpecialChar ~
29106 \SpecialChar ~
29107 \SpecialChar ~
29108 \SpecialChar ~
29109  mov\SpecialChar ~
29110 \SpecialChar ~
29111  (_foo_how2_1_1 + 1),(_glong + 2) 
29112 \layout Standard
29113
29114 Again, variations of these cases may 
29115 \emph on 
29116 not
29117 \emph default 
29118  be recognized.
29119  They are standard C expressions, so I heartily recommend these be the only
29120  way to get the higher order byte/word, (it is portable).
29121  Of course it will be recognized even if it is embedded in other expressions,
29122  e.g.:
29123 \layout Verse
29124
29125
29126 \family typewriter 
29127 xyz = gint + ((gint >> 8) & 0xFF);
29128 \layout Standard
29129
29130 will still be recognized.
29131 \layout Subsection
29132
29133 Peephole Optimizer
29134 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
29135
29136 \end_inset 
29137
29138
29139 \begin_inset LatexCommand \index{Peephole optimizer}
29140
29141 \end_inset 
29142
29143
29144 \layout Standard
29145
29146 The compiler uses a rule based, pattern matching and re-writing mechanism
29147  for peep-hole optimization.
29148  It is inspired by 
29149 \emph on 
29150 copt
29151 \emph default 
29152  a peep-hole optimizer by Christopher W.
29153  Fraser (cwfraser\SpecialChar ~
29154 @\SpecialChar ~
29155 microsoft.com).
29156  A default set of rules are compiled into the compiler, additional rules
29157  may be added with the 
29158 \emph on 
29159 -
29160 \begin_inset ERT
29161 status Collapsed
29162
29163 \layout Standard
29164
29165 \backslash 
29166 /
29167 \end_inset 
29168
29169 -peep-file
29170 \begin_inset LatexCommand \index{-\/-peep-file}
29171
29172 \end_inset 
29173
29174  <filename>
29175 \emph default 
29176  option.
29177  The rule language is best illustrated with examples.
29178 \layout Verse
29179
29180
29181 \family typewriter 
29182 replace { 
29183 \newline 
29184 \SpecialChar ~
29185 \SpecialChar ~
29186 mov %1,a 
29187 \newline 
29188 \SpecialChar ~
29189 \SpecialChar ~
29190 mov a,%1
29191 \newline 
29192 } by {
29193 \newline 
29194 \SpecialChar ~
29195 \SpecialChar ~
29196 mov %1,a
29197 \newline 
29198 }
29199 \layout Standard
29200
29201 The above rule will change the following assembly
29202 \begin_inset LatexCommand \index{Assembler routines}
29203
29204 \end_inset 
29205
29206  sequence:
29207 \layout Verse
29208
29209
29210 \family typewriter 
29211 mov r1,a 
29212 \newline 
29213 mov a,r1
29214 \layout Standard
29215
29216 to
29217 \layout Verse
29218
29219
29220 \family typewriter 
29221 mov r1,a
29222 \layout Standard
29223
29224 Note: All occurrences of a 
29225 \emph on 
29226 %n
29227 \emph default 
29228  (pattern variable) must denote the same string.
29229  With the above rule, the assembly sequence:
29230 \layout Verse
29231
29232
29233 \family typewriter 
29234 mov r1,a 
29235 \newline 
29236 mov a,r2
29237 \layout Standard
29238
29239 will remain unmodified.
29240 \newline 
29241
29242 \newline 
29243 Other special case optimizations may be added by the user (via 
29244 \emph on 
29245 -
29246 \begin_inset ERT
29247 status Collapsed
29248
29249 \layout Standard
29250
29251 \backslash 
29252 /
29253 \end_inset 
29254
29255 -peep-file option
29256 \emph default 
29257 ).
29258  E.g.
29259  some variants of the 8051 MCU
29260 \begin_inset LatexCommand \index{MCS51 variants}
29261
29262 \end_inset 
29263
29264  allow only 
29265 \family typewriter 
29266 ajmp
29267 \family default 
29268  and 
29269 \family typewriter 
29270 acall
29271 \family default 
29272 .
29273  The following two rules will change all 
29274 \family typewriter 
29275 ljmp
29276 \family default 
29277  and 
29278 \family typewriter 
29279 lcall
29280 \family default 
29281  to 
29282 \family typewriter 
29283 ajmp
29284 \family default 
29285  and 
29286 \family typewriter 
29287 acall
29288 \layout Verse
29289
29290
29291 \family typewriter 
29292 replace { lcall %1 } by { acall %1 } 
29293 \newline 
29294 replace { ljmp %1 } by { ajmp %1 }
29295 \layout Standard
29296
29297 The 
29298 \emph on 
29299 inline-assembler code
29300 \emph default 
29301  is also passed through the peep hole optimizer, thus the peephole optimizer
29302  can also be used as an assembly level macro expander.
29303  The rules themselves are MCU dependent whereas the rule language infra-structur
29304 e is MCU independent.
29305  Peephole optimization rules for other MCU can be easily programmed using
29306  the rule language.
29307 \newline 
29308
29309 \newline 
29310 The syntax for a rule is as follows:
29311 \layout Verse
29312
29313
29314 \family typewriter 
29315 rule := replace [ restart ] '{' <assembly sequence> '
29316 \backslash 
29317 n' 
29318 \newline 
29319 \SpecialChar ~
29320  \SpecialChar ~
29321  \SpecialChar ~
29322  \SpecialChar ~
29323  \SpecialChar ~
29324  \SpecialChar ~
29325  \SpecialChar ~
29326  \SpecialChar ~
29327  \SpecialChar ~
29328  \SpecialChar ~
29329  \SpecialChar ~
29330  \SpecialChar ~
29331  \SpecialChar ~
29332  \SpecialChar ~
29333  '}' by '{' '
29334 \backslash 
29335 n' 
29336 \newline 
29337 \SpecialChar ~
29338  \SpecialChar ~
29339  \SpecialChar ~
29340  \SpecialChar ~
29341  \SpecialChar ~
29342  \SpecialChar ~
29343  \SpecialChar ~
29344  \SpecialChar ~
29345  \SpecialChar ~
29346  \SpecialChar ~
29347  \SpecialChar ~
29348  \SpecialChar ~
29349  \SpecialChar ~
29350  \SpecialChar ~
29351  \SpecialChar ~
29352  \SpecialChar ~
29353  <assembly sequence> '
29354 \backslash 
29355 n' 
29356 \newline 
29357 \SpecialChar ~
29358  \SpecialChar ~
29359  \SpecialChar ~
29360  \SpecialChar ~
29361  \SpecialChar ~
29362  \SpecialChar ~
29363  \SpecialChar ~
29364  \SpecialChar ~
29365  \SpecialChar ~
29366  \SpecialChar ~
29367  \SpecialChar ~
29368  \SpecialChar ~
29369  \SpecialChar ~
29370  \SpecialChar ~
29371  '}' [if <functionName> ] '
29372 \backslash 
29373 n' 
29374 \layout Standard
29375
29376 <assembly sequence> := assembly instruction (each instruction including
29377  labels must be on a separate line).
29378 \newline 
29379
29380 \newline 
29381 The optimizer will apply to the rules one by one from the top in the sequence
29382  of their appearance, it will terminate when all rules are exhausted.
29383  If the 'restart' option is specified, then the optimizer will start matching
29384  the rules again from the top, this option for a rule is expensive (performance)
29385 , it is intended to be used in situations where a transformation will trigger
29386  the same rule again.
29387  An example of this (not a good one, it has side effects) is the following
29388  rule:
29389 \layout Verse
29390
29391
29392 \family typewriter 
29393 replace restart { 
29394 \newline 
29395 \SpecialChar ~
29396 \SpecialChar ~
29397 pop %1 
29398 \newline 
29399 \SpecialChar ~
29400 \SpecialChar ~
29401 push %1 } by { 
29402 \newline 
29403 \SpecialChar ~
29404 \SpecialChar ~
29405 ; nop 
29406 \newline 
29407 }
29408 \layout Standard
29409
29410 Note that the replace pattern cannot be a blank, but can be a comment line.
29411  Without the 'restart' option only the innermost 'pop' 'push' pair would
29412  be eliminated, i.e.:
29413 \layout Verse
29414
29415
29416 \family typewriter 
29417 pop ar1 
29418 \newline 
29419 pop ar2 
29420 \newline 
29421 push ar2 
29422 \newline 
29423 push ar1
29424 \layout Standard
29425
29426 would result in:
29427 \layout Verse
29428
29429
29430 \family typewriter 
29431 pop ar1 
29432 \newline 
29433 ; nop 
29434 \newline 
29435 push ar1
29436 \layout Standard
29437
29438
29439 \emph on 
29440 with
29441 \emph default 
29442  the restart option the rule will be applied again to the resulting code
29443  and then all the pop-push pairs will be eliminated to yield:
29444 \layout Verse
29445
29446
29447 \family typewriter 
29448 ; nop 
29449 \newline 
29450 ; nop
29451 \layout Standard
29452
29453 A conditional function can be attached to a rule.
29454  Attaching rules are somewhat more involved, let me illustrate this with
29455  an example.
29456 \layout Verse
29457
29458
29459 \family typewriter 
29460 replace { 
29461 \newline 
29462 \SpecialChar ~
29463  \SpecialChar ~
29464  \SpecialChar ~
29465 ljmp %5 
29466 \newline 
29467 %2:
29468 \newline 
29469 } by { 
29470 \newline 
29471 \SpecialChar ~
29472  \SpecialChar ~
29473  \SpecialChar ~
29474 sjmp %5 
29475 \newline 
29476 %2:
29477 \newline 
29478 } if labelInRange
29479 \layout Standard
29480
29481 The optimizer does a look-up of a function name table defined in function
29482  
29483 \emph on 
29484 callFuncByName
29485 \emph default 
29486  in the source file SDCCpeeph.c, with the name 
29487 \emph on 
29488 labelInRange
29489 \emph default 
29490 .
29491  If it finds a corresponding entry the function is called.
29492  Note there can be no parameters specified for these functions, in this
29493  case the use of 
29494 \emph on 
29495 %5
29496 \emph default 
29497  is crucial, since the function 
29498 \emph on 
29499 labelInRange
29500 \emph default 
29501  expects to find the label in that particular variable (the hash table containin
29502 g the variable bindings is passed as a parameter).
29503  If you want to code more such functions, take a close look at the function
29504  labelInRange and the calling mechanism in source file SDCCpeeph.c.
29505  Currently implemented are 
29506 \emph on 
29507 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
29508  24bitMode, portIsDS390, 24bitModeAndPortDS390 
29509 \emph default 
29510 and
29511 \emph on 
29512  notVolatile
29513 \emph default 
29514 .
29515 \layout Standard
29516
29517 I know this whole thing is a little kludgey, but maybe some day we will
29518  have some better means.
29519  If you are looking at this file, you will see the default rules that are
29520  compiled into the compiler, you can add your own rules in the default set
29521  there if you get tired of specifying the -
29522 \begin_inset ERT
29523 status Collapsed
29524
29525 \layout Standard
29526
29527 \backslash 
29528 /
29529 \end_inset 
29530
29531 -peep-file option.
29532 \layout Section
29533
29534 ANSI-Compliance
29535 \begin_inset LatexCommand \index{ANSI-compliance}
29536
29537 \end_inset 
29538
29539
29540 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
29541
29542 \end_inset 
29543
29544
29545 \layout Standard
29546
29547 The latest publically available version of the standard 
29548 \emph on 
29549 ISO/IEC 9899 - Programming languages - C
29550 \emph default 
29551  should be available at: 
29552 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29553
29554 \end_inset 
29555
29556 .
29557 \newline 
29558
29559 \layout Standard
29560
29561 Deviations from the compliance:
29562 \layout Itemize
29563
29564 functions are not reentrant
29565 \begin_inset LatexCommand \index{reentrant}
29566
29567 \end_inset 
29568
29569  unless explicitly declared as such or the 
29570 \series bold 
29571 -
29572 \begin_inset ERT
29573 status Collapsed
29574
29575 \layout Standard
29576
29577 \backslash 
29578 /
29579 \end_inset 
29580
29581 -stack-auto
29582 \begin_inset LatexCommand \index{-\/-stack-auto}
29583
29584 \end_inset 
29585
29586
29587 \series default 
29588  command line option is specified.
29589 \layout Itemize
29590
29591 structures
29592 \begin_inset LatexCommand \index{struct}
29593
29594 \end_inset 
29595
29596  and unions
29597 \begin_inset LatexCommand \index{union}
29598
29599 \end_inset 
29600
29601  cannot be assigned values directly, cannot be passed as function parameters
29602  or assigned to each other and cannot be a return value
29603 \begin_inset LatexCommand \index{return value}
29604
29605 \end_inset 
29606
29607  from a function, e.g.:
29608 \begin_deeper 
29609 \layout Verse
29610
29611
29612 \family typewriter 
29613 struct s { ...
29614  }; 
29615 \newline 
29616 struct s s1, s2; 
29617 \newline 
29618 foo() 
29619 \newline 
29620
29621 \newline 
29622 \SpecialChar ~
29623 \SpecialChar ~
29624 \SpecialChar ~
29625 \SpecialChar ~
29626 ...
29627  
29628 \newline 
29629 \SpecialChar ~
29630 \SpecialChar ~
29631 \SpecialChar ~
29632 \SpecialChar ~
29633 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
29634 \newline 
29635 \SpecialChar ~
29636 \SpecialChar ~
29637 \SpecialChar ~
29638 \SpecialChar ~
29639 ...
29640  
29641 \newline 
29642 }
29643 \newline 
29644
29645 \series bold 
29646 struct
29647 \series default 
29648  s foo1 (
29649 \series bold 
29650 struct
29651 \series default 
29652  s parms) /* invalid in SDCC although allowed in ANSI */
29653 \newline 
29654
29655 \newline 
29656 \SpecialChar ~
29657 \SpecialChar ~
29658 \SpecialChar ~
29659 \SpecialChar ~
29660 struct s rets; 
29661 \newline 
29662 \SpecialChar ~
29663 \SpecialChar ~
29664 \SpecialChar ~
29665 \SpecialChar ~
29666 ...
29667  
29668 \newline 
29669 \SpecialChar ~
29670 \SpecialChar ~
29671 \SpecialChar ~
29672 \SpecialChar ~
29673 return rets; /* is invalid in SDCC although allowed in ANSI */ 
29674 \newline 
29675 }
29676 \end_deeper 
29677 \layout Itemize
29678
29679 initialization of structure arrays must be fully braced.
29680 \begin_deeper 
29681 \layout Verse
29682
29683
29684 \family typewriter 
29685 struct s { char x } a[] = {1, 2};\SpecialChar ~
29686 \SpecialChar ~
29687 \SpecialChar ~
29688 \SpecialChar ~
29689 \SpecialChar ~
29690 /* invalid in SDCC */
29691 \newline 
29692 struct s { char x } a[] = {{1}, {2}}; /* OK */
29693 \end_deeper 
29694 \layout Itemize
29695
29696 'long long
29697 \begin_inset LatexCommand \index{long long (not supported)}
29698
29699 \end_inset 
29700
29701 ' (64 bit integers
29702 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29703
29704 \end_inset 
29705
29706 ) not supported.
29707 \layout Itemize
29708
29709 'double
29710 \begin_inset LatexCommand \index{double (not supported)}
29711
29712 \end_inset 
29713
29714 ' precision floating point 
29715 \begin_inset LatexCommand \index{Floating point support}
29716
29717 \end_inset 
29718
29719 not supported.
29720 \layout Itemize
29721
29722 Old K&R style
29723 \begin_inset LatexCommand \index{K\&R style}
29724
29725 \end_inset 
29726
29727  function declarations are NOT allowed.
29728 \begin_deeper 
29729 \layout Verse
29730
29731
29732 \family typewriter 
29733 foo(i,j) /* this old style of function declarations */ 
29734 \newline 
29735 int i,j; /* are valid in ANSI but not valid in SDCC */ 
29736 \newline 
29737
29738 \newline 
29739 \SpecialChar ~
29740 \SpecialChar ~
29741 \SpecialChar ~
29742 \SpecialChar ~
29743 ...
29744  
29745 \newline 
29746 }
29747 \end_deeper 
29748 \layout Itemize
29749
29750 Most enhancements in C99 are not supported, f.e.:
29751 \begin_deeper 
29752 \layout Verse
29753
29754
29755 \family typewriter 
29756 \series bold 
29757 inline
29758 \begin_inset LatexCommand \index{inline (not supported)}
29759
29760 \end_inset 
29761
29762
29763 \series default 
29764  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29765  in C99.
29766  An empty define 
29767 \emph on 
29768 #define inline
29769 \emph default 
29770  can be used as a work around */
29771 \newline 
29772
29773 \newline 
29774 for (
29775 \series bold 
29776 int
29777 \series default 
29778  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29779 \end_deeper 
29780 \layout Itemize
29781
29782 Certain words that are valid identifiers in the standard may be reserved
29783  words in SDCC unless the 
29784 \series bold 
29785 -
29786 \begin_inset ERT
29787 status Collapsed
29788
29789 \layout Standard
29790
29791 \backslash 
29792 /
29793 \end_inset 
29794
29795 -std-c89
29796 \begin_inset LatexCommand \index{-\/-std-c89}
29797
29798 \end_inset 
29799
29800  or -
29801 \begin_inset ERT
29802 status Collapsed
29803
29804 \layout Standard
29805
29806 \backslash 
29807 /
29808 \end_inset 
29809
29810 -std-c99
29811 \begin_inset LatexCommand \index{-\/-std-c99}
29812
29813 \end_inset 
29814
29815
29816 \series default 
29817  command line options are used.
29818  These may include (depending on the selected processor): 'at', 'banked',
29819  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29820 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29821  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29822  '_naked'.
29823  Compliant equivalents of these keywords are always available in a form
29824  that begin with two underscores
29825 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29826
29827 \end_inset 
29828
29829 , f.e.
29830  '__data' instead of 'data'.
29831 \layout Section
29832
29833 Cyclomatic Complexity
29834 \begin_inset LatexCommand \index{Cyclomatic complexity}
29835
29836 \end_inset 
29837
29838
29839 \layout Standard
29840
29841 Cyclomatic complexity of a function is defined as the number of independent
29842  paths the program can take during execution of the function.
29843  This is an important number since it defines the number test cases you
29844  have to generate to validate the function.
29845  The accepted industry standard for complexity number is 10, if the cyclomatic
29846  complexity reported by SDCC exceeds 10 you should think about simplification
29847  of the function logic.
29848  Note that the complexity level is not related to the number of lines of
29849  code in a function.
29850  Large functions can have low complexity, and small functions can have large
29851  complexity levels.
29852  
29853 \newline 
29854
29855 \newline 
29856 SDCC uses the following formula to compute the complexity:
29857 \newline 
29858
29859 \layout Standard
29860
29861 complexity = (number of edges in control flow graph) - (number of nodes
29862  in control flow graph) + 2;
29863 \newline 
29864
29865 \newline 
29866 Having said that the industry standard is 10, you should be aware that in
29867  some cases it be may unavoidable to have a complexity level of less than
29868  10.
29869  For example if you have switch statement with more than 10 case labels,
29870  each case label adds one to the complexity level.
29871  The complexity level is by no means an absolute measure of the algorithmic
29872  complexity of the function, it does however provide a good starting point
29873  for which functions you might look at for further optimization.
29874 \layout Section
29875
29876 Retargetting for other Processors
29877 \layout Standard
29878
29879 The issues for retargetting the compiler are far too numerous to be covered
29880  by this document.
29881  What follows is a brief description of each of the seven phases of the
29882  compiler and its MCU dependency.
29883 \layout Itemize
29884
29885 Parsing the source and building the annotated parse tree.
29886  This phase is largely MCU independent (except for the language extensions).
29887  Syntax & semantic checks are also done in this phase, along with some initial
29888  optimizations like back patching labels and the pattern matching optimizations
29889  like bit-rotation etc.
29890 \layout Itemize
29891
29892 The second phase involves generating an intermediate code which can be easy
29893  manipulated during the later phases.
29894  This phase is entirely MCU independent.
29895  The intermediate code generation assumes the target machine has unlimited
29896  number of registers, and designates them with the name iTemp.
29897  The compiler can be made to dump a human readable form of the code generated
29898  by using the -
29899 \begin_inset ERT
29900 status Collapsed
29901
29902 \layout Standard
29903
29904 \backslash 
29905 /
29906 \end_inset 
29907
29908 -dumpraw option.
29909 \layout Itemize
29910
29911 This phase does the bulk of the standard optimizations and is also MCU independe
29912 nt.
29913  This phase can be broken down into several sub-phases:
29914 \newline 
29915
29916 \newline 
29917 Break down intermediate code (iCode) into basic blocks.
29918 \newline 
29919 Do control flow & data flow analysis on the basic blocks.
29920 \newline 
29921 Do local common subexpression elimination, then global subexpression elimination
29922 \newline 
29923 Dead code elimination
29924 \newline 
29925 Loop optimizations
29926 \newline 
29927 If loop optimizations caused any changes then do 'global subexpression eliminati
29928 on' and 'dead code elimination' again.
29929 \layout Itemize
29930
29931 This phase determines the live-ranges; by live range I mean those iTemp
29932  variables defined by the compiler that still survive after all the optimization
29933 s.
29934  Live range analysis
29935 \begin_inset LatexCommand \index{Live range analysis}
29936
29937 \end_inset 
29938
29939  is essential for register allocation, since these computation determines
29940  which of these iTemps will be assigned to registers, and for how long.
29941 \layout Itemize
29942
29943 Phase five is register allocation.
29944  There are two parts to this process.
29945 \newline 
29946
29947 \newline 
29948 The first part I call 'register packing' (for lack of a better term).
29949  In this case several MCU specific expression folding is done to reduce
29950  register pressure.
29951 \newline 
29952
29953 \newline 
29954 The second part is more MCU independent and deals with allocating registers
29955  to the remaining live ranges.
29956  A lot of MCU specific code does creep into this phase because of the limited
29957  number of index registers available in the 8051.
29958 \layout Itemize
29959
29960 The Code generation phase is (unhappily), entirely MCU dependent and very
29961  little (if any at all) of this code can be reused for other MCU.
29962  However the scheme for allocating a homogenized assembler operand for each
29963  iCode operand may be reused.
29964 \layout Itemize
29965
29966 As mentioned in the optimization section the peep-hole optimizer is rule
29967  based system, which can reprogrammed for other MCUs.
29968 \layout Standard
29969
29970 More information is available in a wiki
29971 \begin_inset LatexCommand \index{wiki}
29972
29973 \end_inset 
29974
29975  (preliminary link 
29976 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
29977
29978 \end_inset 
29979
29980 ) and in the thread 
29981 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
29982
29983 \end_inset 
29984
29985  .
29986 \layout Chapter
29987
29988 Compiler internals
29989 \begin_inset LatexCommand \index{Compiler internals}
29990
29991 \end_inset 
29992
29993
29994 \layout Section
29995
29996 The anatomy of the compiler
29997 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29998
29999 \end_inset 
30000
30001
30002 \layout Standard
30003
30004
30005 \shape italic 
30006 This is an excerpt from an article published in Circuit Cellar Magazine
30007  in 
30008 \series bold 
30009 August 2000
30010 \series default 
30011 .
30012  It's a little outdated (the compiler is much more efficient now and user/develo
30013 per friendly), but pretty well exposes the guts of it all.
30014 \shape default 
30015
30016 \newline 
30017
30018 \newline 
30019 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
30020  It is fairly easy to retarget for other 8-bit MCU.
30021  Here we take a look at some of the internals of the compiler.
30022  
30023 \layout Paragraph*
30024
30025 Parsing
30026 \begin_inset LatexCommand \index{Parsing}
30027
30028 \end_inset 
30029
30030  
30031 \layout Standard
30032
30033 Parsing the input source file and creating an AST (Annotated Syntax Tree
30034 \begin_inset LatexCommand \index{Annotated syntax tree}
30035
30036 \end_inset 
30037
30038 ).
30039  This phase also involves propagating types (annotating each node of the
30040  parse tree with type information) and semantic analysis.
30041  There are some MCU specific parsing rules.
30042  For example the storage classes, the extended storage classes are MCU specific
30043  while there may be a xdata storage class for 8051 there is no such storage
30044  class for z80 or Atmel AVR.
30045  SDCC allows MCU specific storage class extensions, i.e.
30046  xdata will be treated as a storage class specifier when parsing 8051 C
30047  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
30048  C code.
30049 \layout Paragraph*
30050
30051 Generating iCode
30052 \begin_inset LatexCommand \index{iCode}
30053
30054 \end_inset 
30055
30056
30057 \layout Standard
30058
30059 Intermediate code generation.
30060  In this phase the AST is broken down into three-operand form (iCode).
30061  These three operand forms are represented as doubly linked lists.
30062  ICode is the term given to the intermediate form generated by the compiler.
30063  ICode example section shows some examples of iCode generated for some simple
30064  C source functions.
30065 \layout Paragraph*
30066
30067 Optimizations
30068 \begin_inset LatexCommand \index{Optimizations}
30069
30070 \end_inset 
30071
30072 .
30073 \layout Standard
30074
30075 Bulk of the target independent optimizations is performed in this phase.
30076  The optimizations include constant propagation, common sub-expression eliminati
30077 on, loop invariant code movement, strength reduction of loop induction variables
30078  and dead-code elimination.
30079 \layout Paragraph*
30080
30081 Live range analysis
30082 \begin_inset LatexCommand \index{Live range analysis}
30083
30084 \end_inset 
30085
30086
30087 \layout Standard
30088
30089 During intermediate code generation phase, the compiler assumes the target
30090  machine has infinite number of registers and generates a lot of temporary
30091  variables.
30092  The live range computation determines the lifetime of each of these compiler-ge
30093 nerated temporaries.
30094  A picture speaks a thousand words.
30095  ICode example sections show the live range annotations for each of the
30096  operand.
30097  It is important to note here, each iCode is assigned a number in the order
30098  of its execution in the function.
30099  The live ranges are computed in terms of these numbers.
30100  The from number is the number of the iCode which first defines the operand
30101  and the to number signifies the iCode which uses this operand last.
30102 \layout Paragraph*
30103
30104 Register Allocation
30105 \begin_inset LatexCommand \index{Register allocation}
30106
30107 \end_inset 
30108
30109
30110 \layout Standard
30111
30112 The register allocation determines the type and number of registers needed
30113  by each operand.
30114  In most MCUs only a few registers can be used for indirect addressing.
30115  In case of 8051 for example the registers R0 & R1 can be used to indirectly
30116  address the internal ram and DPTR to indirectly address the external ram.
30117  The compiler will try to allocate the appropriate register to pointer variables
30118  if it can.
30119  ICode example section shows the operands annotated with the registers assigned
30120  to them.
30121  The compiler will try to keep operands in registers as much as possible;
30122  there are several schemes the compiler uses to do achieve this.
30123  When the compiler runs out of registers the compiler will check to see
30124  if there are any live operands which is not used or defined in the current
30125  basic block being processed, if there are any found then it will push that
30126  operand and use the registers in this block, the operand will then be popped
30127  at the end of the basic block.
30128  
30129 \layout Standard
30130
30131 There are other MCU specific considerations in this phase.
30132  Some MCUs have an accumulator; very short-lived operands could be assigned
30133  to the accumulator instead of a general-purpose register.
30134 \layout Paragraph*
30135
30136 Code generation
30137 \layout Standard
30138
30139 Figure II gives a table of iCode
30140 \begin_inset LatexCommand \index{iCode}
30141
30142 \end_inset 
30143
30144  operations supported by the compiler.
30145  The code generation involves translating these operations into corresponding
30146  assembly code for the processor.
30147  This sounds overly simple but that is the essence of code generation.
30148  Some of the iCode operations are generated on a MCU specific manner for
30149  example, the z80 port does not use registers to pass parameters so the
30150  SEND and RECV iCode operations will not be generated, and it also does
30151  not support JUMPTABLES.
30152  
30153 \newline 
30154
30155 \layout Standard
30156
30157
30158 \size footnotesize 
30159 Figure II 
30160 \begin_inset  Tabular
30161 <lyxtabular version="3" rows="39" columns="4">
30162 <features islongtable="true" headBottomDL="true">
30163 <column alignment="block" valignment="top" leftline="true" width="13col%">
30164 <column alignment="left" valignment="top" leftline="true" width="13col%">
30165 <column alignment="block" valignment="top" leftline="true" width="22col%">
30166 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
30167 <row topline="true" bottomline="true" endhead="true">
30168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30169 \begin_inset Text
30170
30171 \layout Standard
30172
30173
30174 \series bold 
30175 iCode
30176 \series default 
30177
30178 \begin_inset LatexCommand \index{iCode}
30179
30180 \end_inset 
30181
30182
30183 \end_inset 
30184 </cell>
30185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30186 \begin_inset Text
30187
30188 \layout Standard
30189
30190
30191 \series bold 
30192 Operands
30193 \end_inset 
30194 </cell>
30195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30196 \begin_inset Text
30197
30198 \layout Standard
30199
30200
30201 \series bold 
30202 Description
30203 \end_inset 
30204 </cell>
30205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30206 \begin_inset Text
30207
30208 \layout Standard
30209
30210
30211 \series bold 
30212 C Equivalent
30213 \end_inset 
30214 </cell>
30215 </row>
30216 <row topline="true">
30217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30218 \begin_inset Text
30219
30220 \layout Standard
30221
30222
30223 \size footnotesize 
30224 '!'
30225 \end_inset 
30226 </cell>
30227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30228 \begin_inset Text
30229
30230 \layout Standard
30231
30232
30233 \size footnotesize 
30234 IC_LEFT() IC_RESULT()
30235 \end_inset 
30236 </cell>
30237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30238 \begin_inset Text
30239
30240 \layout Standard
30241
30242
30243 \size footnotesize 
30244 NOT operation 
30245 \end_inset 
30246 </cell>
30247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30248 \begin_inset Text
30249
30250 \layout Standard
30251
30252
30253 \size footnotesize 
30254 IC_RESULT = ! IC_LEFT;
30255 \end_inset 
30256 </cell>
30257 </row>
30258 <row topline="true">
30259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30260 \begin_inset Text
30261
30262 \layout Standard
30263
30264
30265 \size footnotesize 
30266 '~'
30267 \end_inset 
30268 </cell>
30269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30270 \begin_inset Text
30271
30272 \layout Standard
30273
30274
30275 \size footnotesize 
30276 IC_LEFT() IC_RESULT()
30277 \end_inset 
30278 </cell>
30279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30280 \begin_inset Text
30281
30282 \layout Standard
30283
30284
30285 \size footnotesize 
30286 Bitwise complement of 
30287 \end_inset 
30288 </cell>
30289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30290 \begin_inset Text
30291
30292 \layout Standard
30293
30294
30295 \size footnotesize 
30296 IC_RESULT = ~IC_LEFT;
30297 \end_inset 
30298 </cell>
30299 </row>
30300 <row topline="true">
30301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30302 \begin_inset Text
30303
30304 \layout Standard
30305
30306
30307 \size footnotesize 
30308 RRC
30309 \end_inset 
30310 </cell>
30311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30312 \begin_inset Text
30313
30314 \layout Standard
30315
30316
30317 \size footnotesize 
30318 IC_LEFT() IC_RESULT()
30319 \end_inset 
30320 </cell>
30321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30322 \begin_inset Text
30323
30324 \layout Standard
30325
30326
30327 \size footnotesize 
30328 Rotate right with carry
30329 \end_inset 
30330 </cell>
30331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30332 \begin_inset Text
30333
30334 \layout Standard
30335
30336
30337 \size footnotesize 
30338 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
30339 \end_inset 
30340 </cell>
30341 </row>
30342 <row topline="true">
30343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30344 \begin_inset Text
30345
30346 \layout Standard
30347
30348
30349 \size footnotesize 
30350 RLC
30351 \end_inset 
30352 </cell>
30353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30354 \begin_inset Text
30355
30356 \layout Standard
30357
30358
30359 \size footnotesize 
30360 IC_LEFT() IC_RESULT()
30361 \end_inset 
30362 </cell>
30363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30364 \begin_inset Text
30365
30366 \layout Standard
30367
30368
30369 \size footnotesize 
30370 Rotate left with carry
30371 \end_inset 
30372 </cell>
30373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30374 \begin_inset Text
30375
30376 \layout Standard
30377
30378
30379 \size footnotesize 
30380 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
30381 \end_inset 
30382 </cell>
30383 </row>
30384 <row topline="true">
30385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30386 \begin_inset Text
30387
30388 \layout Standard
30389
30390
30391 \size footnotesize 
30392 GETHBIT
30393 \end_inset 
30394 </cell>
30395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30396 \begin_inset Text
30397
30398 \layout Standard
30399
30400
30401 \size footnotesize 
30402 IC_LEFT() IC_RESULT()
30403 \end_inset 
30404 </cell>
30405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30406 \begin_inset Text
30407
30408 \layout Standard
30409
30410
30411 \size footnotesize 
30412 Get the highest order bit of IC_LEFT
30413 \end_inset 
30414 </cell>
30415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30416 \begin_inset Text
30417
30418 \layout Standard
30419
30420
30421 \size footnotesize 
30422 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
30423 \end_inset 
30424 </cell>
30425 </row>
30426 <row topline="true">
30427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30428 \begin_inset Text
30429
30430 \layout Standard
30431
30432
30433 \size footnotesize 
30434 UNARYMINUS
30435 \end_inset 
30436 </cell>
30437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30438 \begin_inset Text
30439
30440 \layout Standard
30441
30442
30443 \size footnotesize 
30444 IC_LEFT() IC_RESULT()
30445 \end_inset 
30446 </cell>
30447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30448 \begin_inset Text
30449
30450 \layout Standard
30451
30452
30453 \size footnotesize 
30454 Unary minus
30455 \end_inset 
30456 </cell>
30457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30458 \begin_inset Text
30459
30460 \layout Standard
30461
30462
30463 \size footnotesize 
30464 IC_RESULT = - IC_LEFT;
30465 \end_inset 
30466 </cell>
30467 </row>
30468 <row topline="true">
30469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30470 \begin_inset Text
30471
30472 \layout Standard
30473
30474
30475 \size footnotesize 
30476 IPUSH
30477 \end_inset 
30478 </cell>
30479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30480 \begin_inset Text
30481
30482 \layout Standard
30483
30484
30485 \size footnotesize 
30486 IC_LEFT()
30487 \end_inset 
30488 </cell>
30489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30490 \begin_inset Text
30491
30492 \layout Standard
30493
30494
30495 \size footnotesize 
30496 Push the operand into stack
30497 \end_inset 
30498 </cell>
30499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30500 \begin_inset Text
30501
30502 \layout Standard
30503
30504
30505 \size footnotesize 
30506 NONE
30507 \end_inset 
30508 </cell>
30509 </row>
30510 <row topline="true">
30511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30512 \begin_inset Text
30513
30514 \layout Standard
30515
30516
30517 \size footnotesize 
30518 IPOP
30519 \end_inset 
30520 </cell>
30521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30522 \begin_inset Text
30523
30524 \layout Standard
30525
30526
30527 \size footnotesize 
30528 IC_LEFT()
30529 \end_inset 
30530 </cell>
30531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30532 \begin_inset Text
30533
30534 \layout Standard
30535
30536
30537 \size footnotesize 
30538 Pop the operand from the stack 
30539 \end_inset 
30540 </cell>
30541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30542 \begin_inset Text
30543
30544 \layout Standard
30545
30546
30547 \size footnotesize 
30548 NONE
30549 \end_inset 
30550 </cell>
30551 </row>
30552 <row topline="true">
30553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30554 \begin_inset Text
30555
30556 \layout Standard
30557
30558
30559 \size footnotesize 
30560 CALL
30561 \end_inset 
30562 </cell>
30563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30564 \begin_inset Text
30565
30566 \layout Standard
30567
30568
30569 \size footnotesize 
30570 IC_LEFT() IC_RESULT()
30571 \end_inset 
30572 </cell>
30573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30574 \begin_inset Text
30575
30576 \layout Standard
30577
30578
30579 \size footnotesize 
30580 Call the function represented by IC_LEFT 
30581 \end_inset 
30582 </cell>
30583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30584 \begin_inset Text
30585
30586 \layout Standard
30587
30588
30589 \size footnotesize 
30590 IC_RESULT = IC_LEFT();
30591 \end_inset 
30592 </cell>
30593 </row>
30594 <row topline="true">
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30596 \begin_inset Text
30597
30598 \layout Standard
30599
30600
30601 \size footnotesize 
30602 PCALL
30603 \end_inset 
30604 </cell>
30605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30606 \begin_inset Text
30607
30608 \layout Standard
30609
30610
30611 \size footnotesize 
30612 IC_LEFT() IC_RESULT()
30613 \end_inset 
30614 </cell>
30615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30616 \begin_inset Text
30617
30618 \layout Standard
30619
30620
30621 \size footnotesize 
30622 Call via function pointer
30623 \end_inset 
30624 </cell>
30625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30626 \begin_inset Text
30627
30628 \layout Standard
30629
30630
30631 \size footnotesize 
30632 IC_RESULT = (*IC_LEFT)();
30633 \end_inset 
30634 </cell>
30635 </row>
30636 <row topline="true">
30637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30638 \begin_inset Text
30639
30640 \layout Standard
30641
30642
30643 \size footnotesize 
30644 RETURN
30645 \end_inset 
30646 </cell>
30647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30648 \begin_inset Text
30649
30650 \layout Standard
30651
30652
30653 \size footnotesize 
30654 IC_LEFT()
30655 \end_inset 
30656 </cell>
30657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30658 \begin_inset Text
30659
30660 \layout Standard
30661
30662
30663 \size footnotesize 
30664 Return the value in operand IC_LEFT 
30665 \end_inset 
30666 </cell>
30667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30668 \begin_inset Text
30669
30670 \layout Standard
30671
30672
30673 \size footnotesize 
30674 return IC_LEFT;
30675 \end_inset 
30676 </cell>
30677 </row>
30678 <row topline="true">
30679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30680 \begin_inset Text
30681
30682 \layout Standard
30683
30684
30685 \size footnotesize 
30686 LABEL
30687 \end_inset 
30688 </cell>
30689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30690 \begin_inset Text
30691
30692 \layout Standard
30693
30694
30695 \size footnotesize 
30696 IC_LABEL() 
30697 \end_inset 
30698 </cell>
30699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30700 \begin_inset Text
30701
30702 \layout Standard
30703
30704
30705 \size footnotesize 
30706 Label
30707 \end_inset 
30708 </cell>
30709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30710 \begin_inset Text
30711
30712 \layout Standard
30713
30714
30715 \size footnotesize 
30716 IC_LABEL:
30717 \end_inset 
30718 </cell>
30719 </row>
30720 <row topline="true">
30721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30722 \begin_inset Text
30723
30724 \layout Standard
30725
30726
30727 \size footnotesize 
30728 GOTO
30729 \end_inset 
30730 </cell>
30731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30732 \begin_inset Text
30733
30734 \layout Standard
30735
30736
30737 \size footnotesize 
30738 IC_LABEL() 
30739 \end_inset 
30740 </cell>
30741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30742 \begin_inset Text
30743
30744 \layout Standard
30745
30746
30747 \size footnotesize 
30748 Goto label
30749 \end_inset 
30750 </cell>
30751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30752 \begin_inset Text
30753
30754 \layout Standard
30755
30756
30757 \size footnotesize 
30758 goto IC_LABEL();
30759 \end_inset 
30760 </cell>
30761 </row>
30762 <row topline="true">
30763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30764 \begin_inset Text
30765
30766 \layout Standard
30767
30768
30769 \size footnotesize 
30770 '+'
30771 \end_inset 
30772 </cell>
30773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30774 \begin_inset Text
30775
30776 \layout Standard
30777
30778
30779 \size footnotesize 
30780 IC_LEFT() IC_RIGHT() IC_RESULT()
30781 \end_inset 
30782 </cell>
30783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30784 \begin_inset Text
30785
30786 \layout Standard
30787
30788
30789 \size footnotesize 
30790 Addition
30791 \end_inset 
30792 </cell>
30793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30794 \begin_inset Text
30795
30796 \layout Standard
30797
30798
30799 \size footnotesize 
30800 IC_RESULT = IC_LEFT + IC_RIGHT
30801 \end_inset 
30802 </cell>
30803 </row>
30804 <row topline="true">
30805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30806 \begin_inset Text
30807
30808 \layout Standard
30809
30810
30811 \size footnotesize 
30812 '-'
30813 \end_inset 
30814 </cell>
30815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30816 \begin_inset Text
30817
30818 \layout Standard
30819
30820
30821 \size footnotesize 
30822 IC_LEFT() IC_RIGHT() IC_RESULT()
30823 \end_inset 
30824 </cell>
30825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30826 \begin_inset Text
30827
30828 \layout Standard
30829
30830
30831 \size footnotesize 
30832 Subtraction
30833 \end_inset 
30834 </cell>
30835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30836 \begin_inset Text
30837
30838 \layout Standard
30839
30840
30841 \size footnotesize 
30842 IC_RESULT = IC_LEFT - IC_RIGHT 
30843 \end_inset 
30844 </cell>
30845 </row>
30846 <row topline="true">
30847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30848 \begin_inset Text
30849
30850 \layout Standard
30851
30852
30853 \size footnotesize 
30854 '*'
30855 \end_inset 
30856 </cell>
30857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30858 \begin_inset Text
30859
30860 \layout Standard
30861
30862
30863 \size footnotesize 
30864 IC_LEFT() IC_RIGHT() IC_RESULT()
30865 \end_inset 
30866 </cell>
30867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30868 \begin_inset Text
30869
30870 \layout Standard
30871
30872
30873 \size footnotesize 
30874 Multiplication 
30875 \end_inset 
30876 </cell>
30877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30878 \begin_inset Text
30879
30880 \layout Standard
30881
30882
30883 \size footnotesize 
30884 IC_RESULT = IC_LEFT * IC_RIGHT;
30885 \end_inset 
30886 </cell>
30887 </row>
30888 <row topline="true">
30889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30890 \begin_inset Text
30891
30892 \layout Standard
30893
30894
30895 \size footnotesize 
30896 '/'
30897 \end_inset 
30898 </cell>
30899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30900 \begin_inset Text
30901
30902 \layout Standard
30903
30904
30905 \size footnotesize 
30906 IC_LEFT() IC_RIGHT() IC_RESULT()
30907 \end_inset 
30908 </cell>
30909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30910 \begin_inset Text
30911
30912 \layout Standard
30913
30914
30915 \size footnotesize 
30916 Division
30917 \end_inset 
30918 </cell>
30919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30920 \begin_inset Text
30921
30922 \layout Standard
30923
30924
30925 \size footnotesize 
30926 IC_RESULT = IC_LEFT / IC_RIGHT;
30927 \end_inset 
30928 </cell>
30929 </row>
30930 <row topline="true">
30931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30932 \begin_inset Text
30933
30934 \layout Standard
30935
30936
30937 \size footnotesize 
30938 '%'
30939 \end_inset 
30940 </cell>
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30942 \begin_inset Text
30943
30944 \layout Standard
30945
30946
30947 \size footnotesize 
30948 IC_LEFT() IC_RIGHT() IC_RESULT()
30949 \end_inset 
30950 </cell>
30951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30952 \begin_inset Text
30953
30954 \layout Standard
30955
30956
30957 \size footnotesize 
30958 Modulus
30959 \end_inset 
30960 </cell>
30961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30962 \begin_inset Text
30963
30964 \layout Standard
30965
30966
30967 \size footnotesize 
30968 IC_RESULT = IC_LEFT % IC_RIGHT;
30969 \end_inset 
30970 </cell>
30971 </row>
30972 <row topline="true">
30973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30974 \begin_inset Text
30975
30976 \layout Standard
30977
30978
30979 \size footnotesize 
30980 '<'
30981 \end_inset 
30982 </cell>
30983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30984 \begin_inset Text
30985
30986 \layout Standard
30987
30988
30989 \size footnotesize 
30990 IC_LEFT() IC_RIGHT() IC_RESULT()
30991 \end_inset 
30992 </cell>
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30994 \begin_inset Text
30995
30996 \layout Standard
30997
30998
30999 \size footnotesize 
31000 Less than
31001 \end_inset 
31002 </cell>
31003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31004 \begin_inset Text
31005
31006 \layout Standard
31007
31008
31009 \size footnotesize 
31010 IC_RESULT = IC_LEFT < IC_RIGHT;
31011 \end_inset 
31012 </cell>
31013 </row>
31014 <row topline="true">
31015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31016 \begin_inset Text
31017
31018 \layout Standard
31019
31020
31021 \size footnotesize 
31022 '>'
31023 \end_inset 
31024 </cell>
31025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31026 \begin_inset Text
31027
31028 \layout Standard
31029
31030
31031 \size footnotesize 
31032 IC_LEFT() IC_RIGHT() IC_RESULT()
31033 \end_inset 
31034 </cell>
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31036 \begin_inset Text
31037
31038 \layout Standard
31039
31040
31041 \size footnotesize 
31042 Greater than 
31043 \end_inset 
31044 </cell>
31045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31046 \begin_inset Text
31047
31048 \layout Standard
31049
31050
31051 \size footnotesize 
31052 IC_RESULT = IC_LEFT > IC_RIGHT;
31053 \end_inset 
31054 </cell>
31055 </row>
31056 <row topline="true">
31057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31058 \begin_inset Text
31059
31060 \layout Standard
31061
31062
31063 \size footnotesize 
31064 EQ_OP
31065 \end_inset 
31066 </cell>
31067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31068 \begin_inset Text
31069
31070 \layout Standard
31071
31072
31073 \size footnotesize 
31074 IC_LEFT() IC_RIGHT() IC_RESULT()
31075 \end_inset 
31076 </cell>
31077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31078 \begin_inset Text
31079
31080 \layout Standard
31081
31082
31083 \size footnotesize 
31084 Equal to 
31085 \end_inset 
31086 </cell>
31087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31088 \begin_inset Text
31089
31090 \layout Standard
31091
31092
31093 \size footnotesize 
31094 IC_RESULT = IC_LEFT == IC_RIGHT;
31095 \end_inset 
31096 </cell>
31097 </row>
31098 <row topline="true">
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31100 \begin_inset Text
31101
31102 \layout Standard
31103
31104
31105 \size footnotesize 
31106 AND_OP
31107 \end_inset 
31108 </cell>
31109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31110 \begin_inset Text
31111
31112 \layout Standard
31113
31114
31115 \size footnotesize 
31116 IC_LEFT() IC_RIGHT() IC_RESULT() 
31117 \end_inset 
31118 </cell>
31119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31120 \begin_inset Text
31121
31122 \layout Standard
31123
31124
31125 \size footnotesize 
31126 Logical and operation
31127 \end_inset 
31128 </cell>
31129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31130 \begin_inset Text
31131
31132 \layout Standard
31133
31134
31135 \size footnotesize 
31136 IC_RESULT = IC_LEFT && IC_RIGHT; 
31137 \end_inset 
31138 </cell>
31139 </row>
31140 <row topline="true">
31141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31142 \begin_inset Text
31143
31144 \layout Standard
31145
31146
31147 \size footnotesize 
31148 OR_OP
31149 \end_inset 
31150 </cell>
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31152 \begin_inset Text
31153
31154 \layout Standard
31155
31156
31157 \size footnotesize 
31158 IC_LEFT() IC_RIGHT() IC_RESULT() 
31159 \end_inset 
31160 </cell>
31161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31162 \begin_inset Text
31163
31164 \layout Standard
31165
31166
31167 \size footnotesize 
31168 Logical or operation 
31169 \end_inset 
31170 </cell>
31171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31172 \begin_inset Text
31173
31174 \layout Standard
31175
31176
31177 \size footnotesize 
31178 IC_RESULT = IC_LEFT || IC_RIGHT; 
31179 \end_inset 
31180 </cell>
31181 </row>
31182 <row topline="true">
31183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31184 \begin_inset Text
31185
31186 \layout Standard
31187
31188
31189 \size footnotesize 
31190 '^'
31191 \end_inset 
31192 </cell>
31193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31194 \begin_inset Text
31195
31196 \layout Standard
31197
31198
31199 \size footnotesize 
31200 IC_LEFT() IC_RIGHT() IC_RESULT() 
31201 \end_inset 
31202 </cell>
31203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31204 \begin_inset Text
31205
31206 \layout Standard
31207
31208
31209 \size footnotesize 
31210 Exclusive OR
31211 \end_inset 
31212 </cell>
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31214 \begin_inset Text
31215
31216 \layout Standard
31217
31218
31219 \size footnotesize 
31220 IC_RESULT = IC_LEFT ^ IC_RIGHT;
31221 \end_inset 
31222 </cell>
31223 </row>
31224 <row topline="true">
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31226 \begin_inset Text
31227
31228 \layout Standard
31229
31230
31231 \size footnotesize 
31232 '|'
31233 \end_inset 
31234 </cell>
31235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31236 \begin_inset Text
31237
31238 \layout Standard
31239
31240
31241 \size footnotesize 
31242 IC_LEFT() IC_RIGHT() IC_RESULT() 
31243 \end_inset 
31244 </cell>
31245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31246 \begin_inset Text
31247
31248 \layout Standard
31249
31250
31251 \size footnotesize 
31252 Bitwise OR 
31253 \end_inset 
31254 </cell>
31255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31256 \begin_inset Text
31257
31258 \layout Standard
31259
31260
31261 \size footnotesize 
31262 IC_RESULT = IC_LEFT | IC_RIGHT;
31263 \end_inset 
31264 </cell>
31265 </row>
31266 <row topline="true">
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31268 \begin_inset Text
31269
31270 \layout Standard
31271
31272
31273 \size footnotesize 
31274 BITWISEAND
31275 \end_inset 
31276 </cell>
31277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31278 \begin_inset Text
31279
31280 \layout Standard
31281
31282
31283 \size footnotesize 
31284 IC_LEFT() IC_RIGHT() IC_RESULT()
31285 \end_inset 
31286 </cell>
31287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31288 \begin_inset Text
31289
31290 \layout Standard
31291
31292
31293 \size footnotesize 
31294 Bitwise AND 
31295 \end_inset 
31296 </cell>
31297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31298 \begin_inset Text
31299
31300 \layout Standard
31301
31302
31303 \size footnotesize 
31304 IC_RESULT = IC_LEFT & IC_RIGHT;
31305 \end_inset 
31306 </cell>
31307 </row>
31308 <row topline="true">
31309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31310 \begin_inset Text
31311
31312 \layout Standard
31313
31314
31315 \size footnotesize 
31316 LEFT_OP
31317 \end_inset 
31318 </cell>
31319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31320 \begin_inset Text
31321
31322 \layout Standard
31323
31324
31325 \size footnotesize 
31326 IC_LEFT() IC_RIGHT() IC_RESULT()
31327 \end_inset 
31328 </cell>
31329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31330 \begin_inset Text
31331
31332 \layout Standard
31333
31334
31335 \size footnotesize 
31336 Left shift 
31337 \end_inset 
31338 </cell>
31339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31340 \begin_inset Text
31341
31342 \layout Standard
31343
31344
31345 \size footnotesize 
31346 IC_RESULT = IC_LEFT << IC_RIGHT 
31347 \end_inset 
31348 </cell>
31349 </row>
31350 <row topline="true">
31351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31352 \begin_inset Text
31353
31354 \layout Standard
31355
31356
31357 \size footnotesize 
31358 RIGHT_OP
31359 \end_inset 
31360 </cell>
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_inset Text
31363
31364 \layout Standard
31365
31366
31367 \size footnotesize 
31368 IC_LEFT() IC_RIGHT() IC_RESULT()
31369 \end_inset 
31370 </cell>
31371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31372 \begin_inset Text
31373
31374 \layout Standard
31375
31376
31377 \size footnotesize 
31378 Right shift
31379 \end_inset 
31380 </cell>
31381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31382 \begin_inset Text
31383
31384 \layout Standard
31385
31386
31387 \size footnotesize 
31388 IC_RESULT = IC_LEFT >> IC_RIGHT 
31389 \end_inset 
31390 </cell>
31391 </row>
31392 <row topline="true">
31393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31394 \begin_inset Text
31395
31396 \layout Standard
31397
31398
31399 \size footnotesize 
31400 GET_VALUE_
31401 \newline 
31402 AT_ ADDRESS
31403 \end_inset 
31404 </cell>
31405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31406 \begin_inset Text
31407
31408 \layout Standard
31409
31410
31411 \size footnotesize 
31412 IC_LEFT() IC_RESULT()
31413 \end_inset 
31414 </cell>
31415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31416 \begin_inset Text
31417
31418 \layout Standard
31419
31420
31421 \size footnotesize 
31422 Indirect fetch 
31423 \end_inset 
31424 </cell>
31425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31426 \begin_inset Text
31427
31428 \layout Standard
31429
31430
31431 \size footnotesize 
31432 IC_RESULT = (*IC_LEFT);
31433 \end_inset 
31434 </cell>
31435 </row>
31436 <row topline="true">
31437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31438 \begin_inset Text
31439
31440 \layout Standard
31441
31442
31443 \size footnotesize 
31444 POINTER_SET
31445 \end_inset 
31446 </cell>
31447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31448 \begin_inset Text
31449
31450 \layout Standard
31451
31452
31453 \size footnotesize 
31454 IC_RIGHT() IC_RESULT() 
31455 \end_inset 
31456 </cell>
31457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31458 \begin_inset Text
31459
31460 \layout Standard
31461
31462
31463 \size footnotesize 
31464 Indirect set
31465 \end_inset 
31466 </cell>
31467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31468 \begin_inset Text
31469
31470 \layout Standard
31471
31472
31473 \size footnotesize 
31474 (*IC_RESULT) = IC_RIGHT;
31475 \end_inset 
31476 </cell>
31477 </row>
31478 <row topline="true">
31479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31480 \begin_inset Text
31481
31482 \layout Standard
31483
31484
31485 \size footnotesize 
31486 '='
31487 \end_inset 
31488 </cell>
31489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31490 \begin_inset Text
31491
31492 \layout Standard
31493
31494
31495 \size footnotesize 
31496 IC_RIGHT() IC_RESULT()
31497 \end_inset 
31498 </cell>
31499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31500 \begin_inset Text
31501
31502 \layout Standard
31503
31504
31505 \size footnotesize 
31506 Assignment
31507 \end_inset 
31508 </cell>
31509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31510 \begin_inset Text
31511
31512 \layout Standard
31513
31514
31515 \size footnotesize 
31516 IC_RESULT = IC_RIGHT;
31517 \end_inset 
31518 </cell>
31519 </row>
31520 <row topline="true">
31521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31522 \begin_inset Text
31523
31524 \layout Standard
31525
31526
31527 \size footnotesize 
31528 IFX
31529 \end_inset 
31530 </cell>
31531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31532 \begin_inset Text
31533
31534 \layout Standard
31535
31536
31537 \size footnotesize 
31538 IC_COND IC_TRUE IC_LABEL
31539 \end_inset 
31540 </cell>
31541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31542 \begin_inset Text
31543
31544 \layout Standard
31545
31546
31547 \size footnotesize 
31548 Conditional jump.
31549  If true label is present then jump to true label if condition is true else
31550  jump to false label if condition is false 
31551 \end_inset 
31552 </cell>
31553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31554 \begin_inset Text
31555
31556 \layout Standard
31557
31558
31559 \size footnotesize 
31560 if (IC_COND) goto IC_TRUE; 
31561 \newline 
31562 \SpecialChar ~
31563 \SpecialChar ~
31564 Or 
31565 \newline 
31566 If (!IC_COND) goto IC_FALSE;
31567 \end_inset 
31568 </cell>
31569 </row>
31570 <row topline="true">
31571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31572 \begin_inset Text
31573
31574 \layout Standard
31575
31576
31577 \size footnotesize 
31578 ADDRESS_OF
31579 \end_inset 
31580 </cell>
31581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31582 \begin_inset Text
31583
31584 \layout Standard
31585
31586
31587 \size footnotesize 
31588 IC_LEFT() IC_RESULT()
31589 \end_inset 
31590 </cell>
31591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31592 \begin_inset Text
31593
31594 \layout Standard
31595
31596
31597 \size footnotesize 
31598 Address of 
31599 \end_inset 
31600 </cell>
31601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31602 \begin_inset Text
31603
31604 \layout Standard
31605
31606
31607 \size footnotesize 
31608 IC_RESULT = &IC_LEFT();
31609 \end_inset 
31610 </cell>
31611 </row>
31612 <row topline="true">
31613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31614 \begin_inset Text
31615
31616 \layout Standard
31617
31618
31619 \size footnotesize 
31620 JUMPTABLE
31621 \end_inset 
31622 </cell>
31623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31624 \begin_inset Text
31625
31626 \layout Standard
31627
31628
31629 \size footnotesize 
31630 IC_JTCOND IC_JTLABELS
31631 \end_inset 
31632 </cell>
31633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31634 \begin_inset Text
31635
31636 \layout Standard
31637
31638
31639 \size footnotesize 
31640 Jump to list of labels depending on the value of JTCOND
31641 \end_inset 
31642 </cell>
31643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31644 \begin_inset Text
31645
31646 \layout Standard
31647
31648
31649 \size footnotesize 
31650 Switch statement
31651 \end_inset 
31652 </cell>
31653 </row>
31654 <row topline="true">
31655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31656 \begin_inset Text
31657
31658 \layout Standard
31659
31660
31661 \size footnotesize 
31662 CAST
31663 \end_inset 
31664 </cell>
31665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31666 \begin_inset Text
31667
31668 \layout Standard
31669
31670
31671 \size footnotesize 
31672 IC_RIGHT() IC_LEFT() IC_RESULT()
31673 \end_inset 
31674 </cell>
31675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31676 \begin_inset Text
31677
31678 \layout Standard
31679
31680
31681 \size footnotesize 
31682 Cast types 
31683 \end_inset 
31684 </cell>
31685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31686 \begin_inset Text
31687
31688 \layout Standard
31689
31690
31691 \size footnotesize 
31692 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
31693 \end_inset 
31694 </cell>
31695 </row>
31696 <row topline="true">
31697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31698 \begin_inset Text
31699
31700 \layout Standard
31701
31702
31703 \size footnotesize 
31704 SEND
31705 \end_inset 
31706 </cell>
31707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31708 \begin_inset Text
31709
31710 \layout Standard
31711
31712
31713 \size footnotesize 
31714 IC_LEFT()
31715 \end_inset 
31716 </cell>
31717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31718 \begin_inset Text
31719
31720 \layout Standard
31721
31722
31723 \size footnotesize 
31724 This is used for passing parameters in registers; 
31725 \newline 
31726 move IC_LEFT to the next available parameter register.
31727 \end_inset 
31728 </cell>
31729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31730 \begin_inset Text
31731
31732 \layout Standard
31733
31734
31735 \size footnotesize 
31736 None
31737 \end_inset 
31738 </cell>
31739 </row>
31740 <row topline="true">
31741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31742 \begin_inset Text
31743
31744 \layout Standard
31745
31746
31747 \size footnotesize 
31748 RECV
31749 \end_inset 
31750 </cell>
31751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31752 \begin_inset Text
31753
31754 \layout Standard
31755
31756
31757 \size footnotesize 
31758 IC_RESULT()
31759 \end_inset 
31760 </cell>
31761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31762 \begin_inset Text
31763
31764 \layout Standard
31765
31766
31767 \size footnotesize 
31768 This is used for receiving parameters passed in registers;
31769 \newline 
31770 Move the values in the next parameter register to IC_RESULT 
31771 \end_inset 
31772 </cell>
31773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31774 \begin_inset Text
31775
31776 \layout Standard
31777
31778
31779 \size footnotesize 
31780 None
31781 \end_inset 
31782 </cell>
31783 </row>
31784 <row topline="true" bottomline="true">
31785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31786 \begin_inset Text
31787
31788 \layout Standard
31789
31790
31791 \shape slanted 
31792 \size footnotesize 
31793 (some more have been added)
31794 \end_inset 
31795 </cell>
31796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31797 \begin_inset Text
31798
31799 \layout Standard
31800
31801 \end_inset 
31802 </cell>
31803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31804 \begin_inset Text
31805
31806 \layout Standard
31807
31808 \end_inset 
31809 </cell>
31810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31811 \begin_inset Text
31812
31813 \layout Standard
31814
31815
31816 \shape slanted 
31817 \size footnotesize 
31818 see f.e.
31819  
31820 \family typewriter 
31821 gen51Code()
31822 \family default 
31823  in 
31824 \family typewriter 
31825 src/mcs51/gen.c
31826 \end_inset 
31827 </cell>
31828 </row>
31829 </lyxtabular>
31830
31831 \end_inset 
31832
31833
31834 \layout Comment
31835
31836 In the original article Figure II was announced to be downloadable on 
31837 \shape italic 
31838 Circuit Cellar
31839 \shape default 
31840 's web site.
31841  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
31842 \layout Paragraph*
31843
31844 ICode Example
31845 \begin_inset LatexCommand \index{iCode}
31846
31847 \end_inset 
31848
31849
31850 \layout Standard
31851
31852 This section shows some details of iCode.
31853  The example C code does not do anything useful; it is used as an example
31854  to illustrate the intermediate code generated by the compiler.
31855 \layout Verse
31856
31857
31858 \family typewriter 
31859 1.\SpecialChar ~
31860 xdata int * p;
31861 \newline 
31862 2.\SpecialChar ~
31863 int gint;
31864 \newline 
31865 3.\SpecialChar ~
31866 /* This function does nothing useful.
31867  It is used
31868 \newline 
31869 4.\SpecialChar ~
31870 \SpecialChar ~
31871 \SpecialChar ~
31872 \SpecialChar ~
31873 for the purpose of explaining iCode */
31874 \newline 
31875 5.\SpecialChar ~
31876 short function (data int *x)
31877 \newline 
31878 6.\SpecialChar ~
31879 {
31880 \newline 
31881 7.\SpecialChar ~
31882 \SpecialChar ~
31883 \SpecialChar ~
31884 short i=10; \SpecialChar ~
31885 \SpecialChar ~
31886 /* dead initialization eliminated */
31887 \newline 
31888 8.\SpecialChar ~
31889 \SpecialChar ~
31890 \SpecialChar ~
31891 short sum=10; /* dead initialization eliminated */
31892 \newline 
31893 9.\SpecialChar ~
31894 \SpecialChar ~
31895 \SpecialChar ~
31896 short mul;
31897 \newline 
31898 10.\SpecialChar ~
31899 \SpecialChar ~
31900 int j ;
31901 \newline 
31902 11.\SpecialChar ~
31903 \SpecialChar ~
31904 while (*x) *x++ = *p++; 
31905 \newline 
31906 12.\SpecialChar ~
31907 \SpecialChar ~
31908 \SpecialChar ~
31909 \SpecialChar ~
31910 sum = 0 ; 
31911 \newline 
31912 13.\SpecialChar ~
31913 \SpecialChar ~
31914 mul = 0;
31915 \newline 
31916 14.\SpecialChar ~
31917 \SpecialChar ~
31918 /* compiler detects i,j to be induction variables */
31919 \newline 
31920 15.\SpecialChar ~
31921 \SpecialChar ~
31922 for (i = 0, j = 10 ; i < 10 ; i++, j
31923 \family default 
31924 -
31925 \begin_inset ERT
31926 status Collapsed
31927
31928 \layout Standard
31929
31930 \backslash 
31931 /
31932 \end_inset 
31933
31934 -
31935 \family typewriter 
31936 ) {
31937 \newline 
31938 16.\SpecialChar ~
31939 \SpecialChar ~
31940 \SpecialChar ~
31941 \SpecialChar ~
31942 sum += i;
31943 \newline 
31944 17.\SpecialChar ~
31945 \SpecialChar ~
31946 \SpecialChar ~
31947 \SpecialChar ~
31948 mul += i * 3; \SpecialChar ~
31949 \SpecialChar ~
31950 /* this multiplication remains */
31951 \newline 
31952 18.\SpecialChar ~
31953 \SpecialChar ~
31954 \SpecialChar ~
31955 \SpecialChar ~
31956 gint += j * 3;\SpecialChar ~
31957 \SpecialChar ~
31958 /* this multiplication changed to addition */
31959 \newline 
31960 19.\SpecialChar ~
31961 \SpecialChar ~
31962 }
31963 \newline 
31964 20.\SpecialChar ~
31965 \SpecialChar ~
31966 return sum+mul;
31967 \newline 
31968 21.\SpecialChar ~
31969 }
31970 \layout Standard
31971
31972 In addition to the operands each iCode contains information about the filename
31973  and line it corresponds to in the source file.
31974  The first field in the listing should be interpreted as follows:
31975 \newline 
31976
31977 \shape italic 
31978 \size footnotesize 
31979 Filename(linenumber: iCode Execution sequence number : ICode hash table
31980  key : loop depth of the iCode).
31981 \shape default 
31982 \size default 
31983
31984 \newline 
31985 Then follows the human readable form of the ICode operation.
31986  Each operand of this triplet form can be of three basic types a) compiler
31987  generated temporary b) user defined variable c) a constant value.
31988  Note that local variables and parameters are replaced by compiler generated
31989  temporaries.
31990  Live ranges
31991 \begin_inset LatexCommand \index{Live range analysis}
31992
31993 \end_inset 
31994
31995  are computed only for temporaries (i.e.
31996  live ranges are not computed for global variables).
31997  Registers
31998 \begin_inset LatexCommand \index{Register allocation}
31999
32000 \end_inset 
32001
32002  are allocated for temporaries only.
32003  Operands are formatted in the following manner:
32004 \newline 
32005
32006 \shape italic 
32007 \size footnotesize 
32008 Operand Name [lr live-from : live-to ] { type information } [ registers
32009  allocated ].
32010 \shape default 
32011 \size default 
32012
32013 \newline 
32014 As mentioned earlier the live ranges are computed in terms of the execution
32015  sequence number of the iCodes, for example 
32016 \newline 
32017 the iTemp0 is live from (i.e.
32018  first defined in iCode with execution sequence number 3, and is last used
32019  in the iCode with sequence number 5).
32020  For induction variables such as iTemp21 the live range computation extends
32021  the lifetime from the start to the end of the loop.
32022 \newline 
32023 The register allocator used the live range information to allocate registers,
32024  the same registers may be used for different temporaries if their live
32025  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
32026  iTemp17 since their live ranges do not overlap.
32027  In addition the allocator also takes into consideration the type and usage
32028  of a temporary, for example itemp6 is a pointer to near space and is used
32029  as to fetch data from (i.e.
32030  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
32031  Some short lived temporaries are allocated to special registers which have
32032  meaning to the code generator e.g.
32033  iTemp13 is allocated to a pseudo register CC which tells the back end that
32034  the temporary is used only for a conditional jump the code generation makes
32035  use of this information to optimize a compare and jump ICode.
32036 \newline 
32037 There are several loop optimizations
32038 \begin_inset LatexCommand \index{Loop optimization}
32039
32040 \end_inset 
32041
32042  performed by the compiler.
32043  It can detect induction variables iTemp21(i) and iTemp23(j).
32044  Also note the compiler does selective strength reduction
32045 \begin_inset LatexCommand \index{Strength reduction}
32046
32047 \end_inset 
32048
32049 , i.e.
32050  the multiplication of an induction variable in line 18 (gint = j * 3) is
32051  changed to addition, a new temporary iTemp17 is allocated and assigned
32052  a initial value, a constant 3 is then added for each iteration of the loop.
32053  The compiler does not change the multiplication
32054 \begin_inset LatexCommand \index{Multiplication}
32055
32056 \end_inset 
32057
32058  in line 17 however since the processor does support an 8 * 8 bit multiplication.
32059 \newline 
32060 Note the dead code elimination
32061 \begin_inset LatexCommand \index{Dead-code elimination}
32062
32063 \end_inset 
32064
32065  optimization eliminated the dead assignments in line 7 & 8 to I and sum
32066  respectively.
32067 \newline 
32068
32069 \layout Standard
32070
32071
32072 \size footnotesize 
32073 Sample.c (5:1:0:0) _entry($9) :
32074 \layout Standard
32075
32076
32077 \size footnotesize 
32078 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
32079 \layout Standard
32080
32081
32082 \size footnotesize 
32083 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
32084 \layout Standard
32085
32086
32087 \size footnotesize 
32088 Sample.c(11:4:53:0) preHeaderLbl0($11) :
32089 \layout Standard
32090
32091
32092 \size footnotesize 
32093 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
32094  * int}[r2]
32095 \layout Standard
32096
32097
32098 \size footnotesize 
32099 Sample.c(11:6:5:1) _whilecontinue_0($1) :
32100 \layout Standard
32101
32102
32103 \size footnotesize 
32104 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
32105  int}[r0]]
32106 \layout Standard
32107
32108
32109 \size footnotesize 
32110 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
32111 \layout Standard
32112
32113
32114 \size footnotesize 
32115 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
32116  * int}
32117 \layout Standard
32118
32119
32120 \size footnotesize 
32121 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
32122  {short}
32123 \layout Standard
32124
32125
32126 \size footnotesize 
32127 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
32128  * int}[DPTR]]
32129 \layout Standard
32130
32131
32132 \size footnotesize 
32133 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
32134 }[r2 r3]
32135 \layout Standard
32136
32137
32138 \size footnotesize 
32139 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
32140  * int}[r0] + 0x2 {short}
32141 \layout Standard
32142
32143
32144 \size footnotesize 
32145 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
32146 \layout Standard
32147
32148
32149 \size footnotesize 
32150 Sample.c(11:17:21:0)_whilebreak_0($3) :
32151 \layout Standard
32152
32153
32154 \size footnotesize 
32155 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
32156 \layout Standard
32157
32158
32159 \size footnotesize 
32160 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
32161 \layout Standard
32162
32163
32164 \size footnotesize 
32165 Sample.c(15:20:54:0)preHeaderLbl1($13) :
32166 \layout Standard
32167
32168
32169 \size footnotesize 
32170 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
32171 \layout Standard
32172
32173
32174 \size footnotesize 
32175 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
32176 \layout Standard
32177
32178
32179 \size footnotesize 
32180 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
32181 \layout Standard
32182
32183
32184 \size footnotesize 
32185 Sample.c(15:24:26:1)_forcond_0($4) :
32186 \layout Standard
32187
32188
32189 \size footnotesize 
32190 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
32191  < 0xa {short}
32192 \layout Standard
32193
32194
32195 \size footnotesize 
32196 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
32197 \layout Standard
32198
32199
32200 \size footnotesize 
32201 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
32202  + ITemp21 [lr21:38]{short}[r4]
32203 \layout Standard
32204
32205
32206 \size footnotesize 
32207 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
32208  * 0x3 {short}
32209 \layout Standard
32210
32211
32212 \size footnotesize 
32213 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
32214  + iTemp15 [lr29:30]{short}[r1]
32215 \layout Standard
32216
32217
32218 \size footnotesize 
32219 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
32220  r0]- 0x3 {short}
32221 \layout Standard
32222
32223
32224 \size footnotesize 
32225 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
32226 int}[r7 r0]
32227 \layout Standard
32228
32229
32230 \size footnotesize 
32231 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
32232  + 0x1 {short}
32233 \layout Standard
32234
32235
32236 \size footnotesize 
32237 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
32238  r6]- 0x1 {short}
32239 \layout Standard
32240
32241
32242 \size footnotesize 
32243 Sample.c(19:38:47:1) goto _forcond_0($4)
32244 \layout Standard
32245
32246
32247 \size footnotesize 
32248 Sample.c(19:39:48:0)_forbreak_0($7) :
32249 \layout Standard
32250
32251
32252 \size footnotesize 
32253 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
32254  + ITemp11 [lr19:40]{short}[r3]
32255 \layout Standard
32256
32257
32258 \size footnotesize 
32259 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
32260 \layout Standard
32261
32262
32263 \size footnotesize 
32264 Sample.c(20:42:51:0)_return($8) :
32265 \layout Standard
32266
32267
32268 \size footnotesize 
32269 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
32270 \size default 
32271
32272 \newline 
32273
32274 \newline 
32275 Finally the code generated for this function:
32276 \newline 
32277
32278 \layout Standard
32279
32280
32281 \size footnotesize 
32282 .area DSEG (DATA)
32283 \layout Standard
32284
32285
32286 \size footnotesize 
32287 _p::
32288 \layout Standard
32289
32290
32291 \size footnotesize 
32292 \SpecialChar ~
32293 \SpecialChar ~
32294 .ds 2
32295 \layout Standard
32296
32297
32298 \size footnotesize 
32299 _gint::
32300 \layout Standard
32301
32302
32303 \size footnotesize 
32304 \SpecialChar ~
32305 \SpecialChar ~
32306 .ds 2
32307 \layout Standard
32308
32309
32310 \size footnotesize 
32311 ; sample.c 5
32312 \layout Standard
32313
32314
32315 \size footnotesize 
32316 ; ----------------------------------------------
32317 \layout Standard
32318
32319
32320 \size footnotesize 
32321 ; function function
32322 \layout Standard
32323
32324
32325 \size footnotesize 
32326 ; ----------------------------------------------
32327 \layout Standard
32328
32329
32330 \size footnotesize 
32331 _function:
32332 \layout Standard
32333
32334
32335 \size footnotesize 
32336 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
32337 \layout Standard
32338
32339
32340 \size footnotesize 
32341 \SpecialChar ~
32342 \SpecialChar ~
32343 mov r2,dpl
32344 \layout Standard
32345
32346
32347 \size footnotesize 
32348 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
32349 \layout Standard
32350
32351
32352 \size footnotesize 
32353 \SpecialChar ~
32354 \SpecialChar ~
32355 mov ar0,r2
32356 \layout Standard
32357
32358
32359 \size footnotesize 
32360 ;_whilecontinue_0($1) :
32361 \layout Standard
32362
32363
32364 \size footnotesize 
32365 00101$:
32366 \layout Standard
32367
32368
32369 \size footnotesize 
32370 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
32371 \layout Standard
32372
32373
32374 \size footnotesize 
32375 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
32376 \layout Standard
32377
32378
32379 \size footnotesize 
32380 \SpecialChar ~
32381 \SpecialChar ~
32382 mov ar2,@r0
32383 \layout Standard
32384
32385
32386 \size footnotesize 
32387 \SpecialChar ~
32388 \SpecialChar ~
32389 inc r0
32390 \layout Standard
32391
32392
32393 \size footnotesize 
32394 \SpecialChar ~
32395 \SpecialChar ~
32396 mov ar3,@r0
32397 \layout Standard
32398
32399
32400 \size footnotesize 
32401 \SpecialChar ~
32402 \SpecialChar ~
32403 dec r0
32404 \layout Standard
32405
32406
32407 \size footnotesize 
32408 \SpecialChar ~
32409 \SpecialChar ~
32410 mov a,r2
32411 \layout Standard
32412
32413
32414 \size footnotesize 
32415 \SpecialChar ~
32416 \SpecialChar ~
32417 orl a,r3
32418 \layout Standard
32419
32420
32421 \size footnotesize 
32422 \SpecialChar ~
32423 \SpecialChar ~
32424 jz 00103$
32425 \layout Standard
32426
32427
32428 \size footnotesize 
32429 00114$:
32430 \layout Standard
32431
32432
32433 \size footnotesize 
32434 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
32435 \layout Standard
32436
32437
32438 \size footnotesize 
32439 \SpecialChar ~
32440 \SpecialChar ~
32441 mov dpl,_p
32442 \layout Standard
32443
32444
32445 \size footnotesize 
32446 \SpecialChar ~
32447 \SpecialChar ~
32448 mov dph,(_p + 1)
32449 \layout Standard
32450
32451
32452 \size footnotesize 
32453 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
32454 \layout Standard
32455
32456
32457 \size footnotesize 
32458 \SpecialChar ~
32459 \SpecialChar ~
32460 mov a,#0x02
32461 \layout Standard
32462
32463
32464 \size footnotesize 
32465 \SpecialChar ~
32466 \SpecialChar ~
32467 add a,_p
32468 \layout Standard
32469
32470
32471 \size footnotesize 
32472 \SpecialChar ~
32473 \SpecialChar ~
32474 mov _p,a
32475 \layout Standard
32476
32477
32478 \size footnotesize 
32479 \SpecialChar ~
32480 \SpecialChar ~
32481 clr a
32482 \layout Standard
32483
32484
32485 \size footnotesize 
32486 \SpecialChar ~
32487 \SpecialChar ~
32488 addc a,(_p + 1)
32489 \layout Standard
32490
32491
32492 \size footnotesize 
32493 \SpecialChar ~
32494 \SpecialChar ~
32495 mov (_p + 1),a
32496 \layout Standard
32497
32498
32499 \size footnotesize 
32500 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
32501 \layout Standard
32502
32503
32504 \size footnotesize 
32505 \SpecialChar ~
32506 \SpecialChar ~
32507 movx a,@dptr
32508 \layout Standard
32509
32510
32511 \size footnotesize 
32512 \SpecialChar ~
32513 \SpecialChar ~
32514 mov r2,a
32515 \layout Standard
32516
32517
32518 \size footnotesize 
32519 \SpecialChar ~
32520 \SpecialChar ~
32521 inc dptr
32522 \layout Standard
32523
32524
32525 \size footnotesize 
32526 \SpecialChar ~
32527 \SpecialChar ~
32528 movx a,@dptr
32529 \layout Standard
32530
32531
32532 \size footnotesize 
32533 \SpecialChar ~
32534 \SpecialChar ~
32535 mov r3,a
32536 \layout Standard
32537
32538
32539 \size footnotesize 
32540 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
32541 \layout Standard
32542
32543
32544 \size footnotesize 
32545 \SpecialChar ~
32546 \SpecialChar ~
32547 mov @r0,ar2
32548 \layout Standard
32549
32550
32551 \size footnotesize 
32552 \SpecialChar ~
32553 \SpecialChar ~
32554 inc r0
32555 \layout Standard
32556
32557
32558 \size footnotesize 
32559 \SpecialChar ~
32560 \SpecialChar ~
32561 mov @r0,ar3
32562 \layout Standard
32563
32564
32565 \size footnotesize 
32566 ; iTemp6 [lr5:16]{_near * int}[r0] = 
32567 \layout Standard
32568
32569
32570 \size footnotesize 
32571 ; iTemp6 [lr5:16]{_near * int}[r0] + 
32572 \layout Standard
32573
32574
32575 \size footnotesize 
32576 ; 0x2 {short}
32577 \layout Standard
32578
32579
32580 \size footnotesize 
32581 \SpecialChar ~
32582 \SpecialChar ~
32583 inc r0
32584 \layout Standard
32585
32586
32587 \size footnotesize 
32588 ; goto _whilecontinue_0($1)
32589 \layout Standard
32590
32591
32592 \size footnotesize 
32593 \SpecialChar ~
32594 \SpecialChar ~
32595 sjmp 00101$
32596 \layout Standard
32597
32598
32599 \size footnotesize 
32600 ; _whilebreak_0($3) :
32601 \layout Standard
32602
32603
32604 \size footnotesize 
32605 00103$:
32606 \layout Standard
32607
32608
32609 \size footnotesize 
32610 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
32611 \layout Standard
32612
32613
32614 \size footnotesize 
32615 \SpecialChar ~
32616 \SpecialChar ~
32617 mov r2,#0x00
32618 \layout Standard
32619
32620
32621 \size footnotesize 
32622 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
32623 \layout Standard
32624
32625
32626 \size footnotesize 
32627 \SpecialChar ~
32628 \SpecialChar ~
32629 mov r3,#0x00
32630 \layout Standard
32631
32632
32633 \size footnotesize 
32634 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
32635 \layout Standard
32636
32637
32638 \size footnotesize 
32639 \SpecialChar ~
32640 \SpecialChar ~
32641 mov r4,#0x00
32642 \layout Standard
32643
32644
32645 \size footnotesize 
32646 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
32647 \layout Standard
32648
32649
32650 \size footnotesize 
32651 \SpecialChar ~
32652 \SpecialChar ~
32653 mov r5,#0x0A
32654 \layout Standard
32655
32656
32657 \size footnotesize 
32658 \SpecialChar ~
32659 \SpecialChar ~
32660 mov r6,#0x00
32661 \layout Standard
32662
32663
32664 \size footnotesize 
32665 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
32666 \layout Standard
32667
32668
32669 \size footnotesize 
32670 \SpecialChar ~
32671 \SpecialChar ~
32672 mov r7,#0x1E
32673 \layout Standard
32674
32675
32676 \size footnotesize 
32677 \SpecialChar ~
32678 \SpecialChar ~
32679 mov r0,#0x00
32680 \layout Standard
32681
32682
32683 \size footnotesize 
32684 ; _forcond_0($4) :
32685 \layout Standard
32686
32687
32688 \size footnotesize 
32689 00104$:
32690 \layout Standard
32691
32692
32693 \size footnotesize 
32694 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
32695 \layout Standard
32696
32697
32698 \size footnotesize 
32699 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
32700 \layout Standard
32701
32702
32703 \size footnotesize 
32704 \SpecialChar ~
32705 \SpecialChar ~
32706 clr c
32707 \layout Standard
32708
32709
32710 \size footnotesize 
32711 \SpecialChar ~
32712 \SpecialChar ~
32713 mov a,r4
32714 \layout Standard
32715
32716
32717 \size footnotesize 
32718 \SpecialChar ~
32719 \SpecialChar ~
32720 xrl a,#0x80
32721 \layout Standard
32722
32723
32724 \size footnotesize 
32725 \SpecialChar ~
32726 \SpecialChar ~
32727 subb a,#0x8a
32728 \layout Standard
32729
32730
32731 \size footnotesize 
32732 \SpecialChar ~
32733 \SpecialChar ~
32734 jnc 00107$
32735 \layout Standard
32736
32737
32738 \size footnotesize 
32739 00115$:
32740 \layout Standard
32741
32742
32743 \size footnotesize 
32744 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
32745 \layout Standard
32746
32747
32748 \size footnotesize 
32749 ; iTemp21 [lr21:38]{short}[r4]
32750 \layout Standard
32751
32752
32753 \size footnotesize 
32754 \SpecialChar ~
32755 \SpecialChar ~
32756 mov a,r4
32757 \layout Standard
32758
32759
32760 \size footnotesize 
32761 \SpecialChar ~
32762 \SpecialChar ~
32763 add a,r2
32764 \layout Standard
32765
32766
32767 \size footnotesize 
32768 \SpecialChar ~
32769 \SpecialChar ~
32770 mov r2,a
32771 \layout Standard
32772
32773
32774 \size footnotesize 
32775 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
32776 \layout Standard
32777
32778
32779 \size footnotesize 
32780 \SpecialChar ~
32781 \SpecialChar ~
32782 mov b,#0x03
32783 \layout Standard
32784
32785
32786 \size footnotesize 
32787 \SpecialChar ~
32788 \SpecialChar ~
32789 mov a,r4
32790 \layout Standard
32791
32792
32793 \size footnotesize 
32794 \SpecialChar ~
32795 \SpecialChar ~
32796 mul ab
32797 \layout Standard
32798
32799
32800 \size footnotesize 
32801 \SpecialChar ~
32802 \SpecialChar ~
32803 mov r1,a
32804 \layout Standard
32805
32806
32807 \size footnotesize 
32808 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
32809 \layout Standard
32810
32811
32812 \size footnotesize 
32813 ; iTemp15 [lr29:30]{short}[r1]
32814 \layout Standard
32815
32816
32817 \size footnotesize 
32818 \SpecialChar ~
32819 \SpecialChar ~
32820 add a,r3
32821 \layout Standard
32822
32823
32824 \size footnotesize 
32825 \SpecialChar ~
32826 \SpecialChar ~
32827 mov r3,a
32828 \layout Standard
32829
32830
32831 \size footnotesize 
32832 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
32833 \layout Standard
32834
32835
32836 \size footnotesize 
32837 \SpecialChar ~
32838 \SpecialChar ~
32839 mov a,r7
32840 \layout Standard
32841
32842
32843 \size footnotesize 
32844 \SpecialChar ~
32845 \SpecialChar ~
32846 add a,#0xfd
32847 \layout Standard
32848
32849
32850 \size footnotesize 
32851 \SpecialChar ~
32852 \SpecialChar ~
32853 mov r7,a
32854 \layout Standard
32855
32856
32857 \size footnotesize 
32858 \SpecialChar ~
32859 \SpecialChar ~
32860 mov a,r0
32861 \layout Standard
32862
32863
32864 \size footnotesize 
32865 \SpecialChar ~
32866 \SpecialChar ~
32867 addc a,#0xff
32868 \layout Standard
32869
32870
32871 \size footnotesize 
32872 \SpecialChar ~
32873 \SpecialChar ~
32874 mov r0,a
32875 \layout Standard
32876
32877
32878 \size footnotesize 
32879 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
32880 \layout Standard
32881
32882
32883 \size footnotesize 
32884 \SpecialChar ~
32885 \SpecialChar ~
32886 mov a,r7
32887 \layout Standard
32888
32889
32890 \size footnotesize 
32891 \SpecialChar ~
32892 \SpecialChar ~
32893 add a,_gint
32894 \layout Standard
32895
32896
32897 \size footnotesize 
32898 \SpecialChar ~
32899 \SpecialChar ~
32900 mov _gint,a
32901 \layout Standard
32902
32903
32904 \size footnotesize 
32905 \SpecialChar ~
32906 \SpecialChar ~
32907 mov a,r0
32908 \layout Standard
32909
32910
32911 \size footnotesize 
32912 \SpecialChar ~
32913 \SpecialChar ~
32914 addc a,(_gint + 1)
32915 \layout Standard
32916
32917
32918 \size footnotesize 
32919 \SpecialChar ~
32920 \SpecialChar ~
32921 mov (_gint + 1),a
32922 \layout Standard
32923
32924
32925 \size footnotesize 
32926 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
32927 \layout Standard
32928
32929
32930 \size footnotesize 
32931 \SpecialChar ~
32932 \SpecialChar ~
32933 inc r4
32934 \layout Standard
32935
32936
32937 \size footnotesize 
32938 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
32939 \layout Standard
32940
32941
32942 \size footnotesize 
32943 \SpecialChar ~
32944 \SpecialChar ~
32945 dec r5
32946 \layout Standard
32947
32948
32949 \size footnotesize 
32950 \SpecialChar ~
32951 \SpecialChar ~
32952 cjne r5,#0xff,00104$
32953 \layout Standard
32954
32955
32956 \size footnotesize 
32957 \SpecialChar ~
32958 \SpecialChar ~
32959 dec r6
32960 \layout Standard
32961
32962
32963 \size footnotesize 
32964 ; goto _forcond_0($4)
32965 \layout Standard
32966
32967
32968 \size footnotesize 
32969 \SpecialChar ~
32970 \SpecialChar ~
32971 sjmp 00104$
32972 \layout Standard
32973
32974
32975 \size footnotesize 
32976 ; _forbreak_0($7) :
32977 \layout Standard
32978
32979
32980 \size footnotesize 
32981 00107$:
32982 \layout Standard
32983
32984
32985 \size footnotesize 
32986 ; ret iTemp24 [lr40:41]{short}
32987 \layout Standard
32988
32989
32990 \size footnotesize 
32991 \SpecialChar ~
32992 \SpecialChar ~
32993 mov a,r3
32994 \layout Standard
32995
32996
32997 \size footnotesize 
32998 \SpecialChar ~
32999 \SpecialChar ~
33000 add a,r2
33001 \layout Standard
33002
33003
33004 \size footnotesize 
33005 \SpecialChar ~
33006 \SpecialChar ~
33007 mov dpl,a
33008 \layout Standard
33009
33010
33011 \size footnotesize 
33012 ; _return($8) :
33013 \layout Standard
33014
33015
33016 \size footnotesize 
33017 00108$:
33018 \layout Standard
33019
33020
33021 \size footnotesize 
33022 \SpecialChar ~
33023 \SpecialChar ~
33024 ret
33025 \newline 
33026
33027 \layout Section
33028
33029 A few words about basic block successors, predecessors and dominators
33030 \layout Standard
33031
33032 Successors are basic blocks
33033 \begin_inset LatexCommand \index{Basic blocks}
33034
33035 \end_inset 
33036
33037  that might execute after this basic block.
33038 \newline 
33039 Predecessors are basic blocks that might execute before reaching this basic
33040  block.
33041 \newline 
33042 Dominators are basic blocks that WILL execute before reaching this basic
33043  block.
33044 \newline 
33045
33046 \layout Standard
33047
33048 [basic block 1]
33049 \layout Standard
33050
33051 if (something)
33052 \layout Standard
33053
33054 \SpecialChar ~
33055 \SpecialChar ~
33056 \SpecialChar ~
33057 \SpecialChar ~
33058 [basic block 2]
33059 \layout Standard
33060
33061 else
33062 \layout Standard
33063
33064 \SpecialChar ~
33065 \SpecialChar ~
33066 \SpecialChar ~
33067 \SpecialChar ~
33068 [basic block 3]
33069 \layout Standard
33070
33071 [basic block 4]
33072 \newline 
33073
33074 \layout Standard
33075
33076 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
33077 \layout Standard
33078
33079 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
33080 \layout Standard
33081
33082 c) domVect of [BB4] = BB1 ...
33083  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
33084  was executed.
33085 \layout Chapter
33086
33087 Acknowledgments
33088 \layout Standard
33089
33090
33091 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
33092
33093 \end_inset 
33094
33095
33096 \newline 
33097
33098 \newline 
33099
33100 \emph on 
33101 Thanks to all the other volunteer developers who have helped with coding,
33102  testing, web-page creation, distribution sets, etc.
33103  You know who you are :-)
33104 \emph default 
33105
33106 \newline 
33107
33108 \newline 
33109
33110 \emph on 
33111 Also thanks to Sourceforge 
33112 \begin_inset LatexCommand \url{http://www.sf.net}
33113
33114 \end_inset 
33115
33116  which has hosted the project since 1999 and donates significant download
33117  bandwidth and probably more than 
33118 \begin_inset ERT
33119 status Collapsed
33120
33121 \layout Standard
33122 $10^{13}$
33123 \end_inset 
33124
33125 CPU cycles per day.
33126 \newline 
33127  
33128 \begin_inset Note
33129 collapsed false
33130
33131 \layout Standard
33132
33133 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
33134  minutes for (configure+make+regression test), and there is (i386, amd64,
33135  alpha, ppc64, (mingw32), sparc, macosx).
33136  
33137 \end_inset 
33138
33139
33140 \layout Standard
33141
33142 This document was initially written by Sandeep Dutta
33143 \layout Standard
33144
33145 All product names mentioned herein may be trademarks
33146 \begin_inset LatexCommand \index{Trademarks}
33147
33148 \end_inset 
33149
33150  of their respective companies.
33151  
33152 \layout Section*
33153
33154 Alphabetical index
33155 \layout Standard
33156
33157 To avoid confusion, the installation and building options for SDCC itself
33158  (chapter 2) are not part of the index.
33159 \layout Standard
33160
33161
33162 \begin_inset LatexCommand \printindex{}
33163
33164 \end_inset 
33165
33166
33167 \the_end