* doc/Makefile.in: two runs of makeindex seem needed to get correct page references...
[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 CPU DS390                 embedded free Freescale GPL HC08 Intel manual Maxim mcs51 Microchip microcontroller open source PIC 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.5.6
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 retargetted for other microprocessors, support for Microchip
146  PIC, 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 retargettable 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  SDCDB and ucSim are currently not available on Win32 platforms.
583  
584 \newline 
585
586 \newline 
587 The latest version can be downloaded from 
588 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
589
590 \end_inset 
591
592 .
593
594 \series bold 
595  
596 \series default 
597 \emph on 
598 Please note: the compiler will probably always be some steps ahead of this
599  documentation
600 \series bold 
601 \emph default 
602
603 \begin_inset LatexCommand \index{Status of documentation}
604
605 \end_inset 
606
607
608 \begin_inset Foot
609 collapsed false
610
611 \layout Standard
612
613 Obviously this has pros and cons
614 \end_inset 
615
616 .
617 \layout Section
618
619 Open Source
620 \layout Standard
621
622 All packages used in this compiler system are 
623 \emph on 
624 open source
625 \emph default 
626  and 
627 \emph on 
628 freeware
629 \emph default 
630 ; source code for all the sub-packages (pre-processor, assemblers, linkers
631  etc) is distributed with the package.
632  This documentation is maintained using a freeware word processor (LyX).
633 \newline 
634 This program is free software; you can redistribute it and/or modify it
635  under the terms of the GNU General Public License
636 \begin_inset LatexCommand \index{GNU General Public License, GPL}
637
638 \end_inset 
639
640  as published by the Free Software Foundation; either version 2, or (at
641  your option) any later version.
642  This program is distributed in the hope that it will be useful, but WITHOUT
643  ANY WARRANTY; without even the implied warranty
644 \begin_inset LatexCommand \index{warranty}
645
646 \end_inset 
647
648  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
649  See the GNU General Public License for more details.
650  You should have received a copy of the GNU General Public License along
651  with this program; if not, write to the Free Software Foundation, 59 Temple
652  Place - Suite 330, Boston, MA 02111-1307, USA.
653  In other words, you are welcome to use, share and improve this program.
654  You are forbidden to forbid anyone else to use, share and improve what
655  you give them.
656  Help stamp out software-hoarding! 
657 \layout Section
658
659 Typographic conventions
660 \begin_inset LatexCommand \index{Typographic conventions}
661
662 \end_inset 
663
664
665 \layout Standard
666
667 Throughout this manual, we will use the following convention.
668  Commands you have to type in are printed in 
669 \family sans 
670 \series bold 
671 "sans serif"
672 \series default 
673 .
674
675 \family default 
676  Code samples are printed in 
677 \family typewriter 
678 typewriter font.
679
680 \family default 
681  Interesting items and new terms are printed in 
682 \emph on 
683 italic.
684 \layout Section
685
686 Compatibility
687 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
688
689 \end_inset 
690
691  with previous versions
692 \begin_inset LatexCommand \index{Compatibility with previous versions}
693
694 \end_inset 
695
696
697 \layout Standard
698
699 This version has numerous bug fixes compared with the previous version.
700  But we also introduced some incompatibilities with older versions.
701  Not just for the fun of it, but to make the compiler more stable, efficient
702  and ANSI compliant
703 \begin_inset LatexCommand \index{ANSI-compliance}
704
705 \end_inset 
706
707  (see section 
708 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
709
710 \end_inset 
711
712  for ANSI-Compliance).
713  
714 \newline 
715
716 \layout Itemize
717
718 short is now equivalent to int (16 bits), it used to be equivalent to char
719  (8 bits) which is not ANSI compliant.
720 \layout Itemize
721
722 the default directory for gcc-builds where include, library and documentation
723  files are stored is now in /usr/local/share.
724 \layout Itemize
725
726 char type parameters to vararg functions are casted to int unless explicitly
727  casted, e.g.: 
728 \newline 
729
730 \family typewriter 
731 \SpecialChar ~
732 \SpecialChar ~
733 char a=3;
734 \newline 
735 \SpecialChar ~
736 \SpecialChar ~
737 printf ("%d %c
738 \backslash 
739 n", a, (char)a);
740 \family default 
741
742 \newline 
743  will push a as an int and as a char resp.
744 \layout Itemize
745
746 option -
747 \begin_inset ERT
748 status Collapsed
749
750 \layout Standard
751
752 \backslash 
753 /
754 \end_inset 
755
756 -regextend has been removed.
757 \layout Itemize
758
759 option -
760 \begin_inset ERT
761 status Collapsed
762
763 \layout Standard
764
765 \backslash 
766 /
767 \end_inset 
768
769 -noregparms has been removed.
770 \layout Itemize
771
772 option -
773 \begin_inset ERT
774 status Collapsed
775
776 \layout Standard
777
778 \backslash 
779 /
780 \end_inset 
781
782 -stack-after-data has been removed.
783 \layout Itemize
784
785 bit
786 \begin_inset LatexCommand \index{bit}
787
788 \end_inset 
789
790  and sbit
791 \begin_inset LatexCommand \index{sbit}
792
793 \end_inset 
794
795
796 \begin_inset LatexCommand \index{\_\_sbit}
797
798 \end_inset 
799
800  types now consistently behave like the C99 _Bool type with respect to type
801  conversion
802 \begin_inset LatexCommand \index{type conversion}
803
804 \end_inset 
805
806
807 \begin_inset LatexCommand \index{type promotion}
808
809 \end_inset 
810
811 .
812  The most common incompatibility resulting from this change is related to
813  bit toggling
814 \begin_inset LatexCommand \index{Bit toggling}
815
816 \end_inset 
817
818  idioms, e.g.:
819 \newline 
820
821 \family typewriter 
822 \SpecialChar ~
823 \SpecialChar ~
824 bit b;
825 \newline 
826 \SpecialChar ~
827 \SpecialChar ~
828 b = ~b; /* equivalent to b=1 instead of toggling b */
829 \begin_inset Marginal
830 collapsed false
831
832 \layout Standard
833
834
835 \series bold 
836 \SpecialChar ~
837 !
838 \end_inset 
839
840
841 \newline 
842 \SpecialChar ~
843 \SpecialChar ~
844 b = !b; /* toggles b */
845 \newline 
846
847 \family default 
848 In previous versions, both forms would have toggled the bit.
849 \layout Standard
850
851
852 \emph on 
853 <pending: more incompatibilities?>
854 \layout Section
855
856 System Requirements
857 \layout Standard
858
859 What do you need before you start installation of SDCC? A computer, and
860  a desire to compute.
861  The preferred method of installation is to compile SDCC from source using
862  GNU gcc and make.
863  For Windows some pre-compiled binary distributions are available for your
864  convenience.
865  You should have some experience with command line tools and compiler use.
866 \layout Section
867
868 Other Resources
869 \layout Standard
870
871 The SDCC home page at 
872 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
873
874 \end_inset 
875
876  is a great place to find distribution sets.
877  You can also find links to the user mailing lists that offer help or discuss
878  SDCC with other SDCC users.
879  Web links to other SDCC related sites can also be found here.
880  This document can be found in the DOC directory of the source package as
881  a text or HTML file.
882  A pdf version of this document is available at 
883 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
884
885 \end_inset 
886
887 .
888  Some of the other tools (simulator and assembler) included with SDCC contain
889  their own documentation and can be found in the source distribution.
890  If you want the latest unreleased software, the complete source package
891  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
892 /trunk/sdcc.
893 \layout Section
894
895 Wishes for the future
896 \layout Standard
897
898 There are (and always will be) some things that could be done.
899  Here are some I can think of:
900 \newline 
901
902 \layout Standard
903
904
905 \family typewriter 
906 char KernelFunction3(char p) at 0x340;
907 \newline 
908
909 \layout Standard
910
911
912 \family typewriter 
913 better code banking
914 \begin_inset LatexCommand \index{code banking (limited support)}
915
916 \end_inset 
917
918  support for mcs51
919 \newline 
920
921 \newline 
922
923 \family default 
924 If you can think of some more, please see the section 
925 \begin_inset LatexCommand \ref{sub:Requesting-Features}
926
927 \end_inset 
928
929  about filing feature requests
930 \begin_inset LatexCommand \index{Requesting features}
931
932 \end_inset 
933
934
935 \begin_inset LatexCommand \index{Feature request}
936
937 \end_inset 
938
939 .
940 \newline 
941
942 \layout Chapter
943
944 Installing SDCC
945 \begin_inset LatexCommand \index{Installation}
946
947 \end_inset 
948
949
950 \layout Standard
951
952 For most users it is sufficient to skip to either section 
953 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
954
955 \end_inset 
956
957  or section 
958 \begin_inset LatexCommand \ref{sub:Windows-Install}
959
960 \end_inset 
961
962 .
963  More detailled instructions follow below.
964 \layout Section
965
966 Configure Options
967 \begin_inset LatexCommand \index{Options SDCC configuration}
968
969 \end_inset 
970
971
972 \layout Standard
973
974 The install paths, search paths and other options are defined when running
975  'configure'.
976  The defaults can be overridden by:
977 \layout List
978 \labelwidthstring 00.00.0000
979
980 -
981 \begin_inset ERT
982 status Collapsed
983
984 \layout Standard
985
986 \backslash 
987 /
988 \end_inset 
989
990 -prefix see table below
991 \layout List
992 \labelwidthstring 00.00.0000
993
994 -
995 \begin_inset ERT
996 status Collapsed
997
998 \layout Standard
999
1000 \backslash 
1001 /
1002 \end_inset 
1003
1004 -exec_prefix see table below
1005 \layout List
1006 \labelwidthstring 00.00.0000
1007
1008 -
1009 \begin_inset ERT
1010 status Collapsed
1011
1012 \layout Standard
1013
1014 \backslash 
1015 /
1016 \end_inset 
1017
1018 -bindir see table below
1019 \layout List
1020 \labelwidthstring 00.00.0000
1021
1022 -
1023 \begin_inset ERT
1024 status Collapsed
1025
1026 \layout Standard
1027
1028 \backslash 
1029 /
1030 \end_inset 
1031
1032 -datadir see table below
1033 \layout List
1034 \labelwidthstring 00.00.0000
1035
1036 docdir environment variable, see table below
1037 \layout List
1038 \labelwidthstring 00.00.0000
1039
1040 include_dir_suffix environment variable, see table below
1041 \layout List
1042 \labelwidthstring 00.00.0000
1043
1044 lib_dir_suffix environment variable, see table below
1045 \layout List
1046 \labelwidthstring 00.00.0000
1047
1048 sdccconf_h_dir_separator environment variable, either / or 
1049 \backslash 
1050
1051 \backslash 
1052  makes sense here.
1053  This character will only be used in sdccconf.h; don't forget it's a C-header,
1054  therefore a double-backslash is needed there.
1055 \layout List
1056 \labelwidthstring 00.00.0000
1057
1058 -
1059 \begin_inset ERT
1060 status Collapsed
1061
1062 \layout Standard
1063
1064 \backslash 
1065 /
1066 \end_inset 
1067
1068 -disable-mcs51-port Excludes the Intel mcs51 port
1069 \layout List
1070 \labelwidthstring 00.00.0000
1071
1072 -
1073 \begin_inset ERT
1074 status Collapsed
1075
1076 \layout Standard
1077
1078 \backslash 
1079 /
1080 \end_inset 
1081
1082 -disable-gbz80-port Excludes the Gameboy gbz80 port
1083 \layout List
1084 \labelwidthstring 00.00.0000
1085
1086 -
1087 \begin_inset ERT
1088 status Collapsed
1089
1090 \layout Standard
1091
1092 \backslash 
1093 /
1094 \end_inset 
1095
1096 -disable-z80-port Excludes the z80 port
1097 \layout List
1098 \labelwidthstring 00.00.0000
1099
1100 -
1101 \begin_inset ERT
1102 status Collapsed
1103
1104 \layout Standard
1105
1106 \backslash 
1107 /
1108 \end_inset 
1109
1110 -disable-avr-port Excludes the AVR port
1111 \layout List
1112 \labelwidthstring 00.00.0000
1113
1114 -
1115 \begin_inset ERT
1116 status Collapsed
1117
1118 \layout Standard
1119
1120 \backslash 
1121 /
1122 \end_inset 
1123
1124 -disable-ds390-port Excludes the DS390 port
1125 \layout List
1126 \labelwidthstring 00.00.0000
1127
1128 -
1129 \begin_inset ERT
1130 status Collapsed
1131
1132 \layout Standard
1133
1134 \backslash 
1135 /
1136 \end_inset 
1137
1138 -disable-hc08-port Excludes the HC08 port
1139 \layout List
1140 \labelwidthstring 00.00.0000
1141
1142 -
1143 \begin_inset ERT
1144 status Collapsed
1145
1146 \layout Standard
1147
1148 \backslash 
1149 /
1150 \end_inset 
1151
1152 -disable-pic-port Excludes the PIC port
1153 \layout List
1154 \labelwidthstring 00.00.0000
1155
1156 -
1157 \begin_inset ERT
1158 status Collapsed
1159
1160 \layout Standard
1161
1162 \backslash 
1163 /
1164 \end_inset 
1165
1166 -disable-xa51-port Excludes the XA51 port
1167 \layout List
1168 \labelwidthstring 00.00.0000
1169
1170 -
1171 \begin_inset ERT
1172 status Collapsed
1173
1174 \layout Standard
1175
1176 \backslash 
1177 /
1178 \end_inset 
1179
1180 -disable-ucsim Disables configuring and building of ucsim
1181 \layout List
1182 \labelwidthstring 00.00.0000
1183
1184 -
1185 \begin_inset ERT
1186 status Collapsed
1187
1188 \layout Standard
1189
1190 \backslash 
1191 /
1192 \end_inset 
1193
1194 -disable-device-lib Disables automatically building device libraries
1195 \layout List
1196 \labelwidthstring 00.00.0000
1197
1198 -
1199 \begin_inset ERT
1200 status Collapsed
1201
1202 \layout Standard
1203
1204 \backslash 
1205 /
1206 \end_inset 
1207
1208 -disable-packihx Disables building packihx
1209 \layout List
1210 \labelwidthstring 00.00.0000
1211
1212 -
1213 \begin_inset ERT
1214 status Collapsed
1215
1216 \layout Standard
1217
1218 \backslash 
1219 /
1220 \end_inset 
1221
1222 -enable-doc Build pdf, html and txt files from the lyx sources
1223 \layout List
1224 \labelwidthstring 00.00.0000
1225
1226 -
1227 \begin_inset ERT
1228 status Collapsed
1229
1230 \layout Standard
1231
1232 \backslash 
1233 /
1234 \end_inset 
1235
1236 -enable-libgc Use the Bohem memory allocator.
1237  Lower runtime footprint.
1238 \layout Standard
1239
1240 Furthermore the environment variables CC, CFLAGS, ...
1241  the tools and their arguments can be influenced.
1242  Please see `configure -
1243 \begin_inset ERT
1244 status Collapsed
1245
1246 \layout Standard
1247
1248 \backslash 
1249 /
1250 \end_inset 
1251
1252 -help` and the man/info pages of `configure` for details.
1253 \newline 
1254
1255 \newline 
1256 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1257  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1258 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1259  At the moment it's not possible to change the default settings (it was
1260  simply never required).
1261 \newline 
1262
1263 \newline 
1264 These configure options are compiled into the binaries, and can only be
1265  changed by rerunning 'configure' and recompiling SDCC.
1266  The configure options are written in 
1267 \emph on 
1268 italics
1269 \emph default 
1270  to distinguish them from run time environment variables (see section search
1271  paths).
1272 \newline 
1273
1274 \newline 
1275 The settings for 
1276 \begin_inset Quotes sld
1277 \end_inset 
1278
1279 Win32 builds
1280 \begin_inset Quotes srd
1281 \end_inset 
1282
1283  are used by the SDCC team to build the official Win32 binaries.
1284  The SDCC team uses Mingw32 to build the official Windows binaries, because
1285  it's
1286 \layout Enumerate
1287
1288 open source, 
1289 \layout Enumerate
1290
1291 a gcc compiler and last but not least
1292 \layout Enumerate
1293
1294 the binaries can be built by cross compiling on Sourceforge's compile farm.
1295 \layout Standard
1296
1297 See the examples, how to pass the Win32 settings to 'configure'.
1298  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1299  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1300  for Win32.
1301 \newline 
1302
1303 \newline 
1304 These defaults are:
1305 \newline 
1306
1307 \layout Standard
1308 \align center 
1309
1310 \begin_inset  Tabular
1311 <lyxtabular version="3" rows="8" columns="3">
1312 <features>
1313 <column alignment="block" valignment="top" leftline="true" width="0in">
1314 <column alignment="block" valignment="top" leftline="true" width="0in">
1315 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1316 <row topline="true" bottomline="true">
1317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1318 \begin_inset Text
1319
1320 \layout Standard
1321
1322 Variable
1323 \end_inset 
1324 </cell>
1325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1326 \begin_inset Text
1327
1328 \layout Standard
1329
1330 default
1331 \end_inset 
1332 </cell>
1333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1334 \begin_inset Text
1335
1336 \layout Standard
1337
1338 Win32 builds
1339 \end_inset 
1340 </cell>
1341 </row>
1342 <row topline="true">
1343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1344 \begin_inset Text
1345
1346 \layout Standard
1347
1348
1349 \emph on 
1350 PREFIX
1351 \end_inset 
1352 </cell>
1353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1354 \begin_inset Text
1355
1356 \layout Standard
1357
1358 /usr/local
1359 \end_inset 
1360 </cell>
1361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1362 \begin_inset Text
1363
1364 \layout Standard
1365
1366
1367 \backslash 
1368 sdcc
1369 \end_inset 
1370 </cell>
1371 </row>
1372 <row topline="true">
1373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1374 \begin_inset Text
1375
1376 \layout Standard
1377
1378
1379 \emph on 
1380 EXEC_PREFIX
1381 \end_inset 
1382 </cell>
1383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1384 \begin_inset Text
1385
1386 \layout Standard
1387
1388
1389 \emph on 
1390 $PREFIX
1391 \end_inset 
1392 </cell>
1393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1394 \begin_inset Text
1395
1396 \layout Standard
1397
1398
1399 \emph on 
1400 $PREFIX
1401 \end_inset 
1402 </cell>
1403 </row>
1404 <row topline="true">
1405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1406 \begin_inset Text
1407
1408 \layout Standard
1409
1410
1411 \emph on 
1412 BINDIR
1413 \end_inset 
1414 </cell>
1415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1416 \begin_inset Text
1417
1418 \layout Standard
1419
1420
1421 \emph on 
1422 $EXECPREFIX
1423 \emph default 
1424 /bin
1425 \end_inset 
1426 </cell>
1427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1428 \begin_inset Text
1429
1430 \layout Standard
1431
1432
1433 \emph on 
1434 $EXECPREFIX
1435 \emph default 
1436
1437 \backslash 
1438 bin
1439 \end_inset 
1440 </cell>
1441 </row>
1442 <row topline="true">
1443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1444 \begin_inset Text
1445
1446 \layout Standard
1447
1448
1449 \emph on 
1450 DATADIR
1451 \end_inset 
1452 </cell>
1453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1454 \begin_inset Text
1455
1456 \layout Standard
1457
1458
1459 \emph on 
1460 $PREFIX
1461 \emph default 
1462 /share
1463 \end_inset 
1464 </cell>
1465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1466 \begin_inset Text
1467
1468 \layout Standard
1469
1470
1471 \emph on 
1472 $PREFIX
1473 \end_inset 
1474 </cell>
1475 </row>
1476 <row topline="true">
1477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1478 \begin_inset Text
1479
1480 \layout Standard
1481
1482
1483 \emph on 
1484 DOCDIR
1485 \end_inset 
1486 </cell>
1487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1488 \begin_inset Text
1489
1490 \layout Standard
1491
1492
1493 \emph on 
1494 $DATADIR
1495 \emph default 
1496 /sdcc/doc
1497 \end_inset 
1498 </cell>
1499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1500 \begin_inset Text
1501
1502 \layout Standard
1503
1504
1505 \emph on 
1506 $DATADIR
1507 \emph default 
1508
1509 \backslash 
1510 doc
1511 \end_inset 
1512 </cell>
1513 </row>
1514 <row topline="true">
1515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1516 \begin_inset Text
1517
1518 \layout Standard
1519
1520
1521 \emph on 
1522 INCLUDE_DIR_SUFFIX
1523 \end_inset 
1524 </cell>
1525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1526 \begin_inset Text
1527
1528 \layout Standard
1529
1530 sdcc/include
1531 \end_inset 
1532 </cell>
1533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1534 \begin_inset Text
1535
1536 \layout Standard
1537
1538 include
1539 \end_inset 
1540 </cell>
1541 </row>
1542 <row topline="true" bottomline="true">
1543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1544 \begin_inset Text
1545
1546 \layout Standard
1547
1548
1549 \emph on 
1550 LIB_DIR_SUFFIX
1551 \end_inset 
1552 </cell>
1553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1554 \begin_inset Text
1555
1556 \layout Standard
1557
1558 sdcc/lib
1559 \end_inset 
1560 </cell>
1561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1562 \begin_inset Text
1563
1564 \layout Standard
1565
1566 lib
1567 \end_inset 
1568 </cell>
1569 </row>
1570 </lyxtabular>
1571
1572 \end_inset 
1573
1574
1575 \newline 
1576
1577 \layout Standard
1578 \noindent 
1579 'configure' also computes relative paths.
1580  This is needed for full relocatability of a binary package and to complete
1581  search paths (see section search paths below):
1582 \newline 
1583  
1584 \layout Standard
1585 \align center 
1586
1587 \begin_inset  Tabular
1588 <lyxtabular version="3" rows="4" columns="3">
1589 <features>
1590 <column alignment="block" valignment="top" leftline="true" width="0in">
1591 <column alignment="block" valignment="top" leftline="true" width="0in">
1592 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1593 <row topline="true" bottomline="true">
1594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1595 \begin_inset Text
1596
1597 \layout Standard
1598
1599 Variable (computed)
1600 \end_inset 
1601 </cell>
1602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1603 \begin_inset Text
1604
1605 \layout Standard
1606
1607 default
1608 \end_inset 
1609 </cell>
1610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1611 \begin_inset Text
1612
1613 \layout Standard
1614
1615 Win32 builds
1616 \end_inset 
1617 </cell>
1618 </row>
1619 <row topline="true" bottomline="true">
1620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1621 \begin_inset Text
1622
1623 \layout Standard
1624
1625
1626 \emph on 
1627 BIN2DATA_DIR
1628 \end_inset 
1629 </cell>
1630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1631 \begin_inset Text
1632
1633 \layout Standard
1634
1635 ../share
1636 \end_inset 
1637 </cell>
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1639 \begin_inset Text
1640
1641 \layout Standard
1642
1643 ..
1644 \end_inset 
1645 </cell>
1646 </row>
1647 <row bottomline="true">
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1649 \begin_inset Text
1650
1651 \layout Standard
1652
1653
1654 \emph on 
1655 PREFIX2BIN_DIR
1656 \end_inset 
1657 </cell>
1658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1659 \begin_inset Text
1660
1661 \layout Standard
1662
1663 bin
1664 \end_inset 
1665 </cell>
1666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1667 \begin_inset Text
1668
1669 \layout Standard
1670
1671 bin
1672 \end_inset 
1673 </cell>
1674 </row>
1675 <row bottomline="true">
1676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1677 \begin_inset Text
1678
1679 \layout Standard
1680
1681
1682 \emph on 
1683 PREFIX2DATA_DIR
1684 \end_inset 
1685 </cell>
1686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1687 \begin_inset Text
1688
1689 \layout Standard
1690
1691 share/sdcc
1692 \end_inset 
1693 </cell>
1694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1695 \begin_inset Text
1696
1697 \layout Standard
1698
1699 \end_inset 
1700 </cell>
1701 </row>
1702 </lyxtabular>
1703
1704 \end_inset 
1705
1706
1707 \newline 
1708
1709 \layout Standard
1710 \noindent 
1711 Examples:
1712 \layout LyX-Code
1713
1714 ./configure
1715 \newline 
1716 ./configure -
1717 \begin_inset ERT
1718 status Collapsed
1719
1720 \layout Standard
1721
1722 \backslash 
1723 /
1724 \end_inset 
1725
1726 -prefix=
1727 \begin_inset Quotes srd
1728 \end_inset 
1729
1730 /usr/bin
1731 \begin_inset Quotes srd
1732 \end_inset 
1733
1734  -
1735 \begin_inset ERT
1736 status Collapsed
1737
1738 \layout Standard
1739
1740 \backslash 
1741 /
1742 \end_inset 
1743
1744 -datadir=
1745 \begin_inset Quotes srd
1746 \end_inset 
1747
1748 /usr/share
1749 \begin_inset Quotes srd
1750 \end_inset 
1751
1752
1753 \newline 
1754 ./configure -
1755 \begin_inset ERT
1756 status Collapsed
1757
1758 \layout Standard
1759
1760 \backslash 
1761 /
1762 \end_inset 
1763
1764 -disable-avr-port -
1765 \begin_inset ERT
1766 status Collapsed
1767
1768 \layout Standard
1769
1770 \backslash 
1771 /
1772 \end_inset 
1773
1774 -disable-xa51-port
1775 \layout Standard
1776
1777 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1778 32'):
1779 \layout LyX-Code
1780
1781 ./configure 
1782 \backslash 
1783
1784 \newline 
1785 CC=
1786 \begin_inset Quotes srd
1787 \end_inset 
1788
1789 i586-mingw32msvc-gcc
1790 \begin_inset Quotes srd
1791 \end_inset 
1792
1793  CXX=
1794 \begin_inset Quotes srd
1795 \end_inset 
1796
1797 i586-mingw32msvc-g++
1798 \begin_inset Quotes srd
1799 \end_inset 
1800
1801  
1802 \backslash 
1803  
1804 \newline 
1805 RANLIB=
1806 \begin_inset Quotes srd
1807 \end_inset 
1808
1809 i586-mingw32msvc-ranlib
1810 \begin_inset Quotes srd
1811 \end_inset 
1812
1813  
1814 \backslash 
1815
1816 \newline 
1817 STRIP=
1818 \begin_inset Quotes srd
1819 \end_inset 
1820
1821 i586-mingw32msvc-strip
1822 \begin_inset Quotes srd
1823 \end_inset 
1824
1825  
1826 \backslash 
1827
1828 \newline 
1829 -
1830 \begin_inset ERT
1831 status Collapsed
1832
1833 \layout Standard
1834
1835 \backslash 
1836 /
1837 \end_inset 
1838
1839 -prefix=
1840 \begin_inset Quotes srd
1841 \end_inset 
1842
1843 /sdcc
1844 \begin_inset Quotes srd
1845 \end_inset 
1846
1847  
1848 \backslash 
1849
1850 \newline 
1851 -
1852 \begin_inset ERT
1853 status Collapsed
1854
1855 \layout Standard
1856
1857 \backslash 
1858 /
1859 \end_inset 
1860
1861 -datadir=
1862 \begin_inset Quotes srd
1863 \end_inset 
1864
1865 /sdcc
1866 \begin_inset Quotes srd
1867 \end_inset 
1868
1869  
1870 \backslash 
1871
1872 \newline 
1873 docdir=
1874 \begin_inset Quotes srd
1875 \end_inset 
1876
1877 /sdcc/doc
1878 \begin_inset Quotes srd
1879 \end_inset 
1880
1881  
1882 \backslash 
1883
1884 \newline 
1885 include_dir_suffix=
1886 \begin_inset Quotes srd
1887 \end_inset 
1888
1889 include
1890 \begin_inset Quotes srd
1891 \end_inset 
1892
1893  
1894 \backslash 
1895
1896 \newline 
1897 lib_dir_suffix=
1898 \begin_inset Quotes srd
1899 \end_inset 
1900
1901 lib
1902 \begin_inset Quotes srd
1903 \end_inset 
1904
1905  
1906 \backslash 
1907
1908 \newline 
1909 sdccconf_h_dir_separator=
1910 \begin_inset Quotes srd
1911 \end_inset 
1912
1913
1914 \backslash 
1915
1916 \backslash 
1917
1918 \backslash 
1919
1920 \backslash 
1921
1922 \begin_inset Quotes srd
1923 \end_inset 
1924
1925  
1926 \backslash 
1927
1928 \newline 
1929 -
1930 \begin_inset ERT
1931 status Collapsed
1932
1933 \layout Standard
1934
1935 \backslash 
1936 /
1937 \end_inset 
1938
1939 -disable-device-lib
1940 \backslash 
1941
1942 \newline 
1943 -
1944 \begin_inset ERT
1945 status Collapsed
1946
1947 \layout Standard
1948
1949 \backslash 
1950 /
1951 \end_inset 
1952
1953 -disable-ucsim
1954 \backslash 
1955
1956 \newline 
1957 -
1958 \begin_inset ERT
1959 status Collapsed
1960
1961 \layout Standard
1962
1963 \backslash 
1964 /
1965 \end_inset 
1966
1967 -host=i586-mingw32msvc -
1968 \begin_inset ERT
1969 status Collapsed
1970
1971 \layout Standard
1972
1973 \backslash 
1974 /
1975 \end_inset 
1976
1977 -build=unknown-unknown-linux-gnu
1978 \layout Standard
1979
1980 To 
1981 \begin_inset Quotes sld
1982 \end_inset 
1983
1984 cross
1985 \begin_inset Quotes srd
1986 \end_inset 
1987
1988 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1989 ):
1990 \layout LyX-Code
1991
1992 ./configure -C 
1993 \backslash 
1994
1995 \newline 
1996 CFLAGS=
1997 \begin_inset Quotes srd
1998 \end_inset 
1999
2000 -mno-cygwin -O2
2001 \begin_inset Quotes srd
2002 \end_inset 
2003
2004  
2005 \backslash 
2006
2007 \newline 
2008 LDFLAGS=
2009 \begin_inset Quotes srd
2010 \end_inset 
2011
2012 -mno-cygwin
2013 \begin_inset Quotes srd
2014 \end_inset 
2015
2016  
2017 \backslash 
2018
2019 \newline 
2020 -
2021 \begin_inset ERT
2022 status Collapsed
2023
2024 \layout Standard
2025
2026 \backslash 
2027 /
2028 \end_inset 
2029
2030 -prefix=
2031 \begin_inset Quotes srd
2032 \end_inset 
2033
2034 /sdcc
2035 \begin_inset Quotes srd
2036 \end_inset 
2037
2038  
2039 \backslash 
2040
2041 \newline 
2042 -
2043 \begin_inset ERT
2044 status Collapsed
2045
2046 \layout Standard
2047
2048 \backslash 
2049 /
2050 \end_inset 
2051
2052 -datadir=
2053 \begin_inset Quotes srd
2054 \end_inset 
2055
2056 /sdcc
2057 \begin_inset Quotes srd
2058 \end_inset 
2059
2060  
2061 \backslash 
2062
2063 \newline 
2064 docdir=
2065 \begin_inset Quotes srd
2066 \end_inset 
2067
2068 /sdcc/doc
2069 \begin_inset Quotes srd
2070 \end_inset 
2071
2072  
2073 \backslash 
2074  
2075 \newline 
2076 include_dir_suffix=
2077 \begin_inset Quotes srd
2078 \end_inset 
2079
2080 include
2081 \begin_inset Quotes srd
2082 \end_inset 
2083
2084  
2085 \backslash 
2086
2087 \newline 
2088 lib_dir_suffix=
2089 \begin_inset Quotes srd
2090 \end_inset 
2091
2092 lib
2093 \begin_inset Quotes srd
2094 \end_inset 
2095
2096  
2097 \backslash 
2098
2099 \newline 
2100 sdccconf_h_dir_separator=
2101 \begin_inset Quotes srd
2102 \end_inset 
2103
2104
2105 \backslash 
2106
2107 \backslash 
2108
2109 \backslash 
2110
2111 \backslash 
2112
2113 \begin_inset Quotes srd
2114 \end_inset 
2115
2116  
2117 \backslash 
2118
2119 \newline 
2120 -
2121 \begin_inset ERT
2122 status Collapsed
2123
2124 \layout Standard
2125
2126 \backslash 
2127 /
2128 \end_inset 
2129
2130 -disable-ucsim
2131 \layout Standard
2132
2133 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2134  The option '-
2135 \begin_inset ERT
2136 status Collapsed
2137
2138 \layout Standard
2139
2140 \backslash 
2141 /
2142 \end_inset 
2143
2144 -C' turns on caching, which gives a little bit extra speed.
2145  However if options are changed, it can be necessary to delete the config.cache
2146  file.
2147 \layout Section
2148
2149 Install paths
2150 \begin_inset LatexCommand \label{sub:Install-paths}
2151
2152 \end_inset 
2153
2154
2155 \begin_inset LatexCommand \index{Install paths}
2156
2157 \end_inset 
2158
2159
2160 \layout Standard
2161 \added_space_top medskip \align center 
2162
2163 \begin_inset  Tabular
2164 <lyxtabular version="3" rows="5" columns="4">
2165 <features>
2166 <column alignment="left" valignment="top" leftline="true" width="0">
2167 <column alignment="left" valignment="top" leftline="true" width="0">
2168 <column alignment="left" valignment="top" leftline="true" width="0">
2169 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2170 <row topline="true" bottomline="true">
2171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2172 \begin_inset Text
2173
2174 \layout Standard
2175
2176
2177 \series bold 
2178 Description
2179 \end_inset 
2180 </cell>
2181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2182 \begin_inset Text
2183
2184 \layout Standard
2185
2186
2187 \series bold 
2188 Path
2189 \end_inset 
2190 </cell>
2191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2192 \begin_inset Text
2193
2194 \layout Standard
2195
2196
2197 \series bold 
2198 Default
2199 \end_inset 
2200 </cell>
2201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2202 \begin_inset Text
2203
2204 \layout Standard
2205
2206
2207 \series bold 
2208 Win32 builds
2209 \end_inset 
2210 </cell>
2211 </row>
2212 <row topline="true">
2213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2214 \begin_inset Text
2215
2216 \layout Standard
2217
2218 Binary files*
2219 \end_inset 
2220 </cell>
2221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2222 \begin_inset Text
2223
2224 \layout Standard
2225
2226
2227 \emph on 
2228 $EXEC_PREFIX
2229 \end_inset 
2230 </cell>
2231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2232 \begin_inset Text
2233
2234 \layout Standard
2235
2236 /usr/local/bin
2237 \end_inset 
2238 </cell>
2239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2240 \begin_inset Text
2241
2242 \layout Standard
2243
2244
2245 \backslash 
2246 sdcc
2247 \backslash 
2248 bin
2249 \end_inset 
2250 </cell>
2251 </row>
2252 <row topline="true">
2253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2254 \begin_inset Text
2255
2256 \layout Standard
2257
2258 Include files
2259 \end_inset 
2260 </cell>
2261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2262 \begin_inset Text
2263
2264 \layout Standard
2265
2266
2267 \emph on 
2268 $DATADIR/ $INCLUDE_DIR_SUFFIX
2269 \end_inset 
2270 </cell>
2271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2272 \begin_inset Text
2273
2274 \layout Standard
2275
2276 /usr/local/share/sdcc/include
2277 \end_inset 
2278 </cell>
2279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2280 \begin_inset Text
2281
2282 \layout Standard
2283
2284
2285 \backslash 
2286 sdcc
2287 \backslash 
2288 include
2289 \end_inset 
2290 </cell>
2291 </row>
2292 <row topline="true">
2293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2294 \begin_inset Text
2295
2296 \layout Standard
2297
2298 Library file**
2299 \end_inset 
2300 </cell>
2301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2302 \begin_inset Text
2303
2304 \layout Standard
2305
2306
2307 \emph on 
2308 $DATADIR/$LIB_DIR_SUFFIX
2309 \end_inset 
2310 </cell>
2311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2312 \begin_inset Text
2313
2314 \layout Standard
2315
2316 /usr/local/share/sdcc/lib
2317 \end_inset 
2318 </cell>
2319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2320 \begin_inset Text
2321
2322 \layout Standard
2323
2324
2325 \backslash 
2326 sdcc
2327 \backslash 
2328 lib
2329 \end_inset 
2330 </cell>
2331 </row>
2332 <row topline="true" bottomline="true">
2333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2334 \begin_inset Text
2335
2336 \layout Standard
2337
2338 Documentation
2339 \end_inset 
2340 </cell>
2341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2342 \begin_inset Text
2343
2344 \layout Standard
2345
2346
2347 \emph on 
2348 $DOCDIR
2349 \end_inset 
2350 </cell>
2351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2352 \begin_inset Text
2353
2354 \layout Standard
2355
2356 /usr/local/share/sdcc/doc
2357 \end_inset 
2358 </cell>
2359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2360 \begin_inset Text
2361
2362 \layout Standard
2363
2364
2365 \backslash 
2366 sdcc
2367 \backslash 
2368 doc
2369 \end_inset 
2370 </cell>
2371 </row>
2372 </lyxtabular>
2373
2374 \end_inset 
2375
2376
2377 \layout Verse
2378
2379
2380 \size footnotesize 
2381 *compiler, preprocessor, assembler, and linker
2382 \newline 
2383 **the 
2384 \shape italic 
2385 model
2386 \shape default 
2387  is auto-appended by the compiler, e.g.
2388  small, large, z80, ds390 etc
2389 \layout Standard
2390 \noindent 
2391 The install paths can still be changed during `make install` with e.g.:
2392 \layout LyX-Code
2393
2394 make install prefix=$(HOME)/local/sdcc
2395 \layout Standard
2396
2397 Of course this doesn't change the search paths compiled into the binaries.
2398 \newline 
2399
2400 \newline 
2401 Moreover the install path can be changed by defining DESTDIR
2402 \begin_inset LatexCommand \index{DESTDIR}
2403
2404 \end_inset 
2405
2406 :
2407 \layout LyX-Code
2408
2409 make install DESTDIR=$(HOME)/sdcc.rpm/
2410 \layout Standard
2411
2412 Please note that DESTDIR must have a trailing slash!
2413 \layout Section
2414
2415 Search Paths
2416 \begin_inset LatexCommand \label{sub:Search-Paths}
2417
2418 \end_inset 
2419
2420
2421 \begin_inset LatexCommand \index{Search path}
2422
2423 \end_inset 
2424
2425
2426 \layout Standard
2427
2428 Some search paths or parts of them are determined by configure variables
2429  (in 
2430 \emph on 
2431 italics
2432 \emph default 
2433 , see section above).
2434  Further search paths are determined by environment variables during runtime.
2435  
2436 \newline 
2437 The paths searched when running the compiler are as follows (the first catch
2438  wins):
2439 \newline 
2440
2441 \newline 
2442 1.
2443  Binary files (preprocessor, assembler and linker)
2444 \newline 
2445
2446 \layout Standard
2447 \align center 
2448
2449 \begin_inset  Tabular
2450 <lyxtabular version="3" rows="4" columns="3">
2451 <features>
2452 <column alignment="block" valignment="top" leftline="true" width="0in">
2453 <column alignment="block" valignment="top" leftline="true" width="0in">
2454 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2455 <row topline="true" bottomline="true">
2456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2457 \begin_inset Text
2458
2459 \layout Standard
2460
2461 Search path
2462 \end_inset 
2463 </cell>
2464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2465 \begin_inset Text
2466
2467 \layout Standard
2468
2469 default
2470 \end_inset 
2471 </cell>
2472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2473 \begin_inset Text
2474
2475 \layout Standard
2476
2477 Win32 builds
2478 \end_inset 
2479 </cell>
2480 </row>
2481 <row topline="true">
2482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2483 \begin_inset Text
2484
2485 \layout Standard
2486
2487 $SDCC_HOME/
2488 \emph on 
2489 $PPREFIX2BIN_DIR
2490 \end_inset 
2491 </cell>
2492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2493 \begin_inset Text
2494
2495 \layout Standard
2496
2497 $SDCC_HOME/bin
2498 \end_inset 
2499 </cell>
2500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2501 \begin_inset Text
2502
2503 \layout Standard
2504
2505 $SDCC_HOME
2506 \backslash 
2507 bin
2508 \end_inset 
2509 </cell>
2510 </row>
2511 <row topline="true">
2512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2513 \begin_inset Text
2514
2515 \layout Standard
2516
2517 Path of argv[0] (if available)
2518 \end_inset 
2519 </cell>
2520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2521 \begin_inset Text
2522
2523 \layout Standard
2524
2525 Path of argv[0]
2526 \end_inset 
2527 </cell>
2528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2529 \begin_inset Text
2530
2531 \layout Standard
2532
2533 Path of argv[0]
2534 \end_inset 
2535 </cell>
2536 </row>
2537 <row topline="true" bottomline="true">
2538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2539 \begin_inset Text
2540
2541 \layout Standard
2542
2543 $PATH
2544 \end_inset 
2545 </cell>
2546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2547 \begin_inset Text
2548
2549 \layout Standard
2550
2551 $PATH
2552 \end_inset 
2553 </cell>
2554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2555 \begin_inset Text
2556
2557 \layout Standard
2558
2559 $PATH
2560 \end_inset 
2561 </cell>
2562 </row>
2563 </lyxtabular>
2564
2565 \end_inset 
2566
2567  
2568 \newline 
2569
2570 \layout Standard
2571 \noindent 
2572 2.
2573  Include files
2574 \newline 
2575
2576 \layout Standard
2577 \align center 
2578
2579 \begin_inset  Tabular
2580 <lyxtabular version="3" rows="6" columns="3">
2581 <features>
2582 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2583 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2584 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2585 <row topline="true" bottomline="true">
2586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2587 \begin_inset Text
2588
2589 \layout Standard
2590
2591 Search path
2592 \end_inset 
2593 </cell>
2594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2595 \begin_inset Text
2596
2597 \layout Standard
2598
2599 default
2600 \end_inset 
2601 </cell>
2602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2603 \begin_inset Text
2604
2605 \layout Standard
2606
2607 Win32 builds
2608 \end_inset 
2609 </cell>
2610 </row>
2611 <row topline="true">
2612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2613 \begin_inset Text
2614
2615 \layout Standard
2616
2617 -
2618 \begin_inset ERT
2619 status Collapsed
2620
2621 \layout Standard
2622
2623 \backslash 
2624 /
2625 \end_inset 
2626
2627 -I dir
2628 \end_inset 
2629 </cell>
2630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2631 \begin_inset Text
2632
2633 \layout Standard
2634
2635 -
2636 \begin_inset ERT
2637 status Collapsed
2638
2639 \layout Standard
2640
2641 \backslash 
2642 /
2643 \end_inset 
2644
2645 -I dir
2646 \end_inset 
2647 </cell>
2648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2649 \begin_inset Text
2650
2651 \layout Standard
2652
2653 -
2654 \begin_inset ERT
2655 status Collapsed
2656
2657 \layout Standard
2658
2659 \backslash 
2660 /
2661 \end_inset 
2662
2663 -I dir
2664 \end_inset 
2665 </cell>
2666 </row>
2667 <row topline="true">
2668 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2669 \begin_inset Text
2670
2671 \layout Standard
2672
2673 $SDCC_INCLUDE
2674 \end_inset 
2675 </cell>
2676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2677 \begin_inset Text
2678
2679 \layout Standard
2680
2681 $SDCC_INCLUDE
2682 \end_inset 
2683 </cell>
2684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2685 \begin_inset Text
2686
2687 \layout Standard
2688
2689 $SDCC_INCLUDE
2690 \end_inset 
2691 </cell>
2692 </row>
2693 <row topline="true">
2694 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2695 \begin_inset Text
2696
2697 \layout Standard
2698
2699 $SDCC_HOME/
2700 \newline 
2701
2702 \emph on 
2703 $PREFIX2DATA_DIR/
2704 \newline 
2705 $INCLUDE_DIR_SUFFIX
2706 \end_inset 
2707 </cell>
2708 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2709 \begin_inset Text
2710
2711 \layout Standard
2712
2713 $SDCC_ HOME/
2714 \newline 
2715 share/sdcc/
2716 \newline 
2717 include
2718 \end_inset 
2719 </cell>
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2721 \begin_inset Text
2722
2723 \layout Standard
2724
2725 $SDCC_HOME
2726 \backslash 
2727 include
2728 \end_inset 
2729 </cell>
2730 </row>
2731 <row topline="true">
2732 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2733 \begin_inset Text
2734
2735 \layout Standard
2736
2737 path(argv[0])/
2738 \newline 
2739
2740 \emph on 
2741 $BIN2DATADIR/
2742 \emph default 
2743
2744 \newline 
2745
2746 \emph on 
2747 $INCLUDE_DIR_SUFFIX
2748 \end_inset 
2749 </cell>
2750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2751 \begin_inset Text
2752
2753 \layout Standard
2754
2755 path(argv[0])/
2756 \newline 
2757 ../sdcc/include
2758 \newline 
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 \SpecialChar ~
2793 \SpecialChar ~
2794 \SpecialChar ~
2795 \SpecialChar ~
2796 \SpecialChar ~
2797
2798 \end_inset 
2799 </cell>
2800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2801 \begin_inset Text
2802
2803 \layout Standard
2804
2805 path(argv[0])
2806 \backslash 
2807 ..
2808 \backslash 
2809 include
2810 \end_inset 
2811 </cell>
2812 </row>
2813 <row topline="true" bottomline="true">
2814 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2815 \begin_inset Text
2816
2817 \layout Standard
2818
2819
2820 \emph on 
2821 $DATADIR/
2822 \emph default 
2823
2824 \newline 
2825
2826 \emph on 
2827 $INCLUDE_DIR_SUFFIX
2828 \end_inset 
2829 </cell>
2830 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2831 \begin_inset Text
2832
2833 \layout Standard
2834
2835 /usr/local/share/sdcc/
2836 \newline 
2837 include
2838 \end_inset 
2839 </cell>
2840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2841 \begin_inset Text
2842
2843 \layout Standard
2844
2845 (not on Win32)
2846 \end_inset 
2847 </cell>
2848 </row>
2849 </lyxtabular>
2850
2851 \end_inset 
2852
2853  
2854 \newline 
2855
2856 \layout Standard
2857 \noindent 
2858 The option -
2859 \begin_inset ERT
2860 status Collapsed
2861
2862 \layout Standard
2863
2864 \backslash 
2865 /
2866 \end_inset 
2867
2868 -nostdinc disables the last two search paths.
2869 \newline 
2870
2871 \newline 
2872 3.
2873  Library files 
2874 \newline 
2875
2876 \layout Standard
2877
2878 With the exception of 
2879 \begin_inset Quotes sld
2880 \end_inset 
2881
2882 -
2883 \begin_inset ERT
2884 status Collapsed
2885
2886 \layout Standard
2887
2888 \backslash 
2889 /
2890 \end_inset 
2891
2892 -L dir
2893 \begin_inset Quotes srd
2894 \end_inset 
2895
2896  the 
2897 \shape italic 
2898 model
2899 \shape default 
2900  is auto-appended by the compiler (e.g.
2901  small, large, z80, ds390 etc.).
2902  
2903 \newline 
2904
2905 \layout Standard
2906 \align center 
2907
2908 \begin_inset  Tabular
2909 <lyxtabular version="3" rows="6" columns="3">
2910 <features>
2911 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2912 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2913 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2914 <row topline="true" bottomline="true">
2915 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2916 \begin_inset Text
2917
2918 \layout Standard
2919
2920 Search path
2921 \end_inset 
2922 </cell>
2923 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2924 \begin_inset Text
2925
2926 \layout Standard
2927
2928 default
2929 \end_inset 
2930 </cell>
2931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2932 \begin_inset Text
2933
2934 \layout Standard
2935
2936 Win32 builds
2937 \end_inset 
2938 </cell>
2939 </row>
2940 <row topline="true">
2941 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2942 \begin_inset Text
2943
2944 \layout Standard
2945
2946 -
2947 \begin_inset ERT
2948 status Collapsed
2949
2950 \layout Standard
2951
2952 \backslash 
2953 /
2954 \end_inset 
2955
2956 -L dir
2957 \end_inset 
2958 </cell>
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_inset Text
2961
2962 \layout Standard
2963
2964 -
2965 \begin_inset ERT
2966 status Collapsed
2967
2968 \layout Standard
2969
2970 \backslash 
2971 /
2972 \end_inset 
2973
2974 -L dir
2975 \end_inset 
2976 </cell>
2977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2978 \begin_inset Text
2979
2980 \layout Standard
2981
2982 -
2983 \begin_inset ERT
2984 status Collapsed
2985
2986 \layout Standard
2987
2988 \backslash 
2989 /
2990 \end_inset 
2991
2992 -L dir
2993 \end_inset 
2994 </cell>
2995 </row>
2996 <row topline="true">
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2998 \begin_inset Text
2999
3000 \layout Standard
3001
3002 $SDCC_LIB/
3003 \newline 
3004
3005 \emph on 
3006 <model>
3007 \end_inset 
3008 </cell>
3009 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3010 \begin_inset Text
3011
3012 \layout Standard
3013
3014 $SDCC_LIB/
3015 \newline 
3016
3017 \emph on 
3018 <model>
3019 \end_inset 
3020 </cell>
3021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3022 \begin_inset Text
3023
3024 \layout Standard
3025
3026 $SDCC_LIB
3027 \backslash 
3028
3029 \newline 
3030
3031 \emph on 
3032 <model>
3033 \end_inset 
3034 </cell>
3035 </row>
3036 <row topline="true">
3037 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3038 \begin_inset Text
3039
3040 \layout Standard
3041
3042 $SDCC_HOME/
3043 \newline 
3044
3045 \emph on 
3046 $PREFIX2DATA_DIR/
3047 \newline 
3048 $LIB_DIR_SUFFIX/<model>
3049 \end_inset 
3050 </cell>
3051 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_inset Text
3053
3054 \layout Standard
3055
3056 $SDCC_HOME/
3057 \newline 
3058 share/sdcc/
3059 \newline 
3060 lib/
3061 \emph on 
3062 <model>
3063 \end_inset 
3064 </cell>
3065 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3066 \begin_inset Text
3067
3068 \layout Standard
3069
3070 $SDCC_HOME
3071 \backslash 
3072 lib
3073 \backslash 
3074
3075 \emph on 
3076
3077 \newline 
3078 <model>
3079 \end_inset 
3080 </cell>
3081 </row>
3082 <row topline="true">
3083 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3084 \begin_inset Text
3085
3086 \layout Standard
3087
3088 path(argv[0])/
3089 \newline 
3090
3091 \emph on 
3092 $BIN2DATADIR/
3093 \emph default 
3094
3095 \newline 
3096
3097 \emph on 
3098 $LIB_DIR_SUFFIX/<model>
3099 \end_inset 
3100 </cell>
3101 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3102 \begin_inset Text
3103
3104 \layout Standard
3105
3106 path(argv[0])/
3107 \newline 
3108 ../sdcc/lib/
3109 \emph on 
3110 <model>
3111 \newline 
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 \SpecialChar ~
3147 \SpecialChar ~
3148 \SpecialChar ~
3149 \SpecialChar ~
3150 \SpecialChar ~
3151
3152 \end_inset 
3153 </cell>
3154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3155 \begin_inset Text
3156
3157 \layout Standard
3158
3159 path(argv[0])
3160 \backslash 
3161
3162 \newline 
3163 ..
3164 \backslash 
3165 lib
3166 \backslash 
3167
3168 \emph on 
3169 <model>
3170 \newline 
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 \SpecialChar ~
3202 \SpecialChar ~
3203 \SpecialChar ~
3204 \SpecialChar ~
3205 \SpecialChar ~
3206
3207 \end_inset 
3208 </cell>
3209 </row>
3210 <row topline="true" bottomline="true">
3211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3212 \begin_inset Text
3213
3214 \layout Standard
3215
3216
3217 \emph on 
3218 $DATADIR/
3219 \newline 
3220 $LIB_DIR_SUFFIX/<model>
3221 \end_inset 
3222 </cell>
3223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3224 \begin_inset Text
3225
3226 \layout Standard
3227
3228 /usr/local/share/sdcc/
3229 \newline 
3230 lib/
3231 \emph on 
3232 <model>
3233 \end_inset 
3234 </cell>
3235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3236 \begin_inset Text
3237
3238 \layout Standard
3239
3240 (not on Win32)
3241 \end_inset 
3242 </cell>
3243 </row>
3244 </lyxtabular>
3245
3246 \end_inset 
3247
3248
3249 \newline 
3250
3251 \layout Comment
3252
3253 Don't delete any of the stray spaces in the table above without checking
3254  the HTML output (last line)!
3255 \layout Standard
3256
3257 \SpecialChar ~
3258
3259 \newline 
3260 The option -
3261 \begin_inset ERT
3262 status Collapsed
3263
3264 \layout Standard
3265
3266 \backslash 
3267 /
3268 \end_inset 
3269
3270 -nostdlib disables the last two search paths.
3271 \layout Section
3272
3273 Building SDCC
3274 \begin_inset LatexCommand \index{Building SDCC}
3275
3276 \end_inset 
3277
3278
3279 \layout Subsection
3280
3281 Building SDCC on Linux
3282 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3283
3284 \end_inset 
3285
3286
3287 \layout Enumerate
3288
3289
3290 \series medium 
3291 Download the source package
3292 \series default 
3293  either from the SDCC Subversion repository or from the nightly snapshots
3294 \series medium 
3295 , it will be named something like sdcc
3296 \series default 
3297 .src
3298 \series medium 
3299 .t
3300 \series default 
3301 ar.
3302 \series medium 
3303 gz
3304 \series default 
3305  
3306 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3307
3308 \end_inset 
3309
3310 .
3311 \layout Enumerate
3312
3313
3314 \series medium 
3315 Bring up a command line terminal, such as xterm.
3316 \layout Enumerate
3317
3318
3319 \series medium 
3320 Unpack the file using a command like: 
3321 \family sans 
3322 \series bold 
3323 "tar -xvzf sdcc.src.tar.gz
3324 \family default 
3325 \series default 
3326 "
3327 \series medium 
3328 , this will create a sub-directory called sdcc with all of the sources.
3329 \layout Enumerate
3330
3331 Change directory into the main SDCC directory, for example type: 
3332 \family sans 
3333 \series bold 
3334 "cd sdcc
3335 \series default 
3336 ".
3337 \layout Enumerate
3338
3339
3340 \series medium 
3341 Type 
3342 \family sans 
3343 \series bold 
3344 "./configure
3345 \family default 
3346 \series default 
3347 ".
3348  This configures the package for compilation on your system.
3349 \layout Enumerate
3350
3351
3352 \series medium 
3353 Type 
3354 \family sans 
3355 \series bold 
3356 "make
3357 \family default 
3358 \series default 
3359 "
3360 \series medium 
3361 .
3362
3363 \series default 
3364  All of the source packages will compile, this can take a while.
3365 \layout Enumerate
3366
3367
3368 \series medium 
3369 Type 
3370 \family sans 
3371 \series bold 
3372 "make install"
3373 \family default 
3374 \series default 
3375  as root
3376 \series medium 
3377 .
3378
3379 \series default 
3380  This copies the binary executables, the include files, the libraries and
3381  the documentation to the install directories.
3382  Proceed with section 
3383 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3384
3385 \end_inset 
3386
3387 .
3388 \layout Subsection
3389
3390 Building SDCC on OSX 2.x
3391 \layout Standard
3392
3393 Follow the instruction for Linux.
3394 \newline 
3395
3396 \newline 
3397 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3398 )) fails to compile SDCC.
3399  Fortunately there's also gcc 2.9.x installed, which works fine.
3400  This compiler can be selected by running 'configure' with:
3401 \layout LyX-Code
3402
3403 ./configure CC=gcc2 CXX=g++2
3404 \layout Subsection
3405
3406 Cross compiling SDCC on Linux for Windows
3407 \layout Standard
3408
3409 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3410  See section 'Configure Options'.
3411 \layout Subsection
3412
3413 Building SDCC on Windows 
3414 \layout Standard
3415
3416 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
3417  built on Windows.
3418  They use Unix-sockets, which are not available on Win32.
3419 \layout Subsection
3420
3421 Building SDCC using Cygwin and Mingw32
3422 \layout Standard
3423
3424 For building and installing a Cygwin executable follow the instructions
3425  for Linux.
3426 \newline 
3427
3428 \newline 
3429 On Cygwin a 
3430 \begin_inset Quotes sld
3431 \end_inset 
3432
3433 native
3434 \begin_inset Quotes srd
3435 \end_inset 
3436
3437  Win32-binary can be built, which will not need the Cygwin-DLL.
3438  For the necessary 'configure' options see section 'configure options' or
3439  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3440 \newline 
3441
3442 \newline 
3443 In order to install Cygwin on Windows download setup.exe from 
3444 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3445
3446 \end_inset 
3447
3448 .
3449  Run it, set the 
3450 \begin_inset Quotes sld
3451 \end_inset 
3452
3453 default text file type
3454 \begin_inset Quotes srd
3455 \end_inset 
3456
3457  to 
3458 \begin_inset Quotes sld
3459 \end_inset 
3460
3461 unix
3462 \begin_inset Quotes srd
3463 \end_inset 
3464
3465  and download/install at least the following packages.
3466  Some packages are selected by default, others will be automatically selected
3467  because of dependencies with the manually selected packages.
3468  Never deselect these packages!
3469 \layout Itemize
3470
3471 flex
3472 \layout Itemize
3473
3474 bison
3475 \layout Itemize
3476
3477 gcc ; version 3.x is fine, no need to use the old 2.9x
3478 \layout Itemize
3479
3480 binutils ; selected with gcc
3481 \layout Itemize
3482
3483 make
3484 \layout Itemize
3485
3486 rxvt ; a nice console, which makes life much easier under windoze (see below)
3487 \layout Itemize
3488
3489 man ; not really needed for building SDCC, but you'll miss it sooner or
3490  later
3491 \layout Itemize
3492
3493 less ; not really needed for building SDCC, but you'll miss it sooner or
3494  later
3495 \layout Itemize
3496
3497 svn ; only if you use Subversion access
3498 \layout Standard
3499
3500 If you want to develop something you'll need:
3501 \layout Itemize
3502
3503 python ; for the regression tests
3504 \layout Itemize
3505
3506 gdb ; the gnu debugger, together with the nice GUI 
3507 \begin_inset Quotes sld
3508 \end_inset 
3509
3510 insight
3511 \begin_inset Quotes srd
3512 \end_inset 
3513
3514
3515 \layout Itemize
3516
3517 openssh ; to access the CF or commit changes
3518 \layout Itemize
3519
3520 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3521  use autoconf-stable!
3522 \layout Standard
3523
3524 rxvt is a nice console with history.
3525  Replace in your cygwin.bat the line
3526 \layout LyX-Code
3527
3528 bash -
3529 \begin_inset ERT
3530 status Collapsed
3531
3532 \layout Standard
3533
3534 \backslash 
3535 /
3536 \end_inset 
3537
3538 -login -i 
3539 \layout Standard
3540
3541 with (one line):
3542 \layout LyX-Code
3543
3544 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3545 \layout LyX-Code
3546
3547      -bg black -fg white -geometry 100x65 -e bash -
3548 \begin_inset ERT
3549 status Collapsed
3550
3551 \layout Standard
3552
3553 \backslash 
3554 /
3555 \end_inset 
3556
3557 -login
3558 \layout Standard
3559
3560 Text selected with the mouse is automatically copied to the clipboard, pasting
3561  works with shift-insert.
3562 \newline 
3563
3564 \newline 
3565 The other good tip is to make sure you have no //c/-style paths anywhere,
3566  use /cygdrive/c/ instead.
3567  Using // invokes a network lookup which is very slow.
3568  If you think 
3569 \begin_inset Quotes sld
3570 \end_inset 
3571
3572 cygdrive
3573 \begin_inset Quotes srd
3574 \end_inset 
3575
3576  is too long, you can change it with e.g.
3577 \layout LyX-Code
3578
3579 mount -s -u -c /mnt
3580 \layout Standard
3581
3582 SDCC sources use the unix line ending LF.
3583  Life is much easier, if you store the source tree on a drive which is mounted
3584  in binary mode.
3585  And use an editor which can handle LF-only line endings.
3586  Make sure not to commit files with windows line endings.
3587  The tabulator spacing
3588 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3589
3590 \end_inset 
3591
3592  used in the project is 8.
3593  Although a tabulator spacing of 8 is a sensible choice for programmers
3594  (it's a power of 2 and allows to display 8/16 bit signed variables without
3595  loosing columns) the plan is to move towards using only spaces in the source.
3596 \layout Subsection
3597
3598 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3599 \layout Standard
3600
3601
3602 \series medium 
3603 Download the source package
3604 \series default 
3605  either from the SDCC Subversion repository or from the 
3606 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3607
3608 \end_inset 
3609
3610
3611 \series medium 
3612 , it will be named something like sdcc
3613 \series default 
3614 .src
3615 \series medium 
3616 .tgz.
3617
3618 \series default 
3619  SDCC is distributed with all the projects, workspaces, and files you need
3620  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3621  doesn't build under MSVC).
3622  The workspace name is 'sdcc.dsw'.
3623  Please note that as it is now, all the executables are created in a folder
3624  called sdcc
3625 \backslash 
3626 bin_vc.
3627  Once built you need to copy the executables from sdcc
3628 \backslash 
3629 bin_vc to sdcc
3630 \backslash 
3631 bin before running SDCC.
3632  
3633 \newline 
3634
3635 \newline 
3636 WARNING: Visual studio is very picky with line terminations; it expects
3637  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3638  When using the Subversion repository it's easiest to configure the svn
3639  client to convert automatically for you.
3640  If however you are getting a message such as "This makefile was not generated
3641  by Developer Studio etc.
3642  etc.
3643 \begin_inset Quotes srd
3644 \end_inset 
3645
3646  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3647  need to convert the Unix style line endings to DOS style line endings.
3648  To do so you can use the 
3649 \begin_inset Quotes sld
3650 \end_inset 
3651
3652 unix2dos
3653 \begin_inset Quotes srd
3654 \end_inset 
3655
3656  utility freely available on the internet.
3657  Doug Hawkins reported in the sdcc-user list that this works:
3658 \newline 
3659
3660 \newline 
3661 C:
3662 \backslash 
3663 Programming
3664 \backslash 
3665 SDCC> unix2dos sdcc.dsw
3666 \newline 
3667 C:
3668 \backslash 
3669 Programming
3670 \backslash 
3671 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3672 \newline 
3673
3674 \newline 
3675 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3676  flex.exe, and gawk.exe.
3677  One good place to get them is 
3678 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3679
3680 \end_inset 
3681
3682
3683 \newline 
3684
3685 \newline 
3686 Download the file UnxUtils
3687 \begin_inset LatexCommand \index{UnxUtils}
3688
3689 \end_inset 
3690
3691 .zip.
3692  Now you have to install the utilities and setup MSVC so it can locate the
3693  required programs.
3694  Here there are two alternatives (choose one!):
3695 \layout Enumerate
3696
3697 The easy way:
3698 \newline 
3699
3700 \newline 
3701 a) Extract UnxUtils.zip to your C:
3702 \backslash 
3703  hard disk PRESERVING the original paths, otherwise bison won't work.
3704  (If you are using WinZip make certain that 'Use folder names' is selected)
3705 \newline 
3706
3707 \newline 
3708 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3709  in 'Show directories for:' select 'Executable files', and in the directories
3710  window add a new path: 'C:
3711 \backslash 
3712 user
3713 \backslash 
3714 local
3715 \backslash 
3716 wbin', click ok.
3717 \newline 
3718
3719 \newline 
3720 (As a side effect, you get a bunch of Unix utilities that could be useful,
3721  such as diff and patch.)
3722 \layout Enumerate
3723
3724 A more compact way:
3725 \newline 
3726
3727 \newline 
3728 This one avoids extracting a bunch of files you may not use, but requires
3729  some extra work:
3730 \newline 
3731
3732 \newline 
3733 a) Create a directory were to put the tools needed, or use a directory already
3734  present.
3735  Say for example 'C:
3736 \backslash 
3737 util'.
3738 \newline 
3739
3740 \newline 
3741 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3742  to such directory WITHOUT preserving the original paths.
3743  (If you are using WinZip make certain that 'Use folder names' is not selected)
3744 \newline 
3745
3746 \newline 
3747 c) Rename bison.exe to '_bison.exe'.
3748 \newline 
3749
3750 \newline 
3751 d) Create a batch file 'bison.bat' in 'C:
3752 \backslash 
3753 util
3754 \backslash 
3755 ' and add these lines: 
3756 \newline 
3757 \SpecialChar ~
3758 \SpecialChar ~
3759 set BISON_SIMPLE=C:
3760 \backslash 
3761 util
3762 \backslash 
3763 bison.simple 
3764 \newline 
3765 \SpecialChar ~
3766 \SpecialChar ~
3767 set BISON_HAIRY=C:
3768 \backslash 
3769 util
3770 \backslash 
3771 bison.hairy
3772 \newline 
3773 \SpecialChar ~
3774 \SpecialChar ~
3775 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3776 \newline 
3777
3778 \newline 
3779 Steps 'c' and 'd' are needed because bison requires by default that the
3780  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3781  '/usr/local/share/' I think.
3782  So it is necessary to tell bison where those files are located if they
3783  are not in such directory.
3784  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3785 \newline 
3786
3787 \newline 
3788 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3789  in 'Show directories for:' select 'Executable files', and in the directories
3790  window add a new path: 'c:
3791 \backslash 
3792 util', click ok.
3793  Note that you can use any other path instead of 'c:
3794 \backslash 
3795 util', even the path where the Visual C++ tools are, probably: 'C:
3796 \backslash 
3797 Program Files
3798 \backslash 
3799 Microsoft Visual Studio
3800 \backslash 
3801 Common
3802 \backslash 
3803 Tools'.
3804  So you don't have to execute step 'e' :)
3805 \layout Standard
3806
3807 That is it.
3808  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3809  the executables from sdcc
3810 \backslash 
3811 bin_vc to sdcc
3812 \backslash 
3813 bin, and you can compile using SDCC.
3814 \layout Subsection
3815
3816 Building SDCC Using Borland
3817 \layout Enumerate
3818
3819 From the sdcc directory, run the command "make -f Makefile.bcc".
3820  This should regenerate all the .exe files in the bin directory except for
3821  sdcdb.exe (which currently doesn't build under Borland C++).
3822 \layout Enumerate
3823
3824 If you modify any source files and need to rebuild, be aware that the dependenci
3825 es may not be correctly calculated.
3826  The safest option is to delete all .obj files and run the build again.
3827  From a Cygwin BASH prompt, this can easily be done with the command (be
3828  sure you are in the sdcc directory):
3829 \newline 
3830
3831 \newline 
3832
3833 \family sans 
3834 \series bold 
3835 find .
3836  
3837 \backslash 
3838 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3839 \backslash 
3840 ) -print -exec rm {} 
3841 \backslash 
3842 ;
3843 \family default 
3844 \series default 
3845
3846 \newline 
3847
3848 \newline 
3849 or on Windows NT/2000/XP from the command prompt with the command:
3850 \newline 
3851
3852 \family sans 
3853 \series bold 
3854
3855 \newline 
3856 del /s *.obj *.lib *.rul
3857 \family default 
3858 \series default 
3859  from the sdcc directory.
3860 \layout Subsection
3861
3862 Windows Install Using a ZIP Package
3863 \layout Enumerate
3864
3865 Download the binary zip package from 
3866 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3867
3868 \end_inset 
3869
3870  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3871  This should unpack to a group of sub-directories.
3872  An example directory structure after unpacking the mingw32 package is:
3873  c:
3874 \backslash 
3875 sdcc
3876 \backslash 
3877 bin for the executables, c:
3878 \backslash 
3879 sdcc
3880 \backslash 
3881 include and c:
3882 \backslash 
3883 sdcc
3884 \backslash 
3885 lib for the include and libraries.
3886 \layout Enumerate
3887
3888 Adjust your environment variable PATH to include the location of the bin
3889  directory or start sdcc using the full path.
3890 \layout Subsection
3891
3892 Windows Install Using the Setup Program
3893 \begin_inset LatexCommand \label{sub:Windows-Install}
3894
3895 \end_inset 
3896
3897
3898 \layout Standard
3899
3900 Download the setup program 
3901 \emph on 
3902 sdcc-x.y.z-setup.exe
3903 \emph default 
3904  for an official release from 
3905 \newline 
3906
3907 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3908
3909 \end_inset 
3910
3911  or a setup program for one of the snapshots 
3912 \emph on 
3913 sdcc-yyyymmdd-xxxx-setup.exe
3914 \emph default 
3915  from 
3916 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3917
3918 \end_inset 
3919
3920  and execute it.
3921  A windows typical installer will guide you through the installation process.
3922 \layout Subsection
3923
3924 VPATH
3925 \begin_inset LatexCommand \index{VPATH}
3926
3927 \end_inset 
3928
3929  feature
3930 \layout Standard
3931
3932 SDCC supports the VPATH feature provided by configure and make.
3933  It allows to separate the source and build trees.
3934  Here's an example:
3935 \layout Standard
3936
3937
3938 \family typewriter 
3939 cd ~\SpecialChar ~
3940 \SpecialChar ~
3941 \SpecialChar ~
3942 \SpecialChar ~
3943 \SpecialChar ~
3944 \SpecialChar ~
3945 \SpecialChar ~
3946 \SpecialChar ~
3947 \SpecialChar ~
3948 \SpecialChar ~
3949 \SpecialChar ~
3950 \SpecialChar ~
3951 \SpecialChar ~
3952 \SpecialChar ~
3953 \SpecialChar ~
3954 \SpecialChar ~
3955 \SpecialChar ~
3956 \SpecialChar ~
3957 \SpecialChar ~
3958 \SpecialChar ~
3959 \SpecialChar ~
3960 # cd $HOME
3961 \layout Standard
3962
3963
3964 \family typewriter 
3965 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3966 # extract source to directory sdcc
3967 \layout Standard
3968
3969
3970 \family typewriter 
3971 mkdir sdcc.build\SpecialChar ~
3972 \SpecialChar ~
3973 \SpecialChar ~
3974 \SpecialChar ~
3975 \SpecialChar ~
3976 \SpecialChar ~
3977 \SpecialChar ~
3978 \SpecialChar ~
3979 \SpecialChar ~
3980 # put output in sdcc.build
3981 \layout Standard
3982
3983
3984 \family typewriter 
3985 cd sdcc.build
3986 \layout Standard
3987
3988
3989 \family typewriter 
3990 ../sdcc/configure\SpecialChar ~
3991 \SpecialChar ~
3992 \SpecialChar ~
3993 \SpecialChar ~
3994 \SpecialChar ~
3995 \SpecialChar ~
3996 \SpecialChar ~
3997 \SpecialChar ~
3998 # configure is doing all the magic!
3999 \layout Standard
4000
4001
4002 \family typewriter 
4003 make
4004 \layout Standard
4005 \noindent 
4006 That's it! 
4007 \series bold 
4008 configure
4009 \series default 
4010  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4011  It automagically computes the variables srcdir, top_srcdir and top_buildir
4012  for each directory.
4013  After running 
4014 \series bold 
4015 make
4016 \series default 
4017  the generated files will be in ~/sdcc.build, while the source files stay
4018  in ~/sdcc.
4019 \newline 
4020 This is not only usefull for building different binaries, e.g.
4021  when cross compiling.
4022  It also gives you a much better overview in the source tree when all the
4023  generated files are not scattered between the source files.
4024  And the best thing is: if you want to change a file you can leave the original
4025  file untouched in the source directory.
4026  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4027  Makefile.dep` and `make`.
4028  
4029 \series bold 
4030 make
4031 \series default 
4032  will do the rest for you!
4033 \layout Section
4034
4035 Building the Documentation
4036 \layout Standard
4037
4038 Add -
4039 \begin_inset ERT
4040 status Collapsed
4041
4042 \layout Standard
4043
4044 \backslash 
4045 /
4046 \end_inset 
4047
4048 -enable-doc to the configure arguments to build the documentation together
4049  with all the other stuff.
4050  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4051  dvips and makeindex) to get the job done.
4052  Another possibility is to change to the doc directory and to type 
4053 \family sans 
4054 \series bold 
4055
4056 \begin_inset Quotes srd
4057 \end_inset 
4058
4059 make
4060 \begin_inset Quotes srd
4061 \end_inset 
4062
4063
4064 \family default 
4065 \series default 
4066  there.
4067  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4068 x).
4069  Using LyX 
4070 \begin_inset LatexCommand \url{http://www.lyx.org}
4071
4072 \end_inset 
4073
4074  as editor is straightforward.
4075  Prebuilt documentation in html and pdf format is available from 
4076 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4077
4078 \end_inset 
4079
4080 .
4081 \layout Section
4082
4083 Reading the Documentation
4084 \layout Standard
4085
4086 Currently reading the document in pdf format is recommended, as for unknown
4087  reason the hyperlinks are working there whereas in the html version they
4088  are not
4089 \begin_inset Foot
4090 collapsed false
4091
4092 \layout Standard
4093
4094 If you should know why please drop us a note
4095 \end_inset 
4096
4097 .
4098  
4099 \newline 
4100 You'll find the pdf version
4101 \begin_inset LatexCommand \index{PDF version of this document}
4102
4103 \end_inset 
4104
4105  at 
4106 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4107
4108 \end_inset 
4109
4110 .
4111  
4112 \newline 
4113 A html version
4114 \begin_inset LatexCommand \index{HTML version of this document}
4115
4116 \end_inset 
4117
4118  should be online at 
4119 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4120
4121 \end_inset 
4122
4123 .
4124 \newline 
4125 This documentation is in some aspects different from a commercial documentation:
4126  
4127 \layout Itemize
4128
4129 It tries to document SDCC for several processor architectures in one document
4130  (commercially these probably would be separate documents/products).
4131  This document
4132 \begin_inset LatexCommand \index{Status of documentation}
4133
4134 \end_inset 
4135
4136  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4137 on about f.e.
4138  Z80, PIC14, PIC16 and HC08.
4139 \layout Itemize
4140
4141 There are many references pointing away from this documentation.
4142  Don't let this distract you.
4143  If there f.e.
4144  was a reference like 
4145 \begin_inset LatexCommand \url{http://www.opencores.org}
4146
4147 \end_inset 
4148
4149  together with a statement 
4150 \begin_inset Quotes sld
4151 \end_inset 
4152
4153 some processors which are targetted by SDCC can be implemented in a 
4154 \emph on 
4155 f
4156 \emph default 
4157 ield 
4158 \emph on 
4159 p
4160 \emph default 
4161 rogrammable 
4162 \emph on 
4163 g
4164 \emph default 
4165 ate 
4166 \emph on 
4167 a
4168 \emph default 
4169 rray
4170 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4171
4172 \end_inset 
4173
4174
4175 \begin_inset Quotes srd
4176 \end_inset 
4177
4178  or 
4179 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4180
4181 \end_inset 
4182
4183
4184 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4185
4186 \end_inset 
4187
4188  
4189 \begin_inset Quotes sld
4190 \end_inset 
4191
4192 have you ever heard of an open source compiler that compiles a subset of
4193  C for an FPGA?
4194 \begin_inset Quotes srd
4195 \end_inset 
4196
4197  we expect you to have a quick look there and come back.
4198  If you read this you are on the right track.
4199 \layout Itemize
4200
4201 Some sections attribute more space to problems, restrictions and warnings
4202  than to the solution.
4203 \layout Itemize
4204
4205 The installation section and the section about the debugger is intimidating.
4206 \layout Itemize
4207
4208 There are still lots of typos and there are more different writing styles
4209  than pictures.
4210 \layout Section
4211
4212 Testing the SDCC Compiler
4213 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4214
4215 \end_inset 
4216
4217
4218 \layout Standard
4219
4220 The first thing you should do after installing your SDCC compiler is to
4221  see if it runs.
4222  Type 
4223 \family sans 
4224 \series bold 
4225 "sdcc -
4226 \begin_inset ERT
4227 status Collapsed
4228
4229 \layout Standard
4230
4231 \backslash 
4232 /
4233 \end_inset 
4234
4235 -version"
4236 \begin_inset LatexCommand \index{version}
4237
4238 \end_inset 
4239
4240
4241 \family default 
4242 \series default 
4243  at the prompt, and the program should run and output its version like:
4244  
4245 \newline 
4246
4247 \family typewriter 
4248 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4249  (UNIX)
4250 \layout Standard
4251
4252 If it doesn't run, or gives a message about not finding sdcc program, then
4253  you need to check over your installation.
4254  Make sure that the sdcc bin directory is in your executable search path
4255  defined by the PATH environment setting (
4256 \series medium 
4257 see 
4258 \series default 
4259 section 
4260 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4261
4262 \end_inset 
4263
4264 \SpecialChar ~
4265
4266 \series medium 
4267 Install trouble-shooting for suggestions
4268 \series default 
4269 ).
4270  Make sure that the sdcc program is in the bin folder, if not perhaps something
4271  did not install correctly.
4272 \newline 
4273
4274 \newline 
4275
4276 \series medium 
4277 SDCC 
4278 \series default 
4279 is commonly installed as described in section 
4280 \begin_inset Quotes sld
4281 \end_inset 
4282
4283 Install and search paths
4284 \begin_inset Quotes srd
4285 \end_inset 
4286
4287 .
4288 \newline 
4289
4290 \newline 
4291
4292 \series medium 
4293 Make sure the compiler works on a very simple example.
4294  Type in the following test.c program using your favorite 
4295 \series default 
4296 ASCII 
4297 \series medium 
4298 editor:
4299 \layout Verse
4300
4301
4302 \family typewriter 
4303 char test;
4304 \newline 
4305
4306 \newline 
4307 void main(void) {
4308 \newline 
4309 \SpecialChar ~
4310 \SpecialChar ~
4311 \SpecialChar ~
4312 \SpecialChar ~
4313 test=0;
4314 \newline 
4315 }
4316 \layout Standard
4317
4318
4319 \series medium 
4320 Compile this using the following command: 
4321 \family sans 
4322 \series bold 
4323 "sdcc -c test.c".
4324
4325 \family default 
4326 \series default 
4327  
4328 \series medium 
4329 If all goes well, the compiler will generate a test.asm and test.rel file.
4330  Congratulations, you've just compiled your first program with SDCC.
4331  We used the -c option to tell SDCC not to link the generated code, just
4332  to keep things simple for this step.
4333 \series default 
4334
4335 \newline 
4336
4337 \newline 
4338
4339 \series medium 
4340 The next step is to try it with the linker.
4341  Type in 
4342 \family sans 
4343 \series bold 
4344 "sdcc test.c
4345 \family default 
4346 \series default 
4347 "
4348 \series medium 
4349 .
4350  If all goes well the compiler will link with the libraries and produce
4351  a test.ihx output file.
4352  If this step fails
4353 \series default 
4354  
4355 \series medium 
4356 (no test.ihx, and the linker generates warnings), then the problem is most
4357  likely that 
4358 \series default 
4359 SDCC
4360 \series medium 
4361  cannot find the 
4362 \series default 
4363 /
4364 \series medium 
4365 usr/local/share/sdcc/lib directory
4366 \series default 
4367  
4368 \series medium 
4369 (see 
4370 \series default 
4371 section 
4372 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4373
4374 \end_inset 
4375
4376 \SpecialChar ~
4377
4378 \series medium 
4379 Install trouble-shooting for suggestions).
4380 \series default 
4381
4382 \newline 
4383
4384 \newline 
4385
4386 \series medium 
4387 The final test is to ensure 
4388 \series default 
4389 SDCC
4390 \series medium 
4391  can use the 
4392 \series default 
4393 standard
4394 \series medium 
4395  header files and libraries.
4396  Edit test.c and change it to the following:
4397 \layout Verse
4398
4399
4400 \family typewriter 
4401 #include <string.h>
4402 \newline 
4403
4404 \newline 
4405 char str1[10];
4406 \newline 
4407
4408 \newline 
4409 void main(void) {
4410 \newline 
4411 \SpecialChar ~
4412 \SpecialChar ~
4413 strcpy(str1, "testing");
4414 \newline 
4415 }
4416 \layout Standard
4417
4418
4419 \series medium 
4420 Compile this by typing 
4421 \family sans 
4422 \series bold 
4423 "sdcc test.c"
4424 \family default 
4425 \series medium 
4426 .
4427  This should generate a test.ihx output file, and it should give no warnings
4428  such as not finding the string.h file.
4429  If it cannot find the string.h file, then the problem is that 
4430 \series default 
4431 SDCC
4432 \series medium 
4433  cannot find the /usr/local/share/sdcc/include directory
4434 \series default 
4435  
4436 \series medium 
4437 (see the 
4438 \series default 
4439 section 
4440 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4441
4442 \end_inset 
4443
4444 \SpecialChar ~
4445
4446 \series medium 
4447 Install trouble-shooting section for suggestions).
4448
4449 \series default 
4450  Use option 
4451 \series bold 
4452 -
4453 \begin_inset ERT
4454 status Collapsed
4455
4456 \layout Standard
4457
4458 \backslash 
4459 /
4460 \end_inset 
4461
4462 -print-search-dirs
4463 \series default 
4464
4465 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4466
4467 \end_inset 
4468
4469  to find exactly where SDCC is looking for the include and lib files.
4470 \layout Section
4471
4472 Install Trouble-shooting
4473 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4474
4475 \end_inset 
4476
4477
4478 \begin_inset LatexCommand \index{Install trouble-shooting}
4479
4480 \end_inset 
4481
4482
4483 \layout Subsection
4484
4485 If SDCC does not build correctly
4486 \layout Standard
4487
4488 A thing to try is starting from scratch by unpacking the .tgz source package
4489  again in an empty directory.
4490  Configure it like:
4491 \newline 
4492
4493 \newline 
4494
4495 \family sans 
4496 \series bold 
4497 ./configure 2>&1 | tee configure.log
4498 \family default 
4499 \series default 
4500
4501 \newline 
4502
4503 \newline 
4504 and build it like:
4505 \newline 
4506
4507 \newline 
4508
4509 \family sans 
4510 \series bold 
4511 make 2>&1 | tee make.log
4512 \family default 
4513 \series default 
4514
4515 \newline 
4516
4517 \newline 
4518 If anything goes wrong, you can review the log files to locate the problem.
4519  Or a relevant part of this can be attached to an email that could be helpful
4520  when requesting help from the mailing list.
4521 \layout Subsection
4522
4523 What the 
4524 \begin_inset Quotes sld
4525 \end_inset 
4526
4527 ./configure
4528 \begin_inset Quotes srd
4529 \end_inset 
4530
4531  does
4532 \layout Standard
4533
4534 The 
4535 \begin_inset Quotes sld
4536 \end_inset 
4537
4538 ./configure
4539 \begin_inset Quotes srd
4540 \end_inset 
4541
4542  command is a script that analyzes your system and performs some configuration
4543  to ensure the source package compiles on your system.
4544  It will take a few minutes to run, and will compile a few tests to determine
4545  what compiler features are installed.
4546 \layout Subsection
4547
4548 What the 
4549 \begin_inset Quotes sld
4550 \end_inset 
4551
4552 make
4553 \begin_inset Quotes srd
4554 \end_inset 
4555
4556  does
4557 \layout Standard
4558
4559 This runs the GNU make tool, which automatically compiles all the source
4560  packages into the final installed binary executables.
4561 \layout Subsection
4562
4563 What the 
4564 \begin_inset Quotes sld
4565 \end_inset 
4566
4567 make install
4568 \begin_inset Quotes erd
4569 \end_inset 
4570
4571  command does.
4572 \layout Standard
4573
4574 This will install the compiler, other executables libraries and include
4575  files into the appropriate directories.
4576  See sections 
4577 \begin_inset LatexCommand \ref{sub:Install-paths}
4578
4579 \end_inset 
4580
4581 ,\SpecialChar ~
4582
4583 \begin_inset LatexCommand \ref{sub:Search-Paths}
4584
4585 \end_inset 
4586
4587 \SpecialChar ~
4588 about install and search paths.
4589 \newline 
4590 On most systems you will need super-user privileges to do this.
4591 \layout Section
4592
4593 Components of SDCC
4594 \layout Standard
4595
4596 SDCC is not just a compiler, but a collection of tools by various developers.
4597  These include linkers, assemblers, simulators and other components.
4598  Here is a summary of some of the components.
4599  Note that the included simulator and assembler have separate documentation
4600  which you can find in the source package in their respective directories.
4601  As SDCC grows to include support for other processors, other packages from
4602  various developers are included and may have their own sets of documentation.
4603 \newline 
4604
4605 \newline 
4606 You might want to look at the files which are installed in <installdir>.
4607  At the time of this writing, we find the following programs for gcc-builds:
4608 \newline 
4609  
4610 \newline 
4611 In <installdir>/bin:
4612 \layout Itemize
4613
4614 sdcc - The compiler.
4615 \layout Itemize
4616
4617 sdcpp - The C preprocessor.
4618 \layout Itemize
4619
4620 asx8051 - The assembler for 8051 type processors.
4621 \layout Itemize
4622
4623 as-z80
4624 \series bold 
4625
4626 \series default 
4627 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4628 \layout Itemize
4629
4630 aslink -The linker for 8051 type processors.
4631 \layout Itemize
4632
4633 link-z80
4634 \series bold 
4635
4636 \series default 
4637 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4638 \layout Itemize
4639
4640 s51 - The ucSim 8051 simulator.
4641  Not available on Win32 platforms.
4642 \layout Itemize
4643
4644 sdcdb - The source debugger.
4645  Not available on Win32 platforms.
4646 \layout Itemize
4647
4648 packihx - A tool to pack (compress) Intel hex files.
4649 \layout Standard
4650
4651 In <installdir>/share/sdcc/include
4652 \layout Itemize
4653
4654 the include files
4655 \layout Standard
4656
4657 In <installdir>/share/sdcc/lib
4658 \layout Itemize
4659
4660 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4661  relocatables.
4662 \layout Standard
4663
4664 In <installdir>/share/sdcc/doc
4665 \layout Itemize
4666
4667 the documentation
4668 \layout Standard
4669
4670 As development for other processors proceeds, this list will expand to include
4671  executables to support processors like AVR, PIC, etc.
4672 \layout Subsection
4673
4674 sdcc - The Compiler
4675 \layout Standard
4676
4677 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4678  the assembler and linkage editor.
4679 \layout Subsection
4680
4681 sdcpp - The C-Preprocessor
4682 \layout Standard
4683
4684 The preprocessor
4685 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4686
4687 \end_inset 
4688
4689  is a modified version of the GNU preprocessor.
4690  The C preprocessor is used to pull in #include sources, process #ifdef
4691  statements, #defines and so on.
4692 \layout Subsection
4693
4694 as
4695 \emph on 
4696 xxxx
4697 \emph default 
4698 , aslink, link-
4699 \emph on 
4700 xxx
4701 \emph default 
4702  - The Assemblers and Linkage Editors
4703 \layout Standard
4704
4705 This is retargettable assembler & linkage editor, it was developed by Alan
4706  Baldwin.
4707  John Hartman created the version for 8051, and I (Sandeep) have made some
4708  enhancements and bug fixes for it to work properly with SDCC.
4709 \layout Subsection
4710
4711 s51 - The Simulator
4712 \layout Standard
4713
4714 S51
4715 \begin_inset LatexCommand \index{s51}
4716
4717 \end_inset 
4718
4719  is a freeware, opensource simulator developed by Daniel Drotos.
4720  The simulator is built as part of the build process.
4721  For more information visit Daniel's web site at: 
4722 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4723
4724 \end_inset 
4725
4726 .
4727  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4728  XA51 family.
4729  S51 is currently not available on Win32 platfors.
4730 \layout Subsection
4731
4732 sdcdb - Source Level Debugger
4733 \layout Standard
4734
4735 Sdcdb
4736 \begin_inset LatexCommand \index{sdcdb (debugger)}
4737
4738 \end_inset 
4739
4740  is the companion source level debugger.
4741  More about sdcdb in section 
4742 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4743
4744 \end_inset 
4745
4746 .
4747  The current version of the debugger uses Daniel's Simulator S51
4748 \begin_inset LatexCommand \index{s51}
4749
4750 \end_inset 
4751
4752 , but can be easily changed to use other simulators.
4753  Sdcdb is currently not available on Win32 platfors.
4754 \layout Chapter
4755
4756 Using SDCC
4757 \layout Section
4758
4759 Compiling
4760 \layout Subsection
4761
4762 Single Source File Projects
4763 \layout Standard
4764
4765 For single source file 8051 projects the process is very simple.
4766  Compile your programs with the following command 
4767 \family sans 
4768 \series bold 
4769 "sdcc sourcefile.c".
4770
4771 \family default 
4772 \series default 
4773  This will compile, assemble and link your source file.
4774  Output files are as follows:
4775 \layout Itemize
4776
4777 sourcefile.asm
4778 \begin_inset LatexCommand \index{<file>.asm}
4779
4780 \end_inset 
4781
4782  - Assembler source
4783 \begin_inset LatexCommand \index{Assembler source}
4784
4785 \end_inset 
4786
4787  file created by the compiler
4788 \layout Itemize
4789
4790 sourcefile.lst
4791 \begin_inset LatexCommand \index{<file>.lst}
4792
4793 \end_inset 
4794
4795  - Assembler listing
4796 \begin_inset LatexCommand \index{Assembler listing}
4797
4798 \end_inset 
4799
4800  file created by the Assembler
4801 \layout Itemize
4802
4803 sourcefile.rst
4804 \begin_inset LatexCommand \index{<file>.rst}
4805
4806 \end_inset 
4807
4808  - Assembler listing
4809 \begin_inset LatexCommand \index{Assembler listing}
4810
4811 \end_inset 
4812
4813  file updated with linkedit information, created by linkage editor
4814 \layout Itemize
4815
4816 sourcefile.sym
4817 \begin_inset LatexCommand \index{<file>.sym}
4818
4819 \end_inset 
4820
4821  - symbol listing
4822 \begin_inset LatexCommand \index{Symbol listing}
4823
4824 \end_inset 
4825
4826  for the sourcefile, created by the assembler
4827 \layout Itemize
4828
4829 sourcefile.rel
4830 \begin_inset LatexCommand \index{<file>.rel}
4831
4832 \end_inset 
4833
4834  or sourcefile.o
4835 \begin_inset LatexCommand \index{<file>.o}
4836
4837 \end_inset 
4838
4839  - Object file
4840 \begin_inset LatexCommand \index{Object file}
4841
4842 \end_inset 
4843
4844  created by the assembler, input to Linkage editor
4845 \layout Itemize
4846
4847 sourcefile.map
4848 \begin_inset LatexCommand \index{<file>.map}
4849
4850 \end_inset 
4851
4852  - The memory map
4853 \begin_inset LatexCommand \index{Memory map}
4854
4855 \end_inset 
4856
4857  for the load module, created by the Linker
4858 \layout Itemize
4859
4860 sourcefile.mem
4861 \begin_inset LatexCommand \index{<file>.mem}
4862
4863 \end_inset 
4864
4865  - A file with a summary of the memory usage
4866 \layout Itemize
4867
4868 sourcefile.ihx
4869 \begin_inset LatexCommand \index{<file>.ihx}
4870
4871 \end_inset 
4872
4873  - The load module in Intel hex format
4874 \begin_inset LatexCommand \index{Intel hex format}
4875
4876 \end_inset 
4877
4878  (you can select the Motorola S19 format
4879 \begin_inset LatexCommand \index{Motorola S19 format}
4880
4881 \end_inset 
4882
4883  with -
4884 \begin_inset ERT
4885 status Collapsed
4886
4887 \layout Standard
4888
4889 \backslash 
4890 /
4891 \end_inset 
4892
4893 -out-fmt-s19
4894 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4895
4896 \end_inset 
4897
4898 .
4899  If you need another format you might want to use 
4900 \family sans 
4901 \shape italic 
4902 objdump
4903 \family default 
4904 \shape default 
4905
4906 \begin_inset LatexCommand \index{objdump (tool)}
4907
4908 \end_inset 
4909
4910  or
4911 \family sans 
4912 \shape italic 
4913  srecord
4914 \family default 
4915 \shape default 
4916
4917 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4918
4919 \end_inset 
4920
4921 ).
4922  Both formats are documented in the documentation of srecord
4923 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4924
4925 \end_inset 
4926
4927
4928 \layout Itemize
4929
4930 sourcefile.adb
4931 \begin_inset LatexCommand \index{<file>.adb}
4932
4933 \end_inset 
4934
4935  - An intermediate file containing debug information needed to create the
4936  .cdb file (with -
4937 \begin_inset ERT
4938 status Open
4939
4940 \layout Standard
4941
4942 \backslash 
4943 /
4944 \end_inset 
4945
4946 -debug
4947 \begin_inset LatexCommand \index{-\/-debug}
4948
4949 \end_inset 
4950
4951
4952 \layout Itemize
4953
4954 sourcefile.cdb
4955 \begin_inset LatexCommand \index{<file>.cdb}
4956
4957 \end_inset 
4958
4959  - An optional file (with -
4960 \begin_inset ERT
4961 status Collapsed
4962
4963 \layout Standard
4964
4965 \backslash 
4966 /
4967 \end_inset 
4968
4969 -debug) containing debug information.
4970  The format is documented in cdbfileformat.pdf
4971 \layout Itemize
4972
4973 sourcefile.
4974  - (no extension)
4975 \begin_inset LatexCommand \index{<file> (no extension)}
4976
4977 \end_inset 
4978
4979  An optional AOMF or AOMF51
4980 \begin_inset LatexCommand \index{AOMF, AOMF51}
4981
4982 \end_inset 
4983
4984  
4985 \begin_inset LatexCommand \label{OMF file}
4986
4987 \end_inset 
4988
4989 file containing debug information (generated with option -
4990 \begin_inset ERT
4991 status Collapsed
4992
4993 \layout Standard
4994
4995 \backslash 
4996 /
4997 \end_inset 
4998
4999 -debug).
5000  The (Intel)
5001 \emph on 
5002  a
5003 \emph default 
5004 bsolute 
5005 \emph on 
5006 o
5007 \emph default 
5008 bject 
5009 \emph on 
5010 m
5011 \emph default 
5012 odule 
5013 \emph on 
5014 f
5015 \emph default 
5016 ormat is commonly used by third party tools (debuggers
5017 \begin_inset LatexCommand \index{Debugger}
5018
5019 \end_inset 
5020
5021 , simulators, emulators)
5022 \layout Itemize
5023
5024 sourcefile.dump*
5025 \begin_inset LatexCommand \index{<file>.dump*}
5026
5027 \end_inset 
5028
5029  - Dump file to debug the compiler it self (generated with option -
5030 \begin_inset ERT
5031 status Collapsed
5032
5033 \layout Standard
5034
5035 \backslash 
5036 /
5037 \end_inset 
5038
5039 -dumpall) (see section 
5040 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5041
5042 \end_inset 
5043
5044 \SpecialChar ~
5045  and section 
5046 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5047
5048 \end_inset 
5049
5050 \SpecialChar ~
5051
5052 \begin_inset Quotes sld
5053 \end_inset 
5054
5055 Anatomy of the compiler
5056 \begin_inset Quotes srd
5057 \end_inset 
5058
5059 ).
5060 \layout Subsection
5061
5062 Projects with Multiple Source Files
5063 \layout Standard
5064
5065 SDCC can compile only ONE file at a time.
5066  Let us for example assume that you have a project containing the following
5067  files:
5068 \newline 
5069
5070 \newline 
5071 foo1.c (contains some functions)
5072 \newline 
5073 foo2.c (contains some more functions)
5074 \newline 
5075 foomain.c (contains more functions and the function main)
5076 \newline 
5077
5078 \size footnotesize 
5079
5080 \newline 
5081
5082 \size default 
5083 The first two files will need to be compiled separately with the commands:
5084 \size footnotesize 
5085  
5086 \size default 
5087
5088 \newline 
5089
5090 \newline 
5091
5092 \family sans 
5093 \series bold 
5094 sdcc\SpecialChar ~
5095 -c\SpecialChar ~
5096 foo1.c
5097 \family default 
5098 \series default 
5099 \size footnotesize 
5100
5101 \newline 
5102
5103 \family sans 
5104 \series bold 
5105 \size default 
5106 sdcc\SpecialChar ~
5107 -c\SpecialChar ~
5108 foo2.c
5109 \family default 
5110 \series default 
5111
5112 \newline 
5113
5114 \newline 
5115 Then compile the source file containing the 
5116 \emph on 
5117 main()
5118 \emph default 
5119  function and link
5120 \begin_inset LatexCommand \index{Linker}
5121
5122 \end_inset 
5123
5124  the files together with the following command: 
5125 \newline 
5126
5127 \newline 
5128
5129 \family sans 
5130 \series bold 
5131 sdcc\SpecialChar ~
5132 foomain.c\SpecialChar ~
5133 foo1.rel\SpecialChar ~
5134 foo2.rel
5135 \family default 
5136 \series default 
5137
5138 \begin_inset LatexCommand \index{<file>.rel}
5139
5140 \end_inset 
5141
5142
5143 \newline 
5144
5145 \newline 
5146 Alternatively, 
5147 \emph on 
5148 foomain.c 
5149 \emph default 
5150 can be separately compiled as well: 
5151 \family sans 
5152 \series bold 
5153
5154 \newline 
5155
5156 \newline 
5157 sdcc\SpecialChar ~
5158 -c\SpecialChar ~
5159 foomain.c
5160 \newline 
5161 sdcc foomain.rel foo1.rel foo2.rel
5162 \newline 
5163
5164 \newline 
5165
5166 \family default 
5167 \series default 
5168 The file containing the 
5169 \emph on 
5170 main()
5171 \emph default 
5172  function
5173 \emph on 
5174  
5175 \emph default 
5176 \noun on 
5177 must
5178 \noun default 
5179  be the 
5180 \noun on 
5181 first
5182 \noun default 
5183  file specified in the command line, since the linkage editor processes
5184  file in the order they are presented to it.
5185  The linker is invoked from SDCC using a script file with extension .lnk
5186 \begin_inset LatexCommand \index{<file>.lnk}
5187
5188 \end_inset 
5189
5190 .
5191  You can view this file to troubleshoot linking problems such as those arising
5192  from missing libraries.
5193 \layout Subsection
5194
5195 Projects with Additional Libraries
5196 \begin_inset LatexCommand \index{Libraries}
5197
5198 \end_inset 
5199
5200
5201 \layout Standard
5202
5203 Some reusable routines may be compiled into a library, see the documentation
5204  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5205  for how to create a 
5206 \emph on 
5207 .lib
5208 \begin_inset LatexCommand \index{<file>.lib}
5209
5210 \end_inset 
5211
5212
5213 \emph default 
5214  library file.
5215  Libraries created in this manner can be included in the command line.
5216  Make sure you include the -L <library-path> option to tell the linker where
5217  to look for these files if they are not in the current directory.
5218  Here is an example, assuming you have the source file 
5219 \emph on 
5220 foomain.c
5221 \emph default 
5222  and a library
5223 \emph on 
5224  foolib.lib
5225 \emph default 
5226  in the directory 
5227 \emph on 
5228 mylib
5229 \emph default 
5230  (if that is not the same as your current project):
5231 \newline 
5232
5233 \newline 
5234
5235 \family sans 
5236 \series bold 
5237 sdcc foomain.c foolib.lib -L mylib
5238 \newline 
5239
5240 \newline 
5241
5242 \family default 
5243 \series default 
5244 Note here that
5245 \emph on 
5246  mylib
5247 \emph default 
5248  must be an absolute path name.
5249 \newline 
5250
5251 \newline 
5252 The most efficient way to use libraries is to keep separate modules in separate
5253  source files.
5254  The lib file now should name all the modules.rel
5255 \begin_inset LatexCommand \index{<file>.rel}
5256
5257 \end_inset 
5258
5259  files.
5260  For an example see the standard library file 
5261 \emph on 
5262 libsdcc.lib
5263 \emph default 
5264  in the directory <installdir>/share/lib/small.
5265 \layout Subsection
5266
5267 Using sdcclib to Create and Manage Libraries
5268 \begin_inset LatexCommand \index{sdcclib}
5269
5270 \end_inset 
5271
5272
5273 \layout Standard
5274
5275 Alternatively, instead of having a .rel file for each entry on the library
5276  file as described in the preceding section, sdcclib can be used to embed
5277  all the modules belonging to such library in the library file itself.
5278  This results in a larger library file, but it greatly reduces the number
5279  of disk files accessed by the linker.
5280   Additionally, the packed library file contains an index of all include
5281  modules and symbols that significantly speeds up the linking process.
5282  To display a list of options supported by sdcclib type:
5283 \newline 
5284
5285 \layout Standard
5286
5287
5288 \family sans 
5289 \series bold 
5290 sdcclib -?
5291 \begin_inset LatexCommand \index{sdcclib}
5292
5293 \end_inset 
5294
5295
5296 \newline 
5297
5298 \newline 
5299
5300 \family default 
5301 \series default 
5302 To create a new library file, start by compiling all the required modules.
5303  For example:
5304 \newline 
5305
5306 \layout Standard
5307
5308
5309 \family sans 
5310 \series bold 
5311 sdcc -c _divsint.c
5312 \layout Standard
5313
5314
5315 \family sans 
5316 \series bold 
5317 sdcc -c _divuint.c
5318 \layout Standard
5319
5320
5321 \family sans 
5322 \series bold 
5323 sdcc -c _modsint.c
5324 \layout Standard
5325
5326
5327 \family sans 
5328 \series bold 
5329 sdcc -c _moduint.c
5330 \layout Standard
5331
5332
5333 \family sans 
5334 \series bold 
5335 sdcc -c _mulint.c
5336 \newline 
5337
5338 \layout Standard
5339
5340 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5341  and _mulint.rel.
5342  The next step is to add the .rel files to the library file:
5343 \newline 
5344
5345 \layout Standard
5346
5347
5348 \family sans 
5349 \series bold 
5350 sdcclib libint.lib _divsint.rel
5351 \family default 
5352
5353 \begin_inset LatexCommand \index{sdcclib}
5354
5355 \end_inset 
5356
5357
5358 \layout Standard
5359
5360
5361 \family sans 
5362 \series bold 
5363 sdcclib libint.lib _divuint.rel
5364 \layout Standard
5365
5366
5367 \family sans 
5368 \series bold 
5369 sdcclib libint.lib _modsint.rel
5370 \layout Standard
5371
5372
5373 \family sans 
5374 \series bold 
5375 sdcclib libint.lib _moduint.rel
5376 \layout Standard
5377
5378
5379 \family sans 
5380 \series bold 
5381 sdcclib libint.lib _mulint.rel
5382 \series default 
5383
5384 \newline 
5385
5386 \layout Standard
5387
5388 If the file already exists in the library, it will be replaced.
5389  To see what modules and symbols are included in the library, options -s
5390  and -m are available.
5391  For example:
5392 \newline 
5393
5394 \newline 
5395
5396 \family sans 
5397 \series bold 
5398 sdcclib -s libint.lib
5399 \family default 
5400
5401 \begin_inset LatexCommand \index{sdcclib}
5402
5403 \end_inset 
5404
5405
5406 \newline 
5407
5408 \family typewriter 
5409 \series default 
5410 _divsint.rel:
5411 \layout Standard
5412
5413
5414 \family typewriter 
5415 __divsint_a_1_1
5416 \layout Standard
5417
5418
5419 \family typewriter 
5420 __divsint_PARM_2
5421 \layout Standard
5422
5423
5424 \family typewriter 
5425 __divsint
5426 \newline 
5427 _divuint.rel:
5428 \layout Standard
5429
5430
5431 \family typewriter 
5432 __divuint_a_1_1
5433 \layout Standard
5434
5435
5436 \family typewriter 
5437 __divuint_PARM_2
5438 \layout Standard
5439
5440
5441 \family typewriter 
5442 __divuint_reste_1_1
5443 \layout Standard
5444
5445
5446 \family typewriter 
5447 __divuint_count_1_1
5448 \layout Standard
5449
5450
5451 \family typewriter 
5452 __divuint
5453 \newline 
5454 _modsint.rel:
5455 \layout Standard
5456
5457
5458 \family typewriter 
5459 __modsint_a_1_1
5460 \layout Standard
5461
5462
5463 \family typewriter 
5464 __modsint_PARM_2
5465 \layout Standard
5466
5467
5468 \family typewriter 
5469 __modsint
5470 \newline 
5471 _moduint.rel:
5472 \layout Standard
5473
5474
5475 \family typewriter 
5476 __moduint_a_1_1
5477 \layout Standard
5478
5479
5480 \family typewriter 
5481 __moduint_PARM_2
5482 \layout Standard
5483
5484
5485 \family typewriter 
5486 __moduint_count_1_1
5487 \layout Standard
5488
5489
5490 \family typewriter 
5491 __moduint
5492 \newline 
5493 _mulint.rel:
5494 \layout Standard
5495
5496
5497 \family typewriter 
5498 __mulint_PARM_2
5499 \layout Standard
5500
5501
5502 \family typewriter 
5503 __mulint
5504 \family default 
5505 \series bold 
5506
5507 \newline 
5508
5509 \layout Standard
5510
5511 If the source files are compiled using -
5512 \begin_inset ERT
5513 status Open
5514
5515 \layout Standard
5516
5517 \backslash 
5518 /
5519 \end_inset 
5520
5521 -debug
5522 \begin_inset LatexCommand \index{-\/-debug}
5523
5524 \end_inset 
5525
5526 , the corresponding debug information file .adb will be include in the library
5527  file as well.
5528  The library files created with sdcclib are plain text files, so they can
5529  be viewed with a text editor.
5530  It is not recomended to modify a library file created with sdcclib using
5531  a text editor, as there are file indexes numbers located accross the file
5532  used by the linker to quickly locate the required module to link.
5533  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5534  it can be safely deleted, since all the information required for linking
5535  is embedded in the library file itself.
5536  Library files created using sdcclib are used as described in the preceding
5537  sections.
5538 \layout Section
5539
5540 Command Line Options
5541 \begin_inset LatexCommand \index{Command Line Options}
5542
5543 \end_inset 
5544
5545
5546 \layout Subsection
5547
5548 Processor Selection Options
5549 \begin_inset LatexCommand \index{Options processor selection}
5550
5551 \end_inset 
5552
5553
5554 \begin_inset LatexCommand \index{Processor selection options}
5555
5556 \end_inset 
5557
5558
5559 \layout List
5560 \labelwidthstring 00.00.0000
5561
5562
5563 \series bold 
5564 -mmcs51
5565 \begin_inset LatexCommand \index{-mmcs51}
5566
5567 \end_inset 
5568
5569
5570 \series default 
5571  Generate code for the Intel MCS51
5572 \begin_inset LatexCommand \index{MCS51}
5573
5574 \end_inset 
5575
5576  family of processors.
5577  This is the default processor target.
5578 \layout List
5579 \labelwidthstring 00.00.0000
5580
5581
5582 \series bold 
5583 -mds390
5584 \begin_inset LatexCommand \index{-mds390}
5585
5586 \end_inset 
5587
5588
5589 \series default 
5590  Generate code for the Dallas DS80C390
5591 \begin_inset LatexCommand \index{DS80C390}
5592
5593 \end_inset 
5594
5595  processor.
5596 \layout List
5597 \labelwidthstring 00.00.0000
5598
5599
5600 \series bold 
5601 -mds400
5602 \begin_inset LatexCommand \index{-mds400}
5603
5604 \end_inset 
5605
5606
5607 \series default 
5608  Generate code for the Dallas DS80C400
5609 \begin_inset LatexCommand \index{DS80C400}
5610
5611 \end_inset 
5612
5613  processor.
5614 \layout List
5615 \labelwidthstring 00.00.0000
5616
5617
5618 \series bold 
5619 -mhc08
5620 \begin_inset LatexCommand \index{-mhc08}
5621
5622 \end_inset 
5623
5624
5625 \series default 
5626  Generate code for the Freescale/Motorola HC08
5627 \begin_inset LatexCommand \index{HC08}
5628
5629 \end_inset 
5630
5631  family of processors.
5632 \layout List
5633 \labelwidthstring 00.00.0000
5634
5635
5636 \series bold 
5637 -mz80
5638 \begin_inset LatexCommand \index{-mz80}
5639
5640 \end_inset 
5641
5642
5643 \series default 
5644  Generate code for the Zilog Z80
5645 \begin_inset LatexCommand \index{Z80}
5646
5647 \end_inset 
5648
5649  family of processors.
5650 \layout List
5651 \labelwidthstring 00.00.0000
5652
5653
5654 \series bold 
5655 -mgbz80
5656 \begin_inset LatexCommand \index{-mgbz80}
5657
5658 \end_inset 
5659
5660
5661 \series default 
5662  Generate code for the GameBoy Z80
5663 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5664
5665 \end_inset 
5666
5667  processor (Not actively maintained).
5668 \layout List
5669 \labelwidthstring 00.00.0000
5670
5671
5672 \series bold 
5673 -mavr
5674 \begin_inset LatexCommand \index{-mavr}
5675
5676 \end_inset 
5677
5678
5679 \series default 
5680  Generate code for the Atmel AVR
5681 \begin_inset LatexCommand \index{AVR}
5682
5683 \end_inset 
5684
5685  processor (In development, not complete).
5686  AVR users should probably have a look at winavr 
5687 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5688
5689 \end_inset 
5690
5691  or 
5692 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5693
5694 \end_inset 
5695
5696 .
5697 \layout Comment
5698
5699 I think it is fair to direct users there for now.
5700  Open source is also about avoiding unnecessary work .
5701  But I didn't find the 'official' link.
5702 \layout List
5703 \labelwidthstring 00.00.0000
5704
5705
5706 \series bold 
5707 -mpic14
5708 \begin_inset LatexCommand \index{-mpic14}
5709
5710 \end_inset 
5711
5712
5713 \series default 
5714  Generate code for the Microchip PIC 14
5715 \begin_inset LatexCommand \index{PIC14}
5716
5717 \end_inset 
5718
5719 -bit processors (p16f84 and variants.
5720  In development, not complete).
5721 \layout Comment
5722
5723 p16f627 p16f628 p16f84 p16f873 p16f877?
5724 \layout List
5725 \labelwidthstring 00.00.0000
5726
5727
5728 \series bold 
5729 -mpic16
5730 \begin_inset LatexCommand \index{-mpic16}
5731
5732 \end_inset 
5733
5734
5735 \series default 
5736  Generate code for the Microchip PIC 16
5737 \begin_inset LatexCommand \index{PIC16}
5738
5739 \end_inset 
5740
5741 -bit processors (p18f452 and variants.
5742  In development, not complete).
5743 \layout List
5744 \labelwidthstring 00.00.0000
5745
5746
5747 \series bold 
5748 -mtlcs900h
5749 \series default 
5750  Generate code for the Toshiba TLCS-900H
5751 \begin_inset LatexCommand \index{TLCS-900H}
5752
5753 \end_inset 
5754
5755  processor (Not maintained, not complete).
5756 \layout List
5757 \labelwidthstring 00.00.0000
5758
5759
5760 \series bold 
5761 -mxa51
5762 \begin_inset LatexCommand \index{-mxa51}
5763
5764 \end_inset 
5765
5766
5767 \series default 
5768  Generate code for the Phillips XA51
5769 \begin_inset LatexCommand \index{XA51}
5770
5771 \end_inset 
5772
5773  processor (Not maintained, not complete).
5774 \layout Subsection
5775
5776 Preprocessor Options
5777 \begin_inset LatexCommand \index{Options preprocessor}
5778
5779 \end_inset 
5780
5781
5782 \begin_inset LatexCommand \index{Preprocessor options}
5783
5784 \end_inset 
5785
5786
5787 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5788
5789 \end_inset 
5790
5791
5792 \layout List
5793 \labelwidthstring 00.00.0000
5794
5795
5796 \series bold 
5797 -I<path>
5798 \begin_inset LatexCommand \index{-I<path>}
5799
5800 \end_inset 
5801
5802
5803 \series default 
5804  The additional location where the pre processor will look for <..h> or 
5805 \begin_inset Quotes eld
5806 \end_inset 
5807
5808 ..h
5809 \begin_inset Quotes erd
5810 \end_inset 
5811
5812  files.
5813 \layout List
5814 \labelwidthstring 00.00.0000
5815
5816
5817 \series bold 
5818 -D<macro[=value]>
5819 \begin_inset LatexCommand \index{-D<macro[=value]>}
5820
5821 \end_inset 
5822
5823
5824 \series default 
5825  Command line definition of macros.
5826  Passed to the preprocessor.
5827 \layout List
5828 \labelwidthstring 00.00.0000
5829
5830
5831 \series bold 
5832 -M
5833 \begin_inset LatexCommand \index{-M}
5834
5835 \end_inset 
5836
5837
5838 \series default 
5839  Tell the preprocessor to output a rule suitable for make describing the
5840  dependencies of each object file.
5841  For each source file, the preprocessor outputs one make-rule whose target
5842  is the object file name for that source file and whose dependencies are
5843  all the files `#include'd in it.
5844  This rule may be a single line or may be continued with `
5845 \backslash 
5846 '-newline if it is long.
5847  The list of rules is printed on standard output instead of the preprocessed
5848  C program.
5849  `-M' implies `-E
5850 \begin_inset LatexCommand \index{-E}
5851
5852 \end_inset 
5853
5854 '.
5855 \layout List
5856 \labelwidthstring 00.00.0000
5857
5858
5859 \series bold 
5860 -C
5861 \begin_inset LatexCommand \index{-C}
5862
5863 \end_inset 
5864
5865
5866 \series default 
5867  Tell the preprocessor not to discard comments.
5868  Used with the `-E' option.
5869 \layout List
5870 \labelwidthstring 00.00.0000
5871
5872
5873 \series bold 
5874 -MM
5875 \begin_inset LatexCommand \index{-MM}
5876
5877 \end_inset 
5878
5879
5880 \size large 
5881 \bar under 
5882  
5883 \series default 
5884 \size default 
5885 \bar default 
5886 Like `-M' but the output mentions only the user header files included with
5887  `#include 
5888 \begin_inset Quotes eld
5889 \end_inset 
5890
5891 file"'.
5892  System header files included with `#include <file>' are omitted.
5893 \layout List
5894 \labelwidthstring 00.00.0000
5895
5896
5897 \series bold 
5898 -Aquestion(answer)
5899 \begin_inset LatexCommand \index{-Aquestion(answer)}
5900
5901 \end_inset 
5902
5903
5904 \series default 
5905  Assert the answer answer for question, in case it is tested with a preprocessor
5906  conditional such as `#if #question(answer)'.
5907  `-A-' disables the standard assertions that normally describe the target
5908  machine.
5909 \layout List
5910 \labelwidthstring 00.00.0000
5911
5912
5913 \series bold 
5914 -Umacro
5915 \begin_inset LatexCommand \index{-Umacro}
5916
5917 \end_inset 
5918
5919
5920 \series default 
5921  Undefine macro macro.
5922  `-U' options are evaluated after all `-D' options, but before any `-include'
5923  and `-imacros' options.
5924 \layout List
5925 \labelwidthstring 00.00.0000
5926
5927
5928 \series bold 
5929 -dM
5930 \begin_inset LatexCommand \index{-dM}
5931
5932 \end_inset 
5933
5934
5935 \series default 
5936  Tell the preprocessor to output only a list of the macro definitions that
5937  are in effect at the end of preprocessing.
5938  Used with the `-E' option.
5939 \layout List
5940 \labelwidthstring 00.00.0000
5941
5942
5943 \series bold 
5944 -dD
5945 \begin_inset LatexCommand \index{-dD}
5946
5947 \end_inset 
5948
5949
5950 \series default 
5951  Tell the preprocessor to pass all macro definitions into the output, in
5952  their proper sequence in the rest of the output.
5953 \layout List
5954 \labelwidthstring 00.00.0000
5955
5956
5957 \series bold 
5958 -dN
5959 \begin_inset LatexCommand \index{-dN}
5960
5961 \end_inset 
5962
5963
5964 \size large 
5965 \bar under 
5966  
5967 \series default 
5968 \size default 
5969 \bar default 
5970 Like `-dD' except that the macro arguments and contents are omitted.
5971  Only `#define name' is included in the output.
5972 \layout List
5973 \labelwidthstring 00.00.0000
5974
5975
5976 \series bold 
5977 -Wp\SpecialChar ~
5978 preprocessorOption[,preprocessorOption]
5979 \series default 
5980
5981 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5982
5983 \end_inset 
5984
5985 ...
5986  Pass the preprocessorOption to the preprocessor 
5987 \family typewriter 
5988 sdcpp
5989 \family default 
5990
5991 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5992
5993 \end_inset 
5994
5995 .
5996  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5997  Collection (gcc), if you need more dedicated options please refer to the
5998  documentation at 
5999 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6000
6001 \end_inset 
6002
6003 .
6004 \layout Subsection
6005
6006 Linker Options
6007 \begin_inset LatexCommand \index{Options linker}
6008
6009 \end_inset 
6010
6011
6012 \begin_inset LatexCommand \index{Linker options}
6013
6014 \end_inset 
6015
6016
6017 \layout List
6018 \labelwidthstring 00.00.0000
6019
6020
6021 \series bold 
6022 -L\SpecialChar ~
6023 -
6024 \series default 
6025
6026 \begin_inset ERT
6027 status Collapsed
6028
6029 \layout Standard
6030
6031 \backslash 
6032 /
6033 \end_inset 
6034
6035
6036 \series bold 
6037 -lib-path
6038 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6039
6040 \end_inset 
6041
6042
6043 \begin_inset LatexCommand \index{-L -\/-lib-path}
6044
6045 \end_inset 
6046
6047
6048 \series default 
6049 \SpecialChar ~
6050 <absolute path to additional libraries> This option is passed to the linkage
6051  editor's additional libraries
6052 \begin_inset LatexCommand \index{Libraries}
6053
6054 \end_inset 
6055
6056  search path.
6057  The path name must be absolute.
6058  Additional library files may be specified in the command line.
6059  See section Compiling programs for more details.
6060 \layout List
6061 \labelwidthstring 00.00.0000
6062
6063
6064 \series bold 
6065 -
6066 \begin_inset ERT
6067 status Collapsed
6068
6069 \layout Standard
6070
6071 \backslash 
6072 /
6073 \end_inset 
6074
6075 -xram-loc
6076 \series default 
6077
6078 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6079
6080 \end_inset 
6081
6082 \SpecialChar ~
6083 <Value> The start location of the external ram
6084 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6085
6086 \end_inset 
6087
6088 , default value is 0.
6089  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6090 \begin_inset ERT
6091 status Collapsed
6092
6093 \layout Standard
6094
6095 \backslash 
6096 /
6097 \end_inset 
6098
6099 -xram-loc 0x8000 or -
6100 \begin_inset ERT
6101 status Collapsed
6102
6103 \layout Standard
6104
6105 \backslash 
6106 /
6107 \end_inset 
6108
6109 -xram-loc 32768.
6110 \layout List
6111 \labelwidthstring 00.00.0000
6112
6113
6114 \series bold 
6115 -
6116 \begin_inset ERT
6117 status Collapsed
6118
6119 \layout Standard
6120
6121 \backslash 
6122 /
6123 \end_inset 
6124
6125 -code-loc
6126 \series default 
6127
6128 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6129
6130 \end_inset 
6131
6132 \SpecialChar ~
6133 <Value> The start location of the code
6134 \begin_inset LatexCommand \index{code}
6135
6136 \end_inset 
6137
6138  segment, default value 0.
6139  Note when this option is used the interrupt vector table is also relocated
6140  to the given address.
6141  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6142 \begin_inset ERT
6143 status Collapsed
6144
6145 \layout Standard
6146
6147 \backslash 
6148 /
6149 \end_inset 
6150
6151 -code-loc 0x8000 or -
6152 \begin_inset ERT
6153 status Collapsed
6154
6155 \layout Standard
6156
6157 \backslash 
6158 /
6159 \end_inset 
6160
6161 -code-loc 32768.
6162 \layout List
6163 \labelwidthstring 00.00.0000
6164
6165
6166 \series bold 
6167 -
6168 \begin_inset ERT
6169 status Collapsed
6170
6171 \layout Standard
6172
6173 \backslash 
6174 /
6175 \end_inset 
6176
6177 -stack-loc
6178 \series default 
6179
6180 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6181
6182 \end_inset 
6183
6184 \SpecialChar ~
6185 <Value> By default the stack
6186 \begin_inset LatexCommand \index{stack}
6187
6188 \end_inset 
6189
6190  is placed after the data segment.
6191  Using this option the stack can be placed anywhere in the internal memory
6192  space of the 8051.
6193  The value entered can be in Hexadecimal or Decimal format, e.g.
6194  -
6195 \begin_inset ERT
6196 status Collapsed
6197
6198 \layout Standard
6199
6200 \backslash 
6201 /
6202 \end_inset 
6203
6204 -stack-loc 0x20 or -
6205 \begin_inset ERT
6206 status Collapsed
6207
6208 \layout Standard
6209
6210 \backslash 
6211 /
6212 \end_inset 
6213
6214 -stack-loc 32.
6215  Since the sp register is incremented before a push or call, the initial
6216  sp will be set to one byte prior the provided value.
6217  The provided value should not overlap any other memory areas such as used
6218  register banks or the data segment and with enough space for the current
6219  application.
6220  The 
6221 \series bold 
6222 -
6223 \begin_inset ERT
6224 status Collapsed
6225
6226 \layout Standard
6227
6228 \backslash 
6229 /
6230 \end_inset 
6231
6232 -pack-iram
6233 \series default 
6234 \SpecialChar ~
6235
6236 \begin_inset LatexCommand \index{-\/-pack-iram}
6237
6238 \end_inset 
6239
6240  option (which is now a default setting) will override this setting, so
6241  you should also specify the 
6242 \series bold 
6243 -
6244 \begin_inset ERT
6245 status Collapsed
6246
6247 \layout Standard
6248
6249 \backslash 
6250 /
6251 \end_inset 
6252
6253 -no-pack-iram
6254 \series default 
6255 \SpecialChar ~
6256
6257 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6258
6259 \end_inset 
6260
6261  option if you need to manually place the stack.
6262 \layout List
6263 \labelwidthstring 00.00.0000
6264
6265
6266 \series bold 
6267 -
6268 \begin_inset ERT
6269 status Collapsed
6270
6271 \layout Standard
6272
6273 \backslash 
6274 /
6275 \end_inset 
6276
6277 -xstack-loc
6278 \series default 
6279
6280 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6281
6282 \end_inset 
6283
6284 \SpecialChar ~
6285 <Value> By default the external stack
6286 \begin_inset LatexCommand \index{xstack}
6287
6288 \end_inset 
6289
6290  is placed after the pdata segment.
6291  Using this option the xstack can be placed anywhere in the external memory
6292  space of the 8051.
6293  The value entered can be in Hexadecimal or Decimal format, e.g.
6294  -
6295 \begin_inset ERT
6296 status Collapsed
6297
6298 \layout Standard
6299
6300 \backslash 
6301 /
6302 \end_inset 
6303
6304 -xstack-loc 0x8000 or -
6305 \begin_inset ERT
6306 status Collapsed
6307
6308 \layout Standard
6309
6310 \backslash 
6311 /
6312 \end_inset 
6313
6314 -stack-loc 32768.
6315  The provided value should not overlap any other memory areas such as the
6316  pdata or xdata segment and with enough space for the current application.
6317 \layout List
6318 \labelwidthstring 00.00.0000
6319
6320
6321 \series bold 
6322 -
6323 \begin_inset ERT
6324 status Collapsed
6325
6326 \layout Standard
6327
6328 \backslash 
6329 /
6330 \end_inset 
6331
6332 -data-loc
6333 \series default 
6334
6335 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6336
6337 \end_inset 
6338
6339 \SpecialChar ~
6340 <Value> The start location of the internal ram data
6341 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6342
6343 \end_inset 
6344
6345  segment.
6346  The value entered can be in Hexadecimal or Decimal format, eg.
6347  -
6348 \begin_inset ERT
6349 status Collapsed
6350
6351 \layout Standard
6352
6353 \backslash 
6354 /
6355 \end_inset 
6356
6357 -data-loc 0x20 or -
6358 \begin_inset ERT
6359 status Collapsed
6360
6361 \layout Standard
6362
6363 \backslash 
6364 /
6365 \end_inset 
6366
6367 -data-loc 32.
6368  (By default, the start location of the internal ram data segment  is set
6369  as low as possible in memory, taking into account the used register banks
6370  and the bit segment at address 0x20.
6371  For example if register banks 0 and 1 are used without bit variables, the
6372  data segment will be set, if -
6373 \begin_inset ERT
6374 status Collapsed
6375
6376 \layout Standard
6377
6378 \backslash 
6379 /
6380 \end_inset 
6381
6382 -data-loc is not used, to location 0x10.)
6383 \layout List
6384 \labelwidthstring 00.00.0000
6385
6386
6387 \series bold 
6388 -
6389 \begin_inset ERT
6390 status Collapsed
6391
6392 \layout Standard
6393
6394 \backslash 
6395 /
6396 \end_inset 
6397
6398 -idata-loc
6399 \series default 
6400
6401 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6402
6403 \end_inset 
6404
6405 \SpecialChar ~
6406 <Value> The start location of the indirectly addressable internal ram
6407 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6408
6409 \end_inset 
6410
6411  of the 8051, default value is 0x80.
6412  The value entered can be in Hexadecimal or Decimal format, eg.
6413  -
6414 \begin_inset ERT
6415 status Collapsed
6416
6417 \layout Standard
6418
6419 \backslash 
6420 /
6421 \end_inset 
6422
6423 -idata-loc 0x88 or -
6424 \begin_inset ERT
6425 status Collapsed
6426
6427 \layout Standard
6428
6429 \backslash 
6430 /
6431 \end_inset 
6432
6433 -idata-loc 136.
6434 \layout List
6435 \labelwidthstring 00.00.0000
6436
6437
6438 \series bold 
6439 -
6440 \begin_inset ERT
6441 status Collapsed
6442
6443 \layout Standard
6444
6445 \backslash 
6446 /
6447 \end_inset 
6448
6449 -bit-loc
6450 \series default 
6451 \SpecialChar ~
6452 <Value> The start location of the bit
6453 \begin_inset LatexCommand \index{bit}
6454
6455 \end_inset 
6456
6457  addressable internal ram of the 8051.
6458  This is 
6459 \emph on 
6460 not
6461 \emph default 
6462  implemented yet.
6463  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6464 -bBSEG=<Value>.
6465 \layout List
6466 \labelwidthstring 00.00.0000
6467
6468
6469 \series bold 
6470 -
6471 \begin_inset ERT
6472 status Collapsed
6473
6474 \layout Standard
6475
6476 \backslash 
6477 /
6478 \end_inset 
6479
6480 -out-fmt-ihx
6481 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6482
6483 \end_inset 
6484
6485
6486 \bar under 
6487  
6488 \series default 
6489 \bar default 
6490 The linker output (final object code) is in Intel Hex format.
6491 \begin_inset LatexCommand \index{Intel hex format}
6492
6493 \end_inset 
6494
6495  This is the default option.
6496  The format itself is documented in the documentation of srecord
6497 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6498
6499 \end_inset 
6500
6501 .
6502 \layout List
6503 \labelwidthstring 00.00.0000
6504
6505
6506 \series bold 
6507 -
6508 \begin_inset ERT
6509 status Collapsed
6510
6511 \layout Standard
6512
6513 \backslash 
6514 /
6515 \end_inset 
6516
6517 -out-fmt-s19
6518 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6519
6520 \end_inset 
6521
6522
6523 \bar under 
6524  
6525 \series default 
6526 \bar default 
6527 The linker output (final object code) is in Motorola S19 format
6528 \begin_inset LatexCommand \index{Motorola S19 format}
6529
6530 \end_inset 
6531
6532 .
6533  The format itself is documented in the documentation of srecord.
6534 \layout List
6535 \labelwidthstring 00.00.0000
6536
6537
6538 \series bold 
6539 -
6540 \begin_inset ERT
6541 status Collapsed
6542
6543 \layout Standard
6544
6545 \backslash 
6546 /
6547 \end_inset 
6548
6549 -out-fmt-elf
6550 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6551
6552 \end_inset 
6553
6554
6555 \bar under 
6556  
6557 \series default 
6558 \bar default 
6559 The linker output (final object code) is in ELF format
6560 \begin_inset LatexCommand \index{ELF format}
6561
6562 \end_inset 
6563
6564 .
6565  (Currently only supported for the HC08 processors)
6566 \layout List
6567 \labelwidthstring 00.00.0000
6568
6569
6570 \series bold 
6571 -Wl\SpecialChar ~
6572 linkOption[,linkOption]
6573 \series default 
6574
6575 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6576
6577 \end_inset 
6578
6579 ...
6580  Pass the linkOption to the linker.
6581  See file sdcc/as/doc/asxhtm.html for more on linker options.
6582 \layout Subsection
6583
6584 MCS51 Options
6585 \begin_inset LatexCommand \index{Options MCS51}
6586
6587 \end_inset 
6588
6589
6590 \begin_inset LatexCommand \index{MCS51 options}
6591
6592 \end_inset 
6593
6594
6595 \layout List
6596 \labelwidthstring 00.00.0000
6597
6598
6599 \series bold 
6600 -
6601 \begin_inset ERT
6602 status Collapsed
6603
6604 \layout Standard
6605
6606 \backslash 
6607 /
6608 \end_inset 
6609
6610 -model-small
6611 \begin_inset LatexCommand \index{-\/-model-small}
6612
6613 \end_inset 
6614
6615
6616 \series default 
6617 \size large 
6618 \emph on 
6619  
6620 \size default 
6621 \emph default 
6622 Generate code for Small Model programs, see section Memory Models for more
6623  details.
6624  This is the default model.
6625 \layout List
6626 \labelwidthstring 00.00.0000
6627
6628
6629 \series bold 
6630 -
6631 \begin_inset ERT
6632 status Collapsed
6633
6634 \layout Standard
6635
6636 \backslash 
6637 /
6638 \end_inset 
6639
6640 -model-medium
6641 \begin_inset LatexCommand \index{-\/-model-medium}
6642
6643 \end_inset 
6644
6645
6646 \series default 
6647  Generate code for Medium model programs, see section Memory Models for
6648  more details.
6649  If this option is used all source files in the project have to be compiled
6650  with this option.
6651  It must also be used when invoking the linker.
6652 \layout List
6653 \labelwidthstring 00.00.0000
6654
6655
6656 \series bold 
6657 -
6658 \begin_inset ERT
6659 status Collapsed
6660
6661 \layout Standard
6662
6663 \backslash 
6664 /
6665 \end_inset 
6666
6667 -model-large
6668 \begin_inset LatexCommand \index{-\/-model-large}
6669
6670 \end_inset 
6671
6672
6673 \series default 
6674  Generate code for Large model programs, see section Memory Models for more
6675  details.
6676  If this option is used all source files in the project have to be compiled
6677  with this option.
6678  It must also be used when invoking the linker.
6679 \layout List
6680 \labelwidthstring 00.00.0000
6681
6682
6683 \series bold 
6684 -
6685 \begin_inset ERT
6686 status Collapsed
6687
6688 \layout Standard
6689
6690 \backslash 
6691 /
6692 \end_inset 
6693
6694 -xstack
6695 \begin_inset LatexCommand \index{-\/-xstack}
6696
6697 \end_inset 
6698
6699
6700 \series default 
6701  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
6702  variables and passing parameters.
6703  See section 
6704 \begin_inset LatexCommand \ref{sub:External-Stack}
6705
6706 \end_inset 
6707
6708 \SpecialChar ~
6709  External Stack for more details.
6710 \layout List
6711 \labelwidthstring 00.00.0000
6712
6713
6714 \series bold 
6715 -
6716 \begin_inset ERT
6717 status Collapsed
6718
6719 \layout Standard
6720
6721 \backslash 
6722 /
6723 \end_inset 
6724
6725 -iram-size
6726 \series default 
6727 \SpecialChar ~
6728 <Value>
6729 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6730
6731 \end_inset 
6732
6733  Causes the linker to check if the internal ram usage is within limits of
6734  the given value.
6735 \layout List
6736 \labelwidthstring 00.00.0000
6737
6738
6739 \series bold 
6740 -
6741 \begin_inset ERT
6742 status Collapsed
6743
6744 \layout Standard
6745
6746 \backslash 
6747 /
6748 \end_inset 
6749
6750 -xram-size
6751 \series default 
6752 \SpecialChar ~
6753 <Value>
6754 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6755
6756 \end_inset 
6757
6758  Causes the linker to check if the external ram usage is within limits of
6759  the given value.
6760 \layout List
6761 \labelwidthstring 00.00.0000
6762
6763
6764 \series bold 
6765 -
6766 \begin_inset ERT
6767 status Collapsed
6768
6769 \layout Standard
6770
6771 \backslash 
6772 /
6773 \end_inset 
6774
6775 -code-size
6776 \series default 
6777 \SpecialChar ~
6778 <Value>
6779 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6780
6781 \end_inset 
6782
6783  Causes the linker to check if the code memory usage is within limits of
6784  the given value.
6785 \layout List
6786 \labelwidthstring 00.00.0000
6787
6788
6789 \series bold 
6790 -
6791 \begin_inset ERT
6792 status Collapsed
6793
6794 \layout Standard
6795
6796 \backslash 
6797 /
6798 \end_inset 
6799
6800 -stack-size
6801 \series default 
6802 \SpecialChar ~
6803 <Value>
6804 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6805
6806 \end_inset 
6807
6808  Causes the linker to check if there is at minimum <Value> bytes for stack.
6809 \layout List
6810 \labelwidthstring 00.00.0000
6811
6812
6813 \series bold 
6814 -
6815 \begin_inset ERT
6816 status Collapsed
6817
6818 \layout Standard
6819
6820 \backslash 
6821 /
6822 \end_inset 
6823
6824 -pack-iram
6825 \series default 
6826 \SpecialChar ~
6827
6828 \begin_inset LatexCommand \index{-\/-pack-iram}
6829
6830 \end_inset 
6831
6832  Causes the linker to use unused register banks for data variables and pack
6833  data, idata and stack together.
6834  This is the default now.
6835 \layout List
6836 \labelwidthstring 00.00.0000
6837
6838
6839 \series bold 
6840 -
6841 \begin_inset ERT
6842 status Collapsed
6843
6844 \layout Standard
6845
6846 \backslash 
6847 /
6848 \end_inset 
6849
6850 -no-pack-iram
6851 \series default 
6852 \SpecialChar ~
6853
6854 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6855
6856 \end_inset 
6857
6858  Causes the linker to use old style for allocating memory areas.
6859 \layout Subsection
6860
6861 DS390 / DS400 Options
6862 \begin_inset LatexCommand \index{Options DS390}
6863
6864 \end_inset 
6865
6866
6867 \begin_inset LatexCommand \index{DS390 options}
6868
6869 \end_inset 
6870
6871
6872 \layout List
6873 \labelwidthstring 00.00.0000
6874
6875
6876 \series bold 
6877 -
6878 \begin_inset ERT
6879 status Collapsed
6880
6881 \layout Standard
6882
6883 \backslash 
6884 /
6885 \end_inset 
6886
6887 -model-flat24
6888 \series default 
6889
6890 \begin_inset LatexCommand \index{-\/-model-flat24}
6891
6892 \end_inset 
6893
6894
6895 \size large 
6896 \emph on 
6897  
6898 \size default 
6899 \emph default 
6900 Generate 24-bit flat mode code.
6901  This is the one and only that the ds390 code generator supports right now
6902  and is default when using 
6903 \emph on 
6904 -mds390
6905 \emph default 
6906 .
6907  See section Memory Models for more details.
6908 \layout List
6909 \labelwidthstring 00.00.0000
6910
6911
6912 \series bold 
6913 -
6914 \begin_inset ERT
6915 status Collapsed
6916
6917 \layout Standard
6918
6919 \backslash 
6920 /
6921 \end_inset 
6922
6923 -protect-sp-update
6924 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6925
6926 \end_inset 
6927
6928
6929 \series default 
6930  disable interrupts during ESP:SP updates.
6931 \layout List
6932 \labelwidthstring 00.00.0000
6933
6934
6935 \series bold 
6936 -
6937 \begin_inset ERT
6938 status Collapsed
6939
6940 \layout Standard
6941
6942 \backslash 
6943 /
6944 \end_inset 
6945
6946 -stack-10bit
6947 \series default 
6948
6949 \begin_inset LatexCommand \index{-\/-stack-10bit}
6950
6951 \end_inset 
6952
6953  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6954  This is the one and only that the ds390 code generator supports right now
6955  and is default when using 
6956 \emph on 
6957 -mds390
6958 \emph default 
6959 .
6960  In this mode, the stack is located in the lower 1K of the internal RAM,
6961  which is mapped to 0x400000.
6962  Note that the support is incomplete, since it still uses a single byte
6963  as the stack pointer.
6964  This means that only the lower 256 bytes of the potential 1K stack space
6965  will actually be used.
6966  However, this does allow you to reclaim the precious 256 bytes of low RAM
6967  for use for the DATA and IDATA segments.
6968  The compiler will not generate any code to put the processor into 10 bit
6969  stack mode.
6970  It is important to ensure that the processor is in this mode before calling
6971  any re-entrant functions compiled with this option.
6972  In principle, this should work with the 
6973 \emph on 
6974 -
6975 \begin_inset ERT
6976 status Collapsed
6977
6978 \layout Standard
6979
6980 \backslash 
6981 /
6982 \end_inset 
6983
6984 -stack-auto
6985 \begin_inset LatexCommand \index{-\/-stack-auto}
6986
6987 \end_inset 
6988
6989
6990 \emph default 
6991  option, but that has not been tested.
6992  It is incompatible with the 
6993 \emph on 
6994 -
6995 \begin_inset ERT
6996 status Collapsed
6997
6998 \layout Standard
6999
7000 \backslash 
7001 /
7002 \end_inset 
7003
7004 -xstack
7005 \begin_inset LatexCommand \index{-\/-xstack}
7006
7007 \end_inset 
7008
7009
7010 \emph default 
7011  option.
7012  It also only makes sense if the processor is in 24 bit contiguous addressing
7013  mode (see the 
7014 \emph on 
7015 -
7016 \begin_inset ERT
7017 status Collapsed
7018
7019 \layout Standard
7020
7021 \backslash 
7022 /
7023 \end_inset 
7024
7025 -model-flat24 option
7026 \emph default 
7027 ).
7028 \layout List
7029 \labelwidthstring 00.00.0000
7030
7031
7032 \series bold 
7033 -
7034 \begin_inset ERT
7035 status Collapsed
7036
7037 \layout Standard
7038
7039 \backslash 
7040 /
7041 \end_inset 
7042
7043 -stack-probe
7044 \begin_inset LatexCommand \index{-\/-stack-probe}
7045
7046 \end_inset 
7047
7048
7049 \series default 
7050  insert call to function __stack_probe at each function prologue.
7051 \layout List
7052 \labelwidthstring 00.00.0000
7053
7054
7055 \series bold 
7056 -
7057 \begin_inset ERT
7058 status Collapsed
7059
7060 \layout Standard
7061
7062 \backslash 
7063 /
7064 \end_inset 
7065
7066 -tini-libid
7067 \begin_inset LatexCommand \index{-\/-tini-libid}
7068
7069 \end_inset 
7070
7071
7072 \series default 
7073  <nnnn> LibraryID used in -mTININative.
7074  
7075 \layout List
7076 \labelwidthstring 00.00.0000
7077
7078
7079 \series bold 
7080 -
7081 \begin_inset ERT
7082 status Collapsed
7083
7084 \layout Standard
7085
7086 \backslash 
7087 /
7088 \end_inset 
7089
7090 -use-accelerator
7091 \begin_inset LatexCommand \index{-\/-use-accelerator}
7092
7093 \end_inset 
7094
7095
7096 \series default 
7097  generate code for DS390 Arithmetic Accelerator.
7098  
7099 \layout Subsection
7100
7101 Z80 Options
7102 \begin_inset LatexCommand \index{Options Z80}
7103
7104 \end_inset 
7105
7106
7107 \begin_inset LatexCommand \index{Z80 options}
7108
7109 \end_inset 
7110
7111
7112 \layout List
7113 \labelwidthstring 00.00.0000
7114
7115
7116 \series bold 
7117 -
7118 \begin_inset ERT
7119 status Collapsed
7120
7121 \layout Standard
7122
7123 \backslash 
7124 /
7125 \end_inset 
7126
7127 -callee-saves-bc
7128 \series default 
7129
7130 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
7131
7132 \end_inset 
7133
7134
7135 \size large 
7136 \emph on 
7137  
7138 \size default 
7139 \emph default 
7140 Force a called function to always save BC.
7141 \layout List
7142 \labelwidthstring 00.00.0000
7143
7144
7145 \series bold 
7146 -
7147 \begin_inset ERT
7148 status Collapsed
7149
7150 \layout Standard
7151
7152 \backslash 
7153 /
7154 \end_inset 
7155
7156 -no-std-crt0
7157 \series default 
7158
7159 \begin_inset LatexCommand \index{-\/-no-std-crt0}
7160
7161 \end_inset 
7162
7163  When linking, skip the standard crt0.o object file.
7164  You must provide your own crt0.o for your system when linking.
7165  
7166 \layout Subsection
7167
7168 Optimization Options
7169 \begin_inset LatexCommand \index{Options optimization}
7170
7171 \end_inset 
7172
7173
7174 \begin_inset LatexCommand \index{Optimization options}
7175
7176 \end_inset 
7177
7178
7179 \layout List
7180 \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 -nogcse
7195 \begin_inset LatexCommand \index{-\/-nogcse}
7196
7197 \end_inset 
7198
7199
7200 \series default 
7201  Will not do global subexpression elimination, this option may be used when
7202  the compiler creates undesirably large stack/data spaces to store compiler
7203  temporaries (
7204 \emph on 
7205 s
7206 \emph default 
7207 pill 
7208 \emph on 
7209 loc
7210 \emph default 
7211 ations, sloc
7212 \begin_inset LatexCommand \index{sloc (spill location)}
7213
7214 \end_inset 
7215
7216 ).
7217  A warning message will be generated when this happens and the compiler
7218  will indicate the number of extra bytes it allocated.
7219  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7220 nogcse
7221 \begin_inset LatexCommand \index{\#pragma nogcse}
7222
7223 \end_inset 
7224
7225  can be used to turn off global subexpression elimination
7226 \begin_inset LatexCommand \index{Subexpression elimination}
7227
7228 \end_inset 
7229
7230  for a given function only.
7231 \layout List
7232 \labelwidthstring 00.00.0000
7233
7234
7235 \series bold 
7236 -
7237 \begin_inset ERT
7238 status Collapsed
7239
7240 \layout Standard
7241
7242 \backslash 
7243 /
7244 \end_inset 
7245
7246 -noinvariant
7247 \begin_inset LatexCommand \index{-\/-noinvariant}
7248
7249 \end_inset 
7250
7251
7252 \series default 
7253  Will not do loop invariant optimizations, this may be turned off for reasons
7254  explained for the previous option.
7255  For more details of loop optimizations performed see Loop Invariants in
7256  section 
7257 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7258
7259 \end_inset 
7260
7261 .
7262  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7263 noinvariant
7264 \begin_inset LatexCommand \index{\#pragma noinvariant}
7265
7266 \end_inset 
7267
7268  can be used to turn off invariant optimizations for a given function only.
7269 \layout List
7270 \labelwidthstring 00.00.0000
7271
7272
7273 \series bold 
7274 -
7275 \begin_inset ERT
7276 status Collapsed
7277
7278 \layout Standard
7279
7280 \backslash 
7281 /
7282 \end_inset 
7283
7284 -noinduction
7285 \begin_inset LatexCommand \index{-\/-noinduction}
7286
7287 \end_inset 
7288
7289
7290 \series default 
7291  Will not do loop induction optimizations, see section strength reduction
7292  for more details.
7293  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7294 noinduction
7295 \begin_inset LatexCommand \index{\#pragma noinduction}
7296
7297 \end_inset 
7298
7299  can be used to turn off induction optimizations for a given function only.
7300 \layout List
7301 \labelwidthstring 00.00.0000
7302
7303
7304 \series bold 
7305 -
7306 \begin_inset ERT
7307 status Collapsed
7308
7309 \layout Standard
7310
7311 \backslash 
7312 /
7313 \end_inset 
7314
7315 -nojtbound
7316 \begin_inset LatexCommand \index{-\/-nojtbound}
7317
7318 \end_inset 
7319
7320
7321 \size large 
7322 \bar under 
7323  
7324 \series default 
7325 \size default 
7326 \bar default 
7327  Will not generate boundary condition check when switch statements
7328 \begin_inset LatexCommand \index{switch statement}
7329
7330 \end_inset 
7331
7332  are implemented using jump-tables.
7333  See section 
7334 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7335
7336 \end_inset 
7337
7338 \SpecialChar ~
7339 Switch Statements for more details.
7340  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7341 nojtbound
7342 \begin_inset LatexCommand \index{\#pragma nojtbound}
7343
7344 \end_inset 
7345
7346  can be used to turn off boundary checking for jump tables for a given function
7347  only.
7348 \layout List
7349 \labelwidthstring 00.00.0000
7350
7351
7352 \series bold 
7353 -
7354 \begin_inset ERT
7355 status Collapsed
7356
7357 \layout Standard
7358
7359 \backslash 
7360 /
7361 \end_inset 
7362
7363 -noloopreverse
7364 \begin_inset LatexCommand \index{-\/-noloopreverse}
7365
7366 \end_inset 
7367
7368
7369 \series default 
7370 \size large 
7371  
7372 \size default 
7373 Will not do loop reversal 
7374 \begin_inset LatexCommand \index{Loop reversing}
7375
7376 \end_inset 
7377
7378 optimization.
7379 \layout List
7380 \labelwidthstring 00.00.0000
7381
7382 -
7383 \begin_inset ERT
7384 status Collapsed
7385
7386 \layout Standard
7387
7388 \backslash 
7389 /
7390 \end_inset 
7391
7392 -
7393 \series bold 
7394 nolabelopt
7395 \series default 
7396  
7397 \begin_inset LatexCommand \index{-\/-nolabelopt }
7398
7399 \end_inset 
7400
7401 Will not optimize labels (makes the dumpfiles more readable).
7402 \layout List
7403 \labelwidthstring 00.00.0000
7404
7405
7406 \series bold 
7407 -
7408 \begin_inset ERT
7409 status Collapsed
7410
7411 \layout Standard
7412
7413 \backslash 
7414 /
7415 \end_inset 
7416
7417 -no-xinit-opt
7418 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7419
7420 \end_inset 
7421
7422
7423 \series default 
7424  Will not memcpy initialized data from code space into xdata space.
7425  This saves a few bytes in code space if you don't have initialized data
7426 \begin_inset LatexCommand \index{Variable initialization}
7427
7428 \end_inset 
7429
7430 .
7431 \layout List
7432 \labelwidthstring 00.00.0000
7433
7434
7435 \series bold 
7436 -
7437 \begin_inset ERT
7438 status Collapsed
7439
7440 \layout Standard
7441
7442 \backslash 
7443 /
7444 \end_inset 
7445
7446 -nooverlay
7447 \begin_inset LatexCommand \index{-\/-nooverlay}
7448
7449 \end_inset 
7450
7451
7452 \series default 
7453   The compiler will not overlay parameters and local variables of any function,
7454  see section Parameters and local variables for more details.
7455 \layout List
7456 \labelwidthstring 00.00.0000
7457
7458
7459 \series bold 
7460 -
7461 \begin_inset ERT
7462 status Collapsed
7463
7464 \layout Standard
7465
7466 \backslash 
7467 /
7468 \end_inset 
7469
7470 -no-peep
7471 \begin_inset LatexCommand \index{-\/-no-peep}
7472
7473 \end_inset 
7474
7475
7476 \series default 
7477  Disable peep-hole optimization with built-in rules.
7478 \layout List
7479 \labelwidthstring 00.00.0000
7480
7481
7482 \series bold 
7483 -
7484 \begin_inset ERT
7485 status Collapsed
7486
7487 \layout Standard
7488
7489 \backslash 
7490 /
7491 \end_inset 
7492
7493 -peep-file
7494 \series default 
7495
7496 \begin_inset LatexCommand \index{-\/-peep-file}
7497
7498 \end_inset 
7499
7500 \SpecialChar ~
7501 <filename> This option can be used to use additional rules to be used by
7502  the peep hole optimizer.
7503  See section 
7504 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7505
7506 \end_inset 
7507
7508 \SpecialChar ~
7509 Peep Hole optimizations for details on how to write these rules.
7510 \layout List
7511 \labelwidthstring 00.00.0000
7512
7513
7514 \series bold 
7515 -
7516 \begin_inset ERT
7517 status Collapsed
7518
7519 \layout Standard
7520
7521 \backslash 
7522 /
7523 \end_inset 
7524
7525 -peep-asm
7526 \begin_inset LatexCommand \index{-\/-peep-asm}
7527
7528 \end_inset 
7529
7530
7531 \series default 
7532  Pass the inline assembler code through the peep hole optimizer.
7533  This can cause unexpected changes to inline assembler code, please go through
7534  the peephole optimizer
7535 \begin_inset LatexCommand \index{Peephole optimizer}
7536
7537 \end_inset 
7538
7539  rules defined in the source file tree '<target>/peeph.def' before using
7540  this option.
7541 \layout List
7542 \labelwidthstring 00.00.0000
7543
7544
7545 \series bold 
7546 -
7547 \begin_inset ERT
7548 status Collapsed
7549
7550 \layout Standard
7551
7552 \backslash 
7553 /
7554 \end_inset 
7555
7556 -opt-code-speed
7557 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7558
7559 \end_inset 
7560
7561
7562 \series default 
7563  The compiler will optimize code generation towards fast code, possibly
7564  at the expense of code size.
7565 \layout List
7566 \labelwidthstring 00.00.0000
7567
7568
7569 \series bold 
7570 -
7571 \begin_inset ERT
7572 status Collapsed
7573
7574 \layout Standard
7575
7576 \backslash 
7577 /
7578 \end_inset 
7579
7580 -opt-code-size
7581 \begin_inset LatexCommand \index{-\/-opt-code-size}
7582
7583 \end_inset 
7584
7585
7586 \series default 
7587  The compiler will optimize code generation towards compact code, possibly
7588  at the expense of code speed.
7589 \layout Subsection
7590
7591 Other Options
7592 \begin_inset LatexCommand \index{Options other}
7593
7594 \end_inset 
7595
7596
7597 \layout List
7598 \labelwidthstring 00.00.0000
7599
7600
7601 \series bold 
7602 -c\SpecialChar ~
7603 -
7604 \begin_inset ERT
7605 status Collapsed
7606
7607 \layout Standard
7608
7609 \backslash 
7610 /
7611 \end_inset 
7612
7613 -compile-only
7614 \begin_inset LatexCommand \index{-\/-compile-only}
7615
7616 \end_inset 
7617
7618
7619 \begin_inset LatexCommand \index{-c -\/-compile-only}
7620
7621 \end_inset 
7622
7623
7624 \series default 
7625  will compile and assemble the source, but will not call the linkage editor.
7626 \layout List
7627 \labelwidthstring 00.00.0000
7628
7629
7630 \series bold 
7631 -
7632 \series default 
7633
7634 \begin_inset ERT
7635 status Collapsed
7636
7637 \layout Standard
7638
7639 \backslash 
7640 /
7641 \end_inset 
7642
7643
7644 \series bold 
7645 -c1mode
7646 \begin_inset LatexCommand \index{-\/-c1mode}
7647
7648 \end_inset 
7649
7650
7651 \series default 
7652  reads the preprocessed source from standard input and compiles it.
7653  The file name for the assembler output must be specified using the -o option.
7654 \layout List
7655 \labelwidthstring 00.00.0000
7656
7657
7658 \series bold 
7659 -E
7660 \begin_inset LatexCommand \index{-E}
7661
7662 \end_inset 
7663
7664
7665 \series default 
7666  Run only the C preprocessor.
7667  Preprocess all the C source files specified and output the results to standard
7668  output.
7669 \layout List
7670 \labelwidthstring 00.00.0000
7671
7672
7673 \series bold 
7674 -o\SpecialChar ~
7675 <path/file>
7676 \begin_inset LatexCommand \index{-o <path/file>}
7677
7678 \end_inset 
7679
7680  
7681 \series default 
7682 The output path resp.
7683  file where everything will be placed.
7684  If the parameter is a path, it must have a trailing slash (or backslash
7685  for the Windows binaries) to be recognized as a path.
7686  
7687 \layout List
7688 \labelwidthstring 00.00.0000
7689
7690
7691 \series bold 
7692 -
7693 \begin_inset ERT
7694 status Collapsed
7695
7696 \layout Standard
7697
7698 \backslash 
7699 /
7700 \end_inset 
7701
7702 -stack-auto
7703 \begin_inset LatexCommand \index{-\/-stack-auto}
7704
7705 \end_inset 
7706
7707
7708 \series default 
7709 \size large 
7710 \emph on 
7711  
7712 \size default 
7713 \emph default 
7714 All functions in the source file will be compiled as 
7715 \emph on 
7716 reentrant
7717 \emph default 
7718
7719 \begin_inset LatexCommand \index{reentrant}
7720
7721 \end_inset 
7722
7723 , i.e.
7724  the parameters and local variables will be allocated on the stack
7725 \begin_inset LatexCommand \index{stack}
7726
7727 \end_inset 
7728
7729 .
7730  See section 
7731 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7732
7733 \end_inset 
7734
7735  Parameters and Local Variables for more details.
7736  If this option is used all source files in the project should be compiled
7737  with this option.
7738  It automatically implies --int-long-reent and --float-reent.
7739  
7740 \layout List
7741 \labelwidthstring 00.00.0000
7742
7743
7744 \series bold 
7745 -
7746 \begin_inset ERT
7747 status Collapsed
7748
7749 \layout Standard
7750
7751 \backslash 
7752 /
7753 \end_inset 
7754
7755 -callee-saves
7756 \begin_inset LatexCommand \index{-\/-callee-saves}
7757
7758 \end_inset 
7759
7760  function1[,function2][,function3]....
7761
7762 \series default 
7763  The compiler by default uses a caller saves convention for register saving
7764  across function calls, however this can cause unnecessary register pushing
7765  & popping when calling small functions from larger functions.
7766  This option can be used to switch the register saving convention for the
7767  function names specified.
7768  The compiler will not save registers when calling these functions, no extra
7769  code will be generated at the entry & exit (function prologue
7770 \series bold 
7771
7772 \begin_inset LatexCommand \index{function prologue}
7773
7774 \end_inset 
7775
7776
7777 \series default 
7778  & epilogue
7779 \series bold 
7780
7781 \begin_inset LatexCommand \index{function epilogue}
7782
7783 \end_inset 
7784
7785
7786 \series default 
7787 ) for these functions to save & restore the registers used by these functions,
7788  this can SUBSTANTIALLY reduce code & improve run time performance of the
7789  generated code.
7790  In the future the compiler (with inter procedural analysis) will be able
7791  to determine the appropriate scheme to use for each function call.
7792  DO NOT use this option for built-in functions such as _mulint..., if this
7793  option is used for a library function the appropriate library function
7794  needs to be recompiled with the same option.
7795  If the project consists of multiple source files then all the source file
7796  should be compiled with the same -
7797 \begin_inset ERT
7798 status Collapsed
7799
7800 \layout Standard
7801
7802 \backslash 
7803 /
7804 \end_inset 
7805
7806 -callee-saves option string.
7807  Also see #pragma\SpecialChar ~
7808 callee_saves
7809 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7810
7811 \end_inset 
7812
7813 .
7814 \layout List
7815 \labelwidthstring 00.00.0000
7816
7817
7818 \series bold 
7819 -
7820 \begin_inset ERT
7821 status Collapsed
7822
7823 \layout Standard
7824
7825 \backslash 
7826 /
7827 \end_inset 
7828
7829 -debug
7830 \begin_inset LatexCommand \index{-\/-debug}
7831
7832 \end_inset 
7833
7834
7835 \bar under 
7836  
7837 \series default 
7838 \bar default 
7839 When this option is used the compiler will generate debug information.
7840  The debug information collected in a file with .cdb extension can be used
7841  with the SDCDB.
7842  For more information see documentation for SDCDB.
7843  Another file with no extension contains debug information in AOMF or AOMF51
7844 \begin_inset LatexCommand \index{AOMF, AOMF51}
7845
7846 \end_inset 
7847
7848  format which is commonly used by third party tools.
7849 \layout List
7850 \labelwidthstring 00.00.0000
7851
7852
7853 \series bold 
7854 -S
7855 \begin_inset LatexCommand \index{-S}
7856
7857 \end_inset 
7858
7859
7860 \size large 
7861 \bar under 
7862  
7863 \series default 
7864 \size default 
7865 \bar default 
7866 Stop after the stage of compilation proper; do not assemble.
7867  The output is an assembler code file for the input file specified.
7868 \layout List
7869 \labelwidthstring 00.00.0000
7870
7871
7872 \series bold 
7873 -
7874 \begin_inset ERT
7875 status Collapsed
7876
7877 \layout Standard
7878
7879 \backslash 
7880 /
7881 \end_inset 
7882
7883 -int-long-reent
7884 \begin_inset LatexCommand \index{-\/-int-long-reent}
7885
7886 \end_inset 
7887
7888
7889 \series default 
7890  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7891  Note by default these libraries are compiled as non-reentrant.
7892  See section Installation for more details.
7893 \layout List
7894 \labelwidthstring 00.00.0000
7895
7896
7897 \series bold 
7898 -
7899 \begin_inset ERT
7900 status Collapsed
7901
7902 \layout Standard
7903
7904 \backslash 
7905 /
7906 \end_inset 
7907
7908 -cyclomatic
7909 \begin_inset LatexCommand \index{-\/-cyclomatic}
7910
7911 \end_inset 
7912
7913
7914 \bar under 
7915  
7916 \series default 
7917 \bar default 
7918 This option will cause the compiler to generate an information message for
7919  each function in the source file.
7920  The message contains some 
7921 \emph on 
7922 important
7923 \emph default 
7924  information about the function.
7925  The number of edges and nodes the compiler detected in the control flow
7926  graph of the function, and most importantly the 
7927 \emph on 
7928 cyclomatic complexity
7929 \begin_inset LatexCommand \index{Cyclomatic complexity}
7930
7931 \end_inset 
7932
7933
7934 \emph default 
7935  see section on Cyclomatic Complexity for more details.
7936 \layout List
7937 \labelwidthstring 00.00.0000
7938
7939
7940 \series bold 
7941 -
7942 \begin_inset ERT
7943 status Collapsed
7944
7945 \layout Standard
7946
7947 \backslash 
7948 /
7949 \end_inset 
7950
7951 -float-reent
7952 \begin_inset LatexCommand \index{-\/-float-reent}
7953
7954 \end_inset 
7955
7956
7957 \series default 
7958  Floating point library is compiled as reentrant
7959 \begin_inset LatexCommand \index{reentrant}
7960
7961 \end_inset 
7962
7963 .
7964  See section Installation for more details.
7965 \layout List
7966 \labelwidthstring 00.00.0000
7967
7968
7969 \series bold 
7970 -
7971 \begin_inset ERT
7972 status Collapsed
7973
7974 \layout Standard
7975
7976 \backslash 
7977 /
7978 \end_inset 
7979
7980 -main-return
7981 \begin_inset LatexCommand \index{-\/-main-return}
7982
7983 \end_inset 
7984
7985
7986 \series default 
7987  This option can be used if the code generated is called by a monitor program
7988  or if the main routine includes an endless loop.
7989  This option might result in slightly smaller code and save two bytes of
7990  stack space.
7991  The return from the 'main'
7992 \begin_inset LatexCommand \index{main return}
7993
7994 \end_inset 
7995
7996  function will return to the function calling main.
7997  The default setting is to lock up i.e.
7998  generate a '
7999 \family typewriter 
8000 sjmp .
8001 \family default 
8002 '.
8003 \layout List
8004 \labelwidthstring 00.00.0000
8005
8006
8007 \series bold 
8008 -
8009 \begin_inset ERT
8010 status Collapsed
8011
8012 \layout Standard
8013
8014 \backslash 
8015 /
8016 \end_inset 
8017
8018 -nostdinc
8019 \begin_inset LatexCommand \index{-\/-nostdinc}
8020
8021 \end_inset 
8022
8023
8024 \series default 
8025  This will prevent the compiler from passing on the default include path
8026  to the preprocessor.
8027 \layout List
8028 \labelwidthstring 00.00.0000
8029
8030
8031 \series bold 
8032 -
8033 \begin_inset ERT
8034 status Collapsed
8035
8036 \layout Standard
8037
8038 \backslash 
8039 /
8040 \end_inset 
8041
8042 -nostdlib
8043 \begin_inset LatexCommand \index{-\/-nostdlib}
8044
8045 \end_inset 
8046
8047
8048 \series default 
8049  This will prevent the compiler from passing on the default library
8050 \begin_inset LatexCommand \index{Libraries}
8051
8052 \end_inset 
8053
8054  path to the linker.
8055 \layout List
8056 \labelwidthstring 00.00.0000
8057
8058
8059 \series bold 
8060 -
8061 \begin_inset ERT
8062 status Collapsed
8063
8064 \layout Standard
8065
8066 \backslash 
8067 /
8068 \end_inset 
8069
8070 -verbose
8071 \begin_inset LatexCommand \index{-\/-verbose}
8072
8073 \end_inset 
8074
8075
8076 \series default 
8077  Shows the various actions the compiler is performing.
8078 \layout List
8079 \labelwidthstring 00.00.0000
8080
8081
8082 \series bold 
8083 -V
8084 \begin_inset LatexCommand \index{-V}
8085
8086 \end_inset 
8087
8088
8089 \series default 
8090  Shows the actual commands the compiler is executing.
8091 \layout List
8092 \labelwidthstring 00.00.0000
8093
8094
8095 \series bold 
8096 -
8097 \begin_inset ERT
8098 status Collapsed
8099
8100 \layout Standard
8101
8102 \backslash 
8103 /
8104 \end_inset 
8105
8106 -no-c-code-in-asm
8107 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8108
8109 \end_inset 
8110
8111
8112 \series default 
8113  Hides your ugly and inefficient c-code from the asm file, so you can always
8114  blame the compiler :)
8115 \layout List
8116 \labelwidthstring 00.00.0000
8117
8118
8119 \series bold 
8120 -
8121 \begin_inset ERT
8122 status Collapsed
8123
8124 \layout Standard
8125
8126 \backslash 
8127 /
8128 \end_inset 
8129
8130 -no-peep-comments
8131 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8132
8133 \end_inset 
8134
8135
8136 \series default 
8137  Will not include peep-hole comments in the generated files.
8138 \layout List
8139 \labelwidthstring 00.00.0000
8140
8141
8142 \series bold 
8143 -
8144 \begin_inset ERT
8145 status Collapsed
8146
8147 \layout Standard
8148
8149 \backslash 
8150 /
8151 \end_inset 
8152
8153 -i-code-in-asm
8154 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8155
8156 \end_inset 
8157
8158
8159 \series default 
8160  Include i-codes in the asm file.
8161  Sounds like noise but is most helpful for debugging the compiler itself.
8162 \layout List
8163 \labelwidthstring 00.00.0000
8164
8165
8166 \series bold 
8167 -
8168 \begin_inset ERT
8169 status Collapsed
8170
8171 \layout Standard
8172
8173 \backslash 
8174 /
8175 \end_inset 
8176
8177 -less-pedantic
8178 \begin_inset LatexCommand \index{-\/-less-pedantic}
8179
8180 \end_inset 
8181
8182
8183 \series default 
8184  Disable some of the more pedantic warnings
8185 \begin_inset LatexCommand \index{Warnings}
8186
8187 \end_inset 
8188
8189  (jwk burps: please be more specific here, please!).
8190 \layout List
8191 \labelwidthstring 00.00.0000
8192
8193
8194 \series bold 
8195 -
8196 \begin_inset ERT
8197 status Collapsed
8198
8199 \layout Standard
8200
8201 \backslash 
8202 /
8203 \end_inset 
8204
8205 -disable-warning\SpecialChar ~
8206 <nnnn>
8207 \begin_inset LatexCommand \index{-\/-disable-warning}
8208
8209 \end_inset 
8210
8211
8212 \series default 
8213  Disable specific warning with number <nnnn>.
8214 \layout List
8215 \labelwidthstring 00.00.0000
8216
8217
8218 \series bold 
8219 -
8220 \begin_inset ERT
8221 status Collapsed
8222
8223 \layout Standard
8224
8225 \backslash 
8226 /
8227 \end_inset 
8228
8229 -print-search-dirs
8230 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8231
8232 \end_inset 
8233
8234
8235 \series default 
8236  Display the directories in the compiler's search path
8237 \layout List
8238 \labelwidthstring 00.00.0000
8239
8240
8241 \series bold 
8242 -
8243 \begin_inset ERT
8244 status Collapsed
8245
8246 \layout Standard
8247
8248 \backslash 
8249 /
8250 \end_inset 
8251
8252 -vc
8253 \begin_inset LatexCommand \index{-\/-vc}
8254
8255 \end_inset 
8256
8257
8258 \series default 
8259  Display errors and warnings using MSVC style, so you can use SDCC with
8260  visual studio.
8261 \layout List
8262 \labelwidthstring 00.00.0000
8263
8264
8265 \series bold 
8266 -
8267 \begin_inset ERT
8268 status Collapsed
8269
8270 \layout Standard
8271
8272 \backslash 
8273 /
8274 \end_inset 
8275
8276 -use-stdout
8277 \begin_inset LatexCommand \index{-\/-use-stdout}
8278
8279 \end_inset 
8280
8281
8282 \series default 
8283  Send errors and warnings to stdout instead of stderr.
8284 \layout List
8285 \labelwidthstring 00.00.0000
8286
8287
8288 \series bold 
8289 -Wa\SpecialChar ~
8290 asmOption[,asmOption]
8291 \series default 
8292
8293 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8294
8295 \end_inset 
8296
8297 ...
8298  Pass the asmOption to the assembler
8299 \begin_inset LatexCommand \index{Options assembler}
8300
8301 \end_inset 
8302
8303
8304 \begin_inset LatexCommand \index{Assembler options}
8305
8306 \end_inset 
8307
8308 .
8309  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8310 \layout List
8311 \labelwidthstring 00.00.0000
8312
8313
8314 \series bold 
8315 -
8316 \begin_inset ERT
8317 status Collapsed
8318
8319 \layout Standard
8320
8321 \backslash 
8322 /
8323 \end_inset 
8324
8325 -std-sdcc89
8326 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8327
8328 \end_inset 
8329
8330
8331 \series default 
8332  Generally follow the C89 standard, but allow SDCC features that conflict
8333  with the standard (default).
8334 \layout List
8335 \labelwidthstring 00.00.0000
8336
8337
8338 \series bold 
8339 -
8340 \begin_inset ERT
8341 status Collapsed
8342
8343 \layout Standard
8344
8345 \backslash 
8346 /
8347 \end_inset 
8348
8349 -std-c89
8350 \begin_inset LatexCommand \index{-\/-std-c89}
8351
8352 \end_inset 
8353
8354
8355 \series default 
8356  Follow the C89 standard and disable SDCC features that conflict with the
8357  standard.
8358 \layout List
8359 \labelwidthstring 00.00.0000
8360
8361
8362 \series bold 
8363 -
8364 \begin_inset ERT
8365 status Collapsed
8366
8367 \layout Standard
8368
8369 \backslash 
8370 /
8371 \end_inset 
8372
8373 -std-sdcc99
8374 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8375
8376 \end_inset 
8377
8378
8379 \series default 
8380  Generally follow the C99 standard, but allow SDCC features that conflict
8381  with the standard (incomplete support).
8382 \layout List
8383 \labelwidthstring 00.00.0000
8384
8385
8386 \series bold 
8387 -
8388 \begin_inset ERT
8389 status Collapsed
8390
8391 \layout Standard
8392
8393 \backslash 
8394 /
8395 \end_inset 
8396
8397 -std-c99
8398 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8399
8400 \end_inset 
8401
8402
8403 \series default 
8404  Follow the C99 standard and disable SDCC features that conflict with the
8405  standard (incomplete support).
8406 \layout List
8407 \labelwidthstring 00.00.0000
8408
8409
8410 \series bold 
8411 -
8412 \begin_inset ERT
8413 status Collapsed
8414
8415 \layout Standard
8416
8417 \backslash 
8418 /
8419 \end_inset 
8420
8421 -codeseg
8422 \series default 
8423
8424 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8425
8426 \end_inset 
8427
8428 \SpecialChar ~
8429 <Name> The name to be used for the code
8430 \begin_inset LatexCommand \index{code}
8431
8432 \end_inset 
8433
8434  segment, default CSEG.
8435  This is useful if you need to tell the compiler to put the code in a special
8436  segment so you can later on tell the linker to put this segment in a special
8437  place in memory.
8438  Can be used for instance when using bank switching to put the code in a
8439  bank.
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 -constseg
8456 \series default 
8457
8458 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8459
8460 \end_inset 
8461
8462 \SpecialChar ~
8463 <Name> The name to be used for the const
8464 \begin_inset LatexCommand \index{code}
8465
8466 \end_inset 
8467
8468  segment, default CONST.
8469  This is useful if you need to tell the compiler to put the const data in
8470  a special segment so you can later on tell the linker to put this segment
8471  in a special place in memory.
8472  Can be used for instance when using bank switching to put the const data
8473  in a bank.
8474 \layout List
8475 \labelwidthstring 00.00.0000
8476
8477
8478 \series bold 
8479 more-pedantic
8480 \series default 
8481  Actually this is 
8482 \series bold 
8483 \emph on 
8484 not
8485 \series default 
8486 \emph default 
8487  a SDCC compiler option but if you want 
8488 \emph on 
8489 more
8490 \emph default 
8491  warnings you can use a separate tool dedicated to syntax checking like
8492  splint
8493 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8494
8495 \end_inset 
8496
8497
8498 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8499
8500 \end_inset 
8501
8502  
8503 \begin_inset LatexCommand \url{http://www.splint.org}
8504
8505 \end_inset 
8506
8507 .
8508  To make your source files parseable by splint you will have to include
8509  
8510 \family sans 
8511 lint.h
8512 \family default 
8513
8514 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8515
8516 \end_inset 
8517
8518  in your source file and add brackets around extended keywords (like 
8519 \family sans 
8520
8521 \begin_inset Quotes sld
8522 \end_inset 
8523
8524 __at\SpecialChar ~
8525
8526 \series bold 
8527 (
8528 \series default 
8529 0xab
8530 \series bold 
8531 )
8532 \series default 
8533
8534 \begin_inset Quotes srd
8535 \end_inset 
8536
8537
8538 \family default 
8539  and 
8540 \family sans 
8541
8542 \begin_inset Quotes sld
8543 \end_inset 
8544
8545 __interrupt\SpecialChar ~
8546 (2)
8547 \begin_inset Quotes srd
8548 \end_inset 
8549
8550
8551 \family default 
8552 ).
8553  
8554 \newline 
8555 Splint has an excellent on line manual at 
8556 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8557
8558 \end_inset 
8559
8560  and it's capabilities go beyond pure syntax checking.
8561  You'll need to tell splint the location of SDCC's include files so a typical
8562  command line could look like this: 
8563 \newline 
8564
8565 \family sans 
8566 splint\SpecialChar ~
8567 -I\SpecialChar ~
8568 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8569 \SpecialChar ~
8570 myprogram.c
8571 \layout Subsection
8572
8573 Intermediate Dump Options
8574 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8575
8576 \end_inset 
8577
8578
8579 \begin_inset LatexCommand \index{Options intermediate dump}
8580
8581 \end_inset 
8582
8583
8584 \begin_inset LatexCommand \index{Intermediate dump options}
8585
8586 \end_inset 
8587
8588
8589 \layout Standard
8590
8591 The following options are provided for the purpose of retargetting and debugging
8592  the compiler.
8593  They provide a means to dump the intermediate code (iCode
8594 \begin_inset LatexCommand \index{iCode}
8595
8596 \end_inset 
8597
8598 ) generated by the compiler in human readable form at various stages of
8599  the compilation process.
8600  More on iCodes see chapter 
8601 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8602
8603 \end_inset 
8604
8605  
8606 \begin_inset Quotes srd
8607 \end_inset 
8608
8609 The anatomy of the compiler
8610 \begin_inset Quotes srd
8611 \end_inset 
8612
8613 .
8614 \layout List
8615 \labelwidthstring 00.00.0000
8616
8617
8618 \series bold 
8619 -
8620 \begin_inset ERT
8621 status Collapsed
8622
8623 \layout Standard
8624
8625 \backslash 
8626 /
8627 \end_inset 
8628
8629 -dumpraw
8630 \begin_inset LatexCommand \index{-\/-dumpraw}
8631
8632 \end_inset 
8633
8634
8635 \series default 
8636  This option will cause the compiler to dump the intermediate code into
8637  a file of named 
8638 \emph on 
8639 <source filename>.dumpraw
8640 \emph default 
8641  just after the intermediate code has been generated for a function, i.e.
8642  before any optimizations are done.
8643  The basic blocks
8644 \begin_inset LatexCommand \index{Basic blocks}
8645
8646 \end_inset 
8647
8648  at this stage ordered in the depth first number, so they may not be in
8649  sequence of execution.
8650 \layout List
8651 \labelwidthstring 00.00.0000
8652
8653
8654 \series bold 
8655 -
8656 \begin_inset ERT
8657 status Collapsed
8658
8659 \layout Standard
8660
8661 \backslash 
8662 /
8663 \end_inset 
8664
8665 -dumpgcse
8666 \begin_inset LatexCommand \index{-\/-dumpgcse}
8667
8668 \end_inset 
8669
8670
8671 \series default 
8672  Will create a dump of iCode's, after global subexpression elimination
8673 \begin_inset LatexCommand \index{Global subexpression elimination}
8674
8675 \end_inset 
8676
8677 , into a file named 
8678 \emph on 
8679 <source filename>.dumpgcse.
8680 \layout List
8681 \labelwidthstring 00.00.0000
8682
8683
8684 \series bold 
8685 -
8686 \begin_inset ERT
8687 status Collapsed
8688
8689 \layout Standard
8690
8691 \backslash 
8692 /
8693 \end_inset 
8694
8695 -dumpdeadcode
8696 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8697
8698 \end_inset 
8699
8700
8701 \series default 
8702  Will create a dump of iCode's, after deadcode elimination
8703 \begin_inset LatexCommand \index{Dead-code elimination}
8704
8705 \end_inset 
8706
8707 , into a file named 
8708 \emph on 
8709 <source filename>.dumpdeadcode.
8710 \layout List
8711 \labelwidthstring 00.00.0000
8712
8713
8714 \series bold 
8715 -
8716 \begin_inset ERT
8717 status Collapsed
8718
8719 \layout Standard
8720
8721 \backslash 
8722 /
8723 \end_inset 
8724
8725 -dumploop
8726 \begin_inset LatexCommand \index{-\/-dumploop}
8727
8728 \end_inset 
8729
8730
8731 \series default 
8732 \size large 
8733  
8734 \size default 
8735 Will create a dump of iCode's, after loop optimizations
8736 \begin_inset LatexCommand \index{Loop optimization}
8737
8738 \end_inset 
8739
8740 , into a file named 
8741 \emph on 
8742 <source filename>.dumploop.
8743 \layout List
8744 \labelwidthstring 00.00.0000
8745
8746
8747 \series bold 
8748 -
8749 \begin_inset ERT
8750 status Collapsed
8751
8752 \layout Standard
8753
8754 \backslash 
8755 /
8756 \end_inset 
8757
8758 -dumprange
8759 \begin_inset LatexCommand \index{-\/-dumprange}
8760
8761 \end_inset 
8762
8763
8764 \series default 
8765 \size large 
8766  
8767 \size default 
8768 Will create a dump of iCode's, after live range analysis
8769 \begin_inset LatexCommand \index{Live range analysis}
8770
8771 \end_inset 
8772
8773 , into a file named 
8774 \emph on 
8775 <source filename>.dumprange.
8776 \layout List
8777 \labelwidthstring 00.00.0000
8778
8779
8780 \series bold 
8781 -
8782 \begin_inset ERT
8783 status Collapsed
8784
8785 \layout Standard
8786
8787 \backslash 
8788 /
8789 \end_inset 
8790
8791 -dumlrange
8792 \begin_inset LatexCommand \index{-\/-dumlrange}
8793
8794 \end_inset 
8795
8796
8797 \series default 
8798  Will dump the life ranges
8799 \begin_inset LatexCommand \index{Live range analysis}
8800
8801 \end_inset 
8802
8803  for all symbols.
8804 \layout List
8805 \labelwidthstring 00.00.0000
8806
8807
8808 \series bold 
8809 -
8810 \begin_inset ERT
8811 status Collapsed
8812
8813 \layout Standard
8814
8815 \backslash 
8816 /
8817 \end_inset 
8818
8819 -dumpregassign
8820 \begin_inset LatexCommand \index{-\/-dumpregassign}
8821
8822 \end_inset 
8823
8824
8825 \bar under 
8826  
8827 \series default 
8828 \bar default 
8829 Will create a dump of iCode's, after register assignment
8830 \begin_inset LatexCommand \index{Register assignment}
8831
8832 \end_inset 
8833
8834 , into a file named 
8835 \emph on 
8836 <source filename>.dumprassgn.
8837 \layout List
8838 \labelwidthstring 00.00.0000
8839
8840
8841 \series bold 
8842 -
8843 \begin_inset ERT
8844 status Collapsed
8845
8846 \layout Standard
8847
8848 \backslash 
8849 /
8850 \end_inset 
8851
8852 -dumplrange
8853 \begin_inset LatexCommand \index{-\/-dumplrange}
8854
8855 \end_inset 
8856
8857
8858 \series default 
8859  Will create a dump of the live ranges of iTemp's
8860 \layout List
8861 \labelwidthstring 00.00.0000
8862
8863
8864 \series bold 
8865 -
8866 \begin_inset ERT
8867 status Collapsed
8868
8869 \layout Standard
8870
8871 \backslash 
8872 /
8873 \end_inset 
8874
8875 -dumpall
8876 \begin_inset LatexCommand \index{-\/-dumpall}
8877
8878 \end_inset 
8879
8880
8881 \size large 
8882 \bar under 
8883  
8884 \series default 
8885 \size default 
8886 \bar default 
8887 Will cause all the above mentioned dumps to be created.
8888 \layout Subsection
8889
8890 Redirecting output on Windows Shells
8891 \layout Standard
8892
8893 By default SDCC writes it's error messages to 
8894 \begin_inset Quotes sld
8895 \end_inset 
8896
8897 standard error
8898 \begin_inset Quotes srd
8899 \end_inset 
8900
8901 .
8902  To force all messages to 
8903 \begin_inset Quotes sld
8904 \end_inset 
8905
8906 standard output
8907 \begin_inset Quotes srd
8908 \end_inset 
8909
8910  use 
8911 \series bold 
8912 -
8913 \series default 
8914 \emph on 
8915
8916 \begin_inset ERT
8917 status Collapsed
8918
8919 \layout Standard
8920
8921 \backslash 
8922 /
8923 \end_inset 
8924
8925
8926 \series bold 
8927 \emph default 
8928 -
8929 \series default 
8930 use-stdout
8931 \begin_inset LatexCommand \index{-\/-use-stdout}
8932
8933 \end_inset 
8934
8935 .
8936  Additionally, if you happen to have visual studio installed in your windows
8937  machine, you can use it to compile your sources using a custom build and
8938  the SDCC -
8939 \emph on 
8940
8941 \begin_inset ERT
8942 status Collapsed
8943
8944 \layout Standard
8945
8946 \backslash 
8947 /
8948 \end_inset 
8949
8950
8951 \emph default 
8952 -vc
8953 \begin_inset LatexCommand \index{-\/-vc}
8954
8955 \end_inset 
8956
8957  option.
8958  Something like this should work:
8959 \newline 
8960
8961 \newline 
8962
8963 \series bold 
8964 c:
8965 \backslash 
8966 sdcc
8967 \backslash 
8968 bin
8969 \backslash 
8970 sdcc.exe -
8971 \series default 
8972 \emph on 
8973
8974 \begin_inset ERT
8975 status Collapsed
8976
8977 \layout Standard
8978
8979 \backslash 
8980 /
8981 \end_inset 
8982
8983
8984 \series bold 
8985 \emph default 
8986 -vc -
8987 \series default 
8988 \emph on 
8989
8990 \begin_inset ERT
8991 status Collapsed
8992
8993 \layout Standard
8994
8995 \backslash 
8996 /
8997 \end_inset 
8998
8999
9000 \series bold 
9001 \emph default 
9002 -model-large -c $(InputPath)
9003 \layout Section
9004
9005 Environment variables
9006 \begin_inset LatexCommand \index{Environment variables}
9007
9008 \end_inset 
9009
9010
9011 \layout Standard
9012
9013 SDCC recognizes the following environment variables:
9014 \layout List
9015 \labelwidthstring 00.00.0000
9016
9017
9018 \series bold 
9019 SDCC_LEAVE_SIGNALS
9020 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9021
9022 \end_inset 
9023
9024
9025 \series default 
9026  SDCC installs a signal handler
9027 \begin_inset LatexCommand \index{signal handler}
9028
9029 \end_inset 
9030
9031  to be able to delete temporary files after an user break (^C) or an exception.
9032  If this environment variable is set, SDCC won't install the signal handler
9033  in order to be able to debug SDCC.
9034 \layout List
9035 \labelwidthstring 00.00.0000
9036
9037
9038 \series bold 
9039 TMP,\SpecialChar ~
9040 TEMP,\SpecialChar ~
9041 TMPDIR
9042 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9043
9044 \end_inset 
9045
9046
9047 \series default 
9048  Path, where temporary files will be created.
9049  The order of the variables is the search order.
9050  In a standard *nix environment these variables are not set, and there's
9051  no need to set them.
9052  On Windows it's recommended to set one of them.
9053 \layout List
9054 \labelwidthstring 00.00.0000
9055
9056
9057 \series bold 
9058 SDCC_HOME
9059 \begin_inset LatexCommand \index{SDCC\_HOME}
9060
9061 \end_inset 
9062
9063
9064 \series default 
9065  Path, see section 
9066 \begin_inset LatexCommand \ref{sub:Install-paths}
9067
9068 \end_inset 
9069
9070 \SpecialChar ~
9071
9072 \begin_inset Quotes sld
9073 \end_inset 
9074
9075  Install Paths
9076 \begin_inset Quotes srd
9077 \end_inset 
9078
9079 .
9080 \layout List
9081 \labelwidthstring 00.00.0000
9082
9083
9084 \series bold 
9085 SDCC_INCLUDE
9086 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9087
9088 \end_inset 
9089
9090
9091 \series default 
9092  Path, see section 
9093 \begin_inset LatexCommand \ref{sub:Search-Paths}
9094
9095 \end_inset 
9096
9097 \SpecialChar ~
9098
9099 \begin_inset Quotes sld
9100 \end_inset 
9101
9102 Search Paths
9103 \begin_inset Quotes srd
9104 \end_inset 
9105
9106 .
9107 \layout List
9108 \labelwidthstring 00.00.0000
9109
9110
9111 \series bold 
9112 SDCC_LIB
9113 \begin_inset LatexCommand \index{SDCC\_LIB}
9114
9115 \end_inset 
9116
9117
9118 \series default 
9119  Path, see section 
9120 \begin_inset LatexCommand \ref{sub:Search-Paths}
9121
9122 \end_inset 
9123
9124 \SpecialChar ~
9125
9126 \begin_inset Quotes sld
9127 \end_inset 
9128
9129 Search Paths
9130 \begin_inset Quotes srd
9131 \end_inset 
9132
9133 ..
9134 \layout Standard
9135
9136 There are some more environment variables recognized by SDCC, but these
9137  are solely used for debugging purposes.
9138  They can change or disappear very quickly, and will never be documented.
9139 \layout Section
9140
9141 Storage Class Language Extensions
9142 \layout Subsection
9143
9144 MCS51/DS390 Storage Class
9145 \begin_inset LatexCommand \index{Storage class}
9146
9147 \end_inset 
9148
9149  Language Extensions
9150 \layout Standard
9151
9152 In addition to the ANSI storage classes SDCC allows the following MCS51
9153  specific storage classes:
9154 \layout Subsubsection
9155
9156 data
9157 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9158
9159 \end_inset 
9160
9161
9162 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9163
9164 \end_inset 
9165
9166  / near
9167 \begin_inset LatexCommand \index{near (storage class)}
9168
9169 \end_inset 
9170
9171
9172 \begin_inset LatexCommand \index{\_\_near (storage class)}
9173
9174 \end_inset 
9175
9176
9177 \layout Standard
9178
9179 This is the 
9180 \series bold 
9181 default
9182 \series default 
9183  storage class for the Small Memory model (
9184 \emph on 
9185 data
9186 \emph default 
9187  and 
9188 \emph on 
9189 near
9190 \emph default 
9191  or the more ANSI-C compliant forms 
9192 \emph on 
9193 __data
9194 \emph default 
9195  and 
9196 \emph on 
9197 __near
9198 \emph default 
9199  can be used synonymously).
9200  Variables declared with this storage class will be allocated in the directly
9201  addressable portion of the internal RAM of a 8051, e.g.:
9202 \layout Verse
9203
9204
9205 \family typewriter 
9206 __data unsigned char test_data;
9207 \layout Standard
9208
9209 Writing 0x01 to this variable generates the assembly code:
9210 \layout Verse
9211
9212
9213 \family typewriter 
9214 75*00 01\SpecialChar ~
9215 \SpecialChar ~
9216 \SpecialChar ~
9217 mov\SpecialChar ~
9218 \SpecialChar ~
9219 _test_data,#0x01
9220 \layout Subsubsection
9221
9222 xdata
9223 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9224
9225 \end_inset 
9226
9227
9228 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9229
9230 \end_inset 
9231
9232  / far
9233 \begin_inset LatexCommand \index{far (storage class)}
9234
9235 \end_inset 
9236
9237
9238 \begin_inset LatexCommand \index{\_\_far (storage class)}
9239
9240 \end_inset 
9241
9242
9243 \layout Standard
9244
9245 Variables declared with this storage class will be placed in the external
9246  RAM.
9247  This is the 
9248 \series bold 
9249 default
9250 \series default 
9251  storage class for the Large Memory model, e.g.:
9252 \layout Verse
9253
9254
9255 \family typewriter 
9256 __xdata unsigned char test_xdata;
9257 \layout Standard
9258
9259 Writing 0x01 to this variable generates the assembly code:
9260 \layout Verse
9261
9262
9263 \family typewriter 
9264 90s00r00\SpecialChar ~
9265 \SpecialChar ~
9266 \SpecialChar ~
9267 mov\SpecialChar ~
9268 \SpecialChar ~
9269 dptr,#_test_xdata 
9270 \newline 
9271 74\SpecialChar ~
9272 01\SpecialChar ~
9273 \SpecialChar ~
9274 \SpecialChar ~
9275 \SpecialChar ~
9276 \SpecialChar ~
9277 \SpecialChar ~
9278 mov\SpecialChar ~
9279 \SpecialChar ~
9280 a,#0x01 
9281 \newline 
9282 F0\SpecialChar ~
9283 \SpecialChar ~
9284 \SpecialChar ~
9285 \SpecialChar ~
9286 \SpecialChar ~
9287 \SpecialChar ~
9288 \SpecialChar ~
9289 \SpecialChar ~
9290 \SpecialChar ~
9291 movx\SpecialChar ~
9292 @dptr,a 
9293 \layout Subsubsection
9294
9295 idata
9296 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9297
9298 \end_inset 
9299
9300
9301 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9302
9303 \end_inset 
9304
9305
9306 \layout Standard
9307
9308 Variables declared with this storage class will be allocated into the indirectly
9309  addressable portion of the internal ram of a 8051, e.g.:
9310 \layout Verse
9311
9312
9313 \family typewriter 
9314 __idata unsigned char test_idata;
9315 \layout Standard
9316
9317 Writing 0x01 to this variable generates the assembly code:
9318 \layout Verse
9319
9320
9321 \family typewriter 
9322 78r00\SpecialChar ~
9323 \SpecialChar ~
9324 \SpecialChar ~
9325 \SpecialChar ~
9326 \SpecialChar ~
9327 \SpecialChar ~
9328 \SpecialChar ~
9329 mov\SpecialChar ~
9330 \SpecialChar ~
9331 r0,#_test_idata
9332 \newline 
9333 76\SpecialChar ~
9334 01\SpecialChar ~
9335 \SpecialChar ~
9336 \SpecialChar ~
9337 \SpecialChar ~
9338 \SpecialChar ~
9339 \SpecialChar ~
9340 \SpecialChar ~
9341 mov\SpecialChar ~
9342 \SpecialChar ~
9343 @r0,#0x01
9344 \layout Standard
9345
9346 Please note, the first 128 byte of idata physically access the same RAM
9347  as the data memory.
9348  The original 8051 had 128 byte idata memory, nowadays most devices have
9349  256 byte idata memory.
9350  The stack
9351 \begin_inset LatexCommand \index{stack}
9352
9353 \end_inset 
9354
9355  is located in idata memory.
9356 \layout Subsubsection
9357
9358 pdata
9359 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9360
9361 \end_inset 
9362
9363
9364 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9365
9366 \end_inset 
9367
9368
9369 \layout Standard
9370
9371 Paged xdata access is just as straightforward as using the other addressing
9372  modes of a 8051.
9373  It is typically located at the start of xdata and has a maximum size of
9374  256 bytes.
9375  The following example writes 0x01 to the pdata variable.
9376  Please note, pdata access physically accesses xdata memory.
9377  The high byte of the address is determined by port P2 
9378 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9379
9380 \end_inset 
9381
9382 (or in case of some 8051 variants by a separate Special Function Register,
9383  see section 
9384 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9385
9386 \end_inset 
9387
9388 ).
9389  This is the 
9390 \series bold 
9391 default
9392 \series default 
9393  storage class for the Medium Memory model, e.g.:
9394 \layout Verse
9395
9396
9397 \family typewriter 
9398 __pdata unsigned char test_pdata;
9399 \layout Standard
9400
9401 Writing 0x01 to this variable generates the assembly code:
9402 \layout Verse
9403
9404
9405 \family typewriter 
9406 78r00\SpecialChar ~
9407 \SpecialChar ~
9408 \SpecialChar ~
9409 \SpecialChar ~
9410 \SpecialChar ~
9411 \SpecialChar ~
9412 mov r0,#_test_pdata
9413 \newline 
9414 74 01\SpecialChar ~
9415 \SpecialChar ~
9416 \SpecialChar ~
9417 \SpecialChar ~
9418 \SpecialChar ~
9419 \SpecialChar ~
9420 mov a,#0x01 
9421 \newline 
9422 F2\SpecialChar ~
9423 \SpecialChar ~
9424 \SpecialChar ~
9425 \SpecialChar ~
9426 \SpecialChar ~
9427 \SpecialChar ~
9428 \SpecialChar ~
9429 \SpecialChar ~
9430 \SpecialChar ~
9431 movx @r0,a
9432 \layout Standard
9433
9434 If the -
9435 \begin_inset ERT
9436 status Collapsed
9437
9438 \layout Standard
9439
9440 \backslash 
9441 /
9442 \end_inset 
9443
9444 -xstack
9445 \begin_inset LatexCommand \index{-\/-xstack}
9446
9447 \end_inset 
9448
9449  option is used the pdata memory area is followed by the xstack memory area
9450  and the sum of their sizes is limited to 256 bytes.
9451 \layout Subsubsection
9452
9453 code
9454 \begin_inset LatexCommand \index{code}
9455
9456 \end_inset 
9457
9458
9459 \begin_inset LatexCommand \index{\_\_code}
9460
9461 \end_inset 
9462
9463
9464 \layout Standard
9465
9466 'Variables' declared with this storage class will be placed in the code
9467  memory:
9468 \layout Verse
9469
9470
9471 \family typewriter 
9472 __code unsigned char test_code;
9473 \layout Standard
9474
9475 Read access to this variable generates the assembly code:
9476 \layout Verse
9477
9478
9479 \family typewriter 
9480 90s00r6F\SpecialChar ~
9481 \SpecialChar ~
9482 \SpecialChar ~
9483 mov dptr,#_test_code
9484 \newline 
9485 E4\SpecialChar ~
9486 \SpecialChar ~
9487 \SpecialChar ~
9488 \SpecialChar ~
9489 \SpecialChar ~
9490 \SpecialChar ~
9491 \SpecialChar ~
9492 \SpecialChar ~
9493 \SpecialChar ~
9494 clr a
9495 \newline 
9496 93\SpecialChar ~
9497 \SpecialChar ~
9498 \SpecialChar ~
9499 \SpecialChar ~
9500 \SpecialChar ~
9501 \SpecialChar ~
9502 \SpecialChar ~
9503 \SpecialChar ~
9504 \SpecialChar ~
9505 movc a,@a+dptr 
9506 \layout Standard
9507
9508
9509 \family typewriter 
9510 char
9511 \family default 
9512  indexed arrays of characters in code memory can be accessed efficiently:
9513 \layout Verse
9514
9515
9516 \family typewriter 
9517 __code char test_array[] = {'c','h','e','a','p'}; 
9518 \layout Standard
9519
9520 Read access to this array using an 8-bit unsigned index generates the assembly
9521  code:
9522 \layout Verse
9523
9524
9525 \family typewriter 
9526 E5*00\SpecialChar ~
9527 \SpecialChar ~
9528 \SpecialChar ~
9529 \SpecialChar ~
9530 \SpecialChar ~
9531 \SpecialChar ~
9532 mov a,_index 
9533 \layout Verse
9534
9535
9536 \family typewriter 
9537 90s00r41\SpecialChar ~
9538 \SpecialChar ~
9539 \SpecialChar ~
9540 mov dptr,#_test_array
9541 \layout Verse
9542
9543
9544 \family typewriter 
9545 93\SpecialChar ~
9546 \SpecialChar ~
9547 \SpecialChar ~
9548 \SpecialChar ~
9549 \SpecialChar ~
9550 \SpecialChar ~
9551 \SpecialChar ~
9552 \SpecialChar ~
9553 \SpecialChar ~
9554 movc a,@a+dptr 
9555 \layout Subsubsection
9556
9557 bit
9558 \begin_inset LatexCommand \index{bit}
9559
9560 \end_inset 
9561
9562
9563 \begin_inset LatexCommand \index{\_\_bit}
9564
9565 \end_inset 
9566
9567
9568 \layout Standard
9569
9570 This is a data-type and a storage class specifier.
9571  When a variable is declared as a bit, it is allocated into the bit addressable
9572  memory of 8051, e.g.:
9573 \layout Verse
9574
9575
9576 \family typewriter 
9577 __bit test_bit;
9578 \layout Standard
9579
9580 Writing 1 to this variable generates the assembly code:
9581 \layout Verse
9582
9583
9584 \family typewriter 
9585 D2*00\SpecialChar ~
9586 \SpecialChar ~
9587 \SpecialChar ~
9588 \SpecialChar ~
9589 \SpecialChar ~
9590 \SpecialChar ~
9591 \SpecialChar ~
9592 setb\SpecialChar ~
9593 _test_bit
9594 \layout Standard
9595
9596 The bit addressable memory consists of 128 bits which are located from 0x20
9597  to 0x2f in data memory.
9598  
9599 \newline 
9600 Apart from this 8051 specific storage class most architectures support ANSI-C
9601  bitfields
9602 \begin_inset LatexCommand \index{bitfields}
9603
9604 \end_inset 
9605
9606
9607 \begin_inset Foot
9608 collapsed false
9609
9610 \layout Standard
9611
9612 Not really meant as examples, but nevertheless showing what bitfields are
9613  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9614 \end_inset 
9615
9616 .
9617  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9618  signed modifier are implemented as unsigned.
9619 \layout Subsubsection
9620
9621 sfr
9622 \begin_inset LatexCommand \index{sfr}
9623
9624 \end_inset 
9625
9626
9627 \begin_inset LatexCommand \index{\_\_sfr}
9628
9629 \end_inset 
9630
9631  / sfr16
9632 \begin_inset LatexCommand \index{sfr16}
9633
9634 \end_inset 
9635
9636
9637 \begin_inset LatexCommand \index{\_\_sfr16}
9638
9639 \end_inset 
9640
9641  / sfr32
9642 \begin_inset LatexCommand \index{sfr32}
9643
9644 \end_inset 
9645
9646
9647 \begin_inset LatexCommand \index{\_\_sfr32}
9648
9649 \end_inset 
9650
9651  / sbit
9652 \begin_inset LatexCommand \index{\_\_sbit}
9653
9654 \end_inset 
9655
9656
9657 \layout Standard
9658
9659 Like the bit keyword, 
9660 \emph on 
9661 sfr / sfr16 / sfr32 / sbit 
9662 \emph default 
9663 signify both a data-type and storage class, they are used to describe the
9664  
9665 \emph on 
9666 s
9667 \emph default 
9668 pecial 
9669 \emph on 
9670 f
9671 \emph default 
9672 unction 
9673 \emph on 
9674 r
9675 \emph default 
9676 egisters and 
9677 \emph on 
9678 s
9679 \emph default 
9680 pecial 
9681 \emph on 
9682 bit
9683 \emph default 
9684  variables of a 8051, eg:
9685 \layout Verse
9686
9687
9688 \family typewriter 
9689 __sfr __at
9690 \begin_inset LatexCommand \index{at}
9691
9692 \end_inset 
9693
9694
9695 \begin_inset LatexCommand \index{\_\_at}
9696
9697 \end_inset 
9698
9699  (0x80) P0;\SpecialChar ~
9700  /* special function register P0 at location 0x80 */
9701 \newline 
9702 /* 16 bit special function register combination for timer 0 */
9703 \newline 
9704 /* with the high byte at location 0x8C and the low byte at location 0x8A
9705  */
9706 \newline 
9707 __sfr16 __at
9708 \begin_inset LatexCommand \index{at}
9709
9710 \end_inset 
9711
9712
9713 \begin_inset LatexCommand \index{\_\_at}
9714
9715 \end_inset 
9716
9717  (0x8C8A) TMR0;
9718 \newline 
9719 __sbit __at (0xd7) CY; /* CY (Carry Flag
9720 \begin_inset LatexCommand \index{Flags}
9721
9722 \end_inset 
9723
9724
9725 \begin_inset LatexCommand \index{Carry flag}
9726
9727 \end_inset 
9728
9729 ) */
9730 \layout Standard
9731
9732 Special function registers which are located on an address dividable by
9733  8 are bit-addressable, an
9734 \emph on 
9735  sbit
9736 \emph default 
9737  addresses a specific bit within these sfr.
9738 \newline 
9739 16 Bit and 32 bit special function register combinations which require a
9740  certain access order are better not declared using 
9741 \emph on 
9742 sfr16
9743 \emph default 
9744  or 
9745 \emph on 
9746 sfr32.
9747
9748 \emph default 
9749  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9750  this is not guaranteed.
9751 \layout Subsubsection
9752
9753 Pointers
9754 \begin_inset LatexCommand \index{Pointer}
9755
9756 \end_inset 
9757
9758  to MCS51/DS390 specific memory spaces
9759 \layout Standard
9760
9761 SDCC allows (via language extensions) pointers to explicitly point to any
9762  of the memory spaces
9763 \begin_inset LatexCommand \index{Memory model}
9764
9765 \end_inset 
9766
9767  of the 8051.
9768  In addition to the explicit pointers, the compiler uses (by default) generic
9769  pointers which can be used to point to any of the memory spaces.
9770 \newline 
9771
9772 \newline 
9773 Pointer declaration examples:
9774 \layout Verse
9775
9776
9777 \family typewriter 
9778 /* pointer physically in internal ram pointing to object in external ram
9779  */ 
9780 \newline 
9781 __xdata unsigned char * __data p;
9782 \newline 
9783
9784 \newline 
9785 /* pointer physically in external ram pointing to object in internal ram
9786  */ 
9787 \newline 
9788 __data unsigned char * __xdata p;
9789 \newline 
9790
9791 \newline 
9792 /* pointer physically in code rom pointing to data in xdata space */ 
9793 \newline 
9794 __xdata unsigned char * __code p;
9795 \newline 
9796
9797 \newline 
9798 /* pointer physically in code space pointing to data in code space */ 
9799 \newline 
9800 __code unsigned char * __code p;
9801 \newline 
9802
9803 \newline 
9804 /* the following is a generic pointer physically located in xdata space
9805  */
9806 \newline 
9807 char * __xdata p;
9808 \newline 
9809
9810 \newline 
9811 /* the following is a function pointer physically located in data space
9812  */
9813 \newline 
9814 char (* __data fp)(void);
9815 \layout Standard
9816
9817 Well you get the idea.
9818  
9819 \newline 
9820
9821 \newline 
9822 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
9823 \emph on 
9824 generic
9825 \emph default 
9826  pointers.
9827  
9828 \size small 
9829
9830 \newline 
9831
9832 \newline 
9833
9834 \size default 
9835 The highest order byte of the 
9836 \emph on 
9837 generic
9838 \emph default 
9839  pointers contains the data space information.
9840  Assembler support routines are called whenever data is stored or retrieved
9841  using 
9842 \emph on 
9843 generic
9844 \emph default 
9845  pointers.
9846  These are useful for developing reusable library
9847 \begin_inset LatexCommand \index{Libraries}
9848
9849 \end_inset 
9850
9851  routines.
9852  Explicitly specifying the pointer type will generate the most efficient
9853  code.
9854 \layout Subsubsection
9855
9856 Notes on MCS51 memory
9857 \begin_inset LatexCommand \index{MCS51 memory}
9858
9859 \end_inset 
9860
9861  layout
9862 \layout Standard
9863
9864 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
9865  RAM memory which is structured as follows:
9866 \newline 
9867
9868 \newline 
9869 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
9870  
9871 \newline 
9872 - Bytes 20-2F - 16 bytes to hold 128 bit
9873 \begin_inset LatexCommand \index{bit}
9874
9875 \end_inset 
9876
9877  variables and, 
9878 \newline 
9879 - Bytes 30-7F - 80 bytes for general purpose use.
9880 \newline 
9881
9882 \layout Standard
9883
9884 Additionally some members of the MCS51 family may have up to 128 bytes of
9885  additional, indirectly addressable, internal RAM memory (
9886 \emph on 
9887 idata
9888 \emph default 
9889
9890 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9891
9892 \end_inset 
9893
9894
9895 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9896
9897 \end_inset 
9898
9899 ).
9900  Furthermore, some chips may have some built in external memory (
9901 \emph on 
9902 xdata
9903 \emph default 
9904
9905 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9906
9907 \end_inset 
9908
9909
9910 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9911
9912 \end_inset 
9913
9914 ) which should not be confused with the internal, directly addressable RAM
9915  memory (
9916 \emph on 
9917 data
9918 \emph default 
9919
9920 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9921
9922 \end_inset 
9923
9924
9925 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9926
9927 \end_inset 
9928
9929 ).
9930  Sometimes this built in 
9931 \emph on 
9932 xdata
9933 \emph default 
9934  memory has to be activated before using it (you can probably find this
9935  information on the datasheet of the microcontroller your are using, see
9936  also section 
9937 \begin_inset LatexCommand \ref{sub:Startup-Code}
9938
9939 \end_inset 
9940
9941 \SpecialChar ~
9942 Startup-Code).
9943 \layout Standard
9944
9945 Normally SDCC will only use the first bank
9946 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9947
9948 \end_inset 
9949
9950  of registers (register bank 0), but it is possible to specify that other
9951  banks of registers (keyword 
9952 \emph on 
9953 using
9954 \emph default 
9955  
9956 \emph on 
9957
9958 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9959
9960 \end_inset 
9961
9962
9963 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
9964
9965 \end_inset 
9966
9967
9968 \emph default 
9969 ) should be used in interrupt
9970 \begin_inset LatexCommand \index{interrupt}
9971
9972 \end_inset 
9973
9974
9975 \begin_inset LatexCommand \index{\_\_interrupt}
9976
9977 \end_inset 
9978
9979  routines.
9980  By default, the compiler will place the stack after the last byte of allocated
9981  memory for variables.
9982  For example, if the first 2 banks of registers are used, and only four
9983  bytes are used for 
9984 \emph on 
9985 data
9986 \emph default 
9987  variables, it will position the base of the internal stack at address 20
9988  (0x14).
9989  This implies that as the stack
9990 \begin_inset LatexCommand \index{stack}
9991
9992 \end_inset 
9993
9994  grows, it will use up the remaining register banks, and the 16 bytes used
9995  by the 128 bit variables, and 80 bytes for general purpose use.
9996  If any bit variables are used, the data variables will be placed in unused
9997  register banks and after the byte holding the last bit variable.
9998  For example, if register banks 0 and 1 are used, and there are 9 bit variables
9999  (two bytes used), 
10000 \emph on 
10001 data
10002 \emph default 
10003  variables will be placed starting from address 0x10 to 0x20 and continue
10004  at address 0x22.
10005  You can also use -
10006 \begin_inset ERT
10007 status Collapsed
10008
10009 \layout Standard
10010
10011 \backslash 
10012 /
10013 \end_inset 
10014
10015 -data-loc
10016 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10017
10018 \end_inset 
10019
10020  to specify the start address of the 
10021 \emph on 
10022 data
10023 \emph default 
10024  and -
10025 \begin_inset ERT
10026 status Collapsed
10027
10028 \layout Standard
10029
10030 \backslash 
10031 /
10032 \end_inset 
10033
10034 -iram-size
10035 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10036
10037 \end_inset 
10038
10039  to specify the size of the total internal RAM (
10040 \emph on 
10041 data
10042 \emph default 
10043 +
10044 \emph on 
10045 idata
10046 \emph default 
10047 ).
10048  
10049 \newline 
10050
10051 \layout Standard
10052
10053 By default the 8051 linker will place the stack after the last byte of (i)data
10054  variables.
10055  Option -
10056 \begin_inset ERT
10057 status Collapsed
10058
10059 \layout Standard
10060
10061 \backslash 
10062 /
10063 \end_inset 
10064
10065 -stack-loc
10066 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10067
10068 \end_inset 
10069
10070  allows you to specify the start of the stack, i.e.
10071  you could start it after any data in the general purpose area.
10072  If your microcontroller has additional indirectly addressable internal
10073  RAM (
10074 \emph on 
10075 idata
10076 \emph default 
10077 ) you can place the stack on it.
10078  You may also need to use -
10079 \begin_inset ERT
10080 status Collapsed
10081
10082 \layout Standard
10083
10084 \backslash 
10085 /
10086 \end_inset 
10087
10088 -xdata-loc
10089 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10090
10091 \end_inset 
10092
10093  to set the start address of the external RAM (
10094 \emph on 
10095 xdata
10096 \emph default 
10097 ) and -
10098 \begin_inset ERT
10099 status Collapsed
10100
10101 \layout Standard
10102
10103 \backslash 
10104 /
10105 \end_inset 
10106
10107 -xram-size
10108 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10109
10110 \end_inset 
10111
10112  to specify its size.
10113  Same goes for the code memory, using -
10114 \begin_inset ERT
10115 status Collapsed
10116
10117 \layout Standard
10118
10119 \backslash 
10120 /
10121 \end_inset 
10122
10123 -code-loc
10124 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10125
10126 \end_inset 
10127
10128  and -
10129 \begin_inset ERT
10130 status Collapsed
10131
10132 \layout Standard
10133
10134 \backslash 
10135 /
10136 \end_inset 
10137
10138 -code-size
10139 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10140
10141 \end_inset 
10142
10143 .
10144  If in doubt, don't specify any options and see if the resulting memory
10145  layout is appropriate, then you can adjust it.
10146 \layout Standard
10147
10148 The linker generates two files with memory allocation information.
10149  The first, with extension .map
10150 \begin_inset LatexCommand \index{<file>.map}
10151
10152 \end_inset 
10153
10154  shows all the variables and segments.
10155  The second with extension .mem
10156 \begin_inset LatexCommand \index{<file>.mem}
10157
10158 \end_inset 
10159
10160  shows the final memory layout.
10161  The linker will complain either if memory segments overlap, there is not
10162  enough memory, or there is not enough space for stack.
10163  If you get any linking warnings and/or errors related to stack or segments
10164  allocation, take a look at either the .map or .mem files to find out what
10165  the problem is.
10166  The .mem file may even suggest a solution to the problem.
10167 \layout Subsection
10168
10169 Z80/Z180 Storage Class
10170 \begin_inset LatexCommand \index{Storage class}
10171
10172 \end_inset 
10173
10174  Language Extensions
10175 \layout Subsubsection
10176
10177 sfr
10178 \begin_inset LatexCommand \index{sfr}
10179
10180 \end_inset 
10181
10182
10183 \begin_inset LatexCommand \index{\_\_sfr}
10184
10185 \end_inset 
10186
10187  (in/out to 8-bit addresses)
10188 \layout Standard
10189
10190 The Z80
10191 \begin_inset LatexCommand \index{Z80}
10192
10193 \end_inset 
10194
10195  family has separate address spaces for memory and 
10196 \emph on 
10197 i
10198 \emph default 
10199 nput/
10200 \emph on 
10201 o
10202 \emph default 
10203 utput memory.
10204  I/O memory
10205 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10206
10207 \end_inset 
10208
10209  is accessed with special instructions, e.g.:
10210 \layout Verse
10211
10212
10213 \family typewriter 
10214 sfr at 0x78 IoPort;\SpecialChar ~
10215 \SpecialChar ~
10216 /* define a var in I/O space at 78h called IoPort */
10217  
10218 \layout Standard
10219
10220 Writing 0x01 to this variable generates the assembly code:
10221 \layout Verse
10222
10223
10224 \family typewriter 
10225 3E 01\SpecialChar ~
10226 \SpecialChar ~
10227 \SpecialChar ~
10228 \SpecialChar ~
10229 \SpecialChar ~
10230 \SpecialChar ~
10231 ld a,#0x01
10232 \newline 
10233 D3 78\SpecialChar ~
10234 \SpecialChar ~
10235 \SpecialChar ~
10236 \SpecialChar ~
10237 \SpecialChar ~
10238 \SpecialChar ~
10239 out (_IoPort),a 
10240 \layout Subsubsection
10241
10242 banked sfr
10243 \begin_inset LatexCommand \index{sfr}
10244
10245 \end_inset 
10246
10247
10248 \begin_inset LatexCommand \index{\_\_sfr}
10249
10250 \end_inset 
10251
10252  (in/out to 16-bit addresses)
10253 \layout Standard
10254
10255 The keyword 
10256 \emph on 
10257 banked
10258 \emph default 
10259  is used to support 16 bit addresses in I/O memory e.g.:
10260 \layout Verse
10261
10262
10263 \family typewriter 
10264 sfr banked at
10265 \begin_inset LatexCommand \index{at}
10266
10267 \end_inset 
10268
10269
10270 \begin_inset LatexCommand \index{\_\_at}
10271
10272 \end_inset 
10273
10274  0x123 IoPort; 
10275 \layout Standard
10276
10277 Writing 0x01 to this variable generates the assembly code:
10278 \layout Verse
10279
10280
10281 \family typewriter 
10282 01 23 01\SpecialChar ~
10283 \SpecialChar ~
10284 \SpecialChar ~
10285 ld bc,#_IoPort
10286 \newline 
10287 3E 01\SpecialChar ~
10288 \SpecialChar ~
10289 \SpecialChar ~
10290 \SpecialChar ~
10291 \SpecialChar ~
10292 \SpecialChar ~
10293 ld a,#0x01 
10294 \newline 
10295 ED 79\SpecialChar ~
10296 \SpecialChar ~
10297 \SpecialChar ~
10298 \SpecialChar ~
10299 \SpecialChar ~
10300 \SpecialChar ~
10301 out (c),a 
10302 \layout Subsubsection
10303
10304 sfr
10305 \begin_inset LatexCommand \index{sfr}
10306
10307 \end_inset 
10308
10309
10310 \begin_inset LatexCommand \index{\_\_sfr}
10311
10312 \end_inset 
10313
10314  (in0/out0 to 8 bit addresses on Z180
10315 \begin_inset LatexCommand \index{Z180}
10316
10317 \end_inset 
10318
10319 /HD64180
10320 \begin_inset LatexCommand \index{HD64180}
10321
10322 \end_inset 
10323
10324 )
10325 \layout Standard
10326
10327 The compiler option -
10328 \begin_inset ERT
10329 status Collapsed
10330
10331 \layout Standard
10332
10333 \backslash 
10334 /
10335 \end_inset 
10336
10337 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
10338 portmode
10339 \begin_inset LatexCommand \index{\#pragma portmode}
10340
10341 \end_inset 
10342
10343 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10344 ns 
10345 \family typewriter 
10346 in0/out0
10347 \family default 
10348  instead of 
10349 \family typewriter 
10350 in/out
10351 \family default 
10352 .
10353  If you include the file z180.h this will be set automatically.
10354 \layout Subsection
10355
10356 HC08 Storage Class
10357 \begin_inset LatexCommand \index{Storage class}
10358
10359 \end_inset 
10360
10361  Language Extensions
10362 \layout Subsubsection
10363
10364 data
10365 \begin_inset LatexCommand \index{data (hc08 storage class)}
10366
10367 \end_inset 
10368
10369
10370 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10371
10372 \end_inset 
10373
10374  
10375 \layout Standard
10376
10377 The data storage class declares a variable that resides in the first 256
10378  bytes of memory (the direct page).
10379  The HC08 is most efficient at accessing variables (especially pointers)
10380  stored here.
10381 \layout Subsubsection
10382
10383 xdata
10384 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10385
10386 \end_inset 
10387
10388
10389 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10390
10391 \end_inset 
10392
10393  
10394 \layout Standard
10395
10396 The xdata storage class declares a variable that can reside anywhere in
10397  memory.
10398  This is the default if no storage class is specified.
10399  
10400 \layout Section
10401
10402 Absolute Addressing
10403 \begin_inset LatexCommand \index{Absolute addressing}
10404
10405 \end_inset 
10406
10407
10408 \layout Standard
10409
10410 Data items can be assigned an absolute address with the 
10411 \emph on 
10412 at
10413 \begin_inset LatexCommand \index{at}
10414
10415 \end_inset 
10416
10417
10418 \begin_inset LatexCommand \index{\_\_at}
10419
10420 \end_inset 
10421
10422  <address>
10423 \emph default 
10424  keyword, in addition to a storage class, e.g.:
10425 \layout Verse
10426
10427
10428 \family typewriter 
10429 xdata
10430 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10431
10432 \end_inset 
10433
10434
10435 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10436
10437 \end_inset 
10438
10439  at
10440 \begin_inset LatexCommand \index{at}
10441
10442 \end_inset 
10443
10444
10445 \begin_inset LatexCommand \index{\_\_at}
10446
10447 \end_inset 
10448
10449  (0x7ffe) unsigned int chksum;
10450 \layout Standard
10451
10452 or
10453 \layout Verse
10454
10455
10456 \family typewriter 
10457 __xdata __at (0x7ffe) unsigned int chksum;
10458 \layout Standard
10459
10460 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10461  of the external ram.
10462  The compiler does 
10463 \emph on 
10464 not
10465 \emph default 
10466  reserve any space for variables declared in this way
10467 \begin_inset Marginal
10468 collapsed true
10469
10470 \layout Standard
10471
10472
10473 \series bold 
10474 \SpecialChar ~
10475 !
10476 \end_inset 
10477
10478  (they are implemented with an equate in the assembler).
10479  Thus it is left to the programmer to make sure there are no overlaps with
10480  other variables that are declared without the absolute address.
10481  The assembler listing file (.lst
10482 \begin_inset LatexCommand \index{<file>.lst}
10483
10484 \end_inset 
10485
10486 ) and the linker output files (.rst
10487 \begin_inset LatexCommand \index{<file>.rst}
10488
10489 \end_inset 
10490
10491 ) and (.map
10492 \begin_inset LatexCommand \index{<file>.map}
10493
10494 \end_inset 
10495
10496 ) are good places to look for such overlaps.
10497  Variables with an absolute address are 
10498 \emph on 
10499 not
10500 \begin_inset Marginal
10501 collapsed true
10502
10503 \layout Standard
10504
10505
10506 \series bold 
10507 \SpecialChar ~
10508 !
10509 \end_inset 
10510
10511
10512 \emph default 
10513  initialized
10514 \begin_inset LatexCommand \index{Variable initialization}
10515
10516 \end_inset 
10517
10518 .
10519 \layout Standard
10520
10521 In case of memory mapped I/O devices the keyword 
10522 \emph on 
10523 volatile
10524 \emph default 
10525  has to be used to tell the compiler that accesses might not be removed:
10526 \layout Verse
10527
10528
10529 \family typewriter 
10530 volatile
10531 \begin_inset LatexCommand \index{volatile}
10532
10533 \end_inset 
10534
10535  __xdata
10536 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10537
10538 \end_inset 
10539
10540  __at
10541 \begin_inset LatexCommand \index{at}
10542
10543 \end_inset 
10544
10545  (0x8000) unsigned char PORTA_8255;
10546 \layout Standard
10547
10548 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10549 r) array
10550 \family typewriter 
10551 \size footnotesize 
10552
10553 \begin_inset LatexCommand \index{Aligned array}
10554
10555 \end_inset 
10556
10557
10558 \family default 
10559 \size default 
10560  starts at a block (256 byte) boundary
10561 \begin_inset LatexCommand \index{block boundary}
10562
10563 \end_inset 
10564
10565  (section 
10566 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10567
10568 \end_inset 
10569
10570  has an example).
10571 \newline 
10572 Absolute addresses can be specified for variables in all storage classes,
10573  e.g.:
10574 \layout Verse
10575
10576
10577 \family typewriter 
10578 __bit
10579 \begin_inset LatexCommand \index{bit}
10580
10581 \end_inset 
10582
10583  __at
10584 \begin_inset LatexCommand \index{at}
10585
10586 \end_inset 
10587
10588  (0x02) bvar;
10589 \layout Standard
10590
10591 The above example will allocate the variable at offset 0x02 in the bit-addressab
10592 le space.
10593  There is no real advantage to assigning absolute addresses to variables
10594  in this manner, unless you want strict control over all the variables allocated.
10595  One possible use would be to write hardware portable code.
10596  For example, if you have a routine that uses one or more of the microcontroller
10597  I/O pins, and such pins are different for two different hardwares, you
10598  can declare the I/O pins in your routine using:
10599 \layout Verse
10600
10601
10602 \family typewriter 
10603 extern volatile
10604 \begin_inset LatexCommand \index{volatile}
10605
10606 \end_inset 
10607
10608  __bit MOSI;\SpecialChar ~
10609 \SpecialChar ~
10610 \SpecialChar ~
10611 \SpecialChar ~
10612 /* master out, slave in */
10613 \newline 
10614 extern volatile __bit MISO;\SpecialChar ~
10615 \SpecialChar ~
10616 \SpecialChar ~
10617 \SpecialChar ~
10618 /* master in, slave out */
10619 \newline 
10620 extern volatile __bit MCLK;\SpecialChar ~
10621 \SpecialChar ~
10622 \SpecialChar ~
10623 \SpecialChar ~
10624 /* master clock */
10625 \newline 
10626
10627 \newline 
10628 /* Input and Output of a byte on a 3-wire serial bus.
10629 \newline 
10630 \SpecialChar ~
10631 \SpecialChar ~
10632 \SpecialChar ~
10633 If needed adapt polarity of clock, polarity of data and bit order
10634 \newline 
10635 \SpecialChar ~
10636 */
10637 \newline 
10638 unsigned char spi_io(unsigned char out_byte) 
10639 \newline 
10640
10641 \newline 
10642 \SpecialChar ~
10643 \SpecialChar ~
10644 \SpecialChar ~
10645 \SpecialChar ~
10646 unsigned char i=8;
10647 \newline 
10648 \SpecialChar ~
10649 \SpecialChar ~
10650 \SpecialChar ~
10651 \SpecialChar ~
10652 do { 
10653 \newline 
10654 \SpecialChar ~
10655 \SpecialChar ~
10656 \SpecialChar ~
10657 \SpecialChar ~
10658 \SpecialChar ~
10659 \SpecialChar ~
10660 \SpecialChar ~
10661 \SpecialChar ~
10662 MOSI = out_byte & 0x80; 
10663 \newline 
10664 \SpecialChar ~
10665 \SpecialChar ~
10666 \SpecialChar ~
10667 \SpecialChar ~
10668 \SpecialChar ~
10669 \SpecialChar ~
10670 \SpecialChar ~
10671 \SpecialChar ~
10672 out_byte <<= 1;
10673 \newline 
10674 \SpecialChar ~
10675 \SpecialChar ~
10676 \SpecialChar ~
10677 \SpecialChar ~
10678 \SpecialChar ~
10679 \SpecialChar ~
10680 \SpecialChar ~
10681 \SpecialChar ~
10682 MCLK = 1; 
10683 \newline 
10684 \SpecialChar ~
10685 \SpecialChar ~
10686 \SpecialChar ~
10687 \SpecialChar ~
10688 \SpecialChar ~
10689 \SpecialChar ~
10690 \SpecialChar ~
10691 \SpecialChar ~
10692 /* _asm nop _endasm; */\SpecialChar ~
10693 \SpecialChar ~
10694 \SpecialChar ~
10695 \SpecialChar ~
10696 \SpecialChar ~
10697 \SpecialChar ~
10698 \SpecialChar ~
10699 \SpecialChar ~
10700 /* for slow peripherals */
10701 \newline 
10702 \SpecialChar ~
10703 \SpecialChar ~
10704 \SpecialChar ~
10705 \SpecialChar ~
10706 \SpecialChar ~
10707 \SpecialChar ~
10708 \SpecialChar ~
10709 \SpecialChar ~
10710 if(MISO) 
10711 \newline 
10712 \SpecialChar ~
10713 \SpecialChar ~
10714 \SpecialChar ~
10715 \SpecialChar ~
10716 \SpecialChar ~
10717 \SpecialChar ~
10718 \SpecialChar ~
10719 \SpecialChar ~
10720 \SpecialChar ~
10721 \SpecialChar ~
10722 \SpecialChar ~
10723 \SpecialChar ~
10724 out_byte += 1; 
10725 \newline 
10726 \SpecialChar ~
10727 \SpecialChar ~
10728 \SpecialChar ~
10729 \SpecialChar ~
10730 \SpecialChar ~
10731 \SpecialChar ~
10732 \SpecialChar ~
10733 \SpecialChar ~
10734 MCLK = 0; 
10735 \newline 
10736 \SpecialChar ~
10737 \SpecialChar ~
10738 \SpecialChar ~
10739 \SpecialChar ~
10740 } while(--i);
10741 \newline 
10742 \SpecialChar ~
10743 \SpecialChar ~
10744 \SpecialChar ~
10745 \SpecialChar ~
10746 return out_byte; 
10747 \newline 
10748 }
10749 \layout Standard
10750
10751 Then, someplace in the code for the first hardware you would use
10752 \layout Verse
10753
10754
10755 \family typewriter 
10756 __bit __at
10757 \begin_inset LatexCommand \index{at}
10758
10759 \end_inset 
10760
10761
10762 \begin_inset LatexCommand \index{\_\_at}
10763
10764 \end_inset 
10765
10766  (0x80) MOSI;\SpecialChar ~
10767 \SpecialChar ~
10768 \SpecialChar ~
10769 \SpecialChar ~
10770 /* I/O port 0, bit 0 */
10771 \newline 
10772 __bit __at (0x81) MISO;\SpecialChar ~
10773 \SpecialChar ~
10774 \SpecialChar ~
10775 \SpecialChar ~
10776 /* I/O port 0, bit 1 */
10777 \newline 
10778 __bit __at (0x82) MCLK;\SpecialChar ~
10779 \SpecialChar ~
10780 \SpecialChar ~
10781 \SpecialChar ~
10782 /* I/O port 0, bit 2 */
10783 \layout Standard
10784
10785 Similarly, for the second hardware you would use
10786 \layout Verse
10787
10788
10789 \family typewriter 
10790 __bit __at (0x83) MOSI;\SpecialChar ~
10791 \SpecialChar ~
10792 \SpecialChar ~
10793 \SpecialChar ~
10794 /* I/O port 0, bit 3 */
10795 \newline 
10796 __bit __at (0x91) MISO;\SpecialChar ~
10797 \SpecialChar ~
10798 \SpecialChar ~
10799 \SpecialChar ~
10800 /* I/O port 1, bit 1 */
10801 \newline 
10802 __bit
10803 \begin_inset LatexCommand \index{bit}
10804
10805 \end_inset 
10806
10807  __at (0x92) MCLK;\SpecialChar ~
10808 \SpecialChar ~
10809 \SpecialChar ~
10810 \SpecialChar ~
10811 /* I/O port 1, bit 2 */
10812 \layout Standard
10813
10814 and you can use the same hardware dependent routine without changes, as
10815  for example in a library.
10816  This is somehow similar to sbit, but only one absolute address has to be
10817  specified in the whole project.
10818 \layout Section
10819
10820 Parameters
10821 \begin_inset LatexCommand \index{Parameters}
10822
10823 \end_inset 
10824
10825
10826 \begin_inset LatexCommand \index{function parameter}
10827
10828 \end_inset 
10829
10830  & Local Variables
10831 \begin_inset LatexCommand \index{local variables}
10832
10833 \end_inset 
10834
10835
10836 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
10837
10838 \end_inset 
10839
10840
10841 \layout Standard
10842
10843 Automatic (local) variables and parameters to functions can either be placed
10844  on the stack or in data-space.
10845  The default action of the compiler is to place these variables in the internal
10846  RAM (for small model) or external RAM (for large model).
10847  This in fact makes them similar to 
10848 \emph on 
10849 static
10850 \begin_inset LatexCommand \index{static}
10851
10852 \end_inset 
10853
10854
10855 \emph default 
10856  so by default functions are non-reentrant
10857 \begin_inset LatexCommand \index{reentrant}
10858
10859 \end_inset 
10860
10861 .
10862  
10863 \newline 
10864
10865 \newline 
10866 They can be placed on the stack
10867 \begin_inset LatexCommand \index{stack}
10868
10869 \end_inset 
10870
10871  by using the
10872 \emph on 
10873  -
10874 \begin_inset ERT
10875 status Collapsed
10876
10877 \layout Standard
10878
10879 \backslash 
10880 /
10881 \end_inset 
10882
10883 -stack-auto
10884 \begin_inset LatexCommand \index{-\/-stack-auto}
10885
10886 \end_inset 
10887
10888
10889 \emph default 
10890  option, by using 
10891 \emph on 
10892 #pragma\SpecialChar ~
10893 stackauto
10894 \emph default 
10895
10896 \begin_inset LatexCommand \index{\#pragma stackauto}
10897
10898 \end_inset 
10899
10900  or by using the 
10901 \emph on 
10902 reentrant
10903 \begin_inset LatexCommand \index{reentrant}
10904
10905 \end_inset 
10906
10907
10908 \emph default 
10909  keyword in the function declaration, e.g.:
10910 \layout Verse
10911
10912
10913 \family typewriter 
10914 unsigned char foo(char i) __reentrant 
10915 \newline 
10916
10917 \newline 
10918 \SpecialChar ~
10919 \SpecialChar ~
10920 \SpecialChar ~
10921 \SpecialChar ~
10922 ...
10923  
10924 \newline 
10925 }
10926 \layout Standard
10927
10928 Since stack space on 8051 is limited, the 
10929 \emph on 
10930 reentrant 
10931 \emph default 
10932 keyword or the
10933 \emph on 
10934  -
10935 \begin_inset ERT
10936 status Collapsed
10937
10938 \layout Standard
10939
10940 \backslash 
10941 /
10942 \end_inset 
10943
10944 -stack-auto
10945 \emph default 
10946  option should be used sparingly.
10947  Note that the reentrant keyword just means that the parameters & local
10948  variables will be allocated to the stack, it 
10949 \emph on 
10950 does not
10951 \emph default 
10952  mean that the function is register bank
10953 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10954
10955 \end_inset 
10956
10957  independent.
10958 \newline 
10959
10960 \newline 
10961 Local variables
10962 \begin_inset LatexCommand \index{local variables}
10963
10964 \end_inset 
10965
10966  can be assigned storage classes and absolute
10967 \begin_inset LatexCommand \index{Absolute addressing}
10968
10969 \end_inset 
10970
10971  addresses, e.g.: 
10972 \layout Verse
10973
10974
10975 \family typewriter 
10976 unsigned char foo() 
10977 \newline 
10978 {
10979 \newline 
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 __xdata unsigned char i;
10985 \newline 
10986 \SpecialChar ~
10987 \SpecialChar ~
10988 \SpecialChar ~
10989 \SpecialChar ~
10990 __bit bvar;
10991 \newline 
10992 \SpecialChar ~
10993 \SpecialChar ~
10994 \SpecialChar ~
10995 \SpecialChar ~
10996 __data __at
10997 \begin_inset LatexCommand \index{at}
10998
10999 \end_inset 
11000
11001  (0x31) unsigned char j;
11002 \newline 
11003 \SpecialChar ~
11004 \SpecialChar ~
11005 \SpecialChar ~
11006 \SpecialChar ~
11007 ...
11008  
11009 \newline 
11010 }
11011 \layout Standard
11012
11013 In the above example the variable 
11014 \emph on 
11015 i
11016 \emph default 
11017  will be allocated in the external ram, 
11018 \emph on 
11019 bvar
11020 \emph default 
11021  in bit addressable space and
11022 \emph on 
11023  j
11024 \emph default 
11025  in internal ram.
11026  When compiled with 
11027 \emph on 
11028 -
11029 \begin_inset ERT
11030 status Collapsed
11031
11032 \layout Standard
11033
11034 \backslash 
11035 /
11036 \end_inset 
11037
11038 -stack-auto
11039 \emph default 
11040  or when a function is declared as 
11041 \emph on 
11042 reentrant
11043 \emph default 
11044  this should only be done for static variables.
11045 \layout Standard
11046
11047 Parameters
11048 \begin_inset LatexCommand \index{function parameter}
11049
11050 \end_inset 
11051
11052  however are not allowed any storage class
11053 \begin_inset LatexCommand \index{Storage class}
11054
11055 \end_inset 
11056
11057 , (storage classes for parameters will be ignored), their allocation is
11058  governed by the memory model in use, and the reentrancy options.
11059 \layout Standard
11060
11061 It is however allowed to use bit parameters in reentrant functions and also
11062  non-static local bit variables are supported.
11063  Efficient use is limited to 8 semi-bitregisters in bit space.
11064  They are pushed and popped to stack as a single byte just like the normal
11065  registers.
11066 \layout Section
11067
11068 Overlaying
11069 \begin_inset LatexCommand \label{sub:Overlaying}
11070
11071 \end_inset 
11072
11073
11074 \begin_inset LatexCommand \index{Overlaying}
11075
11076 \end_inset 
11077
11078
11079 \layout Standard
11080
11081 For non-reentrant
11082 \begin_inset LatexCommand \index{reentrant}
11083
11084 \end_inset 
11085
11086  functions SDCC will try to reduce internal ram space usage by overlaying
11087  parameters and local variables of a function (if possible).
11088  Parameters and local variables
11089 \begin_inset LatexCommand \index{local variables}
11090
11091 \end_inset 
11092
11093  of a function will be allocated to an overlayable segment if the function
11094  has 
11095 \emph on 
11096 no other function calls and the function is non-reentrant and the memory
11097  model
11098 \begin_inset LatexCommand \index{Memory model}
11099
11100 \end_inset 
11101
11102  is small.
11103
11104 \emph default 
11105  If an explicit storage class
11106 \begin_inset LatexCommand \index{Storage class}
11107
11108 \end_inset 
11109
11110  is specified for a local variable, it will NOT be overlayed.
11111 \layout Standard
11112
11113 Note that the compiler (not the linkage editor) makes the decision for overlayin
11114 g the data items.
11115  Functions that are called from an interrupt service routine
11116 \begin_inset Marginal
11117 collapsed true
11118
11119 \layout Standard
11120
11121
11122 \series bold 
11123 !
11124 \end_inset 
11125
11126  should be preceded by a #pragma\SpecialChar ~
11127 nooverlay
11128 \begin_inset LatexCommand \index{\#pragma nooverlay}
11129
11130 \end_inset 
11131
11132  if they are not reentrant.
11133 \layout Standard
11134
11135 Also note that the compiler does not do any processing of inline assembler
11136  code, so the compiler might incorrectly assign local variables and parameters
11137  of a function into the overlay segment if the inline assembler code calls
11138  other c-functions that might use the overlay.
11139  In that case the #pragma\SpecialChar ~
11140 nooverlay should be used.
11141 \layout Standard
11142
11143 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11144 tion
11145 \begin_inset LatexCommand \index{Multiplication}
11146
11147 \end_inset 
11148
11149  or division
11150 \begin_inset LatexCommand \index{Division}
11151
11152 \end_inset 
11153
11154  will NOT be overlayed since these are implemented using external functions,
11155  e.g.:
11156 \layout Verse
11157
11158
11159 \family typewriter 
11160 #pragma save 
11161 \newline 
11162 #pragma nooverlay
11163 \begin_inset LatexCommand \index{\#pragma nooverlay}
11164
11165 \end_inset 
11166
11167  
11168 \newline 
11169 void set_error(unsigned char errcd) 
11170 \newline 
11171 {
11172 \newline 
11173 \SpecialChar ~
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 P3 = errcd;
11178 \newline 
11179
11180 \newline 
11181 #pragma restore 
11182 \newline 
11183
11184 \newline 
11185 void some_isr () __interrupt
11186 \begin_inset LatexCommand \index{interrupt}
11187
11188 \end_inset 
11189
11190  (2)
11191 \newline 
11192 {
11193 \newline 
11194 \SpecialChar ~
11195 \SpecialChar ~
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 ...
11199 \newline 
11200 \SpecialChar ~
11201 \SpecialChar ~
11202 \SpecialChar ~
11203 \SpecialChar ~
11204 set_error(10);
11205 \newline 
11206 \SpecialChar ~
11207 \SpecialChar ~
11208 \SpecialChar ~
11209 \SpecialChar ~
11210 ...
11211  
11212 \newline 
11213 }
11214 \layout Standard
11215
11216 In the above example the parameter 
11217 \emph on 
11218 errcd
11219 \emph default 
11220  for the function 
11221 \emph on 
11222 set_error
11223 \emph default 
11224  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11225 nooverlay was
11226  not present, this could cause unpredictable runtime behavior when called
11227  from an interrupt service routine.
11228  The #pragma\SpecialChar ~
11229 nooverlay ensures that the parameters and local variables for
11230  the function are NOT overlayed.
11231 \layout Section
11232
11233 Interrupt Service Routines
11234 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11235
11236 \end_inset 
11237
11238
11239 \layout Subsection
11240
11241 General Information
11242 \layout Standard
11243
11244 SDCC allows 
11245 \emph on 
11246 i
11247 \emph default 
11248 nterrupt 
11249 \emph on 
11250 s
11251 \emph default 
11252 ervice 
11253 \emph on 
11254 r
11255 \emph default 
11256 outines to be coded in C, with some extended keywords.
11257 \layout Verse
11258
11259
11260 \family typewriter 
11261 void timer_isr (void) __interrupt (1) __using (1) 
11262 \newline 
11263
11264 \newline 
11265 \SpecialChar ~
11266 \SpecialChar ~
11267 \SpecialChar ~
11268 \SpecialChar ~
11269 ...
11270  
11271 \newline 
11272 }
11273 \layout Standard
11274
11275 The optional number following the 
11276 \emph on 
11277 interrupt
11278 \begin_inset LatexCommand \index{interrupt}
11279
11280 \end_inset 
11281
11282
11283 \begin_inset LatexCommand \index{\_\_interrupt}
11284
11285 \end_inset 
11286
11287
11288 \emph default 
11289  keyword is the interrupt number this routine will service.
11290  When present, the compiler will insert a call to this routine in the interrupt
11291  vector table for the interrupt number specified.
11292  If you have multiple source files in your project, interrupt service routines
11293  can be present in any of them, but a prototype of the isr MUST be present
11294  or included in the file that contains the function 
11295 \emph on 
11296 main
11297 \emph default 
11298 .
11299  The optional 
11300 \emph on 
11301 using
11302 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11303
11304 \end_inset 
11305
11306
11307 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11308
11309 \end_inset 
11310
11311
11312 \emph default 
11313  keyword can be used to tell the compiler to use the specified register
11314  bank (8051 specific) when generating code for this function.
11315  
11316 \newline 
11317
11318 \layout Standard
11319
11320 Interrupt service routines open the door for some very interesting bugs:
11321 \newline 
11322 If an interrupt service routine changes variables which are accessed by
11323  other functions these variables have to be declared 
11324 \emph on 
11325 volatile
11326 \emph default 
11327
11328 \begin_inset LatexCommand \index{volatile}
11329
11330 \end_inset 
11331
11332 .
11333  
11334 \layout Standard
11335
11336 If the access to these variables is not 
11337 \emph on 
11338 atomic
11339 \begin_inset LatexCommand \index{atomic}
11340
11341 \end_inset 
11342
11343
11344 \emph default 
11345  (i.e.
11346  the processor needs more than one instruction for the access and could
11347  be interrupted while accessing the variable) the interrupt must be disabled
11348  during the access to avoid inconsistent data.
11349  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
11350  and should be protected by disabling interrupts.
11351  You're not automatically on the safe side if you use 8 bit variables though.
11352  We need an example here: f.e.
11353  on the 8051 the harmless looking 
11354 \begin_inset Quotes srd
11355 \end_inset 
11356
11357
11358 \family typewriter 
11359 flags\SpecialChar ~
11360 |=\SpecialChar ~
11361 0x80;
11362 \family default 
11363
11364 \begin_inset Quotes sld
11365 \end_inset 
11366
11367  is not atomic if 
11368 \family typewriter 
11369 flags
11370 \family default 
11371  resides in xdata.
11372  Setting 
11373 \begin_inset Quotes srd
11374 \end_inset 
11375
11376
11377 \family typewriter 
11378 flags\SpecialChar ~
11379 |=\SpecialChar ~
11380 0x40;
11381 \family default 
11382
11383 \begin_inset Quotes sld
11384 \end_inset 
11385
11386  from within an interrupt routine might get lost if the interrupt occurs
11387  at the wrong time.
11388  
11389 \begin_inset Quotes sld
11390 \end_inset 
11391
11392
11393 \family typewriter 
11394 counter\SpecialChar ~
11395 +=\SpecialChar ~
11396 8;
11397 \family default 
11398
11399 \begin_inset Quotes srd
11400 \end_inset 
11401
11402  is not atomic on the 8051 even if 
11403 \family typewriter 
11404 counter
11405 \family default 
11406  is located in data memory.
11407  Bugs like these are hard to reproduce and can cause a lot of trouble.
11408  
11409 \layout Standard
11410
11411 The return address and the registers used in the interrupt service routine
11412  are saved on the stack
11413 \begin_inset LatexCommand \index{stack}
11414
11415 \end_inset 
11416
11417  so there must be sufficient stack space.
11418  If there isn't variables or registers (or even the return address itself)
11419  will be corrupted.
11420  This 
11421 \emph on 
11422 stack overflow
11423 \emph default 
11424
11425 \begin_inset LatexCommand \index{stack overflow}
11426
11427 \end_inset 
11428
11429  is most likely to happen if the interrupt occurs during the 
11430 \begin_inset Quotes sld
11431 \end_inset 
11432
11433 deepest
11434 \begin_inset Quotes srd
11435 \end_inset 
11436
11437  subroutine when the stack is already in use for f.e.
11438  many return addresses.
11439 \layout Standard
11440
11441 A special note here, int (16 bit) and long (32 bit) integer division
11442 \begin_inset LatexCommand \index{Division}
11443
11444 \end_inset 
11445
11446 , multiplication
11447 \begin_inset LatexCommand \index{Multiplication}
11448
11449 \end_inset 
11450
11451  & modulus
11452 \begin_inset LatexCommand \index{Modulus}
11453
11454 \end_inset 
11455
11456  and floating-point
11457 \begin_inset LatexCommand \index{Floating point support}
11458
11459 \end_inset 
11460
11461  operations are implemented using external support routines developed in
11462  ANSI-C.
11463  If an interrupt service routine needs to do any of these operations then
11464  the support routines (as mentioned in a following section) will have to
11465  be recompiled using the
11466 \emph on 
11467  -
11468 \begin_inset ERT
11469 status Collapsed
11470
11471 \layout Standard
11472
11473 \backslash 
11474 /
11475 \end_inset 
11476
11477 -stack-auto
11478 \begin_inset LatexCommand \index{-\/-stack-auto}
11479
11480 \end_inset 
11481
11482
11483 \emph default 
11484  option and the source file will need to be compiled using the 
11485 \emph on 
11486 -
11487 \begin_inset ERT
11488 status Collapsed
11489
11490 \layout Standard
11491
11492 \backslash 
11493 /
11494 \end_inset 
11495
11496 -int-long-reent
11497 \emph default 
11498
11499 \begin_inset LatexCommand \index{-\/-int-long-reent}
11500
11501 \end_inset 
11502
11503  compiler option.
11504  Note, the type promotion
11505 \begin_inset LatexCommand \index{type promotion}
11506
11507 \end_inset 
11508
11509  required by ANSI C can cause 16 bit routines to be used without the programmer
11510  being aware of it.
11511  
11512 \layout Standard
11513
11514 Calling other functions from an interrupt service routine is not recommended,
11515  avoid it if possible.
11516  Note that when some function is called from an interrupt service routine
11517  it should be preceded by a #pragma\SpecialChar ~
11518 nooverlay
11519 \begin_inset LatexCommand \index{\#pragma nooverlay}
11520
11521 \end_inset 
11522
11523  if it is not reentrant.
11524  Furthermore nonreentrant functions should not be called from the main program
11525  while the interrupt service routine might be active.
11526  They also must not be called from low priority interrupt service routines
11527  while a high priority interrupt service routine might be active.
11528  You could use semaphores or make the function
11529 \emph on 
11530  critical
11531 \emph default 
11532  if all parameters are passed in registers.
11533 \newline 
11534
11535 \newline 
11536 Also see section 
11537 \begin_inset LatexCommand \ref{sub:Overlaying}
11538
11539 \end_inset 
11540
11541 \SpecialChar ~
11542 about Overlaying and section 
11543 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11544
11545 \end_inset 
11546
11547 \SpecialChar ~
11548 about Functions using private register banks.
11549 \layout Subsection
11550
11551 MCS51/DS390 Interrupt Service Routines
11552 \layout Standard
11553
11554 Interrupt numbers and the corresponding address & descriptions for the Standard
11555  8051/8052 are listed below.
11556  SDCC will automatically adjust the interrupt vector table to the maximum
11557  interrupt number specified.
11558 \newline 
11559
11560 \layout Standard
11561 \align center 
11562
11563 \begin_inset  Tabular
11564 <lyxtabular version="3" rows="9" columns="3">
11565 <features>
11566 <column alignment="center" valignment="top" leftline="true" width="0in">
11567 <column alignment="left" valignment="top" leftline="true" width="0in">
11568 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
11569 <row topline="true" bottomline="true">
11570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11571 \begin_inset Text
11572
11573 \layout Standard
11574
11575 Interrupt #
11576 \end_inset 
11577 </cell>
11578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11579 \begin_inset Text
11580
11581 \layout Standard
11582
11583 Description
11584 \end_inset 
11585 </cell>
11586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11587 \begin_inset Text
11588
11589 \layout Standard
11590
11591 Vector Address
11592 \end_inset 
11593 </cell>
11594 </row>
11595 <row topline="true">
11596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11597 \begin_inset Text
11598
11599 \layout Standard
11600
11601 0
11602 \end_inset 
11603 </cell>
11604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11605 \begin_inset Text
11606
11607 \layout Standard
11608
11609 External 0
11610 \end_inset 
11611 </cell>
11612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11613 \begin_inset Text
11614
11615 \layout Standard
11616
11617 0x0003
11618 \end_inset 
11619 </cell>
11620 </row>
11621 <row topline="true">
11622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11623 \begin_inset Text
11624
11625 \layout Standard
11626
11627 1
11628 \end_inset 
11629 </cell>
11630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11631 \begin_inset Text
11632
11633 \layout Standard
11634
11635 Timer 0
11636 \end_inset 
11637 </cell>
11638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11639 \begin_inset Text
11640
11641 \layout Standard
11642
11643 0x000b
11644 \end_inset 
11645 </cell>
11646 </row>
11647 <row topline="true">
11648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11649 \begin_inset Text
11650
11651 \layout Standard
11652
11653 2
11654 \end_inset 
11655 </cell>
11656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11657 \begin_inset Text
11658
11659 \layout Standard
11660
11661 External 1
11662 \end_inset 
11663 </cell>
11664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11665 \begin_inset Text
11666
11667 \layout Standard
11668
11669 0x0013
11670 \end_inset 
11671 </cell>
11672 </row>
11673 <row topline="true">
11674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11675 \begin_inset Text
11676
11677 \layout Standard
11678
11679 3
11680 \end_inset 
11681 </cell>
11682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11683 \begin_inset Text
11684
11685 \layout Standard
11686
11687 Timer 1
11688 \end_inset 
11689 </cell>
11690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11691 \begin_inset Text
11692
11693 \layout Standard
11694
11695 0x001b
11696 \end_inset 
11697 </cell>
11698 </row>
11699 <row topline="true">
11700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11701 \begin_inset Text
11702
11703 \layout Standard
11704
11705 4
11706 \end_inset 
11707 </cell>
11708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11709 \begin_inset Text
11710
11711 \layout Standard
11712
11713 Serial
11714 \end_inset 
11715 </cell>
11716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11717 \begin_inset Text
11718
11719 \layout Standard
11720
11721 0x0023
11722 \end_inset 
11723 </cell>
11724 </row>
11725 <row topline="true">
11726 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11727 \begin_inset Text
11728
11729 \layout Standard
11730
11731 5
11732 \end_inset 
11733 </cell>
11734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11735 \begin_inset Text
11736
11737 \layout Standard
11738
11739 Timer 2 (8052)
11740 \end_inset 
11741 </cell>
11742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11743 \begin_inset Text
11744
11745 \layout Standard
11746
11747 0x002b
11748 \end_inset 
11749 </cell>
11750 </row>
11751 <row topline="true">
11752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11753 \begin_inset Text
11754
11755 \layout Standard
11756
11757 ...
11758 \end_inset 
11759 </cell>
11760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11761 \begin_inset Text
11762
11763 \layout Standard
11764
11765 \end_inset 
11766 </cell>
11767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11768 \begin_inset Text
11769
11770 \layout Standard
11771
11772 ...
11773 \end_inset 
11774 </cell>
11775 </row>
11776 <row topline="true" bottomline="true">
11777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11778 \begin_inset Text
11779
11780 \layout Standard
11781
11782 n
11783 \end_inset 
11784 </cell>
11785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11786 \begin_inset Text
11787
11788 \layout Standard
11789
11790 \end_inset 
11791 </cell>
11792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11793 \begin_inset Text
11794
11795 \layout Standard
11796
11797 0x0003 + 8*n
11798 \end_inset 
11799 </cell>
11800 </row>
11801 </lyxtabular>
11802
11803 \end_inset 
11804
11805
11806 \newline 
11807
11808 \layout Standard
11809
11810 If the interrupt service routine is defined without 
11811 \emph on 
11812 using
11813 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11814
11815 \end_inset 
11816
11817
11818 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11819
11820 \end_inset 
11821
11822
11823 \emph default 
11824  a register bank or with register bank 0 (
11825 \emph on 
11826 using
11827 \emph default 
11828  0), the compiler will save the registers used by itself on the stack upon
11829  entry and restore them at exit, however if such an interrupt service routine
11830  calls another function then the entire register bank will be saved on the
11831  stack.
11832  This scheme may be advantageous for small interrupt service routines which
11833  have low register usage.
11834 \layout Standard
11835
11836 If the interrupt service routine is defined to be using a specific register
11837  bank then only 
11838 \emph on 
11839 a, b, dptr
11840 \emph default 
11841  & psw are saved and restored, if such an interrupt service routine calls
11842  another function (using another register bank) then the entire register
11843  bank of the called function will be saved on the stack.
11844  This scheme is recommended for larger interrupt service routines.
11845 \layout Subsection
11846
11847 HC08 Interrupt Service Routines
11848 \layout Standard
11849
11850 Since the number of interrupts available is chip specific and the interrupt
11851  vector table always ends at the last byte of memory, the interrupt numbers
11852  corresponds to the interrupt vectors in reverse order of address.
11853  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
11854  2 will use the interrupt vector at 0xfffa, and so on.
11855  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
11856  this way; instead see section 
11857 \begin_inset LatexCommand \ref{sub:Startup-Code}
11858
11859 \end_inset 
11860
11861  for details on customizing startup.
11862 \layout Subsection
11863
11864 Z80 Interrupt Service Routines
11865 \layout Standard
11866
11867 The Z80 uses several different methods for determining the correct interrupt
11868  vector depending on the hardware implementation.
11869  Therefore, SDCC ignores the optional interrupt number and does not attempt
11870  to generate an interrupt vector table.
11871 \layout Standard
11872
11873 By default, SDCC generates code for a maskable interrupt, which uses a RETI
11874  instruction to return from the interrupt.
11875  To write an interrupt handler for the non-maskable interrupt, which needs
11876  a RETN instruction instead, add the 
11877 \emph on 
11878 critical
11879 \emph default 
11880  keyword:
11881 \layout Verse
11882
11883
11884 \family typewriter 
11885 void nmi_isr (void) critical interrupt
11886 \newline 
11887
11888 \newline 
11889 \SpecialChar ~
11890 \SpecialChar ~
11891 \SpecialChar ~
11892 \SpecialChar ~
11893 ...
11894  
11895 \newline 
11896 }
11897 \layout Standard
11898
11899 However if you need to create a non-interruptable interrupt service routine
11900  you would also require the 
11901 \emph on 
11902 critical
11903 \emph default 
11904  keyword.
11905  To distinguish between this and an nmi_isr you must provide an interrupt
11906  number.
11907 \layout Section
11908
11909 Enabling and Disabling Interrupts
11910 \layout Subsection
11911
11912 Critical Functions and Critical Statements
11913 \layout Standard
11914
11915 A special keyword may be associated with a block or a function declaring
11916  it as 
11917 \emph on 
11918 critical
11919 \emph default 
11920 .
11921  SDCC will generate code to disable all interrupts
11922 \begin_inset LatexCommand \index{interrupt}
11923
11924 \end_inset 
11925
11926  upon entry to a critical function and restore the interrupt enable to the
11927  previous state before returning.
11928  Nesting critical functions will need one additional byte on the stack
11929 \begin_inset LatexCommand \index{stack}
11930
11931 \end_inset 
11932
11933  for each call.
11934 \layout Verse
11935
11936
11937 \family typewriter 
11938 int foo () __critical
11939 \begin_inset LatexCommand \index{critical}
11940
11941 \end_inset 
11942
11943
11944 \begin_inset LatexCommand \index{\_\_critical}
11945
11946 \end_inset 
11947
11948  
11949 \newline 
11950
11951 \newline 
11952 \SpecialChar ~
11953 \SpecialChar ~
11954 \SpecialChar ~
11955 \SpecialChar ~
11956 ...
11957  
11958 \newline 
11959 \SpecialChar ~
11960 \SpecialChar ~
11961 \SpecialChar ~
11962 \SpecialChar ~
11963 ...
11964  
11965 \newline 
11966 }
11967 \layout Standard
11968
11969 The critical attribute maybe used with other attributes like 
11970 \emph on 
11971 reentrant.
11972 \emph default 
11973
11974 \newline 
11975 The keyword 
11976 \emph on 
11977 critical
11978 \emph default 
11979  may also be used to disable interrupts more locally:
11980 \layout Verse
11981
11982
11983 \family typewriter 
11984 __critical{ i++; }
11985 \layout Standard
11986
11987 More than one statement could have been included in the block.
11988 \layout Subsection
11989
11990 Enabling and Disabling Interrupts directly
11991 \layout Standard
11992
11993 Interrupts
11994 \begin_inset LatexCommand \index{interrupt}
11995
11996 \end_inset 
11997
11998  can also be disabled and enabled directly (8051):
11999 \layout Verse
12000
12001
12002 \family typewriter 
12003 EA = 0;\SpecialChar ~
12004 \SpecialChar ~
12005 \SpecialChar ~
12006 \SpecialChar ~
12007 \SpecialChar ~
12008 \SpecialChar ~
12009 \SpecialChar ~
12010 \SpecialChar ~
12011 \SpecialChar ~
12012 \SpecialChar ~
12013 \SpecialChar ~
12014 \SpecialChar ~
12015 or:\SpecialChar ~
12016 \SpecialChar ~
12017 \SpecialChar ~
12018 \SpecialChar ~
12019 \SpecialChar ~
12020 \SpecialChar ~
12021 \SpecialChar ~
12022 \SpecialChar ~
12023 \SpecialChar ~
12024 \SpecialChar ~
12025 \SpecialChar ~
12026 EA_SAVE = EA;
12027 \layout Verse
12028
12029
12030 \family typewriter 
12031 ...\SpecialChar ~
12032 \SpecialChar ~
12033 \SpecialChar ~
12034 \SpecialChar ~
12035 \SpecialChar ~
12036 \SpecialChar ~
12037 \SpecialChar ~
12038 \SpecialChar ~
12039 \SpecialChar ~
12040 \SpecialChar ~
12041 \SpecialChar ~
12042 \SpecialChar ~
12043 \SpecialChar ~
12044 \SpecialChar ~
12045 \SpecialChar ~
12046 \SpecialChar ~
12047 \SpecialChar ~
12048 \SpecialChar ~
12049 \SpecialChar ~
12050 \SpecialChar ~
12051 \SpecialChar ~
12052 \SpecialChar ~
12053 \SpecialChar ~
12054 \SpecialChar ~
12055 \SpecialChar ~
12056 \SpecialChar ~
12057 \SpecialChar ~
12058 \SpecialChar ~
12059 \SpecialChar ~
12060 \SpecialChar ~
12061 EA = 0;
12062 \layout Verse
12063
12064
12065 \family typewriter 
12066 EA = 1;\SpecialChar ~
12067 \SpecialChar ~
12068 \SpecialChar ~
12069 \SpecialChar ~
12070 \SpecialChar ~
12071 \SpecialChar ~
12072 \SpecialChar ~
12073 \SpecialChar ~
12074 \SpecialChar ~
12075 \SpecialChar ~
12076 \SpecialChar ~
12077 \SpecialChar ~
12078 \SpecialChar ~
12079 \SpecialChar ~
12080 \SpecialChar ~
12081 \SpecialChar ~
12082 \SpecialChar ~
12083 \SpecialChar ~
12084 \SpecialChar ~
12085 \SpecialChar ~
12086 \SpecialChar ~
12087 \SpecialChar ~
12088 \SpecialChar ~
12089 \SpecialChar ~
12090 \SpecialChar ~
12091 \SpecialChar ~
12092 ...
12093 \layout Verse
12094
12095
12096 \family typewriter 
12097 \SpecialChar ~
12098 \SpecialChar ~
12099 \SpecialChar ~
12100 \SpecialChar ~
12101 \SpecialChar ~
12102 \SpecialChar ~
12103 \SpecialChar ~
12104 \SpecialChar ~
12105 \SpecialChar ~
12106 \SpecialChar ~
12107 \SpecialChar ~
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 \SpecialChar ~
12111 \SpecialChar ~
12112 \SpecialChar ~
12113 \SpecialChar ~
12114 \SpecialChar ~
12115 \SpecialChar ~
12116 \SpecialChar ~
12117 \SpecialChar ~
12118 \SpecialChar ~
12119 \SpecialChar ~
12120 \SpecialChar ~
12121 \SpecialChar ~
12122 \SpecialChar ~
12123 \SpecialChar ~
12124 \SpecialChar ~
12125 \SpecialChar ~
12126 \SpecialChar ~
12127 \SpecialChar ~
12128 \SpecialChar ~
12129 \SpecialChar ~
12130 EA = EA_SAVE;
12131 \layout Standard
12132
12133 On other architectures which have seperate opcodes for enabling and disabling
12134  interrupts you might want to make use of defines with inline assembly
12135 \begin_inset LatexCommand \index{Assembler routines}
12136
12137 \end_inset 
12138
12139  (HC08):
12140 \layout Verse
12141
12142
12143 \family typewriter 
12144 #define CLI _asm
12145 \begin_inset LatexCommand \index{\_asm}
12146
12147 \end_inset 
12148
12149 \SpecialChar ~
12150 \SpecialChar ~
12151 cli\SpecialChar ~
12152 \SpecialChar ~
12153 _endasm
12154 \begin_inset LatexCommand \index{\_endasm}
12155
12156 \end_inset 
12157
12158
12159 \layout Verse
12160
12161
12162 \family typewriter 
12163 #define SEI _asm\SpecialChar ~
12164 \SpecialChar ~
12165 sei\SpecialChar ~
12166 \SpecialChar ~
12167 _endasm; 
12168 \layout Verse
12169
12170
12171 \family typewriter 
12172 ...
12173 \layout Standard
12174
12175 Note: it is sometimes sufficient to disable only a specific interrupt source
12176  like f.e.
12177  a timer or serial interrupt by manipulating an 
12178 \emph on 
12179 interrupt mask
12180 \begin_inset LatexCommand \index{interrupt mask}
12181
12182 \end_inset 
12183
12184
12185 \emph default 
12186  register.
12187  
12188 \layout Standard
12189
12190 Usually the time during which interrupts are disabled should be kept as
12191  short as possible.
12192  This minimizes both 
12193 \emph on 
12194 interrupt latency
12195 \emph default 
12196
12197 \begin_inset LatexCommand \index{interrupt latency}
12198
12199 \end_inset 
12200
12201  (the time between the occurrence of the interrupt and the execution of
12202  the first code in the interrupt routine) and 
12203 \emph on 
12204 interrupt jitter
12205 \emph default 
12206
12207 \begin_inset LatexCommand \index{interrupt jitter}
12208
12209 \end_inset 
12210
12211  (the difference between the shortest and the longest interrupt latency).
12212  These really are something different, f.e.
12213  a serial interrupt has to be served before its buffer overruns so it cares
12214  for the maximum interrupt latency, whereas it does not care about jitter.
12215  On a loudspeaker driven via a digital to analog converter which is fed
12216  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12217  a much smaller jitter will be very audible.
12218 \layout Standard
12219
12220 You can reenable interrupts within an interrupt routine and on some architecture
12221 s you can make use of two (or more) levels of 
12222 \emph on 
12223 interrupt priorities
12224 \emph default 
12225
12226 \begin_inset LatexCommand \index{interrupt priority}
12227
12228 \end_inset 
12229
12230 .
12231  On some architectures which don't support interrupt priorities these can
12232  be implemented by manipulating the interrupt mask and reenabling interrupts
12233  within the interrupt routine.
12234  Check there is sufficient space on the stack
12235 \begin_inset LatexCommand \index{stack}
12236
12237 \end_inset 
12238
12239  and don't add complexity unless you have to.
12240  
12241 \layout Subsection
12242
12243 Semaphore
12244 \begin_inset LatexCommand \index{semaphore}
12245
12246 \end_inset 
12247
12248  locking (mcs51/ds390)
12249 \layout Standard
12250
12251 Some architectures (mcs51/ds390) have an atomic
12252 \begin_inset LatexCommand \index{atomic}
12253
12254 \end_inset 
12255
12256  bit test and
12257 \emph on 
12258  
12259 \emph default 
12260 clear
12261 \emph on 
12262  
12263 \emph default 
12264 instruction.
12265  These type of instructions are typically used in preemptive multitasking
12266  systems, where a routine f.e.
12267  claims the use of a data structure ('acquires a lock
12268 \begin_inset LatexCommand \index{lock}
12269
12270 \end_inset 
12271
12272  on it'), makes some modifications and then releases the lock when the data
12273  structure is consistent again.
12274  The instruction may also be used if interrupt and non-interrupt code have
12275  to compete for a resource.
12276  With the atomic bit test and clear instruction interrupts
12277 \begin_inset LatexCommand \index{interrupt}
12278
12279 \end_inset 
12280
12281  don't have to be disabled for the locking operation.
12282  
12283 \layout Standard
12284
12285 SDCC generates this instruction if the source follows this pattern:
12286 \layout Verse
12287
12288
12289 \family typewriter 
12290 volatile
12291 \begin_inset LatexCommand \index{volatile}
12292
12293 \end_inset 
12294
12295  bit resource_is_free; 
12296 \newline 
12297
12298 \newline 
12299 if (resource_is_free) 
12300 \newline 
12301 \SpecialChar ~
12302 \SpecialChar ~
12303
12304 \newline 
12305 \SpecialChar ~
12306 \SpecialChar ~
12307 \SpecialChar ~
12308 \SpecialChar ~
12309 resource_is_free=0; 
12310 \newline 
12311 \SpecialChar ~
12312 \SpecialChar ~
12313 \SpecialChar ~
12314 \SpecialChar ~
12315 ...
12316  
12317 \newline 
12318 \SpecialChar ~
12319 \SpecialChar ~
12320 \SpecialChar ~
12321 \SpecialChar ~
12322 resource_is_free=1;
12323 \newline 
12324 \SpecialChar ~
12325 \SpecialChar ~
12326
12327 \layout Standard
12328
12329 Note, mcs51 and ds390 support only an atomic
12330 \begin_inset LatexCommand \index{atomic}
12331
12332 \end_inset 
12333
12334  bit test and 
12335 \emph on 
12336 clear
12337 \emph default 
12338  instruction (as opposed to atomic bit test and 
12339 \emph on 
12340 set).
12341 \layout Section
12342
12343 Functions using private register banks
12344 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12345
12346 \end_inset 
12347
12348  (mcs51/ds390)
12349 \layout Standard
12350
12351 Some architectures have support for quickly changing register sets.
12352  SDCC supports this feature with the 
12353 \emph on 
12354 using
12355 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12356
12357 \end_inset 
12358
12359
12360 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12361
12362 \end_inset 
12363
12364
12365 \emph default 
12366  attribute (which tells the compiler to use a register bank
12367 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12368
12369 \end_inset 
12370
12371  other than the default bank zero).
12372  It should only be applied to 
12373 \emph on 
12374 interrupt
12375 \begin_inset LatexCommand \index{interrupt}
12376
12377 \end_inset 
12378
12379
12380 \emph default 
12381  functions (see footnote below).
12382  This will in most circumstances make the generated ISR code more efficient
12383  since it will not have to save registers on the stack.
12384 \layout Standard
12385
12386 The 
12387 \emph on 
12388 using
12389 \emph default 
12390  attribute will have no effect on the generated code for a 
12391 \emph on 
12392 non-interrupt
12393 \emph default 
12394  function (but may occasionally be useful anyway
12395 \begin_inset Foot
12396 collapsed false
12397
12398 \layout Standard
12399
12400 possible exception: if a function is called ONLY from 'interrupt' functions
12401  using a particular bank, it can be declared with the same 'using' attribute
12402  as the calling 'interrupt' functions.
12403  For instance, if you have several ISRs using bank one, and all of them
12404  call memcpy(), it might make sense to create a specialized version of memcpy()
12405  'using 1', since this would prevent the ISR from having to save bank zero
12406  to the stack on entry and switch to bank zero before calling the function
12407 \end_inset 
12408
12409 ).
12410 \newline 
12411
12412 \emph on 
12413 (pending: I don't think this has been done yet)
12414 \layout Standard
12415
12416 An 
12417 \emph on 
12418 interrupt
12419 \emph default 
12420  function using a non-zero bank will assume that it can trash that register
12421  bank, and will not save it.
12422  Since high-priority interrupts
12423 \begin_inset LatexCommand \index{interrupts}
12424
12425 \end_inset 
12426
12427
12428 \begin_inset LatexCommand \index{interrupt priority}
12429
12430 \end_inset 
12431
12432  can interrupt low-priority ones on the 8051 and friends, this means that
12433  if a high-priority ISR 
12434 \emph on 
12435 using
12436 \emph default 
12437  a particular bank occurs while processing a low-priority ISR 
12438 \emph on 
12439 using
12440 \emph default 
12441  the same bank, terrible and bad things can happen.
12442  To prevent this, no single register bank should be 
12443 \emph on 
12444 used
12445 \emph default 
12446  by both a high priority and a low priority ISR.
12447  This is probably most easily done by having all high priority ISRs use
12448  one bank and all low priority ISRs use another.
12449  If you have an ISR which can change priority at runtime, you're on your
12450  own: I suggest using the default bank zero and taking the small performance
12451  hit.
12452 \layout Standard
12453
12454 It is most efficient if your ISR calls no other functions.
12455  If your ISR must call other functions, it is most efficient if those functions
12456  use the same bank as the ISR (see note 1 below); the next best is if the
12457  called functions use bank zero.
12458  It is very inefficient to call a function using a different, non-zero bank
12459  from an ISR.
12460  
12461 \layout Section
12462
12463 Startup Code
12464 \begin_inset LatexCommand \label{sub:Startup-Code}
12465
12466 \end_inset 
12467
12468
12469 \begin_inset LatexCommand \index{Startup code}
12470
12471 \end_inset 
12472
12473
12474 \layout Subsection
12475
12476 MCS51/DS390 Startup Code
12477 \layout Standard
12478
12479 The compiler inserts a call to the C routine 
12480 \emph on 
12481 _sdcc_external_startup()
12482 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12483
12484 \end_inset 
12485
12486
12487 \series bold 
12488 \emph default 
12489  
12490 \series default 
12491 at the start of the CODE area.
12492  This routine is in the runtime library
12493 \begin_inset LatexCommand \index{Runtime library}
12494
12495 \end_inset 
12496
12497 .
12498  By default this routine returns 0, if this routine returns a non-zero value,
12499  the static & global variable initialization will be skipped and the function
12500  main will be invoked.
12501  Otherwise static & global variables will be initialized before the function
12502  main is invoked.
12503  You could add a 
12504 \emph on 
12505 _sdcc_external_startup()
12506 \emph default 
12507  routine to your program to override the default if you need to setup hardware
12508  or perform some other critical operation prior to static & global variable
12509  initialization
12510 \begin_inset LatexCommand \index{Variable initialization}
12511
12512 \end_inset 
12513
12514 .
12515  On some mcs51 variants xdata
12516 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12517
12518 \end_inset 
12519
12520  memory has to be explicitly enabled before it can be accessed or if the
12521  watchdog needs to be disabled, this is the place to do it.
12522  The startup code clears all internal data memory, 256 bytes by default,
12523  but from 0 to n-1 if 
12524 \emph on 
12525 -
12526 \begin_inset ERT
12527 status Collapsed
12528
12529 \layout Standard
12530
12531 \backslash 
12532 /
12533 \end_inset 
12534
12535 -iram-size
12536 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12537
12538 \end_inset 
12539
12540 n
12541 \emph default 
12542  is used.
12543  (recommended for Chipcon CC1010).
12544 \layout Standard
12545
12546 See also the compiler option 
12547 \emph on 
12548 -
12549 \begin_inset ERT
12550 status Collapsed
12551
12552 \layout Standard
12553
12554 \backslash 
12555 /
12556 \end_inset 
12557
12558 -no-xinit
12559 \emph default 
12560 -
12561 \emph on 
12562 opt
12563 \emph default 
12564
12565 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
12566
12567 \end_inset 
12568
12569  and section 
12570 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12571
12572 \end_inset 
12573
12574 \SpecialChar ~
12575 about MCS51-variants.
12576 \layout Subsection
12577
12578 HC08 Startup Code
12579 \layout Standard
12580
12581 The HC08 startup code follows the same scheme as the MCS51 startup code.
12582 \layout Subsection
12583
12584 Z80 Startup Code
12585 \layout Standard
12586
12587 On the Z80 the startup code is inserted by linking with crt0.o which is generated
12588  from sdcc/device/lib/z80/crt0.s.
12589  If you need a different startup code you can use the compiler option 
12590 \emph on 
12591 -
12592 \series bold 
12593 \emph default 
12594
12595 \begin_inset ERT
12596 status Collapsed
12597
12598 \layout Standard
12599
12600 \backslash 
12601 /
12602 \end_inset 
12603
12604
12605 \series default 
12606 \emph on 
12607 -no-std-crt0
12608 \emph default 
12609
12610 \begin_inset LatexCommand \index{-\/-no-std-crt0}
12611
12612 \end_inset 
12613
12614  and provide your own crt0.o.
12615  
12616 \layout Section
12617
12618 Inline Assembler Code
12619 \begin_inset LatexCommand \index{Assembler routines}
12620
12621 \end_inset 
12622
12623
12624 \layout Subsection
12625
12626 A Step by Step Introduction
12627 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
12628
12629 \end_inset 
12630
12631
12632 \layout Standard
12633
12634 Starting from a small snippet of c-code this example shows for the MCS51
12635  how to use inline assembly, access variables, a function parameter and
12636  an array in xdata memory.
12637  The example uses an MCS51 here but is easily adapted for other architectures.
12638  This is a buffer routine which should be optimized:
12639 \layout Verse
12640
12641
12642 \family typewriter 
12643 \size footnotesize 
12644 unsigned char __far
12645 \begin_inset LatexCommand \index{far (storage class)}
12646
12647 \end_inset 
12648
12649
12650 \begin_inset LatexCommand \index{\_\_far (storage class)}
12651
12652 \end_inset 
12653
12654  __at
12655 \begin_inset LatexCommand \index{at}
12656
12657 \end_inset 
12658
12659
12660 \begin_inset LatexCommand \index{\_\_at}
12661
12662 \end_inset 
12663
12664 (0x7f00) buf[0x100];
12665 \begin_inset LatexCommand \index{Aligned array}
12666
12667 \end_inset 
12668
12669
12670 \newline 
12671 unsigned char head, tail;
12672 \newline 
12673
12674 \newline 
12675 void to_buffer( unsigned char c ) 
12676 \newline 
12677 {
12678 \newline 
12679 \SpecialChar ~
12680 \SpecialChar ~
12681 \SpecialChar ~
12682 \SpecialChar ~
12683 if( head != (unsigned char)(tail-1) )\SpecialChar ~
12684 /* cast 
12685 \series bold 
12686 needed
12687 \series default 
12688  to avoid promotion
12689 \begin_inset LatexCommand \index{promotion to signed int}
12690
12691 \end_inset 
12692
12693
12694 \begin_inset LatexCommand \index{type promotion}
12695
12696 \end_inset 
12697
12698  to integer */
12699 \begin_inset Marginal
12700 collapsed false
12701
12702 \layout Standard
12703
12704
12705 \series bold 
12706 \SpecialChar ~
12707 !
12708 \end_inset 
12709
12710
12711 \newline 
12712 \SpecialChar ~
12713 \SpecialChar ~
12714 \SpecialChar ~
12715 \SpecialChar ~
12716 \SpecialChar ~
12717 \SpecialChar ~
12718 \SpecialChar ~
12719 \SpecialChar ~
12720 buf[ head++ ] = c;\SpecialChar ~
12721 \SpecialChar ~
12722 \SpecialChar ~
12723 \SpecialChar ~
12724 \SpecialChar ~
12725 \SpecialChar ~
12726 \SpecialChar ~
12727 \SpecialChar ~
12728 \SpecialChar ~
12729 \SpecialChar ~
12730 \SpecialChar ~
12731 \SpecialChar ~
12732 \SpecialChar ~
12733 \SpecialChar ~
12734 \SpecialChar ~
12735 \SpecialChar ~
12736 /* access to a 256 byte aligned array */
12737 \newline 
12738
12739 \layout Standard
12740
12741 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
12742  then a corresponding buffer.asm file is generated.
12743  We define a new function 
12744 \family typewriter 
12745 to_buffer_asm()
12746 \family default 
12747  in file buffer.c in which we cut and paste the generated code, removing
12748  unwanted comments and some ':'.
12749  Then add 
12750 \begin_inset Quotes sld
12751 \end_inset 
12752
12753 _asm
12754 \begin_inset Quotes srd
12755 \end_inset 
12756
12757  and 
12758 \begin_inset Quotes sld
12759 \end_inset 
12760
12761 _endasm;
12762 \begin_inset Quotes srd
12763 \end_inset 
12764
12765  to the beginning and the end of the function body:
12766 \layout Verse
12767
12768
12769 \family typewriter 
12770 \size footnotesize 
12771 /* With a cut and paste from the .asm file, we have something to start with.
12772 \newline 
12773 \SpecialChar ~
12774 \SpecialChar ~
12775 \SpecialChar ~
12776 The function is not yet OK! (registers aren't saved) */ 
12777 \newline 
12778 void to_buffer_asm( unsigned char c ) 
12779 \newline 
12780
12781 \newline 
12782 \SpecialChar ~
12783 \SpecialChar ~
12784 \SpecialChar ~
12785 \SpecialChar ~
12786 _asm
12787 \begin_inset LatexCommand \index{\_asm}
12788
12789 \end_inset 
12790
12791
12792 \begin_inset LatexCommand \index{\_\_asm}
12793
12794 \end_inset 
12795
12796
12797 \newline 
12798 \SpecialChar ~
12799 \SpecialChar ~
12800 \SpecialChar ~
12801 \SpecialChar ~
12802 mov\SpecialChar ~
12803 \SpecialChar ~
12804 r2,dpl 
12805 \newline 
12806 ;buffer.c if( head != (unsigned char)(tail-1) ) 
12807 \newline 
12808 \SpecialChar ~
12809 \SpecialChar ~
12810 \SpecialChar ~
12811 \SpecialChar ~
12812 mov\SpecialChar ~
12813 \SpecialChar ~
12814 a,_tail 
12815 \newline 
12816 \SpecialChar ~
12817 \SpecialChar ~
12818 \SpecialChar ~
12819 \SpecialChar ~
12820 dec\SpecialChar ~
12821 \SpecialChar ~
12822
12823 \newline 
12824 \SpecialChar ~
12825 \SpecialChar ~
12826 \SpecialChar ~
12827 \SpecialChar ~
12828 mov\SpecialChar ~
12829 \SpecialChar ~
12830 r3,a 
12831 \newline 
12832 \SpecialChar ~
12833 \SpecialChar ~
12834 \SpecialChar ~
12835 \SpecialChar ~
12836 mov\SpecialChar ~
12837 \SpecialChar ~
12838 a,_head 
12839 \newline 
12840 \SpecialChar ~
12841 \SpecialChar ~
12842 \SpecialChar ~
12843 \SpecialChar ~
12844 cjne a,ar3,00106$ 
12845 \newline 
12846 \SpecialChar ~
12847 \SpecialChar ~
12848 \SpecialChar ~
12849 \SpecialChar ~
12850 ret
12851 \newline 
12852 00106$: 
12853 \newline 
12854 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
12855 \begin_inset LatexCommand \index{Aligned array}
12856
12857 \end_inset 
12858
12859
12860 \newline 
12861 \SpecialChar ~
12862 \SpecialChar ~
12863 \SpecialChar ~
12864 \SpecialChar ~
12865 mov\SpecialChar ~
12866 \SpecialChar ~
12867 r3,_head 
12868 \newline 
12869 \SpecialChar ~
12870 \SpecialChar ~
12871 \SpecialChar ~
12872 \SpecialChar ~
12873 inc\SpecialChar ~
12874 \SpecialChar ~
12875 _head 
12876 \newline 
12877 \SpecialChar ~
12878 \SpecialChar ~
12879 \SpecialChar ~
12880 \SpecialChar ~
12881 mov\SpecialChar ~
12882 \SpecialChar ~
12883 dpl,r3 
12884 \newline 
12885 \SpecialChar ~
12886 \SpecialChar ~
12887 \SpecialChar ~
12888 \SpecialChar ~
12889 mov\SpecialChar ~
12890 \SpecialChar ~
12891 dph,#(_buf >> 8) 
12892 \newline 
12893 \SpecialChar ~
12894 \SpecialChar ~
12895 \SpecialChar ~
12896 \SpecialChar ~
12897 mov\SpecialChar ~
12898 \SpecialChar ~
12899 a,r2 
12900 \newline 
12901 \SpecialChar ~
12902 \SpecialChar ~
12903 \SpecialChar ~
12904 \SpecialChar ~
12905 movx @dptr,a 
12906 \newline 
12907 00103$: 
12908 \newline 
12909 \SpecialChar ~
12910 \SpecialChar ~
12911 \SpecialChar ~
12912 \SpecialChar ~
12913 ret
12914 \newline 
12915 \SpecialChar ~
12916 \SpecialChar ~
12917 \SpecialChar ~
12918 \SpecialChar ~
12919 _endasm
12920 \begin_inset LatexCommand \index{\_endasm}
12921
12922 \end_inset 
12923
12924
12925 \begin_inset LatexCommand \index{\_\_endasm}
12926
12927 \end_inset 
12928
12929 ;
12930 \newline 
12931
12932 \layout Standard
12933
12934 The new file buffer.c should compile with only one warning about the unreferenced
12935  function argument 'c'.
12936  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
12937  (1) and finally have:
12938 \layout Verse
12939
12940
12941 \family typewriter 
12942 \size footnotesize 
12943 unsigned char __far __at(0x7f00) buf[0x100];
12944 \newline 
12945 unsigned char head, tail;
12946 \newline 
12947 #define USE_ASSEMBLY (1)
12948 \newline 
12949
12950 \newline 
12951 #if !USE_ASSEMBLY
12952 \newline 
12953
12954 \newline 
12955 void to_buffer( unsigned char c )
12956 \newline 
12957 {
12958 \newline 
12959 \SpecialChar ~
12960 \SpecialChar ~
12961 \SpecialChar ~
12962 \SpecialChar ~
12963 if( head != (unsigned char)(tail-1) )
12964 \newline 
12965 \SpecialChar ~
12966 \SpecialChar ~
12967 \SpecialChar ~
12968 \SpecialChar ~
12969 \SpecialChar ~
12970 \SpecialChar ~
12971 \SpecialChar ~
12972 \SpecialChar ~
12973 buf[ head++ ] = c;
12974 \newline 
12975 }
12976 \newline 
12977
12978 \newline 
12979 #else
12980 \newline 
12981
12982 \newline 
12983 void to_buffer( unsigned char c )
12984 \newline 
12985 {
12986 \newline 
12987 \SpecialChar ~
12988 \SpecialChar ~
12989 \SpecialChar ~
12990 \SpecialChar ~
12991 c; // to avoid warning: unreferenced function argument
12992 \newline 
12993 \SpecialChar ~
12994 \SpecialChar ~
12995 \SpecialChar ~
12996 \SpecialChar ~
12997 _asm
12998 \begin_inset LatexCommand \index{\_asm}
12999
13000 \end_inset 
13001
13002
13003 \begin_inset LatexCommand \index{\_\_asm}
13004
13005 \end_inset 
13006
13007
13008 \newline 
13009 \SpecialChar ~
13010 \SpecialChar ~
13011 \SpecialChar ~
13012 \SpecialChar ~
13013 \SpecialChar ~
13014 \SpecialChar ~
13015 \SpecialChar ~
13016 \SpecialChar ~
13017 ; save used registers here.
13018  
13019 \newline 
13020 \SpecialChar ~
13021 \SpecialChar ~
13022 \SpecialChar ~
13023 \SpecialChar ~
13024 \SpecialChar ~
13025 \SpecialChar ~
13026 \SpecialChar ~
13027 \SpecialChar ~
13028 ; If we were still using r2,r3 we would have to push them here.
13029  
13030 \newline 
13031 ; if( head != (unsigned char)(tail-1) )
13032 \newline 
13033 \SpecialChar ~
13034 \SpecialChar ~
13035 \SpecialChar ~
13036 \SpecialChar ~
13037 \SpecialChar ~
13038 \SpecialChar ~
13039 \SpecialChar ~
13040 \SpecialChar ~
13041 mov\SpecialChar ~
13042  a,_tail
13043 \newline 
13044 \SpecialChar ~
13045 \SpecialChar ~
13046 \SpecialChar ~
13047 \SpecialChar ~
13048 \SpecialChar ~
13049 \SpecialChar ~
13050 \SpecialChar ~
13051 \SpecialChar ~
13052 dec\SpecialChar ~
13053  a
13054 \newline 
13055 \SpecialChar ~
13056 \SpecialChar ~
13057 \SpecialChar ~
13058 \SpecialChar ~
13059 \SpecialChar ~
13060 \SpecialChar ~
13061 \SpecialChar ~
13062 \SpecialChar ~
13063 xrl\SpecialChar ~
13064  a,_head
13065 \newline 
13066 \SpecialChar ~
13067 \SpecialChar ~
13068 \SpecialChar ~
13069 \SpecialChar ~
13070 \SpecialChar ~
13071 \SpecialChar ~
13072 \SpecialChar ~
13073 \SpecialChar ~
13074 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13075 \newline 
13076 \SpecialChar ~
13077 \SpecialChar ~
13078 \SpecialChar ~
13079 \SpecialChar ~
13080 \SpecialChar ~
13081 \SpecialChar ~
13082 \SpecialChar ~
13083 \SpecialChar ~
13084 jz\SpecialChar ~
13085 \SpecialChar ~
13086  t_b_end$
13087 \newline 
13088 \SpecialChar ~
13089 \SpecialChar ~
13090 \SpecialChar ~
13091 \SpecialChar ~
13092 \SpecialChar ~
13093 \SpecialChar ~
13094 \SpecialChar ~
13095 \SpecialChar ~
13096 ;
13097 \newline 
13098 ; buf[ head++ ] = c;
13099 \newline 
13100 \SpecialChar ~
13101 \SpecialChar ~
13102 \SpecialChar ~
13103 \SpecialChar ~
13104 \SpecialChar ~
13105 \SpecialChar ~
13106 \SpecialChar ~
13107 \SpecialChar ~
13108 mov\SpecialChar ~
13109  a,dpl \SpecialChar ~
13110 \SpecialChar ~
13111 \SpecialChar ~
13112 \SpecialChar ~
13113 \SpecialChar ~
13114 \SpecialChar ~
13115 \SpecialChar ~
13116 ; dpl holds lower byte of function argument
13117 \newline 
13118 \SpecialChar ~
13119 \SpecialChar ~
13120 \SpecialChar ~
13121 \SpecialChar ~
13122 \SpecialChar ~
13123 \SpecialChar ~
13124 \SpecialChar ~
13125 \SpecialChar ~
13126 mov\SpecialChar ~
13127  dpl,_head \SpecialChar ~
13128 \SpecialChar ~
13129 \SpecialChar ~
13130 ; buf is 0x100 byte aligned so head can be used directly
13131 \newline 
13132 \SpecialChar ~
13133 \SpecialChar ~
13134 \SpecialChar ~
13135 \SpecialChar ~
13136 \SpecialChar ~
13137 \SpecialChar ~
13138 \SpecialChar ~
13139 \SpecialChar ~
13140 mov\SpecialChar ~
13141  dph,#(_buf>>8)
13142 \newline 
13143 \SpecialChar ~
13144 \SpecialChar ~
13145 \SpecialChar ~
13146 \SpecialChar ~
13147 \SpecialChar ~
13148 \SpecialChar ~
13149 \SpecialChar ~
13150 \SpecialChar ~
13151 movx @dptr,a
13152 \newline 
13153 \SpecialChar ~
13154 \SpecialChar ~
13155 \SpecialChar ~
13156 \SpecialChar ~
13157 \SpecialChar ~
13158 \SpecialChar ~
13159 \SpecialChar ~
13160 \SpecialChar ~
13161 inc \SpecialChar ~
13162 _head
13163 \newline 
13164 \SpecialChar ~
13165 \SpecialChar ~
13166 \SpecialChar ~
13167 \SpecialChar ~
13168 \SpecialChar ~
13169 \SpecialChar ~
13170 \SpecialChar ~
13171 \SpecialChar ~
13172 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13173 \newline 
13174 t_b_end$:
13175 \newline 
13176 \SpecialChar ~
13177 \SpecialChar ~
13178 \SpecialChar ~
13179 \SpecialChar ~
13180 \SpecialChar ~
13181 \SpecialChar ~
13182 \SpecialChar ~
13183 \SpecialChar ~
13184 ; restore used registers here 
13185 \newline 
13186 \SpecialChar ~
13187 \SpecialChar ~
13188 \SpecialChar ~
13189 \SpecialChar ~
13190 _endasm
13191 \begin_inset LatexCommand \index{\_endasm}
13192
13193 \end_inset 
13194
13195
13196 \begin_inset LatexCommand \index{\_\_endasm}
13197
13198 \end_inset 
13199
13200 ;
13201 \newline 
13202 }
13203 \newline 
13204 #endif
13205 \layout Standard
13206
13207 The inline assembler code can contain any valid code understood by the assembler
13208 , this includes any assembler directives and comment lines
13209 \begin_inset Foot
13210 collapsed false
13211
13212 \layout Standard
13213
13214 The assembler does not like some characters like ':' or ''' in comments.
13215  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13216 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13217
13218 \end_inset 
13219
13220
13221 \begin_inset LatexCommand \index{Assembler documentation}
13222
13223 \end_inset 
13224
13225
13226 \end_inset 
13227
13228 .
13229  The compiler does not do any validation of the code within the 
13230 \family typewriter 
13231 _asm
13232 \begin_inset LatexCommand \index{\_asm}
13233
13234 \end_inset 
13235
13236
13237 \begin_inset LatexCommand \index{\_\_asm}
13238
13239 \end_inset 
13240
13241  ...
13242  _endasm
13243 \size footnotesize 
13244
13245 \begin_inset LatexCommand \index{\_endasm}
13246
13247 \end_inset 
13248
13249
13250 \begin_inset LatexCommand \index{\_\_endasm}
13251
13252 \end_inset 
13253
13254
13255 \size default 
13256 ;
13257 \family default 
13258  keyword pair.
13259  Specifically it will not know which registers are used and thus register
13260  pushing/popping
13261 \begin_inset LatexCommand \index{push/pop}
13262
13263 \end_inset 
13264
13265  has to be done manually.
13266  
13267 \layout Standard
13268
13269 It is recommended that each assembly instruction (including labels) be placed
13270  in a separate line (as the example shows).
13271  When the -
13272 \begin_inset ERT
13273 status Collapsed
13274
13275 \layout Standard
13276
13277 \backslash 
13278 /
13279 \end_inset 
13280
13281 -
13282 \emph on 
13283 peep-asm
13284 \begin_inset LatexCommand \index{-\/-peep-asm}
13285
13286 \end_inset 
13287
13288
13289 \emph default 
13290  command line option is used, the inline assembler code will be passed through
13291  the peephole optimizer
13292 \begin_inset LatexCommand \index{Peephole optimizer}
13293
13294 \end_inset 
13295
13296 .
13297  There are only a few (if any) cases where this option makes sense, it might
13298  cause some unexpected changes in the inline assembler code.
13299  Please go through the peephole optimizer rules defined in file 
13300 \emph on 
13301 SDCCpeeph.def
13302 \emph default 
13303  before using this option.
13304 \layout Subsection
13305
13306 Naked Functions
13307 \begin_inset LatexCommand \label{sub:Naked-Functions}
13308
13309 \end_inset 
13310
13311
13312 \begin_inset LatexCommand \index{Naked functions}
13313
13314 \end_inset 
13315
13316
13317 \layout Standard
13318
13319 A special keyword may be associated with a function declaring it as 
13320 \emph on 
13321 _naked
13322 \begin_inset LatexCommand \index{\_naked}
13323
13324 \end_inset 
13325
13326
13327 \begin_inset LatexCommand \index{\_\_naked}
13328
13329 \end_inset 
13330
13331 .
13332  
13333 \emph default 
13334 The 
13335 \emph on 
13336 _naked
13337 \emph default 
13338  function modifier attribute prevents the compiler from generating prologue
13339 \begin_inset LatexCommand \index{function prologue}
13340
13341 \end_inset 
13342
13343  and epilogue
13344 \begin_inset LatexCommand \index{function epilogue}
13345
13346 \end_inset 
13347
13348  code for that function.
13349  This means that the user is entirely responsible for such things as saving
13350  any registers that may need to be preserved, selecting the proper register
13351  bank, generating the 
13352 \emph on 
13353 return
13354 \emph default 
13355  instruction at the end, etc.
13356  Practically, this means that the contents of the function must be written
13357  in inline assembler.
13358  This is particularly useful for interrupt functions, which can have a large
13359  (and often unnecessary) prologue/epilogue.
13360  For example, compare the code generated by these two functions:
13361 \layout Verse
13362
13363
13364 \family typewriter 
13365 volatile
13366 \begin_inset LatexCommand \index{volatile}
13367
13368 \end_inset 
13369
13370  data unsigned char counter;
13371 \newline 
13372
13373 \newline 
13374 void simpleInterrupt(void) __interrupt
13375 \begin_inset LatexCommand \index{interrupt}
13376
13377 \end_inset 
13378
13379
13380 \begin_inset LatexCommand \index{\_\_interrupt}
13381
13382 \end_inset 
13383
13384  (1)
13385 \newline 
13386 {
13387 \newline 
13388 \SpecialChar ~
13389 \SpecialChar ~
13390 \SpecialChar ~
13391 \SpecialChar ~
13392 counter++;
13393 \newline 
13394 }
13395 \newline 
13396
13397 \newline 
13398 void nakedInterrupt(void) __interrupt (2) __naked
13399 \newline 
13400 {
13401 \newline 
13402 \SpecialChar ~
13403 \SpecialChar ~
13404 \SpecialChar ~
13405 \SpecialChar ~
13406 _asm
13407 \begin_inset LatexCommand \index{\_asm}
13408
13409 \end_inset 
13410
13411
13412 \begin_inset LatexCommand \index{\_\_asm}
13413
13414 \end_inset 
13415
13416
13417 \newline 
13418 \SpecialChar ~
13419 \SpecialChar ~
13420 \SpecialChar ~
13421 \SpecialChar ~
13422 \SpecialChar ~
13423 \SpecialChar ~
13424 inc\SpecialChar ~
13425 \SpecialChar ~
13426 \SpecialChar ~
13427 \SpecialChar ~
13428 \SpecialChar ~
13429 _counter ; does not change flags, no need to save psw
13430 \newline 
13431 \SpecialChar ~
13432 \SpecialChar ~
13433 \SpecialChar ~
13434 \SpecialChar ~
13435 \SpecialChar ~
13436 \SpecialChar ~
13437 reti\SpecialChar ~
13438 \SpecialChar ~
13439 \SpecialChar ~
13440 \SpecialChar ~
13441 ; MUST explicitly include ret or reti in _naked function.
13442 \newline 
13443 \SpecialChar ~
13444 \SpecialChar ~
13445 \SpecialChar ~
13446 \SpecialChar ~
13447 _endasm
13448 \begin_inset LatexCommand \index{\_endasm}
13449
13450 \end_inset 
13451
13452
13453 \begin_inset LatexCommand \index{\_\_endasm}
13454
13455 \end_inset 
13456
13457 ;
13458 \newline 
13459 }
13460 \layout Standard
13461
13462 For an 8051 target, the generated simpleInterrupt looks like:
13463 \layout Verse
13464
13465
13466 \family typewriter 
13467 Note, this is an 
13468 \series bold 
13469 outdated
13470 \series default 
13471  example, recent versions of SDCC generate
13472 \newline 
13473 the same code for simpleInterrupt() and nakedInterrupt()!
13474 \newline 
13475
13476 \newline 
13477 _simpleInterrupt:
13478 \newline 
13479 \SpecialChar ~
13480 \SpecialChar ~
13481 \SpecialChar ~
13482 \SpecialChar ~
13483 push\SpecialChar ~
13484 \SpecialChar ~
13485 \SpecialChar ~
13486 \SpecialChar ~
13487 acc
13488 \newline 
13489 \SpecialChar ~
13490 \SpecialChar ~
13491 \SpecialChar ~
13492 \SpecialChar ~
13493 push\SpecialChar ~
13494 \SpecialChar ~
13495 \SpecialChar ~
13496 \SpecialChar ~
13497 b
13498 \newline 
13499 \SpecialChar ~
13500 \SpecialChar ~
13501 \SpecialChar ~
13502 \SpecialChar ~
13503 push\SpecialChar ~
13504 \SpecialChar ~
13505 \SpecialChar ~
13506 \SpecialChar ~
13507 dpl
13508 \newline 
13509 \SpecialChar ~
13510 \SpecialChar ~
13511 \SpecialChar ~
13512 \SpecialChar ~
13513 push\SpecialChar ~
13514 \SpecialChar ~
13515 \SpecialChar ~
13516 \SpecialChar ~
13517 dph
13518 \newline 
13519 \SpecialChar ~
13520 \SpecialChar ~
13521 \SpecialChar ~
13522 \SpecialChar ~
13523 push\SpecialChar ~
13524 \SpecialChar ~
13525 \SpecialChar ~
13526 \SpecialChar ~
13527 psw
13528 \newline 
13529 \SpecialChar ~
13530 \SpecialChar ~
13531 \SpecialChar ~
13532 \SpecialChar ~
13533 mov\SpecialChar ~
13534 \SpecialChar ~
13535 \SpecialChar ~
13536 \SpecialChar ~
13537 \SpecialChar ~
13538 psw,#0x00
13539 \newline 
13540 \SpecialChar ~
13541 \SpecialChar ~
13542 \SpecialChar ~
13543 \SpecialChar ~
13544 inc\SpecialChar ~
13545 \SpecialChar ~
13546 \SpecialChar ~
13547 \SpecialChar ~
13548 \SpecialChar ~
13549 _counter
13550 \newline 
13551 \SpecialChar ~
13552 \SpecialChar ~
13553 \SpecialChar ~
13554 \SpecialChar ~
13555 pop\SpecialChar ~
13556 \SpecialChar ~
13557 \SpecialChar ~
13558 \SpecialChar ~
13559 \SpecialChar ~
13560 psw
13561 \newline 
13562 \SpecialChar ~
13563 \SpecialChar ~
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 pop\SpecialChar ~
13567 \SpecialChar ~
13568 \SpecialChar ~
13569 \SpecialChar ~
13570 \SpecialChar ~
13571 dph
13572 \newline 
13573 \SpecialChar ~
13574 \SpecialChar ~
13575 \SpecialChar ~
13576 \SpecialChar ~
13577 pop\SpecialChar ~
13578 \SpecialChar ~
13579 \SpecialChar ~
13580 \SpecialChar ~
13581 \SpecialChar ~
13582 dpl
13583 \newline 
13584 \SpecialChar ~
13585 \SpecialChar ~
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 pop\SpecialChar ~
13589 \SpecialChar ~
13590 \SpecialChar ~
13591 \SpecialChar ~
13592 \SpecialChar ~
13593 b
13594 \newline 
13595 \SpecialChar ~
13596 \SpecialChar ~
13597 \SpecialChar ~
13598 \SpecialChar ~
13599 pop\SpecialChar ~
13600 \SpecialChar ~
13601 \SpecialChar ~
13602 \SpecialChar ~
13603 \SpecialChar ~
13604 acc
13605 \newline 
13606 \SpecialChar ~
13607 \SpecialChar ~
13608 \SpecialChar ~
13609 \SpecialChar ~
13610 reti
13611 \layout Standard
13612
13613 whereas nakedInterrupt looks like:
13614 \layout Verse
13615
13616
13617 \family typewriter 
13618 _nakedInterrupt:
13619 \newline 
13620 \SpecialChar ~
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 inc\SpecialChar ~
13625 \SpecialChar ~
13626 \SpecialChar ~
13627 \SpecialChar ~
13628 _counter ; does not change flags, no need to save psw
13629 \newline 
13630 \SpecialChar ~
13631 \SpecialChar ~
13632 \SpecialChar ~
13633 \SpecialChar ~
13634 reti\SpecialChar ~
13635 \SpecialChar ~
13636 \SpecialChar ~
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 \SpecialChar ~
13641 \SpecialChar ~
13642 \SpecialChar ~
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 \SpecialChar ~
13646 ; MUST explicitly include ret or reti in _naked function
13647 \layout Standard
13648
13649 The related directive #pragma exclude
13650 \begin_inset LatexCommand \index{\#pragma exclude}
13651
13652 \end_inset 
13653
13654  allows a more fine grained control over pushing & popping
13655 \begin_inset LatexCommand \index{push/pop}
13656
13657 \end_inset 
13658
13659  the registers.
13660 \layout Standard
13661
13662 While there is nothing preventing you from writing C code inside a 
13663 \family typewriter 
13664 _naked
13665 \family default 
13666  function, there are many ways to shoot yourself in the foot doing this,
13667  and it is recommended that you stick to inline assembler.
13668 \layout Subsection
13669
13670 Use of Labels within Inline Assembler
13671 \layout Standard
13672
13673 SDCC allows the use of in-line assembler with a few restrictions regarding
13674  labels.
13675  In older versions of the compiler all labels defined within inline assembler
13676  code 
13677 \emph on 
13678 had to be
13679 \emph default 
13680  of the form 
13681 \emph on 
13682 nnnnn$
13683 \emph default 
13684  where nnnn is a number less than 100 (which implies a limit of utmost 100
13685  inline assembler labels 
13686 \emph on 
13687 per function
13688 \emph default 
13689 \noun on 
13690 )
13691 \noun default 
13692 .
13693  
13694 \layout Verse
13695
13696
13697 \family typewriter 
13698 _asm
13699 \begin_inset LatexCommand \index{\_asm}
13700
13701 \end_inset 
13702
13703
13704 \begin_inset LatexCommand \index{\_\_asm}
13705
13706 \end_inset 
13707
13708  
13709 \newline 
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 \SpecialChar ~
13713 \SpecialChar ~
13714 mov\SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 \SpecialChar ~
13718 \SpecialChar ~
13719 b,#10 
13720 \newline 
13721 00001$: 
13722 \newline 
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 djnz\SpecialChar ~
13728 \SpecialChar ~
13729 \SpecialChar ~
13730 \SpecialChar ~
13731 b,00001$ 
13732 \newline 
13733 _endasm
13734 \begin_inset LatexCommand \index{\_endasm}
13735
13736 \end_inset 
13737
13738
13739 \begin_inset LatexCommand \index{\_\_endasm}
13740
13741 \end_inset 
13742
13743  ;
13744 \layout Standard
13745
13746 Inline assembler code cannot reference any C-Labels, however it can reference
13747  labels
13748 \begin_inset LatexCommand \index{Labels}
13749
13750 \end_inset 
13751
13752  defined by the inline assembler, e.g.:
13753 \layout Verse
13754
13755
13756 \family typewriter 
13757 foo() { 
13758 \newline 
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 \SpecialChar ~
13762 \SpecialChar ~
13763 /* some c code */ 
13764 \newline 
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 \SpecialChar ~
13768 \SpecialChar ~
13769 _asm 
13770 \newline 
13771 \SpecialChar ~
13772 \SpecialChar ~
13773 \SpecialChar ~
13774 \SpecialChar ~
13775 \SpecialChar ~
13776 \SpecialChar ~
13777 ; some assembler code 
13778 \newline 
13779 \SpecialChar ~
13780 \SpecialChar ~
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 ljmp $0003 
13786 \newline 
13787 \SpecialChar ~
13788 \SpecialChar ~
13789 \SpecialChar ~
13790 \SpecialChar ~
13791 _endasm; 
13792 \newline 
13793 \SpecialChar ~
13794 \SpecialChar ~
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 /* some more c code */ 
13798 \newline 
13799 clabel:\SpecialChar ~
13800 \SpecialChar ~
13801 /* inline assembler cannot reference this label */ 
13802 \newline 
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 _asm
13808 \newline 
13809 \SpecialChar ~
13810 \SpecialChar ~
13811 \SpecialChar ~
13812 \SpecialChar ~
13813 $0003: ;label (can be referenced by inline assembler only) 
13814 \newline 
13815 \SpecialChar ~
13816 \SpecialChar ~
13817 \SpecialChar ~
13818 \SpecialChar ~
13819 _endasm
13820 \begin_inset LatexCommand \index{\_endasm}
13821
13822 \end_inset 
13823
13824
13825 \begin_inset LatexCommand \index{\_\_endasm}
13826
13827 \end_inset 
13828
13829  ; 
13830 \newline 
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 \SpecialChar ~
13835 /* some more c code */
13836 \newline 
13837 }
13838 \layout Standard
13839
13840 In other words inline assembly code can access labels defined in inline
13841  assembly within the scope of the function.
13842  The same goes the other way, i.e.
13843  labels defines in inline assembly can not be accessed by C statements.
13844 \layout Section
13845
13846 Interfacing with Assembler Code
13847 \begin_inset LatexCommand \index{Assembler routines}
13848
13849 \end_inset 
13850
13851
13852 \layout Subsection
13853
13854 Global Registers used for Parameter Passing
13855 \begin_inset LatexCommand \index{Parameter passing}
13856
13857 \end_inset 
13858
13859
13860 \layout Standard
13861
13862 The compiler always uses the global registers 
13863 \emph on 
13864 DPL, DPH
13865 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
13866
13867 \end_inset 
13868
13869
13870 \begin_inset LatexCommand \index{DPTR}
13871
13872 \end_inset 
13873
13874 , B
13875 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
13876
13877 \end_inset 
13878
13879  
13880 \emph default 
13881 and
13882 \emph on 
13883  ACC
13884 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
13885
13886 \end_inset 
13887
13888
13889 \emph default 
13890  to pass the first parameter to a routine.
13891  The second parameter onwards is either allocated on the stack (for reentrant
13892  routines or if -
13893 \begin_inset ERT
13894 status Collapsed
13895
13896 \layout Standard
13897
13898 \backslash 
13899 /
13900 \end_inset 
13901
13902 -stack-auto is used) or in data / xdata memory (depending on the memory
13903  model).
13904  
13905 \layout Subsection
13906
13907 Assembler Routine (non-reentrant)
13908 \layout Standard
13909
13910 In the following example
13911 \begin_inset LatexCommand \index{reentrant}
13912
13913 \end_inset 
13914
13915
13916 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
13917
13918 \end_inset 
13919
13920  the function c_func calls an assembler routine asm_func, which takes two
13921  parameters
13922 \begin_inset LatexCommand \index{function parameter}
13923
13924 \end_inset 
13925
13926 .
13927 \layout Verse
13928
13929
13930 \family typewriter 
13931 extern int asm_func(unsigned char, unsigned char);
13932 \newline 
13933
13934 \newline 
13935 int c_func (unsigned char i, unsigned char j)
13936 \newline 
13937 {
13938 \newline 
13939 \SpecialChar ~
13940 \SpecialChar ~
13941 \SpecialChar ~
13942 \SpecialChar ~
13943 return asm_func(i,j);
13944 \newline 
13945 }
13946 \newline 
13947
13948 \newline 
13949 int main()
13950 \newline 
13951 {
13952 \newline 
13953 \SpecialChar ~
13954 \SpecialChar ~
13955 \SpecialChar ~
13956 \SpecialChar ~
13957 return c_func(10,9);
13958 \newline 
13959 }
13960 \layout Standard
13961
13962 The corresponding assembler function is:
13963 \layout Verse
13964
13965
13966 \family typewriter 
13967 .globl _asm_func_PARM_2 
13968 \newline 
13969 \SpecialChar ~
13970 \SpecialChar ~
13971 \SpecialChar ~
13972 \SpecialChar ~
13973 \SpecialChar ~
13974 \SpecialChar ~
13975 \SpecialChar ~
13976 \SpecialChar ~
13977 .globl _asm_func 
13978 \newline 
13979 \SpecialChar ~
13980 \SpecialChar ~
13981 \SpecialChar ~
13982 \SpecialChar ~
13983 \SpecialChar ~
13984 \SpecialChar ~
13985 \SpecialChar ~
13986 \SpecialChar ~
13987 .area OSEG 
13988 \newline 
13989 _asm_func_PARM_2:
13990 \newline 
13991 \SpecialChar ~
13992 \SpecialChar ~
13993 \SpecialChar ~
13994 \SpecialChar ~
13995 \SpecialChar ~
13996 \SpecialChar ~
13997 \SpecialChar ~
13998 \SpecialChar ~
13999 .ds    1 
14000 \newline 
14001 \SpecialChar ~
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 \SpecialChar ~
14005 \SpecialChar ~
14006 \SpecialChar ~
14007 \SpecialChar ~
14008 \SpecialChar ~
14009 .area CSEG 
14010 \newline 
14011 _asm_func: 
14012 \newline 
14013 \SpecialChar ~
14014 \SpecialChar ~
14015 \SpecialChar ~
14016 \SpecialChar ~
14017 \SpecialChar ~
14018 \SpecialChar ~
14019 \SpecialChar ~
14020 \SpecialChar ~
14021 mov\SpecialChar ~
14022 \SpecialChar ~
14023 \SpecialChar ~
14024 \SpecialChar ~
14025 a,dpl 
14026 \newline 
14027 \SpecialChar ~
14028 \SpecialChar ~
14029 \SpecialChar ~
14030 \SpecialChar ~
14031 \SpecialChar ~
14032 \SpecialChar ~
14033 \SpecialChar ~
14034 \SpecialChar ~
14035 add\SpecialChar ~
14036 \SpecialChar ~
14037 \SpecialChar ~
14038 \SpecialChar ~
14039 a,_asm_func_PARM_2 
14040 \newline 
14041 \SpecialChar ~
14042 \SpecialChar ~
14043 \SpecialChar ~
14044 \SpecialChar ~
14045 \SpecialChar ~
14046 \SpecialChar ~
14047 \SpecialChar ~
14048 \SpecialChar ~
14049 mov\SpecialChar ~
14050 \SpecialChar ~
14051 \SpecialChar ~
14052 \SpecialChar ~
14053 dpl,a 
14054 \newline 
14055 \SpecialChar ~
14056 \SpecialChar ~
14057 \SpecialChar ~
14058 \SpecialChar ~
14059 \SpecialChar ~
14060 \SpecialChar ~
14061 \SpecialChar ~
14062 \SpecialChar ~
14063 mov\SpecialChar ~
14064 \SpecialChar ~
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 dph
14068 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14069
14070 \end_inset 
14071
14072 ,#0x00 
14073 \newline 
14074 \SpecialChar ~
14075 \SpecialChar ~
14076 \SpecialChar ~
14077 \SpecialChar ~
14078 \SpecialChar ~
14079 \SpecialChar ~
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 ret
14083 \layout Standard
14084
14085 Note here that the return values
14086 \begin_inset LatexCommand \index{return value}
14087
14088 \end_inset 
14089
14090  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14091  two byte values.
14092  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14093 b' & 'acc' for four byte values.
14094 \layout Standard
14095
14096 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14097  the parameter number starting from 1, and counting from the left.
14098  The first parameter is passed in 
14099 \begin_inset Quotes eld
14100 \end_inset 
14101
14102 dpl
14103 \begin_inset Quotes erd
14104 \end_inset 
14105
14106  for a one byte parameter, 
14107 \begin_inset Quotes eld
14108 \end_inset 
14109
14110 dptr
14111 \begin_inset Quotes erd
14112 \end_inset 
14113
14114  for two bytes, 
14115 \begin_inset Quotes eld
14116 \end_inset 
14117
14118 b,dptr
14119 \begin_inset Quotes erd
14120 \end_inset 
14121
14122  for three bytes and 
14123 \begin_inset Quotes eld
14124 \end_inset 
14125
14126 acc,b,dptr
14127 \begin_inset Quotes erd
14128 \end_inset 
14129
14130  for a four bytes parameter.
14131  The variable name for the second parameter will be _<function_name>_PARM_2.
14132 \newline 
14133
14134 \newline 
14135 Assemble the assembler routine with the following command:
14136 \newline 
14137
14138 \newline 
14139
14140 \family sans 
14141 \series bold 
14142 asx8051 -losg asmfunc.asm
14143 \newline 
14144
14145 \newline 
14146
14147 \family default 
14148 \series default 
14149 Then compile and link the assembler routine to the C source file with the
14150  following command:
14151 \newline 
14152
14153 \newline 
14154
14155 \family sans 
14156 \series bold 
14157 sdcc cfunc.c asmfunc.rel
14158 \layout Subsection
14159
14160 Assembler Routine (reentrant)
14161 \layout Standard
14162
14163 In this case
14164 \begin_inset LatexCommand \index{reentrant}
14165
14166 \end_inset 
14167
14168
14169 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14170
14171 \end_inset 
14172
14173  the second parameter
14174 \begin_inset LatexCommand \index{function parameter}
14175
14176 \end_inset 
14177
14178  onwards will be passed on the stack, the parameters are pushed from right
14179  to left i.e.
14180  after the call the leftmost parameter will be on the top of the stack.
14181  Here is an example:
14182 \layout Verse
14183
14184
14185 \family typewriter 
14186 extern int asm_func(unsigned char, unsigned char);
14187 \newline 
14188
14189 \newline 
14190 int c_func (unsigned char i, unsigned char j) reentrant 
14191 \newline 
14192
14193 \newline 
14194 \SpecialChar ~
14195 \SpecialChar ~
14196 \SpecialChar ~
14197 \SpecialChar ~
14198 return asm_func(i,j); 
14199 \newline 
14200
14201 \newline 
14202
14203 \newline 
14204 int main() 
14205 \newline 
14206
14207 \newline 
14208 \SpecialChar ~
14209 \SpecialChar ~
14210 \SpecialChar ~
14211 \SpecialChar ~
14212 return c_func(10,9); 
14213 \newline 
14214 }
14215 \layout Standard
14216
14217 The corresponding assembler routine is:
14218 \layout Verse
14219
14220
14221 \family typewriter 
14222 .globl _asm_func 
14223 \newline 
14224 _asm_func: 
14225 \newline 
14226 \SpecialChar ~
14227 \SpecialChar ~
14228 \SpecialChar ~
14229 \SpecialChar ~
14230 push  _bp 
14231 \newline 
14232 \SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 \SpecialChar ~
14236 mov _bp,sp 
14237 \newline 
14238 \SpecialChar ~
14239 \SpecialChar ~
14240 \SpecialChar ~
14241 \SpecialChar ~
14242 mov r2,dpl
14243 \newline 
14244 \SpecialChar ~
14245 \SpecialChar ~
14246 \SpecialChar ~
14247 \SpecialChar ~
14248 mov a,_bp 
14249 \newline 
14250 \SpecialChar ~
14251 \SpecialChar ~
14252 \SpecialChar ~
14253 \SpecialChar ~
14254 add a,#0xfd 
14255 \newline 
14256 \SpecialChar ~
14257 \SpecialChar ~
14258 \SpecialChar ~
14259 \SpecialChar ~
14260 mov r0,a 
14261 \newline 
14262 \SpecialChar ~
14263 \SpecialChar ~
14264 \SpecialChar ~
14265 \SpecialChar ~
14266 add  a,#0xfc ;?
14267 \newline 
14268 \SpecialChar ~
14269 \SpecialChar ~
14270 \SpecialChar ~
14271 \SpecialChar ~
14272 mov  r1,a 
14273 \newline 
14274 \SpecialChar ~
14275 \SpecialChar ~
14276 \SpecialChar ~
14277 \SpecialChar ~
14278 mov  a,@r0 
14279 \newline 
14280 \SpecialChar ~
14281 \SpecialChar ~
14282 \SpecialChar ~
14283 \SpecialChar ~
14284 add  a,r2 ;?
14285 \newline 
14286 \SpecialChar ~
14287 \SpecialChar ~
14288 \SpecialChar ~
14289 \SpecialChar ~
14290 mov  dpl,a 
14291 \newline 
14292 \SpecialChar ~
14293 \SpecialChar ~
14294 \SpecialChar ~
14295 \SpecialChar ~
14296 mov  dph,#0x00 
14297 \newline 
14298 \SpecialChar ~
14299 \SpecialChar ~
14300 \SpecialChar ~
14301 \SpecialChar ~
14302 mov  sp,_bp 
14303 \newline 
14304 \SpecialChar ~
14305 \SpecialChar ~
14306 \SpecialChar ~
14307 \SpecialChar ~
14308 pop  _bp 
14309 \newline 
14310 \SpecialChar ~
14311 \SpecialChar ~
14312 \SpecialChar ~
14313 \SpecialChar ~
14314 ret
14315 \layout Standard
14316
14317 The compiling and linking procedure remains the same, however note the extra
14318  entry & exit linkage required for the assembler code, _bp is the stack
14319  frame pointer and is used to compute the offset into the stack for parameters
14320  and local variables.
14321 \layout Section
14322
14323 int (16 bit)
14324 \begin_inset LatexCommand \index{int (16 bit)}
14325
14326 \end_inset 
14327
14328  and long (32 bit)
14329 \begin_inset LatexCommand \index{long (32 bit)}
14330
14331 \end_inset 
14332
14333  Support
14334 \layout Standard
14335
14336 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14337  multiplication and modulus operations are implemented by support routines.
14338  These support routines are all developed in ANSI-C to facilitate porting
14339  to other MCUs, although some model specific assembler optimizations are
14340  used.
14341  The following files contain the described routines, all of them can be
14342  found in <installdir>/share/sdcc/lib.
14343 \newline 
14344
14345 \layout Standard
14346 \align center 
14347
14348 \begin_inset  Tabular
14349 <lyxtabular version="3" rows="11" columns="2">
14350 <features>
14351 <column alignment="left" valignment="top" leftline="true" width="0">
14352 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14353 <row topline="true" bottomline="true">
14354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14355 \begin_inset Text
14356
14357 \layout Standard
14358
14359
14360 \series bold 
14361 Function
14362 \end_inset 
14363 </cell>
14364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14365 \begin_inset Text
14366
14367 \layout Standard
14368
14369
14370 \series bold 
14371 Description
14372 \end_inset 
14373 </cell>
14374 </row>
14375 <row topline="true">
14376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14377 \begin_inset Text
14378
14379 \layout Standard
14380
14381 _mulint.c 
14382 \end_inset 
14383 </cell>
14384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14385 \begin_inset Text
14386
14387 \layout Standard
14388
14389 16 bit multiplication
14390 \end_inset 
14391 </cell>
14392 </row>
14393 <row topline="true">
14394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14395 \begin_inset Text
14396
14397 \layout Standard
14398
14399 _divsint.c 
14400 \end_inset 
14401 </cell>
14402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14403 \begin_inset Text
14404
14405 \layout Standard
14406
14407  signed 16 bit division (calls _divuint)
14408 \end_inset 
14409 </cell>
14410 </row>
14411 <row topline="true">
14412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14413 \begin_inset Text
14414
14415 \layout Standard
14416
14417 _divuint.c 
14418 \end_inset 
14419 </cell>
14420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14421 \begin_inset Text
14422
14423 \layout Standard
14424
14425  unsigned 16 bit division
14426 \end_inset 
14427 </cell>
14428 </row>
14429 <row topline="true">
14430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14431 \begin_inset Text
14432
14433 \layout Standard
14434
14435 _modsint.c
14436 \end_inset 
14437 </cell>
14438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14439 \begin_inset Text
14440
14441 \layout Standard
14442
14443 signed 16 bit modulus (calls _moduint)
14444 \end_inset 
14445 </cell>
14446 </row>
14447 <row topline="true">
14448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14449 \begin_inset Text
14450
14451 \layout Standard
14452
14453 _moduint.c
14454 \end_inset 
14455 </cell>
14456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14457 \begin_inset Text
14458
14459 \layout Standard
14460
14461 unsigned 16 bit modulus
14462 \end_inset 
14463 </cell>
14464 </row>
14465 <row topline="true">
14466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14467 \begin_inset Text
14468
14469 \layout Standard
14470
14471 _mullong.c
14472 \end_inset 
14473 </cell>
14474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14475 \begin_inset Text
14476
14477 \layout Standard
14478
14479 32 bit multiplication
14480 \end_inset 
14481 </cell>
14482 </row>
14483 <row topline="true">
14484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14485 \begin_inset Text
14486
14487 \layout Standard
14488
14489 _divslong.c 
14490 \end_inset 
14491 </cell>
14492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14493 \begin_inset Text
14494
14495 \layout Standard
14496
14497  signed 32 division (calls _divulong)
14498 \end_inset 
14499 </cell>
14500 </row>
14501 <row topline="true">
14502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14503 \begin_inset Text
14504
14505 \layout Standard
14506
14507 _divulong.c 
14508 \end_inset 
14509 </cell>
14510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14511 \begin_inset Text
14512
14513 \layout Standard
14514
14515 unsigned 32 division
14516 \end_inset 
14517 </cell>
14518 </row>
14519 <row topline="true">
14520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14521 \begin_inset Text
14522
14523 \layout Standard
14524
14525 _modslong.c
14526 \end_inset 
14527 </cell>
14528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14529 \begin_inset Text
14530
14531 \layout Standard
14532
14533  signed 32 bit modulus (calls _modulong)
14534 \end_inset 
14535 </cell>
14536 </row>
14537 <row topline="true" bottomline="true">
14538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14539 \begin_inset Text
14540
14541 \layout Standard
14542
14543 _modulong.c
14544 \end_inset 
14545 </cell>
14546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14547 \begin_inset Text
14548
14549 \layout Standard
14550
14551 unsigned 32 bit modulus
14552 \end_inset 
14553 </cell>
14554 </row>
14555 </lyxtabular>
14556
14557 \end_inset 
14558
14559
14560 \newline 
14561
14562 \layout Standard
14563
14564 Since they are compiled as 
14565 \emph on 
14566 non-reentrant
14567 \emph default 
14568
14569 \begin_inset LatexCommand \index{reentrant}
14570
14571 \end_inset 
14572
14573 , interrupt
14574 \begin_inset LatexCommand \index{interrupt}
14575
14576 \end_inset 
14577
14578  service routines should not do any of the above operations.
14579  If this is unavoidable then the above routines will need to be compiled
14580  with the 
14581 \emph on 
14582 -
14583 \begin_inset ERT
14584 status Collapsed
14585
14586 \layout Standard
14587
14588 \backslash 
14589 /
14590 \end_inset 
14591
14592 -stack-auto
14593 \begin_inset LatexCommand \index{-\/-stack-auto}
14594
14595 \end_inset 
14596
14597
14598 \emph default 
14599  option, after which the source program will have to be compiled with 
14600 \emph on 
14601 -
14602 \begin_inset ERT
14603 status Collapsed
14604
14605 \layout Standard
14606
14607 \backslash 
14608 /
14609 \end_inset 
14610
14611 -int-long-reent
14612 \begin_inset LatexCommand \index{-\/-int-long-reent}
14613
14614 \end_inset 
14615
14616
14617 \emph default 
14618  option.
14619  Notice that you don't have to call these routines directly.
14620  The compiler will use them automatically every time an integer operation
14621  is required.
14622 \layout Section
14623
14624 Floating Point Support
14625 \begin_inset LatexCommand \index{Floating point support}
14626
14627 \end_inset 
14628
14629
14630 \layout Standard
14631
14632 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
14633  floating point support routines are derived from gcc's floatlib.c and consist
14634  of the following routines:
14635 \newline 
14636
14637 \layout Standard
14638 \align center 
14639
14640 \size footnotesize 
14641
14642 \begin_inset  Tabular
14643 <lyxtabular version="3" rows="17" columns="2">
14644 <features>
14645 <column alignment="left" valignment="top" leftline="true" width="0">
14646 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14647 <row topline="true" bottomline="true">
14648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14649 \begin_inset Text
14650
14651 \layout Standard
14652
14653
14654 \family roman 
14655 \series medium 
14656 \shape up 
14657 \size normal 
14658 \emph off 
14659 \bar no 
14660 \noun off 
14661 \color none
14662 Function 
14663 \end_inset 
14664 </cell>
14665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14666 \begin_inset Text
14667
14668 \layout Standard
14669
14670 Description
14671 \end_inset 
14672 </cell>
14673 </row>
14674 <row topline="true">
14675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14676 \begin_inset Text
14677
14678 \layout Standard
14679
14680
14681 \family roman 
14682 \series medium 
14683 \shape up 
14684 \size normal 
14685 \emph off 
14686 \bar no 
14687 \noun off 
14688 \color none
14689 _fsadd.c
14690 \end_inset 
14691 </cell>
14692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14693 \begin_inset Text
14694
14695 \layout Standard
14696
14697
14698 \family roman 
14699 \series medium 
14700 \shape up 
14701 \size normal 
14702 \emph off 
14703 \bar no 
14704 \noun off 
14705 \color none
14706 add floating point numbers
14707 \end_inset 
14708 </cell>
14709 </row>
14710 <row topline="true">
14711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14712 \begin_inset Text
14713
14714 \layout Standard
14715
14716
14717 \family roman 
14718 \series medium 
14719 \shape up 
14720 \size normal 
14721 \emph off 
14722 \bar no 
14723 \noun off 
14724 \color none
14725 _fssub.c 
14726 \end_inset 
14727 </cell>
14728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14729 \begin_inset Text
14730
14731 \layout Standard
14732
14733
14734 \family roman 
14735 \series medium 
14736 \shape up 
14737 \size normal 
14738 \emph off 
14739 \bar no 
14740 \noun off 
14741 \color none
14742 subtract floating point numbers 
14743 \end_inset 
14744 </cell>
14745 </row>
14746 <row topline="true">
14747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14748 \begin_inset Text
14749
14750 \layout Standard
14751
14752
14753 \family roman 
14754 \series medium 
14755 \shape up 
14756 \size normal 
14757 \emph off 
14758 \bar no 
14759 \noun off 
14760 \color none
14761 _fsdiv.c 
14762 \end_inset 
14763 </cell>
14764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14765 \begin_inset Text
14766
14767 \layout Standard
14768
14769
14770 \family roman 
14771 \series medium 
14772 \shape up 
14773 \size normal 
14774 \emph off 
14775 \bar no 
14776 \noun off 
14777 \color none
14778 divide floating point numbers 
14779 \end_inset 
14780 </cell>
14781 </row>
14782 <row topline="true">
14783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14784 \begin_inset Text
14785
14786 \layout Standard
14787
14788
14789 \family roman 
14790 \series medium 
14791 \shape up 
14792 \size normal 
14793 \emph off 
14794 \bar no 
14795 \noun off 
14796 \color none
14797 _fsmul.c 
14798 \end_inset 
14799 </cell>
14800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14801 \begin_inset Text
14802
14803 \layout Standard
14804
14805
14806 \family roman 
14807 \series medium 
14808 \shape up 
14809 \size normal 
14810 \emph off 
14811 \bar no 
14812 \noun off 
14813 \color none
14814 multiply floating point numbers 
14815 \end_inset 
14816 </cell>
14817 </row>
14818 <row topline="true">
14819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14820 \begin_inset Text
14821
14822 \layout Standard
14823
14824
14825 \family roman 
14826 \series medium 
14827 \shape up 
14828 \size normal 
14829 \emph off 
14830 \bar no 
14831 \noun off 
14832 \color none
14833 _fs2uchar.c
14834 \end_inset 
14835 </cell>
14836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14837 \begin_inset Text
14838
14839 \layout Standard
14840
14841
14842 \family roman 
14843 \series medium 
14844 \shape up 
14845 \size normal 
14846 \emph off 
14847 \bar no 
14848 \noun off 
14849 \color none
14850 convert floating point to unsigned char
14851 \end_inset 
14852 </cell>
14853 </row>
14854 <row topline="true">
14855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14856 \begin_inset Text
14857
14858 \layout Standard
14859
14860
14861 \family roman 
14862 \series medium 
14863 \shape up 
14864 \size normal 
14865 \emph off 
14866 \bar no 
14867 \noun off 
14868 \color none
14869 _fs2char.c
14870 \end_inset 
14871 </cell>
14872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14873 \begin_inset Text
14874
14875 \layout Standard
14876
14877
14878 \family roman 
14879 \series medium 
14880 \shape up 
14881 \size normal 
14882 \emph off 
14883 \bar no 
14884 \noun off 
14885 \color none
14886 convert floating point to signed char
14887 \end_inset 
14888 </cell>
14889 </row>
14890 <row topline="true">
14891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14892 \begin_inset Text
14893
14894 \layout Standard
14895
14896
14897 \family roman 
14898 \series medium 
14899 \shape up 
14900 \size normal 
14901 \emph off 
14902 \bar no 
14903 \noun off 
14904 \color none
14905 _fs2uint.c
14906 \end_inset 
14907 </cell>
14908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14909 \begin_inset Text
14910
14911 \layout Standard
14912
14913
14914 \family roman 
14915 \series medium 
14916 \shape up 
14917 \size normal 
14918 \emph off 
14919 \bar no 
14920 \noun off 
14921 \color none
14922 convert floating point to unsigned int
14923 \end_inset 
14924 </cell>
14925 </row>
14926 <row topline="true">
14927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14928 \begin_inset Text
14929
14930 \layout Standard
14931
14932
14933 \family roman 
14934 \series medium 
14935 \shape up 
14936 \size normal 
14937 \emph off 
14938 \bar no 
14939 \noun off 
14940 \color none
14941 _fs2int.c
14942 \end_inset 
14943 </cell>
14944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14945 \begin_inset Text
14946
14947 \layout Standard
14948
14949
14950 \family roman 
14951 \series medium 
14952 \shape up 
14953 \size normal 
14954 \emph off 
14955 \bar no 
14956 \noun off 
14957 \color none
14958 convert floating point to signed int
14959 \end_inset 
14960 </cell>
14961 </row>
14962 <row topline="true">
14963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14964 \begin_inset Text
14965
14966 \layout Standard
14967
14968
14969 \family roman 
14970 \series medium 
14971 \shape up 
14972 \size normal 
14973 \emph off 
14974 \bar no 
14975 \noun off 
14976 \color none
14977 _fs2ulong.
14978 \family default 
14979 \series default 
14980 \shape default 
14981 \size default 
14982 \emph default 
14983 \bar default 
14984 \noun default 
14985 \color default
14986 c
14987 \end_inset 
14988 </cell>
14989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14990 \begin_inset Text
14991
14992 \layout Standard
14993
14994
14995 \family roman 
14996 \series medium 
14997 \shape up 
14998 \size normal 
14999 \emph off 
15000 \bar no 
15001 \noun off 
15002 \color none
15003 convert floating point to unsigned long
15004 \end_inset 
15005 </cell>
15006 </row>
15007 <row topline="true">
15008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15009 \begin_inset Text
15010
15011 \layout Standard
15012
15013
15014 \family roman 
15015 \series medium 
15016 \shape up 
15017 \size normal 
15018 \emph off 
15019 \bar no 
15020 \noun off 
15021 \color none
15022 _fs2long.c
15023 \end_inset 
15024 </cell>
15025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15026 \begin_inset Text
15027
15028 \layout Standard
15029
15030
15031 \family roman 
15032 \series medium 
15033 \shape up 
15034 \size normal 
15035 \emph off 
15036 \bar no 
15037 \noun off 
15038 \color none
15039 convert floating point to signed long
15040 \end_inset 
15041 </cell>
15042 </row>
15043 <row topline="true">
15044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15045 \begin_inset Text
15046
15047 \layout Standard
15048
15049
15050 \family roman 
15051 \series medium 
15052 \shape up 
15053 \size normal 
15054 \emph off 
15055 \bar no 
15056 \noun off 
15057 \color none
15058 _uchar2fs.c
15059 \end_inset 
15060 </cell>
15061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15062 \begin_inset Text
15063
15064 \layout Standard
15065
15066
15067 \family roman 
15068 \series medium 
15069 \shape up 
15070 \size normal 
15071 \emph off 
15072 \bar no 
15073 \noun off 
15074 \color none
15075 convert unsigned char to floating point
15076 \end_inset 
15077 </cell>
15078 </row>
15079 <row topline="true">
15080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15081 \begin_inset Text
15082
15083 \layout Standard
15084
15085
15086 \family roman 
15087 \series medium 
15088 \shape up 
15089 \size normal 
15090 \emph off 
15091 \bar no 
15092 \noun off 
15093 \color none
15094 _char2fs.c
15095 \end_inset 
15096 </cell>
15097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15098 \begin_inset Text
15099
15100 \layout Standard
15101
15102
15103 \family roman 
15104 \series medium 
15105 \shape up 
15106 \size normal 
15107 \emph off 
15108 \bar no 
15109 \noun off 
15110 \color none
15111 convert char to floating point number
15112 \end_inset 
15113 </cell>
15114 </row>
15115 <row topline="true">
15116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15117 \begin_inset Text
15118
15119 \layout Standard
15120
15121
15122 \family roman 
15123 \series medium 
15124 \shape up 
15125 \size normal 
15126 \emph off 
15127 \bar no 
15128 \noun off 
15129 \color none
15130 _uint2fs.c
15131 \end_inset 
15132 </cell>
15133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15134 \begin_inset Text
15135
15136 \layout Standard
15137
15138
15139 \family roman 
15140 \series medium 
15141 \shape up 
15142 \size normal 
15143 \emph off 
15144 \bar no 
15145 \noun off 
15146 \color none
15147 convert unsigned int to floating point
15148 \end_inset 
15149 </cell>
15150 </row>
15151 <row topline="true">
15152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15153 \begin_inset Text
15154
15155 \layout Standard
15156
15157
15158 \family roman 
15159 \series medium 
15160 \shape up 
15161 \size normal 
15162 \emph off 
15163 \bar no 
15164 \noun off 
15165 \color none
15166 _int2fs.c
15167 \end_inset 
15168 </cell>
15169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15170 \begin_inset Text
15171
15172 \layout Standard
15173
15174
15175 \family roman 
15176 \series medium 
15177 \shape up 
15178 \size normal 
15179 \emph off 
15180 \bar no 
15181 \noun off 
15182 \color none
15183 convert int to floating point numbers
15184 \end_inset 
15185 </cell>
15186 </row>
15187 <row topline="true">
15188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15189 \begin_inset Text
15190
15191 \layout Standard
15192
15193
15194 \family roman 
15195 \series medium 
15196 \shape up 
15197 \size normal 
15198 \emph off 
15199 \bar no 
15200 \noun off 
15201 \color none
15202 _ulong2fs.c
15203 \end_inset 
15204 </cell>
15205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15206 \begin_inset Text
15207
15208 \layout Standard
15209
15210
15211 \family roman 
15212 \series medium 
15213 \shape up 
15214 \size normal 
15215 \emph off 
15216 \bar no 
15217 \noun off 
15218 \color none
15219 convert unsigned long to floating point number
15220 \end_inset 
15221 </cell>
15222 </row>
15223 <row topline="true" bottomline="true">
15224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15225 \begin_inset Text
15226
15227 \layout Standard
15228
15229
15230 \family roman 
15231 \series medium 
15232 \shape up 
15233 \size normal 
15234 \emph off 
15235 \bar no 
15236 \noun off 
15237 \color none
15238 _long2fs.c
15239 \end_inset 
15240 </cell>
15241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15242 \begin_inset Text
15243
15244 \layout Standard
15245
15246
15247 \family roman 
15248 \series medium 
15249 \shape up 
15250 \size normal 
15251 \emph off 
15252 \bar no 
15253 \noun off 
15254 \color none
15255 convert long to floating point number
15256 \end_inset 
15257 </cell>
15258 </row>
15259 </lyxtabular>
15260
15261 \end_inset 
15262
15263
15264 \newline 
15265
15266 \layout Standard
15267
15268 These support routines are developed in ANSI-C so there is room for space
15269  and speed improvement
15270 \begin_inset Foot
15271 collapsed false
15272
15273 \layout Standard
15274
15275 These floating point routines (
15276 \emph on 
15277 not
15278 \emph default 
15279  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15280  
15281 \end_inset 
15282
15283 .
15284  Note if all these routines are used simultaneously the data space might
15285  overflow.
15286  For serious floating point usage the large model might be needed.
15287  Also notice that you don't have to call this routines directly.
15288  The compiler will use them automatically every time a floating point operation
15289  is required.
15290 \layout Section
15291
15292 Library Routines
15293 \begin_inset LatexCommand \index{Libraries}
15294
15295 \end_inset 
15296
15297
15298 \layout Standard
15299
15300
15301 \emph on 
15302 <pending: this is messy and incomplete - a little more information is in
15303  sdcc/doc/libdoc.txt
15304 \emph default 
15305  >
15306 \layout Subsection
15307
15308 Compiler support routines (_gptrget, _mulint etc.)
15309 \layout Subsection
15310
15311 Stdclib functions (puts, printf, strcat etc.)
15312 \layout Subsubsection
15313
15314 <stdio.h>
15315 \layout Standard
15316
15317
15318 \begin_inset LatexCommand \index{<stdio.h>}
15319
15320 \end_inset 
15321
15322 As usual on embedded systems you have to provide your own 
15323 \family typewriter 
15324 getchar()
15325 \begin_inset LatexCommand \index{getchar()}
15326
15327 \end_inset 
15328
15329  
15330 \family default 
15331 and 
15332 \family typewriter 
15333 putchar()
15334 \begin_inset LatexCommand \index{putchar()}
15335
15336 \end_inset 
15337
15338
15339 \family default 
15340  routines.
15341  SDCC does not know whether the system connects to a serial line with or
15342  without handshake, LCD, keyboard or other device.
15343  And whether a 
15344 \family typewriter 
15345 lf
15346 \family default 
15347  to 
15348 \family typewriter 
15349 crlf
15350 \family default 
15351  conversion within 
15352 \family typewriter 
15353 putchar()
15354 \family default 
15355  is intended.
15356  You'll find examples for serial routines f.e.
15357  in sdcc/device/lib.
15358 \layout Standard
15359
15360 The default
15361 \family typewriter 
15362  printf()
15363 \begin_inset LatexCommand \index{printf()}
15364
15365 \end_inset 
15366
15367
15368 \family default 
15369 implementation in
15370 \family typewriter 
15371  printf_large.c
15372 \family default 
15373  does not support float (except on ds390).
15374  To enable this recompile it with the option 
15375 \emph on 
15376 -
15377 \begin_inset ERT
15378 status Collapsed
15379
15380 \layout Standard
15381
15382 \backslash 
15383 /
15384 \end_inset 
15385
15386 DUSE_FLOATS=1
15387 \begin_inset LatexCommand \index{USE\_FLOATS}
15388
15389 \end_inset 
15390
15391
15392 \emph default 
15393  on the command line.
15394  Use
15395 \emph on 
15396  -
15397 \begin_inset ERT
15398 status Collapsed
15399
15400 \layout Standard
15401
15402 \backslash 
15403 /
15404 \end_inset 
15405
15406 -model-large
15407 \begin_inset LatexCommand \index{-\/-model-large}
15408
15409 \end_inset 
15410
15411
15412 \emph default 
15413  for the mcs51 port, since this uses a lot of memory.
15414 \layout Standard
15415
15416 If you're short on memory you might want to use 
15417 \family typewriter 
15418 printf_small()
15419 \begin_inset LatexCommand \index{printf\_small()}
15420
15421 \end_inset 
15422
15423
15424 \family default 
15425  
15426 \emph on 
15427 instead
15428 \emph default 
15429  of
15430 \family typewriter 
15431  printf().
15432
15433 \family default 
15434  For the mcs51 there additionally are assembly versions 
15435 \family typewriter 
15436 printf_tiny()
15437 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
15438
15439 \end_inset 
15440
15441
15442 \family default 
15443  (subset of printf using less than 270 bytes) and 
15444 \family typewriter 
15445 printf_fast()
15446 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
15447
15448 \end_inset 
15449
15450  
15451 \family default 
15452 and
15453 \family typewriter 
15454  printf_fast_f()
15455 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
15456
15457 \end_inset 
15458
15459
15460 \family default 
15461  (floating-point aware version of printf_fast) which should fit the requirements
15462  of many embedded systems (printf_fast() can be customized by unsetting
15463  #defines to 
15464 \emph on 
15465 not
15466 \emph default 
15467  support long variables and field widths).
15468 \layout Subsection
15469
15470 Math functions (sinf, powf, sqrtf etc.)
15471 \layout Subsubsection
15472
15473 <math.h>
15474 \layout Standard
15475
15476 See definitions in file <math.h>.
15477 \layout Subsection
15478
15479 Other libraries
15480 \layout Standard
15481
15482 Libraries
15483 \begin_inset LatexCommand \index{Libraries}
15484
15485 \end_inset 
15486
15487  included in SDCC should have a license at least as liberal as the GNU Lesser
15488  General Public License
15489 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15490
15491 \end_inset 
15492
15493  
15494 \emph on 
15495 LGPL
15496 \emph default 
15497 .
15498 \layout Comment
15499
15500 license statements for the libraries are missing.
15501  sdcc/device/lib/ser_ir.c
15502 \layout Comment
15503
15504 or _decdptr f.e.
15505  come with a GPL (as opposed to LGPL) License - this will not be liberal
15506  enough for many embedded programmers.
15507 \layout Standard
15508
15509 If you have ported some library or want to share experience about some code
15510  which f.e.
15511  falls into any of these categories Busses (I
15512 \begin_inset Formula $^{\textrm{2}}$
15513 \end_inset 
15514
15515 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
15516  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
15517  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
15518 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
15519
15520 \end_inset 
15521
15522 \SpecialChar ~
15523 would certainly like to hear about it.
15524  Programmers coding for embedded systems are not especially famous for being
15525  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
15526 e these references are very valuable.
15527  Let's help to create a climate where information is shared.
15528 \layout Section
15529
15530 Memory Models
15531 \layout Subsection
15532
15533 MCS51 Memory Models
15534 \begin_inset LatexCommand \index{Memory model}
15535
15536 \end_inset 
15537
15538
15539 \begin_inset LatexCommand \index{MCS51 memory model}
15540
15541 \end_inset 
15542
15543
15544 \layout Subsubsection
15545
15546 Small, Medium and Large
15547 \layout Standard
15548
15549 SDCC allows three memory models for MCS51 code, 
15550 \shape slanted 
15551 small, medium
15552 \shape default 
15553  and 
15554 \shape slanted 
15555 large
15556 \shape default 
15557 .
15558  Modules compiled with different memory models should 
15559 \emph on 
15560 never
15561 \emph default 
15562  be combined together or the results would be unpredictable.
15563  The library routines supplied with the compiler are compiled as small,
15564  medium and large.
15565  The compiled library modules are contained in separate directories as small,
15566  medium and large so that you can link to the appropriate set.
15567 \layout Standard
15568
15569 When the medium or large model is used all variables declared without a
15570  storage class will be allocated into the external ram, this includes all
15571  parameters and local variables (for non-reentrant
15572 \begin_inset LatexCommand \index{reentrant}
15573
15574 \end_inset 
15575
15576  functions).
15577  When the small model is used variables without storage class are allocated
15578  in the internal ram.
15579 \layout Standard
15580
15581 Judicious usage of the processor specific storage classes
15582 \begin_inset LatexCommand \index{Storage class}
15583
15584 \end_inset 
15585
15586  and the 'reentrant' function type will yield much more efficient code,
15587  than using the large model.
15588  Several optimizations are disabled when the program is compiled using the
15589  large model, it is therefore recommended that the small model be used unless
15590  absolutely required.
15591 \layout Subsubsection
15592
15593 External Stack
15594 \begin_inset LatexCommand \label{sub:External-Stack}
15595
15596 \end_inset 
15597
15598
15599 \begin_inset LatexCommand \index{stack}
15600
15601 \end_inset 
15602
15603
15604 \begin_inset LatexCommand \index{External stack (mcs51)}
15605
15606 \end_inset 
15607
15608
15609 \layout Standard
15610
15611 The external stack (-
15612 \begin_inset ERT
15613 status Collapsed
15614
15615 \layout Standard
15616
15617 \backslash 
15618 /
15619 \end_inset 
15620
15621 -xstack option
15622 \begin_inset LatexCommand \index{-\/-xstack}
15623
15624 \end_inset 
15625
15626 ) is located in pdata
15627 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
15628
15629 \end_inset 
15630
15631  memory (usually at the start of the external ram segment) and uses all
15632  unused space in pdata (max.
15633  256 bytes).
15634  When -
15635 \begin_inset ERT
15636 status Collapsed
15637
15638 \layout Standard
15639
15640 \backslash 
15641 /
15642 \end_inset 
15643
15644 -xstack option is used to compile the program, the parameters and local
15645  variables
15646 \begin_inset LatexCommand \index{local variables}
15647
15648 \end_inset 
15649
15650  of all reentrant functions are allocated in this area.
15651  This option is provided for programs with large stack space requirements.
15652  When used with the -
15653 \begin_inset ERT
15654 status Collapsed
15655
15656 \layout Standard
15657
15658 \backslash 
15659 /
15660 \end_inset 
15661
15662 -stack-auto
15663 \begin_inset LatexCommand \index{-\/-stack-auto}
15664
15665 \end_inset 
15666
15667  option, all parameters and local variables are allocated on the external
15668  stack (note: support libraries will need to be recompiled with the same
15669  options.
15670  There is a predefined target in the library makefile).
15671 \layout Standard
15672
15673 The compiler outputs the higher order address byte of the external ram segment
15674  into port P2
15675 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
15676
15677 \end_inset 
15678
15679  (see also section 
15680 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15681
15682 \end_inset 
15683
15684 ), therefore when using the External Stack option, this port 
15685 \emph on 
15686 may not
15687 \emph default 
15688  be used by the application program.
15689 \layout Subsection
15690
15691 DS390 Memory Model
15692 \begin_inset LatexCommand \index{Memory model}
15693
15694 \end_inset 
15695
15696
15697 \begin_inset LatexCommand \index{DS390 memory model}
15698
15699 \end_inset 
15700
15701
15702 \layout Standard
15703
15704 The only model supported is Flat 24
15705 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
15706
15707 \end_inset 
15708
15709 .
15710  This generates code for the 24 bit contiguous addressing mode of the Dallas
15711  DS80C390 part.
15712  In this mode, up to four meg of external RAM or code space can be directly
15713  addressed.
15714  See the data sheets at www.dalsemi.com for further information on this part.
15715 \newline 
15716
15717 \newline 
15718 Note that the compiler does not generate any code to place the processor
15719  into 24 bitmode (although 
15720 \emph on 
15721 tinibios
15722 \emph default 
15723  in the ds390 libraries will do that for you).
15724  If you don't use 
15725 \emph on 
15726 tinibios
15727 \emph default 
15728
15729 \begin_inset LatexCommand \index{Tinibios (DS390)}
15730
15731 \end_inset 
15732
15733 , the boot loader or similar code must ensure that the processor is in 24
15734  bit contiguous addressing mode before calling the SDCC startup code.
15735 \newline 
15736
15737 \newline 
15738 Like the 
15739 \emph on 
15740 -
15741 \begin_inset ERT
15742 status Collapsed
15743
15744 \layout Standard
15745
15746 \backslash 
15747 /
15748 \end_inset 
15749
15750 -model-large
15751 \emph default 
15752  option, variables will by default be placed into the XDATA segment.
15753  
15754 \newline 
15755
15756 \newline 
15757 Segments may be placed anywhere in the 4 meg address space using the usual
15758  -
15759 \begin_inset ERT
15760 status Collapsed
15761
15762 \layout Standard
15763
15764 \backslash 
15765 /
15766 \end_inset 
15767
15768 -*-loc options.
15769  Note that if any segments are located above 64K, the -r flag must be passed
15770  to the linker to generate the proper segment relocations, and the Intel
15771  HEX output format must be used.
15772  The -r flag can be passed to the linker by using the option 
15773 \emph on 
15774 -Wl-r
15775 \emph default 
15776  on the SDCC command line.
15777  However, currently the linker can not handle code segments > 64k.
15778 \layout Section
15779
15780 Pragmas
15781 \begin_inset LatexCommand \index{Pragmas}
15782
15783 \end_inset 
15784
15785
15786 \layout Standard
15787
15788 SDCC supports the following #pragma directives:
15789 \layout Itemize
15790
15791 save
15792 \begin_inset LatexCommand \index{\#pragma save}
15793
15794 \end_inset 
15795
15796  - this will save all current options to the save/restore stack.
15797  See #pragma\SpecialChar ~
15798 restore.
15799 \layout Itemize
15800
15801 restore
15802 \begin_inset LatexCommand \index{\#pragma restore}
15803
15804 \end_inset 
15805
15806  - will restore saved options from the last save.
15807  saves & restores can be nested.
15808  SDCC uses a save/restore stack: save pushes current options to the stack,
15809  restore pulls current options from the stack.
15810  See #pragma\SpecialChar ~
15811 save.
15812 \newline 
15813
15814 \layout Itemize
15815
15816 callee_saves
15817 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15818
15819 \end_inset 
15820
15821
15822 \begin_inset LatexCommand \index{function prologue}
15823
15824 \end_inset 
15825
15826  function1[,function2[,function3...]] - The compiler by default uses a caller
15827  saves convention for register saving across function calls, however this
15828  can cause unnecessary register pushing & popping
15829 \begin_inset LatexCommand \index{push/pop}
15830
15831 \end_inset 
15832
15833  when calling small functions from larger functions.
15834  This option can be used to switch off the register saving convention for
15835  the function names specified.
15836  The compiler will not save registers when calling these functions, extra
15837  code need to be manually inserted at the entry & exit for these functions
15838  to save & restore the registers used by these functions, this can SUBSTANTIALLY
15839  reduce code & improve run time performance of the generated code.
15840  In the future the compiler (with inter procedural analysis) may be able
15841  to determine the appropriate scheme to use for each function call.
15842  If -
15843 \begin_inset ERT
15844 status Collapsed
15845
15846 \layout Standard
15847
15848 \backslash 
15849 /
15850 \end_inset 
15851
15852 -callee-saves command line option is used, the function names specified
15853  in #pragma\SpecialChar ~
15854 callee_saves
15855 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15856
15857 \end_inset 
15858
15859  is appended to the list of functions specified in the command line.
15860 \layout Itemize
15861
15862 exclude
15863 \begin_inset LatexCommand \index{\#pragma exclude}
15864
15865 \end_inset 
15866
15867  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
15868  of pairs of push/pop
15869 \begin_inset LatexCommand \index{push/pop}
15870
15871 \end_inset 
15872
15873  instructions in 
15874 \emph on 
15875 I
15876 \emph default 
15877 nterrupt
15878 \begin_inset LatexCommand \index{interrupt}
15879
15880 \end_inset 
15881
15882  
15883 \emph on 
15884 S
15885 \emph default 
15886 ervice 
15887 \emph on 
15888 R
15889 \emph default 
15890 outines.
15891  The directive should be placed immediately before the ISR function definition
15892  and it affects ALL ISR functions following it.
15893  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
15894 exclude\SpecialChar ~
15895 none
15896 \begin_inset LatexCommand \index{\#pragma exclude}
15897
15898 \end_inset 
15899
15900 .
15901  See also the related keyword _naked
15902 \begin_inset LatexCommand \index{\_naked}
15903
15904 \end_inset 
15905
15906
15907 \begin_inset LatexCommand \index{\_\_naked}
15908
15909 \end_inset 
15910
15911 .
15912 \layout Itemize
15913
15914 less_pedantic
15915 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
15916
15917 \end_inset 
15918
15919  - the compiler will not warn you anymore for obvious mistakes, you'r on
15920  your own now ;-(
15921 \layout Itemize
15922
15923 disable_warning <nnnn>
15924 \begin_inset LatexCommand \index{\#pragma disable\_warning}
15925
15926 \end_inset 
15927
15928  - the compiler will not warn you anymore about warning number <nnnn>.
15929 \layout Itemize
15930
15931 nogcse
15932 \begin_inset LatexCommand \index{\#pragma nogcse}
15933
15934 \end_inset 
15935
15936  - will stop global common subexpression elimination.
15937 \layout Itemize
15938
15939 noinduction
15940 \begin_inset LatexCommand \index{\#pragma noinduction}
15941
15942 \end_inset 
15943
15944  - will stop loop induction optimizations.
15945 \layout Itemize
15946
15947 noinvariant
15948 \begin_inset LatexCommand \index{\#pragma noinvariant}
15949
15950 \end_inset 
15951
15952  - will not do loop invariant optimizations.
15953  For more details see Loop Invariants in section
15954 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
15955
15956 \end_inset 
15957
15958 .
15959 \layout Itemize
15960
15961 noiv
15962 \begin_inset LatexCommand \index{\#pragma noiv}
15963
15964 \end_inset 
15965
15966  - Do not generate interrupt
15967 \begin_inset LatexCommand \index{interrupt}
15968
15969 \end_inset 
15970
15971  vector table entries for all ISR functions defined after the pragma.
15972  This is useful in cases where the interrupt vector table must be defined
15973  manually, or when there is a secondary, manually defined interrupt vector
15974  table (e.g.
15975  for the autovector feature of the Cypress EZ-USB FX2).
15976  More elegantly this can be achieved by obmitting the optional interrupt
15977  number after the interrupt keyword, see section 
15978 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
15979
15980 \end_inset 
15981
15982 \SpecialChar ~
15983 about interrupts.
15984 \layout Itemize
15985
15986 nojtbound
15987 \begin_inset LatexCommand \index{\#pragma nojtbound}
15988
15989 \end_inset 
15990
15991  - will not generate code for boundary value checking, when switch statements
15992  are turned into jump-tables (dangerous).
15993  For more details see section 
15994 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
15995
15996 \end_inset 
15997
15998 .
15999 \layout Itemize
16000
16001 noloopreverse
16002 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16003
16004 \end_inset 
16005
16006  - Will not do loop reversal optimization
16007 \layout Itemize
16008
16009 nooverlay
16010 \begin_inset LatexCommand \index{\#pragma nooverlay}
16011
16012 \end_inset 
16013
16014  - the compiler will not overlay the parameters and local variables of a
16015  function.
16016 \layout Itemize
16017
16018 stackauto
16019 \begin_inset LatexCommand \index{\#pragma stackauto}
16020
16021 \end_inset 
16022
16023 - See option -
16024 \begin_inset ERT
16025 status Collapsed
16026
16027 \layout Standard
16028
16029 \backslash 
16030 /
16031 \end_inset 
16032
16033 -stack-auto
16034 \begin_inset LatexCommand \index{-\/-stack-auto}
16035
16036 \end_inset 
16037
16038  and section 
16039 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16040
16041 \end_inset 
16042
16043  Parameters and Local Variables.
16044 \layout Itemize
16045
16046 opt_code_speed 
16047 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16048
16049 \end_inset 
16050
16051 - The compiler will optimize code generation towards fast code, possibly
16052  at the expense of code size.
16053 \layout Itemize
16054
16055 opt_code_size 
16056 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16057
16058 \end_inset 
16059
16060 - The compiler will optimize code generation towards compact code, possibly
16061  at the expense of code speed.
16062 \layout Itemize
16063
16064 opt_code_balanced 
16065 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16066
16067 \end_inset 
16068
16069 - The compiler will attempt to generate code that is both compact and fast,
16070  as long as meeting one goal is not a detriment to the other (this is the
16071  default).
16072  
16073 \layout Itemize
16074
16075 std_sdcc89 
16076 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16077
16078 \end_inset 
16079
16080 - Generally follow the C89 standard, but allow SDCC features that conflict
16081  with the standard (default).
16082 \layout Itemize
16083
16084 std_c89 
16085 \begin_inset LatexCommand \index{\#pragma std\_c89}
16086
16087 \end_inset 
16088
16089 - Follow the C89 standard and disable SDCC features that conflict with the
16090  standard.
16091 \layout Itemize
16092
16093 std_sdcc99 
16094 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16095
16096 \end_inset 
16097
16098 - Generally follow the C99 standard, but allow SDCC features that conflict
16099  with the standard (incomplete support).
16100 \layout Itemize
16101
16102 std_c99 
16103 \begin_inset LatexCommand \index{\#pragma std\_c99}
16104
16105 \end_inset 
16106
16107 - Follow the C99 standard and disable SDCC features that conflict with the
16108  standard (incomplete support).
16109 \layout Itemize
16110
16111 codeseg <name>
16112 \begin_inset LatexCommand \index{\#pragma codeseg}
16113
16114 \end_inset 
16115
16116 - Use this name (max.
16117  8 characters) for the code segment.
16118  See option -
16119 \begin_inset ERT
16120 status Collapsed
16121
16122 \layout Standard
16123
16124 \backslash 
16125 /
16126 \end_inset 
16127
16128 -codeseg.
16129 \layout Itemize
16130
16131 constseg <name>
16132 \begin_inset LatexCommand \index{\#pragma constseg}
16133
16134 \end_inset 
16135
16136 - Use this name (max.
16137  8 characters) for the const segment.
16138  See option -
16139 \begin_inset ERT
16140 status Collapsed
16141
16142 \layout Standard
16143
16144 \backslash 
16145 /
16146 \end_inset 
16147
16148 -constseg.
16149 \layout Standard
16150
16151 SDCPP supports the following #pragma directives:
16152 \layout Itemize
16153
16154 preproc_asm
16155 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16156
16157 \end_inset 
16158
16159  (+ | -) - switch _asm _endasm block preprocessing on / off.
16160  Default is on.
16161 \layout Standard
16162
16163 The pragma's are intended to be used to turn-on or off certain optimizations
16164  which might cause the compiler to generate extra stack / data space to
16165  store compiler generated temporary variables.
16166  This usually happens in large functions.
16167  Pragma directives should be used as shown in the following example, they
16168  are used to control options & optimizations for a given function; pragmas
16169  should be placed before and/or after a function, placing pragma's inside
16170  a function body could have unpredictable results.
16171 \layout Verse
16172
16173
16174 \family typewriter 
16175 #pragma save
16176 \begin_inset LatexCommand \index{\#pragma save}
16177
16178 \end_inset 
16179
16180  \SpecialChar ~
16181 \SpecialChar ~
16182 \SpecialChar ~
16183 \SpecialChar ~
16184 \SpecialChar ~
16185 \SpecialChar ~
16186 \SpecialChar ~
16187 /* save the current settings */ 
16188 \newline 
16189 #pragma nogcse
16190 \begin_inset LatexCommand \index{\#pragma nogcse}
16191
16192 \end_inset 
16193
16194  \SpecialChar ~
16195 \SpecialChar ~
16196 \SpecialChar ~
16197 \SpecialChar ~
16198 \SpecialChar ~
16199 /* turnoff global subexpression elimination */ 
16200 \newline 
16201 #pragma noinduction
16202 \begin_inset LatexCommand \index{\#pragma noinduction}
16203
16204 \end_inset 
16205
16206  /* turn off induction optimizations */ 
16207 \newline 
16208 int foo () 
16209 \newline 
16210
16211 \newline 
16212 \SpecialChar ~
16213  \SpecialChar ~
16214  ...
16215  
16216 \newline 
16217 \SpecialChar ~
16218  \SpecialChar ~
16219  /* large code */ 
16220 \newline 
16221 \SpecialChar ~
16222  \SpecialChar ~
16223  ...
16224  
16225 \newline 
16226
16227 \newline 
16228 #pragma restore
16229 \begin_inset LatexCommand \index{\#pragma restore}
16230
16231 \end_inset 
16232
16233  /* turn the optimizations back on */
16234 \layout Standard
16235
16236 The compiler will generate a warning message when extra space is allocated.
16237  It is strongly recommended that the save and restore pragma's be used when
16238  changing options for a function.
16239 \layout Section
16240
16241 Defines Created by the Compiler
16242 \layout Standard
16243
16244 The compiler creates the following #defines
16245 \begin_inset LatexCommand \index{\#defines}
16246
16247 \end_inset 
16248
16249
16250 \begin_inset LatexCommand \index{Defines created by the compiler}
16251
16252 \end_inset 
16253
16254 :
16255 \newline 
16256
16257 \layout Standard
16258
16259
16260 \begin_inset  Tabular
16261 <lyxtabular version="3" rows="11" columns="2">
16262 <features>
16263 <column alignment="left" valignment="top" leftline="true" width="0">
16264 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16265 <row topline="true" bottomline="true">
16266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16267 \begin_inset Text
16268
16269 \layout Standard
16270
16271
16272 \series bold 
16273 #define
16274 \end_inset 
16275 </cell>
16276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16277 \begin_inset Text
16278
16279 \layout Standard
16280
16281
16282 \series bold 
16283 Description
16284 \end_inset 
16285 </cell>
16286 </row>
16287 <row topline="true">
16288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16289 \begin_inset Text
16290
16291 \layout Standard
16292
16293 SDCC
16294 \begin_inset LatexCommand \index{SDCC}
16295
16296 \end_inset 
16297
16298  
16299 \end_inset 
16300 </cell>
16301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16302 \begin_inset Text
16303
16304 \layout Standard
16305
16306 Always defined.
16307  Since version 2.5.6 the version number as an int (ex.
16308  256)
16309 \end_inset 
16310 </cell>
16311 </row>
16312 <row topline="true">
16313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16314 \begin_inset Text
16315
16316 \layout Standard
16317
16318 SDCC_mcs51
16319 \begin_inset LatexCommand \index{SDCC\_mcs51}
16320
16321 \end_inset 
16322
16323  or SDCC_ds390
16324 \begin_inset LatexCommand \index{SDCC\_ds390}
16325
16326 \end_inset 
16327
16328  or SDCC_z80
16329 \begin_inset LatexCommand \index{SDCC\_z80}
16330
16331 \end_inset 
16332
16333 , etc
16334 \end_inset 
16335 </cell>
16336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16337 \begin_inset Text
16338
16339 \layout Standard
16340
16341 depending on the model used (e.g.: -mds390
16342 \end_inset 
16343 </cell>
16344 </row>
16345 <row topline="true">
16346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16347 \begin_inset Text
16348
16349 \layout Standard
16350
16351 __mcs51
16352 \begin_inset LatexCommand \index{\_\_mcs51}
16353
16354 \end_inset 
16355
16356 , __ds390
16357 \begin_inset LatexCommand \index{\_\_ds390}
16358
16359 \end_inset 
16360
16361 , __hc08
16362 \begin_inset LatexCommand \index{\_\_hc08}
16363
16364 \end_inset 
16365
16366 , __z80
16367 \begin_inset LatexCommand \index{\_\_z80}
16368
16369 \end_inset 
16370
16371 , etc
16372 \end_inset 
16373 </cell>
16374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16375 \begin_inset Text
16376
16377 \layout Standard
16378
16379 depending on the model used (e.g.
16380  -mz80)
16381 \end_inset 
16382 </cell>
16383 </row>
16384 <row topline="true">
16385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16386 \begin_inset Text
16387
16388 \layout Standard
16389
16390 SDCC_STACK_AUTO
16391 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
16392
16393 \end_inset 
16394
16395
16396 \end_inset 
16397 </cell>
16398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16399 \begin_inset Text
16400
16401 \layout Standard
16402
16403 when 
16404 \emph on 
16405 -
16406 \begin_inset ERT
16407 status Collapsed
16408
16409 \layout Standard
16410
16411 \backslash 
16412 /
16413 \end_inset 
16414
16415 -stack-auto
16416 \emph default 
16417  option is used
16418 \end_inset 
16419 </cell>
16420 </row>
16421 <row topline="true">
16422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16423 \begin_inset Text
16424
16425 \layout Standard
16426
16427 SDCC_MODEL_SMALL
16428 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
16429
16430 \end_inset 
16431
16432
16433 \end_inset 
16434 </cell>
16435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16436 \begin_inset Text
16437
16438 \layout Standard
16439
16440 when 
16441 \emph on 
16442 -
16443 \begin_inset ERT
16444 status Collapsed
16445
16446 \layout Standard
16447
16448 \backslash 
16449 /
16450 \end_inset 
16451
16452 -model-small
16453 \emph default 
16454  is used
16455 \end_inset 
16456 </cell>
16457 </row>
16458 <row topline="true">
16459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16460 \begin_inset Text
16461
16462 \layout Standard
16463
16464 SDCC_MODEL_MEDIUM
16465 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
16466
16467 \end_inset 
16468
16469
16470 \end_inset 
16471 </cell>
16472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16473 \begin_inset Text
16474
16475 \layout Standard
16476
16477 when 
16478 \emph on 
16479 -
16480 \begin_inset ERT
16481 status Collapsed
16482
16483 \layout Standard
16484
16485 \backslash 
16486 /
16487 \end_inset 
16488
16489 -model-medium
16490 \emph default 
16491  is used
16492 \end_inset 
16493 </cell>
16494 </row>
16495 <row topline="true">
16496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16497 \begin_inset Text
16498
16499 \layout Standard
16500
16501 SDCC_MODEL_LARGE
16502 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
16503
16504 \end_inset 
16505
16506
16507 \end_inset 
16508 </cell>
16509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16510 \begin_inset Text
16511
16512 \layout Standard
16513
16514 when 
16515 \emph on 
16516 -
16517 \begin_inset ERT
16518 status Collapsed
16519
16520 \layout Standard
16521
16522 \backslash 
16523 /
16524 \end_inset 
16525
16526 -model-large
16527 \emph default 
16528  is used
16529 \end_inset 
16530 </cell>
16531 </row>
16532 <row topline="true">
16533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16534 \begin_inset Text
16535
16536 \layout Standard
16537
16538 SDCC_USE_XSTACK
16539 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
16540
16541 \end_inset 
16542
16543
16544 \end_inset 
16545 </cell>
16546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16547 \begin_inset Text
16548
16549 \layout Standard
16550
16551 when 
16552 \emph on 
16553 -
16554 \begin_inset ERT
16555 status Collapsed
16556
16557 \layout Standard
16558
16559 \backslash 
16560 /
16561 \end_inset 
16562
16563 -xstack
16564 \emph default 
16565  option is used
16566 \end_inset 
16567 </cell>
16568 </row>
16569 <row topline="true">
16570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16571 \begin_inset Text
16572
16573 \layout Standard
16574
16575 SDCC_STACK_TENBIT
16576 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
16577
16578 \end_inset 
16579
16580  
16581 \end_inset 
16582 </cell>
16583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16584 \begin_inset Text
16585
16586 \layout Standard
16587
16588 when 
16589 \emph on 
16590 -mds390
16591 \emph default 
16592  is used
16593 \end_inset 
16594 </cell>
16595 </row>
16596 <row topline="true" bottomline="true">
16597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16598 \begin_inset Text
16599
16600 \layout Standard
16601
16602 SDCC_MODEL_FLAT24
16603 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
16604
16605 \end_inset 
16606
16607
16608 \end_inset 
16609 </cell>
16610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16611 \begin_inset Text
16612
16613 \layout Standard
16614
16615 when 
16616 \emph on 
16617 -mds390
16618 \emph default 
16619  is used
16620 \end_inset 
16621 </cell>
16622 </row>
16623 </lyxtabular>
16624
16625 \end_inset 
16626
16627
16628 \layout Chapter
16629
16630 Notes on supported Processors
16631 \layout Section
16632
16633 MCS51 variants
16634 \begin_inset LatexCommand \label{sub:MCS51-variants}
16635
16636 \end_inset 
16637
16638
16639 \begin_inset LatexCommand \index{MCS51 variants}
16640
16641 \end_inset 
16642
16643
16644 \layout Standard
16645
16646 MCS51 processors are available from many vendors and come in many different
16647  flavours.
16648  While they might differ considerably in respect to Special Function Registers
16649  the core MCS51 is usually not modified or is kept compatible.
16650  
16651 \layout Subsection
16652
16653 pdata access by SFR 
16654 \layout Standard
16655
16656 With the upcome of devices with internal xdata and flash memory devices
16657  using port P2
16658 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16659
16660 \end_inset 
16661
16662  as dedicated I/O port is becoming more popular.
16663  Switching the high byte for pdata
16664 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16665
16666 \end_inset 
16667
16668  access which was formerly done by port P2 is then achieved by a Special
16669  Function Register
16670 \begin_inset LatexCommand \index{sfr}
16671
16672 \end_inset 
16673
16674 .
16675  In well-established MCS51 tradition the address of this 
16676 \emph on 
16677 sfr
16678 \emph default 
16679  is where the chip designers decided to put it.
16680  Needless to say that they didn't agree on a common name either.
16681  So that the startup code can correctly initialize xdata variables, you
16682  should define an sfr with the name _XPAGE
16683 \family typewriter 
16684
16685 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
16686
16687 \end_inset 
16688
16689
16690 \family default 
16691  at the appropriate location if the default, port P2, is not used for this.
16692  Some examples are:
16693 \layout Verse
16694
16695
16696 \family typewriter 
16697 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
16698 \layout Verse
16699
16700
16701 \family typewriter 
16702 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
16703 \layout Verse
16704
16705
16706 \family typewriter 
16707 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
16708 \layout Standard
16709
16710 For more exotic implementations further customizations may be needed.
16711  See section 
16712 \begin_inset LatexCommand \ref{sub:Startup-Code}
16713
16714 \end_inset 
16715
16716  for other possibilities.
16717 \layout Subsection
16718
16719 Other Features available by SFR
16720 \layout Standard
16721
16722 Some MCS51 variants offer features like Double DPTR
16723 \begin_inset LatexCommand \index{DPTR}
16724
16725 \end_inset 
16726
16727 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
16728  These are currently not used for the MCS51 port.
16729  If you absolutely need them you can fall back to inline assembly or submit
16730  a patch to SDCC.
16731 \layout Section
16732
16733 DS400 port
16734 \layout Standard
16735
16736 The DS80C400 microcontroller has a rich set of peripherals.
16737  In its built-in ROM library it includes functions to access some of the
16738  features, among them is a TCP stack with IP4 and IP6 support.
16739  Library headers (currently in beta status) and other files are provided
16740  at 
16741 \size footnotesize 
16742
16743 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
16744
16745 \end_inset 
16746
16747 .
16748  
16749 \layout Section
16750
16751 The Z80 and gbz80 port
16752 \layout Standard
16753
16754 SDCC can target both the Zilog 
16755 \begin_inset LatexCommand \index{Z80}
16756
16757 \end_inset 
16758
16759  and the Nintendo Gameboy's Z80-like gbz80
16760 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
16761
16762 \end_inset 
16763
16764 .
16765  The Z80 port is passed through the same 
16766 \emph on 
16767 regressions tests
16768 \begin_inset LatexCommand \index{Regression test}
16769
16770 \end_inset 
16771
16772
16773 \emph default 
16774  as the MCS51 and DS390 ports, so floating point support, support for long
16775  variables and bitfield support is fine.
16776  See mailing lists and forums about interrupt routines.
16777 \layout Standard
16778
16779 As always, the code is the authoritative reference - see z80/ralloc.c and
16780  z80/gen.c.
16781  The stack
16782 \begin_inset LatexCommand \index{stack}
16783
16784 \end_inset 
16785
16786  frame is similar to that generated by the IAR Z80 compiler.
16787  IX is used as the base pointer, HL and IY are used as a temporary registers,
16788  and BC and DE are available for holding variables.
16789  Return values
16790 \begin_inset LatexCommand \index{return value}
16791
16792 \end_inset 
16793
16794  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
16795  bytes).
16796  The gbz80 port use the same set of registers for the return values, but
16797  in a different order of significance: E (one byte), DE (two bytes), or
16798  HLDE (four bytes).
16799 \layout Section
16800
16801 The HC08 port
16802 \layout Standard
16803
16804 The port to the Motorola HC08
16805 \begin_inset LatexCommand \index{HC08}
16806
16807 \end_inset 
16808
16809  family has been added in October 2003, and is still undergoing some basic
16810  development.
16811  The code generator is complete, but the register allocation is still quite
16812  unoptimized.
16813  Some of the SDCC's standard C library functions have embedded non-HC08
16814  inline assembly and so are not yet usable.
16815 \newline 
16816
16817 \newline 
16818
16819 \layout Section
16820
16821 The PIC14 port
16822 \layout Standard
16823
16824 The 14bit PIC
16825 \begin_inset LatexCommand \index{PIC14}
16826
16827 \end_inset 
16828
16829  port still requires a major effort from the development community.
16830  However it can work for very simple code.
16831 \layout Subsection
16832
16833 C code and 14bit PIC code page
16834 \begin_inset LatexCommand \index{code page (pic14)}
16835
16836 \end_inset 
16837
16838  and RAM banks
16839 \begin_inset LatexCommand \index{RAM bank (pic14)}
16840
16841 \end_inset 
16842
16843
16844 \layout Standard
16845
16846 The linker organizes allocation for the code page and RAM banks.
16847  It does not have intimate knowledge of the code flow.
16848  It will put all the code section of a single asm file into a single code
16849  page.
16850  In order to make use of multiple code pages, separate asm files must be
16851  used.
16852  The compiler treats all functions of a single C file as being in the same
16853  code page unless it is non static.
16854  The compiler treats all local variables of a single C file as being in
16855  the same RAM bank unless it is an extern.
16856 \newline 
16857
16858 \newline 
16859 To get the best follow these guide lines:
16860 \layout Enumerate
16861
16862 make local functions static, as non static functions require code page selection
16863  overhead.
16864 \layout Enumerate
16865
16866 Make local variables static as extern variables require RAM bank selection
16867  overhead.
16868 \layout Enumerate
16869
16870 For devices that have multiple code pages it is more efficient to use the
16871  same number of files as pages, i.e.
16872  for the 16F877 use 4 separate files and i.e.
16873  for the 16F874 use 2 separate files.
16874  This way the linker can put the code for each file into different code
16875  pages and the compiler can allocate reusable variables more efficiently
16876  and there's less page selection overhead.
16877  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
16878  instruction set) use 'unsigned char' whereever possible instead of 'int'.
16879 \layout Subsection
16880
16881 Creating a device include file 
16882 \layout Standard
16883
16884 For generating a device include file use the support perl script inc2h.pl
16885  kept in directory support/script.
16886 \layout Subsection
16887
16888 Interrupt code
16889 \layout Standard
16890
16891 For the interrupt function, use the keyword 'interrupt'
16892 \begin_inset LatexCommand \index{interrupt}
16893
16894 \end_inset 
16895
16896  with level number of 0 (PIC14 only has 1 interrupt so this number is only
16897  there to avoid a syntax error - it ought to be fixed).
16898  E.g.:
16899 \layout Verse
16900
16901
16902 \family typewriter 
16903 void Intr(void) interrupt 0
16904 \newline 
16905 {
16906 \newline 
16907 \SpecialChar ~
16908 \SpecialChar ~
16909 T0IF = 0; /* Clear timer interrupt */
16910 \newline 
16911 }
16912 \layout Subsection
16913
16914 Linking and assembling
16915 \layout Standard
16916
16917 For assembling you can use either GPUTILS'
16918 \begin_inset LatexCommand \index{gputils (pic tools)}
16919
16920 \end_inset 
16921
16922  gpasm.exe or MPLAB's mpasmwin.exe.
16923  GPUTILS is available from 
16924 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
16925
16926 \end_inset 
16927
16928 .
16929  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
16930  If you use MPLAB and an interrupt function then the linker script file
16931  vectors section will need to be enlarged to link with mplink.
16932 \newline 
16933
16934 \newline 
16935 Here is a 
16936 \family typewriter 
16937 Makefile
16938 \family default 
16939  using GPUTILS:
16940 \layout Verse
16941
16942
16943 \family typewriter 
16944 .c.o:
16945 \newline 
16946 \SpecialChar ~
16947 \SpecialChar ~
16948 \SpecialChar ~
16949 \SpecialChar ~
16950 \SpecialChar ~
16951 \SpecialChar ~
16952 \SpecialChar ~
16953 \SpecialChar ~
16954 sdcc -S -V -mpic14 -p16F877 $< 
16955 \newline 
16956 \SpecialChar ~
16957 \SpecialChar ~
16958 \SpecialChar ~
16959 \SpecialChar ~
16960 \SpecialChar ~
16961 \SpecialChar ~
16962 \SpecialChar ~
16963 \SpecialChar ~
16964 gpasm -c $*.asm
16965 \newline 
16966
16967 \newline 
16968 $(PRJ).hex: $(OBJS) 
16969 \newline 
16970 \SpecialChar ~
16971 \SpecialChar ~
16972 \SpecialChar ~
16973 \SpecialChar ~
16974 \SpecialChar ~
16975 \SpecialChar ~
16976 \SpecialChar ~
16977 \SpecialChar ~
16978 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
16979 \layout Standard
16980
16981 Here is a 
16982 \family typewriter 
16983 Makefile
16984 \family default 
16985  using MPLAB:
16986 \layout Verse
16987
16988
16989 \family typewriter 
16990 .c.o: 
16991 \newline 
16992 \SpecialChar ~
16993 \SpecialChar ~
16994 \SpecialChar ~
16995 \SpecialChar ~
16996 \SpecialChar ~
16997 \SpecialChar ~
16998 \SpecialChar ~
16999 \SpecialChar ~
17000 sdcc -S -V -mpic14 -p16F877 $< 
17001 \newline 
17002 \SpecialChar ~
17003 \SpecialChar ~
17004 \SpecialChar ~
17005 \SpecialChar ~
17006 \SpecialChar ~
17007 \SpecialChar ~
17008 \SpecialChar ~
17009 \SpecialChar ~
17010 mpasmwin /q /o $*.asm
17011 \newline 
17012
17013 \newline 
17014 $(PRJ).hex: $(OBJS) 
17015 \newline 
17016 \SpecialChar ~
17017 \SpecialChar ~
17018 \SpecialChar ~
17019 \SpecialChar ~
17020 \SpecialChar ~
17021 \SpecialChar ~
17022 \SpecialChar ~
17023 \SpecialChar ~
17024 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17025 \layout Standard
17026
17027 Please note that indentations within a
17028 \family typewriter 
17029  Makefile
17030 \family default 
17031  have to be done with a tabulator character.
17032 \layout Subsection
17033
17034 Command-line options
17035 \layout Standard
17036
17037 Besides the switches common to all SDCC backends, the PIC14 port accepts
17038  the following options (for an updated list see sdcc -
17039 \begin_inset ERT
17040 status Collapsed
17041
17042 \layout Standard
17043
17044 \backslash 
17045 /
17046 \end_inset 
17047
17048 -help):
17049 \layout List
17050 \labelwidthstring 00.00.0000
17051
17052 -
17053 \begin_inset ERT
17054 status Collapsed
17055
17056 \layout Standard
17057
17058 \backslash 
17059 /
17060 \end_inset 
17061
17062 -debug-extra emit debug info in assembly output
17063 \layout List
17064 \labelwidthstring 00.00.0000
17065
17066 -
17067 \begin_inset ERT
17068 status Collapsed
17069
17070 \layout Standard
17071
17072 \backslash 
17073 /
17074 \end_inset 
17075
17076 -no-pcode-opt disable (slightly faulty) optimization on pCode
17077 \layout Subsection
17078
17079 The library
17080 \layout Subsubsection
17081
17082 error: missing definition for symbol 
17083 \begin_inset Quotes sld
17084 \end_inset 
17085
17086 __gptrget1
17087 \begin_inset Quotes srd
17088 \end_inset 
17089
17090
17091 \layout Standard
17092
17093 The PIC14 port uses library routines to provide more complex operations
17094  like multiplication, division/modulus and (generic) pointer dereferencing.
17095  In order to add these routines to your project, you must link with PIC14's
17096  
17097 \family typewriter 
17098 libsdcc.lib
17099 \family default 
17100 .
17101  For single source file projects this is done automatically, more complex
17102  projects must add 
17103 \family typewriter 
17104 libsdcc.lib
17105 \family default 
17106  to the linker's arguments.
17107  Make sure you also add an include path for the library (using the -I switch
17108  to the linker)!
17109 \layout Subsubsection
17110
17111 Processor mismatch in file 
17112 \begin_inset Quotes sld
17113 \end_inset 
17114
17115 XXX
17116 \begin_inset Quotes srd
17117 \end_inset 
17118
17119 .
17120 \layout Standard
17121
17122 This warning can usually be ignored due to the very good compatibility amongst
17123  14 bit PIC devices.
17124 \layout Standard
17125
17126 You might also consider recompiling the library for your specific device
17127  by changing the ARCH=p16f877 (default target) entry in 
17128 \family typewriter 
17129 device/lib/pic/Makefile.in
17130 \family default 
17131  and 
17132 \family typewriter 
17133 device/lib/pic/Makefile
17134 \family default 
17135  to reflect your device.
17136  This might even improve performance for smaller devices as unneccesary
17137  BANKSELs migth be removed.
17138 \layout Subsection
17139
17140 Known bugs
17141 \layout Subsubsection
17142
17143 initialized data
17144 \layout Standard
17145
17146 Currently, data can only be initialized if it resides in the source file
17147  together with 
17148 \emph on 
17149 main()
17150 \emph default 
17151 .
17152  Data in other source files will silently 
17153 \series bold 
17154 not
17155 \series default 
17156  be initialized.
17157 \layout Section
17158
17159 The PIC16
17160 \begin_inset LatexCommand \index{PIC16}
17161
17162 \end_inset 
17163
17164  port
17165 \layout Standard
17166
17167 The PIC16
17168 \begin_inset LatexCommand \index{PIC16}
17169
17170 \end_inset 
17171
17172  port is the portion of SDCC that is responsible to produce code for the
17173  Microchip
17174 \begin_inset LatexCommand \index{Microchip}
17175
17176 \end_inset 
17177
17178 (TM) microcontrollers with 16 bit core.
17179  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
17180  Currently supported devices are:
17181 \layout Standard
17182 \align center 
17183
17184 \begin_inset  Tabular
17185 <lyxtabular version="3" rows="4" columns="6">
17186 <features>
17187 <column alignment="center" valignment="top" leftline="true" width="0">
17188 <column alignment="center" valignment="top" leftline="true" width="0">
17189 <column alignment="center" valignment="top" leftline="true" width="0">
17190 <column alignment="center" valignment="top" leftline="true" width="0">
17191 <column alignment="center" valignment="top" leftline="true" width="0">
17192 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17193 <row topline="true">
17194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17195 \begin_inset Text
17196
17197 \layout Standard
17198
17199 18F242
17200 \end_inset 
17201 </cell>
17202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17203 \begin_inset Text
17204
17205 \layout Standard
17206
17207 18F248
17208 \end_inset 
17209 </cell>
17210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17211 \begin_inset Text
17212
17213 \layout Standard
17214
17215 18F252
17216 \end_inset 
17217 </cell>
17218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17219 \begin_inset Text
17220
17221 \layout Standard
17222
17223 18F258
17224 \end_inset 
17225 </cell>
17226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17227 \begin_inset Text
17228
17229 \layout Standard
17230
17231 18F442
17232 \end_inset 
17233 </cell>
17234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17235 \begin_inset Text
17236
17237 \layout Standard
17238
17239 18F448
17240 \end_inset 
17241 </cell>
17242 </row>
17243 <row topline="true">
17244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17245 \begin_inset Text
17246
17247 \layout Standard
17248
17249 18F452
17250 \end_inset 
17251 </cell>
17252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17253 \begin_inset Text
17254
17255 \layout Standard
17256
17257 18F458
17258 \end_inset 
17259 </cell>
17260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17261 \begin_inset Text
17262
17263 \layout Standard
17264
17265 18F1220
17266 \end_inset 
17267 </cell>
17268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17269 \begin_inset Text
17270
17271 \layout Standard
17272
17273 18F2220
17274 \end_inset 
17275 </cell>
17276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17277 \begin_inset Text
17278
17279 \layout Standard
17280
17281 18F2550
17282 \end_inset 
17283 </cell>
17284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17285 \begin_inset Text
17286
17287 \layout Standard
17288
17289 18F4331
17290 \end_inset 
17291 </cell>
17292 </row>
17293 <row topline="true">
17294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17295 \begin_inset Text
17296
17297 \layout Standard
17298
17299 18F4455
17300 \end_inset 
17301 </cell>
17302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17303 \begin_inset Text
17304
17305 \layout Standard
17306
17307 18F6520
17308 \end_inset 
17309 </cell>
17310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17311 \begin_inset Text
17312
17313 \layout Standard
17314
17315 18F6620
17316 \end_inset 
17317 </cell>
17318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17319 \begin_inset Text
17320
17321 \layout Standard
17322
17323 18F6680
17324 \end_inset 
17325 </cell>
17326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17327 \begin_inset Text
17328
17329 \layout Standard
17330
17331 18F6720
17332 \end_inset 
17333 </cell>
17334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17335 \begin_inset Text
17336
17337 \layout Standard
17338
17339 18F8520
17340 \end_inset 
17341 </cell>
17342 </row>
17343 <row topline="true" bottomline="true">
17344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17345 \begin_inset Text
17346
17347 \layout Standard
17348
17349 18F8620
17350 \end_inset 
17351 </cell>
17352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17353 \begin_inset Text
17354
17355 \layout Standard
17356
17357 18F8680
17358 \end_inset 
17359 </cell>
17360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17361 \begin_inset Text
17362
17363 \layout Standard
17364
17365 18F8720
17366 \end_inset 
17367 </cell>
17368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17369 \begin_inset Text
17370
17371 \layout Standard
17372
17373 \end_inset 
17374 </cell>
17375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17376 \begin_inset Text
17377
17378 \layout Standard
17379
17380 \end_inset 
17381 </cell>
17382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17383 \begin_inset Text
17384
17385 \layout Standard
17386
17387 \end_inset 
17388 </cell>
17389 </row>
17390 </lyxtabular>
17391
17392 \end_inset 
17393
17394
17395 \layout Subsection
17396
17397 Global Options
17398 \layout Standard
17399
17400 PIC16 port supports the standard command line arguments as supposed, with
17401  the exception of certain cases that will be mentioned in the following
17402  list:
17403 \layout List
17404 \labelwidthstring 00.00.0000
17405
17406 -
17407 \begin_inset ERT
17408 status Collapsed
17409
17410 \layout Standard
17411
17412 \backslash 
17413 /
17414 \end_inset 
17415
17416 -callee-saves See -
17417 \begin_inset ERT
17418 status Collapsed
17419
17420 \layout Standard
17421
17422 \backslash 
17423 /
17424 \end_inset 
17425
17426 -all-callee-saves
17427 \layout List
17428 \labelwidthstring 00.00.0000
17429
17430 -
17431 \begin_inset ERT
17432 status Collapsed
17433
17434 \layout Standard
17435
17436 \backslash 
17437 /
17438 \end_inset 
17439
17440 -all-callee-saves All function arguments are passed on stack by default.
17441  
17442 \emph on 
17443 There is no need to specify this in the command line.
17444 \layout List
17445 \labelwidthstring 00.00.0000
17446
17447 -
17448 \begin_inset ERT
17449 status Collapsed
17450
17451 \layout Standard
17452
17453 \backslash 
17454 /
17455 \end_inset 
17456
17457 -fommit-frame-pointer Frame pointer will be omitted when the function uses
17458  no local variables.
17459 \layout Subsection
17460
17461 Port Specific Options
17462 \begin_inset LatexCommand \index{Options PIC16}
17463
17464 \end_inset 
17465
17466
17467 \layout Standard
17468
17469 The port specific options appear after the global options in the sdcc --help
17470  output.
17471 \layout Subsubsection
17472
17473 General Options
17474 \layout Standard
17475
17476 General options enable certain port features and optimizations.
17477 \layout List
17478 \labelwidthstring 00.00.0000
17479
17480 -
17481 \begin_inset ERT
17482 status Collapsed
17483
17484 \layout Standard
17485
17486 \backslash 
17487 /
17488 \end_inset 
17489
17490 -stack-model=[model] Used in conjuction with the command above.
17491  Defines the stack model to be used, valid stack models are : 
17492 \begin_deeper 
17493 \layout List
17494 \labelwidthstring 00.00.0000
17495
17496
17497 \emph on 
17498 small
17499 \emph default 
17500  Selects small stack model.
17501  8 bit stack and frame pointers.
17502  Supports 256 bytes stack size.
17503 \layout List
17504 \labelwidthstring 00.00.0000
17505
17506
17507 \emph on 
17508 large
17509 \emph default 
17510  Selects large stack model.
17511  16 bit stack and frame pointers.
17512  Supports 65536 bytes stack size.
17513 \end_deeper 
17514 \layout List
17515 \labelwidthstring 00.00.0000
17516
17517 -
17518 \begin_inset ERT
17519 status Collapsed
17520
17521 \layout Standard
17522
17523 \backslash 
17524 /
17525 \end_inset 
17526
17527 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
17528  unitialized data variables with [kword].
17529  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
17530 \layout List
17531 \labelwidthstring 00.00.0000
17532
17533 -
17534 \begin_inset ERT
17535 status Collapsed
17536
17537 \layout Standard
17538
17539 \backslash 
17540 /
17541 \end_inset 
17542
17543 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
17544  Useful for bootloaders.
17545 \layout List
17546 \labelwidthstring 00.00.0000
17547
17548 -
17549 \begin_inset ERT
17550 status Collapsed
17551
17552 \layout Standard
17553
17554 \backslash 
17555 /
17556 \end_inset 
17557
17558 -asm= sets the full path and name of an external assembler to call.
17559 \layout List
17560 \labelwidthstring 00.00.0000
17561
17562 -
17563 \begin_inset ERT
17564 status Collapsed
17565
17566 \layout Standard
17567
17568 \backslash 
17569 /
17570 \end_inset 
17571
17572 -link= sets the full path and name of an external linker to call.
17573 \layout List
17574 \labelwidthstring 00.00.0000
17575
17576 -
17577 \begin_inset ERT
17578 status Collapsed
17579
17580 \layout Standard
17581
17582 \backslash 
17583 /
17584 \end_inset 
17585
17586 -mplab-comp MPLAB compatibility option.
17587  Currently only suppresses special gpasm directives.
17588 \layout Subsubsection
17589
17590 Optimization Options
17591 \layout List
17592 \labelwidthstring 00.00.0000
17593
17594 -
17595 \begin_inset ERT
17596 status Collapsed
17597
17598 \layout Standard
17599
17600 \backslash 
17601 /
17602 \end_inset 
17603
17604 -optimize-goto Try to use (conditional) BRA instead of GOTO
17605 \layout List
17606 \labelwidthstring 00.00.0000
17607
17608 -
17609 \begin_inset ERT
17610 status Collapsed
17611
17612 \layout Standard
17613
17614 \backslash 
17615 /
17616 \end_inset 
17617
17618 -optimize-cmp Try to optimize some compares.
17619 \layout List
17620 \labelwidthstring 00.00.0000
17621
17622 -
17623 \begin_inset ERT
17624 status Collapsed
17625
17626 \layout Standard
17627
17628 \backslash 
17629 /
17630 \end_inset 
17631
17632 -optimize-df Analyze the dataflow of the generated code and improve it.
17633 \layout List
17634 \labelwidthstring 00.00.0000
17635
17636 -
17637 \begin_inset ERT
17638 status Collapsed
17639
17640 \layout Standard
17641
17642 \backslash 
17643 /
17644 \end_inset 
17645
17646 -obanksel=nn Set optimization level for inserting BANKSELs.
17647 \newline 
17648
17649 \begin_deeper 
17650 \layout List
17651 \labelwidthstring 00.00.0000
17652
17653 0 no optimization
17654 \layout List
17655 \labelwidthstring 00.00.0000
17656
17657 1 checks previous used register and if it is the same then does not emit
17658  BANKSEL, accounts only for labels.
17659 \layout List
17660 \labelwidthstring 00.00.0000
17661
17662 2 tries to check the location of (even different) symbols and removes BANKSELs
17663  if they are in the same bank.
17664  
17665 \newline 
17666
17667 \emph on 
17668 Important: There might be problems if the linker script has data sections
17669  across bank borders!
17670 \end_deeper 
17671 \layout Subsubsection
17672
17673 Linking Options
17674 \layout List
17675 \labelwidthstring 00.00.0000
17676
17677 -
17678 \begin_inset ERT
17679 status Collapsed
17680
17681 \layout Standard
17682
17683 \backslash 
17684 /
17685 \end_inset 
17686
17687 -nodefaultlibs do not link default libraries when linking
17688 \layout List
17689 \labelwidthstring 00.00.0000
17690
17691 -
17692 \begin_inset ERT
17693 status Collapsed
17694
17695 \layout Standard
17696
17697 \backslash 
17698 /
17699 \end_inset 
17700
17701 -no-crt Don't link the default run-time modules
17702 \layout List
17703 \labelwidthstring 00.00.0000
17704
17705 -
17706 \begin_inset ERT
17707 status Collapsed
17708
17709 \layout Standard
17710
17711 \backslash 
17712 /
17713 \end_inset 
17714
17715 -use-crt= Use a custom run-time module instead of the defaults.
17716 \layout Subsubsection
17717
17718 Debugging Options
17719 \layout Standard
17720
17721 Debugging options enable extra debugging information in the output files.
17722 \layout List
17723 \labelwidthstring 00.00.0000
17724
17725 -
17726 \begin_inset ERT
17727 status Collapsed
17728
17729 \layout Standard
17730
17731 \backslash 
17732 /
17733 \end_inset 
17734
17735 -debug-xtra Similar to -
17736 \begin_inset ERT
17737 status Collapsed
17738
17739 \layout Standard
17740
17741 \backslash 
17742 /
17743 \end_inset 
17744
17745 -debug
17746 \begin_inset LatexCommand \index{-\/-debug}
17747
17748 \end_inset 
17749
17750 , but dumps more information.
17751 \layout List
17752 \labelwidthstring 00.00.0000
17753
17754 -
17755 \begin_inset ERT
17756 status Collapsed
17757
17758 \layout Standard
17759
17760 \backslash 
17761 /
17762 \end_inset 
17763
17764 -debug-ralloc Force register allocator to dump <source>.d file with debugging
17765  information.
17766  <source> is the name of the file compiled.
17767 \layout List
17768 \labelwidthstring 00.00.0000
17769
17770 -
17771 \begin_inset ERT
17772 status Collapsed
17773
17774 \layout Standard
17775
17776 \backslash 
17777 /
17778 \end_inset 
17779
17780 -pcode-verbose Enable pcode debugging information in translation.
17781 \layout List
17782 \labelwidthstring 00.00.0000
17783
17784 -
17785 \begin_inset ERT
17786 status Collapsed
17787
17788 \layout Standard
17789
17790 \backslash 
17791 /
17792 \end_inset 
17793
17794 -denable-peeps Force the usage of peepholes.
17795  Use with care.
17796 \layout List
17797 \labelwidthstring 00.00.0000
17798
17799 -
17800 \begin_inset ERT
17801 status Collapsed
17802
17803 \layout Standard
17804
17805 \backslash 
17806 /
17807 \end_inset 
17808
17809 -gstack Trace push/pops for stack pointer overflow
17810 \layout List
17811 \labelwidthstring 00.00.0000
17812
17813 -
17814 \begin_inset ERT
17815 status Collapsed
17816
17817 \layout Standard
17818
17819 \backslash 
17820 /
17821 \end_inset 
17822
17823 -call-tree dump call tree in .calltree file
17824 \layout Subsection
17825
17826 Enviromental Variables
17827 \layout Standard
17828
17829 There is a number of enviromental variables that can be used when running
17830  SDCC to enable certain optimizations or force a specific program behaviour.
17831  these variables are primarily for debugging purposes so they can be enabled/dis
17832 abled at will.
17833 \layout Standard
17834
17835 Currently there is only two such variables available:
17836 \layout List
17837 \labelwidthstring 00.00.0000
17838
17839 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
17840  bitfields is optimized by directly loading FSR0 with the address of the
17841  bitfield structure.
17842  Normally SDCC will cast the bitfield structure to a bitfield pointer and
17843  then load FSR0.
17844  This step saves data ram and code space for functions that perform heavy
17845  use of bitfields.
17846  (ie.
17847  80 bytes of code space are saved when compiling malloc.c with this option).
17848  
17849 \layout List
17850 \labelwidthstring 00.00.0000
17851
17852 NO_REG_OPT do not perform pCode registers optimization.
17853  This should be used for debugging purposes.
17854  In some where bugs in the pcode optimizer are found, users can benefit
17855  from temporarily disabling the optimizer until the bug is fixed.
17856 \layout Subsection
17857
17858 Preprocessor Macros
17859 \layout Standard
17860
17861 PIC16 port defines the following preprocessor macros while translating a
17862  source.
17863 \layout Standard
17864 \align center 
17865
17866 \begin_inset  Tabular
17867 <lyxtabular version="3" rows="6" columns="2">
17868 <features>
17869 <column alignment="center" valignment="top" leftline="true" width="0">
17870 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17871 <row topline="true" bottomline="true">
17872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17873 \begin_inset Text
17874
17875 \layout Standard
17876
17877 Macro
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 Description
17886 \end_inset 
17887 </cell>
17888 </row>
17889 <row topline="true">
17890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17891 \begin_inset Text
17892
17893 \layout Standard
17894
17895 SDCC_pic16
17896 \end_inset 
17897 </cell>
17898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17899 \begin_inset Text
17900
17901 \layout Standard
17902
17903 Port identification
17904 \end_inset 
17905 </cell>
17906 </row>
17907 <row topline="true">
17908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17909 \begin_inset Text
17910
17911 \layout Standard
17912
17913 _
17914 \begin_inset ERT
17915 status Collapsed
17916
17917 \layout Standard
17918
17919 \backslash 
17920 /
17921 \end_inset 
17922
17923 _pic16
17924 \end_inset 
17925 </cell>
17926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17927 \begin_inset Text
17928
17929 \layout Standard
17930
17931 Port identification (same as above)
17932 \end_inset 
17933 </cell>
17934 </row>
17935 <row topline="true">
17936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17937 \begin_inset Text
17938
17939 \layout Standard
17940
17941 pic18fxxxx
17942 \end_inset 
17943 </cell>
17944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17945 \begin_inset Text
17946
17947 \layout Standard
17948
17949 MCU Identification.
17950  
17951 \emph on 
17952 xxxx
17953 \emph default 
17954  is the microcontrol identification number, i.e.
17955  452, 6620, etc
17956 \end_inset 
17957 </cell>
17958 </row>
17959 <row topline="true">
17960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17961 \begin_inset Text
17962
17963 \layout Standard
17964
17965 _
17966 \begin_inset ERT
17967 status Collapsed
17968
17969 \layout Standard
17970
17971 \backslash 
17972 /
17973 \end_inset 
17974
17975 _18Fxxxx
17976 \end_inset 
17977 </cell>
17978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17979 \begin_inset Text
17980
17981 \layout Standard
17982
17983 MCU Identification (same as above)
17984 \end_inset 
17985 </cell>
17986 </row>
17987 <row topline="true" bottomline="true">
17988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17989 \begin_inset Text
17990
17991 \layout Standard
17992
17993 STACK_MODEL_nnn
17994 \end_inset 
17995 </cell>
17996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17997 \begin_inset Text
17998
17999 \layout Standard
18000
18001 nnn = SMALL or LARGE respectively according to the stack model used
18002 \end_inset 
18003 </cell>
18004 </row>
18005 </lyxtabular>
18006
18007 \end_inset 
18008
18009
18010 \layout Standard
18011
18012 In addition the following macros are defined when calling assembler:
18013 \layout Standard
18014 \align center 
18015
18016 \begin_inset  Tabular
18017 <lyxtabular version="3" rows="4" columns="2">
18018 <features>
18019 <column alignment="center" valignment="top" leftline="true" width="0">
18020 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18021 <row topline="true" bottomline="true">
18022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18023 \begin_inset Text
18024
18025 \layout Standard
18026
18027 Macro
18028 \end_inset 
18029 </cell>
18030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18031 \begin_inset Text
18032
18033 \layout Standard
18034
18035 Description
18036 \end_inset 
18037 </cell>
18038 </row>
18039 <row topline="true">
18040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18041 \begin_inset Text
18042
18043 \layout Standard
18044
18045 __18Fxxxx
18046 \end_inset 
18047 </cell>
18048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18049 \begin_inset Text
18050
18051 \layout Standard
18052
18053 MCU Identification.
18054  
18055 \emph on 
18056 xxxx
18057 \emph default 
18058  is the microcontrol identification number, i.e.
18059  452, 6620, etc
18060 \end_inset 
18061 </cell>
18062 </row>
18063 <row topline="true">
18064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18065 \begin_inset Text
18066
18067 \layout Standard
18068
18069 SDCC_MODEL_nnn
18070 \end_inset 
18071 </cell>
18072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18073 \begin_inset Text
18074
18075 \layout Standard
18076
18077 nnn = SMALL or LARGE respectively according to the memory model used for
18078  SDCC
18079 \end_inset 
18080 </cell>
18081 </row>
18082 <row topline="true" bottomline="true">
18083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18084 \begin_inset Text
18085
18086 \layout Standard
18087
18088 STACK_MODEL_nnn
18089 \end_inset 
18090 </cell>
18091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18092 \begin_inset Text
18093
18094 \layout Standard
18095
18096 nnn = SMALL or LARGE respectively according to the stack model used
18097 \end_inset 
18098 </cell>
18099 </row>
18100 </lyxtabular>
18101
18102 \end_inset 
18103
18104
18105 \layout Subsection
18106
18107 Directories
18108 \layout Standard
18109
18110 PIC16
18111 \begin_inset LatexCommand \index{PIC16}
18112
18113 \end_inset 
18114
18115  port uses the following directories for searching header files and libraries.
18116 \layout Standard
18117 \align center 
18118
18119 \begin_inset  Tabular
18120 <lyxtabular version="3" rows="3" columns="4">
18121 <features>
18122 <column alignment="center" valignment="top" leftline="true" width="0">
18123 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18124 <column alignment="center" valignment="top" width="0">
18125 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18126 <row topline="true" bottomline="true">
18127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18128 \begin_inset Text
18129
18130 \layout Standard
18131
18132 Directory
18133 \end_inset 
18134 </cell>
18135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18136 \begin_inset Text
18137
18138 \layout Standard
18139
18140 Description
18141 \end_inset 
18142 </cell>
18143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18144 \begin_inset Text
18145
18146 \layout Standard
18147
18148 Target
18149 \end_inset 
18150 </cell>
18151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18152 \begin_inset Text
18153
18154 \layout Standard
18155
18156 Command prefix
18157 \end_inset 
18158 </cell>
18159 </row>
18160 <row topline="true">
18161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18162 \begin_inset Text
18163
18164 \layout Standard
18165
18166 PREFIX/sdcc/include/pic16
18167 \end_inset 
18168 </cell>
18169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18170 \begin_inset Text
18171
18172 \layout Standard
18173
18174 PIC16 specific headers
18175 \end_inset 
18176 </cell>
18177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18178 \begin_inset Text
18179
18180 \layout Standard
18181
18182 Compiler
18183 \end_inset 
18184 </cell>
18185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18186 \begin_inset Text
18187
18188 \layout Standard
18189
18190 -I
18191 \end_inset 
18192 </cell>
18193 </row>
18194 <row topline="true" bottomline="true">
18195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18196 \begin_inset Text
18197
18198 \layout Standard
18199
18200 PREFIX/sdcc/lib/pic16
18201 \end_inset 
18202 </cell>
18203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18204 \begin_inset Text
18205
18206 \layout Standard
18207
18208 PIC16 specific libraries
18209 \end_inset 
18210 </cell>
18211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18212 \begin_inset Text
18213
18214 \layout Standard
18215
18216 Linker
18217 \end_inset 
18218 </cell>
18219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18220 \begin_inset Text
18221
18222 \layout Standard
18223
18224 -L
18225 \end_inset 
18226 </cell>
18227 </row>
18228 </lyxtabular>
18229
18230 \end_inset 
18231
18232
18233 \layout Subsection
18234
18235 Pragmas
18236 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
18237
18238 \end_inset 
18239
18240
18241 \layout Standard
18242
18243 PIC16 port currently supports the following pragmas:
18244 \layout List
18245 \labelwidthstring 00.00.0000
18246
18247 stack pragma stack forces the code generator to initialize the stack & frame
18248  pointers at a specific address.
18249  This is an adhoc solution for cases where no STACK directive is available
18250  in the linker script or gplink is not instructed to create a stack section.
18251 \newline 
18252 The stack pragma should be used only once in a project.
18253  Multiple pragmas may result in indeterminate behaviour of the program.
18254 \begin_inset Foot
18255 collapsed false
18256
18257 \layout Standard
18258
18259 The old format (ie.
18260  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
18261  cross page boundaries (or even exceed the available data RAM) and crash
18262  the program.
18263  Make sure that stack does not cross page boundaries when using the SMALL
18264  stack model.
18265 \end_inset 
18266
18267
18268 \newline 
18269 The format is as follows:
18270 \layout LyX-Code
18271
18272 #pragma stack bottom_address [stack_size]
18273 \layout Standard
18274
18275
18276 \emph on 
18277 bottom_address
18278 \emph default 
18279  is the lower bound of the stack section.
18280  The stack pointer initially will point at address (bottom_address+stack_size-1).
18281 \layout LyX-Code
18282
18283 Example:
18284 \layout LyX-Code
18285
18286 \layout LyX-Code
18287
18288 /* initializes stack of 100 bytes at RAM address 0x200 */
18289 \layout LyX-Code
18290
18291 #pragma stack 0x200 100
18292 \layout Standard
18293
18294 If the stack_size field is omitted then a stack is created with the default
18295  size of 64.
18296  This size might be enough for most programs, but its not enough for operations
18297  with deep function nesting or excessive stack usage.
18298 \layout List
18299 \labelwidthstring 00.00.0000
18300
18301 wparam 
18302 \emph on 
18303 This pragma is deprecated.
18304  Its use will cause a warning message to be issued.
18305 \emph default 
18306
18307 \newline 
18308
18309 \layout List
18310 \labelwidthstring 00.00.0000
18311
18312 code place a function symbol at static FLASH address
18313 \layout LyX-Code
18314
18315 Example:
18316 \layout LyX-Code
18317
18318 \layout LyX-Code
18319
18320 /* place function test_func at 0x4000 */
18321 \layout LyX-Code
18322
18323 #pragma code test_func 0x4000
18324 \layout LyX-Code
18325
18326 \layout List
18327 \labelwidthstring 00.00.0000
18328
18329 library instructs the linker to use a library module.
18330 \newline 
18331 Usage:
18332 \layout LyX-Code
18333
18334 #pragma library module_name
18335 \layout Standard
18336
18337
18338 \emph on 
18339 module_name
18340 \emph default 
18341  can be any library or object file (including its path).
18342  Note that there are four reserved keywords which have special meaning.
18343  These are:
18344 \layout Standard
18345 \align center 
18346
18347 \begin_inset  Tabular
18348 <lyxtabular version="3" rows="6" columns="3">
18349 <features>
18350 <column alignment="center" valignment="top" leftline="true" width="0">
18351 <column alignment="block" valignment="top" leftline="true" width="20page%">
18352 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18353 <row topline="true" bottomline="true">
18354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18355 \begin_inset Text
18356
18357 \layout Standard
18358
18359 Keyword
18360 \end_inset 
18361 </cell>
18362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18363 \begin_inset Text
18364
18365 \layout Standard
18366
18367 Description
18368 \end_inset 
18369 </cell>
18370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18371 \begin_inset Text
18372
18373 \layout Standard
18374
18375 Module to link
18376 \end_inset 
18377 </cell>
18378 </row>
18379 <row topline="true">
18380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18381 \begin_inset Text
18382
18383 \layout Standard
18384
18385
18386 \series bold 
18387 ignore
18388 \end_inset 
18389 </cell>
18390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18391 \begin_inset Text
18392
18393 \layout Standard
18394
18395 ignore all library pragmas
18396 \end_inset 
18397 </cell>
18398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18399 \begin_inset Text
18400
18401 \layout Standard
18402
18403
18404 \emph on 
18405 (none)
18406 \end_inset 
18407 </cell>
18408 </row>
18409 <row topline="true">
18410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18411 \begin_inset Text
18412
18413 \layout Standard
18414
18415
18416 \series bold 
18417 c
18418 \end_inset 
18419 </cell>
18420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18421 \begin_inset Text
18422
18423 \layout Standard
18424
18425 link the C library
18426 \end_inset 
18427 </cell>
18428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18429 \begin_inset Text
18430
18431 \layout Standard
18432
18433
18434 \emph on 
18435 libc18f
18436 \emph default 
18437 .lib
18438 \end_inset 
18439 </cell>
18440 </row>
18441 <row topline="true">
18442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18443 \begin_inset Text
18444
18445 \layout Standard
18446
18447
18448 \series bold 
18449 math
18450 \end_inset 
18451 </cell>
18452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18453 \begin_inset Text
18454
18455 \layout Standard
18456
18457 link the Math libarary
18458 \end_inset 
18459 </cell>
18460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18461 \begin_inset Text
18462
18463 \layout Standard
18464
18465
18466 \emph on 
18467 libm18f
18468 \emph default 
18469 .lib
18470 \end_inset 
18471 </cell>
18472 </row>
18473 <row topline="true">
18474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18475 \begin_inset Text
18476
18477 \layout Standard
18478
18479
18480 \series bold 
18481 io
18482 \end_inset 
18483 </cell>
18484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18485 \begin_inset Text
18486
18487 \layout Standard
18488
18489 link the I/O library
18490 \end_inset 
18491 </cell>
18492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18493 \begin_inset Text
18494
18495 \layout Standard
18496
18497
18498 \emph on 
18499 libio18f*
18500 \emph default 
18501 .lib
18502 \end_inset 
18503 </cell>
18504 </row>
18505 <row topline="true" bottomline="true">
18506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18507 \begin_inset Text
18508
18509 \layout Standard
18510
18511
18512 \series bold 
18513 debug
18514 \end_inset 
18515 </cell>
18516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18517 \begin_inset Text
18518
18519 \layout Standard
18520
18521 link the debug library
18522 \end_inset 
18523 </cell>
18524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18525 \begin_inset Text
18526
18527 \layout Standard
18528
18529
18530 \emph on 
18531 libdebug
18532 \emph default 
18533 .lib
18534 \end_inset 
18535 </cell>
18536 </row>
18537 </lyxtabular>
18538
18539 \end_inset 
18540
18541
18542 \newline 
18543 * is the device number, i.e.
18544  452 for PIC18F452 MCU.
18545 \layout Standard
18546
18547 This feature allows for linking with specific libraries withoug having to
18548  explicit name them in the command line.
18549  Note that the 
18550 \noun on 
18551 ignore
18552 \noun default 
18553  keyword will reject all modules specified by the library pragma.
18554 \layout List
18555 \labelwidthstring 00.00.0000
18556
18557 udata pragma udata instructs the compiler to emit code so that linker will
18558  place a variable at a specific memory bank
18559 \layout LyX-Code
18560
18561 Example:
18562 \layout LyX-Code
18563
18564 \layout LyX-Code
18565
18566 /* places variable foo at bank2 */
18567 \layout LyX-Code
18568
18569 #pragma udata bank2 foo
18570 \layout LyX-Code
18571
18572 char foo;
18573 \layout Standard
18574
18575 In order for this pragma to work extra SECTION directives should be added
18576  in the .lkr script.
18577  In the following example a sample .lkr file is shown:
18578 \layout LyX-Code
18579
18580 \layout LyX-Code
18581
18582 // Sample linker script for the PIC18F452 processor
18583 \layout LyX-Code
18584
18585 LIBPATH .
18586 \layout LyX-Code
18587
18588 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
18589 \layout LyX-Code
18590
18591 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
18592 \layout LyX-Code
18593
18594 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
18595 \layout LyX-Code
18596
18597 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
18598 \layout LyX-Code
18599
18600 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
18601 \layout LyX-Code
18602
18603 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
18604 \layout LyX-Code
18605
18606 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
18607 \layout LyX-Code
18608
18609 \layout LyX-Code
18610
18611 DATABANK   NAME=gpr0       START=0x80           END=0xFF
18612 \layout LyX-Code
18613
18614 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
18615 \layout LyX-Code
18616
18617 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
18618 \layout LyX-Code
18619
18620 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
18621 \layout LyX-Code
18622
18623 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
18624 \layout LyX-Code
18625
18626 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
18627 \layout LyX-Code
18628
18629 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
18630 \layout LyX-Code
18631
18632 \layout LyX-Code
18633
18634 SECTION    NAME=CONFIG     ROM=config
18635 \layout LyX-Code
18636
18637 \layout LyX-Code
18638
18639 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
18640 \layout LyX-Code
18641
18642 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
18643 \layout LyX-Code
18644
18645 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
18646 \layout LyX-Code
18647
18648 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
18649 \layout LyX-Code
18650
18651 SECTION    NAME=bank4      RAM=gpr4
18652 \layout LyX-Code
18653
18654 SECTION    NAME=bank5      RAM=gpr5
18655 \layout Standard
18656
18657 The linker will recognise the section name set in the pragma statement and
18658  will position the variable at the memory bank set with the RAM field at
18659  the SECTION line in the linker script file.
18660 \layout Subsection
18661
18662 Header Files
18663 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
18664
18665 \end_inset 
18666
18667
18668 \layout Standard
18669
18670 There is one main header file that can be included to the source files using
18671  the pic16 port.
18672  That file is the 
18673 \series bold 
18674 pic18fregs.h
18675 \series default 
18676 .
18677  This header file contains the definitions for the processor special registers,
18678  so it is necessary if the source accesses them.
18679  It can be included by adding the following line in the beginning of the
18680  file:
18681 \layout LyX-Code
18682
18683 #include <pic18fregs.h>
18684 \layout Standard
18685
18686 The specific microcontroller is selected within the pic18fregs.h automatically,
18687  so the same source can be used with a variety of devices.
18688 \layout Subsection
18689
18690 Libraries
18691 \layout Standard
18692
18693 The libraries that PIC16
18694 \begin_inset LatexCommand \index{PIC16}
18695
18696 \end_inset 
18697
18698  port depends on are the microcontroller device libraries which contain
18699  the symbol definitions for the microcontroller special function registers.
18700  These libraries have the format pic18fxxxx.lib, where 
18701 \emph on 
18702 xxxx
18703 \emph default 
18704  is the microcontroller identification number.
18705  The specific library is selected automatically by the compiler at link
18706  stage according to the selected device.
18707 \layout Standard
18708
18709 Libraries are created with gplib which is part of the gputils package 
18710 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
18711
18712 \end_inset 
18713
18714 .
18715 \layout Subsubsection*
18716
18717 Building the libraries
18718 \layout Standard
18719
18720 Before using SDCC/pic16 there are some libraries that need to be compiled.
18721  This process is not done automatically by SDCC since not all users use
18722  SDCC for pic16 projects.
18723  So each user should compile the libraries separately.
18724 \layout Standard
18725
18726 The steps to compile the pic16 libraries under Linux are:
18727 \layout LyX-Code
18728
18729 cd device/lib/pic16
18730 \layout LyX-Code
18731
18732 ./configure
18733 \layout LyX-Code
18734
18735 make
18736 \layout LyX-Code
18737
18738 cd ..
18739 \layout LyX-Code
18740
18741 make model-pic16
18742 \layout LyX-Code
18743
18744 su -c 'make install'     # install the libraries, you need the root password
18745 \layout Standard
18746
18747 If you need to install the headers too, do:
18748 \layout LyX-Code
18749
18750 cd device/include
18751 \layout LyX-Code
18752
18753 su -c 'make install'     # install the headers, you need the root password
18754 \layout Standard
18755
18756 There exist a special target to build the I/O libraries.
18757  This target is not automatically build because it will build the I/O library
18758  for 
18759 \emph on 
18760 every
18761 \emph default 
18762  supported device.
18763  This way building will take quite a lot of time.
18764  Users are advised to edit the 
18765 \series bold 
18766 device/lib/pic16/pics.build
18767 \series default 
18768  file and then execute:
18769 \layout LyX-Code
18770
18771 make lib-io
18772 \layout Subsection
18773
18774 Memory Models
18775 \layout Standard
18776
18777 The following memory models are supported by the PIC16 port:
18778 \layout Itemize
18779
18780 small model
18781 \layout Itemize
18782
18783 large model
18784 \layout Standard
18785
18786 Memory model affects the default size of pointers within the source.
18787  The sizes are shown in the next table:
18788 \layout Standard
18789 \align center 
18790
18791 \begin_inset  Tabular
18792 <lyxtabular version="3" rows="3" columns="3">
18793 <features>
18794 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18795 <column alignment="center" valignment="top" leftline="true" width="0">
18796 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18797 <row topline="true" bottomline="true">
18798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18799 \begin_inset Text
18800
18801 \layout Standard
18802
18803 Pointer sizes according to memory model
18804 \end_inset 
18805 </cell>
18806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18807 \begin_inset Text
18808
18809 \layout Standard
18810
18811 small model
18812 \end_inset 
18813 </cell>
18814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18815 \begin_inset Text
18816
18817 \layout Standard
18818
18819 large model
18820 \end_inset 
18821 </cell>
18822 </row>
18823 <row topline="true" bottomline="true">
18824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18825 \begin_inset Text
18826
18827 \layout Standard
18828
18829 code pointers
18830 \end_inset 
18831 </cell>
18832 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18833 \begin_inset Text
18834
18835 \layout Standard
18836
18837 16-bits
18838 \end_inset 
18839 </cell>
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18841 \begin_inset Text
18842
18843 \layout Standard
18844
18845 24-bits
18846 \end_inset 
18847 </cell>
18848 </row>
18849 <row topline="true" bottomline="true">
18850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18851 \begin_inset Text
18852
18853 \layout Standard
18854
18855 data pointers
18856 \end_inset 
18857 </cell>
18858 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
18859 \begin_inset Text
18860
18861 \layout Standard
18862
18863 16-bits
18864 \end_inset 
18865 </cell>
18866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18867 \begin_inset Text
18868
18869 \layout Standard
18870
18871 16-bits
18872 \end_inset 
18873 </cell>
18874 </row>
18875 </lyxtabular>
18876
18877 \end_inset 
18878
18879
18880 \layout Standard
18881
18882 It is advisable that all sources within a project are compiled with the
18883  same memory model.
18884  If one wants to override the default memory model, this can be done by
18885  declaring a pointer as 
18886 \series bold 
18887 far
18888 \series default 
18889  or 
18890 \series bold 
18891 near
18892 \series default 
18893 .
18894  Far selects large memory model's pointers, while near selects small memory
18895  model's pointers.
18896 \layout Standard
18897
18898 The standard device libraries (see 
18899 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
18900
18901 \end_inset 
18902
18903 ) contain no reference to pointers, so they can be used with both memory
18904  models.
18905 \layout Subsection
18906
18907 Stack
18908 \layout Standard
18909
18910 The stack implementation for the PIC16 port uses two indirect registers,
18911  FSR1 and FSR2.
18912 \layout List
18913 \labelwidthstring 00.00.0000
18914
18915 FSR1 is assigned as stack pointer
18916 \layout List
18917 \labelwidthstring 00.00.0000
18918
18919 FSR2 is assigned as frame pointer
18920 \layout Standard
18921
18922 The following stack models are supported by the PIC16 port
18923 \layout Itemize
18924
18925
18926 \noun on 
18927 small
18928 \noun default 
18929  model
18930 \layout Itemize
18931
18932
18933 \noun on 
18934 large
18935 \noun default 
18936  model
18937 \layout Standard
18938
18939
18940 \noun on 
18941 Small
18942 \noun default 
18943  model means that only the FSRxL byte is used to access stack and frame,
18944  while 
18945 \emph on 
18946 \noun on 
18947 large
18948 \emph default 
18949 \noun default 
18950  uses both FSRxL and FSRxH registers.
18951  The following table shows the stack/frame pointers sizes according to stack
18952  model and the maximum space they can address:
18953 \layout Standard
18954 \align center 
18955
18956 \begin_inset  Tabular
18957 <lyxtabular version="3" rows="3" columns="3">
18958 <features>
18959 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18960 <column alignment="center" valignment="top" leftline="true" width="0">
18961 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18962 <row topline="true" bottomline="true">
18963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18964 \begin_inset Text
18965
18966 \layout Standard
18967
18968 Stack & Frame pointer sizes according to stack model
18969 \end_inset 
18970 </cell>
18971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18972 \begin_inset Text
18973
18974 \layout Standard
18975
18976 small
18977 \end_inset 
18978 </cell>
18979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18980 \begin_inset Text
18981
18982 \layout Standard
18983
18984 large
18985 \end_inset 
18986 </cell>
18987 </row>
18988 <row topline="true">
18989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18990 \begin_inset Text
18991
18992 \layout Standard
18993
18994 Stack pointer FSR1
18995 \end_inset 
18996 </cell>
18997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18998 \begin_inset Text
18999
19000 \layout Standard
19001
19002 8-bits
19003 \end_inset 
19004 </cell>
19005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19006 \begin_inset Text
19007
19008 \layout Standard
19009
19010 16-bits
19011 \end_inset 
19012 </cell>
19013 </row>
19014 <row topline="true" bottomline="true">
19015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19016 \begin_inset Text
19017
19018 \layout Standard
19019
19020 Frame pointer FSR2
19021 \end_inset 
19022 </cell>
19023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19024 \begin_inset Text
19025
19026 \layout Standard
19027
19028 8-bits
19029 \end_inset 
19030 </cell>
19031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19032 \begin_inset Text
19033
19034 \layout Standard
19035
19036 16-bits
19037 \end_inset 
19038 </cell>
19039 </row>
19040 </lyxtabular>
19041
19042 \end_inset 
19043
19044
19045 \layout Standard
19046
19047
19048 \noun on 
19049 Large 
19050 \noun default 
19051 stack model is currently not working properly throughout the code generator.
19052  So its use is not advised.
19053  Also there are some other points that need special care:
19054 \newline 
19055
19056 \layout Enumerate
19057
19058 Do not create stack sections with size more than one physical bank (that
19059  is 256 bytes)
19060 \layout Enumerate
19061
19062 Stack sections should no cross physical bank limits (i.e.
19063  #pragma stack 0x50 0x100)
19064 \layout Standard
19065
19066 These limitations are caused by the fact that only FSRxL is modified when
19067  using SMALL stack model, so no more than 256 bytes of stack can be used.
19068  This problem will disappear after LARGE model is fully implemented.
19069 \layout Subsection
19070
19071 Functions
19072 \layout Standard
19073
19074 In addition to the standard SDCC function keywords, PIC16 port makes available
19075  two more:
19076 \layout List
19077 \labelwidthstring 00.00.0000
19078
19079 wparam Use the WREG to pass one byte of the first function argument.
19080  This improves speed but you may not use this for functions with arguments
19081  that are called via function pointers, otherwise the first byte of the
19082  first parameter will get lost.
19083  Usage:
19084 \layout LyX-Code
19085
19086 void func_wparam(int a) wparam
19087 \layout LyX-Code
19088
19089 {
19090 \layout LyX-Code
19091
19092     /* WREG hold the lower part of a */
19093 \layout LyX-Code
19094
19095     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
19096  */
19097 \layout LyX-Code
19098
19099 ...
19100 \layout LyX-Code
19101
19102 }
19103 \layout Standard
19104
19105 This keyword replaces the deprecated wparam pragma.
19106 \layout List
19107 \labelwidthstring 00.00.0000
19108
19109 shadowregs When entering/exiting an ISR, it is possible to take advantage
19110  of the PIC18F hardware shadow registers which hold the values of WREG,
19111  STATUS and BSR registers.
19112  This can be done by adding the keyword 
19113 \emph on 
19114 shadowregs
19115 \emph default 
19116  before the 
19117 \emph on 
19118 interrupt
19119 \emph default 
19120  keyword in the function's header.
19121 \layout LyX-Code
19122
19123 void isr_shadow(void) shadowregs interrupt 1
19124 \layout LyX-Code
19125
19126 {
19127 \layout LyX-Code
19128
19129 ...
19130 \layout LyX-Code
19131
19132 }
19133 \layout Standard
19134
19135
19136 \emph on 
19137 shadowregs
19138 \emph default 
19139  instructs the code generator not to store/restore WREG, STATUS, BSR when
19140  entering/exiting the ISR.
19141 \layout Subsection
19142
19143 Function return values
19144 \layout Standard
19145
19146 Return values from functions are placed to the appropriate registers following
19147  a modified Microchip policy optimized for SDCC.
19148  The following table shows these registers:
19149 \layout Standard
19150 \align center 
19151
19152 \begin_inset  Tabular
19153 <lyxtabular version="3" rows="6" columns="2">
19154 <features>
19155 <column alignment="center" valignment="top" leftline="true" width="0">
19156 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19157 <row topline="true" bottomline="true">
19158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19159 \begin_inset Text
19160
19161 \layout Standard
19162
19163 size
19164 \end_inset 
19165 </cell>
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19167 \begin_inset Text
19168
19169 \layout Standard
19170
19171 destination register
19172 \end_inset 
19173 </cell>
19174 </row>
19175 <row topline="true">
19176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19177 \begin_inset Text
19178
19179 \layout Standard
19180
19181 8 bits
19182 \end_inset 
19183 </cell>
19184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19185 \begin_inset Text
19186
19187 \layout Standard
19188
19189 WREG
19190 \end_inset 
19191 </cell>
19192 </row>
19193 <row topline="true">
19194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19195 \begin_inset Text
19196
19197 \layout Standard
19198
19199 16 bits
19200 \end_inset 
19201 </cell>
19202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19203 \begin_inset Text
19204
19205 \layout Standard
19206
19207 PRODL:WREG
19208 \end_inset 
19209 </cell>
19210 </row>
19211 <row topline="true">
19212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19213 \begin_inset Text
19214
19215 \layout Standard
19216
19217 24 bits
19218 \end_inset 
19219 </cell>
19220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19221 \begin_inset Text
19222
19223 \layout Standard
19224
19225 PRODH:PRODL:WREG
19226 \end_inset 
19227 </cell>
19228 </row>
19229 <row topline="true">
19230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19231 \begin_inset Text
19232
19233 \layout Standard
19234
19235 32 bits
19236 \end_inset 
19237 </cell>
19238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19239 \begin_inset Text
19240
19241 \layout Standard
19242
19243 FSR0L:PRODH:PRODL:WREG
19244 \end_inset 
19245 </cell>
19246 </row>
19247 <row topline="true" bottomline="true">
19248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19249 \begin_inset Text
19250
19251 \layout Standard
19252
19253 >32 bits
19254 \end_inset 
19255 </cell>
19256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19257 \begin_inset Text
19258
19259 \layout Standard
19260
19261 on stack, FSR0 points to the beginning
19262 \end_inset 
19263 </cell>
19264 </row>
19265 </lyxtabular>
19266
19267 \end_inset 
19268
19269
19270 \layout Subsection
19271
19272 Interrupts
19273 \layout Standard
19274
19275 An interrupt servive routine (ISR) is declared using the 
19276 \emph on 
19277 interrupt
19278 \emph default 
19279  keyword.
19280 \layout LyX-Code
19281
19282 void isr(void) interrupt 
19283 \emph on 
19284 n
19285 \layout LyX-Code
19286
19287 {
19288 \layout LyX-Code
19289
19290 ...
19291 \layout LyX-Code
19292
19293 }
19294 \layout Standard
19295
19296
19297 \emph on 
19298 n
19299 \emph default 
19300  is the interrupt number, which for PIC18F devices can be:
19301 \layout Standard
19302 \align center 
19303
19304 \begin_inset  Tabular
19305 <lyxtabular version="3" rows="4" columns="3">
19306 <features>
19307 <column alignment="center" valignment="top" leftline="true" width="0">
19308 <column alignment="center" valignment="top" leftline="true" width="0">
19309 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19310 <row topline="true" bottomline="true">
19311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19312 \begin_inset Text
19313
19314 \layout Standard
19315
19316
19317 \emph on 
19318 n
19319 \end_inset 
19320 </cell>
19321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19322 \begin_inset Text
19323
19324 \layout Standard
19325
19326 Interrupt Vector
19327 \end_inset 
19328 </cell>
19329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19330 \begin_inset Text
19331
19332 \layout Standard
19333
19334 Interrupt Vector Address
19335 \end_inset 
19336 </cell>
19337 </row>
19338 <row topline="true">
19339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19340 \begin_inset Text
19341
19342 \layout Standard
19343
19344 0
19345 \end_inset 
19346 </cell>
19347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19348 \begin_inset Text
19349
19350 \layout Standard
19351
19352 RESET vector
19353 \end_inset 
19354 </cell>
19355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19356 \begin_inset Text
19357
19358 \layout Standard
19359
19360 0x000000
19361 \end_inset 
19362 </cell>
19363 </row>
19364 <row topline="true">
19365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19366 \begin_inset Text
19367
19368 \layout Standard
19369
19370
19371 \family roman 
19372 \series medium 
19373 \shape up 
19374 \size normal 
19375 \emph off 
19376 \bar no 
19377 \noun off 
19378 \color none
19379 1
19380 \end_inset 
19381 </cell>
19382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19383 \begin_inset Text
19384
19385 \layout Standard
19386
19387
19388 \family roman 
19389 \series medium 
19390 \shape up 
19391 \size normal 
19392 \emph off 
19393 \bar no 
19394 \noun off 
19395 \color none
19396 HIGH priority interrupts
19397 \end_inset 
19398 </cell>
19399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19400 \begin_inset Text
19401
19402 \layout Standard
19403
19404 0x000008
19405 \end_inset 
19406 </cell>
19407 </row>
19408 <row topline="true" bottomline="true">
19409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19410 \begin_inset Text
19411
19412 \layout Standard
19413
19414 2
19415 \end_inset 
19416 </cell>
19417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19418 \begin_inset Text
19419
19420 \layout Standard
19421
19422 LOW priority interrupts
19423 \end_inset 
19424 </cell>
19425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19426 \begin_inset Text
19427
19428 \layout Standard
19429
19430 0x000018
19431 \end_inset 
19432 </cell>
19433 </row>
19434 </lyxtabular>
19435
19436 \end_inset 
19437
19438
19439 \layout Standard
19440
19441 When generating assembly code for ISR the code generator places a 
19442 \noun on 
19443 goto 
19444 \noun default 
19445 instruction at the 
19446 \emph on 
19447 Interrupt Vector Address
19448 \emph default 
19449  which points at the genetated ISR.
19450  This single GOTO instruction is part of an automatically generated 
19451 \emph on 
19452 interrupt entry point
19453 \emph default 
19454  function.
19455  The actuall ISR code is placed as normally would in the code space.
19456  Upon interrupt request, the GOTO instruction is executed which jumps to
19457  the ISR code.
19458  When declaring interrupt functions as _naked this GOTO instruction is 
19459 \series bold 
19460 not
19461 \series default 
19462  generated.
19463  The whole interrupt functions is therefore placed at the Interrupt Vector
19464  Address of the specific interrupt.
19465  This is not a problem for the LOW priority interrupts, but it is a problem
19466  for the RESET and the HIGH priority interrupts because code may be written
19467  at the next interrupt´s vector address and cause undeterminate program
19468  behaviour if that interrupt is raised.
19469 \begin_inset Foot
19470 collapsed false
19471
19472 \layout Standard
19473
19474 This is not a problem when
19475 \layout Enumerate
19476
19477 this is a HIGH interrupt ISR and LOW interrupts are 
19478 \emph on 
19479 disabled
19480 \emph default 
19481  or not used.
19482 \layout Enumerate
19483
19484 when the ISR is small enough not to reach the next interrupt´s vector address.
19485 \end_inset 
19486
19487
19488 \layout Standard
19489
19490
19491 \emph on 
19492 n
19493 \emph default 
19494  is possible to be omitted.
19495  This way a function is generated similar to an ISR, but it is not assigned
19496  to any interrupt.
19497 \layout Standard
19498
19499 When entering an interrupt, currently the PIC16
19500 \begin_inset LatexCommand \index{PIC16}
19501
19502 \end_inset 
19503
19504  port automatically saves the following registers:
19505 \layout Itemize
19506
19507 WREG
19508 \layout Itemize
19509
19510 STATUS
19511 \layout Itemize
19512
19513 BSR
19514 \layout Itemize
19515
19516 PROD (PRODL and PRODH)
19517 \layout Itemize
19518
19519 FSR0 (FSR0L and FSR0H)
19520 \layout Standard
19521
19522 These registers are restored upon return from the interrupt routine.
19523 \begin_inset Foot
19524 collapsed false
19525
19526 \layout Standard
19527
19528 NOTE that when the _naked attribute is specified for an interrupt routine,
19529  then NO registers are stored or restored.
19530 \end_inset 
19531
19532
19533 \layout Subsection
19534
19535 Generic Pointers
19536 \layout Standard
19537
19538 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
19539  There are 3 types of generic pointers currently implemented data, code
19540  and eeprom pointers.
19541  They are differentiated by the value of the 7th and 6th bits of the upper
19542  byte:
19543 \layout Standard
19544 \align center 
19545
19546 \begin_inset  Tabular
19547 <lyxtabular version="3" rows="5" columns="5">
19548 <features>
19549 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19550 <column alignment="center" valignment="top" width="0">
19551 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19552 <column alignment="center" valignment="top" width="0">
19553 <column alignment="left" valignment="top" rightline="true" width="0">
19554 <row topline="true" bottomline="true">
19555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19556 \begin_inset Text
19557
19558 \layout Standard
19559
19560 pointer type
19561 \end_inset 
19562 </cell>
19563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19564 \begin_inset Text
19565
19566 \layout Standard
19567
19568 7th bit
19569 \end_inset 
19570 </cell>
19571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19572 \begin_inset Text
19573
19574 \layout Standard
19575
19576 6th bit
19577 \end_inset 
19578 </cell>
19579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19580 \begin_inset Text
19581
19582 \layout Standard
19583
19584 rest of the pointer
19585 \end_inset 
19586 </cell>
19587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19588 \begin_inset Text
19589
19590 \layout Standard
19591
19592 descrption
19593 \end_inset 
19594 </cell>
19595 </row>
19596 <row topline="true" bottomline="true">
19597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19598 \begin_inset Text
19599
19600 \layout Standard
19601
19602 data 
19603 \end_inset 
19604 </cell>
19605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19606 \begin_inset Text
19607
19608 \layout Standard
19609
19610 1
19611 \end_inset 
19612 </cell>
19613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19614 \begin_inset Text
19615
19616 \layout Standard
19617
19618 0
19619 \end_inset 
19620 </cell>
19621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19622 \begin_inset Text
19623
19624 \layout Standard
19625
19626
19627 \family typewriter 
19628 \shape slanted 
19629 \emph on 
19630 uuuuuu uuuuxxxx xxxxxxxx
19631 \end_inset 
19632 </cell>
19633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19634 \begin_inset Text
19635
19636 \layout Standard
19637
19638 a 12-bit data pointer in data RAM memory
19639 \end_inset 
19640 </cell>
19641 </row>
19642 <row bottomline="true">
19643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19644 \begin_inset Text
19645
19646 \layout Standard
19647
19648 code
19649 \end_inset 
19650 </cell>
19651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19652 \begin_inset Text
19653
19654 \layout Standard
19655
19656 0
19657 \end_inset 
19658 </cell>
19659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19660 \begin_inset Text
19661
19662 \layout Standard
19663
19664 0
19665 \end_inset 
19666 </cell>
19667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19668 \begin_inset Text
19669
19670 \layout Standard
19671
19672
19673 \family typewriter 
19674 \shape slanted 
19675 \emph on 
19676 uxxxxx xxxxxxxx xxxxxxxx
19677 \end_inset 
19678 </cell>
19679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19680 \begin_inset Text
19681
19682 \layout Standard
19683
19684 a 21-bit code pointer in FLASH memory
19685 \end_inset 
19686 </cell>
19687 </row>
19688 <row bottomline="true">
19689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19690 \begin_inset Text
19691
19692 \layout Standard
19693
19694 eeprom
19695 \end_inset 
19696 </cell>
19697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19698 \begin_inset Text
19699
19700 \layout Standard
19701
19702 0
19703 \end_inset 
19704 </cell>
19705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19706 \begin_inset Text
19707
19708 \layout Standard
19709
19710 1
19711 \end_inset 
19712 </cell>
19713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19714 \begin_inset Text
19715
19716 \layout Standard
19717
19718
19719 \family typewriter 
19720 \shape slanted 
19721 \emph on 
19722 uuuuuu uuuuuuxx xxxxxxxx
19723 \end_inset 
19724 </cell>
19725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19726 \begin_inset Text
19727
19728 \layout Standard
19729
19730 a 10-bit eeprom pointer in EEPROM memory
19731 \end_inset 
19732 </cell>
19733 </row>
19734 <row bottomline="true">
19735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19736 \begin_inset Text
19737
19738 \layout Standard
19739
19740 (unimplemented)
19741 \end_inset 
19742 </cell>
19743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19744 \begin_inset Text
19745
19746 \layout Standard
19747
19748 1
19749 \end_inset 
19750 </cell>
19751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19752 \begin_inset Text
19753
19754 \layout Standard
19755
19756 1
19757 \end_inset 
19758 </cell>
19759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19760 \begin_inset Text
19761
19762 \layout Standard
19763
19764
19765 \family typewriter 
19766 \shape slanted 
19767 \emph on 
19768 xxxxxx xxxxxxxx xxxxxxxx
19769 \end_inset 
19770 </cell>
19771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19772 \begin_inset Text
19773
19774 \layout Standard
19775
19776 unimplemented pointer type
19777 \end_inset 
19778 </cell>
19779 </row>
19780 </lyxtabular>
19781
19782 \end_inset 
19783
19784
19785 \layout Standard
19786
19787 Generic pointer are read and written with a set of library functions which
19788  read/write 1, 2, 3, 4 bytes.
19789 \layout Subsection
19790
19791 PIC16 C Libraries
19792 \layout Subsubsection
19793
19794 Standard I/O Streams
19795 \layout Standard
19796
19797 In the 
19798 \emph on 
19799 stdio.h
19800 \emph default 
19801  the type FILE is defined as:
19802 \layout LyX-Code
19803
19804 typedef char * FILE;
19805 \layout Standard
19806
19807 This type is the stream type implemented I/O in the PIC18F devices.
19808  Also the standard input and output streams are declared in stdio.h:
19809 \layout LyX-Code
19810
19811 extern FILE * stdin;
19812 \layout LyX-Code
19813
19814 extern FILE * stdout;
19815 \layout Standard
19816
19817 The FILE type is actually a generic pointer which defines one more type
19818  of generic pointers, the 
19819 \emph on 
19820 stream 
19821 \emph default 
19822 pointer.
19823  This new type has the format:
19824 \layout Standard
19825 \align center 
19826
19827 \begin_inset  Tabular
19828 <lyxtabular version="3" rows="2" columns="7">
19829 <features>
19830 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19831 <column alignment="center" valignment="top" width="0">
19832 <column alignment="center" valignment="top" leftline="true" width="0">
19833 <column alignment="center" valignment="top" leftline="true" width="0">
19834 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19835 <column alignment="center" valignment="top" width="0">
19836 <column alignment="left" valignment="top" rightline="true" width="0">
19837 <row topline="true" bottomline="true">
19838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19839 \begin_inset Text
19840
19841 \layout Standard
19842
19843 pointer type
19844 \end_inset 
19845 </cell>
19846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19847 \begin_inset Text
19848
19849 \layout Standard
19850
19851 <7:6>
19852 \end_inset 
19853 </cell>
19854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19855 \begin_inset Text
19856
19857 \layout Standard
19858
19859 <5>
19860 \end_inset 
19861 </cell>
19862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19863 \begin_inset Text
19864
19865 \layout Standard
19866
19867 <4>
19868 \end_inset 
19869 </cell>
19870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19871 \begin_inset Text
19872
19873 \layout Standard
19874
19875 <3:0>
19876 \end_inset 
19877 </cell>
19878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19879 \begin_inset Text
19880
19881 \layout Standard
19882
19883 rest of the pointer
19884 \end_inset 
19885 </cell>
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19887 \begin_inset Text
19888
19889 \layout Standard
19890
19891 descrption
19892 \end_inset 
19893 </cell>
19894 </row>
19895 <row topline="true" bottomline="true">
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19897 \begin_inset Text
19898
19899 \layout Standard
19900
19901 stream
19902 \end_inset 
19903 </cell>
19904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19905 \begin_inset Text
19906
19907 \layout Standard
19908
19909 00
19910 \end_inset 
19911 </cell>
19912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19913 \begin_inset Text
19914
19915 \layout Standard
19916
19917 1
19918 \end_inset 
19919 </cell>
19920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19921 \begin_inset Text
19922
19923 \layout Standard
19924
19925 0
19926 \end_inset 
19927 </cell>
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19929 \begin_inset Text
19930
19931 \layout Standard
19932
19933 nnnn
19934 \end_inset 
19935 </cell>
19936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19937 \begin_inset Text
19938
19939 \layout Standard
19940
19941
19942 \family typewriter 
19943 \shape slanted 
19944 \emph on 
19945 uuuuuuuu uuuuuuuu
19946 \end_inset 
19947 </cell>
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19949 \begin_inset Text
19950
19951 \layout Standard
19952
19953 upper byte high nubble is 0x2n, the rest are zeroes
19954 \end_inset 
19955 </cell>
19956 </row>
19957 </lyxtabular>
19958
19959 \end_inset 
19960
19961
19962 \layout Standard
19963
19964 Currently implemented there are 3 types of streams defined:
19965 \layout Standard
19966 \align center 
19967
19968 \begin_inset  Tabular
19969 <lyxtabular version="3" rows="4" columns="4">
19970 <features>
19971 <column alignment="center" valignment="top" leftline="true" width="0">
19972 <column alignment="center" valignment="top" leftline="true" width="0">
19973 <column alignment="center" valignment="top" leftline="true" width="0">
19974 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19975 <row topline="true" bottomline="true">
19976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19977 \begin_inset Text
19978
19979 \layout Standard
19980
19981 stream type
19982 \end_inset 
19983 </cell>
19984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19985 \begin_inset Text
19986
19987 \layout Standard
19988
19989 value
19990 \end_inset 
19991 </cell>
19992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19993 \begin_inset Text
19994
19995 \layout Standard
19996
19997 module
19998 \end_inset 
19999 </cell>
20000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20001 \begin_inset Text
20002
20003 \layout Standard
20004
20005 description
20006 \end_inset 
20007 </cell>
20008 </row>
20009 <row topline="true">
20010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20011 \begin_inset Text
20012
20013 \layout Standard
20014
20015 STREAM_USART
20016 \end_inset 
20017 </cell>
20018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20019 \begin_inset Text
20020
20021 \layout Standard
20022
20023
20024 \family typewriter 
20025 0x200000UL
20026 \end_inset 
20027 </cell>
20028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20029 \begin_inset Text
20030
20031 \layout Standard
20032
20033 USART
20034 \end_inset 
20035 </cell>
20036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20037 \begin_inset Text
20038
20039 \layout Standard
20040
20041 Writes/Reads characters via the USART peripheral
20042 \end_inset 
20043 </cell>
20044 </row>
20045 <row topline="true">
20046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20047 \begin_inset Text
20048
20049 \layout Standard
20050
20051 STREAM_MSSP
20052 \end_inset 
20053 </cell>
20054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20055 \begin_inset Text
20056
20057 \layout Standard
20058
20059
20060 \family typewriter 
20061 0x210000UL
20062 \end_inset 
20063 </cell>
20064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20065 \begin_inset Text
20066
20067 \layout Standard
20068
20069 MSSP
20070 \end_inset 
20071 </cell>
20072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20073 \begin_inset Text
20074
20075 \layout Standard
20076
20077 Writes/Reads characters via the MSSP peripheral
20078 \end_inset 
20079 </cell>
20080 </row>
20081 <row topline="true" bottomline="true">
20082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20083 \begin_inset Text
20084
20085 \layout Standard
20086
20087 STREAM_USER
20088 \end_inset 
20089 </cell>
20090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20091 \begin_inset Text
20092
20093 \layout Standard
20094
20095
20096 \family typewriter 
20097 0x2f0000UL
20098 \end_inset 
20099 </cell>
20100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20101 \begin_inset Text
20102
20103 \layout Standard
20104
20105 (none)
20106 \end_inset 
20107 </cell>
20108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20109 \begin_inset Text
20110
20111 \layout Standard
20112
20113 Writes/Reads characters via used defined functions
20114 \end_inset 
20115 </cell>
20116 </row>
20117 </lyxtabular>
20118
20119 \end_inset 
20120
20121
20122 \layout Standard
20123
20124 The stream identifiers are declared as macros in the stdio.h header.
20125 \layout Standard
20126
20127 In the libc library there exist the functions that are used to write to
20128  each of the above streams.
20129  These are
20130 \layout List
20131 \labelwidthstring 00.00.0000
20132
20133 _
20134 \begin_inset ERT
20135 status Collapsed
20136
20137 \layout Standard
20138
20139 \backslash 
20140 /
20141 \end_inset 
20142
20143 _stream_usart_putchar writes a character at the USART stream
20144 \layout List
20145 \labelwidthstring 00.00.0000
20146
20147 _
20148 \begin_inset ERT
20149 status Collapsed
20150
20151 \layout Standard
20152
20153 \backslash 
20154 /
20155 \end_inset 
20156
20157 _stream_mssp_putchar writes a character at the MSSP stream
20158 \layout List
20159 \labelwidthstring 00.00.0000
20160
20161 putchar dummy function.
20162  This writes a character to a user specified manner.
20163 \layout Standard
20164
20165 In order to increase performance 
20166 \emph on 
20167 putchar 
20168 \emph default 
20169 is declared in stdio.h as having its parameter in WREG (it has the wparam
20170  keyword).
20171  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
20172  in a user-friendly way.
20173  
20174 \emph on 
20175 arg
20176 \emph default 
20177  is the name of the variable that holds the character to print.
20178  An example follows:
20179 \layout LyX-Code
20180
20181 #include <pic18fregs.h>
20182 \newline 
20183 #include <stdio.h>
20184 \newline 
20185
20186 \newline 
20187 PUTCHAR( c )
20188 \layout LyX-Code
20189
20190 {
20191 \layout LyX-Code
20192
20193     PORTA = c;    /* dump character c to PORTA */
20194 \layout LyX-Code
20195
20196
20197 \newline 
20198
20199 \newline 
20200 void main(void)
20201 \layout LyX-Code
20202
20203 {
20204 \layout LyX-Code
20205
20206     stdout = STREAM_USER;    /* this is not necessery, since stdout points
20207 \layout LyX-Code
20208
20209                               * by default to STREAM_USER */
20210 \layout LyX-Code
20211
20212     printf (¨This is a printf test
20213 \backslash 
20214 n¨);
20215 \layout LyX-Code
20216
20217 }
20218 \layout LyX-Code
20219
20220 \layout Subsubsection
20221
20222 Printing functions
20223 \layout Standard
20224
20225 PIC16 contains an implementation of the printf-family of functions.
20226  There exist the following functions:
20227 \layout LyX-Code
20228
20229 extern unsigned int sprintf(char *buf, char *fmt, ...);
20230 \layout LyX-Code
20231
20232 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
20233 \layout LyX-Code
20234
20235 \layout LyX-Code
20236
20237 extern unsigned int printf(char *fmt, ...);
20238 \layout LyX-Code
20239
20240 extern unsigned int vprintf(char *fmt, va_lista ap);
20241 \layout LyX-Code
20242
20243 \layout LyX-Code
20244
20245 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
20246 \layout LyX-Code
20247
20248 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
20249 \layout Standard
20250
20251 For sprintf and vsprintf 
20252 \emph on 
20253 buf 
20254 \emph default 
20255 should normally be a data pointer where the resulting string will be placed.
20256  No range checking is done so the user should allocate the necessery buffer.
20257  For fprintf and vfprintf 
20258 \emph on 
20259 fp
20260 \emph default 
20261  should be a stream pointer (i.e.
20262  stdout, STREAM_MSSP, etc...).
20263 \layout Subsubsection
20264
20265 Signals
20266 \layout Standard
20267
20268 The PIC18F family of microcontrollers supports a number of interrupt sources.
20269  A list of these interrupts is shown in the following table:
20270 \layout Standard
20271 \align center 
20272
20273 \begin_inset  Tabular
20274 <lyxtabular version="3" rows="11" columns="4">
20275 <features>
20276 <column alignment="left" valignment="top" leftline="true" width="0">
20277 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20278 <column alignment="left" valignment="top" leftline="true" width="0">
20279 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20280 <row topline="true" bottomline="true">
20281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20282 \begin_inset Text
20283
20284 \layout Standard
20285
20286 signal name
20287 \end_inset 
20288 </cell>
20289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20290 \begin_inset Text
20291
20292 \layout Standard
20293
20294 description
20295 \end_inset 
20296 </cell>
20297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20298 \begin_inset Text
20299
20300 \layout Standard
20301
20302 signal name
20303 \end_inset 
20304 </cell>
20305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20306 \begin_inset Text
20307
20308 \layout Standard
20309
20310 descritpion
20311 \end_inset 
20312 </cell>
20313 </row>
20314 <row topline="true">
20315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20316 \begin_inset Text
20317
20318 \layout Standard
20319
20320 SIG_RB
20321 \end_inset 
20322 </cell>
20323 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20324 \begin_inset Text
20325
20326 \layout Standard
20327
20328 PORTB change interrupt
20329 \end_inset 
20330 </cell>
20331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20332 \begin_inset Text
20333
20334 \layout Standard
20335
20336 SIG_EE
20337 \end_inset 
20338 </cell>
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20340 \begin_inset Text
20341
20342 \layout Standard
20343
20344 EEPROM/FLASH write complete interrupt
20345 \end_inset 
20346 </cell>
20347 </row>
20348 <row topline="true">
20349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20350 \begin_inset Text
20351
20352 \layout Standard
20353
20354 SIG_INT0
20355 \end_inset 
20356 </cell>
20357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20358 \begin_inset Text
20359
20360 \layout Standard
20361
20362 INT0 external interrupt
20363 \end_inset 
20364 </cell>
20365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20366 \begin_inset Text
20367
20368 \layout Standard
20369
20370 SIG_BCOL
20371 \end_inset 
20372 </cell>
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20374 \begin_inset Text
20375
20376 \layout Standard
20377
20378 Bus collision interrupt
20379 \end_inset 
20380 </cell>
20381 </row>
20382 <row topline="true">
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20384 \begin_inset Text
20385
20386 \layout Standard
20387
20388 SIG_INT1
20389 \end_inset 
20390 </cell>
20391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20392 \begin_inset Text
20393
20394 \layout Standard
20395
20396 INT1 external interrupt
20397 \end_inset 
20398 </cell>
20399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20400 \begin_inset Text
20401
20402 \layout Standard
20403
20404 SIG_LVD
20405 \end_inset 
20406 </cell>
20407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20408 \begin_inset Text
20409
20410 \layout Standard
20411
20412 Low voltage detect interrupt
20413 \end_inset 
20414 </cell>
20415 </row>
20416 <row topline="true">
20417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20418 \begin_inset Text
20419
20420 \layout Standard
20421
20422 SIG_INT2
20423 \end_inset 
20424 </cell>
20425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20426 \begin_inset Text
20427
20428 \layout Standard
20429
20430 INT2 external interrupt
20431 \end_inset 
20432 </cell>
20433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20434 \begin_inset Text
20435
20436 \layout Standard
20437
20438 SIG_PSP
20439 \end_inset 
20440 </cell>
20441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20442 \begin_inset Text
20443
20444 \layout Standard
20445
20446 Parallel slave port interrupt
20447 \end_inset 
20448 </cell>
20449 </row>
20450 <row topline="true">
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20452 \begin_inset Text
20453
20454 \layout Standard
20455
20456 SIG_CCP1
20457 \end_inset 
20458 </cell>
20459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20460 \begin_inset Text
20461
20462 \layout Standard
20463
20464 CCP1 module interrupt
20465 \end_inset 
20466 </cell>
20467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20468 \begin_inset Text
20469
20470 \layout Standard
20471
20472 SIG_AD
20473 \end_inset 
20474 </cell>
20475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20476 \begin_inset Text
20477
20478 \layout Standard
20479
20480 AD convertion complete interrupt
20481 \end_inset 
20482 </cell>
20483 </row>
20484 <row topline="true">
20485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20486 \begin_inset Text
20487
20488 \layout Standard
20489
20490 SIG_CCP2
20491 \end_inset 
20492 </cell>
20493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20494 \begin_inset Text
20495
20496 \layout Standard
20497
20498 CCP2 module interrupt
20499 \end_inset 
20500 </cell>
20501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20502 \begin_inset Text
20503
20504 \layout Standard
20505
20506 SIG_RC
20507 \end_inset 
20508 </cell>
20509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20510 \begin_inset Text
20511
20512 \layout Standard
20513
20514 USART receive interrupt
20515 \end_inset 
20516 </cell>
20517 </row>
20518 <row topline="true">
20519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20520 \begin_inset Text
20521
20522 \layout Standard
20523
20524 SIG_TMR0
20525 \end_inset 
20526 </cell>
20527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20528 \begin_inset Text
20529
20530 \layout Standard
20531
20532 TMR0 overflow interrupt
20533 \end_inset 
20534 </cell>
20535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20536 \begin_inset Text
20537
20538 \layout Standard
20539
20540 SIG_TX
20541 \end_inset 
20542 </cell>
20543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20544 \begin_inset Text
20545
20546 \layout Standard
20547
20548 USART transmit interrupt
20549 \end_inset 
20550 </cell>
20551 </row>
20552 <row topline="true">
20553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20554 \begin_inset Text
20555
20556 \layout Standard
20557
20558 SIG_TMR1
20559 \end_inset 
20560 </cell>
20561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20562 \begin_inset Text
20563
20564 \layout Standard
20565
20566 TMR1 overflow interrupt
20567 \end_inset 
20568 </cell>
20569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20570 \begin_inset Text
20571
20572 \layout Standard
20573
20574 SIG_MSSP
20575 \end_inset 
20576 </cell>
20577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20578 \begin_inset Text
20579
20580 \layout Standard
20581
20582 SSP receive/transmit interrupt
20583 \end_inset 
20584 </cell>
20585 </row>
20586 <row topline="true">
20587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20588 \begin_inset Text
20589
20590 \layout Standard
20591
20592 SIG_TMR2
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 TMR2 matches PR2 interrupt
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 \end_inset 
20609 </cell>
20610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20611 \begin_inset Text
20612
20613 \layout Standard
20614
20615 \end_inset 
20616 </cell>
20617 </row>
20618 <row topline="true" bottomline="true">
20619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20620 \begin_inset Text
20621
20622 \layout Standard
20623
20624 SIG_TMR3
20625 \end_inset 
20626 </cell>
20627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20628 \begin_inset Text
20629
20630 \layout Standard
20631
20632 TMR3 overflow interrupt
20633 \end_inset 
20634 </cell>
20635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20636 \begin_inset Text
20637
20638 \layout Standard
20639
20640 \end_inset 
20641 </cell>
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20643 \begin_inset Text
20644
20645 \layout Standard
20646
20647 \end_inset 
20648 </cell>
20649 </row>
20650 </lyxtabular>
20651
20652 \end_inset 
20653
20654
20655 \layout Standard
20656
20657 The prototypes for these names are defined in the header file 
20658 \emph on 
20659 signal.h
20660 \emph default 
20661  .
20662 \layout Standard
20663
20664 In order to simplify signal handling, a number of macros is provided:
20665 \layout List
20666 \labelwidthstring 00.00.0000
20667
20668 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
20669  high priority interrupts.
20670  
20671 \emph on 
20672 name
20673 \emph default 
20674  is the function name to use.
20675 \layout List
20676 \labelwidthstring 00.00.0000
20677
20678 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
20679  low priority interrupt.
20680  
20681 \emph on 
20682 name
20683 \emph default 
20684  is the function name to use.
20685 \layout List
20686 \labelwidthstring 00.00.0000
20687
20688 DEF_HANDLER(sig,handler) define a handler for signal 
20689 \emph on 
20690 sig.
20691 \layout List
20692 \labelwidthstring 00.00.0000
20693
20694 END_DEF end the declaration of the dispatch table.
20695 \layout Standard
20696
20697 Additionally there are two more macros to simplify the declaration of the
20698  signal handler:
20699 \layout List
20700 \labelwidthstring 00.00.0000
20701
20702
20703 \series medium 
20704 SIGHANDLER(handler) 
20705 \series default 
20706 this declares the function prototype for the 
20707 \emph on 
20708 handler
20709 \emph default 
20710  function.
20711 \layout List
20712 \labelwidthstring 00.00.0000
20713
20714 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
20715 \layout Standard
20716
20717 An example of using the macros above is shown below:
20718 \layout LyX-Code
20719
20720 #include <pic18fregs.h>
20721 \layout LyX-Code
20722
20723 #include <signal.h>
20724 \newline 
20725
20726 \newline 
20727 DEF_INTHIGH(high_int)
20728 \layout LyX-Code
20729
20730 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
20731 \layout LyX-Code
20732
20733 DEF_HANDLER(SIG_BCOL, _bcol_handler)
20734 \layout LyX-Code
20735
20736 END_DEF
20737 \newline 
20738
20739 \newline 
20740 SIGHANDLER(_tmr0_handler)
20741 \layout LyX-Code
20742
20743 {
20744 \layout LyX-Code
20745
20746   /* action to be taken when timer 0 overflows */
20747 \layout LyX-Code
20748
20749 }
20750 \newline 
20751
20752 \newline 
20753 SIGHANDLERNAKED(_bcol_handler)
20754 \layout LyX-Code
20755
20756 {
20757 \layout LyX-Code
20758
20759   _asm
20760 \layout LyX-Code
20761
20762     /* action to be taken when bus collision occurs */
20763 \layout LyX-Code
20764
20765     retfie
20766 \layout LyX-Code
20767
20768  _endasm;
20769 \layout LyX-Code
20770
20771 }
20772 \layout Standard
20773
20774
20775 \series bold 
20776 NOTES:
20777 \series default 
20778  Special care should be taken when using the above scheme:
20779 \layout Itemize
20780
20781 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
20782 \layout Itemize
20783
20784 when declaring SIGHANDLERNAKED handler never forget to use 
20785 \emph on 
20786 retfie
20787 \emph default 
20788  for proper returning.
20789 \layout Subsection
20790
20791 PIC16 Port -- Tips
20792 \layout Standard
20793
20794 Here you can find some general tips for compiling programs with SDCC/pic16.
20795 \layout Subsubsection
20796
20797 Stack size
20798 \layout Standard
20799
20800 The default stack size (that is 64 bytes) probably is enough for many programs.
20801  One must take care that when there are many levels of function nesting,
20802  or there is excessive usage of stack, its size should be extended.
20803  An example of such a case is the printf/sprintf family of functions.
20804  If you encounter problems like not being able to print integers, then you
20805  need to set the stack size around the maximum (256 for small stack model).
20806  The following diagram shows what happens when calling printf to print an
20807  integer:
20808 \layout LyX-Code
20809
20810 printf () --> ltoa () --> ultoa () --> divschar ()
20811 \layout Standard
20812
20813 It is should be understood that stack is easily consumed when calling complicate
20814 d functions.
20815  Using command line arguments like -
20816 \begin_inset ERT
20817 status Collapsed
20818
20819 \layout Standard
20820
20821 \backslash 
20822 /
20823 \end_inset 
20824
20825 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
20826  stack frames.
20827  Other ways to reduce stack usage may exist.
20828 \layout Chapter
20829
20830 Debugging
20831 \layout Standard
20832
20833 There are several approaches to debugging your code.
20834  This chapter is meant to show your options and to give detail on some of
20835  them:
20836 \newline 
20837
20838 \newline 
20839 When writing your code:
20840 \layout Itemize
20841
20842 write your code with debugging in mind (avoid duplicating code, put conceptually
20843  similar variables into structs, use structured code, have strategic points
20844  within your code where all variables are consistent, ...)
20845 \layout Itemize
20846
20847 run a syntax-checking tool like splint
20848 \begin_inset LatexCommand \index{splint (syntax checking tool)}
20849
20850 \end_inset 
20851
20852
20853 \begin_inset LatexCommand \index{lint (syntax checking tool)}
20854
20855 \end_inset 
20856
20857  (see -
20858 \begin_inset ERT
20859 status Collapsed
20860
20861 \layout Standard
20862
20863 \backslash 
20864 /
20865 \end_inset 
20866
20867 -more-pedantic 
20868 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
20869
20870 \end_inset 
20871
20872 ) over the code.
20873 \layout Itemize
20874
20875 for the high level code use a C-compiler (like f.e.
20876  GCC) to compile run and debug the code on your host.
20877  See (see -
20878 \begin_inset ERT
20879 status Collapsed
20880
20881 \layout Standard
20882
20883 \backslash 
20884 /
20885 \end_inset 
20886
20887 -more-pedantic 
20888 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
20889
20890 \end_inset 
20891
20892  ) on howto handle syntax extensions like __xdata, __at(), ...
20893  
20894 \layout Itemize
20895
20896 use another C-compiler to compile code for your target.
20897  Always an option but not recommended:) And not very likely to help you.
20898  If you seriously consider walking this path you should at least occasionally
20899  check portability of your code.
20900  Most commercial compiler vendors will offer an evaluation version so you
20901  can test compile your code or snippets of your code.
20902 \layout Standard
20903
20904 Debugging on a simulator:
20905 \layout Itemize
20906
20907 there is a separate section about SDCDB (section 
20908 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
20909
20910 \end_inset 
20911
20912 ) below.
20913 \layout Itemize
20914
20915 or (8051 specific) use a freeware/commercial simulator which interfaces
20916  to the AOMF
20917 \begin_inset LatexCommand \index{AOMF, AOMF51}
20918
20919 \end_inset 
20920
20921  file (see 
20922 \begin_inset LatexCommand \ref{OMF file}
20923
20924 \end_inset 
20925
20926 ) optionally generated by SDCC.
20927 \layout Standard
20928
20929 Debugging On-target: 
20930 \layout Itemize
20931
20932 use a MCU port pin to serially output debug data to the RS232 port of your
20933  host.
20934  You'll probably want some level shifting device typically involving a MAX232
20935  or similar IC.
20936  If the hardware serial port of the MCU is not available search for 'Software
20937  UART' in your favourite search machine.
20938 \layout Itemize
20939
20940 use an on-target monitor.
20941  In this context a monitor is a small program which usually accepts commands
20942  via a serial line and allows to set program counter, to single step through
20943  a program and read/write memory locations.
20944  For the 8051 good examples of monitors are paulmon and cmon51 (see section
20945  
20946 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
20947
20948 \end_inset 
20949
20950 ).
20951 \layout Itemize
20952
20953 toggle MCU port pins at strategic points within your code and use an oscilloscop
20954 e.
20955  A 
20956 \emph on 
20957 digital oscilloscope
20958 \emph default 
20959
20960 \begin_inset LatexCommand \index{oscilloscope}
20961
20962 \end_inset 
20963
20964  with deep trace memory is really helpful especially if you have to debug
20965  a realtime application.
20966  If you need to monitor more pins than your oscilloscope provides you can
20967  sometimes get away with a small R-2R network.
20968  On a single channel oscilloscope you could f.e.
20969  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
20970 k
20971 \begin_inset Formula $\Omega$
20972 \end_inset 
20973
20974  resistor and the other one by a 5\SpecialChar ~
20975 k
20976 \begin_inset Formula $\Omega$
20977 \end_inset 
20978
20979  resistor to the oscilloscope probe (check output drive capability of the
20980  pins you want to monitor).
20981  If you need to monitor many more pins a 
20982 \emph on 
20983 logic analyzer
20984 \emph default 
20985  will be handy.
20986 \layout Itemize
20987
20988 use an ICE (
20989 \emph on 
20990 i
20991 \emph default 
20992
20993 \emph on 
20994 c
20995 \emph default 
20996 ircuit 
20997 \emph on 
20998 e
20999 \emph default 
21000 mulator
21001 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
21002
21003 \end_inset 
21004
21005 ).
21006  Usually very expensive.
21007  And very nice to have too.
21008  And usually locks you (for years...) to the devices the ICE can emulate.
21009  
21010 \layout Itemize
21011
21012 use a remote debugger.
21013  In most 8-bit systems the symbol information is not available on the target,
21014  and a complete debugger is too bulky for the target system.
21015  Therefore usually a debugger on the host system connects to an on-target
21016  debugging stub which accepts only primitive commands.
21017  
21018 \newline 
21019 Terms to enter into your favourite search engine could be 'remote debugging',
21020  'gdb stub' or 'inferior debugger'.
21021  (is there one?)
21022 \layout Itemize
21023
21024 use an on target hardware debugger.
21025  Some of the more modern MCUs include hardware support for setting break
21026  points and monitoring/changing variables by using dedicated hardware pins.
21027  This facility doesn't require additional code to run on the target and
21028  
21029 \emph on 
21030 usually
21031 \emph default 
21032  doesn't affect runtime behaviour until a breakpoint is hit.
21033  For the mcs51 most hardware debuggers use the AOMF
21034 \begin_inset LatexCommand \index{AOMF, AOMF51}
21035
21036 \end_inset 
21037
21038  file (see 
21039 \begin_inset LatexCommand \ref{OMF file}
21040
21041 \end_inset 
21042
21043 ) as input file.
21044  
21045 \layout Standard
21046
21047 Last not least:
21048 \layout Itemize
21049
21050 if you are not familiar with any of the following terms you're likely to
21051  run into problems rather sooner than later: 
21052 \emph on 
21053 volatile
21054 \emph default 
21055
21056 \emph on 
21057 atomic
21058 \emph default 
21059
21060 \emph on 
21061 memory map
21062 \emph default 
21063
21064 \emph on 
21065 overlay
21066 \emph default 
21067 .
21068  As an embedded programmer you 
21069 \emph on 
21070 have
21071 \emph default 
21072  to know them so why not look them up 
21073 \emph on 
21074 before
21075 \emph default 
21076  you have problems?)
21077 \layout Itemize
21078
21079 tell someone else about your problem (actually this is a surprisingly effective
21080  means to hunt down the bug even if the listener is not familiar with your
21081  environment).
21082  As 'failure to communicate' is probably one of the job-induced deformations
21083  of an embedded programmer this is highly encouraged.
21084 \layout Section
21085
21086 Debugging with SDCDB
21087 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
21088
21089 \end_inset 
21090
21091
21092 \begin_inset LatexCommand \index{sdcdb (debugger)}
21093
21094 \end_inset 
21095
21096  
21097 \layout Standard
21098
21099 SDCC is distributed with a source level debugger
21100 \begin_inset LatexCommand \index{Debugger}
21101
21102 \end_inset 
21103
21104 .
21105  The debugger uses a command line interface, the command repertoire of the
21106  debugger has been kept as close to gdb
21107 \begin_inset LatexCommand \index{gdb}
21108
21109 \end_inset 
21110
21111  (the GNU debugger) as possible.
21112  The configuration and build process is part of the standard compiler installati
21113 on, which also builds and installs the debugger in the target directory
21114  specified during configuration.
21115  The debugger allows you debug BOTH at the C source and at the ASM source
21116  level.
21117  Sdcdb is currently not available on Win32 platforms.
21118 \layout Subsection
21119
21120 Compiling for Debugging
21121 \layout Standard
21122
21123 The -
21124 \begin_inset ERT
21125 status Collapsed
21126
21127 \layout Standard
21128
21129 \backslash 
21130 /
21131 \end_inset 
21132
21133 -debug
21134 \begin_inset LatexCommand \index{-\/-debug}
21135
21136 \end_inset 
21137
21138  option must be specified for all files for which debug information is to
21139  be generated.
21140  The compiler generates a .adb file for each of these files.
21141  The linker creates the .cdb
21142 \begin_inset LatexCommand \index{<file>.cdb}
21143
21144 \end_inset 
21145
21146  file from the .adb
21147 \begin_inset LatexCommand \index{<file>.adb}
21148
21149 \end_inset 
21150
21151  files and the address information.
21152  This .cdb is used by the debugger.
21153 \layout Subsection
21154
21155 How the Debugger Works
21156 \layout Standard
21157
21158 When the -
21159 \begin_inset ERT
21160 status Collapsed
21161
21162 \layout Standard
21163
21164 \backslash 
21165 /
21166 \end_inset 
21167
21168 -debug option is specified the compiler generates extra symbol information
21169  some of which are put into the assembler source and some are put into the
21170  .adb file.
21171  Then the linker creates the .cdb file from the individual .adb files with
21172  the address information for the symbols.
21173  The debugger reads the symbolic information generated by the compiler &
21174  the address information generated by the linker.
21175  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
21176  execution is controlled by the debugger.
21177  When a command is issued for the debugger, it translates it into appropriate
21178  commands for the simulator.
21179  (Currently sdcdb only connects to the simulator but 
21180 \emph on 
21181 newcdb
21182 \emph default 
21183  at 
21184 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
21185
21186 \end_inset 
21187
21188  is an effort to connect directly to the hardware.) 
21189 \layout Subsection
21190
21191 Starting the Debugger SDCDB
21192 \layout Standard
21193
21194 The debugger can be started using the following command line.
21195  (Assume the file you are debugging has the file name foo).
21196 \newline 
21197
21198 \newline 
21199
21200 \family sans 
21201 \series bold 
21202 sdcdb foo
21203 \newline 
21204
21205 \family default 
21206 \series default 
21207
21208 \newline 
21209 The debugger will look for the following files.
21210 \layout Itemize
21211
21212 foo.c - the source file.
21213 \layout Itemize
21214
21215 foo.cdb - the debugger symbol information file.
21216 \layout Itemize
21217
21218 foo.ihx - the Intel hex format
21219 \begin_inset LatexCommand \index{Intel hex format}
21220
21221 \end_inset 
21222
21223  object file.
21224 \layout Subsection
21225
21226 SDCDB Command Line Options
21227 \layout Itemize
21228
21229 -
21230 \begin_inset ERT
21231 status Collapsed
21232
21233 \layout Standard
21234
21235 \backslash 
21236 /
21237 \end_inset 
21238
21239 -directory=<source file directory> this option can used to specify the directory
21240  search list.
21241  The debugger will look into the directory list specified for source, cdb
21242  & ihx files.
21243  The items in the directory list must be separated by ':', e.g.
21244  if the source files can be in the directories /home/src1 and /home/src2,
21245  the -
21246 \begin_inset ERT
21247 status Collapsed
21248
21249 \layout Standard
21250
21251 \backslash 
21252 /
21253 \end_inset 
21254
21255 -directory option should be -
21256 \begin_inset ERT
21257 status Collapsed
21258
21259 \layout Standard
21260
21261 \backslash 
21262 /
21263 \end_inset 
21264
21265 -directory=/home/src1:/home/src2.
21266  Note there can be no spaces in the option.
21267  
21268 \layout Itemize
21269
21270 -cd <directory> - change to the <directory>.
21271 \layout Itemize
21272
21273 -fullname - used by GUI front ends.
21274 \layout Itemize
21275
21276 -cpu <cpu-type> - this argument is passed to the simulator please see the
21277  simulator docs for details.
21278 \layout Itemize
21279
21280 -X <Clock frequency > this options is passed to the simulator please see
21281  the simulator docs for details.
21282 \layout Itemize
21283
21284 -s <serial port file> passed to simulator see the simulator docs for details.
21285 \layout Itemize
21286
21287 -S <serial in,out> passed to simulator see the simulator docs for details.
21288 \layout Itemize
21289
21290 -k <port number> passed to simulator see the simulator docs for details.
21291 \layout Subsection
21292
21293 SDCDB Debugger Commands
21294 \layout Standard
21295
21296 As mentioned earlier the command interface for the debugger has been deliberatel
21297 y kept as close the GNU debugger gdb, as possible.
21298  This will help the integration with existing graphical user interfaces
21299  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
21300  If you use a graphical user interface for the debugger you can skip this
21301  section.
21302 \layout Subsubsection*
21303
21304 break [line | file:line | function | file:function]
21305 \layout Standard
21306
21307 Set breakpoint at specified line or function:
21308 \newline 
21309
21310 \newline 
21311
21312 \family sans 
21313 \series bold 
21314 sdcdb>break 100 
21315 \newline 
21316 sdcdb>break foo.c:100
21317 \newline 
21318 sdcdb>break funcfoo
21319 \newline 
21320 sdcdb>break foo.c:funcfoo
21321 \layout Subsubsection*
21322
21323 clear [line | file:line | function | file:function ]
21324 \layout Standard
21325
21326 Clear breakpoint at specified line or function:
21327 \newline 
21328
21329 \newline 
21330
21331 \family sans 
21332 \series bold 
21333 sdcdb>clear 100
21334 \newline 
21335 sdcdb>clear foo.c:100
21336 \newline 
21337 sdcdb>clear funcfoo
21338 \newline 
21339 sdcdb>clear foo.c:funcfoo
21340 \layout Subsubsection*
21341
21342 continue
21343 \layout Standard
21344
21345 Continue program being debugged, after breakpoint.
21346 \layout Subsubsection*
21347
21348 finish
21349 \layout Standard
21350
21351 Execute till the end of the current function.
21352 \layout Subsubsection*
21353
21354 delete [n]
21355 \layout Standard
21356
21357 Delete breakpoint number 'n'.
21358  If used without any option clear ALL user defined break points.
21359 \layout Subsubsection*
21360
21361 info [break | stack | frame | registers ]
21362 \layout Itemize
21363
21364 info break - list all breakpoints
21365 \layout Itemize
21366
21367 info stack - show the function call stack.
21368 \layout Itemize
21369
21370 info frame - show information about the current execution frame.
21371 \layout Itemize
21372
21373 info registers - show content of all registers.
21374 \layout Subsubsection*
21375
21376 step
21377 \layout Standard
21378
21379 Step program until it reaches a different source line.
21380  Note: pressing <return> repeats the last command.
21381 \layout Subsubsection*
21382
21383 next
21384 \layout Standard
21385
21386 Step program, proceeding through subroutine calls.
21387 \layout Subsubsection*
21388
21389 run
21390 \layout Standard
21391
21392 Start debugged program.
21393 \layout Subsubsection*
21394
21395 ptype variable 
21396 \layout Standard
21397
21398 Print type information of the variable.
21399 \layout Subsubsection*
21400
21401 print variable
21402 \layout Standard
21403
21404 print value of variable.
21405 \layout Subsubsection*
21406
21407 file filename
21408 \layout Standard
21409
21410 load the given file name.
21411  Note this is an alternate method of loading file for debugging.
21412 \layout Subsubsection*
21413
21414 frame
21415 \layout Standard
21416
21417 print information about current frame.
21418 \layout Subsubsection*
21419
21420 set srcmode
21421 \layout Standard
21422
21423 Toggle between C source & assembly source.
21424 \layout Subsubsection*
21425
21426 ! simulator command
21427 \layout Standard
21428
21429 Send the string following '!' to the simulator, the simulator response is
21430  displayed.
21431  Note the debugger does not interpret the command being sent to the simulator,
21432  so if a command like 'go' is sent the debugger can loose its execution
21433  context and may display incorrect values.
21434 \layout Subsubsection*
21435
21436 quit
21437 \layout Standard
21438
21439 "Watch me now.
21440  Iam going Down.
21441  My name is Bobby Brown"
21442 \layout Subsection
21443
21444 Interfacing SDCDB with DDD
21445 \layout Comment
21446
21447 The screenshot was converted from png to eps with: 
21448 \begin_inset Quotes sld
21449 \end_inset 
21450
21451 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
21452 \begin_inset Quotes srd
21453 \end_inset 
21454
21455  which produces a pretty compact eps file which is free from compression
21456  artifacts.
21457 \layout Comment
21458
21459 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
21460  as this broke the build system on Sourceforge (pdf-file was broken).
21461 \layout Standard
21462
21463 The .eps File 
21464 \size footnotesize 
21465
21466 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.eps}
21467
21468 \end_inset 
21469
21470
21471 \size default 
21472  shows a screenshot of a debugging session with DDD
21473 \begin_inset LatexCommand \index{DDD (debugger)}
21474
21475 \end_inset 
21476
21477  (Unix only) on a simulated 8032.
21478  The debugging session might not run as smoothly as the screenshot suggests.
21479  The debugger allows setting of breakpoints, displaying and changing variables,
21480  single stepping through C and assembler code.
21481  
21482 \newline 
21483 The source was compiled with 
21484 \family sans 
21485 \series bold 
21486
21487 \newline 
21488
21489 \newline 
21490 sdcc -
21491 \family default 
21492 \series default 
21493
21494 \begin_inset ERT
21495 status Collapsed
21496
21497 \layout Standard
21498
21499 \backslash 
21500 /
21501 \end_inset 
21502
21503
21504 \family sans 
21505 \series bold 
21506 -debug ddd_example.c
21507 \family default 
21508 \series default 
21509  
21510 \family sans 
21511 \series bold 
21512
21513 \newline 
21514
21515 \family default 
21516 \series default 
21517
21518 \newline 
21519 and DDD was invoked with 
21520 \family sans 
21521 \series bold 
21522
21523 \newline 
21524
21525 \newline 
21526 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
21527 \layout Subsection
21528
21529 Interfacing SDCDB with XEmacs
21530 \begin_inset LatexCommand \index{XEmacs}
21531
21532 \end_inset 
21533
21534
21535 \begin_inset LatexCommand \index{Emacs}
21536
21537 \end_inset 
21538
21539
21540 \layout Standard
21541
21542 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
21543  sdcdb.el and sdcdbsrc.el.
21544  These two files can be found in the $(prefix)/bin directory after the installat
21545 ion is complete.
21546  These files need to be loaded into XEmacs for the interface to work.
21547  This can be done at XEmacs startup time by inserting the following into
21548  your '.xemacs' file (which can be found in your HOME directory): 
21549 \newline 
21550
21551 \newline 
21552
21553 \family typewriter 
21554 (load-file sdcdbsrc.el) 
21555 \family default 
21556
21557 \newline 
21558
21559 \newline 
21560 .xemacs is a lisp file so the () around the command is REQUIRED.
21561  The files can also be loaded dynamically while XEmacs is running, set the
21562  environment variable 'EMACSLOADPATH' to the installation bin directory
21563  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
21564  To start the interface enter the following command: 
21565 \newline 
21566
21567 \newline 
21568
21569 \family sans 
21570 \series bold 
21571 ESC-x sdcdbsrc
21572 \family default 
21573 \series default 
21574
21575 \newline 
21576
21577 \newline 
21578 You will prompted to enter the file name to be debugged.
21579  
21580 \newline 
21581
21582 \newline 
21583 The command line options that are passed to the simulator directly are bound
21584  to default values in the file sdcdbsrc.el.
21585  The variables are listed below, these values maybe changed as required.
21586 \layout Itemize
21587
21588 sdcdbsrc-cpu-type '51
21589 \layout Itemize
21590
21591 sdcdbsrc-frequency '11059200
21592 \layout Itemize
21593
21594 sdcdbsrc-serial nil
21595 \layout Standard
21596
21597 The following is a list of key mapping for the debugger interface.
21598 \layout Standard
21599
21600 \SpecialChar ~
21601
21602 \family typewriter 
21603
21604 \newline 
21605 ;;\SpecialChar ~
21606 Current Listing :: 
21607 \newline 
21608 ;;key\SpecialChar ~
21609 \SpecialChar ~
21610 \SpecialChar ~
21611 \SpecialChar ~
21612 \SpecialChar ~
21613 \SpecialChar ~
21614 \SpecialChar ~
21615 \SpecialChar ~
21616 \SpecialChar ~
21617 \SpecialChar ~
21618 \SpecialChar ~
21619 \SpecialChar ~
21620 \SpecialChar ~
21621 \SpecialChar ~
21622 binding\SpecialChar ~
21623 \SpecialChar ~
21624 \SpecialChar ~
21625 \SpecialChar ~
21626 \SpecialChar ~
21627 \SpecialChar ~
21628 \SpecialChar ~
21629 \SpecialChar ~
21630 \SpecialChar ~
21631 \SpecialChar ~
21632 \SpecialChar ~
21633 \SpecialChar ~
21634 \SpecialChar ~
21635 \SpecialChar ~
21636 \SpecialChar ~
21637 \SpecialChar ~
21638 \SpecialChar ~
21639 \SpecialChar ~
21640 \SpecialChar ~
21641 \SpecialChar ~
21642 \SpecialChar ~
21643 \SpecialChar ~
21644 Comment 
21645 \newline 
21646 ;;---\SpecialChar ~
21647 \SpecialChar ~
21648 \SpecialChar ~
21649 \SpecialChar ~
21650 \SpecialChar ~
21651 \SpecialChar ~
21652 \SpecialChar ~
21653 \SpecialChar ~
21654 \SpecialChar ~
21655 \SpecialChar ~
21656 \SpecialChar ~
21657 \SpecialChar ~
21658 \SpecialChar ~
21659 \SpecialChar ~
21660 -------\SpecialChar ~
21661 \SpecialChar ~
21662 \SpecialChar ~
21663 \SpecialChar ~
21664 \SpecialChar ~
21665 \SpecialChar ~
21666 \SpecialChar ~
21667 \SpecialChar ~
21668 \SpecialChar ~
21669 \SpecialChar ~
21670 \SpecialChar ~
21671 \SpecialChar ~
21672 \SpecialChar ~
21673 \SpecialChar ~
21674 \SpecialChar ~
21675 \SpecialChar ~
21676 \SpecialChar ~
21677 \SpecialChar ~
21678 \SpecialChar ~
21679 \SpecialChar ~
21680 \SpecialChar ~
21681 \SpecialChar ~
21682 -------
21683 \newline 
21684 ;; 
21685 \newline 
21686 ;;\SpecialChar ~
21687 n\SpecialChar ~
21688 \SpecialChar ~
21689 \SpecialChar ~
21690 \SpecialChar ~
21691 \SpecialChar ~
21692 \SpecialChar ~
21693 \SpecialChar ~
21694 \SpecialChar ~
21695 \SpecialChar ~
21696 \SpecialChar ~
21697 \SpecialChar ~
21698 \SpecialChar ~
21699 \SpecialChar ~
21700 \SpecialChar ~
21701 \SpecialChar ~
21702 sdcdb-next-from-src\SpecialChar ~
21703 \SpecialChar ~
21704 \SpecialChar ~
21705 \SpecialChar ~
21706 \SpecialChar ~
21707 \SpecialChar ~
21708 \SpecialChar ~
21709 \SpecialChar ~
21710 \SpecialChar ~
21711 \SpecialChar ~
21712 SDCDB next command 
21713 \newline 
21714 ;;\SpecialChar ~
21715 b\SpecialChar ~
21716 \SpecialChar ~
21717 \SpecialChar ~
21718 \SpecialChar ~
21719 \SpecialChar ~
21720 \SpecialChar ~
21721 \SpecialChar ~
21722 \SpecialChar ~
21723 \SpecialChar ~
21724 \SpecialChar ~
21725 \SpecialChar ~
21726 \SpecialChar ~
21727 \SpecialChar ~
21728 \SpecialChar ~
21729 \SpecialChar ~
21730 sdcdb-back-from-src\SpecialChar ~
21731 \SpecialChar ~
21732 \SpecialChar ~
21733 \SpecialChar ~
21734 \SpecialChar ~
21735 \SpecialChar ~
21736 \SpecialChar ~
21737 \SpecialChar ~
21738 \SpecialChar ~
21739 \SpecialChar ~
21740 SDCDB back command 
21741 \newline 
21742 ;;\SpecialChar ~
21743 c\SpecialChar ~
21744 \SpecialChar ~
21745 \SpecialChar ~
21746 \SpecialChar ~
21747 \SpecialChar ~
21748 \SpecialChar ~
21749 \SpecialChar ~
21750 \SpecialChar ~
21751 \SpecialChar ~
21752 \SpecialChar ~
21753 \SpecialChar ~
21754 \SpecialChar ~
21755 \SpecialChar ~
21756 \SpecialChar ~
21757 \SpecialChar ~
21758 sdcdb-cont-from-src\SpecialChar ~
21759 \SpecialChar ~
21760 \SpecialChar ~
21761 \SpecialChar ~
21762 \SpecialChar ~
21763 \SpecialChar ~
21764 \SpecialChar ~
21765 \SpecialChar ~
21766 \SpecialChar ~
21767 \SpecialChar ~
21768 SDCDB continue command
21769 \newline 
21770 ;;\SpecialChar ~
21771 s\SpecialChar ~
21772 \SpecialChar ~
21773 \SpecialChar ~
21774 \SpecialChar ~
21775 \SpecialChar ~
21776 \SpecialChar ~
21777 \SpecialChar ~
21778 \SpecialChar ~
21779 \SpecialChar ~
21780 \SpecialChar ~
21781 \SpecialChar ~
21782 \SpecialChar ~
21783 \SpecialChar ~
21784 \SpecialChar ~
21785 \SpecialChar ~
21786 sdcdb-step-from-src\SpecialChar ~
21787 \SpecialChar ~
21788 \SpecialChar ~
21789 \SpecialChar ~
21790 \SpecialChar ~
21791 \SpecialChar ~
21792 \SpecialChar ~
21793 \SpecialChar ~
21794 \SpecialChar ~
21795 \SpecialChar ~
21796 SDCDB step command 
21797 \newline 
21798 ;;\SpecialChar ~
21799 ?\SpecialChar ~
21800 \SpecialChar ~
21801 \SpecialChar ~
21802 \SpecialChar ~
21803 \SpecialChar ~
21804 \SpecialChar ~
21805 \SpecialChar ~
21806 \SpecialChar ~
21807 \SpecialChar ~
21808 \SpecialChar ~
21809 \SpecialChar ~
21810 \SpecialChar ~
21811 \SpecialChar ~
21812 \SpecialChar ~
21813 \SpecialChar ~
21814 sdcdb-whatis-c-sexp\SpecialChar ~
21815 \SpecialChar ~
21816 \SpecialChar ~
21817 \SpecialChar ~
21818 \SpecialChar ~
21819 \SpecialChar ~
21820 \SpecialChar ~
21821 \SpecialChar ~
21822 \SpecialChar ~
21823 \SpecialChar ~
21824 SDCDB ptypecommand for data at 
21825 \newline 
21826 ;;\SpecialChar ~
21827 \SpecialChar ~
21828 \SpecialChar ~
21829 \SpecialChar ~
21830 \SpecialChar ~
21831 \SpecialChar ~
21832 \SpecialChar ~
21833 \SpecialChar ~
21834 \SpecialChar ~
21835 \SpecialChar ~
21836 \SpecialChar ~
21837 \SpecialChar ~
21838 \SpecialChar ~
21839 \SpecialChar ~
21840 \SpecialChar ~
21841 \SpecialChar ~
21842 \SpecialChar ~
21843 \SpecialChar ~
21844 \SpecialChar ~
21845 \SpecialChar ~
21846 \SpecialChar ~
21847 \SpecialChar ~
21848 \SpecialChar ~
21849 \SpecialChar ~
21850 \SpecialChar ~
21851 \SpecialChar ~
21852 \SpecialChar ~
21853 \SpecialChar ~
21854 \SpecialChar ~
21855 \SpecialChar ~
21856 \SpecialChar ~
21857 \SpecialChar ~
21858 \SpecialChar ~
21859 \SpecialChar ~
21860 \SpecialChar ~
21861 \SpecialChar ~
21862 \SpecialChar ~
21863 \SpecialChar ~
21864 \SpecialChar ~
21865 \SpecialChar ~
21866 \SpecialChar ~
21867 \SpecialChar ~
21868 \SpecialChar ~
21869 \SpecialChar ~
21870 \SpecialChar ~
21871 \SpecialChar ~
21872 \SpecialChar ~
21873 buffer point 
21874 \newline 
21875 ;;\SpecialChar ~
21876 x\SpecialChar ~
21877 \SpecialChar ~
21878 \SpecialChar ~
21879 \SpecialChar ~
21880 \SpecialChar ~
21881 \SpecialChar ~
21882 \SpecialChar ~
21883 \SpecialChar ~
21884 \SpecialChar ~
21885 \SpecialChar ~
21886 \SpecialChar ~
21887 \SpecialChar ~
21888 \SpecialChar ~
21889 \SpecialChar ~
21890 \SpecialChar ~
21891 sdcdbsrc-delete\SpecialChar ~
21892 \SpecialChar ~
21893 \SpecialChar ~
21894 \SpecialChar ~
21895 \SpecialChar ~
21896 \SpecialChar ~
21897 \SpecialChar ~
21898 \SpecialChar ~
21899 \SpecialChar ~
21900 \SpecialChar ~
21901 \SpecialChar ~
21902 \SpecialChar ~
21903 \SpecialChar ~
21904 \SpecialChar ~
21905 SDCDB Delete all breakpoints if no arg 
21906 \newline 
21907 ;;\SpecialChar ~
21908 \SpecialChar ~
21909 \SpecialChar ~
21910 \SpecialChar ~
21911 \SpecialChar ~
21912 \SpecialChar ~
21913 \SpecialChar ~
21914 \SpecialChar ~
21915 \SpecialChar ~
21916 \SpecialChar ~
21917 \SpecialChar ~
21918 \SpecialChar ~
21919 \SpecialChar ~
21920 \SpecialChar ~
21921 \SpecialChar ~
21922 \SpecialChar ~
21923 \SpecialChar ~
21924 \SpecialChar ~
21925 \SpecialChar ~
21926 \SpecialChar ~
21927 \SpecialChar ~
21928 \SpecialChar ~
21929 \SpecialChar ~
21930 \SpecialChar ~
21931 \SpecialChar ~
21932 \SpecialChar ~
21933 \SpecialChar ~
21934 \SpecialChar ~
21935 \SpecialChar ~
21936 \SpecialChar ~
21937 \SpecialChar ~
21938 \SpecialChar ~
21939 \SpecialChar ~
21940 \SpecialChar ~
21941 \SpecialChar ~
21942 \SpecialChar ~
21943 \SpecialChar ~
21944 \SpecialChar ~
21945 \SpecialChar ~
21946 \SpecialChar ~
21947 \SpecialChar ~
21948 \SpecialChar ~
21949 \SpecialChar ~
21950 \SpecialChar ~
21951 \SpecialChar ~
21952 \SpecialChar ~
21953 \SpecialChar ~
21954 given or delete arg (C-u arg x) 
21955 \newline 
21956 ;;\SpecialChar ~
21957 m\SpecialChar ~
21958 \SpecialChar ~
21959 \SpecialChar ~
21960 \SpecialChar ~
21961 \SpecialChar ~
21962 \SpecialChar ~
21963 \SpecialChar ~
21964 \SpecialChar ~
21965 \SpecialChar ~
21966 \SpecialChar ~
21967 \SpecialChar ~
21968 \SpecialChar ~
21969 \SpecialChar ~
21970 \SpecialChar ~
21971 \SpecialChar ~
21972 sdcdbsrc-frame\SpecialChar ~
21973 \SpecialChar ~
21974 \SpecialChar ~
21975 \SpecialChar ~
21976 \SpecialChar ~
21977 \SpecialChar ~
21978 \SpecialChar ~
21979 \SpecialChar ~
21980 \SpecialChar ~
21981 \SpecialChar ~
21982 \SpecialChar ~
21983 \SpecialChar ~
21984 \SpecialChar ~
21985 \SpecialChar ~
21986 \SpecialChar ~
21987 SDCDB Display current frame if no arg, 
21988 \newline 
21989 ;;\SpecialChar ~
21990 \SpecialChar ~
21991 \SpecialChar ~
21992 \SpecialChar ~
21993 \SpecialChar ~
21994 \SpecialChar ~
21995 \SpecialChar ~
21996 \SpecialChar ~
21997 \SpecialChar ~
21998 \SpecialChar ~
21999 \SpecialChar ~
22000 \SpecialChar ~
22001 \SpecialChar ~
22002 \SpecialChar ~
22003 \SpecialChar ~
22004 \SpecialChar ~
22005 \SpecialChar ~
22006 \SpecialChar ~
22007 \SpecialChar ~
22008 \SpecialChar ~
22009 \SpecialChar ~
22010 \SpecialChar ~
22011 \SpecialChar ~
22012 \SpecialChar ~
22013 \SpecialChar ~
22014 \SpecialChar ~
22015 \SpecialChar ~
22016 \SpecialChar ~
22017 \SpecialChar ~
22018 \SpecialChar ~
22019 \SpecialChar ~
22020 \SpecialChar ~
22021 \SpecialChar ~
22022 \SpecialChar ~
22023 \SpecialChar ~
22024 \SpecialChar ~
22025 \SpecialChar ~
22026 \SpecialChar ~
22027 \SpecialChar ~
22028 \SpecialChar ~
22029 \SpecialChar ~
22030 \SpecialChar ~
22031 \SpecialChar ~
22032 \SpecialChar ~
22033 \SpecialChar ~
22034 \SpecialChar ~
22035 \SpecialChar ~
22036 given or display frame arg 
22037 \newline 
22038 ;;\SpecialChar ~
22039 \SpecialChar ~
22040 \SpecialChar ~
22041 \SpecialChar ~
22042 \SpecialChar ~
22043 \SpecialChar ~
22044 \SpecialChar ~
22045 \SpecialChar ~
22046 \SpecialChar ~
22047 \SpecialChar ~
22048 \SpecialChar ~
22049 \SpecialChar ~
22050 \SpecialChar ~
22051 \SpecialChar ~
22052 \SpecialChar ~
22053 \SpecialChar ~
22054 \SpecialChar ~
22055 \SpecialChar ~
22056 \SpecialChar ~
22057 \SpecialChar ~
22058 \SpecialChar ~
22059 \SpecialChar ~
22060 \SpecialChar ~
22061 \SpecialChar ~
22062 \SpecialChar ~
22063 \SpecialChar ~
22064 \SpecialChar ~
22065 \SpecialChar ~
22066 \SpecialChar ~
22067 \SpecialChar ~
22068 \SpecialChar ~
22069 \SpecialChar ~
22070 \SpecialChar ~
22071 \SpecialChar ~
22072 \SpecialChar ~
22073 \SpecialChar ~
22074 \SpecialChar ~
22075 \SpecialChar ~
22076 \SpecialChar ~
22077 \SpecialChar ~
22078 \SpecialChar ~
22079 \SpecialChar ~
22080 \SpecialChar ~
22081 \SpecialChar ~
22082 \SpecialChar ~
22083 \SpecialChar ~
22084 \SpecialChar ~
22085 buffer point 
22086 \newline 
22087 ;;\SpecialChar ~
22088 !\SpecialChar ~
22089 \SpecialChar ~
22090 \SpecialChar ~
22091 \SpecialChar ~
22092 \SpecialChar ~
22093 \SpecialChar ~
22094 \SpecialChar ~
22095 \SpecialChar ~
22096 \SpecialChar ~
22097 \SpecialChar ~
22098 \SpecialChar ~
22099 \SpecialChar ~
22100 \SpecialChar ~
22101 \SpecialChar ~
22102 \SpecialChar ~
22103 sdcdbsrc-goto-sdcdb\SpecialChar ~
22104 \SpecialChar ~
22105 \SpecialChar ~
22106 \SpecialChar ~
22107 \SpecialChar ~
22108 \SpecialChar ~
22109 \SpecialChar ~
22110 \SpecialChar ~
22111 \SpecialChar ~
22112 \SpecialChar ~
22113 Goto the SDCDB output buffer 
22114 \newline 
22115 ;;\SpecialChar ~
22116 p\SpecialChar ~
22117 \SpecialChar ~
22118 \SpecialChar ~
22119 \SpecialChar ~
22120 \SpecialChar ~
22121 \SpecialChar ~
22122 \SpecialChar ~
22123 \SpecialChar ~
22124 \SpecialChar ~
22125 \SpecialChar ~
22126 \SpecialChar ~
22127 \SpecialChar ~
22128 \SpecialChar ~
22129 \SpecialChar ~
22130 \SpecialChar ~
22131 sdcdb-print-c-sexp\SpecialChar ~
22132 \SpecialChar ~
22133 \SpecialChar ~
22134 \SpecialChar ~
22135 \SpecialChar ~
22136 \SpecialChar ~
22137 \SpecialChar ~
22138 \SpecialChar ~
22139 \SpecialChar ~
22140 \SpecialChar ~
22141 \SpecialChar ~
22142 SDCDB print command for data at 
22143 \newline 
22144 ;;\SpecialChar ~
22145 \SpecialChar ~
22146 \SpecialChar ~
22147 \SpecialChar ~
22148 \SpecialChar ~
22149 \SpecialChar ~
22150 \SpecialChar ~
22151 \SpecialChar ~
22152 \SpecialChar ~
22153 \SpecialChar ~
22154 \SpecialChar ~
22155 \SpecialChar ~
22156 \SpecialChar ~
22157 \SpecialChar ~
22158 \SpecialChar ~
22159 \SpecialChar ~
22160 \SpecialChar ~
22161 \SpecialChar ~
22162 \SpecialChar ~
22163 \SpecialChar ~
22164 \SpecialChar ~
22165 \SpecialChar ~
22166 \SpecialChar ~
22167 \SpecialChar ~
22168 \SpecialChar ~
22169 \SpecialChar ~
22170 \SpecialChar ~
22171 \SpecialChar ~
22172 \SpecialChar ~
22173 \SpecialChar ~
22174 \SpecialChar ~
22175 \SpecialChar ~
22176 \SpecialChar ~
22177 \SpecialChar ~
22178 \SpecialChar ~
22179 \SpecialChar ~
22180 \SpecialChar ~
22181 \SpecialChar ~
22182 \SpecialChar ~
22183 \SpecialChar ~
22184 \SpecialChar ~
22185 \SpecialChar ~
22186 \SpecialChar ~
22187 \SpecialChar ~
22188 \SpecialChar ~
22189 \SpecialChar ~
22190 \SpecialChar ~
22191 buffer point 
22192 \newline 
22193 ;;\SpecialChar ~
22194 g\SpecialChar ~
22195 \SpecialChar ~
22196 \SpecialChar ~
22197 \SpecialChar ~
22198 \SpecialChar ~
22199 \SpecialChar ~
22200 \SpecialChar ~
22201 \SpecialChar ~
22202 \SpecialChar ~
22203 \SpecialChar ~
22204 \SpecialChar ~
22205 \SpecialChar ~
22206 \SpecialChar ~
22207 \SpecialChar ~
22208 \SpecialChar ~
22209 sdcdbsrc-goto-sdcdb\SpecialChar ~
22210 \SpecialChar ~
22211 \SpecialChar ~
22212 \SpecialChar ~
22213 \SpecialChar ~
22214 \SpecialChar ~
22215 \SpecialChar ~
22216 \SpecialChar ~
22217 \SpecialChar ~
22218 \SpecialChar ~
22219 Goto the SDCDB output buffer 
22220 \newline 
22221 ;;\SpecialChar ~
22222 t\SpecialChar ~
22223 \SpecialChar ~
22224 \SpecialChar ~
22225 \SpecialChar ~
22226 \SpecialChar ~
22227 \SpecialChar ~
22228 \SpecialChar ~
22229 \SpecialChar ~
22230 \SpecialChar ~
22231 \SpecialChar ~
22232 \SpecialChar ~
22233 \SpecialChar ~
22234 \SpecialChar ~
22235 \SpecialChar ~
22236 \SpecialChar ~
22237 sdcdbsrc-mode\SpecialChar ~
22238 \SpecialChar ~
22239 \SpecialChar ~
22240 \SpecialChar ~
22241 \SpecialChar ~
22242 \SpecialChar ~
22243 \SpecialChar ~
22244 \SpecialChar ~
22245 \SpecialChar ~
22246 \SpecialChar ~
22247 \SpecialChar ~
22248 \SpecialChar ~
22249 \SpecialChar ~
22250 \SpecialChar ~
22251 \SpecialChar ~
22252 \SpecialChar ~
22253 Toggles Sdcdbsrc mode (turns it off) 
22254 \newline 
22255 ;; 
22256 \newline 
22257 ;;\SpecialChar ~
22258 C-c\SpecialChar ~
22259 C-f\SpecialChar ~
22260 \SpecialChar ~
22261 \SpecialChar ~
22262 \SpecialChar ~
22263 \SpecialChar ~
22264 \SpecialChar ~
22265 \SpecialChar ~
22266 \SpecialChar ~
22267 \SpecialChar ~
22268 sdcdb-finish-from-src\SpecialChar ~
22269 \SpecialChar ~
22270 \SpecialChar ~
22271 \SpecialChar ~
22272 \SpecialChar ~
22273 \SpecialChar ~
22274 \SpecialChar ~
22275 \SpecialChar ~
22276 SDCDB finish command 
22277 \newline 
22278 ;; 
22279 \newline 
22280 ;;\SpecialChar ~
22281 C-x\SpecialChar ~
22282 SPC\SpecialChar ~
22283 \SpecialChar ~
22284 \SpecialChar ~
22285 \SpecialChar ~
22286 \SpecialChar ~
22287 \SpecialChar ~
22288 \SpecialChar ~
22289 \SpecialChar ~
22290 \SpecialChar ~
22291 sdcdb-break\SpecialChar ~
22292 \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 \SpecialChar ~
22307 \SpecialChar ~
22308 \SpecialChar ~
22309 Set break for line with point 
22310 \newline 
22311 ;;\SpecialChar ~
22312 ESC\SpecialChar ~
22313 t\SpecialChar ~
22314 \SpecialChar ~
22315 \SpecialChar ~
22316 \SpecialChar ~
22317 \SpecialChar ~
22318 \SpecialChar ~
22319 \SpecialChar ~
22320 \SpecialChar ~
22321 \SpecialChar ~
22322 \SpecialChar ~
22323 \SpecialChar ~
22324 sdcdbsrc-mode\SpecialChar ~
22325 \SpecialChar ~
22326 \SpecialChar ~
22327 \SpecialChar ~
22328 \SpecialChar ~
22329 \SpecialChar ~
22330 \SpecialChar ~
22331 \SpecialChar ~
22332 \SpecialChar ~
22333 \SpecialChar ~
22334 \SpecialChar ~
22335 \SpecialChar ~
22336 \SpecialChar ~
22337 \SpecialChar ~
22338 \SpecialChar ~
22339 \SpecialChar ~
22340 Toggle Sdcdbsrc mode 
22341 \newline 
22342 ;;\SpecialChar ~
22343 ESC\SpecialChar ~
22344 m\SpecialChar ~
22345 \SpecialChar ~
22346 \SpecialChar ~
22347 \SpecialChar ~
22348 \SpecialChar ~
22349 \SpecialChar ~
22350 \SpecialChar ~
22351 \SpecialChar ~
22352 \SpecialChar ~
22353 \SpecialChar ~
22354 \SpecialChar ~
22355 sdcdbsrc-srcmode\SpecialChar ~
22356 \SpecialChar ~
22357 \SpecialChar ~
22358 \SpecialChar ~
22359 \SpecialChar ~
22360 \SpecialChar ~
22361 \SpecialChar ~
22362 \SpecialChar ~
22363 \SpecialChar ~
22364 \SpecialChar ~
22365 \SpecialChar ~
22366 \SpecialChar ~
22367 \SpecialChar ~
22368 Toggle list mode 
22369 \newline 
22370 ;; 
22371 \newline 
22372
22373 \layout Chapter
22374 \pagebreak_top 
22375 TIPS
22376 \layout Standard
22377
22378 Here are a few guidelines that will help the compiler generate more efficient
22379  code, some of the tips are specific to this compiler others are generally
22380  good programming practice.
22381 \layout Itemize
22382
22383 Use the smallest data type to represent your data-value.
22384  If it is known in advance that the value is going to be less than 256 then
22385  use an 'unsigned char' instead of a 'short' or 'int'.
22386  Please note, that ANSI C requires both signed and unsigned chars to be
22387  promoted to 'signed int'
22388 \begin_inset LatexCommand \index{promotion to signed int}
22389
22390 \end_inset 
22391
22392  before doing any operation.
22393  This promotion
22394 \begin_inset LatexCommand \index{type promotion}
22395
22396 \end_inset 
22397
22398
22399 \begin_inset LatexCommand \label{type promotion}
22400
22401 \end_inset 
22402
22403  can be omitted, if the result is the same.
22404  The effect of the promotion rules together with the sign-extension is often
22405  surprising:
22406 \begin_deeper 
22407 \layout Verse
22408
22409
22410 \family typewriter 
22411 unsigned char uc = 0xfe;
22412 \newline 
22413 if (uc * uc < 0) /* this is true! */
22414 \newline 
22415 {
22416 \newline 
22417 \SpecialChar ~
22418 \SpecialChar ~
22419 \SpecialChar ~
22420 \SpecialChar ~
22421 ....
22422 \newline 
22423 }
22424 \layout Standard
22425
22426
22427 \family typewriter 
22428 uc * uc
22429 \family default 
22430  is evaluated as 
22431 \family typewriter 
22432 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
22433 \family default 
22434 .
22435  
22436 \newline 
22437 Another one:
22438 \layout Verse
22439
22440
22441 \family typewriter 
22442 (unsigned char) -12 / (signed char) -3 = ...
22443 \layout Standard
22444
22445 No, the result is not 4:
22446 \layout Verse
22447
22448
22449 \family typewriter 
22450 (int) (unsigned char) -12 / (int) (signed char) -3 =
22451 \newline 
22452 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
22453 \newline 
22454 (int) 0x00f4 / (int) 0xfffd =
22455 \newline 
22456 (int) 0x00f4 / (int) 0xfffd =
22457 \newline 
22458 (int) 244 / (int) -3 =
22459 \newline 
22460 (int) -81 = (int) 0xffaf;
22461 \layout Standard
22462
22463 Don't complain, that gcc gives you a different result.
22464  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
22465  Therefore the results are different.
22466 \newline 
22467 From 
22468 \begin_inset Quotes sld
22469 \end_inset 
22470
22471 comp.lang.c FAQ
22472 \begin_inset Quotes srd
22473 \end_inset 
22474
22475 :
22476 \layout Quote
22477
22478 If well-defined overflow characteristics are important and negative values
22479  are not, or if you want to steer clear of sign-extension problems when
22480  manipulating bits or bytes, use one of the corresponding unsigned types.
22481  (Beware when mixing signed and unsigned values in expressions, though.)
22482 \newline 
22483 Although character types (especially unsigned char) can be used as "tiny"
22484  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
22485 ble sign extension and increased code size.
22486 \end_deeper 
22487 \layout Itemize
22488
22489 Use unsigned when it is known in advance that the value is not going to
22490  be negative.
22491  This helps especially if you are doing division or multiplication, bit-shifting
22492  or are using an array index.
22493 \layout Itemize
22494
22495 NEVER jump into a LOOP.
22496 \layout Itemize
22497
22498 Declare the variables to be local
22499 \begin_inset LatexCommand \index{local variables}
22500
22501 \end_inset 
22502
22503  whenever possible, especially loop control variables (induction).
22504 \layout Itemize
22505
22506 Since the compiler does not always do implicit integral promotion, the programme
22507 r should do an explicit cast when integral promotion is required.
22508 \layout Itemize
22509
22510 Reducing the size of division, multiplication & modulus operations can reduce
22511  code size substantially.
22512  Take the following code for example.
22513 \begin_deeper 
22514 \layout Verse
22515
22516
22517 \family typewriter 
22518 foobar(unsigned int p1, unsigned char ch)
22519 \newline 
22520 {
22521 \newline 
22522 \SpecialChar ~
22523 \SpecialChar ~
22524 \SpecialChar ~
22525 \SpecialChar ~
22526 unsigned char ch1 = p1 % ch ;
22527 \newline 
22528 \SpecialChar ~
22529 \SpecialChar ~
22530 \SpecialChar ~
22531 \SpecialChar ~
22532 ....
22533 \newline 
22534 }
22535 \layout Standard
22536
22537 For the modulus operation the variable ch will be promoted to unsigned int
22538  first then the modulus operation will be performed (this will lead to a
22539  call to support routine _moduint()), and the result will be casted to a
22540  char.
22541  If the code is changed to 
22542 \layout Verse
22543
22544
22545 \family typewriter 
22546 foobar(unsigned int p1, unsigned char ch)
22547 \newline 
22548 {
22549 \newline 
22550 \SpecialChar ~
22551 \SpecialChar ~
22552 \SpecialChar ~
22553 \SpecialChar ~
22554 unsigned char ch1 = (unsigned char)p1 % ch ;
22555 \newline 
22556 \SpecialChar ~
22557 \SpecialChar ~
22558 \SpecialChar ~
22559 \SpecialChar ~
22560 ....
22561 \newline 
22562 }
22563 \layout Standard
22564
22565 It would substantially reduce the code generated (future versions of the
22566  compiler will be smart enough to detect such optimization opportunities).
22567 \end_deeper 
22568 \layout Itemize
22569
22570 Have a look at the assembly listing to get a 
22571 \begin_inset Quotes sld
22572 \end_inset 
22573
22574 feeling
22575 \begin_inset Quotes srd
22576 \end_inset 
22577
22578  for the code generation.
22579 \layout Section
22580
22581 Porting code from or to other compilers
22582 \layout Itemize
22583
22584 check whether endianness of the compilers differs and adapt where needed.
22585 \layout Itemize
22586
22587 check the device specific header files for compiler specific syntax.
22588  Eventually include the file <compiler.h
22589 \begin_inset LatexCommand \index{compiler.h (include file)}
22590
22591 \end_inset 
22592
22593 > to allow using common header files.
22594 \layout Itemize
22595
22596 check whether the startup code contains the correct initialization (watchdog,
22597  peripherals).
22598 \layout Itemize
22599
22600 check whether the sizes of short, int, long match.
22601 \layout Itemize
22602
22603 check if some 16 or 32 bit hardware registers require a specific addressing
22604  order (least significant or most significant byte first) and adapt if needed
22605  (
22606 \emph on 
22607 first
22608 \emph default 
22609  and 
22610 \emph on 
22611 last
22612 \emph default 
22613  relate to time and not to lower/upper memory location here, so this is
22614  
22615 \emph on 
22616 not
22617 \emph default 
22618  the same as endianness).
22619 \layout Itemize
22620
22621 check whether the keyword 
22622 \emph on 
22623 volatile
22624 \emph default 
22625  is used where needed.
22626  The compilers might differ in their optimization characteristics (as different
22627  versions of the same compiler might also use more clever optimizations
22628  this is good idea anyway).
22629 \layout Itemize
22630
22631 check that the compilers are not told to supress warnings.
22632 \layout Itemize
22633
22634 check and convert compiler specific extensions (interrupts, memory areas,
22635  pragmas etc.).
22636 \layout Itemize
22637
22638 check for differences in type promotion (especially check for math operations
22639  on char variables and for the use of the ~\SpecialChar ~
22640 operator on bit variables.
22641  See 
22642 \begin_inset LatexCommand \ref{type promotion}
22643
22644 \end_inset 
22645
22646  and 
22647 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
22648
22649 \end_inset 
22650
22651 ).
22652 \layout Itemize
22653
22654 check the assembly code generated for interrupt routines (f.e.
22655  for calls to possibly non-reentrant library functions).
22656 \layout Itemize
22657
22658 check whether timing loops result in proper timing (or preferably consider
22659  a rewrite of the code with timer based delays instead).
22660 \layout Itemize
22661
22662 check for differences in printf parameters (some compilers push (va_arg
22663 \begin_inset LatexCommand \index{va\_arg}
22664
22665 \end_inset 
22666
22667 ) char variables as integers others as char).
22668 \layout Itemize
22669
22670 check the resulting memory layout.
22671 \layout Section
22672
22673 Tools
22674 \begin_inset LatexCommand \index{Tools}
22675
22676 \end_inset 
22677
22678  included in the distribution
22679 \layout Standard
22680 \align center 
22681
22682 \begin_inset  Tabular
22683 <lyxtabular version="3" rows="12" columns="3">
22684 <features>
22685 <column alignment="left" valignment="top" leftline="true" width="0pt">
22686 <column alignment="left" valignment="top" leftline="true" width="0pt">
22687 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
22688 <row topline="true" bottomline="true">
22689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22690 \begin_inset Text
22691
22692 \layout Standard
22693
22694 Name
22695 \end_inset 
22696 </cell>
22697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22698 \begin_inset Text
22699
22700 \layout Standard
22701
22702 Purpose
22703 \end_inset 
22704 </cell>
22705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22706 \begin_inset Text
22707
22708 \layout Standard
22709
22710 Directory
22711 \end_inset 
22712 </cell>
22713 </row>
22714 <row topline="true">
22715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22716 \begin_inset Text
22717
22718 \layout Standard
22719
22720 uCsim
22721 \end_inset 
22722 </cell>
22723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22724 \begin_inset Text
22725
22726 \layout Standard
22727
22728 Simulator for various architectures
22729 \end_inset 
22730 </cell>
22731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22732 \begin_inset Text
22733
22734 \layout Standard
22735
22736 sdcc/sim/ucsim
22737 \end_inset 
22738 </cell>
22739 </row>
22740 <row topline="true">
22741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22742 \begin_inset Text
22743
22744 \layout Standard
22745
22746 keil2sdcc.pl
22747 \end_inset 
22748 </cell>
22749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22750 \begin_inset Text
22751
22752 \layout Standard
22753
22754 header file conversion
22755 \end_inset 
22756 </cell>
22757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22758 \begin_inset Text
22759
22760 \layout Standard
22761
22762 sdcc/support/scripts
22763 \end_inset 
22764 </cell>
22765 </row>
22766 <row topline="true">
22767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22768 \begin_inset Text
22769
22770 \layout Standard
22771
22772 mh2h.c
22773 \end_inset 
22774 </cell>
22775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22776 \begin_inset Text
22777
22778 \layout Standard
22779
22780 header file conversion
22781 \end_inset 
22782 </cell>
22783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22784 \begin_inset Text
22785
22786 \layout Standard
22787
22788 sdcc/support/scripts
22789 \end_inset 
22790 </cell>
22791 </row>
22792 <row topline="true">
22793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22794 \begin_inset Text
22795
22796 \layout Standard
22797
22798 as-gbz80
22799 \end_inset 
22800 </cell>
22801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22802 \begin_inset Text
22803
22804 \layout Standard
22805
22806 Assembler
22807 \end_inset 
22808 </cell>
22809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22810 \begin_inset Text
22811
22812 \layout Standard
22813
22814
22815 \family roman 
22816 \series medium 
22817 \shape up 
22818 \size normal 
22819 \emph off 
22820 \bar no 
22821 \noun off 
22822 \color none
22823 sdcc/bin
22824 \end_inset 
22825 </cell>
22826 </row>
22827 <row topline="true">
22828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22829 \begin_inset Text
22830
22831 \layout Standard
22832
22833 as-z80
22834 \end_inset 
22835 </cell>
22836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22837 \begin_inset Text
22838
22839 \layout Standard
22840
22841 Assembler
22842 \end_inset 
22843 </cell>
22844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22845 \begin_inset Text
22846
22847 \layout Standard
22848
22849
22850 \family roman 
22851 \series medium 
22852 \shape up 
22853 \size normal 
22854 \emph off 
22855 \bar no 
22856 \noun off 
22857 \color none
22858 sdcc/bin
22859 \end_inset 
22860 </cell>
22861 </row>
22862 <row topline="true">
22863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22864 \begin_inset Text
22865
22866 \layout Standard
22867
22868 asx8051
22869 \end_inset 
22870 </cell>
22871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22872 \begin_inset Text
22873
22874 \layout Standard
22875
22876 Assembler
22877 \end_inset 
22878 </cell>
22879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22880 \begin_inset Text
22881
22882 \layout Standard
22883
22884
22885 \family roman 
22886 \series medium 
22887 \shape up 
22888 \size normal 
22889 \emph off 
22890 \bar no 
22891 \noun off 
22892 \color none
22893 sdcc/bin
22894 \end_inset 
22895 </cell>
22896 </row>
22897 <row topline="true">
22898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22899 \begin_inset Text
22900
22901 \layout Standard
22902
22903 sdcdb
22904 \end_inset 
22905 </cell>
22906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22907 \begin_inset Text
22908
22909 \layout Standard
22910
22911 Simulator
22912 \end_inset 
22913 </cell>
22914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22915 \begin_inset Text
22916
22917 \layout Standard
22918
22919
22920 \family roman 
22921 \series medium 
22922 \shape up 
22923 \size normal 
22924 \emph off 
22925 \bar no 
22926 \noun off 
22927 \color none
22928 sdcc/bin
22929 \end_inset 
22930 </cell>
22931 </row>
22932 <row topline="true">
22933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22934 \begin_inset Text
22935
22936 \layout Standard
22937
22938 aslink
22939 \end_inset 
22940 </cell>
22941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22942 \begin_inset Text
22943
22944 \layout Standard
22945
22946 Linker
22947 \end_inset 
22948 </cell>
22949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22950 \begin_inset Text
22951
22952 \layout Standard
22953
22954
22955 \family roman 
22956 \series medium 
22957 \shape up 
22958 \size normal 
22959 \emph off 
22960 \bar no 
22961 \noun off 
22962 \color none
22963 sdcc/bin
22964 \end_inset 
22965 </cell>
22966 </row>
22967 <row topline="true">
22968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22969 \begin_inset Text
22970
22971 \layout Standard
22972
22973 link-z80
22974 \end_inset 
22975 </cell>
22976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22977 \begin_inset Text
22978
22979 \layout Standard
22980
22981 Linker
22982 \end_inset 
22983 </cell>
22984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22985 \begin_inset Text
22986
22987 \layout Standard
22988
22989
22990 \family roman 
22991 \series medium 
22992 \shape up 
22993 \size normal 
22994 \emph off 
22995 \bar no 
22996 \noun off 
22997 \color none
22998 sdcc/bin
22999 \end_inset 
23000 </cell>
23001 </row>
23002 <row topline="true">
23003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23004 \begin_inset Text
23005
23006 \layout Standard
23007
23008 link-gbz80
23009 \end_inset 
23010 </cell>
23011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23012 \begin_inset Text
23013
23014 \layout Standard
23015
23016 Linker
23017 \end_inset 
23018 </cell>
23019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23020 \begin_inset Text
23021
23022 \layout Standard
23023
23024
23025 \family roman 
23026 \series medium 
23027 \shape up 
23028 \size normal 
23029 \emph off 
23030 \bar no 
23031 \noun off 
23032 \color none
23033 sdcc/bin
23034 \end_inset 
23035 </cell>
23036 </row>
23037 <row topline="true" bottomline="true">
23038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23039 \begin_inset Text
23040
23041 \layout Standard
23042
23043 packihx
23044 \end_inset 
23045 </cell>
23046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23047 \begin_inset Text
23048
23049 \layout Standard
23050
23051 ihx packer
23052 \end_inset 
23053 </cell>
23054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23055 \begin_inset Text
23056
23057 \layout Standard
23058
23059
23060 \family roman 
23061 \series medium 
23062 \shape up 
23063 \size normal 
23064 \emph off 
23065 \bar no 
23066 \noun off 
23067 \color none
23068 sdcc/bin
23069 \end_inset 
23070 </cell>
23071 </row>
23072 </lyxtabular>
23073
23074 \end_inset 
23075
23076
23077 \newline 
23078
23079 \layout Section
23080
23081 Documentation
23082 \begin_inset LatexCommand \index{Documentation}
23083
23084 \end_inset 
23085
23086  included in the distribution
23087 \layout Standard
23088 \align center 
23089
23090 \begin_inset  Tabular
23091 <lyxtabular version="3" rows="10" columns="2">
23092 <features>
23093 <column alignment="left" valignment="top" leftline="true" width="0">
23094 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23095 <row topline="true" bottomline="true">
23096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23097 \begin_inset Text
23098
23099 \layout Standard
23100
23101 Subject / Title
23102 \end_inset 
23103 </cell>
23104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23105 \begin_inset Text
23106
23107 \layout Standard
23108
23109 Where to get / filename
23110 \end_inset 
23111 </cell>
23112 </row>
23113 <row topline="true">
23114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23115 \begin_inset Text
23116
23117 \layout Standard
23118
23119 SDCC Compiler User Guide
23120 \end_inset 
23121 </cell>
23122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23123 \begin_inset Text
23124
23125 \layout Standard
23126
23127 You're reading it right now
23128 \end_inset 
23129 </cell>
23130 </row>
23131 <row topline="true">
23132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23133 \begin_inset Text
23134
23135 \layout Standard
23136
23137 Changelog of SDCC
23138 \end_inset 
23139 </cell>
23140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23141 \begin_inset Text
23142
23143 \layout Standard
23144
23145 sdcc/Changelog
23146 \end_inset 
23147 </cell>
23148 </row>
23149 <row topline="true">
23150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23151 \begin_inset Text
23152
23153 \layout Standard
23154
23155 ASXXXX
23156 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
23157
23158 \end_inset 
23159
23160
23161 \begin_inset LatexCommand \index{Assembler documentation}
23162
23163 \end_inset 
23164
23165  Assemblers and ASLINK
23166 \begin_inset LatexCommand \index{aslink}
23167
23168 \end_inset 
23169
23170
23171 \begin_inset LatexCommand \index{Linker documentation}
23172
23173 \end_inset 
23174
23175  Relocating Linker
23176 \end_inset 
23177 </cell>
23178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23179 \begin_inset Text
23180
23181 \layout Standard
23182
23183 sdcc/as/doc/asxhtm.html
23184 \end_inset 
23185 </cell>
23186 </row>
23187 <row topline="true">
23188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23189 \begin_inset Text
23190
23191 \layout Standard
23192
23193 SDCC regression test
23194 \begin_inset LatexCommand \index{Regression test}
23195
23196 \end_inset 
23197
23198
23199 \end_inset 
23200 </cell>
23201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23202 \begin_inset Text
23203
23204 \layout Standard
23205
23206 sdcc/doc/test_suite_spec.pdf
23207 \end_inset 
23208 </cell>
23209 </row>
23210 <row topline="true">
23211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23212 \begin_inset Text
23213
23214 \layout Standard
23215
23216 Various notes
23217 \end_inset 
23218 </cell>
23219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23220 \begin_inset Text
23221
23222 \layout Standard
23223
23224 sdcc/doc/*
23225 \end_inset 
23226 </cell>
23227 </row>
23228 <row topline="true">
23229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23230 \begin_inset Text
23231
23232 \layout Standard
23233
23234 Notes on debugging with sdcdb
23235 \begin_inset LatexCommand \index{sdcdb (debugger)}
23236
23237 \end_inset 
23238
23239
23240 \end_inset 
23241 </cell>
23242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23243 \begin_inset Text
23244
23245 \layout Standard
23246
23247 sdcc/debugger/README
23248 \end_inset 
23249 </cell>
23250 </row>
23251 <row topline="true">
23252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23253 \begin_inset Text
23254
23255 \layout Standard
23256
23257 Software simulator for microcontrollers
23258 \end_inset 
23259 </cell>
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23261 \begin_inset Text
23262
23263 \layout Standard
23264
23265
23266 \family roman 
23267 \series medium 
23268 \shape up 
23269 \size normal 
23270 \emph off 
23271 \bar no 
23272 \noun off 
23273 \color none
23274 sdcc/sim/ucsim/doc
23275 \family default 
23276 \series default 
23277 \shape default 
23278 \size default 
23279 \emph default 
23280 \bar default 
23281 \noun default 
23282 \color default
23283 /index.html
23284 \end_inset 
23285 </cell>
23286 </row>
23287 <row topline="true">
23288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23289 \begin_inset Text
23290
23291 \layout Standard
23292
23293 Temporary notes on the pic16
23294 \begin_inset LatexCommand \index{PIC16}
23295
23296 \end_inset 
23297
23298  port
23299 \end_inset 
23300 </cell>
23301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23302 \begin_inset Text
23303
23304 \layout Standard
23305
23306 sdcc/src/pic16/NOTES
23307 \end_inset 
23308 </cell>
23309 </row>
23310 <row topline="true" bottomline="true">
23311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23312 \begin_inset Text
23313
23314 \layout Standard
23315
23316 SDCC internal documentation (debugging file format)
23317 \end_inset 
23318 </cell>
23319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23320 \begin_inset Text
23321
23322 \layout Standard
23323
23324 sdcc/doc/
23325 \family roman 
23326 \series medium 
23327 \shape up 
23328 \size normal 
23329 \emph off 
23330 \bar no 
23331 \noun off 
23332 \color none
23333 cdbfileformat.pd
23334 \family default 
23335 \series default 
23336 \shape default 
23337 \size default 
23338 \emph default 
23339 \bar default 
23340 \noun default 
23341 \color default
23342 f
23343 \end_inset 
23344 </cell>
23345 </row>
23346 </lyxtabular>
23347
23348 \end_inset 
23349
23350
23351 \newline 
23352
23353 \layout Section
23354
23355 Related open source tools
23356 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
23357
23358 \end_inset 
23359
23360
23361 \begin_inset LatexCommand \index{Related tools}
23362
23363 \end_inset 
23364
23365
23366 \layout Standard
23367 \align center 
23368
23369 \begin_inset  Tabular
23370 <lyxtabular version="3" rows="14" columns="3">
23371 <features>
23372 <column alignment="left" valignment="top" leftline="true" width="0pt">
23373 <column alignment="block" valignment="top" leftline="true" width="30line%">
23374 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23375 <row topline="true" bottomline="true">
23376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23377 \begin_inset Text
23378
23379 \layout Standard
23380
23381 Name
23382 \end_inset 
23383 </cell>
23384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23385 \begin_inset Text
23386
23387 \layout Standard
23388
23389 Purpose
23390 \end_inset 
23391 </cell>
23392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23393 \begin_inset Text
23394
23395 \layout Standard
23396
23397 Where to get
23398 \end_inset 
23399 </cell>
23400 </row>
23401 <row topline="true">
23402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23403 \begin_inset Text
23404
23405 \layout Standard
23406
23407 gpsim
23408 \begin_inset LatexCommand \index{gpsim (pic simulator)}
23409
23410 \end_inset 
23411
23412
23413 \end_inset 
23414 </cell>
23415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23416 \begin_inset Text
23417
23418 \layout Standard
23419
23420 PIC simulator
23421 \end_inset 
23422 </cell>
23423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23424 \begin_inset Text
23425
23426 \layout Standard
23427
23428
23429 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
23430
23431 \end_inset 
23432
23433
23434 \end_inset 
23435 </cell>
23436 </row>
23437 <row topline="true">
23438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23439 \begin_inset Text
23440
23441 \layout Standard
23442
23443 gputils
23444 \begin_inset LatexCommand \index{gputils (pic tools)}
23445
23446 \end_inset 
23447
23448
23449 \end_inset 
23450 </cell>
23451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23452 \begin_inset Text
23453
23454 \layout Standard
23455
23456 GNU PIC utilities
23457 \end_inset 
23458 </cell>
23459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23460 \begin_inset Text
23461
23462 \layout Standard
23463
23464
23465 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23466
23467 \end_inset 
23468
23469
23470 \end_inset 
23471 </cell>
23472 </row>
23473 <row topline="true">
23474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23475 \begin_inset Text
23476
23477 \layout Standard
23478
23479 flP5
23480 \end_inset 
23481 </cell>
23482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23483 \begin_inset Text
23484
23485 \layout Standard
23486
23487 PIC programmer
23488 \end_inset 
23489 </cell>
23490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23491 \begin_inset Text
23492
23493 \layout Standard
23494
23495
23496 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
23497
23498 \end_inset 
23499
23500
23501 \end_inset 
23502 </cell>
23503 </row>
23504 <row topline="true">
23505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23506 \begin_inset Text
23507
23508 \layout Standard
23509
23510 ec2drv/newcdb
23511 \end_inset 
23512 </cell>
23513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23514 \begin_inset Text
23515
23516 \layout Standard
23517
23518 Tools for Silicon Laboratories JTAG debug adapter, partly based on sdcdb
23519  (Unix only)
23520 \end_inset 
23521 </cell>
23522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23523 \begin_inset Text
23524
23525 \layout Standard
23526
23527
23528 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
23529
23530 \end_inset 
23531
23532
23533 \end_inset 
23534 </cell>
23535 </row>
23536 <row topline="true">
23537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23538 \begin_inset Text
23539
23540 \layout Standard
23541
23542 indent
23543 \begin_inset LatexCommand \index{indent (source formatting tool)}
23544
23545 \end_inset 
23546
23547
23548 \end_inset 
23549 </cell>
23550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23551 \begin_inset Text
23552
23553 \layout Standard
23554
23555 Formats C source - Master of the white spaces
23556 \end_inset 
23557 </cell>
23558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23559 \begin_inset Text
23560
23561 \layout Standard
23562
23563
23564 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
23565
23566 \end_inset 
23567
23568
23569 \end_inset 
23570 </cell>
23571 </row>
23572 <row topline="true">
23573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23574 \begin_inset Text
23575
23576 \layout Standard
23577
23578 srecord
23579 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
23580
23581 \end_inset 
23582
23583
23584 \end_inset 
23585 </cell>
23586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23587 \begin_inset Text
23588
23589 \layout Standard
23590
23591 Object file conversion, checksumming, ...
23592 \end_inset 
23593 </cell>
23594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23595 \begin_inset Text
23596
23597 \layout Standard
23598
23599
23600 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
23601
23602 \end_inset 
23603
23604
23605 \end_inset 
23606 </cell>
23607 </row>
23608 <row topline="true">
23609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23610 \begin_inset Text
23611
23612 \layout Standard
23613
23614 objdump
23615 \begin_inset LatexCommand \index{objdump (tool)}
23616
23617 \end_inset 
23618
23619
23620 \end_inset 
23621 </cell>
23622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23623 \begin_inset Text
23624
23625 \layout Standard
23626
23627 Object file conversion, ...
23628 \end_inset 
23629 </cell>
23630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23631 \begin_inset Text
23632
23633 \layout Standard
23634
23635 Part of binutils (should be there anyway)
23636 \end_inset 
23637 </cell>
23638 </row>
23639 <row topline="true">
23640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23641 \begin_inset Text
23642
23643 \layout Standard
23644
23645 cmon51
23646 \end_inset 
23647 </cell>
23648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23649 \begin_inset Text
23650
23651 \layout Standard
23652
23653 8051 monitor (hex up-/download, single step, disassemble)
23654 \end_inset 
23655 </cell>
23656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23657 \begin_inset Text
23658
23659 \layout Standard
23660
23661
23662 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
23663
23664 \end_inset 
23665
23666
23667 \end_inset 
23668 </cell>
23669 </row>
23670 <row topline="true">
23671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23672 \begin_inset Text
23673
23674 \layout Standard
23675
23676 doxygen
23677 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
23678
23679 \end_inset 
23680
23681
23682 \end_inset 
23683 </cell>
23684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23685 \begin_inset Text
23686
23687 \layout Standard
23688
23689 Source code documentation system
23690 \end_inset 
23691 </cell>
23692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23693 \begin_inset Text
23694
23695 \layout Standard
23696
23697
23698 \begin_inset LatexCommand \url{http://www.doxygen.org}
23699
23700 \end_inset 
23701
23702
23703 \end_inset 
23704 </cell>
23705 </row>
23706 <row topline="true">
23707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23708 \begin_inset Text
23709
23710 \layout Standard
23711
23712 kdevelop
23713 \end_inset 
23714 </cell>
23715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23716 \begin_inset Text
23717
23718 \layout Standard
23719
23720 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
23721 \end_inset 
23722 </cell>
23723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23724 \begin_inset Text
23725
23726 \layout Standard
23727
23728
23729 \begin_inset LatexCommand \url{http://www.kdevelop.org}
23730
23731 \end_inset 
23732
23733
23734 \end_inset 
23735 </cell>
23736 </row>
23737 <row topline="true">
23738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23739 \begin_inset Text
23740
23741 \layout Standard
23742
23743 paulmon
23744 \end_inset 
23745 </cell>
23746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23747 \begin_inset Text
23748
23749 \layout Standard
23750
23751 8051 monitor (hex up-/download, single step, disassemble)
23752 \end_inset 
23753 </cell>
23754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23755 \begin_inset Text
23756
23757 \layout Standard
23758
23759
23760 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
23761
23762 \end_inset 
23763
23764
23765 \end_inset 
23766 </cell>
23767 </row>
23768 <row topline="true">
23769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23770 \begin_inset Text
23771
23772 \layout Standard
23773
23774 splint
23775 \begin_inset LatexCommand \index{splint (syntax checking tool)}
23776
23777 \end_inset 
23778
23779
23780 \end_inset 
23781 </cell>
23782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23783 \begin_inset Text
23784
23785 \layout Standard
23786
23787 Statically checks c sources (see 
23788 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23789
23790 \end_inset 
23791
23792 )
23793 \end_inset 
23794 </cell>
23795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23796 \begin_inset Text
23797
23798 \layout Standard
23799
23800
23801 \begin_inset LatexCommand \url{http://www.splint.org}
23802
23803 \end_inset 
23804
23805
23806 \end_inset 
23807 </cell>
23808 </row>
23809 <row topline="true" bottomline="true">
23810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23811 \begin_inset Text
23812
23813 \layout Standard
23814
23815 ddd
23816 \begin_inset LatexCommand \index{ddd (debugger)}
23817
23818 \end_inset 
23819
23820
23821 \end_inset 
23822 </cell>
23823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23824 \begin_inset Text
23825
23826 \layout Standard
23827
23828 Debugger, serves nicely as GUI to sdcdb
23829 \begin_inset LatexCommand \index{sdcdb (debugger)}
23830
23831 \end_inset 
23832
23833  (Unix only)
23834 \end_inset 
23835 </cell>
23836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23837 \begin_inset Text
23838
23839 \layout Standard
23840
23841
23842 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
23843
23844 \end_inset 
23845
23846
23847 \end_inset 
23848 </cell>
23849 </row>
23850 </lyxtabular>
23851
23852 \end_inset 
23853
23854
23855 \newline 
23856
23857 \layout Section
23858
23859 Related documentation / recommended reading
23860 \layout Standard
23861 \align center 
23862
23863 \begin_inset  Tabular
23864 <lyxtabular version="3" rows="8" columns="3">
23865 <features>
23866 <column alignment="left" valignment="top" leftline="true" width="0pt">
23867 <column alignment="block" valignment="top" leftline="true" width="30line%">
23868 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23869 <row topline="true" bottomline="true">
23870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23871 \begin_inset Text
23872
23873 \layout Standard
23874
23875 Name
23876 \end_inset 
23877 </cell>
23878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23879 \begin_inset Text
23880
23881 \layout Standard
23882
23883 Subject / Title
23884 \end_inset 
23885 </cell>
23886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23887 \begin_inset Text
23888
23889 \layout Standard
23890
23891 Where to get
23892 \end_inset 
23893 </cell>
23894 </row>
23895 <row topline="true">
23896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23897 \begin_inset Text
23898
23899 \layout Standard
23900
23901
23902 \family roman 
23903 \series medium 
23904 \shape up 
23905 \size normal 
23906 \emph off 
23907 \bar no 
23908 \noun off 
23909 \color none
23910 c-refcard.pdf
23911 \end_inset 
23912 </cell>
23913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23914 \begin_inset Text
23915
23916 \layout Standard
23917
23918 C Reference Card
23919 \begin_inset LatexCommand \index{C Reference card}
23920
23921 \end_inset 
23922
23923 , 2 pages
23924 \end_inset 
23925 </cell>
23926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23927 \begin_inset Text
23928
23929 \layout Standard
23930
23931
23932 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
23933
23934 \end_inset 
23935
23936
23937 \end_inset 
23938 </cell>
23939 </row>
23940 <row topline="true">
23941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23942 \begin_inset Text
23943
23944 \layout Standard
23945
23946 c-faq
23947 \end_inset 
23948 </cell>
23949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23950 \begin_inset Text
23951
23952 \layout Standard
23953
23954 C-FAQ-list
23955 \end_inset 
23956 </cell>
23957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23958 \begin_inset Text
23959
23960 \layout Standard
23961
23962
23963 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
23964
23965 \end_inset 
23966
23967
23968 \end_inset 
23969 </cell>
23970 </row>
23971 <row topline="true">
23972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23973 \begin_inset Text
23974
23975 \layout Standard
23976
23977 ISO/IEC 9899:TC2
23978 \end_inset 
23979 </cell>
23980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23981 \begin_inset Text
23982
23983 \layout Standard
23984
23985
23986 \begin_inset Quotes sld
23987 \end_inset 
23988
23989 C-Standard
23990 \begin_inset Quotes srd
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
24002 \size footnotesize 
24003
24004 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
24005
24006 \end_inset 
24007
24008
24009 \end_inset 
24010 </cell>
24011 </row>
24012 <row topline="true">
24013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24014 \begin_inset Text
24015
24016 \layout Standard
24017
24018 ISO/IEC DTR 18037
24019 \end_inset 
24020 </cell>
24021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24022 \begin_inset Text
24023
24024 \layout Standard
24025
24026
24027 \begin_inset Quotes sld
24028 \end_inset 
24029
24030 Extensions for Embedded C
24031 \begin_inset Quotes srd
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
24043 \size footnotesize 
24044
24045 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
24046
24047 \end_inset 
24048
24049
24050 \end_inset 
24051 </cell>
24052 </row>
24053 <row topline="true">
24054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24055 \begin_inset Text
24056
24057 \layout Standard
24058
24059 \end_inset 
24060 </cell>
24061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24062 \begin_inset Text
24063
24064 \layout Standard
24065
24066 Latest datasheet of the target CPU
24067 \end_inset 
24068 </cell>
24069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24070 \begin_inset Text
24071
24072 \layout Standard
24073
24074 vendor
24075 \end_inset 
24076 </cell>
24077 </row>
24078 <row topline="true">
24079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24080 \begin_inset Text
24081
24082 \layout Standard
24083
24084 \end_inset 
24085 </cell>
24086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24087 \begin_inset Text
24088
24089 \layout Standard
24090
24091 Revision history of datasheet
24092 \end_inset 
24093 </cell>
24094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24095 \begin_inset Text
24096
24097 \layout Standard
24098
24099 vendor
24100 \end_inset 
24101 </cell>
24102 </row>
24103 <row topline="true" bottomline="true">
24104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24105 \begin_inset Text
24106
24107 \layout Standard
24108
24109 S.
24110  S.
24111  Muchnick
24112 \end_inset 
24113 </cell>
24114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24115 \begin_inset Text
24116
24117 \layout Standard
24118
24119 Advanced Compiler Design and Implementation
24120 \end_inset 
24121 </cell>
24122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24123 \begin_inset Text
24124
24125 \layout Standard
24126
24127 bookstore (very dedicated, probably read other books first)
24128 \end_inset 
24129 </cell>
24130 </row>
24131 </lyxtabular>
24132
24133 \end_inset 
24134
24135
24136 \newline 
24137
24138 \layout Section
24139
24140 Some Questions
24141 \layout Standard
24142
24143 Some questions answered, some pointers given - it might be time to in turn
24144  ask 
24145 \emph on 
24146 you
24147 \emph default 
24148  some questions: 
24149 \layout Itemize
24150
24151 can you solve your project with the selected microcontroller? Would you
24152  find out early or rather late that your target is too small/slow/whatever?
24153  Can you switch to a slightly better device if it doesn't fit?
24154 \layout Itemize
24155
24156 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
24157  and/or another programming language be more adequate? Would an operating
24158  system on the target device help?
24159 \layout Itemize
24160
24161 if you solved the problem, will the marketing department be happy?
24162 \layout Itemize
24163
24164 if the marketing department is happy, will customers be happy?
24165 \layout Itemize
24166
24167 if you're the project manager, marketing department and maybe even the customer
24168  in one person, have you tried to see the project from the outside?
24169 \layout Itemize
24170
24171 is the project done if you think it is done? Or is just that other interface/pro
24172 tocol/feature/configuration/option missing? How about website, manual(s),
24173  internationali(z|s)ation, packaging, labels, 2nd source for components,
24174  electromagnetic compatability/interference, documentation for production,
24175  production test software, update mechanism, patent issues?
24176 \layout Itemize
24177
24178 is your project adequately positioned in that magic triangle: fame, fortune,
24179  fun?
24180 \layout Standard
24181
24182 Maybe not all answers to these questions are known and some answers may
24183  even be 
24184 \emph on 
24185 no
24186 \emph default 
24187 , nevertheless knowing these questions may help you to avoid burnout
24188 \begin_inset Foot
24189 collapsed false
24190
24191 \layout Standard
24192
24193 burnout is bad for electronic devices, programmers and motorcycle tyres
24194 \end_inset 
24195
24196 .
24197  Chances are you didn't want to hear some of them...
24198 \layout Chapter
24199
24200 Support
24201 \begin_inset LatexCommand \index{Support}
24202
24203 \end_inset 
24204
24205
24206 \layout Standard
24207
24208 SDCC has grown to be a large project.
24209  The compiler alone (without the preprocessor, assembler and linker) is
24210  well over 100,000 lines of code (blank stripped).
24211  The open source nature of this project is a key to its continued growth
24212  and support.
24213  You gain the benefit and support of many active software developers and
24214  end users.
24215  Is SDCC perfect? No, that's why we need your help.
24216  The developers take pride in fixing reported bugs.
24217  You can help by reporting the bugs and helping other SDCC users.
24218  There are lots of ways to contribute, and we encourage you to take part
24219  in making SDCC a great software package.
24220  
24221 \layout Standard
24222
24223 The SDCC project is hosted on the SDCC sourceforge site at 
24224 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
24225
24226 \end_inset 
24227
24228 .
24229  You'll find the complete set of mailing lists
24230 \begin_inset LatexCommand \index{Mailing list(s)}
24231
24232 \end_inset 
24233
24234 , forums, bug reporting system, patch submission
24235 \begin_inset LatexCommand \index{Patch submission}
24236
24237 \end_inset 
24238
24239  system, download
24240 \begin_inset LatexCommand \index{download}
24241
24242 \end_inset 
24243
24244  area and Subversion code repository
24245 \begin_inset LatexCommand \index{Subversion code repository}
24246
24247 \end_inset 
24248
24249  there.
24250 \layout Section
24251
24252 Reporting Bugs
24253 \begin_inset LatexCommand \index{Bug reporting}
24254
24255 \end_inset 
24256
24257
24258 \begin_inset LatexCommand \index{Reporting bugs}
24259
24260 \end_inset 
24261
24262
24263 \layout Standard
24264
24265 The recommended way of reporting bugs is using the infrastructure of the
24266  sourceforge site.
24267  You can follow the status of bug reports there and have an overview about
24268  the known bugs.
24269 \layout Standard
24270
24271 Bug reports are automatically forwarded to the developer mailing list and
24272  will be fixed ASAP.
24273  When reporting a bug, it is very useful to include a small test program
24274  (the smaller the better) which reproduces the problem.
24275  If you can isolate the problem by looking at the generated assembly code,
24276  this can be very helpful.
24277  Compiling your program with the -
24278 \begin_inset ERT
24279 status Collapsed
24280
24281 \layout Standard
24282
24283 \backslash 
24284 /
24285 \end_inset 
24286
24287 -dumpall
24288 \begin_inset LatexCommand \index{-\/-dumpall}
24289
24290 \end_inset 
24291
24292  option can sometimes be useful in locating optimization problems.
24293  When reporting a bug please maker sure you:
24294 \layout Enumerate
24295
24296 Attach the code you are compiling with SDCC.
24297  
24298 \layout Enumerate
24299
24300 Specify the exact command you use to run SDCC, or attach your Makefile.
24301  
24302 \layout Enumerate
24303
24304 Specify the SDCC version (type "
24305 \family sans 
24306 \series bold 
24307 sdcc -v
24308 \family default 
24309 \series default 
24310 "), your platform, and operating system.
24311  
24312 \layout Enumerate
24313
24314 Provide an exact copy of any error message or incorrect output.
24315  
24316 \layout Enumerate
24317
24318 Put something meaningful in the subject of your message.
24319 \layout Standard
24320
24321 Please attempt to include these 5 important parts, as applicable, in all
24322  requests for support or when reporting any problems or bugs with SDCC.
24323  Though this will make your message lengthy, it will greatly improve your
24324  chance that SDCC users and developers will be able to help you.
24325  Some SDCC developers are frustrated by bug reports without code provided
24326  that they can use to reproduce and ultimately fix the problem, so please
24327  be sure to provide sample code if you are reporting a bug! 
24328 \layout Standard
24329
24330 Please have a short check that you are using a recent version of SDCC and
24331  the bug is not yet known.
24332  This is the link for reporting bugs: 
24333 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
24334
24335 \end_inset 
24336
24337 .
24338 \layout Section
24339
24340 Requesting Features
24341 \begin_inset LatexCommand \label{sub:Requesting-Features}
24342
24343 \end_inset 
24344
24345
24346 \begin_inset LatexCommand \index{Feature request}
24347
24348 \end_inset 
24349
24350
24351 \begin_inset LatexCommand \index{Requesting features}
24352
24353 \end_inset 
24354
24355
24356 \layout Standard
24357
24358 Like bug reports feature requests are forwarded to the developer mailing
24359  list.
24360  This is the link for requesting features: 
24361 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
24362
24363 \end_inset 
24364
24365 .
24366 \layout Section
24367
24368 Submitting patches
24369 \layout Standard
24370
24371 Like bug reports contributed patches are forwarded to the developer mailing
24372  list.
24373  This is the link for submitting patches
24374 \begin_inset LatexCommand \index{Patch submission}
24375
24376 \end_inset 
24377
24378
24379 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
24380
24381 \end_inset 
24382
24383 .
24384 \layout Standard
24385
24386 You need to specify some parameters to the 
24387 \family typewriter 
24388 diff
24389 \family default 
24390  command for the patches to be useful.
24391  If you modified more than one file a patch created f.e.
24392  with 
24393 \family sans 
24394 \series bold 
24395
24396 \begin_inset Quotes sld
24397 \end_inset 
24398
24399 diff -Naur unmodified_directory modified_directory >my_changes.patch
24400 \begin_inset Quotes srd
24401 \end_inset 
24402
24403
24404 \family default 
24405 \series default 
24406  will be fine, otherwise 
24407 \family sans 
24408 \series bold 
24409
24410 \begin_inset Quotes sld
24411 \end_inset 
24412
24413 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
24414 \begin_inset Quotes srd
24415 \end_inset 
24416
24417
24418 \series default 
24419  
24420 \family default 
24421 will do.
24422 \layout Section
24423
24424 Getting Help
24425 \layout Standard
24426
24427 These links should take you directly to the 
24428 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
24429
24430 \end_inset 
24431
24432
24433 \begin_inset Foot
24434 collapsed false
24435
24436 \layout Standard
24437
24438 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
24439  automated messages (mid 2003)
24440 \end_inset 
24441
24442  and the 
24443 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
24444
24445 \end_inset 
24446
24447 , lists
24448 \begin_inset LatexCommand \index{Mailing list(s)}
24449
24450 \end_inset 
24451
24452  and forums are archived and searchable so if you are lucky someone already
24453  had a similar problem.
24454  While mails to the lists themselves are delivered promptly their web front
24455  end on sourceforge sometimes shows a severe time lag (up to several weeks),
24456  if you're seriously using SDCC please consider subscribing to the lists.
24457 \layout Section
24458
24459 ChangeLog
24460 \layout Standard
24461
24462 You can follow the status of the Subversion version
24463 \begin_inset LatexCommand \index{version}
24464
24465 \end_inset 
24466
24467  of SDCC by watching the Changelog
24468 \begin_inset LatexCommand \index{Changelog}
24469
24470 \end_inset 
24471
24472  in the Subversion repository
24473 \size footnotesize 
24474  
24475 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
24476
24477 \end_inset 
24478
24479 .
24480 \layout Section
24481
24482 Subversion Source Code Repository
24483 \layout Standard
24484
24485 The output of 
24486 \family sans 
24487 \series bold 
24488 sdcc --version
24489 \family default 
24490 \series default 
24491  or the filenames of the snapshot versions of SDCC include date and its
24492  Subversion
24493 \begin_inset LatexCommand \index{Subversion}
24494
24495 \end_inset 
24496
24497  number.
24498  Subversion allows to download the source of recent or previous versions
24499  
24500 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
24501
24502 \end_inset 
24503
24504  (by number or by date).
24505  An on-line source code browser and detailled instructions are also available
24506  there.
24507  SDCC versions starting from 1999 up to now are available (currently the
24508  versions prior to the conversion from cvs to Subversion (April 2006) are
24509  either by accessible by Subversion or by cvs).
24510 \layout Section
24511
24512 Release policy
24513 \begin_inset LatexCommand \index{Release policy}
24514
24515 \end_inset 
24516
24517
24518 \layout Standard
24519
24520 Historically there often were long delays between official releases and
24521  the sourceforge download area tends to get not updated at all.
24522  Excuses in the past might have referred to problems with live range analysis,
24523  but as this was fixed a while ago, the current problem is that another
24524  excuse has to be found.
24525  Kidding aside, we have to get better there! On the other hand there are
24526  daily snapshots available at 
24527 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
24528
24529 \end_inset 
24530
24531 , and you can always build the very last version (hopefully with many bugs
24532  fixed, and features added) from the source code available at 
24533 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
24534
24535 \end_inset 
24536
24537 .
24538 \layout Section
24539
24540 Examples
24541 \begin_inset LatexCommand \index{Examples}
24542
24543 \end_inset 
24544
24545
24546 \layout Standard
24547
24548 You'll find some small examples in the directory 
24549 \emph on 
24550 sdcc/device/examples/.
24551  
24552 \emph default 
24553 More examples and libraries are available at
24554 \emph on 
24555  The SDCC Open Knowledge Resource 
24556 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
24557
24558 \end_inset 
24559
24560  
24561 \emph default 
24562 web site or at 
24563 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
24564
24565 \end_inset 
24566
24567 .
24568 \layout Comment
24569
24570 I did insert a reference to Paul's web site here although it seems rather
24571  dedicated to a specific 8032 board (I think it's okay because it f.e.
24572  shows LCD/Harddisc interface and has a free 8051 monitor.
24573  Independent 8032 board vendors face hard competition of heavily subsidized
24574  development boards anyway).
24575 \layout Comment
24576
24577 Maybe we should include some links to real world applications.
24578  Preferably pointer to pointers (one for each architecture) so this stays
24579  manageable here?
24580 \layout Section
24581
24582 Quality control
24583 \begin_inset LatexCommand \index{Quality control}
24584
24585 \end_inset 
24586
24587
24588 \layout Standard
24589
24590 The compiler is passed through nightly compile and build checks.
24591  The so called 
24592 \shape italic 
24593 regression tests
24594 \shape default 
24595
24596 \begin_inset LatexCommand \index{Regression test}
24597
24598 \end_inset 
24599
24600  check that SDCC itself compiles flawlessly on several platforms and checks
24601  the quality of the code generated by SDCC by running the code through simulator
24602 s.
24603  There is a separate document 
24604 \shape italic 
24605 test_suite.pdf
24606 \begin_inset LatexCommand \index{Test suite}
24607
24608 \end_inset 
24609
24610
24611 \shape default 
24612  about this.
24613 \layout Standard
24614
24615 You'll find the test code in the directory 
24616 \shape italic 
24617 sdcc/support/regression
24618 \shape default 
24619 .
24620  You can run these tests manually by running 
24621 \family sans 
24622 make
24623 \family default 
24624  in this directory (or f.e.
24625  
24626 \family sans 
24627 \series bold 
24628
24629 \begin_inset Quotes sld
24630 \end_inset 
24631
24632 make test-mcs51
24633 \begin_inset Quotes srd
24634 \end_inset 
24635
24636
24637 \family default 
24638 \series default 
24639  if you don't want to run the complete tests).
24640  The test code might also be interesting if you want to look for examples
24641 \begin_inset LatexCommand \index{Examples}
24642
24643 \end_inset 
24644
24645  checking corner cases of SDCC or if you plan to submit patches
24646 \begin_inset LatexCommand \index{Patch submission}
24647
24648 \end_inset 
24649
24650 .
24651 \layout Standard
24652
24653 The pic port uses a different set of regression tests, you'll find them
24654  in the directory 
24655 \shape italic 
24656 sdcc/src/regression
24657 \shape default 
24658 .
24659 \layout Section
24660
24661 Use of SDCC in Education
24662 \layout Standard
24663
24664 In short: 
24665 \emph on 
24666 highly
24667 \emph default 
24668  encouraged
24669 \begin_inset Foot
24670 collapsed false
24671
24672 \layout Standard
24673
24674 the phrase "use in education" might evoke the association "
24675 \emph on 
24676 only
24677 \emph default 
24678  fit for use in education".
24679  This connotation is not intended but nevertheless risked as the licensing
24680  of SDCC makes it difficult to offer educational discounts
24681 \end_inset 
24682
24683 .
24684  If your rationales are to:
24685 \layout Enumerate
24686
24687 give students a chance to understand the 
24688 \emph on 
24689 complete
24690 \emph default 
24691  steps of code generation
24692 \layout Enumerate
24693
24694 have a curriculum that can be extended for years.
24695  Then you could use an fpga board as target and your curriculum will seamlessly
24696  extend from logic synthesis (
24697 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
24698
24699 \end_inset 
24700
24701
24702 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
24703
24704 \end_inset 
24705
24706 ), over assembly programming, to C to FPGA compilers (
24707 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
24708
24709 \end_inset 
24710
24711 ) and to C.
24712 \layout Enumerate
24713
24714 be able to insert excursions about skills like using a revision control
24715  system, submitting/applying patches, using a type-setting (as opposed to
24716  word-processing) engine LyX/LaTeX, using 
24717 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
24718
24719 \end_inset 
24720
24721 , following some 
24722 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
24723
24724 \end_inset 
24725
24726 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
24727  Source Software, CPU simulation, compiler regression tests
24728 \begin_inset LatexCommand \index{Regression test}
24729
24730 \end_inset 
24731
24732 .
24733  
24734 \newline 
24735 And if there should be a shortage of ideas then you can always point students
24736  to the ever-growing feature request list 
24737 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
24738
24739 \end_inset 
24740
24741 .
24742 \layout Enumerate
24743
24744 not tie students to a specific host platform and instead allow them to use
24745  a host platform of 
24746 \emph on 
24747 their
24748 \emph default 
24749  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
24750  eventually 
24751 \begin_inset LatexCommand \url[OLPC]{http://wiki.laptop.org/wiki/One_Laptop_per_Child}
24752
24753 \end_inset 
24754
24755 )
24756 \layout Enumerate
24757
24758 not encourage students to use illegal copies of educational software
24759 \layout Enumerate
24760
24761 be immune to licensing/availability/price changes of the chosen tool chain
24762 \layout Enumerate
24763
24764 be able to change to a new target platform without having to adopt a new
24765  tool chain
24766 \layout Enumerate
24767
24768 have complete control over and insight into the tool chain
24769 \layout Enumerate
24770
24771 make your students aware about the pros and cons of open source software
24772  development
24773 \layout Enumerate
24774
24775 give back to the public as you are probably at least partially publically
24776  funded
24777 \layout Enumerate
24778
24779 give students a chance to publically prove their skills and to possibly
24780  see a world wide impact
24781 \layout Standard
24782
24783 then SDCC is probably among the first choices.
24784  Well, probably SDCC might be the only choice.
24785 \layout Chapter
24786 \pagebreak_top 
24787 SDCC Technical Data
24788 \layout Section
24789
24790 Optimizations
24791 \begin_inset LatexCommand \index{Optimizations}
24792
24793 \end_inset 
24794
24795
24796 \layout Standard
24797
24798 SDCC performs a host of standard optimizations in addition to some MCU specific
24799  optimizations.
24800  
24801 \layout Subsection
24802
24803 Sub-expression Elimination
24804 \begin_inset LatexCommand \index{Subexpression elimination}
24805
24806 \end_inset 
24807
24808
24809 \layout Standard
24810
24811 The compiler does local and 
24812 \emph on 
24813 g
24814 \emph default 
24815 lobal 
24816 \emph on 
24817 c
24818 \emph default 
24819 ommon 
24820 \emph on 
24821 s
24822 \emph default 
24823 ubexpression 
24824 \emph on 
24825 e
24826 \emph default 
24827 limination, e.g.: 
24828 \layout Verse
24829
24830
24831 \family typewriter 
24832 i = x + y + 1; 
24833 \newline 
24834 j = x + y;
24835 \layout Standard
24836
24837 will be translated to
24838 \layout Verse
24839
24840
24841 \family typewriter 
24842 iTemp = x + y; 
24843 \newline 
24844 i = iTemp + 1; 
24845 \newline 
24846 j = iTemp;
24847 \layout Standard
24848
24849 Some subexpressions are not as obvious as the above example, e.g.:
24850 \layout Verse
24851
24852
24853 \family typewriter 
24854 a->b[i].c = 10; 
24855 \newline 
24856 a->b[i].d = 11;
24857 \layout Standard
24858
24859 In this case the address arithmetic a->b[i] will be computed only once;
24860  the equivalent code in C would be.
24861 \layout Verse
24862
24863
24864 \family typewriter 
24865 iTemp = a->b[i]; 
24866 \newline 
24867 iTemp.c = 10; 
24868 \newline 
24869 iTemp.d = 11;
24870 \layout Standard
24871
24872 The compiler will try to keep these temporary variables in registers.
24873 \layout Subsection
24874
24875 Dead-Code Elimination
24876 \begin_inset LatexCommand \index{Dead-code elimination}
24877
24878 \end_inset 
24879
24880
24881 \layout Verse
24882
24883
24884 \family typewriter 
24885 int global;
24886 \newline 
24887
24888 \newline 
24889 void f () { 
24890 \newline 
24891 \SpecialChar ~
24892 \SpecialChar ~
24893 int i; 
24894 \newline 
24895 \SpecialChar ~
24896 \SpecialChar ~
24897 i = 1; \SpecialChar ~
24898 \SpecialChar ~
24899 \SpecialChar ~
24900 \SpecialChar ~
24901 \SpecialChar ~
24902 /* dead store */ 
24903 \newline 
24904 \SpecialChar ~
24905 \SpecialChar ~
24906 global = 1;\SpecialChar ~
24907 /* dead store */ 
24908 \newline 
24909 \SpecialChar ~
24910 \SpecialChar ~
24911 global = 2; 
24912 \newline 
24913 \SpecialChar ~
24914 \SpecialChar ~
24915 return; 
24916 \newline 
24917 \SpecialChar ~
24918 \SpecialChar ~
24919 global = 3;\SpecialChar ~
24920 /* unreachable */ 
24921 \newline 
24922 }
24923 \layout Standard
24924
24925 will be changed to
24926 \layout Verse
24927
24928
24929 \family typewriter 
24930 int global;
24931 \newline 
24932
24933 \newline 
24934 void f () {
24935 \newline 
24936 \SpecialChar ~
24937 \SpecialChar ~
24938 global = 2; 
24939 \newline 
24940 }
24941 \layout Subsection
24942
24943 Copy-Propagation
24944 \begin_inset LatexCommand \index{Copy propagation}
24945
24946 \end_inset 
24947
24948
24949 \layout Verse
24950
24951
24952 \family typewriter 
24953 int f() { 
24954 \newline 
24955 \SpecialChar ~
24956 \SpecialChar ~
24957 int i, j; 
24958 \newline 
24959 \SpecialChar ~
24960 \SpecialChar ~
24961 i = 10; 
24962 \newline 
24963 \SpecialChar ~
24964 \SpecialChar ~
24965 j = i; 
24966 \newline 
24967 \SpecialChar ~
24968 \SpecialChar ~
24969 return j; 
24970 \newline 
24971 }
24972 \layout Standard
24973
24974 will be changed to 
24975 \layout Verse
24976
24977
24978 \family typewriter 
24979 int f() { 
24980 \newline 
24981 \SpecialChar ~
24982 \SpecialChar ~
24983 int i, j; 
24984 \newline 
24985 \SpecialChar ~
24986 \SpecialChar ~
24987 i = 10; 
24988 \newline 
24989 \SpecialChar ~
24990 \SpecialChar ~
24991 j = 10; 
24992 \newline 
24993 \SpecialChar ~
24994 \SpecialChar ~
24995 return 10; 
24996 \newline 
24997 }
24998 \layout Standard
24999
25000 Note: the dead stores created by this copy propagation will be eliminated
25001  by dead-code elimination.
25002 \layout Subsection
25003
25004 Loop Optimizations
25005 \begin_inset LatexCommand \index{Loop optimization}
25006
25007 \end_inset 
25008
25009
25010 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
25011
25012 \end_inset 
25013
25014
25015 \layout Standard
25016
25017 Two types of loop optimizations are done by SDCC 
25018 \emph on 
25019 loop invariant
25020 \emph default 
25021  lifting and
25022 \emph on 
25023  strength reduction
25024 \emph default 
25025  of loop induction variables.
25026  In addition to the strength reduction the optimizer marks the induction
25027  variables and the register allocator tries to keep the induction variables
25028  in registers for the duration of the loop.
25029  Because of this preference of the register allocator
25030 \begin_inset LatexCommand \index{Register allocation}
25031
25032 \end_inset 
25033
25034 , loop induction optimization causes an increase in register pressure, which
25035  may cause unwanted spilling of other temporary variables into the stack
25036 \begin_inset LatexCommand \index{stack}
25037
25038 \end_inset 
25039
25040  / data space.
25041  The compiler will generate a warning message when it is forced to allocate
25042  extra space either on the stack or data space.
25043  If this extra space allocation is undesirable then induction optimization
25044  can be eliminated either for the entire source file (with -
25045 \begin_inset ERT
25046 status Collapsed
25047
25048 \layout Standard
25049
25050 \backslash 
25051 /
25052 \end_inset 
25053
25054 -noinduction option) or for a given function only using #pragma\SpecialChar ~
25055 noinduction
25056 \begin_inset LatexCommand \index{\#pragma noinduction}
25057
25058 \end_inset 
25059
25060 .
25061 \newline 
25062
25063 \newline 
25064 Loop Invariant:
25065 \layout Verse
25066
25067
25068 \family typewriter 
25069 for (i = 0 ; i < 100 ; i ++) 
25070 \newline 
25071 \SpecialChar ~
25072 \SpecialChar ~
25073 \SpecialChar ~
25074 \SpecialChar ~
25075 f += k + l;
25076 \layout Standard
25077
25078 changed to
25079 \layout Verse
25080
25081
25082 \family typewriter 
25083 itemp = k + l; 
25084 \newline 
25085 for (i = 0; i < 100; i++) 
25086 \newline 
25087 \SpecialChar ~
25088 \SpecialChar ~
25089 \SpecialChar ~
25090 \SpecialChar ~
25091 f += itemp;
25092 \layout Standard
25093
25094 As mentioned previously some loop invariants are not as apparent, all static
25095  address computations are also moved out of the loop.
25096 \newline 
25097
25098 \newline 
25099 Strength Reduction
25100 \begin_inset LatexCommand \index{Strength reduction}
25101
25102 \end_inset 
25103
25104 , this optimization substitutes an expression by a cheaper expression:
25105 \layout Verse
25106
25107
25108 \family typewriter 
25109 for (i=0;i < 100; i++)
25110 \newline 
25111 \SpecialChar ~
25112 \SpecialChar ~
25113 \SpecialChar ~
25114 \SpecialChar ~
25115 ar[i*5] = i*3;
25116 \layout Standard
25117
25118 changed to
25119 \layout Verse
25120
25121
25122 \family typewriter 
25123 itemp1 = 0; 
25124 \newline 
25125 itemp2 = 0; 
25126 \newline 
25127 for (i=0;i< 100;i++) { 
25128 \newline 
25129 \SpecialChar ~
25130 \SpecialChar ~
25131 \SpecialChar ~
25132 \SpecialChar ~
25133 ar[itemp1] = itemp2; 
25134 \newline 
25135 \SpecialChar ~
25136 \SpecialChar ~
25137 \SpecialChar ~
25138 \SpecialChar ~
25139 itemp1 += 5; 
25140 \newline 
25141 \SpecialChar ~
25142 \SpecialChar ~
25143 \SpecialChar ~
25144 \SpecialChar ~
25145 itemp2 += 3; 
25146 \newline 
25147 }
25148 \layout Standard
25149
25150 The more expensive multiplication
25151 \begin_inset LatexCommand \index{Multiplication}
25152
25153 \end_inset 
25154
25155  is changed to a less expensive addition.
25156 \layout Subsection
25157
25158 Loop Reversing
25159 \begin_inset LatexCommand \index{Loop reversing}
25160
25161 \end_inset 
25162
25163
25164 \layout Standard
25165
25166 This optimization is done to reduce the overhead of checking loop boundaries
25167  for every iteration.
25168  Some simple loops can be reversed and implemented using a 
25169 \begin_inset Quotes eld
25170 \end_inset 
25171
25172 decrement and jump if not zero
25173 \begin_inset Quotes erd
25174 \end_inset 
25175
25176  instruction.
25177  SDCC checks for the following criterion to determine if a loop is reversible
25178  (note: more sophisticated compilers use data-dependency analysis to make
25179  this determination, SDCC uses a more simple minded analysis).
25180 \layout Itemize
25181
25182 The 'for' loop is of the form 
25183 \newline 
25184
25185 \newline 
25186
25187 \family typewriter 
25188 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
25189  += 1])
25190 \newline 
25191 \SpecialChar ~
25192 \SpecialChar ~
25193 \SpecialChar ~
25194 \SpecialChar ~
25195 <for body>
25196 \layout Itemize
25197
25198 The <for body> does not contain 
25199 \begin_inset Quotes eld
25200 \end_inset 
25201
25202 continue
25203 \begin_inset Quotes erd
25204 \end_inset 
25205
25206  or 'break
25207 \begin_inset Quotes erd
25208 \end_inset 
25209
25210 .
25211 \layout Itemize
25212
25213 All goto's are contained within the loop.
25214 \layout Itemize
25215
25216 No function calls within the loop.
25217 \layout Itemize
25218
25219 The loop control variable <sym> is not assigned any value within the loop
25220 \layout Itemize
25221
25222 The loop control variable does NOT participate in any arithmetic operation
25223  within the loop.
25224 \layout Itemize
25225
25226 There are NO switch statements in the loop.
25227 \layout Subsection
25228
25229 Algebraic Simplifications
25230 \layout Standard
25231
25232 SDCC does numerous algebraic simplifications, the following is a small sub-set
25233  of these optimizations.
25234 \layout Verse
25235
25236
25237 \family typewriter 
25238 i = j + 0;\SpecialChar ~
25239 \SpecialChar ~
25240 \SpecialChar ~
25241 \SpecialChar ~
25242  /* changed to: */\SpecialChar ~
25243 \SpecialChar ~
25244 \SpecialChar ~
25245 \SpecialChar ~
25246  i = j; 
25247 \newline 
25248 i /= 2;\SpecialChar ~
25249 \SpecialChar ~
25250 \SpecialChar ~
25251 \SpecialChar ~
25252 \SpecialChar ~
25253 \SpecialChar ~
25254 \SpecialChar ~
25255  /* changed to: */\SpecialChar ~
25256 \SpecialChar ~
25257 \SpecialChar ~
25258 \SpecialChar ~
25259  i >>= 1; 
25260 \newline 
25261 i = j - j;\SpecialChar ~
25262 \SpecialChar ~
25263 \SpecialChar ~
25264 \SpecialChar ~
25265  /* changed to: */\SpecialChar ~
25266 \SpecialChar ~
25267 \SpecialChar ~
25268 \SpecialChar ~
25269  i = 0; 
25270 \newline 
25271 i = j / 1;\SpecialChar ~
25272 \SpecialChar ~
25273 \SpecialChar ~
25274 \SpecialChar ~
25275  /* changed to: */\SpecialChar ~
25276 \SpecialChar ~
25277 \SpecialChar ~
25278 \SpecialChar ~
25279  i = j;
25280 \layout Standard
25281
25282 Note the subexpressions
25283 \begin_inset LatexCommand \index{Subexpression}
25284
25285 \end_inset 
25286
25287  given above are generally introduced by macro expansions or as a result
25288  of copy/constant propagation.
25289 \layout Subsection
25290
25291 'switch' Statements
25292 \begin_inset LatexCommand \label{sub:'switch'-Statements}
25293
25294 \end_inset 
25295
25296
25297 \begin_inset LatexCommand \index{switch statement}
25298
25299 \end_inset 
25300
25301
25302 \layout Standard
25303
25304 SDCC can optimize switch statements to jump tables
25305 \begin_inset LatexCommand \index{jump tables}
25306
25307 \end_inset 
25308
25309 .
25310  It makes the decision based on an estimate of the generated code size.
25311  SDCC is quite liberal in the requirements for jump table generation: 
25312 \layout Itemize
25313
25314 The labels need not be in order, and the starting number need not be one
25315  or zero, the case labels are in numerical sequence or not too many case
25316  labels are missing.
25317 \begin_deeper 
25318 \layout Verse
25319
25320
25321 \family typewriter 
25322 switch(i) {\SpecialChar ~
25323 \SpecialChar ~
25324 \SpecialChar ~
25325 \SpecialChar ~
25326 \SpecialChar ~
25327 \SpecialChar ~
25328 \SpecialChar ~
25329 \SpecialChar ~
25330 \SpecialChar ~
25331 \SpecialChar ~
25332 \SpecialChar ~
25333 \SpecialChar ~
25334 \SpecialChar ~
25335 \SpecialChar ~
25336 \SpecialChar ~
25337 \SpecialChar ~
25338 \SpecialChar ~
25339 \SpecialChar ~
25340 \SpecialChar ~
25341 \SpecialChar ~
25342 \SpecialChar ~
25343 \SpecialChar ~
25344 \SpecialChar ~
25345 \SpecialChar ~
25346 \SpecialChar ~
25347 \SpecialChar ~
25348 switch (i) { 
25349 \newline 
25350 \SpecialChar ~
25351 \SpecialChar ~
25352 \SpecialChar ~
25353 case 4: ...\SpecialChar ~
25354 \SpecialChar ~
25355 \SpecialChar ~
25356 \SpecialChar ~
25357 \SpecialChar ~
25358 \SpecialChar ~
25359 \SpecialChar ~
25360 \SpecialChar ~
25361 \SpecialChar ~
25362 \SpecialChar ~
25363 \SpecialChar ~
25364 \SpecialChar ~
25365 \SpecialChar ~
25366 \SpecialChar ~
25367 \SpecialChar ~
25368 \SpecialChar ~
25369 \SpecialChar ~
25370 \SpecialChar ~
25371 \SpecialChar ~
25372 \SpecialChar ~
25373 \SpecialChar ~
25374 \SpecialChar ~
25375 \SpecialChar ~
25376 \SpecialChar ~
25377 \SpecialChar ~
25378 \SpecialChar ~
25379 case 0: ...
25380  
25381 \newline 
25382 \SpecialChar ~
25383 \SpecialChar ~
25384 \SpecialChar ~
25385 case 5: ...\SpecialChar ~
25386 \SpecialChar ~
25387 \SpecialChar ~
25388 \SpecialChar ~
25389 \SpecialChar ~
25390 \SpecialChar ~
25391 \SpecialChar ~
25392 \SpecialChar ~
25393 \SpecialChar ~
25394 \SpecialChar ~
25395 \SpecialChar ~
25396 \SpecialChar ~
25397 \SpecialChar ~
25398 \SpecialChar ~
25399 \SpecialChar ~
25400 \SpecialChar ~
25401 \SpecialChar ~
25402 \SpecialChar ~
25403 \SpecialChar ~
25404 \SpecialChar ~
25405 \SpecialChar ~
25406 \SpecialChar ~
25407 \SpecialChar ~
25408 \SpecialChar ~
25409 \SpecialChar ~
25410 \SpecialChar ~
25411 case 1: ...
25412  
25413 \newline 
25414 \SpecialChar ~
25415 \SpecialChar ~
25416 \SpecialChar ~
25417 case 3: ...\SpecialChar ~
25418 \SpecialChar ~
25419 \SpecialChar ~
25420 \SpecialChar ~
25421 \SpecialChar ~
25422 \SpecialChar ~
25423 \SpecialChar ~
25424 \SpecialChar ~
25425 \SpecialChar ~
25426 \SpecialChar ~
25427 \SpecialChar ~
25428 \SpecialChar ~
25429 \SpecialChar ~
25430 \SpecialChar ~
25431 \SpecialChar ~
25432 \SpecialChar ~
25433 \SpecialChar ~
25434 \SpecialChar ~
25435 \SpecialChar ~
25436 \SpecialChar ~
25437 \SpecialChar ~
25438 \SpecialChar ~
25439 \SpecialChar ~
25440 \SpecialChar ~
25441 \SpecialChar ~
25442 \SpecialChar ~
25443
25444 \newline 
25445 \SpecialChar ~
25446 \SpecialChar ~
25447 \SpecialChar ~
25448 case 6: ...\SpecialChar ~
25449 \SpecialChar ~
25450 \SpecialChar ~
25451 \SpecialChar ~
25452 \SpecialChar ~
25453 \SpecialChar ~
25454 \SpecialChar ~
25455 \SpecialChar ~
25456 \SpecialChar ~
25457 \SpecialChar ~
25458 \SpecialChar ~
25459 \SpecialChar ~
25460 \SpecialChar ~
25461 \SpecialChar ~
25462 \SpecialChar ~
25463 \SpecialChar ~
25464 \SpecialChar ~
25465 \SpecialChar ~
25466 \SpecialChar ~
25467 \SpecialChar ~
25468 \SpecialChar ~
25469 \SpecialChar ~
25470 \SpecialChar ~
25471 \SpecialChar ~
25472 \SpecialChar ~
25473 \SpecialChar ~
25474 case 3: ...
25475  
25476 \newline 
25477 \SpecialChar ~
25478 \SpecialChar ~
25479 \SpecialChar ~
25480 case 7: ...\SpecialChar ~
25481 \SpecialChar ~
25482 \SpecialChar ~
25483 \SpecialChar ~
25484 \SpecialChar ~
25485 \SpecialChar ~
25486 \SpecialChar ~
25487 \SpecialChar ~
25488 \SpecialChar ~
25489 \SpecialChar ~
25490 \SpecialChar ~
25491 \SpecialChar ~
25492 \SpecialChar ~
25493 \SpecialChar ~
25494 \SpecialChar ~
25495 \SpecialChar ~
25496 \SpecialChar ~
25497 \SpecialChar ~
25498 \SpecialChar ~
25499 \SpecialChar ~
25500 \SpecialChar ~
25501 \SpecialChar ~
25502 \SpecialChar ~
25503 \SpecialChar ~
25504 \SpecialChar ~
25505 \SpecialChar ~
25506 case 4: ...
25507  
25508 \newline 
25509 \SpecialChar ~
25510 \SpecialChar ~
25511 \SpecialChar ~
25512 case 8: ...\SpecialChar ~
25513 \SpecialChar ~
25514 \SpecialChar ~
25515 \SpecialChar ~
25516 \SpecialChar ~
25517 \SpecialChar ~
25518 \SpecialChar ~
25519 \SpecialChar ~
25520 \SpecialChar ~
25521 \SpecialChar ~
25522 \SpecialChar ~
25523 \SpecialChar ~
25524 \SpecialChar ~
25525 \SpecialChar ~
25526 \SpecialChar ~
25527 \SpecialChar ~
25528 \SpecialChar ~
25529 \SpecialChar ~
25530 \SpecialChar ~
25531 \SpecialChar ~
25532 \SpecialChar ~
25533 \SpecialChar ~
25534 \SpecialChar ~
25535 \SpecialChar ~
25536 \SpecialChar ~
25537 \SpecialChar ~
25538 case 5: ...
25539  
25540 \newline 
25541 \SpecialChar ~
25542 \SpecialChar ~
25543 \SpecialChar ~
25544 case 9: ...\SpecialChar ~
25545 \SpecialChar ~
25546 \SpecialChar ~
25547 \SpecialChar ~
25548 \SpecialChar ~
25549 \SpecialChar ~
25550 \SpecialChar ~
25551 \SpecialChar ~
25552 \SpecialChar ~
25553 \SpecialChar ~
25554 \SpecialChar ~
25555 \SpecialChar ~
25556 \SpecialChar ~
25557 \SpecialChar ~
25558 \SpecialChar ~
25559 \SpecialChar ~
25560 \SpecialChar ~
25561 \SpecialChar ~
25562 \SpecialChar ~
25563 \SpecialChar ~
25564 \SpecialChar ~
25565 \SpecialChar ~
25566 \SpecialChar ~
25567 \SpecialChar ~
25568 \SpecialChar ~
25569 \SpecialChar ~
25570 case 6: ...
25571  
25572 \newline 
25573 \SpecialChar ~
25574 \SpecialChar ~
25575 \SpecialChar ~
25576 case 10: ...\SpecialChar ~
25577 \SpecialChar ~
25578 \SpecialChar ~
25579 \SpecialChar ~
25580 \SpecialChar ~
25581 \SpecialChar ~
25582 \SpecialChar ~
25583 \SpecialChar ~
25584 \SpecialChar ~
25585 \SpecialChar ~
25586 \SpecialChar ~
25587 \SpecialChar ~
25588 \SpecialChar ~
25589 \SpecialChar ~
25590 \SpecialChar ~
25591 \SpecialChar ~
25592 \SpecialChar ~
25593 \SpecialChar ~
25594 \SpecialChar ~
25595 \SpecialChar ~
25596 \SpecialChar ~
25597 \SpecialChar ~
25598 \SpecialChar ~
25599 \SpecialChar ~
25600 \SpecialChar ~
25601 case 7: ...
25602  
25603 \newline 
25604 \SpecialChar ~
25605 \SpecialChar ~
25606 \SpecialChar ~
25607 case 11: ...\SpecialChar ~
25608 \SpecialChar ~
25609 \SpecialChar ~
25610 \SpecialChar ~
25611 \SpecialChar ~
25612 \SpecialChar ~
25613 \SpecialChar ~
25614 \SpecialChar ~
25615 \SpecialChar ~
25616 \SpecialChar ~
25617 \SpecialChar ~
25618 \SpecialChar ~
25619 \SpecialChar ~
25620 \SpecialChar ~
25621 \SpecialChar ~
25622 \SpecialChar ~
25623 \SpecialChar ~
25624 \SpecialChar ~
25625 \SpecialChar ~
25626 \SpecialChar ~
25627 \SpecialChar ~
25628 \SpecialChar ~
25629 \SpecialChar ~
25630 \SpecialChar ~
25631 \SpecialChar ~
25632 case 8: ...
25633  
25634 \newline 
25635 }\SpecialChar ~
25636 \SpecialChar ~
25637 \SpecialChar ~
25638 \SpecialChar ~
25639 \SpecialChar ~
25640 \SpecialChar ~
25641 \SpecialChar ~
25642 \SpecialChar ~
25643 \SpecialChar ~
25644 \SpecialChar ~
25645 \SpecialChar ~
25646 \SpecialChar ~
25647 \SpecialChar ~
25648 \SpecialChar ~
25649 \SpecialChar ~
25650 \SpecialChar ~
25651 \SpecialChar ~
25652 \SpecialChar ~
25653 \SpecialChar ~
25654 \SpecialChar ~
25655 \SpecialChar ~
25656 \SpecialChar ~
25657 \SpecialChar ~
25658 \SpecialChar ~
25659 \SpecialChar ~
25660 \SpecialChar ~
25661 \SpecialChar ~
25662 \SpecialChar ~
25663 \SpecialChar ~
25664 \SpecialChar ~
25665 \SpecialChar ~
25666 \SpecialChar ~
25667 \SpecialChar ~
25668 \SpecialChar ~
25669 \SpecialChar ~
25670 \SpecialChar ~
25671 }
25672 \layout Standard
25673
25674 Both the above switch statements will be implemented using a jump-table.
25675  The example to the right side is slightly more efficient as the check for
25676  the lower boundary of the jump-table is not needed.
25677 \end_deeper 
25678 \layout Itemize
25679
25680 The number of case labels is not larger than supported by the target architectur
25681 e.
25682 \layout Itemize
25683
25684 If the case labels are not in numerical sequence ('gaps' between cases)
25685  SDCC checks whether a jump table with additionally inserted dummy cases
25686  is still attractive.
25687  
25688 \layout Itemize
25689
25690 If the starting number is not zero and a check for the lower boundary of
25691  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
25692  ...
25693  .
25694 \layout Standard
25695
25696 Switch statements which have large gaps in the numeric sequence or those
25697  that have too many case labels can be split into more than one switch statement
25698  for efficient code generation, e.g.:
25699 \layout Verse
25700
25701
25702 \family typewriter 
25703 switch (i) { 
25704 \newline 
25705 \SpecialChar ~
25706 \SpecialChar ~
25707 case 1: ...
25708  
25709 \newline 
25710 \SpecialChar ~
25711 \SpecialChar ~
25712 case 2: ...
25713  
25714 \newline 
25715 \SpecialChar ~
25716 \SpecialChar ~
25717 case 3: ...
25718  
25719 \newline 
25720 \SpecialChar ~
25721 \SpecialChar ~
25722 case 4: ...
25723  
25724 \newline 
25725 \SpecialChar ~
25726 \SpecialChar ~
25727 case 5: ...
25728  
25729 \newline 
25730 \SpecialChar ~
25731 \SpecialChar ~
25732 case 6: ...
25733  
25734 \newline 
25735 \SpecialChar ~
25736 \SpecialChar ~
25737 case 7: ...
25738  
25739 \newline 
25740 \SpecialChar ~
25741 \SpecialChar ~
25742 case 101: ...
25743  
25744 \newline 
25745 \SpecialChar ~
25746 \SpecialChar ~
25747 case 102: ...
25748  
25749 \newline 
25750 \SpecialChar ~
25751 \SpecialChar ~
25752 case 103: ...
25753  
25754 \newline 
25755 \SpecialChar ~
25756 \SpecialChar ~
25757 case 104: ...
25758  
25759 \newline 
25760 \SpecialChar ~
25761 \SpecialChar ~
25762 case 105: ...
25763  
25764 \newline 
25765 \SpecialChar ~
25766 \SpecialChar ~
25767 case 106: ...
25768  
25769 \newline 
25770 \SpecialChar ~
25771 \SpecialChar ~
25772 case 107: ...
25773  
25774 \newline 
25775 }
25776 \layout Standard
25777
25778 If the above switch statement is broken down into two switch statements
25779 \layout Verse
25780
25781
25782 \family typewriter 
25783 switch (i) { 
25784 \newline 
25785 \SpecialChar ~
25786 \SpecialChar ~
25787 case 1: ...
25788  
25789 \newline 
25790 \SpecialChar ~
25791 \SpecialChar ~
25792 case 2: ...
25793  
25794 \newline 
25795 \SpecialChar ~
25796 \SpecialChar ~
25797 case 3: ...
25798  
25799 \newline 
25800 \SpecialChar ~
25801 \SpecialChar ~
25802 case 4: ...
25803  
25804 \newline 
25805 \SpecialChar ~
25806 \SpecialChar ~
25807 case 5: ...
25808  
25809 \newline 
25810 \SpecialChar ~
25811 \SpecialChar ~
25812 case 6: ...
25813  
25814 \newline 
25815 \SpecialChar ~
25816 \SpecialChar ~
25817 case 7: ...
25818  
25819 \newline 
25820 }
25821 \layout Standard
25822
25823 and
25824 \layout Verse
25825
25826
25827 \family typewriter 
25828 switch (i) { 
25829 \newline 
25830 \SpecialChar ~
25831 \SpecialChar ~
25832 case 101: ...
25833  
25834 \newline 
25835 \SpecialChar ~
25836 \SpecialChar ~
25837 case 102: ...
25838  
25839 \newline 
25840 \SpecialChar ~
25841 \SpecialChar ~
25842 case 103: ...
25843  
25844 \newline 
25845 \SpecialChar ~
25846 \SpecialChar ~
25847 case 104: ...
25848  
25849 \newline 
25850 \SpecialChar ~
25851 \SpecialChar ~
25852 case 105: ...
25853  
25854 \newline 
25855 \SpecialChar ~
25856 \SpecialChar ~
25857 case 106: ...
25858  
25859 \newline 
25860 \SpecialChar ~
25861 \SpecialChar ~
25862 case 107: ...
25863  
25864 \newline 
25865 }
25866 \layout Standard
25867
25868 then both the switch statements will be implemented using jump-tables whereas
25869  the unmodified switch statement will not be.
25870 \layout Comment
25871
25872 There might be reasons which SDCC cannot know about to either favour or
25873  not favour jump tables.
25874  If the target system has to be as quick for the last switch case as for
25875  the first (pro jump table), or if the switch argument is known to be zero
25876  in the majority of the cases (contra jump table).
25877 \layout Standard
25878
25879 The pragma nojtbound
25880 \begin_inset LatexCommand \index{\#pragma nojtbound}
25881
25882 \end_inset 
25883
25884  can be used to turn off checking the 
25885 \emph on 
25886 j
25887 \emph default 
25888 ump 
25889 \emph on 
25890 t
25891 \emph default 
25892 able 
25893 \emph on 
25894 bound
25895 \emph default 
25896 aries.
25897  It has no effect if a default label is supplied.
25898  Use of this pragma is dangerous: if the switch
25899 \begin_inset LatexCommand \index{switch statement}
25900
25901 \end_inset 
25902
25903  argument is not matched by a case statement the processor will happily
25904  jump into Nirvana.
25905 \layout Subsection
25906
25907 Bit-shifting Operations
25908 \begin_inset LatexCommand \index{Bit shifting}
25909
25910 \end_inset 
25911
25912 .
25913 \layout Standard
25914
25915 Bit shifting is one of the most frequently used operation in embedded programmin
25916 g.
25917  SDCC tries to implement bit-shift operations in the most efficient way
25918  possible, e.g.:
25919 \layout Verse
25920
25921
25922 \family typewriter 
25923 unsigned char i;
25924 \newline 
25925 ...
25926  
25927 \newline 
25928 i >>= 4; 
25929 \newline 
25930 ...
25931 \layout Standard
25932
25933 generates the following code:
25934 \layout Verse
25935
25936
25937 \family typewriter 
25938 mov\SpecialChar ~
25939  a,_i 
25940 \newline 
25941 swap a 
25942 \newline 
25943 anl\SpecialChar ~
25944  a,#0x0f 
25945 \newline 
25946 mov\SpecialChar ~
25947  _i,a
25948 \layout Standard
25949
25950 In general SDCC will never setup a loop if the shift count is known.
25951  Another example:
25952 \layout Verse
25953
25954
25955 \family typewriter 
25956 unsigned int i; 
25957 \newline 
25958 ...
25959  
25960 \newline 
25961 i >>= 9; 
25962 \newline 
25963 ...
25964 \layout Standard
25965
25966 will generate:
25967 \layout Verse
25968
25969
25970 \family typewriter 
25971 mov\SpecialChar ~
25972 \SpecialChar ~
25973 a,(_i + 1) 
25974 \newline 
25975 mov\SpecialChar ~
25976 \SpecialChar ~
25977 (_i + 1),#0x00 
25978 \newline 
25979 clr\SpecialChar ~
25980 \SpecialChar ~
25981
25982 \newline 
25983 rrc\SpecialChar ~
25984 \SpecialChar ~
25985
25986 \newline 
25987 mov\SpecialChar ~
25988 \SpecialChar ~
25989 _i,a
25990 \layout Subsection
25991
25992 Bit-rotation
25993 \begin_inset LatexCommand \index{Bit rotation}
25994
25995 \end_inset 
25996
25997
25998 \layout Standard
25999
26000 A special case of the bit-shift operation is bit rotation
26001 \begin_inset LatexCommand \index{rotating bits}
26002
26003 \end_inset 
26004
26005 , SDCC recognizes the following expression to be a left bit-rotation:
26006 \layout Verse
26007
26008
26009 \family typewriter 
26010 \series bold 
26011 unsigned
26012 \series default 
26013 \SpecialChar ~
26014 \SpecialChar ~
26015 char i;\SpecialChar ~
26016 \SpecialChar ~
26017 \SpecialChar ~
26018 \SpecialChar ~
26019 \SpecialChar ~
26020 \SpecialChar ~
26021 \SpecialChar ~
26022 \SpecialChar ~
26023 \SpecialChar ~
26024 \SpecialChar ~
26025 \SpecialChar ~
26026 /* unsigned is needed for rotation */ 
26027 \newline 
26028 ...
26029  
26030 \newline 
26031 i = ((i << 1) | (i >> 7)); 
26032 \family default 
26033
26034 \newline 
26035
26036 \family typewriter 
26037 ...
26038 \layout Standard
26039
26040 will generate the following code:
26041 \layout Verse
26042
26043
26044 \family typewriter 
26045 mov\SpecialChar ~
26046 \SpecialChar ~
26047 a,_i 
26048 \newline 
26049 rl\SpecialChar ~
26050 \SpecialChar ~
26051 \SpecialChar ~
26052
26053 \newline 
26054 mov\SpecialChar ~
26055 \SpecialChar ~
26056 _i,a
26057 \layout Standard
26058
26059 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
26060 ns of this case will also be recognized as bit-rotation, i.e.: 
26061 \layout Verse
26062
26063
26064 \family typewriter 
26065 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
26066 \layout Subsection
26067
26068 Nibble and Byte Swapping
26069 \layout Standard
26070
26071 Other special cases of the bit-shift operations are nibble or byte swapping
26072 \begin_inset LatexCommand \index{swapping nibbles/bytes}
26073
26074 \end_inset 
26075
26076 , SDCC recognizes the following expressions:
26077 \layout Verse
26078
26079
26080 \family typewriter 
26081 \series bold 
26082 unsigned
26083 \series default 
26084 \SpecialChar ~
26085 \SpecialChar ~
26086 char i; 
26087 \newline 
26088
26089 \series bold 
26090 unsigned
26091 \series default 
26092 \SpecialChar ~
26093 \SpecialChar ~
26094 int j; 
26095 \newline 
26096 ...
26097  
26098 \newline 
26099 i = ((i << 4) | (i >> 4)); 
26100 \family default 
26101
26102 \newline 
26103
26104 \family typewriter 
26105 j = ((j << 8) | (j >> 8)); 
26106 \layout Standard
26107
26108 and generates a swap instruction for the nibble swapping
26109 \begin_inset LatexCommand \index{Nibble swapping}
26110
26111 \end_inset 
26112
26113  or move instructions for the byte swapping
26114 \begin_inset LatexCommand \index{Byte swapping}
26115
26116 \end_inset 
26117
26118 .
26119  The 
26120 \begin_inset Quotes sld
26121 \end_inset 
26122
26123 j
26124 \begin_inset Quotes srd
26125 \end_inset 
26126
26127  example can be used to convert from little to big-endian or vice versa.
26128  If you want to change the endianness of a 
26129 \emph on 
26130 signed
26131 \emph default 
26132  integer you have to cast to 
26133 \family typewriter 
26134 (unsigned int)
26135 \family default 
26136  first.
26137 \layout Standard
26138
26139 Note that SDCC stores numbers in little-endian
26140 \begin_inset Foot
26141 collapsed false
26142
26143 \layout Standard
26144
26145 Usually 8-bit processors don't care much about endianness.
26146  This is not the case for the standard 8051 which only has an instruction
26147  to increment its 
26148 \emph on 
26149 dptr
26150 \emph default 
26151
26152 \begin_inset LatexCommand \index{DPTR}
26153
26154 \end_inset 
26155
26156 -datapointer
26157 \emph on 
26158  
26159 \emph default 
26160 so little-endian is the more efficient byte order.
26161 \end_inset 
26162
26163
26164 \begin_inset LatexCommand \index{little-endian}
26165
26166 \end_inset 
26167
26168
26169 \begin_inset LatexCommand \index{Endianness}
26170
26171 \end_inset 
26172
26173  format (i.e.
26174  lowest order first).
26175 \layout Subsection
26176
26177 Highest Order Bit
26178 \begin_inset LatexCommand \index{Highest Order Bit}
26179
26180 \end_inset 
26181
26182  / Any Order Bit
26183 \begin_inset LatexCommand \index{Any Order Bit}
26184
26185 \end_inset 
26186
26187
26188 \layout Standard
26189
26190 It is frequently required to obtain the highest order bit of an integral
26191  type (long, int, short or char types).
26192  Also obtaining any other order bit is not uncommon.
26193  SDCC recognizes the following expressions to yield the highest order bit
26194  and generates optimized code for it, e.g.:
26195 \layout Verse
26196
26197
26198 \family typewriter 
26199 unsigned int gint; 
26200 \newline 
26201
26202 \newline 
26203 foo () { 
26204 \newline 
26205 \SpecialChar ~
26206 \SpecialChar ~
26207 unsigned char hob1, aob1; 
26208 \newline 
26209 \SpecialChar ~
26210 \SpecialChar ~
26211 bit hob2, hob3, aob2, aob3; 
26212 \newline 
26213 \SpecialChar ~
26214 \SpecialChar ~
26215 ...
26216  
26217 \newline 
26218 \SpecialChar ~
26219 \SpecialChar ~
26220 hob1 = (gint >> 15) & 1; 
26221 \newline 
26222 \SpecialChar ~
26223 \SpecialChar ~
26224 hob2 = (gint >> 15) & 1; 
26225 \newline 
26226 \SpecialChar ~
26227 \SpecialChar ~
26228 hob3 = gint & 0x8000; 
26229 \newline 
26230 \SpecialChar ~
26231 \SpecialChar ~
26232 aob1 = (gint >> 9) & 1; 
26233 \newline 
26234 \SpecialChar ~
26235 \SpecialChar ~
26236 aob2 = (gint >> 8) & 1; 
26237 \newline 
26238 \SpecialChar ~
26239 \SpecialChar ~
26240 aob3 = gint & 0x0800; 
26241 \newline 
26242 \SpecialChar ~
26243 \SpecialChar ~
26244 ..
26245  
26246 \newline 
26247 }
26248 \layout Standard
26249
26250 will generate the following code:
26251 \layout Verse
26252
26253
26254 \family typewriter 
26255 \SpecialChar ~
26256 \SpecialChar ~
26257 \SpecialChar ~
26258 \SpecialChar ~
26259 \SpecialChar ~
26260 \SpecialChar ~
26261 \SpecialChar ~
26262 \SpecialChar ~
26263 \SpecialChar ~
26264 \SpecialChar ~
26265 \SpecialChar ~
26266 \SpecialChar ~
26267 \SpecialChar ~
26268 \SpecialChar ~
26269 \SpecialChar ~
26270 \SpecialChar ~
26271 \SpecialChar ~
26272 \SpecialChar ~
26273 \SpecialChar ~
26274 \SpecialChar ~
26275 \SpecialChar ~
26276 \SpecialChar ~
26277 \SpecialChar ~
26278 \SpecialChar ~
26279 \SpecialChar ~
26280  61 ;\SpecialChar ~
26281  hob.c 7 
26282 \newline 
26283 000A E5*01\SpecialChar ~
26284 \SpecialChar ~
26285 \SpecialChar ~
26286 \SpecialChar ~
26287 \SpecialChar ~
26288 \SpecialChar ~
26289 \SpecialChar ~
26290 \SpecialChar ~
26291 \SpecialChar ~
26292 \SpecialChar ~
26293 \SpecialChar ~
26294 \SpecialChar ~
26295 \SpecialChar ~
26296 \SpecialChar ~
26297 \SpecialChar ~
26298  62\SpecialChar ~
26299 \SpecialChar ~
26300 \SpecialChar ~
26301 \SpecialChar ~
26302 \SpecialChar ~
26303 \SpecialChar ~
26304 \SpecialChar ~
26305 \SpecialChar ~
26306  mov\SpecialChar ~
26307 \SpecialChar ~
26308  a,(_gint + 1) 
26309 \newline 
26310 000C 23\SpecialChar ~
26311 \SpecialChar ~
26312 \SpecialChar ~
26313 \SpecialChar ~
26314 \SpecialChar ~
26315 \SpecialChar ~
26316 \SpecialChar ~
26317 \SpecialChar ~
26318 \SpecialChar ~
26319 \SpecialChar ~
26320 \SpecialChar ~
26321 \SpecialChar ~
26322 \SpecialChar ~
26323 \SpecialChar ~
26324 \SpecialChar ~
26325 \SpecialChar ~
26326 \SpecialChar ~
26327 \SpecialChar ~
26328  63\SpecialChar ~
26329 \SpecialChar ~
26330 \SpecialChar ~
26331 \SpecialChar ~
26332 \SpecialChar ~
26333 \SpecialChar ~
26334 \SpecialChar ~
26335 \SpecialChar ~
26336  rl\SpecialChar ~
26337 \SpecialChar ~
26338 \SpecialChar ~
26339  a 
26340 \newline 
26341 000D 54 01\SpecialChar ~
26342 \SpecialChar ~
26343 \SpecialChar ~
26344 \SpecialChar ~
26345 \SpecialChar ~
26346 \SpecialChar ~
26347 \SpecialChar ~
26348 \SpecialChar ~
26349 \SpecialChar ~
26350 \SpecialChar ~
26351 \SpecialChar ~
26352 \SpecialChar ~
26353 \SpecialChar ~
26354 \SpecialChar ~
26355 \SpecialChar ~
26356  64\SpecialChar ~
26357 \SpecialChar ~
26358 \SpecialChar ~
26359 \SpecialChar ~
26360 \SpecialChar ~
26361 \SpecialChar ~
26362 \SpecialChar ~
26363 \SpecialChar ~
26364  anl\SpecialChar ~
26365 \SpecialChar ~
26366  a,#0x01 
26367 \newline 
26368 000F F5*02\SpecialChar ~
26369 \SpecialChar ~
26370 \SpecialChar ~
26371 \SpecialChar ~
26372 \SpecialChar ~
26373 \SpecialChar ~
26374 \SpecialChar ~
26375 \SpecialChar ~
26376 \SpecialChar ~
26377 \SpecialChar ~
26378 \SpecialChar ~
26379 \SpecialChar ~
26380 \SpecialChar ~
26381 \SpecialChar ~
26382 \SpecialChar ~
26383  65\SpecialChar ~
26384 \SpecialChar ~
26385 \SpecialChar ~
26386 \SpecialChar ~
26387 \SpecialChar ~
26388 \SpecialChar ~
26389 \SpecialChar ~
26390 \SpecialChar ~
26391  mov\SpecialChar ~
26392 \SpecialChar ~
26393  _foo_hob1_1_1,a 
26394 \newline 
26395 \SpecialChar ~
26396 \SpecialChar ~
26397 \SpecialChar ~
26398 \SpecialChar ~
26399 \SpecialChar ~
26400 \SpecialChar ~
26401 \SpecialChar ~
26402 \SpecialChar ~
26403 \SpecialChar ~
26404 \SpecialChar ~
26405 \SpecialChar ~
26406 \SpecialChar ~
26407 \SpecialChar ~
26408 \SpecialChar ~
26409 \SpecialChar ~
26410 \SpecialChar ~
26411 \SpecialChar ~
26412 \SpecialChar ~
26413 \SpecialChar ~
26414 \SpecialChar ~
26415 \SpecialChar ~
26416 \SpecialChar ~
26417 \SpecialChar ~
26418 \SpecialChar ~
26419 \SpecialChar ~
26420  66 ;\SpecialChar ~
26421  hob.c 8 
26422 \newline 
26423 0011 E5*01\SpecialChar ~
26424 \SpecialChar ~
26425 \SpecialChar ~
26426 \SpecialChar ~
26427 \SpecialChar ~
26428 \SpecialChar ~
26429 \SpecialChar ~
26430 \SpecialChar ~
26431 \SpecialChar ~
26432 \SpecialChar ~
26433 \SpecialChar ~
26434 \SpecialChar ~
26435 \SpecialChar ~
26436 \SpecialChar ~
26437 \SpecialChar ~
26438  67\SpecialChar ~
26439 \SpecialChar ~
26440 \SpecialChar ~
26441 \SpecialChar ~
26442 \SpecialChar ~
26443 \SpecialChar ~
26444 \SpecialChar ~
26445 \SpecialChar ~
26446  mov\SpecialChar ~
26447 \SpecialChar ~
26448  a,(_gint + 1) 
26449 \newline 
26450 0013 33\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 \SpecialChar ~
26464 \SpecialChar ~
26465 \SpecialChar ~
26466 \SpecialChar ~
26467 \SpecialChar ~
26468  68\SpecialChar ~
26469 \SpecialChar ~
26470 \SpecialChar ~
26471 \SpecialChar ~
26472 \SpecialChar ~
26473 \SpecialChar ~
26474 \SpecialChar ~
26475 \SpecialChar ~
26476  rlc\SpecialChar ~
26477 \SpecialChar ~
26478  a 
26479 \newline 
26480 0014 92*00\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 \SpecialChar ~
26495  69\SpecialChar ~
26496 \SpecialChar ~
26497 \SpecialChar ~
26498 \SpecialChar ~
26499 \SpecialChar ~
26500 \SpecialChar ~
26501 \SpecialChar ~
26502 \SpecialChar ~
26503  mov\SpecialChar ~
26504 \SpecialChar ~
26505  _foo_hob2_1_1,c 
26506 \newline 
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 \SpecialChar ~
26527 \SpecialChar ~
26528 \SpecialChar ~
26529 \SpecialChar ~
26530 \SpecialChar ~
26531 \SpecialChar ~
26532  66 ;\SpecialChar ~
26533  hob.c 9 
26534 \newline 
26535 0016 E5*01\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  67\SpecialChar ~
26551 \SpecialChar ~
26552 \SpecialChar ~
26553 \SpecialChar ~
26554 \SpecialChar ~
26555 \SpecialChar ~
26556 \SpecialChar ~
26557 \SpecialChar ~
26558  mov\SpecialChar ~
26559 \SpecialChar ~
26560  a,(_gint + 1) 
26561 \newline 
26562 0018 33\SpecialChar ~
26563 \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  68\SpecialChar ~
26581 \SpecialChar ~
26582 \SpecialChar ~
26583 \SpecialChar ~
26584 \SpecialChar ~
26585 \SpecialChar ~
26586 \SpecialChar ~
26587 \SpecialChar ~
26588  rlc\SpecialChar ~
26589 \SpecialChar ~
26590  a 
26591 \newline 
26592 0019 92*01\SpecialChar ~
26593 \SpecialChar ~
26594 \SpecialChar ~
26595 \SpecialChar ~
26596 \SpecialChar ~
26597 \SpecialChar ~
26598 \SpecialChar ~
26599 \SpecialChar ~
26600 \SpecialChar ~
26601 \SpecialChar ~
26602 \SpecialChar ~
26603 \SpecialChar ~
26604 \SpecialChar ~
26605 \SpecialChar ~
26606 \SpecialChar ~
26607  69\SpecialChar ~
26608 \SpecialChar ~
26609 \SpecialChar ~
26610 \SpecialChar ~
26611 \SpecialChar ~
26612 \SpecialChar ~
26613 \SpecialChar ~
26614 \SpecialChar ~
26615  mov\SpecialChar ~
26616 \SpecialChar ~
26617  _foo_hob3_1_1,c 
26618 \newline 
26619 \SpecialChar ~
26620 \SpecialChar ~
26621 \SpecialChar ~
26622 \SpecialChar ~
26623 \SpecialChar ~
26624 \SpecialChar ~
26625 \SpecialChar ~
26626 \SpecialChar ~
26627 \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  70 ;\SpecialChar ~
26645  hob.c 10 
26646 \newline 
26647 001B E5*01\SpecialChar ~
26648 \SpecialChar ~
26649 \SpecialChar ~
26650 \SpecialChar ~
26651 \SpecialChar ~
26652 \SpecialChar ~
26653 \SpecialChar ~
26654 \SpecialChar ~
26655 \SpecialChar ~
26656 \SpecialChar ~
26657 \SpecialChar ~
26658 \SpecialChar ~
26659 \SpecialChar ~
26660 \SpecialChar ~
26661 \SpecialChar ~
26662  71\SpecialChar ~
26663 \SpecialChar ~
26664 \SpecialChar ~
26665 \SpecialChar ~
26666 \SpecialChar ~
26667 \SpecialChar ~
26668 \SpecialChar ~
26669 \SpecialChar ~
26670  mov\SpecialChar ~
26671 \SpecialChar ~
26672  a,(_gint + 1) 
26673 \newline 
26674 001D 03\SpecialChar ~
26675 \SpecialChar ~
26676 \SpecialChar ~
26677 \SpecialChar ~
26678 \SpecialChar ~
26679 \SpecialChar ~
26680 \SpecialChar ~
26681 \SpecialChar ~
26682 \SpecialChar ~
26683 \SpecialChar ~
26684 \SpecialChar ~
26685 \SpecialChar ~
26686 \SpecialChar ~
26687 \SpecialChar ~
26688 \SpecialChar ~
26689 \SpecialChar ~
26690 \SpecialChar ~
26691 \SpecialChar ~
26692  72\SpecialChar ~
26693 \SpecialChar ~
26694 \SpecialChar ~
26695 \SpecialChar ~
26696 \SpecialChar ~
26697 \SpecialChar ~
26698 \SpecialChar ~
26699 \SpecialChar ~
26700  rr\SpecialChar ~
26701 \SpecialChar ~
26702 \SpecialChar ~
26703  a 
26704 \newline 
26705 001E 54 01\SpecialChar ~
26706 \SpecialChar ~
26707 \SpecialChar ~
26708 \SpecialChar ~
26709 \SpecialChar ~
26710 \SpecialChar ~
26711 \SpecialChar ~
26712 \SpecialChar ~
26713 \SpecialChar ~
26714 \SpecialChar ~
26715 \SpecialChar ~
26716 \SpecialChar ~
26717 \SpecialChar ~
26718 \SpecialChar ~
26719 \SpecialChar ~
26720  73\SpecialChar ~
26721 \SpecialChar ~
26722 \SpecialChar ~
26723 \SpecialChar ~
26724 \SpecialChar ~
26725 \SpecialChar ~
26726 \SpecialChar ~
26727 \SpecialChar ~
26728  anl\SpecialChar ~
26729 \SpecialChar ~
26730  a,#0x01 
26731 \newline 
26732 0020 F5*03\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  74\SpecialChar ~
26748 \SpecialChar ~
26749 \SpecialChar ~
26750 \SpecialChar ~
26751 \SpecialChar ~
26752 \SpecialChar ~
26753 \SpecialChar ~
26754 \SpecialChar ~
26755  mov\SpecialChar ~
26756 \SpecialChar ~
26757  _foo_aob1_1_1,a 
26758 \newline 
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  75 ;\SpecialChar ~
26785  hob.c 11 
26786 \newline 
26787 0022 E5*01\SpecialChar ~
26788 \SpecialChar ~
26789 \SpecialChar ~
26790 \SpecialChar ~
26791 \SpecialChar ~
26792 \SpecialChar ~
26793 \SpecialChar ~
26794 \SpecialChar ~
26795 \SpecialChar ~
26796 \SpecialChar ~
26797 \SpecialChar ~
26798 \SpecialChar ~
26799 \SpecialChar ~
26800 \SpecialChar ~
26801 \SpecialChar ~
26802  76\SpecialChar ~
26803 \SpecialChar ~
26804 \SpecialChar ~
26805 \SpecialChar ~
26806 \SpecialChar ~
26807 \SpecialChar ~
26808 \SpecialChar ~
26809 \SpecialChar ~
26810  mov\SpecialChar ~
26811 \SpecialChar ~
26812  a,(_gint + 1) 
26813 \newline 
26814 0024 13\SpecialChar ~
26815 \SpecialChar ~
26816 \SpecialChar ~
26817 \SpecialChar ~
26818 \SpecialChar ~
26819 \SpecialChar ~
26820 \SpecialChar ~
26821 \SpecialChar ~
26822 \SpecialChar ~
26823 \SpecialChar ~
26824 \SpecialChar ~
26825 \SpecialChar ~
26826 \SpecialChar ~
26827 \SpecialChar ~
26828 \SpecialChar ~
26829 \SpecialChar ~
26830 \SpecialChar ~
26831 \SpecialChar ~
26832  77\SpecialChar ~
26833 \SpecialChar ~
26834 \SpecialChar ~
26835 \SpecialChar ~
26836 \SpecialChar ~
26837 \SpecialChar ~
26838 \SpecialChar ~
26839 \SpecialChar ~
26840  rrc\SpecialChar ~
26841 \SpecialChar ~
26842  a 
26843 \newline 
26844 0025 92*02\SpecialChar ~
26845 \SpecialChar ~
26846 \SpecialChar ~
26847 \SpecialChar ~
26848 \SpecialChar ~
26849 \SpecialChar ~
26850 \SpecialChar ~
26851 \SpecialChar ~
26852 \SpecialChar ~
26853 \SpecialChar ~
26854 \SpecialChar ~
26855 \SpecialChar ~
26856 \SpecialChar ~
26857 \SpecialChar ~
26858 \SpecialChar ~
26859  78\SpecialChar ~
26860 \SpecialChar ~
26861 \SpecialChar ~
26862 \SpecialChar ~
26863 \SpecialChar ~
26864 \SpecialChar ~
26865 \SpecialChar ~
26866 \SpecialChar ~
26867  mov\SpecialChar ~
26868 \SpecialChar ~
26869  _foo_aob2_1_1,c 
26870 \newline 
26871 \SpecialChar ~
26872 \SpecialChar ~
26873 \SpecialChar ~
26874 \SpecialChar ~
26875 \SpecialChar ~
26876 \SpecialChar ~
26877 \SpecialChar ~
26878 \SpecialChar ~
26879 \SpecialChar ~
26880 \SpecialChar ~
26881 \SpecialChar ~
26882 \SpecialChar ~
26883 \SpecialChar ~
26884 \SpecialChar ~
26885 \SpecialChar ~
26886 \SpecialChar ~
26887 \SpecialChar ~
26888 \SpecialChar ~
26889 \SpecialChar ~
26890 \SpecialChar ~
26891 \SpecialChar ~
26892 \SpecialChar ~
26893 \SpecialChar ~
26894 \SpecialChar ~
26895 \SpecialChar ~
26896  79 ;\SpecialChar ~
26897  hob.c 12 
26898 \newline 
26899 0027 E5*01\SpecialChar ~
26900 \SpecialChar ~
26901 \SpecialChar ~
26902 \SpecialChar ~
26903 \SpecialChar ~
26904 \SpecialChar ~
26905 \SpecialChar ~
26906 \SpecialChar ~
26907 \SpecialChar ~
26908 \SpecialChar ~
26909 \SpecialChar ~
26910 \SpecialChar ~
26911 \SpecialChar ~
26912 \SpecialChar ~
26913 \SpecialChar ~
26914  80\SpecialChar ~
26915 \SpecialChar ~
26916 \SpecialChar ~
26917 \SpecialChar ~
26918 \SpecialChar ~
26919 \SpecialChar ~
26920 \SpecialChar ~
26921 \SpecialChar ~
26922  mov\SpecialChar ~
26923 \SpecialChar ~
26924  a,(_gint + 1) 
26925 \newline 
26926 0029 A2 E3\SpecialChar ~
26927 \SpecialChar ~
26928 \SpecialChar ~
26929 \SpecialChar ~
26930 \SpecialChar ~
26931 \SpecialChar ~
26932 \SpecialChar ~
26933 \SpecialChar ~
26934 \SpecialChar ~
26935 \SpecialChar ~
26936 \SpecialChar ~
26937 \SpecialChar ~
26938 \SpecialChar ~
26939 \SpecialChar ~
26940 \SpecialChar ~
26941  81\SpecialChar ~
26942 \SpecialChar ~
26943 \SpecialChar ~
26944 \SpecialChar ~
26945 \SpecialChar ~
26946 \SpecialChar ~
26947 \SpecialChar ~
26948 \SpecialChar ~
26949  mov\SpecialChar ~
26950 \SpecialChar ~
26951  c,acc[3] 
26952 \newline 
26953 002B 92*03\SpecialChar ~
26954 \SpecialChar ~
26955 \SpecialChar ~
26956 \SpecialChar ~
26957 \SpecialChar ~
26958 \SpecialChar ~
26959 \SpecialChar ~
26960 \SpecialChar ~
26961 \SpecialChar ~
26962 \SpecialChar ~
26963 \SpecialChar ~
26964 \SpecialChar ~
26965 \SpecialChar ~
26966 \SpecialChar ~
26967 \SpecialChar ~
26968  82\SpecialChar ~
26969 \SpecialChar ~
26970 \SpecialChar ~
26971 \SpecialChar ~
26972 \SpecialChar ~
26973 \SpecialChar ~
26974 \SpecialChar ~
26975 \SpecialChar ~
26976  mov\SpecialChar ~
26977 \SpecialChar ~
26978  _foo_aob3_1_1,c 
26979 \layout Standard
26980
26981 Other variations of these cases however will 
26982 \emph on 
26983 not
26984 \emph default 
26985  be recognized.
26986  They are standard C expressions, so I heartily recommend these be the only
26987  way to get the highest order bit, (it is portable).
26988  Of course it will be recognized even if it is embedded in other expressions,
26989  e.g.:
26990 \layout Verse
26991
26992
26993 \family typewriter 
26994 xyz = gint + ((gint >> 15) & 1);
26995 \layout Standard
26996
26997 will still be recognized.
26998 \layout Subsection
26999
27000 Higher Order Byte
27001 \begin_inset LatexCommand \index{Higher Order Byte}
27002
27003 \end_inset 
27004
27005  / Higher Order Word
27006 \begin_inset LatexCommand \index{Higher Order Word}
27007
27008 \end_inset 
27009
27010
27011 \layout Standard
27012
27013 It is also frequently required to obtain a higher order byte or word of
27014  a larger integral type (long, int or short types).
27015  SDCC recognizes the following expressions to yield the higher order byte
27016  or word and generates optimized code for it, e.g.:
27017 \layout Verse
27018
27019
27020 \family typewriter 
27021 unsigned int gint; 
27022 \newline 
27023 unsigned long int glong; 
27024 \newline 
27025
27026 \newline 
27027 foo () { 
27028 \newline 
27029 \SpecialChar ~
27030 \SpecialChar ~
27031 unsigned char hob1, hob2; 
27032 \newline 
27033 \SpecialChar ~
27034 \SpecialChar ~
27035 unsigned int how1, how2; 
27036 \newline 
27037 \SpecialChar ~
27038 \SpecialChar ~
27039 ...
27040  
27041 \newline 
27042 \SpecialChar ~
27043 \SpecialChar ~
27044 hob1 = (gint >> 8) & 0xFF; 
27045 \newline 
27046 \SpecialChar ~
27047 \SpecialChar ~
27048 hob2 = glong >> 24; 
27049 \newline 
27050 \SpecialChar ~
27051 \SpecialChar ~
27052 how1 = (glong >> 16) & 0xFFFF; 
27053 \newline 
27054 \SpecialChar ~
27055 \SpecialChar ~
27056 how2 = glong >> 8; 
27057 \newline 
27058 \SpecialChar ~
27059 \SpecialChar ~
27060 ..
27061  
27062 \newline 
27063 }
27064 \layout Standard
27065
27066 will generate the following code:
27067 \layout Verse
27068
27069
27070 \family typewriter 
27071 \SpecialChar ~
27072 \SpecialChar ~
27073 \SpecialChar ~
27074 \SpecialChar ~
27075 \SpecialChar ~
27076 \SpecialChar ~
27077 \SpecialChar ~
27078 \SpecialChar ~
27079 \SpecialChar ~
27080 \SpecialChar ~
27081 \SpecialChar ~
27082 \SpecialChar ~
27083 \SpecialChar ~
27084 \SpecialChar ~
27085 \SpecialChar ~
27086 \SpecialChar ~
27087 \SpecialChar ~
27088 \SpecialChar ~
27089 \SpecialChar ~
27090 \SpecialChar ~
27091 \SpecialChar ~
27092 \SpecialChar ~
27093 \SpecialChar ~
27094 \SpecialChar ~
27095 \SpecialChar ~
27096  91 ;\SpecialChar ~
27097  hob.c 15 
27098 \newline 
27099 0037 85*01*06\SpecialChar ~
27100 \SpecialChar ~
27101 \SpecialChar ~
27102 \SpecialChar ~
27103 \SpecialChar ~
27104 \SpecialChar ~
27105 \SpecialChar ~
27106 \SpecialChar ~
27107 \SpecialChar ~
27108 \SpecialChar ~
27109 \SpecialChar ~
27110 \SpecialChar ~
27111  92\SpecialChar ~
27112 \SpecialChar ~
27113 \SpecialChar ~
27114 \SpecialChar ~
27115 \SpecialChar ~
27116 \SpecialChar ~
27117 \SpecialChar ~
27118 \SpecialChar ~
27119  mov\SpecialChar ~
27120 \SpecialChar ~
27121  _foo_hob1_1_1,(_gint + 1) 
27122 \newline 
27123 \SpecialChar ~
27124 \SpecialChar ~
27125 \SpecialChar ~
27126 \SpecialChar ~
27127 \SpecialChar ~
27128 \SpecialChar ~
27129 \SpecialChar ~
27130 \SpecialChar ~
27131 \SpecialChar ~
27132 \SpecialChar ~
27133 \SpecialChar ~
27134 \SpecialChar ~
27135 \SpecialChar ~
27136 \SpecialChar ~
27137 \SpecialChar ~
27138 \SpecialChar ~
27139 \SpecialChar ~
27140 \SpecialChar ~
27141 \SpecialChar ~
27142 \SpecialChar ~
27143 \SpecialChar ~
27144 \SpecialChar ~
27145 \SpecialChar ~
27146 \SpecialChar ~
27147 \SpecialChar ~
27148  93 ;\SpecialChar ~
27149  hob.c 16 
27150 \newline 
27151 003A 85*05*07\SpecialChar ~
27152 \SpecialChar ~
27153 \SpecialChar ~
27154 \SpecialChar ~
27155 \SpecialChar ~
27156 \SpecialChar ~
27157 \SpecialChar ~
27158 \SpecialChar ~
27159 \SpecialChar ~
27160 \SpecialChar ~
27161 \SpecialChar ~
27162 \SpecialChar ~
27163  94\SpecialChar ~
27164 \SpecialChar ~
27165 \SpecialChar ~
27166 \SpecialChar ~
27167 \SpecialChar ~
27168 \SpecialChar ~
27169 \SpecialChar ~
27170 \SpecialChar ~
27171  mov\SpecialChar ~
27172 \SpecialChar ~
27173  _foo_hob2_1_1,(_glong + 3) 
27174 \newline 
27175 \SpecialChar ~
27176 \SpecialChar ~
27177 \SpecialChar ~
27178 \SpecialChar ~
27179 \SpecialChar ~
27180 \SpecialChar ~
27181 \SpecialChar ~
27182 \SpecialChar ~
27183 \SpecialChar ~
27184 \SpecialChar ~
27185 \SpecialChar ~
27186 \SpecialChar ~
27187 \SpecialChar ~
27188 \SpecialChar ~
27189 \SpecialChar ~
27190 \SpecialChar ~
27191 \SpecialChar ~
27192 \SpecialChar ~
27193 \SpecialChar ~
27194 \SpecialChar ~
27195 \SpecialChar ~
27196 \SpecialChar ~
27197 \SpecialChar ~
27198 \SpecialChar ~
27199 \SpecialChar ~
27200  95 ;\SpecialChar ~
27201  hob.c 17 
27202 \newline 
27203 003D 85*04*08\SpecialChar ~
27204 \SpecialChar ~
27205 \SpecialChar ~
27206 \SpecialChar ~
27207 \SpecialChar ~
27208 \SpecialChar ~
27209 \SpecialChar ~
27210 \SpecialChar ~
27211 \SpecialChar ~
27212 \SpecialChar ~
27213 \SpecialChar ~
27214 \SpecialChar ~
27215  96\SpecialChar ~
27216 \SpecialChar ~
27217 \SpecialChar ~
27218 \SpecialChar ~
27219 \SpecialChar ~
27220 \SpecialChar ~
27221 \SpecialChar ~
27222 \SpecialChar ~
27223  mov\SpecialChar ~
27224 \SpecialChar ~
27225  _foo_how1_1_1,(_glong + 2) 
27226 \newline 
27227 0040 85*05*09\SpecialChar ~
27228 \SpecialChar ~
27229 \SpecialChar ~
27230 \SpecialChar ~
27231 \SpecialChar ~
27232 \SpecialChar ~
27233 \SpecialChar ~
27234 \SpecialChar ~
27235 \SpecialChar ~
27236 \SpecialChar ~
27237 \SpecialChar ~
27238 \SpecialChar ~
27239  97\SpecialChar ~
27240 \SpecialChar ~
27241 \SpecialChar ~
27242 \SpecialChar ~
27243 \SpecialChar ~
27244 \SpecialChar ~
27245 \SpecialChar ~
27246 \SpecialChar ~
27247  mov\SpecialChar ~
27248 \SpecialChar ~
27249  (_foo_how1_1_1 + 1),(_glong + 3) 
27250 \newline 
27251 0043 85*03*0A\SpecialChar ~
27252 \SpecialChar ~
27253 \SpecialChar ~
27254 \SpecialChar ~
27255 \SpecialChar ~
27256 \SpecialChar ~
27257 \SpecialChar ~
27258 \SpecialChar ~
27259 \SpecialChar ~
27260 \SpecialChar ~
27261 \SpecialChar ~
27262 \SpecialChar ~
27263  98\SpecialChar ~
27264 \SpecialChar ~
27265 \SpecialChar ~
27266 \SpecialChar ~
27267 \SpecialChar ~
27268 \SpecialChar ~
27269 \SpecialChar ~
27270 \SpecialChar ~
27271  mov\SpecialChar ~
27272 \SpecialChar ~
27273  _foo_how2_1_1,(_glong + 1) 
27274 \newline 
27275 0046 85*04*0B\SpecialChar ~
27276 \SpecialChar ~
27277 \SpecialChar ~
27278 \SpecialChar ~
27279 \SpecialChar ~
27280 \SpecialChar ~
27281 \SpecialChar ~
27282 \SpecialChar ~
27283 \SpecialChar ~
27284 \SpecialChar ~
27285 \SpecialChar ~
27286 \SpecialChar ~
27287  99\SpecialChar ~
27288 \SpecialChar ~
27289 \SpecialChar ~
27290 \SpecialChar ~
27291 \SpecialChar ~
27292 \SpecialChar ~
27293 \SpecialChar ~
27294 \SpecialChar ~
27295  mov\SpecialChar ~
27296 \SpecialChar ~
27297  (_foo_how2_1_1 + 1),(_glong + 2) 
27298 \layout Standard
27299
27300 Again, variations of these cases may 
27301 \emph on 
27302 not
27303 \emph default 
27304  be recognized.
27305  They are standard C expressions, so I heartily recommend these be the only
27306  way to get the higher order byte/word, (it is portable).
27307  Of course it will be recognized even if it is embedded in other expressions,
27308  e.g.:
27309 \layout Verse
27310
27311
27312 \family typewriter 
27313 xyz = gint + ((gint >> 8) & 0xFF);
27314 \layout Standard
27315
27316 will still be recognized.
27317 \layout Subsection
27318
27319 Peephole Optimizer
27320 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
27321
27322 \end_inset 
27323
27324
27325 \begin_inset LatexCommand \index{Peephole optimizer}
27326
27327 \end_inset 
27328
27329
27330 \layout Standard
27331
27332 The compiler uses a rule based, pattern matching and re-writing mechanism
27333  for peep-hole optimization.
27334  It is inspired by 
27335 \emph on 
27336 copt
27337 \emph default 
27338  a peep-hole optimizer by Christopher W.
27339  Fraser (cwfraser\SpecialChar ~
27340 @\SpecialChar ~
27341 microsoft.com).
27342  A default set of rules are compiled into the compiler, additional rules
27343  may be added with the 
27344 \emph on 
27345 -
27346 \begin_inset ERT
27347 status Collapsed
27348
27349 \layout Standard
27350
27351 \backslash 
27352 /
27353 \end_inset 
27354
27355 -peep-file
27356 \begin_inset LatexCommand \index{-\/-peep-file}
27357
27358 \end_inset 
27359
27360  <filename>
27361 \emph default 
27362  option.
27363  The rule language is best illustrated with examples.
27364 \layout Verse
27365
27366
27367 \family typewriter 
27368 replace { 
27369 \newline 
27370 \SpecialChar ~
27371 \SpecialChar ~
27372 mov %1,a 
27373 \newline 
27374 \SpecialChar ~
27375 \SpecialChar ~
27376 mov a,%1
27377 \newline 
27378 } by {
27379 \newline 
27380 \SpecialChar ~
27381 \SpecialChar ~
27382 mov %1,a
27383 \newline 
27384 }
27385 \layout Standard
27386
27387 The above rule will change the following assembly
27388 \begin_inset LatexCommand \index{Assembler routines}
27389
27390 \end_inset 
27391
27392  sequence:
27393 \layout Verse
27394
27395
27396 \family typewriter 
27397 mov r1,a 
27398 \newline 
27399 mov a,r1
27400 \layout Standard
27401
27402 to
27403 \layout Verse
27404
27405
27406 \family typewriter 
27407 mov r1,a
27408 \layout Standard
27409
27410 Note: All occurrences of a 
27411 \emph on 
27412 %n
27413 \emph default 
27414  (pattern variable) must denote the same string.
27415  With the above rule, the assembly sequence:
27416 \layout Verse
27417
27418
27419 \family typewriter 
27420 mov r1,a 
27421 \newline 
27422 mov a,r2
27423 \layout Standard
27424
27425 will remain unmodified.
27426 \newline 
27427
27428 \newline 
27429 Other special case optimizations may be added by the user (via 
27430 \emph on 
27431 -
27432 \begin_inset ERT
27433 status Collapsed
27434
27435 \layout Standard
27436
27437 \backslash 
27438 /
27439 \end_inset 
27440
27441 -peep-file option
27442 \emph default 
27443 ).
27444  E.g.
27445  some variants of the 8051 MCU
27446 \begin_inset LatexCommand \index{MCS51 variants}
27447
27448 \end_inset 
27449
27450  allow only 
27451 \family typewriter 
27452 ajmp
27453 \family default 
27454  and 
27455 \family typewriter 
27456 acall
27457 \family default 
27458 .
27459  The following two rules will change all 
27460 \family typewriter 
27461 ljmp
27462 \family default 
27463  and 
27464 \family typewriter 
27465 lcall
27466 \family default 
27467  to 
27468 \family typewriter 
27469 ajmp
27470 \family default 
27471  and 
27472 \family typewriter 
27473 acall
27474 \layout Verse
27475
27476
27477 \family typewriter 
27478 replace { lcall %1 } by { acall %1 } 
27479 \newline 
27480 replace { ljmp %1 } by { ajmp %1 }
27481 \layout Standard
27482
27483 The 
27484 \emph on 
27485 inline-assembler code
27486 \emph default 
27487  is also passed through the peep hole optimizer, thus the peephole optimizer
27488  can also be used as an assembly level macro expander.
27489  The rules themselves are MCU dependent whereas the rule language infra-structur
27490 e is MCU independent.
27491  Peephole optimization rules for other MCU can be easily programmed using
27492  the rule language.
27493 \newline 
27494
27495 \newline 
27496 The syntax for a rule is as follows:
27497 \layout Verse
27498
27499
27500 \family typewriter 
27501 rule := replace [ restart ] '{' <assembly sequence> '
27502 \backslash 
27503 n' 
27504 \newline 
27505 \SpecialChar ~
27506  \SpecialChar ~
27507  \SpecialChar ~
27508  \SpecialChar ~
27509  \SpecialChar ~
27510  \SpecialChar ~
27511  \SpecialChar ~
27512  \SpecialChar ~
27513  \SpecialChar ~
27514  \SpecialChar ~
27515  \SpecialChar ~
27516  \SpecialChar ~
27517  \SpecialChar ~
27518  \SpecialChar ~
27519  '}' by '{' '
27520 \backslash 
27521 n' 
27522 \newline 
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  \SpecialChar ~
27536  \SpecialChar ~
27537  \SpecialChar ~
27538  \SpecialChar ~
27539  <assembly sequence> '
27540 \backslash 
27541 n' 
27542 \newline 
27543 \SpecialChar ~
27544  \SpecialChar ~
27545  \SpecialChar ~
27546  \SpecialChar ~
27547  \SpecialChar ~
27548  \SpecialChar ~
27549  \SpecialChar ~
27550  \SpecialChar ~
27551  \SpecialChar ~
27552  \SpecialChar ~
27553  \SpecialChar ~
27554  \SpecialChar ~
27555  \SpecialChar ~
27556  \SpecialChar ~
27557  '}' [if <functionName> ] '
27558 \backslash 
27559 n' 
27560 \layout Standard
27561
27562 <assembly sequence> := assembly instruction (each instruction including
27563  labels must be on a separate line).
27564 \newline 
27565
27566 \newline 
27567 The optimizer will apply to the rules one by one from the top in the sequence
27568  of their appearance, it will terminate when all rules are exhausted.
27569  If the 'restart' option is specified, then the optimizer will start matching
27570  the rules again from the top, this option for a rule is expensive (performance)
27571 , it is intended to be used in situations where a transformation will trigger
27572  the same rule again.
27573  An example of this (not a good one, it has side effects) is the following
27574  rule:
27575 \layout Verse
27576
27577
27578 \family typewriter 
27579 replace restart { 
27580 \newline 
27581 \SpecialChar ~
27582 \SpecialChar ~
27583 pop %1 
27584 \newline 
27585 \SpecialChar ~
27586 \SpecialChar ~
27587 push %1 } by { 
27588 \newline 
27589 \SpecialChar ~
27590 \SpecialChar ~
27591 ; nop 
27592 \newline 
27593 }
27594 \layout Standard
27595
27596 Note that the replace pattern cannot be a blank, but can be a comment line.
27597  Without the 'restart' option only the innermost 'pop' 'push' pair would
27598  be eliminated, i.e.:
27599 \layout Verse
27600
27601
27602 \family typewriter 
27603 pop ar1 
27604 \newline 
27605 pop ar2 
27606 \newline 
27607 push ar2 
27608 \newline 
27609 push ar1
27610 \layout Standard
27611
27612 would result in:
27613 \layout Verse
27614
27615
27616 \family typewriter 
27617 pop ar1 
27618 \newline 
27619 ; nop 
27620 \newline 
27621 push ar1
27622 \layout Standard
27623
27624
27625 \emph on 
27626 with
27627 \emph default 
27628  the restart option the rule will be applied again to the resulting code
27629  and then all the pop-push pairs will be eliminated to yield:
27630 \layout Verse
27631
27632
27633 \family typewriter 
27634 ; nop 
27635 \newline 
27636 ; nop
27637 \layout Standard
27638
27639 A conditional function can be attached to a rule.
27640  Attaching rules are somewhat more involved, let me illustrate this with
27641  an example.
27642 \layout Verse
27643
27644
27645 \family typewriter 
27646 replace { 
27647 \newline 
27648 \SpecialChar ~
27649  \SpecialChar ~
27650  \SpecialChar ~
27651 ljmp %5 
27652 \newline 
27653 %2:
27654 \newline 
27655 } by { 
27656 \newline 
27657 \SpecialChar ~
27658  \SpecialChar ~
27659  \SpecialChar ~
27660 sjmp %5 
27661 \newline 
27662 %2:
27663 \newline 
27664 } if labelInRange
27665 \layout Standard
27666
27667 The optimizer does a look-up of a function name table defined in function
27668  
27669 \emph on 
27670 callFuncByName
27671 \emph default 
27672  in the source file SDCCpeeph.c, with the name 
27673 \emph on 
27674 labelInRange
27675 \emph default 
27676 .
27677  If it finds a corresponding entry the function is called.
27678  Note there can be no parameters specified for these functions, in this
27679  case the use of 
27680 \emph on 
27681 %5
27682 \emph default 
27683  is crucial, since the function 
27684 \emph on 
27685 labelInRange
27686 \emph default 
27687  expects to find the label in that particular variable (the hash table containin
27688 g the variable bindings is passed as a parameter).
27689  If you want to code more such functions, take a close look at the function
27690  labelInRange and the calling mechanism in source file SDCCpeeph.c.
27691  Currently implemented are 
27692 \emph on 
27693 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
27694  24bitMode, portIsDS390, 24bitModeAndPortDS390 
27695 \emph default 
27696 and
27697 \emph on 
27698  notVolatile
27699 \emph default 
27700 .
27701 \layout Standard
27702
27703 I know this whole thing is a little kludgey, but maybe some day we will
27704  have some better means.
27705  If you are looking at this file, you will see the default rules that are
27706  compiled into the compiler, you can add your own rules in the default set
27707  there if you get tired of specifying the -
27708 \begin_inset ERT
27709 status Collapsed
27710
27711 \layout Standard
27712
27713 \backslash 
27714 /
27715 \end_inset 
27716
27717 -peep-file option.
27718 \layout Section
27719
27720 ANSI-Compliance
27721 \begin_inset LatexCommand \index{ANSI-compliance}
27722
27723 \end_inset 
27724
27725
27726 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
27727
27728 \end_inset 
27729
27730
27731 \layout Standard
27732
27733 The latest publically available version of the standard 
27734 \emph on 
27735 ISO/IEC 9899 - Programming languages - C
27736 \emph default 
27737  should be available at: 
27738 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
27739
27740 \end_inset 
27741
27742 .
27743 \newline 
27744
27745 \layout Standard
27746
27747 Deviations from the compliance:
27748 \layout Itemize
27749
27750 functions are not reentrant
27751 \begin_inset LatexCommand \index{reentrant}
27752
27753 \end_inset 
27754
27755  unless explicitly declared as such or the 
27756 \series bold 
27757 -
27758 \begin_inset ERT
27759 status Collapsed
27760
27761 \layout Standard
27762
27763 \backslash 
27764 /
27765 \end_inset 
27766
27767 -stack-auto
27768 \begin_inset LatexCommand \index{-\/-stack-auto}
27769
27770 \end_inset 
27771
27772
27773 \series default 
27774  command line option is specified.
27775 \layout Itemize
27776
27777 structures and unions cannot be assigned values directly, cannot be passed
27778  as function parameters or assigned to each other and cannot be a return
27779  value from a function, e.g.:
27780 \begin_deeper 
27781 \layout Verse
27782
27783
27784 \family typewriter 
27785 struct s { ...
27786  }; 
27787 \newline 
27788 struct s s1, s2; 
27789 \newline 
27790 foo() 
27791 \newline 
27792
27793 \newline 
27794 \SpecialChar ~
27795 \SpecialChar ~
27796 \SpecialChar ~
27797 \SpecialChar ~
27798 ...
27799  
27800 \newline 
27801 \SpecialChar ~
27802 \SpecialChar ~
27803 \SpecialChar ~
27804 \SpecialChar ~
27805 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
27806 \newline 
27807 \SpecialChar ~
27808 \SpecialChar ~
27809 \SpecialChar ~
27810 \SpecialChar ~
27811 ...
27812  
27813 \newline 
27814 }
27815 \newline 
27816 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
27817  */
27818 \newline 
27819
27820 \newline 
27821 \SpecialChar ~
27822 \SpecialChar ~
27823 \SpecialChar ~
27824 \SpecialChar ~
27825 struct s rets; 
27826 \newline 
27827 \SpecialChar ~
27828 \SpecialChar ~
27829 \SpecialChar ~
27830 \SpecialChar ~
27831 ...
27832  
27833 \newline 
27834 \SpecialChar ~
27835 \SpecialChar ~
27836 \SpecialChar ~
27837 \SpecialChar ~
27838 return rets;/* is invalid in SDCC although allowed in ANSI */ 
27839 \newline 
27840 }
27841 \end_deeper 
27842 \layout Itemize
27843
27844 initialization of structure arrays must be fully braced.
27845 \begin_deeper 
27846 \layout Verse
27847
27848
27849 \family typewriter 
27850 struct s { char x } a[] = {1, 2}; /* invalid in SDCC */
27851 \newline 
27852 struct s { char x } a[] = {{1}, {2}}; /* OK */
27853 \end_deeper 
27854 \layout Itemize
27855
27856 'long long
27857 \begin_inset LatexCommand \index{long long (not supported)}
27858
27859 \end_inset 
27860
27861 ' (64 bit integers
27862 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
27863
27864 \end_inset 
27865
27866 ) not supported.
27867 \layout Itemize
27868
27869 'double
27870 \begin_inset LatexCommand \index{double (not supported)}
27871
27872 \end_inset 
27873
27874 ' precision floating point 
27875 \begin_inset LatexCommand \index{Floating point support}
27876
27877 \end_inset 
27878
27879 not supported.
27880 \layout Itemize
27881
27882 Old K&R style
27883 \begin_inset LatexCommand \index{K\&R style}
27884
27885 \end_inset 
27886
27887  function declarations are NOT allowed.
27888 \begin_deeper 
27889 \layout Verse
27890
27891
27892 \family typewriter 
27893 foo(i,j) /* this old style of function declarations */ 
27894 \newline 
27895 int i,j; /* are valid in ANSI but not valid in SDCC */ 
27896 \newline 
27897
27898 \newline 
27899 \SpecialChar ~
27900 \SpecialChar ~
27901 \SpecialChar ~
27902 \SpecialChar ~
27903 ...
27904  
27905 \newline 
27906 }
27907 \end_deeper 
27908 \layout Itemize
27909
27910 Most enhancements in C99 are not supported, f.e.:
27911 \begin_deeper 
27912 \layout Verse
27913
27914
27915 \family typewriter 
27916 \series bold 
27917 inline
27918 \series default 
27919  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
27920  in C99 */
27921 \newline 
27922 for (
27923 \series bold 
27924 int
27925 \series default 
27926  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
27927 \end_deeper 
27928 \layout Itemize
27929
27930 Certain words that are valid identifiers in the standard may be reserved
27931  words in SDCC unless the 
27932 \series bold 
27933 -
27934 \begin_inset ERT
27935 status Collapsed
27936
27937 \layout Standard
27938
27939 \backslash 
27940 /
27941 \end_inset 
27942
27943 -std-c89
27944 \begin_inset LatexCommand \index{-\/-std-c89}
27945
27946 \end_inset 
27947
27948  or -
27949 \begin_inset ERT
27950 status Collapsed
27951
27952 \layout Standard
27953
27954 \backslash 
27955 /
27956 \end_inset 
27957
27958 -std-c99
27959 \begin_inset LatexCommand \index{-\/-std-c99}
27960
27961 \end_inset 
27962
27963
27964 \series default 
27965  command line options are used.
27966  These may include (depending on the selected processor): 'at', 'banked',
27967  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
27968 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
27969  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
27970  '_naked'.
27971  Compliant equivalents of these keywords are always available in a form
27972  that begin with two underscores
27973 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
27974
27975 \end_inset 
27976
27977 , f.e.
27978  '__data' instead of 'data'.
27979 \layout Section
27980
27981 Cyclomatic Complexity
27982 \begin_inset LatexCommand \index{Cyclomatic complexity}
27983
27984 \end_inset 
27985
27986
27987 \layout Standard
27988
27989 Cyclomatic complexity of a function is defined as the number of independent
27990  paths the program can take during execution of the function.
27991  This is an important number since it defines the number test cases you
27992  have to generate to validate the function.
27993  The accepted industry standard for complexity number is 10, if the cyclomatic
27994  complexity reported by SDCC exceeds 10 you should think about simplification
27995  of the function logic.
27996  Note that the complexity level is not related to the number of lines of
27997  code in a function.
27998  Large functions can have low complexity, and small functions can have large
27999  complexity levels.
28000  
28001 \newline 
28002
28003 \newline 
28004 SDCC uses the following formula to compute the complexity:
28005 \newline 
28006
28007 \layout Standard
28008
28009 complexity = (number of edges in control flow graph) - (number of nodes
28010  in control flow graph) + 2;
28011 \newline 
28012
28013 \newline 
28014 Having said that the industry standard is 10, you should be aware that in
28015  some cases it be may unavoidable to have a complexity level of less than
28016  10.
28017  For example if you have switch statement with more than 10 case labels,
28018  each case label adds one to the complexity level.
28019  The complexity level is by no means an absolute measure of the algorithmic
28020  complexity of the function, it does however provide a good starting point
28021  for which functions you might look at for further optimization.
28022 \layout Section
28023
28024 Retargetting for other Processors
28025 \layout Standard
28026
28027 The issues for retargetting the compiler are far too numerous to be covered
28028  by this document.
28029  What follows is a brief description of each of the seven phases of the
28030  compiler and its MCU dependency.
28031 \layout Itemize
28032
28033 Parsing the source and building the annotated parse tree.
28034  This phase is largely MCU independent (except for the language extensions).
28035  Syntax & semantic checks are also done in this phase, along with some initial
28036  optimizations like back patching labels and the pattern matching optimizations
28037  like bit-rotation etc.
28038 \layout Itemize
28039
28040 The second phase involves generating an intermediate code which can be easy
28041  manipulated during the later phases.
28042  This phase is entirely MCU independent.
28043  The intermediate code generation assumes the target machine has unlimited
28044  number of registers, and designates them with the name iTemp.
28045  The compiler can be made to dump a human readable form of the code generated
28046  by using the -
28047 \begin_inset ERT
28048 status Collapsed
28049
28050 \layout Standard
28051
28052 \backslash 
28053 /
28054 \end_inset 
28055
28056 -dumpraw option.
28057 \layout Itemize
28058
28059 This phase does the bulk of the standard optimizations and is also MCU independe
28060 nt.
28061  This phase can be broken down into several sub-phases:
28062 \newline 
28063
28064 \newline 
28065 Break down intermediate code (iCode) into basic blocks.
28066 \newline 
28067 Do control flow & data flow analysis on the basic blocks.
28068 \newline 
28069 Do local common subexpression elimination, then global subexpression elimination
28070 \newline 
28071 Dead code elimination
28072 \newline 
28073 Loop optimizations
28074 \newline 
28075 If loop optimizations caused any changes then do 'global subexpression eliminati
28076 on' and 'dead code elimination' again.
28077 \layout Itemize
28078
28079 This phase determines the live-ranges; by live range I mean those iTemp
28080  variables defined by the compiler that still survive after all the optimization
28081 s.
28082  Live range analysis
28083 \begin_inset LatexCommand \index{Live range analysis}
28084
28085 \end_inset 
28086
28087  is essential for register allocation, since these computation determines
28088  which of these iTemps will be assigned to registers, and for how long.
28089 \layout Itemize
28090
28091 Phase five is register allocation.
28092  There are two parts to this process.
28093 \newline 
28094
28095 \newline 
28096 The first part I call 'register packing' (for lack of a better term).
28097  In this case several MCU specific expression folding is done to reduce
28098  register pressure.
28099 \newline 
28100
28101 \newline 
28102 The second part is more MCU independent and deals with allocating registers
28103  to the remaining live ranges.
28104  A lot of MCU specific code does creep into this phase because of the limited
28105  number of index registers available in the 8051.
28106 \layout Itemize
28107
28108 The Code generation phase is (unhappily), entirely MCU dependent and very
28109  little (if any at all) of this code can be reused for other MCU.
28110  However the scheme for allocating a homogenized assembler operand for each
28111  iCode operand may be reused.
28112 \layout Itemize
28113
28114 As mentioned in the optimization section the peep-hole optimizer is rule
28115  based system, which can reprogrammed for other MCUs.
28116 \layout Chapter
28117
28118 Compiler internals
28119 \begin_inset LatexCommand \index{Compiler internals}
28120
28121 \end_inset 
28122
28123
28124 \layout Section
28125
28126 The anatomy of the compiler
28127 \begin_inset LatexCommand \label{sub:The-anatomy-of}
28128
28129 \end_inset 
28130
28131
28132 \layout Standard
28133
28134
28135 \shape italic 
28136 This is an excerpt from an article published in Circuit Cellar Magazine
28137  in 
28138 \series bold 
28139 August 2000
28140 \series default 
28141 .
28142  It's a little outdated (the compiler is much more efficient now and user/develo
28143 per friendly), but pretty well exposes the guts of it all.
28144 \shape default 
28145
28146 \newline 
28147
28148 \newline 
28149 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
28150  It is fairly easy to retarget for other 8-bit MCU.
28151  Here we take a look at some of the internals of the compiler.
28152  
28153 \layout Paragraph*
28154
28155 Parsing
28156 \begin_inset LatexCommand \index{Parsing}
28157
28158 \end_inset 
28159
28160  
28161 \layout Standard
28162
28163 Parsing the input source file and creating an AST (Annotated Syntax Tree
28164 \begin_inset LatexCommand \index{Annotated syntax tree}
28165
28166 \end_inset 
28167
28168 ).
28169  This phase also involves propagating types (annotating each node of the
28170  parse tree with type information) and semantic analysis.
28171  There are some MCU specific parsing rules.
28172  For example the storage classes, the extended storage classes are MCU specific
28173  while there may be a xdata storage class for 8051 there is no such storage
28174  class for z80 or Atmel AVR.
28175  SDCC allows MCU specific storage class extensions, i.e.
28176  xdata will be treated as a storage class specifier when parsing 8051 C
28177  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
28178  C code.
28179 \layout Paragraph*
28180
28181 Generating iCode
28182 \begin_inset LatexCommand \index{iCode}
28183
28184 \end_inset 
28185
28186
28187 \layout Standard
28188
28189 Intermediate code generation.
28190  In this phase the AST is broken down into three-operand form (iCode).
28191  These three operand forms are represented as doubly linked lists.
28192  ICode is the term given to the intermediate form generated by the compiler.
28193  ICode example section shows some examples of iCode generated for some simple
28194  C source functions.
28195 \layout Paragraph*
28196
28197 Optimizations
28198 \begin_inset LatexCommand \index{Optimizations}
28199
28200 \end_inset 
28201
28202 .
28203 \layout Standard
28204
28205 Bulk of the target independent optimizations is performed in this phase.
28206  The optimizations include constant propagation, common sub-expression eliminati
28207 on, loop invariant code movement, strength reduction of loop induction variables
28208  and dead-code elimination.
28209 \layout Paragraph*
28210
28211 Live range analysis
28212 \begin_inset LatexCommand \index{Live range analysis}
28213
28214 \end_inset 
28215
28216
28217 \layout Standard
28218
28219 During intermediate code generation phase, the compiler assumes the target
28220  machine has infinite number of registers and generates a lot of temporary
28221  variables.
28222  The live range computation determines the lifetime of each of these compiler-ge
28223 nerated temporaries.
28224  A picture speaks a thousand words.
28225  ICode example sections show the live range annotations for each of the
28226  operand.
28227  It is important to note here, each iCode is assigned a number in the order
28228  of its execution in the function.
28229  The live ranges are computed in terms of these numbers.
28230  The from number is the number of the iCode which first defines the operand
28231  and the to number signifies the iCode which uses this operand last.
28232 \layout Paragraph*
28233
28234 Register Allocation
28235 \begin_inset LatexCommand \index{Register allocation}
28236
28237 \end_inset 
28238
28239
28240 \layout Standard
28241
28242 The register allocation determines the type and number of registers needed
28243  by each operand.
28244  In most MCUs only a few registers can be used for indirect addressing.
28245  In case of 8051 for example the registers R0 & R1 can be used to indirectly
28246  address the internal ram and DPTR to indirectly address the external ram.
28247  The compiler will try to allocate the appropriate register to pointer variables
28248  if it can.
28249  ICode example section shows the operands annotated with the registers assigned
28250  to them.
28251  The compiler will try to keep operands in registers as much as possible;
28252  there are several schemes the compiler uses to do achieve this.
28253  When the compiler runs out of registers the compiler will check to see
28254  if there are any live operands which is not used or defined in the current
28255  basic block being processed, if there are any found then it will push that
28256  operand and use the registers in this block, the operand will then be popped
28257  at the end of the basic block.
28258  
28259 \layout Standard
28260
28261 There are other MCU specific considerations in this phase.
28262  Some MCUs have an accumulator; very short-lived operands could be assigned
28263  to the accumulator instead of a general-purpose register.
28264 \layout Paragraph*
28265
28266 Code generation
28267 \layout Standard
28268
28269 Figure II gives a table of iCode operations supported by the compiler.
28270  The code generation involves translating these operations into corresponding
28271  assembly code for the processor.
28272  This sounds overly simple but that is the essence of code generation.
28273  Some of the iCode operations are generated on a MCU specific manner for
28274  example, the z80 port does not use registers to pass parameters so the
28275  SEND and RECV iCode operations will not be generated, and it also does
28276  not support JUMPTABLES.
28277  
28278 \newline 
28279
28280 \series bold 
28281 \shape italic 
28282 \color red
28283 <Where is Figure II?>
28284 \layout Comment
28285
28286 In the original article Figure II was announced to be downloadable on 
28287 \shape italic 
28288 Circuit Cellar
28289 \shape default 
28290 's web site.
28291  Unfortunately it never seemed to have shown up there, so: where is Figure
28292  II?
28293 \layout Paragraph*
28294
28295 ICode Example
28296 \begin_inset LatexCommand \index{iCode}
28297
28298 \end_inset 
28299
28300
28301 \layout Standard
28302
28303 This section shows some details of iCode.
28304  The example C code does not do anything useful; it is used as an example
28305  to illustrate the intermediate code generated by the compiler.
28306 \layout Verse
28307
28308
28309 \family typewriter 
28310 1.\SpecialChar ~
28311 xdata int * p;
28312 \newline 
28313 2.\SpecialChar ~
28314 int gint;
28315 \newline 
28316 3.\SpecialChar ~
28317 /* This function does nothing useful.
28318  It is used
28319 \newline 
28320 4.\SpecialChar ~
28321 \SpecialChar ~
28322 \SpecialChar ~
28323 \SpecialChar ~
28324 for the purpose of explaining iCode */
28325 \newline 
28326 5.\SpecialChar ~
28327 short function (data int *x)
28328 \newline 
28329 6.\SpecialChar ~
28330 {
28331 \newline 
28332 7.\SpecialChar ~
28333 \SpecialChar ~
28334 \SpecialChar ~
28335 short i=10; \SpecialChar ~
28336 \SpecialChar ~
28337 /* dead initialization eliminated */
28338 \newline 
28339 8.\SpecialChar ~
28340 \SpecialChar ~
28341 \SpecialChar ~
28342 short sum=10; /* dead initialization eliminated */
28343 \newline 
28344 9.\SpecialChar ~
28345 \SpecialChar ~
28346 \SpecialChar ~
28347 short mul;
28348 \newline 
28349 10.\SpecialChar ~
28350 \SpecialChar ~
28351 int j ;
28352 \newline 
28353 11.\SpecialChar ~
28354 \SpecialChar ~
28355 while (*x) *x++ = *p++; 
28356 \newline 
28357 12.\SpecialChar ~
28358 \SpecialChar ~
28359 \SpecialChar ~
28360 \SpecialChar ~
28361 sum = 0 ; 
28362 \newline 
28363 13.\SpecialChar ~
28364 \SpecialChar ~
28365 mul = 0;
28366 \newline 
28367 14.\SpecialChar ~
28368 \SpecialChar ~
28369 /* compiler detects i,j to be induction variables */
28370 \newline 
28371 15.\SpecialChar ~
28372 \SpecialChar ~
28373 for (i = 0, j = 10 ; i < 10 ; i++, j
28374 \family default 
28375 -
28376 \begin_inset ERT
28377 status Collapsed
28378
28379 \layout Standard
28380
28381 \backslash 
28382 /
28383 \end_inset 
28384
28385 -
28386 \family typewriter 
28387 ) {
28388 \newline 
28389 16.\SpecialChar ~
28390 \SpecialChar ~
28391 \SpecialChar ~
28392 \SpecialChar ~
28393 sum += i;
28394 \newline 
28395 17.\SpecialChar ~
28396 \SpecialChar ~
28397 \SpecialChar ~
28398 \SpecialChar ~
28399 mul += i * 3; \SpecialChar ~
28400 \SpecialChar ~
28401 /* this multiplication remains */
28402 \newline 
28403 18.\SpecialChar ~
28404 \SpecialChar ~
28405 \SpecialChar ~
28406 \SpecialChar ~
28407 gint += j * 3;\SpecialChar ~
28408 \SpecialChar ~
28409 /* this multiplication changed to addition */
28410 \newline 
28411 19.\SpecialChar ~
28412 \SpecialChar ~
28413 }
28414 \newline 
28415 20.\SpecialChar ~
28416 \SpecialChar ~
28417 return sum+mul;
28418 \newline 
28419 21.\SpecialChar ~
28420 }
28421 \layout Standard
28422
28423 In addition to the operands each iCode contains information about the filename
28424  and line it corresponds to in the source file.
28425  The first field in the listing should be interpreted as follows:
28426 \newline 
28427
28428 \shape italic 
28429 \size footnotesize 
28430 Filename(linenumber: iCode Execution sequence number : ICode hash table
28431  key : loop depth of the iCode).
28432 \shape default 
28433 \size default 
28434
28435 \newline 
28436 Then follows the human readable form of the ICode operation.
28437  Each operand of this triplet form can be of three basic types a) compiler
28438  generated temporary b) user defined variable c) a constant value.
28439  Note that local variables and parameters are replaced by compiler generated
28440  temporaries.
28441  Live ranges
28442 \begin_inset LatexCommand \index{Live range analysis}
28443
28444 \end_inset 
28445
28446  are computed only for temporaries (i.e.
28447  live ranges are not computed for global variables).
28448  Registers
28449 \begin_inset LatexCommand \index{Register allocation}
28450
28451 \end_inset 
28452
28453  are allocated for temporaries only.
28454  Operands are formatted in the following manner:
28455 \newline 
28456
28457 \shape italic 
28458 \size footnotesize 
28459 Operand Name [lr live-from : live-to ] { type information } [ registers
28460  allocated ].
28461 \shape default 
28462 \size default 
28463
28464 \newline 
28465 As mentioned earlier the live ranges are computed in terms of the execution
28466  sequence number of the iCodes, for example 
28467 \newline 
28468 the iTemp0 is live from (i.e.
28469  first defined in iCode with execution sequence number 3, and is last used
28470  in the iCode with sequence number 5).
28471  For induction variables such as iTemp21 the live range computation extends
28472  the lifetime from the start to the end of the loop.
28473 \newline 
28474 The register allocator used the live range information to allocate registers,
28475  the same registers may be used for different temporaries if their live
28476  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
28477  iTemp17 since their live ranges do not overlap.
28478  In addition the allocator also takes into consideration the type and usage
28479  of a temporary, for example itemp6 is a pointer to near space and is used
28480  as to fetch data from (i.e.
28481  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
28482  Some short lived temporaries are allocated to special registers which have
28483  meaning to the code generator e.g.
28484  iTemp13 is allocated to a pseudo register CC which tells the back end that
28485  the temporary is used only for a conditional jump the code generation makes
28486  use of this information to optimize a compare and jump ICode.
28487 \newline 
28488 There are several loop optimizations
28489 \begin_inset LatexCommand \index{Loop optimization}
28490
28491 \end_inset 
28492
28493  performed by the compiler.
28494  It can detect induction variables iTemp21(i) and iTemp23(j).
28495  Also note the compiler does selective strength reduction
28496 \begin_inset LatexCommand \index{Strength reduction}
28497
28498 \end_inset 
28499
28500 , i.e.
28501  the multiplication of an induction variable in line 18 (gint = j * 3) is
28502  changed to addition, a new temporary iTemp17 is allocated and assigned
28503  a initial value, a constant 3 is then added for each iteration of the loop.
28504  The compiler does not change the multiplication
28505 \begin_inset LatexCommand \index{Multiplication}
28506
28507 \end_inset 
28508
28509  in line 17 however since the processor does support an 8 * 8 bit multiplication.
28510 \newline 
28511 Note the dead code elimination
28512 \begin_inset LatexCommand \index{Dead-code elimination}
28513
28514 \end_inset 
28515
28516  optimization eliminated the dead assignments in line 7 & 8 to I and sum
28517  respectively.
28518 \newline 
28519
28520 \layout Standard
28521
28522
28523 \size footnotesize 
28524 Sample.c (5:1:0:0) _entry($9) :
28525 \layout Standard
28526
28527
28528 \size footnotesize 
28529 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
28530 \layout Standard
28531
28532
28533 \size footnotesize 
28534 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
28535 \layout Standard
28536
28537
28538 \size footnotesize 
28539 Sample.c(11:4:53:0) preHeaderLbl0($11) :
28540 \layout Standard
28541
28542
28543 \size footnotesize 
28544 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
28545  * int}[r2]
28546 \layout Standard
28547
28548
28549 \size footnotesize 
28550 Sample.c(11:6:5:1) _whilecontinue_0($1) :
28551 \layout Standard
28552
28553
28554 \size footnotesize 
28555 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
28556  int}[r0]]
28557 \layout Standard
28558
28559
28560 \size footnotesize 
28561 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
28562 \layout Standard
28563
28564
28565 \size footnotesize 
28566 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
28567  * int}
28568 \layout Standard
28569
28570
28571 \size footnotesize 
28572 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
28573  {short}
28574 \layout Standard
28575
28576
28577 \size footnotesize 
28578 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
28579  * int}[DPTR]]
28580 \layout Standard
28581
28582
28583 \size footnotesize 
28584 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
28585 }[r2 r3]
28586 \layout Standard
28587
28588
28589 \size footnotesize 
28590 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
28591  * int}[r0] + 0x2 {short}
28592 \layout Standard
28593
28594
28595 \size footnotesize 
28596 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
28597 \layout Standard
28598
28599
28600 \size footnotesize 
28601 Sample.c(11:17:21:0)_whilebreak_0($3) :
28602 \layout Standard
28603
28604
28605 \size footnotesize 
28606 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
28607 \layout Standard
28608
28609
28610 \size footnotesize 
28611 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
28612 \layout Standard
28613
28614
28615 \size footnotesize 
28616 Sample.c(15:20:54:0)preHeaderLbl1($13) :
28617 \layout Standard
28618
28619
28620 \size footnotesize 
28621 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
28622 \layout Standard
28623
28624
28625 \size footnotesize 
28626 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
28627 \layout Standard
28628
28629
28630 \size footnotesize 
28631 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
28632 \layout Standard
28633
28634
28635 \size footnotesize 
28636 Sample.c(15:24:26:1)_forcond_0($4) :
28637 \layout Standard
28638
28639
28640 \size footnotesize 
28641 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
28642  < 0xa {short}
28643 \layout Standard
28644
28645
28646 \size footnotesize 
28647 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
28648 \layout Standard
28649
28650
28651 \size footnotesize 
28652 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
28653  + ITemp21 [lr21:38]{short}[r4]
28654 \layout Standard
28655
28656
28657 \size footnotesize 
28658 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
28659  * 0x3 {short}
28660 \layout Standard
28661
28662
28663 \size footnotesize 
28664 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
28665  + iTemp15 [lr29:30]{short}[r1]
28666 \layout Standard
28667
28668
28669 \size footnotesize 
28670 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
28671  r0]- 0x3 {short}
28672 \layout Standard
28673
28674
28675 \size footnotesize 
28676 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
28677 int}[r7 r0]
28678 \layout Standard
28679
28680
28681 \size footnotesize 
28682 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
28683  + 0x1 {short}
28684 \layout Standard
28685
28686
28687 \size footnotesize 
28688 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
28689  r6]- 0x1 {short}
28690 \layout Standard
28691
28692
28693 \size footnotesize 
28694 Sample.c(19:38:47:1) goto _forcond_0($4)
28695 \layout Standard
28696
28697
28698 \size footnotesize 
28699 Sample.c(19:39:48:0)_forbreak_0($7) :
28700 \layout Standard
28701
28702
28703 \size footnotesize 
28704 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
28705  + ITemp11 [lr19:40]{short}[r3]
28706 \layout Standard
28707
28708
28709 \size footnotesize 
28710 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
28711 \layout Standard
28712
28713
28714 \size footnotesize 
28715 Sample.c(20:42:51:0)_return($8) :
28716 \layout Standard
28717
28718
28719 \size footnotesize 
28720 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
28721 \size default 
28722
28723 \newline 
28724
28725 \newline 
28726 Finally the code generated for this function:
28727 \newline 
28728
28729 \layout Standard
28730
28731
28732 \size footnotesize 
28733 .area DSEG (DATA)
28734 \layout Standard
28735
28736
28737 \size footnotesize 
28738 _p::
28739 \layout Standard
28740
28741
28742 \size footnotesize 
28743 \SpecialChar ~
28744 \SpecialChar ~
28745 .ds 2
28746 \layout Standard
28747
28748
28749 \size footnotesize 
28750 _gint::
28751 \layout Standard
28752
28753
28754 \size footnotesize 
28755 \SpecialChar ~
28756 \SpecialChar ~
28757 .ds 2
28758 \layout Standard
28759
28760
28761 \size footnotesize 
28762 ; sample.c 5
28763 \layout Standard
28764
28765
28766 \size footnotesize 
28767 ; ----------------------------------------------
28768 \layout Standard
28769
28770
28771 \size footnotesize 
28772 ; function function
28773 \layout Standard
28774
28775
28776 \size footnotesize 
28777 ; ----------------------------------------------
28778 \layout Standard
28779
28780
28781 \size footnotesize 
28782 _function:
28783 \layout Standard
28784
28785
28786 \size footnotesize 
28787 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
28788 \layout Standard
28789
28790
28791 \size footnotesize 
28792 \SpecialChar ~
28793 \SpecialChar ~
28794 mov r2,dpl
28795 \layout Standard
28796
28797
28798 \size footnotesize 
28799 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
28800 \layout Standard
28801
28802
28803 \size footnotesize 
28804 \SpecialChar ~
28805 \SpecialChar ~
28806 mov ar0,r2
28807 \layout Standard
28808
28809
28810 \size footnotesize 
28811 ;_whilecontinue_0($1) :
28812 \layout Standard
28813
28814
28815 \size footnotesize 
28816 00101$:
28817 \layout Standard
28818
28819
28820 \size footnotesize 
28821 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
28822 \layout Standard
28823
28824
28825 \size footnotesize 
28826 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
28827 \layout Standard
28828
28829
28830 \size footnotesize 
28831 \SpecialChar ~
28832 \SpecialChar ~
28833 mov ar2,@r0
28834 \layout Standard
28835
28836
28837 \size footnotesize 
28838 \SpecialChar ~
28839 \SpecialChar ~
28840 inc r0
28841 \layout Standard
28842
28843
28844 \size footnotesize 
28845 \SpecialChar ~
28846 \SpecialChar ~
28847 mov ar3,@r0
28848 \layout Standard
28849
28850
28851 \size footnotesize 
28852 \SpecialChar ~
28853 \SpecialChar ~
28854 dec r0
28855 \layout Standard
28856
28857
28858 \size footnotesize 
28859 \SpecialChar ~
28860 \SpecialChar ~
28861 mov a,r2
28862 \layout Standard
28863
28864
28865 \size footnotesize 
28866 \SpecialChar ~
28867 \SpecialChar ~
28868 orl a,r3
28869 \layout Standard
28870
28871
28872 \size footnotesize 
28873 \SpecialChar ~
28874 \SpecialChar ~
28875 jz 00103$
28876 \layout Standard
28877
28878
28879 \size footnotesize 
28880 00114$:
28881 \layout Standard
28882
28883
28884 \size footnotesize 
28885 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
28886 \layout Standard
28887
28888
28889 \size footnotesize 
28890 \SpecialChar ~
28891 \SpecialChar ~
28892 mov dpl,_p
28893 \layout Standard
28894
28895
28896 \size footnotesize 
28897 \SpecialChar ~
28898 \SpecialChar ~
28899 mov dph,(_p + 1)
28900 \layout Standard
28901
28902
28903 \size footnotesize 
28904 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
28905 \layout Standard
28906
28907
28908 \size footnotesize 
28909 \SpecialChar ~
28910 \SpecialChar ~
28911 mov a,#0x02
28912 \layout Standard
28913
28914
28915 \size footnotesize 
28916 \SpecialChar ~
28917 \SpecialChar ~
28918 add a,_p
28919 \layout Standard
28920
28921
28922 \size footnotesize 
28923 \SpecialChar ~
28924 \SpecialChar ~
28925 mov _p,a
28926 \layout Standard
28927
28928
28929 \size footnotesize 
28930 \SpecialChar ~
28931 \SpecialChar ~
28932 clr a
28933 \layout Standard
28934
28935
28936 \size footnotesize 
28937 \SpecialChar ~
28938 \SpecialChar ~
28939 addc a,(_p + 1)
28940 \layout Standard
28941
28942
28943 \size footnotesize 
28944 \SpecialChar ~
28945 \SpecialChar ~
28946 mov (_p + 1),a
28947 \layout Standard
28948
28949
28950 \size footnotesize 
28951 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
28952 \layout Standard
28953
28954
28955 \size footnotesize 
28956 \SpecialChar ~
28957 \SpecialChar ~
28958 movx a,@dptr
28959 \layout Standard
28960
28961
28962 \size footnotesize 
28963 \SpecialChar ~
28964 \SpecialChar ~
28965 mov r2,a
28966 \layout Standard
28967
28968
28969 \size footnotesize 
28970 \SpecialChar ~
28971 \SpecialChar ~
28972 inc dptr
28973 \layout Standard
28974
28975
28976 \size footnotesize 
28977 \SpecialChar ~
28978 \SpecialChar ~
28979 movx a,@dptr
28980 \layout Standard
28981
28982
28983 \size footnotesize 
28984 \SpecialChar ~
28985 \SpecialChar ~
28986 mov r3,a
28987 \layout Standard
28988
28989
28990 \size footnotesize 
28991 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
28992 \layout Standard
28993
28994
28995 \size footnotesize 
28996 \SpecialChar ~
28997 \SpecialChar ~
28998 mov @r0,ar2
28999 \layout Standard
29000
29001
29002 \size footnotesize 
29003 \SpecialChar ~
29004 \SpecialChar ~
29005 inc r0
29006 \layout Standard
29007
29008
29009 \size footnotesize 
29010 \SpecialChar ~
29011 \SpecialChar ~
29012 mov @r0,ar3
29013 \layout Standard
29014
29015
29016 \size footnotesize 
29017 ; iTemp6 [lr5:16]{_near * int}[r0] = 
29018 \layout Standard
29019
29020
29021 \size footnotesize 
29022 ; iTemp6 [lr5:16]{_near * int}[r0] + 
29023 \layout Standard
29024
29025
29026 \size footnotesize 
29027 ; 0x2 {short}
29028 \layout Standard
29029
29030
29031 \size footnotesize 
29032 \SpecialChar ~
29033 \SpecialChar ~
29034 inc r0
29035 \layout Standard
29036
29037
29038 \size footnotesize 
29039 ; goto _whilecontinue_0($1)
29040 \layout Standard
29041
29042
29043 \size footnotesize 
29044 \SpecialChar ~
29045 \SpecialChar ~
29046 sjmp 00101$
29047 \layout Standard
29048
29049
29050 \size footnotesize 
29051 ; _whilebreak_0($3) :
29052 \layout Standard
29053
29054
29055 \size footnotesize 
29056 00103$:
29057 \layout Standard
29058
29059
29060 \size footnotesize 
29061 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
29062 \layout Standard
29063
29064
29065 \size footnotesize 
29066 \SpecialChar ~
29067 \SpecialChar ~
29068 mov r2,#0x00
29069 \layout Standard
29070
29071
29072 \size footnotesize 
29073 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
29074 \layout Standard
29075
29076
29077 \size footnotesize 
29078 \SpecialChar ~
29079 \SpecialChar ~
29080 mov r3,#0x00
29081 \layout Standard
29082
29083
29084 \size footnotesize 
29085 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
29086 \layout Standard
29087
29088
29089 \size footnotesize 
29090 \SpecialChar ~
29091 \SpecialChar ~
29092 mov r4,#0x00
29093 \layout Standard
29094
29095
29096 \size footnotesize 
29097 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
29098 \layout Standard
29099
29100
29101 \size footnotesize 
29102 \SpecialChar ~
29103 \SpecialChar ~
29104 mov r5,#0x0A
29105 \layout Standard
29106
29107
29108 \size footnotesize 
29109 \SpecialChar ~
29110 \SpecialChar ~
29111 mov r6,#0x00
29112 \layout Standard
29113
29114
29115 \size footnotesize 
29116 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
29117 \layout Standard
29118
29119
29120 \size footnotesize 
29121 \SpecialChar ~
29122 \SpecialChar ~
29123 mov r7,#0x1E
29124 \layout Standard
29125
29126
29127 \size footnotesize 
29128 \SpecialChar ~
29129 \SpecialChar ~
29130 mov r0,#0x00
29131 \layout Standard
29132
29133
29134 \size footnotesize 
29135 ; _forcond_0($4) :
29136 \layout Standard
29137
29138
29139 \size footnotesize 
29140 00104$:
29141 \layout Standard
29142
29143
29144 \size footnotesize 
29145 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
29146 \layout Standard
29147
29148
29149 \size footnotesize 
29150 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
29151 \layout Standard
29152
29153
29154 \size footnotesize 
29155 \SpecialChar ~
29156 \SpecialChar ~
29157 clr c
29158 \layout Standard
29159
29160
29161 \size footnotesize 
29162 \SpecialChar ~
29163 \SpecialChar ~
29164 mov a,r4
29165 \layout Standard
29166
29167
29168 \size footnotesize 
29169 \SpecialChar ~
29170 \SpecialChar ~
29171 xrl a,#0x80
29172 \layout Standard
29173
29174
29175 \size footnotesize 
29176 \SpecialChar ~
29177 \SpecialChar ~
29178 subb a,#0x8a
29179 \layout Standard
29180
29181
29182 \size footnotesize 
29183 \SpecialChar ~
29184 \SpecialChar ~
29185 jnc 00107$
29186 \layout Standard
29187
29188
29189 \size footnotesize 
29190 00115$:
29191 \layout Standard
29192
29193
29194 \size footnotesize 
29195 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
29196 \layout Standard
29197
29198
29199 \size footnotesize 
29200 ; iTemp21 [lr21:38]{short}[r4]
29201 \layout Standard
29202
29203
29204 \size footnotesize 
29205 \SpecialChar ~
29206 \SpecialChar ~
29207 mov a,r4
29208 \layout Standard
29209
29210
29211 \size footnotesize 
29212 \SpecialChar ~
29213 \SpecialChar ~
29214 add a,r2
29215 \layout Standard
29216
29217
29218 \size footnotesize 
29219 \SpecialChar ~
29220 \SpecialChar ~
29221 mov r2,a
29222 \layout Standard
29223
29224
29225 \size footnotesize 
29226 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
29227 \layout Standard
29228
29229
29230 \size footnotesize 
29231 \SpecialChar ~
29232 \SpecialChar ~
29233 mov b,#0x03
29234 \layout Standard
29235
29236
29237 \size footnotesize 
29238 \SpecialChar ~
29239 \SpecialChar ~
29240 mov a,r4
29241 \layout Standard
29242
29243
29244 \size footnotesize 
29245 \SpecialChar ~
29246 \SpecialChar ~
29247 mul ab
29248 \layout Standard
29249
29250
29251 \size footnotesize 
29252 \SpecialChar ~
29253 \SpecialChar ~
29254 mov r1,a
29255 \layout Standard
29256
29257
29258 \size footnotesize 
29259 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
29260 \layout Standard
29261
29262
29263 \size footnotesize 
29264 ; iTemp15 [lr29:30]{short}[r1]
29265 \layout Standard
29266
29267
29268 \size footnotesize 
29269 \SpecialChar ~
29270 \SpecialChar ~
29271 add a,r3
29272 \layout Standard
29273
29274
29275 \size footnotesize 
29276 \SpecialChar ~
29277 \SpecialChar ~
29278 mov r3,a
29279 \layout Standard
29280
29281
29282 \size footnotesize 
29283 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
29284 \layout Standard
29285
29286
29287 \size footnotesize 
29288 \SpecialChar ~
29289 \SpecialChar ~
29290 mov a,r7
29291 \layout Standard
29292
29293
29294 \size footnotesize 
29295 \SpecialChar ~
29296 \SpecialChar ~
29297 add a,#0xfd
29298 \layout Standard
29299
29300
29301 \size footnotesize 
29302 \SpecialChar ~
29303 \SpecialChar ~
29304 mov r7,a
29305 \layout Standard
29306
29307
29308 \size footnotesize 
29309 \SpecialChar ~
29310 \SpecialChar ~
29311 mov a,r0
29312 \layout Standard
29313
29314
29315 \size footnotesize 
29316 \SpecialChar ~
29317 \SpecialChar ~
29318 addc a,#0xff
29319 \layout Standard
29320
29321
29322 \size footnotesize 
29323 \SpecialChar ~
29324 \SpecialChar ~
29325 mov r0,a
29326 \layout Standard
29327
29328
29329 \size footnotesize 
29330 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
29331 \layout Standard
29332
29333
29334 \size footnotesize 
29335 \SpecialChar ~
29336 \SpecialChar ~
29337 mov a,r7
29338 \layout Standard
29339
29340
29341 \size footnotesize 
29342 \SpecialChar ~
29343 \SpecialChar ~
29344 add a,_gint
29345 \layout Standard
29346
29347
29348 \size footnotesize 
29349 \SpecialChar ~
29350 \SpecialChar ~
29351 mov _gint,a
29352 \layout Standard
29353
29354
29355 \size footnotesize 
29356 \SpecialChar ~
29357 \SpecialChar ~
29358 mov a,r0
29359 \layout Standard
29360
29361
29362 \size footnotesize 
29363 \SpecialChar ~
29364 \SpecialChar ~
29365 addc a,(_gint + 1)
29366 \layout Standard
29367
29368
29369 \size footnotesize 
29370 \SpecialChar ~
29371 \SpecialChar ~
29372 mov (_gint + 1),a
29373 \layout Standard
29374
29375
29376 \size footnotesize 
29377 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
29378 \layout Standard
29379
29380
29381 \size footnotesize 
29382 \SpecialChar ~
29383 \SpecialChar ~
29384 inc r4
29385 \layout Standard
29386
29387
29388 \size footnotesize 
29389 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
29390 \layout Standard
29391
29392
29393 \size footnotesize 
29394 \SpecialChar ~
29395 \SpecialChar ~
29396 dec r5
29397 \layout Standard
29398
29399
29400 \size footnotesize 
29401 \SpecialChar ~
29402 \SpecialChar ~
29403 cjne r5,#0xff,00104$
29404 \layout Standard
29405
29406
29407 \size footnotesize 
29408 \SpecialChar ~
29409 \SpecialChar ~
29410 dec r6
29411 \layout Standard
29412
29413
29414 \size footnotesize 
29415 ; goto _forcond_0($4)
29416 \layout Standard
29417
29418
29419 \size footnotesize 
29420 \SpecialChar ~
29421 \SpecialChar ~
29422 sjmp 00104$
29423 \layout Standard
29424
29425
29426 \size footnotesize 
29427 ; _forbreak_0($7) :
29428 \layout Standard
29429
29430
29431 \size footnotesize 
29432 00107$:
29433 \layout Standard
29434
29435
29436 \size footnotesize 
29437 ; ret iTemp24 [lr40:41]{short}
29438 \layout Standard
29439
29440
29441 \size footnotesize 
29442 \SpecialChar ~
29443 \SpecialChar ~
29444 mov a,r3
29445 \layout Standard
29446
29447
29448 \size footnotesize 
29449 \SpecialChar ~
29450 \SpecialChar ~
29451 add a,r2
29452 \layout Standard
29453
29454
29455 \size footnotesize 
29456 \SpecialChar ~
29457 \SpecialChar ~
29458 mov dpl,a
29459 \layout Standard
29460
29461
29462 \size footnotesize 
29463 ; _return($8) :
29464 \layout Standard
29465
29466
29467 \size footnotesize 
29468 00108$:
29469 \layout Standard
29470
29471
29472 \size footnotesize 
29473 \SpecialChar ~
29474 \SpecialChar ~
29475 ret
29476 \newline 
29477
29478 \layout Section
29479
29480 A few words about basic block successors, predecessors and dominators
29481 \layout Standard
29482
29483 Successors are basic blocks
29484 \begin_inset LatexCommand \index{Basic blocks}
29485
29486 \end_inset 
29487
29488  that might execute after this basic block.
29489 \newline 
29490 Predecessors are basic blocks that might execute before reaching this basic
29491  block.
29492 \newline 
29493 Dominators are basic blocks that WILL execute before reaching this basic
29494  block.
29495 \newline 
29496
29497 \layout Standard
29498
29499 [basic block 1]
29500 \layout Standard
29501
29502 if (something)
29503 \layout Standard
29504
29505 \SpecialChar ~
29506 \SpecialChar ~
29507 \SpecialChar ~
29508 \SpecialChar ~
29509 [basic block 2]
29510 \layout Standard
29511
29512 else
29513 \layout Standard
29514
29515 \SpecialChar ~
29516 \SpecialChar ~
29517 \SpecialChar ~
29518 \SpecialChar ~
29519 [basic block 3]
29520 \layout Standard
29521
29522 [basic block 4]
29523 \newline 
29524
29525 \layout Standard
29526
29527 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
29528 \layout Standard
29529
29530 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
29531 \layout Standard
29532
29533 c) domVect of [BB4] = BB1 ...
29534  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
29535  was executed.
29536 \layout Chapter
29537
29538 Acknowledgments
29539 \layout Standard
29540
29541
29542 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
29543
29544 \end_inset 
29545
29546
29547 \newline 
29548
29549 \newline 
29550
29551 \emph on 
29552 Thanks to all the other volunteer developers who have helped with coding,
29553  testing, web-page creation, distribution sets, etc.
29554  You know who you are :-)
29555 \emph default 
29556
29557 \newline 
29558
29559 \layout Standard
29560
29561 This document was initially written by Sandeep Dutta
29562 \layout Standard
29563
29564 All product names mentioned herein may be trademarks
29565 \begin_inset LatexCommand \index{Trademarks}
29566
29567 \end_inset 
29568
29569  of their respective companies.
29570  
29571 \layout Section*
29572
29573 Alphabetical index
29574 \layout Standard
29575
29576 To avoid confusion, the installation and building options for SDCC itself
29577  (chapter 2) are not part of the index.
29578 \layout Standard
29579
29580
29581 \begin_inset LatexCommand \printindex{}
29582
29583 \end_inset 
29584
29585
29586 \the_end