* doc/sdccman.lyx: added note on dynamic memory heap initialization
[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 retargetted for other microprocessors, support for Microchip
146  PIC, Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargettable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Standard
206
207
208 \begin_inset  Tabular
209 <lyxtabular version="3" rows="8" columns="5">
210 <features>
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
216 <row topline="true" bottomline="true">
217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
218 \begin_inset Text
219
220 \layout Standard
221
222 type
223 \end_inset 
224 </cell>
225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
226 \begin_inset Text
227
228 \layout Standard
229
230 width
231 \end_inset 
232 </cell>
233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
234 \begin_inset Text
235
236 \layout Standard
237
238 default
239 \end_inset 
240 </cell>
241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
242 \begin_inset Text
243
244 \layout Standard
245
246 signed range
247 \end_inset 
248 </cell>
249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
250 \begin_inset Text
251
252 \layout Standard
253
254 unsigned range
255 \end_inset 
256 </cell>
257 </row>
258 <row topline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \layout Standard
263
264 bool
265 \end_inset 
266 </cell>
267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
268 \begin_inset Text
269
270 \layout Standard
271
272 1 bit
273 \end_inset 
274 </cell>
275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
276 \begin_inset Text
277
278 \layout Standard
279
280 unsigned
281 \end_inset 
282 </cell>
283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_inset Text
285
286 \layout Standard
287
288 -
289 \end_inset 
290 </cell>
291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
292 \begin_inset Text
293
294 \layout Standard
295
296 0, 1
297 \end_inset 
298 </cell>
299 </row>
300 <row topline="true">
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_inset Text
303
304 \layout Standard
305
306 char
307 \end_inset 
308 </cell>
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
310 \begin_inset Text
311
312 \layout Standard
313
314 8 bits, 1 byte
315 \end_inset 
316 </cell>
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_inset Text
319
320 \layout Standard
321
322 signed
323 \end_inset 
324 </cell>
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
326 \begin_inset Text
327
328 \layout Standard
329
330 -128, +127
331 \end_inset 
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
334 \begin_inset Text
335
336 \layout Standard
337
338 0, +255
339 \end_inset 
340 </cell>
341 </row>
342 <row topline="true">
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
344 \begin_inset Text
345
346 \layout Standard
347
348 short
349 \end_inset 
350 </cell>
351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
352 \begin_inset Text
353
354 \layout Standard
355
356 16 bits, 2 bytes
357 \end_inset 
358 </cell>
359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
360 \begin_inset Text
361
362 \layout Standard
363
364 signed
365 \end_inset 
366 </cell>
367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
368 \begin_inset Text
369
370 \layout Standard
371
372 -32.768, +32.767
373 \end_inset 
374 </cell>
375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
376 \begin_inset Text
377
378 \layout Standard
379
380 0, +65.535
381 \end_inset 
382 </cell>
383 </row>
384 <row topline="true">
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
386 \begin_inset Text
387
388 \layout Standard
389
390 int
391 \end_inset 
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
394 \begin_inset Text
395
396 \layout Standard
397
398 16 bits, 2 bytes
399 \end_inset 
400 </cell>
401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
402 \begin_inset Text
403
404 \layout Standard
405
406 signed
407 \end_inset 
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \layout Standard
413
414 -32.768, +32.767
415 \end_inset 
416 </cell>
417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
418 \begin_inset Text
419
420 \layout Standard
421
422 0, +65.535
423 \end_inset 
424 </cell>
425 </row>
426 <row topline="true" bottomline="true">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \layout Standard
431
432 long
433 \end_inset 
434 </cell>
435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
436 \begin_inset Text
437
438 \layout Standard
439
440 32 bits, 4 bytes
441 \end_inset 
442 </cell>
443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
444 \begin_inset Text
445
446 \layout Standard
447
448 signed
449 \end_inset 
450 </cell>
451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
452 \begin_inset Text
453
454 \layout Standard
455
456 -2.147.483.648, +2.147.483.647
457 \end_inset 
458 </cell>
459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
460 \begin_inset Text
461
462 \layout Standard
463
464 0, +4.294.967.296
465 \end_inset 
466 </cell>
467 </row>
468 <row topline="true" bottomline="true">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \layout Standard
473
474 float
475 \end_inset 
476 </cell>
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
478 \begin_inset Text
479
480 \layout Standard
481
482 4 bytes IEEE 754
483 \end_inset 
484 </cell>
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
486 \begin_inset Text
487
488 \layout Standard
489
490 signed
491 \end_inset 
492 </cell>
493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
494 \begin_inset Text
495
496 \layout Standard
497
498 \end_inset 
499 </cell>
500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
501 \begin_inset Text
502
503 \layout Standard
504
505 \end_inset 
506 </cell>
507 </row>
508 <row topline="true" bottomline="true">
509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
510 \begin_inset Text
511
512 \layout Standard
513
514 pointer
515 \end_inset 
516 </cell>
517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
518 \begin_inset Text
519
520 \layout Standard
521
522 1, 2, 3 or 4 bytes
523 \end_inset 
524 </cell>
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
526 \begin_inset Text
527
528 \layout Standard
529
530 generic
531 \end_inset 
532 </cell>
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
534 \begin_inset Text
535
536 \layout Standard
537
538 \end_inset 
539 </cell>
540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
541 \begin_inset Text
542
543 \layout Standard
544
545 \end_inset 
546 </cell>
547 </row>
548 </lyxtabular>
549
550 \end_inset 
551
552
553 \newline 
554 The compiler also allows 
555 \emph on 
556 inline assembler code
557 \emph default 
558  to be embedded anywhere in a function.
559  In addition, routines developed in assembly can also be called.
560 \newline 
561
562 \newline 
563 SDCC also provides an option (-
564 \begin_inset ERT
565 status Collapsed
566
567 \layout Standard
568
569 \backslash 
570 /
571 \end_inset 
572
573 -cyclomatic) to report the relative complexity of a function.
574  These functions can then be further optimized, or hand coded in assembly
575  if needed.
576  
577 \newline 
578
579 \newline 
580 SDCC also comes with a companion source level debugger SDCDB, the debugger
581  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
582  SDCDB and ucSim are currently not available on Win32 platforms.
583  
584 \newline 
585
586 \newline 
587 The latest version can be downloaded from 
588 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
589
590 \end_inset 
591
592 .
593
594 \series bold 
595  
596 \series default 
597 \emph on 
598 Please note: the compiler will probably always be some steps ahead of this
599  documentation
600 \series bold 
601 \emph default 
602
603 \begin_inset LatexCommand \index{Status of documentation}
604
605 \end_inset 
606
607
608 \begin_inset Foot
609 collapsed false
610
611 \layout Standard
612
613 Obviously this has pros and cons
614 \end_inset 
615
616 .
617 \layout Section
618
619 Open Source
620 \layout Standard
621
622 All packages used in this compiler system are 
623 \emph on 
624 open source
625 \emph default 
626  and 
627 \emph on 
628 freeware
629 \emph default 
630 ; source code for all the sub-packages (pre-processor, assemblers, linkers
631  etc) is distributed with the package.
632  This documentation is maintained using a freeware word processor (LyX).
633 \newline 
634 This program is free software; you can redistribute it and/or modify it
635  under the terms of the GNU General Public License
636 \begin_inset LatexCommand \index{GNU General Public License, GPL}
637
638 \end_inset 
639
640  as published by the Free Software Foundation; either version 2, or (at
641  your option) any later version.
642  This program is distributed in the hope that it will be useful, but WITHOUT
643  ANY WARRANTY; without even the implied warranty
644 \begin_inset LatexCommand \index{warranty}
645
646 \end_inset 
647
648  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
649  See the GNU General Public License for more details.
650  You should have received a copy of the GNU General Public License along
651  with this program; if not, write to the Free Software Foundation, 59 Temple
652  Place - Suite 330, Boston, MA 02111-1307, USA.
653  In other words, you are welcome to use, share and improve this program.
654  You are forbidden to forbid anyone else to use, share and improve what
655  you give them.
656  Help stamp out software-hoarding! 
657 \layout Section
658
659 Typographic conventions
660 \begin_inset LatexCommand \index{Typographic conventions}
661
662 \end_inset 
663
664
665 \layout Standard
666
667 Throughout this manual, we will use the following convention.
668  Commands you have to type in are printed in 
669 \family sans 
670 \series bold 
671 "sans serif"
672 \series default 
673 .
674
675 \family default 
676  Code samples are printed in 
677 \family typewriter 
678 typewriter font.
679
680 \family default 
681  Interesting items and new terms are printed in 
682 \emph on 
683 italic.
684 \layout Section
685
686 Compatibility
687 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
688
689 \end_inset 
690
691  with previous versions
692 \begin_inset LatexCommand \index{Compatibility with previous versions}
693
694 \end_inset 
695
696
697 \layout Standard
698
699 This version has numerous bug fixes compared with the previous version.
700  But we also introduced some incompatibilities with older versions.
701  Not just for the fun of it, but to make the compiler more stable, efficient
702  and ANSI compliant
703 \begin_inset LatexCommand \index{ANSI-compliance}
704
705 \end_inset 
706
707  (see section 
708 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
709
710 \end_inset 
711
712  for ANSI-Compliance).
713  
714 \newline 
715
716 \layout Itemize
717
718 short is now equivalent to int (16 bits), it used to be equivalent to char
719  (8 bits) which is not ANSI compliant.
720 \layout Itemize
721
722 the default directory for gcc-builds where include, library and documentation
723  files are stored is now in /usr/local/share.
724 \layout Itemize
725
726 char type parameters to vararg functions are casted to int unless explicitly
727  casted, e.g.: 
728 \newline 
729
730 \family typewriter 
731 \SpecialChar ~
732 \SpecialChar ~
733 char a=3;
734 \newline 
735 \SpecialChar ~
736 \SpecialChar ~
737 printf ("%d %c
738 \backslash 
739 n", a, (char)a);
740 \family default 
741
742 \newline 
743  will push a as an int and as a char resp.
744 \layout Itemize
745
746 option -
747 \begin_inset ERT
748 status Collapsed
749
750 \layout Standard
751
752 \backslash 
753 /
754 \end_inset 
755
756 -regextend has been removed.
757 \layout Itemize
758
759 option -
760 \begin_inset ERT
761 status Collapsed
762
763 \layout Standard
764
765 \backslash 
766 /
767 \end_inset 
768
769 -noregparms has been removed.
770 \layout Itemize
771
772 option -
773 \begin_inset ERT
774 status Collapsed
775
776 \layout Standard
777
778 \backslash 
779 /
780 \end_inset 
781
782 -stack-after-data has been removed.
783 \layout Itemize
784
785 bit
786 \begin_inset LatexCommand \index{bit}
787
788 \end_inset 
789
790  and sbit
791 \begin_inset LatexCommand \index{sbit}
792
793 \end_inset 
794
795
796 \begin_inset LatexCommand \index{\_\_sbit}
797
798 \end_inset 
799
800  types now consistently behave like the C99 _Bool type with respect to type
801  conversion
802 \begin_inset LatexCommand \index{type conversion}
803
804 \end_inset 
805
806
807 \begin_inset LatexCommand \index{type promotion}
808
809 \end_inset 
810
811 .
812  The most common incompatibility resulting from this change is related to
813  bit toggling
814 \begin_inset LatexCommand \index{Bit toggling}
815
816 \end_inset 
817
818  idioms, e.g.:
819 \newline 
820
821 \family typewriter 
822 \SpecialChar ~
823 \SpecialChar ~
824 bit b;
825 \newline 
826 \SpecialChar ~
827 \SpecialChar ~
828 b = ~b; /* equivalent to b=1 instead of toggling b */
829 \begin_inset Marginal
830 collapsed false
831
832 \layout Standard
833
834
835 \series bold 
836 \SpecialChar ~
837 !
838 \end_inset 
839
840
841 \newline 
842 \SpecialChar ~
843 \SpecialChar ~
844 b = !b; /* toggles b */
845 \newline 
846
847 \family default 
848 In previous versions, both forms would have toggled the bit.
849 \layout Standard
850
851
852 \emph on 
853 <pending: more incompatibilities?>
854 \layout Section
855
856 System Requirements
857 \layout Standard
858
859 What do you need before you start installation of SDCC? A computer, and
860  a desire to compute.
861  The preferred method of installation is to compile SDCC from source using
862  GNU gcc and make.
863  For Windows some pre-compiled binary distributions are available for your
864  convenience.
865  You should have some experience with command line tools and compiler use.
866 \layout Section
867
868 Other Resources
869 \layout Standard
870
871 The SDCC home page at 
872 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
873
874 \end_inset 
875
876  is a great place to find distribution sets.
877  You can also find links to the user mailing lists that offer help or discuss
878  SDCC with other SDCC users.
879  Web links to other SDCC related sites can also be found here.
880  This document can be found in the DOC directory of the source package as
881  a text or HTML file.
882  A pdf version of this document is available at 
883 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
884
885 \end_inset 
886
887 .
888  Some of the other tools (simulator and assembler) included with SDCC contain
889  their own documentation and can be found in the source distribution.
890  If you want the latest unreleased software, the complete source package
891  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
892 /trunk/sdcc.
893 \layout Section
894
895 Wishes for the future
896 \layout Standard
897
898 There are (and always will be) some things that could be done.
899  Here are some I can think of:
900 \newline 
901
902 \layout Standard
903
904
905 \family typewriter 
906 char KernelFunction3(char p) at 0x340;
907 \newline 
908
909 \layout Standard
910
911
912 \family typewriter 
913 better code banking
914 \begin_inset LatexCommand \index{code banking (limited support)}
915
916 \end_inset 
917
918  support for mcs51
919 \newline 
920
921 \newline 
922
923 \family default 
924 If you can think of some more, please see the section 
925 \begin_inset LatexCommand \ref{sub:Requesting-Features}
926
927 \end_inset 
928
929  about filing feature requests
930 \begin_inset LatexCommand \index{Requesting features}
931
932 \end_inset 
933
934
935 \begin_inset LatexCommand \index{Feature request}
936
937 \end_inset 
938
939 .
940 \newline 
941
942 \layout Chapter
943
944 Installing SDCC
945 \begin_inset LatexCommand \index{Installation}
946
947 \end_inset 
948
949
950 \layout Standard
951
952 For most users it is sufficient to skip to either section 
953 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
954
955 \end_inset 
956
957  or section 
958 \begin_inset LatexCommand \ref{sub:Windows-Install}
959
960 \end_inset 
961
962 .
963  More detailled instructions follow below.
964 \layout Section
965
966 Configure Options
967 \begin_inset LatexCommand \index{Options SDCC configuration}
968
969 \end_inset 
970
971
972 \layout Standard
973
974 The install paths, search paths and other options are defined when running
975  'configure'.
976  The defaults can be overridden by:
977 \layout List
978 \labelwidthstring 00.00.0000
979
980 -
981 \begin_inset ERT
982 status Collapsed
983
984 \layout Standard
985
986 \backslash 
987 /
988 \end_inset 
989
990 -prefix see table below
991 \layout List
992 \labelwidthstring 00.00.0000
993
994 -
995 \begin_inset ERT
996 status Collapsed
997
998 \layout Standard
999
1000 \backslash 
1001 /
1002 \end_inset 
1003
1004 -exec_prefix see table below
1005 \layout List
1006 \labelwidthstring 00.00.0000
1007
1008 -
1009 \begin_inset ERT
1010 status Collapsed
1011
1012 \layout Standard
1013
1014 \backslash 
1015 /
1016 \end_inset 
1017
1018 -bindir see table below
1019 \layout List
1020 \labelwidthstring 00.00.0000
1021
1022 -
1023 \begin_inset ERT
1024 status Collapsed
1025
1026 \layout Standard
1027
1028 \backslash 
1029 /
1030 \end_inset 
1031
1032 -datadir see table below
1033 \layout List
1034 \labelwidthstring 00.00.0000
1035
1036 docdir environment variable, see table below
1037 \layout List
1038 \labelwidthstring 00.00.0000
1039
1040 include_dir_suffix environment variable, see table below
1041 \layout List
1042 \labelwidthstring 00.00.0000
1043
1044 lib_dir_suffix environment variable, see table below
1045 \layout List
1046 \labelwidthstring 00.00.0000
1047
1048 sdccconf_h_dir_separator environment variable, either / or 
1049 \backslash 
1050
1051 \backslash 
1052  makes sense here.
1053  This character will only be used in sdccconf.h; don't forget it's a C-header,
1054  therefore a double-backslash is needed there.
1055 \layout List
1056 \labelwidthstring 00.00.0000
1057
1058 -
1059 \begin_inset ERT
1060 status Collapsed
1061
1062 \layout Standard
1063
1064 \backslash 
1065 /
1066 \end_inset 
1067
1068 -disable-mcs51-port Excludes the Intel mcs51 port
1069 \layout List
1070 \labelwidthstring 00.00.0000
1071
1072 -
1073 \begin_inset ERT
1074 status Collapsed
1075
1076 \layout Standard
1077
1078 \backslash 
1079 /
1080 \end_inset 
1081
1082 -disable-gbz80-port Excludes the Gameboy gbz80 port
1083 \layout List
1084 \labelwidthstring 00.00.0000
1085
1086 -
1087 \begin_inset ERT
1088 status Collapsed
1089
1090 \layout Standard
1091
1092 \backslash 
1093 /
1094 \end_inset 
1095
1096 -disable-z80-port Excludes the z80 port
1097 \layout List
1098 \labelwidthstring 00.00.0000
1099
1100 -
1101 \begin_inset ERT
1102 status Collapsed
1103
1104 \layout Standard
1105
1106 \backslash 
1107 /
1108 \end_inset 
1109
1110 -disable-avr-port Excludes the AVR port
1111 \layout List
1112 \labelwidthstring 00.00.0000
1113
1114 -
1115 \begin_inset ERT
1116 status Collapsed
1117
1118 \layout Standard
1119
1120 \backslash 
1121 /
1122 \end_inset 
1123
1124 -disable-ds390-port Excludes the DS390 port
1125 \layout List
1126 \labelwidthstring 00.00.0000
1127
1128 -
1129 \begin_inset ERT
1130 status Collapsed
1131
1132 \layout Standard
1133
1134 \backslash 
1135 /
1136 \end_inset 
1137
1138 -disable-hc08-port Excludes the HC08 port
1139 \layout List
1140 \labelwidthstring 00.00.0000
1141
1142 -
1143 \begin_inset ERT
1144 status Collapsed
1145
1146 \layout Standard
1147
1148 \backslash 
1149 /
1150 \end_inset 
1151
1152 -disable-pic-port Excludes the PIC port
1153 \layout List
1154 \labelwidthstring 00.00.0000
1155
1156 -
1157 \begin_inset ERT
1158 status Collapsed
1159
1160 \layout Standard
1161
1162 \backslash 
1163 /
1164 \end_inset 
1165
1166 -disable-xa51-port Excludes the XA51 port
1167 \layout List
1168 \labelwidthstring 00.00.0000
1169
1170 -
1171 \begin_inset ERT
1172 status Collapsed
1173
1174 \layout Standard
1175
1176 \backslash 
1177 /
1178 \end_inset 
1179
1180 -disable-ucsim Disables configuring and building of ucsim
1181 \layout List
1182 \labelwidthstring 00.00.0000
1183
1184 -
1185 \begin_inset ERT
1186 status Collapsed
1187
1188 \layout Standard
1189
1190 \backslash 
1191 /
1192 \end_inset 
1193
1194 -disable-device-lib Disables automatically building device libraries
1195 \layout List
1196 \labelwidthstring 00.00.0000
1197
1198 -
1199 \begin_inset ERT
1200 status Collapsed
1201
1202 \layout Standard
1203
1204 \backslash 
1205 /
1206 \end_inset 
1207
1208 -disable-packihx Disables building packihx
1209 \layout List
1210 \labelwidthstring 00.00.0000
1211
1212 -
1213 \begin_inset ERT
1214 status Collapsed
1215
1216 \layout Standard
1217
1218 \backslash 
1219 /
1220 \end_inset 
1221
1222 -enable-doc Build pdf, html and txt files from the lyx sources
1223 \layout List
1224 \labelwidthstring 00.00.0000
1225
1226 -
1227 \begin_inset ERT
1228 status Collapsed
1229
1230 \layout Standard
1231
1232 \backslash 
1233 /
1234 \end_inset 
1235
1236 -enable-libgc Use the Bohem memory allocator.
1237  Lower runtime footprint.
1238 \layout Standard
1239
1240 Furthermore the environment variables CC, CFLAGS, ...
1241  the tools and their arguments can be influenced.
1242  Please see `configure -
1243 \begin_inset ERT
1244 status Collapsed
1245
1246 \layout Standard
1247
1248 \backslash 
1249 /
1250 \end_inset 
1251
1252 -help` and the man/info pages of `configure` for details.
1253 \newline 
1254
1255 \newline 
1256 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1257  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1258 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1259  At the moment it's not possible to change the default settings (it was
1260  simply never required).
1261 \newline 
1262
1263 \newline 
1264 These configure options are compiled into the binaries, and can only be
1265  changed by rerunning 'configure' and recompiling SDCC.
1266  The configure options are written in 
1267 \emph on 
1268 italics
1269 \emph default 
1270  to distinguish them from run time environment variables (see section search
1271  paths).
1272 \newline 
1273
1274 \newline 
1275 The settings for 
1276 \begin_inset Quotes sld
1277 \end_inset 
1278
1279 Win32 builds
1280 \begin_inset Quotes srd
1281 \end_inset 
1282
1283  are used by the SDCC team to build the official Win32 binaries.
1284  The SDCC team uses Mingw32 to build the official Windows binaries, because
1285  it's
1286 \layout Enumerate
1287
1288 open source, 
1289 \layout Enumerate
1290
1291 a gcc compiler and last but not least
1292 \layout Enumerate
1293
1294 the binaries can be built by cross compiling on Sourceforge's compile farm.
1295 \layout Standard
1296
1297 See the examples, how to pass the Win32 settings to 'configure'.
1298  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1299  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1300  for Win32.
1301 \newline 
1302
1303 \newline 
1304 These defaults are:
1305 \newline 
1306
1307 \layout Standard
1308 \align center 
1309
1310 \begin_inset  Tabular
1311 <lyxtabular version="3" rows="8" columns="3">
1312 <features>
1313 <column alignment="block" valignment="top" leftline="true" width="0in">
1314 <column alignment="block" valignment="top" leftline="true" width="0in">
1315 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1316 <row topline="true" bottomline="true">
1317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1318 \begin_inset Text
1319
1320 \layout Standard
1321
1322 Variable
1323 \end_inset 
1324 </cell>
1325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1326 \begin_inset Text
1327
1328 \layout Standard
1329
1330 default
1331 \end_inset 
1332 </cell>
1333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1334 \begin_inset Text
1335
1336 \layout Standard
1337
1338 Win32 builds
1339 \end_inset 
1340 </cell>
1341 </row>
1342 <row topline="true">
1343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1344 \begin_inset Text
1345
1346 \layout Standard
1347
1348
1349 \emph on 
1350 PREFIX
1351 \end_inset 
1352 </cell>
1353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1354 \begin_inset Text
1355
1356 \layout Standard
1357
1358 /usr/local
1359 \end_inset 
1360 </cell>
1361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1362 \begin_inset Text
1363
1364 \layout Standard
1365
1366
1367 \backslash 
1368 sdcc
1369 \end_inset 
1370 </cell>
1371 </row>
1372 <row topline="true">
1373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1374 \begin_inset Text
1375
1376 \layout Standard
1377
1378
1379 \emph on 
1380 EXEC_PREFIX
1381 \end_inset 
1382 </cell>
1383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1384 \begin_inset Text
1385
1386 \layout Standard
1387
1388
1389 \emph on 
1390 $PREFIX
1391 \end_inset 
1392 </cell>
1393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1394 \begin_inset Text
1395
1396 \layout Standard
1397
1398
1399 \emph on 
1400 $PREFIX
1401 \end_inset 
1402 </cell>
1403 </row>
1404 <row topline="true">
1405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1406 \begin_inset Text
1407
1408 \layout Standard
1409
1410
1411 \emph on 
1412 BINDIR
1413 \end_inset 
1414 </cell>
1415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1416 \begin_inset Text
1417
1418 \layout Standard
1419
1420
1421 \emph on 
1422 $EXECPREFIX
1423 \emph default 
1424 /bin
1425 \end_inset 
1426 </cell>
1427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1428 \begin_inset Text
1429
1430 \layout Standard
1431
1432
1433 \emph on 
1434 $EXECPREFIX
1435 \emph default 
1436
1437 \backslash 
1438 bin
1439 \end_inset 
1440 </cell>
1441 </row>
1442 <row topline="true">
1443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1444 \begin_inset Text
1445
1446 \layout Standard
1447
1448
1449 \emph on 
1450 DATADIR
1451 \end_inset 
1452 </cell>
1453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1454 \begin_inset Text
1455
1456 \layout Standard
1457
1458
1459 \emph on 
1460 $PREFIX
1461 \emph default 
1462 /share
1463 \end_inset 
1464 </cell>
1465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1466 \begin_inset Text
1467
1468 \layout Standard
1469
1470
1471 \emph on 
1472 $PREFIX
1473 \end_inset 
1474 </cell>
1475 </row>
1476 <row topline="true">
1477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1478 \begin_inset Text
1479
1480 \layout Standard
1481
1482
1483 \emph on 
1484 DOCDIR
1485 \end_inset 
1486 </cell>
1487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1488 \begin_inset Text
1489
1490 \layout Standard
1491
1492
1493 \emph on 
1494 $DATADIR
1495 \emph default 
1496 /sdcc/doc
1497 \end_inset 
1498 </cell>
1499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1500 \begin_inset Text
1501
1502 \layout Standard
1503
1504
1505 \emph on 
1506 $DATADIR
1507 \emph default 
1508
1509 \backslash 
1510 doc
1511 \end_inset 
1512 </cell>
1513 </row>
1514 <row topline="true">
1515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1516 \begin_inset Text
1517
1518 \layout Standard
1519
1520
1521 \emph on 
1522 INCLUDE_DIR_SUFFIX
1523 \end_inset 
1524 </cell>
1525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1526 \begin_inset Text
1527
1528 \layout Standard
1529
1530 sdcc/include
1531 \end_inset 
1532 </cell>
1533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1534 \begin_inset Text
1535
1536 \layout Standard
1537
1538 include
1539 \end_inset 
1540 </cell>
1541 </row>
1542 <row topline="true" bottomline="true">
1543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1544 \begin_inset Text
1545
1546 \layout Standard
1547
1548
1549 \emph on 
1550 LIB_DIR_SUFFIX
1551 \end_inset 
1552 </cell>
1553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1554 \begin_inset Text
1555
1556 \layout Standard
1557
1558 sdcc/lib
1559 \end_inset 
1560 </cell>
1561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1562 \begin_inset Text
1563
1564 \layout Standard
1565
1566 lib
1567 \end_inset 
1568 </cell>
1569 </row>
1570 </lyxtabular>
1571
1572 \end_inset 
1573
1574
1575 \newline 
1576
1577 \layout Standard
1578 \noindent 
1579 'configure' also computes relative paths.
1580  This is needed for full relocatability of a binary package and to complete
1581  search paths (see section search paths below):
1582 \newline 
1583  
1584 \layout Standard
1585 \align center 
1586
1587 \begin_inset  Tabular
1588 <lyxtabular version="3" rows="4" columns="3">
1589 <features>
1590 <column alignment="block" valignment="top" leftline="true" width="0in">
1591 <column alignment="block" valignment="top" leftline="true" width="0in">
1592 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1593 <row topline="true" bottomline="true">
1594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1595 \begin_inset Text
1596
1597 \layout Standard
1598
1599 Variable (computed)
1600 \end_inset 
1601 </cell>
1602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1603 \begin_inset Text
1604
1605 \layout Standard
1606
1607 default
1608 \end_inset 
1609 </cell>
1610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1611 \begin_inset Text
1612
1613 \layout Standard
1614
1615 Win32 builds
1616 \end_inset 
1617 </cell>
1618 </row>
1619 <row topline="true" bottomline="true">
1620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1621 \begin_inset Text
1622
1623 \layout Standard
1624
1625
1626 \emph on 
1627 BIN2DATA_DIR
1628 \end_inset 
1629 </cell>
1630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1631 \begin_inset Text
1632
1633 \layout Standard
1634
1635 ../share
1636 \end_inset 
1637 </cell>
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1639 \begin_inset Text
1640
1641 \layout Standard
1642
1643 ..
1644 \end_inset 
1645 </cell>
1646 </row>
1647 <row bottomline="true">
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1649 \begin_inset Text
1650
1651 \layout Standard
1652
1653
1654 \emph on 
1655 PREFIX2BIN_DIR
1656 \end_inset 
1657 </cell>
1658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1659 \begin_inset Text
1660
1661 \layout Standard
1662
1663 bin
1664 \end_inset 
1665 </cell>
1666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1667 \begin_inset Text
1668
1669 \layout Standard
1670
1671 bin
1672 \end_inset 
1673 </cell>
1674 </row>
1675 <row bottomline="true">
1676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1677 \begin_inset Text
1678
1679 \layout Standard
1680
1681
1682 \emph on 
1683 PREFIX2DATA_DIR
1684 \end_inset 
1685 </cell>
1686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1687 \begin_inset Text
1688
1689 \layout Standard
1690
1691 share/sdcc
1692 \end_inset 
1693 </cell>
1694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1695 \begin_inset Text
1696
1697 \layout Standard
1698
1699 \end_inset 
1700 </cell>
1701 </row>
1702 </lyxtabular>
1703
1704 \end_inset 
1705
1706
1707 \newline 
1708
1709 \layout Standard
1710 \noindent 
1711 Examples:
1712 \layout LyX-Code
1713
1714 ./configure
1715 \newline 
1716 ./configure -
1717 \begin_inset ERT
1718 status Collapsed
1719
1720 \layout Standard
1721
1722 \backslash 
1723 /
1724 \end_inset 
1725
1726 -prefix=
1727 \begin_inset Quotes srd
1728 \end_inset 
1729
1730 /usr/bin
1731 \begin_inset Quotes srd
1732 \end_inset 
1733
1734  -
1735 \begin_inset ERT
1736 status Collapsed
1737
1738 \layout Standard
1739
1740 \backslash 
1741 /
1742 \end_inset 
1743
1744 -datadir=
1745 \begin_inset Quotes srd
1746 \end_inset 
1747
1748 /usr/share
1749 \begin_inset Quotes srd
1750 \end_inset 
1751
1752
1753 \newline 
1754 ./configure -
1755 \begin_inset ERT
1756 status Collapsed
1757
1758 \layout Standard
1759
1760 \backslash 
1761 /
1762 \end_inset 
1763
1764 -disable-avr-port -
1765 \begin_inset ERT
1766 status Collapsed
1767
1768 \layout Standard
1769
1770 \backslash 
1771 /
1772 \end_inset 
1773
1774 -disable-xa51-port
1775 \layout Standard
1776
1777 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1778 32'):
1779 \layout LyX-Code
1780
1781 ./configure 
1782 \backslash 
1783
1784 \newline 
1785 CC=
1786 \begin_inset Quotes srd
1787 \end_inset 
1788
1789 i586-mingw32msvc-gcc
1790 \begin_inset Quotes srd
1791 \end_inset 
1792
1793  CXX=
1794 \begin_inset Quotes srd
1795 \end_inset 
1796
1797 i586-mingw32msvc-g++
1798 \begin_inset Quotes srd
1799 \end_inset 
1800
1801  
1802 \backslash 
1803  
1804 \newline 
1805 RANLIB=
1806 \begin_inset Quotes srd
1807 \end_inset 
1808
1809 i586-mingw32msvc-ranlib
1810 \begin_inset Quotes srd
1811 \end_inset 
1812
1813  
1814 \backslash 
1815
1816 \newline 
1817 STRIP=
1818 \begin_inset Quotes srd
1819 \end_inset 
1820
1821 i586-mingw32msvc-strip
1822 \begin_inset Quotes srd
1823 \end_inset 
1824
1825  
1826 \backslash 
1827
1828 \newline 
1829 -
1830 \begin_inset ERT
1831 status Collapsed
1832
1833 \layout Standard
1834
1835 \backslash 
1836 /
1837 \end_inset 
1838
1839 -prefix=
1840 \begin_inset Quotes srd
1841 \end_inset 
1842
1843 /sdcc
1844 \begin_inset Quotes srd
1845 \end_inset 
1846
1847  
1848 \backslash 
1849
1850 \newline 
1851 -
1852 \begin_inset ERT
1853 status Collapsed
1854
1855 \layout Standard
1856
1857 \backslash 
1858 /
1859 \end_inset 
1860
1861 -datadir=
1862 \begin_inset Quotes srd
1863 \end_inset 
1864
1865 /sdcc
1866 \begin_inset Quotes srd
1867 \end_inset 
1868
1869  
1870 \backslash 
1871
1872 \newline 
1873 docdir=
1874 \begin_inset Quotes srd
1875 \end_inset 
1876
1877 /sdcc/doc
1878 \begin_inset Quotes srd
1879 \end_inset 
1880
1881  
1882 \backslash 
1883
1884 \newline 
1885 include_dir_suffix=
1886 \begin_inset Quotes srd
1887 \end_inset 
1888
1889 include
1890 \begin_inset Quotes srd
1891 \end_inset 
1892
1893  
1894 \backslash 
1895
1896 \newline 
1897 lib_dir_suffix=
1898 \begin_inset Quotes srd
1899 \end_inset 
1900
1901 lib
1902 \begin_inset Quotes srd
1903 \end_inset 
1904
1905  
1906 \backslash 
1907
1908 \newline 
1909 sdccconf_h_dir_separator=
1910 \begin_inset Quotes srd
1911 \end_inset 
1912
1913
1914 \backslash 
1915
1916 \backslash 
1917
1918 \backslash 
1919
1920 \backslash 
1921
1922 \begin_inset Quotes srd
1923 \end_inset 
1924
1925  
1926 \backslash 
1927
1928 \newline 
1929 -
1930 \begin_inset ERT
1931 status Collapsed
1932
1933 \layout Standard
1934
1935 \backslash 
1936 /
1937 \end_inset 
1938
1939 -disable-device-lib
1940 \backslash 
1941
1942 \newline 
1943 -
1944 \begin_inset ERT
1945 status Collapsed
1946
1947 \layout Standard
1948
1949 \backslash 
1950 /
1951 \end_inset 
1952
1953 -disable-ucsim
1954 \backslash 
1955
1956 \newline 
1957 -
1958 \begin_inset ERT
1959 status Collapsed
1960
1961 \layout Standard
1962
1963 \backslash 
1964 /
1965 \end_inset 
1966
1967 -host=i586-mingw32msvc -
1968 \begin_inset ERT
1969 status Collapsed
1970
1971 \layout Standard
1972
1973 \backslash 
1974 /
1975 \end_inset 
1976
1977 -build=unknown-unknown-linux-gnu
1978 \layout Standard
1979
1980 To 
1981 \begin_inset Quotes sld
1982 \end_inset 
1983
1984 cross
1985 \begin_inset Quotes srd
1986 \end_inset 
1987
1988 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1989 ):
1990 \layout LyX-Code
1991
1992 ./configure -C 
1993 \backslash 
1994
1995 \newline 
1996 CFLAGS=
1997 \begin_inset Quotes srd
1998 \end_inset 
1999
2000 -mno-cygwin -O2
2001 \begin_inset Quotes srd
2002 \end_inset 
2003
2004  
2005 \backslash 
2006
2007 \newline 
2008 LDFLAGS=
2009 \begin_inset Quotes srd
2010 \end_inset 
2011
2012 -mno-cygwin
2013 \begin_inset Quotes srd
2014 \end_inset 
2015
2016  
2017 \backslash 
2018
2019 \newline 
2020 -
2021 \begin_inset ERT
2022 status Collapsed
2023
2024 \layout Standard
2025
2026 \backslash 
2027 /
2028 \end_inset 
2029
2030 -prefix=
2031 \begin_inset Quotes srd
2032 \end_inset 
2033
2034 /sdcc
2035 \begin_inset Quotes srd
2036 \end_inset 
2037
2038  
2039 \backslash 
2040
2041 \newline 
2042 -
2043 \begin_inset ERT
2044 status Collapsed
2045
2046 \layout Standard
2047
2048 \backslash 
2049 /
2050 \end_inset 
2051
2052 -datadir=
2053 \begin_inset Quotes srd
2054 \end_inset 
2055
2056 /sdcc
2057 \begin_inset Quotes srd
2058 \end_inset 
2059
2060  
2061 \backslash 
2062
2063 \newline 
2064 docdir=
2065 \begin_inset Quotes srd
2066 \end_inset 
2067
2068 /sdcc/doc
2069 \begin_inset Quotes srd
2070 \end_inset 
2071
2072  
2073 \backslash 
2074  
2075 \newline 
2076 include_dir_suffix=
2077 \begin_inset Quotes srd
2078 \end_inset 
2079
2080 include
2081 \begin_inset Quotes srd
2082 \end_inset 
2083
2084  
2085 \backslash 
2086
2087 \newline 
2088 lib_dir_suffix=
2089 \begin_inset Quotes srd
2090 \end_inset 
2091
2092 lib
2093 \begin_inset Quotes srd
2094 \end_inset 
2095
2096  
2097 \backslash 
2098
2099 \newline 
2100 sdccconf_h_dir_separator=
2101 \begin_inset Quotes srd
2102 \end_inset 
2103
2104
2105 \backslash 
2106
2107 \backslash 
2108
2109 \backslash 
2110
2111 \backslash 
2112
2113 \begin_inset Quotes srd
2114 \end_inset 
2115
2116  
2117 \backslash 
2118
2119 \newline 
2120 -
2121 \begin_inset ERT
2122 status Collapsed
2123
2124 \layout Standard
2125
2126 \backslash 
2127 /
2128 \end_inset 
2129
2130 -disable-ucsim
2131 \layout Standard
2132
2133 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2134  The option '-
2135 \begin_inset ERT
2136 status Collapsed
2137
2138 \layout Standard
2139
2140 \backslash 
2141 /
2142 \end_inset 
2143
2144 -C' turns on caching, which gives a little bit extra speed.
2145  However if options are changed, it can be necessary to delete the config.cache
2146  file.
2147 \layout Section
2148
2149 Install paths
2150 \begin_inset LatexCommand \label{sub:Install-paths}
2151
2152 \end_inset 
2153
2154
2155 \begin_inset LatexCommand \index{Install paths}
2156
2157 \end_inset 
2158
2159
2160 \layout Standard
2161 \added_space_top medskip \align center 
2162
2163 \begin_inset  Tabular
2164 <lyxtabular version="3" rows="5" columns="4">
2165 <features>
2166 <column alignment="left" valignment="top" leftline="true" width="0">
2167 <column alignment="left" valignment="top" leftline="true" width="0">
2168 <column alignment="left" valignment="top" leftline="true" width="0">
2169 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2170 <row topline="true" bottomline="true">
2171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2172 \begin_inset Text
2173
2174 \layout Standard
2175
2176
2177 \series bold 
2178 Description
2179 \end_inset 
2180 </cell>
2181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2182 \begin_inset Text
2183
2184 \layout Standard
2185
2186
2187 \series bold 
2188 Path
2189 \end_inset 
2190 </cell>
2191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2192 \begin_inset Text
2193
2194 \layout Standard
2195
2196
2197 \series bold 
2198 Default
2199 \end_inset 
2200 </cell>
2201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2202 \begin_inset Text
2203
2204 \layout Standard
2205
2206
2207 \series bold 
2208 Win32 builds
2209 \end_inset 
2210 </cell>
2211 </row>
2212 <row topline="true">
2213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2214 \begin_inset Text
2215
2216 \layout Standard
2217
2218 Binary files*
2219 \end_inset 
2220 </cell>
2221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2222 \begin_inset Text
2223
2224 \layout Standard
2225
2226
2227 \emph on 
2228 $EXEC_PREFIX
2229 \end_inset 
2230 </cell>
2231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2232 \begin_inset Text
2233
2234 \layout Standard
2235
2236 /usr/local/bin
2237 \end_inset 
2238 </cell>
2239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2240 \begin_inset Text
2241
2242 \layout Standard
2243
2244
2245 \backslash 
2246 sdcc
2247 \backslash 
2248 bin
2249 \end_inset 
2250 </cell>
2251 </row>
2252 <row topline="true">
2253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2254 \begin_inset Text
2255
2256 \layout Standard
2257
2258 Include files
2259 \end_inset 
2260 </cell>
2261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2262 \begin_inset Text
2263
2264 \layout Standard
2265
2266
2267 \emph on 
2268 $DATADIR/ $INCLUDE_DIR_SUFFIX
2269 \end_inset 
2270 </cell>
2271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2272 \begin_inset Text
2273
2274 \layout Standard
2275
2276 /usr/local/share/sdcc/include
2277 \end_inset 
2278 </cell>
2279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2280 \begin_inset Text
2281
2282 \layout Standard
2283
2284
2285 \backslash 
2286 sdcc
2287 \backslash 
2288 include
2289 \end_inset 
2290 </cell>
2291 </row>
2292 <row topline="true">
2293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2294 \begin_inset Text
2295
2296 \layout Standard
2297
2298 Library file**
2299 \end_inset 
2300 </cell>
2301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2302 \begin_inset Text
2303
2304 \layout Standard
2305
2306
2307 \emph on 
2308 $DATADIR/$LIB_DIR_SUFFIX
2309 \end_inset 
2310 </cell>
2311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2312 \begin_inset Text
2313
2314 \layout Standard
2315
2316 /usr/local/share/sdcc/lib
2317 \end_inset 
2318 </cell>
2319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2320 \begin_inset Text
2321
2322 \layout Standard
2323
2324
2325 \backslash 
2326 sdcc
2327 \backslash 
2328 lib
2329 \end_inset 
2330 </cell>
2331 </row>
2332 <row topline="true" bottomline="true">
2333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2334 \begin_inset Text
2335
2336 \layout Standard
2337
2338 Documentation
2339 \end_inset 
2340 </cell>
2341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2342 \begin_inset Text
2343
2344 \layout Standard
2345
2346
2347 \emph on 
2348 $DOCDIR
2349 \end_inset 
2350 </cell>
2351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2352 \begin_inset Text
2353
2354 \layout Standard
2355
2356 /usr/local/share/sdcc/doc
2357 \end_inset 
2358 </cell>
2359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2360 \begin_inset Text
2361
2362 \layout Standard
2363
2364
2365 \backslash 
2366 sdcc
2367 \backslash 
2368 doc
2369 \end_inset 
2370 </cell>
2371 </row>
2372 </lyxtabular>
2373
2374 \end_inset 
2375
2376
2377 \layout Verse
2378
2379
2380 \size footnotesize 
2381 *compiler, preprocessor, assembler, and linker
2382 \newline 
2383 **the 
2384 \shape italic 
2385 model
2386 \shape default 
2387  is auto-appended by the compiler, e.g.
2388  small, large, z80, ds390 etc
2389 \layout Standard
2390 \noindent 
2391 The install paths can still be changed during `make install` with e.g.:
2392 \layout LyX-Code
2393
2394 make install prefix=$(HOME)/local/sdcc
2395 \layout Standard
2396
2397 Of course this doesn't change the search paths compiled into the binaries.
2398 \newline 
2399
2400 \newline 
2401 Moreover the install path can be changed by defining DESTDIR
2402 \begin_inset LatexCommand \index{DESTDIR}
2403
2404 \end_inset 
2405
2406 :
2407 \layout LyX-Code
2408
2409 make install DESTDIR=$(HOME)/sdcc.rpm/
2410 \layout Standard
2411
2412 Please note that DESTDIR must have a trailing slash!
2413 \layout Section
2414
2415 Search Paths
2416 \begin_inset LatexCommand \label{sub:Search-Paths}
2417
2418 \end_inset 
2419
2420
2421 \begin_inset LatexCommand \index{Search path}
2422
2423 \end_inset 
2424
2425
2426 \layout Standard
2427
2428 Some search paths or parts of them are determined by configure variables
2429  (in 
2430 \emph on 
2431 italics
2432 \emph default 
2433 , see section above).
2434  Further search paths are determined by environment variables during runtime.
2435  
2436 \newline 
2437 The paths searched when running the compiler are as follows (the first catch
2438  wins):
2439 \newline 
2440
2441 \newline 
2442 1.
2443  Binary files (preprocessor, assembler and linker)
2444 \newline 
2445
2446 \layout Standard
2447 \align center 
2448
2449 \begin_inset  Tabular
2450 <lyxtabular version="3" rows="4" columns="3">
2451 <features>
2452 <column alignment="block" valignment="top" leftline="true" width="0in">
2453 <column alignment="block" valignment="top" leftline="true" width="0in">
2454 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2455 <row topline="true" bottomline="true">
2456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2457 \begin_inset Text
2458
2459 \layout Standard
2460
2461 Search path
2462 \end_inset 
2463 </cell>
2464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2465 \begin_inset Text
2466
2467 \layout Standard
2468
2469 default
2470 \end_inset 
2471 </cell>
2472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2473 \begin_inset Text
2474
2475 \layout Standard
2476
2477 Win32 builds
2478 \end_inset 
2479 </cell>
2480 </row>
2481 <row topline="true">
2482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2483 \begin_inset Text
2484
2485 \layout Standard
2486
2487 $SDCC_HOME/
2488 \emph on 
2489 $PPREFIX2BIN_DIR
2490 \end_inset 
2491 </cell>
2492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2493 \begin_inset Text
2494
2495 \layout Standard
2496
2497 $SDCC_HOME/bin
2498 \end_inset 
2499 </cell>
2500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2501 \begin_inset Text
2502
2503 \layout Standard
2504
2505 $SDCC_HOME
2506 \backslash 
2507 bin
2508 \end_inset 
2509 </cell>
2510 </row>
2511 <row topline="true">
2512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2513 \begin_inset Text
2514
2515 \layout Standard
2516
2517 Path of argv[0] (if available)
2518 \end_inset 
2519 </cell>
2520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2521 \begin_inset Text
2522
2523 \layout Standard
2524
2525 Path of argv[0]
2526 \end_inset 
2527 </cell>
2528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2529 \begin_inset Text
2530
2531 \layout Standard
2532
2533 Path of argv[0]
2534 \end_inset 
2535 </cell>
2536 </row>
2537 <row topline="true" bottomline="true">
2538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2539 \begin_inset Text
2540
2541 \layout Standard
2542
2543 $PATH
2544 \end_inset 
2545 </cell>
2546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2547 \begin_inset Text
2548
2549 \layout Standard
2550
2551 $PATH
2552 \end_inset 
2553 </cell>
2554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2555 \begin_inset Text
2556
2557 \layout Standard
2558
2559 $PATH
2560 \end_inset 
2561 </cell>
2562 </row>
2563 </lyxtabular>
2564
2565 \end_inset 
2566
2567  
2568 \newline 
2569
2570 \layout Standard
2571 \noindent 
2572 2.
2573  Include files
2574 \newline 
2575
2576 \layout Standard
2577 \align center 
2578
2579 \begin_inset  Tabular
2580 <lyxtabular version="3" rows="6" columns="3">
2581 <features>
2582 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2583 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2584 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2585 <row topline="true" bottomline="true">
2586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2587 \begin_inset Text
2588
2589 \layout Standard
2590
2591 Search path
2592 \end_inset 
2593 </cell>
2594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2595 \begin_inset Text
2596
2597 \layout Standard
2598
2599 default
2600 \end_inset 
2601 </cell>
2602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2603 \begin_inset Text
2604
2605 \layout Standard
2606
2607 Win32 builds
2608 \end_inset 
2609 </cell>
2610 </row>
2611 <row topline="true">
2612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2613 \begin_inset Text
2614
2615 \layout Standard
2616
2617 -
2618 \begin_inset ERT
2619 status Collapsed
2620
2621 \layout Standard
2622
2623 \backslash 
2624 /
2625 \end_inset 
2626
2627 -I dir
2628 \end_inset 
2629 </cell>
2630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2631 \begin_inset Text
2632
2633 \layout Standard
2634
2635 -
2636 \begin_inset ERT
2637 status Collapsed
2638
2639 \layout Standard
2640
2641 \backslash 
2642 /
2643 \end_inset 
2644
2645 -I dir
2646 \end_inset 
2647 </cell>
2648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2649 \begin_inset Text
2650
2651 \layout Standard
2652
2653 -
2654 \begin_inset ERT
2655 status Collapsed
2656
2657 \layout Standard
2658
2659 \backslash 
2660 /
2661 \end_inset 
2662
2663 -I dir
2664 \end_inset 
2665 </cell>
2666 </row>
2667 <row topline="true">
2668 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2669 \begin_inset Text
2670
2671 \layout Standard
2672
2673 $SDCC_INCLUDE
2674 \end_inset 
2675 </cell>
2676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2677 \begin_inset Text
2678
2679 \layout Standard
2680
2681 $SDCC_INCLUDE
2682 \end_inset 
2683 </cell>
2684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2685 \begin_inset Text
2686
2687 \layout Standard
2688
2689 $SDCC_INCLUDE
2690 \end_inset 
2691 </cell>
2692 </row>
2693 <row topline="true">
2694 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2695 \begin_inset Text
2696
2697 \layout Standard
2698
2699 $SDCC_HOME/
2700 \newline 
2701
2702 \emph on 
2703 $PREFIX2DATA_DIR/
2704 \newline 
2705 $INCLUDE_DIR_SUFFIX
2706 \end_inset 
2707 </cell>
2708 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2709 \begin_inset Text
2710
2711 \layout Standard
2712
2713 $SDCC_ HOME/
2714 \newline 
2715 share/sdcc/
2716 \newline 
2717 include
2718 \end_inset 
2719 </cell>
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2721 \begin_inset Text
2722
2723 \layout Standard
2724
2725 $SDCC_HOME
2726 \backslash 
2727 include
2728 \end_inset 
2729 </cell>
2730 </row>
2731 <row topline="true">
2732 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2733 \begin_inset Text
2734
2735 \layout Standard
2736
2737 path(argv[0])/
2738 \newline 
2739
2740 \emph on 
2741 $BIN2DATADIR/
2742 \emph default 
2743
2744 \newline 
2745
2746 \emph on 
2747 $INCLUDE_DIR_SUFFIX
2748 \end_inset 
2749 </cell>
2750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2751 \begin_inset Text
2752
2753 \layout Standard
2754
2755 path(argv[0])/
2756 \newline 
2757 ../sdcc/include
2758 \newline 
2759 \SpecialChar ~
2760 \SpecialChar ~
2761 \SpecialChar ~
2762 \SpecialChar ~
2763 \SpecialChar ~
2764 \SpecialChar ~
2765 \SpecialChar ~
2766 \SpecialChar ~
2767 \SpecialChar ~
2768 \SpecialChar ~
2769 \SpecialChar ~
2770 \SpecialChar ~
2771 \SpecialChar ~
2772 \SpecialChar ~
2773 \SpecialChar ~
2774 \SpecialChar ~
2775 \SpecialChar ~
2776 \SpecialChar ~
2777 \SpecialChar ~
2778 \SpecialChar ~
2779 \SpecialChar ~
2780 \SpecialChar ~
2781 \SpecialChar ~
2782 \SpecialChar ~
2783 \SpecialChar ~
2784 \SpecialChar ~
2785 \SpecialChar ~
2786 \SpecialChar ~
2787 \SpecialChar ~
2788 \SpecialChar ~
2789 \SpecialChar ~
2790 \SpecialChar ~
2791 \SpecialChar ~
2792 \SpecialChar ~
2793 \SpecialChar ~
2794 \SpecialChar ~
2795 \SpecialChar ~
2796 \SpecialChar ~
2797
2798 \end_inset 
2799 </cell>
2800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2801 \begin_inset Text
2802
2803 \layout Standard
2804
2805 path(argv[0])
2806 \backslash 
2807 ..
2808 \backslash 
2809 include
2810 \end_inset 
2811 </cell>
2812 </row>
2813 <row topline="true" bottomline="true">
2814 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2815 \begin_inset Text
2816
2817 \layout Standard
2818
2819
2820 \emph on 
2821 $DATADIR/
2822 \emph default 
2823
2824 \newline 
2825
2826 \emph on 
2827 $INCLUDE_DIR_SUFFIX
2828 \end_inset 
2829 </cell>
2830 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2831 \begin_inset Text
2832
2833 \layout Standard
2834
2835 /usr/local/share/sdcc/
2836 \newline 
2837 include
2838 \end_inset 
2839 </cell>
2840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2841 \begin_inset Text
2842
2843 \layout Standard
2844
2845 (not on Win32)
2846 \end_inset 
2847 </cell>
2848 </row>
2849 </lyxtabular>
2850
2851 \end_inset 
2852
2853  
2854 \newline 
2855
2856 \layout Standard
2857 \noindent 
2858 The option -
2859 \begin_inset ERT
2860 status Collapsed
2861
2862 \layout Standard
2863
2864 \backslash 
2865 /
2866 \end_inset 
2867
2868 -nostdinc disables the last two search paths.
2869 \newline 
2870
2871 \newline 
2872 3.
2873  Library files 
2874 \newline 
2875
2876 \layout Standard
2877
2878 With the exception of 
2879 \begin_inset Quotes sld
2880 \end_inset 
2881
2882 -
2883 \begin_inset ERT
2884 status Collapsed
2885
2886 \layout Standard
2887
2888 \backslash 
2889 /
2890 \end_inset 
2891
2892 -L dir
2893 \begin_inset Quotes srd
2894 \end_inset 
2895
2896  the 
2897 \shape italic 
2898 model
2899 \shape default 
2900  is auto-appended by the compiler (e.g.
2901  small, large, z80, ds390 etc.).
2902  
2903 \newline 
2904
2905 \layout Standard
2906 \align center 
2907
2908 \begin_inset  Tabular
2909 <lyxtabular version="3" rows="6" columns="3">
2910 <features>
2911 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2912 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2913 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2914 <row topline="true" bottomline="true">
2915 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2916 \begin_inset Text
2917
2918 \layout Standard
2919
2920 Search path
2921 \end_inset 
2922 </cell>
2923 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2924 \begin_inset Text
2925
2926 \layout Standard
2927
2928 default
2929 \end_inset 
2930 </cell>
2931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2932 \begin_inset Text
2933
2934 \layout Standard
2935
2936 Win32 builds
2937 \end_inset 
2938 </cell>
2939 </row>
2940 <row topline="true">
2941 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2942 \begin_inset Text
2943
2944 \layout Standard
2945
2946 -
2947 \begin_inset ERT
2948 status Collapsed
2949
2950 \layout Standard
2951
2952 \backslash 
2953 /
2954 \end_inset 
2955
2956 -L dir
2957 \end_inset 
2958 </cell>
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_inset Text
2961
2962 \layout Standard
2963
2964 -
2965 \begin_inset ERT
2966 status Collapsed
2967
2968 \layout Standard
2969
2970 \backslash 
2971 /
2972 \end_inset 
2973
2974 -L dir
2975 \end_inset 
2976 </cell>
2977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2978 \begin_inset Text
2979
2980 \layout Standard
2981
2982 -
2983 \begin_inset ERT
2984 status Collapsed
2985
2986 \layout Standard
2987
2988 \backslash 
2989 /
2990 \end_inset 
2991
2992 -L dir
2993 \end_inset 
2994 </cell>
2995 </row>
2996 <row topline="true">
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2998 \begin_inset Text
2999
3000 \layout Standard
3001
3002 $SDCC_LIB/
3003 \newline 
3004
3005 \emph on 
3006 <model>
3007 \end_inset 
3008 </cell>
3009 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3010 \begin_inset Text
3011
3012 \layout Standard
3013
3014 $SDCC_LIB/
3015 \newline 
3016
3017 \emph on 
3018 <model>
3019 \end_inset 
3020 </cell>
3021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3022 \begin_inset Text
3023
3024 \layout Standard
3025
3026 $SDCC_LIB
3027 \backslash 
3028
3029 \newline 
3030
3031 \emph on 
3032 <model>
3033 \end_inset 
3034 </cell>
3035 </row>
3036 <row topline="true">
3037 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3038 \begin_inset Text
3039
3040 \layout Standard
3041
3042 $SDCC_HOME/
3043 \newline 
3044
3045 \emph on 
3046 $PREFIX2DATA_DIR/
3047 \newline 
3048 $LIB_DIR_SUFFIX/<model>
3049 \end_inset 
3050 </cell>
3051 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_inset Text
3053
3054 \layout Standard
3055
3056 $SDCC_HOME/
3057 \newline 
3058 share/sdcc/
3059 \newline 
3060 lib/
3061 \emph on 
3062 <model>
3063 \end_inset 
3064 </cell>
3065 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3066 \begin_inset Text
3067
3068 \layout Standard
3069
3070 $SDCC_HOME
3071 \backslash 
3072 lib
3073 \backslash 
3074
3075 \emph on 
3076
3077 \newline 
3078 <model>
3079 \end_inset 
3080 </cell>
3081 </row>
3082 <row topline="true">
3083 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3084 \begin_inset Text
3085
3086 \layout Standard
3087
3088 path(argv[0])/
3089 \newline 
3090
3091 \emph on 
3092 $BIN2DATADIR/
3093 \emph default 
3094
3095 \newline 
3096
3097 \emph on 
3098 $LIB_DIR_SUFFIX/<model>
3099 \end_inset 
3100 </cell>
3101 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3102 \begin_inset Text
3103
3104 \layout Standard
3105
3106 path(argv[0])/
3107 \newline 
3108 ../sdcc/lib/
3109 \emph on 
3110 <model>
3111 \newline 
3112 \SpecialChar ~
3113 \SpecialChar ~
3114 \SpecialChar ~
3115 \SpecialChar ~
3116 \SpecialChar ~
3117 \SpecialChar ~
3118 \SpecialChar ~
3119 \SpecialChar ~
3120 \SpecialChar ~
3121 \SpecialChar ~
3122 \SpecialChar ~
3123 \SpecialChar ~
3124 \SpecialChar ~
3125 \SpecialChar ~
3126 \SpecialChar ~
3127 \SpecialChar ~
3128 \SpecialChar ~
3129 \SpecialChar ~
3130 \SpecialChar ~
3131 \SpecialChar ~
3132 \SpecialChar ~
3133 \SpecialChar ~
3134 \SpecialChar ~
3135 \SpecialChar ~
3136 \SpecialChar ~
3137 \SpecialChar ~
3138 \SpecialChar ~
3139 \SpecialChar ~
3140 \SpecialChar ~
3141 \SpecialChar ~
3142 \SpecialChar ~
3143 \SpecialChar ~
3144 \SpecialChar ~
3145 \SpecialChar ~
3146 \SpecialChar ~
3147 \SpecialChar ~
3148 \SpecialChar ~
3149 \SpecialChar ~
3150 \SpecialChar ~
3151
3152 \end_inset 
3153 </cell>
3154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3155 \begin_inset Text
3156
3157 \layout Standard
3158
3159 path(argv[0])
3160 \backslash 
3161
3162 \newline 
3163 ..
3164 \backslash 
3165 lib
3166 \backslash 
3167
3168 \emph on 
3169 <model>
3170 \newline 
3171 \SpecialChar ~
3172 \SpecialChar ~
3173 \SpecialChar ~
3174 \SpecialChar ~
3175 \SpecialChar ~
3176 \SpecialChar ~
3177 \SpecialChar ~
3178 \SpecialChar ~
3179 \SpecialChar ~
3180 \SpecialChar ~
3181 \SpecialChar ~
3182 \SpecialChar ~
3183 \SpecialChar ~
3184 \SpecialChar ~
3185 \SpecialChar ~
3186 \SpecialChar ~
3187 \SpecialChar ~
3188 \SpecialChar ~
3189 \SpecialChar ~
3190 \SpecialChar ~
3191 \SpecialChar ~
3192 \SpecialChar ~
3193 \SpecialChar ~
3194 \SpecialChar ~
3195 \SpecialChar ~
3196 \SpecialChar ~
3197 \SpecialChar ~
3198 \SpecialChar ~
3199 \SpecialChar ~
3200 \SpecialChar ~
3201 \SpecialChar ~
3202 \SpecialChar ~
3203 \SpecialChar ~
3204 \SpecialChar ~
3205 \SpecialChar ~
3206
3207 \end_inset 
3208 </cell>
3209 </row>
3210 <row topline="true" bottomline="true">
3211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3212 \begin_inset Text
3213
3214 \layout Standard
3215
3216
3217 \emph on 
3218 $DATADIR/
3219 \newline 
3220 $LIB_DIR_SUFFIX/<model>
3221 \end_inset 
3222 </cell>
3223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3224 \begin_inset Text
3225
3226 \layout Standard
3227
3228 /usr/local/share/sdcc/
3229 \newline 
3230 lib/
3231 \emph on 
3232 <model>
3233 \end_inset 
3234 </cell>
3235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3236 \begin_inset Text
3237
3238 \layout Standard
3239
3240 (not on Win32)
3241 \end_inset 
3242 </cell>
3243 </row>
3244 </lyxtabular>
3245
3246 \end_inset 
3247
3248
3249 \newline 
3250
3251 \layout Comment
3252
3253 Don't delete any of the stray spaces in the table above without checking
3254  the HTML output (last line)!
3255 \layout Standard
3256
3257 \SpecialChar ~
3258
3259 \newline 
3260 The option -
3261 \begin_inset ERT
3262 status Collapsed
3263
3264 \layout Standard
3265
3266 \backslash 
3267 /
3268 \end_inset 
3269
3270 -nostdlib disables the last two search paths.
3271 \layout Section
3272
3273 Building SDCC
3274 \begin_inset LatexCommand \index{Building SDCC}
3275
3276 \end_inset 
3277
3278
3279 \layout Subsection
3280
3281 Building SDCC on Linux
3282 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3283
3284 \end_inset 
3285
3286
3287 \layout Enumerate
3288
3289
3290 \series medium 
3291 Download the source package
3292 \series default 
3293  either from the SDCC Subversion repository or from the nightly snapshots
3294 \series medium 
3295 , it will be named something like sdcc
3296 \series default 
3297 .src
3298 \series medium 
3299 .t
3300 \series default 
3301 ar.
3302 \series medium 
3303 gz
3304 \series default 
3305  
3306 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3307
3308 \end_inset 
3309
3310 .
3311 \layout Enumerate
3312
3313
3314 \series medium 
3315 Bring up a command line terminal, such as xterm.
3316 \layout Enumerate
3317
3318
3319 \series medium 
3320 Unpack the file using a command like: 
3321 \family sans 
3322 \series bold 
3323 "tar -xvzf sdcc.src.tar.gz
3324 \family default 
3325 \series default 
3326 "
3327 \series medium 
3328 , this will create a sub-directory called sdcc with all of the sources.
3329 \layout Enumerate
3330
3331 Change directory into the main SDCC directory, for example type: 
3332 \family sans 
3333 \series bold 
3334 "cd sdcc
3335 \series default 
3336 ".
3337 \layout Enumerate
3338
3339
3340 \series medium 
3341 Type 
3342 \family sans 
3343 \series bold 
3344 "./configure
3345 \family default 
3346 \series default 
3347 ".
3348  This configures the package for compilation on your system.
3349 \layout Enumerate
3350
3351
3352 \series medium 
3353 Type 
3354 \family sans 
3355 \series bold 
3356 "make
3357 \family default 
3358 \series default 
3359 "
3360 \series medium 
3361 .
3362
3363 \series default 
3364  All of the source packages will compile, this can take a while.
3365 \layout Enumerate
3366
3367
3368 \series medium 
3369 Type 
3370 \family sans 
3371 \series bold 
3372 "make install"
3373 \family default 
3374 \series default 
3375  as root
3376 \series medium 
3377 .
3378
3379 \series default 
3380  This copies the binary executables, the include files, the libraries and
3381  the documentation to the install directories.
3382  Proceed with section 
3383 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3384
3385 \end_inset 
3386
3387 .
3388 \layout Subsection
3389
3390 Building SDCC on OSX 2.x
3391 \layout Standard
3392
3393 Follow the instruction for Linux.
3394 \newline 
3395
3396 \newline 
3397 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3398 )) fails to compile SDCC.
3399  Fortunately there's also gcc 2.9.x installed, which works fine.
3400  This compiler can be selected by running 'configure' with:
3401 \layout LyX-Code
3402
3403 ./configure CC=gcc2 CXX=g++2
3404 \layout Subsection
3405
3406 Cross compiling SDCC on Linux for Windows
3407 \layout Standard
3408
3409 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3410  See section 'Configure Options'.
3411 \layout Subsection
3412
3413 Building SDCC on Windows 
3414 \layout Standard
3415
3416 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
3417  built on Windows.
3418  They use Unix-sockets, which are not available on Win32.
3419 \layout Subsection
3420
3421 Building SDCC using Cygwin and Mingw32
3422 \layout Standard
3423
3424 For building and installing a Cygwin executable follow the instructions
3425  for Linux.
3426 \newline 
3427
3428 \newline 
3429 On Cygwin a 
3430 \begin_inset Quotes sld
3431 \end_inset 
3432
3433 native
3434 \begin_inset Quotes srd
3435 \end_inset 
3436
3437  Win32-binary can be built, which will not need the Cygwin-DLL.
3438  For the necessary 'configure' options see section 'configure options' or
3439  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3440 \newline 
3441
3442 \newline 
3443 In order to install Cygwin on Windows download setup.exe from 
3444 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3445
3446 \end_inset 
3447
3448 .
3449  Run it, set the 
3450 \begin_inset Quotes sld
3451 \end_inset 
3452
3453 default text file type
3454 \begin_inset Quotes srd
3455 \end_inset 
3456
3457  to 
3458 \begin_inset Quotes sld
3459 \end_inset 
3460
3461 unix
3462 \begin_inset Quotes srd
3463 \end_inset 
3464
3465  and download/install at least the following packages.
3466  Some packages are selected by default, others will be automatically selected
3467  because of dependencies with the manually selected packages.
3468  Never deselect these packages!
3469 \layout Itemize
3470
3471 flex
3472 \layout Itemize
3473
3474 bison
3475 \layout Itemize
3476
3477 gcc ; version 3.x is fine, no need to use the old 2.9x
3478 \layout Itemize
3479
3480 binutils ; selected with gcc
3481 \layout Itemize
3482
3483 make
3484 \layout Itemize
3485
3486 rxvt ; a nice console, which makes life much easier under windoze (see below)
3487 \layout Itemize
3488
3489 man ; not really needed for building SDCC, but you'll miss it sooner or
3490  later
3491 \layout Itemize
3492
3493 less ; not really needed for building SDCC, but you'll miss it sooner or
3494  later
3495 \layout Itemize
3496
3497 svn ; only if you use Subversion access
3498 \layout Standard
3499
3500 If you want to develop something you'll need:
3501 \layout Itemize
3502
3503 python ; for the regression tests
3504 \layout Itemize
3505
3506 gdb ; the gnu debugger, together with the nice GUI 
3507 \begin_inset Quotes sld
3508 \end_inset 
3509
3510 insight
3511 \begin_inset Quotes srd
3512 \end_inset 
3513
3514
3515 \layout Itemize
3516
3517 openssh ; to access the CF or commit changes
3518 \layout Itemize
3519
3520 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3521  use autoconf-stable!
3522 \layout Standard
3523
3524 rxvt is a nice console with history.
3525  Replace in your cygwin.bat the line
3526 \layout LyX-Code
3527
3528 bash -
3529 \begin_inset ERT
3530 status Collapsed
3531
3532 \layout Standard
3533
3534 \backslash 
3535 /
3536 \end_inset 
3537
3538 -login -i 
3539 \layout Standard
3540
3541 with (one line):
3542 \layout LyX-Code
3543
3544 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3545 \layout LyX-Code
3546
3547      -bg black -fg white -geometry 100x65 -e bash -
3548 \begin_inset ERT
3549 status Collapsed
3550
3551 \layout Standard
3552
3553 \backslash 
3554 /
3555 \end_inset 
3556
3557 -login
3558 \layout Standard
3559
3560 Text selected with the mouse is automatically copied to the clipboard, pasting
3561  works with shift-insert.
3562 \newline 
3563
3564 \newline 
3565 The other good tip is to make sure you have no //c/-style paths anywhere,
3566  use /cygdrive/c/ instead.
3567  Using // invokes a network lookup which is very slow.
3568  If you think 
3569 \begin_inset Quotes sld
3570 \end_inset 
3571
3572 cygdrive
3573 \begin_inset Quotes srd
3574 \end_inset 
3575
3576  is too long, you can change it with e.g.
3577 \layout LyX-Code
3578
3579 mount -s -u -c /mnt
3580 \layout Standard
3581
3582 SDCC sources use the unix line ending LF.
3583  Life is much easier, if you store the source tree on a drive which is mounted
3584  in binary mode.
3585  And use an editor which can handle LF-only line endings.
3586  Make sure not to commit files with windows line endings.
3587  The tabulator spacing
3588 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3589
3590 \end_inset 
3591
3592  used in the project is 8.
3593  Although a tabulator spacing of 8 is a sensible choice for programmers
3594  (it's a power of 2 and allows to display 8/16 bit signed variables without
3595  loosing columns) the plan is to move towards using only spaces in the source.
3596 \layout Subsection
3597
3598 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3599 \layout Standard
3600
3601
3602 \series medium 
3603 Download the source package
3604 \series default 
3605  either from the SDCC Subversion repository or from the 
3606 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3607
3608 \end_inset 
3609
3610
3611 \series medium 
3612 , it will be named something like sdcc
3613 \series default 
3614 .src
3615 \series medium 
3616 .tgz.
3617
3618 \series default 
3619  SDCC is distributed with all the projects, workspaces, and files you need
3620  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3621  doesn't build under MSVC).
3622  The workspace name is 'sdcc.dsw'.
3623  Please note that as it is now, all the executables are created in a folder
3624  called sdcc
3625 \backslash 
3626 bin_vc.
3627  Once built you need to copy the executables from sdcc
3628 \backslash 
3629 bin_vc to sdcc
3630 \backslash 
3631 bin before running SDCC.
3632  
3633 \newline 
3634
3635 \newline 
3636 WARNING: Visual studio is very picky with line terminations; it expects
3637  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3638  When using the Subversion repository it's easiest to configure the svn
3639  client to convert automatically for you.
3640  If however you are getting a message such as "This makefile was not generated
3641  by Developer Studio etc.
3642  etc.
3643 \begin_inset Quotes srd
3644 \end_inset 
3645
3646  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3647  need to convert the Unix style line endings to DOS style line endings.
3648  To do so you can use the 
3649 \begin_inset Quotes sld
3650 \end_inset 
3651
3652 unix2dos
3653 \begin_inset Quotes srd
3654 \end_inset 
3655
3656  utility freely available on the internet.
3657  Doug Hawkins reported in the sdcc-user list that this works:
3658 \newline 
3659
3660 \newline 
3661 C:
3662 \backslash 
3663 Programming
3664 \backslash 
3665 SDCC> unix2dos sdcc.dsw
3666 \newline 
3667 C:
3668 \backslash 
3669 Programming
3670 \backslash 
3671 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3672 \newline 
3673
3674 \newline 
3675 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3676  flex.exe, and gawk.exe.
3677  One good place to get them is 
3678 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3679
3680 \end_inset 
3681
3682
3683 \newline 
3684
3685 \newline 
3686 Download the file UnxUtils
3687 \begin_inset LatexCommand \index{UnxUtils}
3688
3689 \end_inset 
3690
3691 .zip.
3692  Now you have to install the utilities and setup MSVC so it can locate the
3693  required programs.
3694  Here there are two alternatives (choose one!):
3695 \layout Enumerate
3696
3697 The easy way:
3698 \newline 
3699
3700 \newline 
3701 a) Extract UnxUtils.zip to your C:
3702 \backslash 
3703  hard disk PRESERVING the original paths, otherwise bison won't work.
3704  (If you are using WinZip make certain that 'Use folder names' is selected)
3705 \newline 
3706
3707 \newline 
3708 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3709  in 'Show directories for:' select 'Executable files', and in the directories
3710  window add a new path: 'C:
3711 \backslash 
3712 user
3713 \backslash 
3714 local
3715 \backslash 
3716 wbin', click ok.
3717 \newline 
3718
3719 \newline 
3720 (As a side effect, you get a bunch of Unix utilities that could be useful,
3721  such as diff and patch.)
3722 \layout Enumerate
3723
3724 A more compact way:
3725 \newline 
3726
3727 \newline 
3728 This one avoids extracting a bunch of files you may not use, but requires
3729  some extra work:
3730 \newline 
3731
3732 \newline 
3733 a) Create a directory were to put the tools needed, or use a directory already
3734  present.
3735  Say for example 'C:
3736 \backslash 
3737 util'.
3738 \newline 
3739
3740 \newline 
3741 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3742  to such directory WITHOUT preserving the original paths.
3743  (If you are using WinZip make certain that 'Use folder names' is not selected)
3744 \newline 
3745
3746 \newline 
3747 c) Rename bison.exe to '_bison.exe'.
3748 \newline 
3749
3750 \newline 
3751 d) Create a batch file 'bison.bat' in 'C:
3752 \backslash 
3753 util
3754 \backslash 
3755 ' and add these lines: 
3756 \newline 
3757 \SpecialChar ~
3758 \SpecialChar ~
3759 set BISON_SIMPLE=C:
3760 \backslash 
3761 util
3762 \backslash 
3763 bison.simple 
3764 \newline 
3765 \SpecialChar ~
3766 \SpecialChar ~
3767 set BISON_HAIRY=C:
3768 \backslash 
3769 util
3770 \backslash 
3771 bison.hairy
3772 \newline 
3773 \SpecialChar ~
3774 \SpecialChar ~
3775 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3776 \newline 
3777
3778 \newline 
3779 Steps 'c' and 'd' are needed because bison requires by default that the
3780  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3781  '/usr/local/share/' I think.
3782  So it is necessary to tell bison where those files are located if they
3783  are not in such directory.
3784  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3785 \newline 
3786
3787 \newline 
3788 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3789  in 'Show directories for:' select 'Executable files', and in the directories
3790  window add a new path: 'c:
3791 \backslash 
3792 util', click ok.
3793  Note that you can use any other path instead of 'c:
3794 \backslash 
3795 util', even the path where the Visual C++ tools are, probably: 'C:
3796 \backslash 
3797 Program Files
3798 \backslash 
3799 Microsoft Visual Studio
3800 \backslash 
3801 Common
3802 \backslash 
3803 Tools'.
3804  So you don't have to execute step 'e' :)
3805 \layout Standard
3806
3807 That is it.
3808  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3809  the executables from sdcc
3810 \backslash 
3811 bin_vc to sdcc
3812 \backslash 
3813 bin, and you can compile using SDCC.
3814 \layout Subsection
3815
3816 Building SDCC Using Borland
3817 \layout Enumerate
3818
3819 From the sdcc directory, run the command "make -f Makefile.bcc".
3820  This should regenerate all the .exe files in the bin directory except for
3821  sdcdb.exe (which currently doesn't build under Borland C++).
3822 \layout Enumerate
3823
3824 If you modify any source files and need to rebuild, be aware that the dependenci
3825 es may not be correctly calculated.
3826  The safest option is to delete all .obj files and run the build again.
3827  From a Cygwin BASH prompt, this can easily be done with the command (be
3828  sure you are in the sdcc directory):
3829 \newline 
3830
3831 \newline 
3832
3833 \family sans 
3834 \series bold 
3835 find .
3836  
3837 \backslash 
3838 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3839 \backslash 
3840 ) -print -exec rm {} 
3841 \backslash 
3842 ;
3843 \family default 
3844 \series default 
3845
3846 \newline 
3847
3848 \newline 
3849 or on Windows NT/2000/XP from the command prompt with the command:
3850 \newline 
3851
3852 \family sans 
3853 \series bold 
3854
3855 \newline 
3856 del /s *.obj *.lib *.rul
3857 \family default 
3858 \series default 
3859  from the sdcc directory.
3860 \layout Subsection
3861
3862 Windows Install Using a ZIP Package
3863 \layout Enumerate
3864
3865 Download the binary zip package from 
3866 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3867
3868 \end_inset 
3869
3870  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3871  This should unpack to a group of sub-directories.
3872  An example directory structure after unpacking the mingw32 package is:
3873  c:
3874 \backslash 
3875 sdcc
3876 \backslash 
3877 bin for the executables, c:
3878 \backslash 
3879 sdcc
3880 \backslash 
3881 include and c:
3882 \backslash 
3883 sdcc
3884 \backslash 
3885 lib for the include and libraries.
3886 \layout Enumerate
3887
3888 Adjust your environment variable PATH to include the location of the bin
3889  directory or start sdcc using the full path.
3890 \layout Subsection
3891
3892 Windows Install Using the Setup Program
3893 \begin_inset LatexCommand \label{sub:Windows-Install}
3894
3895 \end_inset 
3896
3897
3898 \layout Standard
3899
3900 Download the setup program 
3901 \emph on 
3902 sdcc-x.y.z-setup.exe
3903 \emph default 
3904  for an official release from 
3905 \newline 
3906
3907 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3908
3909 \end_inset 
3910
3911  or a setup program for one of the snapshots 
3912 \emph on 
3913 sdcc-yyyymmdd-xxxx-setup.exe
3914 \emph default 
3915  from 
3916 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3917
3918 \end_inset 
3919
3920  and execute it.
3921  A windows typical installer will guide you through the installation process.
3922 \layout Subsection
3923
3924 VPATH
3925 \begin_inset LatexCommand \index{VPATH}
3926
3927 \end_inset 
3928
3929  feature
3930 \layout Standard
3931
3932 SDCC supports the VPATH feature provided by configure and make.
3933  It allows to separate the source and build trees.
3934  Here's an example:
3935 \layout Standard
3936
3937
3938 \family typewriter 
3939 cd ~\SpecialChar ~
3940 \SpecialChar ~
3941 \SpecialChar ~
3942 \SpecialChar ~
3943 \SpecialChar ~
3944 \SpecialChar ~
3945 \SpecialChar ~
3946 \SpecialChar ~
3947 \SpecialChar ~
3948 \SpecialChar ~
3949 \SpecialChar ~
3950 \SpecialChar ~
3951 \SpecialChar ~
3952 \SpecialChar ~
3953 \SpecialChar ~
3954 \SpecialChar ~
3955 \SpecialChar ~
3956 \SpecialChar ~
3957 \SpecialChar ~
3958 \SpecialChar ~
3959 \SpecialChar ~
3960 # cd $HOME
3961 \layout Standard
3962
3963
3964 \family typewriter 
3965 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3966 # extract source to directory sdcc
3967 \layout Standard
3968
3969
3970 \family typewriter 
3971 mkdir sdcc.build\SpecialChar ~
3972 \SpecialChar ~
3973 \SpecialChar ~
3974 \SpecialChar ~
3975 \SpecialChar ~
3976 \SpecialChar ~
3977 \SpecialChar ~
3978 \SpecialChar ~
3979 \SpecialChar ~
3980 # put output in sdcc.build
3981 \layout Standard
3982
3983
3984 \family typewriter 
3985 cd sdcc.build
3986 \layout Standard
3987
3988
3989 \family typewriter 
3990 ../sdcc/configure\SpecialChar ~
3991 \SpecialChar ~
3992 \SpecialChar ~
3993 \SpecialChar ~
3994 \SpecialChar ~
3995 \SpecialChar ~
3996 \SpecialChar ~
3997 \SpecialChar ~
3998 # configure is doing all the magic!
3999 \layout Standard
4000
4001
4002 \family typewriter 
4003 make
4004 \layout Standard
4005 \noindent 
4006 That's it! 
4007 \series bold 
4008 configure
4009 \series default 
4010  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4011  It automagically computes the variables srcdir, top_srcdir and top_buildir
4012  for each directory.
4013  After running 
4014 \series bold 
4015 make
4016 \series default 
4017  the generated files will be in ~/sdcc.build, while the source files stay
4018  in ~/sdcc.
4019 \newline 
4020 This is not only usefull for building different binaries, e.g.
4021  when cross compiling.
4022  It also gives you a much better overview in the source tree when all the
4023  generated files are not scattered between the source files.
4024  And the best thing is: if you want to change a file you can leave the original
4025  file untouched in the source directory.
4026  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4027  Makefile.dep` and `make`.
4028  
4029 \series bold 
4030 make
4031 \series default 
4032  will do the rest for you!
4033 \layout Section
4034
4035 Building the Documentation
4036 \layout Standard
4037
4038 Add -
4039 \begin_inset ERT
4040 status Collapsed
4041
4042 \layout Standard
4043
4044 \backslash 
4045 /
4046 \end_inset 
4047
4048 -enable-doc to the configure arguments to build the documentation together
4049  with all the other stuff.
4050  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4051  dvips and makeindex) to get the job done.
4052  Another possibility is to change to the doc directory and to type 
4053 \family sans 
4054 \series bold 
4055
4056 \begin_inset Quotes srd
4057 \end_inset 
4058
4059 make
4060 \begin_inset Quotes srd
4061 \end_inset 
4062
4063
4064 \family default 
4065 \series default 
4066  there.
4067  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4068 x).
4069  Using LyX 
4070 \begin_inset LatexCommand \url{http://www.lyx.org}
4071
4072 \end_inset 
4073
4074  as editor is straightforward.
4075  Prebuilt documentation in html and pdf format is available from 
4076 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4077
4078 \end_inset 
4079
4080 .
4081 \layout Section
4082
4083 Reading the Documentation
4084 \layout Standard
4085
4086 Currently reading the document in pdf format is recommended, as for unknown
4087  reason the hyperlinks are working there whereas in the html version they
4088  are not
4089 \begin_inset Foot
4090 collapsed false
4091
4092 \layout Standard
4093
4094 If you should know why please drop us a note
4095 \end_inset 
4096
4097 .
4098  
4099 \newline 
4100 You'll find the pdf version
4101 \begin_inset LatexCommand \index{PDF version of this document}
4102
4103 \end_inset 
4104
4105  at 
4106 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4107
4108 \end_inset 
4109
4110 .
4111  
4112 \newline 
4113 A html version
4114 \begin_inset LatexCommand \index{HTML version of this document}
4115
4116 \end_inset 
4117
4118  should be online at 
4119 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4120
4121 \end_inset 
4122
4123 .
4124 \newline 
4125 This documentation is in some aspects different from a commercial documentation:
4126  
4127 \layout Itemize
4128
4129 It tries to document SDCC for several processor architectures in one document
4130  (commercially these probably would be separate documents/products).
4131  This document
4132 \begin_inset LatexCommand \index{Status of documentation}
4133
4134 \end_inset 
4135
4136  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4137 on about f.e.
4138  Z80, PIC14, PIC16 and HC08.
4139 \layout Itemize
4140
4141 There are many references pointing away from this documentation.
4142  Don't let this distract you.
4143  If there f.e.
4144  was a reference like 
4145 \begin_inset LatexCommand \url{http://www.opencores.org}
4146
4147 \end_inset 
4148
4149  together with a statement 
4150 \begin_inset Quotes sld
4151 \end_inset 
4152
4153 some processors which are targetted by SDCC can be implemented in a 
4154 \emph on 
4155 f
4156 \emph default 
4157 ield 
4158 \emph on 
4159 p
4160 \emph default 
4161 rogrammable 
4162 \emph on 
4163 g
4164 \emph default 
4165 ate 
4166 \emph on 
4167 a
4168 \emph default 
4169 rray
4170 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4171
4172 \end_inset 
4173
4174
4175 \begin_inset Quotes srd
4176 \end_inset 
4177
4178  or 
4179 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4180
4181 \end_inset 
4182
4183
4184 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4185
4186 \end_inset 
4187
4188  
4189 \begin_inset Quotes sld
4190 \end_inset 
4191
4192 have you ever heard of an open source compiler that compiles a subset of
4193  C for an FPGA?
4194 \begin_inset Quotes srd
4195 \end_inset 
4196
4197  we expect you to have a quick look there and come back.
4198  If you read this you are on the right track.
4199 \layout Itemize
4200
4201 Some sections attribute more space to problems, restrictions and warnings
4202  than to the solution.
4203 \layout Itemize
4204
4205 The installation section and the section about the debugger is intimidating.
4206 \layout Itemize
4207
4208 There are still lots of typos and there are more different writing styles
4209  than pictures.
4210 \layout Section
4211
4212 Testing the SDCC Compiler
4213 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4214
4215 \end_inset 
4216
4217
4218 \layout Standard
4219
4220 The first thing you should do after installing your SDCC compiler is to
4221  see if it runs.
4222  Type 
4223 \family sans 
4224 \series bold 
4225 "sdcc -
4226 \begin_inset ERT
4227 status Collapsed
4228
4229 \layout Standard
4230
4231 \backslash 
4232 /
4233 \end_inset 
4234
4235 -version"
4236 \begin_inset LatexCommand \index{version}
4237
4238 \end_inset 
4239
4240
4241 \family default 
4242 \series default 
4243  at the prompt, and the program should run and output its version like:
4244  
4245 \newline 
4246
4247 \family typewriter 
4248 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4249  (UNIX)
4250 \layout Standard
4251
4252 If it doesn't run, or gives a message about not finding sdcc program, then
4253  you need to check over your installation.
4254  Make sure that the sdcc bin directory is in your executable search path
4255  defined by the PATH environment setting (
4256 \series medium 
4257 see 
4258 \series default 
4259 section 
4260 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4261
4262 \end_inset 
4263
4264 \SpecialChar ~
4265
4266 \series medium 
4267 Install trouble-shooting for suggestions
4268 \series default 
4269 ).
4270  Make sure that the sdcc program is in the bin folder, if not perhaps something
4271  did not install correctly.
4272 \newline 
4273
4274 \newline 
4275
4276 \series medium 
4277 SDCC 
4278 \series default 
4279 is commonly installed as described in section 
4280 \begin_inset Quotes sld
4281 \end_inset 
4282
4283 Install and search paths
4284 \begin_inset Quotes srd
4285 \end_inset 
4286
4287 .
4288 \newline 
4289
4290 \newline 
4291
4292 \series medium 
4293 Make sure the compiler works on a very simple example.
4294  Type in the following test.c program using your favorite 
4295 \series default 
4296 ASCII 
4297 \series medium 
4298 editor:
4299 \layout Verse
4300
4301
4302 \family typewriter 
4303 char test;
4304 \newline 
4305
4306 \newline 
4307 void main(void) {
4308 \newline 
4309 \SpecialChar ~
4310 \SpecialChar ~
4311 \SpecialChar ~
4312 \SpecialChar ~
4313 test=0;
4314 \newline 
4315 }
4316 \layout Standard
4317
4318
4319 \series medium 
4320 Compile this using the following command: 
4321 \family sans 
4322 \series bold 
4323 "sdcc -c test.c".
4324
4325 \family default 
4326 \series default 
4327  
4328 \series medium 
4329 If all goes well, the compiler will generate a test.asm and test.rel file.
4330  Congratulations, you've just compiled your first program with SDCC.
4331  We used the -c option to tell SDCC not to link the generated code, just
4332  to keep things simple for this step.
4333 \series default 
4334
4335 \newline 
4336
4337 \newline 
4338
4339 \series medium 
4340 The next step is to try it with the linker.
4341  Type in 
4342 \family sans 
4343 \series bold 
4344 "sdcc test.c
4345 \family default 
4346 \series default 
4347 "
4348 \series medium 
4349 .
4350  If all goes well the compiler will link with the libraries and produce
4351  a test.ihx output file.
4352  If this step fails
4353 \series default 
4354  
4355 \series medium 
4356 (no test.ihx, and the linker generates warnings), then the problem is most
4357  likely that 
4358 \series default 
4359 SDCC
4360 \series medium 
4361  cannot find the 
4362 \series default 
4363 /
4364 \series medium 
4365 usr/local/share/sdcc/lib directory
4366 \series default 
4367  
4368 \series medium 
4369 (see 
4370 \series default 
4371 section 
4372 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4373
4374 \end_inset 
4375
4376 \SpecialChar ~
4377
4378 \series medium 
4379 Install trouble-shooting for suggestions).
4380 \series default 
4381
4382 \newline 
4383
4384 \newline 
4385
4386 \series medium 
4387 The final test is to ensure 
4388 \series default 
4389 SDCC
4390 \series medium 
4391  can use the 
4392 \series default 
4393 standard
4394 \series medium 
4395  header files and libraries.
4396  Edit test.c and change it to the following:
4397 \layout Verse
4398
4399
4400 \family typewriter 
4401 #include <string.h>
4402 \newline 
4403
4404 \newline 
4405 char str1[10];
4406 \newline 
4407
4408 \newline 
4409 void main(void) {
4410 \newline 
4411 \SpecialChar ~
4412 \SpecialChar ~
4413 strcpy(str1, "testing");
4414 \newline 
4415 }
4416 \layout Standard
4417
4418
4419 \series medium 
4420 Compile this by typing 
4421 \family sans 
4422 \series bold 
4423 "sdcc test.c"
4424 \family default 
4425 \series medium 
4426 .
4427  This should generate a test.ihx output file, and it should give no warnings
4428  such as not finding the string.h file.
4429  If it cannot find the string.h file, then the problem is that 
4430 \series default 
4431 SDCC
4432 \series medium 
4433  cannot find the /usr/local/share/sdcc/include directory
4434 \series default 
4435  
4436 \series medium 
4437 (see the 
4438 \series default 
4439 section 
4440 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4441
4442 \end_inset 
4443
4444 \SpecialChar ~
4445
4446 \series medium 
4447 Install trouble-shooting section for suggestions).
4448
4449 \series default 
4450  Use option 
4451 \series bold 
4452 -
4453 \begin_inset ERT
4454 status Collapsed
4455
4456 \layout Standard
4457
4458 \backslash 
4459 /
4460 \end_inset 
4461
4462 -print-search-dirs
4463 \series default 
4464
4465 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4466
4467 \end_inset 
4468
4469  to find exactly where SDCC is looking for the include and lib files.
4470 \layout Section
4471
4472 Install Trouble-shooting
4473 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4474
4475 \end_inset 
4476
4477
4478 \begin_inset LatexCommand \index{Install trouble-shooting}
4479
4480 \end_inset 
4481
4482
4483 \layout Subsection
4484
4485 If SDCC does not build correctly
4486 \layout Standard
4487
4488 A thing to try is starting from scratch by unpacking the .tgz source package
4489  again in an empty directory.
4490  Configure it like:
4491 \newline 
4492
4493 \newline 
4494
4495 \family sans 
4496 \series bold 
4497 ./configure 2>&1 | tee configure.log
4498 \family default 
4499 \series default 
4500
4501 \newline 
4502
4503 \newline 
4504 and build it like:
4505 \newline 
4506
4507 \newline 
4508
4509 \family sans 
4510 \series bold 
4511 make 2>&1 | tee make.log
4512 \family default 
4513 \series default 
4514
4515 \newline 
4516
4517 \newline 
4518 If anything goes wrong, you can review the log files to locate the problem.
4519  Or a relevant part of this can be attached to an email that could be helpful
4520  when requesting help from the mailing list.
4521 \layout Subsection
4522
4523 What the 
4524 \begin_inset Quotes sld
4525 \end_inset 
4526
4527 ./configure
4528 \begin_inset Quotes srd
4529 \end_inset 
4530
4531  does
4532 \layout Standard
4533
4534 The 
4535 \begin_inset Quotes sld
4536 \end_inset 
4537
4538 ./configure
4539 \begin_inset Quotes srd
4540 \end_inset 
4541
4542  command is a script that analyzes your system and performs some configuration
4543  to ensure the source package compiles on your system.
4544  It will take a few minutes to run, and will compile a few tests to determine
4545  what compiler features are installed.
4546 \layout Subsection
4547
4548 What the 
4549 \begin_inset Quotes sld
4550 \end_inset 
4551
4552 make
4553 \begin_inset Quotes srd
4554 \end_inset 
4555
4556  does
4557 \layout Standard
4558
4559 This runs the GNU make tool, which automatically compiles all the source
4560  packages into the final installed binary executables.
4561 \layout Subsection
4562
4563 What the 
4564 \begin_inset Quotes sld
4565 \end_inset 
4566
4567 make install
4568 \begin_inset Quotes erd
4569 \end_inset 
4570
4571  command does.
4572 \layout Standard
4573
4574 This will install the compiler, other executables libraries and include
4575  files into the appropriate directories.
4576  See sections 
4577 \begin_inset LatexCommand \ref{sub:Install-paths}
4578
4579 \end_inset 
4580
4581 ,\SpecialChar ~
4582
4583 \begin_inset LatexCommand \ref{sub:Search-Paths}
4584
4585 \end_inset 
4586
4587 \SpecialChar ~
4588 about install and search paths.
4589 \newline 
4590 On most systems you will need super-user privileges to do this.
4591 \layout Section
4592
4593 Components of SDCC
4594 \layout Standard
4595
4596 SDCC is not just a compiler, but a collection of tools by various developers.
4597  These include linkers, assemblers, simulators and other components.
4598  Here is a summary of some of the components.
4599  Note that the included simulator and assembler have separate documentation
4600  which you can find in the source package in their respective directories.
4601  As SDCC grows to include support for other processors, other packages from
4602  various developers are included and may have their own sets of documentation.
4603 \newline 
4604
4605 \newline 
4606 You might want to look at the files which are installed in <installdir>.
4607  At the time of this writing, we find the following programs for gcc-builds:
4608 \newline 
4609  
4610 \newline 
4611 In <installdir>/bin:
4612 \layout Itemize
4613
4614 sdcc - The compiler.
4615 \layout Itemize
4616
4617 sdcpp - The C preprocessor.
4618 \layout Itemize
4619
4620 asx8051 - The assembler for 8051 type processors.
4621 \layout Itemize
4622
4623 as-z80
4624 \series bold 
4625
4626 \series default 
4627 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4628 \layout Itemize
4629
4630 aslink -The linker for 8051 type processors.
4631 \layout Itemize
4632
4633 link-z80
4634 \series bold 
4635
4636 \series default 
4637 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4638 \layout Itemize
4639
4640 s51 - The ucSim 8051 simulator.
4641  Not available on Win32 platforms.
4642 \layout Itemize
4643
4644 sdcdb - The source debugger.
4645  Not available on Win32 platforms.
4646 \layout Itemize
4647
4648 packihx - A tool to pack (compress) Intel hex files.
4649 \layout Standard
4650
4651 In <installdir>/share/sdcc/include
4652 \layout Itemize
4653
4654 the include files
4655 \layout Standard
4656
4657 In <installdir>/share/sdcc/lib
4658 \layout Itemize
4659
4660 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4661  relocatables.
4662 \layout Standard
4663
4664 In <installdir>/share/sdcc/doc
4665 \layout Itemize
4666
4667 the documentation
4668 \layout Standard
4669
4670 As development for other processors proceeds, this list will expand to include
4671  executables to support processors like AVR, PIC, etc.
4672 \layout Subsection
4673
4674 sdcc - The Compiler
4675 \layout Standard
4676
4677 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4678  the assembler and linkage editor.
4679 \layout Subsection
4680
4681 sdcpp - The C-Preprocessor
4682 \layout Standard
4683
4684 The preprocessor
4685 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4686
4687 \end_inset 
4688
4689  is a modified version of the GNU preprocessor.
4690  The C preprocessor is used to pull in #include sources, process #ifdef
4691  statements, #defines and so on.
4692 \layout Subsection
4693
4694 as
4695 \emph on 
4696 xxxx
4697 \emph default 
4698 , aslink, link-
4699 \emph on 
4700 xxx
4701 \emph default 
4702  - The Assemblers and Linkage Editors
4703 \layout Standard
4704
4705 This is retargettable assembler & linkage editor, it was developed by Alan
4706  Baldwin.
4707  John Hartman created the version for 8051, and I (Sandeep) have made some
4708  enhancements and bug fixes for it to work properly with SDCC.
4709 \layout Subsection
4710
4711 s51 - The Simulator
4712 \layout Standard
4713
4714 S51
4715 \begin_inset LatexCommand \index{s51}
4716
4717 \end_inset 
4718
4719  is a freeware, opensource simulator developed by Daniel Drotos.
4720  The simulator is built as part of the build process.
4721  For more information visit Daniel's web site at: 
4722 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4723
4724 \end_inset 
4725
4726 .
4727  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4728  XA51 family.
4729  S51 is currently not available on Win32 platfors.
4730 \layout Subsection
4731
4732 sdcdb - Source Level Debugger
4733 \layout Standard
4734
4735 Sdcdb
4736 \begin_inset LatexCommand \index{sdcdb (debugger)}
4737
4738 \end_inset 
4739
4740  is the companion source level debugger.
4741  More about sdcdb in section 
4742 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4743
4744 \end_inset 
4745
4746 .
4747  The current version of the debugger uses Daniel's Simulator S51
4748 \begin_inset LatexCommand \index{s51}
4749
4750 \end_inset 
4751
4752 , but can be easily changed to use other simulators.
4753  Sdcdb is currently not available on Win32 platfors.
4754 \layout Chapter
4755
4756 Using SDCC
4757 \layout Section
4758
4759 Compiling
4760 \layout Subsection
4761
4762 Single Source File Projects
4763 \layout Standard
4764
4765 For single source file 8051 projects the process is very simple.
4766  Compile your programs with the following command 
4767 \family sans 
4768 \series bold 
4769 "sdcc sourcefile.c".
4770
4771 \family default 
4772 \series default 
4773  This will compile, assemble and link your source file.
4774  Output files are as follows:
4775 \layout Itemize
4776
4777 sourcefile.asm
4778 \begin_inset LatexCommand \index{<file>.asm}
4779
4780 \end_inset 
4781
4782  - Assembler source
4783 \begin_inset LatexCommand \index{Assembler source}
4784
4785 \end_inset 
4786
4787  file created by the compiler
4788 \layout Itemize
4789
4790 sourcefile.lst
4791 \begin_inset LatexCommand \index{<file>.lst}
4792
4793 \end_inset 
4794
4795  - Assembler listing
4796 \begin_inset LatexCommand \index{Assembler listing}
4797
4798 \end_inset 
4799
4800  file created by the Assembler
4801 \layout Itemize
4802
4803 sourcefile.rst
4804 \begin_inset LatexCommand \index{<file>.rst}
4805
4806 \end_inset 
4807
4808  - Assembler listing
4809 \begin_inset LatexCommand \index{Assembler listing}
4810
4811 \end_inset 
4812
4813  file updated with linkedit information, created by linkage editor
4814 \layout Itemize
4815
4816 sourcefile.sym
4817 \begin_inset LatexCommand \index{<file>.sym}
4818
4819 \end_inset 
4820
4821  - symbol listing
4822 \begin_inset LatexCommand \index{Symbol listing}
4823
4824 \end_inset 
4825
4826  for the sourcefile, created by the assembler
4827 \layout Itemize
4828
4829 sourcefile.rel
4830 \begin_inset LatexCommand \index{<file>.rel}
4831
4832 \end_inset 
4833
4834  or sourcefile.o
4835 \begin_inset LatexCommand \index{<file>.o}
4836
4837 \end_inset 
4838
4839  - Object file
4840 \begin_inset LatexCommand \index{Object file}
4841
4842 \end_inset 
4843
4844  created by the assembler, input to Linkage editor
4845 \layout Itemize
4846
4847 sourcefile.map
4848 \begin_inset LatexCommand \index{<file>.map}
4849
4850 \end_inset 
4851
4852  - The memory map
4853 \begin_inset LatexCommand \index{Memory map}
4854
4855 \end_inset 
4856
4857  for the load module, created by the Linker
4858 \layout Itemize
4859
4860 sourcefile.mem
4861 \begin_inset LatexCommand \index{<file>.mem}
4862
4863 \end_inset 
4864
4865  - A file with a summary of the memory usage
4866 \layout Itemize
4867
4868 sourcefile.ihx
4869 \begin_inset LatexCommand \index{<file>.ihx}
4870
4871 \end_inset 
4872
4873  - The load module in Intel hex format
4874 \begin_inset LatexCommand \index{Intel hex format}
4875
4876 \end_inset 
4877
4878  (you can select the Motorola S19 format
4879 \begin_inset LatexCommand \index{Motorola S19 format}
4880
4881 \end_inset 
4882
4883  with -
4884 \begin_inset ERT
4885 status Collapsed
4886
4887 \layout Standard
4888
4889 \backslash 
4890 /
4891 \end_inset 
4892
4893 -out-fmt-s19
4894 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4895
4896 \end_inset 
4897
4898 .
4899  If you need another format you might want to use 
4900 \family sans 
4901 \shape italic 
4902 objdump
4903 \family default 
4904 \shape default 
4905
4906 \begin_inset LatexCommand \index{objdump (tool)}
4907
4908 \end_inset 
4909
4910  or
4911 \family sans 
4912 \shape italic 
4913  srecord
4914 \family default 
4915 \shape default 
4916
4917 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4918
4919 \end_inset 
4920
4921 ).
4922  Both formats are documented in the documentation of srecord
4923 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4924
4925 \end_inset 
4926
4927
4928 \layout Itemize
4929
4930 sourcefile.adb
4931 \begin_inset LatexCommand \index{<file>.adb}
4932
4933 \end_inset 
4934
4935  - An intermediate file containing debug information needed to create the
4936  .cdb file (with -
4937 \begin_inset ERT
4938 status Open
4939
4940 \layout Standard
4941
4942 \backslash 
4943 /
4944 \end_inset 
4945
4946 -debug
4947 \begin_inset LatexCommand \index{-\/-debug}
4948
4949 \end_inset 
4950
4951
4952 \layout Itemize
4953
4954 sourcefile.cdb
4955 \begin_inset LatexCommand \index{<file>.cdb}
4956
4957 \end_inset 
4958
4959  - An optional file (with -
4960 \begin_inset ERT
4961 status Collapsed
4962
4963 \layout Standard
4964
4965 \backslash 
4966 /
4967 \end_inset 
4968
4969 -debug) containing debug information.
4970  The format is documented in cdbfileformat.pdf
4971 \layout Itemize
4972
4973 sourcefile.
4974  - (no extension)
4975 \begin_inset LatexCommand \index{<file> (no extension)}
4976
4977 \end_inset 
4978
4979  An optional AOMF or AOMF51
4980 \begin_inset LatexCommand \index{AOMF, AOMF51}
4981
4982 \end_inset 
4983
4984  
4985 \begin_inset LatexCommand \label{OMF file}
4986
4987 \end_inset 
4988
4989 file containing debug information (generated with option -
4990 \begin_inset ERT
4991 status Collapsed
4992
4993 \layout Standard
4994
4995 \backslash 
4996 /
4997 \end_inset 
4998
4999 -debug).
5000  The (Intel)
5001 \emph on 
5002  a
5003 \emph default 
5004 bsolute 
5005 \emph on 
5006 o
5007 \emph default 
5008 bject 
5009 \emph on 
5010 m
5011 \emph default 
5012 odule 
5013 \emph on 
5014 f
5015 \emph default 
5016 ormat is commonly used by third party tools (debuggers
5017 \begin_inset LatexCommand \index{Debugger}
5018
5019 \end_inset 
5020
5021 , simulators, emulators)
5022 \layout Itemize
5023
5024 sourcefile.dump*
5025 \begin_inset LatexCommand \index{<file>.dump*}
5026
5027 \end_inset 
5028
5029  - Dump file to debug the compiler it self (generated with option -
5030 \begin_inset ERT
5031 status Collapsed
5032
5033 \layout Standard
5034
5035 \backslash 
5036 /
5037 \end_inset 
5038
5039 -dumpall) (see section 
5040 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5041
5042 \end_inset 
5043
5044 \SpecialChar ~
5045  and section 
5046 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5047
5048 \end_inset 
5049
5050 \SpecialChar ~
5051
5052 \begin_inset Quotes sld
5053 \end_inset 
5054
5055 Anatomy of the compiler
5056 \begin_inset Quotes srd
5057 \end_inset 
5058
5059 ).
5060 \layout Subsection
5061
5062 Projects with Multiple Source Files
5063 \layout Standard
5064
5065 SDCC can compile only ONE file at a time.
5066  Let us for example assume that you have a project containing the following
5067  files:
5068 \newline 
5069
5070 \newline 
5071 foo1.c (contains some functions)
5072 \newline 
5073 foo2.c (contains some more functions)
5074 \newline 
5075 foomain.c (contains more functions and the function main)
5076 \newline 
5077
5078 \size footnotesize 
5079
5080 \newline 
5081
5082 \size default 
5083 The first two files will need to be compiled separately with the commands:
5084 \size footnotesize 
5085  
5086 \size default 
5087
5088 \newline 
5089
5090 \newline 
5091
5092 \family sans 
5093 \series bold 
5094 sdcc\SpecialChar ~
5095 -c\SpecialChar ~
5096 foo1.c
5097 \family default 
5098 \series default 
5099 \size footnotesize 
5100
5101 \newline 
5102
5103 \family sans 
5104 \series bold 
5105 \size default 
5106 sdcc\SpecialChar ~
5107 -c\SpecialChar ~
5108 foo2.c
5109 \family default 
5110 \series default 
5111
5112 \newline 
5113
5114 \newline 
5115 Then compile the source file containing the 
5116 \emph on 
5117 main()
5118 \emph default 
5119  function and link
5120 \begin_inset LatexCommand \index{Linker}
5121
5122 \end_inset 
5123
5124  the files together with the following command: 
5125 \newline 
5126
5127 \newline 
5128
5129 \family sans 
5130 \series bold 
5131 sdcc\SpecialChar ~
5132 foomain.c\SpecialChar ~
5133 foo1.rel\SpecialChar ~
5134 foo2.rel
5135 \family default 
5136 \series default 
5137
5138 \begin_inset LatexCommand \index{<file>.rel}
5139
5140 \end_inset 
5141
5142
5143 \newline 
5144
5145 \newline 
5146 Alternatively, 
5147 \emph on 
5148 foomain.c 
5149 \emph default 
5150 can be separately compiled as well: 
5151 \family sans 
5152 \series bold 
5153
5154 \newline 
5155
5156 \newline 
5157 sdcc\SpecialChar ~
5158 -c\SpecialChar ~
5159 foomain.c
5160 \newline 
5161 sdcc foomain.rel foo1.rel foo2.rel
5162 \newline 
5163
5164 \newline 
5165
5166 \family default 
5167 \series default 
5168 The file containing the 
5169 \emph on 
5170 main()
5171 \emph default 
5172  function
5173 \emph on 
5174  
5175 \emph default 
5176 \noun on 
5177 must
5178 \noun default 
5179  be the 
5180 \noun on 
5181 first
5182 \noun default 
5183  file specified in the command line, since the linkage editor processes
5184  file in the order they are presented to it.
5185  The linker is invoked from SDCC using a script file with extension .lnk
5186 \begin_inset LatexCommand \index{<file>.lnk}
5187
5188 \end_inset 
5189
5190 .
5191  You can view this file to troubleshoot linking problems such as those arising
5192  from missing libraries.
5193 \layout Subsection
5194
5195 Projects with Additional Libraries
5196 \begin_inset LatexCommand \index{Libraries}
5197
5198 \end_inset 
5199
5200
5201 \layout Standard
5202
5203 Some reusable routines may be compiled into a library, see the documentation
5204  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5205  for how to create a 
5206 \emph on 
5207 .lib
5208 \begin_inset LatexCommand \index{<file>.lib}
5209
5210 \end_inset 
5211
5212
5213 \emph default 
5214  library file.
5215  Libraries created in this manner can be included in the command line.
5216  Make sure you include the -L <library-path> option to tell the linker where
5217  to look for these files if they are not in the current directory.
5218  Here is an example, assuming you have the source file 
5219 \emph on 
5220 foomain.c
5221 \emph default 
5222  and a library
5223 \emph on 
5224  foolib.lib
5225 \emph default 
5226  in the directory 
5227 \emph on 
5228 mylib
5229 \emph default 
5230  (if that is not the same as your current project):
5231 \newline 
5232
5233 \newline 
5234
5235 \family sans 
5236 \series bold 
5237 sdcc foomain.c foolib.lib -L mylib
5238 \newline 
5239
5240 \newline 
5241
5242 \family default 
5243 \series default 
5244 Note here that
5245 \emph on 
5246  mylib
5247 \emph default 
5248  must be an absolute path name.
5249 \newline 
5250
5251 \newline 
5252 The most efficient way to use libraries is to keep separate modules in separate
5253  source files.
5254  The lib file now should name all the modules.rel
5255 \begin_inset LatexCommand \index{<file>.rel}
5256
5257 \end_inset 
5258
5259  files.
5260  For an example see the standard library file 
5261 \emph on 
5262 libsdcc.lib
5263 \emph default 
5264  in the directory <installdir>/share/lib/small.
5265 \layout Subsection
5266
5267 Using sdcclib to Create and Manage Libraries
5268 \begin_inset LatexCommand \index{sdcclib}
5269
5270 \end_inset 
5271
5272
5273 \layout Standard
5274
5275 Alternatively, instead of having a .rel file for each entry on the library
5276  file as described in the preceding section, sdcclib can be used to embed
5277  all the modules belonging to such library in the library file itself.
5278  This results in a larger library file, but it greatly reduces the number
5279  of disk files accessed by the linker.
5280   Additionally, the packed library file contains an index of all include
5281  modules and symbols that significantly speeds up the linking process.
5282  To display a list of options supported by sdcclib type:
5283 \newline 
5284
5285 \layout Standard
5286
5287
5288 \family sans 
5289 \series bold 
5290 sdcclib -?
5291 \begin_inset LatexCommand \index{sdcclib}
5292
5293 \end_inset 
5294
5295
5296 \newline 
5297
5298 \newline 
5299
5300 \family default 
5301 \series default 
5302 To create a new library file, start by compiling all the required modules.
5303  For example:
5304 \newline 
5305
5306 \layout Standard
5307
5308
5309 \family sans 
5310 \series bold 
5311 sdcc -c _divsint.c
5312 \layout Standard
5313
5314
5315 \family sans 
5316 \series bold 
5317 sdcc -c _divuint.c
5318 \layout Standard
5319
5320
5321 \family sans 
5322 \series bold 
5323 sdcc -c _modsint.c
5324 \layout Standard
5325
5326
5327 \family sans 
5328 \series bold 
5329 sdcc -c _moduint.c
5330 \layout Standard
5331
5332
5333 \family sans 
5334 \series bold 
5335 sdcc -c _mulint.c
5336 \newline 
5337
5338 \layout Standard
5339
5340 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5341  and _mulint.rel.
5342  The next step is to add the .rel files to the library file:
5343 \newline 
5344
5345 \layout Standard
5346
5347
5348 \family sans 
5349 \series bold 
5350 sdcclib libint.lib _divsint.rel
5351 \family default 
5352
5353 \begin_inset LatexCommand \index{sdcclib}
5354
5355 \end_inset 
5356
5357
5358 \layout Standard
5359
5360
5361 \family sans 
5362 \series bold 
5363 sdcclib libint.lib _divuint.rel
5364 \layout Standard
5365
5366
5367 \family sans 
5368 \series bold 
5369 sdcclib libint.lib _modsint.rel
5370 \layout Standard
5371
5372
5373 \family sans 
5374 \series bold 
5375 sdcclib libint.lib _moduint.rel
5376 \layout Standard
5377
5378
5379 \family sans 
5380 \series bold 
5381 sdcclib libint.lib _mulint.rel
5382 \series default 
5383
5384 \newline 
5385
5386 \layout Standard
5387
5388 If the file already exists in the library, it will be replaced.
5389  To see what modules and symbols are included in the library, options -s
5390  and -m are available.
5391  For example:
5392 \newline 
5393
5394 \newline 
5395
5396 \family sans 
5397 \series bold 
5398 sdcclib -s libint.lib
5399 \family default 
5400
5401 \begin_inset LatexCommand \index{sdcclib}
5402
5403 \end_inset 
5404
5405
5406 \newline 
5407
5408 \family typewriter 
5409 \series default 
5410 _divsint.rel:
5411 \layout Standard
5412
5413
5414 \family typewriter 
5415 __divsint_a_1_1
5416 \layout Standard
5417
5418
5419 \family typewriter 
5420 __divsint_PARM_2
5421 \layout Standard
5422
5423
5424 \family typewriter 
5425 __divsint
5426 \newline 
5427 _divuint.rel:
5428 \layout Standard
5429
5430
5431 \family typewriter 
5432 __divuint_a_1_1
5433 \layout Standard
5434
5435
5436 \family typewriter 
5437 __divuint_PARM_2
5438 \layout Standard
5439
5440
5441 \family typewriter 
5442 __divuint_reste_1_1
5443 \layout Standard
5444
5445
5446 \family typewriter 
5447 __divuint_count_1_1
5448 \layout Standard
5449
5450
5451 \family typewriter 
5452 __divuint
5453 \newline 
5454 _modsint.rel:
5455 \layout Standard
5456
5457
5458 \family typewriter 
5459 __modsint_a_1_1
5460 \layout Standard
5461
5462
5463 \family typewriter 
5464 __modsint_PARM_2
5465 \layout Standard
5466
5467
5468 \family typewriter 
5469 __modsint
5470 \newline 
5471 _moduint.rel:
5472 \layout Standard
5473
5474
5475 \family typewriter 
5476 __moduint_a_1_1
5477 \layout Standard
5478
5479
5480 \family typewriter 
5481 __moduint_PARM_2
5482 \layout Standard
5483
5484
5485 \family typewriter 
5486 __moduint_count_1_1
5487 \layout Standard
5488
5489
5490 \family typewriter 
5491 __moduint
5492 \newline 
5493 _mulint.rel:
5494 \layout Standard
5495
5496
5497 \family typewriter 
5498 __mulint_PARM_2
5499 \layout Standard
5500
5501
5502 \family typewriter 
5503 __mulint
5504 \family default 
5505 \series bold 
5506
5507 \newline 
5508
5509 \layout Standard
5510
5511 If the source files are compiled using -
5512 \begin_inset ERT
5513 status Open
5514
5515 \layout Standard
5516
5517 \backslash 
5518 /
5519 \end_inset 
5520
5521 -debug
5522 \begin_inset LatexCommand \index{-\/-debug}
5523
5524 \end_inset 
5525
5526 , the corresponding debug information file .adb will be include in the library
5527  file as well.
5528  The library files created with sdcclib are plain text files, so they can
5529  be viewed with a text editor.
5530  It is not recomended to modify a library file created with sdcclib using
5531  a text editor, as there are file indexes numbers located accross the file
5532  used by the linker to quickly locate the required module to link.
5533  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5534  it can be safely deleted, since all the information required for linking
5535  is embedded in the library file itself.
5536  Library files created using sdcclib are used as described in the preceding
5537  sections.
5538 \layout Section
5539
5540 Command Line Options
5541 \begin_inset LatexCommand \index{Command Line Options}
5542
5543 \end_inset 
5544
5545
5546 \layout Subsection
5547
5548 Processor Selection Options
5549 \begin_inset LatexCommand \index{Options processor selection}
5550
5551 \end_inset 
5552
5553
5554 \begin_inset LatexCommand \index{Processor selection options}
5555
5556 \end_inset 
5557
5558
5559 \layout List
5560 \labelwidthstring 00.00.0000
5561
5562
5563 \series bold 
5564 -mmcs51
5565 \begin_inset LatexCommand \index{-mmcs51}
5566
5567 \end_inset 
5568
5569
5570 \series default 
5571  Generate code for the Intel MCS51
5572 \begin_inset LatexCommand \index{MCS51}
5573
5574 \end_inset 
5575
5576  family of processors.
5577  This is the default processor target.
5578 \layout List
5579 \labelwidthstring 00.00.0000
5580
5581
5582 \series bold 
5583 -mds390
5584 \begin_inset LatexCommand \index{-mds390}
5585
5586 \end_inset 
5587
5588
5589 \series default 
5590  Generate code for the Dallas DS80C390
5591 \begin_inset LatexCommand \index{DS80C390}
5592
5593 \end_inset 
5594
5595  processor.
5596 \layout List
5597 \labelwidthstring 00.00.0000
5598
5599
5600 \series bold 
5601 -mds400
5602 \begin_inset LatexCommand \index{-mds400}
5603
5604 \end_inset 
5605
5606
5607 \series default 
5608  Generate code for the Dallas DS80C400
5609 \begin_inset LatexCommand \index{DS80C400}
5610
5611 \end_inset 
5612
5613  processor.
5614 \layout List
5615 \labelwidthstring 00.00.0000
5616
5617
5618 \series bold 
5619 -mhc08
5620 \begin_inset LatexCommand \index{-mhc08}
5621
5622 \end_inset 
5623
5624
5625 \series default 
5626  Generate code for the Freescale/Motorola HC08
5627 \begin_inset LatexCommand \index{HC08}
5628
5629 \end_inset 
5630
5631  family of processors.
5632 \layout List
5633 \labelwidthstring 00.00.0000
5634
5635
5636 \series bold 
5637 -mz80
5638 \begin_inset LatexCommand \index{-mz80}
5639
5640 \end_inset 
5641
5642
5643 \series default 
5644  Generate code for the Zilog Z80
5645 \begin_inset LatexCommand \index{Z80}
5646
5647 \end_inset 
5648
5649  family of processors.
5650 \layout List
5651 \labelwidthstring 00.00.0000
5652
5653
5654 \series bold 
5655 -mgbz80
5656 \begin_inset LatexCommand \index{-mgbz80}
5657
5658 \end_inset 
5659
5660
5661 \series default 
5662  Generate code for the GameBoy Z80
5663 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5664
5665 \end_inset 
5666
5667  processor (Not actively maintained).
5668 \layout List
5669 \labelwidthstring 00.00.0000
5670
5671
5672 \series bold 
5673 -mavr
5674 \begin_inset LatexCommand \index{-mavr}
5675
5676 \end_inset 
5677
5678
5679 \series default 
5680  Generate code for the Atmel AVR
5681 \begin_inset LatexCommand \index{AVR}
5682
5683 \end_inset 
5684
5685  processor (In development, not complete).
5686  AVR users should probably have a look at winavr 
5687 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5688
5689 \end_inset 
5690
5691  or 
5692 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5693
5694 \end_inset 
5695
5696 .
5697 \layout Comment
5698
5699 I think it is fair to direct users there for now.
5700  Open source is also about avoiding unnecessary work .
5701  But I didn't find the 'official' link.
5702 \layout List
5703 \labelwidthstring 00.00.0000
5704
5705
5706 \series bold 
5707 -mpic14
5708 \begin_inset LatexCommand \index{-mpic14}
5709
5710 \end_inset 
5711
5712
5713 \series default 
5714  Generate code for the Microchip PIC 14
5715 \begin_inset LatexCommand \index{PIC14}
5716
5717 \end_inset 
5718
5719 -bit processors (p16f84 and variants.
5720  In development, not complete).
5721 \layout Comment
5722
5723 p16f627 p16f628 p16f84 p16f873 p16f877?
5724 \layout List
5725 \labelwidthstring 00.00.0000
5726
5727
5728 \series bold 
5729 -mpic16
5730 \begin_inset LatexCommand \index{-mpic16}
5731
5732 \end_inset 
5733
5734
5735 \series default 
5736  Generate code for the Microchip PIC 16
5737 \begin_inset LatexCommand \index{PIC16}
5738
5739 \end_inset 
5740
5741 -bit processors (p18f452 and variants.
5742  In development, not complete).
5743 \layout List
5744 \labelwidthstring 00.00.0000
5745
5746
5747 \series bold 
5748 -mtlcs900h
5749 \series default 
5750  Generate code for the Toshiba TLCS-900H
5751 \begin_inset LatexCommand \index{TLCS-900H}
5752
5753 \end_inset 
5754
5755  processor (Not maintained, not complete).
5756 \layout List
5757 \labelwidthstring 00.00.0000
5758
5759
5760 \series bold 
5761 -mxa51
5762 \begin_inset LatexCommand \index{-mxa51}
5763
5764 \end_inset 
5765
5766
5767 \series default 
5768  Generate code for the Phillips XA51
5769 \begin_inset LatexCommand \index{XA51}
5770
5771 \end_inset 
5772
5773  processor (Not maintained, not complete).
5774 \layout Subsection
5775
5776 Preprocessor Options
5777 \begin_inset LatexCommand \index{Options preprocessor}
5778
5779 \end_inset 
5780
5781
5782 \begin_inset LatexCommand \index{Preprocessor options}
5783
5784 \end_inset 
5785
5786
5787 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5788
5789 \end_inset 
5790
5791
5792 \layout List
5793 \labelwidthstring 00.00.0000
5794
5795
5796 \series bold 
5797 -I<path>
5798 \begin_inset LatexCommand \index{-I<path>}
5799
5800 \end_inset 
5801
5802
5803 \series default 
5804  The additional location where the pre processor will look for <..h> or 
5805 \begin_inset Quotes eld
5806 \end_inset 
5807
5808 ..h
5809 \begin_inset Quotes erd
5810 \end_inset 
5811
5812  files.
5813 \layout List
5814 \labelwidthstring 00.00.0000
5815
5816
5817 \series bold 
5818 -D<macro[=value]>
5819 \begin_inset LatexCommand \index{-D<macro[=value]>}
5820
5821 \end_inset 
5822
5823
5824 \series default 
5825  Command line definition of macros.
5826  Passed to the preprocessor.
5827 \layout List
5828 \labelwidthstring 00.00.0000
5829
5830
5831 \series bold 
5832 -M
5833 \begin_inset LatexCommand \index{-M}
5834
5835 \end_inset 
5836
5837
5838 \series default 
5839  Tell the preprocessor to output a rule suitable for make describing the
5840  dependencies of each object file.
5841  For each source file, the preprocessor outputs one make-rule whose target
5842  is the object file name for that source file and whose dependencies are
5843  all the files `#include'd in it.
5844  This rule may be a single line or may be continued with `
5845 \backslash 
5846 '-newline if it is long.
5847  The list of rules is printed on standard output instead of the preprocessed
5848  C program.
5849  `-M' implies `-E
5850 \begin_inset LatexCommand \index{-E}
5851
5852 \end_inset 
5853
5854 '.
5855 \layout List
5856 \labelwidthstring 00.00.0000
5857
5858
5859 \series bold 
5860 -C
5861 \begin_inset LatexCommand \index{-C}
5862
5863 \end_inset 
5864
5865
5866 \series default 
5867  Tell the preprocessor not to discard comments.
5868  Used with the `-E' option.
5869 \layout List
5870 \labelwidthstring 00.00.0000
5871
5872
5873 \series bold 
5874 -MM
5875 \begin_inset LatexCommand \index{-MM}
5876
5877 \end_inset 
5878
5879
5880 \size large 
5881 \bar under 
5882  
5883 \series default 
5884 \size default 
5885 \bar default 
5886 Like `-M' but the output mentions only the user header files included with
5887  `#include 
5888 \begin_inset Quotes eld
5889 \end_inset 
5890
5891 file"'.
5892  System header files included with `#include <file>' are omitted.
5893 \layout List
5894 \labelwidthstring 00.00.0000
5895
5896
5897 \series bold 
5898 -Aquestion(answer)
5899 \begin_inset LatexCommand \index{-Aquestion(answer)}
5900
5901 \end_inset 
5902
5903
5904 \series default 
5905  Assert the answer answer for question, in case it is tested with a preprocessor
5906  conditional such as `#if #question(answer)'.
5907  `-A-' disables the standard assertions that normally describe the target
5908  machine.
5909 \layout List
5910 \labelwidthstring 00.00.0000
5911
5912
5913 \series bold 
5914 -Umacro
5915 \begin_inset LatexCommand \index{-Umacro}
5916
5917 \end_inset 
5918
5919
5920 \series default 
5921  Undefine macro macro.
5922  `-U' options are evaluated after all `-D' options, but before any `-include'
5923  and `-imacros' options.
5924 \layout List
5925 \labelwidthstring 00.00.0000
5926
5927
5928 \series bold 
5929 -dM
5930 \begin_inset LatexCommand \index{-dM}
5931
5932 \end_inset 
5933
5934
5935 \series default 
5936  Tell the preprocessor to output only a list of the macro definitions that
5937  are in effect at the end of preprocessing.
5938  Used with the `-E' option.
5939 \layout List
5940 \labelwidthstring 00.00.0000
5941
5942
5943 \series bold 
5944 -dD
5945 \begin_inset LatexCommand \index{-dD}
5946
5947 \end_inset 
5948
5949
5950 \series default 
5951  Tell the preprocessor to pass all macro definitions into the output, in
5952  their proper sequence in the rest of the output.
5953 \layout List
5954 \labelwidthstring 00.00.0000
5955
5956
5957 \series bold 
5958 -dN
5959 \begin_inset LatexCommand \index{-dN}
5960
5961 \end_inset 
5962
5963
5964 \size large 
5965 \bar under 
5966  
5967 \series default 
5968 \size default 
5969 \bar default 
5970 Like `-dD' except that the macro arguments and contents are omitted.
5971  Only `#define name' is included in the output.
5972 \layout List
5973 \labelwidthstring 00.00.0000
5974
5975
5976 \series bold 
5977 -Wp\SpecialChar ~
5978 preprocessorOption[,preprocessorOption]
5979 \series default 
5980
5981 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5982
5983 \end_inset 
5984
5985 ...
5986  Pass the preprocessorOption to the preprocessor 
5987 \family typewriter 
5988 sdcpp
5989 \family default 
5990
5991 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5992
5993 \end_inset 
5994
5995 .
5996  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5997  Collection (gcc), if you need more dedicated options please refer to the
5998  documentation at 
5999 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6000
6001 \end_inset 
6002
6003 .
6004 \layout Subsection
6005
6006 Linker Options
6007 \begin_inset LatexCommand \index{Options linker}
6008
6009 \end_inset 
6010
6011
6012 \begin_inset LatexCommand \index{Linker options}
6013
6014 \end_inset 
6015
6016
6017 \layout List
6018 \labelwidthstring 00.00.0000
6019
6020
6021 \series bold 
6022 -L\SpecialChar ~
6023 -
6024 \series default 
6025
6026 \begin_inset ERT
6027 status Collapsed
6028
6029 \layout Standard
6030
6031 \backslash 
6032 /
6033 \end_inset 
6034
6035
6036 \series bold 
6037 -lib-path
6038 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6039
6040 \end_inset 
6041
6042
6043 \begin_inset LatexCommand \index{-L -\/-lib-path}
6044
6045 \end_inset 
6046
6047
6048 \series default 
6049 \SpecialChar ~
6050 <absolute path to additional libraries> This option is passed to the linkage
6051  editor's additional libraries
6052 \begin_inset LatexCommand \index{Libraries}
6053
6054 \end_inset 
6055
6056  search path.
6057  The path name must be absolute.
6058  Additional library files may be specified in the command line.
6059  See section Compiling programs for more details.
6060 \layout List
6061 \labelwidthstring 00.00.0000
6062
6063
6064 \series bold 
6065 -
6066 \begin_inset ERT
6067 status Collapsed
6068
6069 \layout Standard
6070
6071 \backslash 
6072 /
6073 \end_inset 
6074
6075 -xram-loc
6076 \series default 
6077
6078 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6079
6080 \end_inset 
6081
6082 \SpecialChar ~
6083 <Value> The start location of the external ram
6084 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6085
6086 \end_inset 
6087
6088 , default value is 0.
6089  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6090 \begin_inset ERT
6091 status Collapsed
6092
6093 \layout Standard
6094
6095 \backslash 
6096 /
6097 \end_inset 
6098
6099 -xram-loc 0x8000 or -
6100 \begin_inset ERT
6101 status Collapsed
6102
6103 \layout Standard
6104
6105 \backslash 
6106 /
6107 \end_inset 
6108
6109 -xram-loc 32768.
6110 \layout List
6111 \labelwidthstring 00.00.0000
6112
6113
6114 \series bold 
6115 -
6116 \begin_inset ERT
6117 status Collapsed
6118
6119 \layout Standard
6120
6121 \backslash 
6122 /
6123 \end_inset 
6124
6125 -code-loc
6126 \series default 
6127
6128 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6129
6130 \end_inset 
6131
6132 \SpecialChar ~
6133 <Value> The start location of the code
6134 \begin_inset LatexCommand \index{code}
6135
6136 \end_inset 
6137
6138  segment, default value 0.
6139  Note when this option is used the interrupt vector table is also relocated
6140  to the given address.
6141  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6142 \begin_inset ERT
6143 status Collapsed
6144
6145 \layout Standard
6146
6147 \backslash 
6148 /
6149 \end_inset 
6150
6151 -code-loc 0x8000 or -
6152 \begin_inset ERT
6153 status Collapsed
6154
6155 \layout Standard
6156
6157 \backslash 
6158 /
6159 \end_inset 
6160
6161 -code-loc 32768.
6162 \layout List
6163 \labelwidthstring 00.00.0000
6164
6165
6166 \series bold 
6167 -
6168 \begin_inset ERT
6169 status Collapsed
6170
6171 \layout Standard
6172
6173 \backslash 
6174 /
6175 \end_inset 
6176
6177 -stack-loc
6178 \series default 
6179
6180 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6181
6182 \end_inset 
6183
6184 \SpecialChar ~
6185 <Value> By default the stack
6186 \begin_inset LatexCommand \index{stack}
6187
6188 \end_inset 
6189
6190  is placed after the data segment.
6191  Using this option the stack can be placed anywhere in the internal memory
6192  space of the 8051.
6193  The value entered can be in Hexadecimal or Decimal format, e.g.
6194  -
6195 \begin_inset ERT
6196 status Collapsed
6197
6198 \layout Standard
6199
6200 \backslash 
6201 /
6202 \end_inset 
6203
6204 -stack-loc 0x20 or -
6205 \begin_inset ERT
6206 status Collapsed
6207
6208 \layout Standard
6209
6210 \backslash 
6211 /
6212 \end_inset 
6213
6214 -stack-loc 32.
6215  Since the sp register is incremented before a push or call, the initial
6216  sp will be set to one byte prior the provided value.
6217  The provided value should not overlap any other memory areas such as used
6218  register banks or the data segment and with enough space for the current
6219  application.
6220  The 
6221 \series bold 
6222 -
6223 \begin_inset ERT
6224 status Collapsed
6225
6226 \layout Standard
6227
6228 \backslash 
6229 /
6230 \end_inset 
6231
6232 -pack-iram
6233 \series default 
6234 \SpecialChar ~
6235
6236 \begin_inset LatexCommand \index{-\/-pack-iram}
6237
6238 \end_inset 
6239
6240  option (which is now a default setting) will override this setting, so
6241  you should also specify the 
6242 \series bold 
6243 -
6244 \begin_inset ERT
6245 status Collapsed
6246
6247 \layout Standard
6248
6249 \backslash 
6250 /
6251 \end_inset 
6252
6253 -no-pack-iram
6254 \series default 
6255 \SpecialChar ~
6256
6257 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6258
6259 \end_inset 
6260
6261  option if you need to manually place the stack.
6262 \layout List
6263 \labelwidthstring 00.00.0000
6264
6265
6266 \series bold 
6267 -
6268 \begin_inset ERT
6269 status Collapsed
6270
6271 \layout Standard
6272
6273 \backslash 
6274 /
6275 \end_inset 
6276
6277 -xstack-loc
6278 \series default 
6279
6280 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6281
6282 \end_inset 
6283
6284 \SpecialChar ~
6285 <Value> By default the external stack
6286 \begin_inset LatexCommand \index{xstack}
6287
6288 \end_inset 
6289
6290  is placed after the pdata segment.
6291  Using this option the xstack can be placed anywhere in the external memory
6292  space of the 8051.
6293  The value entered can be in Hexadecimal or Decimal format, e.g.
6294  -
6295 \begin_inset ERT
6296 status Collapsed
6297
6298 \layout Standard
6299
6300 \backslash 
6301 /
6302 \end_inset 
6303
6304 -xstack-loc 0x8000 or -
6305 \begin_inset ERT
6306 status Collapsed
6307
6308 \layout Standard
6309
6310 \backslash 
6311 /
6312 \end_inset 
6313
6314 -stack-loc 32768.
6315  The provided value should not overlap any other memory areas such as the
6316  pdata or xdata segment and with enough space for the current application.
6317 \layout List
6318 \labelwidthstring 00.00.0000
6319
6320
6321 \series bold 
6322 -
6323 \begin_inset ERT
6324 status Collapsed
6325
6326 \layout Standard
6327
6328 \backslash 
6329 /
6330 \end_inset 
6331
6332 -data-loc
6333 \series default 
6334
6335 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6336
6337 \end_inset 
6338
6339 \SpecialChar ~
6340 <Value> The start location of the internal ram data
6341 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6342
6343 \end_inset 
6344
6345  segment.
6346  The value entered can be in Hexadecimal or Decimal format, eg.
6347  -
6348 \begin_inset ERT
6349 status Collapsed
6350
6351 \layout Standard
6352
6353 \backslash 
6354 /
6355 \end_inset 
6356
6357 -data-loc 0x20 or -
6358 \begin_inset ERT
6359 status Collapsed
6360
6361 \layout Standard
6362
6363 \backslash 
6364 /
6365 \end_inset 
6366
6367 -data-loc 32.
6368  (By default, the start location of the internal ram data segment  is set
6369  as low as possible in memory, taking into account the used register banks
6370  and the bit segment at address 0x20.
6371  For example if register banks 0 and 1 are used without bit variables, the
6372  data segment will be set, if -
6373 \begin_inset ERT
6374 status Collapsed
6375
6376 \layout Standard
6377
6378 \backslash 
6379 /
6380 \end_inset 
6381
6382 -data-loc is not used, to location 0x10.)
6383 \layout List
6384 \labelwidthstring 00.00.0000
6385
6386
6387 \series bold 
6388 -
6389 \begin_inset ERT
6390 status Collapsed
6391
6392 \layout Standard
6393
6394 \backslash 
6395 /
6396 \end_inset 
6397
6398 -idata-loc
6399 \series default 
6400
6401 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6402
6403 \end_inset 
6404
6405 \SpecialChar ~
6406 <Value> The start location of the indirectly addressable internal ram
6407 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6408
6409 \end_inset 
6410
6411  of the 8051, default value is 0x80.
6412  The value entered can be in Hexadecimal or Decimal format, eg.
6413  -
6414 \begin_inset ERT
6415 status Collapsed
6416
6417 \layout Standard
6418
6419 \backslash 
6420 /
6421 \end_inset 
6422
6423 -idata-loc 0x88 or -
6424 \begin_inset ERT
6425 status Collapsed
6426
6427 \layout Standard
6428
6429 \backslash 
6430 /
6431 \end_inset 
6432
6433 -idata-loc 136.
6434 \layout List
6435 \labelwidthstring 00.00.0000
6436
6437
6438 \series bold 
6439 -
6440 \begin_inset ERT
6441 status Collapsed
6442
6443 \layout Standard
6444
6445 \backslash 
6446 /
6447 \end_inset 
6448
6449 -bit-loc
6450 \series default 
6451 \SpecialChar ~
6452 <Value> The start location of the bit
6453 \begin_inset LatexCommand \index{bit}
6454
6455 \end_inset 
6456
6457  addressable internal ram of the 8051.
6458  This is 
6459 \emph on 
6460 not
6461 \emph default 
6462  implemented yet.
6463  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6464 -bBSEG=<Value>.
6465 \layout List
6466 \labelwidthstring 00.00.0000
6467
6468
6469 \series bold 
6470 -
6471 \begin_inset ERT
6472 status Collapsed
6473
6474 \layout Standard
6475
6476 \backslash 
6477 /
6478 \end_inset 
6479
6480 -out-fmt-ihx
6481 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6482
6483 \end_inset 
6484
6485
6486 \bar under 
6487  
6488 \series default 
6489 \bar default 
6490 The linker output (final object code) is in Intel Hex format.
6491 \begin_inset LatexCommand \index{Intel hex format}
6492
6493 \end_inset 
6494
6495  This is the default option.
6496  The format itself is documented in the documentation of srecord
6497 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6498
6499 \end_inset 
6500
6501 .
6502 \layout List
6503 \labelwidthstring 00.00.0000
6504
6505
6506 \series bold 
6507 -
6508 \begin_inset ERT
6509 status Collapsed
6510
6511 \layout Standard
6512
6513 \backslash 
6514 /
6515 \end_inset 
6516
6517 -out-fmt-s19
6518 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6519
6520 \end_inset 
6521
6522
6523 \bar under 
6524  
6525 \series default 
6526 \bar default 
6527 The linker output (final object code) is in Motorola S19 format
6528 \begin_inset LatexCommand \index{Motorola S19 format}
6529
6530 \end_inset 
6531
6532 .
6533  The format itself is documented in the documentation of srecord.
6534 \layout List
6535 \labelwidthstring 00.00.0000
6536
6537
6538 \series bold 
6539 -
6540 \begin_inset ERT
6541 status Collapsed
6542
6543 \layout Standard
6544
6545 \backslash 
6546 /
6547 \end_inset 
6548
6549 -out-fmt-elf
6550 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6551
6552 \end_inset 
6553
6554
6555 \bar under 
6556  
6557 \series default 
6558 \bar default 
6559 The linker output (final object code) is in ELF format
6560 \begin_inset LatexCommand \index{ELF format}
6561
6562 \end_inset 
6563
6564 .
6565  (Currently only supported for the HC08 processors)
6566 \layout List
6567 \labelwidthstring 00.00.0000
6568
6569
6570 \series bold 
6571 -Wl\SpecialChar ~
6572 linkOption[,linkOption]
6573 \series default 
6574
6575 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6576
6577 \end_inset 
6578
6579 ...
6580  Pass the linkOption to the linker.
6581  See file sdcc/as/doc/asxhtm.html for more on linker options.
6582 \layout Subsection
6583
6584 MCS51 Options
6585 \begin_inset LatexCommand \index{Options MCS51}
6586
6587 \end_inset 
6588
6589
6590 \begin_inset LatexCommand \index{MCS51 options}
6591
6592 \end_inset 
6593
6594
6595 \layout List
6596 \labelwidthstring 00.00.0000
6597
6598
6599 \series bold 
6600 -
6601 \begin_inset ERT
6602 status Collapsed
6603
6604 \layout Standard
6605
6606 \backslash 
6607 /
6608 \end_inset 
6609
6610 -model-small
6611 \begin_inset LatexCommand \index{-\/-model-small}
6612
6613 \end_inset 
6614
6615
6616 \series default 
6617 \size large 
6618 \emph on 
6619  
6620 \size default 
6621 \emph default 
6622 Generate code for Small Model programs, see section Memory Models for more
6623  details.
6624  This is the default model.
6625 \layout List
6626 \labelwidthstring 00.00.0000
6627
6628
6629 \series bold 
6630 -
6631 \begin_inset ERT
6632 status Collapsed
6633
6634 \layout Standard
6635
6636 \backslash 
6637 /
6638 \end_inset 
6639
6640 -model-medium
6641 \begin_inset LatexCommand \index{-\/-model-medium}
6642
6643 \end_inset 
6644
6645
6646 \series default 
6647  Generate code for Medium model programs, see section Memory Models for
6648  more details.
6649  If this option is used all source files in the project have to be compiled
6650  with this option.
6651  It must also be used when invoking the linker.
6652 \layout List
6653 \labelwidthstring 00.00.0000
6654
6655
6656 \series bold 
6657 -
6658 \begin_inset ERT
6659 status Collapsed
6660
6661 \layout Standard
6662
6663 \backslash 
6664 /
6665 \end_inset 
6666
6667 -model-large
6668 \begin_inset LatexCommand \index{-\/-model-large}
6669
6670 \end_inset 
6671
6672
6673 \series default 
6674  Generate code for Large model programs, see section Memory Models for more
6675  details.
6676  If this option is used all source files in the project have to be compiled
6677  with this option.
6678  It must also be used when invoking the linker.
6679 \layout List
6680 \labelwidthstring 00.00.0000
6681
6682
6683 \series bold 
6684 -
6685 \begin_inset ERT
6686 status Collapsed
6687
6688 \layout Standard
6689
6690 \backslash 
6691 /
6692 \end_inset 
6693
6694 -xstack
6695 \begin_inset LatexCommand \index{-\/-xstack}
6696
6697 \end_inset 
6698
6699
6700 \series default 
6701  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
6702  variables and passing parameters.
6703  See section 
6704 \begin_inset LatexCommand \ref{sub:External-Stack}
6705
6706 \end_inset 
6707
6708 \SpecialChar ~
6709  External Stack for more details.
6710 \layout List
6711 \labelwidthstring 00.00.0000
6712
6713
6714 \series bold 
6715 -
6716 \begin_inset ERT
6717 status Collapsed
6718
6719 \layout Standard
6720
6721 \backslash 
6722 /
6723 \end_inset 
6724
6725 -iram-size
6726 \series default 
6727 \SpecialChar ~
6728 <Value>
6729 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6730
6731 \end_inset 
6732
6733  Causes the linker to check if the internal ram usage is within limits of
6734  the given value.
6735 \layout List
6736 \labelwidthstring 00.00.0000
6737
6738
6739 \series bold 
6740 -
6741 \begin_inset ERT
6742 status Collapsed
6743
6744 \layout Standard
6745
6746 \backslash 
6747 /
6748 \end_inset 
6749
6750 -xram-size
6751 \series default 
6752 \SpecialChar ~
6753 <Value>
6754 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6755
6756 \end_inset 
6757
6758  Causes the linker to check if the external ram usage is within limits of
6759  the given value.
6760 \layout List
6761 \labelwidthstring 00.00.0000
6762
6763
6764 \series bold 
6765 -
6766 \begin_inset ERT
6767 status Collapsed
6768
6769 \layout Standard
6770
6771 \backslash 
6772 /
6773 \end_inset 
6774
6775 -code-size
6776 \series default 
6777 \SpecialChar ~
6778 <Value>
6779 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6780
6781 \end_inset 
6782
6783  Causes the linker to check if the code memory usage is within limits of
6784  the given value.
6785 \layout List
6786 \labelwidthstring 00.00.0000
6787
6788
6789 \series bold 
6790 -
6791 \begin_inset ERT
6792 status Collapsed
6793
6794 \layout Standard
6795
6796 \backslash 
6797 /
6798 \end_inset 
6799
6800 -stack-size
6801 \series default 
6802 \SpecialChar ~
6803 <Value>
6804 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6805
6806 \end_inset 
6807
6808  Causes the linker to check if there is at minimum <Value> bytes for stack.
6809 \layout List
6810 \labelwidthstring 00.00.0000
6811
6812
6813 \series bold 
6814 -
6815 \begin_inset ERT
6816 status Collapsed
6817
6818 \layout Standard
6819
6820 \backslash 
6821 /
6822 \end_inset 
6823
6824 -pack-iram
6825 \series default 
6826 \SpecialChar ~
6827
6828 \begin_inset LatexCommand \index{-\/-pack-iram}
6829
6830 \end_inset 
6831
6832  Causes the linker to use unused register banks for data variables and pack
6833  data, idata and stack together.
6834  This is the default now.
6835 \layout List
6836 \labelwidthstring 00.00.0000
6837
6838
6839 \series bold 
6840 -
6841 \begin_inset ERT
6842 status Collapsed
6843
6844 \layout Standard
6845
6846 \backslash 
6847 /
6848 \end_inset 
6849
6850 -no-pack-iram
6851 \series default 
6852 \SpecialChar ~
6853
6854 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6855
6856 \end_inset 
6857
6858  Causes the linker to use old style for allocating memory areas.
6859 \layout Subsection
6860
6861 DS390 / DS400 Options
6862 \begin_inset LatexCommand \index{Options DS390}
6863
6864 \end_inset 
6865
6866
6867 \begin_inset LatexCommand \index{DS390 options}
6868
6869 \end_inset 
6870
6871
6872 \layout List
6873 \labelwidthstring 00.00.0000
6874
6875
6876 \series bold 
6877 -
6878 \begin_inset ERT
6879 status Collapsed
6880
6881 \layout Standard
6882
6883 \backslash 
6884 /
6885 \end_inset 
6886
6887 -model-flat24
6888 \series default 
6889
6890 \begin_inset LatexCommand \index{-\/-model-flat24}
6891
6892 \end_inset 
6893
6894
6895 \size large 
6896 \emph on 
6897  
6898 \size default 
6899 \emph default 
6900 Generate 24-bit flat mode code.
6901  This is the one and only that the ds390 code generator supports right now
6902  and is default when using 
6903 \emph on 
6904 -mds390
6905 \emph default 
6906 .
6907  See section Memory Models for more details.
6908 \layout List
6909 \labelwidthstring 00.00.0000
6910
6911
6912 \series bold 
6913 -
6914 \begin_inset ERT
6915 status Collapsed
6916
6917 \layout Standard
6918
6919 \backslash 
6920 /
6921 \end_inset 
6922
6923 -protect-sp-update
6924 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6925
6926 \end_inset 
6927
6928
6929 \series default 
6930  disable interrupts during ESP:SP updates.
6931 \layout List
6932 \labelwidthstring 00.00.0000
6933
6934
6935 \series bold 
6936 -
6937 \begin_inset ERT
6938 status Collapsed
6939
6940 \layout Standard
6941
6942 \backslash 
6943 /
6944 \end_inset 
6945
6946 -stack-10bit
6947 \series default 
6948
6949 \begin_inset LatexCommand \index{-\/-stack-10bit}
6950
6951 \end_inset 
6952
6953  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6954  This is the one and only that the ds390 code generator supports right now
6955  and is default when using 
6956 \emph on 
6957 -mds390
6958 \emph default 
6959 .
6960  In this mode, the stack is located in the lower 1K of the internal RAM,
6961  which is mapped to 0x400000.
6962  Note that the support is incomplete, since it still uses a single byte
6963  as the stack pointer.
6964  This means that only the lower 256 bytes of the potential 1K stack space
6965  will actually be used.
6966  However, this does allow you to reclaim the precious 256 bytes of low RAM
6967  for use for the DATA and IDATA segments.
6968  The compiler will not generate any code to put the processor into 10 bit
6969  stack mode.
6970  It is important to ensure that the processor is in this mode before calling
6971  any re-entrant functions compiled with this option.
6972  In principle, this should work with the 
6973 \emph on 
6974 -
6975 \begin_inset ERT
6976 status Collapsed
6977
6978 \layout Standard
6979
6980 \backslash 
6981 /
6982 \end_inset 
6983
6984 -stack-auto
6985 \begin_inset LatexCommand \index{-\/-stack-auto}
6986
6987 \end_inset 
6988
6989
6990 \emph default 
6991  option, but that has not been tested.
6992  It is incompatible with the 
6993 \emph on 
6994 -
6995 \begin_inset ERT
6996 status Collapsed
6997
6998 \layout Standard
6999
7000 \backslash 
7001 /
7002 \end_inset 
7003
7004 -xstack
7005 \begin_inset LatexCommand \index{-\/-xstack}
7006
7007 \end_inset 
7008
7009
7010 \emph default 
7011  option.
7012  It also only makes sense if the processor is in 24 bit contiguous addressing
7013  mode (see the 
7014 \emph on 
7015 -
7016 \begin_inset ERT
7017 status Collapsed
7018
7019 \layout Standard
7020
7021 \backslash 
7022 /
7023 \end_inset 
7024
7025 -model-flat24 option
7026 \emph default 
7027 ).
7028 \layout List
7029 \labelwidthstring 00.00.0000
7030
7031
7032 \series bold 
7033 -
7034 \begin_inset ERT
7035 status Collapsed
7036
7037 \layout Standard
7038
7039 \backslash 
7040 /
7041 \end_inset 
7042
7043 -stack-probe
7044 \begin_inset LatexCommand \index{-\/-stack-probe}
7045
7046 \end_inset 
7047
7048
7049 \series default 
7050  insert call to function __stack_probe at each function prologue.
7051 \layout List
7052 \labelwidthstring 00.00.0000
7053
7054
7055 \series bold 
7056 -
7057 \begin_inset ERT
7058 status Collapsed
7059
7060 \layout Standard
7061
7062 \backslash 
7063 /
7064 \end_inset 
7065
7066 -tini-libid
7067 \begin_inset LatexCommand \index{-\/-tini-libid}
7068
7069 \end_inset 
7070
7071
7072 \series default 
7073  <nnnn> LibraryID used in -mTININative.
7074  
7075 \layout List
7076 \labelwidthstring 00.00.0000
7077
7078
7079 \series bold 
7080 -
7081 \begin_inset ERT
7082 status Collapsed
7083
7084 \layout Standard
7085
7086 \backslash 
7087 /
7088 \end_inset 
7089
7090 -use-accelerator
7091 \begin_inset LatexCommand \index{-\/-use-accelerator}
7092
7093 \end_inset 
7094
7095
7096 \series default 
7097  generate code for DS390 Arithmetic Accelerator.
7098  
7099 \layout Subsection
7100
7101 Z80 Options
7102 \begin_inset LatexCommand \index{Options Z80}
7103
7104 \end_inset 
7105
7106
7107 \begin_inset LatexCommand \index{Z80 options}
7108
7109 \end_inset 
7110
7111
7112 \layout List
7113 \labelwidthstring 00.00.0000
7114
7115
7116 \series bold 
7117 -
7118 \begin_inset ERT
7119 status Collapsed
7120
7121 \layout Standard
7122
7123 \backslash 
7124 /
7125 \end_inset 
7126
7127 -callee-saves-bc
7128 \series default 
7129
7130 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
7131
7132 \end_inset 
7133
7134
7135 \size large 
7136 \emph on 
7137  
7138 \size default 
7139 \emph default 
7140 Force a called function to always save BC.
7141 \layout List
7142 \labelwidthstring 00.00.0000
7143
7144
7145 \series bold 
7146 -
7147 \begin_inset ERT
7148 status Collapsed
7149
7150 \layout Standard
7151
7152 \backslash 
7153 /
7154 \end_inset 
7155
7156 -no-std-crt0
7157 \series default 
7158
7159 \begin_inset LatexCommand \index{-\/-no-std-crt0}
7160
7161 \end_inset 
7162
7163  When linking, skip the standard crt0.o object file.
7164  You must provide your own crt0.o for your system when linking.
7165  
7166 \layout Subsection
7167
7168 Optimization Options
7169 \begin_inset LatexCommand \index{Options optimization}
7170
7171 \end_inset 
7172
7173
7174 \begin_inset LatexCommand \index{Optimization options}
7175
7176 \end_inset 
7177
7178
7179 \layout List
7180 \labelwidthstring 00.00.0000
7181
7182
7183 \series bold 
7184 -
7185 \begin_inset ERT
7186 status Collapsed
7187
7188 \layout Standard
7189
7190 \backslash 
7191 /
7192 \end_inset 
7193
7194 -nogcse
7195 \begin_inset LatexCommand \index{-\/-nogcse}
7196
7197 \end_inset 
7198
7199
7200 \series default 
7201  Will not do global subexpression elimination, this option may be used when
7202  the compiler creates undesirably large stack/data spaces to store compiler
7203  temporaries (
7204 \emph on 
7205 s
7206 \emph default 
7207 pill 
7208 \emph on 
7209 loc
7210 \emph default 
7211 ations, sloc
7212 \begin_inset LatexCommand \index{sloc (spill location)}
7213
7214 \end_inset 
7215
7216 ).
7217  A warning message will be generated when this happens and the compiler
7218  will indicate the number of extra bytes it allocated.
7219  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7220 nogcse
7221 \begin_inset LatexCommand \index{\#pragma nogcse}
7222
7223 \end_inset 
7224
7225  can be used to turn off global subexpression elimination
7226 \begin_inset LatexCommand \index{Subexpression elimination}
7227
7228 \end_inset 
7229
7230  for a given function only.
7231 \layout List
7232 \labelwidthstring 00.00.0000
7233
7234
7235 \series bold 
7236 -
7237 \begin_inset ERT
7238 status Collapsed
7239
7240 \layout Standard
7241
7242 \backslash 
7243 /
7244 \end_inset 
7245
7246 -noinvariant
7247 \begin_inset LatexCommand \index{-\/-noinvariant}
7248
7249 \end_inset 
7250
7251
7252 \series default 
7253  Will not do loop invariant optimizations, this may be turned off for reasons
7254  explained for the previous option.
7255  For more details of loop optimizations performed see Loop Invariants in
7256  section 
7257 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7258
7259 \end_inset 
7260
7261 .
7262  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7263 noinvariant
7264 \begin_inset LatexCommand \index{\#pragma noinvariant}
7265
7266 \end_inset 
7267
7268  can be used to turn off invariant optimizations for a given function only.
7269 \layout List
7270 \labelwidthstring 00.00.0000
7271
7272
7273 \series bold 
7274 -
7275 \begin_inset ERT
7276 status Collapsed
7277
7278 \layout Standard
7279
7280 \backslash 
7281 /
7282 \end_inset 
7283
7284 -noinduction
7285 \begin_inset LatexCommand \index{-\/-noinduction}
7286
7287 \end_inset 
7288
7289
7290 \series default 
7291  Will not do loop induction optimizations, see section strength reduction
7292  for more details.
7293  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7294 noinduction
7295 \begin_inset LatexCommand \index{\#pragma noinduction}
7296
7297 \end_inset 
7298
7299  can be used to turn off induction optimizations for a given function only.
7300 \layout List
7301 \labelwidthstring 00.00.0000
7302
7303
7304 \series bold 
7305 -
7306 \begin_inset ERT
7307 status Collapsed
7308
7309 \layout Standard
7310
7311 \backslash 
7312 /
7313 \end_inset 
7314
7315 -nojtbound
7316 \begin_inset LatexCommand \index{-\/-nojtbound}
7317
7318 \end_inset 
7319
7320
7321 \size large 
7322 \bar under 
7323  
7324 \series default 
7325 \size default 
7326 \bar default 
7327  Will not generate boundary condition check when switch statements
7328 \begin_inset LatexCommand \index{switch statement}
7329
7330 \end_inset 
7331
7332  are implemented using jump-tables.
7333  See section 
7334 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7335
7336 \end_inset 
7337
7338 \SpecialChar ~
7339 Switch Statements for more details.
7340  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7341 nojtbound
7342 \begin_inset LatexCommand \index{\#pragma nojtbound}
7343
7344 \end_inset 
7345
7346  can be used to turn off boundary checking for jump tables for a given function
7347  only.
7348 \layout List
7349 \labelwidthstring 00.00.0000
7350
7351
7352 \series bold 
7353 -
7354 \begin_inset ERT
7355 status Collapsed
7356
7357 \layout Standard
7358
7359 \backslash 
7360 /
7361 \end_inset 
7362
7363 -noloopreverse
7364 \begin_inset LatexCommand \index{-\/-noloopreverse}
7365
7366 \end_inset 
7367
7368
7369 \series default 
7370 \size large 
7371  
7372 \size default 
7373 Will not do loop reversal 
7374 \begin_inset LatexCommand \index{Loop reversing}
7375
7376 \end_inset 
7377
7378 optimization.
7379 \layout List
7380 \labelwidthstring 00.00.0000
7381
7382 -
7383 \begin_inset ERT
7384 status Collapsed
7385
7386 \layout Standard
7387
7388 \backslash 
7389 /
7390 \end_inset 
7391
7392 -
7393 \series bold 
7394 nolabelopt
7395 \series default 
7396  
7397 \begin_inset LatexCommand \index{-\/-nolabelopt }
7398
7399 \end_inset 
7400
7401 Will not optimize labels (makes the dumpfiles more readable).
7402 \layout List
7403 \labelwidthstring 00.00.0000
7404
7405
7406 \series bold 
7407 -
7408 \begin_inset ERT
7409 status Collapsed
7410
7411 \layout Standard
7412
7413 \backslash 
7414 /
7415 \end_inset 
7416
7417 -no-xinit-opt
7418 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7419
7420 \end_inset 
7421
7422
7423 \series default 
7424  Will not memcpy initialized data from code space into xdata space.
7425  This saves a few bytes in code space if you don't have initialized data
7426 \begin_inset LatexCommand \index{Variable initialization}
7427
7428 \end_inset 
7429
7430 .
7431 \layout List
7432 \labelwidthstring 00.00.0000
7433
7434
7435 \series bold 
7436 -
7437 \begin_inset ERT
7438 status Collapsed
7439
7440 \layout Standard
7441
7442 \backslash 
7443 /
7444 \end_inset 
7445
7446 -nooverlay
7447 \begin_inset LatexCommand \index{-\/-nooverlay}
7448
7449 \end_inset 
7450
7451
7452 \series default 
7453   The compiler will not overlay parameters and local variables of any function,
7454  see section Parameters and local variables for more details.
7455 \layout List
7456 \labelwidthstring 00.00.0000
7457
7458
7459 \series bold 
7460 -
7461 \begin_inset ERT
7462 status Collapsed
7463
7464 \layout Standard
7465
7466 \backslash 
7467 /
7468 \end_inset 
7469
7470 -no-peep
7471 \begin_inset LatexCommand \index{-\/-no-peep}
7472
7473 \end_inset 
7474
7475
7476 \series default 
7477  Disable peep-hole optimization with built-in rules.
7478 \layout List
7479 \labelwidthstring 00.00.0000
7480
7481
7482 \series bold 
7483 -
7484 \begin_inset ERT
7485 status Collapsed
7486
7487 \layout Standard
7488
7489 \backslash 
7490 /
7491 \end_inset 
7492
7493 -peep-file
7494 \series default 
7495
7496 \begin_inset LatexCommand \index{-\/-peep-file}
7497
7498 \end_inset 
7499
7500 \SpecialChar ~
7501 <filename> This option can be used to use additional rules to be used by
7502  the peep hole optimizer.
7503  See section 
7504 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7505
7506 \end_inset 
7507
7508 \SpecialChar ~
7509 Peep Hole optimizations for details on how to write these rules.
7510 \layout List
7511 \labelwidthstring 00.00.0000
7512
7513
7514 \series bold 
7515 -
7516 \begin_inset ERT
7517 status Collapsed
7518
7519 \layout Standard
7520
7521 \backslash 
7522 /
7523 \end_inset 
7524
7525 -peep-asm
7526 \begin_inset LatexCommand \index{-\/-peep-asm}
7527
7528 \end_inset 
7529
7530
7531 \series default 
7532  Pass the inline assembler code through the peep hole optimizer.
7533  This can cause unexpected changes to inline assembler code, please go through
7534  the peephole optimizer
7535 \begin_inset LatexCommand \index{Peephole optimizer}
7536
7537 \end_inset 
7538
7539  rules defined in the source file tree '<target>/peeph.def' before using
7540  this option.
7541 \layout List
7542 \labelwidthstring 00.00.0000
7543
7544
7545 \series bold 
7546 -
7547 \begin_inset ERT
7548 status Collapsed
7549
7550 \layout Standard
7551
7552 \backslash 
7553 /
7554 \end_inset 
7555
7556 -opt-code-speed
7557 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7558
7559 \end_inset 
7560
7561
7562 \series default 
7563  The compiler will optimize code generation towards fast code, possibly
7564  at the expense of code size.
7565 \layout List
7566 \labelwidthstring 00.00.0000
7567
7568
7569 \series bold 
7570 -
7571 \begin_inset ERT
7572 status Collapsed
7573
7574 \layout Standard
7575
7576 \backslash 
7577 /
7578 \end_inset 
7579
7580 -opt-code-size
7581 \begin_inset LatexCommand \index{-\/-opt-code-size}
7582
7583 \end_inset 
7584
7585
7586 \series default 
7587  The compiler will optimize code generation towards compact code, possibly
7588  at the expense of code speed.
7589 \layout Subsection
7590
7591 Other Options
7592 \begin_inset LatexCommand \index{Options other}
7593
7594 \end_inset 
7595
7596
7597 \layout List
7598 \labelwidthstring 00.00.0000
7599
7600
7601 \series bold 
7602 -c\SpecialChar ~
7603 -
7604 \begin_inset ERT
7605 status Collapsed
7606
7607 \layout Standard
7608
7609 \backslash 
7610 /
7611 \end_inset 
7612
7613 -compile-only
7614 \begin_inset LatexCommand \index{-\/-compile-only}
7615
7616 \end_inset 
7617
7618
7619 \begin_inset LatexCommand \index{-c -\/-compile-only}
7620
7621 \end_inset 
7622
7623
7624 \series default 
7625  will compile and assemble the source, but will not call the linkage editor.
7626 \layout List
7627 \labelwidthstring 00.00.0000
7628
7629
7630 \series bold 
7631 -
7632 \series default 
7633
7634 \begin_inset ERT
7635 status Collapsed
7636
7637 \layout Standard
7638
7639 \backslash 
7640 /
7641 \end_inset 
7642
7643
7644 \series bold 
7645 -c1mode
7646 \begin_inset LatexCommand \index{-\/-c1mode}
7647
7648 \end_inset 
7649
7650
7651 \series default 
7652  reads the preprocessed source from standard input and compiles it.
7653  The file name for the assembler output must be specified using the -o option.
7654 \layout List
7655 \labelwidthstring 00.00.0000
7656
7657
7658 \series bold 
7659 -E
7660 \begin_inset LatexCommand \index{-E}
7661
7662 \end_inset 
7663
7664
7665 \series default 
7666  Run only the C preprocessor.
7667  Preprocess all the C source files specified and output the results to standard
7668  output.
7669 \layout List
7670 \labelwidthstring 00.00.0000
7671
7672
7673 \series bold 
7674 -o\SpecialChar ~
7675 <path/file>
7676 \begin_inset LatexCommand \index{-o <path/file>}
7677
7678 \end_inset 
7679
7680  
7681 \series default 
7682 The output path resp.
7683  file where everything will be placed.
7684  If the parameter is a path, it must have a trailing slash (or backslash
7685  for the Windows binaries) to be recognized as a path.
7686  
7687 \layout List
7688 \labelwidthstring 00.00.0000
7689
7690
7691 \series bold 
7692 -
7693 \begin_inset ERT
7694 status Collapsed
7695
7696 \layout Standard
7697
7698 \backslash 
7699 /
7700 \end_inset 
7701
7702 -stack-auto
7703 \begin_inset LatexCommand \index{-\/-stack-auto}
7704
7705 \end_inset 
7706
7707
7708 \series default 
7709 \size large 
7710 \emph on 
7711  
7712 \size default 
7713 \emph default 
7714 All functions in the source file will be compiled as 
7715 \emph on 
7716 reentrant
7717 \emph default 
7718
7719 \begin_inset LatexCommand \index{reentrant}
7720
7721 \end_inset 
7722
7723 , i.e.
7724  the parameters and local variables will be allocated on the stack
7725 \begin_inset LatexCommand \index{stack}
7726
7727 \end_inset 
7728
7729 .
7730  See section 
7731 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7732
7733 \end_inset 
7734
7735  Parameters and Local Variables for more details.
7736  If this option is used all source files in the project should be compiled
7737  with this option.
7738  It automatically implies --int-long-reent and --float-reent.
7739  
7740 \layout List
7741 \labelwidthstring 00.00.0000
7742
7743
7744 \series bold 
7745 -
7746 \begin_inset ERT
7747 status Collapsed
7748
7749 \layout Standard
7750
7751 \backslash 
7752 /
7753 \end_inset 
7754
7755 -callee-saves
7756 \begin_inset LatexCommand \index{-\/-callee-saves}
7757
7758 \end_inset 
7759
7760  function1[,function2][,function3]....
7761
7762 \series default 
7763  The compiler by default uses a caller saves convention for register saving
7764  across function calls, however this can cause unnecessary register pushing
7765  & popping when calling small functions from larger functions.
7766  This option can be used to switch the register saving convention for the
7767  function names specified.
7768  The compiler will not save registers when calling these functions, no extra
7769  code will be generated at the entry & exit (function prologue
7770 \series bold 
7771
7772 \begin_inset LatexCommand \index{function prologue}
7773
7774 \end_inset 
7775
7776
7777 \series default 
7778  & epilogue
7779 \series bold 
7780
7781 \begin_inset LatexCommand \index{function epilogue}
7782
7783 \end_inset 
7784
7785
7786 \series default 
7787 ) for these functions to save & restore the registers used by these functions,
7788  this can SUBSTANTIALLY reduce code & improve run time performance of the
7789  generated code.
7790  In the future the compiler (with inter procedural analysis) will be able
7791  to determine the appropriate scheme to use for each function call.
7792  DO NOT use this option for built-in functions such as _mulint..., if this
7793  option is used for a library function the appropriate library function
7794  needs to be recompiled with the same option.
7795  If the project consists of multiple source files then all the source file
7796  should be compiled with the same -
7797 \begin_inset ERT
7798 status Collapsed
7799
7800 \layout Standard
7801
7802 \backslash 
7803 /
7804 \end_inset 
7805
7806 -callee-saves option string.
7807  Also see #pragma\SpecialChar ~
7808 callee_saves
7809 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7810
7811 \end_inset 
7812
7813 .
7814 \layout List
7815 \labelwidthstring 00.00.0000
7816
7817
7818 \series bold 
7819 -
7820 \begin_inset ERT
7821 status Collapsed
7822
7823 \layout Standard
7824
7825 \backslash 
7826 /
7827 \end_inset 
7828
7829 -debug
7830 \begin_inset LatexCommand \index{-\/-debug}
7831
7832 \end_inset 
7833
7834
7835 \bar under 
7836  
7837 \series default 
7838 \bar default 
7839 When this option is used the compiler will generate debug information.
7840  The debug information collected in a file with .cdb extension can be used
7841  with the SDCDB.
7842  For more information see documentation for SDCDB.
7843  Another file with no extension contains debug information in AOMF or AOMF51
7844 \begin_inset LatexCommand \index{AOMF, AOMF51}
7845
7846 \end_inset 
7847
7848  format which is commonly used by third party tools.
7849 \layout List
7850 \labelwidthstring 00.00.0000
7851
7852
7853 \series bold 
7854 -S
7855 \begin_inset LatexCommand \index{-S}
7856
7857 \end_inset 
7858
7859
7860 \size large 
7861 \bar under 
7862  
7863 \series default 
7864 \size default 
7865 \bar default 
7866 Stop after the stage of compilation proper; do not assemble.
7867  The output is an assembler code file for the input file specified.
7868 \layout List
7869 \labelwidthstring 00.00.0000
7870
7871
7872 \series bold 
7873 -
7874 \begin_inset ERT
7875 status Collapsed
7876
7877 \layout Standard
7878
7879 \backslash 
7880 /
7881 \end_inset 
7882
7883 -int-long-reent
7884 \begin_inset LatexCommand \index{-\/-int-long-reent}
7885
7886 \end_inset 
7887
7888
7889 \series default 
7890  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7891  Note by default these libraries are compiled as non-reentrant.
7892  See section Installation for more details.
7893 \layout List
7894 \labelwidthstring 00.00.0000
7895
7896
7897 \series bold 
7898 -
7899 \begin_inset ERT
7900 status Collapsed
7901
7902 \layout Standard
7903
7904 \backslash 
7905 /
7906 \end_inset 
7907
7908 -cyclomatic
7909 \begin_inset LatexCommand \index{-\/-cyclomatic}
7910
7911 \end_inset 
7912
7913
7914 \bar under 
7915  
7916 \series default 
7917 \bar default 
7918 This option will cause the compiler to generate an information message for
7919  each function in the source file.
7920  The message contains some 
7921 \emph on 
7922 important
7923 \emph default 
7924  information about the function.
7925  The number of edges and nodes the compiler detected in the control flow
7926  graph of the function, and most importantly the 
7927 \emph on 
7928 cyclomatic complexity
7929 \begin_inset LatexCommand \index{Cyclomatic complexity}
7930
7931 \end_inset 
7932
7933
7934 \emph default 
7935  see section on Cyclomatic Complexity for more details.
7936 \layout List
7937 \labelwidthstring 00.00.0000
7938
7939
7940 \series bold 
7941 -
7942 \begin_inset ERT
7943 status Collapsed
7944
7945 \layout Standard
7946
7947 \backslash 
7948 /
7949 \end_inset 
7950
7951 -float-reent
7952 \begin_inset LatexCommand \index{-\/-float-reent}
7953
7954 \end_inset 
7955
7956
7957 \series default 
7958  Floating point library is compiled as reentrant
7959 \begin_inset LatexCommand \index{reentrant}
7960
7961 \end_inset 
7962
7963 .
7964  See section Installation for more details.
7965 \layout List
7966 \labelwidthstring 00.00.0000
7967
7968
7969 \series bold 
7970 -
7971 \begin_inset ERT
7972 status Collapsed
7973
7974 \layout Standard
7975
7976 \backslash 
7977 /
7978 \end_inset 
7979
7980 -main-return
7981 \begin_inset LatexCommand \index{-\/-main-return}
7982
7983 \end_inset 
7984
7985
7986 \series default 
7987  This option can be used if the code generated is called by a monitor program
7988  or if the main routine includes an endless loop.
7989  This option might result in slightly smaller code and save two bytes of
7990  stack space.
7991  The return from the 'main'
7992 \begin_inset LatexCommand \index{main return}
7993
7994 \end_inset 
7995
7996  function will return to the function calling main.
7997  The default setting is to lock up i.e.
7998  generate a '
7999 \family typewriter 
8000 sjmp .
8001 \family default 
8002 '.
8003 \layout List
8004 \labelwidthstring 00.00.0000
8005
8006
8007 \series bold 
8008 -
8009 \begin_inset ERT
8010 status Collapsed
8011
8012 \layout Standard
8013
8014 \backslash 
8015 /
8016 \end_inset 
8017
8018 -nostdinc
8019 \begin_inset LatexCommand \index{-\/-nostdinc}
8020
8021 \end_inset 
8022
8023
8024 \series default 
8025  This will prevent the compiler from passing on the default include path
8026  to the preprocessor.
8027 \layout List
8028 \labelwidthstring 00.00.0000
8029
8030
8031 \series bold 
8032 -
8033 \begin_inset ERT
8034 status Collapsed
8035
8036 \layout Standard
8037
8038 \backslash 
8039 /
8040 \end_inset 
8041
8042 -nostdlib
8043 \begin_inset LatexCommand \index{-\/-nostdlib}
8044
8045 \end_inset 
8046
8047
8048 \series default 
8049  This will prevent the compiler from passing on the default library
8050 \begin_inset LatexCommand \index{Libraries}
8051
8052 \end_inset 
8053
8054  path to the linker.
8055 \layout List
8056 \labelwidthstring 00.00.0000
8057
8058
8059 \series bold 
8060 -
8061 \begin_inset ERT
8062 status Collapsed
8063
8064 \layout Standard
8065
8066 \backslash 
8067 /
8068 \end_inset 
8069
8070 -verbose
8071 \begin_inset LatexCommand \index{-\/-verbose}
8072
8073 \end_inset 
8074
8075
8076 \series default 
8077  Shows the various actions the compiler is performing.
8078 \layout List
8079 \labelwidthstring 00.00.0000
8080
8081
8082 \series bold 
8083 -V
8084 \begin_inset LatexCommand \index{-V}
8085
8086 \end_inset 
8087
8088
8089 \series default 
8090  Shows the actual commands the compiler is executing.
8091 \layout List
8092 \labelwidthstring 00.00.0000
8093
8094
8095 \series bold 
8096 -
8097 \begin_inset ERT
8098 status Collapsed
8099
8100 \layout Standard
8101
8102 \backslash 
8103 /
8104 \end_inset 
8105
8106 -no-c-code-in-asm
8107 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8108
8109 \end_inset 
8110
8111
8112 \series default 
8113  Hides your ugly and inefficient c-code from the asm file, so you can always
8114  blame the compiler :)
8115 \layout List
8116 \labelwidthstring 00.00.0000
8117
8118
8119 \series bold 
8120 -
8121 \begin_inset ERT
8122 status Collapsed
8123
8124 \layout Standard
8125
8126 \backslash 
8127 /
8128 \end_inset 
8129
8130 -no-peep-comments
8131 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8132
8133 \end_inset 
8134
8135
8136 \series default 
8137  Will not include peep-hole comments in the generated files.
8138 \layout List
8139 \labelwidthstring 00.00.0000
8140
8141
8142 \series bold 
8143 -
8144 \begin_inset ERT
8145 status Collapsed
8146
8147 \layout Standard
8148
8149 \backslash 
8150 /
8151 \end_inset 
8152
8153 -i-code-in-asm
8154 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8155
8156 \end_inset 
8157
8158
8159 \series default 
8160  Include i-codes in the asm file.
8161  Sounds like noise but is most helpful for debugging the compiler itself.
8162 \layout List
8163 \labelwidthstring 00.00.0000
8164
8165
8166 \series bold 
8167 -
8168 \begin_inset ERT
8169 status Collapsed
8170
8171 \layout Standard
8172
8173 \backslash 
8174 /
8175 \end_inset 
8176
8177 -less-pedantic
8178 \begin_inset LatexCommand \index{-\/-less-pedantic}
8179
8180 \end_inset 
8181
8182
8183 \series default 
8184  Disable some of the more pedantic warnings
8185 \begin_inset LatexCommand \index{Warnings}
8186
8187 \end_inset 
8188
8189  (jwk burps: please be more specific here, please!).
8190 \layout List
8191 \labelwidthstring 00.00.0000
8192
8193
8194 \series bold 
8195 -
8196 \begin_inset ERT
8197 status Collapsed
8198
8199 \layout Standard
8200
8201 \backslash 
8202 /
8203 \end_inset 
8204
8205 -disable-warning\SpecialChar ~
8206 <nnnn>
8207 \begin_inset LatexCommand \index{-\/-disable-warning}
8208
8209 \end_inset 
8210
8211
8212 \series default 
8213  Disable specific warning with number <nnnn>.
8214 \layout List
8215 \labelwidthstring 00.00.0000
8216
8217
8218 \series bold 
8219 -
8220 \begin_inset ERT
8221 status Collapsed
8222
8223 \layout Standard
8224
8225 \backslash 
8226 /
8227 \end_inset 
8228
8229 -print-search-dirs
8230 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8231
8232 \end_inset 
8233
8234
8235 \series default 
8236  Display the directories in the compiler's search path
8237 \layout List
8238 \labelwidthstring 00.00.0000
8239
8240
8241 \series bold 
8242 -
8243 \begin_inset ERT
8244 status Collapsed
8245
8246 \layout Standard
8247
8248 \backslash 
8249 /
8250 \end_inset 
8251
8252 -vc
8253 \begin_inset LatexCommand \index{-\/-vc}
8254
8255 \end_inset 
8256
8257
8258 \series default 
8259  Display errors and warnings using MSVC style, so you can use SDCC with
8260  visual studio.
8261 \layout List
8262 \labelwidthstring 00.00.0000
8263
8264
8265 \series bold 
8266 -
8267 \begin_inset ERT
8268 status Collapsed
8269
8270 \layout Standard
8271
8272 \backslash 
8273 /
8274 \end_inset 
8275
8276 -use-stdout
8277 \begin_inset LatexCommand \index{-\/-use-stdout}
8278
8279 \end_inset 
8280
8281
8282 \series default 
8283  Send errors and warnings to stdout instead of stderr.
8284 \layout List
8285 \labelwidthstring 00.00.0000
8286
8287
8288 \series bold 
8289 -Wa\SpecialChar ~
8290 asmOption[,asmOption]
8291 \series default 
8292
8293 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8294
8295 \end_inset 
8296
8297 ...
8298  Pass the asmOption to the assembler
8299 \begin_inset LatexCommand \index{Options assembler}
8300
8301 \end_inset 
8302
8303
8304 \begin_inset LatexCommand \index{Assembler options}
8305
8306 \end_inset 
8307
8308 .
8309  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8310 \layout List
8311 \labelwidthstring 00.00.0000
8312
8313
8314 \series bold 
8315 -
8316 \begin_inset ERT
8317 status Collapsed
8318
8319 \layout Standard
8320
8321 \backslash 
8322 /
8323 \end_inset 
8324
8325 -std-sdcc89
8326 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8327
8328 \end_inset 
8329
8330
8331 \series default 
8332  Generally follow the C89 standard, but allow SDCC features that conflict
8333  with the standard (default).
8334 \layout List
8335 \labelwidthstring 00.00.0000
8336
8337
8338 \series bold 
8339 -
8340 \begin_inset ERT
8341 status Collapsed
8342
8343 \layout Standard
8344
8345 \backslash 
8346 /
8347 \end_inset 
8348
8349 -std-c89
8350 \begin_inset LatexCommand \index{-\/-std-c89}
8351
8352 \end_inset 
8353
8354
8355 \series default 
8356  Follow the C89 standard and disable SDCC features that conflict with the
8357  standard.
8358 \layout List
8359 \labelwidthstring 00.00.0000
8360
8361
8362 \series bold 
8363 -
8364 \begin_inset ERT
8365 status Collapsed
8366
8367 \layout Standard
8368
8369 \backslash 
8370 /
8371 \end_inset 
8372
8373 -std-sdcc99
8374 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8375
8376 \end_inset 
8377
8378
8379 \series default 
8380  Generally follow the C99 standard, but allow SDCC features that conflict
8381  with the standard (incomplete support).
8382 \layout List
8383 \labelwidthstring 00.00.0000
8384
8385
8386 \series bold 
8387 -
8388 \begin_inset ERT
8389 status Collapsed
8390
8391 \layout Standard
8392
8393 \backslash 
8394 /
8395 \end_inset 
8396
8397 -std-c99
8398 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8399
8400 \end_inset 
8401
8402
8403 \series default 
8404  Follow the C99 standard and disable SDCC features that conflict with the
8405  standard (incomplete support).
8406 \layout List
8407 \labelwidthstring 00.00.0000
8408
8409
8410 \series bold 
8411 -
8412 \begin_inset ERT
8413 status Collapsed
8414
8415 \layout Standard
8416
8417 \backslash 
8418 /
8419 \end_inset 
8420
8421 -codeseg
8422 \series default 
8423
8424 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8425
8426 \end_inset 
8427
8428 \SpecialChar ~
8429 <Name> The name to be used for the code
8430 \begin_inset LatexCommand \index{code}
8431
8432 \end_inset 
8433
8434  segment, default CSEG.
8435  This is useful if you need to tell the compiler to put the code in a special
8436  segment so you can later on tell the linker to put this segment in a special
8437  place in memory.
8438  Can be used for instance when using bank switching to put the code in a
8439  bank.
8440 \layout List
8441 \labelwidthstring 00.00.0000
8442
8443
8444 \series bold 
8445 -
8446 \begin_inset ERT
8447 status Collapsed
8448
8449 \layout Standard
8450
8451 \backslash 
8452 /
8453 \end_inset 
8454
8455 -constseg
8456 \series default 
8457
8458 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8459
8460 \end_inset 
8461
8462 \SpecialChar ~
8463 <Name> The name to be used for the const
8464 \begin_inset LatexCommand \index{code}
8465
8466 \end_inset 
8467
8468  segment, default CONST.
8469  This is useful if you need to tell the compiler to put the const data in
8470  a special segment so you can later on tell the linker to put this segment
8471  in a special place in memory.
8472  Can be used for instance when using bank switching to put the const data
8473  in a bank.
8474 \layout List
8475 \labelwidthstring 00.00.0000
8476
8477
8478 \series bold 
8479 more-pedantic
8480 \series default 
8481  Actually this is 
8482 \series bold 
8483 \emph on 
8484 not
8485 \series default 
8486 \emph default 
8487  a SDCC compiler option but if you want 
8488 \emph on 
8489 more
8490 \emph default 
8491  warnings you can use a separate tool dedicated to syntax checking like
8492  splint
8493 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8494
8495 \end_inset 
8496
8497
8498 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8499
8500 \end_inset 
8501
8502  
8503 \begin_inset LatexCommand \url{http://www.splint.org}
8504
8505 \end_inset 
8506
8507 .
8508  To make your source files parseable by splint you will have to include
8509  
8510 \family sans 
8511 lint.h
8512 \family default 
8513
8514 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8515
8516 \end_inset 
8517
8518  in your source file and add brackets around extended keywords (like 
8519 \family sans 
8520
8521 \begin_inset Quotes sld
8522 \end_inset 
8523
8524 __at\SpecialChar ~
8525
8526 \series bold 
8527 (
8528 \series default 
8529 0xab
8530 \series bold 
8531 )
8532 \series default 
8533
8534 \begin_inset Quotes srd
8535 \end_inset 
8536
8537
8538 \family default 
8539  and 
8540 \family sans 
8541
8542 \begin_inset Quotes sld
8543 \end_inset 
8544
8545 __interrupt\SpecialChar ~
8546 (2)
8547 \begin_inset Quotes srd
8548 \end_inset 
8549
8550
8551 \family default 
8552 ).
8553  
8554 \newline 
8555 Splint has an excellent on line manual at 
8556 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8557
8558 \end_inset 
8559
8560  and it's capabilities go beyond pure syntax checking.
8561  You'll need to tell splint the location of SDCC's include files so a typical
8562  command line could look like this: 
8563 \newline 
8564
8565 \family sans 
8566 splint\SpecialChar ~
8567 -I\SpecialChar ~
8568 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8569 \SpecialChar ~
8570 myprogram.c
8571 \layout Subsection
8572
8573 Intermediate Dump Options
8574 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8575
8576 \end_inset 
8577
8578
8579 \begin_inset LatexCommand \index{Options intermediate dump}
8580
8581 \end_inset 
8582
8583
8584 \begin_inset LatexCommand \index{Intermediate dump options}
8585
8586 \end_inset 
8587
8588
8589 \layout Standard
8590
8591 The following options are provided for the purpose of retargetting and debugging
8592  the compiler.
8593  They provide a means to dump the intermediate code (iCode
8594 \begin_inset LatexCommand \index{iCode}
8595
8596 \end_inset 
8597
8598 ) generated by the compiler in human readable form at various stages of
8599  the compilation process.
8600  More on iCodes see chapter 
8601 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8602
8603 \end_inset 
8604
8605  
8606 \begin_inset Quotes srd
8607 \end_inset 
8608
8609 The anatomy of the compiler
8610 \begin_inset Quotes srd
8611 \end_inset 
8612
8613 .
8614 \layout List
8615 \labelwidthstring 00.00.0000
8616
8617
8618 \series bold 
8619 -
8620 \begin_inset ERT
8621 status Collapsed
8622
8623 \layout Standard
8624
8625 \backslash 
8626 /
8627 \end_inset 
8628
8629 -dumpraw
8630 \begin_inset LatexCommand \index{-\/-dumpraw}
8631
8632 \end_inset 
8633
8634
8635 \series default 
8636  This option will cause the compiler to dump the intermediate code into
8637  a file of named 
8638 \emph on 
8639 <source filename>.dumpraw
8640 \emph default 
8641  just after the intermediate code has been generated for a function, i.e.
8642  before any optimizations are done.
8643  The basic blocks
8644 \begin_inset LatexCommand \index{Basic blocks}
8645
8646 \end_inset 
8647
8648  at this stage ordered in the depth first number, so they may not be in
8649  sequence of execution.
8650 \layout List
8651 \labelwidthstring 00.00.0000
8652
8653
8654 \series bold 
8655 -
8656 \begin_inset ERT
8657 status Collapsed
8658
8659 \layout Standard
8660
8661 \backslash 
8662 /
8663 \end_inset 
8664
8665 -dumpgcse
8666 \begin_inset LatexCommand \index{-\/-dumpgcse}
8667
8668 \end_inset 
8669
8670
8671 \series default 
8672  Will create a dump of iCode's, after global subexpression elimination
8673 \begin_inset LatexCommand \index{Global subexpression elimination}
8674
8675 \end_inset 
8676
8677 , into a file named 
8678 \emph on 
8679 <source filename>.dumpgcse.
8680 \layout List
8681 \labelwidthstring 00.00.0000
8682
8683
8684 \series bold 
8685 -
8686 \begin_inset ERT
8687 status Collapsed
8688
8689 \layout Standard
8690
8691 \backslash 
8692 /
8693 \end_inset 
8694
8695 -dumpdeadcode
8696 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8697
8698 \end_inset 
8699
8700
8701 \series default 
8702  Will create a dump of iCode's, after deadcode elimination
8703 \begin_inset LatexCommand \index{Dead-code elimination}
8704
8705 \end_inset 
8706
8707 , into a file named 
8708 \emph on 
8709 <source filename>.dumpdeadcode.
8710 \layout List
8711 \labelwidthstring 00.00.0000
8712
8713
8714 \series bold 
8715 -
8716 \begin_inset ERT
8717 status Collapsed
8718
8719 \layout Standard
8720
8721 \backslash 
8722 /
8723 \end_inset 
8724
8725 -dumploop
8726 \begin_inset LatexCommand \index{-\/-dumploop}
8727
8728 \end_inset 
8729
8730
8731 \series default 
8732 \size large 
8733  
8734 \size default 
8735 Will create a dump of iCode's, after loop optimizations
8736 \begin_inset LatexCommand \index{Loop optimization}
8737
8738 \end_inset 
8739
8740 , into a file named 
8741 \emph on 
8742 <source filename>.dumploop.
8743 \layout List
8744 \labelwidthstring 00.00.0000
8745
8746
8747 \series bold 
8748 -
8749 \begin_inset ERT
8750 status Collapsed
8751
8752 \layout Standard
8753
8754 \backslash 
8755 /
8756 \end_inset 
8757
8758 -dumprange
8759 \begin_inset LatexCommand \index{-\/-dumprange}
8760
8761 \end_inset 
8762
8763
8764 \series default 
8765 \size large 
8766  
8767 \size default 
8768 Will create a dump of iCode's, after live range analysis
8769 \begin_inset LatexCommand \index{Live range analysis}
8770
8771 \end_inset 
8772
8773 , into a file named 
8774 \emph on 
8775 <source filename>.dumprange.
8776 \layout List
8777 \labelwidthstring 00.00.0000
8778
8779
8780 \series bold 
8781 -
8782 \begin_inset ERT
8783 status Collapsed
8784
8785 \layout Standard
8786
8787 \backslash 
8788 /
8789 \end_inset 
8790
8791 -dumlrange
8792 \begin_inset LatexCommand \index{-\/-dumlrange}
8793
8794 \end_inset 
8795
8796
8797 \series default 
8798  Will dump the life ranges
8799 \begin_inset LatexCommand \index{Live range analysis}
8800
8801 \end_inset 
8802
8803  for all symbols.
8804 \layout List
8805 \labelwidthstring 00.00.0000
8806
8807
8808 \series bold 
8809 -
8810 \begin_inset ERT
8811 status Collapsed
8812
8813 \layout Standard
8814
8815 \backslash 
8816 /
8817 \end_inset 
8818
8819 -dumpregassign
8820 \begin_inset LatexCommand \index{-\/-dumpregassign}
8821
8822 \end_inset 
8823
8824
8825 \bar under 
8826  
8827 \series default 
8828 \bar default 
8829 Will create a dump of iCode's, after register assignment
8830 \begin_inset LatexCommand \index{Register assignment}
8831
8832 \end_inset 
8833
8834 , into a file named 
8835 \emph on 
8836 <source filename>.dumprassgn.
8837 \layout List
8838 \labelwidthstring 00.00.0000
8839
8840
8841 \series bold 
8842 -
8843 \begin_inset ERT
8844 status Collapsed
8845
8846 \layout Standard
8847
8848 \backslash 
8849 /
8850 \end_inset 
8851
8852 -dumplrange
8853 \begin_inset LatexCommand \index{-\/-dumplrange}
8854
8855 \end_inset 
8856
8857
8858 \series default 
8859  Will create a dump of the live ranges of iTemp's
8860 \layout List
8861 \labelwidthstring 00.00.0000
8862
8863
8864 \series bold 
8865 -
8866 \begin_inset ERT
8867 status Collapsed
8868
8869 \layout Standard
8870
8871 \backslash 
8872 /
8873 \end_inset 
8874
8875 -dumpall
8876 \begin_inset LatexCommand \index{-\/-dumpall}
8877
8878 \end_inset 
8879
8880
8881 \size large 
8882 \bar under 
8883  
8884 \series default 
8885 \size default 
8886 \bar default 
8887 Will cause all the above mentioned dumps to be created.
8888 \layout Subsection
8889
8890 Redirecting output on Windows Shells
8891 \layout Standard
8892
8893 By default SDCC writes it's error messages to 
8894 \begin_inset Quotes sld
8895 \end_inset 
8896
8897 standard error
8898 \begin_inset Quotes srd
8899 \end_inset 
8900
8901 .
8902  To force all messages to 
8903 \begin_inset Quotes sld
8904 \end_inset 
8905
8906 standard output
8907 \begin_inset Quotes srd
8908 \end_inset 
8909
8910  use 
8911 \series bold 
8912 -
8913 \series default 
8914 \emph on 
8915
8916 \begin_inset ERT
8917 status Collapsed
8918
8919 \layout Standard
8920
8921 \backslash 
8922 /
8923 \end_inset 
8924
8925
8926 \series bold 
8927 \emph default 
8928 -
8929 \series default 
8930 use-stdout
8931 \begin_inset LatexCommand \index{-\/-use-stdout}
8932
8933 \end_inset 
8934
8935 .
8936  Additionally, if you happen to have visual studio installed in your windows
8937  machine, you can use it to compile your sources using a custom build and
8938  the SDCC -
8939 \emph on 
8940
8941 \begin_inset ERT
8942 status Collapsed
8943
8944 \layout Standard
8945
8946 \backslash 
8947 /
8948 \end_inset 
8949
8950
8951 \emph default 
8952 -vc
8953 \begin_inset LatexCommand \index{-\/-vc}
8954
8955 \end_inset 
8956
8957  option.
8958  Something like this should work:
8959 \newline 
8960
8961 \newline 
8962
8963 \series bold 
8964 c:
8965 \backslash 
8966 sdcc
8967 \backslash 
8968 bin
8969 \backslash 
8970 sdcc.exe -
8971 \series default 
8972 \emph on 
8973
8974 \begin_inset ERT
8975 status Collapsed
8976
8977 \layout Standard
8978
8979 \backslash 
8980 /
8981 \end_inset 
8982
8983
8984 \series bold 
8985 \emph default 
8986 -vc -
8987 \series default 
8988 \emph on 
8989
8990 \begin_inset ERT
8991 status Collapsed
8992
8993 \layout Standard
8994
8995 \backslash 
8996 /
8997 \end_inset 
8998
8999
9000 \series bold 
9001 \emph default 
9002 -model-large -c $(InputPath)
9003 \layout Section
9004
9005 Environment variables
9006 \begin_inset LatexCommand \index{Environment variables}
9007
9008 \end_inset 
9009
9010
9011 \layout Standard
9012
9013 SDCC recognizes the following environment variables:
9014 \layout List
9015 \labelwidthstring 00.00.0000
9016
9017
9018 \series bold 
9019 SDCC_LEAVE_SIGNALS
9020 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9021
9022 \end_inset 
9023
9024
9025 \series default 
9026  SDCC installs a signal handler
9027 \begin_inset LatexCommand \index{signal handler}
9028
9029 \end_inset 
9030
9031  to be able to delete temporary files after an user break (^C) or an exception.
9032  If this environment variable is set, SDCC won't install the signal handler
9033  in order to be able to debug SDCC.
9034 \layout List
9035 \labelwidthstring 00.00.0000
9036
9037
9038 \series bold 
9039 TMP,\SpecialChar ~
9040 TEMP,\SpecialChar ~
9041 TMPDIR
9042 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9043
9044 \end_inset 
9045
9046
9047 \series default 
9048  Path, where temporary files will be created.
9049  The order of the variables is the search order.
9050  In a standard *nix environment these variables are not set, and there's
9051  no need to set them.
9052  On Windows it's recommended to set one of them.
9053 \layout List
9054 \labelwidthstring 00.00.0000
9055
9056
9057 \series bold 
9058 SDCC_HOME
9059 \begin_inset LatexCommand \index{SDCC\_HOME}
9060
9061 \end_inset 
9062
9063
9064 \series default 
9065  Path, see section 
9066 \begin_inset LatexCommand \ref{sub:Install-paths}
9067
9068 \end_inset 
9069
9070 \SpecialChar ~
9071
9072 \begin_inset Quotes sld
9073 \end_inset 
9074
9075  Install Paths
9076 \begin_inset Quotes srd
9077 \end_inset 
9078
9079 .
9080 \layout List
9081 \labelwidthstring 00.00.0000
9082
9083
9084 \series bold 
9085 SDCC_INCLUDE
9086 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9087
9088 \end_inset 
9089
9090
9091 \series default 
9092  Path, see section 
9093 \begin_inset LatexCommand \ref{sub:Search-Paths}
9094
9095 \end_inset 
9096
9097 \SpecialChar ~
9098
9099 \begin_inset Quotes sld
9100 \end_inset 
9101
9102 Search Paths
9103 \begin_inset Quotes srd
9104 \end_inset 
9105
9106 .
9107 \layout List
9108 \labelwidthstring 00.00.0000
9109
9110
9111 \series bold 
9112 SDCC_LIB
9113 \begin_inset LatexCommand \index{SDCC\_LIB}
9114
9115 \end_inset 
9116
9117
9118 \series default 
9119  Path, see section 
9120 \begin_inset LatexCommand \ref{sub:Search-Paths}
9121
9122 \end_inset 
9123
9124 \SpecialChar ~
9125
9126 \begin_inset Quotes sld
9127 \end_inset 
9128
9129 Search Paths
9130 \begin_inset Quotes srd
9131 \end_inset 
9132
9133 ..
9134 \layout Standard
9135
9136 There are some more environment variables recognized by SDCC, but these
9137  are solely used for debugging purposes.
9138  They can change or disappear very quickly, and will never be documented.
9139 \layout Section
9140
9141 Storage Class Language Extensions
9142 \layout Subsection
9143
9144 MCS51/DS390 Storage Class
9145 \begin_inset LatexCommand \index{Storage class}
9146
9147 \end_inset 
9148
9149  Language Extensions
9150 \layout Standard
9151
9152 In addition to the ANSI storage classes SDCC allows the following MCS51
9153  specific storage classes:
9154 \layout Subsubsection
9155
9156 data
9157 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9158
9159 \end_inset 
9160
9161
9162 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9163
9164 \end_inset 
9165
9166  / near
9167 \begin_inset LatexCommand \index{near (storage class)}
9168
9169 \end_inset 
9170
9171
9172 \begin_inset LatexCommand \index{\_\_near (storage class)}
9173
9174 \end_inset 
9175
9176
9177 \layout Standard
9178
9179 This is the 
9180 \series bold 
9181 default
9182 \series default 
9183  storage class for the Small Memory model (
9184 \emph on 
9185 data
9186 \emph default 
9187  and 
9188 \emph on 
9189 near
9190 \emph default 
9191  or the more ANSI-C compliant forms 
9192 \emph on 
9193 __data
9194 \emph default 
9195  and 
9196 \emph on 
9197 __near
9198 \emph default 
9199  can be used synonymously).
9200  Variables declared with this storage class will be allocated in the directly
9201  addressable portion of the internal RAM of a 8051, e.g.:
9202 \layout Verse
9203
9204
9205 \family typewriter 
9206 __data unsigned char test_data;
9207 \layout Standard
9208
9209 Writing 0x01 to this variable generates the assembly code:
9210 \layout Verse
9211
9212
9213 \family typewriter 
9214 75*00 01\SpecialChar ~
9215 \SpecialChar ~
9216 \SpecialChar ~
9217 mov\SpecialChar ~
9218 \SpecialChar ~
9219 _test_data,#0x01
9220 \layout Subsubsection
9221
9222 xdata
9223 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9224
9225 \end_inset 
9226
9227
9228 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9229
9230 \end_inset 
9231
9232  / far
9233 \begin_inset LatexCommand \index{far (storage class)}
9234
9235 \end_inset 
9236
9237
9238 \begin_inset LatexCommand \index{\_\_far (storage class)}
9239
9240 \end_inset 
9241
9242
9243 \layout Standard
9244
9245 Variables declared with this storage class will be placed in the external
9246  RAM.
9247  This is the 
9248 \series bold 
9249 default
9250 \series default 
9251  storage class for the Large Memory model, e.g.:
9252 \layout Verse
9253
9254
9255 \family typewriter 
9256 __xdata unsigned char test_xdata;
9257 \layout Standard
9258
9259 Writing 0x01 to this variable generates the assembly code:
9260 \layout Verse
9261
9262
9263 \family typewriter 
9264 90s00r00\SpecialChar ~
9265 \SpecialChar ~
9266 \SpecialChar ~
9267 mov\SpecialChar ~
9268 \SpecialChar ~
9269 dptr,#_test_xdata 
9270 \newline 
9271 74\SpecialChar ~
9272 01\SpecialChar ~
9273 \SpecialChar ~
9274 \SpecialChar ~
9275 \SpecialChar ~
9276 \SpecialChar ~
9277 \SpecialChar ~
9278 mov\SpecialChar ~
9279 \SpecialChar ~
9280 a,#0x01 
9281 \newline 
9282 F0\SpecialChar ~
9283 \SpecialChar ~
9284 \SpecialChar ~
9285 \SpecialChar ~
9286 \SpecialChar ~
9287 \SpecialChar ~
9288 \SpecialChar ~
9289 \SpecialChar ~
9290 \SpecialChar ~
9291 movx\SpecialChar ~
9292 @dptr,a 
9293 \layout Subsubsection
9294
9295 idata
9296 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9297
9298 \end_inset 
9299
9300
9301 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9302
9303 \end_inset 
9304
9305
9306 \layout Standard
9307
9308 Variables declared with this storage class will be allocated into the indirectly
9309  addressable portion of the internal ram of a 8051, e.g.:
9310 \layout Verse
9311
9312
9313 \family typewriter 
9314 __idata unsigned char test_idata;
9315 \layout Standard
9316
9317 Writing 0x01 to this variable generates the assembly code:
9318 \layout Verse
9319
9320
9321 \family typewriter 
9322 78r00\SpecialChar ~
9323 \SpecialChar ~
9324 \SpecialChar ~
9325 \SpecialChar ~
9326 \SpecialChar ~
9327 \SpecialChar ~
9328 \SpecialChar ~
9329 mov\SpecialChar ~
9330 \SpecialChar ~
9331 r0,#_test_idata
9332 \newline 
9333 76\SpecialChar ~
9334 01\SpecialChar ~
9335 \SpecialChar ~
9336 \SpecialChar ~
9337 \SpecialChar ~
9338 \SpecialChar ~
9339 \SpecialChar ~
9340 \SpecialChar ~
9341 mov\SpecialChar ~
9342 \SpecialChar ~
9343 @r0,#0x01
9344 \layout Standard
9345
9346 Please note, the first 128 byte of idata physically access the same RAM
9347  as the data memory.
9348  The original 8051 had 128 byte idata memory, nowadays most devices have
9349  256 byte idata memory.
9350  The stack
9351 \begin_inset LatexCommand \index{stack}
9352
9353 \end_inset 
9354
9355  is located in idata memory.
9356 \layout Subsubsection
9357
9358 pdata
9359 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9360
9361 \end_inset 
9362
9363
9364 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9365
9366 \end_inset 
9367
9368
9369 \layout Standard
9370
9371 Paged xdata access is just as straightforward as using the other addressing
9372  modes of a 8051.
9373  It is typically located at the start of xdata and has a maximum size of
9374  256 bytes.
9375  The following example writes 0x01 to the pdata variable.
9376  Please note, pdata access physically accesses xdata memory.
9377  The high byte of the address is determined by port P2 
9378 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9379
9380 \end_inset 
9381
9382 (or in case of some 8051 variants by a separate Special Function Register,
9383  see section 
9384 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9385
9386 \end_inset 
9387
9388 ).
9389  This is the 
9390 \series bold 
9391 default
9392 \series default 
9393  storage class for the Medium Memory model, e.g.:
9394 \layout Verse
9395
9396
9397 \family typewriter 
9398 __pdata unsigned char test_pdata;
9399 \layout Standard
9400
9401 Writing 0x01 to this variable generates the assembly code:
9402 \layout Verse
9403
9404
9405 \family typewriter 
9406 78r00\SpecialChar ~
9407 \SpecialChar ~
9408 \SpecialChar ~
9409 \SpecialChar ~
9410 \SpecialChar ~
9411 \SpecialChar ~
9412 mov r0,#_test_pdata
9413 \newline 
9414 74 01\SpecialChar ~
9415 \SpecialChar ~
9416 \SpecialChar ~
9417 \SpecialChar ~
9418 \SpecialChar ~
9419 \SpecialChar ~
9420 mov a,#0x01 
9421 \newline 
9422 F2\SpecialChar ~
9423 \SpecialChar ~
9424 \SpecialChar ~
9425 \SpecialChar ~
9426 \SpecialChar ~
9427 \SpecialChar ~
9428 \SpecialChar ~
9429 \SpecialChar ~
9430 \SpecialChar ~
9431 movx @r0,a
9432 \layout Standard
9433
9434 If the -
9435 \begin_inset ERT
9436 status Collapsed
9437
9438 \layout Standard
9439
9440 \backslash 
9441 /
9442 \end_inset 
9443
9444 -xstack
9445 \begin_inset LatexCommand \index{-\/-xstack}
9446
9447 \end_inset 
9448
9449  option is used the pdata memory area is followed by the xstack memory area
9450  and the sum of their sizes is limited to 256 bytes.
9451 \layout Subsubsection
9452
9453 code
9454 \begin_inset LatexCommand \index{code}
9455
9456 \end_inset 
9457
9458
9459 \begin_inset LatexCommand \index{\_\_code}
9460
9461 \end_inset 
9462
9463
9464 \layout Standard
9465
9466 'Variables' declared with this storage class will be placed in the code
9467  memory:
9468 \layout Verse
9469
9470
9471 \family typewriter 
9472 __code unsigned char test_code;
9473 \layout Standard
9474
9475 Read access to this variable generates the assembly code:
9476 \layout Verse
9477
9478
9479 \family typewriter 
9480 90s00r6F\SpecialChar ~
9481 \SpecialChar ~
9482 \SpecialChar ~
9483 mov dptr,#_test_code
9484 \newline 
9485 E4\SpecialChar ~
9486 \SpecialChar ~
9487 \SpecialChar ~
9488 \SpecialChar ~
9489 \SpecialChar ~
9490 \SpecialChar ~
9491 \SpecialChar ~
9492 \SpecialChar ~
9493 \SpecialChar ~
9494 clr a
9495 \newline 
9496 93\SpecialChar ~
9497 \SpecialChar ~
9498 \SpecialChar ~
9499 \SpecialChar ~
9500 \SpecialChar ~
9501 \SpecialChar ~
9502 \SpecialChar ~
9503 \SpecialChar ~
9504 \SpecialChar ~
9505 movc a,@a+dptr 
9506 \layout Standard
9507
9508
9509 \family typewriter 
9510 char
9511 \family default 
9512  indexed arrays of characters in code memory can be accessed efficiently:
9513 \layout Verse
9514
9515
9516 \family typewriter 
9517 __code char test_array[] = {'c','h','e','a','p'}; 
9518 \layout Standard
9519
9520 Read access to this array using an 8-bit unsigned index generates the assembly
9521  code:
9522 \layout Verse
9523
9524
9525 \family typewriter 
9526 E5*00\SpecialChar ~
9527 \SpecialChar ~
9528 \SpecialChar ~
9529 \SpecialChar ~
9530 \SpecialChar ~
9531 \SpecialChar ~
9532 mov a,_index 
9533 \layout Verse
9534
9535
9536 \family typewriter 
9537 90s00r41\SpecialChar ~
9538 \SpecialChar ~
9539 \SpecialChar ~
9540 mov dptr,#_test_array
9541 \layout Verse
9542
9543
9544 \family typewriter 
9545 93\SpecialChar ~
9546 \SpecialChar ~
9547 \SpecialChar ~
9548 \SpecialChar ~
9549 \SpecialChar ~
9550 \SpecialChar ~
9551 \SpecialChar ~
9552 \SpecialChar ~
9553 \SpecialChar ~
9554 movc a,@a+dptr 
9555 \layout Subsubsection
9556
9557 bit
9558 \begin_inset LatexCommand \index{bit}
9559
9560 \end_inset 
9561
9562
9563 \begin_inset LatexCommand \index{\_\_bit}
9564
9565 \end_inset 
9566
9567
9568 \layout Standard
9569
9570 This is a data-type and a storage class specifier.
9571  When a variable is declared as a bit, it is allocated into the bit addressable
9572  memory of 8051, e.g.:
9573 \layout Verse
9574
9575
9576 \family typewriter 
9577 __bit test_bit;
9578 \layout Standard
9579
9580 Writing 1 to this variable generates the assembly code:
9581 \layout Verse
9582
9583
9584 \family typewriter 
9585 D2*00\SpecialChar ~
9586 \SpecialChar ~
9587 \SpecialChar ~
9588 \SpecialChar ~
9589 \SpecialChar ~
9590 \SpecialChar ~
9591 \SpecialChar ~
9592 setb\SpecialChar ~
9593 _test_bit
9594 \layout Standard
9595
9596 The bit addressable memory consists of 128 bits which are located from 0x20
9597  to 0x2f in data memory.
9598  
9599 \newline 
9600 Apart from this 8051 specific storage class most architectures support ANSI-C
9601  bitfields
9602 \begin_inset LatexCommand \index{bitfields}
9603
9604 \end_inset 
9605
9606
9607 \begin_inset Foot
9608 collapsed false
9609
9610 \layout Standard
9611
9612 Not really meant as examples, but nevertheless showing what bitfields are
9613  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9614 \end_inset 
9615
9616 .
9617  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9618  signed modifier are implemented as unsigned.
9619 \layout Subsubsection
9620
9621 sfr
9622 \begin_inset LatexCommand \index{sfr}
9623
9624 \end_inset 
9625
9626
9627 \begin_inset LatexCommand \index{\_\_sfr}
9628
9629 \end_inset 
9630
9631  / sfr16
9632 \begin_inset LatexCommand \index{sfr16}
9633
9634 \end_inset 
9635
9636
9637 \begin_inset LatexCommand \index{\_\_sfr16}
9638
9639 \end_inset 
9640
9641  / sfr32
9642 \begin_inset LatexCommand \index{sfr32}
9643
9644 \end_inset 
9645
9646
9647 \begin_inset LatexCommand \index{\_\_sfr32}
9648
9649 \end_inset 
9650
9651  / sbit
9652 \begin_inset LatexCommand \index{\_\_sbit}
9653
9654 \end_inset 
9655
9656
9657 \layout Standard
9658
9659 Like the bit keyword, 
9660 \emph on 
9661 sfr / sfr16 / sfr32 / sbit 
9662 \emph default 
9663 signify both a data-type and storage class, they are used to describe the
9664  
9665 \emph on 
9666 s
9667 \emph default 
9668 pecial 
9669 \emph on 
9670 f
9671 \emph default 
9672 unction 
9673 \emph on 
9674 r
9675 \emph default 
9676 egisters and 
9677 \emph on 
9678 s
9679 \emph default 
9680 pecial 
9681 \emph on 
9682 bit
9683 \emph default 
9684  variables of a 8051, eg:
9685 \layout Verse
9686
9687
9688 \family typewriter 
9689 __sfr __at
9690 \begin_inset LatexCommand \index{at}
9691
9692 \end_inset 
9693
9694
9695 \begin_inset LatexCommand \index{\_\_at}
9696
9697 \end_inset 
9698
9699  (0x80) P0;\SpecialChar ~
9700  /* special function register P0 at location 0x80 */
9701 \newline 
9702 /* 16 bit special function register combination for timer 0 */
9703 \newline 
9704 /* with the high byte at location 0x8C and the low byte at location 0x8A
9705  */
9706 \newline 
9707 __sfr16 __at
9708 \begin_inset LatexCommand \index{at}
9709
9710 \end_inset 
9711
9712
9713 \begin_inset LatexCommand \index{\_\_at}
9714
9715 \end_inset 
9716
9717  (0x8C8A) TMR0;
9718 \newline 
9719 __sbit __at (0xd7) CY; /* CY (Carry Flag
9720 \begin_inset LatexCommand \index{Flags}
9721
9722 \end_inset 
9723
9724
9725 \begin_inset LatexCommand \index{Carry flag}
9726
9727 \end_inset 
9728
9729 ) */
9730 \layout Standard
9731
9732 Special function registers which are located on an address dividable by
9733  8 are bit-addressable, an
9734 \emph on 
9735  sbit
9736 \emph default 
9737  addresses a specific bit within these sfr.
9738 \newline 
9739 16 Bit and 32 bit special function register combinations which require a
9740  certain access order are better not declared using 
9741 \emph on 
9742 sfr16
9743 \emph default 
9744  or 
9745 \emph on 
9746 sfr32.
9747
9748 \emph default 
9749  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9750  this is not guaranteed.
9751 \layout Subsubsection
9752
9753 Pointers
9754 \begin_inset LatexCommand \index{Pointer}
9755
9756 \end_inset 
9757
9758  to MCS51/DS390 specific memory spaces
9759 \layout Standard
9760
9761 SDCC allows (via language extensions) pointers to explicitly point to any
9762  of the memory spaces
9763 \begin_inset LatexCommand \index{Memory model}
9764
9765 \end_inset 
9766
9767  of the 8051.
9768  In addition to the explicit pointers, the compiler uses (by default) generic
9769  pointers which can be used to point to any of the memory spaces.
9770 \newline 
9771
9772 \newline 
9773 Pointer declaration examples:
9774 \layout Verse
9775
9776
9777 \family typewriter 
9778 /* pointer physically in internal ram pointing to object in external ram
9779  */ 
9780 \newline 
9781 __xdata unsigned char * __data p;
9782 \newline 
9783
9784 \newline 
9785 /* pointer physically in external ram pointing to object in internal ram
9786  */ 
9787 \newline 
9788 __data unsigned char * __xdata p;
9789 \newline 
9790
9791 \newline 
9792 /* pointer physically in code rom pointing to data in xdata space */ 
9793 \newline 
9794 __xdata unsigned char * __code p;
9795 \newline 
9796
9797 \newline 
9798 /* pointer physically in code space pointing to data in code space */ 
9799 \newline 
9800 __code unsigned char * __code p;
9801 \newline 
9802
9803 \newline 
9804 /* the following is a generic pointer physically located in xdata space
9805  */
9806 \newline 
9807 char * __xdata p;
9808 \newline 
9809
9810 \newline 
9811 /* the following is a function pointer physically located in data space
9812  */
9813 \newline 
9814 char (* __data fp)(void);
9815 \layout Standard
9816
9817 Well you get the idea.
9818  
9819 \newline 
9820
9821 \newline 
9822 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
9823 \emph on 
9824 generic
9825 \emph default 
9826  pointers.
9827  
9828 \size small 
9829
9830 \newline 
9831
9832 \newline 
9833
9834 \size default 
9835 The highest order byte of the 
9836 \emph on 
9837 generic
9838 \emph default 
9839  pointers contains the data space information.
9840  Assembler support routines are called whenever data is stored or retrieved
9841  using 
9842 \emph on 
9843 generic
9844 \emph default 
9845  pointers.
9846  These are useful for developing reusable library
9847 \begin_inset LatexCommand \index{Libraries}
9848
9849 \end_inset 
9850
9851  routines.
9852  Explicitly specifying the pointer type will generate the most efficient
9853  code.
9854 \layout Subsubsection
9855
9856 Notes on MCS51 memory
9857 \begin_inset LatexCommand \index{MCS51 memory}
9858
9859 \end_inset 
9860
9861  layout
9862 \layout Standard
9863
9864 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
9865  RAM memory which is structured as follows:
9866 \newline 
9867
9868 \newline 
9869 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
9870  
9871 \newline 
9872 - Bytes 20-2F - 16 bytes to hold 128 bit
9873 \begin_inset LatexCommand \index{bit}
9874
9875 \end_inset 
9876
9877  variables and, 
9878 \newline 
9879 - Bytes 30-7F - 80 bytes for general purpose use.
9880 \newline 
9881
9882 \layout Standard
9883
9884 Additionally some members of the MCS51 family may have up to 128 bytes of
9885  additional, indirectly addressable, internal RAM memory (
9886 \emph on 
9887 idata
9888 \emph default 
9889
9890 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9891
9892 \end_inset 
9893
9894
9895 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9896
9897 \end_inset 
9898
9899 ).
9900  Furthermore, some chips may have some built in external memory (
9901 \emph on 
9902 xdata
9903 \emph default 
9904
9905 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9906
9907 \end_inset 
9908
9909
9910 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9911
9912 \end_inset 
9913
9914 ) which should not be confused with the internal, directly addressable RAM
9915  memory (
9916 \emph on 
9917 data
9918 \emph default 
9919
9920 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9921
9922 \end_inset 
9923
9924
9925 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9926
9927 \end_inset 
9928
9929 ).
9930  Sometimes this built in 
9931 \emph on 
9932 xdata
9933 \emph default 
9934  memory has to be activated before using it (you can probably find this
9935  information on the datasheet of the microcontroller your are using, see
9936  also section 
9937 \begin_inset LatexCommand \ref{sub:Startup-Code}
9938
9939 \end_inset 
9940
9941 \SpecialChar ~
9942 Startup-Code).
9943 \layout Standard
9944
9945 Normally SDCC will only use the first bank
9946 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9947
9948 \end_inset 
9949
9950  of registers (register bank 0), but it is possible to specify that other
9951  banks of registers (keyword 
9952 \emph on 
9953 using
9954 \emph default 
9955  
9956 \emph on 
9957
9958 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9959
9960 \end_inset 
9961
9962
9963 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
9964
9965 \end_inset 
9966
9967
9968 \emph default 
9969 ) should be used in interrupt
9970 \begin_inset LatexCommand \index{interrupt}
9971
9972 \end_inset 
9973
9974
9975 \begin_inset LatexCommand \index{\_\_interrupt}
9976
9977 \end_inset 
9978
9979  routines.
9980  By default, the compiler will place the stack after the last byte of allocated
9981  memory for variables.
9982  For example, if the first 2 banks of registers are used, and only four
9983  bytes are used for 
9984 \emph on 
9985 data
9986 \emph default 
9987  variables, it will position the base of the internal stack at address 20
9988  (0x14).
9989  This implies that as the stack
9990 \begin_inset LatexCommand \index{stack}
9991
9992 \end_inset 
9993
9994  grows, it will use up the remaining register banks, and the 16 bytes used
9995  by the 128 bit variables, and 80 bytes for general purpose use.
9996  If any bit variables are used, the data variables will be placed in unused
9997  register banks and after the byte holding the last bit variable.
9998  For example, if register banks 0 and 1 are used, and there are 9 bit variables
9999  (two bytes used), 
10000 \emph on 
10001 data
10002 \emph default 
10003  variables will be placed starting from address 0x10 to 0x20 and continue
10004  at address 0x22.
10005  You can also use -
10006 \begin_inset ERT
10007 status Collapsed
10008
10009 \layout Standard
10010
10011 \backslash 
10012 /
10013 \end_inset 
10014
10015 -data-loc
10016 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10017
10018 \end_inset 
10019
10020  to specify the start address of the 
10021 \emph on 
10022 data
10023 \emph default 
10024  and -
10025 \begin_inset ERT
10026 status Collapsed
10027
10028 \layout Standard
10029
10030 \backslash 
10031 /
10032 \end_inset 
10033
10034 -iram-size
10035 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10036
10037 \end_inset 
10038
10039  to specify the size of the total internal RAM (
10040 \emph on 
10041 data
10042 \emph default 
10043 +
10044 \emph on 
10045 idata
10046 \emph default 
10047 ).
10048  
10049 \newline 
10050
10051 \layout Standard
10052
10053 By default the 8051 linker will place the stack after the last byte of (i)data
10054  variables.
10055  Option -
10056 \begin_inset ERT
10057 status Collapsed
10058
10059 \layout Standard
10060
10061 \backslash 
10062 /
10063 \end_inset 
10064
10065 -stack-loc
10066 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10067
10068 \end_inset 
10069
10070  allows you to specify the start of the stack, i.e.
10071  you could start it after any data in the general purpose area.
10072  If your microcontroller has additional indirectly addressable internal
10073  RAM (
10074 \emph on 
10075 idata
10076 \emph default 
10077 ) you can place the stack on it.
10078  You may also need to use -
10079 \begin_inset ERT
10080 status Collapsed
10081
10082 \layout Standard
10083
10084 \backslash 
10085 /
10086 \end_inset 
10087
10088 -xdata-loc
10089 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10090
10091 \end_inset 
10092
10093  to set the start address of the external RAM (
10094 \emph on 
10095 xdata
10096 \emph default 
10097 ) and -
10098 \begin_inset ERT
10099 status Collapsed
10100
10101 \layout Standard
10102
10103 \backslash 
10104 /
10105 \end_inset 
10106
10107 -xram-size
10108 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10109
10110 \end_inset 
10111
10112  to specify its size.
10113  Same goes for the code memory, using -
10114 \begin_inset ERT
10115 status Collapsed
10116
10117 \layout Standard
10118
10119 \backslash 
10120 /
10121 \end_inset 
10122
10123 -code-loc
10124 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10125
10126 \end_inset 
10127
10128  and -
10129 \begin_inset ERT
10130 status Collapsed
10131
10132 \layout Standard
10133
10134 \backslash 
10135 /
10136 \end_inset 
10137
10138 -code-size
10139 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10140
10141 \end_inset 
10142
10143 .
10144  If in doubt, don't specify any options and see if the resulting memory
10145  layout is appropriate, then you can adjust it.
10146 \layout Standard
10147
10148 The linker generates two files with memory allocation information.
10149  The first, with extension .map
10150 \begin_inset LatexCommand \index{<file>.map}
10151
10152 \end_inset 
10153
10154  shows all the variables and segments.
10155  The second with extension .mem
10156 \begin_inset LatexCommand \index{<file>.mem}
10157
10158 \end_inset 
10159
10160  shows the final memory layout.
10161  The linker will complain either if memory segments overlap, there is not
10162  enough memory, or there is not enough space for stack.
10163  If you get any linking warnings and/or errors related to stack or segments
10164  allocation, take a look at either the .map or .mem files to find out what
10165  the problem is.
10166  The .mem file may even suggest a solution to the problem.
10167 \layout Subsection
10168
10169 Z80/Z180 Storage Class
10170 \begin_inset LatexCommand \index{Storage class}
10171
10172 \end_inset 
10173
10174  Language Extensions
10175 \layout Subsubsection
10176
10177 sfr
10178 \begin_inset LatexCommand \index{sfr}
10179
10180 \end_inset 
10181
10182
10183 \begin_inset LatexCommand \index{\_\_sfr}
10184
10185 \end_inset 
10186
10187  (in/out to 8-bit addresses)
10188 \layout Standard
10189
10190 The Z80
10191 \begin_inset LatexCommand \index{Z80}
10192
10193 \end_inset 
10194
10195  family has separate address spaces for memory and 
10196 \emph on 
10197 i
10198 \emph default 
10199 nput/
10200 \emph on 
10201 o
10202 \emph default 
10203 utput memory.
10204  I/O memory
10205 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10206
10207 \end_inset 
10208
10209  is accessed with special instructions, e.g.:
10210 \layout Verse
10211
10212
10213 \family typewriter 
10214 sfr at 0x78 IoPort;\SpecialChar ~
10215 \SpecialChar ~
10216 /* define a var in I/O space at 78h called IoPort */
10217  
10218 \layout Standard
10219
10220 Writing 0x01 to this variable generates the assembly code:
10221 \layout Verse
10222
10223
10224 \family typewriter 
10225 3E 01\SpecialChar ~
10226 \SpecialChar ~
10227 \SpecialChar ~
10228 \SpecialChar ~
10229 \SpecialChar ~
10230 \SpecialChar ~
10231 ld a,#0x01
10232 \newline 
10233 D3 78\SpecialChar ~
10234 \SpecialChar ~
10235 \SpecialChar ~
10236 \SpecialChar ~
10237 \SpecialChar ~
10238 \SpecialChar ~
10239 out (_IoPort),a 
10240 \layout Subsubsection
10241
10242 banked sfr
10243 \begin_inset LatexCommand \index{sfr}
10244
10245 \end_inset 
10246
10247
10248 \begin_inset LatexCommand \index{\_\_sfr}
10249
10250 \end_inset 
10251
10252  (in/out to 16-bit addresses)
10253 \layout Standard
10254
10255 The keyword 
10256 \emph on 
10257 banked
10258 \emph default 
10259  is used to support 16 bit addresses in I/O memory e.g.:
10260 \layout Verse
10261
10262
10263 \family typewriter 
10264 sfr banked at
10265 \begin_inset LatexCommand \index{at}
10266
10267 \end_inset 
10268
10269
10270 \begin_inset LatexCommand \index{\_\_at}
10271
10272 \end_inset 
10273
10274  0x123 IoPort; 
10275 \layout Standard
10276
10277 Writing 0x01 to this variable generates the assembly code:
10278 \layout Verse
10279
10280
10281 \family typewriter 
10282 01 23 01\SpecialChar ~
10283 \SpecialChar ~
10284 \SpecialChar ~
10285 ld bc,#_IoPort
10286 \newline 
10287 3E 01\SpecialChar ~
10288 \SpecialChar ~
10289 \SpecialChar ~
10290 \SpecialChar ~
10291 \SpecialChar ~
10292 \SpecialChar ~
10293 ld a,#0x01 
10294 \newline 
10295 ED 79\SpecialChar ~
10296 \SpecialChar ~
10297 \SpecialChar ~
10298 \SpecialChar ~
10299 \SpecialChar ~
10300 \SpecialChar ~
10301 out (c),a 
10302 \layout Subsubsection
10303
10304 sfr
10305 \begin_inset LatexCommand \index{sfr}
10306
10307 \end_inset 
10308
10309
10310 \begin_inset LatexCommand \index{\_\_sfr}
10311
10312 \end_inset 
10313
10314  (in0/out0 to 8 bit addresses on Z180
10315 \begin_inset LatexCommand \index{Z180}
10316
10317 \end_inset 
10318
10319 /HD64180
10320 \begin_inset LatexCommand \index{HD64180}
10321
10322 \end_inset 
10323
10324 )
10325 \layout Standard
10326
10327 The compiler option -
10328 \begin_inset ERT
10329 status Collapsed
10330
10331 \layout Standard
10332
10333 \backslash 
10334 /
10335 \end_inset 
10336
10337 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
10338 portmode
10339 \begin_inset LatexCommand \index{\#pragma portmode}
10340
10341 \end_inset 
10342
10343 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10344 ns 
10345 \family typewriter 
10346 in0/out0
10347 \family default 
10348  instead of 
10349 \family typewriter 
10350 in/out
10351 \family default 
10352 .
10353  If you include the file z180.h this will be set automatically.
10354 \layout Subsection
10355
10356 HC08 Storage Class
10357 \begin_inset LatexCommand \index{Storage class}
10358
10359 \end_inset 
10360
10361  Language Extensions
10362 \layout Subsubsection
10363
10364 data
10365 \begin_inset LatexCommand \index{data (hc08 storage class)}
10366
10367 \end_inset 
10368
10369
10370 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10371
10372 \end_inset 
10373
10374  
10375 \layout Standard
10376
10377 The data storage class declares a variable that resides in the first 256
10378  bytes of memory (the direct page).
10379  The HC08 is most efficient at accessing variables (especially pointers)
10380  stored here.
10381 \layout Subsubsection
10382
10383 xdata
10384 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10385
10386 \end_inset 
10387
10388
10389 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10390
10391 \end_inset 
10392
10393  
10394 \layout Standard
10395
10396 The xdata storage class declares a variable that can reside anywhere in
10397  memory.
10398  This is the default if no storage class is specified.
10399  
10400 \layout Section
10401
10402 Absolute Addressing
10403 \begin_inset LatexCommand \index{Absolute addressing}
10404
10405 \end_inset 
10406
10407
10408 \layout Standard
10409
10410 Data items can be assigned an absolute address with the 
10411 \emph on 
10412 at
10413 \begin_inset LatexCommand \index{at}
10414
10415 \end_inset 
10416
10417
10418 \begin_inset LatexCommand \index{\_\_at}
10419
10420 \end_inset 
10421
10422  <address>
10423 \emph default 
10424  keyword, in addition to a storage class, e.g.:
10425 \layout Verse
10426
10427
10428 \family typewriter 
10429 xdata
10430 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10431
10432 \end_inset 
10433
10434
10435 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10436
10437 \end_inset 
10438
10439  at
10440 \begin_inset LatexCommand \index{at}
10441
10442 \end_inset 
10443
10444
10445 \begin_inset LatexCommand \index{\_\_at}
10446
10447 \end_inset 
10448
10449  (0x7ffe) unsigned int chksum;
10450 \layout Standard
10451
10452 or
10453 \layout Verse
10454
10455
10456 \family typewriter 
10457 __xdata __at (0x7ffe) unsigned int chksum;
10458 \layout Standard
10459
10460 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10461  of the external ram.
10462  The compiler does 
10463 \emph on 
10464 not
10465 \emph default 
10466  reserve any space for variables declared in this way
10467 \begin_inset Marginal
10468 collapsed true
10469
10470 \layout Standard
10471
10472
10473 \series bold 
10474 \SpecialChar ~
10475 !
10476 \end_inset 
10477
10478  (they are implemented with an equate in the assembler).
10479  Thus it is left to the programmer to make sure there are no overlaps with
10480  other variables that are declared without the absolute address.
10481  The assembler listing file (.lst
10482 \begin_inset LatexCommand \index{<file>.lst}
10483
10484 \end_inset 
10485
10486 ) and the linker output files (.rst
10487 \begin_inset LatexCommand \index{<file>.rst}
10488
10489 \end_inset 
10490
10491 ) and (.map
10492 \begin_inset LatexCommand \index{<file>.map}
10493
10494 \end_inset 
10495
10496 ) are good places to look for such overlaps.
10497  Variables with an absolute address are 
10498 \emph on 
10499 not
10500 \begin_inset Marginal
10501 collapsed true
10502
10503 \layout Standard
10504
10505
10506 \series bold 
10507 \SpecialChar ~
10508 !
10509 \end_inset 
10510
10511
10512 \emph default 
10513  initialized
10514 \begin_inset LatexCommand \index{Variable initialization}
10515
10516 \end_inset 
10517
10518 .
10519 \layout Standard
10520
10521 In case of memory mapped I/O devices the keyword 
10522 \emph on 
10523 volatile
10524 \emph default 
10525  has to be used to tell the compiler that accesses might not be removed:
10526 \layout Verse
10527
10528
10529 \family typewriter 
10530 volatile
10531 \begin_inset LatexCommand \index{volatile}
10532
10533 \end_inset 
10534
10535  __xdata
10536 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10537
10538 \end_inset 
10539
10540  __at
10541 \begin_inset LatexCommand \index{at}
10542
10543 \end_inset 
10544
10545  (0x8000) unsigned char PORTA_8255;
10546 \layout Standard
10547
10548 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10549 r) array
10550 \family typewriter 
10551 \size footnotesize 
10552
10553 \begin_inset LatexCommand \index{Aligned array}
10554
10555 \end_inset 
10556
10557
10558 \family default 
10559 \size default 
10560  starts at a block (256 byte) boundary
10561 \begin_inset LatexCommand \index{block boundary}
10562
10563 \end_inset 
10564
10565  (section 
10566 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10567
10568 \end_inset 
10569
10570  has an example).
10571 \newline 
10572 Absolute addresses can be specified for variables in all storage classes,
10573  e.g.:
10574 \layout Verse
10575
10576
10577 \family typewriter 
10578 __bit
10579 \begin_inset LatexCommand \index{bit}
10580
10581 \end_inset 
10582
10583  __at
10584 \begin_inset LatexCommand \index{at}
10585
10586 \end_inset 
10587
10588  (0x02) bvar;
10589 \layout Standard
10590
10591 The above example will allocate the variable at offset 0x02 in the bit-addressab
10592 le space.
10593  There is no real advantage to assigning absolute addresses to variables
10594  in this manner, unless you want strict control over all the variables allocated.
10595  One possible use would be to write hardware portable code.
10596  For example, if you have a routine that uses one or more of the microcontroller
10597  I/O pins, and such pins are different for two different hardwares, you
10598  can declare the I/O pins in your routine using:
10599 \layout Verse
10600
10601
10602 \family typewriter 
10603 extern volatile
10604 \begin_inset LatexCommand \index{volatile}
10605
10606 \end_inset 
10607
10608  __bit MOSI;\SpecialChar ~
10609 \SpecialChar ~
10610 \SpecialChar ~
10611 \SpecialChar ~
10612 /* master out, slave in */
10613 \newline 
10614 extern volatile __bit MISO;\SpecialChar ~
10615 \SpecialChar ~
10616 \SpecialChar ~
10617 \SpecialChar ~
10618 /* master in, slave out */
10619 \newline 
10620 extern volatile __bit MCLK;\SpecialChar ~
10621 \SpecialChar ~
10622 \SpecialChar ~
10623 \SpecialChar ~
10624 /* master clock */
10625 \newline 
10626
10627 \newline 
10628 /* Input and Output of a byte on a 3-wire serial bus.
10629 \newline 
10630 \SpecialChar ~
10631 \SpecialChar ~
10632 \SpecialChar ~
10633 If needed adapt polarity of clock, polarity of data and bit order
10634 \newline 
10635 \SpecialChar ~
10636 */
10637 \newline 
10638 unsigned char spi_io(unsigned char out_byte) 
10639 \newline 
10640
10641 \newline 
10642 \SpecialChar ~
10643 \SpecialChar ~
10644 \SpecialChar ~
10645 \SpecialChar ~
10646 unsigned char i=8;
10647 \newline 
10648 \SpecialChar ~
10649 \SpecialChar ~
10650 \SpecialChar ~
10651 \SpecialChar ~
10652 do { 
10653 \newline 
10654 \SpecialChar ~
10655 \SpecialChar ~
10656 \SpecialChar ~
10657 \SpecialChar ~
10658 \SpecialChar ~
10659 \SpecialChar ~
10660 \SpecialChar ~
10661 \SpecialChar ~
10662 MOSI = out_byte & 0x80; 
10663 \newline 
10664 \SpecialChar ~
10665 \SpecialChar ~
10666 \SpecialChar ~
10667 \SpecialChar ~
10668 \SpecialChar ~
10669 \SpecialChar ~
10670 \SpecialChar ~
10671 \SpecialChar ~
10672 out_byte <<= 1;
10673 \newline 
10674 \SpecialChar ~
10675 \SpecialChar ~
10676 \SpecialChar ~
10677 \SpecialChar ~
10678 \SpecialChar ~
10679 \SpecialChar ~
10680 \SpecialChar ~
10681 \SpecialChar ~
10682 MCLK = 1; 
10683 \newline 
10684 \SpecialChar ~
10685 \SpecialChar ~
10686 \SpecialChar ~
10687 \SpecialChar ~
10688 \SpecialChar ~
10689 \SpecialChar ~
10690 \SpecialChar ~
10691 \SpecialChar ~
10692 /* _asm nop _endasm; */\SpecialChar ~
10693 \SpecialChar ~
10694 \SpecialChar ~
10695 \SpecialChar ~
10696 \SpecialChar ~
10697 \SpecialChar ~
10698 \SpecialChar ~
10699 \SpecialChar ~
10700 /* for slow peripherals */
10701 \newline 
10702 \SpecialChar ~
10703 \SpecialChar ~
10704 \SpecialChar ~
10705 \SpecialChar ~
10706 \SpecialChar ~
10707 \SpecialChar ~
10708 \SpecialChar ~
10709 \SpecialChar ~
10710 if(MISO) 
10711 \newline 
10712 \SpecialChar ~
10713 \SpecialChar ~
10714 \SpecialChar ~
10715 \SpecialChar ~
10716 \SpecialChar ~
10717 \SpecialChar ~
10718 \SpecialChar ~
10719 \SpecialChar ~
10720 \SpecialChar ~
10721 \SpecialChar ~
10722 \SpecialChar ~
10723 \SpecialChar ~
10724 out_byte += 1; 
10725 \newline 
10726 \SpecialChar ~
10727 \SpecialChar ~
10728 \SpecialChar ~
10729 \SpecialChar ~
10730 \SpecialChar ~
10731 \SpecialChar ~
10732 \SpecialChar ~
10733 \SpecialChar ~
10734 MCLK = 0; 
10735 \newline 
10736 \SpecialChar ~
10737 \SpecialChar ~
10738 \SpecialChar ~
10739 \SpecialChar ~
10740 } while(--i);
10741 \newline 
10742 \SpecialChar ~
10743 \SpecialChar ~
10744 \SpecialChar ~
10745 \SpecialChar ~
10746 return out_byte; 
10747 \newline 
10748 }
10749 \layout Standard
10750
10751 Then, someplace in the code for the first hardware you would use
10752 \layout Verse
10753
10754
10755 \family typewriter 
10756 __bit __at
10757 \begin_inset LatexCommand \index{at}
10758
10759 \end_inset 
10760
10761
10762 \begin_inset LatexCommand \index{\_\_at}
10763
10764 \end_inset 
10765
10766  (0x80) MOSI;\SpecialChar ~
10767 \SpecialChar ~
10768 \SpecialChar ~
10769 \SpecialChar ~
10770 /* I/O port 0, bit 0 */
10771 \newline 
10772 __bit __at (0x81) MISO;\SpecialChar ~
10773 \SpecialChar ~
10774 \SpecialChar ~
10775 \SpecialChar ~
10776 /* I/O port 0, bit 1 */
10777 \newline 
10778 __bit __at (0x82) MCLK;\SpecialChar ~
10779 \SpecialChar ~
10780 \SpecialChar ~
10781 \SpecialChar ~
10782 /* I/O port 0, bit 2 */
10783 \layout Standard
10784
10785 Similarly, for the second hardware you would use
10786 \layout Verse
10787
10788
10789 \family typewriter 
10790 __bit __at (0x83) MOSI;\SpecialChar ~
10791 \SpecialChar ~
10792 \SpecialChar ~
10793 \SpecialChar ~
10794 /* I/O port 0, bit 3 */
10795 \newline 
10796 __bit __at (0x91) MISO;\SpecialChar ~
10797 \SpecialChar ~
10798 \SpecialChar ~
10799 \SpecialChar ~
10800 /* I/O port 1, bit 1 */
10801 \newline 
10802 __bit
10803 \begin_inset LatexCommand \index{bit}
10804
10805 \end_inset 
10806
10807  __at (0x92) MCLK;\SpecialChar ~
10808 \SpecialChar ~
10809 \SpecialChar ~
10810 \SpecialChar ~
10811 /* I/O port 1, bit 2 */
10812 \layout Standard
10813
10814 and you can use the same hardware dependent routine without changes, as
10815  for example in a library.
10816  This is somehow similar to sbit, but only one absolute address has to be
10817  specified in the whole project.
10818 \layout Section
10819
10820 Parameters
10821 \begin_inset LatexCommand \index{Parameters}
10822
10823 \end_inset 
10824
10825
10826 \begin_inset LatexCommand \index{function parameter}
10827
10828 \end_inset 
10829
10830  & Local Variables
10831 \begin_inset LatexCommand \index{local variables}
10832
10833 \end_inset 
10834
10835
10836 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
10837
10838 \end_inset 
10839
10840
10841 \layout Standard
10842
10843 Automatic (local) variables and parameters to functions can either be placed
10844  on the stack or in data-space.
10845  The default action of the compiler is to place these variables in the internal
10846  RAM (for small model) or external RAM (for large model).
10847  This in fact makes them similar to 
10848 \emph on 
10849 static
10850 \begin_inset LatexCommand \index{static}
10851
10852 \end_inset 
10853
10854
10855 \emph default 
10856  so by default functions are non-reentrant
10857 \begin_inset LatexCommand \index{reentrant}
10858
10859 \end_inset 
10860
10861 .
10862  
10863 \newline 
10864
10865 \newline 
10866 They can be placed on the stack
10867 \begin_inset LatexCommand \index{stack}
10868
10869 \end_inset 
10870
10871  by using the
10872 \emph on 
10873  -
10874 \begin_inset ERT
10875 status Collapsed
10876
10877 \layout Standard
10878
10879 \backslash 
10880 /
10881 \end_inset 
10882
10883 -stack-auto
10884 \begin_inset LatexCommand \index{-\/-stack-auto}
10885
10886 \end_inset 
10887
10888
10889 \emph default 
10890  option, by using 
10891 \emph on 
10892 #pragma\SpecialChar ~
10893 stackauto
10894 \emph default 
10895
10896 \begin_inset LatexCommand \index{\#pragma stackauto}
10897
10898 \end_inset 
10899
10900  or by using the 
10901 \emph on 
10902 reentrant
10903 \begin_inset LatexCommand \index{reentrant}
10904
10905 \end_inset 
10906
10907
10908 \emph default 
10909  keyword in the function declaration, e.g.:
10910 \layout Verse
10911
10912
10913 \family typewriter 
10914 unsigned char foo(char i) __reentrant 
10915 \newline 
10916
10917 \newline 
10918 \SpecialChar ~
10919 \SpecialChar ~
10920 \SpecialChar ~
10921 \SpecialChar ~
10922 ...
10923  
10924 \newline 
10925 }
10926 \layout Standard
10927
10928 Since stack space on 8051 is limited, the 
10929 \emph on 
10930 reentrant 
10931 \emph default 
10932 keyword or the
10933 \emph on 
10934  -
10935 \begin_inset ERT
10936 status Collapsed
10937
10938 \layout Standard
10939
10940 \backslash 
10941 /
10942 \end_inset 
10943
10944 -stack-auto
10945 \emph default 
10946  option should be used sparingly.
10947  Note that the reentrant keyword just means that the parameters & local
10948  variables will be allocated to the stack, it 
10949 \emph on 
10950 does not
10951 \emph default 
10952  mean that the function is register bank
10953 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10954
10955 \end_inset 
10956
10957  independent.
10958 \newline 
10959
10960 \newline 
10961 Local variables
10962 \begin_inset LatexCommand \index{local variables}
10963
10964 \end_inset 
10965
10966  can be assigned storage classes and absolute
10967 \begin_inset LatexCommand \index{Absolute addressing}
10968
10969 \end_inset 
10970
10971  addresses, e.g.: 
10972 \layout Verse
10973
10974
10975 \family typewriter 
10976 unsigned char foo() 
10977 \newline 
10978 {
10979 \newline 
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 __xdata unsigned char i;
10985 \newline 
10986 \SpecialChar ~
10987 \SpecialChar ~
10988 \SpecialChar ~
10989 \SpecialChar ~
10990 __bit bvar;
10991 \newline 
10992 \SpecialChar ~
10993 \SpecialChar ~
10994 \SpecialChar ~
10995 \SpecialChar ~
10996 __data __at
10997 \begin_inset LatexCommand \index{at}
10998
10999 \end_inset 
11000
11001  (0x31) unsigned char j;
11002 \newline 
11003 \SpecialChar ~
11004 \SpecialChar ~
11005 \SpecialChar ~
11006 \SpecialChar ~
11007 ...
11008  
11009 \newline 
11010 }
11011 \layout Standard
11012
11013 In the above example the variable 
11014 \emph on 
11015 i
11016 \emph default 
11017  will be allocated in the external ram, 
11018 \emph on 
11019 bvar
11020 \emph default 
11021  in bit addressable space and
11022 \emph on 
11023  j
11024 \emph default 
11025  in internal ram.
11026  When compiled with 
11027 \emph on 
11028 -
11029 \begin_inset ERT
11030 status Collapsed
11031
11032 \layout Standard
11033
11034 \backslash 
11035 /
11036 \end_inset 
11037
11038 -stack-auto
11039 \emph default 
11040  or when a function is declared as 
11041 \emph on 
11042 reentrant
11043 \emph default 
11044  this should only be done for static variables.
11045 \layout Standard
11046
11047 Parameters
11048 \begin_inset LatexCommand \index{function parameter}
11049
11050 \end_inset 
11051
11052  however are not allowed any storage class
11053 \begin_inset LatexCommand \index{Storage class}
11054
11055 \end_inset 
11056
11057 , (storage classes for parameters will be ignored), their allocation is
11058  governed by the memory model in use, and the reentrancy options.
11059 \layout Standard
11060
11061 It is however allowed to use bit parameters in reentrant functions and also
11062  non-static local bit variables are supported.
11063  Efficient use is limited to 8 semi-bitregisters in bit space.
11064  They are pushed and popped to stack as a single byte just like the normal
11065  registers.
11066 \layout Section
11067
11068 Overlaying
11069 \begin_inset LatexCommand \label{sub:Overlaying}
11070
11071 \end_inset 
11072
11073
11074 \begin_inset LatexCommand \index{Overlaying}
11075
11076 \end_inset 
11077
11078
11079 \layout Standard
11080
11081 For non-reentrant
11082 \begin_inset LatexCommand \index{reentrant}
11083
11084 \end_inset 
11085
11086  functions SDCC will try to reduce internal ram space usage by overlaying
11087  parameters and local variables of a function (if possible).
11088  Parameters and local variables
11089 \begin_inset LatexCommand \index{local variables}
11090
11091 \end_inset 
11092
11093  of a function will be allocated to an overlayable segment if the function
11094  has 
11095 \emph on 
11096 no other function calls and the function is non-reentrant and the memory
11097  model
11098 \begin_inset LatexCommand \index{Memory model}
11099
11100 \end_inset 
11101
11102  is small.
11103
11104 \emph default 
11105  If an explicit storage class
11106 \begin_inset LatexCommand \index{Storage class}
11107
11108 \end_inset 
11109
11110  is specified for a local variable, it will NOT be overlayed.
11111 \layout Standard
11112
11113 Note that the compiler (not the linkage editor) makes the decision for overlayin
11114 g the data items.
11115  Functions that are called from an interrupt service routine
11116 \begin_inset Marginal
11117 collapsed true
11118
11119 \layout Standard
11120
11121
11122 \series bold 
11123 !
11124 \end_inset 
11125
11126  should be preceded by a #pragma\SpecialChar ~
11127 nooverlay
11128 \begin_inset LatexCommand \index{\#pragma nooverlay}
11129
11130 \end_inset 
11131
11132  if they are not reentrant.
11133 \layout Standard
11134
11135 Also note that the compiler does not do any processing of inline assembler
11136  code, so the compiler might incorrectly assign local variables and parameters
11137  of a function into the overlay segment if the inline assembler code calls
11138  other c-functions that might use the overlay.
11139  In that case the #pragma\SpecialChar ~
11140 nooverlay should be used.
11141 \layout Standard
11142
11143 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11144 tion
11145 \begin_inset LatexCommand \index{Multiplication}
11146
11147 \end_inset 
11148
11149  or division
11150 \begin_inset LatexCommand \index{Division}
11151
11152 \end_inset 
11153
11154  will NOT be overlayed since these are implemented using external functions,
11155  e.g.:
11156 \layout Verse
11157
11158
11159 \family typewriter 
11160 #pragma save 
11161 \newline 
11162 #pragma nooverlay
11163 \begin_inset LatexCommand \index{\#pragma nooverlay}
11164
11165 \end_inset 
11166
11167  
11168 \newline 
11169 void set_error(unsigned char errcd) 
11170 \newline 
11171 {
11172 \newline 
11173 \SpecialChar ~
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 P3 = errcd;
11178 \newline 
11179
11180 \newline 
11181 #pragma restore 
11182 \newline 
11183
11184 \newline 
11185 void some_isr () __interrupt
11186 \begin_inset LatexCommand \index{interrupt}
11187
11188 \end_inset 
11189
11190  (2)
11191 \newline 
11192 {
11193 \newline 
11194 \SpecialChar ~
11195 \SpecialChar ~
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 ...
11199 \newline 
11200 \SpecialChar ~
11201 \SpecialChar ~
11202 \SpecialChar ~
11203 \SpecialChar ~
11204 set_error(10);
11205 \newline 
11206 \SpecialChar ~
11207 \SpecialChar ~
11208 \SpecialChar ~
11209 \SpecialChar ~
11210 ...
11211  
11212 \newline 
11213 }
11214 \layout Standard
11215
11216 In the above example the parameter 
11217 \emph on 
11218 errcd
11219 \emph default 
11220  for the function 
11221 \emph on 
11222 set_error
11223 \emph default 
11224  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11225 nooverlay was
11226  not present, this could cause unpredictable runtime behavior when called
11227  from an interrupt service routine.
11228  The #pragma\SpecialChar ~
11229 nooverlay ensures that the parameters and local variables for
11230  the function are NOT overlayed.
11231 \layout Section
11232
11233 Interrupt Service Routines
11234 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11235
11236 \end_inset 
11237
11238
11239 \layout Subsection
11240
11241 General Information
11242 \layout Standard
11243
11244 SDCC allows 
11245 \emph on 
11246 i
11247 \emph default 
11248 nterrupt 
11249 \emph on 
11250 s
11251 \emph default 
11252 ervice 
11253 \emph on 
11254 r
11255 \emph default 
11256 outines to be coded in C, with some extended keywords.
11257 \layout Verse
11258
11259
11260 \family typewriter 
11261 void timer_isr (void) __interrupt (1) __using (1) 
11262 \newline 
11263
11264 \newline 
11265 \SpecialChar ~
11266 \SpecialChar ~
11267 \SpecialChar ~
11268 \SpecialChar ~
11269 ...
11270  
11271 \newline 
11272 }
11273 \layout Standard
11274
11275 The optional number following the 
11276 \emph on 
11277 interrupt
11278 \begin_inset LatexCommand \index{interrupt}
11279
11280 \end_inset 
11281
11282
11283 \begin_inset LatexCommand \index{\_\_interrupt}
11284
11285 \end_inset 
11286
11287
11288 \emph default 
11289  keyword is the interrupt number this routine will service.
11290  When present, the compiler will insert a call to this routine in the interrupt
11291  vector table for the interrupt number specified.
11292  If you have multiple source files in your project, interrupt service routines
11293  can be present in any of them, but a prototype of the isr MUST be present
11294  or included in the file that contains the function 
11295 \emph on 
11296 main
11297 \emph default 
11298 .
11299  The optional 
11300 \emph on 
11301 using
11302 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11303
11304 \end_inset 
11305
11306
11307 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11308
11309 \end_inset 
11310
11311
11312 \emph default 
11313  keyword can be used to tell the compiler to use the specified register
11314  bank (8051 specific) when generating code for this function.
11315  
11316 \newline 
11317
11318 \layout Standard
11319
11320 Interrupt service routines open the door for some very interesting bugs:
11321 \newline 
11322 If an interrupt service routine changes variables which are accessed by
11323  other functions these variables have to be declared 
11324 \emph on 
11325 volatile
11326 \emph default 
11327
11328 \begin_inset LatexCommand \index{volatile}
11329
11330 \end_inset 
11331
11332 .
11333  
11334 \layout Standard
11335
11336 If the access to these variables is not 
11337 \emph on 
11338 atomic
11339 \begin_inset LatexCommand \index{atomic}
11340
11341 \end_inset 
11342
11343
11344 \emph default 
11345  (i.e.
11346  the processor needs more than one instruction for the access and could
11347  be interrupted while accessing the variable) the interrupt must be disabled
11348  during the access to avoid inconsistent data.
11349  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
11350  and should be protected by disabling interrupts.
11351  You're not automatically on the safe side if you use 8 bit variables though.
11352  We need an example here: f.e.
11353  on the 8051 the harmless looking 
11354 \begin_inset Quotes srd
11355 \end_inset 
11356
11357
11358 \family typewriter 
11359 flags\SpecialChar ~
11360 |=\SpecialChar ~
11361 0x80;
11362 \family default 
11363
11364 \begin_inset Quotes sld
11365 \end_inset 
11366
11367  is not atomic if 
11368 \family typewriter 
11369 flags
11370 \family default 
11371  resides in xdata.
11372  Setting 
11373 \begin_inset Quotes srd
11374 \end_inset 
11375
11376
11377 \family typewriter 
11378 flags\SpecialChar ~
11379 |=\SpecialChar ~
11380 0x40;
11381 \family default 
11382
11383 \begin_inset Quotes sld
11384 \end_inset 
11385
11386  from within an interrupt routine might get lost if the interrupt occurs
11387  at the wrong time.
11388  
11389 \begin_inset Quotes sld
11390 \end_inset 
11391
11392
11393 \family typewriter 
11394 counter\SpecialChar ~
11395 +=\SpecialChar ~
11396 8;
11397 \family default 
11398
11399 \begin_inset Quotes srd
11400 \end_inset 
11401
11402  is not atomic on the 8051 even if 
11403 \family typewriter 
11404 counter
11405 \family default 
11406  is located in data memory.
11407  Bugs like these are hard to reproduce and can cause a lot of trouble.
11408  
11409 \layout Standard
11410
11411 The return address and the registers used in the interrupt service routine
11412  are saved on the stack
11413 \begin_inset LatexCommand \index{stack}
11414
11415 \end_inset 
11416
11417  so there must be sufficient stack space.
11418  If there isn't variables or registers (or even the return address itself)
11419  will be corrupted.
11420  This 
11421 \emph on 
11422 stack overflow
11423 \emph default 
11424
11425 \begin_inset LatexCommand \index{stack overflow}
11426
11427 \end_inset 
11428
11429  is most likely to happen if the interrupt occurs during the 
11430 \begin_inset Quotes sld
11431 \end_inset 
11432
11433 deepest
11434 \begin_inset Quotes srd
11435 \end_inset 
11436
11437  subroutine when the stack is already in use for f.e.
11438  many return addresses.
11439 \layout Standard
11440
11441 A special note here, int (16 bit) and long (32 bit) integer division
11442 \begin_inset LatexCommand \index{Division}
11443
11444 \end_inset 
11445
11446 , multiplication
11447 \begin_inset LatexCommand \index{Multiplication}
11448
11449 \end_inset 
11450
11451  & modulus
11452 \begin_inset LatexCommand \index{Modulus}
11453
11454 \end_inset 
11455
11456  and floating-point
11457 \begin_inset LatexCommand \index{Floating point support}
11458
11459 \end_inset 
11460
11461  operations are implemented using external support routines developed in
11462  ANSI-C.
11463  If an interrupt service routine needs to do any of these operations then
11464  the support routines (as mentioned in a following section) will have to
11465  be recompiled using the
11466 \emph on 
11467  -
11468 \begin_inset ERT
11469 status Collapsed
11470
11471 \layout Standard
11472
11473 \backslash 
11474 /
11475 \end_inset 
11476
11477 -stack-auto
11478 \begin_inset LatexCommand \index{-\/-stack-auto}
11479
11480 \end_inset 
11481
11482
11483 \emph default 
11484  option and the source file will need to be compiled using the 
11485 \emph on 
11486 -
11487 \begin_inset ERT
11488 status Collapsed
11489
11490 \layout Standard
11491
11492 \backslash 
11493 /
11494 \end_inset 
11495
11496 -int-long-reent
11497 \emph default 
11498
11499 \begin_inset LatexCommand \index{-\/-int-long-reent}
11500
11501 \end_inset 
11502
11503  compiler option.
11504  Note, the type promotion
11505 \begin_inset LatexCommand \index{type promotion}
11506
11507 \end_inset 
11508
11509  required by ANSI C can cause 16 bit routines to be used without the programmer
11510  being aware of it.
11511  
11512 \layout Standard
11513
11514 Calling other functions from an interrupt service routine is not recommended,
11515  avoid it if possible.
11516  Note that when some function is called from an interrupt service routine
11517  it should be preceded by a #pragma\SpecialChar ~
11518 nooverlay
11519 \begin_inset LatexCommand \index{\#pragma nooverlay}
11520
11521 \end_inset 
11522
11523  if it is not reentrant.
11524  Furthermore nonreentrant functions should not be called from the main program
11525  while the interrupt service routine might be active.
11526  They also must not be called from low priority interrupt service routines
11527  while a high priority interrupt service routine might be active.
11528  You could use semaphores or make the function
11529 \emph on 
11530  critical
11531 \emph default 
11532  if all parameters are passed in registers.
11533 \newline 
11534
11535 \newline 
11536 Also see section 
11537 \begin_inset LatexCommand \ref{sub:Overlaying}
11538
11539 \end_inset 
11540
11541 \SpecialChar ~
11542 about Overlaying and section 
11543 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11544
11545 \end_inset 
11546
11547 \SpecialChar ~
11548 about Functions using private register banks.
11549 \layout Subsection
11550
11551 MCS51/DS390 Interrupt Service Routines
11552 \layout Standard
11553
11554 Interrupt numbers and the corresponding address & descriptions for the Standard
11555  8051/8052 are listed below.
11556  SDCC will automatically adjust the interrupt vector table to the maximum
11557  interrupt number specified.
11558 \newline 
11559
11560 \layout Standard
11561 \align center 
11562
11563 \begin_inset  Tabular
11564 <lyxtabular version="3" rows="9" columns="3">
11565 <features>
11566 <column alignment="center" valignment="top" leftline="true" width="0in">
11567 <column alignment="left" valignment="top" leftline="true" width="0in">
11568 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
11569 <row topline="true" bottomline="true">
11570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11571 \begin_inset Text
11572
11573 \layout Standard
11574
11575 Interrupt #
11576 \end_inset 
11577 </cell>
11578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11579 \begin_inset Text
11580
11581 \layout Standard
11582
11583 Description
11584 \end_inset 
11585 </cell>
11586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11587 \begin_inset Text
11588
11589 \layout Standard
11590
11591 Vector Address
11592 \end_inset 
11593 </cell>
11594 </row>
11595 <row topline="true">
11596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11597 \begin_inset Text
11598
11599 \layout Standard
11600
11601 0
11602 \end_inset 
11603 </cell>
11604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11605 \begin_inset Text
11606
11607 \layout Standard
11608
11609 External 0
11610 \end_inset 
11611 </cell>
11612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11613 \begin_inset Text
11614
11615 \layout Standard
11616
11617 0x0003
11618 \end_inset 
11619 </cell>
11620 </row>
11621 <row topline="true">
11622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11623 \begin_inset Text
11624
11625 \layout Standard
11626
11627 1
11628 \end_inset 
11629 </cell>
11630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11631 \begin_inset Text
11632
11633 \layout Standard
11634
11635 Timer 0
11636 \end_inset 
11637 </cell>
11638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11639 \begin_inset Text
11640
11641 \layout Standard
11642
11643 0x000b
11644 \end_inset 
11645 </cell>
11646 </row>
11647 <row topline="true">
11648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11649 \begin_inset Text
11650
11651 \layout Standard
11652
11653 2
11654 \end_inset 
11655 </cell>
11656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11657 \begin_inset Text
11658
11659 \layout Standard
11660
11661 External 1
11662 \end_inset 
11663 </cell>
11664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11665 \begin_inset Text
11666
11667 \layout Standard
11668
11669 0x0013
11670 \end_inset 
11671 </cell>
11672 </row>
11673 <row topline="true">
11674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11675 \begin_inset Text
11676
11677 \layout Standard
11678
11679 3
11680 \end_inset 
11681 </cell>
11682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11683 \begin_inset Text
11684
11685 \layout Standard
11686
11687 Timer 1
11688 \end_inset 
11689 </cell>
11690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11691 \begin_inset Text
11692
11693 \layout Standard
11694
11695 0x001b
11696 \end_inset 
11697 </cell>
11698 </row>
11699 <row topline="true">
11700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11701 \begin_inset Text
11702
11703 \layout Standard
11704
11705 4
11706 \end_inset 
11707 </cell>
11708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11709 \begin_inset Text
11710
11711 \layout Standard
11712
11713 Serial
11714 \end_inset 
11715 </cell>
11716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11717 \begin_inset Text
11718
11719 \layout Standard
11720
11721 0x0023
11722 \end_inset 
11723 </cell>
11724 </row>
11725 <row topline="true">
11726 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11727 \begin_inset Text
11728
11729 \layout Standard
11730
11731 5
11732 \end_inset 
11733 </cell>
11734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11735 \begin_inset Text
11736
11737 \layout Standard
11738
11739 Timer 2 (8052)
11740 \end_inset 
11741 </cell>
11742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11743 \begin_inset Text
11744
11745 \layout Standard
11746
11747 0x002b
11748 \end_inset 
11749 </cell>
11750 </row>
11751 <row topline="true">
11752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11753 \begin_inset Text
11754
11755 \layout Standard
11756
11757 ...
11758 \end_inset 
11759 </cell>
11760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11761 \begin_inset Text
11762
11763 \layout Standard
11764
11765 \end_inset 
11766 </cell>
11767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11768 \begin_inset Text
11769
11770 \layout Standard
11771
11772 ...
11773 \end_inset 
11774 </cell>
11775 </row>
11776 <row topline="true" bottomline="true">
11777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11778 \begin_inset Text
11779
11780 \layout Standard
11781
11782 n
11783 \end_inset 
11784 </cell>
11785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11786 \begin_inset Text
11787
11788 \layout Standard
11789
11790 \end_inset 
11791 </cell>
11792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11793 \begin_inset Text
11794
11795 \layout Standard
11796
11797 0x0003 + 8*n
11798 \end_inset 
11799 </cell>
11800 </row>
11801 </lyxtabular>
11802
11803 \end_inset 
11804
11805
11806 \newline 
11807
11808 \layout Standard
11809
11810 If the interrupt service routine is defined without 
11811 \emph on 
11812 using
11813 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11814
11815 \end_inset 
11816
11817
11818 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11819
11820 \end_inset 
11821
11822
11823 \emph default 
11824  a register bank or with register bank 0 (
11825 \emph on 
11826 using
11827 \emph default 
11828  0), the compiler will save the registers used by itself on the stack upon
11829  entry and restore them at exit, however if such an interrupt service routine
11830  calls another function then the entire register bank will be saved on the
11831  stack.
11832  This scheme may be advantageous for small interrupt service routines which
11833  have low register usage.
11834 \layout Standard
11835
11836 If the interrupt service routine is defined to be using a specific register
11837  bank then only 
11838 \emph on 
11839 a, b, dptr
11840 \emph default 
11841  & psw are saved and restored, if such an interrupt service routine calls
11842  another function (using another register bank) then the entire register
11843  bank of the called function will be saved on the stack.
11844  This scheme is recommended for larger interrupt service routines.
11845 \layout Subsection
11846
11847 HC08 Interrupt Service Routines
11848 \layout Standard
11849
11850 Since the number of interrupts available is chip specific and the interrupt
11851  vector table always ends at the last byte of memory, the interrupt numbers
11852  corresponds to the interrupt vectors in reverse order of address.
11853  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
11854  2 will use the interrupt vector at 0xfffa, and so on.
11855  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
11856  this way; instead see section 
11857 \begin_inset LatexCommand \ref{sub:Startup-Code}
11858
11859 \end_inset 
11860
11861  for details on customizing startup.
11862 \layout Subsection
11863
11864 Z80 Interrupt Service Routines
11865 \layout Standard
11866
11867 The Z80 uses several different methods for determining the correct interrupt
11868  vector depending on the hardware implementation.
11869  Therefore, SDCC ignores the optional interrupt number and does not attempt
11870  to generate an interrupt vector table.
11871 \layout Standard
11872
11873 By default, SDCC generates code for a maskable interrupt, which uses a RETI
11874  instruction to return from the interrupt.
11875  To write an interrupt handler for the non-maskable interrupt, which needs
11876  a RETN instruction instead, add the 
11877 \emph on 
11878 critical
11879 \emph default 
11880  keyword:
11881 \layout Verse
11882
11883
11884 \family typewriter 
11885 void nmi_isr (void) critical interrupt
11886 \newline 
11887
11888 \newline 
11889 \SpecialChar ~
11890 \SpecialChar ~
11891 \SpecialChar ~
11892 \SpecialChar ~
11893 ...
11894  
11895 \newline 
11896 }
11897 \layout Standard
11898
11899 However if you need to create a non-interruptable interrupt service routine
11900  you would also require the 
11901 \emph on 
11902 critical
11903 \emph default 
11904  keyword.
11905  To distinguish between this and an nmi_isr you must provide an interrupt
11906  number.
11907 \layout Section
11908
11909 Enabling and Disabling Interrupts
11910 \layout Subsection
11911
11912 Critical Functions and Critical Statements
11913 \layout Standard
11914
11915 A special keyword may be associated with a block or a function declaring
11916  it as 
11917 \emph on 
11918 critical
11919 \emph default 
11920 .
11921  SDCC will generate code to disable all interrupts
11922 \begin_inset LatexCommand \index{interrupt}
11923
11924 \end_inset 
11925
11926  upon entry to a critical function and restore the interrupt enable to the
11927  previous state before returning.
11928  Nesting critical functions will need one additional byte on the stack
11929 \begin_inset LatexCommand \index{stack}
11930
11931 \end_inset 
11932
11933  for each call.
11934 \layout Verse
11935
11936
11937 \family typewriter 
11938 int foo () __critical
11939 \begin_inset LatexCommand \index{critical}
11940
11941 \end_inset 
11942
11943
11944 \begin_inset LatexCommand \index{\_\_critical}
11945
11946 \end_inset 
11947
11948  
11949 \newline 
11950
11951 \newline 
11952 \SpecialChar ~
11953 \SpecialChar ~
11954 \SpecialChar ~
11955 \SpecialChar ~
11956 ...
11957  
11958 \newline 
11959 \SpecialChar ~
11960 \SpecialChar ~
11961 \SpecialChar ~
11962 \SpecialChar ~
11963 ...
11964  
11965 \newline 
11966 }
11967 \layout Standard
11968
11969 The critical attribute maybe used with other attributes like 
11970 \emph on 
11971 reentrant.
11972 \emph default 
11973
11974 \newline 
11975 The keyword 
11976 \emph on 
11977 critical
11978 \emph default 
11979  may also be used to disable interrupts more locally:
11980 \layout Verse
11981
11982
11983 \family typewriter 
11984 __critical{ i++; }
11985 \layout Standard
11986
11987 More than one statement could have been included in the block.
11988 \layout Subsection
11989
11990 Enabling and Disabling Interrupts directly
11991 \layout Standard
11992
11993 Interrupts
11994 \begin_inset LatexCommand \index{interrupt}
11995
11996 \end_inset 
11997
11998  can also be disabled and enabled directly (8051):
11999 \layout Verse
12000
12001
12002 \family typewriter 
12003 EA = 0;\SpecialChar ~
12004 \SpecialChar ~
12005 \SpecialChar ~
12006 \SpecialChar ~
12007 \SpecialChar ~
12008 \SpecialChar ~
12009 \SpecialChar ~
12010 \SpecialChar ~
12011 \SpecialChar ~
12012 \SpecialChar ~
12013 \SpecialChar ~
12014 \SpecialChar ~
12015 or:\SpecialChar ~
12016 \SpecialChar ~
12017 \SpecialChar ~
12018 \SpecialChar ~
12019 \SpecialChar ~
12020 \SpecialChar ~
12021 \SpecialChar ~
12022 \SpecialChar ~
12023 \SpecialChar ~
12024 \SpecialChar ~
12025 \SpecialChar ~
12026 EA_SAVE = EA;
12027 \layout Verse
12028
12029
12030 \family typewriter 
12031 ...\SpecialChar ~
12032 \SpecialChar ~
12033 \SpecialChar ~
12034 \SpecialChar ~
12035 \SpecialChar ~
12036 \SpecialChar ~
12037 \SpecialChar ~
12038 \SpecialChar ~
12039 \SpecialChar ~
12040 \SpecialChar ~
12041 \SpecialChar ~
12042 \SpecialChar ~
12043 \SpecialChar ~
12044 \SpecialChar ~
12045 \SpecialChar ~
12046 \SpecialChar ~
12047 \SpecialChar ~
12048 \SpecialChar ~
12049 \SpecialChar ~
12050 \SpecialChar ~
12051 \SpecialChar ~
12052 \SpecialChar ~
12053 \SpecialChar ~
12054 \SpecialChar ~
12055 \SpecialChar ~
12056 \SpecialChar ~
12057 \SpecialChar ~
12058 \SpecialChar ~
12059 \SpecialChar ~
12060 \SpecialChar ~
12061 EA = 0;
12062 \layout Verse
12063
12064
12065 \family typewriter 
12066 EA = 1;\SpecialChar ~
12067 \SpecialChar ~
12068 \SpecialChar ~
12069 \SpecialChar ~
12070 \SpecialChar ~
12071 \SpecialChar ~
12072 \SpecialChar ~
12073 \SpecialChar ~
12074 \SpecialChar ~
12075 \SpecialChar ~
12076 \SpecialChar ~
12077 \SpecialChar ~
12078 \SpecialChar ~
12079 \SpecialChar ~
12080 \SpecialChar ~
12081 \SpecialChar ~
12082 \SpecialChar ~
12083 \SpecialChar ~
12084 \SpecialChar ~
12085 \SpecialChar ~
12086 \SpecialChar ~
12087 \SpecialChar ~
12088 \SpecialChar ~
12089 \SpecialChar ~
12090 \SpecialChar ~
12091 \SpecialChar ~
12092 ...
12093 \layout Verse
12094
12095
12096 \family typewriter 
12097 \SpecialChar ~
12098 \SpecialChar ~
12099 \SpecialChar ~
12100 \SpecialChar ~
12101 \SpecialChar ~
12102 \SpecialChar ~
12103 \SpecialChar ~
12104 \SpecialChar ~
12105 \SpecialChar ~
12106 \SpecialChar ~
12107 \SpecialChar ~
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 \SpecialChar ~
12111 \SpecialChar ~
12112 \SpecialChar ~
12113 \SpecialChar ~
12114 \SpecialChar ~
12115 \SpecialChar ~
12116 \SpecialChar ~
12117 \SpecialChar ~
12118 \SpecialChar ~
12119 \SpecialChar ~
12120 \SpecialChar ~
12121 \SpecialChar ~
12122 \SpecialChar ~
12123 \SpecialChar ~
12124 \SpecialChar ~
12125 \SpecialChar ~
12126 \SpecialChar ~
12127 \SpecialChar ~
12128 \SpecialChar ~
12129 \SpecialChar ~
12130 EA = EA_SAVE;
12131 \layout Standard
12132
12133 On other architectures which have seperate opcodes for enabling and disabling
12134  interrupts you might want to make use of defines with inline assembly
12135 \begin_inset LatexCommand \index{Assembler routines}
12136
12137 \end_inset 
12138
12139  (HC08):
12140 \layout Verse
12141
12142
12143 \family typewriter 
12144 #define CLI _asm
12145 \begin_inset LatexCommand \index{\_asm}
12146
12147 \end_inset 
12148
12149 \SpecialChar ~
12150 \SpecialChar ~
12151 cli\SpecialChar ~
12152 \SpecialChar ~
12153 _endasm
12154 \begin_inset LatexCommand \index{\_endasm}
12155
12156 \end_inset 
12157
12158
12159 \layout Verse
12160
12161
12162 \family typewriter 
12163 #define SEI _asm\SpecialChar ~
12164 \SpecialChar ~
12165 sei\SpecialChar ~
12166 \SpecialChar ~
12167 _endasm; 
12168 \layout Verse
12169
12170
12171 \family typewriter 
12172 ...
12173 \layout Standard
12174
12175 Note: it is sometimes sufficient to disable only a specific interrupt source
12176  like f.e.
12177  a timer or serial interrupt by manipulating an 
12178 \emph on 
12179 interrupt mask
12180 \begin_inset LatexCommand \index{interrupt mask}
12181
12182 \end_inset 
12183
12184
12185 \emph default 
12186  register.
12187  
12188 \layout Standard
12189
12190 Usually the time during which interrupts are disabled should be kept as
12191  short as possible.
12192  This minimizes both 
12193 \emph on 
12194 interrupt latency
12195 \emph default 
12196
12197 \begin_inset LatexCommand \index{interrupt latency}
12198
12199 \end_inset 
12200
12201  (the time between the occurrence of the interrupt and the execution of
12202  the first code in the interrupt routine) and 
12203 \emph on 
12204 interrupt jitter
12205 \emph default 
12206
12207 \begin_inset LatexCommand \index{interrupt jitter}
12208
12209 \end_inset 
12210
12211  (the difference between the shortest and the longest interrupt latency).
12212  These really are something different, f.e.
12213  a serial interrupt has to be served before its buffer overruns so it cares
12214  for the maximum interrupt latency, whereas it does not care about jitter.
12215  On a loudspeaker driven via a digital to analog converter which is fed
12216  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12217  a much smaller jitter will be very audible.
12218 \layout Standard
12219
12220 You can reenable interrupts within an interrupt routine and on some architecture
12221 s you can make use of two (or more) levels of 
12222 \emph on 
12223 interrupt priorities
12224 \emph default 
12225
12226 \begin_inset LatexCommand \index{interrupt priority}
12227
12228 \end_inset 
12229
12230 .
12231  On some architectures which don't support interrupt priorities these can
12232  be implemented by manipulating the interrupt mask and reenabling interrupts
12233  within the interrupt routine.
12234  Check there is sufficient space on the stack
12235 \begin_inset LatexCommand \index{stack}
12236
12237 \end_inset 
12238
12239  and don't add complexity unless you have to.
12240  
12241 \layout Subsection
12242
12243 Semaphore
12244 \begin_inset LatexCommand \index{semaphore}
12245
12246 \end_inset 
12247
12248  locking (mcs51/ds390)
12249 \layout Standard
12250
12251 Some architectures (mcs51/ds390) have an atomic
12252 \begin_inset LatexCommand \index{atomic}
12253
12254 \end_inset 
12255
12256  bit test and
12257 \emph on 
12258  
12259 \emph default 
12260 clear
12261 \emph on 
12262  
12263 \emph default 
12264 instruction.
12265  These type of instructions are typically used in preemptive multitasking
12266  systems, where a routine f.e.
12267  claims the use of a data structure ('acquires a lock
12268 \begin_inset LatexCommand \index{lock}
12269
12270 \end_inset 
12271
12272  on it'), makes some modifications and then releases the lock when the data
12273  structure is consistent again.
12274  The instruction may also be used if interrupt and non-interrupt code have
12275  to compete for a resource.
12276  With the atomic bit test and clear instruction interrupts
12277 \begin_inset LatexCommand \index{interrupt}
12278
12279 \end_inset 
12280
12281  don't have to be disabled for the locking operation.
12282  
12283 \layout Standard
12284
12285 SDCC generates this instruction if the source follows this pattern:
12286 \layout Verse
12287
12288
12289 \family typewriter 
12290 volatile
12291 \begin_inset LatexCommand \index{volatile}
12292
12293 \end_inset 
12294
12295  bit resource_is_free; 
12296 \newline 
12297
12298 \newline 
12299 if (resource_is_free) 
12300 \newline 
12301 \SpecialChar ~
12302 \SpecialChar ~
12303
12304 \newline 
12305 \SpecialChar ~
12306 \SpecialChar ~
12307 \SpecialChar ~
12308 \SpecialChar ~
12309 resource_is_free=0; 
12310 \newline 
12311 \SpecialChar ~
12312 \SpecialChar ~
12313 \SpecialChar ~
12314 \SpecialChar ~
12315 ...
12316  
12317 \newline 
12318 \SpecialChar ~
12319 \SpecialChar ~
12320 \SpecialChar ~
12321 \SpecialChar ~
12322 resource_is_free=1;
12323 \newline 
12324 \SpecialChar ~
12325 \SpecialChar ~
12326
12327 \layout Standard
12328
12329 Note, mcs51 and ds390 support only an atomic
12330 \begin_inset LatexCommand \index{atomic}
12331
12332 \end_inset 
12333
12334  bit test and 
12335 \emph on 
12336 clear
12337 \emph default 
12338  instruction (as opposed to atomic bit test and 
12339 \emph on 
12340 set).
12341 \layout Section
12342
12343 Functions using private register banks
12344 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12345
12346 \end_inset 
12347
12348  (mcs51/ds390)
12349 \layout Standard
12350
12351 Some architectures have support for quickly changing register sets.
12352  SDCC supports this feature with the 
12353 \emph on 
12354 using
12355 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12356
12357 \end_inset 
12358
12359
12360 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12361
12362 \end_inset 
12363
12364
12365 \emph default 
12366  attribute (which tells the compiler to use a register bank
12367 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12368
12369 \end_inset 
12370
12371  other than the default bank zero).
12372  It should only be applied to 
12373 \emph on 
12374 interrupt
12375 \begin_inset LatexCommand \index{interrupt}
12376
12377 \end_inset 
12378
12379
12380 \emph default 
12381  functions (see footnote below).
12382  This will in most circumstances make the generated ISR code more efficient
12383  since it will not have to save registers on the stack.
12384 \layout Standard
12385
12386 The 
12387 \emph on 
12388 using
12389 \emph default 
12390  attribute will have no effect on the generated code for a 
12391 \emph on 
12392 non-interrupt
12393 \emph default 
12394  function (but may occasionally be useful anyway
12395 \begin_inset Foot
12396 collapsed false
12397
12398 \layout Standard
12399
12400 possible exception: if a function is called ONLY from 'interrupt' functions
12401  using a particular bank, it can be declared with the same 'using' attribute
12402  as the calling 'interrupt' functions.
12403  For instance, if you have several ISRs using bank one, and all of them
12404  call memcpy(), it might make sense to create a specialized version of memcpy()
12405  'using 1', since this would prevent the ISR from having to save bank zero
12406  to the stack on entry and switch to bank zero before calling the function
12407 \end_inset 
12408
12409 ).
12410 \newline 
12411
12412 \emph on 
12413 (pending: I don't think this has been done yet)
12414 \layout Standard
12415
12416 An 
12417 \emph on 
12418 interrupt
12419 \emph default 
12420  function using a non-zero bank will assume that it can trash that register
12421  bank, and will not save it.
12422  Since high-priority interrupts
12423 \begin_inset LatexCommand \index{interrupts}
12424
12425 \end_inset 
12426
12427
12428 \begin_inset LatexCommand \index{interrupt priority}
12429
12430 \end_inset 
12431
12432  can interrupt low-priority ones on the 8051 and friends, this means that
12433  if a high-priority ISR 
12434 \emph on 
12435 using
12436 \emph default 
12437  a particular bank occurs while processing a low-priority ISR 
12438 \emph on 
12439 using
12440 \emph default 
12441  the same bank, terrible and bad things can happen.
12442  To prevent this, no single register bank should be 
12443 \emph on 
12444 used
12445 \emph default 
12446  by both a high priority and a low priority ISR.
12447  This is probably most easily done by having all high priority ISRs use
12448  one bank and all low priority ISRs use another.
12449  If you have an ISR which can change priority at runtime, you're on your
12450  own: I suggest using the default bank zero and taking the small performance
12451  hit.
12452 \layout Standard
12453
12454 It is most efficient if your ISR calls no other functions.
12455  If your ISR must call other functions, it is most efficient if those functions
12456  use the same bank as the ISR (see note 1 below); the next best is if the
12457  called functions use bank zero.
12458  It is very inefficient to call a function using a different, non-zero bank
12459  from an ISR.
12460  
12461 \layout Section
12462
12463 Startup Code
12464 \begin_inset LatexCommand \label{sub:Startup-Code}
12465
12466 \end_inset 
12467
12468
12469 \begin_inset LatexCommand \index{Startup code}
12470
12471 \end_inset 
12472
12473
12474 \layout Subsection
12475
12476 MCS51/DS390 Startup Code
12477 \layout Standard
12478
12479 The compiler inserts a call to the C routine 
12480 \emph on 
12481 _sdcc_external_startup()
12482 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12483
12484 \end_inset 
12485
12486
12487 \series bold 
12488 \emph default 
12489  
12490 \series default 
12491 at the start of the CODE area.
12492  This routine is in the runtime library
12493 \begin_inset LatexCommand \index{Runtime library}
12494
12495 \end_inset 
12496
12497 .
12498  By default this routine returns 0, if this routine returns a non-zero value,
12499  the static & global variable initialization will be skipped and the function
12500  main will be invoked.
12501  Otherwise static & global variables will be initialized before the function
12502  main is invoked.
12503  You could add a 
12504 \emph on 
12505 _sdcc_external_startup()
12506 \emph default 
12507  routine to your program to override the default if you need to setup hardware
12508  or perform some other critical operation prior to static & global variable
12509  initialization
12510 \begin_inset LatexCommand \index{Variable initialization}
12511
12512 \end_inset 
12513
12514 .
12515  On some mcs51 variants xdata
12516 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12517
12518 \end_inset 
12519
12520  memory has to be explicitly enabled before it can be accessed or if the
12521  watchdog needs to be disabled, this is the place to do it.
12522  The startup code clears all internal data memory, 256 bytes by default,
12523  but from 0 to n-1 if 
12524 \emph on 
12525 -
12526 \begin_inset ERT
12527 status Collapsed
12528
12529 \layout Standard
12530
12531 \backslash 
12532 /
12533 \end_inset 
12534
12535 -iram-size
12536 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12537
12538 \end_inset 
12539
12540 n
12541 \emph default 
12542  is used.
12543  (recommended for Chipcon CC1010).
12544 \layout Standard
12545
12546 See also the compiler option 
12547 \emph on 
12548 -
12549 \begin_inset ERT
12550 status Collapsed
12551
12552 \layout Standard
12553
12554 \backslash 
12555 /
12556 \end_inset 
12557
12558 -no-xinit
12559 \emph default 
12560 -
12561 \emph on 
12562 opt
12563 \emph default 
12564
12565 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
12566
12567 \end_inset 
12568
12569  and section 
12570 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12571
12572 \end_inset 
12573
12574 \SpecialChar ~
12575 about MCS51-variants.
12576 \layout Subsection
12577
12578 HC08 Startup Code
12579 \layout Standard
12580
12581 The HC08 startup code follows the same scheme as the MCS51 startup code.
12582 \layout Subsection
12583
12584 Z80 Startup Code
12585 \layout Standard
12586
12587 On the Z80 the startup code is inserted by linking with crt0.o which is generated
12588  from sdcc/device/lib/z80/crt0.s.
12589  If you need a different startup code you can use the compiler option 
12590 \emph on 
12591 -
12592 \series bold 
12593 \emph default 
12594
12595 \begin_inset ERT
12596 status Collapsed
12597
12598 \layout Standard
12599
12600 \backslash 
12601 /
12602 \end_inset 
12603
12604
12605 \series default 
12606 \emph on 
12607 -no-std-crt0
12608 \emph default 
12609
12610 \begin_inset LatexCommand \index{-\/-no-std-crt0}
12611
12612 \end_inset 
12613
12614  and provide your own crt0.o.
12615  
12616 \layout Section
12617
12618 Inline Assembler Code
12619 \begin_inset LatexCommand \index{Assembler routines}
12620
12621 \end_inset 
12622
12623
12624 \layout Subsection
12625
12626 A Step by Step Introduction
12627 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
12628
12629 \end_inset 
12630
12631
12632 \layout Standard
12633
12634 Starting from a small snippet of c-code this example shows for the MCS51
12635  how to use inline assembly, access variables, a function parameter and
12636  an array in xdata memory.
12637  The example uses an MCS51 here but is easily adapted for other architectures.
12638  This is a buffer routine which should be optimized:
12639 \layout Verse
12640
12641
12642 \family typewriter 
12643 \size footnotesize 
12644 unsigned char __far
12645 \begin_inset LatexCommand \index{far (storage class)}
12646
12647 \end_inset 
12648
12649
12650 \begin_inset LatexCommand \index{\_\_far (storage class)}
12651
12652 \end_inset 
12653
12654  __at
12655 \begin_inset LatexCommand \index{at}
12656
12657 \end_inset 
12658
12659
12660 \begin_inset LatexCommand \index{\_\_at}
12661
12662 \end_inset 
12663
12664 (0x7f00) buf[0x100];
12665 \begin_inset LatexCommand \index{Aligned array}
12666
12667 \end_inset 
12668
12669
12670 \newline 
12671 unsigned char head, tail;
12672 \newline 
12673
12674 \newline 
12675 void to_buffer( unsigned char c ) 
12676 \newline 
12677 {
12678 \newline 
12679 \SpecialChar ~
12680 \SpecialChar ~
12681 \SpecialChar ~
12682 \SpecialChar ~
12683 if( head != (unsigned char)(tail-1) )\SpecialChar ~
12684 /* cast 
12685 \series bold 
12686 needed
12687 \series default 
12688  to avoid promotion
12689 \begin_inset LatexCommand \index{promotion to signed int}
12690
12691 \end_inset 
12692
12693
12694 \begin_inset LatexCommand \index{type promotion}
12695
12696 \end_inset 
12697
12698  to integer */
12699 \begin_inset Marginal
12700 collapsed false
12701
12702 \layout Standard
12703
12704
12705 \series bold 
12706 \SpecialChar ~
12707 !
12708 \end_inset 
12709
12710
12711 \newline 
12712 \SpecialChar ~
12713 \SpecialChar ~
12714 \SpecialChar ~
12715 \SpecialChar ~
12716 \SpecialChar ~
12717 \SpecialChar ~
12718 \SpecialChar ~
12719 \SpecialChar ~
12720 buf[ head++ ] = c;\SpecialChar ~
12721 \SpecialChar ~
12722 \SpecialChar ~
12723 \SpecialChar ~
12724 \SpecialChar ~
12725 \SpecialChar ~
12726 \SpecialChar ~
12727 \SpecialChar ~
12728 \SpecialChar ~
12729 \SpecialChar ~
12730 \SpecialChar ~
12731 \SpecialChar ~
12732 \SpecialChar ~
12733 \SpecialChar ~
12734 \SpecialChar ~
12735 \SpecialChar ~
12736 /* access to a 256 byte aligned array */
12737 \newline 
12738
12739 \layout Standard
12740
12741 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
12742  then a corresponding buffer.asm file is generated.
12743  We define a new function 
12744 \family typewriter 
12745 to_buffer_asm()
12746 \family default 
12747  in file buffer.c in which we cut and paste the generated code, removing
12748  unwanted comments and some ':'.
12749  Then add 
12750 \begin_inset Quotes sld
12751 \end_inset 
12752
12753 _asm
12754 \begin_inset Quotes srd
12755 \end_inset 
12756
12757  and 
12758 \begin_inset Quotes sld
12759 \end_inset 
12760
12761 _endasm;
12762 \begin_inset Quotes srd
12763 \end_inset 
12764
12765  to the beginning and the end of the function body:
12766 \layout Verse
12767
12768
12769 \family typewriter 
12770 \size footnotesize 
12771 /* With a cut and paste from the .asm file, we have something to start with.
12772 \newline 
12773 \SpecialChar ~
12774 \SpecialChar ~
12775 \SpecialChar ~
12776 The function is not yet OK! (registers aren't saved) */ 
12777 \newline 
12778 void to_buffer_asm( unsigned char c ) 
12779 \newline 
12780
12781 \newline 
12782 \SpecialChar ~
12783 \SpecialChar ~
12784 \SpecialChar ~
12785 \SpecialChar ~
12786 _asm
12787 \begin_inset LatexCommand \index{\_asm}
12788
12789 \end_inset 
12790
12791
12792 \begin_inset LatexCommand \index{\_\_asm}
12793
12794 \end_inset 
12795
12796
12797 \newline 
12798 \SpecialChar ~
12799 \SpecialChar ~
12800 \SpecialChar ~
12801 \SpecialChar ~
12802 mov\SpecialChar ~
12803 \SpecialChar ~
12804 r2,dpl 
12805 \newline 
12806 ;buffer.c if( head != (unsigned char)(tail-1) ) 
12807 \newline 
12808 \SpecialChar ~
12809 \SpecialChar ~
12810 \SpecialChar ~
12811 \SpecialChar ~
12812 mov\SpecialChar ~
12813 \SpecialChar ~
12814 a,_tail 
12815 \newline 
12816 \SpecialChar ~
12817 \SpecialChar ~
12818 \SpecialChar ~
12819 \SpecialChar ~
12820 dec\SpecialChar ~
12821 \SpecialChar ~
12822
12823 \newline 
12824 \SpecialChar ~
12825 \SpecialChar ~
12826 \SpecialChar ~
12827 \SpecialChar ~
12828 mov\SpecialChar ~
12829 \SpecialChar ~
12830 r3,a 
12831 \newline 
12832 \SpecialChar ~
12833 \SpecialChar ~
12834 \SpecialChar ~
12835 \SpecialChar ~
12836 mov\SpecialChar ~
12837 \SpecialChar ~
12838 a,_head 
12839 \newline 
12840 \SpecialChar ~
12841 \SpecialChar ~
12842 \SpecialChar ~
12843 \SpecialChar ~
12844 cjne a,ar3,00106$ 
12845 \newline 
12846 \SpecialChar ~
12847 \SpecialChar ~
12848 \SpecialChar ~
12849 \SpecialChar ~
12850 ret
12851 \newline 
12852 00106$: 
12853 \newline 
12854 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
12855 \begin_inset LatexCommand \index{Aligned array}
12856
12857 \end_inset 
12858
12859
12860 \newline 
12861 \SpecialChar ~
12862 \SpecialChar ~
12863 \SpecialChar ~
12864 \SpecialChar ~
12865 mov\SpecialChar ~
12866 \SpecialChar ~
12867 r3,_head 
12868 \newline 
12869 \SpecialChar ~
12870 \SpecialChar ~
12871 \SpecialChar ~
12872 \SpecialChar ~
12873 inc\SpecialChar ~
12874 \SpecialChar ~
12875 _head 
12876 \newline 
12877 \SpecialChar ~
12878 \SpecialChar ~
12879 \SpecialChar ~
12880 \SpecialChar ~
12881 mov\SpecialChar ~
12882 \SpecialChar ~
12883 dpl,r3 
12884 \newline 
12885 \SpecialChar ~
12886 \SpecialChar ~
12887 \SpecialChar ~
12888 \SpecialChar ~
12889 mov\SpecialChar ~
12890 \SpecialChar ~
12891 dph,#(_buf >> 8) 
12892 \newline 
12893 \SpecialChar ~
12894 \SpecialChar ~
12895 \SpecialChar ~
12896 \SpecialChar ~
12897 mov\SpecialChar ~
12898 \SpecialChar ~
12899 a,r2 
12900 \newline 
12901 \SpecialChar ~
12902 \SpecialChar ~
12903 \SpecialChar ~
12904 \SpecialChar ~
12905 movx @dptr,a 
12906 \newline 
12907 00103$: 
12908 \newline 
12909 \SpecialChar ~
12910 \SpecialChar ~
12911 \SpecialChar ~
12912 \SpecialChar ~
12913 ret
12914 \newline 
12915 \SpecialChar ~
12916 \SpecialChar ~
12917 \SpecialChar ~
12918 \SpecialChar ~
12919 _endasm
12920 \begin_inset LatexCommand \index{\_endasm}
12921
12922 \end_inset 
12923
12924
12925 \begin_inset LatexCommand \index{\_\_endasm}
12926
12927 \end_inset 
12928
12929 ;
12930 \newline 
12931
12932 \layout Standard
12933
12934 The new file buffer.c should compile with only one warning about the unreferenced
12935  function argument 'c'.
12936  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
12937  (1) and finally have:
12938 \layout Verse
12939
12940
12941 \family typewriter 
12942 \size footnotesize 
12943 unsigned char __far __at(0x7f00) buf[0x100];
12944 \newline 
12945 unsigned char head, tail;
12946 \newline 
12947 #define USE_ASSEMBLY (1)
12948 \newline 
12949
12950 \newline 
12951 #if !USE_ASSEMBLY
12952 \newline 
12953
12954 \newline 
12955 void to_buffer( unsigned char c )
12956 \newline 
12957 {
12958 \newline 
12959 \SpecialChar ~
12960 \SpecialChar ~
12961 \SpecialChar ~
12962 \SpecialChar ~
12963 if( head != (unsigned char)(tail-1) )
12964 \newline 
12965 \SpecialChar ~
12966 \SpecialChar ~
12967 \SpecialChar ~
12968 \SpecialChar ~
12969 \SpecialChar ~
12970 \SpecialChar ~
12971 \SpecialChar ~
12972 \SpecialChar ~
12973 buf[ head++ ] = c;
12974 \newline 
12975 }
12976 \newline 
12977
12978 \newline 
12979 #else
12980 \newline 
12981
12982 \newline 
12983 void to_buffer( unsigned char c )
12984 \newline 
12985 {
12986 \newline 
12987 \SpecialChar ~
12988 \SpecialChar ~
12989 \SpecialChar ~
12990 \SpecialChar ~
12991 c; // to avoid warning: unreferenced function argument
12992 \newline 
12993 \SpecialChar ~
12994 \SpecialChar ~
12995 \SpecialChar ~
12996 \SpecialChar ~
12997 _asm
12998 \begin_inset LatexCommand \index{\_asm}
12999
13000 \end_inset 
13001
13002
13003 \begin_inset LatexCommand \index{\_\_asm}
13004
13005 \end_inset 
13006
13007
13008 \newline 
13009 \SpecialChar ~
13010 \SpecialChar ~
13011 \SpecialChar ~
13012 \SpecialChar ~
13013 \SpecialChar ~
13014 \SpecialChar ~
13015 \SpecialChar ~
13016 \SpecialChar ~
13017 ; save used registers here.
13018  
13019 \newline 
13020 \SpecialChar ~
13021 \SpecialChar ~
13022 \SpecialChar ~
13023 \SpecialChar ~
13024 \SpecialChar ~
13025 \SpecialChar ~
13026 \SpecialChar ~
13027 \SpecialChar ~
13028 ; If we were still using r2,r3 we would have to push them here.
13029  
13030 \newline 
13031 ; if( head != (unsigned char)(tail-1) )
13032 \newline 
13033 \SpecialChar ~
13034 \SpecialChar ~
13035 \SpecialChar ~
13036 \SpecialChar ~
13037 \SpecialChar ~
13038 \SpecialChar ~
13039 \SpecialChar ~
13040 \SpecialChar ~
13041 mov\SpecialChar ~
13042  a,_tail
13043 \newline 
13044 \SpecialChar ~
13045 \SpecialChar ~
13046 \SpecialChar ~
13047 \SpecialChar ~
13048 \SpecialChar ~
13049 \SpecialChar ~
13050 \SpecialChar ~
13051 \SpecialChar ~
13052 dec\SpecialChar ~
13053  a
13054 \newline 
13055 \SpecialChar ~
13056 \SpecialChar ~
13057 \SpecialChar ~
13058 \SpecialChar ~
13059 \SpecialChar ~
13060 \SpecialChar ~
13061 \SpecialChar ~
13062 \SpecialChar ~
13063 xrl\SpecialChar ~
13064  a,_head
13065 \newline 
13066 \SpecialChar ~
13067 \SpecialChar ~
13068 \SpecialChar ~
13069 \SpecialChar ~
13070 \SpecialChar ~
13071 \SpecialChar ~
13072 \SpecialChar ~
13073 \SpecialChar ~
13074 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13075 \newline 
13076 \SpecialChar ~
13077 \SpecialChar ~
13078 \SpecialChar ~
13079 \SpecialChar ~
13080 \SpecialChar ~
13081 \SpecialChar ~
13082 \SpecialChar ~
13083 \SpecialChar ~
13084 jz\SpecialChar ~
13085 \SpecialChar ~
13086  t_b_end$
13087 \newline 
13088 \SpecialChar ~
13089 \SpecialChar ~
13090 \SpecialChar ~
13091 \SpecialChar ~
13092 \SpecialChar ~
13093 \SpecialChar ~
13094 \SpecialChar ~
13095 \SpecialChar ~
13096 ;
13097 \newline 
13098 ; buf[ head++ ] = c;
13099 \newline 
13100 \SpecialChar ~
13101 \SpecialChar ~
13102 \SpecialChar ~
13103 \SpecialChar ~
13104 \SpecialChar ~
13105 \SpecialChar ~
13106 \SpecialChar ~
13107 \SpecialChar ~
13108 mov\SpecialChar ~
13109  a,dpl \SpecialChar ~
13110 \SpecialChar ~
13111 \SpecialChar ~
13112 \SpecialChar ~
13113 \SpecialChar ~
13114 \SpecialChar ~
13115 \SpecialChar ~
13116 ; dpl holds lower byte of function argument
13117 \newline 
13118 \SpecialChar ~
13119 \SpecialChar ~
13120 \SpecialChar ~
13121 \SpecialChar ~
13122 \SpecialChar ~
13123 \SpecialChar ~
13124 \SpecialChar ~
13125 \SpecialChar ~
13126 mov\SpecialChar ~
13127  dpl,_head \SpecialChar ~
13128 \SpecialChar ~
13129 \SpecialChar ~
13130 ; buf is 0x100 byte aligned so head can be used directly
13131 \newline 
13132 \SpecialChar ~
13133 \SpecialChar ~
13134 \SpecialChar ~
13135 \SpecialChar ~
13136 \SpecialChar ~
13137 \SpecialChar ~
13138 \SpecialChar ~
13139 \SpecialChar ~
13140 mov\SpecialChar ~
13141  dph,#(_buf>>8)
13142 \newline 
13143 \SpecialChar ~
13144 \SpecialChar ~
13145 \SpecialChar ~
13146 \SpecialChar ~
13147 \SpecialChar ~
13148 \SpecialChar ~
13149 \SpecialChar ~
13150 \SpecialChar ~
13151 movx @dptr,a
13152 \newline 
13153 \SpecialChar ~
13154 \SpecialChar ~
13155 \SpecialChar ~
13156 \SpecialChar ~
13157 \SpecialChar ~
13158 \SpecialChar ~
13159 \SpecialChar ~
13160 \SpecialChar ~
13161 inc \SpecialChar ~
13162 _head
13163 \newline 
13164 \SpecialChar ~
13165 \SpecialChar ~
13166 \SpecialChar ~
13167 \SpecialChar ~
13168 \SpecialChar ~
13169 \SpecialChar ~
13170 \SpecialChar ~
13171 \SpecialChar ~
13172 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13173 \newline 
13174 t_b_end$:
13175 \newline 
13176 \SpecialChar ~
13177 \SpecialChar ~
13178 \SpecialChar ~
13179 \SpecialChar ~
13180 \SpecialChar ~
13181 \SpecialChar ~
13182 \SpecialChar ~
13183 \SpecialChar ~
13184 ; restore used registers here 
13185 \newline 
13186 \SpecialChar ~
13187 \SpecialChar ~
13188 \SpecialChar ~
13189 \SpecialChar ~
13190 _endasm
13191 \begin_inset LatexCommand \index{\_endasm}
13192
13193 \end_inset 
13194
13195
13196 \begin_inset LatexCommand \index{\_\_endasm}
13197
13198 \end_inset 
13199
13200 ;
13201 \newline 
13202 }
13203 \newline 
13204 #endif
13205 \layout Standard
13206
13207 The inline assembler code can contain any valid code understood by the assembler
13208 , this includes any assembler directives and comment lines
13209 \begin_inset Foot
13210 collapsed false
13211
13212 \layout Standard
13213
13214 The assembler does not like some characters like ':' or ''' in comments.
13215  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13216 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13217
13218 \end_inset 
13219
13220
13221 \begin_inset LatexCommand \index{Assembler documentation}
13222
13223 \end_inset 
13224
13225
13226 \end_inset 
13227
13228 .
13229  The compiler does not do any validation of the code within the 
13230 \family typewriter 
13231 _asm
13232 \begin_inset LatexCommand \index{\_asm}
13233
13234 \end_inset 
13235
13236
13237 \begin_inset LatexCommand \index{\_\_asm}
13238
13239 \end_inset 
13240
13241  ...
13242  _endasm
13243 \size footnotesize 
13244
13245 \begin_inset LatexCommand \index{\_endasm}
13246
13247 \end_inset 
13248
13249
13250 \begin_inset LatexCommand \index{\_\_endasm}
13251
13252 \end_inset 
13253
13254
13255 \size default 
13256 ;
13257 \family default 
13258  keyword pair.
13259  Specifically it will not know which registers are used and thus register
13260  pushing/popping
13261 \begin_inset LatexCommand \index{push/pop}
13262
13263 \end_inset 
13264
13265  has to be done manually.
13266  
13267 \layout Standard
13268
13269 It is recommended that each assembly instruction (including labels) be placed
13270  in a separate line (as the example shows).
13271  When the -
13272 \begin_inset ERT
13273 status Collapsed
13274
13275 \layout Standard
13276
13277 \backslash 
13278 /
13279 \end_inset 
13280
13281 -
13282 \emph on 
13283 peep-asm
13284 \begin_inset LatexCommand \index{-\/-peep-asm}
13285
13286 \end_inset 
13287
13288
13289 \emph default 
13290  command line option is used, the inline assembler code will be passed through
13291  the peephole optimizer
13292 \begin_inset LatexCommand \index{Peephole optimizer}
13293
13294 \end_inset 
13295
13296 .
13297  There are only a few (if any) cases where this option makes sense, it might
13298  cause some unexpected changes in the inline assembler code.
13299  Please go through the peephole optimizer rules defined in file 
13300 \emph on 
13301 SDCCpeeph.def
13302 \emph default 
13303  before using this option.
13304 \layout Subsection
13305
13306 Naked Functions
13307 \begin_inset LatexCommand \label{sub:Naked-Functions}
13308
13309 \end_inset 
13310
13311
13312 \begin_inset LatexCommand \index{Naked functions}
13313
13314 \end_inset 
13315
13316
13317 \layout Standard
13318
13319 A special keyword may be associated with a function declaring it as 
13320 \emph on 
13321 _naked
13322 \begin_inset LatexCommand \index{\_naked}
13323
13324 \end_inset 
13325
13326
13327 \begin_inset LatexCommand \index{\_\_naked}
13328
13329 \end_inset 
13330
13331 .
13332  
13333 \emph default 
13334 The 
13335 \emph on 
13336 _naked
13337 \emph default 
13338  function modifier attribute prevents the compiler from generating prologue
13339 \begin_inset LatexCommand \index{function prologue}
13340
13341 \end_inset 
13342
13343  and epilogue
13344 \begin_inset LatexCommand \index{function epilogue}
13345
13346 \end_inset 
13347
13348  code for that function.
13349  This means that the user is entirely responsible for such things as saving
13350  any registers that may need to be preserved, selecting the proper register
13351  bank, generating the 
13352 \emph on 
13353 return
13354 \emph default 
13355  instruction at the end, etc.
13356  Practically, this means that the contents of the function must be written
13357  in inline assembler.
13358  This is particularly useful for interrupt functions, which can have a large
13359  (and often unnecessary) prologue/epilogue.
13360  For example, compare the code generated by these two functions:
13361 \layout Verse
13362
13363
13364 \family typewriter 
13365 volatile
13366 \begin_inset LatexCommand \index{volatile}
13367
13368 \end_inset 
13369
13370  data unsigned char counter;
13371 \newline 
13372
13373 \newline 
13374 void simpleInterrupt(void) __interrupt
13375 \begin_inset LatexCommand \index{interrupt}
13376
13377 \end_inset 
13378
13379
13380 \begin_inset LatexCommand \index{\_\_interrupt}
13381
13382 \end_inset 
13383
13384  (1)
13385 \newline 
13386 {
13387 \newline 
13388 \SpecialChar ~
13389 \SpecialChar ~
13390 \SpecialChar ~
13391 \SpecialChar ~
13392 counter++;
13393 \newline 
13394 }
13395 \newline 
13396
13397 \newline 
13398 void nakedInterrupt(void) __interrupt (2) __naked
13399 \newline 
13400 {
13401 \newline 
13402 \SpecialChar ~
13403 \SpecialChar ~
13404 \SpecialChar ~
13405 \SpecialChar ~
13406 _asm
13407 \begin_inset LatexCommand \index{\_asm}
13408
13409 \end_inset 
13410
13411
13412 \begin_inset LatexCommand \index{\_\_asm}
13413
13414 \end_inset 
13415
13416
13417 \newline 
13418 \SpecialChar ~
13419 \SpecialChar ~
13420 \SpecialChar ~
13421 \SpecialChar ~
13422 \SpecialChar ~
13423 \SpecialChar ~
13424 inc\SpecialChar ~
13425 \SpecialChar ~
13426 \SpecialChar ~
13427 \SpecialChar ~
13428 \SpecialChar ~
13429 _counter ; does not change flags, no need to save psw
13430 \newline 
13431 \SpecialChar ~
13432 \SpecialChar ~
13433 \SpecialChar ~
13434 \SpecialChar ~
13435 \SpecialChar ~
13436 \SpecialChar ~
13437 reti\SpecialChar ~
13438 \SpecialChar ~
13439 \SpecialChar ~
13440 \SpecialChar ~
13441 ; MUST explicitly include ret or reti in _naked function.
13442 \newline 
13443 \SpecialChar ~
13444 \SpecialChar ~
13445 \SpecialChar ~
13446 \SpecialChar ~
13447 _endasm
13448 \begin_inset LatexCommand \index{\_endasm}
13449
13450 \end_inset 
13451
13452
13453 \begin_inset LatexCommand \index{\_\_endasm}
13454
13455 \end_inset 
13456
13457 ;
13458 \newline 
13459 }
13460 \layout Standard
13461
13462 For an 8051 target, the generated simpleInterrupt looks like:
13463 \layout Verse
13464
13465
13466 \family typewriter 
13467 Note, this is an 
13468 \series bold 
13469 outdated
13470 \series default 
13471  example, recent versions of SDCC generate
13472 \newline 
13473 the same code for simpleInterrupt() and nakedInterrupt()!
13474 \newline 
13475
13476 \newline 
13477 _simpleInterrupt:
13478 \newline 
13479 \SpecialChar ~
13480 \SpecialChar ~
13481 \SpecialChar ~
13482 \SpecialChar ~
13483 push\SpecialChar ~
13484 \SpecialChar ~
13485 \SpecialChar ~
13486 \SpecialChar ~
13487 acc
13488 \newline 
13489 \SpecialChar ~
13490 \SpecialChar ~
13491 \SpecialChar ~
13492 \SpecialChar ~
13493 push\SpecialChar ~
13494 \SpecialChar ~
13495 \SpecialChar ~
13496 \SpecialChar ~
13497 b
13498 \newline 
13499 \SpecialChar ~
13500 \SpecialChar ~
13501 \SpecialChar ~
13502 \SpecialChar ~
13503 push\SpecialChar ~
13504 \SpecialChar ~
13505 \SpecialChar ~
13506 \SpecialChar ~
13507 dpl
13508 \newline 
13509 \SpecialChar ~
13510 \SpecialChar ~
13511 \SpecialChar ~
13512 \SpecialChar ~
13513 push\SpecialChar ~
13514 \SpecialChar ~
13515 \SpecialChar ~
13516 \SpecialChar ~
13517 dph
13518 \newline 
13519 \SpecialChar ~
13520 \SpecialChar ~
13521 \SpecialChar ~
13522 \SpecialChar ~
13523 push\SpecialChar ~
13524 \SpecialChar ~
13525 \SpecialChar ~
13526 \SpecialChar ~
13527 psw
13528 \newline 
13529 \SpecialChar ~
13530 \SpecialChar ~
13531 \SpecialChar ~
13532 \SpecialChar ~
13533 mov\SpecialChar ~
13534 \SpecialChar ~
13535 \SpecialChar ~
13536 \SpecialChar ~
13537 \SpecialChar ~
13538 psw,#0x00
13539 \newline 
13540 \SpecialChar ~
13541 \SpecialChar ~
13542 \SpecialChar ~
13543 \SpecialChar ~
13544 inc\SpecialChar ~
13545 \SpecialChar ~
13546 \SpecialChar ~
13547 \SpecialChar ~
13548 \SpecialChar ~
13549 _counter
13550 \newline 
13551 \SpecialChar ~
13552 \SpecialChar ~
13553 \SpecialChar ~
13554 \SpecialChar ~
13555 pop\SpecialChar ~
13556 \SpecialChar ~
13557 \SpecialChar ~
13558 \SpecialChar ~
13559 \SpecialChar ~
13560 psw
13561 \newline 
13562 \SpecialChar ~
13563 \SpecialChar ~
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 pop\SpecialChar ~
13567 \SpecialChar ~
13568 \SpecialChar ~
13569 \SpecialChar ~
13570 \SpecialChar ~
13571 dph
13572 \newline 
13573 \SpecialChar ~
13574 \SpecialChar ~
13575 \SpecialChar ~
13576 \SpecialChar ~
13577 pop\SpecialChar ~
13578 \SpecialChar ~
13579 \SpecialChar ~
13580 \SpecialChar ~
13581 \SpecialChar ~
13582 dpl
13583 \newline 
13584 \SpecialChar ~
13585 \SpecialChar ~
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 pop\SpecialChar ~
13589 \SpecialChar ~
13590 \SpecialChar ~
13591 \SpecialChar ~
13592 \SpecialChar ~
13593 b
13594 \newline 
13595 \SpecialChar ~
13596 \SpecialChar ~
13597 \SpecialChar ~
13598 \SpecialChar ~
13599 pop\SpecialChar ~
13600 \SpecialChar ~
13601 \SpecialChar ~
13602 \SpecialChar ~
13603 \SpecialChar ~
13604 acc
13605 \newline 
13606 \SpecialChar ~
13607 \SpecialChar ~
13608 \SpecialChar ~
13609 \SpecialChar ~
13610 reti
13611 \layout Standard
13612
13613 whereas nakedInterrupt looks like:
13614 \layout Verse
13615
13616
13617 \family typewriter 
13618 _nakedInterrupt:
13619 \newline 
13620 \SpecialChar ~
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 inc\SpecialChar ~
13625 \SpecialChar ~
13626 \SpecialChar ~
13627 \SpecialChar ~
13628 _counter ; does not change flags, no need to save psw
13629 \newline 
13630 \SpecialChar ~
13631 \SpecialChar ~
13632 \SpecialChar ~
13633 \SpecialChar ~
13634 reti\SpecialChar ~
13635 \SpecialChar ~
13636 \SpecialChar ~
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 \SpecialChar ~
13641 \SpecialChar ~
13642 \SpecialChar ~
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 \SpecialChar ~
13646 ; MUST explicitly include ret or reti in _naked function
13647 \layout Standard
13648
13649 The related directive #pragma exclude
13650 \begin_inset LatexCommand \index{\#pragma exclude}
13651
13652 \end_inset 
13653
13654  allows a more fine grained control over pushing & popping
13655 \begin_inset LatexCommand \index{push/pop}
13656
13657 \end_inset 
13658
13659  the registers.
13660 \layout Standard
13661
13662 While there is nothing preventing you from writing C code inside a 
13663 \family typewriter 
13664 _naked
13665 \family default 
13666  function, there are many ways to shoot yourself in the foot doing this,
13667  and it is recommended that you stick to inline assembler.
13668 \layout Subsection
13669
13670 Use of Labels within Inline Assembler
13671 \layout Standard
13672
13673 SDCC allows the use of in-line assembler with a few restrictions regarding
13674  labels.
13675  In older versions of the compiler all labels defined within inline assembler
13676  code 
13677 \emph on 
13678 had to be
13679 \emph default 
13680  of the form 
13681 \emph on 
13682 nnnnn$
13683 \emph default 
13684  where nnnn is a number less than 100 (which implies a limit of utmost 100
13685  inline assembler labels 
13686 \emph on 
13687 per function
13688 \emph default 
13689 \noun on 
13690 )
13691 \noun default 
13692 .
13693  
13694 \layout Verse
13695
13696
13697 \family typewriter 
13698 _asm
13699 \begin_inset LatexCommand \index{\_asm}
13700
13701 \end_inset 
13702
13703
13704 \begin_inset LatexCommand \index{\_\_asm}
13705
13706 \end_inset 
13707
13708  
13709 \newline 
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 \SpecialChar ~
13713 \SpecialChar ~
13714 mov\SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 \SpecialChar ~
13718 \SpecialChar ~
13719 b,#10 
13720 \newline 
13721 00001$: 
13722 \newline 
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 djnz\SpecialChar ~
13728 \SpecialChar ~
13729 \SpecialChar ~
13730 \SpecialChar ~
13731 b,00001$ 
13732 \newline 
13733 _endasm
13734 \begin_inset LatexCommand \index{\_endasm}
13735
13736 \end_inset 
13737
13738
13739 \begin_inset LatexCommand \index{\_\_endasm}
13740
13741 \end_inset 
13742
13743  ;
13744 \layout Standard
13745
13746 Inline assembler code cannot reference any C-Labels, however it can reference
13747  labels
13748 \begin_inset LatexCommand \index{Labels}
13749
13750 \end_inset 
13751
13752  defined by the inline assembler, e.g.:
13753 \layout Verse
13754
13755
13756 \family typewriter 
13757 foo() { 
13758 \newline 
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 \SpecialChar ~
13762 \SpecialChar ~
13763 /* some c code */ 
13764 \newline 
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 \SpecialChar ~
13768 \SpecialChar ~
13769 _asm 
13770 \newline 
13771 \SpecialChar ~
13772 \SpecialChar ~
13773 \SpecialChar ~
13774 \SpecialChar ~
13775 \SpecialChar ~
13776 \SpecialChar ~
13777 ; some assembler code 
13778 \newline 
13779 \SpecialChar ~
13780 \SpecialChar ~
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 ljmp $0003 
13786 \newline 
13787 \SpecialChar ~
13788 \SpecialChar ~
13789 \SpecialChar ~
13790 \SpecialChar ~
13791 _endasm; 
13792 \newline 
13793 \SpecialChar ~
13794 \SpecialChar ~
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 /* some more c code */ 
13798 \newline 
13799 clabel:\SpecialChar ~
13800 \SpecialChar ~
13801 /* inline assembler cannot reference this label */ 
13802 \newline 
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 _asm
13808 \newline 
13809 \SpecialChar ~
13810 \SpecialChar ~
13811 \SpecialChar ~
13812 \SpecialChar ~
13813 $0003: ;label (can be referenced by inline assembler only) 
13814 \newline 
13815 \SpecialChar ~
13816 \SpecialChar ~
13817 \SpecialChar ~
13818 \SpecialChar ~
13819 _endasm
13820 \begin_inset LatexCommand \index{\_endasm}
13821
13822 \end_inset 
13823
13824
13825 \begin_inset LatexCommand \index{\_\_endasm}
13826
13827 \end_inset 
13828
13829  ; 
13830 \newline 
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 \SpecialChar ~
13835 /* some more c code */
13836 \newline 
13837 }
13838 \layout Standard
13839
13840 In other words inline assembly code can access labels defined in inline
13841  assembly within the scope of the function.
13842  The same goes the other way, i.e.
13843  labels defines in inline assembly can not be accessed by C statements.
13844 \layout Section
13845
13846 Interfacing with Assembler Code
13847 \begin_inset LatexCommand \index{Assembler routines}
13848
13849 \end_inset 
13850
13851
13852 \layout Subsection
13853
13854 Global Registers used for Parameter Passing
13855 \begin_inset LatexCommand \index{Parameter passing}
13856
13857 \end_inset 
13858
13859
13860 \layout Standard
13861
13862 The compiler always uses the global registers 
13863 \emph on 
13864 DPL, DPH
13865 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
13866
13867 \end_inset 
13868
13869
13870 \begin_inset LatexCommand \index{DPTR}
13871
13872 \end_inset 
13873
13874 , B
13875 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
13876
13877 \end_inset 
13878
13879  
13880 \emph default 
13881 and
13882 \emph on 
13883  ACC
13884 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
13885
13886 \end_inset 
13887
13888
13889 \emph default 
13890  to pass the first parameter to a routine.
13891  The second parameter onwards is either allocated on the stack (for reentrant
13892  routines or if -
13893 \begin_inset ERT
13894 status Collapsed
13895
13896 \layout Standard
13897
13898 \backslash 
13899 /
13900 \end_inset 
13901
13902 -stack-auto is used) or in data / xdata memory (depending on the memory
13903  model).
13904  
13905 \layout Subsection
13906
13907 Assembler Routine (non-reentrant)
13908 \layout Standard
13909
13910 In the following example
13911 \begin_inset LatexCommand \index{reentrant}
13912
13913 \end_inset 
13914
13915
13916 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
13917
13918 \end_inset 
13919
13920  the function c_func calls an assembler routine asm_func, which takes two
13921  parameters
13922 \begin_inset LatexCommand \index{function parameter}
13923
13924 \end_inset 
13925
13926 .
13927 \layout Verse
13928
13929
13930 \family typewriter 
13931 extern int asm_func(unsigned char, unsigned char);
13932 \newline 
13933
13934 \newline 
13935 int c_func (unsigned char i, unsigned char j)
13936 \newline 
13937 {
13938 \newline 
13939 \SpecialChar ~
13940 \SpecialChar ~
13941 \SpecialChar ~
13942 \SpecialChar ~
13943 return asm_func(i,j);
13944 \newline 
13945 }
13946 \newline 
13947
13948 \newline 
13949 int main()
13950 \newline 
13951 {
13952 \newline 
13953 \SpecialChar ~
13954 \SpecialChar ~
13955 \SpecialChar ~
13956 \SpecialChar ~
13957 return c_func(10,9);
13958 \newline 
13959 }
13960 \layout Standard
13961
13962 The corresponding assembler function is:
13963 \layout Verse
13964
13965
13966 \family typewriter 
13967 .globl _asm_func_PARM_2 
13968 \newline 
13969 \SpecialChar ~
13970 \SpecialChar ~
13971 \SpecialChar ~
13972 \SpecialChar ~
13973 \SpecialChar ~
13974 \SpecialChar ~
13975 \SpecialChar ~
13976 \SpecialChar ~
13977 .globl _asm_func 
13978 \newline 
13979 \SpecialChar ~
13980 \SpecialChar ~
13981 \SpecialChar ~
13982 \SpecialChar ~
13983 \SpecialChar ~
13984 \SpecialChar ~
13985 \SpecialChar ~
13986 \SpecialChar ~
13987 .area OSEG 
13988 \newline 
13989 _asm_func_PARM_2:
13990 \newline 
13991 \SpecialChar ~
13992 \SpecialChar ~
13993 \SpecialChar ~
13994 \SpecialChar ~
13995 \SpecialChar ~
13996 \SpecialChar ~
13997 \SpecialChar ~
13998 \SpecialChar ~
13999 .ds    1 
14000 \newline 
14001 \SpecialChar ~
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 \SpecialChar ~
14005 \SpecialChar ~
14006 \SpecialChar ~
14007 \SpecialChar ~
14008 \SpecialChar ~
14009 .area CSEG 
14010 \newline 
14011 _asm_func: 
14012 \newline 
14013 \SpecialChar ~
14014 \SpecialChar ~
14015 \SpecialChar ~
14016 \SpecialChar ~
14017 \SpecialChar ~
14018 \SpecialChar ~
14019 \SpecialChar ~
14020 \SpecialChar ~
14021 mov\SpecialChar ~
14022 \SpecialChar ~
14023 \SpecialChar ~
14024 \SpecialChar ~
14025 a,dpl 
14026 \newline 
14027 \SpecialChar ~
14028 \SpecialChar ~
14029 \SpecialChar ~
14030 \SpecialChar ~
14031 \SpecialChar ~
14032 \SpecialChar ~
14033 \SpecialChar ~
14034 \SpecialChar ~
14035 add\SpecialChar ~
14036 \SpecialChar ~
14037 \SpecialChar ~
14038 \SpecialChar ~
14039 a,_asm_func_PARM_2 
14040 \newline 
14041 \SpecialChar ~
14042 \SpecialChar ~
14043 \SpecialChar ~
14044 \SpecialChar ~
14045 \SpecialChar ~
14046 \SpecialChar ~
14047 \SpecialChar ~
14048 \SpecialChar ~
14049 mov\SpecialChar ~
14050 \SpecialChar ~
14051 \SpecialChar ~
14052 \SpecialChar ~
14053 dpl,a 
14054 \newline 
14055 \SpecialChar ~
14056 \SpecialChar ~
14057 \SpecialChar ~
14058 \SpecialChar ~
14059 \SpecialChar ~
14060 \SpecialChar ~
14061 \SpecialChar ~
14062 \SpecialChar ~
14063 mov\SpecialChar ~
14064 \SpecialChar ~
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 dph
14068 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14069
14070 \end_inset 
14071
14072 ,#0x00 
14073 \newline 
14074 \SpecialChar ~
14075 \SpecialChar ~
14076 \SpecialChar ~
14077 \SpecialChar ~
14078 \SpecialChar ~
14079 \SpecialChar ~
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 ret
14083 \layout Standard
14084
14085 Note here that the return values
14086 \begin_inset LatexCommand \index{return value}
14087
14088 \end_inset 
14089
14090  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14091  two byte values.
14092  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14093 b' & 'acc' for four byte values.
14094 \layout Standard
14095
14096 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14097  the parameter number starting from 1, and counting from the left.
14098  The first parameter is passed in 
14099 \begin_inset Quotes eld
14100 \end_inset 
14101
14102 dpl
14103 \begin_inset Quotes erd
14104 \end_inset 
14105
14106  for a one byte parameter, 
14107 \begin_inset Quotes eld
14108 \end_inset 
14109
14110 dptr
14111 \begin_inset Quotes erd
14112 \end_inset 
14113
14114  for two bytes, 
14115 \begin_inset Quotes eld
14116 \end_inset 
14117
14118 b,dptr
14119 \begin_inset Quotes erd
14120 \end_inset 
14121
14122  for three bytes and 
14123 \begin_inset Quotes eld
14124 \end_inset 
14125
14126 acc,b,dptr
14127 \begin_inset Quotes erd
14128 \end_inset 
14129
14130  for a four bytes parameter.
14131  The variable name for the second parameter will be _<function_name>_PARM_2.
14132 \newline 
14133
14134 \newline 
14135 Assemble the assembler routine with the following command:
14136 \newline 
14137
14138 \newline 
14139
14140 \family sans 
14141 \series bold 
14142 asx8051 -losg asmfunc.asm
14143 \newline 
14144
14145 \newline 
14146
14147 \family default 
14148 \series default 
14149 Then compile and link the assembler routine to the C source file with the
14150  following command:
14151 \newline 
14152
14153 \newline 
14154
14155 \family sans 
14156 \series bold 
14157 sdcc cfunc.c asmfunc.rel
14158 \layout Subsection
14159
14160 Assembler Routine (reentrant)
14161 \layout Standard
14162
14163 In this case
14164 \begin_inset LatexCommand \index{reentrant}
14165
14166 \end_inset 
14167
14168
14169 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14170
14171 \end_inset 
14172
14173  the second parameter
14174 \begin_inset LatexCommand \index{function parameter}
14175
14176 \end_inset 
14177
14178  onwards will be passed on the stack, the parameters are pushed from right
14179  to left i.e.
14180  after the call the leftmost parameter will be on the top of the stack.
14181  Here is an example:
14182 \layout Verse
14183
14184
14185 \family typewriter 
14186 extern int asm_func(unsigned char, unsigned char);
14187 \newline 
14188
14189 \newline 
14190 int c_func (unsigned char i, unsigned char j) reentrant 
14191 \newline 
14192
14193 \newline 
14194 \SpecialChar ~
14195 \SpecialChar ~
14196 \SpecialChar ~
14197 \SpecialChar ~
14198 return asm_func(i,j); 
14199 \newline 
14200
14201 \newline 
14202
14203 \newline 
14204 int main() 
14205 \newline 
14206
14207 \newline 
14208 \SpecialChar ~
14209 \SpecialChar ~
14210 \SpecialChar ~
14211 \SpecialChar ~
14212 return c_func(10,9); 
14213 \newline 
14214 }
14215 \layout Standard
14216
14217 The corresponding assembler routine is:
14218 \layout Verse
14219
14220
14221 \family typewriter 
14222 .globl _asm_func 
14223 \newline 
14224 _asm_func: 
14225 \newline 
14226 \SpecialChar ~
14227 \SpecialChar ~
14228 \SpecialChar ~
14229 \SpecialChar ~
14230 push  _bp 
14231 \newline 
14232 \SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 \SpecialChar ~
14236 mov _bp,sp 
14237 \newline 
14238 \SpecialChar ~
14239 \SpecialChar ~
14240 \SpecialChar ~
14241 \SpecialChar ~
14242 mov r2,dpl
14243 \newline 
14244 \SpecialChar ~
14245 \SpecialChar ~
14246 \SpecialChar ~
14247 \SpecialChar ~
14248 mov a,_bp 
14249 \newline 
14250 \SpecialChar ~
14251 \SpecialChar ~
14252 \SpecialChar ~
14253 \SpecialChar ~
14254 add a,#0xfd 
14255 \newline 
14256 \SpecialChar ~
14257 \SpecialChar ~
14258 \SpecialChar ~
14259 \SpecialChar ~
14260 mov r0,a 
14261 \newline 
14262 \SpecialChar ~
14263 \SpecialChar ~
14264 \SpecialChar ~
14265 \SpecialChar ~
14266 add  a,#0xfc ;?
14267 \newline 
14268 \SpecialChar ~
14269 \SpecialChar ~
14270 \SpecialChar ~
14271 \SpecialChar ~
14272 mov  r1,a 
14273 \newline 
14274 \SpecialChar ~
14275 \SpecialChar ~
14276 \SpecialChar ~
14277 \SpecialChar ~
14278 mov  a,@r0 
14279 \newline 
14280 \SpecialChar ~
14281 \SpecialChar ~
14282 \SpecialChar ~
14283 \SpecialChar ~
14284 add  a,r2 ;?
14285 \newline 
14286 \SpecialChar ~
14287 \SpecialChar ~
14288 \SpecialChar ~
14289 \SpecialChar ~
14290 mov  dpl,a 
14291 \newline 
14292 \SpecialChar ~
14293 \SpecialChar ~
14294 \SpecialChar ~
14295 \SpecialChar ~
14296 mov  dph,#0x00 
14297 \newline 
14298 \SpecialChar ~
14299 \SpecialChar ~
14300 \SpecialChar ~
14301 \SpecialChar ~
14302 mov  sp,_bp 
14303 \newline 
14304 \SpecialChar ~
14305 \SpecialChar ~
14306 \SpecialChar ~
14307 \SpecialChar ~
14308 pop  _bp 
14309 \newline 
14310 \SpecialChar ~
14311 \SpecialChar ~
14312 \SpecialChar ~
14313 \SpecialChar ~
14314 ret
14315 \layout Standard
14316
14317 The compiling and linking procedure remains the same, however note the extra
14318  entry & exit linkage required for the assembler code, _bp is the stack
14319  frame pointer and is used to compute the offset into the stack for parameters
14320  and local variables.
14321 \layout Section
14322
14323 int (16 bit)
14324 \begin_inset LatexCommand \index{int (16 bit)}
14325
14326 \end_inset 
14327
14328  and long (32 bit)
14329 \begin_inset LatexCommand \index{long (32 bit)}
14330
14331 \end_inset 
14332
14333  Support
14334 \layout Standard
14335
14336 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14337  multiplication and modulus operations are implemented by support routines.
14338  These support routines are all developed in ANSI-C to facilitate porting
14339  to other MCUs, although some model specific assembler optimizations are
14340  used.
14341  The following files contain the described routines, all of them can be
14342  found in <installdir>/share/sdcc/lib.
14343 \newline 
14344
14345 \layout Standard
14346 \align center 
14347
14348 \begin_inset  Tabular
14349 <lyxtabular version="3" rows="11" columns="2">
14350 <features>
14351 <column alignment="left" valignment="top" leftline="true" width="0">
14352 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14353 <row topline="true" bottomline="true">
14354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14355 \begin_inset Text
14356
14357 \layout Standard
14358
14359
14360 \series bold 
14361 Function
14362 \end_inset 
14363 </cell>
14364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14365 \begin_inset Text
14366
14367 \layout Standard
14368
14369
14370 \series bold 
14371 Description
14372 \end_inset 
14373 </cell>
14374 </row>
14375 <row topline="true">
14376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14377 \begin_inset Text
14378
14379 \layout Standard
14380
14381 _mulint.c 
14382 \end_inset 
14383 </cell>
14384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14385 \begin_inset Text
14386
14387 \layout Standard
14388
14389 16 bit multiplication
14390 \end_inset 
14391 </cell>
14392 </row>
14393 <row topline="true">
14394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14395 \begin_inset Text
14396
14397 \layout Standard
14398
14399 _divsint.c 
14400 \end_inset 
14401 </cell>
14402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14403 \begin_inset Text
14404
14405 \layout Standard
14406
14407  signed 16 bit division (calls _divuint)
14408 \end_inset 
14409 </cell>
14410 </row>
14411 <row topline="true">
14412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14413 \begin_inset Text
14414
14415 \layout Standard
14416
14417 _divuint.c 
14418 \end_inset 
14419 </cell>
14420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14421 \begin_inset Text
14422
14423 \layout Standard
14424
14425  unsigned 16 bit division
14426 \end_inset 
14427 </cell>
14428 </row>
14429 <row topline="true">
14430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14431 \begin_inset Text
14432
14433 \layout Standard
14434
14435 _modsint.c
14436 \end_inset 
14437 </cell>
14438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14439 \begin_inset Text
14440
14441 \layout Standard
14442
14443 signed 16 bit modulus (calls _moduint)
14444 \end_inset 
14445 </cell>
14446 </row>
14447 <row topline="true">
14448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14449 \begin_inset Text
14450
14451 \layout Standard
14452
14453 _moduint.c
14454 \end_inset 
14455 </cell>
14456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14457 \begin_inset Text
14458
14459 \layout Standard
14460
14461 unsigned 16 bit modulus
14462 \end_inset 
14463 </cell>
14464 </row>
14465 <row topline="true">
14466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14467 \begin_inset Text
14468
14469 \layout Standard
14470
14471 _mullong.c
14472 \end_inset 
14473 </cell>
14474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14475 \begin_inset Text
14476
14477 \layout Standard
14478
14479 32 bit multiplication
14480 \end_inset 
14481 </cell>
14482 </row>
14483 <row topline="true">
14484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14485 \begin_inset Text
14486
14487 \layout Standard
14488
14489 _divslong.c 
14490 \end_inset 
14491 </cell>
14492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14493 \begin_inset Text
14494
14495 \layout Standard
14496
14497  signed 32 division (calls _divulong)
14498 \end_inset 
14499 </cell>
14500 </row>
14501 <row topline="true">
14502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14503 \begin_inset Text
14504
14505 \layout Standard
14506
14507 _divulong.c 
14508 \end_inset 
14509 </cell>
14510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14511 \begin_inset Text
14512
14513 \layout Standard
14514
14515 unsigned 32 division
14516 \end_inset 
14517 </cell>
14518 </row>
14519 <row topline="true">
14520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14521 \begin_inset Text
14522
14523 \layout Standard
14524
14525 _modslong.c
14526 \end_inset 
14527 </cell>
14528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14529 \begin_inset Text
14530
14531 \layout Standard
14532
14533  signed 32 bit modulus (calls _modulong)
14534 \end_inset 
14535 </cell>
14536 </row>
14537 <row topline="true" bottomline="true">
14538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14539 \begin_inset Text
14540
14541 \layout Standard
14542
14543 _modulong.c
14544 \end_inset 
14545 </cell>
14546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14547 \begin_inset Text
14548
14549 \layout Standard
14550
14551 unsigned 32 bit modulus
14552 \end_inset 
14553 </cell>
14554 </row>
14555 </lyxtabular>
14556
14557 \end_inset 
14558
14559
14560 \newline 
14561
14562 \layout Standard
14563
14564 Since they are compiled as 
14565 \emph on 
14566 non-reentrant
14567 \emph default 
14568
14569 \begin_inset LatexCommand \index{reentrant}
14570
14571 \end_inset 
14572
14573 , interrupt
14574 \begin_inset LatexCommand \index{interrupt}
14575
14576 \end_inset 
14577
14578  service routines should not do any of the above operations.
14579  If this is unavoidable then the above routines will need to be compiled
14580  with the 
14581 \emph on 
14582 -
14583 \begin_inset ERT
14584 status Collapsed
14585
14586 \layout Standard
14587
14588 \backslash 
14589 /
14590 \end_inset 
14591
14592 -stack-auto
14593 \begin_inset LatexCommand \index{-\/-stack-auto}
14594
14595 \end_inset 
14596
14597
14598 \emph default 
14599  option, after which the source program will have to be compiled with 
14600 \emph on 
14601 -
14602 \begin_inset ERT
14603 status Collapsed
14604
14605 \layout Standard
14606
14607 \backslash 
14608 /
14609 \end_inset 
14610
14611 -int-long-reent
14612 \begin_inset LatexCommand \index{-\/-int-long-reent}
14613
14614 \end_inset 
14615
14616
14617 \emph default 
14618  option.
14619  Notice that you don't have to call these routines directly.
14620  The compiler will use them automatically every time an integer operation
14621  is required.
14622 \layout Section
14623
14624 Floating Point Support
14625 \begin_inset LatexCommand \index{Floating point support}
14626
14627 \end_inset 
14628
14629
14630 \layout Standard
14631
14632 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
14633  floating point support routines are derived from gcc's floatlib.c and consist
14634  of the following routines:
14635 \newline 
14636
14637 \layout Standard
14638 \align center 
14639
14640 \size footnotesize 
14641
14642 \begin_inset  Tabular
14643 <lyxtabular version="3" rows="17" columns="2">
14644 <features>
14645 <column alignment="left" valignment="top" leftline="true" width="0">
14646 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14647 <row topline="true" bottomline="true">
14648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14649 \begin_inset Text
14650
14651 \layout Standard
14652
14653
14654 \family roman 
14655 \series medium 
14656 \shape up 
14657 \size normal 
14658 \emph off 
14659 \bar no 
14660 \noun off 
14661 \color none
14662 Function 
14663 \end_inset 
14664 </cell>
14665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14666 \begin_inset Text
14667
14668 \layout Standard
14669
14670 Description
14671 \end_inset 
14672 </cell>
14673 </row>
14674 <row topline="true">
14675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14676 \begin_inset Text
14677
14678 \layout Standard
14679
14680
14681 \family roman 
14682 \series medium 
14683 \shape up 
14684 \size normal 
14685 \emph off 
14686 \bar no 
14687 \noun off 
14688 \color none
14689 _fsadd.c
14690 \end_inset 
14691 </cell>
14692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14693 \begin_inset Text
14694
14695 \layout Standard
14696
14697
14698 \family roman 
14699 \series medium 
14700 \shape up 
14701 \size normal 
14702 \emph off 
14703 \bar no 
14704 \noun off 
14705 \color none
14706 add floating point numbers
14707 \end_inset 
14708 </cell>
14709 </row>
14710 <row topline="true">
14711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14712 \begin_inset Text
14713
14714 \layout Standard
14715
14716
14717 \family roman 
14718 \series medium 
14719 \shape up 
14720 \size normal 
14721 \emph off 
14722 \bar no 
14723 \noun off 
14724 \color none
14725 _fssub.c 
14726 \end_inset 
14727 </cell>
14728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14729 \begin_inset Text
14730
14731 \layout Standard
14732
14733
14734 \family roman 
14735 \series medium 
14736 \shape up 
14737 \size normal 
14738 \emph off 
14739 \bar no 
14740 \noun off 
14741 \color none
14742 subtract floating point numbers 
14743 \end_inset 
14744 </cell>
14745 </row>
14746 <row topline="true">
14747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14748 \begin_inset Text
14749
14750 \layout Standard
14751
14752
14753 \family roman 
14754 \series medium 
14755 \shape up 
14756 \size normal 
14757 \emph off 
14758 \bar no 
14759 \noun off 
14760 \color none
14761 _fsdiv.c 
14762 \end_inset 
14763 </cell>
14764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14765 \begin_inset Text
14766
14767 \layout Standard
14768
14769
14770 \family roman 
14771 \series medium 
14772 \shape up 
14773 \size normal 
14774 \emph off 
14775 \bar no 
14776 \noun off 
14777 \color none
14778 divide floating point numbers 
14779 \end_inset 
14780 </cell>
14781 </row>
14782 <row topline="true">
14783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14784 \begin_inset Text
14785
14786 \layout Standard
14787
14788
14789 \family roman 
14790 \series medium 
14791 \shape up 
14792 \size normal 
14793 \emph off 
14794 \bar no 
14795 \noun off 
14796 \color none
14797 _fsmul.c 
14798 \end_inset 
14799 </cell>
14800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14801 \begin_inset Text
14802
14803 \layout Standard
14804
14805
14806 \family roman 
14807 \series medium 
14808 \shape up 
14809 \size normal 
14810 \emph off 
14811 \bar no 
14812 \noun off 
14813 \color none
14814 multiply floating point numbers 
14815 \end_inset 
14816 </cell>
14817 </row>
14818 <row topline="true">
14819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14820 \begin_inset Text
14821
14822 \layout Standard
14823
14824
14825 \family roman 
14826 \series medium 
14827 \shape up 
14828 \size normal 
14829 \emph off 
14830 \bar no 
14831 \noun off 
14832 \color none
14833 _fs2uchar.c
14834 \end_inset 
14835 </cell>
14836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14837 \begin_inset Text
14838
14839 \layout Standard
14840
14841
14842 \family roman 
14843 \series medium 
14844 \shape up 
14845 \size normal 
14846 \emph off 
14847 \bar no 
14848 \noun off 
14849 \color none
14850 convert floating point to unsigned char
14851 \end_inset 
14852 </cell>
14853 </row>
14854 <row topline="true">
14855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14856 \begin_inset Text
14857
14858 \layout Standard
14859
14860
14861 \family roman 
14862 \series medium 
14863 \shape up 
14864 \size normal 
14865 \emph off 
14866 \bar no 
14867 \noun off 
14868 \color none
14869 _fs2char.c
14870 \end_inset 
14871 </cell>
14872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14873 \begin_inset Text
14874
14875 \layout Standard
14876
14877
14878 \family roman 
14879 \series medium 
14880 \shape up 
14881 \size normal 
14882 \emph off 
14883 \bar no 
14884 \noun off 
14885 \color none
14886 convert floating point to signed char
14887 \end_inset 
14888 </cell>
14889 </row>
14890 <row topline="true">
14891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14892 \begin_inset Text
14893
14894 \layout Standard
14895
14896
14897 \family roman 
14898 \series medium 
14899 \shape up 
14900 \size normal 
14901 \emph off 
14902 \bar no 
14903 \noun off 
14904 \color none
14905 _fs2uint.c
14906 \end_inset 
14907 </cell>
14908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14909 \begin_inset Text
14910
14911 \layout Standard
14912
14913
14914 \family roman 
14915 \series medium 
14916 \shape up 
14917 \size normal 
14918 \emph off 
14919 \bar no 
14920 \noun off 
14921 \color none
14922 convert floating point to unsigned int
14923 \end_inset 
14924 </cell>
14925 </row>
14926 <row topline="true">
14927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14928 \begin_inset Text
14929
14930 \layout Standard
14931
14932
14933 \family roman 
14934 \series medium 
14935 \shape up 
14936 \size normal 
14937 \emph off 
14938 \bar no 
14939 \noun off 
14940 \color none
14941 _fs2int.c
14942 \end_inset 
14943 </cell>
14944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14945 \begin_inset Text
14946
14947 \layout Standard
14948
14949
14950 \family roman 
14951 \series medium 
14952 \shape up 
14953 \size normal 
14954 \emph off 
14955 \bar no 
14956 \noun off 
14957 \color none
14958 convert floating point to signed int
14959 \end_inset 
14960 </cell>
14961 </row>
14962 <row topline="true">
14963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14964 \begin_inset Text
14965
14966 \layout Standard
14967
14968
14969 \family roman 
14970 \series medium 
14971 \shape up 
14972 \size normal 
14973 \emph off 
14974 \bar no 
14975 \noun off 
14976 \color none
14977 _fs2ulong.
14978 \family default 
14979 \series default 
14980 \shape default 
14981 \size default 
14982 \emph default 
14983 \bar default 
14984 \noun default 
14985 \color default
14986 c
14987 \end_inset 
14988 </cell>
14989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14990 \begin_inset Text
14991
14992 \layout Standard
14993
14994
14995 \family roman 
14996 \series medium 
14997 \shape up 
14998 \size normal 
14999 \emph off 
15000 \bar no 
15001 \noun off 
15002 \color none
15003 convert floating point to unsigned long
15004 \end_inset 
15005 </cell>
15006 </row>
15007 <row topline="true">
15008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15009 \begin_inset Text
15010
15011 \layout Standard
15012
15013
15014 \family roman 
15015 \series medium 
15016 \shape up 
15017 \size normal 
15018 \emph off 
15019 \bar no 
15020 \noun off 
15021 \color none
15022 _fs2long.c
15023 \end_inset 
15024 </cell>
15025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15026 \begin_inset Text
15027
15028 \layout Standard
15029
15030
15031 \family roman 
15032 \series medium 
15033 \shape up 
15034 \size normal 
15035 \emph off 
15036 \bar no 
15037 \noun off 
15038 \color none
15039 convert floating point to signed long
15040 \end_inset 
15041 </cell>
15042 </row>
15043 <row topline="true">
15044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15045 \begin_inset Text
15046
15047 \layout Standard
15048
15049
15050 \family roman 
15051 \series medium 
15052 \shape up 
15053 \size normal 
15054 \emph off 
15055 \bar no 
15056 \noun off 
15057 \color none
15058 _uchar2fs.c
15059 \end_inset 
15060 </cell>
15061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15062 \begin_inset Text
15063
15064 \layout Standard
15065
15066
15067 \family roman 
15068 \series medium 
15069 \shape up 
15070 \size normal 
15071 \emph off 
15072 \bar no 
15073 \noun off 
15074 \color none
15075 convert unsigned char to floating point
15076 \end_inset 
15077 </cell>
15078 </row>
15079 <row topline="true">
15080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15081 \begin_inset Text
15082
15083 \layout Standard
15084
15085
15086 \family roman 
15087 \series medium 
15088 \shape up 
15089 \size normal 
15090 \emph off 
15091 \bar no 
15092 \noun off 
15093 \color none
15094 _char2fs.c
15095 \end_inset 
15096 </cell>
15097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15098 \begin_inset Text
15099
15100 \layout Standard
15101
15102
15103 \family roman 
15104 \series medium 
15105 \shape up 
15106 \size normal 
15107 \emph off 
15108 \bar no 
15109 \noun off 
15110 \color none
15111 convert char to floating point number
15112 \end_inset 
15113 </cell>
15114 </row>
15115 <row topline="true">
15116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15117 \begin_inset Text
15118
15119 \layout Standard
15120
15121
15122 \family roman 
15123 \series medium 
15124 \shape up 
15125 \size normal 
15126 \emph off 
15127 \bar no 
15128 \noun off 
15129 \color none
15130 _uint2fs.c
15131 \end_inset 
15132 </cell>
15133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15134 \begin_inset Text
15135
15136 \layout Standard
15137
15138
15139 \family roman 
15140 \series medium 
15141 \shape up 
15142 \size normal 
15143 \emph off 
15144 \bar no 
15145 \noun off 
15146 \color none
15147 convert unsigned int to floating point
15148 \end_inset 
15149 </cell>
15150 </row>
15151 <row topline="true">
15152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15153 \begin_inset Text
15154
15155 \layout Standard
15156
15157
15158 \family roman 
15159 \series medium 
15160 \shape up 
15161 \size normal 
15162 \emph off 
15163 \bar no 
15164 \noun off 
15165 \color none
15166 _int2fs.c
15167 \end_inset 
15168 </cell>
15169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15170 \begin_inset Text
15171
15172 \layout Standard
15173
15174
15175 \family roman 
15176 \series medium 
15177 \shape up 
15178 \size normal 
15179 \emph off 
15180 \bar no 
15181 \noun off 
15182 \color none
15183 convert int to floating point numbers
15184 \end_inset 
15185 </cell>
15186 </row>
15187 <row topline="true">
15188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15189 \begin_inset Text
15190
15191 \layout Standard
15192
15193
15194 \family roman 
15195 \series medium 
15196 \shape up 
15197 \size normal 
15198 \emph off 
15199 \bar no 
15200 \noun off 
15201 \color none
15202 _ulong2fs.c
15203 \end_inset 
15204 </cell>
15205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15206 \begin_inset Text
15207
15208 \layout Standard
15209
15210
15211 \family roman 
15212 \series medium 
15213 \shape up 
15214 \size normal 
15215 \emph off 
15216 \bar no 
15217 \noun off 
15218 \color none
15219 convert unsigned long to floating point number
15220 \end_inset 
15221 </cell>
15222 </row>
15223 <row topline="true" bottomline="true">
15224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15225 \begin_inset Text
15226
15227 \layout Standard
15228
15229
15230 \family roman 
15231 \series medium 
15232 \shape up 
15233 \size normal 
15234 \emph off 
15235 \bar no 
15236 \noun off 
15237 \color none
15238 _long2fs.c
15239 \end_inset 
15240 </cell>
15241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15242 \begin_inset Text
15243
15244 \layout Standard
15245
15246
15247 \family roman 
15248 \series medium 
15249 \shape up 
15250 \size normal 
15251 \emph off 
15252 \bar no 
15253 \noun off 
15254 \color none
15255 convert long to floating point number
15256 \end_inset 
15257 </cell>
15258 </row>
15259 </lyxtabular>
15260
15261 \end_inset 
15262
15263
15264 \newline 
15265
15266 \layout Standard
15267
15268 These support routines are developed in ANSI-C so there is room for space
15269  and speed improvement
15270 \begin_inset Foot
15271 collapsed false
15272
15273 \layout Standard
15274
15275 These floating point routines (
15276 \emph on 
15277 not
15278 \emph default 
15279  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15280  
15281 \end_inset 
15282
15283 .
15284  Note if all these routines are used simultaneously the data space might
15285  overflow.
15286  For serious floating point usage the large model might be needed.
15287  Also notice that you don't have to call this routines directly.
15288  The compiler will use them automatically every time a floating point operation
15289  is required.
15290 \layout Section
15291
15292 Library Routines
15293 \begin_inset LatexCommand \index{Libraries}
15294
15295 \end_inset 
15296
15297
15298 \layout Standard
15299
15300
15301 \emph on 
15302 <pending: this is messy and incomplete - a little more information is in
15303  sdcc/doc/libdoc.txt
15304 \emph default 
15305  >
15306 \layout Subsection
15307
15308 Compiler support routines (_gptrget, _mulint etc.)
15309 \layout Subsection
15310
15311 Stdclib functions (puts, printf, strcat etc.)
15312 \layout Subsubsection
15313
15314 <stdio.h>
15315 \layout Standard
15316
15317
15318 \begin_inset LatexCommand \index{<stdio.h>}
15319
15320 \end_inset 
15321
15322 As usual on embedded systems you have to provide your own 
15323 \family typewriter 
15324 getchar()
15325 \begin_inset LatexCommand \index{getchar()}
15326
15327 \end_inset 
15328
15329  
15330 \family default 
15331 and 
15332 \family typewriter 
15333 putchar()
15334 \begin_inset LatexCommand \index{putchar()}
15335
15336 \end_inset 
15337
15338
15339 \family default 
15340  routines.
15341  SDCC does not know whether the system connects to a serial line with or
15342  without handshake, LCD, keyboard or other device.
15343  And whether a 
15344 \family typewriter 
15345 lf
15346 \family default 
15347  to 
15348 \family typewriter 
15349 crlf
15350 \family default 
15351  conversion within 
15352 \family typewriter 
15353 putchar()
15354 \family default 
15355  is intended.
15356  You'll find examples for serial routines f.e.
15357  in sdcc/device/lib.
15358 \layout Standard
15359
15360 The default
15361 \family typewriter 
15362  printf()
15363 \begin_inset LatexCommand \index{printf()}
15364
15365 \end_inset 
15366
15367
15368 \family default 
15369 implementation in
15370 \family typewriter 
15371  printf_large.c
15372 \family default 
15373  does not support float (except on ds390).
15374  To enable this recompile it with the option 
15375 \emph on 
15376 -
15377 \begin_inset ERT
15378 status Collapsed
15379
15380 \layout Standard
15381
15382 \backslash 
15383 /
15384 \end_inset 
15385
15386 DUSE_FLOATS=1
15387 \begin_inset LatexCommand \index{USE\_FLOATS}
15388
15389 \end_inset 
15390
15391
15392 \emph default 
15393  on the command line.
15394  Use
15395 \emph on 
15396  -
15397 \begin_inset ERT
15398 status Collapsed
15399
15400 \layout Standard
15401
15402 \backslash 
15403 /
15404 \end_inset 
15405
15406 -model-large
15407 \begin_inset LatexCommand \index{-\/-model-large}
15408
15409 \end_inset 
15410
15411
15412 \emph default 
15413  for the mcs51 port, since this uses a lot of memory.
15414 \layout Standard
15415
15416 If you're short on memory you might want to use 
15417 \family typewriter 
15418 printf_small()
15419 \begin_inset LatexCommand \index{printf\_small()}
15420
15421 \end_inset 
15422
15423
15424 \family default 
15425  
15426 \emph on 
15427 instead
15428 \emph default 
15429  of
15430 \family typewriter 
15431  printf().
15432
15433 \family default 
15434  For the mcs51 there additionally are assembly versions 
15435 \family typewriter 
15436 printf_tiny()
15437 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
15438
15439 \end_inset 
15440
15441
15442 \family default 
15443  (subset of printf using less than 270 bytes) and 
15444 \family typewriter 
15445 printf_fast()
15446 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
15447
15448 \end_inset 
15449
15450  
15451 \family default 
15452 and
15453 \family typewriter 
15454  printf_fast_f()
15455 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
15456
15457 \end_inset 
15458
15459
15460 \family default 
15461  (floating-point aware version of printf_fast) which should fit the requirements
15462  of many embedded systems (printf_fast() can be customized by unsetting
15463  #defines to 
15464 \emph on 
15465 not
15466 \emph default 
15467  support long variables and field widths).
15468 \layout 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 \layout Standard
16256
16257 The pragma's are intended to be used to turn-on or off certain optimizations
16258  which might cause the compiler to generate extra stack / data space to
16259  store compiler generated temporary variables.
16260  This usually happens in large functions.
16261  Pragma directives should be used as shown in the following example, they
16262  are used to control options & optimizations for a given function; pragmas
16263  should be placed before and/or after a function, placing pragma's inside
16264  a function body could have unpredictable results.
16265 \layout Verse
16266
16267
16268 \family typewriter 
16269 #pragma save
16270 \begin_inset LatexCommand \index{\#pragma save}
16271
16272 \end_inset 
16273
16274  \SpecialChar ~
16275 \SpecialChar ~
16276 \SpecialChar ~
16277 \SpecialChar ~
16278 \SpecialChar ~
16279 \SpecialChar ~
16280 \SpecialChar ~
16281 /* save the current settings */ 
16282 \newline 
16283 #pragma nogcse
16284 \begin_inset LatexCommand \index{\#pragma nogcse}
16285
16286 \end_inset 
16287
16288  \SpecialChar ~
16289 \SpecialChar ~
16290 \SpecialChar ~
16291 \SpecialChar ~
16292 \SpecialChar ~
16293 /* turnoff global subexpression elimination */ 
16294 \newline 
16295 #pragma noinduction
16296 \begin_inset LatexCommand \index{\#pragma noinduction}
16297
16298 \end_inset 
16299
16300  /* turn off induction optimizations */ 
16301 \newline 
16302 int foo () 
16303 \newline 
16304
16305 \newline 
16306 \SpecialChar ~
16307  \SpecialChar ~
16308  ...
16309  
16310 \newline 
16311 \SpecialChar ~
16312  \SpecialChar ~
16313  /* large code */ 
16314 \newline 
16315 \SpecialChar ~
16316  \SpecialChar ~
16317  ...
16318  
16319 \newline 
16320
16321 \newline 
16322 #pragma restore
16323 \begin_inset LatexCommand \index{\#pragma restore}
16324
16325 \end_inset 
16326
16327  /* turn the optimizations back on */
16328 \layout Standard
16329
16330 The compiler will generate a warning message when extra space is allocated.
16331  It is strongly recommended that the save and restore pragma's be used when
16332  changing options for a function.
16333 \layout Section
16334
16335 Defines Created by the Compiler
16336 \layout Standard
16337
16338 The compiler creates the following #defines
16339 \begin_inset LatexCommand \index{\#defines}
16340
16341 \end_inset 
16342
16343
16344 \begin_inset LatexCommand \index{Defines created by the compiler}
16345
16346 \end_inset 
16347
16348 :
16349 \newline 
16350
16351 \layout Standard
16352
16353
16354 \begin_inset  Tabular
16355 <lyxtabular version="3" rows="11" columns="2">
16356 <features>
16357 <column alignment="left" valignment="top" leftline="true" width="0">
16358 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16359 <row topline="true" bottomline="true">
16360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16361 \begin_inset Text
16362
16363 \layout Standard
16364
16365
16366 \series bold 
16367 #define
16368 \end_inset 
16369 </cell>
16370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16371 \begin_inset Text
16372
16373 \layout Standard
16374
16375
16376 \series bold 
16377 Description
16378 \end_inset 
16379 </cell>
16380 </row>
16381 <row topline="true">
16382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16383 \begin_inset Text
16384
16385 \layout Standard
16386
16387 SDCC
16388 \begin_inset LatexCommand \index{SDCC}
16389
16390 \end_inset 
16391
16392  
16393 \end_inset 
16394 </cell>
16395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16396 \begin_inset Text
16397
16398 \layout Standard
16399
16400 Always defined.
16401  Since version 2.5.6 the version number as an int (ex.
16402  256)
16403 \end_inset 
16404 </cell>
16405 </row>
16406 <row topline="true">
16407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16408 \begin_inset Text
16409
16410 \layout Standard
16411
16412 SDCC_mcs51
16413 \begin_inset LatexCommand \index{SDCC\_mcs51}
16414
16415 \end_inset 
16416
16417  or SDCC_ds390
16418 \begin_inset LatexCommand \index{SDCC\_ds390}
16419
16420 \end_inset 
16421
16422  or SDCC_z80
16423 \begin_inset LatexCommand \index{SDCC\_z80}
16424
16425 \end_inset 
16426
16427 , etc
16428 \end_inset 
16429 </cell>
16430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16431 \begin_inset Text
16432
16433 \layout Standard
16434
16435 depending on the model used (e.g.: -mds390
16436 \end_inset 
16437 </cell>
16438 </row>
16439 <row topline="true">
16440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16441 \begin_inset Text
16442
16443 \layout Standard
16444
16445 __mcs51
16446 \begin_inset LatexCommand \index{\_\_mcs51}
16447
16448 \end_inset 
16449
16450 , __ds390
16451 \begin_inset LatexCommand \index{\_\_ds390}
16452
16453 \end_inset 
16454
16455 , __hc08
16456 \begin_inset LatexCommand \index{\_\_hc08}
16457
16458 \end_inset 
16459
16460 , __z80
16461 \begin_inset LatexCommand \index{\_\_z80}
16462
16463 \end_inset 
16464
16465 , etc
16466 \end_inset 
16467 </cell>
16468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16469 \begin_inset Text
16470
16471 \layout Standard
16472
16473 depending on the model used (e.g.
16474  -mz80)
16475 \end_inset 
16476 </cell>
16477 </row>
16478 <row topline="true">
16479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16480 \begin_inset Text
16481
16482 \layout Standard
16483
16484 SDCC_STACK_AUTO
16485 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
16486
16487 \end_inset 
16488
16489
16490 \end_inset 
16491 </cell>
16492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16493 \begin_inset Text
16494
16495 \layout Standard
16496
16497 when 
16498 \emph on 
16499 -
16500 \begin_inset ERT
16501 status Collapsed
16502
16503 \layout Standard
16504
16505 \backslash 
16506 /
16507 \end_inset 
16508
16509 -stack-auto
16510 \emph default 
16511  option is used
16512 \end_inset 
16513 </cell>
16514 </row>
16515 <row topline="true">
16516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16517 \begin_inset Text
16518
16519 \layout Standard
16520
16521 SDCC_MODEL_SMALL
16522 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
16523
16524 \end_inset 
16525
16526
16527 \end_inset 
16528 </cell>
16529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16530 \begin_inset Text
16531
16532 \layout Standard
16533
16534 when 
16535 \emph on 
16536 -
16537 \begin_inset ERT
16538 status Collapsed
16539
16540 \layout Standard
16541
16542 \backslash 
16543 /
16544 \end_inset 
16545
16546 -model-small
16547 \emph default 
16548  is used
16549 \end_inset 
16550 </cell>
16551 </row>
16552 <row topline="true">
16553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16554 \begin_inset Text
16555
16556 \layout Standard
16557
16558 SDCC_MODEL_MEDIUM
16559 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
16560
16561 \end_inset 
16562
16563
16564 \end_inset 
16565 </cell>
16566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16567 \begin_inset Text
16568
16569 \layout Standard
16570
16571 when 
16572 \emph on 
16573 -
16574 \begin_inset ERT
16575 status Collapsed
16576
16577 \layout Standard
16578
16579 \backslash 
16580 /
16581 \end_inset 
16582
16583 -model-medium
16584 \emph default 
16585  is used
16586 \end_inset 
16587 </cell>
16588 </row>
16589 <row topline="true">
16590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16591 \begin_inset Text
16592
16593 \layout Standard
16594
16595 SDCC_MODEL_LARGE
16596 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
16597
16598 \end_inset 
16599
16600
16601 \end_inset 
16602 </cell>
16603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16604 \begin_inset Text
16605
16606 \layout Standard
16607
16608 when 
16609 \emph on 
16610 -
16611 \begin_inset ERT
16612 status Collapsed
16613
16614 \layout Standard
16615
16616 \backslash 
16617 /
16618 \end_inset 
16619
16620 -model-large
16621 \emph default 
16622  is used
16623 \end_inset 
16624 </cell>
16625 </row>
16626 <row topline="true">
16627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16628 \begin_inset Text
16629
16630 \layout Standard
16631
16632 SDCC_USE_XSTACK
16633 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
16634
16635 \end_inset 
16636
16637
16638 \end_inset 
16639 </cell>
16640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16641 \begin_inset Text
16642
16643 \layout Standard
16644
16645 when 
16646 \emph on 
16647 -
16648 \begin_inset ERT
16649 status Collapsed
16650
16651 \layout Standard
16652
16653 \backslash 
16654 /
16655 \end_inset 
16656
16657 -xstack
16658 \emph default 
16659  option is used
16660 \end_inset 
16661 </cell>
16662 </row>
16663 <row topline="true">
16664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16665 \begin_inset Text
16666
16667 \layout Standard
16668
16669 SDCC_STACK_TENBIT
16670 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
16671
16672 \end_inset 
16673
16674  
16675 \end_inset 
16676 </cell>
16677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16678 \begin_inset Text
16679
16680 \layout Standard
16681
16682 when 
16683 \emph on 
16684 -mds390
16685 \emph default 
16686  is used
16687 \end_inset 
16688 </cell>
16689 </row>
16690 <row topline="true" bottomline="true">
16691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16692 \begin_inset Text
16693
16694 \layout Standard
16695
16696 SDCC_MODEL_FLAT24
16697 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
16698
16699 \end_inset 
16700
16701
16702 \end_inset 
16703 </cell>
16704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16705 \begin_inset Text
16706
16707 \layout Standard
16708
16709 when 
16710 \emph on 
16711 -mds390
16712 \emph default 
16713  is used
16714 \end_inset 
16715 </cell>
16716 </row>
16717 </lyxtabular>
16718
16719 \end_inset 
16720
16721
16722 \layout Chapter
16723
16724 Notes on supported Processors
16725 \layout Section
16726
16727 MCS51 variants
16728 \begin_inset LatexCommand \label{sub:MCS51-variants}
16729
16730 \end_inset 
16731
16732
16733 \begin_inset LatexCommand \index{MCS51 variants}
16734
16735 \end_inset 
16736
16737
16738 \layout Standard
16739
16740 MCS51 processors are available from many vendors and come in many different
16741  flavours.
16742  While they might differ considerably in respect to Special Function Registers
16743  the core MCS51 is usually not modified or is kept compatible.
16744  
16745 \layout Subsection
16746
16747 pdata access by SFR 
16748 \layout Standard
16749
16750 With the upcome of devices with internal xdata and flash memory devices
16751  using port P2
16752 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16753
16754 \end_inset 
16755
16756  as dedicated I/O port is becoming more popular.
16757  Switching the high byte for pdata
16758 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16759
16760 \end_inset 
16761
16762  access which was formerly done by port P2 is then achieved by a Special
16763  Function Register
16764 \begin_inset LatexCommand \index{sfr}
16765
16766 \end_inset 
16767
16768 .
16769  In well-established MCS51 tradition the address of this 
16770 \emph on 
16771 sfr
16772 \emph default 
16773  is where the chip designers decided to put it.
16774  Needless to say that they didn't agree on a common name either.
16775  So that the startup code can correctly initialize xdata variables, you
16776  should define an sfr with the name _XPAGE
16777 \family typewriter 
16778
16779 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
16780
16781 \end_inset 
16782
16783
16784 \family default 
16785  at the appropriate location if the default, port P2, is not used for this.
16786  Some examples are:
16787 \layout Verse
16788
16789
16790 \family typewriter 
16791 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
16792 \layout Verse
16793
16794
16795 \family typewriter 
16796 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
16797 \layout Verse
16798
16799
16800 \family typewriter 
16801 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
16802 \layout Standard
16803
16804 For more exotic implementations further customizations may be needed.
16805  See section 
16806 \begin_inset LatexCommand \ref{sub:Startup-Code}
16807
16808 \end_inset 
16809
16810  for other possibilities.
16811 \layout Subsection
16812
16813 Other Features available by SFR
16814 \layout Standard
16815
16816 Some MCS51 variants offer features like Double DPTR
16817 \begin_inset LatexCommand \index{DPTR}
16818
16819 \end_inset 
16820
16821 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
16822  These are currently not used for the MCS51 port.
16823  If you absolutely need them you can fall back to inline assembly or submit
16824  a patch to SDCC.
16825 \layout Section
16826
16827 DS400 port
16828 \layout Standard
16829
16830 The DS80C400 microcontroller has a rich set of peripherals.
16831  In its built-in ROM library it includes functions to access some of the
16832  features, among them is a TCP stack with IP4 and IP6 support.
16833  Library headers (currently in beta status) and other files are provided
16834  at 
16835 \size footnotesize 
16836
16837 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
16838
16839 \end_inset 
16840
16841 .
16842  
16843 \layout Section
16844
16845 The Z80 and gbz80 port
16846 \layout Standard
16847
16848 SDCC can target both the Zilog 
16849 \begin_inset LatexCommand \index{Z80}
16850
16851 \end_inset 
16852
16853  and the Nintendo Gameboy's Z80-like gbz80
16854 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
16855
16856 \end_inset 
16857
16858 .
16859  The Z80 port is passed through the same 
16860 \emph on 
16861 regressions tests
16862 \begin_inset LatexCommand \index{Regression test}
16863
16864 \end_inset 
16865
16866
16867 \emph default 
16868  as the MCS51 and DS390 ports, so floating point support, support for long
16869  variables and bitfield support is fine.
16870  See mailing lists and forums about interrupt routines.
16871 \layout Standard
16872
16873 As always, the code is the authoritative reference - see z80/ralloc.c and
16874  z80/gen.c.
16875  The stack
16876 \begin_inset LatexCommand \index{stack}
16877
16878 \end_inset 
16879
16880  frame is similar to that generated by the IAR Z80 compiler.
16881  IX is used as the base pointer, HL and IY are used as a temporary registers,
16882  and BC and DE are available for holding variables.
16883  Return values
16884 \begin_inset LatexCommand \index{return value}
16885
16886 \end_inset 
16887
16888  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
16889  bytes).
16890  The gbz80 port use the same set of registers for the return values, but
16891  in a different order of significance: E (one byte), DE (two bytes), or
16892  HLDE (four bytes).
16893 \layout Section
16894
16895 The HC08 port
16896 \layout Standard
16897
16898 The port to the Motorola HC08
16899 \begin_inset LatexCommand \index{HC08}
16900
16901 \end_inset 
16902
16903  family has been added in October 2003, and is still undergoing some basic
16904  development.
16905  The code generator is complete, but the register allocation is still quite
16906  unoptimized.
16907  Some of the SDCC's standard C library functions have embedded non-HC08
16908  inline assembly and so are not yet usable.
16909 \newline 
16910
16911 \newline 
16912
16913 \layout Section
16914
16915 The PIC14 port
16916 \layout Standard
16917
16918 The 14bit PIC
16919 \begin_inset LatexCommand \index{PIC14}
16920
16921 \end_inset 
16922
16923  port still requires a major effort from the development community.
16924  However it can work for very simple code.
16925 \layout Subsection
16926
16927 C code and 14bit PIC code page
16928 \begin_inset LatexCommand \index{code page (pic14)}
16929
16930 \end_inset 
16931
16932  and RAM banks
16933 \begin_inset LatexCommand \index{RAM bank (pic14)}
16934
16935 \end_inset 
16936
16937
16938 \layout Standard
16939
16940 The linker organizes allocation for the code page and RAM banks.
16941  It does not have intimate knowledge of the code flow.
16942  It will put all the code section of a single asm file into a single code
16943  page.
16944  In order to make use of multiple code pages, separate asm files must be
16945  used.
16946  The compiler treats all functions of a single C file as being in the same
16947  code page unless it is non static.
16948  The compiler treats all local variables of a single C file as being in
16949  the same RAM bank unless it is an extern.
16950 \newline 
16951
16952 \newline 
16953 To get the best follow these guide lines:
16954 \layout Enumerate
16955
16956 make local functions static, as non static functions require code page selection
16957  overhead.
16958 \layout Enumerate
16959
16960 Make local variables static as extern variables require RAM bank selection
16961  overhead.
16962 \layout Enumerate
16963
16964 For devices that have multiple code pages it is more efficient to use the
16965  same number of files as pages, i.e.
16966  for the 16F877 use 4 separate files and i.e.
16967  for the 16F874 use 2 separate files.
16968  This way the linker can put the code for each file into different code
16969  pages and the compiler can allocate reusable variables more efficiently
16970  and there's less page selection overhead.
16971  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
16972  instruction set) use 'unsigned char' whereever possible instead of 'int'.
16973 \layout Subsection
16974
16975 Creating a device include file 
16976 \layout Standard
16977
16978 For generating a device include file use the support perl script inc2h.pl
16979  kept in directory support/script.
16980 \layout Subsection
16981
16982 Interrupt code
16983 \layout Standard
16984
16985 For the interrupt function, use the keyword 'interrupt'
16986 \begin_inset LatexCommand \index{interrupt}
16987
16988 \end_inset 
16989
16990  with level number of 0 (PIC14 only has 1 interrupt so this number is only
16991  there to avoid a syntax error - it ought to be fixed).
16992  E.g.:
16993 \layout Verse
16994
16995
16996 \family typewriter 
16997 void Intr(void) interrupt 0
16998 \newline 
16999 {
17000 \newline 
17001 \SpecialChar ~
17002 \SpecialChar ~
17003 T0IF = 0; /* Clear timer interrupt */
17004 \newline 
17005 }
17006 \layout Subsection
17007
17008 Linking and assembling
17009 \layout Standard
17010
17011 For assembling you can use either GPUTILS'
17012 \begin_inset LatexCommand \index{gputils (pic tools)}
17013
17014 \end_inset 
17015
17016  gpasm.exe or MPLAB's mpasmwin.exe.
17017  GPUTILS is available from 
17018 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17019
17020 \end_inset 
17021
17022 .
17023  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17024  If you use MPLAB and an interrupt function then the linker script file
17025  vectors section will need to be enlarged to link with mplink.
17026 \newline 
17027
17028 \newline 
17029 Here is a 
17030 \family typewriter 
17031 Makefile
17032 \family default 
17033  using GPUTILS:
17034 \layout Verse
17035
17036
17037 \family typewriter 
17038 .c.o:
17039 \newline 
17040 \SpecialChar ~
17041 \SpecialChar ~
17042 \SpecialChar ~
17043 \SpecialChar ~
17044 \SpecialChar ~
17045 \SpecialChar ~
17046 \SpecialChar ~
17047 \SpecialChar ~
17048 sdcc -S -V -mpic14 -p16F877 $< 
17049 \newline 
17050 \SpecialChar ~
17051 \SpecialChar ~
17052 \SpecialChar ~
17053 \SpecialChar ~
17054 \SpecialChar ~
17055 \SpecialChar ~
17056 \SpecialChar ~
17057 \SpecialChar ~
17058 gpasm -c $*.asm
17059 \newline 
17060
17061 \newline 
17062 $(PRJ).hex: $(OBJS) 
17063 \newline 
17064 \SpecialChar ~
17065 \SpecialChar ~
17066 \SpecialChar ~
17067 \SpecialChar ~
17068 \SpecialChar ~
17069 \SpecialChar ~
17070 \SpecialChar ~
17071 \SpecialChar ~
17072 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
17073 \layout Standard
17074
17075 Here is a 
17076 \family typewriter 
17077 Makefile
17078 \family default 
17079  using MPLAB:
17080 \layout Verse
17081
17082
17083 \family typewriter 
17084 .c.o: 
17085 \newline 
17086 \SpecialChar ~
17087 \SpecialChar ~
17088 \SpecialChar ~
17089 \SpecialChar ~
17090 \SpecialChar ~
17091 \SpecialChar ~
17092 \SpecialChar ~
17093 \SpecialChar ~
17094 sdcc -S -V -mpic14 -p16F877 $< 
17095 \newline 
17096 \SpecialChar ~
17097 \SpecialChar ~
17098 \SpecialChar ~
17099 \SpecialChar ~
17100 \SpecialChar ~
17101 \SpecialChar ~
17102 \SpecialChar ~
17103 \SpecialChar ~
17104 mpasmwin /q /o $*.asm
17105 \newline 
17106
17107 \newline 
17108 $(PRJ).hex: $(OBJS) 
17109 \newline 
17110 \SpecialChar ~
17111 \SpecialChar ~
17112 \SpecialChar ~
17113 \SpecialChar ~
17114 \SpecialChar ~
17115 \SpecialChar ~
17116 \SpecialChar ~
17117 \SpecialChar ~
17118 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17119 \layout Standard
17120
17121 Please note that indentations within a
17122 \family typewriter 
17123  Makefile
17124 \family default 
17125  have to be done with a tabulator character.
17126 \layout Subsection
17127
17128 Command-line options
17129 \layout Standard
17130
17131 Besides the switches common to all SDCC backends, the PIC14 port accepts
17132  the following options (for an updated list see sdcc -
17133 \begin_inset ERT
17134 status Collapsed
17135
17136 \layout Standard
17137
17138 \backslash 
17139 /
17140 \end_inset 
17141
17142 -help):
17143 \layout List
17144 \labelwidthstring 00.00.0000
17145
17146 -
17147 \begin_inset ERT
17148 status Collapsed
17149
17150 \layout Standard
17151
17152 \backslash 
17153 /
17154 \end_inset 
17155
17156 -debug-extra emit debug info in assembly output
17157 \layout List
17158 \labelwidthstring 00.00.0000
17159
17160 -
17161 \begin_inset ERT
17162 status Collapsed
17163
17164 \layout Standard
17165
17166 \backslash 
17167 /
17168 \end_inset 
17169
17170 -no-pcode-opt disable (slightly faulty) optimization on pCode
17171 \layout Subsection
17172
17173 The library
17174 \layout Subsubsection
17175
17176 error: missing definition for symbol 
17177 \begin_inset Quotes sld
17178 \end_inset 
17179
17180 __gptrget1
17181 \begin_inset Quotes srd
17182 \end_inset 
17183
17184
17185 \layout Standard
17186
17187 The PIC14 port uses library routines to provide more complex operations
17188  like multiplication, division/modulus and (generic) pointer dereferencing.
17189  In order to add these routines to your project, you must link with PIC14's
17190  
17191 \family typewriter 
17192 libsdcc.lib
17193 \family default 
17194 .
17195  For single source file projects this is done automatically, more complex
17196  projects must add 
17197 \family typewriter 
17198 libsdcc.lib
17199 \family default 
17200  to the linker's arguments.
17201  Make sure you also add an include path for the library (using the -I switch
17202  to the linker)!
17203 \layout Subsubsection
17204
17205 Processor mismatch in file 
17206 \begin_inset Quotes sld
17207 \end_inset 
17208
17209 XXX
17210 \begin_inset Quotes srd
17211 \end_inset 
17212
17213 .
17214 \layout Standard
17215
17216 This warning can usually be ignored due to the very good compatibility amongst
17217  14 bit PIC devices.
17218 \layout Standard
17219
17220 You might also consider recompiling the library for your specific device
17221  by changing the ARCH=p16f877 (default target) entry in 
17222 \family typewriter 
17223 device/lib/pic/Makefile.in
17224 \family default 
17225  and 
17226 \family typewriter 
17227 device/lib/pic/Makefile
17228 \family default 
17229  to reflect your device.
17230  This might even improve performance for smaller devices as unneccesary
17231  BANKSELs migth be removed.
17232 \layout Subsection
17233
17234 Known bugs
17235 \layout Subsubsection
17236
17237 initialized data
17238 \layout Standard
17239
17240 Currently, data can only be initialized if it resides in the source file
17241  together with 
17242 \emph on 
17243 main()
17244 \emph default 
17245 .
17246  Data in other source files will silently 
17247 \series bold 
17248 not
17249 \series default 
17250  be initialized.
17251 \layout Section
17252
17253 The PIC16
17254 \begin_inset LatexCommand \index{PIC16}
17255
17256 \end_inset 
17257
17258  port
17259 \layout Standard
17260
17261 The PIC16
17262 \begin_inset LatexCommand \index{PIC16}
17263
17264 \end_inset 
17265
17266  port is the portion of SDCC that is responsible to produce code for the
17267  Microchip
17268 \begin_inset LatexCommand \index{Microchip}
17269
17270 \end_inset 
17271
17272 (TM) microcontrollers with 16 bit core.
17273  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
17274  Currently supported devices are:
17275 \layout Standard
17276 \align center 
17277
17278 \begin_inset  Tabular
17279 <lyxtabular version="3" rows="4" columns="6">
17280 <features>
17281 <column alignment="center" valignment="top" leftline="true" width="0">
17282 <column alignment="center" valignment="top" leftline="true" width="0">
17283 <column alignment="center" valignment="top" leftline="true" width="0">
17284 <column alignment="center" valignment="top" leftline="true" width="0">
17285 <column alignment="center" valignment="top" leftline="true" width="0">
17286 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17287 <row topline="true">
17288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17289 \begin_inset Text
17290
17291 \layout Standard
17292
17293 18F242
17294 \end_inset 
17295 </cell>
17296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17297 \begin_inset Text
17298
17299 \layout Standard
17300
17301 18F248
17302 \end_inset 
17303 </cell>
17304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17305 \begin_inset Text
17306
17307 \layout Standard
17308
17309 18F252
17310 \end_inset 
17311 </cell>
17312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17313 \begin_inset Text
17314
17315 \layout Standard
17316
17317 18F258
17318 \end_inset 
17319 </cell>
17320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17321 \begin_inset Text
17322
17323 \layout Standard
17324
17325 18F442
17326 \end_inset 
17327 </cell>
17328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17329 \begin_inset Text
17330
17331 \layout Standard
17332
17333 18F448
17334 \end_inset 
17335 </cell>
17336 </row>
17337 <row topline="true">
17338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17339 \begin_inset Text
17340
17341 \layout Standard
17342
17343 18F452
17344 \end_inset 
17345 </cell>
17346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17347 \begin_inset Text
17348
17349 \layout Standard
17350
17351 18F458
17352 \end_inset 
17353 </cell>
17354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17355 \begin_inset Text
17356
17357 \layout Standard
17358
17359 18F1220
17360 \end_inset 
17361 </cell>
17362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17363 \begin_inset Text
17364
17365 \layout Standard
17366
17367 18F2220
17368 \end_inset 
17369 </cell>
17370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17371 \begin_inset Text
17372
17373 \layout Standard
17374
17375 18F2550
17376 \end_inset 
17377 </cell>
17378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17379 \begin_inset Text
17380
17381 \layout Standard
17382
17383 18F4331
17384 \end_inset 
17385 </cell>
17386 </row>
17387 <row topline="true">
17388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17389 \begin_inset Text
17390
17391 \layout Standard
17392
17393 18F4455
17394 \end_inset 
17395 </cell>
17396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17397 \begin_inset Text
17398
17399 \layout Standard
17400
17401 18F6520
17402 \end_inset 
17403 </cell>
17404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17405 \begin_inset Text
17406
17407 \layout Standard
17408
17409 18F6620
17410 \end_inset 
17411 </cell>
17412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17413 \begin_inset Text
17414
17415 \layout Standard
17416
17417 18F6680
17418 \end_inset 
17419 </cell>
17420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17421 \begin_inset Text
17422
17423 \layout Standard
17424
17425 18F6720
17426 \end_inset 
17427 </cell>
17428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17429 \begin_inset Text
17430
17431 \layout Standard
17432
17433 18F8520
17434 \end_inset 
17435 </cell>
17436 </row>
17437 <row topline="true" bottomline="true">
17438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17439 \begin_inset Text
17440
17441 \layout Standard
17442
17443 18F8620
17444 \end_inset 
17445 </cell>
17446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17447 \begin_inset Text
17448
17449 \layout Standard
17450
17451 18F8680
17452 \end_inset 
17453 </cell>
17454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17455 \begin_inset Text
17456
17457 \layout Standard
17458
17459 18F8720
17460 \end_inset 
17461 </cell>
17462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17463 \begin_inset Text
17464
17465 \layout Standard
17466
17467 \end_inset 
17468 </cell>
17469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17470 \begin_inset Text
17471
17472 \layout Standard
17473
17474 \end_inset 
17475 </cell>
17476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17477 \begin_inset Text
17478
17479 \layout Standard
17480
17481 \end_inset 
17482 </cell>
17483 </row>
17484 </lyxtabular>
17485
17486 \end_inset 
17487
17488
17489 \layout Subsection
17490
17491 Global Options
17492 \layout Standard
17493
17494 PIC16 port supports the standard command line arguments as supposed, with
17495  the exception of certain cases that will be mentioned in the following
17496  list:
17497 \layout List
17498 \labelwidthstring 00.00.0000
17499
17500 -
17501 \begin_inset ERT
17502 status Collapsed
17503
17504 \layout Standard
17505
17506 \backslash 
17507 /
17508 \end_inset 
17509
17510 -callee-saves See -
17511 \begin_inset ERT
17512 status Collapsed
17513
17514 \layout Standard
17515
17516 \backslash 
17517 /
17518 \end_inset 
17519
17520 -all-callee-saves
17521 \layout List
17522 \labelwidthstring 00.00.0000
17523
17524 -
17525 \begin_inset ERT
17526 status Collapsed
17527
17528 \layout Standard
17529
17530 \backslash 
17531 /
17532 \end_inset 
17533
17534 -all-callee-saves All function arguments are passed on stack by default.
17535  
17536 \emph on 
17537 There is no need to specify this in the command line.
17538 \layout List
17539 \labelwidthstring 00.00.0000
17540
17541 -
17542 \begin_inset ERT
17543 status Collapsed
17544
17545 \layout Standard
17546
17547 \backslash 
17548 /
17549 \end_inset 
17550
17551 -fommit-frame-pointer Frame pointer will be omitted when the function uses
17552  no local variables.
17553 \layout Subsection
17554
17555 Port Specific Options
17556 \begin_inset LatexCommand \index{Options PIC16}
17557
17558 \end_inset 
17559
17560
17561 \layout Standard
17562
17563 The port specific options appear after the global options in the sdcc --help
17564  output.
17565 \layout Subsubsection
17566
17567 General Options
17568 \layout Standard
17569
17570 General options enable certain port features and optimizations.
17571 \layout List
17572 \labelwidthstring 00.00.0000
17573
17574 -
17575 \begin_inset ERT
17576 status Collapsed
17577
17578 \layout Standard
17579
17580 \backslash 
17581 /
17582 \end_inset 
17583
17584 -stack-model=[model] Used in conjuction with the command above.
17585  Defines the stack model to be used, valid stack models are : 
17586 \begin_deeper 
17587 \layout List
17588 \labelwidthstring 00.00.0000
17589
17590
17591 \emph on 
17592 small
17593 \emph default 
17594  Selects small stack model.
17595  8 bit stack and frame pointers.
17596  Supports 256 bytes stack size.
17597 \layout List
17598 \labelwidthstring 00.00.0000
17599
17600
17601 \emph on 
17602 large
17603 \emph default 
17604  Selects large stack model.
17605  16 bit stack and frame pointers.
17606  Supports 65536 bytes stack size.
17607 \end_deeper 
17608 \layout List
17609 \labelwidthstring 00.00.0000
17610
17611 -
17612 \begin_inset ERT
17613 status Collapsed
17614
17615 \layout Standard
17616
17617 \backslash 
17618 /
17619 \end_inset 
17620
17621 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
17622  unitialized data variables with [kword].
17623  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
17624 \layout List
17625 \labelwidthstring 00.00.0000
17626
17627 -
17628 \begin_inset ERT
17629 status Collapsed
17630
17631 \layout Standard
17632
17633 \backslash 
17634 /
17635 \end_inset 
17636
17637 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
17638  Useful for bootloaders.
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 -asm= sets the full path and name of an external assembler to call.
17653 \layout List
17654 \labelwidthstring 00.00.0000
17655
17656 -
17657 \begin_inset ERT
17658 status Collapsed
17659
17660 \layout Standard
17661
17662 \backslash 
17663 /
17664 \end_inset 
17665
17666 -link= sets the full path and name of an external linker to call.
17667 \layout List
17668 \labelwidthstring 00.00.0000
17669
17670 -
17671 \begin_inset ERT
17672 status Collapsed
17673
17674 \layout Standard
17675
17676 \backslash 
17677 /
17678 \end_inset 
17679
17680 -mplab-comp MPLAB compatibility option.
17681  Currently only suppresses special gpasm directives.
17682 \layout Subsubsection
17683
17684 Optimization Options
17685 \layout List
17686 \labelwidthstring 00.00.0000
17687
17688 -
17689 \begin_inset ERT
17690 status Collapsed
17691
17692 \layout Standard
17693
17694 \backslash 
17695 /
17696 \end_inset 
17697
17698 -optimize-goto Try to use (conditional) BRA instead of GOTO
17699 \layout List
17700 \labelwidthstring 00.00.0000
17701
17702 -
17703 \begin_inset ERT
17704 status Collapsed
17705
17706 \layout Standard
17707
17708 \backslash 
17709 /
17710 \end_inset 
17711
17712 -optimize-cmp Try to optimize some compares.
17713 \layout List
17714 \labelwidthstring 00.00.0000
17715
17716 -
17717 \begin_inset ERT
17718 status Collapsed
17719
17720 \layout Standard
17721
17722 \backslash 
17723 /
17724 \end_inset 
17725
17726 -optimize-df Analyze the dataflow of the generated code and improve it.
17727 \layout List
17728 \labelwidthstring 00.00.0000
17729
17730 -
17731 \begin_inset ERT
17732 status Collapsed
17733
17734 \layout Standard
17735
17736 \backslash 
17737 /
17738 \end_inset 
17739
17740 -obanksel=nn Set optimization level for inserting BANKSELs.
17741 \newline 
17742
17743 \begin_deeper 
17744 \layout List
17745 \labelwidthstring 00.00.0000
17746
17747 0 no optimization
17748 \layout List
17749 \labelwidthstring 00.00.0000
17750
17751 1 checks previous used register and if it is the same then does not emit
17752  BANKSEL, accounts only for labels.
17753 \layout List
17754 \labelwidthstring 00.00.0000
17755
17756 2 tries to check the location of (even different) symbols and removes BANKSELs
17757  if they are in the same bank.
17758  
17759 \newline 
17760
17761 \emph on 
17762 Important: There might be problems if the linker script has data sections
17763  across bank borders!
17764 \end_deeper 
17765 \layout Subsubsection
17766
17767 Linking Options
17768 \layout List
17769 \labelwidthstring 00.00.0000
17770
17771 -
17772 \begin_inset ERT
17773 status Collapsed
17774
17775 \layout Standard
17776
17777 \backslash 
17778 /
17779 \end_inset 
17780
17781 -nodefaultlibs do not link default libraries when linking
17782 \layout List
17783 \labelwidthstring 00.00.0000
17784
17785 -
17786 \begin_inset ERT
17787 status Collapsed
17788
17789 \layout Standard
17790
17791 \backslash 
17792 /
17793 \end_inset 
17794
17795 -no-crt Don't link the default run-time modules
17796 \layout List
17797 \labelwidthstring 00.00.0000
17798
17799 -
17800 \begin_inset ERT
17801 status Collapsed
17802
17803 \layout Standard
17804
17805 \backslash 
17806 /
17807 \end_inset 
17808
17809 -use-crt= Use a custom run-time module instead of the defaults.
17810 \layout Subsubsection
17811
17812 Debugging Options
17813 \layout Standard
17814
17815 Debugging options enable extra debugging information in the output files.
17816 \layout List
17817 \labelwidthstring 00.00.0000
17818
17819 -
17820 \begin_inset ERT
17821 status Collapsed
17822
17823 \layout Standard
17824
17825 \backslash 
17826 /
17827 \end_inset 
17828
17829 -debug-xtra Similar to -
17830 \begin_inset ERT
17831 status Collapsed
17832
17833 \layout Standard
17834
17835 \backslash 
17836 /
17837 \end_inset 
17838
17839 -debug
17840 \begin_inset LatexCommand \index{-\/-debug}
17841
17842 \end_inset 
17843
17844 , but dumps more information.
17845 \layout List
17846 \labelwidthstring 00.00.0000
17847
17848 -
17849 \begin_inset ERT
17850 status Collapsed
17851
17852 \layout Standard
17853
17854 \backslash 
17855 /
17856 \end_inset 
17857
17858 -debug-ralloc Force register allocator to dump <source>.d file with debugging
17859  information.
17860  <source> is the name of the file compiled.
17861 \layout List
17862 \labelwidthstring 00.00.0000
17863
17864 -
17865 \begin_inset ERT
17866 status Collapsed
17867
17868 \layout Standard
17869
17870 \backslash 
17871 /
17872 \end_inset 
17873
17874 -pcode-verbose Enable pcode debugging information in translation.
17875 \layout List
17876 \labelwidthstring 00.00.0000
17877
17878 -
17879 \begin_inset ERT
17880 status Collapsed
17881
17882 \layout Standard
17883
17884 \backslash 
17885 /
17886 \end_inset 
17887
17888 -denable-peeps Force the usage of peepholes.
17889  Use with care.
17890 \layout List
17891 \labelwidthstring 00.00.0000
17892
17893 -
17894 \begin_inset ERT
17895 status Collapsed
17896
17897 \layout Standard
17898
17899 \backslash 
17900 /
17901 \end_inset 
17902
17903 -gstack Trace push/pops for stack pointer overflow
17904 \layout List
17905 \labelwidthstring 00.00.0000
17906
17907 -
17908 \begin_inset ERT
17909 status Collapsed
17910
17911 \layout Standard
17912
17913 \backslash 
17914 /
17915 \end_inset 
17916
17917 -call-tree dump call tree in .calltree file
17918 \layout Subsection
17919
17920 Enviromental Variables
17921 \layout Standard
17922
17923 There is a number of enviromental variables that can be used when running
17924  SDCC to enable certain optimizations or force a specific program behaviour.
17925  these variables are primarily for debugging purposes so they can be enabled/dis
17926 abled at will.
17927 \layout Standard
17928
17929 Currently there is only two such variables available:
17930 \layout List
17931 \labelwidthstring 00.00.0000
17932
17933 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
17934  bitfields is optimized by directly loading FSR0 with the address of the
17935  bitfield structure.
17936  Normally SDCC will cast the bitfield structure to a bitfield pointer and
17937  then load FSR0.
17938  This step saves data ram and code space for functions that perform heavy
17939  use of bitfields.
17940  (ie.
17941  80 bytes of code space are saved when compiling malloc.c with this option).
17942  
17943 \layout List
17944 \labelwidthstring 00.00.0000
17945
17946 NO_REG_OPT do not perform pCode registers optimization.
17947  This should be used for debugging purposes.
17948  In some where bugs in the pcode optimizer are found, users can benefit
17949  from temporarily disabling the optimizer until the bug is fixed.
17950 \layout Subsection
17951
17952 Preprocessor Macros
17953 \layout Standard
17954
17955 PIC16 port defines the following preprocessor macros while translating a
17956  source.
17957 \layout Standard
17958 \align center 
17959
17960 \begin_inset  Tabular
17961 <lyxtabular version="3" rows="6" columns="2">
17962 <features>
17963 <column alignment="center" valignment="top" leftline="true" width="0">
17964 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17965 <row topline="true" bottomline="true">
17966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17967 \begin_inset Text
17968
17969 \layout Standard
17970
17971 Macro
17972 \end_inset 
17973 </cell>
17974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17975 \begin_inset Text
17976
17977 \layout Standard
17978
17979 Description
17980 \end_inset 
17981 </cell>
17982 </row>
17983 <row topline="true">
17984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17985 \begin_inset Text
17986
17987 \layout Standard
17988
17989 SDCC_pic16
17990 \end_inset 
17991 </cell>
17992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17993 \begin_inset Text
17994
17995 \layout Standard
17996
17997 Port identification
17998 \end_inset 
17999 </cell>
18000 </row>
18001 <row topline="true">
18002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18003 \begin_inset Text
18004
18005 \layout Standard
18006
18007 _
18008 \begin_inset ERT
18009 status Collapsed
18010
18011 \layout Standard
18012
18013 \backslash 
18014 /
18015 \end_inset 
18016
18017 _pic16
18018 \end_inset 
18019 </cell>
18020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18021 \begin_inset Text
18022
18023 \layout Standard
18024
18025 Port identification (same as above)
18026 \end_inset 
18027 </cell>
18028 </row>
18029 <row topline="true">
18030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18031 \begin_inset Text
18032
18033 \layout Standard
18034
18035 pic18fxxxx
18036 \end_inset 
18037 </cell>
18038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18039 \begin_inset Text
18040
18041 \layout Standard
18042
18043 MCU Identification.
18044  
18045 \emph on 
18046 xxxx
18047 \emph default 
18048  is the microcontrol identification number, i.e.
18049  452, 6620, etc
18050 \end_inset 
18051 </cell>
18052 </row>
18053 <row topline="true">
18054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18055 \begin_inset Text
18056
18057 \layout Standard
18058
18059 _
18060 \begin_inset ERT
18061 status Collapsed
18062
18063 \layout Standard
18064
18065 \backslash 
18066 /
18067 \end_inset 
18068
18069 _18Fxxxx
18070 \end_inset 
18071 </cell>
18072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18073 \begin_inset Text
18074
18075 \layout Standard
18076
18077 MCU Identification (same as above)
18078 \end_inset 
18079 </cell>
18080 </row>
18081 <row topline="true" bottomline="true">
18082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18083 \begin_inset Text
18084
18085 \layout Standard
18086
18087 STACK_MODEL_nnn
18088 \end_inset 
18089 </cell>
18090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18091 \begin_inset Text
18092
18093 \layout Standard
18094
18095 nnn = SMALL or LARGE respectively according to the stack model used
18096 \end_inset 
18097 </cell>
18098 </row>
18099 </lyxtabular>
18100
18101 \end_inset 
18102
18103
18104 \layout Standard
18105
18106 In addition the following macros are defined when calling assembler:
18107 \layout Standard
18108 \align center 
18109
18110 \begin_inset  Tabular
18111 <lyxtabular version="3" rows="4" columns="2">
18112 <features>
18113 <column alignment="center" valignment="top" leftline="true" width="0">
18114 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18115 <row topline="true" bottomline="true">
18116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18117 \begin_inset Text
18118
18119 \layout Standard
18120
18121 Macro
18122 \end_inset 
18123 </cell>
18124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18125 \begin_inset Text
18126
18127 \layout Standard
18128
18129 Description
18130 \end_inset 
18131 </cell>
18132 </row>
18133 <row topline="true">
18134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18135 \begin_inset Text
18136
18137 \layout Standard
18138
18139 __18Fxxxx
18140 \end_inset 
18141 </cell>
18142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18143 \begin_inset Text
18144
18145 \layout Standard
18146
18147 MCU Identification.
18148  
18149 \emph on 
18150 xxxx
18151 \emph default 
18152  is the microcontrol identification number, i.e.
18153  452, 6620, etc
18154 \end_inset 
18155 </cell>
18156 </row>
18157 <row topline="true">
18158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18159 \begin_inset Text
18160
18161 \layout Standard
18162
18163 SDCC_MODEL_nnn
18164 \end_inset 
18165 </cell>
18166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18167 \begin_inset Text
18168
18169 \layout Standard
18170
18171 nnn = SMALL or LARGE respectively according to the memory model used for
18172  SDCC
18173 \end_inset 
18174 </cell>
18175 </row>
18176 <row topline="true" bottomline="true">
18177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18178 \begin_inset Text
18179
18180 \layout Standard
18181
18182 STACK_MODEL_nnn
18183 \end_inset 
18184 </cell>
18185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18186 \begin_inset Text
18187
18188 \layout Standard
18189
18190 nnn = SMALL or LARGE respectively according to the stack model used
18191 \end_inset 
18192 </cell>
18193 </row>
18194 </lyxtabular>
18195
18196 \end_inset 
18197
18198
18199 \layout Subsection
18200
18201 Directories
18202 \layout Standard
18203
18204 PIC16
18205 \begin_inset LatexCommand \index{PIC16}
18206
18207 \end_inset 
18208
18209  port uses the following directories for searching header files and libraries.
18210 \layout Standard
18211 \align center 
18212
18213 \begin_inset  Tabular
18214 <lyxtabular version="3" rows="3" columns="4">
18215 <features>
18216 <column alignment="center" valignment="top" leftline="true" width="0">
18217 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18218 <column alignment="center" valignment="top" width="0">
18219 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18220 <row topline="true" bottomline="true">
18221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18222 \begin_inset Text
18223
18224 \layout Standard
18225
18226 Directory
18227 \end_inset 
18228 </cell>
18229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18230 \begin_inset Text
18231
18232 \layout Standard
18233
18234 Description
18235 \end_inset 
18236 </cell>
18237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18238 \begin_inset Text
18239
18240 \layout Standard
18241
18242 Target
18243 \end_inset 
18244 </cell>
18245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18246 \begin_inset Text
18247
18248 \layout Standard
18249
18250 Command prefix
18251 \end_inset 
18252 </cell>
18253 </row>
18254 <row topline="true">
18255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18256 \begin_inset Text
18257
18258 \layout Standard
18259
18260 PREFIX/sdcc/include/pic16
18261 \end_inset 
18262 </cell>
18263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18264 \begin_inset Text
18265
18266 \layout Standard
18267
18268 PIC16 specific headers
18269 \end_inset 
18270 </cell>
18271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18272 \begin_inset Text
18273
18274 \layout Standard
18275
18276 Compiler
18277 \end_inset 
18278 </cell>
18279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18280 \begin_inset Text
18281
18282 \layout Standard
18283
18284 -I
18285 \end_inset 
18286 </cell>
18287 </row>
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 PREFIX/sdcc/lib/pic16
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 PIC16 specific libraries
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 Linker
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 -L
18319 \end_inset 
18320 </cell>
18321 </row>
18322 </lyxtabular>
18323
18324 \end_inset 
18325
18326
18327 \layout Subsection
18328
18329 Pragmas
18330 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
18331
18332 \end_inset 
18333
18334
18335 \layout Standard
18336
18337 PIC16 port currently supports the following pragmas:
18338 \layout List
18339 \labelwidthstring 00.00.0000
18340
18341 stack pragma stack forces the code generator to initialize the stack & frame
18342  pointers at a specific address.
18343  This is an adhoc solution for cases where no STACK directive is available
18344  in the linker script or gplink is not instructed to create a stack section.
18345 \newline 
18346 The stack pragma should be used only once in a project.
18347  Multiple pragmas may result in indeterminate behaviour of the program.
18348 \begin_inset Foot
18349 collapsed false
18350
18351 \layout Standard
18352
18353 The old format (ie.
18354  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
18355  cross page boundaries (or even exceed the available data RAM) and crash
18356  the program.
18357  Make sure that stack does not cross page boundaries when using the SMALL
18358  stack model.
18359 \end_inset 
18360
18361
18362 \newline 
18363 The format is as follows:
18364 \layout LyX-Code
18365
18366 #pragma stack bottom_address [stack_size]
18367 \layout Standard
18368
18369
18370 \emph on 
18371 bottom_address
18372 \emph default 
18373  is the lower bound of the stack section.
18374  The stack pointer initially will point at address (bottom_address+stack_size-1).
18375 \layout LyX-Code
18376
18377 Example:
18378 \layout LyX-Code
18379
18380 \layout LyX-Code
18381
18382 /* initializes stack of 100 bytes at RAM address 0x200 */
18383 \layout LyX-Code
18384
18385 #pragma stack 0x200 100
18386 \layout Standard
18387
18388 If the stack_size field is omitted then a stack is created with the default
18389  size of 64.
18390  This size might be enough for most programs, but its not enough for operations
18391  with deep function nesting or excessive stack usage.
18392 \layout List
18393 \labelwidthstring 00.00.0000
18394
18395 wparam 
18396 \emph on 
18397 This pragma is deprecated.
18398  Its use will cause a warning message to be issued.
18399 \emph default 
18400
18401 \newline 
18402
18403 \layout List
18404 \labelwidthstring 00.00.0000
18405
18406 code place a function symbol at static FLASH address
18407 \layout LyX-Code
18408
18409 Example:
18410 \layout LyX-Code
18411
18412 \layout LyX-Code
18413
18414 /* place function test_func at 0x4000 */
18415 \layout LyX-Code
18416
18417 #pragma code test_func 0x4000
18418 \layout LyX-Code
18419
18420 \layout List
18421 \labelwidthstring 00.00.0000
18422
18423 library instructs the linker to use a library module.
18424 \newline 
18425 Usage:
18426 \layout LyX-Code
18427
18428 #pragma library module_name
18429 \layout Standard
18430
18431
18432 \emph on 
18433 module_name
18434 \emph default 
18435  can be any library or object file (including its path).
18436  Note that there are four reserved keywords which have special meaning.
18437  These are:
18438 \layout Standard
18439 \align center 
18440
18441 \begin_inset  Tabular
18442 <lyxtabular version="3" rows="6" columns="3">
18443 <features>
18444 <column alignment="center" valignment="top" leftline="true" width="0">
18445 <column alignment="block" valignment="top" leftline="true" width="20page%">
18446 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18447 <row topline="true" bottomline="true">
18448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18449 \begin_inset Text
18450
18451 \layout Standard
18452
18453 Keyword
18454 \end_inset 
18455 </cell>
18456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18457 \begin_inset Text
18458
18459 \layout Standard
18460
18461 Description
18462 \end_inset 
18463 </cell>
18464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18465 \begin_inset Text
18466
18467 \layout Standard
18468
18469 Module to link
18470 \end_inset 
18471 </cell>
18472 </row>
18473 <row topline="true">
18474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18475 \begin_inset Text
18476
18477 \layout Standard
18478
18479
18480 \series bold 
18481 ignore
18482 \end_inset 
18483 </cell>
18484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18485 \begin_inset Text
18486
18487 \layout Standard
18488
18489 ignore all library pragmas
18490 \end_inset 
18491 </cell>
18492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18493 \begin_inset Text
18494
18495 \layout Standard
18496
18497
18498 \emph on 
18499 (none)
18500 \end_inset 
18501 </cell>
18502 </row>
18503 <row topline="true">
18504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18505 \begin_inset Text
18506
18507 \layout Standard
18508
18509
18510 \series bold 
18511 c
18512 \end_inset 
18513 </cell>
18514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18515 \begin_inset Text
18516
18517 \layout Standard
18518
18519 link the C library
18520 \end_inset 
18521 </cell>
18522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18523 \begin_inset Text
18524
18525 \layout Standard
18526
18527
18528 \emph on 
18529 libc18f
18530 \emph default 
18531 .lib
18532 \end_inset 
18533 </cell>
18534 </row>
18535 <row topline="true">
18536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18537 \begin_inset Text
18538
18539 \layout Standard
18540
18541
18542 \series bold 
18543 math
18544 \end_inset 
18545 </cell>
18546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18547 \begin_inset Text
18548
18549 \layout Standard
18550
18551 link the Math libarary
18552 \end_inset 
18553 </cell>
18554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18555 \begin_inset Text
18556
18557 \layout Standard
18558
18559
18560 \emph on 
18561 libm18f
18562 \emph default 
18563 .lib
18564 \end_inset 
18565 </cell>
18566 </row>
18567 <row topline="true">
18568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18569 \begin_inset Text
18570
18571 \layout Standard
18572
18573
18574 \series bold 
18575 io
18576 \end_inset 
18577 </cell>
18578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18579 \begin_inset Text
18580
18581 \layout Standard
18582
18583 link the I/O library
18584 \end_inset 
18585 </cell>
18586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18587 \begin_inset Text
18588
18589 \layout Standard
18590
18591
18592 \emph on 
18593 libio18f*
18594 \emph default 
18595 .lib
18596 \end_inset 
18597 </cell>
18598 </row>
18599 <row topline="true" bottomline="true">
18600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18601 \begin_inset Text
18602
18603 \layout Standard
18604
18605
18606 \series bold 
18607 debug
18608 \end_inset 
18609 </cell>
18610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18611 \begin_inset Text
18612
18613 \layout Standard
18614
18615 link the debug library
18616 \end_inset 
18617 </cell>
18618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18619 \begin_inset Text
18620
18621 \layout Standard
18622
18623
18624 \emph on 
18625 libdebug
18626 \emph default 
18627 .lib
18628 \end_inset 
18629 </cell>
18630 </row>
18631 </lyxtabular>
18632
18633 \end_inset 
18634
18635
18636 \newline 
18637 * is the device number, i.e.
18638  452 for PIC18F452 MCU.
18639 \layout Standard
18640
18641 This feature allows for linking with specific libraries withoug having to
18642  explicit name them in the command line.
18643  Note that the 
18644 \noun on 
18645 ignore
18646 \noun default 
18647  keyword will reject all modules specified by the library pragma.
18648 \layout List
18649 \labelwidthstring 00.00.0000
18650
18651 udata pragma udata instructs the compiler to emit code so that linker will
18652  place a variable at a specific memory bank
18653 \layout LyX-Code
18654
18655 Example:
18656 \layout LyX-Code
18657
18658 \layout LyX-Code
18659
18660 /* places variable foo at bank2 */
18661 \layout LyX-Code
18662
18663 #pragma udata bank2 foo
18664 \layout LyX-Code
18665
18666 char foo;
18667 \layout Standard
18668
18669 In order for this pragma to work extra SECTION directives should be added
18670  in the .lkr script.
18671  In the following example a sample .lkr file is shown:
18672 \layout LyX-Code
18673
18674 \layout LyX-Code
18675
18676 // Sample linker script for the PIC18F452 processor
18677 \layout LyX-Code
18678
18679 LIBPATH .
18680 \layout LyX-Code
18681
18682 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
18683 \layout LyX-Code
18684
18685 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
18686 \layout LyX-Code
18687
18688 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
18689 \layout LyX-Code
18690
18691 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
18692 \layout LyX-Code
18693
18694 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
18695 \layout LyX-Code
18696
18697 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
18698 \layout LyX-Code
18699
18700 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
18701 \layout LyX-Code
18702
18703 \layout LyX-Code
18704
18705 DATABANK   NAME=gpr0       START=0x80           END=0xFF
18706 \layout LyX-Code
18707
18708 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
18709 \layout LyX-Code
18710
18711 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
18712 \layout LyX-Code
18713
18714 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
18715 \layout LyX-Code
18716
18717 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
18718 \layout LyX-Code
18719
18720 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
18721 \layout LyX-Code
18722
18723 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
18724 \layout LyX-Code
18725
18726 \layout LyX-Code
18727
18728 SECTION    NAME=CONFIG     ROM=config
18729 \layout LyX-Code
18730
18731 \layout LyX-Code
18732
18733 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
18734 \layout LyX-Code
18735
18736 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
18737 \layout LyX-Code
18738
18739 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
18740 \layout LyX-Code
18741
18742 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
18743 \layout LyX-Code
18744
18745 SECTION    NAME=bank4      RAM=gpr4
18746 \layout LyX-Code
18747
18748 SECTION    NAME=bank5      RAM=gpr5
18749 \layout Standard
18750
18751 The linker will recognise the section name set in the pragma statement and
18752  will position the variable at the memory bank set with the RAM field at
18753  the SECTION line in the linker script file.
18754 \layout Subsection
18755
18756 Header Files
18757 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
18758
18759 \end_inset 
18760
18761
18762 \layout Standard
18763
18764 There is one main header file that can be included to the source files using
18765  the pic16 port.
18766  That file is the 
18767 \series bold 
18768 pic18fregs.h
18769 \series default 
18770 .
18771  This header file contains the definitions for the processor special registers,
18772  so it is necessary if the source accesses them.
18773  It can be included by adding the following line in the beginning of the
18774  file:
18775 \layout LyX-Code
18776
18777 #include <pic18fregs.h>
18778 \layout Standard
18779
18780 The specific microcontroller is selected within the pic18fregs.h automatically,
18781  so the same source can be used with a variety of devices.
18782 \layout Subsection
18783
18784 Libraries
18785 \layout Standard
18786
18787 The libraries that PIC16
18788 \begin_inset LatexCommand \index{PIC16}
18789
18790 \end_inset 
18791
18792  port depends on are the microcontroller device libraries which contain
18793  the symbol definitions for the microcontroller special function registers.
18794  These libraries have the format pic18fxxxx.lib, where 
18795 \emph on 
18796 xxxx
18797 \emph default 
18798  is the microcontroller identification number.
18799  The specific library is selected automatically by the compiler at link
18800  stage according to the selected device.
18801 \layout Standard
18802
18803 Libraries are created with gplib which is part of the gputils package 
18804 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
18805
18806 \end_inset 
18807
18808 .
18809 \layout Subsubsection*
18810
18811 Building the libraries
18812 \layout Standard
18813
18814 Before using SDCC/pic16 there are some libraries that need to be compiled.
18815  This process is not done automatically by SDCC since not all users use
18816  SDCC for pic16 projects.
18817  So each user should compile the libraries separately.
18818 \layout Standard
18819
18820 The steps to compile the pic16 libraries under Linux are:
18821 \layout LyX-Code
18822
18823 cd device/lib/pic16
18824 \layout LyX-Code
18825
18826 ./configure
18827 \layout LyX-Code
18828
18829 make
18830 \layout LyX-Code
18831
18832 cd ..
18833 \layout LyX-Code
18834
18835 make model-pic16
18836 \layout LyX-Code
18837
18838 su -c 'make install'     # install the libraries, you need the root password
18839 \layout Standard
18840
18841 If you need to install the headers too, do:
18842 \layout LyX-Code
18843
18844 cd device/include
18845 \layout LyX-Code
18846
18847 su -c 'make install'     # install the headers, you need the root password
18848 \layout Standard
18849
18850 There exist a special target to build the I/O libraries.
18851  This target is not automatically build because it will build the I/O library
18852  for 
18853 \emph on 
18854 every
18855 \emph default 
18856  supported device.
18857  This way building will take quite a lot of time.
18858  Users are advised to edit the 
18859 \series bold 
18860 device/lib/pic16/pics.build
18861 \series default 
18862  file and then execute:
18863 \layout LyX-Code
18864
18865 make lib-io
18866 \layout Subsection
18867
18868 Memory Models
18869 \layout Standard
18870
18871 The following memory models are supported by the PIC16 port:
18872 \layout Itemize
18873
18874 small model
18875 \layout Itemize
18876
18877 large model
18878 \layout Standard
18879
18880 Memory model affects the default size of pointers within the source.
18881  The sizes are shown in the next table:
18882 \layout Standard
18883 \align center 
18884
18885 \begin_inset  Tabular
18886 <lyxtabular version="3" rows="3" columns="3">
18887 <features>
18888 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18889 <column alignment="center" valignment="top" leftline="true" width="0">
18890 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18891 <row topline="true" bottomline="true">
18892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18893 \begin_inset Text
18894
18895 \layout Standard
18896
18897 Pointer sizes according to memory model
18898 \end_inset 
18899 </cell>
18900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18901 \begin_inset Text
18902
18903 \layout Standard
18904
18905 small model
18906 \end_inset 
18907 </cell>
18908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18909 \begin_inset Text
18910
18911 \layout Standard
18912
18913 large model
18914 \end_inset 
18915 </cell>
18916 </row>
18917 <row topline="true" bottomline="true">
18918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18919 \begin_inset Text
18920
18921 \layout Standard
18922
18923 code pointers
18924 \end_inset 
18925 </cell>
18926 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18927 \begin_inset Text
18928
18929 \layout Standard
18930
18931 16-bits
18932 \end_inset 
18933 </cell>
18934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18935 \begin_inset Text
18936
18937 \layout Standard
18938
18939 24-bits
18940 \end_inset 
18941 </cell>
18942 </row>
18943 <row topline="true" bottomline="true">
18944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18945 \begin_inset Text
18946
18947 \layout Standard
18948
18949 data pointers
18950 \end_inset 
18951 </cell>
18952 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
18953 \begin_inset Text
18954
18955 \layout Standard
18956
18957 16-bits
18958 \end_inset 
18959 </cell>
18960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18961 \begin_inset Text
18962
18963 \layout Standard
18964
18965 16-bits
18966 \end_inset 
18967 </cell>
18968 </row>
18969 </lyxtabular>
18970
18971 \end_inset 
18972
18973
18974 \layout Standard
18975
18976 It is advisable that all sources within a project are compiled with the
18977  same memory model.
18978  If one wants to override the default memory model, this can be done by
18979  declaring a pointer as 
18980 \series bold 
18981 far
18982 \series default 
18983  or 
18984 \series bold 
18985 near
18986 \series default 
18987 .
18988  Far selects large memory model's pointers, while near selects small memory
18989  model's pointers.
18990 \layout Standard
18991
18992 The standard device libraries (see 
18993 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
18994
18995 \end_inset 
18996
18997 ) contain no reference to pointers, so they can be used with both memory
18998  models.
18999 \layout Subsection
19000
19001 Stack
19002 \layout Standard
19003
19004 The stack implementation for the PIC16 port uses two indirect registers,
19005  FSR1 and FSR2.
19006 \layout List
19007 \labelwidthstring 00.00.0000
19008
19009 FSR1 is assigned as stack pointer
19010 \layout List
19011 \labelwidthstring 00.00.0000
19012
19013 FSR2 is assigned as frame pointer
19014 \layout Standard
19015
19016 The following stack models are supported by the PIC16 port
19017 \layout Itemize
19018
19019
19020 \noun on 
19021 small
19022 \noun default 
19023  model
19024 \layout Itemize
19025
19026
19027 \noun on 
19028 large
19029 \noun default 
19030  model
19031 \layout Standard
19032
19033
19034 \noun on 
19035 Small
19036 \noun default 
19037  model means that only the FSRxL byte is used to access stack and frame,
19038  while 
19039 \emph on 
19040 \noun on 
19041 large
19042 \emph default 
19043 \noun default 
19044  uses both FSRxL and FSRxH registers.
19045  The following table shows the stack/frame pointers sizes according to stack
19046  model and the maximum space they can address:
19047 \layout Standard
19048 \align center 
19049
19050 \begin_inset  Tabular
19051 <lyxtabular version="3" rows="3" columns="3">
19052 <features>
19053 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19054 <column alignment="center" valignment="top" leftline="true" width="0">
19055 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19056 <row topline="true" bottomline="true">
19057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19058 \begin_inset Text
19059
19060 \layout Standard
19061
19062 Stack & Frame pointer sizes according to stack model
19063 \end_inset 
19064 </cell>
19065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19066 \begin_inset Text
19067
19068 \layout Standard
19069
19070 small
19071 \end_inset 
19072 </cell>
19073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19074 \begin_inset Text
19075
19076 \layout Standard
19077
19078 large
19079 \end_inset 
19080 </cell>
19081 </row>
19082 <row topline="true">
19083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19084 \begin_inset Text
19085
19086 \layout Standard
19087
19088 Stack pointer FSR1
19089 \end_inset 
19090 </cell>
19091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19092 \begin_inset Text
19093
19094 \layout Standard
19095
19096 8-bits
19097 \end_inset 
19098 </cell>
19099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19100 \begin_inset Text
19101
19102 \layout Standard
19103
19104 16-bits
19105 \end_inset 
19106 </cell>
19107 </row>
19108 <row topline="true" bottomline="true">
19109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19110 \begin_inset Text
19111
19112 \layout Standard
19113
19114 Frame pointer FSR2
19115 \end_inset 
19116 </cell>
19117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19118 \begin_inset Text
19119
19120 \layout Standard
19121
19122 8-bits
19123 \end_inset 
19124 </cell>
19125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19126 \begin_inset Text
19127
19128 \layout Standard
19129
19130 16-bits
19131 \end_inset 
19132 </cell>
19133 </row>
19134 </lyxtabular>
19135
19136 \end_inset 
19137
19138
19139 \layout Standard
19140
19141
19142 \noun on 
19143 Large 
19144 \noun default 
19145 stack model is currently not working properly throughout the code generator.
19146  So its use is not advised.
19147  Also there are some other points that need special care:
19148 \newline 
19149
19150 \layout Enumerate
19151
19152 Do not create stack sections with size more than one physical bank (that
19153  is 256 bytes)
19154 \layout Enumerate
19155
19156 Stack sections should no cross physical bank limits (i.e.
19157  #pragma stack 0x50 0x100)
19158 \layout Standard
19159
19160 These limitations are caused by the fact that only FSRxL is modified when
19161  using SMALL stack model, so no more than 256 bytes of stack can be used.
19162  This problem will disappear after LARGE model is fully implemented.
19163 \layout Subsection
19164
19165 Functions
19166 \layout Standard
19167
19168 In addition to the standard SDCC function keywords, PIC16 port makes available
19169  two more:
19170 \layout List
19171 \labelwidthstring 00.00.0000
19172
19173 wparam Use the WREG to pass one byte of the first function argument.
19174  This improves speed but you may not use this for functions with arguments
19175  that are called via function pointers, otherwise the first byte of the
19176  first parameter will get lost.
19177  Usage:
19178 \layout LyX-Code
19179
19180 void func_wparam(int a) wparam
19181 \layout LyX-Code
19182
19183 {
19184 \layout LyX-Code
19185
19186     /* WREG hold the lower part of a */
19187 \layout LyX-Code
19188
19189     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
19190  */
19191 \layout LyX-Code
19192
19193 ...
19194 \layout LyX-Code
19195
19196 }
19197 \layout Standard
19198
19199 This keyword replaces the deprecated wparam pragma.
19200 \layout List
19201 \labelwidthstring 00.00.0000
19202
19203 shadowregs When entering/exiting an ISR, it is possible to take advantage
19204  of the PIC18F hardware shadow registers which hold the values of WREG,
19205  STATUS and BSR registers.
19206  This can be done by adding the keyword 
19207 \emph on 
19208 shadowregs
19209 \emph default 
19210  before the 
19211 \emph on 
19212 interrupt
19213 \emph default 
19214  keyword in the function's header.
19215 \layout LyX-Code
19216
19217 void isr_shadow(void) shadowregs interrupt 1
19218 \layout LyX-Code
19219
19220 {
19221 \layout LyX-Code
19222
19223 ...
19224 \layout LyX-Code
19225
19226 }
19227 \layout Standard
19228
19229
19230 \emph on 
19231 shadowregs
19232 \emph default 
19233  instructs the code generator not to store/restore WREG, STATUS, BSR when
19234  entering/exiting the ISR.
19235 \layout Subsection
19236
19237 Function return values
19238 \layout Standard
19239
19240 Return values from functions are placed to the appropriate registers following
19241  a modified Microchip policy optimized for SDCC.
19242  The following table shows these registers:
19243 \layout Standard
19244 \align center 
19245
19246 \begin_inset  Tabular
19247 <lyxtabular version="3" rows="6" columns="2">
19248 <features>
19249 <column alignment="center" valignment="top" leftline="true" width="0">
19250 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19251 <row topline="true" bottomline="true">
19252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19253 \begin_inset Text
19254
19255 \layout Standard
19256
19257 size
19258 \end_inset 
19259 </cell>
19260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19261 \begin_inset Text
19262
19263 \layout Standard
19264
19265 destination register
19266 \end_inset 
19267 </cell>
19268 </row>
19269 <row topline="true">
19270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19271 \begin_inset Text
19272
19273 \layout Standard
19274
19275 8 bits
19276 \end_inset 
19277 </cell>
19278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19279 \begin_inset Text
19280
19281 \layout Standard
19282
19283 WREG
19284 \end_inset 
19285 </cell>
19286 </row>
19287 <row topline="true">
19288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19289 \begin_inset Text
19290
19291 \layout Standard
19292
19293 16 bits
19294 \end_inset 
19295 </cell>
19296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19297 \begin_inset Text
19298
19299 \layout Standard
19300
19301 PRODL:WREG
19302 \end_inset 
19303 </cell>
19304 </row>
19305 <row topline="true">
19306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19307 \begin_inset Text
19308
19309 \layout Standard
19310
19311 24 bits
19312 \end_inset 
19313 </cell>
19314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19315 \begin_inset Text
19316
19317 \layout Standard
19318
19319 PRODH:PRODL:WREG
19320 \end_inset 
19321 </cell>
19322 </row>
19323 <row topline="true">
19324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19325 \begin_inset Text
19326
19327 \layout Standard
19328
19329 32 bits
19330 \end_inset 
19331 </cell>
19332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19333 \begin_inset Text
19334
19335 \layout Standard
19336
19337 FSR0L:PRODH:PRODL:WREG
19338 \end_inset 
19339 </cell>
19340 </row>
19341 <row topline="true" bottomline="true">
19342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19343 \begin_inset Text
19344
19345 \layout Standard
19346
19347 >32 bits
19348 \end_inset 
19349 </cell>
19350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19351 \begin_inset Text
19352
19353 \layout Standard
19354
19355 on stack, FSR0 points to the beginning
19356 \end_inset 
19357 </cell>
19358 </row>
19359 </lyxtabular>
19360
19361 \end_inset 
19362
19363
19364 \layout Subsection
19365
19366 Interrupts
19367 \layout Standard
19368
19369 An interrupt servive routine (ISR) is declared using the 
19370 \emph on 
19371 interrupt
19372 \emph default 
19373  keyword.
19374 \layout LyX-Code
19375
19376 void isr(void) interrupt 
19377 \emph on 
19378 n
19379 \layout LyX-Code
19380
19381 {
19382 \layout LyX-Code
19383
19384 ...
19385 \layout LyX-Code
19386
19387 }
19388 \layout Standard
19389
19390
19391 \emph on 
19392 n
19393 \emph default 
19394  is the interrupt number, which for PIC18F devices can be:
19395 \layout Standard
19396 \align center 
19397
19398 \begin_inset  Tabular
19399 <lyxtabular version="3" rows="4" columns="3">
19400 <features>
19401 <column alignment="center" valignment="top" leftline="true" width="0">
19402 <column alignment="center" valignment="top" leftline="true" width="0">
19403 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19404 <row topline="true" bottomline="true">
19405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19406 \begin_inset Text
19407
19408 \layout Standard
19409
19410
19411 \emph on 
19412 n
19413 \end_inset 
19414 </cell>
19415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19416 \begin_inset Text
19417
19418 \layout Standard
19419
19420 Interrupt Vector
19421 \end_inset 
19422 </cell>
19423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19424 \begin_inset Text
19425
19426 \layout Standard
19427
19428 Interrupt Vector Address
19429 \end_inset 
19430 </cell>
19431 </row>
19432 <row topline="true">
19433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19434 \begin_inset Text
19435
19436 \layout Standard
19437
19438 0
19439 \end_inset 
19440 </cell>
19441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19442 \begin_inset Text
19443
19444 \layout Standard
19445
19446 RESET vector
19447 \end_inset 
19448 </cell>
19449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19450 \begin_inset Text
19451
19452 \layout Standard
19453
19454 0x000000
19455 \end_inset 
19456 </cell>
19457 </row>
19458 <row topline="true">
19459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19460 \begin_inset Text
19461
19462 \layout Standard
19463
19464
19465 \family roman 
19466 \series medium 
19467 \shape up 
19468 \size normal 
19469 \emph off 
19470 \bar no 
19471 \noun off 
19472 \color none
19473 1
19474 \end_inset 
19475 </cell>
19476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19477 \begin_inset Text
19478
19479 \layout Standard
19480
19481
19482 \family roman 
19483 \series medium 
19484 \shape up 
19485 \size normal 
19486 \emph off 
19487 \bar no 
19488 \noun off 
19489 \color none
19490 HIGH priority interrupts
19491 \end_inset 
19492 </cell>
19493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19494 \begin_inset Text
19495
19496 \layout Standard
19497
19498 0x000008
19499 \end_inset 
19500 </cell>
19501 </row>
19502 <row topline="true" bottomline="true">
19503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19504 \begin_inset Text
19505
19506 \layout Standard
19507
19508 2
19509 \end_inset 
19510 </cell>
19511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19512 \begin_inset Text
19513
19514 \layout Standard
19515
19516 LOW priority interrupts
19517 \end_inset 
19518 </cell>
19519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19520 \begin_inset Text
19521
19522 \layout Standard
19523
19524 0x000018
19525 \end_inset 
19526 </cell>
19527 </row>
19528 </lyxtabular>
19529
19530 \end_inset 
19531
19532
19533 \layout Standard
19534
19535 When generating assembly code for ISR the code generator places a 
19536 \noun on 
19537 goto 
19538 \noun default 
19539 instruction at the 
19540 \emph on 
19541 Interrupt Vector Address
19542 \emph default 
19543  which points at the genetated ISR.
19544  This single GOTO instruction is part of an automatically generated 
19545 \emph on 
19546 interrupt entry point
19547 \emph default 
19548  function.
19549  The actuall ISR code is placed as normally would in the code space.
19550  Upon interrupt request, the GOTO instruction is executed which jumps to
19551  the ISR code.
19552  When declaring interrupt functions as _naked this GOTO instruction is 
19553 \series bold 
19554 not
19555 \series default 
19556  generated.
19557  The whole interrupt functions is therefore placed at the Interrupt Vector
19558  Address of the specific interrupt.
19559  This is not a problem for the LOW priority interrupts, but it is a problem
19560  for the RESET and the HIGH priority interrupts because code may be written
19561  at the next interrupt´s vector address and cause undeterminate program
19562  behaviour if that interrupt is raised.
19563 \begin_inset Foot
19564 collapsed false
19565
19566 \layout Standard
19567
19568 This is not a problem when
19569 \layout Enumerate
19570
19571 this is a HIGH interrupt ISR and LOW interrupts are 
19572 \emph on 
19573 disabled
19574 \emph default 
19575  or not used.
19576 \layout Enumerate
19577
19578 when the ISR is small enough not to reach the next interrupt´s vector address.
19579 \end_inset 
19580
19581
19582 \layout Standard
19583
19584
19585 \emph on 
19586 n
19587 \emph default 
19588  is possible to be omitted.
19589  This way a function is generated similar to an ISR, but it is not assigned
19590  to any interrupt.
19591 \layout Standard
19592
19593 When entering an interrupt, currently the PIC16
19594 \begin_inset LatexCommand \index{PIC16}
19595
19596 \end_inset 
19597
19598  port automatically saves the following registers:
19599 \layout Itemize
19600
19601 WREG
19602 \layout Itemize
19603
19604 STATUS
19605 \layout Itemize
19606
19607 BSR
19608 \layout Itemize
19609
19610 PROD (PRODL and PRODH)
19611 \layout Itemize
19612
19613 FSR0 (FSR0L and FSR0H)
19614 \layout Standard
19615
19616 These registers are restored upon return from the interrupt routine.
19617 \begin_inset Foot
19618 collapsed false
19619
19620 \layout Standard
19621
19622 NOTE that when the _naked attribute is specified for an interrupt routine,
19623  then NO registers are stored or restored.
19624 \end_inset 
19625
19626
19627 \layout Subsection
19628
19629 Generic Pointers
19630 \layout Standard
19631
19632 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
19633  There are 3 types of generic pointers currently implemented data, code
19634  and eeprom pointers.
19635  They are differentiated by the value of the 7th and 6th bits of the upper
19636  byte:
19637 \layout Standard
19638 \align center 
19639
19640 \begin_inset  Tabular
19641 <lyxtabular version="3" rows="5" columns="5">
19642 <features>
19643 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19644 <column alignment="center" valignment="top" width="0">
19645 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19646 <column alignment="center" valignment="top" width="0">
19647 <column alignment="left" valignment="top" rightline="true" width="0">
19648 <row topline="true" bottomline="true">
19649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19650 \begin_inset Text
19651
19652 \layout Standard
19653
19654 pointer type
19655 \end_inset 
19656 </cell>
19657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19658 \begin_inset Text
19659
19660 \layout Standard
19661
19662 7th bit
19663 \end_inset 
19664 </cell>
19665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19666 \begin_inset Text
19667
19668 \layout Standard
19669
19670 6th bit
19671 \end_inset 
19672 </cell>
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19674 \begin_inset Text
19675
19676 \layout Standard
19677
19678 rest of the pointer
19679 \end_inset 
19680 </cell>
19681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19682 \begin_inset Text
19683
19684 \layout Standard
19685
19686 descrption
19687 \end_inset 
19688 </cell>
19689 </row>
19690 <row topline="true" bottomline="true">
19691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19692 \begin_inset Text
19693
19694 \layout Standard
19695
19696 data 
19697 \end_inset 
19698 </cell>
19699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19700 \begin_inset Text
19701
19702 \layout Standard
19703
19704 1
19705 \end_inset 
19706 </cell>
19707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19708 \begin_inset Text
19709
19710 \layout Standard
19711
19712 0
19713 \end_inset 
19714 </cell>
19715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19716 \begin_inset Text
19717
19718 \layout Standard
19719
19720
19721 \family typewriter 
19722 \shape slanted 
19723 \emph on 
19724 uuuuuu uuuuxxxx xxxxxxxx
19725 \end_inset 
19726 </cell>
19727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19728 \begin_inset Text
19729
19730 \layout Standard
19731
19732 a 12-bit data pointer in data RAM memory
19733 \end_inset 
19734 </cell>
19735 </row>
19736 <row bottomline="true">
19737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19738 \begin_inset Text
19739
19740 \layout Standard
19741
19742 code
19743 \end_inset 
19744 </cell>
19745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19746 \begin_inset Text
19747
19748 \layout Standard
19749
19750 0
19751 \end_inset 
19752 </cell>
19753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19754 \begin_inset Text
19755
19756 \layout Standard
19757
19758 0
19759 \end_inset 
19760 </cell>
19761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19762 \begin_inset Text
19763
19764 \layout Standard
19765
19766
19767 \family typewriter 
19768 \shape slanted 
19769 \emph on 
19770 uxxxxx xxxxxxxx xxxxxxxx
19771 \end_inset 
19772 </cell>
19773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19774 \begin_inset Text
19775
19776 \layout Standard
19777
19778 a 21-bit code pointer in FLASH memory
19779 \end_inset 
19780 </cell>
19781 </row>
19782 <row bottomline="true">
19783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19784 \begin_inset Text
19785
19786 \layout Standard
19787
19788 eeprom
19789 \end_inset 
19790 </cell>
19791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19792 \begin_inset Text
19793
19794 \layout Standard
19795
19796 0
19797 \end_inset 
19798 </cell>
19799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19800 \begin_inset Text
19801
19802 \layout Standard
19803
19804 1
19805 \end_inset 
19806 </cell>
19807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19808 \begin_inset Text
19809
19810 \layout Standard
19811
19812
19813 \family typewriter 
19814 \shape slanted 
19815 \emph on 
19816 uuuuuu uuuuuuxx xxxxxxxx
19817 \end_inset 
19818 </cell>
19819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19820 \begin_inset Text
19821
19822 \layout Standard
19823
19824 a 10-bit eeprom pointer in EEPROM memory
19825 \end_inset 
19826 </cell>
19827 </row>
19828 <row bottomline="true">
19829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19830 \begin_inset Text
19831
19832 \layout Standard
19833
19834 (unimplemented)
19835 \end_inset 
19836 </cell>
19837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19838 \begin_inset Text
19839
19840 \layout Standard
19841
19842 1
19843 \end_inset 
19844 </cell>
19845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19846 \begin_inset Text
19847
19848 \layout Standard
19849
19850 1
19851 \end_inset 
19852 </cell>
19853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19854 \begin_inset Text
19855
19856 \layout Standard
19857
19858
19859 \family typewriter 
19860 \shape slanted 
19861 \emph on 
19862 xxxxxx xxxxxxxx xxxxxxxx
19863 \end_inset 
19864 </cell>
19865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19866 \begin_inset Text
19867
19868 \layout Standard
19869
19870 unimplemented pointer type
19871 \end_inset 
19872 </cell>
19873 </row>
19874 </lyxtabular>
19875
19876 \end_inset 
19877
19878
19879 \layout Standard
19880
19881 Generic pointer are read and written with a set of library functions which
19882  read/write 1, 2, 3, 4 bytes.
19883 \layout Subsection
19884
19885 PIC16 C Libraries
19886 \layout Subsubsection
19887
19888 Standard I/O Streams
19889 \layout Standard
19890
19891 In the 
19892 \emph on 
19893 stdio.h
19894 \emph default 
19895  the type FILE is defined as:
19896 \layout LyX-Code
19897
19898 typedef char * FILE;
19899 \layout Standard
19900
19901 This type is the stream type implemented I/O in the PIC18F devices.
19902  Also the standard input and output streams are declared in stdio.h:
19903 \layout LyX-Code
19904
19905 extern FILE * stdin;
19906 \layout LyX-Code
19907
19908 extern FILE * stdout;
19909 \layout Standard
19910
19911 The FILE type is actually a generic pointer which defines one more type
19912  of generic pointers, the 
19913 \emph on 
19914 stream 
19915 \emph default 
19916 pointer.
19917  This new type has the format:
19918 \layout Standard
19919 \align center 
19920
19921 \begin_inset  Tabular
19922 <lyxtabular version="3" rows="2" columns="7">
19923 <features>
19924 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19925 <column alignment="center" valignment="top" width="0">
19926 <column alignment="center" valignment="top" leftline="true" width="0">
19927 <column alignment="center" valignment="top" leftline="true" width="0">
19928 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19929 <column alignment="center" valignment="top" width="0">
19930 <column alignment="left" valignment="top" rightline="true" width="0">
19931 <row topline="true" bottomline="true">
19932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19933 \begin_inset Text
19934
19935 \layout Standard
19936
19937 pointer type
19938 \end_inset 
19939 </cell>
19940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19941 \begin_inset Text
19942
19943 \layout Standard
19944
19945 <7:6>
19946 \end_inset 
19947 </cell>
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19949 \begin_inset Text
19950
19951 \layout Standard
19952
19953 <5>
19954 \end_inset 
19955 </cell>
19956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19957 \begin_inset Text
19958
19959 \layout Standard
19960
19961 <4>
19962 \end_inset 
19963 </cell>
19964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19965 \begin_inset Text
19966
19967 \layout Standard
19968
19969 <3:0>
19970 \end_inset 
19971 </cell>
19972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19973 \begin_inset Text
19974
19975 \layout Standard
19976
19977 rest of the pointer
19978 \end_inset 
19979 </cell>
19980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19981 \begin_inset Text
19982
19983 \layout Standard
19984
19985 descrption
19986 \end_inset 
19987 </cell>
19988 </row>
19989 <row topline="true" bottomline="true">
19990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19991 \begin_inset Text
19992
19993 \layout Standard
19994
19995 stream
19996 \end_inset 
19997 </cell>
19998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19999 \begin_inset Text
20000
20001 \layout Standard
20002
20003 00
20004 \end_inset 
20005 </cell>
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20007 \begin_inset Text
20008
20009 \layout Standard
20010
20011 1
20012 \end_inset 
20013 </cell>
20014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20015 \begin_inset Text
20016
20017 \layout Standard
20018
20019 0
20020 \end_inset 
20021 </cell>
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20023 \begin_inset Text
20024
20025 \layout Standard
20026
20027 nnnn
20028 \end_inset 
20029 </cell>
20030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20031 \begin_inset Text
20032
20033 \layout Standard
20034
20035
20036 \family typewriter 
20037 \shape slanted 
20038 \emph on 
20039 uuuuuuuu uuuuuuuu
20040 \end_inset 
20041 </cell>
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20043 \begin_inset Text
20044
20045 \layout Standard
20046
20047 upper byte high nubble is 0x2n, the rest are zeroes
20048 \end_inset 
20049 </cell>
20050 </row>
20051 </lyxtabular>
20052
20053 \end_inset 
20054
20055
20056 \layout Standard
20057
20058 Currently implemented there are 3 types of streams defined:
20059 \layout Standard
20060 \align center 
20061
20062 \begin_inset  Tabular
20063 <lyxtabular version="3" rows="4" columns="4">
20064 <features>
20065 <column alignment="center" valignment="top" leftline="true" width="0">
20066 <column alignment="center" valignment="top" leftline="true" width="0">
20067 <column alignment="center" valignment="top" leftline="true" width="0">
20068 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20069 <row topline="true" bottomline="true">
20070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20071 \begin_inset Text
20072
20073 \layout Standard
20074
20075 stream type
20076 \end_inset 
20077 </cell>
20078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20079 \begin_inset Text
20080
20081 \layout Standard
20082
20083 value
20084 \end_inset 
20085 </cell>
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20087 \begin_inset Text
20088
20089 \layout Standard
20090
20091 module
20092 \end_inset 
20093 </cell>
20094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20095 \begin_inset Text
20096
20097 \layout Standard
20098
20099 description
20100 \end_inset 
20101 </cell>
20102 </row>
20103 <row topline="true">
20104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20105 \begin_inset Text
20106
20107 \layout Standard
20108
20109 STREAM_USART
20110 \end_inset 
20111 </cell>
20112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20113 \begin_inset Text
20114
20115 \layout Standard
20116
20117
20118 \family typewriter 
20119 0x200000UL
20120 \end_inset 
20121 </cell>
20122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20123 \begin_inset Text
20124
20125 \layout Standard
20126
20127 USART
20128 \end_inset 
20129 </cell>
20130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20131 \begin_inset Text
20132
20133 \layout Standard
20134
20135 Writes/Reads characters via the USART peripheral
20136 \end_inset 
20137 </cell>
20138 </row>
20139 <row topline="true">
20140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20141 \begin_inset Text
20142
20143 \layout Standard
20144
20145 STREAM_MSSP
20146 \end_inset 
20147 </cell>
20148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20149 \begin_inset Text
20150
20151 \layout Standard
20152
20153
20154 \family typewriter 
20155 0x210000UL
20156 \end_inset 
20157 </cell>
20158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20159 \begin_inset Text
20160
20161 \layout Standard
20162
20163 MSSP
20164 \end_inset 
20165 </cell>
20166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20167 \begin_inset Text
20168
20169 \layout Standard
20170
20171 Writes/Reads characters via the MSSP peripheral
20172 \end_inset 
20173 </cell>
20174 </row>
20175 <row topline="true" bottomline="true">
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20177 \begin_inset Text
20178
20179 \layout Standard
20180
20181 STREAM_USER
20182 \end_inset 
20183 </cell>
20184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20185 \begin_inset Text
20186
20187 \layout Standard
20188
20189
20190 \family typewriter 
20191 0x2f0000UL
20192 \end_inset 
20193 </cell>
20194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20195 \begin_inset Text
20196
20197 \layout Standard
20198
20199 (none)
20200 \end_inset 
20201 </cell>
20202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20203 \begin_inset Text
20204
20205 \layout Standard
20206
20207 Writes/Reads characters via used defined functions
20208 \end_inset 
20209 </cell>
20210 </row>
20211 </lyxtabular>
20212
20213 \end_inset 
20214
20215
20216 \layout Standard
20217
20218 The stream identifiers are declared as macros in the stdio.h header.
20219 \layout Standard
20220
20221 In the libc library there exist the functions that are used to write to
20222  each of the above streams.
20223  These are
20224 \layout List
20225 \labelwidthstring 00.00.0000
20226
20227 _
20228 \begin_inset ERT
20229 status Collapsed
20230
20231 \layout Standard
20232
20233 \backslash 
20234 /
20235 \end_inset 
20236
20237 _stream_usart_putchar writes a character at the USART stream
20238 \layout List
20239 \labelwidthstring 00.00.0000
20240
20241 _
20242 \begin_inset ERT
20243 status Collapsed
20244
20245 \layout Standard
20246
20247 \backslash 
20248 /
20249 \end_inset 
20250
20251 _stream_mssp_putchar writes a character at the MSSP stream
20252 \layout List
20253 \labelwidthstring 00.00.0000
20254
20255 putchar dummy function.
20256  This writes a character to a user specified manner.
20257 \layout Standard
20258
20259 In order to increase performance 
20260 \emph on 
20261 putchar 
20262 \emph default 
20263 is declared in stdio.h as having its parameter in WREG (it has the wparam
20264  keyword).
20265  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
20266  in a user-friendly way.
20267  
20268 \emph on 
20269 arg
20270 \emph default 
20271  is the name of the variable that holds the character to print.
20272  An example follows:
20273 \layout LyX-Code
20274
20275 #include <pic18fregs.h>
20276 \newline 
20277 #include <stdio.h>
20278 \newline 
20279
20280 \newline 
20281 PUTCHAR( c )
20282 \layout LyX-Code
20283
20284 {
20285 \layout LyX-Code
20286
20287     PORTA = c;    /* dump character c to PORTA */
20288 \layout LyX-Code
20289
20290
20291 \newline 
20292
20293 \newline 
20294 void main(void)
20295 \layout LyX-Code
20296
20297 {
20298 \layout LyX-Code
20299
20300     stdout = STREAM_USER;    /* this is not necessery, since stdout points
20301 \layout LyX-Code
20302
20303                               * by default to STREAM_USER */
20304 \layout LyX-Code
20305
20306     printf (¨This is a printf test
20307 \backslash 
20308 n¨);
20309 \layout LyX-Code
20310
20311 }
20312 \layout LyX-Code
20313
20314 \layout Subsubsection
20315
20316 Printing functions
20317 \layout Standard
20318
20319 PIC16 contains an implementation of the printf-family of functions.
20320  There exist the following functions:
20321 \layout LyX-Code
20322
20323 extern unsigned int sprintf(char *buf, char *fmt, ...);
20324 \layout LyX-Code
20325
20326 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
20327 \layout LyX-Code
20328
20329 \layout LyX-Code
20330
20331 extern unsigned int printf(char *fmt, ...);
20332 \layout LyX-Code
20333
20334 extern unsigned int vprintf(char *fmt, va_lista ap);
20335 \layout LyX-Code
20336
20337 \layout LyX-Code
20338
20339 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
20340 \layout LyX-Code
20341
20342 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
20343 \layout Standard
20344
20345 For sprintf and vsprintf 
20346 \emph on 
20347 buf 
20348 \emph default 
20349 should normally be a data pointer where the resulting string will be placed.
20350  No range checking is done so the user should allocate the necessery buffer.
20351  For fprintf and vfprintf 
20352 \emph on 
20353 fp
20354 \emph default 
20355  should be a stream pointer (i.e.
20356  stdout, STREAM_MSSP, etc...).
20357 \layout Subsubsection
20358
20359 Signals
20360 \layout Standard
20361
20362 The PIC18F family of microcontrollers supports a number of interrupt sources.
20363  A list of these interrupts is shown in the following table:
20364 \layout Standard
20365 \align center 
20366
20367 \begin_inset  Tabular
20368 <lyxtabular version="3" rows="11" columns="4">
20369 <features>
20370 <column alignment="left" valignment="top" leftline="true" width="0">
20371 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20372 <column alignment="left" valignment="top" leftline="true" width="0">
20373 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20374 <row topline="true" bottomline="true">
20375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20376 \begin_inset Text
20377
20378 \layout Standard
20379
20380 signal name
20381 \end_inset 
20382 </cell>
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20384 \begin_inset Text
20385
20386 \layout Standard
20387
20388 description
20389 \end_inset 
20390 </cell>
20391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20392 \begin_inset Text
20393
20394 \layout Standard
20395
20396 signal name
20397 \end_inset 
20398 </cell>
20399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20400 \begin_inset Text
20401
20402 \layout Standard
20403
20404 descritpion
20405 \end_inset 
20406 </cell>
20407 </row>
20408 <row topline="true">
20409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20410 \begin_inset Text
20411
20412 \layout Standard
20413
20414 SIG_RB
20415 \end_inset 
20416 </cell>
20417 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20418 \begin_inset Text
20419
20420 \layout Standard
20421
20422 PORTB change interrupt
20423 \end_inset 
20424 </cell>
20425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20426 \begin_inset Text
20427
20428 \layout Standard
20429
20430 SIG_EE
20431 \end_inset 
20432 </cell>
20433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20434 \begin_inset Text
20435
20436 \layout Standard
20437
20438 EEPROM/FLASH write complete interrupt
20439 \end_inset 
20440 </cell>
20441 </row>
20442 <row topline="true">
20443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20444 \begin_inset Text
20445
20446 \layout Standard
20447
20448 SIG_INT0
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 INT0 external interrupt
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 SIG_BCOL
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 Bus collision interrupt
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_INT1
20483 \end_inset 
20484 </cell>
20485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20486 \begin_inset Text
20487
20488 \layout Standard
20489
20490 INT1 external 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_LVD
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 Low voltage detect 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_INT2
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 INT2 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_PSP
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 Parallel slave port 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_CCP1
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 CCP1 module 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_AD
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 AD convertion complete 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_CCP2
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 CCP2 module 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_RC
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 USART receive 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_TMR0
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 TMR0 overflow 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_TX
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 USART transmit 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_TMR1
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 TMR1 overflow 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_MSSP
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 SSP receive/transmit 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_TMR2
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 TMR2 matches PR2 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 \end_inset 
20703 </cell>
20704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20705 \begin_inset Text
20706
20707 \layout Standard
20708
20709 \end_inset 
20710 </cell>
20711 </row>
20712 <row topline="true" bottomline="true">
20713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20714 \begin_inset Text
20715
20716 \layout Standard
20717
20718 SIG_TMR3
20719 \end_inset 
20720 </cell>
20721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20722 \begin_inset Text
20723
20724 \layout Standard
20725
20726 TMR3 overflow interrupt
20727 \end_inset 
20728 </cell>
20729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20730 \begin_inset Text
20731
20732 \layout Standard
20733
20734 \end_inset 
20735 </cell>
20736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20737 \begin_inset Text
20738
20739 \layout Standard
20740
20741 \end_inset 
20742 </cell>
20743 </row>
20744 </lyxtabular>
20745
20746 \end_inset 
20747
20748
20749 \layout Standard
20750
20751 The prototypes for these names are defined in the header file 
20752 \emph on 
20753 signal.h
20754 \emph default 
20755  .
20756 \layout Standard
20757
20758 In order to simplify signal handling, a number of macros is provided:
20759 \layout List
20760 \labelwidthstring 00.00.0000
20761
20762 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
20763  high priority interrupts.
20764  
20765 \emph on 
20766 name
20767 \emph default 
20768  is the function name to use.
20769 \layout List
20770 \labelwidthstring 00.00.0000
20771
20772 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
20773  low priority interrupt.
20774  
20775 \emph on 
20776 name
20777 \emph default 
20778  is the function name to use.
20779 \layout List
20780 \labelwidthstring 00.00.0000
20781
20782 DEF_HANDLER(sig,handler) define a handler for signal 
20783 \emph on 
20784 sig.
20785 \layout List
20786 \labelwidthstring 00.00.0000
20787
20788 END_DEF end the declaration of the dispatch table.
20789 \layout Standard
20790
20791 Additionally there are two more macros to simplify the declaration of the
20792  signal handler:
20793 \layout List
20794 \labelwidthstring 00.00.0000
20795
20796
20797 \series medium 
20798 SIGHANDLER(handler) 
20799 \series default 
20800 this declares the function prototype for the 
20801 \emph on 
20802 handler
20803 \emph default 
20804  function.
20805 \layout List
20806 \labelwidthstring 00.00.0000
20807
20808 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
20809 \layout Standard
20810
20811 An example of using the macros above is shown below:
20812 \layout LyX-Code
20813
20814 #include <pic18fregs.h>
20815 \layout LyX-Code
20816
20817 #include <signal.h>
20818 \newline 
20819
20820 \newline 
20821 DEF_INTHIGH(high_int)
20822 \layout LyX-Code
20823
20824 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
20825 \layout LyX-Code
20826
20827 DEF_HANDLER(SIG_BCOL, _bcol_handler)
20828 \layout LyX-Code
20829
20830 END_DEF
20831 \newline 
20832
20833 \newline 
20834 SIGHANDLER(_tmr0_handler)
20835 \layout LyX-Code
20836
20837 {
20838 \layout LyX-Code
20839
20840   /* action to be taken when timer 0 overflows */
20841 \layout LyX-Code
20842
20843 }
20844 \newline 
20845
20846 \newline 
20847 SIGHANDLERNAKED(_bcol_handler)
20848 \layout LyX-Code
20849
20850 {
20851 \layout LyX-Code
20852
20853   _asm
20854 \layout LyX-Code
20855
20856     /* action to be taken when bus collision occurs */
20857 \layout LyX-Code
20858
20859     retfie
20860 \layout LyX-Code
20861
20862  _endasm;
20863 \layout LyX-Code
20864
20865 }
20866 \layout Standard
20867
20868
20869 \series bold 
20870 NOTES:
20871 \series default 
20872  Special care should be taken when using the above scheme:
20873 \layout Itemize
20874
20875 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
20876 \layout Itemize
20877
20878 when declaring SIGHANDLERNAKED handler never forget to use 
20879 \emph on 
20880 retfie
20881 \emph default 
20882  for proper returning.
20883 \layout Subsection
20884
20885 PIC16 Port -- Tips
20886 \layout Standard
20887
20888 Here you can find some general tips for compiling programs with SDCC/pic16.
20889 \layout Subsubsection
20890
20891 Stack size
20892 \layout Standard
20893
20894 The default stack size (that is 64 bytes) probably is enough for many programs.
20895  One must take care that when there are many levels of function nesting,
20896  or there is excessive usage of stack, its size should be extended.
20897  An example of such a case is the printf/sprintf family of functions.
20898  If you encounter problems like not being able to print integers, then you
20899  need to set the stack size around the maximum (256 for small stack model).
20900  The following diagram shows what happens when calling printf to print an
20901  integer:
20902 \layout LyX-Code
20903
20904 printf () --> ltoa () --> ultoa () --> divschar ()
20905 \layout Standard
20906
20907 It is should be understood that stack is easily consumed when calling complicate
20908 d functions.
20909  Using command line arguments like -
20910 \begin_inset ERT
20911 status Collapsed
20912
20913 \layout Standard
20914
20915 \backslash 
20916 /
20917 \end_inset 
20918
20919 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
20920  stack frames.
20921  Other ways to reduce stack usage may exist.
20922 \layout Chapter
20923
20924 Debugging
20925 \layout Standard
20926
20927 There are several approaches to debugging your code.
20928  This chapter is meant to show your options and to give detail on some of
20929  them:
20930 \newline 
20931
20932 \newline 
20933 When writing your code:
20934 \layout Itemize
20935
20936 write your code with debugging in mind (avoid duplicating code, put conceptually
20937  similar variables into structs, use structured code, have strategic points
20938  within your code where all variables are consistent, ...)
20939 \layout Itemize
20940
20941 run a syntax-checking tool like splint
20942 \begin_inset LatexCommand \index{splint (syntax checking tool)}
20943
20944 \end_inset 
20945
20946
20947 \begin_inset LatexCommand \index{lint (syntax checking tool)}
20948
20949 \end_inset 
20950
20951  (see -
20952 \begin_inset ERT
20953 status Collapsed
20954
20955 \layout Standard
20956
20957 \backslash 
20958 /
20959 \end_inset 
20960
20961 -more-pedantic 
20962 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
20963
20964 \end_inset 
20965
20966 ) over the code.
20967 \layout Itemize
20968
20969 for the high level code use a C-compiler (like f.e.
20970  GCC) to compile run and debug the code on your host.
20971  See (see -
20972 \begin_inset ERT
20973 status Collapsed
20974
20975 \layout Standard
20976
20977 \backslash 
20978 /
20979 \end_inset 
20980
20981 -more-pedantic 
20982 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
20983
20984 \end_inset 
20985
20986  ) on howto handle syntax extensions like __xdata, __at(), ...
20987  
20988 \layout Itemize
20989
20990 use another C-compiler to compile code for your target.
20991  Always an option but not recommended:) And not very likely to help you.
20992  If you seriously consider walking this path you should at least occasionally
20993  check portability of your code.
20994  Most commercial compiler vendors will offer an evaluation version so you
20995  can test compile your code or snippets of your code.
20996 \layout Standard
20997
20998 Debugging on a simulator:
20999 \layout Itemize
21000
21001 there is a separate section about SDCDB (section 
21002 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
21003
21004 \end_inset 
21005
21006 ) below.
21007 \layout Itemize
21008
21009 or (8051 specific) use a freeware/commercial simulator which interfaces
21010  to the AOMF
21011 \begin_inset LatexCommand \index{AOMF, AOMF51}
21012
21013 \end_inset 
21014
21015  file (see 
21016 \begin_inset LatexCommand \ref{OMF file}
21017
21018 \end_inset 
21019
21020 ) optionally generated by SDCC.
21021 \layout Standard
21022
21023 Debugging On-target: 
21024 \layout Itemize
21025
21026 use a MCU port pin to serially output debug data to the RS232 port of your
21027  host.
21028  You'll probably want some level shifting device typically involving a MAX232
21029  or similar IC.
21030  If the hardware serial port of the MCU is not available search for 'Software
21031  UART' in your favourite search machine.
21032 \layout Itemize
21033
21034 use an on-target monitor.
21035  In this context a monitor is a small program which usually accepts commands
21036  via a serial line and allows to set program counter, to single step through
21037  a program and read/write memory locations.
21038  For the 8051 good examples of monitors are paulmon and cmon51 (see section
21039  
21040 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
21041
21042 \end_inset 
21043
21044 ).
21045 \layout Itemize
21046
21047 toggle MCU port pins at strategic points within your code and use an oscilloscop
21048 e.
21049  A 
21050 \emph on 
21051 digital oscilloscope
21052 \emph default 
21053
21054 \begin_inset LatexCommand \index{oscilloscope}
21055
21056 \end_inset 
21057
21058  with deep trace memory is really helpful especially if you have to debug
21059  a realtime application.
21060  If you need to monitor more pins than your oscilloscope provides you can
21061  sometimes get away with a small R-2R network.
21062  On a single channel oscilloscope you could f.e.
21063  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
21064 k
21065 \begin_inset Formula $\Omega$
21066 \end_inset 
21067
21068  resistor and the other one by a 5\SpecialChar ~
21069 k
21070 \begin_inset Formula $\Omega$
21071 \end_inset 
21072
21073  resistor to the oscilloscope probe (check output drive capability of the
21074  pins you want to monitor).
21075  If you need to monitor many more pins a 
21076 \emph on 
21077 logic analyzer
21078 \emph default 
21079  will be handy.
21080 \layout Itemize
21081
21082 use an ICE (
21083 \emph on 
21084 i
21085 \emph default 
21086
21087 \emph on 
21088 c
21089 \emph default 
21090 ircuit 
21091 \emph on 
21092 e
21093 \emph default 
21094 mulator
21095 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
21096
21097 \end_inset 
21098
21099 ).
21100  Usually very expensive.
21101  And very nice to have too.
21102  And usually locks you (for years...) to the devices the ICE can emulate.
21103  
21104 \layout Itemize
21105
21106 use a remote debugger.
21107  In most 8-bit systems the symbol information is not available on the target,
21108  and a complete debugger is too bulky for the target system.
21109  Therefore usually a debugger on the host system connects to an on-target
21110  debugging stub which accepts only primitive commands.
21111  
21112 \newline 
21113 Terms to enter into your favourite search engine could be 'remote debugging',
21114  'gdb stub' or 'inferior debugger'.
21115  (is there one?)
21116 \layout Itemize
21117
21118 use an on target hardware debugger.
21119  Some of the more modern MCUs include hardware support for setting break
21120  points and monitoring/changing variables by using dedicated hardware pins.
21121  This facility doesn't require additional code to run on the target and
21122  
21123 \emph on 
21124 usually
21125 \emph default 
21126  doesn't affect runtime behaviour until a breakpoint is hit.
21127  For the mcs51 most hardware debuggers use the AOMF
21128 \begin_inset LatexCommand \index{AOMF, AOMF51}
21129
21130 \end_inset 
21131
21132  file (see 
21133 \begin_inset LatexCommand \ref{OMF file}
21134
21135 \end_inset 
21136
21137 ) as input file.
21138  
21139 \layout Standard
21140
21141 Last not least:
21142 \layout Itemize
21143
21144 if you are not familiar with any of the following terms you're likely to
21145  run into problems rather sooner than later: 
21146 \emph on 
21147 volatile
21148 \emph default 
21149
21150 \emph on 
21151 atomic
21152 \emph default 
21153
21154 \emph on 
21155 memory map
21156 \emph default 
21157
21158 \emph on 
21159 overlay
21160 \emph default 
21161 .
21162  As an embedded programmer you 
21163 \emph on 
21164 have
21165 \emph default 
21166  to know them so why not look them up 
21167 \emph on 
21168 before
21169 \emph default 
21170  you have problems?)
21171 \layout Itemize
21172
21173 tell someone else about your problem (actually this is a surprisingly effective
21174  means to hunt down the bug even if the listener is not familiar with your
21175  environment).
21176  As 'failure to communicate' is probably one of the job-induced deformations
21177  of an embedded programmer this is highly encouraged.
21178 \layout Section
21179
21180 Debugging with SDCDB
21181 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
21182
21183 \end_inset 
21184
21185
21186 \begin_inset LatexCommand \index{sdcdb (debugger)}
21187
21188 \end_inset 
21189
21190  
21191 \layout Standard
21192
21193 SDCC is distributed with a source level debugger
21194 \begin_inset LatexCommand \index{Debugger}
21195
21196 \end_inset 
21197
21198 .
21199  The debugger uses a command line interface, the command repertoire of the
21200  debugger has been kept as close to gdb
21201 \begin_inset LatexCommand \index{gdb}
21202
21203 \end_inset 
21204
21205  (the GNU debugger) as possible.
21206  The configuration and build process is part of the standard compiler installati
21207 on, which also builds and installs the debugger in the target directory
21208  specified during configuration.
21209  The debugger allows you debug BOTH at the C source and at the ASM source
21210  level.
21211  Sdcdb is currently not available on Win32 platforms.
21212 \layout Subsection
21213
21214 Compiling for Debugging
21215 \layout Standard
21216
21217 The -
21218 \begin_inset ERT
21219 status Collapsed
21220
21221 \layout Standard
21222
21223 \backslash 
21224 /
21225 \end_inset 
21226
21227 -debug
21228 \begin_inset LatexCommand \index{-\/-debug}
21229
21230 \end_inset 
21231
21232  option must be specified for all files for which debug information is to
21233  be generated.
21234  The compiler generates a .adb file for each of these files.
21235  The linker creates the .cdb
21236 \begin_inset LatexCommand \index{<file>.cdb}
21237
21238 \end_inset 
21239
21240  file from the .adb
21241 \begin_inset LatexCommand \index{<file>.adb}
21242
21243 \end_inset 
21244
21245  files and the address information.
21246  This .cdb is used by the debugger.
21247 \layout Subsection
21248
21249 How the Debugger Works
21250 \layout Standard
21251
21252 When the -
21253 \begin_inset ERT
21254 status Collapsed
21255
21256 \layout Standard
21257
21258 \backslash 
21259 /
21260 \end_inset 
21261
21262 -debug option is specified the compiler generates extra symbol information
21263  some of which are put into the assembler source and some are put into the
21264  .adb file.
21265  Then the linker creates the .cdb file from the individual .adb files with
21266  the address information for the symbols.
21267  The debugger reads the symbolic information generated by the compiler &
21268  the address information generated by the linker.
21269  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
21270  execution is controlled by the debugger.
21271  When a command is issued for the debugger, it translates it into appropriate
21272  commands for the simulator.
21273  (Currently sdcdb only connects to the simulator but 
21274 \emph on 
21275 newcdb
21276 \emph default 
21277  at 
21278 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
21279
21280 \end_inset 
21281
21282  is an effort to connect directly to the hardware.) 
21283 \layout Subsection
21284
21285 Starting the Debugger SDCDB
21286 \layout Standard
21287
21288 The debugger can be started using the following command line.
21289  (Assume the file you are debugging has the file name foo).
21290 \newline 
21291
21292 \newline 
21293
21294 \family sans 
21295 \series bold 
21296 sdcdb foo
21297 \newline 
21298
21299 \family default 
21300 \series default 
21301
21302 \newline 
21303 The debugger will look for the following files.
21304 \layout Itemize
21305
21306 foo.c - the source file.
21307 \layout Itemize
21308
21309 foo.cdb - the debugger symbol information file.
21310 \layout Itemize
21311
21312 foo.ihx - the Intel hex format
21313 \begin_inset LatexCommand \index{Intel hex format}
21314
21315 \end_inset 
21316
21317  object file.
21318 \layout Subsection
21319
21320 SDCDB Command Line Options
21321 \layout Itemize
21322
21323 -
21324 \begin_inset ERT
21325 status Collapsed
21326
21327 \layout Standard
21328
21329 \backslash 
21330 /
21331 \end_inset 
21332
21333 -directory=<source file directory> this option can used to specify the directory
21334  search list.
21335  The debugger will look into the directory list specified for source, cdb
21336  & ihx files.
21337  The items in the directory list must be separated by ':', e.g.
21338  if the source files can be in the directories /home/src1 and /home/src2,
21339  the -
21340 \begin_inset ERT
21341 status Collapsed
21342
21343 \layout Standard
21344
21345 \backslash 
21346 /
21347 \end_inset 
21348
21349 -directory option should be -
21350 \begin_inset ERT
21351 status Collapsed
21352
21353 \layout Standard
21354
21355 \backslash 
21356 /
21357 \end_inset 
21358
21359 -directory=/home/src1:/home/src2.
21360  Note there can be no spaces in the option.
21361  
21362 \layout Itemize
21363
21364 -cd <directory> - change to the <directory>.
21365 \layout Itemize
21366
21367 -fullname - used by GUI front ends.
21368 \layout Itemize
21369
21370 -cpu <cpu-type> - this argument is passed to the simulator please see the
21371  simulator docs for details.
21372 \layout Itemize
21373
21374 -X <Clock frequency > this options is passed to the simulator please see
21375  the simulator docs for details.
21376 \layout Itemize
21377
21378 -s <serial port file> passed to simulator see the simulator docs for details.
21379 \layout Itemize
21380
21381 -S <serial in,out> passed to simulator see the simulator docs for details.
21382 \layout Itemize
21383
21384 -k <port number> passed to simulator see the simulator docs for details.
21385 \layout Subsection
21386
21387 SDCDB Debugger Commands
21388 \layout Standard
21389
21390 As mentioned earlier the command interface for the debugger has been deliberatel
21391 y kept as close the GNU debugger gdb, as possible.
21392  This will help the integration with existing graphical user interfaces
21393  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
21394  If you use a graphical user interface for the debugger you can skip this
21395  section.
21396 \layout Subsubsection*
21397
21398 break [line | file:line | function | file:function]
21399 \layout Standard
21400
21401 Set breakpoint at specified line or function:
21402 \newline 
21403
21404 \newline 
21405
21406 \family sans 
21407 \series bold 
21408 sdcdb>break 100 
21409 \newline 
21410 sdcdb>break foo.c:100
21411 \newline 
21412 sdcdb>break funcfoo
21413 \newline 
21414 sdcdb>break foo.c:funcfoo
21415 \layout Subsubsection*
21416
21417 clear [line | file:line | function | file:function ]
21418 \layout Standard
21419
21420 Clear breakpoint at specified line or function:
21421 \newline 
21422
21423 \newline 
21424
21425 \family sans 
21426 \series bold 
21427 sdcdb>clear 100
21428 \newline 
21429 sdcdb>clear foo.c:100
21430 \newline 
21431 sdcdb>clear funcfoo
21432 \newline 
21433 sdcdb>clear foo.c:funcfoo
21434 \layout Subsubsection*
21435
21436 continue
21437 \layout Standard
21438
21439 Continue program being debugged, after breakpoint.
21440 \layout Subsubsection*
21441
21442 finish
21443 \layout Standard
21444
21445 Execute till the end of the current function.
21446 \layout Subsubsection*
21447
21448 delete [n]
21449 \layout Standard
21450
21451 Delete breakpoint number 'n'.
21452  If used without any option clear ALL user defined break points.
21453 \layout Subsubsection*
21454
21455 info [break | stack | frame | registers ]
21456 \layout Itemize
21457
21458 info break - list all breakpoints
21459 \layout Itemize
21460
21461 info stack - show the function call stack.
21462 \layout Itemize
21463
21464 info frame - show information about the current execution frame.
21465 \layout Itemize
21466
21467 info registers - show content of all registers.
21468 \layout Subsubsection*
21469
21470 step
21471 \layout Standard
21472
21473 Step program until it reaches a different source line.
21474  Note: pressing <return> repeats the last command.
21475 \layout Subsubsection*
21476
21477 next
21478 \layout Standard
21479
21480 Step program, proceeding through subroutine calls.
21481 \layout Subsubsection*
21482
21483 run
21484 \layout Standard
21485
21486 Start debugged program.
21487 \layout Subsubsection*
21488
21489 ptype variable 
21490 \layout Standard
21491
21492 Print type information of the variable.
21493 \layout Subsubsection*
21494
21495 print variable
21496 \layout Standard
21497
21498 print value of variable.
21499 \layout Subsubsection*
21500
21501 file filename
21502 \layout Standard
21503
21504 load the given file name.
21505  Note this is an alternate method of loading file for debugging.
21506 \layout Subsubsection*
21507
21508 frame
21509 \layout Standard
21510
21511 print information about current frame.
21512 \layout Subsubsection*
21513
21514 set srcmode
21515 \layout Standard
21516
21517 Toggle between C source & assembly source.
21518 \layout Subsubsection*
21519
21520 ! simulator command
21521 \layout Standard
21522
21523 Send the string following '!' to the simulator, the simulator response is
21524  displayed.
21525  Note the debugger does not interpret the command being sent to the simulator,
21526  so if a command like 'go' is sent the debugger can loose its execution
21527  context and may display incorrect values.
21528 \layout Subsubsection*
21529
21530 quit
21531 \layout Standard
21532
21533 "Watch me now.
21534  Iam going Down.
21535  My name is Bobby Brown"
21536 \layout Subsection
21537
21538 Interfacing SDCDB with DDD
21539 \layout Comment
21540
21541 The screenshot was converted from png to eps with: 
21542 \begin_inset Quotes sld
21543 \end_inset 
21544
21545 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
21546 \begin_inset Quotes srd
21547 \end_inset 
21548
21549  which produces a pretty compact eps file which is free from compression
21550  artifacts.
21551 \layout Comment
21552
21553 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
21554  as this broke the build system on Sourceforge (pdf-file was broken).
21555 \layout Standard
21556
21557 The .eps File 
21558 \size footnotesize 
21559
21560 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.eps}
21561
21562 \end_inset 
21563
21564
21565 \size default 
21566  shows a screenshot of a debugging session with DDD
21567 \begin_inset LatexCommand \index{DDD (debugger)}
21568
21569 \end_inset 
21570
21571  (Unix only) on a simulated 8032.
21572  The debugging session might not run as smoothly as the screenshot suggests.
21573  The debugger allows setting of breakpoints, displaying and changing variables,
21574  single stepping through C and assembler code.
21575  
21576 \newline 
21577 The source was compiled with 
21578 \family sans 
21579 \series bold 
21580
21581 \newline 
21582
21583 \newline 
21584 sdcc -
21585 \family default 
21586 \series default 
21587
21588 \begin_inset ERT
21589 status Collapsed
21590
21591 \layout Standard
21592
21593 \backslash 
21594 /
21595 \end_inset 
21596
21597
21598 \family sans 
21599 \series bold 
21600 -debug ddd_example.c
21601 \family default 
21602 \series default 
21603  
21604 \family sans 
21605 \series bold 
21606
21607 \newline 
21608
21609 \family default 
21610 \series default 
21611
21612 \newline 
21613 and DDD was invoked with 
21614 \family sans 
21615 \series bold 
21616
21617 \newline 
21618
21619 \newline 
21620 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
21621 \layout Subsection
21622
21623 Interfacing SDCDB with XEmacs
21624 \begin_inset LatexCommand \index{XEmacs}
21625
21626 \end_inset 
21627
21628
21629 \begin_inset LatexCommand \index{Emacs}
21630
21631 \end_inset 
21632
21633
21634 \layout Standard
21635
21636 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
21637  sdcdb.el and sdcdbsrc.el.
21638  These two files can be found in the $(prefix)/bin directory after the installat
21639 ion is complete.
21640  These files need to be loaded into XEmacs for the interface to work.
21641  This can be done at XEmacs startup time by inserting the following into
21642  your '.xemacs' file (which can be found in your HOME directory): 
21643 \newline 
21644
21645 \newline 
21646
21647 \family typewriter 
21648 (load-file sdcdbsrc.el) 
21649 \family default 
21650
21651 \newline 
21652
21653 \newline 
21654 .xemacs is a lisp file so the () around the command is REQUIRED.
21655  The files can also be loaded dynamically while XEmacs is running, set the
21656  environment variable 'EMACSLOADPATH' to the installation bin directory
21657  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
21658  To start the interface enter the following command: 
21659 \newline 
21660
21661 \newline 
21662
21663 \family sans 
21664 \series bold 
21665 ESC-x sdcdbsrc
21666 \family default 
21667 \series default 
21668
21669 \newline 
21670
21671 \newline 
21672 You will prompted to enter the file name to be debugged.
21673  
21674 \newline 
21675
21676 \newline 
21677 The command line options that are passed to the simulator directly are bound
21678  to default values in the file sdcdbsrc.el.
21679  The variables are listed below, these values maybe changed as required.
21680 \layout Itemize
21681
21682 sdcdbsrc-cpu-type '51
21683 \layout Itemize
21684
21685 sdcdbsrc-frequency '11059200
21686 \layout Itemize
21687
21688 sdcdbsrc-serial nil
21689 \layout Standard
21690
21691 The following is a list of key mapping for the debugger interface.
21692 \layout Standard
21693
21694 \SpecialChar ~
21695
21696 \family typewriter 
21697
21698 \newline 
21699 ;;\SpecialChar ~
21700 Current Listing :: 
21701 \newline 
21702 ;;key\SpecialChar ~
21703 \SpecialChar ~
21704 \SpecialChar ~
21705 \SpecialChar ~
21706 \SpecialChar ~
21707 \SpecialChar ~
21708 \SpecialChar ~
21709 \SpecialChar ~
21710 \SpecialChar ~
21711 \SpecialChar ~
21712 \SpecialChar ~
21713 \SpecialChar ~
21714 \SpecialChar ~
21715 \SpecialChar ~
21716 binding\SpecialChar ~
21717 \SpecialChar ~
21718 \SpecialChar ~
21719 \SpecialChar ~
21720 \SpecialChar ~
21721 \SpecialChar ~
21722 \SpecialChar ~
21723 \SpecialChar ~
21724 \SpecialChar ~
21725 \SpecialChar ~
21726 \SpecialChar ~
21727 \SpecialChar ~
21728 \SpecialChar ~
21729 \SpecialChar ~
21730 \SpecialChar ~
21731 \SpecialChar ~
21732 \SpecialChar ~
21733 \SpecialChar ~
21734 \SpecialChar ~
21735 \SpecialChar ~
21736 \SpecialChar ~
21737 \SpecialChar ~
21738 Comment 
21739 \newline 
21740 ;;---\SpecialChar ~
21741 \SpecialChar ~
21742 \SpecialChar ~
21743 \SpecialChar ~
21744 \SpecialChar ~
21745 \SpecialChar ~
21746 \SpecialChar ~
21747 \SpecialChar ~
21748 \SpecialChar ~
21749 \SpecialChar ~
21750 \SpecialChar ~
21751 \SpecialChar ~
21752 \SpecialChar ~
21753 \SpecialChar ~
21754 -------\SpecialChar ~
21755 \SpecialChar ~
21756 \SpecialChar ~
21757 \SpecialChar ~
21758 \SpecialChar ~
21759 \SpecialChar ~
21760 \SpecialChar ~
21761 \SpecialChar ~
21762 \SpecialChar ~
21763 \SpecialChar ~
21764 \SpecialChar ~
21765 \SpecialChar ~
21766 \SpecialChar ~
21767 \SpecialChar ~
21768 \SpecialChar ~
21769 \SpecialChar ~
21770 \SpecialChar ~
21771 \SpecialChar ~
21772 \SpecialChar ~
21773 \SpecialChar ~
21774 \SpecialChar ~
21775 \SpecialChar ~
21776 -------
21777 \newline 
21778 ;; 
21779 \newline 
21780 ;;\SpecialChar ~
21781 n\SpecialChar ~
21782 \SpecialChar ~
21783 \SpecialChar ~
21784 \SpecialChar ~
21785 \SpecialChar ~
21786 \SpecialChar ~
21787 \SpecialChar ~
21788 \SpecialChar ~
21789 \SpecialChar ~
21790 \SpecialChar ~
21791 \SpecialChar ~
21792 \SpecialChar ~
21793 \SpecialChar ~
21794 \SpecialChar ~
21795 \SpecialChar ~
21796 sdcdb-next-from-src\SpecialChar ~
21797 \SpecialChar ~
21798 \SpecialChar ~
21799 \SpecialChar ~
21800 \SpecialChar ~
21801 \SpecialChar ~
21802 \SpecialChar ~
21803 \SpecialChar ~
21804 \SpecialChar ~
21805 \SpecialChar ~
21806 SDCDB next command 
21807 \newline 
21808 ;;\SpecialChar ~
21809 b\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 sdcdb-back-from-src\SpecialChar ~
21825 \SpecialChar ~
21826 \SpecialChar ~
21827 \SpecialChar ~
21828 \SpecialChar ~
21829 \SpecialChar ~
21830 \SpecialChar ~
21831 \SpecialChar ~
21832 \SpecialChar ~
21833 \SpecialChar ~
21834 SDCDB back command 
21835 \newline 
21836 ;;\SpecialChar ~
21837 c\SpecialChar ~
21838 \SpecialChar ~
21839 \SpecialChar ~
21840 \SpecialChar ~
21841 \SpecialChar ~
21842 \SpecialChar ~
21843 \SpecialChar ~
21844 \SpecialChar ~
21845 \SpecialChar ~
21846 \SpecialChar ~
21847 \SpecialChar ~
21848 \SpecialChar ~
21849 \SpecialChar ~
21850 \SpecialChar ~
21851 \SpecialChar ~
21852 sdcdb-cont-from-src\SpecialChar ~
21853 \SpecialChar ~
21854 \SpecialChar ~
21855 \SpecialChar ~
21856 \SpecialChar ~
21857 \SpecialChar ~
21858 \SpecialChar ~
21859 \SpecialChar ~
21860 \SpecialChar ~
21861 \SpecialChar ~
21862 SDCDB continue command
21863 \newline 
21864 ;;\SpecialChar ~
21865 s\SpecialChar ~
21866 \SpecialChar ~
21867 \SpecialChar ~
21868 \SpecialChar ~
21869 \SpecialChar ~
21870 \SpecialChar ~
21871 \SpecialChar ~
21872 \SpecialChar ~
21873 \SpecialChar ~
21874 \SpecialChar ~
21875 \SpecialChar ~
21876 \SpecialChar ~
21877 \SpecialChar ~
21878 \SpecialChar ~
21879 \SpecialChar ~
21880 sdcdb-step-from-src\SpecialChar ~
21881 \SpecialChar ~
21882 \SpecialChar ~
21883 \SpecialChar ~
21884 \SpecialChar ~
21885 \SpecialChar ~
21886 \SpecialChar ~
21887 \SpecialChar ~
21888 \SpecialChar ~
21889 \SpecialChar ~
21890 SDCDB step command 
21891 \newline 
21892 ;;\SpecialChar ~
21893 ?\SpecialChar ~
21894 \SpecialChar ~
21895 \SpecialChar ~
21896 \SpecialChar ~
21897 \SpecialChar ~
21898 \SpecialChar ~
21899 \SpecialChar ~
21900 \SpecialChar ~
21901 \SpecialChar ~
21902 \SpecialChar ~
21903 \SpecialChar ~
21904 \SpecialChar ~
21905 \SpecialChar ~
21906 \SpecialChar ~
21907 \SpecialChar ~
21908 sdcdb-whatis-c-sexp\SpecialChar ~
21909 \SpecialChar ~
21910 \SpecialChar ~
21911 \SpecialChar ~
21912 \SpecialChar ~
21913 \SpecialChar ~
21914 \SpecialChar ~
21915 \SpecialChar ~
21916 \SpecialChar ~
21917 \SpecialChar ~
21918 SDCDB ptypecommand for data at 
21919 \newline 
21920 ;;\SpecialChar ~
21921 \SpecialChar ~
21922 \SpecialChar ~
21923 \SpecialChar ~
21924 \SpecialChar ~
21925 \SpecialChar ~
21926 \SpecialChar ~
21927 \SpecialChar ~
21928 \SpecialChar ~
21929 \SpecialChar ~
21930 \SpecialChar ~
21931 \SpecialChar ~
21932 \SpecialChar ~
21933 \SpecialChar ~
21934 \SpecialChar ~
21935 \SpecialChar ~
21936 \SpecialChar ~
21937 \SpecialChar ~
21938 \SpecialChar ~
21939 \SpecialChar ~
21940 \SpecialChar ~
21941 \SpecialChar ~
21942 \SpecialChar ~
21943 \SpecialChar ~
21944 \SpecialChar ~
21945 \SpecialChar ~
21946 \SpecialChar ~
21947 \SpecialChar ~
21948 \SpecialChar ~
21949 \SpecialChar ~
21950 \SpecialChar ~
21951 \SpecialChar ~
21952 \SpecialChar ~
21953 \SpecialChar ~
21954 \SpecialChar ~
21955 \SpecialChar ~
21956 \SpecialChar ~
21957 \SpecialChar ~
21958 \SpecialChar ~
21959 \SpecialChar ~
21960 \SpecialChar ~
21961 \SpecialChar ~
21962 \SpecialChar ~
21963 \SpecialChar ~
21964 \SpecialChar ~
21965 \SpecialChar ~
21966 \SpecialChar ~
21967 buffer point 
21968 \newline 
21969 ;;\SpecialChar ~
21970 x\SpecialChar ~
21971 \SpecialChar ~
21972 \SpecialChar ~
21973 \SpecialChar ~
21974 \SpecialChar ~
21975 \SpecialChar ~
21976 \SpecialChar ~
21977 \SpecialChar ~
21978 \SpecialChar ~
21979 \SpecialChar ~
21980 \SpecialChar ~
21981 \SpecialChar ~
21982 \SpecialChar ~
21983 \SpecialChar ~
21984 \SpecialChar ~
21985 sdcdbsrc-delete\SpecialChar ~
21986 \SpecialChar ~
21987 \SpecialChar ~
21988 \SpecialChar ~
21989 \SpecialChar ~
21990 \SpecialChar ~
21991 \SpecialChar ~
21992 \SpecialChar ~
21993 \SpecialChar ~
21994 \SpecialChar ~
21995 \SpecialChar ~
21996 \SpecialChar ~
21997 \SpecialChar ~
21998 \SpecialChar ~
21999 SDCDB Delete all breakpoints if no arg 
22000 \newline 
22001 ;;\SpecialChar ~
22002 \SpecialChar ~
22003 \SpecialChar ~
22004 \SpecialChar ~
22005 \SpecialChar ~
22006 \SpecialChar ~
22007 \SpecialChar ~
22008 \SpecialChar ~
22009 \SpecialChar ~
22010 \SpecialChar ~
22011 \SpecialChar ~
22012 \SpecialChar ~
22013 \SpecialChar ~
22014 \SpecialChar ~
22015 \SpecialChar ~
22016 \SpecialChar ~
22017 \SpecialChar ~
22018 \SpecialChar ~
22019 \SpecialChar ~
22020 \SpecialChar ~
22021 \SpecialChar ~
22022 \SpecialChar ~
22023 \SpecialChar ~
22024 \SpecialChar ~
22025 \SpecialChar ~
22026 \SpecialChar ~
22027 \SpecialChar ~
22028 \SpecialChar ~
22029 \SpecialChar ~
22030 \SpecialChar ~
22031 \SpecialChar ~
22032 \SpecialChar ~
22033 \SpecialChar ~
22034 \SpecialChar ~
22035 \SpecialChar ~
22036 \SpecialChar ~
22037 \SpecialChar ~
22038 \SpecialChar ~
22039 \SpecialChar ~
22040 \SpecialChar ~
22041 \SpecialChar ~
22042 \SpecialChar ~
22043 \SpecialChar ~
22044 \SpecialChar ~
22045 \SpecialChar ~
22046 \SpecialChar ~
22047 \SpecialChar ~
22048 given or delete arg (C-u arg x) 
22049 \newline 
22050 ;;\SpecialChar ~
22051 m\SpecialChar ~
22052 \SpecialChar ~
22053 \SpecialChar ~
22054 \SpecialChar ~
22055 \SpecialChar ~
22056 \SpecialChar ~
22057 \SpecialChar ~
22058 \SpecialChar ~
22059 \SpecialChar ~
22060 \SpecialChar ~
22061 \SpecialChar ~
22062 \SpecialChar ~
22063 \SpecialChar ~
22064 \SpecialChar ~
22065 \SpecialChar ~
22066 sdcdbsrc-frame\SpecialChar ~
22067 \SpecialChar ~
22068 \SpecialChar ~
22069 \SpecialChar ~
22070 \SpecialChar ~
22071 \SpecialChar ~
22072 \SpecialChar ~
22073 \SpecialChar ~
22074 \SpecialChar ~
22075 \SpecialChar ~
22076 \SpecialChar ~
22077 \SpecialChar ~
22078 \SpecialChar ~
22079 \SpecialChar ~
22080 \SpecialChar ~
22081 SDCDB Display current frame if no arg, 
22082 \newline 
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 \SpecialChar ~
22117 \SpecialChar ~
22118 \SpecialChar ~
22119 \SpecialChar ~
22120 \SpecialChar ~
22121 \SpecialChar ~
22122 \SpecialChar ~
22123 \SpecialChar ~
22124 \SpecialChar ~
22125 \SpecialChar ~
22126 \SpecialChar ~
22127 \SpecialChar ~
22128 \SpecialChar ~
22129 \SpecialChar ~
22130 given or display frame arg 
22131 \newline 
22132 ;;\SpecialChar ~
22133 \SpecialChar ~
22134 \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 \SpecialChar ~
22150 \SpecialChar ~
22151 \SpecialChar ~
22152 \SpecialChar ~
22153 \SpecialChar ~
22154 \SpecialChar ~
22155 \SpecialChar ~
22156 \SpecialChar ~
22157 \SpecialChar ~
22158 \SpecialChar ~
22159 \SpecialChar ~
22160 \SpecialChar ~
22161 \SpecialChar ~
22162 \SpecialChar ~
22163 \SpecialChar ~
22164 \SpecialChar ~
22165 \SpecialChar ~
22166 \SpecialChar ~
22167 \SpecialChar ~
22168 \SpecialChar ~
22169 \SpecialChar ~
22170 \SpecialChar ~
22171 \SpecialChar ~
22172 \SpecialChar ~
22173 \SpecialChar ~
22174 \SpecialChar ~
22175 \SpecialChar ~
22176 \SpecialChar ~
22177 \SpecialChar ~
22178 \SpecialChar ~
22179 buffer point 
22180 \newline 
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 sdcdbsrc-goto-sdcdb\SpecialChar ~
22198 \SpecialChar ~
22199 \SpecialChar ~
22200 \SpecialChar ~
22201 \SpecialChar ~
22202 \SpecialChar ~
22203 \SpecialChar ~
22204 \SpecialChar ~
22205 \SpecialChar ~
22206 \SpecialChar ~
22207 Goto the SDCDB output buffer 
22208 \newline 
22209 ;;\SpecialChar ~
22210 p\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 sdcdb-print-c-sexp\SpecialChar ~
22226 \SpecialChar ~
22227 \SpecialChar ~
22228 \SpecialChar ~
22229 \SpecialChar ~
22230 \SpecialChar ~
22231 \SpecialChar ~
22232 \SpecialChar ~
22233 \SpecialChar ~
22234 \SpecialChar ~
22235 \SpecialChar ~
22236 SDCDB print command for data at 
22237 \newline 
22238 ;;\SpecialChar ~
22239 \SpecialChar ~
22240 \SpecialChar ~
22241 \SpecialChar ~
22242 \SpecialChar ~
22243 \SpecialChar ~
22244 \SpecialChar ~
22245 \SpecialChar ~
22246 \SpecialChar ~
22247 \SpecialChar ~
22248 \SpecialChar ~
22249 \SpecialChar ~
22250 \SpecialChar ~
22251 \SpecialChar ~
22252 \SpecialChar ~
22253 \SpecialChar ~
22254 \SpecialChar ~
22255 \SpecialChar ~
22256 \SpecialChar ~
22257 \SpecialChar ~
22258 \SpecialChar ~
22259 \SpecialChar ~
22260 \SpecialChar ~
22261 \SpecialChar ~
22262 \SpecialChar ~
22263 \SpecialChar ~
22264 \SpecialChar ~
22265 \SpecialChar ~
22266 \SpecialChar ~
22267 \SpecialChar ~
22268 \SpecialChar ~
22269 \SpecialChar ~
22270 \SpecialChar ~
22271 \SpecialChar ~
22272 \SpecialChar ~
22273 \SpecialChar ~
22274 \SpecialChar ~
22275 \SpecialChar ~
22276 \SpecialChar ~
22277 \SpecialChar ~
22278 \SpecialChar ~
22279 \SpecialChar ~
22280 \SpecialChar ~
22281 \SpecialChar ~
22282 \SpecialChar ~
22283 \SpecialChar ~
22284 \SpecialChar ~
22285 buffer point 
22286 \newline 
22287 ;;\SpecialChar ~
22288 g\SpecialChar ~
22289 \SpecialChar ~
22290 \SpecialChar ~
22291 \SpecialChar ~
22292 \SpecialChar ~
22293 \SpecialChar ~
22294 \SpecialChar ~
22295 \SpecialChar ~
22296 \SpecialChar ~
22297 \SpecialChar ~
22298 \SpecialChar ~
22299 \SpecialChar ~
22300 \SpecialChar ~
22301 \SpecialChar ~
22302 \SpecialChar ~
22303 sdcdbsrc-goto-sdcdb\SpecialChar ~
22304 \SpecialChar ~
22305 \SpecialChar ~
22306 \SpecialChar ~
22307 \SpecialChar ~
22308 \SpecialChar ~
22309 \SpecialChar ~
22310 \SpecialChar ~
22311 \SpecialChar ~
22312 \SpecialChar ~
22313 Goto the SDCDB output buffer 
22314 \newline 
22315 ;;\SpecialChar ~
22316 t\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 sdcdbsrc-mode\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 Toggles Sdcdbsrc mode (turns it off) 
22348 \newline 
22349 ;; 
22350 \newline 
22351 ;;\SpecialChar ~
22352 C-c\SpecialChar ~
22353 C-f\SpecialChar ~
22354 \SpecialChar ~
22355 \SpecialChar ~
22356 \SpecialChar ~
22357 \SpecialChar ~
22358 \SpecialChar ~
22359 \SpecialChar ~
22360 \SpecialChar ~
22361 \SpecialChar ~
22362 sdcdb-finish-from-src\SpecialChar ~
22363 \SpecialChar ~
22364 \SpecialChar ~
22365 \SpecialChar ~
22366 \SpecialChar ~
22367 \SpecialChar ~
22368 \SpecialChar ~
22369 \SpecialChar ~
22370 SDCDB finish command 
22371 \newline 
22372 ;; 
22373 \newline 
22374 ;;\SpecialChar ~
22375 C-x\SpecialChar ~
22376 SPC\SpecialChar ~
22377 \SpecialChar ~
22378 \SpecialChar ~
22379 \SpecialChar ~
22380 \SpecialChar ~
22381 \SpecialChar ~
22382 \SpecialChar ~
22383 \SpecialChar ~
22384 \SpecialChar ~
22385 sdcdb-break\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 \SpecialChar ~
22400 \SpecialChar ~
22401 \SpecialChar ~
22402 \SpecialChar ~
22403 Set break for line with point 
22404 \newline 
22405 ;;\SpecialChar ~
22406 ESC\SpecialChar ~
22407 t\SpecialChar ~
22408 \SpecialChar ~
22409 \SpecialChar ~
22410 \SpecialChar ~
22411 \SpecialChar ~
22412 \SpecialChar ~
22413 \SpecialChar ~
22414 \SpecialChar ~
22415 \SpecialChar ~
22416 \SpecialChar ~
22417 \SpecialChar ~
22418 sdcdbsrc-mode\SpecialChar ~
22419 \SpecialChar ~
22420 \SpecialChar ~
22421 \SpecialChar ~
22422 \SpecialChar ~
22423 \SpecialChar ~
22424 \SpecialChar ~
22425 \SpecialChar ~
22426 \SpecialChar ~
22427 \SpecialChar ~
22428 \SpecialChar ~
22429 \SpecialChar ~
22430 \SpecialChar ~
22431 \SpecialChar ~
22432 \SpecialChar ~
22433 \SpecialChar ~
22434 Toggle Sdcdbsrc mode 
22435 \newline 
22436 ;;\SpecialChar ~
22437 ESC\SpecialChar ~
22438 m\SpecialChar ~
22439 \SpecialChar ~
22440 \SpecialChar ~
22441 \SpecialChar ~
22442 \SpecialChar ~
22443 \SpecialChar ~
22444 \SpecialChar ~
22445 \SpecialChar ~
22446 \SpecialChar ~
22447 \SpecialChar ~
22448 \SpecialChar ~
22449 sdcdbsrc-srcmode\SpecialChar ~
22450 \SpecialChar ~
22451 \SpecialChar ~
22452 \SpecialChar ~
22453 \SpecialChar ~
22454 \SpecialChar ~
22455 \SpecialChar ~
22456 \SpecialChar ~
22457 \SpecialChar ~
22458 \SpecialChar ~
22459 \SpecialChar ~
22460 \SpecialChar ~
22461 \SpecialChar ~
22462 Toggle list mode 
22463 \newline 
22464 ;; 
22465 \newline 
22466
22467 \layout Chapter
22468 \pagebreak_top 
22469 TIPS
22470 \layout Standard
22471
22472 Here are a few guidelines that will help the compiler generate more efficient
22473  code, some of the tips are specific to this compiler others are generally
22474  good programming practice.
22475 \layout Itemize
22476
22477 Use the smallest data type to represent your data-value.
22478  If it is known in advance that the value is going to be less than 256 then
22479  use an 'unsigned char' instead of a 'short' or 'int'.
22480  Please note, that ANSI C requires both signed and unsigned chars to be
22481  promoted to 'signed int'
22482 \begin_inset LatexCommand \index{promotion to signed int}
22483
22484 \end_inset 
22485
22486  before doing any operation.
22487  This promotion
22488 \begin_inset LatexCommand \index{type promotion}
22489
22490 \end_inset 
22491
22492
22493 \begin_inset LatexCommand \label{type promotion}
22494
22495 \end_inset 
22496
22497  can be omitted, if the result is the same.
22498  The effect of the promotion rules together with the sign-extension is often
22499  surprising:
22500 \begin_deeper 
22501 \layout Verse
22502
22503
22504 \family typewriter 
22505 unsigned char uc = 0xfe;
22506 \newline 
22507 if (uc * uc < 0) /* this is true! */
22508 \newline 
22509 {
22510 \newline 
22511 \SpecialChar ~
22512 \SpecialChar ~
22513 \SpecialChar ~
22514 \SpecialChar ~
22515 ....
22516 \newline 
22517 }
22518 \layout Standard
22519
22520
22521 \family typewriter 
22522 uc * uc
22523 \family default 
22524  is evaluated as 
22525 \family typewriter 
22526 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
22527 \family default 
22528 .
22529  
22530 \newline 
22531 Another one:
22532 \layout Verse
22533
22534
22535 \family typewriter 
22536 (unsigned char) -12 / (signed char) -3 = ...
22537 \layout Standard
22538
22539 No, the result is not 4:
22540 \layout Verse
22541
22542
22543 \family typewriter 
22544 (int) (unsigned char) -12 / (int) (signed char) -3 =
22545 \newline 
22546 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
22547 \newline 
22548 (int) 0x00f4 / (int) 0xfffd =
22549 \newline 
22550 (int) 0x00f4 / (int) 0xfffd =
22551 \newline 
22552 (int) 244 / (int) -3 =
22553 \newline 
22554 (int) -81 = (int) 0xffaf;
22555 \layout Standard
22556
22557 Don't complain, that gcc gives you a different result.
22558  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
22559  Therefore the results are different.
22560 \newline 
22561 From 
22562 \begin_inset Quotes sld
22563 \end_inset 
22564
22565 comp.lang.c FAQ
22566 \begin_inset Quotes srd
22567 \end_inset 
22568
22569 :
22570 \layout Quote
22571
22572 If well-defined overflow characteristics are important and negative values
22573  are not, or if you want to steer clear of sign-extension problems when
22574  manipulating bits or bytes, use one of the corresponding unsigned types.
22575  (Beware when mixing signed and unsigned values in expressions, though.)
22576 \newline 
22577 Although character types (especially unsigned char) can be used as "tiny"
22578  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
22579 ble sign extension and increased code size.
22580 \end_deeper 
22581 \layout Itemize
22582
22583 Use unsigned when it is known in advance that the value is not going to
22584  be negative.
22585  This helps especially if you are doing division or multiplication, bit-shifting
22586  or are using an array index.
22587 \layout Itemize
22588
22589 NEVER jump into a LOOP.
22590 \layout Itemize
22591
22592 Declare the variables to be local
22593 \begin_inset LatexCommand \index{local variables}
22594
22595 \end_inset 
22596
22597  whenever possible, especially loop control variables (induction).
22598 \layout Itemize
22599
22600 Since the compiler does not always do implicit integral promotion, the programme
22601 r should do an explicit cast when integral promotion is required.
22602 \layout Itemize
22603
22604 Reducing the size of division, multiplication & modulus operations can reduce
22605  code size substantially.
22606  Take the following code for example.
22607 \begin_deeper 
22608 \layout Verse
22609
22610
22611 \family typewriter 
22612 foobar(unsigned int p1, unsigned char ch)
22613 \newline 
22614 {
22615 \newline 
22616 \SpecialChar ~
22617 \SpecialChar ~
22618 \SpecialChar ~
22619 \SpecialChar ~
22620 unsigned char ch1 = p1 % ch ;
22621 \newline 
22622 \SpecialChar ~
22623 \SpecialChar ~
22624 \SpecialChar ~
22625 \SpecialChar ~
22626 ....
22627 \newline 
22628 }
22629 \layout Standard
22630
22631 For the modulus operation the variable ch will be promoted to unsigned int
22632  first then the modulus operation will be performed (this will lead to a
22633  call to support routine _moduint()), and the result will be casted to a
22634  char.
22635  If the code is changed to 
22636 \layout Verse
22637
22638
22639 \family typewriter 
22640 foobar(unsigned int p1, unsigned char ch)
22641 \newline 
22642 {
22643 \newline 
22644 \SpecialChar ~
22645 \SpecialChar ~
22646 \SpecialChar ~
22647 \SpecialChar ~
22648 unsigned char ch1 = (unsigned char)p1 % ch ;
22649 \newline 
22650 \SpecialChar ~
22651 \SpecialChar ~
22652 \SpecialChar ~
22653 \SpecialChar ~
22654 ....
22655 \newline 
22656 }
22657 \layout Standard
22658
22659 It would substantially reduce the code generated (future versions of the
22660  compiler will be smart enough to detect such optimization opportunities).
22661 \end_deeper 
22662 \layout Itemize
22663
22664 Have a look at the assembly listing to get a 
22665 \begin_inset Quotes sld
22666 \end_inset 
22667
22668 feeling
22669 \begin_inset Quotes srd
22670 \end_inset 
22671
22672  for the code generation.
22673 \layout Section
22674
22675 Porting code from or to other compilers
22676 \layout Itemize
22677
22678 check whether endianness of the compilers differs and adapt where needed.
22679 \layout Itemize
22680
22681 check the device specific header files for compiler specific syntax.
22682  Eventually include the file <compiler.h
22683 \begin_inset LatexCommand \index{compiler.h (include file)}
22684
22685 \end_inset 
22686
22687 > to allow using common header files.
22688 \layout Itemize
22689
22690 check whether the startup code contains the correct initialization (watchdog,
22691  peripherals).
22692 \layout Itemize
22693
22694 check whether the sizes of short, int, long match.
22695 \layout Itemize
22696
22697 check if some 16 or 32 bit hardware registers require a specific addressing
22698  order (least significant or most significant byte first) and adapt if needed
22699  (
22700 \emph on 
22701 first
22702 \emph default 
22703  and 
22704 \emph on 
22705 last
22706 \emph default 
22707  relate to time and not to lower/upper memory location here, so this is
22708  
22709 \emph on 
22710 not
22711 \emph default 
22712  the same as endianness).
22713 \layout Itemize
22714
22715 check whether the keyword 
22716 \emph on 
22717 volatile
22718 \emph default 
22719  is used where needed.
22720  The compilers might differ in their optimization characteristics (as different
22721  versions of the same compiler might also use more clever optimizations
22722  this is good idea anyway).
22723 \layout Itemize
22724
22725 check that the compilers are not told to supress warnings.
22726 \layout Itemize
22727
22728 check and convert compiler specific extensions (interrupts, memory areas,
22729  pragmas etc.).
22730 \layout Itemize
22731
22732 check for differences in type promotion (especially check for math operations
22733  on char variables and for the use of the ~\SpecialChar ~
22734 operator on bit variables.
22735  See 
22736 \begin_inset LatexCommand \ref{type promotion}
22737
22738 \end_inset 
22739
22740  and 
22741 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
22742
22743 \end_inset 
22744
22745 ).
22746 \layout Itemize
22747
22748 check the assembly code generated for interrupt routines (f.e.
22749  for calls to possibly non-reentrant library functions).
22750 \layout Itemize
22751
22752 check whether timing loops result in proper timing (or preferably consider
22753  a rewrite of the code with timer based delays instead).
22754 \layout Itemize
22755
22756 check for differences in printf parameters (some compilers push (va_arg
22757 \begin_inset LatexCommand \index{va\_arg}
22758
22759 \end_inset 
22760
22761 ) char variables as integers others as char).
22762 \layout Itemize
22763
22764 check the resulting memory layout.
22765 \layout Section
22766
22767 Tools
22768 \begin_inset LatexCommand \index{Tools}
22769
22770 \end_inset 
22771
22772  included in the distribution
22773 \layout Standard
22774 \align center 
22775
22776 \begin_inset  Tabular
22777 <lyxtabular version="3" rows="12" columns="3">
22778 <features>
22779 <column alignment="left" valignment="top" leftline="true" width="0pt">
22780 <column alignment="left" valignment="top" leftline="true" width="0pt">
22781 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
22782 <row topline="true" bottomline="true">
22783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22784 \begin_inset Text
22785
22786 \layout Standard
22787
22788 Name
22789 \end_inset 
22790 </cell>
22791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22792 \begin_inset Text
22793
22794 \layout Standard
22795
22796 Purpose
22797 \end_inset 
22798 </cell>
22799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22800 \begin_inset Text
22801
22802 \layout Standard
22803
22804 Directory
22805 \end_inset 
22806 </cell>
22807 </row>
22808 <row topline="true">
22809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22810 \begin_inset Text
22811
22812 \layout Standard
22813
22814 uCsim
22815 \end_inset 
22816 </cell>
22817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22818 \begin_inset Text
22819
22820 \layout Standard
22821
22822 Simulator for various architectures
22823 \end_inset 
22824 </cell>
22825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22826 \begin_inset Text
22827
22828 \layout Standard
22829
22830 sdcc/sim/ucsim
22831 \end_inset 
22832 </cell>
22833 </row>
22834 <row topline="true">
22835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22836 \begin_inset Text
22837
22838 \layout Standard
22839
22840 keil2sdcc.pl
22841 \end_inset 
22842 </cell>
22843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22844 \begin_inset Text
22845
22846 \layout Standard
22847
22848 header file conversion
22849 \end_inset 
22850 </cell>
22851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22852 \begin_inset Text
22853
22854 \layout Standard
22855
22856 sdcc/support/scripts
22857 \end_inset 
22858 </cell>
22859 </row>
22860 <row topline="true">
22861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22862 \begin_inset Text
22863
22864 \layout Standard
22865
22866 mh2h.c
22867 \end_inset 
22868 </cell>
22869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22870 \begin_inset Text
22871
22872 \layout Standard
22873
22874 header file conversion
22875 \end_inset 
22876 </cell>
22877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22878 \begin_inset Text
22879
22880 \layout Standard
22881
22882 sdcc/support/scripts
22883 \end_inset 
22884 </cell>
22885 </row>
22886 <row topline="true">
22887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22888 \begin_inset Text
22889
22890 \layout Standard
22891
22892 as-gbz80
22893 \end_inset 
22894 </cell>
22895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22896 \begin_inset Text
22897
22898 \layout Standard
22899
22900 Assembler
22901 \end_inset 
22902 </cell>
22903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22904 \begin_inset Text
22905
22906 \layout Standard
22907
22908
22909 \family roman 
22910 \series medium 
22911 \shape up 
22912 \size normal 
22913 \emph off 
22914 \bar no 
22915 \noun off 
22916 \color none
22917 sdcc/bin
22918 \end_inset 
22919 </cell>
22920 </row>
22921 <row topline="true">
22922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22923 \begin_inset Text
22924
22925 \layout Standard
22926
22927 as-z80
22928 \end_inset 
22929 </cell>
22930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22931 \begin_inset Text
22932
22933 \layout Standard
22934
22935 Assembler
22936 \end_inset 
22937 </cell>
22938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22939 \begin_inset Text
22940
22941 \layout Standard
22942
22943
22944 \family roman 
22945 \series medium 
22946 \shape up 
22947 \size normal 
22948 \emph off 
22949 \bar no 
22950 \noun off 
22951 \color none
22952 sdcc/bin
22953 \end_inset 
22954 </cell>
22955 </row>
22956 <row topline="true">
22957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22958 \begin_inset Text
22959
22960 \layout Standard
22961
22962 asx8051
22963 \end_inset 
22964 </cell>
22965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22966 \begin_inset Text
22967
22968 \layout Standard
22969
22970 Assembler
22971 \end_inset 
22972 </cell>
22973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22974 \begin_inset Text
22975
22976 \layout Standard
22977
22978
22979 \family roman 
22980 \series medium 
22981 \shape up 
22982 \size normal 
22983 \emph off 
22984 \bar no 
22985 \noun off 
22986 \color none
22987 sdcc/bin
22988 \end_inset 
22989 </cell>
22990 </row>
22991 <row topline="true">
22992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22993 \begin_inset Text
22994
22995 \layout Standard
22996
22997 sdcdb
22998 \end_inset 
22999 </cell>
23000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23001 \begin_inset Text
23002
23003 \layout Standard
23004
23005 Simulator
23006 \end_inset 
23007 </cell>
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23009 \begin_inset Text
23010
23011 \layout Standard
23012
23013
23014 \family roman 
23015 \series medium 
23016 \shape up 
23017 \size normal 
23018 \emph off 
23019 \bar no 
23020 \noun off 
23021 \color none
23022 sdcc/bin
23023 \end_inset 
23024 </cell>
23025 </row>
23026 <row topline="true">
23027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23028 \begin_inset Text
23029
23030 \layout Standard
23031
23032 aslink
23033 \end_inset 
23034 </cell>
23035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23036 \begin_inset Text
23037
23038 \layout Standard
23039
23040 Linker
23041 \end_inset 
23042 </cell>
23043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23044 \begin_inset Text
23045
23046 \layout Standard
23047
23048
23049 \family roman 
23050 \series medium 
23051 \shape up 
23052 \size normal 
23053 \emph off 
23054 \bar no 
23055 \noun off 
23056 \color none
23057 sdcc/bin
23058 \end_inset 
23059 </cell>
23060 </row>
23061 <row topline="true">
23062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23063 \begin_inset Text
23064
23065 \layout Standard
23066
23067 link-z80
23068 \end_inset 
23069 </cell>
23070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23071 \begin_inset Text
23072
23073 \layout Standard
23074
23075 Linker
23076 \end_inset 
23077 </cell>
23078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23079 \begin_inset Text
23080
23081 \layout Standard
23082
23083
23084 \family roman 
23085 \series medium 
23086 \shape up 
23087 \size normal 
23088 \emph off 
23089 \bar no 
23090 \noun off 
23091 \color none
23092 sdcc/bin
23093 \end_inset 
23094 </cell>
23095 </row>
23096 <row topline="true">
23097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23098 \begin_inset Text
23099
23100 \layout Standard
23101
23102 link-gbz80
23103 \end_inset 
23104 </cell>
23105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23106 \begin_inset Text
23107
23108 \layout Standard
23109
23110 Linker
23111 \end_inset 
23112 </cell>
23113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23114 \begin_inset Text
23115
23116 \layout Standard
23117
23118
23119 \family roman 
23120 \series medium 
23121 \shape up 
23122 \size normal 
23123 \emph off 
23124 \bar no 
23125 \noun off 
23126 \color none
23127 sdcc/bin
23128 \end_inset 
23129 </cell>
23130 </row>
23131 <row topline="true" bottomline="true">
23132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23133 \begin_inset Text
23134
23135 \layout Standard
23136
23137 packihx
23138 \end_inset 
23139 </cell>
23140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23141 \begin_inset Text
23142
23143 \layout Standard
23144
23145 ihx packer
23146 \end_inset 
23147 </cell>
23148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23149 \begin_inset Text
23150
23151 \layout Standard
23152
23153
23154 \family roman 
23155 \series medium 
23156 \shape up 
23157 \size normal 
23158 \emph off 
23159 \bar no 
23160 \noun off 
23161 \color none
23162 sdcc/bin
23163 \end_inset 
23164 </cell>
23165 </row>
23166 </lyxtabular>
23167
23168 \end_inset 
23169
23170
23171 \newline 
23172
23173 \layout Section
23174
23175 Documentation
23176 \begin_inset LatexCommand \index{Documentation}
23177
23178 \end_inset 
23179
23180  included in the distribution
23181 \layout Standard
23182 \align center 
23183
23184 \begin_inset  Tabular
23185 <lyxtabular version="3" rows="10" columns="2">
23186 <features>
23187 <column alignment="left" valignment="top" leftline="true" width="0">
23188 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23189 <row topline="true" bottomline="true">
23190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23191 \begin_inset Text
23192
23193 \layout Standard
23194
23195 Subject / Title
23196 \end_inset 
23197 </cell>
23198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23199 \begin_inset Text
23200
23201 \layout Standard
23202
23203 Where to get / filename
23204 \end_inset 
23205 </cell>
23206 </row>
23207 <row topline="true">
23208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23209 \begin_inset Text
23210
23211 \layout Standard
23212
23213 SDCC Compiler User Guide
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 You're reading it right now
23222 \end_inset 
23223 </cell>
23224 </row>
23225 <row topline="true">
23226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23227 \begin_inset Text
23228
23229 \layout Standard
23230
23231 Changelog of SDCC
23232 \end_inset 
23233 </cell>
23234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23235 \begin_inset Text
23236
23237 \layout Standard
23238
23239 sdcc/Changelog
23240 \end_inset 
23241 </cell>
23242 </row>
23243 <row topline="true">
23244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23245 \begin_inset Text
23246
23247 \layout Standard
23248
23249 ASXXXX
23250 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
23251
23252 \end_inset 
23253
23254
23255 \begin_inset LatexCommand \index{Assembler documentation}
23256
23257 \end_inset 
23258
23259  Assemblers and ASLINK
23260 \begin_inset LatexCommand \index{aslink}
23261
23262 \end_inset 
23263
23264
23265 \begin_inset LatexCommand \index{Linker documentation}
23266
23267 \end_inset 
23268
23269  Relocating Linker
23270 \end_inset 
23271 </cell>
23272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23273 \begin_inset Text
23274
23275 \layout Standard
23276
23277 sdcc/as/doc/asxhtm.html
23278 \end_inset 
23279 </cell>
23280 </row>
23281 <row topline="true">
23282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23283 \begin_inset Text
23284
23285 \layout Standard
23286
23287 SDCC regression test
23288 \begin_inset LatexCommand \index{Regression test}
23289
23290 \end_inset 
23291
23292
23293 \end_inset 
23294 </cell>
23295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23296 \begin_inset Text
23297
23298 \layout Standard
23299
23300 sdcc/doc/test_suite_spec.pdf
23301 \end_inset 
23302 </cell>
23303 </row>
23304 <row topline="true">
23305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23306 \begin_inset Text
23307
23308 \layout Standard
23309
23310 Various notes
23311 \end_inset 
23312 </cell>
23313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23314 \begin_inset Text
23315
23316 \layout Standard
23317
23318 sdcc/doc/*
23319 \end_inset 
23320 </cell>
23321 </row>
23322 <row topline="true">
23323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23324 \begin_inset Text
23325
23326 \layout Standard
23327
23328 Notes on debugging with sdcdb
23329 \begin_inset LatexCommand \index{sdcdb (debugger)}
23330
23331 \end_inset 
23332
23333
23334 \end_inset 
23335 </cell>
23336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23337 \begin_inset Text
23338
23339 \layout Standard
23340
23341 sdcc/debugger/README
23342 \end_inset 
23343 </cell>
23344 </row>
23345 <row topline="true">
23346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23347 \begin_inset Text
23348
23349 \layout Standard
23350
23351 Software simulator for microcontrollers
23352 \end_inset 
23353 </cell>
23354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23355 \begin_inset Text
23356
23357 \layout Standard
23358
23359
23360 \family roman 
23361 \series medium 
23362 \shape up 
23363 \size normal 
23364 \emph off 
23365 \bar no 
23366 \noun off 
23367 \color none
23368 sdcc/sim/ucsim/doc
23369 \family default 
23370 \series default 
23371 \shape default 
23372 \size default 
23373 \emph default 
23374 \bar default 
23375 \noun default 
23376 \color default
23377 /index.html
23378 \end_inset 
23379 </cell>
23380 </row>
23381 <row topline="true">
23382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23383 \begin_inset Text
23384
23385 \layout Standard
23386
23387 Temporary notes on the pic16
23388 \begin_inset LatexCommand \index{PIC16}
23389
23390 \end_inset 
23391
23392  port
23393 \end_inset 
23394 </cell>
23395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23396 \begin_inset Text
23397
23398 \layout Standard
23399
23400 sdcc/src/pic16/NOTES
23401 \end_inset 
23402 </cell>
23403 </row>
23404 <row topline="true" bottomline="true">
23405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23406 \begin_inset Text
23407
23408 \layout Standard
23409
23410 SDCC internal documentation (debugging file format)
23411 \end_inset 
23412 </cell>
23413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23414 \begin_inset Text
23415
23416 \layout Standard
23417
23418 sdcc/doc/
23419 \family roman 
23420 \series medium 
23421 \shape up 
23422 \size normal 
23423 \emph off 
23424 \bar no 
23425 \noun off 
23426 \color none
23427 cdbfileformat.pd
23428 \family default 
23429 \series default 
23430 \shape default 
23431 \size default 
23432 \emph default 
23433 \bar default 
23434 \noun default 
23435 \color default
23436 f
23437 \end_inset 
23438 </cell>
23439 </row>
23440 </lyxtabular>
23441
23442 \end_inset 
23443
23444
23445 \newline 
23446
23447 \layout Section
23448
23449 Related open source tools
23450 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
23451
23452 \end_inset 
23453
23454
23455 \begin_inset LatexCommand \index{Related tools}
23456
23457 \end_inset 
23458
23459
23460 \layout Standard
23461 \align center 
23462
23463 \begin_inset  Tabular
23464 <lyxtabular version="3" rows="14" columns="3">
23465 <features>
23466 <column alignment="left" valignment="top" leftline="true" width="0pt">
23467 <column alignment="block" valignment="top" leftline="true" width="30line%">
23468 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23469 <row topline="true" bottomline="true">
23470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23471 \begin_inset Text
23472
23473 \layout Standard
23474
23475 Name
23476 \end_inset 
23477 </cell>
23478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23479 \begin_inset Text
23480
23481 \layout Standard
23482
23483 Purpose
23484 \end_inset 
23485 </cell>
23486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23487 \begin_inset Text
23488
23489 \layout Standard
23490
23491 Where to get
23492 \end_inset 
23493 </cell>
23494 </row>
23495 <row topline="true">
23496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23497 \begin_inset Text
23498
23499 \layout Standard
23500
23501 gpsim
23502 \begin_inset LatexCommand \index{gpsim (pic simulator)}
23503
23504 \end_inset 
23505
23506
23507 \end_inset 
23508 </cell>
23509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23510 \begin_inset Text
23511
23512 \layout Standard
23513
23514 PIC simulator
23515 \end_inset 
23516 </cell>
23517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23518 \begin_inset Text
23519
23520 \layout Standard
23521
23522
23523 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
23524
23525 \end_inset 
23526
23527
23528 \end_inset 
23529 </cell>
23530 </row>
23531 <row topline="true">
23532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23533 \begin_inset Text
23534
23535 \layout Standard
23536
23537 gputils
23538 \begin_inset LatexCommand \index{gputils (pic tools)}
23539
23540 \end_inset 
23541
23542
23543 \end_inset 
23544 </cell>
23545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23546 \begin_inset Text
23547
23548 \layout Standard
23549
23550 GNU PIC utilities
23551 \end_inset 
23552 </cell>
23553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23554 \begin_inset Text
23555
23556 \layout Standard
23557
23558
23559 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23560
23561 \end_inset 
23562
23563
23564 \end_inset 
23565 </cell>
23566 </row>
23567 <row topline="true">
23568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23569 \begin_inset Text
23570
23571 \layout Standard
23572
23573 flP5
23574 \end_inset 
23575 </cell>
23576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23577 \begin_inset Text
23578
23579 \layout Standard
23580
23581 PIC programmer
23582 \end_inset 
23583 </cell>
23584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23585 \begin_inset Text
23586
23587 \layout Standard
23588
23589
23590 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
23591
23592 \end_inset 
23593
23594
23595 \end_inset 
23596 </cell>
23597 </row>
23598 <row topline="true">
23599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23600 \begin_inset Text
23601
23602 \layout Standard
23603
23604 ec2drv/newcdb
23605 \end_inset 
23606 </cell>
23607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23608 \begin_inset Text
23609
23610 \layout Standard
23611
23612 Tools for Silicon Laboratories JTAG debug adapter, partly based on sdcdb
23613  (Unix only)
23614 \end_inset 
23615 </cell>
23616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23617 \begin_inset Text
23618
23619 \layout Standard
23620
23621
23622 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
23623
23624 \end_inset 
23625
23626
23627 \end_inset 
23628 </cell>
23629 </row>
23630 <row topline="true">
23631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23632 \begin_inset Text
23633
23634 \layout Standard
23635
23636 indent
23637 \begin_inset LatexCommand \index{indent (source formatting tool)}
23638
23639 \end_inset 
23640
23641
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 Formats C source - Master of the white spaces
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://directory.fsf.org/GNU/indent.html}
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 srecord
23673 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
23674
23675 \end_inset 
23676
23677
23678 \end_inset 
23679 </cell>
23680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23681 \begin_inset Text
23682
23683 \layout Standard
23684
23685 Object file conversion, checksumming, ...
23686 \end_inset 
23687 </cell>
23688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23689 \begin_inset Text
23690
23691 \layout Standard
23692
23693
23694 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
23695
23696 \end_inset 
23697
23698
23699 \end_inset 
23700 </cell>
23701 </row>
23702 <row topline="true">
23703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23704 \begin_inset Text
23705
23706 \layout Standard
23707
23708 objdump
23709 \begin_inset LatexCommand \index{objdump (tool)}
23710
23711 \end_inset 
23712
23713
23714 \end_inset 
23715 </cell>
23716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23717 \begin_inset Text
23718
23719 \layout Standard
23720
23721 Object file conversion, ...
23722 \end_inset 
23723 </cell>
23724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23725 \begin_inset Text
23726
23727 \layout Standard
23728
23729 Part of binutils (should be there anyway)
23730 \end_inset 
23731 </cell>
23732 </row>
23733 <row topline="true">
23734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23735 \begin_inset Text
23736
23737 \layout Standard
23738
23739 cmon51
23740 \end_inset 
23741 </cell>
23742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23743 \begin_inset Text
23744
23745 \layout Standard
23746
23747 8051 monitor (hex up-/download, single step, disassemble)
23748 \end_inset 
23749 </cell>
23750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23751 \begin_inset Text
23752
23753 \layout Standard
23754
23755
23756 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
23757
23758 \end_inset 
23759
23760
23761 \end_inset 
23762 </cell>
23763 </row>
23764 <row topline="true">
23765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23766 \begin_inset Text
23767
23768 \layout Standard
23769
23770 doxygen
23771 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
23772
23773 \end_inset 
23774
23775
23776 \end_inset 
23777 </cell>
23778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23779 \begin_inset Text
23780
23781 \layout Standard
23782
23783 Source code documentation system
23784 \end_inset 
23785 </cell>
23786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23787 \begin_inset Text
23788
23789 \layout Standard
23790
23791
23792 \begin_inset LatexCommand \url{http://www.doxygen.org}
23793
23794 \end_inset 
23795
23796
23797 \end_inset 
23798 </cell>
23799 </row>
23800 <row topline="true">
23801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23802 \begin_inset Text
23803
23804 \layout Standard
23805
23806 kdevelop
23807 \end_inset 
23808 </cell>
23809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23810 \begin_inset Text
23811
23812 \layout Standard
23813
23814 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
23815 \end_inset 
23816 </cell>
23817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23818 \begin_inset Text
23819
23820 \layout Standard
23821
23822
23823 \begin_inset LatexCommand \url{http://www.kdevelop.org}
23824
23825 \end_inset 
23826
23827
23828 \end_inset 
23829 </cell>
23830 </row>
23831 <row topline="true">
23832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23833 \begin_inset Text
23834
23835 \layout Standard
23836
23837 paulmon
23838 \end_inset 
23839 </cell>
23840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23841 \begin_inset Text
23842
23843 \layout Standard
23844
23845 8051 monitor (hex up-/download, single step, disassemble)
23846 \end_inset 
23847 </cell>
23848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23849 \begin_inset Text
23850
23851 \layout Standard
23852
23853
23854 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
23855
23856 \end_inset 
23857
23858
23859 \end_inset 
23860 </cell>
23861 </row>
23862 <row topline="true">
23863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23864 \begin_inset Text
23865
23866 \layout Standard
23867
23868 splint
23869 \begin_inset LatexCommand \index{splint (syntax checking tool)}
23870
23871 \end_inset 
23872
23873
23874 \end_inset 
23875 </cell>
23876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23877 \begin_inset Text
23878
23879 \layout Standard
23880
23881 Statically checks c sources (see 
23882 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23883
23884 \end_inset 
23885
23886 )
23887 \end_inset 
23888 </cell>
23889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23890 \begin_inset Text
23891
23892 \layout Standard
23893
23894
23895 \begin_inset LatexCommand \url{http://www.splint.org}
23896
23897 \end_inset 
23898
23899
23900 \end_inset 
23901 </cell>
23902 </row>
23903 <row topline="true" bottomline="true">
23904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23905 \begin_inset Text
23906
23907 \layout Standard
23908
23909 ddd
23910 \begin_inset LatexCommand \index{ddd (debugger)}
23911
23912 \end_inset 
23913
23914
23915 \end_inset 
23916 </cell>
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23918 \begin_inset Text
23919
23920 \layout Standard
23921
23922 Debugger, serves nicely as GUI to sdcdb
23923 \begin_inset LatexCommand \index{sdcdb (debugger)}
23924
23925 \end_inset 
23926
23927  (Unix only)
23928 \end_inset 
23929 </cell>
23930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23931 \begin_inset Text
23932
23933 \layout Standard
23934
23935
23936 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
23937
23938 \end_inset 
23939
23940
23941 \end_inset 
23942 </cell>
23943 </row>
23944 </lyxtabular>
23945
23946 \end_inset 
23947
23948
23949 \newline 
23950
23951 \layout Section
23952
23953 Related documentation / recommended reading
23954 \layout Standard
23955 \align center 
23956
23957 \begin_inset  Tabular
23958 <lyxtabular version="3" rows="8" columns="3">
23959 <features>
23960 <column alignment="left" valignment="top" leftline="true" width="0pt">
23961 <column alignment="block" valignment="top" leftline="true" width="30line%">
23962 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23963 <row topline="true" bottomline="true">
23964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23965 \begin_inset Text
23966
23967 \layout Standard
23968
23969 Name
23970 \end_inset 
23971 </cell>
23972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23973 \begin_inset Text
23974
23975 \layout Standard
23976
23977 Subject / Title
23978 \end_inset 
23979 </cell>
23980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23981 \begin_inset Text
23982
23983 \layout Standard
23984
23985 Where to get
23986 \end_inset 
23987 </cell>
23988 </row>
23989 <row topline="true">
23990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23991 \begin_inset Text
23992
23993 \layout Standard
23994
23995
23996 \family roman 
23997 \series medium 
23998 \shape up 
23999 \size normal 
24000 \emph off 
24001 \bar no 
24002 \noun off 
24003 \color none
24004 c-refcard.pdf
24005 \end_inset 
24006 </cell>
24007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24008 \begin_inset Text
24009
24010 \layout Standard
24011
24012 C Reference Card
24013 \begin_inset LatexCommand \index{C Reference card}
24014
24015 \end_inset 
24016
24017 , 2 pages
24018 \end_inset 
24019 </cell>
24020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24021 \begin_inset Text
24022
24023 \layout Standard
24024
24025
24026 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
24027
24028 \end_inset 
24029
24030
24031 \end_inset 
24032 </cell>
24033 </row>
24034 <row topline="true">
24035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24036 \begin_inset Text
24037
24038 \layout Standard
24039
24040 c-faq
24041 \end_inset 
24042 </cell>
24043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24044 \begin_inset Text
24045
24046 \layout Standard
24047
24048 C-FAQ-list
24049 \end_inset 
24050 </cell>
24051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24052 \begin_inset Text
24053
24054 \layout Standard
24055
24056
24057 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
24058
24059 \end_inset 
24060
24061
24062 \end_inset 
24063 </cell>
24064 </row>
24065 <row topline="true">
24066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24067 \begin_inset Text
24068
24069 \layout Standard
24070
24071 ISO/IEC 9899:TC2
24072 \end_inset 
24073 </cell>
24074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24075 \begin_inset Text
24076
24077 \layout Standard
24078
24079
24080 \begin_inset Quotes sld
24081 \end_inset 
24082
24083 C-Standard
24084 \begin_inset Quotes srd
24085 \end_inset 
24086
24087
24088 \end_inset 
24089 </cell>
24090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24091 \begin_inset Text
24092
24093 \layout Standard
24094
24095
24096 \size footnotesize 
24097
24098 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
24099
24100 \end_inset 
24101
24102
24103 \end_inset 
24104 </cell>
24105 </row>
24106 <row topline="true">
24107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24108 \begin_inset Text
24109
24110 \layout Standard
24111
24112 ISO/IEC DTR 18037
24113 \end_inset 
24114 </cell>
24115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24116 \begin_inset Text
24117
24118 \layout Standard
24119
24120
24121 \begin_inset Quotes sld
24122 \end_inset 
24123
24124 Extensions for Embedded C
24125 \begin_inset Quotes srd
24126 \end_inset 
24127
24128
24129 \end_inset 
24130 </cell>
24131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24132 \begin_inset Text
24133
24134 \layout Standard
24135
24136
24137 \size footnotesize 
24138
24139 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
24140
24141 \end_inset 
24142
24143
24144 \end_inset 
24145 </cell>
24146 </row>
24147 <row topline="true">
24148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24149 \begin_inset Text
24150
24151 \layout Standard
24152
24153 \end_inset 
24154 </cell>
24155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24156 \begin_inset Text
24157
24158 \layout Standard
24159
24160 Latest datasheet of the target CPU
24161 \end_inset 
24162 </cell>
24163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24164 \begin_inset Text
24165
24166 \layout Standard
24167
24168 vendor
24169 \end_inset 
24170 </cell>
24171 </row>
24172 <row topline="true">
24173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24174 \begin_inset Text
24175
24176 \layout Standard
24177
24178 \end_inset 
24179 </cell>
24180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24181 \begin_inset Text
24182
24183 \layout Standard
24184
24185 Revision history of datasheet
24186 \end_inset 
24187 </cell>
24188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24189 \begin_inset Text
24190
24191 \layout Standard
24192
24193 vendor
24194 \end_inset 
24195 </cell>
24196 </row>
24197 <row topline="true" bottomline="true">
24198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24199 \begin_inset Text
24200
24201 \layout Standard
24202
24203 S.
24204  S.
24205  Muchnick
24206 \end_inset 
24207 </cell>
24208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24209 \begin_inset Text
24210
24211 \layout Standard
24212
24213 Advanced Compiler Design and Implementation
24214 \end_inset 
24215 </cell>
24216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24217 \begin_inset Text
24218
24219 \layout Standard
24220
24221 bookstore (very dedicated, probably read other books first)
24222 \end_inset 
24223 </cell>
24224 </row>
24225 </lyxtabular>
24226
24227 \end_inset 
24228
24229
24230 \newline 
24231
24232 \layout Section
24233
24234 Some Questions
24235 \layout Standard
24236
24237 Some questions answered, some pointers given - it might be time to in turn
24238  ask 
24239 \emph on 
24240 you
24241 \emph default 
24242  some questions: 
24243 \layout Itemize
24244
24245 can you solve your project with the selected microcontroller? Would you
24246  find out early or rather late that your target is too small/slow/whatever?
24247  Can you switch to a slightly better device if it doesn't fit?
24248 \layout Itemize
24249
24250 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
24251  and/or another programming language be more adequate? Would an operating
24252  system on the target device help?
24253 \layout Itemize
24254
24255 if you solved the problem, will the marketing department be happy?
24256 \layout Itemize
24257
24258 if the marketing department is happy, will customers be happy?
24259 \layout Itemize
24260
24261 if you're the project manager, marketing department and maybe even the customer
24262  in one person, have you tried to see the project from the outside?
24263 \layout Itemize
24264
24265 is the project done if you think it is done? Or is just that other interface/pro
24266 tocol/feature/configuration/option missing? How about website, manual(s),
24267  internationali(z|s)ation, packaging, labels, 2nd source for components,
24268  electromagnetic compatability/interference, documentation for production,
24269  production test software, update mechanism, patent issues?
24270 \layout Itemize
24271
24272 is your project adequately positioned in that magic triangle: fame, fortune,
24273  fun?
24274 \layout Standard
24275
24276 Maybe not all answers to these questions are known and some answers may
24277  even be 
24278 \emph on 
24279 no
24280 \emph default 
24281 , nevertheless knowing these questions may help you to avoid burnout
24282 \begin_inset Foot
24283 collapsed false
24284
24285 \layout Standard
24286
24287 burnout is bad for electronic devices, programmers and motorcycle tyres
24288 \end_inset 
24289
24290 .
24291  Chances are you didn't want to hear some of them...
24292 \layout Chapter
24293
24294 Support
24295 \begin_inset LatexCommand \index{Support}
24296
24297 \end_inset 
24298
24299
24300 \layout Standard
24301
24302 SDCC has grown to be a large project.
24303  The compiler alone (without the preprocessor, assembler and linker) is
24304  well over 100,000 lines of code (blank stripped).
24305  The open source nature of this project is a key to its continued growth
24306  and support.
24307  You gain the benefit and support of many active software developers and
24308  end users.
24309  Is SDCC perfect? No, that's why we need your help.
24310  The developers take pride in fixing reported bugs.
24311  You can help by reporting the bugs and helping other SDCC users.
24312  There are lots of ways to contribute, and we encourage you to take part
24313  in making SDCC a great software package.
24314  
24315 \layout Standard
24316
24317 The SDCC project is hosted on the SDCC sourceforge site at 
24318 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
24319
24320 \end_inset 
24321
24322 .
24323  You'll find the complete set of mailing lists
24324 \begin_inset LatexCommand \index{Mailing list(s)}
24325
24326 \end_inset 
24327
24328 , forums, bug reporting system, patch submission
24329 \begin_inset LatexCommand \index{Patch submission}
24330
24331 \end_inset 
24332
24333  system, download
24334 \begin_inset LatexCommand \index{download}
24335
24336 \end_inset 
24337
24338  area and Subversion code repository
24339 \begin_inset LatexCommand \index{Subversion code repository}
24340
24341 \end_inset 
24342
24343  there.
24344 \layout Section
24345
24346 Reporting Bugs
24347 \begin_inset LatexCommand \index{Bug reporting}
24348
24349 \end_inset 
24350
24351
24352 \begin_inset LatexCommand \index{Reporting bugs}
24353
24354 \end_inset 
24355
24356
24357 \layout Standard
24358
24359 The recommended way of reporting bugs is using the infrastructure of the
24360  sourceforge site.
24361  You can follow the status of bug reports there and have an overview about
24362  the known bugs.
24363 \layout Standard
24364
24365 Bug reports are automatically forwarded to the developer mailing list and
24366  will be fixed ASAP.
24367  When reporting a bug, it is very useful to include a small test program
24368  (the smaller the better) which reproduces the problem.
24369  If you can isolate the problem by looking at the generated assembly code,
24370  this can be very helpful.
24371  Compiling your program with the -
24372 \begin_inset ERT
24373 status Collapsed
24374
24375 \layout Standard
24376
24377 \backslash 
24378 /
24379 \end_inset 
24380
24381 -dumpall
24382 \begin_inset LatexCommand \index{-\/-dumpall}
24383
24384 \end_inset 
24385
24386  option can sometimes be useful in locating optimization problems.
24387  When reporting a bug please maker sure you:
24388 \layout Enumerate
24389
24390 Attach the code you are compiling with SDCC.
24391  
24392 \layout Enumerate
24393
24394 Specify the exact command you use to run SDCC, or attach your Makefile.
24395  
24396 \layout Enumerate
24397
24398 Specify the SDCC version (type "
24399 \family sans 
24400 \series bold 
24401 sdcc -v
24402 \family default 
24403 \series default 
24404 "), your platform, and operating system.
24405  
24406 \layout Enumerate
24407
24408 Provide an exact copy of any error message or incorrect output.
24409  
24410 \layout Enumerate
24411
24412 Put something meaningful in the subject of your message.
24413 \layout Standard
24414
24415 Please attempt to include these 5 important parts, as applicable, in all
24416  requests for support or when reporting any problems or bugs with SDCC.
24417  Though this will make your message lengthy, it will greatly improve your
24418  chance that SDCC users and developers will be able to help you.
24419  Some SDCC developers are frustrated by bug reports without code provided
24420  that they can use to reproduce and ultimately fix the problem, so please
24421  be sure to provide sample code if you are reporting a bug! 
24422 \layout Standard
24423
24424 Please have a short check that you are using a recent version of SDCC and
24425  the bug is not yet known.
24426  This is the link for reporting bugs: 
24427 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
24428
24429 \end_inset 
24430
24431 .
24432 \layout Section
24433
24434 Requesting Features
24435 \begin_inset LatexCommand \label{sub:Requesting-Features}
24436
24437 \end_inset 
24438
24439
24440 \begin_inset LatexCommand \index{Feature request}
24441
24442 \end_inset 
24443
24444
24445 \begin_inset LatexCommand \index{Requesting features}
24446
24447 \end_inset 
24448
24449
24450 \layout Standard
24451
24452 Like bug reports feature requests are forwarded to the developer mailing
24453  list.
24454  This is the link for requesting features: 
24455 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
24456
24457 \end_inset 
24458
24459 .
24460 \layout Section
24461
24462 Submitting patches
24463 \layout Standard
24464
24465 Like bug reports contributed patches are forwarded to the developer mailing
24466  list.
24467  This is the link for submitting patches
24468 \begin_inset LatexCommand \index{Patch submission}
24469
24470 \end_inset 
24471
24472
24473 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
24474
24475 \end_inset 
24476
24477 .
24478 \layout Standard
24479
24480 You need to specify some parameters to the 
24481 \family typewriter 
24482 diff
24483 \family default 
24484  command for the patches to be useful.
24485  If you modified more than one file a patch created f.e.
24486  with 
24487 \family sans 
24488 \series bold 
24489
24490 \begin_inset Quotes sld
24491 \end_inset 
24492
24493 diff -Naur unmodified_directory modified_directory >my_changes.patch
24494 \begin_inset Quotes srd
24495 \end_inset 
24496
24497
24498 \family default 
24499 \series default 
24500  will be fine, otherwise 
24501 \family sans 
24502 \series bold 
24503
24504 \begin_inset Quotes sld
24505 \end_inset 
24506
24507 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
24508 \begin_inset Quotes srd
24509 \end_inset 
24510
24511
24512 \series default 
24513  
24514 \family default 
24515 will do.
24516 \layout Section
24517
24518 Getting Help
24519 \layout Standard
24520
24521 These links should take you directly to the 
24522 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
24523
24524 \end_inset 
24525
24526
24527 \begin_inset Foot
24528 collapsed false
24529
24530 \layout Standard
24531
24532 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
24533  automated messages (mid 2003)
24534 \end_inset 
24535
24536  and the 
24537 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
24538
24539 \end_inset 
24540
24541 , lists
24542 \begin_inset LatexCommand \index{Mailing list(s)}
24543
24544 \end_inset 
24545
24546  and forums are archived and searchable so if you are lucky someone already
24547  had a similar problem.
24548  While mails to the lists themselves are delivered promptly their web front
24549  end on sourceforge sometimes shows a severe time lag (up to several weeks),
24550  if you're seriously using SDCC please consider subscribing to the lists.
24551 \layout Section
24552
24553 ChangeLog
24554 \layout Standard
24555
24556 You can follow the status of the Subversion version
24557 \begin_inset LatexCommand \index{version}
24558
24559 \end_inset 
24560
24561  of SDCC by watching the Changelog
24562 \begin_inset LatexCommand \index{Changelog}
24563
24564 \end_inset 
24565
24566  in the Subversion repository
24567 \size footnotesize 
24568  
24569 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
24570
24571 \end_inset 
24572
24573 .
24574 \layout Section
24575
24576 Subversion Source Code Repository
24577 \layout Standard
24578
24579 The output of 
24580 \family sans 
24581 \series bold 
24582 sdcc --version
24583 \family default 
24584 \series default 
24585  or the filenames of the snapshot versions of SDCC include date and its
24586  Subversion
24587 \begin_inset LatexCommand \index{Subversion}
24588
24589 \end_inset 
24590
24591  number.
24592  Subversion allows to download the source of recent or previous versions
24593  
24594 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
24595
24596 \end_inset 
24597
24598  (by number or by date).
24599  An on-line source code browser and detailled instructions are also available
24600  there.
24601  SDCC versions starting from 1999 up to now are available (currently the
24602  versions prior to the conversion from cvs to Subversion (April 2006) are
24603  either by accessible by Subversion or by cvs).
24604 \layout Section
24605
24606 Release policy
24607 \begin_inset LatexCommand \index{Release policy}
24608
24609 \end_inset 
24610
24611
24612 \layout Standard
24613
24614 Historically there often were long delays between official releases and
24615  the sourceforge download area tends to get not updated at all.
24616  Excuses in the past might have referred to problems with live range analysis,
24617  but as this was fixed a while ago, the current problem is that another
24618  excuse has to be found.
24619  Kidding aside, we have to get better there! On the other hand there are
24620  daily snapshots available at 
24621 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
24622
24623 \end_inset 
24624
24625 , and you can always build the very last version (hopefully with many bugs
24626  fixed, and features added) from the source code available at 
24627 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
24628
24629 \end_inset 
24630
24631 .
24632 \layout Section
24633
24634 Examples
24635 \begin_inset LatexCommand \index{Examples}
24636
24637 \end_inset 
24638
24639
24640 \layout Standard
24641
24642 You'll find some small examples in the directory 
24643 \emph on 
24644 sdcc/device/examples/.
24645  
24646 \emph default 
24647 More examples and libraries are available at
24648 \emph on 
24649  The SDCC Open Knowledge Resource 
24650 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
24651
24652 \end_inset 
24653
24654  
24655 \emph default 
24656 web site or at 
24657 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
24658
24659 \end_inset 
24660
24661 .
24662 \layout Comment
24663
24664 I did insert a reference to Paul's web site here although it seems rather
24665  dedicated to a specific 8032 board (I think it's okay because it f.e.
24666  shows LCD/Harddisc interface and has a free 8051 monitor.
24667  Independent 8032 board vendors face hard competition of heavily subsidized
24668  development boards anyway).
24669 \layout Comment
24670
24671 Maybe we should include some links to real world applications.
24672  Preferably pointer to pointers (one for each architecture) so this stays
24673  manageable here?
24674 \layout Section
24675
24676 Quality control
24677 \begin_inset LatexCommand \index{Quality control}
24678
24679 \end_inset 
24680
24681
24682 \layout Standard
24683
24684 The compiler is passed through nightly compile and build checks.
24685  The so called 
24686 \shape italic 
24687 regression tests
24688 \shape default 
24689
24690 \begin_inset LatexCommand \index{Regression test}
24691
24692 \end_inset 
24693
24694  check that SDCC itself compiles flawlessly on several platforms and checks
24695  the quality of the code generated by SDCC by running the code through simulator
24696 s.
24697  There is a separate document 
24698 \shape italic 
24699 test_suite.pdf
24700 \begin_inset LatexCommand \index{Test suite}
24701
24702 \end_inset 
24703
24704
24705 \shape default 
24706  about this.
24707 \layout Standard
24708
24709 You'll find the test code in the directory 
24710 \shape italic 
24711 sdcc/support/regression
24712 \shape default 
24713 .
24714  You can run these tests manually by running 
24715 \family sans 
24716 make
24717 \family default 
24718  in this directory (or f.e.
24719  
24720 \family sans 
24721 \series bold 
24722
24723 \begin_inset Quotes sld
24724 \end_inset 
24725
24726 make test-mcs51
24727 \begin_inset Quotes srd
24728 \end_inset 
24729
24730
24731 \family default 
24732 \series default 
24733  if you don't want to run the complete tests).
24734  The test code might also be interesting if you want to look for examples
24735 \begin_inset LatexCommand \index{Examples}
24736
24737 \end_inset 
24738
24739  checking corner cases of SDCC or if you plan to submit patches
24740 \begin_inset LatexCommand \index{Patch submission}
24741
24742 \end_inset 
24743
24744 .
24745 \layout Standard
24746
24747 The pic port uses a different set of regression tests, you'll find them
24748  in the directory 
24749 \shape italic 
24750 sdcc/src/regression
24751 \shape default 
24752 .
24753 \layout Section
24754
24755 Use of SDCC in Education
24756 \layout Standard
24757
24758 In short: 
24759 \emph on 
24760 highly
24761 \emph default 
24762  encouraged
24763 \begin_inset Foot
24764 collapsed false
24765
24766 \layout Standard
24767
24768 the phrase "use in education" might evoke the association "
24769 \emph on 
24770 only
24771 \emph default 
24772  fit for use in education".
24773  This connotation is not intended but nevertheless risked as the licensing
24774  of SDCC makes it difficult to offer educational discounts
24775 \end_inset 
24776
24777 .
24778  If your rationales are to:
24779 \layout Enumerate
24780
24781 give students a chance to understand the 
24782 \emph on 
24783 complete
24784 \emph default 
24785  steps of code generation
24786 \layout Enumerate
24787
24788 have a curriculum that can be extended for years.
24789  Then you could use an fpga board as target and your curriculum will seamlessly
24790  extend from logic synthesis (
24791 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
24792
24793 \end_inset 
24794
24795
24796 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
24797
24798 \end_inset 
24799
24800 ), over assembly programming, to C to FPGA compilers (
24801 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
24802
24803 \end_inset 
24804
24805 ) and to C.
24806 \layout Enumerate
24807
24808 be able to insert excursions about skills like using a revision control
24809  system, submitting/applying patches, using a type-setting (as opposed to
24810  word-processing) engine LyX/LaTeX, using 
24811 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
24812
24813 \end_inset 
24814
24815 , following some 
24816 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
24817
24818 \end_inset 
24819
24820 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
24821  Source Software, CPU simulation, compiler regression tests
24822 \begin_inset LatexCommand \index{Regression test}
24823
24824 \end_inset 
24825
24826 .
24827  
24828 \newline 
24829 And if there should be a shortage of ideas then you can always point students
24830  to the ever-growing feature request list 
24831 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
24832
24833 \end_inset 
24834
24835 .
24836 \layout Enumerate
24837
24838 not tie students to a specific host platform and instead allow them to use
24839  a host platform of 
24840 \emph on 
24841 their
24842 \emph default 
24843  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
24844  eventually 
24845 \begin_inset LatexCommand \url[OLPC]{http://wiki.laptop.org/wiki/One_Laptop_per_Child}
24846
24847 \end_inset 
24848
24849 )
24850 \layout Enumerate
24851
24852 not encourage students to use illegal copies of educational software
24853 \layout Enumerate
24854
24855 be immune to licensing/availability/price changes of the chosen tool chain
24856 \layout Enumerate
24857
24858 be able to change to a new target platform without having to adopt a new
24859  tool chain
24860 \layout Enumerate
24861
24862 have complete control over and insight into the tool chain
24863 \layout Enumerate
24864
24865 make your students aware about the pros and cons of open source software
24866  development
24867 \layout Enumerate
24868
24869 give back to the public as you are probably at least partially publically
24870  funded
24871 \layout Enumerate
24872
24873 give students a chance to publically prove their skills and to possibly
24874  see a world wide impact
24875 \layout Standard
24876
24877 then SDCC is probably among the first choices.
24878  Well, probably SDCC might be the only choice.
24879 \layout Chapter
24880 \pagebreak_top 
24881 SDCC Technical Data
24882 \layout Section
24883
24884 Optimizations
24885 \begin_inset LatexCommand \index{Optimizations}
24886
24887 \end_inset 
24888
24889
24890 \layout Standard
24891
24892 SDCC performs a host of standard optimizations in addition to some MCU specific
24893  optimizations.
24894  
24895 \layout Subsection
24896
24897 Sub-expression Elimination
24898 \begin_inset LatexCommand \index{Subexpression elimination}
24899
24900 \end_inset 
24901
24902
24903 \layout Standard
24904
24905 The compiler does local and 
24906 \emph on 
24907 g
24908 \emph default 
24909 lobal 
24910 \emph on 
24911 c
24912 \emph default 
24913 ommon 
24914 \emph on 
24915 s
24916 \emph default 
24917 ubexpression 
24918 \emph on 
24919 e
24920 \emph default 
24921 limination, e.g.: 
24922 \layout Verse
24923
24924
24925 \family typewriter 
24926 i = x + y + 1; 
24927 \newline 
24928 j = x + y;
24929 \layout Standard
24930
24931 will be translated to
24932 \layout Verse
24933
24934
24935 \family typewriter 
24936 iTemp = x + y; 
24937 \newline 
24938 i = iTemp + 1; 
24939 \newline 
24940 j = iTemp;
24941 \layout Standard
24942
24943 Some subexpressions are not as obvious as the above example, e.g.:
24944 \layout Verse
24945
24946
24947 \family typewriter 
24948 a->b[i].c = 10; 
24949 \newline 
24950 a->b[i].d = 11;
24951 \layout Standard
24952
24953 In this case the address arithmetic a->b[i] will be computed only once;
24954  the equivalent code in C would be.
24955 \layout Verse
24956
24957
24958 \family typewriter 
24959 iTemp = a->b[i]; 
24960 \newline 
24961 iTemp.c = 10; 
24962 \newline 
24963 iTemp.d = 11;
24964 \layout Standard
24965
24966 The compiler will try to keep these temporary variables in registers.
24967 \layout Subsection
24968
24969 Dead-Code Elimination
24970 \begin_inset LatexCommand \index{Dead-code elimination}
24971
24972 \end_inset 
24973
24974
24975 \layout Verse
24976
24977
24978 \family typewriter 
24979 int global;
24980 \newline 
24981
24982 \newline 
24983 void f () { 
24984 \newline 
24985 \SpecialChar ~
24986 \SpecialChar ~
24987 int i; 
24988 \newline 
24989 \SpecialChar ~
24990 \SpecialChar ~
24991 i = 1; \SpecialChar ~
24992 \SpecialChar ~
24993 \SpecialChar ~
24994 \SpecialChar ~
24995 \SpecialChar ~
24996 /* dead store */ 
24997 \newline 
24998 \SpecialChar ~
24999 \SpecialChar ~
25000 global = 1;\SpecialChar ~
25001 /* dead store */ 
25002 \newline 
25003 \SpecialChar ~
25004 \SpecialChar ~
25005 global = 2; 
25006 \newline 
25007 \SpecialChar ~
25008 \SpecialChar ~
25009 return; 
25010 \newline 
25011 \SpecialChar ~
25012 \SpecialChar ~
25013 global = 3;\SpecialChar ~
25014 /* unreachable */ 
25015 \newline 
25016 }
25017 \layout Standard
25018
25019 will be changed to
25020 \layout Verse
25021
25022
25023 \family typewriter 
25024 int global;
25025 \newline 
25026
25027 \newline 
25028 void f () {
25029 \newline 
25030 \SpecialChar ~
25031 \SpecialChar ~
25032 global = 2; 
25033 \newline 
25034 }
25035 \layout Subsection
25036
25037 Copy-Propagation
25038 \begin_inset LatexCommand \index{Copy propagation}
25039
25040 \end_inset 
25041
25042
25043 \layout Verse
25044
25045
25046 \family typewriter 
25047 int f() { 
25048 \newline 
25049 \SpecialChar ~
25050 \SpecialChar ~
25051 int i, j; 
25052 \newline 
25053 \SpecialChar ~
25054 \SpecialChar ~
25055 i = 10; 
25056 \newline 
25057 \SpecialChar ~
25058 \SpecialChar ~
25059 j = i; 
25060 \newline 
25061 \SpecialChar ~
25062 \SpecialChar ~
25063 return j; 
25064 \newline 
25065 }
25066 \layout Standard
25067
25068 will be changed to 
25069 \layout Verse
25070
25071
25072 \family typewriter 
25073 int f() { 
25074 \newline 
25075 \SpecialChar ~
25076 \SpecialChar ~
25077 int i, j; 
25078 \newline 
25079 \SpecialChar ~
25080 \SpecialChar ~
25081 i = 10; 
25082 \newline 
25083 \SpecialChar ~
25084 \SpecialChar ~
25085 j = 10; 
25086 \newline 
25087 \SpecialChar ~
25088 \SpecialChar ~
25089 return 10; 
25090 \newline 
25091 }
25092 \layout Standard
25093
25094 Note: the dead stores created by this copy propagation will be eliminated
25095  by dead-code elimination.
25096 \layout Subsection
25097
25098 Loop Optimizations
25099 \begin_inset LatexCommand \index{Loop optimization}
25100
25101 \end_inset 
25102
25103
25104 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
25105
25106 \end_inset 
25107
25108
25109 \layout Standard
25110
25111 Two types of loop optimizations are done by SDCC 
25112 \emph on 
25113 loop invariant
25114 \emph default 
25115  lifting and
25116 \emph on 
25117  strength reduction
25118 \emph default 
25119  of loop induction variables.
25120  In addition to the strength reduction the optimizer marks the induction
25121  variables and the register allocator tries to keep the induction variables
25122  in registers for the duration of the loop.
25123  Because of this preference of the register allocator
25124 \begin_inset LatexCommand \index{Register allocation}
25125
25126 \end_inset 
25127
25128 , loop induction optimization causes an increase in register pressure, which
25129  may cause unwanted spilling of other temporary variables into the stack
25130 \begin_inset LatexCommand \index{stack}
25131
25132 \end_inset 
25133
25134  / data space.
25135  The compiler will generate a warning message when it is forced to allocate
25136  extra space either on the stack or data space.
25137  If this extra space allocation is undesirable then induction optimization
25138  can be eliminated either for the entire source file (with -
25139 \begin_inset ERT
25140 status Collapsed
25141
25142 \layout Standard
25143
25144 \backslash 
25145 /
25146 \end_inset 
25147
25148 -noinduction option) or for a given function only using #pragma\SpecialChar ~
25149 noinduction
25150 \begin_inset LatexCommand \index{\#pragma noinduction}
25151
25152 \end_inset 
25153
25154 .
25155 \newline 
25156
25157 \newline 
25158 Loop Invariant:
25159 \layout Verse
25160
25161
25162 \family typewriter 
25163 for (i = 0 ; i < 100 ; i ++) 
25164 \newline 
25165 \SpecialChar ~
25166 \SpecialChar ~
25167 \SpecialChar ~
25168 \SpecialChar ~
25169 f += k + l;
25170 \layout Standard
25171
25172 changed to
25173 \layout Verse
25174
25175
25176 \family typewriter 
25177 itemp = k + l; 
25178 \newline 
25179 for (i = 0; i < 100; i++) 
25180 \newline 
25181 \SpecialChar ~
25182 \SpecialChar ~
25183 \SpecialChar ~
25184 \SpecialChar ~
25185 f += itemp;
25186 \layout Standard
25187
25188 As mentioned previously some loop invariants are not as apparent, all static
25189  address computations are also moved out of the loop.
25190 \newline 
25191
25192 \newline 
25193 Strength Reduction
25194 \begin_inset LatexCommand \index{Strength reduction}
25195
25196 \end_inset 
25197
25198 , this optimization substitutes an expression by a cheaper expression:
25199 \layout Verse
25200
25201
25202 \family typewriter 
25203 for (i=0;i < 100; i++)
25204 \newline 
25205 \SpecialChar ~
25206 \SpecialChar ~
25207 \SpecialChar ~
25208 \SpecialChar ~
25209 ar[i*5] = i*3;
25210 \layout Standard
25211
25212 changed to
25213 \layout Verse
25214
25215
25216 \family typewriter 
25217 itemp1 = 0; 
25218 \newline 
25219 itemp2 = 0; 
25220 \newline 
25221 for (i=0;i< 100;i++) { 
25222 \newline 
25223 \SpecialChar ~
25224 \SpecialChar ~
25225 \SpecialChar ~
25226 \SpecialChar ~
25227 ar[itemp1] = itemp2; 
25228 \newline 
25229 \SpecialChar ~
25230 \SpecialChar ~
25231 \SpecialChar ~
25232 \SpecialChar ~
25233 itemp1 += 5; 
25234 \newline 
25235 \SpecialChar ~
25236 \SpecialChar ~
25237 \SpecialChar ~
25238 \SpecialChar ~
25239 itemp2 += 3; 
25240 \newline 
25241 }
25242 \layout Standard
25243
25244 The more expensive multiplication
25245 \begin_inset LatexCommand \index{Multiplication}
25246
25247 \end_inset 
25248
25249  is changed to a less expensive addition.
25250 \layout Subsection
25251
25252 Loop Reversing
25253 \begin_inset LatexCommand \index{Loop reversing}
25254
25255 \end_inset 
25256
25257
25258 \layout Standard
25259
25260 This optimization is done to reduce the overhead of checking loop boundaries
25261  for every iteration.
25262  Some simple loops can be reversed and implemented using a 
25263 \begin_inset Quotes eld
25264 \end_inset 
25265
25266 decrement and jump if not zero
25267 \begin_inset Quotes erd
25268 \end_inset 
25269
25270  instruction.
25271  SDCC checks for the following criterion to determine if a loop is reversible
25272  (note: more sophisticated compilers use data-dependency analysis to make
25273  this determination, SDCC uses a more simple minded analysis).
25274 \layout Itemize
25275
25276 The 'for' loop is of the form 
25277 \newline 
25278
25279 \newline 
25280
25281 \family typewriter 
25282 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
25283  += 1])
25284 \newline 
25285 \SpecialChar ~
25286 \SpecialChar ~
25287 \SpecialChar ~
25288 \SpecialChar ~
25289 <for body>
25290 \layout Itemize
25291
25292 The <for body> does not contain 
25293 \begin_inset Quotes eld
25294 \end_inset 
25295
25296 continue
25297 \begin_inset Quotes erd
25298 \end_inset 
25299
25300  or 'break
25301 \begin_inset Quotes erd
25302 \end_inset 
25303
25304 .
25305 \layout Itemize
25306
25307 All goto's are contained within the loop.
25308 \layout Itemize
25309
25310 No function calls within the loop.
25311 \layout Itemize
25312
25313 The loop control variable <sym> is not assigned any value within the loop
25314 \layout Itemize
25315
25316 The loop control variable does NOT participate in any arithmetic operation
25317  within the loop.
25318 \layout Itemize
25319
25320 There are NO switch statements in the loop.
25321 \layout Subsection
25322
25323 Algebraic Simplifications
25324 \layout Standard
25325
25326 SDCC does numerous algebraic simplifications, the following is a small sub-set
25327  of these optimizations.
25328 \layout Verse
25329
25330
25331 \family typewriter 
25332 i = j + 0;\SpecialChar ~
25333 \SpecialChar ~
25334 \SpecialChar ~
25335 \SpecialChar ~
25336  /* changed to: */\SpecialChar ~
25337 \SpecialChar ~
25338 \SpecialChar ~
25339 \SpecialChar ~
25340  i = j; 
25341 \newline 
25342 i /= 2;\SpecialChar ~
25343 \SpecialChar ~
25344 \SpecialChar ~
25345 \SpecialChar ~
25346 \SpecialChar ~
25347 \SpecialChar ~
25348 \SpecialChar ~
25349  /* changed to: */\SpecialChar ~
25350 \SpecialChar ~
25351 \SpecialChar ~
25352 \SpecialChar ~
25353  i >>= 1; 
25354 \newline 
25355 i = j - j;\SpecialChar ~
25356 \SpecialChar ~
25357 \SpecialChar ~
25358 \SpecialChar ~
25359  /* changed to: */\SpecialChar ~
25360 \SpecialChar ~
25361 \SpecialChar ~
25362 \SpecialChar ~
25363  i = 0; 
25364 \newline 
25365 i = j / 1;\SpecialChar ~
25366 \SpecialChar ~
25367 \SpecialChar ~
25368 \SpecialChar ~
25369  /* changed to: */\SpecialChar ~
25370 \SpecialChar ~
25371 \SpecialChar ~
25372 \SpecialChar ~
25373  i = j;
25374 \layout Standard
25375
25376 Note the subexpressions
25377 \begin_inset LatexCommand \index{Subexpression}
25378
25379 \end_inset 
25380
25381  given above are generally introduced by macro expansions or as a result
25382  of copy/constant propagation.
25383 \layout Subsection
25384
25385 'switch' Statements
25386 \begin_inset LatexCommand \label{sub:'switch'-Statements}
25387
25388 \end_inset 
25389
25390
25391 \begin_inset LatexCommand \index{switch statement}
25392
25393 \end_inset 
25394
25395
25396 \layout Standard
25397
25398 SDCC can optimize switch statements to jump tables
25399 \begin_inset LatexCommand \index{jump tables}
25400
25401 \end_inset 
25402
25403 .
25404  It makes the decision based on an estimate of the generated code size.
25405  SDCC is quite liberal in the requirements for jump table generation: 
25406 \layout Itemize
25407
25408 The labels need not be in order, and the starting number need not be one
25409  or zero, the case labels are in numerical sequence or not too many case
25410  labels are missing.
25411 \begin_deeper 
25412 \layout Verse
25413
25414
25415 \family typewriter 
25416 switch(i) {\SpecialChar ~
25417 \SpecialChar ~
25418 \SpecialChar ~
25419 \SpecialChar ~
25420 \SpecialChar ~
25421 \SpecialChar ~
25422 \SpecialChar ~
25423 \SpecialChar ~
25424 \SpecialChar ~
25425 \SpecialChar ~
25426 \SpecialChar ~
25427 \SpecialChar ~
25428 \SpecialChar ~
25429 \SpecialChar ~
25430 \SpecialChar ~
25431 \SpecialChar ~
25432 \SpecialChar ~
25433 \SpecialChar ~
25434 \SpecialChar ~
25435 \SpecialChar ~
25436 \SpecialChar ~
25437 \SpecialChar ~
25438 \SpecialChar ~
25439 \SpecialChar ~
25440 \SpecialChar ~
25441 \SpecialChar ~
25442 switch (i) { 
25443 \newline 
25444 \SpecialChar ~
25445 \SpecialChar ~
25446 \SpecialChar ~
25447 case 4: ...\SpecialChar ~
25448 \SpecialChar ~
25449 \SpecialChar ~
25450 \SpecialChar ~
25451 \SpecialChar ~
25452 \SpecialChar ~
25453 \SpecialChar ~
25454 \SpecialChar ~
25455 \SpecialChar ~
25456 \SpecialChar ~
25457 \SpecialChar ~
25458 \SpecialChar ~
25459 \SpecialChar ~
25460 \SpecialChar ~
25461 \SpecialChar ~
25462 \SpecialChar ~
25463 \SpecialChar ~
25464 \SpecialChar ~
25465 \SpecialChar ~
25466 \SpecialChar ~
25467 \SpecialChar ~
25468 \SpecialChar ~
25469 \SpecialChar ~
25470 \SpecialChar ~
25471 \SpecialChar ~
25472 \SpecialChar ~
25473 case 0: ...
25474  
25475 \newline 
25476 \SpecialChar ~
25477 \SpecialChar ~
25478 \SpecialChar ~
25479 case 5: ...\SpecialChar ~
25480 \SpecialChar ~
25481 \SpecialChar ~
25482 \SpecialChar ~
25483 \SpecialChar ~
25484 \SpecialChar ~
25485 \SpecialChar ~
25486 \SpecialChar ~
25487 \SpecialChar ~
25488 \SpecialChar ~
25489 \SpecialChar ~
25490 \SpecialChar ~
25491 \SpecialChar ~
25492 \SpecialChar ~
25493 \SpecialChar ~
25494 \SpecialChar ~
25495 \SpecialChar ~
25496 \SpecialChar ~
25497 \SpecialChar ~
25498 \SpecialChar ~
25499 \SpecialChar ~
25500 \SpecialChar ~
25501 \SpecialChar ~
25502 \SpecialChar ~
25503 \SpecialChar ~
25504 \SpecialChar ~
25505 case 1: ...
25506  
25507 \newline 
25508 \SpecialChar ~
25509 \SpecialChar ~
25510 \SpecialChar ~
25511 case 3: ...\SpecialChar ~
25512 \SpecialChar ~
25513 \SpecialChar ~
25514 \SpecialChar ~
25515 \SpecialChar ~
25516 \SpecialChar ~
25517 \SpecialChar ~
25518 \SpecialChar ~
25519 \SpecialChar ~
25520 \SpecialChar ~
25521 \SpecialChar ~
25522 \SpecialChar ~
25523 \SpecialChar ~
25524 \SpecialChar ~
25525 \SpecialChar ~
25526 \SpecialChar ~
25527 \SpecialChar ~
25528 \SpecialChar ~
25529 \SpecialChar ~
25530 \SpecialChar ~
25531 \SpecialChar ~
25532 \SpecialChar ~
25533 \SpecialChar ~
25534 \SpecialChar ~
25535 \SpecialChar ~
25536 \SpecialChar ~
25537
25538 \newline 
25539 \SpecialChar ~
25540 \SpecialChar ~
25541 \SpecialChar ~
25542 case 6: ...\SpecialChar ~
25543 \SpecialChar ~
25544 \SpecialChar ~
25545 \SpecialChar ~
25546 \SpecialChar ~
25547 \SpecialChar ~
25548 \SpecialChar ~
25549 \SpecialChar ~
25550 \SpecialChar ~
25551 \SpecialChar ~
25552 \SpecialChar ~
25553 \SpecialChar ~
25554 \SpecialChar ~
25555 \SpecialChar ~
25556 \SpecialChar ~
25557 \SpecialChar ~
25558 \SpecialChar ~
25559 \SpecialChar ~
25560 \SpecialChar ~
25561 \SpecialChar ~
25562 \SpecialChar ~
25563 \SpecialChar ~
25564 \SpecialChar ~
25565 \SpecialChar ~
25566 \SpecialChar ~
25567 \SpecialChar ~
25568 case 3: ...
25569  
25570 \newline 
25571 \SpecialChar ~
25572 \SpecialChar ~
25573 \SpecialChar ~
25574 case 7: ...\SpecialChar ~
25575 \SpecialChar ~
25576 \SpecialChar ~
25577 \SpecialChar ~
25578 \SpecialChar ~
25579 \SpecialChar ~
25580 \SpecialChar ~
25581 \SpecialChar ~
25582 \SpecialChar ~
25583 \SpecialChar ~
25584 \SpecialChar ~
25585 \SpecialChar ~
25586 \SpecialChar ~
25587 \SpecialChar ~
25588 \SpecialChar ~
25589 \SpecialChar ~
25590 \SpecialChar ~
25591 \SpecialChar ~
25592 \SpecialChar ~
25593 \SpecialChar ~
25594 \SpecialChar ~
25595 \SpecialChar ~
25596 \SpecialChar ~
25597 \SpecialChar ~
25598 \SpecialChar ~
25599 \SpecialChar ~
25600 case 4: ...
25601  
25602 \newline 
25603 \SpecialChar ~
25604 \SpecialChar ~
25605 \SpecialChar ~
25606 case 8: ...\SpecialChar ~
25607 \SpecialChar ~
25608 \SpecialChar ~
25609 \SpecialChar ~
25610 \SpecialChar ~
25611 \SpecialChar ~
25612 \SpecialChar ~
25613 \SpecialChar ~
25614 \SpecialChar ~
25615 \SpecialChar ~
25616 \SpecialChar ~
25617 \SpecialChar ~
25618 \SpecialChar ~
25619 \SpecialChar ~
25620 \SpecialChar ~
25621 \SpecialChar ~
25622 \SpecialChar ~
25623 \SpecialChar ~
25624 \SpecialChar ~
25625 \SpecialChar ~
25626 \SpecialChar ~
25627 \SpecialChar ~
25628 \SpecialChar ~
25629 \SpecialChar ~
25630 \SpecialChar ~
25631 \SpecialChar ~
25632 case 5: ...
25633  
25634 \newline 
25635 \SpecialChar ~
25636 \SpecialChar ~
25637 \SpecialChar ~
25638 case 9: ...\SpecialChar ~
25639 \SpecialChar ~
25640 \SpecialChar ~
25641 \SpecialChar ~
25642 \SpecialChar ~
25643 \SpecialChar ~
25644 \SpecialChar ~
25645 \SpecialChar ~
25646 \SpecialChar ~
25647 \SpecialChar ~
25648 \SpecialChar ~
25649 \SpecialChar ~
25650 \SpecialChar ~
25651 \SpecialChar ~
25652 \SpecialChar ~
25653 \SpecialChar ~
25654 \SpecialChar ~
25655 \SpecialChar ~
25656 \SpecialChar ~
25657 \SpecialChar ~
25658 \SpecialChar ~
25659 \SpecialChar ~
25660 \SpecialChar ~
25661 \SpecialChar ~
25662 \SpecialChar ~
25663 \SpecialChar ~
25664 case 6: ...
25665  
25666 \newline 
25667 \SpecialChar ~
25668 \SpecialChar ~
25669 \SpecialChar ~
25670 case 10: ...\SpecialChar ~
25671 \SpecialChar ~
25672 \SpecialChar ~
25673 \SpecialChar ~
25674 \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 case 7: ...
25696  
25697 \newline 
25698 \SpecialChar ~
25699 \SpecialChar ~
25700 \SpecialChar ~
25701 case 11: ...\SpecialChar ~
25702 \SpecialChar ~
25703 \SpecialChar ~
25704 \SpecialChar ~
25705 \SpecialChar ~
25706 \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 case 8: ...
25727  
25728 \newline 
25729 }\SpecialChar ~
25730 \SpecialChar ~
25731 \SpecialChar ~
25732 \SpecialChar ~
25733 \SpecialChar ~
25734 \SpecialChar ~
25735 \SpecialChar ~
25736 \SpecialChar ~
25737 \SpecialChar ~
25738 \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 \SpecialChar ~
25764 \SpecialChar ~
25765 }
25766 \layout Standard
25767
25768 Both the above switch statements will be implemented using a jump-table.
25769  The example to the right side is slightly more efficient as the check for
25770  the lower boundary of the jump-table is not needed.
25771 \end_deeper 
25772 \layout Itemize
25773
25774 The number of case labels is not larger than supported by the target architectur
25775 e.
25776 \layout Itemize
25777
25778 If the case labels are not in numerical sequence ('gaps' between cases)
25779  SDCC checks whether a jump table with additionally inserted dummy cases
25780  is still attractive.
25781  
25782 \layout Itemize
25783
25784 If the starting number is not zero and a check for the lower boundary of
25785  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
25786  ...
25787  .
25788 \layout Standard
25789
25790 Switch statements which have large gaps in the numeric sequence or those
25791  that have too many case labels can be split into more than one switch statement
25792  for efficient code generation, e.g.:
25793 \layout Verse
25794
25795
25796 \family typewriter 
25797 switch (i) { 
25798 \newline 
25799 \SpecialChar ~
25800 \SpecialChar ~
25801 case 1: ...
25802  
25803 \newline 
25804 \SpecialChar ~
25805 \SpecialChar ~
25806 case 2: ...
25807  
25808 \newline 
25809 \SpecialChar ~
25810 \SpecialChar ~
25811 case 3: ...
25812  
25813 \newline 
25814 \SpecialChar ~
25815 \SpecialChar ~
25816 case 4: ...
25817  
25818 \newline 
25819 \SpecialChar ~
25820 \SpecialChar ~
25821 case 5: ...
25822  
25823 \newline 
25824 \SpecialChar ~
25825 \SpecialChar ~
25826 case 6: ...
25827  
25828 \newline 
25829 \SpecialChar ~
25830 \SpecialChar ~
25831 case 7: ...
25832  
25833 \newline 
25834 \SpecialChar ~
25835 \SpecialChar ~
25836 case 101: ...
25837  
25838 \newline 
25839 \SpecialChar ~
25840 \SpecialChar ~
25841 case 102: ...
25842  
25843 \newline 
25844 \SpecialChar ~
25845 \SpecialChar ~
25846 case 103: ...
25847  
25848 \newline 
25849 \SpecialChar ~
25850 \SpecialChar ~
25851 case 104: ...
25852  
25853 \newline 
25854 \SpecialChar ~
25855 \SpecialChar ~
25856 case 105: ...
25857  
25858 \newline 
25859 \SpecialChar ~
25860 \SpecialChar ~
25861 case 106: ...
25862  
25863 \newline 
25864 \SpecialChar ~
25865 \SpecialChar ~
25866 case 107: ...
25867  
25868 \newline 
25869 }
25870 \layout Standard
25871
25872 If the above switch statement is broken down into two switch statements
25873 \layout Verse
25874
25875
25876 \family typewriter 
25877 switch (i) { 
25878 \newline 
25879 \SpecialChar ~
25880 \SpecialChar ~
25881 case 1: ...
25882  
25883 \newline 
25884 \SpecialChar ~
25885 \SpecialChar ~
25886 case 2: ...
25887  
25888 \newline 
25889 \SpecialChar ~
25890 \SpecialChar ~
25891 case 3: ...
25892  
25893 \newline 
25894 \SpecialChar ~
25895 \SpecialChar ~
25896 case 4: ...
25897  
25898 \newline 
25899 \SpecialChar ~
25900 \SpecialChar ~
25901 case 5: ...
25902  
25903 \newline 
25904 \SpecialChar ~
25905 \SpecialChar ~
25906 case 6: ...
25907  
25908 \newline 
25909 \SpecialChar ~
25910 \SpecialChar ~
25911 case 7: ...
25912  
25913 \newline 
25914 }
25915 \layout Standard
25916
25917 and
25918 \layout Verse
25919
25920
25921 \family typewriter 
25922 switch (i) { 
25923 \newline 
25924 \SpecialChar ~
25925 \SpecialChar ~
25926 case 101: ...
25927  
25928 \newline 
25929 \SpecialChar ~
25930 \SpecialChar ~
25931 case 102: ...
25932  
25933 \newline 
25934 \SpecialChar ~
25935 \SpecialChar ~
25936 case 103: ...
25937  
25938 \newline 
25939 \SpecialChar ~
25940 \SpecialChar ~
25941 case 104: ...
25942  
25943 \newline 
25944 \SpecialChar ~
25945 \SpecialChar ~
25946 case 105: ...
25947  
25948 \newline 
25949 \SpecialChar ~
25950 \SpecialChar ~
25951 case 106: ...
25952  
25953 \newline 
25954 \SpecialChar ~
25955 \SpecialChar ~
25956 case 107: ...
25957  
25958 \newline 
25959 }
25960 \layout Standard
25961
25962 then both the switch statements will be implemented using jump-tables whereas
25963  the unmodified switch statement will not be.
25964 \layout Comment
25965
25966 There might be reasons which SDCC cannot know about to either favour or
25967  not favour jump tables.
25968  If the target system has to be as quick for the last switch case as for
25969  the first (pro jump table), or if the switch argument is known to be zero
25970  in the majority of the cases (contra jump table).
25971 \layout Standard
25972
25973 The pragma nojtbound
25974 \begin_inset LatexCommand \index{\#pragma nojtbound}
25975
25976 \end_inset 
25977
25978  can be used to turn off checking the 
25979 \emph on 
25980 j
25981 \emph default 
25982 ump 
25983 \emph on 
25984 t
25985 \emph default 
25986 able 
25987 \emph on 
25988 bound
25989 \emph default 
25990 aries.
25991  It has no effect if a default label is supplied.
25992  Use of this pragma is dangerous: if the switch
25993 \begin_inset LatexCommand \index{switch statement}
25994
25995 \end_inset 
25996
25997  argument is not matched by a case statement the processor will happily
25998  jump into Nirvana.
25999 \layout Subsection
26000
26001 Bit-shifting Operations
26002 \begin_inset LatexCommand \index{Bit shifting}
26003
26004 \end_inset 
26005
26006 .
26007 \layout Standard
26008
26009 Bit shifting is one of the most frequently used operation in embedded programmin
26010 g.
26011  SDCC tries to implement bit-shift operations in the most efficient way
26012  possible, e.g.:
26013 \layout Verse
26014
26015
26016 \family typewriter 
26017 unsigned char i;
26018 \newline 
26019 ...
26020  
26021 \newline 
26022 i >>= 4; 
26023 \newline 
26024 ...
26025 \layout Standard
26026
26027 generates the following code:
26028 \layout Verse
26029
26030
26031 \family typewriter 
26032 mov\SpecialChar ~
26033  a,_i 
26034 \newline 
26035 swap a 
26036 \newline 
26037 anl\SpecialChar ~
26038  a,#0x0f 
26039 \newline 
26040 mov\SpecialChar ~
26041  _i,a
26042 \layout Standard
26043
26044 In general SDCC will never setup a loop if the shift count is known.
26045  Another example:
26046 \layout Verse
26047
26048
26049 \family typewriter 
26050 unsigned int i; 
26051 \newline 
26052 ...
26053  
26054 \newline 
26055 i >>= 9; 
26056 \newline 
26057 ...
26058 \layout Standard
26059
26060 will generate:
26061 \layout Verse
26062
26063
26064 \family typewriter 
26065 mov\SpecialChar ~
26066 \SpecialChar ~
26067 a,(_i + 1) 
26068 \newline 
26069 mov\SpecialChar ~
26070 \SpecialChar ~
26071 (_i + 1),#0x00 
26072 \newline 
26073 clr\SpecialChar ~
26074 \SpecialChar ~
26075
26076 \newline 
26077 rrc\SpecialChar ~
26078 \SpecialChar ~
26079
26080 \newline 
26081 mov\SpecialChar ~
26082 \SpecialChar ~
26083 _i,a
26084 \layout Subsection
26085
26086 Bit-rotation
26087 \begin_inset LatexCommand \index{Bit rotation}
26088
26089 \end_inset 
26090
26091
26092 \layout Standard
26093
26094 A special case of the bit-shift operation is bit rotation
26095 \begin_inset LatexCommand \index{rotating bits}
26096
26097 \end_inset 
26098
26099 , SDCC recognizes the following expression to be a left bit-rotation:
26100 \layout Verse
26101
26102
26103 \family typewriter 
26104 \series bold 
26105 unsigned
26106 \series default 
26107 \SpecialChar ~
26108 \SpecialChar ~
26109 char i;\SpecialChar ~
26110 \SpecialChar ~
26111 \SpecialChar ~
26112 \SpecialChar ~
26113 \SpecialChar ~
26114 \SpecialChar ~
26115 \SpecialChar ~
26116 \SpecialChar ~
26117 \SpecialChar ~
26118 \SpecialChar ~
26119 \SpecialChar ~
26120 /* unsigned is needed for rotation */ 
26121 \newline 
26122 ...
26123  
26124 \newline 
26125 i = ((i << 1) | (i >> 7)); 
26126 \family default 
26127
26128 \newline 
26129
26130 \family typewriter 
26131 ...
26132 \layout Standard
26133
26134 will generate the following code:
26135 \layout Verse
26136
26137
26138 \family typewriter 
26139 mov\SpecialChar ~
26140 \SpecialChar ~
26141 a,_i 
26142 \newline 
26143 rl\SpecialChar ~
26144 \SpecialChar ~
26145 \SpecialChar ~
26146
26147 \newline 
26148 mov\SpecialChar ~
26149 \SpecialChar ~
26150 _i,a
26151 \layout Standard
26152
26153 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
26154 ns of this case will also be recognized as bit-rotation, i.e.: 
26155 \layout Verse
26156
26157
26158 \family typewriter 
26159 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
26160 \layout Subsection
26161
26162 Nibble and Byte Swapping
26163 \layout Standard
26164
26165 Other special cases of the bit-shift operations are nibble or byte swapping
26166 \begin_inset LatexCommand \index{swapping nibbles/bytes}
26167
26168 \end_inset 
26169
26170 , SDCC recognizes the following expressions:
26171 \layout Verse
26172
26173
26174 \family typewriter 
26175 \series bold 
26176 unsigned
26177 \series default 
26178 \SpecialChar ~
26179 \SpecialChar ~
26180 char i; 
26181 \newline 
26182
26183 \series bold 
26184 unsigned
26185 \series default 
26186 \SpecialChar ~
26187 \SpecialChar ~
26188 int j; 
26189 \newline 
26190 ...
26191  
26192 \newline 
26193 i = ((i << 4) | (i >> 4)); 
26194 \family default 
26195
26196 \newline 
26197
26198 \family typewriter 
26199 j = ((j << 8) | (j >> 8)); 
26200 \layout Standard
26201
26202 and generates a swap instruction for the nibble swapping
26203 \begin_inset LatexCommand \index{Nibble swapping}
26204
26205 \end_inset 
26206
26207  or move instructions for the byte swapping
26208 \begin_inset LatexCommand \index{Byte swapping}
26209
26210 \end_inset 
26211
26212 .
26213  The 
26214 \begin_inset Quotes sld
26215 \end_inset 
26216
26217 j
26218 \begin_inset Quotes srd
26219 \end_inset 
26220
26221  example can be used to convert from little to big-endian or vice versa.
26222  If you want to change the endianness of a 
26223 \emph on 
26224 signed
26225 \emph default 
26226  integer you have to cast to 
26227 \family typewriter 
26228 (unsigned int)
26229 \family default 
26230  first.
26231 \layout Standard
26232
26233 Note that SDCC stores numbers in little-endian
26234 \begin_inset Foot
26235 collapsed false
26236
26237 \layout Standard
26238
26239 Usually 8-bit processors don't care much about endianness.
26240  This is not the case for the standard 8051 which only has an instruction
26241  to increment its 
26242 \emph on 
26243 dptr
26244 \emph default 
26245
26246 \begin_inset LatexCommand \index{DPTR}
26247
26248 \end_inset 
26249
26250 -datapointer
26251 \emph on 
26252  
26253 \emph default 
26254 so little-endian is the more efficient byte order.
26255 \end_inset 
26256
26257
26258 \begin_inset LatexCommand \index{little-endian}
26259
26260 \end_inset 
26261
26262
26263 \begin_inset LatexCommand \index{Endianness}
26264
26265 \end_inset 
26266
26267  format (i.e.
26268  lowest order first).
26269 \layout Subsection
26270
26271 Highest Order Bit
26272 \begin_inset LatexCommand \index{Highest Order Bit}
26273
26274 \end_inset 
26275
26276  / Any Order Bit
26277 \begin_inset LatexCommand \index{Any Order Bit}
26278
26279 \end_inset 
26280
26281
26282 \layout Standard
26283
26284 It is frequently required to obtain the highest order bit of an integral
26285  type (long, int, short or char types).
26286  Also obtaining any other order bit is not uncommon.
26287  SDCC recognizes the following expressions to yield the highest order bit
26288  and generates optimized code for it, e.g.:
26289 \layout Verse
26290
26291
26292 \family typewriter 
26293 unsigned int gint; 
26294 \newline 
26295
26296 \newline 
26297 foo () { 
26298 \newline 
26299 \SpecialChar ~
26300 \SpecialChar ~
26301 unsigned char hob1, aob1; 
26302 \newline 
26303 \SpecialChar ~
26304 \SpecialChar ~
26305 bit hob2, hob3, aob2, aob3; 
26306 \newline 
26307 \SpecialChar ~
26308 \SpecialChar ~
26309 ...
26310  
26311 \newline 
26312 \SpecialChar ~
26313 \SpecialChar ~
26314 hob1 = (gint >> 15) & 1; 
26315 \newline 
26316 \SpecialChar ~
26317 \SpecialChar ~
26318 hob2 = (gint >> 15) & 1; 
26319 \newline 
26320 \SpecialChar ~
26321 \SpecialChar ~
26322 hob3 = gint & 0x8000; 
26323 \newline 
26324 \SpecialChar ~
26325 \SpecialChar ~
26326 aob1 = (gint >> 9) & 1; 
26327 \newline 
26328 \SpecialChar ~
26329 \SpecialChar ~
26330 aob2 = (gint >> 8) & 1; 
26331 \newline 
26332 \SpecialChar ~
26333 \SpecialChar ~
26334 aob3 = gint & 0x0800; 
26335 \newline 
26336 \SpecialChar ~
26337 \SpecialChar ~
26338 ..
26339  
26340 \newline 
26341 }
26342 \layout Standard
26343
26344 will generate the following code:
26345 \layout Verse
26346
26347
26348 \family typewriter 
26349 \SpecialChar ~
26350 \SpecialChar ~
26351 \SpecialChar ~
26352 \SpecialChar ~
26353 \SpecialChar ~
26354 \SpecialChar ~
26355 \SpecialChar ~
26356 \SpecialChar ~
26357 \SpecialChar ~
26358 \SpecialChar ~
26359 \SpecialChar ~
26360 \SpecialChar ~
26361 \SpecialChar ~
26362 \SpecialChar ~
26363 \SpecialChar ~
26364 \SpecialChar ~
26365 \SpecialChar ~
26366 \SpecialChar ~
26367 \SpecialChar ~
26368 \SpecialChar ~
26369 \SpecialChar ~
26370 \SpecialChar ~
26371 \SpecialChar ~
26372 \SpecialChar ~
26373 \SpecialChar ~
26374  61 ;\SpecialChar ~
26375  hob.c 7 
26376 \newline 
26377 000A E5*01\SpecialChar ~
26378 \SpecialChar ~
26379 \SpecialChar ~
26380 \SpecialChar ~
26381 \SpecialChar ~
26382 \SpecialChar ~
26383 \SpecialChar ~
26384 \SpecialChar ~
26385 \SpecialChar ~
26386 \SpecialChar ~
26387 \SpecialChar ~
26388 \SpecialChar ~
26389 \SpecialChar ~
26390 \SpecialChar ~
26391 \SpecialChar ~
26392  62\SpecialChar ~
26393 \SpecialChar ~
26394 \SpecialChar ~
26395 \SpecialChar ~
26396 \SpecialChar ~
26397 \SpecialChar ~
26398 \SpecialChar ~
26399 \SpecialChar ~
26400  mov\SpecialChar ~
26401 \SpecialChar ~
26402  a,(_gint + 1) 
26403 \newline 
26404 000C 23\SpecialChar ~
26405 \SpecialChar ~
26406 \SpecialChar ~
26407 \SpecialChar ~
26408 \SpecialChar ~
26409 \SpecialChar ~
26410 \SpecialChar ~
26411 \SpecialChar ~
26412 \SpecialChar ~
26413 \SpecialChar ~
26414 \SpecialChar ~
26415 \SpecialChar ~
26416 \SpecialChar ~
26417 \SpecialChar ~
26418 \SpecialChar ~
26419 \SpecialChar ~
26420 \SpecialChar ~
26421 \SpecialChar ~
26422  63\SpecialChar ~
26423 \SpecialChar ~
26424 \SpecialChar ~
26425 \SpecialChar ~
26426 \SpecialChar ~
26427 \SpecialChar ~
26428 \SpecialChar ~
26429 \SpecialChar ~
26430  rl\SpecialChar ~
26431 \SpecialChar ~
26432 \SpecialChar ~
26433  a 
26434 \newline 
26435 000D 54 01\SpecialChar ~
26436 \SpecialChar ~
26437 \SpecialChar ~
26438 \SpecialChar ~
26439 \SpecialChar ~
26440 \SpecialChar ~
26441 \SpecialChar ~
26442 \SpecialChar ~
26443 \SpecialChar ~
26444 \SpecialChar ~
26445 \SpecialChar ~
26446 \SpecialChar ~
26447 \SpecialChar ~
26448 \SpecialChar ~
26449 \SpecialChar ~
26450  64\SpecialChar ~
26451 \SpecialChar ~
26452 \SpecialChar ~
26453 \SpecialChar ~
26454 \SpecialChar ~
26455 \SpecialChar ~
26456 \SpecialChar ~
26457 \SpecialChar ~
26458  anl\SpecialChar ~
26459 \SpecialChar ~
26460  a,#0x01 
26461 \newline 
26462 000F F5*02\SpecialChar ~
26463 \SpecialChar ~
26464 \SpecialChar ~
26465 \SpecialChar ~
26466 \SpecialChar ~
26467 \SpecialChar ~
26468 \SpecialChar ~
26469 \SpecialChar ~
26470 \SpecialChar ~
26471 \SpecialChar ~
26472 \SpecialChar ~
26473 \SpecialChar ~
26474 \SpecialChar ~
26475 \SpecialChar ~
26476 \SpecialChar ~
26477  65\SpecialChar ~
26478 \SpecialChar ~
26479 \SpecialChar ~
26480 \SpecialChar ~
26481 \SpecialChar ~
26482 \SpecialChar ~
26483 \SpecialChar ~
26484 \SpecialChar ~
26485  mov\SpecialChar ~
26486 \SpecialChar ~
26487  _foo_hob1_1_1,a 
26488 \newline 
26489 \SpecialChar ~
26490 \SpecialChar ~
26491 \SpecialChar ~
26492 \SpecialChar ~
26493 \SpecialChar ~
26494 \SpecialChar ~
26495 \SpecialChar ~
26496 \SpecialChar ~
26497 \SpecialChar ~
26498 \SpecialChar ~
26499 \SpecialChar ~
26500 \SpecialChar ~
26501 \SpecialChar ~
26502 \SpecialChar ~
26503 \SpecialChar ~
26504 \SpecialChar ~
26505 \SpecialChar ~
26506 \SpecialChar ~
26507 \SpecialChar ~
26508 \SpecialChar ~
26509 \SpecialChar ~
26510 \SpecialChar ~
26511 \SpecialChar ~
26512 \SpecialChar ~
26513 \SpecialChar ~
26514  66 ;\SpecialChar ~
26515  hob.c 8 
26516 \newline 
26517 0011 E5*01\SpecialChar ~
26518 \SpecialChar ~
26519 \SpecialChar ~
26520 \SpecialChar ~
26521 \SpecialChar ~
26522 \SpecialChar ~
26523 \SpecialChar ~
26524 \SpecialChar ~
26525 \SpecialChar ~
26526 \SpecialChar ~
26527 \SpecialChar ~
26528 \SpecialChar ~
26529 \SpecialChar ~
26530 \SpecialChar ~
26531 \SpecialChar ~
26532  67\SpecialChar ~
26533 \SpecialChar ~
26534 \SpecialChar ~
26535 \SpecialChar ~
26536 \SpecialChar ~
26537 \SpecialChar ~
26538 \SpecialChar ~
26539 \SpecialChar ~
26540  mov\SpecialChar ~
26541 \SpecialChar ~
26542  a,(_gint + 1) 
26543 \newline 
26544 0013 33\SpecialChar ~
26545 \SpecialChar ~
26546 \SpecialChar ~
26547 \SpecialChar ~
26548 \SpecialChar ~
26549 \SpecialChar ~
26550 \SpecialChar ~
26551 \SpecialChar ~
26552 \SpecialChar ~
26553 \SpecialChar ~
26554 \SpecialChar ~
26555 \SpecialChar ~
26556 \SpecialChar ~
26557 \SpecialChar ~
26558 \SpecialChar ~
26559 \SpecialChar ~
26560 \SpecialChar ~
26561 \SpecialChar ~
26562  68\SpecialChar ~
26563 \SpecialChar ~
26564 \SpecialChar ~
26565 \SpecialChar ~
26566 \SpecialChar ~
26567 \SpecialChar ~
26568 \SpecialChar ~
26569 \SpecialChar ~
26570  rlc\SpecialChar ~
26571 \SpecialChar ~
26572  a 
26573 \newline 
26574 0014 92*00\SpecialChar ~
26575 \SpecialChar ~
26576 \SpecialChar ~
26577 \SpecialChar ~
26578 \SpecialChar ~
26579 \SpecialChar ~
26580 \SpecialChar ~
26581 \SpecialChar ~
26582 \SpecialChar ~
26583 \SpecialChar ~
26584 \SpecialChar ~
26585 \SpecialChar ~
26586 \SpecialChar ~
26587 \SpecialChar ~
26588 \SpecialChar ~
26589  69\SpecialChar ~
26590 \SpecialChar ~
26591 \SpecialChar ~
26592 \SpecialChar ~
26593 \SpecialChar ~
26594 \SpecialChar ~
26595 \SpecialChar ~
26596 \SpecialChar ~
26597  mov\SpecialChar ~
26598 \SpecialChar ~
26599  _foo_hob2_1_1,c 
26600 \newline 
26601 \SpecialChar ~
26602 \SpecialChar ~
26603 \SpecialChar ~
26604 \SpecialChar ~
26605 \SpecialChar ~
26606 \SpecialChar ~
26607 \SpecialChar ~
26608 \SpecialChar ~
26609 \SpecialChar ~
26610 \SpecialChar ~
26611 \SpecialChar ~
26612 \SpecialChar ~
26613 \SpecialChar ~
26614 \SpecialChar ~
26615 \SpecialChar ~
26616 \SpecialChar ~
26617 \SpecialChar ~
26618 \SpecialChar ~
26619 \SpecialChar ~
26620 \SpecialChar ~
26621 \SpecialChar ~
26622 \SpecialChar ~
26623 \SpecialChar ~
26624 \SpecialChar ~
26625 \SpecialChar ~
26626  66 ;\SpecialChar ~
26627  hob.c 9 
26628 \newline 
26629 0016 E5*01\SpecialChar ~
26630 \SpecialChar ~
26631 \SpecialChar ~
26632 \SpecialChar ~
26633 \SpecialChar ~
26634 \SpecialChar ~
26635 \SpecialChar ~
26636 \SpecialChar ~
26637 \SpecialChar ~
26638 \SpecialChar ~
26639 \SpecialChar ~
26640 \SpecialChar ~
26641 \SpecialChar ~
26642 \SpecialChar ~
26643 \SpecialChar ~
26644  67\SpecialChar ~
26645 \SpecialChar ~
26646 \SpecialChar ~
26647 \SpecialChar ~
26648 \SpecialChar ~
26649 \SpecialChar ~
26650 \SpecialChar ~
26651 \SpecialChar ~
26652  mov\SpecialChar ~
26653 \SpecialChar ~
26654  a,(_gint + 1) 
26655 \newline 
26656 0018 33\SpecialChar ~
26657 \SpecialChar ~
26658 \SpecialChar ~
26659 \SpecialChar ~
26660 \SpecialChar ~
26661 \SpecialChar ~
26662 \SpecialChar ~
26663 \SpecialChar ~
26664 \SpecialChar ~
26665 \SpecialChar ~
26666 \SpecialChar ~
26667 \SpecialChar ~
26668 \SpecialChar ~
26669 \SpecialChar ~
26670 \SpecialChar ~
26671 \SpecialChar ~
26672 \SpecialChar ~
26673 \SpecialChar ~
26674  68\SpecialChar ~
26675 \SpecialChar ~
26676 \SpecialChar ~
26677 \SpecialChar ~
26678 \SpecialChar ~
26679 \SpecialChar ~
26680 \SpecialChar ~
26681 \SpecialChar ~
26682  rlc\SpecialChar ~
26683 \SpecialChar ~
26684  a 
26685 \newline 
26686 0019 92*01\SpecialChar ~
26687 \SpecialChar ~
26688 \SpecialChar ~
26689 \SpecialChar ~
26690 \SpecialChar ~
26691 \SpecialChar ~
26692 \SpecialChar ~
26693 \SpecialChar ~
26694 \SpecialChar ~
26695 \SpecialChar ~
26696 \SpecialChar ~
26697 \SpecialChar ~
26698 \SpecialChar ~
26699 \SpecialChar ~
26700 \SpecialChar ~
26701  69\SpecialChar ~
26702 \SpecialChar ~
26703 \SpecialChar ~
26704 \SpecialChar ~
26705 \SpecialChar ~
26706 \SpecialChar ~
26707 \SpecialChar ~
26708 \SpecialChar ~
26709  mov\SpecialChar ~
26710 \SpecialChar ~
26711  _foo_hob3_1_1,c 
26712 \newline 
26713 \SpecialChar ~
26714 \SpecialChar ~
26715 \SpecialChar ~
26716 \SpecialChar ~
26717 \SpecialChar ~
26718 \SpecialChar ~
26719 \SpecialChar ~
26720 \SpecialChar ~
26721 \SpecialChar ~
26722 \SpecialChar ~
26723 \SpecialChar ~
26724 \SpecialChar ~
26725 \SpecialChar ~
26726 \SpecialChar ~
26727 \SpecialChar ~
26728 \SpecialChar ~
26729 \SpecialChar ~
26730 \SpecialChar ~
26731 \SpecialChar ~
26732 \SpecialChar ~
26733 \SpecialChar ~
26734 \SpecialChar ~
26735 \SpecialChar ~
26736 \SpecialChar ~
26737 \SpecialChar ~
26738  70 ;\SpecialChar ~
26739  hob.c 10 
26740 \newline 
26741 001B E5*01\SpecialChar ~
26742 \SpecialChar ~
26743 \SpecialChar ~
26744 \SpecialChar ~
26745 \SpecialChar ~
26746 \SpecialChar ~
26747 \SpecialChar ~
26748 \SpecialChar ~
26749 \SpecialChar ~
26750 \SpecialChar ~
26751 \SpecialChar ~
26752 \SpecialChar ~
26753 \SpecialChar ~
26754 \SpecialChar ~
26755 \SpecialChar ~
26756  71\SpecialChar ~
26757 \SpecialChar ~
26758 \SpecialChar ~
26759 \SpecialChar ~
26760 \SpecialChar ~
26761 \SpecialChar ~
26762 \SpecialChar ~
26763 \SpecialChar ~
26764  mov\SpecialChar ~
26765 \SpecialChar ~
26766  a,(_gint + 1) 
26767 \newline 
26768 001D 03\SpecialChar ~
26769 \SpecialChar ~
26770 \SpecialChar ~
26771 \SpecialChar ~
26772 \SpecialChar ~
26773 \SpecialChar ~
26774 \SpecialChar ~
26775 \SpecialChar ~
26776 \SpecialChar ~
26777 \SpecialChar ~
26778 \SpecialChar ~
26779 \SpecialChar ~
26780 \SpecialChar ~
26781 \SpecialChar ~
26782 \SpecialChar ~
26783 \SpecialChar ~
26784 \SpecialChar ~
26785 \SpecialChar ~
26786  72\SpecialChar ~
26787 \SpecialChar ~
26788 \SpecialChar ~
26789 \SpecialChar ~
26790 \SpecialChar ~
26791 \SpecialChar ~
26792 \SpecialChar ~
26793 \SpecialChar ~
26794  rr\SpecialChar ~
26795 \SpecialChar ~
26796 \SpecialChar ~
26797  a 
26798 \newline 
26799 001E 54 01\SpecialChar ~
26800 \SpecialChar ~
26801 \SpecialChar ~
26802 \SpecialChar ~
26803 \SpecialChar ~
26804 \SpecialChar ~
26805 \SpecialChar ~
26806 \SpecialChar ~
26807 \SpecialChar ~
26808 \SpecialChar ~
26809 \SpecialChar ~
26810 \SpecialChar ~
26811 \SpecialChar ~
26812 \SpecialChar ~
26813 \SpecialChar ~
26814  73\SpecialChar ~
26815 \SpecialChar ~
26816 \SpecialChar ~
26817 \SpecialChar ~
26818 \SpecialChar ~
26819 \SpecialChar ~
26820 \SpecialChar ~
26821 \SpecialChar ~
26822  anl\SpecialChar ~
26823 \SpecialChar ~
26824  a,#0x01 
26825 \newline 
26826 0020 F5*03\SpecialChar ~
26827 \SpecialChar ~
26828 \SpecialChar ~
26829 \SpecialChar ~
26830 \SpecialChar ~
26831 \SpecialChar ~
26832 \SpecialChar ~
26833 \SpecialChar ~
26834 \SpecialChar ~
26835 \SpecialChar ~
26836 \SpecialChar ~
26837 \SpecialChar ~
26838 \SpecialChar ~
26839 \SpecialChar ~
26840 \SpecialChar ~
26841  74\SpecialChar ~
26842 \SpecialChar ~
26843 \SpecialChar ~
26844 \SpecialChar ~
26845 \SpecialChar ~
26846 \SpecialChar ~
26847 \SpecialChar ~
26848 \SpecialChar ~
26849  mov\SpecialChar ~
26850 \SpecialChar ~
26851  _foo_aob1_1_1,a 
26852 \newline 
26853 \SpecialChar ~
26854 \SpecialChar ~
26855 \SpecialChar ~
26856 \SpecialChar ~
26857 \SpecialChar ~
26858 \SpecialChar ~
26859 \SpecialChar ~
26860 \SpecialChar ~
26861 \SpecialChar ~
26862 \SpecialChar ~
26863 \SpecialChar ~
26864 \SpecialChar ~
26865 \SpecialChar ~
26866 \SpecialChar ~
26867 \SpecialChar ~
26868 \SpecialChar ~
26869 \SpecialChar ~
26870 \SpecialChar ~
26871 \SpecialChar ~
26872 \SpecialChar ~
26873 \SpecialChar ~
26874 \SpecialChar ~
26875 \SpecialChar ~
26876 \SpecialChar ~
26877 \SpecialChar ~
26878  75 ;\SpecialChar ~
26879  hob.c 11 
26880 \newline 
26881 0022 E5*01\SpecialChar ~
26882 \SpecialChar ~
26883 \SpecialChar ~
26884 \SpecialChar ~
26885 \SpecialChar ~
26886 \SpecialChar ~
26887 \SpecialChar ~
26888 \SpecialChar ~
26889 \SpecialChar ~
26890 \SpecialChar ~
26891 \SpecialChar ~
26892 \SpecialChar ~
26893 \SpecialChar ~
26894 \SpecialChar ~
26895 \SpecialChar ~
26896  76\SpecialChar ~
26897 \SpecialChar ~
26898 \SpecialChar ~
26899 \SpecialChar ~
26900 \SpecialChar ~
26901 \SpecialChar ~
26902 \SpecialChar ~
26903 \SpecialChar ~
26904  mov\SpecialChar ~
26905 \SpecialChar ~
26906  a,(_gint + 1) 
26907 \newline 
26908 0024 13\SpecialChar ~
26909 \SpecialChar ~
26910 \SpecialChar ~
26911 \SpecialChar ~
26912 \SpecialChar ~
26913 \SpecialChar ~
26914 \SpecialChar ~
26915 \SpecialChar ~
26916 \SpecialChar ~
26917 \SpecialChar ~
26918 \SpecialChar ~
26919 \SpecialChar ~
26920 \SpecialChar ~
26921 \SpecialChar ~
26922 \SpecialChar ~
26923 \SpecialChar ~
26924 \SpecialChar ~
26925 \SpecialChar ~
26926  77\SpecialChar ~
26927 \SpecialChar ~
26928 \SpecialChar ~
26929 \SpecialChar ~
26930 \SpecialChar ~
26931 \SpecialChar ~
26932 \SpecialChar ~
26933 \SpecialChar ~
26934  rrc\SpecialChar ~
26935 \SpecialChar ~
26936  a 
26937 \newline 
26938 0025 92*02\SpecialChar ~
26939 \SpecialChar ~
26940 \SpecialChar ~
26941 \SpecialChar ~
26942 \SpecialChar ~
26943 \SpecialChar ~
26944 \SpecialChar ~
26945 \SpecialChar ~
26946 \SpecialChar ~
26947 \SpecialChar ~
26948 \SpecialChar ~
26949 \SpecialChar ~
26950 \SpecialChar ~
26951 \SpecialChar ~
26952 \SpecialChar ~
26953  78\SpecialChar ~
26954 \SpecialChar ~
26955 \SpecialChar ~
26956 \SpecialChar ~
26957 \SpecialChar ~
26958 \SpecialChar ~
26959 \SpecialChar ~
26960 \SpecialChar ~
26961  mov\SpecialChar ~
26962 \SpecialChar ~
26963  _foo_aob2_1_1,c 
26964 \newline 
26965 \SpecialChar ~
26966 \SpecialChar ~
26967 \SpecialChar ~
26968 \SpecialChar ~
26969 \SpecialChar ~
26970 \SpecialChar ~
26971 \SpecialChar ~
26972 \SpecialChar ~
26973 \SpecialChar ~
26974 \SpecialChar ~
26975 \SpecialChar ~
26976 \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  79 ;\SpecialChar ~
26991  hob.c 12 
26992 \newline 
26993 0027 E5*01\SpecialChar ~
26994 \SpecialChar ~
26995 \SpecialChar ~
26996 \SpecialChar ~
26997 \SpecialChar ~
26998 \SpecialChar ~
26999 \SpecialChar ~
27000 \SpecialChar ~
27001 \SpecialChar ~
27002 \SpecialChar ~
27003 \SpecialChar ~
27004 \SpecialChar ~
27005 \SpecialChar ~
27006 \SpecialChar ~
27007 \SpecialChar ~
27008  80\SpecialChar ~
27009 \SpecialChar ~
27010 \SpecialChar ~
27011 \SpecialChar ~
27012 \SpecialChar ~
27013 \SpecialChar ~
27014 \SpecialChar ~
27015 \SpecialChar ~
27016  mov\SpecialChar ~
27017 \SpecialChar ~
27018  a,(_gint + 1) 
27019 \newline 
27020 0029 A2 E3\SpecialChar ~
27021 \SpecialChar ~
27022 \SpecialChar ~
27023 \SpecialChar ~
27024 \SpecialChar ~
27025 \SpecialChar ~
27026 \SpecialChar ~
27027 \SpecialChar ~
27028 \SpecialChar ~
27029 \SpecialChar ~
27030 \SpecialChar ~
27031 \SpecialChar ~
27032 \SpecialChar ~
27033 \SpecialChar ~
27034 \SpecialChar ~
27035  81\SpecialChar ~
27036 \SpecialChar ~
27037 \SpecialChar ~
27038 \SpecialChar ~
27039 \SpecialChar ~
27040 \SpecialChar ~
27041 \SpecialChar ~
27042 \SpecialChar ~
27043  mov\SpecialChar ~
27044 \SpecialChar ~
27045  c,acc[3] 
27046 \newline 
27047 002B 92*03\SpecialChar ~
27048 \SpecialChar ~
27049 \SpecialChar ~
27050 \SpecialChar ~
27051 \SpecialChar ~
27052 \SpecialChar ~
27053 \SpecialChar ~
27054 \SpecialChar ~
27055 \SpecialChar ~
27056 \SpecialChar ~
27057 \SpecialChar ~
27058 \SpecialChar ~
27059 \SpecialChar ~
27060 \SpecialChar ~
27061 \SpecialChar ~
27062  82\SpecialChar ~
27063 \SpecialChar ~
27064 \SpecialChar ~
27065 \SpecialChar ~
27066 \SpecialChar ~
27067 \SpecialChar ~
27068 \SpecialChar ~
27069 \SpecialChar ~
27070  mov\SpecialChar ~
27071 \SpecialChar ~
27072  _foo_aob3_1_1,c 
27073 \layout Standard
27074
27075 Other variations of these cases however will 
27076 \emph on 
27077 not
27078 \emph default 
27079  be recognized.
27080  They are standard C expressions, so I heartily recommend these be the only
27081  way to get the highest order bit, (it is portable).
27082  Of course it will be recognized even if it is embedded in other expressions,
27083  e.g.:
27084 \layout Verse
27085
27086
27087 \family typewriter 
27088 xyz = gint + ((gint >> 15) & 1);
27089 \layout Standard
27090
27091 will still be recognized.
27092 \layout Subsection
27093
27094 Higher Order Byte
27095 \begin_inset LatexCommand \index{Higher Order Byte}
27096
27097 \end_inset 
27098
27099  / Higher Order Word
27100 \begin_inset LatexCommand \index{Higher Order Word}
27101
27102 \end_inset 
27103
27104
27105 \layout Standard
27106
27107 It is also frequently required to obtain a higher order byte or word of
27108  a larger integral type (long, int or short types).
27109  SDCC recognizes the following expressions to yield the higher order byte
27110  or word and generates optimized code for it, e.g.:
27111 \layout Verse
27112
27113
27114 \family typewriter 
27115 unsigned int gint; 
27116 \newline 
27117 unsigned long int glong; 
27118 \newline 
27119
27120 \newline 
27121 foo () { 
27122 \newline 
27123 \SpecialChar ~
27124 \SpecialChar ~
27125 unsigned char hob1, hob2; 
27126 \newline 
27127 \SpecialChar ~
27128 \SpecialChar ~
27129 unsigned int how1, how2; 
27130 \newline 
27131 \SpecialChar ~
27132 \SpecialChar ~
27133 ...
27134  
27135 \newline 
27136 \SpecialChar ~
27137 \SpecialChar ~
27138 hob1 = (gint >> 8) & 0xFF; 
27139 \newline 
27140 \SpecialChar ~
27141 \SpecialChar ~
27142 hob2 = glong >> 24; 
27143 \newline 
27144 \SpecialChar ~
27145 \SpecialChar ~
27146 how1 = (glong >> 16) & 0xFFFF; 
27147 \newline 
27148 \SpecialChar ~
27149 \SpecialChar ~
27150 how2 = glong >> 8; 
27151 \newline 
27152 \SpecialChar ~
27153 \SpecialChar ~
27154 ..
27155  
27156 \newline 
27157 }
27158 \layout Standard
27159
27160 will generate the following code:
27161 \layout Verse
27162
27163
27164 \family typewriter 
27165 \SpecialChar ~
27166 \SpecialChar ~
27167 \SpecialChar ~
27168 \SpecialChar ~
27169 \SpecialChar ~
27170 \SpecialChar ~
27171 \SpecialChar ~
27172 \SpecialChar ~
27173 \SpecialChar ~
27174 \SpecialChar ~
27175 \SpecialChar ~
27176 \SpecialChar ~
27177 \SpecialChar ~
27178 \SpecialChar ~
27179 \SpecialChar ~
27180 \SpecialChar ~
27181 \SpecialChar ~
27182 \SpecialChar ~
27183 \SpecialChar ~
27184 \SpecialChar ~
27185 \SpecialChar ~
27186 \SpecialChar ~
27187 \SpecialChar ~
27188 \SpecialChar ~
27189 \SpecialChar ~
27190  91 ;\SpecialChar ~
27191  hob.c 15 
27192 \newline 
27193 0037 85*01*06\SpecialChar ~
27194 \SpecialChar ~
27195 \SpecialChar ~
27196 \SpecialChar ~
27197 \SpecialChar ~
27198 \SpecialChar ~
27199 \SpecialChar ~
27200 \SpecialChar ~
27201 \SpecialChar ~
27202 \SpecialChar ~
27203 \SpecialChar ~
27204 \SpecialChar ~
27205  92\SpecialChar ~
27206 \SpecialChar ~
27207 \SpecialChar ~
27208 \SpecialChar ~
27209 \SpecialChar ~
27210 \SpecialChar ~
27211 \SpecialChar ~
27212 \SpecialChar ~
27213  mov\SpecialChar ~
27214 \SpecialChar ~
27215  _foo_hob1_1_1,(_gint + 1) 
27216 \newline 
27217 \SpecialChar ~
27218 \SpecialChar ~
27219 \SpecialChar ~
27220 \SpecialChar ~
27221 \SpecialChar ~
27222 \SpecialChar ~
27223 \SpecialChar ~
27224 \SpecialChar ~
27225 \SpecialChar ~
27226 \SpecialChar ~
27227 \SpecialChar ~
27228 \SpecialChar ~
27229 \SpecialChar ~
27230 \SpecialChar ~
27231 \SpecialChar ~
27232 \SpecialChar ~
27233 \SpecialChar ~
27234 \SpecialChar ~
27235 \SpecialChar ~
27236 \SpecialChar ~
27237 \SpecialChar ~
27238 \SpecialChar ~
27239 \SpecialChar ~
27240 \SpecialChar ~
27241 \SpecialChar ~
27242  93 ;\SpecialChar ~
27243  hob.c 16 
27244 \newline 
27245 003A 85*05*07\SpecialChar ~
27246 \SpecialChar ~
27247 \SpecialChar ~
27248 \SpecialChar ~
27249 \SpecialChar ~
27250 \SpecialChar ~
27251 \SpecialChar ~
27252 \SpecialChar ~
27253 \SpecialChar ~
27254 \SpecialChar ~
27255 \SpecialChar ~
27256 \SpecialChar ~
27257  94\SpecialChar ~
27258 \SpecialChar ~
27259 \SpecialChar ~
27260 \SpecialChar ~
27261 \SpecialChar ~
27262 \SpecialChar ~
27263 \SpecialChar ~
27264 \SpecialChar ~
27265  mov\SpecialChar ~
27266 \SpecialChar ~
27267  _foo_hob2_1_1,(_glong + 3) 
27268 \newline 
27269 \SpecialChar ~
27270 \SpecialChar ~
27271 \SpecialChar ~
27272 \SpecialChar ~
27273 \SpecialChar ~
27274 \SpecialChar ~
27275 \SpecialChar ~
27276 \SpecialChar ~
27277 \SpecialChar ~
27278 \SpecialChar ~
27279 \SpecialChar ~
27280 \SpecialChar ~
27281 \SpecialChar ~
27282 \SpecialChar ~
27283 \SpecialChar ~
27284 \SpecialChar ~
27285 \SpecialChar ~
27286 \SpecialChar ~
27287 \SpecialChar ~
27288 \SpecialChar ~
27289 \SpecialChar ~
27290 \SpecialChar ~
27291 \SpecialChar ~
27292 \SpecialChar ~
27293 \SpecialChar ~
27294  95 ;\SpecialChar ~
27295  hob.c 17 
27296 \newline 
27297 003D 85*04*08\SpecialChar ~
27298 \SpecialChar ~
27299 \SpecialChar ~
27300 \SpecialChar ~
27301 \SpecialChar ~
27302 \SpecialChar ~
27303 \SpecialChar ~
27304 \SpecialChar ~
27305 \SpecialChar ~
27306 \SpecialChar ~
27307 \SpecialChar ~
27308 \SpecialChar ~
27309  96\SpecialChar ~
27310 \SpecialChar ~
27311 \SpecialChar ~
27312 \SpecialChar ~
27313 \SpecialChar ~
27314 \SpecialChar ~
27315 \SpecialChar ~
27316 \SpecialChar ~
27317  mov\SpecialChar ~
27318 \SpecialChar ~
27319  _foo_how1_1_1,(_glong + 2) 
27320 \newline 
27321 0040 85*05*09\SpecialChar ~
27322 \SpecialChar ~
27323 \SpecialChar ~
27324 \SpecialChar ~
27325 \SpecialChar ~
27326 \SpecialChar ~
27327 \SpecialChar ~
27328 \SpecialChar ~
27329 \SpecialChar ~
27330 \SpecialChar ~
27331 \SpecialChar ~
27332 \SpecialChar ~
27333  97\SpecialChar ~
27334 \SpecialChar ~
27335 \SpecialChar ~
27336 \SpecialChar ~
27337 \SpecialChar ~
27338 \SpecialChar ~
27339 \SpecialChar ~
27340 \SpecialChar ~
27341  mov\SpecialChar ~
27342 \SpecialChar ~
27343  (_foo_how1_1_1 + 1),(_glong + 3) 
27344 \newline 
27345 0043 85*03*0A\SpecialChar ~
27346 \SpecialChar ~
27347 \SpecialChar ~
27348 \SpecialChar ~
27349 \SpecialChar ~
27350 \SpecialChar ~
27351 \SpecialChar ~
27352 \SpecialChar ~
27353 \SpecialChar ~
27354 \SpecialChar ~
27355 \SpecialChar ~
27356 \SpecialChar ~
27357  98\SpecialChar ~
27358 \SpecialChar ~
27359 \SpecialChar ~
27360 \SpecialChar ~
27361 \SpecialChar ~
27362 \SpecialChar ~
27363 \SpecialChar ~
27364 \SpecialChar ~
27365  mov\SpecialChar ~
27366 \SpecialChar ~
27367  _foo_how2_1_1,(_glong + 1) 
27368 \newline 
27369 0046 85*04*0B\SpecialChar ~
27370 \SpecialChar ~
27371 \SpecialChar ~
27372 \SpecialChar ~
27373 \SpecialChar ~
27374 \SpecialChar ~
27375 \SpecialChar ~
27376 \SpecialChar ~
27377 \SpecialChar ~
27378 \SpecialChar ~
27379 \SpecialChar ~
27380 \SpecialChar ~
27381  99\SpecialChar ~
27382 \SpecialChar ~
27383 \SpecialChar ~
27384 \SpecialChar ~
27385 \SpecialChar ~
27386 \SpecialChar ~
27387 \SpecialChar ~
27388 \SpecialChar ~
27389  mov\SpecialChar ~
27390 \SpecialChar ~
27391  (_foo_how2_1_1 + 1),(_glong + 2) 
27392 \layout Standard
27393
27394 Again, variations of these cases may 
27395 \emph on 
27396 not
27397 \emph default 
27398  be recognized.
27399  They are standard C expressions, so I heartily recommend these be the only
27400  way to get the higher order byte/word, (it is portable).
27401  Of course it will be recognized even if it is embedded in other expressions,
27402  e.g.:
27403 \layout Verse
27404
27405
27406 \family typewriter 
27407 xyz = gint + ((gint >> 8) & 0xFF);
27408 \layout Standard
27409
27410 will still be recognized.
27411 \layout Subsection
27412
27413 Peephole Optimizer
27414 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
27415
27416 \end_inset 
27417
27418
27419 \begin_inset LatexCommand \index{Peephole optimizer}
27420
27421 \end_inset 
27422
27423
27424 \layout Standard
27425
27426 The compiler uses a rule based, pattern matching and re-writing mechanism
27427  for peep-hole optimization.
27428  It is inspired by 
27429 \emph on 
27430 copt
27431 \emph default 
27432  a peep-hole optimizer by Christopher W.
27433  Fraser (cwfraser\SpecialChar ~
27434 @\SpecialChar ~
27435 microsoft.com).
27436  A default set of rules are compiled into the compiler, additional rules
27437  may be added with the 
27438 \emph on 
27439 -
27440 \begin_inset ERT
27441 status Collapsed
27442
27443 \layout Standard
27444
27445 \backslash 
27446 /
27447 \end_inset 
27448
27449 -peep-file
27450 \begin_inset LatexCommand \index{-\/-peep-file}
27451
27452 \end_inset 
27453
27454  <filename>
27455 \emph default 
27456  option.
27457  The rule language is best illustrated with examples.
27458 \layout Verse
27459
27460
27461 \family typewriter 
27462 replace { 
27463 \newline 
27464 \SpecialChar ~
27465 \SpecialChar ~
27466 mov %1,a 
27467 \newline 
27468 \SpecialChar ~
27469 \SpecialChar ~
27470 mov a,%1
27471 \newline 
27472 } by {
27473 \newline 
27474 \SpecialChar ~
27475 \SpecialChar ~
27476 mov %1,a
27477 \newline 
27478 }
27479 \layout Standard
27480
27481 The above rule will change the following assembly
27482 \begin_inset LatexCommand \index{Assembler routines}
27483
27484 \end_inset 
27485
27486  sequence:
27487 \layout Verse
27488
27489
27490 \family typewriter 
27491 mov r1,a 
27492 \newline 
27493 mov a,r1
27494 \layout Standard
27495
27496 to
27497 \layout Verse
27498
27499
27500 \family typewriter 
27501 mov r1,a
27502 \layout Standard
27503
27504 Note: All occurrences of a 
27505 \emph on 
27506 %n
27507 \emph default 
27508  (pattern variable) must denote the same string.
27509  With the above rule, the assembly sequence:
27510 \layout Verse
27511
27512
27513 \family typewriter 
27514 mov r1,a 
27515 \newline 
27516 mov a,r2
27517 \layout Standard
27518
27519 will remain unmodified.
27520 \newline 
27521
27522 \newline 
27523 Other special case optimizations may be added by the user (via 
27524 \emph on 
27525 -
27526 \begin_inset ERT
27527 status Collapsed
27528
27529 \layout Standard
27530
27531 \backslash 
27532 /
27533 \end_inset 
27534
27535 -peep-file option
27536 \emph default 
27537 ).
27538  E.g.
27539  some variants of the 8051 MCU
27540 \begin_inset LatexCommand \index{MCS51 variants}
27541
27542 \end_inset 
27543
27544  allow only 
27545 \family typewriter 
27546 ajmp
27547 \family default 
27548  and 
27549 \family typewriter 
27550 acall
27551 \family default 
27552 .
27553  The following two rules will change all 
27554 \family typewriter 
27555 ljmp
27556 \family default 
27557  and 
27558 \family typewriter 
27559 lcall
27560 \family default 
27561  to 
27562 \family typewriter 
27563 ajmp
27564 \family default 
27565  and 
27566 \family typewriter 
27567 acall
27568 \layout Verse
27569
27570
27571 \family typewriter 
27572 replace { lcall %1 } by { acall %1 } 
27573 \newline 
27574 replace { ljmp %1 } by { ajmp %1 }
27575 \layout Standard
27576
27577 The 
27578 \emph on 
27579 inline-assembler code
27580 \emph default 
27581  is also passed through the peep hole optimizer, thus the peephole optimizer
27582  can also be used as an assembly level macro expander.
27583  The rules themselves are MCU dependent whereas the rule language infra-structur
27584 e is MCU independent.
27585  Peephole optimization rules for other MCU can be easily programmed using
27586  the rule language.
27587 \newline 
27588
27589 \newline 
27590 The syntax for a rule is as follows:
27591 \layout Verse
27592
27593
27594 \family typewriter 
27595 rule := replace [ restart ] '{' <assembly sequence> '
27596 \backslash 
27597 n' 
27598 \newline 
27599 \SpecialChar ~
27600  \SpecialChar ~
27601  \SpecialChar ~
27602  \SpecialChar ~
27603  \SpecialChar ~
27604  \SpecialChar ~
27605  \SpecialChar ~
27606  \SpecialChar ~
27607  \SpecialChar ~
27608  \SpecialChar ~
27609  \SpecialChar ~
27610  \SpecialChar ~
27611  \SpecialChar ~
27612  \SpecialChar ~
27613  '}' by '{' '
27614 \backslash 
27615 n' 
27616 \newline 
27617 \SpecialChar ~
27618  \SpecialChar ~
27619  \SpecialChar ~
27620  \SpecialChar ~
27621  \SpecialChar ~
27622  \SpecialChar ~
27623  \SpecialChar ~
27624  \SpecialChar ~
27625  \SpecialChar ~
27626  \SpecialChar ~
27627  \SpecialChar ~
27628  \SpecialChar ~
27629  \SpecialChar ~
27630  \SpecialChar ~
27631  \SpecialChar ~
27632  \SpecialChar ~
27633  <assembly sequence> '
27634 \backslash 
27635 n' 
27636 \newline 
27637 \SpecialChar ~
27638  \SpecialChar ~
27639  \SpecialChar ~
27640  \SpecialChar ~
27641  \SpecialChar ~
27642  \SpecialChar ~
27643  \SpecialChar ~
27644  \SpecialChar ~
27645  \SpecialChar ~
27646  \SpecialChar ~
27647  \SpecialChar ~
27648  \SpecialChar ~
27649  \SpecialChar ~
27650  \SpecialChar ~
27651  '}' [if <functionName> ] '
27652 \backslash 
27653 n' 
27654 \layout Standard
27655
27656 <assembly sequence> := assembly instruction (each instruction including
27657  labels must be on a separate line).
27658 \newline 
27659
27660 \newline 
27661 The optimizer will apply to the rules one by one from the top in the sequence
27662  of their appearance, it will terminate when all rules are exhausted.
27663  If the 'restart' option is specified, then the optimizer will start matching
27664  the rules again from the top, this option for a rule is expensive (performance)
27665 , it is intended to be used in situations where a transformation will trigger
27666  the same rule again.
27667  An example of this (not a good one, it has side effects) is the following
27668  rule:
27669 \layout Verse
27670
27671
27672 \family typewriter 
27673 replace restart { 
27674 \newline 
27675 \SpecialChar ~
27676 \SpecialChar ~
27677 pop %1 
27678 \newline 
27679 \SpecialChar ~
27680 \SpecialChar ~
27681 push %1 } by { 
27682 \newline 
27683 \SpecialChar ~
27684 \SpecialChar ~
27685 ; nop 
27686 \newline 
27687 }
27688 \layout Standard
27689
27690 Note that the replace pattern cannot be a blank, but can be a comment line.
27691  Without the 'restart' option only the innermost 'pop' 'push' pair would
27692  be eliminated, i.e.:
27693 \layout Verse
27694
27695
27696 \family typewriter 
27697 pop ar1 
27698 \newline 
27699 pop ar2 
27700 \newline 
27701 push ar2 
27702 \newline 
27703 push ar1
27704 \layout Standard
27705
27706 would result in:
27707 \layout Verse
27708
27709
27710 \family typewriter 
27711 pop ar1 
27712 \newline 
27713 ; nop 
27714 \newline 
27715 push ar1
27716 \layout Standard
27717
27718
27719 \emph on 
27720 with
27721 \emph default 
27722  the restart option the rule will be applied again to the resulting code
27723  and then all the pop-push pairs will be eliminated to yield:
27724 \layout Verse
27725
27726
27727 \family typewriter 
27728 ; nop 
27729 \newline 
27730 ; nop
27731 \layout Standard
27732
27733 A conditional function can be attached to a rule.
27734  Attaching rules are somewhat more involved, let me illustrate this with
27735  an example.
27736 \layout Verse
27737
27738
27739 \family typewriter 
27740 replace { 
27741 \newline 
27742 \SpecialChar ~
27743  \SpecialChar ~
27744  \SpecialChar ~
27745 ljmp %5 
27746 \newline 
27747 %2:
27748 \newline 
27749 } by { 
27750 \newline 
27751 \SpecialChar ~
27752  \SpecialChar ~
27753  \SpecialChar ~
27754 sjmp %5 
27755 \newline 
27756 %2:
27757 \newline 
27758 } if labelInRange
27759 \layout Standard
27760
27761 The optimizer does a look-up of a function name table defined in function
27762  
27763 \emph on 
27764 callFuncByName
27765 \emph default 
27766  in the source file SDCCpeeph.c, with the name 
27767 \emph on 
27768 labelInRange
27769 \emph default 
27770 .
27771  If it finds a corresponding entry the function is called.
27772  Note there can be no parameters specified for these functions, in this
27773  case the use of 
27774 \emph on 
27775 %5
27776 \emph default 
27777  is crucial, since the function 
27778 \emph on 
27779 labelInRange
27780 \emph default 
27781  expects to find the label in that particular variable (the hash table containin
27782 g the variable bindings is passed as a parameter).
27783  If you want to code more such functions, take a close look at the function
27784  labelInRange and the calling mechanism in source file SDCCpeeph.c.
27785  Currently implemented are 
27786 \emph on 
27787 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
27788  24bitMode, portIsDS390, 24bitModeAndPortDS390 
27789 \emph default 
27790 and
27791 \emph on 
27792  notVolatile
27793 \emph default 
27794 .
27795 \layout Standard
27796
27797 I know this whole thing is a little kludgey, but maybe some day we will
27798  have some better means.
27799  If you are looking at this file, you will see the default rules that are
27800  compiled into the compiler, you can add your own rules in the default set
27801  there if you get tired of specifying the -
27802 \begin_inset ERT
27803 status Collapsed
27804
27805 \layout Standard
27806
27807 \backslash 
27808 /
27809 \end_inset 
27810
27811 -peep-file option.
27812 \layout Section
27813
27814 ANSI-Compliance
27815 \begin_inset LatexCommand \index{ANSI-compliance}
27816
27817 \end_inset 
27818
27819
27820 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
27821
27822 \end_inset 
27823
27824
27825 \layout Standard
27826
27827 The latest publically available version of the standard 
27828 \emph on 
27829 ISO/IEC 9899 - Programming languages - C
27830 \emph default 
27831  should be available at: 
27832 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
27833
27834 \end_inset 
27835
27836 .
27837 \newline 
27838
27839 \layout Standard
27840
27841 Deviations from the compliance:
27842 \layout Itemize
27843
27844 functions are not reentrant
27845 \begin_inset LatexCommand \index{reentrant}
27846
27847 \end_inset 
27848
27849  unless explicitly declared as such or the 
27850 \series bold 
27851 -
27852 \begin_inset ERT
27853 status Collapsed
27854
27855 \layout Standard
27856
27857 \backslash 
27858 /
27859 \end_inset 
27860
27861 -stack-auto
27862 \begin_inset LatexCommand \index{-\/-stack-auto}
27863
27864 \end_inset 
27865
27866
27867 \series default 
27868  command line option is specified.
27869 \layout Itemize
27870
27871 structures and unions cannot be assigned values directly, cannot be passed
27872  as function parameters or assigned to each other and cannot be a return
27873  value from a function, e.g.:
27874 \begin_deeper 
27875 \layout Verse
27876
27877
27878 \family typewriter 
27879 struct s { ...
27880  }; 
27881 \newline 
27882 struct s s1, s2; 
27883 \newline 
27884 foo() 
27885 \newline 
27886
27887 \newline 
27888 \SpecialChar ~
27889 \SpecialChar ~
27890 \SpecialChar ~
27891 \SpecialChar ~
27892 ...
27893  
27894 \newline 
27895 \SpecialChar ~
27896 \SpecialChar ~
27897 \SpecialChar ~
27898 \SpecialChar ~
27899 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
27900 \newline 
27901 \SpecialChar ~
27902 \SpecialChar ~
27903 \SpecialChar ~
27904 \SpecialChar ~
27905 ...
27906  
27907 \newline 
27908 }
27909 \newline 
27910 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
27911  */
27912 \newline 
27913
27914 \newline 
27915 \SpecialChar ~
27916 \SpecialChar ~
27917 \SpecialChar ~
27918 \SpecialChar ~
27919 struct s rets; 
27920 \newline 
27921 \SpecialChar ~
27922 \SpecialChar ~
27923 \SpecialChar ~
27924 \SpecialChar ~
27925 ...
27926  
27927 \newline 
27928 \SpecialChar ~
27929 \SpecialChar ~
27930 \SpecialChar ~
27931 \SpecialChar ~
27932 return rets;/* is invalid in SDCC although allowed in ANSI */ 
27933 \newline 
27934 }
27935 \end_deeper 
27936 \layout Itemize
27937
27938 initialization of structure arrays must be fully braced.
27939 \begin_deeper 
27940 \layout Verse
27941
27942
27943 \family typewriter 
27944 struct s { char x } a[] = {1, 2}; /* invalid in SDCC */
27945 \newline 
27946 struct s { char x } a[] = {{1}, {2}}; /* OK */
27947 \end_deeper 
27948 \layout Itemize
27949
27950 'long long
27951 \begin_inset LatexCommand \index{long long (not supported)}
27952
27953 \end_inset 
27954
27955 ' (64 bit integers
27956 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
27957
27958 \end_inset 
27959
27960 ) not supported.
27961 \layout Itemize
27962
27963 'double
27964 \begin_inset LatexCommand \index{double (not supported)}
27965
27966 \end_inset 
27967
27968 ' precision floating point 
27969 \begin_inset LatexCommand \index{Floating point support}
27970
27971 \end_inset 
27972
27973 not supported.
27974 \layout Itemize
27975
27976 Old K&R style
27977 \begin_inset LatexCommand \index{K\&R style}
27978
27979 \end_inset 
27980
27981  function declarations are NOT allowed.
27982 \begin_deeper 
27983 \layout Verse
27984
27985
27986 \family typewriter 
27987 foo(i,j) /* this old style of function declarations */ 
27988 \newline 
27989 int i,j; /* are valid in ANSI but not valid in SDCC */ 
27990 \newline 
27991
27992 \newline 
27993 \SpecialChar ~
27994 \SpecialChar ~
27995 \SpecialChar ~
27996 \SpecialChar ~
27997 ...
27998  
27999 \newline 
28000 }
28001 \end_deeper 
28002 \layout Itemize
28003
28004 Most enhancements in C99 are not supported, f.e.:
28005 \begin_deeper 
28006 \layout Verse
28007
28008
28009 \family typewriter 
28010 \series bold 
28011 inline
28012 \series default 
28013  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
28014  in C99 */
28015 \newline 
28016 for (
28017 \series bold 
28018 int
28019 \series default 
28020  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
28021 \end_deeper 
28022 \layout Itemize
28023
28024 Certain words that are valid identifiers in the standard may be reserved
28025  words in SDCC unless the 
28026 \series bold 
28027 -
28028 \begin_inset ERT
28029 status Collapsed
28030
28031 \layout Standard
28032
28033 \backslash 
28034 /
28035 \end_inset 
28036
28037 -std-c89
28038 \begin_inset LatexCommand \index{-\/-std-c89}
28039
28040 \end_inset 
28041
28042  or -
28043 \begin_inset ERT
28044 status Collapsed
28045
28046 \layout Standard
28047
28048 \backslash 
28049 /
28050 \end_inset 
28051
28052 -std-c99
28053 \begin_inset LatexCommand \index{-\/-std-c99}
28054
28055 \end_inset 
28056
28057
28058 \series default 
28059  command line options are used.
28060  These may include (depending on the selected processor): 'at', 'banked',
28061  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
28062 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
28063  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
28064  '_naked'.
28065  Compliant equivalents of these keywords are always available in a form
28066  that begin with two underscores
28067 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
28068
28069 \end_inset 
28070
28071 , f.e.
28072  '__data' instead of 'data'.
28073 \layout Section
28074
28075 Cyclomatic Complexity
28076 \begin_inset LatexCommand \index{Cyclomatic complexity}
28077
28078 \end_inset 
28079
28080
28081 \layout Standard
28082
28083 Cyclomatic complexity of a function is defined as the number of independent
28084  paths the program can take during execution of the function.
28085  This is an important number since it defines the number test cases you
28086  have to generate to validate the function.
28087  The accepted industry standard for complexity number is 10, if the cyclomatic
28088  complexity reported by SDCC exceeds 10 you should think about simplification
28089  of the function logic.
28090  Note that the complexity level is not related to the number of lines of
28091  code in a function.
28092  Large functions can have low complexity, and small functions can have large
28093  complexity levels.
28094  
28095 \newline 
28096
28097 \newline 
28098 SDCC uses the following formula to compute the complexity:
28099 \newline 
28100
28101 \layout Standard
28102
28103 complexity = (number of edges in control flow graph) - (number of nodes
28104  in control flow graph) + 2;
28105 \newline 
28106
28107 \newline 
28108 Having said that the industry standard is 10, you should be aware that in
28109  some cases it be may unavoidable to have a complexity level of less than
28110  10.
28111  For example if you have switch statement with more than 10 case labels,
28112  each case label adds one to the complexity level.
28113  The complexity level is by no means an absolute measure of the algorithmic
28114  complexity of the function, it does however provide a good starting point
28115  for which functions you might look at for further optimization.
28116 \layout Section
28117
28118 Retargetting for other Processors
28119 \layout Standard
28120
28121 The issues for retargetting the compiler are far too numerous to be covered
28122  by this document.
28123  What follows is a brief description of each of the seven phases of the
28124  compiler and its MCU dependency.
28125 \layout Itemize
28126
28127 Parsing the source and building the annotated parse tree.
28128  This phase is largely MCU independent (except for the language extensions).
28129  Syntax & semantic checks are also done in this phase, along with some initial
28130  optimizations like back patching labels and the pattern matching optimizations
28131  like bit-rotation etc.
28132 \layout Itemize
28133
28134 The second phase involves generating an intermediate code which can be easy
28135  manipulated during the later phases.
28136  This phase is entirely MCU independent.
28137  The intermediate code generation assumes the target machine has unlimited
28138  number of registers, and designates them with the name iTemp.
28139  The compiler can be made to dump a human readable form of the code generated
28140  by using the -
28141 \begin_inset ERT
28142 status Collapsed
28143
28144 \layout Standard
28145
28146 \backslash 
28147 /
28148 \end_inset 
28149
28150 -dumpraw option.
28151 \layout Itemize
28152
28153 This phase does the bulk of the standard optimizations and is also MCU independe
28154 nt.
28155  This phase can be broken down into several sub-phases:
28156 \newline 
28157
28158 \newline 
28159 Break down intermediate code (iCode) into basic blocks.
28160 \newline 
28161 Do control flow & data flow analysis on the basic blocks.
28162 \newline 
28163 Do local common subexpression elimination, then global subexpression elimination
28164 \newline 
28165 Dead code elimination
28166 \newline 
28167 Loop optimizations
28168 \newline 
28169 If loop optimizations caused any changes then do 'global subexpression eliminati
28170 on' and 'dead code elimination' again.
28171 \layout Itemize
28172
28173 This phase determines the live-ranges; by live range I mean those iTemp
28174  variables defined by the compiler that still survive after all the optimization
28175 s.
28176  Live range analysis
28177 \begin_inset LatexCommand \index{Live range analysis}
28178
28179 \end_inset 
28180
28181  is essential for register allocation, since these computation determines
28182  which of these iTemps will be assigned to registers, and for how long.
28183 \layout Itemize
28184
28185 Phase five is register allocation.
28186  There are two parts to this process.
28187 \newline 
28188
28189 \newline 
28190 The first part I call 'register packing' (for lack of a better term).
28191  In this case several MCU specific expression folding is done to reduce
28192  register pressure.
28193 \newline 
28194
28195 \newline 
28196 The second part is more MCU independent and deals with allocating registers
28197  to the remaining live ranges.
28198  A lot of MCU specific code does creep into this phase because of the limited
28199  number of index registers available in the 8051.
28200 \layout Itemize
28201
28202 The Code generation phase is (unhappily), entirely MCU dependent and very
28203  little (if any at all) of this code can be reused for other MCU.
28204  However the scheme for allocating a homogenized assembler operand for each
28205  iCode operand may be reused.
28206 \layout Itemize
28207
28208 As mentioned in the optimization section the peep-hole optimizer is rule
28209  based system, which can reprogrammed for other MCUs.
28210 \layout Chapter
28211
28212 Compiler internals
28213 \begin_inset LatexCommand \index{Compiler internals}
28214
28215 \end_inset 
28216
28217
28218 \layout Section
28219
28220 The anatomy of the compiler
28221 \begin_inset LatexCommand \label{sub:The-anatomy-of}
28222
28223 \end_inset 
28224
28225
28226 \layout Standard
28227
28228
28229 \shape italic 
28230 This is an excerpt from an article published in Circuit Cellar Magazine
28231  in 
28232 \series bold 
28233 August 2000
28234 \series default 
28235 .
28236  It's a little outdated (the compiler is much more efficient now and user/develo
28237 per friendly), but pretty well exposes the guts of it all.
28238 \shape default 
28239
28240 \newline 
28241
28242 \newline 
28243 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
28244  It is fairly easy to retarget for other 8-bit MCU.
28245  Here we take a look at some of the internals of the compiler.
28246  
28247 \layout Paragraph*
28248
28249 Parsing
28250 \begin_inset LatexCommand \index{Parsing}
28251
28252 \end_inset 
28253
28254  
28255 \layout Standard
28256
28257 Parsing the input source file and creating an AST (Annotated Syntax Tree
28258 \begin_inset LatexCommand \index{Annotated syntax tree}
28259
28260 \end_inset 
28261
28262 ).
28263  This phase also involves propagating types (annotating each node of the
28264  parse tree with type information) and semantic analysis.
28265  There are some MCU specific parsing rules.
28266  For example the storage classes, the extended storage classes are MCU specific
28267  while there may be a xdata storage class for 8051 there is no such storage
28268  class for z80 or Atmel AVR.
28269  SDCC allows MCU specific storage class extensions, i.e.
28270  xdata will be treated as a storage class specifier when parsing 8051 C
28271  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
28272  C code.
28273 \layout Paragraph*
28274
28275 Generating iCode
28276 \begin_inset LatexCommand \index{iCode}
28277
28278 \end_inset 
28279
28280
28281 \layout Standard
28282
28283 Intermediate code generation.
28284  In this phase the AST is broken down into three-operand form (iCode).
28285  These three operand forms are represented as doubly linked lists.
28286  ICode is the term given to the intermediate form generated by the compiler.
28287  ICode example section shows some examples of iCode generated for some simple
28288  C source functions.
28289 \layout Paragraph*
28290
28291 Optimizations
28292 \begin_inset LatexCommand \index{Optimizations}
28293
28294 \end_inset 
28295
28296 .
28297 \layout Standard
28298
28299 Bulk of the target independent optimizations is performed in this phase.
28300  The optimizations include constant propagation, common sub-expression eliminati
28301 on, loop invariant code movement, strength reduction of loop induction variables
28302  and dead-code elimination.
28303 \layout Paragraph*
28304
28305 Live range analysis
28306 \begin_inset LatexCommand \index{Live range analysis}
28307
28308 \end_inset 
28309
28310
28311 \layout Standard
28312
28313 During intermediate code generation phase, the compiler assumes the target
28314  machine has infinite number of registers and generates a lot of temporary
28315  variables.
28316  The live range computation determines the lifetime of each of these compiler-ge
28317 nerated temporaries.
28318  A picture speaks a thousand words.
28319  ICode example sections show the live range annotations for each of the
28320  operand.
28321  It is important to note here, each iCode is assigned a number in the order
28322  of its execution in the function.
28323  The live ranges are computed in terms of these numbers.
28324  The from number is the number of the iCode which first defines the operand
28325  and the to number signifies the iCode which uses this operand last.
28326 \layout Paragraph*
28327
28328 Register Allocation
28329 \begin_inset LatexCommand \index{Register allocation}
28330
28331 \end_inset 
28332
28333
28334 \layout Standard
28335
28336 The register allocation determines the type and number of registers needed
28337  by each operand.
28338  In most MCUs only a few registers can be used for indirect addressing.
28339  In case of 8051 for example the registers R0 & R1 can be used to indirectly
28340  address the internal ram and DPTR to indirectly address the external ram.
28341  The compiler will try to allocate the appropriate register to pointer variables
28342  if it can.
28343  ICode example section shows the operands annotated with the registers assigned
28344  to them.
28345  The compiler will try to keep operands in registers as much as possible;
28346  there are several schemes the compiler uses to do achieve this.
28347  When the compiler runs out of registers the compiler will check to see
28348  if there are any live operands which is not used or defined in the current
28349  basic block being processed, if there are any found then it will push that
28350  operand and use the registers in this block, the operand will then be popped
28351  at the end of the basic block.
28352  
28353 \layout Standard
28354
28355 There are other MCU specific considerations in this phase.
28356  Some MCUs have an accumulator; very short-lived operands could be assigned
28357  to the accumulator instead of a general-purpose register.
28358 \layout Paragraph*
28359
28360 Code generation
28361 \layout Standard
28362
28363 Figure II gives a table of iCode operations supported by the compiler.
28364  The code generation involves translating these operations into corresponding
28365  assembly code for the processor.
28366  This sounds overly simple but that is the essence of code generation.
28367  Some of the iCode operations are generated on a MCU specific manner for
28368  example, the z80 port does not use registers to pass parameters so the
28369  SEND and RECV iCode operations will not be generated, and it also does
28370  not support JUMPTABLES.
28371  
28372 \newline 
28373
28374 \series bold 
28375 \shape italic 
28376 \color red
28377 <Where is Figure II?>
28378 \layout Comment
28379
28380 In the original article Figure II was announced to be downloadable on 
28381 \shape italic 
28382 Circuit Cellar
28383 \shape default 
28384 's web site.
28385  Unfortunately it never seemed to have shown up there, so: where is Figure
28386  II?
28387 \layout Paragraph*
28388
28389 ICode Example
28390 \begin_inset LatexCommand \index{iCode}
28391
28392 \end_inset 
28393
28394
28395 \layout Standard
28396
28397 This section shows some details of iCode.
28398  The example C code does not do anything useful; it is used as an example
28399  to illustrate the intermediate code generated by the compiler.
28400 \layout Verse
28401
28402
28403 \family typewriter 
28404 1.\SpecialChar ~
28405 xdata int * p;
28406 \newline 
28407 2.\SpecialChar ~
28408 int gint;
28409 \newline 
28410 3.\SpecialChar ~
28411 /* This function does nothing useful.
28412  It is used
28413 \newline 
28414 4.\SpecialChar ~
28415 \SpecialChar ~
28416 \SpecialChar ~
28417 \SpecialChar ~
28418 for the purpose of explaining iCode */
28419 \newline 
28420 5.\SpecialChar ~
28421 short function (data int *x)
28422 \newline 
28423 6.\SpecialChar ~
28424 {
28425 \newline 
28426 7.\SpecialChar ~
28427 \SpecialChar ~
28428 \SpecialChar ~
28429 short i=10; \SpecialChar ~
28430 \SpecialChar ~
28431 /* dead initialization eliminated */
28432 \newline 
28433 8.\SpecialChar ~
28434 \SpecialChar ~
28435 \SpecialChar ~
28436 short sum=10; /* dead initialization eliminated */
28437 \newline 
28438 9.\SpecialChar ~
28439 \SpecialChar ~
28440 \SpecialChar ~
28441 short mul;
28442 \newline 
28443 10.\SpecialChar ~
28444 \SpecialChar ~
28445 int j ;
28446 \newline 
28447 11.\SpecialChar ~
28448 \SpecialChar ~
28449 while (*x) *x++ = *p++; 
28450 \newline 
28451 12.\SpecialChar ~
28452 \SpecialChar ~
28453 \SpecialChar ~
28454 \SpecialChar ~
28455 sum = 0 ; 
28456 \newline 
28457 13.\SpecialChar ~
28458 \SpecialChar ~
28459 mul = 0;
28460 \newline 
28461 14.\SpecialChar ~
28462 \SpecialChar ~
28463 /* compiler detects i,j to be induction variables */
28464 \newline 
28465 15.\SpecialChar ~
28466 \SpecialChar ~
28467 for (i = 0, j = 10 ; i < 10 ; i++, j
28468 \family default 
28469 -
28470 \begin_inset ERT
28471 status Collapsed
28472
28473 \layout Standard
28474
28475 \backslash 
28476 /
28477 \end_inset 
28478
28479 -
28480 \family typewriter 
28481 ) {
28482 \newline 
28483 16.\SpecialChar ~
28484 \SpecialChar ~
28485 \SpecialChar ~
28486 \SpecialChar ~
28487 sum += i;
28488 \newline 
28489 17.\SpecialChar ~
28490 \SpecialChar ~
28491 \SpecialChar ~
28492 \SpecialChar ~
28493 mul += i * 3; \SpecialChar ~
28494 \SpecialChar ~
28495 /* this multiplication remains */
28496 \newline 
28497 18.\SpecialChar ~
28498 \SpecialChar ~
28499 \SpecialChar ~
28500 \SpecialChar ~
28501 gint += j * 3;\SpecialChar ~
28502 \SpecialChar ~
28503 /* this multiplication changed to addition */
28504 \newline 
28505 19.\SpecialChar ~
28506 \SpecialChar ~
28507 }
28508 \newline 
28509 20.\SpecialChar ~
28510 \SpecialChar ~
28511 return sum+mul;
28512 \newline 
28513 21.\SpecialChar ~
28514 }
28515 \layout Standard
28516
28517 In addition to the operands each iCode contains information about the filename
28518  and line it corresponds to in the source file.
28519  The first field in the listing should be interpreted as follows:
28520 \newline 
28521
28522 \shape italic 
28523 \size footnotesize 
28524 Filename(linenumber: iCode Execution sequence number : ICode hash table
28525  key : loop depth of the iCode).
28526 \shape default 
28527 \size default 
28528
28529 \newline 
28530 Then follows the human readable form of the ICode operation.
28531  Each operand of this triplet form can be of three basic types a) compiler
28532  generated temporary b) user defined variable c) a constant value.
28533  Note that local variables and parameters are replaced by compiler generated
28534  temporaries.
28535  Live ranges
28536 \begin_inset LatexCommand \index{Live range analysis}
28537
28538 \end_inset 
28539
28540  are computed only for temporaries (i.e.
28541  live ranges are not computed for global variables).
28542  Registers
28543 \begin_inset LatexCommand \index{Register allocation}
28544
28545 \end_inset 
28546
28547  are allocated for temporaries only.
28548  Operands are formatted in the following manner:
28549 \newline 
28550
28551 \shape italic 
28552 \size footnotesize 
28553 Operand Name [lr live-from : live-to ] { type information } [ registers
28554  allocated ].
28555 \shape default 
28556 \size default 
28557
28558 \newline 
28559 As mentioned earlier the live ranges are computed in terms of the execution
28560  sequence number of the iCodes, for example 
28561 \newline 
28562 the iTemp0 is live from (i.e.
28563  first defined in iCode with execution sequence number 3, and is last used
28564  in the iCode with sequence number 5).
28565  For induction variables such as iTemp21 the live range computation extends
28566  the lifetime from the start to the end of the loop.
28567 \newline 
28568 The register allocator used the live range information to allocate registers,
28569  the same registers may be used for different temporaries if their live
28570  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
28571  iTemp17 since their live ranges do not overlap.
28572  In addition the allocator also takes into consideration the type and usage
28573  of a temporary, for example itemp6 is a pointer to near space and is used
28574  as to fetch data from (i.e.
28575  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
28576  Some short lived temporaries are allocated to special registers which have
28577  meaning to the code generator e.g.
28578  iTemp13 is allocated to a pseudo register CC which tells the back end that
28579  the temporary is used only for a conditional jump the code generation makes
28580  use of this information to optimize a compare and jump ICode.
28581 \newline 
28582 There are several loop optimizations
28583 \begin_inset LatexCommand \index{Loop optimization}
28584
28585 \end_inset 
28586
28587  performed by the compiler.
28588  It can detect induction variables iTemp21(i) and iTemp23(j).
28589  Also note the compiler does selective strength reduction
28590 \begin_inset LatexCommand \index{Strength reduction}
28591
28592 \end_inset 
28593
28594 , i.e.
28595  the multiplication of an induction variable in line 18 (gint = j * 3) is
28596  changed to addition, a new temporary iTemp17 is allocated and assigned
28597  a initial value, a constant 3 is then added for each iteration of the loop.
28598  The compiler does not change the multiplication
28599 \begin_inset LatexCommand \index{Multiplication}
28600
28601 \end_inset 
28602
28603  in line 17 however since the processor does support an 8 * 8 bit multiplication.
28604 \newline 
28605 Note the dead code elimination
28606 \begin_inset LatexCommand \index{Dead-code elimination}
28607
28608 \end_inset 
28609
28610  optimization eliminated the dead assignments in line 7 & 8 to I and sum
28611  respectively.
28612 \newline 
28613
28614 \layout Standard
28615
28616
28617 \size footnotesize 
28618 Sample.c (5:1:0:0) _entry($9) :
28619 \layout Standard
28620
28621
28622 \size footnotesize 
28623 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
28624 \layout Standard
28625
28626
28627 \size footnotesize 
28628 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
28629 \layout Standard
28630
28631
28632 \size footnotesize 
28633 Sample.c(11:4:53:0) preHeaderLbl0($11) :
28634 \layout Standard
28635
28636
28637 \size footnotesize 
28638 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
28639  * int}[r2]
28640 \layout Standard
28641
28642
28643 \size footnotesize 
28644 Sample.c(11:6:5:1) _whilecontinue_0($1) :
28645 \layout Standard
28646
28647
28648 \size footnotesize 
28649 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
28650  int}[r0]]
28651 \layout Standard
28652
28653
28654 \size footnotesize 
28655 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
28656 \layout Standard
28657
28658
28659 \size footnotesize 
28660 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
28661  * int}
28662 \layout Standard
28663
28664
28665 \size footnotesize 
28666 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
28667  {short}
28668 \layout Standard
28669
28670
28671 \size footnotesize 
28672 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
28673  * int}[DPTR]]
28674 \layout Standard
28675
28676
28677 \size footnotesize 
28678 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
28679 }[r2 r3]
28680 \layout Standard
28681
28682
28683 \size footnotesize 
28684 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
28685  * int}[r0] + 0x2 {short}
28686 \layout Standard
28687
28688
28689 \size footnotesize 
28690 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
28691 \layout Standard
28692
28693
28694 \size footnotesize 
28695 Sample.c(11:17:21:0)_whilebreak_0($3) :
28696 \layout Standard
28697
28698
28699 \size footnotesize 
28700 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
28701 \layout Standard
28702
28703
28704 \size footnotesize 
28705 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
28706 \layout Standard
28707
28708
28709 \size footnotesize 
28710 Sample.c(15:20:54:0)preHeaderLbl1($13) :
28711 \layout Standard
28712
28713
28714 \size footnotesize 
28715 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
28716 \layout Standard
28717
28718
28719 \size footnotesize 
28720 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
28721 \layout Standard
28722
28723
28724 \size footnotesize 
28725 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
28726 \layout Standard
28727
28728
28729 \size footnotesize 
28730 Sample.c(15:24:26:1)_forcond_0($4) :
28731 \layout Standard
28732
28733
28734 \size footnotesize 
28735 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
28736  < 0xa {short}
28737 \layout Standard
28738
28739
28740 \size footnotesize 
28741 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
28742 \layout Standard
28743
28744
28745 \size footnotesize 
28746 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
28747  + ITemp21 [lr21:38]{short}[r4]
28748 \layout Standard
28749
28750
28751 \size footnotesize 
28752 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
28753  * 0x3 {short}
28754 \layout Standard
28755
28756
28757 \size footnotesize 
28758 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
28759  + iTemp15 [lr29:30]{short}[r1]
28760 \layout Standard
28761
28762
28763 \size footnotesize 
28764 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
28765  r0]- 0x3 {short}
28766 \layout Standard
28767
28768
28769 \size footnotesize 
28770 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
28771 int}[r7 r0]
28772 \layout Standard
28773
28774
28775 \size footnotesize 
28776 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
28777  + 0x1 {short}
28778 \layout Standard
28779
28780
28781 \size footnotesize 
28782 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
28783  r6]- 0x1 {short}
28784 \layout Standard
28785
28786
28787 \size footnotesize 
28788 Sample.c(19:38:47:1) goto _forcond_0($4)
28789 \layout Standard
28790
28791
28792 \size footnotesize 
28793 Sample.c(19:39:48:0)_forbreak_0($7) :
28794 \layout Standard
28795
28796
28797 \size footnotesize 
28798 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
28799  + ITemp11 [lr19:40]{short}[r3]
28800 \layout Standard
28801
28802
28803 \size footnotesize 
28804 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
28805 \layout Standard
28806
28807
28808 \size footnotesize 
28809 Sample.c(20:42:51:0)_return($8) :
28810 \layout Standard
28811
28812
28813 \size footnotesize 
28814 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
28815 \size default 
28816
28817 \newline 
28818
28819 \newline 
28820 Finally the code generated for this function:
28821 \newline 
28822
28823 \layout Standard
28824
28825
28826 \size footnotesize 
28827 .area DSEG (DATA)
28828 \layout Standard
28829
28830
28831 \size footnotesize 
28832 _p::
28833 \layout Standard
28834
28835
28836 \size footnotesize 
28837 \SpecialChar ~
28838 \SpecialChar ~
28839 .ds 2
28840 \layout Standard
28841
28842
28843 \size footnotesize 
28844 _gint::
28845 \layout Standard
28846
28847
28848 \size footnotesize 
28849 \SpecialChar ~
28850 \SpecialChar ~
28851 .ds 2
28852 \layout Standard
28853
28854
28855 \size footnotesize 
28856 ; sample.c 5
28857 \layout Standard
28858
28859
28860 \size footnotesize 
28861 ; ----------------------------------------------
28862 \layout Standard
28863
28864
28865 \size footnotesize 
28866 ; function function
28867 \layout Standard
28868
28869
28870 \size footnotesize 
28871 ; ----------------------------------------------
28872 \layout Standard
28873
28874
28875 \size footnotesize 
28876 _function:
28877 \layout Standard
28878
28879
28880 \size footnotesize 
28881 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
28882 \layout Standard
28883
28884
28885 \size footnotesize 
28886 \SpecialChar ~
28887 \SpecialChar ~
28888 mov r2,dpl
28889 \layout Standard
28890
28891
28892 \size footnotesize 
28893 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
28894 \layout Standard
28895
28896
28897 \size footnotesize 
28898 \SpecialChar ~
28899 \SpecialChar ~
28900 mov ar0,r2
28901 \layout Standard
28902
28903
28904 \size footnotesize 
28905 ;_whilecontinue_0($1) :
28906 \layout Standard
28907
28908
28909 \size footnotesize 
28910 00101$:
28911 \layout Standard
28912
28913
28914 \size footnotesize 
28915 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
28916 \layout Standard
28917
28918
28919 \size footnotesize 
28920 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
28921 \layout Standard
28922
28923
28924 \size footnotesize 
28925 \SpecialChar ~
28926 \SpecialChar ~
28927 mov ar2,@r0
28928 \layout Standard
28929
28930
28931 \size footnotesize 
28932 \SpecialChar ~
28933 \SpecialChar ~
28934 inc r0
28935 \layout Standard
28936
28937
28938 \size footnotesize 
28939 \SpecialChar ~
28940 \SpecialChar ~
28941 mov ar3,@r0
28942 \layout Standard
28943
28944
28945 \size footnotesize 
28946 \SpecialChar ~
28947 \SpecialChar ~
28948 dec r0
28949 \layout Standard
28950
28951
28952 \size footnotesize 
28953 \SpecialChar ~
28954 \SpecialChar ~
28955 mov a,r2
28956 \layout Standard
28957
28958
28959 \size footnotesize 
28960 \SpecialChar ~
28961 \SpecialChar ~
28962 orl a,r3
28963 \layout Standard
28964
28965
28966 \size footnotesize 
28967 \SpecialChar ~
28968 \SpecialChar ~
28969 jz 00103$
28970 \layout Standard
28971
28972
28973 \size footnotesize 
28974 00114$:
28975 \layout Standard
28976
28977
28978 \size footnotesize 
28979 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
28980 \layout Standard
28981
28982
28983 \size footnotesize 
28984 \SpecialChar ~
28985 \SpecialChar ~
28986 mov dpl,_p
28987 \layout Standard
28988
28989
28990 \size footnotesize 
28991 \SpecialChar ~
28992 \SpecialChar ~
28993 mov dph,(_p + 1)
28994 \layout Standard
28995
28996
28997 \size footnotesize 
28998 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
28999 \layout Standard
29000
29001
29002 \size footnotesize 
29003 \SpecialChar ~
29004 \SpecialChar ~
29005 mov a,#0x02
29006 \layout Standard
29007
29008
29009 \size footnotesize 
29010 \SpecialChar ~
29011 \SpecialChar ~
29012 add a,_p
29013 \layout Standard
29014
29015
29016 \size footnotesize 
29017 \SpecialChar ~
29018 \SpecialChar ~
29019 mov _p,a
29020 \layout Standard
29021
29022
29023 \size footnotesize 
29024 \SpecialChar ~
29025 \SpecialChar ~
29026 clr a
29027 \layout Standard
29028
29029
29030 \size footnotesize 
29031 \SpecialChar ~
29032 \SpecialChar ~
29033 addc a,(_p + 1)
29034 \layout Standard
29035
29036
29037 \size footnotesize 
29038 \SpecialChar ~
29039 \SpecialChar ~
29040 mov (_p + 1),a
29041 \layout Standard
29042
29043
29044 \size footnotesize 
29045 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
29046 \layout Standard
29047
29048
29049 \size footnotesize 
29050 \SpecialChar ~
29051 \SpecialChar ~
29052 movx a,@dptr
29053 \layout Standard
29054
29055
29056 \size footnotesize 
29057 \SpecialChar ~
29058 \SpecialChar ~
29059 mov r2,a
29060 \layout Standard
29061
29062
29063 \size footnotesize 
29064 \SpecialChar ~
29065 \SpecialChar ~
29066 inc dptr
29067 \layout Standard
29068
29069
29070 \size footnotesize 
29071 \SpecialChar ~
29072 \SpecialChar ~
29073 movx a,@dptr
29074 \layout Standard
29075
29076
29077 \size footnotesize 
29078 \SpecialChar ~
29079 \SpecialChar ~
29080 mov r3,a
29081 \layout Standard
29082
29083
29084 \size footnotesize 
29085 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
29086 \layout Standard
29087
29088
29089 \size footnotesize 
29090 \SpecialChar ~
29091 \SpecialChar ~
29092 mov @r0,ar2
29093 \layout Standard
29094
29095
29096 \size footnotesize 
29097 \SpecialChar ~
29098 \SpecialChar ~
29099 inc r0
29100 \layout Standard
29101
29102
29103 \size footnotesize 
29104 \SpecialChar ~
29105 \SpecialChar ~
29106 mov @r0,ar3
29107 \layout Standard
29108
29109
29110 \size footnotesize 
29111 ; iTemp6 [lr5:16]{_near * int}[r0] = 
29112 \layout Standard
29113
29114
29115 \size footnotesize 
29116 ; iTemp6 [lr5:16]{_near * int}[r0] + 
29117 \layout Standard
29118
29119
29120 \size footnotesize 
29121 ; 0x2 {short}
29122 \layout Standard
29123
29124
29125 \size footnotesize 
29126 \SpecialChar ~
29127 \SpecialChar ~
29128 inc r0
29129 \layout Standard
29130
29131
29132 \size footnotesize 
29133 ; goto _whilecontinue_0($1)
29134 \layout Standard
29135
29136
29137 \size footnotesize 
29138 \SpecialChar ~
29139 \SpecialChar ~
29140 sjmp 00101$
29141 \layout Standard
29142
29143
29144 \size footnotesize 
29145 ; _whilebreak_0($3) :
29146 \layout Standard
29147
29148
29149 \size footnotesize 
29150 00103$:
29151 \layout Standard
29152
29153
29154 \size footnotesize 
29155 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
29156 \layout Standard
29157
29158
29159 \size footnotesize 
29160 \SpecialChar ~
29161 \SpecialChar ~
29162 mov r2,#0x00
29163 \layout Standard
29164
29165
29166 \size footnotesize 
29167 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
29168 \layout Standard
29169
29170
29171 \size footnotesize 
29172 \SpecialChar ~
29173 \SpecialChar ~
29174 mov r3,#0x00
29175 \layout Standard
29176
29177
29178 \size footnotesize 
29179 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
29180 \layout Standard
29181
29182
29183 \size footnotesize 
29184 \SpecialChar ~
29185 \SpecialChar ~
29186 mov r4,#0x00
29187 \layout Standard
29188
29189
29190 \size footnotesize 
29191 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
29192 \layout Standard
29193
29194
29195 \size footnotesize 
29196 \SpecialChar ~
29197 \SpecialChar ~
29198 mov r5,#0x0A
29199 \layout Standard
29200
29201
29202 \size footnotesize 
29203 \SpecialChar ~
29204 \SpecialChar ~
29205 mov r6,#0x00
29206 \layout Standard
29207
29208
29209 \size footnotesize 
29210 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
29211 \layout Standard
29212
29213
29214 \size footnotesize 
29215 \SpecialChar ~
29216 \SpecialChar ~
29217 mov r7,#0x1E
29218 \layout Standard
29219
29220
29221 \size footnotesize 
29222 \SpecialChar ~
29223 \SpecialChar ~
29224 mov r0,#0x00
29225 \layout Standard
29226
29227
29228 \size footnotesize 
29229 ; _forcond_0($4) :
29230 \layout Standard
29231
29232
29233 \size footnotesize 
29234 00104$:
29235 \layout Standard
29236
29237
29238 \size footnotesize 
29239 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
29240 \layout Standard
29241
29242
29243 \size footnotesize 
29244 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
29245 \layout Standard
29246
29247
29248 \size footnotesize 
29249 \SpecialChar ~
29250 \SpecialChar ~
29251 clr c
29252 \layout Standard
29253
29254
29255 \size footnotesize 
29256 \SpecialChar ~
29257 \SpecialChar ~
29258 mov a,r4
29259 \layout Standard
29260
29261
29262 \size footnotesize 
29263 \SpecialChar ~
29264 \SpecialChar ~
29265 xrl a,#0x80
29266 \layout Standard
29267
29268
29269 \size footnotesize 
29270 \SpecialChar ~
29271 \SpecialChar ~
29272 subb a,#0x8a
29273 \layout Standard
29274
29275
29276 \size footnotesize 
29277 \SpecialChar ~
29278 \SpecialChar ~
29279 jnc 00107$
29280 \layout Standard
29281
29282
29283 \size footnotesize 
29284 00115$:
29285 \layout Standard
29286
29287
29288 \size footnotesize 
29289 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
29290 \layout Standard
29291
29292
29293 \size footnotesize 
29294 ; iTemp21 [lr21:38]{short}[r4]
29295 \layout Standard
29296
29297
29298 \size footnotesize 
29299 \SpecialChar ~
29300 \SpecialChar ~
29301 mov a,r4
29302 \layout Standard
29303
29304
29305 \size footnotesize 
29306 \SpecialChar ~
29307 \SpecialChar ~
29308 add a,r2
29309 \layout Standard
29310
29311
29312 \size footnotesize 
29313 \SpecialChar ~
29314 \SpecialChar ~
29315 mov r2,a
29316 \layout Standard
29317
29318
29319 \size footnotesize 
29320 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
29321 \layout Standard
29322
29323
29324 \size footnotesize 
29325 \SpecialChar ~
29326 \SpecialChar ~
29327 mov b,#0x03
29328 \layout Standard
29329
29330
29331 \size footnotesize 
29332 \SpecialChar ~
29333 \SpecialChar ~
29334 mov a,r4
29335 \layout Standard
29336
29337
29338 \size footnotesize 
29339 \SpecialChar ~
29340 \SpecialChar ~
29341 mul ab
29342 \layout Standard
29343
29344
29345 \size footnotesize 
29346 \SpecialChar ~
29347 \SpecialChar ~
29348 mov r1,a
29349 \layout Standard
29350
29351
29352 \size footnotesize 
29353 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
29354 \layout Standard
29355
29356
29357 \size footnotesize 
29358 ; iTemp15 [lr29:30]{short}[r1]
29359 \layout Standard
29360
29361
29362 \size footnotesize 
29363 \SpecialChar ~
29364 \SpecialChar ~
29365 add a,r3
29366 \layout Standard
29367
29368
29369 \size footnotesize 
29370 \SpecialChar ~
29371 \SpecialChar ~
29372 mov r3,a
29373 \layout Standard
29374
29375
29376 \size footnotesize 
29377 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
29378 \layout Standard
29379
29380
29381 \size footnotesize 
29382 \SpecialChar ~
29383 \SpecialChar ~
29384 mov a,r7
29385 \layout Standard
29386
29387
29388 \size footnotesize 
29389 \SpecialChar ~
29390 \SpecialChar ~
29391 add a,#0xfd
29392 \layout Standard
29393
29394
29395 \size footnotesize 
29396 \SpecialChar ~
29397 \SpecialChar ~
29398 mov r7,a
29399 \layout Standard
29400
29401
29402 \size footnotesize 
29403 \SpecialChar ~
29404 \SpecialChar ~
29405 mov a,r0
29406 \layout Standard
29407
29408
29409 \size footnotesize 
29410 \SpecialChar ~
29411 \SpecialChar ~
29412 addc a,#0xff
29413 \layout Standard
29414
29415
29416 \size footnotesize 
29417 \SpecialChar ~
29418 \SpecialChar ~
29419 mov r0,a
29420 \layout Standard
29421
29422
29423 \size footnotesize 
29424 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
29425 \layout Standard
29426
29427
29428 \size footnotesize 
29429 \SpecialChar ~
29430 \SpecialChar ~
29431 mov a,r7
29432 \layout Standard
29433
29434
29435 \size footnotesize 
29436 \SpecialChar ~
29437 \SpecialChar ~
29438 add a,_gint
29439 \layout Standard
29440
29441
29442 \size footnotesize 
29443 \SpecialChar ~
29444 \SpecialChar ~
29445 mov _gint,a
29446 \layout Standard
29447
29448
29449 \size footnotesize 
29450 \SpecialChar ~
29451 \SpecialChar ~
29452 mov a,r0
29453 \layout Standard
29454
29455
29456 \size footnotesize 
29457 \SpecialChar ~
29458 \SpecialChar ~
29459 addc a,(_gint + 1)
29460 \layout Standard
29461
29462
29463 \size footnotesize 
29464 \SpecialChar ~
29465 \SpecialChar ~
29466 mov (_gint + 1),a
29467 \layout Standard
29468
29469
29470 \size footnotesize 
29471 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
29472 \layout Standard
29473
29474
29475 \size footnotesize 
29476 \SpecialChar ~
29477 \SpecialChar ~
29478 inc r4
29479 \layout Standard
29480
29481
29482 \size footnotesize 
29483 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
29484 \layout Standard
29485
29486
29487 \size footnotesize 
29488 \SpecialChar ~
29489 \SpecialChar ~
29490 dec r5
29491 \layout Standard
29492
29493
29494 \size footnotesize 
29495 \SpecialChar ~
29496 \SpecialChar ~
29497 cjne r5,#0xff,00104$
29498 \layout Standard
29499
29500
29501 \size footnotesize 
29502 \SpecialChar ~
29503 \SpecialChar ~
29504 dec r6
29505 \layout Standard
29506
29507
29508 \size footnotesize 
29509 ; goto _forcond_0($4)
29510 \layout Standard
29511
29512
29513 \size footnotesize 
29514 \SpecialChar ~
29515 \SpecialChar ~
29516 sjmp 00104$
29517 \layout Standard
29518
29519
29520 \size footnotesize 
29521 ; _forbreak_0($7) :
29522 \layout Standard
29523
29524
29525 \size footnotesize 
29526 00107$:
29527 \layout Standard
29528
29529
29530 \size footnotesize 
29531 ; ret iTemp24 [lr40:41]{short}
29532 \layout Standard
29533
29534
29535 \size footnotesize 
29536 \SpecialChar ~
29537 \SpecialChar ~
29538 mov a,r3
29539 \layout Standard
29540
29541
29542 \size footnotesize 
29543 \SpecialChar ~
29544 \SpecialChar ~
29545 add a,r2
29546 \layout Standard
29547
29548
29549 \size footnotesize 
29550 \SpecialChar ~
29551 \SpecialChar ~
29552 mov dpl,a
29553 \layout Standard
29554
29555
29556 \size footnotesize 
29557 ; _return($8) :
29558 \layout Standard
29559
29560
29561 \size footnotesize 
29562 00108$:
29563 \layout Standard
29564
29565
29566 \size footnotesize 
29567 \SpecialChar ~
29568 \SpecialChar ~
29569 ret
29570 \newline 
29571
29572 \layout Section
29573
29574 A few words about basic block successors, predecessors and dominators
29575 \layout Standard
29576
29577 Successors are basic blocks
29578 \begin_inset LatexCommand \index{Basic blocks}
29579
29580 \end_inset 
29581
29582  that might execute after this basic block.
29583 \newline 
29584 Predecessors are basic blocks that might execute before reaching this basic
29585  block.
29586 \newline 
29587 Dominators are basic blocks that WILL execute before reaching this basic
29588  block.
29589 \newline 
29590
29591 \layout Standard
29592
29593 [basic block 1]
29594 \layout Standard
29595
29596 if (something)
29597 \layout Standard
29598
29599 \SpecialChar ~
29600 \SpecialChar ~
29601 \SpecialChar ~
29602 \SpecialChar ~
29603 [basic block 2]
29604 \layout Standard
29605
29606 else
29607 \layout Standard
29608
29609 \SpecialChar ~
29610 \SpecialChar ~
29611 \SpecialChar ~
29612 \SpecialChar ~
29613 [basic block 3]
29614 \layout Standard
29615
29616 [basic block 4]
29617 \newline 
29618
29619 \layout Standard
29620
29621 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
29622 \layout Standard
29623
29624 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
29625 \layout Standard
29626
29627 c) domVect of [BB4] = BB1 ...
29628  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
29629  was executed.
29630 \layout Chapter
29631
29632 Acknowledgments
29633 \layout Standard
29634
29635
29636 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
29637
29638 \end_inset 
29639
29640
29641 \newline 
29642
29643 \newline 
29644
29645 \emph on 
29646 Thanks to all the other volunteer developers who have helped with coding,
29647  testing, web-page creation, distribution sets, etc.
29648  You know who you are :-)
29649 \emph default 
29650
29651 \newline 
29652
29653 \layout Standard
29654
29655 This document was initially written by Sandeep Dutta
29656 \layout Standard
29657
29658 All product names mentioned herein may be trademarks
29659 \begin_inset LatexCommand \index{Trademarks}
29660
29661 \end_inset 
29662
29663  of their respective companies.
29664  
29665 \layout Section*
29666
29667 Alphabetical index
29668 \layout Standard
29669
29670 To avoid confusion, the installation and building options for SDCC itself
29671  (chapter 2) are not part of the index.
29672 \layout Standard
29673
29674
29675 \begin_inset LatexCommand \printindex{}
29676
29677 \end_inset 
29678
29679
29680 \the_end