doc/sdccman.lyx: Some re-formating plus example on using #pragma preproc_asm +/-
[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.6.1
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by Subversion
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
132  
133 \series bold 
134 Sandeep Dutta
135 \series default 
136  designed for 8 bit Microprocessors.
137  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
138  8051, 8052
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
140
141 \end_inset 
142
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144  Zilog Z80 based MCUs.
145  It can be retargeted for other microprocessors, support for Microchip PIC,
146  Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargetable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Standard
206
207
208 \begin_inset  Tabular
209 <lyxtabular version="3" rows="8" columns="5">
210 <features>
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
216 <row topline="true" bottomline="true">
217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
218 \begin_inset Text
219
220 \layout Standard
221
222 type
223 \end_inset 
224 </cell>
225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
226 \begin_inset Text
227
228 \layout Standard
229
230 width
231 \end_inset 
232 </cell>
233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
234 \begin_inset Text
235
236 \layout Standard
237
238 default
239 \end_inset 
240 </cell>
241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
242 \begin_inset Text
243
244 \layout Standard
245
246 signed range
247 \end_inset 
248 </cell>
249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
250 \begin_inset Text
251
252 \layout Standard
253
254 unsigned range
255 \end_inset 
256 </cell>
257 </row>
258 <row topline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \layout Standard
263
264 bool
265 \end_inset 
266 </cell>
267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
268 \begin_inset Text
269
270 \layout Standard
271
272 1 bit
273 \end_inset 
274 </cell>
275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
276 \begin_inset Text
277
278 \layout Standard
279
280 unsigned
281 \end_inset 
282 </cell>
283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_inset Text
285
286 \layout Standard
287
288 -
289 \end_inset 
290 </cell>
291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
292 \begin_inset Text
293
294 \layout Standard
295
296 0, 1
297 \end_inset 
298 </cell>
299 </row>
300 <row topline="true">
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_inset Text
303
304 \layout Standard
305
306 char
307 \end_inset 
308 </cell>
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
310 \begin_inset Text
311
312 \layout Standard
313
314 8 bits, 1 byte
315 \end_inset 
316 </cell>
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_inset Text
319
320 \layout Standard
321
322 signed
323 \end_inset 
324 </cell>
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
326 \begin_inset Text
327
328 \layout Standard
329
330 -128, +127
331 \end_inset 
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
334 \begin_inset Text
335
336 \layout Standard
337
338 0, +255
339 \end_inset 
340 </cell>
341 </row>
342 <row topline="true">
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
344 \begin_inset Text
345
346 \layout Standard
347
348 short
349 \end_inset 
350 </cell>
351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
352 \begin_inset Text
353
354 \layout Standard
355
356 16 bits, 2 bytes
357 \end_inset 
358 </cell>
359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
360 \begin_inset Text
361
362 \layout Standard
363
364 signed
365 \end_inset 
366 </cell>
367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
368 \begin_inset Text
369
370 \layout Standard
371
372 -32.768, +32.767
373 \end_inset 
374 </cell>
375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
376 \begin_inset Text
377
378 \layout Standard
379
380 0, +65.535
381 \end_inset 
382 </cell>
383 </row>
384 <row topline="true">
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
386 \begin_inset Text
387
388 \layout Standard
389
390 int
391 \end_inset 
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
394 \begin_inset Text
395
396 \layout Standard
397
398 16 bits, 2 bytes
399 \end_inset 
400 </cell>
401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
402 \begin_inset Text
403
404 \layout Standard
405
406 signed
407 \end_inset 
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \layout Standard
413
414 -32.768, +32.767
415 \end_inset 
416 </cell>
417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
418 \begin_inset Text
419
420 \layout Standard
421
422 0, +65.535
423 \end_inset 
424 </cell>
425 </row>
426 <row topline="true" bottomline="true">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \layout Standard
431
432 long
433 \end_inset 
434 </cell>
435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
436 \begin_inset Text
437
438 \layout Standard
439
440 32 bits, 4 bytes
441 \end_inset 
442 </cell>
443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
444 \begin_inset Text
445
446 \layout Standard
447
448 signed
449 \end_inset 
450 </cell>
451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
452 \begin_inset Text
453
454 \layout Standard
455
456 -2.147.483.648, +2.147.483.647
457 \end_inset 
458 </cell>
459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
460 \begin_inset Text
461
462 \layout Standard
463
464 0, +4.294.967.296
465 \end_inset 
466 </cell>
467 </row>
468 <row topline="true" bottomline="true">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \layout Standard
473
474 float
475 \end_inset 
476 </cell>
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
478 \begin_inset Text
479
480 \layout Standard
481
482 4 bytes IEEE 754
483 \end_inset 
484 </cell>
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
486 \begin_inset Text
487
488 \layout Standard
489
490 signed
491 \end_inset 
492 </cell>
493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
494 \begin_inset Text
495
496 \layout Standard
497
498 \end_inset 
499 </cell>
500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
501 \begin_inset Text
502
503 \layout Standard
504
505 \end_inset 
506 </cell>
507 </row>
508 <row topline="true" bottomline="true">
509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
510 \begin_inset Text
511
512 \layout Standard
513
514 pointer
515 \end_inset 
516 </cell>
517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
518 \begin_inset Text
519
520 \layout Standard
521
522 1, 2, 3 or 4 bytes
523 \end_inset 
524 </cell>
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
526 \begin_inset Text
527
528 \layout Standard
529
530 generic
531 \end_inset 
532 </cell>
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
534 \begin_inset Text
535
536 \layout Standard
537
538 \end_inset 
539 </cell>
540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
541 \begin_inset Text
542
543 \layout Standard
544
545 \end_inset 
546 </cell>
547 </row>
548 </lyxtabular>
549
550 \end_inset 
551
552
553 \newline 
554 The compiler also allows 
555 \emph on 
556 inline assembler code
557 \emph default 
558  to be embedded anywhere in a function.
559  In addition, routines developed in assembly can also be called.
560 \newline 
561
562 \newline 
563 SDCC also provides an option (-
564 \begin_inset ERT
565 status Collapsed
566
567 \layout Standard
568
569 \backslash 
570 /
571 \end_inset 
572
573 -cyclomatic) to report the relative complexity of a function.
574  These functions can then be further optimized, or hand coded in assembly
575  if needed.
576  
577 \newline 
578
579 \newline 
580 SDCC also comes with a companion source level debugger SDCDB, the debugger
581  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
582  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 detailed 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 Subsubsection
15469
15470 <malloc.h>
15471 \begin_inset LatexCommand \index{malloc.h}
15472
15473 \end_inset 
15474
15475
15476 \layout Standard
15477
15478 Before using dynamic
15479 \begin_inset LatexCommand \index{dynamic}
15480
15481 \end_inset 
15482
15483  memory allocation with SDCC, you have to provide heap
15484 \begin_inset LatexCommand \index{heap}
15485
15486 \end_inset 
15487
15488  space for malloc to allocate memory from
15489 \family typewriter 
15490 .
15491  
15492 \family default 
15493 You can acomplish this by including the following code into your source:
15494 \layout Verse
15495
15496
15497 \family typewriter 
15498 #include <malloc.h>
15499 \begin_inset LatexCommand \index{malloc.h}
15500
15501 \end_inset 
15502
15503  /* calloc
15504 \begin_inset LatexCommand \index{calloc}
15505
15506 \end_inset 
15507
15508 , malloc
15509 \begin_inset LatexCommand \index{malloc}
15510
15511 \end_inset 
15512
15513 , realloc
15514 \begin_inset LatexCommand \index{realloc}
15515
15516 \end_inset 
15517
15518 , and free
15519 \begin_inset LatexCommand \index{free}
15520
15521 \end_inset 
15522
15523  */ 
15524 \newline 
15525
15526 \newline 
15527 #define HEAPSIZE 0x1000 /* Adjust depending on available memory */ 
15528 \newline 
15529 unsigned char xdata myheap[HEAPSIZE]; /* The actual heap for dynamic memory
15530  */ 
15531 \newline 
15532
15533 \newline 
15534 void main (void) 
15535 \newline 
15536
15537 \newline 
15538 \SpecialChar ~
15539 \SpecialChar ~
15540 \SpecialChar ~
15541 /* Your variable declarations come here*/
15542 \newline 
15543 \SpecialChar ~
15544 \SpecialChar ~
15545 \SpecialChar ~
15546 ...
15547 \newline 
15548 \SpecialChar ~
15549 \SpecialChar ~
15550 \SpecialChar ~
15551 init_dynamic_memory((MEMHEADER xdata *)myheap, HEAPSIZE);
15552 \newline 
15553 \SpecialChar ~
15554 \SpecialChar ~
15555 \SpecialChar ~
15556 ...
15557  /* Rest of your code*/
15558 \newline 
15559
15560 \newline 
15561
15562 \layout Subsection
15563
15564 Math functions (sinf, powf, sqrtf etc.)
15565 \layout Subsubsection
15566
15567 <math.h>
15568 \layout Standard
15569
15570 See definitions in file <math.h>.
15571 \layout Subsection
15572
15573 Other libraries
15574 \layout Standard
15575
15576 Libraries
15577 \begin_inset LatexCommand \index{Libraries}
15578
15579 \end_inset 
15580
15581  included in SDCC should have a license at least as liberal as the GNU Lesser
15582  General Public License
15583 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15584
15585 \end_inset 
15586
15587  
15588 \emph on 
15589 LGPL
15590 \emph default 
15591 .
15592 \layout Comment
15593
15594 license statements for the libraries are missing.
15595  sdcc/device/lib/ser_ir.c
15596 \layout Comment
15597
15598 or _decdptr f.e.
15599  come with a GPL (as opposed to LGPL) License - this will not be liberal
15600  enough for many embedded programmers.
15601 \layout Standard
15602
15603 If you have ported some library or want to share experience about some code
15604  which f.e.
15605  falls into any of these categories Busses (I
15606 \begin_inset Formula $^{\textrm{2}}$
15607 \end_inset 
15608
15609 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
15610  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
15611  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
15612 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
15613
15614 \end_inset 
15615
15616 \SpecialChar ~
15617 would certainly like to hear about it.
15618  Programmers coding for embedded systems are not especially famous for being
15619  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
15620 e these references are very valuable.
15621  Let's help to create a climate where information is shared.
15622 \layout Section
15623
15624 Memory Models
15625 \layout Subsection
15626
15627 MCS51 Memory Models
15628 \begin_inset LatexCommand \index{Memory model}
15629
15630 \end_inset 
15631
15632
15633 \begin_inset LatexCommand \index{MCS51 memory model}
15634
15635 \end_inset 
15636
15637
15638 \layout Subsubsection
15639
15640 Small, Medium and Large
15641 \layout Standard
15642
15643 SDCC allows three memory models for MCS51 code, 
15644 \shape slanted 
15645 small, medium
15646 \shape default 
15647  and 
15648 \shape slanted 
15649 large
15650 \shape default 
15651 .
15652  Modules compiled with different memory models should 
15653 \emph on 
15654 never
15655 \emph default 
15656  be combined together or the results would be unpredictable.
15657  The library routines supplied with the compiler are compiled as small,
15658  medium and large.
15659  The compiled library modules are contained in separate directories as small,
15660  medium and large so that you can link to the appropriate set.
15661 \layout Standard
15662
15663 When the medium or large model is used all variables declared without a
15664  storage class will be allocated into the external ram, this includes all
15665  parameters and local variables (for non-reentrant
15666 \begin_inset LatexCommand \index{reentrant}
15667
15668 \end_inset 
15669
15670  functions).
15671  When the small model is used variables without storage class are allocated
15672  in the internal ram.
15673 \layout Standard
15674
15675 Judicious usage of the processor specific storage classes
15676 \begin_inset LatexCommand \index{Storage class}
15677
15678 \end_inset 
15679
15680  and the 'reentrant' function type will yield much more efficient code,
15681  than using the large model.
15682  Several optimizations are disabled when the program is compiled using the
15683  large model, it is therefore recommended that the small model be used unless
15684  absolutely required.
15685 \layout Subsubsection
15686
15687 External Stack
15688 \begin_inset LatexCommand \label{sub:External-Stack}
15689
15690 \end_inset 
15691
15692
15693 \begin_inset LatexCommand \index{stack}
15694
15695 \end_inset 
15696
15697
15698 \begin_inset LatexCommand \index{External stack (mcs51)}
15699
15700 \end_inset 
15701
15702
15703 \layout Standard
15704
15705 The external stack (-
15706 \begin_inset ERT
15707 status Collapsed
15708
15709 \layout Standard
15710
15711 \backslash 
15712 /
15713 \end_inset 
15714
15715 -xstack option
15716 \begin_inset LatexCommand \index{-\/-xstack}
15717
15718 \end_inset 
15719
15720 ) is located in pdata
15721 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
15722
15723 \end_inset 
15724
15725  memory (usually at the start of the external ram segment) and uses all
15726  unused space in pdata (max.
15727  256 bytes).
15728  When -
15729 \begin_inset ERT
15730 status Collapsed
15731
15732 \layout Standard
15733
15734 \backslash 
15735 /
15736 \end_inset 
15737
15738 -xstack option is used to compile the program, the parameters and local
15739  variables
15740 \begin_inset LatexCommand \index{local variables}
15741
15742 \end_inset 
15743
15744  of all reentrant functions are allocated in this area.
15745  This option is provided for programs with large stack space requirements.
15746  When used with the -
15747 \begin_inset ERT
15748 status Collapsed
15749
15750 \layout Standard
15751
15752 \backslash 
15753 /
15754 \end_inset 
15755
15756 -stack-auto
15757 \begin_inset LatexCommand \index{-\/-stack-auto}
15758
15759 \end_inset 
15760
15761  option, all parameters and local variables are allocated on the external
15762  stack (note: support libraries will need to be recompiled with the same
15763  options.
15764  There is a predefined target in the library makefile).
15765 \layout Standard
15766
15767 The compiler outputs the higher order address byte of the external ram segment
15768  into port P2
15769 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
15770
15771 \end_inset 
15772
15773  (see also section 
15774 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15775
15776 \end_inset 
15777
15778 ), therefore when using the External Stack option, this port 
15779 \emph on 
15780 may not
15781 \emph default 
15782  be used by the application program.
15783 \layout Subsection
15784
15785 DS390 Memory Model
15786 \begin_inset LatexCommand \index{Memory model}
15787
15788 \end_inset 
15789
15790
15791 \begin_inset LatexCommand \index{DS390 memory model}
15792
15793 \end_inset 
15794
15795
15796 \layout Standard
15797
15798 The only model supported is Flat 24
15799 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
15800
15801 \end_inset 
15802
15803 .
15804  This generates code for the 24 bit contiguous addressing mode of the Dallas
15805  DS80C390 part.
15806  In this mode, up to four meg of external RAM or code space can be directly
15807  addressed.
15808  See the data sheets at www.dalsemi.com for further information on this part.
15809 \newline 
15810
15811 \newline 
15812 Note that the compiler does not generate any code to place the processor
15813  into 24 bitmode (although 
15814 \emph on 
15815 tinibios
15816 \emph default 
15817  in the ds390 libraries will do that for you).
15818  If you don't use 
15819 \emph on 
15820 tinibios
15821 \emph default 
15822
15823 \begin_inset LatexCommand \index{Tinibios (DS390)}
15824
15825 \end_inset 
15826
15827 , the boot loader or similar code must ensure that the processor is in 24
15828  bit contiguous addressing mode before calling the SDCC startup code.
15829 \newline 
15830
15831 \newline 
15832 Like the 
15833 \emph on 
15834 -
15835 \begin_inset ERT
15836 status Collapsed
15837
15838 \layout Standard
15839
15840 \backslash 
15841 /
15842 \end_inset 
15843
15844 -model-large
15845 \emph default 
15846  option, variables will by default be placed into the XDATA segment.
15847  
15848 \newline 
15849
15850 \newline 
15851 Segments may be placed anywhere in the 4 meg address space using the usual
15852  -
15853 \begin_inset ERT
15854 status Collapsed
15855
15856 \layout Standard
15857
15858 \backslash 
15859 /
15860 \end_inset 
15861
15862 -*-loc options.
15863  Note that if any segments are located above 64K, the -r flag must be passed
15864  to the linker to generate the proper segment relocations, and the Intel
15865  HEX output format must be used.
15866  The -r flag can be passed to the linker by using the option 
15867 \emph on 
15868 -Wl-r
15869 \emph default 
15870  on the SDCC command line.
15871  However, currently the linker can not handle code segments > 64k.
15872 \layout Section
15873
15874 Pragmas
15875 \begin_inset LatexCommand \index{Pragmas}
15876
15877 \end_inset 
15878
15879
15880 \layout Standard
15881
15882 SDCC supports the following #pragma directives:
15883 \layout Itemize
15884
15885 save
15886 \begin_inset LatexCommand \index{\#pragma save}
15887
15888 \end_inset 
15889
15890  - this will save all current options to the save/restore stack.
15891  See #pragma\SpecialChar ~
15892 restore.
15893 \layout Itemize
15894
15895 restore
15896 \begin_inset LatexCommand \index{\#pragma restore}
15897
15898 \end_inset 
15899
15900  - will restore saved options from the last save.
15901  saves & restores can be nested.
15902  SDCC uses a save/restore stack: save pushes current options to the stack,
15903  restore pulls current options from the stack.
15904  See #pragma\SpecialChar ~
15905 save.
15906 \newline 
15907
15908 \layout Itemize
15909
15910 callee_saves
15911 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15912
15913 \end_inset 
15914
15915
15916 \begin_inset LatexCommand \index{function prologue}
15917
15918 \end_inset 
15919
15920  function1[,function2[,function3...]] - The compiler by default uses a caller
15921  saves convention for register saving across function calls, however this
15922  can cause unnecessary register pushing & popping
15923 \begin_inset LatexCommand \index{push/pop}
15924
15925 \end_inset 
15926
15927  when calling small functions from larger functions.
15928  This option can be used to switch off the register saving convention for
15929  the function names specified.
15930  The compiler will not save registers when calling these functions, extra
15931  code need to be manually inserted at the entry & exit for these functions
15932  to save & restore the registers used by these functions, this can SUBSTANTIALLY
15933  reduce code & improve run time performance of the generated code.
15934  In the future the compiler (with inter procedural analysis) may be able
15935  to determine the appropriate scheme to use for each function call.
15936  If -
15937 \begin_inset ERT
15938 status Collapsed
15939
15940 \layout Standard
15941
15942 \backslash 
15943 /
15944 \end_inset 
15945
15946 -callee-saves command line option is used, the function names specified
15947  in #pragma\SpecialChar ~
15948 callee_saves
15949 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15950
15951 \end_inset 
15952
15953  is appended to the list of functions specified in the command line.
15954 \layout Itemize
15955
15956 exclude
15957 \begin_inset LatexCommand \index{\#pragma exclude}
15958
15959 \end_inset 
15960
15961  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
15962  of pairs of push/pop
15963 \begin_inset LatexCommand \index{push/pop}
15964
15965 \end_inset 
15966
15967  instructions in 
15968 \emph on 
15969 I
15970 \emph default 
15971 nterrupt
15972 \begin_inset LatexCommand \index{interrupt}
15973
15974 \end_inset 
15975
15976  
15977 \emph on 
15978 S
15979 \emph default 
15980 ervice 
15981 \emph on 
15982 R
15983 \emph default 
15984 outines.
15985  The directive should be placed immediately before the ISR function definition
15986  and it affects ALL ISR functions following it.
15987  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
15988 exclude\SpecialChar ~
15989 none
15990 \begin_inset LatexCommand \index{\#pragma exclude}
15991
15992 \end_inset 
15993
15994 .
15995  See also the related keyword _naked
15996 \begin_inset LatexCommand \index{\_naked}
15997
15998 \end_inset 
15999
16000
16001 \begin_inset LatexCommand \index{\_\_naked}
16002
16003 \end_inset 
16004
16005 .
16006 \layout Itemize
16007
16008 less_pedantic
16009 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16010
16011 \end_inset 
16012
16013  - the compiler will not warn you anymore for obvious mistakes, you'r on
16014  your own now ;-(
16015 \layout Itemize
16016
16017 disable_warning <nnnn>
16018 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16019
16020 \end_inset 
16021
16022  - the compiler will not warn you anymore about warning number <nnnn>.
16023 \layout Itemize
16024
16025 nogcse
16026 \begin_inset LatexCommand \index{\#pragma nogcse}
16027
16028 \end_inset 
16029
16030  - will stop global common subexpression elimination.
16031 \layout Itemize
16032
16033 noinduction
16034 \begin_inset LatexCommand \index{\#pragma noinduction}
16035
16036 \end_inset 
16037
16038  - will stop loop induction optimizations.
16039 \layout Itemize
16040
16041 noinvariant
16042 \begin_inset LatexCommand \index{\#pragma noinvariant}
16043
16044 \end_inset 
16045
16046  - will not do loop invariant optimizations.
16047  For more details see Loop Invariants in section
16048 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16049
16050 \end_inset 
16051
16052 .
16053 \layout Itemize
16054
16055 noiv
16056 \begin_inset LatexCommand \index{\#pragma noiv}
16057
16058 \end_inset 
16059
16060  - Do not generate interrupt
16061 \begin_inset LatexCommand \index{interrupt}
16062
16063 \end_inset 
16064
16065  vector table entries for all ISR functions defined after the pragma.
16066  This is useful in cases where the interrupt vector table must be defined
16067  manually, or when there is a secondary, manually defined interrupt vector
16068  table (e.g.
16069  for the autovector feature of the Cypress EZ-USB FX2).
16070  More elegantly this can be achieved by obmitting the optional interrupt
16071  number after the interrupt keyword, see section 
16072 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16073
16074 \end_inset 
16075
16076 \SpecialChar ~
16077 about interrupts.
16078 \layout Itemize
16079
16080 nojtbound
16081 \begin_inset LatexCommand \index{\#pragma nojtbound}
16082
16083 \end_inset 
16084
16085  - will not generate code for boundary value checking, when switch statements
16086  are turned into jump-tables (dangerous).
16087  For more details see section 
16088 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16089
16090 \end_inset 
16091
16092 .
16093 \layout Itemize
16094
16095 noloopreverse
16096 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16097
16098 \end_inset 
16099
16100  - Will not do loop reversal optimization
16101 \layout Itemize
16102
16103 nooverlay
16104 \begin_inset LatexCommand \index{\#pragma nooverlay}
16105
16106 \end_inset 
16107
16108  - the compiler will not overlay the parameters and local variables of a
16109  function.
16110 \layout Itemize
16111
16112 stackauto
16113 \begin_inset LatexCommand \index{\#pragma stackauto}
16114
16115 \end_inset 
16116
16117 - See option -
16118 \begin_inset ERT
16119 status Collapsed
16120
16121 \layout Standard
16122
16123 \backslash 
16124 /
16125 \end_inset 
16126
16127 -stack-auto
16128 \begin_inset LatexCommand \index{-\/-stack-auto}
16129
16130 \end_inset 
16131
16132  and section 
16133 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16134
16135 \end_inset 
16136
16137  Parameters and Local Variables.
16138 \layout Itemize
16139
16140 opt_code_speed 
16141 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16142
16143 \end_inset 
16144
16145 - The compiler will optimize code generation towards fast code, possibly
16146  at the expense of code size.
16147 \layout Itemize
16148
16149 opt_code_size 
16150 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16151
16152 \end_inset 
16153
16154 - The compiler will optimize code generation towards compact code, possibly
16155  at the expense of code speed.
16156 \layout Itemize
16157
16158 opt_code_balanced 
16159 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16160
16161 \end_inset 
16162
16163 - The compiler will attempt to generate code that is both compact and fast,
16164  as long as meeting one goal is not a detriment to the other (this is the
16165  default).
16166  
16167 \layout Itemize
16168
16169 std_sdcc89 
16170 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16171
16172 \end_inset 
16173
16174 - Generally follow the C89 standard, but allow SDCC features that conflict
16175  with the standard (default).
16176 \layout Itemize
16177
16178 std_c89 
16179 \begin_inset LatexCommand \index{\#pragma std\_c89}
16180
16181 \end_inset 
16182
16183 - Follow the C89 standard and disable SDCC features that conflict with the
16184  standard.
16185 \layout Itemize
16186
16187 std_sdcc99 
16188 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16189
16190 \end_inset 
16191
16192 - Generally follow the C99 standard, but allow SDCC features that conflict
16193  with the standard (incomplete support).
16194 \layout Itemize
16195
16196 std_c99 
16197 \begin_inset LatexCommand \index{\#pragma std\_c99}
16198
16199 \end_inset 
16200
16201 - Follow the C99 standard and disable SDCC features that conflict with the
16202  standard (incomplete support).
16203 \layout Itemize
16204
16205 codeseg <name>
16206 \begin_inset LatexCommand \index{\#pragma codeseg}
16207
16208 \end_inset 
16209
16210 - Use this name (max.
16211  8 characters) for the code segment.
16212  See option -
16213 \begin_inset ERT
16214 status Collapsed
16215
16216 \layout Standard
16217
16218 \backslash 
16219 /
16220 \end_inset 
16221
16222 -codeseg.
16223 \layout Itemize
16224
16225 constseg <name>
16226 \begin_inset LatexCommand \index{\#pragma constseg}
16227
16228 \end_inset 
16229
16230 - Use this name (max.
16231  8 characters) for the const segment.
16232  See option -
16233 \begin_inset ERT
16234 status Collapsed
16235
16236 \layout Standard
16237
16238 \backslash 
16239 /
16240 \end_inset 
16241
16242 -constseg.
16243 \layout Standard
16244
16245 SDCPP supports the following #pragma directives:
16246 \layout Itemize
16247
16248 preproc_asm
16249 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16250
16251 \end_inset 
16252
16253  (+ | -) - switch _asm _endasm block preprocessing on / off.
16254  Default is on.
16255  You use this prama to define multilines of assembly code.
16256  This will prevent the preprocessor from changing the formating required
16257  by assembly code.
16258  Below is an example on how to use this pragma.
16259 \layout Verse
16260
16261
16262 \family typewriter 
16263 #pragma preproc_asm -
16264 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16265
16266 \end_inset 
16267
16268
16269 \newline 
16270 #define MYDELAY _asm
16271 \newline 
16272 \SpecialChar ~
16273 \SpecialChar ~
16274 \SpecialChar ~
16275 nop ;my assembly comment...
16276 \newline 
16277 \SpecialChar ~
16278 \SpecialChar ~
16279 \SpecialChar ~
16280 nop
16281 \newline 
16282 \SpecialChar ~
16283 \SpecialChar ~
16284 \SpecialChar ~
16285 nop
16286 \newline 
16287 _endasm
16288 \newline 
16289 #pragma preproc_asm +
16290 \newline 
16291
16292 \newline 
16293 void foo (void) 
16294 \newline 
16295
16296 \newline 
16297 \SpecialChar ~
16298 \SpecialChar ~
16299 \SpecialChar ~
16300  ...
16301  
16302 \newline 
16303 \SpecialChar ~
16304 \SpecialChar ~
16305 \SpecialChar ~
16306  MYDELAY;
16307 \newline 
16308 \SpecialChar ~
16309 \SpecialChar ~
16310 \SpecialChar ~
16311  ...
16312  
16313 \newline 
16314
16315 \newline 
16316
16317 \layout Standard
16318
16319 The pragma's are intended to be used to turn-on or off certain optimizations
16320  which might cause the compiler to generate extra stack / data space to
16321  store compiler generated temporary variables.
16322  This usually happens in large functions.
16323  Pragma directives should be used as shown in the following example, they
16324  are used to control options & optimizations for a given function; pragmas
16325  should be placed before and/or after a function, placing pragma's inside
16326  a function body could have unpredictable results.
16327 \layout Verse
16328
16329
16330 \family typewriter 
16331 #pragma save
16332 \begin_inset LatexCommand \index{\#pragma save}
16333
16334 \end_inset 
16335
16336  \SpecialChar ~
16337 \SpecialChar ~
16338 \SpecialChar ~
16339 \SpecialChar ~
16340 \SpecialChar ~
16341 \SpecialChar ~
16342 \SpecialChar ~
16343 /* save the current settings */ 
16344 \newline 
16345 #pragma nogcse
16346 \begin_inset LatexCommand \index{\#pragma nogcse}
16347
16348 \end_inset 
16349
16350  \SpecialChar ~
16351 \SpecialChar ~
16352 \SpecialChar ~
16353 \SpecialChar ~
16354 \SpecialChar ~
16355 /* turnoff global subexpression elimination */ 
16356 \newline 
16357 #pragma noinduction
16358 \begin_inset LatexCommand \index{\#pragma noinduction}
16359
16360 \end_inset 
16361
16362  /* turn off induction optimizations */ 
16363 \newline 
16364 int foo () 
16365 \newline 
16366
16367 \newline 
16368 \SpecialChar ~
16369  \SpecialChar ~
16370  ...
16371  
16372 \newline 
16373 \SpecialChar ~
16374  \SpecialChar ~
16375  /* large code */ 
16376 \newline 
16377 \SpecialChar ~
16378  \SpecialChar ~
16379  ...
16380  
16381 \newline 
16382
16383 \newline 
16384 #pragma restore
16385 \begin_inset LatexCommand \index{\#pragma restore}
16386
16387 \end_inset 
16388
16389  /* turn the optimizations back on */
16390 \layout Standard
16391
16392 The compiler will generate a warning message when extra space is allocated.
16393  It is strongly recommended that the save and restore pragma's be used when
16394  changing options for a function.
16395 \newline 
16396
16397 \newline 
16398
16399 \newline 
16400
16401 \layout Section
16402
16403 Defines Created by the Compiler
16404 \layout Standard
16405
16406 The compiler creates the following #defines
16407 \begin_inset LatexCommand \index{\#defines}
16408
16409 \end_inset 
16410
16411
16412 \begin_inset LatexCommand \index{Defines created by the compiler}
16413
16414 \end_inset 
16415
16416 :
16417 \newline 
16418
16419 \layout Standard
16420
16421
16422 \begin_inset  Tabular
16423 <lyxtabular version="3" rows="11" columns="2">
16424 <features>
16425 <column alignment="left" valignment="top" leftline="true" width="3in">
16426 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
16427 <row topline="true" bottomline="true">
16428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16429 \begin_inset Text
16430
16431 \layout Standard
16432
16433
16434 \series bold 
16435 #define
16436 \end_inset 
16437 </cell>
16438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16439 \begin_inset Text
16440
16441 \layout Standard
16442
16443
16444 \series bold 
16445 Description
16446 \end_inset 
16447 </cell>
16448 </row>
16449 <row topline="true">
16450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16451 \begin_inset Text
16452
16453 \layout Standard
16454
16455 SDCC
16456 \begin_inset LatexCommand \index{SDCC}
16457
16458 \end_inset 
16459
16460  
16461 \end_inset 
16462 </cell>
16463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16464 \begin_inset Text
16465
16466 \layout Standard
16467
16468 Always defined.
16469  Since version 2.5.6 the version number as an int (ex.
16470  256)
16471 \end_inset 
16472 </cell>
16473 </row>
16474 <row topline="true">
16475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16476 \begin_inset Text
16477
16478 \layout Standard
16479
16480 SDCC_mcs51
16481 \begin_inset LatexCommand \index{SDCC\_mcs51}
16482
16483 \end_inset 
16484
16485  or SDCC_ds390
16486 \begin_inset LatexCommand \index{SDCC\_ds390}
16487
16488 \end_inset 
16489
16490  or SDCC_z80
16491 \begin_inset LatexCommand \index{SDCC\_z80}
16492
16493 \end_inset 
16494
16495 , etc.
16496 \end_inset 
16497 </cell>
16498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16499 \begin_inset Text
16500
16501 \layout Standard
16502
16503 depending on the model used (e.g.: -mds390)
16504 \end_inset 
16505 </cell>
16506 </row>
16507 <row topline="true">
16508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16509 \begin_inset Text
16510
16511 \layout Standard
16512
16513 __mcs51
16514 \begin_inset LatexCommand \index{\_\_mcs51}
16515
16516 \end_inset 
16517
16518 , __ds390
16519 \begin_inset LatexCommand \index{\_\_ds390}
16520
16521 \end_inset 
16522
16523 , __hc08
16524 \begin_inset LatexCommand \index{\_\_hc08}
16525
16526 \end_inset 
16527
16528 , __z80
16529 \begin_inset LatexCommand \index{\_\_z80}
16530
16531 \end_inset 
16532
16533 , etc
16534 \end_inset 
16535 </cell>
16536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16537 \begin_inset Text
16538
16539 \layout Standard
16540
16541 depending on the model used (e.g.
16542  -mz80)
16543 \end_inset 
16544 </cell>
16545 </row>
16546 <row topline="true">
16547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16548 \begin_inset Text
16549
16550 \layout Standard
16551
16552 SDCC_STACK_AUTO
16553 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
16554
16555 \end_inset 
16556
16557
16558 \end_inset 
16559 </cell>
16560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16561 \begin_inset Text
16562
16563 \layout Standard
16564
16565 when 
16566 \emph on 
16567 -
16568 \begin_inset ERT
16569 status Collapsed
16570
16571 \layout Standard
16572
16573 \backslash 
16574 /
16575 \end_inset 
16576
16577 -stack-auto
16578 \emph default 
16579  option is used
16580 \end_inset 
16581 </cell>
16582 </row>
16583 <row topline="true">
16584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16585 \begin_inset Text
16586
16587 \layout Standard
16588
16589 SDCC_MODEL_SMALL
16590 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
16591
16592 \end_inset 
16593
16594
16595 \end_inset 
16596 </cell>
16597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16598 \begin_inset Text
16599
16600 \layout Standard
16601
16602 when 
16603 \emph on 
16604 -
16605 \begin_inset ERT
16606 status Collapsed
16607
16608 \layout Standard
16609
16610 \backslash 
16611 /
16612 \end_inset 
16613
16614 -model-small
16615 \emph default 
16616  is used
16617 \end_inset 
16618 </cell>
16619 </row>
16620 <row topline="true">
16621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16622 \begin_inset Text
16623
16624 \layout Standard
16625
16626 SDCC_MODEL_MEDIUM
16627 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
16628
16629 \end_inset 
16630
16631
16632 \end_inset 
16633 </cell>
16634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16635 \begin_inset Text
16636
16637 \layout Standard
16638
16639 when 
16640 \emph on 
16641 -
16642 \begin_inset ERT
16643 status Collapsed
16644
16645 \layout Standard
16646
16647 \backslash 
16648 /
16649 \end_inset 
16650
16651 -model-medium
16652 \emph default 
16653  is used
16654 \end_inset 
16655 </cell>
16656 </row>
16657 <row topline="true">
16658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16659 \begin_inset Text
16660
16661 \layout Standard
16662
16663 SDCC_MODEL_LARGE
16664 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
16665
16666 \end_inset 
16667
16668
16669 \end_inset 
16670 </cell>
16671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16672 \begin_inset Text
16673
16674 \layout Standard
16675
16676 when 
16677 \emph on 
16678 -
16679 \begin_inset ERT
16680 status Collapsed
16681
16682 \layout Standard
16683
16684 \backslash 
16685 /
16686 \end_inset 
16687
16688 -model-large
16689 \emph default 
16690  is used
16691 \end_inset 
16692 </cell>
16693 </row>
16694 <row topline="true">
16695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16696 \begin_inset Text
16697
16698 \layout Standard
16699
16700 SDCC_USE_XSTACK
16701 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
16702
16703 \end_inset 
16704
16705
16706 \end_inset 
16707 </cell>
16708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16709 \begin_inset Text
16710
16711 \layout Standard
16712
16713 when 
16714 \emph on 
16715 -
16716 \begin_inset ERT
16717 status Collapsed
16718
16719 \layout Standard
16720
16721 \backslash 
16722 /
16723 \end_inset 
16724
16725 -xstack
16726 \emph default 
16727  option is used
16728 \end_inset 
16729 </cell>
16730 </row>
16731 <row topline="true">
16732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16733 \begin_inset Text
16734
16735 \layout Standard
16736
16737 SDCC_STACK_TENBIT
16738 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
16739
16740 \end_inset 
16741
16742  
16743 \end_inset 
16744 </cell>
16745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16746 \begin_inset Text
16747
16748 \layout Standard
16749
16750 when 
16751 \emph on 
16752 -mds390
16753 \emph default 
16754  is used
16755 \end_inset 
16756 </cell>
16757 </row>
16758 <row topline="true" bottomline="true">
16759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16760 \begin_inset Text
16761
16762 \layout Standard
16763
16764 SDCC_MODEL_FLAT24
16765 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
16766
16767 \end_inset 
16768
16769
16770 \end_inset 
16771 </cell>
16772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16773 \begin_inset Text
16774
16775 \layout Standard
16776
16777 when 
16778 \emph on 
16779 -mds390
16780 \emph default 
16781  is used
16782 \end_inset 
16783 </cell>
16784 </row>
16785 </lyxtabular>
16786
16787 \end_inset 
16788
16789
16790 \layout Chapter
16791
16792 Notes on supported Processors
16793 \layout Section
16794
16795 MCS51 variants
16796 \begin_inset LatexCommand \label{sub:MCS51-variants}
16797
16798 \end_inset 
16799
16800
16801 \begin_inset LatexCommand \index{MCS51 variants}
16802
16803 \end_inset 
16804
16805
16806 \layout Standard
16807
16808 MCS51 processors are available from many vendors and come in many different
16809  flavours.
16810  While they might differ considerably in respect to Special Function Registers
16811  the core MCS51 is usually not modified or is kept compatible.
16812  
16813 \layout Subsection
16814
16815 pdata access by SFR 
16816 \layout Standard
16817
16818 With the upcome of devices with internal xdata and flash memory devices
16819  using port P2
16820 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16821
16822 \end_inset 
16823
16824  as dedicated I/O port is becoming more popular.
16825  Switching the high byte for pdata
16826 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16827
16828 \end_inset 
16829
16830  access which was formerly done by port P2 is then achieved by a Special
16831  Function Register
16832 \begin_inset LatexCommand \index{sfr}
16833
16834 \end_inset 
16835
16836 .
16837  In well-established MCS51 tradition the address of this 
16838 \emph on 
16839 sfr
16840 \emph default 
16841  is where the chip designers decided to put it.
16842  Needless to say that they didn't agree on a common name either.
16843  So that the startup code can correctly initialize xdata variables, you
16844  should define an sfr with the name _XPAGE
16845 \family typewriter 
16846
16847 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
16848
16849 \end_inset 
16850
16851
16852 \family default 
16853  at the appropriate location if the default, port P2, is not used for this.
16854  Some examples are:
16855 \layout Verse
16856
16857
16858 \family typewriter 
16859 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
16860 \layout Verse
16861
16862
16863 \family typewriter 
16864 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
16865 \layout Verse
16866
16867
16868 \family typewriter 
16869 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
16870 \layout Standard
16871
16872 For more exotic implementations further customizations may be needed.
16873  See section 
16874 \begin_inset LatexCommand \ref{sub:Startup-Code}
16875
16876 \end_inset 
16877
16878  for other possibilities.
16879 \layout Subsection
16880
16881 Other Features available by SFR
16882 \layout Standard
16883
16884 Some MCS51 variants offer features like Double DPTR
16885 \begin_inset LatexCommand \index{DPTR}
16886
16887 \end_inset 
16888
16889 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
16890  These are currently not used for the MCS51 port.
16891  If you absolutely need them you can fall back to inline assembly or submit
16892  a patch to SDCC.
16893 \layout Section
16894
16895 DS400 port
16896 \layout Standard
16897
16898 The DS80C400 microcontroller has a rich set of peripherals.
16899  In its built-in ROM library it includes functions to access some of the
16900  features, among them is a TCP stack with IP4 and IP6 support.
16901  Library headers (currently in beta status) and other files are provided
16902  at 
16903 \size footnotesize 
16904
16905 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
16906
16907 \end_inset 
16908
16909 .
16910  
16911 \layout Section
16912
16913 The Z80 and gbz80 port
16914 \layout Standard
16915
16916 SDCC can target both the Zilog 
16917 \begin_inset LatexCommand \index{Z80}
16918
16919 \end_inset 
16920
16921  and the Nintendo Gameboy's Z80-like gbz80
16922 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
16923
16924 \end_inset 
16925
16926 .
16927  The Z80 port is passed through the same 
16928 \emph on 
16929 regressions tests
16930 \begin_inset LatexCommand \index{Regression test}
16931
16932 \end_inset 
16933
16934
16935 \emph default 
16936  as the MCS51 and DS390 ports, so floating point support, support for long
16937  variables and bitfield support is fine.
16938  See mailing lists and forums about interrupt routines.
16939 \layout Standard
16940
16941 As always, the code is the authoritative reference - see z80/ralloc.c and
16942  z80/gen.c.
16943  The stack
16944 \begin_inset LatexCommand \index{stack}
16945
16946 \end_inset 
16947
16948  frame is similar to that generated by the IAR Z80 compiler.
16949  IX is used as the base pointer, HL and IY are used as a temporary registers,
16950  and BC and DE are available for holding variables.
16951  Return values
16952 \begin_inset LatexCommand \index{return value}
16953
16954 \end_inset 
16955
16956  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
16957  bytes).
16958  The gbz80 port use the same set of registers for the return values, but
16959  in a different order of significance: E (one byte), DE (two bytes), or
16960  HLDE (four bytes).
16961 \layout Section
16962
16963 The HC08 port
16964 \layout Standard
16965
16966 The port to the Motorola HC08
16967 \begin_inset LatexCommand \index{HC08}
16968
16969 \end_inset 
16970
16971  family has been added in October 2003, and is still undergoing some basic
16972  development.
16973  The code generator is complete, but the register allocation is still quite
16974  unoptimized.
16975  Some of the SDCC's standard C library functions have embedded non-HC08
16976  inline assembly and so are not yet usable.
16977 \newline 
16978
16979 \newline 
16980
16981 \layout Section
16982
16983 The PIC14 port
16984 \layout Standard
16985
16986 The 14bit PIC
16987 \begin_inset LatexCommand \index{PIC14}
16988
16989 \end_inset 
16990
16991  port still requires a major effort from the development community.
16992  However it can work for very simple code.
16993 \layout Subsection
16994
16995 C code and 14bit PIC code page
16996 \begin_inset LatexCommand \index{code page (pic14)}
16997
16998 \end_inset 
16999
17000  and RAM banks
17001 \begin_inset LatexCommand \index{RAM bank (pic14)}
17002
17003 \end_inset 
17004
17005
17006 \layout Standard
17007
17008 The linker organizes allocation for the code page and RAM banks.
17009  It does not have intimate knowledge of the code flow.
17010  It will put all the code section of a single asm file into a single code
17011  page.
17012  In order to make use of multiple code pages, separate asm files must be
17013  used.
17014  The compiler treats all functions of a single C file as being in the same
17015  code page unless it is non static.
17016  The compiler treats all local variables of a single C file as being in
17017  the same RAM bank unless it is an extern.
17018 \newline 
17019
17020 \newline 
17021 To get the best follow these guide lines:
17022 \layout Enumerate
17023
17024 make local functions static, as non static functions require code page selection
17025  overhead.
17026 \layout Enumerate
17027
17028 Make local variables static as extern variables require RAM bank selection
17029  overhead.
17030 \layout Enumerate
17031
17032 For devices that have multiple code pages it is more efficient to use the
17033  same number of files as pages, i.e.
17034  for the 16F877 use 4 separate files and i.e.
17035  for the 16F874 use 2 separate files.
17036  This way the linker can put the code for each file into different code
17037  pages and the compiler can allocate reusable variables more efficiently
17038  and there's less page selection overhead.
17039  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17040  instruction set) use 'unsigned char' whereever possible instead of 'int'.
17041 \layout Subsection
17042
17043 Creating a device include file 
17044 \layout Standard
17045
17046 For generating a device include file use the support perl script inc2h.pl
17047  kept in directory support/script.
17048 \layout Subsection
17049
17050 Interrupt code
17051 \layout Standard
17052
17053 For the interrupt function, use the keyword 'interrupt'
17054 \begin_inset LatexCommand \index{interrupt}
17055
17056 \end_inset 
17057
17058  with level number of 0 (PIC14 only has 1 interrupt so this number is only
17059  there to avoid a syntax error - it ought to be fixed).
17060  E.g.:
17061 \layout Verse
17062
17063
17064 \family typewriter 
17065 void Intr(void) interrupt 0
17066 \newline 
17067 {
17068 \newline 
17069 \SpecialChar ~
17070 \SpecialChar ~
17071 T0IF = 0; /* Clear timer interrupt */
17072 \newline 
17073 }
17074 \layout Subsection
17075
17076 Linking and assembling
17077 \layout Standard
17078
17079 For assembling you can use either GPUTILS'
17080 \begin_inset LatexCommand \index{gputils (pic tools)}
17081
17082 \end_inset 
17083
17084  gpasm.exe or MPLAB's mpasmwin.exe.
17085  GPUTILS is available from 
17086 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17087
17088 \end_inset 
17089
17090 .
17091  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17092  If you use MPLAB and an interrupt function then the linker script file
17093  vectors section will need to be enlarged to link with mplink.
17094 \newline 
17095
17096 \newline 
17097 Here is a 
17098 \family typewriter 
17099 Makefile
17100 \family default 
17101  using GPUTILS:
17102 \layout Verse
17103
17104
17105 \family typewriter 
17106 .c.o:
17107 \newline 
17108 \SpecialChar ~
17109 \SpecialChar ~
17110 \SpecialChar ~
17111 \SpecialChar ~
17112 \SpecialChar ~
17113 \SpecialChar ~
17114 \SpecialChar ~
17115 \SpecialChar ~
17116 sdcc -S -V -mpic14 -p16F877 $< 
17117 \newline 
17118 \SpecialChar ~
17119 \SpecialChar ~
17120 \SpecialChar ~
17121 \SpecialChar ~
17122 \SpecialChar ~
17123 \SpecialChar ~
17124 \SpecialChar ~
17125 \SpecialChar ~
17126 gpasm -c $*.asm
17127 \newline 
17128
17129 \newline 
17130 $(PRJ).hex: $(OBJS) 
17131 \newline 
17132 \SpecialChar ~
17133 \SpecialChar ~
17134 \SpecialChar ~
17135 \SpecialChar ~
17136 \SpecialChar ~
17137 \SpecialChar ~
17138 \SpecialChar ~
17139 \SpecialChar ~
17140 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
17141 \layout Standard
17142
17143 Here is a 
17144 \family typewriter 
17145 Makefile
17146 \family default 
17147  using MPLAB:
17148 \layout Verse
17149
17150
17151 \family typewriter 
17152 .c.o: 
17153 \newline 
17154 \SpecialChar ~
17155 \SpecialChar ~
17156 \SpecialChar ~
17157 \SpecialChar ~
17158 \SpecialChar ~
17159 \SpecialChar ~
17160 \SpecialChar ~
17161 \SpecialChar ~
17162 sdcc -S -V -mpic14 -p16F877 $< 
17163 \newline 
17164 \SpecialChar ~
17165 \SpecialChar ~
17166 \SpecialChar ~
17167 \SpecialChar ~
17168 \SpecialChar ~
17169 \SpecialChar ~
17170 \SpecialChar ~
17171 \SpecialChar ~
17172 mpasmwin /q /o $*.asm
17173 \newline 
17174
17175 \newline 
17176 $(PRJ).hex: $(OBJS) 
17177 \newline 
17178 \SpecialChar ~
17179 \SpecialChar ~
17180 \SpecialChar ~
17181 \SpecialChar ~
17182 \SpecialChar ~
17183 \SpecialChar ~
17184 \SpecialChar ~
17185 \SpecialChar ~
17186 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17187 \layout Standard
17188
17189 Please note that indentations within a
17190 \family typewriter 
17191  Makefile
17192 \family default 
17193  have to be done with a tabulator character.
17194 \layout Subsection
17195
17196 Command-line options
17197 \layout Standard
17198
17199 Besides the switches common to all SDCC backends, the PIC14 port accepts
17200  the following options (for an updated list see sdcc -
17201 \begin_inset ERT
17202 status Collapsed
17203
17204 \layout Standard
17205
17206 \backslash 
17207 /
17208 \end_inset 
17209
17210 -help):
17211 \layout List
17212 \labelwidthstring 00.00.0000
17213
17214 -
17215 \begin_inset ERT
17216 status Collapsed
17217
17218 \layout Standard
17219
17220 \backslash 
17221 /
17222 \end_inset 
17223
17224 -debug-extra emit debug info in assembly output
17225 \layout List
17226 \labelwidthstring 00.00.0000
17227
17228 -
17229 \begin_inset ERT
17230 status Collapsed
17231
17232 \layout Standard
17233
17234 \backslash 
17235 /
17236 \end_inset 
17237
17238 -no-pcode-opt disable (slightly faulty) optimization on pCode
17239 \layout Subsection
17240
17241 The library
17242 \layout Subsubsection
17243
17244 error: missing definition for symbol 
17245 \begin_inset Quotes sld
17246 \end_inset 
17247
17248 __gptrget1
17249 \begin_inset Quotes srd
17250 \end_inset 
17251
17252
17253 \layout Standard
17254
17255 The PIC14 port uses library routines to provide more complex operations
17256  like multiplication, division/modulus and (generic) pointer dereferencing.
17257  In order to add these routines to your project, you must link with PIC14's
17258  
17259 \family typewriter 
17260 libsdcc.lib
17261 \family default 
17262 .
17263  For single source file projects this is done automatically, more complex
17264  projects must add 
17265 \family typewriter 
17266 libsdcc.lib
17267 \family default 
17268  to the linker's arguments.
17269  Make sure you also add an include path for the library (using the -I switch
17270  to the linker)!
17271 \layout Subsubsection
17272
17273 Processor mismatch in file 
17274 \begin_inset Quotes sld
17275 \end_inset 
17276
17277 XXX
17278 \begin_inset Quotes srd
17279 \end_inset 
17280
17281 .
17282 \layout Standard
17283
17284 This warning can usually be ignored due to the very good compatibility amongst
17285  14 bit PIC devices.
17286 \layout Standard
17287
17288 You might also consider recompiling the library for your specific device
17289  by changing the ARCH=p16f877 (default target) entry in 
17290 \family typewriter 
17291 device/lib/pic/Makefile.in
17292 \family default 
17293  and 
17294 \family typewriter 
17295 device/lib/pic/Makefile
17296 \family default 
17297  to reflect your device.
17298  This might even improve performance for smaller devices as unneccesary
17299  BANKSELs migth be removed.
17300 \layout Subsection
17301
17302 Known bugs
17303 \layout Subsubsection
17304
17305 initialized data
17306 \layout Standard
17307
17308 Currently, data can only be initialized if it resides in the source file
17309  together with 
17310 \emph on 
17311 main()
17312 \emph default 
17313 .
17314  Data in other source files will silently 
17315 \series bold 
17316 not
17317 \series default 
17318  be initialized.
17319 \layout Section
17320
17321 The PIC16
17322 \begin_inset LatexCommand \index{PIC16}
17323
17324 \end_inset 
17325
17326  port
17327 \layout Standard
17328
17329 The PIC16
17330 \begin_inset LatexCommand \index{PIC16}
17331
17332 \end_inset 
17333
17334  port is the portion of SDCC that is responsible to produce code for the
17335  Microchip
17336 \begin_inset LatexCommand \index{Microchip}
17337
17338 \end_inset 
17339
17340 (TM) microcontrollers with 16 bit core.
17341  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
17342  Currently supported devices are:
17343 \layout Standard
17344 \align center 
17345
17346 \begin_inset  Tabular
17347 <lyxtabular version="3" rows="4" columns="6">
17348 <features>
17349 <column alignment="center" valignment="top" leftline="true" width="0">
17350 <column alignment="center" valignment="top" leftline="true" width="0">
17351 <column alignment="center" valignment="top" leftline="true" width="0">
17352 <column alignment="center" valignment="top" leftline="true" width="0">
17353 <column alignment="center" valignment="top" leftline="true" width="0">
17354 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17355 <row topline="true">
17356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17357 \begin_inset Text
17358
17359 \layout Standard
17360
17361 18F242
17362 \end_inset 
17363 </cell>
17364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17365 \begin_inset Text
17366
17367 \layout Standard
17368
17369 18F248
17370 \end_inset 
17371 </cell>
17372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17373 \begin_inset Text
17374
17375 \layout Standard
17376
17377 18F252
17378 \end_inset 
17379 </cell>
17380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17381 \begin_inset Text
17382
17383 \layout Standard
17384
17385 18F258
17386 \end_inset 
17387 </cell>
17388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17389 \begin_inset Text
17390
17391 \layout Standard
17392
17393 18F442
17394 \end_inset 
17395 </cell>
17396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17397 \begin_inset Text
17398
17399 \layout Standard
17400
17401 18F448
17402 \end_inset 
17403 </cell>
17404 </row>
17405 <row topline="true">
17406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17407 \begin_inset Text
17408
17409 \layout Standard
17410
17411 18F452
17412 \end_inset 
17413 </cell>
17414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17415 \begin_inset Text
17416
17417 \layout Standard
17418
17419 18F458
17420 \end_inset 
17421 </cell>
17422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17423 \begin_inset Text
17424
17425 \layout Standard
17426
17427 18F1220
17428 \end_inset 
17429 </cell>
17430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17431 \begin_inset Text
17432
17433 \layout Standard
17434
17435 18F2220
17436 \end_inset 
17437 </cell>
17438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17439 \begin_inset Text
17440
17441 \layout Standard
17442
17443 18F2550
17444 \end_inset 
17445 </cell>
17446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17447 \begin_inset Text
17448
17449 \layout Standard
17450
17451 18F4331
17452 \end_inset 
17453 </cell>
17454 </row>
17455 <row topline="true">
17456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17457 \begin_inset Text
17458
17459 \layout Standard
17460
17461 18F4455
17462 \end_inset 
17463 </cell>
17464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17465 \begin_inset Text
17466
17467 \layout Standard
17468
17469 18F6520
17470 \end_inset 
17471 </cell>
17472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17473 \begin_inset Text
17474
17475 \layout Standard
17476
17477 18F6620
17478 \end_inset 
17479 </cell>
17480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17481 \begin_inset Text
17482
17483 \layout Standard
17484
17485 18F6680
17486 \end_inset 
17487 </cell>
17488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17489 \begin_inset Text
17490
17491 \layout Standard
17492
17493 18F6720
17494 \end_inset 
17495 </cell>
17496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17497 \begin_inset Text
17498
17499 \layout Standard
17500
17501 18F8520
17502 \end_inset 
17503 </cell>
17504 </row>
17505 <row topline="true" bottomline="true">
17506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17507 \begin_inset Text
17508
17509 \layout Standard
17510
17511 18F8620
17512 \end_inset 
17513 </cell>
17514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17515 \begin_inset Text
17516
17517 \layout Standard
17518
17519 18F8680
17520 \end_inset 
17521 </cell>
17522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17523 \begin_inset Text
17524
17525 \layout Standard
17526
17527 18F8720
17528 \end_inset 
17529 </cell>
17530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17531 \begin_inset Text
17532
17533 \layout Standard
17534
17535 \end_inset 
17536 </cell>
17537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17538 \begin_inset Text
17539
17540 \layout Standard
17541
17542 \end_inset 
17543 </cell>
17544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17545 \begin_inset Text
17546
17547 \layout Standard
17548
17549 \end_inset 
17550 </cell>
17551 </row>
17552 </lyxtabular>
17553
17554 \end_inset 
17555
17556
17557 \layout Subsection
17558
17559 Global Options
17560 \layout Standard
17561
17562 PIC16 port supports the standard command line arguments as supposed, with
17563  the exception of certain cases that will be mentioned in the following
17564  list:
17565 \layout List
17566 \labelwidthstring 00.00.0000
17567
17568 -
17569 \begin_inset ERT
17570 status Collapsed
17571
17572 \layout Standard
17573
17574 \backslash 
17575 /
17576 \end_inset 
17577
17578 -callee-saves See -
17579 \begin_inset ERT
17580 status Collapsed
17581
17582 \layout Standard
17583
17584 \backslash 
17585 /
17586 \end_inset 
17587
17588 -all-callee-saves
17589 \layout List
17590 \labelwidthstring 00.00.0000
17591
17592 -
17593 \begin_inset ERT
17594 status Collapsed
17595
17596 \layout Standard
17597
17598 \backslash 
17599 /
17600 \end_inset 
17601
17602 -all-callee-saves All function arguments are passed on stack by default.
17603  
17604 \emph on 
17605 There is no need to specify this in the command line.
17606 \layout List
17607 \labelwidthstring 00.00.0000
17608
17609 -
17610 \begin_inset ERT
17611 status Collapsed
17612
17613 \layout Standard
17614
17615 \backslash 
17616 /
17617 \end_inset 
17618
17619 -fommit-frame-pointer Frame pointer will be omitted when the function uses
17620  no local variables.
17621 \layout Subsection
17622
17623 Port Specific Options
17624 \begin_inset LatexCommand \index{Options PIC16}
17625
17626 \end_inset 
17627
17628
17629 \layout Standard
17630
17631 The port specific options appear after the global options in the sdcc --help
17632  output.
17633 \layout Subsubsection
17634
17635 General Options
17636 \layout Standard
17637
17638 General options enable certain port features and optimizations.
17639 \layout List
17640 \labelwidthstring 00.00.0000
17641
17642 -
17643 \begin_inset ERT
17644 status Collapsed
17645
17646 \layout Standard
17647
17648 \backslash 
17649 /
17650 \end_inset 
17651
17652 -stack-model=[model] Used in conjuction with the command above.
17653  Defines the stack model to be used, valid stack models are : 
17654 \begin_deeper 
17655 \layout List
17656 \labelwidthstring 00.00.0000
17657
17658
17659 \emph on 
17660 small
17661 \emph default 
17662  Selects small stack model.
17663  8 bit stack and frame pointers.
17664  Supports 256 bytes stack size.
17665 \layout List
17666 \labelwidthstring 00.00.0000
17667
17668
17669 \emph on 
17670 large
17671 \emph default 
17672  Selects large stack model.
17673  16 bit stack and frame pointers.
17674  Supports 65536 bytes stack size.
17675 \end_deeper 
17676 \layout List
17677 \labelwidthstring 00.00.0000
17678
17679 -
17680 \begin_inset ERT
17681 status Collapsed
17682
17683 \layout Standard
17684
17685 \backslash 
17686 /
17687 \end_inset 
17688
17689 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
17690  unitialized data variables with [kword].
17691  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
17692 \layout List
17693 \labelwidthstring 00.00.0000
17694
17695 -
17696 \begin_inset ERT
17697 status Collapsed
17698
17699 \layout Standard
17700
17701 \backslash 
17702 /
17703 \end_inset 
17704
17705 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
17706  Useful for bootloaders.
17707 \layout List
17708 \labelwidthstring 00.00.0000
17709
17710 -
17711 \begin_inset ERT
17712 status Collapsed
17713
17714 \layout Standard
17715
17716 \backslash 
17717 /
17718 \end_inset 
17719
17720 -asm= sets the full path and name of an external assembler to call.
17721 \layout List
17722 \labelwidthstring 00.00.0000
17723
17724 -
17725 \begin_inset ERT
17726 status Collapsed
17727
17728 \layout Standard
17729
17730 \backslash 
17731 /
17732 \end_inset 
17733
17734 -link= sets the full path and name of an external linker to call.
17735 \layout List
17736 \labelwidthstring 00.00.0000
17737
17738 -
17739 \begin_inset ERT
17740 status Collapsed
17741
17742 \layout Standard
17743
17744 \backslash 
17745 /
17746 \end_inset 
17747
17748 -mplab-comp MPLAB compatibility option.
17749  Currently only suppresses special gpasm directives.
17750 \layout Subsubsection
17751
17752 Optimization Options
17753 \layout List
17754 \labelwidthstring 00.00.0000
17755
17756 -
17757 \begin_inset ERT
17758 status Collapsed
17759
17760 \layout Standard
17761
17762 \backslash 
17763 /
17764 \end_inset 
17765
17766 -optimize-goto Try to use (conditional) BRA instead of GOTO
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 -optimize-cmp Try to optimize some compares.
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 -optimize-df Analyze the dataflow of the generated code and improve it.
17795 \layout List
17796 \labelwidthstring 00.00.0000
17797
17798 -
17799 \begin_inset ERT
17800 status Collapsed
17801
17802 \layout Standard
17803
17804 \backslash 
17805 /
17806 \end_inset 
17807
17808 -obanksel=nn Set optimization level for inserting BANKSELs.
17809 \newline 
17810
17811 \begin_deeper 
17812 \layout List
17813 \labelwidthstring 00.00.0000
17814
17815 0 no optimization
17816 \layout List
17817 \labelwidthstring 00.00.0000
17818
17819 1 checks previous used register and if it is the same then does not emit
17820  BANKSEL, accounts only for labels.
17821 \layout List
17822 \labelwidthstring 00.00.0000
17823
17824 2 tries to check the location of (even different) symbols and removes BANKSELs
17825  if they are in the same bank.
17826  
17827 \newline 
17828
17829 \emph on 
17830 Important: There might be problems if the linker script has data sections
17831  across bank borders!
17832 \end_deeper 
17833 \layout Subsubsection
17834
17835 Linking Options
17836 \layout List
17837 \labelwidthstring 00.00.0000
17838
17839 -
17840 \begin_inset ERT
17841 status Collapsed
17842
17843 \layout Standard
17844
17845 \backslash 
17846 /
17847 \end_inset 
17848
17849 -nodefaultlibs do not link default libraries when linking
17850 \layout List
17851 \labelwidthstring 00.00.0000
17852
17853 -
17854 \begin_inset ERT
17855 status Collapsed
17856
17857 \layout Standard
17858
17859 \backslash 
17860 /
17861 \end_inset 
17862
17863 -no-crt Don't link the default run-time modules
17864 \layout List
17865 \labelwidthstring 00.00.0000
17866
17867 -
17868 \begin_inset ERT
17869 status Collapsed
17870
17871 \layout Standard
17872
17873 \backslash 
17874 /
17875 \end_inset 
17876
17877 -use-crt= Use a custom run-time module instead of the defaults.
17878 \layout Subsubsection
17879
17880 Debugging Options
17881 \layout Standard
17882
17883 Debugging options enable extra debugging information in the output files.
17884 \layout List
17885 \labelwidthstring 00.00.0000
17886
17887 -
17888 \begin_inset ERT
17889 status Collapsed
17890
17891 \layout Standard
17892
17893 \backslash 
17894 /
17895 \end_inset 
17896
17897 -debug-xtra Similar to -
17898 \begin_inset ERT
17899 status Collapsed
17900
17901 \layout Standard
17902
17903 \backslash 
17904 /
17905 \end_inset 
17906
17907 -debug
17908 \begin_inset LatexCommand \index{-\/-debug}
17909
17910 \end_inset 
17911
17912 , but dumps more information.
17913 \layout List
17914 \labelwidthstring 00.00.0000
17915
17916 -
17917 \begin_inset ERT
17918 status Collapsed
17919
17920 \layout Standard
17921
17922 \backslash 
17923 /
17924 \end_inset 
17925
17926 -debug-ralloc Force register allocator to dump <source>.d file with debugging
17927  information.
17928  <source> is the name of the file compiled.
17929 \layout List
17930 \labelwidthstring 00.00.0000
17931
17932 -
17933 \begin_inset ERT
17934 status Collapsed
17935
17936 \layout Standard
17937
17938 \backslash 
17939 /
17940 \end_inset 
17941
17942 -pcode-verbose Enable pcode debugging information in translation.
17943 \layout List
17944 \labelwidthstring 00.00.0000
17945
17946 -
17947 \begin_inset ERT
17948 status Collapsed
17949
17950 \layout Standard
17951
17952 \backslash 
17953 /
17954 \end_inset 
17955
17956 -denable-peeps Force the usage of peepholes.
17957  Use with care.
17958 \layout List
17959 \labelwidthstring 00.00.0000
17960
17961 -
17962 \begin_inset ERT
17963 status Collapsed
17964
17965 \layout Standard
17966
17967 \backslash 
17968 /
17969 \end_inset 
17970
17971 -gstack Trace push/pops for stack pointer overflow
17972 \layout List
17973 \labelwidthstring 00.00.0000
17974
17975 -
17976 \begin_inset ERT
17977 status Collapsed
17978
17979 \layout Standard
17980
17981 \backslash 
17982 /
17983 \end_inset 
17984
17985 -call-tree dump call tree in .calltree file
17986 \layout Subsection
17987
17988 Enviromental Variables
17989 \layout Standard
17990
17991 There is a number of enviromental variables that can be used when running
17992  SDCC to enable certain optimizations or force a specific program behaviour.
17993  these variables are primarily for debugging purposes so they can be enabled/dis
17994 abled at will.
17995 \layout Standard
17996
17997 Currently there is only two such variables available:
17998 \layout List
17999 \labelwidthstring 00.00.0000
18000
18001 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18002  bitfields is optimized by directly loading FSR0 with the address of the
18003  bitfield structure.
18004  Normally SDCC will cast the bitfield structure to a bitfield pointer and
18005  then load FSR0.
18006  This step saves data ram and code space for functions that perform heavy
18007  use of bitfields.
18008  (ie.
18009  80 bytes of code space are saved when compiling malloc.c with this option).
18010  
18011 \layout List
18012 \labelwidthstring 00.00.0000
18013
18014 NO_REG_OPT do not perform pCode registers optimization.
18015  This should be used for debugging purposes.
18016  In some where bugs in the pcode optimizer are found, users can benefit
18017  from temporarily disabling the optimizer until the bug is fixed.
18018 \layout Subsection
18019
18020 Preprocessor Macros
18021 \layout Standard
18022
18023 PIC16 port defines the following preprocessor macros while translating a
18024  source.
18025 \layout Standard
18026 \align center 
18027
18028 \begin_inset  Tabular
18029 <lyxtabular version="3" rows="6" columns="2">
18030 <features>
18031 <column alignment="center" valignment="top" leftline="true" width="0">
18032 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18033 <row topline="true" bottomline="true">
18034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18035 \begin_inset Text
18036
18037 \layout Standard
18038
18039 Macro
18040 \end_inset 
18041 </cell>
18042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18043 \begin_inset Text
18044
18045 \layout Standard
18046
18047 Description
18048 \end_inset 
18049 </cell>
18050 </row>
18051 <row topline="true">
18052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18053 \begin_inset Text
18054
18055 \layout Standard
18056
18057 SDCC_pic16
18058 \end_inset 
18059 </cell>
18060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18061 \begin_inset Text
18062
18063 \layout Standard
18064
18065 Port identification
18066 \end_inset 
18067 </cell>
18068 </row>
18069 <row topline="true">
18070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18071 \begin_inset Text
18072
18073 \layout Standard
18074
18075 _
18076 \begin_inset ERT
18077 status Collapsed
18078
18079 \layout Standard
18080
18081 \backslash 
18082 /
18083 \end_inset 
18084
18085 _pic16
18086 \end_inset 
18087 </cell>
18088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18089 \begin_inset Text
18090
18091 \layout Standard
18092
18093 Port identification (same as above)
18094 \end_inset 
18095 </cell>
18096 </row>
18097 <row topline="true">
18098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18099 \begin_inset Text
18100
18101 \layout Standard
18102
18103 pic18fxxxx
18104 \end_inset 
18105 </cell>
18106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18107 \begin_inset Text
18108
18109 \layout Standard
18110
18111 MCU Identification.
18112  
18113 \emph on 
18114 xxxx
18115 \emph default 
18116  is the microcontrol identification number, i.e.
18117  452, 6620, etc
18118 \end_inset 
18119 </cell>
18120 </row>
18121 <row topline="true">
18122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18123 \begin_inset Text
18124
18125 \layout Standard
18126
18127 _
18128 \begin_inset ERT
18129 status Collapsed
18130
18131 \layout Standard
18132
18133 \backslash 
18134 /
18135 \end_inset 
18136
18137 _18Fxxxx
18138 \end_inset 
18139 </cell>
18140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18141 \begin_inset Text
18142
18143 \layout Standard
18144
18145 MCU Identification (same as above)
18146 \end_inset 
18147 </cell>
18148 </row>
18149 <row topline="true" bottomline="true">
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18151 \begin_inset Text
18152
18153 \layout Standard
18154
18155 STACK_MODEL_nnn
18156 \end_inset 
18157 </cell>
18158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18159 \begin_inset Text
18160
18161 \layout Standard
18162
18163 nnn = SMALL or LARGE respectively according to the stack model used
18164 \end_inset 
18165 </cell>
18166 </row>
18167 </lyxtabular>
18168
18169 \end_inset 
18170
18171
18172 \layout Standard
18173
18174 In addition the following macros are defined when calling assembler:
18175 \layout Standard
18176 \align center 
18177
18178 \begin_inset  Tabular
18179 <lyxtabular version="3" rows="4" columns="2">
18180 <features>
18181 <column alignment="center" valignment="top" leftline="true" width="0">
18182 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18183 <row topline="true" bottomline="true">
18184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18185 \begin_inset Text
18186
18187 \layout Standard
18188
18189 Macro
18190 \end_inset 
18191 </cell>
18192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18193 \begin_inset Text
18194
18195 \layout Standard
18196
18197 Description
18198 \end_inset 
18199 </cell>
18200 </row>
18201 <row topline="true">
18202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18203 \begin_inset Text
18204
18205 \layout Standard
18206
18207 __18Fxxxx
18208 \end_inset 
18209 </cell>
18210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18211 \begin_inset Text
18212
18213 \layout Standard
18214
18215 MCU Identification.
18216  
18217 \emph on 
18218 xxxx
18219 \emph default 
18220  is the microcontrol identification number, i.e.
18221  452, 6620, etc
18222 \end_inset 
18223 </cell>
18224 </row>
18225 <row topline="true">
18226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18227 \begin_inset Text
18228
18229 \layout Standard
18230
18231 SDCC_MODEL_nnn
18232 \end_inset 
18233 </cell>
18234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18235 \begin_inset Text
18236
18237 \layout Standard
18238
18239 nnn = SMALL or LARGE respectively according to the memory model used for
18240  SDCC
18241 \end_inset 
18242 </cell>
18243 </row>
18244 <row topline="true" bottomline="true">
18245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18246 \begin_inset Text
18247
18248 \layout Standard
18249
18250 STACK_MODEL_nnn
18251 \end_inset 
18252 </cell>
18253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18254 \begin_inset Text
18255
18256 \layout Standard
18257
18258 nnn = SMALL or LARGE respectively according to the stack model used
18259 \end_inset 
18260 </cell>
18261 </row>
18262 </lyxtabular>
18263
18264 \end_inset 
18265
18266
18267 \layout Subsection
18268
18269 Directories
18270 \layout Standard
18271
18272 PIC16
18273 \begin_inset LatexCommand \index{PIC16}
18274
18275 \end_inset 
18276
18277  port uses the following directories for searching header files and libraries.
18278 \layout Standard
18279 \align center 
18280
18281 \begin_inset  Tabular
18282 <lyxtabular version="3" rows="3" columns="4">
18283 <features>
18284 <column alignment="center" valignment="top" leftline="true" width="0">
18285 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18286 <column alignment="center" valignment="top" width="0">
18287 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18288 <row topline="true" bottomline="true">
18289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18290 \begin_inset Text
18291
18292 \layout Standard
18293
18294 Directory
18295 \end_inset 
18296 </cell>
18297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18298 \begin_inset Text
18299
18300 \layout Standard
18301
18302 Description
18303 \end_inset 
18304 </cell>
18305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18306 \begin_inset Text
18307
18308 \layout Standard
18309
18310 Target
18311 \end_inset 
18312 </cell>
18313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18314 \begin_inset Text
18315
18316 \layout Standard
18317
18318 Command prefix
18319 \end_inset 
18320 </cell>
18321 </row>
18322 <row topline="true">
18323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18324 \begin_inset Text
18325
18326 \layout Standard
18327
18328 PREFIX/sdcc/include/pic16
18329 \end_inset 
18330 </cell>
18331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18332 \begin_inset Text
18333
18334 \layout Standard
18335
18336 PIC16 specific headers
18337 \end_inset 
18338 </cell>
18339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18340 \begin_inset Text
18341
18342 \layout Standard
18343
18344 Compiler
18345 \end_inset 
18346 </cell>
18347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18348 \begin_inset Text
18349
18350 \layout Standard
18351
18352 -I
18353 \end_inset 
18354 </cell>
18355 </row>
18356 <row topline="true" bottomline="true">
18357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18358 \begin_inset Text
18359
18360 \layout Standard
18361
18362 PREFIX/sdcc/lib/pic16
18363 \end_inset 
18364 </cell>
18365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18366 \begin_inset Text
18367
18368 \layout Standard
18369
18370 PIC16 specific libraries
18371 \end_inset 
18372 </cell>
18373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18374 \begin_inset Text
18375
18376 \layout Standard
18377
18378 Linker
18379 \end_inset 
18380 </cell>
18381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18382 \begin_inset Text
18383
18384 \layout Standard
18385
18386 -L
18387 \end_inset 
18388 </cell>
18389 </row>
18390 </lyxtabular>
18391
18392 \end_inset 
18393
18394
18395 \layout Subsection
18396
18397 Pragmas
18398 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
18399
18400 \end_inset 
18401
18402
18403 \layout Standard
18404
18405 PIC16 port currently supports the following pragmas:
18406 \layout List
18407 \labelwidthstring 00.00.0000
18408
18409 stack pragma stack forces the code generator to initialize the stack & frame
18410  pointers at a specific address.
18411  This is an adhoc solution for cases where no STACK directive is available
18412  in the linker script or gplink is not instructed to create a stack section.
18413 \newline 
18414 The stack pragma should be used only once in a project.
18415  Multiple pragmas may result in indeterminate behaviour of the program.
18416 \begin_inset Foot
18417 collapsed false
18418
18419 \layout Standard
18420
18421 The old format (ie.
18422  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
18423  cross page boundaries (or even exceed the available data RAM) and crash
18424  the program.
18425  Make sure that stack does not cross page boundaries when using the SMALL
18426  stack model.
18427 \end_inset 
18428
18429
18430 \newline 
18431 The format is as follows:
18432 \layout LyX-Code
18433
18434 #pragma stack bottom_address [stack_size]
18435 \layout Standard
18436
18437
18438 \emph on 
18439 bottom_address
18440 \emph default 
18441  is the lower bound of the stack section.
18442  The stack pointer initially will point at address (bottom_address+stack_size-1).
18443 \layout LyX-Code
18444
18445 Example:
18446 \layout LyX-Code
18447
18448 \layout LyX-Code
18449
18450 /* initializes stack of 100 bytes at RAM address 0x200 */
18451 \layout LyX-Code
18452
18453 #pragma stack 0x200 100
18454 \layout Standard
18455
18456 If the stack_size field is omitted then a stack is created with the default
18457  size of 64.
18458  This size might be enough for most programs, but its not enough for operations
18459  with deep function nesting or excessive stack usage.
18460 \layout List
18461 \labelwidthstring 00.00.0000
18462
18463 wparam 
18464 \emph on 
18465 This pragma is deprecated.
18466  Its use will cause a warning message to be issued.
18467 \emph default 
18468
18469 \newline 
18470
18471 \layout List
18472 \labelwidthstring 00.00.0000
18473
18474 code place a function symbol at static FLASH address
18475 \layout LyX-Code
18476
18477 Example:
18478 \layout LyX-Code
18479
18480 \layout LyX-Code
18481
18482 /* place function test_func at 0x4000 */
18483 \layout LyX-Code
18484
18485 #pragma code test_func 0x4000
18486 \layout LyX-Code
18487
18488 \layout List
18489 \labelwidthstring 00.00.0000
18490
18491 library instructs the linker to use a library module.
18492 \newline 
18493 Usage:
18494 \layout LyX-Code
18495
18496 #pragma library module_name
18497 \layout Standard
18498
18499
18500 \emph on 
18501 module_name
18502 \emph default 
18503  can be any library or object file (including its path).
18504  Note that there are four reserved keywords which have special meaning.
18505  These are:
18506 \layout Standard
18507 \align center 
18508
18509 \begin_inset  Tabular
18510 <lyxtabular version="3" rows="6" columns="3">
18511 <features>
18512 <column alignment="center" valignment="top" leftline="true" width="0">
18513 <column alignment="block" valignment="top" leftline="true" width="20page%">
18514 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18515 <row topline="true" bottomline="true">
18516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18517 \begin_inset Text
18518
18519 \layout Standard
18520
18521 Keyword
18522 \end_inset 
18523 </cell>
18524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18525 \begin_inset Text
18526
18527 \layout Standard
18528
18529 Description
18530 \end_inset 
18531 </cell>
18532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18533 \begin_inset Text
18534
18535 \layout Standard
18536
18537 Module to link
18538 \end_inset 
18539 </cell>
18540 </row>
18541 <row topline="true">
18542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18543 \begin_inset Text
18544
18545 \layout Standard
18546
18547
18548 \series bold 
18549 ignore
18550 \end_inset 
18551 </cell>
18552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18553 \begin_inset Text
18554
18555 \layout Standard
18556
18557 ignore all library pragmas
18558 \end_inset 
18559 </cell>
18560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18561 \begin_inset Text
18562
18563 \layout Standard
18564
18565
18566 \emph on 
18567 (none)
18568 \end_inset 
18569 </cell>
18570 </row>
18571 <row topline="true">
18572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18573 \begin_inset Text
18574
18575 \layout Standard
18576
18577
18578 \series bold 
18579 c
18580 \end_inset 
18581 </cell>
18582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18583 \begin_inset Text
18584
18585 \layout Standard
18586
18587 link the C library
18588 \end_inset 
18589 </cell>
18590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18591 \begin_inset Text
18592
18593 \layout Standard
18594
18595
18596 \emph on 
18597 libc18f
18598 \emph default 
18599 .lib
18600 \end_inset 
18601 </cell>
18602 </row>
18603 <row topline="true">
18604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18605 \begin_inset Text
18606
18607 \layout Standard
18608
18609
18610 \series bold 
18611 math
18612 \end_inset 
18613 </cell>
18614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18615 \begin_inset Text
18616
18617 \layout Standard
18618
18619 link the Math libarary
18620 \end_inset 
18621 </cell>
18622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18623 \begin_inset Text
18624
18625 \layout Standard
18626
18627
18628 \emph on 
18629 libm18f
18630 \emph default 
18631 .lib
18632 \end_inset 
18633 </cell>
18634 </row>
18635 <row topline="true">
18636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18637 \begin_inset Text
18638
18639 \layout Standard
18640
18641
18642 \series bold 
18643 io
18644 \end_inset 
18645 </cell>
18646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18647 \begin_inset Text
18648
18649 \layout Standard
18650
18651 link the I/O library
18652 \end_inset 
18653 </cell>
18654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18655 \begin_inset Text
18656
18657 \layout Standard
18658
18659
18660 \emph on 
18661 libio18f*
18662 \emph default 
18663 .lib
18664 \end_inset 
18665 </cell>
18666 </row>
18667 <row topline="true" bottomline="true">
18668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18669 \begin_inset Text
18670
18671 \layout Standard
18672
18673
18674 \series bold 
18675 debug
18676 \end_inset 
18677 </cell>
18678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18679 \begin_inset Text
18680
18681 \layout Standard
18682
18683 link the debug library
18684 \end_inset 
18685 </cell>
18686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18687 \begin_inset Text
18688
18689 \layout Standard
18690
18691
18692 \emph on 
18693 libdebug
18694 \emph default 
18695 .lib
18696 \end_inset 
18697 </cell>
18698 </row>
18699 </lyxtabular>
18700
18701 \end_inset 
18702
18703
18704 \newline 
18705 * is the device number, i.e.
18706  452 for PIC18F452 MCU.
18707 \layout Standard
18708
18709 This feature allows for linking with specific libraries withoug having to
18710  explicit name them in the command line.
18711  Note that the 
18712 \noun on 
18713 ignore
18714 \noun default 
18715  keyword will reject all modules specified by the library pragma.
18716 \layout List
18717 \labelwidthstring 00.00.0000
18718
18719 udata pragma udata instructs the compiler to emit code so that linker will
18720  place a variable at a specific memory bank
18721 \layout LyX-Code
18722
18723 Example:
18724 \layout LyX-Code
18725
18726 \layout LyX-Code
18727
18728 /* places variable foo at bank2 */
18729 \layout LyX-Code
18730
18731 #pragma udata bank2 foo
18732 \layout LyX-Code
18733
18734 char foo;
18735 \layout Standard
18736
18737 In order for this pragma to work extra SECTION directives should be added
18738  in the .lkr script.
18739  In the following example a sample .lkr file is shown:
18740 \layout LyX-Code
18741
18742 \layout LyX-Code
18743
18744 // Sample linker script for the PIC18F452 processor
18745 \layout LyX-Code
18746
18747 LIBPATH .
18748 \layout LyX-Code
18749
18750 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
18751 \layout LyX-Code
18752
18753 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
18754 \layout LyX-Code
18755
18756 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
18757 \layout LyX-Code
18758
18759 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
18760 \layout LyX-Code
18761
18762 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
18763 \layout LyX-Code
18764
18765 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
18766 \layout LyX-Code
18767
18768 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
18769 \layout LyX-Code
18770
18771 \layout LyX-Code
18772
18773 DATABANK   NAME=gpr0       START=0x80           END=0xFF
18774 \layout LyX-Code
18775
18776 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
18777 \layout LyX-Code
18778
18779 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
18780 \layout LyX-Code
18781
18782 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
18783 \layout LyX-Code
18784
18785 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
18786 \layout LyX-Code
18787
18788 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
18789 \layout LyX-Code
18790
18791 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
18792 \layout LyX-Code
18793
18794 \layout LyX-Code
18795
18796 SECTION    NAME=CONFIG     ROM=config
18797 \layout LyX-Code
18798
18799 \layout LyX-Code
18800
18801 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
18802 \layout LyX-Code
18803
18804 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
18805 \layout LyX-Code
18806
18807 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
18808 \layout LyX-Code
18809
18810 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
18811 \layout LyX-Code
18812
18813 SECTION    NAME=bank4      RAM=gpr4
18814 \layout LyX-Code
18815
18816 SECTION    NAME=bank5      RAM=gpr5
18817 \layout Standard
18818
18819 The linker will recognise the section name set in the pragma statement and
18820  will position the variable at the memory bank set with the RAM field at
18821  the SECTION line in the linker script file.
18822 \layout Subsection
18823
18824 Header Files
18825 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
18826
18827 \end_inset 
18828
18829
18830 \layout Standard
18831
18832 There is one main header file that can be included to the source files using
18833  the pic16 port.
18834  That file is the 
18835 \series bold 
18836 pic18fregs.h
18837 \series default 
18838 .
18839  This header file contains the definitions for the processor special registers,
18840  so it is necessary if the source accesses them.
18841  It can be included by adding the following line in the beginning of the
18842  file:
18843 \layout LyX-Code
18844
18845 #include <pic18fregs.h>
18846 \layout Standard
18847
18848 The specific microcontroller is selected within the pic18fregs.h automatically,
18849  so the same source can be used with a variety of devices.
18850 \layout Subsection
18851
18852 Libraries
18853 \layout Standard
18854
18855 The libraries that PIC16
18856 \begin_inset LatexCommand \index{PIC16}
18857
18858 \end_inset 
18859
18860  port depends on are the microcontroller device libraries which contain
18861  the symbol definitions for the microcontroller special function registers.
18862  These libraries have the format pic18fxxxx.lib, where 
18863 \emph on 
18864 xxxx
18865 \emph default 
18866  is the microcontroller identification number.
18867  The specific library is selected automatically by the compiler at link
18868  stage according to the selected device.
18869 \layout Standard
18870
18871 Libraries are created with gplib which is part of the gputils package 
18872 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
18873
18874 \end_inset 
18875
18876 .
18877 \layout Subsubsection*
18878
18879 Building the libraries
18880 \layout Standard
18881
18882 Before using SDCC/pic16 there are some libraries that need to be compiled.
18883  This process is not done automatically by SDCC since not all users use
18884  SDCC for pic16 projects.
18885  So each user should compile the libraries separately.
18886 \layout Standard
18887
18888 The steps to compile the pic16 libraries under Linux are:
18889 \layout LyX-Code
18890
18891 cd device/lib/pic16
18892 \layout LyX-Code
18893
18894 ./configure
18895 \layout LyX-Code
18896
18897 make
18898 \layout LyX-Code
18899
18900 cd ..
18901 \layout LyX-Code
18902
18903 make model-pic16
18904 \layout LyX-Code
18905
18906 su -c 'make install'     # install the libraries, you need the root password
18907 \layout Standard
18908
18909 If you need to install the headers too, do:
18910 \layout LyX-Code
18911
18912 cd device/include
18913 \layout LyX-Code
18914
18915 su -c 'make install'     # install the headers, you need the root password
18916 \layout Standard
18917
18918 There exist a special target to build the I/O libraries.
18919  This target is not automatically build because it will build the I/O library
18920  for 
18921 \emph on 
18922 every
18923 \emph default 
18924  supported device.
18925  This way building will take quite a lot of time.
18926  Users are advised to edit the 
18927 \series bold 
18928 device/lib/pic16/pics.build
18929 \series default 
18930  file and then execute:
18931 \layout LyX-Code
18932
18933 make lib-io
18934 \layout Subsection
18935
18936 Memory Models
18937 \layout Standard
18938
18939 The following memory models are supported by the PIC16 port:
18940 \layout Itemize
18941
18942 small model
18943 \layout Itemize
18944
18945 large model
18946 \layout Standard
18947
18948 Memory model affects the default size of pointers within the source.
18949  The sizes are shown in the next table:
18950 \layout Standard
18951 \align center 
18952
18953 \begin_inset  Tabular
18954 <lyxtabular version="3" rows="3" columns="3">
18955 <features>
18956 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18957 <column alignment="center" valignment="top" leftline="true" width="0">
18958 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18959 <row topline="true" bottomline="true">
18960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18961 \begin_inset Text
18962
18963 \layout Standard
18964
18965 Pointer sizes according to memory model
18966 \end_inset 
18967 </cell>
18968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18969 \begin_inset Text
18970
18971 \layout Standard
18972
18973 small model
18974 \end_inset 
18975 </cell>
18976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18977 \begin_inset Text
18978
18979 \layout Standard
18980
18981 large model
18982 \end_inset 
18983 </cell>
18984 </row>
18985 <row topline="true" bottomline="true">
18986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18987 \begin_inset Text
18988
18989 \layout Standard
18990
18991 code pointers
18992 \end_inset 
18993 </cell>
18994 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18995 \begin_inset Text
18996
18997 \layout Standard
18998
18999 16-bits
19000 \end_inset 
19001 </cell>
19002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19003 \begin_inset Text
19004
19005 \layout Standard
19006
19007 24-bits
19008 \end_inset 
19009 </cell>
19010 </row>
19011 <row topline="true" bottomline="true">
19012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19013 \begin_inset Text
19014
19015 \layout Standard
19016
19017 data pointers
19018 \end_inset 
19019 </cell>
19020 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
19021 \begin_inset Text
19022
19023 \layout Standard
19024
19025 16-bits
19026 \end_inset 
19027 </cell>
19028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19029 \begin_inset Text
19030
19031 \layout Standard
19032
19033 16-bits
19034 \end_inset 
19035 </cell>
19036 </row>
19037 </lyxtabular>
19038
19039 \end_inset 
19040
19041
19042 \layout Standard
19043
19044 It is advisable that all sources within a project are compiled with the
19045  same memory model.
19046  If one wants to override the default memory model, this can be done by
19047  declaring a pointer as 
19048 \series bold 
19049 far
19050 \series default 
19051  or 
19052 \series bold 
19053 near
19054 \series default 
19055 .
19056  Far selects large memory model's pointers, while near selects small memory
19057  model's pointers.
19058 \layout Standard
19059
19060 The standard device libraries (see 
19061 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
19062
19063 \end_inset 
19064
19065 ) contain no reference to pointers, so they can be used with both memory
19066  models.
19067 \layout Subsection
19068
19069 Stack
19070 \layout Standard
19071
19072 The stack implementation for the PIC16 port uses two indirect registers,
19073  FSR1 and FSR2.
19074 \layout List
19075 \labelwidthstring 00.00.0000
19076
19077 FSR1 is assigned as stack pointer
19078 \layout List
19079 \labelwidthstring 00.00.0000
19080
19081 FSR2 is assigned as frame pointer
19082 \layout Standard
19083
19084 The following stack models are supported by the PIC16 port
19085 \layout Itemize
19086
19087
19088 \noun on 
19089 small
19090 \noun default 
19091  model
19092 \layout Itemize
19093
19094
19095 \noun on 
19096 large
19097 \noun default 
19098  model
19099 \layout Standard
19100
19101
19102 \noun on 
19103 Small
19104 \noun default 
19105  model means that only the FSRxL byte is used to access stack and frame,
19106  while 
19107 \emph on 
19108 \noun on 
19109 large
19110 \emph default 
19111 \noun default 
19112  uses both FSRxL and FSRxH registers.
19113  The following table shows the stack/frame pointers sizes according to stack
19114  model and the maximum space they can address:
19115 \layout Standard
19116 \align center 
19117
19118 \begin_inset  Tabular
19119 <lyxtabular version="3" rows="3" columns="3">
19120 <features>
19121 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19122 <column alignment="center" valignment="top" leftline="true" width="0">
19123 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19124 <row topline="true" bottomline="true">
19125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19126 \begin_inset Text
19127
19128 \layout Standard
19129
19130 Stack & Frame pointer sizes according to stack model
19131 \end_inset 
19132 </cell>
19133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19134 \begin_inset Text
19135
19136 \layout Standard
19137
19138 small
19139 \end_inset 
19140 </cell>
19141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19142 \begin_inset Text
19143
19144 \layout Standard
19145
19146 large
19147 \end_inset 
19148 </cell>
19149 </row>
19150 <row topline="true">
19151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19152 \begin_inset Text
19153
19154 \layout Standard
19155
19156 Stack pointer FSR1
19157 \end_inset 
19158 </cell>
19159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19160 \begin_inset Text
19161
19162 \layout Standard
19163
19164 8-bits
19165 \end_inset 
19166 </cell>
19167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19168 \begin_inset Text
19169
19170 \layout Standard
19171
19172 16-bits
19173 \end_inset 
19174 </cell>
19175 </row>
19176 <row topline="true" bottomline="true">
19177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19178 \begin_inset Text
19179
19180 \layout Standard
19181
19182 Frame pointer FSR2
19183 \end_inset 
19184 </cell>
19185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19186 \begin_inset Text
19187
19188 \layout Standard
19189
19190 8-bits
19191 \end_inset 
19192 </cell>
19193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19194 \begin_inset Text
19195
19196 \layout Standard
19197
19198 16-bits
19199 \end_inset 
19200 </cell>
19201 </row>
19202 </lyxtabular>
19203
19204 \end_inset 
19205
19206
19207 \layout Standard
19208
19209
19210 \noun on 
19211 Large 
19212 \noun default 
19213 stack model is currently not working properly throughout the code generator.
19214  So its use is not advised.
19215  Also there are some other points that need special care:
19216 \newline 
19217
19218 \layout Enumerate
19219
19220 Do not create stack sections with size more than one physical bank (that
19221  is 256 bytes)
19222 \layout Enumerate
19223
19224 Stack sections should no cross physical bank limits (i.e.
19225  #pragma stack 0x50 0x100)
19226 \layout Standard
19227
19228 These limitations are caused by the fact that only FSRxL is modified when
19229  using SMALL stack model, so no more than 256 bytes of stack can be used.
19230  This problem will disappear after LARGE model is fully implemented.
19231 \layout Subsection
19232
19233 Functions
19234 \layout Standard
19235
19236 In addition to the standard SDCC function keywords, PIC16 port makes available
19237  two more:
19238 \layout List
19239 \labelwidthstring 00.00.0000
19240
19241 wparam Use the WREG to pass one byte of the first function argument.
19242  This improves speed but you may not use this for functions with arguments
19243  that are called via function pointers, otherwise the first byte of the
19244  first parameter will get lost.
19245  Usage:
19246 \layout LyX-Code
19247
19248 void func_wparam(int a) wparam
19249 \layout LyX-Code
19250
19251 {
19252 \layout LyX-Code
19253
19254     /* WREG hold the lower part of a */
19255 \layout LyX-Code
19256
19257     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
19258  */
19259 \layout LyX-Code
19260
19261 ...
19262 \layout LyX-Code
19263
19264 }
19265 \layout Standard
19266
19267 This keyword replaces the deprecated wparam pragma.
19268 \layout List
19269 \labelwidthstring 00.00.0000
19270
19271 shadowregs When entering/exiting an ISR, it is possible to take advantage
19272  of the PIC18F hardware shadow registers which hold the values of WREG,
19273  STATUS and BSR registers.
19274  This can be done by adding the keyword 
19275 \emph on 
19276 shadowregs
19277 \emph default 
19278  before the 
19279 \emph on 
19280 interrupt
19281 \emph default 
19282  keyword in the function's header.
19283 \layout LyX-Code
19284
19285 void isr_shadow(void) shadowregs interrupt 1
19286 \layout LyX-Code
19287
19288 {
19289 \layout LyX-Code
19290
19291 ...
19292 \layout LyX-Code
19293
19294 }
19295 \layout Standard
19296
19297
19298 \emph on 
19299 shadowregs
19300 \emph default 
19301  instructs the code generator not to store/restore WREG, STATUS, BSR when
19302  entering/exiting the ISR.
19303 \layout Subsection
19304
19305 Function return values
19306 \layout Standard
19307
19308 Return values from functions are placed to the appropriate registers following
19309  a modified Microchip policy optimized for SDCC.
19310  The following table shows these registers:
19311 \layout Standard
19312 \align center 
19313
19314 \begin_inset  Tabular
19315 <lyxtabular version="3" rows="6" columns="2">
19316 <features>
19317 <column alignment="center" valignment="top" leftline="true" width="0">
19318 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19319 <row topline="true" bottomline="true">
19320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19321 \begin_inset Text
19322
19323 \layout Standard
19324
19325 size
19326 \end_inset 
19327 </cell>
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19329 \begin_inset Text
19330
19331 \layout Standard
19332
19333 destination register
19334 \end_inset 
19335 </cell>
19336 </row>
19337 <row topline="true">
19338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19339 \begin_inset Text
19340
19341 \layout Standard
19342
19343 8 bits
19344 \end_inset 
19345 </cell>
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19347 \begin_inset Text
19348
19349 \layout Standard
19350
19351 WREG
19352 \end_inset 
19353 </cell>
19354 </row>
19355 <row topline="true">
19356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19357 \begin_inset Text
19358
19359 \layout Standard
19360
19361 16 bits
19362 \end_inset 
19363 </cell>
19364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19365 \begin_inset Text
19366
19367 \layout Standard
19368
19369 PRODL:WREG
19370 \end_inset 
19371 </cell>
19372 </row>
19373 <row topline="true">
19374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19375 \begin_inset Text
19376
19377 \layout Standard
19378
19379 24 bits
19380 \end_inset 
19381 </cell>
19382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19383 \begin_inset Text
19384
19385 \layout Standard
19386
19387 PRODH:PRODL:WREG
19388 \end_inset 
19389 </cell>
19390 </row>
19391 <row topline="true">
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19393 \begin_inset Text
19394
19395 \layout Standard
19396
19397 32 bits
19398 \end_inset 
19399 </cell>
19400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19401 \begin_inset Text
19402
19403 \layout Standard
19404
19405 FSR0L:PRODH:PRODL:WREG
19406 \end_inset 
19407 </cell>
19408 </row>
19409 <row topline="true" bottomline="true">
19410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19411 \begin_inset Text
19412
19413 \layout Standard
19414
19415 >32 bits
19416 \end_inset 
19417 </cell>
19418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19419 \begin_inset Text
19420
19421 \layout Standard
19422
19423 on stack, FSR0 points to the beginning
19424 \end_inset 
19425 </cell>
19426 </row>
19427 </lyxtabular>
19428
19429 \end_inset 
19430
19431
19432 \layout Subsection
19433
19434 Interrupts
19435 \layout Standard
19436
19437 An interrupt servive routine (ISR) is declared using the 
19438 \emph on 
19439 interrupt
19440 \emph default 
19441  keyword.
19442 \layout LyX-Code
19443
19444 void isr(void) interrupt 
19445 \emph on 
19446 n
19447 \layout LyX-Code
19448
19449 {
19450 \layout LyX-Code
19451
19452 ...
19453 \layout LyX-Code
19454
19455 }
19456 \layout Standard
19457
19458
19459 \emph on 
19460 n
19461 \emph default 
19462  is the interrupt number, which for PIC18F devices can be:
19463 \layout Standard
19464 \align center 
19465
19466 \begin_inset  Tabular
19467 <lyxtabular version="3" rows="4" columns="3">
19468 <features>
19469 <column alignment="center" valignment="top" leftline="true" width="0">
19470 <column alignment="center" valignment="top" leftline="true" width="0">
19471 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19472 <row topline="true" bottomline="true">
19473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19474 \begin_inset Text
19475
19476 \layout Standard
19477
19478
19479 \emph on 
19480 n
19481 \end_inset 
19482 </cell>
19483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19484 \begin_inset Text
19485
19486 \layout Standard
19487
19488 Interrupt Vector
19489 \end_inset 
19490 </cell>
19491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19492 \begin_inset Text
19493
19494 \layout Standard
19495
19496 Interrupt Vector Address
19497 \end_inset 
19498 </cell>
19499 </row>
19500 <row topline="true">
19501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19502 \begin_inset Text
19503
19504 \layout Standard
19505
19506 0
19507 \end_inset 
19508 </cell>
19509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19510 \begin_inset Text
19511
19512 \layout Standard
19513
19514 RESET vector
19515 \end_inset 
19516 </cell>
19517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19518 \begin_inset Text
19519
19520 \layout Standard
19521
19522 0x000000
19523 \end_inset 
19524 </cell>
19525 </row>
19526 <row topline="true">
19527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19528 \begin_inset Text
19529
19530 \layout Standard
19531
19532
19533 \family roman 
19534 \series medium 
19535 \shape up 
19536 \size normal 
19537 \emph off 
19538 \bar no 
19539 \noun off 
19540 \color none
19541 1
19542 \end_inset 
19543 </cell>
19544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19545 \begin_inset Text
19546
19547 \layout Standard
19548
19549
19550 \family roman 
19551 \series medium 
19552 \shape up 
19553 \size normal 
19554 \emph off 
19555 \bar no 
19556 \noun off 
19557 \color none
19558 HIGH priority interrupts
19559 \end_inset 
19560 </cell>
19561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19562 \begin_inset Text
19563
19564 \layout Standard
19565
19566 0x000008
19567 \end_inset 
19568 </cell>
19569 </row>
19570 <row topline="true" bottomline="true">
19571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19572 \begin_inset Text
19573
19574 \layout Standard
19575
19576 2
19577 \end_inset 
19578 </cell>
19579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19580 \begin_inset Text
19581
19582 \layout Standard
19583
19584 LOW priority interrupts
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 0x000018
19593 \end_inset 
19594 </cell>
19595 </row>
19596 </lyxtabular>
19597
19598 \end_inset 
19599
19600
19601 \layout Standard
19602
19603 When generating assembly code for ISR the code generator places a 
19604 \noun on 
19605 goto 
19606 \noun default 
19607 instruction at the 
19608 \emph on 
19609 Interrupt Vector Address
19610 \emph default 
19611  which points at the genetated ISR.
19612  This single GOTO instruction is part of an automatically generated 
19613 \emph on 
19614 interrupt entry point
19615 \emph default 
19616  function.
19617  The actuall ISR code is placed as normally would in the code space.
19618  Upon interrupt request, the GOTO instruction is executed which jumps to
19619  the ISR code.
19620  When declaring interrupt functions as _naked this GOTO instruction is 
19621 \series bold 
19622 not
19623 \series default 
19624  generated.
19625  The whole interrupt functions is therefore placed at the Interrupt Vector
19626  Address of the specific interrupt.
19627  This is not a problem for the LOW priority interrupts, but it is a problem
19628  for the RESET and the HIGH priority interrupts because code may be written
19629  at the next interrupt´s vector address and cause undeterminate program
19630  behaviour if that interrupt is raised.
19631 \begin_inset Foot
19632 collapsed false
19633
19634 \layout Standard
19635
19636 This is not a problem when
19637 \layout Enumerate
19638
19639 this is a HIGH interrupt ISR and LOW interrupts are 
19640 \emph on 
19641 disabled
19642 \emph default 
19643  or not used.
19644 \layout Enumerate
19645
19646 when the ISR is small enough not to reach the next interrupt´s vector address.
19647 \end_inset 
19648
19649
19650 \layout Standard
19651
19652
19653 \emph on 
19654 n
19655 \emph default 
19656  is possible to be omitted.
19657  This way a function is generated similar to an ISR, but it is not assigned
19658  to any interrupt.
19659 \layout Standard
19660
19661 When entering an interrupt, currently the PIC16
19662 \begin_inset LatexCommand \index{PIC16}
19663
19664 \end_inset 
19665
19666  port automatically saves the following registers:
19667 \layout Itemize
19668
19669 WREG
19670 \layout Itemize
19671
19672 STATUS
19673 \layout Itemize
19674
19675 BSR
19676 \layout Itemize
19677
19678 PROD (PRODL and PRODH)
19679 \layout Itemize
19680
19681 FSR0 (FSR0L and FSR0H)
19682 \layout Standard
19683
19684 These registers are restored upon return from the interrupt routine.
19685 \begin_inset Foot
19686 collapsed false
19687
19688 \layout Standard
19689
19690 NOTE that when the _naked attribute is specified for an interrupt routine,
19691  then NO registers are stored or restored.
19692 \end_inset 
19693
19694
19695 \layout Subsection
19696
19697 Generic Pointers
19698 \layout Standard
19699
19700 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
19701  There are 3 types of generic pointers currently implemented data, code
19702  and eeprom pointers.
19703  They are differentiated by the value of the 7th and 6th bits of the upper
19704  byte:
19705 \layout Standard
19706 \align center 
19707
19708 \begin_inset  Tabular
19709 <lyxtabular version="3" rows="5" columns="5">
19710 <features>
19711 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19712 <column alignment="center" valignment="top" width="0">
19713 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19714 <column alignment="center" valignment="top" width="0">
19715 <column alignment="left" valignment="top" rightline="true" width="0">
19716 <row topline="true" bottomline="true">
19717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19718 \begin_inset Text
19719
19720 \layout Standard
19721
19722 pointer type
19723 \end_inset 
19724 </cell>
19725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19726 \begin_inset Text
19727
19728 \layout Standard
19729
19730 7th bit
19731 \end_inset 
19732 </cell>
19733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19734 \begin_inset Text
19735
19736 \layout Standard
19737
19738 6th bit
19739 \end_inset 
19740 </cell>
19741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19742 \begin_inset Text
19743
19744 \layout Standard
19745
19746 rest of the pointer
19747 \end_inset 
19748 </cell>
19749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19750 \begin_inset Text
19751
19752 \layout Standard
19753
19754 description
19755 \end_inset 
19756 </cell>
19757 </row>
19758 <row topline="true" bottomline="true">
19759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19760 \begin_inset Text
19761
19762 \layout Standard
19763
19764 data 
19765 \end_inset 
19766 </cell>
19767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19768 \begin_inset Text
19769
19770 \layout Standard
19771
19772 1
19773 \end_inset 
19774 </cell>
19775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19776 \begin_inset Text
19777
19778 \layout Standard
19779
19780 0
19781 \end_inset 
19782 </cell>
19783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19784 \begin_inset Text
19785
19786 \layout Standard
19787
19788
19789 \family typewriter 
19790 \shape slanted 
19791 \emph on 
19792 uuuuuu uuuuxxxx xxxxxxxx
19793 \end_inset 
19794 </cell>
19795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19796 \begin_inset Text
19797
19798 \layout Standard
19799
19800 a 12-bit data pointer in data RAM memory
19801 \end_inset 
19802 </cell>
19803 </row>
19804 <row bottomline="true">
19805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19806 \begin_inset Text
19807
19808 \layout Standard
19809
19810 code
19811 \end_inset 
19812 </cell>
19813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19814 \begin_inset Text
19815
19816 \layout Standard
19817
19818 0
19819 \end_inset 
19820 </cell>
19821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19822 \begin_inset Text
19823
19824 \layout Standard
19825
19826 0
19827 \end_inset 
19828 </cell>
19829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19830 \begin_inset Text
19831
19832 \layout Standard
19833
19834
19835 \family typewriter 
19836 \shape slanted 
19837 \emph on 
19838 uxxxxx xxxxxxxx xxxxxxxx
19839 \end_inset 
19840 </cell>
19841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19842 \begin_inset Text
19843
19844 \layout Standard
19845
19846 a 21-bit code pointer in FLASH memory
19847 \end_inset 
19848 </cell>
19849 </row>
19850 <row bottomline="true">
19851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19852 \begin_inset Text
19853
19854 \layout Standard
19855
19856 eeprom
19857 \end_inset 
19858 </cell>
19859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19860 \begin_inset Text
19861
19862 \layout Standard
19863
19864 0
19865 \end_inset 
19866 </cell>
19867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19868 \begin_inset Text
19869
19870 \layout Standard
19871
19872 1
19873 \end_inset 
19874 </cell>
19875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19876 \begin_inset Text
19877
19878 \layout Standard
19879
19880
19881 \family typewriter 
19882 \shape slanted 
19883 \emph on 
19884 uuuuuu uuuuuuxx xxxxxxxx
19885 \end_inset 
19886 </cell>
19887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19888 \begin_inset Text
19889
19890 \layout Standard
19891
19892 a 10-bit eeprom pointer in EEPROM memory
19893 \end_inset 
19894 </cell>
19895 </row>
19896 <row bottomline="true">
19897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19898 \begin_inset Text
19899
19900 \layout Standard
19901
19902 (unimplemented)
19903 \end_inset 
19904 </cell>
19905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19906 \begin_inset Text
19907
19908 \layout Standard
19909
19910 1
19911 \end_inset 
19912 </cell>
19913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19914 \begin_inset Text
19915
19916 \layout Standard
19917
19918 1
19919 \end_inset 
19920 </cell>
19921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19922 \begin_inset Text
19923
19924 \layout Standard
19925
19926
19927 \family typewriter 
19928 \shape slanted 
19929 \emph on 
19930 xxxxxx xxxxxxxx xxxxxxxx
19931 \end_inset 
19932 </cell>
19933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19934 \begin_inset Text
19935
19936 \layout Standard
19937
19938 unimplemented pointer type
19939 \end_inset 
19940 </cell>
19941 </row>
19942 </lyxtabular>
19943
19944 \end_inset 
19945
19946
19947 \layout Standard
19948
19949 Generic pointer are read and written with a set of library functions which
19950  read/write 1, 2, 3, 4 bytes.
19951 \layout Subsection
19952
19953 PIC16 C Libraries
19954 \layout Subsubsection
19955
19956 Standard I/O Streams
19957 \layout Standard
19958
19959 In the 
19960 \emph on 
19961 stdio.h
19962 \emph default 
19963  the type FILE is defined as:
19964 \layout LyX-Code
19965
19966 typedef char * FILE;
19967 \layout Standard
19968
19969 This type is the stream type implemented I/O in the PIC18F devices.
19970  Also the standard input and output streams are declared in stdio.h:
19971 \layout LyX-Code
19972
19973 extern FILE * stdin;
19974 \layout LyX-Code
19975
19976 extern FILE * stdout;
19977 \layout Standard
19978
19979 The FILE type is actually a generic pointer which defines one more type
19980  of generic pointers, the 
19981 \emph on 
19982 stream 
19983 \emph default 
19984 pointer.
19985  This new type has the format:
19986 \layout Standard
19987 \align center 
19988
19989 \begin_inset  Tabular
19990 <lyxtabular version="3" rows="2" columns="7">
19991 <features>
19992 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19993 <column alignment="center" valignment="top" width="0">
19994 <column alignment="center" valignment="top" leftline="true" width="0">
19995 <column alignment="center" valignment="top" leftline="true" width="0">
19996 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19997 <column alignment="center" valignment="top" width="0">
19998 <column alignment="left" valignment="top" rightline="true" width="0">
19999 <row topline="true" bottomline="true">
20000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20001 \begin_inset Text
20002
20003 \layout Standard
20004
20005 pointer type
20006 \end_inset 
20007 </cell>
20008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20009 \begin_inset Text
20010
20011 \layout Standard
20012
20013 <7:6>
20014 \end_inset 
20015 </cell>
20016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20017 \begin_inset Text
20018
20019 \layout Standard
20020
20021 <5>
20022 \end_inset 
20023 </cell>
20024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20025 \begin_inset Text
20026
20027 \layout Standard
20028
20029 <4>
20030 \end_inset 
20031 </cell>
20032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20033 \begin_inset Text
20034
20035 \layout Standard
20036
20037 <3:0>
20038 \end_inset 
20039 </cell>
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20041 \begin_inset Text
20042
20043 \layout Standard
20044
20045 rest of the pointer
20046 \end_inset 
20047 </cell>
20048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20049 \begin_inset Text
20050
20051 \layout Standard
20052
20053 descrption
20054 \end_inset 
20055 </cell>
20056 </row>
20057 <row topline="true" bottomline="true">
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20059 \begin_inset Text
20060
20061 \layout Standard
20062
20063 stream
20064 \end_inset 
20065 </cell>
20066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20067 \begin_inset Text
20068
20069 \layout Standard
20070
20071 00
20072 \end_inset 
20073 </cell>
20074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20075 \begin_inset Text
20076
20077 \layout Standard
20078
20079 1
20080 \end_inset 
20081 </cell>
20082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20083 \begin_inset Text
20084
20085 \layout Standard
20086
20087 0
20088 \end_inset 
20089 </cell>
20090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20091 \begin_inset Text
20092
20093 \layout Standard
20094
20095 nnnn
20096 \end_inset 
20097 </cell>
20098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20099 \begin_inset Text
20100
20101 \layout Standard
20102
20103
20104 \family typewriter 
20105 \shape slanted 
20106 \emph on 
20107 uuuuuuuu uuuuuuuu
20108 \end_inset 
20109 </cell>
20110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20111 \begin_inset Text
20112
20113 \layout Standard
20114
20115 upper byte high nubble is 0x2n, the rest are zeroes
20116 \end_inset 
20117 </cell>
20118 </row>
20119 </lyxtabular>
20120
20121 \end_inset 
20122
20123
20124 \layout Standard
20125
20126 Currently implemented there are 3 types of streams defined:
20127 \layout Standard
20128 \align center 
20129
20130 \begin_inset  Tabular
20131 <lyxtabular version="3" rows="4" columns="4">
20132 <features>
20133 <column alignment="center" valignment="top" leftline="true" width="0">
20134 <column alignment="center" valignment="top" leftline="true" width="0">
20135 <column alignment="center" valignment="top" leftline="true" width="0">
20136 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20137 <row topline="true" bottomline="true">
20138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20139 \begin_inset Text
20140
20141 \layout Standard
20142
20143 stream type
20144 \end_inset 
20145 </cell>
20146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20147 \begin_inset Text
20148
20149 \layout Standard
20150
20151 value
20152 \end_inset 
20153 </cell>
20154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20155 \begin_inset Text
20156
20157 \layout Standard
20158
20159 module
20160 \end_inset 
20161 </cell>
20162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20163 \begin_inset Text
20164
20165 \layout Standard
20166
20167 description
20168 \end_inset 
20169 </cell>
20170 </row>
20171 <row topline="true">
20172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20173 \begin_inset Text
20174
20175 \layout Standard
20176
20177 STREAM_USART
20178 \end_inset 
20179 </cell>
20180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20181 \begin_inset Text
20182
20183 \layout Standard
20184
20185
20186 \family typewriter 
20187 0x200000UL
20188 \end_inset 
20189 </cell>
20190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20191 \begin_inset Text
20192
20193 \layout Standard
20194
20195 USART
20196 \end_inset 
20197 </cell>
20198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20199 \begin_inset Text
20200
20201 \layout Standard
20202
20203 Writes/Reads characters via the USART peripheral
20204 \end_inset 
20205 </cell>
20206 </row>
20207 <row topline="true">
20208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20209 \begin_inset Text
20210
20211 \layout Standard
20212
20213 STREAM_MSSP
20214 \end_inset 
20215 </cell>
20216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20217 \begin_inset Text
20218
20219 \layout Standard
20220
20221
20222 \family typewriter 
20223 0x210000UL
20224 \end_inset 
20225 </cell>
20226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20227 \begin_inset Text
20228
20229 \layout Standard
20230
20231 MSSP
20232 \end_inset 
20233 </cell>
20234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20235 \begin_inset Text
20236
20237 \layout Standard
20238
20239 Writes/Reads characters via the MSSP peripheral
20240 \end_inset 
20241 </cell>
20242 </row>
20243 <row topline="true" bottomline="true">
20244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20245 \begin_inset Text
20246
20247 \layout Standard
20248
20249 STREAM_USER
20250 \end_inset 
20251 </cell>
20252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20253 \begin_inset Text
20254
20255 \layout Standard
20256
20257
20258 \family typewriter 
20259 0x2f0000UL
20260 \end_inset 
20261 </cell>
20262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20263 \begin_inset Text
20264
20265 \layout Standard
20266
20267 (none)
20268 \end_inset 
20269 </cell>
20270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20271 \begin_inset Text
20272
20273 \layout Standard
20274
20275 Writes/Reads characters via used defined functions
20276 \end_inset 
20277 </cell>
20278 </row>
20279 </lyxtabular>
20280
20281 \end_inset 
20282
20283
20284 \layout Standard
20285
20286 The stream identifiers are declared as macros in the stdio.h header.
20287 \layout Standard
20288
20289 In the libc library there exist the functions that are used to write to
20290  each of the above streams.
20291  These are
20292 \layout List
20293 \labelwidthstring 00.00.0000
20294
20295 _
20296 \begin_inset ERT
20297 status Collapsed
20298
20299 \layout Standard
20300
20301 \backslash 
20302 /
20303 \end_inset 
20304
20305 _stream_usart_putchar writes a character at the USART stream
20306 \layout List
20307 \labelwidthstring 00.00.0000
20308
20309 _
20310 \begin_inset ERT
20311 status Collapsed
20312
20313 \layout Standard
20314
20315 \backslash 
20316 /
20317 \end_inset 
20318
20319 _stream_mssp_putchar writes a character at the MSSP stream
20320 \layout List
20321 \labelwidthstring 00.00.0000
20322
20323 putchar dummy function.
20324  This writes a character to a user specified manner.
20325 \layout Standard
20326
20327 In order to increase performance 
20328 \emph on 
20329 putchar 
20330 \emph default 
20331 is declared in stdio.h as having its parameter in WREG (it has the wparam
20332  keyword).
20333  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
20334  in a user-friendly way.
20335  
20336 \emph on 
20337 arg
20338 \emph default 
20339  is the name of the variable that holds the character to print.
20340  An example follows:
20341 \layout LyX-Code
20342
20343 #include <pic18fregs.h>
20344 \newline 
20345 #include <stdio.h>
20346 \newline 
20347
20348 \newline 
20349 PUTCHAR( c )
20350 \layout LyX-Code
20351
20352 {
20353 \layout LyX-Code
20354
20355     PORTA = c;    /* dump character c to PORTA */
20356 \layout LyX-Code
20357
20358
20359 \newline 
20360
20361 \newline 
20362 void main(void)
20363 \layout LyX-Code
20364
20365 {
20366 \layout LyX-Code
20367
20368     stdout = STREAM_USER;    /* this is not necessary, since stdout points
20369 \layout LyX-Code
20370
20371                               * by default to STREAM_USER */
20372 \layout LyX-Code
20373
20374     printf (¨This is a printf test
20375 \backslash 
20376 n¨);
20377 \layout LyX-Code
20378
20379 }
20380 \layout LyX-Code
20381
20382 \layout Subsubsection
20383
20384 Printing functions
20385 \layout Standard
20386
20387 PIC16 contains an implementation of the printf-family of functions.
20388  There exist the following functions:
20389 \layout LyX-Code
20390
20391 extern unsigned int sprintf(char *buf, char *fmt, ...);
20392 \layout LyX-Code
20393
20394 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
20395 \layout LyX-Code
20396
20397 \layout LyX-Code
20398
20399 extern unsigned int printf(char *fmt, ...);
20400 \layout LyX-Code
20401
20402 extern unsigned int vprintf(char *fmt, va_lista ap);
20403 \layout LyX-Code
20404
20405 \layout LyX-Code
20406
20407 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
20408 \layout LyX-Code
20409
20410 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
20411 \layout Standard
20412
20413 For sprintf and vsprintf 
20414 \emph on 
20415 buf 
20416 \emph default 
20417 should normally be a data pointer where the resulting string will be placed.
20418  No range checking is done so the user should allocate the necessery buffer.
20419  For fprintf and vfprintf 
20420 \emph on 
20421 fp
20422 \emph default 
20423  should be a stream pointer (i.e.
20424  stdout, STREAM_MSSP, etc...).
20425 \layout Subsubsection
20426
20427 Signals
20428 \layout Standard
20429
20430 The PIC18F family of microcontrollers supports a number of interrupt sources.
20431  A list of these interrupts is shown in the following table:
20432 \layout Standard
20433 \align center 
20434
20435 \begin_inset  Tabular
20436 <lyxtabular version="3" rows="11" columns="4">
20437 <features>
20438 <column alignment="left" valignment="top" leftline="true" width="0">
20439 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20440 <column alignment="left" valignment="top" leftline="true" width="0">
20441 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20442 <row topline="true" bottomline="true">
20443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20444 \begin_inset Text
20445
20446 \layout Standard
20447
20448 signal name
20449 \end_inset 
20450 </cell>
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20452 \begin_inset Text
20453
20454 \layout Standard
20455
20456 description
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 signal name
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 descritpion
20473 \end_inset 
20474 </cell>
20475 </row>
20476 <row topline="true">
20477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20478 \begin_inset Text
20479
20480 \layout Standard
20481
20482 SIG_RB
20483 \end_inset 
20484 </cell>
20485 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20486 \begin_inset Text
20487
20488 \layout Standard
20489
20490 PORTB change interrupt
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 SIG_EE
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 EEPROM/FLASH write complete interrupt
20507 \end_inset 
20508 </cell>
20509 </row>
20510 <row topline="true">
20511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20512 \begin_inset Text
20513
20514 \layout Standard
20515
20516 SIG_INT0
20517 \end_inset 
20518 </cell>
20519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20520 \begin_inset Text
20521
20522 \layout Standard
20523
20524 INT0 external interrupt
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 SIG_BCOL
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 Bus collision interrupt
20541 \end_inset 
20542 </cell>
20543 </row>
20544 <row topline="true">
20545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20546 \begin_inset Text
20547
20548 \layout Standard
20549
20550 SIG_INT1
20551 \end_inset 
20552 </cell>
20553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20554 \begin_inset Text
20555
20556 \layout Standard
20557
20558 INT1 external interrupt
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 SIG_LVD
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 Low voltage detect interrupt
20575 \end_inset 
20576 </cell>
20577 </row>
20578 <row topline="true">
20579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20580 \begin_inset Text
20581
20582 \layout Standard
20583
20584 SIG_INT2
20585 \end_inset 
20586 </cell>
20587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20588 \begin_inset Text
20589
20590 \layout Standard
20591
20592 INT2 external interrupt
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 SIG_PSP
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 Parallel slave port interrupt
20609 \end_inset 
20610 </cell>
20611 </row>
20612 <row topline="true">
20613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20614 \begin_inset Text
20615
20616 \layout Standard
20617
20618 SIG_CCP1
20619 \end_inset 
20620 </cell>
20621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20622 \begin_inset Text
20623
20624 \layout Standard
20625
20626 CCP1 module interrupt
20627 \end_inset 
20628 </cell>
20629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20630 \begin_inset Text
20631
20632 \layout Standard
20633
20634 SIG_AD
20635 \end_inset 
20636 </cell>
20637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20638 \begin_inset Text
20639
20640 \layout Standard
20641
20642 AD convertion complete interrupt
20643 \end_inset 
20644 </cell>
20645 </row>
20646 <row topline="true">
20647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20648 \begin_inset Text
20649
20650 \layout Standard
20651
20652 SIG_CCP2
20653 \end_inset 
20654 </cell>
20655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20656 \begin_inset Text
20657
20658 \layout Standard
20659
20660 CCP2 module interrupt
20661 \end_inset 
20662 </cell>
20663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20664 \begin_inset Text
20665
20666 \layout Standard
20667
20668 SIG_RC
20669 \end_inset 
20670 </cell>
20671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20672 \begin_inset Text
20673
20674 \layout Standard
20675
20676 USART receive interrupt
20677 \end_inset 
20678 </cell>
20679 </row>
20680 <row topline="true">
20681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20682 \begin_inset Text
20683
20684 \layout Standard
20685
20686 SIG_TMR0
20687 \end_inset 
20688 </cell>
20689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20690 \begin_inset Text
20691
20692 \layout Standard
20693
20694 TMR0 overflow interrupt
20695 \end_inset 
20696 </cell>
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20698 \begin_inset Text
20699
20700 \layout Standard
20701
20702 SIG_TX
20703 \end_inset 
20704 </cell>
20705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20706 \begin_inset Text
20707
20708 \layout Standard
20709
20710 USART transmit interrupt
20711 \end_inset 
20712 </cell>
20713 </row>
20714 <row topline="true">
20715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20716 \begin_inset Text
20717
20718 \layout Standard
20719
20720 SIG_TMR1
20721 \end_inset 
20722 </cell>
20723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20724 \begin_inset Text
20725
20726 \layout Standard
20727
20728 TMR1 overflow interrupt
20729 \end_inset 
20730 </cell>
20731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20732 \begin_inset Text
20733
20734 \layout Standard
20735
20736 SIG_MSSP
20737 \end_inset 
20738 </cell>
20739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20740 \begin_inset Text
20741
20742 \layout Standard
20743
20744 SSP receive/transmit interrupt
20745 \end_inset 
20746 </cell>
20747 </row>
20748 <row topline="true">
20749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20750 \begin_inset Text
20751
20752 \layout Standard
20753
20754 SIG_TMR2
20755 \end_inset 
20756 </cell>
20757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20758 \begin_inset Text
20759
20760 \layout Standard
20761
20762 TMR2 matches PR2 interrupt
20763 \end_inset 
20764 </cell>
20765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20766 \begin_inset Text
20767
20768 \layout Standard
20769
20770 \end_inset 
20771 </cell>
20772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20773 \begin_inset Text
20774
20775 \layout Standard
20776
20777 \end_inset 
20778 </cell>
20779 </row>
20780 <row topline="true" bottomline="true">
20781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20782 \begin_inset Text
20783
20784 \layout Standard
20785
20786 SIG_TMR3
20787 \end_inset 
20788 </cell>
20789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20790 \begin_inset Text
20791
20792 \layout Standard
20793
20794 TMR3 overflow interrupt
20795 \end_inset 
20796 </cell>
20797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20798 \begin_inset Text
20799
20800 \layout Standard
20801
20802 \end_inset 
20803 </cell>
20804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20805 \begin_inset Text
20806
20807 \layout Standard
20808
20809 \end_inset 
20810 </cell>
20811 </row>
20812 </lyxtabular>
20813
20814 \end_inset 
20815
20816
20817 \layout Standard
20818
20819 The prototypes for these names are defined in the header file 
20820 \emph on 
20821 signal.h
20822 \emph default 
20823  .
20824 \layout Standard
20825
20826 In order to simplify signal handling, a number of macros is provided:
20827 \layout List
20828 \labelwidthstring 00.00.0000
20829
20830 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
20831  high priority interrupts.
20832  
20833 \emph on 
20834 name
20835 \emph default 
20836  is the function name to use.
20837 \layout List
20838 \labelwidthstring 00.00.0000
20839
20840 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
20841  low priority interrupt.
20842  
20843 \emph on 
20844 name
20845 \emph default 
20846  is the function name to use.
20847 \layout List
20848 \labelwidthstring 00.00.0000
20849
20850 DEF_HANDLER(sig,handler) define a handler for signal 
20851 \emph on 
20852 sig.
20853 \layout List
20854 \labelwidthstring 00.00.0000
20855
20856 END_DEF end the declaration of the dispatch table.
20857 \layout Standard
20858
20859 Additionally there are two more macros to simplify the declaration of the
20860  signal handler:
20861 \layout List
20862 \labelwidthstring 00.00.0000
20863
20864
20865 \series medium 
20866 SIGHANDLER(handler) 
20867 \series default 
20868 this declares the function prototype for the 
20869 \emph on 
20870 handler
20871 \emph default 
20872  function.
20873 \layout List
20874 \labelwidthstring 00.00.0000
20875
20876 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
20877 \layout Standard
20878
20879 An example of using the macros above is shown below:
20880 \layout LyX-Code
20881
20882 #include <pic18fregs.h>
20883 \layout LyX-Code
20884
20885 #include <signal.h>
20886 \newline 
20887
20888 \newline 
20889 DEF_INTHIGH(high_int)
20890 \layout LyX-Code
20891
20892 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
20893 \layout LyX-Code
20894
20895 DEF_HANDLER(SIG_BCOL, _bcol_handler)
20896 \layout LyX-Code
20897
20898 END_DEF
20899 \newline 
20900
20901 \newline 
20902 SIGHANDLER(_tmr0_handler)
20903 \layout LyX-Code
20904
20905 {
20906 \layout LyX-Code
20907
20908   /* action to be taken when timer 0 overflows */
20909 \layout LyX-Code
20910
20911 }
20912 \newline 
20913
20914 \newline 
20915 SIGHANDLERNAKED(_bcol_handler)
20916 \layout LyX-Code
20917
20918 {
20919 \layout LyX-Code
20920
20921   _asm
20922 \layout LyX-Code
20923
20924     /* action to be taken when bus collision occurs */
20925 \layout LyX-Code
20926
20927     retfie
20928 \layout LyX-Code
20929
20930  _endasm;
20931 \layout LyX-Code
20932
20933 }
20934 \layout Standard
20935
20936
20937 \series bold 
20938 NOTES:
20939 \series default 
20940  Special care should be taken when using the above scheme:
20941 \layout Itemize
20942
20943 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
20944 \layout Itemize
20945
20946 when declaring SIGHANDLERNAKED handler never forget to use 
20947 \emph on 
20948 retfie
20949 \emph default 
20950  for proper returning.
20951 \layout Subsection
20952
20953 PIC16 Port -- Tips
20954 \layout Standard
20955
20956 Here you can find some general tips for compiling programs with SDCC/pic16.
20957 \layout Subsubsection
20958
20959 Stack size
20960 \layout Standard
20961
20962 The default stack size (that is 64 bytes) probably is enough for many programs.
20963  One must take care that when there are many levels of function nesting,
20964  or there is excessive usage of stack, its size should be extended.
20965  An example of such a case is the printf/sprintf family of functions.
20966  If you encounter problems like not being able to print integers, then you
20967  need to set the stack size around the maximum (256 for small stack model).
20968  The following diagram shows what happens when calling printf to print an
20969  integer:
20970 \layout LyX-Code
20971
20972 printf () --> ltoa () --> ultoa () --> divschar ()
20973 \layout Standard
20974
20975 It is should be understood that stack is easily consumed when calling complicate
20976 d functions.
20977  Using command line arguments like -
20978 \begin_inset ERT
20979 status Collapsed
20980
20981 \layout Standard
20982
20983 \backslash 
20984 /
20985 \end_inset 
20986
20987 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
20988  stack frames.
20989  Other ways to reduce stack usage may exist.
20990 \layout Chapter
20991
20992 Debugging
20993 \layout Standard
20994
20995 There are several approaches to debugging your code.
20996  This chapter is meant to show your options and to give detail on some of
20997  them:
20998 \newline 
20999
21000 \newline 
21001 When writing your code:
21002 \layout Itemize
21003
21004 write your code with debugging in mind (avoid duplicating code, put conceptually
21005  similar variables into structs, use structured code, have strategic points
21006  within your code where all variables are consistent, ...)
21007 \layout Itemize
21008
21009 run a syntax-checking tool like splint
21010 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21011
21012 \end_inset 
21013
21014
21015 \begin_inset LatexCommand \index{lint (syntax checking tool)}
21016
21017 \end_inset 
21018
21019  (see -
21020 \begin_inset ERT
21021 status Collapsed
21022
21023 \layout Standard
21024
21025 \backslash 
21026 /
21027 \end_inset 
21028
21029 -more-pedantic 
21030 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21031
21032 \end_inset 
21033
21034 ) over the code.
21035 \layout Itemize
21036
21037 for the high level code use a C-compiler (like f.e.
21038  GCC) to compile run and debug the code on your host.
21039  See (see -
21040 \begin_inset ERT
21041 status Collapsed
21042
21043 \layout Standard
21044
21045 \backslash 
21046 /
21047 \end_inset 
21048
21049 -more-pedantic 
21050 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21051
21052 \end_inset 
21053
21054  ) on howto handle syntax extensions like __xdata, __at(), ...
21055  
21056 \layout Itemize
21057
21058 use another C-compiler to compile code for your target.
21059  Always an option but not recommended:) And not very likely to help you.
21060  If you seriously consider walking this path you should at least occasionally
21061  check portability of your code.
21062  Most commercial compiler vendors will offer an evaluation version so you
21063  can test compile your code or snippets of your code.
21064 \layout Standard
21065
21066 Debugging on a simulator:
21067 \layout Itemize
21068
21069 there is a separate section about SDCDB (section 
21070 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
21071
21072 \end_inset 
21073
21074 ) below.
21075 \layout Itemize
21076
21077 or (8051 specific) use a freeware/commercial simulator which interfaces
21078  to the AOMF
21079 \begin_inset LatexCommand \index{AOMF, AOMF51}
21080
21081 \end_inset 
21082
21083  file (see 
21084 \begin_inset LatexCommand \ref{OMF file}
21085
21086 \end_inset 
21087
21088 ) optionally generated by SDCC.
21089 \layout Standard
21090
21091 Debugging On-target: 
21092 \layout Itemize
21093
21094 use a MCU port pin to serially output debug data to the RS232 port of your
21095  host.
21096  You'll probably want some level shifting device typically involving a MAX232
21097  or similar IC.
21098  If the hardware serial port of the MCU is not available search for 'Software
21099  UART' in your favourite search machine.
21100 \layout Itemize
21101
21102 use an on-target monitor.
21103  In this context a monitor is a small program which usually accepts commands
21104  via a serial line and allows to set program counter, to single step through
21105  a program and read/write memory locations.
21106  For the 8051 good examples of monitors are paulmon and cmon51 (see section
21107  
21108 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
21109
21110 \end_inset 
21111
21112 ).
21113 \layout Itemize
21114
21115 toggle MCU port pins at strategic points within your code and use an oscilloscop
21116 e.
21117  A 
21118 \emph on 
21119 digital oscilloscope
21120 \emph default 
21121
21122 \begin_inset LatexCommand \index{oscilloscope}
21123
21124 \end_inset 
21125
21126  with deep trace memory is really helpful especially if you have to debug
21127  a realtime application.
21128  If you need to monitor more pins than your oscilloscope provides you can
21129  sometimes get away with a small R-2R network.
21130  On a single channel oscilloscope you could f.e.
21131  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
21132 k
21133 \begin_inset Formula $\Omega$
21134 \end_inset 
21135
21136  resistor and the other one by a 5\SpecialChar ~
21137 k
21138 \begin_inset Formula $\Omega$
21139 \end_inset 
21140
21141  resistor to the oscilloscope probe (check output drive capability of the
21142  pins you want to monitor).
21143  If you need to monitor many more pins a 
21144 \emph on 
21145 logic analyzer
21146 \emph default 
21147  will be handy.
21148 \layout Itemize
21149
21150 use an ICE (
21151 \emph on 
21152 i
21153 \emph default 
21154
21155 \emph on 
21156 c
21157 \emph default 
21158 ircuit 
21159 \emph on 
21160 e
21161 \emph default 
21162 mulator
21163 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
21164
21165 \end_inset 
21166
21167 ).
21168  Usually very expensive.
21169  And very nice to have too.
21170  And usually locks you (for years...) to the devices the ICE can emulate.
21171  
21172 \layout Itemize
21173
21174 use a remote debugger.
21175  In most 8-bit systems the symbol information is not available on the target,
21176  and a complete debugger is too bulky for the target system.
21177  Therefore usually a debugger on the host system connects to an on-target
21178  debugging stub which accepts only primitive commands.
21179  
21180 \newline 
21181 Terms to enter into your favourite search engine could be 'remote debugging',
21182  'gdb stub' or 'inferior debugger'.
21183  (is there one?)
21184 \layout Itemize
21185
21186 use an on target hardware debugger.
21187  Some of the more modern MCUs include hardware support for setting break
21188  points and monitoring/changing variables by using dedicated hardware pins.
21189  This facility doesn't require additional code to run on the target and
21190  
21191 \emph on 
21192 usually
21193 \emph default 
21194  doesn't affect runtime behaviour until a breakpoint is hit.
21195  For the mcs51 most hardware debuggers use the AOMF
21196 \begin_inset LatexCommand \index{AOMF, AOMF51}
21197
21198 \end_inset 
21199
21200  file (see 
21201 \begin_inset LatexCommand \ref{OMF file}
21202
21203 \end_inset 
21204
21205 ) as input file.
21206  
21207 \layout Standard
21208
21209 Last not least:
21210 \layout Itemize
21211
21212 if you are not familiar with any of the following terms you're likely to
21213  run into problems rather sooner than later: 
21214 \emph on 
21215 volatile
21216 \emph default 
21217
21218 \emph on 
21219 atomic
21220 \emph default 
21221
21222 \emph on 
21223 memory map
21224 \emph default 
21225
21226 \emph on 
21227 overlay
21228 \emph default 
21229 .
21230  As an embedded programmer you 
21231 \emph on 
21232 have
21233 \emph default 
21234  to know them so why not look them up 
21235 \emph on 
21236 before
21237 \emph default 
21238  you have problems?)
21239 \layout Itemize
21240
21241 tell someone else about your problem (actually this is a surprisingly effective
21242  means to hunt down the bug even if the listener is not familiar with your
21243  environment).
21244  As 'failure to communicate' is probably one of the job-induced deformations
21245  of an embedded programmer this is highly encouraged.
21246 \layout Section
21247
21248 Debugging with SDCDB
21249 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
21250
21251 \end_inset 
21252
21253
21254 \begin_inset LatexCommand \index{sdcdb (debugger)}
21255
21256 \end_inset 
21257
21258  
21259 \layout Standard
21260
21261 SDCC is distributed with a source level debugger
21262 \begin_inset LatexCommand \index{Debugger}
21263
21264 \end_inset 
21265
21266 .
21267  The debugger uses a command line interface, the command repertoire of the
21268  debugger has been kept as close to gdb
21269 \begin_inset LatexCommand \index{gdb}
21270
21271 \end_inset 
21272
21273  (the GNU debugger) as possible.
21274  The configuration and build process is part of the standard compiler installati
21275 on, which also builds and installs the debugger in the target directory
21276  specified during configuration.
21277  The debugger allows you debug BOTH at the C source and at the ASM source
21278  level.
21279  Sdcdb is currently not available on Win32 platforms.
21280 \layout Subsection
21281
21282 Compiling for Debugging
21283 \layout Standard
21284
21285 The -
21286 \begin_inset ERT
21287 status Collapsed
21288
21289 \layout Standard
21290
21291 \backslash 
21292 /
21293 \end_inset 
21294
21295 -debug
21296 \begin_inset LatexCommand \index{-\/-debug}
21297
21298 \end_inset 
21299
21300  option must be specified for all files for which debug information is to
21301  be generated.
21302  The compiler generates a .adb file for each of these files.
21303  The linker creates the .cdb
21304 \begin_inset LatexCommand \index{<file>.cdb}
21305
21306 \end_inset 
21307
21308  file from the .adb
21309 \begin_inset LatexCommand \index{<file>.adb}
21310
21311 \end_inset 
21312
21313  files and the address information.
21314  This .cdb is used by the debugger.
21315 \layout Subsection
21316
21317 How the Debugger Works
21318 \layout Standard
21319
21320 When the -
21321 \begin_inset ERT
21322 status Collapsed
21323
21324 \layout Standard
21325
21326 \backslash 
21327 /
21328 \end_inset 
21329
21330 -debug option is specified the compiler generates extra symbol information
21331  some of which are put into the assembler source and some are put into the
21332  .adb file.
21333  Then the linker creates the .cdb file from the individual .adb files with
21334  the address information for the symbols.
21335  The debugger reads the symbolic information generated by the compiler &
21336  the address information generated by the linker.
21337  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
21338  execution is controlled by the debugger.
21339  When a command is issued for the debugger, it translates it into appropriate
21340  commands for the simulator.
21341  (Currently sdcdb only connects to the simulator but 
21342 \emph on 
21343 newcdb
21344 \emph default 
21345  at 
21346 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
21347
21348 \end_inset 
21349
21350  is an effort to connect directly to the hardware.) 
21351 \layout Subsection
21352
21353 Starting the Debugger SDCDB
21354 \layout Standard
21355
21356 The debugger can be started using the following command line.
21357  (Assume the file you are debugging has the file name foo).
21358 \newline 
21359
21360 \newline 
21361
21362 \family sans 
21363 \series bold 
21364 sdcdb foo
21365 \newline 
21366
21367 \family default 
21368 \series default 
21369
21370 \newline 
21371 The debugger will look for the following files.
21372 \layout Itemize
21373
21374 foo.c - the source file.
21375 \layout Itemize
21376
21377 foo.cdb - the debugger symbol information file.
21378 \layout Itemize
21379
21380 foo.ihx - the Intel hex format
21381 \begin_inset LatexCommand \index{Intel hex format}
21382
21383 \end_inset 
21384
21385  object file.
21386 \layout Subsection
21387
21388 SDCDB Command Line Options
21389 \layout Itemize
21390
21391 -
21392 \begin_inset ERT
21393 status Collapsed
21394
21395 \layout Standard
21396
21397 \backslash 
21398 /
21399 \end_inset 
21400
21401 -directory=<source file directory> this option can used to specify the directory
21402  search list.
21403  The debugger will look into the directory list specified for source, cdb
21404  & ihx files.
21405  The items in the directory list must be separated by ':', e.g.
21406  if the source files can be in the directories /home/src1 and /home/src2,
21407  the -
21408 \begin_inset ERT
21409 status Collapsed
21410
21411 \layout Standard
21412
21413 \backslash 
21414 /
21415 \end_inset 
21416
21417 -directory option should be -
21418 \begin_inset ERT
21419 status Collapsed
21420
21421 \layout Standard
21422
21423 \backslash 
21424 /
21425 \end_inset 
21426
21427 -directory=/home/src1:/home/src2.
21428  Note there can be no spaces in the option.
21429  
21430 \layout Itemize
21431
21432 -cd <directory> - change to the <directory>.
21433 \layout Itemize
21434
21435 -fullname - used by GUI front ends.
21436 \layout Itemize
21437
21438 -cpu <cpu-type> - this argument is passed to the simulator please see the
21439  simulator docs for details.
21440 \layout Itemize
21441
21442 -X <Clock frequency > this options is passed to the simulator please see
21443  the simulator docs for details.
21444 \layout Itemize
21445
21446 -s <serial port file> passed to simulator see the simulator docs for details.
21447 \layout Itemize
21448
21449 -S <serial in,out> passed to simulator see the simulator docs for details.
21450 \layout Itemize
21451
21452 -k <port number> passed to simulator see the simulator docs for details.
21453 \layout Subsection
21454
21455 SDCDB Debugger Commands
21456 \layout Standard
21457
21458 As mentioned earlier the command interface for the debugger has been deliberatel
21459 y kept as close the GNU debugger gdb, as possible.
21460  This will help the integration with existing graphical user interfaces
21461  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
21462  If you use a graphical user interface for the debugger you can skip this
21463  section.
21464 \layout Subsubsection*
21465
21466 break [line | file:line | function | file:function]
21467 \layout Standard
21468
21469 Set breakpoint at specified line or function:
21470 \newline 
21471
21472 \newline 
21473
21474 \family sans 
21475 \series bold 
21476 sdcdb>break 100 
21477 \newline 
21478 sdcdb>break foo.c:100
21479 \newline 
21480 sdcdb>break funcfoo
21481 \newline 
21482 sdcdb>break foo.c:funcfoo
21483 \layout Subsubsection*
21484
21485 clear [line | file:line | function | file:function ]
21486 \layout Standard
21487
21488 Clear breakpoint at specified line or function:
21489 \newline 
21490
21491 \newline 
21492
21493 \family sans 
21494 \series bold 
21495 sdcdb>clear 100
21496 \newline 
21497 sdcdb>clear foo.c:100
21498 \newline 
21499 sdcdb>clear funcfoo
21500 \newline 
21501 sdcdb>clear foo.c:funcfoo
21502 \layout Subsubsection*
21503
21504 continue
21505 \layout Standard
21506
21507 Continue program being debugged, after breakpoint.
21508 \layout Subsubsection*
21509
21510 finish
21511 \layout Standard
21512
21513 Execute till the end of the current function.
21514 \layout Subsubsection*
21515
21516 delete [n]
21517 \layout Standard
21518
21519 Delete breakpoint number 'n'.
21520  If used without any option clear ALL user defined break points.
21521 \layout Subsubsection*
21522
21523 info [break | stack | frame | registers ]
21524 \layout Itemize
21525
21526 info break - list all breakpoints
21527 \layout Itemize
21528
21529 info stack - show the function call stack.
21530 \layout Itemize
21531
21532 info frame - show information about the current execution frame.
21533 \layout Itemize
21534
21535 info registers - show content of all registers.
21536 \layout Subsubsection*
21537
21538 step
21539 \layout Standard
21540
21541 Step program until it reaches a different source line.
21542  Note: pressing <return> repeats the last command.
21543 \layout Subsubsection*
21544
21545 next
21546 \layout Standard
21547
21548 Step program, proceeding through subroutine calls.
21549 \layout Subsubsection*
21550
21551 run
21552 \layout Standard
21553
21554 Start debugged program.
21555 \layout Subsubsection*
21556
21557 ptype variable 
21558 \layout Standard
21559
21560 Print type information of the variable.
21561 \layout Subsubsection*
21562
21563 print variable
21564 \layout Standard
21565
21566 print value of variable.
21567 \layout Subsubsection*
21568
21569 file filename
21570 \layout Standard
21571
21572 load the given file name.
21573  Note this is an alternate method of loading file for debugging.
21574 \layout Subsubsection*
21575
21576 frame
21577 \layout Standard
21578
21579 print information about current frame.
21580 \layout Subsubsection*
21581
21582 set srcmode
21583 \layout Standard
21584
21585 Toggle between C source & assembly source.
21586 \layout Subsubsection*
21587
21588 ! simulator command
21589 \layout Standard
21590
21591 Send the string following '!' to the simulator, the simulator response is
21592  displayed.
21593  Note the debugger does not interpret the command being sent to the simulator,
21594  so if a command like 'go' is sent the debugger can loose its execution
21595  context and may display incorrect values.
21596 \layout Subsubsection*
21597
21598 quit
21599 \layout Standard
21600
21601 "Watch me now.
21602  Iam going Down.
21603  My name is Bobby Brown"
21604 \layout Subsection
21605
21606 Interfacing SDCDB with DDD
21607 \layout Comment
21608
21609 The screenshot was converted from png to eps with: 
21610 \begin_inset Quotes sld
21611 \end_inset 
21612
21613 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
21614 \begin_inset Quotes srd
21615 \end_inset 
21616
21617  which produces a pretty compact eps file which is free from compression
21618  artifacts.
21619 \layout Comment
21620
21621 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
21622  as this broke the build system on Sourceforge (pdf-file was broken).
21623 \layout Standard
21624
21625 The .eps File 
21626 \size footnotesize 
21627
21628 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.eps}
21629
21630 \end_inset 
21631
21632
21633 \size default 
21634  shows a screenshot of a debugging session with DDD
21635 \begin_inset LatexCommand \index{DDD (debugger)}
21636
21637 \end_inset 
21638
21639  (Unix only) on a simulated 8032.
21640  The debugging session might not run as smoothly as the screenshot suggests.
21641  The debugger allows setting of breakpoints, displaying and changing variables,
21642  single stepping through C and assembler code.
21643  
21644 \newline 
21645 The source was compiled with 
21646 \family sans 
21647 \series bold 
21648
21649 \newline 
21650
21651 \newline 
21652 sdcc -
21653 \family default 
21654 \series default 
21655
21656 \begin_inset ERT
21657 status Collapsed
21658
21659 \layout Standard
21660
21661 \backslash 
21662 /
21663 \end_inset 
21664
21665
21666 \family sans 
21667 \series bold 
21668 -debug ddd_example.c
21669 \family default 
21670 \series default 
21671  
21672 \family sans 
21673 \series bold 
21674
21675 \newline 
21676
21677 \family default 
21678 \series default 
21679
21680 \newline 
21681 and DDD was invoked with 
21682 \family sans 
21683 \series bold 
21684
21685 \newline 
21686
21687 \newline 
21688 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
21689 \layout Subsection
21690
21691 Interfacing SDCDB with XEmacs
21692 \begin_inset LatexCommand \index{XEmacs}
21693
21694 \end_inset 
21695
21696
21697 \begin_inset LatexCommand \index{Emacs}
21698
21699 \end_inset 
21700
21701
21702 \layout Standard
21703
21704 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
21705  sdcdb.el and sdcdbsrc.el.
21706  These two files can be found in the $(prefix)/bin directory after the installat
21707 ion is complete.
21708  These files need to be loaded into XEmacs for the interface to work.
21709  This can be done at XEmacs startup time by inserting the following into
21710  your '.xemacs' file (which can be found in your HOME directory): 
21711 \newline 
21712
21713 \newline 
21714
21715 \family typewriter 
21716 (load-file sdcdbsrc.el) 
21717 \family default 
21718
21719 \newline 
21720
21721 \newline 
21722 .xemacs is a lisp file so the () around the command is REQUIRED.
21723  The files can also be loaded dynamically while XEmacs is running, set the
21724  environment variable 'EMACSLOADPATH' to the installation bin directory
21725  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
21726  To start the interface enter the following command: 
21727 \newline 
21728
21729 \newline 
21730
21731 \family sans 
21732 \series bold 
21733 ESC-x sdcdbsrc
21734 \family default 
21735 \series default 
21736
21737 \newline 
21738
21739 \newline 
21740 You will prompted to enter the file name to be debugged.
21741  
21742 \newline 
21743
21744 \newline 
21745 The command line options that are passed to the simulator directly are bound
21746  to default values in the file sdcdbsrc.el.
21747  The variables are listed below, these values maybe changed as required.
21748 \layout Itemize
21749
21750 sdcdbsrc-cpu-type '51
21751 \layout Itemize
21752
21753 sdcdbsrc-frequency '11059200
21754 \layout Itemize
21755
21756 sdcdbsrc-serial nil
21757 \layout Standard
21758
21759 The following is a list of key mapping for the debugger interface.
21760 \layout Standard
21761
21762 \SpecialChar ~
21763
21764 \family typewriter 
21765
21766 \newline 
21767 ;;\SpecialChar ~
21768 Current Listing :: 
21769 \newline 
21770 ;;key\SpecialChar ~
21771 \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 binding\SpecialChar ~
21785 \SpecialChar ~
21786 \SpecialChar ~
21787 \SpecialChar ~
21788 \SpecialChar ~
21789 \SpecialChar ~
21790 \SpecialChar ~
21791 \SpecialChar ~
21792 \SpecialChar ~
21793 \SpecialChar ~
21794 \SpecialChar ~
21795 \SpecialChar ~
21796 \SpecialChar ~
21797 \SpecialChar ~
21798 \SpecialChar ~
21799 \SpecialChar ~
21800 \SpecialChar ~
21801 \SpecialChar ~
21802 \SpecialChar ~
21803 \SpecialChar ~
21804 \SpecialChar ~
21805 \SpecialChar ~
21806 Comment 
21807 \newline 
21808 ;;---\SpecialChar ~
21809 \SpecialChar ~
21810 \SpecialChar ~
21811 \SpecialChar ~
21812 \SpecialChar ~
21813 \SpecialChar ~
21814 \SpecialChar ~
21815 \SpecialChar ~
21816 \SpecialChar ~
21817 \SpecialChar ~
21818 \SpecialChar ~
21819 \SpecialChar ~
21820 \SpecialChar ~
21821 \SpecialChar ~
21822 -------\SpecialChar ~
21823 \SpecialChar ~
21824 \SpecialChar ~
21825 \SpecialChar ~
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 -------
21845 \newline 
21846 ;; 
21847 \newline 
21848 ;;\SpecialChar ~
21849 n\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 sdcdb-next-from-src\SpecialChar ~
21865 \SpecialChar ~
21866 \SpecialChar ~
21867 \SpecialChar ~
21868 \SpecialChar ~
21869 \SpecialChar ~
21870 \SpecialChar ~
21871 \SpecialChar ~
21872 \SpecialChar ~
21873 \SpecialChar ~
21874 SDCDB next command 
21875 \newline 
21876 ;;\SpecialChar ~
21877 b\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 \SpecialChar ~
21892 sdcdb-back-from-src\SpecialChar ~
21893 \SpecialChar ~
21894 \SpecialChar ~
21895 \SpecialChar ~
21896 \SpecialChar ~
21897 \SpecialChar ~
21898 \SpecialChar ~
21899 \SpecialChar ~
21900 \SpecialChar ~
21901 \SpecialChar ~
21902 SDCDB back command 
21903 \newline 
21904 ;;\SpecialChar ~
21905 c\SpecialChar ~
21906 \SpecialChar ~
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 sdcdb-cont-from-src\SpecialChar ~
21921 \SpecialChar ~
21922 \SpecialChar ~
21923 \SpecialChar ~
21924 \SpecialChar ~
21925 \SpecialChar ~
21926 \SpecialChar ~
21927 \SpecialChar ~
21928 \SpecialChar ~
21929 \SpecialChar ~
21930 SDCDB continue command
21931 \newline 
21932 ;;\SpecialChar ~
21933 s\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 sdcdb-step-from-src\SpecialChar ~
21949 \SpecialChar ~
21950 \SpecialChar ~
21951 \SpecialChar ~
21952 \SpecialChar ~
21953 \SpecialChar ~
21954 \SpecialChar ~
21955 \SpecialChar ~
21956 \SpecialChar ~
21957 \SpecialChar ~
21958 SDCDB step command 
21959 \newline 
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 \SpecialChar ~
21973 \SpecialChar ~
21974 \SpecialChar ~
21975 \SpecialChar ~
21976 sdcdb-whatis-c-sexp\SpecialChar ~
21977 \SpecialChar ~
21978 \SpecialChar ~
21979 \SpecialChar ~
21980 \SpecialChar ~
21981 \SpecialChar ~
21982 \SpecialChar ~
21983 \SpecialChar ~
21984 \SpecialChar ~
21985 \SpecialChar ~
21986 SDCDB ptypecommand for data at 
21987 \newline 
21988 ;;\SpecialChar ~
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 buffer point 
22036 \newline 
22037 ;;\SpecialChar ~
22038 x\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 sdcdbsrc-delete\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 SDCDB Delete all breakpoints if no arg 
22068 \newline 
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 \SpecialChar ~
22086 \SpecialChar ~
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 \SpecialChar ~
22104 \SpecialChar ~
22105 \SpecialChar ~
22106 \SpecialChar ~
22107 \SpecialChar ~
22108 \SpecialChar ~
22109 \SpecialChar ~
22110 \SpecialChar ~
22111 \SpecialChar ~
22112 \SpecialChar ~
22113 \SpecialChar ~
22114 \SpecialChar ~
22115 \SpecialChar ~
22116 given or delete arg (C-u arg x) 
22117 \newline 
22118 ;;\SpecialChar ~
22119 m\SpecialChar ~
22120 \SpecialChar ~
22121 \SpecialChar ~
22122 \SpecialChar ~
22123 \SpecialChar ~
22124 \SpecialChar ~
22125 \SpecialChar ~
22126 \SpecialChar ~
22127 \SpecialChar ~
22128 \SpecialChar ~
22129 \SpecialChar ~
22130 \SpecialChar ~
22131 \SpecialChar ~
22132 \SpecialChar ~
22133 \SpecialChar ~
22134 sdcdbsrc-frame\SpecialChar ~
22135 \SpecialChar ~
22136 \SpecialChar ~
22137 \SpecialChar ~
22138 \SpecialChar ~
22139 \SpecialChar ~
22140 \SpecialChar ~
22141 \SpecialChar ~
22142 \SpecialChar ~
22143 \SpecialChar ~
22144 \SpecialChar ~
22145 \SpecialChar ~
22146 \SpecialChar ~
22147 \SpecialChar ~
22148 \SpecialChar ~
22149 SDCDB Display current frame if no arg, 
22150 \newline 
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 \SpecialChar ~
22192 \SpecialChar ~
22193 \SpecialChar ~
22194 \SpecialChar ~
22195 \SpecialChar ~
22196 \SpecialChar ~
22197 \SpecialChar ~
22198 given or display frame arg 
22199 \newline 
22200 ;;\SpecialChar ~
22201 \SpecialChar ~
22202 \SpecialChar ~
22203 \SpecialChar ~
22204 \SpecialChar ~
22205 \SpecialChar ~
22206 \SpecialChar ~
22207 \SpecialChar ~
22208 \SpecialChar ~
22209 \SpecialChar ~
22210 \SpecialChar ~
22211 \SpecialChar ~
22212 \SpecialChar ~
22213 \SpecialChar ~
22214 \SpecialChar ~
22215 \SpecialChar ~
22216 \SpecialChar ~
22217 \SpecialChar ~
22218 \SpecialChar ~
22219 \SpecialChar ~
22220 \SpecialChar ~
22221 \SpecialChar ~
22222 \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 \SpecialChar ~
22238 \SpecialChar ~
22239 \SpecialChar ~
22240 \SpecialChar ~
22241 \SpecialChar ~
22242 \SpecialChar ~
22243 \SpecialChar ~
22244 \SpecialChar ~
22245 \SpecialChar ~
22246 \SpecialChar ~
22247 buffer point 
22248 \newline 
22249 ;;\SpecialChar ~
22250 !\SpecialChar ~
22251 \SpecialChar ~
22252 \SpecialChar ~
22253 \SpecialChar ~
22254 \SpecialChar ~
22255 \SpecialChar ~
22256 \SpecialChar ~
22257 \SpecialChar ~
22258 \SpecialChar ~
22259 \SpecialChar ~
22260 \SpecialChar ~
22261 \SpecialChar ~
22262 \SpecialChar ~
22263 \SpecialChar ~
22264 \SpecialChar ~
22265 sdcdbsrc-goto-sdcdb\SpecialChar ~
22266 \SpecialChar ~
22267 \SpecialChar ~
22268 \SpecialChar ~
22269 \SpecialChar ~
22270 \SpecialChar ~
22271 \SpecialChar ~
22272 \SpecialChar ~
22273 \SpecialChar ~
22274 \SpecialChar ~
22275 Goto the SDCDB output buffer 
22276 \newline 
22277 ;;\SpecialChar ~
22278 p\SpecialChar ~
22279 \SpecialChar ~
22280 \SpecialChar ~
22281 \SpecialChar ~
22282 \SpecialChar ~
22283 \SpecialChar ~
22284 \SpecialChar ~
22285 \SpecialChar ~
22286 \SpecialChar ~
22287 \SpecialChar ~
22288 \SpecialChar ~
22289 \SpecialChar ~
22290 \SpecialChar ~
22291 \SpecialChar ~
22292 \SpecialChar ~
22293 sdcdb-print-c-sexp\SpecialChar ~
22294 \SpecialChar ~
22295 \SpecialChar ~
22296 \SpecialChar ~
22297 \SpecialChar ~
22298 \SpecialChar ~
22299 \SpecialChar ~
22300 \SpecialChar ~
22301 \SpecialChar ~
22302 \SpecialChar ~
22303 \SpecialChar ~
22304 SDCDB print command for data at 
22305 \newline 
22306 ;;\SpecialChar ~
22307 \SpecialChar ~
22308 \SpecialChar ~
22309 \SpecialChar ~
22310 \SpecialChar ~
22311 \SpecialChar ~
22312 \SpecialChar ~
22313 \SpecialChar ~
22314 \SpecialChar ~
22315 \SpecialChar ~
22316 \SpecialChar ~
22317 \SpecialChar ~
22318 \SpecialChar ~
22319 \SpecialChar ~
22320 \SpecialChar ~
22321 \SpecialChar ~
22322 \SpecialChar ~
22323 \SpecialChar ~
22324 \SpecialChar ~
22325 \SpecialChar ~
22326 \SpecialChar ~
22327 \SpecialChar ~
22328 \SpecialChar ~
22329 \SpecialChar ~
22330 \SpecialChar ~
22331 \SpecialChar ~
22332 \SpecialChar ~
22333 \SpecialChar ~
22334 \SpecialChar ~
22335 \SpecialChar ~
22336 \SpecialChar ~
22337 \SpecialChar ~
22338 \SpecialChar ~
22339 \SpecialChar ~
22340 \SpecialChar ~
22341 \SpecialChar ~
22342 \SpecialChar ~
22343 \SpecialChar ~
22344 \SpecialChar ~
22345 \SpecialChar ~
22346 \SpecialChar ~
22347 \SpecialChar ~
22348 \SpecialChar ~
22349 \SpecialChar ~
22350 \SpecialChar ~
22351 \SpecialChar ~
22352 \SpecialChar ~
22353 buffer point 
22354 \newline 
22355 ;;\SpecialChar ~
22356 g\SpecialChar ~
22357 \SpecialChar ~
22358 \SpecialChar ~
22359 \SpecialChar ~
22360 \SpecialChar ~
22361 \SpecialChar ~
22362 \SpecialChar ~
22363 \SpecialChar ~
22364 \SpecialChar ~
22365 \SpecialChar ~
22366 \SpecialChar ~
22367 \SpecialChar ~
22368 \SpecialChar ~
22369 \SpecialChar ~
22370 \SpecialChar ~
22371 sdcdbsrc-goto-sdcdb\SpecialChar ~
22372 \SpecialChar ~
22373 \SpecialChar ~
22374 \SpecialChar ~
22375 \SpecialChar ~
22376 \SpecialChar ~
22377 \SpecialChar ~
22378 \SpecialChar ~
22379 \SpecialChar ~
22380 \SpecialChar ~
22381 Goto the SDCDB output buffer 
22382 \newline 
22383 ;;\SpecialChar ~
22384 t\SpecialChar ~
22385 \SpecialChar ~
22386 \SpecialChar ~
22387 \SpecialChar ~
22388 \SpecialChar ~
22389 \SpecialChar ~
22390 \SpecialChar ~
22391 \SpecialChar ~
22392 \SpecialChar ~
22393 \SpecialChar ~
22394 \SpecialChar ~
22395 \SpecialChar ~
22396 \SpecialChar ~
22397 \SpecialChar ~
22398 \SpecialChar ~
22399 sdcdbsrc-mode\SpecialChar ~
22400 \SpecialChar ~
22401 \SpecialChar ~
22402 \SpecialChar ~
22403 \SpecialChar ~
22404 \SpecialChar ~
22405 \SpecialChar ~
22406 \SpecialChar ~
22407 \SpecialChar ~
22408 \SpecialChar ~
22409 \SpecialChar ~
22410 \SpecialChar ~
22411 \SpecialChar ~
22412 \SpecialChar ~
22413 \SpecialChar ~
22414 \SpecialChar ~
22415 Toggles Sdcdbsrc mode (turns it off) 
22416 \newline 
22417 ;; 
22418 \newline 
22419 ;;\SpecialChar ~
22420 C-c\SpecialChar ~
22421 C-f\SpecialChar ~
22422 \SpecialChar ~
22423 \SpecialChar ~
22424 \SpecialChar ~
22425 \SpecialChar ~
22426 \SpecialChar ~
22427 \SpecialChar ~
22428 \SpecialChar ~
22429 \SpecialChar ~
22430 sdcdb-finish-from-src\SpecialChar ~
22431 \SpecialChar ~
22432 \SpecialChar ~
22433 \SpecialChar ~
22434 \SpecialChar ~
22435 \SpecialChar ~
22436 \SpecialChar ~
22437 \SpecialChar ~
22438 SDCDB finish command 
22439 \newline 
22440 ;; 
22441 \newline 
22442 ;;\SpecialChar ~
22443 C-x\SpecialChar ~
22444 SPC\SpecialChar ~
22445 \SpecialChar ~
22446 \SpecialChar ~
22447 \SpecialChar ~
22448 \SpecialChar ~
22449 \SpecialChar ~
22450 \SpecialChar ~
22451 \SpecialChar ~
22452 \SpecialChar ~
22453 sdcdb-break\SpecialChar ~
22454 \SpecialChar ~
22455 \SpecialChar ~
22456 \SpecialChar ~
22457 \SpecialChar ~
22458 \SpecialChar ~
22459 \SpecialChar ~
22460 \SpecialChar ~
22461 \SpecialChar ~
22462 \SpecialChar ~
22463 \SpecialChar ~
22464 \SpecialChar ~
22465 \SpecialChar ~
22466 \SpecialChar ~
22467 \SpecialChar ~
22468 \SpecialChar ~
22469 \SpecialChar ~
22470 \SpecialChar ~
22471 Set break for line with point 
22472 \newline 
22473 ;;\SpecialChar ~
22474 ESC\SpecialChar ~
22475 t\SpecialChar ~
22476 \SpecialChar ~
22477 \SpecialChar ~
22478 \SpecialChar ~
22479 \SpecialChar ~
22480 \SpecialChar ~
22481 \SpecialChar ~
22482 \SpecialChar ~
22483 \SpecialChar ~
22484 \SpecialChar ~
22485 \SpecialChar ~
22486 sdcdbsrc-mode\SpecialChar ~
22487 \SpecialChar ~
22488 \SpecialChar ~
22489 \SpecialChar ~
22490 \SpecialChar ~
22491 \SpecialChar ~
22492 \SpecialChar ~
22493 \SpecialChar ~
22494 \SpecialChar ~
22495 \SpecialChar ~
22496 \SpecialChar ~
22497 \SpecialChar ~
22498 \SpecialChar ~
22499 \SpecialChar ~
22500 \SpecialChar ~
22501 \SpecialChar ~
22502 Toggle Sdcdbsrc mode 
22503 \newline 
22504 ;;\SpecialChar ~
22505 ESC\SpecialChar ~
22506 m\SpecialChar ~
22507 \SpecialChar ~
22508 \SpecialChar ~
22509 \SpecialChar ~
22510 \SpecialChar ~
22511 \SpecialChar ~
22512 \SpecialChar ~
22513 \SpecialChar ~
22514 \SpecialChar ~
22515 \SpecialChar ~
22516 \SpecialChar ~
22517 sdcdbsrc-srcmode\SpecialChar ~
22518 \SpecialChar ~
22519 \SpecialChar ~
22520 \SpecialChar ~
22521 \SpecialChar ~
22522 \SpecialChar ~
22523 \SpecialChar ~
22524 \SpecialChar ~
22525 \SpecialChar ~
22526 \SpecialChar ~
22527 \SpecialChar ~
22528 \SpecialChar ~
22529 \SpecialChar ~
22530 Toggle list mode 
22531 \newline 
22532 ;; 
22533 \newline 
22534
22535 \layout Chapter
22536 \pagebreak_top 
22537 TIPS
22538 \layout Standard
22539
22540 Here are a few guidelines that will help the compiler generate more efficient
22541  code, some of the tips are specific to this compiler others are generally
22542  good programming practice.
22543 \layout Itemize
22544
22545 Use the smallest data type to represent your data-value.
22546  If it is known in advance that the value is going to be less than 256 then
22547  use an 'unsigned char' instead of a 'short' or 'int'.
22548  Please note, that ANSI C requires both signed and unsigned chars to be
22549  promoted to 'signed int'
22550 \begin_inset LatexCommand \index{promotion to signed int}
22551
22552 \end_inset 
22553
22554  before doing any operation.
22555  This promotion
22556 \begin_inset LatexCommand \index{type promotion}
22557
22558 \end_inset 
22559
22560
22561 \begin_inset LatexCommand \label{type promotion}
22562
22563 \end_inset 
22564
22565  can be omitted, if the result is the same.
22566  The effect of the promotion rules together with the sign-extension is often
22567  surprising:
22568 \begin_deeper 
22569 \layout Verse
22570
22571
22572 \family typewriter 
22573 unsigned char uc = 0xfe;
22574 \newline 
22575 if (uc * uc < 0) /* this is true! */
22576 \newline 
22577 {
22578 \newline 
22579 \SpecialChar ~
22580 \SpecialChar ~
22581 \SpecialChar ~
22582 \SpecialChar ~
22583 ....
22584 \newline 
22585 }
22586 \layout Standard
22587
22588
22589 \family typewriter 
22590 uc * uc
22591 \family default 
22592  is evaluated as 
22593 \family typewriter 
22594 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
22595 \family default 
22596 .
22597  
22598 \newline 
22599 Another one:
22600 \layout Verse
22601
22602
22603 \family typewriter 
22604 (unsigned char) -12 / (signed char) -3 = ...
22605 \layout Standard
22606
22607 No, the result is not 4:
22608 \layout Verse
22609
22610
22611 \family typewriter 
22612 (int) (unsigned char) -12 / (int) (signed char) -3 =
22613 \newline 
22614 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
22615 \newline 
22616 (int) 0x00f4 / (int) 0xfffd =
22617 \newline 
22618 (int) 0x00f4 / (int) 0xfffd =
22619 \newline 
22620 (int) 244 / (int) -3 =
22621 \newline 
22622 (int) -81 = (int) 0xffaf;
22623 \layout Standard
22624
22625 Don't complain, that gcc gives you a different result.
22626  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
22627  Therefore the results are different.
22628 \newline 
22629 From 
22630 \begin_inset Quotes sld
22631 \end_inset 
22632
22633 comp.lang.c FAQ
22634 \begin_inset Quotes srd
22635 \end_inset 
22636
22637 :
22638 \layout Quote
22639
22640 If well-defined overflow characteristics are important and negative values
22641  are not, or if you want to steer clear of sign-extension problems when
22642  manipulating bits or bytes, use one of the corresponding unsigned types.
22643  (Beware when mixing signed and unsigned values in expressions, though.)
22644 \newline 
22645 Although character types (especially unsigned char) can be used as "tiny"
22646  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
22647 ble sign extension and increased code size.
22648 \end_deeper 
22649 \layout Itemize
22650
22651 Use unsigned when it is known in advance that the value is not going to
22652  be negative.
22653  This helps especially if you are doing division or multiplication, bit-shifting
22654  or are using an array index.
22655 \layout Itemize
22656
22657 NEVER jump into a LOOP.
22658 \layout Itemize
22659
22660 Declare the variables to be local
22661 \begin_inset LatexCommand \index{local variables}
22662
22663 \end_inset 
22664
22665  whenever possible, especially loop control variables (induction).
22666 \layout Itemize
22667
22668 Since the compiler does not always do implicit integral promotion, the programme
22669 r should do an explicit cast when integral promotion is required.
22670 \layout Itemize
22671
22672 Reducing the size of division, multiplication & modulus operations can reduce
22673  code size substantially.
22674  Take the following code for example.
22675 \begin_deeper 
22676 \layout Verse
22677
22678
22679 \family typewriter 
22680 foobar(unsigned int p1, unsigned char ch)
22681 \newline 
22682 {
22683 \newline 
22684 \SpecialChar ~
22685 \SpecialChar ~
22686 \SpecialChar ~
22687 \SpecialChar ~
22688 unsigned char ch1 = p1 % ch ;
22689 \newline 
22690 \SpecialChar ~
22691 \SpecialChar ~
22692 \SpecialChar ~
22693 \SpecialChar ~
22694 ....
22695 \newline 
22696 }
22697 \layout Standard
22698
22699 For the modulus operation the variable ch will be promoted to unsigned int
22700  first then the modulus operation will be performed (this will lead to a
22701  call to support routine _moduint()), and the result will be casted to a
22702  char.
22703  If the code is changed to 
22704 \layout Verse
22705
22706
22707 \family typewriter 
22708 foobar(unsigned int p1, unsigned char ch)
22709 \newline 
22710 {
22711 \newline 
22712 \SpecialChar ~
22713 \SpecialChar ~
22714 \SpecialChar ~
22715 \SpecialChar ~
22716 unsigned char ch1 = (unsigned char)p1 % ch ;
22717 \newline 
22718 \SpecialChar ~
22719 \SpecialChar ~
22720 \SpecialChar ~
22721 \SpecialChar ~
22722 ....
22723 \newline 
22724 }
22725 \layout Standard
22726
22727 It would substantially reduce the code generated (future versions of the
22728  compiler will be smart enough to detect such optimization opportunities).
22729 \end_deeper 
22730 \layout Itemize
22731
22732 Have a look at the assembly listing to get a 
22733 \begin_inset Quotes sld
22734 \end_inset 
22735
22736 feeling
22737 \begin_inset Quotes srd
22738 \end_inset 
22739
22740  for the code generation.
22741 \layout Section
22742
22743 Porting code from or to other compilers
22744 \layout Itemize
22745
22746 check whether endianness of the compilers differs and adapt where needed.
22747 \layout Itemize
22748
22749 check the device specific header files for compiler specific syntax.
22750  Eventually include the file <compiler.h
22751 \begin_inset LatexCommand \index{compiler.h (include file)}
22752
22753 \end_inset 
22754
22755 > to allow using common header files.
22756 \layout Itemize
22757
22758 check whether the startup code contains the correct initialization (watchdog,
22759  peripherals).
22760 \layout Itemize
22761
22762 check whether the sizes of short, int, long match.
22763 \layout Itemize
22764
22765 check if some 16 or 32 bit hardware registers require a specific addressing
22766  order (least significant or most significant byte first) and adapt if needed
22767  (
22768 \emph on 
22769 first
22770 \emph default 
22771  and 
22772 \emph on 
22773 last
22774 \emph default 
22775  relate to time and not to lower/upper memory location here, so this is
22776  
22777 \emph on 
22778 not
22779 \emph default 
22780  the same as endianness).
22781 \layout Itemize
22782
22783 check whether the keyword 
22784 \emph on 
22785 volatile
22786 \emph default 
22787  is used where needed.
22788  The compilers might differ in their optimization characteristics (as different
22789  versions of the same compiler might also use more clever optimizations
22790  this is good idea anyway).
22791 \layout Itemize
22792
22793 check that the compilers are not told to supress warnings.
22794 \layout Itemize
22795
22796 check and convert compiler specific extensions (interrupts, memory areas,
22797  pragmas etc.).
22798 \layout Itemize
22799
22800 check for differences in type promotion (especially check for math operations
22801  on char variables and for the use of the ~\SpecialChar ~
22802 operator on bit variables.
22803  See 
22804 \begin_inset LatexCommand \ref{type promotion}
22805
22806 \end_inset 
22807
22808  and 
22809 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
22810
22811 \end_inset 
22812
22813 ).
22814 \layout Itemize
22815
22816 check the assembly code generated for interrupt routines (f.e.
22817  for calls to possibly non-reentrant library functions).
22818 \layout Itemize
22819
22820 check whether timing loops result in proper timing (or preferably consider
22821  a rewrite of the code with timer based delays instead).
22822 \layout Itemize
22823
22824 check for differences in printf parameters (some compilers push (va_arg
22825 \begin_inset LatexCommand \index{va\_arg}
22826
22827 \end_inset 
22828
22829 ) char variables as integers others as char).
22830 \layout Itemize
22831
22832 check the resulting memory layout.
22833 \layout Section
22834
22835 Tools
22836 \begin_inset LatexCommand \index{Tools}
22837
22838 \end_inset 
22839
22840  included in the distribution
22841 \layout Standard
22842 \align center 
22843
22844 \begin_inset  Tabular
22845 <lyxtabular version="3" rows="12" columns="3">
22846 <features>
22847 <column alignment="left" valignment="top" leftline="true" width="0pt">
22848 <column alignment="left" valignment="top" leftline="true" width="0pt">
22849 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
22850 <row topline="true" bottomline="true">
22851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22852 \begin_inset Text
22853
22854 \layout Standard
22855
22856 Name
22857 \end_inset 
22858 </cell>
22859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22860 \begin_inset Text
22861
22862 \layout Standard
22863
22864 Purpose
22865 \end_inset 
22866 </cell>
22867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22868 \begin_inset Text
22869
22870 \layout Standard
22871
22872 Directory
22873 \end_inset 
22874 </cell>
22875 </row>
22876 <row topline="true">
22877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22878 \begin_inset Text
22879
22880 \layout Standard
22881
22882 uCsim
22883 \end_inset 
22884 </cell>
22885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22886 \begin_inset Text
22887
22888 \layout Standard
22889
22890 Simulator for various architectures
22891 \end_inset 
22892 </cell>
22893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22894 \begin_inset Text
22895
22896 \layout Standard
22897
22898 sdcc/sim/ucsim
22899 \end_inset 
22900 </cell>
22901 </row>
22902 <row topline="true">
22903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22904 \begin_inset Text
22905
22906 \layout Standard
22907
22908 keil2sdcc.pl
22909 \end_inset 
22910 </cell>
22911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22912 \begin_inset Text
22913
22914 \layout Standard
22915
22916 header file conversion
22917 \end_inset 
22918 </cell>
22919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22920 \begin_inset Text
22921
22922 \layout Standard
22923
22924 sdcc/support/scripts
22925 \end_inset 
22926 </cell>
22927 </row>
22928 <row topline="true">
22929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22930 \begin_inset Text
22931
22932 \layout Standard
22933
22934 mh2h.c
22935 \end_inset 
22936 </cell>
22937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22938 \begin_inset Text
22939
22940 \layout Standard
22941
22942 header file conversion
22943 \end_inset 
22944 </cell>
22945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22946 \begin_inset Text
22947
22948 \layout Standard
22949
22950 sdcc/support/scripts
22951 \end_inset 
22952 </cell>
22953 </row>
22954 <row topline="true">
22955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22956 \begin_inset Text
22957
22958 \layout Standard
22959
22960 as-gbz80
22961 \end_inset 
22962 </cell>
22963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22964 \begin_inset Text
22965
22966 \layout Standard
22967
22968 Assembler
22969 \end_inset 
22970 </cell>
22971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22972 \begin_inset Text
22973
22974 \layout Standard
22975
22976
22977 \family roman 
22978 \series medium 
22979 \shape up 
22980 \size normal 
22981 \emph off 
22982 \bar no 
22983 \noun off 
22984 \color none
22985 sdcc/bin
22986 \end_inset 
22987 </cell>
22988 </row>
22989 <row topline="true">
22990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22991 \begin_inset Text
22992
22993 \layout Standard
22994
22995 as-z80
22996 \end_inset 
22997 </cell>
22998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22999 \begin_inset Text
23000
23001 \layout Standard
23002
23003 Assembler
23004 \end_inset 
23005 </cell>
23006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23007 \begin_inset Text
23008
23009 \layout Standard
23010
23011
23012 \family roman 
23013 \series medium 
23014 \shape up 
23015 \size normal 
23016 \emph off 
23017 \bar no 
23018 \noun off 
23019 \color none
23020 sdcc/bin
23021 \end_inset 
23022 </cell>
23023 </row>
23024 <row topline="true">
23025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23026 \begin_inset Text
23027
23028 \layout Standard
23029
23030 asx8051
23031 \end_inset 
23032 </cell>
23033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23034 \begin_inset Text
23035
23036 \layout Standard
23037
23038 Assembler
23039 \end_inset 
23040 </cell>
23041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23042 \begin_inset Text
23043
23044 \layout Standard
23045
23046
23047 \family roman 
23048 \series medium 
23049 \shape up 
23050 \size normal 
23051 \emph off 
23052 \bar no 
23053 \noun off 
23054 \color none
23055 sdcc/bin
23056 \end_inset 
23057 </cell>
23058 </row>
23059 <row topline="true">
23060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23061 \begin_inset Text
23062
23063 \layout Standard
23064
23065 sdcdb
23066 \end_inset 
23067 </cell>
23068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23069 \begin_inset Text
23070
23071 \layout Standard
23072
23073 Simulator
23074 \end_inset 
23075 </cell>
23076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23077 \begin_inset Text
23078
23079 \layout Standard
23080
23081
23082 \family roman 
23083 \series medium 
23084 \shape up 
23085 \size normal 
23086 \emph off 
23087 \bar no 
23088 \noun off 
23089 \color none
23090 sdcc/bin
23091 \end_inset 
23092 </cell>
23093 </row>
23094 <row topline="true">
23095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23096 \begin_inset Text
23097
23098 \layout Standard
23099
23100 aslink
23101 \end_inset 
23102 </cell>
23103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23104 \begin_inset Text
23105
23106 \layout Standard
23107
23108 Linker
23109 \end_inset 
23110 </cell>
23111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23112 \begin_inset Text
23113
23114 \layout Standard
23115
23116
23117 \family roman 
23118 \series medium 
23119 \shape up 
23120 \size normal 
23121 \emph off 
23122 \bar no 
23123 \noun off 
23124 \color none
23125 sdcc/bin
23126 \end_inset 
23127 </cell>
23128 </row>
23129 <row topline="true">
23130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23131 \begin_inset Text
23132
23133 \layout Standard
23134
23135 link-z80
23136 \end_inset 
23137 </cell>
23138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23139 \begin_inset Text
23140
23141 \layout Standard
23142
23143 Linker
23144 \end_inset 
23145 </cell>
23146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23147 \begin_inset Text
23148
23149 \layout Standard
23150
23151
23152 \family roman 
23153 \series medium 
23154 \shape up 
23155 \size normal 
23156 \emph off 
23157 \bar no 
23158 \noun off 
23159 \color none
23160 sdcc/bin
23161 \end_inset 
23162 </cell>
23163 </row>
23164 <row topline="true">
23165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23166 \begin_inset Text
23167
23168 \layout Standard
23169
23170 link-gbz80
23171 \end_inset 
23172 </cell>
23173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23174 \begin_inset Text
23175
23176 \layout Standard
23177
23178 Linker
23179 \end_inset 
23180 </cell>
23181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23182 \begin_inset Text
23183
23184 \layout Standard
23185
23186
23187 \family roman 
23188 \series medium 
23189 \shape up 
23190 \size normal 
23191 \emph off 
23192 \bar no 
23193 \noun off 
23194 \color none
23195 sdcc/bin
23196 \end_inset 
23197 </cell>
23198 </row>
23199 <row topline="true" bottomline="true">
23200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23201 \begin_inset Text
23202
23203 \layout Standard
23204
23205 packihx
23206 \end_inset 
23207 </cell>
23208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23209 \begin_inset Text
23210
23211 \layout Standard
23212
23213 ihx packer
23214 \end_inset 
23215 </cell>
23216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23217 \begin_inset Text
23218
23219 \layout Standard
23220
23221
23222 \family roman 
23223 \series medium 
23224 \shape up 
23225 \size normal 
23226 \emph off 
23227 \bar no 
23228 \noun off 
23229 \color none
23230 sdcc/bin
23231 \end_inset 
23232 </cell>
23233 </row>
23234 </lyxtabular>
23235
23236 \end_inset 
23237
23238
23239 \newline 
23240
23241 \layout Section
23242
23243 Documentation
23244 \begin_inset LatexCommand \index{Documentation}
23245
23246 \end_inset 
23247
23248  included in the distribution
23249 \layout Standard
23250 \align center 
23251
23252 \begin_inset  Tabular
23253 <lyxtabular version="3" rows="10" columns="2">
23254 <features>
23255 <column alignment="left" valignment="top" leftline="true" width="0">
23256 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23257 <row topline="true" bottomline="true">
23258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23259 \begin_inset Text
23260
23261 \layout Standard
23262
23263 Subject / Title
23264 \end_inset 
23265 </cell>
23266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23267 \begin_inset Text
23268
23269 \layout Standard
23270
23271 Where to get / filename
23272 \end_inset 
23273 </cell>
23274 </row>
23275 <row topline="true">
23276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23277 \begin_inset Text
23278
23279 \layout Standard
23280
23281 SDCC Compiler User Guide
23282 \end_inset 
23283 </cell>
23284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23285 \begin_inset Text
23286
23287 \layout Standard
23288
23289 You're reading it right now
23290 \end_inset 
23291 </cell>
23292 </row>
23293 <row topline="true">
23294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23295 \begin_inset Text
23296
23297 \layout Standard
23298
23299 Changelog of SDCC
23300 \end_inset 
23301 </cell>
23302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23303 \begin_inset Text
23304
23305 \layout Standard
23306
23307 sdcc/Changelog
23308 \end_inset 
23309 </cell>
23310 </row>
23311 <row topline="true">
23312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23313 \begin_inset Text
23314
23315 \layout Standard
23316
23317 ASXXXX
23318 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
23319
23320 \end_inset 
23321
23322
23323 \begin_inset LatexCommand \index{Assembler documentation}
23324
23325 \end_inset 
23326
23327  Assemblers and ASLINK
23328 \begin_inset LatexCommand \index{aslink}
23329
23330 \end_inset 
23331
23332
23333 \begin_inset LatexCommand \index{Linker documentation}
23334
23335 \end_inset 
23336
23337  Relocating Linker
23338 \end_inset 
23339 </cell>
23340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23341 \begin_inset Text
23342
23343 \layout Standard
23344
23345 sdcc/as/doc/asxhtm.html
23346 \end_inset 
23347 </cell>
23348 </row>
23349 <row topline="true">
23350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23351 \begin_inset Text
23352
23353 \layout Standard
23354
23355 SDCC regression test
23356 \begin_inset LatexCommand \index{Regression test}
23357
23358 \end_inset 
23359
23360
23361 \end_inset 
23362 </cell>
23363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23364 \begin_inset Text
23365
23366 \layout Standard
23367
23368 sdcc/doc/test_suite_spec.pdf
23369 \end_inset 
23370 </cell>
23371 </row>
23372 <row topline="true">
23373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23374 \begin_inset Text
23375
23376 \layout Standard
23377
23378 Various notes
23379 \end_inset 
23380 </cell>
23381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23382 \begin_inset Text
23383
23384 \layout Standard
23385
23386 sdcc/doc/*
23387 \end_inset 
23388 </cell>
23389 </row>
23390 <row topline="true">
23391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23392 \begin_inset Text
23393
23394 \layout Standard
23395
23396 Notes on debugging with sdcdb
23397 \begin_inset LatexCommand \index{sdcdb (debugger)}
23398
23399 \end_inset 
23400
23401
23402 \end_inset 
23403 </cell>
23404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23405 \begin_inset Text
23406
23407 \layout Standard
23408
23409 sdcc/debugger/README
23410 \end_inset 
23411 </cell>
23412 </row>
23413 <row topline="true">
23414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23415 \begin_inset Text
23416
23417 \layout Standard
23418
23419 Software simulator for microcontrollers
23420 \end_inset 
23421 </cell>
23422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23423 \begin_inset Text
23424
23425 \layout Standard
23426
23427
23428 \family roman 
23429 \series medium 
23430 \shape up 
23431 \size normal 
23432 \emph off 
23433 \bar no 
23434 \noun off 
23435 \color none
23436 sdcc/sim/ucsim/doc
23437 \family default 
23438 \series default 
23439 \shape default 
23440 \size default 
23441 \emph default 
23442 \bar default 
23443 \noun default 
23444 \color default
23445 /index.html
23446 \end_inset 
23447 </cell>
23448 </row>
23449 <row topline="true">
23450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23451 \begin_inset Text
23452
23453 \layout Standard
23454
23455 Temporary notes on the pic16
23456 \begin_inset LatexCommand \index{PIC16}
23457
23458 \end_inset 
23459
23460  port
23461 \end_inset 
23462 </cell>
23463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23464 \begin_inset Text
23465
23466 \layout Standard
23467
23468 sdcc/src/pic16/NOTES
23469 \end_inset 
23470 </cell>
23471 </row>
23472 <row topline="true" bottomline="true">
23473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23474 \begin_inset Text
23475
23476 \layout Standard
23477
23478 SDCC internal documentation (debugging file format)
23479 \end_inset 
23480 </cell>
23481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23482 \begin_inset Text
23483
23484 \layout Standard
23485
23486 sdcc/doc/
23487 \family roman 
23488 \series medium 
23489 \shape up 
23490 \size normal 
23491 \emph off 
23492 \bar no 
23493 \noun off 
23494 \color none
23495 cdbfileformat.pd
23496 \family default 
23497 \series default 
23498 \shape default 
23499 \size default 
23500 \emph default 
23501 \bar default 
23502 \noun default 
23503 \color default
23504 f
23505 \end_inset 
23506 </cell>
23507 </row>
23508 </lyxtabular>
23509
23510 \end_inset 
23511
23512
23513 \newline 
23514
23515 \layout Section
23516
23517 Related open source tools
23518 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
23519
23520 \end_inset 
23521
23522
23523 \begin_inset LatexCommand \index{Related tools}
23524
23525 \end_inset 
23526
23527
23528 \layout Standard
23529 \align center 
23530
23531 \begin_inset  Tabular
23532 <lyxtabular version="3" rows="14" columns="3">
23533 <features>
23534 <column alignment="left" valignment="top" leftline="true" width="0pt">
23535 <column alignment="block" valignment="top" leftline="true" width="30line%">
23536 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23537 <row topline="true" bottomline="true">
23538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23539 \begin_inset Text
23540
23541 \layout Standard
23542
23543 Name
23544 \end_inset 
23545 </cell>
23546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23547 \begin_inset Text
23548
23549 \layout Standard
23550
23551 Purpose
23552 \end_inset 
23553 </cell>
23554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23555 \begin_inset Text
23556
23557 \layout Standard
23558
23559 Where to get
23560 \end_inset 
23561 </cell>
23562 </row>
23563 <row topline="true">
23564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23565 \begin_inset Text
23566
23567 \layout Standard
23568
23569 gpsim
23570 \begin_inset LatexCommand \index{gpsim (pic simulator)}
23571
23572 \end_inset 
23573
23574
23575 \end_inset 
23576 </cell>
23577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23578 \begin_inset Text
23579
23580 \layout Standard
23581
23582 PIC simulator
23583 \end_inset 
23584 </cell>
23585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23586 \begin_inset Text
23587
23588 \layout Standard
23589
23590
23591 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
23592
23593 \end_inset 
23594
23595
23596 \end_inset 
23597 </cell>
23598 </row>
23599 <row topline="true">
23600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23601 \begin_inset Text
23602
23603 \layout Standard
23604
23605 gputils
23606 \begin_inset LatexCommand \index{gputils (pic tools)}
23607
23608 \end_inset 
23609
23610
23611 \end_inset 
23612 </cell>
23613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23614 \begin_inset Text
23615
23616 \layout Standard
23617
23618 GNU PIC utilities
23619 \end_inset 
23620 </cell>
23621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23622 \begin_inset Text
23623
23624 \layout Standard
23625
23626
23627 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23628
23629 \end_inset 
23630
23631
23632 \end_inset 
23633 </cell>
23634 </row>
23635 <row topline="true">
23636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23637 \begin_inset Text
23638
23639 \layout Standard
23640
23641 flP5
23642 \end_inset 
23643 </cell>
23644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23645 \begin_inset Text
23646
23647 \layout Standard
23648
23649 PIC programmer
23650 \end_inset 
23651 </cell>
23652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23653 \begin_inset Text
23654
23655 \layout Standard
23656
23657
23658 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
23659
23660 \end_inset 
23661
23662
23663 \end_inset 
23664 </cell>
23665 </row>
23666 <row topline="true">
23667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23668 \begin_inset Text
23669
23670 \layout Standard
23671
23672 ec2drv/newcdb
23673 \end_inset 
23674 </cell>
23675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23676 \begin_inset Text
23677
23678 \layout Standard
23679
23680 Tools for Silicon Laboratories JTAG debug adapter, partly based on sdcdb
23681  (Unix only)
23682 \end_inset 
23683 </cell>
23684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23685 \begin_inset Text
23686
23687 \layout Standard
23688
23689
23690 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
23691
23692 \end_inset 
23693
23694
23695 \end_inset 
23696 </cell>
23697 </row>
23698 <row topline="true">
23699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23700 \begin_inset Text
23701
23702 \layout Standard
23703
23704 indent
23705 \begin_inset LatexCommand \index{indent (source formatting tool)}
23706
23707 \end_inset 
23708
23709
23710 \end_inset 
23711 </cell>
23712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23713 \begin_inset Text
23714
23715 \layout Standard
23716
23717 Formats C source - Master of the white spaces
23718 \end_inset 
23719 </cell>
23720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23721 \begin_inset Text
23722
23723 \layout Standard
23724
23725
23726 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
23727
23728 \end_inset 
23729
23730
23731 \end_inset 
23732 </cell>
23733 </row>
23734 <row topline="true">
23735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23736 \begin_inset Text
23737
23738 \layout Standard
23739
23740 srecord
23741 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
23742
23743 \end_inset 
23744
23745
23746 \end_inset 
23747 </cell>
23748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23749 \begin_inset Text
23750
23751 \layout Standard
23752
23753 Object file conversion, checksumming, ...
23754 \end_inset 
23755 </cell>
23756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23757 \begin_inset Text
23758
23759 \layout Standard
23760
23761
23762 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
23763
23764 \end_inset 
23765
23766
23767 \end_inset 
23768 </cell>
23769 </row>
23770 <row topline="true">
23771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23772 \begin_inset Text
23773
23774 \layout Standard
23775
23776 objdump
23777 \begin_inset LatexCommand \index{objdump (tool)}
23778
23779 \end_inset 
23780
23781
23782 \end_inset 
23783 </cell>
23784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23785 \begin_inset Text
23786
23787 \layout Standard
23788
23789 Object file conversion, ...
23790 \end_inset 
23791 </cell>
23792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23793 \begin_inset Text
23794
23795 \layout Standard
23796
23797 Part of binutils (should be there anyway)
23798 \end_inset 
23799 </cell>
23800 </row>
23801 <row topline="true">
23802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23803 \begin_inset Text
23804
23805 \layout Standard
23806
23807 cmon51
23808 \end_inset 
23809 </cell>
23810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23811 \begin_inset Text
23812
23813 \layout Standard
23814
23815 8051 monitor (hex up-/download, single step, disassemble)
23816 \end_inset 
23817 </cell>
23818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23819 \begin_inset Text
23820
23821 \layout Standard
23822
23823
23824 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
23825
23826 \end_inset 
23827
23828
23829 \end_inset 
23830 </cell>
23831 </row>
23832 <row topline="true">
23833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23834 \begin_inset Text
23835
23836 \layout Standard
23837
23838 doxygen
23839 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
23840
23841 \end_inset 
23842
23843
23844 \end_inset 
23845 </cell>
23846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23847 \begin_inset Text
23848
23849 \layout Standard
23850
23851 Source code documentation system
23852 \end_inset 
23853 </cell>
23854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23855 \begin_inset Text
23856
23857 \layout Standard
23858
23859
23860 \begin_inset LatexCommand \url{http://www.doxygen.org}
23861
23862 \end_inset 
23863
23864
23865 \end_inset 
23866 </cell>
23867 </row>
23868 <row topline="true">
23869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23870 \begin_inset Text
23871
23872 \layout Standard
23873
23874 kdevelop
23875 \end_inset 
23876 </cell>
23877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23878 \begin_inset Text
23879
23880 \layout Standard
23881
23882 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
23883 \end_inset 
23884 </cell>
23885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23886 \begin_inset Text
23887
23888 \layout Standard
23889
23890
23891 \begin_inset LatexCommand \url{http://www.kdevelop.org}
23892
23893 \end_inset 
23894
23895
23896 \end_inset 
23897 </cell>
23898 </row>
23899 <row topline="true">
23900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23901 \begin_inset Text
23902
23903 \layout Standard
23904
23905 paulmon
23906 \end_inset 
23907 </cell>
23908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23909 \begin_inset Text
23910
23911 \layout Standard
23912
23913 8051 monitor (hex up-/download, single step, disassemble)
23914 \end_inset 
23915 </cell>
23916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23917 \begin_inset Text
23918
23919 \layout Standard
23920
23921
23922 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
23923
23924 \end_inset 
23925
23926
23927 \end_inset 
23928 </cell>
23929 </row>
23930 <row topline="true">
23931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23932 \begin_inset Text
23933
23934 \layout Standard
23935
23936 splint
23937 \begin_inset LatexCommand \index{splint (syntax checking tool)}
23938
23939 \end_inset 
23940
23941
23942 \end_inset 
23943 </cell>
23944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23945 \begin_inset Text
23946
23947 \layout Standard
23948
23949 Statically checks c sources (see 
23950 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23951
23952 \end_inset 
23953
23954 )
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.splint.org}
23964
23965 \end_inset 
23966
23967
23968 \end_inset 
23969 </cell>
23970 </row>
23971 <row topline="true" bottomline="true">
23972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23973 \begin_inset Text
23974
23975 \layout Standard
23976
23977 ddd
23978 \begin_inset LatexCommand \index{ddd (debugger)}
23979
23980 \end_inset 
23981
23982
23983 \end_inset 
23984 </cell>
23985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23986 \begin_inset Text
23987
23988 \layout Standard
23989
23990 Debugger, serves nicely as GUI to sdcdb
23991 \begin_inset LatexCommand \index{sdcdb (debugger)}
23992
23993 \end_inset 
23994
23995  (Unix only)
23996 \end_inset 
23997 </cell>
23998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23999 \begin_inset Text
24000
24001 \layout Standard
24002
24003
24004 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
24005
24006 \end_inset 
24007
24008
24009 \end_inset 
24010 </cell>
24011 </row>
24012 </lyxtabular>
24013
24014 \end_inset 
24015
24016
24017 \newline 
24018
24019 \layout Section
24020
24021 Related documentation / recommended reading
24022 \layout Standard
24023 \align center 
24024
24025 \begin_inset  Tabular
24026 <lyxtabular version="3" rows="8" columns="3">
24027 <features>
24028 <column alignment="left" valignment="top" leftline="true" width="0pt">
24029 <column alignment="block" valignment="top" leftline="true" width="30line%">
24030 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24031 <row topline="true" bottomline="true">
24032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24033 \begin_inset Text
24034
24035 \layout Standard
24036
24037 Name
24038 \end_inset 
24039 </cell>
24040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24041 \begin_inset Text
24042
24043 \layout Standard
24044
24045 Subject / Title
24046 \end_inset 
24047 </cell>
24048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24049 \begin_inset Text
24050
24051 \layout Standard
24052
24053 Where to get
24054 \end_inset 
24055 </cell>
24056 </row>
24057 <row topline="true">
24058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24059 \begin_inset Text
24060
24061 \layout Standard
24062
24063
24064 \family roman 
24065 \series medium 
24066 \shape up 
24067 \size normal 
24068 \emph off 
24069 \bar no 
24070 \noun off 
24071 \color none
24072 c-refcard.pdf
24073 \end_inset 
24074 </cell>
24075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24076 \begin_inset Text
24077
24078 \layout Standard
24079
24080 C Reference Card
24081 \begin_inset LatexCommand \index{C Reference card}
24082
24083 \end_inset 
24084
24085 , 2 pages
24086 \end_inset 
24087 </cell>
24088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24089 \begin_inset Text
24090
24091 \layout Standard
24092
24093
24094 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
24095
24096 \end_inset 
24097
24098
24099 \end_inset 
24100 </cell>
24101 </row>
24102 <row topline="true">
24103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24104 \begin_inset Text
24105
24106 \layout Standard
24107
24108 c-faq
24109 \end_inset 
24110 </cell>
24111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24112 \begin_inset Text
24113
24114 \layout Standard
24115
24116 C-FAQ-list
24117 \end_inset 
24118 </cell>
24119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24120 \begin_inset Text
24121
24122 \layout Standard
24123
24124
24125 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
24126
24127 \end_inset 
24128
24129
24130 \end_inset 
24131 </cell>
24132 </row>
24133 <row topline="true">
24134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24135 \begin_inset Text
24136
24137 \layout Standard
24138
24139 ISO/IEC 9899:TC2
24140 \end_inset 
24141 </cell>
24142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24143 \begin_inset Text
24144
24145 \layout Standard
24146
24147
24148 \begin_inset Quotes sld
24149 \end_inset 
24150
24151 C-Standard
24152 \begin_inset Quotes srd
24153 \end_inset 
24154
24155
24156 \end_inset 
24157 </cell>
24158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24159 \begin_inset Text
24160
24161 \layout Standard
24162
24163
24164 \size footnotesize 
24165
24166 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
24167
24168 \end_inset 
24169
24170
24171 \end_inset 
24172 </cell>
24173 </row>
24174 <row topline="true">
24175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24176 \begin_inset Text
24177
24178 \layout Standard
24179
24180 ISO/IEC DTR 18037
24181 \end_inset 
24182 </cell>
24183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24184 \begin_inset Text
24185
24186 \layout Standard
24187
24188
24189 \begin_inset Quotes sld
24190 \end_inset 
24191
24192 Extensions for Embedded C
24193 \begin_inset Quotes srd
24194 \end_inset 
24195
24196
24197 \end_inset 
24198 </cell>
24199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24200 \begin_inset Text
24201
24202 \layout Standard
24203
24204
24205 \size footnotesize 
24206
24207 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
24208
24209 \end_inset 
24210
24211
24212 \end_inset 
24213 </cell>
24214 </row>
24215 <row topline="true">
24216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24217 \begin_inset Text
24218
24219 \layout Standard
24220
24221 \end_inset 
24222 </cell>
24223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24224 \begin_inset Text
24225
24226 \layout Standard
24227
24228 Latest datasheet of the target CPU
24229 \end_inset 
24230 </cell>
24231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24232 \begin_inset Text
24233
24234 \layout Standard
24235
24236 vendor
24237 \end_inset 
24238 </cell>
24239 </row>
24240 <row topline="true">
24241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24242 \begin_inset Text
24243
24244 \layout Standard
24245
24246 \end_inset 
24247 </cell>
24248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24249 \begin_inset Text
24250
24251 \layout Standard
24252
24253 Revision history of datasheet
24254 \end_inset 
24255 </cell>
24256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24257 \begin_inset Text
24258
24259 \layout Standard
24260
24261 vendor
24262 \end_inset 
24263 </cell>
24264 </row>
24265 <row topline="true" bottomline="true">
24266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24267 \begin_inset Text
24268
24269 \layout Standard
24270
24271 S.
24272  S.
24273  Muchnick
24274 \end_inset 
24275 </cell>
24276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24277 \begin_inset Text
24278
24279 \layout Standard
24280
24281 Advanced Compiler Design and Implementation
24282 \end_inset 
24283 </cell>
24284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24285 \begin_inset Text
24286
24287 \layout Standard
24288
24289 bookstore (very dedicated, probably read other books first)
24290 \end_inset 
24291 </cell>
24292 </row>
24293 </lyxtabular>
24294
24295 \end_inset 
24296
24297
24298 \newline 
24299
24300 \layout Section
24301
24302 Some Questions
24303 \layout Standard
24304
24305 Some questions answered, some pointers given - it might be time to in turn
24306  ask 
24307 \emph on 
24308 you
24309 \emph default 
24310  some questions: 
24311 \layout Itemize
24312
24313 can you solve your project with the selected microcontroller? Would you
24314  find out early or rather late that your target is too small/slow/whatever?
24315  Can you switch to a slightly better device if it doesn't fit?
24316 \layout Itemize
24317
24318 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
24319  and/or another programming language be more adequate? Would an operating
24320  system on the target device help?
24321 \layout Itemize
24322
24323 if you solved the problem, will the marketing department be happy?
24324 \layout Itemize
24325
24326 if the marketing department is happy, will customers be happy?
24327 \layout Itemize
24328
24329 if you're the project manager, marketing department and maybe even the customer
24330  in one person, have you tried to see the project from the outside?
24331 \layout Itemize
24332
24333 is the project done if you think it is done? Or is just that other interface/pro
24334 tocol/feature/configuration/option missing? How about website, manual(s),
24335  internationali(z|s)ation, packaging, labels, 2nd source for components,
24336  electromagnetic compatability/interference, documentation for production,
24337  production test software, update mechanism, patent issues?
24338 \layout Itemize
24339
24340 is your project adequately positioned in that magic triangle: fame, fortune,
24341  fun?
24342 \layout Standard
24343
24344 Maybe not all answers to these questions are known and some answers may
24345  even be 
24346 \emph on 
24347 no
24348 \emph default 
24349 , nevertheless knowing these questions may help you to avoid burnout
24350 \begin_inset Foot
24351 collapsed false
24352
24353 \layout Standard
24354
24355 burnout is bad for electronic devices, programmers and motorcycle tyres
24356 \end_inset 
24357
24358 .
24359  Chances are you didn't want to hear some of them...
24360 \layout Chapter
24361
24362 Support
24363 \begin_inset LatexCommand \index{Support}
24364
24365 \end_inset 
24366
24367
24368 \layout Standard
24369
24370 SDCC has grown to be a large project.
24371  The compiler alone (without the preprocessor, assembler and linker) is
24372  well over 100,000 lines of code (blank stripped).
24373  The open source nature of this project is a key to its continued growth
24374  and support.
24375  You gain the benefit and support of many active software developers and
24376  end users.
24377  Is SDCC perfect? No, that's why we need your help.
24378  The developers take pride in fixing reported bugs.
24379  You can help by reporting the bugs and helping other SDCC users.
24380  There are lots of ways to contribute, and we encourage you to take part
24381  in making SDCC a great software package.
24382  
24383 \layout Standard
24384
24385 The SDCC project is hosted on the SDCC sourceforge site at 
24386 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
24387
24388 \end_inset 
24389
24390 .
24391  You'll find the complete set of mailing lists
24392 \begin_inset LatexCommand \index{Mailing list(s)}
24393
24394 \end_inset 
24395
24396 , forums, bug reporting system, patch submission
24397 \begin_inset LatexCommand \index{Patch submission}
24398
24399 \end_inset 
24400
24401  system, download
24402 \begin_inset LatexCommand \index{download}
24403
24404 \end_inset 
24405
24406  area and Subversion code repository
24407 \begin_inset LatexCommand \index{Subversion code repository}
24408
24409 \end_inset 
24410
24411  there.
24412 \layout Section
24413
24414 Reporting Bugs
24415 \begin_inset LatexCommand \index{Bug reporting}
24416
24417 \end_inset 
24418
24419
24420 \begin_inset LatexCommand \index{Reporting bugs}
24421
24422 \end_inset 
24423
24424
24425 \layout Standard
24426
24427 The recommended way of reporting bugs is using the infrastructure of the
24428  sourceforge site.
24429  You can follow the status of bug reports there and have an overview about
24430  the known bugs.
24431 \layout Standard
24432
24433 Bug reports are automatically forwarded to the developer mailing list and
24434  will be fixed ASAP.
24435  When reporting a bug, it is very useful to include a small test program
24436  (the smaller the better) which reproduces the problem.
24437  If you can isolate the problem by looking at the generated assembly code,
24438  this can be very helpful.
24439  Compiling your program with the -
24440 \begin_inset ERT
24441 status Collapsed
24442
24443 \layout Standard
24444
24445 \backslash 
24446 /
24447 \end_inset 
24448
24449 -dumpall
24450 \begin_inset LatexCommand \index{-\/-dumpall}
24451
24452 \end_inset 
24453
24454  option can sometimes be useful in locating optimization problems.
24455  When reporting a bug please maker sure you:
24456 \layout Enumerate
24457
24458 Attach the code you are compiling with SDCC.
24459  
24460 \layout Enumerate
24461
24462 Specify the exact command you use to run SDCC, or attach your Makefile.
24463  
24464 \layout Enumerate
24465
24466 Specify the SDCC version (type "
24467 \family sans 
24468 \series bold 
24469 sdcc -v
24470 \family default 
24471 \series default 
24472 "), your platform, and operating system.
24473  
24474 \layout Enumerate
24475
24476 Provide an exact copy of any error message or incorrect output.
24477  
24478 \layout Enumerate
24479
24480 Put something meaningful in the subject of your message.
24481 \layout Standard
24482
24483 Please attempt to include these 5 important parts, as applicable, in all
24484  requests for support or when reporting any problems or bugs with SDCC.
24485  Though this will make your message lengthy, it will greatly improve your
24486  chance that SDCC users and developers will be able to help you.
24487  Some SDCC developers are frustrated by bug reports without code provided
24488  that they can use to reproduce and ultimately fix the problem, so please
24489  be sure to provide sample code if you are reporting a bug! 
24490 \layout Standard
24491
24492 Please have a short check that you are using a recent version of SDCC and
24493  the bug is not yet known.
24494  This is the link for reporting bugs: 
24495 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
24496
24497 \end_inset 
24498
24499 .
24500 \layout Section
24501
24502 Requesting Features
24503 \begin_inset LatexCommand \label{sub:Requesting-Features}
24504
24505 \end_inset 
24506
24507
24508 \begin_inset LatexCommand \index{Feature request}
24509
24510 \end_inset 
24511
24512
24513 \begin_inset LatexCommand \index{Requesting features}
24514
24515 \end_inset 
24516
24517
24518 \layout Standard
24519
24520 Like bug reports feature requests are forwarded to the developer mailing
24521  list.
24522  This is the link for requesting features: 
24523 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
24524
24525 \end_inset 
24526
24527 .
24528 \layout Section
24529
24530 Submitting patches
24531 \layout Standard
24532
24533 Like bug reports contributed patches are forwarded to the developer mailing
24534  list.
24535  This is the link for submitting patches
24536 \begin_inset LatexCommand \index{Patch submission}
24537
24538 \end_inset 
24539
24540
24541 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
24542
24543 \end_inset 
24544
24545 .
24546 \layout Standard
24547
24548 You need to specify some parameters to the 
24549 \family typewriter 
24550 diff
24551 \family default 
24552  command for the patches to be useful.
24553  If you modified more than one file a patch created f.e.
24554  with 
24555 \family sans 
24556 \series bold 
24557
24558 \begin_inset Quotes sld
24559 \end_inset 
24560
24561 diff -Naur unmodified_directory modified_directory >my_changes.patch
24562 \begin_inset Quotes srd
24563 \end_inset 
24564
24565
24566 \family default 
24567 \series default 
24568  will be fine, otherwise 
24569 \family sans 
24570 \series bold 
24571
24572 \begin_inset Quotes sld
24573 \end_inset 
24574
24575 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
24576 \begin_inset Quotes srd
24577 \end_inset 
24578
24579
24580 \series default 
24581  
24582 \family default 
24583 will do.
24584 \layout Section
24585
24586 Getting Help
24587 \layout Standard
24588
24589 These links should take you directly to the 
24590 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
24591
24592 \end_inset 
24593
24594
24595 \begin_inset Foot
24596 collapsed false
24597
24598 \layout Standard
24599
24600 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
24601  automated messages (mid 2003)
24602 \end_inset 
24603
24604  and the 
24605 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
24606
24607 \end_inset 
24608
24609 , lists
24610 \begin_inset LatexCommand \index{Mailing list(s)}
24611
24612 \end_inset 
24613
24614  and forums are archived and searchable so if you are lucky someone already
24615  had a similar problem.
24616  While mails to the lists themselves are delivered promptly their web front
24617  end on sourceforge sometimes shows a severe time lag (up to several weeks),
24618  if you're seriously using SDCC please consider subscribing to the lists.
24619 \layout Section
24620
24621 ChangeLog
24622 \layout Standard
24623
24624 You can follow the status of the Subversion version
24625 \begin_inset LatexCommand \index{version}
24626
24627 \end_inset 
24628
24629  of SDCC by watching the Changelog
24630 \begin_inset LatexCommand \index{Changelog}
24631
24632 \end_inset 
24633
24634  in the Subversion repository
24635 \size footnotesize 
24636  
24637 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
24638
24639 \end_inset 
24640
24641 .
24642 \layout Section
24643
24644 Subversion Source Code Repository
24645 \layout Standard
24646
24647 The output of 
24648 \family sans 
24649 \series bold 
24650 sdcc --version
24651 \family default 
24652 \series default 
24653  or the filenames of the snapshot versions of SDCC include date and its
24654  Subversion
24655 \begin_inset LatexCommand \index{Subversion}
24656
24657 \end_inset 
24658
24659  number.
24660  Subversion allows to download the source of recent or previous versions
24661  
24662 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
24663
24664 \end_inset 
24665
24666  (by number or by date).
24667  An on-line source code browser and detailled instructions are also available
24668  there.
24669  SDCC versions starting from 1999 up to now are available (currently the
24670  versions prior to the conversion from cvs to Subversion (April 2006) are
24671  either by accessible by Subversion or by cvs).
24672 \layout Section
24673
24674 Release policy
24675 \begin_inset LatexCommand \index{Release policy}
24676
24677 \end_inset 
24678
24679
24680 \layout Standard
24681
24682 Historically there often were long delays between official releases and
24683  the sourceforge download area tends to get not updated at all.
24684  Excuses in the past might have referred to problems with live range analysis,
24685  but as this was fixed a while ago, the current problem is that another
24686  excuse has to be found.
24687  Kidding aside, we have to get better there! On the other hand there are
24688  daily snapshots available at 
24689 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
24690
24691 \end_inset 
24692
24693 , and you can always build the very last version (hopefully with many bugs
24694  fixed, and features added) from the source code available at 
24695 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
24696
24697 \end_inset 
24698
24699 .
24700 \layout Section
24701
24702 Examples
24703 \begin_inset LatexCommand \index{Examples}
24704
24705 \end_inset 
24706
24707
24708 \layout Standard
24709
24710 You'll find some small examples in the directory 
24711 \emph on 
24712 sdcc/device/examples/.
24713  
24714 \emph default 
24715 More examples and libraries are available at
24716 \emph on 
24717  The SDCC Open Knowledge Resource 
24718 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
24719
24720 \end_inset 
24721
24722  
24723 \emph default 
24724 web site or at 
24725 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
24726
24727 \end_inset 
24728
24729 .
24730 \layout Comment
24731
24732 I did insert a reference to Paul's web site here although it seems rather
24733  dedicated to a specific 8032 board (I think it's okay because it f.e.
24734  shows LCD/Harddisc interface and has a free 8051 monitor.
24735  Independent 8032 board vendors face hard competition of heavily subsidized
24736  development boards anyway).
24737 \layout Comment
24738
24739 Maybe we should include some links to real world applications.
24740  Preferably pointer to pointers (one for each architecture) so this stays
24741  manageable here?
24742 \layout Section
24743
24744 Quality control
24745 \begin_inset LatexCommand \index{Quality control}
24746
24747 \end_inset 
24748
24749
24750 \layout Standard
24751
24752 The compiler is passed through nightly compile and build checks.
24753  The so called 
24754 \shape italic 
24755 regression tests
24756 \shape default 
24757
24758 \begin_inset LatexCommand \index{Regression test}
24759
24760 \end_inset 
24761
24762  check that SDCC itself compiles flawlessly on several platforms and checks
24763  the quality of the code generated by SDCC by running the code through simulator
24764 s.
24765  There is a separate document 
24766 \shape italic 
24767 test_suite.pdf
24768 \begin_inset LatexCommand \index{Test suite}
24769
24770 \end_inset 
24771
24772
24773 \shape default 
24774  about this.
24775 \layout Standard
24776
24777 You'll find the test code in the directory 
24778 \shape italic 
24779 sdcc/support/regression
24780 \shape default 
24781 .
24782  You can run these tests manually by running 
24783 \family sans 
24784 make
24785 \family default 
24786  in this directory (or f.e.
24787  
24788 \family sans 
24789 \series bold 
24790
24791 \begin_inset Quotes sld
24792 \end_inset 
24793
24794 make test-mcs51
24795 \begin_inset Quotes srd
24796 \end_inset 
24797
24798
24799 \family default 
24800 \series default 
24801  if you don't want to run the complete tests).
24802  The test code might also be interesting if you want to look for examples
24803 \begin_inset LatexCommand \index{Examples}
24804
24805 \end_inset 
24806
24807  checking corner cases of SDCC or if you plan to submit patches
24808 \begin_inset LatexCommand \index{Patch submission}
24809
24810 \end_inset 
24811
24812 .
24813 \layout Standard
24814
24815 The pic port uses a different set of regression tests, you'll find them
24816  in the directory 
24817 \shape italic 
24818 sdcc/src/regression
24819 \shape default 
24820 .
24821 \layout Section
24822
24823 Use of SDCC in Education
24824 \layout Standard
24825
24826 In short: 
24827 \emph on 
24828 highly
24829 \emph default 
24830  encouraged
24831 \begin_inset Foot
24832 collapsed false
24833
24834 \layout Standard
24835
24836 the phrase "use in education" might evoke the association "
24837 \emph on 
24838 only
24839 \emph default 
24840  fit for use in education".
24841  This connotation is not intended but nevertheless risked as the licensing
24842  of SDCC makes it difficult to offer educational discounts
24843 \end_inset 
24844
24845 .
24846  If your rationales are to:
24847 \layout Enumerate
24848
24849 give students a chance to understand the 
24850 \emph on 
24851 complete
24852 \emph default 
24853  steps of code generation
24854 \layout Enumerate
24855
24856 have a curriculum that can be extended for years.
24857  Then you could use an fpga board as target and your curriculum will seamlessly
24858  extend from logic synthesis (
24859 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
24860
24861 \end_inset 
24862
24863
24864 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
24865
24866 \end_inset 
24867
24868 ), over assembly programming, to C to FPGA compilers (
24869 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
24870
24871 \end_inset 
24872
24873 ) and to C.
24874 \layout Enumerate
24875
24876 be able to insert excursions about skills like using a revision control
24877  system, submitting/applying patches, using a type-setting (as opposed to
24878  word-processing) engine LyX/LaTeX, using 
24879 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
24880
24881 \end_inset 
24882
24883 , following some 
24884 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
24885
24886 \end_inset 
24887
24888 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
24889  Source Software, CPU simulation, compiler regression tests
24890 \begin_inset LatexCommand \index{Regression test}
24891
24892 \end_inset 
24893
24894 .
24895  
24896 \newline 
24897 And if there should be a shortage of ideas then you can always point students
24898  to the ever-growing feature request list 
24899 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
24900
24901 \end_inset 
24902
24903 .
24904 \layout Enumerate
24905
24906 not tie students to a specific host platform and instead allow them to use
24907  a host platform of 
24908 \emph on 
24909 their
24910 \emph default 
24911  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
24912  eventually 
24913 \begin_inset LatexCommand \url[OLPC]{http://wiki.laptop.org/wiki/One_Laptop_per_Child}
24914
24915 \end_inset 
24916
24917 )
24918 \layout Enumerate
24919
24920 not encourage students to use illegal copies of educational software
24921 \layout Enumerate
24922
24923 be immune to licensing/availability/price changes of the chosen tool chain
24924 \layout Enumerate
24925
24926 be able to change to a new target platform without having to adopt a new
24927  tool chain
24928 \layout Enumerate
24929
24930 have complete control over and insight into the tool chain
24931 \layout Enumerate
24932
24933 make your students aware about the pros and cons of open source software
24934  development
24935 \layout Enumerate
24936
24937 give back to the public as you are probably at least partially publically
24938  funded
24939 \layout Enumerate
24940
24941 give students a chance to publically prove their skills and to possibly
24942  see a world wide impact
24943 \layout Standard
24944
24945 then SDCC is probably among the first choices.
24946  Well, probably SDCC might be the only choice.
24947 \layout Chapter
24948 \pagebreak_top 
24949 SDCC Technical Data
24950 \layout Section
24951
24952 Optimizations
24953 \begin_inset LatexCommand \index{Optimizations}
24954
24955 \end_inset 
24956
24957
24958 \layout Standard
24959
24960 SDCC performs a host of standard optimizations in addition to some MCU specific
24961  optimizations.
24962  
24963 \layout Subsection
24964
24965 Sub-expression Elimination
24966 \begin_inset LatexCommand \index{Subexpression elimination}
24967
24968 \end_inset 
24969
24970
24971 \layout Standard
24972
24973 The compiler does local and 
24974 \emph on 
24975 g
24976 \emph default 
24977 lobal 
24978 \emph on 
24979 c
24980 \emph default 
24981 ommon 
24982 \emph on 
24983 s
24984 \emph default 
24985 ubexpression 
24986 \emph on 
24987 e
24988 \emph default 
24989 limination, e.g.: 
24990 \layout Verse
24991
24992
24993 \family typewriter 
24994 i = x + y + 1; 
24995 \newline 
24996 j = x + y;
24997 \layout Standard
24998
24999 will be translated to
25000 \layout Verse
25001
25002
25003 \family typewriter 
25004 iTemp = x + y; 
25005 \newline 
25006 i = iTemp + 1; 
25007 \newline 
25008 j = iTemp;
25009 \layout Standard
25010
25011 Some subexpressions are not as obvious as the above example, e.g.:
25012 \layout Verse
25013
25014
25015 \family typewriter 
25016 a->b[i].c = 10; 
25017 \newline 
25018 a->b[i].d = 11;
25019 \layout Standard
25020
25021 In this case the address arithmetic a->b[i] will be computed only once;
25022  the equivalent code in C would be.
25023 \layout Verse
25024
25025
25026 \family typewriter 
25027 iTemp = a->b[i]; 
25028 \newline 
25029 iTemp.c = 10; 
25030 \newline 
25031 iTemp.d = 11;
25032 \layout Standard
25033
25034 The compiler will try to keep these temporary variables in registers.
25035 \layout Subsection
25036
25037 Dead-Code Elimination
25038 \begin_inset LatexCommand \index{Dead-code elimination}
25039
25040 \end_inset 
25041
25042
25043 \layout Verse
25044
25045
25046 \family typewriter 
25047 int global;
25048 \newline 
25049
25050 \newline 
25051 void f () { 
25052 \newline 
25053 \SpecialChar ~
25054 \SpecialChar ~
25055 int i; 
25056 \newline 
25057 \SpecialChar ~
25058 \SpecialChar ~
25059 i = 1; \SpecialChar ~
25060 \SpecialChar ~
25061 \SpecialChar ~
25062 \SpecialChar ~
25063 \SpecialChar ~
25064 /* dead store */ 
25065 \newline 
25066 \SpecialChar ~
25067 \SpecialChar ~
25068 global = 1;\SpecialChar ~
25069 /* dead store */ 
25070 \newline 
25071 \SpecialChar ~
25072 \SpecialChar ~
25073 global = 2; 
25074 \newline 
25075 \SpecialChar ~
25076 \SpecialChar ~
25077 return; 
25078 \newline 
25079 \SpecialChar ~
25080 \SpecialChar ~
25081 global = 3;\SpecialChar ~
25082 /* unreachable */ 
25083 \newline 
25084 }
25085 \layout Standard
25086
25087 will be changed to
25088 \layout Verse
25089
25090
25091 \family typewriter 
25092 int global;
25093 \newline 
25094
25095 \newline 
25096 void f () {
25097 \newline 
25098 \SpecialChar ~
25099 \SpecialChar ~
25100 global = 2; 
25101 \newline 
25102 }
25103 \layout Subsection
25104
25105 Copy-Propagation
25106 \begin_inset LatexCommand \index{Copy propagation}
25107
25108 \end_inset 
25109
25110
25111 \layout Verse
25112
25113
25114 \family typewriter 
25115 int f() { 
25116 \newline 
25117 \SpecialChar ~
25118 \SpecialChar ~
25119 int i, j; 
25120 \newline 
25121 \SpecialChar ~
25122 \SpecialChar ~
25123 i = 10; 
25124 \newline 
25125 \SpecialChar ~
25126 \SpecialChar ~
25127 j = i; 
25128 \newline 
25129 \SpecialChar ~
25130 \SpecialChar ~
25131 return j; 
25132 \newline 
25133 }
25134 \layout Standard
25135
25136 will be changed to 
25137 \layout Verse
25138
25139
25140 \family typewriter 
25141 int f() { 
25142 \newline 
25143 \SpecialChar ~
25144 \SpecialChar ~
25145 int i, j; 
25146 \newline 
25147 \SpecialChar ~
25148 \SpecialChar ~
25149 i = 10; 
25150 \newline 
25151 \SpecialChar ~
25152 \SpecialChar ~
25153 j = 10; 
25154 \newline 
25155 \SpecialChar ~
25156 \SpecialChar ~
25157 return 10; 
25158 \newline 
25159 }
25160 \layout Standard
25161
25162 Note: the dead stores created by this copy propagation will be eliminated
25163  by dead-code elimination.
25164 \layout Subsection
25165
25166 Loop Optimizations
25167 \begin_inset LatexCommand \index{Loop optimization}
25168
25169 \end_inset 
25170
25171
25172 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
25173
25174 \end_inset 
25175
25176
25177 \layout Standard
25178
25179 Two types of loop optimizations are done by SDCC 
25180 \emph on 
25181 loop invariant
25182 \emph default 
25183  lifting and
25184 \emph on 
25185  strength reduction
25186 \emph default 
25187  of loop induction variables.
25188  In addition to the strength reduction the optimizer marks the induction
25189  variables and the register allocator tries to keep the induction variables
25190  in registers for the duration of the loop.
25191  Because of this preference of the register allocator
25192 \begin_inset LatexCommand \index{Register allocation}
25193
25194 \end_inset 
25195
25196 , loop induction optimization causes an increase in register pressure, which
25197  may cause unwanted spilling of other temporary variables into the stack
25198 \begin_inset LatexCommand \index{stack}
25199
25200 \end_inset 
25201
25202  / data space.
25203  The compiler will generate a warning message when it is forced to allocate
25204  extra space either on the stack or data space.
25205  If this extra space allocation is undesirable then induction optimization
25206  can be eliminated either for the entire source file (with -
25207 \begin_inset ERT
25208 status Collapsed
25209
25210 \layout Standard
25211
25212 \backslash 
25213 /
25214 \end_inset 
25215
25216 -noinduction option) or for a given function only using #pragma\SpecialChar ~
25217 noinduction
25218 \begin_inset LatexCommand \index{\#pragma noinduction}
25219
25220 \end_inset 
25221
25222 .
25223 \newline 
25224
25225 \newline 
25226 Loop Invariant:
25227 \layout Verse
25228
25229
25230 \family typewriter 
25231 for (i = 0 ; i < 100 ; i ++) 
25232 \newline 
25233 \SpecialChar ~
25234 \SpecialChar ~
25235 \SpecialChar ~
25236 \SpecialChar ~
25237 f += k + l;
25238 \layout Standard
25239
25240 changed to
25241 \layout Verse
25242
25243
25244 \family typewriter 
25245 itemp = k + l; 
25246 \newline 
25247 for (i = 0; i < 100; i++) 
25248 \newline 
25249 \SpecialChar ~
25250 \SpecialChar ~
25251 \SpecialChar ~
25252 \SpecialChar ~
25253 f += itemp;
25254 \layout Standard
25255
25256 As mentioned previously some loop invariants are not as apparent, all static
25257  address computations are also moved out of the loop.
25258 \newline 
25259
25260 \newline 
25261 Strength Reduction
25262 \begin_inset LatexCommand \index{Strength reduction}
25263
25264 \end_inset 
25265
25266 , this optimization substitutes an expression by a cheaper expression:
25267 \layout Verse
25268
25269
25270 \family typewriter 
25271 for (i=0;i < 100; i++)
25272 \newline 
25273 \SpecialChar ~
25274 \SpecialChar ~
25275 \SpecialChar ~
25276 \SpecialChar ~
25277 ar[i*5] = i*3;
25278 \layout Standard
25279
25280 changed to
25281 \layout Verse
25282
25283
25284 \family typewriter 
25285 itemp1 = 0; 
25286 \newline 
25287 itemp2 = 0; 
25288 \newline 
25289 for (i=0;i< 100;i++) { 
25290 \newline 
25291 \SpecialChar ~
25292 \SpecialChar ~
25293 \SpecialChar ~
25294 \SpecialChar ~
25295 ar[itemp1] = itemp2; 
25296 \newline 
25297 \SpecialChar ~
25298 \SpecialChar ~
25299 \SpecialChar ~
25300 \SpecialChar ~
25301 itemp1 += 5; 
25302 \newline 
25303 \SpecialChar ~
25304 \SpecialChar ~
25305 \SpecialChar ~
25306 \SpecialChar ~
25307 itemp2 += 3; 
25308 \newline 
25309 }
25310 \layout Standard
25311
25312 The more expensive multiplication
25313 \begin_inset LatexCommand \index{Multiplication}
25314
25315 \end_inset 
25316
25317  is changed to a less expensive addition.
25318 \layout Subsection
25319
25320 Loop Reversing
25321 \begin_inset LatexCommand \index{Loop reversing}
25322
25323 \end_inset 
25324
25325
25326 \layout Standard
25327
25328 This optimization is done to reduce the overhead of checking loop boundaries
25329  for every iteration.
25330  Some simple loops can be reversed and implemented using a 
25331 \begin_inset Quotes eld
25332 \end_inset 
25333
25334 decrement and jump if not zero
25335 \begin_inset Quotes erd
25336 \end_inset 
25337
25338  instruction.
25339  SDCC checks for the following criterion to determine if a loop is reversible
25340  (note: more sophisticated compilers use data-dependency analysis to make
25341  this determination, SDCC uses a more simple minded analysis).
25342 \layout Itemize
25343
25344 The 'for' loop is of the form 
25345 \newline 
25346
25347 \newline 
25348
25349 \family typewriter 
25350 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
25351  += 1])
25352 \newline 
25353 \SpecialChar ~
25354 \SpecialChar ~
25355 \SpecialChar ~
25356 \SpecialChar ~
25357 <for body>
25358 \layout Itemize
25359
25360 The <for body> does not contain 
25361 \begin_inset Quotes eld
25362 \end_inset 
25363
25364 continue
25365 \begin_inset Quotes erd
25366 \end_inset 
25367
25368  or 'break
25369 \begin_inset Quotes erd
25370 \end_inset 
25371
25372 .
25373 \layout Itemize
25374
25375 All goto's are contained within the loop.
25376 \layout Itemize
25377
25378 No function calls within the loop.
25379 \layout Itemize
25380
25381 The loop control variable <sym> is not assigned any value within the loop
25382 \layout Itemize
25383
25384 The loop control variable does NOT participate in any arithmetic operation
25385  within the loop.
25386 \layout Itemize
25387
25388 There are NO switch statements in the loop.
25389 \layout Subsection
25390
25391 Algebraic Simplifications
25392 \layout Standard
25393
25394 SDCC does numerous algebraic simplifications, the following is a small sub-set
25395  of these optimizations.
25396 \layout Verse
25397
25398
25399 \family typewriter 
25400 i = j + 0;\SpecialChar ~
25401 \SpecialChar ~
25402 \SpecialChar ~
25403 \SpecialChar ~
25404  /* changed to: */\SpecialChar ~
25405 \SpecialChar ~
25406 \SpecialChar ~
25407 \SpecialChar ~
25408  i = j; 
25409 \newline 
25410 i /= 2;\SpecialChar ~
25411 \SpecialChar ~
25412 \SpecialChar ~
25413 \SpecialChar ~
25414 \SpecialChar ~
25415 \SpecialChar ~
25416 \SpecialChar ~
25417  /* changed to: */\SpecialChar ~
25418 \SpecialChar ~
25419 \SpecialChar ~
25420 \SpecialChar ~
25421  i >>= 1; 
25422 \newline 
25423 i = j - j;\SpecialChar ~
25424 \SpecialChar ~
25425 \SpecialChar ~
25426 \SpecialChar ~
25427  /* changed to: */\SpecialChar ~
25428 \SpecialChar ~
25429 \SpecialChar ~
25430 \SpecialChar ~
25431  i = 0; 
25432 \newline 
25433 i = j / 1;\SpecialChar ~
25434 \SpecialChar ~
25435 \SpecialChar ~
25436 \SpecialChar ~
25437  /* changed to: */\SpecialChar ~
25438 \SpecialChar ~
25439 \SpecialChar ~
25440 \SpecialChar ~
25441  i = j;
25442 \layout Standard
25443
25444 Note the subexpressions
25445 \begin_inset LatexCommand \index{Subexpression}
25446
25447 \end_inset 
25448
25449  given above are generally introduced by macro expansions or as a result
25450  of copy/constant propagation.
25451 \layout Subsection
25452
25453 'switch' Statements
25454 \begin_inset LatexCommand \label{sub:'switch'-Statements}
25455
25456 \end_inset 
25457
25458
25459 \begin_inset LatexCommand \index{switch statement}
25460
25461 \end_inset 
25462
25463
25464 \layout Standard
25465
25466 SDCC can optimize switch statements to jump tables
25467 \begin_inset LatexCommand \index{jump tables}
25468
25469 \end_inset 
25470
25471 .
25472  It makes the decision based on an estimate of the generated code size.
25473  SDCC is quite liberal in the requirements for jump table generation: 
25474 \layout Itemize
25475
25476 The labels need not be in order, and the starting number need not be one
25477  or zero, the case labels are in numerical sequence or not too many case
25478  labels are missing.
25479 \begin_deeper 
25480 \layout Verse
25481
25482
25483 \family typewriter 
25484 switch(i) {\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 \SpecialChar ~
25507 \SpecialChar ~
25508 \SpecialChar ~
25509 \SpecialChar ~
25510 switch (i) { 
25511 \newline 
25512 \SpecialChar ~
25513 \SpecialChar ~
25514 \SpecialChar ~
25515 case 4: ...\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 \SpecialChar ~
25539 \SpecialChar ~
25540 \SpecialChar ~
25541 case 0: ...
25542  
25543 \newline 
25544 \SpecialChar ~
25545 \SpecialChar ~
25546 \SpecialChar ~
25547 case 5: ...\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 \SpecialChar ~
25571 \SpecialChar ~
25572 \SpecialChar ~
25573 case 1: ...
25574  
25575 \newline 
25576 \SpecialChar ~
25577 \SpecialChar ~
25578 \SpecialChar ~
25579 case 3: ...\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 \SpecialChar ~
25602 \SpecialChar ~
25603 \SpecialChar ~
25604 \SpecialChar ~
25605
25606 \newline 
25607 \SpecialChar ~
25608 \SpecialChar ~
25609 \SpecialChar ~
25610 case 6: ...\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 \SpecialChar ~
25633 \SpecialChar ~
25634 \SpecialChar ~
25635 \SpecialChar ~
25636 case 3: ...
25637  
25638 \newline 
25639 \SpecialChar ~
25640 \SpecialChar ~
25641 \SpecialChar ~
25642 case 7: ...\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 case 4: ...
25669  
25670 \newline 
25671 \SpecialChar ~
25672 \SpecialChar ~
25673 \SpecialChar ~
25674 case 8: ...\SpecialChar ~
25675 \SpecialChar ~
25676 \SpecialChar ~
25677 \SpecialChar ~
25678 \SpecialChar ~
25679 \SpecialChar ~
25680 \SpecialChar ~
25681 \SpecialChar ~
25682 \SpecialChar ~
25683 \SpecialChar ~
25684 \SpecialChar ~
25685 \SpecialChar ~
25686 \SpecialChar ~
25687 \SpecialChar ~
25688 \SpecialChar ~
25689 \SpecialChar ~
25690 \SpecialChar ~
25691 \SpecialChar ~
25692 \SpecialChar ~
25693 \SpecialChar ~
25694 \SpecialChar ~
25695 \SpecialChar ~
25696 \SpecialChar ~
25697 \SpecialChar ~
25698 \SpecialChar ~
25699 \SpecialChar ~
25700 case 5: ...
25701  
25702 \newline 
25703 \SpecialChar ~
25704 \SpecialChar ~
25705 \SpecialChar ~
25706 case 9: ...\SpecialChar ~
25707 \SpecialChar ~
25708 \SpecialChar ~
25709 \SpecialChar ~
25710 \SpecialChar ~
25711 \SpecialChar ~
25712 \SpecialChar ~
25713 \SpecialChar ~
25714 \SpecialChar ~
25715 \SpecialChar ~
25716 \SpecialChar ~
25717 \SpecialChar ~
25718 \SpecialChar ~
25719 \SpecialChar ~
25720 \SpecialChar ~
25721 \SpecialChar ~
25722 \SpecialChar ~
25723 \SpecialChar ~
25724 \SpecialChar ~
25725 \SpecialChar ~
25726 \SpecialChar ~
25727 \SpecialChar ~
25728 \SpecialChar ~
25729 \SpecialChar ~
25730 \SpecialChar ~
25731 \SpecialChar ~
25732 case 6: ...
25733  
25734 \newline 
25735 \SpecialChar ~
25736 \SpecialChar ~
25737 \SpecialChar ~
25738 case 10: ...\SpecialChar ~
25739 \SpecialChar ~
25740 \SpecialChar ~
25741 \SpecialChar ~
25742 \SpecialChar ~
25743 \SpecialChar ~
25744 \SpecialChar ~
25745 \SpecialChar ~
25746 \SpecialChar ~
25747 \SpecialChar ~
25748 \SpecialChar ~
25749 \SpecialChar ~
25750 \SpecialChar ~
25751 \SpecialChar ~
25752 \SpecialChar ~
25753 \SpecialChar ~
25754 \SpecialChar ~
25755 \SpecialChar ~
25756 \SpecialChar ~
25757 \SpecialChar ~
25758 \SpecialChar ~
25759 \SpecialChar ~
25760 \SpecialChar ~
25761 \SpecialChar ~
25762 \SpecialChar ~
25763 case 7: ...
25764  
25765 \newline 
25766 \SpecialChar ~
25767 \SpecialChar ~
25768 \SpecialChar ~
25769 case 11: ...\SpecialChar ~
25770 \SpecialChar ~
25771 \SpecialChar ~
25772 \SpecialChar ~
25773 \SpecialChar ~
25774 \SpecialChar ~
25775 \SpecialChar ~
25776 \SpecialChar ~
25777 \SpecialChar ~
25778 \SpecialChar ~
25779 \SpecialChar ~
25780 \SpecialChar ~
25781 \SpecialChar ~
25782 \SpecialChar ~
25783 \SpecialChar ~
25784 \SpecialChar ~
25785 \SpecialChar ~
25786 \SpecialChar ~
25787 \SpecialChar ~
25788 \SpecialChar ~
25789 \SpecialChar ~
25790 \SpecialChar ~
25791 \SpecialChar ~
25792 \SpecialChar ~
25793 \SpecialChar ~
25794 case 8: ...
25795  
25796 \newline 
25797 }\SpecialChar ~
25798 \SpecialChar ~
25799 \SpecialChar ~
25800 \SpecialChar ~
25801 \SpecialChar ~
25802 \SpecialChar ~
25803 \SpecialChar ~
25804 \SpecialChar ~
25805 \SpecialChar ~
25806 \SpecialChar ~
25807 \SpecialChar ~
25808 \SpecialChar ~
25809 \SpecialChar ~
25810 \SpecialChar ~
25811 \SpecialChar ~
25812 \SpecialChar ~
25813 \SpecialChar ~
25814 \SpecialChar ~
25815 \SpecialChar ~
25816 \SpecialChar ~
25817 \SpecialChar ~
25818 \SpecialChar ~
25819 \SpecialChar ~
25820 \SpecialChar ~
25821 \SpecialChar ~
25822 \SpecialChar ~
25823 \SpecialChar ~
25824 \SpecialChar ~
25825 \SpecialChar ~
25826 \SpecialChar ~
25827 \SpecialChar ~
25828 \SpecialChar ~
25829 \SpecialChar ~
25830 \SpecialChar ~
25831 \SpecialChar ~
25832 \SpecialChar ~
25833 }
25834 \layout Standard
25835
25836 Both the above switch statements will be implemented using a jump-table.
25837  The example to the right side is slightly more efficient as the check for
25838  the lower boundary of the jump-table is not needed.
25839 \end_deeper 
25840 \layout Itemize
25841
25842 The number of case labels is not larger than supported by the target architectur
25843 e.
25844 \layout Itemize
25845
25846 If the case labels are not in numerical sequence ('gaps' between cases)
25847  SDCC checks whether a jump table with additionally inserted dummy cases
25848  is still attractive.
25849  
25850 \layout Itemize
25851
25852 If the starting number is not zero and a check for the lower boundary of
25853  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
25854  ...
25855  .
25856 \layout Standard
25857
25858 Switch statements which have large gaps in the numeric sequence or those
25859  that have too many case labels can be split into more than one switch statement
25860  for efficient code generation, e.g.:
25861 \layout Verse
25862
25863
25864 \family typewriter 
25865 switch (i) { 
25866 \newline 
25867 \SpecialChar ~
25868 \SpecialChar ~
25869 case 1: ...
25870  
25871 \newline 
25872 \SpecialChar ~
25873 \SpecialChar ~
25874 case 2: ...
25875  
25876 \newline 
25877 \SpecialChar ~
25878 \SpecialChar ~
25879 case 3: ...
25880  
25881 \newline 
25882 \SpecialChar ~
25883 \SpecialChar ~
25884 case 4: ...
25885  
25886 \newline 
25887 \SpecialChar ~
25888 \SpecialChar ~
25889 case 5: ...
25890  
25891 \newline 
25892 \SpecialChar ~
25893 \SpecialChar ~
25894 case 6: ...
25895  
25896 \newline 
25897 \SpecialChar ~
25898 \SpecialChar ~
25899 case 7: ...
25900  
25901 \newline 
25902 \SpecialChar ~
25903 \SpecialChar ~
25904 case 101: ...
25905  
25906 \newline 
25907 \SpecialChar ~
25908 \SpecialChar ~
25909 case 102: ...
25910  
25911 \newline 
25912 \SpecialChar ~
25913 \SpecialChar ~
25914 case 103: ...
25915  
25916 \newline 
25917 \SpecialChar ~
25918 \SpecialChar ~
25919 case 104: ...
25920  
25921 \newline 
25922 \SpecialChar ~
25923 \SpecialChar ~
25924 case 105: ...
25925  
25926 \newline 
25927 \SpecialChar ~
25928 \SpecialChar ~
25929 case 106: ...
25930  
25931 \newline 
25932 \SpecialChar ~
25933 \SpecialChar ~
25934 case 107: ...
25935  
25936 \newline 
25937 }
25938 \layout Standard
25939
25940 If the above switch statement is broken down into two switch statements
25941 \layout Verse
25942
25943
25944 \family typewriter 
25945 switch (i) { 
25946 \newline 
25947 \SpecialChar ~
25948 \SpecialChar ~
25949 case 1: ...
25950  
25951 \newline 
25952 \SpecialChar ~
25953 \SpecialChar ~
25954 case 2: ...
25955  
25956 \newline 
25957 \SpecialChar ~
25958 \SpecialChar ~
25959 case 3: ...
25960  
25961 \newline 
25962 \SpecialChar ~
25963 \SpecialChar ~
25964 case 4: ...
25965  
25966 \newline 
25967 \SpecialChar ~
25968 \SpecialChar ~
25969 case 5: ...
25970  
25971 \newline 
25972 \SpecialChar ~
25973 \SpecialChar ~
25974 case 6: ...
25975  
25976 \newline 
25977 \SpecialChar ~
25978 \SpecialChar ~
25979 case 7: ...
25980  
25981 \newline 
25982 }
25983 \layout Standard
25984
25985 and
25986 \layout Verse
25987
25988
25989 \family typewriter 
25990 switch (i) { 
25991 \newline 
25992 \SpecialChar ~
25993 \SpecialChar ~
25994 case 101: ...
25995  
25996 \newline 
25997 \SpecialChar ~
25998 \SpecialChar ~
25999 case 102: ...
26000  
26001 \newline 
26002 \SpecialChar ~
26003 \SpecialChar ~
26004 case 103: ...
26005  
26006 \newline 
26007 \SpecialChar ~
26008 \SpecialChar ~
26009 case 104: ...
26010  
26011 \newline 
26012 \SpecialChar ~
26013 \SpecialChar ~
26014 case 105: ...
26015  
26016 \newline 
26017 \SpecialChar ~
26018 \SpecialChar ~
26019 case 106: ...
26020  
26021 \newline 
26022 \SpecialChar ~
26023 \SpecialChar ~
26024 case 107: ...
26025  
26026 \newline 
26027 }
26028 \layout Standard
26029
26030 then both the switch statements will be implemented using jump-tables whereas
26031  the unmodified switch statement will not be.
26032 \layout Comment
26033
26034 There might be reasons which SDCC cannot know about to either favour or
26035  not favour jump tables.
26036  If the target system has to be as quick for the last switch case as for
26037  the first (pro jump table), or if the switch argument is known to be zero
26038  in the majority of the cases (contra jump table).
26039 \layout Standard
26040
26041 The pragma nojtbound
26042 \begin_inset LatexCommand \index{\#pragma nojtbound}
26043
26044 \end_inset 
26045
26046  can be used to turn off checking the 
26047 \emph on 
26048 j
26049 \emph default 
26050 ump 
26051 \emph on 
26052 t
26053 \emph default 
26054 able 
26055 \emph on 
26056 bound
26057 \emph default 
26058 aries.
26059  It has no effect if a default label is supplied.
26060  Use of this pragma is dangerous: if the switch
26061 \begin_inset LatexCommand \index{switch statement}
26062
26063 \end_inset 
26064
26065  argument is not matched by a case statement the processor will happily
26066  jump into Nirvana.
26067 \layout Subsection
26068
26069 Bit-shifting Operations
26070 \begin_inset LatexCommand \index{Bit shifting}
26071
26072 \end_inset 
26073
26074 .
26075 \layout Standard
26076
26077 Bit shifting is one of the most frequently used operation in embedded programmin
26078 g.
26079  SDCC tries to implement bit-shift operations in the most efficient way
26080  possible, e.g.:
26081 \layout Verse
26082
26083
26084 \family typewriter 
26085 unsigned char i;
26086 \newline 
26087 ...
26088  
26089 \newline 
26090 i >>= 4; 
26091 \newline 
26092 ...
26093 \layout Standard
26094
26095 generates the following code:
26096 \layout Verse
26097
26098
26099 \family typewriter 
26100 mov\SpecialChar ~
26101  a,_i 
26102 \newline 
26103 swap a 
26104 \newline 
26105 anl\SpecialChar ~
26106  a,#0x0f 
26107 \newline 
26108 mov\SpecialChar ~
26109  _i,a
26110 \layout Standard
26111
26112 In general SDCC will never setup a loop if the shift count is known.
26113  Another example:
26114 \layout Verse
26115
26116
26117 \family typewriter 
26118 unsigned int i; 
26119 \newline 
26120 ...
26121  
26122 \newline 
26123 i >>= 9; 
26124 \newline 
26125 ...
26126 \layout Standard
26127
26128 will generate:
26129 \layout Verse
26130
26131
26132 \family typewriter 
26133 mov\SpecialChar ~
26134 \SpecialChar ~
26135 a,(_i + 1) 
26136 \newline 
26137 mov\SpecialChar ~
26138 \SpecialChar ~
26139 (_i + 1),#0x00 
26140 \newline 
26141 clr\SpecialChar ~
26142 \SpecialChar ~
26143
26144 \newline 
26145 rrc\SpecialChar ~
26146 \SpecialChar ~
26147
26148 \newline 
26149 mov\SpecialChar ~
26150 \SpecialChar ~
26151 _i,a
26152 \layout Subsection
26153
26154 Bit-rotation
26155 \begin_inset LatexCommand \index{Bit rotation}
26156
26157 \end_inset 
26158
26159
26160 \layout Standard
26161
26162 A special case of the bit-shift operation is bit rotation
26163 \begin_inset LatexCommand \index{rotating bits}
26164
26165 \end_inset 
26166
26167 , SDCC recognizes the following expression to be a left bit-rotation:
26168 \layout Verse
26169
26170
26171 \family typewriter 
26172 \series bold 
26173 unsigned
26174 \series default 
26175 \SpecialChar ~
26176 \SpecialChar ~
26177 char i;\SpecialChar ~
26178 \SpecialChar ~
26179 \SpecialChar ~
26180 \SpecialChar ~
26181 \SpecialChar ~
26182 \SpecialChar ~
26183 \SpecialChar ~
26184 \SpecialChar ~
26185 \SpecialChar ~
26186 \SpecialChar ~
26187 \SpecialChar ~
26188 /* unsigned is needed for rotation */ 
26189 \newline 
26190 ...
26191  
26192 \newline 
26193 i = ((i << 1) | (i >> 7)); 
26194 \family default 
26195
26196 \newline 
26197
26198 \family typewriter 
26199 ...
26200 \layout Standard
26201
26202 will generate the following code:
26203 \layout Verse
26204
26205
26206 \family typewriter 
26207 mov\SpecialChar ~
26208 \SpecialChar ~
26209 a,_i 
26210 \newline 
26211 rl\SpecialChar ~
26212 \SpecialChar ~
26213 \SpecialChar ~
26214
26215 \newline 
26216 mov\SpecialChar ~
26217 \SpecialChar ~
26218 _i,a
26219 \layout Standard
26220
26221 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
26222 ns of this case will also be recognized as bit-rotation, i.e.: 
26223 \layout Verse
26224
26225
26226 \family typewriter 
26227 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
26228 \layout Subsection
26229
26230 Nibble and Byte Swapping
26231 \layout Standard
26232
26233 Other special cases of the bit-shift operations are nibble or byte swapping
26234 \begin_inset LatexCommand \index{swapping nibbles/bytes}
26235
26236 \end_inset 
26237
26238 , SDCC recognizes the following expressions:
26239 \layout Verse
26240
26241
26242 \family typewriter 
26243 \series bold 
26244 unsigned
26245 \series default 
26246 \SpecialChar ~
26247 \SpecialChar ~
26248 char i; 
26249 \newline 
26250
26251 \series bold 
26252 unsigned
26253 \series default 
26254 \SpecialChar ~
26255 \SpecialChar ~
26256 int j; 
26257 \newline 
26258 ...
26259  
26260 \newline 
26261 i = ((i << 4) | (i >> 4)); 
26262 \family default 
26263
26264 \newline 
26265
26266 \family typewriter 
26267 j = ((j << 8) | (j >> 8)); 
26268 \layout Standard
26269
26270 and generates a swap instruction for the nibble swapping
26271 \begin_inset LatexCommand \index{Nibble swapping}
26272
26273 \end_inset 
26274
26275  or move instructions for the byte swapping
26276 \begin_inset LatexCommand \index{Byte swapping}
26277
26278 \end_inset 
26279
26280 .
26281  The 
26282 \begin_inset Quotes sld
26283 \end_inset 
26284
26285 j
26286 \begin_inset Quotes srd
26287 \end_inset 
26288
26289  example can be used to convert from little to big-endian or vice versa.
26290  If you want to change the endianness of a 
26291 \emph on 
26292 signed
26293 \emph default 
26294  integer you have to cast to 
26295 \family typewriter 
26296 (unsigned int)
26297 \family default 
26298  first.
26299 \layout Standard
26300
26301 Note that SDCC stores numbers in little-endian
26302 \begin_inset Foot
26303 collapsed false
26304
26305 \layout Standard
26306
26307 Usually 8-bit processors don't care much about endianness.
26308  This is not the case for the standard 8051 which only has an instruction
26309  to increment its 
26310 \emph on 
26311 dptr
26312 \emph default 
26313
26314 \begin_inset LatexCommand \index{DPTR}
26315
26316 \end_inset 
26317
26318 -datapointer
26319 \emph on 
26320  
26321 \emph default 
26322 so little-endian is the more efficient byte order.
26323 \end_inset 
26324
26325
26326 \begin_inset LatexCommand \index{little-endian}
26327
26328 \end_inset 
26329
26330
26331 \begin_inset LatexCommand \index{Endianness}
26332
26333 \end_inset 
26334
26335  format (i.e.
26336  lowest order first).
26337 \layout Subsection
26338
26339 Highest Order Bit
26340 \begin_inset LatexCommand \index{Highest Order Bit}
26341
26342 \end_inset 
26343
26344  / Any Order Bit
26345 \begin_inset LatexCommand \index{Any Order Bit}
26346
26347 \end_inset 
26348
26349
26350 \layout Standard
26351
26352 It is frequently required to obtain the highest order bit of an integral
26353  type (long, int, short or char types).
26354  Also obtaining any other order bit is not uncommon.
26355  SDCC recognizes the following expressions to yield the highest order bit
26356  and generates optimized code for it, e.g.:
26357 \layout Verse
26358
26359
26360 \family typewriter 
26361 unsigned int gint; 
26362 \newline 
26363
26364 \newline 
26365 foo () { 
26366 \newline 
26367 \SpecialChar ~
26368 \SpecialChar ~
26369 unsigned char hob1, aob1; 
26370 \newline 
26371 \SpecialChar ~
26372 \SpecialChar ~
26373 bit hob2, hob3, aob2, aob3; 
26374 \newline 
26375 \SpecialChar ~
26376 \SpecialChar ~
26377 ...
26378  
26379 \newline 
26380 \SpecialChar ~
26381 \SpecialChar ~
26382 hob1 = (gint >> 15) & 1; 
26383 \newline 
26384 \SpecialChar ~
26385 \SpecialChar ~
26386 hob2 = (gint >> 15) & 1; 
26387 \newline 
26388 \SpecialChar ~
26389 \SpecialChar ~
26390 hob3 = gint & 0x8000; 
26391 \newline 
26392 \SpecialChar ~
26393 \SpecialChar ~
26394 aob1 = (gint >> 9) & 1; 
26395 \newline 
26396 \SpecialChar ~
26397 \SpecialChar ~
26398 aob2 = (gint >> 8) & 1; 
26399 \newline 
26400 \SpecialChar ~
26401 \SpecialChar ~
26402 aob3 = gint & 0x0800; 
26403 \newline 
26404 \SpecialChar ~
26405 \SpecialChar ~
26406 ..
26407  
26408 \newline 
26409 }
26410 \layout Standard
26411
26412 will generate the following code:
26413 \layout Verse
26414
26415
26416 \family typewriter 
26417 \SpecialChar ~
26418 \SpecialChar ~
26419 \SpecialChar ~
26420 \SpecialChar ~
26421 \SpecialChar ~
26422 \SpecialChar ~
26423 \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 \SpecialChar ~
26439 \SpecialChar ~
26440 \SpecialChar ~
26441 \SpecialChar ~
26442  61 ;\SpecialChar ~
26443  hob.c 7 
26444 \newline 
26445 000A E5*01\SpecialChar ~
26446 \SpecialChar ~
26447 \SpecialChar ~
26448 \SpecialChar ~
26449 \SpecialChar ~
26450 \SpecialChar ~
26451 \SpecialChar ~
26452 \SpecialChar ~
26453 \SpecialChar ~
26454 \SpecialChar ~
26455 \SpecialChar ~
26456 \SpecialChar ~
26457 \SpecialChar ~
26458 \SpecialChar ~
26459 \SpecialChar ~
26460  62\SpecialChar ~
26461 \SpecialChar ~
26462 \SpecialChar ~
26463 \SpecialChar ~
26464 \SpecialChar ~
26465 \SpecialChar ~
26466 \SpecialChar ~
26467 \SpecialChar ~
26468  mov\SpecialChar ~
26469 \SpecialChar ~
26470  a,(_gint + 1) 
26471 \newline 
26472 000C 23\SpecialChar ~
26473 \SpecialChar ~
26474 \SpecialChar ~
26475 \SpecialChar ~
26476 \SpecialChar ~
26477 \SpecialChar ~
26478 \SpecialChar ~
26479 \SpecialChar ~
26480 \SpecialChar ~
26481 \SpecialChar ~
26482 \SpecialChar ~
26483 \SpecialChar ~
26484 \SpecialChar ~
26485 \SpecialChar ~
26486 \SpecialChar ~
26487 \SpecialChar ~
26488 \SpecialChar ~
26489 \SpecialChar ~
26490  63\SpecialChar ~
26491 \SpecialChar ~
26492 \SpecialChar ~
26493 \SpecialChar ~
26494 \SpecialChar ~
26495 \SpecialChar ~
26496 \SpecialChar ~
26497 \SpecialChar ~
26498  rl\SpecialChar ~
26499 \SpecialChar ~
26500 \SpecialChar ~
26501  a 
26502 \newline 
26503 000D 54 01\SpecialChar ~
26504 \SpecialChar ~
26505 \SpecialChar ~
26506 \SpecialChar ~
26507 \SpecialChar ~
26508 \SpecialChar ~
26509 \SpecialChar ~
26510 \SpecialChar ~
26511 \SpecialChar ~
26512 \SpecialChar ~
26513 \SpecialChar ~
26514 \SpecialChar ~
26515 \SpecialChar ~
26516 \SpecialChar ~
26517 \SpecialChar ~
26518  64\SpecialChar ~
26519 \SpecialChar ~
26520 \SpecialChar ~
26521 \SpecialChar ~
26522 \SpecialChar ~
26523 \SpecialChar ~
26524 \SpecialChar ~
26525 \SpecialChar ~
26526  anl\SpecialChar ~
26527 \SpecialChar ~
26528  a,#0x01 
26529 \newline 
26530 000F F5*02\SpecialChar ~
26531 \SpecialChar ~
26532 \SpecialChar ~
26533 \SpecialChar ~
26534 \SpecialChar ~
26535 \SpecialChar ~
26536 \SpecialChar ~
26537 \SpecialChar ~
26538 \SpecialChar ~
26539 \SpecialChar ~
26540 \SpecialChar ~
26541 \SpecialChar ~
26542 \SpecialChar ~
26543 \SpecialChar ~
26544 \SpecialChar ~
26545  65\SpecialChar ~
26546 \SpecialChar ~
26547 \SpecialChar ~
26548 \SpecialChar ~
26549 \SpecialChar ~
26550 \SpecialChar ~
26551 \SpecialChar ~
26552 \SpecialChar ~
26553  mov\SpecialChar ~
26554 \SpecialChar ~
26555  _foo_hob1_1_1,a 
26556 \newline 
26557 \SpecialChar ~
26558 \SpecialChar ~
26559 \SpecialChar ~
26560 \SpecialChar ~
26561 \SpecialChar ~
26562 \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 \SpecialChar ~
26581 \SpecialChar ~
26582  66 ;\SpecialChar ~
26583  hob.c 8 
26584 \newline 
26585 0011 E5*01\SpecialChar ~
26586 \SpecialChar ~
26587 \SpecialChar ~
26588 \SpecialChar ~
26589 \SpecialChar ~
26590 \SpecialChar ~
26591 \SpecialChar ~
26592 \SpecialChar ~
26593 \SpecialChar ~
26594 \SpecialChar ~
26595 \SpecialChar ~
26596 \SpecialChar ~
26597 \SpecialChar ~
26598 \SpecialChar ~
26599 \SpecialChar ~
26600  67\SpecialChar ~
26601 \SpecialChar ~
26602 \SpecialChar ~
26603 \SpecialChar ~
26604 \SpecialChar ~
26605 \SpecialChar ~
26606 \SpecialChar ~
26607 \SpecialChar ~
26608  mov\SpecialChar ~
26609 \SpecialChar ~
26610  a,(_gint + 1) 
26611 \newline 
26612 0013 33\SpecialChar ~
26613 \SpecialChar ~
26614 \SpecialChar ~
26615 \SpecialChar ~
26616 \SpecialChar ~
26617 \SpecialChar ~
26618 \SpecialChar ~
26619 \SpecialChar ~
26620 \SpecialChar ~
26621 \SpecialChar ~
26622 \SpecialChar ~
26623 \SpecialChar ~
26624 \SpecialChar ~
26625 \SpecialChar ~
26626 \SpecialChar ~
26627 \SpecialChar ~
26628 \SpecialChar ~
26629 \SpecialChar ~
26630  68\SpecialChar ~
26631 \SpecialChar ~
26632 \SpecialChar ~
26633 \SpecialChar ~
26634 \SpecialChar ~
26635 \SpecialChar ~
26636 \SpecialChar ~
26637 \SpecialChar ~
26638  rlc\SpecialChar ~
26639 \SpecialChar ~
26640  a 
26641 \newline 
26642 0014 92*00\SpecialChar ~
26643 \SpecialChar ~
26644 \SpecialChar ~
26645 \SpecialChar ~
26646 \SpecialChar ~
26647 \SpecialChar ~
26648 \SpecialChar ~
26649 \SpecialChar ~
26650 \SpecialChar ~
26651 \SpecialChar ~
26652 \SpecialChar ~
26653 \SpecialChar ~
26654 \SpecialChar ~
26655 \SpecialChar ~
26656 \SpecialChar ~
26657  69\SpecialChar ~
26658 \SpecialChar ~
26659 \SpecialChar ~
26660 \SpecialChar ~
26661 \SpecialChar ~
26662 \SpecialChar ~
26663 \SpecialChar ~
26664 \SpecialChar ~
26665  mov\SpecialChar ~
26666 \SpecialChar ~
26667  _foo_hob2_1_1,c 
26668 \newline 
26669 \SpecialChar ~
26670 \SpecialChar ~
26671 \SpecialChar ~
26672 \SpecialChar ~
26673 \SpecialChar ~
26674 \SpecialChar ~
26675 \SpecialChar ~
26676 \SpecialChar ~
26677 \SpecialChar ~
26678 \SpecialChar ~
26679 \SpecialChar ~
26680 \SpecialChar ~
26681 \SpecialChar ~
26682 \SpecialChar ~
26683 \SpecialChar ~
26684 \SpecialChar ~
26685 \SpecialChar ~
26686 \SpecialChar ~
26687 \SpecialChar ~
26688 \SpecialChar ~
26689 \SpecialChar ~
26690 \SpecialChar ~
26691 \SpecialChar ~
26692 \SpecialChar ~
26693 \SpecialChar ~
26694  66 ;\SpecialChar ~
26695  hob.c 9 
26696 \newline 
26697 0016 E5*01\SpecialChar ~
26698 \SpecialChar ~
26699 \SpecialChar ~
26700 \SpecialChar ~
26701 \SpecialChar ~
26702 \SpecialChar ~
26703 \SpecialChar ~
26704 \SpecialChar ~
26705 \SpecialChar ~
26706 \SpecialChar ~
26707 \SpecialChar ~
26708 \SpecialChar ~
26709 \SpecialChar ~
26710 \SpecialChar ~
26711 \SpecialChar ~
26712  67\SpecialChar ~
26713 \SpecialChar ~
26714 \SpecialChar ~
26715 \SpecialChar ~
26716 \SpecialChar ~
26717 \SpecialChar ~
26718 \SpecialChar ~
26719 \SpecialChar ~
26720  mov\SpecialChar ~
26721 \SpecialChar ~
26722  a,(_gint + 1) 
26723 \newline 
26724 0018 33\SpecialChar ~
26725 \SpecialChar ~
26726 \SpecialChar ~
26727 \SpecialChar ~
26728 \SpecialChar ~
26729 \SpecialChar ~
26730 \SpecialChar ~
26731 \SpecialChar ~
26732 \SpecialChar ~
26733 \SpecialChar ~
26734 \SpecialChar ~
26735 \SpecialChar ~
26736 \SpecialChar ~
26737 \SpecialChar ~
26738 \SpecialChar ~
26739 \SpecialChar ~
26740 \SpecialChar ~
26741 \SpecialChar ~
26742  68\SpecialChar ~
26743 \SpecialChar ~
26744 \SpecialChar ~
26745 \SpecialChar ~
26746 \SpecialChar ~
26747 \SpecialChar ~
26748 \SpecialChar ~
26749 \SpecialChar ~
26750  rlc\SpecialChar ~
26751 \SpecialChar ~
26752  a 
26753 \newline 
26754 0019 92*01\SpecialChar ~
26755 \SpecialChar ~
26756 \SpecialChar ~
26757 \SpecialChar ~
26758 \SpecialChar ~
26759 \SpecialChar ~
26760 \SpecialChar ~
26761 \SpecialChar ~
26762 \SpecialChar ~
26763 \SpecialChar ~
26764 \SpecialChar ~
26765 \SpecialChar ~
26766 \SpecialChar ~
26767 \SpecialChar ~
26768 \SpecialChar ~
26769  69\SpecialChar ~
26770 \SpecialChar ~
26771 \SpecialChar ~
26772 \SpecialChar ~
26773 \SpecialChar ~
26774 \SpecialChar ~
26775 \SpecialChar ~
26776 \SpecialChar ~
26777  mov\SpecialChar ~
26778 \SpecialChar ~
26779  _foo_hob3_1_1,c 
26780 \newline 
26781 \SpecialChar ~
26782 \SpecialChar ~
26783 \SpecialChar ~
26784 \SpecialChar ~
26785 \SpecialChar ~
26786 \SpecialChar ~
26787 \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 \SpecialChar ~
26803 \SpecialChar ~
26804 \SpecialChar ~
26805 \SpecialChar ~
26806  70 ;\SpecialChar ~
26807  hob.c 10 
26808 \newline 
26809 001B E5*01\SpecialChar ~
26810 \SpecialChar ~
26811 \SpecialChar ~
26812 \SpecialChar ~
26813 \SpecialChar ~
26814 \SpecialChar ~
26815 \SpecialChar ~
26816 \SpecialChar ~
26817 \SpecialChar ~
26818 \SpecialChar ~
26819 \SpecialChar ~
26820 \SpecialChar ~
26821 \SpecialChar ~
26822 \SpecialChar ~
26823 \SpecialChar ~
26824  71\SpecialChar ~
26825 \SpecialChar ~
26826 \SpecialChar ~
26827 \SpecialChar ~
26828 \SpecialChar ~
26829 \SpecialChar ~
26830 \SpecialChar ~
26831 \SpecialChar ~
26832  mov\SpecialChar ~
26833 \SpecialChar ~
26834  a,(_gint + 1) 
26835 \newline 
26836 001D 03\SpecialChar ~
26837 \SpecialChar ~
26838 \SpecialChar ~
26839 \SpecialChar ~
26840 \SpecialChar ~
26841 \SpecialChar ~
26842 \SpecialChar ~
26843 \SpecialChar ~
26844 \SpecialChar ~
26845 \SpecialChar ~
26846 \SpecialChar ~
26847 \SpecialChar ~
26848 \SpecialChar ~
26849 \SpecialChar ~
26850 \SpecialChar ~
26851 \SpecialChar ~
26852 \SpecialChar ~
26853 \SpecialChar ~
26854  72\SpecialChar ~
26855 \SpecialChar ~
26856 \SpecialChar ~
26857 \SpecialChar ~
26858 \SpecialChar ~
26859 \SpecialChar ~
26860 \SpecialChar ~
26861 \SpecialChar ~
26862  rr\SpecialChar ~
26863 \SpecialChar ~
26864 \SpecialChar ~
26865  a 
26866 \newline 
26867 001E 54 01\SpecialChar ~
26868 \SpecialChar ~
26869 \SpecialChar ~
26870 \SpecialChar ~
26871 \SpecialChar ~
26872 \SpecialChar ~
26873 \SpecialChar ~
26874 \SpecialChar ~
26875 \SpecialChar ~
26876 \SpecialChar ~
26877 \SpecialChar ~
26878 \SpecialChar ~
26879 \SpecialChar ~
26880 \SpecialChar ~
26881 \SpecialChar ~
26882  73\SpecialChar ~
26883 \SpecialChar ~
26884 \SpecialChar ~
26885 \SpecialChar ~
26886 \SpecialChar ~
26887 \SpecialChar ~
26888 \SpecialChar ~
26889 \SpecialChar ~
26890  anl\SpecialChar ~
26891 \SpecialChar ~
26892  a,#0x01 
26893 \newline 
26894 0020 F5*03\SpecialChar ~
26895 \SpecialChar ~
26896 \SpecialChar ~
26897 \SpecialChar ~
26898 \SpecialChar ~
26899 \SpecialChar ~
26900 \SpecialChar ~
26901 \SpecialChar ~
26902 \SpecialChar ~
26903 \SpecialChar ~
26904 \SpecialChar ~
26905 \SpecialChar ~
26906 \SpecialChar ~
26907 \SpecialChar ~
26908 \SpecialChar ~
26909  74\SpecialChar ~
26910 \SpecialChar ~
26911 \SpecialChar ~
26912 \SpecialChar ~
26913 \SpecialChar ~
26914 \SpecialChar ~
26915 \SpecialChar ~
26916 \SpecialChar ~
26917  mov\SpecialChar ~
26918 \SpecialChar ~
26919  _foo_aob1_1_1,a 
26920 \newline 
26921 \SpecialChar ~
26922 \SpecialChar ~
26923 \SpecialChar ~
26924 \SpecialChar ~
26925 \SpecialChar ~
26926 \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 \SpecialChar ~
26942 \SpecialChar ~
26943 \SpecialChar ~
26944 \SpecialChar ~
26945 \SpecialChar ~
26946  75 ;\SpecialChar ~
26947  hob.c 11 
26948 \newline 
26949 0022 E5*01\SpecialChar ~
26950 \SpecialChar ~
26951 \SpecialChar ~
26952 \SpecialChar ~
26953 \SpecialChar ~
26954 \SpecialChar ~
26955 \SpecialChar ~
26956 \SpecialChar ~
26957 \SpecialChar ~
26958 \SpecialChar ~
26959 \SpecialChar ~
26960 \SpecialChar ~
26961 \SpecialChar ~
26962 \SpecialChar ~
26963 \SpecialChar ~
26964  76\SpecialChar ~
26965 \SpecialChar ~
26966 \SpecialChar ~
26967 \SpecialChar ~
26968 \SpecialChar ~
26969 \SpecialChar ~
26970 \SpecialChar ~
26971 \SpecialChar ~
26972  mov\SpecialChar ~
26973 \SpecialChar ~
26974  a,(_gint + 1) 
26975 \newline 
26976 0024 13\SpecialChar ~
26977 \SpecialChar ~
26978 \SpecialChar ~
26979 \SpecialChar ~
26980 \SpecialChar ~
26981 \SpecialChar ~
26982 \SpecialChar ~
26983 \SpecialChar ~
26984 \SpecialChar ~
26985 \SpecialChar ~
26986 \SpecialChar ~
26987 \SpecialChar ~
26988 \SpecialChar ~
26989 \SpecialChar ~
26990 \SpecialChar ~
26991 \SpecialChar ~
26992 \SpecialChar ~
26993 \SpecialChar ~
26994  77\SpecialChar ~
26995 \SpecialChar ~
26996 \SpecialChar ~
26997 \SpecialChar ~
26998 \SpecialChar ~
26999 \SpecialChar ~
27000 \SpecialChar ~
27001 \SpecialChar ~
27002  rrc\SpecialChar ~
27003 \SpecialChar ~
27004  a 
27005 \newline 
27006 0025 92*02\SpecialChar ~
27007 \SpecialChar ~
27008 \SpecialChar ~
27009 \SpecialChar ~
27010 \SpecialChar ~
27011 \SpecialChar ~
27012 \SpecialChar ~
27013 \SpecialChar ~
27014 \SpecialChar ~
27015 \SpecialChar ~
27016 \SpecialChar ~
27017 \SpecialChar ~
27018 \SpecialChar ~
27019 \SpecialChar ~
27020 \SpecialChar ~
27021  78\SpecialChar ~
27022 \SpecialChar ~
27023 \SpecialChar ~
27024 \SpecialChar ~
27025 \SpecialChar ~
27026 \SpecialChar ~
27027 \SpecialChar ~
27028 \SpecialChar ~
27029  mov\SpecialChar ~
27030 \SpecialChar ~
27031  _foo_aob2_1_1,c 
27032 \newline 
27033 \SpecialChar ~
27034 \SpecialChar ~
27035 \SpecialChar ~
27036 \SpecialChar ~
27037 \SpecialChar ~
27038 \SpecialChar ~
27039 \SpecialChar ~
27040 \SpecialChar ~
27041 \SpecialChar ~
27042 \SpecialChar ~
27043 \SpecialChar ~
27044 \SpecialChar ~
27045 \SpecialChar ~
27046 \SpecialChar ~
27047 \SpecialChar ~
27048 \SpecialChar ~
27049 \SpecialChar ~
27050 \SpecialChar ~
27051 \SpecialChar ~
27052 \SpecialChar ~
27053 \SpecialChar ~
27054 \SpecialChar ~
27055 \SpecialChar ~
27056 \SpecialChar ~
27057 \SpecialChar ~
27058  79 ;\SpecialChar ~
27059  hob.c 12 
27060 \newline 
27061 0027 E5*01\SpecialChar ~
27062 \SpecialChar ~
27063 \SpecialChar ~
27064 \SpecialChar ~
27065 \SpecialChar ~
27066 \SpecialChar ~
27067 \SpecialChar ~
27068 \SpecialChar ~
27069 \SpecialChar ~
27070 \SpecialChar ~
27071 \SpecialChar ~
27072 \SpecialChar ~
27073 \SpecialChar ~
27074 \SpecialChar ~
27075 \SpecialChar ~
27076  80\SpecialChar ~
27077 \SpecialChar ~
27078 \SpecialChar ~
27079 \SpecialChar ~
27080 \SpecialChar ~
27081 \SpecialChar ~
27082 \SpecialChar ~
27083 \SpecialChar ~
27084  mov\SpecialChar ~
27085 \SpecialChar ~
27086  a,(_gint + 1) 
27087 \newline 
27088 0029 A2 E3\SpecialChar ~
27089 \SpecialChar ~
27090 \SpecialChar ~
27091 \SpecialChar ~
27092 \SpecialChar ~
27093 \SpecialChar ~
27094 \SpecialChar ~
27095 \SpecialChar ~
27096 \SpecialChar ~
27097 \SpecialChar ~
27098 \SpecialChar ~
27099 \SpecialChar ~
27100 \SpecialChar ~
27101 \SpecialChar ~
27102 \SpecialChar ~
27103  81\SpecialChar ~
27104 \SpecialChar ~
27105 \SpecialChar ~
27106 \SpecialChar ~
27107 \SpecialChar ~
27108 \SpecialChar ~
27109 \SpecialChar ~
27110 \SpecialChar ~
27111  mov\SpecialChar ~
27112 \SpecialChar ~
27113  c,acc[3] 
27114 \newline 
27115 002B 92*03\SpecialChar ~
27116 \SpecialChar ~
27117 \SpecialChar ~
27118 \SpecialChar ~
27119 \SpecialChar ~
27120 \SpecialChar ~
27121 \SpecialChar ~
27122 \SpecialChar ~
27123 \SpecialChar ~
27124 \SpecialChar ~
27125 \SpecialChar ~
27126 \SpecialChar ~
27127 \SpecialChar ~
27128 \SpecialChar ~
27129 \SpecialChar ~
27130  82\SpecialChar ~
27131 \SpecialChar ~
27132 \SpecialChar ~
27133 \SpecialChar ~
27134 \SpecialChar ~
27135 \SpecialChar ~
27136 \SpecialChar ~
27137 \SpecialChar ~
27138  mov\SpecialChar ~
27139 \SpecialChar ~
27140  _foo_aob3_1_1,c 
27141 \layout Standard
27142
27143 Other variations of these cases however will 
27144 \emph on 
27145 not
27146 \emph default 
27147  be recognized.
27148  They are standard C expressions, so I heartily recommend these be the only
27149  way to get the highest order bit, (it is portable).
27150  Of course it will be recognized even if it is embedded in other expressions,
27151  e.g.:
27152 \layout Verse
27153
27154
27155 \family typewriter 
27156 xyz = gint + ((gint >> 15) & 1);
27157 \layout Standard
27158
27159 will still be recognized.
27160 \layout Subsection
27161
27162 Higher Order Byte
27163 \begin_inset LatexCommand \index{Higher Order Byte}
27164
27165 \end_inset 
27166
27167  / Higher Order Word
27168 \begin_inset LatexCommand \index{Higher Order Word}
27169
27170 \end_inset 
27171
27172
27173 \layout Standard
27174
27175 It is also frequently required to obtain a higher order byte or word of
27176  a larger integral type (long, int or short types).
27177  SDCC recognizes the following expressions to yield the higher order byte
27178  or word and generates optimized code for it, e.g.:
27179 \layout Verse
27180
27181
27182 \family typewriter 
27183 unsigned int gint; 
27184 \newline 
27185 unsigned long int glong; 
27186 \newline 
27187
27188 \newline 
27189 foo () { 
27190 \newline 
27191 \SpecialChar ~
27192 \SpecialChar ~
27193 unsigned char hob1, hob2; 
27194 \newline 
27195 \SpecialChar ~
27196 \SpecialChar ~
27197 unsigned int how1, how2; 
27198 \newline 
27199 \SpecialChar ~
27200 \SpecialChar ~
27201 ...
27202  
27203 \newline 
27204 \SpecialChar ~
27205 \SpecialChar ~
27206 hob1 = (gint >> 8) & 0xFF; 
27207 \newline 
27208 \SpecialChar ~
27209 \SpecialChar ~
27210 hob2 = glong >> 24; 
27211 \newline 
27212 \SpecialChar ~
27213 \SpecialChar ~
27214 how1 = (glong >> 16) & 0xFFFF; 
27215 \newline 
27216 \SpecialChar ~
27217 \SpecialChar ~
27218 how2 = glong >> 8; 
27219 \newline 
27220 \SpecialChar ~
27221 \SpecialChar ~
27222 ..
27223  
27224 \newline 
27225 }
27226 \layout Standard
27227
27228 will generate the following code:
27229 \layout Verse
27230
27231
27232 \family typewriter 
27233 \SpecialChar ~
27234 \SpecialChar ~
27235 \SpecialChar ~
27236 \SpecialChar ~
27237 \SpecialChar ~
27238 \SpecialChar ~
27239 \SpecialChar ~
27240 \SpecialChar ~
27241 \SpecialChar ~
27242 \SpecialChar ~
27243 \SpecialChar ~
27244 \SpecialChar ~
27245 \SpecialChar ~
27246 \SpecialChar ~
27247 \SpecialChar ~
27248 \SpecialChar ~
27249 \SpecialChar ~
27250 \SpecialChar ~
27251 \SpecialChar ~
27252 \SpecialChar ~
27253 \SpecialChar ~
27254 \SpecialChar ~
27255 \SpecialChar ~
27256 \SpecialChar ~
27257 \SpecialChar ~
27258  91 ;\SpecialChar ~
27259  hob.c 15 
27260 \newline 
27261 0037 85*01*06\SpecialChar ~
27262 \SpecialChar ~
27263 \SpecialChar ~
27264 \SpecialChar ~
27265 \SpecialChar ~
27266 \SpecialChar ~
27267 \SpecialChar ~
27268 \SpecialChar ~
27269 \SpecialChar ~
27270 \SpecialChar ~
27271 \SpecialChar ~
27272 \SpecialChar ~
27273  92\SpecialChar ~
27274 \SpecialChar ~
27275 \SpecialChar ~
27276 \SpecialChar ~
27277 \SpecialChar ~
27278 \SpecialChar ~
27279 \SpecialChar ~
27280 \SpecialChar ~
27281  mov\SpecialChar ~
27282 \SpecialChar ~
27283  _foo_hob1_1_1,(_gint + 1) 
27284 \newline 
27285 \SpecialChar ~
27286 \SpecialChar ~
27287 \SpecialChar ~
27288 \SpecialChar ~
27289 \SpecialChar ~
27290 \SpecialChar ~
27291 \SpecialChar ~
27292 \SpecialChar ~
27293 \SpecialChar ~
27294 \SpecialChar ~
27295 \SpecialChar ~
27296 \SpecialChar ~
27297 \SpecialChar ~
27298 \SpecialChar ~
27299 \SpecialChar ~
27300 \SpecialChar ~
27301 \SpecialChar ~
27302 \SpecialChar ~
27303 \SpecialChar ~
27304 \SpecialChar ~
27305 \SpecialChar ~
27306 \SpecialChar ~
27307 \SpecialChar ~
27308 \SpecialChar ~
27309 \SpecialChar ~
27310  93 ;\SpecialChar ~
27311  hob.c 16 
27312 \newline 
27313 003A 85*05*07\SpecialChar ~
27314 \SpecialChar ~
27315 \SpecialChar ~
27316 \SpecialChar ~
27317 \SpecialChar ~
27318 \SpecialChar ~
27319 \SpecialChar ~
27320 \SpecialChar ~
27321 \SpecialChar ~
27322 \SpecialChar ~
27323 \SpecialChar ~
27324 \SpecialChar ~
27325  94\SpecialChar ~
27326 \SpecialChar ~
27327 \SpecialChar ~
27328 \SpecialChar ~
27329 \SpecialChar ~
27330 \SpecialChar ~
27331 \SpecialChar ~
27332 \SpecialChar ~
27333  mov\SpecialChar ~
27334 \SpecialChar ~
27335  _foo_hob2_1_1,(_glong + 3) 
27336 \newline 
27337 \SpecialChar ~
27338 \SpecialChar ~
27339 \SpecialChar ~
27340 \SpecialChar ~
27341 \SpecialChar ~
27342 \SpecialChar ~
27343 \SpecialChar ~
27344 \SpecialChar ~
27345 \SpecialChar ~
27346 \SpecialChar ~
27347 \SpecialChar ~
27348 \SpecialChar ~
27349 \SpecialChar ~
27350 \SpecialChar ~
27351 \SpecialChar ~
27352 \SpecialChar ~
27353 \SpecialChar ~
27354 \SpecialChar ~
27355 \SpecialChar ~
27356 \SpecialChar ~
27357 \SpecialChar ~
27358 \SpecialChar ~
27359 \SpecialChar ~
27360 \SpecialChar ~
27361 \SpecialChar ~
27362  95 ;\SpecialChar ~
27363  hob.c 17 
27364 \newline 
27365 003D 85*04*08\SpecialChar ~
27366 \SpecialChar ~
27367 \SpecialChar ~
27368 \SpecialChar ~
27369 \SpecialChar ~
27370 \SpecialChar ~
27371 \SpecialChar ~
27372 \SpecialChar ~
27373 \SpecialChar ~
27374 \SpecialChar ~
27375 \SpecialChar ~
27376 \SpecialChar ~
27377  96\SpecialChar ~
27378 \SpecialChar ~
27379 \SpecialChar ~
27380 \SpecialChar ~
27381 \SpecialChar ~
27382 \SpecialChar ~
27383 \SpecialChar ~
27384 \SpecialChar ~
27385  mov\SpecialChar ~
27386 \SpecialChar ~
27387  _foo_how1_1_1,(_glong + 2) 
27388 \newline 
27389 0040 85*05*09\SpecialChar ~
27390 \SpecialChar ~
27391 \SpecialChar ~
27392 \SpecialChar ~
27393 \SpecialChar ~
27394 \SpecialChar ~
27395 \SpecialChar ~
27396 \SpecialChar ~
27397 \SpecialChar ~
27398 \SpecialChar ~
27399 \SpecialChar ~
27400 \SpecialChar ~
27401  97\SpecialChar ~
27402 \SpecialChar ~
27403 \SpecialChar ~
27404 \SpecialChar ~
27405 \SpecialChar ~
27406 \SpecialChar ~
27407 \SpecialChar ~
27408 \SpecialChar ~
27409  mov\SpecialChar ~
27410 \SpecialChar ~
27411  (_foo_how1_1_1 + 1),(_glong + 3) 
27412 \newline 
27413 0043 85*03*0A\SpecialChar ~
27414 \SpecialChar ~
27415 \SpecialChar ~
27416 \SpecialChar ~
27417 \SpecialChar ~
27418 \SpecialChar ~
27419 \SpecialChar ~
27420 \SpecialChar ~
27421 \SpecialChar ~
27422 \SpecialChar ~
27423 \SpecialChar ~
27424 \SpecialChar ~
27425  98\SpecialChar ~
27426 \SpecialChar ~
27427 \SpecialChar ~
27428 \SpecialChar ~
27429 \SpecialChar ~
27430 \SpecialChar ~
27431 \SpecialChar ~
27432 \SpecialChar ~
27433  mov\SpecialChar ~
27434 \SpecialChar ~
27435  _foo_how2_1_1,(_glong + 1) 
27436 \newline 
27437 0046 85*04*0B\SpecialChar ~
27438 \SpecialChar ~
27439 \SpecialChar ~
27440 \SpecialChar ~
27441 \SpecialChar ~
27442 \SpecialChar ~
27443 \SpecialChar ~
27444 \SpecialChar ~
27445 \SpecialChar ~
27446 \SpecialChar ~
27447 \SpecialChar ~
27448 \SpecialChar ~
27449  99\SpecialChar ~
27450 \SpecialChar ~
27451 \SpecialChar ~
27452 \SpecialChar ~
27453 \SpecialChar ~
27454 \SpecialChar ~
27455 \SpecialChar ~
27456 \SpecialChar ~
27457  mov\SpecialChar ~
27458 \SpecialChar ~
27459  (_foo_how2_1_1 + 1),(_glong + 2) 
27460 \layout Standard
27461
27462 Again, variations of these cases may 
27463 \emph on 
27464 not
27465 \emph default 
27466  be recognized.
27467  They are standard C expressions, so I heartily recommend these be the only
27468  way to get the higher order byte/word, (it is portable).
27469  Of course it will be recognized even if it is embedded in other expressions,
27470  e.g.:
27471 \layout Verse
27472
27473
27474 \family typewriter 
27475 xyz = gint + ((gint >> 8) & 0xFF);
27476 \layout Standard
27477
27478 will still be recognized.
27479 \layout Subsection
27480
27481 Peephole Optimizer
27482 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
27483
27484 \end_inset 
27485
27486
27487 \begin_inset LatexCommand \index{Peephole optimizer}
27488
27489 \end_inset 
27490
27491
27492 \layout Standard
27493
27494 The compiler uses a rule based, pattern matching and re-writing mechanism
27495  for peep-hole optimization.
27496  It is inspired by 
27497 \emph on 
27498 copt
27499 \emph default 
27500  a peep-hole optimizer by Christopher W.
27501  Fraser (cwfraser\SpecialChar ~
27502 @\SpecialChar ~
27503 microsoft.com).
27504  A default set of rules are compiled into the compiler, additional rules
27505  may be added with the 
27506 \emph on 
27507 -
27508 \begin_inset ERT
27509 status Collapsed
27510
27511 \layout Standard
27512
27513 \backslash 
27514 /
27515 \end_inset 
27516
27517 -peep-file
27518 \begin_inset LatexCommand \index{-\/-peep-file}
27519
27520 \end_inset 
27521
27522  <filename>
27523 \emph default 
27524  option.
27525  The rule language is best illustrated with examples.
27526 \layout Verse
27527
27528
27529 \family typewriter 
27530 replace { 
27531 \newline 
27532 \SpecialChar ~
27533 \SpecialChar ~
27534 mov %1,a 
27535 \newline 
27536 \SpecialChar ~
27537 \SpecialChar ~
27538 mov a,%1
27539 \newline 
27540 } by {
27541 \newline 
27542 \SpecialChar ~
27543 \SpecialChar ~
27544 mov %1,a
27545 \newline 
27546 }
27547 \layout Standard
27548
27549 The above rule will change the following assembly
27550 \begin_inset LatexCommand \index{Assembler routines}
27551
27552 \end_inset 
27553
27554  sequence:
27555 \layout Verse
27556
27557
27558 \family typewriter 
27559 mov r1,a 
27560 \newline 
27561 mov a,r1
27562 \layout Standard
27563
27564 to
27565 \layout Verse
27566
27567
27568 \family typewriter 
27569 mov r1,a
27570 \layout Standard
27571
27572 Note: All occurrences of a 
27573 \emph on 
27574 %n
27575 \emph default 
27576  (pattern variable) must denote the same string.
27577  With the above rule, the assembly sequence:
27578 \layout Verse
27579
27580
27581 \family typewriter 
27582 mov r1,a 
27583 \newline 
27584 mov a,r2
27585 \layout Standard
27586
27587 will remain unmodified.
27588 \newline 
27589
27590 \newline 
27591 Other special case optimizations may be added by the user (via 
27592 \emph on 
27593 -
27594 \begin_inset ERT
27595 status Collapsed
27596
27597 \layout Standard
27598
27599 \backslash 
27600 /
27601 \end_inset 
27602
27603 -peep-file option
27604 \emph default 
27605 ).
27606  E.g.
27607  some variants of the 8051 MCU
27608 \begin_inset LatexCommand \index{MCS51 variants}
27609
27610 \end_inset 
27611
27612  allow only 
27613 \family typewriter 
27614 ajmp
27615 \family default 
27616  and 
27617 \family typewriter 
27618 acall
27619 \family default 
27620 .
27621  The following two rules will change all 
27622 \family typewriter 
27623 ljmp
27624 \family default 
27625  and 
27626 \family typewriter 
27627 lcall
27628 \family default 
27629  to 
27630 \family typewriter 
27631 ajmp
27632 \family default 
27633  and 
27634 \family typewriter 
27635 acall
27636 \layout Verse
27637
27638
27639 \family typewriter 
27640 replace { lcall %1 } by { acall %1 } 
27641 \newline 
27642 replace { ljmp %1 } by { ajmp %1 }
27643 \layout Standard
27644
27645 The 
27646 \emph on 
27647 inline-assembler code
27648 \emph default 
27649  is also passed through the peep hole optimizer, thus the peephole optimizer
27650  can also be used as an assembly level macro expander.
27651  The rules themselves are MCU dependent whereas the rule language infra-structur
27652 e is MCU independent.
27653  Peephole optimization rules for other MCU can be easily programmed using
27654  the rule language.
27655 \newline 
27656
27657 \newline 
27658 The syntax for a rule is as follows:
27659 \layout Verse
27660
27661
27662 \family typewriter 
27663 rule := replace [ restart ] '{' <assembly sequence> '
27664 \backslash 
27665 n' 
27666 \newline 
27667 \SpecialChar ~
27668  \SpecialChar ~
27669  \SpecialChar ~
27670  \SpecialChar ~
27671  \SpecialChar ~
27672  \SpecialChar ~
27673  \SpecialChar ~
27674  \SpecialChar ~
27675  \SpecialChar ~
27676  \SpecialChar ~
27677  \SpecialChar ~
27678  \SpecialChar ~
27679  \SpecialChar ~
27680  \SpecialChar ~
27681  '}' by '{' '
27682 \backslash 
27683 n' 
27684 \newline 
27685 \SpecialChar ~
27686  \SpecialChar ~
27687  \SpecialChar ~
27688  \SpecialChar ~
27689  \SpecialChar ~
27690  \SpecialChar ~
27691  \SpecialChar ~
27692  \SpecialChar ~
27693  \SpecialChar ~
27694  \SpecialChar ~
27695  \SpecialChar ~
27696  \SpecialChar ~
27697  \SpecialChar ~
27698  \SpecialChar ~
27699  \SpecialChar ~
27700  \SpecialChar ~
27701  <assembly sequence> '
27702 \backslash 
27703 n' 
27704 \newline 
27705 \SpecialChar ~
27706  \SpecialChar ~
27707  \SpecialChar ~
27708  \SpecialChar ~
27709  \SpecialChar ~
27710  \SpecialChar ~
27711  \SpecialChar ~
27712  \SpecialChar ~
27713  \SpecialChar ~
27714  \SpecialChar ~
27715  \SpecialChar ~
27716  \SpecialChar ~
27717  \SpecialChar ~
27718  \SpecialChar ~
27719  '}' [if <functionName> ] '
27720 \backslash 
27721 n' 
27722 \layout Standard
27723
27724 <assembly sequence> := assembly instruction (each instruction including
27725  labels must be on a separate line).
27726 \newline 
27727
27728 \newline 
27729 The optimizer will apply to the rules one by one from the top in the sequence
27730  of their appearance, it will terminate when all rules are exhausted.
27731  If the 'restart' option is specified, then the optimizer will start matching
27732  the rules again from the top, this option for a rule is expensive (performance)
27733 , it is intended to be used in situations where a transformation will trigger
27734  the same rule again.
27735  An example of this (not a good one, it has side effects) is the following
27736  rule:
27737 \layout Verse
27738
27739
27740 \family typewriter 
27741 replace restart { 
27742 \newline 
27743 \SpecialChar ~
27744 \SpecialChar ~
27745 pop %1 
27746 \newline 
27747 \SpecialChar ~
27748 \SpecialChar ~
27749 push %1 } by { 
27750 \newline 
27751 \SpecialChar ~
27752 \SpecialChar ~
27753 ; nop 
27754 \newline 
27755 }
27756 \layout Standard
27757
27758 Note that the replace pattern cannot be a blank, but can be a comment line.
27759  Without the 'restart' option only the innermost 'pop' 'push' pair would
27760  be eliminated, i.e.:
27761 \layout Verse
27762
27763
27764 \family typewriter 
27765 pop ar1 
27766 \newline 
27767 pop ar2 
27768 \newline 
27769 push ar2 
27770 \newline 
27771 push ar1
27772 \layout Standard
27773
27774 would result in:
27775 \layout Verse
27776
27777
27778 \family typewriter 
27779 pop ar1 
27780 \newline 
27781 ; nop 
27782 \newline 
27783 push ar1
27784 \layout Standard
27785
27786
27787 \emph on 
27788 with
27789 \emph default 
27790  the restart option the rule will be applied again to the resulting code
27791  and then all the pop-push pairs will be eliminated to yield:
27792 \layout Verse
27793
27794
27795 \family typewriter 
27796 ; nop 
27797 \newline 
27798 ; nop
27799 \layout Standard
27800
27801 A conditional function can be attached to a rule.
27802  Attaching rules are somewhat more involved, let me illustrate this with
27803  an example.
27804 \layout Verse
27805
27806
27807 \family typewriter 
27808 replace { 
27809 \newline 
27810 \SpecialChar ~
27811  \SpecialChar ~
27812  \SpecialChar ~
27813 ljmp %5 
27814 \newline 
27815 %2:
27816 \newline 
27817 } by { 
27818 \newline 
27819 \SpecialChar ~
27820  \SpecialChar ~
27821  \SpecialChar ~
27822 sjmp %5 
27823 \newline 
27824 %2:
27825 \newline 
27826 } if labelInRange
27827 \layout Standard
27828
27829 The optimizer does a look-up of a function name table defined in function
27830  
27831 \emph on 
27832 callFuncByName
27833 \emph default 
27834  in the source file SDCCpeeph.c, with the name 
27835 \emph on 
27836 labelInRange
27837 \emph default 
27838 .
27839  If it finds a corresponding entry the function is called.
27840  Note there can be no parameters specified for these functions, in this
27841  case the use of 
27842 \emph on 
27843 %5
27844 \emph default 
27845  is crucial, since the function 
27846 \emph on 
27847 labelInRange
27848 \emph default 
27849  expects to find the label in that particular variable (the hash table containin
27850 g the variable bindings is passed as a parameter).
27851  If you want to code more such functions, take a close look at the function
27852  labelInRange and the calling mechanism in source file SDCCpeeph.c.
27853  Currently implemented are 
27854 \emph on 
27855 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
27856  24bitMode, portIsDS390, 24bitModeAndPortDS390 
27857 \emph default 
27858 and
27859 \emph on 
27860  notVolatile
27861 \emph default 
27862 .
27863 \layout Standard
27864
27865 I know this whole thing is a little kludgey, but maybe some day we will
27866  have some better means.
27867  If you are looking at this file, you will see the default rules that are
27868  compiled into the compiler, you can add your own rules in the default set
27869  there if you get tired of specifying the -
27870 \begin_inset ERT
27871 status Collapsed
27872
27873 \layout Standard
27874
27875 \backslash 
27876 /
27877 \end_inset 
27878
27879 -peep-file option.
27880 \layout Section
27881
27882 ANSI-Compliance
27883 \begin_inset LatexCommand \index{ANSI-compliance}
27884
27885 \end_inset 
27886
27887
27888 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
27889
27890 \end_inset 
27891
27892
27893 \layout Standard
27894
27895 The latest publically available version of the standard 
27896 \emph on 
27897 ISO/IEC 9899 - Programming languages - C
27898 \emph default 
27899  should be available at: 
27900 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
27901
27902 \end_inset 
27903
27904 .
27905 \newline 
27906
27907 \layout Standard
27908
27909 Deviations from the compliance:
27910 \layout Itemize
27911
27912 functions are not reentrant
27913 \begin_inset LatexCommand \index{reentrant}
27914
27915 \end_inset 
27916
27917  unless explicitly declared as such or the 
27918 \series bold 
27919 -
27920 \begin_inset ERT
27921 status Collapsed
27922
27923 \layout Standard
27924
27925 \backslash 
27926 /
27927 \end_inset 
27928
27929 -stack-auto
27930 \begin_inset LatexCommand \index{-\/-stack-auto}
27931
27932 \end_inset 
27933
27934
27935 \series default 
27936  command line option is specified.
27937 \layout Itemize
27938
27939 structures and unions cannot be assigned values directly, cannot be passed
27940  as function parameters or assigned to each other and cannot be a return
27941  value from a function, e.g.:
27942 \begin_deeper 
27943 \layout Verse
27944
27945
27946 \family typewriter 
27947 struct s { ...
27948  }; 
27949 \newline 
27950 struct s s1, s2; 
27951 \newline 
27952 foo() 
27953 \newline 
27954
27955 \newline 
27956 \SpecialChar ~
27957 \SpecialChar ~
27958 \SpecialChar ~
27959 \SpecialChar ~
27960 ...
27961  
27962 \newline 
27963 \SpecialChar ~
27964 \SpecialChar ~
27965 \SpecialChar ~
27966 \SpecialChar ~
27967 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
27968 \newline 
27969 \SpecialChar ~
27970 \SpecialChar ~
27971 \SpecialChar ~
27972 \SpecialChar ~
27973 ...
27974  
27975 \newline 
27976 }
27977 \newline 
27978 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
27979  */
27980 \newline 
27981
27982 \newline 
27983 \SpecialChar ~
27984 \SpecialChar ~
27985 \SpecialChar ~
27986 \SpecialChar ~
27987 struct s rets; 
27988 \newline 
27989 \SpecialChar ~
27990 \SpecialChar ~
27991 \SpecialChar ~
27992 \SpecialChar ~
27993 ...
27994  
27995 \newline 
27996 \SpecialChar ~
27997 \SpecialChar ~
27998 \SpecialChar ~
27999 \SpecialChar ~
28000 return rets;/* is invalid in SDCC although allowed in ANSI */ 
28001 \newline 
28002 }
28003 \end_deeper 
28004 \layout Itemize
28005
28006 initialization of structure arrays must be fully braced.
28007 \begin_deeper 
28008 \layout Verse
28009
28010
28011 \family typewriter 
28012 struct s { char x } a[] = {1, 2}; /* invalid in SDCC */
28013 \newline 
28014 struct s { char x } a[] = {{1}, {2}}; /* OK */
28015 \end_deeper 
28016 \layout Itemize
28017
28018 'long long
28019 \begin_inset LatexCommand \index{long long (not supported)}
28020
28021 \end_inset 
28022
28023 ' (64 bit integers
28024 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
28025
28026 \end_inset 
28027
28028 ) not supported.
28029 \layout Itemize
28030
28031 'double
28032 \begin_inset LatexCommand \index{double (not supported)}
28033
28034 \end_inset 
28035
28036 ' precision floating point 
28037 \begin_inset LatexCommand \index{Floating point support}
28038
28039 \end_inset 
28040
28041 not supported.
28042 \layout Itemize
28043
28044 Old K&R style
28045 \begin_inset LatexCommand \index{K\&R style}
28046
28047 \end_inset 
28048
28049  function declarations are NOT allowed.
28050 \begin_deeper 
28051 \layout Verse
28052
28053
28054 \family typewriter 
28055 foo(i,j) /* this old style of function declarations */ 
28056 \newline 
28057 int i,j; /* are valid in ANSI but not valid in SDCC */ 
28058 \newline 
28059
28060 \newline 
28061 \SpecialChar ~
28062 \SpecialChar ~
28063 \SpecialChar ~
28064 \SpecialChar ~
28065 ...
28066  
28067 \newline 
28068 }
28069 \end_deeper 
28070 \layout Itemize
28071
28072 Most enhancements in C99 are not supported, f.e.:
28073 \begin_deeper 
28074 \layout Verse
28075
28076
28077 \family typewriter 
28078 \series bold 
28079 inline
28080 \series default 
28081  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
28082  in C99 */
28083 \newline 
28084 for (
28085 \series bold 
28086 int
28087 \series default 
28088  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
28089 \end_deeper 
28090 \layout Itemize
28091
28092 Certain words that are valid identifiers in the standard may be reserved
28093  words in SDCC unless the 
28094 \series bold 
28095 -
28096 \begin_inset ERT
28097 status Collapsed
28098
28099 \layout Standard
28100
28101 \backslash 
28102 /
28103 \end_inset 
28104
28105 -std-c89
28106 \begin_inset LatexCommand \index{-\/-std-c89}
28107
28108 \end_inset 
28109
28110  or -
28111 \begin_inset ERT
28112 status Collapsed
28113
28114 \layout Standard
28115
28116 \backslash 
28117 /
28118 \end_inset 
28119
28120 -std-c99
28121 \begin_inset LatexCommand \index{-\/-std-c99}
28122
28123 \end_inset 
28124
28125
28126 \series default 
28127  command line options are used.
28128  These may include (depending on the selected processor): 'at', 'banked',
28129  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
28130 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
28131  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
28132  '_naked'.
28133  Compliant equivalents of these keywords are always available in a form
28134  that begin with two underscores
28135 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
28136
28137 \end_inset 
28138
28139 , f.e.
28140  '__data' instead of 'data'.
28141 \layout Section
28142
28143 Cyclomatic Complexity
28144 \begin_inset LatexCommand \index{Cyclomatic complexity}
28145
28146 \end_inset 
28147
28148
28149 \layout Standard
28150
28151 Cyclomatic complexity of a function is defined as the number of independent
28152  paths the program can take during execution of the function.
28153  This is an important number since it defines the number test cases you
28154  have to generate to validate the function.
28155  The accepted industry standard for complexity number is 10, if the cyclomatic
28156  complexity reported by SDCC exceeds 10 you should think about simplification
28157  of the function logic.
28158  Note that the complexity level is not related to the number of lines of
28159  code in a function.
28160  Large functions can have low complexity, and small functions can have large
28161  complexity levels.
28162  
28163 \newline 
28164
28165 \newline 
28166 SDCC uses the following formula to compute the complexity:
28167 \newline 
28168
28169 \layout Standard
28170
28171 complexity = (number of edges in control flow graph) - (number of nodes
28172  in control flow graph) + 2;
28173 \newline 
28174
28175 \newline 
28176 Having said that the industry standard is 10, you should be aware that in
28177  some cases it be may unavoidable to have a complexity level of less than
28178  10.
28179  For example if you have switch statement with more than 10 case labels,
28180  each case label adds one to the complexity level.
28181  The complexity level is by no means an absolute measure of the algorithmic
28182  complexity of the function, it does however provide a good starting point
28183  for which functions you might look at for further optimization.
28184 \layout Section
28185
28186 Retargetting for other Processors
28187 \layout Standard
28188
28189 The issues for retargetting the compiler are far too numerous to be covered
28190  by this document.
28191  What follows is a brief description of each of the seven phases of the
28192  compiler and its MCU dependency.
28193 \layout Itemize
28194
28195 Parsing the source and building the annotated parse tree.
28196  This phase is largely MCU independent (except for the language extensions).
28197  Syntax & semantic checks are also done in this phase, along with some initial
28198  optimizations like back patching labels and the pattern matching optimizations
28199  like bit-rotation etc.
28200 \layout Itemize
28201
28202 The second phase involves generating an intermediate code which can be easy
28203  manipulated during the later phases.
28204  This phase is entirely MCU independent.
28205  The intermediate code generation assumes the target machine has unlimited
28206  number of registers, and designates them with the name iTemp.
28207  The compiler can be made to dump a human readable form of the code generated
28208  by using the -
28209 \begin_inset ERT
28210 status Collapsed
28211
28212 \layout Standard
28213
28214 \backslash 
28215 /
28216 \end_inset 
28217
28218 -dumpraw option.
28219 \layout Itemize
28220
28221 This phase does the bulk of the standard optimizations and is also MCU independe
28222 nt.
28223  This phase can be broken down into several sub-phases:
28224 \newline 
28225
28226 \newline 
28227 Break down intermediate code (iCode) into basic blocks.
28228 \newline 
28229 Do control flow & data flow analysis on the basic blocks.
28230 \newline 
28231 Do local common subexpression elimination, then global subexpression elimination
28232 \newline 
28233 Dead code elimination
28234 \newline 
28235 Loop optimizations
28236 \newline 
28237 If loop optimizations caused any changes then do 'global subexpression eliminati
28238 on' and 'dead code elimination' again.
28239 \layout Itemize
28240
28241 This phase determines the live-ranges; by live range I mean those iTemp
28242  variables defined by the compiler that still survive after all the optimization
28243 s.
28244  Live range analysis
28245 \begin_inset LatexCommand \index{Live range analysis}
28246
28247 \end_inset 
28248
28249  is essential for register allocation, since these computation determines
28250  which of these iTemps will be assigned to registers, and for how long.
28251 \layout Itemize
28252
28253 Phase five is register allocation.
28254  There are two parts to this process.
28255 \newline 
28256
28257 \newline 
28258 The first part I call 'register packing' (for lack of a better term).
28259  In this case several MCU specific expression folding is done to reduce
28260  register pressure.
28261 \newline 
28262
28263 \newline 
28264 The second part is more MCU independent and deals with allocating registers
28265  to the remaining live ranges.
28266  A lot of MCU specific code does creep into this phase because of the limited
28267  number of index registers available in the 8051.
28268 \layout Itemize
28269
28270 The Code generation phase is (unhappily), entirely MCU dependent and very
28271  little (if any at all) of this code can be reused for other MCU.
28272  However the scheme for allocating a homogenized assembler operand for each
28273  iCode operand may be reused.
28274 \layout Itemize
28275
28276 As mentioned in the optimization section the peep-hole optimizer is rule
28277  based system, which can reprogrammed for other MCUs.
28278 \layout Chapter
28279
28280 Compiler internals
28281 \begin_inset LatexCommand \index{Compiler internals}
28282
28283 \end_inset 
28284
28285
28286 \layout Section
28287
28288 The anatomy of the compiler
28289 \begin_inset LatexCommand \label{sub:The-anatomy-of}
28290
28291 \end_inset 
28292
28293
28294 \layout Standard
28295
28296
28297 \shape italic 
28298 This is an excerpt from an article published in Circuit Cellar Magazine
28299  in 
28300 \series bold 
28301 August 2000
28302 \series default 
28303 .
28304  It's a little outdated (the compiler is much more efficient now and user/develo
28305 per friendly), but pretty well exposes the guts of it all.
28306 \shape default 
28307
28308 \newline 
28309
28310 \newline 
28311 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
28312  It is fairly easy to retarget for other 8-bit MCU.
28313  Here we take a look at some of the internals of the compiler.
28314  
28315 \layout Paragraph*
28316
28317 Parsing
28318 \begin_inset LatexCommand \index{Parsing}
28319
28320 \end_inset 
28321
28322  
28323 \layout Standard
28324
28325 Parsing the input source file and creating an AST (Annotated Syntax Tree
28326 \begin_inset LatexCommand \index{Annotated syntax tree}
28327
28328 \end_inset 
28329
28330 ).
28331  This phase also involves propagating types (annotating each node of the
28332  parse tree with type information) and semantic analysis.
28333  There are some MCU specific parsing rules.
28334  For example the storage classes, the extended storage classes are MCU specific
28335  while there may be a xdata storage class for 8051 there is no such storage
28336  class for z80 or Atmel AVR.
28337  SDCC allows MCU specific storage class extensions, i.e.
28338  xdata will be treated as a storage class specifier when parsing 8051 C
28339  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
28340  C code.
28341 \layout Paragraph*
28342
28343 Generating iCode
28344 \begin_inset LatexCommand \index{iCode}
28345
28346 \end_inset 
28347
28348
28349 \layout Standard
28350
28351 Intermediate code generation.
28352  In this phase the AST is broken down into three-operand form (iCode).
28353  These three operand forms are represented as doubly linked lists.
28354  ICode is the term given to the intermediate form generated by the compiler.
28355  ICode example section shows some examples of iCode generated for some simple
28356  C source functions.
28357 \layout Paragraph*
28358
28359 Optimizations
28360 \begin_inset LatexCommand \index{Optimizations}
28361
28362 \end_inset 
28363
28364 .
28365 \layout Standard
28366
28367 Bulk of the target independent optimizations is performed in this phase.
28368  The optimizations include constant propagation, common sub-expression eliminati
28369 on, loop invariant code movement, strength reduction of loop induction variables
28370  and dead-code elimination.
28371 \layout Paragraph*
28372
28373 Live range analysis
28374 \begin_inset LatexCommand \index{Live range analysis}
28375
28376 \end_inset 
28377
28378
28379 \layout Standard
28380
28381 During intermediate code generation phase, the compiler assumes the target
28382  machine has infinite number of registers and generates a lot of temporary
28383  variables.
28384  The live range computation determines the lifetime of each of these compiler-ge
28385 nerated temporaries.
28386  A picture speaks a thousand words.
28387  ICode example sections show the live range annotations for each of the
28388  operand.
28389  It is important to note here, each iCode is assigned a number in the order
28390  of its execution in the function.
28391  The live ranges are computed in terms of these numbers.
28392  The from number is the number of the iCode which first defines the operand
28393  and the to number signifies the iCode which uses this operand last.
28394 \layout Paragraph*
28395
28396 Register Allocation
28397 \begin_inset LatexCommand \index{Register allocation}
28398
28399 \end_inset 
28400
28401
28402 \layout Standard
28403
28404 The register allocation determines the type and number of registers needed
28405  by each operand.
28406  In most MCUs only a few registers can be used for indirect addressing.
28407  In case of 8051 for example the registers R0 & R1 can be used to indirectly
28408  address the internal ram and DPTR to indirectly address the external ram.
28409  The compiler will try to allocate the appropriate register to pointer variables
28410  if it can.
28411  ICode example section shows the operands annotated with the registers assigned
28412  to them.
28413  The compiler will try to keep operands in registers as much as possible;
28414  there are several schemes the compiler uses to do achieve this.
28415  When the compiler runs out of registers the compiler will check to see
28416  if there are any live operands which is not used or defined in the current
28417  basic block being processed, if there are any found then it will push that
28418  operand and use the registers in this block, the operand will then be popped
28419  at the end of the basic block.
28420  
28421 \layout Standard
28422
28423 There are other MCU specific considerations in this phase.
28424  Some MCUs have an accumulator; very short-lived operands could be assigned
28425  to the accumulator instead of a general-purpose register.
28426 \layout Paragraph*
28427
28428 Code generation
28429 \layout Standard
28430
28431 Figure II gives a table of iCode operations supported by the compiler.
28432  The code generation involves translating these operations into corresponding
28433  assembly code for the processor.
28434  This sounds overly simple but that is the essence of code generation.
28435  Some of the iCode operations are generated on a MCU specific manner for
28436  example, the z80 port does not use registers to pass parameters so the
28437  SEND and RECV iCode operations will not be generated, and it also does
28438  not support JUMPTABLES.
28439  
28440 \newline 
28441
28442 \series bold 
28443 \shape italic 
28444 \color red
28445 <Where is Figure II?>
28446 \layout Comment
28447
28448 In the original article Figure II was announced to be downloadable on 
28449 \shape italic 
28450 Circuit Cellar
28451 \shape default 
28452 's web site.
28453  Unfortunately it never seemed to have shown up there, so: where is Figure
28454  II?
28455 \layout Paragraph*
28456
28457 ICode Example
28458 \begin_inset LatexCommand \index{iCode}
28459
28460 \end_inset 
28461
28462
28463 \layout Standard
28464
28465 This section shows some details of iCode.
28466  The example C code does not do anything useful; it is used as an example
28467  to illustrate the intermediate code generated by the compiler.
28468 \layout Verse
28469
28470
28471 \family typewriter 
28472 1.\SpecialChar ~
28473 xdata int * p;
28474 \newline 
28475 2.\SpecialChar ~
28476 int gint;
28477 \newline 
28478 3.\SpecialChar ~
28479 /* This function does nothing useful.
28480  It is used
28481 \newline 
28482 4.\SpecialChar ~
28483 \SpecialChar ~
28484 \SpecialChar ~
28485 \SpecialChar ~
28486 for the purpose of explaining iCode */
28487 \newline 
28488 5.\SpecialChar ~
28489 short function (data int *x)
28490 \newline 
28491 6.\SpecialChar ~
28492 {
28493 \newline 
28494 7.\SpecialChar ~
28495 \SpecialChar ~
28496 \SpecialChar ~
28497 short i=10; \SpecialChar ~
28498 \SpecialChar ~
28499 /* dead initialization eliminated */
28500 \newline 
28501 8.\SpecialChar ~
28502 \SpecialChar ~
28503 \SpecialChar ~
28504 short sum=10; /* dead initialization eliminated */
28505 \newline 
28506 9.\SpecialChar ~
28507 \SpecialChar ~
28508 \SpecialChar ~
28509 short mul;
28510 \newline 
28511 10.\SpecialChar ~
28512 \SpecialChar ~
28513 int j ;
28514 \newline 
28515 11.\SpecialChar ~
28516 \SpecialChar ~
28517 while (*x) *x++ = *p++; 
28518 \newline 
28519 12.\SpecialChar ~
28520 \SpecialChar ~
28521 \SpecialChar ~
28522 \SpecialChar ~
28523 sum = 0 ; 
28524 \newline 
28525 13.\SpecialChar ~
28526 \SpecialChar ~
28527 mul = 0;
28528 \newline 
28529 14.\SpecialChar ~
28530 \SpecialChar ~
28531 /* compiler detects i,j to be induction variables */
28532 \newline 
28533 15.\SpecialChar ~
28534 \SpecialChar ~
28535 for (i = 0, j = 10 ; i < 10 ; i++, j
28536 \family default 
28537 -
28538 \begin_inset ERT
28539 status Collapsed
28540
28541 \layout Standard
28542
28543 \backslash 
28544 /
28545 \end_inset 
28546
28547 -
28548 \family typewriter 
28549 ) {
28550 \newline 
28551 16.\SpecialChar ~
28552 \SpecialChar ~
28553 \SpecialChar ~
28554 \SpecialChar ~
28555 sum += i;
28556 \newline 
28557 17.\SpecialChar ~
28558 \SpecialChar ~
28559 \SpecialChar ~
28560 \SpecialChar ~
28561 mul += i * 3; \SpecialChar ~
28562 \SpecialChar ~
28563 /* this multiplication remains */
28564 \newline 
28565 18.\SpecialChar ~
28566 \SpecialChar ~
28567 \SpecialChar ~
28568 \SpecialChar ~
28569 gint += j * 3;\SpecialChar ~
28570 \SpecialChar ~
28571 /* this multiplication changed to addition */
28572 \newline 
28573 19.\SpecialChar ~
28574 \SpecialChar ~
28575 }
28576 \newline 
28577 20.\SpecialChar ~
28578 \SpecialChar ~
28579 return sum+mul;
28580 \newline 
28581 21.\SpecialChar ~
28582 }
28583 \layout Standard
28584
28585 In addition to the operands each iCode contains information about the filename
28586  and line it corresponds to in the source file.
28587  The first field in the listing should be interpreted as follows:
28588 \newline 
28589
28590 \shape italic 
28591 \size footnotesize 
28592 Filename(linenumber: iCode Execution sequence number : ICode hash table
28593  key : loop depth of the iCode).
28594 \shape default 
28595 \size default 
28596
28597 \newline 
28598 Then follows the human readable form of the ICode operation.
28599  Each operand of this triplet form can be of three basic types a) compiler
28600  generated temporary b) user defined variable c) a constant value.
28601  Note that local variables and parameters are replaced by compiler generated
28602  temporaries.
28603  Live ranges
28604 \begin_inset LatexCommand \index{Live range analysis}
28605
28606 \end_inset 
28607
28608  are computed only for temporaries (i.e.
28609  live ranges are not computed for global variables).
28610  Registers
28611 \begin_inset LatexCommand \index{Register allocation}
28612
28613 \end_inset 
28614
28615  are allocated for temporaries only.
28616  Operands are formatted in the following manner:
28617 \newline 
28618
28619 \shape italic 
28620 \size footnotesize 
28621 Operand Name [lr live-from : live-to ] { type information } [ registers
28622  allocated ].
28623 \shape default 
28624 \size default 
28625
28626 \newline 
28627 As mentioned earlier the live ranges are computed in terms of the execution
28628  sequence number of the iCodes, for example 
28629 \newline 
28630 the iTemp0 is live from (i.e.
28631  first defined in iCode with execution sequence number 3, and is last used
28632  in the iCode with sequence number 5).
28633  For induction variables such as iTemp21 the live range computation extends
28634  the lifetime from the start to the end of the loop.
28635 \newline 
28636 The register allocator used the live range information to allocate registers,
28637  the same registers may be used for different temporaries if their live
28638  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
28639  iTemp17 since their live ranges do not overlap.
28640  In addition the allocator also takes into consideration the type and usage
28641  of a temporary, for example itemp6 is a pointer to near space and is used
28642  as to fetch data from (i.e.
28643  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
28644  Some short lived temporaries are allocated to special registers which have
28645  meaning to the code generator e.g.
28646  iTemp13 is allocated to a pseudo register CC which tells the back end that
28647  the temporary is used only for a conditional jump the code generation makes
28648  use of this information to optimize a compare and jump ICode.
28649 \newline 
28650 There are several loop optimizations
28651 \begin_inset LatexCommand \index{Loop optimization}
28652
28653 \end_inset 
28654
28655  performed by the compiler.
28656  It can detect induction variables iTemp21(i) and iTemp23(j).
28657  Also note the compiler does selective strength reduction
28658 \begin_inset LatexCommand \index{Strength reduction}
28659
28660 \end_inset 
28661
28662 , i.e.
28663  the multiplication of an induction variable in line 18 (gint = j * 3) is
28664  changed to addition, a new temporary iTemp17 is allocated and assigned
28665  a initial value, a constant 3 is then added for each iteration of the loop.
28666  The compiler does not change the multiplication
28667 \begin_inset LatexCommand \index{Multiplication}
28668
28669 \end_inset 
28670
28671  in line 17 however since the processor does support an 8 * 8 bit multiplication.
28672 \newline 
28673 Note the dead code elimination
28674 \begin_inset LatexCommand \index{Dead-code elimination}
28675
28676 \end_inset 
28677
28678  optimization eliminated the dead assignments in line 7 & 8 to I and sum
28679  respectively.
28680 \newline 
28681
28682 \layout Standard
28683
28684
28685 \size footnotesize 
28686 Sample.c (5:1:0:0) _entry($9) :
28687 \layout Standard
28688
28689
28690 \size footnotesize 
28691 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
28692 \layout Standard
28693
28694
28695 \size footnotesize 
28696 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
28697 \layout Standard
28698
28699
28700 \size footnotesize 
28701 Sample.c(11:4:53:0) preHeaderLbl0($11) :
28702 \layout Standard
28703
28704
28705 \size footnotesize 
28706 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
28707  * int}[r2]
28708 \layout Standard
28709
28710
28711 \size footnotesize 
28712 Sample.c(11:6:5:1) _whilecontinue_0($1) :
28713 \layout Standard
28714
28715
28716 \size footnotesize 
28717 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
28718  int}[r0]]
28719 \layout Standard
28720
28721
28722 \size footnotesize 
28723 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
28724 \layout Standard
28725
28726
28727 \size footnotesize 
28728 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
28729  * int}
28730 \layout Standard
28731
28732
28733 \size footnotesize 
28734 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
28735  {short}
28736 \layout Standard
28737
28738
28739 \size footnotesize 
28740 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
28741  * int}[DPTR]]
28742 \layout Standard
28743
28744
28745 \size footnotesize 
28746 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
28747 }[r2 r3]
28748 \layout Standard
28749
28750
28751 \size footnotesize 
28752 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
28753  * int}[r0] + 0x2 {short}
28754 \layout Standard
28755
28756
28757 \size footnotesize 
28758 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
28759 \layout Standard
28760
28761
28762 \size footnotesize 
28763 Sample.c(11:17:21:0)_whilebreak_0($3) :
28764 \layout Standard
28765
28766
28767 \size footnotesize 
28768 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
28769 \layout Standard
28770
28771
28772 \size footnotesize 
28773 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
28774 \layout Standard
28775
28776
28777 \size footnotesize 
28778 Sample.c(15:20:54:0)preHeaderLbl1($13) :
28779 \layout Standard
28780
28781
28782 \size footnotesize 
28783 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
28784 \layout Standard
28785
28786
28787 \size footnotesize 
28788 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
28789 \layout Standard
28790
28791
28792 \size footnotesize 
28793 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
28794 \layout Standard
28795
28796
28797 \size footnotesize 
28798 Sample.c(15:24:26:1)_forcond_0($4) :
28799 \layout Standard
28800
28801
28802 \size footnotesize 
28803 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
28804  < 0xa {short}
28805 \layout Standard
28806
28807
28808 \size footnotesize 
28809 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
28810 \layout Standard
28811
28812
28813 \size footnotesize 
28814 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
28815  + ITemp21 [lr21:38]{short}[r4]
28816 \layout Standard
28817
28818
28819 \size footnotesize 
28820 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
28821  * 0x3 {short}
28822 \layout Standard
28823
28824
28825 \size footnotesize 
28826 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
28827  + iTemp15 [lr29:30]{short}[r1]
28828 \layout Standard
28829
28830
28831 \size footnotesize 
28832 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
28833  r0]- 0x3 {short}
28834 \layout Standard
28835
28836
28837 \size footnotesize 
28838 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
28839 int}[r7 r0]
28840 \layout Standard
28841
28842
28843 \size footnotesize 
28844 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
28845  + 0x1 {short}
28846 \layout Standard
28847
28848
28849 \size footnotesize 
28850 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
28851  r6]- 0x1 {short}
28852 \layout Standard
28853
28854
28855 \size footnotesize 
28856 Sample.c(19:38:47:1) goto _forcond_0($4)
28857 \layout Standard
28858
28859
28860 \size footnotesize 
28861 Sample.c(19:39:48:0)_forbreak_0($7) :
28862 \layout Standard
28863
28864
28865 \size footnotesize 
28866 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
28867  + ITemp11 [lr19:40]{short}[r3]
28868 \layout Standard
28869
28870
28871 \size footnotesize 
28872 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
28873 \layout Standard
28874
28875
28876 \size footnotesize 
28877 Sample.c(20:42:51:0)_return($8) :
28878 \layout Standard
28879
28880
28881 \size footnotesize 
28882 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
28883 \size default 
28884
28885 \newline 
28886
28887 \newline 
28888 Finally the code generated for this function:
28889 \newline 
28890
28891 \layout Standard
28892
28893
28894 \size footnotesize 
28895 .area DSEG (DATA)
28896 \layout Standard
28897
28898
28899 \size footnotesize 
28900 _p::
28901 \layout Standard
28902
28903
28904 \size footnotesize 
28905 \SpecialChar ~
28906 \SpecialChar ~
28907 .ds 2
28908 \layout Standard
28909
28910
28911 \size footnotesize 
28912 _gint::
28913 \layout Standard
28914
28915
28916 \size footnotesize 
28917 \SpecialChar ~
28918 \SpecialChar ~
28919 .ds 2
28920 \layout Standard
28921
28922
28923 \size footnotesize 
28924 ; sample.c 5
28925 \layout Standard
28926
28927
28928 \size footnotesize 
28929 ; ----------------------------------------------
28930 \layout Standard
28931
28932
28933 \size footnotesize 
28934 ; function function
28935 \layout Standard
28936
28937
28938 \size footnotesize 
28939 ; ----------------------------------------------
28940 \layout Standard
28941
28942
28943 \size footnotesize 
28944 _function:
28945 \layout Standard
28946
28947
28948 \size footnotesize 
28949 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
28950 \layout Standard
28951
28952
28953 \size footnotesize 
28954 \SpecialChar ~
28955 \SpecialChar ~
28956 mov r2,dpl
28957 \layout Standard
28958
28959
28960 \size footnotesize 
28961 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
28962 \layout Standard
28963
28964
28965 \size footnotesize 
28966 \SpecialChar ~
28967 \SpecialChar ~
28968 mov ar0,r2
28969 \layout Standard
28970
28971
28972 \size footnotesize 
28973 ;_whilecontinue_0($1) :
28974 \layout Standard
28975
28976
28977 \size footnotesize 
28978 00101$:
28979 \layout Standard
28980
28981
28982 \size footnotesize 
28983 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
28984 \layout Standard
28985
28986
28987 \size footnotesize 
28988 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
28989 \layout Standard
28990
28991
28992 \size footnotesize 
28993 \SpecialChar ~
28994 \SpecialChar ~
28995 mov ar2,@r0
28996 \layout Standard
28997
28998
28999 \size footnotesize 
29000 \SpecialChar ~
29001 \SpecialChar ~
29002 inc r0
29003 \layout Standard
29004
29005
29006 \size footnotesize 
29007 \SpecialChar ~
29008 \SpecialChar ~
29009 mov ar3,@r0
29010 \layout Standard
29011
29012
29013 \size footnotesize 
29014 \SpecialChar ~
29015 \SpecialChar ~
29016 dec r0
29017 \layout Standard
29018
29019
29020 \size footnotesize 
29021 \SpecialChar ~
29022 \SpecialChar ~
29023 mov a,r2
29024 \layout Standard
29025
29026
29027 \size footnotesize 
29028 \SpecialChar ~
29029 \SpecialChar ~
29030 orl a,r3
29031 \layout Standard
29032
29033
29034 \size footnotesize 
29035 \SpecialChar ~
29036 \SpecialChar ~
29037 jz 00103$
29038 \layout Standard
29039
29040
29041 \size footnotesize 
29042 00114$:
29043 \layout Standard
29044
29045
29046 \size footnotesize 
29047 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
29048 \layout Standard
29049
29050
29051 \size footnotesize 
29052 \SpecialChar ~
29053 \SpecialChar ~
29054 mov dpl,_p
29055 \layout Standard
29056
29057
29058 \size footnotesize 
29059 \SpecialChar ~
29060 \SpecialChar ~
29061 mov dph,(_p + 1)
29062 \layout Standard
29063
29064
29065 \size footnotesize 
29066 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
29067 \layout Standard
29068
29069
29070 \size footnotesize 
29071 \SpecialChar ~
29072 \SpecialChar ~
29073 mov a,#0x02
29074 \layout Standard
29075
29076
29077 \size footnotesize 
29078 \SpecialChar ~
29079 \SpecialChar ~
29080 add a,_p
29081 \layout Standard
29082
29083
29084 \size footnotesize 
29085 \SpecialChar ~
29086 \SpecialChar ~
29087 mov _p,a
29088 \layout Standard
29089
29090
29091 \size footnotesize 
29092 \SpecialChar ~
29093 \SpecialChar ~
29094 clr a
29095 \layout Standard
29096
29097
29098 \size footnotesize 
29099 \SpecialChar ~
29100 \SpecialChar ~
29101 addc a,(_p + 1)
29102 \layout Standard
29103
29104
29105 \size footnotesize 
29106 \SpecialChar ~
29107 \SpecialChar ~
29108 mov (_p + 1),a
29109 \layout Standard
29110
29111
29112 \size footnotesize 
29113 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
29114 \layout Standard
29115
29116
29117 \size footnotesize 
29118 \SpecialChar ~
29119 \SpecialChar ~
29120 movx a,@dptr
29121 \layout Standard
29122
29123
29124 \size footnotesize 
29125 \SpecialChar ~
29126 \SpecialChar ~
29127 mov r2,a
29128 \layout Standard
29129
29130
29131 \size footnotesize 
29132 \SpecialChar ~
29133 \SpecialChar ~
29134 inc dptr
29135 \layout Standard
29136
29137
29138 \size footnotesize 
29139 \SpecialChar ~
29140 \SpecialChar ~
29141 movx a,@dptr
29142 \layout Standard
29143
29144
29145 \size footnotesize 
29146 \SpecialChar ~
29147 \SpecialChar ~
29148 mov r3,a
29149 \layout Standard
29150
29151
29152 \size footnotesize 
29153 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
29154 \layout Standard
29155
29156
29157 \size footnotesize 
29158 \SpecialChar ~
29159 \SpecialChar ~
29160 mov @r0,ar2
29161 \layout Standard
29162
29163
29164 \size footnotesize 
29165 \SpecialChar ~
29166 \SpecialChar ~
29167 inc r0
29168 \layout Standard
29169
29170
29171 \size footnotesize 
29172 \SpecialChar ~
29173 \SpecialChar ~
29174 mov @r0,ar3
29175 \layout Standard
29176
29177
29178 \size footnotesize 
29179 ; iTemp6 [lr5:16]{_near * int}[r0] = 
29180 \layout Standard
29181
29182
29183 \size footnotesize 
29184 ; iTemp6 [lr5:16]{_near * int}[r0] + 
29185 \layout Standard
29186
29187
29188 \size footnotesize 
29189 ; 0x2 {short}
29190 \layout Standard
29191
29192
29193 \size footnotesize 
29194 \SpecialChar ~
29195 \SpecialChar ~
29196 inc r0
29197 \layout Standard
29198
29199
29200 \size footnotesize 
29201 ; goto _whilecontinue_0($1)
29202 \layout Standard
29203
29204
29205 \size footnotesize 
29206 \SpecialChar ~
29207 \SpecialChar ~
29208 sjmp 00101$
29209 \layout Standard
29210
29211
29212 \size footnotesize 
29213 ; _whilebreak_0($3) :
29214 \layout Standard
29215
29216
29217 \size footnotesize 
29218 00103$:
29219 \layout Standard
29220
29221
29222 \size footnotesize 
29223 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
29224 \layout Standard
29225
29226
29227 \size footnotesize 
29228 \SpecialChar ~
29229 \SpecialChar ~
29230 mov r2,#0x00
29231 \layout Standard
29232
29233
29234 \size footnotesize 
29235 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
29236 \layout Standard
29237
29238
29239 \size footnotesize 
29240 \SpecialChar ~
29241 \SpecialChar ~
29242 mov r3,#0x00
29243 \layout Standard
29244
29245
29246 \size footnotesize 
29247 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
29248 \layout Standard
29249
29250
29251 \size footnotesize 
29252 \SpecialChar ~
29253 \SpecialChar ~
29254 mov r4,#0x00
29255 \layout Standard
29256
29257
29258 \size footnotesize 
29259 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
29260 \layout Standard
29261
29262
29263 \size footnotesize 
29264 \SpecialChar ~
29265 \SpecialChar ~
29266 mov r5,#0x0A
29267 \layout Standard
29268
29269
29270 \size footnotesize 
29271 \SpecialChar ~
29272 \SpecialChar ~
29273 mov r6,#0x00
29274 \layout Standard
29275
29276
29277 \size footnotesize 
29278 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
29279 \layout Standard
29280
29281
29282 \size footnotesize 
29283 \SpecialChar ~
29284 \SpecialChar ~
29285 mov r7,#0x1E
29286 \layout Standard
29287
29288
29289 \size footnotesize 
29290 \SpecialChar ~
29291 \SpecialChar ~
29292 mov r0,#0x00
29293 \layout Standard
29294
29295
29296 \size footnotesize 
29297 ; _forcond_0($4) :
29298 \layout Standard
29299
29300
29301 \size footnotesize 
29302 00104$:
29303 \layout Standard
29304
29305
29306 \size footnotesize 
29307 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
29308 \layout Standard
29309
29310
29311 \size footnotesize 
29312 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
29313 \layout Standard
29314
29315
29316 \size footnotesize 
29317 \SpecialChar ~
29318 \SpecialChar ~
29319 clr c
29320 \layout Standard
29321
29322
29323 \size footnotesize 
29324 \SpecialChar ~
29325 \SpecialChar ~
29326 mov a,r4
29327 \layout Standard
29328
29329
29330 \size footnotesize 
29331 \SpecialChar ~
29332 \SpecialChar ~
29333 xrl a,#0x80
29334 \layout Standard
29335
29336
29337 \size footnotesize 
29338 \SpecialChar ~
29339 \SpecialChar ~
29340 subb a,#0x8a
29341 \layout Standard
29342
29343
29344 \size footnotesize 
29345 \SpecialChar ~
29346 \SpecialChar ~
29347 jnc 00107$
29348 \layout Standard
29349
29350
29351 \size footnotesize 
29352 00115$:
29353 \layout Standard
29354
29355
29356 \size footnotesize 
29357 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
29358 \layout Standard
29359
29360
29361 \size footnotesize 
29362 ; iTemp21 [lr21:38]{short}[r4]
29363 \layout Standard
29364
29365
29366 \size footnotesize 
29367 \SpecialChar ~
29368 \SpecialChar ~
29369 mov a,r4
29370 \layout Standard
29371
29372
29373 \size footnotesize 
29374 \SpecialChar ~
29375 \SpecialChar ~
29376 add a,r2
29377 \layout Standard
29378
29379
29380 \size footnotesize 
29381 \SpecialChar ~
29382 \SpecialChar ~
29383 mov r2,a
29384 \layout Standard
29385
29386
29387 \size footnotesize 
29388 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
29389 \layout Standard
29390
29391
29392 \size footnotesize 
29393 \SpecialChar ~
29394 \SpecialChar ~
29395 mov b,#0x03
29396 \layout Standard
29397
29398
29399 \size footnotesize 
29400 \SpecialChar ~
29401 \SpecialChar ~
29402 mov a,r4
29403 \layout Standard
29404
29405
29406 \size footnotesize 
29407 \SpecialChar ~
29408 \SpecialChar ~
29409 mul ab
29410 \layout Standard
29411
29412
29413 \size footnotesize 
29414 \SpecialChar ~
29415 \SpecialChar ~
29416 mov r1,a
29417 \layout Standard
29418
29419
29420 \size footnotesize 
29421 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
29422 \layout Standard
29423
29424
29425 \size footnotesize 
29426 ; iTemp15 [lr29:30]{short}[r1]
29427 \layout Standard
29428
29429
29430 \size footnotesize 
29431 \SpecialChar ~
29432 \SpecialChar ~
29433 add a,r3
29434 \layout Standard
29435
29436
29437 \size footnotesize 
29438 \SpecialChar ~
29439 \SpecialChar ~
29440 mov r3,a
29441 \layout Standard
29442
29443
29444 \size footnotesize 
29445 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
29446 \layout Standard
29447
29448
29449 \size footnotesize 
29450 \SpecialChar ~
29451 \SpecialChar ~
29452 mov a,r7
29453 \layout Standard
29454
29455
29456 \size footnotesize 
29457 \SpecialChar ~
29458 \SpecialChar ~
29459 add a,#0xfd
29460 \layout Standard
29461
29462
29463 \size footnotesize 
29464 \SpecialChar ~
29465 \SpecialChar ~
29466 mov r7,a
29467 \layout Standard
29468
29469
29470 \size footnotesize 
29471 \SpecialChar ~
29472 \SpecialChar ~
29473 mov a,r0
29474 \layout Standard
29475
29476
29477 \size footnotesize 
29478 \SpecialChar ~
29479 \SpecialChar ~
29480 addc a,#0xff
29481 \layout Standard
29482
29483
29484 \size footnotesize 
29485 \SpecialChar ~
29486 \SpecialChar ~
29487 mov r0,a
29488 \layout Standard
29489
29490
29491 \size footnotesize 
29492 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
29493 \layout Standard
29494
29495
29496 \size footnotesize 
29497 \SpecialChar ~
29498 \SpecialChar ~
29499 mov a,r7
29500 \layout Standard
29501
29502
29503 \size footnotesize 
29504 \SpecialChar ~
29505 \SpecialChar ~
29506 add a,_gint
29507 \layout Standard
29508
29509
29510 \size footnotesize 
29511 \SpecialChar ~
29512 \SpecialChar ~
29513 mov _gint,a
29514 \layout Standard
29515
29516
29517 \size footnotesize 
29518 \SpecialChar ~
29519 \SpecialChar ~
29520 mov a,r0
29521 \layout Standard
29522
29523
29524 \size footnotesize 
29525 \SpecialChar ~
29526 \SpecialChar ~
29527 addc a,(_gint + 1)
29528 \layout Standard
29529
29530
29531 \size footnotesize 
29532 \SpecialChar ~
29533 \SpecialChar ~
29534 mov (_gint + 1),a
29535 \layout Standard
29536
29537
29538 \size footnotesize 
29539 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
29540 \layout Standard
29541
29542
29543 \size footnotesize 
29544 \SpecialChar ~
29545 \SpecialChar ~
29546 inc r4
29547 \layout Standard
29548
29549
29550 \size footnotesize 
29551 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
29552 \layout Standard
29553
29554
29555 \size footnotesize 
29556 \SpecialChar ~
29557 \SpecialChar ~
29558 dec r5
29559 \layout Standard
29560
29561
29562 \size footnotesize 
29563 \SpecialChar ~
29564 \SpecialChar ~
29565 cjne r5,#0xff,00104$
29566 \layout Standard
29567
29568
29569 \size footnotesize 
29570 \SpecialChar ~
29571 \SpecialChar ~
29572 dec r6
29573 \layout Standard
29574
29575
29576 \size footnotesize 
29577 ; goto _forcond_0($4)
29578 \layout Standard
29579
29580
29581 \size footnotesize 
29582 \SpecialChar ~
29583 \SpecialChar ~
29584 sjmp 00104$
29585 \layout Standard
29586
29587
29588 \size footnotesize 
29589 ; _forbreak_0($7) :
29590 \layout Standard
29591
29592
29593 \size footnotesize 
29594 00107$:
29595 \layout Standard
29596
29597
29598 \size footnotesize 
29599 ; ret iTemp24 [lr40:41]{short}
29600 \layout Standard
29601
29602
29603 \size footnotesize 
29604 \SpecialChar ~
29605 \SpecialChar ~
29606 mov a,r3
29607 \layout Standard
29608
29609
29610 \size footnotesize 
29611 \SpecialChar ~
29612 \SpecialChar ~
29613 add a,r2
29614 \layout Standard
29615
29616
29617 \size footnotesize 
29618 \SpecialChar ~
29619 \SpecialChar ~
29620 mov dpl,a
29621 \layout Standard
29622
29623
29624 \size footnotesize 
29625 ; _return($8) :
29626 \layout Standard
29627
29628
29629 \size footnotesize 
29630 00108$:
29631 \layout Standard
29632
29633
29634 \size footnotesize 
29635 \SpecialChar ~
29636 \SpecialChar ~
29637 ret
29638 \newline 
29639
29640 \layout Section
29641
29642 A few words about basic block successors, predecessors and dominators
29643 \layout Standard
29644
29645 Successors are basic blocks
29646 \begin_inset LatexCommand \index{Basic blocks}
29647
29648 \end_inset 
29649
29650  that might execute after this basic block.
29651 \newline 
29652 Predecessors are basic blocks that might execute before reaching this basic
29653  block.
29654 \newline 
29655 Dominators are basic blocks that WILL execute before reaching this basic
29656  block.
29657 \newline 
29658
29659 \layout Standard
29660
29661 [basic block 1]
29662 \layout Standard
29663
29664 if (something)
29665 \layout Standard
29666
29667 \SpecialChar ~
29668 \SpecialChar ~
29669 \SpecialChar ~
29670 \SpecialChar ~
29671 [basic block 2]
29672 \layout Standard
29673
29674 else
29675 \layout Standard
29676
29677 \SpecialChar ~
29678 \SpecialChar ~
29679 \SpecialChar ~
29680 \SpecialChar ~
29681 [basic block 3]
29682 \layout Standard
29683
29684 [basic block 4]
29685 \newline 
29686
29687 \layout Standard
29688
29689 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
29690 \layout Standard
29691
29692 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
29693 \layout Standard
29694
29695 c) domVect of [BB4] = BB1 ...
29696  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
29697  was executed.
29698 \layout Chapter
29699
29700 Acknowledgments
29701 \layout Standard
29702
29703
29704 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
29705
29706 \end_inset 
29707
29708
29709 \newline 
29710
29711 \newline 
29712
29713 \emph on 
29714 Thanks to all the other volunteer developers who have helped with coding,
29715  testing, web-page creation, distribution sets, etc.
29716  You know who you are :-)
29717 \emph default 
29718
29719 \newline 
29720
29721 \layout Standard
29722
29723 This document was initially written by Sandeep Dutta
29724 \layout Standard
29725
29726 All product names mentioned herein may be trademarks
29727 \begin_inset LatexCommand \index{Trademarks}
29728
29729 \end_inset 
29730
29731  of their respective companies.
29732  
29733 \layout Section*
29734
29735 Alphabetical index
29736 \layout Standard
29737
29738 To avoid confusion, the installation and building options for SDCC itself
29739  (chapter 2) are not part of the index.
29740 \layout Standard
29741
29742
29743 \begin_inset LatexCommand \printindex{}
29744
29745 \end_inset 
29746
29747
29748 \the_end