* device/lib/printf_large.c: slightly smaller
[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.1
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="center" valignment="top" leftline="true" rightline="true" width="0">
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.296
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 \end_inset 
506 </cell>
507 </row>
508 <row topline="true" bottomline="true">
509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
510 \begin_inset Text
511
512 \layout Standard
513
514 pointer
515 \end_inset 
516 </cell>
517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
518 \begin_inset Text
519
520 \layout Standard
521
522 1, 2, 3 or 4 bytes
523 \end_inset 
524 </cell>
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
526 \begin_inset Text
527
528 \layout Standard
529
530 generic
531 \end_inset 
532 </cell>
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
534 \begin_inset Text
535
536 \layout Standard
537
538 \end_inset 
539 </cell>
540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
541 \begin_inset Text
542
543 \layout Standard
544
545 \end_inset 
546 </cell>
547 </row>
548 </lyxtabular>
549
550 \end_inset 
551
552
553 \newline 
554 The compiler also allows 
555 \emph on 
556 inline assembler code
557 \emph default 
558  to be embedded anywhere in a function.
559  In addition, routines developed in assembly can also be called.
560 \newline 
561
562 \newline 
563 SDCC also provides an option (-
564 \begin_inset ERT
565 status Collapsed
566
567 \layout Standard
568
569 \backslash 
570 /
571 \end_inset 
572
573 -cyclomatic) to report the relative complexity of a function.
574  These functions can then be further optimized, or hand coded in assembly
575  if needed.
576  
577 \newline 
578
579 \newline 
580 SDCC also comes with a companion source level debugger SDCDB, the debugger
581  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
582 \newline 
583
584 \newline 
585 The latest version can be downloaded from 
586 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
587
588 \end_inset 
589
590 .
591
592 \series bold 
593  
594 \series default 
595 \emph on 
596 Please note: the compiler will probably always be some steps ahead of this
597  documentation
598 \series bold 
599 \emph default 
600
601 \begin_inset LatexCommand \index{Status of documentation}
602
603 \end_inset 
604
605
606 \begin_inset Foot
607 collapsed false
608
609 \layout Standard
610
611 Obviously this has pros and cons
612 \end_inset 
613
614 .
615 \layout Section
616
617 Open Source
618 \layout Standard
619
620 All packages used in this compiler system are 
621 \emph on 
622 open source
623 \emph default 
624  and 
625 \emph on 
626 freeware
627 \emph default 
628 ; source code for all the sub-packages (pre-processor, assemblers, linkers
629  etc) is distributed with the package.
630  This documentation is maintained using a freeware word processor (LyX).
631 \newline 
632 This program is free software; you can redistribute it and/or modify it
633  under the terms of the GNU General Public License
634 \begin_inset LatexCommand \index{GNU General Public License, GPL}
635
636 \end_inset 
637
638  as published by the Free Software Foundation; either version 2, or (at
639  your option) any later version.
640  This program is distributed in the hope that it will be useful, but WITHOUT
641  ANY WARRANTY; without even the implied warranty
642 \begin_inset LatexCommand \index{warranty}
643
644 \end_inset 
645
646  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
647  See the GNU General Public License for more details.
648  You should have received a copy of the GNU General Public License along
649  with this program; if not, write to the Free Software Foundation, 59 Temple
650  Place - Suite 330, Boston, MA 02111-1307, USA.
651  In other words, you are welcome to use, share and improve this program.
652  You are forbidden to forbid anyone else to use, share and improve what
653  you give them.
654  Help stamp out software-hoarding! 
655 \layout Section
656
657 Typographic conventions
658 \begin_inset LatexCommand \index{Typographic conventions}
659
660 \end_inset 
661
662
663 \layout Standard
664
665 Throughout this manual, we will use the following convention.
666  Commands you have to type in are printed in 
667 \family sans 
668 \series bold 
669 "sans serif"
670 \series default 
671 .
672
673 \family default 
674  Code samples are printed in 
675 \family typewriter 
676 typewriter font.
677
678 \family default 
679  Interesting items and new terms are printed in 
680 \emph on 
681 italic.
682 \layout Section
683
684 Compatibility
685 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
686
687 \end_inset 
688
689  with previous versions
690 \begin_inset LatexCommand \index{Compatibility with previous versions}
691
692 \end_inset 
693
694
695 \layout Standard
696
697 This version has numerous bug fixes compared with the previous version.
698  But we also introduced some incompatibilities with older versions.
699  Not just for the fun of it, but to make the compiler more stable, efficient
700  and ANSI compliant
701 \begin_inset LatexCommand \index{ANSI-compliance}
702
703 \end_inset 
704
705  (see section 
706 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
707
708 \end_inset 
709
710  for ANSI-Compliance).
711  
712 \newline 
713
714 \layout Itemize
715
716 short is now equivalent to int (16 bits), it used to be equivalent to char
717  (8 bits) which is not ANSI compliant.
718 \layout Itemize
719
720 the default directory for gcc-builds where include, library and documentation
721  files are stored is now in /usr/local/share.
722 \layout Itemize
723
724 char type parameters to vararg
725 \begin_inset LatexCommand \index{vararg, va\_arg}
726
727 \end_inset 
728
729  functions are casted to int unless explicitly casted
730 \begin_inset Marginal
731 collapsed true
732
733 \layout Standard
734
735
736 \series bold 
737 \SpecialChar ~
738 !
739 \end_inset 
740
741 , e.g.: 
742 \newline 
743
744 \family typewriter 
745 \SpecialChar ~
746 \SpecialChar ~
747 char a=3;
748 \newline 
749 \SpecialChar ~
750 \SpecialChar ~
751 printf ("%d %c
752 \backslash 
753 n", a, (char)a);
754 \family default 
755
756 \newline 
757  will push a as an int and as a char resp.
758 \layout Itemize
759
760 option -
761 \begin_inset ERT
762 status Collapsed
763
764 \layout Standard
765
766 \backslash 
767 /
768 \end_inset 
769
770 -regextend has been removed.
771 \layout Itemize
772
773 option -
774 \begin_inset ERT
775 status Collapsed
776
777 \layout Standard
778
779 \backslash 
780 /
781 \end_inset 
782
783 -noregparms has been removed.
784 \layout Itemize
785
786 option -
787 \begin_inset ERT
788 status Collapsed
789
790 \layout Standard
791
792 \backslash 
793 /
794 \end_inset 
795
796 -stack-after-data has been removed.
797 \layout Itemize
798
799 bit
800 \begin_inset LatexCommand \index{bit}
801
802 \end_inset 
803
804  and sbit
805 \begin_inset LatexCommand \index{sbit}
806
807 \end_inset 
808
809
810 \begin_inset LatexCommand \index{\_\_sbit}
811
812 \end_inset 
813
814  types now consistently behave like the C99 _Bool type with respect to type
815  conversion
816 \begin_inset LatexCommand \index{type conversion}
817
818 \end_inset 
819
820
821 \begin_inset LatexCommand \index{type promotion}
822
823 \end_inset 
824
825 .
826  The most common incompatibility resulting from this change is related to
827  bit toggling
828 \begin_inset LatexCommand \index{Bit toggling}
829
830 \end_inset 
831
832  idioms, e.g.:
833 \newline 
834
835 \family typewriter 
836 \SpecialChar ~
837 \SpecialChar ~
838 bit b;
839 \newline 
840 \SpecialChar ~
841 \SpecialChar ~
842 b = ~
843 \begin_inset LatexCommand \index{\~\/ Operator}
844
845 \end_inset 
846
847 b; /* equivalent to b=1 instead of toggling b */
848 \begin_inset Marginal
849 collapsed true
850
851 \layout Standard
852
853
854 \series bold 
855 \SpecialChar ~
856 !
857 \end_inset 
858
859
860 \newline 
861 \SpecialChar ~
862 \SpecialChar ~
863 b = !b; /* toggles b */
864 \newline 
865
866 \family default 
867 In previous versions, both forms would have toggled the bit.
868 \layout Standard
869
870
871 \emph on 
872 <pending: more incompatibilities?>
873 \layout Section
874
875 System Requirements
876 \layout Standard
877
878 What do you need before you start installation of SDCC? A computer, and
879  a desire to compute.
880  The preferred method of installation is to compile SDCC from source using
881  GNU gcc and make.
882  For Windows some pre-compiled binary distributions are available for your
883  convenience.
884  You should have some experience with command line tools and compiler use.
885 \layout Section
886
887 Other Resources
888 \layout Standard
889
890 The SDCC home page at 
891 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
892
893 \end_inset 
894
895  is a great place to find distribution sets.
896  You can also find links to the user mailing lists that offer help or discuss
897  SDCC with other SDCC users.
898  Web links to other SDCC related sites can also be found here.
899  This document can be found in the DOC directory of the source package as
900  a text or HTML file.
901  A pdf version of this document is available at 
902 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
903
904 \end_inset 
905
906 .
907  Some of the other tools (simulator and assembler) included with SDCC contain
908  their own documentation and can be found in the source distribution.
909  If you want the latest unreleased software, the complete source package
910  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
911 /trunk/sdcc.
912 \layout Section
913
914 Wishes for the future
915 \layout Standard
916
917 There are (and always will be) some things that could be done.
918  Here are some I can think of:
919 \newline 
920
921 \layout Standard
922
923
924 \family typewriter 
925 char KernelFunction3(char p) at 0x340;
926 \newline 
927
928 \layout Standard
929
930
931 \family typewriter 
932 better code banking
933 \begin_inset LatexCommand \index{code banking (limited support)}
934
935 \end_inset 
936
937  support for mcs51
938 \newline 
939
940 \newline 
941
942 \family default 
943 If you can think of some more, please see the section 
944 \begin_inset LatexCommand \ref{sub:Requesting-Features}
945
946 \end_inset 
947
948  about filing feature requests
949 \begin_inset LatexCommand \index{Requesting features}
950
951 \end_inset 
952
953
954 \begin_inset LatexCommand \index{Feature request}
955
956 \end_inset 
957
958 .
959 \newline 
960
961 \layout Chapter
962
963 Installing SDCC
964 \begin_inset LatexCommand \index{Installation}
965
966 \end_inset 
967
968
969 \layout Standard
970
971 For most users it is sufficient to skip to either section 
972 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
973
974 \end_inset 
975
976  (Unix) or section 
977 \begin_inset LatexCommand \ref{sub:Windows-Install}
978
979 \end_inset 
980
981  (Windows).
982  More detailed instructions follow below.
983 \layout Section
984
985 Configure Options
986 \begin_inset LatexCommand \index{Options SDCC configuration}
987
988 \end_inset 
989
990
991 \layout Standard
992
993 The install paths, search paths and other options are defined when running
994  'configure'.
995  The defaults can be overridden by:
996 \layout List
997 \labelwidthstring 00.00.0000
998
999 -
1000 \begin_inset ERT
1001 status Collapsed
1002
1003 \layout Standard
1004
1005 \backslash 
1006 /
1007 \end_inset 
1008
1009 -prefix see table below
1010 \layout List
1011 \labelwidthstring 00.00.0000
1012
1013 -
1014 \begin_inset ERT
1015 status Collapsed
1016
1017 \layout Standard
1018
1019 \backslash 
1020 /
1021 \end_inset 
1022
1023 -exec_prefix see table below
1024 \layout List
1025 \labelwidthstring 00.00.0000
1026
1027 -
1028 \begin_inset ERT
1029 status Collapsed
1030
1031 \layout Standard
1032
1033 \backslash 
1034 /
1035 \end_inset 
1036
1037 -bindir see table below
1038 \layout List
1039 \labelwidthstring 00.00.0000
1040
1041 -
1042 \begin_inset ERT
1043 status Collapsed
1044
1045 \layout Standard
1046
1047 \backslash 
1048 /
1049 \end_inset 
1050
1051 -datadir see table below
1052 \layout List
1053 \labelwidthstring 00.00.0000
1054
1055 docdir environment variable, see table below
1056 \layout List
1057 \labelwidthstring 00.00.0000
1058
1059 include_dir_suffix environment variable, see table below
1060 \layout List
1061 \labelwidthstring 00.00.0000
1062
1063 lib_dir_suffix environment variable, see table below
1064 \layout List
1065 \labelwidthstring 00.00.0000
1066
1067 sdccconf_h_dir_separator environment variable, either / or 
1068 \backslash 
1069
1070 \backslash 
1071  makes sense here.
1072  This character will only be used in sdccconf.h; don't forget it's a C-header,
1073  therefore a double-backslash is needed there.
1074 \layout List
1075 \labelwidthstring 00.00.0000
1076
1077 -
1078 \begin_inset ERT
1079 status Collapsed
1080
1081 \layout Standard
1082
1083 \backslash 
1084 /
1085 \end_inset 
1086
1087 -disable-mcs51-port Excludes the Intel mcs51 port
1088 \layout List
1089 \labelwidthstring 00.00.0000
1090
1091 -
1092 \begin_inset ERT
1093 status Collapsed
1094
1095 \layout Standard
1096
1097 \backslash 
1098 /
1099 \end_inset 
1100
1101 -disable-gbz80-port Excludes the Gameboy gbz80 port
1102 \layout List
1103 \labelwidthstring 00.00.0000
1104
1105 -
1106 \begin_inset ERT
1107 status Collapsed
1108
1109 \layout Standard
1110
1111 \backslash 
1112 /
1113 \end_inset 
1114
1115 -disable-z80-port Excludes the z80 port
1116 \layout List
1117 \labelwidthstring 00.00.0000
1118
1119 -
1120 \begin_inset ERT
1121 status Collapsed
1122
1123 \layout Standard
1124
1125 \backslash 
1126 /
1127 \end_inset 
1128
1129 -disable-avr-port Excludes the AVR port
1130 \layout List
1131 \labelwidthstring 00.00.0000
1132
1133 -
1134 \begin_inset ERT
1135 status Collapsed
1136
1137 \layout Standard
1138
1139 \backslash 
1140 /
1141 \end_inset 
1142
1143 -disable-ds390-port Excludes the DS390 port
1144 \layout List
1145 \labelwidthstring 00.00.0000
1146
1147 -
1148 \begin_inset ERT
1149 status Collapsed
1150
1151 \layout Standard
1152
1153 \backslash 
1154 /
1155 \end_inset 
1156
1157 -disable-hc08-port Excludes the HC08 port
1158 \layout List
1159 \labelwidthstring 00.00.0000
1160
1161 -
1162 \begin_inset ERT
1163 status Collapsed
1164
1165 \layout Standard
1166
1167 \backslash 
1168 /
1169 \end_inset 
1170
1171 -disable-pic-port Excludes the PIC port
1172 \layout List
1173 \labelwidthstring 00.00.0000
1174
1175 -
1176 \begin_inset ERT
1177 status Collapsed
1178
1179 \layout Standard
1180
1181 \backslash 
1182 /
1183 \end_inset 
1184
1185 -disable-xa51-port Excludes the XA51 port
1186 \layout List
1187 \labelwidthstring 00.00.0000
1188
1189 -
1190 \begin_inset ERT
1191 status Collapsed
1192
1193 \layout Standard
1194
1195 \backslash 
1196 /
1197 \end_inset 
1198
1199 -disable-ucsim Disables configuring and building of ucsim
1200 \layout List
1201 \labelwidthstring 00.00.0000
1202
1203 -
1204 \begin_inset ERT
1205 status Collapsed
1206
1207 \layout Standard
1208
1209 \backslash 
1210 /
1211 \end_inset 
1212
1213 -disable-device-lib Disables automatically building device libraries
1214 \layout List
1215 \labelwidthstring 00.00.0000
1216
1217 -
1218 \begin_inset ERT
1219 status Collapsed
1220
1221 \layout Standard
1222
1223 \backslash 
1224 /
1225 \end_inset 
1226
1227 -disable-packihx Disables building packihx
1228 \layout List
1229 \labelwidthstring 00.00.0000
1230
1231 -
1232 \begin_inset ERT
1233 status Collapsed
1234
1235 \layout Standard
1236
1237 \backslash 
1238 /
1239 \end_inset 
1240
1241 -enable-doc Build pdf, html and txt files from the lyx sources
1242 \layout List
1243 \labelwidthstring 00.00.0000
1244
1245 -
1246 \begin_inset ERT
1247 status Collapsed
1248
1249 \layout Standard
1250
1251 \backslash 
1252 /
1253 \end_inset 
1254
1255 -enable-libgc Use the Bohem memory allocator.
1256  Lower runtime footprint.
1257 \layout Standard
1258
1259 Furthermore the environment variables CC, CFLAGS, ...
1260  the tools and their arguments can be influenced.
1261  Please see `configure -
1262 \begin_inset ERT
1263 status Collapsed
1264
1265 \layout Standard
1266
1267 \backslash 
1268 /
1269 \end_inset 
1270
1271 -help` and the man/info pages of `configure` for details.
1272 \newline 
1273
1274 \newline 
1275 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1276  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1277 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1278  At the moment it's not possible to change the default settings (it was
1279  simply never required).
1280 \newline 
1281
1282 \newline 
1283 These configure options are compiled into the binaries, and can only be
1284  changed by rerunning 'configure' and recompiling SDCC.
1285  The configure options are written in 
1286 \emph on 
1287 italics
1288 \emph default 
1289  to distinguish them from run time environment variables (see section search
1290  paths).
1291 \newline 
1292
1293 \newline 
1294 The settings for 
1295 \begin_inset Quotes sld
1296 \end_inset 
1297
1298 Win32 builds
1299 \begin_inset Quotes srd
1300 \end_inset 
1301
1302  are used by the SDCC team to build the official Win32 binaries.
1303  The SDCC team uses Mingw32 to build the official Windows binaries, because
1304  it's
1305 \layout Enumerate
1306
1307 open source, 
1308 \layout Enumerate
1309
1310 a gcc compiler and last but not least
1311 \layout Enumerate
1312
1313 the binaries can be built by cross compiling on Sourceforge's compile farm.
1314 \layout Standard
1315
1316 See the examples, how to pass the Win32 settings to 'configure'.
1317  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1318  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1319  for Win32.
1320 \newline 
1321
1322 \newline 
1323 These defaults are:
1324 \newline 
1325
1326 \layout Standard
1327 \align center 
1328
1329 \begin_inset  Tabular
1330 <lyxtabular version="3" rows="8" columns="3">
1331 <features>
1332 <column alignment="block" valignment="top" leftline="true" width="0in">
1333 <column alignment="block" valignment="top" leftline="true" width="0in">
1334 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1335 <row topline="true" bottomline="true">
1336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1337 \begin_inset Text
1338
1339 \layout Standard
1340
1341 Variable
1342 \end_inset 
1343 </cell>
1344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1345 \begin_inset Text
1346
1347 \layout Standard
1348
1349 default
1350 \end_inset 
1351 </cell>
1352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1353 \begin_inset Text
1354
1355 \layout Standard
1356
1357 Win32 builds
1358 \end_inset 
1359 </cell>
1360 </row>
1361 <row topline="true">
1362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1363 \begin_inset Text
1364
1365 \layout Standard
1366
1367
1368 \emph on 
1369 PREFIX
1370 \end_inset 
1371 </cell>
1372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1373 \begin_inset Text
1374
1375 \layout Standard
1376
1377 /usr/local
1378 \end_inset 
1379 </cell>
1380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1381 \begin_inset Text
1382
1383 \layout Standard
1384
1385
1386 \backslash 
1387 sdcc
1388 \end_inset 
1389 </cell>
1390 </row>
1391 <row topline="true">
1392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1393 \begin_inset Text
1394
1395 \layout Standard
1396
1397
1398 \emph on 
1399 EXEC_PREFIX
1400 \end_inset 
1401 </cell>
1402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1403 \begin_inset Text
1404
1405 \layout Standard
1406
1407
1408 \emph on 
1409 $PREFIX
1410 \end_inset 
1411 </cell>
1412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1413 \begin_inset Text
1414
1415 \layout Standard
1416
1417
1418 \emph on 
1419 $PREFIX
1420 \end_inset 
1421 </cell>
1422 </row>
1423 <row topline="true">
1424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1425 \begin_inset Text
1426
1427 \layout Standard
1428
1429
1430 \emph on 
1431 BINDIR
1432 \end_inset 
1433 </cell>
1434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1435 \begin_inset Text
1436
1437 \layout Standard
1438
1439
1440 \emph on 
1441 $EXECPREFIX
1442 \emph default 
1443 /bin
1444 \end_inset 
1445 </cell>
1446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1447 \begin_inset Text
1448
1449 \layout Standard
1450
1451
1452 \emph on 
1453 $EXECPREFIX
1454 \emph default 
1455
1456 \backslash 
1457 bin
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 DATADIR
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 $PREFIX
1480 \emph default 
1481 /share
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 $PREFIX
1492 \end_inset 
1493 </cell>
1494 </row>
1495 <row topline="true">
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1497 \begin_inset Text
1498
1499 \layout Standard
1500
1501
1502 \emph on 
1503 DOCDIR
1504 \end_inset 
1505 </cell>
1506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1507 \begin_inset Text
1508
1509 \layout Standard
1510
1511
1512 \emph on 
1513 $DATADIR
1514 \emph default 
1515 /sdcc/doc
1516 \end_inset 
1517 </cell>
1518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1519 \begin_inset Text
1520
1521 \layout Standard
1522
1523
1524 \emph on 
1525 $DATADIR
1526 \emph default 
1527
1528 \backslash 
1529 doc
1530 \end_inset 
1531 </cell>
1532 </row>
1533 <row topline="true">
1534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1535 \begin_inset Text
1536
1537 \layout Standard
1538
1539
1540 \emph on 
1541 INCLUDE_DIR_SUFFIX
1542 \end_inset 
1543 </cell>
1544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1545 \begin_inset Text
1546
1547 \layout Standard
1548
1549 sdcc/include
1550 \end_inset 
1551 </cell>
1552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1553 \begin_inset Text
1554
1555 \layout Standard
1556
1557 include
1558 \end_inset 
1559 </cell>
1560 </row>
1561 <row topline="true" bottomline="true">
1562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1563 \begin_inset Text
1564
1565 \layout Standard
1566
1567
1568 \emph on 
1569 LIB_DIR_SUFFIX
1570 \end_inset 
1571 </cell>
1572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1573 \begin_inset Text
1574
1575 \layout Standard
1576
1577 sdcc/lib
1578 \end_inset 
1579 </cell>
1580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1581 \begin_inset Text
1582
1583 \layout Standard
1584
1585 lib
1586 \end_inset 
1587 </cell>
1588 </row>
1589 </lyxtabular>
1590
1591 \end_inset 
1592
1593
1594 \newline 
1595
1596 \layout Standard
1597 \noindent 
1598 'configure' also computes relative paths.
1599  This is needed for full relocatability of a binary package and to complete
1600  search paths (see section search paths below):
1601 \newline 
1602  
1603 \layout Standard
1604 \align center 
1605
1606 \begin_inset  Tabular
1607 <lyxtabular version="3" rows="4" columns="3">
1608 <features>
1609 <column alignment="block" valignment="top" leftline="true" width="0in">
1610 <column alignment="block" valignment="top" leftline="true" width="0in">
1611 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1612 <row topline="true" bottomline="true">
1613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1614 \begin_inset Text
1615
1616 \layout Standard
1617
1618 Variable (computed)
1619 \end_inset 
1620 </cell>
1621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1622 \begin_inset Text
1623
1624 \layout Standard
1625
1626 default
1627 \end_inset 
1628 </cell>
1629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1630 \begin_inset Text
1631
1632 \layout Standard
1633
1634 Win32 builds
1635 \end_inset 
1636 </cell>
1637 </row>
1638 <row topline="true" bottomline="true">
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1640 \begin_inset Text
1641
1642 \layout Standard
1643
1644
1645 \emph on 
1646 BIN2DATA_DIR
1647 \end_inset 
1648 </cell>
1649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1650 \begin_inset Text
1651
1652 \layout Standard
1653
1654 ../share
1655 \end_inset 
1656 </cell>
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1658 \begin_inset Text
1659
1660 \layout Standard
1661
1662 ..
1663 \end_inset 
1664 </cell>
1665 </row>
1666 <row bottomline="true">
1667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1668 \begin_inset Text
1669
1670 \layout Standard
1671
1672
1673 \emph on 
1674 PREFIX2BIN_DIR
1675 \end_inset 
1676 </cell>
1677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1678 \begin_inset Text
1679
1680 \layout Standard
1681
1682 bin
1683 \end_inset 
1684 </cell>
1685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1686 \begin_inset Text
1687
1688 \layout Standard
1689
1690 bin
1691 \end_inset 
1692 </cell>
1693 </row>
1694 <row bottomline="true">
1695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1696 \begin_inset Text
1697
1698 \layout Standard
1699
1700
1701 \emph on 
1702 PREFIX2DATA_DIR
1703 \end_inset 
1704 </cell>
1705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1706 \begin_inset Text
1707
1708 \layout Standard
1709
1710 share/sdcc
1711 \end_inset 
1712 </cell>
1713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1714 \begin_inset Text
1715
1716 \layout Standard
1717
1718 \end_inset 
1719 </cell>
1720 </row>
1721 </lyxtabular>
1722
1723 \end_inset 
1724
1725
1726 \newline 
1727
1728 \layout Standard
1729 \noindent 
1730 Examples:
1731 \layout LyX-Code
1732
1733 ./configure
1734 \newline 
1735 ./configure -
1736 \begin_inset ERT
1737 status Collapsed
1738
1739 \layout Standard
1740
1741 \backslash 
1742 /
1743 \end_inset 
1744
1745 -prefix=
1746 \begin_inset Quotes srd
1747 \end_inset 
1748
1749 /usr/bin
1750 \begin_inset Quotes srd
1751 \end_inset 
1752
1753  -
1754 \begin_inset ERT
1755 status Collapsed
1756
1757 \layout Standard
1758
1759 \backslash 
1760 /
1761 \end_inset 
1762
1763 -datadir=
1764 \begin_inset Quotes srd
1765 \end_inset 
1766
1767 /usr/share
1768 \begin_inset Quotes srd
1769 \end_inset 
1770
1771
1772 \newline 
1773 ./configure -
1774 \begin_inset ERT
1775 status Collapsed
1776
1777 \layout Standard
1778
1779 \backslash 
1780 /
1781 \end_inset 
1782
1783 -disable-avr-port -
1784 \begin_inset ERT
1785 status Collapsed
1786
1787 \layout Standard
1788
1789 \backslash 
1790 /
1791 \end_inset 
1792
1793 -disable-xa51-port
1794 \layout Standard
1795
1796 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1797 32'):
1798 \layout LyX-Code
1799
1800 ./configure 
1801 \backslash 
1802
1803 \newline 
1804 CC=
1805 \begin_inset Quotes srd
1806 \end_inset 
1807
1808 i586-mingw32msvc-gcc
1809 \begin_inset Quotes srd
1810 \end_inset 
1811
1812  CXX=
1813 \begin_inset Quotes srd
1814 \end_inset 
1815
1816 i586-mingw32msvc-g++
1817 \begin_inset Quotes srd
1818 \end_inset 
1819
1820  
1821 \backslash 
1822  
1823 \newline 
1824 RANLIB=
1825 \begin_inset Quotes srd
1826 \end_inset 
1827
1828 i586-mingw32msvc-ranlib
1829 \begin_inset Quotes srd
1830 \end_inset 
1831
1832  
1833 \backslash 
1834
1835 \newline 
1836 STRIP=
1837 \begin_inset Quotes srd
1838 \end_inset 
1839
1840 i586-mingw32msvc-strip
1841 \begin_inset Quotes srd
1842 \end_inset 
1843
1844  
1845 \backslash 
1846
1847 \newline 
1848 -
1849 \begin_inset ERT
1850 status Collapsed
1851
1852 \layout Standard
1853
1854 \backslash 
1855 /
1856 \end_inset 
1857
1858 -prefix=
1859 \begin_inset Quotes srd
1860 \end_inset 
1861
1862 /sdcc
1863 \begin_inset Quotes srd
1864 \end_inset 
1865
1866  
1867 \backslash 
1868
1869 \newline 
1870 -
1871 \begin_inset ERT
1872 status Collapsed
1873
1874 \layout Standard
1875
1876 \backslash 
1877 /
1878 \end_inset 
1879
1880 -datadir=
1881 \begin_inset Quotes srd
1882 \end_inset 
1883
1884 /sdcc
1885 \begin_inset Quotes srd
1886 \end_inset 
1887
1888  
1889 \backslash 
1890
1891 \newline 
1892 docdir=
1893 \begin_inset Quotes srd
1894 \end_inset 
1895
1896 /sdcc/doc
1897 \begin_inset Quotes srd
1898 \end_inset 
1899
1900  
1901 \backslash 
1902
1903 \newline 
1904 include_dir_suffix=
1905 \begin_inset Quotes srd
1906 \end_inset 
1907
1908 include
1909 \begin_inset Quotes srd
1910 \end_inset 
1911
1912  
1913 \backslash 
1914
1915 \newline 
1916 lib_dir_suffix=
1917 \begin_inset Quotes srd
1918 \end_inset 
1919
1920 lib
1921 \begin_inset Quotes srd
1922 \end_inset 
1923
1924  
1925 \backslash 
1926
1927 \newline 
1928 sdccconf_h_dir_separator=
1929 \begin_inset Quotes srd
1930 \end_inset 
1931
1932
1933 \backslash 
1934
1935 \backslash 
1936
1937 \backslash 
1938
1939 \backslash 
1940
1941 \begin_inset Quotes srd
1942 \end_inset 
1943
1944  
1945 \backslash 
1946
1947 \newline 
1948 -
1949 \begin_inset ERT
1950 status Collapsed
1951
1952 \layout Standard
1953
1954 \backslash 
1955 /
1956 \end_inset 
1957
1958 -disable-device-lib
1959 \backslash 
1960
1961 \newline 
1962 -
1963 \begin_inset ERT
1964 status Collapsed
1965
1966 \layout Standard
1967
1968 \backslash 
1969 /
1970 \end_inset 
1971
1972 -host=i586-mingw32msvc
1973 \backslash 
1974
1975 \newline 
1976 -
1977 \begin_inset ERT
1978 status Collapsed
1979
1980 \layout Standard
1981
1982 \backslash 
1983 /
1984 \end_inset 
1985
1986 -build=unknown-unknown-linux-gnu
1987 \layout Standard
1988
1989 To 
1990 \begin_inset Quotes sld
1991 \end_inset 
1992
1993 cross
1994 \begin_inset Quotes srd
1995 \end_inset 
1996
1997 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1998 ):
1999 \layout LyX-Code
2000
2001 ./configure -C 
2002 \backslash 
2003
2004 \newline 
2005 -
2006 \begin_inset ERT
2007 status Collapsed
2008
2009 \layout Standard
2010
2011 \backslash 
2012 /
2013 \end_inset 
2014
2015 -prefix=
2016 \begin_inset Quotes srd
2017 \end_inset 
2018
2019 /sdcc
2020 \begin_inset Quotes srd
2021 \end_inset 
2022
2023  
2024 \backslash 
2025
2026 \newline 
2027 -
2028 \begin_inset ERT
2029 status Collapsed
2030
2031 \layout Standard
2032
2033 \backslash 
2034 /
2035 \end_inset 
2036
2037 -datadir=
2038 \begin_inset Quotes srd
2039 \end_inset 
2040
2041 /sdcc
2042 \begin_inset Quotes srd
2043 \end_inset 
2044
2045  
2046 \backslash 
2047
2048 \newline 
2049 docdir=
2050 \begin_inset Quotes srd
2051 \end_inset 
2052
2053 /sdcc/doc
2054 \begin_inset Quotes srd
2055 \end_inset 
2056
2057  
2058 \backslash 
2059  
2060 \newline 
2061 include_dir_suffix=
2062 \begin_inset Quotes srd
2063 \end_inset 
2064
2065 include
2066 \begin_inset Quotes srd
2067 \end_inset 
2068
2069  
2070 \backslash 
2071
2072 \newline 
2073 lib_dir_suffix=
2074 \begin_inset Quotes srd
2075 \end_inset 
2076
2077 lib
2078 \begin_inset Quotes srd
2079 \end_inset 
2080
2081  
2082 \backslash 
2083
2084 \newline 
2085 sdccconf_h_dir_separator=
2086 \begin_inset Quotes srd
2087 \end_inset 
2088
2089
2090 \backslash 
2091
2092 \backslash 
2093
2094 \backslash 
2095
2096 \backslash 
2097
2098 \begin_inset Quotes srd
2099 \end_inset 
2100
2101  
2102 \backslash 
2103
2104 \newline 
2105 CC=
2106 \begin_inset Quotes srd
2107 \end_inset 
2108
2109 gcc -mno-cygwin
2110 \begin_inset Quotes srd
2111 \end_inset 
2112
2113  
2114 \backslash 
2115
2116 \newline 
2117 CXX=
2118 \begin_inset Quotes srd
2119 \end_inset 
2120
2121 g++ -mno-cygwin
2122 \begin_inset Quotes srd
2123 \end_inset 
2124
2125  
2126 \layout Standard
2127
2128 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2129  The option '-
2130 \begin_inset ERT
2131 status Collapsed
2132
2133 \layout Standard
2134
2135 \backslash 
2136 /
2137 \end_inset 
2138
2139 -C' turns on caching, which gives a little bit extra speed.
2140  However if options are changed, it can be necessary to delete the config.cache
2141  file.
2142 \layout Section
2143
2144 Install paths
2145 \begin_inset LatexCommand \label{sub:Install-paths}
2146
2147 \end_inset 
2148
2149
2150 \begin_inset LatexCommand \index{Install paths}
2151
2152 \end_inset 
2153
2154
2155 \layout Standard
2156 \added_space_top medskip \align center 
2157
2158 \begin_inset  Tabular
2159 <lyxtabular version="3" rows="5" columns="4">
2160 <features>
2161 <column alignment="left" valignment="top" leftline="true" width="0">
2162 <column alignment="left" valignment="top" leftline="true" width="0">
2163 <column alignment="left" valignment="top" leftline="true" width="0">
2164 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2165 <row topline="true" bottomline="true">
2166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2167 \begin_inset Text
2168
2169 \layout Standard
2170
2171
2172 \series bold 
2173 Description
2174 \end_inset 
2175 </cell>
2176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2177 \begin_inset Text
2178
2179 \layout Standard
2180
2181
2182 \series bold 
2183 Path
2184 \end_inset 
2185 </cell>
2186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2187 \begin_inset Text
2188
2189 \layout Standard
2190
2191
2192 \series bold 
2193 Default
2194 \end_inset 
2195 </cell>
2196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2197 \begin_inset Text
2198
2199 \layout Standard
2200
2201
2202 \series bold 
2203 Win32 builds
2204 \end_inset 
2205 </cell>
2206 </row>
2207 <row topline="true">
2208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2209 \begin_inset Text
2210
2211 \layout Standard
2212
2213 Binary files*
2214 \end_inset 
2215 </cell>
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2217 \begin_inset Text
2218
2219 \layout Standard
2220
2221
2222 \emph on 
2223 $EXEC_PREFIX
2224 \end_inset 
2225 </cell>
2226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2227 \begin_inset Text
2228
2229 \layout Standard
2230
2231 /usr/local/bin
2232 \end_inset 
2233 </cell>
2234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2235 \begin_inset Text
2236
2237 \layout Standard
2238
2239
2240 \backslash 
2241 sdcc
2242 \backslash 
2243 bin
2244 \end_inset 
2245 </cell>
2246 </row>
2247 <row topline="true">
2248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2249 \begin_inset Text
2250
2251 \layout Standard
2252
2253 Include files
2254 \end_inset 
2255 </cell>
2256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2257 \begin_inset Text
2258
2259 \layout Standard
2260
2261
2262 \emph on 
2263 $DATADIR/ $INCLUDE_DIR_SUFFIX
2264 \end_inset 
2265 </cell>
2266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2267 \begin_inset Text
2268
2269 \layout Standard
2270
2271 /usr/local/share/sdcc/include
2272 \end_inset 
2273 </cell>
2274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2275 \begin_inset Text
2276
2277 \layout Standard
2278
2279
2280 \backslash 
2281 sdcc
2282 \backslash 
2283 include
2284 \end_inset 
2285 </cell>
2286 </row>
2287 <row topline="true">
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2289 \begin_inset Text
2290
2291 \layout Standard
2292
2293 Library file**
2294 \end_inset 
2295 </cell>
2296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2297 \begin_inset Text
2298
2299 \layout Standard
2300
2301
2302 \emph on 
2303 $DATADIR/$LIB_DIR_SUFFIX
2304 \end_inset 
2305 </cell>
2306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2307 \begin_inset Text
2308
2309 \layout Standard
2310
2311 /usr/local/share/sdcc/lib
2312 \end_inset 
2313 </cell>
2314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2315 \begin_inset Text
2316
2317 \layout Standard
2318
2319
2320 \backslash 
2321 sdcc
2322 \backslash 
2323 lib
2324 \end_inset 
2325 </cell>
2326 </row>
2327 <row topline="true" bottomline="true">
2328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2329 \begin_inset Text
2330
2331 \layout Standard
2332
2333 Documentation
2334 \end_inset 
2335 </cell>
2336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2337 \begin_inset Text
2338
2339 \layout Standard
2340
2341
2342 \emph on 
2343 $DOCDIR
2344 \end_inset 
2345 </cell>
2346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2347 \begin_inset Text
2348
2349 \layout Standard
2350
2351 /usr/local/share/sdcc/doc
2352 \end_inset 
2353 </cell>
2354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2355 \begin_inset Text
2356
2357 \layout Standard
2358
2359
2360 \backslash 
2361 sdcc
2362 \backslash 
2363 doc
2364 \end_inset 
2365 </cell>
2366 </row>
2367 </lyxtabular>
2368
2369 \end_inset 
2370
2371
2372 \layout Verse
2373
2374
2375 \size footnotesize 
2376 *compiler, preprocessor, assembler, and linker
2377 \newline 
2378 **the 
2379 \shape italic 
2380 model
2381 \shape default 
2382  is auto-appended by the compiler, e.g.
2383  small, large, z80, ds390 etc
2384 \layout Standard
2385 \noindent 
2386 The install paths can still be changed during `make install` with e.g.:
2387 \layout LyX-Code
2388
2389 make install prefix=$(HOME)/local/sdcc
2390 \layout Standard
2391
2392 Of course this doesn't change the search paths compiled into the binaries.
2393 \newline 
2394
2395 \newline 
2396 Moreover the install path can be changed by defining DESTDIR
2397 \begin_inset LatexCommand \index{DESTDIR}
2398
2399 \end_inset 
2400
2401 :
2402 \layout LyX-Code
2403
2404 make install DESTDIR=$(HOME)/sdcc.rpm/
2405 \layout Standard
2406
2407 Please note that DESTDIR must have a trailing slash!
2408 \layout Section
2409
2410 Search Paths
2411 \begin_inset LatexCommand \label{sub:Search-Paths}
2412
2413 \end_inset 
2414
2415
2416 \begin_inset LatexCommand \index{Search path}
2417
2418 \end_inset 
2419
2420
2421 \layout Standard
2422
2423 Some search paths or parts of them are determined by configure variables
2424  (in 
2425 \emph on 
2426 italics
2427 \emph default 
2428 , see section above).
2429  Further search paths are determined by environment variables during runtime.
2430  
2431 \newline 
2432 The paths searched when running the compiler are as follows (the first catch
2433  wins):
2434 \newline 
2435
2436 \newline 
2437 1.
2438  Binary files (preprocessor, assembler and linker)
2439 \newline 
2440
2441 \layout Standard
2442 \align center 
2443
2444 \begin_inset  Tabular
2445 <lyxtabular version="3" rows="4" columns="3">
2446 <features>
2447 <column alignment="block" valignment="top" leftline="true" width="0in">
2448 <column alignment="block" valignment="top" leftline="true" width="0in">
2449 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2450 <row topline="true" bottomline="true">
2451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2452 \begin_inset Text
2453
2454 \layout Standard
2455
2456 Search path
2457 \end_inset 
2458 </cell>
2459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2460 \begin_inset Text
2461
2462 \layout Standard
2463
2464 default
2465 \end_inset 
2466 </cell>
2467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2468 \begin_inset Text
2469
2470 \layout Standard
2471
2472 Win32 builds
2473 \end_inset 
2474 </cell>
2475 </row>
2476 <row topline="true">
2477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2478 \begin_inset Text
2479
2480 \layout Standard
2481
2482 $SDCC_HOME/
2483 \emph on 
2484 $PPREFIX2BIN_DIR
2485 \end_inset 
2486 </cell>
2487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2488 \begin_inset Text
2489
2490 \layout Standard
2491
2492 $SDCC_HOME/bin
2493 \end_inset 
2494 </cell>
2495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2496 \begin_inset Text
2497
2498 \layout Standard
2499
2500 $SDCC_HOME
2501 \backslash 
2502 bin
2503 \end_inset 
2504 </cell>
2505 </row>
2506 <row topline="true">
2507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2508 \begin_inset Text
2509
2510 \layout Standard
2511
2512 Path of argv[0] (if available)
2513 \end_inset 
2514 </cell>
2515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2516 \begin_inset Text
2517
2518 \layout Standard
2519
2520 Path of argv[0]
2521 \end_inset 
2522 </cell>
2523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2524 \begin_inset Text
2525
2526 \layout Standard
2527
2528 Path of argv[0]
2529 \end_inset 
2530 </cell>
2531 </row>
2532 <row topline="true" bottomline="true">
2533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2534 \begin_inset Text
2535
2536 \layout Standard
2537
2538 $PATH
2539 \end_inset 
2540 </cell>
2541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2542 \begin_inset Text
2543
2544 \layout Standard
2545
2546 $PATH
2547 \end_inset 
2548 </cell>
2549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2550 \begin_inset Text
2551
2552 \layout Standard
2553
2554 $PATH
2555 \end_inset 
2556 </cell>
2557 </row>
2558 </lyxtabular>
2559
2560 \end_inset 
2561
2562  
2563 \newline 
2564
2565 \layout Standard
2566 \noindent 
2567 2.
2568  Include files
2569 \newline 
2570
2571 \layout Standard
2572 \align center 
2573
2574 \begin_inset  Tabular
2575 <lyxtabular version="3" rows="6" columns="3">
2576 <features>
2577 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2578 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2579 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2580 <row topline="true" bottomline="true">
2581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2582 \begin_inset Text
2583
2584 \layout Standard
2585
2586 Search path
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 default
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 Win32 builds
2603 \end_inset 
2604 </cell>
2605 </row>
2606 <row topline="true">
2607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2608 \begin_inset Text
2609
2610 \layout Standard
2611
2612 -
2613 \begin_inset ERT
2614 status Collapsed
2615
2616 \layout Standard
2617
2618 \backslash 
2619 /
2620 \end_inset 
2621
2622 -I dir
2623 \end_inset 
2624 </cell>
2625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2626 \begin_inset Text
2627
2628 \layout Standard
2629
2630 -
2631 \begin_inset ERT
2632 status Collapsed
2633
2634 \layout Standard
2635
2636 \backslash 
2637 /
2638 \end_inset 
2639
2640 -I dir
2641 \end_inset 
2642 </cell>
2643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2644 \begin_inset Text
2645
2646 \layout Standard
2647
2648 -
2649 \begin_inset ERT
2650 status Collapsed
2651
2652 \layout Standard
2653
2654 \backslash 
2655 /
2656 \end_inset 
2657
2658 -I dir
2659 \end_inset 
2660 </cell>
2661 </row>
2662 <row topline="true">
2663 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2664 \begin_inset Text
2665
2666 \layout Standard
2667
2668 $SDCC_INCLUDE
2669 \end_inset 
2670 </cell>
2671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2672 \begin_inset Text
2673
2674 \layout Standard
2675
2676 $SDCC_INCLUDE
2677 \end_inset 
2678 </cell>
2679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2680 \begin_inset Text
2681
2682 \layout Standard
2683
2684 $SDCC_INCLUDE
2685 \end_inset 
2686 </cell>
2687 </row>
2688 <row topline="true">
2689 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2690 \begin_inset Text
2691
2692 \layout Standard
2693
2694 $SDCC_HOME/
2695 \newline 
2696
2697 \emph on 
2698 $PREFIX2DATA_DIR/
2699 \newline 
2700 $INCLUDE_DIR_SUFFIX
2701 \end_inset 
2702 </cell>
2703 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2704 \begin_inset Text
2705
2706 \layout Standard
2707
2708 $SDCC_ HOME/
2709 \newline 
2710 share/sdcc/
2711 \newline 
2712 include
2713 \end_inset 
2714 </cell>
2715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2716 \begin_inset Text
2717
2718 \layout Standard
2719
2720 $SDCC_HOME
2721 \backslash 
2722 include
2723 \end_inset 
2724 </cell>
2725 </row>
2726 <row topline="true">
2727 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2728 \begin_inset Text
2729
2730 \layout Standard
2731
2732 path(argv[0])/
2733 \newline 
2734
2735 \emph on 
2736 $BIN2DATADIR/
2737 \emph default 
2738
2739 \newline 
2740
2741 \emph on 
2742 $INCLUDE_DIR_SUFFIX
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 path(argv[0])/
2751 \newline 
2752 ../sdcc/include
2753 \newline 
2754 \SpecialChar ~
2755 \SpecialChar ~
2756 \SpecialChar ~
2757 \SpecialChar ~
2758 \SpecialChar ~
2759 \SpecialChar ~
2760 \SpecialChar ~
2761 \SpecialChar ~
2762 \SpecialChar ~
2763 \SpecialChar ~
2764 \SpecialChar ~
2765 \SpecialChar ~
2766 \SpecialChar ~
2767 \SpecialChar ~
2768 \SpecialChar ~
2769 \SpecialChar ~
2770 \SpecialChar ~
2771 \SpecialChar ~
2772 \SpecialChar ~
2773 \SpecialChar ~
2774 \SpecialChar ~
2775 \SpecialChar ~
2776 \SpecialChar ~
2777 \SpecialChar ~
2778 \SpecialChar ~
2779 \SpecialChar ~
2780 \SpecialChar ~
2781 \SpecialChar ~
2782 \SpecialChar ~
2783 \SpecialChar ~
2784 \SpecialChar ~
2785 \SpecialChar ~
2786 \SpecialChar ~
2787 \SpecialChar ~
2788 \SpecialChar ~
2789 \SpecialChar ~
2790 \SpecialChar ~
2791 \SpecialChar ~
2792
2793 \end_inset 
2794 </cell>
2795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2796 \begin_inset Text
2797
2798 \layout Standard
2799
2800 path(argv[0])
2801 \backslash 
2802 ..
2803 \backslash 
2804 include
2805 \end_inset 
2806 </cell>
2807 </row>
2808 <row topline="true" bottomline="true">
2809 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2810 \begin_inset Text
2811
2812 \layout Standard
2813
2814
2815 \emph on 
2816 $DATADIR/
2817 \emph default 
2818
2819 \newline 
2820
2821 \emph on 
2822 $INCLUDE_DIR_SUFFIX
2823 \end_inset 
2824 </cell>
2825 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2826 \begin_inset Text
2827
2828 \layout Standard
2829
2830 /usr/local/share/sdcc/
2831 \newline 
2832 include
2833 \end_inset 
2834 </cell>
2835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2836 \begin_inset Text
2837
2838 \layout Standard
2839
2840 (not on Win32)
2841 \end_inset 
2842 </cell>
2843 </row>
2844 </lyxtabular>
2845
2846 \end_inset 
2847
2848  
2849 \newline 
2850
2851 \layout Standard
2852 \noindent 
2853 The option -
2854 \begin_inset ERT
2855 status Collapsed
2856
2857 \layout Standard
2858
2859 \backslash 
2860 /
2861 \end_inset 
2862
2863 -nostdinc disables the last two search paths.
2864 \newline 
2865
2866 \newline 
2867 3.
2868  Library files 
2869 \newline 
2870
2871 \layout Standard
2872
2873 With the exception of 
2874 \begin_inset Quotes sld
2875 \end_inset 
2876
2877 -
2878 \begin_inset ERT
2879 status Collapsed
2880
2881 \layout Standard
2882
2883 \backslash 
2884 /
2885 \end_inset 
2886
2887 -L dir
2888 \begin_inset Quotes srd
2889 \end_inset 
2890
2891  the 
2892 \shape italic 
2893 model
2894 \shape default 
2895  is auto-appended by the compiler (e.g.
2896  small, large, z80, ds390 etc.).
2897  
2898 \newline 
2899
2900 \layout Standard
2901 \align center 
2902
2903 \begin_inset  Tabular
2904 <lyxtabular version="3" rows="6" columns="3">
2905 <features>
2906 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2907 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2908 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2909 <row topline="true" bottomline="true">
2910 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2911 \begin_inset Text
2912
2913 \layout Standard
2914
2915 Search path
2916 \end_inset 
2917 </cell>
2918 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2919 \begin_inset Text
2920
2921 \layout Standard
2922
2923 default
2924 \end_inset 
2925 </cell>
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2927 \begin_inset Text
2928
2929 \layout Standard
2930
2931 Win32 builds
2932 \end_inset 
2933 </cell>
2934 </row>
2935 <row topline="true">
2936 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2937 \begin_inset Text
2938
2939 \layout Standard
2940
2941 -
2942 \begin_inset ERT
2943 status Collapsed
2944
2945 \layout Standard
2946
2947 \backslash 
2948 /
2949 \end_inset 
2950
2951 -L dir
2952 \end_inset 
2953 </cell>
2954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2955 \begin_inset Text
2956
2957 \layout Standard
2958
2959 -
2960 \begin_inset ERT
2961 status Collapsed
2962
2963 \layout Standard
2964
2965 \backslash 
2966 /
2967 \end_inset 
2968
2969 -L dir
2970 \end_inset 
2971 </cell>
2972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2973 \begin_inset Text
2974
2975 \layout Standard
2976
2977 -
2978 \begin_inset ERT
2979 status Collapsed
2980
2981 \layout Standard
2982
2983 \backslash 
2984 /
2985 \end_inset 
2986
2987 -L dir
2988 \end_inset 
2989 </cell>
2990 </row>
2991 <row topline="true">
2992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2993 \begin_inset Text
2994
2995 \layout Standard
2996
2997 $SDCC_LIB/
2998 \newline 
2999
3000 \emph on 
3001 <model>
3002 \end_inset 
3003 </cell>
3004 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3005 \begin_inset Text
3006
3007 \layout Standard
3008
3009 $SDCC_LIB/
3010 \newline 
3011
3012 \emph on 
3013 <model>
3014 \end_inset 
3015 </cell>
3016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3017 \begin_inset Text
3018
3019 \layout Standard
3020
3021 $SDCC_LIB
3022 \backslash 
3023
3024 \newline 
3025
3026 \emph on 
3027 <model>
3028 \end_inset 
3029 </cell>
3030 </row>
3031 <row topline="true">
3032 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3033 \begin_inset Text
3034
3035 \layout Standard
3036
3037 $SDCC_HOME/
3038 \newline 
3039
3040 \emph on 
3041 $PREFIX2DATA_DIR/
3042 \newline 
3043 $LIB_DIR_SUFFIX/<model>
3044 \end_inset 
3045 </cell>
3046 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3047 \begin_inset Text
3048
3049 \layout Standard
3050
3051 $SDCC_HOME/
3052 \newline 
3053 share/sdcc/
3054 \newline 
3055 lib/
3056 \emph on 
3057 <model>
3058 \end_inset 
3059 </cell>
3060 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3061 \begin_inset Text
3062
3063 \layout Standard
3064
3065 $SDCC_HOME
3066 \backslash 
3067 lib
3068 \backslash 
3069
3070 \emph on 
3071
3072 \newline 
3073 <model>
3074 \end_inset 
3075 </cell>
3076 </row>
3077 <row topline="true">
3078 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3079 \begin_inset Text
3080
3081 \layout Standard
3082
3083 path(argv[0])/
3084 \newline 
3085
3086 \emph on 
3087 $BIN2DATADIR/
3088 \emph default 
3089
3090 \newline 
3091
3092 \emph on 
3093 $LIB_DIR_SUFFIX/<model>
3094 \end_inset 
3095 </cell>
3096 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3097 \begin_inset Text
3098
3099 \layout Standard
3100
3101 path(argv[0])/
3102 \newline 
3103 ../sdcc/lib/
3104 \emph on 
3105 <model>
3106 \newline 
3107 \SpecialChar ~
3108 \SpecialChar ~
3109 \SpecialChar ~
3110 \SpecialChar ~
3111 \SpecialChar ~
3112 \SpecialChar ~
3113 \SpecialChar ~
3114 \SpecialChar ~
3115 \SpecialChar ~
3116 \SpecialChar ~
3117 \SpecialChar ~
3118 \SpecialChar ~
3119 \SpecialChar ~
3120 \SpecialChar ~
3121 \SpecialChar ~
3122 \SpecialChar ~
3123 \SpecialChar ~
3124 \SpecialChar ~
3125 \SpecialChar ~
3126 \SpecialChar ~
3127 \SpecialChar ~
3128 \SpecialChar ~
3129 \SpecialChar ~
3130 \SpecialChar ~
3131 \SpecialChar ~
3132 \SpecialChar ~
3133 \SpecialChar ~
3134 \SpecialChar ~
3135 \SpecialChar ~
3136 \SpecialChar ~
3137 \SpecialChar ~
3138 \SpecialChar ~
3139 \SpecialChar ~
3140 \SpecialChar ~
3141 \SpecialChar ~
3142 \SpecialChar ~
3143 \SpecialChar ~
3144 \SpecialChar ~
3145 \SpecialChar ~
3146
3147 \end_inset 
3148 </cell>
3149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3150 \begin_inset Text
3151
3152 \layout Standard
3153
3154 path(argv[0])
3155 \backslash 
3156
3157 \newline 
3158 ..
3159 \backslash 
3160 lib
3161 \backslash 
3162
3163 \emph on 
3164 <model>
3165 \newline 
3166 \SpecialChar ~
3167 \SpecialChar ~
3168 \SpecialChar ~
3169 \SpecialChar ~
3170 \SpecialChar ~
3171 \SpecialChar ~
3172 \SpecialChar ~
3173 \SpecialChar ~
3174 \SpecialChar ~
3175 \SpecialChar ~
3176 \SpecialChar ~
3177 \SpecialChar ~
3178 \SpecialChar ~
3179 \SpecialChar ~
3180 \SpecialChar ~
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
3202 \end_inset 
3203 </cell>
3204 </row>
3205 <row topline="true" bottomline="true">
3206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3207 \begin_inset Text
3208
3209 \layout Standard
3210
3211
3212 \emph on 
3213 $DATADIR/
3214 \newline 
3215 $LIB_DIR_SUFFIX/<model>
3216 \end_inset 
3217 </cell>
3218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3219 \begin_inset Text
3220
3221 \layout Standard
3222
3223 /usr/local/share/sdcc/
3224 \newline 
3225 lib/
3226 \emph on 
3227 <model>
3228 \end_inset 
3229 </cell>
3230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3231 \begin_inset Text
3232
3233 \layout Standard
3234
3235 (not on Win32)
3236 \end_inset 
3237 </cell>
3238 </row>
3239 </lyxtabular>
3240
3241 \end_inset 
3242
3243
3244 \newline 
3245
3246 \layout Comment
3247
3248 Don't delete any of the stray spaces in the table above without checking
3249  the HTML output (last line)!
3250 \layout Standard
3251
3252 \SpecialChar ~
3253
3254 \newline 
3255 The option -
3256 \begin_inset ERT
3257 status Collapsed
3258
3259 \layout Standard
3260
3261 \backslash 
3262 /
3263 \end_inset 
3264
3265 -nostdlib disables the last two search paths.
3266 \layout Section
3267
3268 Building SDCC
3269 \begin_inset LatexCommand \index{Building SDCC}
3270
3271 \end_inset 
3272
3273
3274 \layout Subsection
3275
3276 Building SDCC on Linux
3277 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3278
3279 \end_inset 
3280
3281
3282 \layout Enumerate
3283
3284
3285 \series medium 
3286 Download the source package
3287 \series default 
3288  either from the SDCC Subversion repository or from the nightly snapshots
3289 \series medium 
3290 , it will be named something like sdcc
3291 \series default 
3292 .src
3293 \series medium 
3294 .t
3295 \series default 
3296 ar.
3297 \series medium 
3298 gz
3299 \series default 
3300  
3301 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3302
3303 \end_inset 
3304
3305 .
3306 \layout Enumerate
3307
3308
3309 \series medium 
3310 Bring up a command line terminal, such as xterm.
3311 \layout Enumerate
3312
3313
3314 \series medium 
3315 Unpack the file using a command like: 
3316 \family sans 
3317 \series bold 
3318 "tar -xvzf sdcc.src.tar.gz
3319 \family default 
3320 \series default 
3321 "
3322 \series medium 
3323 , this will create a sub-directory called sdcc with all of the sources.
3324 \layout Enumerate
3325
3326 Change directory into the main SDCC directory, for example type: 
3327 \family sans 
3328 \series bold 
3329 "cd sdcc
3330 \series default 
3331 ".
3332 \layout Enumerate
3333
3334
3335 \series medium 
3336 Type 
3337 \family sans 
3338 \series bold 
3339 "./configure
3340 \family default 
3341 \series default 
3342 ".
3343  This configures the package for compilation on your system.
3344 \layout Enumerate
3345
3346
3347 \series medium 
3348 Type 
3349 \family sans 
3350 \series bold 
3351 "make
3352 \family default 
3353 \series default 
3354 "
3355 \series medium 
3356 .
3357
3358 \series default 
3359  All of the source packages will compile, this can take a while.
3360 \layout Enumerate
3361
3362
3363 \series medium 
3364 Type 
3365 \family sans 
3366 \series bold 
3367 "make install"
3368 \family default 
3369 \series default 
3370  as root
3371 \series medium 
3372 .
3373
3374 \series default 
3375  This copies the binary executables, the include files, the libraries and
3376  the documentation to the install directories.
3377  Proceed with section 
3378 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3379
3380 \end_inset 
3381
3382 .
3383 \layout Subsection
3384
3385 Building SDCC on OSX 2.x
3386 \layout Standard
3387
3388 Follow the instruction for Linux.
3389 \newline 
3390
3391 \newline 
3392 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3393 )) fails to compile SDCC.
3394  Fortunately there's also gcc 2.9.x installed, which works fine.
3395  This compiler can be selected by running 'configure' with:
3396 \layout LyX-Code
3397
3398 ./configure CC=gcc2 CXX=g++2
3399 \layout Subsection
3400
3401 Cross compiling SDCC on Linux for Windows
3402 \layout Standard
3403
3404 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3405  See section 'Configure Options'.
3406 \layout Subsection
3407
3408 Building SDCC using Cygwin and Mingw32
3409 \layout Standard
3410
3411 For building and installing a Cygwin executable follow the instructions
3412  for Linux.
3413 \newline 
3414
3415 \newline 
3416 On Cygwin a 
3417 \begin_inset Quotes sld
3418 \end_inset 
3419
3420 native
3421 \begin_inset Quotes srd
3422 \end_inset 
3423
3424  Win32-binary can be built, which will not need the Cygwin-DLL.
3425  For the necessary 'configure' options see section 'configure options' or
3426  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3427 \newline 
3428
3429 \newline 
3430 In order to install Cygwin on Windows download setup.exe from 
3431 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3432
3433 \end_inset 
3434
3435 .
3436  Run it, set the 
3437 \begin_inset Quotes sld
3438 \end_inset 
3439
3440 default text file type
3441 \begin_inset Quotes srd
3442 \end_inset 
3443
3444  to 
3445 \begin_inset Quotes sld
3446 \end_inset 
3447
3448 unix
3449 \begin_inset Quotes srd
3450 \end_inset 
3451
3452  and download/install at least the following packages.
3453  Some packages are selected by default, others will be automatically selected
3454  because of dependencies with the manually selected packages.
3455  Never deselect these packages!
3456 \layout Itemize
3457
3458 flex
3459 \layout Itemize
3460
3461 bison
3462 \layout Itemize
3463
3464 gcc ; version 3.x is fine, no need to use the old 2.9x
3465 \layout Itemize
3466
3467 binutils ; selected with gcc
3468 \layout Itemize
3469
3470 make
3471 \layout Itemize
3472
3473 rxvt ; a nice console, which makes life much easier under windoze (see below)
3474 \layout Itemize
3475
3476 man ; not really needed for building SDCC, but you'll miss it sooner or
3477  later
3478 \layout Itemize
3479
3480 less ; not really needed for building SDCC, but you'll miss it sooner or
3481  later
3482 \layout Itemize
3483
3484 svn ; only if you use Subversion access
3485 \layout Standard
3486
3487 If you want to develop something you'll need:
3488 \layout Itemize
3489
3490 python ; for the regression tests
3491 \layout Itemize
3492
3493 gdb ; the gnu debugger, together with the nice GUI 
3494 \begin_inset Quotes sld
3495 \end_inset 
3496
3497 insight
3498 \begin_inset Quotes srd
3499 \end_inset 
3500
3501
3502 \layout Itemize
3503
3504 openssh ; to access the CF or commit changes
3505 \layout Itemize
3506
3507 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3508  use autoconf-stable!
3509 \layout Standard
3510
3511 rxvt is a nice console with history.
3512  Replace in your cygwin.bat the line
3513 \layout LyX-Code
3514
3515 bash -
3516 \begin_inset ERT
3517 status Collapsed
3518
3519 \layout Standard
3520
3521 \backslash 
3522 /
3523 \end_inset 
3524
3525 -login -i 
3526 \layout Standard
3527
3528 with (one line):
3529 \layout LyX-Code
3530
3531 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3532 \layout LyX-Code
3533
3534      -bg black -fg white -geometry 100x65 -e bash -
3535 \begin_inset ERT
3536 status Collapsed
3537
3538 \layout Standard
3539
3540 \backslash 
3541 /
3542 \end_inset 
3543
3544 -login
3545 \layout Standard
3546
3547 Text selected with the mouse is automatically copied to the clipboard, pasting
3548  works with shift-insert.
3549 \newline 
3550
3551 \newline 
3552 The other good tip is to make sure you have no //c/-style paths anywhere,
3553  use /cygdrive/c/ instead.
3554  Using // invokes a network lookup which is very slow.
3555  If you think 
3556 \begin_inset Quotes sld
3557 \end_inset 
3558
3559 cygdrive
3560 \begin_inset Quotes srd
3561 \end_inset 
3562
3563  is too long, you can change it with e.g.
3564 \layout LyX-Code
3565
3566 mount -s -u -c /mnt
3567 \layout Standard
3568
3569 SDCC sources use the unix line ending LF.
3570  Life is much easier, if you store the source tree on a drive which is mounted
3571  in binary mode.
3572  And use an editor which can handle LF-only line endings.
3573  Make sure not to commit files with windows line endings.
3574  The tabulator spacing
3575 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3576
3577 \end_inset 
3578
3579  used in the project is 8.
3580  Although a tabulator spacing of 8 is a sensible choice for programmers
3581  (it's a power of 2 and allows to display 8/16 bit signed variables without
3582  loosing columns) the plan is to move towards using only spaces in the source.
3583 \layout Subsection
3584
3585 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3586 \layout Standard
3587
3588
3589 \series medium 
3590 Download the source package
3591 \series default 
3592  either from the SDCC Subversion repository or from the 
3593 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3594
3595 \end_inset 
3596
3597
3598 \series medium 
3599 , it will be named something like sdcc
3600 \series default 
3601 .src
3602 \series medium 
3603 .tgz.
3604
3605 \series default 
3606  SDCC is distributed with all the projects, workspaces, and files you need
3607  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3608  The workspace name is 'sdcc.dsw'.
3609  Please note that as it is now, all the executables are created in a folder
3610  called sdcc
3611 \backslash 
3612 bin_vc.
3613  Once built you need to copy the executables from sdcc
3614 \backslash 
3615 bin_vc to sdcc
3616 \backslash 
3617 bin before running SDCC.
3618  
3619 \newline 
3620
3621 \newline 
3622 WARNING: Visual studio is very picky with line terminations; it expects
3623  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3624  When using the Subversion repository it's easiest to configure the svn
3625  client to convert automatically for you.
3626  If however you are getting a message such as "This makefile was not generated
3627  by Developer Studio etc.
3628  etc.
3629 \begin_inset Quotes srd
3630 \end_inset 
3631
3632  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3633  need to convert the Unix style line endings to DOS style line endings.
3634  To do so you can use the 
3635 \begin_inset Quotes sld
3636 \end_inset 
3637
3638 unix2dos
3639 \begin_inset Quotes srd
3640 \end_inset 
3641
3642  utility freely available on the internet.
3643  Doug Hawkins reported in the sdcc-user list that this works:
3644 \newline 
3645
3646 \newline 
3647 C:
3648 \backslash 
3649 Programming
3650 \backslash 
3651 SDCC> unix2dos sdcc.dsw
3652 \newline 
3653 C:
3654 \backslash 
3655 Programming
3656 \backslash 
3657 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3658 \newline 
3659
3660 \newline 
3661 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3662  flex.exe, and gawk.exe.
3663  One good place to get them is 
3664 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3665
3666 \end_inset 
3667
3668
3669 \newline 
3670
3671 \newline 
3672 Download the file UnxUtils
3673 \begin_inset LatexCommand \index{UnxUtils}
3674
3675 \end_inset 
3676
3677 .zip.
3678  Now you have to install the utilities and setup MSVC so it can locate the
3679  required programs.
3680  Here there are two alternatives (choose one!):
3681 \layout Enumerate
3682
3683 The easy way:
3684 \newline 
3685
3686 \newline 
3687 a) Extract UnxUtils.zip to your C:
3688 \backslash 
3689  hard disk PRESERVING the original paths, otherwise bison won't work.
3690  (If you are using WinZip make certain that 'Use folder names' is selected)
3691 \newline 
3692
3693 \newline 
3694 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3695  in 'Show directories for:' select 'Executable files', and in the directories
3696  window add a new path: 'C:
3697 \backslash 
3698 user
3699 \backslash 
3700 local
3701 \backslash 
3702 wbin', click ok.
3703 \newline 
3704
3705 \newline 
3706 (As a side effect, you get a bunch of Unix utilities that could be useful,
3707  such as diff and patch.)
3708 \layout Enumerate
3709
3710 A more compact way:
3711 \newline 
3712
3713 \newline 
3714 This one avoids extracting a bunch of files you may not use, but requires
3715  some extra work:
3716 \newline 
3717
3718 \newline 
3719 a) Create a directory were to put the tools needed, or use a directory already
3720  present.
3721  Say for example 'C:
3722 \backslash 
3723 util'.
3724 \newline 
3725
3726 \newline 
3727 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3728  to such directory WITHOUT preserving the original paths.
3729  (If you are using WinZip make certain that 'Use folder names' is not selected)
3730 \newline 
3731
3732 \newline 
3733 c) Rename bison.exe to '_bison.exe'.
3734 \newline 
3735
3736 \newline 
3737 d) Create a batch file 'bison.bat' in 'C:
3738 \backslash 
3739 util
3740 \backslash 
3741 ' and add these lines: 
3742 \newline 
3743 \SpecialChar ~
3744 \SpecialChar ~
3745 set BISON_SIMPLE=C:
3746 \backslash 
3747 util
3748 \backslash 
3749 bison.simple 
3750 \newline 
3751 \SpecialChar ~
3752 \SpecialChar ~
3753 set BISON_HAIRY=C:
3754 \backslash 
3755 util
3756 \backslash 
3757 bison.hairy
3758 \newline 
3759 \SpecialChar ~
3760 \SpecialChar ~
3761 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3762 \newline 
3763
3764 \newline 
3765 Steps 'c' and 'd' are needed because bison requires by default that the
3766  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3767  '/usr/local/share/' I think.
3768  So it is necessary to tell bison where those files are located if they
3769  are not in such directory.
3770  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3771 \newline 
3772
3773 \newline 
3774 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3775  in 'Show directories for:' select 'Executable files', and in the directories
3776  window add a new path: 'c:
3777 \backslash 
3778 util', click ok.
3779  Note that you can use any other path instead of 'c:
3780 \backslash 
3781 util', even the path where the Visual C++ tools are, probably: 'C:
3782 \backslash 
3783 Program Files
3784 \backslash 
3785 Microsoft Visual Studio
3786 \backslash 
3787 Common
3788 \backslash 
3789 Tools'.
3790  So you don't have to execute step 'e' :)
3791 \layout Standard
3792
3793 That is it.
3794  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3795  the executables from sdcc
3796 \backslash 
3797 bin_vc to sdcc
3798 \backslash 
3799 bin, and you can compile using SDCC.
3800 \layout Subsection
3801
3802 Building SDCC Using Borland
3803 \layout Enumerate
3804
3805 From the sdcc directory, run the command "make -f Makefile.bcc".
3806  This should regenerate all the .exe files in the bin directory except for
3807  SDCDB and ucSim.
3808 \layout Enumerate
3809
3810 If you modify any source files and need to rebuild, be aware that the dependenci
3811 es may not be correctly calculated.
3812  The safest option is to delete all .obj files and run the build again.
3813  From a Cygwin BASH prompt, this can easily be done with the command (be
3814  sure you are in the sdcc directory):
3815 \newline 
3816
3817 \newline 
3818
3819 \family sans 
3820 \series bold 
3821 find .
3822  
3823 \backslash 
3824 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3825 \backslash 
3826 ) -print -exec rm {} 
3827 \backslash 
3828 ;
3829 \family default 
3830 \series default 
3831
3832 \newline 
3833
3834 \newline 
3835 or on Windows NT/2000/XP from the command prompt with the command:
3836 \newline 
3837
3838 \family sans 
3839 \series bold 
3840
3841 \newline 
3842 del /s *.obj *.lib *.rul
3843 \family default 
3844 \series default 
3845  from the sdcc directory.
3846 \layout Subsection
3847
3848 Windows Install Using a ZIP Package
3849 \layout Enumerate
3850
3851 Download the binary zip package from 
3852 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3853
3854 \end_inset 
3855
3856  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3857  This should unpack to a group of sub-directories.
3858  An example directory structure after unpacking the mingw32 package is:
3859  c:
3860 \backslash 
3861 sdcc
3862 \backslash 
3863 bin for the executables, c:
3864 \backslash 
3865 sdcc
3866 \backslash 
3867 include and c:
3868 \backslash 
3869 sdcc
3870 \backslash 
3871 lib for the include and libraries.
3872 \layout Enumerate
3873
3874 Adjust your environment variable PATH to include the location of the bin
3875  directory or start sdcc using the full path.
3876 \layout Subsection
3877
3878 Windows Install Using the Setup Program
3879 \begin_inset LatexCommand \label{sub:Windows-Install}
3880
3881 \end_inset 
3882
3883
3884 \layout Standard
3885
3886 Download the setup program 
3887 \emph on 
3888 sdcc-x.y.z-setup.exe
3889 \emph default 
3890  for an official release from 
3891 \newline 
3892
3893 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3894
3895 \end_inset 
3896
3897  or a setup program for one of the snapshots 
3898 \emph on 
3899 sdcc-yyyymmdd-xxxx-setup.exe
3900 \emph default 
3901  from 
3902 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3903
3904 \end_inset 
3905
3906  and execute it.
3907  A windows typical installer will guide you through the installation process.
3908 \layout Subsection
3909
3910 VPATH
3911 \begin_inset LatexCommand \index{VPATH}
3912
3913 \end_inset 
3914
3915  feature
3916 \layout Standard
3917
3918 SDCC supports the VPATH feature provided by configure and make.
3919  It allows to separate the source and build trees.
3920  Here's an example:
3921 \layout Standard
3922
3923
3924 \family typewriter 
3925 cd ~\SpecialChar ~
3926 \SpecialChar ~
3927 \SpecialChar ~
3928 \SpecialChar ~
3929 \SpecialChar ~
3930 \SpecialChar ~
3931 \SpecialChar ~
3932 \SpecialChar ~
3933 \SpecialChar ~
3934 \SpecialChar ~
3935 \SpecialChar ~
3936 \SpecialChar ~
3937 \SpecialChar ~
3938 \SpecialChar ~
3939 \SpecialChar ~
3940 \SpecialChar ~
3941 \SpecialChar ~
3942 \SpecialChar ~
3943 \SpecialChar ~
3944 \SpecialChar ~
3945 \SpecialChar ~
3946 # cd $HOME
3947 \layout Standard
3948
3949
3950 \family typewriter 
3951 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3952 # extract source to directory sdcc
3953 \layout Standard
3954
3955
3956 \family typewriter 
3957 mkdir sdcc.build\SpecialChar ~
3958 \SpecialChar ~
3959 \SpecialChar ~
3960 \SpecialChar ~
3961 \SpecialChar ~
3962 \SpecialChar ~
3963 \SpecialChar ~
3964 \SpecialChar ~
3965 \SpecialChar ~
3966 # put output in sdcc.build
3967 \layout Standard
3968
3969
3970 \family typewriter 
3971 cd sdcc.build
3972 \layout Standard
3973
3974
3975 \family typewriter 
3976 ../sdcc/configure\SpecialChar ~
3977 \SpecialChar ~
3978 \SpecialChar ~
3979 \SpecialChar ~
3980 \SpecialChar ~
3981 \SpecialChar ~
3982 \SpecialChar ~
3983 \SpecialChar ~
3984 # configure is doing all the magic!
3985 \layout Standard
3986
3987
3988 \family typewriter 
3989 make
3990 \layout Standard
3991 \noindent 
3992 That's it! 
3993 \series bold 
3994 configure
3995 \series default 
3996  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
3997  It automagically computes the variables srcdir, top_srcdir and top_buildir
3998  for each directory.
3999  After running 
4000 \series bold 
4001 make
4002 \series default 
4003  the generated files will be in ~/sdcc.build, while the source files stay
4004  in ~/sdcc.
4005 \newline 
4006 This is not only usefull for building different binaries, e.g.
4007  when cross compiling.
4008  It also gives you a much better overview in the source tree when all the
4009  generated files are not scattered between the source files.
4010  And the best thing is: if you want to change a file you can leave the original
4011  file untouched in the source directory.
4012  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4013  Makefile.dep` and `make`.
4014  
4015 \series bold 
4016 make
4017 \series default 
4018  will do the rest for you!
4019 \layout Section
4020
4021 Building the Documentation
4022 \layout Standard
4023
4024 Add -
4025 \begin_inset ERT
4026 status Collapsed
4027
4028 \layout Standard
4029
4030 \backslash 
4031 /
4032 \end_inset 
4033
4034 -enable-doc to the configure arguments to build the documentation together
4035  with all the other stuff.
4036  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4037  dvips and makeindex) to get the job done.
4038  Another possibility is to change to the doc directory and to type 
4039 \family sans 
4040 \series bold 
4041
4042 \begin_inset Quotes srd
4043 \end_inset 
4044
4045 make
4046 \begin_inset Quotes srd
4047 \end_inset 
4048
4049
4050 \family default 
4051 \series default 
4052  there.
4053  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4054 x).
4055  Using LyX 
4056 \begin_inset LatexCommand \url{http://www.lyx.org}
4057
4058 \end_inset 
4059
4060  as editor is straightforward.
4061  Prebuilt documentation in html and pdf format is available from 
4062 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4063
4064 \end_inset 
4065
4066 .
4067 \layout Section
4068
4069 Reading the Documentation
4070 \begin_inset LatexCommand \index{Documentation}
4071
4072 \end_inset 
4073
4074
4075 \layout Standard
4076
4077 Currently reading the document in pdf format is recommended, as for unknown
4078  reason the hyperlinks are working there whereas in the html version they
4079  are not
4080 \begin_inset Foot
4081 collapsed false
4082
4083 \layout Standard
4084
4085 If you should know why please drop us a note
4086 \end_inset 
4087
4088 .
4089  
4090 \newline 
4091 You'll find the pdf version
4092 \begin_inset LatexCommand \index{PDF version of this document}
4093
4094 \end_inset 
4095
4096  at 
4097 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4098
4099 \end_inset 
4100
4101 .
4102  
4103 \newline 
4104 A html version
4105 \begin_inset LatexCommand \index{HTML version of this document}
4106
4107 \end_inset 
4108
4109  should be online at 
4110 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4111
4112 \end_inset 
4113
4114 .
4115 \newline 
4116 This documentation is in some aspects different from a commercial documentation:
4117  
4118 \layout Itemize
4119
4120 It tries to document SDCC for several processor architectures in one document
4121  (commercially these probably would be separate documents/products).
4122  This document
4123 \begin_inset LatexCommand \index{Status of documentation}
4124
4125 \end_inset 
4126
4127  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4128 on about f.e.
4129  Z80, PIC14, PIC16 and HC08.
4130 \layout Itemize
4131
4132 There are many references pointing away from this documentation.
4133  Don't let this distract you.
4134  If there f.e.
4135  was a reference like 
4136 \begin_inset LatexCommand \url{http://www.opencores.org}
4137
4138 \end_inset 
4139
4140  together with a statement 
4141 \begin_inset Quotes sld
4142 \end_inset 
4143
4144 some processors which are targetted by SDCC can be implemented in a 
4145 \emph on 
4146 f
4147 \emph default 
4148 ield 
4149 \emph on 
4150 p
4151 \emph default 
4152 rogrammable 
4153 \emph on 
4154 g
4155 \emph default 
4156 ate 
4157 \emph on 
4158 a
4159 \emph default 
4160 rray
4161 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4162
4163 \end_inset 
4164
4165
4166 \begin_inset Quotes srd
4167 \end_inset 
4168
4169  or 
4170 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4171
4172 \end_inset 
4173
4174
4175 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4176
4177 \end_inset 
4178
4179  
4180 \begin_inset Quotes sld
4181 \end_inset 
4182
4183 have you ever heard of an open source compiler that compiles a subset of
4184  C for an FPGA?
4185 \begin_inset Quotes srd
4186 \end_inset 
4187
4188  we expect you to have a quick look there and come back.
4189  If you read this you are on the right track.
4190 \layout Itemize
4191
4192 Some sections attribute more space to problems, restrictions and warnings
4193  than to the solution.
4194 \layout Itemize
4195
4196 The installation section and the section about the debugger is intimidating.
4197 \layout Itemize
4198
4199 There are still lots of typos and there are more different writing styles
4200  than pictures.
4201 \layout Section
4202
4203 Testing the SDCC Compiler
4204 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4205
4206 \end_inset 
4207
4208
4209 \layout Standard
4210
4211 The first thing you should do after installing your SDCC compiler is to
4212  see if it runs.
4213  Type 
4214 \family sans 
4215 \series bold 
4216 "sdcc -
4217 \begin_inset ERT
4218 status Collapsed
4219
4220 \layout Standard
4221
4222 \backslash 
4223 /
4224 \end_inset 
4225
4226 -version"
4227 \begin_inset LatexCommand \index{version}
4228
4229 \end_inset 
4230
4231
4232 \family default 
4233 \series default 
4234  at the prompt, and the program should run and output its version like:
4235  
4236 \newline 
4237
4238 \family typewriter 
4239 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4240  (UNIX)
4241 \layout Standard
4242
4243 If it doesn't run, or gives a message about not finding sdcc program, then
4244  you need to check over your installation.
4245  Make sure that the sdcc bin directory is in your executable search path
4246  defined by the PATH environment setting (
4247 \series medium 
4248 see 
4249 \series default 
4250 section 
4251 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4252
4253 \end_inset 
4254
4255 \SpecialChar ~
4256
4257 \series medium 
4258 Install trouble-shooting for suggestions
4259 \series default 
4260 ).
4261  Make sure that the sdcc program is in the bin folder, if not perhaps something
4262  did not install correctly.
4263 \newline 
4264
4265 \newline 
4266
4267 \series medium 
4268 SDCC 
4269 \series default 
4270 is commonly installed as described in section 
4271 \begin_inset Quotes sld
4272 \end_inset 
4273
4274 Install and search paths
4275 \begin_inset Quotes srd
4276 \end_inset 
4277
4278 .
4279 \newline 
4280
4281 \newline 
4282
4283 \series medium 
4284 Make sure the compiler works on a very simple example.
4285  Type in the following test.c program using your favorite 
4286 \series default 
4287 ASCII 
4288 \series medium 
4289 editor:
4290 \layout Verse
4291
4292
4293 \family typewriter 
4294 char test;
4295 \newline 
4296
4297 \newline 
4298 void main(void) {
4299 \newline 
4300 \SpecialChar ~
4301 \SpecialChar ~
4302 \SpecialChar ~
4303 \SpecialChar ~
4304 test=0;
4305 \newline 
4306 }
4307 \layout Standard
4308
4309
4310 \series medium 
4311 Compile this using the following command: 
4312 \family sans 
4313 \series bold 
4314 "sdcc -c test.c".
4315
4316 \family default 
4317 \series default 
4318  
4319 \series medium 
4320 If all goes well, the compiler will generate a test.asm and test.rel file.
4321  Congratulations, you've just compiled your first program with SDCC.
4322  We used the -c option to tell SDCC not to link the generated code, just
4323  to keep things simple for this step.
4324 \series default 
4325
4326 \newline 
4327
4328 \newline 
4329
4330 \series medium 
4331 The next step is to try it with the linker.
4332  Type in 
4333 \family sans 
4334 \series bold 
4335 "sdcc test.c
4336 \family default 
4337 \series default 
4338 "
4339 \series medium 
4340 .
4341  If all goes well the compiler will link with the libraries and produce
4342  a test.ihx output file.
4343  If this step fails
4344 \series default 
4345  
4346 \series medium 
4347 (no test.ihx, and the linker generates warnings), then the problem is most
4348  likely that 
4349 \series default 
4350 SDCC
4351 \series medium 
4352  cannot find the 
4353 \series default 
4354 /
4355 \series medium 
4356 usr/local/share/sdcc/lib directory
4357 \series default 
4358  
4359 \series medium 
4360 (see 
4361 \series default 
4362 section 
4363 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4364
4365 \end_inset 
4366
4367 \SpecialChar ~
4368
4369 \series medium 
4370 Install trouble-shooting for suggestions).
4371 \series default 
4372
4373 \newline 
4374
4375 \newline 
4376
4377 \series medium 
4378 The final test is to ensure 
4379 \series default 
4380 SDCC
4381 \series medium 
4382  can use the 
4383 \series default 
4384 standard
4385 \series medium 
4386  header files and libraries.
4387  Edit test.c and change it to the following:
4388 \layout Verse
4389
4390
4391 \family typewriter 
4392 #include <string.h>
4393 \newline 
4394
4395 \newline 
4396 char str1[10];
4397 \newline 
4398
4399 \newline 
4400 void main(void) {
4401 \newline 
4402 \SpecialChar ~
4403 \SpecialChar ~
4404 strcpy(str1, "testing");
4405 \newline 
4406 }
4407 \layout Standard
4408
4409
4410 \series medium 
4411 Compile this by typing 
4412 \family sans 
4413 \series bold 
4414 "sdcc test.c"
4415 \family default 
4416 \series medium 
4417 .
4418  This should generate a test.ihx output file, and it should give no warnings
4419  such as not finding the string.h file.
4420  If it cannot find the string.h file, then the problem is that 
4421 \series default 
4422 SDCC
4423 \series medium 
4424  cannot find the /usr/local/share/sdcc/include directory
4425 \series default 
4426  
4427 \series medium 
4428 (see the 
4429 \series default 
4430 section 
4431 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4432
4433 \end_inset 
4434
4435 \SpecialChar ~
4436
4437 \series medium 
4438 Install trouble-shooting section for suggestions).
4439
4440 \series default 
4441  Use option 
4442 \series bold 
4443 -
4444 \begin_inset ERT
4445 status Collapsed
4446
4447 \layout Standard
4448
4449 \backslash 
4450 /
4451 \end_inset 
4452
4453 -print-search-dirs
4454 \series default 
4455
4456 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4457
4458 \end_inset 
4459
4460  to find exactly where SDCC is looking for the include and lib files.
4461 \layout Section
4462
4463 Install Trouble-shooting
4464 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4465
4466 \end_inset 
4467
4468
4469 \begin_inset LatexCommand \index{Install trouble-shooting}
4470
4471 \end_inset 
4472
4473
4474 \layout Subsection
4475
4476 If SDCC does not build correctly
4477 \layout Standard
4478
4479 A thing to try is starting from scratch by unpacking the .tgz source package
4480  again in an empty directory.
4481  Configure it like:
4482 \newline 
4483
4484 \newline 
4485
4486 \family sans 
4487 \series bold 
4488 ./configure 2>&1 | tee configure.log
4489 \family default 
4490 \series default 
4491
4492 \newline 
4493
4494 \newline 
4495 and build it like:
4496 \newline 
4497
4498 \newline 
4499
4500 \family sans 
4501 \series bold 
4502 make 2>&1 | tee make.log
4503 \family default 
4504 \series default 
4505
4506 \newline 
4507
4508 \newline 
4509 If anything goes wrong, you can review the log files to locate the problem.
4510  Or a relevant part of this can be attached to an email that could be helpful
4511  when requesting help from the mailing list.
4512 \layout Subsection
4513
4514 What the 
4515 \begin_inset Quotes sld
4516 \end_inset 
4517
4518 ./configure
4519 \begin_inset Quotes srd
4520 \end_inset 
4521
4522  does
4523 \layout Standard
4524
4525 The 
4526 \begin_inset Quotes sld
4527 \end_inset 
4528
4529 ./configure
4530 \begin_inset Quotes srd
4531 \end_inset 
4532
4533  command is a script that analyzes your system and performs some configuration
4534  to ensure the source package compiles on your system.
4535  It will take a few minutes to run, and will compile a few tests to determine
4536  what compiler features are installed.
4537 \layout Subsection
4538
4539 What the 
4540 \begin_inset Quotes sld
4541 \end_inset 
4542
4543 make
4544 \begin_inset Quotes srd
4545 \end_inset 
4546
4547  does
4548 \layout Standard
4549
4550 This runs the GNU make tool, which automatically compiles all the source
4551  packages into the final installed binary executables.
4552 \layout Subsection
4553
4554 What the 
4555 \begin_inset Quotes sld
4556 \end_inset 
4557
4558 make install
4559 \begin_inset Quotes erd
4560 \end_inset 
4561
4562  command does.
4563 \layout Standard
4564
4565 This will install the compiler, other executables libraries and include
4566  files into the appropriate directories.
4567  See sections 
4568 \begin_inset LatexCommand \ref{sub:Install-paths}
4569
4570 \end_inset 
4571
4572 ,\SpecialChar ~
4573
4574 \begin_inset LatexCommand \ref{sub:Search-Paths}
4575
4576 \end_inset 
4577
4578 \SpecialChar ~
4579 about install and search paths.
4580 \newline 
4581 On most systems you will need super-user privileges to do this.
4582 \layout Section
4583
4584 Components of SDCC
4585 \layout Standard
4586
4587 SDCC is not just a compiler, but a collection of tools by various developers.
4588  These include linkers, assemblers, simulators and other components.
4589  Here is a summary of some of the components.
4590  Note that the included simulator and assembler have separate documentation
4591  which you can find in the source package in their respective directories.
4592  As SDCC grows to include support for other processors, other packages from
4593  various developers are included and may have their own sets of documentation.
4594 \newline 
4595
4596 \newline 
4597 You might want to look at the files which are installed in <installdir>.
4598  At the time of this writing, we find the following programs for gcc-builds:
4599 \newline 
4600  
4601 \newline 
4602 In <installdir>/bin:
4603 \layout Itemize
4604
4605 sdcc - The compiler.
4606 \layout Itemize
4607
4608 sdcpp - The C preprocessor.
4609 \layout Itemize
4610
4611 asx8051 - The assembler for 8051 type processors.
4612 \layout Itemize
4613
4614 as-z80
4615 \series bold 
4616
4617 \series default 
4618 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4619 \layout Itemize
4620
4621 aslink -The linker for 8051 type processors.
4622 \layout Itemize
4623
4624 link-z80
4625 \series bold 
4626
4627 \series default 
4628 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4629 \layout Itemize
4630
4631 s51 - The ucSim 8051 simulator.
4632 \layout Itemize
4633
4634 sdcdb - The source debugger.
4635 \layout Itemize
4636
4637 packihx - A tool to pack (compress) Intel hex files.
4638 \layout Standard
4639
4640 In <installdir>/share/sdcc/include
4641 \layout Itemize
4642
4643 the include files
4644 \layout Standard
4645
4646 In <installdir>/share/sdcc/lib
4647 \layout Itemize
4648
4649 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4650  relocatables.
4651 \layout Standard
4652
4653 In <installdir>/share/sdcc/doc
4654 \layout Itemize
4655
4656 the documentation
4657 \layout Standard
4658
4659 As development for other processors proceeds, this list will expand to include
4660  executables to support processors like AVR, PIC, etc.
4661 \layout Subsection
4662
4663 sdcc - The Compiler
4664 \layout Standard
4665
4666 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4667  the assembler and linkage editor.
4668 \layout Subsection
4669
4670 sdcpp - The C-Preprocessor
4671 \layout Standard
4672
4673 The preprocessor
4674 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4675
4676 \end_inset 
4677
4678  is a modified version of the GNU preprocessor.
4679  The C preprocessor is used to pull in #include sources, process #ifdef
4680  statements, #defines and so on.
4681 \layout Subsection
4682
4683 as
4684 \emph on 
4685 xxxx
4686 \emph default 
4687 , aslink, link-
4688 \emph on 
4689 xxx
4690 \emph default 
4691  - The Assemblers and Linkage Editors
4692 \layout Standard
4693
4694 This is retargettable assembler & linkage editor, it was developed by Alan
4695  Baldwin.
4696  John Hartman created the version for 8051, and I (Sandeep) have made some
4697  enhancements and bug fixes for it to work properly with SDCC.
4698 \layout Subsection
4699
4700 s51 - The Simulator
4701 \layout Standard
4702
4703 S51
4704 \begin_inset LatexCommand \index{s51}
4705
4706 \end_inset 
4707
4708  is a freeware, opensource simulator developed by Daniel Drotos.
4709  The simulator is built as part of the build process.
4710  For more information visit Daniel's web site at: 
4711 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4712
4713 \end_inset 
4714
4715 .
4716  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4717  XA51 family.
4718 \layout Subsection
4719
4720 sdcdb - Source Level Debugger
4721 \layout Standard
4722
4723 SDCDB
4724 \begin_inset LatexCommand \index{SDCDB (debugger)}
4725
4726 \end_inset 
4727
4728  is the companion source level debugger.
4729  More about SDCDB in section 
4730 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4731
4732 \end_inset 
4733
4734 .
4735  The current version of the debugger uses Daniel's Simulator S51
4736 \begin_inset LatexCommand \index{s51}
4737
4738 \end_inset 
4739
4740 , but can be easily changed to use other simulators.
4741 \layout Chapter
4742
4743 Using SDCC
4744 \layout Section
4745
4746 Compiling
4747 \layout Subsection
4748
4749 Single Source File Projects
4750 \layout Standard
4751
4752 For single source file 8051 projects the process is very simple.
4753  Compile your programs with the following command 
4754 \family sans 
4755 \series bold 
4756 "sdcc sourcefile.c".
4757
4758 \family default 
4759 \series default 
4760  This will compile, assemble and link your source file.
4761  Output files are as follows:
4762 \layout Itemize
4763
4764 sourcefile.asm
4765 \begin_inset LatexCommand \index{<file>.asm}
4766
4767 \end_inset 
4768
4769  - Assembler source
4770 \begin_inset LatexCommand \index{Assembler source}
4771
4772 \end_inset 
4773
4774  file created by the compiler
4775 \layout Itemize
4776
4777 sourcefile.lst
4778 \begin_inset LatexCommand \index{<file>.lst}
4779
4780 \end_inset 
4781
4782  - Assembler listing
4783 \begin_inset LatexCommand \index{Assembler listing}
4784
4785 \end_inset 
4786
4787  file created by the Assembler
4788 \layout Itemize
4789
4790 sourcefile.rst
4791 \begin_inset LatexCommand \index{<file>.rst}
4792
4793 \end_inset 
4794
4795  - Assembler listing
4796 \begin_inset LatexCommand \index{Assembler listing}
4797
4798 \end_inset 
4799
4800  file updated with linkedit information, created by linkage editor
4801 \layout Itemize
4802
4803 sourcefile.sym
4804 \begin_inset LatexCommand \index{<file>.sym}
4805
4806 \end_inset 
4807
4808  - symbol listing
4809 \begin_inset LatexCommand \index{Symbol listing}
4810
4811 \end_inset 
4812
4813  for the sourcefile, created by the assembler
4814 \layout Itemize
4815
4816 sourcefile.rel
4817 \begin_inset LatexCommand \index{<file>.rel}
4818
4819 \end_inset 
4820
4821  or sourcefile.o
4822 \begin_inset LatexCommand \index{<file>.o}
4823
4824 \end_inset 
4825
4826  - Object file
4827 \begin_inset LatexCommand \index{Object file}
4828
4829 \end_inset 
4830
4831  created by the assembler, input to Linkage editor
4832 \layout Itemize
4833
4834 sourcefile.map
4835 \begin_inset LatexCommand \index{<file>.map}
4836
4837 \end_inset 
4838
4839  - The memory map
4840 \begin_inset LatexCommand \index{Memory map}
4841
4842 \end_inset 
4843
4844  for the load module, created by the Linker
4845 \layout Itemize
4846
4847 sourcefile.mem
4848 \begin_inset LatexCommand \index{<file>.mem}
4849
4850 \end_inset 
4851
4852  - A file with a summary of the memory usage
4853 \layout Itemize
4854
4855 sourcefile.ihx
4856 \begin_inset LatexCommand \index{<file>.ihx}
4857
4858 \end_inset 
4859
4860  - The load module in Intel hex format
4861 \begin_inset LatexCommand \index{Intel hex format}
4862
4863 \end_inset 
4864
4865  (you can select the Motorola S19 format
4866 \begin_inset LatexCommand \index{Motorola S19 format}
4867
4868 \end_inset 
4869
4870  with -
4871 \begin_inset ERT
4872 status Collapsed
4873
4874 \layout Standard
4875
4876 \backslash 
4877 /
4878 \end_inset 
4879
4880 -out-fmt-s19
4881 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4882
4883 \end_inset 
4884
4885 .
4886  If you need another format you might want to use 
4887 \family sans 
4888 \shape italic 
4889 objdump
4890 \family default 
4891 \shape default 
4892
4893 \begin_inset LatexCommand \index{objdump (tool)}
4894
4895 \end_inset 
4896
4897  or
4898 \family sans 
4899 \shape italic 
4900  srecord
4901 \family default 
4902 \shape default 
4903
4904 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4905
4906 \end_inset 
4907
4908 ).
4909  Both formats are documented in the documentation of srecord
4910 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4911
4912 \end_inset 
4913
4914
4915 \layout Itemize
4916
4917 sourcefile.adb
4918 \begin_inset LatexCommand \index{<file>.adb}
4919
4920 \end_inset 
4921
4922  - An intermediate file containing debug information needed to create the
4923  .cdb file (with -
4924 \begin_inset ERT
4925 status Collapsed
4926
4927 \layout Standard
4928
4929 \backslash 
4930 /
4931 \end_inset 
4932
4933 -debug
4934 \begin_inset LatexCommand \index{-\/-debug}
4935
4936 \end_inset 
4937
4938
4939 \layout Itemize
4940
4941 sourcefile.cdb
4942 \begin_inset LatexCommand \index{<file>.cdb}
4943
4944 \end_inset 
4945
4946  - An optional file (with -
4947 \begin_inset ERT
4948 status Collapsed
4949
4950 \layout Standard
4951
4952 \backslash 
4953 /
4954 \end_inset 
4955
4956 -debug) containing debug information.
4957  The format is documented in cdbfileformat.pdf
4958 \layout Itemize
4959
4960 sourcefile.
4961  - (no extension)
4962 \begin_inset LatexCommand \index{<file> (no extension)}
4963
4964 \end_inset 
4965
4966  An optional AOMF or AOMF51
4967 \begin_inset LatexCommand \index{AOMF, AOMF51}
4968
4969 \end_inset 
4970
4971  
4972 \begin_inset LatexCommand \label{OMF file}
4973
4974 \end_inset 
4975
4976 file containing debug information (generated with option -
4977 \begin_inset ERT
4978 status Collapsed
4979
4980 \layout Standard
4981
4982 \backslash 
4983 /
4984 \end_inset 
4985
4986 -debug).
4987  The (Intel)
4988 \emph on 
4989  a
4990 \emph default 
4991 bsolute 
4992 \emph on 
4993 o
4994 \emph default 
4995 bject 
4996 \emph on 
4997 m
4998 \emph default 
4999 odule 
5000 \emph on 
5001 f
5002 \emph default 
5003 ormat is commonly used by third party tools (debuggers
5004 \begin_inset LatexCommand \index{Debugger}
5005
5006 \end_inset 
5007
5008 , simulators, emulators)
5009 \layout Itemize
5010
5011 sourcefile.dump*
5012 \begin_inset LatexCommand \index{<file>.dump*}
5013
5014 \end_inset 
5015
5016  - Dump file to debug the compiler it self (generated with option -
5017 \begin_inset ERT
5018 status Collapsed
5019
5020 \layout Standard
5021
5022 \backslash 
5023 /
5024 \end_inset 
5025
5026 -dumpall) (see section 
5027 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5028
5029 \end_inset 
5030
5031 \SpecialChar ~
5032  and section 
5033 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5034
5035 \end_inset 
5036
5037 \SpecialChar ~
5038
5039 \begin_inset Quotes sld
5040 \end_inset 
5041
5042 Anatomy of the compiler
5043 \begin_inset Quotes srd
5044 \end_inset 
5045
5046 ).
5047 \layout Subsection
5048
5049 Postprocessing the Intel Hex
5050 \begin_inset LatexCommand \index{Intel hex format}
5051
5052 \end_inset 
5053
5054  file
5055 \layout Standard
5056
5057 The Intel Hex file
5058 \begin_inset LatexCommand \index{<file>.ihx}
5059
5060 \end_inset 
5061
5062  which is generated by SDCC might include lines of varying length and the
5063  addresses within the file are not guaranteed to be strictly ascending.
5064  If your toolchain or a bootloader does not like this you can use the tool
5065  
5066 \family typewriter 
5067 packihx
5068 \family default 
5069
5070 \begin_inset LatexCommand \index{packihx (tool)}
5071
5072 \end_inset 
5073
5074  which is part of the SDCC distribution: 
5075 \newline 
5076
5077 \newline 
5078
5079 \family sans 
5080 \series bold 
5081  packihx sourcefile.ihx >sourcefile.hex
5082 \family default 
5083 \series default 
5084
5085 \newline 
5086
5087 \newline 
5088 The separately available
5089 \emph on 
5090  srecord
5091 \emph default 
5092
5093 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5094
5095 \end_inset 
5096
5097  package additionally allows to set undefined locations to a predefined
5098  value, to insert checksums of various flavours (crc, add, xor) and to perform
5099  other manipulations (convert, split, crop, offset, ...).
5100  
5101 \newline 
5102
5103 \newline 
5104
5105 \family sans 
5106 \series bold 
5107 srec_cat\SpecialChar ~
5108 \SpecialChar ~
5109 sourcefile.ihx -intel\SpecialChar ~
5110 \SpecialChar ~
5111 \SpecialChar ~
5112 -fill 0xff 0x0000 0x8000\SpecialChar ~
5113 \SpecialChar ~
5114 \SpecialChar ~
5115 -o sourcefile.hex -intel
5116 \newline 
5117
5118 \newline 
5119
5120 \family default 
5121 \series default 
5122 The srecord package is available at 
5123 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5124
5125 \end_inset 
5126
5127  .
5128 \layout Subsection
5129
5130 Projects with Multiple Source Files
5131 \layout Standard
5132
5133 SDCC can compile only ONE file at a time.
5134  Let us for example assume that you have a project containing the following
5135  files:
5136 \newline 
5137
5138 \newline 
5139 foo1.c (contains some functions)
5140 \newline 
5141 foo2.c (contains some more functions)
5142 \newline 
5143 foomain.c (contains more functions and the function main)
5144 \newline 
5145
5146 \size footnotesize 
5147
5148 \newline 
5149
5150 \size default 
5151 The first two files will need to be compiled separately with the commands:
5152 \size footnotesize 
5153  
5154 \size default 
5155
5156 \newline 
5157
5158 \newline 
5159
5160 \family sans 
5161 \series bold 
5162 sdcc\SpecialChar ~
5163 -c\SpecialChar ~
5164 foo1.c
5165 \family default 
5166 \series default 
5167 \size footnotesize 
5168
5169 \newline 
5170
5171 \family sans 
5172 \series bold 
5173 \size default 
5174 sdcc\SpecialChar ~
5175 -c\SpecialChar ~
5176 foo2.c
5177 \family default 
5178 \series default 
5179
5180 \newline 
5181
5182 \newline 
5183 Then compile the source file containing the 
5184 \emph on 
5185 main()
5186 \emph default 
5187  function and link
5188 \begin_inset LatexCommand \index{Linker}
5189
5190 \end_inset 
5191
5192  the files together with the following command: 
5193 \newline 
5194
5195 \newline 
5196
5197 \family sans 
5198 \series bold 
5199 sdcc\SpecialChar ~
5200 foomain.c\SpecialChar ~
5201 foo1.rel\SpecialChar ~
5202 foo2.rel
5203 \family default 
5204 \series default 
5205
5206 \begin_inset LatexCommand \index{<file>.rel}
5207
5208 \end_inset 
5209
5210
5211 \newline 
5212
5213 \newline 
5214 Alternatively, 
5215 \emph on 
5216 foomain.c 
5217 \emph default 
5218 can be separately compiled as well: 
5219 \family sans 
5220 \series bold 
5221
5222 \newline 
5223
5224 \newline 
5225 sdcc\SpecialChar ~
5226 -c\SpecialChar ~
5227 foomain.c
5228 \newline 
5229 sdcc foomain.rel foo1.rel foo2.rel
5230 \newline 
5231
5232 \newline 
5233
5234 \family default 
5235 \series default 
5236 The file containing the 
5237 \emph on 
5238 main()
5239 \emph default 
5240  function
5241 \emph on 
5242  
5243 \emph default 
5244 \noun on 
5245 must
5246 \noun default 
5247  be the 
5248 \noun on 
5249 first
5250 \noun default 
5251  file specified in the command line, since the linkage editor processes
5252  file in the order they are presented to it.
5253  The linker is invoked from SDCC using a script file with extension .lnk
5254 \begin_inset LatexCommand \index{<file>.lnk}
5255
5256 \end_inset 
5257
5258 .
5259  You can view this file to troubleshoot linking problems such as those arising
5260  from missing libraries.
5261 \layout Subsection
5262
5263 Projects with Additional Libraries
5264 \begin_inset LatexCommand \index{Libraries}
5265
5266 \end_inset 
5267
5268
5269 \layout Standard
5270
5271 Some reusable routines may be compiled into a library, see the documentation
5272  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5273  for how to create a 
5274 \emph on 
5275 .lib
5276 \begin_inset LatexCommand \index{<file>.lib}
5277
5278 \end_inset 
5279
5280
5281 \emph default 
5282  library file.
5283  Libraries created in this manner can be included in the command line.
5284  Make sure you include the -L <library-path> option to tell the linker where
5285  to look for these files if they are not in the current directory.
5286  Here is an example, assuming you have the source file 
5287 \emph on 
5288 foomain.c
5289 \emph default 
5290  and a library
5291 \emph on 
5292  foolib.lib
5293 \emph default 
5294  in the directory 
5295 \emph on 
5296 mylib
5297 \emph default 
5298  (if that is not the same as your current project):
5299 \newline 
5300
5301 \newline 
5302
5303 \family sans 
5304 \series bold 
5305 sdcc foomain.c foolib.lib -L mylib
5306 \newline 
5307
5308 \newline 
5309
5310 \family default 
5311 \series default 
5312 Note here that
5313 \emph on 
5314  mylib
5315 \emph default 
5316  must be an absolute path name.
5317 \newline 
5318
5319 \newline 
5320 The most efficient way to use libraries is to keep separate modules in separate
5321  source files.
5322  The lib file now should name all the modules.rel
5323 \begin_inset LatexCommand \index{<file>.rel}
5324
5325 \end_inset 
5326
5327  files.
5328  For an example see the standard library file 
5329 \emph on 
5330 libsdcc.lib
5331 \emph default 
5332  in the directory <installdir>/share/lib/small.
5333 \layout Subsection
5334
5335 Using sdcclib to Create and Manage Libraries
5336 \begin_inset LatexCommand \index{sdcclib}
5337
5338 \end_inset 
5339
5340
5341 \layout Standard
5342
5343 Alternatively, instead of having a .rel file for each entry on the library
5344  file as described in the preceding section, sdcclib can be used to embed
5345  all the modules belonging to such library in the library file itself.
5346  This results in a larger library file, but it greatly reduces the number
5347  of disk files accessed by the linker.
5348   Additionally, the packed library file contains an index of all include
5349  modules and symbols that significantly speeds up the linking process.
5350  To display a list of options supported by sdcclib type:
5351 \newline 
5352
5353 \layout Standard
5354
5355
5356 \family sans 
5357 \series bold 
5358 sdcclib -?
5359 \begin_inset LatexCommand \index{sdcclib}
5360
5361 \end_inset 
5362
5363
5364 \newline 
5365
5366 \newline 
5367
5368 \family default 
5369 \series default 
5370 To create a new library file, start by compiling all the required modules.
5371  For example:
5372 \newline 
5373
5374 \layout Standard
5375
5376
5377 \family sans 
5378 \series bold 
5379 sdcc -c _divsint.c
5380 \layout Standard
5381
5382
5383 \family sans 
5384 \series bold 
5385 sdcc -c _divuint.c
5386 \layout Standard
5387
5388
5389 \family sans 
5390 \series bold 
5391 sdcc -c _modsint.c
5392 \layout Standard
5393
5394
5395 \family sans 
5396 \series bold 
5397 sdcc -c _moduint.c
5398 \layout Standard
5399
5400
5401 \family sans 
5402 \series bold 
5403 sdcc -c _mulint.c
5404 \newline 
5405
5406 \layout Standard
5407
5408 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5409  and _mulint.rel.
5410  The next step is to add the .rel files to the library file:
5411 \newline 
5412
5413 \layout Standard
5414
5415
5416 \family sans 
5417 \series bold 
5418 sdcclib libint.lib _divsint.rel
5419 \family default 
5420
5421 \begin_inset LatexCommand \index{sdcclib}
5422
5423 \end_inset 
5424
5425
5426 \layout Standard
5427
5428
5429 \family sans 
5430 \series bold 
5431 sdcclib libint.lib _divuint.rel
5432 \layout Standard
5433
5434
5435 \family sans 
5436 \series bold 
5437 sdcclib libint.lib _modsint.rel
5438 \layout Standard
5439
5440
5441 \family sans 
5442 \series bold 
5443 sdcclib libint.lib _moduint.rel
5444 \layout Standard
5445
5446
5447 \family sans 
5448 \series bold 
5449 sdcclib libint.lib _mulint.rel
5450 \series default 
5451
5452 \newline 
5453
5454 \layout Standard
5455
5456 If the file already exists in the library, it will be replaced.
5457  To see what modules and symbols are included in the library, options -s
5458  and -m are available.
5459  For example:
5460 \newline 
5461
5462 \newline 
5463
5464 \family sans 
5465 \series bold 
5466 sdcclib -s libint.lib
5467 \family default 
5468
5469 \begin_inset LatexCommand \index{sdcclib}
5470
5471 \end_inset 
5472
5473
5474 \newline 
5475
5476 \family typewriter 
5477 \series default 
5478 _divsint.rel:
5479 \layout Standard
5480
5481
5482 \family typewriter 
5483 __divsint_a_1_1
5484 \layout Standard
5485
5486
5487 \family typewriter 
5488 __divsint_PARM_2
5489 \layout Standard
5490
5491
5492 \family typewriter 
5493 __divsint
5494 \newline 
5495 _divuint.rel:
5496 \layout Standard
5497
5498
5499 \family typewriter 
5500 __divuint_a_1_1
5501 \layout Standard
5502
5503
5504 \family typewriter 
5505 __divuint_PARM_2
5506 \layout Standard
5507
5508
5509 \family typewriter 
5510 __divuint_reste_1_1
5511 \layout Standard
5512
5513
5514 \family typewriter 
5515 __divuint_count_1_1
5516 \layout Standard
5517
5518
5519 \family typewriter 
5520 __divuint
5521 \newline 
5522 _modsint.rel:
5523 \layout Standard
5524
5525
5526 \family typewriter 
5527 __modsint_a_1_1
5528 \layout Standard
5529
5530
5531 \family typewriter 
5532 __modsint_PARM_2
5533 \layout Standard
5534
5535
5536 \family typewriter 
5537 __modsint
5538 \newline 
5539 _moduint.rel:
5540 \layout Standard
5541
5542
5543 \family typewriter 
5544 __moduint_a_1_1
5545 \layout Standard
5546
5547
5548 \family typewriter 
5549 __moduint_PARM_2
5550 \layout Standard
5551
5552
5553 \family typewriter 
5554 __moduint_count_1_1
5555 \layout Standard
5556
5557
5558 \family typewriter 
5559 __moduint
5560 \newline 
5561 _mulint.rel:
5562 \layout Standard
5563
5564
5565 \family typewriter 
5566 __mulint_PARM_2
5567 \layout Standard
5568
5569
5570 \family typewriter 
5571 __mulint
5572 \family default 
5573 \series bold 
5574
5575 \newline 
5576
5577 \layout Standard
5578 \added_space_bottom bigskip 
5579 If the source files are compiled using -
5580 \begin_inset ERT
5581 status Collapsed
5582
5583 \layout Standard
5584
5585 \backslash 
5586 /
5587 \end_inset 
5588
5589 -debug
5590 \begin_inset LatexCommand \index{-\/-debug}
5591
5592 \end_inset 
5593
5594 , the corresponding debug information file .adb will be include in the library
5595  file as well.
5596  The library files created with sdcclib are plain text files, so they can
5597  be viewed with a text editor.
5598  It is not recomended to modify a library file created with sdcclib using
5599  a text editor, as there are file indexes numbers located accross the file
5600  used by the linker to quickly locate the required module to link.
5601  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5602  it can be safely deleted, since all the information required for linking
5603  is embedded in the library file itself.
5604  Library files created using sdcclib are used as described in the preceding
5605  sections.
5606 \layout Section
5607
5608 Command Line Options
5609 \begin_inset LatexCommand \index{Command Line Options}
5610
5611 \end_inset 
5612
5613
5614 \layout Subsection
5615
5616 Processor Selection Options
5617 \begin_inset LatexCommand \index{Options processor selection}
5618
5619 \end_inset 
5620
5621
5622 \begin_inset LatexCommand \index{Processor selection options}
5623
5624 \end_inset 
5625
5626
5627 \layout List
5628 \labelwidthstring 00.00.0000
5629
5630
5631 \series bold 
5632 -mmcs51
5633 \begin_inset LatexCommand \index{-mmcs51}
5634
5635 \end_inset 
5636
5637
5638 \series default 
5639  Generate code for the Intel MCS51
5640 \begin_inset LatexCommand \index{MCS51}
5641
5642 \end_inset 
5643
5644  family of processors.
5645  This is the default processor target.
5646 \layout List
5647 \labelwidthstring 00.00.0000
5648
5649
5650 \series bold 
5651 -mds390
5652 \begin_inset LatexCommand \index{-mds390}
5653
5654 \end_inset 
5655
5656
5657 \series default 
5658  Generate code for the Dallas DS80C390
5659 \begin_inset LatexCommand \index{DS80C390}
5660
5661 \end_inset 
5662
5663  processor.
5664 \layout List
5665 \labelwidthstring 00.00.0000
5666
5667
5668 \series bold 
5669 -mds400
5670 \begin_inset LatexCommand \index{-mds400}
5671
5672 \end_inset 
5673
5674
5675 \series default 
5676  Generate code for the Dallas DS80C400
5677 \begin_inset LatexCommand \index{DS80C400}
5678
5679 \end_inset 
5680
5681  processor.
5682 \layout List
5683 \labelwidthstring 00.00.0000
5684
5685
5686 \series bold 
5687 -mhc08
5688 \begin_inset LatexCommand \index{-mhc08}
5689
5690 \end_inset 
5691
5692
5693 \series default 
5694  Generate code for the Freescale/Motorola HC08
5695 \begin_inset LatexCommand \index{HC08}
5696
5697 \end_inset 
5698
5699  family of processors.
5700 \layout List
5701 \labelwidthstring 00.00.0000
5702
5703
5704 \series bold 
5705 -mz80
5706 \begin_inset LatexCommand \index{-mz80}
5707
5708 \end_inset 
5709
5710
5711 \series default 
5712  Generate code for the Zilog Z80
5713 \begin_inset LatexCommand \index{Z80}
5714
5715 \end_inset 
5716
5717  family of processors.
5718 \layout List
5719 \labelwidthstring 00.00.0000
5720
5721
5722 \series bold 
5723 -mgbz80
5724 \begin_inset LatexCommand \index{-mgbz80}
5725
5726 \end_inset 
5727
5728
5729 \series default 
5730  Generate code for the GameBoy Z80
5731 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5732
5733 \end_inset 
5734
5735  processor (Not actively maintained).
5736 \layout List
5737 \labelwidthstring 00.00.0000
5738
5739
5740 \series bold 
5741 -mavr
5742 \begin_inset LatexCommand \index{-mavr}
5743
5744 \end_inset 
5745
5746
5747 \series default 
5748  Generate code for the Atmel AVR
5749 \begin_inset LatexCommand \index{AVR}
5750
5751 \end_inset 
5752
5753  processor (In development, not complete).
5754  AVR users should probably have a look at winavr 
5755 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5756
5757 \end_inset 
5758
5759  or 
5760 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5761
5762 \end_inset 
5763
5764 .
5765 \layout Comment
5766
5767 I think it is fair to direct users there for now.
5768  Open source is also about avoiding unnecessary work .
5769  But I didn't find the 'official' link.
5770 \layout List
5771 \labelwidthstring 00.00.0000
5772
5773
5774 \series bold 
5775 -mpic14
5776 \begin_inset LatexCommand \index{-mpic14}
5777
5778 \end_inset 
5779
5780
5781 \series default 
5782  Generate code for the Microchip PIC 14
5783 \begin_inset LatexCommand \index{PIC14}
5784
5785 \end_inset 
5786
5787 -bit processors (p16f84 and variants.
5788  In development, not complete).
5789 \layout Comment
5790
5791 p16f627 p16f628 p16f84 p16f873 p16f877?
5792 \layout List
5793 \labelwidthstring 00.00.0000
5794
5795
5796 \series bold 
5797 -mpic16
5798 \begin_inset LatexCommand \index{-mpic16}
5799
5800 \end_inset 
5801
5802
5803 \series default 
5804  Generate code for the Microchip PIC 16
5805 \begin_inset LatexCommand \index{PIC16}
5806
5807 \end_inset 
5808
5809 -bit processors (p18f452 and variants.
5810  In development, not complete).
5811 \layout List
5812 \labelwidthstring 00.00.0000
5813
5814
5815 \series bold 
5816 -mtlcs900h
5817 \series default 
5818  Generate code for the Toshiba TLCS-900H
5819 \begin_inset LatexCommand \index{TLCS-900H}
5820
5821 \end_inset 
5822
5823  processor (Not maintained, not complete).
5824 \layout List
5825 \added_space_bottom bigskip \labelwidthstring 00.00.0000
5826
5827
5828 \series bold 
5829 -mxa51
5830 \begin_inset LatexCommand \index{-mxa51}
5831
5832 \end_inset 
5833
5834
5835 \series default 
5836  Generate code for the Phillips XA51
5837 \begin_inset LatexCommand \index{XA51}
5838
5839 \end_inset 
5840
5841  processor (Not maintained, not complete).
5842 \layout Subsection
5843
5844 Preprocessor Options
5845 \begin_inset LatexCommand \index{Options preprocessor}
5846
5847 \end_inset 
5848
5849
5850 \begin_inset LatexCommand \index{Preprocessor options}
5851
5852 \end_inset 
5853
5854
5855 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5856
5857 \end_inset 
5858
5859
5860 \layout List
5861 \labelwidthstring 00.00.0000
5862
5863
5864 \series bold 
5865 -I<path>
5866 \begin_inset LatexCommand \index{-I<path>}
5867
5868 \end_inset 
5869
5870
5871 \series default 
5872  The additional location where the pre processor will look for <..h> or 
5873 \begin_inset Quotes eld
5874 \end_inset 
5875
5876 ..h
5877 \begin_inset Quotes erd
5878 \end_inset 
5879
5880  files.
5881 \layout List
5882 \labelwidthstring 00.00.0000
5883
5884
5885 \series bold 
5886 -D<macro[=value]>
5887 \begin_inset LatexCommand \index{-D<macro[=value]>}
5888
5889 \end_inset 
5890
5891
5892 \series default 
5893  Command line definition of macros.
5894  Passed to the preprocessor.
5895 \layout List
5896 \labelwidthstring 00.00.0000
5897
5898
5899 \series bold 
5900 -M
5901 \begin_inset LatexCommand \index{-M}
5902
5903 \end_inset 
5904
5905
5906 \series default 
5907  Tell the preprocessor to output a rule suitable for make describing the
5908  dependencies of each object file.
5909  For each source file, the preprocessor outputs one make-rule whose target
5910  is the object file name for that source file and whose dependencies are
5911  all the files `#include'd in it.
5912  This rule may be a single line or may be continued with `
5913 \backslash 
5914 '-newline if it is long.
5915  The list of rules is printed on standard output instead of the preprocessed
5916  C program.
5917  `-M' implies `-E
5918 \begin_inset LatexCommand \index{-E}
5919
5920 \end_inset 
5921
5922 '.
5923 \layout List
5924 \labelwidthstring 00.00.0000
5925
5926
5927 \series bold 
5928 -C
5929 \begin_inset LatexCommand \index{-C}
5930
5931 \end_inset 
5932
5933
5934 \series default 
5935  Tell the preprocessor not to discard comments.
5936  Used with the `-E' option.
5937 \layout List
5938 \labelwidthstring 00.00.0000
5939
5940
5941 \series bold 
5942 -MM
5943 \begin_inset LatexCommand \index{-MM}
5944
5945 \end_inset 
5946
5947
5948 \size large 
5949 \bar under 
5950  
5951 \series default 
5952 \size default 
5953 \bar default 
5954 Like `-M' but the output mentions only the user header files included with
5955  `#include 
5956 \begin_inset Quotes eld
5957 \end_inset 
5958
5959 file"'.
5960  System header files included with `#include <file>' are omitted.
5961 \layout List
5962 \labelwidthstring 00.00.0000
5963
5964
5965 \series bold 
5966 -Aquestion(answer)
5967 \begin_inset LatexCommand \index{-Aquestion(answer)}
5968
5969 \end_inset 
5970
5971
5972 \series default 
5973  Assert the answer answer for question, in case it is tested with a preprocessor
5974  conditional such as `#if #question(answer)'.
5975  `-A-' disables the standard assertions that normally describe the target
5976  machine.
5977 \layout List
5978 \labelwidthstring 00.00.0000
5979
5980
5981 \series bold 
5982 -Umacro
5983 \begin_inset LatexCommand \index{-Umacro}
5984
5985 \end_inset 
5986
5987
5988 \series default 
5989  Undefine macro macro.
5990  `-U' options are evaluated after all `-D' options, but before any `-include'
5991  and `-imacros' options.
5992 \layout List
5993 \labelwidthstring 00.00.0000
5994
5995
5996 \series bold 
5997 -dM
5998 \begin_inset LatexCommand \index{-dM}
5999
6000 \end_inset 
6001
6002
6003 \series default 
6004  Tell the preprocessor to output only a list of the macro definitions that
6005  are in effect at the end of preprocessing.
6006  Used with the `-E' option.
6007 \layout List
6008 \labelwidthstring 00.00.0000
6009
6010
6011 \series bold 
6012 -dD
6013 \begin_inset LatexCommand \index{-dD}
6014
6015 \end_inset 
6016
6017
6018 \series default 
6019  Tell the preprocessor to pass all macro definitions into the output, in
6020  their proper sequence in the rest of the output.
6021 \layout List
6022 \labelwidthstring 00.00.0000
6023
6024
6025 \series bold 
6026 -dN
6027 \begin_inset LatexCommand \index{-dN}
6028
6029 \end_inset 
6030
6031
6032 \size large 
6033 \bar under 
6034  
6035 \series default 
6036 \size default 
6037 \bar default 
6038 Like `-dD' except that the macro arguments and contents are omitted.
6039  Only `#define name' is included in the output.
6040 \layout List
6041 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6042
6043
6044 \series bold 
6045 -Wp\SpecialChar ~
6046 preprocessorOption[,preprocessorOption]
6047 \series default 
6048
6049 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6050
6051 \end_inset 
6052
6053 ...
6054  Pass the preprocessorOption to the preprocessor 
6055 \family typewriter 
6056 sdcpp
6057 \family default 
6058
6059 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6060
6061 \end_inset 
6062
6063 .
6064  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
6065  Collection (gcc), if you need more dedicated options please refer to the
6066  documentation at 
6067 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6068
6069 \end_inset 
6070
6071 .
6072 \layout Subsection
6073
6074 Linker Options
6075 \begin_inset LatexCommand \index{Options linker}
6076
6077 \end_inset 
6078
6079
6080 \begin_inset LatexCommand \index{Linker options}
6081
6082 \end_inset 
6083
6084
6085 \layout List
6086 \labelwidthstring 00.00.0000
6087
6088
6089 \series bold 
6090 -L\SpecialChar ~
6091 -
6092 \series default 
6093
6094 \begin_inset ERT
6095 status Collapsed
6096
6097 \layout Standard
6098
6099 \backslash 
6100 /
6101 \end_inset 
6102
6103
6104 \series bold 
6105 -lib-path
6106 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6107
6108 \end_inset 
6109
6110
6111 \begin_inset LatexCommand \index{-L -\/-lib-path}
6112
6113 \end_inset 
6114
6115
6116 \series default 
6117 \SpecialChar ~
6118 <absolute path to additional libraries> This option is passed to the linkage
6119  editor's additional libraries
6120 \begin_inset LatexCommand \index{Libraries}
6121
6122 \end_inset 
6123
6124  search path.
6125  The path name must be absolute.
6126  Additional library files may be specified in the command line.
6127  See section Compiling programs for more details.
6128 \layout List
6129 \labelwidthstring 00.00.0000
6130
6131
6132 \series bold 
6133 -
6134 \begin_inset ERT
6135 status Collapsed
6136
6137 \layout Standard
6138
6139 \backslash 
6140 /
6141 \end_inset 
6142
6143 -xram-loc
6144 \series default 
6145
6146 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6147
6148 \end_inset 
6149
6150 \SpecialChar ~
6151 <Value> The start location of the external ram
6152 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6153
6154 \end_inset 
6155
6156 , default value is 0.
6157  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6158 \begin_inset ERT
6159 status Collapsed
6160
6161 \layout Standard
6162
6163 \backslash 
6164 /
6165 \end_inset 
6166
6167 -xram-loc 0x8000 or -
6168 \begin_inset ERT
6169 status Collapsed
6170
6171 \layout Standard
6172
6173 \backslash 
6174 /
6175 \end_inset 
6176
6177 -xram-loc 32768.
6178 \layout List
6179 \labelwidthstring 00.00.0000
6180
6181
6182 \series bold 
6183 -
6184 \begin_inset ERT
6185 status Collapsed
6186
6187 \layout Standard
6188
6189 \backslash 
6190 /
6191 \end_inset 
6192
6193 -code-loc
6194 \series default 
6195
6196 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6197
6198 \end_inset 
6199
6200 \SpecialChar ~
6201 <Value> The start location of the code
6202 \begin_inset LatexCommand \index{code}
6203
6204 \end_inset 
6205
6206  segment, default value 0.
6207  Note when this option is used the interrupt vector table is also relocated
6208  to the given address.
6209  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6210 \begin_inset ERT
6211 status Collapsed
6212
6213 \layout Standard
6214
6215 \backslash 
6216 /
6217 \end_inset 
6218
6219 -code-loc 0x8000 or -
6220 \begin_inset ERT
6221 status Collapsed
6222
6223 \layout Standard
6224
6225 \backslash 
6226 /
6227 \end_inset 
6228
6229 -code-loc 32768.
6230 \layout List
6231 \labelwidthstring 00.00.0000
6232
6233
6234 \series bold 
6235 -
6236 \begin_inset ERT
6237 status Collapsed
6238
6239 \layout Standard
6240
6241 \backslash 
6242 /
6243 \end_inset 
6244
6245 -stack-loc
6246 \series default 
6247
6248 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6249
6250 \end_inset 
6251
6252 \SpecialChar ~
6253 <Value> By default the stack
6254 \begin_inset LatexCommand \index{stack}
6255
6256 \end_inset 
6257
6258  is placed after the data segment.
6259  Using this option the stack can be placed anywhere in the internal memory
6260  space of the 8051.
6261  The value entered can be in Hexadecimal or Decimal format, e.g.
6262  -
6263 \begin_inset ERT
6264 status Collapsed
6265
6266 \layout Standard
6267
6268 \backslash 
6269 /
6270 \end_inset 
6271
6272 -stack-loc 0x20 or -
6273 \begin_inset ERT
6274 status Collapsed
6275
6276 \layout Standard
6277
6278 \backslash 
6279 /
6280 \end_inset 
6281
6282 -stack-loc 32.
6283  Since the sp register is incremented before a push or call, the initial
6284  sp will be set to one byte prior the provided value.
6285  The provided value should not overlap any other memory areas such as used
6286  register banks or the data segment and with enough space for the current
6287  application.
6288  The 
6289 \series bold 
6290 -
6291 \begin_inset ERT
6292 status Collapsed
6293
6294 \layout Standard
6295
6296 \backslash 
6297 /
6298 \end_inset 
6299
6300 -pack-iram
6301 \series default 
6302 \SpecialChar ~
6303
6304 \begin_inset LatexCommand \index{-\/-pack-iram}
6305
6306 \end_inset 
6307
6308  option (which is now a default setting) will override this setting, so
6309  you should also specify the 
6310 \series bold 
6311 -
6312 \begin_inset ERT
6313 status Collapsed
6314
6315 \layout Standard
6316
6317 \backslash 
6318 /
6319 \end_inset 
6320
6321 -no-pack-iram
6322 \series default 
6323 \SpecialChar ~
6324
6325 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6326
6327 \end_inset 
6328
6329  option if you need to manually place the stack.
6330 \layout List
6331 \labelwidthstring 00.00.0000
6332
6333
6334 \series bold 
6335 -
6336 \begin_inset ERT
6337 status Collapsed
6338
6339 \layout Standard
6340
6341 \backslash 
6342 /
6343 \end_inset 
6344
6345 -xstack-loc
6346 \series default 
6347
6348 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6349
6350 \end_inset 
6351
6352 \SpecialChar ~
6353 <Value> By default the external stack
6354 \begin_inset LatexCommand \index{xstack}
6355
6356 \end_inset 
6357
6358  is placed after the pdata
6359 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6360
6361 \end_inset 
6362
6363  segment.
6364  Using this option the xstack can be placed anywhere in the external memory
6365  space of the 8051.
6366  The value entered can be in Hexadecimal or Decimal format, e.g.
6367  -
6368 \begin_inset ERT
6369 status Collapsed
6370
6371 \layout Standard
6372
6373 \backslash 
6374 /
6375 \end_inset 
6376
6377 -xstack-loc 0x8000 or -
6378 \begin_inset ERT
6379 status Collapsed
6380
6381 \layout Standard
6382
6383 \backslash 
6384 /
6385 \end_inset 
6386
6387 -stack-loc 32768.
6388  The provided value should not overlap any other memory areas such as the
6389  pdata or xdata segment and with enough space for the current application.
6390 \layout List
6391 \labelwidthstring 00.00.0000
6392
6393
6394 \series bold 
6395 -
6396 \begin_inset ERT
6397 status Collapsed
6398
6399 \layout Standard
6400
6401 \backslash 
6402 /
6403 \end_inset 
6404
6405 -data-loc
6406 \series default 
6407
6408 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6409
6410 \end_inset 
6411
6412 \SpecialChar ~
6413 <Value> The start location of the internal ram data
6414 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6415
6416 \end_inset 
6417
6418  segment.
6419  The value entered can be in Hexadecimal or Decimal format, eg.
6420  -
6421 \begin_inset ERT
6422 status Collapsed
6423
6424 \layout Standard
6425
6426 \backslash 
6427 /
6428 \end_inset 
6429
6430 -data-loc 0x20 or -
6431 \begin_inset ERT
6432 status Collapsed
6433
6434 \layout Standard
6435
6436 \backslash 
6437 /
6438 \end_inset 
6439
6440 -data-loc 32.
6441  (By default, the start location of the internal ram data segment  is set
6442  as low as possible in memory, taking into account the used register banks
6443  and the bit segment at address 0x20.
6444  For example if register banks 0 and 1 are used without bit variables, the
6445  data segment will be set, if -
6446 \begin_inset ERT
6447 status Collapsed
6448
6449 \layout Standard
6450
6451 \backslash 
6452 /
6453 \end_inset 
6454
6455 -data-loc is not used, to location 0x10.)
6456 \layout List
6457 \labelwidthstring 00.00.0000
6458
6459
6460 \series bold 
6461 -
6462 \begin_inset ERT
6463 status Collapsed
6464
6465 \layout Standard
6466
6467 \backslash 
6468 /
6469 \end_inset 
6470
6471 -idata-loc
6472 \series default 
6473
6474 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6475
6476 \end_inset 
6477
6478 \SpecialChar ~
6479 <Value> The start location of the indirectly addressable internal ram
6480 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6481
6482 \end_inset 
6483
6484  of the 8051, default value is 0x80.
6485  The value entered can be in Hexadecimal or Decimal format, eg.
6486  -
6487 \begin_inset ERT
6488 status Collapsed
6489
6490 \layout Standard
6491
6492 \backslash 
6493 /
6494 \end_inset 
6495
6496 -idata-loc 0x88 or -
6497 \begin_inset ERT
6498 status Collapsed
6499
6500 \layout Standard
6501
6502 \backslash 
6503 /
6504 \end_inset 
6505
6506 -idata-loc 136.
6507 \layout List
6508 \labelwidthstring 00.00.0000
6509
6510
6511 \series bold 
6512 -
6513 \begin_inset ERT
6514 status Collapsed
6515
6516 \layout Standard
6517
6518 \backslash 
6519 /
6520 \end_inset 
6521
6522 -bit-loc
6523 \series default 
6524 \SpecialChar ~
6525 <Value> The start location of the bit
6526 \begin_inset LatexCommand \index{bit}
6527
6528 \end_inset 
6529
6530  addressable internal ram of the 8051.
6531  This is 
6532 \emph on 
6533 not
6534 \emph default 
6535  implemented yet.
6536  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6537 -bBSEG=<Value>.
6538 \layout List
6539 \labelwidthstring 00.00.0000
6540
6541
6542 \series bold 
6543 -
6544 \begin_inset ERT
6545 status Collapsed
6546
6547 \layout Standard
6548
6549 \backslash 
6550 /
6551 \end_inset 
6552
6553 -out-fmt-ihx
6554 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6555
6556 \end_inset 
6557
6558
6559 \bar under 
6560  
6561 \series default 
6562 \bar default 
6563 The linker output (final object code) is in Intel Hex format.
6564 \begin_inset LatexCommand \index{Intel hex format}
6565
6566 \end_inset 
6567
6568  This is the default option.
6569  The format itself is documented in the documentation of srecord
6570 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6571
6572 \end_inset 
6573
6574 .
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 -out-fmt-s19
6591 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6592
6593 \end_inset 
6594
6595
6596 \bar under 
6597  
6598 \series default 
6599 \bar default 
6600 The linker output (final object code) is in Motorola S19 format
6601 \begin_inset LatexCommand \index{Motorola S19 format}
6602
6603 \end_inset 
6604
6605 .
6606  The format itself is documented in the documentation of srecord.
6607 \layout List
6608 \labelwidthstring 00.00.0000
6609
6610
6611 \series bold 
6612 -
6613 \begin_inset ERT
6614 status Collapsed
6615
6616 \layout Standard
6617
6618 \backslash 
6619 /
6620 \end_inset 
6621
6622 -out-fmt-elf
6623 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6624
6625 \end_inset 
6626
6627
6628 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6629
6630 \end_inset 
6631
6632
6633 \bar under 
6634  
6635 \series default 
6636 \bar default 
6637 The linker output (final object code) is in ELF format
6638 \begin_inset LatexCommand \index{ELF format}
6639
6640 \end_inset 
6641
6642 .
6643  (Currently only supported for the HC08
6644 \begin_inset LatexCommand \index{HC08}
6645
6646 \end_inset 
6647
6648  processors)
6649 \layout List
6650 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6651
6652
6653 \series bold 
6654 -Wl\SpecialChar ~
6655 linkOption[,linkOption]
6656 \series default 
6657
6658 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6659
6660 \end_inset 
6661
6662 ...
6663  Pass the linkOption to the linker.
6664  If a bootloader is used an option like 
6665 \begin_inset Quotes sld
6666 \end_inset 
6667
6668 -Wl\SpecialChar ~
6669 -bCSEG=0x1000
6670 \begin_inset Quotes srd
6671 \end_inset 
6672
6673  would be typical to set the start of the code segment.
6674  See also #pragma constseg and #pragma codeseg in section 
6675 \begin_inset LatexCommand \ref{sec:Pragmas}
6676
6677 \end_inset 
6678
6679  .
6680  File sdcc/as/doc/asxhtm.html has more on linker options.
6681 \layout Subsection
6682
6683 MCS51 Options
6684 \begin_inset LatexCommand \index{Options MCS51}
6685
6686 \end_inset 
6687
6688
6689 \begin_inset LatexCommand \index{MCS51 options}
6690
6691 \end_inset 
6692
6693
6694 \layout List
6695 \labelwidthstring 00.00.0000
6696
6697
6698 \series bold 
6699 -
6700 \begin_inset ERT
6701 status Collapsed
6702
6703 \layout Standard
6704
6705 \backslash 
6706 /
6707 \end_inset 
6708
6709 -model-small
6710 \begin_inset LatexCommand \index{-\/-model-small}
6711
6712 \end_inset 
6713
6714
6715 \series default 
6716 \size large 
6717 \emph on 
6718  
6719 \size default 
6720 \emph default 
6721 Generate code for Small Model programs, see section Memory Models for more
6722  details.
6723  This is the default model.
6724 \layout List
6725 \labelwidthstring 00.00.0000
6726
6727
6728 \series bold 
6729 -
6730 \begin_inset ERT
6731 status Collapsed
6732
6733 \layout Standard
6734
6735 \backslash 
6736 /
6737 \end_inset 
6738
6739 -model-medium
6740 \begin_inset LatexCommand \index{-\/-model-medium}
6741
6742 \end_inset 
6743
6744
6745 \series default 
6746  Generate code for Medium model programs, see section Memory Models for
6747  more details.
6748  If this option is used all source files in the project have to be compiled
6749  with this option.
6750  It must also be used when invoking the linker.
6751 \layout List
6752 \labelwidthstring 00.00.0000
6753
6754
6755 \series bold 
6756 -
6757 \begin_inset ERT
6758 status Collapsed
6759
6760 \layout Standard
6761
6762 \backslash 
6763 /
6764 \end_inset 
6765
6766 -model-large
6767 \begin_inset LatexCommand \index{-\/-model-large}
6768
6769 \end_inset 
6770
6771
6772 \series default 
6773  Generate code for Large model programs, see section Memory Models for more
6774  details.
6775  If this option is used all source files in the project have to be compiled
6776  with this option.
6777  It must also be used when invoking the linker.
6778 \layout List
6779 \labelwidthstring 00.00.0000
6780
6781
6782 \series bold 
6783 -
6784 \begin_inset ERT
6785 status Collapsed
6786
6787 \layout Standard
6788
6789 \backslash 
6790 /
6791 \end_inset 
6792
6793 -xstack
6794 \begin_inset LatexCommand \index{-\/-xstack}
6795
6796 \end_inset 
6797
6798
6799 \series default 
6800  Uses a pseudo stack in the pdata
6801 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6802
6803 \end_inset 
6804
6805  area (usually the first 256 bytes in the external ram) for allocating variables
6806  and passing parameters.
6807  See section 
6808 \begin_inset LatexCommand \ref{sub:External-Stack}
6809
6810 \end_inset 
6811
6812 \SpecialChar ~
6813  External Stack for more details.
6814 \layout List
6815 \labelwidthstring 00.00.0000
6816
6817
6818 \series bold 
6819 -
6820 \begin_inset ERT
6821 status Collapsed
6822
6823 \layout Standard
6824
6825 \backslash 
6826 /
6827 \end_inset 
6828
6829 -iram-size
6830 \series default 
6831 \SpecialChar ~
6832 <Value>
6833 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6834
6835 \end_inset 
6836
6837  Causes the linker to check if the internal ram usage is within limits of
6838  the given value.
6839 \layout List
6840 \labelwidthstring 00.00.0000
6841
6842
6843 \series bold 
6844 -
6845 \begin_inset ERT
6846 status Collapsed
6847
6848 \layout Standard
6849
6850 \backslash 
6851 /
6852 \end_inset 
6853
6854 -xram-size
6855 \series default 
6856 \SpecialChar ~
6857 <Value>
6858 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6859
6860 \end_inset 
6861
6862  Causes the linker to check if the external ram usage is within limits of
6863  the given value.
6864 \layout List
6865 \labelwidthstring 00.00.0000
6866
6867
6868 \series bold 
6869 -
6870 \begin_inset ERT
6871 status Collapsed
6872
6873 \layout Standard
6874
6875 \backslash 
6876 /
6877 \end_inset 
6878
6879 -code-size
6880 \series default 
6881 \SpecialChar ~
6882 <Value>
6883 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6884
6885 \end_inset 
6886
6887  Causes the linker to check if the code memory usage is within limits of
6888  the given value.
6889 \layout List
6890 \labelwidthstring 00.00.0000
6891
6892
6893 \series bold 
6894 -
6895 \begin_inset ERT
6896 status Collapsed
6897
6898 \layout Standard
6899
6900 \backslash 
6901 /
6902 \end_inset 
6903
6904 -stack-size
6905 \series default 
6906 \SpecialChar ~
6907 <Value>
6908 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6909
6910 \end_inset 
6911
6912  Causes the linker to check if there is at minimum <Value> bytes for stack.
6913 \layout List
6914 \labelwidthstring 00.00.0000
6915
6916
6917 \series bold 
6918 -
6919 \begin_inset ERT
6920 status Collapsed
6921
6922 \layout Standard
6923
6924 \backslash 
6925 /
6926 \end_inset 
6927
6928 -pack-iram
6929 \series default 
6930 \SpecialChar ~
6931
6932 \begin_inset LatexCommand \index{-\/-pack-iram}
6933
6934 \end_inset 
6935
6936  Causes the linker to use unused register banks for data variables and pack
6937  data, idata and stack together.
6938  This is the default now.
6939 \layout List
6940 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6941
6942
6943 \series bold 
6944 -
6945 \begin_inset ERT
6946 status Collapsed
6947
6948 \layout Standard
6949
6950 \backslash 
6951 /
6952 \end_inset 
6953
6954 -no-pack-iram
6955 \series default 
6956 \SpecialChar ~
6957
6958 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6959
6960 \end_inset 
6961
6962  Causes the linker to use old style for allocating memory areas.
6963 \layout Subsection
6964
6965 DS390 / DS400 Options
6966 \begin_inset LatexCommand \index{Options DS390}
6967
6968 \end_inset 
6969
6970
6971 \begin_inset LatexCommand \index{DS390}
6972
6973 \end_inset 
6974
6975
6976 \layout List
6977 \labelwidthstring 00.00.0000
6978
6979
6980 \series bold 
6981 -
6982 \begin_inset ERT
6983 status Collapsed
6984
6985 \layout Standard
6986
6987 \backslash 
6988 /
6989 \end_inset 
6990
6991 -model-flat24
6992 \series default 
6993
6994 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
6995
6996 \end_inset 
6997
6998
6999 \size large 
7000 \emph on 
7001  
7002 \size default 
7003 \emph default 
7004 Generate 24-bit flat mode code.
7005  This is the one and only that the ds390 code generator supports right now
7006  and is default when using 
7007 \emph on 
7008 -mds390
7009 \emph default 
7010 .
7011  See section Memory Models for more details.
7012 \layout List
7013 \labelwidthstring 00.00.0000
7014
7015
7016 \series bold 
7017 -
7018 \begin_inset ERT
7019 status Collapsed
7020
7021 \layout Standard
7022
7023 \backslash 
7024 /
7025 \end_inset 
7026
7027 -protect-sp-update
7028 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7029
7030 \end_inset 
7031
7032
7033 \series default 
7034  disable interrupts during ESP:SP updates.
7035 \layout List
7036 \labelwidthstring 00.00.0000
7037
7038
7039 \series bold 
7040 -
7041 \begin_inset ERT
7042 status Collapsed
7043
7044 \layout Standard
7045
7046 \backslash 
7047 /
7048 \end_inset 
7049
7050 -stack-10bit
7051 \series default 
7052
7053 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7054
7055 \end_inset 
7056
7057  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7058  This is the one and only that the ds390 code generator supports right now
7059  and is default when using 
7060 \emph on 
7061 -mds390
7062 \emph default 
7063 .
7064  In this mode, the stack is located in the lower 1K of the internal RAM,
7065  which is mapped to 0x400000.
7066  Note that the support is incomplete, since it still uses a single byte
7067  as the stack pointer.
7068  This means that only the lower 256 bytes of the potential 1K stack space
7069  will actually be used.
7070  However, this does allow you to reclaim the precious 256 bytes of low RAM
7071  for use for the DATA and IDATA segments.
7072  The compiler will not generate any code to put the processor into 10 bit
7073  stack mode.
7074  It is important to ensure that the processor is in this mode before calling
7075  any re-entrant functions compiled with this option.
7076  In principle, this should work with the 
7077 \emph on 
7078 -
7079 \begin_inset ERT
7080 status Collapsed
7081
7082 \layout Standard
7083
7084 \backslash 
7085 /
7086 \end_inset 
7087
7088 -stack-auto
7089 \begin_inset LatexCommand \index{-\/-stack-auto}
7090
7091 \end_inset 
7092
7093
7094 \emph default 
7095  option, but that has not been tested.
7096  It is incompatible with the 
7097 \emph on 
7098 -
7099 \begin_inset ERT
7100 status Collapsed
7101
7102 \layout Standard
7103
7104 \backslash 
7105 /
7106 \end_inset 
7107
7108 -xstack
7109 \begin_inset LatexCommand \index{-\/-xstack}
7110
7111 \end_inset 
7112
7113
7114 \emph default 
7115  option.
7116  It also only makes sense if the processor is in 24 bit contiguous addressing
7117  mode (see the 
7118 \emph on 
7119 -
7120 \begin_inset ERT
7121 status Collapsed
7122
7123 \layout Standard
7124
7125 \backslash 
7126 /
7127 \end_inset 
7128
7129 -model-flat24 option
7130 \emph default 
7131 ).
7132 \layout List
7133 \labelwidthstring 00.00.0000
7134
7135
7136 \series bold 
7137 -
7138 \begin_inset ERT
7139 status Collapsed
7140
7141 \layout Standard
7142
7143 \backslash 
7144 /
7145 \end_inset 
7146
7147 -stack-probe
7148 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7149
7150 \end_inset 
7151
7152
7153 \series default 
7154  insert call to function __stack_probe at each function prologue.
7155 \layout List
7156 \labelwidthstring 00.00.0000
7157
7158
7159 \series bold 
7160 -
7161 \begin_inset ERT
7162 status Collapsed
7163
7164 \layout Standard
7165
7166 \backslash 
7167 /
7168 \end_inset 
7169
7170 -tini-libid
7171 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7172
7173 \end_inset 
7174
7175
7176 \series default 
7177  <nnnn> LibraryID used in -mTININative.
7178  
7179 \layout List
7180 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7181
7182
7183 \series bold 
7184 -
7185 \begin_inset ERT
7186 status Collapsed
7187
7188 \layout Standard
7189
7190 \backslash 
7191 /
7192 \end_inset 
7193
7194 -use-accelerator
7195 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7196
7197 \end_inset 
7198
7199
7200 \series default 
7201  generate code for DS390 Arithmetic Accelerator.
7202  
7203 \layout Subsection
7204
7205 Z80 Options
7206 \begin_inset LatexCommand \index{Options Z80}
7207
7208 \end_inset 
7209
7210
7211 \begin_inset LatexCommand \index{Z80}
7212
7213 \end_inset 
7214
7215
7216 \layout List
7217 \labelwidthstring 00.00.0000
7218
7219
7220 \series bold 
7221 -
7222 \begin_inset ERT
7223 status Collapsed
7224
7225 \layout Standard
7226
7227 \backslash 
7228 /
7229 \end_inset 
7230
7231 -callee-saves-bc
7232 \series default 
7233
7234 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7235
7236 \end_inset 
7237
7238
7239 \size large 
7240 \emph on 
7241  
7242 \size default 
7243 \emph default 
7244 Force a called function to always save BC.
7245 \layout List
7246 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7247
7248
7249 \series bold 
7250 -
7251 \begin_inset ERT
7252 status Collapsed
7253
7254 \layout Standard
7255
7256 \backslash 
7257 /
7258 \end_inset 
7259
7260 -no-std-crt0
7261 \series default 
7262
7263 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7264
7265 \end_inset 
7266
7267  When linking, skip the standard crt0.o object file.
7268  You must provide your own crt0.o for your system when linking.
7269  
7270 \layout Subsection
7271
7272 Optimization Options
7273 \begin_inset LatexCommand \index{Options optimization}
7274
7275 \end_inset 
7276
7277
7278 \begin_inset LatexCommand \index{Optimization options}
7279
7280 \end_inset 
7281
7282
7283 \layout List
7284 \labelwidthstring 00.00.0000
7285
7286
7287 \series bold 
7288 -
7289 \begin_inset ERT
7290 status Collapsed
7291
7292 \layout Standard
7293
7294 \backslash 
7295 /
7296 \end_inset 
7297
7298 -nogcse
7299 \begin_inset LatexCommand \index{-\/-nogcse}
7300
7301 \end_inset 
7302
7303
7304 \series default 
7305  Will not do global subexpression elimination, this option may be used when
7306  the compiler creates undesirably large stack/data spaces to store compiler
7307  temporaries (
7308 \emph on 
7309 s
7310 \emph default 
7311 pill 
7312 \emph on 
7313 loc
7314 \emph default 
7315 ations, sloc
7316 \begin_inset LatexCommand \index{sloc (spill location)}
7317
7318 \end_inset 
7319
7320 ).
7321  A warning message will be generated when this happens and the compiler
7322  will indicate the number of extra bytes it allocated.
7323  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7324 nogcse
7325 \begin_inset LatexCommand \index{\#pragma nogcse}
7326
7327 \end_inset 
7328
7329  can be used to turn off global subexpression elimination
7330 \begin_inset LatexCommand \index{Subexpression elimination}
7331
7332 \end_inset 
7333
7334  for a given function only.
7335 \layout List
7336 \labelwidthstring 00.00.0000
7337
7338
7339 \series bold 
7340 -
7341 \begin_inset ERT
7342 status Collapsed
7343
7344 \layout Standard
7345
7346 \backslash 
7347 /
7348 \end_inset 
7349
7350 -noinvariant
7351 \begin_inset LatexCommand \index{-\/-noinvariant}
7352
7353 \end_inset 
7354
7355
7356 \series default 
7357  Will not do loop invariant optimizations, this may be turned off for reasons
7358  explained for the previous option.
7359  For more details of loop optimizations performed see Loop Invariants in
7360  section 
7361 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7362
7363 \end_inset 
7364
7365 .
7366  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7367 noinvariant
7368 \begin_inset LatexCommand \index{\#pragma noinvariant}
7369
7370 \end_inset 
7371
7372  can be used to turn off invariant optimizations for a given function only.
7373 \layout List
7374 \labelwidthstring 00.00.0000
7375
7376
7377 \series bold 
7378 -
7379 \begin_inset ERT
7380 status Collapsed
7381
7382 \layout Standard
7383
7384 \backslash 
7385 /
7386 \end_inset 
7387
7388 -noinduction
7389 \begin_inset LatexCommand \index{-\/-noinduction}
7390
7391 \end_inset 
7392
7393
7394 \series default 
7395  Will not do loop induction optimizations, see section strength reduction
7396  for more details.
7397  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7398 noinduction
7399 \begin_inset LatexCommand \index{\#pragma noinduction}
7400
7401 \end_inset 
7402
7403  can be used to turn off induction optimizations for a given function only.
7404 \layout List
7405 \labelwidthstring 00.00.0000
7406
7407
7408 \series bold 
7409 -
7410 \begin_inset ERT
7411 status Collapsed
7412
7413 \layout Standard
7414
7415 \backslash 
7416 /
7417 \end_inset 
7418
7419 -nojtbound
7420 \begin_inset LatexCommand \index{-\/-nojtbound}
7421
7422 \end_inset 
7423
7424
7425 \size large 
7426 \bar under 
7427  
7428 \series default 
7429 \size default 
7430 \bar default 
7431  Will not generate boundary condition check when switch statements
7432 \begin_inset LatexCommand \index{switch statement}
7433
7434 \end_inset 
7435
7436  are implemented using jump-tables.
7437  See section 
7438 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7439
7440 \end_inset 
7441
7442 \SpecialChar ~
7443 Switch Statements for more details.
7444  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7445 nojtbound
7446 \begin_inset LatexCommand \index{\#pragma nojtbound}
7447
7448 \end_inset 
7449
7450  can be used to turn off boundary checking for jump tables for a given function
7451  only.
7452 \layout List
7453 \labelwidthstring 00.00.0000
7454
7455
7456 \series bold 
7457 -
7458 \begin_inset ERT
7459 status Collapsed
7460
7461 \layout Standard
7462
7463 \backslash 
7464 /
7465 \end_inset 
7466
7467 -noloopreverse
7468 \begin_inset LatexCommand \index{-\/-noloopreverse}
7469
7470 \end_inset 
7471
7472
7473 \series default 
7474 \size large 
7475  
7476 \size default 
7477 Will not do loop reversal 
7478 \begin_inset LatexCommand \index{Loop reversing}
7479
7480 \end_inset 
7481
7482 optimization.
7483 \layout List
7484 \labelwidthstring 00.00.0000
7485
7486 -
7487 \begin_inset ERT
7488 status Collapsed
7489
7490 \layout Standard
7491
7492 \backslash 
7493 /
7494 \end_inset 
7495
7496 -
7497 \series bold 
7498 nolabelopt
7499 \series default 
7500  
7501 \begin_inset LatexCommand \index{-\/-nolabelopt }
7502
7503 \end_inset 
7504
7505 Will not optimize labels (makes the dumpfiles more readable).
7506 \layout List
7507 \labelwidthstring 00.00.0000
7508
7509
7510 \series bold 
7511 -
7512 \begin_inset ERT
7513 status Collapsed
7514
7515 \layout Standard
7516
7517 \backslash 
7518 /
7519 \end_inset 
7520
7521 -no-xinit-opt
7522 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7523
7524 \end_inset 
7525
7526
7527 \series default 
7528  Will not memcpy initialized data from code space into xdata space.
7529  This saves a few bytes in code space if you don't have initialized data
7530 \begin_inset LatexCommand \index{Variable initialization}
7531
7532 \end_inset 
7533
7534 .
7535 \layout List
7536 \labelwidthstring 00.00.0000
7537
7538
7539 \series bold 
7540 -
7541 \begin_inset ERT
7542 status Collapsed
7543
7544 \layout Standard
7545
7546 \backslash 
7547 /
7548 \end_inset 
7549
7550 -nooverlay
7551 \begin_inset LatexCommand \index{-\/-nooverlay}
7552
7553 \end_inset 
7554
7555
7556 \series default 
7557   The compiler will not overlay parameters and local variables of any function,
7558  see section Parameters and local variables for more details.
7559 \layout List
7560 \labelwidthstring 00.00.0000
7561
7562
7563 \series bold 
7564 -
7565 \begin_inset ERT
7566 status Collapsed
7567
7568 \layout Standard
7569
7570 \backslash 
7571 /
7572 \end_inset 
7573
7574 -no-peep
7575 \begin_inset LatexCommand \index{-\/-no-peep}
7576
7577 \end_inset 
7578
7579
7580 \series default 
7581  Disable peep-hole optimization with built-in rules.
7582 \layout List
7583 \labelwidthstring 00.00.0000
7584
7585
7586 \series bold 
7587 -
7588 \begin_inset ERT
7589 status Collapsed
7590
7591 \layout Standard
7592
7593 \backslash 
7594 /
7595 \end_inset 
7596
7597 -peep-file
7598 \series default 
7599
7600 \begin_inset LatexCommand \index{-\/-peep-file}
7601
7602 \end_inset 
7603
7604 \SpecialChar ~
7605 <filename> This option can be used to use additional rules to be used by
7606  the peep hole optimizer.
7607  See section 
7608 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7609
7610 \end_inset 
7611
7612 \SpecialChar ~
7613 Peep Hole optimizations for details on how to write these rules.
7614 \layout List
7615 \labelwidthstring 00.00.0000
7616
7617
7618 \series bold 
7619 -
7620 \begin_inset ERT
7621 status Collapsed
7622
7623 \layout Standard
7624
7625 \backslash 
7626 /
7627 \end_inset 
7628
7629 -peep-asm
7630 \begin_inset LatexCommand \index{-\/-peep-asm}
7631
7632 \end_inset 
7633
7634
7635 \series default 
7636  Pass the inline assembler code through the peep hole optimizer.
7637  This can cause unexpected changes to inline assembler code, please go through
7638  the peephole optimizer
7639 \begin_inset LatexCommand \index{Peephole optimizer}
7640
7641 \end_inset 
7642
7643  rules defined in the source file tree '<target>/peeph.def' before using
7644  this option.
7645 \layout List
7646 \labelwidthstring 00.00.0000
7647
7648
7649 \series bold 
7650 -
7651 \begin_inset ERT
7652 status Collapsed
7653
7654 \layout Standard
7655
7656 \backslash 
7657 /
7658 \end_inset 
7659
7660 -opt-code-speed
7661 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7662
7663 \end_inset 
7664
7665
7666 \series default 
7667  The compiler will optimize code generation towards fast code, possibly
7668  at the expense of code size.
7669 \layout List
7670 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7671
7672
7673 \series bold 
7674 -
7675 \begin_inset ERT
7676 status Collapsed
7677
7678 \layout Standard
7679
7680 \backslash 
7681 /
7682 \end_inset 
7683
7684 -opt-code-size
7685 \begin_inset LatexCommand \index{-\/-opt-code-size}
7686
7687 \end_inset 
7688
7689
7690 \series default 
7691  The compiler will optimize code generation towards compact code, possibly
7692  at the expense of code speed.
7693 \layout Subsection
7694
7695 Other Options
7696 \begin_inset LatexCommand \index{Options other}
7697
7698 \end_inset 
7699
7700
7701 \layout List
7702 \labelwidthstring 00.00.0000
7703
7704
7705 \series bold 
7706 -c\SpecialChar ~
7707 -
7708 \begin_inset ERT
7709 status Collapsed
7710
7711 \layout Standard
7712
7713 \backslash 
7714 /
7715 \end_inset 
7716
7717 -compile-only
7718 \begin_inset LatexCommand \index{-\/-compile-only}
7719
7720 \end_inset 
7721
7722
7723 \begin_inset LatexCommand \index{-c -\/-compile-only}
7724
7725 \end_inset 
7726
7727
7728 \series default 
7729  will compile and assemble the source, but will not call the linkage editor.
7730 \layout List
7731 \labelwidthstring 00.00.0000
7732
7733
7734 \series bold 
7735 -
7736 \series default 
7737
7738 \begin_inset ERT
7739 status Collapsed
7740
7741 \layout Standard
7742
7743 \backslash 
7744 /
7745 \end_inset 
7746
7747
7748 \series bold 
7749 -c1mode
7750 \begin_inset LatexCommand \index{-\/-c1mode}
7751
7752 \end_inset 
7753
7754
7755 \series default 
7756  reads the preprocessed source from standard input and compiles it.
7757  The file name for the assembler output must be specified using the -o option.
7758 \layout List
7759 \labelwidthstring 00.00.0000
7760
7761
7762 \series bold 
7763 -E
7764 \begin_inset LatexCommand \index{-E}
7765
7766 \end_inset 
7767
7768
7769 \series default 
7770  Run only the C preprocessor.
7771  Preprocess all the C source files specified and output the results to standard
7772  output.
7773 \layout List
7774 \labelwidthstring 00.00.0000
7775
7776
7777 \series bold 
7778 -o\SpecialChar ~
7779 <path/file>
7780 \begin_inset LatexCommand \index{-o <path/file>}
7781
7782 \end_inset 
7783
7784  
7785 \series default 
7786 The output path resp.
7787  file where everything will be placed.
7788  If the parameter is a path, it must have a trailing slash (or backslash
7789  for the Windows binaries) to be recognized as a path.
7790  
7791 \layout List
7792 \labelwidthstring 00.00.0000
7793
7794
7795 \series bold 
7796 -
7797 \begin_inset ERT
7798 status Collapsed
7799
7800 \layout Standard
7801
7802 \backslash 
7803 /
7804 \end_inset 
7805
7806 -stack-auto
7807 \begin_inset LatexCommand \index{-\/-stack-auto}
7808
7809 \end_inset 
7810
7811
7812 \series default 
7813 \size large 
7814 \emph on 
7815  
7816 \size default 
7817 \emph default 
7818 All functions in the source file will be compiled as 
7819 \emph on 
7820 reentrant
7821 \emph default 
7822
7823 \begin_inset LatexCommand \index{reentrant}
7824
7825 \end_inset 
7826
7827 , i.e.
7828  the parameters and local variables will be allocated on the stack
7829 \begin_inset LatexCommand \index{stack}
7830
7831 \end_inset 
7832
7833 .
7834  See section 
7835 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7836
7837 \end_inset 
7838
7839  Parameters and Local Variables for more details.
7840  If this option is used all source files in the project should be compiled
7841  with this option.
7842  It automatically implies --int-long-reent and --float-reent.
7843  
7844 \layout List
7845 \labelwidthstring 00.00.0000
7846
7847
7848 \series bold 
7849 -
7850 \begin_inset ERT
7851 status Collapsed
7852
7853 \layout Standard
7854
7855 \backslash 
7856 /
7857 \end_inset 
7858
7859 -callee-saves
7860 \begin_inset LatexCommand \index{-\/-callee-saves}
7861
7862 \end_inset 
7863
7864  function1[,function2][,function3]....
7865
7866 \series default 
7867  The compiler by default uses a caller saves convention for register saving
7868  across function calls, however this can cause unnecessary register pushing
7869  & popping when calling small functions from larger functions.
7870  This option can be used to switch the register saving convention for the
7871  function names specified.
7872  The compiler will not save registers when calling these functions, no extra
7873  code will be generated at the entry & exit (function prologue
7874 \series bold 
7875
7876 \begin_inset LatexCommand \index{function prologue}
7877
7878 \end_inset 
7879
7880
7881 \series default 
7882  & epilogue
7883 \series bold 
7884
7885 \begin_inset LatexCommand \index{function epilogue}
7886
7887 \end_inset 
7888
7889
7890 \series default 
7891 ) for these functions to save & restore the registers used by these functions,
7892  this can SUBSTANTIALLY reduce code & improve run time performance of the
7893  generated code.
7894  In the future the compiler (with inter procedural analysis) will be able
7895  to determine the appropriate scheme to use for each function call.
7896  DO NOT use this option for built-in functions such as _mulint..., if this
7897  option is used for a library function the appropriate library function
7898  needs to be recompiled with the same option.
7899  If the project consists of multiple source files then all the source file
7900  should be compiled with the same -
7901 \begin_inset ERT
7902 status Collapsed
7903
7904 \layout Standard
7905
7906 \backslash 
7907 /
7908 \end_inset 
7909
7910 -callee-saves option string.
7911  Also see #pragma\SpecialChar ~
7912 callee_saves
7913 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7914
7915 \end_inset 
7916
7917 .
7918 \layout List
7919 \labelwidthstring 00.00.0000
7920
7921
7922 \series bold 
7923 -
7924 \begin_inset ERT
7925 status Collapsed
7926
7927 \layout Standard
7928
7929 \backslash 
7930 /
7931 \end_inset 
7932
7933 -debug
7934 \begin_inset LatexCommand \index{-\/-debug}
7935
7936 \end_inset 
7937
7938
7939 \bar under 
7940  
7941 \series default 
7942 \bar default 
7943 When this option is used the compiler will generate debug information.
7944  The debug information collected in a file with .cdb extension can be used
7945  with the SDCDB.
7946  For more information see documentation for SDCDB.
7947  Another file with no extension contains debug information in AOMF or AOMF51
7948 \begin_inset LatexCommand \index{AOMF, AOMF51}
7949
7950 \end_inset 
7951
7952  format which is commonly used by third party tools.
7953 \layout List
7954 \labelwidthstring 00.00.0000
7955
7956
7957 \series bold 
7958 -S
7959 \begin_inset LatexCommand \index{-S}
7960
7961 \end_inset 
7962
7963
7964 \size large 
7965 \bar under 
7966  
7967 \series default 
7968 \size default 
7969 \bar default 
7970 Stop after the stage of compilation proper; do not assemble.
7971  The output is an assembler code file for the input file specified.
7972 \layout List
7973 \labelwidthstring 00.00.0000
7974
7975
7976 \series bold 
7977 -
7978 \begin_inset ERT
7979 status Collapsed
7980
7981 \layout Standard
7982
7983 \backslash 
7984 /
7985 \end_inset 
7986
7987 -int-long-reent
7988 \begin_inset LatexCommand \index{-\/-int-long-reent}
7989
7990 \end_inset 
7991
7992
7993 \series default 
7994  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7995  Note by default these libraries are compiled as non-reentrant.
7996  See section Installation for more details.
7997 \layout List
7998 \labelwidthstring 00.00.0000
7999
8000
8001 \series bold 
8002 -
8003 \begin_inset ERT
8004 status Collapsed
8005
8006 \layout Standard
8007
8008 \backslash 
8009 /
8010 \end_inset 
8011
8012 -cyclomatic
8013 \begin_inset LatexCommand \index{-\/-cyclomatic}
8014
8015 \end_inset 
8016
8017
8018 \bar under 
8019  
8020 \series default 
8021 \bar default 
8022 This option will cause the compiler to generate an information message for
8023  each function in the source file.
8024  The message contains some 
8025 \emph on 
8026 important
8027 \emph default 
8028  information about the function.
8029  The number of edges and nodes the compiler detected in the control flow
8030  graph of the function, and most importantly the 
8031 \emph on 
8032 cyclomatic complexity
8033 \begin_inset LatexCommand \index{Cyclomatic complexity}
8034
8035 \end_inset 
8036
8037
8038 \emph default 
8039  see section on Cyclomatic Complexity for more details.
8040 \layout List
8041 \labelwidthstring 00.00.0000
8042
8043
8044 \series bold 
8045 -
8046 \begin_inset ERT
8047 status Collapsed
8048
8049 \layout Standard
8050
8051 \backslash 
8052 /
8053 \end_inset 
8054
8055 -float-reent
8056 \begin_inset LatexCommand \index{-\/-float-reent}
8057
8058 \end_inset 
8059
8060
8061 \series default 
8062  Floating point library is compiled as reentrant
8063 \begin_inset LatexCommand \index{reentrant}
8064
8065 \end_inset 
8066
8067 .
8068  See section Installation for more details.
8069 \layout List
8070 \labelwidthstring 00.00.0000
8071
8072
8073 \series bold 
8074 -
8075 \begin_inset ERT
8076 status Collapsed
8077
8078 \layout Standard
8079
8080 \backslash 
8081 /
8082 \end_inset 
8083
8084 -main-return
8085 \begin_inset LatexCommand \index{-\/-main-return}
8086
8087 \end_inset 
8088
8089
8090 \series default 
8091  This option can be used if the code generated is called by a monitor program
8092  or if the main routine includes an endless loop.
8093  This option results in slightly smaller code and saves two bytes of stack
8094  space.
8095  The return from the 'main'
8096 \begin_inset LatexCommand \index{main return}
8097
8098 \end_inset 
8099
8100  function will return to the function calling main.
8101  The default setting is to lock up i.e.
8102  generate a '
8103 \family typewriter 
8104 sjmp .
8105 \family default 
8106 '.
8107 \layout List
8108 \labelwidthstring 00.00.0000
8109
8110
8111 \series bold 
8112 -
8113 \begin_inset ERT
8114 status Collapsed
8115
8116 \layout Standard
8117
8118 \backslash 
8119 /
8120 \end_inset 
8121
8122 -nostdinc
8123 \begin_inset LatexCommand \index{-\/-nostdinc}
8124
8125 \end_inset 
8126
8127
8128 \series default 
8129  This will prevent the compiler from passing on the default include path
8130  to the preprocessor.
8131 \layout List
8132 \labelwidthstring 00.00.0000
8133
8134
8135 \series bold 
8136 -
8137 \begin_inset ERT
8138 status Collapsed
8139
8140 \layout Standard
8141
8142 \backslash 
8143 /
8144 \end_inset 
8145
8146 -nostdlib
8147 \begin_inset LatexCommand \index{-\/-nostdlib}
8148
8149 \end_inset 
8150
8151
8152 \series default 
8153  This will prevent the compiler from passing on the default library
8154 \begin_inset LatexCommand \index{Libraries}
8155
8156 \end_inset 
8157
8158  path to the linker.
8159 \layout List
8160 \labelwidthstring 00.00.0000
8161
8162
8163 \series bold 
8164 -
8165 \begin_inset ERT
8166 status Collapsed
8167
8168 \layout Standard
8169
8170 \backslash 
8171 /
8172 \end_inset 
8173
8174 -verbose
8175 \begin_inset LatexCommand \index{-\/-verbose}
8176
8177 \end_inset 
8178
8179
8180 \series default 
8181  Shows the various actions the compiler is performing.
8182 \layout List
8183 \labelwidthstring 00.00.0000
8184
8185
8186 \series bold 
8187 -V
8188 \begin_inset LatexCommand \index{-V}
8189
8190 \end_inset 
8191
8192
8193 \series default 
8194  Shows the actual commands the compiler is executing.
8195 \layout List
8196 \labelwidthstring 00.00.0000
8197
8198
8199 \series bold 
8200 -
8201 \begin_inset ERT
8202 status Collapsed
8203
8204 \layout Standard
8205
8206 \backslash 
8207 /
8208 \end_inset 
8209
8210 -no-c-code-in-asm
8211 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8212
8213 \end_inset 
8214
8215
8216 \series default 
8217  Hides your ugly and inefficient c-code from the asm file, so you can always
8218  blame the compiler :)
8219 \layout List
8220 \labelwidthstring 00.00.0000
8221
8222
8223 \series bold 
8224 -
8225 \begin_inset ERT
8226 status Collapsed
8227
8228 \layout Standard
8229
8230 \backslash 
8231 /
8232 \end_inset 
8233
8234 -no-peep-comments
8235 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8236
8237 \end_inset 
8238
8239
8240 \series default 
8241  Will not include peep-hole comments in the generated files.
8242 \layout List
8243 \labelwidthstring 00.00.0000
8244
8245
8246 \series bold 
8247 -
8248 \begin_inset ERT
8249 status Collapsed
8250
8251 \layout Standard
8252
8253 \backslash 
8254 /
8255 \end_inset 
8256
8257 -i-code-in-asm
8258 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8259
8260 \end_inset 
8261
8262
8263 \series default 
8264  Include i-codes in the asm file.
8265  Sounds like noise but is most helpful for debugging the compiler itself.
8266 \layout List
8267 \labelwidthstring 00.00.0000
8268
8269
8270 \series bold 
8271 -
8272 \begin_inset ERT
8273 status Collapsed
8274
8275 \layout Standard
8276
8277 \backslash 
8278 /
8279 \end_inset 
8280
8281 -less-pedantic
8282 \begin_inset LatexCommand \index{-\/-less-pedantic}
8283
8284 \end_inset 
8285
8286
8287 \series default 
8288  Disable some of the more pedantic warnings
8289 \begin_inset LatexCommand \index{Warnings}
8290
8291 \end_inset 
8292
8293  (jwk burps: please be more specific here, please!).
8294 \layout List
8295 \labelwidthstring 00.00.0000
8296
8297
8298 \series bold 
8299 -
8300 \begin_inset ERT
8301 status Collapsed
8302
8303 \layout Standard
8304
8305 \backslash 
8306 /
8307 \end_inset 
8308
8309 -disable-warning\SpecialChar ~
8310 <nnnn>
8311 \begin_inset LatexCommand \index{-\/-disable-warning}
8312
8313 \end_inset 
8314
8315
8316 \series default 
8317  Disable specific warning with number <nnnn>.
8318 \layout List
8319 \labelwidthstring 00.00.0000
8320
8321
8322 \series bold 
8323 -
8324 \begin_inset ERT
8325 status Collapsed
8326
8327 \layout Standard
8328
8329 \backslash 
8330 /
8331 \end_inset 
8332
8333 -print-search-dirs
8334 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8335
8336 \end_inset 
8337
8338
8339 \series default 
8340  Display the directories in the compiler's search path
8341 \layout List
8342 \labelwidthstring 00.00.0000
8343
8344
8345 \series bold 
8346 -
8347 \begin_inset ERT
8348 status Collapsed
8349
8350 \layout Standard
8351
8352 \backslash 
8353 /
8354 \end_inset 
8355
8356 -vc
8357 \begin_inset LatexCommand \index{-\/-vc}
8358
8359 \end_inset 
8360
8361
8362 \series default 
8363  Display errors and warnings using MSVC style, so you can use SDCC with
8364  visual studio.
8365  With SDCC both offering a GCC-like (the default) and a MSVC-like output
8366  style, integration into most programming editors should be straightforward.
8367 \layout List
8368 \labelwidthstring 00.00.0000
8369
8370
8371 \series bold 
8372 -
8373 \begin_inset ERT
8374 status Collapsed
8375
8376 \layout Standard
8377
8378 \backslash 
8379 /
8380 \end_inset 
8381
8382 -use-stdout
8383 \begin_inset LatexCommand \index{-\/-use-stdout}
8384
8385 \end_inset 
8386
8387
8388 \series default 
8389  Send errors and warnings to stdout instead of stderr.
8390 \layout List
8391 \labelwidthstring 00.00.0000
8392
8393
8394 \series bold 
8395 -Wa\SpecialChar ~
8396 asmOption[,asmOption]
8397 \series default 
8398
8399 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8400
8401 \end_inset 
8402
8403 ...
8404  Pass the asmOption to the assembler
8405 \begin_inset LatexCommand \index{Options assembler}
8406
8407 \end_inset 
8408
8409
8410 \begin_inset LatexCommand \index{Assembler options}
8411
8412 \end_inset 
8413
8414 .
8415  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8416 \layout List
8417 \labelwidthstring 00.00.0000
8418
8419
8420 \series bold 
8421 -
8422 \begin_inset ERT
8423 status Collapsed
8424
8425 \layout Standard
8426
8427 \backslash 
8428 /
8429 \end_inset 
8430
8431 -std-sdcc89
8432 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8433
8434 \end_inset 
8435
8436
8437 \series default 
8438  Generally follow the C89 standard, but allow SDCC features that conflict
8439  with the standard (default).
8440 \layout List
8441 \labelwidthstring 00.00.0000
8442
8443
8444 \series bold 
8445 -
8446 \begin_inset ERT
8447 status Collapsed
8448
8449 \layout Standard
8450
8451 \backslash 
8452 /
8453 \end_inset 
8454
8455 -std-c89
8456 \begin_inset LatexCommand \index{-\/-std-c89}
8457
8458 \end_inset 
8459
8460
8461 \series default 
8462  Follow the C89 standard and disable SDCC features that conflict with the
8463  standard.
8464 \layout List
8465 \labelwidthstring 00.00.0000
8466
8467
8468 \series bold 
8469 -
8470 \begin_inset ERT
8471 status Collapsed
8472
8473 \layout Standard
8474
8475 \backslash 
8476 /
8477 \end_inset 
8478
8479 -std-sdcc99
8480 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8481
8482 \end_inset 
8483
8484
8485 \series default 
8486  Generally follow the C99 standard, but allow SDCC features that conflict
8487  with the standard (incomplete support).
8488 \layout List
8489 \labelwidthstring 00.00.0000
8490
8491
8492 \series bold 
8493 -
8494 \begin_inset ERT
8495 status Collapsed
8496
8497 \layout Standard
8498
8499 \backslash 
8500 /
8501 \end_inset 
8502
8503 -std-c99
8504 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8505
8506 \end_inset 
8507
8508
8509 \series default 
8510  Follow the C99 standard and disable SDCC features that conflict with the
8511  standard (incomplete support).
8512 \layout List
8513 \labelwidthstring 00.00.0000
8514
8515
8516 \series bold 
8517 -
8518 \begin_inset ERT
8519 status Collapsed
8520
8521 \layout Standard
8522
8523 \backslash 
8524 /
8525 \end_inset 
8526
8527 -codeseg
8528 \series default 
8529
8530 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8531
8532 \end_inset 
8533
8534 \SpecialChar ~
8535 <Name> The name to be used for the code
8536 \begin_inset LatexCommand \index{code}
8537
8538 \end_inset 
8539
8540  segment, default CSEG.
8541  This is useful if you need to tell the compiler to put the code in a special
8542  segment so you can later on tell the linker to put this segment in a special
8543  place in memory.
8544  Can be used for instance when using bank switching to put the code in a
8545  bank.
8546 \layout List
8547 \labelwidthstring 00.00.0000
8548
8549
8550 \series bold 
8551 -
8552 \begin_inset ERT
8553 status Collapsed
8554
8555 \layout Standard
8556
8557 \backslash 
8558 /
8559 \end_inset 
8560
8561 -constseg
8562 \series default 
8563
8564 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8565
8566 \end_inset 
8567
8568 \SpecialChar ~
8569 <Name> The name to be used for the const
8570 \begin_inset LatexCommand \index{code}
8571
8572 \end_inset 
8573
8574  segment, default CONST.
8575  This is useful if you need to tell the compiler to put the const data in
8576  a special segment so you can later on tell the linker to put this segment
8577  in a special place in memory.
8578  Can be used for instance when using bank switching to put the const data
8579  in a bank.
8580 \layout List
8581 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8582
8583
8584 \series bold 
8585 more-pedantic
8586 \series default 
8587  Actually this is 
8588 \series bold 
8589 \emph on 
8590 not
8591 \series default 
8592 \emph default 
8593  a SDCC compiler option but if you want 
8594 \emph on 
8595 more
8596 \emph default 
8597  warnings you can use a separate tool dedicated to syntax checking like
8598  splint
8599 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8600
8601 \end_inset 
8602
8603
8604 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8605
8606 \end_inset 
8607
8608  
8609 \begin_inset LatexCommand \url{http://www.splint.org}
8610
8611 \end_inset 
8612
8613 .
8614  To make your source files parseable by splint you will have to include
8615  
8616 \family sans 
8617 lint.h
8618 \family default 
8619
8620 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8621
8622 \end_inset 
8623
8624  in your source file and add brackets around extended keywords (like 
8625 \family sans 
8626
8627 \begin_inset Quotes sld
8628 \end_inset 
8629
8630 __at\SpecialChar ~
8631
8632 \series bold 
8633 (
8634 \series default 
8635 0xab
8636 \series bold 
8637 )
8638 \series default 
8639
8640 \begin_inset Quotes srd
8641 \end_inset 
8642
8643
8644 \family default 
8645  and 
8646 \family sans 
8647
8648 \begin_inset Quotes sld
8649 \end_inset 
8650
8651 __interrupt\SpecialChar ~
8652 (2)
8653 \begin_inset Quotes srd
8654 \end_inset 
8655
8656
8657 \family default 
8658 ).
8659  
8660 \newline 
8661 Splint has an excellent on line manual at 
8662 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8663
8664 \end_inset 
8665
8666  and it's capabilities go beyond pure syntax checking.
8667  You'll need to tell splint the location of SDCC's include files so a typical
8668  command line could look like this: 
8669 \newline 
8670
8671 \family sans 
8672 splint\SpecialChar ~
8673 -I\SpecialChar ~
8674 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8675 \SpecialChar ~
8676 myprogram.c
8677 \layout Subsection
8678
8679 Intermediate Dump Options
8680 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8681
8682 \end_inset 
8683
8684
8685 \begin_inset LatexCommand \index{Options intermediate dump}
8686
8687 \end_inset 
8688
8689
8690 \begin_inset LatexCommand \index{Intermediate dump options}
8691
8692 \end_inset 
8693
8694
8695 \layout Standard
8696
8697 The following options are provided for the purpose of retargetting and debugging
8698  the compiler.
8699  They provide a means to dump the intermediate code (iCode
8700 \begin_inset LatexCommand \index{iCode}
8701
8702 \end_inset 
8703
8704 ) generated by the compiler in human readable form at various stages of
8705  the compilation process.
8706  More on iCodes see chapter 
8707 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8708
8709 \end_inset 
8710
8711  
8712 \begin_inset Quotes srd
8713 \end_inset 
8714
8715 The anatomy of the compiler
8716 \begin_inset Quotes srd
8717 \end_inset 
8718
8719 .
8720 \layout List
8721 \labelwidthstring 00.00.0000
8722
8723
8724 \series bold 
8725 -
8726 \begin_inset ERT
8727 status Collapsed
8728
8729 \layout Standard
8730
8731 \backslash 
8732 /
8733 \end_inset 
8734
8735 -dumpraw
8736 \begin_inset LatexCommand \index{-\/-dumpraw}
8737
8738 \end_inset 
8739
8740
8741 \series default 
8742  This option will cause the compiler to dump the intermediate code into
8743  a file of named 
8744 \emph on 
8745 <source filename>.dumpraw
8746 \emph default 
8747  just after the intermediate code has been generated for a function, i.e.
8748  before any optimizations are done.
8749  The basic blocks
8750 \begin_inset LatexCommand \index{Basic blocks}
8751
8752 \end_inset 
8753
8754  at this stage ordered in the depth first number, so they may not be in
8755  sequence of execution.
8756 \layout List
8757 \labelwidthstring 00.00.0000
8758
8759
8760 \series bold 
8761 -
8762 \begin_inset ERT
8763 status Collapsed
8764
8765 \layout Standard
8766
8767 \backslash 
8768 /
8769 \end_inset 
8770
8771 -dumpgcse
8772 \begin_inset LatexCommand \index{-\/-dumpgcse}
8773
8774 \end_inset 
8775
8776
8777 \series default 
8778  Will create a dump of iCode's, after global subexpression elimination
8779 \begin_inset LatexCommand \index{Global subexpression elimination}
8780
8781 \end_inset 
8782
8783 , into a file named 
8784 \emph on 
8785 <source filename>.dumpgcse.
8786 \layout List
8787 \labelwidthstring 00.00.0000
8788
8789
8790 \series bold 
8791 -
8792 \begin_inset ERT
8793 status Collapsed
8794
8795 \layout Standard
8796
8797 \backslash 
8798 /
8799 \end_inset 
8800
8801 -dumpdeadcode
8802 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8803
8804 \end_inset 
8805
8806
8807 \series default 
8808  Will create a dump of iCode's, after deadcode elimination
8809 \begin_inset LatexCommand \index{Dead-code elimination}
8810
8811 \end_inset 
8812
8813 , into a file named 
8814 \emph on 
8815 <source filename>.dumpdeadcode.
8816 \layout List
8817 \labelwidthstring 00.00.0000
8818
8819
8820 \series bold 
8821 -
8822 \begin_inset ERT
8823 status Collapsed
8824
8825 \layout Standard
8826
8827 \backslash 
8828 /
8829 \end_inset 
8830
8831 -dumploop
8832 \begin_inset LatexCommand \index{-\/-dumploop}
8833
8834 \end_inset 
8835
8836
8837 \series default 
8838 \size large 
8839  
8840 \size default 
8841 Will create a dump of iCode's, after loop optimizations
8842 \begin_inset LatexCommand \index{Loop optimization}
8843
8844 \end_inset 
8845
8846 , into a file named 
8847 \emph on 
8848 <source filename>.dumploop.
8849 \layout List
8850 \labelwidthstring 00.00.0000
8851
8852
8853 \series bold 
8854 -
8855 \begin_inset ERT
8856 status Collapsed
8857
8858 \layout Standard
8859
8860 \backslash 
8861 /
8862 \end_inset 
8863
8864 -dumprange
8865 \begin_inset LatexCommand \index{-\/-dumprange}
8866
8867 \end_inset 
8868
8869
8870 \series default 
8871 \size large 
8872  
8873 \size default 
8874 Will create a dump of iCode's, after live range analysis
8875 \begin_inset LatexCommand \index{Live range analysis}
8876
8877 \end_inset 
8878
8879 , into a file named 
8880 \emph on 
8881 <source filename>.dumprange.
8882 \layout List
8883 \labelwidthstring 00.00.0000
8884
8885
8886 \series bold 
8887 -
8888 \begin_inset ERT
8889 status Collapsed
8890
8891 \layout Standard
8892
8893 \backslash 
8894 /
8895 \end_inset 
8896
8897 -dumlrange
8898 \begin_inset LatexCommand \index{-\/-dumlrange}
8899
8900 \end_inset 
8901
8902
8903 \series default 
8904  Will dump the life ranges
8905 \begin_inset LatexCommand \index{Live range analysis}
8906
8907 \end_inset 
8908
8909  for all symbols.
8910 \layout List
8911 \labelwidthstring 00.00.0000
8912
8913
8914 \series bold 
8915 -
8916 \begin_inset ERT
8917 status Collapsed
8918
8919 \layout Standard
8920
8921 \backslash 
8922 /
8923 \end_inset 
8924
8925 -dumpregassign
8926 \begin_inset LatexCommand \index{-\/-dumpregassign}
8927
8928 \end_inset 
8929
8930
8931 \bar under 
8932  
8933 \series default 
8934 \bar default 
8935 Will create a dump of iCode's, after register assignment
8936 \begin_inset LatexCommand \index{Register assignment}
8937
8938 \end_inset 
8939
8940 , into a file named 
8941 \emph on 
8942 <source filename>.dumprassgn.
8943 \layout List
8944 \labelwidthstring 00.00.0000
8945
8946
8947 \series bold 
8948 -
8949 \begin_inset ERT
8950 status Collapsed
8951
8952 \layout Standard
8953
8954 \backslash 
8955 /
8956 \end_inset 
8957
8958 -dumplrange
8959 \begin_inset LatexCommand \index{-\/-dumplrange}
8960
8961 \end_inset 
8962
8963
8964 \series default 
8965  Will create a dump of the live ranges of iTemp's
8966 \layout List
8967 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8968
8969
8970 \series bold 
8971 -
8972 \begin_inset ERT
8973 status Collapsed
8974
8975 \layout Standard
8976
8977 \backslash 
8978 /
8979 \end_inset 
8980
8981 -dumpall
8982 \begin_inset LatexCommand \index{-\/-dumpall}
8983
8984 \end_inset 
8985
8986
8987 \size large 
8988 \bar under 
8989  
8990 \series default 
8991 \size default 
8992 \bar default 
8993 Will cause all the above mentioned dumps to be created.
8994 \layout Subsection
8995
8996 Redirecting output on Windows Shells
8997 \layout Standard
8998 \added_space_bottom bigskip 
8999 By default SDCC writes it's error messages to 
9000 \begin_inset Quotes sld
9001 \end_inset 
9002
9003 standard error
9004 \begin_inset Quotes srd
9005 \end_inset 
9006
9007 .
9008  To force all messages to 
9009 \begin_inset Quotes sld
9010 \end_inset 
9011
9012 standard output
9013 \begin_inset Quotes srd
9014 \end_inset 
9015
9016  use 
9017 \series bold 
9018 -
9019 \series default 
9020 \emph on 
9021
9022 \begin_inset ERT
9023 status Collapsed
9024
9025 \layout Standard
9026
9027 \backslash 
9028 /
9029 \end_inset 
9030
9031
9032 \series bold 
9033 \emph default 
9034 -
9035 \series default 
9036 use-stdout
9037 \begin_inset LatexCommand \index{-\/-use-stdout}
9038
9039 \end_inset 
9040
9041 .
9042  Additionally, if you happen to have visual studio installed in your windows
9043  machine, you can use it to compile your sources using a custom build and
9044  the SDCC -
9045 \emph on 
9046
9047 \begin_inset ERT
9048 status Collapsed
9049
9050 \layout Standard
9051
9052 \backslash 
9053 /
9054 \end_inset 
9055
9056
9057 \emph default 
9058 -vc
9059 \begin_inset LatexCommand \index{-\/-vc}
9060
9061 \end_inset 
9062
9063  option.
9064  Something like this should work:
9065 \newline 
9066
9067 \newline 
9068
9069 \series bold 
9070 c:
9071 \backslash 
9072 sdcc
9073 \backslash 
9074 bin
9075 \backslash 
9076 sdcc.exe -
9077 \series default 
9078 \emph on 
9079
9080 \begin_inset ERT
9081 status Collapsed
9082
9083 \layout Standard
9084
9085 \backslash 
9086 /
9087 \end_inset 
9088
9089
9090 \series bold 
9091 \emph default 
9092 -vc -
9093 \series default 
9094 \emph on 
9095
9096 \begin_inset ERT
9097 status Collapsed
9098
9099 \layout Standard
9100
9101 \backslash 
9102 /
9103 \end_inset 
9104
9105
9106 \series bold 
9107 \emph default 
9108 -model-large -c $(InputPath)
9109 \layout Section
9110
9111 Environment variables
9112 \begin_inset LatexCommand \index{Environment variables}
9113
9114 \end_inset 
9115
9116
9117 \layout Standard
9118
9119 SDCC recognizes the following environment variables:
9120 \layout List
9121 \labelwidthstring 00.00.0000
9122
9123
9124 \series bold 
9125 SDCC_LEAVE_SIGNALS
9126 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9127
9128 \end_inset 
9129
9130
9131 \series default 
9132  SDCC installs a signal handler
9133 \begin_inset LatexCommand \index{signal handler}
9134
9135 \end_inset 
9136
9137  to be able to delete temporary files after an user break (^C) or an exception.
9138  If this environment variable is set, SDCC won't install the signal handler
9139  in order to be able to debug SDCC.
9140 \layout List
9141 \labelwidthstring 00.00.0000
9142
9143
9144 \series bold 
9145 TMP,\SpecialChar ~
9146 TEMP,\SpecialChar ~
9147 TMPDIR
9148 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9149
9150 \end_inset 
9151
9152
9153 \series default 
9154  Path, where temporary files will be created.
9155  The order of the variables is the search order.
9156  In a standard *nix environment these variables are not set, and there's
9157  no need to set them.
9158  On Windows it's recommended to set one of them.
9159 \layout List
9160 \labelwidthstring 00.00.0000
9161
9162
9163 \series bold 
9164 SDCC_HOME
9165 \begin_inset LatexCommand \index{SDCC\_HOME}
9166
9167 \end_inset 
9168
9169
9170 \series default 
9171  Path, see section 
9172 \begin_inset LatexCommand \ref{sub:Install-paths}
9173
9174 \end_inset 
9175
9176 \SpecialChar ~
9177
9178 \begin_inset Quotes sld
9179 \end_inset 
9180
9181  Install Paths
9182 \begin_inset Quotes srd
9183 \end_inset 
9184
9185 .
9186 \layout List
9187 \labelwidthstring 00.00.0000
9188
9189
9190 \series bold 
9191 SDCC_INCLUDE
9192 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9193
9194 \end_inset 
9195
9196
9197 \series default 
9198  Path, see section 
9199 \begin_inset LatexCommand \ref{sub:Search-Paths}
9200
9201 \end_inset 
9202
9203 \SpecialChar ~
9204
9205 \begin_inset Quotes sld
9206 \end_inset 
9207
9208 Search Paths
9209 \begin_inset Quotes srd
9210 \end_inset 
9211
9212 .
9213 \layout List
9214 \labelwidthstring 00.00.0000
9215
9216
9217 \series bold 
9218 SDCC_LIB
9219 \begin_inset LatexCommand \index{SDCC\_LIB}
9220
9221 \end_inset 
9222
9223
9224 \series default 
9225  Path, see section 
9226 \begin_inset LatexCommand \ref{sub:Search-Paths}
9227
9228 \end_inset 
9229
9230 \SpecialChar ~
9231
9232 \begin_inset Quotes sld
9233 \end_inset 
9234
9235 Search Paths
9236 \begin_inset Quotes srd
9237 \end_inset 
9238
9239 ..
9240 \layout Standard
9241 \added_space_bottom bigskip 
9242 There are some more environment variables recognized by SDCC, but these
9243  are solely used for debugging purposes.
9244  They can change or disappear very quickly, and will never be documented.
9245 \layout Section
9246
9247 Storage Class Language Extensions
9248 \layout Subsection
9249
9250 MCS51/DS390 Storage Class
9251 \begin_inset LatexCommand \index{Storage class}
9252
9253 \end_inset 
9254
9255  Language Extensions
9256 \layout Standard
9257
9258 In addition to the ANSI storage classes SDCC allows the following MCS51
9259  specific storage classes:
9260 \layout Subsubsection
9261
9262 data
9263 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9264
9265 \end_inset 
9266
9267
9268 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9269
9270 \end_inset 
9271
9272  / near
9273 \begin_inset LatexCommand \index{near (storage class)}
9274
9275 \end_inset 
9276
9277
9278 \begin_inset LatexCommand \index{\_\_near (storage class)}
9279
9280 \end_inset 
9281
9282
9283 \layout Standard
9284
9285 This is the 
9286 \series bold 
9287 default
9288 \series default 
9289  storage class for the Small Memory model (
9290 \emph on 
9291 data
9292 \emph default 
9293  and 
9294 \emph on 
9295 near
9296 \emph default 
9297  or the more ANSI-C compliant forms 
9298 \emph on 
9299 __data
9300 \emph default 
9301  and 
9302 \emph on 
9303 __near
9304 \emph default 
9305  can be used synonymously).
9306  Variables declared with this storage class will be allocated in the directly
9307  addressable portion of the internal RAM of a 8051, e.g.:
9308 \layout Verse
9309
9310
9311 \family typewriter 
9312 __data unsigned char test_data;
9313 \layout Standard
9314
9315 Writing 0x01 to this variable generates the assembly code:
9316 \layout Verse
9317
9318
9319 \family typewriter 
9320 75*00 01\SpecialChar ~
9321 \SpecialChar ~
9322 \SpecialChar ~
9323 mov\SpecialChar ~
9324 \SpecialChar ~
9325 _test_data,#0x01
9326 \layout Subsubsection
9327
9328 xdata
9329 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9330
9331 \end_inset 
9332
9333
9334 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9335
9336 \end_inset 
9337
9338  / far
9339 \begin_inset LatexCommand \index{far (storage class)}
9340
9341 \end_inset 
9342
9343
9344 \begin_inset LatexCommand \index{\_\_far (storage class)}
9345
9346 \end_inset 
9347
9348
9349 \layout Standard
9350
9351 Variables declared with this storage class will be placed in the external
9352  RAM.
9353  This is the 
9354 \series bold 
9355 default
9356 \series default 
9357  storage class for the Large Memory model, e.g.:
9358 \layout Verse
9359
9360
9361 \family typewriter 
9362 __xdata unsigned char test_xdata;
9363 \layout Standard
9364
9365 Writing 0x01 to this variable generates the assembly code:
9366 \layout Verse
9367
9368
9369 \family typewriter 
9370 90s00r00\SpecialChar ~
9371 \SpecialChar ~
9372 \SpecialChar ~
9373 mov\SpecialChar ~
9374 \SpecialChar ~
9375 dptr,#_test_xdata 
9376 \newline 
9377 74\SpecialChar ~
9378 01\SpecialChar ~
9379 \SpecialChar ~
9380 \SpecialChar ~
9381 \SpecialChar ~
9382 \SpecialChar ~
9383 \SpecialChar ~
9384 mov\SpecialChar ~
9385 \SpecialChar ~
9386 a,#0x01 
9387 \newline 
9388 F0\SpecialChar ~
9389 \SpecialChar ~
9390 \SpecialChar ~
9391 \SpecialChar ~
9392 \SpecialChar ~
9393 \SpecialChar ~
9394 \SpecialChar ~
9395 \SpecialChar ~
9396 \SpecialChar ~
9397 movx\SpecialChar ~
9398 @dptr,a 
9399 \layout Subsubsection
9400
9401 idata
9402 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9403
9404 \end_inset 
9405
9406
9407 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9408
9409 \end_inset 
9410
9411
9412 \layout Standard
9413
9414 Variables declared with this storage class will be allocated into the indirectly
9415  addressable portion of the internal ram of a 8051, e.g.:
9416 \layout Verse
9417
9418
9419 \family typewriter 
9420 __idata unsigned char test_idata;
9421 \layout Standard
9422
9423 Writing 0x01 to this variable generates the assembly code:
9424 \layout Verse
9425
9426
9427 \family typewriter 
9428 78r00\SpecialChar ~
9429 \SpecialChar ~
9430 \SpecialChar ~
9431 \SpecialChar ~
9432 \SpecialChar ~
9433 \SpecialChar ~
9434 \SpecialChar ~
9435 mov\SpecialChar ~
9436 \SpecialChar ~
9437 r0,#_test_idata
9438 \newline 
9439 76\SpecialChar ~
9440 01\SpecialChar ~
9441 \SpecialChar ~
9442 \SpecialChar ~
9443 \SpecialChar ~
9444 \SpecialChar ~
9445 \SpecialChar ~
9446 \SpecialChar ~
9447 mov\SpecialChar ~
9448 \SpecialChar ~
9449 @r0,#0x01
9450 \layout Standard
9451
9452 Please note, the first 128 byte of idata physically access the same RAM
9453  as the data memory.
9454  The original 8051 had 128 byte idata memory, nowadays most devices have
9455  256 byte idata memory.
9456  The stack
9457 \begin_inset LatexCommand \index{stack}
9458
9459 \end_inset 
9460
9461  is located in idata memory.
9462 \layout Subsubsection
9463
9464 pdata
9465 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9466
9467 \end_inset 
9468
9469
9470 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9471
9472 \end_inset 
9473
9474
9475 \layout Standard
9476
9477 Paged xdata access is just as straightforward as using the other addressing
9478  modes of a 8051.
9479  It is typically located at the start of xdata and has a maximum size of
9480  256 bytes.
9481  The following example writes 0x01 to the pdata variable.
9482  Please note, pdata access physically accesses xdata memory.
9483  The high byte of the address is determined by port P2 
9484 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9485
9486 \end_inset 
9487
9488 (or in case of some 8051 variants by a separate Special Function Register,
9489  see section 
9490 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9491
9492 \end_inset 
9493
9494 ).
9495  This is the 
9496 \series bold 
9497 default
9498 \series default 
9499  storage class for the Medium Memory model, e.g.:
9500 \layout Verse
9501
9502
9503 \family typewriter 
9504 __pdata unsigned char test_pdata;
9505 \layout Standard
9506
9507 Writing 0x01 to this variable generates the assembly code:
9508 \layout Verse
9509
9510
9511 \family typewriter 
9512 78r00\SpecialChar ~
9513 \SpecialChar ~
9514 \SpecialChar ~
9515 \SpecialChar ~
9516 \SpecialChar ~
9517 \SpecialChar ~
9518 mov r0,#_test_pdata
9519 \newline 
9520 74 01\SpecialChar ~
9521 \SpecialChar ~
9522 \SpecialChar ~
9523 \SpecialChar ~
9524 \SpecialChar ~
9525 \SpecialChar ~
9526 mov a,#0x01 
9527 \newline 
9528 F2\SpecialChar ~
9529 \SpecialChar ~
9530 \SpecialChar ~
9531 \SpecialChar ~
9532 \SpecialChar ~
9533 \SpecialChar ~
9534 \SpecialChar ~
9535 \SpecialChar ~
9536 \SpecialChar ~
9537 movx @r0,a
9538 \layout Standard
9539
9540 If the -
9541 \begin_inset ERT
9542 status Collapsed
9543
9544 \layout Standard
9545
9546 \backslash 
9547 /
9548 \end_inset 
9549
9550 -xstack
9551 \begin_inset LatexCommand \index{-\/-xstack}
9552
9553 \end_inset 
9554
9555  option is used the pdata memory area is followed by the xstack memory area
9556  and the sum of their sizes is limited to 256 bytes.
9557 \layout Subsubsection
9558
9559 code
9560 \begin_inset LatexCommand \index{code}
9561
9562 \end_inset 
9563
9564
9565 \begin_inset LatexCommand \index{\_\_code}
9566
9567 \end_inset 
9568
9569
9570 \layout Standard
9571
9572 'Variables' declared with this storage class will be placed in the code
9573  memory:
9574 \layout Verse
9575
9576
9577 \family typewriter 
9578 __code unsigned char test_code;
9579 \layout Standard
9580
9581 Read access to this variable generates the assembly code:
9582 \layout Verse
9583
9584
9585 \family typewriter 
9586 90s00r6F\SpecialChar ~
9587 \SpecialChar ~
9588 \SpecialChar ~
9589 mov dptr,#_test_code
9590 \newline 
9591 E4\SpecialChar ~
9592 \SpecialChar ~
9593 \SpecialChar ~
9594 \SpecialChar ~
9595 \SpecialChar ~
9596 \SpecialChar ~
9597 \SpecialChar ~
9598 \SpecialChar ~
9599 \SpecialChar ~
9600 clr a
9601 \newline 
9602 93\SpecialChar ~
9603 \SpecialChar ~
9604 \SpecialChar ~
9605 \SpecialChar ~
9606 \SpecialChar ~
9607 \SpecialChar ~
9608 \SpecialChar ~
9609 \SpecialChar ~
9610 \SpecialChar ~
9611 movc a,@a+dptr 
9612 \layout Standard
9613
9614
9615 \family typewriter 
9616 char
9617 \family default 
9618  indexed arrays of characters in code memory can be accessed efficiently:
9619 \layout Verse
9620
9621
9622 \family typewriter 
9623 __code char test_array[] = {'c','h','e','a','p'}; 
9624 \layout Standard
9625
9626 Read access to this array using an 8-bit unsigned index generates the assembly
9627  code:
9628 \layout Verse
9629
9630
9631 \family typewriter 
9632 E5*00\SpecialChar ~
9633 \SpecialChar ~
9634 \SpecialChar ~
9635 \SpecialChar ~
9636 \SpecialChar ~
9637 \SpecialChar ~
9638 mov a,_index 
9639 \layout Verse
9640
9641
9642 \family typewriter 
9643 90s00r41\SpecialChar ~
9644 \SpecialChar ~
9645 \SpecialChar ~
9646 mov dptr,#_test_array
9647 \layout Verse
9648
9649
9650 \family typewriter 
9651 93\SpecialChar ~
9652 \SpecialChar ~
9653 \SpecialChar ~
9654 \SpecialChar ~
9655 \SpecialChar ~
9656 \SpecialChar ~
9657 \SpecialChar ~
9658 \SpecialChar ~
9659 \SpecialChar ~
9660 movc a,@a+dptr 
9661 \layout Subsubsection
9662
9663 bit
9664 \begin_inset LatexCommand \index{bit}
9665
9666 \end_inset 
9667
9668
9669 \begin_inset LatexCommand \index{\_\_bit}
9670
9671 \end_inset 
9672
9673
9674 \layout Standard
9675
9676 This is a data-type and a storage class specifier.
9677  When a variable is declared as a bit, it is allocated into the bit addressable
9678  memory of 8051, e.g.:
9679 \layout Verse
9680
9681
9682 \family typewriter 
9683 __bit test_bit;
9684 \layout Standard
9685
9686 Writing 1 to this variable generates the assembly code:
9687 \layout Verse
9688
9689
9690 \family typewriter 
9691 D2*00\SpecialChar ~
9692 \SpecialChar ~
9693 \SpecialChar ~
9694 \SpecialChar ~
9695 \SpecialChar ~
9696 \SpecialChar ~
9697 \SpecialChar ~
9698 setb\SpecialChar ~
9699 _test_bit
9700 \layout Standard
9701
9702 The bit addressable memory consists of 128 bits which are located from 0x20
9703  to 0x2f in data memory.
9704  
9705 \newline 
9706 Apart from this 8051 specific storage class most architectures support ANSI-C
9707  bitfields
9708 \begin_inset LatexCommand \index{bitfields}
9709
9710 \end_inset 
9711
9712
9713 \begin_inset Foot
9714 collapsed false
9715
9716 \layout Standard
9717
9718 Not really meant as examples, but nevertheless showing what bitfields are
9719  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9720 \end_inset 
9721
9722 .
9723  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9724  signed modifier are implemented as unsigned.
9725 \layout Subsubsection
9726
9727 sfr
9728 \begin_inset LatexCommand \index{sfr}
9729
9730 \end_inset 
9731
9732
9733 \begin_inset LatexCommand \index{\_\_sfr}
9734
9735 \end_inset 
9736
9737  / sfr16
9738 \begin_inset LatexCommand \index{sfr16}
9739
9740 \end_inset 
9741
9742
9743 \begin_inset LatexCommand \index{\_\_sfr16}
9744
9745 \end_inset 
9746
9747  / sfr32
9748 \begin_inset LatexCommand \index{sfr32}
9749
9750 \end_inset 
9751
9752
9753 \begin_inset LatexCommand \index{\_\_sfr32}
9754
9755 \end_inset 
9756
9757  / sbit
9758 \begin_inset LatexCommand \index{\_\_sbit}
9759
9760 \end_inset 
9761
9762
9763 \begin_inset LatexCommand \index{sbit}
9764
9765 \end_inset 
9766
9767
9768 \layout Standard
9769
9770 Like the bit keyword, 
9771 \emph on 
9772 sfr / sfr16 / sfr32 / sbit 
9773 \emph default 
9774 signify both a data-type and storage class, they are used to describe the
9775  
9776 \emph on 
9777 s
9778 \emph default 
9779 pecial 
9780 \emph on 
9781 f
9782 \emph default 
9783 unction 
9784 \emph on 
9785 r
9786 \emph default 
9787 egisters and 
9788 \emph on 
9789 s
9790 \emph default 
9791 pecial 
9792 \emph on 
9793 bit
9794 \emph default 
9795  variables of a 8051, eg:
9796 \layout Verse
9797
9798
9799 \family typewriter 
9800 __sfr __at
9801 \begin_inset LatexCommand \index{at}
9802
9803 \end_inset 
9804
9805
9806 \begin_inset LatexCommand \index{\_\_at}
9807
9808 \end_inset 
9809
9810  (0x80) P0;\SpecialChar ~
9811  /* special function register P0 at location 0x80 */
9812 \newline 
9813 /* 16 bit special function register combination for timer 0 */
9814 \newline 
9815 /* with the high byte at location 0x8C and the low byte at location 0x8A
9816  */
9817 \newline 
9818 __sfr16 __at
9819 \begin_inset LatexCommand \index{at}
9820
9821 \end_inset 
9822
9823
9824 \begin_inset LatexCommand \index{\_\_at}
9825
9826 \end_inset 
9827
9828  (0x8C8A) TMR0;
9829 \newline 
9830 __sbit __at (0xd7) CY; /* CY (Carry Flag
9831 \begin_inset LatexCommand \index{Flags}
9832
9833 \end_inset 
9834
9835
9836 \begin_inset LatexCommand \index{Carry flag}
9837
9838 \end_inset 
9839
9840 ) */
9841 \layout Standard
9842
9843 Special function registers which are located on an address dividable by
9844  8 are bit-addressable, an
9845 \emph on 
9846  sbit
9847 \emph default 
9848  addresses a specific bit within these sfr.
9849 \newline 
9850 16 Bit and 32 bit special function register combinations which require a
9851  certain access order are better not declared using 
9852 \emph on 
9853 sfr16
9854 \emph default 
9855  or 
9856 \emph on 
9857 sfr32.
9858
9859 \emph default 
9860  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9861  this is not guaranteed.
9862 \newline 
9863
9864 \layout Standard
9865
9866 Please note, if you use a header file which was written for another compiler
9867  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
9868  likely be 
9869 \emph on 
9870 not 
9871 \emph default 
9872 compatible.
9873  Specifically the syntax 
9874 \family typewriter 
9875 \SpecialChar ~
9876 sfr P0 = 0x80;\SpecialChar ~
9877
9878 \family default 
9879  is compiled 
9880 \emph on 
9881 without warning
9882 \emph default 
9883  by SDCC to an assignment of 0x80 to a variable called P0 
9884 \family typewriter 
9885
9886 \begin_inset Marginal
9887 collapsed true
9888
9889 \layout Standard
9890
9891
9892 \series bold 
9893 \SpecialChar ~
9894 !
9895 \end_inset 
9896
9897 .
9898  
9899 \family default 
9900 Nevertheless it is possible to write header files
9901 \begin_inset LatexCommand \index{Header files}
9902
9903 \end_inset 
9904
9905
9906 \begin_inset LatexCommand \index{Include files}
9907
9908 \end_inset 
9909
9910  which can be shared among different compilers (see section 
9911 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
9912
9913 \end_inset 
9914
9915 ).
9916  
9917 \layout Subsubsection
9918
9919 Pointers
9920 \begin_inset LatexCommand \index{Pointer}
9921
9922 \end_inset 
9923
9924  to MCS51/DS390 specific memory spaces
9925 \layout Standard
9926
9927 SDCC allows (via language extensions) pointers to explicitly point to any
9928  of the memory spaces
9929 \begin_inset LatexCommand \index{Memory model}
9930
9931 \end_inset 
9932
9933  of the 8051.
9934  In addition to the explicit pointers, the compiler uses (by default) generic
9935  pointers which can be used to point to any of the memory spaces.
9936 \newline 
9937
9938 \newline 
9939 Pointer declaration examples:
9940 \layout Verse
9941
9942
9943 \family typewriter 
9944 /* pointer physically in internal ram pointing to object in external ram
9945  */ 
9946 \newline 
9947 __xdata unsigned char * __data p;
9948 \newline 
9949
9950 \newline 
9951 /* pointer physically in external ram pointing to object in internal ram
9952  */ 
9953 \newline 
9954 __data unsigned char * __xdata p;
9955 \newline 
9956
9957 \newline 
9958 /* pointer physically in code rom pointing to data in xdata space */ 
9959 \newline 
9960 __xdata unsigned char * __code p;
9961 \newline 
9962
9963 \newline 
9964 /* pointer physically in code space pointing to data in code space */ 
9965 \newline 
9966 __code unsigned char * __code p;
9967 \newline 
9968
9969 \newline 
9970 /* generic pointer physically located in xdata space */
9971 \newline 
9972 unsigned char * __xdata p;
9973 \newline 
9974
9975 \newline 
9976 /* generic pointer physically located in default memory space */
9977 \newline 
9978 unsigned char * p;
9979 \newline 
9980
9981 \newline 
9982 /* the following is a function pointer physically located in data space
9983  */
9984 \newline 
9985 char (* __data fp)(void);
9986 \layout Standard
9987
9988 Well you get the idea.
9989  
9990 \newline 
9991
9992 \newline 
9993 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
9994 \emph on 
9995 generic
9996 \emph default 
9997  pointers.
9998  
9999 \size small 
10000
10001 \newline 
10002
10003 \newline 
10004
10005 \size default 
10006 The highest order byte of the 
10007 \emph on 
10008 generic
10009 \emph default 
10010  pointers contains the data space information.
10011  Assembler support routines are called whenever data is stored or retrieved
10012  using 
10013 \emph on 
10014 generic
10015 \emph default 
10016  pointers.
10017  These are useful for developing reusable library
10018 \begin_inset LatexCommand \index{Libraries}
10019
10020 \end_inset 
10021
10022  routines.
10023  Explicitly specifying the pointer type will generate the most efficient
10024  code.
10025 \layout Subsubsection
10026
10027 Notes on MCS51 memory
10028 \begin_inset LatexCommand \index{MCS51 memory}
10029
10030 \end_inset 
10031
10032  layout
10033 \layout Standard
10034
10035 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10036  RAM memory which is structured as follows:
10037 \newline 
10038
10039 \newline 
10040 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10041  
10042 \newline 
10043 - Bytes 20-2F - 16 bytes to hold 128 bit
10044 \begin_inset LatexCommand \index{bit}
10045
10046 \end_inset 
10047
10048  variables and, 
10049 \newline 
10050 - Bytes 30-7F - 80 bytes for general purpose use.
10051 \newline 
10052
10053 \layout Standard
10054
10055 Additionally some members of the MCS51 family may have up to 128 bytes of
10056  additional, indirectly addressable, internal RAM memory (
10057 \emph on 
10058 idata
10059 \emph default 
10060
10061 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10062
10063 \end_inset 
10064
10065
10066 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10067
10068 \end_inset 
10069
10070 ).
10071  Furthermore, some chips may have some built in external memory (
10072 \emph on 
10073 xdata
10074 \emph default 
10075
10076 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10077
10078 \end_inset 
10079
10080
10081 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10082
10083 \end_inset 
10084
10085 ) which should not be confused with the internal, directly addressable RAM
10086  memory (
10087 \emph on 
10088 data
10089 \emph default 
10090
10091 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10092
10093 \end_inset 
10094
10095
10096 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10097
10098 \end_inset 
10099
10100 ).
10101  Sometimes this built in 
10102 \emph on 
10103 xdata
10104 \emph default 
10105  memory has to be activated before using it (you can probably find this
10106  information on the datasheet of the microcontroller your are using, see
10107  also section 
10108 \begin_inset LatexCommand \ref{sub:Startup-Code}
10109
10110 \end_inset 
10111
10112 \SpecialChar ~
10113 Startup-Code).
10114 \layout Standard
10115
10116 Normally SDCC will only use the first bank
10117 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10118
10119 \end_inset 
10120
10121  of registers (register bank 0), but it is possible to specify that other
10122  banks of registers (keyword 
10123 \emph on 
10124 using
10125 \emph default 
10126  
10127 \emph on 
10128
10129 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10130
10131 \end_inset 
10132
10133
10134 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10135
10136 \end_inset 
10137
10138
10139 \emph default 
10140 ) should be used in interrupt
10141 \begin_inset LatexCommand \index{interrupt}
10142
10143 \end_inset 
10144
10145
10146 \begin_inset LatexCommand \index{\_\_interrupt}
10147
10148 \end_inset 
10149
10150  routines.
10151  By default, the compiler will place the stack after the last byte of allocated
10152  memory for variables.
10153  For example, if the first 2 banks of registers are used, and only four
10154  bytes are used for 
10155 \emph on 
10156 data
10157 \emph default 
10158  variables, it will position the base of the internal stack at address 20
10159  (0x14).
10160  This implies that as the stack
10161 \begin_inset LatexCommand \index{stack}
10162
10163 \end_inset 
10164
10165  grows, it will use up the remaining register banks, and the 16 bytes used
10166  by the 128 bit variables, and 80 bytes for general purpose use.
10167  If any bit variables are used, the data variables will be placed in unused
10168  register banks and after the byte holding the last bit variable.
10169  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10170  (two bytes used), 
10171 \emph on 
10172 data
10173 \emph default 
10174  variables will be placed starting from address 0x10 to 0x20 and continue
10175  at address 0x22.
10176  You can also use -
10177 \begin_inset ERT
10178 status Collapsed
10179
10180 \layout Standard
10181
10182 \backslash 
10183 /
10184 \end_inset 
10185
10186 -data-loc
10187 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10188
10189 \end_inset 
10190
10191  to specify the start address of the 
10192 \emph on 
10193 data
10194 \emph default 
10195  and -
10196 \begin_inset ERT
10197 status Collapsed
10198
10199 \layout Standard
10200
10201 \backslash 
10202 /
10203 \end_inset 
10204
10205 -iram-size
10206 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10207
10208 \end_inset 
10209
10210  to specify the size of the total internal RAM (
10211 \emph on 
10212 data
10213 \emph default 
10214 +
10215 \emph on 
10216 idata
10217 \emph default 
10218 ).
10219  
10220 \newline 
10221
10222 \layout Standard
10223
10224 By default the 8051 linker will place the stack after the last byte of (i)data
10225  variables.
10226  Option -
10227 \begin_inset ERT
10228 status Collapsed
10229
10230 \layout Standard
10231
10232 \backslash 
10233 /
10234 \end_inset 
10235
10236 -stack-loc
10237 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10238
10239 \end_inset 
10240
10241  allows you to specify the start of the stack, i.e.
10242  you could start it after any data in the general purpose area.
10243  If your microcontroller has additional indirectly addressable internal
10244  RAM (
10245 \emph on 
10246 idata
10247 \emph default 
10248 ) you can place the stack on it.
10249  You may also need to use -
10250 \begin_inset ERT
10251 status Collapsed
10252
10253 \layout Standard
10254
10255 \backslash 
10256 /
10257 \end_inset 
10258
10259 -xdata-loc
10260 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10261
10262 \end_inset 
10263
10264  to set the start address of the external RAM (
10265 \emph on 
10266 xdata
10267 \emph default 
10268 ) and -
10269 \begin_inset ERT
10270 status Collapsed
10271
10272 \layout Standard
10273
10274 \backslash 
10275 /
10276 \end_inset 
10277
10278 -xram-size
10279 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10280
10281 \end_inset 
10282
10283  to specify its size.
10284  Same goes for the code memory, using -
10285 \begin_inset ERT
10286 status Collapsed
10287
10288 \layout Standard
10289
10290 \backslash 
10291 /
10292 \end_inset 
10293
10294 -code-loc
10295 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10296
10297 \end_inset 
10298
10299  and -
10300 \begin_inset ERT
10301 status Collapsed
10302
10303 \layout Standard
10304
10305 \backslash 
10306 /
10307 \end_inset 
10308
10309 -code-size
10310 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10311
10312 \end_inset 
10313
10314 .
10315  If in doubt, don't specify any options and see if the resulting memory
10316  layout is appropriate, then you can adjust it.
10317 \layout Standard
10318 \added_space_bottom bigskip 
10319 The linker generates two files with memory allocation information.
10320  The first, with extension .map
10321 \begin_inset LatexCommand \index{<file>.map}
10322
10323 \end_inset 
10324
10325  shows all the variables and segments.
10326  The second with extension .mem
10327 \begin_inset LatexCommand \index{<file>.mem}
10328
10329 \end_inset 
10330
10331  shows the final memory layout.
10332  The linker will complain either if memory segments overlap, there is not
10333  enough memory, or there is not enough space for stack.
10334  If you get any linking warnings and/or errors related to stack or segments
10335  allocation, take a look at either the .map or .mem files to find out what
10336  the problem is.
10337  The .mem file may even suggest a solution to the problem.
10338 \layout Subsection
10339
10340 Z80/Z180 Storage Class
10341 \begin_inset LatexCommand \index{Z80!Storage class}
10342
10343 \end_inset 
10344
10345  Language Extensions
10346 \layout Subsubsection
10347
10348 sfr
10349 \begin_inset LatexCommand \index{sfr}
10350
10351 \end_inset 
10352
10353
10354 \begin_inset LatexCommand \index{\_\_sfr}
10355
10356 \end_inset 
10357
10358  (in/out to 8-bit addresses)
10359 \layout Standard
10360
10361 The Z80
10362 \begin_inset LatexCommand \index{Z80}
10363
10364 \end_inset 
10365
10366  family has separate address spaces for memory and 
10367 \emph on 
10368 i
10369 \emph default 
10370 nput/
10371 \emph on 
10372 o
10373 \emph default 
10374 utput memory.
10375  I/O memory
10376 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10377
10378 \end_inset 
10379
10380
10381 \begin_inset LatexCommand \index{Z80!I/O memory}
10382
10383 \end_inset 
10384
10385
10386 \begin_inset LatexCommand \index{Z180!I/O memory}
10387
10388 \end_inset 
10389
10390  is accessed with special instructions, e.g.:
10391 \layout Verse
10392
10393
10394 \family typewriter 
10395 sfr at 0x78 IoPort;\SpecialChar ~
10396 \SpecialChar ~
10397 /* define a var in I/O space at 78h called IoPort */
10398  
10399 \layout Standard
10400
10401 Writing 0x01 to this variable generates the assembly code:
10402 \layout Verse
10403
10404
10405 \family typewriter 
10406 3E 01\SpecialChar ~
10407 \SpecialChar ~
10408 \SpecialChar ~
10409 \SpecialChar ~
10410 \SpecialChar ~
10411 \SpecialChar ~
10412 ld a,#0x01
10413 \newline 
10414 D3 78\SpecialChar ~
10415 \SpecialChar ~
10416 \SpecialChar ~
10417 \SpecialChar ~
10418 \SpecialChar ~
10419 \SpecialChar ~
10420 out (_IoPort),a 
10421 \layout Subsubsection
10422
10423 banked sfr
10424 \begin_inset LatexCommand \index{sfr}
10425
10426 \end_inset 
10427
10428
10429 \begin_inset LatexCommand \index{\_\_sfr}
10430
10431 \end_inset 
10432
10433  (in/out to 16-bit addresses)
10434 \layout Standard
10435
10436 The keyword 
10437 \emph on 
10438 banked
10439 \emph default 
10440  is used to support 16 bit addresses in I/O memory e.g.:
10441 \layout Verse
10442
10443
10444 \family typewriter 
10445 sfr banked at
10446 \begin_inset LatexCommand \index{at}
10447
10448 \end_inset 
10449
10450
10451 \begin_inset LatexCommand \index{\_\_at}
10452
10453 \end_inset 
10454
10455  0x123 IoPort; 
10456 \layout Standard
10457
10458 Writing 0x01 to this variable generates the assembly code:
10459 \layout Verse
10460
10461
10462 \family typewriter 
10463 01 23 01\SpecialChar ~
10464 \SpecialChar ~
10465 \SpecialChar ~
10466 ld bc,#_IoPort
10467 \newline 
10468 3E 01\SpecialChar ~
10469 \SpecialChar ~
10470 \SpecialChar ~
10471 \SpecialChar ~
10472 \SpecialChar ~
10473 \SpecialChar ~
10474 ld a,#0x01 
10475 \newline 
10476 ED 79\SpecialChar ~
10477 \SpecialChar ~
10478 \SpecialChar ~
10479 \SpecialChar ~
10480 \SpecialChar ~
10481 \SpecialChar ~
10482 out (c),a 
10483 \layout Subsubsection
10484
10485 sfr
10486 \begin_inset LatexCommand \index{sfr}
10487
10488 \end_inset 
10489
10490
10491 \begin_inset LatexCommand \index{\_\_sfr}
10492
10493 \end_inset 
10494
10495  (in0/out0 to 8 bit addresses on Z180
10496 \begin_inset LatexCommand \index{Z180}
10497
10498 \end_inset 
10499
10500 /HD64180
10501 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10502
10503 \end_inset 
10504
10505 )
10506 \layout Standard
10507 \added_space_bottom bigskip 
10508 The compiler option -
10509 \begin_inset ERT
10510 status Collapsed
10511
10512 \layout Standard
10513
10514 \backslash 
10515 /
10516 \end_inset 
10517
10518 -portmode
10519 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10520
10521 \end_inset 
10522
10523 =180 (80) and a compiler #pragma\SpecialChar ~
10524 portmode
10525 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10526
10527 \end_inset 
10528
10529 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10530 ns 
10531 \family typewriter 
10532 in0/out0
10533 \family default 
10534  instead of 
10535 \family typewriter 
10536 in/out
10537 \family default 
10538 .
10539  If you include the file z180.h this will be set automatically.
10540 \layout Subsection
10541
10542 HC08 Storage Class
10543 \begin_inset LatexCommand \index{HC08!Storage class}
10544
10545 \end_inset 
10546
10547  Language Extensions
10548 \layout Subsubsection
10549
10550 data
10551 \begin_inset LatexCommand \index{data (hc08 storage class)}
10552
10553 \end_inset 
10554
10555
10556 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10557
10558 \end_inset 
10559
10560  
10561 \layout Standard
10562
10563 The data storage class declares a variable that resides in the first 256
10564  bytes of memory (the direct page).
10565  The HC08
10566 \begin_inset LatexCommand \index{HC08}
10567
10568 \end_inset 
10569
10570  is most efficient at accessing variables (especially pointers) stored here.
10571 \layout Subsubsection
10572
10573 xdata
10574 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10575
10576 \end_inset 
10577
10578
10579 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10580
10581 \end_inset 
10582
10583  
10584 \layout Standard
10585 \added_space_bottom bigskip 
10586 The xdata storage class declares a variable that can reside anywhere in
10587  memory.
10588  This is the default if no storage class is specified.
10589  
10590 \layout Section
10591
10592 Absolute Addressing
10593 \begin_inset LatexCommand \index{Absolute addressing}
10594
10595 \end_inset 
10596
10597
10598 \layout Standard
10599
10600 Data items can be assigned an absolute address with the 
10601 \emph on 
10602 at
10603 \begin_inset LatexCommand \index{at}
10604
10605 \end_inset 
10606
10607
10608 \begin_inset LatexCommand \index{\_\_at}
10609
10610 \end_inset 
10611
10612  <address>
10613 \emph default 
10614  keyword, in addition to a storage class, e.g.:
10615 \layout Verse
10616
10617
10618 \family typewriter 
10619 xdata
10620 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10621
10622 \end_inset 
10623
10624
10625 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10626
10627 \end_inset 
10628
10629  at
10630 \begin_inset LatexCommand \index{at}
10631
10632 \end_inset 
10633
10634
10635 \begin_inset LatexCommand \index{\_\_at}
10636
10637 \end_inset 
10638
10639  0x7ffe unsigned int chksum;
10640 \layout Standard
10641
10642 or, better conforming to ISO/IEC 9899 C:
10643 \layout Verse
10644
10645
10646 \family typewriter 
10647 __xdata __at (0x7ffe) unsigned int chksum;
10648 \layout Standard
10649
10650 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10651  of the external ram.
10652  The compiler does 
10653 \emph on 
10654 not
10655 \emph default 
10656  reserve any space for variables declared in this way
10657 \begin_inset Marginal
10658 collapsed true
10659
10660 \layout Standard
10661
10662
10663 \series bold 
10664 \SpecialChar ~
10665 !
10666 \end_inset 
10667
10668  (they are implemented with an equate in the assembler).
10669  Thus it is left to the programmer to make sure there are no overlaps with
10670  other variables that are declared without the absolute address.
10671  The assembler listing file (.lst
10672 \begin_inset LatexCommand \index{<file>.lst}
10673
10674 \end_inset 
10675
10676 ) and the linker output files (.rst
10677 \begin_inset LatexCommand \index{<file>.rst}
10678
10679 \end_inset 
10680
10681 ) and (.map
10682 \begin_inset LatexCommand \index{<file>.map}
10683
10684 \end_inset 
10685
10686 ) are good places to look for such overlaps.
10687  Variables with an absolute address are 
10688 \emph on 
10689 not
10690 \begin_inset Marginal
10691 collapsed true
10692
10693 \layout Standard
10694
10695
10696 \series bold 
10697 \SpecialChar ~
10698 !
10699 \end_inset 
10700
10701
10702 \emph default 
10703  initialized
10704 \begin_inset LatexCommand \index{Variable initialization}
10705
10706 \end_inset 
10707
10708 .
10709 \layout Standard
10710
10711 In case of memory mapped I/O devices the keyword 
10712 \emph on 
10713 volatile
10714 \emph default 
10715  has to be used to tell the compiler that accesses might not be removed:
10716 \layout Verse
10717
10718
10719 \family typewriter 
10720 volatile
10721 \begin_inset LatexCommand \index{volatile}
10722
10723 \end_inset 
10724
10725  __xdata
10726 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10727
10728 \end_inset 
10729
10730  __at
10731 \begin_inset LatexCommand \index{at}
10732
10733 \end_inset 
10734
10735  (0x8000) unsigned char PORTA_8255;
10736 \layout Standard
10737
10738 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10739 r) array
10740 \family typewriter 
10741 \size footnotesize 
10742
10743 \begin_inset LatexCommand \index{Aligned array}
10744
10745 \end_inset 
10746
10747
10748 \family default 
10749 \size default 
10750  starts at a block (256 byte) boundary
10751 \begin_inset LatexCommand \index{block boundary}
10752
10753 \end_inset 
10754
10755  (section 
10756 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10757
10758 \end_inset 
10759
10760  has an example).
10761 \newline 
10762 Absolute addresses can be specified for variables in all storage classes,
10763  e.g.:
10764 \layout Verse
10765
10766
10767 \family typewriter 
10768 __bit
10769 \begin_inset LatexCommand \index{bit}
10770
10771 \end_inset 
10772
10773  __at
10774 \begin_inset LatexCommand \index{at}
10775
10776 \end_inset 
10777
10778  (0x02) bvar;
10779 \layout Standard
10780
10781 The above example will allocate the variable at offset 0x02 in the bit-addressab
10782 le space.
10783  There is no real advantage to assigning absolute addresses to variables
10784  in this manner, unless you want strict control over all the variables allocated.
10785  One possible use would be to write hardware portable code.
10786  For example, if you have a routine that uses one or more of the microcontroller
10787  I/O pins, and such pins are different for two different hardwares, you
10788  can declare the I/O pins in your routine using:
10789 \layout Verse
10790
10791
10792 \family typewriter 
10793 extern volatile
10794 \begin_inset LatexCommand \index{volatile}
10795
10796 \end_inset 
10797
10798  __bit MOSI;\SpecialChar ~
10799 \SpecialChar ~
10800 \SpecialChar ~
10801 \SpecialChar ~
10802 /* master out, slave in */
10803 \newline 
10804 extern volatile __bit MISO;\SpecialChar ~
10805 \SpecialChar ~
10806 \SpecialChar ~
10807 \SpecialChar ~
10808 /* master in, slave out */
10809 \newline 
10810 extern volatile __bit MCLK;\SpecialChar ~
10811 \SpecialChar ~
10812 \SpecialChar ~
10813 \SpecialChar ~
10814 /* master clock */
10815 \newline 
10816
10817 \newline 
10818 /* Input and Output of a byte on a 3-wire serial bus.
10819 \newline 
10820 \SpecialChar ~
10821 \SpecialChar ~
10822 \SpecialChar ~
10823 If needed adapt polarity of clock, polarity of data and bit order
10824 \newline 
10825 \SpecialChar ~
10826 */
10827 \newline 
10828 unsigned char spi_io(unsigned char out_byte) 
10829 \newline 
10830
10831 \newline 
10832 \SpecialChar ~
10833 \SpecialChar ~
10834 \SpecialChar ~
10835 \SpecialChar ~
10836 unsigned char i=8;
10837 \newline 
10838 \SpecialChar ~
10839 \SpecialChar ~
10840 \SpecialChar ~
10841 \SpecialChar ~
10842 do { 
10843 \newline 
10844 \SpecialChar ~
10845 \SpecialChar ~
10846 \SpecialChar ~
10847 \SpecialChar ~
10848 \SpecialChar ~
10849 \SpecialChar ~
10850 \SpecialChar ~
10851 \SpecialChar ~
10852 MOSI = out_byte & 0x80; 
10853 \newline 
10854 \SpecialChar ~
10855 \SpecialChar ~
10856 \SpecialChar ~
10857 \SpecialChar ~
10858 \SpecialChar ~
10859 \SpecialChar ~
10860 \SpecialChar ~
10861 \SpecialChar ~
10862 out_byte <<= 1;
10863 \newline 
10864 \SpecialChar ~
10865 \SpecialChar ~
10866 \SpecialChar ~
10867 \SpecialChar ~
10868 \SpecialChar ~
10869 \SpecialChar ~
10870 \SpecialChar ~
10871 \SpecialChar ~
10872 MCLK = 1; 
10873 \newline 
10874 \SpecialChar ~
10875 \SpecialChar ~
10876 \SpecialChar ~
10877 \SpecialChar ~
10878 \SpecialChar ~
10879 \SpecialChar ~
10880 \SpecialChar ~
10881 \SpecialChar ~
10882 /* _asm nop _endasm; */\SpecialChar ~
10883 \SpecialChar ~
10884 \SpecialChar ~
10885 \SpecialChar ~
10886 \SpecialChar ~
10887 \SpecialChar ~
10888 \SpecialChar ~
10889 \SpecialChar ~
10890 /* for slow peripherals */
10891 \newline 
10892 \SpecialChar ~
10893 \SpecialChar ~
10894 \SpecialChar ~
10895 \SpecialChar ~
10896 \SpecialChar ~
10897 \SpecialChar ~
10898 \SpecialChar ~
10899 \SpecialChar ~
10900 if(MISO) 
10901 \newline 
10902 \SpecialChar ~
10903 \SpecialChar ~
10904 \SpecialChar ~
10905 \SpecialChar ~
10906 \SpecialChar ~
10907 \SpecialChar ~
10908 \SpecialChar ~
10909 \SpecialChar ~
10910 \SpecialChar ~
10911 \SpecialChar ~
10912 \SpecialChar ~
10913 \SpecialChar ~
10914 out_byte += 1; 
10915 \newline 
10916 \SpecialChar ~
10917 \SpecialChar ~
10918 \SpecialChar ~
10919 \SpecialChar ~
10920 \SpecialChar ~
10921 \SpecialChar ~
10922 \SpecialChar ~
10923 \SpecialChar ~
10924 MCLK = 0; 
10925 \newline 
10926 \SpecialChar ~
10927 \SpecialChar ~
10928 \SpecialChar ~
10929 \SpecialChar ~
10930 } while(--i);
10931 \newline 
10932 \SpecialChar ~
10933 \SpecialChar ~
10934 \SpecialChar ~
10935 \SpecialChar ~
10936 return out_byte; 
10937 \newline 
10938 }
10939 \layout Standard
10940
10941 Then, someplace in the code for the first hardware you would use
10942 \layout Verse
10943
10944
10945 \family typewriter 
10946 __bit __at
10947 \begin_inset LatexCommand \index{at}
10948
10949 \end_inset 
10950
10951
10952 \begin_inset LatexCommand \index{\_\_at}
10953
10954 \end_inset 
10955
10956  (0x80) MOSI;\SpecialChar ~
10957 \SpecialChar ~
10958 \SpecialChar ~
10959 \SpecialChar ~
10960 /* I/O port 0, bit 0 */
10961 \newline 
10962 __bit __at (0x81) MISO;\SpecialChar ~
10963 \SpecialChar ~
10964 \SpecialChar ~
10965 \SpecialChar ~
10966 /* I/O port 0, bit 1 */
10967 \newline 
10968 __bit __at (0x82) MCLK;\SpecialChar ~
10969 \SpecialChar ~
10970 \SpecialChar ~
10971 \SpecialChar ~
10972 /* I/O port 0, bit 2 */
10973 \layout Standard
10974
10975 Similarly, for the second hardware you would use
10976 \layout Verse
10977
10978
10979 \family typewriter 
10980 __bit __at (0x83) MOSI;\SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 /* I/O port 0, bit 3 */
10985 \newline 
10986 __bit __at (0x91) MISO;\SpecialChar ~
10987 \SpecialChar ~
10988 \SpecialChar ~
10989 \SpecialChar ~
10990 /* I/O port 1, bit 1 */
10991 \newline 
10992 __bit
10993 \begin_inset LatexCommand \index{bit}
10994
10995 \end_inset 
10996
10997  __at (0x92) MCLK;\SpecialChar ~
10998 \SpecialChar ~
10999 \SpecialChar ~
11000 \SpecialChar ~
11001 /* I/O port 1, bit 2 */
11002 \layout Standard
11003 \added_space_bottom bigskip 
11004 and you can use the same hardware dependent routine without changes, as
11005  for example in a library.
11006  This is somehow similar to sbit, but only one absolute address has to be
11007  specified in the whole project.
11008 \layout Section
11009
11010 Parameters
11011 \begin_inset LatexCommand \index{Parameters}
11012
11013 \end_inset 
11014
11015
11016 \begin_inset LatexCommand \index{function parameter}
11017
11018 \end_inset 
11019
11020  & Local Variables
11021 \begin_inset LatexCommand \index{local variables}
11022
11023 \end_inset 
11024
11025
11026 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11027
11028 \end_inset 
11029
11030
11031 \layout Standard
11032
11033 Automatic (local) variables and parameters to functions can either be placed
11034  on the stack or in data-space.
11035  The default action of the compiler is to place these variables in the internal
11036  RAM (for small model) or external RAM (for large model).
11037  This in fact makes them similar to 
11038 \emph on 
11039 static
11040 \begin_inset LatexCommand \index{static}
11041
11042 \end_inset 
11043
11044
11045 \emph default 
11046  so by default functions are non-reentrant
11047 \begin_inset LatexCommand \index{reentrant}
11048
11049 \end_inset 
11050
11051 .
11052  
11053 \newline 
11054
11055 \newline 
11056 They can be placed on the stack
11057 \begin_inset LatexCommand \index{stack}
11058
11059 \end_inset 
11060
11061  by using the
11062 \emph on 
11063  -
11064 \begin_inset ERT
11065 status Collapsed
11066
11067 \layout Standard
11068
11069 \backslash 
11070 /
11071 \end_inset 
11072
11073 -stack-auto
11074 \begin_inset LatexCommand \index{-\/-stack-auto}
11075
11076 \end_inset 
11077
11078
11079 \emph default 
11080  option, by using 
11081 \emph on 
11082 #pragma\SpecialChar ~
11083 stackauto
11084 \emph default 
11085
11086 \begin_inset LatexCommand \index{\#pragma stackauto}
11087
11088 \end_inset 
11089
11090  or by using the 
11091 \emph on 
11092 reentrant
11093 \begin_inset LatexCommand \index{reentrant}
11094
11095 \end_inset 
11096
11097
11098 \emph default 
11099  keyword in the function declaration, e.g.:
11100 \layout Verse
11101
11102
11103 \family typewriter 
11104 unsigned char foo(char i) __reentrant 
11105 \newline 
11106
11107 \newline 
11108 \SpecialChar ~
11109 \SpecialChar ~
11110 \SpecialChar ~
11111 \SpecialChar ~
11112 ...
11113  
11114 \newline 
11115 }
11116 \layout Standard
11117
11118 Since stack space on 8051 is limited, the 
11119 \emph on 
11120 reentrant 
11121 \emph default 
11122 keyword or the
11123 \emph on 
11124  -
11125 \begin_inset ERT
11126 status Collapsed
11127
11128 \layout Standard
11129
11130 \backslash 
11131 /
11132 \end_inset 
11133
11134 -stack-auto
11135 \emph default 
11136  option should be used sparingly.
11137  Note that the reentrant keyword just means that the parameters & local
11138  variables will be allocated to the stack, it 
11139 \emph on 
11140 does not
11141 \emph default 
11142  mean that the function is register bank
11143 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11144
11145 \end_inset 
11146
11147  independent.
11148 \newline 
11149
11150 \newline 
11151 Local variables
11152 \begin_inset LatexCommand \index{local variables}
11153
11154 \end_inset 
11155
11156  can be assigned storage classes and absolute
11157 \begin_inset LatexCommand \index{Absolute addressing}
11158
11159 \end_inset 
11160
11161  addresses, e.g.: 
11162 \layout Verse
11163
11164
11165 \family typewriter 
11166 unsigned char foo() 
11167 \newline 
11168 {
11169 \newline 
11170 \SpecialChar ~
11171 \SpecialChar ~
11172 \SpecialChar ~
11173 \SpecialChar ~
11174 __xdata unsigned char i;
11175 \newline 
11176 \SpecialChar ~
11177 \SpecialChar ~
11178 \SpecialChar ~
11179 \SpecialChar ~
11180 __bit bvar;
11181 \newline 
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 \SpecialChar ~
11186 __data __at
11187 \begin_inset LatexCommand \index{at}
11188
11189 \end_inset 
11190
11191  (0x31) unsigned char j;
11192 \newline 
11193 \SpecialChar ~
11194 \SpecialChar ~
11195 \SpecialChar ~
11196 \SpecialChar ~
11197 ...
11198  
11199 \newline 
11200 }
11201 \layout Standard
11202
11203 In the above example the variable 
11204 \emph on 
11205 i
11206 \emph default 
11207  will be allocated in the external ram, 
11208 \emph on 
11209 bvar
11210 \emph default 
11211  in bit addressable space and
11212 \emph on 
11213  j
11214 \emph default 
11215  in internal ram.
11216  When compiled with 
11217 \emph on 
11218 -
11219 \begin_inset ERT
11220 status Collapsed
11221
11222 \layout Standard
11223
11224 \backslash 
11225 /
11226 \end_inset 
11227
11228 -stack-auto
11229 \emph default 
11230  or when a function is declared as 
11231 \emph on 
11232 reentrant
11233 \emph default 
11234  this should only be done for static variables.
11235 \layout Standard
11236
11237 Parameters
11238 \begin_inset LatexCommand \index{function parameter}
11239
11240 \end_inset 
11241
11242  however are not allowed any storage class
11243 \begin_inset LatexCommand \index{Storage class}
11244
11245 \end_inset 
11246
11247 , (storage classes for parameters will be ignored), their allocation is
11248  governed by the memory model in use, and the reentrancy options.
11249 \layout Standard
11250
11251 It is however allowed to use bit parameters in reentrant functions and also
11252  non-static local bit variables are supported.
11253  Efficient use is limited to 8 semi-bitregisters in bit space.
11254  They are pushed and popped to stack
11255 \begin_inset LatexCommand \index{stack}
11256
11257 \end_inset 
11258
11259  as a single byte just like the normal registers.
11260 \layout Section
11261
11262 Overlaying
11263 \begin_inset LatexCommand \label{sub:Overlaying}
11264
11265 \end_inset 
11266
11267
11268 \begin_inset LatexCommand \index{Overlaying}
11269
11270 \end_inset 
11271
11272
11273 \layout Standard
11274
11275 For non-reentrant
11276 \begin_inset LatexCommand \index{reentrant}
11277
11278 \end_inset 
11279
11280  functions SDCC will try to reduce internal ram space usage by overlaying
11281  parameters and local variables of a function (if possible).
11282  Parameters and local variables
11283 \begin_inset LatexCommand \index{local variables}
11284
11285 \end_inset 
11286
11287  of a function will be allocated to an overlayable segment if the function
11288  has 
11289 \emph on 
11290 no other function calls and the function is non-reentrant and the memory
11291  model
11292 \begin_inset LatexCommand \index{Memory model}
11293
11294 \end_inset 
11295
11296  is small.
11297
11298 \emph default 
11299  If an explicit storage class
11300 \begin_inset LatexCommand \index{Storage class}
11301
11302 \end_inset 
11303
11304  is specified for a local variable, it will NOT be overlayed.
11305 \layout Standard
11306
11307 Note that the compiler (not the linkage editor) makes the decision for overlayin
11308 g the data items.
11309  Functions that are called from an interrupt service routine
11310 \begin_inset Marginal
11311 collapsed true
11312
11313 \layout Standard
11314
11315
11316 \series bold 
11317 !
11318 \end_inset 
11319
11320  should be preceded by a #pragma\SpecialChar ~
11321 nooverlay
11322 \begin_inset LatexCommand \index{\#pragma nooverlay}
11323
11324 \end_inset 
11325
11326  if they are not reentrant.
11327 \layout Standard
11328
11329 Also note that the compiler does not do any processing of inline assembler
11330  code, so the compiler might incorrectly assign local variables and parameters
11331  of a function into the overlay segment if the inline assembler code calls
11332  other c-functions that might use the overlay.
11333  In that case the #pragma\SpecialChar ~
11334 nooverlay should be used.
11335 \layout Standard
11336
11337 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11338 tion
11339 \begin_inset LatexCommand \index{Multiplication}
11340
11341 \end_inset 
11342
11343  or division
11344 \begin_inset LatexCommand \index{Division}
11345
11346 \end_inset 
11347
11348  will NOT be overlayed since these are implemented using external functions,
11349  e.g.:
11350 \layout Verse
11351
11352
11353 \family typewriter 
11354 #pragma save 
11355 \newline 
11356 #pragma nooverlay
11357 \begin_inset LatexCommand \index{\#pragma nooverlay}
11358
11359 \end_inset 
11360
11361  
11362 \newline 
11363 void set_error(unsigned char errcd) 
11364 \newline 
11365 {
11366 \newline 
11367 \SpecialChar ~
11368 \SpecialChar ~
11369 \SpecialChar ~
11370 \SpecialChar ~
11371 P3 = errcd;
11372 \newline 
11373
11374 \newline 
11375 #pragma restore 
11376 \newline 
11377
11378 \newline 
11379 void some_isr () __interrupt
11380 \begin_inset LatexCommand \index{interrupt}
11381
11382 \end_inset 
11383
11384  (2)
11385 \newline 
11386 {
11387 \newline 
11388 \SpecialChar ~
11389 \SpecialChar ~
11390 \SpecialChar ~
11391 \SpecialChar ~
11392 ...
11393 \newline 
11394 \SpecialChar ~
11395 \SpecialChar ~
11396 \SpecialChar ~
11397 \SpecialChar ~
11398 set_error(10);
11399 \newline 
11400 \SpecialChar ~
11401 \SpecialChar ~
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 ...
11405  
11406 \newline 
11407 }
11408 \layout Standard
11409 \added_space_bottom bigskip 
11410 In the above example the parameter 
11411 \emph on 
11412 errcd
11413 \emph default 
11414  for the function 
11415 \emph on 
11416 set_error
11417 \emph default 
11418  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11419 nooverlay was
11420  not present, this could cause unpredictable runtime behavior when called
11421  from an interrupt service routine.
11422  The #pragma\SpecialChar ~
11423 nooverlay ensures that the parameters and local variables for
11424  the function are NOT overlayed.
11425 \layout Section
11426
11427 Interrupt Service Routines
11428 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11429
11430 \end_inset 
11431
11432
11433 \layout Subsection
11434
11435 General Information
11436 \layout Standard
11437
11438 SDCC allows 
11439 \emph on 
11440 i
11441 \emph default 
11442 nterrupt 
11443 \emph on 
11444 s
11445 \emph default 
11446 ervice 
11447 \emph on 
11448 r
11449 \emph default 
11450 outines to be coded in C, with some extended keywords.
11451 \layout Verse
11452
11453
11454 \family typewriter 
11455 void timer_isr (void) __interrupt (1) __using (1) 
11456 \newline 
11457
11458 \newline 
11459 \SpecialChar ~
11460 \SpecialChar ~
11461 \SpecialChar ~
11462 \SpecialChar ~
11463 ...
11464  
11465 \newline 
11466 }
11467 \layout Standard
11468
11469 The optional number following the 
11470 \emph on 
11471 interrupt
11472 \begin_inset LatexCommand \index{interrupt}
11473
11474 \end_inset 
11475
11476
11477 \begin_inset LatexCommand \index{\_\_interrupt}
11478
11479 \end_inset 
11480
11481
11482 \emph default 
11483  keyword is the interrupt number this routine will service.
11484  When present, the compiler will insert a call to this routine in the interrupt
11485  vector table for the interrupt number specified.
11486  If you have multiple source files in your project, interrupt service routines
11487  can be present in any of them, but a prototype of the isr MUST be present
11488  or included in the file that contains the function 
11489 \emph on 
11490 main
11491 \emph default 
11492 .
11493  The optional 
11494 \emph on 
11495 using
11496 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11497
11498 \end_inset 
11499
11500
11501 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11502
11503 \end_inset 
11504
11505
11506 \emph default 
11507  keyword can be used to tell the compiler to use the specified register
11508  bank (8051 specific) when generating code for this function.
11509  
11510 \newline 
11511
11512 \layout Standard
11513
11514 Interrupt service routines open the door for some very interesting bugs:
11515 \newline 
11516 If an interrupt service routine changes variables which are accessed by
11517  other functions these variables have to be declared 
11518 \emph on 
11519 volatile
11520 \emph default 
11521
11522 \begin_inset LatexCommand \index{volatile}
11523
11524 \end_inset 
11525
11526 .
11527  
11528 \layout Standard
11529
11530 If the access to these variables is not 
11531 \emph on 
11532 atomic
11533 \begin_inset LatexCommand \index{atomic}
11534
11535 \end_inset 
11536
11537
11538 \emph default 
11539  (i.e.
11540  the processor needs more than one instruction for the access and could
11541  be interrupted while accessing the variable) the interrupt must be disabled
11542  during the access to avoid inconsistent data.
11543  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
11544  and should be protected by disabling interrupts.
11545  You're not automatically on the safe side if you use 8 bit variables though.
11546  We need an example here: f.e.
11547  on the 8051 the harmless looking 
11548 \begin_inset Quotes srd
11549 \end_inset 
11550
11551
11552 \family typewriter 
11553 flags\SpecialChar ~
11554 |=\SpecialChar ~
11555 0x80;
11556 \family default 
11557
11558 \begin_inset Quotes sld
11559 \end_inset 
11560
11561  is not atomic if 
11562 \family typewriter 
11563 flags
11564 \family default 
11565  resides in xdata.
11566  Setting 
11567 \begin_inset Quotes srd
11568 \end_inset 
11569
11570
11571 \family typewriter 
11572 flags\SpecialChar ~
11573 |=\SpecialChar ~
11574 0x40;
11575 \family default 
11576
11577 \begin_inset Quotes sld
11578 \end_inset 
11579
11580  from within an interrupt routine might get lost if the interrupt occurs
11581  at the wrong time.
11582  
11583 \begin_inset Quotes sld
11584 \end_inset 
11585
11586
11587 \family typewriter 
11588 counter\SpecialChar ~
11589 +=\SpecialChar ~
11590 8;
11591 \family default 
11592
11593 \begin_inset Quotes srd
11594 \end_inset 
11595
11596  is not atomic on the 8051 even if 
11597 \family typewriter 
11598 counter
11599 \family default 
11600  is located in data memory.
11601  Bugs like these are hard to reproduce and can cause a lot of trouble.
11602  
11603 \layout Standard
11604
11605 The return address and the registers used in the interrupt service routine
11606  are saved on the stack
11607 \begin_inset LatexCommand \index{stack}
11608
11609 \end_inset 
11610
11611  so there must be sufficient stack space.
11612  If there isn't variables or registers (or even the return address itself)
11613  will be corrupted.
11614  This 
11615 \emph on 
11616 stack overflow
11617 \emph default 
11618
11619 \begin_inset LatexCommand \index{stack overflow}
11620
11621 \end_inset 
11622
11623  is most likely to happen if the interrupt occurs during the 
11624 \begin_inset Quotes sld
11625 \end_inset 
11626
11627 deepest
11628 \begin_inset Quotes srd
11629 \end_inset 
11630
11631  subroutine when the stack is already in use for f.e.
11632  many return addresses.
11633 \layout Standard
11634
11635 A special note here, int (16 bit) and long (32 bit) integer division
11636 \begin_inset LatexCommand \index{Division}
11637
11638 \end_inset 
11639
11640 , multiplication
11641 \begin_inset LatexCommand \index{Multiplication}
11642
11643 \end_inset 
11644
11645  & modulus
11646 \begin_inset LatexCommand \index{Modulus}
11647
11648 \end_inset 
11649
11650  and floating-point
11651 \begin_inset LatexCommand \index{Floating point support}
11652
11653 \end_inset 
11654
11655  operations are implemented using external support routines developed in
11656  ANSI-C.
11657  If an interrupt service routine needs to do any of these operations then
11658  the support routines (as mentioned in a following section) will have to
11659  be recompiled using the
11660 \emph on 
11661  -
11662 \begin_inset ERT
11663 status Collapsed
11664
11665 \layout Standard
11666
11667 \backslash 
11668 /
11669 \end_inset 
11670
11671 -stack-auto
11672 \begin_inset LatexCommand \index{-\/-stack-auto}
11673
11674 \end_inset 
11675
11676
11677 \emph default 
11678  option and the source file will need to be compiled using the 
11679 \emph on 
11680 -
11681 \begin_inset ERT
11682 status Collapsed
11683
11684 \layout Standard
11685
11686 \backslash 
11687 /
11688 \end_inset 
11689
11690 -int-long-reent
11691 \emph default 
11692
11693 \begin_inset LatexCommand \index{-\/-int-long-reent}
11694
11695 \end_inset 
11696
11697  compiler option.
11698  Note, the type promotion
11699 \begin_inset LatexCommand \index{type promotion}
11700
11701 \end_inset 
11702
11703  required by ANSI C can cause 16 bit routines to be used without the programmer
11704  being aware of it.
11705  
11706 \layout Standard
11707 \added_space_bottom bigskip 
11708 Calling other functions from an interrupt service routine is not recommended,
11709  avoid it if possible.
11710  Note that when some function is called from an interrupt service routine
11711  it should be preceded by a #pragma\SpecialChar ~
11712 nooverlay
11713 \begin_inset LatexCommand \index{\#pragma nooverlay}
11714
11715 \end_inset 
11716
11717  if it is not reentrant.
11718  Furthermore nonreentrant functions should not be called from the main program
11719  while the interrupt service routine might be active.
11720  They also must not be called from low priority interrupt service routines
11721  while a high priority interrupt service routine might be active.
11722  You could use semaphores or make the function
11723 \emph on 
11724  critical
11725 \emph default 
11726  if all parameters are passed in registers.
11727 \newline 
11728
11729 \newline 
11730 Also see section 
11731 \begin_inset LatexCommand \ref{sub:Overlaying}
11732
11733 \end_inset 
11734
11735 \SpecialChar ~
11736 about Overlaying and section 
11737 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11738
11739 \end_inset 
11740
11741 \SpecialChar ~
11742 about Functions using private register banks.
11743 \layout Subsection
11744
11745 MCS51/DS390 Interrupt Service Routines
11746 \layout Standard
11747
11748 Interrupt numbers and the corresponding address & descriptions for the Standard
11749  8051/8052 are listed below.
11750  SDCC will automatically adjust the interrupt vector table to the maximum
11751  interrupt number specified.
11752 \newline 
11753
11754 \layout Standard
11755 \align center 
11756
11757 \begin_inset  Tabular
11758 <lyxtabular version="3" rows="9" columns="3">
11759 <features>
11760 <column alignment="center" valignment="top" leftline="true" width="0in">
11761 <column alignment="left" valignment="top" leftline="true" width="0in">
11762 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
11763 <row topline="true" bottomline="true">
11764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11765 \begin_inset Text
11766
11767 \layout Standard
11768
11769 Interrupt #
11770 \end_inset 
11771 </cell>
11772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11773 \begin_inset Text
11774
11775 \layout Standard
11776
11777 Description
11778 \end_inset 
11779 </cell>
11780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11781 \begin_inset Text
11782
11783 \layout Standard
11784
11785 Vector Address
11786 \end_inset 
11787 </cell>
11788 </row>
11789 <row topline="true">
11790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11791 \begin_inset Text
11792
11793 \layout Standard
11794
11795 0
11796 \end_inset 
11797 </cell>
11798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11799 \begin_inset Text
11800
11801 \layout Standard
11802
11803 External 0
11804 \end_inset 
11805 </cell>
11806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11807 \begin_inset Text
11808
11809 \layout Standard
11810
11811 0x0003
11812 \end_inset 
11813 </cell>
11814 </row>
11815 <row topline="true">
11816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11817 \begin_inset Text
11818
11819 \layout Standard
11820
11821 1
11822 \end_inset 
11823 </cell>
11824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11825 \begin_inset Text
11826
11827 \layout Standard
11828
11829 Timer 0
11830 \end_inset 
11831 </cell>
11832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11833 \begin_inset Text
11834
11835 \layout Standard
11836
11837 0x000b
11838 \end_inset 
11839 </cell>
11840 </row>
11841 <row topline="true">
11842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11843 \begin_inset Text
11844
11845 \layout Standard
11846
11847 2
11848 \end_inset 
11849 </cell>
11850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11851 \begin_inset Text
11852
11853 \layout Standard
11854
11855 External 1
11856 \end_inset 
11857 </cell>
11858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11859 \begin_inset Text
11860
11861 \layout Standard
11862
11863 0x0013
11864 \end_inset 
11865 </cell>
11866 </row>
11867 <row topline="true">
11868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11869 \begin_inset Text
11870
11871 \layout Standard
11872
11873 3
11874 \end_inset 
11875 </cell>
11876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11877 \begin_inset Text
11878
11879 \layout Standard
11880
11881 Timer 1
11882 \end_inset 
11883 </cell>
11884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11885 \begin_inset Text
11886
11887 \layout Standard
11888
11889 0x001b
11890 \end_inset 
11891 </cell>
11892 </row>
11893 <row topline="true">
11894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11895 \begin_inset Text
11896
11897 \layout Standard
11898
11899 4
11900 \end_inset 
11901 </cell>
11902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11903 \begin_inset Text
11904
11905 \layout Standard
11906
11907 Serial
11908 \end_inset 
11909 </cell>
11910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11911 \begin_inset Text
11912
11913 \layout Standard
11914
11915 0x0023
11916 \end_inset 
11917 </cell>
11918 </row>
11919 <row topline="true">
11920 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11921 \begin_inset Text
11922
11923 \layout Standard
11924
11925 5
11926 \end_inset 
11927 </cell>
11928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11929 \begin_inset Text
11930
11931 \layout Standard
11932
11933 Timer 2 (8052)
11934 \end_inset 
11935 </cell>
11936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11937 \begin_inset Text
11938
11939 \layout Standard
11940
11941 0x002b
11942 \end_inset 
11943 </cell>
11944 </row>
11945 <row topline="true">
11946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11947 \begin_inset Text
11948
11949 \layout Standard
11950
11951 ...
11952 \end_inset 
11953 </cell>
11954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11955 \begin_inset Text
11956
11957 \layout Standard
11958
11959 \end_inset 
11960 </cell>
11961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11962 \begin_inset Text
11963
11964 \layout Standard
11965
11966 ...
11967 \end_inset 
11968 </cell>
11969 </row>
11970 <row topline="true" bottomline="true">
11971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11972 \begin_inset Text
11973
11974 \layout Standard
11975
11976 n
11977 \end_inset 
11978 </cell>
11979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11980 \begin_inset Text
11981
11982 \layout Standard
11983
11984 \end_inset 
11985 </cell>
11986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11987 \begin_inset Text
11988
11989 \layout Standard
11990
11991 0x0003 + 8*n
11992 \end_inset 
11993 </cell>
11994 </row>
11995 </lyxtabular>
11996
11997 \end_inset 
11998
11999
12000 \newline 
12001
12002 \layout Standard
12003
12004 If the interrupt service routine is defined without 
12005 \emph on 
12006 using
12007 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12008
12009 \end_inset 
12010
12011
12012 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12013
12014 \end_inset 
12015
12016
12017 \emph default 
12018  a register bank or with register bank 0 (
12019 \emph on 
12020 using
12021 \emph default 
12022  0), the compiler will save the registers used by itself on the stack upon
12023  entry and restore them at exit, however if such an interrupt service routine
12024  calls another function then the entire register bank will be saved on the
12025  stack.
12026  This scheme may be advantageous for small interrupt service routines which
12027  have low register usage.
12028 \layout Standard
12029 \added_space_bottom bigskip 
12030 If the interrupt service routine is defined to be using a specific register
12031  bank then only 
12032 \emph on 
12033 a, b, dptr
12034 \emph default 
12035  & psw are saved and restored, if such an interrupt service routine calls
12036  another function (using another register bank) then the entire register
12037  bank of the called function will be saved on the stack
12038 \begin_inset LatexCommand \index{stack}
12039
12040 \end_inset 
12041
12042 .
12043  This scheme is recommended for larger interrupt service routines.
12044 \layout Subsection
12045
12046 HC08
12047 \begin_inset LatexCommand \index{HC08}
12048
12049 \end_inset 
12050
12051  Interrupt Service Routines
12052 \layout Standard
12053 \added_space_bottom bigskip 
12054 Since the number of interrupts
12055 \begin_inset LatexCommand \index{HC08!interrupt}
12056
12057 \end_inset 
12058
12059  available is chip specific and the interrupt vector table always ends at
12060  the last byte of memory, the interrupt numbers corresponds to the interrupt
12061  vectors in reverse order of address.
12062  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12063  2 will use the interrupt vector at 0xfffa, and so on.
12064  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12065  this way; instead see section 
12066 \begin_inset LatexCommand \ref{sub:Startup-Code}
12067
12068 \end_inset 
12069
12070  for details on customizing startup.
12071 \layout Subsection
12072
12073 Z80 Interrupt Service Routines
12074 \layout Standard
12075
12076 The Z80
12077 \begin_inset LatexCommand \index{Z80}
12078
12079 \end_inset 
12080
12081  uses several different methods for determining the correct interrupt
12082 \begin_inset LatexCommand \index{Z80!interrupt}
12083
12084 \end_inset 
12085
12086  vector depending on the hardware implementation.
12087  Therefore, SDCC ignores the optional interrupt number and does not attempt
12088  to generate an interrupt vector table.
12089 \layout Standard
12090
12091 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12092  instruction to return from the interrupt.
12093  To write an interrupt handler for the non-maskable interrupt, which needs
12094  a RETN instruction instead, add the 
12095 \emph on 
12096 critical
12097 \emph default 
12098  keyword:
12099 \layout Verse
12100
12101
12102 \family typewriter 
12103 void nmi_isr (void) critical interrupt
12104 \newline 
12105
12106 \newline 
12107 \SpecialChar ~
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 \SpecialChar ~
12111 ...
12112  
12113 \newline 
12114 }
12115 \layout Standard
12116 \added_space_bottom bigskip 
12117 However if you need to create a non-interruptable interrupt service routine
12118  you would also require the 
12119 \emph on 
12120 critical
12121 \emph default 
12122  keyword.
12123  To distinguish between this and an nmi_isr you must provide an interrupt
12124  number.
12125 \layout Section
12126
12127 Enabling and Disabling Interrupts
12128 \layout Subsection
12129
12130 Critical Functions and Critical Statements
12131 \layout Standard
12132
12133 A special keyword may be associated with a block or a function declaring
12134  it as 
12135 \emph on 
12136 critical
12137 \emph default 
12138 .
12139  SDCC will generate code to disable all interrupts
12140 \begin_inset LatexCommand \index{interrupt}
12141
12142 \end_inset 
12143
12144  upon entry to a critical function and restore the interrupt enable to the
12145  previous state before returning.
12146  Nesting critical functions will need one additional byte on the stack
12147 \begin_inset LatexCommand \index{stack}
12148
12149 \end_inset 
12150
12151  for each call.
12152 \layout Verse
12153
12154
12155 \family typewriter 
12156 int foo () __critical
12157 \begin_inset LatexCommand \index{critical}
12158
12159 \end_inset 
12160
12161
12162 \begin_inset LatexCommand \index{\_\_critical}
12163
12164 \end_inset 
12165
12166  
12167 \newline 
12168
12169 \newline 
12170 \SpecialChar ~
12171 \SpecialChar ~
12172 \SpecialChar ~
12173 \SpecialChar ~
12174 ...
12175  
12176 \newline 
12177 \SpecialChar ~
12178 \SpecialChar ~
12179 \SpecialChar ~
12180 \SpecialChar ~
12181 ...
12182  
12183 \newline 
12184 }
12185 \layout Standard
12186
12187 The critical attribute maybe used with other attributes like 
12188 \emph on 
12189 reentrant.
12190 \emph default 
12191
12192 \newline 
12193 The keyword 
12194 \emph on 
12195 critical
12196 \emph default 
12197  may also be used to disable interrupts more locally:
12198 \layout Verse
12199
12200
12201 \family typewriter 
12202 __critical{ i++; }
12203 \layout Standard
12204
12205 More than one statement could have been included in the block.
12206 \layout Subsection
12207
12208 Enabling and Disabling Interrupts directly
12209 \layout Standard
12210
12211 Interrupts
12212 \begin_inset LatexCommand \index{interrupt}
12213
12214 \end_inset 
12215
12216  can also be disabled and enabled directly (8051):
12217 \layout Verse
12218
12219
12220 \family typewriter 
12221 EA = 0;\SpecialChar ~
12222 \SpecialChar ~
12223 \SpecialChar ~
12224 \SpecialChar ~
12225 \SpecialChar ~
12226 \SpecialChar ~
12227 \SpecialChar ~
12228 \SpecialChar ~
12229 \SpecialChar ~
12230 \SpecialChar ~
12231 \SpecialChar ~
12232 \SpecialChar ~
12233 or:\SpecialChar ~
12234 \SpecialChar ~
12235 \SpecialChar ~
12236 \SpecialChar ~
12237 \SpecialChar ~
12238 \SpecialChar ~
12239 \SpecialChar ~
12240 \SpecialChar ~
12241 \SpecialChar ~
12242 \SpecialChar ~
12243 \SpecialChar ~
12244 EA_SAVE = EA;
12245 \layout Verse
12246
12247
12248 \family typewriter 
12249 ...\SpecialChar ~
12250 \SpecialChar ~
12251 \SpecialChar ~
12252 \SpecialChar ~
12253 \SpecialChar ~
12254 \SpecialChar ~
12255 \SpecialChar ~
12256 \SpecialChar ~
12257 \SpecialChar ~
12258 \SpecialChar ~
12259 \SpecialChar ~
12260 \SpecialChar ~
12261 \SpecialChar ~
12262 \SpecialChar ~
12263 \SpecialChar ~
12264 \SpecialChar ~
12265 \SpecialChar ~
12266 \SpecialChar ~
12267 \SpecialChar ~
12268 \SpecialChar ~
12269 \SpecialChar ~
12270 \SpecialChar ~
12271 \SpecialChar ~
12272 \SpecialChar ~
12273 \SpecialChar ~
12274 \SpecialChar ~
12275 \SpecialChar ~
12276 \SpecialChar ~
12277 \SpecialChar ~
12278 \SpecialChar ~
12279 EA = 0;
12280 \layout Verse
12281
12282
12283 \family typewriter 
12284 EA = 1;\SpecialChar ~
12285 \SpecialChar ~
12286 \SpecialChar ~
12287 \SpecialChar ~
12288 \SpecialChar ~
12289 \SpecialChar ~
12290 \SpecialChar ~
12291 \SpecialChar ~
12292 \SpecialChar ~
12293 \SpecialChar ~
12294 \SpecialChar ~
12295 \SpecialChar ~
12296 \SpecialChar ~
12297 \SpecialChar ~
12298 \SpecialChar ~
12299 \SpecialChar ~
12300 \SpecialChar ~
12301 \SpecialChar ~
12302 \SpecialChar ~
12303 \SpecialChar ~
12304 \SpecialChar ~
12305 \SpecialChar ~
12306 \SpecialChar ~
12307 \SpecialChar ~
12308 \SpecialChar ~
12309 \SpecialChar ~
12310 ...
12311 \layout Verse
12312
12313
12314 \family typewriter 
12315 \SpecialChar ~
12316 \SpecialChar ~
12317 \SpecialChar ~
12318 \SpecialChar ~
12319 \SpecialChar ~
12320 \SpecialChar ~
12321 \SpecialChar ~
12322 \SpecialChar ~
12323 \SpecialChar ~
12324 \SpecialChar ~
12325 \SpecialChar ~
12326 \SpecialChar ~
12327 \SpecialChar ~
12328 \SpecialChar ~
12329 \SpecialChar ~
12330 \SpecialChar ~
12331 \SpecialChar ~
12332 \SpecialChar ~
12333 \SpecialChar ~
12334 \SpecialChar ~
12335 \SpecialChar ~
12336 \SpecialChar ~
12337 \SpecialChar ~
12338 \SpecialChar ~
12339 \SpecialChar ~
12340 \SpecialChar ~
12341 \SpecialChar ~
12342 \SpecialChar ~
12343 \SpecialChar ~
12344 \SpecialChar ~
12345 \SpecialChar ~
12346 \SpecialChar ~
12347 \SpecialChar ~
12348 EA = EA_SAVE;
12349 \layout Standard
12350
12351 On other architectures which have seperate opcodes for enabling and disabling
12352  interrupts you might want to make use of defines with inline assembly
12353 \begin_inset LatexCommand \index{Assembler routines}
12354
12355 \end_inset 
12356
12357  (HC08
12358 \begin_inset LatexCommand \index{HC08!interrupt}
12359
12360 \end_inset 
12361
12362 ):
12363 \layout Verse
12364
12365
12366 \family typewriter 
12367 #define CLI _asm
12368 \begin_inset LatexCommand \index{\_asm}
12369
12370 \end_inset 
12371
12372 \SpecialChar ~
12373 \SpecialChar ~
12374 cli\SpecialChar ~
12375 \SpecialChar ~
12376 _endasm
12377 \begin_inset LatexCommand \index{\_endasm}
12378
12379 \end_inset 
12380
12381
12382 \layout Verse
12383
12384
12385 \family typewriter 
12386 #define SEI _asm\SpecialChar ~
12387 \SpecialChar ~
12388 sei\SpecialChar ~
12389 \SpecialChar ~
12390 _endasm; 
12391 \layout Verse
12392
12393
12394 \family typewriter 
12395 ...
12396 \layout Standard
12397
12398 Note: it is sometimes sufficient to disable only a specific interrupt source
12399  like f.e.
12400  a timer or serial interrupt by manipulating an 
12401 \emph on 
12402 interrupt mask
12403 \begin_inset LatexCommand \index{interrupt mask}
12404
12405 \end_inset 
12406
12407
12408 \emph default 
12409  register.
12410  
12411 \layout Standard
12412
12413 Usually the time during which interrupts are disabled should be kept as
12414  short as possible.
12415  This minimizes both 
12416 \emph on 
12417 interrupt latency
12418 \emph default 
12419
12420 \begin_inset LatexCommand \index{interrupt latency}
12421
12422 \end_inset 
12423
12424  (the time between the occurrence of the interrupt and the execution of
12425  the first code in the interrupt routine) and 
12426 \emph on 
12427 interrupt jitter
12428 \emph default 
12429
12430 \begin_inset LatexCommand \index{interrupt jitter}
12431
12432 \end_inset 
12433
12434  (the difference between the shortest and the longest interrupt latency).
12435  These really are something different, f.e.
12436  a serial interrupt has to be served before its buffer overruns so it cares
12437  for the maximum interrupt latency, whereas it does not care about jitter.
12438  On a loudspeaker driven via a digital to analog converter which is fed
12439  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12440  a much smaller jitter will be very audible.
12441 \layout Standard
12442
12443 You can reenable interrupts within an interrupt routine and on some architecture
12444 s you can make use of two (or more) levels of 
12445 \emph on 
12446 interrupt priorities
12447 \emph default 
12448
12449 \begin_inset LatexCommand \index{interrupt priority}
12450
12451 \end_inset 
12452
12453 .
12454  On some architectures which don't support interrupt priorities these can
12455  be implemented by manipulating the interrupt mask and reenabling interrupts
12456  within the interrupt routine.
12457  Check there is sufficient space on the stack
12458 \begin_inset LatexCommand \index{stack}
12459
12460 \end_inset 
12461
12462  and don't add complexity unless you have to.
12463  
12464 \layout Subsection
12465
12466 Semaphore
12467 \begin_inset LatexCommand \index{semaphore}
12468
12469 \end_inset 
12470
12471  locking (mcs51/ds390)
12472 \layout Standard
12473
12474 Some architectures (mcs51/ds390) have an atomic
12475 \begin_inset LatexCommand \index{atomic}
12476
12477 \end_inset 
12478
12479  bit test and
12480 \emph on 
12481  
12482 \emph default 
12483 clear
12484 \emph on 
12485  
12486 \emph default 
12487 instruction.
12488  These type of instructions are typically used in preemptive multitasking
12489  systems, where a routine f.e.
12490  claims the use of a data structure ('acquires a lock
12491 \begin_inset LatexCommand \index{lock}
12492
12493 \end_inset 
12494
12495  on it'), makes some modifications and then releases the lock when the data
12496  structure is consistent again.
12497  The instruction may also be used if interrupt and non-interrupt code have
12498  to compete for a resource.
12499  With the atomic bit test and clear instruction interrupts
12500 \begin_inset LatexCommand \index{interrupt}
12501
12502 \end_inset 
12503
12504  don't have to be disabled for the locking operation.
12505  
12506 \layout Standard
12507
12508 SDCC generates this instruction if the source follows this pattern:
12509 \layout Verse
12510
12511
12512 \family typewriter 
12513 volatile
12514 \begin_inset LatexCommand \index{volatile}
12515
12516 \end_inset 
12517
12518  bit resource_is_free; 
12519 \newline 
12520
12521 \newline 
12522 if (resource_is_free) 
12523 \newline 
12524 \SpecialChar ~
12525 \SpecialChar ~
12526
12527 \newline 
12528 \SpecialChar ~
12529 \SpecialChar ~
12530 \SpecialChar ~
12531 \SpecialChar ~
12532 resource_is_free=0; 
12533 \newline 
12534 \SpecialChar ~
12535 \SpecialChar ~
12536 \SpecialChar ~
12537 \SpecialChar ~
12538 ...
12539  
12540 \newline 
12541 \SpecialChar ~
12542 \SpecialChar ~
12543 \SpecialChar ~
12544 \SpecialChar ~
12545 resource_is_free=1;
12546 \newline 
12547 \SpecialChar ~
12548 \SpecialChar ~
12549
12550 \layout Standard
12551
12552 Note, mcs51 and ds390 support only an atomic
12553 \begin_inset LatexCommand \index{atomic}
12554
12555 \end_inset 
12556
12557  bit test and 
12558 \emph on 
12559 clear
12560 \emph default 
12561  instruction (as opposed to atomic bit test and 
12562 \emph on 
12563 set).
12564 \layout Section
12565
12566 Functions using private register banks
12567 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12568
12569 \end_inset 
12570
12571  (mcs51/ds390)
12572 \layout Standard
12573
12574 Some architectures have support for quickly changing register sets.
12575  SDCC supports this feature with the 
12576 \emph on 
12577 using
12578 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12579
12580 \end_inset 
12581
12582
12583 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12584
12585 \end_inset 
12586
12587
12588 \emph default 
12589  attribute (which tells the compiler to use a register bank
12590 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12591
12592 \end_inset 
12593
12594  other than the default bank zero).
12595  It should only be applied to 
12596 \emph on 
12597 interrupt
12598 \begin_inset LatexCommand \index{interrupt}
12599
12600 \end_inset 
12601
12602
12603 \emph default 
12604  functions (see footnote below).
12605  This will in most circumstances make the generated ISR code more efficient
12606  since it will not have to save registers on the stack.
12607 \layout Standard
12608
12609 The 
12610 \emph on 
12611 using
12612 \emph default 
12613  attribute will have no effect on the generated code for a 
12614 \emph on 
12615 non-interrupt
12616 \emph default 
12617  function (but may occasionally be useful anyway
12618 \begin_inset Foot
12619 collapsed false
12620
12621 \layout Standard
12622
12623 possible exception: if a function is called ONLY from 'interrupt' functions
12624  using a particular bank, it can be declared with the same 'using' attribute
12625  as the calling 'interrupt' functions.
12626  For instance, if you have several ISRs using bank one, and all of them
12627  call memcpy(), it might make sense to create a specialized version of memcpy()
12628  'using 1', since this would prevent the ISR from having to save bank zero
12629  to the stack on entry and switch to bank zero before calling the function
12630 \end_inset 
12631
12632 ).
12633 \newline 
12634
12635 \emph on 
12636 (pending: Note, nowadays the 
12637 \emph default 
12638 using
12639 \emph on 
12640  attribute has an effect on
12641 \emph default 
12642  
12643 \emph on 
12644 the generated code for a 
12645 \emph default 
12646 non-interrupt
12647 \emph on 
12648  function
12649 \emph default 
12650 .
12651 \emph on 
12652 )
12653 \layout Standard
12654
12655 An 
12656 \emph on 
12657 interrupt
12658 \emph default 
12659  function using a non-zero bank will assume that it can trash that register
12660  bank, and will not save it.
12661  Since high-priority interrupts
12662 \begin_inset LatexCommand \index{interrupts}
12663
12664 \end_inset 
12665
12666
12667 \begin_inset LatexCommand \index{interrupt priority}
12668
12669 \end_inset 
12670
12671  can interrupt low-priority ones on the 8051 and friends, this means that
12672  if a high-priority ISR 
12673 \emph on 
12674 using
12675 \emph default 
12676  a particular bank occurs while processing a low-priority ISR 
12677 \emph on 
12678 using
12679 \emph default 
12680  the same bank, terrible and bad things can happen.
12681  To prevent this, no single register bank should be 
12682 \emph on 
12683 used
12684 \emph default 
12685  by both a high priority and a low priority ISR.
12686  This is probably most easily done by having all high priority ISRs use
12687  one bank and all low priority ISRs use another.
12688  If you have an ISR which can change priority at runtime, you're on your
12689  own: I suggest using the default bank zero and taking the small performance
12690  hit.
12691 \layout Standard
12692 \added_space_bottom bigskip 
12693 It is most efficient if your ISR calls no other functions.
12694  If your ISR must call other functions, it is most efficient if those functions
12695  use the same bank as the ISR (see note 1 below); the next best is if the
12696  called functions use bank zero.
12697  It is very inefficient to call a function using a different, non-zero bank
12698  from an ISR.
12699  
12700 \layout Section
12701
12702 Startup Code
12703 \begin_inset LatexCommand \label{sub:Startup-Code}
12704
12705 \end_inset 
12706
12707
12708 \begin_inset LatexCommand \index{Startup code}
12709
12710 \end_inset 
12711
12712
12713 \layout Subsection
12714
12715 MCS51/DS390 Startup Code
12716 \layout Standard
12717
12718 The compiler inserts a call to the C routine 
12719 \emph on 
12720 _sdcc_external_startup()
12721 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12722
12723 \end_inset 
12724
12725
12726 \series bold 
12727 \emph default 
12728  
12729 \series default 
12730 at the start of the CODE area.
12731  This routine is in the runtime library
12732 \begin_inset LatexCommand \index{Runtime library}
12733
12734 \end_inset 
12735
12736 .
12737  By default this routine returns 0, if this routine returns a non-zero value,
12738  the static & global variable initialization will be skipped and the function
12739  main will be invoked.
12740  Otherwise static & global variables will be initialized before the function
12741  main is invoked.
12742  You could add a 
12743 \emph on 
12744 _sdcc_external_startup()
12745 \emph default 
12746  routine to your program to override the default if you need to setup hardware
12747  or perform some other critical operation prior to static & global variable
12748  initialization
12749 \begin_inset LatexCommand \index{Variable initialization}
12750
12751 \end_inset 
12752
12753 .
12754  On some mcs51 variants xdata
12755 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12756
12757 \end_inset 
12758
12759  memory has to be explicitly enabled before it can be accessed or if the
12760  watchdog
12761 \begin_inset LatexCommand \index{watchdog}
12762
12763 \end_inset 
12764
12765  needs to be disabled, this is the place to do it.
12766  The startup code clears all internal data memory, 256 bytes by default,
12767  but from 0 to n-1 if 
12768 \emph on 
12769 -
12770 \begin_inset ERT
12771 status Collapsed
12772
12773 \layout Standard
12774
12775 \backslash 
12776 /
12777 \end_inset 
12778
12779 -iram-size
12780 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12781
12782 \end_inset 
12783
12784 n
12785 \emph default 
12786  is used.
12787  (recommended for Chipcon CC1010).
12788 \layout Standard
12789 \added_space_bottom bigskip 
12790 See also the compiler options 
12791 \emph on 
12792 -
12793 \begin_inset ERT
12794 status Collapsed
12795
12796 \layout Standard
12797
12798 \backslash 
12799 /
12800 \end_inset 
12801
12802 -no-xinit
12803 \emph default 
12804 -
12805 \emph on 
12806 opt
12807 \emph default 
12808
12809 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
12810
12811 \end_inset 
12812
12813
12814 \emph on 
12815 -
12816 \begin_inset ERT
12817 status Collapsed
12818
12819 \layout Standard
12820
12821 \backslash 
12822 /
12823 \end_inset 
12824
12825 -main-return
12826 \emph default 
12827
12828 \begin_inset LatexCommand \index{-\/-main-return}
12829
12830 \end_inset 
12831
12832 and section 
12833 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12834
12835 \end_inset 
12836
12837 \SpecialChar ~
12838 about MCS51-variants.
12839 \layout Subsection
12840
12841 HC08 Startup Code
12842 \layout Standard
12843 \added_space_bottom bigskip 
12844 The HC08
12845 \begin_inset LatexCommand \index{HC08}
12846
12847 \end_inset 
12848
12849  startup code follows the same scheme as the MCS51 startup code.
12850 \layout Subsection
12851
12852 Z80 Startup Code
12853 \layout Standard
12854 \added_space_bottom bigskip 
12855 On the Z80
12856 \begin_inset LatexCommand \index{Z80}
12857
12858 \end_inset 
12859
12860  the startup code is inserted by linking with crt0.o which is generated from
12861  sdcc/device/lib/z80/crt0.s.
12862  If you need a different startup code you can use the compiler option 
12863 \emph on 
12864 -
12865 \series bold 
12866 \emph default 
12867
12868 \begin_inset ERT
12869 status Collapsed
12870
12871 \layout Standard
12872
12873 \backslash 
12874 /
12875 \end_inset 
12876
12877
12878 \series default 
12879 \emph on 
12880 -no-std-crt0
12881 \emph default 
12882
12883 \begin_inset LatexCommand \index{-\/-no-std-crt0}
12884
12885 \end_inset 
12886
12887  and provide your own crt0.o.
12888  
12889 \layout Section
12890
12891 Inline Assembler Code
12892 \begin_inset LatexCommand \index{Assembler routines}
12893
12894 \end_inset 
12895
12896
12897 \layout Subsection
12898
12899 A Step by Step Introduction
12900 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
12901
12902 \end_inset 
12903
12904
12905 \layout Standard
12906
12907 Starting from a small snippet of c-code this example shows for the MCS51
12908  how to use inline assembly, access variables, a function parameter and
12909  an array in xdata memory.
12910  The example uses an MCS51 here but is easily adapted for other architectures.
12911  This is a buffer routine which should be optimized:
12912 \layout Verse
12913
12914
12915 \family typewriter 
12916 \size footnotesize 
12917 unsigned char __far
12918 \begin_inset LatexCommand \index{far (storage class)}
12919
12920 \end_inset 
12921
12922
12923 \begin_inset LatexCommand \index{\_\_far (storage class)}
12924
12925 \end_inset 
12926
12927  __at
12928 \begin_inset LatexCommand \index{at}
12929
12930 \end_inset 
12931
12932
12933 \begin_inset LatexCommand \index{\_\_at}
12934
12935 \end_inset 
12936
12937 (0x7f00) buf[0x100];
12938 \begin_inset LatexCommand \index{Aligned array}
12939
12940 \end_inset 
12941
12942
12943 \newline 
12944 unsigned char head, tail;
12945 \newline 
12946
12947 \newline 
12948 void to_buffer( unsigned char c ) 
12949 \newline 
12950 {
12951 \newline 
12952 \SpecialChar ~
12953 \SpecialChar ~
12954 \SpecialChar ~
12955 \SpecialChar ~
12956 if( head != (unsigned char)(tail-1) )\SpecialChar ~
12957 /* cast 
12958 \series bold 
12959 needed
12960 \series default 
12961  to avoid promotion
12962 \begin_inset LatexCommand \index{promotion to signed int}
12963
12964 \end_inset 
12965
12966
12967 \begin_inset LatexCommand \index{type promotion}
12968
12969 \end_inset 
12970
12971  to integer */
12972 \begin_inset Marginal
12973 collapsed true
12974
12975 \layout Standard
12976
12977
12978 \series bold 
12979 \SpecialChar ~
12980 !
12981 \end_inset 
12982
12983
12984 \newline 
12985 \SpecialChar ~
12986 \SpecialChar ~
12987 \SpecialChar ~
12988 \SpecialChar ~
12989 \SpecialChar ~
12990 \SpecialChar ~
12991 \SpecialChar ~
12992 \SpecialChar ~
12993 buf[ head++ ] = c;\SpecialChar ~
12994 \SpecialChar ~
12995 \SpecialChar ~
12996 \SpecialChar ~
12997 \SpecialChar ~
12998 \SpecialChar ~
12999 \SpecialChar ~
13000 \SpecialChar ~
13001 \SpecialChar ~
13002 \SpecialChar ~
13003 \SpecialChar ~
13004 \SpecialChar ~
13005 \SpecialChar ~
13006 \SpecialChar ~
13007 \SpecialChar ~
13008 \SpecialChar ~
13009 /* access to a 256 byte aligned array */
13010 \newline 
13011
13012 \layout Standard
13013
13014 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13015  then a corresponding buffer.asm file is generated.
13016  We define a new function 
13017 \family typewriter 
13018 to_buffer_asm()
13019 \family default 
13020  in file buffer.c in which we cut and paste the generated code, removing
13021  unwanted comments and some ':'.
13022  Then add 
13023 \begin_inset Quotes sld
13024 \end_inset 
13025
13026 _asm
13027 \begin_inset Quotes srd
13028 \end_inset 
13029
13030  and 
13031 \begin_inset Quotes sld
13032 \end_inset 
13033
13034 _endasm;
13035 \begin_inset Quotes srd
13036 \end_inset 
13037
13038  to the beginning and the end of the function body:
13039 \layout Verse
13040
13041
13042 \family typewriter 
13043 \size footnotesize 
13044 /* With a cut and paste from the .asm file, we have something to start with.
13045 \newline 
13046 \SpecialChar ~
13047 \SpecialChar ~
13048 \SpecialChar ~
13049 The function is not yet OK! (registers aren't saved) */ 
13050 \newline 
13051 void to_buffer_asm( unsigned char c ) 
13052 \newline 
13053
13054 \newline 
13055 \SpecialChar ~
13056 \SpecialChar ~
13057 \SpecialChar ~
13058 \SpecialChar ~
13059 _asm
13060 \begin_inset LatexCommand \index{\_asm}
13061
13062 \end_inset 
13063
13064
13065 \begin_inset LatexCommand \index{\_\_asm}
13066
13067 \end_inset 
13068
13069
13070 \newline 
13071 \SpecialChar ~
13072 \SpecialChar ~
13073 \SpecialChar ~
13074 \SpecialChar ~
13075 mov\SpecialChar ~
13076 \SpecialChar ~
13077 r2,dpl 
13078 \newline 
13079 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13080 /* cast 
13081 \series bold 
13082 needed
13083 \series default 
13084  to avoid promotion
13085 \begin_inset LatexCommand \index{promotion to signed int}
13086
13087 \end_inset 
13088
13089
13090 \begin_inset LatexCommand \index{type promotion}
13091
13092 \end_inset 
13093
13094  to integer */
13095 \newline 
13096 \SpecialChar ~
13097 \SpecialChar ~
13098 \SpecialChar ~
13099 \SpecialChar ~
13100 mov\SpecialChar ~
13101 \SpecialChar ~
13102 a,_tail 
13103 \newline 
13104 \SpecialChar ~
13105 \SpecialChar ~
13106 \SpecialChar ~
13107 \SpecialChar ~
13108 dec\SpecialChar ~
13109 \SpecialChar ~
13110
13111 \newline 
13112 \SpecialChar ~
13113 \SpecialChar ~
13114 \SpecialChar ~
13115 \SpecialChar ~
13116 mov\SpecialChar ~
13117 \SpecialChar ~
13118 r3,a 
13119 \newline 
13120 \SpecialChar ~
13121 \SpecialChar ~
13122 \SpecialChar ~
13123 \SpecialChar ~
13124 mov\SpecialChar ~
13125 \SpecialChar ~
13126 a,_head 
13127 \newline 
13128 \SpecialChar ~
13129 \SpecialChar ~
13130 \SpecialChar ~
13131 \SpecialChar ~
13132 cjne a,ar3,00106$ 
13133 \newline 
13134 \SpecialChar ~
13135 \SpecialChar ~
13136 \SpecialChar ~
13137 \SpecialChar ~
13138 ret
13139 \newline 
13140 00106$: 
13141 \newline 
13142 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13143 \begin_inset LatexCommand \index{Aligned array}
13144
13145 \end_inset 
13146
13147
13148 \newline 
13149 \SpecialChar ~
13150 \SpecialChar ~
13151 \SpecialChar ~
13152 \SpecialChar ~
13153 mov\SpecialChar ~
13154 \SpecialChar ~
13155 r3,_head 
13156 \newline 
13157 \SpecialChar ~
13158 \SpecialChar ~
13159 \SpecialChar ~
13160 \SpecialChar ~
13161 inc\SpecialChar ~
13162 \SpecialChar ~
13163 _head 
13164 \newline 
13165 \SpecialChar ~
13166 \SpecialChar ~
13167 \SpecialChar ~
13168 \SpecialChar ~
13169 mov\SpecialChar ~
13170 \SpecialChar ~
13171 dpl,r3 
13172 \newline 
13173 \SpecialChar ~
13174 \SpecialChar ~
13175 \SpecialChar ~
13176 \SpecialChar ~
13177 mov\SpecialChar ~
13178 \SpecialChar ~
13179 dph,#(_buf >> 8) 
13180 \newline 
13181 \SpecialChar ~
13182 \SpecialChar ~
13183 \SpecialChar ~
13184 \SpecialChar ~
13185 mov\SpecialChar ~
13186 \SpecialChar ~
13187 a,r2 
13188 \newline 
13189 \SpecialChar ~
13190 \SpecialChar ~
13191 \SpecialChar ~
13192 \SpecialChar ~
13193 movx @dptr,a 
13194 \newline 
13195 00103$: 
13196 \newline 
13197 \SpecialChar ~
13198 \SpecialChar ~
13199 \SpecialChar ~
13200 \SpecialChar ~
13201 ret
13202 \newline 
13203 \SpecialChar ~
13204 \SpecialChar ~
13205 \SpecialChar ~
13206 \SpecialChar ~
13207 _endasm
13208 \begin_inset LatexCommand \index{\_endasm}
13209
13210 \end_inset 
13211
13212
13213 \begin_inset LatexCommand \index{\_\_endasm}
13214
13215 \end_inset 
13216
13217 ;
13218 \newline 
13219
13220 \layout Standard
13221
13222 The new file buffer.c should compile with only one warning about the unreferenced
13223  function argument 'c'.
13224  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13225  (1) and finally have:
13226 \layout Verse
13227
13228
13229 \family typewriter 
13230 \size footnotesize 
13231 unsigned char __far __at(0x7f00) buf[0x100];
13232 \newline 
13233 unsigned char head, tail;
13234 \newline 
13235 #define USE_ASSEMBLY (1)
13236 \newline 
13237
13238 \newline 
13239 #if !USE_ASSEMBLY
13240 \newline 
13241
13242 \newline 
13243 void to_buffer( unsigned char c )
13244 \newline 
13245 {
13246 \newline 
13247 \SpecialChar ~
13248 \SpecialChar ~
13249 \SpecialChar ~
13250 \SpecialChar ~
13251 if( head != (unsigned char)(tail-1) )
13252 \newline 
13253 \SpecialChar ~
13254 \SpecialChar ~
13255 \SpecialChar ~
13256 \SpecialChar ~
13257 \SpecialChar ~
13258 \SpecialChar ~
13259 \SpecialChar ~
13260 \SpecialChar ~
13261 buf[ head++ ] = c;
13262 \newline 
13263 }
13264 \newline 
13265
13266 \newline 
13267 #else
13268 \newline 
13269
13270 \newline 
13271 void to_buffer( unsigned char c )
13272 \newline 
13273 {
13274 \newline 
13275 \SpecialChar ~
13276 \SpecialChar ~
13277 \SpecialChar ~
13278 \SpecialChar ~
13279 c; // to avoid warning: unreferenced function argument
13280 \newline 
13281 \SpecialChar ~
13282 \SpecialChar ~
13283 \SpecialChar ~
13284 \SpecialChar ~
13285 _asm
13286 \begin_inset LatexCommand \index{\_asm}
13287
13288 \end_inset 
13289
13290
13291 \begin_inset LatexCommand \index{\_\_asm}
13292
13293 \end_inset 
13294
13295
13296 \newline 
13297 \SpecialChar ~
13298 \SpecialChar ~
13299 \SpecialChar ~
13300 \SpecialChar ~
13301 \SpecialChar ~
13302 \SpecialChar ~
13303 \SpecialChar ~
13304 \SpecialChar ~
13305 ; save used registers here.
13306  
13307 \newline 
13308 \SpecialChar ~
13309 \SpecialChar ~
13310 \SpecialChar ~
13311 \SpecialChar ~
13312 \SpecialChar ~
13313 \SpecialChar ~
13314 \SpecialChar ~
13315 \SpecialChar ~
13316 ; If we were still using r2,r3 we would have to push them here.
13317  
13318 \newline 
13319 ; if( head != (unsigned char)(tail-1) )
13320 \newline 
13321 \SpecialChar ~
13322 \SpecialChar ~
13323 \SpecialChar ~
13324 \SpecialChar ~
13325 \SpecialChar ~
13326 \SpecialChar ~
13327 \SpecialChar ~
13328 \SpecialChar ~
13329 mov\SpecialChar ~
13330  a,_tail
13331 \newline 
13332 \SpecialChar ~
13333 \SpecialChar ~
13334 \SpecialChar ~
13335 \SpecialChar ~
13336 \SpecialChar ~
13337 \SpecialChar ~
13338 \SpecialChar ~
13339 \SpecialChar ~
13340 dec\SpecialChar ~
13341  a
13342 \newline 
13343 \SpecialChar ~
13344 \SpecialChar ~
13345 \SpecialChar ~
13346 \SpecialChar ~
13347 \SpecialChar ~
13348 \SpecialChar ~
13349 \SpecialChar ~
13350 \SpecialChar ~
13351 xrl\SpecialChar ~
13352  a,_head
13353 \newline 
13354 \SpecialChar ~
13355 \SpecialChar ~
13356 \SpecialChar ~
13357 \SpecialChar ~
13358 \SpecialChar ~
13359 \SpecialChar ~
13360 \SpecialChar ~
13361 \SpecialChar ~
13362 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13363 \newline 
13364 \SpecialChar ~
13365 \SpecialChar ~
13366 \SpecialChar ~
13367 \SpecialChar ~
13368 \SpecialChar ~
13369 \SpecialChar ~
13370 \SpecialChar ~
13371 \SpecialChar ~
13372 jz\SpecialChar ~
13373 \SpecialChar ~
13374  t_b_end$
13375 \newline 
13376 \SpecialChar ~
13377 \SpecialChar ~
13378 \SpecialChar ~
13379 \SpecialChar ~
13380 \SpecialChar ~
13381 \SpecialChar ~
13382 \SpecialChar ~
13383 \SpecialChar ~
13384 ;
13385 \newline 
13386 ; buf[ head++ ] = c;
13387 \newline 
13388 \SpecialChar ~
13389 \SpecialChar ~
13390 \SpecialChar ~
13391 \SpecialChar ~
13392 \SpecialChar ~
13393 \SpecialChar ~
13394 \SpecialChar ~
13395 \SpecialChar ~
13396 mov\SpecialChar ~
13397  a,dpl \SpecialChar ~
13398 \SpecialChar ~
13399 \SpecialChar ~
13400 \SpecialChar ~
13401 \SpecialChar ~
13402 \SpecialChar ~
13403 \SpecialChar ~
13404 ; dpl holds lower byte of function argument
13405 \newline 
13406 \SpecialChar ~
13407 \SpecialChar ~
13408 \SpecialChar ~
13409 \SpecialChar ~
13410 \SpecialChar ~
13411 \SpecialChar ~
13412 \SpecialChar ~
13413 \SpecialChar ~
13414 mov\SpecialChar ~
13415  dpl,_head \SpecialChar ~
13416 \SpecialChar ~
13417 \SpecialChar ~
13418 ; buf is 0x100 byte aligned so head can be used directly
13419 \newline 
13420 \SpecialChar ~
13421 \SpecialChar ~
13422 \SpecialChar ~
13423 \SpecialChar ~
13424 \SpecialChar ~
13425 \SpecialChar ~
13426 \SpecialChar ~
13427 \SpecialChar ~
13428 mov\SpecialChar ~
13429  dph,#(_buf>>8)
13430 \newline 
13431 \SpecialChar ~
13432 \SpecialChar ~
13433 \SpecialChar ~
13434 \SpecialChar ~
13435 \SpecialChar ~
13436 \SpecialChar ~
13437 \SpecialChar ~
13438 \SpecialChar ~
13439 movx @dptr,a
13440 \newline 
13441 \SpecialChar ~
13442 \SpecialChar ~
13443 \SpecialChar ~
13444 \SpecialChar ~
13445 \SpecialChar ~
13446 \SpecialChar ~
13447 \SpecialChar ~
13448 \SpecialChar ~
13449 inc \SpecialChar ~
13450 _head
13451 \newline 
13452 \SpecialChar ~
13453 \SpecialChar ~
13454 \SpecialChar ~
13455 \SpecialChar ~
13456 \SpecialChar ~
13457 \SpecialChar ~
13458 \SpecialChar ~
13459 \SpecialChar ~
13460 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13461 \newline 
13462 t_b_end$:
13463 \newline 
13464 \SpecialChar ~
13465 \SpecialChar ~
13466 \SpecialChar ~
13467 \SpecialChar ~
13468 \SpecialChar ~
13469 \SpecialChar ~
13470 \SpecialChar ~
13471 \SpecialChar ~
13472 ; restore used registers here 
13473 \newline 
13474 \SpecialChar ~
13475 \SpecialChar ~
13476 \SpecialChar ~
13477 \SpecialChar ~
13478 _endasm
13479 \begin_inset LatexCommand \index{\_endasm}
13480
13481 \end_inset 
13482
13483
13484 \begin_inset LatexCommand \index{\_\_endasm}
13485
13486 \end_inset 
13487
13488 ;
13489 \newline 
13490 }
13491 \newline 
13492 #endif
13493 \layout Standard
13494
13495 The inline assembler code can contain any valid code understood by the assembler
13496 , this includes any assembler directives and comment lines.
13497  The assembler does not like some characters like ':' or ''' in comments.
13498  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13499 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13500
13501 \end_inset 
13502
13503
13504 \begin_inset LatexCommand \index{Assembler documentation}
13505
13506 \end_inset 
13507
13508  or online at 
13509 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13510
13511 \end_inset 
13512
13513 \SpecialChar ~
13514 .
13515 \layout Standard
13516
13517 The compiler does not do any validation of the code within the 
13518 \family typewriter 
13519 _asm
13520 \begin_inset LatexCommand \index{\_asm}
13521
13522 \end_inset 
13523
13524
13525 \begin_inset LatexCommand \index{\_\_asm}
13526
13527 \end_inset 
13528
13529  ...
13530  _endasm
13531 \size footnotesize 
13532
13533 \begin_inset LatexCommand \index{\_endasm}
13534
13535 \end_inset 
13536
13537
13538 \begin_inset LatexCommand \index{\_\_endasm}
13539
13540 \end_inset 
13541
13542
13543 \size default 
13544 ;
13545 \family default 
13546  keyword pair.
13547  Specifically it will not know which registers are used and thus register
13548  pushing/popping
13549 \begin_inset LatexCommand \index{push/pop}
13550
13551 \end_inset 
13552
13553  has to be done manually.
13554  
13555 \layout Standard
13556
13557 It is recommended that each assembly instruction (including labels) be placed
13558  in a separate line (as the example shows).
13559  When the -
13560 \begin_inset ERT
13561 status Collapsed
13562
13563 \layout Standard
13564
13565 \backslash 
13566 /
13567 \end_inset 
13568
13569 -
13570 \emph on 
13571 peep-asm
13572 \begin_inset LatexCommand \index{-\/-peep-asm}
13573
13574 \end_inset 
13575
13576
13577 \emph default 
13578  command line option is used, the inline assembler code will be passed through
13579  the peephole optimizer
13580 \begin_inset LatexCommand \index{Peephole optimizer}
13581
13582 \end_inset 
13583
13584 .
13585  There are only a few (if any) cases where this option makes sense, it might
13586  cause some unexpected changes in the inline assembler code.
13587  Please go through the peephole optimizer rules defined in file 
13588 \emph on 
13589 SDCCpeeph.def
13590 \emph default 
13591  before using this option.
13592 \layout Subsection
13593
13594 Naked Functions
13595 \begin_inset LatexCommand \label{sub:Naked-Functions}
13596
13597 \end_inset 
13598
13599
13600 \begin_inset LatexCommand \index{Naked functions}
13601
13602 \end_inset 
13603
13604
13605 \layout Standard
13606
13607 A special keyword may be associated with a function declaring it as 
13608 \emph on 
13609 _naked
13610 \begin_inset LatexCommand \index{\_naked}
13611
13612 \end_inset 
13613
13614
13615 \begin_inset LatexCommand \index{\_\_naked}
13616
13617 \end_inset 
13618
13619 .
13620  
13621 \emph default 
13622 The 
13623 \emph on 
13624 _naked
13625 \emph default 
13626  function modifier attribute prevents the compiler from generating prologue
13627 \begin_inset LatexCommand \index{function prologue}
13628
13629 \end_inset 
13630
13631  and epilogue
13632 \begin_inset LatexCommand \index{function epilogue}
13633
13634 \end_inset 
13635
13636  code for that function.
13637  This means that the user is entirely responsible for such things as saving
13638  any registers that may need to be preserved, selecting the proper register
13639  bank, generating the 
13640 \emph on 
13641 return
13642 \emph default 
13643  instruction at the end, etc.
13644  Practically, this means that the contents of the function must be written
13645  in inline assembler.
13646  This is particularly useful for interrupt functions, which can have a large
13647  (and often unnecessary) prologue/epilogue.
13648  For example, compare the code generated by these two functions:
13649 \layout Verse
13650
13651
13652 \family typewriter 
13653 volatile
13654 \begin_inset LatexCommand \index{volatile}
13655
13656 \end_inset 
13657
13658  data unsigned char counter;
13659 \newline 
13660
13661 \newline 
13662 void simpleInterrupt(void) __interrupt
13663 \begin_inset LatexCommand \index{interrupt}
13664
13665 \end_inset 
13666
13667
13668 \begin_inset LatexCommand \index{\_\_interrupt}
13669
13670 \end_inset 
13671
13672  (1)
13673 \newline 
13674 {
13675 \newline 
13676 \SpecialChar ~
13677 \SpecialChar ~
13678 \SpecialChar ~
13679 \SpecialChar ~
13680 counter++;
13681 \newline 
13682 }
13683 \newline 
13684
13685 \newline 
13686 void nakedInterrupt(void) __interrupt (2) __naked
13687 \newline 
13688 {
13689 \newline 
13690 \SpecialChar ~
13691 \SpecialChar ~
13692 \SpecialChar ~
13693 \SpecialChar ~
13694 _asm
13695 \begin_inset LatexCommand \index{\_asm}
13696
13697 \end_inset 
13698
13699
13700 \begin_inset LatexCommand \index{\_\_asm}
13701
13702 \end_inset 
13703
13704
13705 \newline 
13706 \SpecialChar ~
13707 \SpecialChar ~
13708 \SpecialChar ~
13709 \SpecialChar ~
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 inc\SpecialChar ~
13713 \SpecialChar ~
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 _counter ; does not change flags, no need to save psw
13718 \newline 
13719 \SpecialChar ~
13720 \SpecialChar ~
13721 \SpecialChar ~
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 reti\SpecialChar ~
13726 \SpecialChar ~
13727 \SpecialChar ~
13728 \SpecialChar ~
13729 ; MUST explicitly include ret or reti in _naked function.
13730 \newline 
13731 \SpecialChar ~
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 _endasm
13736 \begin_inset LatexCommand \index{\_endasm}
13737
13738 \end_inset 
13739
13740
13741 \begin_inset LatexCommand \index{\_\_endasm}
13742
13743 \end_inset 
13744
13745 ;
13746 \newline 
13747 }
13748 \layout Standard
13749
13750 For an 8051 target, the generated simpleInterrupt looks like:
13751 \layout Verse
13752
13753
13754 \family typewriter 
13755 Note, this is an 
13756 \emph on 
13757 outdated
13758 \emph default 
13759  example, recent versions of SDCC generate
13760 \newline 
13761 the 
13762 \emph on 
13763 same
13764 \emph default 
13765  code for simpleInterrupt() and nakedInterrupt()!
13766 \newline 
13767
13768 \newline 
13769 _simpleInterrupt:
13770 \newline 
13771 \SpecialChar ~
13772 \SpecialChar ~
13773 \SpecialChar ~
13774 \SpecialChar ~
13775 push\SpecialChar ~
13776 \SpecialChar ~
13777 \SpecialChar ~
13778 \SpecialChar ~
13779 acc
13780 \newline 
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 push\SpecialChar ~
13786 \SpecialChar ~
13787 \SpecialChar ~
13788 \SpecialChar ~
13789 b
13790 \newline 
13791 \SpecialChar ~
13792 \SpecialChar ~
13793 \SpecialChar ~
13794 \SpecialChar ~
13795 push\SpecialChar ~
13796 \SpecialChar ~
13797 \SpecialChar ~
13798 \SpecialChar ~
13799 dpl
13800 \newline 
13801 \SpecialChar ~
13802 \SpecialChar ~
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 push\SpecialChar ~
13806 \SpecialChar ~
13807 \SpecialChar ~
13808 \SpecialChar ~
13809 dph
13810 \newline 
13811 \SpecialChar ~
13812 \SpecialChar ~
13813 \SpecialChar ~
13814 \SpecialChar ~
13815 push\SpecialChar ~
13816 \SpecialChar ~
13817 \SpecialChar ~
13818 \SpecialChar ~
13819 psw
13820 \newline 
13821 \SpecialChar ~
13822 \SpecialChar ~
13823 \SpecialChar ~
13824 \SpecialChar ~
13825 mov\SpecialChar ~
13826 \SpecialChar ~
13827 \SpecialChar ~
13828 \SpecialChar ~
13829 \SpecialChar ~
13830 psw,#0x00
13831 \newline 
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 \SpecialChar ~
13835 \SpecialChar ~
13836 inc\SpecialChar ~
13837 \SpecialChar ~
13838 \SpecialChar ~
13839 \SpecialChar ~
13840 \SpecialChar ~
13841 _counter
13842 \newline 
13843 \SpecialChar ~
13844 \SpecialChar ~
13845 \SpecialChar ~
13846 \SpecialChar ~
13847 pop\SpecialChar ~
13848 \SpecialChar ~
13849 \SpecialChar ~
13850 \SpecialChar ~
13851 \SpecialChar ~
13852 psw
13853 \newline 
13854 \SpecialChar ~
13855 \SpecialChar ~
13856 \SpecialChar ~
13857 \SpecialChar ~
13858 pop\SpecialChar ~
13859 \SpecialChar ~
13860 \SpecialChar ~
13861 \SpecialChar ~
13862 \SpecialChar ~
13863 dph
13864 \newline 
13865 \SpecialChar ~
13866 \SpecialChar ~
13867 \SpecialChar ~
13868 \SpecialChar ~
13869 pop\SpecialChar ~
13870 \SpecialChar ~
13871 \SpecialChar ~
13872 \SpecialChar ~
13873 \SpecialChar ~
13874 dpl
13875 \newline 
13876 \SpecialChar ~
13877 \SpecialChar ~
13878 \SpecialChar ~
13879 \SpecialChar ~
13880 pop\SpecialChar ~
13881 \SpecialChar ~
13882 \SpecialChar ~
13883 \SpecialChar ~
13884 \SpecialChar ~
13885 b
13886 \newline 
13887 \SpecialChar ~
13888 \SpecialChar ~
13889 \SpecialChar ~
13890 \SpecialChar ~
13891 pop\SpecialChar ~
13892 \SpecialChar ~
13893 \SpecialChar ~
13894 \SpecialChar ~
13895 \SpecialChar ~
13896 acc
13897 \newline 
13898 \SpecialChar ~
13899 \SpecialChar ~
13900 \SpecialChar ~
13901 \SpecialChar ~
13902 reti
13903 \layout Standard
13904
13905 whereas nakedInterrupt looks like:
13906 \layout Verse
13907
13908
13909 \family typewriter 
13910 _nakedInterrupt:
13911 \newline 
13912 \SpecialChar ~
13913 \SpecialChar ~
13914 \SpecialChar ~
13915 \SpecialChar ~
13916 inc\SpecialChar ~
13917 \SpecialChar ~
13918 \SpecialChar ~
13919 \SpecialChar ~
13920 _counter ; does not change flags, no need to save psw
13921 \newline 
13922 \SpecialChar ~
13923 \SpecialChar ~
13924 \SpecialChar ~
13925 \SpecialChar ~
13926 reti\SpecialChar ~
13927 \SpecialChar ~
13928 \SpecialChar ~
13929 \SpecialChar ~
13930 \SpecialChar ~
13931 \SpecialChar ~
13932 \SpecialChar ~
13933 \SpecialChar ~
13934 \SpecialChar ~
13935 \SpecialChar ~
13936 \SpecialChar ~
13937 \SpecialChar ~
13938 ; MUST explicitly include ret or reti in _naked function
13939 \layout Standard
13940
13941 The related directive #pragma exclude
13942 \begin_inset LatexCommand \index{\#pragma exclude}
13943
13944 \end_inset 
13945
13946  allows a more fine grained control over pushing & popping
13947 \begin_inset LatexCommand \index{push/pop}
13948
13949 \end_inset 
13950
13951  the registers.
13952 \layout Standard
13953
13954 While there is nothing preventing you from writing C code inside a 
13955 \family typewriter 
13956 _naked
13957 \family default 
13958  function, there are many ways to shoot yourself in the foot doing this,
13959  and it is recommended that you stick to inline assembler.
13960 \layout Subsection
13961
13962 Use of Labels within Inline Assembler
13963 \layout Standard
13964
13965 SDCC allows the use of in-line assembler with a few restrictions regarding
13966  labels.
13967  In older versions of the compiler all labels defined within inline assembler
13968  code 
13969 \emph on 
13970 had to be
13971 \emph default 
13972  of the form 
13973 \emph on 
13974 nnnnn$
13975 \emph default 
13976  where nnnn is a number less than 100 (which implies a limit of utmost 100
13977  inline assembler labels 
13978 \emph on 
13979 per function
13980 \emph default 
13981 \noun on 
13982 )
13983 \noun default 
13984 .
13985  
13986 \layout Verse
13987
13988
13989 \family typewriter 
13990 _asm
13991 \begin_inset LatexCommand \index{\_asm}
13992
13993 \end_inset 
13994
13995
13996 \begin_inset LatexCommand \index{\_\_asm}
13997
13998 \end_inset 
13999
14000  
14001 \newline 
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 \SpecialChar ~
14005 \SpecialChar ~
14006 mov\SpecialChar ~
14007 \SpecialChar ~
14008 \SpecialChar ~
14009 \SpecialChar ~
14010 \SpecialChar ~
14011 b,#10 
14012 \newline 
14013 00001$: 
14014 \newline 
14015 \SpecialChar ~
14016 \SpecialChar ~
14017 \SpecialChar ~
14018 \SpecialChar ~
14019 djnz\SpecialChar ~
14020 \SpecialChar ~
14021 \SpecialChar ~
14022 \SpecialChar ~
14023 b,00001$ 
14024 \newline 
14025 _endasm
14026 \begin_inset LatexCommand \index{\_endasm}
14027
14028 \end_inset 
14029
14030
14031 \begin_inset LatexCommand \index{\_\_endasm}
14032
14033 \end_inset 
14034
14035  ;
14036 \layout Standard
14037
14038 Inline assembler code cannot reference any C-Labels, however it can reference
14039  labels
14040 \begin_inset LatexCommand \index{Labels}
14041
14042 \end_inset 
14043
14044  defined by the inline assembler, e.g.:
14045 \layout Verse
14046
14047
14048 \family typewriter 
14049 foo() { 
14050 \newline 
14051 \SpecialChar ~
14052 \SpecialChar ~
14053 \SpecialChar ~
14054 \SpecialChar ~
14055 /* some c code */ 
14056 \newline 
14057 \SpecialChar ~
14058 \SpecialChar ~
14059 \SpecialChar ~
14060 \SpecialChar ~
14061 _asm 
14062 \newline 
14063 \SpecialChar ~
14064 \SpecialChar ~
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 \SpecialChar ~
14068 \SpecialChar ~
14069 ; some assembler code 
14070 \newline 
14071 \SpecialChar ~
14072 \SpecialChar ~
14073 \SpecialChar ~
14074 \SpecialChar ~
14075 \SpecialChar ~
14076 \SpecialChar ~
14077 ljmp $0003 
14078 \newline 
14079 \SpecialChar ~
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 _endasm; 
14084 \newline 
14085 \SpecialChar ~
14086 \SpecialChar ~
14087 \SpecialChar ~
14088 \SpecialChar ~
14089 /* some more c code */ 
14090 \newline 
14091 clabel:\SpecialChar ~
14092 \SpecialChar ~
14093 /* inline assembler cannot reference this label */ 
14094 \newline 
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 \SpecialChar ~
14099 _asm
14100 \newline 
14101 \SpecialChar ~
14102 \SpecialChar ~
14103 \SpecialChar ~
14104 \SpecialChar ~
14105 $0003: ;label (can be referenced by inline assembler only) 
14106 \newline 
14107 \SpecialChar ~
14108 \SpecialChar ~
14109 \SpecialChar ~
14110 \SpecialChar ~
14111 _endasm
14112 \begin_inset LatexCommand \index{\_endasm}
14113
14114 \end_inset 
14115
14116
14117 \begin_inset LatexCommand \index{\_\_endasm}
14118
14119 \end_inset 
14120
14121  ; 
14122 \newline 
14123 \SpecialChar ~
14124 \SpecialChar ~
14125 \SpecialChar ~
14126 \SpecialChar ~
14127 /* some more c code */
14128 \newline 
14129 }
14130 \layout Standard
14131
14132 In other words inline assembly code can access labels defined in inline
14133  assembly within the scope of the function.
14134  The same goes the other way, i.e.
14135  labels defines in inline assembly can not be accessed by C statements.
14136 \layout Section
14137
14138 Interfacing with Assembler Code
14139 \begin_inset LatexCommand \index{Assembler routines}
14140
14141 \end_inset 
14142
14143
14144 \layout Subsection
14145
14146 Global Registers used for Parameter Passing
14147 \begin_inset LatexCommand \index{Parameter passing}
14148
14149 \end_inset 
14150
14151
14152 \layout Standard
14153
14154 The compiler always uses the global registers 
14155 \emph on 
14156 DPL, DPH
14157 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14158
14159 \end_inset 
14160
14161
14162 \begin_inset LatexCommand \index{DPTR}
14163
14164 \end_inset 
14165
14166 , B
14167 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14168
14169 \end_inset 
14170
14171  
14172 \emph default 
14173 and
14174 \emph on 
14175  ACC
14176 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14177
14178 \end_inset 
14179
14180
14181 \emph default 
14182  to pass the first parameter to a routine.
14183  The second parameter onwards is either allocated on the stack (for reentrant
14184  routines or if -
14185 \begin_inset ERT
14186 status Collapsed
14187
14188 \layout Standard
14189
14190 \backslash 
14191 /
14192 \end_inset 
14193
14194 -stack-auto is used) or in data / xdata memory (depending on the memory
14195  model).
14196  
14197 \layout Subsection
14198
14199 Assembler Routine (non-reentrant)
14200 \layout Standard
14201
14202 In the following example
14203 \begin_inset LatexCommand \index{reentrant}
14204
14205 \end_inset 
14206
14207
14208 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14209
14210 \end_inset 
14211
14212  the function c_func calls an assembler routine asm_func, which takes two
14213  parameters
14214 \begin_inset LatexCommand \index{function parameter}
14215
14216 \end_inset 
14217
14218 .
14219 \layout Verse
14220
14221
14222 \family typewriter 
14223 extern int asm_func(unsigned char, unsigned char);
14224 \newline 
14225
14226 \newline 
14227 int c_func (unsigned char i, unsigned char j)
14228 \newline 
14229 {
14230 \newline 
14231 \SpecialChar ~
14232 \SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 return asm_func(i,j);
14236 \newline 
14237 }
14238 \newline 
14239
14240 \newline 
14241 int main()
14242 \newline 
14243 {
14244 \newline 
14245 \SpecialChar ~
14246 \SpecialChar ~
14247 \SpecialChar ~
14248 \SpecialChar ~
14249 return c_func(10,9);
14250 \newline 
14251 }
14252 \layout Standard
14253
14254 The corresponding assembler function is:
14255 \layout Verse
14256
14257
14258 \family typewriter 
14259 .globl _asm_func_PARM_2 
14260 \newline 
14261 \SpecialChar ~
14262 \SpecialChar ~
14263 \SpecialChar ~
14264 \SpecialChar ~
14265 \SpecialChar ~
14266 \SpecialChar ~
14267 \SpecialChar ~
14268 \SpecialChar ~
14269 .globl _asm_func 
14270 \newline 
14271 \SpecialChar ~
14272 \SpecialChar ~
14273 \SpecialChar ~
14274 \SpecialChar ~
14275 \SpecialChar ~
14276 \SpecialChar ~
14277 \SpecialChar ~
14278 \SpecialChar ~
14279 .area OSEG 
14280 \newline 
14281 _asm_func_PARM_2:
14282 \newline 
14283 \SpecialChar ~
14284 \SpecialChar ~
14285 \SpecialChar ~
14286 \SpecialChar ~
14287 \SpecialChar ~
14288 \SpecialChar ~
14289 \SpecialChar ~
14290 \SpecialChar ~
14291 .ds    1 
14292 \newline 
14293 \SpecialChar ~
14294 \SpecialChar ~
14295 \SpecialChar ~
14296 \SpecialChar ~
14297 \SpecialChar ~
14298 \SpecialChar ~
14299 \SpecialChar ~
14300 \SpecialChar ~
14301 .area CSEG 
14302 \newline 
14303 _asm_func: 
14304 \newline 
14305 \SpecialChar ~
14306 \SpecialChar ~
14307 \SpecialChar ~
14308 \SpecialChar ~
14309 \SpecialChar ~
14310 \SpecialChar ~
14311 \SpecialChar ~
14312 \SpecialChar ~
14313 mov\SpecialChar ~
14314 \SpecialChar ~
14315 \SpecialChar ~
14316 \SpecialChar ~
14317 a,dpl 
14318 \newline 
14319 \SpecialChar ~
14320 \SpecialChar ~
14321 \SpecialChar ~
14322 \SpecialChar ~
14323 \SpecialChar ~
14324 \SpecialChar ~
14325 \SpecialChar ~
14326 \SpecialChar ~
14327 add\SpecialChar ~
14328 \SpecialChar ~
14329 \SpecialChar ~
14330 \SpecialChar ~
14331 a,_asm_func_PARM_2 
14332 \newline 
14333 \SpecialChar ~
14334 \SpecialChar ~
14335 \SpecialChar ~
14336 \SpecialChar ~
14337 \SpecialChar ~
14338 \SpecialChar ~
14339 \SpecialChar ~
14340 \SpecialChar ~
14341 mov\SpecialChar ~
14342 \SpecialChar ~
14343 \SpecialChar ~
14344 \SpecialChar ~
14345 dpl,a 
14346 \newline 
14347 \SpecialChar ~
14348 \SpecialChar ~
14349 \SpecialChar ~
14350 \SpecialChar ~
14351 \SpecialChar ~
14352 \SpecialChar ~
14353 \SpecialChar ~
14354 \SpecialChar ~
14355 mov\SpecialChar ~
14356 \SpecialChar ~
14357 \SpecialChar ~
14358 \SpecialChar ~
14359 dph
14360 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14361
14362 \end_inset 
14363
14364 ,#0x00 
14365 \newline 
14366 \SpecialChar ~
14367 \SpecialChar ~
14368 \SpecialChar ~
14369 \SpecialChar ~
14370 \SpecialChar ~
14371 \SpecialChar ~
14372 \SpecialChar ~
14373 \SpecialChar ~
14374 ret
14375 \layout Standard
14376
14377 Note here that the return values
14378 \begin_inset LatexCommand \index{return value}
14379
14380 \end_inset 
14381
14382  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14383  two byte values.
14384  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14385 b' & 'acc' for four byte values.
14386 \layout Standard
14387
14388 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14389  the parameter number starting from 1, and counting from the left.
14390  The first parameter is passed in 
14391 \begin_inset Quotes eld
14392 \end_inset 
14393
14394 dpl
14395 \begin_inset Quotes erd
14396 \end_inset 
14397
14398  for a one byte parameter, 
14399 \begin_inset Quotes eld
14400 \end_inset 
14401
14402 dptr
14403 \begin_inset Quotes erd
14404 \end_inset 
14405
14406  for two bytes, 
14407 \begin_inset Quotes eld
14408 \end_inset 
14409
14410 b,dptr
14411 \begin_inset Quotes erd
14412 \end_inset 
14413
14414  for three bytes and 
14415 \begin_inset Quotes eld
14416 \end_inset 
14417
14418 acc,b,dptr
14419 \begin_inset Quotes erd
14420 \end_inset 
14421
14422  for a four bytes parameter.
14423  The variable name for the second parameter will be _<function_name>_PARM_2.
14424 \newline 
14425
14426 \newline 
14427 Assemble the assembler routine with the following command:
14428 \newline 
14429
14430 \newline 
14431
14432 \family sans 
14433 \series bold 
14434 asx8051 -losg asmfunc.asm
14435 \newline 
14436
14437 \newline 
14438
14439 \family default 
14440 \series default 
14441 Then compile and link the assembler routine to the C source file with the
14442  following command:
14443 \newline 
14444
14445 \newline 
14446
14447 \family sans 
14448 \series bold 
14449 sdcc cfunc.c asmfunc.rel
14450 \layout Subsection
14451
14452 Assembler Routine (reentrant)
14453 \layout Standard
14454
14455 In this case
14456 \begin_inset LatexCommand \index{reentrant}
14457
14458 \end_inset 
14459
14460
14461 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14462
14463 \end_inset 
14464
14465  the second parameter
14466 \begin_inset LatexCommand \index{function parameter}
14467
14468 \end_inset 
14469
14470  onwards will be passed on the stack, the parameters are pushed from right
14471  to left i.e.
14472  after the call the leftmost parameter will be on the top of the stack.
14473  Here is an example:
14474 \layout Verse
14475
14476
14477 \family typewriter 
14478 extern int asm_func(unsigned char, unsigned char);
14479 \newline 
14480
14481 \newline 
14482 int c_func (unsigned char i, unsigned char j) reentrant 
14483 \newline 
14484
14485 \newline 
14486 \SpecialChar ~
14487 \SpecialChar ~
14488 \SpecialChar ~
14489 \SpecialChar ~
14490 return asm_func(i,j); 
14491 \newline 
14492
14493 \newline 
14494
14495 \newline 
14496 int main() 
14497 \newline 
14498
14499 \newline 
14500 \SpecialChar ~
14501 \SpecialChar ~
14502 \SpecialChar ~
14503 \SpecialChar ~
14504 return c_func(10,9); 
14505 \newline 
14506 }
14507 \layout Standard
14508
14509 The corresponding assembler routine is:
14510 \layout Verse
14511
14512
14513 \family typewriter 
14514 .globl _asm_func 
14515 \newline 
14516 _asm_func: 
14517 \newline 
14518 \SpecialChar ~
14519 \SpecialChar ~
14520 \SpecialChar ~
14521 \SpecialChar ~
14522 push  _bp 
14523 \newline 
14524 \SpecialChar ~
14525 \SpecialChar ~
14526 \SpecialChar ~
14527 \SpecialChar ~
14528 mov _bp,sp 
14529 \newline 
14530 \SpecialChar ~
14531 \SpecialChar ~
14532 \SpecialChar ~
14533 \SpecialChar ~
14534 mov r2,dpl
14535 \newline 
14536 \SpecialChar ~
14537 \SpecialChar ~
14538 \SpecialChar ~
14539 \SpecialChar ~
14540 mov a,_bp 
14541 \newline 
14542 \SpecialChar ~
14543 \SpecialChar ~
14544 \SpecialChar ~
14545 \SpecialChar ~
14546 add a,#0xfd 
14547 \newline 
14548 \SpecialChar ~
14549 \SpecialChar ~
14550 \SpecialChar ~
14551 \SpecialChar ~
14552 mov r0,a 
14553 \newline 
14554 \SpecialChar ~
14555 \SpecialChar ~
14556 \SpecialChar ~
14557 \SpecialChar ~
14558 add  a,#0xfc ;?
14559 \newline 
14560 \SpecialChar ~
14561 \SpecialChar ~
14562 \SpecialChar ~
14563 \SpecialChar ~
14564 mov  r1,a 
14565 \newline 
14566 \SpecialChar ~
14567 \SpecialChar ~
14568 \SpecialChar ~
14569 \SpecialChar ~
14570 mov  a,@r0 
14571 \newline 
14572 \SpecialChar ~
14573 \SpecialChar ~
14574 \SpecialChar ~
14575 \SpecialChar ~
14576 add  a,r2 ;?
14577 \newline 
14578 \SpecialChar ~
14579 \SpecialChar ~
14580 \SpecialChar ~
14581 \SpecialChar ~
14582 mov  dpl,a 
14583 \newline 
14584 \SpecialChar ~
14585 \SpecialChar ~
14586 \SpecialChar ~
14587 \SpecialChar ~
14588 mov  dph,#0x00 
14589 \newline 
14590 \SpecialChar ~
14591 \SpecialChar ~
14592 \SpecialChar ~
14593 \SpecialChar ~
14594 mov  sp,_bp 
14595 \newline 
14596 \SpecialChar ~
14597 \SpecialChar ~
14598 \SpecialChar ~
14599 \SpecialChar ~
14600 pop  _bp 
14601 \newline 
14602 \SpecialChar ~
14603 \SpecialChar ~
14604 \SpecialChar ~
14605 \SpecialChar ~
14606 ret
14607 \layout Standard
14608 \added_space_bottom bigskip 
14609 The compiling and linking procedure remains the same, however note the extra
14610  entry & exit linkage required for the assembler code, _bp is the stack
14611  frame pointer and is used to compute the offset into the stack for parameters
14612  and local variables.
14613 \layout Section
14614
14615 int (16 bit)
14616 \begin_inset LatexCommand \index{int (16 bit)}
14617
14618 \end_inset 
14619
14620  and long (32 bit)
14621 \begin_inset LatexCommand \index{long (32 bit)}
14622
14623 \end_inset 
14624
14625  Support
14626 \layout Standard
14627
14628 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14629  multiplication and modulus operations are implemented by support routines.
14630  These support routines are all developed in ANSI-C to facilitate porting
14631  to other MCUs, although some model specific assembler optimizations are
14632  used.
14633  The following files contain the described routines, all of them can be
14634  found in <installdir>/share/sdcc/lib.
14635 \newline 
14636
14637 \layout Standard
14638 \align center 
14639
14640 \begin_inset  Tabular
14641 <lyxtabular version="3" rows="11" columns="2">
14642 <features>
14643 <column alignment="left" valignment="top" leftline="true" width="0">
14644 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14645 <row topline="true" bottomline="true">
14646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14647 \begin_inset Text
14648
14649 \layout Standard
14650
14651
14652 \series bold 
14653 Function
14654 \end_inset 
14655 </cell>
14656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14657 \begin_inset Text
14658
14659 \layout Standard
14660
14661
14662 \series bold 
14663 Description
14664 \end_inset 
14665 </cell>
14666 </row>
14667 <row topline="true">
14668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14669 \begin_inset Text
14670
14671 \layout Standard
14672
14673 _mulint.c 
14674 \end_inset 
14675 </cell>
14676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14677 \begin_inset Text
14678
14679 \layout Standard
14680
14681 16 bit multiplication
14682 \end_inset 
14683 </cell>
14684 </row>
14685 <row topline="true">
14686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14687 \begin_inset Text
14688
14689 \layout Standard
14690
14691 _divsint.c 
14692 \end_inset 
14693 </cell>
14694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14695 \begin_inset Text
14696
14697 \layout Standard
14698
14699  signed 16 bit division (calls _divuint)
14700 \end_inset 
14701 </cell>
14702 </row>
14703 <row topline="true">
14704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14705 \begin_inset Text
14706
14707 \layout Standard
14708
14709 _divuint.c 
14710 \end_inset 
14711 </cell>
14712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14713 \begin_inset Text
14714
14715 \layout Standard
14716
14717  unsigned 16 bit division
14718 \end_inset 
14719 </cell>
14720 </row>
14721 <row topline="true">
14722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14723 \begin_inset Text
14724
14725 \layout Standard
14726
14727 _modsint.c
14728 \end_inset 
14729 </cell>
14730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14731 \begin_inset Text
14732
14733 \layout Standard
14734
14735 signed 16 bit modulus (calls _moduint)
14736 \end_inset 
14737 </cell>
14738 </row>
14739 <row topline="true">
14740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14741 \begin_inset Text
14742
14743 \layout Standard
14744
14745 _moduint.c
14746 \end_inset 
14747 </cell>
14748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14749 \begin_inset Text
14750
14751 \layout Standard
14752
14753 unsigned 16 bit modulus
14754 \end_inset 
14755 </cell>
14756 </row>
14757 <row topline="true">
14758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14759 \begin_inset Text
14760
14761 \layout Standard
14762
14763 _mullong.c
14764 \end_inset 
14765 </cell>
14766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14767 \begin_inset Text
14768
14769 \layout Standard
14770
14771 32 bit multiplication
14772 \end_inset 
14773 </cell>
14774 </row>
14775 <row topline="true">
14776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14777 \begin_inset Text
14778
14779 \layout Standard
14780
14781 _divslong.c 
14782 \end_inset 
14783 </cell>
14784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14785 \begin_inset Text
14786
14787 \layout Standard
14788
14789  signed 32 division (calls _divulong)
14790 \end_inset 
14791 </cell>
14792 </row>
14793 <row topline="true">
14794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14795 \begin_inset Text
14796
14797 \layout Standard
14798
14799 _divulong.c 
14800 \end_inset 
14801 </cell>
14802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14803 \begin_inset Text
14804
14805 \layout Standard
14806
14807 unsigned 32 division
14808 \end_inset 
14809 </cell>
14810 </row>
14811 <row topline="true">
14812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14813 \begin_inset Text
14814
14815 \layout Standard
14816
14817 _modslong.c
14818 \end_inset 
14819 </cell>
14820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14821 \begin_inset Text
14822
14823 \layout Standard
14824
14825  signed 32 bit modulus (calls _modulong)
14826 \end_inset 
14827 </cell>
14828 </row>
14829 <row topline="true" bottomline="true">
14830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14831 \begin_inset Text
14832
14833 \layout Standard
14834
14835 _modulong.c
14836 \end_inset 
14837 </cell>
14838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14839 \begin_inset Text
14840
14841 \layout Standard
14842
14843 unsigned 32 bit modulus
14844 \end_inset 
14845 </cell>
14846 </row>
14847 </lyxtabular>
14848
14849 \end_inset 
14850
14851
14852 \newline 
14853
14854 \layout Standard
14855
14856 Since they are compiled as 
14857 \emph on 
14858 non-reentrant
14859 \emph default 
14860
14861 \begin_inset LatexCommand \index{reentrant}
14862
14863 \end_inset 
14864
14865 , interrupt
14866 \begin_inset LatexCommand \index{interrupt}
14867
14868 \end_inset 
14869
14870  service routines should not do any of the above operations.
14871  If this is unavoidable then the above routines will need to be compiled
14872  with the 
14873 \emph on 
14874 -
14875 \begin_inset ERT
14876 status Collapsed
14877
14878 \layout Standard
14879
14880 \backslash 
14881 /
14882 \end_inset 
14883
14884 -stack-auto
14885 \begin_inset LatexCommand \index{-\/-stack-auto}
14886
14887 \end_inset 
14888
14889
14890 \emph default 
14891  option, after which the source program will have to be compiled with 
14892 \emph on 
14893 -
14894 \begin_inset ERT
14895 status Collapsed
14896
14897 \layout Standard
14898
14899 \backslash 
14900 /
14901 \end_inset 
14902
14903 -int-long-reent
14904 \begin_inset LatexCommand \index{-\/-int-long-reent}
14905
14906 \end_inset 
14907
14908
14909 \emph default 
14910  option.
14911  Notice that you don't have to call these routines directly.
14912  The compiler will use them automatically every time an integer operation
14913  is required.
14914 \layout Section
14915
14916 Floating Point Support
14917 \begin_inset LatexCommand \index{Floating point support}
14918
14919 \end_inset 
14920
14921
14922 \layout Standard
14923
14924 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
14925  The floating point support routines are derived from gcc's floatlib.c and
14926  consist of the following routines:
14927 \newline 
14928
14929 \layout Standard
14930 \align center 
14931
14932 \size footnotesize 
14933
14934 \begin_inset  Tabular
14935 <lyxtabular version="3" rows="17" columns="2">
14936 <features>
14937 <column alignment="left" valignment="top" leftline="true" width="0">
14938 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14939 <row topline="true" bottomline="true">
14940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14941 \begin_inset Text
14942
14943 \layout Standard
14944
14945
14946 \family roman 
14947 \series medium 
14948 \shape up 
14949 \size normal 
14950 \emph off 
14951 \bar no 
14952 \noun off 
14953 \color none
14954 Function 
14955 \end_inset 
14956 </cell>
14957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14958 \begin_inset Text
14959
14960 \layout Standard
14961
14962 Description
14963 \end_inset 
14964 </cell>
14965 </row>
14966 <row topline="true">
14967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14968 \begin_inset Text
14969
14970 \layout Standard
14971
14972
14973 \family roman 
14974 \series medium 
14975 \shape up 
14976 \size normal 
14977 \emph off 
14978 \bar no 
14979 \noun off 
14980 \color none
14981 _fsadd.c
14982 \end_inset 
14983 </cell>
14984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14985 \begin_inset Text
14986
14987 \layout Standard
14988
14989
14990 \family roman 
14991 \series medium 
14992 \shape up 
14993 \size normal 
14994 \emph off 
14995 \bar no 
14996 \noun off 
14997 \color none
14998 add floating point numbers
14999 \end_inset 
15000 </cell>
15001 </row>
15002 <row topline="true">
15003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15004 \begin_inset Text
15005
15006 \layout Standard
15007
15008
15009 \family roman 
15010 \series medium 
15011 \shape up 
15012 \size normal 
15013 \emph off 
15014 \bar no 
15015 \noun off 
15016 \color none
15017 _fssub.c 
15018 \end_inset 
15019 </cell>
15020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15021 \begin_inset Text
15022
15023 \layout Standard
15024
15025
15026 \family roman 
15027 \series medium 
15028 \shape up 
15029 \size normal 
15030 \emph off 
15031 \bar no 
15032 \noun off 
15033 \color none
15034 subtract floating point numbers 
15035 \end_inset 
15036 </cell>
15037 </row>
15038 <row topline="true">
15039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15040 \begin_inset Text
15041
15042 \layout Standard
15043
15044
15045 \family roman 
15046 \series medium 
15047 \shape up 
15048 \size normal 
15049 \emph off 
15050 \bar no 
15051 \noun off 
15052 \color none
15053 _fsdiv.c 
15054 \end_inset 
15055 </cell>
15056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15057 \begin_inset Text
15058
15059 \layout Standard
15060
15061
15062 \family roman 
15063 \series medium 
15064 \shape up 
15065 \size normal 
15066 \emph off 
15067 \bar no 
15068 \noun off 
15069 \color none
15070 divide floating point numbers 
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
15081 \family roman 
15082 \series medium 
15083 \shape up 
15084 \size normal 
15085 \emph off 
15086 \bar no 
15087 \noun off 
15088 \color none
15089 _fsmul.c 
15090 \end_inset 
15091 </cell>
15092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15093 \begin_inset Text
15094
15095 \layout Standard
15096
15097
15098 \family roman 
15099 \series medium 
15100 \shape up 
15101 \size normal 
15102 \emph off 
15103 \bar no 
15104 \noun off 
15105 \color none
15106 multiply floating point numbers 
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
15117 \family roman 
15118 \series medium 
15119 \shape up 
15120 \size normal 
15121 \emph off 
15122 \bar no 
15123 \noun off 
15124 \color none
15125 _fs2uchar.c
15126 \end_inset 
15127 </cell>
15128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15129 \begin_inset Text
15130
15131 \layout Standard
15132
15133
15134 \family roman 
15135 \series medium 
15136 \shape up 
15137 \size normal 
15138 \emph off 
15139 \bar no 
15140 \noun off 
15141 \color none
15142 convert floating point to unsigned char
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
15153 \family roman 
15154 \series medium 
15155 \shape up 
15156 \size normal 
15157 \emph off 
15158 \bar no 
15159 \noun off 
15160 \color none
15161 _fs2char.c
15162 \end_inset 
15163 </cell>
15164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15165 \begin_inset Text
15166
15167 \layout Standard
15168
15169
15170 \family roman 
15171 \series medium 
15172 \shape up 
15173 \size normal 
15174 \emph off 
15175 \bar no 
15176 \noun off 
15177 \color none
15178 convert floating point to signed char
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
15189 \family roman 
15190 \series medium 
15191 \shape up 
15192 \size normal 
15193 \emph off 
15194 \bar no 
15195 \noun off 
15196 \color none
15197 _fs2uint.c
15198 \end_inset 
15199 </cell>
15200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15201 \begin_inset Text
15202
15203 \layout Standard
15204
15205
15206 \family roman 
15207 \series medium 
15208 \shape up 
15209 \size normal 
15210 \emph off 
15211 \bar no 
15212 \noun off 
15213 \color none
15214 convert floating point to unsigned int
15215 \end_inset 
15216 </cell>
15217 </row>
15218 <row topline="true">
15219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15220 \begin_inset Text
15221
15222 \layout Standard
15223
15224
15225 \family roman 
15226 \series medium 
15227 \shape up 
15228 \size normal 
15229 \emph off 
15230 \bar no 
15231 \noun off 
15232 \color none
15233 _fs2int.c
15234 \end_inset 
15235 </cell>
15236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15237 \begin_inset Text
15238
15239 \layout Standard
15240
15241
15242 \family roman 
15243 \series medium 
15244 \shape up 
15245 \size normal 
15246 \emph off 
15247 \bar no 
15248 \noun off 
15249 \color none
15250 convert floating point to signed int
15251 \end_inset 
15252 </cell>
15253 </row>
15254 <row topline="true">
15255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15256 \begin_inset Text
15257
15258 \layout Standard
15259
15260
15261 \family roman 
15262 \series medium 
15263 \shape up 
15264 \size normal 
15265 \emph off 
15266 \bar no 
15267 \noun off 
15268 \color none
15269 _fs2ulong.
15270 \family default 
15271 \series default 
15272 \shape default 
15273 \size default 
15274 \emph default 
15275 \bar default 
15276 \noun default 
15277 \color default
15278 c
15279 \end_inset 
15280 </cell>
15281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15282 \begin_inset Text
15283
15284 \layout Standard
15285
15286
15287 \family roman 
15288 \series medium 
15289 \shape up 
15290 \size normal 
15291 \emph off 
15292 \bar no 
15293 \noun off 
15294 \color none
15295 convert floating point to unsigned long
15296 \end_inset 
15297 </cell>
15298 </row>
15299 <row topline="true">
15300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15301 \begin_inset Text
15302
15303 \layout Standard
15304
15305
15306 \family roman 
15307 \series medium 
15308 \shape up 
15309 \size normal 
15310 \emph off 
15311 \bar no 
15312 \noun off 
15313 \color none
15314 _fs2long.c
15315 \end_inset 
15316 </cell>
15317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15318 \begin_inset Text
15319
15320 \layout Standard
15321
15322
15323 \family roman 
15324 \series medium 
15325 \shape up 
15326 \size normal 
15327 \emph off 
15328 \bar no 
15329 \noun off 
15330 \color none
15331 convert floating point to signed long
15332 \end_inset 
15333 </cell>
15334 </row>
15335 <row topline="true">
15336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15337 \begin_inset Text
15338
15339 \layout Standard
15340
15341
15342 \family roman 
15343 \series medium 
15344 \shape up 
15345 \size normal 
15346 \emph off 
15347 \bar no 
15348 \noun off 
15349 \color none
15350 _uchar2fs.c
15351 \end_inset 
15352 </cell>
15353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15354 \begin_inset Text
15355
15356 \layout Standard
15357
15358
15359 \family roman 
15360 \series medium 
15361 \shape up 
15362 \size normal 
15363 \emph off 
15364 \bar no 
15365 \noun off 
15366 \color none
15367 convert unsigned char to floating point
15368 \end_inset 
15369 </cell>
15370 </row>
15371 <row topline="true">
15372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15373 \begin_inset Text
15374
15375 \layout Standard
15376
15377
15378 \family roman 
15379 \series medium 
15380 \shape up 
15381 \size normal 
15382 \emph off 
15383 \bar no 
15384 \noun off 
15385 \color none
15386 _char2fs.c
15387 \end_inset 
15388 </cell>
15389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15390 \begin_inset Text
15391
15392 \layout Standard
15393
15394
15395 \family roman 
15396 \series medium 
15397 \shape up 
15398 \size normal 
15399 \emph off 
15400 \bar no 
15401 \noun off 
15402 \color none
15403 convert char to floating point number
15404 \end_inset 
15405 </cell>
15406 </row>
15407 <row topline="true">
15408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15409 \begin_inset Text
15410
15411 \layout Standard
15412
15413
15414 \family roman 
15415 \series medium 
15416 \shape up 
15417 \size normal 
15418 \emph off 
15419 \bar no 
15420 \noun off 
15421 \color none
15422 _uint2fs.c
15423 \end_inset 
15424 </cell>
15425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15426 \begin_inset Text
15427
15428 \layout Standard
15429
15430
15431 \family roman 
15432 \series medium 
15433 \shape up 
15434 \size normal 
15435 \emph off 
15436 \bar no 
15437 \noun off 
15438 \color none
15439 convert unsigned int to floating point
15440 \end_inset 
15441 </cell>
15442 </row>
15443 <row topline="true">
15444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15445 \begin_inset Text
15446
15447 \layout Standard
15448
15449
15450 \family roman 
15451 \series medium 
15452 \shape up 
15453 \size normal 
15454 \emph off 
15455 \bar no 
15456 \noun off 
15457 \color none
15458 _int2fs.c
15459 \end_inset 
15460 </cell>
15461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15462 \begin_inset Text
15463
15464 \layout Standard
15465
15466
15467 \family roman 
15468 \series medium 
15469 \shape up 
15470 \size normal 
15471 \emph off 
15472 \bar no 
15473 \noun off 
15474 \color none
15475 convert int to floating point numbers
15476 \end_inset 
15477 </cell>
15478 </row>
15479 <row topline="true">
15480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15481 \begin_inset Text
15482
15483 \layout Standard
15484
15485
15486 \family roman 
15487 \series medium 
15488 \shape up 
15489 \size normal 
15490 \emph off 
15491 \bar no 
15492 \noun off 
15493 \color none
15494 _ulong2fs.c
15495 \end_inset 
15496 </cell>
15497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15498 \begin_inset Text
15499
15500 \layout Standard
15501
15502
15503 \family roman 
15504 \series medium 
15505 \shape up 
15506 \size normal 
15507 \emph off 
15508 \bar no 
15509 \noun off 
15510 \color none
15511 convert unsigned long to floating point number
15512 \end_inset 
15513 </cell>
15514 </row>
15515 <row topline="true" bottomline="true">
15516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15517 \begin_inset Text
15518
15519 \layout Standard
15520
15521
15522 \family roman 
15523 \series medium 
15524 \shape up 
15525 \size normal 
15526 \emph off 
15527 \bar no 
15528 \noun off 
15529 \color none
15530 _long2fs.c
15531 \end_inset 
15532 </cell>
15533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15534 \begin_inset Text
15535
15536 \layout Standard
15537
15538
15539 \family roman 
15540 \series medium 
15541 \shape up 
15542 \size normal 
15543 \emph off 
15544 \bar no 
15545 \noun off 
15546 \color none
15547 convert long to floating point number
15548 \end_inset 
15549 </cell>
15550 </row>
15551 </lyxtabular>
15552
15553 \end_inset 
15554
15555
15556 \newline 
15557
15558 \layout Standard
15559 \added_space_bottom bigskip 
15560 These support routines are developed in ANSI-C so there is room for space
15561  and speed improvement
15562 \begin_inset Foot
15563 collapsed false
15564
15565 \layout Standard
15566
15567 These floating point routines (
15568 \emph on 
15569 not
15570 \emph default 
15571  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15572  
15573 \end_inset 
15574
15575 .
15576  Note if all these routines are used simultaneously the data space might
15577  overflow.
15578  For serious floating point usage the large model might be needed.
15579  Also notice that you don't have to call this routines directly.
15580  The compiler will use them automatically every time a floating point operation
15581  is required.
15582 \layout Section
15583
15584 Library Routines
15585 \begin_inset LatexCommand \index{Libraries}
15586
15587 \end_inset 
15588
15589
15590 \layout Standard
15591
15592
15593 \emph on 
15594 <pending: this is messy and incomplete - a little more information is in
15595  sdcc/doc/libdoc.txt
15596 \emph default 
15597  >
15598 \layout Subsection
15599
15600 Compiler support routines (_gptrget, _mulint etc.)
15601 \layout Subsection
15602
15603 Stdclib functions (puts, printf, strcat etc.)
15604 \layout Subsubsection
15605
15606 <stdio.h>
15607 \layout Standard
15608
15609
15610 \begin_inset LatexCommand \index{<stdio.h>}
15611
15612 \end_inset 
15613
15614 As usual on embedded systems you have to provide your own 
15615 \family typewriter 
15616 getchar()
15617 \begin_inset LatexCommand \index{getchar()}
15618
15619 \end_inset 
15620
15621  
15622 \family default 
15623 and 
15624 \family typewriter 
15625 putchar()
15626 \begin_inset LatexCommand \index{putchar()}
15627
15628 \end_inset 
15629
15630
15631 \family default 
15632  routines.
15633  SDCC does not know whether the system connects to a serial line with or
15634  without handshake, LCD, keyboard or other device.
15635  And whether a 
15636 \family typewriter 
15637 lf
15638 \family default 
15639  to 
15640 \family typewriter 
15641 crlf
15642 \family default 
15643  conversion within 
15644 \family typewriter 
15645 putchar()
15646 \family default 
15647  is intended.
15648  You'll find examples for serial routines f.e.
15649  in sdcc/device/lib.
15650 \layout Standard
15651
15652 The default
15653 \family typewriter 
15654  printf()
15655 \begin_inset LatexCommand \index{printf()}
15656
15657 \end_inset 
15658
15659
15660 \family default 
15661 implementation in
15662 \family typewriter 
15663  printf_large.c
15664 \family default 
15665  does not support float (except on ds390).
15666  To enable this recompile it with the option 
15667 \emph on 
15668 -
15669 \begin_inset ERT
15670 status Collapsed
15671
15672 \layout Standard
15673
15674 \backslash 
15675 /
15676 \end_inset 
15677
15678 DUSE_FLOATS=1
15679 \begin_inset LatexCommand \index{USE\_FLOATS}
15680
15681 \end_inset 
15682
15683
15684 \emph default 
15685  on the command line.
15686  Use
15687 \emph on 
15688  -
15689 \begin_inset ERT
15690 status Collapsed
15691
15692 \layout Standard
15693
15694 \backslash 
15695 /
15696 \end_inset 
15697
15698 -model-large
15699 \begin_inset LatexCommand \index{-\/-model-large}
15700
15701 \end_inset 
15702
15703
15704 \emph default 
15705  for the mcs51 port, since this uses a lot of memory.
15706 \layout Standard
15707
15708 If you're short on memory you might want to use 
15709 \family typewriter 
15710 printf_small()
15711 \begin_inset LatexCommand \index{printf\_small()}
15712
15713 \end_inset 
15714
15715
15716 \family default 
15717  
15718 \emph on 
15719 instead
15720 \emph default 
15721  of
15722 \family typewriter 
15723  printf().
15724
15725 \family default 
15726  For the mcs51 there additionally are assembly versions 
15727 \family typewriter 
15728 printf_tiny()
15729 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
15730
15731 \end_inset 
15732
15733
15734 \family default 
15735  (subset of printf using less than 270 bytes) and 
15736 \family typewriter 
15737 printf_fast()
15738 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
15739
15740 \end_inset 
15741
15742  
15743 \family default 
15744 and
15745 \family typewriter 
15746  printf_fast_f()
15747 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
15748
15749 \end_inset 
15750
15751
15752 \family default 
15753  (floating-point aware version of printf_fast) which should fit the requirements
15754  of many embedded systems (printf_fast() can be customized by unsetting
15755  #defines to 
15756 \emph on 
15757 not
15758 \emph default 
15759  support long variables and field widths).
15760 \layout Subsubsection
15761
15762 <malloc.h>
15763 \begin_inset LatexCommand \index{malloc.h}
15764
15765 \end_inset 
15766
15767
15768 \layout Standard
15769
15770 Before using dynamic
15771 \begin_inset LatexCommand \index{dynamic}
15772
15773 \end_inset 
15774
15775  memory allocation with SDCC, you have to provide heap
15776 \begin_inset LatexCommand \index{heap}
15777
15778 \end_inset 
15779
15780  space for malloc to allocate memory from
15781 \family typewriter 
15782 .
15783  
15784 \family default 
15785 You can acomplish this by including the following code into your source:
15786 \layout Verse
15787
15788
15789 \family typewriter 
15790 #include <malloc.h>
15791 \begin_inset LatexCommand \index{malloc.h}
15792
15793 \end_inset 
15794
15795  /* calloc
15796 \begin_inset LatexCommand \index{calloc}
15797
15798 \end_inset 
15799
15800 , malloc
15801 \begin_inset LatexCommand \index{malloc}
15802
15803 \end_inset 
15804
15805 , realloc
15806 \begin_inset LatexCommand \index{realloc}
15807
15808 \end_inset 
15809
15810 , and free
15811 \begin_inset LatexCommand \index{free}
15812
15813 \end_inset 
15814
15815  */ 
15816 \newline 
15817
15818 \newline 
15819 #define HEAPSIZE 0x1000 /* Adjust depending on available memory */ 
15820 \newline 
15821 unsigned char xdata myheap[HEAPSIZE]; /* The actual heap for dynamic memory
15822  */ 
15823 \newline 
15824
15825 \newline 
15826 void main (void) 
15827 \newline 
15828
15829 \newline 
15830 \SpecialChar ~
15831 \SpecialChar ~
15832 \SpecialChar ~
15833 /* Your variable declarations come here*/
15834 \newline 
15835 \SpecialChar ~
15836 \SpecialChar ~
15837 \SpecialChar ~
15838 ...
15839 \newline 
15840 \SpecialChar ~
15841 \SpecialChar ~
15842 \SpecialChar ~
15843 init_dynamic_memory((MEMHEADER xdata *)myheap, HEAPSIZE);
15844 \newline 
15845 \SpecialChar ~
15846 \SpecialChar ~
15847 \SpecialChar ~
15848 ...
15849  /* Rest of your code*/
15850 \newline 
15851
15852 \newline 
15853
15854 \layout Subsection
15855
15856 Math functions (sinf, powf, sqrtf etc.)
15857 \layout Subsubsection
15858
15859 <math.h>
15860 \layout Standard
15861
15862 See definitions in file <math.h>.
15863 \layout Subsection
15864
15865 Other libraries
15866 \layout Standard
15867
15868 Libraries
15869 \begin_inset LatexCommand \index{Libraries}
15870
15871 \end_inset 
15872
15873  included in SDCC should have a license at least as liberal as the GNU Lesser
15874  General Public License
15875 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15876
15877 \end_inset 
15878
15879  
15880 \emph on 
15881 LGPL
15882 \emph default 
15883 .
15884 \layout Comment
15885
15886 license statements for the libraries are missing.
15887  sdcc/device/lib/ser_ir.c
15888 \layout Comment
15889
15890 or _decdptr f.e.
15891  come with a GPL (as opposed to LGPL) License - this will not be liberal
15892  enough for many embedded programmers.
15893 \layout Standard
15894
15895 If you have ported some library or want to share experience about some code
15896  which f.e.
15897  falls into any of these categories Busses (I
15898 \begin_inset Formula $^{\textrm{2}}$
15899 \end_inset 
15900
15901 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
15902  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
15903  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
15904 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
15905
15906 \end_inset 
15907
15908 \SpecialChar ~
15909 would certainly like to hear about it.
15910 \layout Standard
15911 \added_space_bottom bigskip 
15912 Programmers coding for embedded systems are not especially famous for being
15913  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
15914 e these references are very valuable.
15915  Let's help to create a climate where information is shared.
15916 \layout Section
15917
15918 Memory Models
15919 \layout Subsection
15920
15921 MCS51 Memory Models
15922 \begin_inset LatexCommand \index{Memory model}
15923
15924 \end_inset 
15925
15926
15927 \begin_inset LatexCommand \index{MCS51 memory model}
15928
15929 \end_inset 
15930
15931
15932 \layout Subsubsection
15933
15934 Small, Medium and Large
15935 \layout Standard
15936
15937 SDCC allows three memory models for MCS51 code, 
15938 \shape slanted 
15939 small, medium
15940 \shape default 
15941  and 
15942 \shape slanted 
15943 large
15944 \shape default 
15945 .
15946  Modules compiled with different memory models should 
15947 \emph on 
15948 never
15949 \emph default 
15950  be combined together or the results would be unpredictable.
15951  The library routines supplied with the compiler are compiled as small,
15952  medium and large.
15953  The compiled library modules are contained in separate directories as small,
15954  medium and large so that you can link to the appropriate set.
15955 \layout Standard
15956
15957 When the medium or large model is used all variables declared without a
15958  storage class will be allocated into the external ram, this includes all
15959  parameters and local variables (for non-reentrant
15960 \begin_inset LatexCommand \index{reentrant}
15961
15962 \end_inset 
15963
15964  functions).
15965  When the small model is used variables without storage class are allocated
15966  in the internal ram.
15967 \layout Standard
15968
15969 Judicious usage of the processor specific storage classes
15970 \begin_inset LatexCommand \index{Storage class}
15971
15972 \end_inset 
15973
15974  and the 'reentrant' function type will yield much more efficient code,
15975  than using the large model.
15976  Several optimizations are disabled when the program is compiled using the
15977  large model, it is therefore recommended that the small model be used unless
15978  absolutely required.
15979 \layout Subsubsection
15980
15981 External Stack
15982 \begin_inset LatexCommand \label{sub:External-Stack}
15983
15984 \end_inset 
15985
15986
15987 \begin_inset LatexCommand \index{stack}
15988
15989 \end_inset 
15990
15991
15992 \begin_inset LatexCommand \index{External stack (mcs51)}
15993
15994 \end_inset 
15995
15996
15997 \layout Standard
15998
15999 The external stack (-
16000 \begin_inset ERT
16001 status Collapsed
16002
16003 \layout Standard
16004
16005 \backslash 
16006 /
16007 \end_inset 
16008
16009 -xstack option
16010 \begin_inset LatexCommand \index{-\/-xstack}
16011
16012 \end_inset 
16013
16014 ) is located in pdata
16015 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16016
16017 \end_inset 
16018
16019  memory (usually at the start of the external ram segment) and uses all
16020  unused space in pdata (max.
16021  256 bytes).
16022  When -
16023 \begin_inset ERT
16024 status Collapsed
16025
16026 \layout Standard
16027
16028 \backslash 
16029 /
16030 \end_inset 
16031
16032 -xstack option is used to compile the program, the parameters and local
16033  variables
16034 \begin_inset LatexCommand \index{local variables}
16035
16036 \end_inset 
16037
16038  of all reentrant functions are allocated in this area.
16039  This option is provided for programs with large stack space requirements.
16040  When used with the -
16041 \begin_inset ERT
16042 status Collapsed
16043
16044 \layout Standard
16045
16046 \backslash 
16047 /
16048 \end_inset 
16049
16050 -stack-auto
16051 \begin_inset LatexCommand \index{-\/-stack-auto}
16052
16053 \end_inset 
16054
16055  option, all parameters and local variables are allocated on the external
16056  stack (note: support libraries will need to be recompiled with the same
16057  options.
16058  There is a predefined target in the library makefile).
16059 \layout Standard
16060
16061 The compiler outputs the higher order address byte of the external ram segment
16062  into port P2
16063 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16064
16065 \end_inset 
16066
16067  (see also section 
16068 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16069
16070 \end_inset 
16071
16072 ), therefore when using the External Stack option, this port 
16073 \emph on 
16074 may not
16075 \emph default 
16076  be used by the application program.
16077 \layout Subsection
16078
16079 DS390 Memory Model
16080 \begin_inset LatexCommand \index{Memory model}
16081
16082 \end_inset 
16083
16084
16085 \begin_inset LatexCommand \index{DS390 memory model}
16086
16087 \end_inset 
16088
16089
16090 \layout Standard
16091
16092 The only model supported is Flat 24
16093 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
16094
16095 \end_inset 
16096
16097 .
16098  This generates code for the 24 bit contiguous addressing mode of the Dallas
16099  DS80C390 part.
16100  In this mode, up to four meg of external RAM or code space can be directly
16101  addressed.
16102  See the data sheets at www.dalsemi.com for further information on this part.
16103 \newline 
16104
16105 \newline 
16106 Note that the compiler does not generate any code to place the processor
16107  into 24 bitmode (although 
16108 \emph on 
16109 tinibios
16110 \emph default 
16111  in the ds390 libraries will do that for you).
16112  If you don't use 
16113 \emph on 
16114 tinibios
16115 \emph default 
16116
16117 \begin_inset LatexCommand \index{Tinibios (DS390)}
16118
16119 \end_inset 
16120
16121 , the boot loader or similar code must ensure that the processor is in 24
16122  bit contiguous addressing mode before calling the SDCC startup code.
16123 \newline 
16124
16125 \newline 
16126 Like the 
16127 \emph on 
16128 -
16129 \begin_inset ERT
16130 status Collapsed
16131
16132 \layout Standard
16133
16134 \backslash 
16135 /
16136 \end_inset 
16137
16138 -model-large
16139 \emph default 
16140  option, variables will by default be placed into the XDATA segment.
16141  
16142 \newline 
16143
16144 \newline 
16145 Segments may be placed anywhere in the 4 meg address space using the usual
16146  -
16147 \begin_inset ERT
16148 status Collapsed
16149
16150 \layout Standard
16151
16152 \backslash 
16153 /
16154 \end_inset 
16155
16156 -*-loc options.
16157  Note that if any segments are located above 64K, the -r flag must be passed
16158  to the linker to generate the proper segment relocations, and the Intel
16159  HEX output format must be used.
16160  The -r flag can be passed to the linker by using the option 
16161 \emph on 
16162 -Wl-r
16163 \emph default 
16164  on the SDCC command line.
16165  However, currently the linker can not handle code segments > 64k.
16166 \layout Section
16167
16168 Pragmas
16169 \begin_inset LatexCommand \label{sec:Pragmas}
16170
16171 \end_inset 
16172
16173
16174 \begin_inset LatexCommand \index{Pragmas}
16175
16176 \end_inset 
16177
16178
16179 \layout Standard
16180
16181 SDCC supports the following #pragma directives:
16182 \layout Itemize
16183
16184
16185 \series bold 
16186 save
16187 \series default 
16188
16189 \begin_inset LatexCommand \index{\#pragma save}
16190
16191 \end_inset 
16192
16193  - this will save most current options to the save/restore stack.
16194  See #pragma\SpecialChar ~
16195 restore.
16196 \layout Itemize
16197
16198
16199 \series bold 
16200 restore
16201 \series default 
16202
16203 \begin_inset LatexCommand \index{\#pragma restore}
16204
16205 \end_inset 
16206
16207  - will restore saved options from the last save.
16208  saves & restores can be nested.
16209  SDCC uses a save/restore stack: save pushes current options to the stack,
16210  restore pulls current options from the stack.
16211  See #pragma\SpecialChar ~
16212 save.
16213 \newline 
16214
16215 \layout Itemize
16216
16217
16218 \series bold 
16219 callee_saves
16220 \series default 
16221
16222 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16223
16224 \end_inset 
16225
16226
16227 \begin_inset LatexCommand \index{function prologue}
16228
16229 \end_inset 
16230
16231  function1[,function2[,function3...]] - The compiler by default uses a caller
16232  saves convention for register saving across function calls, however this
16233  can cause unnecessary register pushing & popping
16234 \begin_inset LatexCommand \index{push/pop}
16235
16236 \end_inset 
16237
16238  when calling small functions from larger functions.
16239  This option can be used to switch off the register saving convention for
16240  the function names specified.
16241  The compiler will not save registers when calling these functions, extra
16242  code need to be manually inserted at the entry & exit for these functions
16243  to save & restore the registers used by these functions, this can SUBSTANTIALLY
16244  reduce code & improve run time performance of the generated code.
16245  In the future the compiler (with inter procedural analysis) may be able
16246  to determine the appropriate scheme to use for each function call.
16247  If -
16248 \begin_inset ERT
16249 status Collapsed
16250
16251 \layout Standard
16252
16253 \backslash 
16254 /
16255 \end_inset 
16256
16257 -callee-saves command line option is used, the function names specified
16258  in #pragma\SpecialChar ~
16259 callee_saves
16260 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16261
16262 \end_inset 
16263
16264  is appended to the list of functions specified in the command line.
16265 \layout Itemize
16266
16267
16268 \series bold 
16269 exclude
16270 \series default 
16271
16272 \begin_inset LatexCommand \index{\#pragma exclude}
16273
16274 \end_inset 
16275
16276  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
16277  of pairs of push/pop
16278 \begin_inset LatexCommand \index{push/pop}
16279
16280 \end_inset 
16281
16282  instructions in 
16283 \emph on 
16284 I
16285 \emph default 
16286 nterrupt
16287 \begin_inset LatexCommand \index{interrupt}
16288
16289 \end_inset 
16290
16291  
16292 \emph on 
16293 S
16294 \emph default 
16295 ervice 
16296 \emph on 
16297 R
16298 \emph default 
16299 outines.
16300  The directive should be placed immediately before the ISR function definition
16301  and it affects ALL ISR functions following it.
16302  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
16303 exclude\SpecialChar ~
16304 none
16305 \begin_inset LatexCommand \index{\#pragma exclude}
16306
16307 \end_inset 
16308
16309 .
16310  See also the related keyword _naked
16311 \begin_inset LatexCommand \index{\_naked}
16312
16313 \end_inset 
16314
16315
16316 \begin_inset LatexCommand \index{\_\_naked}
16317
16318 \end_inset 
16319
16320 .
16321 \layout Itemize
16322
16323
16324 \series bold 
16325 less_pedantic
16326 \series default 
16327
16328 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16329
16330 \end_inset 
16331
16332  - the compiler will not warn you anymore for obvious mistakes, you'r on
16333  your own now ;-(
16334 \layout Itemize
16335
16336
16337 \series bold 
16338 disable_warning
16339 \series default 
16340  <nnnn>
16341 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16342
16343 \end_inset 
16344
16345  - the compiler will not warn you anymore about warning number <nnnn>.
16346 \layout Itemize
16347
16348
16349 \series bold 
16350 nogcse
16351 \series default 
16352
16353 \begin_inset LatexCommand \index{\#pragma nogcse}
16354
16355 \end_inset 
16356
16357  - will stop global common subexpression elimination.
16358 \layout Itemize
16359
16360
16361 \series bold 
16362 noinduction
16363 \series default 
16364
16365 \begin_inset LatexCommand \index{\#pragma noinduction}
16366
16367 \end_inset 
16368
16369  - will stop loop induction optimizations.
16370 \layout Itemize
16371
16372
16373 \series bold 
16374 noinvariant
16375 \series default 
16376
16377 \begin_inset LatexCommand \index{\#pragma noinvariant}
16378
16379 \end_inset 
16380
16381  - will not do loop invariant optimizations.
16382  For more details see Loop Invariants in section
16383 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16384
16385 \end_inset 
16386
16387 .
16388 \layout Itemize
16389
16390
16391 \series bold 
16392 noiv
16393 \series default 
16394
16395 \begin_inset LatexCommand \index{\#pragma noiv}
16396
16397 \end_inset 
16398
16399  - Do not generate interrupt
16400 \begin_inset LatexCommand \index{interrupt}
16401
16402 \end_inset 
16403
16404  vector table entries for all ISR functions defined after the pragma.
16405  This is useful in cases where the interrupt vector table must be defined
16406  manually, or when there is a secondary, manually defined interrupt vector
16407  table (e.g.
16408  for the autovector feature of the Cypress EZ-USB FX2).
16409  More elegantly this can be achieved by obmitting the optional interrupt
16410  number after the interrupt keyword, see section 
16411 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16412
16413 \end_inset 
16414
16415 \SpecialChar ~
16416 about interrupts.
16417 \layout Itemize
16418
16419
16420 \series bold 
16421 nojtbound
16422 \series default 
16423
16424 \begin_inset LatexCommand \index{\#pragma nojtbound}
16425
16426 \end_inset 
16427
16428  - will not generate code for boundary value checking, when switch statements
16429  are turned into jump-tables (dangerous).
16430  For more details see section 
16431 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16432
16433 \end_inset 
16434
16435 .
16436 \layout Itemize
16437
16438
16439 \series bold 
16440 noloopreverse
16441 \series default 
16442
16443 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16444
16445 \end_inset 
16446
16447  - Will not do loop reversal optimization
16448 \layout Itemize
16449
16450
16451 \series bold 
16452 nooverlay
16453 \series default 
16454
16455 \begin_inset LatexCommand \index{\#pragma nooverlay}
16456
16457 \end_inset 
16458
16459  - the compiler will not overlay the parameters and local variables of a
16460  function.
16461 \layout Itemize
16462
16463
16464 \series bold 
16465 stackauto
16466 \series default 
16467
16468 \begin_inset LatexCommand \index{\#pragma stackauto}
16469
16470 \end_inset 
16471
16472 - See option -
16473 \begin_inset ERT
16474 status Collapsed
16475
16476 \layout Standard
16477
16478 \backslash 
16479 /
16480 \end_inset 
16481
16482 -stack-auto
16483 \begin_inset LatexCommand \index{-\/-stack-auto}
16484
16485 \end_inset 
16486
16487  and section 
16488 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16489
16490 \end_inset 
16491
16492  Parameters and Local Variables.
16493 \layout Itemize
16494
16495
16496 \series bold 
16497 opt_code_speed
16498 \series default 
16499  
16500 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16501
16502 \end_inset 
16503
16504 - The compiler will optimize code generation towards fast code, possibly
16505  at the expense of code size.
16506  Currently this has little effect.
16507 \layout Itemize
16508
16509
16510 \series bold 
16511 opt_code_size
16512 \series default 
16513  
16514 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16515
16516 \end_inset 
16517
16518 - The compiler will optimize code generation towards compact code, possibly
16519  at the expense of code speed.
16520  Currently this has little effect.
16521 \layout Itemize
16522
16523
16524 \series bold 
16525 opt_code_balanced
16526 \series default 
16527  
16528 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16529
16530 \end_inset 
16531
16532 - The compiler will attempt to generate code that is both compact and fast,
16533  as long as meeting one goal is not a detriment to the other (this is the
16534  default).
16535  
16536 \layout Itemize
16537
16538
16539 \series bold 
16540 std_sdcc89
16541 \series default 
16542  
16543 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16544
16545 \end_inset 
16546
16547 - Generally follow the C89 standard, but allow SDCC features that conflict
16548  with the standard (default).
16549 \layout Itemize
16550
16551
16552 \series bold 
16553 std_c89
16554 \series default 
16555  
16556 \begin_inset LatexCommand \index{\#pragma std\_c89}
16557
16558 \end_inset 
16559
16560 - Follow the C89 standard and disable SDCC features that conflict with the
16561  standard.
16562 \layout Itemize
16563
16564
16565 \series bold 
16566 std_sdcc99
16567 \series default 
16568  
16569 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16570
16571 \end_inset 
16572
16573 - Generally follow the C99 standard, but allow SDCC features that conflict
16574  with the standard (incomplete support).
16575 \layout Itemize
16576
16577
16578 \series bold 
16579 std_c99
16580 \series default 
16581  
16582 \begin_inset LatexCommand \index{\#pragma std\_c99}
16583
16584 \end_inset 
16585
16586 - Follow the C99 standard and disable SDCC features that conflict with the
16587  standard (incomplete support).
16588 \layout Itemize
16589
16590
16591 \series bold 
16592 codeseg
16593 \series default 
16594  <name>
16595 \begin_inset LatexCommand \index{\#pragma codeseg}
16596
16597 \end_inset 
16598
16599 - Use this name (max.
16600  8 characters) for the code segment.
16601  See option -
16602 \begin_inset ERT
16603 status Collapsed
16604
16605 \layout Standard
16606
16607 \backslash 
16608 /
16609 \end_inset 
16610
16611 -codeseg.
16612 \layout Itemize
16613
16614
16615 \series bold 
16616 constseg
16617 \series default 
16618  <name>
16619 \begin_inset LatexCommand \index{\#pragma constseg}
16620
16621 \end_inset 
16622
16623 - Use this name (max.
16624  8 characters) for the const segment.
16625  See option -
16626 \begin_inset ERT
16627 status Collapsed
16628
16629 \layout Standard
16630
16631 \backslash 
16632 /
16633 \end_inset 
16634
16635 -constseg.
16636 \layout Standard
16637
16638 The preprocessor SDCPP
16639 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
16640
16641 \end_inset 
16642
16643  supports the following #pragma directives:
16644 \layout Itemize
16645
16646
16647 \series bold 
16648 preproc_asm
16649 \series default 
16650
16651 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16652
16653 \end_inset 
16654
16655  (+ | -) - switch _asm _endasm block preprocessing on / off.
16656  Default is on.
16657  You use this prama to define multilines of assembly code.
16658  This will prevent the preprocessor from changing the formating required
16659  by assembly code.
16660  Below is an example on how to use this pragma.
16661 \layout Verse
16662
16663
16664 \family typewriter 
16665 #pragma preproc_asm -
16666 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16667
16668 \end_inset 
16669
16670
16671 \newline 
16672 #define MYDELAY _asm
16673 \newline 
16674 \SpecialChar ~
16675 \SpecialChar ~
16676 \SpecialChar ~
16677 nop ;my assembly comment...
16678 \newline 
16679 \SpecialChar ~
16680 \SpecialChar ~
16681 \SpecialChar ~
16682 nop
16683 \newline 
16684 \SpecialChar ~
16685 \SpecialChar ~
16686 \SpecialChar ~
16687 nop
16688 \newline 
16689 _endasm
16690 \newline 
16691 #pragma preproc_asm +
16692 \newline 
16693
16694 \newline 
16695 void foo (void) 
16696 \newline 
16697
16698 \newline 
16699 \SpecialChar ~
16700 \SpecialChar ~
16701 \SpecialChar ~
16702  ...
16703  
16704 \newline 
16705 \SpecialChar ~
16706 \SpecialChar ~
16707 \SpecialChar ~
16708  MYDELAY;
16709 \newline 
16710 \SpecialChar ~
16711 \SpecialChar ~
16712 \SpecialChar ~
16713  ...
16714  
16715 \newline 
16716
16717 \newline 
16718
16719 \layout Standard
16720
16721 The pragma's are intended to be used to turn-on or off certain optimizations
16722  which might cause the compiler to generate extra stack / data space to
16723  store compiler generated temporary variables.
16724  This usually happens in large functions.
16725  Pragma directives should be used as shown in the following example, they
16726  are used to control options & optimizations for a given function; pragmas
16727  should be placed before and/or after a function, placing pragma's inside
16728  a function body could have unpredictable results.
16729 \layout Verse
16730
16731
16732 \family typewriter 
16733 #pragma save
16734 \begin_inset LatexCommand \index{\#pragma save}
16735
16736 \end_inset 
16737
16738  \SpecialChar ~
16739 \SpecialChar ~
16740 \SpecialChar ~
16741 \SpecialChar ~
16742 \SpecialChar ~
16743 \SpecialChar ~
16744 \SpecialChar ~
16745 /* save the current settings */ 
16746 \newline 
16747 #pragma nogcse
16748 \begin_inset LatexCommand \index{\#pragma nogcse}
16749
16750 \end_inset 
16751
16752  \SpecialChar ~
16753 \SpecialChar ~
16754 \SpecialChar ~
16755 \SpecialChar ~
16756 \SpecialChar ~
16757 /* turnoff global subexpression elimination */ 
16758 \newline 
16759 #pragma noinduction
16760 \begin_inset LatexCommand \index{\#pragma noinduction}
16761
16762 \end_inset 
16763
16764  /* turn off induction optimizations */ 
16765 \newline 
16766 int foo () 
16767 \newline 
16768
16769 \newline 
16770 \SpecialChar ~
16771  \SpecialChar ~
16772  ...
16773  
16774 \newline 
16775 \SpecialChar ~
16776  \SpecialChar ~
16777  /* large code */ 
16778 \newline 
16779 \SpecialChar ~
16780  \SpecialChar ~
16781  ...
16782  
16783 \newline 
16784
16785 \newline 
16786 #pragma restore
16787 \begin_inset LatexCommand \index{\#pragma restore}
16788
16789 \end_inset 
16790
16791  /* turn the optimizations back on */
16792 \layout Standard
16793
16794 The compiler will generate a warning message when extra space is allocated.
16795  It is strongly recommended that the save and restore pragma's be used when
16796  changing options for a function.
16797 \newline 
16798
16799 \newline 
16800
16801 \newline 
16802
16803 \layout Section
16804
16805 Defines Created by the Compiler
16806 \layout Standard
16807
16808 The compiler creates the following #defines
16809 \begin_inset LatexCommand \index{\#defines}
16810
16811 \end_inset 
16812
16813
16814 \begin_inset LatexCommand \index{Defines created by the compiler}
16815
16816 \end_inset 
16817
16818 :
16819 \newline 
16820
16821 \layout Standard
16822
16823
16824 \begin_inset  Tabular
16825 <lyxtabular version="3" rows="11" columns="2">
16826 <features>
16827 <column alignment="left" valignment="top" leftline="true" width="3in">
16828 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
16829 <row topline="true" bottomline="true">
16830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16831 \begin_inset Text
16832
16833 \layout Standard
16834
16835
16836 \series bold 
16837 #define
16838 \end_inset 
16839 </cell>
16840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16841 \begin_inset Text
16842
16843 \layout Standard
16844
16845
16846 \series bold 
16847 Description
16848 \end_inset 
16849 </cell>
16850 </row>
16851 <row topline="true">
16852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16853 \begin_inset Text
16854
16855 \layout Standard
16856
16857 SDCC
16858 \begin_inset LatexCommand \index{SDCC}
16859
16860 \end_inset 
16861
16862  
16863 \end_inset 
16864 </cell>
16865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16866 \begin_inset Text
16867
16868 \layout Standard
16869
16870 Always defined.
16871  Since version 2.5.6 the version number as an int (ex.
16872  256)
16873 \end_inset 
16874 </cell>
16875 </row>
16876 <row topline="true">
16877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16878 \begin_inset Text
16879
16880 \layout Standard
16881
16882 SDCC_mcs51
16883 \begin_inset LatexCommand \index{SDCC\_mcs51}
16884
16885 \end_inset 
16886
16887  or SDCC_ds390
16888 \begin_inset LatexCommand \index{SDCC\_ds390}
16889
16890 \end_inset 
16891
16892  or SDCC_z80
16893 \begin_inset LatexCommand \index{SDCC\_z80}
16894
16895 \end_inset 
16896
16897 , etc.
16898 \end_inset 
16899 </cell>
16900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16901 \begin_inset Text
16902
16903 \layout Standard
16904
16905 depending on the model used (e.g.: -mds390)
16906 \end_inset 
16907 </cell>
16908 </row>
16909 <row topline="true">
16910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16911 \begin_inset Text
16912
16913 \layout Standard
16914
16915 __mcs51
16916 \begin_inset LatexCommand \index{\_\_mcs51}
16917
16918 \end_inset 
16919
16920 , __ds390
16921 \begin_inset LatexCommand \index{\_\_ds390}
16922
16923 \end_inset 
16924
16925 , __hc08
16926 \begin_inset LatexCommand \index{\_\_hc08}
16927
16928 \end_inset 
16929
16930 , __z80
16931 \begin_inset LatexCommand \index{\_\_z80}
16932
16933 \end_inset 
16934
16935 , etc
16936 \end_inset 
16937 </cell>
16938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16939 \begin_inset Text
16940
16941 \layout Standard
16942
16943 depending on the model used (e.g.
16944  -mz80)
16945 \end_inset 
16946 </cell>
16947 </row>
16948 <row topline="true">
16949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16950 \begin_inset Text
16951
16952 \layout Standard
16953
16954 SDCC_STACK_AUTO
16955 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
16956
16957 \end_inset 
16958
16959
16960 \end_inset 
16961 </cell>
16962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16963 \begin_inset Text
16964
16965 \layout Standard
16966
16967 when 
16968 \emph on 
16969 -
16970 \begin_inset ERT
16971 status Collapsed
16972
16973 \layout Standard
16974
16975 \backslash 
16976 /
16977 \end_inset 
16978
16979 -stack-auto
16980 \emph default 
16981  option is used
16982 \end_inset 
16983 </cell>
16984 </row>
16985 <row topline="true">
16986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16987 \begin_inset Text
16988
16989 \layout Standard
16990
16991 SDCC_MODEL_SMALL
16992 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
16993
16994 \end_inset 
16995
16996
16997 \end_inset 
16998 </cell>
16999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17000 \begin_inset Text
17001
17002 \layout Standard
17003
17004 when 
17005 \emph on 
17006 -
17007 \begin_inset ERT
17008 status Collapsed
17009
17010 \layout Standard
17011
17012 \backslash 
17013 /
17014 \end_inset 
17015
17016 -model-small
17017 \emph default 
17018  is used
17019 \end_inset 
17020 </cell>
17021 </row>
17022 <row topline="true">
17023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17024 \begin_inset Text
17025
17026 \layout Standard
17027
17028 SDCC_MODEL_MEDIUM
17029 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
17030
17031 \end_inset 
17032
17033
17034 \end_inset 
17035 </cell>
17036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17037 \begin_inset Text
17038
17039 \layout Standard
17040
17041 when 
17042 \emph on 
17043 -
17044 \begin_inset ERT
17045 status Collapsed
17046
17047 \layout Standard
17048
17049 \backslash 
17050 /
17051 \end_inset 
17052
17053 -model-medium
17054 \emph default 
17055  is used
17056 \end_inset 
17057 </cell>
17058 </row>
17059 <row topline="true">
17060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17061 \begin_inset Text
17062
17063 \layout Standard
17064
17065 SDCC_MODEL_LARGE
17066 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
17067
17068 \end_inset 
17069
17070
17071 \end_inset 
17072 </cell>
17073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17074 \begin_inset Text
17075
17076 \layout Standard
17077
17078 when 
17079 \emph on 
17080 -
17081 \begin_inset ERT
17082 status Collapsed
17083
17084 \layout Standard
17085
17086 \backslash 
17087 /
17088 \end_inset 
17089
17090 -model-large
17091 \emph default 
17092  is used
17093 \end_inset 
17094 </cell>
17095 </row>
17096 <row topline="true">
17097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17098 \begin_inset Text
17099
17100 \layout Standard
17101
17102 SDCC_USE_XSTACK
17103 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
17104
17105 \end_inset 
17106
17107
17108 \end_inset 
17109 </cell>
17110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17111 \begin_inset Text
17112
17113 \layout Standard
17114
17115 when 
17116 \emph on 
17117 -
17118 \begin_inset ERT
17119 status Collapsed
17120
17121 \layout Standard
17122
17123 \backslash 
17124 /
17125 \end_inset 
17126
17127 -xstack
17128 \emph default 
17129  option is used
17130 \end_inset 
17131 </cell>
17132 </row>
17133 <row topline="true">
17134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17135 \begin_inset Text
17136
17137 \layout Standard
17138
17139 SDCC_STACK_TENBIT
17140 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
17141
17142 \end_inset 
17143
17144  
17145 \end_inset 
17146 </cell>
17147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17148 \begin_inset Text
17149
17150 \layout Standard
17151
17152 when 
17153 \emph on 
17154 -mds390
17155 \emph default 
17156  is used
17157 \end_inset 
17158 </cell>
17159 </row>
17160 <row topline="true" bottomline="true">
17161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17162 \begin_inset Text
17163
17164 \layout Standard
17165
17166 SDCC_MODEL_FLAT24
17167 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
17168
17169 \end_inset 
17170
17171
17172 \end_inset 
17173 </cell>
17174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17175 \begin_inset Text
17176
17177 \layout Standard
17178
17179 when 
17180 \emph on 
17181 -mds390
17182 \emph default 
17183  is used
17184 \end_inset 
17185 </cell>
17186 </row>
17187 </lyxtabular>
17188
17189 \end_inset 
17190
17191
17192 \layout Chapter
17193
17194 Notes on supported Processors
17195 \layout Section
17196
17197 MCS51 variants
17198 \begin_inset LatexCommand \label{sub:MCS51-variants}
17199
17200 \end_inset 
17201
17202
17203 \begin_inset LatexCommand \index{MCS51 variants}
17204
17205 \end_inset 
17206
17207
17208 \layout Standard
17209
17210 MCS51 processors are available from many vendors and come in many different
17211  flavours.
17212  While they might differ considerably in respect to Special Function Registers
17213  the core MCS51 is usually not modified or is kept compatible.
17214  
17215 \layout Subsection
17216
17217 pdata access by SFR 
17218 \layout Standard
17219
17220 With the upcome of devices with internal xdata and flash memory devices
17221  using port P2
17222 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17223
17224 \end_inset 
17225
17226  as dedicated I/O port is becoming more popular.
17227  Switching the high byte for pdata
17228 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17229
17230 \end_inset 
17231
17232  access which was formerly done by port P2 is then achieved by a Special
17233  Function Register
17234 \begin_inset LatexCommand \index{sfr}
17235
17236 \end_inset 
17237
17238 .
17239  In well-established MCS51 tradition the address of this 
17240 \emph on 
17241 sfr
17242 \emph default 
17243  is where the chip designers decided to put it.
17244  Needless to say that they didn't agree on a common name either.
17245  So that the startup code can correctly initialize xdata variables, you
17246  should define an sfr with the name _XPAGE
17247 \family typewriter 
17248
17249 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
17250
17251 \end_inset 
17252
17253
17254 \family default 
17255  at the appropriate location if the default, port P2, is not used for this.
17256  Some examples are:
17257 \layout Verse
17258
17259
17260 \family typewriter 
17261 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
17262 \layout Verse
17263
17264
17265 \family typewriter 
17266 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17267 \layout Verse
17268
17269
17270 \family typewriter 
17271 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17272 \layout Standard
17273
17274 For more exotic implementations further customizations may be needed.
17275  See section 
17276 \begin_inset LatexCommand \ref{sub:Startup-Code}
17277
17278 \end_inset 
17279
17280  for other possibilities.
17281 \layout Subsection
17282
17283 Other Features available by SFR
17284 \layout Standard
17285 \added_space_bottom bigskip 
17286 Some MCS51 variants offer features like Double DPTR
17287 \begin_inset LatexCommand \index{DPTR}
17288
17289 \end_inset 
17290
17291 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17292  These are currently not used for the MCS51 port.
17293  If you absolutely need them you can fall back to inline assembly or submit
17294  a patch to SDCC.
17295 \layout Section
17296
17297 DS400 port
17298 \layout Standard
17299 \added_space_bottom bigskip 
17300 The DS80C400
17301 \begin_inset LatexCommand \index{DS80C400}
17302
17303 \end_inset 
17304
17305
17306 \begin_inset LatexCommand \index{DS400}
17307
17308 \end_inset 
17309
17310  microcontroller has a rich set of peripherals.
17311  In its built-in ROM library it includes functions to access some of the
17312  features, among them is a TCP stack with IP4 and IP6 support.
17313  Library headers (currently in beta status) and other files are provided
17314  at 
17315 \size footnotesize 
17316
17317 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
17318
17319 \end_inset 
17320
17321 .
17322  
17323 \layout Section
17324
17325 The Z80 and gbz80 port
17326 \layout Standard
17327
17328 SDCC can target both the Zilog Z80
17329 \begin_inset LatexCommand \index{Z80}
17330
17331 \end_inset 
17332
17333  and the Nintendo Gameboy's Z80-like gbz80
17334 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17335
17336 \end_inset 
17337
17338 .
17339  The Z80 port is passed through the same 
17340 \emph on 
17341 regressions tests
17342 \begin_inset LatexCommand \index{Regression test}
17343
17344 \end_inset 
17345
17346
17347 \emph default 
17348  as the MCS51 and DS390 ports, so floating point support, support for long
17349  variables and bitfield support is fine.
17350  See mailing lists and forums about interrupt routines.
17351 \layout Standard
17352 \added_space_bottom bigskip 
17353 As always, the code is the authoritative reference - see z80/ralloc.c and
17354  z80/gen.c.
17355  The stack
17356 \begin_inset LatexCommand \index{Z80!stack}
17357
17358 \end_inset 
17359
17360  frame is similar to that generated by the IAR Z80 compiler.
17361  IX is used as the base pointer, HL and IY are used as a temporary registers,
17362  and BC and DE are available for holding variables.
17363  Return values
17364 \begin_inset LatexCommand \index{Z80!return value}
17365
17366 \end_inset 
17367
17368  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
17369  bytes).
17370  The gbz80 port use the same set of registers for the return values, but
17371  in a different order of significance: E (one byte), DE (two bytes), or
17372  HLDE (four bytes).
17373 \layout Section
17374
17375 The HC08 port
17376 \layout Standard
17377 \added_space_bottom bigskip 
17378 The port to the Motorola HC08
17379 \begin_inset LatexCommand \index{HC08}
17380
17381 \end_inset 
17382
17383  family has been added in October 2003, and is still undergoing some basic
17384  development.
17385  The code generator is complete, but the register allocation is still quite
17386  unoptimized.
17387  Some of the SDCC's standard C library functions have embedded non-HC08
17388  inline assembly and so are not yet usable.
17389 \layout Section
17390 \pagebreak_top 
17391 The PIC14 port
17392 \layout Standard
17393
17394 The 14bit PIC
17395 \begin_inset LatexCommand \index{PIC14}
17396
17397 \end_inset 
17398
17399  port still requires a major effort from the development community.
17400  However it can work for very simple code.
17401 \layout Subsection
17402
17403 C code and 14bit PIC code page
17404 \begin_inset LatexCommand \index{code page (pic14)}
17405
17406 \end_inset 
17407
17408  and RAM banks
17409 \begin_inset LatexCommand \index{RAM bank (pic14)}
17410
17411 \end_inset 
17412
17413
17414 \layout Standard
17415
17416 The linker organizes allocation for the code page and RAM banks.
17417  It does not have intimate knowledge of the code flow.
17418  It will put all the code section of a single asm file into a single code
17419  page.
17420  In order to make use of multiple code pages, separate asm files must be
17421  used.
17422  The compiler treats all functions of a single C file as being in the same
17423  code page unless it is non static.
17424  The compiler treats all local variables of a single C file as being in
17425  the same RAM bank unless it is an extern.
17426 \newline 
17427
17428 \newline 
17429 To get the best follow these guide lines:
17430 \layout Enumerate
17431
17432 make local functions static, as non static functions require code page selection
17433  overhead.
17434 \layout Enumerate
17435
17436 Make local variables static as extern variables require RAM bank selection
17437  overhead.
17438 \layout Enumerate
17439
17440 For devices that have multiple code pages it is more efficient to use the
17441  same number of files as pages, i.e.
17442  for the 16F877 use 4 separate files and i.e.
17443  for the 16F874 use 2 separate files.
17444  This way the linker can put the code for each file into different code
17445  pages and the compiler can allocate reusable variables more efficiently
17446  and there's less page selection overhead.
17447  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17448  instruction set) use 'unsigned char' whereever possible instead of 'int'.
17449 \layout Subsection
17450
17451 Creating a device include file 
17452 \layout Standard
17453
17454 For generating a device include file
17455 \begin_inset LatexCommand \index{PIC14!Header files}
17456
17457 \end_inset 
17458
17459  use the support perl script inc2h.pl kept in directory support/script.
17460 \layout Subsection
17461
17462 Interrupt code
17463 \layout Standard
17464
17465 For the interrupt function, use the keyword 'interrupt'
17466 \begin_inset LatexCommand \index{PIC14!interrupt}
17467
17468 \end_inset 
17469
17470  with level number of 0 (PIC14 only has 1 interrupt so this number is only
17471  there to avoid a syntax error - it ought to be fixed).
17472  E.g.:
17473 \layout Verse
17474
17475
17476 \family typewriter 
17477 void Intr(void) interrupt 0
17478 \newline 
17479 {
17480 \newline 
17481 \SpecialChar ~
17482 \SpecialChar ~
17483 T0IF = 0; /* Clear timer interrupt */
17484 \newline 
17485 }
17486 \layout Subsection
17487
17488 Linking and assembling
17489 \layout Standard
17490
17491 For assembling you can use either GPUTILS'
17492 \begin_inset LatexCommand \index{gputils (pic tools)}
17493
17494 \end_inset 
17495
17496  gpasm.exe or MPLAB's mpasmwin.exe.
17497  GPUTILS is available from 
17498 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17499
17500 \end_inset 
17501
17502 .
17503  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17504  If you use MPLAB and an interrupt function then the linker script file
17505  vectors section will need to be enlarged to link with mplink.
17506 \newline 
17507
17508 \newline 
17509 Here is a 
17510 \family typewriter 
17511 Makefile
17512 \family default 
17513  using GPUTILS:
17514 \layout Verse
17515
17516
17517 \family typewriter 
17518 .c.o:
17519 \newline 
17520 \SpecialChar ~
17521 \SpecialChar ~
17522 \SpecialChar ~
17523 \SpecialChar ~
17524 \SpecialChar ~
17525 \SpecialChar ~
17526 \SpecialChar ~
17527 \SpecialChar ~
17528 sdcc -S -V -mpic14 -p16F877 $< 
17529 \newline 
17530 \SpecialChar ~
17531 \SpecialChar ~
17532 \SpecialChar ~
17533 \SpecialChar ~
17534 \SpecialChar ~
17535 \SpecialChar ~
17536 \SpecialChar ~
17537 \SpecialChar ~
17538 gpasm -c $*.asm
17539 \newline 
17540
17541 \newline 
17542 $(PRJ).hex: $(OBJS) 
17543 \newline 
17544 \SpecialChar ~
17545 \SpecialChar ~
17546 \SpecialChar ~
17547 \SpecialChar ~
17548 \SpecialChar ~
17549 \SpecialChar ~
17550 \SpecialChar ~
17551 \SpecialChar ~
17552 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
17553 \layout Standard
17554
17555 Here is a 
17556 \family typewriter 
17557 Makefile
17558 \family default 
17559  using MPLAB:
17560 \layout Verse
17561
17562
17563 \family typewriter 
17564 .c.o: 
17565 \newline 
17566 \SpecialChar ~
17567 \SpecialChar ~
17568 \SpecialChar ~
17569 \SpecialChar ~
17570 \SpecialChar ~
17571 \SpecialChar ~
17572 \SpecialChar ~
17573 \SpecialChar ~
17574 sdcc -S -V -mpic14 -p16F877 $< 
17575 \newline 
17576 \SpecialChar ~
17577 \SpecialChar ~
17578 \SpecialChar ~
17579 \SpecialChar ~
17580 \SpecialChar ~
17581 \SpecialChar ~
17582 \SpecialChar ~
17583 \SpecialChar ~
17584 mpasmwin /q /o $*.asm
17585 \newline 
17586
17587 \newline 
17588 $(PRJ).hex: $(OBJS) 
17589 \newline 
17590 \SpecialChar ~
17591 \SpecialChar ~
17592 \SpecialChar ~
17593 \SpecialChar ~
17594 \SpecialChar ~
17595 \SpecialChar ~
17596 \SpecialChar ~
17597 \SpecialChar ~
17598 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17599 \layout Standard
17600
17601 Please note that indentations within a
17602 \family typewriter 
17603  Makefile
17604 \family default 
17605  have to be done with a tabulator character.
17606 \layout Subsection
17607
17608 Command-line options
17609 \layout Standard
17610
17611 Besides the switches common to all SDCC backends, the PIC14 port accepts
17612  the following options (for an updated list see sdcc -
17613 \begin_inset ERT
17614 status Collapsed
17615
17616 \layout Standard
17617
17618 \backslash 
17619 /
17620 \end_inset 
17621
17622 -help):
17623 \layout List
17624 \labelwidthstring 00.00.0000
17625
17626 -
17627 \begin_inset ERT
17628 status Collapsed
17629
17630 \layout Standard
17631
17632 \backslash 
17633 /
17634 \end_inset 
17635
17636 -debug-extra
17637 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
17638
17639 \end_inset 
17640
17641  emit debug info in assembly output
17642 \layout List
17643 \labelwidthstring 00.00.0000
17644
17645 -
17646 \begin_inset ERT
17647 status Collapsed
17648
17649 \layout Standard
17650
17651 \backslash 
17652 /
17653 \end_inset 
17654
17655 -no-pcode-opt
17656 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
17657
17658 \end_inset 
17659
17660  disable (slightly faulty) optimization on pCode
17661 \layout Subsection
17662
17663 The library
17664 \layout Subsubsection
17665
17666 error: missing definition for symbol 
17667 \begin_inset Quotes sld
17668 \end_inset 
17669
17670 __gptrget1
17671 \begin_inset Quotes srd
17672 \end_inset 
17673
17674
17675 \layout Standard
17676
17677 The PIC14 port uses library routines to provide more complex operations
17678  like multiplication, division/modulus and (generic) pointer dereferencing.
17679  In order to add these routines to your project, you must link with PIC14's
17680  
17681 \family typewriter 
17682 libsdcc.lib
17683 \family default 
17684 .
17685  For single source file projects this is done automatically, more complex
17686  projects must add 
17687 \family typewriter 
17688 libsdcc.lib
17689 \family default 
17690  to the linker's arguments.
17691  Make sure you also add an include path for the library (using the -I switch
17692  to the linker)!
17693 \layout Subsubsection
17694
17695 Processor mismatch in file 
17696 \begin_inset Quotes sld
17697 \end_inset 
17698
17699 XXX
17700 \begin_inset Quotes srd
17701 \end_inset 
17702
17703 .
17704 \layout Standard
17705
17706 This warning can usually be ignored due to the very good compatibility amongst
17707  14 bit PIC
17708 \begin_inset LatexCommand \index{PIC14}
17709
17710 \end_inset 
17711
17712  devices.
17713 \layout Standard
17714
17715 You might also consider recompiling the library for your specific device
17716  by changing the ARCH=p16f877 (default target) entry in 
17717 \family typewriter 
17718 device/lib/pic/Makefile.in
17719 \family default 
17720  and 
17721 \family typewriter 
17722 device/lib/pic/Makefile
17723 \family default 
17724  to reflect your device.
17725  This might even improve performance for smaller devices as unneccesary
17726  BANKSELs migth be removed.
17727 \layout Subsection
17728
17729 Known bugs
17730 \layout Subsubsection
17731
17732 initialized data
17733 \layout Standard
17734
17735 Currently, data can only be initialized if it resides in the source file
17736  together with 
17737 \emph on 
17738 main()
17739 \emph default 
17740 .
17741  Data in other source files will silently 
17742 \series bold 
17743 not
17744 \series default 
17745  be initialized.
17746 \family typewriter 
17747 \size footnotesize 
17748
17749 \begin_inset Marginal
17750 collapsed true
17751
17752 \layout Standard
17753
17754
17755 \series bold 
17756 \SpecialChar ~
17757 !
17758 \end_inset 
17759
17760
17761 \layout Section
17762 \pagebreak_top 
17763 The PIC16
17764 \begin_inset LatexCommand \index{PIC16}
17765
17766 \end_inset 
17767
17768  port
17769 \layout Standard
17770
17771 The PIC16
17772 \begin_inset LatexCommand \index{PIC16}
17773
17774 \end_inset 
17775
17776  port is the portion of SDCC that is responsible to produce code for the
17777  Microchip
17778 \begin_inset LatexCommand \index{Microchip}
17779
17780 \end_inset 
17781
17782 (TM) microcontrollers with 16 bit core.
17783  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
17784  Currently supported devices are:
17785 \layout Standard
17786 \align center 
17787
17788 \begin_inset  Tabular
17789 <lyxtabular version="3" rows="4" columns="6">
17790 <features>
17791 <column alignment="center" valignment="top" leftline="true" width="0">
17792 <column alignment="center" valignment="top" leftline="true" width="0">
17793 <column alignment="center" valignment="top" leftline="true" width="0">
17794 <column alignment="center" valignment="top" leftline="true" width="0">
17795 <column alignment="center" valignment="top" leftline="true" width="0">
17796 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17797 <row topline="true">
17798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17799 \begin_inset Text
17800
17801 \layout Standard
17802
17803 18F242
17804 \end_inset 
17805 </cell>
17806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17807 \begin_inset Text
17808
17809 \layout Standard
17810
17811 18F248
17812 \end_inset 
17813 </cell>
17814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17815 \begin_inset Text
17816
17817 \layout Standard
17818
17819 18F252
17820 \end_inset 
17821 </cell>
17822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17823 \begin_inset Text
17824
17825 \layout Standard
17826
17827 18F258
17828 \end_inset 
17829 </cell>
17830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17831 \begin_inset Text
17832
17833 \layout Standard
17834
17835 18F442
17836 \end_inset 
17837 </cell>
17838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17839 \begin_inset Text
17840
17841 \layout Standard
17842
17843 18F448
17844 \end_inset 
17845 </cell>
17846 </row>
17847 <row topline="true">
17848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17849 \begin_inset Text
17850
17851 \layout Standard
17852
17853 18F452
17854 \end_inset 
17855 </cell>
17856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17857 \begin_inset Text
17858
17859 \layout Standard
17860
17861 18F458
17862 \end_inset 
17863 </cell>
17864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17865 \begin_inset Text
17866
17867 \layout Standard
17868
17869 18F1220
17870 \end_inset 
17871 </cell>
17872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17873 \begin_inset Text
17874
17875 \layout Standard
17876
17877 18F2220
17878 \end_inset 
17879 </cell>
17880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17881 \begin_inset Text
17882
17883 \layout Standard
17884
17885 18F2550
17886 \end_inset 
17887 </cell>
17888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17889 \begin_inset Text
17890
17891 \layout Standard
17892
17893 18F4331
17894 \end_inset 
17895 </cell>
17896 </row>
17897 <row topline="true">
17898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17899 \begin_inset Text
17900
17901 \layout Standard
17902
17903 18F4455
17904 \end_inset 
17905 </cell>
17906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17907 \begin_inset Text
17908
17909 \layout Standard
17910
17911 18F6520
17912 \end_inset 
17913 </cell>
17914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17915 \begin_inset Text
17916
17917 \layout Standard
17918
17919 18F6620
17920 \end_inset 
17921 </cell>
17922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17923 \begin_inset Text
17924
17925 \layout Standard
17926
17927 18F6680
17928 \end_inset 
17929 </cell>
17930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17931 \begin_inset Text
17932
17933 \layout Standard
17934
17935 18F6720
17936 \end_inset 
17937 </cell>
17938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17939 \begin_inset Text
17940
17941 \layout Standard
17942
17943 18F8520
17944 \end_inset 
17945 </cell>
17946 </row>
17947 <row topline="true" bottomline="true">
17948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17949 \begin_inset Text
17950
17951 \layout Standard
17952
17953 18F8620
17954 \end_inset 
17955 </cell>
17956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17957 \begin_inset Text
17958
17959 \layout Standard
17960
17961 18F8680
17962 \end_inset 
17963 </cell>
17964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17965 \begin_inset Text
17966
17967 \layout Standard
17968
17969 18F8720
17970 \end_inset 
17971 </cell>
17972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17973 \begin_inset Text
17974
17975 \layout Standard
17976
17977 \end_inset 
17978 </cell>
17979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17980 \begin_inset Text
17981
17982 \layout Standard
17983
17984 \end_inset 
17985 </cell>
17986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17987 \begin_inset Text
17988
17989 \layout Standard
17990
17991 \end_inset 
17992 </cell>
17993 </row>
17994 </lyxtabular>
17995
17996 \end_inset 
17997
17998
17999 \layout Subsection
18000
18001 Global Options
18002 \layout Standard
18003
18004 PIC16 port supports the standard command line arguments as supposed, with
18005  the exception of certain cases that will be mentioned in the following
18006  list:
18007 \layout List
18008 \labelwidthstring 00.00.0000
18009
18010 -
18011 \begin_inset ERT
18012 status Collapsed
18013
18014 \layout Standard
18015
18016 \backslash 
18017 /
18018 \end_inset 
18019
18020 -callee-saves
18021 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
18022
18023 \end_inset 
18024
18025  See -
18026 \begin_inset ERT
18027 status Collapsed
18028
18029 \layout Standard
18030
18031 \backslash 
18032 /
18033 \end_inset 
18034
18035 -all-callee-saves
18036 \layout List
18037 \labelwidthstring 00.00.0000
18038
18039 -
18040 \begin_inset ERT
18041 status Collapsed
18042
18043 \layout Standard
18044
18045 \backslash 
18046 /
18047 \end_inset 
18048
18049 -all-callee-saves
18050 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
18051
18052 \end_inset 
18053
18054  All function arguments are passed on stack by default.
18055  
18056 \emph on 
18057 There is no need to specify this in the command line.
18058 \layout List
18059 \labelwidthstring 00.00.0000
18060
18061 -
18062 \begin_inset ERT
18063 status Collapsed
18064
18065 \layout Standard
18066
18067 \backslash 
18068 /
18069 \end_inset 
18070
18071 -fommit-frame-pointer
18072 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
18073
18074 \end_inset 
18075
18076  Frame pointer will be omitted when the function uses no local variables.
18077 \layout Subsection
18078
18079 Port Specific Options
18080 \begin_inset LatexCommand \index{Options PIC16}
18081
18082 \end_inset 
18083
18084
18085 \layout Standard
18086
18087 The port specific options appear after the global options in the sdcc --help
18088  output.
18089 \layout Subsubsection
18090
18091 General Options
18092 \layout Standard
18093
18094 General options enable certain port features and optimizations.
18095 \layout List
18096 \labelwidthstring 00.00.0000
18097
18098 -
18099 \begin_inset ERT
18100 status Collapsed
18101
18102 \layout Standard
18103
18104 \backslash 
18105 /
18106 \end_inset 
18107
18108 -stack-model=[model] Used in conjuction with the command above.
18109  Defines the stack model to be used, valid stack models are : 
18110 \begin_deeper 
18111 \layout List
18112 \labelwidthstring 00.00.0000
18113
18114
18115 \emph on 
18116 small
18117 \emph default 
18118  Selects small stack model.
18119  8 bit stack and frame pointers.
18120  Supports 256 bytes stack size.
18121 \layout List
18122 \labelwidthstring 00.00.0000
18123
18124
18125 \emph on 
18126 large
18127 \emph default 
18128  Selects large stack model.
18129  16 bit stack and frame pointers.
18130  Supports 65536 bytes stack size.
18131 \end_deeper 
18132 \layout List
18133 \labelwidthstring 00.00.0000
18134
18135 -
18136 \begin_inset ERT
18137 status Collapsed
18138
18139 \layout Standard
18140
18141 \backslash 
18142 /
18143 \end_inset 
18144
18145 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
18146  unitialized data variables with [kword].
18147  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
18148 \layout List
18149 \labelwidthstring 00.00.0000
18150
18151 -
18152 \begin_inset ERT
18153 status Collapsed
18154
18155 \layout Standard
18156
18157 \backslash 
18158 /
18159 \end_inset 
18160
18161 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
18162  Useful for bootloaders.
18163 \layout List
18164 \labelwidthstring 00.00.0000
18165
18166 -
18167 \begin_inset ERT
18168 status Collapsed
18169
18170 \layout Standard
18171
18172 \backslash 
18173 /
18174 \end_inset 
18175
18176 -asm= sets the full path and name of an external assembler to call.
18177 \layout List
18178 \labelwidthstring 00.00.0000
18179
18180 -
18181 \begin_inset ERT
18182 status Collapsed
18183
18184 \layout Standard
18185
18186 \backslash 
18187 /
18188 \end_inset 
18189
18190 -link= sets the full path and name of an external linker to call.
18191 \layout List
18192 \labelwidthstring 00.00.0000
18193
18194 -
18195 \begin_inset ERT
18196 status Collapsed
18197
18198 \layout Standard
18199
18200 \backslash 
18201 /
18202 \end_inset 
18203
18204 -mplab-comp MPLAB
18205 \begin_inset LatexCommand \index{PIC16!MPLAB}
18206
18207 \end_inset 
18208
18209  compatibility option.
18210  Currently only suppresses special gpasm directives.
18211 \layout Subsubsection
18212
18213 Optimization Options
18214 \layout List
18215 \labelwidthstring 00.00.0000
18216
18217 -
18218 \begin_inset ERT
18219 status Collapsed
18220
18221 \layout Standard
18222
18223 \backslash 
18224 /
18225 \end_inset 
18226
18227 -optimize-goto Try to use (conditional) BRA instead of GOTO
18228 \layout List
18229 \labelwidthstring 00.00.0000
18230
18231 -
18232 \begin_inset ERT
18233 status Collapsed
18234
18235 \layout Standard
18236
18237 \backslash 
18238 /
18239 \end_inset 
18240
18241 -optimize-cmp Try to optimize some compares.
18242 \layout List
18243 \labelwidthstring 00.00.0000
18244
18245 -
18246 \begin_inset ERT
18247 status Collapsed
18248
18249 \layout Standard
18250
18251 \backslash 
18252 /
18253 \end_inset 
18254
18255 -optimize-df Analyze the dataflow of the generated code and improve it.
18256 \layout List
18257 \labelwidthstring 00.00.0000
18258
18259 -
18260 \begin_inset ERT
18261 status Collapsed
18262
18263 \layout Standard
18264
18265 \backslash 
18266 /
18267 \end_inset 
18268
18269 -obanksel=nn Set optimization level for inserting BANKSELs.
18270 \newline 
18271
18272 \begin_deeper 
18273 \layout List
18274 \labelwidthstring 00.00.0000
18275
18276 0 no optimization
18277 \layout List
18278 \labelwidthstring 00.00.0000
18279
18280 1 checks previous used register and if it is the same then does not emit
18281  BANKSEL, accounts only for labels.
18282 \layout List
18283 \labelwidthstring 00.00.0000
18284
18285 2 tries to check the location of (even different) symbols and removes BANKSELs
18286  if they are in the same bank.
18287  
18288 \newline 
18289
18290 \emph on 
18291 Important: There might be problems if the linker script has data sections
18292  across bank borders!
18293 \end_deeper 
18294 \layout Subsubsection
18295
18296 Linking Options
18297 \layout List
18298 \labelwidthstring 00.00.0000
18299
18300 -
18301 \begin_inset ERT
18302 status Collapsed
18303
18304 \layout Standard
18305
18306 \backslash 
18307 /
18308 \end_inset 
18309
18310 -nodefaultlibs do not link default libraries when linking
18311 \layout List
18312 \labelwidthstring 00.00.0000
18313
18314 -
18315 \begin_inset ERT
18316 status Collapsed
18317
18318 \layout Standard
18319
18320 \backslash 
18321 /
18322 \end_inset 
18323
18324 -no-crt Don't link the default run-time modules
18325 \layout List
18326 \labelwidthstring 00.00.0000
18327
18328 -
18329 \begin_inset ERT
18330 status Collapsed
18331
18332 \layout Standard
18333
18334 \backslash 
18335 /
18336 \end_inset 
18337
18338 -use-crt= Use a custom run-time module instead of the defaults.
18339 \layout Subsubsection
18340
18341 Debugging Options
18342 \layout Standard
18343
18344 Debugging options enable extra debugging information in the output files.
18345 \layout List
18346 \labelwidthstring 00.00.0000
18347
18348 -
18349 \begin_inset ERT
18350 status Collapsed
18351
18352 \layout Standard
18353
18354 \backslash 
18355 /
18356 \end_inset 
18357
18358 -debug-xtra Similar to -
18359 \begin_inset ERT
18360 status Collapsed
18361
18362 \layout Standard
18363
18364 \backslash 
18365 /
18366 \end_inset 
18367
18368 -debug
18369 \begin_inset LatexCommand \index{-\/-debug}
18370
18371 \end_inset 
18372
18373 , but dumps more information.
18374 \layout List
18375 \labelwidthstring 00.00.0000
18376
18377 -
18378 \begin_inset ERT
18379 status Collapsed
18380
18381 \layout Standard
18382
18383 \backslash 
18384 /
18385 \end_inset 
18386
18387 -debug-ralloc Force register allocator to dump <source>.d file with debugging
18388  information.
18389  <source> is the name of the file compiled.
18390 \layout List
18391 \labelwidthstring 00.00.0000
18392
18393 -
18394 \begin_inset ERT
18395 status Collapsed
18396
18397 \layout Standard
18398
18399 \backslash 
18400 /
18401 \end_inset 
18402
18403 -pcode-verbose Enable pcode debugging information in translation.
18404 \layout List
18405 \labelwidthstring 00.00.0000
18406
18407 -
18408 \begin_inset ERT
18409 status Collapsed
18410
18411 \layout Standard
18412
18413 \backslash 
18414 /
18415 \end_inset 
18416
18417 -denable-peeps Force the usage of peepholes.
18418  Use with care.
18419 \layout List
18420 \labelwidthstring 00.00.0000
18421
18422 -
18423 \begin_inset ERT
18424 status Collapsed
18425
18426 \layout Standard
18427
18428 \backslash 
18429 /
18430 \end_inset 
18431
18432 -gstack Trace push/pops for stack pointer overflow
18433 \layout List
18434 \labelwidthstring 00.00.0000
18435
18436 -
18437 \begin_inset ERT
18438 status Collapsed
18439
18440 \layout Standard
18441
18442 \backslash 
18443 /
18444 \end_inset 
18445
18446 -call-tree dump call tree in .calltree file
18447 \layout Subsection
18448
18449 Enviromental Variables
18450 \layout Standard
18451
18452 There is a number of enviromental variables that can be used when running
18453  SDCC to enable certain optimizations or force a specific program behaviour.
18454  these variables are primarily for debugging purposes so they can be enabled/dis
18455 abled at will.
18456 \layout Standard
18457
18458 Currently there is only two such variables available:
18459 \layout List
18460 \labelwidthstring 00.00.0000
18461
18462 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18463  bitfields is optimized by directly loading FSR0 with the address of the
18464  bitfield structure.
18465  Normally SDCC will cast the bitfield structure to a bitfield pointer and
18466  then load FSR0.
18467  This step saves data ram and code space for functions that perform heavy
18468  use of bitfields.
18469  (ie.
18470  80 bytes of code space are saved when compiling malloc.c with this option).
18471  
18472 \layout List
18473 \labelwidthstring 00.00.0000
18474
18475 NO_REG_OPT do not perform pCode registers optimization.
18476  This should be used for debugging purposes.
18477  In some where bugs in the pcode optimizer are found, users can benefit
18478  from temporarily disabling the optimizer until the bug is fixed.
18479 \layout Subsection
18480
18481 Preprocessor Macros
18482 \layout Standard
18483
18484 PIC16 port defines the following preprocessor macros while translating a
18485  source.
18486 \layout Standard
18487 \align center 
18488
18489 \begin_inset  Tabular
18490 <lyxtabular version="3" rows="6" columns="2">
18491 <features>
18492 <column alignment="center" valignment="top" leftline="true" width="0">
18493 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18494 <row topline="true" bottomline="true">
18495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18496 \begin_inset Text
18497
18498 \layout Standard
18499
18500 Macro
18501 \end_inset 
18502 </cell>
18503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18504 \begin_inset Text
18505
18506 \layout Standard
18507
18508 Description
18509 \end_inset 
18510 </cell>
18511 </row>
18512 <row topline="true">
18513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18514 \begin_inset Text
18515
18516 \layout Standard
18517
18518 SDCC_pic16
18519 \end_inset 
18520 </cell>
18521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18522 \begin_inset Text
18523
18524 \layout Standard
18525
18526 Port identification
18527 \end_inset 
18528 </cell>
18529 </row>
18530 <row topline="true">
18531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18532 \begin_inset Text
18533
18534 \layout Standard
18535
18536 _
18537 \begin_inset ERT
18538 status Collapsed
18539
18540 \layout Standard
18541
18542 \backslash 
18543 /
18544 \end_inset 
18545
18546 _pic16
18547 \end_inset 
18548 </cell>
18549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18550 \begin_inset Text
18551
18552 \layout Standard
18553
18554 Port identification (same as above)
18555 \end_inset 
18556 </cell>
18557 </row>
18558 <row topline="true">
18559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18560 \begin_inset Text
18561
18562 \layout Standard
18563
18564 pic18fxxxx
18565 \end_inset 
18566 </cell>
18567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18568 \begin_inset Text
18569
18570 \layout Standard
18571
18572 MCU Identification.
18573  
18574 \emph on 
18575 xxxx
18576 \emph default 
18577  is the microcontrol identification number, i.e.
18578  452, 6620, etc
18579 \end_inset 
18580 </cell>
18581 </row>
18582 <row topline="true">
18583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18584 \begin_inset Text
18585
18586 \layout Standard
18587
18588 _
18589 \begin_inset ERT
18590 status Collapsed
18591
18592 \layout Standard
18593
18594 \backslash 
18595 /
18596 \end_inset 
18597
18598 _18Fxxxx
18599 \end_inset 
18600 </cell>
18601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18602 \begin_inset Text
18603
18604 \layout Standard
18605
18606 MCU Identification (same as above)
18607 \end_inset 
18608 </cell>
18609 </row>
18610 <row topline="true" bottomline="true">
18611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18612 \begin_inset Text
18613
18614 \layout Standard
18615
18616 STACK_MODEL_nnn
18617 \end_inset 
18618 </cell>
18619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18620 \begin_inset Text
18621
18622 \layout Standard
18623
18624 nnn = SMALL or LARGE respectively according to the stack model used
18625 \end_inset 
18626 </cell>
18627 </row>
18628 </lyxtabular>
18629
18630 \end_inset 
18631
18632
18633 \layout Standard
18634
18635 In addition the following macros are defined when calling assembler:
18636 \layout Standard
18637 \align center 
18638
18639 \begin_inset  Tabular
18640 <lyxtabular version="3" rows="4" columns="2">
18641 <features>
18642 <column alignment="center" valignment="top" leftline="true" width="0">
18643 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18644 <row topline="true" bottomline="true">
18645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18646 \begin_inset Text
18647
18648 \layout Standard
18649
18650 Macro
18651 \end_inset 
18652 </cell>
18653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18654 \begin_inset Text
18655
18656 \layout Standard
18657
18658 Description
18659 \end_inset 
18660 </cell>
18661 </row>
18662 <row topline="true">
18663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18664 \begin_inset Text
18665
18666 \layout Standard
18667
18668 __18Fxxxx
18669 \end_inset 
18670 </cell>
18671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18672 \begin_inset Text
18673
18674 \layout Standard
18675
18676 MCU Identification.
18677  
18678 \emph on 
18679 xxxx
18680 \emph default 
18681  is the microcontrol identification number, i.e.
18682  452, 6620, etc
18683 \end_inset 
18684 </cell>
18685 </row>
18686 <row topline="true">
18687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18688 \begin_inset Text
18689
18690 \layout Standard
18691
18692 SDCC_MODEL_nnn
18693 \end_inset 
18694 </cell>
18695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18696 \begin_inset Text
18697
18698 \layout Standard
18699
18700 nnn = SMALL or LARGE respectively according to the memory model used for
18701  SDCC
18702 \end_inset 
18703 </cell>
18704 </row>
18705 <row topline="true" bottomline="true">
18706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18707 \begin_inset Text
18708
18709 \layout Standard
18710
18711 STACK_MODEL_nnn
18712 \end_inset 
18713 </cell>
18714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18715 \begin_inset Text
18716
18717 \layout Standard
18718
18719 nnn = SMALL or LARGE respectively according to the stack model used
18720 \end_inset 
18721 </cell>
18722 </row>
18723 </lyxtabular>
18724
18725 \end_inset 
18726
18727
18728 \layout Subsection
18729
18730 Directories
18731 \layout Standard
18732
18733 PIC16
18734 \begin_inset LatexCommand \index{PIC16}
18735
18736 \end_inset 
18737
18738  port uses the following directories for searching header files and libraries.
18739 \layout Standard
18740 \align center 
18741
18742 \begin_inset  Tabular
18743 <lyxtabular version="3" rows="3" columns="4">
18744 <features>
18745 <column alignment="center" valignment="top" leftline="true" width="0">
18746 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18747 <column alignment="center" valignment="top" width="0">
18748 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18749 <row topline="true" bottomline="true">
18750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18751 \begin_inset Text
18752
18753 \layout Standard
18754
18755 Directory
18756 \end_inset 
18757 </cell>
18758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18759 \begin_inset Text
18760
18761 \layout Standard
18762
18763 Description
18764 \end_inset 
18765 </cell>
18766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18767 \begin_inset Text
18768
18769 \layout Standard
18770
18771 Target
18772 \end_inset 
18773 </cell>
18774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18775 \begin_inset Text
18776
18777 \layout Standard
18778
18779 Command prefix
18780 \end_inset 
18781 </cell>
18782 </row>
18783 <row topline="true">
18784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18785 \begin_inset Text
18786
18787 \layout Standard
18788
18789 PREFIX/sdcc/include/pic16
18790 \end_inset 
18791 </cell>
18792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18793 \begin_inset Text
18794
18795 \layout Standard
18796
18797 PIC16 specific headers
18798 \end_inset 
18799 </cell>
18800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18801 \begin_inset Text
18802
18803 \layout Standard
18804
18805 Compiler
18806 \end_inset 
18807 </cell>
18808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18809 \begin_inset Text
18810
18811 \layout Standard
18812
18813 -I
18814 \end_inset 
18815 </cell>
18816 </row>
18817 <row topline="true" bottomline="true">
18818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18819 \begin_inset Text
18820
18821 \layout Standard
18822
18823 PREFIX/sdcc/lib/pic16
18824 \end_inset 
18825 </cell>
18826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18827 \begin_inset Text
18828
18829 \layout Standard
18830
18831 PIC16 specific libraries
18832 \end_inset 
18833 </cell>
18834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18835 \begin_inset Text
18836
18837 \layout Standard
18838
18839 Linker
18840 \end_inset 
18841 </cell>
18842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18843 \begin_inset Text
18844
18845 \layout Standard
18846
18847 -L
18848 \end_inset 
18849 </cell>
18850 </row>
18851 </lyxtabular>
18852
18853 \end_inset 
18854
18855
18856 \layout Subsection
18857
18858 Pragmas
18859 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
18860
18861 \end_inset 
18862
18863
18864 \layout Standard
18865
18866 PIC16 port currently supports the following pragmas:
18867 \layout List
18868 \labelwidthstring 00.00.0000
18869
18870 stack
18871 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
18872
18873 \end_inset 
18874
18875  pragma stack
18876 \begin_inset LatexCommand \index{PIC16!stack}
18877
18878 \end_inset 
18879
18880  forces the code generator to initialize the stack & frame pointers at a
18881  specific address.
18882  This is an adhoc solution for cases where no STACK directive is available
18883  in the linker script or gplink is not instructed to create a stack section.
18884 \newline 
18885 The stack pragma should be used only once in a project.
18886  Multiple pragmas may result in indeterminate behaviour of the program.
18887 \begin_inset Foot
18888 collapsed false
18889
18890 \layout Standard
18891
18892 The old format (ie.
18893  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
18894  cross page boundaries (or even exceed the available data RAM) and crash
18895  the program.
18896  Make sure that stack does not cross page boundaries when using the SMALL
18897  stack model.
18898 \end_inset 
18899
18900
18901 \newline 
18902 The format is as follows:
18903 \layout LyX-Code
18904
18905 #pragma stack bottom_address [stack_size]
18906 \layout Standard
18907
18908
18909 \emph on 
18910 bottom_address
18911 \emph default 
18912  is the lower bound of the stack section.
18913  The stack pointer initially will point at address (bottom_address+stack_size-1).
18914 \layout LyX-Code
18915
18916 Example:
18917 \layout LyX-Code
18918
18919 \layout LyX-Code
18920
18921 /* initializes stack of 100 bytes at RAM address 0x200 */
18922 \layout LyX-Code
18923
18924 #pragma stack 0x200 100
18925 \layout Standard
18926
18927 If the stack_size field is omitted then a stack is created with the default
18928  size of 64.
18929  This size might be enough for most programs, but its not enough for operations
18930  with deep function nesting or excessive stack usage.
18931 \layout List
18932 \labelwidthstring 00.00.0000
18933
18934 wparam 
18935 \emph on 
18936 This pragma is deprecated.
18937  Its use will cause a warning message to be issued.
18938 \emph default 
18939
18940 \newline 
18941
18942 \layout List
18943 \labelwidthstring 00.00.0000
18944
18945 code
18946 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
18947
18948 \end_inset 
18949
18950  place a function symbol at static FLASH address
18951 \layout LyX-Code
18952
18953 Example:
18954 \layout LyX-Code
18955
18956 \layout LyX-Code
18957
18958 /* place function test_func at 0x4000 */
18959 \layout LyX-Code
18960
18961 #pragma code test_func 0x4000
18962 \layout LyX-Code
18963
18964 \layout List
18965 \labelwidthstring 00.00.0000
18966
18967 library instructs the linker to use a library module.
18968 \newline 
18969 Usage:
18970 \layout LyX-Code
18971
18972 #pragma library module_name
18973 \layout Standard
18974
18975
18976 \emph on 
18977 module_name
18978 \emph default 
18979  can be any library or object file (including its path).
18980  Note that there are four reserved keywords which have special meaning.
18981  These are:
18982 \layout Standard
18983 \align center 
18984
18985 \begin_inset  Tabular
18986 <lyxtabular version="3" rows="6" columns="3">
18987 <features>
18988 <column alignment="center" valignment="top" leftline="true" width="0">
18989 <column alignment="block" valignment="top" leftline="true" width="20page%">
18990 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18991 <row topline="true" bottomline="true">
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18993 \begin_inset Text
18994
18995 \layout Standard
18996
18997 Keyword
18998 \end_inset 
18999 </cell>
19000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19001 \begin_inset Text
19002
19003 \layout Standard
19004
19005 Description
19006 \end_inset 
19007 </cell>
19008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19009 \begin_inset Text
19010
19011 \layout Standard
19012
19013 Module to link
19014 \end_inset 
19015 </cell>
19016 </row>
19017 <row topline="true">
19018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19019 \begin_inset Text
19020
19021 \layout Standard
19022
19023
19024 \series bold 
19025 ignore
19026 \end_inset 
19027 </cell>
19028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19029 \begin_inset Text
19030
19031 \layout Standard
19032
19033 ignore all library pragmas
19034 \end_inset 
19035 </cell>
19036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19037 \begin_inset Text
19038
19039 \layout Standard
19040
19041
19042 \emph on 
19043 (none)
19044 \end_inset 
19045 </cell>
19046 </row>
19047 <row topline="true">
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19049 \begin_inset Text
19050
19051 \layout Standard
19052
19053
19054 \series bold 
19055 c
19056 \end_inset 
19057 </cell>
19058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19059 \begin_inset Text
19060
19061 \layout Standard
19062
19063 link the C library
19064 \end_inset 
19065 </cell>
19066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19067 \begin_inset Text
19068
19069 \layout Standard
19070
19071
19072 \emph on 
19073 libc18f
19074 \emph default 
19075 .lib
19076 \end_inset 
19077 </cell>
19078 </row>
19079 <row topline="true">
19080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19081 \begin_inset Text
19082
19083 \layout Standard
19084
19085
19086 \series bold 
19087 math
19088 \end_inset 
19089 </cell>
19090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19091 \begin_inset Text
19092
19093 \layout Standard
19094
19095 link the Math libarary
19096 \end_inset 
19097 </cell>
19098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19099 \begin_inset Text
19100
19101 \layout Standard
19102
19103
19104 \emph on 
19105 libm18f
19106 \emph default 
19107 .lib
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 \series bold 
19119 io
19120 \end_inset 
19121 </cell>
19122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19123 \begin_inset Text
19124
19125 \layout Standard
19126
19127 link the I/O library
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
19136 \emph on 
19137 libio18f*
19138 \emph default 
19139 .lib
19140 \end_inset 
19141 </cell>
19142 </row>
19143 <row topline="true" bottomline="true">
19144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19145 \begin_inset Text
19146
19147 \layout Standard
19148
19149
19150 \series bold 
19151 debug
19152 \end_inset 
19153 </cell>
19154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19155 \begin_inset Text
19156
19157 \layout Standard
19158
19159 link the debug library
19160 \end_inset 
19161 </cell>
19162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19163 \begin_inset Text
19164
19165 \layout Standard
19166
19167
19168 \emph on 
19169 libdebug
19170 \emph default 
19171 .lib
19172 \end_inset 
19173 </cell>
19174 </row>
19175 </lyxtabular>
19176
19177 \end_inset 
19178
19179
19180 \newline 
19181 * is the device number, i.e.
19182  452 for PIC18F452 MCU.
19183 \layout Standard
19184
19185 This feature allows for linking with specific libraries withoug having to
19186  explicit name them in the command line.
19187  Note that the 
19188 \noun on 
19189 ignore
19190 \noun default 
19191  keyword will reject all modules specified by the library pragma.
19192 \layout List
19193 \labelwidthstring 00.00.0000
19194
19195 udata pragma udata instructs the compiler to emit code so that linker will
19196  place a variable at a specific memory bank
19197 \layout LyX-Code
19198
19199 Example:
19200 \layout LyX-Code
19201
19202 \layout LyX-Code
19203
19204 /* places variable foo at bank2 */
19205 \layout LyX-Code
19206
19207 #pragma udata bank2 foo
19208 \layout LyX-Code
19209
19210 char foo;
19211 \layout Standard
19212
19213 In order for this pragma to work extra SECTION directives should be added
19214  in the .lkr script.
19215  In the following example a sample .lkr file is shown:
19216 \layout LyX-Code
19217
19218 \layout LyX-Code
19219
19220 // Sample linker script for the PIC18F452 processor
19221 \layout LyX-Code
19222
19223 LIBPATH .
19224 \layout LyX-Code
19225
19226 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
19227 \layout LyX-Code
19228
19229 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
19230 \layout LyX-Code
19231
19232 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
19233 \layout LyX-Code
19234
19235 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
19236 \layout LyX-Code
19237
19238 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
19239 \layout LyX-Code
19240
19241 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
19242 \layout LyX-Code
19243
19244 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
19245 \layout LyX-Code
19246
19247 \layout LyX-Code
19248
19249 DATABANK   NAME=gpr0       START=0x80           END=0xFF
19250 \layout LyX-Code
19251
19252 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
19253 \layout LyX-Code
19254
19255 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
19256 \layout LyX-Code
19257
19258 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
19259 \layout LyX-Code
19260
19261 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
19262 \layout LyX-Code
19263
19264 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
19265 \layout LyX-Code
19266
19267 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
19268 \layout LyX-Code
19269
19270 \layout LyX-Code
19271
19272 SECTION    NAME=CONFIG     ROM=config
19273 \layout LyX-Code
19274
19275 \layout LyX-Code
19276
19277 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
19278 \layout LyX-Code
19279
19280 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
19281 \layout LyX-Code
19282
19283 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
19284 \layout LyX-Code
19285
19286 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
19287 \layout LyX-Code
19288
19289 SECTION    NAME=bank4      RAM=gpr4
19290 \layout LyX-Code
19291
19292 SECTION    NAME=bank5      RAM=gpr5
19293 \layout Standard
19294
19295 The linker will recognise the section name set in the pragma statement and
19296  will position the variable at the memory bank set with the RAM field at
19297  the SECTION line in the linker script file.
19298 \layout Subsection
19299
19300 Header Files
19301 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19302
19303 \end_inset 
19304
19305
19306 \layout Standard
19307
19308 There is one main header file
19309 \begin_inset LatexCommand \index{PIC16!Header files}
19310
19311 \end_inset 
19312
19313  that can be included to the source files using the pic16 port.
19314  That file is the 
19315 \series bold 
19316 pic18fregs.h
19317 \series default 
19318 .
19319  This header file contains the definitions for the processor special registers,
19320  so it is necessary if the source accesses them.
19321  It can be included by adding the following line in the beginning of the
19322  file:
19323 \layout LyX-Code
19324
19325 #include <pic18fregs.h>
19326 \layout Standard
19327
19328 The specific microcontroller is selected within the pic18fregs.h automatically,
19329  so the same source can be used with a variety of devices.
19330 \layout Subsection
19331
19332 Libraries
19333 \layout Standard
19334
19335 The libraries
19336 \begin_inset LatexCommand \index{PIC16!Libraries}
19337
19338 \end_inset 
19339
19340  that PIC16
19341 \begin_inset LatexCommand \index{PIC16}
19342
19343 \end_inset 
19344
19345  port depends on are the microcontroller device libraries which contain
19346  the symbol definitions for the microcontroller special function registers.
19347  These libraries have the format pic18fxxxx.lib, where 
19348 \emph on 
19349 xxxx
19350 \emph default 
19351  is the microcontroller identification number.
19352  The specific library is selected automatically by the compiler at link
19353  stage according to the selected device.
19354 \layout Standard
19355
19356 Libraries are created with gplib which is part of the gputils package 
19357 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19358
19359 \end_inset 
19360
19361 .
19362 \layout Subsubsection*
19363
19364 Building the libraries
19365 \layout Standard
19366
19367 Before using SDCC/pic16 there are some libraries that need to be compiled.
19368  This process is not done automatically by SDCC since not all users use
19369  SDCC for pic16 projects.
19370  So each user should compile the libraries separately.
19371 \layout Standard
19372
19373 The steps to compile the pic16 libraries under Linux are:
19374 \layout LyX-Code
19375
19376 cd device/lib/pic16
19377 \layout LyX-Code
19378
19379 ./configure
19380 \layout LyX-Code
19381
19382 make
19383 \layout LyX-Code
19384
19385 cd ..
19386 \layout LyX-Code
19387
19388 make model-pic16
19389 \layout LyX-Code
19390
19391 su -c 'make install'     # install the libraries, you need the root password
19392 \layout Standard
19393
19394 If you need to install the headers too, do:
19395 \layout LyX-Code
19396
19397 cd device/include
19398 \layout LyX-Code
19399
19400 su -c 'make install'     # install the headers, you need the root password
19401 \layout Standard
19402
19403 There exist a special target to build the I/O libraries.
19404  This target is not automatically build because it will build the I/O library
19405  for 
19406 \emph on 
19407 every
19408 \emph default 
19409  supported device.
19410  This way building will take quite a lot of time.
19411  Users are advised to edit the 
19412 \series bold 
19413 device/lib/pic16/pics.build
19414 \series default 
19415  file and then execute:
19416 \layout LyX-Code
19417
19418 make lib-io
19419 \layout Subsection
19420
19421 Memory Models
19422 \layout Standard
19423
19424 The following memory models are supported by the PIC16 port:
19425 \layout Itemize
19426
19427 small model
19428 \layout Itemize
19429
19430 large model
19431 \layout Standard
19432
19433 Memory model affects the default size of pointers within the source.
19434  The sizes are shown in the next table:
19435 \layout Standard
19436 \align center 
19437
19438 \begin_inset  Tabular
19439 <lyxtabular version="3" rows="3" columns="3">
19440 <features>
19441 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19442 <column alignment="center" valignment="top" leftline="true" width="0">
19443 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19444 <row topline="true" bottomline="true">
19445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19446 \begin_inset Text
19447
19448 \layout Standard
19449
19450 Pointer sizes according to memory model
19451 \end_inset 
19452 </cell>
19453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19454 \begin_inset Text
19455
19456 \layout Standard
19457
19458 small model
19459 \end_inset 
19460 </cell>
19461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19462 \begin_inset Text
19463
19464 \layout Standard
19465
19466 large model
19467 \end_inset 
19468 </cell>
19469 </row>
19470 <row topline="true" bottomline="true">
19471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19472 \begin_inset Text
19473
19474 \layout Standard
19475
19476 code pointers
19477 \end_inset 
19478 </cell>
19479 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19480 \begin_inset Text
19481
19482 \layout Standard
19483
19484 16-bits
19485 \end_inset 
19486 </cell>
19487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19488 \begin_inset Text
19489
19490 \layout Standard
19491
19492 24-bits
19493 \end_inset 
19494 </cell>
19495 </row>
19496 <row topline="true" bottomline="true">
19497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19498 \begin_inset Text
19499
19500 \layout Standard
19501
19502 data pointers
19503 \end_inset 
19504 </cell>
19505 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
19506 \begin_inset Text
19507
19508 \layout Standard
19509
19510 16-bits
19511 \end_inset 
19512 </cell>
19513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19514 \begin_inset Text
19515
19516 \layout Standard
19517
19518 16-bits
19519 \end_inset 
19520 </cell>
19521 </row>
19522 </lyxtabular>
19523
19524 \end_inset 
19525
19526
19527 \layout Standard
19528
19529 It is advisable that all sources within a project are compiled with the
19530  same memory model.
19531  If one wants to override the default memory model, this can be done by
19532  declaring a pointer as 
19533 \series bold 
19534 far
19535 \series default 
19536  or 
19537 \series bold 
19538 near
19539 \series default 
19540 .
19541  Far selects large memory model's pointers, while near selects small memory
19542  model's pointers.
19543 \layout Standard
19544
19545 The standard device libraries (see 
19546 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
19547
19548 \end_inset 
19549
19550 ) contain no reference to pointers, so they can be used with both memory
19551  models.
19552 \layout Subsection
19553
19554 Stack
19555 \layout Standard
19556
19557 The stack
19558 \begin_inset LatexCommand \index{PIC16!stack}
19559
19560 \end_inset 
19561
19562  implementation for the PIC16 port uses two indirect registers, FSR1 and
19563  FSR2.
19564 \layout List
19565 \labelwidthstring 00.00.0000
19566
19567 FSR1 is assigned as stack pointer
19568 \layout List
19569 \labelwidthstring 00.00.0000
19570
19571 FSR2 is assigned as frame pointer
19572 \layout Standard
19573
19574 The following stack models are supported by the PIC16 port
19575 \layout Itemize
19576
19577
19578 \noun on 
19579 small
19580 \noun default 
19581  model
19582 \layout Itemize
19583
19584
19585 \noun on 
19586 large
19587 \noun default 
19588  model
19589 \layout Standard
19590
19591
19592 \noun on 
19593 Small
19594 \noun default 
19595  model means that only the FSRxL byte is used to access stack and frame,
19596  while 
19597 \emph on 
19598 \noun on 
19599 large
19600 \emph default 
19601 \noun default 
19602  uses both FSRxL and FSRxH registers.
19603  The following table shows the stack/frame pointers sizes according to stack
19604  model and the maximum space they can address:
19605 \layout Standard
19606 \align center 
19607
19608 \begin_inset  Tabular
19609 <lyxtabular version="3" rows="3" columns="3">
19610 <features>
19611 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19612 <column alignment="center" valignment="top" leftline="true" width="0">
19613 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19614 <row topline="true" bottomline="true">
19615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19616 \begin_inset Text
19617
19618 \layout Standard
19619
19620 Stack & Frame pointer sizes according to stack model
19621 \end_inset 
19622 </cell>
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19624 \begin_inset Text
19625
19626 \layout Standard
19627
19628 small
19629 \end_inset 
19630 </cell>
19631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19632 \begin_inset Text
19633
19634 \layout Standard
19635
19636 large
19637 \end_inset 
19638 </cell>
19639 </row>
19640 <row topline="true">
19641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19642 \begin_inset Text
19643
19644 \layout Standard
19645
19646 Stack pointer FSR1
19647 \end_inset 
19648 </cell>
19649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19650 \begin_inset Text
19651
19652 \layout Standard
19653
19654 8-bits
19655 \end_inset 
19656 </cell>
19657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19658 \begin_inset Text
19659
19660 \layout Standard
19661
19662 16-bits
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 Frame pointer FSR2
19673 \end_inset 
19674 </cell>
19675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19676 \begin_inset Text
19677
19678 \layout Standard
19679
19680 8-bits
19681 \end_inset 
19682 </cell>
19683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19684 \begin_inset Text
19685
19686 \layout Standard
19687
19688 16-bits
19689 \end_inset 
19690 </cell>
19691 </row>
19692 </lyxtabular>
19693
19694 \end_inset 
19695
19696
19697 \layout Standard
19698
19699
19700 \noun on 
19701 Large 
19702 \noun default 
19703 stack model is currently not working properly throughout the code generator.
19704  So its use is not advised.
19705  Also there are some other points that need special care:
19706 \newline 
19707
19708 \layout Enumerate
19709
19710 Do not create stack sections with size more than one physical bank (that
19711  is 256 bytes)
19712 \layout Enumerate
19713
19714 Stack sections should no cross physical bank limits (i.e.
19715  #pragma stack 0x50 0x100)
19716 \layout Standard
19717
19718 These limitations are caused by the fact that only FSRxL is modified when
19719  using SMALL stack model, so no more than 256 bytes of stack can be used.
19720  This problem will disappear after LARGE model is fully implemented.
19721 \layout Subsection
19722
19723 Functions
19724 \layout Standard
19725
19726 In addition to the standard SDCC function keywords, PIC16 port makes available
19727  two more:
19728 \layout List
19729 \labelwidthstring 00.00.0000
19730
19731 wparam
19732 \begin_inset LatexCommand \index{PIC16!wparam}
19733
19734 \end_inset 
19735
19736  Use the WREG to pass one byte of the first function argument.
19737  This improves speed but you may not use this for functions with arguments
19738  that are called via function pointers, otherwise the first byte of the
19739  first parameter will get lost.
19740  Usage:
19741 \layout LyX-Code
19742
19743 void func_wparam(int a) wparam
19744 \layout LyX-Code
19745
19746 {
19747 \layout LyX-Code
19748
19749     /* WREG hold the lower part of a */
19750 \layout LyX-Code
19751
19752     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
19753  */
19754 \layout LyX-Code
19755
19756 ...
19757 \layout LyX-Code
19758
19759 }
19760 \layout Standard
19761
19762 This keyword replaces the deprecated wparam pragma.
19763 \layout List
19764 \labelwidthstring 00.00.0000
19765
19766 shadowregs
19767 \begin_inset LatexCommand \index{PIC16!shadowregs}
19768
19769 \end_inset 
19770
19771  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
19772  hardware shadow registers which hold the values of WREG, STATUS and BSR
19773  registers.
19774  This can be done by adding the keyword 
19775 \emph on 
19776 shadowregs
19777 \emph default 
19778  before the 
19779 \emph on 
19780 interrupt
19781 \emph default 
19782  keyword in the function's header.
19783 \layout LyX-Code
19784
19785 void isr_shadow(void) shadowregs interrupt 1
19786 \layout LyX-Code
19787
19788 {
19789 \layout LyX-Code
19790
19791 ...
19792 \layout LyX-Code
19793
19794 }
19795 \layout Standard
19796
19797
19798 \emph on 
19799 shadowregs
19800 \emph default 
19801  instructs the code generator not to store/restore WREG, STATUS, BSR when
19802  entering/exiting the ISR.
19803 \layout Subsection
19804
19805 Function return values
19806 \layout Standard
19807
19808 Return values from functions are placed to the appropriate registers following
19809  a modified Microchip policy optimized for SDCC.
19810  The following table shows these registers:
19811 \layout Standard
19812 \align center 
19813
19814 \begin_inset  Tabular
19815 <lyxtabular version="3" rows="6" columns="2">
19816 <features>
19817 <column alignment="center" valignment="top" leftline="true" width="0">
19818 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19819 <row topline="true" bottomline="true">
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19821 \begin_inset Text
19822
19823 \layout Standard
19824
19825 size
19826 \end_inset 
19827 </cell>
19828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19829 \begin_inset Text
19830
19831 \layout Standard
19832
19833 destination register
19834 \end_inset 
19835 </cell>
19836 </row>
19837 <row topline="true">
19838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19839 \begin_inset Text
19840
19841 \layout Standard
19842
19843 8 bits
19844 \end_inset 
19845 </cell>
19846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19847 \begin_inset Text
19848
19849 \layout Standard
19850
19851 WREG
19852 \end_inset 
19853 </cell>
19854 </row>
19855 <row topline="true">
19856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19857 \begin_inset Text
19858
19859 \layout Standard
19860
19861 16 bits
19862 \end_inset 
19863 </cell>
19864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19865 \begin_inset Text
19866
19867 \layout Standard
19868
19869 PRODL:WREG
19870 \end_inset 
19871 </cell>
19872 </row>
19873 <row topline="true">
19874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19875 \begin_inset Text
19876
19877 \layout Standard
19878
19879 24 bits
19880 \end_inset 
19881 </cell>
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19883 \begin_inset Text
19884
19885 \layout Standard
19886
19887 PRODH:PRODL:WREG
19888 \end_inset 
19889 </cell>
19890 </row>
19891 <row topline="true">
19892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19893 \begin_inset Text
19894
19895 \layout Standard
19896
19897 32 bits
19898 \end_inset 
19899 </cell>
19900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19901 \begin_inset Text
19902
19903 \layout Standard
19904
19905 FSR0L:PRODH:PRODL:WREG
19906 \end_inset 
19907 </cell>
19908 </row>
19909 <row topline="true" bottomline="true">
19910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19911 \begin_inset Text
19912
19913 \layout Standard
19914
19915 >32 bits
19916 \end_inset 
19917 </cell>
19918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19919 \begin_inset Text
19920
19921 \layout Standard
19922
19923 on stack, FSR0 points to the beginning
19924 \end_inset 
19925 </cell>
19926 </row>
19927 </lyxtabular>
19928
19929 \end_inset 
19930
19931
19932 \layout Subsection
19933
19934 Interrupts
19935 \layout Standard
19936
19937 An interrupt
19938 \begin_inset LatexCommand \index{PIC16!interrupt}
19939
19940 \end_inset 
19941
19942  service routine (ISR) is declared using the 
19943 \emph on 
19944 interrupt
19945 \emph default 
19946  keyword.
19947 \layout LyX-Code
19948
19949 void isr(void) interrupt 
19950 \emph on 
19951 n
19952 \layout LyX-Code
19953
19954 {
19955 \layout LyX-Code
19956
19957 ...
19958 \layout LyX-Code
19959
19960 }
19961 \layout Standard
19962
19963
19964 \emph on 
19965 n
19966 \emph default 
19967  is the interrupt number, which for PIC18F devices can be:
19968 \layout Standard
19969 \align center 
19970
19971 \begin_inset  Tabular
19972 <lyxtabular version="3" rows="4" columns="3">
19973 <features>
19974 <column alignment="center" valignment="top" leftline="true" width="0">
19975 <column alignment="center" valignment="top" leftline="true" width="0">
19976 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19977 <row topline="true" bottomline="true">
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19979 \begin_inset Text
19980
19981 \layout Standard
19982
19983
19984 \emph on 
19985 n
19986 \end_inset 
19987 </cell>
19988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19989 \begin_inset Text
19990
19991 \layout Standard
19992
19993 Interrupt Vector
19994 \end_inset 
19995 </cell>
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19997 \begin_inset Text
19998
19999 \layout Standard
20000
20001 Interrupt Vector Address
20002 \end_inset 
20003 </cell>
20004 </row>
20005 <row topline="true">
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20007 \begin_inset Text
20008
20009 \layout Standard
20010
20011 0
20012 \end_inset 
20013 </cell>
20014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20015 \begin_inset Text
20016
20017 \layout Standard
20018
20019 RESET vector
20020 \end_inset 
20021 </cell>
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20023 \begin_inset Text
20024
20025 \layout Standard
20026
20027 0x000000
20028 \end_inset 
20029 </cell>
20030 </row>
20031 <row topline="true">
20032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20033 \begin_inset Text
20034
20035 \layout Standard
20036
20037
20038 \family roman 
20039 \series medium 
20040 \shape up 
20041 \size normal 
20042 \emph off 
20043 \bar no 
20044 \noun off 
20045 \color none
20046 1
20047 \end_inset 
20048 </cell>
20049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20050 \begin_inset Text
20051
20052 \layout Standard
20053
20054
20055 \family roman 
20056 \series medium 
20057 \shape up 
20058 \size normal 
20059 \emph off 
20060 \bar no 
20061 \noun off 
20062 \color none
20063 HIGH priority interrupts
20064 \end_inset 
20065 </cell>
20066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20067 \begin_inset Text
20068
20069 \layout Standard
20070
20071 0x000008
20072 \end_inset 
20073 </cell>
20074 </row>
20075 <row topline="true" bottomline="true">
20076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20077 \begin_inset Text
20078
20079 \layout Standard
20080
20081 2
20082 \end_inset 
20083 </cell>
20084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20085 \begin_inset Text
20086
20087 \layout Standard
20088
20089 LOW priority interrupts
20090 \end_inset 
20091 </cell>
20092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20093 \begin_inset Text
20094
20095 \layout Standard
20096
20097 0x000018
20098 \end_inset 
20099 </cell>
20100 </row>
20101 </lyxtabular>
20102
20103 \end_inset 
20104
20105
20106 \layout Standard
20107
20108 When generating assembly code for ISR the code generator places a 
20109 \noun on 
20110 goto 
20111 \noun default 
20112 instruction at the 
20113 \emph on 
20114 Interrupt Vector Address
20115 \emph default 
20116  which points at the genetated ISR.
20117  This single GOTO instruction is part of an automatically generated 
20118 \emph on 
20119 interrupt entry point
20120 \emph default 
20121  function.
20122  The actuall ISR code is placed as normally would in the code space.
20123  Upon interrupt request, the GOTO instruction is executed which jumps to
20124  the ISR code.
20125  When declaring interrupt functions as _naked this GOTO instruction is 
20126 \series bold 
20127 not
20128 \series default 
20129  generated.
20130  The whole interrupt functions is therefore placed at the Interrupt Vector
20131  Address of the specific interrupt.
20132  This is not a problem for the LOW priority interrupts, but it is a problem
20133  for the RESET and the HIGH priority interrupts because code may be written
20134  at the next interrupt´s vector address and cause undeterminate program
20135  behaviour if that interrupt is raised.
20136 \begin_inset Foot
20137 collapsed false
20138
20139 \layout Standard
20140
20141 This is not a problem when
20142 \layout Enumerate
20143
20144 this is a HIGH interrupt ISR and LOW interrupts are 
20145 \emph on 
20146 disabled
20147 \emph default 
20148  or not used.
20149 \layout Enumerate
20150
20151 when the ISR is small enough not to reach the next interrupt´s vector address.
20152 \end_inset 
20153
20154
20155 \layout Standard
20156
20157
20158 \emph on 
20159 n
20160 \emph default 
20161  is possible to be omitted.
20162  This way a function is generated similar to an ISR, but it is not assigned
20163  to any interrupt.
20164 \layout Standard
20165
20166 When entering an interrupt, currently the PIC16
20167 \begin_inset LatexCommand \index{PIC16}
20168
20169 \end_inset 
20170
20171  port automatically saves the following registers:
20172 \layout Itemize
20173
20174 WREG
20175 \layout Itemize
20176
20177 STATUS
20178 \layout Itemize
20179
20180 BSR
20181 \layout Itemize
20182
20183 PROD (PRODL and PRODH)
20184 \layout Itemize
20185
20186 FSR0 (FSR0L and FSR0H)
20187 \layout Standard
20188
20189 These registers are restored upon return from the interrupt routine.
20190 \begin_inset Foot
20191 collapsed false
20192
20193 \layout Standard
20194
20195 NOTE that when the _naked attribute is specified for an interrupt routine,
20196  then NO registers are stored or restored.
20197 \end_inset 
20198
20199
20200 \layout Subsection
20201
20202 Generic Pointers
20203 \layout Standard
20204
20205 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20206  There are 3 types of generic pointers currently implemented data, code
20207  and eeprom pointers.
20208  They are differentiated by the value of the 7th and 6th bits of the upper
20209  byte:
20210 \layout Standard
20211 \align center 
20212
20213 \begin_inset  Tabular
20214 <lyxtabular version="3" rows="5" columns="5">
20215 <features>
20216 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20217 <column alignment="center" valignment="top" width="0">
20218 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20219 <column alignment="center" valignment="top" width="0">
20220 <column alignment="left" valignment="top" rightline="true" width="0">
20221 <row topline="true" bottomline="true">
20222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20223 \begin_inset Text
20224
20225 \layout Standard
20226
20227 pointer type
20228 \end_inset 
20229 </cell>
20230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20231 \begin_inset Text
20232
20233 \layout Standard
20234
20235 7th bit
20236 \end_inset 
20237 </cell>
20238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20239 \begin_inset Text
20240
20241 \layout Standard
20242
20243 6th bit
20244 \end_inset 
20245 </cell>
20246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20247 \begin_inset Text
20248
20249 \layout Standard
20250
20251 rest of the pointer
20252 \end_inset 
20253 </cell>
20254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20255 \begin_inset Text
20256
20257 \layout Standard
20258
20259 description
20260 \end_inset 
20261 </cell>
20262 </row>
20263 <row topline="true" bottomline="true">
20264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20265 \begin_inset Text
20266
20267 \layout Standard
20268
20269 data 
20270 \end_inset 
20271 </cell>
20272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20273 \begin_inset Text
20274
20275 \layout Standard
20276
20277 1
20278 \end_inset 
20279 </cell>
20280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20281 \begin_inset Text
20282
20283 \layout Standard
20284
20285 0
20286 \end_inset 
20287 </cell>
20288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20289 \begin_inset Text
20290
20291 \layout Standard
20292
20293
20294 \family typewriter 
20295 \shape slanted 
20296 \emph on 
20297 uuuuuu uuuuxxxx xxxxxxxx
20298 \end_inset 
20299 </cell>
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20301 \begin_inset Text
20302
20303 \layout Standard
20304
20305 a 12-bit data pointer in data RAM memory
20306 \end_inset 
20307 </cell>
20308 </row>
20309 <row bottomline="true">
20310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20311 \begin_inset Text
20312
20313 \layout Standard
20314
20315 code
20316 \end_inset 
20317 </cell>
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 \begin_inset Text
20320
20321 \layout Standard
20322
20323 0
20324 \end_inset 
20325 </cell>
20326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20327 \begin_inset Text
20328
20329 \layout Standard
20330
20331 0
20332 \end_inset 
20333 </cell>
20334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20335 \begin_inset Text
20336
20337 \layout Standard
20338
20339
20340 \family typewriter 
20341 \shape slanted 
20342 \emph on 
20343 uxxxxx xxxxxxxx xxxxxxxx
20344 \end_inset 
20345 </cell>
20346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20347 \begin_inset Text
20348
20349 \layout Standard
20350
20351 a 21-bit code pointer in FLASH memory
20352 \end_inset 
20353 </cell>
20354 </row>
20355 <row bottomline="true">
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20357 \begin_inset Text
20358
20359 \layout Standard
20360
20361 eeprom
20362 \end_inset 
20363 </cell>
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20365 \begin_inset Text
20366
20367 \layout Standard
20368
20369 0
20370 \end_inset 
20371 </cell>
20372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20373 \begin_inset Text
20374
20375 \layout Standard
20376
20377 1
20378 \end_inset 
20379 </cell>
20380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20381 \begin_inset Text
20382
20383 \layout Standard
20384
20385
20386 \family typewriter 
20387 \shape slanted 
20388 \emph on 
20389 uuuuuu uuuuuuxx xxxxxxxx
20390 \end_inset 
20391 </cell>
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20393 \begin_inset Text
20394
20395 \layout Standard
20396
20397 a 10-bit eeprom pointer in EEPROM memory
20398 \end_inset 
20399 </cell>
20400 </row>
20401 <row bottomline="true">
20402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20403 \begin_inset Text
20404
20405 \layout Standard
20406
20407 (unimplemented)
20408 \end_inset 
20409 </cell>
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20411 \begin_inset Text
20412
20413 \layout Standard
20414
20415 1
20416 \end_inset 
20417 </cell>
20418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20419 \begin_inset Text
20420
20421 \layout Standard
20422
20423 1
20424 \end_inset 
20425 </cell>
20426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20427 \begin_inset Text
20428
20429 \layout Standard
20430
20431
20432 \family typewriter 
20433 \shape slanted 
20434 \emph on 
20435 xxxxxx xxxxxxxx xxxxxxxx
20436 \end_inset 
20437 </cell>
20438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20439 \begin_inset Text
20440
20441 \layout Standard
20442
20443 unimplemented pointer type
20444 \end_inset 
20445 </cell>
20446 </row>
20447 </lyxtabular>
20448
20449 \end_inset 
20450
20451
20452 \layout Standard
20453
20454 Generic pointer are read and written with a set of library functions which
20455  read/write 1, 2, 3, 4 bytes.
20456 \layout Subsection
20457
20458 PIC16 C Libraries
20459 \layout Subsubsection
20460
20461 Standard I/O Streams
20462 \layout Standard
20463
20464 In the 
20465 \emph on 
20466 stdio.h
20467 \emph default 
20468  the type FILE is defined as:
20469 \layout LyX-Code
20470
20471 typedef char * FILE;
20472 \layout Standard
20473
20474 This type is the stream type implemented I/O in the PIC18F devices.
20475  Also the standard input and output streams are declared in stdio.h:
20476 \layout LyX-Code
20477
20478 extern FILE * stdin;
20479 \layout LyX-Code
20480
20481 extern FILE * stdout;
20482 \layout Standard
20483
20484 The FILE type is actually a generic pointer which defines one more type
20485  of generic pointers, the 
20486 \emph on 
20487 stream 
20488 \emph default 
20489 pointer.
20490  This new type has the format:
20491 \layout Standard
20492 \align center 
20493
20494 \begin_inset  Tabular
20495 <lyxtabular version="3" rows="2" columns="7">
20496 <features>
20497 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20498 <column alignment="center" valignment="top" width="0">
20499 <column alignment="center" valignment="top" leftline="true" width="0">
20500 <column alignment="center" valignment="top" leftline="true" width="0">
20501 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20502 <column alignment="center" valignment="top" width="0">
20503 <column alignment="left" valignment="top" rightline="true" width="0">
20504 <row topline="true" bottomline="true">
20505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20506 \begin_inset Text
20507
20508 \layout Standard
20509
20510 pointer type
20511 \end_inset 
20512 </cell>
20513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20514 \begin_inset Text
20515
20516 \layout Standard
20517
20518 <7:6>
20519 \end_inset 
20520 </cell>
20521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20522 \begin_inset Text
20523
20524 \layout Standard
20525
20526 <5>
20527 \end_inset 
20528 </cell>
20529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20530 \begin_inset Text
20531
20532 \layout Standard
20533
20534 <4>
20535 \end_inset 
20536 </cell>
20537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20538 \begin_inset Text
20539
20540 \layout Standard
20541
20542 <3:0>
20543 \end_inset 
20544 </cell>
20545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20546 \begin_inset Text
20547
20548 \layout Standard
20549
20550 rest of the pointer
20551 \end_inset 
20552 </cell>
20553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20554 \begin_inset Text
20555
20556 \layout Standard
20557
20558 descrption
20559 \end_inset 
20560 </cell>
20561 </row>
20562 <row topline="true" bottomline="true">
20563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20564 \begin_inset Text
20565
20566 \layout Standard
20567
20568 stream
20569 \end_inset 
20570 </cell>
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20572 \begin_inset Text
20573
20574 \layout Standard
20575
20576 00
20577 \end_inset 
20578 </cell>
20579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20580 \begin_inset Text
20581
20582 \layout Standard
20583
20584 1
20585 \end_inset 
20586 </cell>
20587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20588 \begin_inset Text
20589
20590 \layout Standard
20591
20592 0
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 nnnn
20601 \end_inset 
20602 </cell>
20603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20604 \begin_inset Text
20605
20606 \layout Standard
20607
20608
20609 \family typewriter 
20610 \shape slanted 
20611 \emph on 
20612 uuuuuuuu uuuuuuuu
20613 \end_inset 
20614 </cell>
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20616 \begin_inset Text
20617
20618 \layout Standard
20619
20620 upper byte high nubble is 0x2n, the rest are zeroes
20621 \end_inset 
20622 </cell>
20623 </row>
20624 </lyxtabular>
20625
20626 \end_inset 
20627
20628
20629 \layout Standard
20630
20631 Currently implemented there are 3 types of streams defined:
20632 \layout Standard
20633 \align center 
20634
20635 \begin_inset  Tabular
20636 <lyxtabular version="3" rows="4" columns="4">
20637 <features>
20638 <column alignment="center" valignment="top" leftline="true" width="0">
20639 <column alignment="center" valignment="top" leftline="true" width="0">
20640 <column alignment="center" valignment="top" leftline="true" width="0">
20641 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20642 <row topline="true" bottomline="true">
20643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20644 \begin_inset Text
20645
20646 \layout Standard
20647
20648 stream type
20649 \end_inset 
20650 </cell>
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20652 \begin_inset Text
20653
20654 \layout Standard
20655
20656 value
20657 \end_inset 
20658 </cell>
20659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20660 \begin_inset Text
20661
20662 \layout Standard
20663
20664 module
20665 \end_inset 
20666 </cell>
20667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20668 \begin_inset Text
20669
20670 \layout Standard
20671
20672 description
20673 \end_inset 
20674 </cell>
20675 </row>
20676 <row topline="true">
20677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20678 \begin_inset Text
20679
20680 \layout Standard
20681
20682 STREAM_USART
20683 \end_inset 
20684 </cell>
20685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20686 \begin_inset Text
20687
20688 \layout Standard
20689
20690
20691 \family typewriter 
20692 0x200000UL
20693 \end_inset 
20694 </cell>
20695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20696 \begin_inset Text
20697
20698 \layout Standard
20699
20700 USART
20701 \end_inset 
20702 </cell>
20703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20704 \begin_inset Text
20705
20706 \layout Standard
20707
20708 Writes/Reads characters via the USART peripheral
20709 \end_inset 
20710 </cell>
20711 </row>
20712 <row topline="true">
20713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20714 \begin_inset Text
20715
20716 \layout Standard
20717
20718 STREAM_MSSP
20719 \end_inset 
20720 </cell>
20721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20722 \begin_inset Text
20723
20724 \layout Standard
20725
20726
20727 \family typewriter 
20728 0x210000UL
20729 \end_inset 
20730 </cell>
20731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20732 \begin_inset Text
20733
20734 \layout Standard
20735
20736 MSSP
20737 \end_inset 
20738 </cell>
20739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20740 \begin_inset Text
20741
20742 \layout Standard
20743
20744 Writes/Reads characters via the MSSP peripheral
20745 \end_inset 
20746 </cell>
20747 </row>
20748 <row topline="true" bottomline="true">
20749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20750 \begin_inset Text
20751
20752 \layout Standard
20753
20754 STREAM_USER
20755 \end_inset 
20756 </cell>
20757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20758 \begin_inset Text
20759
20760 \layout Standard
20761
20762
20763 \family typewriter 
20764 0x2f0000UL
20765 \end_inset 
20766 </cell>
20767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20768 \begin_inset Text
20769
20770 \layout Standard
20771
20772 (none)
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 Writes/Reads characters via used defined functions
20781 \end_inset 
20782 </cell>
20783 </row>
20784 </lyxtabular>
20785
20786 \end_inset 
20787
20788
20789 \layout Standard
20790
20791 The stream identifiers are declared as macros in the stdio.h header.
20792 \layout Standard
20793
20794 In the libc library there exist the functions that are used to write to
20795  each of the above streams.
20796  These are
20797 \layout List
20798 \labelwidthstring 00.00.0000
20799
20800 _
20801 \begin_inset ERT
20802 status Collapsed
20803
20804 \layout Standard
20805
20806 \backslash 
20807 /
20808 \end_inset 
20809
20810 _stream_usart_putchar writes a character at the USART stream
20811 \layout List
20812 \labelwidthstring 00.00.0000
20813
20814 _
20815 \begin_inset ERT
20816 status Collapsed
20817
20818 \layout Standard
20819
20820 \backslash 
20821 /
20822 \end_inset 
20823
20824 _stream_mssp_putchar writes a character at the MSSP stream
20825 \layout List
20826 \labelwidthstring 00.00.0000
20827
20828 putchar dummy function.
20829  This writes a character to a user specified manner.
20830 \layout Standard
20831
20832 In order to increase performance 
20833 \emph on 
20834 putchar 
20835 \emph default 
20836 is declared in stdio.h as having its parameter in WREG (it has the wparam
20837  keyword).
20838  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
20839  in a user-friendly way.
20840  
20841 \emph on 
20842 arg
20843 \emph default 
20844  is the name of the variable that holds the character to print.
20845  An example follows:
20846 \layout LyX-Code
20847
20848 #include <pic18fregs.h>
20849 \newline 
20850 #include <stdio.h>
20851 \newline 
20852
20853 \newline 
20854 PUTCHAR( c )
20855 \layout LyX-Code
20856
20857 {
20858 \layout LyX-Code
20859
20860     PORTA = c;    /* dump character c to PORTA */
20861 \layout LyX-Code
20862
20863
20864 \newline 
20865
20866 \newline 
20867 void main(void)
20868 \layout LyX-Code
20869
20870 {
20871 \layout LyX-Code
20872
20873     stdout = STREAM_USER;    /* this is not necessary, since stdout points
20874 \layout LyX-Code
20875
20876                               * by default to STREAM_USER */
20877 \layout LyX-Code
20878
20879     printf (¨This is a printf test
20880 \backslash 
20881 n¨);
20882 \layout LyX-Code
20883
20884 }
20885 \layout LyX-Code
20886
20887 \layout Subsubsection
20888
20889 Printing functions
20890 \layout Standard
20891
20892 PIC16 contains an implementation of the printf-family of functions.
20893  There exist the following functions:
20894 \layout LyX-Code
20895
20896 extern unsigned int sprintf(char *buf, char *fmt, ...);
20897 \layout LyX-Code
20898
20899 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
20900 \layout LyX-Code
20901
20902 \layout LyX-Code
20903
20904 extern unsigned int printf(char *fmt, ...);
20905 \layout LyX-Code
20906
20907 extern unsigned int vprintf(char *fmt, va_lista ap);
20908 \layout LyX-Code
20909
20910 \layout LyX-Code
20911
20912 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
20913 \layout LyX-Code
20914
20915 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
20916 \layout Standard
20917
20918 For sprintf and vsprintf 
20919 \emph on 
20920 buf 
20921 \emph default 
20922 should normally be a data pointer where the resulting string will be placed.
20923  No range checking is done so the user should allocate the necessery buffer.
20924  For fprintf and vfprintf 
20925 \emph on 
20926 fp
20927 \emph default 
20928  should be a stream pointer (i.e.
20929  stdout, STREAM_MSSP, etc...).
20930 \layout Subsubsection
20931
20932 Signals
20933 \layout Standard
20934
20935 The PIC18F family of microcontrollers supports a number of interrupt sources.
20936  A list of these interrupts is shown in the following table:
20937 \layout Standard
20938 \align center 
20939
20940 \begin_inset  Tabular
20941 <lyxtabular version="3" rows="11" columns="4">
20942 <features>
20943 <column alignment="left" valignment="top" leftline="true" width="0">
20944 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20945 <column alignment="left" valignment="top" leftline="true" width="0">
20946 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20947 <row topline="true" bottomline="true">
20948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20949 \begin_inset Text
20950
20951 \layout Standard
20952
20953 signal name
20954 \end_inset 
20955 </cell>
20956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20957 \begin_inset Text
20958
20959 \layout Standard
20960
20961 description
20962 \end_inset 
20963 </cell>
20964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20965 \begin_inset Text
20966
20967 \layout Standard
20968
20969 signal name
20970 \end_inset 
20971 </cell>
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20973 \begin_inset Text
20974
20975 \layout Standard
20976
20977 descritpion
20978 \end_inset 
20979 </cell>
20980 </row>
20981 <row topline="true">
20982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20983 \begin_inset Text
20984
20985 \layout Standard
20986
20987 SIG_RB
20988 \end_inset 
20989 </cell>
20990 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20991 \begin_inset Text
20992
20993 \layout Standard
20994
20995 PORTB change interrupt
20996 \end_inset 
20997 </cell>
20998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20999 \begin_inset Text
21000
21001 \layout Standard
21002
21003 SIG_EE
21004 \end_inset 
21005 </cell>
21006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21007 \begin_inset Text
21008
21009 \layout Standard
21010
21011 EEPROM/FLASH write complete interrupt
21012 \end_inset 
21013 </cell>
21014 </row>
21015 <row topline="true">
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21017 \begin_inset Text
21018
21019 \layout Standard
21020
21021 SIG_INT0
21022 \end_inset 
21023 </cell>
21024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21025 \begin_inset Text
21026
21027 \layout Standard
21028
21029 INT0 external interrupt
21030 \end_inset 
21031 </cell>
21032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21033 \begin_inset Text
21034
21035 \layout Standard
21036
21037 SIG_BCOL
21038 \end_inset 
21039 </cell>
21040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21041 \begin_inset Text
21042
21043 \layout Standard
21044
21045 Bus collision interrupt
21046 \end_inset 
21047 </cell>
21048 </row>
21049 <row topline="true">
21050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21051 \begin_inset Text
21052
21053 \layout Standard
21054
21055 SIG_INT1
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 INT1 external interrupt
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 SIG_LVD
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 Low voltage detect interrupt
21080 \end_inset 
21081 </cell>
21082 </row>
21083 <row topline="true">
21084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21085 \begin_inset Text
21086
21087 \layout Standard
21088
21089 SIG_INT2
21090 \end_inset 
21091 </cell>
21092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21093 \begin_inset Text
21094
21095 \layout Standard
21096
21097 INT2 external interrupt
21098 \end_inset 
21099 </cell>
21100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21101 \begin_inset Text
21102
21103 \layout Standard
21104
21105 SIG_PSP
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 Parallel slave port interrupt
21114 \end_inset 
21115 </cell>
21116 </row>
21117 <row topline="true">
21118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21119 \begin_inset Text
21120
21121 \layout Standard
21122
21123 SIG_CCP1
21124 \end_inset 
21125 </cell>
21126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21127 \begin_inset Text
21128
21129 \layout Standard
21130
21131 CCP1 module interrupt
21132 \end_inset 
21133 </cell>
21134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21135 \begin_inset Text
21136
21137 \layout Standard
21138
21139 SIG_AD
21140 \end_inset 
21141 </cell>
21142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21143 \begin_inset Text
21144
21145 \layout Standard
21146
21147 AD convertion complete interrupt
21148 \end_inset 
21149 </cell>
21150 </row>
21151 <row topline="true">
21152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21153 \begin_inset Text
21154
21155 \layout Standard
21156
21157 SIG_CCP2
21158 \end_inset 
21159 </cell>
21160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21161 \begin_inset Text
21162
21163 \layout Standard
21164
21165 CCP2 module interrupt
21166 \end_inset 
21167 </cell>
21168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21169 \begin_inset Text
21170
21171 \layout Standard
21172
21173 SIG_RC
21174 \end_inset 
21175 </cell>
21176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21177 \begin_inset Text
21178
21179 \layout Standard
21180
21181 USART receive interrupt
21182 \end_inset 
21183 </cell>
21184 </row>
21185 <row topline="true">
21186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21187 \begin_inset Text
21188
21189 \layout Standard
21190
21191 SIG_TMR0
21192 \end_inset 
21193 </cell>
21194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21195 \begin_inset Text
21196
21197 \layout Standard
21198
21199 TMR0 overflow interrupt
21200 \end_inset 
21201 </cell>
21202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21203 \begin_inset Text
21204
21205 \layout Standard
21206
21207 SIG_TX
21208 \end_inset 
21209 </cell>
21210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21211 \begin_inset Text
21212
21213 \layout Standard
21214
21215 USART transmit interrupt
21216 \end_inset 
21217 </cell>
21218 </row>
21219 <row topline="true">
21220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21221 \begin_inset Text
21222
21223 \layout Standard
21224
21225 SIG_TMR1
21226 \end_inset 
21227 </cell>
21228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21229 \begin_inset Text
21230
21231 \layout Standard
21232
21233 TMR1 overflow interrupt
21234 \end_inset 
21235 </cell>
21236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21237 \begin_inset Text
21238
21239 \layout Standard
21240
21241 SIG_MSSP
21242 \end_inset 
21243 </cell>
21244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21245 \begin_inset Text
21246
21247 \layout Standard
21248
21249 SSP receive/transmit interrupt
21250 \end_inset 
21251 </cell>
21252 </row>
21253 <row topline="true">
21254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21255 \begin_inset Text
21256
21257 \layout Standard
21258
21259 SIG_TMR2
21260 \end_inset 
21261 </cell>
21262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21263 \begin_inset Text
21264
21265 \layout Standard
21266
21267 TMR2 matches PR2 interrupt
21268 \end_inset 
21269 </cell>
21270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21271 \begin_inset Text
21272
21273 \layout Standard
21274
21275 \end_inset 
21276 </cell>
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21278 \begin_inset Text
21279
21280 \layout Standard
21281
21282 \end_inset 
21283 </cell>
21284 </row>
21285 <row topline="true" bottomline="true">
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21287 \begin_inset Text
21288
21289 \layout Standard
21290
21291 SIG_TMR3
21292 \end_inset 
21293 </cell>
21294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21295 \begin_inset Text
21296
21297 \layout Standard
21298
21299 TMR3 overflow interrupt
21300 \end_inset 
21301 </cell>
21302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21303 \begin_inset Text
21304
21305 \layout Standard
21306
21307 \end_inset 
21308 </cell>
21309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21310 \begin_inset Text
21311
21312 \layout Standard
21313
21314 \end_inset 
21315 </cell>
21316 </row>
21317 </lyxtabular>
21318
21319 \end_inset 
21320
21321
21322 \layout Standard
21323
21324 The prototypes for these names are defined in the header file 
21325 \emph on 
21326 signal.h
21327 \emph default 
21328  .
21329 \layout Standard
21330
21331 In order to simplify signal handling, a number of macros is provided:
21332 \layout List
21333 \labelwidthstring 00.00.0000
21334
21335 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21336  high priority interrupts.
21337  
21338 \emph on 
21339 name
21340 \emph default 
21341  is the function name to use.
21342 \layout List
21343 \labelwidthstring 00.00.0000
21344
21345 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21346  low priority interrupt.
21347  
21348 \emph on 
21349 name
21350 \emph default 
21351  is the function name to use.
21352 \layout List
21353 \labelwidthstring 00.00.0000
21354
21355 DEF_HANDLER(sig,handler) define a handler for signal 
21356 \emph on 
21357 sig.
21358 \layout List
21359 \labelwidthstring 00.00.0000
21360
21361 END_DEF end the declaration of the dispatch table.
21362 \layout Standard
21363
21364 Additionally there are two more macros to simplify the declaration of the
21365  signal handler:
21366 \layout List
21367 \labelwidthstring 00.00.0000
21368
21369
21370 \series medium 
21371 SIGHANDLER(handler) 
21372 \series default 
21373 this declares the function prototype for the 
21374 \emph on 
21375 handler
21376 \emph default 
21377  function.
21378 \layout List
21379 \labelwidthstring 00.00.0000
21380
21381 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21382 \layout Standard
21383
21384 An example of using the macros above is shown below:
21385 \layout LyX-Code
21386
21387 #include <pic18fregs.h>
21388 \layout LyX-Code
21389
21390 #include <signal.h>
21391 \newline 
21392
21393 \newline 
21394 DEF_INTHIGH(high_int)
21395 \layout LyX-Code
21396
21397 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21398 \layout LyX-Code
21399
21400 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21401 \layout LyX-Code
21402
21403 END_DEF
21404 \newline 
21405
21406 \newline 
21407 SIGHANDLER(_tmr0_handler)
21408 \layout LyX-Code
21409
21410 {
21411 \layout LyX-Code
21412
21413   /* action to be taken when timer 0 overflows */
21414 \layout LyX-Code
21415
21416 }
21417 \newline 
21418
21419 \newline 
21420 SIGHANDLERNAKED(_bcol_handler)
21421 \layout LyX-Code
21422
21423 {
21424 \layout LyX-Code
21425
21426   _asm
21427 \layout LyX-Code
21428
21429     /* action to be taken when bus collision occurs */
21430 \layout LyX-Code
21431
21432     retfie
21433 \layout LyX-Code
21434
21435  _endasm;
21436 \layout LyX-Code
21437
21438 }
21439 \layout Standard
21440
21441
21442 \series bold 
21443 NOTES:
21444 \series default 
21445  Special care should be taken when using the above scheme:
21446 \layout Itemize
21447
21448 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21449 \layout Itemize
21450
21451 when declaring SIGHANDLERNAKED handler never forget to use 
21452 \emph on 
21453 retfie
21454 \emph default 
21455  for proper returning.
21456 \layout Subsection
21457
21458 PIC16 Port -- Tips
21459 \layout Standard
21460
21461 Here you can find some general tips for compiling programs with SDCC/pic16.
21462 \layout Subsubsection
21463
21464 Stack size
21465 \layout Standard
21466
21467 The default stack
21468 \begin_inset LatexCommand \index{PIC16!stack}
21469
21470 \end_inset 
21471
21472  size (that is 64 bytes) probably is enough for many programs.
21473  One must take care that when there are many levels of function nesting,
21474  or there is excessive usage of stack, its size should be extended.
21475  An example of such a case is the printf/sprintf family of functions.
21476  If you encounter problems like not being able to print integers, then you
21477  need to set the stack size around the maximum (256 for small stack model).
21478  The following diagram shows what happens when calling printf to print an
21479  integer:
21480 \layout LyX-Code
21481
21482 printf () --> ltoa () --> ultoa () --> divschar ()
21483 \layout Standard
21484
21485 It is should be understood that stack is easily consumed when calling complicate
21486 d functions.
21487  Using command line arguments like -
21488 \begin_inset ERT
21489 status Collapsed
21490
21491 \layout Standard
21492
21493 \backslash 
21494 /
21495 \end_inset 
21496
21497 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
21498  stack frames.
21499  Other ways to reduce stack usage may exist.
21500 \layout Chapter
21501
21502 Debugging
21503 \layout Standard
21504
21505 There are several approaches to debugging your code.
21506  This chapter is meant to show your options and to give detail on some of
21507  them:
21508 \newline 
21509
21510 \newline 
21511 When writing your code:
21512 \layout Itemize
21513
21514 write your code with debugging in mind (avoid duplicating code, put conceptually
21515  similar variables into structs, use structured code, have strategic points
21516  within your code where all variables are consistent, ...)
21517 \layout Itemize
21518
21519 run a syntax-checking tool like splint
21520 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21521
21522 \end_inset 
21523
21524
21525 \begin_inset LatexCommand \index{lint (syntax checking tool)}
21526
21527 \end_inset 
21528
21529  (see -
21530 \begin_inset ERT
21531 status Collapsed
21532
21533 \layout Standard
21534
21535 \backslash 
21536 /
21537 \end_inset 
21538
21539 -more-pedantic 
21540 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21541
21542 \end_inset 
21543
21544 ) over the code.
21545 \layout Itemize
21546
21547 for the high level code use a C-compiler (like f.e.
21548  GCC) to compile run and debug the code on your host.
21549  See (see -
21550 \begin_inset ERT
21551 status Collapsed
21552
21553 \layout Standard
21554
21555 \backslash 
21556 /
21557 \end_inset 
21558
21559 -more-pedantic 
21560 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21561
21562 \end_inset 
21563
21564  ) on howto handle syntax extensions like __xdata, __at(), ...
21565  
21566 \layout Itemize
21567
21568 use another C-compiler to compile code for your target.
21569  Always an option but not recommended:) And not very likely to help you.
21570  If you seriously consider walking this path you should at least occasionally
21571  check portability of your code.
21572  Most commercial compiler vendors will offer an evaluation version so you
21573  can test compile your code or snippets of your code.
21574 \layout Standard
21575
21576 Debugging on a simulator:
21577 \layout Itemize
21578
21579 there is a separate section about SDCDB (section 
21580 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
21581
21582 \end_inset 
21583
21584 ) below.
21585 \layout Itemize
21586
21587 or (8051 specific) use a freeware/commercial simulator which interfaces
21588  to the AOMF
21589 \begin_inset LatexCommand \index{AOMF, AOMF51}
21590
21591 \end_inset 
21592
21593  file (see 
21594 \begin_inset LatexCommand \ref{OMF file}
21595
21596 \end_inset 
21597
21598 ) optionally generated by SDCC.
21599 \layout Standard
21600
21601 Debugging On-target: 
21602 \layout Itemize
21603
21604 use a MCU port pin to serially output debug data to the RS232 port of your
21605  host.
21606  You'll probably want some level shifting device typically involving a MAX232
21607  or similar IC.
21608  If the hardware serial port of the MCU is not available search for 'Software
21609  UART' in your favourite search machine.
21610 \layout Itemize
21611
21612 use an on-target monitor.
21613  In this context a monitor is a small program which usually accepts commands
21614  via a serial line and allows to set program counter, to single step through
21615  a program and read/write memory locations.
21616  For the 8051 good examples of monitors are paulmon and cmon51 (see section
21617  
21618 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
21619
21620 \end_inset 
21621
21622 ).
21623 \layout Itemize
21624
21625 toggle MCU port pins at strategic points within your code and use an oscilloscop
21626 e.
21627  A 
21628 \emph on 
21629 digital oscilloscope
21630 \emph default 
21631
21632 \begin_inset LatexCommand \index{Oscilloscope}
21633
21634 \end_inset 
21635
21636  with deep trace memory is really helpful especially if you have to debug
21637  a realtime application.
21638  If you need to monitor more pins than your oscilloscope provides you can
21639  sometimes get away with a small R-2R network.
21640  On a single channel oscilloscope you could f.e.
21641  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
21642 k
21643 \begin_inset Formula $\Omega$
21644 \end_inset 
21645
21646  resistor and the other one by a 5\SpecialChar ~
21647 k
21648 \begin_inset Formula $\Omega$
21649 \end_inset 
21650
21651  resistor to the oscilloscope probe (check output drive capability of the
21652  pins you want to monitor).
21653  If you need to monitor many more pins a 
21654 \emph on 
21655 logic analyzer
21656 \emph default 
21657  will be handy.
21658 \layout Itemize
21659
21660 use an ICE (
21661 \emph on 
21662 i
21663 \emph default 
21664
21665 \emph on 
21666 c
21667 \emph default 
21668 ircuit 
21669 \emph on 
21670 e
21671 \emph default 
21672 mulator
21673 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
21674
21675 \end_inset 
21676
21677 ).
21678  Usually very expensive.
21679  And very nice to have too.
21680  And usually locks you (for years...) to the devices the ICE can emulate.
21681  
21682 \layout Itemize
21683
21684 use a remote debugger.
21685  In most 8-bit systems the symbol information is not available on the target,
21686  and a complete debugger is too bulky for the target system.
21687  Therefore usually a debugger on the host system connects to an on-target
21688  debugging stub which accepts only primitive commands.
21689  
21690 \newline 
21691 Terms to enter into your favourite search engine could be 'remote debugging',
21692  'gdb stub' or 'inferior debugger'.
21693  (is there one?)
21694 \layout Itemize
21695
21696 use an on target hardware debugger.
21697  Some of the more modern MCUs include hardware support for setting break
21698  points and monitoring/changing variables by using dedicated hardware pins.
21699  This facility doesn't require additional code to run on the target and
21700  
21701 \emph on 
21702 usually
21703 \emph default 
21704  doesn't affect runtime behaviour until a breakpoint is hit.
21705  For the mcs51 most hardware debuggers use the AOMF
21706 \begin_inset LatexCommand \index{AOMF, AOMF51}
21707
21708 \end_inset 
21709
21710  file (see 
21711 \begin_inset LatexCommand \ref{OMF file}
21712
21713 \end_inset 
21714
21715 ) as input file.
21716  
21717 \layout Standard
21718
21719 Last not least:
21720 \layout Itemize
21721
21722 if you are not familiar with any of the following terms you're likely to
21723  run into problems rather sooner than later: 
21724 \emph on 
21725 volatile
21726 \emph default 
21727
21728 \emph on 
21729 atomic
21730 \emph default 
21731
21732 \emph on 
21733 memory map
21734 \emph default 
21735
21736 \emph on 
21737 overlay
21738 \emph default 
21739 .
21740  As an embedded programmer you 
21741 \emph on 
21742 have
21743 \emph default 
21744  to know them so why not look them up 
21745 \emph on 
21746 before
21747 \emph default 
21748  you have problems?)
21749 \layout Itemize
21750
21751 tell someone else about your problem (actually this is a surprisingly effective
21752  means to hunt down the bug even if the listener is not familiar with your
21753  environment).
21754  As 'failure to communicate' is probably one of the job-induced deformations
21755  of an embedded programmer this is highly encouraged.
21756 \layout Section
21757
21758 Debugging with SDCDB
21759 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
21760
21761 \end_inset 
21762
21763
21764 \begin_inset LatexCommand \index{SDCDB (debugger)}
21765
21766 \end_inset 
21767
21768  
21769 \layout Standard
21770
21771 SDCC is distributed with a source level debugger
21772 \begin_inset LatexCommand \index{Debugger}
21773
21774 \end_inset 
21775
21776 .
21777  The debugger uses a command line interface, the command repertoire of the
21778  debugger has been kept as close to gdb
21779 \begin_inset LatexCommand \index{gdb}
21780
21781 \end_inset 
21782
21783  (the GNU debugger) as possible.
21784  The configuration and build process is part of the standard compiler installati
21785 on, which also builds and installs the debugger in the target directory
21786  specified during configuration.
21787  The debugger allows you debug BOTH at the C source and at the ASM source
21788  level.
21789 \layout Subsection
21790
21791 Compiling for Debugging
21792 \layout Standard
21793
21794 The -
21795 \begin_inset ERT
21796 status Collapsed
21797
21798 \layout Standard
21799
21800 \backslash 
21801 /
21802 \end_inset 
21803
21804 -debug
21805 \begin_inset LatexCommand \index{-\/-debug}
21806
21807 \end_inset 
21808
21809  option must be specified for all files for which debug information is to
21810  be generated.
21811  The compiler generates a .adb file for each of these files.
21812  The linker creates the .cdb
21813 \begin_inset LatexCommand \index{<file>.cdb}
21814
21815 \end_inset 
21816
21817  file from the .adb
21818 \begin_inset LatexCommand \index{<file>.adb}
21819
21820 \end_inset 
21821
21822  files and the address information.
21823  This .cdb is used by the debugger.
21824 \layout Subsection
21825
21826 How the Debugger Works
21827 \layout Standard
21828
21829 When the -
21830 \begin_inset ERT
21831 status Collapsed
21832
21833 \layout Standard
21834
21835 \backslash 
21836 /
21837 \end_inset 
21838
21839 -debug option is specified the compiler generates extra symbol information
21840  some of which are put into the assembler source and some are put into the
21841  .adb file.
21842  Then the linker creates the .cdb file from the individual .adb files with
21843  the address information for the symbols.
21844  The debugger reads the symbolic information generated by the compiler &
21845  the address information generated by the linker.
21846  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
21847  execution is controlled by the debugger.
21848  When a command is issued for the debugger, it translates it into appropriate
21849  commands for the simulator.
21850  (Currently SDCDM only connects to the simulator but 
21851 \emph on 
21852 newcdb
21853 \emph default 
21854  at 
21855 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
21856
21857 \end_inset 
21858
21859  is an effort to connect directly to the hardware.) 
21860 \layout Subsection
21861
21862 Starting the Debugger SDCDB
21863 \layout Standard
21864
21865 The debugger can be started using the following command line.
21866  (Assume the file you are debugging has the file name foo).
21867 \newline 
21868
21869 \newline 
21870
21871 \family sans 
21872 \series bold 
21873 sdcdb foo
21874 \newline 
21875
21876 \family default 
21877 \series default 
21878
21879 \newline 
21880 The debugger will look for the following files.
21881 \layout Itemize
21882
21883 foo.c - the source file.
21884 \layout Itemize
21885
21886 foo.cdb - the debugger symbol information file.
21887 \layout Itemize
21888
21889 foo.ihx - the Intel hex format
21890 \begin_inset LatexCommand \index{Intel hex format}
21891
21892 \end_inset 
21893
21894  object file.
21895 \layout Subsection
21896
21897 SDCDB Command Line Options
21898 \layout Itemize
21899
21900 -
21901 \begin_inset ERT
21902 status Collapsed
21903
21904 \layout Standard
21905
21906 \backslash 
21907 /
21908 \end_inset 
21909
21910 -directory=<source file directory> this option can used to specify the directory
21911  search list.
21912  The debugger will look into the directory list specified for source, cdb
21913  & ihx files.
21914  The items in the directory list must be separated by ':', e.g.
21915  if the source files can be in the directories /home/src1 and /home/src2,
21916  the -
21917 \begin_inset ERT
21918 status Collapsed
21919
21920 \layout Standard
21921
21922 \backslash 
21923 /
21924 \end_inset 
21925
21926 -directory option should be -
21927 \begin_inset ERT
21928 status Collapsed
21929
21930 \layout Standard
21931
21932 \backslash 
21933 /
21934 \end_inset 
21935
21936 -directory=/home/src1:/home/src2.
21937  Note there can be no spaces in the option.
21938  
21939 \layout Itemize
21940
21941 -cd <directory> - change to the <directory>.
21942 \layout Itemize
21943
21944 -fullname - used by GUI front ends.
21945 \layout Itemize
21946
21947 -cpu <cpu-type> - this argument is passed to the simulator please see the
21948  simulator docs for details.
21949 \layout Itemize
21950
21951 -X <Clock frequency > this options is passed to the simulator please see
21952  the simulator docs for details.
21953 \layout Itemize
21954
21955 -s <serial port file> passed to simulator see the simulator docs for details.
21956 \layout Itemize
21957
21958 -S <serial in,out> passed to simulator see the simulator docs for details.
21959 \layout Itemize
21960
21961 -k <port number> passed to simulator see the simulator docs for details.
21962 \layout Subsection
21963
21964 SDCDB Debugger Commands
21965 \layout Standard
21966
21967 As mentioned earlier the command interface for the debugger has been deliberatel
21968 y kept as close the GNU debugger gdb, as possible.
21969  This will help the integration with existing graphical user interfaces
21970  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
21971  If you use a graphical user interface for the debugger you can skip this
21972  section.
21973 \layout Subsubsection*
21974
21975 break [line | file:line | function | file:function]
21976 \layout Standard
21977
21978 Set breakpoint at specified line or function:
21979 \newline 
21980
21981 \newline 
21982
21983 \family sans 
21984 \series bold 
21985 sdcdb>break 100 
21986 \newline 
21987 sdcdb>break foo.c:100
21988 \newline 
21989 sdcdb>break funcfoo
21990 \newline 
21991 sdcdb>break foo.c:funcfoo
21992 \layout Subsubsection*
21993
21994 clear [line | file:line | function | file:function ]
21995 \layout Standard
21996
21997 Clear breakpoint at specified line or function:
21998 \newline 
21999
22000 \newline 
22001
22002 \family sans 
22003 \series bold 
22004 sdcdb>clear 100
22005 \newline 
22006 sdcdb>clear foo.c:100
22007 \newline 
22008 sdcdb>clear funcfoo
22009 \newline 
22010 sdcdb>clear foo.c:funcfoo
22011 \layout Subsubsection*
22012
22013 continue
22014 \layout Standard
22015
22016 Continue program being debugged, after breakpoint.
22017 \layout Subsubsection*
22018
22019 finish
22020 \layout Standard
22021
22022 Execute till the end of the current function.
22023 \layout Subsubsection*
22024
22025 delete [n]
22026 \layout Standard
22027
22028 Delete breakpoint number 'n'.
22029  If used without any option clear ALL user defined break points.
22030 \layout Subsubsection*
22031
22032 info [break | stack | frame | registers ]
22033 \layout Itemize
22034
22035 info break - list all breakpoints
22036 \layout Itemize
22037
22038 info stack - show the function call stack.
22039 \layout Itemize
22040
22041 info frame - show information about the current execution frame.
22042 \layout Itemize
22043
22044 info registers - show content of all registers.
22045 \layout Subsubsection*
22046
22047 step
22048 \layout Standard
22049
22050 Step program until it reaches a different source line.
22051  Note: pressing <return> repeats the last command.
22052 \layout Subsubsection*
22053
22054 next
22055 \layout Standard
22056
22057 Step program, proceeding through subroutine calls.
22058 \layout Subsubsection*
22059
22060 run
22061 \layout Standard
22062
22063 Start debugged program.
22064 \layout Subsubsection*
22065
22066 ptype variable 
22067 \layout Standard
22068
22069 Print type information of the variable.
22070 \layout Subsubsection*
22071
22072 print variable
22073 \layout Standard
22074
22075 print value of variable.
22076 \layout Subsubsection*
22077
22078 file filename
22079 \layout Standard
22080
22081 load the given file name.
22082  Note this is an alternate method of loading file for debugging.
22083 \layout Subsubsection*
22084
22085 frame
22086 \layout Standard
22087
22088 print information about current frame.
22089 \layout Subsubsection*
22090
22091 set srcmode
22092 \layout Standard
22093
22094 Toggle between C source & assembly source.
22095 \layout Subsubsection*
22096
22097 ! simulator command
22098 \layout Standard
22099
22100 Send the string following '!' to the simulator, the simulator response is
22101  displayed.
22102  Note the debugger does not interpret the command being sent to the simulator,
22103  so if a command like 'go' is sent the debugger can loose its execution
22104  context and may display incorrect values.
22105 \layout Subsubsection*
22106
22107 quit
22108 \layout Standard
22109
22110 "Watch me now.
22111  Iam going Down.
22112  My name is Bobby Brown"
22113 \layout Subsection
22114
22115 Interfacing SDCDB with DDD
22116 \layout Comment
22117
22118 The screenshot was converted from png to eps with: 
22119 \begin_inset Quotes sld
22120 \end_inset 
22121
22122 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22123 \begin_inset Quotes srd
22124 \end_inset 
22125
22126  which produces a pretty compact eps file which is free from compression
22127  artifacts.
22128 \layout Comment
22129
22130 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22131  as this broke the build system on Sourceforge (pdf-file was broken.
22132  pdflatex does not accept eps files).
22133 \layout Standard
22134
22135 The 
22136 \emph on 
22137 p
22138 \emph default 
22139 ortable 
22140 \emph on 
22141 n
22142 \emph default 
22143 etwork 
22144 \emph on 
22145 g
22146 \emph default 
22147 raphics File 
22148 \size footnotesize 
22149
22150 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22151
22152 \end_inset 
22153
22154
22155 \size default 
22156  shows a screenshot of a debugging session with DDD
22157 \begin_inset LatexCommand \index{DDD (debugger)}
22158
22159 \end_inset 
22160
22161  (Unix only) on a simulated 8032.
22162  The debugging session might not run as smoothly as the screenshot suggests.
22163  The debugger allows setting of breakpoints, displaying and changing variables,
22164  single stepping through C and assembler code.
22165  
22166 \newline 
22167 The source was compiled with 
22168 \family sans 
22169 \series bold 
22170
22171 \newline 
22172
22173 \newline 
22174 sdcc -
22175 \family default 
22176 \series default 
22177
22178 \begin_inset ERT
22179 status Collapsed
22180
22181 \layout Standard
22182
22183 \backslash 
22184 /
22185 \end_inset 
22186
22187
22188 \family sans 
22189 \series bold 
22190 -debug ddd_example.c
22191 \family default 
22192 \series default 
22193  
22194 \family sans 
22195 \series bold 
22196
22197 \newline 
22198
22199 \family default 
22200 \series default 
22201
22202 \newline 
22203 and DDD was invoked with 
22204 \family sans 
22205 \series bold 
22206
22207 \newline 
22208
22209 \newline 
22210 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22211 \layout Subsection
22212
22213 Interfacing SDCDB with XEmacs
22214 \begin_inset LatexCommand \index{XEmacs}
22215
22216 \end_inset 
22217
22218
22219 \begin_inset LatexCommand \index{Emacs}
22220
22221 \end_inset 
22222
22223
22224 \layout Standard
22225
22226 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22227  sdcdb.el and sdcdbsrc.el.
22228  These two files can be found in the $(prefix)/bin directory after the installat
22229 ion is complete.
22230  These files need to be loaded into XEmacs for the interface to work.
22231  This can be done at XEmacs startup time by inserting the following into
22232  your '.xemacs' file (which can be found in your HOME directory): 
22233 \newline 
22234
22235 \newline 
22236
22237 \family typewriter 
22238 (load-file sdcdbsrc.el) 
22239 \family default 
22240
22241 \newline 
22242
22243 \newline 
22244 .xemacs is a lisp file so the () around the command is REQUIRED.
22245  The files can also be loaded dynamically while XEmacs is running, set the
22246  environment variable 'EMACSLOADPATH' to the installation bin directory
22247  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22248  To start the interface enter the following command: 
22249 \newline 
22250
22251 \newline 
22252
22253 \family sans 
22254 \series bold 
22255 ESC-x sdcdbsrc
22256 \family default 
22257 \series default 
22258
22259 \newline 
22260
22261 \newline 
22262 You will prompted to enter the file name to be debugged.
22263  
22264 \newline 
22265
22266 \newline 
22267 The command line options that are passed to the simulator directly are bound
22268  to default values in the file sdcdbsrc.el.
22269  The variables are listed below, these values maybe changed as required.
22270 \layout Itemize
22271
22272 sdcdbsrc-cpu-type '51
22273 \layout Itemize
22274
22275 sdcdbsrc-frequency '11059200
22276 \layout Itemize
22277
22278 sdcdbsrc-serial nil
22279 \layout Standard
22280
22281 The following is a list of key mapping for the debugger interface.
22282 \layout Standard
22283
22284 \SpecialChar ~
22285
22286 \family typewriter 
22287
22288 \newline 
22289 ;;\SpecialChar ~
22290 Current Listing :: 
22291 \newline 
22292 ;;key\SpecialChar ~
22293 \SpecialChar ~
22294 \SpecialChar ~
22295 \SpecialChar ~
22296 \SpecialChar ~
22297 \SpecialChar ~
22298 \SpecialChar ~
22299 \SpecialChar ~
22300 \SpecialChar ~
22301 \SpecialChar ~
22302 \SpecialChar ~
22303 \SpecialChar ~
22304 \SpecialChar ~
22305 \SpecialChar ~
22306 binding\SpecialChar ~
22307 \SpecialChar ~
22308 \SpecialChar ~
22309 \SpecialChar ~
22310 \SpecialChar ~
22311 \SpecialChar ~
22312 \SpecialChar ~
22313 \SpecialChar ~
22314 \SpecialChar ~
22315 \SpecialChar ~
22316 \SpecialChar ~
22317 \SpecialChar ~
22318 \SpecialChar ~
22319 \SpecialChar ~
22320 \SpecialChar ~
22321 \SpecialChar ~
22322 \SpecialChar ~
22323 \SpecialChar ~
22324 \SpecialChar ~
22325 \SpecialChar ~
22326 \SpecialChar ~
22327 \SpecialChar ~
22328 Comment 
22329 \newline 
22330 ;;---\SpecialChar ~
22331 \SpecialChar ~
22332 \SpecialChar ~
22333 \SpecialChar ~
22334 \SpecialChar ~
22335 \SpecialChar ~
22336 \SpecialChar ~
22337 \SpecialChar ~
22338 \SpecialChar ~
22339 \SpecialChar ~
22340 \SpecialChar ~
22341 \SpecialChar ~
22342 \SpecialChar ~
22343 \SpecialChar ~
22344 -------\SpecialChar ~
22345 \SpecialChar ~
22346 \SpecialChar ~
22347 \SpecialChar ~
22348 \SpecialChar ~
22349 \SpecialChar ~
22350 \SpecialChar ~
22351 \SpecialChar ~
22352 \SpecialChar ~
22353 \SpecialChar ~
22354 \SpecialChar ~
22355 \SpecialChar ~
22356 \SpecialChar ~
22357 \SpecialChar ~
22358 \SpecialChar ~
22359 \SpecialChar ~
22360 \SpecialChar ~
22361 \SpecialChar ~
22362 \SpecialChar ~
22363 \SpecialChar ~
22364 \SpecialChar ~
22365 \SpecialChar ~
22366 -------
22367 \newline 
22368 ;; 
22369 \newline 
22370 ;;\SpecialChar ~
22371 n\SpecialChar ~
22372 \SpecialChar ~
22373 \SpecialChar ~
22374 \SpecialChar ~
22375 \SpecialChar ~
22376 \SpecialChar ~
22377 \SpecialChar ~
22378 \SpecialChar ~
22379 \SpecialChar ~
22380 \SpecialChar ~
22381 \SpecialChar ~
22382 \SpecialChar ~
22383 \SpecialChar ~
22384 \SpecialChar ~
22385 \SpecialChar ~
22386 sdcdb-next-from-src\SpecialChar ~
22387 \SpecialChar ~
22388 \SpecialChar ~
22389 \SpecialChar ~
22390 \SpecialChar ~
22391 \SpecialChar ~
22392 \SpecialChar ~
22393 \SpecialChar ~
22394 \SpecialChar ~
22395 \SpecialChar ~
22396 SDCDB next command 
22397 \newline 
22398 ;;\SpecialChar ~
22399 b\SpecialChar ~
22400 \SpecialChar ~
22401 \SpecialChar ~
22402 \SpecialChar ~
22403 \SpecialChar ~
22404 \SpecialChar ~
22405 \SpecialChar ~
22406 \SpecialChar ~
22407 \SpecialChar ~
22408 \SpecialChar ~
22409 \SpecialChar ~
22410 \SpecialChar ~
22411 \SpecialChar ~
22412 \SpecialChar ~
22413 \SpecialChar ~
22414 sdcdb-back-from-src\SpecialChar ~
22415 \SpecialChar ~
22416 \SpecialChar ~
22417 \SpecialChar ~
22418 \SpecialChar ~
22419 \SpecialChar ~
22420 \SpecialChar ~
22421 \SpecialChar ~
22422 \SpecialChar ~
22423 \SpecialChar ~
22424 SDCDB back command 
22425 \newline 
22426 ;;\SpecialChar ~
22427 c\SpecialChar ~
22428 \SpecialChar ~
22429 \SpecialChar ~
22430 \SpecialChar ~
22431 \SpecialChar ~
22432 \SpecialChar ~
22433 \SpecialChar ~
22434 \SpecialChar ~
22435 \SpecialChar ~
22436 \SpecialChar ~
22437 \SpecialChar ~
22438 \SpecialChar ~
22439 \SpecialChar ~
22440 \SpecialChar ~
22441 \SpecialChar ~
22442 sdcdb-cont-from-src\SpecialChar ~
22443 \SpecialChar ~
22444 \SpecialChar ~
22445 \SpecialChar ~
22446 \SpecialChar ~
22447 \SpecialChar ~
22448 \SpecialChar ~
22449 \SpecialChar ~
22450 \SpecialChar ~
22451 \SpecialChar ~
22452 SDCDB continue command
22453 \newline 
22454 ;;\SpecialChar ~
22455 s\SpecialChar ~
22456 \SpecialChar ~
22457 \SpecialChar ~
22458 \SpecialChar ~
22459 \SpecialChar ~
22460 \SpecialChar ~
22461 \SpecialChar ~
22462 \SpecialChar ~
22463 \SpecialChar ~
22464 \SpecialChar ~
22465 \SpecialChar ~
22466 \SpecialChar ~
22467 \SpecialChar ~
22468 \SpecialChar ~
22469 \SpecialChar ~
22470 sdcdb-step-from-src\SpecialChar ~
22471 \SpecialChar ~
22472 \SpecialChar ~
22473 \SpecialChar ~
22474 \SpecialChar ~
22475 \SpecialChar ~
22476 \SpecialChar ~
22477 \SpecialChar ~
22478 \SpecialChar ~
22479 \SpecialChar ~
22480 SDCDB step command 
22481 \newline 
22482 ;;\SpecialChar ~
22483 ?\SpecialChar ~
22484 \SpecialChar ~
22485 \SpecialChar ~
22486 \SpecialChar ~
22487 \SpecialChar ~
22488 \SpecialChar ~
22489 \SpecialChar ~
22490 \SpecialChar ~
22491 \SpecialChar ~
22492 \SpecialChar ~
22493 \SpecialChar ~
22494 \SpecialChar ~
22495 \SpecialChar ~
22496 \SpecialChar ~
22497 \SpecialChar ~
22498 sdcdb-whatis-c-sexp\SpecialChar ~
22499 \SpecialChar ~
22500 \SpecialChar ~
22501 \SpecialChar ~
22502 \SpecialChar ~
22503 \SpecialChar ~
22504 \SpecialChar ~
22505 \SpecialChar ~
22506 \SpecialChar ~
22507 \SpecialChar ~
22508 SDCDB ptypecommand for data at 
22509 \newline 
22510 ;;\SpecialChar ~
22511 \SpecialChar ~
22512 \SpecialChar ~
22513 \SpecialChar ~
22514 \SpecialChar ~
22515 \SpecialChar ~
22516 \SpecialChar ~
22517 \SpecialChar ~
22518 \SpecialChar ~
22519 \SpecialChar ~
22520 \SpecialChar ~
22521 \SpecialChar ~
22522 \SpecialChar ~
22523 \SpecialChar ~
22524 \SpecialChar ~
22525 \SpecialChar ~
22526 \SpecialChar ~
22527 \SpecialChar ~
22528 \SpecialChar ~
22529 \SpecialChar ~
22530 \SpecialChar ~
22531 \SpecialChar ~
22532 \SpecialChar ~
22533 \SpecialChar ~
22534 \SpecialChar ~
22535 \SpecialChar ~
22536 \SpecialChar ~
22537 \SpecialChar ~
22538 \SpecialChar ~
22539 \SpecialChar ~
22540 \SpecialChar ~
22541 \SpecialChar ~
22542 \SpecialChar ~
22543 \SpecialChar ~
22544 \SpecialChar ~
22545 \SpecialChar ~
22546 \SpecialChar ~
22547 \SpecialChar ~
22548 \SpecialChar ~
22549 \SpecialChar ~
22550 \SpecialChar ~
22551 \SpecialChar ~
22552 \SpecialChar ~
22553 \SpecialChar ~
22554 \SpecialChar ~
22555 \SpecialChar ~
22556 \SpecialChar ~
22557 buffer point 
22558 \newline 
22559 ;;\SpecialChar ~
22560 x\SpecialChar ~
22561 \SpecialChar ~
22562 \SpecialChar ~
22563 \SpecialChar ~
22564 \SpecialChar ~
22565 \SpecialChar ~
22566 \SpecialChar ~
22567 \SpecialChar ~
22568 \SpecialChar ~
22569 \SpecialChar ~
22570 \SpecialChar ~
22571 \SpecialChar ~
22572 \SpecialChar ~
22573 \SpecialChar ~
22574 \SpecialChar ~
22575 sdcdbsrc-delete\SpecialChar ~
22576 \SpecialChar ~
22577 \SpecialChar ~
22578 \SpecialChar ~
22579 \SpecialChar ~
22580 \SpecialChar ~
22581 \SpecialChar ~
22582 \SpecialChar ~
22583 \SpecialChar ~
22584 \SpecialChar ~
22585 \SpecialChar ~
22586 \SpecialChar ~
22587 \SpecialChar ~
22588 \SpecialChar ~
22589 SDCDB Delete all breakpoints if no arg 
22590 \newline 
22591 ;;\SpecialChar ~
22592 \SpecialChar ~
22593 \SpecialChar ~
22594 \SpecialChar ~
22595 \SpecialChar ~
22596 \SpecialChar ~
22597 \SpecialChar ~
22598 \SpecialChar ~
22599 \SpecialChar ~
22600 \SpecialChar ~
22601 \SpecialChar ~
22602 \SpecialChar ~
22603 \SpecialChar ~
22604 \SpecialChar ~
22605 \SpecialChar ~
22606 \SpecialChar ~
22607 \SpecialChar ~
22608 \SpecialChar ~
22609 \SpecialChar ~
22610 \SpecialChar ~
22611 \SpecialChar ~
22612 \SpecialChar ~
22613 \SpecialChar ~
22614 \SpecialChar ~
22615 \SpecialChar ~
22616 \SpecialChar ~
22617 \SpecialChar ~
22618 \SpecialChar ~
22619 \SpecialChar ~
22620 \SpecialChar ~
22621 \SpecialChar ~
22622 \SpecialChar ~
22623 \SpecialChar ~
22624 \SpecialChar ~
22625 \SpecialChar ~
22626 \SpecialChar ~
22627 \SpecialChar ~
22628 \SpecialChar ~
22629 \SpecialChar ~
22630 \SpecialChar ~
22631 \SpecialChar ~
22632 \SpecialChar ~
22633 \SpecialChar ~
22634 \SpecialChar ~
22635 \SpecialChar ~
22636 \SpecialChar ~
22637 \SpecialChar ~
22638 given or delete arg (C-u arg x) 
22639 \newline 
22640 ;;\SpecialChar ~
22641 m\SpecialChar ~
22642 \SpecialChar ~
22643 \SpecialChar ~
22644 \SpecialChar ~
22645 \SpecialChar ~
22646 \SpecialChar ~
22647 \SpecialChar ~
22648 \SpecialChar ~
22649 \SpecialChar ~
22650 \SpecialChar ~
22651 \SpecialChar ~
22652 \SpecialChar ~
22653 \SpecialChar ~
22654 \SpecialChar ~
22655 \SpecialChar ~
22656 sdcdbsrc-frame\SpecialChar ~
22657 \SpecialChar ~
22658 \SpecialChar ~
22659 \SpecialChar ~
22660 \SpecialChar ~
22661 \SpecialChar ~
22662 \SpecialChar ~
22663 \SpecialChar ~
22664 \SpecialChar ~
22665 \SpecialChar ~
22666 \SpecialChar ~
22667 \SpecialChar ~
22668 \SpecialChar ~
22669 \SpecialChar ~
22670 \SpecialChar ~
22671 SDCDB Display current frame if no arg, 
22672 \newline 
22673 ;;\SpecialChar ~
22674 \SpecialChar ~
22675 \SpecialChar ~
22676 \SpecialChar ~
22677 \SpecialChar ~
22678 \SpecialChar ~
22679 \SpecialChar ~
22680 \SpecialChar ~
22681 \SpecialChar ~
22682 \SpecialChar ~
22683 \SpecialChar ~
22684 \SpecialChar ~
22685 \SpecialChar ~
22686 \SpecialChar ~
22687 \SpecialChar ~
22688 \SpecialChar ~
22689 \SpecialChar ~
22690 \SpecialChar ~
22691 \SpecialChar ~
22692 \SpecialChar ~
22693 \SpecialChar ~
22694 \SpecialChar ~
22695 \SpecialChar ~
22696 \SpecialChar ~
22697 \SpecialChar ~
22698 \SpecialChar ~
22699 \SpecialChar ~
22700 \SpecialChar ~
22701 \SpecialChar ~
22702 \SpecialChar ~
22703 \SpecialChar ~
22704 \SpecialChar ~
22705 \SpecialChar ~
22706 \SpecialChar ~
22707 \SpecialChar ~
22708 \SpecialChar ~
22709 \SpecialChar ~
22710 \SpecialChar ~
22711 \SpecialChar ~
22712 \SpecialChar ~
22713 \SpecialChar ~
22714 \SpecialChar ~
22715 \SpecialChar ~
22716 \SpecialChar ~
22717 \SpecialChar ~
22718 \SpecialChar ~
22719 \SpecialChar ~
22720 given or display frame arg 
22721 \newline 
22722 ;;\SpecialChar ~
22723 \SpecialChar ~
22724 \SpecialChar ~
22725 \SpecialChar ~
22726 \SpecialChar ~
22727 \SpecialChar ~
22728 \SpecialChar ~
22729 \SpecialChar ~
22730 \SpecialChar ~
22731 \SpecialChar ~
22732 \SpecialChar ~
22733 \SpecialChar ~
22734 \SpecialChar ~
22735 \SpecialChar ~
22736 \SpecialChar ~
22737 \SpecialChar ~
22738 \SpecialChar ~
22739 \SpecialChar ~
22740 \SpecialChar ~
22741 \SpecialChar ~
22742 \SpecialChar ~
22743 \SpecialChar ~
22744 \SpecialChar ~
22745 \SpecialChar ~
22746 \SpecialChar ~
22747 \SpecialChar ~
22748 \SpecialChar ~
22749 \SpecialChar ~
22750 \SpecialChar ~
22751 \SpecialChar ~
22752 \SpecialChar ~
22753 \SpecialChar ~
22754 \SpecialChar ~
22755 \SpecialChar ~
22756 \SpecialChar ~
22757 \SpecialChar ~
22758 \SpecialChar ~
22759 \SpecialChar ~
22760 \SpecialChar ~
22761 \SpecialChar ~
22762 \SpecialChar ~
22763 \SpecialChar ~
22764 \SpecialChar ~
22765 \SpecialChar ~
22766 \SpecialChar ~
22767 \SpecialChar ~
22768 \SpecialChar ~
22769 buffer point 
22770 \newline 
22771 ;;\SpecialChar ~
22772 !\SpecialChar ~
22773 \SpecialChar ~
22774 \SpecialChar ~
22775 \SpecialChar ~
22776 \SpecialChar ~
22777 \SpecialChar ~
22778 \SpecialChar ~
22779 \SpecialChar ~
22780 \SpecialChar ~
22781 \SpecialChar ~
22782 \SpecialChar ~
22783 \SpecialChar ~
22784 \SpecialChar ~
22785 \SpecialChar ~
22786 \SpecialChar ~
22787 sdcdbsrc-goto-sdcdb\SpecialChar ~
22788 \SpecialChar ~
22789 \SpecialChar ~
22790 \SpecialChar ~
22791 \SpecialChar ~
22792 \SpecialChar ~
22793 \SpecialChar ~
22794 \SpecialChar ~
22795 \SpecialChar ~
22796 \SpecialChar ~
22797 Goto the SDCDB output buffer 
22798 \newline 
22799 ;;\SpecialChar ~
22800 p\SpecialChar ~
22801 \SpecialChar ~
22802 \SpecialChar ~
22803 \SpecialChar ~
22804 \SpecialChar ~
22805 \SpecialChar ~
22806 \SpecialChar ~
22807 \SpecialChar ~
22808 \SpecialChar ~
22809 \SpecialChar ~
22810 \SpecialChar ~
22811 \SpecialChar ~
22812 \SpecialChar ~
22813 \SpecialChar ~
22814 \SpecialChar ~
22815 sdcdb-print-c-sexp\SpecialChar ~
22816 \SpecialChar ~
22817 \SpecialChar ~
22818 \SpecialChar ~
22819 \SpecialChar ~
22820 \SpecialChar ~
22821 \SpecialChar ~
22822 \SpecialChar ~
22823 \SpecialChar ~
22824 \SpecialChar ~
22825 \SpecialChar ~
22826 SDCDB print command for data at 
22827 \newline 
22828 ;;\SpecialChar ~
22829 \SpecialChar ~
22830 \SpecialChar ~
22831 \SpecialChar ~
22832 \SpecialChar ~
22833 \SpecialChar ~
22834 \SpecialChar ~
22835 \SpecialChar ~
22836 \SpecialChar ~
22837 \SpecialChar ~
22838 \SpecialChar ~
22839 \SpecialChar ~
22840 \SpecialChar ~
22841 \SpecialChar ~
22842 \SpecialChar ~
22843 \SpecialChar ~
22844 \SpecialChar ~
22845 \SpecialChar ~
22846 \SpecialChar ~
22847 \SpecialChar ~
22848 \SpecialChar ~
22849 \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 \SpecialChar ~
22864 \SpecialChar ~
22865 \SpecialChar ~
22866 \SpecialChar ~
22867 \SpecialChar ~
22868 \SpecialChar ~
22869 \SpecialChar ~
22870 \SpecialChar ~
22871 \SpecialChar ~
22872 \SpecialChar ~
22873 \SpecialChar ~
22874 \SpecialChar ~
22875 buffer point 
22876 \newline 
22877 ;;\SpecialChar ~
22878 g\SpecialChar ~
22879 \SpecialChar ~
22880 \SpecialChar ~
22881 \SpecialChar ~
22882 \SpecialChar ~
22883 \SpecialChar ~
22884 \SpecialChar ~
22885 \SpecialChar ~
22886 \SpecialChar ~
22887 \SpecialChar ~
22888 \SpecialChar ~
22889 \SpecialChar ~
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 \SpecialChar ~
22893 sdcdbsrc-goto-sdcdb\SpecialChar ~
22894 \SpecialChar ~
22895 \SpecialChar ~
22896 \SpecialChar ~
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 \SpecialChar ~
22900 \SpecialChar ~
22901 \SpecialChar ~
22902 \SpecialChar ~
22903 Goto the SDCDB output buffer 
22904 \newline 
22905 ;;\SpecialChar ~
22906 t\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 sdcdbsrc-mode\SpecialChar ~
22922 \SpecialChar ~
22923 \SpecialChar ~
22924 \SpecialChar ~
22925 \SpecialChar ~
22926 \SpecialChar ~
22927 \SpecialChar ~
22928 \SpecialChar ~
22929 \SpecialChar ~
22930 \SpecialChar ~
22931 \SpecialChar ~
22932 \SpecialChar ~
22933 \SpecialChar ~
22934 \SpecialChar ~
22935 \SpecialChar ~
22936 \SpecialChar ~
22937 Toggles Sdcdbsrc mode (turns it off) 
22938 \newline 
22939 ;; 
22940 \newline 
22941 ;;\SpecialChar ~
22942 C-c\SpecialChar ~
22943 C-f\SpecialChar ~
22944 \SpecialChar ~
22945 \SpecialChar ~
22946 \SpecialChar ~
22947 \SpecialChar ~
22948 \SpecialChar ~
22949 \SpecialChar ~
22950 \SpecialChar ~
22951 \SpecialChar ~
22952 sdcdb-finish-from-src\SpecialChar ~
22953 \SpecialChar ~
22954 \SpecialChar ~
22955 \SpecialChar ~
22956 \SpecialChar ~
22957 \SpecialChar ~
22958 \SpecialChar ~
22959 \SpecialChar ~
22960 SDCDB finish command 
22961 \newline 
22962 ;; 
22963 \newline 
22964 ;;\SpecialChar ~
22965 C-x\SpecialChar ~
22966 SPC\SpecialChar ~
22967 \SpecialChar ~
22968 \SpecialChar ~
22969 \SpecialChar ~
22970 \SpecialChar ~
22971 \SpecialChar ~
22972 \SpecialChar ~
22973 \SpecialChar ~
22974 \SpecialChar ~
22975 sdcdb-break\SpecialChar ~
22976 \SpecialChar ~
22977 \SpecialChar ~
22978 \SpecialChar ~
22979 \SpecialChar ~
22980 \SpecialChar ~
22981 \SpecialChar ~
22982 \SpecialChar ~
22983 \SpecialChar ~
22984 \SpecialChar ~
22985 \SpecialChar ~
22986 \SpecialChar ~
22987 \SpecialChar ~
22988 \SpecialChar ~
22989 \SpecialChar ~
22990 \SpecialChar ~
22991 \SpecialChar ~
22992 \SpecialChar ~
22993 Set break for line with point 
22994 \newline 
22995 ;;\SpecialChar ~
22996 ESC\SpecialChar ~
22997 t\SpecialChar ~
22998 \SpecialChar ~
22999 \SpecialChar ~
23000 \SpecialChar ~
23001 \SpecialChar ~
23002 \SpecialChar ~
23003 \SpecialChar ~
23004 \SpecialChar ~
23005 \SpecialChar ~
23006 \SpecialChar ~
23007 \SpecialChar ~
23008 sdcdbsrc-mode\SpecialChar ~
23009 \SpecialChar ~
23010 \SpecialChar ~
23011 \SpecialChar ~
23012 \SpecialChar ~
23013 \SpecialChar ~
23014 \SpecialChar ~
23015 \SpecialChar ~
23016 \SpecialChar ~
23017 \SpecialChar ~
23018 \SpecialChar ~
23019 \SpecialChar ~
23020 \SpecialChar ~
23021 \SpecialChar ~
23022 \SpecialChar ~
23023 \SpecialChar ~
23024 Toggle Sdcdbsrc mode 
23025 \newline 
23026 ;;\SpecialChar ~
23027 ESC\SpecialChar ~
23028 m\SpecialChar ~
23029 \SpecialChar ~
23030 \SpecialChar ~
23031 \SpecialChar ~
23032 \SpecialChar ~
23033 \SpecialChar ~
23034 \SpecialChar ~
23035 \SpecialChar ~
23036 \SpecialChar ~
23037 \SpecialChar ~
23038 \SpecialChar ~
23039 sdcdbsrc-srcmode\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 Toggle list mode 
23053 \newline 
23054 ;; 
23055 \newline 
23056
23057 \layout Chapter
23058 \pagebreak_top 
23059 TIPS
23060 \layout Standard
23061
23062 Here are a few guidelines that will help the compiler generate more efficient
23063  code, some of the tips are specific to this compiler others are generally
23064  good programming practice.
23065 \layout Itemize
23066
23067 Use the smallest data type to represent your data-value.
23068  If it is known in advance that the value is going to be less than 256 then
23069  use an 'unsigned char' instead of a 'short' or 'int'.
23070  Please note, that ANSI C requires both signed and unsigned chars to be
23071  promoted to 'signed int'
23072 \begin_inset LatexCommand \index{promotion to signed int}
23073
23074 \end_inset 
23075
23076
23077 \begin_inset Marginal
23078 collapsed true
23079
23080 \layout Standard
23081
23082
23083 \series bold 
23084 \SpecialChar ~
23085 !
23086 \end_inset 
23087
23088  before doing any operation.
23089  This promotion
23090 \begin_inset LatexCommand \index{type promotion}
23091
23092 \end_inset 
23093
23094
23095 \begin_inset LatexCommand \label{type promotion}
23096
23097 \end_inset 
23098
23099  can be omitted, if the result is the same.
23100  The effect of the promotion rules together with the sign-extension is often
23101  surprising:
23102 \begin_deeper 
23103 \layout Verse
23104
23105
23106 \family typewriter 
23107 unsigned char uc = 0xfe;
23108 \newline 
23109 if (uc * uc < 0) /* this is true! */
23110 \newline 
23111 {
23112 \newline 
23113 \SpecialChar ~
23114 \SpecialChar ~
23115 \SpecialChar ~
23116 \SpecialChar ~
23117 ....
23118 \newline 
23119 }
23120 \layout Standard
23121
23122
23123 \family typewriter 
23124 uc * uc
23125 \family default 
23126  is evaluated as 
23127 \family typewriter 
23128 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23129 \family default 
23130 .
23131  
23132 \newline 
23133 Another one:
23134 \layout Verse
23135
23136
23137 \family typewriter 
23138 (unsigned char) -12 / (signed char) -3 = ...
23139 \layout Standard
23140
23141 No, the result is not 4:
23142 \layout Verse
23143
23144
23145 \family typewriter 
23146 (int) (unsigned char) -12 / (int) (signed char) -3 =
23147 \newline 
23148 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23149 \newline 
23150 (int) 0x00f4 / (int) 0xfffd =
23151 \newline 
23152 (int) 0x00f4 / (int) 0xfffd =
23153 \newline 
23154 (int) 244 / (int) -3 =
23155 \newline 
23156 (int) -81 = (int) 0xffaf;
23157 \layout Standard
23158
23159 Don't complain, that gcc gives you a different result.
23160  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23161  Therefore the results are different.
23162 \newline 
23163 From 
23164 \begin_inset Quotes sld
23165 \end_inset 
23166
23167 comp.lang.c FAQ
23168 \begin_inset Quotes srd
23169 \end_inset 
23170
23171 :
23172 \layout Quote
23173
23174
23175 \emph on 
23176 If well-defined overflow characteristics are important and negative values
23177  are not, or if you want to steer clear of sign-extension problems when
23178  manipulating bits or bytes, use one of the corresponding unsigned types.
23179  (Beware when mixing signed and unsigned values in expressions, though.)
23180 \newline 
23181 Although character types (especially unsigned char) can be used as "tiny"
23182  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23183 ble sign extension and increased code size.
23184 \end_deeper 
23185 \layout Itemize
23186
23187 Use unsigned when it is known in advance that the value is not going to
23188  be negative.
23189  This helps especially if you are doing division or multiplication, bit-shifting
23190  or are using an array index.
23191 \layout Itemize
23192
23193 NEVER jump into a LOOP.
23194 \layout Itemize
23195
23196 Declare the variables to be local
23197 \begin_inset LatexCommand \index{local variables}
23198
23199 \end_inset 
23200
23201  whenever possible, especially loop control variables (induction).
23202 \layout Itemize
23203
23204 Since the compiler does not always do implicit integral promotion, the programme
23205 r should do an explicit cast when integral promotion is required.
23206 \layout Itemize
23207
23208 Reducing the size of division, multiplication & modulus operations can reduce
23209  code size substantially.
23210  Take the following code for example.
23211 \begin_deeper 
23212 \layout Verse
23213
23214
23215 \family typewriter 
23216 foobar(unsigned int p1, unsigned char ch)
23217 \newline 
23218 {
23219 \newline 
23220 \SpecialChar ~
23221 \SpecialChar ~
23222 \SpecialChar ~
23223 \SpecialChar ~
23224 unsigned char ch1 = p1 % ch ;
23225 \newline 
23226 \SpecialChar ~
23227 \SpecialChar ~
23228 \SpecialChar ~
23229 \SpecialChar ~
23230 ....
23231 \newline 
23232 }
23233 \layout Standard
23234
23235 For the modulus operation the variable ch will be promoted to unsigned int
23236  first then the modulus operation will be performed (this will lead to a
23237  call to support routine _moduint()), and the result will be casted to a
23238  char.
23239  If the code is changed to 
23240 \layout Verse
23241
23242
23243 \family typewriter 
23244 foobar(unsigned int p1, unsigned char ch)
23245 \newline 
23246 {
23247 \newline 
23248 \SpecialChar ~
23249 \SpecialChar ~
23250 \SpecialChar ~
23251 \SpecialChar ~
23252 unsigned char ch1 = (unsigned char)p1 % ch ;
23253 \newline 
23254 \SpecialChar ~
23255 \SpecialChar ~
23256 \SpecialChar ~
23257 \SpecialChar ~
23258 ....
23259 \newline 
23260 }
23261 \layout Standard
23262
23263 It would substantially reduce the code generated (future versions of the
23264  compiler will be smart enough to detect such optimization opportunities).
23265 \end_deeper 
23266 \layout Itemize
23267
23268 Have a look at the assembly listing to get a 
23269 \begin_inset Quotes sld
23270 \end_inset 
23271
23272 feeling
23273 \begin_inset Quotes srd
23274 \end_inset 
23275
23276  for the code generation.
23277 \layout Section
23278
23279 Porting code from or to other compilers
23280 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23281
23282 \end_inset 
23283
23284
23285 \layout Itemize
23286
23287 check whether endianness of the compilers differs and adapt where needed.
23288 \layout Itemize
23289
23290 check the device specific header files
23291 \begin_inset LatexCommand \index{Header files}
23292
23293 \end_inset 
23294
23295
23296 \begin_inset LatexCommand \index{Include files}
23297
23298 \end_inset 
23299
23300  for compiler specific syntax.
23301  Eventually include the file <compiler.h
23302 \begin_inset LatexCommand \index{compiler.h (include file)}
23303
23304 \end_inset 
23305
23306 > to allow using common header files.
23307  (see f.e.
23308  cc2510fx.h 
23309 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/P89c51RD2.h?view=markup}
23310
23311 \end_inset 
23312
23313 ).
23314 \layout Itemize
23315
23316 check whether the startup code contains the correct initialization (watchdog,
23317  peripherals).
23318 \layout Itemize
23319
23320 check whether the sizes of short, int, long match.
23321 \layout Itemize
23322
23323 check if some 16 or 32 bit hardware registers require a specific addressing
23324  order (least significant or most significant byte first) and adapt if needed
23325  (
23326 \emph on 
23327 first
23328 \emph default 
23329  and 
23330 \emph on 
23331 last
23332 \emph default 
23333  relate to time and not to lower/upper memory location here, so this is
23334  
23335 \emph on 
23336 not
23337 \emph default 
23338  the same as endianness).
23339 \layout Itemize
23340
23341 check whether the keyword 
23342 \emph on 
23343 volatile
23344 \emph default 
23345  is used where needed.
23346  The compilers might differ in their optimization characteristics (as different
23347  versions of the same compiler might also use more clever optimizations
23348  this is good idea anyway).
23349 \layout Itemize
23350
23351 check that the compilers are not told to supress warnings.
23352 \layout Itemize
23353
23354 check and convert compiler specific extensions (interrupts, memory areas,
23355  pragmas etc.).
23356 \layout Itemize
23357
23358 check for differences in type promotion.
23359  Especially check for math operations on 
23360 \family typewriter 
23361 char
23362 \family default 
23363  or 
23364 \family typewriter 
23365 unsigned char
23366 \family default 
23367  variables.
23368  For the sake of C99 compatibility SDCC will probably promote these to 
23369 \family typewriter 
23370 int
23371 \family default 
23372  more often than other compilers.
23373  Eventually insert explicit casts to 
23374 \family typewriter 
23375 (char) 
23376 \family default 
23377 or
23378 \family typewriter 
23379  (unsigned char)
23380 \family default 
23381 .
23382  Also check that the ~\SpecialChar ~
23383 operator
23384 \begin_inset LatexCommand \index{\~\/ Operator}
23385
23386 \end_inset 
23387
23388  is not used on 
23389 \family typewriter 
23390 bit
23391 \begin_inset LatexCommand \index{bit}
23392
23393 \end_inset 
23394
23395
23396 \family default 
23397  variables, use the !\SpecialChar ~
23398 operator instead.
23399  See sections 
23400 \begin_inset LatexCommand \ref{type promotion}
23401
23402 \end_inset 
23403
23404  and 
23405 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23406
23407 \end_inset 
23408
23409 .
23410 \layout Itemize
23411
23412 check the assembly code generated for interrupt routines (f.e.
23413  for calls to possibly non-reentrant library functions).
23414 \layout Itemize
23415
23416 check whether timing loops result in proper timing (or preferably consider
23417  a rewrite of the code with timer based delays instead).
23418 \layout Itemize
23419
23420 check for differences in printf parameters (some compilers push (va_arg
23421 \begin_inset LatexCommand \index{vararg, va\_arg}
23422
23423 \end_inset 
23424
23425 ) char variables as 
23426 \family typewriter 
23427 int
23428 \family default 
23429  others push them as 
23430 \family typewriter 
23431 char
23432 \family default 
23433 .
23434  See section 
23435 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23436
23437 \end_inset 
23438
23439 ).
23440 \layout Itemize
23441
23442 check the resulting memory map
23443 \begin_inset LatexCommand \index{Memory map}
23444
23445 \end_inset 
23446
23447 .
23448  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23449 ly idata, pdata, xdata).
23450  Eventually check if unexpected library functions are included.
23451 \layout Section
23452
23453 Tools
23454 \begin_inset LatexCommand \index{Tools}
23455
23456 \end_inset 
23457
23458  included in the distribution
23459 \layout Standard
23460 \align left 
23461
23462 \begin_inset  Tabular
23463 <lyxtabular version="3" rows="12" columns="3">
23464 <features>
23465 <column alignment="left" valignment="top" leftline="true" width="0pt">
23466 <column alignment="left" valignment="top" leftline="true" width="0pt">
23467 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23468 <row topline="true" bottomline="true">
23469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23470 \begin_inset Text
23471
23472 \layout Standard
23473
23474 Name
23475 \end_inset 
23476 </cell>
23477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23478 \begin_inset Text
23479
23480 \layout Standard
23481
23482 Purpose
23483 \end_inset 
23484 </cell>
23485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23486 \begin_inset Text
23487
23488 \layout Standard
23489
23490 Directory
23491 \end_inset 
23492 </cell>
23493 </row>
23494 <row topline="true">
23495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23496 \begin_inset Text
23497
23498 \layout Standard
23499
23500 ucSsim
23501 \end_inset 
23502 </cell>
23503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23504 \begin_inset Text
23505
23506 \layout Standard
23507
23508 Simulator for various architectures
23509 \end_inset 
23510 </cell>
23511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23512 \begin_inset Text
23513
23514 \layout Standard
23515
23516 sdcc/sim/ucsim
23517 \end_inset 
23518 </cell>
23519 </row>
23520 <row topline="true">
23521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23522 \begin_inset Text
23523
23524 \layout Standard
23525
23526 keil2sdcc.pl
23527 \end_inset 
23528 </cell>
23529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23530 \begin_inset Text
23531
23532 \layout Standard
23533
23534 header file
23535 \begin_inset LatexCommand \index{Header files}
23536
23537 \end_inset 
23538
23539
23540 \begin_inset LatexCommand \index{Include files}
23541
23542 \end_inset 
23543
23544  conversion
23545 \end_inset 
23546 </cell>
23547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23548 \begin_inset Text
23549
23550 \layout Standard
23551
23552 sdcc/support/scripts
23553 \end_inset 
23554 </cell>
23555 </row>
23556 <row topline="true">
23557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23558 \begin_inset Text
23559
23560 \layout Standard
23561
23562 mh2h.c
23563 \end_inset 
23564 </cell>
23565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23566 \begin_inset Text
23567
23568 \layout Standard
23569
23570 header file conversion
23571 \end_inset 
23572 </cell>
23573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23574 \begin_inset Text
23575
23576 \layout Standard
23577
23578 sdcc/support/scripts
23579 \end_inset 
23580 </cell>
23581 </row>
23582 <row topline="true">
23583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23584 \begin_inset Text
23585
23586 \layout Standard
23587
23588 as-gbz80
23589 \end_inset 
23590 </cell>
23591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23592 \begin_inset Text
23593
23594 \layout Standard
23595
23596 Assembler
23597 \end_inset 
23598 </cell>
23599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23600 \begin_inset Text
23601
23602 \layout Standard
23603
23604
23605 \family roman 
23606 \series medium 
23607 \shape up 
23608 \size normal 
23609 \emph off 
23610 \bar no 
23611 \noun off 
23612 \color none
23613 sdcc/bin
23614 \end_inset 
23615 </cell>
23616 </row>
23617 <row topline="true">
23618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23619 \begin_inset Text
23620
23621 \layout Standard
23622
23623 as-z80
23624 \end_inset 
23625 </cell>
23626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23627 \begin_inset Text
23628
23629 \layout Standard
23630
23631 Assembler
23632 \end_inset 
23633 </cell>
23634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23635 \begin_inset Text
23636
23637 \layout Standard
23638
23639
23640 \family roman 
23641 \series medium 
23642 \shape up 
23643 \size normal 
23644 \emph off 
23645 \bar no 
23646 \noun off 
23647 \color none
23648 sdcc/bin
23649 \end_inset 
23650 </cell>
23651 </row>
23652 <row topline="true">
23653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23654 \begin_inset Text
23655
23656 \layout Standard
23657
23658 asx8051
23659 \end_inset 
23660 </cell>
23661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23662 \begin_inset Text
23663
23664 \layout Standard
23665
23666 Assembler
23667 \end_inset 
23668 </cell>
23669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23670 \begin_inset Text
23671
23672 \layout Standard
23673
23674
23675 \family roman 
23676 \series medium 
23677 \shape up 
23678 \size normal 
23679 \emph off 
23680 \bar no 
23681 \noun off 
23682 \color none
23683 sdcc/bin
23684 \end_inset 
23685 </cell>
23686 </row>
23687 <row topline="true">
23688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23689 \begin_inset Text
23690
23691 \layout Standard
23692
23693 SDCDB
23694 \end_inset 
23695 </cell>
23696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23697 \begin_inset Text
23698
23699 \layout Standard
23700
23701 Simulator
23702 \end_inset 
23703 </cell>
23704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23705 \begin_inset Text
23706
23707 \layout Standard
23708
23709
23710 \family roman 
23711 \series medium 
23712 \shape up 
23713 \size normal 
23714 \emph off 
23715 \bar no 
23716 \noun off 
23717 \color none
23718 sdcc/bin
23719 \end_inset 
23720 </cell>
23721 </row>
23722 <row topline="true">
23723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23724 \begin_inset Text
23725
23726 \layout Standard
23727
23728 aslink
23729 \end_inset 
23730 </cell>
23731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23732 \begin_inset Text
23733
23734 \layout Standard
23735
23736 Linker
23737 \end_inset 
23738 </cell>
23739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23740 \begin_inset Text
23741
23742 \layout Standard
23743
23744
23745 \family roman 
23746 \series medium 
23747 \shape up 
23748 \size normal 
23749 \emph off 
23750 \bar no 
23751 \noun off 
23752 \color none
23753 sdcc/bin
23754 \end_inset 
23755 </cell>
23756 </row>
23757 <row topline="true">
23758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23759 \begin_inset Text
23760
23761 \layout Standard
23762
23763 link-z80
23764 \end_inset 
23765 </cell>
23766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23767 \begin_inset Text
23768
23769 \layout Standard
23770
23771 Linker
23772 \end_inset 
23773 </cell>
23774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23775 \begin_inset Text
23776
23777 \layout Standard
23778
23779
23780 \family roman 
23781 \series medium 
23782 \shape up 
23783 \size normal 
23784 \emph off 
23785 \bar no 
23786 \noun off 
23787 \color none
23788 sdcc/bin
23789 \end_inset 
23790 </cell>
23791 </row>
23792 <row topline="true">
23793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23794 \begin_inset Text
23795
23796 \layout Standard
23797
23798 link-gbz80
23799 \end_inset 
23800 </cell>
23801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23802 \begin_inset Text
23803
23804 \layout Standard
23805
23806 Linker
23807 \end_inset 
23808 </cell>
23809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23810 \begin_inset Text
23811
23812 \layout Standard
23813
23814
23815 \family roman 
23816 \series medium 
23817 \shape up 
23818 \size normal 
23819 \emph off 
23820 \bar no 
23821 \noun off 
23822 \color none
23823 sdcc/bin
23824 \end_inset 
23825 </cell>
23826 </row>
23827 <row topline="true" bottomline="true">
23828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23829 \begin_inset Text
23830
23831 \layout Standard
23832
23833 packihx
23834 \end_inset 
23835 </cell>
23836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23837 \begin_inset Text
23838
23839 \layout Standard
23840
23841 Intel Hex packer 
23842 \begin_inset LatexCommand \index{packihx (tool)}
23843
23844 \end_inset 
23845
23846
23847 \end_inset 
23848 </cell>
23849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23850 \begin_inset Text
23851
23852 \layout Standard
23853
23854
23855 \family roman 
23856 \series medium 
23857 \shape up 
23858 \size normal 
23859 \emph off 
23860 \bar no 
23861 \noun off 
23862 \color none
23863 sdcc/bin
23864 \end_inset 
23865 </cell>
23866 </row>
23867 </lyxtabular>
23868
23869 \end_inset 
23870
23871
23872 \newline 
23873
23874 \layout Section
23875
23876 Documentation
23877 \begin_inset LatexCommand \index{Documentation}
23878
23879 \end_inset 
23880
23881  included in the distribution
23882 \layout Standard
23883 \align left 
23884
23885 \begin_inset  Tabular
23886 <lyxtabular version="3" rows="10" columns="2">
23887 <features>
23888 <column alignment="left" valignment="top" leftline="true" width="0">
23889 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23890 <row topline="true" bottomline="true">
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23892 \begin_inset Text
23893
23894 \layout Standard
23895
23896 Subject / Title
23897 \end_inset 
23898 </cell>
23899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23900 \begin_inset Text
23901
23902 \layout Standard
23903
23904 Where to get / filename
23905 \end_inset 
23906 </cell>
23907 </row>
23908 <row topline="true">
23909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23910 \begin_inset Text
23911
23912 \layout Standard
23913
23914 SDCC Compiler User Guide
23915 \end_inset 
23916 </cell>
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23918 \begin_inset Text
23919
23920 \layout Standard
23921
23922 You're reading it right now
23923 \end_inset 
23924 </cell>
23925 </row>
23926 <row topline="true">
23927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23928 \begin_inset Text
23929
23930 \layout Standard
23931
23932 Changelog of SDCC
23933 \end_inset 
23934 </cell>
23935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23936 \begin_inset Text
23937
23938 \layout Standard
23939
23940 sdcc/Changelog
23941 \end_inset 
23942 </cell>
23943 </row>
23944 <row topline="true">
23945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23946 \begin_inset Text
23947
23948 \layout Standard
23949
23950 ASXXXX
23951 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
23952
23953 \end_inset 
23954
23955
23956 \begin_inset LatexCommand \index{Assembler documentation}
23957
23958 \end_inset 
23959
23960  Assemblers and ASLINK
23961 \begin_inset LatexCommand \index{aslink}
23962
23963 \end_inset 
23964
23965
23966 \begin_inset LatexCommand \index{Linker documentation}
23967
23968 \end_inset 
23969
23970  Relocating Linker
23971 \end_inset 
23972 </cell>
23973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23974 \begin_inset Text
23975
23976 \layout Standard
23977
23978 sdcc/as/doc/asxhtm.html
23979 \end_inset 
23980 </cell>
23981 </row>
23982 <row topline="true">
23983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23984 \begin_inset Text
23985
23986 \layout Standard
23987
23988 SDCC regression test
23989 \begin_inset LatexCommand \index{Regression test}
23990
23991 \end_inset 
23992
23993
23994 \end_inset 
23995 </cell>
23996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23997 \begin_inset Text
23998
23999 \layout Standard
24000
24001 sdcc/doc/test_suite_spec.pdf
24002 \end_inset 
24003 </cell>
24004 </row>
24005 <row topline="true">
24006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24007 \begin_inset Text
24008
24009 \layout Standard
24010
24011 Various notes
24012 \end_inset 
24013 </cell>
24014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24015 \begin_inset Text
24016
24017 \layout Standard
24018
24019 sdcc/doc/*
24020 \end_inset 
24021 </cell>
24022 </row>
24023 <row topline="true">
24024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24025 \begin_inset Text
24026
24027 \layout Standard
24028
24029 Notes on debugging with SDCDB
24030 \begin_inset LatexCommand \index{SDCDB (debugger)}
24031
24032 \end_inset 
24033
24034
24035 \end_inset 
24036 </cell>
24037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24038 \begin_inset Text
24039
24040 \layout Standard
24041
24042 sdcc/debugger/README
24043 \end_inset 
24044 </cell>
24045 </row>
24046 <row topline="true">
24047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24048 \begin_inset Text
24049
24050 \layout Standard
24051
24052 Software simulator for microcontrollers
24053 \end_inset 
24054 </cell>
24055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24056 \begin_inset Text
24057
24058 \layout Standard
24059
24060
24061 \family roman 
24062 \series medium 
24063 \shape up 
24064 \size normal 
24065 \emph off 
24066 \bar no 
24067 \noun off 
24068 \color none
24069 sdcc/sim/ucsim/doc
24070 \family default 
24071 \series default 
24072 \shape default 
24073 \size default 
24074 \emph default 
24075 \bar default 
24076 \noun default 
24077 \color default
24078 /index.html
24079 \end_inset 
24080 </cell>
24081 </row>
24082 <row topline="true">
24083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24084 \begin_inset Text
24085
24086 \layout Standard
24087
24088 Temporary notes on the pic16
24089 \begin_inset LatexCommand \index{PIC16}
24090
24091 \end_inset 
24092
24093  port
24094 \end_inset 
24095 </cell>
24096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24097 \begin_inset Text
24098
24099 \layout Standard
24100
24101 sdcc/src/pic16/NOTES
24102 \end_inset 
24103 </cell>
24104 </row>
24105 <row topline="true" bottomline="true">
24106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24107 \begin_inset Text
24108
24109 \layout Standard
24110
24111 SDCC internal documentation (debugging file format)
24112 \end_inset 
24113 </cell>
24114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24115 \begin_inset Text
24116
24117 \layout Standard
24118
24119 sdcc/doc/
24120 \family roman 
24121 \series medium 
24122 \shape up 
24123 \size normal 
24124 \emph off 
24125 \bar no 
24126 \noun off 
24127 \color none
24128 cdbfileformat.pd
24129 \family default 
24130 \series default 
24131 \shape default 
24132 \size default 
24133 \emph default 
24134 \bar default 
24135 \noun default 
24136 \color default
24137 f
24138 \end_inset 
24139 </cell>
24140 </row>
24141 </lyxtabular>
24142
24143 \end_inset 
24144
24145
24146 \newline 
24147
24148 \layout Section
24149
24150 Related open source tools
24151 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24152
24153 \end_inset 
24154
24155
24156 \begin_inset LatexCommand \index{Related tools}
24157
24158 \end_inset 
24159
24160
24161 \layout Standard
24162 \align left 
24163
24164 \begin_inset  Tabular
24165 <lyxtabular version="3" rows="14" columns="3">
24166 <features>
24167 <column alignment="left" valignment="top" leftline="true" width="0pt">
24168 <column alignment="block" valignment="top" leftline="true" width="30line%">
24169 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24170 <row topline="true" bottomline="true">
24171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24172 \begin_inset Text
24173
24174 \layout Standard
24175
24176 Name
24177 \end_inset 
24178 </cell>
24179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24180 \begin_inset Text
24181
24182 \layout Standard
24183
24184 Purpose
24185 \end_inset 
24186 </cell>
24187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24188 \begin_inset Text
24189
24190 \layout Standard
24191
24192 Where to get
24193 \end_inset 
24194 </cell>
24195 </row>
24196 <row topline="true">
24197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24198 \begin_inset Text
24199
24200 \layout Standard
24201
24202 gpsim
24203 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24204
24205 \end_inset 
24206
24207
24208 \end_inset 
24209 </cell>
24210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24211 \begin_inset Text
24212
24213 \layout Standard
24214
24215 PIC simulator
24216 \end_inset 
24217 </cell>
24218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24219 \begin_inset Text
24220
24221 \layout Standard
24222
24223
24224 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24225
24226 \end_inset 
24227
24228
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 gputils
24239 \begin_inset LatexCommand \index{gputils (pic tools)}
24240
24241 \end_inset 
24242
24243
24244 \end_inset 
24245 </cell>
24246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24247 \begin_inset Text
24248
24249 \layout Standard
24250
24251 GNU PIC utilities
24252 \end_inset 
24253 </cell>
24254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24255 \begin_inset Text
24256
24257 \layout Standard
24258
24259
24260 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24261
24262 \end_inset 
24263
24264
24265 \end_inset 
24266 </cell>
24267 </row>
24268 <row topline="true">
24269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24270 \begin_inset Text
24271
24272 \layout Standard
24273
24274 flP5
24275 \end_inset 
24276 </cell>
24277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24278 \begin_inset Text
24279
24280 \layout Standard
24281
24282 PIC programmer
24283 \end_inset 
24284 </cell>
24285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24286 \begin_inset Text
24287
24288 \layout Standard
24289
24290
24291 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24292
24293 \end_inset 
24294
24295
24296 \end_inset 
24297 </cell>
24298 </row>
24299 <row topline="true">
24300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24301 \begin_inset Text
24302
24303 \layout Standard
24304
24305 ec2drv/newcdb
24306 \end_inset 
24307 </cell>
24308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24309 \begin_inset Text
24310
24311 \layout Standard
24312
24313 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24314  (Unix only)
24315 \end_inset 
24316 </cell>
24317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24318 \begin_inset Text
24319
24320 \layout Standard
24321
24322
24323 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24324
24325 \end_inset 
24326
24327
24328 \end_inset 
24329 </cell>
24330 </row>
24331 <row topline="true">
24332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24333 \begin_inset Text
24334
24335 \layout Standard
24336
24337 indent
24338 \begin_inset LatexCommand \index{indent (source formatting tool)}
24339
24340 \end_inset 
24341
24342
24343 \end_inset 
24344 </cell>
24345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24346 \begin_inset Text
24347
24348 \layout Standard
24349
24350 Formats C source - Master of the white spaces
24351 \end_inset 
24352 </cell>
24353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24354 \begin_inset Text
24355
24356 \layout Standard
24357
24358
24359 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
24360
24361 \end_inset 
24362
24363
24364 \end_inset 
24365 </cell>
24366 </row>
24367 <row topline="true">
24368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24369 \begin_inset Text
24370
24371 \layout Standard
24372
24373 srecord
24374 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
24375
24376 \end_inset 
24377
24378
24379 \end_inset 
24380 </cell>
24381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24382 \begin_inset Text
24383
24384 \layout Standard
24385
24386 Object file conversion, checksumming, ...
24387 \end_inset 
24388 </cell>
24389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24390 \begin_inset Text
24391
24392 \layout Standard
24393
24394
24395 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
24396
24397 \end_inset 
24398
24399
24400 \end_inset 
24401 </cell>
24402 </row>
24403 <row topline="true">
24404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24405 \begin_inset Text
24406
24407 \layout Standard
24408
24409 objdump
24410 \begin_inset LatexCommand \index{objdump (tool)}
24411
24412 \end_inset 
24413
24414
24415 \end_inset 
24416 </cell>
24417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24418 \begin_inset Text
24419
24420 \layout Standard
24421
24422 Object file conversion, ...
24423 \end_inset 
24424 </cell>
24425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24426 \begin_inset Text
24427
24428 \layout Standard
24429
24430 Part of binutils (should be there anyway)
24431 \end_inset 
24432 </cell>
24433 </row>
24434 <row topline="true">
24435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24436 \begin_inset Text
24437
24438 \layout Standard
24439
24440 cmon51
24441 \end_inset 
24442 </cell>
24443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24444 \begin_inset Text
24445
24446 \layout Standard
24447
24448 8051 monitor (hex up-/download, single step, disassemble)
24449 \end_inset 
24450 </cell>
24451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24452 \begin_inset Text
24453
24454 \layout Standard
24455
24456
24457 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
24458
24459 \end_inset 
24460
24461
24462 \end_inset 
24463 </cell>
24464 </row>
24465 <row topline="true">
24466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24467 \begin_inset Text
24468
24469 \layout Standard
24470
24471 doxygen
24472 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
24473
24474 \end_inset 
24475
24476
24477 \end_inset 
24478 </cell>
24479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24480 \begin_inset Text
24481
24482 \layout Standard
24483
24484 Source code documentation system
24485 \end_inset 
24486 </cell>
24487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24488 \begin_inset Text
24489
24490 \layout Standard
24491
24492
24493 \begin_inset LatexCommand \url{http://www.doxygen.org}
24494
24495 \end_inset 
24496
24497
24498 \end_inset 
24499 </cell>
24500 </row>
24501 <row topline="true">
24502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24503 \begin_inset Text
24504
24505 \layout Standard
24506
24507 kdevelop
24508 \end_inset 
24509 </cell>
24510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24511 \begin_inset Text
24512
24513 \layout Standard
24514
24515 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
24516 \end_inset 
24517 </cell>
24518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24519 \begin_inset Text
24520
24521 \layout Standard
24522
24523
24524 \begin_inset LatexCommand \url{http://www.kdevelop.org}
24525
24526 \end_inset 
24527
24528
24529 \end_inset 
24530 </cell>
24531 </row>
24532 <row topline="true">
24533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24534 \begin_inset Text
24535
24536 \layout Standard
24537
24538 paulmon
24539 \end_inset 
24540 </cell>
24541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24542 \begin_inset Text
24543
24544 \layout Standard
24545
24546 8051 monitor (hex up-/download, single step, disassemble)
24547 \end_inset 
24548 </cell>
24549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24550 \begin_inset Text
24551
24552 \layout Standard
24553
24554
24555 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
24556
24557 \end_inset 
24558
24559
24560 \end_inset 
24561 </cell>
24562 </row>
24563 <row topline="true">
24564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24565 \begin_inset Text
24566
24567 \layout Standard
24568
24569 splint
24570 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24571
24572 \end_inset 
24573
24574
24575 \end_inset 
24576 </cell>
24577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24578 \begin_inset Text
24579
24580 \layout Standard
24581
24582 Statically checks c sources (see 
24583 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24584
24585 \end_inset 
24586
24587 )
24588 \end_inset 
24589 </cell>
24590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24591 \begin_inset Text
24592
24593 \layout Standard
24594
24595
24596 \begin_inset LatexCommand \url{http://www.splint.org}
24597
24598 \end_inset 
24599
24600
24601 \end_inset 
24602 </cell>
24603 </row>
24604 <row topline="true" bottomline="true">
24605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24606 \begin_inset Text
24607
24608 \layout Standard
24609
24610 ddd
24611 \begin_inset LatexCommand \index{ddd (debugger)}
24612
24613 \end_inset 
24614
24615
24616 \end_inset 
24617 </cell>
24618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24619 \begin_inset Text
24620
24621 \layout Standard
24622
24623 Debugger, serves nicely as GUI to SDCDB
24624 \begin_inset LatexCommand \index{SDCDB (debugger)}
24625
24626 \end_inset 
24627
24628  (Unix only)
24629 \end_inset 
24630 </cell>
24631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24632 \begin_inset Text
24633
24634 \layout Standard
24635
24636
24637 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
24638
24639 \end_inset 
24640
24641
24642 \end_inset 
24643 </cell>
24644 </row>
24645 </lyxtabular>
24646
24647 \end_inset 
24648
24649
24650 \newline 
24651
24652 \layout Section
24653
24654 Related documentation / recommended reading
24655 \layout Standard
24656 \align left 
24657
24658 \begin_inset  Tabular
24659 <lyxtabular version="3" rows="8" columns="3">
24660 <features>
24661 <column alignment="left" valignment="top" leftline="true" width="0pt">
24662 <column alignment="block" valignment="top" leftline="true" width="30line%">
24663 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24664 <row topline="true" bottomline="true">
24665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24666 \begin_inset Text
24667
24668 \layout Standard
24669
24670 Name
24671 \end_inset 
24672 </cell>
24673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24674 \begin_inset Text
24675
24676 \layout Standard
24677
24678 Subject / Title
24679 \end_inset 
24680 </cell>
24681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24682 \begin_inset Text
24683
24684 \layout Standard
24685
24686 Where to get
24687 \end_inset 
24688 </cell>
24689 </row>
24690 <row topline="true">
24691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24692 \begin_inset Text
24693
24694 \layout Standard
24695
24696
24697 \family roman 
24698 \series medium 
24699 \shape up 
24700 \size normal 
24701 \emph off 
24702 \bar no 
24703 \noun off 
24704 \color none
24705 c-refcard.pdf
24706 \end_inset 
24707 </cell>
24708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24709 \begin_inset Text
24710
24711 \layout Standard
24712
24713 C Reference Card
24714 \begin_inset LatexCommand \index{C Reference card}
24715
24716 \end_inset 
24717
24718 , 2 pages
24719 \end_inset 
24720 </cell>
24721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24722 \begin_inset Text
24723
24724 \layout Standard
24725
24726
24727 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
24728
24729 \end_inset 
24730
24731
24732 \end_inset 
24733 </cell>
24734 </row>
24735 <row topline="true">
24736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24737 \begin_inset Text
24738
24739 \layout Standard
24740
24741 c-faq
24742 \end_inset 
24743 </cell>
24744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24745 \begin_inset Text
24746
24747 \layout Standard
24748
24749 C-FAQ-list
24750 \end_inset 
24751 </cell>
24752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24753 \begin_inset Text
24754
24755 \layout Standard
24756
24757
24758 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
24759
24760 \end_inset 
24761
24762
24763 \end_inset 
24764 </cell>
24765 </row>
24766 <row topline="true">
24767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24768 \begin_inset Text
24769
24770 \layout Standard
24771
24772 ISO/IEC 9899:TC2
24773 \end_inset 
24774 </cell>
24775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24776 \begin_inset Text
24777
24778 \layout Standard
24779
24780
24781 \begin_inset Quotes sld
24782 \end_inset 
24783
24784 C-Standard
24785 \begin_inset Quotes srd
24786 \end_inset 
24787
24788
24789 \end_inset 
24790 </cell>
24791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24792 \begin_inset Text
24793
24794 \layout Standard
24795
24796
24797 \size footnotesize 
24798
24799 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
24800
24801 \end_inset 
24802
24803
24804 \end_inset 
24805 </cell>
24806 </row>
24807 <row topline="true">
24808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24809 \begin_inset Text
24810
24811 \layout Standard
24812
24813 ISO/IEC DTR 18037
24814 \end_inset 
24815 </cell>
24816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24817 \begin_inset Text
24818
24819 \layout Standard
24820
24821
24822 \begin_inset Quotes sld
24823 \end_inset 
24824
24825 Extensions for Embedded C
24826 \begin_inset Quotes srd
24827 \end_inset 
24828
24829
24830 \end_inset 
24831 </cell>
24832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24833 \begin_inset Text
24834
24835 \layout Standard
24836
24837
24838 \size footnotesize 
24839
24840 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
24841
24842 \end_inset 
24843
24844
24845 \end_inset 
24846 </cell>
24847 </row>
24848 <row topline="true">
24849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24850 \begin_inset Text
24851
24852 \layout Standard
24853
24854 \end_inset 
24855 </cell>
24856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24857 \begin_inset Text
24858
24859 \layout Standard
24860
24861 Latest datasheet of the target CPU
24862 \end_inset 
24863 </cell>
24864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24865 \begin_inset Text
24866
24867 \layout Standard
24868
24869 vendor
24870 \end_inset 
24871 </cell>
24872 </row>
24873 <row topline="true">
24874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24875 \begin_inset Text
24876
24877 \layout Standard
24878
24879 \end_inset 
24880 </cell>
24881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24882 \begin_inset Text
24883
24884 \layout Standard
24885
24886 Revision history of datasheet
24887 \end_inset 
24888 </cell>
24889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24890 \begin_inset Text
24891
24892 \layout Standard
24893
24894 vendor
24895 \end_inset 
24896 </cell>
24897 </row>
24898 <row topline="true" bottomline="true">
24899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24900 \begin_inset Text
24901
24902 \layout Standard
24903
24904 S.
24905  S.
24906  Muchnick
24907 \end_inset 
24908 </cell>
24909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24910 \begin_inset Text
24911
24912 \layout Standard
24913
24914 Advanced Compiler Design and Implementation
24915 \end_inset 
24916 </cell>
24917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24918 \begin_inset Text
24919
24920 \layout Standard
24921
24922 bookstore (very dedicated, probably read other books first)
24923 \end_inset 
24924 </cell>
24925 </row>
24926 </lyxtabular>
24927
24928 \end_inset 
24929
24930
24931 \newline 
24932
24933 \layout Section
24934
24935 Application notes specifically for SDCC
24936 \layout Standard
24937
24938 SDCC makes no claims about the completeness of this list and about up-to-datenes
24939 s or correctness of the application notes
24940 \begin_inset LatexCommand \index{Application notes}
24941
24942 \end_inset 
24943
24944 .
24945 \layout Standard
24946 \align left 
24947
24948 \size footnotesize 
24949
24950 \begin_inset  Tabular
24951 <lyxtabular version="3" rows="7" columns="3">
24952 <features>
24953 <column alignment="block" valignment="top" leftline="true" width="17col%">
24954 <column alignment="block" valignment="top" leftline="true" width="27col%">
24955 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
24956 <row topline="true" bottomline="true">
24957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24958 \begin_inset Text
24959
24960 \layout Standard
24961
24962
24963 \size footnotesize 
24964 Vendor
24965 \end_inset 
24966 </cell>
24967 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24968 \begin_inset Text
24969
24970 \layout Standard
24971
24972
24973 \size footnotesize 
24974 Subject / Title
24975 \end_inset 
24976 </cell>
24977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24978 \begin_inset Text
24979
24980 \layout Standard
24981
24982
24983 \size footnotesize 
24984 Where to get
24985 \end_inset 
24986 </cell>
24987 </row>
24988 <row topline="true">
24989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24990 \begin_inset Text
24991
24992 \layout Standard
24993
24994
24995 \size footnotesize 
24996 Maxim / Dallas
24997 \end_inset 
24998 </cell>
24999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25000 \begin_inset Text
25001
25002 \layout Standard
25003
25004
25005 \size footnotesize 
25006 Using the SDCC Compiler for the DS80C400
25007 \begin_inset LatexCommand \index{DS80C400}
25008
25009 \end_inset 
25010
25011
25012 \end_inset 
25013 </cell>
25014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25015 \begin_inset Text
25016
25017 \layout Standard
25018
25019
25020 \size footnotesize 
25021
25022 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25023
25024 \end_inset 
25025
25026
25027 \end_inset 
25028 </cell>
25029 </row>
25030 <row topline="true">
25031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25032 \begin_inset Text
25033
25034 \layout Standard
25035
25036
25037 \size footnotesize 
25038 Maxim / Dallas
25039 \end_inset 
25040 </cell>
25041 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25042 \begin_inset Text
25043
25044 \layout Standard
25045
25046
25047 \size footnotesize 
25048 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25049 \begin_inset LatexCommand \index{DS89C4x0}
25050
25051 \end_inset 
25052
25053  Family of Microcontrollers
25054 \end_inset 
25055 </cell>
25056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25057 \begin_inset Text
25058
25059 \layout Standard
25060
25061
25062 \size footnotesize 
25063
25064 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25065
25066 \end_inset 
25067
25068
25069 \end_inset 
25070 </cell>
25071 </row>
25072 <row topline="true">
25073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25074 \begin_inset Text
25075
25076 \layout Standard
25077
25078
25079 \size footnotesize 
25080 Silicon Laboratories / Cygnal
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
25089 \size footnotesize 
25090 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25091 \end_inset 
25092 </cell>
25093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25094 \begin_inset Text
25095
25096 \layout Standard
25097
25098
25099 \size footnotesize 
25100
25101 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
25102
25103 \end_inset 
25104
25105
25106 \end_inset 
25107 </cell>
25108 </row>
25109 <row topline="true">
25110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25111 \begin_inset Text
25112
25113 \layout Standard
25114
25115
25116 \size footnotesize 
25117 Ramtron / Goal Semiconductor
25118 \end_inset 
25119 </cell>
25120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25121 \begin_inset Text
25122
25123 \layout Standard
25124
25125
25126 \size footnotesize 
25127 Interfacing SDCC to Syn and Textpad
25128 \end_inset 
25129 </cell>
25130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25131 \begin_inset Text
25132
25133 \layout Standard
25134
25135
25136 \size footnotesize 
25137
25138 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25139
25140 \end_inset 
25141
25142
25143 \end_inset 
25144 </cell>
25145 </row>
25146 <row topline="true">
25147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25148 \begin_inset Text
25149
25150 \layout Standard
25151
25152
25153 \size footnotesize 
25154 Ramtron / Goal Semiconductor
25155 \end_inset 
25156 </cell>
25157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25158 \begin_inset Text
25159
25160 \layout Standard
25161
25162
25163 \size footnotesize 
25164 Installing and Configuring SDCC and Crimson Editor 
25165 \end_inset 
25166 </cell>
25167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25168 \begin_inset Text
25169
25170 \layout Standard
25171
25172
25173 \size footnotesize 
25174
25175 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25176
25177 \end_inset 
25178
25179
25180 \end_inset 
25181 </cell>
25182 </row>
25183 <row topline="true" bottomline="true">
25184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25185 \begin_inset Text
25186
25187 \layout Standard
25188
25189
25190 \size footnotesize 
25191 Texas Instruments
25192 \end_inset 
25193 </cell>
25194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25195 \begin_inset Text
25196
25197 \layout Standard
25198
25199
25200 \size footnotesize 
25201 MSC12xx Programming with SDCC
25202 \end_inset 
25203 </cell>
25204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25205 \begin_inset Text
25206
25207 \layout Standard
25208
25209
25210 \size footnotesize 
25211
25212 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25213
25214 \end_inset 
25215
25216
25217 \end_inset 
25218 </cell>
25219 </row>
25220 </lyxtabular>
25221
25222 \end_inset 
25223
25224
25225 \layout Section
25226
25227 Some Questions
25228 \layout Standard
25229
25230 Some questions answered, some pointers given - it might be time to in turn
25231  ask 
25232 \emph on 
25233 you
25234 \emph default 
25235  some questions: 
25236 \layout Itemize
25237
25238 can you solve your project with the selected microcontroller? Would you
25239  find out early or rather late that your target is too small/slow/whatever?
25240  Can you switch to a slightly better device if it doesn't fit?
25241 \layout Itemize
25242
25243 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25244  and/or another programming language be more adequate? Would an operating
25245  system on the target device help?
25246 \layout Itemize
25247
25248 if you solved the problem, will the marketing department be happy?
25249 \layout Itemize
25250
25251 if the marketing department is happy, will customers be happy?
25252 \layout Itemize
25253
25254 if you're the project manager, marketing department and maybe even the customer
25255  in one person, have you tried to see the project from the outside?
25256 \layout Itemize
25257
25258 is the project done if you think it is done? Or is just that other interface/pro
25259 tocol/feature/configuration/option missing? How about website, manual(s),
25260  internationali(z|s)ation, packaging, labels, 2nd source for components,
25261  electromagnetic compatability/interference, documentation for production,
25262  production test software, update mechanism, patent issues?
25263 \layout Itemize
25264
25265 is your project adequately positioned in that magic triangle: fame, fortune,
25266  fun?
25267 \layout Standard
25268
25269 Maybe not all answers to these questions are known and some answers may
25270  even be 
25271 \emph on 
25272 no
25273 \emph default 
25274 , nevertheless knowing these questions may help you to avoid burnout
25275 \begin_inset Foot
25276 collapsed false
25277
25278 \layout Standard
25279
25280 burnout is bad for electronic devices, programmers and motorcycle tyres
25281 \end_inset 
25282
25283 .
25284  Chances are you didn't want to hear some of them...
25285 \layout Chapter
25286
25287 Support
25288 \begin_inset LatexCommand \index{Support}
25289
25290 \end_inset 
25291
25292
25293 \layout Standard
25294
25295 SDCC has grown to be a large project.
25296  The compiler alone (without the preprocessor, assembler and linker) is
25297  well over 150,000 lines of code (blank stripped).
25298  The open source nature of this project is a key to its continued growth
25299  and support.
25300  You gain the benefit and support of many active software developers and
25301  end users.
25302  Is SDCC perfect? No, that's why we need your help.
25303  The developers take pride in fixing reported bugs.
25304  You can help by reporting the bugs and helping other SDCC users.
25305  There are lots of ways to contribute, and we encourage you to take part
25306  in making SDCC a great software package.
25307  
25308 \layout Standard
25309
25310 The SDCC project is hosted on the SDCC sourceforge site at 
25311 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25312
25313 \end_inset 
25314
25315 .
25316  You'll find the complete set of mailing lists
25317 \begin_inset LatexCommand \index{Mailing list(s)}
25318
25319 \end_inset 
25320
25321 , forums, bug reporting system, patch submission
25322 \begin_inset LatexCommand \index{Patch submission}
25323
25324 \end_inset 
25325
25326  system, download
25327 \begin_inset LatexCommand \index{download}
25328
25329 \end_inset 
25330
25331  area and Subversion code repository
25332 \begin_inset LatexCommand \index{Subversion code repository}
25333
25334 \end_inset 
25335
25336  there.
25337 \layout Section
25338
25339 Reporting Bugs
25340 \begin_inset LatexCommand \index{Bug reporting}
25341
25342 \end_inset 
25343
25344
25345 \begin_inset LatexCommand \index{Reporting bugs}
25346
25347 \end_inset 
25348
25349
25350 \layout Standard
25351
25352 The recommended way of reporting bugs is using the infrastructure of the
25353  sourceforge site.
25354  You can follow the status of bug reports there and have an overview about
25355  the known bugs.
25356 \layout Standard
25357
25358 Bug reports are automatically forwarded to the developer mailing list and
25359  will be fixed ASAP.
25360  When reporting a bug, it is very useful to include a small test program
25361  (the smaller the better) which reproduces the problem.
25362  If you can isolate the problem by looking at the generated assembly code,
25363  this can be very helpful.
25364  Compiling your program with the -
25365 \begin_inset ERT
25366 status Collapsed
25367
25368 \layout Standard
25369
25370 \backslash 
25371 /
25372 \end_inset 
25373
25374 -dumpall
25375 \begin_inset LatexCommand \index{-\/-dumpall}
25376
25377 \end_inset 
25378
25379  option can sometimes be useful in locating optimization problems.
25380  When reporting a bug please make sure you:
25381 \layout Enumerate
25382
25383 Attach the code you are compiling with SDCC.
25384  
25385 \layout Enumerate
25386
25387 Specify the exact command you use to run SDCC, or attach your Makefile.
25388  
25389 \layout Enumerate
25390
25391 Specify the SDCC version (type "
25392 \family sans 
25393 \series bold 
25394 sdcc -v
25395 \family default 
25396 \series default 
25397 "), your platform, and operating system.
25398  
25399 \layout Enumerate
25400
25401 Provide an exact copy of any error message or incorrect output.
25402  
25403 \layout Enumerate
25404
25405 Put something meaningful in the subject of your message.
25406 \layout Standard
25407
25408 Please attempt to include these 5 important parts, as applicable, in all
25409  requests for support or when reporting any problems or bugs with SDCC.
25410  Though this will make your message lengthy, it will greatly improve your
25411  chance that SDCC users and developers will be able to help you.
25412  Some SDCC developers are frustrated by bug reports without code provided
25413  that they can use to reproduce and ultimately fix the problem, so please
25414  be sure to provide sample code if you are reporting a bug! 
25415 \layout Standard
25416
25417 Please have a short check that you are using a recent version of SDCC and
25418  the bug is not yet known.
25419  This is the link for reporting bugs: 
25420 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
25421
25422 \end_inset 
25423
25424 .
25425  With SDCC on average having more than 200 downloads
25426 \begin_inset LatexCommand \index{download}
25427
25428 \end_inset 
25429
25430  on sourceforge per day
25431 \begin_inset Foot
25432 collapsed false
25433
25434 \layout Standard
25435
25436 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
25437  between 2002 and 2005.
25438  This does not include other methods of distribution.
25439 \end_inset 
25440
25441  there must be some users.
25442  So it's not exactly easy to find a new bug.
25443  If you find one we need it: 
25444 \emph on 
25445 reporting bugs is good
25446 \emph default 
25447 .
25448 \layout Section
25449
25450 Requesting Features
25451 \begin_inset LatexCommand \label{sub:Requesting-Features}
25452
25453 \end_inset 
25454
25455
25456 \begin_inset LatexCommand \index{Feature request}
25457
25458 \end_inset 
25459
25460
25461 \begin_inset LatexCommand \index{Requesting features}
25462
25463 \end_inset 
25464
25465
25466 \layout Standard
25467
25468 Like bug reports feature requests are forwarded to the developer mailing
25469  list.
25470  This is the link for requesting features: 
25471 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
25472
25473 \end_inset 
25474
25475 .
25476 \layout Section
25477
25478 Submitting patches
25479 \layout Standard
25480
25481 Like bug reports contributed patches are forwarded to the developer mailing
25482  list.
25483  This is the link for submitting patches
25484 \begin_inset LatexCommand \index{Patch submission}
25485
25486 \end_inset 
25487
25488
25489 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
25490
25491 \end_inset 
25492
25493 .
25494 \layout Standard
25495
25496 You need to specify some parameters to the 
25497 \family typewriter 
25498 diff
25499 \family default 
25500  command for the patches to be useful.
25501  If you modified more than one file a patch created f.e.
25502  with 
25503 \family sans 
25504 \series bold 
25505
25506 \begin_inset Quotes sld
25507 \end_inset 
25508
25509 diff -Naur unmodified_directory modified_directory >my_changes.patch
25510 \begin_inset Quotes srd
25511 \end_inset 
25512
25513
25514 \family default 
25515 \series default 
25516  will be fine, otherwise 
25517 \family sans 
25518 \series bold 
25519
25520 \begin_inset Quotes sld
25521 \end_inset 
25522
25523 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
25524 \begin_inset Quotes srd
25525 \end_inset 
25526
25527
25528 \series default 
25529  
25530 \family default 
25531 will do.
25532 \layout Section
25533
25534 Getting Help
25535 \layout Standard
25536
25537 These links should take you directly to the 
25538 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
25539
25540 \end_inset 
25541
25542
25543 \begin_inset Foot
25544 collapsed false
25545
25546 \layout Standard
25547
25548 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
25549  automated messages (mid 2003)
25550 \end_inset 
25551
25552  and the 
25553 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
25554
25555 \end_inset 
25556
25557 , lists
25558 \begin_inset LatexCommand \index{Mailing list(s)}
25559
25560 \end_inset 
25561
25562  and forums are archived and searchable so if you are lucky someone already
25563  had a similar problem.
25564  While mails to the lists themselves are delivered promptly their web front
25565  end on sourceforge sometimes shows a severe time lag (up to several weeks),
25566  if you're seriously using SDCC please consider subscribing to the lists.
25567 \layout Section
25568
25569 ChangeLog
25570 \layout Standard
25571
25572 You can follow the status of the Subversion version
25573 \begin_inset LatexCommand \index{version}
25574
25575 \end_inset 
25576
25577  of SDCC by watching the Changelog
25578 \begin_inset LatexCommand \index{Changelog}
25579
25580 \end_inset 
25581
25582  in the Subversion repository
25583 \size footnotesize 
25584  
25585 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
25586
25587 \end_inset 
25588
25589 .
25590 \layout Section
25591
25592 Subversion Source Code Repository
25593 \layout Standard
25594
25595 The output of 
25596 \family sans 
25597 \series bold 
25598 sdcc --version
25599 \family default 
25600 \series default 
25601  or the filenames of the snapshot versions of SDCC include date and its
25602  Subversion
25603 \begin_inset LatexCommand \index{Subversion code repository}
25604
25605 \end_inset 
25606
25607  number.
25608  Subversion allows to download the source of recent or previous versions
25609  
25610 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
25611
25612 \end_inset 
25613
25614  (by number or by date).
25615  An on-line source code browser and detailled instructions are also available
25616  there.
25617  SDCC versions starting from 1999 up to now are available (currently the
25618  versions prior to the conversion from cvs
25619 \begin_inset LatexCommand \index{cvs (see Subversion)}
25620
25621 \end_inset 
25622
25623  to Subversion (April 2006) are either by accessible by Subversion or by
25624  cvs).
25625 \layout Section
25626
25627 Release policy
25628 \begin_inset LatexCommand \index{Release policy}
25629
25630 \end_inset 
25631
25632
25633 \layout Standard
25634
25635 Historically there often were long delays between official releases and
25636  the sourceforge download area tends to get not updated at all.
25637  Excuses in the past might have referred to problems with live range analysis,
25638  but as this was fixed a while ago, the current problem is that another
25639  excuse has to be found.
25640  Kidding aside, we have to get better there! On the other hand there are
25641  daily snapshots available at 
25642 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
25643
25644 \end_inset 
25645
25646 , and you can always build the very last version (hopefully with many bugs
25647  fixed, and features added) from the source code available at 
25648 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
25649
25650 \end_inset 
25651
25652 .
25653 \layout Section
25654
25655 Examples
25656 \begin_inset LatexCommand \index{Examples}
25657
25658 \end_inset 
25659
25660
25661 \layout Standard
25662
25663 You'll find some small examples in the directory 
25664 \emph on 
25665 sdcc/device/examples/.
25666  
25667 \emph default 
25668 More examples and libraries are available at
25669 \emph on 
25670  The SDCC Open Knowledge Resource 
25671 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
25672
25673 \end_inset 
25674
25675  
25676 \emph default 
25677 web site or at 
25678 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
25679
25680 \end_inset 
25681
25682 .
25683 \layout Comment
25684
25685 I did insert a reference to Paul's web site here although it seems rather
25686  dedicated to a specific 8032 board (I think it's okay because it f.e.
25687  shows LCD/Harddisc interface and has a free 8051 monitor.
25688  Independent 8032 board vendors face hard competition of heavily subsidized
25689  development boards anyway).
25690 \layout Comment
25691
25692 Maybe we should include some links to real world applications.
25693  Preferably pointer to pointers (one for each architecture) so this stays
25694  manageable here?
25695 \layout Section
25696
25697 Quality control
25698 \begin_inset LatexCommand \index{Quality control}
25699
25700 \end_inset 
25701
25702
25703 \layout Standard
25704
25705 The compiler is passed through nightly compile and build checks.
25706  The so called 
25707 \shape italic 
25708 regression tests
25709 \shape default 
25710
25711 \begin_inset LatexCommand \index{Regression test}
25712
25713 \end_inset 
25714
25715  check that SDCC itself compiles flawlessly on several platforms and checks
25716  the quality of the code generated by SDCC by running the code through simulator
25717 s.
25718  There is a separate document 
25719 \shape italic 
25720 test_suite.pdf
25721 \begin_inset LatexCommand \index{Test suite}
25722
25723 \end_inset 
25724
25725
25726 \shape default 
25727  about this.
25728 \layout Standard
25729
25730 You'll find the test code in the directory 
25731 \shape italic 
25732 sdcc/support/regression
25733 \shape default 
25734 .
25735  You can run these tests manually by running 
25736 \family sans 
25737 make
25738 \family default 
25739  in this directory (or f.e.
25740  
25741 \family sans 
25742 \series bold 
25743
25744 \begin_inset Quotes sld
25745 \end_inset 
25746
25747 make test-mcs51
25748 \begin_inset Quotes srd
25749 \end_inset 
25750
25751
25752 \family default 
25753 \series default 
25754  if you don't want to run the complete tests).
25755  The test code might also be interesting if you want to look for examples
25756 \begin_inset LatexCommand \index{Examples}
25757
25758 \end_inset 
25759
25760  checking corner cases of SDCC or if you plan to submit patches
25761 \begin_inset LatexCommand \index{Patch submission}
25762
25763 \end_inset 
25764
25765 .
25766 \layout Standard
25767
25768 The pic port uses a different set of regression tests, you'll find them
25769  in the directory 
25770 \shape italic 
25771 sdcc/src/regression
25772 \shape default 
25773 .
25774 \layout Section
25775
25776 Use of SDCC in Education
25777 \layout Standard
25778
25779 In short: 
25780 \emph on 
25781 highly
25782 \emph default 
25783  encouraged
25784 \begin_inset Foot
25785 collapsed false
25786
25787 \layout Standard
25788
25789 the phrase "use in education" might evoke the association "
25790 \emph on 
25791 only
25792 \emph default 
25793  fit for use in education".
25794  This connotation is not intended but nevertheless risked as the licensing
25795  of SDCC makes it difficult to offer educational discounts
25796 \end_inset 
25797
25798 .
25799  If your rationales are to:
25800 \layout Enumerate
25801
25802 give students a chance to understand the 
25803 \emph on 
25804 complete
25805 \emph default 
25806  steps of code generation
25807 \layout Enumerate
25808
25809 have a curriculum that can be extended for years.
25810  Then you could use an fpga board as target and your curriculum will seamlessly
25811  extend from logic synthesis (
25812 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
25813
25814 \end_inset 
25815
25816
25817 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
25818
25819 \end_inset 
25820
25821 ), over assembly programming, to C to FPGA compilers (
25822 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
25823
25824 \end_inset 
25825
25826 ) and to C.
25827 \layout Enumerate
25828
25829 be able to insert excursions about skills like using a revision control
25830  system, submitting/applying patches, using a type-setting (as opposed to
25831  word-processing) engine LyX/LaTeX, using 
25832 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
25833
25834 \end_inset 
25835
25836 , following some 
25837 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
25838
25839 \end_inset 
25840
25841 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
25842  Source Software, CPU simulation, compiler regression tests
25843 \begin_inset LatexCommand \index{Regression test}
25844
25845 \end_inset 
25846
25847 .
25848  
25849 \newline 
25850 And if there should be a shortage of ideas then you can always point students
25851  to the ever-growing feature request list 
25852 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
25853
25854 \end_inset 
25855
25856 .
25857 \layout Enumerate
25858
25859 not tie students to a specific host platform and instead allow them to use
25860  a host platform of 
25861 \emph on 
25862 their
25863 \emph default 
25864  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
25865  eventually 
25866 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
25867
25868 \end_inset 
25869
25870 )
25871 \layout Enumerate
25872
25873 not encourage students to use illegal copies of educational software
25874 \layout Enumerate
25875
25876 be immune to licensing/availability/price changes of the chosen tool chain
25877 \layout Enumerate
25878
25879 be able to change to a new target platform without having to adopt a new
25880  tool chain
25881 \layout Enumerate
25882
25883 have complete control over and insight into the tool chain
25884 \layout Enumerate
25885
25886 make your students aware about the pros and cons of open source software
25887  development
25888 \layout Enumerate
25889
25890 give back to the public as you are probably at least partially publically
25891  funded
25892 \layout Enumerate
25893
25894 give students a chance to publically prove their skills and to possibly
25895  see a world wide impact
25896 \layout Standard
25897
25898 then SDCC is probably among the first choices.
25899  Well, probably SDCC might be the only choice.
25900 \layout Chapter
25901 \pagebreak_top 
25902 SDCC Technical Data
25903 \layout Section
25904
25905 Optimizations
25906 \begin_inset LatexCommand \index{Optimizations}
25907
25908 \end_inset 
25909
25910
25911 \layout Standard
25912
25913 SDCC performs a host of standard optimizations in addition to some MCU specific
25914  optimizations.
25915  
25916 \layout Subsection
25917
25918 Sub-expression Elimination
25919 \begin_inset LatexCommand \index{Subexpression elimination}
25920
25921 \end_inset 
25922
25923
25924 \layout Standard
25925
25926 The compiler does local and 
25927 \emph on 
25928 g
25929 \emph default 
25930 lobal 
25931 \emph on 
25932 c
25933 \emph default 
25934 ommon 
25935 \emph on 
25936 s
25937 \emph default 
25938 ubexpression 
25939 \emph on 
25940 e
25941 \emph default 
25942 limination, e.g.: 
25943 \layout Verse
25944
25945
25946 \family typewriter 
25947 i = x + y + 1; 
25948 \newline 
25949 j = x + y;
25950 \layout Standard
25951
25952 will be translated to
25953 \layout Verse
25954
25955
25956 \family typewriter 
25957 iTemp = x + y; 
25958 \newline 
25959 i = iTemp + 1; 
25960 \newline 
25961 j = iTemp;
25962 \layout Standard
25963
25964 Some subexpressions are not as obvious as the above example, e.g.:
25965 \layout Verse
25966
25967
25968 \family typewriter 
25969 a->b[i].c = 10; 
25970 \newline 
25971 a->b[i].d = 11;
25972 \layout Standard
25973
25974 In this case the address arithmetic a->b[i] will be computed only once;
25975  the equivalent code in C would be.
25976 \layout Verse
25977
25978
25979 \family typewriter 
25980 iTemp = a->b[i]; 
25981 \newline 
25982 iTemp.c = 10; 
25983 \newline 
25984 iTemp.d = 11;
25985 \layout Standard
25986
25987 The compiler will try to keep these temporary variables in registers.
25988 \layout Subsection
25989
25990 Dead-Code Elimination
25991 \begin_inset LatexCommand \index{Dead-code elimination}
25992
25993 \end_inset 
25994
25995
25996 \layout Verse
25997
25998
25999 \family typewriter 
26000 int global;
26001 \newline 
26002
26003 \newline 
26004 void f () { 
26005 \newline 
26006 \SpecialChar ~
26007 \SpecialChar ~
26008 int i; 
26009 \newline 
26010 \SpecialChar ~
26011 \SpecialChar ~
26012 i = 1; \SpecialChar ~
26013 \SpecialChar ~
26014 \SpecialChar ~
26015 \SpecialChar ~
26016 \SpecialChar ~
26017 /* dead store */ 
26018 \newline 
26019 \SpecialChar ~
26020 \SpecialChar ~
26021 global = 1;\SpecialChar ~
26022 /* dead store */ 
26023 \newline 
26024 \SpecialChar ~
26025 \SpecialChar ~
26026 global = 2; 
26027 \newline 
26028 \SpecialChar ~
26029 \SpecialChar ~
26030 return; 
26031 \newline 
26032 \SpecialChar ~
26033 \SpecialChar ~
26034 global = 3;\SpecialChar ~
26035 /* unreachable */ 
26036 \newline 
26037 }
26038 \layout Standard
26039
26040 will be changed to
26041 \layout Verse
26042
26043
26044 \family typewriter 
26045 int global;
26046 \newline 
26047
26048 \newline 
26049 void f () {
26050 \newline 
26051 \SpecialChar ~
26052 \SpecialChar ~
26053 global = 2; 
26054 \newline 
26055 }
26056 \layout Subsection
26057
26058 Copy-Propagation
26059 \begin_inset LatexCommand \index{Copy propagation}
26060
26061 \end_inset 
26062
26063
26064 \layout Verse
26065
26066
26067 \family typewriter 
26068 int f() { 
26069 \newline 
26070 \SpecialChar ~
26071 \SpecialChar ~
26072 int i, j; 
26073 \newline 
26074 \SpecialChar ~
26075 \SpecialChar ~
26076 i = 10; 
26077 \newline 
26078 \SpecialChar ~
26079 \SpecialChar ~
26080 j = i; 
26081 \newline 
26082 \SpecialChar ~
26083 \SpecialChar ~
26084 return j; 
26085 \newline 
26086 }
26087 \layout Standard
26088
26089 will be changed to 
26090 \layout Verse
26091
26092
26093 \family typewriter 
26094 int f() { 
26095 \newline 
26096 \SpecialChar ~
26097 \SpecialChar ~
26098 int i, j; 
26099 \newline 
26100 \SpecialChar ~
26101 \SpecialChar ~
26102 i = 10; 
26103 \newline 
26104 \SpecialChar ~
26105 \SpecialChar ~
26106 j = 10; 
26107 \newline 
26108 \SpecialChar ~
26109 \SpecialChar ~
26110 return 10; 
26111 \newline 
26112 }
26113 \layout Standard
26114
26115 Note: the dead stores created by this copy propagation will be eliminated
26116  by dead-code elimination.
26117 \layout Subsection
26118
26119 Loop Optimizations
26120 \begin_inset LatexCommand \index{Loop optimization}
26121
26122 \end_inset 
26123
26124
26125 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26126
26127 \end_inset 
26128
26129
26130 \layout Standard
26131
26132 Two types of loop optimizations are done by SDCC 
26133 \emph on 
26134 loop invariant
26135 \emph default 
26136  lifting and
26137 \emph on 
26138  strength reduction
26139 \emph default 
26140  of loop induction variables.
26141  In addition to the strength reduction the optimizer marks the induction
26142  variables and the register allocator tries to keep the induction variables
26143  in registers for the duration of the loop.
26144  Because of this preference of the register allocator
26145 \begin_inset LatexCommand \index{Register allocation}
26146
26147 \end_inset 
26148
26149 , loop induction optimization causes an increase in register pressure, which
26150  may cause unwanted spilling of other temporary variables into the stack
26151 \begin_inset LatexCommand \index{stack}
26152
26153 \end_inset 
26154
26155  / data space.
26156  The compiler will generate a warning message when it is forced to allocate
26157  extra space either on the stack or data space.
26158  If this extra space allocation is undesirable then induction optimization
26159  can be eliminated either for the entire source file (with -
26160 \begin_inset ERT
26161 status Collapsed
26162
26163 \layout Standard
26164
26165 \backslash 
26166 /
26167 \end_inset 
26168
26169 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26170 noinduction
26171 \begin_inset LatexCommand \index{\#pragma noinduction}
26172
26173 \end_inset 
26174
26175 .
26176 \newline 
26177
26178 \newline 
26179 Loop Invariant:
26180 \layout Verse
26181
26182
26183 \family typewriter 
26184 for (i = 0 ; i < 100 ; i ++) 
26185 \newline 
26186 \SpecialChar ~
26187 \SpecialChar ~
26188 \SpecialChar ~
26189 \SpecialChar ~
26190 f += k + l;
26191 \layout Standard
26192
26193 changed to
26194 \layout Verse
26195
26196
26197 \family typewriter 
26198 itemp = k + l; 
26199 \newline 
26200 for (i = 0; i < 100; i++) 
26201 \newline 
26202 \SpecialChar ~
26203 \SpecialChar ~
26204 \SpecialChar ~
26205 \SpecialChar ~
26206 f += itemp;
26207 \layout Standard
26208
26209 As mentioned previously some loop invariants are not as apparent, all static
26210  address computations are also moved out of the loop.
26211 \newline 
26212
26213 \newline 
26214 Strength Reduction
26215 \begin_inset LatexCommand \index{Strength reduction}
26216
26217 \end_inset 
26218
26219 , this optimization substitutes an expression by a cheaper expression:
26220 \layout Verse
26221
26222
26223 \family typewriter 
26224 for (i=0;i < 100; i++)
26225 \newline 
26226 \SpecialChar ~
26227 \SpecialChar ~
26228 \SpecialChar ~
26229 \SpecialChar ~
26230 ar[i*5] = i*3;
26231 \layout Standard
26232
26233 changed to
26234 \layout Verse
26235
26236
26237 \family typewriter 
26238 itemp1 = 0; 
26239 \newline 
26240 itemp2 = 0; 
26241 \newline 
26242 for (i=0;i< 100;i++) { 
26243 \newline 
26244 \SpecialChar ~
26245 \SpecialChar ~
26246 \SpecialChar ~
26247 \SpecialChar ~
26248 ar[itemp1] = itemp2; 
26249 \newline 
26250 \SpecialChar ~
26251 \SpecialChar ~
26252 \SpecialChar ~
26253 \SpecialChar ~
26254 itemp1 += 5; 
26255 \newline 
26256 \SpecialChar ~
26257 \SpecialChar ~
26258 \SpecialChar ~
26259 \SpecialChar ~
26260 itemp2 += 3; 
26261 \newline 
26262 }
26263 \layout Standard
26264
26265 The more expensive multiplication
26266 \begin_inset LatexCommand \index{Multiplication}
26267
26268 \end_inset 
26269
26270  is changed to a less expensive addition.
26271 \layout Subsection
26272
26273 Loop Reversing
26274 \begin_inset LatexCommand \index{Loop reversing}
26275
26276 \end_inset 
26277
26278
26279 \layout Standard
26280
26281 This optimization is done to reduce the overhead of checking loop boundaries
26282  for every iteration.
26283  Some simple loops can be reversed and implemented using a 
26284 \begin_inset Quotes eld
26285 \end_inset 
26286
26287 decrement and jump if not zero
26288 \begin_inset Quotes erd
26289 \end_inset 
26290
26291  instruction.
26292  SDCC checks for the following criterion to determine if a loop is reversible
26293  (note: more sophisticated compilers use data-dependency analysis to make
26294  this determination, SDCC uses a more simple minded analysis).
26295 \layout Itemize
26296
26297 The 'for' loop is of the form 
26298 \newline 
26299
26300 \newline 
26301
26302 \family typewriter 
26303 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
26304  += 1])
26305 \newline 
26306 \SpecialChar ~
26307 \SpecialChar ~
26308 \SpecialChar ~
26309 \SpecialChar ~
26310 <for body>
26311 \layout Itemize
26312
26313 The <for body> does not contain 
26314 \begin_inset Quotes eld
26315 \end_inset 
26316
26317 continue
26318 \begin_inset Quotes erd
26319 \end_inset 
26320
26321  or 'break
26322 \begin_inset Quotes erd
26323 \end_inset 
26324
26325 .
26326 \layout Itemize
26327
26328 All goto's are contained within the loop.
26329 \layout Itemize
26330
26331 No function calls within the loop.
26332 \layout Itemize
26333
26334 The loop control variable <sym> is not assigned any value within the loop
26335 \layout Itemize
26336
26337 The loop control variable does NOT participate in any arithmetic operation
26338  within the loop.
26339 \layout Itemize
26340
26341 There are NO switch statements in the loop.
26342 \layout Subsection
26343
26344 Algebraic Simplifications
26345 \layout Standard
26346
26347 SDCC does numerous algebraic simplifications, the following is a small sub-set
26348  of these optimizations.
26349 \layout Verse
26350
26351
26352 \family typewriter 
26353 i = j + 0;\SpecialChar ~
26354 \SpecialChar ~
26355 \SpecialChar ~
26356 \SpecialChar ~
26357  /* changed to: */\SpecialChar ~
26358 \SpecialChar ~
26359 \SpecialChar ~
26360 \SpecialChar ~
26361  i = j; 
26362 \newline 
26363 i /= 2;\SpecialChar ~
26364 \SpecialChar ~
26365 \SpecialChar ~
26366 \SpecialChar ~
26367 \SpecialChar ~
26368 \SpecialChar ~
26369 \SpecialChar ~
26370  /* changed to: */\SpecialChar ~
26371 \SpecialChar ~
26372 \SpecialChar ~
26373 \SpecialChar ~
26374  i >>= 1; 
26375 \newline 
26376 i = j - j;\SpecialChar ~
26377 \SpecialChar ~
26378 \SpecialChar ~
26379 \SpecialChar ~
26380  /* changed to: */\SpecialChar ~
26381 \SpecialChar ~
26382 \SpecialChar ~
26383 \SpecialChar ~
26384  i = 0; 
26385 \newline 
26386 i = j / 1;\SpecialChar ~
26387 \SpecialChar ~
26388 \SpecialChar ~
26389 \SpecialChar ~
26390  /* changed to: */\SpecialChar ~
26391 \SpecialChar ~
26392 \SpecialChar ~
26393 \SpecialChar ~
26394  i = j;
26395 \layout Standard
26396
26397 Note the subexpressions
26398 \begin_inset LatexCommand \index{Subexpression}
26399
26400 \end_inset 
26401
26402  given above are generally introduced by macro expansions or as a result
26403  of copy/constant propagation.
26404 \layout Subsection
26405
26406 'switch' Statements
26407 \begin_inset LatexCommand \label{sub:'switch'-Statements}
26408
26409 \end_inset 
26410
26411
26412 \begin_inset LatexCommand \index{switch statement}
26413
26414 \end_inset 
26415
26416
26417 \layout Standard
26418
26419 SDCC can optimize switch statements to jump tables
26420 \begin_inset LatexCommand \index{jump tables}
26421
26422 \end_inset 
26423
26424 .
26425  It makes the decision based on an estimate of the generated code size.
26426  SDCC is quite liberal in the requirements for jump table generation: 
26427 \layout Itemize
26428
26429 The labels need not be in order, and the starting number need not be one
26430  or zero, the case labels are in numerical sequence or not too many case
26431  labels are missing.
26432 \begin_deeper 
26433 \layout Verse
26434
26435
26436 \family typewriter 
26437 switch(i) {\SpecialChar ~
26438 \SpecialChar ~
26439 \SpecialChar ~
26440 \SpecialChar ~
26441 \SpecialChar ~
26442 \SpecialChar ~
26443 \SpecialChar ~
26444 \SpecialChar ~
26445 \SpecialChar ~
26446 \SpecialChar ~
26447 \SpecialChar ~
26448 \SpecialChar ~
26449 \SpecialChar ~
26450 \SpecialChar ~
26451 \SpecialChar ~
26452 \SpecialChar ~
26453 \SpecialChar ~
26454 \SpecialChar ~
26455 \SpecialChar ~
26456 \SpecialChar ~
26457 \SpecialChar ~
26458 \SpecialChar ~
26459 \SpecialChar ~
26460 \SpecialChar ~
26461 \SpecialChar ~
26462 \SpecialChar ~
26463 switch (i) { 
26464 \newline 
26465 \SpecialChar ~
26466 \SpecialChar ~
26467 \SpecialChar ~
26468 case 4: ...\SpecialChar ~
26469 \SpecialChar ~
26470 \SpecialChar ~
26471 \SpecialChar ~
26472 \SpecialChar ~
26473 \SpecialChar ~
26474 \SpecialChar ~
26475 \SpecialChar ~
26476 \SpecialChar ~
26477 \SpecialChar ~
26478 \SpecialChar ~
26479 \SpecialChar ~
26480 \SpecialChar ~
26481 \SpecialChar ~
26482 \SpecialChar ~
26483 \SpecialChar ~
26484 \SpecialChar ~
26485 \SpecialChar ~
26486 \SpecialChar ~
26487 \SpecialChar ~
26488 \SpecialChar ~
26489 \SpecialChar ~
26490 \SpecialChar ~
26491 \SpecialChar ~
26492 \SpecialChar ~
26493 \SpecialChar ~
26494 case 0: ...
26495  
26496 \newline 
26497 \SpecialChar ~
26498 \SpecialChar ~
26499 \SpecialChar ~
26500 case 5: ...\SpecialChar ~
26501 \SpecialChar ~
26502 \SpecialChar ~
26503 \SpecialChar ~
26504 \SpecialChar ~
26505 \SpecialChar ~
26506 \SpecialChar ~
26507 \SpecialChar ~
26508 \SpecialChar ~
26509 \SpecialChar ~
26510 \SpecialChar ~
26511 \SpecialChar ~
26512 \SpecialChar ~
26513 \SpecialChar ~
26514 \SpecialChar ~
26515 \SpecialChar ~
26516 \SpecialChar ~
26517 \SpecialChar ~
26518 \SpecialChar ~
26519 \SpecialChar ~
26520 \SpecialChar ~
26521 \SpecialChar ~
26522 \SpecialChar ~
26523 \SpecialChar ~
26524 \SpecialChar ~
26525 \SpecialChar ~
26526 case 1: ...
26527  
26528 \newline 
26529 \SpecialChar ~
26530 \SpecialChar ~
26531 \SpecialChar ~
26532 case 3: ...\SpecialChar ~
26533 \SpecialChar ~
26534 \SpecialChar ~
26535 \SpecialChar ~
26536 \SpecialChar ~
26537 \SpecialChar ~
26538 \SpecialChar ~
26539 \SpecialChar ~
26540 \SpecialChar ~
26541 \SpecialChar ~
26542 \SpecialChar ~
26543 \SpecialChar ~
26544 \SpecialChar ~
26545 \SpecialChar ~
26546 \SpecialChar ~
26547 \SpecialChar ~
26548 \SpecialChar ~
26549 \SpecialChar ~
26550 \SpecialChar ~
26551 \SpecialChar ~
26552 \SpecialChar ~
26553 \SpecialChar ~
26554 \SpecialChar ~
26555 \SpecialChar ~
26556 \SpecialChar ~
26557 \SpecialChar ~
26558
26559 \newline 
26560 \SpecialChar ~
26561 \SpecialChar ~
26562 \SpecialChar ~
26563 case 6: ...\SpecialChar ~
26564 \SpecialChar ~
26565 \SpecialChar ~
26566 \SpecialChar ~
26567 \SpecialChar ~
26568 \SpecialChar ~
26569 \SpecialChar ~
26570 \SpecialChar ~
26571 \SpecialChar ~
26572 \SpecialChar ~
26573 \SpecialChar ~
26574 \SpecialChar ~
26575 \SpecialChar ~
26576 \SpecialChar ~
26577 \SpecialChar ~
26578 \SpecialChar ~
26579 \SpecialChar ~
26580 \SpecialChar ~
26581 \SpecialChar ~
26582 \SpecialChar ~
26583 \SpecialChar ~
26584 \SpecialChar ~
26585 \SpecialChar ~
26586 \SpecialChar ~
26587 \SpecialChar ~
26588 \SpecialChar ~
26589 case 3: ...
26590  
26591 \newline 
26592 \SpecialChar ~
26593 \SpecialChar ~
26594 \SpecialChar ~
26595 case 7: ...\SpecialChar ~
26596 \SpecialChar ~
26597 \SpecialChar ~
26598 \SpecialChar ~
26599 \SpecialChar ~
26600 \SpecialChar ~
26601 \SpecialChar ~
26602 \SpecialChar ~
26603 \SpecialChar ~
26604 \SpecialChar ~
26605 \SpecialChar ~
26606 \SpecialChar ~
26607 \SpecialChar ~
26608 \SpecialChar ~
26609 \SpecialChar ~
26610 \SpecialChar ~
26611 \SpecialChar ~
26612 \SpecialChar ~
26613 \SpecialChar ~
26614 \SpecialChar ~
26615 \SpecialChar ~
26616 \SpecialChar ~
26617 \SpecialChar ~
26618 \SpecialChar ~
26619 \SpecialChar ~
26620 \SpecialChar ~
26621 case 4: ...
26622  
26623 \newline 
26624 \SpecialChar ~
26625 \SpecialChar ~
26626 \SpecialChar ~
26627 case 8: ...\SpecialChar ~
26628 \SpecialChar ~
26629 \SpecialChar ~
26630 \SpecialChar ~
26631 \SpecialChar ~
26632 \SpecialChar ~
26633 \SpecialChar ~
26634 \SpecialChar ~
26635 \SpecialChar ~
26636 \SpecialChar ~
26637 \SpecialChar ~
26638 \SpecialChar ~
26639 \SpecialChar ~
26640 \SpecialChar ~
26641 \SpecialChar ~
26642 \SpecialChar ~
26643 \SpecialChar ~
26644 \SpecialChar ~
26645 \SpecialChar ~
26646 \SpecialChar ~
26647 \SpecialChar ~
26648 \SpecialChar ~
26649 \SpecialChar ~
26650 \SpecialChar ~
26651 \SpecialChar ~
26652 \SpecialChar ~
26653 case 5: ...
26654  
26655 \newline 
26656 \SpecialChar ~
26657 \SpecialChar ~
26658 \SpecialChar ~
26659 case 9: ...\SpecialChar ~
26660 \SpecialChar ~
26661 \SpecialChar ~
26662 \SpecialChar ~
26663 \SpecialChar ~
26664 \SpecialChar ~
26665 \SpecialChar ~
26666 \SpecialChar ~
26667 \SpecialChar ~
26668 \SpecialChar ~
26669 \SpecialChar ~
26670 \SpecialChar ~
26671 \SpecialChar ~
26672 \SpecialChar ~
26673 \SpecialChar ~
26674 \SpecialChar ~
26675 \SpecialChar ~
26676 \SpecialChar ~
26677 \SpecialChar ~
26678 \SpecialChar ~
26679 \SpecialChar ~
26680 \SpecialChar ~
26681 \SpecialChar ~
26682 \SpecialChar ~
26683 \SpecialChar ~
26684 \SpecialChar ~
26685 case 6: ...
26686  
26687 \newline 
26688 \SpecialChar ~
26689 \SpecialChar ~
26690 \SpecialChar ~
26691 case 10: ...\SpecialChar ~
26692 \SpecialChar ~
26693 \SpecialChar ~
26694 \SpecialChar ~
26695 \SpecialChar ~
26696 \SpecialChar ~
26697 \SpecialChar ~
26698 \SpecialChar ~
26699 \SpecialChar ~
26700 \SpecialChar ~
26701 \SpecialChar ~
26702 \SpecialChar ~
26703 \SpecialChar ~
26704 \SpecialChar ~
26705 \SpecialChar ~
26706 \SpecialChar ~
26707 \SpecialChar ~
26708 \SpecialChar ~
26709 \SpecialChar ~
26710 \SpecialChar ~
26711 \SpecialChar ~
26712 \SpecialChar ~
26713 \SpecialChar ~
26714 \SpecialChar ~
26715 \SpecialChar ~
26716 case 7: ...
26717  
26718 \newline 
26719 \SpecialChar ~
26720 \SpecialChar ~
26721 \SpecialChar ~
26722 case 11: ...\SpecialChar ~
26723 \SpecialChar ~
26724 \SpecialChar ~
26725 \SpecialChar ~
26726 \SpecialChar ~
26727 \SpecialChar ~
26728 \SpecialChar ~
26729 \SpecialChar ~
26730 \SpecialChar ~
26731 \SpecialChar ~
26732 \SpecialChar ~
26733 \SpecialChar ~
26734 \SpecialChar ~
26735 \SpecialChar ~
26736 \SpecialChar ~
26737 \SpecialChar ~
26738 \SpecialChar ~
26739 \SpecialChar ~
26740 \SpecialChar ~
26741 \SpecialChar ~
26742 \SpecialChar ~
26743 \SpecialChar ~
26744 \SpecialChar ~
26745 \SpecialChar ~
26746 \SpecialChar ~
26747 case 8: ...
26748  
26749 \newline 
26750 }\SpecialChar ~
26751 \SpecialChar ~
26752 \SpecialChar ~
26753 \SpecialChar ~
26754 \SpecialChar ~
26755 \SpecialChar ~
26756 \SpecialChar ~
26757 \SpecialChar ~
26758 \SpecialChar ~
26759 \SpecialChar ~
26760 \SpecialChar ~
26761 \SpecialChar ~
26762 \SpecialChar ~
26763 \SpecialChar ~
26764 \SpecialChar ~
26765 \SpecialChar ~
26766 \SpecialChar ~
26767 \SpecialChar ~
26768 \SpecialChar ~
26769 \SpecialChar ~
26770 \SpecialChar ~
26771 \SpecialChar ~
26772 \SpecialChar ~
26773 \SpecialChar ~
26774 \SpecialChar ~
26775 \SpecialChar ~
26776 \SpecialChar ~
26777 \SpecialChar ~
26778 \SpecialChar ~
26779 \SpecialChar ~
26780 \SpecialChar ~
26781 \SpecialChar ~
26782 \SpecialChar ~
26783 \SpecialChar ~
26784 \SpecialChar ~
26785 \SpecialChar ~
26786 }
26787 \layout Standard
26788
26789 Both the above switch statements will be implemented using a jump-table.
26790  The example to the right side is slightly more efficient as the check for
26791  the lower boundary of the jump-table is not needed.
26792 \end_deeper 
26793 \layout Itemize
26794
26795 The number of case labels is not larger than supported by the target architectur
26796 e.
26797 \layout Itemize
26798
26799 If the case labels are not in numerical sequence ('gaps' between cases)
26800  SDCC checks whether a jump table with additionally inserted dummy cases
26801  is still attractive.
26802  
26803 \layout Itemize
26804
26805 If the starting number is not zero and a check for the lower boundary of
26806  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
26807  ...
26808  .
26809 \layout Standard
26810
26811 Switch statements which have large gaps in the numeric sequence or those
26812  that have too many case labels can be split into more than one switch statement
26813  for efficient code generation, e.g.:
26814 \layout Verse
26815
26816
26817 \family typewriter 
26818 switch (i) { 
26819 \newline 
26820 \SpecialChar ~
26821 \SpecialChar ~
26822 case 1: ...
26823  
26824 \newline 
26825 \SpecialChar ~
26826 \SpecialChar ~
26827 case 2: ...
26828  
26829 \newline 
26830 \SpecialChar ~
26831 \SpecialChar ~
26832 case 3: ...
26833  
26834 \newline 
26835 \SpecialChar ~
26836 \SpecialChar ~
26837 case 4: ...
26838  
26839 \newline 
26840 \SpecialChar ~
26841 \SpecialChar ~
26842 case 5: ...
26843  
26844 \newline 
26845 \SpecialChar ~
26846 \SpecialChar ~
26847 case 6: ...
26848  
26849 \newline 
26850 \SpecialChar ~
26851 \SpecialChar ~
26852 case 7: ...
26853  
26854 \newline 
26855 \SpecialChar ~
26856 \SpecialChar ~
26857 case 101: ...
26858  
26859 \newline 
26860 \SpecialChar ~
26861 \SpecialChar ~
26862 case 102: ...
26863  
26864 \newline 
26865 \SpecialChar ~
26866 \SpecialChar ~
26867 case 103: ...
26868  
26869 \newline 
26870 \SpecialChar ~
26871 \SpecialChar ~
26872 case 104: ...
26873  
26874 \newline 
26875 \SpecialChar ~
26876 \SpecialChar ~
26877 case 105: ...
26878  
26879 \newline 
26880 \SpecialChar ~
26881 \SpecialChar ~
26882 case 106: ...
26883  
26884 \newline 
26885 \SpecialChar ~
26886 \SpecialChar ~
26887 case 107: ...
26888  
26889 \newline 
26890 }
26891 \layout Standard
26892
26893 If the above switch statement is broken down into two switch statements
26894 \layout Verse
26895
26896
26897 \family typewriter 
26898 switch (i) { 
26899 \newline 
26900 \SpecialChar ~
26901 \SpecialChar ~
26902 case 1: ...
26903  
26904 \newline 
26905 \SpecialChar ~
26906 \SpecialChar ~
26907 case 2: ...
26908  
26909 \newline 
26910 \SpecialChar ~
26911 \SpecialChar ~
26912 case 3: ...
26913  
26914 \newline 
26915 \SpecialChar ~
26916 \SpecialChar ~
26917 case 4: ...
26918  
26919 \newline 
26920 \SpecialChar ~
26921 \SpecialChar ~
26922 case 5: ...
26923  
26924 \newline 
26925 \SpecialChar ~
26926 \SpecialChar ~
26927 case 6: ...
26928  
26929 \newline 
26930 \SpecialChar ~
26931 \SpecialChar ~
26932 case 7: ...
26933  
26934 \newline 
26935 }
26936 \layout Standard
26937
26938 and
26939 \layout Verse
26940
26941
26942 \family typewriter 
26943 switch (i) { 
26944 \newline 
26945 \SpecialChar ~
26946 \SpecialChar ~
26947 case 101: ...
26948  
26949 \newline 
26950 \SpecialChar ~
26951 \SpecialChar ~
26952 case 102: ...
26953  
26954 \newline 
26955 \SpecialChar ~
26956 \SpecialChar ~
26957 case 103: ...
26958  
26959 \newline 
26960 \SpecialChar ~
26961 \SpecialChar ~
26962 case 104: ...
26963  
26964 \newline 
26965 \SpecialChar ~
26966 \SpecialChar ~
26967 case 105: ...
26968  
26969 \newline 
26970 \SpecialChar ~
26971 \SpecialChar ~
26972 case 106: ...
26973  
26974 \newline 
26975 \SpecialChar ~
26976 \SpecialChar ~
26977 case 107: ...
26978  
26979 \newline 
26980 }
26981 \layout Standard
26982
26983 then both the switch statements will be implemented using jump-tables whereas
26984  the unmodified switch statement will not be.
26985 \layout Comment
26986
26987 There might be reasons which SDCC cannot know about to either favour or
26988  not favour jump tables.
26989  If the target system has to be as quick for the last switch case as for
26990  the first (pro jump table), or if the switch argument is known to be zero
26991  in the majority of the cases (contra jump table).
26992 \layout Standard
26993
26994 The pragma nojtbound
26995 \begin_inset LatexCommand \index{\#pragma nojtbound}
26996
26997 \end_inset 
26998
26999  can be used to turn off checking the 
27000 \emph on 
27001 j
27002 \emph default 
27003 ump 
27004 \emph on 
27005 t
27006 \emph default 
27007 able 
27008 \emph on 
27009 bound
27010 \emph default 
27011 aries.
27012  It has no effect if a default label is supplied.
27013  Use of this pragma is dangerous: if the switch
27014 \begin_inset LatexCommand \index{switch statement}
27015
27016 \end_inset 
27017
27018  argument is not matched by a case statement the processor will happily
27019  jump into Nirvana.
27020 \layout Subsection
27021
27022 Bit-shifting Operations
27023 \begin_inset LatexCommand \index{Bit shifting}
27024
27025 \end_inset 
27026
27027 .
27028 \layout Standard
27029
27030 Bit shifting is one of the most frequently used operation in embedded programmin
27031 g.
27032  SDCC tries to implement bit-shift operations in the most efficient way
27033  possible, e.g.:
27034 \layout Verse
27035
27036
27037 \family typewriter 
27038 unsigned char i;
27039 \newline 
27040 ...
27041  
27042 \newline 
27043 i >>= 4; 
27044 \newline 
27045 ...
27046 \layout Standard
27047
27048 generates the following code:
27049 \layout Verse
27050
27051
27052 \family typewriter 
27053 mov\SpecialChar ~
27054  a,_i 
27055 \newline 
27056 swap a 
27057 \newline 
27058 anl\SpecialChar ~
27059  a,#0x0f 
27060 \newline 
27061 mov\SpecialChar ~
27062  _i,a
27063 \layout Standard
27064
27065 In general SDCC will never setup a loop if the shift count is known.
27066  Another example:
27067 \layout Verse
27068
27069
27070 \family typewriter 
27071 unsigned int i; 
27072 \newline 
27073 ...
27074  
27075 \newline 
27076 i >>= 9; 
27077 \newline 
27078 ...
27079 \layout Standard
27080
27081 will generate:
27082 \layout Verse
27083
27084
27085 \family typewriter 
27086 mov\SpecialChar ~
27087 \SpecialChar ~
27088 a,(_i + 1) 
27089 \newline 
27090 mov\SpecialChar ~
27091 \SpecialChar ~
27092 (_i + 1),#0x00 
27093 \newline 
27094 clr\SpecialChar ~
27095 \SpecialChar ~
27096
27097 \newline 
27098 rrc\SpecialChar ~
27099 \SpecialChar ~
27100
27101 \newline 
27102 mov\SpecialChar ~
27103 \SpecialChar ~
27104 _i,a
27105 \layout Subsection
27106
27107 Bit-rotation
27108 \begin_inset LatexCommand \index{Bit rotation}
27109
27110 \end_inset 
27111
27112
27113 \layout Standard
27114
27115 A special case of the bit-shift operation is bit rotation
27116 \begin_inset LatexCommand \index{rotating bits}
27117
27118 \end_inset 
27119
27120 , SDCC recognizes the following expression to be a left bit-rotation:
27121 \layout Verse
27122
27123
27124 \family typewriter 
27125 \series bold 
27126 unsigned
27127 \series default 
27128 \SpecialChar ~
27129 \SpecialChar ~
27130 char i;\SpecialChar ~
27131 \SpecialChar ~
27132 \SpecialChar ~
27133 \SpecialChar ~
27134 \SpecialChar ~
27135 \SpecialChar ~
27136 \SpecialChar ~
27137 \SpecialChar ~
27138 \SpecialChar ~
27139 \SpecialChar ~
27140 \SpecialChar ~
27141 /* unsigned is needed for rotation */ 
27142 \newline 
27143 ...
27144  
27145 \newline 
27146 i = ((i << 1) | (i >> 7)); 
27147 \family default 
27148
27149 \newline 
27150
27151 \family typewriter 
27152 ...
27153 \layout Standard
27154
27155 will generate the following code:
27156 \layout Verse
27157
27158
27159 \family typewriter 
27160 mov\SpecialChar ~
27161 \SpecialChar ~
27162 a,_i 
27163 \newline 
27164 rl\SpecialChar ~
27165 \SpecialChar ~
27166 \SpecialChar ~
27167
27168 \newline 
27169 mov\SpecialChar ~
27170 \SpecialChar ~
27171 _i,a
27172 \layout Standard
27173
27174 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27175 ns of this case will also be recognized as bit-rotation, i.e.: 
27176 \layout Verse
27177
27178
27179 \family typewriter 
27180 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27181 \layout Subsection
27182
27183 Nibble and Byte Swapping
27184 \layout Standard
27185
27186 Other special cases of the bit-shift operations are nibble or byte swapping
27187 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27188
27189 \end_inset 
27190
27191 , SDCC recognizes the following expressions:
27192 \layout Verse
27193
27194
27195 \family typewriter 
27196 \series bold 
27197 unsigned
27198 \series default 
27199 \SpecialChar ~
27200 \SpecialChar ~
27201 char i; 
27202 \newline 
27203
27204 \series bold 
27205 unsigned
27206 \series default 
27207 \SpecialChar ~
27208 \SpecialChar ~
27209 int j; 
27210 \newline 
27211 ...
27212  
27213 \newline 
27214 i = ((i << 4) | (i >> 4)); 
27215 \family default 
27216
27217 \newline 
27218
27219 \family typewriter 
27220 j = ((j << 8) | (j >> 8)); 
27221 \layout Standard
27222
27223 and generates a swap instruction for the nibble swapping
27224 \begin_inset LatexCommand \index{Nibble swapping}
27225
27226 \end_inset 
27227
27228  or move instructions for the byte swapping
27229 \begin_inset LatexCommand \index{Byte swapping}
27230
27231 \end_inset 
27232
27233 .
27234  The 
27235 \begin_inset Quotes sld
27236 \end_inset 
27237
27238 j
27239 \begin_inset Quotes srd
27240 \end_inset 
27241
27242  example can be used to convert from little to big-endian or vice versa.
27243  If you want to change the endianness of a 
27244 \emph on 
27245 signed
27246 \emph default 
27247  integer you have to cast to 
27248 \family typewriter 
27249 (unsigned int)
27250 \family default 
27251  first.
27252 \layout Standard
27253
27254 Note that SDCC stores numbers in little-endian
27255 \begin_inset Foot
27256 collapsed false
27257
27258 \layout Standard
27259
27260 Usually 8-bit processors don't care much about endianness.
27261  This is not the case for the standard 8051 which only has an instruction
27262  to increment its 
27263 \emph on 
27264 dptr
27265 \emph default 
27266
27267 \begin_inset LatexCommand \index{DPTR}
27268
27269 \end_inset 
27270
27271 -datapointer
27272 \emph on 
27273  
27274 \emph default 
27275 so little-endian is the more efficient byte order.
27276 \end_inset 
27277
27278
27279 \begin_inset LatexCommand \index{little-endian}
27280
27281 \end_inset 
27282
27283
27284 \begin_inset LatexCommand \index{Endianness}
27285
27286 \end_inset 
27287
27288  format (i.e.
27289  lowest order first).
27290 \layout Subsection
27291
27292 Highest Order Bit
27293 \begin_inset LatexCommand \index{Highest Order Bit}
27294
27295 \end_inset 
27296
27297  / Any Order Bit
27298 \begin_inset LatexCommand \index{Any Order Bit}
27299
27300 \end_inset 
27301
27302
27303 \layout Standard
27304
27305 It is frequently required to obtain the highest order bit of an integral
27306  type (long, int, short or char types).
27307  Also obtaining any other order bit is not uncommon.
27308  SDCC recognizes the following expressions to yield the highest order bit
27309  and generates optimized code for it, e.g.:
27310 \layout Verse
27311
27312
27313 \family typewriter 
27314 unsigned int gint; 
27315 \newline 
27316
27317 \newline 
27318 foo () { 
27319 \newline 
27320 \SpecialChar ~
27321 \SpecialChar ~
27322 unsigned char hob1, aob1; 
27323 \newline 
27324 \SpecialChar ~
27325 \SpecialChar ~
27326 bit hob2, hob3, aob2, aob3; 
27327 \newline 
27328 \SpecialChar ~
27329 \SpecialChar ~
27330 ...
27331  
27332 \newline 
27333 \SpecialChar ~
27334 \SpecialChar ~
27335 hob1 = (gint >> 15) & 1; 
27336 \newline 
27337 \SpecialChar ~
27338 \SpecialChar ~
27339 hob2 = (gint >> 15) & 1; 
27340 \newline 
27341 \SpecialChar ~
27342 \SpecialChar ~
27343 hob3 = gint & 0x8000; 
27344 \newline 
27345 \SpecialChar ~
27346 \SpecialChar ~
27347 aob1 = (gint >> 9) & 1; 
27348 \newline 
27349 \SpecialChar ~
27350 \SpecialChar ~
27351 aob2 = (gint >> 8) & 1; 
27352 \newline 
27353 \SpecialChar ~
27354 \SpecialChar ~
27355 aob3 = gint & 0x0800; 
27356 \newline 
27357 \SpecialChar ~
27358 \SpecialChar ~
27359 ..
27360  
27361 \newline 
27362 }
27363 \layout Standard
27364
27365 will generate the following code:
27366 \layout Verse
27367
27368
27369 \family typewriter 
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 \SpecialChar ~
27385 \SpecialChar ~
27386 \SpecialChar ~
27387 \SpecialChar ~
27388 \SpecialChar ~
27389 \SpecialChar ~
27390 \SpecialChar ~
27391 \SpecialChar ~
27392 \SpecialChar ~
27393 \SpecialChar ~
27394 \SpecialChar ~
27395  61 ;\SpecialChar ~
27396  hob.c 7 
27397 \newline 
27398 000A E5*01\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  62\SpecialChar ~
27414 \SpecialChar ~
27415 \SpecialChar ~
27416 \SpecialChar ~
27417 \SpecialChar ~
27418 \SpecialChar ~
27419 \SpecialChar ~
27420 \SpecialChar ~
27421  mov\SpecialChar ~
27422 \SpecialChar ~
27423  a,(_gint + 1) 
27424 \newline 
27425 000C 23\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  63\SpecialChar ~
27444 \SpecialChar ~
27445 \SpecialChar ~
27446 \SpecialChar ~
27447 \SpecialChar ~
27448 \SpecialChar ~
27449 \SpecialChar ~
27450 \SpecialChar ~
27451  rl\SpecialChar ~
27452 \SpecialChar ~
27453 \SpecialChar ~
27454  a 
27455 \newline 
27456 000D 54 01\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  64\SpecialChar ~
27472 \SpecialChar ~
27473 \SpecialChar ~
27474 \SpecialChar ~
27475 \SpecialChar ~
27476 \SpecialChar ~
27477 \SpecialChar ~
27478 \SpecialChar ~
27479  anl\SpecialChar ~
27480 \SpecialChar ~
27481  a,#0x01 
27482 \newline 
27483 000F F5*02\SpecialChar ~
27484 \SpecialChar ~
27485 \SpecialChar ~
27486 \SpecialChar ~
27487 \SpecialChar ~
27488 \SpecialChar ~
27489 \SpecialChar ~
27490 \SpecialChar ~
27491 \SpecialChar ~
27492 \SpecialChar ~
27493 \SpecialChar ~
27494 \SpecialChar ~
27495 \SpecialChar ~
27496 \SpecialChar ~
27497 \SpecialChar ~
27498  65\SpecialChar ~
27499 \SpecialChar ~
27500 \SpecialChar ~
27501 \SpecialChar ~
27502 \SpecialChar ~
27503 \SpecialChar ~
27504 \SpecialChar ~
27505 \SpecialChar ~
27506  mov\SpecialChar ~
27507 \SpecialChar ~
27508  _foo_hob1_1_1,a 
27509 \newline 
27510 \SpecialChar ~
27511 \SpecialChar ~
27512 \SpecialChar ~
27513 \SpecialChar ~
27514 \SpecialChar ~
27515 \SpecialChar ~
27516 \SpecialChar ~
27517 \SpecialChar ~
27518 \SpecialChar ~
27519 \SpecialChar ~
27520 \SpecialChar ~
27521 \SpecialChar ~
27522 \SpecialChar ~
27523 \SpecialChar ~
27524 \SpecialChar ~
27525 \SpecialChar ~
27526 \SpecialChar ~
27527 \SpecialChar ~
27528 \SpecialChar ~
27529 \SpecialChar ~
27530 \SpecialChar ~
27531 \SpecialChar ~
27532 \SpecialChar ~
27533 \SpecialChar ~
27534 \SpecialChar ~
27535  66 ;\SpecialChar ~
27536  hob.c 8 
27537 \newline 
27538 0011 E5*01\SpecialChar ~
27539 \SpecialChar ~
27540 \SpecialChar ~
27541 \SpecialChar ~
27542 \SpecialChar ~
27543 \SpecialChar ~
27544 \SpecialChar ~
27545 \SpecialChar ~
27546 \SpecialChar ~
27547 \SpecialChar ~
27548 \SpecialChar ~
27549 \SpecialChar ~
27550 \SpecialChar ~
27551 \SpecialChar ~
27552 \SpecialChar ~
27553  67\SpecialChar ~
27554 \SpecialChar ~
27555 \SpecialChar ~
27556 \SpecialChar ~
27557 \SpecialChar ~
27558 \SpecialChar ~
27559 \SpecialChar ~
27560 \SpecialChar ~
27561  mov\SpecialChar ~
27562 \SpecialChar ~
27563  a,(_gint + 1) 
27564 \newline 
27565 0013 33\SpecialChar ~
27566 \SpecialChar ~
27567 \SpecialChar ~
27568 \SpecialChar ~
27569 \SpecialChar ~
27570 \SpecialChar ~
27571 \SpecialChar ~
27572 \SpecialChar ~
27573 \SpecialChar ~
27574 \SpecialChar ~
27575 \SpecialChar ~
27576 \SpecialChar ~
27577 \SpecialChar ~
27578 \SpecialChar ~
27579 \SpecialChar ~
27580 \SpecialChar ~
27581 \SpecialChar ~
27582 \SpecialChar ~
27583  68\SpecialChar ~
27584 \SpecialChar ~
27585 \SpecialChar ~
27586 \SpecialChar ~
27587 \SpecialChar ~
27588 \SpecialChar ~
27589 \SpecialChar ~
27590 \SpecialChar ~
27591  rlc\SpecialChar ~
27592 \SpecialChar ~
27593  a 
27594 \newline 
27595 0014 92*00\SpecialChar ~
27596 \SpecialChar ~
27597 \SpecialChar ~
27598 \SpecialChar ~
27599 \SpecialChar ~
27600 \SpecialChar ~
27601 \SpecialChar ~
27602 \SpecialChar ~
27603 \SpecialChar ~
27604 \SpecialChar ~
27605 \SpecialChar ~
27606 \SpecialChar ~
27607 \SpecialChar ~
27608 \SpecialChar ~
27609 \SpecialChar ~
27610  69\SpecialChar ~
27611 \SpecialChar ~
27612 \SpecialChar ~
27613 \SpecialChar ~
27614 \SpecialChar ~
27615 \SpecialChar ~
27616 \SpecialChar ~
27617 \SpecialChar ~
27618  mov\SpecialChar ~
27619 \SpecialChar ~
27620  _foo_hob2_1_1,c 
27621 \newline 
27622 \SpecialChar ~
27623 \SpecialChar ~
27624 \SpecialChar ~
27625 \SpecialChar ~
27626 \SpecialChar ~
27627 \SpecialChar ~
27628 \SpecialChar ~
27629 \SpecialChar ~
27630 \SpecialChar ~
27631 \SpecialChar ~
27632 \SpecialChar ~
27633 \SpecialChar ~
27634 \SpecialChar ~
27635 \SpecialChar ~
27636 \SpecialChar ~
27637 \SpecialChar ~
27638 \SpecialChar ~
27639 \SpecialChar ~
27640 \SpecialChar ~
27641 \SpecialChar ~
27642 \SpecialChar ~
27643 \SpecialChar ~
27644 \SpecialChar ~
27645 \SpecialChar ~
27646 \SpecialChar ~
27647  66 ;\SpecialChar ~
27648  hob.c 9 
27649 \newline 
27650 0016 E5*01\SpecialChar ~
27651 \SpecialChar ~
27652 \SpecialChar ~
27653 \SpecialChar ~
27654 \SpecialChar ~
27655 \SpecialChar ~
27656 \SpecialChar ~
27657 \SpecialChar ~
27658 \SpecialChar ~
27659 \SpecialChar ~
27660 \SpecialChar ~
27661 \SpecialChar ~
27662 \SpecialChar ~
27663 \SpecialChar ~
27664 \SpecialChar ~
27665  67\SpecialChar ~
27666 \SpecialChar ~
27667 \SpecialChar ~
27668 \SpecialChar ~
27669 \SpecialChar ~
27670 \SpecialChar ~
27671 \SpecialChar ~
27672 \SpecialChar ~
27673  mov\SpecialChar ~
27674 \SpecialChar ~
27675  a,(_gint + 1) 
27676 \newline 
27677 0018 33\SpecialChar ~
27678 \SpecialChar ~
27679 \SpecialChar ~
27680 \SpecialChar ~
27681 \SpecialChar ~
27682 \SpecialChar ~
27683 \SpecialChar ~
27684 \SpecialChar ~
27685 \SpecialChar ~
27686 \SpecialChar ~
27687 \SpecialChar ~
27688 \SpecialChar ~
27689 \SpecialChar ~
27690 \SpecialChar ~
27691 \SpecialChar ~
27692 \SpecialChar ~
27693 \SpecialChar ~
27694 \SpecialChar ~
27695  68\SpecialChar ~
27696 \SpecialChar ~
27697 \SpecialChar ~
27698 \SpecialChar ~
27699 \SpecialChar ~
27700 \SpecialChar ~
27701 \SpecialChar ~
27702 \SpecialChar ~
27703  rlc\SpecialChar ~
27704 \SpecialChar ~
27705  a 
27706 \newline 
27707 0019 92*01\SpecialChar ~
27708 \SpecialChar ~
27709 \SpecialChar ~
27710 \SpecialChar ~
27711 \SpecialChar ~
27712 \SpecialChar ~
27713 \SpecialChar ~
27714 \SpecialChar ~
27715 \SpecialChar ~
27716 \SpecialChar ~
27717 \SpecialChar ~
27718 \SpecialChar ~
27719 \SpecialChar ~
27720 \SpecialChar ~
27721 \SpecialChar ~
27722  69\SpecialChar ~
27723 \SpecialChar ~
27724 \SpecialChar ~
27725 \SpecialChar ~
27726 \SpecialChar ~
27727 \SpecialChar ~
27728 \SpecialChar ~
27729 \SpecialChar ~
27730  mov\SpecialChar ~
27731 \SpecialChar ~
27732  _foo_hob3_1_1,c 
27733 \newline 
27734 \SpecialChar ~
27735 \SpecialChar ~
27736 \SpecialChar ~
27737 \SpecialChar ~
27738 \SpecialChar ~
27739 \SpecialChar ~
27740 \SpecialChar ~
27741 \SpecialChar ~
27742 \SpecialChar ~
27743 \SpecialChar ~
27744 \SpecialChar ~
27745 \SpecialChar ~
27746 \SpecialChar ~
27747 \SpecialChar ~
27748 \SpecialChar ~
27749 \SpecialChar ~
27750 \SpecialChar ~
27751 \SpecialChar ~
27752 \SpecialChar ~
27753 \SpecialChar ~
27754 \SpecialChar ~
27755 \SpecialChar ~
27756 \SpecialChar ~
27757 \SpecialChar ~
27758 \SpecialChar ~
27759  70 ;\SpecialChar ~
27760  hob.c 10 
27761 \newline 
27762 001B E5*01\SpecialChar ~
27763 \SpecialChar ~
27764 \SpecialChar ~
27765 \SpecialChar ~
27766 \SpecialChar ~
27767 \SpecialChar ~
27768 \SpecialChar ~
27769 \SpecialChar ~
27770 \SpecialChar ~
27771 \SpecialChar ~
27772 \SpecialChar ~
27773 \SpecialChar ~
27774 \SpecialChar ~
27775 \SpecialChar ~
27776 \SpecialChar ~
27777  71\SpecialChar ~
27778 \SpecialChar ~
27779 \SpecialChar ~
27780 \SpecialChar ~
27781 \SpecialChar ~
27782 \SpecialChar ~
27783 \SpecialChar ~
27784 \SpecialChar ~
27785  mov\SpecialChar ~
27786 \SpecialChar ~
27787  a,(_gint + 1) 
27788 \newline 
27789 001D 03\SpecialChar ~
27790 \SpecialChar ~
27791 \SpecialChar ~
27792 \SpecialChar ~
27793 \SpecialChar ~
27794 \SpecialChar ~
27795 \SpecialChar ~
27796 \SpecialChar ~
27797 \SpecialChar ~
27798 \SpecialChar ~
27799 \SpecialChar ~
27800 \SpecialChar ~
27801 \SpecialChar ~
27802 \SpecialChar ~
27803 \SpecialChar ~
27804 \SpecialChar ~
27805 \SpecialChar ~
27806 \SpecialChar ~
27807  72\SpecialChar ~
27808 \SpecialChar ~
27809 \SpecialChar ~
27810 \SpecialChar ~
27811 \SpecialChar ~
27812 \SpecialChar ~
27813 \SpecialChar ~
27814 \SpecialChar ~
27815  rr\SpecialChar ~
27816 \SpecialChar ~
27817 \SpecialChar ~
27818  a 
27819 \newline 
27820 001E 54 01\SpecialChar ~
27821 \SpecialChar ~
27822 \SpecialChar ~
27823 \SpecialChar ~
27824 \SpecialChar ~
27825 \SpecialChar ~
27826 \SpecialChar ~
27827 \SpecialChar ~
27828 \SpecialChar ~
27829 \SpecialChar ~
27830 \SpecialChar ~
27831 \SpecialChar ~
27832 \SpecialChar ~
27833 \SpecialChar ~
27834 \SpecialChar ~
27835  73\SpecialChar ~
27836 \SpecialChar ~
27837 \SpecialChar ~
27838 \SpecialChar ~
27839 \SpecialChar ~
27840 \SpecialChar ~
27841 \SpecialChar ~
27842 \SpecialChar ~
27843  anl\SpecialChar ~
27844 \SpecialChar ~
27845  a,#0x01 
27846 \newline 
27847 0020 F5*03\SpecialChar ~
27848 \SpecialChar ~
27849 \SpecialChar ~
27850 \SpecialChar ~
27851 \SpecialChar ~
27852 \SpecialChar ~
27853 \SpecialChar ~
27854 \SpecialChar ~
27855 \SpecialChar ~
27856 \SpecialChar ~
27857 \SpecialChar ~
27858 \SpecialChar ~
27859 \SpecialChar ~
27860 \SpecialChar ~
27861 \SpecialChar ~
27862  74\SpecialChar ~
27863 \SpecialChar ~
27864 \SpecialChar ~
27865 \SpecialChar ~
27866 \SpecialChar ~
27867 \SpecialChar ~
27868 \SpecialChar ~
27869 \SpecialChar ~
27870  mov\SpecialChar ~
27871 \SpecialChar ~
27872  _foo_aob1_1_1,a 
27873 \newline 
27874 \SpecialChar ~
27875 \SpecialChar ~
27876 \SpecialChar ~
27877 \SpecialChar ~
27878 \SpecialChar ~
27879 \SpecialChar ~
27880 \SpecialChar ~
27881 \SpecialChar ~
27882 \SpecialChar ~
27883 \SpecialChar ~
27884 \SpecialChar ~
27885 \SpecialChar ~
27886 \SpecialChar ~
27887 \SpecialChar ~
27888 \SpecialChar ~
27889 \SpecialChar ~
27890 \SpecialChar ~
27891 \SpecialChar ~
27892 \SpecialChar ~
27893 \SpecialChar ~
27894 \SpecialChar ~
27895 \SpecialChar ~
27896 \SpecialChar ~
27897 \SpecialChar ~
27898 \SpecialChar ~
27899  75 ;\SpecialChar ~
27900  hob.c 11 
27901 \newline 
27902 0022 E5*01\SpecialChar ~
27903 \SpecialChar ~
27904 \SpecialChar ~
27905 \SpecialChar ~
27906 \SpecialChar ~
27907 \SpecialChar ~
27908 \SpecialChar ~
27909 \SpecialChar ~
27910 \SpecialChar ~
27911 \SpecialChar ~
27912 \SpecialChar ~
27913 \SpecialChar ~
27914 \SpecialChar ~
27915 \SpecialChar ~
27916 \SpecialChar ~
27917  76\SpecialChar ~
27918 \SpecialChar ~
27919 \SpecialChar ~
27920 \SpecialChar ~
27921 \SpecialChar ~
27922 \SpecialChar ~
27923 \SpecialChar ~
27924 \SpecialChar ~
27925  mov\SpecialChar ~
27926 \SpecialChar ~
27927  a,(_gint + 1) 
27928 \newline 
27929 0024 13\SpecialChar ~
27930 \SpecialChar ~
27931 \SpecialChar ~
27932 \SpecialChar ~
27933 \SpecialChar ~
27934 \SpecialChar ~
27935 \SpecialChar ~
27936 \SpecialChar ~
27937 \SpecialChar ~
27938 \SpecialChar ~
27939 \SpecialChar ~
27940 \SpecialChar ~
27941 \SpecialChar ~
27942 \SpecialChar ~
27943 \SpecialChar ~
27944 \SpecialChar ~
27945 \SpecialChar ~
27946 \SpecialChar ~
27947  77\SpecialChar ~
27948 \SpecialChar ~
27949 \SpecialChar ~
27950 \SpecialChar ~
27951 \SpecialChar ~
27952 \SpecialChar ~
27953 \SpecialChar ~
27954 \SpecialChar ~
27955  rrc\SpecialChar ~
27956 \SpecialChar ~
27957  a 
27958 \newline 
27959 0025 92*02\SpecialChar ~
27960 \SpecialChar ~
27961 \SpecialChar ~
27962 \SpecialChar ~
27963 \SpecialChar ~
27964 \SpecialChar ~
27965 \SpecialChar ~
27966 \SpecialChar ~
27967 \SpecialChar ~
27968 \SpecialChar ~
27969 \SpecialChar ~
27970 \SpecialChar ~
27971 \SpecialChar ~
27972 \SpecialChar ~
27973 \SpecialChar ~
27974  78\SpecialChar ~
27975 \SpecialChar ~
27976 \SpecialChar ~
27977 \SpecialChar ~
27978 \SpecialChar ~
27979 \SpecialChar ~
27980 \SpecialChar ~
27981 \SpecialChar ~
27982  mov\SpecialChar ~
27983 \SpecialChar ~
27984  _foo_aob2_1_1,c 
27985 \newline 
27986 \SpecialChar ~
27987 \SpecialChar ~
27988 \SpecialChar ~
27989 \SpecialChar ~
27990 \SpecialChar ~
27991 \SpecialChar ~
27992 \SpecialChar ~
27993 \SpecialChar ~
27994 \SpecialChar ~
27995 \SpecialChar ~
27996 \SpecialChar ~
27997 \SpecialChar ~
27998 \SpecialChar ~
27999 \SpecialChar ~
28000 \SpecialChar ~
28001 \SpecialChar ~
28002 \SpecialChar ~
28003 \SpecialChar ~
28004 \SpecialChar ~
28005 \SpecialChar ~
28006 \SpecialChar ~
28007 \SpecialChar ~
28008 \SpecialChar ~
28009 \SpecialChar ~
28010 \SpecialChar ~
28011  79 ;\SpecialChar ~
28012  hob.c 12 
28013 \newline 
28014 0027 E5*01\SpecialChar ~
28015 \SpecialChar ~
28016 \SpecialChar ~
28017 \SpecialChar ~
28018 \SpecialChar ~
28019 \SpecialChar ~
28020 \SpecialChar ~
28021 \SpecialChar ~
28022 \SpecialChar ~
28023 \SpecialChar ~
28024 \SpecialChar ~
28025 \SpecialChar ~
28026 \SpecialChar ~
28027 \SpecialChar ~
28028 \SpecialChar ~
28029  80\SpecialChar ~
28030 \SpecialChar ~
28031 \SpecialChar ~
28032 \SpecialChar ~
28033 \SpecialChar ~
28034 \SpecialChar ~
28035 \SpecialChar ~
28036 \SpecialChar ~
28037  mov\SpecialChar ~
28038 \SpecialChar ~
28039  a,(_gint + 1) 
28040 \newline 
28041 0029 A2 E3\SpecialChar ~
28042 \SpecialChar ~
28043 \SpecialChar ~
28044 \SpecialChar ~
28045 \SpecialChar ~
28046 \SpecialChar ~
28047 \SpecialChar ~
28048 \SpecialChar ~
28049 \SpecialChar ~
28050 \SpecialChar ~
28051 \SpecialChar ~
28052 \SpecialChar ~
28053 \SpecialChar ~
28054 \SpecialChar ~
28055 \SpecialChar ~
28056  81\SpecialChar ~
28057 \SpecialChar ~
28058 \SpecialChar ~
28059 \SpecialChar ~
28060 \SpecialChar ~
28061 \SpecialChar ~
28062 \SpecialChar ~
28063 \SpecialChar ~
28064  mov\SpecialChar ~
28065 \SpecialChar ~
28066  c,acc[3] 
28067 \newline 
28068 002B 92*03\SpecialChar ~
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  82\SpecialChar ~
28084 \SpecialChar ~
28085 \SpecialChar ~
28086 \SpecialChar ~
28087 \SpecialChar ~
28088 \SpecialChar ~
28089 \SpecialChar ~
28090 \SpecialChar ~
28091  mov\SpecialChar ~
28092 \SpecialChar ~
28093  _foo_aob3_1_1,c 
28094 \layout Standard
28095
28096 Other variations of these cases however will 
28097 \emph on 
28098 not
28099 \emph default 
28100  be recognized.
28101  They are standard C expressions, so I heartily recommend these be the only
28102  way to get the highest order bit, (it is portable).
28103  Of course it will be recognized even if it is embedded in other expressions,
28104  e.g.:
28105 \layout Verse
28106
28107
28108 \family typewriter 
28109 xyz = gint + ((gint >> 15) & 1);
28110 \layout Standard
28111
28112 will still be recognized.
28113 \layout Subsection
28114
28115 Higher Order Byte
28116 \begin_inset LatexCommand \index{Higher Order Byte}
28117
28118 \end_inset 
28119
28120  / Higher Order Word
28121 \begin_inset LatexCommand \index{Higher Order Word}
28122
28123 \end_inset 
28124
28125
28126 \layout Standard
28127
28128 It is also frequently required to obtain a higher order byte or word of
28129  a larger integral type (long, int or short types).
28130  SDCC recognizes the following expressions to yield the higher order byte
28131  or word and generates optimized code for it, e.g.:
28132 \layout Verse
28133
28134
28135 \family typewriter 
28136 unsigned int gint; 
28137 \newline 
28138 unsigned long int glong; 
28139 \newline 
28140
28141 \newline 
28142 foo () { 
28143 \newline 
28144 \SpecialChar ~
28145 \SpecialChar ~
28146 unsigned char hob1, hob2; 
28147 \newline 
28148 \SpecialChar ~
28149 \SpecialChar ~
28150 unsigned int how1, how2; 
28151 \newline 
28152 \SpecialChar ~
28153 \SpecialChar ~
28154 ...
28155  
28156 \newline 
28157 \SpecialChar ~
28158 \SpecialChar ~
28159 hob1 = (gint >> 8) & 0xFF; 
28160 \newline 
28161 \SpecialChar ~
28162 \SpecialChar ~
28163 hob2 = glong >> 24; 
28164 \newline 
28165 \SpecialChar ~
28166 \SpecialChar ~
28167 how1 = (glong >> 16) & 0xFFFF; 
28168 \newline 
28169 \SpecialChar ~
28170 \SpecialChar ~
28171 how2 = glong >> 8; 
28172 \newline 
28173 \SpecialChar ~
28174 \SpecialChar ~
28175 ..
28176  
28177 \newline 
28178 }
28179 \layout Standard
28180
28181 will generate the following code:
28182 \layout Verse
28183
28184
28185 \family typewriter 
28186 \SpecialChar ~
28187 \SpecialChar ~
28188 \SpecialChar ~
28189 \SpecialChar ~
28190 \SpecialChar ~
28191 \SpecialChar ~
28192 \SpecialChar ~
28193 \SpecialChar ~
28194 \SpecialChar ~
28195 \SpecialChar ~
28196 \SpecialChar ~
28197 \SpecialChar ~
28198 \SpecialChar ~
28199 \SpecialChar ~
28200 \SpecialChar ~
28201 \SpecialChar ~
28202 \SpecialChar ~
28203 \SpecialChar ~
28204 \SpecialChar ~
28205 \SpecialChar ~
28206 \SpecialChar ~
28207 \SpecialChar ~
28208 \SpecialChar ~
28209 \SpecialChar ~
28210 \SpecialChar ~
28211  91 ;\SpecialChar ~
28212  hob.c 15 
28213 \newline 
28214 0037 85*01*06\SpecialChar ~
28215 \SpecialChar ~
28216 \SpecialChar ~
28217 \SpecialChar ~
28218 \SpecialChar ~
28219 \SpecialChar ~
28220 \SpecialChar ~
28221 \SpecialChar ~
28222 \SpecialChar ~
28223 \SpecialChar ~
28224 \SpecialChar ~
28225 \SpecialChar ~
28226  92\SpecialChar ~
28227 \SpecialChar ~
28228 \SpecialChar ~
28229 \SpecialChar ~
28230 \SpecialChar ~
28231 \SpecialChar ~
28232 \SpecialChar ~
28233 \SpecialChar ~
28234  mov\SpecialChar ~
28235 \SpecialChar ~
28236  _foo_hob1_1_1,(_gint + 1) 
28237 \newline 
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 \SpecialChar ~
28253 \SpecialChar ~
28254 \SpecialChar ~
28255 \SpecialChar ~
28256 \SpecialChar ~
28257 \SpecialChar ~
28258 \SpecialChar ~
28259 \SpecialChar ~
28260 \SpecialChar ~
28261 \SpecialChar ~
28262 \SpecialChar ~
28263  93 ;\SpecialChar ~
28264  hob.c 16 
28265 \newline 
28266 003A 85*05*07\SpecialChar ~
28267 \SpecialChar ~
28268 \SpecialChar ~
28269 \SpecialChar ~
28270 \SpecialChar ~
28271 \SpecialChar ~
28272 \SpecialChar ~
28273 \SpecialChar ~
28274 \SpecialChar ~
28275 \SpecialChar ~
28276 \SpecialChar ~
28277 \SpecialChar ~
28278  94\SpecialChar ~
28279 \SpecialChar ~
28280 \SpecialChar ~
28281 \SpecialChar ~
28282 \SpecialChar ~
28283 \SpecialChar ~
28284 \SpecialChar ~
28285 \SpecialChar ~
28286  mov\SpecialChar ~
28287 \SpecialChar ~
28288  _foo_hob2_1_1,(_glong + 3) 
28289 \newline 
28290 \SpecialChar ~
28291 \SpecialChar ~
28292 \SpecialChar ~
28293 \SpecialChar ~
28294 \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 \SpecialChar ~
28310 \SpecialChar ~
28311 \SpecialChar ~
28312 \SpecialChar ~
28313 \SpecialChar ~
28314 \SpecialChar ~
28315  95 ;\SpecialChar ~
28316  hob.c 17 
28317 \newline 
28318 003D 85*04*08\SpecialChar ~
28319 \SpecialChar ~
28320 \SpecialChar ~
28321 \SpecialChar ~
28322 \SpecialChar ~
28323 \SpecialChar ~
28324 \SpecialChar ~
28325 \SpecialChar ~
28326 \SpecialChar ~
28327 \SpecialChar ~
28328 \SpecialChar ~
28329 \SpecialChar ~
28330  96\SpecialChar ~
28331 \SpecialChar ~
28332 \SpecialChar ~
28333 \SpecialChar ~
28334 \SpecialChar ~
28335 \SpecialChar ~
28336 \SpecialChar ~
28337 \SpecialChar ~
28338  mov\SpecialChar ~
28339 \SpecialChar ~
28340  _foo_how1_1_1,(_glong + 2) 
28341 \newline 
28342 0040 85*05*09\SpecialChar ~
28343 \SpecialChar ~
28344 \SpecialChar ~
28345 \SpecialChar ~
28346 \SpecialChar ~
28347 \SpecialChar ~
28348 \SpecialChar ~
28349 \SpecialChar ~
28350 \SpecialChar ~
28351 \SpecialChar ~
28352 \SpecialChar ~
28353 \SpecialChar ~
28354  97\SpecialChar ~
28355 \SpecialChar ~
28356 \SpecialChar ~
28357 \SpecialChar ~
28358 \SpecialChar ~
28359 \SpecialChar ~
28360 \SpecialChar ~
28361 \SpecialChar ~
28362  mov\SpecialChar ~
28363 \SpecialChar ~
28364  (_foo_how1_1_1 + 1),(_glong + 3) 
28365 \newline 
28366 0043 85*03*0A\SpecialChar ~
28367 \SpecialChar ~
28368 \SpecialChar ~
28369 \SpecialChar ~
28370 \SpecialChar ~
28371 \SpecialChar ~
28372 \SpecialChar ~
28373 \SpecialChar ~
28374 \SpecialChar ~
28375 \SpecialChar ~
28376 \SpecialChar ~
28377 \SpecialChar ~
28378  98\SpecialChar ~
28379 \SpecialChar ~
28380 \SpecialChar ~
28381 \SpecialChar ~
28382 \SpecialChar ~
28383 \SpecialChar ~
28384 \SpecialChar ~
28385 \SpecialChar ~
28386  mov\SpecialChar ~
28387 \SpecialChar ~
28388  _foo_how2_1_1,(_glong + 1) 
28389 \newline 
28390 0046 85*04*0B\SpecialChar ~
28391 \SpecialChar ~
28392 \SpecialChar ~
28393 \SpecialChar ~
28394 \SpecialChar ~
28395 \SpecialChar ~
28396 \SpecialChar ~
28397 \SpecialChar ~
28398 \SpecialChar ~
28399 \SpecialChar ~
28400 \SpecialChar ~
28401 \SpecialChar ~
28402  99\SpecialChar ~
28403 \SpecialChar ~
28404 \SpecialChar ~
28405 \SpecialChar ~
28406 \SpecialChar ~
28407 \SpecialChar ~
28408 \SpecialChar ~
28409 \SpecialChar ~
28410  mov\SpecialChar ~
28411 \SpecialChar ~
28412  (_foo_how2_1_1 + 1),(_glong + 2) 
28413 \layout Standard
28414
28415 Again, variations of these cases may 
28416 \emph on 
28417 not
28418 \emph default 
28419  be recognized.
28420  They are standard C expressions, so I heartily recommend these be the only
28421  way to get the higher order byte/word, (it is portable).
28422  Of course it will be recognized even if it is embedded in other expressions,
28423  e.g.:
28424 \layout Verse
28425
28426
28427 \family typewriter 
28428 xyz = gint + ((gint >> 8) & 0xFF);
28429 \layout Standard
28430
28431 will still be recognized.
28432 \layout Subsection
28433
28434 Peephole Optimizer
28435 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
28436
28437 \end_inset 
28438
28439
28440 \begin_inset LatexCommand \index{Peephole optimizer}
28441
28442 \end_inset 
28443
28444
28445 \layout Standard
28446
28447 The compiler uses a rule based, pattern matching and re-writing mechanism
28448  for peep-hole optimization.
28449  It is inspired by 
28450 \emph on 
28451 copt
28452 \emph default 
28453  a peep-hole optimizer by Christopher W.
28454  Fraser (cwfraser\SpecialChar ~
28455 @\SpecialChar ~
28456 microsoft.com).
28457  A default set of rules are compiled into the compiler, additional rules
28458  may be added with the 
28459 \emph on 
28460 -
28461 \begin_inset ERT
28462 status Collapsed
28463
28464 \layout Standard
28465
28466 \backslash 
28467 /
28468 \end_inset 
28469
28470 -peep-file
28471 \begin_inset LatexCommand \index{-\/-peep-file}
28472
28473 \end_inset 
28474
28475  <filename>
28476 \emph default 
28477  option.
28478  The rule language is best illustrated with examples.
28479 \layout Verse
28480
28481
28482 \family typewriter 
28483 replace { 
28484 \newline 
28485 \SpecialChar ~
28486 \SpecialChar ~
28487 mov %1,a 
28488 \newline 
28489 \SpecialChar ~
28490 \SpecialChar ~
28491 mov a,%1
28492 \newline 
28493 } by {
28494 \newline 
28495 \SpecialChar ~
28496 \SpecialChar ~
28497 mov %1,a
28498 \newline 
28499 }
28500 \layout Standard
28501
28502 The above rule will change the following assembly
28503 \begin_inset LatexCommand \index{Assembler routines}
28504
28505 \end_inset 
28506
28507  sequence:
28508 \layout Verse
28509
28510
28511 \family typewriter 
28512 mov r1,a 
28513 \newline 
28514 mov a,r1
28515 \layout Standard
28516
28517 to
28518 \layout Verse
28519
28520
28521 \family typewriter 
28522 mov r1,a
28523 \layout Standard
28524
28525 Note: All occurrences of a 
28526 \emph on 
28527 %n
28528 \emph default 
28529  (pattern variable) must denote the same string.
28530  With the above rule, the assembly sequence:
28531 \layout Verse
28532
28533
28534 \family typewriter 
28535 mov r1,a 
28536 \newline 
28537 mov a,r2
28538 \layout Standard
28539
28540 will remain unmodified.
28541 \newline 
28542
28543 \newline 
28544 Other special case optimizations may be added by the user (via 
28545 \emph on 
28546 -
28547 \begin_inset ERT
28548 status Collapsed
28549
28550 \layout Standard
28551
28552 \backslash 
28553 /
28554 \end_inset 
28555
28556 -peep-file option
28557 \emph default 
28558 ).
28559  E.g.
28560  some variants of the 8051 MCU
28561 \begin_inset LatexCommand \index{MCS51 variants}
28562
28563 \end_inset 
28564
28565  allow only 
28566 \family typewriter 
28567 ajmp
28568 \family default 
28569  and 
28570 \family typewriter 
28571 acall
28572 \family default 
28573 .
28574  The following two rules will change all 
28575 \family typewriter 
28576 ljmp
28577 \family default 
28578  and 
28579 \family typewriter 
28580 lcall
28581 \family default 
28582  to 
28583 \family typewriter 
28584 ajmp
28585 \family default 
28586  and 
28587 \family typewriter 
28588 acall
28589 \layout Verse
28590
28591
28592 \family typewriter 
28593 replace { lcall %1 } by { acall %1 } 
28594 \newline 
28595 replace { ljmp %1 } by { ajmp %1 }
28596 \layout Standard
28597
28598 The 
28599 \emph on 
28600 inline-assembler code
28601 \emph default 
28602  is also passed through the peep hole optimizer, thus the peephole optimizer
28603  can also be used as an assembly level macro expander.
28604  The rules themselves are MCU dependent whereas the rule language infra-structur
28605 e is MCU independent.
28606  Peephole optimization rules for other MCU can be easily programmed using
28607  the rule language.
28608 \newline 
28609
28610 \newline 
28611 The syntax for a rule is as follows:
28612 \layout Verse
28613
28614
28615 \family typewriter 
28616 rule := replace [ restart ] '{' <assembly sequence> '
28617 \backslash 
28618 n' 
28619 \newline 
28620 \SpecialChar ~
28621  \SpecialChar ~
28622  \SpecialChar ~
28623  \SpecialChar ~
28624  \SpecialChar ~
28625  \SpecialChar ~
28626  \SpecialChar ~
28627  \SpecialChar ~
28628  \SpecialChar ~
28629  \SpecialChar ~
28630  \SpecialChar ~
28631  \SpecialChar ~
28632  \SpecialChar ~
28633  \SpecialChar ~
28634  '}' by '{' '
28635 \backslash 
28636 n' 
28637 \newline 
28638 \SpecialChar ~
28639  \SpecialChar ~
28640  \SpecialChar ~
28641  \SpecialChar ~
28642  \SpecialChar ~
28643  \SpecialChar ~
28644  \SpecialChar ~
28645  \SpecialChar ~
28646  \SpecialChar ~
28647  \SpecialChar ~
28648  \SpecialChar ~
28649  \SpecialChar ~
28650  \SpecialChar ~
28651  \SpecialChar ~
28652  \SpecialChar ~
28653  \SpecialChar ~
28654  <assembly sequence> '
28655 \backslash 
28656 n' 
28657 \newline 
28658 \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  '}' [if <functionName> ] '
28673 \backslash 
28674 n' 
28675 \layout Standard
28676
28677 <assembly sequence> := assembly instruction (each instruction including
28678  labels must be on a separate line).
28679 \newline 
28680
28681 \newline 
28682 The optimizer will apply to the rules one by one from the top in the sequence
28683  of their appearance, it will terminate when all rules are exhausted.
28684  If the 'restart' option is specified, then the optimizer will start matching
28685  the rules again from the top, this option for a rule is expensive (performance)
28686 , it is intended to be used in situations where a transformation will trigger
28687  the same rule again.
28688  An example of this (not a good one, it has side effects) is the following
28689  rule:
28690 \layout Verse
28691
28692
28693 \family typewriter 
28694 replace restart { 
28695 \newline 
28696 \SpecialChar ~
28697 \SpecialChar ~
28698 pop %1 
28699 \newline 
28700 \SpecialChar ~
28701 \SpecialChar ~
28702 push %1 } by { 
28703 \newline 
28704 \SpecialChar ~
28705 \SpecialChar ~
28706 ; nop 
28707 \newline 
28708 }
28709 \layout Standard
28710
28711 Note that the replace pattern cannot be a blank, but can be a comment line.
28712  Without the 'restart' option only the innermost 'pop' 'push' pair would
28713  be eliminated, i.e.:
28714 \layout Verse
28715
28716
28717 \family typewriter 
28718 pop ar1 
28719 \newline 
28720 pop ar2 
28721 \newline 
28722 push ar2 
28723 \newline 
28724 push ar1
28725 \layout Standard
28726
28727 would result in:
28728 \layout Verse
28729
28730
28731 \family typewriter 
28732 pop ar1 
28733 \newline 
28734 ; nop 
28735 \newline 
28736 push ar1
28737 \layout Standard
28738
28739
28740 \emph on 
28741 with
28742 \emph default 
28743  the restart option the rule will be applied again to the resulting code
28744  and then all the pop-push pairs will be eliminated to yield:
28745 \layout Verse
28746
28747
28748 \family typewriter 
28749 ; nop 
28750 \newline 
28751 ; nop
28752 \layout Standard
28753
28754 A conditional function can be attached to a rule.
28755  Attaching rules are somewhat more involved, let me illustrate this with
28756  an example.
28757 \layout Verse
28758
28759
28760 \family typewriter 
28761 replace { 
28762 \newline 
28763 \SpecialChar ~
28764  \SpecialChar ~
28765  \SpecialChar ~
28766 ljmp %5 
28767 \newline 
28768 %2:
28769 \newline 
28770 } by { 
28771 \newline 
28772 \SpecialChar ~
28773  \SpecialChar ~
28774  \SpecialChar ~
28775 sjmp %5 
28776 \newline 
28777 %2:
28778 \newline 
28779 } if labelInRange
28780 \layout Standard
28781
28782 The optimizer does a look-up of a function name table defined in function
28783  
28784 \emph on 
28785 callFuncByName
28786 \emph default 
28787  in the source file SDCCpeeph.c, with the name 
28788 \emph on 
28789 labelInRange
28790 \emph default 
28791 .
28792  If it finds a corresponding entry the function is called.
28793  Note there can be no parameters specified for these functions, in this
28794  case the use of 
28795 \emph on 
28796 %5
28797 \emph default 
28798  is crucial, since the function 
28799 \emph on 
28800 labelInRange
28801 \emph default 
28802  expects to find the label in that particular variable (the hash table containin
28803 g the variable bindings is passed as a parameter).
28804  If you want to code more such functions, take a close look at the function
28805  labelInRange and the calling mechanism in source file SDCCpeeph.c.
28806  Currently implemented are 
28807 \emph on 
28808 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
28809  24bitMode, portIsDS390, 24bitModeAndPortDS390 
28810 \emph default 
28811 and
28812 \emph on 
28813  notVolatile
28814 \emph default 
28815 .
28816 \layout Standard
28817
28818 I know this whole thing is a little kludgey, but maybe some day we will
28819  have some better means.
28820  If you are looking at this file, you will see the default rules that are
28821  compiled into the compiler, you can add your own rules in the default set
28822  there if you get tired of specifying the -
28823 \begin_inset ERT
28824 status Collapsed
28825
28826 \layout Standard
28827
28828 \backslash 
28829 /
28830 \end_inset 
28831
28832 -peep-file option.
28833 \layout Section
28834
28835 ANSI-Compliance
28836 \begin_inset LatexCommand \index{ANSI-compliance}
28837
28838 \end_inset 
28839
28840
28841 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
28842
28843 \end_inset 
28844
28845
28846 \layout Standard
28847
28848 The latest publically available version of the standard 
28849 \emph on 
28850 ISO/IEC 9899 - Programming languages - C
28851 \emph default 
28852  should be available at: 
28853 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
28854
28855 \end_inset 
28856
28857 .
28858 \newline 
28859
28860 \layout Standard
28861
28862 Deviations from the compliance:
28863 \layout Itemize
28864
28865 functions are not reentrant
28866 \begin_inset LatexCommand \index{reentrant}
28867
28868 \end_inset 
28869
28870  unless explicitly declared as such or the 
28871 \series bold 
28872 -
28873 \begin_inset ERT
28874 status Collapsed
28875
28876 \layout Standard
28877
28878 \backslash 
28879 /
28880 \end_inset 
28881
28882 -stack-auto
28883 \begin_inset LatexCommand \index{-\/-stack-auto}
28884
28885 \end_inset 
28886
28887
28888 \series default 
28889  command line option is specified.
28890 \layout Itemize
28891
28892 structures
28893 \begin_inset LatexCommand \index{struct}
28894
28895 \end_inset 
28896
28897  and unions
28898 \begin_inset LatexCommand \index{union}
28899
28900 \end_inset 
28901
28902  cannot be assigned values directly, cannot be passed as function parameters
28903  or assigned to each other and cannot be a return value
28904 \begin_inset LatexCommand \index{return value}
28905
28906 \end_inset 
28907
28908  from a function, e.g.:
28909 \begin_deeper 
28910 \layout Verse
28911
28912
28913 \family typewriter 
28914 struct s { ...
28915  }; 
28916 \newline 
28917 struct s s1, s2; 
28918 \newline 
28919 foo() 
28920 \newline 
28921
28922 \newline 
28923 \SpecialChar ~
28924 \SpecialChar ~
28925 \SpecialChar ~
28926 \SpecialChar ~
28927 ...
28928  
28929 \newline 
28930 \SpecialChar ~
28931 \SpecialChar ~
28932 \SpecialChar ~
28933 \SpecialChar ~
28934 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
28935 \newline 
28936 \SpecialChar ~
28937 \SpecialChar ~
28938 \SpecialChar ~
28939 \SpecialChar ~
28940 ...
28941  
28942 \newline 
28943 }
28944 \newline 
28945
28946 \series bold 
28947 struct
28948 \series default 
28949  s foo1 (
28950 \series bold 
28951 struct
28952 \series default 
28953  s parms) /* invalid in SDCC although allowed in ANSI */
28954 \newline 
28955
28956 \newline 
28957 \SpecialChar ~
28958 \SpecialChar ~
28959 \SpecialChar ~
28960 \SpecialChar ~
28961 struct s rets; 
28962 \newline 
28963 \SpecialChar ~
28964 \SpecialChar ~
28965 \SpecialChar ~
28966 \SpecialChar ~
28967 ...
28968  
28969 \newline 
28970 \SpecialChar ~
28971 \SpecialChar ~
28972 \SpecialChar ~
28973 \SpecialChar ~
28974 return rets; /* is invalid in SDCC although allowed in ANSI */ 
28975 \newline 
28976 }
28977 \end_deeper 
28978 \layout Itemize
28979
28980 initialization of structure arrays must be fully braced.
28981 \begin_deeper 
28982 \layout Verse
28983
28984
28985 \family typewriter 
28986 struct s { char x } a[] = {1, 2};\SpecialChar ~
28987 \SpecialChar ~
28988 \SpecialChar ~
28989 \SpecialChar ~
28990 \SpecialChar ~
28991 /* invalid in SDCC */
28992 \newline 
28993 struct s { char x } a[] = {{1}, {2}}; /* OK */
28994 \end_deeper 
28995 \layout Itemize
28996
28997 'long long
28998 \begin_inset LatexCommand \index{long long (not supported)}
28999
29000 \end_inset 
29001
29002 ' (64 bit integers
29003 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29004
29005 \end_inset 
29006
29007 ) not supported.
29008 \layout Itemize
29009
29010 'double
29011 \begin_inset LatexCommand \index{double (not supported)}
29012
29013 \end_inset 
29014
29015 ' precision floating point 
29016 \begin_inset LatexCommand \index{Floating point support}
29017
29018 \end_inset 
29019
29020 not supported.
29021 \layout Itemize
29022
29023 Old K&R style
29024 \begin_inset LatexCommand \index{K\&R style}
29025
29026 \end_inset 
29027
29028  function declarations are NOT allowed.
29029 \begin_deeper 
29030 \layout Verse
29031
29032
29033 \family typewriter 
29034 foo(i,j) /* this old style of function declarations */ 
29035 \newline 
29036 int i,j; /* are valid in ANSI but not valid in SDCC */ 
29037 \newline 
29038
29039 \newline 
29040 \SpecialChar ~
29041 \SpecialChar ~
29042 \SpecialChar ~
29043 \SpecialChar ~
29044 ...
29045  
29046 \newline 
29047 }
29048 \end_deeper 
29049 \layout Itemize
29050
29051 Most enhancements in C99 are not supported, f.e.:
29052 \begin_deeper 
29053 \layout Verse
29054
29055
29056 \family typewriter 
29057 \series bold 
29058 inline
29059 \begin_inset LatexCommand \index{inline (not supported)}
29060
29061 \end_inset 
29062
29063
29064 \series default 
29065  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29066  in C99.
29067  An empty define 
29068 \emph on 
29069 #define inline
29070 \emph default 
29071  can be used as a work around */
29072 \newline 
29073
29074 \newline 
29075 for (
29076 \series bold 
29077 int
29078 \series default 
29079  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29080 \end_deeper 
29081 \layout Itemize
29082
29083 Certain words that are valid identifiers in the standard may be reserved
29084  words in SDCC unless the 
29085 \series bold 
29086 -
29087 \begin_inset ERT
29088 status Collapsed
29089
29090 \layout Standard
29091
29092 \backslash 
29093 /
29094 \end_inset 
29095
29096 -std-c89
29097 \begin_inset LatexCommand \index{-\/-std-c89}
29098
29099 \end_inset 
29100
29101  or -
29102 \begin_inset ERT
29103 status Collapsed
29104
29105 \layout Standard
29106
29107 \backslash 
29108 /
29109 \end_inset 
29110
29111 -std-c99
29112 \begin_inset LatexCommand \index{-\/-std-c99}
29113
29114 \end_inset 
29115
29116
29117 \series default 
29118  command line options are used.
29119  These may include (depending on the selected processor): 'at', 'banked',
29120  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29121 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29122  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29123  '_naked'.
29124  Compliant equivalents of these keywords are always available in a form
29125  that begin with two underscores
29126 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29127
29128 \end_inset 
29129
29130 , f.e.
29131  '__data' instead of 'data'.
29132 \layout Section
29133
29134 Cyclomatic Complexity
29135 \begin_inset LatexCommand \index{Cyclomatic complexity}
29136
29137 \end_inset 
29138
29139
29140 \layout Standard
29141
29142 Cyclomatic complexity of a function is defined as the number of independent
29143  paths the program can take during execution of the function.
29144  This is an important number since it defines the number test cases you
29145  have to generate to validate the function.
29146  The accepted industry standard for complexity number is 10, if the cyclomatic
29147  complexity reported by SDCC exceeds 10 you should think about simplification
29148  of the function logic.
29149  Note that the complexity level is not related to the number of lines of
29150  code in a function.
29151  Large functions can have low complexity, and small functions can have large
29152  complexity levels.
29153  
29154 \newline 
29155
29156 \newline 
29157 SDCC uses the following formula to compute the complexity:
29158 \newline 
29159
29160 \layout Standard
29161
29162 complexity = (number of edges in control flow graph) - (number of nodes
29163  in control flow graph) + 2;
29164 \newline 
29165
29166 \newline 
29167 Having said that the industry standard is 10, you should be aware that in
29168  some cases it be may unavoidable to have a complexity level of less than
29169  10.
29170  For example if you have switch statement with more than 10 case labels,
29171  each case label adds one to the complexity level.
29172  The complexity level is by no means an absolute measure of the algorithmic
29173  complexity of the function, it does however provide a good starting point
29174  for which functions you might look at for further optimization.
29175 \layout Section
29176
29177 Retargetting for other Processors
29178 \layout Standard
29179
29180 The issues for retargetting the compiler are far too numerous to be covered
29181  by this document.
29182  What follows is a brief description of each of the seven phases of the
29183  compiler and its MCU dependency.
29184 \layout Itemize
29185
29186 Parsing the source and building the annotated parse tree.
29187  This phase is largely MCU independent (except for the language extensions).
29188  Syntax & semantic checks are also done in this phase, along with some initial
29189  optimizations like back patching labels and the pattern matching optimizations
29190  like bit-rotation etc.
29191 \layout Itemize
29192
29193 The second phase involves generating an intermediate code which can be easy
29194  manipulated during the later phases.
29195  This phase is entirely MCU independent.
29196  The intermediate code generation assumes the target machine has unlimited
29197  number of registers, and designates them with the name iTemp.
29198  The compiler can be made to dump a human readable form of the code generated
29199  by using the -
29200 \begin_inset ERT
29201 status Collapsed
29202
29203 \layout Standard
29204
29205 \backslash 
29206 /
29207 \end_inset 
29208
29209 -dumpraw option.
29210 \layout Itemize
29211
29212 This phase does the bulk of the standard optimizations and is also MCU independe
29213 nt.
29214  This phase can be broken down into several sub-phases:
29215 \newline 
29216
29217 \newline 
29218 Break down intermediate code (iCode) into basic blocks.
29219 \newline 
29220 Do control flow & data flow analysis on the basic blocks.
29221 \newline 
29222 Do local common subexpression elimination, then global subexpression elimination
29223 \newline 
29224 Dead code elimination
29225 \newline 
29226 Loop optimizations
29227 \newline 
29228 If loop optimizations caused any changes then do 'global subexpression eliminati
29229 on' and 'dead code elimination' again.
29230 \layout Itemize
29231
29232 This phase determines the live-ranges; by live range I mean those iTemp
29233  variables defined by the compiler that still survive after all the optimization
29234 s.
29235  Live range analysis
29236 \begin_inset LatexCommand \index{Live range analysis}
29237
29238 \end_inset 
29239
29240  is essential for register allocation, since these computation determines
29241  which of these iTemps will be assigned to registers, and for how long.
29242 \layout Itemize
29243
29244 Phase five is register allocation.
29245  There are two parts to this process.
29246 \newline 
29247
29248 \newline 
29249 The first part I call 'register packing' (for lack of a better term).
29250  In this case several MCU specific expression folding is done to reduce
29251  register pressure.
29252 \newline 
29253
29254 \newline 
29255 The second part is more MCU independent and deals with allocating registers
29256  to the remaining live ranges.
29257  A lot of MCU specific code does creep into this phase because of the limited
29258  number of index registers available in the 8051.
29259 \layout Itemize
29260
29261 The Code generation phase is (unhappily), entirely MCU dependent and very
29262  little (if any at all) of this code can be reused for other MCU.
29263  However the scheme for allocating a homogenized assembler operand for each
29264  iCode operand may be reused.
29265 \layout Itemize
29266
29267 As mentioned in the optimization section the peep-hole optimizer is rule
29268  based system, which can reprogrammed for other MCUs.
29269 \layout Chapter
29270
29271 Compiler internals
29272 \begin_inset LatexCommand \index{Compiler internals}
29273
29274 \end_inset 
29275
29276
29277 \layout Section
29278
29279 The anatomy of the compiler
29280 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29281
29282 \end_inset 
29283
29284
29285 \layout Standard
29286
29287
29288 \shape italic 
29289 This is an excerpt from an article published in Circuit Cellar Magazine
29290  in 
29291 \series bold 
29292 August 2000
29293 \series default 
29294 .
29295  It's a little outdated (the compiler is much more efficient now and user/develo
29296 per friendly), but pretty well exposes the guts of it all.
29297 \shape default 
29298
29299 \newline 
29300
29301 \newline 
29302 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
29303  It is fairly easy to retarget for other 8-bit MCU.
29304  Here we take a look at some of the internals of the compiler.
29305  
29306 \layout Paragraph*
29307
29308 Parsing
29309 \begin_inset LatexCommand \index{Parsing}
29310
29311 \end_inset 
29312
29313  
29314 \layout Standard
29315
29316 Parsing the input source file and creating an AST (Annotated Syntax Tree
29317 \begin_inset LatexCommand \index{Annotated syntax tree}
29318
29319 \end_inset 
29320
29321 ).
29322  This phase also involves propagating types (annotating each node of the
29323  parse tree with type information) and semantic analysis.
29324  There are some MCU specific parsing rules.
29325  For example the storage classes, the extended storage classes are MCU specific
29326  while there may be a xdata storage class for 8051 there is no such storage
29327  class for z80 or Atmel AVR.
29328  SDCC allows MCU specific storage class extensions, i.e.
29329  xdata will be treated as a storage class specifier when parsing 8051 C
29330  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
29331  C code.
29332 \layout Paragraph*
29333
29334 Generating iCode
29335 \begin_inset LatexCommand \index{iCode}
29336
29337 \end_inset 
29338
29339
29340 \layout Standard
29341
29342 Intermediate code generation.
29343  In this phase the AST is broken down into three-operand form (iCode).
29344  These three operand forms are represented as doubly linked lists.
29345  ICode is the term given to the intermediate form generated by the compiler.
29346  ICode example section shows some examples of iCode generated for some simple
29347  C source functions.
29348 \layout Paragraph*
29349
29350 Optimizations
29351 \begin_inset LatexCommand \index{Optimizations}
29352
29353 \end_inset 
29354
29355 .
29356 \layout Standard
29357
29358 Bulk of the target independent optimizations is performed in this phase.
29359  The optimizations include constant propagation, common sub-expression eliminati
29360 on, loop invariant code movement, strength reduction of loop induction variables
29361  and dead-code elimination.
29362 \layout Paragraph*
29363
29364 Live range analysis
29365 \begin_inset LatexCommand \index{Live range analysis}
29366
29367 \end_inset 
29368
29369
29370 \layout Standard
29371
29372 During intermediate code generation phase, the compiler assumes the target
29373  machine has infinite number of registers and generates a lot of temporary
29374  variables.
29375  The live range computation determines the lifetime of each of these compiler-ge
29376 nerated temporaries.
29377  A picture speaks a thousand words.
29378  ICode example sections show the live range annotations for each of the
29379  operand.
29380  It is important to note here, each iCode is assigned a number in the order
29381  of its execution in the function.
29382  The live ranges are computed in terms of these numbers.
29383  The from number is the number of the iCode which first defines the operand
29384  and the to number signifies the iCode which uses this operand last.
29385 \layout Paragraph*
29386
29387 Register Allocation
29388 \begin_inset LatexCommand \index{Register allocation}
29389
29390 \end_inset 
29391
29392
29393 \layout Standard
29394
29395 The register allocation determines the type and number of registers needed
29396  by each operand.
29397  In most MCUs only a few registers can be used for indirect addressing.
29398  In case of 8051 for example the registers R0 & R1 can be used to indirectly
29399  address the internal ram and DPTR to indirectly address the external ram.
29400  The compiler will try to allocate the appropriate register to pointer variables
29401  if it can.
29402  ICode example section shows the operands annotated with the registers assigned
29403  to them.
29404  The compiler will try to keep operands in registers as much as possible;
29405  there are several schemes the compiler uses to do achieve this.
29406  When the compiler runs out of registers the compiler will check to see
29407  if there are any live operands which is not used or defined in the current
29408  basic block being processed, if there are any found then it will push that
29409  operand and use the registers in this block, the operand will then be popped
29410  at the end of the basic block.
29411  
29412 \layout Standard
29413
29414 There are other MCU specific considerations in this phase.
29415  Some MCUs have an accumulator; very short-lived operands could be assigned
29416  to the accumulator instead of a general-purpose register.
29417 \layout Paragraph*
29418
29419 Code generation
29420 \layout Standard
29421
29422 Figure II gives a table of iCode operations supported by the compiler.
29423  The code generation involves translating these operations into corresponding
29424  assembly code for the processor.
29425  This sounds overly simple but that is the essence of code generation.
29426  Some of the iCode operations are generated on a MCU specific manner for
29427  example, the z80 port does not use registers to pass parameters so the
29428  SEND and RECV iCode operations will not be generated, and it also does
29429  not support JUMPTABLES.
29430  
29431 \newline 
29432
29433 \series bold 
29434 \shape italic 
29435 \color red
29436 <Where is Figure II?>
29437 \layout Comment
29438
29439 In the original article Figure II was announced to be downloadable on 
29440 \shape italic 
29441 Circuit Cellar
29442 \shape default 
29443 's web site.
29444  Unfortunately it never seemed to have shown up there, so: where is Figure
29445  II?
29446 \layout Paragraph*
29447
29448 ICode Example
29449 \begin_inset LatexCommand \index{iCode}
29450
29451 \end_inset 
29452
29453
29454 \layout Standard
29455
29456 This section shows some details of iCode.
29457  The example C code does not do anything useful; it is used as an example
29458  to illustrate the intermediate code generated by the compiler.
29459 \layout Verse
29460
29461
29462 \family typewriter 
29463 1.\SpecialChar ~
29464 xdata int * p;
29465 \newline 
29466 2.\SpecialChar ~
29467 int gint;
29468 \newline 
29469 3.\SpecialChar ~
29470 /* This function does nothing useful.
29471  It is used
29472 \newline 
29473 4.\SpecialChar ~
29474 \SpecialChar ~
29475 \SpecialChar ~
29476 \SpecialChar ~
29477 for the purpose of explaining iCode */
29478 \newline 
29479 5.\SpecialChar ~
29480 short function (data int *x)
29481 \newline 
29482 6.\SpecialChar ~
29483 {
29484 \newline 
29485 7.\SpecialChar ~
29486 \SpecialChar ~
29487 \SpecialChar ~
29488 short i=10; \SpecialChar ~
29489 \SpecialChar ~
29490 /* dead initialization eliminated */
29491 \newline 
29492 8.\SpecialChar ~
29493 \SpecialChar ~
29494 \SpecialChar ~
29495 short sum=10; /* dead initialization eliminated */
29496 \newline 
29497 9.\SpecialChar ~
29498 \SpecialChar ~
29499 \SpecialChar ~
29500 short mul;
29501 \newline 
29502 10.\SpecialChar ~
29503 \SpecialChar ~
29504 int j ;
29505 \newline 
29506 11.\SpecialChar ~
29507 \SpecialChar ~
29508 while (*x) *x++ = *p++; 
29509 \newline 
29510 12.\SpecialChar ~
29511 \SpecialChar ~
29512 \SpecialChar ~
29513 \SpecialChar ~
29514 sum = 0 ; 
29515 \newline 
29516 13.\SpecialChar ~
29517 \SpecialChar ~
29518 mul = 0;
29519 \newline 
29520 14.\SpecialChar ~
29521 \SpecialChar ~
29522 /* compiler detects i,j to be induction variables */
29523 \newline 
29524 15.\SpecialChar ~
29525 \SpecialChar ~
29526 for (i = 0, j = 10 ; i < 10 ; i++, j
29527 \family default 
29528 -
29529 \begin_inset ERT
29530 status Collapsed
29531
29532 \layout Standard
29533
29534 \backslash 
29535 /
29536 \end_inset 
29537
29538 -
29539 \family typewriter 
29540 ) {
29541 \newline 
29542 16.\SpecialChar ~
29543 \SpecialChar ~
29544 \SpecialChar ~
29545 \SpecialChar ~
29546 sum += i;
29547 \newline 
29548 17.\SpecialChar ~
29549 \SpecialChar ~
29550 \SpecialChar ~
29551 \SpecialChar ~
29552 mul += i * 3; \SpecialChar ~
29553 \SpecialChar ~
29554 /* this multiplication remains */
29555 \newline 
29556 18.\SpecialChar ~
29557 \SpecialChar ~
29558 \SpecialChar ~
29559 \SpecialChar ~
29560 gint += j * 3;\SpecialChar ~
29561 \SpecialChar ~
29562 /* this multiplication changed to addition */
29563 \newline 
29564 19.\SpecialChar ~
29565 \SpecialChar ~
29566 }
29567 \newline 
29568 20.\SpecialChar ~
29569 \SpecialChar ~
29570 return sum+mul;
29571 \newline 
29572 21.\SpecialChar ~
29573 }
29574 \layout Standard
29575
29576 In addition to the operands each iCode contains information about the filename
29577  and line it corresponds to in the source file.
29578  The first field in the listing should be interpreted as follows:
29579 \newline 
29580
29581 \shape italic 
29582 \size footnotesize 
29583 Filename(linenumber: iCode Execution sequence number : ICode hash table
29584  key : loop depth of the iCode).
29585 \shape default 
29586 \size default 
29587
29588 \newline 
29589 Then follows the human readable form of the ICode operation.
29590  Each operand of this triplet form can be of three basic types a) compiler
29591  generated temporary b) user defined variable c) a constant value.
29592  Note that local variables and parameters are replaced by compiler generated
29593  temporaries.
29594  Live ranges
29595 \begin_inset LatexCommand \index{Live range analysis}
29596
29597 \end_inset 
29598
29599  are computed only for temporaries (i.e.
29600  live ranges are not computed for global variables).
29601  Registers
29602 \begin_inset LatexCommand \index{Register allocation}
29603
29604 \end_inset 
29605
29606  are allocated for temporaries only.
29607  Operands are formatted in the following manner:
29608 \newline 
29609
29610 \shape italic 
29611 \size footnotesize 
29612 Operand Name [lr live-from : live-to ] { type information } [ registers
29613  allocated ].
29614 \shape default 
29615 \size default 
29616
29617 \newline 
29618 As mentioned earlier the live ranges are computed in terms of the execution
29619  sequence number of the iCodes, for example 
29620 \newline 
29621 the iTemp0 is live from (i.e.
29622  first defined in iCode with execution sequence number 3, and is last used
29623  in the iCode with sequence number 5).
29624  For induction variables such as iTemp21 the live range computation extends
29625  the lifetime from the start to the end of the loop.
29626 \newline 
29627 The register allocator used the live range information to allocate registers,
29628  the same registers may be used for different temporaries if their live
29629  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
29630  iTemp17 since their live ranges do not overlap.
29631  In addition the allocator also takes into consideration the type and usage
29632  of a temporary, for example itemp6 is a pointer to near space and is used
29633  as to fetch data from (i.e.
29634  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
29635  Some short lived temporaries are allocated to special registers which have
29636  meaning to the code generator e.g.
29637  iTemp13 is allocated to a pseudo register CC which tells the back end that
29638  the temporary is used only for a conditional jump the code generation makes
29639  use of this information to optimize a compare and jump ICode.
29640 \newline 
29641 There are several loop optimizations
29642 \begin_inset LatexCommand \index{Loop optimization}
29643
29644 \end_inset 
29645
29646  performed by the compiler.
29647  It can detect induction variables iTemp21(i) and iTemp23(j).
29648  Also note the compiler does selective strength reduction
29649 \begin_inset LatexCommand \index{Strength reduction}
29650
29651 \end_inset 
29652
29653 , i.e.
29654  the multiplication of an induction variable in line 18 (gint = j * 3) is
29655  changed to addition, a new temporary iTemp17 is allocated and assigned
29656  a initial value, a constant 3 is then added for each iteration of the loop.
29657  The compiler does not change the multiplication
29658 \begin_inset LatexCommand \index{Multiplication}
29659
29660 \end_inset 
29661
29662  in line 17 however since the processor does support an 8 * 8 bit multiplication.
29663 \newline 
29664 Note the dead code elimination
29665 \begin_inset LatexCommand \index{Dead-code elimination}
29666
29667 \end_inset 
29668
29669  optimization eliminated the dead assignments in line 7 & 8 to I and sum
29670  respectively.
29671 \newline 
29672
29673 \layout Standard
29674
29675
29676 \size footnotesize 
29677 Sample.c (5:1:0:0) _entry($9) :
29678 \layout Standard
29679
29680
29681 \size footnotesize 
29682 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
29683 \layout Standard
29684
29685
29686 \size footnotesize 
29687 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
29688 \layout Standard
29689
29690
29691 \size footnotesize 
29692 Sample.c(11:4:53:0) preHeaderLbl0($11) :
29693 \layout Standard
29694
29695
29696 \size footnotesize 
29697 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
29698  * int}[r2]
29699 \layout Standard
29700
29701
29702 \size footnotesize 
29703 Sample.c(11:6:5:1) _whilecontinue_0($1) :
29704 \layout Standard
29705
29706
29707 \size footnotesize 
29708 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
29709  int}[r0]]
29710 \layout Standard
29711
29712
29713 \size footnotesize 
29714 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
29715 \layout Standard
29716
29717
29718 \size footnotesize 
29719 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
29720  * int}
29721 \layout Standard
29722
29723
29724 \size footnotesize 
29725 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
29726  {short}
29727 \layout Standard
29728
29729
29730 \size footnotesize 
29731 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
29732  * int}[DPTR]]
29733 \layout Standard
29734
29735
29736 \size footnotesize 
29737 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
29738 }[r2 r3]
29739 \layout Standard
29740
29741
29742 \size footnotesize 
29743 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
29744  * int}[r0] + 0x2 {short}
29745 \layout Standard
29746
29747
29748 \size footnotesize 
29749 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
29750 \layout Standard
29751
29752
29753 \size footnotesize 
29754 Sample.c(11:17:21:0)_whilebreak_0($3) :
29755 \layout Standard
29756
29757
29758 \size footnotesize 
29759 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
29760 \layout Standard
29761
29762
29763 \size footnotesize 
29764 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
29765 \layout Standard
29766
29767
29768 \size footnotesize 
29769 Sample.c(15:20:54:0)preHeaderLbl1($13) :
29770 \layout Standard
29771
29772
29773 \size footnotesize 
29774 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
29775 \layout Standard
29776
29777
29778 \size footnotesize 
29779 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
29780 \layout Standard
29781
29782
29783 \size footnotesize 
29784 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
29785 \layout Standard
29786
29787
29788 \size footnotesize 
29789 Sample.c(15:24:26:1)_forcond_0($4) :
29790 \layout Standard
29791
29792
29793 \size footnotesize 
29794 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
29795  < 0xa {short}
29796 \layout Standard
29797
29798
29799 \size footnotesize 
29800 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
29801 \layout Standard
29802
29803
29804 \size footnotesize 
29805 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
29806  + ITemp21 [lr21:38]{short}[r4]
29807 \layout Standard
29808
29809
29810 \size footnotesize 
29811 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
29812  * 0x3 {short}
29813 \layout Standard
29814
29815
29816 \size footnotesize 
29817 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
29818  + iTemp15 [lr29:30]{short}[r1]
29819 \layout Standard
29820
29821
29822 \size footnotesize 
29823 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
29824  r0]- 0x3 {short}
29825 \layout Standard
29826
29827
29828 \size footnotesize 
29829 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
29830 int}[r7 r0]
29831 \layout Standard
29832
29833
29834 \size footnotesize 
29835 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
29836  + 0x1 {short}
29837 \layout Standard
29838
29839
29840 \size footnotesize 
29841 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
29842  r6]- 0x1 {short}
29843 \layout Standard
29844
29845
29846 \size footnotesize 
29847 Sample.c(19:38:47:1) goto _forcond_0($4)
29848 \layout Standard
29849
29850
29851 \size footnotesize 
29852 Sample.c(19:39:48:0)_forbreak_0($7) :
29853 \layout Standard
29854
29855
29856 \size footnotesize 
29857 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
29858  + ITemp11 [lr19:40]{short}[r3]
29859 \layout Standard
29860
29861
29862 \size footnotesize 
29863 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
29864 \layout Standard
29865
29866
29867 \size footnotesize 
29868 Sample.c(20:42:51:0)_return($8) :
29869 \layout Standard
29870
29871
29872 \size footnotesize 
29873 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
29874 \size default 
29875
29876 \newline 
29877
29878 \newline 
29879 Finally the code generated for this function:
29880 \newline 
29881
29882 \layout Standard
29883
29884
29885 \size footnotesize 
29886 .area DSEG (DATA)
29887 \layout Standard
29888
29889
29890 \size footnotesize 
29891 _p::
29892 \layout Standard
29893
29894
29895 \size footnotesize 
29896 \SpecialChar ~
29897 \SpecialChar ~
29898 .ds 2
29899 \layout Standard
29900
29901
29902 \size footnotesize 
29903 _gint::
29904 \layout Standard
29905
29906
29907 \size footnotesize 
29908 \SpecialChar ~
29909 \SpecialChar ~
29910 .ds 2
29911 \layout Standard
29912
29913
29914 \size footnotesize 
29915 ; sample.c 5
29916 \layout Standard
29917
29918
29919 \size footnotesize 
29920 ; ----------------------------------------------
29921 \layout Standard
29922
29923
29924 \size footnotesize 
29925 ; function function
29926 \layout Standard
29927
29928
29929 \size footnotesize 
29930 ; ----------------------------------------------
29931 \layout Standard
29932
29933
29934 \size footnotesize 
29935 _function:
29936 \layout Standard
29937
29938
29939 \size footnotesize 
29940 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
29941 \layout Standard
29942
29943
29944 \size footnotesize 
29945 \SpecialChar ~
29946 \SpecialChar ~
29947 mov r2,dpl
29948 \layout Standard
29949
29950
29951 \size footnotesize 
29952 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
29953 \layout Standard
29954
29955
29956 \size footnotesize 
29957 \SpecialChar ~
29958 \SpecialChar ~
29959 mov ar0,r2
29960 \layout Standard
29961
29962
29963 \size footnotesize 
29964 ;_whilecontinue_0($1) :
29965 \layout Standard
29966
29967
29968 \size footnotesize 
29969 00101$:
29970 \layout Standard
29971
29972
29973 \size footnotesize 
29974 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
29975 \layout Standard
29976
29977
29978 \size footnotesize 
29979 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
29980 \layout Standard
29981
29982
29983 \size footnotesize 
29984 \SpecialChar ~
29985 \SpecialChar ~
29986 mov ar2,@r0
29987 \layout Standard
29988
29989
29990 \size footnotesize 
29991 \SpecialChar ~
29992 \SpecialChar ~
29993 inc r0
29994 \layout Standard
29995
29996
29997 \size footnotesize 
29998 \SpecialChar ~
29999 \SpecialChar ~
30000 mov ar3,@r0
30001 \layout Standard
30002
30003
30004 \size footnotesize 
30005 \SpecialChar ~
30006 \SpecialChar ~
30007 dec r0
30008 \layout Standard
30009
30010
30011 \size footnotesize 
30012 \SpecialChar ~
30013 \SpecialChar ~
30014 mov a,r2
30015 \layout Standard
30016
30017
30018 \size footnotesize 
30019 \SpecialChar ~
30020 \SpecialChar ~
30021 orl a,r3
30022 \layout Standard
30023
30024
30025 \size footnotesize 
30026 \SpecialChar ~
30027 \SpecialChar ~
30028 jz 00103$
30029 \layout Standard
30030
30031
30032 \size footnotesize 
30033 00114$:
30034 \layout Standard
30035
30036
30037 \size footnotesize 
30038 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
30039 \layout Standard
30040
30041
30042 \size footnotesize 
30043 \SpecialChar ~
30044 \SpecialChar ~
30045 mov dpl,_p
30046 \layout Standard
30047
30048
30049 \size footnotesize 
30050 \SpecialChar ~
30051 \SpecialChar ~
30052 mov dph,(_p + 1)
30053 \layout Standard
30054
30055
30056 \size footnotesize 
30057 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
30058 \layout Standard
30059
30060
30061 \size footnotesize 
30062 \SpecialChar ~
30063 \SpecialChar ~
30064 mov a,#0x02
30065 \layout Standard
30066
30067
30068 \size footnotesize 
30069 \SpecialChar ~
30070 \SpecialChar ~
30071 add a,_p
30072 \layout Standard
30073
30074
30075 \size footnotesize 
30076 \SpecialChar ~
30077 \SpecialChar ~
30078 mov _p,a
30079 \layout Standard
30080
30081
30082 \size footnotesize 
30083 \SpecialChar ~
30084 \SpecialChar ~
30085 clr a
30086 \layout Standard
30087
30088
30089 \size footnotesize 
30090 \SpecialChar ~
30091 \SpecialChar ~
30092 addc a,(_p + 1)
30093 \layout Standard
30094
30095
30096 \size footnotesize 
30097 \SpecialChar ~
30098 \SpecialChar ~
30099 mov (_p + 1),a
30100 \layout Standard
30101
30102
30103 \size footnotesize 
30104 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
30105 \layout Standard
30106
30107
30108 \size footnotesize 
30109 \SpecialChar ~
30110 \SpecialChar ~
30111 movx a,@dptr
30112 \layout Standard
30113
30114
30115 \size footnotesize 
30116 \SpecialChar ~
30117 \SpecialChar ~
30118 mov r2,a
30119 \layout Standard
30120
30121
30122 \size footnotesize 
30123 \SpecialChar ~
30124 \SpecialChar ~
30125 inc dptr
30126 \layout Standard
30127
30128
30129 \size footnotesize 
30130 \SpecialChar ~
30131 \SpecialChar ~
30132 movx a,@dptr
30133 \layout Standard
30134
30135
30136 \size footnotesize 
30137 \SpecialChar ~
30138 \SpecialChar ~
30139 mov r3,a
30140 \layout Standard
30141
30142
30143 \size footnotesize 
30144 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
30145 \layout Standard
30146
30147
30148 \size footnotesize 
30149 \SpecialChar ~
30150 \SpecialChar ~
30151 mov @r0,ar2
30152 \layout Standard
30153
30154
30155 \size footnotesize 
30156 \SpecialChar ~
30157 \SpecialChar ~
30158 inc r0
30159 \layout Standard
30160
30161
30162 \size footnotesize 
30163 \SpecialChar ~
30164 \SpecialChar ~
30165 mov @r0,ar3
30166 \layout Standard
30167
30168
30169 \size footnotesize 
30170 ; iTemp6 [lr5:16]{_near * int}[r0] = 
30171 \layout Standard
30172
30173
30174 \size footnotesize 
30175 ; iTemp6 [lr5:16]{_near * int}[r0] + 
30176 \layout Standard
30177
30178
30179 \size footnotesize 
30180 ; 0x2 {short}
30181 \layout Standard
30182
30183
30184 \size footnotesize 
30185 \SpecialChar ~
30186 \SpecialChar ~
30187 inc r0
30188 \layout Standard
30189
30190
30191 \size footnotesize 
30192 ; goto _whilecontinue_0($1)
30193 \layout Standard
30194
30195
30196 \size footnotesize 
30197 \SpecialChar ~
30198 \SpecialChar ~
30199 sjmp 00101$
30200 \layout Standard
30201
30202
30203 \size footnotesize 
30204 ; _whilebreak_0($3) :
30205 \layout Standard
30206
30207
30208 \size footnotesize 
30209 00103$:
30210 \layout Standard
30211
30212
30213 \size footnotesize 
30214 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
30215 \layout Standard
30216
30217
30218 \size footnotesize 
30219 \SpecialChar ~
30220 \SpecialChar ~
30221 mov r2,#0x00
30222 \layout Standard
30223
30224
30225 \size footnotesize 
30226 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
30227 \layout Standard
30228
30229
30230 \size footnotesize 
30231 \SpecialChar ~
30232 \SpecialChar ~
30233 mov r3,#0x00
30234 \layout Standard
30235
30236
30237 \size footnotesize 
30238 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
30239 \layout Standard
30240
30241
30242 \size footnotesize 
30243 \SpecialChar ~
30244 \SpecialChar ~
30245 mov r4,#0x00
30246 \layout Standard
30247
30248
30249 \size footnotesize 
30250 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
30251 \layout Standard
30252
30253
30254 \size footnotesize 
30255 \SpecialChar ~
30256 \SpecialChar ~
30257 mov r5,#0x0A
30258 \layout Standard
30259
30260
30261 \size footnotesize 
30262 \SpecialChar ~
30263 \SpecialChar ~
30264 mov r6,#0x00
30265 \layout Standard
30266
30267
30268 \size footnotesize 
30269 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
30270 \layout Standard
30271
30272
30273 \size footnotesize 
30274 \SpecialChar ~
30275 \SpecialChar ~
30276 mov r7,#0x1E
30277 \layout Standard
30278
30279
30280 \size footnotesize 
30281 \SpecialChar ~
30282 \SpecialChar ~
30283 mov r0,#0x00
30284 \layout Standard
30285
30286
30287 \size footnotesize 
30288 ; _forcond_0($4) :
30289 \layout Standard
30290
30291
30292 \size footnotesize 
30293 00104$:
30294 \layout Standard
30295
30296
30297 \size footnotesize 
30298 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
30299 \layout Standard
30300
30301
30302 \size footnotesize 
30303 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
30304 \layout Standard
30305
30306
30307 \size footnotesize 
30308 \SpecialChar ~
30309 \SpecialChar ~
30310 clr c
30311 \layout Standard
30312
30313
30314 \size footnotesize 
30315 \SpecialChar ~
30316 \SpecialChar ~
30317 mov a,r4
30318 \layout Standard
30319
30320
30321 \size footnotesize 
30322 \SpecialChar ~
30323 \SpecialChar ~
30324 xrl a,#0x80
30325 \layout Standard
30326
30327
30328 \size footnotesize 
30329 \SpecialChar ~
30330 \SpecialChar ~
30331 subb a,#0x8a
30332 \layout Standard
30333
30334
30335 \size footnotesize 
30336 \SpecialChar ~
30337 \SpecialChar ~
30338 jnc 00107$
30339 \layout Standard
30340
30341
30342 \size footnotesize 
30343 00115$:
30344 \layout Standard
30345
30346
30347 \size footnotesize 
30348 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
30349 \layout Standard
30350
30351
30352 \size footnotesize 
30353 ; iTemp21 [lr21:38]{short}[r4]
30354 \layout Standard
30355
30356
30357 \size footnotesize 
30358 \SpecialChar ~
30359 \SpecialChar ~
30360 mov a,r4
30361 \layout Standard
30362
30363
30364 \size footnotesize 
30365 \SpecialChar ~
30366 \SpecialChar ~
30367 add a,r2
30368 \layout Standard
30369
30370
30371 \size footnotesize 
30372 \SpecialChar ~
30373 \SpecialChar ~
30374 mov r2,a
30375 \layout Standard
30376
30377
30378 \size footnotesize 
30379 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
30380 \layout Standard
30381
30382
30383 \size footnotesize 
30384 \SpecialChar ~
30385 \SpecialChar ~
30386 mov b,#0x03
30387 \layout Standard
30388
30389
30390 \size footnotesize 
30391 \SpecialChar ~
30392 \SpecialChar ~
30393 mov a,r4
30394 \layout Standard
30395
30396
30397 \size footnotesize 
30398 \SpecialChar ~
30399 \SpecialChar ~
30400 mul ab
30401 \layout Standard
30402
30403
30404 \size footnotesize 
30405 \SpecialChar ~
30406 \SpecialChar ~
30407 mov r1,a
30408 \layout Standard
30409
30410
30411 \size footnotesize 
30412 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
30413 \layout Standard
30414
30415
30416 \size footnotesize 
30417 ; iTemp15 [lr29:30]{short}[r1]
30418 \layout Standard
30419
30420
30421 \size footnotesize 
30422 \SpecialChar ~
30423 \SpecialChar ~
30424 add a,r3
30425 \layout Standard
30426
30427
30428 \size footnotesize 
30429 \SpecialChar ~
30430 \SpecialChar ~
30431 mov r3,a
30432 \layout Standard
30433
30434
30435 \size footnotesize 
30436 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
30437 \layout Standard
30438
30439
30440 \size footnotesize 
30441 \SpecialChar ~
30442 \SpecialChar ~
30443 mov a,r7
30444 \layout Standard
30445
30446
30447 \size footnotesize 
30448 \SpecialChar ~
30449 \SpecialChar ~
30450 add a,#0xfd
30451 \layout Standard
30452
30453
30454 \size footnotesize 
30455 \SpecialChar ~
30456 \SpecialChar ~
30457 mov r7,a
30458 \layout Standard
30459
30460
30461 \size footnotesize 
30462 \SpecialChar ~
30463 \SpecialChar ~
30464 mov a,r0
30465 \layout Standard
30466
30467
30468 \size footnotesize 
30469 \SpecialChar ~
30470 \SpecialChar ~
30471 addc a,#0xff
30472 \layout Standard
30473
30474
30475 \size footnotesize 
30476 \SpecialChar ~
30477 \SpecialChar ~
30478 mov r0,a
30479 \layout Standard
30480
30481
30482 \size footnotesize 
30483 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
30484 \layout Standard
30485
30486
30487 \size footnotesize 
30488 \SpecialChar ~
30489 \SpecialChar ~
30490 mov a,r7
30491 \layout Standard
30492
30493
30494 \size footnotesize 
30495 \SpecialChar ~
30496 \SpecialChar ~
30497 add a,_gint
30498 \layout Standard
30499
30500
30501 \size footnotesize 
30502 \SpecialChar ~
30503 \SpecialChar ~
30504 mov _gint,a
30505 \layout Standard
30506
30507
30508 \size footnotesize 
30509 \SpecialChar ~
30510 \SpecialChar ~
30511 mov a,r0
30512 \layout Standard
30513
30514
30515 \size footnotesize 
30516 \SpecialChar ~
30517 \SpecialChar ~
30518 addc a,(_gint + 1)
30519 \layout Standard
30520
30521
30522 \size footnotesize 
30523 \SpecialChar ~
30524 \SpecialChar ~
30525 mov (_gint + 1),a
30526 \layout Standard
30527
30528
30529 \size footnotesize 
30530 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
30531 \layout Standard
30532
30533
30534 \size footnotesize 
30535 \SpecialChar ~
30536 \SpecialChar ~
30537 inc r4
30538 \layout Standard
30539
30540
30541 \size footnotesize 
30542 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
30543 \layout Standard
30544
30545
30546 \size footnotesize 
30547 \SpecialChar ~
30548 \SpecialChar ~
30549 dec r5
30550 \layout Standard
30551
30552
30553 \size footnotesize 
30554 \SpecialChar ~
30555 \SpecialChar ~
30556 cjne r5,#0xff,00104$
30557 \layout Standard
30558
30559
30560 \size footnotesize 
30561 \SpecialChar ~
30562 \SpecialChar ~
30563 dec r6
30564 \layout Standard
30565
30566
30567 \size footnotesize 
30568 ; goto _forcond_0($4)
30569 \layout Standard
30570
30571
30572 \size footnotesize 
30573 \SpecialChar ~
30574 \SpecialChar ~
30575 sjmp 00104$
30576 \layout Standard
30577
30578
30579 \size footnotesize 
30580 ; _forbreak_0($7) :
30581 \layout Standard
30582
30583
30584 \size footnotesize 
30585 00107$:
30586 \layout Standard
30587
30588
30589 \size footnotesize 
30590 ; ret iTemp24 [lr40:41]{short}
30591 \layout Standard
30592
30593
30594 \size footnotesize 
30595 \SpecialChar ~
30596 \SpecialChar ~
30597 mov a,r3
30598 \layout Standard
30599
30600
30601 \size footnotesize 
30602 \SpecialChar ~
30603 \SpecialChar ~
30604 add a,r2
30605 \layout Standard
30606
30607
30608 \size footnotesize 
30609 \SpecialChar ~
30610 \SpecialChar ~
30611 mov dpl,a
30612 \layout Standard
30613
30614
30615 \size footnotesize 
30616 ; _return($8) :
30617 \layout Standard
30618
30619
30620 \size footnotesize 
30621 00108$:
30622 \layout Standard
30623
30624
30625 \size footnotesize 
30626 \SpecialChar ~
30627 \SpecialChar ~
30628 ret
30629 \newline 
30630
30631 \layout Section
30632
30633 A few words about basic block successors, predecessors and dominators
30634 \layout Standard
30635
30636 Successors are basic blocks
30637 \begin_inset LatexCommand \index{Basic blocks}
30638
30639 \end_inset 
30640
30641  that might execute after this basic block.
30642 \newline 
30643 Predecessors are basic blocks that might execute before reaching this basic
30644  block.
30645 \newline 
30646 Dominators are basic blocks that WILL execute before reaching this basic
30647  block.
30648 \newline 
30649
30650 \layout Standard
30651
30652 [basic block 1]
30653 \layout Standard
30654
30655 if (something)
30656 \layout Standard
30657
30658 \SpecialChar ~
30659 \SpecialChar ~
30660 \SpecialChar ~
30661 \SpecialChar ~
30662 [basic block 2]
30663 \layout Standard
30664
30665 else
30666 \layout Standard
30667
30668 \SpecialChar ~
30669 \SpecialChar ~
30670 \SpecialChar ~
30671 \SpecialChar ~
30672 [basic block 3]
30673 \layout Standard
30674
30675 [basic block 4]
30676 \newline 
30677
30678 \layout Standard
30679
30680 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
30681 \layout Standard
30682
30683 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
30684 \layout Standard
30685
30686 c) domVect of [BB4] = BB1 ...
30687  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
30688  was executed.
30689 \layout Chapter
30690
30691 Acknowledgments
30692 \layout Standard
30693
30694
30695 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
30696
30697 \end_inset 
30698
30699
30700 \newline 
30701
30702 \newline 
30703
30704 \emph on 
30705 Thanks to all the other volunteer developers who have helped with coding,
30706  testing, web-page creation, distribution sets, etc.
30707  You know who you are :-)
30708 \emph default 
30709
30710 \newline 
30711
30712 \layout Standard
30713
30714 This document was initially written by Sandeep Dutta
30715 \layout Standard
30716
30717 All product names mentioned herein may be trademarks
30718 \begin_inset LatexCommand \index{Trademarks}
30719
30720 \end_inset 
30721
30722  of their respective companies.
30723  
30724 \layout Section*
30725
30726 Alphabetical index
30727 \layout Standard
30728
30729 To avoid confusion, the installation and building options for SDCC itself
30730  (chapter 2) are not part of the index.
30731 \layout Standard
30732
30733
30734 \begin_inset LatexCommand \printindex{}
30735
30736 \end_inset 
30737
30738
30739 \the_end