git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4515 4a8a32a2...
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass book
4 \begin_preamble
5 \pdfoptionpdfminorversion=3
6 \usepackage[
7   pdftitle={SDCC Compiler User Guide},
8   pdfauthor={SDCC development team},
9   pdfsubject={installation, user manual},
10   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390                 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
11   pdfpagemode=UseOutlines,
12   colorlinks=true,
13   linkcolor=blue] {hyperref}
14 %
15 \sloppy
16 \tolerance=500          
17 \emergencystretch=30pt 
18 %
19 \date{}
20 \end_preamble
21 \language english
22 \inputencoding default
23 \fontscheme pslatex
24 \graphics default
25 \paperfontsize default
26 \spacing single 
27 \papersize letterpaper
28 \paperpackage a4
29 \use_geometry 1
30 \use_amsmath 0
31 \use_natbib 0
32 \use_numerical_citations 0
33 \paperorientation portrait
34 \leftmargin 30mm
35 \topmargin 20mm
36 \rightmargin 25mm
37 \bottommargin 20mm
38 \secnumdepth 3
39 \tocdepth 3
40 \paragraph_separation indent
41 \defskip medskip
42 \quotes_language swedish
43 \quotes_times 2
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47
48 \layout Comment
49
50 Please note: double dashed longoptions (e.g.
51  --version) are written this way: -
52 \begin_inset ERT
53 status Collapsed
54
55 \layout Standard
56
57 \backslash 
58 /
59 \end_inset 
60
61 -
62 \layout Comment
63
64 Two resp.
65  three consecutive dashes simply result in a long resp.
66  extra long dash.
67 \layout Comment
68
69 Architecture specific stuff (like memory models, code examples) should maybe
70  later go
71 \layout Comment
72
73 into seperate sections/chapters/appendices (it is hard to document PIC or
74  Z80 in 
75 \layout Comment
76
77 a 8051 centered document) - for now simply add.
78 \layout Title
79
80 SDCC Compiler User Guide
81 \layout Date
82
83
84 \size normal 
85 SDCC 2.6.2
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by Subversion
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
132  
133 \series bold 
134 Sandeep Dutta
135 \series default 
136  designed for 8 bit Microprocessors.
137  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
138  8051, 8052
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
140
141 \end_inset 
142
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144  Zilog Z80 based MCUs.
145  It can be retargeted for other microprocessors, support for Microchip PIC,
146  Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargetable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Standard
206
207
208 \begin_inset  Tabular
209 <lyxtabular version="3" rows="8" columns="5">
210 <features>
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
216 <row topline="true" bottomline="true">
217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
218 \begin_inset Text
219
220 \layout Standard
221
222 type
223 \end_inset 
224 </cell>
225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
226 \begin_inset Text
227
228 \layout Standard
229
230 width
231 \end_inset 
232 </cell>
233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
234 \begin_inset Text
235
236 \layout Standard
237
238 default
239 \end_inset 
240 </cell>
241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
242 \begin_inset Text
243
244 \layout Standard
245
246 signed range
247 \end_inset 
248 </cell>
249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
250 \begin_inset Text
251
252 \layout Standard
253
254 unsigned range
255 \end_inset 
256 </cell>
257 </row>
258 <row topline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \layout Standard
263
264 bool
265 \end_inset 
266 </cell>
267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
268 \begin_inset Text
269
270 \layout Standard
271
272 1 bit
273 \end_inset 
274 </cell>
275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
276 \begin_inset Text
277
278 \layout Standard
279
280 unsigned
281 \end_inset 
282 </cell>
283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_inset Text
285
286 \layout Standard
287
288 -
289 \end_inset 
290 </cell>
291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
292 \begin_inset Text
293
294 \layout Standard
295
296 0, 1
297 \end_inset 
298 </cell>
299 </row>
300 <row topline="true">
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_inset Text
303
304 \layout Standard
305
306 char
307 \end_inset 
308 </cell>
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
310 \begin_inset Text
311
312 \layout Standard
313
314 8 bits, 1 byte
315 \end_inset 
316 </cell>
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
318 \begin_inset Text
319
320 \layout Standard
321
322 signed
323 \end_inset 
324 </cell>
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
326 \begin_inset Text
327
328 \layout Standard
329
330 -128, +127
331 \end_inset 
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
334 \begin_inset Text
335
336 \layout Standard
337
338 0, +255
339 \end_inset 
340 </cell>
341 </row>
342 <row topline="true">
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
344 \begin_inset Text
345
346 \layout Standard
347
348 short
349 \end_inset 
350 </cell>
351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
352 \begin_inset Text
353
354 \layout Standard
355
356 16 bits, 2 bytes
357 \end_inset 
358 </cell>
359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
360 \begin_inset Text
361
362 \layout Standard
363
364 signed
365 \end_inset 
366 </cell>
367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
368 \begin_inset Text
369
370 \layout Standard
371
372 -32.768, +32.767
373 \end_inset 
374 </cell>
375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
376 \begin_inset Text
377
378 \layout Standard
379
380 0, +65.535
381 \end_inset 
382 </cell>
383 </row>
384 <row topline="true">
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
386 \begin_inset Text
387
388 \layout Standard
389
390 int
391 \end_inset 
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
394 \begin_inset Text
395
396 \layout Standard
397
398 16 bits, 2 bytes
399 \end_inset 
400 </cell>
401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
402 \begin_inset Text
403
404 \layout Standard
405
406 signed
407 \end_inset 
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \layout Standard
413
414 -32.768, +32.767
415 \end_inset 
416 </cell>
417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
418 \begin_inset Text
419
420 \layout Standard
421
422 0, +65.535
423 \end_inset 
424 </cell>
425 </row>
426 <row topline="true" bottomline="true">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \layout Standard
431
432 long
433 \end_inset 
434 </cell>
435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
436 \begin_inset Text
437
438 \layout Standard
439
440 32 bits, 4 bytes
441 \end_inset 
442 </cell>
443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
444 \begin_inset Text
445
446 \layout Standard
447
448 signed
449 \end_inset 
450 </cell>
451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
452 \begin_inset Text
453
454 \layout Standard
455
456 -2.147.483.648, +2.147.483.647
457 \end_inset 
458 </cell>
459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
460 \begin_inset Text
461
462 \layout Standard
463
464 0, +4.294.967.295
465 \end_inset 
466 </cell>
467 </row>
468 <row topline="true" bottomline="true">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \layout Standard
473
474 float
475 \end_inset 
476 </cell>
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
478 \begin_inset Text
479
480 \layout Standard
481
482 4 bytes IEEE 754
483 \end_inset 
484 </cell>
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
486 \begin_inset Text
487
488 \layout Standard
489
490 signed
491 \end_inset 
492 </cell>
493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
494 \begin_inset Text
495
496 \layout Standard
497
498 \end_inset 
499 </cell>
500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
501 \begin_inset Text
502
503 \layout Standard
504
505 1.175494351E-38, 
506 \family roman 
507 \series medium 
508 \shape up 
509 \size normal 
510 \emph off 
511 \bar no 
512 \noun off 
513 \color none
514 3.402823466E+38
515 \end_inset 
516 </cell>
517 </row>
518 <row topline="true" bottomline="true">
519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
520 \begin_inset Text
521
522 \layout Standard
523
524 pointer
525 \end_inset 
526 </cell>
527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
528 \begin_inset Text
529
530 \layout Standard
531
532 1, 2, 3 or 4 bytes
533 \end_inset 
534 </cell>
535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
536 \begin_inset Text
537
538 \layout Standard
539
540 generic
541 \end_inset 
542 </cell>
543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
544 \begin_inset Text
545
546 \layout Standard
547
548 \end_inset 
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
551 \begin_inset Text
552
553 \layout Standard
554
555 \end_inset 
556 </cell>
557 </row>
558 </lyxtabular>
559
560 \end_inset 
561
562
563 \newline 
564 The compiler also allows 
565 \emph on 
566 inline assembler code
567 \emph default 
568  to be embedded anywhere in a function.
569  In addition, routines developed in assembly can also be called.
570 \newline 
571
572 \newline 
573 SDCC also provides an option (-
574 \begin_inset ERT
575 status Collapsed
576
577 \layout Standard
578
579 \backslash 
580 /
581 \end_inset 
582
583 -cyclomatic) to report the relative complexity of a function.
584  These functions can then be further optimized, or hand coded in assembly
585  if needed.
586  
587 \newline 
588
589 \newline 
590 SDCC also comes with a companion source level debugger SDCDB, the debugger
591  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
592 \newline 
593
594 \newline 
595 The latest version can be downloaded from 
596 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
597
598 \end_inset 
599
600 .
601
602 \series bold 
603  
604 \series default 
605 \emph on 
606 Please note: the compiler will probably always be some steps ahead of this
607  documentation
608 \series bold 
609 \emph default 
610
611 \begin_inset LatexCommand \index{Status of documentation}
612
613 \end_inset 
614
615
616 \begin_inset Foot
617 collapsed false
618
619 \layout Standard
620
621 Obviously this has pros and cons
622 \end_inset 
623
624 .
625 \layout Section
626
627 Open Source
628 \layout Standard
629
630 All packages used in this compiler system are 
631 \emph on 
632 open source
633 \emph default 
634  and 
635 \emph on 
636 freeware
637 \emph default 
638 ; source code for all the sub-packages (pre-processor, assemblers, linkers
639  etc) is distributed with the package.
640  This documentation is maintained using a freeware word processor (LyX).
641 \newline 
642 This program is free software; you can redistribute it and/or modify it
643  under the terms of the GNU General Public License
644 \begin_inset LatexCommand \index{GNU General Public License, GPL}
645
646 \end_inset 
647
648  as published by the Free Software Foundation; either version 2, or (at
649  your option) any later version.
650  This program is distributed in the hope that it will be useful, but WITHOUT
651  ANY WARRANTY; without even the implied warranty
652 \begin_inset LatexCommand \index{warranty}
653
654 \end_inset 
655
656  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
657  See the GNU General Public License for more details.
658  You should have received a copy of the GNU General Public License along
659  with this program; if not, write to the Free Software Foundation, 59 Temple
660  Place - Suite 330, Boston, MA 02111-1307, USA.
661  In other words, you are welcome to use, share and improve this program.
662  You are forbidden to forbid anyone else to use, share and improve what
663  you give them.
664  Help stamp out software-hoarding! 
665 \layout Section
666
667 Typographic conventions
668 \begin_inset LatexCommand \index{Typographic conventions}
669
670 \end_inset 
671
672
673 \layout Standard
674
675 Throughout this manual, we will use the following convention.
676  Commands you have to type in are printed in 
677 \family sans 
678 \series bold 
679 "sans serif"
680 \series default 
681 .
682
683 \family default 
684  Code samples are printed in 
685 \family typewriter 
686 typewriter font.
687
688 \family default 
689  Interesting items and new terms are printed in 
690 \emph on 
691 italic.
692 \layout Section
693
694 Compatibility
695 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
696
697 \end_inset 
698
699  with previous versions
700 \begin_inset LatexCommand \index{Compatibility with previous versions}
701
702 \end_inset 
703
704
705 \layout Standard
706
707 This version has numerous bug fixes compared with the previous version.
708  But we also introduced some incompatibilities with older versions.
709  Not just for the fun of it, but to make the compiler more stable, efficient
710  and ANSI compliant
711 \begin_inset LatexCommand \index{ANSI-compliance}
712
713 \end_inset 
714
715  (see section 
716 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
717
718 \end_inset 
719
720  for ANSI-Compliance).
721  
722 \newline 
723
724 \layout Itemize
725
726 short is now equivalent to int (16 bits), it used to be equivalent to char
727  (8 bits) which is not ANSI compliant.
728 \layout Itemize
729
730 the default directory for gcc-builds where include, library and documentation
731  files are stored is now in /usr/local/share.
732 \layout Itemize
733
734 char type parameters to vararg
735 \begin_inset LatexCommand \index{vararg, va\_arg}
736
737 \end_inset 
738
739  functions are casted to int unless explicitly casted
740 \begin_inset Marginal
741 collapsed true
742
743 \layout Standard
744
745
746 \series bold 
747 \SpecialChar ~
748 !
749 \end_inset 
750
751 , e.g.: 
752 \newline 
753
754 \family typewriter 
755 \SpecialChar ~
756 \SpecialChar ~
757 char a=3;
758 \newline 
759 \SpecialChar ~
760 \SpecialChar ~
761 printf ("%d %c
762 \backslash 
763 n", a, (char)a);
764 \family default 
765
766 \newline 
767  will push a as an int and as a char resp.
768 \layout Itemize
769
770 option -
771 \begin_inset ERT
772 status Collapsed
773
774 \layout Standard
775
776 \backslash 
777 /
778 \end_inset 
779
780 -regextend has been removed.
781 \layout Itemize
782
783 option -
784 \begin_inset ERT
785 status Collapsed
786
787 \layout Standard
788
789 \backslash 
790 /
791 \end_inset 
792
793 -noregparms has been removed.
794 \layout Itemize
795
796 option -
797 \begin_inset ERT
798 status Collapsed
799
800 \layout Standard
801
802 \backslash 
803 /
804 \end_inset 
805
806 -stack-after-data has been removed.
807 \layout Itemize
808
809 bit
810 \begin_inset LatexCommand \index{bit}
811
812 \end_inset 
813
814  and sbit
815 \begin_inset LatexCommand \index{sbit}
816
817 \end_inset 
818
819
820 \begin_inset LatexCommand \index{\_\_sbit}
821
822 \end_inset 
823
824  types now consistently behave like the C99 _Bool type with respect to type
825  conversion
826 \begin_inset LatexCommand \index{type conversion}
827
828 \end_inset 
829
830
831 \begin_inset LatexCommand \index{type promotion}
832
833 \end_inset 
834
835 .
836  The most common incompatibility resulting from this change is related to
837  bit toggling
838 \begin_inset LatexCommand \index{Bit toggling}
839
840 \end_inset 
841
842  idioms, e.g.:
843 \newline 
844
845 \family typewriter 
846 \SpecialChar ~
847 \SpecialChar ~
848 bit b;
849 \newline 
850 \SpecialChar ~
851 \SpecialChar ~
852 b = ~
853 \begin_inset LatexCommand \index{\~\/ Operator}
854
855 \end_inset 
856
857 b; /* equivalent to b=1 instead of toggling b */
858 \begin_inset Marginal
859 collapsed true
860
861 \layout Standard
862
863
864 \series bold 
865 \SpecialChar ~
866 !
867 \end_inset 
868
869
870 \newline 
871 \SpecialChar ~
872 \SpecialChar ~
873 b = !b; /* toggles b */
874 \newline 
875
876 \family default 
877 In previous versions, both forms would have toggled the bit.
878 \layout Standard
879
880
881 \emph on 
882 <pending: more incompatibilities?>
883 \layout Section
884
885 System Requirements
886 \layout Standard
887
888 What do you need before you start installation of SDCC? A computer, and
889  a desire to compute.
890  The preferred method of installation is to compile SDCC from source using
891  GNU gcc and make.
892  For Windows some pre-compiled binary distributions are available for your
893  convenience.
894  You should have some experience with command line tools and compiler use.
895 \layout Section
896
897 Other Resources
898 \layout Standard
899
900 The SDCC home page at 
901 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
902
903 \end_inset 
904
905  is a great place to find distribution sets.
906  You can also find links to the user mailing lists that offer help or discuss
907  SDCC with other SDCC users.
908  Web links to other SDCC related sites can also be found here.
909  This document can be found in the DOC directory of the source package as
910  a text or HTML file.
911  A pdf version of this document is available at 
912 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
913
914 \end_inset 
915
916 .
917  Some of the other tools (simulator and assembler) included with SDCC contain
918  their own documentation and can be found in the source distribution.
919  If you want the latest unreleased software, the complete source package
920  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
921 /trunk/sdcc.
922 \layout Section
923
924 Wishes for the future
925 \layout Standard
926
927 There are (and always will be) some things that could be done.
928  Here are some I can think of:
929 \newline 
930
931 \layout Standard
932
933
934 \family typewriter 
935 char KernelFunction3(char p) at 0x340;
936 \newline 
937
938 \layout Standard
939
940
941 \family typewriter 
942 better code banking
943 \begin_inset LatexCommand \index{code banking (limited support)}
944
945 \end_inset 
946
947  support for mcs51
948 \newline 
949
950 \newline 
951
952 \family default 
953 If you can think of some more, please see the section 
954 \begin_inset LatexCommand \ref{sub:Requesting-Features}
955
956 \end_inset 
957
958  about filing feature requests
959 \begin_inset LatexCommand \index{Requesting features}
960
961 \end_inset 
962
963
964 \begin_inset LatexCommand \index{Feature request}
965
966 \end_inset 
967
968 .
969 \newline 
970
971 \layout Chapter
972
973 Installing SDCC
974 \begin_inset LatexCommand \index{Installation}
975
976 \end_inset 
977
978
979 \layout Standard
980
981 For most users it is sufficient to skip to either section 
982 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
983
984 \end_inset 
985
986  (Unix) or section 
987 \begin_inset LatexCommand \ref{sub:Windows-Install}
988
989 \end_inset 
990
991  (Windows).
992  More detailed instructions follow below.
993 \layout Section
994
995 Configure Options
996 \begin_inset LatexCommand \index{Options SDCC configuration}
997
998 \end_inset 
999
1000
1001 \layout Standard
1002
1003 The install paths, search paths and other options are defined when running
1004  'configure'.
1005  The defaults can be overridden by:
1006 \layout List
1007 \labelwidthstring 00.00.0000
1008
1009 -
1010 \begin_inset ERT
1011 status Collapsed
1012
1013 \layout Standard
1014
1015 \backslash 
1016 /
1017 \end_inset 
1018
1019 -prefix see table below
1020 \layout List
1021 \labelwidthstring 00.00.0000
1022
1023 -
1024 \begin_inset ERT
1025 status Collapsed
1026
1027 \layout Standard
1028
1029 \backslash 
1030 /
1031 \end_inset 
1032
1033 -exec_prefix see table below
1034 \layout List
1035 \labelwidthstring 00.00.0000
1036
1037 -
1038 \begin_inset ERT
1039 status Collapsed
1040
1041 \layout Standard
1042
1043 \backslash 
1044 /
1045 \end_inset 
1046
1047 -bindir see table below
1048 \layout List
1049 \labelwidthstring 00.00.0000
1050
1051 -
1052 \begin_inset ERT
1053 status Collapsed
1054
1055 \layout Standard
1056
1057 \backslash 
1058 /
1059 \end_inset 
1060
1061 -datadir see table below
1062 \newline 
1063
1064 \layout List
1065 \labelwidthstring 00.00.0000
1066
1067 \SpecialChar ~
1068 \SpecialChar ~
1069 docdir environment variable, see table below
1070 \layout List
1071 \labelwidthstring 00.00.0000
1072
1073 \SpecialChar ~
1074 \SpecialChar ~
1075 include_dir_suffix environment variable, see table below
1076 \layout List
1077 \labelwidthstring 00.00.0000
1078
1079 \SpecialChar ~
1080 \SpecialChar ~
1081 lib_dir_suffix environment variable, see table below
1082 \layout List
1083 \labelwidthstring 00.00.0000
1084
1085 \SpecialChar ~
1086 \SpecialChar ~
1087 sdccconf_h_dir_separator environment variable, either / or 
1088 \backslash 
1089
1090 \backslash 
1091  makes sense here.
1092  This character will only be used in sdccconf.h; don't forget it's a C-header,
1093  therefore a double-backslash is needed there.
1094 \newline 
1095
1096 \layout List
1097 \labelwidthstring 00.00.0000
1098
1099 -
1100 \begin_inset ERT
1101 status Collapsed
1102
1103 \layout Standard
1104
1105 \backslash 
1106 /
1107 \end_inset 
1108
1109 -disable-mcs51-port Excludes the Intel mcs51 port
1110 \layout List
1111 \labelwidthstring 00.00.0000
1112
1113 -
1114 \begin_inset ERT
1115 status Collapsed
1116
1117 \layout Standard
1118
1119 \backslash 
1120 /
1121 \end_inset 
1122
1123 -disable-gbz80-port Excludes the Gameboy gbz80 port
1124 \layout List
1125 \labelwidthstring 00.00.0000
1126
1127 -
1128 \begin_inset ERT
1129 status Collapsed
1130
1131 \layout Standard
1132
1133 \backslash 
1134 /
1135 \end_inset 
1136
1137 -disable-z80-port Excludes the z80 port
1138 \layout List
1139 \labelwidthstring 00.00.0000
1140
1141 -
1142 \begin_inset ERT
1143 status Collapsed
1144
1145 \layout Standard
1146
1147 \backslash 
1148 /
1149 \end_inset 
1150
1151 -disable-avr-port Excludes the AVR port
1152 \layout List
1153 \labelwidthstring 00.00.0000
1154
1155 -
1156 \begin_inset ERT
1157 status Collapsed
1158
1159 \layout Standard
1160
1161 \backslash 
1162 /
1163 \end_inset 
1164
1165 -disable-ds390-port Excludes the DS390 port
1166 \layout List
1167 \labelwidthstring 00.00.0000
1168
1169 -
1170 \begin_inset ERT
1171 status Collapsed
1172
1173 \layout Standard
1174
1175 \backslash 
1176 /
1177 \end_inset 
1178
1179 -disable-hc08-port Excludes the HC08 port
1180 \layout List
1181 \labelwidthstring 00.00.0000
1182
1183 -
1184 \begin_inset ERT
1185 status Collapsed
1186
1187 \layout Standard
1188
1189 \backslash 
1190 /
1191 \end_inset 
1192
1193 -disable-pic-port Excludes the PIC port
1194 \layout List
1195 \labelwidthstring 00.00.0000
1196
1197 -
1198 \begin_inset ERT
1199 status Collapsed
1200
1201 \layout Standard
1202
1203 \backslash 
1204 /
1205 \end_inset 
1206
1207 -disable-xa51-port Excludes the XA51 port
1208 \layout List
1209 \labelwidthstring 00.00.0000
1210
1211 -
1212 \begin_inset ERT
1213 status Collapsed
1214
1215 \layout Standard
1216
1217 \backslash 
1218 /
1219 \end_inset 
1220
1221 -disable-ucsim Disables configuring and building of ucsim
1222 \layout List
1223 \labelwidthstring 00.00.0000
1224
1225 -
1226 \begin_inset ERT
1227 status Collapsed
1228
1229 \layout Standard
1230
1231 \backslash 
1232 /
1233 \end_inset 
1234
1235 -disable-device-lib Disables automatically building device libraries
1236 \layout List
1237 \labelwidthstring 00.00.0000
1238
1239 -
1240 \begin_inset ERT
1241 status Collapsed
1242
1243 \layout Standard
1244
1245 \backslash 
1246 /
1247 \end_inset 
1248
1249 -disable-packihx Disables building packihx
1250 \newline 
1251
1252 \layout List
1253 \labelwidthstring 00.00.0000
1254
1255 -
1256 \begin_inset ERT
1257 status Collapsed
1258
1259 \layout Standard
1260
1261 \backslash 
1262 /
1263 \end_inset 
1264
1265 -enable-doc Build pdf, html and txt files from the lyx sources
1266 \layout List
1267 \labelwidthstring 00.00.0000
1268
1269 -
1270 \begin_inset ERT
1271 status Collapsed
1272
1273 \layout Standard
1274
1275 \backslash 
1276 /
1277 \end_inset 
1278
1279 -enable-libgc Use the Bohem memory allocator.
1280  Lower runtime footprint.
1281 \layout Standard
1282
1283 Furthermore the environment variables CC, CFLAGS, ...
1284  the tools and their arguments can be influenced.
1285  Please see `configure -
1286 \begin_inset ERT
1287 status Collapsed
1288
1289 \layout Standard
1290
1291 \backslash 
1292 /
1293 \end_inset 
1294
1295 -help` and the man/info pages of `configure` for details.
1296 \newline 
1297
1298 \newline 
1299 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1300  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1301 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1302  At the moment it's not possible to change the default settings (it was
1303  simply never required).
1304 \newline 
1305
1306 \newline 
1307 These configure options are compiled into the binaries, and can only be
1308  changed by rerunning 'configure' and recompiling SDCC.
1309  The configure options are written in 
1310 \emph on 
1311 italics
1312 \emph default 
1313  to distinguish them from run time environment variables (see section search
1314  paths).
1315 \newline 
1316
1317 \newline 
1318 The settings for 
1319 \begin_inset Quotes sld
1320 \end_inset 
1321
1322 Win32 builds
1323 \begin_inset Quotes srd
1324 \end_inset 
1325
1326  are used by the SDCC team to build the official Win32 binaries.
1327  The SDCC team uses Mingw32 to build the official Windows binaries, because
1328  it's
1329 \layout Enumerate
1330
1331 open source, 
1332 \layout Enumerate
1333
1334 a gcc compiler and last but not least
1335 \layout Enumerate
1336
1337 the binaries can be built by cross compiling on Sourceforge's compile farm.
1338 \layout Standard
1339
1340 See the examples, how to pass the Win32 settings to 'configure'.
1341  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1342  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1343  for Win32.
1344 \newline 
1345
1346 \newline 
1347 These defaults are:
1348 \newline 
1349
1350 \layout Standard
1351 \align center 
1352
1353 \begin_inset  Tabular
1354 <lyxtabular version="3" rows="8" columns="3">
1355 <features>
1356 <column alignment="block" valignment="top" leftline="true" width="0in">
1357 <column alignment="block" valignment="top" leftline="true" width="0in">
1358 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1359 <row topline="true" bottomline="true">
1360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1361 \begin_inset Text
1362
1363 \layout Standard
1364
1365 Variable
1366 \end_inset 
1367 </cell>
1368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1369 \begin_inset Text
1370
1371 \layout Standard
1372
1373 default
1374 \end_inset 
1375 </cell>
1376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1377 \begin_inset Text
1378
1379 \layout Standard
1380
1381 Win32 builds
1382 \end_inset 
1383 </cell>
1384 </row>
1385 <row topline="true">
1386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1387 \begin_inset Text
1388
1389 \layout Standard
1390
1391
1392 \emph on 
1393 PREFIX
1394 \end_inset 
1395 </cell>
1396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1397 \begin_inset Text
1398
1399 \layout Standard
1400
1401 /usr/local
1402 \end_inset 
1403 </cell>
1404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1405 \begin_inset Text
1406
1407 \layout Standard
1408
1409
1410 \backslash 
1411 sdcc
1412 \end_inset 
1413 </cell>
1414 </row>
1415 <row topline="true">
1416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1417 \begin_inset Text
1418
1419 \layout Standard
1420
1421
1422 \emph on 
1423 EXEC_PREFIX
1424 \end_inset 
1425 </cell>
1426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1427 \begin_inset Text
1428
1429 \layout Standard
1430
1431
1432 \emph on 
1433 $PREFIX
1434 \end_inset 
1435 </cell>
1436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1437 \begin_inset Text
1438
1439 \layout Standard
1440
1441
1442 \emph on 
1443 $PREFIX
1444 \end_inset 
1445 </cell>
1446 </row>
1447 <row topline="true">
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1449 \begin_inset Text
1450
1451 \layout Standard
1452
1453
1454 \emph on 
1455 BINDIR
1456 \end_inset 
1457 </cell>
1458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1459 \begin_inset Text
1460
1461 \layout Standard
1462
1463
1464 \emph on 
1465 $EXECPREFIX
1466 \emph default 
1467 /bin
1468 \end_inset 
1469 </cell>
1470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1471 \begin_inset Text
1472
1473 \layout Standard
1474
1475
1476 \emph on 
1477 $EXECPREFIX
1478 \emph default 
1479
1480 \backslash 
1481 bin
1482 \end_inset 
1483 </cell>
1484 </row>
1485 <row topline="true">
1486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1487 \begin_inset Text
1488
1489 \layout Standard
1490
1491
1492 \emph on 
1493 DATADIR
1494 \end_inset 
1495 </cell>
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1497 \begin_inset Text
1498
1499 \layout Standard
1500
1501
1502 \emph on 
1503 $PREFIX
1504 \emph default 
1505 /share
1506 \end_inset 
1507 </cell>
1508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1509 \begin_inset Text
1510
1511 \layout Standard
1512
1513
1514 \emph on 
1515 $PREFIX
1516 \end_inset 
1517 </cell>
1518 </row>
1519 <row topline="true">
1520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1521 \begin_inset Text
1522
1523 \layout Standard
1524
1525
1526 \emph on 
1527 DOCDIR
1528 \end_inset 
1529 </cell>
1530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1531 \begin_inset Text
1532
1533 \layout Standard
1534
1535
1536 \emph on 
1537 $DATADIR
1538 \emph default 
1539 /sdcc/doc
1540 \end_inset 
1541 </cell>
1542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1543 \begin_inset Text
1544
1545 \layout Standard
1546
1547
1548 \emph on 
1549 $DATADIR
1550 \emph default 
1551
1552 \backslash 
1553 doc
1554 \end_inset 
1555 </cell>
1556 </row>
1557 <row topline="true">
1558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1559 \begin_inset Text
1560
1561 \layout Standard
1562
1563
1564 \emph on 
1565 INCLUDE_DIR_SUFFIX
1566 \end_inset 
1567 </cell>
1568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1569 \begin_inset Text
1570
1571 \layout Standard
1572
1573 sdcc/include
1574 \end_inset 
1575 </cell>
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1577 \begin_inset Text
1578
1579 \layout Standard
1580
1581 include
1582 \end_inset 
1583 </cell>
1584 </row>
1585 <row topline="true" bottomline="true">
1586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1587 \begin_inset Text
1588
1589 \layout Standard
1590
1591
1592 \emph on 
1593 LIB_DIR_SUFFIX
1594 \end_inset 
1595 </cell>
1596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1597 \begin_inset Text
1598
1599 \layout Standard
1600
1601 sdcc/lib
1602 \end_inset 
1603 </cell>
1604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1605 \begin_inset Text
1606
1607 \layout Standard
1608
1609 lib
1610 \end_inset 
1611 </cell>
1612 </row>
1613 </lyxtabular>
1614
1615 \end_inset 
1616
1617
1618 \newline 
1619
1620 \layout Standard
1621 \noindent 
1622 'configure' also computes relative paths.
1623  This is needed for full relocatability of a binary package and to complete
1624  search paths (see section search paths below):
1625 \newline 
1626  
1627 \layout Standard
1628 \align center 
1629
1630 \begin_inset  Tabular
1631 <lyxtabular version="3" rows="4" columns="3">
1632 <features>
1633 <column alignment="block" valignment="top" leftline="true" width="0in">
1634 <column alignment="block" valignment="top" leftline="true" width="0in">
1635 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1636 <row topline="true" bottomline="true">
1637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1638 \begin_inset Text
1639
1640 \layout Standard
1641
1642 Variable (computed)
1643 \end_inset 
1644 </cell>
1645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1646 \begin_inset Text
1647
1648 \layout Standard
1649
1650 default
1651 \end_inset 
1652 </cell>
1653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1654 \begin_inset Text
1655
1656 \layout Standard
1657
1658 Win32 builds
1659 \end_inset 
1660 </cell>
1661 </row>
1662 <row topline="true" bottomline="true">
1663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1664 \begin_inset Text
1665
1666 \layout Standard
1667
1668
1669 \emph on 
1670 BIN2DATA_DIR
1671 \end_inset 
1672 </cell>
1673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1674 \begin_inset Text
1675
1676 \layout Standard
1677
1678 ../share
1679 \end_inset 
1680 </cell>
1681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1682 \begin_inset Text
1683
1684 \layout Standard
1685
1686 ..
1687 \end_inset 
1688 </cell>
1689 </row>
1690 <row bottomline="true">
1691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1692 \begin_inset Text
1693
1694 \layout Standard
1695
1696
1697 \emph on 
1698 PREFIX2BIN_DIR
1699 \end_inset 
1700 </cell>
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1702 \begin_inset Text
1703
1704 \layout Standard
1705
1706 bin
1707 \end_inset 
1708 </cell>
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1710 \begin_inset Text
1711
1712 \layout Standard
1713
1714 bin
1715 \end_inset 
1716 </cell>
1717 </row>
1718 <row bottomline="true">
1719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1720 \begin_inset Text
1721
1722 \layout Standard
1723
1724
1725 \emph on 
1726 PREFIX2DATA_DIR
1727 \end_inset 
1728 </cell>
1729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1730 \begin_inset Text
1731
1732 \layout Standard
1733
1734 share/sdcc
1735 \end_inset 
1736 </cell>
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1738 \begin_inset Text
1739
1740 \layout Standard
1741
1742 \end_inset 
1743 </cell>
1744 </row>
1745 </lyxtabular>
1746
1747 \end_inset 
1748
1749
1750 \newline 
1751
1752 \layout Standard
1753 \noindent 
1754 Examples:
1755 \layout LyX-Code
1756
1757 ./configure
1758 \newline 
1759 ./configure -
1760 \begin_inset ERT
1761 status Collapsed
1762
1763 \layout Standard
1764
1765 \backslash 
1766 /
1767 \end_inset 
1768
1769 -prefix=
1770 \begin_inset Quotes srd
1771 \end_inset 
1772
1773 /usr/bin
1774 \begin_inset Quotes srd
1775 \end_inset 
1776
1777  -
1778 \begin_inset ERT
1779 status Collapsed
1780
1781 \layout Standard
1782
1783 \backslash 
1784 /
1785 \end_inset 
1786
1787 -datadir=
1788 \begin_inset Quotes srd
1789 \end_inset 
1790
1791 /usr/share
1792 \begin_inset Quotes srd
1793 \end_inset 
1794
1795
1796 \newline 
1797 ./configure -
1798 \begin_inset ERT
1799 status Collapsed
1800
1801 \layout Standard
1802
1803 \backslash 
1804 /
1805 \end_inset 
1806
1807 -disable-avr-port -
1808 \begin_inset ERT
1809 status Collapsed
1810
1811 \layout Standard
1812
1813 \backslash 
1814 /
1815 \end_inset 
1816
1817 -disable-xa51-port
1818 \layout Standard
1819
1820 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1821 32'):
1822 \layout LyX-Code
1823
1824 ./configure 
1825 \backslash 
1826
1827 \newline 
1828 CC=
1829 \begin_inset Quotes srd
1830 \end_inset 
1831
1832 i586-mingw32msvc-gcc
1833 \begin_inset Quotes srd
1834 \end_inset 
1835
1836  CXX=
1837 \begin_inset Quotes srd
1838 \end_inset 
1839
1840 i586-mingw32msvc-g++
1841 \begin_inset Quotes srd
1842 \end_inset 
1843
1844  
1845 \backslash 
1846  
1847 \newline 
1848 RANLIB=
1849 \begin_inset Quotes srd
1850 \end_inset 
1851
1852 i586-mingw32msvc-ranlib
1853 \begin_inset Quotes srd
1854 \end_inset 
1855
1856  
1857 \backslash 
1858
1859 \newline 
1860 STRIP=
1861 \begin_inset Quotes srd
1862 \end_inset 
1863
1864 i586-mingw32msvc-strip
1865 \begin_inset Quotes srd
1866 \end_inset 
1867
1868  
1869 \backslash 
1870
1871 \newline 
1872 -
1873 \begin_inset ERT
1874 status Collapsed
1875
1876 \layout Standard
1877
1878 \backslash 
1879 /
1880 \end_inset 
1881
1882 -prefix=
1883 \begin_inset Quotes srd
1884 \end_inset 
1885
1886 /sdcc
1887 \begin_inset Quotes srd
1888 \end_inset 
1889
1890  
1891 \backslash 
1892
1893 \newline 
1894 -
1895 \begin_inset ERT
1896 status Collapsed
1897
1898 \layout Standard
1899
1900 \backslash 
1901 /
1902 \end_inset 
1903
1904 -datadir=
1905 \begin_inset Quotes srd
1906 \end_inset 
1907
1908 /sdcc
1909 \begin_inset Quotes srd
1910 \end_inset 
1911
1912  
1913 \backslash 
1914
1915 \newline 
1916 docdir=
1917 \begin_inset Quotes srd
1918 \end_inset 
1919
1920 /sdcc/doc
1921 \begin_inset Quotes srd
1922 \end_inset 
1923
1924  
1925 \backslash 
1926
1927 \newline 
1928 include_dir_suffix=
1929 \begin_inset Quotes srd
1930 \end_inset 
1931
1932 include
1933 \begin_inset Quotes srd
1934 \end_inset 
1935
1936  
1937 \backslash 
1938
1939 \newline 
1940 lib_dir_suffix=
1941 \begin_inset Quotes srd
1942 \end_inset 
1943
1944 lib
1945 \begin_inset Quotes srd
1946 \end_inset 
1947
1948  
1949 \backslash 
1950
1951 \newline 
1952 sdccconf_h_dir_separator=
1953 \begin_inset Quotes srd
1954 \end_inset 
1955
1956
1957 \backslash 
1958
1959 \backslash 
1960
1961 \backslash 
1962
1963 \backslash 
1964
1965 \begin_inset Quotes srd
1966 \end_inset 
1967
1968  
1969 \backslash 
1970
1971 \newline 
1972 -
1973 \begin_inset ERT
1974 status Collapsed
1975
1976 \layout Standard
1977
1978 \backslash 
1979 /
1980 \end_inset 
1981
1982 -disable-device-lib
1983 \backslash 
1984
1985 \newline 
1986 -
1987 \begin_inset ERT
1988 status Collapsed
1989
1990 \layout Standard
1991
1992 \backslash 
1993 /
1994 \end_inset 
1995
1996 -host=i586-mingw32msvc
1997 \backslash 
1998
1999 \newline 
2000 -
2001 \begin_inset ERT
2002 status Collapsed
2003
2004 \layout Standard
2005
2006 \backslash 
2007 /
2008 \end_inset 
2009
2010 -build=unknown-unknown-linux-gnu
2011 \layout Standard
2012
2013 To 
2014 \begin_inset Quotes sld
2015 \end_inset 
2016
2017 cross
2018 \begin_inset Quotes srd
2019 \end_inset 
2020
2021 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2022 ):
2023 \layout LyX-Code
2024
2025 ./configure -C 
2026 \backslash 
2027
2028 \newline 
2029 -
2030 \begin_inset ERT
2031 status Collapsed
2032
2033 \layout Standard
2034
2035 \backslash 
2036 /
2037 \end_inset 
2038
2039 -prefix=
2040 \begin_inset Quotes srd
2041 \end_inset 
2042
2043 /sdcc
2044 \begin_inset Quotes srd
2045 \end_inset 
2046
2047  
2048 \backslash 
2049
2050 \newline 
2051 -
2052 \begin_inset ERT
2053 status Collapsed
2054
2055 \layout Standard
2056
2057 \backslash 
2058 /
2059 \end_inset 
2060
2061 -datadir=
2062 \begin_inset Quotes srd
2063 \end_inset 
2064
2065 /sdcc
2066 \begin_inset Quotes srd
2067 \end_inset 
2068
2069  
2070 \backslash 
2071
2072 \newline 
2073 docdir=
2074 \begin_inset Quotes srd
2075 \end_inset 
2076
2077 /sdcc/doc
2078 \begin_inset Quotes srd
2079 \end_inset 
2080
2081  
2082 \backslash 
2083  
2084 \newline 
2085 include_dir_suffix=
2086 \begin_inset Quotes srd
2087 \end_inset 
2088
2089 include
2090 \begin_inset Quotes srd
2091 \end_inset 
2092
2093  
2094 \backslash 
2095
2096 \newline 
2097 lib_dir_suffix=
2098 \begin_inset Quotes srd
2099 \end_inset 
2100
2101 lib
2102 \begin_inset Quotes srd
2103 \end_inset 
2104
2105  
2106 \backslash 
2107
2108 \newline 
2109 sdccconf_h_dir_separator=
2110 \begin_inset Quotes srd
2111 \end_inset 
2112
2113
2114 \backslash 
2115
2116 \backslash 
2117
2118 \backslash 
2119
2120 \backslash 
2121
2122 \begin_inset Quotes srd
2123 \end_inset 
2124
2125  
2126 \backslash 
2127
2128 \newline 
2129 CC=
2130 \begin_inset Quotes srd
2131 \end_inset 
2132
2133 gcc -mno-cygwin
2134 \begin_inset Quotes srd
2135 \end_inset 
2136
2137  
2138 \backslash 
2139
2140 \newline 
2141 CXX=
2142 \begin_inset Quotes srd
2143 \end_inset 
2144
2145 g++ -mno-cygwin
2146 \begin_inset Quotes srd
2147 \end_inset 
2148
2149  
2150 \layout Standard
2151
2152 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2153  The option '-
2154 \begin_inset ERT
2155 status Collapsed
2156
2157 \layout Standard
2158
2159 \backslash 
2160 /
2161 \end_inset 
2162
2163 -C' turns on caching, which gives a little bit extra speed.
2164  However if options are changed, it can be necessary to delete the config.cache
2165  file.
2166 \layout Section
2167
2168 Install paths
2169 \begin_inset LatexCommand \label{sub:Install-paths}
2170
2171 \end_inset 
2172
2173
2174 \begin_inset LatexCommand \index{Install paths}
2175
2176 \end_inset 
2177
2178
2179 \layout Standard
2180 \added_space_top medskip \align center 
2181
2182 \begin_inset  Tabular
2183 <lyxtabular version="3" rows="5" columns="4">
2184 <features>
2185 <column alignment="left" valignment="top" leftline="true" width="0">
2186 <column alignment="left" valignment="top" leftline="true" width="0">
2187 <column alignment="left" valignment="top" leftline="true" width="0">
2188 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2189 <row topline="true" bottomline="true">
2190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2191 \begin_inset Text
2192
2193 \layout Standard
2194
2195
2196 \series bold 
2197 Description
2198 \end_inset 
2199 </cell>
2200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2201 \begin_inset Text
2202
2203 \layout Standard
2204
2205
2206 \series bold 
2207 Path
2208 \end_inset 
2209 </cell>
2210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2211 \begin_inset Text
2212
2213 \layout Standard
2214
2215
2216 \series bold 
2217 Default
2218 \end_inset 
2219 </cell>
2220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2221 \begin_inset Text
2222
2223 \layout Standard
2224
2225
2226 \series bold 
2227 Win32 builds
2228 \end_inset 
2229 </cell>
2230 </row>
2231 <row topline="true">
2232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2233 \begin_inset Text
2234
2235 \layout Standard
2236
2237 Binary files*
2238 \end_inset 
2239 </cell>
2240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2241 \begin_inset Text
2242
2243 \layout Standard
2244
2245
2246 \emph on 
2247 $EXEC_PREFIX
2248 \end_inset 
2249 </cell>
2250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2251 \begin_inset Text
2252
2253 \layout Standard
2254
2255 /usr/local/bin
2256 \end_inset 
2257 </cell>
2258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2259 \begin_inset Text
2260
2261 \layout Standard
2262
2263
2264 \backslash 
2265 sdcc
2266 \backslash 
2267 bin
2268 \end_inset 
2269 </cell>
2270 </row>
2271 <row topline="true">
2272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2273 \begin_inset Text
2274
2275 \layout Standard
2276
2277 Include files
2278 \end_inset 
2279 </cell>
2280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2281 \begin_inset Text
2282
2283 \layout Standard
2284
2285
2286 \emph on 
2287 $DATADIR/ $INCLUDE_DIR_SUFFIX
2288 \end_inset 
2289 </cell>
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_inset Text
2292
2293 \layout Standard
2294
2295 /usr/local/share/sdcc/include
2296 \end_inset 
2297 </cell>
2298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2299 \begin_inset Text
2300
2301 \layout Standard
2302
2303
2304 \backslash 
2305 sdcc
2306 \backslash 
2307 include
2308 \end_inset 
2309 </cell>
2310 </row>
2311 <row topline="true">
2312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2313 \begin_inset Text
2314
2315 \layout Standard
2316
2317 Library file**
2318 \end_inset 
2319 </cell>
2320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2321 \begin_inset Text
2322
2323 \layout Standard
2324
2325
2326 \emph on 
2327 $DATADIR/$LIB_DIR_SUFFIX
2328 \end_inset 
2329 </cell>
2330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2331 \begin_inset Text
2332
2333 \layout Standard
2334
2335 /usr/local/share/sdcc/lib
2336 \end_inset 
2337 </cell>
2338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2339 \begin_inset Text
2340
2341 \layout Standard
2342
2343
2344 \backslash 
2345 sdcc
2346 \backslash 
2347 lib
2348 \end_inset 
2349 </cell>
2350 </row>
2351 <row topline="true" bottomline="true">
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2353 \begin_inset Text
2354
2355 \layout Standard
2356
2357 Documentation
2358 \end_inset 
2359 </cell>
2360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2361 \begin_inset Text
2362
2363 \layout Standard
2364
2365
2366 \emph on 
2367 $DOCDIR
2368 \end_inset 
2369 </cell>
2370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2371 \begin_inset Text
2372
2373 \layout Standard
2374
2375 /usr/local/share/sdcc/doc
2376 \end_inset 
2377 </cell>
2378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2379 \begin_inset Text
2380
2381 \layout Standard
2382
2383
2384 \backslash 
2385 sdcc
2386 \backslash 
2387 doc
2388 \end_inset 
2389 </cell>
2390 </row>
2391 </lyxtabular>
2392
2393 \end_inset 
2394
2395
2396 \layout Verse
2397
2398
2399 \size footnotesize 
2400 *compiler, preprocessor, assembler, and linker
2401 \newline 
2402 **the 
2403 \shape italic 
2404 model
2405 \shape default 
2406  is auto-appended by the compiler, e.g.
2407  small, large, z80, ds390 etc
2408 \layout Standard
2409 \noindent 
2410 The install paths can still be changed during `make install` with e.g.:
2411 \layout LyX-Code
2412
2413 make install prefix=$(HOME)/local/sdcc
2414 \layout Standard
2415
2416 Of course this doesn't change the search paths compiled into the binaries.
2417 \newline 
2418
2419 \newline 
2420 Moreover the install path can be changed by defining DESTDIR
2421 \begin_inset LatexCommand \index{DESTDIR}
2422
2423 \end_inset 
2424
2425 :
2426 \layout LyX-Code
2427
2428 make install DESTDIR=$(HOME)/sdcc.rpm/
2429 \layout Standard
2430
2431 Please note that DESTDIR must have a trailing slash!
2432 \layout Section
2433
2434 Search Paths
2435 \begin_inset LatexCommand \label{sub:Search-Paths}
2436
2437 \end_inset 
2438
2439
2440 \begin_inset LatexCommand \index{Search path}
2441
2442 \end_inset 
2443
2444
2445 \layout Standard
2446
2447 Some search paths or parts of them are determined by configure variables
2448  (in 
2449 \emph on 
2450 italics
2451 \emph default 
2452 , see section above).
2453  Further search paths are determined by environment variables during runtime.
2454  
2455 \newline 
2456 The paths searched when running the compiler are as follows (the first catch
2457  wins):
2458 \newline 
2459
2460 \newline 
2461 1.
2462  Binary files (preprocessor, assembler and linker)
2463 \newline 
2464
2465 \layout Standard
2466 \align center 
2467
2468 \begin_inset  Tabular
2469 <lyxtabular version="3" rows="4" columns="3">
2470 <features>
2471 <column alignment="block" valignment="top" leftline="true" width="0in">
2472 <column alignment="block" valignment="top" leftline="true" width="0in">
2473 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2474 <row topline="true" bottomline="true">
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2476 \begin_inset Text
2477
2478 \layout Standard
2479
2480 Search path
2481 \end_inset 
2482 </cell>
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2484 \begin_inset Text
2485
2486 \layout Standard
2487
2488 default
2489 \end_inset 
2490 </cell>
2491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2492 \begin_inset Text
2493
2494 \layout Standard
2495
2496 Win32 builds
2497 \end_inset 
2498 </cell>
2499 </row>
2500 <row topline="true">
2501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2502 \begin_inset Text
2503
2504 \layout Standard
2505
2506 $SDCC_HOME/
2507 \emph on 
2508 $PPREFIX2BIN_DIR
2509 \end_inset 
2510 </cell>
2511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2512 \begin_inset Text
2513
2514 \layout Standard
2515
2516 $SDCC_HOME/bin
2517 \end_inset 
2518 </cell>
2519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2520 \begin_inset Text
2521
2522 \layout Standard
2523
2524 $SDCC_HOME
2525 \backslash 
2526 bin
2527 \end_inset 
2528 </cell>
2529 </row>
2530 <row topline="true">
2531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2532 \begin_inset Text
2533
2534 \layout Standard
2535
2536 Path of argv[0] (if available)
2537 \end_inset 
2538 </cell>
2539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2540 \begin_inset Text
2541
2542 \layout Standard
2543
2544 Path of argv[0]
2545 \end_inset 
2546 </cell>
2547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2548 \begin_inset Text
2549
2550 \layout Standard
2551
2552 Path of argv[0]
2553 \end_inset 
2554 </cell>
2555 </row>
2556 <row topline="true" bottomline="true">
2557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2558 \begin_inset Text
2559
2560 \layout Standard
2561
2562 $PATH
2563 \end_inset 
2564 </cell>
2565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2566 \begin_inset Text
2567
2568 \layout Standard
2569
2570 $PATH
2571 \end_inset 
2572 </cell>
2573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2574 \begin_inset Text
2575
2576 \layout Standard
2577
2578 $PATH
2579 \end_inset 
2580 </cell>
2581 </row>
2582 </lyxtabular>
2583
2584 \end_inset 
2585
2586  
2587 \newline 
2588
2589 \layout Standard
2590 \noindent 
2591 2.
2592  Include files
2593 \newline 
2594
2595 \layout Standard
2596 \align center 
2597
2598 \begin_inset  Tabular
2599 <lyxtabular version="3" rows="6" columns="3">
2600 <features>
2601 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2602 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2603 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2604 <row topline="true" bottomline="true">
2605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2606 \begin_inset Text
2607
2608 \layout Standard
2609
2610 Search path
2611 \end_inset 
2612 </cell>
2613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2614 \begin_inset Text
2615
2616 \layout Standard
2617
2618 default
2619 \end_inset 
2620 </cell>
2621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2622 \begin_inset Text
2623
2624 \layout Standard
2625
2626 Win32 builds
2627 \end_inset 
2628 </cell>
2629 </row>
2630 <row topline="true">
2631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2632 \begin_inset Text
2633
2634 \layout Standard
2635
2636 -
2637 \begin_inset ERT
2638 status Collapsed
2639
2640 \layout Standard
2641
2642 \backslash 
2643 /
2644 \end_inset 
2645
2646 -I dir
2647 \end_inset 
2648 </cell>
2649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2650 \begin_inset Text
2651
2652 \layout Standard
2653
2654 -
2655 \begin_inset ERT
2656 status Collapsed
2657
2658 \layout Standard
2659
2660 \backslash 
2661 /
2662 \end_inset 
2663
2664 -I dir
2665 \end_inset 
2666 </cell>
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2668 \begin_inset Text
2669
2670 \layout Standard
2671
2672 -
2673 \begin_inset ERT
2674 status Collapsed
2675
2676 \layout Standard
2677
2678 \backslash 
2679 /
2680 \end_inset 
2681
2682 -I dir
2683 \end_inset 
2684 </cell>
2685 </row>
2686 <row topline="true">
2687 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2688 \begin_inset Text
2689
2690 \layout Standard
2691
2692 $SDCC_INCLUDE
2693 \end_inset 
2694 </cell>
2695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2696 \begin_inset Text
2697
2698 \layout Standard
2699
2700 $SDCC_INCLUDE
2701 \end_inset 
2702 </cell>
2703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2704 \begin_inset Text
2705
2706 \layout Standard
2707
2708 $SDCC_INCLUDE
2709 \end_inset 
2710 </cell>
2711 </row>
2712 <row topline="true">
2713 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_inset Text
2715
2716 \layout Standard
2717
2718 $SDCC_HOME/
2719 \newline 
2720
2721 \emph on 
2722 $PREFIX2DATA_DIR/
2723 \newline 
2724 $INCLUDE_DIR_SUFFIX
2725 \end_inset 
2726 </cell>
2727 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2728 \begin_inset Text
2729
2730 \layout Standard
2731
2732 $SDCC_ HOME/
2733 \newline 
2734 share/sdcc/
2735 \newline 
2736 include
2737 \end_inset 
2738 </cell>
2739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2740 \begin_inset Text
2741
2742 \layout Standard
2743
2744 $SDCC_HOME
2745 \backslash 
2746 include
2747 \end_inset 
2748 </cell>
2749 </row>
2750 <row topline="true">
2751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2752 \begin_inset Text
2753
2754 \layout Standard
2755
2756 path(argv[0])/
2757 \newline 
2758
2759 \emph on 
2760 $BIN2DATADIR/
2761 \emph default 
2762
2763 \newline 
2764
2765 \emph on 
2766 $INCLUDE_DIR_SUFFIX
2767 \end_inset 
2768 </cell>
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2770 \begin_inset Text
2771
2772 \layout Standard
2773
2774 path(argv[0])/
2775 \newline 
2776 ../sdcc/include
2777 \newline 
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 \SpecialChar ~
2798 \SpecialChar ~
2799 \SpecialChar ~
2800 \SpecialChar ~
2801 \SpecialChar ~
2802 \SpecialChar ~
2803 \SpecialChar ~
2804 \SpecialChar ~
2805 \SpecialChar ~
2806 \SpecialChar ~
2807 \SpecialChar ~
2808 \SpecialChar ~
2809 \SpecialChar ~
2810 \SpecialChar ~
2811 \SpecialChar ~
2812 \SpecialChar ~
2813 \SpecialChar ~
2814 \SpecialChar ~
2815 \SpecialChar ~
2816
2817 \end_inset 
2818 </cell>
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2820 \begin_inset Text
2821
2822 \layout Standard
2823
2824 path(argv[0])
2825 \backslash 
2826 ..
2827 \backslash 
2828 include
2829 \end_inset 
2830 </cell>
2831 </row>
2832 <row topline="true" bottomline="true">
2833 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2834 \begin_inset Text
2835
2836 \layout Standard
2837
2838
2839 \emph on 
2840 $DATADIR/
2841 \emph default 
2842
2843 \newline 
2844
2845 \emph on 
2846 $INCLUDE_DIR_SUFFIX
2847 \end_inset 
2848 </cell>
2849 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2850 \begin_inset Text
2851
2852 \layout Standard
2853
2854 /usr/local/share/sdcc/
2855 \newline 
2856 include
2857 \end_inset 
2858 </cell>
2859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2860 \begin_inset Text
2861
2862 \layout Standard
2863
2864 (not on Win32)
2865 \end_inset 
2866 </cell>
2867 </row>
2868 </lyxtabular>
2869
2870 \end_inset 
2871
2872  
2873 \newline 
2874
2875 \layout Standard
2876 \noindent 
2877 The option -
2878 \begin_inset ERT
2879 status Collapsed
2880
2881 \layout Standard
2882
2883 \backslash 
2884 /
2885 \end_inset 
2886
2887 -nostdinc disables the last two search paths.
2888 \newline 
2889
2890 \newline 
2891 3.
2892  Library files 
2893 \newline 
2894
2895 \layout Standard
2896
2897 With the exception of 
2898 \begin_inset Quotes sld
2899 \end_inset 
2900
2901 -
2902 \begin_inset ERT
2903 status Collapsed
2904
2905 \layout Standard
2906
2907 \backslash 
2908 /
2909 \end_inset 
2910
2911 -L dir
2912 \begin_inset Quotes srd
2913 \end_inset 
2914
2915  the 
2916 \shape italic 
2917 model
2918 \shape default 
2919  is auto-appended by the compiler (e.g.
2920  small, large, z80, ds390 etc.).
2921  
2922 \newline 
2923
2924 \layout Standard
2925 \align center 
2926
2927 \begin_inset  Tabular
2928 <lyxtabular version="3" rows="6" columns="3">
2929 <features>
2930 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2931 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2932 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2933 <row topline="true" bottomline="true">
2934 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2935 \begin_inset Text
2936
2937 \layout Standard
2938
2939 Search path
2940 \end_inset 
2941 </cell>
2942 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2943 \begin_inset Text
2944
2945 \layout Standard
2946
2947 default
2948 \end_inset 
2949 </cell>
2950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2951 \begin_inset Text
2952
2953 \layout Standard
2954
2955 Win32 builds
2956 \end_inset 
2957 </cell>
2958 </row>
2959 <row topline="true">
2960 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2961 \begin_inset Text
2962
2963 \layout Standard
2964
2965 -
2966 \begin_inset ERT
2967 status Collapsed
2968
2969 \layout Standard
2970
2971 \backslash 
2972 /
2973 \end_inset 
2974
2975 -L dir
2976 \end_inset 
2977 </cell>
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2979 \begin_inset Text
2980
2981 \layout Standard
2982
2983 -
2984 \begin_inset ERT
2985 status Collapsed
2986
2987 \layout Standard
2988
2989 \backslash 
2990 /
2991 \end_inset 
2992
2993 -L dir
2994 \end_inset 
2995 </cell>
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2997 \begin_inset Text
2998
2999 \layout Standard
3000
3001 -
3002 \begin_inset ERT
3003 status Collapsed
3004
3005 \layout Standard
3006
3007 \backslash 
3008 /
3009 \end_inset 
3010
3011 -L dir
3012 \end_inset 
3013 </cell>
3014 </row>
3015 <row topline="true">
3016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3017 \begin_inset Text
3018
3019 \layout Standard
3020
3021 $SDCC_LIB/
3022 \newline 
3023
3024 \emph on 
3025 <model>
3026 \end_inset 
3027 </cell>
3028 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3029 \begin_inset Text
3030
3031 \layout Standard
3032
3033 $SDCC_LIB/
3034 \newline 
3035
3036 \emph on 
3037 <model>
3038 \end_inset 
3039 </cell>
3040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3041 \begin_inset Text
3042
3043 \layout Standard
3044
3045 $SDCC_LIB
3046 \backslash 
3047
3048 \newline 
3049
3050 \emph on 
3051 <model>
3052 \end_inset 
3053 </cell>
3054 </row>
3055 <row topline="true">
3056 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3057 \begin_inset Text
3058
3059 \layout Standard
3060
3061 $SDCC_HOME/
3062 \newline 
3063
3064 \emph on 
3065 $PREFIX2DATA_DIR/
3066 \newline 
3067 $LIB_DIR_SUFFIX/<model>
3068 \end_inset 
3069 </cell>
3070 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3071 \begin_inset Text
3072
3073 \layout Standard
3074
3075 $SDCC_HOME/
3076 \newline 
3077 share/sdcc/
3078 \newline 
3079 lib/
3080 \emph on 
3081 <model>
3082 \end_inset 
3083 </cell>
3084 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3085 \begin_inset Text
3086
3087 \layout Standard
3088
3089 $SDCC_HOME
3090 \backslash 
3091 lib
3092 \backslash 
3093
3094 \emph on 
3095
3096 \newline 
3097 <model>
3098 \end_inset 
3099 </cell>
3100 </row>
3101 <row topline="true">
3102 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3103 \begin_inset Text
3104
3105 \layout Standard
3106
3107 path(argv[0])/
3108 \newline 
3109
3110 \emph on 
3111 $BIN2DATADIR/
3112 \emph default 
3113
3114 \newline 
3115
3116 \emph on 
3117 $LIB_DIR_SUFFIX/<model>
3118 \end_inset 
3119 </cell>
3120 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3121 \begin_inset Text
3122
3123 \layout Standard
3124
3125 path(argv[0])/
3126 \newline 
3127 ../sdcc/lib/
3128 \emph on 
3129 <model>
3130 \newline 
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 \SpecialChar ~
3152 \SpecialChar ~
3153 \SpecialChar ~
3154 \SpecialChar ~
3155 \SpecialChar ~
3156 \SpecialChar ~
3157 \SpecialChar ~
3158 \SpecialChar ~
3159 \SpecialChar ~
3160 \SpecialChar ~
3161 \SpecialChar ~
3162 \SpecialChar ~
3163 \SpecialChar ~
3164 \SpecialChar ~
3165 \SpecialChar ~
3166 \SpecialChar ~
3167 \SpecialChar ~
3168 \SpecialChar ~
3169 \SpecialChar ~
3170
3171 \end_inset 
3172 </cell>
3173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3174 \begin_inset Text
3175
3176 \layout Standard
3177
3178 path(argv[0])
3179 \backslash 
3180
3181 \newline 
3182 ..
3183 \backslash 
3184 lib
3185 \backslash 
3186
3187 \emph on 
3188 <model>
3189 \newline 
3190 \SpecialChar ~
3191 \SpecialChar ~
3192 \SpecialChar ~
3193 \SpecialChar ~
3194 \SpecialChar ~
3195 \SpecialChar ~
3196 \SpecialChar ~
3197 \SpecialChar ~
3198 \SpecialChar ~
3199 \SpecialChar ~
3200 \SpecialChar ~
3201 \SpecialChar ~
3202 \SpecialChar ~
3203 \SpecialChar ~
3204 \SpecialChar ~
3205 \SpecialChar ~
3206 \SpecialChar ~
3207 \SpecialChar ~
3208 \SpecialChar ~
3209 \SpecialChar ~
3210 \SpecialChar ~
3211 \SpecialChar ~
3212 \SpecialChar ~
3213 \SpecialChar ~
3214 \SpecialChar ~
3215 \SpecialChar ~
3216 \SpecialChar ~
3217 \SpecialChar ~
3218 \SpecialChar ~
3219 \SpecialChar ~
3220 \SpecialChar ~
3221 \SpecialChar ~
3222 \SpecialChar ~
3223 \SpecialChar ~
3224 \SpecialChar ~
3225
3226 \end_inset 
3227 </cell>
3228 </row>
3229 <row topline="true" bottomline="true">
3230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3231 \begin_inset Text
3232
3233 \layout Standard
3234
3235
3236 \emph on 
3237 $DATADIR/
3238 \newline 
3239 $LIB_DIR_SUFFIX/<model>
3240 \end_inset 
3241 </cell>
3242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3243 \begin_inset Text
3244
3245 \layout Standard
3246
3247 /usr/local/share/sdcc/
3248 \newline 
3249 lib/
3250 \emph on 
3251 <model>
3252 \end_inset 
3253 </cell>
3254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3255 \begin_inset Text
3256
3257 \layout Standard
3258
3259 (not on Win32)
3260 \end_inset 
3261 </cell>
3262 </row>
3263 </lyxtabular>
3264
3265 \end_inset 
3266
3267
3268 \newline 
3269
3270 \layout Comment
3271
3272 Don't delete any of the stray spaces in the table above without checking
3273  the HTML output (last line)!
3274 \layout Standard
3275
3276 \SpecialChar ~
3277
3278 \newline 
3279 The option -
3280 \begin_inset ERT
3281 status Collapsed
3282
3283 \layout Standard
3284
3285 \backslash 
3286 /
3287 \end_inset 
3288
3289 -nostdlib disables the last two search paths.
3290 \layout Section
3291
3292 Building SDCC
3293 \begin_inset LatexCommand \index{Building SDCC}
3294
3295 \end_inset 
3296
3297
3298 \layout Subsection
3299
3300 Building SDCC on Linux
3301 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3302
3303 \end_inset 
3304
3305
3306 \layout Enumerate
3307
3308
3309 \series medium 
3310 Download the source package
3311 \series default 
3312  either from the SDCC Subversion repository or from the nightly snapshots
3313 \series medium 
3314 , it will be named something like sdcc
3315 \series default 
3316 .src
3317 \series medium 
3318 .t
3319 \series default 
3320 ar.
3321 \series medium 
3322 gz
3323 \series default 
3324  
3325 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3326
3327 \end_inset 
3328
3329 .
3330 \layout Enumerate
3331
3332
3333 \series medium 
3334 Bring up a command line terminal, such as xterm.
3335 \layout Enumerate
3336
3337
3338 \series medium 
3339 Unpack the file using a command like: 
3340 \family sans 
3341 \series bold 
3342 "tar -xvzf sdcc.src.tar.gz
3343 \family default 
3344 \series default 
3345 "
3346 \series medium 
3347 , this will create a sub-directory called sdcc with all of the sources.
3348 \layout Enumerate
3349
3350 Change directory into the main SDCC directory, for example type: 
3351 \family sans 
3352 \series bold 
3353 "cd sdcc
3354 \series default 
3355 ".
3356 \layout Enumerate
3357
3358
3359 \series medium 
3360 Type 
3361 \family sans 
3362 \series bold 
3363 "./configure
3364 \family default 
3365 \series default 
3366 ".
3367  This configures the package for compilation on your system.
3368 \layout Enumerate
3369
3370
3371 \series medium 
3372 Type 
3373 \family sans 
3374 \series bold 
3375 "make
3376 \family default 
3377 \series default 
3378 "
3379 \series medium 
3380 .
3381
3382 \series default 
3383  All of the source packages will compile, this can take a while.
3384 \layout Enumerate
3385
3386
3387 \series medium 
3388 Type 
3389 \family sans 
3390 \series bold 
3391 "make install"
3392 \family default 
3393 \series default 
3394  as root
3395 \series medium 
3396 .
3397
3398 \series default 
3399  This copies the binary executables, the include files, the libraries and
3400  the documentation to the install directories.
3401  Proceed with section 
3402 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3403
3404 \end_inset 
3405
3406 .
3407 \layout Subsection
3408
3409 Building SDCC on OSX 2.x
3410 \layout Standard
3411
3412 Follow the instruction for Linux.
3413 \newline 
3414
3415 \newline 
3416 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3417 )) fails to compile SDCC.
3418  Fortunately there's also gcc 2.9.x installed, which works fine.
3419  This compiler can be selected by running 'configure' with:
3420 \layout LyX-Code
3421
3422 ./configure CC=gcc2 CXX=g++2
3423 \layout Subsection
3424
3425 Cross compiling SDCC on Linux for Windows
3426 \layout Standard
3427
3428 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3429  See section 'Configure Options'.
3430 \layout Subsection
3431
3432 Building SDCC using Cygwin and Mingw32
3433 \layout Standard
3434
3435 For building and installing a Cygwin executable follow the instructions
3436  for Linux.
3437 \newline 
3438
3439 \newline 
3440 On Cygwin a 
3441 \begin_inset Quotes sld
3442 \end_inset 
3443
3444 native
3445 \begin_inset Quotes srd
3446 \end_inset 
3447
3448  Win32-binary can be built, which will not need the Cygwin-DLL.
3449  For the necessary 'configure' options see section 'configure options' or
3450  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3451 \newline 
3452
3453 \newline 
3454 In order to install Cygwin on Windows download setup.exe from 
3455 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3456
3457 \end_inset 
3458
3459 .
3460  Run it, set the 
3461 \begin_inset Quotes sld
3462 \end_inset 
3463
3464 default text file type
3465 \begin_inset Quotes srd
3466 \end_inset 
3467
3468  to 
3469 \begin_inset Quotes sld
3470 \end_inset 
3471
3472 unix
3473 \begin_inset Quotes srd
3474 \end_inset 
3475
3476  and download/install at least the following packages.
3477  Some packages are selected by default, others will be automatically selected
3478  because of dependencies with the manually selected packages.
3479  Never deselect these packages!
3480 \layout Itemize
3481
3482 flex
3483 \layout Itemize
3484
3485 bison
3486 \layout Itemize
3487
3488 gcc ; version 3.x is fine, no need to use the old 2.9x
3489 \layout Itemize
3490
3491 binutils ; selected with gcc
3492 \layout Itemize
3493
3494 make
3495 \layout Itemize
3496
3497 rxvt ; a nice console, which makes life much easier under windoze (see below)
3498 \layout Itemize
3499
3500 man ; not really needed for building SDCC, but you'll miss it sooner or
3501  later
3502 \layout Itemize
3503
3504 less ; not really needed for building SDCC, but you'll miss it sooner or
3505  later
3506 \layout Itemize
3507
3508 svn ; only if you use Subversion access
3509 \layout Standard
3510
3511 If you want to develop something you'll need:
3512 \layout Itemize
3513
3514 python ; for the regression tests
3515 \layout Itemize
3516
3517 gdb ; the gnu debugger, together with the nice GUI 
3518 \begin_inset Quotes sld
3519 \end_inset 
3520
3521 insight
3522 \begin_inset Quotes srd
3523 \end_inset 
3524
3525
3526 \layout Itemize
3527
3528 openssh ; to access the CF or commit changes
3529 \layout Itemize
3530
3531 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3532  use autoconf-stable!
3533 \layout Standard
3534
3535 rxvt is a nice console with history.
3536  Replace in your cygwin.bat the line
3537 \layout LyX-Code
3538
3539 bash -
3540 \begin_inset ERT
3541 status Collapsed
3542
3543 \layout Standard
3544
3545 \backslash 
3546 /
3547 \end_inset 
3548
3549 -login -i 
3550 \layout Standard
3551
3552 with (one line):
3553 \layout LyX-Code
3554
3555 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3556 \layout LyX-Code
3557
3558      -bg black -fg white -geometry 100x65 -e bash -
3559 \begin_inset ERT
3560 status Collapsed
3561
3562 \layout Standard
3563
3564 \backslash 
3565 /
3566 \end_inset 
3567
3568 -login
3569 \layout Standard
3570
3571 Text selected with the mouse is automatically copied to the clipboard, pasting
3572  works with shift-insert.
3573 \newline 
3574
3575 \newline 
3576 The other good tip is to make sure you have no //c/-style paths anywhere,
3577  use /cygdrive/c/ instead.
3578  Using // invokes a network lookup which is very slow.
3579  If you think 
3580 \begin_inset Quotes sld
3581 \end_inset 
3582
3583 cygdrive
3584 \begin_inset Quotes srd
3585 \end_inset 
3586
3587  is too long, you can change it with e.g.
3588 \layout LyX-Code
3589
3590 mount -s -u -c /mnt
3591 \layout Standard
3592
3593 SDCC sources use the unix line ending LF.
3594  Life is much easier, if you store the source tree on a drive which is mounted
3595  in binary mode.
3596  And use an editor which can handle LF-only line endings.
3597  Make sure not to commit files with windows line endings.
3598  The tabulator spacing
3599 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3600
3601 \end_inset 
3602
3603  used in the project is 8.
3604  Although a tabulator spacing of 8 is a sensible choice for programmers
3605  (it's a power of 2 and allows to display 8/16 bit signed variables without
3606  loosing columns) the plan is to move towards using only spaces in the source.
3607 \layout Subsection
3608
3609 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3610 \layout Standard
3611
3612
3613 \series medium 
3614 Download the source package
3615 \series default 
3616  either from the SDCC Subversion repository or from the 
3617 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3618
3619 \end_inset 
3620
3621
3622 \series medium 
3623 , it will be named something like sdcc
3624 \series default 
3625 .src
3626 \series medium 
3627 .tgz.
3628
3629 \series default 
3630  SDCC is distributed with all the projects, workspaces, and files you need
3631  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3632  The workspace name is 'sdcc.dsw'.
3633  Please note that as it is now, all the executables are created in a folder
3634  called sdcc
3635 \backslash 
3636 bin_vc.
3637  Once built you need to copy the executables from sdcc
3638 \backslash 
3639 bin_vc to sdcc
3640 \backslash 
3641 bin before running SDCC.
3642  
3643 \newline 
3644
3645 \newline 
3646 WARNING: Visual studio is very picky with line terminations; it expects
3647  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3648  When using the Subversion repository it's easiest to configure the svn
3649  client to convert automatically for you.
3650  If however you are getting a message such as "This makefile was not generated
3651  by Developer Studio etc.
3652  etc.
3653 \begin_inset Quotes srd
3654 \end_inset 
3655
3656  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3657  need to convert the Unix style line endings to DOS style line endings.
3658  To do so you can use the 
3659 \begin_inset Quotes sld
3660 \end_inset 
3661
3662 unix2dos
3663 \begin_inset Quotes srd
3664 \end_inset 
3665
3666  utility freely available on the internet.
3667  Doug Hawkins reported in the sdcc-user list that this works:
3668 \newline 
3669
3670 \newline 
3671 C:
3672 \backslash 
3673 Programming
3674 \backslash 
3675 SDCC> unix2dos sdcc.dsw
3676 \newline 
3677 C:
3678 \backslash 
3679 Programming
3680 \backslash 
3681 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3682 \newline 
3683
3684 \newline 
3685 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3686  flex.exe, and gawk.exe.
3687  One good place to get them is 
3688 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3689
3690 \end_inset 
3691
3692
3693 \newline 
3694
3695 \newline 
3696 Download the file UnxUtils
3697 \begin_inset LatexCommand \index{UnxUtils}
3698
3699 \end_inset 
3700
3701 .zip.
3702  Now you have to install the utilities and setup MSVC so it can locate the
3703  required programs.
3704  Here there are two alternatives (choose one!):
3705 \layout Enumerate
3706
3707 The easy way:
3708 \newline 
3709
3710 \newline 
3711 a) Extract UnxUtils.zip to your C:
3712 \backslash 
3713  hard disk PRESERVING the original paths, otherwise bison won't work.
3714  (If you are using WinZip make certain that 'Use folder names' is selected)
3715 \newline 
3716
3717 \newline 
3718 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3719  in 'Show directories for:' select 'Executable files', and in the directories
3720  window add a new path: 'C:
3721 \backslash 
3722 user
3723 \backslash 
3724 local
3725 \backslash 
3726 wbin', click ok.
3727 \newline 
3728
3729 \newline 
3730 (As a side effect, you get a bunch of Unix utilities that could be useful,
3731  such as diff and patch.)
3732 \layout Enumerate
3733
3734 A more compact way:
3735 \newline 
3736
3737 \newline 
3738 This one avoids extracting a bunch of files you may not use, but requires
3739  some extra work:
3740 \newline 
3741
3742 \newline 
3743 a) Create a directory were to put the tools needed, or use a directory already
3744  present.
3745  Say for example 'C:
3746 \backslash 
3747 util'.
3748 \newline 
3749
3750 \newline 
3751 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3752  to such directory WITHOUT preserving the original paths.
3753  (If you are using WinZip make certain that 'Use folder names' is not selected)
3754 \newline 
3755
3756 \newline 
3757 c) Rename bison.exe to '_bison.exe'.
3758 \newline 
3759
3760 \newline 
3761 d) Create a batch file 'bison.bat' in 'C:
3762 \backslash 
3763 util
3764 \backslash 
3765 ' and add these lines: 
3766 \newline 
3767 \SpecialChar ~
3768 \SpecialChar ~
3769 set BISON_SIMPLE=C:
3770 \backslash 
3771 util
3772 \backslash 
3773 bison.simple 
3774 \newline 
3775 \SpecialChar ~
3776 \SpecialChar ~
3777 set BISON_HAIRY=C:
3778 \backslash 
3779 util
3780 \backslash 
3781 bison.hairy
3782 \newline 
3783 \SpecialChar ~
3784 \SpecialChar ~
3785 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3786 \newline 
3787
3788 \newline 
3789 Steps 'c' and 'd' are needed because bison requires by default that the
3790  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3791  '/usr/local/share/' I think.
3792  So it is necessary to tell bison where those files are located if they
3793  are not in such directory.
3794  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3795 \newline 
3796
3797 \newline 
3798 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3799  in 'Show directories for:' select 'Executable files', and in the directories
3800  window add a new path: 'c:
3801 \backslash 
3802 util', click ok.
3803  Note that you can use any other path instead of 'c:
3804 \backslash 
3805 util', even the path where the Visual C++ tools are, probably: 'C:
3806 \backslash 
3807 Program Files
3808 \backslash 
3809 Microsoft Visual Studio
3810 \backslash 
3811 Common
3812 \backslash 
3813 Tools'.
3814  So you don't have to execute step 'e' :)
3815 \layout Standard
3816
3817 That is it.
3818  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3819  the executables from sdcc
3820 \backslash 
3821 bin_vc to sdcc
3822 \backslash 
3823 bin, and you can compile using SDCC.
3824 \layout Subsection
3825
3826 Building SDCC Using Borland
3827 \layout Enumerate
3828
3829 From the sdcc directory, run the command "make -f Makefile.bcc".
3830  This should regenerate all the .exe files in the bin directory except for
3831  SDCDB and ucSim.
3832 \layout Enumerate
3833
3834 If you modify any source files and need to rebuild, be aware that the dependenci
3835 es may not be correctly calculated.
3836  The safest option is to delete all .obj files and run the build again.
3837  From a Cygwin BASH prompt, this can easily be done with the command (be
3838  sure you are in the sdcc directory):
3839 \newline 
3840
3841 \newline 
3842
3843 \family sans 
3844 \series bold 
3845 find .
3846  
3847 \backslash 
3848 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3849 \backslash 
3850 ) -print -exec rm {} 
3851 \backslash 
3852 ;
3853 \family default 
3854 \series default 
3855
3856 \newline 
3857
3858 \newline 
3859 or on Windows NT/2000/XP from the command prompt with the command:
3860 \newline 
3861
3862 \family sans 
3863 \series bold 
3864
3865 \newline 
3866 del /s *.obj *.lib *.rul
3867 \family default 
3868 \series default 
3869  from the sdcc directory.
3870 \layout Subsection
3871
3872 Windows Install Using a ZIP Package
3873 \layout Enumerate
3874
3875 Download the binary zip package from 
3876 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3877
3878 \end_inset 
3879
3880  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3881  This should unpack to a group of sub-directories.
3882  An example directory structure after unpacking the mingw32 package is:
3883  c:
3884 \backslash 
3885 sdcc
3886 \backslash 
3887 bin for the executables, c:
3888 \backslash 
3889 sdcc
3890 \backslash 
3891 include and c:
3892 \backslash 
3893 sdcc
3894 \backslash 
3895 lib for the include and libraries.
3896 \layout Enumerate
3897
3898 Adjust your environment variable PATH to include the location of the bin
3899  directory or start sdcc using the full path.
3900 \layout Subsection
3901
3902 Windows Install Using the Setup Program
3903 \begin_inset LatexCommand \label{sub:Windows-Install}
3904
3905 \end_inset 
3906
3907
3908 \layout Standard
3909
3910 Download the setup program 
3911 \emph on 
3912 sdcc-x.y.z-setup.exe
3913 \emph default 
3914  for an official release from 
3915 \newline 
3916
3917 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3918
3919 \end_inset 
3920
3921  or a setup program for one of the snapshots 
3922 \emph on 
3923 sdcc-yyyymmdd-xxxx-setup.exe
3924 \emph default 
3925  from 
3926 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3927
3928 \end_inset 
3929
3930  and execute it.
3931  A windows typical installer will guide you through the installation process.
3932 \layout Subsection
3933
3934 VPATH
3935 \begin_inset LatexCommand \index{VPATH}
3936
3937 \end_inset 
3938
3939  feature
3940 \layout Standard
3941
3942 SDCC supports the VPATH feature provided by configure and make.
3943  It allows to separate the source and build trees.
3944  Here's an example:
3945 \layout Standard
3946
3947
3948 \family typewriter 
3949 cd ~\SpecialChar ~
3950 \SpecialChar ~
3951 \SpecialChar ~
3952 \SpecialChar ~
3953 \SpecialChar ~
3954 \SpecialChar ~
3955 \SpecialChar ~
3956 \SpecialChar ~
3957 \SpecialChar ~
3958 \SpecialChar ~
3959 \SpecialChar ~
3960 \SpecialChar ~
3961 \SpecialChar ~
3962 \SpecialChar ~
3963 \SpecialChar ~
3964 \SpecialChar ~
3965 \SpecialChar ~
3966 \SpecialChar ~
3967 \SpecialChar ~
3968 \SpecialChar ~
3969 \SpecialChar ~
3970 # cd $HOME
3971 \layout Standard
3972
3973
3974 \family typewriter 
3975 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3976 # extract source to directory sdcc
3977 \layout Standard
3978
3979
3980 \family typewriter 
3981 mkdir sdcc.build\SpecialChar ~
3982 \SpecialChar ~
3983 \SpecialChar ~
3984 \SpecialChar ~
3985 \SpecialChar ~
3986 \SpecialChar ~
3987 \SpecialChar ~
3988 \SpecialChar ~
3989 \SpecialChar ~
3990 # put output in sdcc.build
3991 \layout Standard
3992
3993
3994 \family typewriter 
3995 cd sdcc.build
3996 \layout Standard
3997
3998
3999 \family typewriter 
4000 ../sdcc/configure\SpecialChar ~
4001 \SpecialChar ~
4002 \SpecialChar ~
4003 \SpecialChar ~
4004 \SpecialChar ~
4005 \SpecialChar ~
4006 \SpecialChar ~
4007 \SpecialChar ~
4008 # configure is doing all the magic!
4009 \layout Standard
4010
4011
4012 \family typewriter 
4013 make
4014 \layout Standard
4015 \noindent 
4016 That's it! 
4017 \series bold 
4018 configure
4019 \series default 
4020  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4021  It automagically computes the variables srcdir, top_srcdir and top_buildir
4022  for each directory.
4023  After running 
4024 \series bold 
4025 make
4026 \series default 
4027  the generated files will be in ~/sdcc.build, while the source files stay
4028  in ~/sdcc.
4029 \newline 
4030 This is not only usefull for building different binaries, e.g.
4031  when cross compiling.
4032  It also gives you a much better overview in the source tree when all the
4033  generated files are not scattered between the source files.
4034  And the best thing is: if you want to change a file you can leave the original
4035  file untouched in the source directory.
4036  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4037  Makefile.dep` and `make`.
4038  
4039 \series bold 
4040 make
4041 \series default 
4042  will do the rest for you!
4043 \layout Section
4044
4045 Building the Documentation
4046 \layout Standard
4047
4048 Add -
4049 \begin_inset ERT
4050 status Collapsed
4051
4052 \layout Standard
4053
4054 \backslash 
4055 /
4056 \end_inset 
4057
4058 -enable-doc to the configure arguments to build the documentation together
4059  with all the other stuff.
4060  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4061  dvips and makeindex) to get the job done.
4062  Another possibility is to change to the doc directory and to type 
4063 \family sans 
4064 \series bold 
4065
4066 \begin_inset Quotes srd
4067 \end_inset 
4068
4069 make
4070 \begin_inset Quotes srd
4071 \end_inset 
4072
4073
4074 \family default 
4075 \series default 
4076  there.
4077  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4078 x).
4079  Using LyX 
4080 \begin_inset LatexCommand \url{http://www.lyx.org}
4081
4082 \end_inset 
4083
4084  as editor is straightforward.
4085  Prebuilt documentation in html and pdf format is available from 
4086 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4087
4088 \end_inset 
4089
4090 .
4091 \layout Section
4092
4093 Reading the Documentation
4094 \begin_inset LatexCommand \index{Documentation}
4095
4096 \end_inset 
4097
4098
4099 \layout Standard
4100
4101 Currently reading the document in pdf format is recommended, as for unknown
4102  reason the hyperlinks are working there whereas in the html version they
4103  are not
4104 \begin_inset Foot
4105 collapsed false
4106
4107 \layout Standard
4108
4109 If you should know why please drop us a note
4110 \end_inset 
4111
4112 .
4113  
4114 \newline 
4115 You'll find the pdf version
4116 \begin_inset LatexCommand \index{PDF version of this document}
4117
4118 \end_inset 
4119
4120  at 
4121 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4122
4123 \end_inset 
4124
4125 .
4126  
4127 \newline 
4128 A html version
4129 \begin_inset LatexCommand \index{HTML version of this document}
4130
4131 \end_inset 
4132
4133  should be online at 
4134 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4135
4136 \end_inset 
4137
4138 .
4139 \newline 
4140 This documentation is in some aspects different from a commercial documentation:
4141  
4142 \layout Itemize
4143
4144 It tries to document SDCC for several processor architectures in one document
4145  (commercially these probably would be separate documents/products).
4146  This document
4147 \begin_inset LatexCommand \index{Status of documentation}
4148
4149 \end_inset 
4150
4151  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4152 on about f.e.
4153  Z80, PIC14, PIC16 and HC08.
4154 \layout Itemize
4155
4156 There are many references pointing away from this documentation.
4157  Don't let this distract you.
4158  If there f.e.
4159  was a reference like 
4160 \begin_inset LatexCommand \url{http://www.opencores.org}
4161
4162 \end_inset 
4163
4164  together with a statement 
4165 \begin_inset Quotes sld
4166 \end_inset 
4167
4168 some processors which are targetted by SDCC can be implemented in a 
4169 \emph on 
4170 f
4171 \emph default 
4172 ield 
4173 \emph on 
4174 p
4175 \emph default 
4176 rogrammable 
4177 \emph on 
4178 g
4179 \emph default 
4180 ate 
4181 \emph on 
4182 a
4183 \emph default 
4184 rray
4185 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4186
4187 \end_inset 
4188
4189
4190 \begin_inset Quotes srd
4191 \end_inset 
4192
4193  or 
4194 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4195
4196 \end_inset 
4197
4198
4199 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4200
4201 \end_inset 
4202
4203  
4204 \begin_inset Quotes sld
4205 \end_inset 
4206
4207 have you ever heard of an open source compiler that compiles a subset of
4208  C for an FPGA?
4209 \begin_inset Quotes srd
4210 \end_inset 
4211
4212  we expect you to have a quick look there and come back.
4213  If you read this you are on the right track.
4214 \layout Itemize
4215
4216 Some sections attribute more space to problems, restrictions and warnings
4217  than to the solution.
4218 \layout Itemize
4219
4220 The installation section and the section about the debugger is intimidating.
4221 \layout Itemize
4222
4223 There are still lots of typos and there are more different writing styles
4224  than pictures.
4225 \layout Section
4226
4227 Testing the SDCC Compiler
4228 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4229
4230 \end_inset 
4231
4232
4233 \layout Standard
4234
4235 The first thing you should do after installing your SDCC compiler is to
4236  see if it runs.
4237  Type 
4238 \family sans 
4239 \series bold 
4240 "sdcc -
4241 \begin_inset ERT
4242 status Collapsed
4243
4244 \layout Standard
4245
4246 \backslash 
4247 /
4248 \end_inset 
4249
4250 -version"
4251 \begin_inset LatexCommand \index{version}
4252
4253 \end_inset 
4254
4255
4256 \family default 
4257 \series default 
4258  at the prompt, and the program should run and output its version like:
4259  
4260 \newline 
4261
4262 \family typewriter 
4263 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4264  (UNIX)
4265 \layout Standard
4266
4267 If it doesn't run, or gives a message about not finding sdcc program, then
4268  you need to check over your installation.
4269  Make sure that the sdcc bin directory is in your executable search path
4270  defined by the PATH environment setting (
4271 \series medium 
4272 see 
4273 \series default 
4274 section 
4275 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4276
4277 \end_inset 
4278
4279 \SpecialChar ~
4280
4281 \series medium 
4282 Install trouble-shooting for suggestions
4283 \series default 
4284 ).
4285  Make sure that the sdcc program is in the bin folder, if not perhaps something
4286  did not install correctly.
4287 \newline 
4288
4289 \newline 
4290
4291 \series medium 
4292 SDCC 
4293 \series default 
4294 is commonly installed as described in section 
4295 \begin_inset Quotes sld
4296 \end_inset 
4297
4298 Install and search paths
4299 \begin_inset Quotes srd
4300 \end_inset 
4301
4302 .
4303 \newline 
4304
4305 \newline 
4306
4307 \series medium 
4308 Make sure the compiler works on a very simple example.
4309  Type in the following test.c program using your favorite 
4310 \series default 
4311 ASCII 
4312 \series medium 
4313 editor:
4314 \layout Verse
4315
4316
4317 \family typewriter 
4318 char test;
4319 \newline 
4320
4321 \newline 
4322 void main(void) {
4323 \newline 
4324 \SpecialChar ~
4325 \SpecialChar ~
4326 \SpecialChar ~
4327 \SpecialChar ~
4328 test=0;
4329 \newline 
4330 }
4331 \layout Standard
4332
4333
4334 \series medium 
4335 Compile this using the following command: 
4336 \family sans 
4337 \series bold 
4338 "sdcc -c test.c".
4339
4340 \family default 
4341 \series default 
4342  
4343 \series medium 
4344 If all goes well, the compiler will generate a test.asm and test.rel file.
4345  Congratulations, you've just compiled your first program with SDCC.
4346  We used the -c option to tell SDCC not to link the generated code, just
4347  to keep things simple for this step.
4348 \series default 
4349
4350 \newline 
4351
4352 \newline 
4353
4354 \series medium 
4355 The next step is to try it with the linker.
4356  Type in 
4357 \family sans 
4358 \series bold 
4359 "sdcc test.c
4360 \family default 
4361 \series default 
4362 "
4363 \series medium 
4364 .
4365  If all goes well the compiler will link with the libraries and produce
4366  a test.ihx output file.
4367  If this step fails
4368 \series default 
4369  
4370 \series medium 
4371 (no test.ihx, and the linker generates warnings), then the problem is most
4372  likely that 
4373 \series default 
4374 SDCC
4375 \series medium 
4376  cannot find the 
4377 \series default 
4378 /
4379 \series medium 
4380 usr/local/share/sdcc/lib directory
4381 \series default 
4382  
4383 \series medium 
4384 (see 
4385 \series default 
4386 section 
4387 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4388
4389 \end_inset 
4390
4391 \SpecialChar ~
4392
4393 \series medium 
4394 Install trouble-shooting for suggestions).
4395 \series default 
4396
4397 \newline 
4398
4399 \newline 
4400
4401 \series medium 
4402 The final test is to ensure 
4403 \series default 
4404 SDCC
4405 \series medium 
4406  can use the 
4407 \series default 
4408 standard
4409 \series medium 
4410  header files and libraries.
4411  Edit test.c and change it to the following:
4412 \layout Verse
4413
4414
4415 \family typewriter 
4416 #include <string.h>
4417 \newline 
4418
4419 \newline 
4420 char str1[10];
4421 \newline 
4422
4423 \newline 
4424 void main(void) {
4425 \newline 
4426 \SpecialChar ~
4427 \SpecialChar ~
4428 strcpy(str1, "testing");
4429 \newline 
4430 }
4431 \layout Standard
4432
4433
4434 \series medium 
4435 Compile this by typing 
4436 \family sans 
4437 \series bold 
4438 "sdcc test.c"
4439 \family default 
4440 \series medium 
4441 .
4442  This should generate a test.ihx output file, and it should give no warnings
4443  such as not finding the string.h file.
4444  If it cannot find the string.h file, then the problem is that 
4445 \series default 
4446 SDCC
4447 \series medium 
4448  cannot find the /usr/local/share/sdcc/include directory
4449 \series default 
4450  
4451 \series medium 
4452 (see the 
4453 \series default 
4454 section 
4455 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4456
4457 \end_inset 
4458
4459 \SpecialChar ~
4460
4461 \series medium 
4462 Install trouble-shooting section for suggestions).
4463
4464 \series default 
4465  Use option 
4466 \series bold 
4467 -
4468 \begin_inset ERT
4469 status Collapsed
4470
4471 \layout Standard
4472
4473 \backslash 
4474 /
4475 \end_inset 
4476
4477 -print-search-dirs
4478 \series default 
4479
4480 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4481
4482 \end_inset 
4483
4484  to find exactly where SDCC is looking for the include and lib files.
4485 \layout Section
4486
4487 Install Trouble-shooting
4488 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4489
4490 \end_inset 
4491
4492
4493 \begin_inset LatexCommand \index{Install trouble-shooting}
4494
4495 \end_inset 
4496
4497
4498 \layout Subsection
4499
4500 If SDCC does not build correctly
4501 \layout Standard
4502
4503 A thing to try is starting from scratch by unpacking the .tgz source package
4504  again in an empty directory.
4505  Configure it like:
4506 \newline 
4507
4508 \newline 
4509
4510 \family sans 
4511 \series bold 
4512 ./configure 2>&1 | tee configure.log
4513 \family default 
4514 \series default 
4515
4516 \newline 
4517
4518 \newline 
4519 and build it like:
4520 \newline 
4521
4522 \newline 
4523
4524 \family sans 
4525 \series bold 
4526 make 2>&1 | tee make.log
4527 \family default 
4528 \series default 
4529
4530 \newline 
4531
4532 \newline 
4533 If anything goes wrong, you can review the log files to locate the problem.
4534  Or a relevant part of this can be attached to an email that could be helpful
4535  when requesting help from the mailing list.
4536 \layout Subsection
4537
4538 What the 
4539 \begin_inset Quotes sld
4540 \end_inset 
4541
4542 ./configure
4543 \begin_inset Quotes srd
4544 \end_inset 
4545
4546  does
4547 \layout Standard
4548
4549 The 
4550 \begin_inset Quotes sld
4551 \end_inset 
4552
4553 ./configure
4554 \begin_inset Quotes srd
4555 \end_inset 
4556
4557  command is a script that analyzes your system and performs some configuration
4558  to ensure the source package compiles on your system.
4559  It will take a few minutes to run, and will compile a few tests to determine
4560  what compiler features are installed.
4561 \layout Subsection
4562
4563 What the 
4564 \begin_inset Quotes sld
4565 \end_inset 
4566
4567 make
4568 \begin_inset Quotes srd
4569 \end_inset 
4570
4571  does
4572 \layout Standard
4573
4574 This runs the GNU make tool, which automatically compiles all the source
4575  packages into the final installed binary executables.
4576 \layout Subsection
4577
4578 What the 
4579 \begin_inset Quotes sld
4580 \end_inset 
4581
4582 make install
4583 \begin_inset Quotes erd
4584 \end_inset 
4585
4586  command does.
4587 \layout Standard
4588
4589 This will install the compiler, other executables libraries and include
4590  files into the appropriate directories.
4591  See sections 
4592 \begin_inset LatexCommand \ref{sub:Install-paths}
4593
4594 \end_inset 
4595
4596 ,\SpecialChar ~
4597
4598 \begin_inset LatexCommand \ref{sub:Search-Paths}
4599
4600 \end_inset 
4601
4602 \SpecialChar ~
4603 about install and search paths.
4604 \newline 
4605 On most systems you will need super-user privileges to do this.
4606 \layout Section
4607
4608 Components of SDCC
4609 \layout Standard
4610
4611 SDCC is not just a compiler, but a collection of tools by various developers.
4612  These include linkers, assemblers, simulators and other components.
4613  Here is a summary of some of the components.
4614  Note that the included simulator and assembler have separate documentation
4615  which you can find in the source package in their respective directories.
4616  As SDCC grows to include support for other processors, other packages from
4617  various developers are included and may have their own sets of documentation.
4618 \newline 
4619
4620 \newline 
4621 You might want to look at the files which are installed in <installdir>.
4622  At the time of this writing, we find the following programs for gcc-builds:
4623 \newline 
4624  
4625 \newline 
4626 In <installdir>/bin:
4627 \layout Itemize
4628
4629 sdcc - The compiler.
4630 \layout Itemize
4631
4632 sdcpp - The C preprocessor.
4633 \layout Itemize
4634
4635 asx8051 - The assembler for 8051 type processors.
4636 \layout Itemize
4637
4638 as-z80
4639 \series bold 
4640
4641 \series default 
4642 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4643 \layout Itemize
4644
4645 aslink -The linker for 8051 type processors.
4646 \layout Itemize
4647
4648 link-z80
4649 \series bold 
4650
4651 \series default 
4652 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4653 \layout Itemize
4654
4655 s51 - The ucSim 8051 simulator.
4656 \layout Itemize
4657
4658 sdcdb - The source debugger.
4659 \layout Itemize
4660
4661 packihx - A tool to pack (compress) Intel hex files.
4662 \layout Standard
4663
4664 In <installdir>/share/sdcc/include
4665 \layout Itemize
4666
4667 the include files
4668 \layout Standard
4669
4670 In <installdir>/share/sdcc/lib
4671 \layout Itemize
4672
4673 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4674  relocatables.
4675 \layout Standard
4676
4677 In <installdir>/share/sdcc/doc
4678 \layout Itemize
4679
4680 the documentation
4681 \layout Standard
4682
4683 As development for other processors proceeds, this list will expand to include
4684  executables to support processors like AVR, PIC, etc.
4685 \layout Subsection
4686
4687 sdcc - The Compiler
4688 \layout Standard
4689
4690 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4691  the assembler and linkage editor.
4692 \layout Subsection
4693
4694 sdcpp - The C-Preprocessor
4695 \layout Standard
4696
4697 The preprocessor
4698 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4699
4700 \end_inset 
4701
4702  is a modified version of the GNU cpp
4703 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4704
4705 \end_inset 
4706
4707  preprocessor 
4708 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4709
4710 \end_inset 
4711
4712 .
4713  The C preprocessor is used to pull in #include sources, process #ifdef
4714  statements, #defines and so on.
4715 \layout Subsection
4716
4717 as
4718 \emph on 
4719 xxxx
4720 \emph default 
4721 , aslink, link-
4722 \emph on 
4723 xxx
4724 \emph default 
4725  - The Assemblers and Linkage Editors
4726 \layout Standard
4727
4728 This is retargettable assembler & linkage editor, it was developed by Alan
4729  Baldwin.
4730  John Hartman created the version for 8051, and I (Sandeep) have made some
4731  enhancements and bug fixes for it to work properly with SDCC.
4732 \layout Subsection
4733
4734 s51 - The Simulator
4735 \layout Standard
4736
4737 S51
4738 \begin_inset LatexCommand \index{s51}
4739
4740 \end_inset 
4741
4742  is a freeware, opensource simulator developed by Daniel Drotos.
4743  The simulator is built as part of the build process.
4744  For more information visit Daniel's web site at: 
4745 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4746
4747 \end_inset 
4748
4749 .
4750  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4751  XA51 family.
4752 \layout Subsection
4753
4754 sdcdb - Source Level Debugger
4755 \layout Standard
4756
4757 SDCDB
4758 \begin_inset LatexCommand \index{SDCDB (debugger)}
4759
4760 \end_inset 
4761
4762  is the companion source level debugger.
4763  More about SDCDB in section 
4764 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4765
4766 \end_inset 
4767
4768 .
4769  The current version of the debugger uses Daniel's Simulator S51
4770 \begin_inset LatexCommand \index{s51}
4771
4772 \end_inset 
4773
4774 , but can be easily changed to use other simulators.
4775 \layout Chapter
4776
4777 Using SDCC
4778 \layout Section
4779
4780 Compiling
4781 \layout Subsection
4782
4783 Single Source File Projects
4784 \layout Standard
4785
4786 For single source file 8051 projects the process is very simple.
4787  Compile your programs with the following command 
4788 \family sans 
4789 \series bold 
4790 "sdcc sourcefile.c".
4791
4792 \family default 
4793 \series default 
4794  This will compile, assemble and link your source file.
4795  Output files are as follows:
4796 \layout Itemize
4797
4798 sourcefile.asm
4799 \begin_inset LatexCommand \index{<file>.asm}
4800
4801 \end_inset 
4802
4803  - Assembler source
4804 \begin_inset LatexCommand \index{Assembler source}
4805
4806 \end_inset 
4807
4808  file created by the compiler
4809 \layout Itemize
4810
4811 sourcefile.lst
4812 \begin_inset LatexCommand \index{<file>.lst}
4813
4814 \end_inset 
4815
4816  - Assembler listing
4817 \begin_inset LatexCommand \index{Assembler listing}
4818
4819 \end_inset 
4820
4821  file created by the Assembler
4822 \layout Itemize
4823
4824 sourcefile.rst
4825 \begin_inset LatexCommand \index{<file>.rst}
4826
4827 \end_inset 
4828
4829  - Assembler listing
4830 \begin_inset LatexCommand \index{Assembler listing}
4831
4832 \end_inset 
4833
4834  file updated with linkedit information, created by linkage editor
4835 \layout Itemize
4836
4837 sourcefile.sym
4838 \begin_inset LatexCommand \index{<file>.sym}
4839
4840 \end_inset 
4841
4842  - symbol listing
4843 \begin_inset LatexCommand \index{Symbol listing}
4844
4845 \end_inset 
4846
4847  for the sourcefile, created by the assembler
4848 \layout Itemize
4849
4850 sourcefile.rel
4851 \begin_inset LatexCommand \index{<file>.rel}
4852
4853 \end_inset 
4854
4855  or sourcefile.o
4856 \begin_inset LatexCommand \index{<file>.o}
4857
4858 \end_inset 
4859
4860  - Object file
4861 \begin_inset LatexCommand \index{Object file}
4862
4863 \end_inset 
4864
4865  created by the assembler, input to Linkage editor
4866 \layout Itemize
4867
4868 sourcefile.map
4869 \begin_inset LatexCommand \index{<file>.map}
4870
4871 \end_inset 
4872
4873  - The memory map
4874 \begin_inset LatexCommand \index{Memory map}
4875
4876 \end_inset 
4877
4878  for the load module, created by the Linker
4879 \layout Itemize
4880
4881 sourcefile.mem
4882 \begin_inset LatexCommand \index{<file>.mem}
4883
4884 \end_inset 
4885
4886  - A file with a summary of the memory usage
4887 \layout Itemize
4888
4889 sourcefile.ihx
4890 \begin_inset LatexCommand \index{<file>.ihx}
4891
4892 \end_inset 
4893
4894  - The load module in Intel hex format
4895 \begin_inset LatexCommand \index{Intel hex format}
4896
4897 \end_inset 
4898
4899  (you can select the Motorola S19 format
4900 \begin_inset LatexCommand \index{Motorola S19 format}
4901
4902 \end_inset 
4903
4904  with -
4905 \begin_inset ERT
4906 status Collapsed
4907
4908 \layout Standard
4909
4910 \backslash 
4911 /
4912 \end_inset 
4913
4914 -out-fmt-s19
4915 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4916
4917 \end_inset 
4918
4919 .
4920  If you need another format you might want to use 
4921 \family sans 
4922 \shape italic 
4923 objdump
4924 \family default 
4925 \shape default 
4926
4927 \begin_inset LatexCommand \index{objdump (tool)}
4928
4929 \end_inset 
4930
4931  or
4932 \family sans 
4933 \shape italic 
4934  srecord
4935 \family default 
4936 \shape default 
4937
4938 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4939
4940 \end_inset 
4941
4942 ).
4943  Both formats are documented in the documentation of srecord
4944 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4945
4946 \end_inset 
4947
4948
4949 \layout Itemize
4950
4951 sourcefile.adb
4952 \begin_inset LatexCommand \index{<file>.adb}
4953
4954 \end_inset 
4955
4956  - An intermediate file containing debug information needed to create the
4957  .cdb file (with -
4958 \begin_inset ERT
4959 status Collapsed
4960
4961 \layout Standard
4962
4963 \backslash 
4964 /
4965 \end_inset 
4966
4967 -debug
4968 \begin_inset LatexCommand \index{-\/-debug}
4969
4970 \end_inset 
4971
4972
4973 \layout Itemize
4974
4975 sourcefile.cdb
4976 \begin_inset LatexCommand \index{<file>.cdb}
4977
4978 \end_inset 
4979
4980  - An optional file (with -
4981 \begin_inset ERT
4982 status Collapsed
4983
4984 \layout Standard
4985
4986 \backslash 
4987 /
4988 \end_inset 
4989
4990 -debug) containing debug information.
4991  The format is documented in cdbfileformat.pdf
4992 \layout Itemize
4993
4994 sourcefile.
4995  - (no extension)
4996 \begin_inset LatexCommand \index{<file> (no extension)}
4997
4998 \end_inset 
4999
5000  An optional AOMF or AOMF51
5001 \begin_inset LatexCommand \index{AOMF, AOMF51}
5002
5003 \end_inset 
5004
5005  
5006 \begin_inset LatexCommand \label{OMF file}
5007
5008 \end_inset 
5009
5010 file containing debug information (generated with option -
5011 \begin_inset ERT
5012 status Collapsed
5013
5014 \layout Standard
5015
5016 \backslash 
5017 /
5018 \end_inset 
5019
5020 -debug).
5021  The (Intel)
5022 \emph on 
5023  a
5024 \emph default 
5025 bsolute 
5026 \emph on 
5027 o
5028 \emph default 
5029 bject 
5030 \emph on 
5031 m
5032 \emph default 
5033 odule 
5034 \emph on 
5035 f
5036 \emph default 
5037 ormat is commonly used by third party tools (debuggers
5038 \begin_inset LatexCommand \index{Debugger}
5039
5040 \end_inset 
5041
5042 , simulators, emulators)
5043 \layout Itemize
5044
5045 sourcefile.dump*
5046 \begin_inset LatexCommand \index{<file>.dump*}
5047
5048 \end_inset 
5049
5050  - Dump file to debug the compiler it self (generated with option -
5051 \begin_inset ERT
5052 status Collapsed
5053
5054 \layout Standard
5055
5056 \backslash 
5057 /
5058 \end_inset 
5059
5060 -dumpall) (see section 
5061 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5062
5063 \end_inset 
5064
5065 \SpecialChar ~
5066  and section 
5067 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5068
5069 \end_inset 
5070
5071 \SpecialChar ~
5072
5073 \begin_inset Quotes sld
5074 \end_inset 
5075
5076 Anatomy of the compiler
5077 \begin_inset Quotes srd
5078 \end_inset 
5079
5080 ).
5081 \layout Subsection
5082
5083 Postprocessing the Intel Hex
5084 \begin_inset LatexCommand \index{Intel hex format}
5085
5086 \end_inset 
5087
5088  file
5089 \layout Standard
5090
5091 In most cases this won't be needed but the Intel Hex file
5092 \begin_inset LatexCommand \index{<file>.ihx}
5093
5094 \end_inset 
5095
5096  which is generated by SDCC might include lines of varying length and the
5097  addresses within the file are not guaranteed to be strictly ascending.
5098  If your toolchain or a bootloader does not like this you can use the tool
5099  
5100 \family typewriter 
5101 packihx
5102 \family default 
5103
5104 \begin_inset LatexCommand \index{packihx (tool)}
5105
5106 \end_inset 
5107
5108  which is part of the SDCC distribution: 
5109 \newline 
5110
5111 \newline 
5112
5113 \family sans 
5114 \series bold 
5115  packihx sourcefile.ihx >sourcefile.hex
5116 \family default 
5117 \series default 
5118
5119 \newline 
5120
5121 \newline 
5122 The separately available
5123 \emph on 
5124  srecord
5125 \emph default 
5126
5127 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5128
5129 \end_inset 
5130
5131  package additionally allows to set undefined locations to a predefined
5132  value, to insert checksums
5133 \begin_inset LatexCommand \index{checksum}
5134
5135 \end_inset 
5136
5137  of various flavours (crc, add, xor) and to perform other manipulations
5138  (convert, split, crop, offset, ...).
5139  
5140 \newline 
5141
5142 \newline 
5143
5144 \family sans 
5145 \series bold 
5146 srec_cat\SpecialChar ~
5147 \SpecialChar ~
5148 sourcefile.ihx -intel\SpecialChar ~
5149 \SpecialChar ~
5150 -o sourcefile.hex -intel
5151 \newline 
5152
5153 \newline 
5154
5155 \family default 
5156 \series default 
5157 An example for a more complex command line
5158 \begin_inset Foot
5159 collapsed false
5160
5161 \layout Standard
5162
5163 the command backfills
5164 \begin_inset LatexCommand \index{backfill unused memory}
5165
5166 \end_inset 
5167
5168  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5169  block is zero.
5170  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5171  will be interpreted as an 
5172 \family typewriter 
5173 lcall
5174 \family default 
5175  to address 
5176 \family typewriter 
5177 0x1212
5178 \family default 
5179  (where an emergency routine could sit).
5180 \end_inset 
5181
5182  could look like:
5183 \newline 
5184
5185 \newline 
5186
5187 \family sans 
5188 \series bold 
5189 \size footnotesize 
5190 srec_cat\SpecialChar ~
5191 sourcefile.ihx -intel\SpecialChar ~
5192 \SpecialChar ~
5193 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5194 -little-endian-checksum-nega
5195 tive 0xfffe 0x02 0x02\SpecialChar ~
5196 \SpecialChar ~
5197 -o sourcefile.hex -intel
5198 \size default 
5199
5200 \newline 
5201
5202 \newline 
5203
5204 \family default 
5205 \series default 
5206 The srecord package is available at 
5207 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5208
5209 \end_inset 
5210
5211  .
5212 \layout Subsection
5213
5214 Projects with Multiple Source Files
5215 \layout Standard
5216
5217 SDCC can compile only ONE file at a time.
5218  Let us for example assume that you have a project containing the following
5219  files:
5220 \newline 
5221
5222 \newline 
5223 foo1.c (contains some functions)
5224 \newline 
5225 foo2.c (contains some more functions)
5226 \newline 
5227 foomain.c (contains more functions and the function main)
5228 \newline 
5229
5230 \size footnotesize 
5231
5232 \newline 
5233
5234 \size default 
5235 The first two files will need to be compiled separately with the commands:
5236 \size footnotesize 
5237  
5238 \size default 
5239
5240 \newline 
5241
5242 \newline 
5243
5244 \family sans 
5245 \series bold 
5246 sdcc\SpecialChar ~
5247 -c\SpecialChar ~
5248 foo1.c
5249 \family default 
5250 \series default 
5251 \size footnotesize 
5252
5253 \newline 
5254
5255 \family sans 
5256 \series bold 
5257 \size default 
5258 sdcc\SpecialChar ~
5259 -c\SpecialChar ~
5260 foo2.c
5261 \family default 
5262 \series default 
5263
5264 \newline 
5265
5266 \newline 
5267 Then compile the source file containing the 
5268 \emph on 
5269 main()
5270 \emph default 
5271  function and link
5272 \begin_inset LatexCommand \index{Linker}
5273
5274 \end_inset 
5275
5276  the files together with the following command: 
5277 \newline 
5278
5279 \newline 
5280
5281 \family sans 
5282 \series bold 
5283 sdcc\SpecialChar ~
5284 foomain.c\SpecialChar ~
5285 foo1.rel\SpecialChar ~
5286 foo2.rel
5287 \family default 
5288 \series default 
5289
5290 \begin_inset LatexCommand \index{<file>.rel}
5291
5292 \end_inset 
5293
5294
5295 \newline 
5296
5297 \newline 
5298 Alternatively, 
5299 \emph on 
5300 foomain.c 
5301 \emph default 
5302 can be separately compiled as well: 
5303 \family sans 
5304 \series bold 
5305
5306 \newline 
5307
5308 \newline 
5309 sdcc\SpecialChar ~
5310 -c\SpecialChar ~
5311 foomain.c
5312 \newline 
5313 sdcc foomain.rel foo1.rel foo2.rel
5314 \newline 
5315
5316 \newline 
5317
5318 \family default 
5319 \series default 
5320 The file containing the 
5321 \emph on 
5322 main()
5323 \emph default 
5324  function
5325 \emph on 
5326  
5327 \emph default 
5328 \noun on 
5329 must
5330 \noun default 
5331  be the 
5332 \noun on 
5333 first
5334 \noun default 
5335  file specified in the command line, since the linkage editor processes
5336  file in the order they are presented to it.
5337  The linker is invoked from SDCC using a script file with extension .lnk
5338 \begin_inset LatexCommand \index{<file>.lnk}
5339
5340 \end_inset 
5341
5342 .
5343  You can view this file to troubleshoot linking problems such as those arising
5344  from missing libraries.
5345 \layout Subsection
5346
5347 Projects with Additional Libraries
5348 \begin_inset LatexCommand \index{Libraries}
5349
5350 \end_inset 
5351
5352
5353 \layout Standard
5354
5355 Some reusable routines may be compiled into a library, see the documentation
5356  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5357  for how to create a 
5358 \emph on 
5359 .lib
5360 \begin_inset LatexCommand \index{<file>.lib}
5361
5362 \end_inset 
5363
5364
5365 \emph default 
5366  library file.
5367  Libraries created in this manner can be included in the command line.
5368  Make sure you include the -L <library-path> option to tell the linker where
5369  to look for these files if they are not in the current directory.
5370  Here is an example, assuming you have the source file 
5371 \emph on 
5372 foomain.c
5373 \emph default 
5374  and a library
5375 \emph on 
5376  foolib.lib
5377 \emph default 
5378  in the directory 
5379 \emph on 
5380 mylib
5381 \emph default 
5382  (if that is not the same as your current project):
5383 \newline 
5384
5385 \newline 
5386
5387 \family sans 
5388 \series bold 
5389 sdcc foomain.c foolib.lib -L mylib
5390 \newline 
5391
5392 \newline 
5393
5394 \family default 
5395 \series default 
5396 Note here that
5397 \emph on 
5398  mylib
5399 \emph default 
5400  must be an absolute path name.
5401 \newline 
5402
5403 \newline 
5404 The most efficient way to use libraries is to keep separate modules in separate
5405  source files.
5406  The lib file now should name all the modules.rel
5407 \begin_inset LatexCommand \index{<file>.rel}
5408
5409 \end_inset 
5410
5411  files.
5412  For an example see the standard library file 
5413 \emph on 
5414 libsdcc.lib
5415 \emph default 
5416  in the directory <installdir>/share/lib/small.
5417 \layout Subsection
5418
5419 Using sdcclib to Create and Manage Libraries
5420 \begin_inset LatexCommand \index{sdcclib}
5421
5422 \end_inset 
5423
5424
5425 \layout Standard
5426
5427 Alternatively, instead of having a .rel file for each entry on the library
5428  file as described in the preceding section, sdcclib can be used to embed
5429  all the modules belonging to such library in the library file itself.
5430  This results in a larger library file, but it greatly reduces the number
5431  of disk files accessed by the linker.
5432   Additionally, the packed library file contains an index of all include
5433  modules and symbols that significantly speeds up the linking process.
5434  To display a list of options supported by sdcclib type:
5435 \newline 
5436
5437 \layout Standard
5438
5439
5440 \family sans 
5441 \series bold 
5442 sdcclib -?
5443 \begin_inset LatexCommand \index{sdcclib}
5444
5445 \end_inset 
5446
5447
5448 \newline 
5449
5450 \newline 
5451
5452 \family default 
5453 \series default 
5454 To create a new library file, start by compiling all the required modules.
5455  For example:
5456 \newline 
5457
5458 \layout Standard
5459
5460
5461 \family sans 
5462 \series bold 
5463 sdcc -c _divsint.c
5464 \layout Standard
5465
5466
5467 \family sans 
5468 \series bold 
5469 sdcc -c _divuint.c
5470 \layout Standard
5471
5472
5473 \family sans 
5474 \series bold 
5475 sdcc -c _modsint.c
5476 \layout Standard
5477
5478
5479 \family sans 
5480 \series bold 
5481 sdcc -c _moduint.c
5482 \layout Standard
5483
5484
5485 \family sans 
5486 \series bold 
5487 sdcc -c _mulint.c
5488 \newline 
5489
5490 \layout Standard
5491
5492 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5493  and _mulint.rel.
5494  The next step is to add the .rel files to the library file:
5495 \newline 
5496
5497 \layout Standard
5498
5499
5500 \family sans 
5501 \series bold 
5502 sdcclib libint.lib _divsint.rel
5503 \family default 
5504
5505 \begin_inset LatexCommand \index{sdcclib}
5506
5507 \end_inset 
5508
5509
5510 \layout Standard
5511
5512
5513 \family sans 
5514 \series bold 
5515 sdcclib libint.lib _divuint.rel
5516 \layout Standard
5517
5518
5519 \family sans 
5520 \series bold 
5521 sdcclib libint.lib _modsint.rel
5522 \layout Standard
5523
5524
5525 \family sans 
5526 \series bold 
5527 sdcclib libint.lib _moduint.rel
5528 \layout Standard
5529
5530
5531 \family sans 
5532 \series bold 
5533 sdcclib libint.lib _mulint.rel
5534 \series default 
5535
5536 \newline 
5537
5538 \layout Standard
5539
5540 If the file already exists in the library, it will be replaced.
5541  To see what modules and symbols are included in the library, options -s
5542  and -m are available.
5543  For example:
5544 \newline 
5545
5546 \newline 
5547
5548 \family sans 
5549 \series bold 
5550 sdcclib -s libint.lib
5551 \family default 
5552
5553 \begin_inset LatexCommand \index{sdcclib}
5554
5555 \end_inset 
5556
5557
5558 \newline 
5559
5560 \family typewriter 
5561 \series default 
5562 _divsint.rel:
5563 \layout Standard
5564
5565
5566 \family typewriter 
5567 __divsint_a_1_1
5568 \layout Standard
5569
5570
5571 \family typewriter 
5572 __divsint_PARM_2
5573 \layout Standard
5574
5575
5576 \family typewriter 
5577 __divsint
5578 \newline 
5579 _divuint.rel:
5580 \layout Standard
5581
5582
5583 \family typewriter 
5584 __divuint_a_1_1
5585 \layout Standard
5586
5587
5588 \family typewriter 
5589 __divuint_PARM_2
5590 \layout Standard
5591
5592
5593 \family typewriter 
5594 __divuint_reste_1_1
5595 \layout Standard
5596
5597
5598 \family typewriter 
5599 __divuint_count_1_1
5600 \layout Standard
5601
5602
5603 \family typewriter 
5604 __divuint
5605 \newline 
5606 _modsint.rel:
5607 \layout Standard
5608
5609
5610 \family typewriter 
5611 __modsint_a_1_1
5612 \layout Standard
5613
5614
5615 \family typewriter 
5616 __modsint_PARM_2
5617 \layout Standard
5618
5619
5620 \family typewriter 
5621 __modsint
5622 \newline 
5623 _moduint.rel:
5624 \layout Standard
5625
5626
5627 \family typewriter 
5628 __moduint_a_1_1
5629 \layout Standard
5630
5631
5632 \family typewriter 
5633 __moduint_PARM_2
5634 \layout Standard
5635
5636
5637 \family typewriter 
5638 __moduint_count_1_1
5639 \layout Standard
5640
5641
5642 \family typewriter 
5643 __moduint
5644 \newline 
5645 _mulint.rel:
5646 \layout Standard
5647
5648
5649 \family typewriter 
5650 __mulint_PARM_2
5651 \layout Standard
5652
5653
5654 \family typewriter 
5655 __mulint
5656 \family default 
5657 \series bold 
5658
5659 \newline 
5660
5661 \layout Standard
5662 \added_space_bottom bigskip 
5663 If the source files are compiled using -
5664 \begin_inset ERT
5665 status Collapsed
5666
5667 \layout Standard
5668
5669 \backslash 
5670 /
5671 \end_inset 
5672
5673 -debug
5674 \begin_inset LatexCommand \index{-\/-debug}
5675
5676 \end_inset 
5677
5678 , the corresponding debug information file .adb will be include in the library
5679  file as well.
5680  The library files created with sdcclib are plain text files, so they can
5681  be viewed with a text editor.
5682  It is not recomended to modify a library file created with sdcclib using
5683  a text editor, as there are file indexes numbers located accross the file
5684  used by the linker to quickly locate the required module to link.
5685  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5686  it can be safely deleted, since all the information required for linking
5687  is embedded in the library file itself.
5688  Library files created using sdcclib are used as described in the preceding
5689  sections.
5690 \layout Section
5691
5692 Command Line Options
5693 \begin_inset LatexCommand \index{Command Line Options}
5694
5695 \end_inset 
5696
5697
5698 \layout Subsection
5699
5700 Processor Selection Options
5701 \begin_inset LatexCommand \index{Options processor selection}
5702
5703 \end_inset 
5704
5705
5706 \begin_inset LatexCommand \index{Processor selection options}
5707
5708 \end_inset 
5709
5710
5711 \layout List
5712 \labelwidthstring 00.00.0000
5713
5714
5715 \series bold 
5716 -mmcs51
5717 \begin_inset LatexCommand \index{-mmcs51}
5718
5719 \end_inset 
5720
5721
5722 \series default 
5723  Generate code for the Intel MCS51
5724 \begin_inset LatexCommand \index{MCS51}
5725
5726 \end_inset 
5727
5728  family of processors.
5729  This is the default processor target.
5730 \layout List
5731 \labelwidthstring 00.00.0000
5732
5733
5734 \series bold 
5735 -mds390
5736 \begin_inset LatexCommand \index{-mds390}
5737
5738 \end_inset 
5739
5740
5741 \series default 
5742  Generate code for the Dallas DS80C390
5743 \begin_inset LatexCommand \index{DS80C390}
5744
5745 \end_inset 
5746
5747  processor.
5748 \layout List
5749 \labelwidthstring 00.00.0000
5750
5751
5752 \series bold 
5753 -mds400
5754 \begin_inset LatexCommand \index{-mds400}
5755
5756 \end_inset 
5757
5758
5759 \series default 
5760  Generate code for the Dallas DS80C400
5761 \begin_inset LatexCommand \index{DS80C400}
5762
5763 \end_inset 
5764
5765  processor.
5766 \layout List
5767 \labelwidthstring 00.00.0000
5768
5769
5770 \series bold 
5771 -mhc08
5772 \begin_inset LatexCommand \index{-mhc08}
5773
5774 \end_inset 
5775
5776
5777 \series default 
5778  Generate code for the Freescale/Motorola HC08
5779 \begin_inset LatexCommand \index{HC08}
5780
5781 \end_inset 
5782
5783  family of processors.
5784 \layout List
5785 \labelwidthstring 00.00.0000
5786
5787
5788 \series bold 
5789 -mz80
5790 \begin_inset LatexCommand \index{-mz80}
5791
5792 \end_inset 
5793
5794
5795 \series default 
5796  Generate code for the Zilog Z80
5797 \begin_inset LatexCommand \index{Z80}
5798
5799 \end_inset 
5800
5801  family of processors.
5802 \layout List
5803 \labelwidthstring 00.00.0000
5804
5805
5806 \series bold 
5807 -mgbz80
5808 \begin_inset LatexCommand \index{-mgbz80}
5809
5810 \end_inset 
5811
5812
5813 \series default 
5814  Generate code for the GameBoy Z80
5815 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5816
5817 \end_inset 
5818
5819  processor (Not actively maintained).
5820 \layout List
5821 \labelwidthstring 00.00.0000
5822
5823
5824 \series bold 
5825 -mavr
5826 \begin_inset LatexCommand \index{-mavr}
5827
5828 \end_inset 
5829
5830
5831 \series default 
5832  Generate code for the Atmel AVR
5833 \begin_inset LatexCommand \index{AVR}
5834
5835 \end_inset 
5836
5837  processor (Not maintained, not complete).
5838  AVR users should probably have a look at winavr 
5839 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5840
5841 \end_inset 
5842
5843  or 
5844 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5845
5846 \end_inset 
5847
5848 .
5849 \layout Comment
5850
5851 I think it is fair to direct users there for now.
5852  Open source is also about avoiding unnecessary work .
5853  But I didn't find the 'official' link.
5854 \layout List
5855 \labelwidthstring 00.00.0000
5856
5857
5858 \series bold 
5859 -mpic14
5860 \begin_inset LatexCommand \index{-mpic14}
5861
5862 \end_inset 
5863
5864
5865 \series default 
5866  Generate code for the Microchip PIC 14
5867 \begin_inset LatexCommand \index{PIC14}
5868
5869 \end_inset 
5870
5871 -bit processors (p16f84 and variants.
5872  In development, not complete).
5873 \layout Comment
5874
5875 p16f627 p16f628 p16f84 p16f873 p16f877?
5876 \layout List
5877 \labelwidthstring 00.00.0000
5878
5879
5880 \series bold 
5881 -mpic16
5882 \begin_inset LatexCommand \index{-mpic16}
5883
5884 \end_inset 
5885
5886
5887 \series default 
5888  Generate code for the Microchip PIC 16
5889 \begin_inset LatexCommand \index{PIC16}
5890
5891 \end_inset 
5892
5893 -bit processors (p18f452 and variants.
5894  In development, not complete).
5895 \layout List
5896 \labelwidthstring 00.00.0000
5897
5898
5899 \series bold 
5900 -mtlcs900h
5901 \series default 
5902  Generate code for the Toshiba TLCS-900H
5903 \begin_inset LatexCommand \index{TLCS-900H}
5904
5905 \end_inset 
5906
5907  processor (Not maintained, not complete).
5908 \layout List
5909 \added_space_bottom bigskip \labelwidthstring 00.00.0000
5910
5911
5912 \series bold 
5913 -mxa51
5914 \begin_inset LatexCommand \index{-mxa51}
5915
5916 \end_inset 
5917
5918
5919 \series default 
5920  Generate code for the Phillips XA51
5921 \begin_inset LatexCommand \index{XA51}
5922
5923 \end_inset 
5924
5925  processor (Not maintained, not complete).
5926 \layout Subsection
5927
5928 Preprocessor Options
5929 \begin_inset LatexCommand \index{Options preprocessor}
5930
5931 \end_inset 
5932
5933
5934 \begin_inset LatexCommand \index{Preprocessor options}
5935
5936 \end_inset 
5937
5938
5939 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5940
5941 \end_inset 
5942
5943
5944 \layout List
5945 \labelwidthstring 00.00.0000
5946
5947
5948 \series bold 
5949 -I<path>
5950 \begin_inset LatexCommand \index{-I<path>}
5951
5952 \end_inset 
5953
5954
5955 \series default 
5956  The additional location where the pre processor will look for <..h> or 
5957 \begin_inset Quotes eld
5958 \end_inset 
5959
5960 ..h
5961 \begin_inset Quotes erd
5962 \end_inset 
5963
5964  files.
5965 \layout List
5966 \labelwidthstring 00.00.0000
5967
5968
5969 \series bold 
5970 -D<macro[=value]>
5971 \begin_inset LatexCommand \index{-D<macro[=value]>}
5972
5973 \end_inset 
5974
5975
5976 \series default 
5977  Command line definition of macros.
5978  Passed to the preprocessor.
5979 \layout List
5980 \labelwidthstring 00.00.0000
5981
5982
5983 \series bold 
5984 -M
5985 \begin_inset LatexCommand \index{-M}
5986
5987 \end_inset 
5988
5989
5990 \series default 
5991  Tell the preprocessor to output a rule suitable for make describing the
5992  dependencies of each object file.
5993  For each source file, the preprocessor outputs one make-rule whose target
5994  is the object file name for that source file and whose dependencies are
5995  all the files `#include'd in it.
5996  This rule may be a single line or may be continued with `
5997 \backslash 
5998 '-newline if it is long.
5999  The list of rules is printed on standard output instead of the preprocessed
6000  C program.
6001  `-M' implies `-E
6002 \begin_inset LatexCommand \index{-E}
6003
6004 \end_inset 
6005
6006 '.
6007 \layout List
6008 \labelwidthstring 00.00.0000
6009
6010
6011 \series bold 
6012 -C
6013 \begin_inset LatexCommand \index{-C}
6014
6015 \end_inset 
6016
6017
6018 \series default 
6019  Tell the preprocessor not to discard comments.
6020  Used with the `-E' option.
6021 \layout List
6022 \labelwidthstring 00.00.0000
6023
6024
6025 \series bold 
6026 -MM
6027 \begin_inset LatexCommand \index{-MM}
6028
6029 \end_inset 
6030
6031
6032 \size large 
6033 \bar under 
6034  
6035 \series default 
6036 \size default 
6037 \bar default 
6038 Like `-M' but the output mentions only the user header files included with
6039  `#include 
6040 \begin_inset Quotes eld
6041 \end_inset 
6042
6043 file"'.
6044  System header files included with `#include <file>' are omitted.
6045 \layout List
6046 \labelwidthstring 00.00.0000
6047
6048
6049 \series bold 
6050 -Aquestion(answer)
6051 \begin_inset LatexCommand \index{-Aquestion(answer)}
6052
6053 \end_inset 
6054
6055
6056 \series default 
6057  Assert the answer answer for question, in case it is tested with a preprocessor
6058  conditional such as `#if #question(answer)'.
6059  `-A-' disables the standard assertions that normally describe the target
6060  machine.
6061 \layout List
6062 \labelwidthstring 00.00.0000
6063
6064
6065 \series bold 
6066 -Umacro
6067 \begin_inset LatexCommand \index{-Umacro}
6068
6069 \end_inset 
6070
6071
6072 \series default 
6073  Undefine macro macro.
6074  `-U' options are evaluated after all `-D' options, but before any `-include'
6075  and `-imacros' options.
6076 \layout List
6077 \labelwidthstring 00.00.0000
6078
6079
6080 \series bold 
6081 -dM
6082 \begin_inset LatexCommand \index{-dM}
6083
6084 \end_inset 
6085
6086
6087 \series default 
6088  Tell the preprocessor to output only a list of the macro definitions that
6089  are in effect at the end of preprocessing.
6090  Used with the `-E' option.
6091 \layout List
6092 \labelwidthstring 00.00.0000
6093
6094
6095 \series bold 
6096 -dD
6097 \begin_inset LatexCommand \index{-dD}
6098
6099 \end_inset 
6100
6101
6102 \series default 
6103  Tell the preprocessor to pass all macro definitions into the output, in
6104  their proper sequence in the rest of the output.
6105 \layout List
6106 \labelwidthstring 00.00.0000
6107
6108
6109 \series bold 
6110 -dN
6111 \begin_inset LatexCommand \index{-dN}
6112
6113 \end_inset 
6114
6115
6116 \size large 
6117 \bar under 
6118  
6119 \series default 
6120 \size default 
6121 \bar default 
6122 Like `-dD' except that the macro arguments and contents are omitted.
6123  Only `#define name' is included in the output.
6124 \layout List
6125 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6126
6127
6128 \series bold 
6129 -Wp\SpecialChar ~
6130 preprocessorOption[,preprocessorOption]
6131 \series default 
6132
6133 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6134
6135 \end_inset 
6136
6137 ...
6138  Pass the preprocessorOption to the preprocessor 
6139 \family typewriter 
6140 sdcpp
6141 \family default 
6142
6143 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6144
6145 \end_inset 
6146
6147 .
6148  SDCC uses an adapted version of the preprocessor 
6149 \emph on 
6150 cpp
6151 \emph default 
6152  of the GNU Compiler Collection
6153 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6154
6155 \end_inset 
6156
6157  (
6158 \emph on 
6159 gcc
6160 \emph default 
6161  
6162 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6163
6164 \end_inset 
6165
6166 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6167 3.3.6\SpecialChar ~
6168 CPP\SpecialChar ~
6169 Manual
6170  at 
6171 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6172
6173 \end_inset 
6174
6175 .
6176 \layout Subsection
6177
6178 Linker Options
6179 \begin_inset LatexCommand \index{Options linker}
6180
6181 \end_inset 
6182
6183
6184 \begin_inset LatexCommand \index{Linker options}
6185
6186 \end_inset 
6187
6188
6189 \layout List
6190 \labelwidthstring 00.00.0000
6191
6192
6193 \series bold 
6194 -L\SpecialChar ~
6195 -
6196 \series default 
6197
6198 \begin_inset ERT
6199 status Collapsed
6200
6201 \layout Standard
6202
6203 \backslash 
6204 /
6205 \end_inset 
6206
6207
6208 \series bold 
6209 -lib-path
6210 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6211
6212 \end_inset 
6213
6214
6215 \begin_inset LatexCommand \index{-L -\/-lib-path}
6216
6217 \end_inset 
6218
6219
6220 \series default 
6221 \SpecialChar ~
6222 <absolute path to additional libraries> This option is passed to the linkage
6223  editor's additional libraries
6224 \begin_inset LatexCommand \index{Libraries}
6225
6226 \end_inset 
6227
6228  search path.
6229  The path name must be absolute.
6230  Additional library files may be specified in the command line.
6231  See section Compiling programs for more details.
6232 \layout List
6233 \labelwidthstring 00.00.0000
6234
6235
6236 \series bold 
6237 -
6238 \begin_inset ERT
6239 status Collapsed
6240
6241 \layout Standard
6242
6243 \backslash 
6244 /
6245 \end_inset 
6246
6247 -xram-loc
6248 \series default 
6249
6250 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6251
6252 \end_inset 
6253
6254 \SpecialChar ~
6255 <Value> The start location of the external ram
6256 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6257
6258 \end_inset 
6259
6260 , default value is 0.
6261  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6262 \begin_inset ERT
6263 status Collapsed
6264
6265 \layout Standard
6266
6267 \backslash 
6268 /
6269 \end_inset 
6270
6271 -xram-loc 0x8000 or -
6272 \begin_inset ERT
6273 status Collapsed
6274
6275 \layout Standard
6276
6277 \backslash 
6278 /
6279 \end_inset 
6280
6281 -xram-loc 32768.
6282 \layout List
6283 \labelwidthstring 00.00.0000
6284
6285
6286 \series bold 
6287 -
6288 \begin_inset ERT
6289 status Collapsed
6290
6291 \layout Standard
6292
6293 \backslash 
6294 /
6295 \end_inset 
6296
6297 -code-loc
6298 \series default 
6299
6300 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6301
6302 \end_inset 
6303
6304 \SpecialChar ~
6305 <Value> The start location of the code
6306 \begin_inset LatexCommand \index{code}
6307
6308 \end_inset 
6309
6310  segment, default value 0.
6311  Note when this option is used the interrupt vector table
6312 \begin_inset LatexCommand \index{interrupt vector table}
6313
6314 \end_inset 
6315
6316  is also relocated to the given address.
6317  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6318 \begin_inset ERT
6319 status Collapsed
6320
6321 \layout Standard
6322
6323 \backslash 
6324 /
6325 \end_inset 
6326
6327 -code-loc 0x8000 or -
6328 \begin_inset ERT
6329 status Collapsed
6330
6331 \layout Standard
6332
6333 \backslash 
6334 /
6335 \end_inset 
6336
6337 -code-loc 32768.
6338 \layout List
6339 \labelwidthstring 00.00.0000
6340
6341
6342 \series bold 
6343 -
6344 \begin_inset ERT
6345 status Collapsed
6346
6347 \layout Standard
6348
6349 \backslash 
6350 /
6351 \end_inset 
6352
6353 -stack-loc
6354 \series default 
6355
6356 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6357
6358 \end_inset 
6359
6360 \SpecialChar ~
6361 <Value> By default the stack
6362 \begin_inset LatexCommand \index{stack}
6363
6364 \end_inset 
6365
6366  is placed after the data segment.
6367  Using this option the stack can be placed anywhere in the internal memory
6368  space of the 8051.
6369  The value entered can be in Hexadecimal or Decimal format, e.g.
6370  -
6371 \begin_inset ERT
6372 status Collapsed
6373
6374 \layout Standard
6375
6376 \backslash 
6377 /
6378 \end_inset 
6379
6380 -stack-loc 0x20 or -
6381 \begin_inset ERT
6382 status Collapsed
6383
6384 \layout Standard
6385
6386 \backslash 
6387 /
6388 \end_inset 
6389
6390 -stack-loc 32.
6391  Since the sp register is incremented before a push or call, the initial
6392  sp will be set to one byte prior the provided value.
6393  The provided value should not overlap any other memory areas such as used
6394  register banks or the data segment and with enough space for the current
6395  application.
6396  The 
6397 \series bold 
6398 -
6399 \begin_inset ERT
6400 status Collapsed
6401
6402 \layout Standard
6403
6404 \backslash 
6405 /
6406 \end_inset 
6407
6408 -pack-iram
6409 \series default 
6410 \SpecialChar ~
6411
6412 \begin_inset LatexCommand \index{-\/-pack-iram}
6413
6414 \end_inset 
6415
6416  option (which is now a default setting) will override this setting, so
6417  you should also specify the 
6418 \series bold 
6419 -
6420 \begin_inset ERT
6421 status Collapsed
6422
6423 \layout Standard
6424
6425 \backslash 
6426 /
6427 \end_inset 
6428
6429 -no-pack-iram
6430 \series default 
6431 \SpecialChar ~
6432
6433 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6434
6435 \end_inset 
6436
6437  option if you need to manually place the stack.
6438 \layout List
6439 \labelwidthstring 00.00.0000
6440
6441
6442 \series bold 
6443 -
6444 \begin_inset ERT
6445 status Collapsed
6446
6447 \layout Standard
6448
6449 \backslash 
6450 /
6451 \end_inset 
6452
6453 -xstack-loc
6454 \series default 
6455
6456 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6457
6458 \end_inset 
6459
6460 \SpecialChar ~
6461 <Value> By default the external stack
6462 \begin_inset LatexCommand \index{xstack}
6463
6464 \end_inset 
6465
6466  is placed after the pdata
6467 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6468
6469 \end_inset 
6470
6471  segment.
6472  Using this option the xstack can be placed anywhere in the external memory
6473  space of the 8051.
6474  The value entered can be in Hexadecimal or Decimal format, e.g.
6475  -
6476 \begin_inset ERT
6477 status Collapsed
6478
6479 \layout Standard
6480
6481 \backslash 
6482 /
6483 \end_inset 
6484
6485 -xstack-loc 0x8000 or -
6486 \begin_inset ERT
6487 status Collapsed
6488
6489 \layout Standard
6490
6491 \backslash 
6492 /
6493 \end_inset 
6494
6495 -stack-loc 32768.
6496  The provided value should not overlap any other memory areas such as the
6497  pdata or xdata segment and with enough space for the current application.
6498 \layout List
6499 \labelwidthstring 00.00.0000
6500
6501
6502 \series bold 
6503 -
6504 \begin_inset ERT
6505 status Collapsed
6506
6507 \layout Standard
6508
6509 \backslash 
6510 /
6511 \end_inset 
6512
6513 -data-loc
6514 \series default 
6515
6516 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6517
6518 \end_inset 
6519
6520 \SpecialChar ~
6521 <Value> The start location of the internal ram data
6522 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6523
6524 \end_inset 
6525
6526  segment.
6527  The value entered can be in Hexadecimal or Decimal format, eg.
6528  -
6529 \begin_inset ERT
6530 status Collapsed
6531
6532 \layout Standard
6533
6534 \backslash 
6535 /
6536 \end_inset 
6537
6538 -data-loc 0x20 or -
6539 \begin_inset ERT
6540 status Collapsed
6541
6542 \layout Standard
6543
6544 \backslash 
6545 /
6546 \end_inset 
6547
6548 -data-loc 32.
6549  (By default, the start location of the internal ram data segment  is set
6550  as low as possible in memory, taking into account the used register banks
6551  and the bit segment at address 0x20.
6552  For example if register banks 0 and 1 are used without bit variables, the
6553  data segment will be set, if -
6554 \begin_inset ERT
6555 status Collapsed
6556
6557 \layout Standard
6558
6559 \backslash 
6560 /
6561 \end_inset 
6562
6563 -data-loc is not used, to location 0x10.)
6564 \layout List
6565 \labelwidthstring 00.00.0000
6566
6567
6568 \series bold 
6569 -
6570 \begin_inset ERT
6571 status Collapsed
6572
6573 \layout Standard
6574
6575 \backslash 
6576 /
6577 \end_inset 
6578
6579 -idata-loc
6580 \series default 
6581
6582 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6583
6584 \end_inset 
6585
6586 \SpecialChar ~
6587 <Value> The start location of the indirectly addressable internal ram
6588 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6589
6590 \end_inset 
6591
6592  of the 8051, default value is 0x80.
6593  The value entered can be in Hexadecimal or Decimal format, eg.
6594  -
6595 \begin_inset ERT
6596 status Collapsed
6597
6598 \layout Standard
6599
6600 \backslash 
6601 /
6602 \end_inset 
6603
6604 -idata-loc 0x88 or -
6605 \begin_inset ERT
6606 status Collapsed
6607
6608 \layout Standard
6609
6610 \backslash 
6611 /
6612 \end_inset 
6613
6614 -idata-loc 136.
6615 \layout List
6616 \labelwidthstring 00.00.0000
6617
6618
6619 \series bold 
6620 -
6621 \begin_inset ERT
6622 status Collapsed
6623
6624 \layout Standard
6625
6626 \backslash 
6627 /
6628 \end_inset 
6629
6630 -bit-loc
6631 \series default 
6632 \SpecialChar ~
6633 <Value> The start location of the bit
6634 \begin_inset LatexCommand \index{bit}
6635
6636 \end_inset 
6637
6638  addressable internal ram of the 8051.
6639  This is 
6640 \emph on 
6641 not
6642 \emph default 
6643  implemented yet.
6644  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6645 -bBSEG=<Value>.
6646 \layout List
6647 \labelwidthstring 00.00.0000
6648
6649
6650 \series bold 
6651 -
6652 \begin_inset ERT
6653 status Collapsed
6654
6655 \layout Standard
6656
6657 \backslash 
6658 /
6659 \end_inset 
6660
6661 -out-fmt-ihx
6662 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6663
6664 \end_inset 
6665
6666
6667 \bar under 
6668  
6669 \series default 
6670 \bar default 
6671 The linker output (final object code) is in Intel Hex format.
6672 \begin_inset LatexCommand \index{Intel hex format}
6673
6674 \end_inset 
6675
6676  This is the default option.
6677  The format itself is documented in the documentation of srecord
6678 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6679
6680 \end_inset 
6681
6682 .
6683 \layout List
6684 \labelwidthstring 00.00.0000
6685
6686
6687 \series bold 
6688 -
6689 \begin_inset ERT
6690 status Collapsed
6691
6692 \layout Standard
6693
6694 \backslash 
6695 /
6696 \end_inset 
6697
6698 -out-fmt-s19
6699 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6700
6701 \end_inset 
6702
6703
6704 \bar under 
6705  
6706 \series default 
6707 \bar default 
6708 The linker output (final object code) is in Motorola S19 format
6709 \begin_inset LatexCommand \index{Motorola S19 format}
6710
6711 \end_inset 
6712
6713 .
6714  The format itself is documented in the documentation of srecord.
6715 \layout List
6716 \labelwidthstring 00.00.0000
6717
6718
6719 \series bold 
6720 -
6721 \begin_inset ERT
6722 status Collapsed
6723
6724 \layout Standard
6725
6726 \backslash 
6727 /
6728 \end_inset 
6729
6730 -out-fmt-elf
6731 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6732
6733 \end_inset 
6734
6735
6736 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6737
6738 \end_inset 
6739
6740
6741 \bar under 
6742  
6743 \series default 
6744 \bar default 
6745 The linker output (final object code) is in ELF format
6746 \begin_inset LatexCommand \index{ELF format}
6747
6748 \end_inset 
6749
6750 .
6751  (Currently only supported for the HC08
6752 \begin_inset LatexCommand \index{HC08}
6753
6754 \end_inset 
6755
6756  processors)
6757 \layout List
6758 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6759
6760
6761 \series bold 
6762 -Wl\SpecialChar ~
6763 linkOption[,linkOption]
6764 \series default 
6765
6766 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6767
6768 \end_inset 
6769
6770 ...
6771  Pass the linkOption to the linker.
6772  If a bootloader is used an option like 
6773 \begin_inset Quotes sld
6774 \end_inset 
6775
6776 -Wl\SpecialChar ~
6777 -bCSEG=0x1000
6778 \begin_inset Quotes srd
6779 \end_inset 
6780
6781  would be typical to set the start of the code segment.
6782  See also #pragma constseg and #pragma codeseg in section 
6783 \begin_inset LatexCommand \ref{sec:Pragmas}
6784
6785 \end_inset 
6786
6787  .
6788  File sdcc/as/doc/asxhtm.html has more on linker options.
6789 \layout Subsection
6790
6791 MCS51 Options
6792 \begin_inset LatexCommand \index{Options MCS51}
6793
6794 \end_inset 
6795
6796
6797 \begin_inset LatexCommand \index{MCS51 options}
6798
6799 \end_inset 
6800
6801
6802 \layout List
6803 \labelwidthstring 00.00.0000
6804
6805
6806 \series bold 
6807 -
6808 \begin_inset ERT
6809 status Collapsed
6810
6811 \layout Standard
6812
6813 \backslash 
6814 /
6815 \end_inset 
6816
6817 -model-small
6818 \begin_inset LatexCommand \index{-\/-model-small}
6819
6820 \end_inset 
6821
6822
6823 \series default 
6824 \size large 
6825 \emph on 
6826  
6827 \size default 
6828 \emph default 
6829 Generate code for Small Model programs, see section Memory Models for more
6830  details.
6831  This is the default model.
6832 \layout List
6833 \labelwidthstring 00.00.0000
6834
6835
6836 \series bold 
6837 -
6838 \begin_inset ERT
6839 status Collapsed
6840
6841 \layout Standard
6842
6843 \backslash 
6844 /
6845 \end_inset 
6846
6847 -model-medium
6848 \begin_inset LatexCommand \index{-\/-model-medium}
6849
6850 \end_inset 
6851
6852
6853 \series default 
6854  Generate code for Medium model programs, see section Memory Models for
6855  more details.
6856  If this option is used all source files in the project have to be compiled
6857  with this option.
6858  It must also be used when invoking the linker.
6859 \layout List
6860 \labelwidthstring 00.00.0000
6861
6862
6863 \series bold 
6864 -
6865 \begin_inset ERT
6866 status Collapsed
6867
6868 \layout Standard
6869
6870 \backslash 
6871 /
6872 \end_inset 
6873
6874 -model-large
6875 \begin_inset LatexCommand \index{-\/-model-large}
6876
6877 \end_inset 
6878
6879
6880 \series default 
6881  Generate code for Large model programs, see section Memory Models for more
6882  details.
6883  If this option is used all source files in the project have to be compiled
6884  with this option.
6885  It must also be used when invoking the linker.
6886 \layout List
6887 \labelwidthstring 00.00.0000
6888
6889
6890 \series bold 
6891 -
6892 \begin_inset ERT
6893 status Collapsed
6894
6895 \layout Standard
6896
6897 \backslash 
6898 /
6899 \end_inset 
6900
6901 -xstack
6902 \begin_inset LatexCommand \index{-\/-xstack}
6903
6904 \end_inset 
6905
6906
6907 \series default 
6908  Uses a pseudo stack in the pdata
6909 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6910
6911 \end_inset 
6912
6913  area (usually the first 256 bytes in the external ram) for allocating variables
6914  and passing parameters.
6915  See section 
6916 \begin_inset LatexCommand \ref{sub:External-Stack}
6917
6918 \end_inset 
6919
6920 \SpecialChar ~
6921  External Stack for more details.
6922 \layout List
6923 \labelwidthstring 00.00.0000
6924
6925
6926 \series bold 
6927 -
6928 \begin_inset ERT
6929 status Collapsed
6930
6931 \layout Standard
6932
6933 \backslash 
6934 /
6935 \end_inset 
6936
6937 -iram-size
6938 \series default 
6939 \SpecialChar ~
6940 <Value>
6941 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6942
6943 \end_inset 
6944
6945  Causes the linker to check if the internal ram usage is within limits of
6946  the given value.
6947 \layout List
6948 \labelwidthstring 00.00.0000
6949
6950
6951 \series bold 
6952 -
6953 \begin_inset ERT
6954 status Collapsed
6955
6956 \layout Standard
6957
6958 \backslash 
6959 /
6960 \end_inset 
6961
6962 -xram-size
6963 \series default 
6964 \SpecialChar ~
6965 <Value>
6966 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6967
6968 \end_inset 
6969
6970  Causes the linker to check if the external ram usage is within limits of
6971  the given value.
6972 \layout List
6973 \labelwidthstring 00.00.0000
6974
6975
6976 \series bold 
6977 -
6978 \begin_inset ERT
6979 status Collapsed
6980
6981 \layout Standard
6982
6983 \backslash 
6984 /
6985 \end_inset 
6986
6987 -code-size
6988 \series default 
6989 \SpecialChar ~
6990 <Value>
6991 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6992
6993 \end_inset 
6994
6995  Causes the linker to check if the code memory usage is within limits of
6996  the given value.
6997 \layout List
6998 \labelwidthstring 00.00.0000
6999
7000
7001 \series bold 
7002 -
7003 \begin_inset ERT
7004 status Collapsed
7005
7006 \layout Standard
7007
7008 \backslash 
7009 /
7010 \end_inset 
7011
7012 -stack-size
7013 \series default 
7014 \SpecialChar ~
7015 <Value>
7016 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7017
7018 \end_inset 
7019
7020  Causes the linker to check if there is at minimum <Value> bytes for stack.
7021 \layout List
7022 \labelwidthstring 00.00.0000
7023
7024
7025 \series bold 
7026 -
7027 \begin_inset ERT
7028 status Collapsed
7029
7030 \layout Standard
7031
7032 \backslash 
7033 /
7034 \end_inset 
7035
7036 -pack-iram
7037 \series default 
7038 \SpecialChar ~
7039
7040 \begin_inset LatexCommand \index{-\/-pack-iram}
7041
7042 \end_inset 
7043
7044  Causes the linker to use unused register banks for data variables and pack
7045  data, idata and stack together.
7046  This is the default now.
7047 \layout List
7048 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7049
7050
7051 \series bold 
7052 -
7053 \begin_inset ERT
7054 status Collapsed
7055
7056 \layout Standard
7057
7058 \backslash 
7059 /
7060 \end_inset 
7061
7062 -no-pack-iram
7063 \series default 
7064 \SpecialChar ~
7065
7066 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7067
7068 \end_inset 
7069
7070  Causes the linker to use old style for allocating memory areas.
7071 \layout Subsection
7072
7073 DS390 / DS400 Options
7074 \begin_inset LatexCommand \index{Options DS390}
7075
7076 \end_inset 
7077
7078
7079 \begin_inset LatexCommand \index{DS390}
7080
7081 \end_inset 
7082
7083
7084 \layout List
7085 \labelwidthstring 00.00.0000
7086
7087
7088 \series bold 
7089 -
7090 \begin_inset ERT
7091 status Collapsed
7092
7093 \layout Standard
7094
7095 \backslash 
7096 /
7097 \end_inset 
7098
7099 -model-flat24
7100 \series default 
7101
7102 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7103
7104 \end_inset 
7105
7106
7107 \size large 
7108 \emph on 
7109  
7110 \size default 
7111 \emph default 
7112 Generate 24-bit flat mode code.
7113  This is the one and only that the ds390 code generator supports right now
7114  and is default when using 
7115 \emph on 
7116 -mds390
7117 \emph default 
7118 .
7119  See section Memory Models for more details.
7120 \layout List
7121 \labelwidthstring 00.00.0000
7122
7123
7124 \series bold 
7125 -
7126 \begin_inset ERT
7127 status Collapsed
7128
7129 \layout Standard
7130
7131 \backslash 
7132 /
7133 \end_inset 
7134
7135 -protect-sp-update
7136 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7137
7138 \end_inset 
7139
7140
7141 \series default 
7142  disable interrupts during ESP:SP updates.
7143 \layout List
7144 \labelwidthstring 00.00.0000
7145
7146
7147 \series bold 
7148 -
7149 \begin_inset ERT
7150 status Collapsed
7151
7152 \layout Standard
7153
7154 \backslash 
7155 /
7156 \end_inset 
7157
7158 -stack-10bit
7159 \series default 
7160
7161 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7162
7163 \end_inset 
7164
7165  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7166  This is the one and only that the ds390 code generator supports right now
7167  and is default when using 
7168 \emph on 
7169 -mds390
7170 \emph default 
7171 .
7172  In this mode, the stack is located in the lower 1K of the internal RAM,
7173  which is mapped to 0x400000.
7174  Note that the support is incomplete, since it still uses a single byte
7175  as the stack pointer.
7176  This means that only the lower 256 bytes of the potential 1K stack space
7177  will actually be used.
7178  However, this does allow you to reclaim the precious 256 bytes of low RAM
7179  for use for the DATA and IDATA segments.
7180  The compiler will not generate any code to put the processor into 10 bit
7181  stack mode.
7182  It is important to ensure that the processor is in this mode before calling
7183  any re-entrant functions compiled with this option.
7184  In principle, this should work with the 
7185 \emph on 
7186 -
7187 \begin_inset ERT
7188 status Collapsed
7189
7190 \layout Standard
7191
7192 \backslash 
7193 /
7194 \end_inset 
7195
7196 -stack-auto
7197 \begin_inset LatexCommand \index{-\/-stack-auto}
7198
7199 \end_inset 
7200
7201
7202 \emph default 
7203  option, but that has not been tested.
7204  It is incompatible with the 
7205 \emph on 
7206 -
7207 \begin_inset ERT
7208 status Collapsed
7209
7210 \layout Standard
7211
7212 \backslash 
7213 /
7214 \end_inset 
7215
7216 -xstack
7217 \begin_inset LatexCommand \index{-\/-xstack}
7218
7219 \end_inset 
7220
7221
7222 \emph default 
7223  option.
7224  It also only makes sense if the processor is in 24 bit contiguous addressing
7225  mode (see the 
7226 \emph on 
7227 -
7228 \begin_inset ERT
7229 status Collapsed
7230
7231 \layout Standard
7232
7233 \backslash 
7234 /
7235 \end_inset 
7236
7237 -model-flat24 option
7238 \emph default 
7239 ).
7240 \layout List
7241 \labelwidthstring 00.00.0000
7242
7243
7244 \series bold 
7245 -
7246 \begin_inset ERT
7247 status Collapsed
7248
7249 \layout Standard
7250
7251 \backslash 
7252 /
7253 \end_inset 
7254
7255 -stack-probe
7256 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7257
7258 \end_inset 
7259
7260
7261 \series default 
7262  insert call to function __stack_probe at each function prologue.
7263 \layout List
7264 \labelwidthstring 00.00.0000
7265
7266
7267 \series bold 
7268 -
7269 \begin_inset ERT
7270 status Collapsed
7271
7272 \layout Standard
7273
7274 \backslash 
7275 /
7276 \end_inset 
7277
7278 -tini-libid
7279 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7280
7281 \end_inset 
7282
7283
7284 \series default 
7285  <nnnn> LibraryID used in -mTININative.
7286  
7287 \layout List
7288 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7289
7290
7291 \series bold 
7292 -
7293 \begin_inset ERT
7294 status Collapsed
7295
7296 \layout Standard
7297
7298 \backslash 
7299 /
7300 \end_inset 
7301
7302 -use-accelerator
7303 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7304
7305 \end_inset 
7306
7307
7308 \series default 
7309  generate code for DS390 Arithmetic Accelerator.
7310  
7311 \layout Subsection
7312
7313 Z80 Options
7314 \begin_inset LatexCommand \index{Options Z80}
7315
7316 \end_inset 
7317
7318
7319 \begin_inset LatexCommand \index{Z80}
7320
7321 \end_inset 
7322
7323
7324 \layout List
7325 \labelwidthstring 00.00.0000
7326
7327
7328 \series bold 
7329 -
7330 \begin_inset ERT
7331 status Collapsed
7332
7333 \layout Standard
7334
7335 \backslash 
7336 /
7337 \end_inset 
7338
7339 -callee-saves-bc
7340 \series default 
7341
7342 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7343
7344 \end_inset 
7345
7346
7347 \size large 
7348 \emph on 
7349  
7350 \size default 
7351 \emph default 
7352 Force a called function to always save BC.
7353 \layout List
7354 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7355
7356
7357 \series bold 
7358 -
7359 \begin_inset ERT
7360 status Collapsed
7361
7362 \layout Standard
7363
7364 \backslash 
7365 /
7366 \end_inset 
7367
7368 -no-std-crt0
7369 \series default 
7370
7371 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7372
7373 \end_inset 
7374
7375  When linking, skip the standard crt0.o object file.
7376  You must provide your own crt0.o for your system when linking.
7377  
7378 \layout Subsection
7379
7380 Optimization Options
7381 \begin_inset LatexCommand \index{Options optimization}
7382
7383 \end_inset 
7384
7385
7386 \begin_inset LatexCommand \index{Optimization options}
7387
7388 \end_inset 
7389
7390
7391 \layout List
7392 \labelwidthstring 00.00.0000
7393
7394
7395 \series bold 
7396 -
7397 \begin_inset ERT
7398 status Collapsed
7399
7400 \layout Standard
7401
7402 \backslash 
7403 /
7404 \end_inset 
7405
7406 -nogcse
7407 \begin_inset LatexCommand \index{-\/-nogcse}
7408
7409 \end_inset 
7410
7411
7412 \series default 
7413  Will not do global subexpression elimination, this option may be used when
7414  the compiler creates undesirably large stack/data spaces to store compiler
7415  temporaries (
7416 \emph on 
7417 s
7418 \emph default 
7419 pill 
7420 \emph on 
7421 loc
7422 \emph default 
7423 ations, sloc
7424 \begin_inset LatexCommand \index{sloc (spill location)}
7425
7426 \end_inset 
7427
7428 ).
7429  A warning message will be generated when this happens and the compiler
7430  will indicate the number of extra bytes it allocated.
7431  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7432 nogcse
7433 \begin_inset LatexCommand \index{\#pragma nogcse}
7434
7435 \end_inset 
7436
7437  can be used to turn off global subexpression elimination
7438 \begin_inset LatexCommand \index{Subexpression elimination}
7439
7440 \end_inset 
7441
7442  for a given function only.
7443 \layout List
7444 \labelwidthstring 00.00.0000
7445
7446
7447 \series bold 
7448 -
7449 \begin_inset ERT
7450 status Collapsed
7451
7452 \layout Standard
7453
7454 \backslash 
7455 /
7456 \end_inset 
7457
7458 -noinvariant
7459 \begin_inset LatexCommand \index{-\/-noinvariant}
7460
7461 \end_inset 
7462
7463
7464 \series default 
7465  Will not do loop invariant optimizations, this may be turned off for reasons
7466  explained for the previous option.
7467  For more details of loop optimizations performed see Loop Invariants in
7468  section 
7469 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7470
7471 \end_inset 
7472
7473 .
7474  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7475 noinvariant
7476 \begin_inset LatexCommand \index{\#pragma noinvariant}
7477
7478 \end_inset 
7479
7480  can be used to turn off invariant optimizations for a given function only.
7481 \layout List
7482 \labelwidthstring 00.00.0000
7483
7484
7485 \series bold 
7486 -
7487 \begin_inset ERT
7488 status Collapsed
7489
7490 \layout Standard
7491
7492 \backslash 
7493 /
7494 \end_inset 
7495
7496 -noinduction
7497 \begin_inset LatexCommand \index{-\/-noinduction}
7498
7499 \end_inset 
7500
7501
7502 \series default 
7503  Will not do loop induction optimizations, see section strength reduction
7504  for more details.
7505  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7506 noinduction
7507 \begin_inset LatexCommand \index{\#pragma noinduction}
7508
7509 \end_inset 
7510
7511  can be used to turn off induction optimizations for a given function only.
7512 \layout List
7513 \labelwidthstring 00.00.0000
7514
7515
7516 \series bold 
7517 -
7518 \begin_inset ERT
7519 status Collapsed
7520
7521 \layout Standard
7522
7523 \backslash 
7524 /
7525 \end_inset 
7526
7527 -nojtbound
7528 \begin_inset LatexCommand \index{-\/-nojtbound}
7529
7530 \end_inset 
7531
7532
7533 \size large 
7534 \bar under 
7535  
7536 \series default 
7537 \size default 
7538 \bar default 
7539  Will not generate boundary condition check when switch statements
7540 \begin_inset LatexCommand \index{switch statement}
7541
7542 \end_inset 
7543
7544  are implemented using jump-tables.
7545  See section 
7546 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7547
7548 \end_inset 
7549
7550 \SpecialChar ~
7551 Switch Statements for more details.
7552  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7553 nojtbound
7554 \begin_inset LatexCommand \index{\#pragma nojtbound}
7555
7556 \end_inset 
7557
7558  can be used to turn off boundary checking for jump tables for a given function
7559  only.
7560 \layout List
7561 \labelwidthstring 00.00.0000
7562
7563
7564 \series bold 
7565 -
7566 \begin_inset ERT
7567 status Collapsed
7568
7569 \layout Standard
7570
7571 \backslash 
7572 /
7573 \end_inset 
7574
7575 -noloopreverse
7576 \begin_inset LatexCommand \index{-\/-noloopreverse}
7577
7578 \end_inset 
7579
7580
7581 \series default 
7582 \size large 
7583  
7584 \size default 
7585 Will not do loop reversal 
7586 \begin_inset LatexCommand \index{Loop reversing}
7587
7588 \end_inset 
7589
7590 optimization.
7591 \layout List
7592 \labelwidthstring 00.00.0000
7593
7594 -
7595 \begin_inset ERT
7596 status Collapsed
7597
7598 \layout Standard
7599
7600 \backslash 
7601 /
7602 \end_inset 
7603
7604 -
7605 \series bold 
7606 nolabelopt
7607 \series default 
7608  
7609 \begin_inset LatexCommand \index{-\/-nolabelopt }
7610
7611 \end_inset 
7612
7613 Will not optimize labels (makes the dumpfiles more readable).
7614 \layout List
7615 \labelwidthstring 00.00.0000
7616
7617
7618 \series bold 
7619 -
7620 \begin_inset ERT
7621 status Collapsed
7622
7623 \layout Standard
7624
7625 \backslash 
7626 /
7627 \end_inset 
7628
7629 -no-xinit-opt
7630 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7631
7632 \end_inset 
7633
7634
7635 \series default 
7636  Will not memcpy initialized data from code space into xdata space.
7637  This saves a few bytes in code space if you don't have initialized data
7638 \begin_inset LatexCommand \index{Variable initialization}
7639
7640 \end_inset 
7641
7642 .
7643 \layout List
7644 \labelwidthstring 00.00.0000
7645
7646
7647 \series bold 
7648 -
7649 \begin_inset ERT
7650 status Collapsed
7651
7652 \layout Standard
7653
7654 \backslash 
7655 /
7656 \end_inset 
7657
7658 -nooverlay
7659 \begin_inset LatexCommand \index{-\/-nooverlay}
7660
7661 \end_inset 
7662
7663
7664 \series default 
7665   The compiler will not overlay parameters and local variables of any function,
7666  see section Parameters and local variables for more details.
7667 \layout List
7668 \labelwidthstring 00.00.0000
7669
7670
7671 \series bold 
7672 -
7673 \begin_inset ERT
7674 status Collapsed
7675
7676 \layout Standard
7677
7678 \backslash 
7679 /
7680 \end_inset 
7681
7682 -no-peep
7683 \begin_inset LatexCommand \index{-\/-no-peep}
7684
7685 \end_inset 
7686
7687
7688 \series default 
7689  Disable peep-hole optimization with built-in rules.
7690 \layout List
7691 \labelwidthstring 00.00.0000
7692
7693
7694 \series bold 
7695 -
7696 \begin_inset ERT
7697 status Collapsed
7698
7699 \layout Standard
7700
7701 \backslash 
7702 /
7703 \end_inset 
7704
7705 -peep-file
7706 \series default 
7707
7708 \begin_inset LatexCommand \index{-\/-peep-file}
7709
7710 \end_inset 
7711
7712 \SpecialChar ~
7713 <filename> This option can be used to use additional rules to be used by
7714  the peep hole optimizer.
7715  See section 
7716 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7717
7718 \end_inset 
7719
7720 \SpecialChar ~
7721 Peep Hole optimizations for details on how to write these rules.
7722 \layout List
7723 \labelwidthstring 00.00.0000
7724
7725
7726 \series bold 
7727 -
7728 \begin_inset ERT
7729 status Collapsed
7730
7731 \layout Standard
7732
7733 \backslash 
7734 /
7735 \end_inset 
7736
7737 -peep-asm
7738 \begin_inset LatexCommand \index{-\/-peep-asm}
7739
7740 \end_inset 
7741
7742
7743 \series default 
7744  Pass the inline assembler code through the peep hole optimizer.
7745  This can cause unexpected changes to inline assembler code, please go through
7746  the peephole optimizer
7747 \begin_inset LatexCommand \index{Peephole optimizer}
7748
7749 \end_inset 
7750
7751  rules defined in the source file tree '<target>/peeph.def' before using
7752  this option.
7753 \layout List
7754 \labelwidthstring 00.00.0000
7755
7756
7757 \series bold 
7758 -
7759 \begin_inset ERT
7760 status Collapsed
7761
7762 \layout Standard
7763
7764 \backslash 
7765 /
7766 \end_inset 
7767
7768 -opt-code-speed
7769 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7770
7771 \end_inset 
7772
7773
7774 \series default 
7775  The compiler will optimize code generation towards fast code, possibly
7776  at the expense of code size.
7777 \layout List
7778 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7779
7780
7781 \series bold 
7782 -
7783 \begin_inset ERT
7784 status Collapsed
7785
7786 \layout Standard
7787
7788 \backslash 
7789 /
7790 \end_inset 
7791
7792 -opt-code-size
7793 \begin_inset LatexCommand \index{-\/-opt-code-size}
7794
7795 \end_inset 
7796
7797
7798 \series default 
7799  The compiler will optimize code generation towards compact code, possibly
7800  at the expense of code speed.
7801 \layout Subsection
7802
7803 Other Options
7804 \begin_inset LatexCommand \index{Options other}
7805
7806 \end_inset 
7807
7808
7809 \layout List
7810 \labelwidthstring 00.00.0000
7811
7812
7813 \series bold 
7814 -c\SpecialChar ~
7815 -
7816 \begin_inset ERT
7817 status Collapsed
7818
7819 \layout Standard
7820
7821 \backslash 
7822 /
7823 \end_inset 
7824
7825 -compile-only
7826 \begin_inset LatexCommand \index{-\/-compile-only}
7827
7828 \end_inset 
7829
7830
7831 \begin_inset LatexCommand \index{-c -\/-compile-only}
7832
7833 \end_inset 
7834
7835
7836 \series default 
7837  will compile and assemble the source, but will not call the linkage editor.
7838 \layout List
7839 \labelwidthstring 00.00.0000
7840
7841
7842 \series bold 
7843 -
7844 \series default 
7845
7846 \begin_inset ERT
7847 status Collapsed
7848
7849 \layout Standard
7850
7851 \backslash 
7852 /
7853 \end_inset 
7854
7855
7856 \series bold 
7857 -c1mode
7858 \begin_inset LatexCommand \index{-\/-c1mode}
7859
7860 \end_inset 
7861
7862
7863 \series default 
7864  reads the preprocessed source from standard input and compiles it.
7865  The file name for the assembler output must be specified using the -o option.
7866 \layout List
7867 \labelwidthstring 00.00.0000
7868
7869
7870 \series bold 
7871 -E
7872 \begin_inset LatexCommand \index{-E}
7873
7874 \end_inset 
7875
7876
7877 \series default 
7878  Run only the C preprocessor.
7879  Preprocess all the C source files specified and output the results to standard
7880  output.
7881 \layout List
7882 \labelwidthstring 00.00.0000
7883
7884
7885 \series bold 
7886 -o\SpecialChar ~
7887 <path/file>
7888 \begin_inset LatexCommand \index{-o <path/file>}
7889
7890 \end_inset 
7891
7892  
7893 \series default 
7894 The output path resp.
7895  file where everything will be placed.
7896  If the parameter is a path, it must have a trailing slash (or backslash
7897  for the Windows binaries) to be recognized as a path.
7898  
7899 \layout List
7900 \labelwidthstring 00.00.0000
7901
7902
7903 \series bold 
7904 -
7905 \begin_inset ERT
7906 status Collapsed
7907
7908 \layout Standard
7909
7910 \backslash 
7911 /
7912 \end_inset 
7913
7914 -stack-auto
7915 \begin_inset LatexCommand \index{-\/-stack-auto}
7916
7917 \end_inset 
7918
7919
7920 \series default 
7921 \size large 
7922 \emph on 
7923  
7924 \size default 
7925 \emph default 
7926 All functions in the source file will be compiled as 
7927 \emph on 
7928 reentrant
7929 \emph default 
7930
7931 \begin_inset LatexCommand \index{reentrant}
7932
7933 \end_inset 
7934
7935 , i.e.
7936  the parameters and local variables will be allocated on the stack
7937 \begin_inset LatexCommand \index{stack}
7938
7939 \end_inset 
7940
7941 .
7942  See section 
7943 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7944
7945 \end_inset 
7946
7947  Parameters and Local Variables for more details.
7948  If this option is used all source files in the project should be compiled
7949  with this option.
7950  It automatically implies --int-long-reent and --float-reent.
7951  
7952 \layout List
7953 \labelwidthstring 00.00.0000
7954
7955
7956 \series bold 
7957 -
7958 \begin_inset ERT
7959 status Collapsed
7960
7961 \layout Standard
7962
7963 \backslash 
7964 /
7965 \end_inset 
7966
7967 -callee-saves
7968 \begin_inset LatexCommand \index{-\/-callee-saves}
7969
7970 \end_inset 
7971
7972  function1[,function2][,function3]....
7973
7974 \series default 
7975  The compiler by default uses a caller saves convention for register saving
7976  across function calls, however this can cause unnecessary register pushing
7977  & popping when calling small functions from larger functions.
7978  This option can be used to switch the register saving convention for the
7979  function names specified.
7980  The compiler will not save registers when calling these functions, no extra
7981  code will be generated at the entry & exit (function prologue
7982 \series bold 
7983
7984 \begin_inset LatexCommand \index{function prologue}
7985
7986 \end_inset 
7987
7988
7989 \series default 
7990  & epilogue
7991 \series bold 
7992
7993 \begin_inset LatexCommand \index{function epilogue}
7994
7995 \end_inset 
7996
7997
7998 \series default 
7999 ) for these functions to save & restore the registers used by these functions,
8000  this can SUBSTANTIALLY reduce code & improve run time performance of the
8001  generated code.
8002  In the future the compiler (with inter procedural analysis) will be able
8003  to determine the appropriate scheme to use for each function call.
8004  DO NOT use this option for built-in functions such as _mulint..., if this
8005  option is used for a library function the appropriate library function
8006  needs to be recompiled with the same option.
8007  If the project consists of multiple source files then all the source file
8008  should be compiled with the same -
8009 \begin_inset ERT
8010 status Collapsed
8011
8012 \layout Standard
8013
8014 \backslash 
8015 /
8016 \end_inset 
8017
8018 -callee-saves option string.
8019  Also see #pragma\SpecialChar ~
8020 callee_saves
8021 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8022
8023 \end_inset 
8024
8025 .
8026 \layout List
8027 \labelwidthstring 00.00.0000
8028
8029
8030 \series bold 
8031 -
8032 \begin_inset ERT
8033 status Collapsed
8034
8035 \layout Standard
8036
8037 \backslash 
8038 /
8039 \end_inset 
8040
8041 -debug
8042 \begin_inset LatexCommand \index{-\/-debug}
8043
8044 \end_inset 
8045
8046
8047 \bar under 
8048  
8049 \series default 
8050 \bar default 
8051 When this option is used the compiler will generate debug information.
8052  The debug information collected in a file with .cdb extension can be used
8053  with the SDCDB.
8054  For more information see documentation for SDCDB.
8055  Another file with no extension contains debug information in AOMF or AOMF51
8056 \begin_inset LatexCommand \index{AOMF, AOMF51}
8057
8058 \end_inset 
8059
8060  format which is commonly used by third party tools.
8061 \layout List
8062 \labelwidthstring 00.00.0000
8063
8064
8065 \series bold 
8066 -S
8067 \begin_inset LatexCommand \index{-S}
8068
8069 \end_inset 
8070
8071
8072 \size large 
8073 \bar under 
8074  
8075 \series default 
8076 \size default 
8077 \bar default 
8078 Stop after the stage of compilation proper; do not assemble.
8079  The output is an assembler code file for the input file specified.
8080 \layout List
8081 \labelwidthstring 00.00.0000
8082
8083
8084 \series bold 
8085 -
8086 \begin_inset ERT
8087 status Collapsed
8088
8089 \layout Standard
8090
8091 \backslash 
8092 /
8093 \end_inset 
8094
8095 -int-long-reent
8096 \begin_inset LatexCommand \index{-\/-int-long-reent}
8097
8098 \end_inset 
8099
8100
8101 \series default 
8102  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8103  Note by default these libraries are compiled as non-reentrant.
8104  See section Installation for more details.
8105 \layout List
8106 \labelwidthstring 00.00.0000
8107
8108
8109 \series bold 
8110 -
8111 \begin_inset ERT
8112 status Collapsed
8113
8114 \layout Standard
8115
8116 \backslash 
8117 /
8118 \end_inset 
8119
8120 -cyclomatic
8121 \begin_inset LatexCommand \index{-\/-cyclomatic}
8122
8123 \end_inset 
8124
8125
8126 \bar under 
8127  
8128 \series default 
8129 \bar default 
8130 This option will cause the compiler to generate an information message for
8131  each function in the source file.
8132  The message contains some 
8133 \emph on 
8134 important
8135 \emph default 
8136  information about the function.
8137  The number of edges and nodes the compiler detected in the control flow
8138  graph of the function, and most importantly the 
8139 \emph on 
8140 cyclomatic complexity
8141 \begin_inset LatexCommand \index{Cyclomatic complexity}
8142
8143 \end_inset 
8144
8145
8146 \emph default 
8147  see section on Cyclomatic Complexity for more details.
8148 \layout List
8149 \labelwidthstring 00.00.0000
8150
8151
8152 \series bold 
8153 -
8154 \begin_inset ERT
8155 status Collapsed
8156
8157 \layout Standard
8158
8159 \backslash 
8160 /
8161 \end_inset 
8162
8163 -float-reent
8164 \begin_inset LatexCommand \index{-\/-float-reent}
8165
8166 \end_inset 
8167
8168
8169 \series default 
8170  Floating point library is compiled as reentrant
8171 \begin_inset LatexCommand \index{reentrant}
8172
8173 \end_inset 
8174
8175 .
8176  See section Installation for more details.
8177 \layout List
8178 \labelwidthstring 00.00.0000
8179
8180
8181 \series bold 
8182 -
8183 \begin_inset ERT
8184 status Collapsed
8185
8186 \layout Standard
8187
8188 \backslash 
8189 /
8190 \end_inset 
8191
8192 -main-return
8193 \begin_inset LatexCommand \index{-\/-main-return}
8194
8195 \end_inset 
8196
8197
8198 \series default 
8199  This option can be used if the code generated is called by a monitor program
8200  or if the main routine includes an endless loop.
8201  This option results in slightly smaller code and saves two bytes of stack
8202  space.
8203  The return from the 'main'
8204 \begin_inset LatexCommand \index{main return}
8205
8206 \end_inset 
8207
8208  function will return to the function calling main.
8209  The default setting is to lock up i.e.
8210  generate a '
8211 \family typewriter 
8212 sjmp .
8213 \family default 
8214 '.
8215 \layout List
8216 \labelwidthstring 00.00.0000
8217
8218
8219 \series bold 
8220 -
8221 \begin_inset ERT
8222 status Collapsed
8223
8224 \layout Standard
8225
8226 \backslash 
8227 /
8228 \end_inset 
8229
8230 -nostdinc
8231 \begin_inset LatexCommand \index{-\/-nostdinc}
8232
8233 \end_inset 
8234
8235
8236 \series default 
8237  This will prevent the compiler from passing on the default include path
8238  to the preprocessor.
8239 \layout List
8240 \labelwidthstring 00.00.0000
8241
8242
8243 \series bold 
8244 -
8245 \begin_inset ERT
8246 status Collapsed
8247
8248 \layout Standard
8249
8250 \backslash 
8251 /
8252 \end_inset 
8253
8254 -nostdlib
8255 \begin_inset LatexCommand \index{-\/-nostdlib}
8256
8257 \end_inset 
8258
8259
8260 \series default 
8261  This will prevent the compiler from passing on the default library
8262 \begin_inset LatexCommand \index{Libraries}
8263
8264 \end_inset 
8265
8266  path to the linker.
8267 \layout List
8268 \labelwidthstring 00.00.0000
8269
8270
8271 \series bold 
8272 -
8273 \begin_inset ERT
8274 status Collapsed
8275
8276 \layout Standard
8277
8278 \backslash 
8279 /
8280 \end_inset 
8281
8282 -verbose
8283 \begin_inset LatexCommand \index{-\/-verbose}
8284
8285 \end_inset 
8286
8287
8288 \series default 
8289  Shows the various actions the compiler is performing.
8290 \layout List
8291 \labelwidthstring 00.00.0000
8292
8293
8294 \series bold 
8295 -V
8296 \begin_inset LatexCommand \index{-V}
8297
8298 \end_inset 
8299
8300
8301 \series default 
8302  Shows the actual commands the compiler is executing.
8303 \layout List
8304 \labelwidthstring 00.00.0000
8305
8306
8307 \series bold 
8308 -
8309 \begin_inset ERT
8310 status Collapsed
8311
8312 \layout Standard
8313
8314 \backslash 
8315 /
8316 \end_inset 
8317
8318 -no-c-code-in-asm
8319 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8320
8321 \end_inset 
8322
8323
8324 \series default 
8325  Hides your ugly and inefficient c-code from the asm file, so you can always
8326  blame the compiler :)
8327 \layout List
8328 \labelwidthstring 00.00.0000
8329
8330
8331 \series bold 
8332 -
8333 \begin_inset ERT
8334 status Collapsed
8335
8336 \layout Standard
8337
8338 \backslash 
8339 /
8340 \end_inset 
8341
8342 -no-peep-comments
8343 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8344
8345 \end_inset 
8346
8347
8348 \series default 
8349  Will not include peep-hole comments in the generated files.
8350 \layout List
8351 \labelwidthstring 00.00.0000
8352
8353
8354 \series bold 
8355 -
8356 \begin_inset ERT
8357 status Collapsed
8358
8359 \layout Standard
8360
8361 \backslash 
8362 /
8363 \end_inset 
8364
8365 -i-code-in-asm
8366 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8367
8368 \end_inset 
8369
8370
8371 \series default 
8372  Include i-codes in the asm file.
8373  Sounds like noise but is most helpful for debugging the compiler itself.
8374 \layout List
8375 \labelwidthstring 00.00.0000
8376
8377
8378 \series bold 
8379 -
8380 \begin_inset ERT
8381 status Collapsed
8382
8383 \layout Standard
8384
8385 \backslash 
8386 /
8387 \end_inset 
8388
8389 -less-pedantic
8390 \begin_inset LatexCommand \index{-\/-less-pedantic}
8391
8392 \end_inset 
8393
8394
8395 \series default 
8396  Disable some of the more pedantic warnings
8397 \begin_inset LatexCommand \index{Warnings}
8398
8399 \end_inset 
8400
8401  (jwk burps: please be more specific here, please!).
8402 \layout List
8403 \labelwidthstring 00.00.0000
8404
8405
8406 \series bold 
8407 -
8408 \begin_inset ERT
8409 status Collapsed
8410
8411 \layout Standard
8412
8413 \backslash 
8414 /
8415 \end_inset 
8416
8417 -disable-warning\SpecialChar ~
8418 <nnnn>
8419 \begin_inset LatexCommand \index{-\/-disable-warning}
8420
8421 \end_inset 
8422
8423
8424 \series default 
8425  Disable specific warning with number <nnnn>.
8426 \layout List
8427 \labelwidthstring 00.00.0000
8428
8429
8430 \series bold 
8431 -
8432 \begin_inset ERT
8433 status Collapsed
8434
8435 \layout Standard
8436
8437 \backslash 
8438 /
8439 \end_inset 
8440
8441 -print-search-dirs
8442 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8443
8444 \end_inset 
8445
8446
8447 \series default 
8448  Display the directories in the compiler's search path
8449 \layout List
8450 \labelwidthstring 00.00.0000
8451
8452
8453 \series bold 
8454 -
8455 \begin_inset ERT
8456 status Collapsed
8457
8458 \layout Standard
8459
8460 \backslash 
8461 /
8462 \end_inset 
8463
8464 -vc
8465 \begin_inset LatexCommand \index{-\/-vc}
8466
8467 \end_inset 
8468
8469
8470 \series default 
8471  Display errors and warnings using MSVC style, so you can use SDCC with
8472  the visual studio IDE
8473 \begin_inset LatexCommand \index{IDE}
8474
8475 \end_inset 
8476
8477 .
8478  With SDCC both offering a GCC-like (the default) and a MSVC-like
8479 \begin_inset LatexCommand \index{MSVC output style}
8480
8481 \end_inset 
8482
8483  output style, integration into most programming editors should be straightforwa
8484 rd.
8485 \layout List
8486 \labelwidthstring 00.00.0000
8487
8488
8489 \series bold 
8490 -
8491 \begin_inset ERT
8492 status Collapsed
8493
8494 \layout Standard
8495
8496 \backslash 
8497 /
8498 \end_inset 
8499
8500 -use-stdout
8501 \begin_inset LatexCommand \index{-\/-use-stdout}
8502
8503 \end_inset 
8504
8505
8506 \series default 
8507  Send errors and warnings to stdout instead of stderr.
8508 \layout List
8509 \labelwidthstring 00.00.0000
8510
8511
8512 \series bold 
8513 -Wa\SpecialChar ~
8514 asmOption[,asmOption]
8515 \series default 
8516
8517 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8518
8519 \end_inset 
8520
8521 ...
8522  Pass the asmOption to the assembler
8523 \begin_inset LatexCommand \index{Options assembler}
8524
8525 \end_inset 
8526
8527
8528 \begin_inset LatexCommand \index{Assembler options}
8529
8530 \end_inset 
8531
8532 .
8533  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8534 \layout List
8535 \labelwidthstring 00.00.0000
8536
8537
8538 \series bold 
8539 -
8540 \begin_inset ERT
8541 status Collapsed
8542
8543 \layout Standard
8544
8545 \backslash 
8546 /
8547 \end_inset 
8548
8549 -std-sdcc89
8550 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8551
8552 \end_inset 
8553
8554
8555 \series default 
8556  Generally follow the C89 standard, but allow SDCC features that conflict
8557  with the standard (default).
8558 \layout List
8559 \labelwidthstring 00.00.0000
8560
8561
8562 \series bold 
8563 -
8564 \begin_inset ERT
8565 status Collapsed
8566
8567 \layout Standard
8568
8569 \backslash 
8570 /
8571 \end_inset 
8572
8573 -std-c89
8574 \begin_inset LatexCommand \index{-\/-std-c89}
8575
8576 \end_inset 
8577
8578
8579 \series default 
8580  Follow the C89 standard and disable SDCC features that conflict with the
8581  standard.
8582 \layout List
8583 \labelwidthstring 00.00.0000
8584
8585
8586 \series bold 
8587 -
8588 \begin_inset ERT
8589 status Collapsed
8590
8591 \layout Standard
8592
8593 \backslash 
8594 /
8595 \end_inset 
8596
8597 -std-sdcc99
8598 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8599
8600 \end_inset 
8601
8602
8603 \series default 
8604  Generally follow the C99 standard, but allow SDCC features that conflict
8605  with the standard (incomplete support).
8606 \layout List
8607 \labelwidthstring 00.00.0000
8608
8609
8610 \series bold 
8611 -
8612 \begin_inset ERT
8613 status Collapsed
8614
8615 \layout Standard
8616
8617 \backslash 
8618 /
8619 \end_inset 
8620
8621 -std-c99
8622 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8623
8624 \end_inset 
8625
8626
8627 \series default 
8628  Follow the C99 standard and disable SDCC features that conflict with the
8629  standard (incomplete support).
8630 \layout List
8631 \labelwidthstring 00.00.0000
8632
8633
8634 \series bold 
8635 -
8636 \begin_inset ERT
8637 status Collapsed
8638
8639 \layout Standard
8640
8641 \backslash 
8642 /
8643 \end_inset 
8644
8645 -codeseg
8646 \series default 
8647
8648 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8649
8650 \end_inset 
8651
8652 \SpecialChar ~
8653 <Name> The name to be used for the code
8654 \begin_inset LatexCommand \index{code}
8655
8656 \end_inset 
8657
8658  segment, default CSEG.
8659  This is useful if you need to tell the compiler to put the code in a special
8660  segment so you can later on tell the linker to put this segment in a special
8661  place in memory.
8662  Can be used for instance when using bank switching to put the code in a
8663  bank.
8664 \layout List
8665 \labelwidthstring 00.00.0000
8666
8667
8668 \series bold 
8669 -
8670 \begin_inset ERT
8671 status Collapsed
8672
8673 \layout Standard
8674
8675 \backslash 
8676 /
8677 \end_inset 
8678
8679 -constseg
8680 \series default 
8681
8682 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8683
8684 \end_inset 
8685
8686 \SpecialChar ~
8687 <Name> The name to be used for the const
8688 \begin_inset LatexCommand \index{code}
8689
8690 \end_inset 
8691
8692  segment, default CONST.
8693  This is useful if you need to tell the compiler to put the const data in
8694  a special segment so you can later on tell the linker to put this segment
8695  in a special place in memory.
8696  Can be used for instance when using bank switching to put the const data
8697  in a bank.
8698 \layout List
8699 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8700
8701
8702 \series bold 
8703 more-pedantic
8704 \series default 
8705  Actually this is 
8706 \series bold 
8707 \emph on 
8708 not
8709 \series default 
8710 \emph default 
8711  a SDCC compiler option but if you want 
8712 \emph on 
8713 more
8714 \emph default 
8715  warnings you can use a separate tool dedicated to syntax checking like
8716  splint
8717 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8718
8719 \end_inset 
8720
8721
8722 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8723
8724 \end_inset 
8725
8726  
8727 \begin_inset LatexCommand \url{http://www.splint.org}
8728
8729 \end_inset 
8730
8731 .
8732  To make your source files parseable by splint you will have to include
8733  
8734 \family sans 
8735 lint.h
8736 \family default 
8737
8738 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8739
8740 \end_inset 
8741
8742  in your source file and add brackets around extended keywords (like 
8743 \family sans 
8744
8745 \begin_inset Quotes sld
8746 \end_inset 
8747
8748 __at\SpecialChar ~
8749
8750 \series bold 
8751 (
8752 \series default 
8753 0xab
8754 \series bold 
8755 )
8756 \series default 
8757
8758 \begin_inset Quotes srd
8759 \end_inset 
8760
8761
8762 \family default 
8763  and 
8764 \family sans 
8765
8766 \begin_inset Quotes sld
8767 \end_inset 
8768
8769 __interrupt\SpecialChar ~
8770 (2)
8771 \begin_inset Quotes srd
8772 \end_inset 
8773
8774
8775 \family default 
8776 ).
8777  
8778 \newline 
8779 Splint has an excellent on line manual at 
8780 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8781
8782 \end_inset 
8783
8784  and it's capabilities go beyond pure syntax checking.
8785  You'll need to tell splint the location of SDCC's include files so a typical
8786  command line could look like this: 
8787 \newline 
8788
8789 \family sans 
8790 splint\SpecialChar ~
8791 -I\SpecialChar ~
8792 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8793 \SpecialChar ~
8794 myprogram.c
8795 \layout Subsection
8796
8797 Intermediate Dump Options
8798 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8799
8800 \end_inset 
8801
8802
8803 \begin_inset LatexCommand \index{Options intermediate dump}
8804
8805 \end_inset 
8806
8807
8808 \begin_inset LatexCommand \index{Intermediate dump options}
8809
8810 \end_inset 
8811
8812
8813 \layout Standard
8814
8815 The following options are provided for the purpose of retargetting and debugging
8816  the compiler.
8817  They provide a means to dump the intermediate code (iCode
8818 \begin_inset LatexCommand \index{iCode}
8819
8820 \end_inset 
8821
8822 ) generated by the compiler in human readable form at various stages of
8823  the compilation process.
8824  More on iCodes see chapter 
8825 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8826
8827 \end_inset 
8828
8829  
8830 \begin_inset Quotes srd
8831 \end_inset 
8832
8833 The anatomy of the compiler
8834 \begin_inset Quotes srd
8835 \end_inset 
8836
8837 .
8838 \layout List
8839 \labelwidthstring 00.00.0000
8840
8841
8842 \series bold 
8843 -
8844 \begin_inset ERT
8845 status Collapsed
8846
8847 \layout Standard
8848
8849 \backslash 
8850 /
8851 \end_inset 
8852
8853 -dumpraw
8854 \begin_inset LatexCommand \index{-\/-dumpraw}
8855
8856 \end_inset 
8857
8858
8859 \series default 
8860  This option will cause the compiler to dump the intermediate code into
8861  a file of named 
8862 \emph on 
8863 <source filename>.dumpraw
8864 \emph default 
8865  just after the intermediate code has been generated for a function, i.e.
8866  before any optimizations are done.
8867  The basic blocks
8868 \begin_inset LatexCommand \index{Basic blocks}
8869
8870 \end_inset 
8871
8872  at this stage ordered in the depth first number, so they may not be in
8873  sequence of execution.
8874 \layout List
8875 \labelwidthstring 00.00.0000
8876
8877
8878 \series bold 
8879 -
8880 \begin_inset ERT
8881 status Collapsed
8882
8883 \layout Standard
8884
8885 \backslash 
8886 /
8887 \end_inset 
8888
8889 -dumpgcse
8890 \begin_inset LatexCommand \index{-\/-dumpgcse}
8891
8892 \end_inset 
8893
8894
8895 \series default 
8896  Will create a dump of iCode's, after global subexpression elimination
8897 \begin_inset LatexCommand \index{Global subexpression elimination}
8898
8899 \end_inset 
8900
8901 , into a file named 
8902 \emph on 
8903 <source filename>.dumpgcse.
8904 \layout List
8905 \labelwidthstring 00.00.0000
8906
8907
8908 \series bold 
8909 -
8910 \begin_inset ERT
8911 status Collapsed
8912
8913 \layout Standard
8914
8915 \backslash 
8916 /
8917 \end_inset 
8918
8919 -dumpdeadcode
8920 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8921
8922 \end_inset 
8923
8924
8925 \series default 
8926  Will create a dump of iCode's, after deadcode elimination
8927 \begin_inset LatexCommand \index{Dead-code elimination}
8928
8929 \end_inset 
8930
8931 , into a file named 
8932 \emph on 
8933 <source filename>.dumpdeadcode.
8934 \layout List
8935 \labelwidthstring 00.00.0000
8936
8937
8938 \series bold 
8939 -
8940 \begin_inset ERT
8941 status Collapsed
8942
8943 \layout Standard
8944
8945 \backslash 
8946 /
8947 \end_inset 
8948
8949 -dumploop
8950 \begin_inset LatexCommand \index{-\/-dumploop}
8951
8952 \end_inset 
8953
8954
8955 \series default 
8956 \size large 
8957  
8958 \size default 
8959 Will create a dump of iCode's, after loop optimizations
8960 \begin_inset LatexCommand \index{Loop optimization}
8961
8962 \end_inset 
8963
8964 , into a file named 
8965 \emph on 
8966 <source filename>.dumploop.
8967 \layout List
8968 \labelwidthstring 00.00.0000
8969
8970
8971 \series bold 
8972 -
8973 \begin_inset ERT
8974 status Collapsed
8975
8976 \layout Standard
8977
8978 \backslash 
8979 /
8980 \end_inset 
8981
8982 -dumprange
8983 \begin_inset LatexCommand \index{-\/-dumprange}
8984
8985 \end_inset 
8986
8987
8988 \series default 
8989 \size large 
8990  
8991 \size default 
8992 Will create a dump of iCode's, after live range analysis
8993 \begin_inset LatexCommand \index{Live range analysis}
8994
8995 \end_inset 
8996
8997 , into a file named 
8998 \emph on 
8999 <source filename>.dumprange.
9000 \layout List
9001 \labelwidthstring 00.00.0000
9002
9003
9004 \series bold 
9005 -
9006 \begin_inset ERT
9007 status Collapsed
9008
9009 \layout Standard
9010
9011 \backslash 
9012 /
9013 \end_inset 
9014
9015 -dumlrange
9016 \begin_inset LatexCommand \index{-\/-dumlrange}
9017
9018 \end_inset 
9019
9020
9021 \series default 
9022  Will dump the life ranges
9023 \begin_inset LatexCommand \index{Live range analysis}
9024
9025 \end_inset 
9026
9027  for all symbols.
9028 \layout List
9029 \labelwidthstring 00.00.0000
9030
9031
9032 \series bold 
9033 -
9034 \begin_inset ERT
9035 status Collapsed
9036
9037 \layout Standard
9038
9039 \backslash 
9040 /
9041 \end_inset 
9042
9043 -dumpregassign
9044 \begin_inset LatexCommand \index{-\/-dumpregassign}
9045
9046 \end_inset 
9047
9048
9049 \bar under 
9050  
9051 \series default 
9052 \bar default 
9053 Will create a dump of iCode's, after register assignment
9054 \begin_inset LatexCommand \index{Register assignment}
9055
9056 \end_inset 
9057
9058 , into a file named 
9059 \emph on 
9060 <source filename>.dumprassgn.
9061 \layout List
9062 \labelwidthstring 00.00.0000
9063
9064
9065 \series bold 
9066 -
9067 \begin_inset ERT
9068 status Collapsed
9069
9070 \layout Standard
9071
9072 \backslash 
9073 /
9074 \end_inset 
9075
9076 -dumplrange
9077 \begin_inset LatexCommand \index{-\/-dumplrange}
9078
9079 \end_inset 
9080
9081
9082 \series default 
9083  Will create a dump of the live ranges of iTemp's
9084 \layout List
9085 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9086
9087
9088 \series bold 
9089 -
9090 \begin_inset ERT
9091 status Collapsed
9092
9093 \layout Standard
9094
9095 \backslash 
9096 /
9097 \end_inset 
9098
9099 -dumpall
9100 \begin_inset LatexCommand \index{-\/-dumpall}
9101
9102 \end_inset 
9103
9104
9105 \size large 
9106 \bar under 
9107  
9108 \series default 
9109 \size default 
9110 \bar default 
9111 Will cause all the above mentioned dumps to be created.
9112 \layout Subsection
9113
9114 Redirecting output on Windows Shells
9115 \layout Standard
9116 \added_space_bottom bigskip 
9117 By default SDCC writes it's error messages to 
9118 \begin_inset Quotes sld
9119 \end_inset 
9120
9121 standard error
9122 \begin_inset Quotes srd
9123 \end_inset 
9124
9125 .
9126  To force all messages to 
9127 \begin_inset Quotes sld
9128 \end_inset 
9129
9130 standard output
9131 \begin_inset Quotes srd
9132 \end_inset 
9133
9134  use 
9135 \series bold 
9136 -
9137 \series default 
9138 \emph on 
9139
9140 \begin_inset ERT
9141 status Collapsed
9142
9143 \layout Standard
9144
9145 \backslash 
9146 /
9147 \end_inset 
9148
9149
9150 \series bold 
9151 \emph default 
9152 -
9153 \series default 
9154 use-stdout
9155 \begin_inset LatexCommand \index{-\/-use-stdout}
9156
9157 \end_inset 
9158
9159 .
9160  Additionally, if you happen to have visual studio installed in your windows
9161  machine, you can use it to compile your sources using a custom build and
9162  the SDCC -
9163 \emph on 
9164
9165 \begin_inset ERT
9166 status Collapsed
9167
9168 \layout Standard
9169
9170 \backslash 
9171 /
9172 \end_inset 
9173
9174
9175 \emph default 
9176 -vc
9177 \begin_inset LatexCommand \index{-\/-vc}
9178
9179 \end_inset 
9180
9181  option.
9182  Something like this should work:
9183 \newline 
9184
9185 \newline 
9186
9187 \series bold 
9188 c:
9189 \backslash 
9190 sdcc
9191 \backslash 
9192 bin
9193 \backslash 
9194 sdcc.exe -
9195 \series default 
9196 \emph on 
9197
9198 \begin_inset ERT
9199 status Collapsed
9200
9201 \layout Standard
9202
9203 \backslash 
9204 /
9205 \end_inset 
9206
9207
9208 \series bold 
9209 \emph default 
9210 -vc -
9211 \series default 
9212 \emph on 
9213
9214 \begin_inset ERT
9215 status Collapsed
9216
9217 \layout Standard
9218
9219 \backslash 
9220 /
9221 \end_inset 
9222
9223
9224 \series bold 
9225 \emph default 
9226 -model-large -c $(InputPath)
9227 \layout Section
9228
9229 Environment variables
9230 \begin_inset LatexCommand \index{Environment variables}
9231
9232 \end_inset 
9233
9234
9235 \layout Standard
9236
9237 SDCC recognizes the following environment variables:
9238 \layout List
9239 \labelwidthstring 00.00.0000
9240
9241
9242 \series bold 
9243 SDCC_LEAVE_SIGNALS
9244 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9245
9246 \end_inset 
9247
9248
9249 \series default 
9250  SDCC installs a signal handler
9251 \begin_inset LatexCommand \index{signal handler}
9252
9253 \end_inset 
9254
9255  to be able to delete temporary files after an user break (^C) or an exception.
9256  If this environment variable is set, SDCC won't install the signal handler
9257  in order to be able to debug SDCC.
9258 \layout List
9259 \labelwidthstring 00.00.0000
9260
9261
9262 \series bold 
9263 TMP,\SpecialChar ~
9264 TEMP,\SpecialChar ~
9265 TMPDIR
9266 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9267
9268 \end_inset 
9269
9270
9271 \series default 
9272  Path, where temporary files will be created.
9273  The order of the variables is the search order.
9274  In a standard *nix environment these variables are not set, and there's
9275  no need to set them.
9276  On Windows it's recommended to set one of them.
9277 \layout List
9278 \labelwidthstring 00.00.0000
9279
9280
9281 \series bold 
9282 SDCC_HOME
9283 \begin_inset LatexCommand \index{SDCC\_HOME}
9284
9285 \end_inset 
9286
9287
9288 \series default 
9289  Path, see section 
9290 \begin_inset LatexCommand \ref{sub:Install-paths}
9291
9292 \end_inset 
9293
9294 \SpecialChar ~
9295
9296 \begin_inset Quotes sld
9297 \end_inset 
9298
9299  Install Paths
9300 \begin_inset Quotes srd
9301 \end_inset 
9302
9303 .
9304 \layout List
9305 \labelwidthstring 00.00.0000
9306
9307
9308 \series bold 
9309 SDCC_INCLUDE
9310 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9311
9312 \end_inset 
9313
9314
9315 \series default 
9316  Path, see section 
9317 \begin_inset LatexCommand \ref{sub:Search-Paths}
9318
9319 \end_inset 
9320
9321 \SpecialChar ~
9322
9323 \begin_inset Quotes sld
9324 \end_inset 
9325
9326 Search Paths
9327 \begin_inset Quotes srd
9328 \end_inset 
9329
9330 .
9331 \layout List
9332 \labelwidthstring 00.00.0000
9333
9334
9335 \series bold 
9336 SDCC_LIB
9337 \begin_inset LatexCommand \index{SDCC\_LIB}
9338
9339 \end_inset 
9340
9341
9342 \series default 
9343  Path, see section 
9344 \begin_inset LatexCommand \ref{sub:Search-Paths}
9345
9346 \end_inset 
9347
9348 \SpecialChar ~
9349
9350 \begin_inset Quotes sld
9351 \end_inset 
9352
9353 Search Paths
9354 \begin_inset Quotes srd
9355 \end_inset 
9356
9357 ..
9358 \layout Standard
9359 \added_space_bottom bigskip 
9360 There are some more environment variables recognized by SDCC, but these
9361  are solely used for debugging purposes.
9362  They can change or disappear very quickly, and will never be documented.
9363 \layout Section
9364
9365 Storage Class Language Extensions
9366 \layout Subsection
9367
9368 MCS51/DS390 Storage Class
9369 \begin_inset LatexCommand \index{Storage class}
9370
9371 \end_inset 
9372
9373  Language Extensions
9374 \layout Standard
9375
9376 In addition to the ANSI storage classes SDCC allows the following MCS51
9377  specific storage classes:
9378 \layout Subsubsection
9379
9380 data
9381 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9382
9383 \end_inset 
9384
9385
9386 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9387
9388 \end_inset 
9389
9390  / near
9391 \begin_inset LatexCommand \index{near (storage class)}
9392
9393 \end_inset 
9394
9395
9396 \begin_inset LatexCommand \index{\_\_near (storage class)}
9397
9398 \end_inset 
9399
9400
9401 \layout Standard
9402
9403 This is the 
9404 \series bold 
9405 default
9406 \series default 
9407  storage class for the Small Memory model (
9408 \emph on 
9409 data
9410 \emph default 
9411  and 
9412 \emph on 
9413 near
9414 \emph default 
9415  or the more ANSI-C compliant forms 
9416 \emph on 
9417 __data
9418 \emph default 
9419  and 
9420 \emph on 
9421 __near
9422 \emph default 
9423  can be used synonymously).
9424  Variables declared with this storage class will be allocated in the directly
9425  addressable portion of the internal RAM of a 8051, e.g.:
9426 \layout Verse
9427
9428
9429 \family typewriter 
9430 __data unsigned char test_data;
9431 \layout Standard
9432
9433 Writing 0x01 to this variable generates the assembly code:
9434 \layout Verse
9435
9436
9437 \family typewriter 
9438 75*00 01\SpecialChar ~
9439 \SpecialChar ~
9440 \SpecialChar ~
9441 mov\SpecialChar ~
9442 \SpecialChar ~
9443 _test_data,#0x01
9444 \layout Subsubsection
9445
9446 xdata
9447 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9448
9449 \end_inset 
9450
9451
9452 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9453
9454 \end_inset 
9455
9456  / far
9457 \begin_inset LatexCommand \index{far (storage class)}
9458
9459 \end_inset 
9460
9461
9462 \begin_inset LatexCommand \index{\_\_far (storage class)}
9463
9464 \end_inset 
9465
9466
9467 \layout Standard
9468
9469 Variables declared with this storage class will be placed in the external
9470  RAM.
9471  This is the 
9472 \series bold 
9473 default
9474 \series default 
9475  storage class for the Large Memory model, e.g.:
9476 \layout Verse
9477
9478
9479 \family typewriter 
9480 __xdata unsigned char test_xdata;
9481 \layout Standard
9482
9483 Writing 0x01 to this variable generates the assembly code:
9484 \layout Verse
9485
9486
9487 \family typewriter 
9488 90s00r00\SpecialChar ~
9489 \SpecialChar ~
9490 \SpecialChar ~
9491 mov\SpecialChar ~
9492 \SpecialChar ~
9493 dptr,#_test_xdata 
9494 \newline 
9495 74\SpecialChar ~
9496 01\SpecialChar ~
9497 \SpecialChar ~
9498 \SpecialChar ~
9499 \SpecialChar ~
9500 \SpecialChar ~
9501 \SpecialChar ~
9502 mov\SpecialChar ~
9503 \SpecialChar ~
9504 a,#0x01 
9505 \newline 
9506 F0\SpecialChar ~
9507 \SpecialChar ~
9508 \SpecialChar ~
9509 \SpecialChar ~
9510 \SpecialChar ~
9511 \SpecialChar ~
9512 \SpecialChar ~
9513 \SpecialChar ~
9514 \SpecialChar ~
9515 movx\SpecialChar ~
9516 @dptr,a 
9517 \layout Subsubsection
9518
9519 idata
9520 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9521
9522 \end_inset 
9523
9524
9525 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9526
9527 \end_inset 
9528
9529
9530 \layout Standard
9531
9532 Variables declared with this storage class will be allocated into the indirectly
9533  addressable portion of the internal ram of a 8051, e.g.:
9534 \layout Verse
9535
9536
9537 \family typewriter 
9538 __idata unsigned char test_idata;
9539 \layout Standard
9540
9541 Writing 0x01 to this variable generates the assembly code:
9542 \layout Verse
9543
9544
9545 \family typewriter 
9546 78r00\SpecialChar ~
9547 \SpecialChar ~
9548 \SpecialChar ~
9549 \SpecialChar ~
9550 \SpecialChar ~
9551 \SpecialChar ~
9552 \SpecialChar ~
9553 mov\SpecialChar ~
9554 \SpecialChar ~
9555 r0,#_test_idata
9556 \newline 
9557 76\SpecialChar ~
9558 01\SpecialChar ~
9559 \SpecialChar ~
9560 \SpecialChar ~
9561 \SpecialChar ~
9562 \SpecialChar ~
9563 \SpecialChar ~
9564 \SpecialChar ~
9565 mov\SpecialChar ~
9566 \SpecialChar ~
9567 @r0,#0x01
9568 \layout Standard
9569
9570 Please note, the first 128 byte of idata physically access the same RAM
9571  as the data memory.
9572  The original 8051 had 128 byte idata memory, nowadays most devices have
9573  256 byte idata memory.
9574  The stack
9575 \begin_inset LatexCommand \index{stack}
9576
9577 \end_inset 
9578
9579  is located in idata memory.
9580 \layout Subsubsection
9581
9582 pdata
9583 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9584
9585 \end_inset 
9586
9587
9588 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9589
9590 \end_inset 
9591
9592
9593 \layout Standard
9594
9595 Paged xdata access is just as straightforward as using the other addressing
9596  modes of a 8051.
9597  It is typically located at the start of xdata and has a maximum size of
9598  256 bytes.
9599  The following example writes 0x01 to the pdata variable.
9600  Please note, pdata access physically accesses xdata memory.
9601  The high byte of the address is determined by port P2 
9602 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9603
9604 \end_inset 
9605
9606 (or in case of some 8051 variants by a separate Special Function Register,
9607  see section 
9608 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9609
9610 \end_inset 
9611
9612 ).
9613  This is the 
9614 \series bold 
9615 default
9616 \series default 
9617  storage class for the Medium Memory model, e.g.:
9618 \layout Verse
9619
9620
9621 \family typewriter 
9622 __pdata unsigned char test_pdata;
9623 \layout Standard
9624
9625 Writing 0x01 to this variable generates the assembly code:
9626 \layout Verse
9627
9628
9629 \family typewriter 
9630 78r00\SpecialChar ~
9631 \SpecialChar ~
9632 \SpecialChar ~
9633 \SpecialChar ~
9634 \SpecialChar ~
9635 \SpecialChar ~
9636 mov r0,#_test_pdata
9637 \newline 
9638 74 01\SpecialChar ~
9639 \SpecialChar ~
9640 \SpecialChar ~
9641 \SpecialChar ~
9642 \SpecialChar ~
9643 \SpecialChar ~
9644 mov a,#0x01 
9645 \newline 
9646 F2\SpecialChar ~
9647 \SpecialChar ~
9648 \SpecialChar ~
9649 \SpecialChar ~
9650 \SpecialChar ~
9651 \SpecialChar ~
9652 \SpecialChar ~
9653 \SpecialChar ~
9654 \SpecialChar ~
9655 movx @r0,a
9656 \layout Standard
9657
9658 If the -
9659 \begin_inset ERT
9660 status Collapsed
9661
9662 \layout Standard
9663
9664 \backslash 
9665 /
9666 \end_inset 
9667
9668 -xstack
9669 \begin_inset LatexCommand \index{-\/-xstack}
9670
9671 \end_inset 
9672
9673  option is used the pdata memory area is followed by the xstack memory area
9674  and the sum of their sizes is limited to 256 bytes.
9675 \layout Subsubsection
9676
9677 code
9678 \begin_inset LatexCommand \index{code}
9679
9680 \end_inset 
9681
9682
9683 \begin_inset LatexCommand \index{\_\_code}
9684
9685 \end_inset 
9686
9687
9688 \layout Standard
9689
9690 'Variables' declared with this storage class will be placed in the code
9691  memory:
9692 \layout Verse
9693
9694
9695 \family typewriter 
9696 __code unsigned char test_code;
9697 \layout Standard
9698
9699 Read access to this variable generates the assembly code:
9700 \layout Verse
9701
9702
9703 \family typewriter 
9704 90s00r6F\SpecialChar ~
9705 \SpecialChar ~
9706 \SpecialChar ~
9707 mov dptr,#_test_code
9708 \newline 
9709 E4\SpecialChar ~
9710 \SpecialChar ~
9711 \SpecialChar ~
9712 \SpecialChar ~
9713 \SpecialChar ~
9714 \SpecialChar ~
9715 \SpecialChar ~
9716 \SpecialChar ~
9717 \SpecialChar ~
9718 clr a
9719 \newline 
9720 93\SpecialChar ~
9721 \SpecialChar ~
9722 \SpecialChar ~
9723 \SpecialChar ~
9724 \SpecialChar ~
9725 \SpecialChar ~
9726 \SpecialChar ~
9727 \SpecialChar ~
9728 \SpecialChar ~
9729 movc a,@a+dptr 
9730 \layout Standard
9731
9732
9733 \family typewriter 
9734 char
9735 \family default 
9736  indexed arrays of characters in code memory can be accessed efficiently:
9737 \layout Verse
9738
9739
9740 \family typewriter 
9741 __code char test_array[] = {'c','h','e','a','p'}; 
9742 \layout Standard
9743
9744 Read access to this array using an 8-bit unsigned index generates the assembly
9745  code:
9746 \layout Verse
9747
9748
9749 \family typewriter 
9750 E5*00\SpecialChar ~
9751 \SpecialChar ~
9752 \SpecialChar ~
9753 \SpecialChar ~
9754 \SpecialChar ~
9755 \SpecialChar ~
9756 mov a,_index 
9757 \layout Verse
9758
9759
9760 \family typewriter 
9761 90s00r41\SpecialChar ~
9762 \SpecialChar ~
9763 \SpecialChar ~
9764 mov dptr,#_test_array
9765 \layout Verse
9766
9767
9768 \family typewriter 
9769 93\SpecialChar ~
9770 \SpecialChar ~
9771 \SpecialChar ~
9772 \SpecialChar ~
9773 \SpecialChar ~
9774 \SpecialChar ~
9775 \SpecialChar ~
9776 \SpecialChar ~
9777 \SpecialChar ~
9778 movc a,@a+dptr 
9779 \layout Subsubsection
9780
9781 bit
9782 \begin_inset LatexCommand \index{bit}
9783
9784 \end_inset 
9785
9786
9787 \begin_inset LatexCommand \index{\_\_bit}
9788
9789 \end_inset 
9790
9791
9792 \layout Standard
9793
9794 This is a data-type and a storage class specifier.
9795  When a variable is declared as a bit, it is allocated into the bit addressable
9796  memory of 8051, e.g.:
9797 \layout Verse
9798
9799
9800 \family typewriter 
9801 __bit test_bit;
9802 \layout Standard
9803
9804 Writing 1 to this variable generates the assembly code:
9805 \layout Verse
9806
9807
9808 \family typewriter 
9809 D2*00\SpecialChar ~
9810 \SpecialChar ~
9811 \SpecialChar ~
9812 \SpecialChar ~
9813 \SpecialChar ~
9814 \SpecialChar ~
9815 \SpecialChar ~
9816 setb\SpecialChar ~
9817 _test_bit
9818 \layout Standard
9819
9820 The bit addressable memory consists of 128 bits which are located from 0x20
9821  to 0x2f in data memory.
9822  
9823 \newline 
9824 Apart from this 8051 specific storage class most architectures support ANSI-C
9825  bitfields
9826 \begin_inset LatexCommand \index{bitfields}
9827
9828 \end_inset 
9829
9830
9831 \begin_inset Foot
9832 collapsed false
9833
9834 \layout Standard
9835
9836 Not really meant as examples, but nevertheless showing what bitfields are
9837  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9838 \end_inset 
9839
9840 .
9841  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9842  signed modifier are implemented as unsigned.
9843 \layout Subsubsection
9844
9845 sfr
9846 \begin_inset LatexCommand \index{sfr}
9847
9848 \end_inset 
9849
9850
9851 \begin_inset LatexCommand \index{\_\_sfr}
9852
9853 \end_inset 
9854
9855  / sfr16
9856 \begin_inset LatexCommand \index{sfr16}
9857
9858 \end_inset 
9859
9860
9861 \begin_inset LatexCommand \index{\_\_sfr16}
9862
9863 \end_inset 
9864
9865  / sfr32
9866 \begin_inset LatexCommand \index{sfr32}
9867
9868 \end_inset 
9869
9870
9871 \begin_inset LatexCommand \index{\_\_sfr32}
9872
9873 \end_inset 
9874
9875  / sbit
9876 \begin_inset LatexCommand \index{\_\_sbit}
9877
9878 \end_inset 
9879
9880
9881 \begin_inset LatexCommand \index{sbit}
9882
9883 \end_inset 
9884
9885
9886 \layout Standard
9887
9888 Like the bit keyword, 
9889 \emph on 
9890 sfr / sfr16 / sfr32 / sbit 
9891 \emph default 
9892 signify both a data-type and storage class, they are used to describe the
9893  
9894 \emph on 
9895 s
9896 \emph default 
9897 pecial 
9898 \emph on 
9899 f
9900 \emph default 
9901 unction 
9902 \emph on 
9903 r
9904 \emph default 
9905 egisters and 
9906 \emph on 
9907 s
9908 \emph default 
9909 pecial 
9910 \emph on 
9911 bit
9912 \emph default 
9913  variables of a 8051, eg:
9914 \layout Verse
9915
9916
9917 \family typewriter 
9918 __sfr __at
9919 \begin_inset LatexCommand \index{at}
9920
9921 \end_inset 
9922
9923
9924 \begin_inset LatexCommand \index{\_\_at}
9925
9926 \end_inset 
9927
9928  (0x80) P0;\SpecialChar ~
9929  /* special function register P0 at location 0x80 */
9930 \newline 
9931
9932 \newline 
9933 /* 16 bit special function register combination for timer 0
9934 \newline 
9935 \SpecialChar ~
9936 \SpecialChar ~
9937  with the high byte at location 0x8C and the low byte at location 0x8A */
9938 \newline 
9939 __sfr16 __at (0x8C8A) TMR0;
9940 \newline 
9941
9942 \newline 
9943 __sbit __at
9944 \begin_inset LatexCommand \index{at}
9945
9946 \end_inset 
9947
9948
9949 \begin_inset LatexCommand \index{\_\_at}
9950
9951 \end_inset 
9952
9953  (0xd7) CY;\SpecialChar ~
9954  /* CY (Carry Flag
9955 \begin_inset LatexCommand \index{Flags}
9956
9957 \end_inset 
9958
9959
9960 \begin_inset LatexCommand \index{Carry flag}
9961
9962 \end_inset 
9963
9964 ) */
9965 \layout Standard
9966
9967 Special function registers which are located on an address dividable by
9968  8 are bit-addressable, an
9969 \emph on 
9970  sbit
9971 \emph default 
9972  addresses a specific bit within these sfr.
9973 \newline 
9974 16 Bit and 32 bit special function register combinations which require a
9975  certain access order are better not declared using 
9976 \emph on 
9977 sfr16
9978 \emph default 
9979  or 
9980 \emph on 
9981 sfr32.
9982
9983 \emph default 
9984  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9985  this is not guaranteed.
9986 \newline 
9987
9988 \layout Standard
9989
9990 Please note, if you use a header file which was written for another compiler
9991  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
9992  likely be 
9993 \emph on 
9994 not 
9995 \emph default 
9996 compatible.
9997  Specifically the syntax 
9998 \family typewriter 
9999 \SpecialChar ~
10000 sfr P0 = 0x80;\SpecialChar ~
10001
10002 \family default 
10003  is compiled 
10004 \emph on 
10005 without warning
10006 \emph default 
10007  by SDCC to an assignment of 0x80 to a variable called P0 
10008 \family typewriter 
10009
10010 \begin_inset Marginal
10011 collapsed true
10012
10013 \layout Standard
10014
10015
10016 \series bold 
10017 \SpecialChar ~
10018 !
10019 \end_inset 
10020
10021 .
10022  
10023 \family default 
10024 Nevertheless it is possible to write header files
10025 \begin_inset LatexCommand \index{Header files}
10026
10027 \end_inset 
10028
10029
10030 \begin_inset LatexCommand \index{Include files}
10031
10032 \end_inset 
10033
10034  which can be shared among different compilers (see section 
10035 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10036
10037 \end_inset 
10038
10039 ).
10040  
10041 \layout Subsubsection
10042
10043 Pointers
10044 \begin_inset LatexCommand \index{Pointer}
10045
10046 \end_inset 
10047
10048  to MCS51/DS390 specific memory spaces
10049 \layout Standard
10050
10051 SDCC allows (via language extensions) pointers to explicitly point to any
10052  of the memory spaces
10053 \begin_inset LatexCommand \index{Memory model}
10054
10055 \end_inset 
10056
10057  of the 8051.
10058  In addition to the explicit pointers, the compiler uses (by default) generic
10059  pointers which can be used to point to any of the memory spaces.
10060 \newline 
10061
10062 \newline 
10063 Pointer declaration examples:
10064 \layout Verse
10065
10066
10067 \family typewriter 
10068 /* pointer physically in internal ram pointing to object in external ram
10069  */ 
10070 \newline 
10071 __xdata unsigned char * __data p;
10072 \newline 
10073
10074 \newline 
10075 /* pointer physically in external ram pointing to object in internal ram
10076  */ 
10077 \newline 
10078 __data unsigned char * __xdata p;
10079 \newline 
10080
10081 \newline 
10082 /* pointer physically in code rom pointing to data in xdata space */ 
10083 \newline 
10084 __xdata unsigned char * __code p;
10085 \newline 
10086
10087 \newline 
10088 /* pointer physically in code space pointing to data in code space */ 
10089 \newline 
10090 __code unsigned char * __code p;
10091 \newline 
10092
10093 \newline 
10094 /* generic pointer physically located in xdata space */
10095 \newline 
10096 unsigned char * __xdata p;
10097 \newline 
10098
10099 \newline 
10100 /* generic pointer physically located in default memory space */
10101 \newline 
10102 unsigned char * p;
10103 \newline 
10104
10105 \newline 
10106 /* the following is a function pointer
10107 \begin_inset LatexCommand \index{function pointer}
10108
10109 \end_inset 
10110
10111  physically located in data space */
10112 \newline 
10113 char (* __data fp)(void);
10114 \layout Standard
10115
10116 Well you get the idea.
10117  
10118 \newline 
10119
10120 \newline 
10121 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10122 \emph on 
10123 generic
10124 \emph default 
10125  pointers.
10126  
10127 \size small 
10128
10129 \newline 
10130
10131 \newline 
10132
10133 \size default 
10134 The highest order byte of the 
10135 \emph on 
10136 generic
10137 \emph default 
10138  pointers contains the data space information.
10139  Assembler support routines are called whenever data is stored or retrieved
10140  using 
10141 \emph on 
10142 generic
10143 \emph default 
10144  pointers.
10145  These are useful for developing reusable library
10146 \begin_inset LatexCommand \index{Libraries}
10147
10148 \end_inset 
10149
10150  routines.
10151  Explicitly specifying the pointer
10152 \begin_inset LatexCommand \index{pointer}
10153
10154 \end_inset 
10155
10156  type will generate the most efficient code.
10157 \layout Subsubsection
10158
10159 Notes on MCS51 memory
10160 \begin_inset LatexCommand \index{MCS51 memory}
10161
10162 \end_inset 
10163
10164  layout
10165 \layout Standard
10166
10167 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10168  RAM memory which is structured as follows:
10169 \newline 
10170
10171 \newline 
10172 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10173  
10174 \newline 
10175 - Bytes 20-2F - 16 bytes to hold 128 bit
10176 \begin_inset LatexCommand \index{bit}
10177
10178 \end_inset 
10179
10180  variables and, 
10181 \newline 
10182 - Bytes 30-7F - 80 bytes for general purpose use.
10183 \newline 
10184
10185 \layout Standard
10186
10187 Additionally some members of the MCS51 family may have up to 128 bytes of
10188  additional, indirectly addressable, internal RAM memory (
10189 \emph on 
10190 idata
10191 \emph default 
10192
10193 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10194
10195 \end_inset 
10196
10197
10198 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10199
10200 \end_inset 
10201
10202 ).
10203  Furthermore, some chips may have some built in external memory (
10204 \emph on 
10205 xdata
10206 \emph default 
10207
10208 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10209
10210 \end_inset 
10211
10212
10213 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10214
10215 \end_inset 
10216
10217 ) which should not be confused with the internal, directly addressable RAM
10218  memory (
10219 \emph on 
10220 data
10221 \emph default 
10222
10223 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10224
10225 \end_inset 
10226
10227
10228 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10229
10230 \end_inset 
10231
10232 ).
10233  Sometimes this built in 
10234 \emph on 
10235 xdata
10236 \emph default 
10237  memory has to be activated before using it (you can probably find this
10238  information on the datasheet of the microcontroller your are using, see
10239  also section 
10240 \begin_inset LatexCommand \ref{sub:Startup-Code}
10241
10242 \end_inset 
10243
10244 \SpecialChar ~
10245 Startup-Code).
10246 \layout Standard
10247
10248 Normally SDCC will only use the first bank
10249 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10250
10251 \end_inset 
10252
10253  of registers (register bank 0), but it is possible to specify that other
10254  banks of registers (keyword 
10255 \emph on 
10256 using
10257 \emph default 
10258  
10259 \emph on 
10260
10261 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10262
10263 \end_inset 
10264
10265
10266 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10267
10268 \end_inset 
10269
10270
10271 \emph default 
10272 ) should be used in interrupt
10273 \begin_inset LatexCommand \index{interrupt}
10274
10275 \end_inset 
10276
10277
10278 \begin_inset LatexCommand \index{\_\_interrupt}
10279
10280 \end_inset 
10281
10282  routines.
10283  By default, the compiler will place the stack after the last byte of allocated
10284  memory for variables.
10285  For example, if the first 2 banks of registers are used, and only four
10286  bytes are used for 
10287 \emph on 
10288 data
10289 \emph default 
10290  variables, it will position the base of the internal stack at address 20
10291  (0x14).
10292  This implies that as the stack
10293 \begin_inset LatexCommand \index{stack}
10294
10295 \end_inset 
10296
10297  grows, it will use up the remaining register banks, and the 16 bytes used
10298  by the 128 bit variables, and 80 bytes for general purpose use.
10299  If any bit variables are used, the data variables will be placed in unused
10300  register banks and after the byte holding the last bit variable.
10301  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10302  (two bytes used), 
10303 \emph on 
10304 data
10305 \emph default 
10306  variables will be placed starting from address 0x10 to 0x20 and continue
10307  at address 0x22.
10308  You can also use -
10309 \begin_inset ERT
10310 status Collapsed
10311
10312 \layout Standard
10313
10314 \backslash 
10315 /
10316 \end_inset 
10317
10318 -data-loc
10319 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10320
10321 \end_inset 
10322
10323  to specify the start address of the 
10324 \emph on 
10325 data
10326 \emph default 
10327  and -
10328 \begin_inset ERT
10329 status Collapsed
10330
10331 \layout Standard
10332
10333 \backslash 
10334 /
10335 \end_inset 
10336
10337 -iram-size
10338 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10339
10340 \end_inset 
10341
10342  to specify the size of the total internal RAM (
10343 \emph on 
10344 data
10345 \emph default 
10346 +
10347 \emph on 
10348 idata
10349 \emph default 
10350 ).
10351  
10352 \newline 
10353
10354 \layout Standard
10355
10356 By default the 8051 linker will place the stack after the last byte of (i)data
10357  variables.
10358  Option -
10359 \begin_inset ERT
10360 status Collapsed
10361
10362 \layout Standard
10363
10364 \backslash 
10365 /
10366 \end_inset 
10367
10368 -stack-loc
10369 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10370
10371 \end_inset 
10372
10373  allows you to specify the start of the stack, i.e.
10374  you could start it after any data in the general purpose area.
10375  If your microcontroller has additional indirectly addressable internal
10376  RAM (
10377 \emph on 
10378 idata
10379 \emph default 
10380 ) you can place the stack on it.
10381  You may also need to use -
10382 \begin_inset ERT
10383 status Collapsed
10384
10385 \layout Standard
10386
10387 \backslash 
10388 /
10389 \end_inset 
10390
10391 -xdata-loc
10392 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10393
10394 \end_inset 
10395
10396  to set the start address of the external RAM (
10397 \emph on 
10398 xdata
10399 \emph default 
10400 ) and -
10401 \begin_inset ERT
10402 status Collapsed
10403
10404 \layout Standard
10405
10406 \backslash 
10407 /
10408 \end_inset 
10409
10410 -xram-size
10411 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10412
10413 \end_inset 
10414
10415  to specify its size.
10416  Same goes for the code memory, using -
10417 \begin_inset ERT
10418 status Collapsed
10419
10420 \layout Standard
10421
10422 \backslash 
10423 /
10424 \end_inset 
10425
10426 -code-loc
10427 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10428
10429 \end_inset 
10430
10431  and -
10432 \begin_inset ERT
10433 status Collapsed
10434
10435 \layout Standard
10436
10437 \backslash 
10438 /
10439 \end_inset 
10440
10441 -code-size
10442 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10443
10444 \end_inset 
10445
10446 .
10447  If in doubt, don't specify any options and see if the resulting memory
10448  layout is appropriate, then you can adjust it.
10449 \layout Standard
10450 \added_space_bottom bigskip 
10451 The linker generates two files with memory allocation information.
10452  The first, with extension .map
10453 \begin_inset LatexCommand \index{<file>.map}
10454
10455 \end_inset 
10456
10457  shows all the variables and segments.
10458  The second with extension .mem
10459 \begin_inset LatexCommand \index{<file>.mem}
10460
10461 \end_inset 
10462
10463  shows the final memory layout.
10464  The linker will complain either if memory segments overlap, there is not
10465  enough memory, or there is not enough space for stack.
10466  If you get any linking warnings and/or errors related to stack or segments
10467  allocation, take a look at either the .map or .mem files to find out what
10468  the problem is.
10469  The .mem file may even suggest a solution to the problem.
10470 \layout Subsection
10471
10472 Z80/Z180 Storage Class
10473 \begin_inset LatexCommand \index{Z80!Storage class}
10474
10475 \end_inset 
10476
10477  Language Extensions
10478 \layout Subsubsection
10479
10480 sfr
10481 \begin_inset LatexCommand \index{sfr}
10482
10483 \end_inset 
10484
10485
10486 \begin_inset LatexCommand \index{\_\_sfr}
10487
10488 \end_inset 
10489
10490  (in/out to 8-bit addresses)
10491 \layout Standard
10492
10493 The Z80
10494 \begin_inset LatexCommand \index{Z80}
10495
10496 \end_inset 
10497
10498  family has separate address spaces for memory and 
10499 \emph on 
10500 i
10501 \emph default 
10502 nput/
10503 \emph on 
10504 o
10505 \emph default 
10506 utput memory.
10507  I/O memory
10508 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10509
10510 \end_inset 
10511
10512
10513 \begin_inset LatexCommand \index{Z80!I/O memory}
10514
10515 \end_inset 
10516
10517
10518 \begin_inset LatexCommand \index{Z180!I/O memory}
10519
10520 \end_inset 
10521
10522  is accessed with special instructions, e.g.:
10523 \layout Verse
10524
10525
10526 \family typewriter 
10527 sfr at 0x78 IoPort;\SpecialChar ~
10528 \SpecialChar ~
10529 /* define a var in I/O space at 78h called IoPort */
10530  
10531 \layout Standard
10532
10533 Writing 0x01 to this variable generates the assembly code:
10534 \layout Verse
10535
10536
10537 \family typewriter 
10538 3E 01\SpecialChar ~
10539 \SpecialChar ~
10540 \SpecialChar ~
10541 \SpecialChar ~
10542 \SpecialChar ~
10543 \SpecialChar ~
10544 ld a,#0x01
10545 \newline 
10546 D3 78\SpecialChar ~
10547 \SpecialChar ~
10548 \SpecialChar ~
10549 \SpecialChar ~
10550 \SpecialChar ~
10551 \SpecialChar ~
10552 out (_IoPort),a 
10553 \layout Subsubsection
10554
10555 banked sfr
10556 \begin_inset LatexCommand \index{sfr}
10557
10558 \end_inset 
10559
10560
10561 \begin_inset LatexCommand \index{\_\_sfr}
10562
10563 \end_inset 
10564
10565  (in/out to 16-bit addresses)
10566 \layout Standard
10567
10568 The keyword 
10569 \emph on 
10570 banked
10571 \emph default 
10572  is used to support 16 bit addresses in I/O memory e.g.:
10573 \layout Verse
10574
10575
10576 \family typewriter 
10577 sfr banked at
10578 \begin_inset LatexCommand \index{at}
10579
10580 \end_inset 
10581
10582
10583 \begin_inset LatexCommand \index{\_\_at}
10584
10585 \end_inset 
10586
10587  0x123 IoPort; 
10588 \layout Standard
10589
10590 Writing 0x01 to this variable generates the assembly code:
10591 \layout Verse
10592
10593
10594 \family typewriter 
10595 01 23 01\SpecialChar ~
10596 \SpecialChar ~
10597 \SpecialChar ~
10598 ld bc,#_IoPort
10599 \newline 
10600 3E 01\SpecialChar ~
10601 \SpecialChar ~
10602 \SpecialChar ~
10603 \SpecialChar ~
10604 \SpecialChar ~
10605 \SpecialChar ~
10606 ld a,#0x01 
10607 \newline 
10608 ED 79\SpecialChar ~
10609 \SpecialChar ~
10610 \SpecialChar ~
10611 \SpecialChar ~
10612 \SpecialChar ~
10613 \SpecialChar ~
10614 out (c),a 
10615 \layout Subsubsection
10616
10617 sfr
10618 \begin_inset LatexCommand \index{sfr}
10619
10620 \end_inset 
10621
10622
10623 \begin_inset LatexCommand \index{\_\_sfr}
10624
10625 \end_inset 
10626
10627  (in0/out0 to 8 bit addresses on Z180
10628 \begin_inset LatexCommand \index{Z180}
10629
10630 \end_inset 
10631
10632 /HD64180
10633 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10634
10635 \end_inset 
10636
10637 )
10638 \layout Standard
10639 \added_space_bottom bigskip 
10640 The compiler option -
10641 \begin_inset ERT
10642 status Collapsed
10643
10644 \layout Standard
10645
10646 \backslash 
10647 /
10648 \end_inset 
10649
10650 -portmode
10651 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10652
10653 \end_inset 
10654
10655 =180 (80) and a compiler #pragma\SpecialChar ~
10656 portmode
10657 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10658
10659 \end_inset 
10660
10661  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10662 ns 
10663 \family typewriter 
10664 in0/out0
10665 \family default 
10666  instead of 
10667 \family typewriter 
10668 in/out
10669 \family default 
10670 .
10671  If you include the file z180.h this will be set automatically.
10672 \layout Subsection
10673
10674 HC08 Storage Class
10675 \begin_inset LatexCommand \index{HC08!Storage class}
10676
10677 \end_inset 
10678
10679  Language Extensions
10680 \layout Subsubsection
10681
10682 data
10683 \begin_inset LatexCommand \index{data (hc08 storage class)}
10684
10685 \end_inset 
10686
10687
10688 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10689
10690 \end_inset 
10691
10692  
10693 \layout Standard
10694
10695 The data storage class declares a variable that resides in the first 256
10696  bytes of memory (the direct page).
10697  The HC08
10698 \begin_inset LatexCommand \index{HC08}
10699
10700 \end_inset 
10701
10702  is most efficient at accessing variables (especially pointers) stored here.
10703 \layout Subsubsection
10704
10705 xdata
10706 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10707
10708 \end_inset 
10709
10710
10711 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10712
10713 \end_inset 
10714
10715  
10716 \layout Standard
10717 \added_space_bottom bigskip 
10718 The xdata storage class declares a variable that can reside anywhere in
10719  memory.
10720  This is the default if no storage class is specified.
10721  
10722 \layout Section
10723
10724 Absolute Addressing
10725 \begin_inset LatexCommand \index{Absolute addressing}
10726
10727 \end_inset 
10728
10729
10730 \layout Standard
10731
10732 Data items can be assigned an absolute address with the 
10733 \emph on 
10734 at
10735 \begin_inset LatexCommand \index{at}
10736
10737 \end_inset 
10738
10739
10740 \begin_inset LatexCommand \index{\_\_at}
10741
10742 \end_inset 
10743
10744  <address>
10745 \emph default 
10746  keyword, in addition to a storage class, e.g.:
10747 \layout Verse
10748
10749
10750 \family typewriter 
10751 xdata
10752 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10753
10754 \end_inset 
10755
10756
10757 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10758
10759 \end_inset 
10760
10761  at
10762 \begin_inset LatexCommand \index{at}
10763
10764 \end_inset 
10765
10766
10767 \begin_inset LatexCommand \index{\_\_at}
10768
10769 \end_inset 
10770
10771  0x7ffe unsigned int chksum;
10772 \layout Standard
10773
10774 or, better conforming to ISO/IEC 9899 C:
10775 \layout Verse
10776
10777
10778 \family typewriter 
10779 __xdata __at (0x7ffe) unsigned int chksum;
10780 \layout Standard
10781
10782 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10783  of the external ram.
10784  The compiler does 
10785 \emph on 
10786 not
10787 \emph default 
10788  reserve any space for variables declared in this way
10789 \begin_inset Marginal
10790 collapsed true
10791
10792 \layout Standard
10793
10794
10795 \series bold 
10796 \SpecialChar ~
10797 !
10798 \end_inset 
10799
10800  (they are implemented with an equate in the assembler).
10801  Thus it is left to the programmer to make sure there are no overlaps with
10802  other variables that are declared without the absolute address.
10803  The assembler listing file (.lst
10804 \begin_inset LatexCommand \index{<file>.lst}
10805
10806 \end_inset 
10807
10808 ) and the linker output files (.rst
10809 \begin_inset LatexCommand \index{<file>.rst}
10810
10811 \end_inset 
10812
10813 ) and (.map
10814 \begin_inset LatexCommand \index{<file>.map}
10815
10816 \end_inset 
10817
10818 ) are good places to look for such overlaps.
10819  Variables with an absolute address are 
10820 \emph on 
10821 not
10822 \begin_inset Marginal
10823 collapsed true
10824
10825 \layout Standard
10826
10827
10828 \series bold 
10829 \SpecialChar ~
10830 !
10831 \end_inset 
10832
10833
10834 \emph default 
10835  initialized
10836 \begin_inset LatexCommand \index{Variable initialization}
10837
10838 \end_inset 
10839
10840 .
10841 \layout Standard
10842
10843 In case of memory mapped I/O devices the keyword 
10844 \emph on 
10845 volatile
10846 \emph default 
10847  has to be used to tell the compiler that accesses might not be removed:
10848 \layout Verse
10849
10850
10851 \family typewriter 
10852 volatile
10853 \begin_inset LatexCommand \index{volatile}
10854
10855 \end_inset 
10856
10857  __xdata
10858 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10859
10860 \end_inset 
10861
10862  __at
10863 \begin_inset LatexCommand \index{at}
10864
10865 \end_inset 
10866
10867  (0x8000) unsigned char PORTA_8255;
10868 \layout Standard
10869
10870 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10871 r) array
10872 \family typewriter 
10873 \size footnotesize 
10874
10875 \begin_inset LatexCommand \index{Aligned array}
10876
10877 \end_inset 
10878
10879
10880 \family default 
10881 \size default 
10882  starts at a block (256 byte) boundary
10883 \begin_inset LatexCommand \index{block boundary}
10884
10885 \end_inset 
10886
10887  (section 
10888 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10889
10890 \end_inset 
10891
10892  has an example).
10893 \newline 
10894 Absolute addresses can be specified for variables in all storage classes,
10895  e.g.:
10896 \layout Verse
10897
10898
10899 \family typewriter 
10900 __bit
10901 \begin_inset LatexCommand \index{bit}
10902
10903 \end_inset 
10904
10905  __at
10906 \begin_inset LatexCommand \index{at}
10907
10908 \end_inset 
10909
10910  (0x02) bvar;
10911 \layout Standard
10912
10913 The above example will allocate the variable at offset 0x02 in the bit-addressab
10914 le space.
10915  There is no real advantage to assigning absolute addresses to variables
10916  in this manner, unless you want strict control over all the variables allocated.
10917  One possible use would be to write hardware portable code.
10918  For example, if you have a routine that uses one or more of the microcontroller
10919  I/O pins, and such pins are different for two different hardwares, you
10920  can declare the I/O pins in your routine using:
10921 \layout Verse
10922
10923
10924 \family typewriter 
10925 extern volatile
10926 \begin_inset LatexCommand \index{volatile}
10927
10928 \end_inset 
10929
10930  __bit MOSI;\SpecialChar ~
10931 \SpecialChar ~
10932 \SpecialChar ~
10933 \SpecialChar ~
10934 /* master out, slave in */
10935 \newline 
10936 extern volatile __bit MISO;\SpecialChar ~
10937 \SpecialChar ~
10938 \SpecialChar ~
10939 \SpecialChar ~
10940 /* master in, slave out */
10941 \newline 
10942 extern volatile __bit MCLK;\SpecialChar ~
10943 \SpecialChar ~
10944 \SpecialChar ~
10945 \SpecialChar ~
10946 /* master clock */
10947 \newline 
10948
10949 \newline 
10950 /* Input and Output of a byte on a 3-wire serial bus.
10951 \newline 
10952 \SpecialChar ~
10953 \SpecialChar ~
10954 \SpecialChar ~
10955 If needed adapt polarity of clock, polarity of data and bit order
10956 \newline 
10957 \SpecialChar ~
10958 */
10959 \newline 
10960 unsigned char spi_io(unsigned char out_byte) 
10961 \newline 
10962
10963 \newline 
10964 \SpecialChar ~
10965 \SpecialChar ~
10966 \SpecialChar ~
10967 \SpecialChar ~
10968 unsigned char i=8;
10969 \newline 
10970 \SpecialChar ~
10971 \SpecialChar ~
10972 \SpecialChar ~
10973 \SpecialChar ~
10974 do { 
10975 \newline 
10976 \SpecialChar ~
10977 \SpecialChar ~
10978 \SpecialChar ~
10979 \SpecialChar ~
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 MOSI = out_byte & 0x80; 
10985 \newline 
10986 \SpecialChar ~
10987 \SpecialChar ~
10988 \SpecialChar ~
10989 \SpecialChar ~
10990 \SpecialChar ~
10991 \SpecialChar ~
10992 \SpecialChar ~
10993 \SpecialChar ~
10994 out_byte <<= 1;
10995 \newline 
10996 \SpecialChar ~
10997 \SpecialChar ~
10998 \SpecialChar ~
10999 \SpecialChar ~
11000 \SpecialChar ~
11001 \SpecialChar ~
11002 \SpecialChar ~
11003 \SpecialChar ~
11004 MCLK = 1; 
11005 \newline 
11006 \SpecialChar ~
11007 \SpecialChar ~
11008 \SpecialChar ~
11009 \SpecialChar ~
11010 \SpecialChar ~
11011 \SpecialChar ~
11012 \SpecialChar ~
11013 \SpecialChar ~
11014 /* _asm nop _endasm; */\SpecialChar ~
11015 \SpecialChar ~
11016 \SpecialChar ~
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 \SpecialChar ~
11020 \SpecialChar ~
11021 \SpecialChar ~
11022 /* for slow peripherals */
11023 \newline 
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 \SpecialChar ~
11029 \SpecialChar ~
11030 \SpecialChar ~
11031 \SpecialChar ~
11032 if(MISO) 
11033 \newline 
11034 \SpecialChar ~
11035 \SpecialChar ~
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 \SpecialChar ~
11041 \SpecialChar ~
11042 \SpecialChar ~
11043 \SpecialChar ~
11044 \SpecialChar ~
11045 \SpecialChar ~
11046 out_byte += 1; 
11047 \newline 
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 \SpecialChar ~
11051 \SpecialChar ~
11052 \SpecialChar ~
11053 \SpecialChar ~
11054 \SpecialChar ~
11055 \SpecialChar ~
11056 MCLK = 0; 
11057 \newline 
11058 \SpecialChar ~
11059 \SpecialChar ~
11060 \SpecialChar ~
11061 \SpecialChar ~
11062 } while(--i);
11063 \newline 
11064 \SpecialChar ~
11065 \SpecialChar ~
11066 \SpecialChar ~
11067 \SpecialChar ~
11068 return out_byte; 
11069 \newline 
11070 }
11071 \layout Standard
11072
11073 Then, someplace in the code for the first hardware you would use
11074 \layout Verse
11075
11076
11077 \family typewriter 
11078 __bit __at
11079 \begin_inset LatexCommand \index{at}
11080
11081 \end_inset 
11082
11083
11084 \begin_inset LatexCommand \index{\_\_at}
11085
11086 \end_inset 
11087
11088  (0x80) MOSI;\SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 /* I/O port 0, bit 0 */
11093 \newline 
11094 __bit __at (0x81) MISO;\SpecialChar ~
11095 \SpecialChar ~
11096 \SpecialChar ~
11097 \SpecialChar ~
11098 /* I/O port 0, bit 1 */
11099 \newline 
11100 __bit __at (0x82) MCLK;\SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 /* I/O port 0, bit 2 */
11105 \layout Standard
11106
11107 Similarly, for the second hardware you would use
11108 \layout Verse
11109
11110
11111 \family typewriter 
11112 __bit __at (0x83) MOSI;\SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 /* I/O port 0, bit 3 */
11117 \newline 
11118 __bit __at (0x91) MISO;\SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 /* I/O port 1, bit 1 */
11123 \newline 
11124 __bit
11125 \begin_inset LatexCommand \index{bit}
11126
11127 \end_inset 
11128
11129  __at (0x92) MCLK;\SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 \SpecialChar ~
11133 /* I/O port 1, bit 2 */
11134 \layout Standard
11135 \added_space_bottom bigskip 
11136 and you can use the same hardware dependent routine without changes, as
11137  for example in a library.
11138  This is somehow similar to sbit, but only one absolute address has to be
11139  specified in the whole project.
11140 \layout Section
11141
11142 Parameters
11143 \begin_inset LatexCommand \index{Parameters}
11144
11145 \end_inset 
11146
11147
11148 \begin_inset LatexCommand \index{function parameter}
11149
11150 \end_inset 
11151
11152  & Local Variables
11153 \begin_inset LatexCommand \index{local variables}
11154
11155 \end_inset 
11156
11157
11158 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11159
11160 \end_inset 
11161
11162
11163 \layout Standard
11164
11165 Automatic (local) variables and parameters to functions can either be placed
11166  on the stack or in data-space.
11167  The default action of the compiler is to place these variables in the internal
11168  RAM (for small model) or external RAM (for large model).
11169  This in fact makes them similar to 
11170 \emph on 
11171 static
11172 \begin_inset LatexCommand \index{static}
11173
11174 \end_inset 
11175
11176
11177 \emph default 
11178  so by default functions are non-reentrant
11179 \begin_inset LatexCommand \index{reentrant}
11180
11181 \end_inset 
11182
11183 .
11184  
11185 \newline 
11186
11187 \newline 
11188 They can be placed on the stack
11189 \begin_inset LatexCommand \index{stack}
11190
11191 \end_inset 
11192
11193  by using the
11194 \emph on 
11195  -
11196 \begin_inset ERT
11197 status Collapsed
11198
11199 \layout Standard
11200
11201 \backslash 
11202 /
11203 \end_inset 
11204
11205 -stack-auto
11206 \begin_inset LatexCommand \index{-\/-stack-auto}
11207
11208 \end_inset 
11209
11210
11211 \emph default 
11212  option, by using 
11213 \emph on 
11214 #pragma\SpecialChar ~
11215 stackauto
11216 \emph default 
11217
11218 \begin_inset LatexCommand \index{\#pragma stackauto}
11219
11220 \end_inset 
11221
11222  or by using the 
11223 \emph on 
11224 reentrant
11225 \begin_inset LatexCommand \index{reentrant}
11226
11227 \end_inset 
11228
11229
11230 \emph default 
11231  keyword in the function declaration, e.g.:
11232 \layout Verse
11233
11234
11235 \family typewriter 
11236 unsigned char foo(char i) __reentrant 
11237 \newline 
11238
11239 \newline 
11240 \SpecialChar ~
11241 \SpecialChar ~
11242 \SpecialChar ~
11243 \SpecialChar ~
11244 ...
11245  
11246 \newline 
11247 }
11248 \layout Standard
11249
11250 Since stack space on 8051 is limited, the 
11251 \emph on 
11252 reentrant 
11253 \emph default 
11254 keyword or the
11255 \emph on 
11256  -
11257 \begin_inset ERT
11258 status Collapsed
11259
11260 \layout Standard
11261
11262 \backslash 
11263 /
11264 \end_inset 
11265
11266 -stack-auto
11267 \emph default 
11268  option should be used sparingly.
11269  Note that the reentrant keyword just means that the parameters & local
11270  variables will be allocated to the stack, it 
11271 \emph on 
11272 does not
11273 \emph default 
11274  mean that the function is register bank
11275 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11276
11277 \end_inset 
11278
11279  independent.
11280 \newline 
11281
11282 \newline 
11283 Local variables
11284 \begin_inset LatexCommand \index{local variables}
11285
11286 \end_inset 
11287
11288  can be assigned storage classes and absolute
11289 \begin_inset LatexCommand \index{Absolute addressing}
11290
11291 \end_inset 
11292
11293  addresses, e.g.: 
11294 \layout Verse
11295
11296
11297 \family typewriter 
11298 unsigned char foo() 
11299 \newline 
11300 {
11301 \newline 
11302 \SpecialChar ~
11303 \SpecialChar ~
11304 \SpecialChar ~
11305 \SpecialChar ~
11306 __xdata unsigned char i;
11307 \newline 
11308 \SpecialChar ~
11309 \SpecialChar ~
11310 \SpecialChar ~
11311 \SpecialChar ~
11312 __bit bvar;
11313 \newline 
11314 \SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 __data __at
11319 \begin_inset LatexCommand \index{at}
11320
11321 \end_inset 
11322
11323  (0x31) unsigned char j;
11324 \newline 
11325 \SpecialChar ~
11326 \SpecialChar ~
11327 \SpecialChar ~
11328 \SpecialChar ~
11329 ...
11330  
11331 \newline 
11332 }
11333 \layout Standard
11334
11335 In the above example the variable 
11336 \emph on 
11337 i
11338 \emph default 
11339  will be allocated in the external ram, 
11340 \emph on 
11341 bvar
11342 \emph default 
11343  in bit addressable space and
11344 \emph on 
11345  j
11346 \emph default 
11347  in internal ram.
11348  When compiled with 
11349 \emph on 
11350 -
11351 \begin_inset ERT
11352 status Collapsed
11353
11354 \layout Standard
11355
11356 \backslash 
11357 /
11358 \end_inset 
11359
11360 -stack-auto
11361 \emph default 
11362  or when a function is declared as 
11363 \emph on 
11364 reentrant
11365 \emph default 
11366  this should only be done for static variables.
11367 \layout Standard
11368
11369 Parameters
11370 \begin_inset LatexCommand \index{function parameter}
11371
11372 \end_inset 
11373
11374  however are not allowed any storage class
11375 \begin_inset LatexCommand \index{Storage class}
11376
11377 \end_inset 
11378
11379 , (storage classes for parameters will be ignored), their allocation is
11380  governed by the memory model in use, and the reentrancy options.
11381 \layout Standard
11382
11383 It is however allowed to use bit parameters in reentrant functions and also
11384  non-static local bit variables are supported.
11385  Efficient use is limited to 8 semi-bitregisters in bit space.
11386  They are pushed and popped to stack
11387 \begin_inset LatexCommand \index{stack}
11388
11389 \end_inset 
11390
11391  as a single byte just like the normal registers.
11392 \layout Section
11393
11394 Overlaying
11395 \begin_inset LatexCommand \label{sub:Overlaying}
11396
11397 \end_inset 
11398
11399
11400 \begin_inset LatexCommand \index{Overlaying}
11401
11402 \end_inset 
11403
11404
11405 \layout Standard
11406
11407 For non-reentrant
11408 \begin_inset LatexCommand \index{reentrant}
11409
11410 \end_inset 
11411
11412  functions SDCC will try to reduce internal ram space usage by overlaying
11413  parameters and local variables of a function (if possible).
11414  Parameters and local variables
11415 \begin_inset LatexCommand \index{local variables}
11416
11417 \end_inset 
11418
11419  of a function will be allocated to an overlayable segment if the function
11420  has 
11421 \emph on 
11422 no other function calls and the function is non-reentrant and the memory
11423  model
11424 \begin_inset LatexCommand \index{Memory model}
11425
11426 \end_inset 
11427
11428  is small.
11429
11430 \emph default 
11431  If an explicit storage class
11432 \begin_inset LatexCommand \index{Storage class}
11433
11434 \end_inset 
11435
11436  is specified for a local variable, it will NOT be overlayed.
11437 \layout Standard
11438
11439 Note that the compiler (not the linkage editor) makes the decision for overlayin
11440 g the data items.
11441  Functions that are called from an interrupt service routine
11442 \begin_inset Marginal
11443 collapsed true
11444
11445 \layout Standard
11446
11447
11448 \series bold 
11449 !
11450 \end_inset 
11451
11452  should be preceded by a #pragma\SpecialChar ~
11453 nooverlay
11454 \begin_inset LatexCommand \index{\#pragma nooverlay}
11455
11456 \end_inset 
11457
11458  if they are not reentrant.
11459 \layout Standard
11460
11461 Also note that the compiler does not do any processing of inline assembler
11462  code, so the compiler might incorrectly assign local variables and parameters
11463  of a function into the overlay segment if the inline assembler code calls
11464  other c-functions that might use the overlay.
11465  In that case the #pragma\SpecialChar ~
11466 nooverlay should be used.
11467 \layout Standard
11468
11469 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11470 tion
11471 \begin_inset LatexCommand \index{Multiplication}
11472
11473 \end_inset 
11474
11475  or division
11476 \begin_inset LatexCommand \index{Division}
11477
11478 \end_inset 
11479
11480  will NOT be overlayed since these are implemented using external functions,
11481  e.g.:
11482 \layout Verse
11483
11484
11485 \family typewriter 
11486 #pragma save 
11487 \newline 
11488 #pragma nooverlay
11489 \begin_inset LatexCommand \index{\#pragma nooverlay}
11490
11491 \end_inset 
11492
11493  
11494 \newline 
11495 void set_error(unsigned char errcd) 
11496 \newline 
11497 {
11498 \newline 
11499 \SpecialChar ~
11500 \SpecialChar ~
11501 \SpecialChar ~
11502 \SpecialChar ~
11503 P3 = errcd;
11504 \newline 
11505
11506 \newline 
11507 #pragma restore 
11508 \newline 
11509
11510 \newline 
11511 void some_isr () __interrupt
11512 \begin_inset LatexCommand \index{interrupt}
11513
11514 \end_inset 
11515
11516  (2)
11517 \newline 
11518 {
11519 \newline 
11520 \SpecialChar ~
11521 \SpecialChar ~
11522 \SpecialChar ~
11523 \SpecialChar ~
11524 ...
11525 \newline 
11526 \SpecialChar ~
11527 \SpecialChar ~
11528 \SpecialChar ~
11529 \SpecialChar ~
11530 set_error(10);
11531 \newline 
11532 \SpecialChar ~
11533 \SpecialChar ~
11534 \SpecialChar ~
11535 \SpecialChar ~
11536 ...
11537  
11538 \newline 
11539 }
11540 \layout Standard
11541 \added_space_bottom bigskip 
11542 In the above example the parameter 
11543 \emph on 
11544 errcd
11545 \emph default 
11546  for the function 
11547 \emph on 
11548 set_error
11549 \emph default 
11550  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11551 nooverlay was
11552  not present, this could cause unpredictable runtime behavior when called
11553  from an interrupt service routine.
11554  The #pragma\SpecialChar ~
11555 nooverlay ensures that the parameters and local variables for
11556  the function are NOT overlayed.
11557 \layout Section
11558
11559 Interrupt Service Routines
11560 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11561
11562 \end_inset 
11563
11564
11565 \layout Subsection
11566
11567 General Information
11568 \layout Standard
11569
11570 SDCC allows 
11571 \emph on 
11572 i
11573 \emph default 
11574 nterrupt 
11575 \emph on 
11576 s
11577 \emph default 
11578 ervice 
11579 \emph on 
11580 r
11581 \emph default 
11582 outines to be coded in C, with some extended keywords.
11583 \layout Verse
11584
11585
11586 \family typewriter 
11587 void timer_isr (void) __interrupt (1) __using (1) 
11588 \newline 
11589
11590 \newline 
11591 \SpecialChar ~
11592 \SpecialChar ~
11593 \SpecialChar ~
11594 \SpecialChar ~
11595 ...
11596  
11597 \newline 
11598 }
11599 \layout Standard
11600
11601 The optional number following the 
11602 \emph on 
11603 interrupt
11604 \begin_inset LatexCommand \index{interrupt}
11605
11606 \end_inset 
11607
11608
11609 \begin_inset LatexCommand \index{\_\_interrupt}
11610
11611 \end_inset 
11612
11613
11614 \emph default 
11615  keyword is the interrupt number this routine will service.
11616  When present, the compiler will insert a call to this routine in the interrupt
11617  vector table
11618 \begin_inset LatexCommand \index{interrupt vector table}
11619
11620 \end_inset 
11621
11622  for the interrupt number specified.
11623  If you have multiple source files in your project, interrupt service routines
11624  can be present in any of them, but a prototype of the isr MUST be present
11625  or included in the file that contains the function 
11626 \emph on 
11627 main
11628 \emph default 
11629 .
11630  The optional (8051 specific) keyword 
11631 \emph on 
11632 using
11633 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11634
11635 \end_inset 
11636
11637
11638 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11639
11640 \end_inset 
11641
11642
11643 \emph default 
11644  can be used to tell the compiler to use the specified register bank when
11645  generating code for this function.
11646  
11647 \newline 
11648 Interrupt service routines open the door for some very interesting bugs:
11649 \layout Subsubsection
11650
11651
11652 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11653
11654 \end_inset 
11655
11656 Common interrupt pitfall: variable not declared 
11657 \emph on 
11658 volatile
11659 \layout Standard
11660
11661 If an interrupt service routine changes variables which are accessed by
11662  other functions these variables have to be declared 
11663 \emph on 
11664 volatile
11665 \emph default 
11666
11667 \begin_inset LatexCommand \index{volatile}
11668
11669 \end_inset 
11670
11671 .
11672  See 
11673 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11674
11675 \end_inset 
11676
11677  .
11678 \layout Subsubsection
11679
11680
11681 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11682
11683 \end_inset 
11684
11685 Common interrupt pitfall: 
11686 \emph on 
11687 non-atomic access
11688 \layout Standard
11689
11690 If the access to these variables is not 
11691 \emph on 
11692 atomic
11693 \begin_inset LatexCommand \index{atomic}
11694
11695 \end_inset 
11696
11697
11698 \emph default 
11699  (i.e.
11700  the processor needs more than one instruction for the access and could
11701  be interrupted while accessing the variable) the interrupt must be disabled
11702  during the access to avoid inconsistent data.
11703  
11704 \newline 
11705 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11706  should be protected by disabling interrupts.
11707  You're not automatically on the safe side if you use 8 bit variables though.
11708  We need an example here: f.e.
11709  on the 8051 the harmless looking 
11710 \begin_inset Quotes srd
11711 \end_inset 
11712
11713
11714 \family typewriter 
11715 flags\SpecialChar ~
11716 |=\SpecialChar ~
11717 0x80;
11718 \family default 
11719
11720 \begin_inset Quotes sld
11721 \end_inset 
11722
11723  is not atomic if 
11724 \family typewriter 
11725 flags
11726 \family default 
11727  resides in xdata.
11728  Setting 
11729 \begin_inset Quotes srd
11730 \end_inset 
11731
11732
11733 \family typewriter 
11734 flags\SpecialChar ~
11735 |=\SpecialChar ~
11736 0x40;
11737 \family default 
11738
11739 \begin_inset Quotes sld
11740 \end_inset 
11741
11742  from within an interrupt routine might get lost if the interrupt occurs
11743  at the wrong time.
11744  
11745 \begin_inset Quotes sld
11746 \end_inset 
11747
11748
11749 \family typewriter 
11750 counter\SpecialChar ~
11751 +=\SpecialChar ~
11752 8;
11753 \family default 
11754
11755 \begin_inset Quotes srd
11756 \end_inset 
11757
11758  is not atomic on the 8051 even if 
11759 \family typewriter 
11760 counter
11761 \family default 
11762  is located in data memory.
11763 \newline 
11764 Bugs like these are hard to reproduce and can cause a lot of trouble.
11765  
11766 \layout Subsubsection
11767
11768
11769 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11770
11771 \end_inset 
11772
11773 Common interrupt pitfall: 
11774 \emph on 
11775 stack overflow
11776 \layout Standard
11777
11778 The return address and the registers used in the interrupt service routine
11779  are saved on the stack
11780 \begin_inset LatexCommand \index{stack}
11781
11782 \end_inset 
11783
11784  so there must be sufficient stack space.
11785  If there isn't variables or registers (or even the return address itself)
11786  will be corrupted.
11787  This 
11788 \emph on 
11789 stack overflow
11790 \emph default 
11791
11792 \begin_inset LatexCommand \index{stack overflow}
11793
11794 \end_inset 
11795
11796  is most likely to happen if the interrupt occurs during the 
11797 \begin_inset Quotes sld
11798 \end_inset 
11799
11800 deepest
11801 \begin_inset Quotes srd
11802 \end_inset 
11803
11804  subroutine when the stack is already in use for f.e.
11805  many return addresses.
11806 \layout Subsubsection
11807
11808
11809 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11810
11811 \end_inset 
11812
11813 Common interrupt pitfall: 
11814 \emph on 
11815 use of non-reentrant functions
11816 \layout Standard
11817
11818 A special note here, int (16 bit) and long (32 bit) integer division
11819 \begin_inset LatexCommand \index{Division}
11820
11821 \end_inset 
11822
11823 , multiplication
11824 \begin_inset LatexCommand \index{Multiplication}
11825
11826 \end_inset 
11827
11828  & modulus
11829 \begin_inset LatexCommand \index{Modulus}
11830
11831 \end_inset 
11832
11833  and floating-point
11834 \begin_inset LatexCommand \index{Floating point support}
11835
11836 \end_inset 
11837
11838  operations are implemented using external support routines.
11839  If an interrupt service routine needs to do any of these operations then
11840  the support routines (as mentioned in a following section) will have to
11841  be recompiled using the
11842 \emph on 
11843  -
11844 \begin_inset ERT
11845 status Collapsed
11846
11847 \layout Standard
11848
11849 \backslash 
11850 /
11851 \end_inset 
11852
11853 -stack-auto
11854 \begin_inset LatexCommand \index{-\/-stack-auto}
11855
11856 \end_inset 
11857
11858
11859 \emph default 
11860  option and the source file will need to be compiled using the 
11861 \emph on 
11862 -
11863 \begin_inset ERT
11864 status Collapsed
11865
11866 \layout Standard
11867
11868 \backslash 
11869 /
11870 \end_inset 
11871
11872 -int-long-reent
11873 \emph default 
11874
11875 \begin_inset LatexCommand \index{-\/-int-long-reent}
11876
11877 \end_inset 
11878
11879  compiler option.
11880  
11881 \newline 
11882 Note, the type promotion
11883 \begin_inset LatexCommand \index{type promotion}
11884
11885 \end_inset 
11886
11887  required by ANSI C can cause 16 bit routines to be used
11888 \begin_inset Marginal
11889 collapsed true
11890
11891 \layout Standard
11892
11893
11894 \series bold 
11895 \SpecialChar ~
11896 !
11897 \end_inset 
11898
11899  without the programmer being aware of it.
11900  See f.e.
11901  the cast 
11902 \family typewriter 
11903 (unsigned char)(tail-1)
11904 \family default 
11905  within the if clause in section 
11906 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11907
11908 \end_inset 
11909
11910 .
11911 \layout Standard
11912 \added_space_bottom bigskip 
11913 Calling other functions from an interrupt service routine is not recommended,
11914  avoid it if possible.
11915  Note that when some function is called from an interrupt service routine
11916  it should be preceded by a #pragma\SpecialChar ~
11917 nooverlay
11918 \begin_inset LatexCommand \index{\#pragma nooverlay}
11919
11920 \end_inset 
11921
11922  if it is not reentrant.
11923  Furthermore nonreentrant functions should not be called from the main program
11924  while the interrupt service routine might be active.
11925  They also must not be called from low priority interrupt service routines
11926  while a high priority interrupt service routine might be active.
11927  You could use semaphores or make the function
11928 \emph on 
11929  critical
11930 \emph default 
11931  if all parameters are passed in registers.
11932 \newline 
11933  Also see section 
11934 \begin_inset LatexCommand \ref{sub:Overlaying}
11935
11936 \end_inset 
11937
11938 \SpecialChar ~
11939 about Overlaying and section 
11940 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11941
11942 \end_inset 
11943
11944 \SpecialChar ~
11945 about Functions using private register banks.
11946 \layout Subsection
11947
11948 MCS51/DS390 Interrupt Service Routines
11949 \layout Standard
11950
11951 Interrupt
11952 \begin_inset LatexCommand \index{interrupt}
11953
11954 \end_inset 
11955
11956  numbers and the corresponding address & descriptions for the Standard 8051/8052
11957  are listed below.
11958  SDCC will automatically adjust the 
11959 \begin_inset LatexCommand \index{interrupt vector table}
11960
11961 \end_inset 
11962
11963  to the maximum interrupt number specified.
11964 \newline 
11965
11966 \layout Standard
11967 \align center 
11968
11969 \begin_inset  Tabular
11970 <lyxtabular version="3" rows="9" columns="3">
11971 <features>
11972 <column alignment="center" valignment="top" leftline="true" width="0in">
11973 <column alignment="left" valignment="top" leftline="true" width="0in">
11974 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
11975 <row topline="true" bottomline="true">
11976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11977 \begin_inset Text
11978
11979 \layout Standard
11980
11981 Interrupt #
11982 \end_inset 
11983 </cell>
11984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11985 \begin_inset Text
11986
11987 \layout Standard
11988
11989 Description
11990 \end_inset 
11991 </cell>
11992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11993 \begin_inset Text
11994
11995 \layout Standard
11996
11997 Vector Address
11998 \end_inset 
11999 </cell>
12000 </row>
12001 <row topline="true">
12002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12003 \begin_inset Text
12004
12005 \layout Standard
12006
12007 0
12008 \end_inset 
12009 </cell>
12010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12011 \begin_inset Text
12012
12013 \layout Standard
12014
12015 External 0
12016 \end_inset 
12017 </cell>
12018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12019 \begin_inset Text
12020
12021 \layout Standard
12022
12023 0x0003
12024 \end_inset 
12025 </cell>
12026 </row>
12027 <row topline="true">
12028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12029 \begin_inset Text
12030
12031 \layout Standard
12032
12033 1
12034 \end_inset 
12035 </cell>
12036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12037 \begin_inset Text
12038
12039 \layout Standard
12040
12041 Timer 0
12042 \end_inset 
12043 </cell>
12044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12045 \begin_inset Text
12046
12047 \layout Standard
12048
12049 0x000b
12050 \end_inset 
12051 </cell>
12052 </row>
12053 <row topline="true">
12054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12055 \begin_inset Text
12056
12057 \layout Standard
12058
12059 2
12060 \end_inset 
12061 </cell>
12062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12063 \begin_inset Text
12064
12065 \layout Standard
12066
12067 External 1
12068 \end_inset 
12069 </cell>
12070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12071 \begin_inset Text
12072
12073 \layout Standard
12074
12075 0x0013
12076 \end_inset 
12077 </cell>
12078 </row>
12079 <row topline="true">
12080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12081 \begin_inset Text
12082
12083 \layout Standard
12084
12085 3
12086 \end_inset 
12087 </cell>
12088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12089 \begin_inset Text
12090
12091 \layout Standard
12092
12093 Timer 1
12094 \end_inset 
12095 </cell>
12096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12097 \begin_inset Text
12098
12099 \layout Standard
12100
12101 0x001b
12102 \end_inset 
12103 </cell>
12104 </row>
12105 <row topline="true">
12106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12107 \begin_inset Text
12108
12109 \layout Standard
12110
12111 4
12112 \end_inset 
12113 </cell>
12114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12115 \begin_inset Text
12116
12117 \layout Standard
12118
12119 Serial
12120 \end_inset 
12121 </cell>
12122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12123 \begin_inset Text
12124
12125 \layout Standard
12126
12127 0x0023
12128 \end_inset 
12129 </cell>
12130 </row>
12131 <row topline="true">
12132 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12133 \begin_inset Text
12134
12135 \layout Standard
12136
12137 5
12138 \end_inset 
12139 </cell>
12140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12141 \begin_inset Text
12142
12143 \layout Standard
12144
12145 Timer 2 (8052)
12146 \end_inset 
12147 </cell>
12148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12149 \begin_inset Text
12150
12151 \layout Standard
12152
12153 0x002b
12154 \end_inset 
12155 </cell>
12156 </row>
12157 <row topline="true">
12158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12159 \begin_inset Text
12160
12161 \layout Standard
12162
12163 ...
12164 \end_inset 
12165 </cell>
12166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12167 \begin_inset Text
12168
12169 \layout Standard
12170
12171 \end_inset 
12172 </cell>
12173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12174 \begin_inset Text
12175
12176 \layout Standard
12177
12178 ...
12179 \end_inset 
12180 </cell>
12181 </row>
12182 <row topline="true" bottomline="true">
12183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12184 \begin_inset Text
12185
12186 \layout Standard
12187
12188 n
12189 \end_inset 
12190 </cell>
12191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12192 \begin_inset Text
12193
12194 \layout Standard
12195
12196 \end_inset 
12197 </cell>
12198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12199 \begin_inset Text
12200
12201 \layout Standard
12202
12203 0x0003 + 8*n
12204 \end_inset 
12205 </cell>
12206 </row>
12207 </lyxtabular>
12208
12209 \end_inset 
12210
12211
12212 \newline 
12213
12214 \layout Standard
12215
12216 If the interrupt service routine is defined without 
12217 \emph on 
12218 using
12219 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12220
12221 \end_inset 
12222
12223
12224 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12225
12226 \end_inset 
12227
12228
12229 \emph default 
12230  a register bank or with register bank 0 (
12231 \emph on 
12232 using
12233 \emph default 
12234  0), the compiler will save the registers used by itself on the stack upon
12235  entry and restore them at exit, however if such an interrupt service routine
12236  calls another function then the entire register bank will be saved on the
12237  stack.
12238  This scheme may be advantageous for small interrupt service routines which
12239  have low register usage.
12240 \layout Standard
12241 \added_space_bottom bigskip 
12242 If the interrupt service routine is defined to be using a specific register
12243  bank then only 
12244 \emph on 
12245 a, b, dptr
12246 \emph default 
12247  & psw are saved and restored, if such an interrupt service routine calls
12248  another function (using another register bank) then the entire register
12249  bank of the called function will be saved on the stack
12250 \begin_inset LatexCommand \index{stack}
12251
12252 \end_inset 
12253
12254 .
12255  This scheme is recommended for larger interrupt service routines.
12256 \layout Subsection
12257
12258 HC08
12259 \begin_inset LatexCommand \index{HC08}
12260
12261 \end_inset 
12262
12263  Interrupt Service Routines
12264 \layout Standard
12265 \added_space_bottom bigskip 
12266 Since the number of interrupts
12267 \begin_inset LatexCommand \index{HC08!interrupt}
12268
12269 \end_inset 
12270
12271  available is chip specific and the interrupt vector table always ends at
12272  the last byte of memory, the interrupt numbers corresponds to the interrupt
12273  vectors in reverse order of address.
12274  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12275  2 will use the interrupt vector at 0xfffa, and so on.
12276  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12277  this way; instead see section 
12278 \begin_inset LatexCommand \ref{sub:Startup-Code}
12279
12280 \end_inset 
12281
12282  for details on customizing startup.
12283 \layout Subsection
12284
12285 Z80 Interrupt Service Routines
12286 \layout Standard
12287
12288 The Z80
12289 \begin_inset LatexCommand \index{Z80}
12290
12291 \end_inset 
12292
12293  uses several different methods for determining the correct interrupt
12294 \begin_inset LatexCommand \index{Z80!interrupt}
12295
12296 \end_inset 
12297
12298  vector depending on the hardware implementation.
12299  Therefore, SDCC ignores the optional interrupt number and does not attempt
12300  to generate an interrupt vector table.
12301 \layout Standard
12302
12303 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12304  instruction to return from the interrupt.
12305  To write an interrupt handler for the non-maskable interrupt, which needs
12306  a RETN instruction instead, add the 
12307 \emph on 
12308 critical
12309 \emph default 
12310  keyword:
12311 \layout Verse
12312
12313
12314 \family typewriter 
12315 void nmi_isr (void) critical interrupt
12316 \newline 
12317
12318 \newline 
12319 \SpecialChar ~
12320 \SpecialChar ~
12321 \SpecialChar ~
12322 \SpecialChar ~
12323 ...
12324  
12325 \newline 
12326 }
12327 \layout Standard
12328 \added_space_bottom bigskip 
12329 However if you need to create a non-interruptable interrupt service routine
12330  you would also require the 
12331 \emph on 
12332 critical
12333 \emph default 
12334  keyword.
12335  To distinguish between this and an nmi_isr you must provide an interrupt
12336  number.
12337 \layout Section
12338
12339 Enabling and Disabling Interrupts
12340 \layout Subsection
12341
12342 Critical Functions and Critical Statements
12343 \layout Standard
12344
12345 A special keyword may be associated with a block or a function declaring
12346  it as 
12347 \emph on 
12348 critical
12349 \emph default 
12350 .
12351  SDCC will generate code to disable all interrupts
12352 \begin_inset LatexCommand \index{interrupt}
12353
12354 \end_inset 
12355
12356  upon entry to a critical function and restore the interrupt enable to the
12357  previous state before returning.
12358  Nesting critical functions will need one additional byte on the stack
12359 \begin_inset LatexCommand \index{stack}
12360
12361 \end_inset 
12362
12363  for each call.
12364 \layout Verse
12365
12366
12367 \family typewriter 
12368 int foo () __critical
12369 \begin_inset LatexCommand \index{critical}
12370
12371 \end_inset 
12372
12373
12374 \begin_inset LatexCommand \index{\_\_critical}
12375
12376 \end_inset 
12377
12378  
12379 \newline 
12380
12381 \newline 
12382 \SpecialChar ~
12383 \SpecialChar ~
12384 \SpecialChar ~
12385 \SpecialChar ~
12386 ...
12387  
12388 \newline 
12389 \SpecialChar ~
12390 \SpecialChar ~
12391 \SpecialChar ~
12392 \SpecialChar ~
12393 ...
12394  
12395 \newline 
12396 }
12397 \layout Standard
12398
12399 The critical attribute maybe used with other attributes like 
12400 \emph on 
12401 reentrant.
12402 \emph default 
12403
12404 \newline 
12405 The keyword 
12406 \emph on 
12407 critical
12408 \emph default 
12409  may also be used to disable interrupts more locally:
12410 \layout Verse
12411
12412
12413 \family typewriter 
12414 __critical{ i++; }
12415 \layout Standard
12416
12417 More than one statement could have been included in the block.
12418 \layout Subsection
12419
12420 Enabling and Disabling Interrupts directly
12421 \layout Standard
12422
12423 Interrupts
12424 \begin_inset LatexCommand \index{interrupt}
12425
12426 \end_inset 
12427
12428  can also be disabled and enabled directly (8051):
12429 \layout Verse
12430
12431
12432 \family typewriter 
12433 EA = 0;\SpecialChar ~
12434 \SpecialChar ~
12435 \SpecialChar ~
12436 \SpecialChar ~
12437 \SpecialChar ~
12438 \SpecialChar ~
12439 \SpecialChar ~
12440 \SpecialChar ~
12441 \SpecialChar ~
12442 \SpecialChar ~
12443 \SpecialChar ~
12444 \SpecialChar ~
12445 or:\SpecialChar ~
12446 \SpecialChar ~
12447 \SpecialChar ~
12448 \SpecialChar ~
12449 \SpecialChar ~
12450 \SpecialChar ~
12451 \SpecialChar ~
12452 \SpecialChar ~
12453 \SpecialChar ~
12454 \SpecialChar ~
12455 \SpecialChar ~
12456 EA_SAVE = EA;
12457 \layout Verse
12458
12459
12460 \family typewriter 
12461 ...\SpecialChar ~
12462 \SpecialChar ~
12463 \SpecialChar ~
12464 \SpecialChar ~
12465 \SpecialChar ~
12466 \SpecialChar ~
12467 \SpecialChar ~
12468 \SpecialChar ~
12469 \SpecialChar ~
12470 \SpecialChar ~
12471 \SpecialChar ~
12472 \SpecialChar ~
12473 \SpecialChar ~
12474 \SpecialChar ~
12475 \SpecialChar ~
12476 \SpecialChar ~
12477 \SpecialChar ~
12478 \SpecialChar ~
12479 \SpecialChar ~
12480 \SpecialChar ~
12481 \SpecialChar ~
12482 \SpecialChar ~
12483 \SpecialChar ~
12484 \SpecialChar ~
12485 \SpecialChar ~
12486 \SpecialChar ~
12487 \SpecialChar ~
12488 \SpecialChar ~
12489 \SpecialChar ~
12490 \SpecialChar ~
12491 EA = 0;
12492 \layout Verse
12493
12494
12495 \family typewriter 
12496 EA = 1;\SpecialChar ~
12497 \SpecialChar ~
12498 \SpecialChar ~
12499 \SpecialChar ~
12500 \SpecialChar ~
12501 \SpecialChar ~
12502 \SpecialChar ~
12503 \SpecialChar ~
12504 \SpecialChar ~
12505 \SpecialChar ~
12506 \SpecialChar ~
12507 \SpecialChar ~
12508 \SpecialChar ~
12509 \SpecialChar ~
12510 \SpecialChar ~
12511 \SpecialChar ~
12512 \SpecialChar ~
12513 \SpecialChar ~
12514 \SpecialChar ~
12515 \SpecialChar ~
12516 \SpecialChar ~
12517 \SpecialChar ~
12518 \SpecialChar ~
12519 \SpecialChar ~
12520 \SpecialChar ~
12521 \SpecialChar ~
12522 ...
12523 \layout Verse
12524
12525
12526 \family typewriter 
12527 \SpecialChar ~
12528 \SpecialChar ~
12529 \SpecialChar ~
12530 \SpecialChar ~
12531 \SpecialChar ~
12532 \SpecialChar ~
12533 \SpecialChar ~
12534 \SpecialChar ~
12535 \SpecialChar ~
12536 \SpecialChar ~
12537 \SpecialChar ~
12538 \SpecialChar ~
12539 \SpecialChar ~
12540 \SpecialChar ~
12541 \SpecialChar ~
12542 \SpecialChar ~
12543 \SpecialChar ~
12544 \SpecialChar ~
12545 \SpecialChar ~
12546 \SpecialChar ~
12547 \SpecialChar ~
12548 \SpecialChar ~
12549 \SpecialChar ~
12550 \SpecialChar ~
12551 \SpecialChar ~
12552 \SpecialChar ~
12553 \SpecialChar ~
12554 \SpecialChar ~
12555 \SpecialChar ~
12556 \SpecialChar ~
12557 \SpecialChar ~
12558 \SpecialChar ~
12559 \SpecialChar ~
12560 EA = EA_SAVE;
12561 \layout Standard
12562
12563 On other architectures which have seperate opcodes for enabling and disabling
12564  interrupts you might want to make use of defines with inline assembly
12565 \begin_inset LatexCommand \index{Assembler routines}
12566
12567 \end_inset 
12568
12569  (HC08
12570 \begin_inset LatexCommand \index{HC08!interrupt}
12571
12572 \end_inset 
12573
12574 ):
12575 \layout Verse
12576
12577
12578 \family typewriter 
12579 #define CLI _asm
12580 \begin_inset LatexCommand \index{\_asm}
12581
12582 \end_inset 
12583
12584 \SpecialChar ~
12585 \SpecialChar ~
12586 cli\SpecialChar ~
12587 \SpecialChar ~
12588 _endasm
12589 \begin_inset LatexCommand \index{\_endasm}
12590
12591 \end_inset 
12592
12593
12594 \layout Verse
12595
12596
12597 \family typewriter 
12598 #define SEI _asm\SpecialChar ~
12599 \SpecialChar ~
12600 sei\SpecialChar ~
12601 \SpecialChar ~
12602 _endasm; 
12603 \layout Verse
12604
12605
12606 \family typewriter 
12607 ...
12608 \layout Standard
12609
12610 Note: it is sometimes sufficient to disable only a specific interrupt source
12611  like f.e.
12612  a timer or serial interrupt by manipulating an 
12613 \emph on 
12614 interrupt mask
12615 \begin_inset LatexCommand \index{interrupt mask}
12616
12617 \end_inset 
12618
12619
12620 \emph default 
12621  register.
12622  
12623 \layout Standard
12624
12625 Usually the time during which interrupts are disabled should be kept as
12626  short as possible.
12627  This minimizes both 
12628 \emph on 
12629 interrupt latency
12630 \emph default 
12631
12632 \begin_inset LatexCommand \index{interrupt latency}
12633
12634 \end_inset 
12635
12636  (the time between the occurrence of the interrupt and the execution of
12637  the first code in the interrupt routine) and 
12638 \emph on 
12639 interrupt jitter
12640 \emph default 
12641
12642 \begin_inset LatexCommand \index{interrupt jitter}
12643
12644 \end_inset 
12645
12646  (the difference between the shortest and the longest interrupt latency).
12647  These really are something different, f.e.
12648  a serial interrupt has to be served before its buffer overruns so it cares
12649  for the maximum interrupt latency, whereas it does not care about jitter.
12650  On a loudspeaker driven via a digital to analog converter which is fed
12651  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12652  a much smaller jitter will be very audible.
12653 \layout Standard
12654
12655 You can reenable interrupts within an interrupt routine and on some architecture
12656 s you can make use of two (or more) levels of 
12657 \emph on 
12658 interrupt priorities
12659 \emph default 
12660
12661 \begin_inset LatexCommand \index{interrupt priority}
12662
12663 \end_inset 
12664
12665 .
12666  On some architectures which don't support interrupt priorities these can
12667  be implemented by manipulating the interrupt mask and reenabling interrupts
12668  within the interrupt routine.
12669  Check there is sufficient space on the stack
12670 \begin_inset LatexCommand \index{stack}
12671
12672 \end_inset 
12673
12674  and don't add complexity unless you have to.
12675  
12676 \layout Subsection
12677
12678 Semaphore
12679 \begin_inset LatexCommand \index{semaphore}
12680
12681 \end_inset 
12682
12683  locking (mcs51/ds390)
12684 \layout Standard
12685
12686 Some architectures (mcs51/ds390) have an atomic
12687 \begin_inset LatexCommand \index{atomic}
12688
12689 \end_inset 
12690
12691  bit test and
12692 \emph on 
12693  
12694 \emph default 
12695 clear
12696 \emph on 
12697  
12698 \emph default 
12699 instruction.
12700  These type of instructions are typically used in preemptive multitasking
12701  systems, where a routine f.e.
12702  claims the use of a data structure ('acquires a lock
12703 \begin_inset LatexCommand \index{lock}
12704
12705 \end_inset 
12706
12707  on it'), makes some modifications and then releases the lock when the data
12708  structure is consistent again.
12709  The instruction may also be used if interrupt and non-interrupt code have
12710  to compete for a resource.
12711  With the atomic bit test and clear instruction interrupts
12712 \begin_inset LatexCommand \index{interrupt}
12713
12714 \end_inset 
12715
12716  don't have to be disabled for the locking operation.
12717  
12718 \layout Standard
12719
12720 SDCC generates this instruction if the source follows this pattern:
12721 \layout Verse
12722
12723
12724 \family typewriter 
12725 volatile
12726 \begin_inset LatexCommand \index{volatile}
12727
12728 \end_inset 
12729
12730  bit resource_is_free; 
12731 \newline 
12732
12733 \newline 
12734 if (resource_is_free) 
12735 \newline 
12736 \SpecialChar ~
12737 \SpecialChar ~
12738
12739 \newline 
12740 \SpecialChar ~
12741 \SpecialChar ~
12742 \SpecialChar ~
12743 \SpecialChar ~
12744 resource_is_free=0; 
12745 \newline 
12746 \SpecialChar ~
12747 \SpecialChar ~
12748 \SpecialChar ~
12749 \SpecialChar ~
12750 ...
12751  
12752 \newline 
12753 \SpecialChar ~
12754 \SpecialChar ~
12755 \SpecialChar ~
12756 \SpecialChar ~
12757 resource_is_free=1;
12758 \newline 
12759 \SpecialChar ~
12760 \SpecialChar ~
12761
12762 \layout Standard
12763
12764 Note, mcs51 and ds390 support only an atomic
12765 \begin_inset LatexCommand \index{atomic}
12766
12767 \end_inset 
12768
12769  bit test and 
12770 \emph on 
12771 clear
12772 \emph default 
12773  instruction (as opposed to atomic bit test and 
12774 \emph on 
12775 set).
12776 \layout Section
12777
12778 Functions using private register banks
12779 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12780
12781 \end_inset 
12782
12783  (mcs51/ds390)
12784 \layout Standard
12785
12786 Some architectures have support for quickly changing register sets.
12787  SDCC supports this feature with the 
12788 \emph on 
12789 using
12790 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12791
12792 \end_inset 
12793
12794
12795 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12796
12797 \end_inset 
12798
12799
12800 \emph default 
12801  attribute (which tells the compiler to use a register bank
12802 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12803
12804 \end_inset 
12805
12806  other than the default bank zero).
12807  It should only be applied to 
12808 \emph on 
12809 interrupt
12810 \begin_inset LatexCommand \index{interrupt}
12811
12812 \end_inset 
12813
12814
12815 \emph default 
12816  functions (see footnote below).
12817  This will in most circumstances make the generated ISR code more efficient
12818  since it will not have to save registers on the stack.
12819 \layout Standard
12820
12821 The 
12822 \emph on 
12823 using
12824 \emph default 
12825  attribute will have no effect on the generated code for a 
12826 \emph on 
12827 non-interrupt
12828 \emph default 
12829  function (but may occasionally be useful anyway
12830 \begin_inset Foot
12831 collapsed false
12832
12833 \layout Standard
12834
12835 possible exception: if a function is called ONLY from 'interrupt' functions
12836  using a particular bank, it can be declared with the same 'using' attribute
12837  as the calling 'interrupt' functions.
12838  For instance, if you have several ISRs using bank one, and all of them
12839  call memcpy(), it might make sense to create a specialized version of memcpy()
12840  'using 1', since this would prevent the ISR from having to save bank zero
12841  to the stack on entry and switch to bank zero before calling the function
12842 \end_inset 
12843
12844 ).
12845 \newline 
12846
12847 \emph on 
12848 (pending: Note, nowadays the 
12849 \emph default 
12850 using
12851 \emph on 
12852  attribute has an effect on
12853 \emph default 
12854  
12855 \emph on 
12856 the generated code for a 
12857 \emph default 
12858 non-interrupt
12859 \emph on 
12860  function
12861 \emph default 
12862 .
12863 \emph on 
12864 )
12865 \layout Standard
12866
12867 An 
12868 \emph on 
12869 interrupt
12870 \emph default 
12871  function using a non-zero bank will assume that it can trash that register
12872  bank, and will not save it.
12873  Since high-priority interrupts
12874 \begin_inset LatexCommand \index{interrupts}
12875
12876 \end_inset 
12877
12878
12879 \begin_inset LatexCommand \index{interrupt priority}
12880
12881 \end_inset 
12882
12883  can interrupt low-priority ones on the 8051 and friends, this means that
12884  if a high-priority ISR 
12885 \emph on 
12886 using
12887 \emph default 
12888  a particular bank occurs while processing a low-priority ISR 
12889 \emph on 
12890 using
12891 \emph default 
12892  the same bank, terrible and bad things can happen.
12893  To prevent this, no single register bank should be 
12894 \emph on 
12895 used
12896 \emph default 
12897  by both a high priority and a low priority ISR.
12898  This is probably most easily done by having all high priority ISRs use
12899  one bank and all low priority ISRs use another.
12900  If you have an ISR which can change priority at runtime, you're on your
12901  own: I suggest using the default bank zero and taking the small performance
12902  hit.
12903 \layout Standard
12904 \added_space_bottom bigskip 
12905 It is most efficient if your ISR calls no other functions.
12906  If your ISR must call other functions, it is most efficient if those functions
12907  use the same bank as the ISR (see note 1 below); the next best is if the
12908  called functions use bank zero.
12909  It is very inefficient to call a function using a different, non-zero bank
12910  from an ISR.
12911  
12912 \layout Section
12913
12914 Startup Code
12915 \begin_inset LatexCommand \label{sub:Startup-Code}
12916
12917 \end_inset 
12918
12919
12920 \begin_inset LatexCommand \index{Startup code}
12921
12922 \end_inset 
12923
12924
12925 \layout Subsection
12926
12927 MCS51/DS390 Startup Code
12928 \layout Standard
12929
12930 The compiler inserts a call to the C routine 
12931 \emph on 
12932 _sdcc_external_startup()
12933 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12934
12935 \end_inset 
12936
12937
12938 \series bold 
12939 \emph default 
12940  
12941 \series default 
12942 at the start of the CODE area.
12943  This routine is in the runtime library
12944 \begin_inset LatexCommand \index{Runtime library}
12945
12946 \end_inset 
12947
12948 .
12949  By default this routine returns 0, if this routine returns a non-zero value,
12950  the static & global variable initialization will be skipped and the function
12951  main will be invoked.
12952  Otherwise static & global variables will be initialized before the function
12953  main is invoked.
12954  You could add a 
12955 \emph on 
12956 _sdcc_external_startup()
12957 \emph default 
12958  routine to your program to override the default if you need to setup hardware
12959  or perform some other critical operation prior to static & global variable
12960  initialization
12961 \begin_inset LatexCommand \index{Variable initialization}
12962
12963 \end_inset 
12964
12965 .
12966  On some mcs51 variants xdata
12967 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12968
12969 \end_inset 
12970
12971  memory has to be explicitly enabled before it can be accessed or if the
12972  watchdog
12973 \begin_inset LatexCommand \index{watchdog}
12974
12975 \end_inset 
12976
12977  needs to be disabled, this is the place to do it.
12978  The startup code clears all internal data memory, 256 bytes by default,
12979  but from 0 to n-1 if 
12980 \emph on 
12981 -
12982 \begin_inset ERT
12983 status Collapsed
12984
12985 \layout Standard
12986
12987 \backslash 
12988 /
12989 \end_inset 
12990
12991 -iram-size
12992 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12993
12994 \end_inset 
12995
12996 n
12997 \emph default 
12998  is used.
12999  (recommended for Chipcon CC1010).
13000 \layout Standard
13001 \added_space_bottom bigskip 
13002 See also the compiler options 
13003 \emph on 
13004 -
13005 \begin_inset ERT
13006 status Collapsed
13007
13008 \layout Standard
13009
13010 \backslash 
13011 /
13012 \end_inset 
13013
13014 -no-xinit
13015 \emph default 
13016 -
13017 \emph on 
13018 opt
13019 \emph default 
13020
13021 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13022
13023 \end_inset 
13024
13025
13026 \emph on 
13027 -
13028 \begin_inset ERT
13029 status Collapsed
13030
13031 \layout Standard
13032
13033 \backslash 
13034 /
13035 \end_inset 
13036
13037 -main-return
13038 \emph default 
13039
13040 \begin_inset LatexCommand \index{-\/-main-return}
13041
13042 \end_inset 
13043
13044  and section 
13045 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13046
13047 \end_inset 
13048
13049  about MCS51-variants.
13050 \layout Subsection
13051
13052 HC08 Startup Code
13053 \layout Standard
13054 \added_space_bottom bigskip 
13055 The HC08
13056 \begin_inset LatexCommand \index{HC08}
13057
13058 \end_inset 
13059
13060  startup code follows the same scheme as the MCS51 startup code.
13061 \layout Subsection
13062
13063 Z80 Startup Code
13064 \layout Standard
13065 \added_space_bottom bigskip 
13066 On the Z80
13067 \begin_inset LatexCommand \index{Z80}
13068
13069 \end_inset 
13070
13071  the startup code is inserted by linking with crt0.o which is generated from
13072  sdcc/device/lib/z80/crt0.s.
13073  If you need a different startup code you can use the compiler option 
13074 \emph on 
13075 -
13076 \series bold 
13077 \emph default 
13078
13079 \begin_inset ERT
13080 status Collapsed
13081
13082 \layout Standard
13083
13084 \backslash 
13085 /
13086 \end_inset 
13087
13088
13089 \series default 
13090 \emph on 
13091 -no-std-crt0
13092 \emph default 
13093
13094 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13095
13096 \end_inset 
13097
13098  and provide your own crt0.o.
13099  
13100 \layout Section
13101
13102 Inline Assembler Code
13103 \begin_inset LatexCommand \index{Assembler routines}
13104
13105 \end_inset 
13106
13107
13108 \layout Subsection
13109
13110 A Step by Step Introduction
13111 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13112
13113 \end_inset 
13114
13115
13116 \layout Standard
13117
13118 Starting from a small snippet of c-code this example shows for the MCS51
13119  how to use inline assembly, access variables, a function parameter and
13120  an array in xdata memory.
13121  The example uses an MCS51 here but is easily adapted for other architectures.
13122  This is a buffer routine which should be optimized:
13123 \layout Verse
13124
13125
13126 \family typewriter 
13127 \size footnotesize 
13128 unsigned char __far
13129 \begin_inset LatexCommand \index{far (storage class)}
13130
13131 \end_inset 
13132
13133
13134 \begin_inset LatexCommand \index{\_\_far (storage class)}
13135
13136 \end_inset 
13137
13138  __at
13139 \begin_inset LatexCommand \index{at}
13140
13141 \end_inset 
13142
13143
13144 \begin_inset LatexCommand \index{\_\_at}
13145
13146 \end_inset 
13147
13148 (0x7f00) buf[0x100];
13149 \begin_inset LatexCommand \index{Aligned array}
13150
13151 \end_inset 
13152
13153
13154 \newline 
13155 unsigned char head, tail;\SpecialChar ~
13156 \SpecialChar ~
13157 \SpecialChar ~
13158 \SpecialChar ~
13159 \SpecialChar ~
13160 \SpecialChar ~
13161 \SpecialChar ~
13162 \SpecialChar ~
13163 \SpecialChar ~
13164 \SpecialChar ~
13165 \SpecialChar ~
13166 \SpecialChar ~
13167 \SpecialChar ~
13168 \SpecialChar ~
13169 \SpecialChar ~
13170 \SpecialChar ~
13171 \SpecialChar ~
13172 /* if interrupts
13173 \begin_inset LatexCommand \index{interrupt}
13174
13175 \end_inset 
13176
13177  are involved see
13178 \newline 
13179 \SpecialChar ~
13180 \SpecialChar ~
13181 \SpecialChar ~
13182 \SpecialChar ~
13183 \SpecialChar ~
13184 \SpecialChar ~
13185 \SpecialChar ~
13186 \SpecialChar ~
13187 \SpecialChar ~
13188 \SpecialChar ~
13189 \SpecialChar ~
13190 \SpecialChar ~
13191 \SpecialChar ~
13192 \SpecialChar ~
13193 \SpecialChar ~
13194 \SpecialChar ~
13195 \SpecialChar ~
13196 \SpecialChar ~
13197 \SpecialChar ~
13198 \SpecialChar ~
13199 \SpecialChar ~
13200 \SpecialChar ~
13201 \SpecialChar ~
13202 \SpecialChar ~
13203 \SpecialChar ~
13204 \SpecialChar ~
13205 \SpecialChar ~
13206 \SpecialChar ~
13207 \SpecialChar ~
13208 \SpecialChar ~
13209 \SpecialChar ~
13210 \SpecialChar ~
13211 \SpecialChar ~
13212 \SpecialChar ~
13213 \SpecialChar ~
13214 \SpecialChar ~
13215 \SpecialChar ~
13216 \SpecialChar ~
13217 \SpecialChar ~
13218 \SpecialChar ~
13219 \SpecialChar ~
13220 \SpecialChar ~
13221 \SpecialChar ~
13222 \SpecialChar ~
13223 \SpecialChar ~
13224 section 
13225 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13226
13227 \end_inset 
13228
13229  about
13230 \series bold 
13231  volatile
13232 \series default 
13233  */
13234 \newline 
13235
13236 \newline 
13237 void to_buffer( unsigned char c ) 
13238 \newline 
13239 {
13240 \newline 
13241 \SpecialChar ~
13242 \SpecialChar ~
13243 \SpecialChar ~
13244 \SpecialChar ~
13245 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13246 /* cast 
13247 \series bold 
13248 needed
13249 \series default 
13250  to avoid promotion
13251 \begin_inset LatexCommand \index{promotion to signed int}
13252
13253 \end_inset 
13254
13255
13256 \begin_inset LatexCommand \index{type promotion}
13257
13258 \end_inset 
13259
13260  to integer */
13261 \begin_inset Marginal
13262 collapsed true
13263
13264 \layout Standard
13265
13266
13267 \series bold 
13268 \SpecialChar ~
13269 !
13270 \end_inset 
13271
13272
13273 \newline 
13274 \SpecialChar ~
13275 \SpecialChar ~
13276 \SpecialChar ~
13277 \SpecialChar ~
13278 \SpecialChar ~
13279 \SpecialChar ~
13280 \SpecialChar ~
13281 \SpecialChar ~
13282 buf[ head++ ] = c;\SpecialChar ~
13283 \SpecialChar ~
13284 \SpecialChar ~
13285 \SpecialChar ~
13286 \SpecialChar ~
13287 \SpecialChar ~
13288 \SpecialChar ~
13289 \SpecialChar ~
13290 \SpecialChar ~
13291 \SpecialChar ~
13292 \SpecialChar ~
13293 \SpecialChar ~
13294 \SpecialChar ~
13295 \SpecialChar ~
13296 \SpecialChar ~
13297 \SpecialChar ~
13298 /* access to a 256 byte aligned array */
13299 \newline 
13300
13301 \layout Standard
13302
13303 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13304  then a corresponding buffer.asm file is generated.
13305  We define a new function 
13306 \family typewriter 
13307 to_buffer_asm()
13308 \family default 
13309  in file buffer.c in which we cut and paste the generated code, removing
13310  unwanted comments and some ':'.
13311  Then add 
13312 \begin_inset Quotes sld
13313 \end_inset 
13314
13315 _asm
13316 \begin_inset Quotes srd
13317 \end_inset 
13318
13319  and 
13320 \begin_inset Quotes sld
13321 \end_inset 
13322
13323 _endasm;
13324 \begin_inset Quotes srd
13325 \end_inset 
13326
13327  to the beginning and the end of the function body:
13328 \layout Verse
13329
13330
13331 \family typewriter 
13332 \size footnotesize 
13333 /* With a cut and paste from the .asm file, we have something to start with.
13334 \newline 
13335 \SpecialChar ~
13336 \SpecialChar ~
13337 \SpecialChar ~
13338 The function is not yet OK! (registers aren't saved) */ 
13339 \newline 
13340 void to_buffer_asm( unsigned char c ) 
13341 \newline 
13342
13343 \newline 
13344 \SpecialChar ~
13345 \SpecialChar ~
13346 \SpecialChar ~
13347 \SpecialChar ~
13348 _asm
13349 \begin_inset LatexCommand \index{\_asm}
13350
13351 \end_inset 
13352
13353
13354 \begin_inset LatexCommand \index{\_\_asm}
13355
13356 \end_inset 
13357
13358
13359 \newline 
13360 \SpecialChar ~
13361 \SpecialChar ~
13362 \SpecialChar ~
13363 \SpecialChar ~
13364 mov\SpecialChar ~
13365 \SpecialChar ~
13366 r2,dpl 
13367 \newline 
13368 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13369 /* cast 
13370 \series bold 
13371 needed
13372 \series default 
13373  to avoid promotion
13374 \begin_inset LatexCommand \index{promotion to signed int}
13375
13376 \end_inset 
13377
13378
13379 \begin_inset LatexCommand \index{type promotion}
13380
13381 \end_inset 
13382
13383  to integer */
13384 \newline 
13385 \SpecialChar ~
13386 \SpecialChar ~
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 mov\SpecialChar ~
13390 \SpecialChar ~
13391 a,_tail 
13392 \newline 
13393 \SpecialChar ~
13394 \SpecialChar ~
13395 \SpecialChar ~
13396 \SpecialChar ~
13397 dec\SpecialChar ~
13398 \SpecialChar ~
13399
13400 \newline 
13401 \SpecialChar ~
13402 \SpecialChar ~
13403 \SpecialChar ~
13404 \SpecialChar ~
13405 mov\SpecialChar ~
13406 \SpecialChar ~
13407 r3,a 
13408 \newline 
13409 \SpecialChar ~
13410 \SpecialChar ~
13411 \SpecialChar ~
13412 \SpecialChar ~
13413 mov\SpecialChar ~
13414 \SpecialChar ~
13415 a,_head 
13416 \newline 
13417 \SpecialChar ~
13418 \SpecialChar ~
13419 \SpecialChar ~
13420 \SpecialChar ~
13421 cjne a,ar3,00106$ 
13422 \newline 
13423 \SpecialChar ~
13424 \SpecialChar ~
13425 \SpecialChar ~
13426 \SpecialChar ~
13427 ret
13428 \newline 
13429 00106$: 
13430 \newline 
13431 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13432 \begin_inset LatexCommand \index{Aligned array}
13433
13434 \end_inset 
13435
13436
13437 \newline 
13438 \SpecialChar ~
13439 \SpecialChar ~
13440 \SpecialChar ~
13441 \SpecialChar ~
13442 mov\SpecialChar ~
13443 \SpecialChar ~
13444 r3,_head 
13445 \newline 
13446 \SpecialChar ~
13447 \SpecialChar ~
13448 \SpecialChar ~
13449 \SpecialChar ~
13450 inc\SpecialChar ~
13451 \SpecialChar ~
13452 _head 
13453 \newline 
13454 \SpecialChar ~
13455 \SpecialChar ~
13456 \SpecialChar ~
13457 \SpecialChar ~
13458 mov\SpecialChar ~
13459 \SpecialChar ~
13460 dpl,r3 
13461 \newline 
13462 \SpecialChar ~
13463 \SpecialChar ~
13464 \SpecialChar ~
13465 \SpecialChar ~
13466 mov\SpecialChar ~
13467 \SpecialChar ~
13468 dph,#(_buf >> 8) 
13469 \newline 
13470 \SpecialChar ~
13471 \SpecialChar ~
13472 \SpecialChar ~
13473 \SpecialChar ~
13474 mov\SpecialChar ~
13475 \SpecialChar ~
13476 a,r2 
13477 \newline 
13478 \SpecialChar ~
13479 \SpecialChar ~
13480 \SpecialChar ~
13481 \SpecialChar ~
13482 movx @dptr,a 
13483 \newline 
13484 00103$: 
13485 \newline 
13486 \SpecialChar ~
13487 \SpecialChar ~
13488 \SpecialChar ~
13489 \SpecialChar ~
13490 ret
13491 \newline 
13492 \SpecialChar ~
13493 \SpecialChar ~
13494 \SpecialChar ~
13495 \SpecialChar ~
13496 _endasm
13497 \begin_inset LatexCommand \index{\_endasm}
13498
13499 \end_inset 
13500
13501
13502 \begin_inset LatexCommand \index{\_\_endasm}
13503
13504 \end_inset 
13505
13506 ;
13507 \newline 
13508
13509 \layout Standard
13510
13511 The new file buffer.c should compile with only one warning about the unreferenced
13512  function argument 'c'.
13513  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13514  (1) and finally have:
13515 \layout Verse
13516
13517
13518 \family typewriter 
13519 \size footnotesize 
13520 unsigned char __far __at(0x7f00) buf[0x100];
13521 \newline 
13522 unsigned char head, tail;
13523 \newline 
13524 #define USE_ASSEMBLY (1)
13525 \newline 
13526
13527 \newline 
13528 #if !USE_ASSEMBLY
13529 \newline 
13530
13531 \newline 
13532 void to_buffer( unsigned char c )
13533 \newline 
13534 {
13535 \newline 
13536 \SpecialChar ~
13537 \SpecialChar ~
13538 \SpecialChar ~
13539 \SpecialChar ~
13540 if( head != (unsigned char)(tail-1) )
13541 \newline 
13542 \SpecialChar ~
13543 \SpecialChar ~
13544 \SpecialChar ~
13545 \SpecialChar ~
13546 \SpecialChar ~
13547 \SpecialChar ~
13548 \SpecialChar ~
13549 \SpecialChar ~
13550 buf[ head++ ] = c;
13551 \newline 
13552 }
13553 \newline 
13554
13555 \newline 
13556 #else
13557 \newline 
13558
13559 \newline 
13560 void to_buffer( unsigned char c )
13561 \newline 
13562 {
13563 \newline 
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 \SpecialChar ~
13567 \SpecialChar ~
13568 c; // to avoid warning: unreferenced function argument
13569 \newline 
13570 \SpecialChar ~
13571 \SpecialChar ~
13572 \SpecialChar ~
13573 \SpecialChar ~
13574 _asm
13575 \begin_inset LatexCommand \index{\_asm}
13576
13577 \end_inset 
13578
13579
13580 \begin_inset LatexCommand \index{\_\_asm}
13581
13582 \end_inset 
13583
13584
13585 \newline 
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 \SpecialChar ~
13589 \SpecialChar ~
13590 \SpecialChar ~
13591 \SpecialChar ~
13592 \SpecialChar ~
13593 \SpecialChar ~
13594 ; save used registers here.
13595  
13596 \newline 
13597 \SpecialChar ~
13598 \SpecialChar ~
13599 \SpecialChar ~
13600 \SpecialChar ~
13601 \SpecialChar ~
13602 \SpecialChar ~
13603 \SpecialChar ~
13604 \SpecialChar ~
13605 ; If we were still using r2,r3 we would have to push them here.
13606  
13607 \newline 
13608 ; if( head != (unsigned char)(tail-1) )
13609 \newline 
13610 \SpecialChar ~
13611 \SpecialChar ~
13612 \SpecialChar ~
13613 \SpecialChar ~
13614 \SpecialChar ~
13615 \SpecialChar ~
13616 \SpecialChar ~
13617 \SpecialChar ~
13618 mov\SpecialChar ~
13619  a,_tail
13620 \newline 
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 \SpecialChar ~
13625 \SpecialChar ~
13626 \SpecialChar ~
13627 \SpecialChar ~
13628 \SpecialChar ~
13629 dec\SpecialChar ~
13630  a
13631 \newline 
13632 \SpecialChar ~
13633 \SpecialChar ~
13634 \SpecialChar ~
13635 \SpecialChar ~
13636 \SpecialChar ~
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 xrl\SpecialChar ~
13641  a,_head
13642 \newline 
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 \SpecialChar ~
13646 \SpecialChar ~
13647 \SpecialChar ~
13648 \SpecialChar ~
13649 \SpecialChar ~
13650 \SpecialChar ~
13651 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13652 \newline 
13653 \SpecialChar ~
13654 \SpecialChar ~
13655 \SpecialChar ~
13656 \SpecialChar ~
13657 \SpecialChar ~
13658 \SpecialChar ~
13659 \SpecialChar ~
13660 \SpecialChar ~
13661 jz\SpecialChar ~
13662 \SpecialChar ~
13663  t_b_end$
13664 \newline 
13665 \SpecialChar ~
13666 \SpecialChar ~
13667 \SpecialChar ~
13668 \SpecialChar ~
13669 \SpecialChar ~
13670 \SpecialChar ~
13671 \SpecialChar ~
13672 \SpecialChar ~
13673 ;
13674 \newline 
13675 ; buf[ head++ ] = c;
13676 \newline 
13677 \SpecialChar ~
13678 \SpecialChar ~
13679 \SpecialChar ~
13680 \SpecialChar ~
13681 \SpecialChar ~
13682 \SpecialChar ~
13683 \SpecialChar ~
13684 \SpecialChar ~
13685 mov\SpecialChar ~
13686  a,dpl \SpecialChar ~
13687 \SpecialChar ~
13688 \SpecialChar ~
13689 \SpecialChar ~
13690 \SpecialChar ~
13691 \SpecialChar ~
13692 \SpecialChar ~
13693 ; dpl holds lower byte of function argument
13694 \newline 
13695 \SpecialChar ~
13696 \SpecialChar ~
13697 \SpecialChar ~
13698 \SpecialChar ~
13699 \SpecialChar ~
13700 \SpecialChar ~
13701 \SpecialChar ~
13702 \SpecialChar ~
13703 mov\SpecialChar ~
13704  dpl,_head \SpecialChar ~
13705 \SpecialChar ~
13706 \SpecialChar ~
13707 ; buf is 0x100 byte aligned so head can be used directly
13708 \newline 
13709 \SpecialChar ~
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 \SpecialChar ~
13713 \SpecialChar ~
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 mov\SpecialChar ~
13718  dph,#(_buf>>8)
13719 \newline 
13720 \SpecialChar ~
13721 \SpecialChar ~
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 \SpecialChar ~
13728 movx @dptr,a
13729 \newline 
13730 \SpecialChar ~
13731 \SpecialChar ~
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 inc \SpecialChar ~
13739 _head
13740 \newline 
13741 \SpecialChar ~
13742 \SpecialChar ~
13743 \SpecialChar ~
13744 \SpecialChar ~
13745 \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13750 \newline 
13751 t_b_end$:
13752 \newline 
13753 \SpecialChar ~
13754 \SpecialChar ~
13755 \SpecialChar ~
13756 \SpecialChar ~
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 ; restore used registers here 
13762 \newline 
13763 \SpecialChar ~
13764 \SpecialChar ~
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 _endasm
13768 \begin_inset LatexCommand \index{\_endasm}
13769
13770 \end_inset 
13771
13772
13773 \begin_inset LatexCommand \index{\_\_endasm}
13774
13775 \end_inset 
13776
13777 ;
13778 \newline 
13779 }
13780 \newline 
13781 #endif
13782 \layout Standard
13783
13784 The inline assembler code can contain any valid code understood by the assembler
13785 , this includes any assembler directives and comment lines.
13786  The assembler does not like some characters like ':' or ''' in comments.
13787  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13788 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13789
13790 \end_inset 
13791
13792
13793 \begin_inset LatexCommand \index{Assembler documentation}
13794
13795 \end_inset 
13796
13797  or online at 
13798 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13799
13800 \end_inset 
13801
13802 \SpecialChar ~
13803 .
13804 \layout Standard
13805
13806 The compiler does not do any validation of the code within the 
13807 \family typewriter 
13808 _asm
13809 \begin_inset LatexCommand \index{\_asm}
13810
13811 \end_inset 
13812
13813
13814 \begin_inset LatexCommand \index{\_\_asm}
13815
13816 \end_inset 
13817
13818  ...
13819  _endasm
13820 \size footnotesize 
13821
13822 \begin_inset LatexCommand \index{\_endasm}
13823
13824 \end_inset 
13825
13826
13827 \begin_inset LatexCommand \index{\_\_endasm}
13828
13829 \end_inset 
13830
13831
13832 \size default 
13833 ;
13834 \family default 
13835  keyword pair.
13836  Specifically it will not know which registers are used and thus register
13837  pushing/popping
13838 \begin_inset LatexCommand \index{push/pop}
13839
13840 \end_inset 
13841
13842  has to be done manually.
13843  
13844 \layout Standard
13845
13846 It is recommended that each assembly instruction (including labels) be placed
13847  in a separate line (as the example shows).
13848  When the -
13849 \begin_inset ERT
13850 status Collapsed
13851
13852 \layout Standard
13853
13854 \backslash 
13855 /
13856 \end_inset 
13857
13858 -
13859 \emph on 
13860 peep-asm
13861 \begin_inset LatexCommand \index{-\/-peep-asm}
13862
13863 \end_inset 
13864
13865
13866 \emph default 
13867  command line option is used, the inline assembler code will be passed through
13868  the peephole optimizer
13869 \begin_inset LatexCommand \index{Peephole optimizer}
13870
13871 \end_inset 
13872
13873 .
13874  There are only a few (if any) cases where this option makes sense, it might
13875  cause some unexpected changes in the inline assembler code.
13876  Please go through the peephole optimizer rules defined in file 
13877 \emph on 
13878 SDCCpeeph.def
13879 \emph default 
13880  before using this option.
13881 \layout Subsection
13882
13883 Naked Functions
13884 \begin_inset LatexCommand \label{sub:Naked-Functions}
13885
13886 \end_inset 
13887
13888
13889 \begin_inset LatexCommand \index{Naked functions}
13890
13891 \end_inset 
13892
13893
13894 \layout Standard
13895
13896 A special keyword may be associated with a function declaring it as 
13897 \emph on 
13898 _naked
13899 \begin_inset LatexCommand \index{\_naked}
13900
13901 \end_inset 
13902
13903
13904 \begin_inset LatexCommand \index{\_\_naked}
13905
13906 \end_inset 
13907
13908 .
13909  
13910 \emph default 
13911 The 
13912 \emph on 
13913 _naked
13914 \emph default 
13915  function modifier attribute prevents the compiler from generating prologue
13916 \begin_inset LatexCommand \index{function prologue}
13917
13918 \end_inset 
13919
13920  and epilogue
13921 \begin_inset LatexCommand \index{function epilogue}
13922
13923 \end_inset 
13924
13925  code for that function.
13926  This means that the user is entirely responsible for such things as saving
13927  any registers that may need to be preserved, selecting the proper register
13928  bank, generating the 
13929 \emph on 
13930 return
13931 \emph default 
13932  instruction at the end, etc.
13933  Practically, this means that the contents of the function must be written
13934  in inline assembler.
13935  This is particularly useful for interrupt functions, which can have a large
13936  (and often unnecessary) prologue/epilogue.
13937  For example, compare the code generated by these two functions:
13938 \layout Verse
13939
13940
13941 \family typewriter 
13942 volatile
13943 \begin_inset LatexCommand \index{volatile}
13944
13945 \end_inset 
13946
13947  data unsigned char counter;
13948 \newline 
13949
13950 \newline 
13951 void simpleInterrupt(void) __interrupt
13952 \begin_inset LatexCommand \index{interrupt}
13953
13954 \end_inset 
13955
13956
13957 \begin_inset LatexCommand \index{\_\_interrupt}
13958
13959 \end_inset 
13960
13961  (1)
13962 \newline 
13963 {
13964 \newline 
13965 \SpecialChar ~
13966 \SpecialChar ~
13967 \SpecialChar ~
13968 \SpecialChar ~
13969 counter++;
13970 \newline 
13971 }
13972 \newline 
13973
13974 \newline 
13975 void nakedInterrupt(void) __interrupt (2) __naked
13976 \newline 
13977 {
13978 \newline 
13979 \SpecialChar ~
13980 \SpecialChar ~
13981 \SpecialChar ~
13982 \SpecialChar ~
13983 _asm
13984 \begin_inset LatexCommand \index{\_asm}
13985
13986 \end_inset 
13987
13988
13989 \begin_inset LatexCommand \index{\_\_asm}
13990
13991 \end_inset 
13992
13993
13994 \newline 
13995 \SpecialChar ~
13996 \SpecialChar ~
13997 \SpecialChar ~
13998 \SpecialChar ~
13999 \SpecialChar ~
14000 \SpecialChar ~
14001 inc\SpecialChar ~
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 \SpecialChar ~
14005 \SpecialChar ~
14006 _counter ; does not change flags, no need to save psw
14007 \newline 
14008 \SpecialChar ~
14009 \SpecialChar ~
14010 \SpecialChar ~
14011 \SpecialChar ~
14012 \SpecialChar ~
14013 \SpecialChar ~
14014 reti\SpecialChar ~
14015 \SpecialChar ~
14016 \SpecialChar ~
14017 \SpecialChar ~
14018 ; MUST explicitly include ret or reti in _naked function.
14019 \newline 
14020 \SpecialChar ~
14021 \SpecialChar ~
14022 \SpecialChar ~
14023 \SpecialChar ~
14024 _endasm
14025 \begin_inset LatexCommand \index{\_endasm}
14026
14027 \end_inset 
14028
14029
14030 \begin_inset LatexCommand \index{\_\_endasm}
14031
14032 \end_inset 
14033
14034 ;
14035 \newline 
14036 }
14037 \layout Standard
14038
14039 For an 8051 target, the generated simpleInterrupt looks like:
14040 \layout Verse
14041
14042
14043 \family typewriter 
14044 Note, this is an 
14045 \emph on 
14046 outdated
14047 \emph default 
14048  example, recent versions of SDCC generate
14049 \newline 
14050 the 
14051 \emph on 
14052 same
14053 \emph default 
14054  code for simpleInterrupt() and nakedInterrupt()!
14055 \newline 
14056
14057 \newline 
14058 _simpleInterrupt:
14059 \newline 
14060 \SpecialChar ~
14061 \SpecialChar ~
14062 \SpecialChar ~
14063 \SpecialChar ~
14064 push\SpecialChar ~
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 \SpecialChar ~
14068 acc
14069 \newline 
14070 \SpecialChar ~
14071 \SpecialChar ~
14072 \SpecialChar ~
14073 \SpecialChar ~
14074 push\SpecialChar ~
14075 \SpecialChar ~
14076 \SpecialChar ~
14077 \SpecialChar ~
14078 b
14079 \newline 
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 \SpecialChar ~
14084 push\SpecialChar ~
14085 \SpecialChar ~
14086 \SpecialChar ~
14087 \SpecialChar ~
14088 dpl
14089 \newline 
14090 \SpecialChar ~
14091 \SpecialChar ~
14092 \SpecialChar ~
14093 \SpecialChar ~
14094 push\SpecialChar ~
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 dph
14099 \newline 
14100 \SpecialChar ~
14101 \SpecialChar ~
14102 \SpecialChar ~
14103 \SpecialChar ~
14104 push\SpecialChar ~
14105 \SpecialChar ~
14106 \SpecialChar ~
14107 \SpecialChar ~
14108 psw
14109 \newline 
14110 \SpecialChar ~
14111 \SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 mov\SpecialChar ~
14115 \SpecialChar ~
14116 \SpecialChar ~
14117 \SpecialChar ~
14118 \SpecialChar ~
14119 psw,#0x00
14120 \newline 
14121 \SpecialChar ~
14122 \SpecialChar ~
14123 \SpecialChar ~
14124 \SpecialChar ~
14125 inc\SpecialChar ~
14126 \SpecialChar ~
14127 \SpecialChar ~
14128 \SpecialChar ~
14129 \SpecialChar ~
14130 _counter
14131 \newline 
14132 \SpecialChar ~
14133 \SpecialChar ~
14134 \SpecialChar ~
14135 \SpecialChar ~
14136 pop\SpecialChar ~
14137 \SpecialChar ~
14138 \SpecialChar ~
14139 \SpecialChar ~
14140 \SpecialChar ~
14141 psw
14142 \newline 
14143 \SpecialChar ~
14144 \SpecialChar ~
14145 \SpecialChar ~
14146 \SpecialChar ~
14147 pop\SpecialChar ~
14148 \SpecialChar ~
14149 \SpecialChar ~
14150 \SpecialChar ~
14151 \SpecialChar ~
14152 dph
14153 \newline 
14154 \SpecialChar ~
14155 \SpecialChar ~
14156 \SpecialChar ~
14157 \SpecialChar ~
14158 pop\SpecialChar ~
14159 \SpecialChar ~
14160 \SpecialChar ~
14161 \SpecialChar ~
14162 \SpecialChar ~
14163 dpl
14164 \newline 
14165 \SpecialChar ~
14166 \SpecialChar ~
14167 \SpecialChar ~
14168 \SpecialChar ~
14169 pop\SpecialChar ~
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 b
14175 \newline 
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 \SpecialChar ~
14179 \SpecialChar ~
14180 pop\SpecialChar ~
14181 \SpecialChar ~
14182 \SpecialChar ~
14183 \SpecialChar ~
14184 \SpecialChar ~
14185 acc
14186 \newline 
14187 \SpecialChar ~
14188 \SpecialChar ~
14189 \SpecialChar ~
14190 \SpecialChar ~
14191 reti
14192 \layout Standard
14193
14194 whereas nakedInterrupt looks like:
14195 \layout Verse
14196
14197
14198 \family typewriter 
14199 _nakedInterrupt:
14200 \newline 
14201 \SpecialChar ~
14202 \SpecialChar ~
14203 \SpecialChar ~
14204 \SpecialChar ~
14205 inc\SpecialChar ~
14206 \SpecialChar ~
14207 \SpecialChar ~
14208 \SpecialChar ~
14209 _counter ; does not change flags, no need to save psw
14210 \newline 
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 \SpecialChar ~
14214 \SpecialChar ~
14215 reti\SpecialChar ~
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 \SpecialChar ~
14219 \SpecialChar ~
14220 \SpecialChar ~
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 \SpecialChar ~
14224 \SpecialChar ~
14225 \SpecialChar ~
14226 \SpecialChar ~
14227 ; MUST explicitly include ret or reti in _naked function
14228 \layout Standard
14229
14230 The related directive #pragma exclude
14231 \begin_inset LatexCommand \index{\#pragma exclude}
14232
14233 \end_inset 
14234
14235  allows a more fine grained control over pushing & popping
14236 \begin_inset LatexCommand \index{push/pop}
14237
14238 \end_inset 
14239
14240  the registers.
14241 \layout Standard
14242
14243 While there is nothing preventing you from writing C code inside a 
14244 \family typewriter 
14245 _naked
14246 \family default 
14247  function, there are many ways to shoot yourself in the foot doing this,
14248  and it is recommended that you stick to inline assembler.
14249 \layout Subsection
14250
14251 Use of Labels within Inline Assembler
14252 \layout Standard
14253
14254 SDCC allows the use of in-line assembler with a few restrictions regarding
14255  labels.
14256  In older versions of the compiler all labels defined within inline assembler
14257  code 
14258 \emph on 
14259 had to be
14260 \emph default 
14261  of the form 
14262 \emph on 
14263 nnnnn$
14264 \emph default 
14265  where nnnn is a number less than 100 (which implies a limit of utmost 100
14266  inline assembler labels 
14267 \emph on 
14268 per function
14269 \emph default 
14270 \noun on 
14271 )
14272 \noun default 
14273 .
14274  
14275 \layout Verse
14276
14277
14278 \family typewriter 
14279 _asm
14280 \begin_inset LatexCommand \index{\_asm}
14281
14282 \end_inset 
14283
14284
14285 \begin_inset LatexCommand \index{\_\_asm}
14286
14287 \end_inset 
14288
14289  
14290 \newline 
14291 \SpecialChar ~
14292 \SpecialChar ~
14293 \SpecialChar ~
14294 \SpecialChar ~
14295 mov\SpecialChar ~
14296 \SpecialChar ~
14297 \SpecialChar ~
14298 \SpecialChar ~
14299 \SpecialChar ~
14300 b,#10 
14301 \newline 
14302 00001$: 
14303 \newline 
14304 \SpecialChar ~
14305 \SpecialChar ~
14306 \SpecialChar ~
14307 \SpecialChar ~
14308 djnz\SpecialChar ~
14309 \SpecialChar ~
14310 \SpecialChar ~
14311 \SpecialChar ~
14312 b,00001$ 
14313 \newline 
14314 _endasm
14315 \begin_inset LatexCommand \index{\_endasm}
14316
14317 \end_inset 
14318
14319
14320 \begin_inset LatexCommand \index{\_\_endasm}
14321
14322 \end_inset 
14323
14324  ;
14325 \layout Standard
14326
14327 Inline assembler code cannot reference any C-Labels, however it can reference
14328  labels
14329 \begin_inset LatexCommand \index{Labels}
14330
14331 \end_inset 
14332
14333  defined by the inline assembler, e.g.:
14334 \layout Verse
14335
14336
14337 \family typewriter 
14338 foo() { 
14339 \newline 
14340 \SpecialChar ~
14341 \SpecialChar ~
14342 \SpecialChar ~
14343 \SpecialChar ~
14344 /* some c code */ 
14345 \newline 
14346 \SpecialChar ~
14347 \SpecialChar ~
14348 \SpecialChar ~
14349 \SpecialChar ~
14350 _asm 
14351 \newline 
14352 \SpecialChar ~
14353 \SpecialChar ~
14354 \SpecialChar ~
14355 \SpecialChar ~
14356 \SpecialChar ~
14357 \SpecialChar ~
14358 ; some assembler code 
14359 \newline 
14360 \SpecialChar ~
14361 \SpecialChar ~
14362 \SpecialChar ~
14363 \SpecialChar ~
14364 \SpecialChar ~
14365 \SpecialChar ~
14366 ljmp $0003 
14367 \newline 
14368 \SpecialChar ~
14369 \SpecialChar ~
14370 \SpecialChar ~
14371 \SpecialChar ~
14372 _endasm; 
14373 \newline 
14374 \SpecialChar ~
14375 \SpecialChar ~
14376 \SpecialChar ~
14377 \SpecialChar ~
14378 /* some more c code */ 
14379 \newline 
14380 clabel:\SpecialChar ~
14381 \SpecialChar ~
14382 /* inline assembler cannot reference this label */ 
14383 \newline 
14384 \SpecialChar ~
14385 \SpecialChar ~
14386 \SpecialChar ~
14387 \SpecialChar ~
14388 _asm
14389 \newline 
14390 \SpecialChar ~
14391 \SpecialChar ~
14392 \SpecialChar ~
14393 \SpecialChar ~
14394 $0003: ;label (can be referenced by inline assembler only) 
14395 \newline 
14396 \SpecialChar ~
14397 \SpecialChar ~
14398 \SpecialChar ~
14399 \SpecialChar ~
14400 _endasm
14401 \begin_inset LatexCommand \index{\_endasm}
14402
14403 \end_inset 
14404
14405
14406 \begin_inset LatexCommand \index{\_\_endasm}
14407
14408 \end_inset 
14409
14410  ; 
14411 \newline 
14412 \SpecialChar ~
14413 \SpecialChar ~
14414 \SpecialChar ~
14415 \SpecialChar ~
14416 /* some more c code */
14417 \newline 
14418 }
14419 \layout Standard
14420
14421 In other words inline assembly code can access labels defined in inline
14422  assembly within the scope of the function.
14423  The same goes the other way, i.e.
14424  labels defines in inline assembly can not be accessed by C statements.
14425 \layout Section
14426
14427 Interfacing with Assembler Code
14428 \begin_inset LatexCommand \index{Assembler routines}
14429
14430 \end_inset 
14431
14432
14433 \layout Subsection
14434
14435 Global Registers used for Parameter Passing
14436 \begin_inset LatexCommand \index{Parameter passing}
14437
14438 \end_inset 
14439
14440
14441 \layout Standard
14442
14443 The compiler always uses the global registers 
14444 \emph on 
14445 DPL, DPH
14446 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14447
14448 \end_inset 
14449
14450
14451 \begin_inset LatexCommand \index{DPTR}
14452
14453 \end_inset 
14454
14455 , B
14456 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14457
14458 \end_inset 
14459
14460  
14461 \emph default 
14462 and
14463 \emph on 
14464  ACC
14465 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14466
14467 \end_inset 
14468
14469
14470 \emph default 
14471  to pass the first parameter to a routine.
14472  The second parameter onwards is either allocated on the stack (for reentrant
14473  routines or if -
14474 \begin_inset ERT
14475 status Collapsed
14476
14477 \layout Standard
14478
14479 \backslash 
14480 /
14481 \end_inset 
14482
14483 -stack-auto is used) or in data / xdata memory (depending on the memory
14484  model).
14485  
14486 \layout Subsection
14487
14488 Assembler Routine (non-reentrant)
14489 \layout Standard
14490
14491 In the following example
14492 \begin_inset LatexCommand \index{reentrant}
14493
14494 \end_inset 
14495
14496
14497 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14498
14499 \end_inset 
14500
14501  the function c_func calls an assembler routine asm_func, which takes two
14502  parameters
14503 \begin_inset LatexCommand \index{function parameter}
14504
14505 \end_inset 
14506
14507 .
14508 \layout Verse
14509
14510
14511 \family typewriter 
14512 extern int asm_func(unsigned char, unsigned char);
14513 \newline 
14514
14515 \newline 
14516 int c_func (unsigned char i, unsigned char j)
14517 \newline 
14518 {
14519 \newline 
14520 \SpecialChar ~
14521 \SpecialChar ~
14522 \SpecialChar ~
14523 \SpecialChar ~
14524 return asm_func(i,j);
14525 \newline 
14526 }
14527 \newline 
14528
14529 \newline 
14530 int main()
14531 \newline 
14532 {
14533 \newline 
14534 \SpecialChar ~
14535 \SpecialChar ~
14536 \SpecialChar ~
14537 \SpecialChar ~
14538 return c_func(10,9);
14539 \newline 
14540 }
14541 \layout Standard
14542
14543 The corresponding assembler function is:
14544 \layout Verse
14545
14546
14547 \family typewriter 
14548 .globl _asm_func_PARM_2 
14549 \newline 
14550 \SpecialChar ~
14551 \SpecialChar ~
14552 \SpecialChar ~
14553 \SpecialChar ~
14554 \SpecialChar ~
14555 \SpecialChar ~
14556 \SpecialChar ~
14557 \SpecialChar ~
14558 .globl _asm_func 
14559 \newline 
14560 \SpecialChar ~
14561 \SpecialChar ~
14562 \SpecialChar ~
14563 \SpecialChar ~
14564 \SpecialChar ~
14565 \SpecialChar ~
14566 \SpecialChar ~
14567 \SpecialChar ~
14568 .area OSEG 
14569 \newline 
14570 _asm_func_PARM_2:
14571 \newline 
14572 \SpecialChar ~
14573 \SpecialChar ~
14574 \SpecialChar ~
14575 \SpecialChar ~
14576 \SpecialChar ~
14577 \SpecialChar ~
14578 \SpecialChar ~
14579 \SpecialChar ~
14580 .ds    1 
14581 \newline 
14582 \SpecialChar ~
14583 \SpecialChar ~
14584 \SpecialChar ~
14585 \SpecialChar ~
14586 \SpecialChar ~
14587 \SpecialChar ~
14588 \SpecialChar ~
14589 \SpecialChar ~
14590 .area CSEG 
14591 \newline 
14592 _asm_func: 
14593 \newline 
14594 \SpecialChar ~
14595 \SpecialChar ~
14596 \SpecialChar ~
14597 \SpecialChar ~
14598 \SpecialChar ~
14599 \SpecialChar ~
14600 \SpecialChar ~
14601 \SpecialChar ~
14602 mov\SpecialChar ~
14603 \SpecialChar ~
14604 \SpecialChar ~
14605 \SpecialChar ~
14606 a,dpl 
14607 \newline 
14608 \SpecialChar ~
14609 \SpecialChar ~
14610 \SpecialChar ~
14611 \SpecialChar ~
14612 \SpecialChar ~
14613 \SpecialChar ~
14614 \SpecialChar ~
14615 \SpecialChar ~
14616 add\SpecialChar ~
14617 \SpecialChar ~
14618 \SpecialChar ~
14619 \SpecialChar ~
14620 a,_asm_func_PARM_2 
14621 \newline 
14622 \SpecialChar ~
14623 \SpecialChar ~
14624 \SpecialChar ~
14625 \SpecialChar ~
14626 \SpecialChar ~
14627 \SpecialChar ~
14628 \SpecialChar ~
14629 \SpecialChar ~
14630 mov\SpecialChar ~
14631 \SpecialChar ~
14632 \SpecialChar ~
14633 \SpecialChar ~
14634 dpl,a 
14635 \newline 
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 \SpecialChar ~
14639 \SpecialChar ~
14640 \SpecialChar ~
14641 \SpecialChar ~
14642 \SpecialChar ~
14643 \SpecialChar ~
14644 mov\SpecialChar ~
14645 \SpecialChar ~
14646 \SpecialChar ~
14647 \SpecialChar ~
14648 dph
14649 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14650
14651 \end_inset 
14652
14653 ,#0x00 
14654 \newline 
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 \SpecialChar ~
14658 \SpecialChar ~
14659 \SpecialChar ~
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 ret
14664 \layout Standard
14665
14666 Note here that the return values
14667 \begin_inset LatexCommand \index{return value}
14668
14669 \end_inset 
14670
14671  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14672  two byte values.
14673  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14674 b' & 'acc' for four byte values.
14675 \layout Standard
14676
14677 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14678  the parameter number starting from 1, and counting from the left.
14679  The first parameter is passed in 
14680 \begin_inset Quotes eld
14681 \end_inset 
14682
14683 dpl
14684 \begin_inset Quotes erd
14685 \end_inset 
14686
14687  for a one byte parameter, 
14688 \begin_inset Quotes eld
14689 \end_inset 
14690
14691 dptr
14692 \begin_inset Quotes erd
14693 \end_inset 
14694
14695  for two bytes, 
14696 \begin_inset Quotes eld
14697 \end_inset 
14698
14699 b,dptr
14700 \begin_inset Quotes erd
14701 \end_inset 
14702
14703  for three bytes and 
14704 \begin_inset Quotes eld
14705 \end_inset 
14706
14707 acc,b,dptr
14708 \begin_inset Quotes erd
14709 \end_inset 
14710
14711  for a four bytes parameter.
14712  The variable name for the second parameter will be _<function_name>_PARM_2.
14713 \newline 
14714
14715 \newline 
14716 Assemble the assembler routine with the following command:
14717 \newline 
14718
14719 \newline 
14720
14721 \family sans 
14722 \series bold 
14723 asx8051 -losg asmfunc.asm
14724 \newline 
14725
14726 \newline 
14727
14728 \family default 
14729 \series default 
14730 Then compile and link the assembler routine to the C source file with the
14731  following command:
14732 \newline 
14733
14734 \newline 
14735
14736 \family sans 
14737 \series bold 
14738 sdcc cfunc.c asmfunc.rel
14739 \layout Subsection
14740
14741 Assembler Routine (reentrant)
14742 \layout Standard
14743
14744 In this case
14745 \begin_inset LatexCommand \index{reentrant}
14746
14747 \end_inset 
14748
14749
14750 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14751
14752 \end_inset 
14753
14754  the second parameter
14755 \begin_inset LatexCommand \index{function parameter}
14756
14757 \end_inset 
14758
14759  onwards will be passed on the stack, the parameters are pushed from right
14760  to left i.e.
14761  after the call the leftmost parameter will be on the top of the stack.
14762  Here is an example:
14763 \layout Verse
14764
14765
14766 \family typewriter 
14767 extern int asm_func(unsigned char, unsigned char);
14768 \newline 
14769
14770 \newline 
14771 int c_func (unsigned char i, unsigned char j) reentrant 
14772 \newline 
14773
14774 \newline 
14775 \SpecialChar ~
14776 \SpecialChar ~
14777 \SpecialChar ~
14778 \SpecialChar ~
14779 return asm_func(i,j); 
14780 \newline 
14781
14782 \newline 
14783
14784 \newline 
14785 int main() 
14786 \newline 
14787
14788 \newline 
14789 \SpecialChar ~
14790 \SpecialChar ~
14791 \SpecialChar ~
14792 \SpecialChar ~
14793 return c_func(10,9); 
14794 \newline 
14795 }
14796 \layout Standard
14797
14798 The corresponding assembler routine is:
14799 \layout Verse
14800
14801
14802 \family typewriter 
14803 .globl _asm_func 
14804 \newline 
14805 _asm_func: 
14806 \newline 
14807 \SpecialChar ~
14808 \SpecialChar ~
14809 \SpecialChar ~
14810 \SpecialChar ~
14811 push  _bp 
14812 \newline 
14813 \SpecialChar ~
14814 \SpecialChar ~
14815 \SpecialChar ~
14816 \SpecialChar ~
14817 mov _bp,sp 
14818 \newline 
14819 \SpecialChar ~
14820 \SpecialChar ~
14821 \SpecialChar ~
14822 \SpecialChar ~
14823 mov r2,dpl
14824 \newline 
14825 \SpecialChar ~
14826 \SpecialChar ~
14827 \SpecialChar ~
14828 \SpecialChar ~
14829 mov a,_bp 
14830 \newline 
14831 \SpecialChar ~
14832 \SpecialChar ~
14833 \SpecialChar ~
14834 \SpecialChar ~
14835 add a,#0xfd 
14836 \newline 
14837 \SpecialChar ~
14838 \SpecialChar ~
14839 \SpecialChar ~
14840 \SpecialChar ~
14841 mov r0,a 
14842 \newline 
14843 \SpecialChar ~
14844 \SpecialChar ~
14845 \SpecialChar ~
14846 \SpecialChar ~
14847 add  a,#0xfc ;?
14848 \newline 
14849 \SpecialChar ~
14850 \SpecialChar ~
14851 \SpecialChar ~
14852 \SpecialChar ~
14853 mov  r1,a 
14854 \newline 
14855 \SpecialChar ~
14856 \SpecialChar ~
14857 \SpecialChar ~
14858 \SpecialChar ~
14859 mov  a,@r0 
14860 \newline 
14861 \SpecialChar ~
14862 \SpecialChar ~
14863 \SpecialChar ~
14864 \SpecialChar ~
14865 add  a,r2 ;?
14866 \newline 
14867 \SpecialChar ~
14868 \SpecialChar ~
14869 \SpecialChar ~
14870 \SpecialChar ~
14871 mov  dpl,a 
14872 \newline 
14873 \SpecialChar ~
14874 \SpecialChar ~
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 mov  dph,#0x00 
14878 \newline 
14879 \SpecialChar ~
14880 \SpecialChar ~
14881 \SpecialChar ~
14882 \SpecialChar ~
14883 mov  sp,_bp 
14884 \newline 
14885 \SpecialChar ~
14886 \SpecialChar ~
14887 \SpecialChar ~
14888 \SpecialChar ~
14889 pop  _bp 
14890 \newline 
14891 \SpecialChar ~
14892 \SpecialChar ~
14893 \SpecialChar ~
14894 \SpecialChar ~
14895 ret
14896 \layout Standard
14897 \added_space_bottom bigskip 
14898 The compiling and linking procedure remains the same, however note the extra
14899  entry & exit linkage required for the assembler code, _bp is the stack
14900  frame pointer and is used to compute the offset into the stack for parameters
14901  and local variables.
14902 \layout Section
14903
14904 int (16 bit)
14905 \begin_inset LatexCommand \index{int (16 bit)}
14906
14907 \end_inset 
14908
14909  and long (32 bit)
14910 \begin_inset LatexCommand \index{long (32 bit)}
14911
14912 \end_inset 
14913
14914  Support
14915 \layout Standard
14916
14917 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14918  multiplication and modulus operations are implemented by support routines.
14919  These support routines are all developed in ANSI-C to facilitate porting
14920  to other MCUs, although some model specific assembler optimizations are
14921  used.
14922  The following files contain the described routines, all of them can be
14923  found in <installdir>/share/sdcc/lib.
14924 \newline 
14925
14926 \layout Standard
14927 \align center 
14928
14929 \begin_inset  Tabular
14930 <lyxtabular version="3" rows="11" columns="2">
14931 <features>
14932 <column alignment="left" valignment="top" leftline="true" width="0">
14933 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14934 <row topline="true" bottomline="true">
14935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14936 \begin_inset Text
14937
14938 \layout Standard
14939
14940
14941 \series bold 
14942 Function
14943 \end_inset 
14944 </cell>
14945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14946 \begin_inset Text
14947
14948 \layout Standard
14949
14950
14951 \series bold 
14952 Description
14953 \end_inset 
14954 </cell>
14955 </row>
14956 <row topline="true">
14957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14958 \begin_inset Text
14959
14960 \layout Standard
14961
14962 _mulint.c 
14963 \end_inset 
14964 </cell>
14965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14966 \begin_inset Text
14967
14968 \layout Standard
14969
14970 16 bit multiplication
14971 \end_inset 
14972 </cell>
14973 </row>
14974 <row topline="true">
14975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14976 \begin_inset Text
14977
14978 \layout Standard
14979
14980 _divsint.c 
14981 \end_inset 
14982 </cell>
14983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14984 \begin_inset Text
14985
14986 \layout Standard
14987
14988  signed 16 bit division (calls _divuint)
14989 \end_inset 
14990 </cell>
14991 </row>
14992 <row topline="true">
14993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14994 \begin_inset Text
14995
14996 \layout Standard
14997
14998 _divuint.c 
14999 \end_inset 
15000 </cell>
15001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15002 \begin_inset Text
15003
15004 \layout Standard
15005
15006  unsigned 16 bit division
15007 \end_inset 
15008 </cell>
15009 </row>
15010 <row topline="true">
15011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15012 \begin_inset Text
15013
15014 \layout Standard
15015
15016 _modsint.c
15017 \end_inset 
15018 </cell>
15019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15020 \begin_inset Text
15021
15022 \layout Standard
15023
15024 signed 16 bit modulus (calls _moduint)
15025 \end_inset 
15026 </cell>
15027 </row>
15028 <row topline="true">
15029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15030 \begin_inset Text
15031
15032 \layout Standard
15033
15034 _moduint.c
15035 \end_inset 
15036 </cell>
15037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15038 \begin_inset Text
15039
15040 \layout Standard
15041
15042 unsigned 16 bit modulus
15043 \end_inset 
15044 </cell>
15045 </row>
15046 <row topline="true">
15047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15048 \begin_inset Text
15049
15050 \layout Standard
15051
15052 _mullong.c
15053 \end_inset 
15054 </cell>
15055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15056 \begin_inset Text
15057
15058 \layout Standard
15059
15060 32 bit multiplication
15061 \end_inset 
15062 </cell>
15063 </row>
15064 <row topline="true">
15065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15066 \begin_inset Text
15067
15068 \layout Standard
15069
15070 _divslong.c 
15071 \end_inset 
15072 </cell>
15073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15074 \begin_inset Text
15075
15076 \layout Standard
15077
15078  signed 32 division (calls _divulong)
15079 \end_inset 
15080 </cell>
15081 </row>
15082 <row topline="true">
15083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15084 \begin_inset Text
15085
15086 \layout Standard
15087
15088 _divulong.c 
15089 \end_inset 
15090 </cell>
15091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15092 \begin_inset Text
15093
15094 \layout Standard
15095
15096 unsigned 32 division
15097 \end_inset 
15098 </cell>
15099 </row>
15100 <row topline="true">
15101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15102 \begin_inset Text
15103
15104 \layout Standard
15105
15106 _modslong.c
15107 \end_inset 
15108 </cell>
15109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15110 \begin_inset Text
15111
15112 \layout Standard
15113
15114  signed 32 bit modulus (calls _modulong)
15115 \end_inset 
15116 </cell>
15117 </row>
15118 <row topline="true" bottomline="true">
15119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15120 \begin_inset Text
15121
15122 \layout Standard
15123
15124 _modulong.c
15125 \end_inset 
15126 </cell>
15127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15128 \begin_inset Text
15129
15130 \layout Standard
15131
15132 unsigned 32 bit modulus
15133 \end_inset 
15134 </cell>
15135 </row>
15136 </lyxtabular>
15137
15138 \end_inset 
15139
15140
15141 \newline 
15142
15143 \layout Standard
15144
15145 Since they are compiled as 
15146 \emph on 
15147 non-reentrant
15148 \emph default 
15149
15150 \begin_inset LatexCommand \index{reentrant}
15151
15152 \end_inset 
15153
15154 , interrupt
15155 \begin_inset LatexCommand \index{interrupt}
15156
15157 \end_inset 
15158
15159  service routines should not do any of the above operations.
15160  If this is unavoidable then the above routines will need to be compiled
15161  with the 
15162 \emph on 
15163 -
15164 \begin_inset ERT
15165 status Collapsed
15166
15167 \layout Standard
15168
15169 \backslash 
15170 /
15171 \end_inset 
15172
15173 -stack-auto
15174 \begin_inset LatexCommand \index{-\/-stack-auto}
15175
15176 \end_inset 
15177
15178
15179 \emph default 
15180  option, after which the source program will have to be compiled with 
15181 \emph on 
15182 -
15183 \begin_inset ERT
15184 status Collapsed
15185
15186 \layout Standard
15187
15188 \backslash 
15189 /
15190 \end_inset 
15191
15192 -int-long-reent
15193 \begin_inset LatexCommand \index{-\/-int-long-reent}
15194
15195 \end_inset 
15196
15197
15198 \emph default 
15199  option.
15200  Notice that you don't have to call these routines directly.
15201  The compiler will use them automatically every time an integer operation
15202  is required.
15203 \layout Section
15204
15205 Floating Point Support
15206 \begin_inset LatexCommand \index{Floating point support}
15207
15208 \end_inset 
15209
15210
15211 \layout Standard
15212
15213 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15214  The floating point support routines are derived from gcc's floatlib.c and
15215  consist of the following routines:
15216 \newline 
15217
15218 \layout Standard
15219 \align center 
15220
15221 \size footnotesize 
15222
15223 \begin_inset  Tabular
15224 <lyxtabular version="3" rows="17" columns="2">
15225 <features>
15226 <column alignment="left" valignment="top" leftline="true" width="0">
15227 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15228 <row topline="true" bottomline="true">
15229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15230 \begin_inset Text
15231
15232 \layout Standard
15233
15234
15235 \family roman 
15236 \series medium 
15237 \shape up 
15238 \size normal 
15239 \emph off 
15240 \bar no 
15241 \noun off 
15242 \color none
15243 Function 
15244 \end_inset 
15245 </cell>
15246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15247 \begin_inset Text
15248
15249 \layout Standard
15250
15251 Description
15252 \end_inset 
15253 </cell>
15254 </row>
15255 <row topline="true">
15256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15257 \begin_inset Text
15258
15259 \layout Standard
15260
15261
15262 \family roman 
15263 \series medium 
15264 \shape up 
15265 \size normal 
15266 \emph off 
15267 \bar no 
15268 \noun off 
15269 \color none
15270 _fsadd.c
15271 \end_inset 
15272 </cell>
15273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15274 \begin_inset Text
15275
15276 \layout Standard
15277
15278
15279 \family roman 
15280 \series medium 
15281 \shape up 
15282 \size normal 
15283 \emph off 
15284 \bar no 
15285 \noun off 
15286 \color none
15287 add floating point numbers
15288 \end_inset 
15289 </cell>
15290 </row>
15291 <row topline="true">
15292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15293 \begin_inset Text
15294
15295 \layout Standard
15296
15297
15298 \family roman 
15299 \series medium 
15300 \shape up 
15301 \size normal 
15302 \emph off 
15303 \bar no 
15304 \noun off 
15305 \color none
15306 _fssub.c 
15307 \end_inset 
15308 </cell>
15309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15310 \begin_inset Text
15311
15312 \layout Standard
15313
15314
15315 \family roman 
15316 \series medium 
15317 \shape up 
15318 \size normal 
15319 \emph off 
15320 \bar no 
15321 \noun off 
15322 \color none
15323 subtract floating point numbers 
15324 \end_inset 
15325 </cell>
15326 </row>
15327 <row topline="true">
15328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15329 \begin_inset Text
15330
15331 \layout Standard
15332
15333
15334 \family roman 
15335 \series medium 
15336 \shape up 
15337 \size normal 
15338 \emph off 
15339 \bar no 
15340 \noun off 
15341 \color none
15342 _fsdiv.c 
15343 \end_inset 
15344 </cell>
15345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15346 \begin_inset Text
15347
15348 \layout Standard
15349
15350
15351 \family roman 
15352 \series medium 
15353 \shape up 
15354 \size normal 
15355 \emph off 
15356 \bar no 
15357 \noun off 
15358 \color none
15359 divide floating point numbers 
15360 \end_inset 
15361 </cell>
15362 </row>
15363 <row topline="true">
15364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15365 \begin_inset Text
15366
15367 \layout Standard
15368
15369
15370 \family roman 
15371 \series medium 
15372 \shape up 
15373 \size normal 
15374 \emph off 
15375 \bar no 
15376 \noun off 
15377 \color none
15378 _fsmul.c 
15379 \end_inset 
15380 </cell>
15381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15382 \begin_inset Text
15383
15384 \layout Standard
15385
15386
15387 \family roman 
15388 \series medium 
15389 \shape up 
15390 \size normal 
15391 \emph off 
15392 \bar no 
15393 \noun off 
15394 \color none
15395 multiply floating point numbers 
15396 \end_inset 
15397 </cell>
15398 </row>
15399 <row topline="true">
15400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15401 \begin_inset Text
15402
15403 \layout Standard
15404
15405
15406 \family roman 
15407 \series medium 
15408 \shape up 
15409 \size normal 
15410 \emph off 
15411 \bar no 
15412 \noun off 
15413 \color none
15414 _fs2uchar.c
15415 \end_inset 
15416 </cell>
15417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15418 \begin_inset Text
15419
15420 \layout Standard
15421
15422
15423 \family roman 
15424 \series medium 
15425 \shape up 
15426 \size normal 
15427 \emph off 
15428 \bar no 
15429 \noun off 
15430 \color none
15431 convert floating point to unsigned char
15432 \end_inset 
15433 </cell>
15434 </row>
15435 <row topline="true">
15436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15437 \begin_inset Text
15438
15439 \layout Standard
15440
15441
15442 \family roman 
15443 \series medium 
15444 \shape up 
15445 \size normal 
15446 \emph off 
15447 \bar no 
15448 \noun off 
15449 \color none
15450 _fs2char.c
15451 \end_inset 
15452 </cell>
15453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15454 \begin_inset Text
15455
15456 \layout Standard
15457
15458
15459 \family roman 
15460 \series medium 
15461 \shape up 
15462 \size normal 
15463 \emph off 
15464 \bar no 
15465 \noun off 
15466 \color none
15467 convert floating point to signed char
15468 \end_inset 
15469 </cell>
15470 </row>
15471 <row topline="true">
15472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15473 \begin_inset Text
15474
15475 \layout Standard
15476
15477
15478 \family roman 
15479 \series medium 
15480 \shape up 
15481 \size normal 
15482 \emph off 
15483 \bar no 
15484 \noun off 
15485 \color none
15486 _fs2uint.c
15487 \end_inset 
15488 </cell>
15489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15490 \begin_inset Text
15491
15492 \layout Standard
15493
15494
15495 \family roman 
15496 \series medium 
15497 \shape up 
15498 \size normal 
15499 \emph off 
15500 \bar no 
15501 \noun off 
15502 \color none
15503 convert floating point to unsigned int
15504 \end_inset 
15505 </cell>
15506 </row>
15507 <row topline="true">
15508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15509 \begin_inset Text
15510
15511 \layout Standard
15512
15513
15514 \family roman 
15515 \series medium 
15516 \shape up 
15517 \size normal 
15518 \emph off 
15519 \bar no 
15520 \noun off 
15521 \color none
15522 _fs2int.c
15523 \end_inset 
15524 </cell>
15525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15526 \begin_inset Text
15527
15528 \layout Standard
15529
15530
15531 \family roman 
15532 \series medium 
15533 \shape up 
15534 \size normal 
15535 \emph off 
15536 \bar no 
15537 \noun off 
15538 \color none
15539 convert floating point to signed int
15540 \end_inset 
15541 </cell>
15542 </row>
15543 <row topline="true">
15544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15545 \begin_inset Text
15546
15547 \layout Standard
15548
15549
15550 \family roman 
15551 \series medium 
15552 \shape up 
15553 \size normal 
15554 \emph off 
15555 \bar no 
15556 \noun off 
15557 \color none
15558 _fs2ulong.
15559 \family default 
15560 \series default 
15561 \shape default 
15562 \size default 
15563 \emph default 
15564 \bar default 
15565 \noun default 
15566 \color default
15567 c
15568 \end_inset 
15569 </cell>
15570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15571 \begin_inset Text
15572
15573 \layout Standard
15574
15575
15576 \family roman 
15577 \series medium 
15578 \shape up 
15579 \size normal 
15580 \emph off 
15581 \bar no 
15582 \noun off 
15583 \color none
15584 convert floating point to unsigned long
15585 \end_inset 
15586 </cell>
15587 </row>
15588 <row topline="true">
15589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15590 \begin_inset Text
15591
15592 \layout Standard
15593
15594
15595 \family roman 
15596 \series medium 
15597 \shape up 
15598 \size normal 
15599 \emph off 
15600 \bar no 
15601 \noun off 
15602 \color none
15603 _fs2long.c
15604 \end_inset 
15605 </cell>
15606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15607 \begin_inset Text
15608
15609 \layout Standard
15610
15611
15612 \family roman 
15613 \series medium 
15614 \shape up 
15615 \size normal 
15616 \emph off 
15617 \bar no 
15618 \noun off 
15619 \color none
15620 convert floating point to signed long
15621 \end_inset 
15622 </cell>
15623 </row>
15624 <row topline="true">
15625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15626 \begin_inset Text
15627
15628 \layout Standard
15629
15630
15631 \family roman 
15632 \series medium 
15633 \shape up 
15634 \size normal 
15635 \emph off 
15636 \bar no 
15637 \noun off 
15638 \color none
15639 _uchar2fs.c
15640 \end_inset 
15641 </cell>
15642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15643 \begin_inset Text
15644
15645 \layout Standard
15646
15647
15648 \family roman 
15649 \series medium 
15650 \shape up 
15651 \size normal 
15652 \emph off 
15653 \bar no 
15654 \noun off 
15655 \color none
15656 convert unsigned char to floating point
15657 \end_inset 
15658 </cell>
15659 </row>
15660 <row topline="true">
15661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15662 \begin_inset Text
15663
15664 \layout Standard
15665
15666
15667 \family roman 
15668 \series medium 
15669 \shape up 
15670 \size normal 
15671 \emph off 
15672 \bar no 
15673 \noun off 
15674 \color none
15675 _char2fs.c
15676 \end_inset 
15677 </cell>
15678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15679 \begin_inset Text
15680
15681 \layout Standard
15682
15683
15684 \family roman 
15685 \series medium 
15686 \shape up 
15687 \size normal 
15688 \emph off 
15689 \bar no 
15690 \noun off 
15691 \color none
15692 convert char to floating point number
15693 \end_inset 
15694 </cell>
15695 </row>
15696 <row topline="true">
15697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15698 \begin_inset Text
15699
15700 \layout Standard
15701
15702
15703 \family roman 
15704 \series medium 
15705 \shape up 
15706 \size normal 
15707 \emph off 
15708 \bar no 
15709 \noun off 
15710 \color none
15711 _uint2fs.c
15712 \end_inset 
15713 </cell>
15714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15715 \begin_inset Text
15716
15717 \layout Standard
15718
15719
15720 \family roman 
15721 \series medium 
15722 \shape up 
15723 \size normal 
15724 \emph off 
15725 \bar no 
15726 \noun off 
15727 \color none
15728 convert unsigned int to floating point
15729 \end_inset 
15730 </cell>
15731 </row>
15732 <row topline="true">
15733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15734 \begin_inset Text
15735
15736 \layout Standard
15737
15738
15739 \family roman 
15740 \series medium 
15741 \shape up 
15742 \size normal 
15743 \emph off 
15744 \bar no 
15745 \noun off 
15746 \color none
15747 _int2fs.c
15748 \end_inset 
15749 </cell>
15750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15751 \begin_inset Text
15752
15753 \layout Standard
15754
15755
15756 \family roman 
15757 \series medium 
15758 \shape up 
15759 \size normal 
15760 \emph off 
15761 \bar no 
15762 \noun off 
15763 \color none
15764 convert int to floating point numbers
15765 \end_inset 
15766 </cell>
15767 </row>
15768 <row topline="true">
15769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15770 \begin_inset Text
15771
15772 \layout Standard
15773
15774
15775 \family roman 
15776 \series medium 
15777 \shape up 
15778 \size normal 
15779 \emph off 
15780 \bar no 
15781 \noun off 
15782 \color none
15783 _ulong2fs.c
15784 \end_inset 
15785 </cell>
15786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15787 \begin_inset Text
15788
15789 \layout Standard
15790
15791
15792 \family roman 
15793 \series medium 
15794 \shape up 
15795 \size normal 
15796 \emph off 
15797 \bar no 
15798 \noun off 
15799 \color none
15800 convert unsigned long to floating point number
15801 \end_inset 
15802 </cell>
15803 </row>
15804 <row topline="true" bottomline="true">
15805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15806 \begin_inset Text
15807
15808 \layout Standard
15809
15810
15811 \family roman 
15812 \series medium 
15813 \shape up 
15814 \size normal 
15815 \emph off 
15816 \bar no 
15817 \noun off 
15818 \color none
15819 _long2fs.c
15820 \end_inset 
15821 </cell>
15822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15823 \begin_inset Text
15824
15825 \layout Standard
15826
15827
15828 \family roman 
15829 \series medium 
15830 \shape up 
15831 \size normal 
15832 \emph off 
15833 \bar no 
15834 \noun off 
15835 \color none
15836 convert long to floating point number
15837 \end_inset 
15838 </cell>
15839 </row>
15840 </lyxtabular>
15841
15842 \end_inset 
15843
15844
15845 \newline 
15846
15847 \layout Standard
15848 \added_space_bottom bigskip 
15849 These support routines are developed in ANSI-C so there is room for space
15850  and speed improvement
15851 \begin_inset Foot
15852 collapsed false
15853
15854 \layout Standard
15855
15856 These floating point routines (
15857 \emph on 
15858 not
15859 \emph default 
15860  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15861  
15862 \end_inset 
15863
15864 .
15865  Note if all these routines are used simultaneously the data space might
15866  overflow.
15867  For serious floating point usage the large model might be needed.
15868  Also notice that you don't have to call this routines directly.
15869  The compiler will use them automatically every time a floating point operation
15870  is required.
15871 \layout Section
15872
15873 Library Routines
15874 \begin_inset LatexCommand \index{Libraries}
15875
15876 \end_inset 
15877
15878
15879 \layout Standard
15880
15881
15882 \emph on 
15883 <pending: this is messy and incomplete - a little more information is in
15884  sdcc/doc/libdoc.txt
15885 \emph default 
15886  >
15887 \layout Subsection
15888
15889 Compiler support routines (_gptrget, _mulint etc.)
15890 \layout Subsection
15891
15892 Stdclib functions (puts, printf, strcat etc.)
15893 \layout Subsubsection
15894
15895 <stdio.h>
15896 \layout Standard
15897
15898
15899 \begin_inset LatexCommand \index{<stdio.h>}
15900
15901 \end_inset 
15902
15903 As usual on embedded systems you have to provide your own 
15904 \family typewriter 
15905 getchar()
15906 \begin_inset LatexCommand \index{getchar()}
15907
15908 \end_inset 
15909
15910  
15911 \family default 
15912 and 
15913 \family typewriter 
15914 putchar()
15915 \begin_inset LatexCommand \index{putchar()}
15916
15917 \end_inset 
15918
15919
15920 \family default 
15921  routines.
15922  SDCC does not know whether the system connects to a serial line with or
15923  without handshake, LCD, keyboard or other device.
15924  And whether a 
15925 \family typewriter 
15926 lf
15927 \family default 
15928  to 
15929 \family typewriter 
15930 crlf
15931 \family default 
15932  conversion within 
15933 \family typewriter 
15934 putchar()
15935 \family default 
15936  is intended.
15937  You'll find examples for serial routines f.e.
15938  in sdcc/device/lib.
15939 \layout Standard
15940
15941 The default
15942 \family typewriter 
15943  printf()
15944 \begin_inset LatexCommand \index{printf()}
15945
15946 \end_inset 
15947
15948
15949 \family default 
15950 implementation in
15951 \family typewriter 
15952  printf_large.c
15953 \family default 
15954  does not support float (except on ds390).
15955  To enable this recompile it with the option 
15956 \emph on 
15957 -
15958 \begin_inset ERT
15959 status Collapsed
15960
15961 \layout Standard
15962
15963 \backslash 
15964 /
15965 \end_inset 
15966
15967 DUSE_FLOATS=1
15968 \begin_inset LatexCommand \index{USE\_FLOATS}
15969
15970 \end_inset 
15971
15972
15973 \emph default 
15974  on the command line.
15975  Use
15976 \emph on 
15977  -
15978 \begin_inset ERT
15979 status Collapsed
15980
15981 \layout Standard
15982
15983 \backslash 
15984 /
15985 \end_inset 
15986
15987 -model-large
15988 \begin_inset LatexCommand \index{-\/-model-large}
15989
15990 \end_inset 
15991
15992
15993 \emph default 
15994  for the mcs51 port, since this uses a lot of memory.
15995 \layout Standard
15996
15997 If you're short on memory you might want to use 
15998 \family typewriter 
15999 printf_small()
16000 \begin_inset LatexCommand \index{printf\_small()}
16001
16002 \end_inset 
16003
16004
16005 \family default 
16006  
16007 \emph on 
16008 instead
16009 \emph default 
16010  of
16011 \family typewriter 
16012  printf().
16013
16014 \family default 
16015  For the mcs51 there additionally are assembly versions 
16016 \family typewriter 
16017 printf_tiny()
16018 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16019
16020 \end_inset 
16021
16022
16023 \family default 
16024  (subset of printf using less than 270 bytes) and 
16025 \family typewriter 
16026 printf_fast()
16027 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16028
16029 \end_inset 
16030
16031  
16032 \family default 
16033 and
16034 \family typewriter 
16035  printf_fast_f()
16036 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16037
16038 \end_inset 
16039
16040
16041 \family default 
16042  (floating-point aware version of printf_fast) which should fit the requirements
16043  of many embedded systems (printf_fast() can be customized by unsetting
16044  #defines to 
16045 \emph on 
16046 not
16047 \emph default 
16048  support long variables and field widths).
16049 \layout Subsubsection
16050
16051 <malloc.h>
16052 \begin_inset LatexCommand \index{malloc.h}
16053
16054 \end_inset 
16055
16056
16057 \layout Standard
16058
16059 As of SDCC 2.6.2 you no longer need to call an initialization routine before
16060  using dynamic memory allocation
16061 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
16062
16063 \end_inset 
16064
16065  and a default heap
16066 \begin_inset LatexCommand \index{heap (malloc)}
16067
16068 \end_inset 
16069
16070  space of 1024 bytes is provided for malloc to allocate memory from.
16071  
16072 \family default 
16073 If you need a different heap size you need to recompile _heap.c with the
16074  required size defined in HEAP_SIZE. It is recommended to make a copy of this
16075  file into your project directory and compile it there with:
16076 \layout Verse
16077
16078
16079 \family typewriter 
16080 sdcc -c _heap.c -D HEAD_SIZE=2048
16081 \newline 
16082 \family default 
16083 And then link it with:
16084 \layout Verse
16085
16086 \family typewriter 
16087 sdcc main.rel _heap.rel
16088 \newline 
16089
16090 \layout Subsection
16091
16092 Math functions (sinf, powf, sqrtf etc.)
16093 \layout Subsubsection
16094
16095 <math.h>
16096 \layout Standard
16097
16098 See definitions in file <math.h>.
16099 \layout Subsection
16100
16101 Other libraries
16102 \layout Standard
16103
16104 Libraries
16105 \begin_inset LatexCommand \index{Libraries}
16106
16107 \end_inset 
16108
16109  included in SDCC should have a license at least as liberal as the GNU Lesser
16110  General Public License
16111 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16112
16113 \end_inset 
16114
16115  
16116 \emph on 
16117 LGPL
16118 \emph default 
16119 .
16120 \layout Comment
16121
16122 license statements for the libraries are missing.
16123  sdcc/device/lib/ser_ir.c
16124 \layout Comment
16125
16126 or _decdptr f.e.
16127  come with a GPL (as opposed to LGPL) License - this will not be liberal
16128  enough for many embedded programmers.
16129 \layout Standard
16130
16131 If you have ported some library or want to share experience about some code
16132  which f.e.
16133  falls into any of these categories Busses (I
16134 \begin_inset Formula $^{\textrm{2}}$
16135 \end_inset 
16136
16137 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16138  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16139  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
16140 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16141
16142 \end_inset 
16143
16144 \SpecialChar ~
16145 would certainly like to hear about it.
16146 \layout Standard
16147 \added_space_bottom bigskip 
16148 Programmers coding for embedded systems are not especially famous for being
16149  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16150 e these references are very valuable.
16151  Let's help to create a climate where information is shared.
16152 \layout Section
16153
16154 Memory Models
16155 \layout Subsection
16156
16157 MCS51 Memory Models
16158 \begin_inset LatexCommand \index{Memory model}
16159
16160 \end_inset 
16161
16162
16163 \begin_inset LatexCommand \index{MCS51 memory model}
16164
16165 \end_inset 
16166
16167
16168 \layout Subsubsection
16169
16170 Small, Medium and Large
16171 \layout Standard
16172
16173 SDCC allows three memory models for MCS51 code, 
16174 \shape slanted 
16175 small, medium
16176 \shape default 
16177  and 
16178 \shape slanted 
16179 large
16180 \shape default 
16181 .
16182  Modules compiled with different memory models should 
16183 \emph on 
16184 never
16185 \emph default 
16186  be combined together or the results would be unpredictable.
16187  The library routines supplied with the compiler are compiled as small,
16188  medium and large.
16189  The compiled library modules are contained in separate directories as small,
16190  medium and large so that you can link to the appropriate set.
16191 \layout Standard
16192
16193 When the medium or large model is used all variables declared without a
16194  storage class will be allocated into the external ram, this includes all
16195  parameters and local variables (for non-reentrant
16196 \begin_inset LatexCommand \index{reentrant}
16197
16198 \end_inset 
16199
16200  functions).
16201  When the small model is used variables without storage class are allocated
16202  in the internal ram.
16203 \layout Standard
16204
16205 Judicious usage of the processor specific storage classes
16206 \begin_inset LatexCommand \index{Storage class}
16207
16208 \end_inset 
16209
16210  and the 'reentrant' function type will yield much more efficient code,
16211  than using the large model.
16212  Several optimizations are disabled when the program is compiled using the
16213  large model, it is therefore recommended that the small model be used unless
16214  absolutely required.
16215 \layout Subsubsection
16216
16217 External Stack
16218 \begin_inset LatexCommand \label{sub:External-Stack}
16219
16220 \end_inset 
16221
16222
16223 \begin_inset LatexCommand \index{stack}
16224
16225 \end_inset 
16226
16227
16228 \begin_inset LatexCommand \index{External stack (mcs51)}
16229
16230 \end_inset 
16231
16232
16233 \layout Standard
16234
16235 The external stack (-
16236 \begin_inset ERT
16237 status Collapsed
16238
16239 \layout Standard
16240
16241 \backslash 
16242 /
16243 \end_inset 
16244
16245 -xstack option
16246 \begin_inset LatexCommand \index{-\/-xstack}
16247
16248 \end_inset 
16249
16250 ) is located in pdata
16251 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16252
16253 \end_inset 
16254
16255  memory (usually at the start of the external ram segment) and uses all
16256  unused space in pdata (max.
16257  256 bytes).
16258  When -
16259 \begin_inset ERT
16260 status Collapsed
16261
16262 \layout Standard
16263
16264 \backslash 
16265 /
16266 \end_inset 
16267
16268 -xstack option is used to compile the program, the parameters and local
16269  variables
16270 \begin_inset LatexCommand \index{local variables}
16271
16272 \end_inset 
16273
16274  of all reentrant functions are allocated in this area.
16275  This option is provided for programs with large stack space requirements.
16276  When used with the -
16277 \begin_inset ERT
16278 status Collapsed
16279
16280 \layout Standard
16281
16282 \backslash 
16283 /
16284 \end_inset 
16285
16286 -stack-auto
16287 \begin_inset LatexCommand \index{-\/-stack-auto}
16288
16289 \end_inset 
16290
16291  option, all parameters and local variables are allocated on the external
16292  stack (note: support libraries will need to be recompiled with the same
16293  options.
16294  There is a predefined target in the library makefile).
16295 \layout Standard
16296
16297 The compiler outputs the higher order address byte of the external ram segment
16298  into port P2
16299 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16300
16301 \end_inset 
16302
16303  (see also section 
16304 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16305
16306 \end_inset 
16307
16308 ), therefore when using the External Stack option, this port 
16309 \emph on 
16310 may not
16311 \emph default 
16312  be used by the application program.
16313 \layout Subsection
16314
16315 DS390 Memory Model
16316 \begin_inset LatexCommand \index{Memory model}
16317
16318 \end_inset 
16319
16320
16321 \begin_inset LatexCommand \index{DS390 memory model}
16322
16323 \end_inset 
16324
16325
16326 \layout Standard
16327
16328 The only model supported is Flat 24
16329 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
16330
16331 \end_inset 
16332
16333 .
16334  This generates code for the 24 bit contiguous addressing mode of the Dallas
16335  DS80C390 part.
16336  In this mode, up to four meg of external RAM or code space can be directly
16337  addressed.
16338  See the data sheets at www.dalsemi.com for further information on this part.
16339 \newline 
16340
16341 \newline 
16342 Note that the compiler does not generate any code to place the processor
16343  into 24 bitmode (although 
16344 \emph on 
16345 tinibios
16346 \emph default 
16347  in the ds390 libraries will do that for you).
16348  If you don't use 
16349 \emph on 
16350 tinibios
16351 \emph default 
16352
16353 \begin_inset LatexCommand \index{Tinibios (DS390)}
16354
16355 \end_inset 
16356
16357 , the boot loader or similar code must ensure that the processor is in 24
16358  bit contiguous addressing mode before calling the SDCC startup code.
16359 \newline 
16360
16361 \newline 
16362 Like the 
16363 \emph on 
16364 -
16365 \begin_inset ERT
16366 status Collapsed
16367
16368 \layout Standard
16369
16370 \backslash 
16371 /
16372 \end_inset 
16373
16374 -model-large
16375 \emph default 
16376  option, variables will by default be placed into the XDATA segment.
16377  
16378 \newline 
16379
16380 \newline 
16381 Segments may be placed anywhere in the 4 meg address space using the usual
16382  -
16383 \begin_inset ERT
16384 status Collapsed
16385
16386 \layout Standard
16387
16388 \backslash 
16389 /
16390 \end_inset 
16391
16392 -*-loc options.
16393  Note that if any segments are located above 64K, the -r flag must be passed
16394  to the linker to generate the proper segment relocations, and the Intel
16395  HEX output format must be used.
16396  The -r flag can be passed to the linker by using the option 
16397 \emph on 
16398 -Wl-r
16399 \emph default 
16400  on the SDCC command line.
16401  However, currently the linker can not handle code segments > 64k.
16402 \layout Section
16403
16404 Pragmas
16405 \begin_inset LatexCommand \label{sec:Pragmas}
16406
16407 \end_inset 
16408
16409
16410 \begin_inset LatexCommand \index{Pragmas}
16411
16412 \end_inset 
16413
16414
16415 \layout Standard
16416
16417 SDCC supports the following #pragma directives:
16418 \layout Itemize
16419
16420
16421 \series bold 
16422 save
16423 \series default 
16424
16425 \begin_inset LatexCommand \index{\#pragma save}
16426
16427 \end_inset 
16428
16429  - this will save most current options to the save/restore stack.
16430  See #pragma\SpecialChar ~
16431 restore.
16432 \layout Itemize
16433
16434
16435 \series bold 
16436 restore
16437 \series default 
16438
16439 \begin_inset LatexCommand \index{\#pragma restore}
16440
16441 \end_inset 
16442
16443  - will restore saved options from the last save.
16444  saves & restores can be nested.
16445  SDCC uses a save/restore stack: save pushes current options to the stack,
16446  restore pulls current options from the stack.
16447  See #pragma\SpecialChar ~
16448 save.
16449 \newline 
16450
16451 \layout Itemize
16452
16453
16454 \series bold 
16455 callee_saves
16456 \series default 
16457
16458 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16459
16460 \end_inset 
16461
16462
16463 \begin_inset LatexCommand \index{function prologue}
16464
16465 \end_inset 
16466
16467  function1[,function2[,function3...]] - The compiler by default uses a caller
16468  saves convention for register saving across function calls, however this
16469  can cause unnecessary register pushing & popping
16470 \begin_inset LatexCommand \index{push/pop}
16471
16472 \end_inset 
16473
16474  when calling small functions from larger functions.
16475  This option can be used to switch off the register saving convention for
16476  the function names specified.
16477  The compiler will not save registers when calling these functions, extra
16478  code need to be manually inserted at the entry & exit for these functions
16479  to save & restore the registers used by these functions, this can SUBSTANTIALLY
16480  reduce code & improve run time performance of the generated code.
16481  In the future the compiler (with inter procedural analysis) may be able
16482  to determine the appropriate scheme to use for each function call.
16483  If -
16484 \begin_inset ERT
16485 status Collapsed
16486
16487 \layout Standard
16488
16489 \backslash 
16490 /
16491 \end_inset 
16492
16493 -callee-saves command line option is used, the function names specified
16494  in #pragma\SpecialChar ~
16495 callee_saves
16496 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16497
16498 \end_inset 
16499
16500  is appended to the list of functions specified in the command line.
16501 \layout Itemize
16502
16503
16504 \series bold 
16505 exclude
16506 \series default 
16507
16508 \begin_inset LatexCommand \index{\#pragma exclude}
16509
16510 \end_inset 
16511
16512  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
16513  of pairs of push/pop
16514 \begin_inset LatexCommand \index{push/pop}
16515
16516 \end_inset 
16517
16518  instructions in 
16519 \emph on 
16520 I
16521 \emph default 
16522 nterrupt
16523 \begin_inset LatexCommand \index{interrupt}
16524
16525 \end_inset 
16526
16527  
16528 \emph on 
16529 S
16530 \emph default 
16531 ervice 
16532 \emph on 
16533 R
16534 \emph default 
16535 outines.
16536  The directive should be placed immediately before the ISR function definition
16537  and it affects ALL ISR functions following it.
16538  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
16539 exclude\SpecialChar ~
16540 none
16541 \begin_inset LatexCommand \index{\#pragma exclude}
16542
16543 \end_inset 
16544
16545 .
16546  See also the related keyword _naked
16547 \begin_inset LatexCommand \index{\_naked}
16548
16549 \end_inset 
16550
16551
16552 \begin_inset LatexCommand \index{\_\_naked}
16553
16554 \end_inset 
16555
16556 .
16557 \layout Itemize
16558
16559
16560 \series bold 
16561 less_pedantic
16562 \series default 
16563
16564 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16565
16566 \end_inset 
16567
16568  - the compiler will not warn you anymore for obvious mistakes, you'r on
16569  your own now ;-(
16570 \layout Itemize
16571
16572
16573 \series bold 
16574 disable_warning
16575 \series default 
16576  <nnnn>
16577 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16578
16579 \end_inset 
16580
16581  - the compiler will not warn you anymore about warning number <nnnn>.
16582 \layout Itemize
16583
16584
16585 \series bold 
16586 nogcse
16587 \series default 
16588
16589 \begin_inset LatexCommand \index{\#pragma nogcse}
16590
16591 \end_inset 
16592
16593  - will stop global common subexpression elimination.
16594 \layout Itemize
16595
16596
16597 \series bold 
16598 noinduction
16599 \series default 
16600
16601 \begin_inset LatexCommand \index{\#pragma noinduction}
16602
16603 \end_inset 
16604
16605  - will stop loop induction optimizations.
16606 \layout Itemize
16607
16608
16609 \series bold 
16610 noinvariant
16611 \series default 
16612
16613 \begin_inset LatexCommand \index{\#pragma noinvariant}
16614
16615 \end_inset 
16616
16617  - will not do loop invariant optimizations.
16618  For more details see Loop Invariants in section
16619 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16620
16621 \end_inset 
16622
16623 .
16624 \layout Itemize
16625
16626
16627 \series bold 
16628 noiv
16629 \series default 
16630
16631 \begin_inset LatexCommand \index{\#pragma noiv}
16632
16633 \end_inset 
16634
16635  - Do not generate interrupt
16636 \begin_inset LatexCommand \index{interrupt}
16637
16638 \end_inset 
16639
16640  vector table
16641 \begin_inset LatexCommand \index{interrupt vector table}
16642
16643 \end_inset 
16644
16645  entries for all ISR functions defined after the pragma.
16646  This is useful in cases where the interrupt vector table must be defined
16647  manually, or when there is a secondary, manually defined interrupt vector
16648  table (e.g.
16649  for the autovector feature of the Cypress EZ-USB FX2).
16650  More elegantly this can be achieved by obmitting the optional interrupt
16651  number after the interrupt keyword, see section 
16652 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16653
16654 \end_inset 
16655
16656 \SpecialChar ~
16657 about interrupts.
16658 \layout Itemize
16659
16660
16661 \series bold 
16662 nojtbound
16663 \series default 
16664
16665 \begin_inset LatexCommand \index{\#pragma nojtbound}
16666
16667 \end_inset 
16668
16669  - will not generate code for boundary value checking, when switch statements
16670  are turned into jump-tables (dangerous).
16671  For more details see section 
16672 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16673
16674 \end_inset 
16675
16676 .
16677 \layout Itemize
16678
16679
16680 \series bold 
16681 noloopreverse
16682 \series default 
16683
16684 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16685
16686 \end_inset 
16687
16688  - Will not do loop reversal optimization
16689 \layout Itemize
16690
16691
16692 \series bold 
16693 nooverlay
16694 \series default 
16695
16696 \begin_inset LatexCommand \index{\#pragma nooverlay}
16697
16698 \end_inset 
16699
16700  - the compiler will not overlay the parameters and local variables of a
16701  function.
16702 \layout Itemize
16703
16704
16705 \series bold 
16706 stackauto
16707 \series default 
16708
16709 \begin_inset LatexCommand \index{\#pragma stackauto}
16710
16711 \end_inset 
16712
16713 - See option -
16714 \begin_inset ERT
16715 status Collapsed
16716
16717 \layout Standard
16718
16719 \backslash 
16720 /
16721 \end_inset 
16722
16723 -stack-auto
16724 \begin_inset LatexCommand \index{-\/-stack-auto}
16725
16726 \end_inset 
16727
16728  and section 
16729 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16730
16731 \end_inset 
16732
16733  Parameters and Local Variables.
16734 \layout Itemize
16735
16736
16737 \series bold 
16738 opt_code_speed
16739 \series default 
16740  
16741 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16742
16743 \end_inset 
16744
16745 - The compiler will optimize code generation towards fast code, possibly
16746  at the expense of code size.
16747  Currently this has little effect.
16748 \layout Itemize
16749
16750
16751 \series bold 
16752 opt_code_size
16753 \series default 
16754  
16755 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16756
16757 \end_inset 
16758
16759 - The compiler will optimize code generation towards compact code, possibly
16760  at the expense of code speed.
16761  Currently this has little effect.
16762 \layout Itemize
16763
16764
16765 \series bold 
16766 opt_code_balanced
16767 \series default 
16768  
16769 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16770
16771 \end_inset 
16772
16773 - The compiler will attempt to generate code that is both compact and fast,
16774  as long as meeting one goal is not a detriment to the other (this is the
16775  default).
16776  
16777 \layout Itemize
16778
16779
16780 \series bold 
16781 std_sdcc89
16782 \series default 
16783  
16784 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16785
16786 \end_inset 
16787
16788 - Generally follow the C89 standard, but allow SDCC features that conflict
16789  with the standard (default).
16790 \layout Itemize
16791
16792
16793 \series bold 
16794 std_c89
16795 \series default 
16796  
16797 \begin_inset LatexCommand \index{\#pragma std\_c89}
16798
16799 \end_inset 
16800
16801 - Follow the C89 standard and disable SDCC features that conflict with the
16802  standard.
16803 \layout Itemize
16804
16805
16806 \series bold 
16807 std_sdcc99
16808 \series default 
16809  
16810 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16811
16812 \end_inset 
16813
16814 - Generally follow the C99 standard, but allow SDCC features that conflict
16815  with the standard (incomplete support).
16816 \layout Itemize
16817
16818
16819 \series bold 
16820 std_c99
16821 \series default 
16822  
16823 \begin_inset LatexCommand \index{\#pragma std\_c99}
16824
16825 \end_inset 
16826
16827 - Follow the C99 standard and disable SDCC features that conflict with the
16828  standard (incomplete support).
16829 \layout Itemize
16830
16831
16832 \series bold 
16833 codeseg
16834 \series default 
16835  <name>
16836 \begin_inset LatexCommand \index{\#pragma codeseg}
16837
16838 \end_inset 
16839
16840 - Use this name (max.
16841  8 characters) for the code segment.
16842  See option -
16843 \begin_inset ERT
16844 status Collapsed
16845
16846 \layout Standard
16847
16848 \backslash 
16849 /
16850 \end_inset 
16851
16852 -codeseg.
16853 \layout Itemize
16854
16855
16856 \series bold 
16857 constseg
16858 \series default 
16859  <name>
16860 \begin_inset LatexCommand \index{\#pragma constseg}
16861
16862 \end_inset 
16863
16864 - Use this name (max.
16865  8 characters) for the const segment.
16866  See option -
16867 \begin_inset ERT
16868 status Collapsed
16869
16870 \layout Standard
16871
16872 \backslash 
16873 /
16874 \end_inset 
16875
16876 -constseg.
16877 \layout Standard
16878
16879 The preprocessor SDCPP
16880 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
16881
16882 \end_inset 
16883
16884  supports the following #pragma directives:
16885 \layout Itemize
16886
16887
16888 \series bold 
16889 preproc_asm
16890 \series default 
16891
16892 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16893
16894 \end_inset 
16895
16896  (+ | -) - switch _asm _endasm block preprocessing on / off.
16897  Default is on.
16898  You use this prama to define multilines of assembly code.
16899  This will prevent the preprocessor from changing the formating required
16900  by assembly code.
16901  Below is an example on how to use this pragma.
16902 \layout Verse
16903
16904
16905 \family typewriter 
16906 #pragma preproc_asm -
16907 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16908
16909 \end_inset 
16910
16911
16912 \newline 
16913 #define MYDELAY _asm
16914 \newline 
16915 \SpecialChar ~
16916 \SpecialChar ~
16917 \SpecialChar ~
16918 nop ;my assembly comment...
16919 \newline 
16920 \SpecialChar ~
16921 \SpecialChar ~
16922 \SpecialChar ~
16923 nop
16924 \newline 
16925 \SpecialChar ~
16926 \SpecialChar ~
16927 \SpecialChar ~
16928 nop
16929 \newline 
16930 _endasm
16931 \newline 
16932 #pragma preproc_asm +
16933 \newline 
16934
16935 \newline 
16936 void foo (void) 
16937 \newline 
16938
16939 \newline 
16940 \SpecialChar ~
16941 \SpecialChar ~
16942 \SpecialChar ~
16943  ...
16944  
16945 \newline 
16946 \SpecialChar ~
16947 \SpecialChar ~
16948 \SpecialChar ~
16949  MYDELAY;
16950 \newline 
16951 \SpecialChar ~
16952 \SpecialChar ~
16953 \SpecialChar ~
16954  ...
16955  
16956 \newline 
16957
16958 \newline 
16959
16960 \layout Standard
16961
16962 The pragma's are intended to be used to turn-on or off certain optimizations
16963  which might cause the compiler to generate extra stack / data space to
16964  store compiler generated temporary variables.
16965  This usually happens in large functions.
16966  Pragma directives should be used as shown in the following example, they
16967  are used to control options & optimizations for a given function; pragmas
16968  should be placed before and/or after a function, placing pragma's inside
16969  a function body could have unpredictable results.
16970 \layout Verse
16971
16972
16973 \family typewriter 
16974 #pragma save
16975 \begin_inset LatexCommand \index{\#pragma save}
16976
16977 \end_inset 
16978
16979  \SpecialChar ~
16980 \SpecialChar ~
16981 \SpecialChar ~
16982 \SpecialChar ~
16983 \SpecialChar ~
16984 \SpecialChar ~
16985 \SpecialChar ~
16986 /* save the current settings */ 
16987 \newline 
16988 #pragma nogcse
16989 \begin_inset LatexCommand \index{\#pragma nogcse}
16990
16991 \end_inset 
16992
16993  \SpecialChar ~
16994 \SpecialChar ~
16995 \SpecialChar ~
16996 \SpecialChar ~
16997 \SpecialChar ~
16998 /* turnoff global subexpression elimination */ 
16999 \newline 
17000 #pragma noinduction
17001 \begin_inset LatexCommand \index{\#pragma noinduction}
17002
17003 \end_inset 
17004
17005  /* turn off induction optimizations */ 
17006 \newline 
17007 int foo () 
17008 \newline 
17009
17010 \newline 
17011 \SpecialChar ~
17012  \SpecialChar ~
17013  ...
17014  
17015 \newline 
17016 \SpecialChar ~
17017  \SpecialChar ~
17018  /* large code */ 
17019 \newline 
17020 \SpecialChar ~
17021  \SpecialChar ~
17022  ...
17023  
17024 \newline 
17025
17026 \newline 
17027 #pragma restore
17028 \begin_inset LatexCommand \index{\#pragma restore}
17029
17030 \end_inset 
17031
17032  /* turn the optimizations back on */
17033 \layout Standard
17034
17035 The compiler will generate a warning message when extra space is allocated.
17036  It is strongly recommended that the save and restore pragma's be used when
17037  changing options for a function.
17038 \newline 
17039
17040 \newline 
17041
17042 \newline 
17043
17044 \layout Section
17045
17046 Defines Created by the Compiler
17047 \layout Standard
17048
17049 The compiler creates the following #defines
17050 \begin_inset LatexCommand \index{\#defines}
17051
17052 \end_inset 
17053
17054
17055 \begin_inset LatexCommand \index{Defines created by the compiler}
17056
17057 \end_inset 
17058
17059 :
17060 \newline 
17061
17062 \layout Standard
17063
17064
17065 \begin_inset  Tabular
17066 <lyxtabular version="3" rows="11" columns="2">
17067 <features>
17068 <column alignment="left" valignment="top" leftline="true" width="3in">
17069 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
17070 <row topline="true" bottomline="true">
17071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17072 \begin_inset Text
17073
17074 \layout Standard
17075
17076
17077 \series bold 
17078 #define
17079 \end_inset 
17080 </cell>
17081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17082 \begin_inset Text
17083
17084 \layout Standard
17085
17086
17087 \series bold 
17088 Description
17089 \end_inset 
17090 </cell>
17091 </row>
17092 <row topline="true">
17093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17094 \begin_inset Text
17095
17096 \layout Standard
17097
17098 SDCC
17099 \begin_inset LatexCommand \index{SDCC}
17100
17101 \end_inset 
17102
17103  
17104 \end_inset 
17105 </cell>
17106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17107 \begin_inset Text
17108
17109 \layout Standard
17110
17111 Always defined.
17112  Since version 2.5.6 the version number as an int (ex.
17113  256)
17114 \end_inset 
17115 </cell>
17116 </row>
17117 <row topline="true">
17118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17119 \begin_inset Text
17120
17121 \layout Standard
17122
17123 SDCC_mcs51
17124 \begin_inset LatexCommand \index{SDCC\_mcs51}
17125
17126 \end_inset 
17127
17128  or SDCC_ds390
17129 \begin_inset LatexCommand \index{SDCC\_ds390}
17130
17131 \end_inset 
17132
17133  or SDCC_z80
17134 \begin_inset LatexCommand \index{SDCC\_z80}
17135
17136 \end_inset 
17137
17138 , etc.
17139 \end_inset 
17140 </cell>
17141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17142 \begin_inset Text
17143
17144 \layout Standard
17145
17146 depending on the model used (e.g.: -mds390)
17147 \end_inset 
17148 </cell>
17149 </row>
17150 <row topline="true">
17151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17152 \begin_inset Text
17153
17154 \layout Standard
17155
17156 __mcs51
17157 \begin_inset LatexCommand \index{\_\_mcs51}
17158
17159 \end_inset 
17160
17161 , __ds390
17162 \begin_inset LatexCommand \index{\_\_ds390}
17163
17164 \end_inset 
17165
17166 , __hc08
17167 \begin_inset LatexCommand \index{\_\_hc08}
17168
17169 \end_inset 
17170
17171 , __z80
17172 \begin_inset LatexCommand \index{\_\_z80}
17173
17174 \end_inset 
17175
17176 , etc
17177 \end_inset 
17178 </cell>
17179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17180 \begin_inset Text
17181
17182 \layout Standard
17183
17184 depending on the model used (e.g.
17185  -mz80)
17186 \end_inset 
17187 </cell>
17188 </row>
17189 <row topline="true">
17190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17191 \begin_inset Text
17192
17193 \layout Standard
17194
17195 SDCC_STACK_AUTO
17196 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
17197
17198 \end_inset 
17199
17200
17201 \end_inset 
17202 </cell>
17203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17204 \begin_inset Text
17205
17206 \layout Standard
17207
17208 when 
17209 \emph on 
17210 -
17211 \begin_inset ERT
17212 status Collapsed
17213
17214 \layout Standard
17215
17216 \backslash 
17217 /
17218 \end_inset 
17219
17220 -stack-auto
17221 \emph default 
17222  option is used
17223 \end_inset 
17224 </cell>
17225 </row>
17226 <row topline="true">
17227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17228 \begin_inset Text
17229
17230 \layout Standard
17231
17232 SDCC_MODEL_SMALL
17233 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
17234
17235 \end_inset 
17236
17237
17238 \end_inset 
17239 </cell>
17240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17241 \begin_inset Text
17242
17243 \layout Standard
17244
17245 when 
17246 \emph on 
17247 -
17248 \begin_inset ERT
17249 status Collapsed
17250
17251 \layout Standard
17252
17253 \backslash 
17254 /
17255 \end_inset 
17256
17257 -model-small
17258 \emph default 
17259  is used
17260 \end_inset 
17261 </cell>
17262 </row>
17263 <row topline="true">
17264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17265 \begin_inset Text
17266
17267 \layout Standard
17268
17269 SDCC_MODEL_MEDIUM
17270 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
17271
17272 \end_inset 
17273
17274
17275 \end_inset 
17276 </cell>
17277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17278 \begin_inset Text
17279
17280 \layout Standard
17281
17282 when 
17283 \emph on 
17284 -
17285 \begin_inset ERT
17286 status Collapsed
17287
17288 \layout Standard
17289
17290 \backslash 
17291 /
17292 \end_inset 
17293
17294 -model-medium
17295 \emph default 
17296  is used
17297 \end_inset 
17298 </cell>
17299 </row>
17300 <row topline="true">
17301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17302 \begin_inset Text
17303
17304 \layout Standard
17305
17306 SDCC_MODEL_LARGE
17307 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
17308
17309 \end_inset 
17310
17311
17312 \end_inset 
17313 </cell>
17314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17315 \begin_inset Text
17316
17317 \layout Standard
17318
17319 when 
17320 \emph on 
17321 -
17322 \begin_inset ERT
17323 status Collapsed
17324
17325 \layout Standard
17326
17327 \backslash 
17328 /
17329 \end_inset 
17330
17331 -model-large
17332 \emph default 
17333  is used
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 SDCC_USE_XSTACK
17344 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
17345
17346 \end_inset 
17347
17348
17349 \end_inset 
17350 </cell>
17351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17352 \begin_inset Text
17353
17354 \layout Standard
17355
17356 when 
17357 \emph on 
17358 -
17359 \begin_inset ERT
17360 status Collapsed
17361
17362 \layout Standard
17363
17364 \backslash 
17365 /
17366 \end_inset 
17367
17368 -xstack
17369 \emph default 
17370  option is used
17371 \end_inset 
17372 </cell>
17373 </row>
17374 <row topline="true">
17375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17376 \begin_inset Text
17377
17378 \layout Standard
17379
17380 SDCC_STACK_TENBIT
17381 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
17382
17383 \end_inset 
17384
17385  
17386 \end_inset 
17387 </cell>
17388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17389 \begin_inset Text
17390
17391 \layout Standard
17392
17393 when 
17394 \emph on 
17395 -mds390
17396 \emph default 
17397  is used
17398 \end_inset 
17399 </cell>
17400 </row>
17401 <row topline="true" bottomline="true">
17402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17403 \begin_inset Text
17404
17405 \layout Standard
17406
17407 SDCC_MODEL_FLAT24
17408 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
17409
17410 \end_inset 
17411
17412
17413 \end_inset 
17414 </cell>
17415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17416 \begin_inset Text
17417
17418 \layout Standard
17419
17420 when 
17421 \emph on 
17422 -mds390
17423 \emph default 
17424  is used
17425 \end_inset 
17426 </cell>
17427 </row>
17428 </lyxtabular>
17429
17430 \end_inset 
17431
17432
17433 \layout Chapter
17434
17435 Notes on supported Processors
17436 \layout Section
17437
17438 MCS51 variants
17439 \begin_inset LatexCommand \label{sub:MCS51-variants}
17440
17441 \end_inset 
17442
17443
17444 \begin_inset LatexCommand \index{MCS51 variants}
17445
17446 \end_inset 
17447
17448
17449 \layout Standard
17450
17451 MCS51 processors are available from many vendors and come in many different
17452  flavours.
17453  While they might differ considerably in respect to Special Function Registers
17454  the core MCS51 is usually not modified or is kept compatible.
17455  
17456 \layout Subsection
17457
17458 pdata access by SFR 
17459 \layout Standard
17460
17461 With the upcome of devices with internal xdata and flash memory devices
17462  using port P2
17463 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17464
17465 \end_inset 
17466
17467  as dedicated I/O port is becoming more popular.
17468  Switching the high byte for pdata
17469 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17470
17471 \end_inset 
17472
17473  access which was formerly done by port P2 is then achieved by a Special
17474  Function Register
17475 \begin_inset LatexCommand \index{sfr}
17476
17477 \end_inset 
17478
17479 .
17480  In well-established MCS51 tradition the address of this 
17481 \emph on 
17482 sfr
17483 \emph default 
17484  is where the chip designers decided to put it.
17485  Needless to say that they didn't agree on a common name either.
17486  So that the startup code can correctly initialize xdata variables, you
17487  should define an sfr with the name _XPAGE
17488 \family typewriter 
17489
17490 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
17491
17492 \end_inset 
17493
17494
17495 \family default 
17496  at the appropriate location if the default, port P2, is not used for this.
17497  Some examples are:
17498 \layout Verse
17499
17500
17501 \family typewriter 
17502 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
17503 \layout Verse
17504
17505
17506 \family typewriter 
17507 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17508 \layout Verse
17509
17510
17511 \family typewriter 
17512 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17513 \layout Standard
17514
17515 For more exotic implementations further customizations may be needed.
17516  See section 
17517 \begin_inset LatexCommand \ref{sub:Startup-Code}
17518
17519 \end_inset 
17520
17521  for other possibilities.
17522 \layout Subsection
17523
17524 Other Features available by SFR
17525 \layout Standard
17526 \added_space_bottom bigskip 
17527 Some MCS51 variants offer features like Double DPTR
17528 \begin_inset LatexCommand \index{DPTR}
17529
17530 \end_inset 
17531
17532 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17533  These are currently not used for the MCS51 port.
17534  If you absolutely need them you can fall back to inline assembly or submit
17535  a patch to SDCC.
17536 \layout Section
17537
17538 DS400 port
17539 \layout Standard
17540 \added_space_bottom bigskip 
17541 The DS80C400
17542 \begin_inset LatexCommand \index{DS80C400}
17543
17544 \end_inset 
17545
17546
17547 \begin_inset LatexCommand \index{DS400}
17548
17549 \end_inset 
17550
17551  microcontroller has a rich set of peripherals.
17552  In its built-in ROM library it includes functions to access some of the
17553  features, among them is a TCP stack with IP4 and IP6 support.
17554  Library headers (currently in beta status) and other files are provided
17555  at 
17556 \size footnotesize 
17557
17558 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
17559
17560 \end_inset 
17561
17562 .
17563  
17564 \layout Section
17565
17566 The Z80 and gbz80 port
17567 \layout Standard
17568
17569 SDCC can target both the Zilog Z80
17570 \begin_inset LatexCommand \index{Z80}
17571
17572 \end_inset 
17573
17574  and the Nintendo Gameboy's Z80-like gbz80
17575 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17576
17577 \end_inset 
17578
17579 .
17580  The Z80 port is passed through the same 
17581 \emph on 
17582 regressions tests
17583 \begin_inset LatexCommand \index{Regression test}
17584
17585 \end_inset 
17586
17587
17588 \emph default 
17589  (see section 
17590 \begin_inset LatexCommand \ref{sec:Quality-control}
17591
17592 \end_inset 
17593
17594 ) as the MCS51 and DS390 ports, so floating point support, support for long
17595  variables and bitfield support is fine.
17596  See mailing lists and forums about interrupt routines.
17597 \layout Standard
17598 \added_space_bottom bigskip 
17599 As always, the code is the authoritative reference - see z80/ralloc.c and
17600  z80/gen.c.
17601  The stack
17602 \begin_inset LatexCommand \index{Z80!stack}
17603
17604 \end_inset 
17605
17606  frame is similar to that generated by the IAR Z80 compiler.
17607  IX is used as the base pointer, HL and IY are used as a temporary registers,
17608  and BC and DE are available for holding variables.
17609  Return values
17610 \begin_inset LatexCommand \index{Z80!return value}
17611
17612 \end_inset 
17613
17614  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
17615  bytes).
17616  The gbz80 port use the same set of registers for the return values, but
17617  in a different order of significance: E (one byte), DE (two bytes), or
17618  HLDE (four bytes).
17619 \layout Section
17620
17621 The HC08 port
17622 \layout Standard
17623
17624 The port to the Freescale/Motorola HC08
17625 \begin_inset LatexCommand \index{HC08}
17626
17627 \end_inset 
17628
17629  family has been added in October 2003, and is still undergoing some basic
17630  development.
17631  The code generator is complete, but the register allocation is still quite
17632  unoptimized.
17633  Some of the SDCC's standard C library functions have embedded non-HC08
17634  inline assembly and so are not yet usable.
17635 \layout Standard
17636 \added_space_bottom bigskip 
17637 The HC08 port passes the regression test suite (see section 
17638 \begin_inset LatexCommand \ref{sec:Quality-control}
17639
17640 \end_inset 
17641
17642 ).
17643 \layout Section
17644 \pagebreak_top 
17645 The PIC14 port
17646 \layout Standard
17647
17648 The 14bit PIC
17649 \begin_inset LatexCommand \index{PIC14}
17650
17651 \end_inset 
17652
17653  port still requires a major effort from the development community.
17654  However it can work for simple code.
17655  It passes its (smaller set of) regression tests
17656 \begin_inset LatexCommand \index{Regression test (PIC14)}
17657
17658 \end_inset 
17659
17660  in the directory 
17661 \shape italic 
17662 sdcc/src/regression
17663 \shape default 
17664 .
17665 \layout Subsection
17666
17667 C code and 14bit PIC code page
17668 \begin_inset LatexCommand \index{code page (pic14)}
17669
17670 \end_inset 
17671
17672  and RAM banks
17673 \begin_inset LatexCommand \index{RAM bank (pic14)}
17674
17675 \end_inset 
17676
17677
17678 \layout Standard
17679
17680 The linker organizes allocation for the code page and RAM banks.
17681  It does not have intimate knowledge of the code flow.
17682  It will put all the code section of a single asm file into a single code
17683  page.
17684  In order to make use of multiple code pages, separate asm files must be
17685  used.
17686  The compiler treats all functions of a single C file as being in the same
17687  code page unless it is non static.
17688  The compiler treats all local variables of a single C file as being in
17689  the same RAM bank unless it is an extern.
17690 \newline 
17691
17692 \newline 
17693 To get the best follow these guide lines:
17694 \layout Enumerate
17695
17696 make local functions static, as non static functions require code page selection
17697  overhead.
17698 \layout Enumerate
17699
17700 Make local variables static as extern variables require RAM bank selection
17701  overhead.
17702 \layout Enumerate
17703
17704 For devices that have multiple code pages it is more efficient to use the
17705  same number of files as pages, i.e.
17706  for the 16F877 use 4 separate files and i.e.
17707  for the 16F874 use 2 separate files.
17708  This way the linker can put the code for each file into different code
17709  pages and the compiler can allocate reusable variables more efficiently
17710  and there's less page selection overhead.
17711  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17712  instruction set) use 'unsigned char' whereever possible instead of 'int'.
17713 \layout Subsection
17714
17715 Creating a device include file 
17716 \layout Standard
17717
17718 For generating a device include file
17719 \begin_inset LatexCommand \index{PIC14!Header files}
17720
17721 \end_inset 
17722
17723  use the support perl script inc2h.pl kept in directory support/script.
17724 \layout Subsection
17725
17726 Interrupt code
17727 \layout Standard
17728
17729 For the interrupt function, use the keyword 'interrupt'
17730 \begin_inset LatexCommand \index{PIC14!interrupt}
17731
17732 \end_inset 
17733
17734  with level number of 0 (PIC14 only has 1 interrupt so this number is only
17735  there to avoid a syntax error - it ought to be fixed).
17736  E.g.:
17737 \layout Verse
17738
17739
17740 \family typewriter 
17741 void Intr(void) interrupt 0
17742 \newline 
17743 {
17744 \newline 
17745 \SpecialChar ~
17746 \SpecialChar ~
17747 T0IF = 0; /* Clear timer interrupt */
17748 \newline 
17749 }
17750 \layout Subsection
17751
17752 Linking and assembling
17753 \layout Standard
17754
17755 For assembling you can use either GPUTILS'
17756 \begin_inset LatexCommand \index{gputils (pic tools)}
17757
17758 \end_inset 
17759
17760  gpasm.exe or MPLAB's mpasmwin.exe.
17761  GPUTILS is available from 
17762 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17763
17764 \end_inset 
17765
17766 .
17767  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17768  If you use MPLAB and an interrupt function then the linker script file
17769  vectors section will need to be enlarged to link with mplink.
17770 \newline 
17771
17772 \newline 
17773 Here is a 
17774 \family typewriter 
17775 Makefile
17776 \family default 
17777  using GPUTILS:
17778 \layout Verse
17779
17780
17781 \family typewriter 
17782 .c.o:
17783 \newline 
17784 \SpecialChar ~
17785 \SpecialChar ~
17786 \SpecialChar ~
17787 \SpecialChar ~
17788 \SpecialChar ~
17789 \SpecialChar ~
17790 \SpecialChar ~
17791 \SpecialChar ~
17792 sdcc -S -V -mpic14 -p16F877 $< 
17793 \newline 
17794 \SpecialChar ~
17795 \SpecialChar ~
17796 \SpecialChar ~
17797 \SpecialChar ~
17798 \SpecialChar ~
17799 \SpecialChar ~
17800 \SpecialChar ~
17801 \SpecialChar ~
17802 gpasm -c $*.asm
17803 \newline 
17804
17805 \newline 
17806 $(PRJ).hex: $(OBJS) 
17807 \newline 
17808 \SpecialChar ~
17809 \SpecialChar ~
17810 \SpecialChar ~
17811 \SpecialChar ~
17812 \SpecialChar ~
17813 \SpecialChar ~
17814 \SpecialChar ~
17815 \SpecialChar ~
17816 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
17817 \layout Standard
17818
17819 Here is a 
17820 \family typewriter 
17821 Makefile
17822 \family default 
17823  using MPLAB:
17824 \layout Verse
17825
17826
17827 \family typewriter 
17828 .c.o: 
17829 \newline 
17830 \SpecialChar ~
17831 \SpecialChar ~
17832 \SpecialChar ~
17833 \SpecialChar ~
17834 \SpecialChar ~
17835 \SpecialChar ~
17836 \SpecialChar ~
17837 \SpecialChar ~
17838 sdcc -S -V -mpic14 -p16F877 $< 
17839 \newline 
17840 \SpecialChar ~
17841 \SpecialChar ~
17842 \SpecialChar ~
17843 \SpecialChar ~
17844 \SpecialChar ~
17845 \SpecialChar ~
17846 \SpecialChar ~
17847 \SpecialChar ~
17848 mpasmwin /q /o $*.asm
17849 \newline 
17850
17851 \newline 
17852 $(PRJ).hex: $(OBJS) 
17853 \newline 
17854 \SpecialChar ~
17855 \SpecialChar ~
17856 \SpecialChar ~
17857 \SpecialChar ~
17858 \SpecialChar ~
17859 \SpecialChar ~
17860 \SpecialChar ~
17861 \SpecialChar ~
17862 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17863 \layout Standard
17864
17865 Please note that indentations within a
17866 \family typewriter 
17867  Makefile
17868 \family default 
17869  have to be done with a tabulator character.
17870 \layout Subsection
17871
17872 Command-line options
17873 \layout Standard
17874
17875 Besides the switches common to all SDCC backends, the PIC14 port accepts
17876  the following options (for an updated list see sdcc -
17877 \begin_inset ERT
17878 status Collapsed
17879
17880 \layout Standard
17881
17882 \backslash 
17883 /
17884 \end_inset 
17885
17886 -help):
17887 \layout List
17888 \labelwidthstring 00.00.0000
17889
17890 -
17891 \begin_inset ERT
17892 status Collapsed
17893
17894 \layout Standard
17895
17896 \backslash 
17897 /
17898 \end_inset 
17899
17900 -debug-extra
17901 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
17902
17903 \end_inset 
17904
17905  emit debug info in assembly output
17906 \layout List
17907 \labelwidthstring 00.00.0000
17908
17909 -
17910 \begin_inset ERT
17911 status Collapsed
17912
17913 \layout Standard
17914
17915 \backslash 
17916 /
17917 \end_inset 
17918
17919 -no-pcode-opt
17920 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
17921
17922 \end_inset 
17923
17924  disable (slightly faulty) optimization on pCode
17925 \layout Subsection
17926
17927 The library
17928 \layout Subsubsection
17929
17930 error: missing definition for symbol 
17931 \begin_inset Quotes sld
17932 \end_inset 
17933
17934 __gptrget1
17935 \begin_inset Quotes srd
17936 \end_inset 
17937
17938
17939 \layout Standard
17940
17941 The PIC14 port uses library routines to provide more complex operations
17942  like multiplication, division/modulus and (generic) pointer dereferencing.
17943  In order to add these routines to your project, you must link with PIC14's
17944  
17945 \family typewriter 
17946 libsdcc.lib
17947 \family default 
17948 .
17949  For single source file projects this is done automatically, more complex
17950  projects must add 
17951 \family typewriter 
17952 libsdcc.lib
17953 \family default 
17954  to the linker's arguments.
17955  Make sure you also add an include path for the library (using the -I switch
17956  to the linker)!
17957 \layout Subsubsection
17958
17959 Processor mismatch in file 
17960 \begin_inset Quotes sld
17961 \end_inset 
17962
17963 XXX
17964 \begin_inset Quotes srd
17965 \end_inset 
17966
17967 .
17968 \layout Standard
17969
17970 This warning can usually be ignored due to the very good compatibility amongst
17971  14 bit PIC
17972 \begin_inset LatexCommand \index{PIC14}
17973
17974 \end_inset 
17975
17976  devices.
17977 \layout Standard
17978
17979 You might also consider recompiling the library for your specific device
17980  by changing the ARCH=p16f877 (default target) entry in 
17981 \family typewriter 
17982 device/lib/pic/Makefile.in
17983 \family default 
17984  and 
17985 \family typewriter 
17986 device/lib/pic/Makefile
17987 \family default 
17988  to reflect your device.
17989  This might even improve performance for smaller devices as unneccesary
17990  BANKSELs migth be removed.
17991 \layout Subsection
17992
17993 Known bugs
17994 \layout Subsubsection
17995
17996 initialized data
17997 \layout Standard
17998
17999 Currently, data can only be initialized if it resides in the source file
18000  together with 
18001 \emph on 
18002 main()
18003 \emph default 
18004 .
18005  Data in other source files will silently 
18006 \series bold 
18007 not
18008 \series default 
18009  be initialized.
18010 \family typewriter 
18011 \size footnotesize 
18012
18013 \begin_inset Marginal
18014 collapsed true
18015
18016 \layout Standard
18017
18018
18019 \series bold 
18020 \SpecialChar ~
18021 !
18022 \end_inset 
18023
18024
18025 \layout Section
18026 \pagebreak_top 
18027 The PIC16
18028 \begin_inset LatexCommand \index{PIC16}
18029
18030 \end_inset 
18031
18032  port
18033 \layout Standard
18034
18035 The PIC16
18036 \begin_inset LatexCommand \index{PIC16}
18037
18038 \end_inset 
18039
18040  port is the portion of SDCC that is responsible to produce code for the
18041  Microchip
18042 \begin_inset LatexCommand \index{Microchip}
18043
18044 \end_inset 
18045
18046 (TM) microcontrollers with 16 bit core.
18047  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
18048  Currently supported devices are:
18049 \layout Standard
18050 \align center 
18051
18052 \begin_inset  Tabular
18053 <lyxtabular version="3" rows="4" columns="6">
18054 <features>
18055 <column alignment="center" valignment="top" leftline="true" width="0">
18056 <column alignment="center" valignment="top" leftline="true" width="0">
18057 <column alignment="center" valignment="top" leftline="true" width="0">
18058 <column alignment="center" valignment="top" leftline="true" width="0">
18059 <column alignment="center" valignment="top" leftline="true" width="0">
18060 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18061 <row topline="true">
18062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18063 \begin_inset Text
18064
18065 \layout Standard
18066
18067 18F242
18068 \end_inset 
18069 </cell>
18070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18071 \begin_inset Text
18072
18073 \layout Standard
18074
18075 18F248
18076 \end_inset 
18077 </cell>
18078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18079 \begin_inset Text
18080
18081 \layout Standard
18082
18083 18F252
18084 \end_inset 
18085 </cell>
18086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18087 \begin_inset Text
18088
18089 \layout Standard
18090
18091 18F258
18092 \end_inset 
18093 </cell>
18094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18095 \begin_inset Text
18096
18097 \layout Standard
18098
18099 18F442
18100 \end_inset 
18101 </cell>
18102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18103 \begin_inset Text
18104
18105 \layout Standard
18106
18107 18F448
18108 \end_inset 
18109 </cell>
18110 </row>
18111 <row topline="true">
18112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18113 \begin_inset Text
18114
18115 \layout Standard
18116
18117 18F452
18118 \end_inset 
18119 </cell>
18120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18121 \begin_inset Text
18122
18123 \layout Standard
18124
18125 18F458
18126 \end_inset 
18127 </cell>
18128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18129 \begin_inset Text
18130
18131 \layout Standard
18132
18133 18F1220
18134 \end_inset 
18135 </cell>
18136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18137 \begin_inset Text
18138
18139 \layout Standard
18140
18141 18F2220
18142 \end_inset 
18143 </cell>
18144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18145 \begin_inset Text
18146
18147 \layout Standard
18148
18149 18F2550
18150 \end_inset 
18151 </cell>
18152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18153 \begin_inset Text
18154
18155 \layout Standard
18156
18157 18F4331
18158 \end_inset 
18159 </cell>
18160 </row>
18161 <row topline="true">
18162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18163 \begin_inset Text
18164
18165 \layout Standard
18166
18167 18F4455
18168 \end_inset 
18169 </cell>
18170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18171 \begin_inset Text
18172
18173 \layout Standard
18174
18175 18F6520
18176 \end_inset 
18177 </cell>
18178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18179 \begin_inset Text
18180
18181 \layout Standard
18182
18183 18F6620
18184 \end_inset 
18185 </cell>
18186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18187 \begin_inset Text
18188
18189 \layout Standard
18190
18191 18F6680
18192 \end_inset 
18193 </cell>
18194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18195 \begin_inset Text
18196
18197 \layout Standard
18198
18199 18F6720
18200 \end_inset 
18201 </cell>
18202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18203 \begin_inset Text
18204
18205 \layout Standard
18206
18207 18F8520
18208 \end_inset 
18209 </cell>
18210 </row>
18211 <row topline="true" bottomline="true">
18212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18213 \begin_inset Text
18214
18215 \layout Standard
18216
18217 18F8620
18218 \end_inset 
18219 </cell>
18220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18221 \begin_inset Text
18222
18223 \layout Standard
18224
18225 18F8680
18226 \end_inset 
18227 </cell>
18228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18229 \begin_inset Text
18230
18231 \layout Standard
18232
18233 18F8720
18234 \end_inset 
18235 </cell>
18236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18237 \begin_inset Text
18238
18239 \layout Standard
18240
18241 \end_inset 
18242 </cell>
18243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18244 \begin_inset Text
18245
18246 \layout Standard
18247
18248 \end_inset 
18249 </cell>
18250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18251 \begin_inset Text
18252
18253 \layout Standard
18254
18255 \end_inset 
18256 </cell>
18257 </row>
18258 </lyxtabular>
18259
18260 \end_inset 
18261
18262
18263 \layout Subsection
18264
18265 Global Options
18266 \layout Standard
18267
18268 PIC16 port supports the standard command line arguments as supposed, with
18269  the exception of certain cases that will be mentioned in the following
18270  list:
18271 \layout List
18272 \labelwidthstring 00.00.0000
18273
18274 -
18275 \begin_inset ERT
18276 status Collapsed
18277
18278 \layout Standard
18279
18280 \backslash 
18281 /
18282 \end_inset 
18283
18284 -callee-saves
18285 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
18286
18287 \end_inset 
18288
18289  See -
18290 \begin_inset ERT
18291 status Collapsed
18292
18293 \layout Standard
18294
18295 \backslash 
18296 /
18297 \end_inset 
18298
18299 -all-callee-saves
18300 \layout List
18301 \labelwidthstring 00.00.0000
18302
18303 -
18304 \begin_inset ERT
18305 status Collapsed
18306
18307 \layout Standard
18308
18309 \backslash 
18310 /
18311 \end_inset 
18312
18313 -all-callee-saves
18314 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
18315
18316 \end_inset 
18317
18318  All function arguments are passed on stack by default.
18319  
18320 \emph on 
18321 There is no need to specify this in the command line.
18322 \layout List
18323 \labelwidthstring 00.00.0000
18324
18325 -
18326 \begin_inset ERT
18327 status Collapsed
18328
18329 \layout Standard
18330
18331 \backslash 
18332 /
18333 \end_inset 
18334
18335 -fommit-frame-pointer
18336 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
18337
18338 \end_inset 
18339
18340  Frame pointer will be omitted when the function uses no local variables.
18341 \layout Subsection
18342
18343 Port Specific Options
18344 \begin_inset LatexCommand \index{Options PIC16}
18345
18346 \end_inset 
18347
18348
18349 \layout Standard
18350
18351 The port specific options appear after the global options in the sdcc --help
18352  output.
18353 \layout Subsubsection
18354
18355 General Options
18356 \layout Standard
18357
18358 General options enable certain port features and optimizations.
18359 \layout List
18360 \labelwidthstring 00.00.0000
18361
18362 -
18363 \begin_inset ERT
18364 status Collapsed
18365
18366 \layout Standard
18367
18368 \backslash 
18369 /
18370 \end_inset 
18371
18372 -stack-model=[model] Used in conjuction with the command above.
18373  Defines the stack model to be used, valid stack models are : 
18374 \begin_deeper 
18375 \layout List
18376 \labelwidthstring 00.00.0000
18377
18378
18379 \emph on 
18380 small
18381 \emph default 
18382  Selects small stack model.
18383  8 bit stack and frame pointers.
18384  Supports 256 bytes stack size.
18385 \layout List
18386 \labelwidthstring 00.00.0000
18387
18388
18389 \emph on 
18390 large
18391 \emph default 
18392  Selects large stack model.
18393  16 bit stack and frame pointers.
18394  Supports 65536 bytes stack size.
18395 \end_deeper 
18396 \layout List
18397 \labelwidthstring 00.00.0000
18398
18399 -
18400 \begin_inset ERT
18401 status Collapsed
18402
18403 \layout Standard
18404
18405 \backslash 
18406 /
18407 \end_inset 
18408
18409 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
18410  unitialized data variables with [kword].
18411  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
18412 \layout List
18413 \labelwidthstring 00.00.0000
18414
18415 -
18416 \begin_inset ERT
18417 status Collapsed
18418
18419 \layout Standard
18420
18421 \backslash 
18422 /
18423 \end_inset 
18424
18425 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
18426  Useful for bootloaders.
18427 \layout List
18428 \labelwidthstring 00.00.0000
18429
18430 -
18431 \begin_inset ERT
18432 status Collapsed
18433
18434 \layout Standard
18435
18436 \backslash 
18437 /
18438 \end_inset 
18439
18440 -asm= sets the full path and name of an external assembler to call.
18441 \layout List
18442 \labelwidthstring 00.00.0000
18443
18444 -
18445 \begin_inset ERT
18446 status Collapsed
18447
18448 \layout Standard
18449
18450 \backslash 
18451 /
18452 \end_inset 
18453
18454 -link= sets the full path and name of an external linker to call.
18455 \layout List
18456 \labelwidthstring 00.00.0000
18457
18458 -
18459 \begin_inset ERT
18460 status Collapsed
18461
18462 \layout Standard
18463
18464 \backslash 
18465 /
18466 \end_inset 
18467
18468 -mplab-comp MPLAB
18469 \begin_inset LatexCommand \index{PIC16!MPLAB}
18470
18471 \end_inset 
18472
18473  compatibility option.
18474  Currently only suppresses special gpasm directives.
18475 \layout Subsubsection
18476
18477 Optimization Options
18478 \layout List
18479 \labelwidthstring 00.00.0000
18480
18481 -
18482 \begin_inset ERT
18483 status Collapsed
18484
18485 \layout Standard
18486
18487 \backslash 
18488 /
18489 \end_inset 
18490
18491 -optimize-goto Try to use (conditional) BRA instead of GOTO
18492 \layout List
18493 \labelwidthstring 00.00.0000
18494
18495 -
18496 \begin_inset ERT
18497 status Collapsed
18498
18499 \layout Standard
18500
18501 \backslash 
18502 /
18503 \end_inset 
18504
18505 -optimize-cmp Try to optimize some compares.
18506 \layout List
18507 \labelwidthstring 00.00.0000
18508
18509 -
18510 \begin_inset ERT
18511 status Collapsed
18512
18513 \layout Standard
18514
18515 \backslash 
18516 /
18517 \end_inset 
18518
18519 -optimize-df Analyze the dataflow of the generated code and improve it.
18520 \layout List
18521 \labelwidthstring 00.00.0000
18522
18523 -
18524 \begin_inset ERT
18525 status Collapsed
18526
18527 \layout Standard
18528
18529 \backslash 
18530 /
18531 \end_inset 
18532
18533 -obanksel=nn Set optimization level for inserting BANKSELs.
18534 \newline 
18535
18536 \begin_deeper 
18537 \layout List
18538 \labelwidthstring 00.00.0000
18539
18540 0 no optimization
18541 \layout List
18542 \labelwidthstring 00.00.0000
18543
18544 1 checks previous used register and if it is the same then does not emit
18545  BANKSEL, accounts only for labels.
18546 \layout List
18547 \labelwidthstring 00.00.0000
18548
18549 2 tries to check the location of (even different) symbols and removes BANKSELs
18550  if they are in the same bank.
18551  
18552 \newline 
18553
18554 \emph on 
18555 Important: There might be problems if the linker script has data sections
18556  across bank borders!
18557 \end_deeper 
18558 \layout Subsubsection
18559
18560 Linking Options
18561 \layout List
18562 \labelwidthstring 00.00.0000
18563
18564 -
18565 \begin_inset ERT
18566 status Collapsed
18567
18568 \layout Standard
18569
18570 \backslash 
18571 /
18572 \end_inset 
18573
18574 -nodefaultlibs do not link default libraries when linking
18575 \layout List
18576 \labelwidthstring 00.00.0000
18577
18578 -
18579 \begin_inset ERT
18580 status Collapsed
18581
18582 \layout Standard
18583
18584 \backslash 
18585 /
18586 \end_inset 
18587
18588 -no-crt Don't link the default run-time modules
18589 \layout List
18590 \labelwidthstring 00.00.0000
18591
18592 -
18593 \begin_inset ERT
18594 status Collapsed
18595
18596 \layout Standard
18597
18598 \backslash 
18599 /
18600 \end_inset 
18601
18602 -use-crt= Use a custom run-time module instead of the defaults.
18603 \layout Subsubsection
18604
18605 Debugging Options
18606 \layout Standard
18607
18608 Debugging options enable extra debugging information in the output files.
18609 \layout List
18610 \labelwidthstring 00.00.0000
18611
18612 -
18613 \begin_inset ERT
18614 status Collapsed
18615
18616 \layout Standard
18617
18618 \backslash 
18619 /
18620 \end_inset 
18621
18622 -debug-xtra Similar to -
18623 \begin_inset ERT
18624 status Collapsed
18625
18626 \layout Standard
18627
18628 \backslash 
18629 /
18630 \end_inset 
18631
18632 -debug
18633 \begin_inset LatexCommand \index{-\/-debug}
18634
18635 \end_inset 
18636
18637 , but dumps more information.
18638 \layout List
18639 \labelwidthstring 00.00.0000
18640
18641 -
18642 \begin_inset ERT
18643 status Collapsed
18644
18645 \layout Standard
18646
18647 \backslash 
18648 /
18649 \end_inset 
18650
18651 -debug-ralloc Force register allocator to dump <source>.d file with debugging
18652  information.
18653  <source> is the name of the file compiled.
18654 \layout List
18655 \labelwidthstring 00.00.0000
18656
18657 -
18658 \begin_inset ERT
18659 status Collapsed
18660
18661 \layout Standard
18662
18663 \backslash 
18664 /
18665 \end_inset 
18666
18667 -pcode-verbose Enable pcode debugging information in translation.
18668 \layout List
18669 \labelwidthstring 00.00.0000
18670
18671 -
18672 \begin_inset ERT
18673 status Collapsed
18674
18675 \layout Standard
18676
18677 \backslash 
18678 /
18679 \end_inset 
18680
18681 -denable-peeps Force the usage of peepholes.
18682  Use with care.
18683 \layout List
18684 \labelwidthstring 00.00.0000
18685
18686 -
18687 \begin_inset ERT
18688 status Collapsed
18689
18690 \layout Standard
18691
18692 \backslash 
18693 /
18694 \end_inset 
18695
18696 -gstack Trace push/pops for stack pointer overflow
18697 \layout List
18698 \labelwidthstring 00.00.0000
18699
18700 -
18701 \begin_inset ERT
18702 status Collapsed
18703
18704 \layout Standard
18705
18706 \backslash 
18707 /
18708 \end_inset 
18709
18710 -call-tree dump call tree in .calltree file
18711 \layout Subsection
18712
18713 Enviromental Variables
18714 \layout Standard
18715
18716 There is a number of enviromental variables that can be used when running
18717  SDCC to enable certain optimizations or force a specific program behaviour.
18718  these variables are primarily for debugging purposes so they can be enabled/dis
18719 abled at will.
18720 \layout Standard
18721
18722 Currently there is only two such variables available:
18723 \layout List
18724 \labelwidthstring 00.00.0000
18725
18726 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18727  bitfields is optimized by directly loading FSR0 with the address of the
18728  bitfield structure.
18729  Normally SDCC will cast the bitfield structure to a bitfield pointer and
18730  then load FSR0.
18731  This step saves data ram and code space for functions that perform heavy
18732  use of bitfields.
18733  (ie.
18734  80 bytes of code space are saved when compiling malloc.c with this option).
18735  
18736 \layout List
18737 \labelwidthstring 00.00.0000
18738
18739 NO_REG_OPT do not perform pCode registers optimization.
18740  This should be used for debugging purposes.
18741  In some where bugs in the pcode optimizer are found, users can benefit
18742  from temporarily disabling the optimizer until the bug is fixed.
18743 \layout Subsection
18744
18745 Preprocessor Macros
18746 \layout Standard
18747
18748 PIC16
18749 \begin_inset LatexCommand \index{PIC16}
18750
18751 \end_inset 
18752
18753  port defines the following preprocessor macros while translating a source.
18754 \layout Standard
18755 \align center 
18756
18757 \begin_inset  Tabular
18758 <lyxtabular version="3" rows="6" columns="2">
18759 <features>
18760 <column alignment="center" valignment="top" leftline="true" width="0">
18761 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18762 <row topline="true" bottomline="true">
18763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18764 \begin_inset Text
18765
18766 \layout Standard
18767
18768 Macro
18769 \end_inset 
18770 </cell>
18771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18772 \begin_inset Text
18773
18774 \layout Standard
18775
18776 Description
18777 \end_inset 
18778 </cell>
18779 </row>
18780 <row topline="true">
18781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18782 \begin_inset Text
18783
18784 \layout Standard
18785
18786 SDCC_pic16
18787 \end_inset 
18788 </cell>
18789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18790 \begin_inset Text
18791
18792 \layout Standard
18793
18794 Port identification
18795 \end_inset 
18796 </cell>
18797 </row>
18798 <row topline="true">
18799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18800 \begin_inset Text
18801
18802 \layout Standard
18803
18804 _
18805 \begin_inset ERT
18806 status Collapsed
18807
18808 \layout Standard
18809
18810 \backslash 
18811 /
18812 \end_inset 
18813
18814 _pic16
18815 \end_inset 
18816 </cell>
18817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18818 \begin_inset Text
18819
18820 \layout Standard
18821
18822 Port identification (same as above)
18823 \end_inset 
18824 </cell>
18825 </row>
18826 <row topline="true">
18827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18828 \begin_inset Text
18829
18830 \layout Standard
18831
18832 pic18fxxxx
18833 \end_inset 
18834 </cell>
18835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18836 \begin_inset Text
18837
18838 \layout Standard
18839
18840 MCU Identification.
18841  
18842 \emph on 
18843 xxxx
18844 \emph default 
18845  is the microcontrol identification number, i.e.
18846  452, 6620, etc
18847 \end_inset 
18848 </cell>
18849 </row>
18850 <row topline="true">
18851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18852 \begin_inset Text
18853
18854 \layout Standard
18855
18856 _
18857 \begin_inset ERT
18858 status Collapsed
18859
18860 \layout Standard
18861
18862 \backslash 
18863 /
18864 \end_inset 
18865
18866 _18Fxxxx
18867 \end_inset 
18868 </cell>
18869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18870 \begin_inset Text
18871
18872 \layout Standard
18873
18874 MCU Identification (same as above)
18875 \end_inset 
18876 </cell>
18877 </row>
18878 <row topline="true" bottomline="true">
18879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18880 \begin_inset Text
18881
18882 \layout Standard
18883
18884 STACK_MODEL_nnn
18885 \end_inset 
18886 </cell>
18887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18888 \begin_inset Text
18889
18890 \layout Standard
18891
18892 nnn = SMALL or LARGE respectively according to the stack model used
18893 \end_inset 
18894 </cell>
18895 </row>
18896 </lyxtabular>
18897
18898 \end_inset 
18899
18900
18901 \layout Standard
18902
18903 In addition the following macros are defined when calling assembler:
18904 \layout Standard
18905 \align center 
18906
18907 \begin_inset  Tabular
18908 <lyxtabular version="3" rows="4" columns="2">
18909 <features>
18910 <column alignment="center" valignment="top" leftline="true" width="0">
18911 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18912 <row topline="true" bottomline="true">
18913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18914 \begin_inset Text
18915
18916 \layout Standard
18917
18918 Macro
18919 \end_inset 
18920 </cell>
18921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18922 \begin_inset Text
18923
18924 \layout Standard
18925
18926 Description
18927 \end_inset 
18928 </cell>
18929 </row>
18930 <row topline="true">
18931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18932 \begin_inset Text
18933
18934 \layout Standard
18935
18936 __18Fxxxx
18937 \end_inset 
18938 </cell>
18939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18940 \begin_inset Text
18941
18942 \layout Standard
18943
18944 MCU Identification.
18945  
18946 \emph on 
18947 xxxx
18948 \emph default 
18949  is the microcontrol identification number, i.e.
18950  452, 6620, etc
18951 \end_inset 
18952 </cell>
18953 </row>
18954 <row topline="true">
18955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18956 \begin_inset Text
18957
18958 \layout Standard
18959
18960 SDCC_MODEL_nnn
18961 \end_inset 
18962 </cell>
18963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18964 \begin_inset Text
18965
18966 \layout Standard
18967
18968 nnn = SMALL or LARGE respectively according to the memory model used for
18969  SDCC
18970 \end_inset 
18971 </cell>
18972 </row>
18973 <row topline="true" bottomline="true">
18974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18975 \begin_inset Text
18976
18977 \layout Standard
18978
18979 STACK_MODEL_nnn
18980 \end_inset 
18981 </cell>
18982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18983 \begin_inset Text
18984
18985 \layout Standard
18986
18987 nnn = SMALL or LARGE respectively according to the stack model used
18988 \end_inset 
18989 </cell>
18990 </row>
18991 </lyxtabular>
18992
18993 \end_inset 
18994
18995
18996 \layout Subsection
18997
18998 Directories
18999 \layout Standard
19000
19001 PIC16
19002 \begin_inset LatexCommand \index{PIC16}
19003
19004 \end_inset 
19005
19006  port uses the following directories for searching header files and libraries.
19007 \layout Standard
19008 \align center 
19009
19010 \begin_inset  Tabular
19011 <lyxtabular version="3" rows="3" columns="4">
19012 <features>
19013 <column alignment="center" valignment="top" leftline="true" width="0">
19014 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19015 <column alignment="center" valignment="top" width="0">
19016 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19017 <row topline="true" bottomline="true">
19018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19019 \begin_inset Text
19020
19021 \layout Standard
19022
19023 Directory
19024 \end_inset 
19025 </cell>
19026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19027 \begin_inset Text
19028
19029 \layout Standard
19030
19031 Description
19032 \end_inset 
19033 </cell>
19034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19035 \begin_inset Text
19036
19037 \layout Standard
19038
19039 Target
19040 \end_inset 
19041 </cell>
19042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19043 \begin_inset Text
19044
19045 \layout Standard
19046
19047 Command prefix
19048 \end_inset 
19049 </cell>
19050 </row>
19051 <row topline="true">
19052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19053 \begin_inset Text
19054
19055 \layout Standard
19056
19057 PREFIX/sdcc/include/pic16
19058 \end_inset 
19059 </cell>
19060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19061 \begin_inset Text
19062
19063 \layout Standard
19064
19065 PIC16 specific headers
19066 \end_inset 
19067 </cell>
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19069 \begin_inset Text
19070
19071 \layout Standard
19072
19073 Compiler
19074 \end_inset 
19075 </cell>
19076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19077 \begin_inset Text
19078
19079 \layout Standard
19080
19081 -I
19082 \end_inset 
19083 </cell>
19084 </row>
19085 <row topline="true" bottomline="true">
19086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19087 \begin_inset Text
19088
19089 \layout Standard
19090
19091 PREFIX/sdcc/lib/pic16
19092 \end_inset 
19093 </cell>
19094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19095 \begin_inset Text
19096
19097 \layout Standard
19098
19099 PIC16 specific libraries
19100 \end_inset 
19101 </cell>
19102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19103 \begin_inset Text
19104
19105 \layout Standard
19106
19107 Linker
19108 \end_inset 
19109 </cell>
19110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19111 \begin_inset Text
19112
19113 \layout Standard
19114
19115 -L
19116 \end_inset 
19117 </cell>
19118 </row>
19119 </lyxtabular>
19120
19121 \end_inset 
19122
19123
19124 \layout Subsection
19125
19126 Pragmas
19127 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
19128
19129 \end_inset 
19130
19131
19132 \layout Standard
19133
19134 PIC16
19135 \begin_inset LatexCommand \index{PIC16}
19136
19137 \end_inset 
19138
19139  port currently supports the following pragmas:
19140 \layout List
19141 \labelwidthstring 00.00.0000
19142
19143 stack
19144 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
19145
19146 \end_inset 
19147
19148  pragma stack
19149 \begin_inset LatexCommand \index{PIC16!stack}
19150
19151 \end_inset 
19152
19153  forces the code generator to initialize the stack & frame pointers at a
19154  specific address.
19155  This is an adhoc solution for cases where no STACK directive is available
19156  in the linker script or gplink is not instructed to create a stack section.
19157 \newline 
19158 The stack pragma should be used only once in a project.
19159  Multiple pragmas may result in indeterminate behaviour of the program.
19160 \begin_inset Foot
19161 collapsed false
19162
19163 \layout Standard
19164
19165 The old format (ie.
19166  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
19167  cross page boundaries (or even exceed the available data RAM) and crash
19168  the program.
19169  Make sure that stack does not cross page boundaries when using the SMALL
19170  stack model.
19171 \end_inset 
19172
19173
19174 \newline 
19175 The format is as follows:
19176 \layout LyX-Code
19177
19178 #pragma stack bottom_address [stack_size]
19179 \layout Standard
19180
19181
19182 \emph on 
19183 bottom_address
19184 \emph default 
19185  is the lower bound of the stack section.
19186  The stack pointer initially will point at address (bottom_address+stack_size-1).
19187 \layout LyX-Code
19188
19189 Example:
19190 \layout LyX-Code
19191
19192 \layout LyX-Code
19193
19194 /* initializes stack of 100 bytes at RAM address 0x200 */
19195 \layout LyX-Code
19196
19197 #pragma stack 0x200 100
19198 \layout Standard
19199
19200 If the stack_size field is omitted then a stack is created with the default
19201  size of 64.
19202  This size might be enough for most programs, but its not enough for operations
19203  with deep function nesting or excessive stack usage.
19204 \layout List
19205 \labelwidthstring 00.00.0000
19206
19207 code
19208 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
19209
19210 \end_inset 
19211
19212  place a function symbol at static FLASH address
19213 \layout LyX-Code
19214
19215 Example:
19216 \layout LyX-Code
19217
19218 \layout LyX-Code
19219
19220 /* place function test_func at 0x4000 */
19221 \layout LyX-Code
19222
19223 #pragma code test_func 0x4000
19224 \layout LyX-Code
19225
19226 \layout List
19227 \labelwidthstring 00.00.0000
19228
19229 library instructs the linker to use a library module.
19230 \newline 
19231 Usage:
19232 \layout LyX-Code
19233
19234 #pragma library module_name
19235 \layout Standard
19236
19237
19238 \emph on 
19239 module_name
19240 \emph default 
19241  can be any library or object file (including its path).
19242  Note that there are four reserved keywords which have special meaning.
19243  These are:
19244 \layout Standard
19245 \align center 
19246
19247 \begin_inset  Tabular
19248 <lyxtabular version="3" rows="6" columns="3">
19249 <features>
19250 <column alignment="center" valignment="top" leftline="true" width="0">
19251 <column alignment="block" valignment="top" leftline="true" width="20page%">
19252 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19253 <row topline="true" bottomline="true">
19254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19255 \begin_inset Text
19256
19257 \layout Standard
19258
19259 Keyword
19260 \end_inset 
19261 </cell>
19262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19263 \begin_inset Text
19264
19265 \layout Standard
19266
19267 Description
19268 \end_inset 
19269 </cell>
19270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19271 \begin_inset Text
19272
19273 \layout Standard
19274
19275 Module to link
19276 \end_inset 
19277 </cell>
19278 </row>
19279 <row topline="true">
19280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19281 \begin_inset Text
19282
19283 \layout Standard
19284
19285
19286 \series bold 
19287 ignore
19288 \end_inset 
19289 </cell>
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19291 \begin_inset Text
19292
19293 \layout Standard
19294
19295 ignore all library pragmas
19296 \end_inset 
19297 </cell>
19298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19299 \begin_inset Text
19300
19301 \layout Standard
19302
19303
19304 \emph on 
19305 (none)
19306 \end_inset 
19307 </cell>
19308 </row>
19309 <row topline="true">
19310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19311 \begin_inset Text
19312
19313 \layout Standard
19314
19315
19316 \series bold 
19317 c
19318 \end_inset 
19319 </cell>
19320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19321 \begin_inset Text
19322
19323 \layout Standard
19324
19325 link the C library
19326 \end_inset 
19327 </cell>
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19329 \begin_inset Text
19330
19331 \layout Standard
19332
19333
19334 \emph on 
19335 libc18f
19336 \emph default 
19337 .lib
19338 \end_inset 
19339 </cell>
19340 </row>
19341 <row topline="true">
19342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19343 \begin_inset Text
19344
19345 \layout Standard
19346
19347
19348 \series bold 
19349 math
19350 \end_inset 
19351 </cell>
19352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19353 \begin_inset Text
19354
19355 \layout Standard
19356
19357 link the Math libarary
19358 \end_inset 
19359 </cell>
19360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19361 \begin_inset Text
19362
19363 \layout Standard
19364
19365
19366 \emph on 
19367 libm18f
19368 \emph default 
19369 .lib
19370 \end_inset 
19371 </cell>
19372 </row>
19373 <row topline="true">
19374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19375 \begin_inset Text
19376
19377 \layout Standard
19378
19379
19380 \series bold 
19381 io
19382 \end_inset 
19383 </cell>
19384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19385 \begin_inset Text
19386
19387 \layout Standard
19388
19389 link the I/O library
19390 \end_inset 
19391 </cell>
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19393 \begin_inset Text
19394
19395 \layout Standard
19396
19397
19398 \emph on 
19399 libio18f*
19400 \emph default 
19401 .lib
19402 \end_inset 
19403 </cell>
19404 </row>
19405 <row topline="true" bottomline="true">
19406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19407 \begin_inset Text
19408
19409 \layout Standard
19410
19411
19412 \series bold 
19413 debug
19414 \end_inset 
19415 </cell>
19416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19417 \begin_inset Text
19418
19419 \layout Standard
19420
19421 link the debug library
19422 \end_inset 
19423 </cell>
19424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19425 \begin_inset Text
19426
19427 \layout Standard
19428
19429
19430 \emph on 
19431 libdebug
19432 \emph default 
19433 .lib
19434 \end_inset 
19435 </cell>
19436 </row>
19437 </lyxtabular>
19438
19439 \end_inset 
19440
19441
19442 \newline 
19443 * is the device number, i.e.
19444  452 for PIC18F452 MCU.
19445 \layout Standard
19446
19447 This feature allows for linking with specific libraries withoug having to
19448  explicit name them in the command line.
19449  Note that the 
19450 \noun on 
19451 ignore
19452 \noun default 
19453  keyword will reject all modules specified by the library pragma.
19454 \layout List
19455 \labelwidthstring 00.00.0000
19456
19457 udata pragma udata instructs the compiler to emit code so that linker will
19458  place a variable at a specific memory bank
19459 \layout LyX-Code
19460
19461 Example:
19462 \layout LyX-Code
19463
19464 \layout LyX-Code
19465
19466 /* places variable foo at bank2 */
19467 \layout LyX-Code
19468
19469 #pragma udata bank2 foo
19470 \layout LyX-Code
19471
19472 char foo;
19473 \layout Standard
19474
19475 In order for this pragma to work extra SECTION directives should be added
19476  in the .lkr script.
19477  In the following example a sample .lkr file is shown:
19478 \layout LyX-Code
19479
19480 \layout LyX-Code
19481
19482 // Sample linker script for the PIC18F452 processor
19483 \layout LyX-Code
19484
19485 LIBPATH .
19486 \layout LyX-Code
19487
19488 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
19489 \layout LyX-Code
19490
19491 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
19492 \layout LyX-Code
19493
19494 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
19495 \layout LyX-Code
19496
19497 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
19498 \layout LyX-Code
19499
19500 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
19501 \layout LyX-Code
19502
19503 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
19504 \layout LyX-Code
19505
19506 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
19507 \layout LyX-Code
19508
19509 \layout LyX-Code
19510
19511 DATABANK   NAME=gpr0       START=0x80           END=0xFF
19512 \layout LyX-Code
19513
19514 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
19515 \layout LyX-Code
19516
19517 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
19518 \layout LyX-Code
19519
19520 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
19521 \layout LyX-Code
19522
19523 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
19524 \layout LyX-Code
19525
19526 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
19527 \layout LyX-Code
19528
19529 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
19530 \layout LyX-Code
19531
19532 \layout LyX-Code
19533
19534 SECTION    NAME=CONFIG     ROM=config
19535 \layout LyX-Code
19536
19537 \layout LyX-Code
19538
19539 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
19540 \layout LyX-Code
19541
19542 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
19543 \layout LyX-Code
19544
19545 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
19546 \layout LyX-Code
19547
19548 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
19549 \layout LyX-Code
19550
19551 SECTION    NAME=bank4      RAM=gpr4
19552 \layout LyX-Code
19553
19554 SECTION    NAME=bank5      RAM=gpr5
19555 \layout Standard
19556
19557 The linker will recognise the section name set in the pragma statement and
19558  will position the variable at the memory bank set with the RAM field at
19559  the SECTION line in the linker script file.
19560 \layout Subsection
19561
19562 Header Files
19563 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19564
19565 \end_inset 
19566
19567
19568 \layout Standard
19569
19570 There is one main header file
19571 \begin_inset LatexCommand \index{PIC16!Header files}
19572
19573 \end_inset 
19574
19575  that can be included to the source files using the pic16
19576 \begin_inset LatexCommand \index{PIC16}
19577
19578 \end_inset 
19579
19580  port.
19581  That file is the 
19582 \series bold 
19583 pic18fregs.h
19584 \series default 
19585 .
19586  This header file contains the definitions for the processor special registers,
19587  so it is necessary if the source accesses them.
19588  It can be included by adding the following line in the beginning of the
19589  file:
19590 \layout LyX-Code
19591
19592 #include <pic18fregs.h>
19593 \layout Standard
19594
19595 The specific microcontroller is selected within the pic18fregs.h automatically,
19596  so the same source can be used with a variety of devices.
19597 \layout Subsection
19598
19599 Libraries
19600 \layout Standard
19601
19602 The libraries
19603 \begin_inset LatexCommand \index{PIC16!Libraries}
19604
19605 \end_inset 
19606
19607  that PIC16
19608 \begin_inset LatexCommand \index{PIC16}
19609
19610 \end_inset 
19611
19612  port depends on are the microcontroller device libraries which contain
19613  the symbol definitions for the microcontroller special function registers.
19614  These libraries have the format pic18fxxxx.lib, where 
19615 \emph on 
19616 xxxx
19617 \emph default 
19618  is the microcontroller identification number.
19619  The specific library is selected automatically by the compiler at link
19620  stage according to the selected device.
19621 \layout Standard
19622
19623 Libraries are created with gplib which is part of the gputils package 
19624 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19625
19626 \end_inset 
19627
19628 .
19629 \layout Subsubsection*
19630
19631 Building the libraries
19632 \layout Standard
19633
19634 Before using SDCC/pic16 there are some libraries that need to be compiled.
19635  This process is not done automatically by SDCC since not all users use
19636  SDCC for pic16 projects.
19637  So each user should compile the libraries separately.
19638 \layout Standard
19639
19640 The steps to compile the pic16 libraries under Linux are:
19641 \layout LyX-Code
19642
19643 cd device/lib/pic16
19644 \layout LyX-Code
19645
19646 ./configure
19647 \layout LyX-Code
19648
19649 make
19650 \layout LyX-Code
19651
19652 cd ..
19653 \layout LyX-Code
19654
19655 make model-pic16
19656 \layout LyX-Code
19657
19658 su -c 'make install'     # install the libraries, you need the root password
19659 \layout Standard
19660
19661 If you need to install the headers too, do:
19662 \layout LyX-Code
19663
19664 cd device/include
19665 \layout LyX-Code
19666
19667 su -c 'make install'     # install the headers, you need the root password
19668 \layout Standard
19669
19670 There exist a special target to build the I/O libraries.
19671  This target is not automatically build because it will build the I/O library
19672  for 
19673 \emph on 
19674 every
19675 \emph default 
19676  supported device.
19677  This way building will take quite a lot of time.
19678  Users are advised to edit the 
19679 \series bold 
19680 device/lib/pic16/pics.build
19681 \series default 
19682  file and then execute:
19683 \layout LyX-Code
19684
19685 make lib-io
19686 \layout Subsection
19687
19688 Memory Models
19689 \layout Standard
19690
19691 The following memory models are supported by the PIC16 port:
19692 \layout Itemize
19693
19694 small model
19695 \layout Itemize
19696
19697 large model
19698 \layout Standard
19699
19700 Memory model affects the default size of pointers within the source.
19701  The sizes are shown in the next table:
19702 \layout Standard
19703 \align center 
19704
19705 \begin_inset  Tabular
19706 <lyxtabular version="3" rows="3" columns="3">
19707 <features>
19708 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19709 <column alignment="center" valignment="top" leftline="true" width="0">
19710 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19711 <row topline="true" bottomline="true">
19712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19713 \begin_inset Text
19714
19715 \layout Standard
19716
19717 Pointer sizes according to memory model
19718 \end_inset 
19719 </cell>
19720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19721 \begin_inset Text
19722
19723 \layout Standard
19724
19725 small model
19726 \end_inset 
19727 </cell>
19728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19729 \begin_inset Text
19730
19731 \layout Standard
19732
19733 large model
19734 \end_inset 
19735 </cell>
19736 </row>
19737 <row topline="true" bottomline="true">
19738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19739 \begin_inset Text
19740
19741 \layout Standard
19742
19743 code pointers
19744 \end_inset 
19745 </cell>
19746 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19747 \begin_inset Text
19748
19749 \layout Standard
19750
19751 16-bits
19752 \end_inset 
19753 </cell>
19754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19755 \begin_inset Text
19756
19757 \layout Standard
19758
19759 24-bits
19760 \end_inset 
19761 </cell>
19762 </row>
19763 <row topline="true" bottomline="true">
19764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19765 \begin_inset Text
19766
19767 \layout Standard
19768
19769 data pointers
19770 \end_inset 
19771 </cell>
19772 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
19773 \begin_inset Text
19774
19775 \layout Standard
19776
19777 16-bits
19778 \end_inset 
19779 </cell>
19780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19781 \begin_inset Text
19782
19783 \layout Standard
19784
19785 16-bits
19786 \end_inset 
19787 </cell>
19788 </row>
19789 </lyxtabular>
19790
19791 \end_inset 
19792
19793
19794 \layout Standard
19795
19796 It is advisable that all sources within a project are compiled with the
19797  same memory model.
19798  If one wants to override the default memory model, this can be done by
19799  declaring a pointer as 
19800 \series bold 
19801 far
19802 \series default 
19803  or 
19804 \series bold 
19805 near
19806 \series default 
19807 .
19808  Far selects large memory model's pointers, while near selects small memory
19809  model's pointers.
19810 \layout Standard
19811
19812 The standard device libraries (see 
19813 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
19814
19815 \end_inset 
19816
19817 ) contain no reference to pointers, so they can be used with both memory
19818  models.
19819 \layout Subsection
19820
19821 Stack
19822 \layout Standard
19823
19824 The stack
19825 \begin_inset LatexCommand \index{PIC16!stack}
19826
19827 \end_inset 
19828
19829  implementation for the PIC16 port uses two indirect registers, FSR1 and
19830  FSR2.
19831 \layout List
19832 \labelwidthstring 00.00.0000
19833
19834 FSR1 is assigned as stack pointer
19835 \layout List
19836 \labelwidthstring 00.00.0000
19837
19838 FSR2 is assigned as frame pointer
19839 \layout Standard
19840
19841 The following stack models are supported by the PIC16 port
19842 \layout Itemize
19843
19844
19845 \noun on 
19846 small
19847 \noun default 
19848  model
19849 \layout Itemize
19850
19851
19852 \noun on 
19853 large
19854 \noun default 
19855  model
19856 \layout Standard
19857
19858
19859 \noun on 
19860 Small
19861 \noun default 
19862  model means that only the FSRxL byte is used to access stack and frame,
19863  while 
19864 \emph on 
19865 \noun on 
19866 large
19867 \emph default 
19868 \noun default 
19869  uses both FSRxL and FSRxH registers.
19870  The following table shows the stack/frame pointers sizes according to stack
19871  model and the maximum space they can address:
19872 \layout Standard
19873 \align center 
19874
19875 \begin_inset  Tabular
19876 <lyxtabular version="3" rows="3" columns="3">
19877 <features>
19878 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19879 <column alignment="center" valignment="top" leftline="true" width="0">
19880 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19881 <row topline="true" bottomline="true">
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19883 \begin_inset Text
19884
19885 \layout Standard
19886
19887 Stack & Frame pointer sizes according to stack model
19888 \end_inset 
19889 </cell>
19890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19891 \begin_inset Text
19892
19893 \layout Standard
19894
19895 small
19896 \end_inset 
19897 </cell>
19898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19899 \begin_inset Text
19900
19901 \layout Standard
19902
19903 large
19904 \end_inset 
19905 </cell>
19906 </row>
19907 <row topline="true">
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19909 \begin_inset Text
19910
19911 \layout Standard
19912
19913 Stack pointer FSR1
19914 \end_inset 
19915 </cell>
19916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19917 \begin_inset Text
19918
19919 \layout Standard
19920
19921 8-bits
19922 \end_inset 
19923 </cell>
19924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19925 \begin_inset Text
19926
19927 \layout Standard
19928
19929 16-bits
19930 \end_inset 
19931 </cell>
19932 </row>
19933 <row topline="true" bottomline="true">
19934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19935 \begin_inset Text
19936
19937 \layout Standard
19938
19939 Frame pointer FSR2
19940 \end_inset 
19941 </cell>
19942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19943 \begin_inset Text
19944
19945 \layout Standard
19946
19947 8-bits
19948 \end_inset 
19949 </cell>
19950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19951 \begin_inset Text
19952
19953 \layout Standard
19954
19955 16-bits
19956 \end_inset 
19957 </cell>
19958 </row>
19959 </lyxtabular>
19960
19961 \end_inset 
19962
19963
19964 \layout Standard
19965
19966
19967 \noun on 
19968 Large 
19969 \noun default 
19970 stack model is currently not working properly throughout the code generator.
19971  So its use is not advised.
19972  Also there are some other points that need special care:
19973 \newline 
19974
19975 \layout Enumerate
19976
19977 Do not create stack sections with size more than one physical bank (that
19978  is 256 bytes)
19979 \layout Enumerate
19980
19981 Stack sections should no cross physical bank limits (i.e.
19982  #pragma stack 0x50 0x100)
19983 \layout Standard
19984
19985 These limitations are caused by the fact that only FSRxL is modified when
19986  using SMALL stack model, so no more than 256 bytes of stack can be used.
19987  This problem will disappear after LARGE model is fully implemented.
19988 \layout Subsection
19989
19990 Functions
19991 \layout Standard
19992
19993 In addition to the standard SDCC function keywords, PIC16
19994 \begin_inset LatexCommand \index{PIC16}
19995
19996 \end_inset 
19997
19998  port makes available two more:
19999 \layout List
20000 \labelwidthstring 00.00.0000
20001
20002 wparam
20003 \begin_inset LatexCommand \index{PIC16!wparam}
20004
20005 \end_inset 
20006
20007  Use the WREG to pass one byte of the first function argument.
20008  This improves speed but you may not use this for functions with arguments
20009  that are called via function pointers, otherwise the first byte of the
20010  first parameter will get lost.
20011  Usage:
20012 \layout LyX-Code
20013
20014 void func_wparam(int a) wparam
20015 \layout LyX-Code
20016
20017 {
20018 \layout LyX-Code
20019
20020     /* WREG hold the lower part of a */
20021 \layout LyX-Code
20022
20023     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
20024  */
20025 \layout LyX-Code
20026
20027 ...
20028 \layout LyX-Code
20029
20030 }
20031 \layout List
20032 \labelwidthstring 00.00.0000
20033
20034 shadowregs
20035 \begin_inset LatexCommand \index{PIC16!shadowregs}
20036
20037 \end_inset 
20038
20039  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
20040  hardware shadow registers which hold the values of WREG, STATUS and BSR
20041  registers.
20042  This can be done by adding the keyword 
20043 \emph on 
20044 shadowregs
20045 \emph default 
20046  before the 
20047 \emph on 
20048 interrupt
20049 \emph default 
20050  keyword in the function's header.
20051 \layout LyX-Code
20052
20053 void isr_shadow(void) shadowregs interrupt 1
20054 \layout LyX-Code
20055
20056 {
20057 \layout LyX-Code
20058
20059 ...
20060 \layout LyX-Code
20061
20062 }
20063 \layout Standard
20064
20065
20066 \emph on 
20067 shadowregs
20068 \emph default 
20069  instructs the code generator not to store/restore WREG, STATUS, BSR when
20070  entering/exiting the ISR.
20071 \layout Subsection
20072
20073 Function return values
20074 \layout Standard
20075
20076 Return values from functions are placed to the appropriate registers following
20077  a modified Microchip policy optimized for SDCC.
20078  The following table shows these registers:
20079 \layout Standard
20080 \align center 
20081
20082 \begin_inset  Tabular
20083 <lyxtabular version="3" rows="6" columns="2">
20084 <features>
20085 <column alignment="center" valignment="top" leftline="true" width="0">
20086 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20087 <row topline="true" bottomline="true">
20088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20089 \begin_inset Text
20090
20091 \layout Standard
20092
20093 size
20094 \end_inset 
20095 </cell>
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20097 \begin_inset Text
20098
20099 \layout Standard
20100
20101 destination register
20102 \end_inset 
20103 </cell>
20104 </row>
20105 <row topline="true">
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20107 \begin_inset Text
20108
20109 \layout Standard
20110
20111 8 bits
20112 \end_inset 
20113 </cell>
20114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20115 \begin_inset Text
20116
20117 \layout Standard
20118
20119 WREG
20120 \end_inset 
20121 </cell>
20122 </row>
20123 <row topline="true">
20124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20125 \begin_inset Text
20126
20127 \layout Standard
20128
20129 16 bits
20130 \end_inset 
20131 </cell>
20132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20133 \begin_inset Text
20134
20135 \layout Standard
20136
20137 PRODL:WREG
20138 \end_inset 
20139 </cell>
20140 </row>
20141 <row topline="true">
20142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20143 \begin_inset Text
20144
20145 \layout Standard
20146
20147 24 bits
20148 \end_inset 
20149 </cell>
20150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20151 \begin_inset Text
20152
20153 \layout Standard
20154
20155 PRODH:PRODL:WREG
20156 \end_inset 
20157 </cell>
20158 </row>
20159 <row topline="true">
20160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20161 \begin_inset Text
20162
20163 \layout Standard
20164
20165 32 bits
20166 \end_inset 
20167 </cell>
20168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20169 \begin_inset Text
20170
20171 \layout Standard
20172
20173 FSR0L:PRODH:PRODL:WREG
20174 \end_inset 
20175 </cell>
20176 </row>
20177 <row topline="true" bottomline="true">
20178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20179 \begin_inset Text
20180
20181 \layout Standard
20182
20183 >32 bits
20184 \end_inset 
20185 </cell>
20186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20187 \begin_inset Text
20188
20189 \layout Standard
20190
20191 on stack, FSR0 points to the beginning
20192 \end_inset 
20193 </cell>
20194 </row>
20195 </lyxtabular>
20196
20197 \end_inset 
20198
20199
20200 \layout Subsection
20201
20202 Interrupts
20203 \layout Standard
20204
20205 An interrupt
20206 \begin_inset LatexCommand \index{PIC16!interrupt}
20207
20208 \end_inset 
20209
20210  service routine (ISR) is declared using the 
20211 \emph on 
20212 interrupt
20213 \emph default 
20214  keyword.
20215 \layout LyX-Code
20216
20217 void isr(void) interrupt 
20218 \emph on 
20219 n
20220 \layout LyX-Code
20221
20222 {
20223 \layout LyX-Code
20224
20225 ...
20226 \layout LyX-Code
20227
20228 }
20229 \layout Standard
20230
20231
20232 \emph on 
20233 n
20234 \emph default 
20235  is the interrupt number, which for PIC18F devices can be:
20236 \layout Standard
20237 \align center 
20238
20239 \begin_inset  Tabular
20240 <lyxtabular version="3" rows="4" columns="3">
20241 <features>
20242 <column alignment="center" valignment="top" leftline="true" width="0">
20243 <column alignment="center" valignment="top" leftline="true" width="0">
20244 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20245 <row topline="true" bottomline="true">
20246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20247 \begin_inset Text
20248
20249 \layout Standard
20250
20251
20252 \emph on 
20253 n
20254 \end_inset 
20255 </cell>
20256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20257 \begin_inset Text
20258
20259 \layout Standard
20260
20261 Interrupt Vector
20262 \end_inset 
20263 </cell>
20264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20265 \begin_inset Text
20266
20267 \layout Standard
20268
20269 Interrupt Vector Address
20270 \end_inset 
20271 </cell>
20272 </row>
20273 <row topline="true">
20274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20275 \begin_inset Text
20276
20277 \layout Standard
20278
20279 0
20280 \end_inset 
20281 </cell>
20282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20283 \begin_inset Text
20284
20285 \layout Standard
20286
20287 RESET vector
20288 \end_inset 
20289 </cell>
20290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20291 \begin_inset Text
20292
20293 \layout Standard
20294
20295 0x000000
20296 \end_inset 
20297 </cell>
20298 </row>
20299 <row topline="true">
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20301 \begin_inset Text
20302
20303 \layout Standard
20304
20305
20306 \family roman 
20307 \series medium 
20308 \shape up 
20309 \size normal 
20310 \emph off 
20311 \bar no 
20312 \noun off 
20313 \color none
20314 1
20315 \end_inset 
20316 </cell>
20317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20318 \begin_inset Text
20319
20320 \layout Standard
20321
20322
20323 \family roman 
20324 \series medium 
20325 \shape up 
20326 \size normal 
20327 \emph off 
20328 \bar no 
20329 \noun off 
20330 \color none
20331 HIGH priority interrupts
20332 \end_inset 
20333 </cell>
20334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20335 \begin_inset Text
20336
20337 \layout Standard
20338
20339 0x000008
20340 \end_inset 
20341 </cell>
20342 </row>
20343 <row topline="true" bottomline="true">
20344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20345 \begin_inset Text
20346
20347 \layout Standard
20348
20349 2
20350 \end_inset 
20351 </cell>
20352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20353 \begin_inset Text
20354
20355 \layout Standard
20356
20357 LOW priority interrupts
20358 \end_inset 
20359 </cell>
20360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20361 \begin_inset Text
20362
20363 \layout Standard
20364
20365 0x000018
20366 \end_inset 
20367 </cell>
20368 </row>
20369 </lyxtabular>
20370
20371 \end_inset 
20372
20373
20374 \layout Standard
20375
20376 When generating assembly code for ISR the code generator places a 
20377 \noun on 
20378 goto 
20379 \noun default 
20380 instruction at the 
20381 \emph on 
20382 Interrupt Vector Address
20383 \emph default 
20384  which points at the genetated ISR.
20385  This single GOTO instruction is part of an automatically generated 
20386 \emph on 
20387 interrupt entry point
20388 \emph default 
20389  function.
20390  The actuall ISR code is placed as normally would in the code space.
20391  Upon interrupt request, the GOTO instruction is executed which jumps to
20392  the ISR code.
20393  When declaring interrupt functions as _naked this GOTO instruction is 
20394 \series bold 
20395 not
20396 \series default 
20397  generated.
20398  The whole interrupt functions is therefore placed at the Interrupt Vector
20399  Address of the specific interrupt.
20400  This is not a problem for the LOW priority interrupts, but it is a problem
20401  for the RESET and the HIGH priority interrupts because code may be written
20402  at the next interrupt´s vector address and cause undeterminate program
20403  behaviour if that interrupt is raised.
20404 \begin_inset Foot
20405 collapsed false
20406
20407 \layout Standard
20408
20409 This is not a problem when
20410 \layout Enumerate
20411
20412 this is a HIGH interrupt ISR and LOW interrupts are 
20413 \emph on 
20414 disabled
20415 \emph default 
20416  or not used.
20417 \layout Enumerate
20418
20419 when the ISR is small enough not to reach the next interrupt´s vector address.
20420 \end_inset 
20421
20422
20423 \layout Standard
20424
20425
20426 \emph on 
20427 n
20428 \emph default 
20429  is possible to be omitted.
20430  This way a function is generated similar to an ISR, but it is not assigned
20431  to any interrupt.
20432 \layout Standard
20433
20434 When entering an interrupt, currently the PIC16
20435 \begin_inset LatexCommand \index{PIC16}
20436
20437 \end_inset 
20438
20439  port automatically saves the following registers:
20440 \layout Itemize
20441
20442 WREG
20443 \layout Itemize
20444
20445 STATUS
20446 \layout Itemize
20447
20448 BSR
20449 \layout Itemize
20450
20451 PROD (PRODL and PRODH)
20452 \layout Itemize
20453
20454 FSR0 (FSR0L and FSR0H)
20455 \layout Standard
20456
20457 These registers are restored upon return from the interrupt routine.
20458 \begin_inset Foot
20459 collapsed false
20460
20461 \layout Standard
20462
20463 NOTE that when the _naked attribute is specified for an interrupt routine,
20464  then NO registers are stored or restored.
20465 \end_inset 
20466
20467
20468 \layout Subsection
20469
20470 Generic Pointers
20471 \layout Standard
20472
20473 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20474  There are 3 types of generic pointers currently implemented data, code
20475  and eeprom pointers.
20476  They are differentiated by the value of the 7th and 6th bits of the upper
20477  byte:
20478 \layout Standard
20479 \align center 
20480
20481 \begin_inset  Tabular
20482 <lyxtabular version="3" rows="5" columns="5">
20483 <features>
20484 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20485 <column alignment="center" valignment="top" width="0">
20486 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20487 <column alignment="center" valignment="top" width="0">
20488 <column alignment="left" valignment="top" rightline="true" width="0">
20489 <row topline="true" bottomline="true">
20490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20491 \begin_inset Text
20492
20493 \layout Standard
20494
20495 pointer type
20496 \end_inset 
20497 </cell>
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20499 \begin_inset Text
20500
20501 \layout Standard
20502
20503 7th bit
20504 \end_inset 
20505 </cell>
20506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20507 \begin_inset Text
20508
20509 \layout Standard
20510
20511 6th bit
20512 \end_inset 
20513 </cell>
20514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20515 \begin_inset Text
20516
20517 \layout Standard
20518
20519 rest of the pointer
20520 \end_inset 
20521 </cell>
20522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20523 \begin_inset Text
20524
20525 \layout Standard
20526
20527 description
20528 \end_inset 
20529 </cell>
20530 </row>
20531 <row topline="true" bottomline="true">
20532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20533 \begin_inset Text
20534
20535 \layout Standard
20536
20537 data 
20538 \end_inset 
20539 </cell>
20540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20541 \begin_inset Text
20542
20543 \layout Standard
20544
20545 1
20546 \end_inset 
20547 </cell>
20548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20549 \begin_inset Text
20550
20551 \layout Standard
20552
20553 0
20554 \end_inset 
20555 </cell>
20556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20557 \begin_inset Text
20558
20559 \layout Standard
20560
20561
20562 \family typewriter 
20563 \shape slanted 
20564 \emph on 
20565 uuuuuu uuuuxxxx xxxxxxxx
20566 \end_inset 
20567 </cell>
20568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20569 \begin_inset Text
20570
20571 \layout Standard
20572
20573 a 12-bit data pointer in data RAM memory
20574 \end_inset 
20575 </cell>
20576 </row>
20577 <row bottomline="true">
20578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20579 \begin_inset Text
20580
20581 \layout Standard
20582
20583 code
20584 \end_inset 
20585 </cell>
20586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20587 \begin_inset Text
20588
20589 \layout Standard
20590
20591 0
20592 \end_inset 
20593 </cell>
20594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20595 \begin_inset Text
20596
20597 \layout Standard
20598
20599 0
20600 \end_inset 
20601 </cell>
20602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20603 \begin_inset Text
20604
20605 \layout Standard
20606
20607
20608 \family typewriter 
20609 \shape slanted 
20610 \emph on 
20611 uxxxxx xxxxxxxx xxxxxxxx
20612 \end_inset 
20613 </cell>
20614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20615 \begin_inset Text
20616
20617 \layout Standard
20618
20619 a 21-bit code pointer in FLASH memory
20620 \end_inset 
20621 </cell>
20622 </row>
20623 <row bottomline="true">
20624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20625 \begin_inset Text
20626
20627 \layout Standard
20628
20629 eeprom
20630 \end_inset 
20631 </cell>
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20633 \begin_inset Text
20634
20635 \layout Standard
20636
20637 0
20638 \end_inset 
20639 </cell>
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20641 \begin_inset Text
20642
20643 \layout Standard
20644
20645 1
20646 \end_inset 
20647 </cell>
20648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20649 \begin_inset Text
20650
20651 \layout Standard
20652
20653
20654 \family typewriter 
20655 \shape slanted 
20656 \emph on 
20657 uuuuuu uuuuuuxx xxxxxxxx
20658 \end_inset 
20659 </cell>
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20661 \begin_inset Text
20662
20663 \layout Standard
20664
20665 a 10-bit eeprom pointer in EEPROM memory
20666 \end_inset 
20667 </cell>
20668 </row>
20669 <row bottomline="true">
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20671 \begin_inset Text
20672
20673 \layout Standard
20674
20675 (unimplemented)
20676 \end_inset 
20677 </cell>
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20679 \begin_inset Text
20680
20681 \layout Standard
20682
20683 1
20684 \end_inset 
20685 </cell>
20686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20687 \begin_inset Text
20688
20689 \layout Standard
20690
20691 1
20692 \end_inset 
20693 </cell>
20694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20695 \begin_inset Text
20696
20697 \layout Standard
20698
20699
20700 \family typewriter 
20701 \shape slanted 
20702 \emph on 
20703 xxxxxx xxxxxxxx xxxxxxxx
20704 \end_inset 
20705 </cell>
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20707 \begin_inset Text
20708
20709 \layout Standard
20710
20711 unimplemented pointer type
20712 \end_inset 
20713 </cell>
20714 </row>
20715 </lyxtabular>
20716
20717 \end_inset 
20718
20719
20720 \layout Standard
20721
20722 Generic pointer are read and written with a set of library functions which
20723  read/write 1, 2, 3, 4 bytes.
20724 \layout Subsection
20725
20726 PIC16 C Libraries
20727 \layout Subsubsection
20728
20729 Standard I/O Streams
20730 \layout Standard
20731
20732 In the 
20733 \emph on 
20734 stdio.h
20735 \emph default 
20736  the type FILE is defined as:
20737 \layout LyX-Code
20738
20739 typedef char * FILE;
20740 \layout Standard
20741
20742 This type is the stream type implemented I/O in the PIC18F devices.
20743  Also the standard input and output streams are declared in stdio.h:
20744 \layout LyX-Code
20745
20746 extern FILE * stdin;
20747 \layout LyX-Code
20748
20749 extern FILE * stdout;
20750 \layout Standard
20751
20752 The FILE type is actually a generic pointer which defines one more type
20753  of generic pointers, the 
20754 \emph on 
20755 stream 
20756 \emph default 
20757 pointer.
20758  This new type has the format:
20759 \layout Standard
20760 \align center 
20761
20762 \begin_inset  Tabular
20763 <lyxtabular version="3" rows="2" columns="7">
20764 <features>
20765 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20766 <column alignment="center" valignment="top" width="0">
20767 <column alignment="center" valignment="top" leftline="true" width="0">
20768 <column alignment="center" valignment="top" leftline="true" width="0">
20769 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20770 <column alignment="center" valignment="top" width="0">
20771 <column alignment="left" valignment="top" rightline="true" width="0">
20772 <row topline="true" bottomline="true">
20773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20774 \begin_inset Text
20775
20776 \layout Standard
20777
20778 pointer type
20779 \end_inset 
20780 </cell>
20781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20782 \begin_inset Text
20783
20784 \layout Standard
20785
20786 <7:6>
20787 \end_inset 
20788 </cell>
20789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20790 \begin_inset Text
20791
20792 \layout Standard
20793
20794 <5>
20795 \end_inset 
20796 </cell>
20797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20798 \begin_inset Text
20799
20800 \layout Standard
20801
20802 <4>
20803 \end_inset 
20804 </cell>
20805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20806 \begin_inset Text
20807
20808 \layout Standard
20809
20810 <3:0>
20811 \end_inset 
20812 </cell>
20813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20814 \begin_inset Text
20815
20816 \layout Standard
20817
20818 rest of the pointer
20819 \end_inset 
20820 </cell>
20821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20822 \begin_inset Text
20823
20824 \layout Standard
20825
20826 descrption
20827 \end_inset 
20828 </cell>
20829 </row>
20830 <row topline="true" bottomline="true">
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20832 \begin_inset Text
20833
20834 \layout Standard
20835
20836 stream
20837 \end_inset 
20838 </cell>
20839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20840 \begin_inset Text
20841
20842 \layout Standard
20843
20844 00
20845 \end_inset 
20846 </cell>
20847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20848 \begin_inset Text
20849
20850 \layout Standard
20851
20852 1
20853 \end_inset 
20854 </cell>
20855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20856 \begin_inset Text
20857
20858 \layout Standard
20859
20860 0
20861 \end_inset 
20862 </cell>
20863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20864 \begin_inset Text
20865
20866 \layout Standard
20867
20868 nnnn
20869 \end_inset 
20870 </cell>
20871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20872 \begin_inset Text
20873
20874 \layout Standard
20875
20876
20877 \family typewriter 
20878 \shape slanted 
20879 \emph on 
20880 uuuuuuuu uuuuuuuu
20881 \end_inset 
20882 </cell>
20883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20884 \begin_inset Text
20885
20886 \layout Standard
20887
20888 upper byte high nubble is 0x2n, the rest are zeroes
20889 \end_inset 
20890 </cell>
20891 </row>
20892 </lyxtabular>
20893
20894 \end_inset 
20895
20896
20897 \layout Standard
20898
20899 Currently implemented there are 3 types of streams defined:
20900 \layout Standard
20901 \align center 
20902
20903 \begin_inset  Tabular
20904 <lyxtabular version="3" rows="4" columns="4">
20905 <features>
20906 <column alignment="center" valignment="top" leftline="true" width="0">
20907 <column alignment="center" valignment="top" leftline="true" width="0">
20908 <column alignment="center" valignment="top" leftline="true" width="0">
20909 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20910 <row topline="true" bottomline="true">
20911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20912 \begin_inset Text
20913
20914 \layout Standard
20915
20916 stream type
20917 \end_inset 
20918 </cell>
20919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20920 \begin_inset Text
20921
20922 \layout Standard
20923
20924 value
20925 \end_inset 
20926 </cell>
20927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20928 \begin_inset Text
20929
20930 \layout Standard
20931
20932 module
20933 \end_inset 
20934 </cell>
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20936 \begin_inset Text
20937
20938 \layout Standard
20939
20940 description
20941 \end_inset 
20942 </cell>
20943 </row>
20944 <row topline="true">
20945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20946 \begin_inset Text
20947
20948 \layout Standard
20949
20950 STREAM_USART
20951 \end_inset 
20952 </cell>
20953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20954 \begin_inset Text
20955
20956 \layout Standard
20957
20958
20959 \family typewriter 
20960 0x200000UL
20961 \end_inset 
20962 </cell>
20963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20964 \begin_inset Text
20965
20966 \layout Standard
20967
20968 USART
20969 \end_inset 
20970 </cell>
20971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20972 \begin_inset Text
20973
20974 \layout Standard
20975
20976 Writes/Reads characters via the USART peripheral
20977 \end_inset 
20978 </cell>
20979 </row>
20980 <row topline="true">
20981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20982 \begin_inset Text
20983
20984 \layout Standard
20985
20986 STREAM_MSSP
20987 \end_inset 
20988 </cell>
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20990 \begin_inset Text
20991
20992 \layout Standard
20993
20994
20995 \family typewriter 
20996 0x210000UL
20997 \end_inset 
20998 </cell>
20999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21000 \begin_inset Text
21001
21002 \layout Standard
21003
21004 MSSP
21005 \end_inset 
21006 </cell>
21007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21008 \begin_inset Text
21009
21010 \layout Standard
21011
21012 Writes/Reads characters via the MSSP peripheral
21013 \end_inset 
21014 </cell>
21015 </row>
21016 <row topline="true" bottomline="true">
21017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21018 \begin_inset Text
21019
21020 \layout Standard
21021
21022 STREAM_USER
21023 \end_inset 
21024 </cell>
21025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21026 \begin_inset Text
21027
21028 \layout Standard
21029
21030
21031 \family typewriter 
21032 0x2f0000UL
21033 \end_inset 
21034 </cell>
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21036 \begin_inset Text
21037
21038 \layout Standard
21039
21040 (none)
21041 \end_inset 
21042 </cell>
21043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21044 \begin_inset Text
21045
21046 \layout Standard
21047
21048 Writes/Reads characters via used defined functions
21049 \end_inset 
21050 </cell>
21051 </row>
21052 </lyxtabular>
21053
21054 \end_inset 
21055
21056
21057 \layout Standard
21058
21059 The stream identifiers are declared as macros in the stdio.h header.
21060 \layout Standard
21061
21062 In the libc library there exist the functions that are used to write to
21063  each of the above streams.
21064  These are
21065 \layout List
21066 \labelwidthstring 00.00.0000
21067
21068 _
21069 \begin_inset ERT
21070 status Collapsed
21071
21072 \layout Standard
21073
21074 \backslash 
21075 /
21076 \end_inset 
21077
21078 _stream_usart_putchar writes a character at the USART stream
21079 \layout List
21080 \labelwidthstring 00.00.0000
21081
21082 _
21083 \begin_inset ERT
21084 status Collapsed
21085
21086 \layout Standard
21087
21088 \backslash 
21089 /
21090 \end_inset 
21091
21092 _stream_mssp_putchar writes a character at the MSSP stream
21093 \layout List
21094 \labelwidthstring 00.00.0000
21095
21096 putchar dummy function.
21097  This writes a character to a user specified manner.
21098 \layout Standard
21099
21100 In order to increase performance 
21101 \emph on 
21102 putchar 
21103 \emph default 
21104 is declared in stdio.h as having its parameter in WREG (it has the wparam
21105  keyword).
21106  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
21107  in a user-friendly way.
21108  
21109 \emph on 
21110 arg
21111 \emph default 
21112  is the name of the variable that holds the character to print.
21113  An example follows:
21114 \layout LyX-Code
21115
21116 #include <pic18fregs.h>
21117 \newline 
21118 #include <stdio.h>
21119 \newline 
21120
21121 \newline 
21122 PUTCHAR( c )
21123 \layout LyX-Code
21124
21125 {
21126 \layout LyX-Code
21127
21128     PORTA = c;    /* dump character c to PORTA */
21129 \layout LyX-Code
21130
21131
21132 \newline 
21133
21134 \newline 
21135 void main(void)
21136 \layout LyX-Code
21137
21138 {
21139 \layout LyX-Code
21140
21141     stdout = STREAM_USER;    /* this is not necessary, since stdout points
21142 \layout LyX-Code
21143
21144                               * by default to STREAM_USER */
21145 \layout LyX-Code
21146
21147     printf (¨This is a printf test
21148 \backslash 
21149 n¨);
21150 \layout LyX-Code
21151
21152 }
21153 \layout LyX-Code
21154
21155 \layout Subsubsection
21156
21157 Printing functions
21158 \layout Standard
21159
21160 PIC16 contains an implementation of the printf-family of functions.
21161  There exist the following functions:
21162 \layout LyX-Code
21163
21164 extern unsigned int sprintf(char *buf, char *fmt, ...);
21165 \layout LyX-Code
21166
21167 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
21168 \layout LyX-Code
21169
21170 \layout LyX-Code
21171
21172 extern unsigned int printf(char *fmt, ...);
21173 \layout LyX-Code
21174
21175 extern unsigned int vprintf(char *fmt, va_lista ap);
21176 \layout LyX-Code
21177
21178 \layout LyX-Code
21179
21180 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
21181 \layout LyX-Code
21182
21183 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
21184 \layout Standard
21185
21186 For sprintf and vsprintf 
21187 \emph on 
21188 buf 
21189 \emph default 
21190 should normally be a data pointer where the resulting string will be placed.
21191  No range checking is done so the user should allocate the necessery buffer.
21192  For fprintf and vfprintf 
21193 \emph on 
21194 fp
21195 \emph default 
21196  should be a stream pointer (i.e.
21197  stdout, STREAM_MSSP, etc...).
21198 \layout Subsubsection
21199
21200 Signals
21201 \layout Standard
21202
21203 The PIC18F family of microcontrollers supports a number of interrupt sources.
21204  A list of these interrupts is shown in the following table:
21205 \layout Standard
21206 \align center 
21207
21208 \begin_inset  Tabular
21209 <lyxtabular version="3" rows="11" columns="4">
21210 <features>
21211 <column alignment="left" valignment="top" leftline="true" width="0">
21212 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21213 <column alignment="left" valignment="top" leftline="true" width="0">
21214 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21215 <row topline="true" bottomline="true">
21216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21217 \begin_inset Text
21218
21219 \layout Standard
21220
21221 signal name
21222 \end_inset 
21223 </cell>
21224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21225 \begin_inset Text
21226
21227 \layout Standard
21228
21229 description
21230 \end_inset 
21231 </cell>
21232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21233 \begin_inset Text
21234
21235 \layout Standard
21236
21237 signal name
21238 \end_inset 
21239 </cell>
21240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21241 \begin_inset Text
21242
21243 \layout Standard
21244
21245 descritpion
21246 \end_inset 
21247 </cell>
21248 </row>
21249 <row topline="true">
21250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21251 \begin_inset Text
21252
21253 \layout Standard
21254
21255 SIG_RB
21256 \end_inset 
21257 </cell>
21258 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21259 \begin_inset Text
21260
21261 \layout Standard
21262
21263 PORTB change interrupt
21264 \end_inset 
21265 </cell>
21266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21267 \begin_inset Text
21268
21269 \layout Standard
21270
21271 SIG_EE
21272 \end_inset 
21273 </cell>
21274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21275 \begin_inset Text
21276
21277 \layout Standard
21278
21279 EEPROM/FLASH write complete interrupt
21280 \end_inset 
21281 </cell>
21282 </row>
21283 <row topline="true">
21284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21285 \begin_inset Text
21286
21287 \layout Standard
21288
21289 SIG_INT0
21290 \end_inset 
21291 </cell>
21292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21293 \begin_inset Text
21294
21295 \layout Standard
21296
21297 INT0 external interrupt
21298 \end_inset 
21299 </cell>
21300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21301 \begin_inset Text
21302
21303 \layout Standard
21304
21305 SIG_BCOL
21306 \end_inset 
21307 </cell>
21308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21309 \begin_inset Text
21310
21311 \layout Standard
21312
21313 Bus collision interrupt
21314 \end_inset 
21315 </cell>
21316 </row>
21317 <row topline="true">
21318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21319 \begin_inset Text
21320
21321 \layout Standard
21322
21323 SIG_INT1
21324 \end_inset 
21325 </cell>
21326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21327 \begin_inset Text
21328
21329 \layout Standard
21330
21331 INT1 external interrupt
21332 \end_inset 
21333 </cell>
21334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21335 \begin_inset Text
21336
21337 \layout Standard
21338
21339 SIG_LVD
21340 \end_inset 
21341 </cell>
21342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21343 \begin_inset Text
21344
21345 \layout Standard
21346
21347 Low voltage detect interrupt
21348 \end_inset 
21349 </cell>
21350 </row>
21351 <row topline="true">
21352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21353 \begin_inset Text
21354
21355 \layout Standard
21356
21357 SIG_INT2
21358 \end_inset 
21359 </cell>
21360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21361 \begin_inset Text
21362
21363 \layout Standard
21364
21365 INT2 external interrupt
21366 \end_inset 
21367 </cell>
21368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21369 \begin_inset Text
21370
21371 \layout Standard
21372
21373 SIG_PSP
21374 \end_inset 
21375 </cell>
21376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21377 \begin_inset Text
21378
21379 \layout Standard
21380
21381 Parallel slave port interrupt
21382 \end_inset 
21383 </cell>
21384 </row>
21385 <row topline="true">
21386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21387 \begin_inset Text
21388
21389 \layout Standard
21390
21391 SIG_CCP1
21392 \end_inset 
21393 </cell>
21394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21395 \begin_inset Text
21396
21397 \layout Standard
21398
21399 CCP1 module interrupt
21400 \end_inset 
21401 </cell>
21402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21403 \begin_inset Text
21404
21405 \layout Standard
21406
21407 SIG_AD
21408 \end_inset 
21409 </cell>
21410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21411 \begin_inset Text
21412
21413 \layout Standard
21414
21415 AD convertion complete interrupt
21416 \end_inset 
21417 </cell>
21418 </row>
21419 <row topline="true">
21420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21421 \begin_inset Text
21422
21423 \layout Standard
21424
21425 SIG_CCP2
21426 \end_inset 
21427 </cell>
21428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21429 \begin_inset Text
21430
21431 \layout Standard
21432
21433 CCP2 module interrupt
21434 \end_inset 
21435 </cell>
21436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21437 \begin_inset Text
21438
21439 \layout Standard
21440
21441 SIG_RC
21442 \end_inset 
21443 </cell>
21444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21445 \begin_inset Text
21446
21447 \layout Standard
21448
21449 USART receive interrupt
21450 \end_inset 
21451 </cell>
21452 </row>
21453 <row topline="true">
21454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21455 \begin_inset Text
21456
21457 \layout Standard
21458
21459 SIG_TMR0
21460 \end_inset 
21461 </cell>
21462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21463 \begin_inset Text
21464
21465 \layout Standard
21466
21467 TMR0 overflow interrupt
21468 \end_inset 
21469 </cell>
21470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21471 \begin_inset Text
21472
21473 \layout Standard
21474
21475 SIG_TX
21476 \end_inset 
21477 </cell>
21478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21479 \begin_inset Text
21480
21481 \layout Standard
21482
21483 USART transmit interrupt
21484 \end_inset 
21485 </cell>
21486 </row>
21487 <row topline="true">
21488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21489 \begin_inset Text
21490
21491 \layout Standard
21492
21493 SIG_TMR1
21494 \end_inset 
21495 </cell>
21496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21497 \begin_inset Text
21498
21499 \layout Standard
21500
21501 TMR1 overflow interrupt
21502 \end_inset 
21503 </cell>
21504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21505 \begin_inset Text
21506
21507 \layout Standard
21508
21509 SIG_MSSP
21510 \end_inset 
21511 </cell>
21512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21513 \begin_inset Text
21514
21515 \layout Standard
21516
21517 SSP receive/transmit interrupt
21518 \end_inset 
21519 </cell>
21520 </row>
21521 <row topline="true">
21522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21523 \begin_inset Text
21524
21525 \layout Standard
21526
21527 SIG_TMR2
21528 \end_inset 
21529 </cell>
21530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21531 \begin_inset Text
21532
21533 \layout Standard
21534
21535 TMR2 matches PR2 interrupt
21536 \end_inset 
21537 </cell>
21538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21539 \begin_inset Text
21540
21541 \layout Standard
21542
21543 \end_inset 
21544 </cell>
21545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21546 \begin_inset Text
21547
21548 \layout Standard
21549
21550 \end_inset 
21551 </cell>
21552 </row>
21553 <row topline="true" bottomline="true">
21554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21555 \begin_inset Text
21556
21557 \layout Standard
21558
21559 SIG_TMR3
21560 \end_inset 
21561 </cell>
21562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21563 \begin_inset Text
21564
21565 \layout Standard
21566
21567 TMR3 overflow interrupt
21568 \end_inset 
21569 </cell>
21570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21571 \begin_inset Text
21572
21573 \layout Standard
21574
21575 \end_inset 
21576 </cell>
21577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21578 \begin_inset Text
21579
21580 \layout Standard
21581
21582 \end_inset 
21583 </cell>
21584 </row>
21585 </lyxtabular>
21586
21587 \end_inset 
21588
21589
21590 \layout Standard
21591
21592 The prototypes for these names are defined in the header file 
21593 \emph on 
21594 signal.h
21595 \emph default 
21596  .
21597 \layout Standard
21598
21599 In order to simplify signal handling, a number of macros is provided:
21600 \layout List
21601 \labelwidthstring 00.00.0000
21602
21603 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21604  high priority interrupts.
21605  
21606 \emph on 
21607 name
21608 \emph default 
21609  is the function name to use.
21610 \layout List
21611 \labelwidthstring 00.00.0000
21612
21613 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21614  low priority interrupt.
21615  
21616 \emph on 
21617 name
21618 \emph default 
21619  is the function name to use.
21620 \layout List
21621 \labelwidthstring 00.00.0000
21622
21623 DEF_HANDLER(sig,handler) define a handler for signal 
21624 \emph on 
21625 sig.
21626 \layout List
21627 \labelwidthstring 00.00.0000
21628
21629 END_DEF end the declaration of the dispatch table.
21630 \layout Standard
21631
21632 Additionally there are two more macros to simplify the declaration of the
21633  signal handler:
21634 \layout List
21635 \labelwidthstring 00.00.0000
21636
21637
21638 \series medium 
21639 SIGHANDLER(handler) 
21640 \series default 
21641 this declares the function prototype for the 
21642 \emph on 
21643 handler
21644 \emph default 
21645  function.
21646 \layout List
21647 \labelwidthstring 00.00.0000
21648
21649 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21650 \layout Standard
21651
21652 An example of using the macros above is shown below:
21653 \layout LyX-Code
21654
21655 #include <pic18fregs.h>
21656 \layout LyX-Code
21657
21658 #include <signal.h>
21659 \newline 
21660
21661 \newline 
21662 DEF_INTHIGH(high_int)
21663 \layout LyX-Code
21664
21665 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21666 \layout LyX-Code
21667
21668 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21669 \layout LyX-Code
21670
21671 END_DEF
21672 \newline 
21673
21674 \newline 
21675 SIGHANDLER(_tmr0_handler)
21676 \layout LyX-Code
21677
21678 {
21679 \layout LyX-Code
21680
21681   /* action to be taken when timer 0 overflows */
21682 \layout LyX-Code
21683
21684 }
21685 \newline 
21686
21687 \newline 
21688 SIGHANDLERNAKED(_bcol_handler)
21689 \layout LyX-Code
21690
21691 {
21692 \layout LyX-Code
21693
21694   _asm
21695 \layout LyX-Code
21696
21697     /* action to be taken when bus collision occurs */
21698 \layout LyX-Code
21699
21700     retfie
21701 \layout LyX-Code
21702
21703  _endasm;
21704 \layout LyX-Code
21705
21706 }
21707 \layout Standard
21708
21709
21710 \series bold 
21711 NOTES:
21712 \series default 
21713  Special care should be taken when using the above scheme:
21714 \layout Itemize
21715
21716 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21717 \layout Itemize
21718
21719 when declaring SIGHANDLERNAKED handler never forget to use 
21720 \emph on 
21721 retfie
21722 \emph default 
21723  for proper returning.
21724 \layout Subsection
21725
21726 PIC16 Port -- Tips
21727 \layout Standard
21728
21729 Here you can find some general tips for compiling programs with SDCC/pic16.
21730 \layout Subsubsection
21731
21732 Stack size
21733 \layout Standard
21734
21735 The default stack
21736 \begin_inset LatexCommand \index{PIC16!stack}
21737
21738 \end_inset 
21739
21740  size (that is 64 bytes) probably is enough for many programs.
21741  One must take care that when there are many levels of function nesting,
21742  or there is excessive usage of stack, its size should be extended.
21743  An example of such a case is the printf/sprintf family of functions.
21744  If you encounter problems like not being able to print integers, then you
21745  need to set the stack size around the maximum (256 for small stack model).
21746  The following diagram shows what happens when calling printf to print an
21747  integer:
21748 \layout LyX-Code
21749
21750 printf () --> ltoa () --> ultoa () --> divschar ()
21751 \layout Standard
21752
21753 It is should be understood that stack is easily consumed when calling complicate
21754 d functions.
21755  Using command line arguments like -
21756 \begin_inset ERT
21757 status Collapsed
21758
21759 \layout Standard
21760
21761 \backslash 
21762 /
21763 \end_inset 
21764
21765 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
21766  stack frames.
21767  Other ways to reduce stack usage may exist.
21768 \layout Subsection
21769
21770 Known bugs
21771 \layout Standard
21772
21773 The PIC16 Port currently does not pass SDCC's regression test
21774 \begin_inset LatexCommand \index{Regression test (PIC16)}
21775
21776 \end_inset 
21777
21778  suite (see section 
21779 \begin_inset LatexCommand \ref{sec:Quality-control}
21780
21781 \end_inset 
21782
21783 ) and thus the nightly regression tests for the PIC16 target are currently
21784  disabled for all hosts except for 
21785 \emph on 
21786 Linux on Opteron.
21787
21788 \emph default 
21789  This means you can see the result of the PIC16 regression tests f.e.
21790  by checking the log files in 
21791 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
21792
21793 \end_inset 
21794
21795  (pick the most up to date file there, scroll down, lend a hand).
21796 \layout Chapter
21797
21798 Debugging
21799 \layout Standard
21800
21801 There are several approaches to debugging your code.
21802  This chapter is meant to show your options and to give detail on some of
21803  them:
21804 \newline 
21805
21806 \newline 
21807 When writing your code:
21808 \layout Itemize
21809
21810 write your code with debugging in mind (avoid duplicating code, put conceptually
21811  similar variables into structs, use structured code, have strategic points
21812  within your code where all variables are consistent, ...)
21813 \layout Itemize
21814
21815 run a syntax-checking tool like splint
21816 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21817
21818 \end_inset 
21819
21820
21821 \begin_inset LatexCommand \index{lint (syntax checking tool)}
21822
21823 \end_inset 
21824
21825  (see -
21826 \begin_inset ERT
21827 status Collapsed
21828
21829 \layout Standard
21830
21831 \backslash 
21832 /
21833 \end_inset 
21834
21835 -more-pedantic 
21836 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21837
21838 \end_inset 
21839
21840 ) over the code.
21841 \layout Itemize
21842
21843 for the high level code use a C-compiler (like f.e.
21844  GCC) to compile run and debug the code on your host.
21845  See (see -
21846 \begin_inset ERT
21847 status Collapsed
21848
21849 \layout Standard
21850
21851 \backslash 
21852 /
21853 \end_inset 
21854
21855 -more-pedantic 
21856 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21857
21858 \end_inset 
21859
21860  ) on howto handle syntax extensions like __xdata, __at(), ...
21861  
21862 \layout Itemize
21863
21864 use another C-compiler to compile code for your target.
21865  Always an option but not recommended:) And not very likely to help you.
21866  If you seriously consider walking this path you should at least occasionally
21867  check portability of your code.
21868  Most commercial compiler vendors will offer an evaluation version so you
21869  can test compile your code or snippets of your code.
21870 \layout Standard
21871
21872 Debugging on a simulator:
21873 \layout Itemize
21874
21875 there is a separate section about SDCDB (section 
21876 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
21877
21878 \end_inset 
21879
21880 ) below.
21881 \layout Itemize
21882
21883 or (8051 specific) use a freeware/commercial simulator which interfaces
21884  to the AOMF
21885 \begin_inset LatexCommand \index{AOMF, AOMF51}
21886
21887 \end_inset 
21888
21889  file (see 
21890 \begin_inset LatexCommand \ref{OMF file}
21891
21892 \end_inset 
21893
21894 ) optionally generated by SDCC.
21895 \layout Standard
21896
21897 Debugging On-target: 
21898 \layout Itemize
21899
21900 use a MCU port pin to serially output debug data to the RS232 port of your
21901  host.
21902  You'll probably want some level shifting device typically involving a MAX232
21903  or similar IC.
21904  If the hardware serial port of the MCU is not available search for 'Software
21905  UART' in your favourite search machine.
21906 \layout Itemize
21907
21908 use an on-target monitor.
21909  In this context a monitor is a small program which usually accepts commands
21910  via a serial line and allows to set program counter, to single step through
21911  a program and read/write memory locations.
21912  For the 8051 good examples of monitors are paulmon and cmon51 (see section
21913  
21914 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
21915
21916 \end_inset 
21917
21918 ).
21919 \layout Itemize
21920
21921 toggle MCU port pins at strategic points within your code and use an oscilloscop
21922 e.
21923  A 
21924 \emph on 
21925 digital oscilloscope
21926 \emph default 
21927
21928 \begin_inset LatexCommand \index{Oscilloscope}
21929
21930 \end_inset 
21931
21932  with deep trace memory is really helpful especially if you have to debug
21933  a realtime application.
21934  If you need to monitor more pins than your oscilloscope provides you can
21935  sometimes get away with a small R-2R network.
21936  On a single channel oscilloscope you could f.e.
21937  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
21938 k
21939 \begin_inset Formula $\Omega$
21940 \end_inset 
21941
21942  resistor and the other one by a 5\SpecialChar ~
21943 k
21944 \begin_inset Formula $\Omega$
21945 \end_inset 
21946
21947  resistor to the oscilloscope probe (check output drive capability of the
21948  pins you want to monitor).
21949  If you need to monitor many more pins a 
21950 \emph on 
21951 logic analyzer
21952 \emph default 
21953  will be handy.
21954 \layout Itemize
21955
21956 use an ICE (
21957 \emph on 
21958 i
21959 \emph default 
21960
21961 \emph on 
21962 c
21963 \emph default 
21964 ircuit 
21965 \emph on 
21966 e
21967 \emph default 
21968 mulator
21969 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
21970
21971 \end_inset 
21972
21973 ).
21974  Usually very expensive.
21975  And very nice to have too.
21976  And usually locks you (for years...) to the devices the ICE can emulate.
21977  
21978 \layout Itemize
21979
21980 use a remote debugger.
21981  In most 8-bit systems the symbol information is not available on the target,
21982  and a complete debugger is too bulky for the target system.
21983  Therefore usually a debugger on the host system connects to an on-target
21984  debugging stub which accepts only primitive commands.
21985  
21986 \newline 
21987 Terms to enter into your favourite search engine could be 'remote debugging',
21988  'gdb stub' or 'inferior debugger'.
21989  (is there one?)
21990 \layout Itemize
21991
21992 use an on target hardware debugger.
21993  Some of the more modern MCUs include hardware support for setting break
21994  points and monitoring/changing variables by using dedicated hardware pins.
21995  This facility doesn't require additional code to run on the target and
21996  
21997 \emph on 
21998 usually
21999 \emph default 
22000  doesn't affect runtime behaviour until a breakpoint is hit.
22001  For the mcs51 most hardware debuggers use the AOMF
22002 \begin_inset LatexCommand \index{AOMF, AOMF51}
22003
22004 \end_inset 
22005
22006  file (see 
22007 \begin_inset LatexCommand \ref{OMF file}
22008
22009 \end_inset 
22010
22011 ) as input file.
22012  
22013 \layout Standard
22014
22015 Last not least:
22016 \layout Itemize
22017
22018 if you are not familiar with any of the following terms you're likely to
22019  run into problems rather sooner than later: 
22020 \emph on 
22021 volatile
22022 \emph default 
22023
22024 \emph on 
22025 atomic
22026 \emph default 
22027
22028 \emph on 
22029 memory map
22030 \emph default 
22031
22032 \emph on 
22033 overlay
22034 \emph default 
22035 .
22036  As an embedded programmer you 
22037 \emph on 
22038 have
22039 \emph default 
22040  to know them so why not look them up 
22041 \emph on 
22042 before
22043 \emph default 
22044  you have problems?)
22045 \layout Itemize
22046
22047 tell someone else about your problem (actually this is a surprisingly effective
22048  means to hunt down the bug even if the listener is not familiar with your
22049  environment).
22050  As 'failure to communicate' is probably one of the job-induced deformations
22051  of an embedded programmer this is highly encouraged.
22052 \layout Section
22053
22054 Debugging with SDCDB
22055 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
22056
22057 \end_inset 
22058
22059
22060 \begin_inset LatexCommand \index{SDCDB (debugger)}
22061
22062 \end_inset 
22063
22064  
22065 \layout Standard
22066
22067 SDCC is distributed with a source level debugger
22068 \begin_inset LatexCommand \index{Debugger}
22069
22070 \end_inset 
22071
22072 .
22073  The debugger uses a command line interface, the command repertoire of the
22074  debugger has been kept as close to gdb
22075 \begin_inset LatexCommand \index{gdb}
22076
22077 \end_inset 
22078
22079  (the GNU debugger) as possible.
22080  The configuration and build process is part of the standard compiler installati
22081 on, which also builds and installs the debugger in the target directory
22082  specified during configuration.
22083  The debugger allows you debug BOTH at the C source and at the ASM source
22084  level.
22085 \layout Subsection
22086
22087 Compiling for Debugging
22088 \layout Standard
22089
22090 The -
22091 \begin_inset ERT
22092 status Collapsed
22093
22094 \layout Standard
22095
22096 \backslash 
22097 /
22098 \end_inset 
22099
22100 -debug
22101 \begin_inset LatexCommand \index{-\/-debug}
22102
22103 \end_inset 
22104
22105  option must be specified for all files for which debug information is to
22106  be generated.
22107  The compiler generates a .adb file for each of these files.
22108  The linker creates the .cdb
22109 \begin_inset LatexCommand \index{<file>.cdb}
22110
22111 \end_inset 
22112
22113  file from the .adb
22114 \begin_inset LatexCommand \index{<file>.adb}
22115
22116 \end_inset 
22117
22118  files and the address information.
22119  This .cdb is used by the debugger.
22120 \layout Subsection
22121
22122 How the Debugger Works
22123 \layout Standard
22124
22125 When the -
22126 \begin_inset ERT
22127 status Collapsed
22128
22129 \layout Standard
22130
22131 \backslash 
22132 /
22133 \end_inset 
22134
22135 -debug option is specified the compiler generates extra symbol information
22136  some of which are put into the assembler source and some are put into the
22137  .adb file.
22138  Then the linker creates the .cdb file from the individual .adb files with
22139  the address information for the symbols.
22140  The debugger reads the symbolic information generated by the compiler &
22141  the address information generated by the linker.
22142  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
22143  execution is controlled by the debugger.
22144  When a command is issued for the debugger, it translates it into appropriate
22145  commands for the simulator.
22146  (Currently SDCDM only connects to the simulator but 
22147 \emph on 
22148 newcdb
22149 \emph default 
22150  at 
22151 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
22152
22153 \end_inset 
22154
22155  is an effort to connect directly to the hardware.) 
22156 \layout Subsection
22157
22158 Starting the Debugger SDCDB
22159 \layout Standard
22160
22161 The debugger can be started using the following command line.
22162  (Assume the file you are debugging has the file name foo).
22163 \newline 
22164
22165 \newline 
22166
22167 \family sans 
22168 \series bold 
22169 sdcdb foo
22170 \newline 
22171
22172 \family default 
22173 \series default 
22174
22175 \newline 
22176 The debugger will look for the following files.
22177 \layout Itemize
22178
22179 foo.c - the source file.
22180 \layout Itemize
22181
22182 foo.cdb - the debugger symbol information file.
22183 \layout Itemize
22184
22185 foo.ihx - the Intel hex format
22186 \begin_inset LatexCommand \index{Intel hex format}
22187
22188 \end_inset 
22189
22190  object file.
22191 \layout Subsection
22192
22193 SDCDB Command Line Options
22194 \layout Itemize
22195
22196 -
22197 \begin_inset ERT
22198 status Collapsed
22199
22200 \layout Standard
22201
22202 \backslash 
22203 /
22204 \end_inset 
22205
22206 -directory=<source file directory> this option can used to specify the directory
22207  search list.
22208  The debugger will look into the directory list specified for source, cdb
22209  & ihx files.
22210  The items in the directory list must be separated by ':', e.g.
22211  if the source files can be in the directories /home/src1 and /home/src2,
22212  the -
22213 \begin_inset ERT
22214 status Collapsed
22215
22216 \layout Standard
22217
22218 \backslash 
22219 /
22220 \end_inset 
22221
22222 -directory option should be -
22223 \begin_inset ERT
22224 status Collapsed
22225
22226 \layout Standard
22227
22228 \backslash 
22229 /
22230 \end_inset 
22231
22232 -directory=/home/src1:/home/src2.
22233  Note there can be no spaces in the option.
22234  
22235 \layout Itemize
22236
22237 -cd <directory> - change to the <directory>.
22238 \layout Itemize
22239
22240 -fullname - used by GUI front ends.
22241 \layout Itemize
22242
22243 -cpu <cpu-type> - this argument is passed to the simulator please see the
22244  simulator docs for details.
22245 \layout Itemize
22246
22247 -X <Clock frequency > this options is passed to the simulator please see
22248  the simulator docs for details.
22249 \layout Itemize
22250
22251 -s <serial port file> passed to simulator see the simulator docs for details.
22252 \layout Itemize
22253
22254 -S <serial in,out> passed to simulator see the simulator docs for details.
22255 \layout Itemize
22256
22257 -k <port number> passed to simulator see the simulator docs for details.
22258 \layout Subsection
22259
22260 SDCDB Debugger Commands
22261 \layout Standard
22262
22263 As mentioned earlier the command interface for the debugger has been deliberatel
22264 y kept as close the GNU debugger gdb, as possible.
22265  This will help the integration with existing graphical user interfaces
22266  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
22267  If you use a graphical user interface for the debugger you can skip this
22268  section.
22269 \layout Subsubsection*
22270
22271 break [line | file:line | function | file:function]
22272 \layout Standard
22273
22274 Set breakpoint at specified line or function:
22275 \newline 
22276
22277 \newline 
22278
22279 \family sans 
22280 \series bold 
22281 sdcdb>break 100 
22282 \newline 
22283 sdcdb>break foo.c:100
22284 \newline 
22285 sdcdb>break funcfoo
22286 \newline 
22287 sdcdb>break foo.c:funcfoo
22288 \layout Subsubsection*
22289
22290 clear [line | file:line | function | file:function ]
22291 \layout Standard
22292
22293 Clear breakpoint at specified line or function:
22294 \newline 
22295
22296 \newline 
22297
22298 \family sans 
22299 \series bold 
22300 sdcdb>clear 100
22301 \newline 
22302 sdcdb>clear foo.c:100
22303 \newline 
22304 sdcdb>clear funcfoo
22305 \newline 
22306 sdcdb>clear foo.c:funcfoo
22307 \layout Subsubsection*
22308
22309 continue
22310 \layout Standard
22311
22312 Continue program being debugged, after breakpoint.
22313 \layout Subsubsection*
22314
22315 finish
22316 \layout Standard
22317
22318 Execute till the end of the current function.
22319 \layout Subsubsection*
22320
22321 delete [n]
22322 \layout Standard
22323
22324 Delete breakpoint number 'n'.
22325  If used without any option clear ALL user defined break points.
22326 \layout Subsubsection*
22327
22328 info [break | stack | frame | registers ]
22329 \layout Itemize
22330
22331 info break - list all breakpoints
22332 \layout Itemize
22333
22334 info stack - show the function call stack.
22335 \layout Itemize
22336
22337 info frame - show information about the current execution frame.
22338 \layout Itemize
22339
22340 info registers - show content of all registers.
22341 \layout Subsubsection*
22342
22343 step
22344 \layout Standard
22345
22346 Step program until it reaches a different source line.
22347  Note: pressing <return> repeats the last command.
22348 \layout Subsubsection*
22349
22350 next
22351 \layout Standard
22352
22353 Step program, proceeding through subroutine calls.
22354 \layout Subsubsection*
22355
22356 run
22357 \layout Standard
22358
22359 Start debugged program.
22360 \layout Subsubsection*
22361
22362 ptype variable 
22363 \layout Standard
22364
22365 Print type information of the variable.
22366 \layout Subsubsection*
22367
22368 print variable
22369 \layout Standard
22370
22371 print value of variable.
22372 \layout Subsubsection*
22373
22374 file filename
22375 \layout Standard
22376
22377 load the given file name.
22378  Note this is an alternate method of loading file for debugging.
22379 \layout Subsubsection*
22380
22381 frame
22382 \layout Standard
22383
22384 print information about current frame.
22385 \layout Subsubsection*
22386
22387 set srcmode
22388 \layout Standard
22389
22390 Toggle between C source & assembly source.
22391 \layout Subsubsection*
22392
22393 ! simulator command
22394 \layout Standard
22395
22396 Send the string following '!' to the simulator, the simulator response is
22397  displayed.
22398  Note the debugger does not interpret the command being sent to the simulator,
22399  so if a command like 'go' is sent the debugger can loose its execution
22400  context and may display incorrect values.
22401 \layout Subsubsection*
22402
22403 quit
22404 \layout Standard
22405
22406 "Watch me now.
22407  Iam going Down.
22408  My name is Bobby Brown"
22409 \layout Subsection
22410
22411 Interfacing SDCDB with DDD
22412 \layout Comment
22413
22414 The screenshot was converted from png to eps with: 
22415 \begin_inset Quotes sld
22416 \end_inset 
22417
22418 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22419 \begin_inset Quotes srd
22420 \end_inset 
22421
22422  which produces a pretty compact eps file which is free from compression
22423  artifacts.
22424 \layout Comment
22425
22426 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22427  as this broke the build system on Sourceforge (pdf-file was broken.
22428  pdflatex does not accept eps files).
22429 \layout Standard
22430
22431 The 
22432 \emph on 
22433 p
22434 \emph default 
22435 ortable 
22436 \emph on 
22437 n
22438 \emph default 
22439 etwork 
22440 \emph on 
22441 g
22442 \emph default 
22443 raphics File 
22444 \size footnotesize 
22445
22446 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22447
22448 \end_inset 
22449
22450
22451 \size default 
22452  shows a screenshot of a debugging session with DDD
22453 \begin_inset LatexCommand \index{DDD (debugger)}
22454
22455 \end_inset 
22456
22457  (Unix only) on a simulated 8032.
22458  The debugging session might not run as smoothly as the screenshot suggests.
22459  The debugger allows setting of breakpoints, displaying and changing variables,
22460  single stepping through C and assembler code.
22461  
22462 \newline 
22463 The source was compiled with 
22464 \family sans 
22465 \series bold 
22466
22467 \newline 
22468
22469 \newline 
22470 sdcc -
22471 \family default 
22472 \series default 
22473
22474 \begin_inset ERT
22475 status Collapsed
22476
22477 \layout Standard
22478
22479 \backslash 
22480 /
22481 \end_inset 
22482
22483
22484 \family sans 
22485 \series bold 
22486 -debug ddd_example.c
22487 \family default 
22488 \series default 
22489  
22490 \family sans 
22491 \series bold 
22492
22493 \newline 
22494
22495 \family default 
22496 \series default 
22497
22498 \newline 
22499 and DDD was invoked with 
22500 \family sans 
22501 \series bold 
22502
22503 \newline 
22504
22505 \newline 
22506 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22507 \layout Subsection
22508
22509 Interfacing SDCDB with XEmacs
22510 \begin_inset LatexCommand \index{XEmacs}
22511
22512 \end_inset 
22513
22514
22515 \begin_inset LatexCommand \index{Emacs}
22516
22517 \end_inset 
22518
22519
22520 \layout Standard
22521
22522 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22523  sdcdb.el and sdcdbsrc.el.
22524  These two files can be found in the $(prefix)/bin directory after the installat
22525 ion is complete.
22526  These files need to be loaded into XEmacs for the interface to work.
22527  This can be done at XEmacs startup time by inserting the following into
22528  your '.xemacs' file (which can be found in your HOME directory): 
22529 \newline 
22530
22531 \newline 
22532
22533 \family typewriter 
22534 (load-file sdcdbsrc.el) 
22535 \family default 
22536
22537 \newline 
22538
22539 \newline 
22540 .xemacs is a lisp file so the () around the command is REQUIRED.
22541  The files can also be loaded dynamically while XEmacs is running, set the
22542  environment variable 'EMACSLOADPATH' to the installation bin directory
22543  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22544  To start the interface enter the following command: 
22545 \newline 
22546
22547 \newline 
22548
22549 \family sans 
22550 \series bold 
22551 ESC-x sdcdbsrc
22552 \family default 
22553 \series default 
22554
22555 \newline 
22556
22557 \newline 
22558 You will prompted to enter the file name to be debugged.
22559  
22560 \newline 
22561
22562 \newline 
22563 The command line options that are passed to the simulator directly are bound
22564  to default values in the file sdcdbsrc.el.
22565  The variables are listed below, these values maybe changed as required.
22566 \layout Itemize
22567
22568 sdcdbsrc-cpu-type '51
22569 \layout Itemize
22570
22571 sdcdbsrc-frequency '11059200
22572 \layout Itemize
22573
22574 sdcdbsrc-serial nil
22575 \layout Standard
22576
22577 The following is a list of key mapping for the debugger interface.
22578 \layout Standard
22579
22580 \SpecialChar ~
22581
22582 \family typewriter 
22583
22584 \newline 
22585 ;;\SpecialChar ~
22586 Current Listing :: 
22587 \newline 
22588 ;;key\SpecialChar ~
22589 \SpecialChar ~
22590 \SpecialChar ~
22591 \SpecialChar ~
22592 \SpecialChar ~
22593 \SpecialChar ~
22594 \SpecialChar ~
22595 \SpecialChar ~
22596 \SpecialChar ~
22597 \SpecialChar ~
22598 \SpecialChar ~
22599 \SpecialChar ~
22600 \SpecialChar ~
22601 \SpecialChar ~
22602 binding\SpecialChar ~
22603 \SpecialChar ~
22604 \SpecialChar ~
22605 \SpecialChar ~
22606 \SpecialChar ~
22607 \SpecialChar ~
22608 \SpecialChar ~
22609 \SpecialChar ~
22610 \SpecialChar ~
22611 \SpecialChar ~
22612 \SpecialChar ~
22613 \SpecialChar ~
22614 \SpecialChar ~
22615 \SpecialChar ~
22616 \SpecialChar ~
22617 \SpecialChar ~
22618 \SpecialChar ~
22619 \SpecialChar ~
22620 \SpecialChar ~
22621 \SpecialChar ~
22622 \SpecialChar ~
22623 \SpecialChar ~
22624 Comment 
22625 \newline 
22626 ;;---\SpecialChar ~
22627 \SpecialChar ~
22628 \SpecialChar ~
22629 \SpecialChar ~
22630 \SpecialChar ~
22631 \SpecialChar ~
22632 \SpecialChar ~
22633 \SpecialChar ~
22634 \SpecialChar ~
22635 \SpecialChar ~
22636 \SpecialChar ~
22637 \SpecialChar ~
22638 \SpecialChar ~
22639 \SpecialChar ~
22640 -------\SpecialChar ~
22641 \SpecialChar ~
22642 \SpecialChar ~
22643 \SpecialChar ~
22644 \SpecialChar ~
22645 \SpecialChar ~
22646 \SpecialChar ~
22647 \SpecialChar ~
22648 \SpecialChar ~
22649 \SpecialChar ~
22650 \SpecialChar ~
22651 \SpecialChar ~
22652 \SpecialChar ~
22653 \SpecialChar ~
22654 \SpecialChar ~
22655 \SpecialChar ~
22656 \SpecialChar ~
22657 \SpecialChar ~
22658 \SpecialChar ~
22659 \SpecialChar ~
22660 \SpecialChar ~
22661 \SpecialChar ~
22662 -------
22663 \newline 
22664 ;; 
22665 \newline 
22666 ;;\SpecialChar ~
22667 n\SpecialChar ~
22668 \SpecialChar ~
22669 \SpecialChar ~
22670 \SpecialChar ~
22671 \SpecialChar ~
22672 \SpecialChar ~
22673 \SpecialChar ~
22674 \SpecialChar ~
22675 \SpecialChar ~
22676 \SpecialChar ~
22677 \SpecialChar ~
22678 \SpecialChar ~
22679 \SpecialChar ~
22680 \SpecialChar ~
22681 \SpecialChar ~
22682 sdcdb-next-from-src\SpecialChar ~
22683 \SpecialChar ~
22684 \SpecialChar ~
22685 \SpecialChar ~
22686 \SpecialChar ~
22687 \SpecialChar ~
22688 \SpecialChar ~
22689 \SpecialChar ~
22690 \SpecialChar ~
22691 \SpecialChar ~
22692 SDCDB next command 
22693 \newline 
22694 ;;\SpecialChar ~
22695 b\SpecialChar ~
22696 \SpecialChar ~
22697 \SpecialChar ~
22698 \SpecialChar ~
22699 \SpecialChar ~
22700 \SpecialChar ~
22701 \SpecialChar ~
22702 \SpecialChar ~
22703 \SpecialChar ~
22704 \SpecialChar ~
22705 \SpecialChar ~
22706 \SpecialChar ~
22707 \SpecialChar ~
22708 \SpecialChar ~
22709 \SpecialChar ~
22710 sdcdb-back-from-src\SpecialChar ~
22711 \SpecialChar ~
22712 \SpecialChar ~
22713 \SpecialChar ~
22714 \SpecialChar ~
22715 \SpecialChar ~
22716 \SpecialChar ~
22717 \SpecialChar ~
22718 \SpecialChar ~
22719 \SpecialChar ~
22720 SDCDB back command 
22721 \newline 
22722 ;;\SpecialChar ~
22723 c\SpecialChar ~
22724 \SpecialChar ~
22725 \SpecialChar ~
22726 \SpecialChar ~
22727 \SpecialChar ~
22728 \SpecialChar ~
22729 \SpecialChar ~
22730 \SpecialChar ~
22731 \SpecialChar ~
22732 \SpecialChar ~
22733 \SpecialChar ~
22734 \SpecialChar ~
22735 \SpecialChar ~
22736 \SpecialChar ~
22737 \SpecialChar ~
22738 sdcdb-cont-from-src\SpecialChar ~
22739 \SpecialChar ~
22740 \SpecialChar ~
22741 \SpecialChar ~
22742 \SpecialChar ~
22743 \SpecialChar ~
22744 \SpecialChar ~
22745 \SpecialChar ~
22746 \SpecialChar ~
22747 \SpecialChar ~
22748 SDCDB continue command
22749 \newline 
22750 ;;\SpecialChar ~
22751 s\SpecialChar ~
22752 \SpecialChar ~
22753 \SpecialChar ~
22754 \SpecialChar ~
22755 \SpecialChar ~
22756 \SpecialChar ~
22757 \SpecialChar ~
22758 \SpecialChar ~
22759 \SpecialChar ~
22760 \SpecialChar ~
22761 \SpecialChar ~
22762 \SpecialChar ~
22763 \SpecialChar ~
22764 \SpecialChar ~
22765 \SpecialChar ~
22766 sdcdb-step-from-src\SpecialChar ~
22767 \SpecialChar ~
22768 \SpecialChar ~
22769 \SpecialChar ~
22770 \SpecialChar ~
22771 \SpecialChar ~
22772 \SpecialChar ~
22773 \SpecialChar ~
22774 \SpecialChar ~
22775 \SpecialChar ~
22776 SDCDB step command 
22777 \newline 
22778 ;;\SpecialChar ~
22779 ?\SpecialChar ~
22780 \SpecialChar ~
22781 \SpecialChar ~
22782 \SpecialChar ~
22783 \SpecialChar ~
22784 \SpecialChar ~
22785 \SpecialChar ~
22786 \SpecialChar ~
22787 \SpecialChar ~
22788 \SpecialChar ~
22789 \SpecialChar ~
22790 \SpecialChar ~
22791 \SpecialChar ~
22792 \SpecialChar ~
22793 \SpecialChar ~
22794 sdcdb-whatis-c-sexp\SpecialChar ~
22795 \SpecialChar ~
22796 \SpecialChar ~
22797 \SpecialChar ~
22798 \SpecialChar ~
22799 \SpecialChar ~
22800 \SpecialChar ~
22801 \SpecialChar ~
22802 \SpecialChar ~
22803 \SpecialChar ~
22804 SDCDB ptypecommand for data at 
22805 \newline 
22806 ;;\SpecialChar ~
22807 \SpecialChar ~
22808 \SpecialChar ~
22809 \SpecialChar ~
22810 \SpecialChar ~
22811 \SpecialChar ~
22812 \SpecialChar ~
22813 \SpecialChar ~
22814 \SpecialChar ~
22815 \SpecialChar ~
22816 \SpecialChar ~
22817 \SpecialChar ~
22818 \SpecialChar ~
22819 \SpecialChar ~
22820 \SpecialChar ~
22821 \SpecialChar ~
22822 \SpecialChar ~
22823 \SpecialChar ~
22824 \SpecialChar ~
22825 \SpecialChar ~
22826 \SpecialChar ~
22827 \SpecialChar ~
22828 \SpecialChar ~
22829 \SpecialChar ~
22830 \SpecialChar ~
22831 \SpecialChar ~
22832 \SpecialChar ~
22833 \SpecialChar ~
22834 \SpecialChar ~
22835 \SpecialChar ~
22836 \SpecialChar ~
22837 \SpecialChar ~
22838 \SpecialChar ~
22839 \SpecialChar ~
22840 \SpecialChar ~
22841 \SpecialChar ~
22842 \SpecialChar ~
22843 \SpecialChar ~
22844 \SpecialChar ~
22845 \SpecialChar ~
22846 \SpecialChar ~
22847 \SpecialChar ~
22848 \SpecialChar ~
22849 \SpecialChar ~
22850 \SpecialChar ~
22851 \SpecialChar ~
22852 \SpecialChar ~
22853 buffer point 
22854 \newline 
22855 ;;\SpecialChar ~
22856 x\SpecialChar ~
22857 \SpecialChar ~
22858 \SpecialChar ~
22859 \SpecialChar ~
22860 \SpecialChar ~
22861 \SpecialChar ~
22862 \SpecialChar ~
22863 \SpecialChar ~
22864 \SpecialChar ~
22865 \SpecialChar ~
22866 \SpecialChar ~
22867 \SpecialChar ~
22868 \SpecialChar ~
22869 \SpecialChar ~
22870 \SpecialChar ~
22871 sdcdbsrc-delete\SpecialChar ~
22872 \SpecialChar ~
22873 \SpecialChar ~
22874 \SpecialChar ~
22875 \SpecialChar ~
22876 \SpecialChar ~
22877 \SpecialChar ~
22878 \SpecialChar ~
22879 \SpecialChar ~
22880 \SpecialChar ~
22881 \SpecialChar ~
22882 \SpecialChar ~
22883 \SpecialChar ~
22884 \SpecialChar ~
22885 SDCDB Delete all breakpoints if no arg 
22886 \newline 
22887 ;;\SpecialChar ~
22888 \SpecialChar ~
22889 \SpecialChar ~
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 \SpecialChar ~
22893 \SpecialChar ~
22894 \SpecialChar ~
22895 \SpecialChar ~
22896 \SpecialChar ~
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 \SpecialChar ~
22900 \SpecialChar ~
22901 \SpecialChar ~
22902 \SpecialChar ~
22903 \SpecialChar ~
22904 \SpecialChar ~
22905 \SpecialChar ~
22906 \SpecialChar ~
22907 \SpecialChar ~
22908 \SpecialChar ~
22909 \SpecialChar ~
22910 \SpecialChar ~
22911 \SpecialChar ~
22912 \SpecialChar ~
22913 \SpecialChar ~
22914 \SpecialChar ~
22915 \SpecialChar ~
22916 \SpecialChar ~
22917 \SpecialChar ~
22918 \SpecialChar ~
22919 \SpecialChar ~
22920 \SpecialChar ~
22921 \SpecialChar ~
22922 \SpecialChar ~
22923 \SpecialChar ~
22924 \SpecialChar ~
22925 \SpecialChar ~
22926 \SpecialChar ~
22927 \SpecialChar ~
22928 \SpecialChar ~
22929 \SpecialChar ~
22930 \SpecialChar ~
22931 \SpecialChar ~
22932 \SpecialChar ~
22933 \SpecialChar ~
22934 given or delete arg (C-u arg x) 
22935 \newline 
22936 ;;\SpecialChar ~
22937 m\SpecialChar ~
22938 \SpecialChar ~
22939 \SpecialChar ~
22940 \SpecialChar ~
22941 \SpecialChar ~
22942 \SpecialChar ~
22943 \SpecialChar ~
22944 \SpecialChar ~
22945 \SpecialChar ~
22946 \SpecialChar ~
22947 \SpecialChar ~
22948 \SpecialChar ~
22949 \SpecialChar ~
22950 \SpecialChar ~
22951 \SpecialChar ~
22952 sdcdbsrc-frame\SpecialChar ~
22953 \SpecialChar ~
22954 \SpecialChar ~
22955 \SpecialChar ~
22956 \SpecialChar ~
22957 \SpecialChar ~
22958 \SpecialChar ~
22959 \SpecialChar ~
22960 \SpecialChar ~
22961 \SpecialChar ~
22962 \SpecialChar ~
22963 \SpecialChar ~
22964 \SpecialChar ~
22965 \SpecialChar ~
22966 \SpecialChar ~
22967 SDCDB Display current frame if no arg, 
22968 \newline 
22969 ;;\SpecialChar ~
22970 \SpecialChar ~
22971 \SpecialChar ~
22972 \SpecialChar ~
22973 \SpecialChar ~
22974 \SpecialChar ~
22975 \SpecialChar ~
22976 \SpecialChar ~
22977 \SpecialChar ~
22978 \SpecialChar ~
22979 \SpecialChar ~
22980 \SpecialChar ~
22981 \SpecialChar ~
22982 \SpecialChar ~
22983 \SpecialChar ~
22984 \SpecialChar ~
22985 \SpecialChar ~
22986 \SpecialChar ~
22987 \SpecialChar ~
22988 \SpecialChar ~
22989 \SpecialChar ~
22990 \SpecialChar ~
22991 \SpecialChar ~
22992 \SpecialChar ~
22993 \SpecialChar ~
22994 \SpecialChar ~
22995 \SpecialChar ~
22996 \SpecialChar ~
22997 \SpecialChar ~
22998 \SpecialChar ~
22999 \SpecialChar ~
23000 \SpecialChar ~
23001 \SpecialChar ~
23002 \SpecialChar ~
23003 \SpecialChar ~
23004 \SpecialChar ~
23005 \SpecialChar ~
23006 \SpecialChar ~
23007 \SpecialChar ~
23008 \SpecialChar ~
23009 \SpecialChar ~
23010 \SpecialChar ~
23011 \SpecialChar ~
23012 \SpecialChar ~
23013 \SpecialChar ~
23014 \SpecialChar ~
23015 \SpecialChar ~
23016 given or display frame arg 
23017 \newline 
23018 ;;\SpecialChar ~
23019 \SpecialChar ~
23020 \SpecialChar ~
23021 \SpecialChar ~
23022 \SpecialChar ~
23023 \SpecialChar ~
23024 \SpecialChar ~
23025 \SpecialChar ~
23026 \SpecialChar ~
23027 \SpecialChar ~
23028 \SpecialChar ~
23029 \SpecialChar ~
23030 \SpecialChar ~
23031 \SpecialChar ~
23032 \SpecialChar ~
23033 \SpecialChar ~
23034 \SpecialChar ~
23035 \SpecialChar ~
23036 \SpecialChar ~
23037 \SpecialChar ~
23038 \SpecialChar ~
23039 \SpecialChar ~
23040 \SpecialChar ~
23041 \SpecialChar ~
23042 \SpecialChar ~
23043 \SpecialChar ~
23044 \SpecialChar ~
23045 \SpecialChar ~
23046 \SpecialChar ~
23047 \SpecialChar ~
23048 \SpecialChar ~
23049 \SpecialChar ~
23050 \SpecialChar ~
23051 \SpecialChar ~
23052 \SpecialChar ~
23053 \SpecialChar ~
23054 \SpecialChar ~
23055 \SpecialChar ~
23056 \SpecialChar ~
23057 \SpecialChar ~
23058 \SpecialChar ~
23059 \SpecialChar ~
23060 \SpecialChar ~
23061 \SpecialChar ~
23062 \SpecialChar ~
23063 \SpecialChar ~
23064 \SpecialChar ~
23065 buffer point 
23066 \newline 
23067 ;;\SpecialChar ~
23068 !\SpecialChar ~
23069 \SpecialChar ~
23070 \SpecialChar ~
23071 \SpecialChar ~
23072 \SpecialChar ~
23073 \SpecialChar ~
23074 \SpecialChar ~
23075 \SpecialChar ~
23076 \SpecialChar ~
23077 \SpecialChar ~
23078 \SpecialChar ~
23079 \SpecialChar ~
23080 \SpecialChar ~
23081 \SpecialChar ~
23082 \SpecialChar ~
23083 sdcdbsrc-goto-sdcdb\SpecialChar ~
23084 \SpecialChar ~
23085 \SpecialChar ~
23086 \SpecialChar ~
23087 \SpecialChar ~
23088 \SpecialChar ~
23089 \SpecialChar ~
23090 \SpecialChar ~
23091 \SpecialChar ~
23092 \SpecialChar ~
23093 Goto the SDCDB output buffer 
23094 \newline 
23095 ;;\SpecialChar ~
23096 p\SpecialChar ~
23097 \SpecialChar ~
23098 \SpecialChar ~
23099 \SpecialChar ~
23100 \SpecialChar ~
23101 \SpecialChar ~
23102 \SpecialChar ~
23103 \SpecialChar ~
23104 \SpecialChar ~
23105 \SpecialChar ~
23106 \SpecialChar ~
23107 \SpecialChar ~
23108 \SpecialChar ~
23109 \SpecialChar ~
23110 \SpecialChar ~
23111 sdcdb-print-c-sexp\SpecialChar ~
23112 \SpecialChar ~
23113 \SpecialChar ~
23114 \SpecialChar ~
23115 \SpecialChar ~
23116 \SpecialChar ~
23117 \SpecialChar ~
23118 \SpecialChar ~
23119 \SpecialChar ~
23120 \SpecialChar ~
23121 \SpecialChar ~
23122 SDCDB print command for data at 
23123 \newline 
23124 ;;\SpecialChar ~
23125 \SpecialChar ~
23126 \SpecialChar ~
23127 \SpecialChar ~
23128 \SpecialChar ~
23129 \SpecialChar ~
23130 \SpecialChar ~
23131 \SpecialChar ~
23132 \SpecialChar ~
23133 \SpecialChar ~
23134 \SpecialChar ~
23135 \SpecialChar ~
23136 \SpecialChar ~
23137 \SpecialChar ~
23138 \SpecialChar ~
23139 \SpecialChar ~
23140 \SpecialChar ~
23141 \SpecialChar ~
23142 \SpecialChar ~
23143 \SpecialChar ~
23144 \SpecialChar ~
23145 \SpecialChar ~
23146 \SpecialChar ~
23147 \SpecialChar ~
23148 \SpecialChar ~
23149 \SpecialChar ~
23150 \SpecialChar ~
23151 \SpecialChar ~
23152 \SpecialChar ~
23153 \SpecialChar ~
23154 \SpecialChar ~
23155 \SpecialChar ~
23156 \SpecialChar ~
23157 \SpecialChar ~
23158 \SpecialChar ~
23159 \SpecialChar ~
23160 \SpecialChar ~
23161 \SpecialChar ~
23162 \SpecialChar ~
23163 \SpecialChar ~
23164 \SpecialChar ~
23165 \SpecialChar ~
23166 \SpecialChar ~
23167 \SpecialChar ~
23168 \SpecialChar ~
23169 \SpecialChar ~
23170 \SpecialChar ~
23171 buffer point 
23172 \newline 
23173 ;;\SpecialChar ~
23174 g\SpecialChar ~
23175 \SpecialChar ~
23176 \SpecialChar ~
23177 \SpecialChar ~
23178 \SpecialChar ~
23179 \SpecialChar ~
23180 \SpecialChar ~
23181 \SpecialChar ~
23182 \SpecialChar ~
23183 \SpecialChar ~
23184 \SpecialChar ~
23185 \SpecialChar ~
23186 \SpecialChar ~
23187 \SpecialChar ~
23188 \SpecialChar ~
23189 sdcdbsrc-goto-sdcdb\SpecialChar ~
23190 \SpecialChar ~
23191 \SpecialChar ~
23192 \SpecialChar ~
23193 \SpecialChar ~
23194 \SpecialChar ~
23195 \SpecialChar ~
23196 \SpecialChar ~
23197 \SpecialChar ~
23198 \SpecialChar ~
23199 Goto the SDCDB output buffer 
23200 \newline 
23201 ;;\SpecialChar ~
23202 t\SpecialChar ~
23203 \SpecialChar ~
23204 \SpecialChar ~
23205 \SpecialChar ~
23206 \SpecialChar ~
23207 \SpecialChar ~
23208 \SpecialChar ~
23209 \SpecialChar ~
23210 \SpecialChar ~
23211 \SpecialChar ~
23212 \SpecialChar ~
23213 \SpecialChar ~
23214 \SpecialChar ~
23215 \SpecialChar ~
23216 \SpecialChar ~
23217 sdcdbsrc-mode\SpecialChar ~
23218 \SpecialChar ~
23219 \SpecialChar ~
23220 \SpecialChar ~
23221 \SpecialChar ~
23222 \SpecialChar ~
23223 \SpecialChar ~
23224 \SpecialChar ~
23225 \SpecialChar ~
23226 \SpecialChar ~
23227 \SpecialChar ~
23228 \SpecialChar ~
23229 \SpecialChar ~
23230 \SpecialChar ~
23231 \SpecialChar ~
23232 \SpecialChar ~
23233 Toggles Sdcdbsrc mode (turns it off) 
23234 \newline 
23235 ;; 
23236 \newline 
23237 ;;\SpecialChar ~
23238 C-c\SpecialChar ~
23239 C-f\SpecialChar ~
23240 \SpecialChar ~
23241 \SpecialChar ~
23242 \SpecialChar ~
23243 \SpecialChar ~
23244 \SpecialChar ~
23245 \SpecialChar ~
23246 \SpecialChar ~
23247 \SpecialChar ~
23248 sdcdb-finish-from-src\SpecialChar ~
23249 \SpecialChar ~
23250 \SpecialChar ~
23251 \SpecialChar ~
23252 \SpecialChar ~
23253 \SpecialChar ~
23254 \SpecialChar ~
23255 \SpecialChar ~
23256 SDCDB finish command 
23257 \newline 
23258 ;; 
23259 \newline 
23260 ;;\SpecialChar ~
23261 C-x\SpecialChar ~
23262 SPC\SpecialChar ~
23263 \SpecialChar ~
23264 \SpecialChar ~
23265 \SpecialChar ~
23266 \SpecialChar ~
23267 \SpecialChar ~
23268 \SpecialChar ~
23269 \SpecialChar ~
23270 \SpecialChar ~
23271 sdcdb-break\SpecialChar ~
23272 \SpecialChar ~
23273 \SpecialChar ~
23274 \SpecialChar ~
23275 \SpecialChar ~
23276 \SpecialChar ~
23277 \SpecialChar ~
23278 \SpecialChar ~
23279 \SpecialChar ~
23280 \SpecialChar ~
23281 \SpecialChar ~
23282 \SpecialChar ~
23283 \SpecialChar ~
23284 \SpecialChar ~
23285 \SpecialChar ~
23286 \SpecialChar ~
23287 \SpecialChar ~
23288 \SpecialChar ~
23289 Set break for line with point 
23290 \newline 
23291 ;;\SpecialChar ~
23292 ESC\SpecialChar ~
23293 t\SpecialChar ~
23294 \SpecialChar ~
23295 \SpecialChar ~
23296 \SpecialChar ~
23297 \SpecialChar ~
23298 \SpecialChar ~
23299 \SpecialChar ~
23300 \SpecialChar ~
23301 \SpecialChar ~
23302 \SpecialChar ~
23303 \SpecialChar ~
23304 sdcdbsrc-mode\SpecialChar ~
23305 \SpecialChar ~
23306 \SpecialChar ~
23307 \SpecialChar ~
23308 \SpecialChar ~
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 \SpecialChar ~
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 \SpecialChar ~
23315 \SpecialChar ~
23316 \SpecialChar ~
23317 \SpecialChar ~
23318 \SpecialChar ~
23319 \SpecialChar ~
23320 Toggle Sdcdbsrc mode 
23321 \newline 
23322 ;;\SpecialChar ~
23323 ESC\SpecialChar ~
23324 m\SpecialChar ~
23325 \SpecialChar ~
23326 \SpecialChar ~
23327 \SpecialChar ~
23328 \SpecialChar ~
23329 \SpecialChar ~
23330 \SpecialChar ~
23331 \SpecialChar ~
23332 \SpecialChar ~
23333 \SpecialChar ~
23334 \SpecialChar ~
23335 sdcdbsrc-srcmode\SpecialChar ~
23336 \SpecialChar ~
23337 \SpecialChar ~
23338 \SpecialChar ~
23339 \SpecialChar ~
23340 \SpecialChar ~
23341 \SpecialChar ~
23342 \SpecialChar ~
23343 \SpecialChar ~
23344 \SpecialChar ~
23345 \SpecialChar ~
23346 \SpecialChar ~
23347 \SpecialChar ~
23348 Toggle list mode 
23349 \newline 
23350 ;; 
23351 \newline 
23352
23353 \layout Chapter
23354 \pagebreak_top 
23355 TIPS
23356 \layout Standard
23357
23358 Here are a few guidelines that will help the compiler generate more efficient
23359  code, some of the tips are specific to this compiler others are generally
23360  good programming practice.
23361 \layout Itemize
23362
23363 Use the smallest data type to represent your data-value.
23364  If it is known in advance that the value is going to be less than 256 then
23365  use an 'unsigned char' instead of a 'short' or 'int'.
23366  Please note, that ANSI C requires both signed and unsigned chars to be
23367  promoted to 'signed int'
23368 \begin_inset LatexCommand \index{promotion to signed int}
23369
23370 \end_inset 
23371
23372
23373 \begin_inset Marginal
23374 collapsed true
23375
23376 \layout Standard
23377
23378
23379 \series bold 
23380 \SpecialChar ~
23381 !
23382 \end_inset 
23383
23384  before doing any operation.
23385  This promotion
23386 \begin_inset LatexCommand \index{type promotion}
23387
23388 \end_inset 
23389
23390
23391 \begin_inset LatexCommand \label{type promotion}
23392
23393 \end_inset 
23394
23395  can be omitted, if the result is the same.
23396  The effect of the promotion rules together with the sign-extension is often
23397  surprising:
23398 \begin_deeper 
23399 \layout Verse
23400
23401
23402 \family typewriter 
23403 unsigned char uc = 0xfe;
23404 \newline 
23405 if (uc * uc < 0) /* this is true! */
23406 \newline 
23407 {
23408 \newline 
23409 \SpecialChar ~
23410 \SpecialChar ~
23411 \SpecialChar ~
23412 \SpecialChar ~
23413 ....
23414 \newline 
23415 }
23416 \layout Standard
23417
23418
23419 \family typewriter 
23420 uc * uc
23421 \family default 
23422  is evaluated as 
23423 \family typewriter 
23424 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23425 \family default 
23426 .
23427  
23428 \newline 
23429 Another one:
23430 \layout Verse
23431
23432
23433 \family typewriter 
23434 (unsigned char) -12 / (signed char) -3 = ...
23435 \layout Standard
23436
23437 No, the result is not 4:
23438 \layout Verse
23439
23440
23441 \family typewriter 
23442 (int) (unsigned char) -12 / (int) (signed char) -3 =
23443 \newline 
23444 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23445 \newline 
23446 (int) 0x00f4 / (int) 0xfffd =
23447 \newline 
23448 (int) 0x00f4 / (int) 0xfffd =
23449 \newline 
23450 (int) 244 / (int) -3 =
23451 \newline 
23452 (int) -81 = (int) 0xffaf;
23453 \layout Standard
23454
23455 Don't complain, that gcc gives you a different result.
23456  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23457  Therefore the results are different.
23458 \newline 
23459 From 
23460 \begin_inset Quotes sld
23461 \end_inset 
23462
23463 comp.lang.c FAQ
23464 \begin_inset Quotes srd
23465 \end_inset 
23466
23467 :
23468 \layout Quote
23469
23470
23471 \emph on 
23472 If well-defined overflow characteristics are important and negative values
23473  are not, or if you want to steer clear of sign-extension problems when
23474  manipulating bits or bytes, use one of the corresponding unsigned types.
23475  (Beware when mixing signed and unsigned values in expressions, though.)
23476 \newline 
23477 Although character types (especially unsigned char) can be used as "tiny"
23478  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23479 ble sign extension and increased code size.
23480 \end_deeper 
23481 \layout Itemize
23482
23483 Use unsigned when it is known in advance that the value is not going to
23484  be negative.
23485  This helps especially if you are doing division or multiplication, bit-shifting
23486  or are using an array index.
23487 \layout Itemize
23488
23489 NEVER jump into a LOOP.
23490 \layout Itemize
23491
23492 Declare the variables to be local
23493 \begin_inset LatexCommand \index{local variables}
23494
23495 \end_inset 
23496
23497  whenever possible, especially loop control variables (induction).
23498 \layout Itemize
23499
23500 Since the compiler does not always do implicit integral promotion, the programme
23501 r should do an explicit cast when integral promotion is required.
23502 \layout Itemize
23503
23504 Reducing the size of division, multiplication & modulus operations can reduce
23505  code size substantially.
23506  Take the following code for example.
23507 \begin_deeper 
23508 \layout Verse
23509
23510
23511 \family typewriter 
23512 foobar(unsigned int p1, unsigned char ch)
23513 \newline 
23514 {
23515 \newline 
23516 \SpecialChar ~
23517 \SpecialChar ~
23518 \SpecialChar ~
23519 \SpecialChar ~
23520 unsigned char ch1 = p1 % ch ;
23521 \newline 
23522 \SpecialChar ~
23523 \SpecialChar ~
23524 \SpecialChar ~
23525 \SpecialChar ~
23526 ....
23527 \newline 
23528 }
23529 \layout Standard
23530
23531 For the modulus operation the variable ch will be promoted to unsigned int
23532  first then the modulus operation will be performed (this will lead to a
23533  call to support routine _moduint()), and the result will be casted to a
23534  char.
23535  If the code is changed to 
23536 \layout Verse
23537
23538
23539 \family typewriter 
23540 foobar(unsigned int p1, unsigned char ch)
23541 \newline 
23542 {
23543 \newline 
23544 \SpecialChar ~
23545 \SpecialChar ~
23546 \SpecialChar ~
23547 \SpecialChar ~
23548 unsigned char ch1 = (unsigned char)p1 % ch ;
23549 \newline 
23550 \SpecialChar ~
23551 \SpecialChar ~
23552 \SpecialChar ~
23553 \SpecialChar ~
23554 ....
23555 \newline 
23556 }
23557 \layout Standard
23558
23559 It would substantially reduce the code generated (future versions of the
23560  compiler will be smart enough to detect such optimization opportunities).
23561 \end_deeper 
23562 \layout Itemize
23563
23564 Have a look at the assembly listing to get a 
23565 \begin_inset Quotes sld
23566 \end_inset 
23567
23568 feeling
23569 \begin_inset Quotes srd
23570 \end_inset 
23571
23572  for the code generation.
23573 \layout Section
23574
23575 Porting code from or to other compilers
23576 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23577
23578 \end_inset 
23579
23580
23581 \layout Itemize
23582
23583 check whether endianness of the compilers differs and adapt where needed.
23584 \layout Itemize
23585
23586 check the device specific header files
23587 \begin_inset LatexCommand \index{Header files}
23588
23589 \end_inset 
23590
23591
23592 \begin_inset LatexCommand \index{Include files}
23593
23594 \end_inset 
23595
23596  for compiler specific syntax.
23597  Eventually include the file <compiler.h
23598 \begin_inset LatexCommand \index{compiler.h (include file)}
23599
23600 \end_inset 
23601
23602
23603 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
23604
23605 \end_inset 
23606
23607  to allow using common header files.
23608  (see f.e.
23609  cc2510fx.h 
23610 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
23611
23612 \end_inset 
23613
23614 ).
23615 \layout Itemize
23616
23617 check whether the startup code contains the correct initialization (watchdog,
23618  peripherals).
23619 \layout Itemize
23620
23621 check whether the sizes of short, int, long match.
23622 \layout Itemize
23623
23624 check if some 16 or 32 bit hardware registers require a specific addressing
23625  order (least significant or most significant byte first) and adapt if needed
23626  (
23627 \emph on 
23628 first
23629 \emph default 
23630  and 
23631 \emph on 
23632 last
23633 \emph default 
23634  relate to time and not to lower/upper memory location here, so this is
23635  
23636 \emph on 
23637 not
23638 \emph default 
23639  the same as endianness).
23640 \layout Itemize
23641
23642 check whether the keyword 
23643 \emph on 
23644 volatile
23645 \emph default 
23646  is used where needed.
23647  The compilers might differ in their optimization characteristics (as different
23648  versions of the same compiler might also use more clever optimizations
23649  this is good idea anyway).
23650  See section 
23651 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
23652
23653 \end_inset 
23654
23655 .
23656 \layout Itemize
23657
23658 check that the compilers are not told to supress warnings.
23659 \layout Itemize
23660
23661 check and convert compiler specific extensions (interrupts, memory areas,
23662  pragmas etc.).
23663 \layout Itemize
23664
23665 check for differences in type promotion.
23666  Especially check for math operations on 
23667 \family typewriter 
23668 char
23669 \family default 
23670  or 
23671 \family typewriter 
23672 unsigned char
23673 \family default 
23674  variables.
23675  For the sake of C99 compatibility SDCC will probably promote these to 
23676 \family typewriter 
23677 int
23678 \family default 
23679  more often than other compilers.
23680  Eventually insert explicit casts to 
23681 \family typewriter 
23682 (char) 
23683 \family default 
23684 or
23685 \family typewriter 
23686  (unsigned char)
23687 \family default 
23688 .
23689  Also check that the ~\SpecialChar ~
23690 operator
23691 \begin_inset LatexCommand \index{\~\/ Operator}
23692
23693 \end_inset 
23694
23695  is not used on 
23696 \family typewriter 
23697 bit
23698 \begin_inset LatexCommand \index{bit}
23699
23700 \end_inset 
23701
23702
23703 \family default 
23704  variables, use the !\SpecialChar ~
23705 operator instead.
23706  See sections 
23707 \begin_inset LatexCommand \ref{type promotion}
23708
23709 \end_inset 
23710
23711  and 
23712 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23713
23714 \end_inset 
23715
23716 .
23717 \layout Itemize
23718
23719 check the assembly code generated for interrupt routines (f.e.
23720  for calls to possibly non-reentrant library functions).
23721 \layout Itemize
23722
23723 check whether timing loops result in proper timing (or preferably consider
23724  a rewrite of the code with timer based delays instead).
23725 \layout Itemize
23726
23727 check for differences in printf parameters (some compilers push (va_arg
23728 \begin_inset LatexCommand \index{vararg, va\_arg}
23729
23730 \end_inset 
23731
23732 ) char variables as 
23733 \family typewriter 
23734 int
23735 \family default 
23736  others push them as 
23737 \family typewriter 
23738 char
23739 \family default 
23740 .
23741  See section 
23742 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23743
23744 \end_inset 
23745
23746 ).
23747 \layout Itemize
23748
23749 check the resulting memory map
23750 \begin_inset LatexCommand \index{Memory map}
23751
23752 \end_inset 
23753
23754 .
23755  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23756 ly idata, pdata, xdata).
23757  Eventually check if unexpected library functions are included.
23758 \layout Section
23759
23760 Tools
23761 \begin_inset LatexCommand \index{Tools}
23762
23763 \end_inset 
23764
23765  included in the distribution
23766 \layout Standard
23767 \align left 
23768
23769 \begin_inset  Tabular
23770 <lyxtabular version="3" rows="12" columns="3">
23771 <features>
23772 <column alignment="left" valignment="top" leftline="true" width="0pt">
23773 <column alignment="left" valignment="top" leftline="true" width="0pt">
23774 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23775 <row topline="true" bottomline="true">
23776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23777 \begin_inset Text
23778
23779 \layout Standard
23780
23781 Name
23782 \end_inset 
23783 </cell>
23784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23785 \begin_inset Text
23786
23787 \layout Standard
23788
23789 Purpose
23790 \end_inset 
23791 </cell>
23792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23793 \begin_inset Text
23794
23795 \layout Standard
23796
23797 Directory
23798 \end_inset 
23799 </cell>
23800 </row>
23801 <row topline="true">
23802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23803 \begin_inset Text
23804
23805 \layout Standard
23806
23807 ucSsim
23808 \end_inset 
23809 </cell>
23810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23811 \begin_inset Text
23812
23813 \layout Standard
23814
23815 Simulator for various architectures
23816 \end_inset 
23817 </cell>
23818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23819 \begin_inset Text
23820
23821 \layout Standard
23822
23823 sdcc/sim/ucsim
23824 \end_inset 
23825 </cell>
23826 </row>
23827 <row topline="true">
23828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23829 \begin_inset Text
23830
23831 \layout Standard
23832
23833 keil2sdcc.pl
23834 \end_inset 
23835 </cell>
23836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23837 \begin_inset Text
23838
23839 \layout Standard
23840
23841 header file
23842 \begin_inset LatexCommand \index{Header files}
23843
23844 \end_inset 
23845
23846
23847 \begin_inset LatexCommand \index{Include files}
23848
23849 \end_inset 
23850
23851  conversion
23852 \end_inset 
23853 </cell>
23854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23855 \begin_inset Text
23856
23857 \layout Standard
23858
23859 sdcc/support/scripts
23860 \end_inset 
23861 </cell>
23862 </row>
23863 <row topline="true">
23864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23865 \begin_inset Text
23866
23867 \layout Standard
23868
23869 mh2h.c
23870 \end_inset 
23871 </cell>
23872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23873 \begin_inset Text
23874
23875 \layout Standard
23876
23877 header file conversion
23878 \end_inset 
23879 </cell>
23880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23881 \begin_inset Text
23882
23883 \layout Standard
23884
23885 sdcc/support/scripts
23886 \end_inset 
23887 </cell>
23888 </row>
23889 <row topline="true">
23890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23891 \begin_inset Text
23892
23893 \layout Standard
23894
23895 as-gbz80
23896 \end_inset 
23897 </cell>
23898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23899 \begin_inset Text
23900
23901 \layout Standard
23902
23903 Assembler
23904 \end_inset 
23905 </cell>
23906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23907 \begin_inset Text
23908
23909 \layout Standard
23910
23911
23912 \family roman 
23913 \series medium 
23914 \shape up 
23915 \size normal 
23916 \emph off 
23917 \bar no 
23918 \noun off 
23919 \color none
23920 sdcc/bin
23921 \end_inset 
23922 </cell>
23923 </row>
23924 <row topline="true">
23925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23926 \begin_inset Text
23927
23928 \layout Standard
23929
23930 as-z80
23931 \end_inset 
23932 </cell>
23933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23934 \begin_inset Text
23935
23936 \layout Standard
23937
23938 Assembler
23939 \end_inset 
23940 </cell>
23941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23942 \begin_inset Text
23943
23944 \layout Standard
23945
23946
23947 \family roman 
23948 \series medium 
23949 \shape up 
23950 \size normal 
23951 \emph off 
23952 \bar no 
23953 \noun off 
23954 \color none
23955 sdcc/bin
23956 \end_inset 
23957 </cell>
23958 </row>
23959 <row topline="true">
23960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23961 \begin_inset Text
23962
23963 \layout Standard
23964
23965 asx8051
23966 \end_inset 
23967 </cell>
23968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23969 \begin_inset Text
23970
23971 \layout Standard
23972
23973 Assembler
23974 \end_inset 
23975 </cell>
23976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23977 \begin_inset Text
23978
23979 \layout Standard
23980
23981
23982 \family roman 
23983 \series medium 
23984 \shape up 
23985 \size normal 
23986 \emph off 
23987 \bar no 
23988 \noun off 
23989 \color none
23990 sdcc/bin
23991 \end_inset 
23992 </cell>
23993 </row>
23994 <row topline="true">
23995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23996 \begin_inset Text
23997
23998 \layout Standard
23999
24000 SDCDB
24001 \end_inset 
24002 </cell>
24003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24004 \begin_inset Text
24005
24006 \layout Standard
24007
24008 Simulator
24009 \end_inset 
24010 </cell>
24011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24012 \begin_inset Text
24013
24014 \layout Standard
24015
24016
24017 \family roman 
24018 \series medium 
24019 \shape up 
24020 \size normal 
24021 \emph off 
24022 \bar no 
24023 \noun off 
24024 \color none
24025 sdcc/bin
24026 \end_inset 
24027 </cell>
24028 </row>
24029 <row topline="true">
24030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24031 \begin_inset Text
24032
24033 \layout Standard
24034
24035 aslink
24036 \end_inset 
24037 </cell>
24038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24039 \begin_inset Text
24040
24041 \layout Standard
24042
24043 Linker
24044 \end_inset 
24045 </cell>
24046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24047 \begin_inset Text
24048
24049 \layout Standard
24050
24051
24052 \family roman 
24053 \series medium 
24054 \shape up 
24055 \size normal 
24056 \emph off 
24057 \bar no 
24058 \noun off 
24059 \color none
24060 sdcc/bin
24061 \end_inset 
24062 </cell>
24063 </row>
24064 <row topline="true">
24065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24066 \begin_inset Text
24067
24068 \layout Standard
24069
24070 link-z80
24071 \end_inset 
24072 </cell>
24073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24074 \begin_inset Text
24075
24076 \layout Standard
24077
24078 Linker
24079 \end_inset 
24080 </cell>
24081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24082 \begin_inset Text
24083
24084 \layout Standard
24085
24086
24087 \family roman 
24088 \series medium 
24089 \shape up 
24090 \size normal 
24091 \emph off 
24092 \bar no 
24093 \noun off 
24094 \color none
24095 sdcc/bin
24096 \end_inset 
24097 </cell>
24098 </row>
24099 <row topline="true">
24100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24101 \begin_inset Text
24102
24103 \layout Standard
24104
24105 link-gbz80
24106 \end_inset 
24107 </cell>
24108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24109 \begin_inset Text
24110
24111 \layout Standard
24112
24113 Linker
24114 \end_inset 
24115 </cell>
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24117 \begin_inset Text
24118
24119 \layout Standard
24120
24121
24122 \family roman 
24123 \series medium 
24124 \shape up 
24125 \size normal 
24126 \emph off 
24127 \bar no 
24128 \noun off 
24129 \color none
24130 sdcc/bin
24131 \end_inset 
24132 </cell>
24133 </row>
24134 <row topline="true" bottomline="true">
24135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24136 \begin_inset Text
24137
24138 \layout Standard
24139
24140 packihx
24141 \end_inset 
24142 </cell>
24143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24144 \begin_inset Text
24145
24146 \layout Standard
24147
24148 Intel Hex packer 
24149 \begin_inset LatexCommand \index{packihx (tool)}
24150
24151 \end_inset 
24152
24153
24154 \end_inset 
24155 </cell>
24156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24157 \begin_inset Text
24158
24159 \layout Standard
24160
24161
24162 \family roman 
24163 \series medium 
24164 \shape up 
24165 \size normal 
24166 \emph off 
24167 \bar no 
24168 \noun off 
24169 \color none
24170 sdcc/bin
24171 \end_inset 
24172 </cell>
24173 </row>
24174 </lyxtabular>
24175
24176 \end_inset 
24177
24178
24179 \newline 
24180
24181 \layout Section
24182
24183 Documentation
24184 \begin_inset LatexCommand \index{Documentation}
24185
24186 \end_inset 
24187
24188  included in the distribution
24189 \layout Standard
24190 \align left 
24191
24192 \begin_inset  Tabular
24193 <lyxtabular version="3" rows="10" columns="2">
24194 <features>
24195 <column alignment="left" valignment="top" leftline="true" width="0">
24196 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
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 Subject / Title
24204 \end_inset 
24205 </cell>
24206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24207 \begin_inset Text
24208
24209 \layout Standard
24210
24211 Where to get / filename
24212 \end_inset 
24213 </cell>
24214 </row>
24215 <row topline="true">
24216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24217 \begin_inset Text
24218
24219 \layout Standard
24220
24221 SDCC Compiler User Guide
24222 \end_inset 
24223 </cell>
24224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24225 \begin_inset Text
24226
24227 \layout Standard
24228
24229 You're reading it right now
24230 \end_inset 
24231 </cell>
24232 </row>
24233 <row topline="true">
24234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24235 \begin_inset Text
24236
24237 \layout Standard
24238
24239 Changelog of SDCC
24240 \end_inset 
24241 </cell>
24242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24243 \begin_inset Text
24244
24245 \layout Standard
24246
24247 sdcc/Changelog
24248 \end_inset 
24249 </cell>
24250 </row>
24251 <row topline="true">
24252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24253 \begin_inset Text
24254
24255 \layout Standard
24256
24257 ASXXXX
24258 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
24259
24260 \end_inset 
24261
24262
24263 \begin_inset LatexCommand \index{Assembler documentation}
24264
24265 \end_inset 
24266
24267  Assemblers and ASLINK
24268 \begin_inset LatexCommand \index{aslink}
24269
24270 \end_inset 
24271
24272
24273 \begin_inset LatexCommand \index{Linker documentation}
24274
24275 \end_inset 
24276
24277  Relocating Linker
24278 \end_inset 
24279 </cell>
24280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24281 \begin_inset Text
24282
24283 \layout Standard
24284
24285 sdcc/as/doc/asxhtm.html
24286 \end_inset 
24287 </cell>
24288 </row>
24289 <row topline="true">
24290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24291 \begin_inset Text
24292
24293 \layout Standard
24294
24295 SDCC regression test
24296 \begin_inset LatexCommand \index{Regression test}
24297
24298 \end_inset 
24299
24300
24301 \end_inset 
24302 </cell>
24303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24304 \begin_inset Text
24305
24306 \layout Standard
24307
24308 sdcc/doc/test_suite_spec.pdf
24309 \end_inset 
24310 </cell>
24311 </row>
24312 <row topline="true">
24313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24314 \begin_inset Text
24315
24316 \layout Standard
24317
24318 Various notes
24319 \end_inset 
24320 </cell>
24321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24322 \begin_inset Text
24323
24324 \layout Standard
24325
24326 sdcc/doc/*
24327 \end_inset 
24328 </cell>
24329 </row>
24330 <row topline="true">
24331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24332 \begin_inset Text
24333
24334 \layout Standard
24335
24336 Notes on debugging with SDCDB
24337 \begin_inset LatexCommand \index{SDCDB (debugger)}
24338
24339 \end_inset 
24340
24341
24342 \end_inset 
24343 </cell>
24344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24345 \begin_inset Text
24346
24347 \layout Standard
24348
24349 sdcc/debugger/README
24350 \end_inset 
24351 </cell>
24352 </row>
24353 <row topline="true">
24354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24355 \begin_inset Text
24356
24357 \layout Standard
24358
24359 Software simulator for microcontrollers
24360 \end_inset 
24361 </cell>
24362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24363 \begin_inset Text
24364
24365 \layout Standard
24366
24367
24368 \family roman 
24369 \series medium 
24370 \shape up 
24371 \size normal 
24372 \emph off 
24373 \bar no 
24374 \noun off 
24375 \color none
24376 sdcc/sim/ucsim/doc
24377 \family default 
24378 \series default 
24379 \shape default 
24380 \size default 
24381 \emph default 
24382 \bar default 
24383 \noun default 
24384 \color default
24385 /index.html
24386 \end_inset 
24387 </cell>
24388 </row>
24389 <row topline="true">
24390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24391 \begin_inset Text
24392
24393 \layout Standard
24394
24395 Temporary notes on the pic16
24396 \begin_inset LatexCommand \index{PIC16}
24397
24398 \end_inset 
24399
24400  port
24401 \end_inset 
24402 </cell>
24403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24404 \begin_inset Text
24405
24406 \layout Standard
24407
24408 sdcc/src/pic16/NOTES
24409 \end_inset 
24410 </cell>
24411 </row>
24412 <row topline="true" bottomline="true">
24413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24414 \begin_inset Text
24415
24416 \layout Standard
24417
24418 SDCC internal documentation (debugging file format)
24419 \end_inset 
24420 </cell>
24421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24422 \begin_inset Text
24423
24424 \layout Standard
24425
24426 sdcc/doc/
24427 \family roman 
24428 \series medium 
24429 \shape up 
24430 \size normal 
24431 \emph off 
24432 \bar no 
24433 \noun off 
24434 \color none
24435 cdbfileformat.pd
24436 \family default 
24437 \series default 
24438 \shape default 
24439 \size default 
24440 \emph default 
24441 \bar default 
24442 \noun default 
24443 \color default
24444 f
24445 \end_inset 
24446 </cell>
24447 </row>
24448 </lyxtabular>
24449
24450 \end_inset 
24451
24452
24453 \newline 
24454
24455 \layout Section
24456
24457 Related open source tools
24458 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24459
24460 \end_inset 
24461
24462
24463 \begin_inset LatexCommand \index{Related tools}
24464
24465 \end_inset 
24466
24467
24468 \layout Standard
24469 \align left 
24470
24471 \begin_inset  Tabular
24472 <lyxtabular version="3" rows="14" columns="3">
24473 <features>
24474 <column alignment="left" valignment="top" leftline="true" width="0pt">
24475 <column alignment="block" valignment="top" leftline="true" width="30line%">
24476 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24477 <row topline="true" bottomline="true">
24478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24479 \begin_inset Text
24480
24481 \layout Standard
24482
24483 Name
24484 \end_inset 
24485 </cell>
24486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24487 \begin_inset Text
24488
24489 \layout Standard
24490
24491 Purpose
24492 \end_inset 
24493 </cell>
24494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24495 \begin_inset Text
24496
24497 \layout Standard
24498
24499 Where to get
24500 \end_inset 
24501 </cell>
24502 </row>
24503 <row topline="true">
24504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24505 \begin_inset Text
24506
24507 \layout Standard
24508
24509 gpsim
24510 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24511
24512 \end_inset 
24513
24514
24515 \end_inset 
24516 </cell>
24517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24518 \begin_inset Text
24519
24520 \layout Standard
24521
24522 PIC simulator
24523 \end_inset 
24524 </cell>
24525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24526 \begin_inset Text
24527
24528 \layout Standard
24529
24530
24531 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24532
24533 \end_inset 
24534
24535
24536 \end_inset 
24537 </cell>
24538 </row>
24539 <row topline="true">
24540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24541 \begin_inset Text
24542
24543 \layout Standard
24544
24545 gputils
24546 \begin_inset LatexCommand \index{gputils (pic tools)}
24547
24548 \end_inset 
24549
24550
24551 \end_inset 
24552 </cell>
24553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24554 \begin_inset Text
24555
24556 \layout Standard
24557
24558 GNU PIC utilities
24559 \end_inset 
24560 </cell>
24561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24562 \begin_inset Text
24563
24564 \layout Standard
24565
24566
24567 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24568
24569 \end_inset 
24570
24571
24572 \end_inset 
24573 </cell>
24574 </row>
24575 <row topline="true">
24576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24577 \begin_inset Text
24578
24579 \layout Standard
24580
24581 flP5
24582 \end_inset 
24583 </cell>
24584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24585 \begin_inset Text
24586
24587 \layout Standard
24588
24589 PIC programmer
24590 \end_inset 
24591 </cell>
24592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24593 \begin_inset Text
24594
24595 \layout Standard
24596
24597
24598 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24599
24600 \end_inset 
24601
24602
24603 \end_inset 
24604 </cell>
24605 </row>
24606 <row topline="true">
24607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24608 \begin_inset Text
24609
24610 \layout Standard
24611
24612 ec2drv/newcdb
24613 \end_inset 
24614 </cell>
24615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24616 \begin_inset Text
24617
24618 \layout Standard
24619
24620 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24621  (Unix only)
24622 \end_inset 
24623 </cell>
24624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24625 \begin_inset Text
24626
24627 \layout Standard
24628
24629
24630 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24631
24632 \end_inset 
24633
24634
24635 \end_inset 
24636 </cell>
24637 </row>
24638 <row topline="true">
24639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24640 \begin_inset Text
24641
24642 \layout Standard
24643
24644 indent
24645 \begin_inset LatexCommand \index{indent (source formatting tool)}
24646
24647 \end_inset 
24648
24649
24650 \end_inset 
24651 </cell>
24652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24653 \begin_inset Text
24654
24655 \layout Standard
24656
24657 Formats C source - Master of the white spaces
24658 \end_inset 
24659 </cell>
24660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24661 \begin_inset Text
24662
24663 \layout Standard
24664
24665
24666 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
24667
24668 \end_inset 
24669
24670
24671 \end_inset 
24672 </cell>
24673 </row>
24674 <row topline="true">
24675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24676 \begin_inset Text
24677
24678 \layout Standard
24679
24680 srecord
24681 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
24682
24683 \end_inset 
24684
24685
24686 \end_inset 
24687 </cell>
24688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24689 \begin_inset Text
24690
24691 \layout Standard
24692
24693 Object file conversion, checksumming, ...
24694 \end_inset 
24695 </cell>
24696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24697 \begin_inset Text
24698
24699 \layout Standard
24700
24701
24702 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
24703
24704 \end_inset 
24705
24706
24707 \end_inset 
24708 </cell>
24709 </row>
24710 <row topline="true">
24711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24712 \begin_inset Text
24713
24714 \layout Standard
24715
24716 objdump
24717 \begin_inset LatexCommand \index{objdump (tool)}
24718
24719 \end_inset 
24720
24721
24722 \end_inset 
24723 </cell>
24724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24725 \begin_inset Text
24726
24727 \layout Standard
24728
24729 Object file conversion, ...
24730 \end_inset 
24731 </cell>
24732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24733 \begin_inset Text
24734
24735 \layout Standard
24736
24737 Part of binutils (should be there anyway)
24738 \end_inset 
24739 </cell>
24740 </row>
24741 <row topline="true">
24742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24743 \begin_inset Text
24744
24745 \layout Standard
24746
24747 cmon51
24748 \end_inset 
24749 </cell>
24750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24751 \begin_inset Text
24752
24753 \layout Standard
24754
24755 8051 monitor (hex up-/download, single step, disassemble)
24756 \end_inset 
24757 </cell>
24758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24759 \begin_inset Text
24760
24761 \layout Standard
24762
24763
24764 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
24765
24766 \end_inset 
24767
24768
24769 \end_inset 
24770 </cell>
24771 </row>
24772 <row topline="true">
24773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24774 \begin_inset Text
24775
24776 \layout Standard
24777
24778 doxygen
24779 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
24780
24781 \end_inset 
24782
24783
24784 \end_inset 
24785 </cell>
24786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24787 \begin_inset Text
24788
24789 \layout Standard
24790
24791 Source code documentation system
24792 \end_inset 
24793 </cell>
24794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24795 \begin_inset Text
24796
24797 \layout Standard
24798
24799
24800 \begin_inset LatexCommand \url{http://www.doxygen.org}
24801
24802 \end_inset 
24803
24804
24805 \end_inset 
24806 </cell>
24807 </row>
24808 <row topline="true">
24809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24810 \begin_inset Text
24811
24812 \layout Standard
24813
24814 kdevelop
24815 \end_inset 
24816 </cell>
24817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24818 \begin_inset Text
24819
24820 \layout Standard
24821
24822 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
24823 \end_inset 
24824 </cell>
24825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24826 \begin_inset Text
24827
24828 \layout Standard
24829
24830
24831 \begin_inset LatexCommand \url{http://www.kdevelop.org}
24832
24833 \end_inset 
24834
24835
24836 \end_inset 
24837 </cell>
24838 </row>
24839 <row topline="true">
24840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24841 \begin_inset Text
24842
24843 \layout Standard
24844
24845 paulmon
24846 \end_inset 
24847 </cell>
24848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24849 \begin_inset Text
24850
24851 \layout Standard
24852
24853 8051 monitor (hex up-/download, single step, disassemble)
24854 \end_inset 
24855 </cell>
24856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24857 \begin_inset Text
24858
24859 \layout Standard
24860
24861
24862 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
24863
24864 \end_inset 
24865
24866
24867 \end_inset 
24868 </cell>
24869 </row>
24870 <row topline="true">
24871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24872 \begin_inset Text
24873
24874 \layout Standard
24875
24876 splint
24877 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24878
24879 \end_inset 
24880
24881
24882 \end_inset 
24883 </cell>
24884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24885 \begin_inset Text
24886
24887 \layout Standard
24888
24889 Statically checks c sources (see 
24890 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24891
24892 \end_inset 
24893
24894 )
24895 \end_inset 
24896 </cell>
24897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24898 \begin_inset Text
24899
24900 \layout Standard
24901
24902
24903 \begin_inset LatexCommand \url{http://www.splint.org}
24904
24905 \end_inset 
24906
24907
24908 \end_inset 
24909 </cell>
24910 </row>
24911 <row topline="true" bottomline="true">
24912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24913 \begin_inset Text
24914
24915 \layout Standard
24916
24917 ddd
24918 \begin_inset LatexCommand \index{DDD (debugger)}
24919
24920 \end_inset 
24921
24922
24923 \end_inset 
24924 </cell>
24925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24926 \begin_inset Text
24927
24928 \layout Standard
24929
24930 Debugger, serves nicely as GUI to SDCDB
24931 \begin_inset LatexCommand \index{SDCDB (debugger)}
24932
24933 \end_inset 
24934
24935  (Unix only)
24936 \end_inset 
24937 </cell>
24938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24939 \begin_inset Text
24940
24941 \layout Standard
24942
24943
24944 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
24945
24946 \end_inset 
24947
24948
24949 \end_inset 
24950 </cell>
24951 </row>
24952 </lyxtabular>
24953
24954 \end_inset 
24955
24956
24957 \newline 
24958
24959 \layout Section
24960
24961 Related documentation / recommended reading
24962 \layout Standard
24963 \align left 
24964
24965 \begin_inset  Tabular
24966 <lyxtabular version="3" rows="7" columns="3">
24967 <features>
24968 <column alignment="left" valignment="top" leftline="true" width="0pt">
24969 <column alignment="center" valignment="top" leftline="true" width="0">
24970 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24971 <row topline="true" bottomline="true">
24972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24973 \begin_inset Text
24974
24975 \layout Standard
24976
24977 Name
24978 \end_inset 
24979 </cell>
24980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24981 \begin_inset Text
24982
24983 \layout Standard
24984
24985 Subject / Title
24986 \end_inset 
24987 </cell>
24988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24989 \begin_inset Text
24990
24991 \layout Standard
24992
24993 Where to get
24994 \end_inset 
24995 </cell>
24996 </row>
24997 <row topline="true">
24998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24999 \begin_inset Text
25000
25001 \layout Standard
25002
25003
25004 \family roman 
25005 \series medium 
25006 \shape up 
25007 \size normal 
25008 \emph off 
25009 \bar no 
25010 \noun off 
25011 \color none
25012 c-refcard.pdf
25013 \end_inset 
25014 </cell>
25015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25016 \begin_inset Text
25017
25018 \layout Standard
25019
25020 C Reference Card
25021 \begin_inset LatexCommand \index{C Reference card}
25022
25023 \end_inset 
25024
25025 , 2 pages
25026 \end_inset 
25027 </cell>
25028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25029 \begin_inset Text
25030
25031 \layout Standard
25032
25033
25034 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
25035
25036 \end_inset 
25037
25038
25039 \end_inset 
25040 </cell>
25041 </row>
25042 <row topline="true">
25043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25044 \begin_inset Text
25045
25046 \layout Standard
25047
25048 c-faq
25049 \end_inset 
25050 </cell>
25051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25052 \begin_inset Text
25053
25054 \layout Standard
25055
25056 C-FAQ
25057 \begin_inset LatexCommand \index{C FAQ}
25058
25059 \end_inset 
25060
25061
25062 \end_inset 
25063 </cell>
25064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25065 \begin_inset Text
25066
25067 \layout Standard
25068
25069
25070 \begin_inset LatexCommand \url{http://www.c-faq.com}
25071
25072 \end_inset 
25073
25074
25075 \end_inset 
25076 </cell>
25077 </row>
25078 <row topline="true">
25079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25080 \begin_inset Text
25081
25082 \layout Standard
25083
25084 ISO/IEC 9899:TC2
25085 \end_inset 
25086 </cell>
25087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25088 \begin_inset Text
25089
25090 \layout Standard
25091
25092
25093 \begin_inset Quotes sld
25094 \end_inset 
25095
25096 C-Standard
25097 \begin_inset Quotes srd
25098 \end_inset 
25099
25100
25101 \end_inset 
25102 </cell>
25103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25104 \begin_inset Text
25105
25106 \layout Standard
25107
25108
25109 \size footnotesize 
25110
25111 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
25112
25113 \end_inset 
25114
25115
25116 \end_inset 
25117 </cell>
25118 </row>
25119 <row topline="true">
25120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25121 \begin_inset Text
25122
25123 \layout Standard
25124
25125 ISO/IEC DTR 18037
25126 \end_inset 
25127 </cell>
25128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25129 \begin_inset Text
25130
25131 \layout Standard
25132
25133
25134 \begin_inset Quotes sld
25135 \end_inset 
25136
25137 Extensions for Embedded C
25138 \begin_inset Quotes srd
25139 \end_inset 
25140
25141
25142 \end_inset 
25143 </cell>
25144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25145 \begin_inset Text
25146
25147 \layout Standard
25148
25149
25150 \size footnotesize 
25151
25152 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
25153
25154 \end_inset 
25155
25156
25157 \end_inset 
25158 </cell>
25159 </row>
25160 <row topline="true">
25161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25162 \begin_inset Text
25163
25164 \layout Standard
25165
25166 \end_inset 
25167 </cell>
25168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25169 \begin_inset Text
25170
25171 \layout Standard
25172
25173 Latest datasheet of target CPU
25174 \end_inset 
25175 </cell>
25176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25177 \begin_inset Text
25178
25179 \layout Standard
25180
25181 vendor
25182 \end_inset 
25183 </cell>
25184 </row>
25185 <row topline="true" bottomline="true">
25186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25187 \begin_inset Text
25188
25189 \layout Standard
25190
25191 \end_inset 
25192 </cell>
25193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25194 \begin_inset Text
25195
25196 \layout Standard
25197
25198 Revision history of datasheet
25199 \end_inset 
25200 </cell>
25201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25202 \begin_inset Text
25203
25204 \layout Standard
25205
25206 vendor
25207 \end_inset 
25208 </cell>
25209 </row>
25210 </lyxtabular>
25211
25212 \end_inset 
25213
25214
25215 \newline 
25216
25217 \layout Section
25218
25219 Application notes specifically for SDCC
25220 \layout Standard
25221
25222 SDCC makes no claims about the completeness of this list and about up-to-datenes
25223 s or correctness of the application notes
25224 \begin_inset LatexCommand \index{Application notes}
25225
25226 \end_inset 
25227
25228 .
25229 \layout Standard
25230 \align left 
25231
25232 \size footnotesize 
25233
25234 \begin_inset  Tabular
25235 <lyxtabular version="3" rows="7" columns="3">
25236 <features>
25237 <column alignment="block" valignment="top" leftline="true" width="17col%">
25238 <column alignment="block" valignment="top" leftline="true" width="27col%">
25239 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
25240 <row topline="true" bottomline="true">
25241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25242 \begin_inset Text
25243
25244 \layout Standard
25245
25246
25247 \size footnotesize 
25248 Vendor
25249 \end_inset 
25250 </cell>
25251 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25252 \begin_inset Text
25253
25254 \layout Standard
25255
25256
25257 \size footnotesize 
25258 Subject / Title
25259 \end_inset 
25260 </cell>
25261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25262 \begin_inset Text
25263
25264 \layout Standard
25265
25266
25267 \size footnotesize 
25268 Where to get
25269 \end_inset 
25270 </cell>
25271 </row>
25272 <row topline="true">
25273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25274 \begin_inset Text
25275
25276 \layout Standard
25277
25278
25279 \size footnotesize 
25280 Maxim / Dallas
25281 \end_inset 
25282 </cell>
25283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25284 \begin_inset Text
25285
25286 \layout Standard
25287
25288
25289 \size footnotesize 
25290 Using the SDCC Compiler for the DS80C400
25291 \begin_inset LatexCommand \index{DS80C400}
25292
25293 \end_inset 
25294
25295
25296 \end_inset 
25297 </cell>
25298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25299 \begin_inset Text
25300
25301 \layout Standard
25302
25303
25304 \size footnotesize 
25305
25306 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25307
25308 \end_inset 
25309
25310
25311 \end_inset 
25312 </cell>
25313 </row>
25314 <row topline="true">
25315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25316 \begin_inset Text
25317
25318 \layout Standard
25319
25320
25321 \size footnotesize 
25322 Maxim / Dallas
25323 \end_inset 
25324 </cell>
25325 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25326 \begin_inset Text
25327
25328 \layout Standard
25329
25330
25331 \size footnotesize 
25332 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25333 \begin_inset LatexCommand \index{DS89C4x0}
25334
25335 \end_inset 
25336
25337  Family of Microcontrollers
25338 \end_inset 
25339 </cell>
25340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25341 \begin_inset Text
25342
25343 \layout Standard
25344
25345
25346 \size footnotesize 
25347
25348 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25349
25350 \end_inset 
25351
25352
25353 \end_inset 
25354 </cell>
25355 </row>
25356 <row topline="true">
25357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25358 \begin_inset Text
25359
25360 \layout Standard
25361
25362
25363 \size footnotesize 
25364 Silicon Laboratories / Cygnal
25365 \end_inset 
25366 </cell>
25367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25368 \begin_inset Text
25369
25370 \layout Standard
25371
25372
25373 \size footnotesize 
25374 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25375 \begin_inset LatexCommand \index{IDE}
25376
25377 \end_inset 
25378
25379
25380 \end_inset 
25381 </cell>
25382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25383 \begin_inset Text
25384
25385 \layout Standard
25386
25387
25388 \size footnotesize 
25389
25390 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
25391
25392 \end_inset 
25393
25394
25395 \end_inset 
25396 </cell>
25397 </row>
25398 <row topline="true">
25399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25400 \begin_inset Text
25401
25402 \layout Standard
25403
25404
25405 \size footnotesize 
25406 Ramtron / Goal Semiconductor
25407 \end_inset 
25408 </cell>
25409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25410 \begin_inset Text
25411
25412 \layout Standard
25413
25414
25415 \size footnotesize 
25416 Interfacing SDCC to Syn and Textpad
25417 \end_inset 
25418 </cell>
25419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25420 \begin_inset Text
25421
25422 \layout Standard
25423
25424
25425 \size footnotesize 
25426
25427 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25428
25429 \end_inset 
25430
25431
25432 \end_inset 
25433 </cell>
25434 </row>
25435 <row topline="true">
25436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25437 \begin_inset Text
25438
25439 \layout Standard
25440
25441
25442 \size footnotesize 
25443 Ramtron / Goal Semiconductor
25444 \end_inset 
25445 </cell>
25446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25447 \begin_inset Text
25448
25449 \layout Standard
25450
25451
25452 \size footnotesize 
25453 Installing and Configuring SDCC and Crimson Editor 
25454 \end_inset 
25455 </cell>
25456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25457 \begin_inset Text
25458
25459 \layout Standard
25460
25461
25462 \size footnotesize 
25463
25464 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25465
25466 \end_inset 
25467
25468
25469 \end_inset 
25470 </cell>
25471 </row>
25472 <row topline="true" bottomline="true">
25473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25474 \begin_inset Text
25475
25476 \layout Standard
25477
25478
25479 \size footnotesize 
25480 Texas Instruments
25481 \end_inset 
25482 </cell>
25483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25484 \begin_inset Text
25485
25486 \layout Standard
25487
25488
25489 \size footnotesize 
25490 MSC12xx Programming with SDCC
25491 \end_inset 
25492 </cell>
25493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25494 \begin_inset Text
25495
25496 \layout Standard
25497
25498
25499 \size footnotesize 
25500
25501 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25502
25503 \end_inset 
25504
25505
25506 \end_inset 
25507 </cell>
25508 </row>
25509 </lyxtabular>
25510
25511 \end_inset 
25512
25513
25514 \layout Section
25515
25516 Some Questions
25517 \layout Standard
25518
25519 Some questions answered, some pointers given - it might be time to in turn
25520  ask 
25521 \emph on 
25522 you
25523 \emph default 
25524  some questions: 
25525 \layout Itemize
25526
25527 can you solve your project with the selected microcontroller? Would you
25528  find out early or rather late that your target is too small/slow/whatever?
25529  Can you switch to a slightly better device if it doesn't fit?
25530 \layout Itemize
25531
25532 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25533  and/or another programming language be more adequate? Would an operating
25534  system on the target device help?
25535 \layout Itemize
25536
25537 if you solved the problem, will the marketing department be happy?
25538 \layout Itemize
25539
25540 if the marketing department is happy, will customers be happy?
25541 \layout Itemize
25542
25543 if you're the project manager, marketing department and maybe even the customer
25544  in one person, have you tried to see the project from the outside?
25545 \layout Itemize
25546
25547 is the project done if you think it is done? Or is just that other interface/pro
25548 tocol/feature/configuration/option missing? How about website, manual(s),
25549  internationali(z|s)ation, packaging, labels, 2nd source for components,
25550  electromagnetic compatability/interference, documentation for production,
25551  production test software, update mechanism, patent issues?
25552 \layout Itemize
25553
25554 is your project adequately positioned in that magic triangle: fame, fortune,
25555  fun?
25556 \layout Standard
25557
25558 Maybe not all answers to these questions are known and some answers may
25559  even be 
25560 \emph on 
25561 no
25562 \emph default 
25563 , nevertheless knowing these questions may help you to avoid burnout
25564 \begin_inset Foot
25565 collapsed false
25566
25567 \layout Standard
25568
25569 burnout is bad for electronic devices, programmers and motorcycle tyres
25570 \end_inset 
25571
25572 .
25573  Chances are you didn't want to hear some of them...
25574 \layout Chapter
25575
25576 Support
25577 \begin_inset LatexCommand \index{Support}
25578
25579 \end_inset 
25580
25581
25582 \layout Standard
25583
25584 SDCC has grown to be a large project.
25585  The compiler alone (without the preprocessor, assembler and linker) is
25586  well over 150,000 lines of code (blank stripped).
25587  The open source nature of this project is a key to its continued growth
25588  and support.
25589  You gain the benefit and support of many active software developers and
25590  end users.
25591  Is SDCC perfect? No, that's why we need your help.
25592  The developers take pride in fixing reported bugs.
25593  You can help by reporting the bugs and helping other SDCC users.
25594  There are lots of ways to contribute, and we encourage you to take part
25595  in making SDCC a great software package.
25596  
25597 \layout Standard
25598
25599 The SDCC project is hosted on the SDCC sourceforge site at 
25600 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25601
25602 \end_inset 
25603
25604 .
25605  You'll find the complete set of mailing lists
25606 \begin_inset LatexCommand \index{Mailing list(s)}
25607
25608 \end_inset 
25609
25610 , forums, bug reporting system, patch submission
25611 \begin_inset LatexCommand \index{Patch submission}
25612
25613 \end_inset 
25614
25615  system, download
25616 \begin_inset LatexCommand \index{download}
25617
25618 \end_inset 
25619
25620  area and Subversion code repository
25621 \begin_inset LatexCommand \index{Subversion code repository}
25622
25623 \end_inset 
25624
25625  there.
25626 \layout Section
25627
25628 Reporting Bugs
25629 \begin_inset LatexCommand \index{Bug reporting}
25630
25631 \end_inset 
25632
25633
25634 \begin_inset LatexCommand \index{Reporting bugs}
25635
25636 \end_inset 
25637
25638
25639 \layout Standard
25640
25641 The recommended way of reporting bugs is using the infrastructure of the
25642  sourceforge site.
25643  You can follow the status of bug reports there and have an overview about
25644  the known bugs.
25645 \layout Standard
25646
25647 Bug reports are automatically forwarded to the developer mailing list and
25648  will be fixed ASAP.
25649  When reporting a bug, it is very useful to include a small test program
25650  (the smaller the better) which reproduces the problem.
25651  If you can isolate the problem by looking at the generated assembly code,
25652  this can be very helpful.
25653  Compiling your program with the -
25654 \begin_inset ERT
25655 status Collapsed
25656
25657 \layout Standard
25658
25659 \backslash 
25660 /
25661 \end_inset 
25662
25663 -dumpall
25664 \begin_inset LatexCommand \index{-\/-dumpall}
25665
25666 \end_inset 
25667
25668  option can sometimes be useful in locating optimization problems.
25669  When reporting a bug please make sure you:
25670 \layout Enumerate
25671
25672 Attach the code you are compiling with SDCC.
25673  
25674 \layout Enumerate
25675
25676 Specify the exact command you use to run SDCC, or attach your Makefile.
25677  
25678 \layout Enumerate
25679
25680 Specify the SDCC version (type "
25681 \family sans 
25682 \series bold 
25683 sdcc -v
25684 \family default 
25685 \series default 
25686 "), your platform, and operating system.
25687  
25688 \layout Enumerate
25689
25690 Provide an exact copy of any error message or incorrect output.
25691  
25692 \layout Enumerate
25693
25694 Put something meaningful in the subject of your message.
25695 \layout Standard
25696
25697 Please attempt to include these 5 important parts, as applicable, in all
25698  requests for support or when reporting any problems or bugs with SDCC.
25699  Though this will make your message lengthy, it will greatly improve your
25700  chance that SDCC users and developers will be able to help you.
25701  Some SDCC developers are frustrated by bug reports without code provided
25702  that they can use to reproduce and ultimately fix the problem, so please
25703  be sure to provide sample code if you are reporting a bug! 
25704 \layout Standard
25705
25706 Please have a short check that you are using a recent version of SDCC and
25707  the bug is not yet known.
25708  This is the link for reporting bugs: 
25709 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
25710
25711 \end_inset 
25712
25713 .
25714  With SDCC on average having more than 200 downloads
25715 \begin_inset LatexCommand \index{download}
25716
25717 \end_inset 
25718
25719  on sourceforge per day
25720 \begin_inset Foot
25721 collapsed false
25722
25723 \layout Standard
25724
25725 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
25726  between 2002 and 2005.
25727  This does not include other methods of distribution.
25728 \end_inset 
25729
25730  there must be some users.
25731  So it's not exactly easy to find a new bug.
25732  If you find one we need it: 
25733 \emph on 
25734 reporting bugs is good
25735 \emph default 
25736 .
25737 \layout Section
25738
25739 Requesting Features
25740 \begin_inset LatexCommand \label{sub:Requesting-Features}
25741
25742 \end_inset 
25743
25744
25745 \begin_inset LatexCommand \index{Feature request}
25746
25747 \end_inset 
25748
25749
25750 \begin_inset LatexCommand \index{Requesting features}
25751
25752 \end_inset 
25753
25754
25755 \layout Standard
25756
25757 Like bug reports feature requests are forwarded to the developer mailing
25758  list.
25759  This is the link for requesting features: 
25760 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
25761
25762 \end_inset 
25763
25764 .
25765 \layout Section
25766
25767 Submitting patches
25768 \layout Standard
25769
25770 Like bug reports contributed patches are forwarded to the developer mailing
25771  list.
25772  This is the link for submitting patches
25773 \begin_inset LatexCommand \index{Patch submission}
25774
25775 \end_inset 
25776
25777
25778 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
25779
25780 \end_inset 
25781
25782 .
25783 \layout Standard
25784
25785 You need to specify some parameters to the 
25786 \family typewriter 
25787 diff
25788 \family default 
25789  command for the patches to be useful.
25790  If you modified more than one file a patch created f.e.
25791  with 
25792 \family sans 
25793 \series bold 
25794
25795 \begin_inset Quotes sld
25796 \end_inset 
25797
25798 diff -Naur unmodified_directory modified_directory >my_changes.patch
25799 \begin_inset Quotes srd
25800 \end_inset 
25801
25802
25803 \family default 
25804 \series default 
25805  will be fine, otherwise 
25806 \family sans 
25807 \series bold 
25808
25809 \begin_inset Quotes sld
25810 \end_inset 
25811
25812 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
25813 \begin_inset Quotes srd
25814 \end_inset 
25815
25816
25817 \series default 
25818  
25819 \family default 
25820 will do.
25821 \layout Section
25822
25823 Getting Help
25824 \layout Standard
25825
25826 These links should take you directly to the 
25827 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
25828
25829 \end_inset 
25830
25831
25832 \begin_inset Foot
25833 collapsed false
25834
25835 \layout Standard
25836
25837 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
25838  automated messages (mid 2003)
25839 \end_inset 
25840
25841  and the 
25842 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
25843
25844 \end_inset 
25845
25846 , lists
25847 \begin_inset LatexCommand \index{Mailing list(s)}
25848
25849 \end_inset 
25850
25851  and forums are archived and searchable so if you are lucky someone already
25852  had a similar problem.
25853  While mails to the lists themselves are delivered promptly their web front
25854  end on sourceforge sometimes shows a severe time lag (up to several weeks),
25855  if you're seriously using SDCC please consider subscribing to the lists.
25856 \layout Section
25857
25858 ChangeLog
25859 \layout Standard
25860
25861 You can follow the status of the Subversion version
25862 \begin_inset LatexCommand \index{version}
25863
25864 \end_inset 
25865
25866  of SDCC by watching the Changelog
25867 \begin_inset LatexCommand \index{Changelog}
25868
25869 \end_inset 
25870
25871  in the Subversion repository
25872 \size footnotesize 
25873  
25874 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
25875
25876 \end_inset 
25877
25878 .
25879 \layout Section
25880
25881 Subversion Source Code Repository
25882 \layout Standard
25883
25884 The output of 
25885 \family sans 
25886 \series bold 
25887 sdcc --version
25888 \family default 
25889 \series default 
25890  or the filenames of the snapshot versions of SDCC include date and its
25891  Subversion
25892 \begin_inset LatexCommand \index{Subversion code repository}
25893
25894 \end_inset 
25895
25896  number.
25897  Subversion allows to download the source of recent or previous versions
25898  
25899 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
25900
25901 \end_inset 
25902
25903  (by number or by date).
25904  An on-line source code browser and detailled instructions are also available
25905  there.
25906  SDCC versions starting from 1999 up to now are available (currently the
25907  versions prior to the conversion from cvs
25908 \begin_inset LatexCommand \index{cvs|see{Subversion}}
25909
25910 \end_inset 
25911
25912  to Subversion (April 2006) are either by accessible by Subversion or by
25913  cvs).
25914 \layout Section
25915
25916 Release policy
25917 \begin_inset LatexCommand \index{Release policy}
25918
25919 \end_inset 
25920
25921
25922 \layout Standard
25923
25924 Historically there often were long delays between official releases and
25925  the sourceforge download area tends to get not updated at all.
25926  Excuses in the past might have referred to problems with live range analysis,
25927  but as this was fixed a while ago, the current problem is that another
25928  excuse has to be found.
25929  Kidding aside, we have to get better there! On the other hand there are
25930  daily snapshots available at 
25931 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
25932
25933 \end_inset 
25934
25935 , and you can always build the very last version (hopefully with many bugs
25936  fixed, and features added) from the source code available at 
25937 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
25938
25939 \end_inset 
25940
25941 .
25942 \layout Section
25943
25944 Examples
25945 \begin_inset LatexCommand \index{Examples}
25946
25947 \end_inset 
25948
25949
25950 \layout Standard
25951
25952 You'll find some small examples in the directory 
25953 \emph on 
25954 sdcc/device/examples/.
25955  
25956 \emph default 
25957 More examples and libraries are available at
25958 \emph on 
25959  The SDCC Open Knowledge Resource 
25960 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
25961
25962 \end_inset 
25963
25964  
25965 \emph default 
25966 web site or at 
25967 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
25968
25969 \end_inset 
25970
25971 .
25972 \layout Comment
25973
25974 I did insert a reference to Paul's web site here although it seems rather
25975  dedicated to a specific 8032 board (I think it's okay because it f.e.
25976  shows LCD/Harddisc interface and has a free 8051 monitor.
25977  Independent 8032 board vendors face hard competition of heavily subsidized
25978  development boards anyway).
25979 \layout Comment
25980
25981 Maybe we should include some links to real world applications.
25982  Preferably pointer to pointers (one for each architecture) so this stays
25983  manageable here?
25984 \layout Section
25985
25986 Quality control
25987 \begin_inset LatexCommand \label{sec:Quality-control}
25988
25989 \end_inset 
25990
25991
25992 \begin_inset LatexCommand \index{Quality control}
25993
25994 \end_inset 
25995
25996
25997 \layout Standard
25998
25999 The compiler is passed through nightly compile and build checks.
26000  The so called 
26001 \shape italic 
26002 regression tests
26003 \shape default 
26004
26005 \begin_inset LatexCommand \index{Regression test}
26006
26007 \end_inset 
26008
26009  check that SDCC itself compiles flawlessly on several host platforms (i386,
26010  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
26011  the quality of the code generated by SDCC by running the code for several
26012  target platforms through simulators.
26013  The regression test suite comprises more than 100 files which expand to
26014  more than 500 test cases which include more than 4500 tests.
26015  The results of these tests are published daily on SDCC's snapshot page
26016  (click on the red or green symbols on the right side of 
26017 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
26018
26019 \end_inset 
26020
26021 ).
26022 \layout Standard
26023
26024 There is a separate document 
26025 \shape italic 
26026 test_suite.pdf 
26027 \begin_inset LatexCommand \index{Test suite}
26028
26029 \end_inset 
26030
26031
26032 \shape default 
26033  
26034 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26035
26036 \end_inset 
26037
26038  about the regression test suite.
26039 \layout Standard
26040
26041 You'll find the test code in the directory 
26042 \shape italic 
26043 sdcc/support/regression
26044 \shape default 
26045 .
26046  You can run these tests manually by running 
26047 \family sans 
26048 make
26049 \family default 
26050  in this directory (or f.e.
26051  
26052 \family sans 
26053 \series bold 
26054
26055 \begin_inset Quotes sld
26056 \end_inset 
26057
26058 make test-mcs51
26059 \begin_inset Quotes srd
26060 \end_inset 
26061
26062
26063 \family default 
26064 \series default 
26065  if you don't want to run the complete tests).
26066  The test code might also be interesting if you want to look for examples
26067 \begin_inset LatexCommand \index{Examples}
26068
26069 \end_inset 
26070
26071  checking corner cases of SDCC or if you plan to submit patches
26072 \begin_inset LatexCommand \index{Patch submission}
26073
26074 \end_inset 
26075
26076 .
26077 \layout Standard
26078
26079 The 14bit pic port uses a different set of regression tests 
26080 \begin_inset LatexCommand \index{Regression test (PIC14)}
26081
26082 \end_inset 
26083
26084 , you'll find them in the directory 
26085 \shape italic 
26086 sdcc/src/regression
26087 \shape default 
26088 .
26089 \layout Section
26090
26091 Use of SDCC in Education
26092 \layout Standard
26093
26094 In short: 
26095 \emph on 
26096 highly
26097 \emph default 
26098  encouraged
26099 \begin_inset Foot
26100 collapsed false
26101
26102 \layout Standard
26103
26104 the phrase "use in education" might evoke the association "
26105 \emph on 
26106 only
26107 \emph default 
26108  fit for use in education".
26109  This connotation is not intended but nevertheless risked as the licensing
26110  of SDCC makes it difficult to offer educational discounts
26111 \end_inset 
26112
26113 .
26114  If your rationales are to:
26115 \layout Enumerate
26116
26117 give students a chance to understand the 
26118 \emph on 
26119 complete
26120 \emph default 
26121  steps of code generation
26122 \layout Enumerate
26123
26124 have a curriculum that can be extended for years.
26125  Then you could use an fpga board as target and your curriculum will seamlessly
26126  extend from logic synthesis (
26127 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
26128
26129 \end_inset 
26130
26131
26132 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
26133
26134 \end_inset 
26135
26136 ), over assembly programming, to C to FPGA compilers (
26137 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
26138
26139 \end_inset 
26140
26141 ) and to C.
26142 \layout Enumerate
26143
26144 be able to insert excursions about skills like using a revision control
26145  system, submitting/applying patches, using a type-setting (as opposed to
26146  word-processing) engine LyX/LaTeX, using 
26147 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
26148
26149 \end_inset 
26150
26151 , following some 
26152 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
26153
26154 \end_inset 
26155
26156 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
26157  Source Software, CPU simulation, compiler regression tests
26158 \begin_inset LatexCommand \index{Regression test}
26159
26160 \end_inset 
26161
26162 .
26163  
26164 \newline 
26165 And if there should be a shortage of ideas then you can always point students
26166  to the ever-growing feature request list 
26167 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26168
26169 \end_inset 
26170
26171 .
26172 \layout Enumerate
26173
26174 not tie students to a specific host platform and instead allow them to use
26175  a host platform of 
26176 \emph on 
26177 their
26178 \emph default 
26179  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
26180  eventually 
26181 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
26182
26183 \end_inset 
26184
26185 )
26186 \layout Enumerate
26187
26188 not encourage students to use illegal copies of educational software
26189 \layout Enumerate
26190
26191 be immune to licensing/availability/price changes of the chosen tool chain
26192 \layout Enumerate
26193
26194 be able to change to a new target platform without having to adopt a new
26195  tool chain
26196 \layout Enumerate
26197
26198 have complete control over and insight into the tool chain
26199 \layout Enumerate
26200
26201 make your students aware about the pros and cons of open source software
26202  development
26203 \layout Enumerate
26204
26205 give back to the public as you are probably at least partially publically
26206  funded
26207 \layout Enumerate
26208
26209 give students a chance to publically prove their skills and to possibly
26210  see a world wide impact
26211 \layout Standard
26212
26213 then SDCC is probably among the first choices.
26214  Well, probably SDCC might be the only choice.
26215 \layout Chapter
26216 \pagebreak_top 
26217 SDCC Technical Data
26218 \layout Section
26219
26220 Optimizations
26221 \begin_inset LatexCommand \index{Optimizations}
26222
26223 \end_inset 
26224
26225
26226 \layout Standard
26227
26228 SDCC performs a host of standard optimizations in addition to some MCU specific
26229  optimizations.
26230  
26231 \layout Subsection
26232
26233 Sub-expression Elimination
26234 \begin_inset LatexCommand \index{Subexpression elimination}
26235
26236 \end_inset 
26237
26238
26239 \layout Standard
26240
26241 The compiler does local and 
26242 \emph on 
26243 g
26244 \emph default 
26245 lobal 
26246 \emph on 
26247 c
26248 \emph default 
26249 ommon 
26250 \emph on 
26251 s
26252 \emph default 
26253 ubexpression 
26254 \emph on 
26255 e
26256 \emph default 
26257 limination, e.g.: 
26258 \layout Verse
26259
26260
26261 \family typewriter 
26262 i = x + y + 1; 
26263 \newline 
26264 j = x + y;
26265 \layout Standard
26266
26267 will be translated to
26268 \layout Verse
26269
26270
26271 \family typewriter 
26272 iTemp = x + y; 
26273 \newline 
26274 i = iTemp + 1; 
26275 \newline 
26276 j = iTemp;
26277 \layout Standard
26278
26279 Some subexpressions are not as obvious as the above example, e.g.:
26280 \layout Verse
26281
26282
26283 \family typewriter 
26284 a->b[i].c = 10; 
26285 \newline 
26286 a->b[i].d = 11;
26287 \layout Standard
26288
26289 In this case the address arithmetic a->b[i] will be computed only once;
26290  the equivalent code in C would be.
26291 \layout Verse
26292
26293
26294 \family typewriter 
26295 iTemp = a->b[i]; 
26296 \newline 
26297 iTemp.c = 10; 
26298 \newline 
26299 iTemp.d = 11;
26300 \layout Standard
26301
26302 The compiler will try to keep these temporary variables in registers.
26303 \layout Subsection
26304
26305 Dead-Code Elimination
26306 \begin_inset LatexCommand \index{Dead-code elimination}
26307
26308 \end_inset 
26309
26310
26311 \layout Verse
26312
26313
26314 \family typewriter 
26315 int global;
26316 \newline 
26317
26318 \newline 
26319 void f () { 
26320 \newline 
26321 \SpecialChar ~
26322 \SpecialChar ~
26323 int i; 
26324 \newline 
26325 \SpecialChar ~
26326 \SpecialChar ~
26327 i = 1; \SpecialChar ~
26328 \SpecialChar ~
26329 \SpecialChar ~
26330 \SpecialChar ~
26331 \SpecialChar ~
26332 /* dead store */ 
26333 \newline 
26334 \SpecialChar ~
26335 \SpecialChar ~
26336 global = 1;\SpecialChar ~
26337 /* dead store */ 
26338 \newline 
26339 \SpecialChar ~
26340 \SpecialChar ~
26341 global = 2; 
26342 \newline 
26343 \SpecialChar ~
26344 \SpecialChar ~
26345 return; 
26346 \newline 
26347 \SpecialChar ~
26348 \SpecialChar ~
26349 global = 3;\SpecialChar ~
26350 /* unreachable */ 
26351 \newline 
26352 }
26353 \layout Standard
26354
26355 will be changed to
26356 \layout Verse
26357
26358
26359 \family typewriter 
26360 int global;
26361 \newline 
26362
26363 \newline 
26364 void f () {
26365 \newline 
26366 \SpecialChar ~
26367 \SpecialChar ~
26368 global = 2; 
26369 \newline 
26370 }
26371 \layout Subsection
26372
26373 Copy-Propagation
26374 \begin_inset LatexCommand \index{Copy propagation}
26375
26376 \end_inset 
26377
26378
26379 \layout Verse
26380
26381
26382 \family typewriter 
26383 int f() { 
26384 \newline 
26385 \SpecialChar ~
26386 \SpecialChar ~
26387 int i, j; 
26388 \newline 
26389 \SpecialChar ~
26390 \SpecialChar ~
26391 i = 10; 
26392 \newline 
26393 \SpecialChar ~
26394 \SpecialChar ~
26395 j = i; 
26396 \newline 
26397 \SpecialChar ~
26398 \SpecialChar ~
26399 return j; 
26400 \newline 
26401 }
26402 \layout Standard
26403
26404 will be changed to 
26405 \layout Verse
26406
26407
26408 \family typewriter 
26409 int f() { 
26410 \newline 
26411 \SpecialChar ~
26412 \SpecialChar ~
26413 int i, j; 
26414 \newline 
26415 \SpecialChar ~
26416 \SpecialChar ~
26417 i = 10; 
26418 \newline 
26419 \SpecialChar ~
26420 \SpecialChar ~
26421 j = 10; 
26422 \newline 
26423 \SpecialChar ~
26424 \SpecialChar ~
26425 return 10; 
26426 \newline 
26427 }
26428 \layout Standard
26429
26430 Note: the dead stores created by this copy propagation will be eliminated
26431  by dead-code elimination.
26432 \layout Subsection
26433
26434 Loop Optimizations
26435 \begin_inset LatexCommand \index{Loop optimization}
26436
26437 \end_inset 
26438
26439
26440 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26441
26442 \end_inset 
26443
26444
26445 \layout Standard
26446
26447 Two types of loop optimizations are done by SDCC 
26448 \emph on 
26449 loop invariant
26450 \emph default 
26451  lifting and
26452 \emph on 
26453  strength reduction
26454 \emph default 
26455  of loop induction variables.
26456  In addition to the strength reduction the optimizer marks the induction
26457  variables and the register allocator tries to keep the induction variables
26458  in registers for the duration of the loop.
26459  Because of this preference of the register allocator
26460 \begin_inset LatexCommand \index{Register allocation}
26461
26462 \end_inset 
26463
26464 , loop induction optimization causes an increase in register pressure, which
26465  may cause unwanted spilling of other temporary variables into the stack
26466 \begin_inset LatexCommand \index{stack}
26467
26468 \end_inset 
26469
26470  / data space.
26471  The compiler will generate a warning message when it is forced to allocate
26472  extra space either on the stack or data space.
26473  If this extra space allocation is undesirable then induction optimization
26474  can be eliminated either for the entire source file (with -
26475 \begin_inset ERT
26476 status Collapsed
26477
26478 \layout Standard
26479
26480 \backslash 
26481 /
26482 \end_inset 
26483
26484 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26485 noinduction
26486 \begin_inset LatexCommand \index{\#pragma noinduction}
26487
26488 \end_inset 
26489
26490 .
26491 \newline 
26492
26493 \newline 
26494 Loop Invariant:
26495 \layout Verse
26496
26497
26498 \family typewriter 
26499 for (i = 0 ; i < 100 ; i ++) 
26500 \newline 
26501 \SpecialChar ~
26502 \SpecialChar ~
26503 \SpecialChar ~
26504 \SpecialChar ~
26505 f += k + l;
26506 \layout Standard
26507
26508 changed to
26509 \layout Verse
26510
26511
26512 \family typewriter 
26513 itemp = k + l; 
26514 \newline 
26515 for (i = 0; i < 100; i++) 
26516 \newline 
26517 \SpecialChar ~
26518 \SpecialChar ~
26519 \SpecialChar ~
26520 \SpecialChar ~
26521 f += itemp;
26522 \layout Standard
26523
26524 As mentioned previously some loop invariants are not as apparent, all static
26525  address computations are also moved out of the loop.
26526 \newline 
26527
26528 \newline 
26529 Strength Reduction
26530 \begin_inset LatexCommand \index{Strength reduction}
26531
26532 \end_inset 
26533
26534 , this optimization substitutes an expression by a cheaper expression:
26535 \layout Verse
26536
26537
26538 \family typewriter 
26539 for (i=0;i < 100; i++)
26540 \newline 
26541 \SpecialChar ~
26542 \SpecialChar ~
26543 \SpecialChar ~
26544 \SpecialChar ~
26545 ar[i*5] = i*3;
26546 \layout Standard
26547
26548 changed to
26549 \layout Verse
26550
26551
26552 \family typewriter 
26553 itemp1 = 0; 
26554 \newline 
26555 itemp2 = 0; 
26556 \newline 
26557 for (i=0;i< 100;i++) { 
26558 \newline 
26559 \SpecialChar ~
26560 \SpecialChar ~
26561 \SpecialChar ~
26562 \SpecialChar ~
26563 ar[itemp1] = itemp2; 
26564 \newline 
26565 \SpecialChar ~
26566 \SpecialChar ~
26567 \SpecialChar ~
26568 \SpecialChar ~
26569 itemp1 += 5; 
26570 \newline 
26571 \SpecialChar ~
26572 \SpecialChar ~
26573 \SpecialChar ~
26574 \SpecialChar ~
26575 itemp2 += 3; 
26576 \newline 
26577 }
26578 \layout Standard
26579
26580 The more expensive multiplication
26581 \begin_inset LatexCommand \index{Multiplication}
26582
26583 \end_inset 
26584
26585  is changed to a less expensive addition.
26586 \layout Subsection
26587
26588 Loop Reversing
26589 \begin_inset LatexCommand \index{Loop reversing}
26590
26591 \end_inset 
26592
26593
26594 \layout Standard
26595
26596 This optimization is done to reduce the overhead of checking loop boundaries
26597  for every iteration.
26598  Some simple loops can be reversed and implemented using a 
26599 \begin_inset Quotes eld
26600 \end_inset 
26601
26602 decrement and jump if not zero
26603 \begin_inset Quotes erd
26604 \end_inset 
26605
26606  instruction.
26607  SDCC checks for the following criterion to determine if a loop is reversible
26608  (note: more sophisticated compilers use data-dependency analysis to make
26609  this determination, SDCC uses a more simple minded analysis).
26610 \layout Itemize
26611
26612 The 'for' loop is of the form 
26613 \newline 
26614
26615 \newline 
26616
26617 \family typewriter 
26618 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
26619  += 1])
26620 \newline 
26621 \SpecialChar ~
26622 \SpecialChar ~
26623 \SpecialChar ~
26624 \SpecialChar ~
26625 <for body>
26626 \layout Itemize
26627
26628 The <for body> does not contain 
26629 \begin_inset Quotes eld
26630 \end_inset 
26631
26632 continue
26633 \begin_inset Quotes erd
26634 \end_inset 
26635
26636  or 'break
26637 \begin_inset Quotes erd
26638 \end_inset 
26639
26640 .
26641 \layout Itemize
26642
26643 All goto's are contained within the loop.
26644 \layout Itemize
26645
26646 No function calls within the loop.
26647 \layout Itemize
26648
26649 The loop control variable <sym> is not assigned any value within the loop
26650 \layout Itemize
26651
26652 The loop control variable does NOT participate in any arithmetic operation
26653  within the loop.
26654 \layout Itemize
26655
26656 There are NO switch statements in the loop.
26657 \layout Subsection
26658
26659 Algebraic Simplifications
26660 \layout Standard
26661
26662 SDCC does numerous algebraic simplifications, the following is a small sub-set
26663  of these optimizations.
26664 \layout Verse
26665
26666
26667 \family typewriter 
26668 i = j + 0;\SpecialChar ~
26669 \SpecialChar ~
26670 \SpecialChar ~
26671 \SpecialChar ~
26672  /* changed to: */\SpecialChar ~
26673 \SpecialChar ~
26674 \SpecialChar ~
26675 \SpecialChar ~
26676  i = j; 
26677 \newline 
26678 i /= 2;\SpecialChar ~
26679 \SpecialChar ~
26680 \SpecialChar ~
26681 \SpecialChar ~
26682 \SpecialChar ~
26683 \SpecialChar ~
26684 \SpecialChar ~
26685  /* changed to: */\SpecialChar ~
26686 \SpecialChar ~
26687 \SpecialChar ~
26688 \SpecialChar ~
26689  i >>= 1; 
26690 \newline 
26691 i = j - j;\SpecialChar ~
26692 \SpecialChar ~
26693 \SpecialChar ~
26694 \SpecialChar ~
26695  /* changed to: */\SpecialChar ~
26696 \SpecialChar ~
26697 \SpecialChar ~
26698 \SpecialChar ~
26699  i = 0; 
26700 \newline 
26701 i = j / 1;\SpecialChar ~
26702 \SpecialChar ~
26703 \SpecialChar ~
26704 \SpecialChar ~
26705  /* changed to: */\SpecialChar ~
26706 \SpecialChar ~
26707 \SpecialChar ~
26708 \SpecialChar ~
26709  i = j;
26710 \layout Standard
26711
26712 Note the subexpressions
26713 \begin_inset LatexCommand \index{Subexpression}
26714
26715 \end_inset 
26716
26717  given above are generally introduced by macro expansions or as a result
26718  of copy/constant propagation.
26719 \layout Subsection
26720
26721 'switch' Statements
26722 \begin_inset LatexCommand \label{sub:'switch'-Statements}
26723
26724 \end_inset 
26725
26726
26727 \begin_inset LatexCommand \index{switch statement}
26728
26729 \end_inset 
26730
26731
26732 \layout Standard
26733
26734 SDCC can optimize switch statements to jump tables
26735 \begin_inset LatexCommand \index{jump tables}
26736
26737 \end_inset 
26738
26739 .
26740  It makes the decision based on an estimate of the generated code size.
26741  SDCC is quite liberal in the requirements for jump table generation: 
26742 \layout Itemize
26743
26744 The labels need not be in order, and the starting number need not be one
26745  or zero, the case labels are in numerical sequence or not too many case
26746  labels are missing.
26747 \begin_deeper 
26748 \layout Verse
26749
26750
26751 \family typewriter 
26752 switch(i) {\SpecialChar ~
26753 \SpecialChar ~
26754 \SpecialChar ~
26755 \SpecialChar ~
26756 \SpecialChar ~
26757 \SpecialChar ~
26758 \SpecialChar ~
26759 \SpecialChar ~
26760 \SpecialChar ~
26761 \SpecialChar ~
26762 \SpecialChar ~
26763 \SpecialChar ~
26764 \SpecialChar ~
26765 \SpecialChar ~
26766 \SpecialChar ~
26767 \SpecialChar ~
26768 \SpecialChar ~
26769 \SpecialChar ~
26770 \SpecialChar ~
26771 \SpecialChar ~
26772 \SpecialChar ~
26773 \SpecialChar ~
26774 \SpecialChar ~
26775 \SpecialChar ~
26776 \SpecialChar ~
26777 \SpecialChar ~
26778 switch (i) { 
26779 \newline 
26780 \SpecialChar ~
26781 \SpecialChar ~
26782 \SpecialChar ~
26783 case 4: ...\SpecialChar ~
26784 \SpecialChar ~
26785 \SpecialChar ~
26786 \SpecialChar ~
26787 \SpecialChar ~
26788 \SpecialChar ~
26789 \SpecialChar ~
26790 \SpecialChar ~
26791 \SpecialChar ~
26792 \SpecialChar ~
26793 \SpecialChar ~
26794 \SpecialChar ~
26795 \SpecialChar ~
26796 \SpecialChar ~
26797 \SpecialChar ~
26798 \SpecialChar ~
26799 \SpecialChar ~
26800 \SpecialChar ~
26801 \SpecialChar ~
26802 \SpecialChar ~
26803 \SpecialChar ~
26804 \SpecialChar ~
26805 \SpecialChar ~
26806 \SpecialChar ~
26807 \SpecialChar ~
26808 \SpecialChar ~
26809 case 0: ...
26810  
26811 \newline 
26812 \SpecialChar ~
26813 \SpecialChar ~
26814 \SpecialChar ~
26815 case 5: ...\SpecialChar ~
26816 \SpecialChar ~
26817 \SpecialChar ~
26818 \SpecialChar ~
26819 \SpecialChar ~
26820 \SpecialChar ~
26821 \SpecialChar ~
26822 \SpecialChar ~
26823 \SpecialChar ~
26824 \SpecialChar ~
26825 \SpecialChar ~
26826 \SpecialChar ~
26827 \SpecialChar ~
26828 \SpecialChar ~
26829 \SpecialChar ~
26830 \SpecialChar ~
26831 \SpecialChar ~
26832 \SpecialChar ~
26833 \SpecialChar ~
26834 \SpecialChar ~
26835 \SpecialChar ~
26836 \SpecialChar ~
26837 \SpecialChar ~
26838 \SpecialChar ~
26839 \SpecialChar ~
26840 \SpecialChar ~
26841 case 1: ...
26842  
26843 \newline 
26844 \SpecialChar ~
26845 \SpecialChar ~
26846 \SpecialChar ~
26847 case 3: ...\SpecialChar ~
26848 \SpecialChar ~
26849 \SpecialChar ~
26850 \SpecialChar ~
26851 \SpecialChar ~
26852 \SpecialChar ~
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
26874 \newline 
26875 \SpecialChar ~
26876 \SpecialChar ~
26877 \SpecialChar ~
26878 case 6: ...\SpecialChar ~
26879 \SpecialChar ~
26880 \SpecialChar ~
26881 \SpecialChar ~
26882 \SpecialChar ~
26883 \SpecialChar ~
26884 \SpecialChar ~
26885 \SpecialChar ~
26886 \SpecialChar ~
26887 \SpecialChar ~
26888 \SpecialChar ~
26889 \SpecialChar ~
26890 \SpecialChar ~
26891 \SpecialChar ~
26892 \SpecialChar ~
26893 \SpecialChar ~
26894 \SpecialChar ~
26895 \SpecialChar ~
26896 \SpecialChar ~
26897 \SpecialChar ~
26898 \SpecialChar ~
26899 \SpecialChar ~
26900 \SpecialChar ~
26901 \SpecialChar ~
26902 \SpecialChar ~
26903 \SpecialChar ~
26904 case 3: ...
26905  
26906 \newline 
26907 \SpecialChar ~
26908 \SpecialChar ~
26909 \SpecialChar ~
26910 case 7: ...\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 \SpecialChar ~
26927 \SpecialChar ~
26928 \SpecialChar ~
26929 \SpecialChar ~
26930 \SpecialChar ~
26931 \SpecialChar ~
26932 \SpecialChar ~
26933 \SpecialChar ~
26934 \SpecialChar ~
26935 \SpecialChar ~
26936 case 4: ...
26937  
26938 \newline 
26939 \SpecialChar ~
26940 \SpecialChar ~
26941 \SpecialChar ~
26942 case 8: ...\SpecialChar ~
26943 \SpecialChar ~
26944 \SpecialChar ~
26945 \SpecialChar ~
26946 \SpecialChar ~
26947 \SpecialChar ~
26948 \SpecialChar ~
26949 \SpecialChar ~
26950 \SpecialChar ~
26951 \SpecialChar ~
26952 \SpecialChar ~
26953 \SpecialChar ~
26954 \SpecialChar ~
26955 \SpecialChar ~
26956 \SpecialChar ~
26957 \SpecialChar ~
26958 \SpecialChar ~
26959 \SpecialChar ~
26960 \SpecialChar ~
26961 \SpecialChar ~
26962 \SpecialChar ~
26963 \SpecialChar ~
26964 \SpecialChar ~
26965 \SpecialChar ~
26966 \SpecialChar ~
26967 \SpecialChar ~
26968 case 5: ...
26969  
26970 \newline 
26971 \SpecialChar ~
26972 \SpecialChar ~
26973 \SpecialChar ~
26974 case 9: ...\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 \SpecialChar ~
26991 \SpecialChar ~
26992 \SpecialChar ~
26993 \SpecialChar ~
26994 \SpecialChar ~
26995 \SpecialChar ~
26996 \SpecialChar ~
26997 \SpecialChar ~
26998 \SpecialChar ~
26999 \SpecialChar ~
27000 case 6: ...
27001  
27002 \newline 
27003 \SpecialChar ~
27004 \SpecialChar ~
27005 \SpecialChar ~
27006 case 10: ...\SpecialChar ~
27007 \SpecialChar ~
27008 \SpecialChar ~
27009 \SpecialChar ~
27010 \SpecialChar ~
27011 \SpecialChar ~
27012 \SpecialChar ~
27013 \SpecialChar ~
27014 \SpecialChar ~
27015 \SpecialChar ~
27016 \SpecialChar ~
27017 \SpecialChar ~
27018 \SpecialChar ~
27019 \SpecialChar ~
27020 \SpecialChar ~
27021 \SpecialChar ~
27022 \SpecialChar ~
27023 \SpecialChar ~
27024 \SpecialChar ~
27025 \SpecialChar ~
27026 \SpecialChar ~
27027 \SpecialChar ~
27028 \SpecialChar ~
27029 \SpecialChar ~
27030 \SpecialChar ~
27031 case 7: ...
27032  
27033 \newline 
27034 \SpecialChar ~
27035 \SpecialChar ~
27036 \SpecialChar ~
27037 case 11: ...\SpecialChar ~
27038 \SpecialChar ~
27039 \SpecialChar ~
27040 \SpecialChar ~
27041 \SpecialChar ~
27042 \SpecialChar ~
27043 \SpecialChar ~
27044 \SpecialChar ~
27045 \SpecialChar ~
27046 \SpecialChar ~
27047 \SpecialChar ~
27048 \SpecialChar ~
27049 \SpecialChar ~
27050 \SpecialChar ~
27051 \SpecialChar ~
27052 \SpecialChar ~
27053 \SpecialChar ~
27054 \SpecialChar ~
27055 \SpecialChar ~
27056 \SpecialChar ~
27057 \SpecialChar ~
27058 \SpecialChar ~
27059 \SpecialChar ~
27060 \SpecialChar ~
27061 \SpecialChar ~
27062 case 8: ...
27063  
27064 \newline 
27065 }\SpecialChar ~
27066 \SpecialChar ~
27067 \SpecialChar ~
27068 \SpecialChar ~
27069 \SpecialChar ~
27070 \SpecialChar ~
27071 \SpecialChar ~
27072 \SpecialChar ~
27073 \SpecialChar ~
27074 \SpecialChar ~
27075 \SpecialChar ~
27076 \SpecialChar ~
27077 \SpecialChar ~
27078 \SpecialChar ~
27079 \SpecialChar ~
27080 \SpecialChar ~
27081 \SpecialChar ~
27082 \SpecialChar ~
27083 \SpecialChar ~
27084 \SpecialChar ~
27085 \SpecialChar ~
27086 \SpecialChar ~
27087 \SpecialChar ~
27088 \SpecialChar ~
27089 \SpecialChar ~
27090 \SpecialChar ~
27091 \SpecialChar ~
27092 \SpecialChar ~
27093 \SpecialChar ~
27094 \SpecialChar ~
27095 \SpecialChar ~
27096 \SpecialChar ~
27097 \SpecialChar ~
27098 \SpecialChar ~
27099 \SpecialChar ~
27100 \SpecialChar ~
27101 }
27102 \layout Standard
27103
27104 Both the above switch statements will be implemented using a jump-table.
27105  The example to the right side is slightly more efficient as the check for
27106  the lower boundary of the jump-table is not needed.
27107 \end_deeper 
27108 \layout Itemize
27109
27110 The number of case labels is not larger than supported by the target architectur
27111 e.
27112 \layout Itemize
27113
27114 If the case labels are not in numerical sequence ('gaps' between cases)
27115  SDCC checks whether a jump table with additionally inserted dummy cases
27116  is still attractive.
27117  
27118 \layout Itemize
27119
27120 If the starting number is not zero and a check for the lower boundary of
27121  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
27122  ...
27123  .
27124 \layout Standard
27125
27126 Switch statements which have large gaps in the numeric sequence or those
27127  that have too many case labels can be split into more than one switch statement
27128  for efficient code generation, e.g.:
27129 \layout Verse
27130
27131
27132 \family typewriter 
27133 switch (i) { 
27134 \newline 
27135 \SpecialChar ~
27136 \SpecialChar ~
27137 case 1: ...
27138  
27139 \newline 
27140 \SpecialChar ~
27141 \SpecialChar ~
27142 case 2: ...
27143  
27144 \newline 
27145 \SpecialChar ~
27146 \SpecialChar ~
27147 case 3: ...
27148  
27149 \newline 
27150 \SpecialChar ~
27151 \SpecialChar ~
27152 case 4: ...
27153  
27154 \newline 
27155 \SpecialChar ~
27156 \SpecialChar ~
27157 case 5: ...
27158  
27159 \newline 
27160 \SpecialChar ~
27161 \SpecialChar ~
27162 case 6: ...
27163  
27164 \newline 
27165 \SpecialChar ~
27166 \SpecialChar ~
27167 case 7: ...
27168  
27169 \newline 
27170 \SpecialChar ~
27171 \SpecialChar ~
27172 case 101: ...
27173  
27174 \newline 
27175 \SpecialChar ~
27176 \SpecialChar ~
27177 case 102: ...
27178  
27179 \newline 
27180 \SpecialChar ~
27181 \SpecialChar ~
27182 case 103: ...
27183  
27184 \newline 
27185 \SpecialChar ~
27186 \SpecialChar ~
27187 case 104: ...
27188  
27189 \newline 
27190 \SpecialChar ~
27191 \SpecialChar ~
27192 case 105: ...
27193  
27194 \newline 
27195 \SpecialChar ~
27196 \SpecialChar ~
27197 case 106: ...
27198  
27199 \newline 
27200 \SpecialChar ~
27201 \SpecialChar ~
27202 case 107: ...
27203  
27204 \newline 
27205 }
27206 \layout Standard
27207
27208 If the above switch statement is broken down into two switch statements
27209 \layout Verse
27210
27211
27212 \family typewriter 
27213 switch (i) { 
27214 \newline 
27215 \SpecialChar ~
27216 \SpecialChar ~
27217 case 1: ...
27218  
27219 \newline 
27220 \SpecialChar ~
27221 \SpecialChar ~
27222 case 2: ...
27223  
27224 \newline 
27225 \SpecialChar ~
27226 \SpecialChar ~
27227 case 3: ...
27228  
27229 \newline 
27230 \SpecialChar ~
27231 \SpecialChar ~
27232 case 4: ...
27233  
27234 \newline 
27235 \SpecialChar ~
27236 \SpecialChar ~
27237 case 5: ...
27238  
27239 \newline 
27240 \SpecialChar ~
27241 \SpecialChar ~
27242 case 6: ...
27243  
27244 \newline 
27245 \SpecialChar ~
27246 \SpecialChar ~
27247 case 7: ...
27248  
27249 \newline 
27250 }
27251 \layout Standard
27252
27253 and
27254 \layout Verse
27255
27256
27257 \family typewriter 
27258 switch (i) { 
27259 \newline 
27260 \SpecialChar ~
27261 \SpecialChar ~
27262 case 101: ...
27263  
27264 \newline 
27265 \SpecialChar ~
27266 \SpecialChar ~
27267 case 102: ...
27268  
27269 \newline 
27270 \SpecialChar ~
27271 \SpecialChar ~
27272 case 103: ...
27273  
27274 \newline 
27275 \SpecialChar ~
27276 \SpecialChar ~
27277 case 104: ...
27278  
27279 \newline 
27280 \SpecialChar ~
27281 \SpecialChar ~
27282 case 105: ...
27283  
27284 \newline 
27285 \SpecialChar ~
27286 \SpecialChar ~
27287 case 106: ...
27288  
27289 \newline 
27290 \SpecialChar ~
27291 \SpecialChar ~
27292 case 107: ...
27293  
27294 \newline 
27295 }
27296 \layout Standard
27297
27298 then both the switch statements will be implemented using jump-tables whereas
27299  the unmodified switch statement will not be.
27300 \layout Comment
27301
27302 There might be reasons which SDCC cannot know about to either favour or
27303  not favour jump tables.
27304  If the target system has to be as quick for the last switch case as for
27305  the first (pro jump table), or if the switch argument is known to be zero
27306  in the majority of the cases (contra jump table).
27307 \layout Standard
27308
27309 The pragma nojtbound
27310 \begin_inset LatexCommand \index{\#pragma nojtbound}
27311
27312 \end_inset 
27313
27314  can be used to turn off checking the 
27315 \emph on 
27316 j
27317 \emph default 
27318 ump 
27319 \emph on 
27320 t
27321 \emph default 
27322 able 
27323 \emph on 
27324 bound
27325 \emph default 
27326 aries.
27327  It has no effect if a default label is supplied.
27328  Use of this pragma is dangerous: if the switch
27329 \begin_inset LatexCommand \index{switch statement}
27330
27331 \end_inset 
27332
27333  argument is not matched by a case statement the processor will happily
27334  jump into Nirvana.
27335 \layout Subsection
27336
27337 Bit-shifting Operations
27338 \begin_inset LatexCommand \index{Bit shifting}
27339
27340 \end_inset 
27341
27342 .
27343 \layout Standard
27344
27345 Bit shifting is one of the most frequently used operation in embedded programmin
27346 g.
27347  SDCC tries to implement bit-shift operations in the most efficient way
27348  possible, e.g.:
27349 \layout Verse
27350
27351
27352 \family typewriter 
27353 unsigned char i;
27354 \newline 
27355 ...
27356  
27357 \newline 
27358 i >>= 4; 
27359 \newline 
27360 ...
27361 \layout Standard
27362
27363 generates the following code:
27364 \layout Verse
27365
27366
27367 \family typewriter 
27368 mov\SpecialChar ~
27369  a,_i 
27370 \newline 
27371 swap a 
27372 \newline 
27373 anl\SpecialChar ~
27374  a,#0x0f 
27375 \newline 
27376 mov\SpecialChar ~
27377  _i,a
27378 \layout Standard
27379
27380 In general SDCC will never setup a loop if the shift count is known.
27381  Another example:
27382 \layout Verse
27383
27384
27385 \family typewriter 
27386 unsigned int i; 
27387 \newline 
27388 ...
27389  
27390 \newline 
27391 i >>= 9; 
27392 \newline 
27393 ...
27394 \layout Standard
27395
27396 will generate:
27397 \layout Verse
27398
27399
27400 \family typewriter 
27401 mov\SpecialChar ~
27402 \SpecialChar ~
27403 a,(_i + 1) 
27404 \newline 
27405 mov\SpecialChar ~
27406 \SpecialChar ~
27407 (_i + 1),#0x00 
27408 \newline 
27409 clr\SpecialChar ~
27410 \SpecialChar ~
27411
27412 \newline 
27413 rrc\SpecialChar ~
27414 \SpecialChar ~
27415
27416 \newline 
27417 mov\SpecialChar ~
27418 \SpecialChar ~
27419 _i,a
27420 \layout Subsection
27421
27422 Bit-rotation
27423 \begin_inset LatexCommand \index{Bit rotation}
27424
27425 \end_inset 
27426
27427
27428 \layout Standard
27429
27430 A special case of the bit-shift operation is bit rotation
27431 \begin_inset LatexCommand \index{rotating bits}
27432
27433 \end_inset 
27434
27435 , SDCC recognizes the following expression to be a left bit-rotation:
27436 \layout Verse
27437
27438
27439 \family typewriter 
27440 \series bold 
27441 unsigned
27442 \series default 
27443 \SpecialChar ~
27444 \SpecialChar ~
27445 char i;\SpecialChar ~
27446 \SpecialChar ~
27447 \SpecialChar ~
27448 \SpecialChar ~
27449 \SpecialChar ~
27450 \SpecialChar ~
27451 \SpecialChar ~
27452 \SpecialChar ~
27453 \SpecialChar ~
27454 \SpecialChar ~
27455 \SpecialChar ~
27456 /* unsigned is needed for rotation */ 
27457 \newline 
27458 ...
27459  
27460 \newline 
27461 i = ((i << 1) | (i >> 7)); 
27462 \family default 
27463
27464 \newline 
27465
27466 \family typewriter 
27467 ...
27468 \layout Standard
27469
27470 will generate the following code:
27471 \layout Verse
27472
27473
27474 \family typewriter 
27475 mov\SpecialChar ~
27476 \SpecialChar ~
27477 a,_i 
27478 \newline 
27479 rl\SpecialChar ~
27480 \SpecialChar ~
27481 \SpecialChar ~
27482
27483 \newline 
27484 mov\SpecialChar ~
27485 \SpecialChar ~
27486 _i,a
27487 \layout Standard
27488
27489 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27490 ns of this case will also be recognized as bit-rotation, i.e.: 
27491 \layout Verse
27492
27493
27494 \family typewriter 
27495 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27496 \layout Subsection
27497
27498 Nibble and Byte Swapping
27499 \layout Standard
27500
27501 Other special cases of the bit-shift operations are nibble or byte swapping
27502 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27503
27504 \end_inset 
27505
27506 , SDCC recognizes the following expressions:
27507 \layout Verse
27508
27509
27510 \family typewriter 
27511 \series bold 
27512 unsigned
27513 \series default 
27514 \SpecialChar ~
27515 \SpecialChar ~
27516 char i; 
27517 \newline 
27518
27519 \series bold 
27520 unsigned
27521 \series default 
27522 \SpecialChar ~
27523 \SpecialChar ~
27524 int j; 
27525 \newline 
27526 ...
27527  
27528 \newline 
27529 i = ((i << 4) | (i >> 4)); 
27530 \family default 
27531
27532 \newline 
27533
27534 \family typewriter 
27535 j = ((j << 8) | (j >> 8)); 
27536 \layout Standard
27537
27538 and generates a swap instruction for the nibble swapping
27539 \begin_inset LatexCommand \index{Nibble swapping}
27540
27541 \end_inset 
27542
27543  or move instructions for the byte swapping
27544 \begin_inset LatexCommand \index{Byte swapping}
27545
27546 \end_inset 
27547
27548 .
27549  The 
27550 \begin_inset Quotes sld
27551 \end_inset 
27552
27553 j
27554 \begin_inset Quotes srd
27555 \end_inset 
27556
27557  example can be used to convert from little to big-endian or vice versa.
27558  If you want to change the endianness of a 
27559 \emph on 
27560 signed
27561 \emph default 
27562  integer you have to cast to 
27563 \family typewriter 
27564 (unsigned int)
27565 \family default 
27566  first.
27567 \layout Standard
27568
27569 Note that SDCC stores numbers in little-endian
27570 \begin_inset Foot
27571 collapsed false
27572
27573 \layout Standard
27574
27575 Usually 8-bit processors don't care much about endianness.
27576  This is not the case for the standard 8051 which only has an instruction
27577  to increment its 
27578 \emph on 
27579 dptr
27580 \emph default 
27581
27582 \begin_inset LatexCommand \index{DPTR}
27583
27584 \end_inset 
27585
27586 -datapointer
27587 \emph on 
27588  
27589 \emph default 
27590 so little-endian is the more efficient byte order.
27591 \end_inset 
27592
27593
27594 \begin_inset LatexCommand \index{little-endian}
27595
27596 \end_inset 
27597
27598
27599 \begin_inset LatexCommand \index{Endianness}
27600
27601 \end_inset 
27602
27603  format (i.e.
27604  lowest order first).
27605 \layout Subsection
27606
27607 Highest Order Bit
27608 \begin_inset LatexCommand \index{Highest Order Bit}
27609
27610 \end_inset 
27611
27612  / Any Order Bit
27613 \begin_inset LatexCommand \index{Any Order Bit}
27614
27615 \end_inset 
27616
27617
27618 \layout Standard
27619
27620 It is frequently required to obtain the highest order bit of an integral
27621  type (long, int, short or char types).
27622  Also obtaining any other order bit is not uncommon.
27623  SDCC recognizes the following expressions to yield the highest order bit
27624  and generates optimized code for it, e.g.:
27625 \layout Verse
27626
27627
27628 \family typewriter 
27629 unsigned int gint; 
27630 \newline 
27631
27632 \newline 
27633 foo () { 
27634 \newline 
27635 \SpecialChar ~
27636 \SpecialChar ~
27637 unsigned char hob1, aob1; 
27638 \newline 
27639 \SpecialChar ~
27640 \SpecialChar ~
27641 bit hob2, hob3, aob2, aob3; 
27642 \newline 
27643 \SpecialChar ~
27644 \SpecialChar ~
27645 ...
27646  
27647 \newline 
27648 \SpecialChar ~
27649 \SpecialChar ~
27650 hob1 = (gint >> 15) & 1; 
27651 \newline 
27652 \SpecialChar ~
27653 \SpecialChar ~
27654 hob2 = (gint >> 15) & 1; 
27655 \newline 
27656 \SpecialChar ~
27657 \SpecialChar ~
27658 hob3 = gint & 0x8000; 
27659 \newline 
27660 \SpecialChar ~
27661 \SpecialChar ~
27662 aob1 = (gint >> 9) & 1; 
27663 \newline 
27664 \SpecialChar ~
27665 \SpecialChar ~
27666 aob2 = (gint >> 8) & 1; 
27667 \newline 
27668 \SpecialChar ~
27669 \SpecialChar ~
27670 aob3 = gint & 0x0800; 
27671 \newline 
27672 \SpecialChar ~
27673 \SpecialChar ~
27674 ..
27675  
27676 \newline 
27677 }
27678 \layout Standard
27679
27680 will generate the following code:
27681 \layout Verse
27682
27683
27684 \family typewriter 
27685 \SpecialChar ~
27686 \SpecialChar ~
27687 \SpecialChar ~
27688 \SpecialChar ~
27689 \SpecialChar ~
27690 \SpecialChar ~
27691 \SpecialChar ~
27692 \SpecialChar ~
27693 \SpecialChar ~
27694 \SpecialChar ~
27695 \SpecialChar ~
27696 \SpecialChar ~
27697 \SpecialChar ~
27698 \SpecialChar ~
27699 \SpecialChar ~
27700 \SpecialChar ~
27701 \SpecialChar ~
27702 \SpecialChar ~
27703 \SpecialChar ~
27704 \SpecialChar ~
27705 \SpecialChar ~
27706 \SpecialChar ~
27707 \SpecialChar ~
27708 \SpecialChar ~
27709 \SpecialChar ~
27710  61 ;\SpecialChar ~
27711  hob.c 7 
27712 \newline 
27713 000A E5*01\SpecialChar ~
27714 \SpecialChar ~
27715 \SpecialChar ~
27716 \SpecialChar ~
27717 \SpecialChar ~
27718 \SpecialChar ~
27719 \SpecialChar ~
27720 \SpecialChar ~
27721 \SpecialChar ~
27722 \SpecialChar ~
27723 \SpecialChar ~
27724 \SpecialChar ~
27725 \SpecialChar ~
27726 \SpecialChar ~
27727 \SpecialChar ~
27728  62\SpecialChar ~
27729 \SpecialChar ~
27730 \SpecialChar ~
27731 \SpecialChar ~
27732 \SpecialChar ~
27733 \SpecialChar ~
27734 \SpecialChar ~
27735 \SpecialChar ~
27736  mov\SpecialChar ~
27737 \SpecialChar ~
27738  a,(_gint + 1) 
27739 \newline 
27740 000C 23\SpecialChar ~
27741 \SpecialChar ~
27742 \SpecialChar ~
27743 \SpecialChar ~
27744 \SpecialChar ~
27745 \SpecialChar ~
27746 \SpecialChar ~
27747 \SpecialChar ~
27748 \SpecialChar ~
27749 \SpecialChar ~
27750 \SpecialChar ~
27751 \SpecialChar ~
27752 \SpecialChar ~
27753 \SpecialChar ~
27754 \SpecialChar ~
27755 \SpecialChar ~
27756 \SpecialChar ~
27757 \SpecialChar ~
27758  63\SpecialChar ~
27759 \SpecialChar ~
27760 \SpecialChar ~
27761 \SpecialChar ~
27762 \SpecialChar ~
27763 \SpecialChar ~
27764 \SpecialChar ~
27765 \SpecialChar ~
27766  rl\SpecialChar ~
27767 \SpecialChar ~
27768 \SpecialChar ~
27769  a 
27770 \newline 
27771 000D 54 01\SpecialChar ~
27772 \SpecialChar ~
27773 \SpecialChar ~
27774 \SpecialChar ~
27775 \SpecialChar ~
27776 \SpecialChar ~
27777 \SpecialChar ~
27778 \SpecialChar ~
27779 \SpecialChar ~
27780 \SpecialChar ~
27781 \SpecialChar ~
27782 \SpecialChar ~
27783 \SpecialChar ~
27784 \SpecialChar ~
27785 \SpecialChar ~
27786  64\SpecialChar ~
27787 \SpecialChar ~
27788 \SpecialChar ~
27789 \SpecialChar ~
27790 \SpecialChar ~
27791 \SpecialChar ~
27792 \SpecialChar ~
27793 \SpecialChar ~
27794  anl\SpecialChar ~
27795 \SpecialChar ~
27796  a,#0x01 
27797 \newline 
27798 000F F5*02\SpecialChar ~
27799 \SpecialChar ~
27800 \SpecialChar ~
27801 \SpecialChar ~
27802 \SpecialChar ~
27803 \SpecialChar ~
27804 \SpecialChar ~
27805 \SpecialChar ~
27806 \SpecialChar ~
27807 \SpecialChar ~
27808 \SpecialChar ~
27809 \SpecialChar ~
27810 \SpecialChar ~
27811 \SpecialChar ~
27812 \SpecialChar ~
27813  65\SpecialChar ~
27814 \SpecialChar ~
27815 \SpecialChar ~
27816 \SpecialChar ~
27817 \SpecialChar ~
27818 \SpecialChar ~
27819 \SpecialChar ~
27820 \SpecialChar ~
27821  mov\SpecialChar ~
27822 \SpecialChar ~
27823  _foo_hob1_1_1,a 
27824 \newline 
27825 \SpecialChar ~
27826 \SpecialChar ~
27827 \SpecialChar ~
27828 \SpecialChar ~
27829 \SpecialChar ~
27830 \SpecialChar ~
27831 \SpecialChar ~
27832 \SpecialChar ~
27833 \SpecialChar ~
27834 \SpecialChar ~
27835 \SpecialChar ~
27836 \SpecialChar ~
27837 \SpecialChar ~
27838 \SpecialChar ~
27839 \SpecialChar ~
27840 \SpecialChar ~
27841 \SpecialChar ~
27842 \SpecialChar ~
27843 \SpecialChar ~
27844 \SpecialChar ~
27845 \SpecialChar ~
27846 \SpecialChar ~
27847 \SpecialChar ~
27848 \SpecialChar ~
27849 \SpecialChar ~
27850  66 ;\SpecialChar ~
27851  hob.c 8 
27852 \newline 
27853 0011 E5*01\SpecialChar ~
27854 \SpecialChar ~
27855 \SpecialChar ~
27856 \SpecialChar ~
27857 \SpecialChar ~
27858 \SpecialChar ~
27859 \SpecialChar ~
27860 \SpecialChar ~
27861 \SpecialChar ~
27862 \SpecialChar ~
27863 \SpecialChar ~
27864 \SpecialChar ~
27865 \SpecialChar ~
27866 \SpecialChar ~
27867 \SpecialChar ~
27868  67\SpecialChar ~
27869 \SpecialChar ~
27870 \SpecialChar ~
27871 \SpecialChar ~
27872 \SpecialChar ~
27873 \SpecialChar ~
27874 \SpecialChar ~
27875 \SpecialChar ~
27876  mov\SpecialChar ~
27877 \SpecialChar ~
27878  a,(_gint + 1) 
27879 \newline 
27880 0013 33\SpecialChar ~
27881 \SpecialChar ~
27882 \SpecialChar ~
27883 \SpecialChar ~
27884 \SpecialChar ~
27885 \SpecialChar ~
27886 \SpecialChar ~
27887 \SpecialChar ~
27888 \SpecialChar ~
27889 \SpecialChar ~
27890 \SpecialChar ~
27891 \SpecialChar ~
27892 \SpecialChar ~
27893 \SpecialChar ~
27894 \SpecialChar ~
27895 \SpecialChar ~
27896 \SpecialChar ~
27897 \SpecialChar ~
27898  68\SpecialChar ~
27899 \SpecialChar ~
27900 \SpecialChar ~
27901 \SpecialChar ~
27902 \SpecialChar ~
27903 \SpecialChar ~
27904 \SpecialChar ~
27905 \SpecialChar ~
27906  rlc\SpecialChar ~
27907 \SpecialChar ~
27908  a 
27909 \newline 
27910 0014 92*00\SpecialChar ~
27911 \SpecialChar ~
27912 \SpecialChar ~
27913 \SpecialChar ~
27914 \SpecialChar ~
27915 \SpecialChar ~
27916 \SpecialChar ~
27917 \SpecialChar ~
27918 \SpecialChar ~
27919 \SpecialChar ~
27920 \SpecialChar ~
27921 \SpecialChar ~
27922 \SpecialChar ~
27923 \SpecialChar ~
27924 \SpecialChar ~
27925  69\SpecialChar ~
27926 \SpecialChar ~
27927 \SpecialChar ~
27928 \SpecialChar ~
27929 \SpecialChar ~
27930 \SpecialChar ~
27931 \SpecialChar ~
27932 \SpecialChar ~
27933  mov\SpecialChar ~
27934 \SpecialChar ~
27935  _foo_hob2_1_1,c 
27936 \newline 
27937 \SpecialChar ~
27938 \SpecialChar ~
27939 \SpecialChar ~
27940 \SpecialChar ~
27941 \SpecialChar ~
27942 \SpecialChar ~
27943 \SpecialChar ~
27944 \SpecialChar ~
27945 \SpecialChar ~
27946 \SpecialChar ~
27947 \SpecialChar ~
27948 \SpecialChar ~
27949 \SpecialChar ~
27950 \SpecialChar ~
27951 \SpecialChar ~
27952 \SpecialChar ~
27953 \SpecialChar ~
27954 \SpecialChar ~
27955 \SpecialChar ~
27956 \SpecialChar ~
27957 \SpecialChar ~
27958 \SpecialChar ~
27959 \SpecialChar ~
27960 \SpecialChar ~
27961 \SpecialChar ~
27962  66 ;\SpecialChar ~
27963  hob.c 9 
27964 \newline 
27965 0016 E5*01\SpecialChar ~
27966 \SpecialChar ~
27967 \SpecialChar ~
27968 \SpecialChar ~
27969 \SpecialChar ~
27970 \SpecialChar ~
27971 \SpecialChar ~
27972 \SpecialChar ~
27973 \SpecialChar ~
27974 \SpecialChar ~
27975 \SpecialChar ~
27976 \SpecialChar ~
27977 \SpecialChar ~
27978 \SpecialChar ~
27979 \SpecialChar ~
27980  67\SpecialChar ~
27981 \SpecialChar ~
27982 \SpecialChar ~
27983 \SpecialChar ~
27984 \SpecialChar ~
27985 \SpecialChar ~
27986 \SpecialChar ~
27987 \SpecialChar ~
27988  mov\SpecialChar ~
27989 \SpecialChar ~
27990  a,(_gint + 1) 
27991 \newline 
27992 0018 33\SpecialChar ~
27993 \SpecialChar ~
27994 \SpecialChar ~
27995 \SpecialChar ~
27996 \SpecialChar ~
27997 \SpecialChar ~
27998 \SpecialChar ~
27999 \SpecialChar ~
28000 \SpecialChar ~
28001 \SpecialChar ~
28002 \SpecialChar ~
28003 \SpecialChar ~
28004 \SpecialChar ~
28005 \SpecialChar ~
28006 \SpecialChar ~
28007 \SpecialChar ~
28008 \SpecialChar ~
28009 \SpecialChar ~
28010  68\SpecialChar ~
28011 \SpecialChar ~
28012 \SpecialChar ~
28013 \SpecialChar ~
28014 \SpecialChar ~
28015 \SpecialChar ~
28016 \SpecialChar ~
28017 \SpecialChar ~
28018  rlc\SpecialChar ~
28019 \SpecialChar ~
28020  a 
28021 \newline 
28022 0019 92*01\SpecialChar ~
28023 \SpecialChar ~
28024 \SpecialChar ~
28025 \SpecialChar ~
28026 \SpecialChar ~
28027 \SpecialChar ~
28028 \SpecialChar ~
28029 \SpecialChar ~
28030 \SpecialChar ~
28031 \SpecialChar ~
28032 \SpecialChar ~
28033 \SpecialChar ~
28034 \SpecialChar ~
28035 \SpecialChar ~
28036 \SpecialChar ~
28037  69\SpecialChar ~
28038 \SpecialChar ~
28039 \SpecialChar ~
28040 \SpecialChar ~
28041 \SpecialChar ~
28042 \SpecialChar ~
28043 \SpecialChar ~
28044 \SpecialChar ~
28045  mov\SpecialChar ~
28046 \SpecialChar ~
28047  _foo_hob3_1_1,c 
28048 \newline 
28049 \SpecialChar ~
28050 \SpecialChar ~
28051 \SpecialChar ~
28052 \SpecialChar ~
28053 \SpecialChar ~
28054 \SpecialChar ~
28055 \SpecialChar ~
28056 \SpecialChar ~
28057 \SpecialChar ~
28058 \SpecialChar ~
28059 \SpecialChar ~
28060 \SpecialChar ~
28061 \SpecialChar ~
28062 \SpecialChar ~
28063 \SpecialChar ~
28064 \SpecialChar ~
28065 \SpecialChar ~
28066 \SpecialChar ~
28067 \SpecialChar ~
28068 \SpecialChar ~
28069 \SpecialChar ~
28070 \SpecialChar ~
28071 \SpecialChar ~
28072 \SpecialChar ~
28073 \SpecialChar ~
28074  70 ;\SpecialChar ~
28075  hob.c 10 
28076 \newline 
28077 001B E5*01\SpecialChar ~
28078 \SpecialChar ~
28079 \SpecialChar ~
28080 \SpecialChar ~
28081 \SpecialChar ~
28082 \SpecialChar ~
28083 \SpecialChar ~
28084 \SpecialChar ~
28085 \SpecialChar ~
28086 \SpecialChar ~
28087 \SpecialChar ~
28088 \SpecialChar ~
28089 \SpecialChar ~
28090 \SpecialChar ~
28091 \SpecialChar ~
28092  71\SpecialChar ~
28093 \SpecialChar ~
28094 \SpecialChar ~
28095 \SpecialChar ~
28096 \SpecialChar ~
28097 \SpecialChar ~
28098 \SpecialChar ~
28099 \SpecialChar ~
28100  mov\SpecialChar ~
28101 \SpecialChar ~
28102  a,(_gint + 1) 
28103 \newline 
28104 001D 03\SpecialChar ~
28105 \SpecialChar ~
28106 \SpecialChar ~
28107 \SpecialChar ~
28108 \SpecialChar ~
28109 \SpecialChar ~
28110 \SpecialChar ~
28111 \SpecialChar ~
28112 \SpecialChar ~
28113 \SpecialChar ~
28114 \SpecialChar ~
28115 \SpecialChar ~
28116 \SpecialChar ~
28117 \SpecialChar ~
28118 \SpecialChar ~
28119 \SpecialChar ~
28120 \SpecialChar ~
28121 \SpecialChar ~
28122  72\SpecialChar ~
28123 \SpecialChar ~
28124 \SpecialChar ~
28125 \SpecialChar ~
28126 \SpecialChar ~
28127 \SpecialChar ~
28128 \SpecialChar ~
28129 \SpecialChar ~
28130  rr\SpecialChar ~
28131 \SpecialChar ~
28132 \SpecialChar ~
28133  a 
28134 \newline 
28135 001E 54 01\SpecialChar ~
28136 \SpecialChar ~
28137 \SpecialChar ~
28138 \SpecialChar ~
28139 \SpecialChar ~
28140 \SpecialChar ~
28141 \SpecialChar ~
28142 \SpecialChar ~
28143 \SpecialChar ~
28144 \SpecialChar ~
28145 \SpecialChar ~
28146 \SpecialChar ~
28147 \SpecialChar ~
28148 \SpecialChar ~
28149 \SpecialChar ~
28150  73\SpecialChar ~
28151 \SpecialChar ~
28152 \SpecialChar ~
28153 \SpecialChar ~
28154 \SpecialChar ~
28155 \SpecialChar ~
28156 \SpecialChar ~
28157 \SpecialChar ~
28158  anl\SpecialChar ~
28159 \SpecialChar ~
28160  a,#0x01 
28161 \newline 
28162 0020 F5*03\SpecialChar ~
28163 \SpecialChar ~
28164 \SpecialChar ~
28165 \SpecialChar ~
28166 \SpecialChar ~
28167 \SpecialChar ~
28168 \SpecialChar ~
28169 \SpecialChar ~
28170 \SpecialChar ~
28171 \SpecialChar ~
28172 \SpecialChar ~
28173 \SpecialChar ~
28174 \SpecialChar ~
28175 \SpecialChar ~
28176 \SpecialChar ~
28177  74\SpecialChar ~
28178 \SpecialChar ~
28179 \SpecialChar ~
28180 \SpecialChar ~
28181 \SpecialChar ~
28182 \SpecialChar ~
28183 \SpecialChar ~
28184 \SpecialChar ~
28185  mov\SpecialChar ~
28186 \SpecialChar ~
28187  _foo_aob1_1_1,a 
28188 \newline 
28189 \SpecialChar ~
28190 \SpecialChar ~
28191 \SpecialChar ~
28192 \SpecialChar ~
28193 \SpecialChar ~
28194 \SpecialChar ~
28195 \SpecialChar ~
28196 \SpecialChar ~
28197 \SpecialChar ~
28198 \SpecialChar ~
28199 \SpecialChar ~
28200 \SpecialChar ~
28201 \SpecialChar ~
28202 \SpecialChar ~
28203 \SpecialChar ~
28204 \SpecialChar ~
28205 \SpecialChar ~
28206 \SpecialChar ~
28207 \SpecialChar ~
28208 \SpecialChar ~
28209 \SpecialChar ~
28210 \SpecialChar ~
28211 \SpecialChar ~
28212 \SpecialChar ~
28213 \SpecialChar ~
28214  75 ;\SpecialChar ~
28215  hob.c 11 
28216 \newline 
28217 0022 E5*01\SpecialChar ~
28218 \SpecialChar ~
28219 \SpecialChar ~
28220 \SpecialChar ~
28221 \SpecialChar ~
28222 \SpecialChar ~
28223 \SpecialChar ~
28224 \SpecialChar ~
28225 \SpecialChar ~
28226 \SpecialChar ~
28227 \SpecialChar ~
28228 \SpecialChar ~
28229 \SpecialChar ~
28230 \SpecialChar ~
28231 \SpecialChar ~
28232  76\SpecialChar ~
28233 \SpecialChar ~
28234 \SpecialChar ~
28235 \SpecialChar ~
28236 \SpecialChar ~
28237 \SpecialChar ~
28238 \SpecialChar ~
28239 \SpecialChar ~
28240  mov\SpecialChar ~
28241 \SpecialChar ~
28242  a,(_gint + 1) 
28243 \newline 
28244 0024 13\SpecialChar ~
28245 \SpecialChar ~
28246 \SpecialChar ~
28247 \SpecialChar ~
28248 \SpecialChar ~
28249 \SpecialChar ~
28250 \SpecialChar ~
28251 \SpecialChar ~
28252 \SpecialChar ~
28253 \SpecialChar ~
28254 \SpecialChar ~
28255 \SpecialChar ~
28256 \SpecialChar ~
28257 \SpecialChar ~
28258 \SpecialChar ~
28259 \SpecialChar ~
28260 \SpecialChar ~
28261 \SpecialChar ~
28262  77\SpecialChar ~
28263 \SpecialChar ~
28264 \SpecialChar ~
28265 \SpecialChar ~
28266 \SpecialChar ~
28267 \SpecialChar ~
28268 \SpecialChar ~
28269 \SpecialChar ~
28270  rrc\SpecialChar ~
28271 \SpecialChar ~
28272  a 
28273 \newline 
28274 0025 92*02\SpecialChar ~
28275 \SpecialChar ~
28276 \SpecialChar ~
28277 \SpecialChar ~
28278 \SpecialChar ~
28279 \SpecialChar ~
28280 \SpecialChar ~
28281 \SpecialChar ~
28282 \SpecialChar ~
28283 \SpecialChar ~
28284 \SpecialChar ~
28285 \SpecialChar ~
28286 \SpecialChar ~
28287 \SpecialChar ~
28288 \SpecialChar ~
28289  78\SpecialChar ~
28290 \SpecialChar ~
28291 \SpecialChar ~
28292 \SpecialChar ~
28293 \SpecialChar ~
28294 \SpecialChar ~
28295 \SpecialChar ~
28296 \SpecialChar ~
28297  mov\SpecialChar ~
28298 \SpecialChar ~
28299  _foo_aob2_1_1,c 
28300 \newline 
28301 \SpecialChar ~
28302 \SpecialChar ~
28303 \SpecialChar ~
28304 \SpecialChar ~
28305 \SpecialChar ~
28306 \SpecialChar ~
28307 \SpecialChar ~
28308 \SpecialChar ~
28309 \SpecialChar ~
28310 \SpecialChar ~
28311 \SpecialChar ~
28312 \SpecialChar ~
28313 \SpecialChar ~
28314 \SpecialChar ~
28315 \SpecialChar ~
28316 \SpecialChar ~
28317 \SpecialChar ~
28318 \SpecialChar ~
28319 \SpecialChar ~
28320 \SpecialChar ~
28321 \SpecialChar ~
28322 \SpecialChar ~
28323 \SpecialChar ~
28324 \SpecialChar ~
28325 \SpecialChar ~
28326  79 ;\SpecialChar ~
28327  hob.c 12 
28328 \newline 
28329 0027 E5*01\SpecialChar ~
28330 \SpecialChar ~
28331 \SpecialChar ~
28332 \SpecialChar ~
28333 \SpecialChar ~
28334 \SpecialChar ~
28335 \SpecialChar ~
28336 \SpecialChar ~
28337 \SpecialChar ~
28338 \SpecialChar ~
28339 \SpecialChar ~
28340 \SpecialChar ~
28341 \SpecialChar ~
28342 \SpecialChar ~
28343 \SpecialChar ~
28344  80\SpecialChar ~
28345 \SpecialChar ~
28346 \SpecialChar ~
28347 \SpecialChar ~
28348 \SpecialChar ~
28349 \SpecialChar ~
28350 \SpecialChar ~
28351 \SpecialChar ~
28352  mov\SpecialChar ~
28353 \SpecialChar ~
28354  a,(_gint + 1) 
28355 \newline 
28356 0029 A2 E3\SpecialChar ~
28357 \SpecialChar ~
28358 \SpecialChar ~
28359 \SpecialChar ~
28360 \SpecialChar ~
28361 \SpecialChar ~
28362 \SpecialChar ~
28363 \SpecialChar ~
28364 \SpecialChar ~
28365 \SpecialChar ~
28366 \SpecialChar ~
28367 \SpecialChar ~
28368 \SpecialChar ~
28369 \SpecialChar ~
28370 \SpecialChar ~
28371  81\SpecialChar ~
28372 \SpecialChar ~
28373 \SpecialChar ~
28374 \SpecialChar ~
28375 \SpecialChar ~
28376 \SpecialChar ~
28377 \SpecialChar ~
28378 \SpecialChar ~
28379  mov\SpecialChar ~
28380 \SpecialChar ~
28381  c,acc[3] 
28382 \newline 
28383 002B 92*03\SpecialChar ~
28384 \SpecialChar ~
28385 \SpecialChar ~
28386 \SpecialChar ~
28387 \SpecialChar ~
28388 \SpecialChar ~
28389 \SpecialChar ~
28390 \SpecialChar ~
28391 \SpecialChar ~
28392 \SpecialChar ~
28393 \SpecialChar ~
28394 \SpecialChar ~
28395 \SpecialChar ~
28396 \SpecialChar ~
28397 \SpecialChar ~
28398  82\SpecialChar ~
28399 \SpecialChar ~
28400 \SpecialChar ~
28401 \SpecialChar ~
28402 \SpecialChar ~
28403 \SpecialChar ~
28404 \SpecialChar ~
28405 \SpecialChar ~
28406  mov\SpecialChar ~
28407 \SpecialChar ~
28408  _foo_aob3_1_1,c 
28409 \layout Standard
28410
28411 Other variations of these cases however will 
28412 \emph on 
28413 not
28414 \emph default 
28415  be recognized.
28416  They are standard C expressions, so I heartily recommend these be the only
28417  way to get the highest order bit, (it is portable).
28418  Of course it will be recognized even if it is embedded in other expressions,
28419  e.g.:
28420 \layout Verse
28421
28422
28423 \family typewriter 
28424 xyz = gint + ((gint >> 15) & 1);
28425 \layout Standard
28426
28427 will still be recognized.
28428 \layout Subsection
28429
28430 Higher Order Byte
28431 \begin_inset LatexCommand \index{Higher Order Byte}
28432
28433 \end_inset 
28434
28435  / Higher Order Word
28436 \begin_inset LatexCommand \index{Higher Order Word}
28437
28438 \end_inset 
28439
28440
28441 \layout Standard
28442
28443 It is also frequently required to obtain a higher order byte or word of
28444  a larger integral type (long, int or short types).
28445  SDCC recognizes the following expressions to yield the higher order byte
28446  or word and generates optimized code for it, e.g.:
28447 \layout Verse
28448
28449
28450 \family typewriter 
28451 unsigned int gint; 
28452 \newline 
28453 unsigned long int glong; 
28454 \newline 
28455
28456 \newline 
28457 foo () { 
28458 \newline 
28459 \SpecialChar ~
28460 \SpecialChar ~
28461 unsigned char hob1, hob2; 
28462 \newline 
28463 \SpecialChar ~
28464 \SpecialChar ~
28465 unsigned int how1, how2; 
28466 \newline 
28467 \SpecialChar ~
28468 \SpecialChar ~
28469 ...
28470  
28471 \newline 
28472 \SpecialChar ~
28473 \SpecialChar ~
28474 hob1 = (gint >> 8) & 0xFF; 
28475 \newline 
28476 \SpecialChar ~
28477 \SpecialChar ~
28478 hob2 = glong >> 24; 
28479 \newline 
28480 \SpecialChar ~
28481 \SpecialChar ~
28482 how1 = (glong >> 16) & 0xFFFF; 
28483 \newline 
28484 \SpecialChar ~
28485 \SpecialChar ~
28486 how2 = glong >> 8; 
28487 \newline 
28488 \SpecialChar ~
28489 \SpecialChar ~
28490 ..
28491  
28492 \newline 
28493 }
28494 \layout Standard
28495
28496 will generate the following code:
28497 \layout Verse
28498
28499
28500 \family typewriter 
28501 \SpecialChar ~
28502 \SpecialChar ~
28503 \SpecialChar ~
28504 \SpecialChar ~
28505 \SpecialChar ~
28506 \SpecialChar ~
28507 \SpecialChar ~
28508 \SpecialChar ~
28509 \SpecialChar ~
28510 \SpecialChar ~
28511 \SpecialChar ~
28512 \SpecialChar ~
28513 \SpecialChar ~
28514 \SpecialChar ~
28515 \SpecialChar ~
28516 \SpecialChar ~
28517 \SpecialChar ~
28518 \SpecialChar ~
28519 \SpecialChar ~
28520 \SpecialChar ~
28521 \SpecialChar ~
28522 \SpecialChar ~
28523 \SpecialChar ~
28524 \SpecialChar ~
28525 \SpecialChar ~
28526  91 ;\SpecialChar ~
28527  hob.c 15 
28528 \newline 
28529 0037 85*01*06\SpecialChar ~
28530 \SpecialChar ~
28531 \SpecialChar ~
28532 \SpecialChar ~
28533 \SpecialChar ~
28534 \SpecialChar ~
28535 \SpecialChar ~
28536 \SpecialChar ~
28537 \SpecialChar ~
28538 \SpecialChar ~
28539 \SpecialChar ~
28540 \SpecialChar ~
28541  92\SpecialChar ~
28542 \SpecialChar ~
28543 \SpecialChar ~
28544 \SpecialChar ~
28545 \SpecialChar ~
28546 \SpecialChar ~
28547 \SpecialChar ~
28548 \SpecialChar ~
28549  mov\SpecialChar ~
28550 \SpecialChar ~
28551  _foo_hob1_1_1,(_gint + 1) 
28552 \newline 
28553 \SpecialChar ~
28554 \SpecialChar ~
28555 \SpecialChar ~
28556 \SpecialChar ~
28557 \SpecialChar ~
28558 \SpecialChar ~
28559 \SpecialChar ~
28560 \SpecialChar ~
28561 \SpecialChar ~
28562 \SpecialChar ~
28563 \SpecialChar ~
28564 \SpecialChar ~
28565 \SpecialChar ~
28566 \SpecialChar ~
28567 \SpecialChar ~
28568 \SpecialChar ~
28569 \SpecialChar ~
28570 \SpecialChar ~
28571 \SpecialChar ~
28572 \SpecialChar ~
28573 \SpecialChar ~
28574 \SpecialChar ~
28575 \SpecialChar ~
28576 \SpecialChar ~
28577 \SpecialChar ~
28578  93 ;\SpecialChar ~
28579  hob.c 16 
28580 \newline 
28581 003A 85*05*07\SpecialChar ~
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 \SpecialChar ~
28585 \SpecialChar ~
28586 \SpecialChar ~
28587 \SpecialChar ~
28588 \SpecialChar ~
28589 \SpecialChar ~
28590 \SpecialChar ~
28591 \SpecialChar ~
28592 \SpecialChar ~
28593  94\SpecialChar ~
28594 \SpecialChar ~
28595 \SpecialChar ~
28596 \SpecialChar ~
28597 \SpecialChar ~
28598 \SpecialChar ~
28599 \SpecialChar ~
28600 \SpecialChar ~
28601  mov\SpecialChar ~
28602 \SpecialChar ~
28603  _foo_hob2_1_1,(_glong + 3) 
28604 \newline 
28605 \SpecialChar ~
28606 \SpecialChar ~
28607 \SpecialChar ~
28608 \SpecialChar ~
28609 \SpecialChar ~
28610 \SpecialChar ~
28611 \SpecialChar ~
28612 \SpecialChar ~
28613 \SpecialChar ~
28614 \SpecialChar ~
28615 \SpecialChar ~
28616 \SpecialChar ~
28617 \SpecialChar ~
28618 \SpecialChar ~
28619 \SpecialChar ~
28620 \SpecialChar ~
28621 \SpecialChar ~
28622 \SpecialChar ~
28623 \SpecialChar ~
28624 \SpecialChar ~
28625 \SpecialChar ~
28626 \SpecialChar ~
28627 \SpecialChar ~
28628 \SpecialChar ~
28629 \SpecialChar ~
28630  95 ;\SpecialChar ~
28631  hob.c 17 
28632 \newline 
28633 003D 85*04*08\SpecialChar ~
28634 \SpecialChar ~
28635 \SpecialChar ~
28636 \SpecialChar ~
28637 \SpecialChar ~
28638 \SpecialChar ~
28639 \SpecialChar ~
28640 \SpecialChar ~
28641 \SpecialChar ~
28642 \SpecialChar ~
28643 \SpecialChar ~
28644 \SpecialChar ~
28645  96\SpecialChar ~
28646 \SpecialChar ~
28647 \SpecialChar ~
28648 \SpecialChar ~
28649 \SpecialChar ~
28650 \SpecialChar ~
28651 \SpecialChar ~
28652 \SpecialChar ~
28653  mov\SpecialChar ~
28654 \SpecialChar ~
28655  _foo_how1_1_1,(_glong + 2) 
28656 \newline 
28657 0040 85*05*09\SpecialChar ~
28658 \SpecialChar ~
28659 \SpecialChar ~
28660 \SpecialChar ~
28661 \SpecialChar ~
28662 \SpecialChar ~
28663 \SpecialChar ~
28664 \SpecialChar ~
28665 \SpecialChar ~
28666 \SpecialChar ~
28667 \SpecialChar ~
28668 \SpecialChar ~
28669  97\SpecialChar ~
28670 \SpecialChar ~
28671 \SpecialChar ~
28672 \SpecialChar ~
28673 \SpecialChar ~
28674 \SpecialChar ~
28675 \SpecialChar ~
28676 \SpecialChar ~
28677  mov\SpecialChar ~
28678 \SpecialChar ~
28679  (_foo_how1_1_1 + 1),(_glong + 3) 
28680 \newline 
28681 0043 85*03*0A\SpecialChar ~
28682 \SpecialChar ~
28683 \SpecialChar ~
28684 \SpecialChar ~
28685 \SpecialChar ~
28686 \SpecialChar ~
28687 \SpecialChar ~
28688 \SpecialChar ~
28689 \SpecialChar ~
28690 \SpecialChar ~
28691 \SpecialChar ~
28692 \SpecialChar ~
28693  98\SpecialChar ~
28694 \SpecialChar ~
28695 \SpecialChar ~
28696 \SpecialChar ~
28697 \SpecialChar ~
28698 \SpecialChar ~
28699 \SpecialChar ~
28700 \SpecialChar ~
28701  mov\SpecialChar ~
28702 \SpecialChar ~
28703  _foo_how2_1_1,(_glong + 1) 
28704 \newline 
28705 0046 85*04*0B\SpecialChar ~
28706 \SpecialChar ~
28707 \SpecialChar ~
28708 \SpecialChar ~
28709 \SpecialChar ~
28710 \SpecialChar ~
28711 \SpecialChar ~
28712 \SpecialChar ~
28713 \SpecialChar ~
28714 \SpecialChar ~
28715 \SpecialChar ~
28716 \SpecialChar ~
28717  99\SpecialChar ~
28718 \SpecialChar ~
28719 \SpecialChar ~
28720 \SpecialChar ~
28721 \SpecialChar ~
28722 \SpecialChar ~
28723 \SpecialChar ~
28724 \SpecialChar ~
28725  mov\SpecialChar ~
28726 \SpecialChar ~
28727  (_foo_how2_1_1 + 1),(_glong + 2) 
28728 \layout Standard
28729
28730 Again, variations of these cases may 
28731 \emph on 
28732 not
28733 \emph default 
28734  be recognized.
28735  They are standard C expressions, so I heartily recommend these be the only
28736  way to get the higher order byte/word, (it is portable).
28737  Of course it will be recognized even if it is embedded in other expressions,
28738  e.g.:
28739 \layout Verse
28740
28741
28742 \family typewriter 
28743 xyz = gint + ((gint >> 8) & 0xFF);
28744 \layout Standard
28745
28746 will still be recognized.
28747 \layout Subsection
28748
28749 Peephole Optimizer
28750 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
28751
28752 \end_inset 
28753
28754
28755 \begin_inset LatexCommand \index{Peephole optimizer}
28756
28757 \end_inset 
28758
28759
28760 \layout Standard
28761
28762 The compiler uses a rule based, pattern matching and re-writing mechanism
28763  for peep-hole optimization.
28764  It is inspired by 
28765 \emph on 
28766 copt
28767 \emph default 
28768  a peep-hole optimizer by Christopher W.
28769  Fraser (cwfraser\SpecialChar ~
28770 @\SpecialChar ~
28771 microsoft.com).
28772  A default set of rules are compiled into the compiler, additional rules
28773  may be added with the 
28774 \emph on 
28775 -
28776 \begin_inset ERT
28777 status Collapsed
28778
28779 \layout Standard
28780
28781 \backslash 
28782 /
28783 \end_inset 
28784
28785 -peep-file
28786 \begin_inset LatexCommand \index{-\/-peep-file}
28787
28788 \end_inset 
28789
28790  <filename>
28791 \emph default 
28792  option.
28793  The rule language is best illustrated with examples.
28794 \layout Verse
28795
28796
28797 \family typewriter 
28798 replace { 
28799 \newline 
28800 \SpecialChar ~
28801 \SpecialChar ~
28802 mov %1,a 
28803 \newline 
28804 \SpecialChar ~
28805 \SpecialChar ~
28806 mov a,%1
28807 \newline 
28808 } by {
28809 \newline 
28810 \SpecialChar ~
28811 \SpecialChar ~
28812 mov %1,a
28813 \newline 
28814 }
28815 \layout Standard
28816
28817 The above rule will change the following assembly
28818 \begin_inset LatexCommand \index{Assembler routines}
28819
28820 \end_inset 
28821
28822  sequence:
28823 \layout Verse
28824
28825
28826 \family typewriter 
28827 mov r1,a 
28828 \newline 
28829 mov a,r1
28830 \layout Standard
28831
28832 to
28833 \layout Verse
28834
28835
28836 \family typewriter 
28837 mov r1,a
28838 \layout Standard
28839
28840 Note: All occurrences of a 
28841 \emph on 
28842 %n
28843 \emph default 
28844  (pattern variable) must denote the same string.
28845  With the above rule, the assembly sequence:
28846 \layout Verse
28847
28848
28849 \family typewriter 
28850 mov r1,a 
28851 \newline 
28852 mov a,r2
28853 \layout Standard
28854
28855 will remain unmodified.
28856 \newline 
28857
28858 \newline 
28859 Other special case optimizations may be added by the user (via 
28860 \emph on 
28861 -
28862 \begin_inset ERT
28863 status Collapsed
28864
28865 \layout Standard
28866
28867 \backslash 
28868 /
28869 \end_inset 
28870
28871 -peep-file option
28872 \emph default 
28873 ).
28874  E.g.
28875  some variants of the 8051 MCU
28876 \begin_inset LatexCommand \index{MCS51 variants}
28877
28878 \end_inset 
28879
28880  allow only 
28881 \family typewriter 
28882 ajmp
28883 \family default 
28884  and 
28885 \family typewriter 
28886 acall
28887 \family default 
28888 .
28889  The following two rules will change all 
28890 \family typewriter 
28891 ljmp
28892 \family default 
28893  and 
28894 \family typewriter 
28895 lcall
28896 \family default 
28897  to 
28898 \family typewriter 
28899 ajmp
28900 \family default 
28901  and 
28902 \family typewriter 
28903 acall
28904 \layout Verse
28905
28906
28907 \family typewriter 
28908 replace { lcall %1 } by { acall %1 } 
28909 \newline 
28910 replace { ljmp %1 } by { ajmp %1 }
28911 \layout Standard
28912
28913 The 
28914 \emph on 
28915 inline-assembler code
28916 \emph default 
28917  is also passed through the peep hole optimizer, thus the peephole optimizer
28918  can also be used as an assembly level macro expander.
28919  The rules themselves are MCU dependent whereas the rule language infra-structur
28920 e is MCU independent.
28921  Peephole optimization rules for other MCU can be easily programmed using
28922  the rule language.
28923 \newline 
28924
28925 \newline 
28926 The syntax for a rule is as follows:
28927 \layout Verse
28928
28929
28930 \family typewriter 
28931 rule := replace [ restart ] '{' <assembly sequence> '
28932 \backslash 
28933 n' 
28934 \newline 
28935 \SpecialChar ~
28936  \SpecialChar ~
28937  \SpecialChar ~
28938  \SpecialChar ~
28939  \SpecialChar ~
28940  \SpecialChar ~
28941  \SpecialChar ~
28942  \SpecialChar ~
28943  \SpecialChar ~
28944  \SpecialChar ~
28945  \SpecialChar ~
28946  \SpecialChar ~
28947  \SpecialChar ~
28948  \SpecialChar ~
28949  '}' by '{' '
28950 \backslash 
28951 n' 
28952 \newline 
28953 \SpecialChar ~
28954  \SpecialChar ~
28955  \SpecialChar ~
28956  \SpecialChar ~
28957  \SpecialChar ~
28958  \SpecialChar ~
28959  \SpecialChar ~
28960  \SpecialChar ~
28961  \SpecialChar ~
28962  \SpecialChar ~
28963  \SpecialChar ~
28964  \SpecialChar ~
28965  \SpecialChar ~
28966  \SpecialChar ~
28967  \SpecialChar ~
28968  \SpecialChar ~
28969  <assembly sequence> '
28970 \backslash 
28971 n' 
28972 \newline 
28973 \SpecialChar ~
28974  \SpecialChar ~
28975  \SpecialChar ~
28976  \SpecialChar ~
28977  \SpecialChar ~
28978  \SpecialChar ~
28979  \SpecialChar ~
28980  \SpecialChar ~
28981  \SpecialChar ~
28982  \SpecialChar ~
28983  \SpecialChar ~
28984  \SpecialChar ~
28985  \SpecialChar ~
28986  \SpecialChar ~
28987  '}' [if <functionName> ] '
28988 \backslash 
28989 n' 
28990 \layout Standard
28991
28992 <assembly sequence> := assembly instruction (each instruction including
28993  labels must be on a separate line).
28994 \newline 
28995
28996 \newline 
28997 The optimizer will apply to the rules one by one from the top in the sequence
28998  of their appearance, it will terminate when all rules are exhausted.
28999  If the 'restart' option is specified, then the optimizer will start matching
29000  the rules again from the top, this option for a rule is expensive (performance)
29001 , it is intended to be used in situations where a transformation will trigger
29002  the same rule again.
29003  An example of this (not a good one, it has side effects) is the following
29004  rule:
29005 \layout Verse
29006
29007
29008 \family typewriter 
29009 replace restart { 
29010 \newline 
29011 \SpecialChar ~
29012 \SpecialChar ~
29013 pop %1 
29014 \newline 
29015 \SpecialChar ~
29016 \SpecialChar ~
29017 push %1 } by { 
29018 \newline 
29019 \SpecialChar ~
29020 \SpecialChar ~
29021 ; nop 
29022 \newline 
29023 }
29024 \layout Standard
29025
29026 Note that the replace pattern cannot be a blank, but can be a comment line.
29027  Without the 'restart' option only the innermost 'pop' 'push' pair would
29028  be eliminated, i.e.:
29029 \layout Verse
29030
29031
29032 \family typewriter 
29033 pop ar1 
29034 \newline 
29035 pop ar2 
29036 \newline 
29037 push ar2 
29038 \newline 
29039 push ar1
29040 \layout Standard
29041
29042 would result in:
29043 \layout Verse
29044
29045
29046 \family typewriter 
29047 pop ar1 
29048 \newline 
29049 ; nop 
29050 \newline 
29051 push ar1
29052 \layout Standard
29053
29054
29055 \emph on 
29056 with
29057 \emph default 
29058  the restart option the rule will be applied again to the resulting code
29059  and then all the pop-push pairs will be eliminated to yield:
29060 \layout Verse
29061
29062
29063 \family typewriter 
29064 ; nop 
29065 \newline 
29066 ; nop
29067 \layout Standard
29068
29069 A conditional function can be attached to a rule.
29070  Attaching rules are somewhat more involved, let me illustrate this with
29071  an example.
29072 \layout Verse
29073
29074
29075 \family typewriter 
29076 replace { 
29077 \newline 
29078 \SpecialChar ~
29079  \SpecialChar ~
29080  \SpecialChar ~
29081 ljmp %5 
29082 \newline 
29083 %2:
29084 \newline 
29085 } by { 
29086 \newline 
29087 \SpecialChar ~
29088  \SpecialChar ~
29089  \SpecialChar ~
29090 sjmp %5 
29091 \newline 
29092 %2:
29093 \newline 
29094 } if labelInRange
29095 \layout Standard
29096
29097 The optimizer does a look-up of a function name table defined in function
29098  
29099 \emph on 
29100 callFuncByName
29101 \emph default 
29102  in the source file SDCCpeeph.c, with the name 
29103 \emph on 
29104 labelInRange
29105 \emph default 
29106 .
29107  If it finds a corresponding entry the function is called.
29108  Note there can be no parameters specified for these functions, in this
29109  case the use of 
29110 \emph on 
29111 %5
29112 \emph default 
29113  is crucial, since the function 
29114 \emph on 
29115 labelInRange
29116 \emph default 
29117  expects to find the label in that particular variable (the hash table containin
29118 g the variable bindings is passed as a parameter).
29119  If you want to code more such functions, take a close look at the function
29120  labelInRange and the calling mechanism in source file SDCCpeeph.c.
29121  Currently implemented are 
29122 \emph on 
29123 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
29124  24bitMode, portIsDS390, 24bitModeAndPortDS390 
29125 \emph default 
29126 and
29127 \emph on 
29128  notVolatile
29129 \emph default 
29130 .
29131 \layout Standard
29132
29133 I know this whole thing is a little kludgey, but maybe some day we will
29134  have some better means.
29135  If you are looking at this file, you will see the default rules that are
29136  compiled into the compiler, you can add your own rules in the default set
29137  there if you get tired of specifying the -
29138 \begin_inset ERT
29139 status Collapsed
29140
29141 \layout Standard
29142
29143 \backslash 
29144 /
29145 \end_inset 
29146
29147 -peep-file option.
29148 \layout Section
29149
29150 ANSI-Compliance
29151 \begin_inset LatexCommand \index{ANSI-compliance}
29152
29153 \end_inset 
29154
29155
29156 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
29157
29158 \end_inset 
29159
29160
29161 \layout Standard
29162
29163 The latest publically available version of the standard 
29164 \emph on 
29165 ISO/IEC 9899 - Programming languages - C
29166 \emph default 
29167  should be available at: 
29168 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29169
29170 \end_inset 
29171
29172 .
29173 \newline 
29174
29175 \layout Standard
29176
29177 Deviations from the compliance:
29178 \layout Itemize
29179
29180 functions are not reentrant
29181 \begin_inset LatexCommand \index{reentrant}
29182
29183 \end_inset 
29184
29185  unless explicitly declared as such or the 
29186 \series bold 
29187 -
29188 \begin_inset ERT
29189 status Collapsed
29190
29191 \layout Standard
29192
29193 \backslash 
29194 /
29195 \end_inset 
29196
29197 -stack-auto
29198 \begin_inset LatexCommand \index{-\/-stack-auto}
29199
29200 \end_inset 
29201
29202
29203 \series default 
29204  command line option is specified.
29205 \layout Itemize
29206
29207 structures
29208 \begin_inset LatexCommand \index{struct}
29209
29210 \end_inset 
29211
29212  and unions
29213 \begin_inset LatexCommand \index{union}
29214
29215 \end_inset 
29216
29217  cannot be assigned values directly, cannot be passed as function parameters
29218  or assigned to each other and cannot be a return value
29219 \begin_inset LatexCommand \index{return value}
29220
29221 \end_inset 
29222
29223  from a function, e.g.:
29224 \begin_deeper 
29225 \layout Verse
29226
29227
29228 \family typewriter 
29229 struct s { ...
29230  }; 
29231 \newline 
29232 struct s s1, s2; 
29233 \newline 
29234 foo() 
29235 \newline 
29236
29237 \newline 
29238 \SpecialChar ~
29239 \SpecialChar ~
29240 \SpecialChar ~
29241 \SpecialChar ~
29242 ...
29243  
29244 \newline 
29245 \SpecialChar ~
29246 \SpecialChar ~
29247 \SpecialChar ~
29248 \SpecialChar ~
29249 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
29250 \newline 
29251 \SpecialChar ~
29252 \SpecialChar ~
29253 \SpecialChar ~
29254 \SpecialChar ~
29255 ...
29256  
29257 \newline 
29258 }
29259 \newline 
29260
29261 \series bold 
29262 struct
29263 \series default 
29264  s foo1 (
29265 \series bold 
29266 struct
29267 \series default 
29268  s parms) /* invalid in SDCC although allowed in ANSI */
29269 \newline 
29270
29271 \newline 
29272 \SpecialChar ~
29273 \SpecialChar ~
29274 \SpecialChar ~
29275 \SpecialChar ~
29276 struct s rets; 
29277 \newline 
29278 \SpecialChar ~
29279 \SpecialChar ~
29280 \SpecialChar ~
29281 \SpecialChar ~
29282 ...
29283  
29284 \newline 
29285 \SpecialChar ~
29286 \SpecialChar ~
29287 \SpecialChar ~
29288 \SpecialChar ~
29289 return rets; /* is invalid in SDCC although allowed in ANSI */ 
29290 \newline 
29291 }
29292 \end_deeper 
29293 \layout Itemize
29294
29295 initialization of structure arrays must be fully braced.
29296 \begin_deeper 
29297 \layout Verse
29298
29299
29300 \family typewriter 
29301 struct s { char x } a[] = {1, 2};\SpecialChar ~
29302 \SpecialChar ~
29303 \SpecialChar ~
29304 \SpecialChar ~
29305 \SpecialChar ~
29306 /* invalid in SDCC */
29307 \newline 
29308 struct s { char x } a[] = {{1}, {2}}; /* OK */
29309 \end_deeper 
29310 \layout Itemize
29311
29312 'long long
29313 \begin_inset LatexCommand \index{long long (not supported)}
29314
29315 \end_inset 
29316
29317 ' (64 bit integers
29318 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29319
29320 \end_inset 
29321
29322 ) not supported.
29323 \layout Itemize
29324
29325 'double
29326 \begin_inset LatexCommand \index{double (not supported)}
29327
29328 \end_inset 
29329
29330 ' precision floating point 
29331 \begin_inset LatexCommand \index{Floating point support}
29332
29333 \end_inset 
29334
29335 not supported.
29336 \layout Itemize
29337
29338 Old K&R style
29339 \begin_inset LatexCommand \index{K\&R style}
29340
29341 \end_inset 
29342
29343  function declarations are NOT allowed.
29344 \begin_deeper 
29345 \layout Verse
29346
29347
29348 \family typewriter 
29349 foo(i,j) /* this old style of function declarations */ 
29350 \newline 
29351 int i,j; /* are valid in ANSI but not valid in SDCC */ 
29352 \newline 
29353
29354 \newline 
29355 \SpecialChar ~
29356 \SpecialChar ~
29357 \SpecialChar ~
29358 \SpecialChar ~
29359 ...
29360  
29361 \newline 
29362 }
29363 \end_deeper 
29364 \layout Itemize
29365
29366 Most enhancements in C99 are not supported, f.e.:
29367 \begin_deeper 
29368 \layout Verse
29369
29370
29371 \family typewriter 
29372 \series bold 
29373 inline
29374 \begin_inset LatexCommand \index{inline (not supported)}
29375
29376 \end_inset 
29377
29378
29379 \series default 
29380  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29381  in C99.
29382  An empty define 
29383 \emph on 
29384 #define inline
29385 \emph default 
29386  can be used as a work around */
29387 \newline 
29388
29389 \newline 
29390 for (
29391 \series bold 
29392 int
29393 \series default 
29394  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29395 \end_deeper 
29396 \layout Itemize
29397
29398 Certain words that are valid identifiers in the standard may be reserved
29399  words in SDCC unless the 
29400 \series bold 
29401 -
29402 \begin_inset ERT
29403 status Collapsed
29404
29405 \layout Standard
29406
29407 \backslash 
29408 /
29409 \end_inset 
29410
29411 -std-c89
29412 \begin_inset LatexCommand \index{-\/-std-c89}
29413
29414 \end_inset 
29415
29416  or -
29417 \begin_inset ERT
29418 status Collapsed
29419
29420 \layout Standard
29421
29422 \backslash 
29423 /
29424 \end_inset 
29425
29426 -std-c99
29427 \begin_inset LatexCommand \index{-\/-std-c99}
29428
29429 \end_inset 
29430
29431
29432 \series default 
29433  command line options are used.
29434  These may include (depending on the selected processor): 'at', 'banked',
29435  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29436 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29437  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29438  '_naked'.
29439  Compliant equivalents of these keywords are always available in a form
29440  that begin with two underscores
29441 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29442
29443 \end_inset 
29444
29445 , f.e.
29446  '__data' instead of 'data'.
29447 \layout Section
29448
29449 Cyclomatic Complexity
29450 \begin_inset LatexCommand \index{Cyclomatic complexity}
29451
29452 \end_inset 
29453
29454
29455 \layout Standard
29456
29457 Cyclomatic complexity of a function is defined as the number of independent
29458  paths the program can take during execution of the function.
29459  This is an important number since it defines the number test cases you
29460  have to generate to validate the function.
29461  The accepted industry standard for complexity number is 10, if the cyclomatic
29462  complexity reported by SDCC exceeds 10 you should think about simplification
29463  of the function logic.
29464  Note that the complexity level is not related to the number of lines of
29465  code in a function.
29466  Large functions can have low complexity, and small functions can have large
29467  complexity levels.
29468  
29469 \newline 
29470
29471 \newline 
29472 SDCC uses the following formula to compute the complexity:
29473 \newline 
29474
29475 \layout Standard
29476
29477 complexity = (number of edges in control flow graph) - (number of nodes
29478  in control flow graph) + 2;
29479 \newline 
29480
29481 \newline 
29482 Having said that the industry standard is 10, you should be aware that in
29483  some cases it be may unavoidable to have a complexity level of less than
29484  10.
29485  For example if you have switch statement with more than 10 case labels,
29486  each case label adds one to the complexity level.
29487  The complexity level is by no means an absolute measure of the algorithmic
29488  complexity of the function, it does however provide a good starting point
29489  for which functions you might look at for further optimization.
29490 \layout Section
29491
29492 Retargetting for other Processors
29493 \layout Standard
29494
29495 The issues for retargetting the compiler are far too numerous to be covered
29496  by this document.
29497  What follows is a brief description of each of the seven phases of the
29498  compiler and its MCU dependency.
29499 \layout Itemize
29500
29501 Parsing the source and building the annotated parse tree.
29502  This phase is largely MCU independent (except for the language extensions).
29503  Syntax & semantic checks are also done in this phase, along with some initial
29504  optimizations like back patching labels and the pattern matching optimizations
29505  like bit-rotation etc.
29506 \layout Itemize
29507
29508 The second phase involves generating an intermediate code which can be easy
29509  manipulated during the later phases.
29510  This phase is entirely MCU independent.
29511  The intermediate code generation assumes the target machine has unlimited
29512  number of registers, and designates them with the name iTemp.
29513  The compiler can be made to dump a human readable form of the code generated
29514  by using the -
29515 \begin_inset ERT
29516 status Collapsed
29517
29518 \layout Standard
29519
29520 \backslash 
29521 /
29522 \end_inset 
29523
29524 -dumpraw option.
29525 \layout Itemize
29526
29527 This phase does the bulk of the standard optimizations and is also MCU independe
29528 nt.
29529  This phase can be broken down into several sub-phases:
29530 \newline 
29531
29532 \newline 
29533 Break down intermediate code (iCode) into basic blocks.
29534 \newline 
29535 Do control flow & data flow analysis on the basic blocks.
29536 \newline 
29537 Do local common subexpression elimination, then global subexpression elimination
29538 \newline 
29539 Dead code elimination
29540 \newline 
29541 Loop optimizations
29542 \newline 
29543 If loop optimizations caused any changes then do 'global subexpression eliminati
29544 on' and 'dead code elimination' again.
29545 \layout Itemize
29546
29547 This phase determines the live-ranges; by live range I mean those iTemp
29548  variables defined by the compiler that still survive after all the optimization
29549 s.
29550  Live range analysis
29551 \begin_inset LatexCommand \index{Live range analysis}
29552
29553 \end_inset 
29554
29555  is essential for register allocation, since these computation determines
29556  which of these iTemps will be assigned to registers, and for how long.
29557 \layout Itemize
29558
29559 Phase five is register allocation.
29560  There are two parts to this process.
29561 \newline 
29562
29563 \newline 
29564 The first part I call 'register packing' (for lack of a better term).
29565  In this case several MCU specific expression folding is done to reduce
29566  register pressure.
29567 \newline 
29568
29569 \newline 
29570 The second part is more MCU independent and deals with allocating registers
29571  to the remaining live ranges.
29572  A lot of MCU specific code does creep into this phase because of the limited
29573  number of index registers available in the 8051.
29574 \layout Itemize
29575
29576 The Code generation phase is (unhappily), entirely MCU dependent and very
29577  little (if any at all) of this code can be reused for other MCU.
29578  However the scheme for allocating a homogenized assembler operand for each
29579  iCode operand may be reused.
29580 \layout Itemize
29581
29582 As mentioned in the optimization section the peep-hole optimizer is rule
29583  based system, which can reprogrammed for other MCUs.
29584 \layout Chapter
29585
29586 Compiler internals
29587 \begin_inset LatexCommand \index{Compiler internals}
29588
29589 \end_inset 
29590
29591
29592 \layout Section
29593
29594 The anatomy of the compiler
29595 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29596
29597 \end_inset 
29598
29599
29600 \layout Standard
29601
29602
29603 \shape italic 
29604 This is an excerpt from an article published in Circuit Cellar Magazine
29605  in 
29606 \series bold 
29607 August 2000
29608 \series default 
29609 .
29610  It's a little outdated (the compiler is much more efficient now and user/develo
29611 per friendly), but pretty well exposes the guts of it all.
29612 \shape default 
29613
29614 \newline 
29615
29616 \newline 
29617 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
29618  It is fairly easy to retarget for other 8-bit MCU.
29619  Here we take a look at some of the internals of the compiler.
29620  
29621 \layout Paragraph*
29622
29623 Parsing
29624 \begin_inset LatexCommand \index{Parsing}
29625
29626 \end_inset 
29627
29628  
29629 \layout Standard
29630
29631 Parsing the input source file and creating an AST (Annotated Syntax Tree
29632 \begin_inset LatexCommand \index{Annotated syntax tree}
29633
29634 \end_inset 
29635
29636 ).
29637  This phase also involves propagating types (annotating each node of the
29638  parse tree with type information) and semantic analysis.
29639  There are some MCU specific parsing rules.
29640  For example the storage classes, the extended storage classes are MCU specific
29641  while there may be a xdata storage class for 8051 there is no such storage
29642  class for z80 or Atmel AVR.
29643  SDCC allows MCU specific storage class extensions, i.e.
29644  xdata will be treated as a storage class specifier when parsing 8051 C
29645  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
29646  C code.
29647 \layout Paragraph*
29648
29649 Generating iCode
29650 \begin_inset LatexCommand \index{iCode}
29651
29652 \end_inset 
29653
29654
29655 \layout Standard
29656
29657 Intermediate code generation.
29658  In this phase the AST is broken down into three-operand form (iCode).
29659  These three operand forms are represented as doubly linked lists.
29660  ICode is the term given to the intermediate form generated by the compiler.
29661  ICode example section shows some examples of iCode generated for some simple
29662  C source functions.
29663 \layout Paragraph*
29664
29665 Optimizations
29666 \begin_inset LatexCommand \index{Optimizations}
29667
29668 \end_inset 
29669
29670 .
29671 \layout Standard
29672
29673 Bulk of the target independent optimizations is performed in this phase.
29674  The optimizations include constant propagation, common sub-expression eliminati
29675 on, loop invariant code movement, strength reduction of loop induction variables
29676  and dead-code elimination.
29677 \layout Paragraph*
29678
29679 Live range analysis
29680 \begin_inset LatexCommand \index{Live range analysis}
29681
29682 \end_inset 
29683
29684
29685 \layout Standard
29686
29687 During intermediate code generation phase, the compiler assumes the target
29688  machine has infinite number of registers and generates a lot of temporary
29689  variables.
29690  The live range computation determines the lifetime of each of these compiler-ge
29691 nerated temporaries.
29692  A picture speaks a thousand words.
29693  ICode example sections show the live range annotations for each of the
29694  operand.
29695  It is important to note here, each iCode is assigned a number in the order
29696  of its execution in the function.
29697  The live ranges are computed in terms of these numbers.
29698  The from number is the number of the iCode which first defines the operand
29699  and the to number signifies the iCode which uses this operand last.
29700 \layout Paragraph*
29701
29702 Register Allocation
29703 \begin_inset LatexCommand \index{Register allocation}
29704
29705 \end_inset 
29706
29707
29708 \layout Standard
29709
29710 The register allocation determines the type and number of registers needed
29711  by each operand.
29712  In most MCUs only a few registers can be used for indirect addressing.
29713  In case of 8051 for example the registers R0 & R1 can be used to indirectly
29714  address the internal ram and DPTR to indirectly address the external ram.
29715  The compiler will try to allocate the appropriate register to pointer variables
29716  if it can.
29717  ICode example section shows the operands annotated with the registers assigned
29718  to them.
29719  The compiler will try to keep operands in registers as much as possible;
29720  there are several schemes the compiler uses to do achieve this.
29721  When the compiler runs out of registers the compiler will check to see
29722  if there are any live operands which is not used or defined in the current
29723  basic block being processed, if there are any found then it will push that
29724  operand and use the registers in this block, the operand will then be popped
29725  at the end of the basic block.
29726  
29727 \layout Standard
29728
29729 There are other MCU specific considerations in this phase.
29730  Some MCUs have an accumulator; very short-lived operands could be assigned
29731  to the accumulator instead of a general-purpose register.
29732 \layout Paragraph*
29733
29734 Code generation
29735 \layout Standard
29736
29737 Figure II gives a table of iCode operations supported by the compiler.
29738  The code generation involves translating these operations into corresponding
29739  assembly code for the processor.
29740  This sounds overly simple but that is the essence of code generation.
29741  Some of the iCode operations are generated on a MCU specific manner for
29742  example, the z80 port does not use registers to pass parameters so the
29743  SEND and RECV iCode operations will not be generated, and it also does
29744  not support JUMPTABLES.
29745  
29746 \newline 
29747
29748 \series bold 
29749 \shape italic 
29750 \color red
29751 <Where is Figure II?>
29752 \layout Comment
29753
29754 In the original article Figure II was announced to be downloadable on 
29755 \shape italic 
29756 Circuit Cellar
29757 \shape default 
29758 's web site.
29759  Unfortunately it never seemed to have shown up there, so: where is Figure
29760  II?
29761 \layout Paragraph*
29762
29763 ICode Example
29764 \begin_inset LatexCommand \index{iCode}
29765
29766 \end_inset 
29767
29768
29769 \layout Standard
29770
29771 This section shows some details of iCode.
29772  The example C code does not do anything useful; it is used as an example
29773  to illustrate the intermediate code generated by the compiler.
29774 \layout Verse
29775
29776
29777 \family typewriter 
29778 1.\SpecialChar ~
29779 xdata int * p;
29780 \newline 
29781 2.\SpecialChar ~
29782 int gint;
29783 \newline 
29784 3.\SpecialChar ~
29785 /* This function does nothing useful.
29786  It is used
29787 \newline 
29788 4.\SpecialChar ~
29789 \SpecialChar ~
29790 \SpecialChar ~
29791 \SpecialChar ~
29792 for the purpose of explaining iCode */
29793 \newline 
29794 5.\SpecialChar ~
29795 short function (data int *x)
29796 \newline 
29797 6.\SpecialChar ~
29798 {
29799 \newline 
29800 7.\SpecialChar ~
29801 \SpecialChar ~
29802 \SpecialChar ~
29803 short i=10; \SpecialChar ~
29804 \SpecialChar ~
29805 /* dead initialization eliminated */
29806 \newline 
29807 8.\SpecialChar ~
29808 \SpecialChar ~
29809 \SpecialChar ~
29810 short sum=10; /* dead initialization eliminated */
29811 \newline 
29812 9.\SpecialChar ~
29813 \SpecialChar ~
29814 \SpecialChar ~
29815 short mul;
29816 \newline 
29817 10.\SpecialChar ~
29818 \SpecialChar ~
29819 int j ;
29820 \newline 
29821 11.\SpecialChar ~
29822 \SpecialChar ~
29823 while (*x) *x++ = *p++; 
29824 \newline 
29825 12.\SpecialChar ~
29826 \SpecialChar ~
29827 \SpecialChar ~
29828 \SpecialChar ~
29829 sum = 0 ; 
29830 \newline 
29831 13.\SpecialChar ~
29832 \SpecialChar ~
29833 mul = 0;
29834 \newline 
29835 14.\SpecialChar ~
29836 \SpecialChar ~
29837 /* compiler detects i,j to be induction variables */
29838 \newline 
29839 15.\SpecialChar ~
29840 \SpecialChar ~
29841 for (i = 0, j = 10 ; i < 10 ; i++, j
29842 \family default 
29843 -
29844 \begin_inset ERT
29845 status Collapsed
29846
29847 \layout Standard
29848
29849 \backslash 
29850 /
29851 \end_inset 
29852
29853 -
29854 \family typewriter 
29855 ) {
29856 \newline 
29857 16.\SpecialChar ~
29858 \SpecialChar ~
29859 \SpecialChar ~
29860 \SpecialChar ~
29861 sum += i;
29862 \newline 
29863 17.\SpecialChar ~
29864 \SpecialChar ~
29865 \SpecialChar ~
29866 \SpecialChar ~
29867 mul += i * 3; \SpecialChar ~
29868 \SpecialChar ~
29869 /* this multiplication remains */
29870 \newline 
29871 18.\SpecialChar ~
29872 \SpecialChar ~
29873 \SpecialChar ~
29874 \SpecialChar ~
29875 gint += j * 3;\SpecialChar ~
29876 \SpecialChar ~
29877 /* this multiplication changed to addition */
29878 \newline 
29879 19.\SpecialChar ~
29880 \SpecialChar ~
29881 }
29882 \newline 
29883 20.\SpecialChar ~
29884 \SpecialChar ~
29885 return sum+mul;
29886 \newline 
29887 21.\SpecialChar ~
29888 }
29889 \layout Standard
29890
29891 In addition to the operands each iCode contains information about the filename
29892  and line it corresponds to in the source file.
29893  The first field in the listing should be interpreted as follows:
29894 \newline 
29895
29896 \shape italic 
29897 \size footnotesize 
29898 Filename(linenumber: iCode Execution sequence number : ICode hash table
29899  key : loop depth of the iCode).
29900 \shape default 
29901 \size default 
29902
29903 \newline 
29904 Then follows the human readable form of the ICode operation.
29905  Each operand of this triplet form can be of three basic types a) compiler
29906  generated temporary b) user defined variable c) a constant value.
29907  Note that local variables and parameters are replaced by compiler generated
29908  temporaries.
29909  Live ranges
29910 \begin_inset LatexCommand \index{Live range analysis}
29911
29912 \end_inset 
29913
29914  are computed only for temporaries (i.e.
29915  live ranges are not computed for global variables).
29916  Registers
29917 \begin_inset LatexCommand \index{Register allocation}
29918
29919 \end_inset 
29920
29921  are allocated for temporaries only.
29922  Operands are formatted in the following manner:
29923 \newline 
29924
29925 \shape italic 
29926 \size footnotesize 
29927 Operand Name [lr live-from : live-to ] { type information } [ registers
29928  allocated ].
29929 \shape default 
29930 \size default 
29931
29932 \newline 
29933 As mentioned earlier the live ranges are computed in terms of the execution
29934  sequence number of the iCodes, for example 
29935 \newline 
29936 the iTemp0 is live from (i.e.
29937  first defined in iCode with execution sequence number 3, and is last used
29938  in the iCode with sequence number 5).
29939  For induction variables such as iTemp21 the live range computation extends
29940  the lifetime from the start to the end of the loop.
29941 \newline 
29942 The register allocator used the live range information to allocate registers,
29943  the same registers may be used for different temporaries if their live
29944  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
29945  iTemp17 since their live ranges do not overlap.
29946  In addition the allocator also takes into consideration the type and usage
29947  of a temporary, for example itemp6 is a pointer to near space and is used
29948  as to fetch data from (i.e.
29949  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
29950  Some short lived temporaries are allocated to special registers which have
29951  meaning to the code generator e.g.
29952  iTemp13 is allocated to a pseudo register CC which tells the back end that
29953  the temporary is used only for a conditional jump the code generation makes
29954  use of this information to optimize a compare and jump ICode.
29955 \newline 
29956 There are several loop optimizations
29957 \begin_inset LatexCommand \index{Loop optimization}
29958
29959 \end_inset 
29960
29961  performed by the compiler.
29962  It can detect induction variables iTemp21(i) and iTemp23(j).
29963  Also note the compiler does selective strength reduction
29964 \begin_inset LatexCommand \index{Strength reduction}
29965
29966 \end_inset 
29967
29968 , i.e.
29969  the multiplication of an induction variable in line 18 (gint = j * 3) is
29970  changed to addition, a new temporary iTemp17 is allocated and assigned
29971  a initial value, a constant 3 is then added for each iteration of the loop.
29972  The compiler does not change the multiplication
29973 \begin_inset LatexCommand \index{Multiplication}
29974
29975 \end_inset 
29976
29977  in line 17 however since the processor does support an 8 * 8 bit multiplication.
29978 \newline 
29979 Note the dead code elimination
29980 \begin_inset LatexCommand \index{Dead-code elimination}
29981
29982 \end_inset 
29983
29984  optimization eliminated the dead assignments in line 7 & 8 to I and sum
29985  respectively.
29986 \newline 
29987
29988 \layout Standard
29989
29990
29991 \size footnotesize 
29992 Sample.c (5:1:0:0) _entry($9) :
29993 \layout Standard
29994
29995
29996 \size footnotesize 
29997 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
29998 \layout Standard
29999
30000
30001 \size footnotesize 
30002 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
30003 \layout Standard
30004
30005
30006 \size footnotesize 
30007 Sample.c(11:4:53:0) preHeaderLbl0($11) :
30008 \layout Standard
30009
30010
30011 \size footnotesize 
30012 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
30013  * int}[r2]
30014 \layout Standard
30015
30016
30017 \size footnotesize 
30018 Sample.c(11:6:5:1) _whilecontinue_0($1) :
30019 \layout Standard
30020
30021
30022 \size footnotesize 
30023 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
30024  int}[r0]]
30025 \layout Standard
30026
30027
30028 \size footnotesize 
30029 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
30030 \layout Standard
30031
30032
30033 \size footnotesize 
30034 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
30035  * int}
30036 \layout Standard
30037
30038
30039 \size footnotesize 
30040 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
30041  {short}
30042 \layout Standard
30043
30044
30045 \size footnotesize 
30046 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
30047  * int}[DPTR]]
30048 \layout Standard
30049
30050
30051 \size footnotesize 
30052 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
30053 }[r2 r3]
30054 \layout Standard
30055
30056
30057 \size footnotesize 
30058 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
30059  * int}[r0] + 0x2 {short}
30060 \layout Standard
30061
30062
30063 \size footnotesize 
30064 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
30065 \layout Standard
30066
30067
30068 \size footnotesize 
30069 Sample.c(11:17:21:0)_whilebreak_0($3) :
30070 \layout Standard
30071
30072
30073 \size footnotesize 
30074 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
30075 \layout Standard
30076
30077
30078 \size footnotesize 
30079 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
30080 \layout Standard
30081
30082
30083 \size footnotesize 
30084 Sample.c(15:20:54:0)preHeaderLbl1($13) :
30085 \layout Standard
30086
30087
30088 \size footnotesize 
30089 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
30090 \layout Standard
30091
30092
30093 \size footnotesize 
30094 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
30095 \layout Standard
30096
30097
30098 \size footnotesize 
30099 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
30100 \layout Standard
30101
30102
30103 \size footnotesize 
30104 Sample.c(15:24:26:1)_forcond_0($4) :
30105 \layout Standard
30106
30107
30108 \size footnotesize 
30109 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
30110  < 0xa {short}
30111 \layout Standard
30112
30113
30114 \size footnotesize 
30115 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
30116 \layout Standard
30117
30118
30119 \size footnotesize 
30120 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
30121  + ITemp21 [lr21:38]{short}[r4]
30122 \layout Standard
30123
30124
30125 \size footnotesize 
30126 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
30127  * 0x3 {short}
30128 \layout Standard
30129
30130
30131 \size footnotesize 
30132 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
30133  + iTemp15 [lr29:30]{short}[r1]
30134 \layout Standard
30135
30136
30137 \size footnotesize 
30138 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
30139  r0]- 0x3 {short}
30140 \layout Standard
30141
30142
30143 \size footnotesize 
30144 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
30145 int}[r7 r0]
30146 \layout Standard
30147
30148
30149 \size footnotesize 
30150 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
30151  + 0x1 {short}
30152 \layout Standard
30153
30154
30155 \size footnotesize 
30156 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
30157  r6]- 0x1 {short}
30158 \layout Standard
30159
30160
30161 \size footnotesize 
30162 Sample.c(19:38:47:1) goto _forcond_0($4)
30163 \layout Standard
30164
30165
30166 \size footnotesize 
30167 Sample.c(19:39:48:0)_forbreak_0($7) :
30168 \layout Standard
30169
30170
30171 \size footnotesize 
30172 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
30173  + ITemp11 [lr19:40]{short}[r3]
30174 \layout Standard
30175
30176
30177 \size footnotesize 
30178 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
30179 \layout Standard
30180
30181
30182 \size footnotesize 
30183 Sample.c(20:42:51:0)_return($8) :
30184 \layout Standard
30185
30186
30187 \size footnotesize 
30188 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
30189 \size default 
30190
30191 \newline 
30192
30193 \newline 
30194 Finally the code generated for this function:
30195 \newline 
30196
30197 \layout Standard
30198
30199
30200 \size footnotesize 
30201 .area DSEG (DATA)
30202 \layout Standard
30203
30204
30205 \size footnotesize 
30206 _p::
30207 \layout Standard
30208
30209
30210 \size footnotesize 
30211 \SpecialChar ~
30212 \SpecialChar ~
30213 .ds 2
30214 \layout Standard
30215
30216
30217 \size footnotesize 
30218 _gint::
30219 \layout Standard
30220
30221
30222 \size footnotesize 
30223 \SpecialChar ~
30224 \SpecialChar ~
30225 .ds 2
30226 \layout Standard
30227
30228
30229 \size footnotesize 
30230 ; sample.c 5
30231 \layout Standard
30232
30233
30234 \size footnotesize 
30235 ; ----------------------------------------------
30236 \layout Standard
30237
30238
30239 \size footnotesize 
30240 ; function function
30241 \layout Standard
30242
30243
30244 \size footnotesize 
30245 ; ----------------------------------------------
30246 \layout Standard
30247
30248
30249 \size footnotesize 
30250 _function:
30251 \layout Standard
30252
30253
30254 \size footnotesize 
30255 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
30256 \layout Standard
30257
30258
30259 \size footnotesize 
30260 \SpecialChar ~
30261 \SpecialChar ~
30262 mov r2,dpl
30263 \layout Standard
30264
30265
30266 \size footnotesize 
30267 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
30268 \layout Standard
30269
30270
30271 \size footnotesize 
30272 \SpecialChar ~
30273 \SpecialChar ~
30274 mov ar0,r2
30275 \layout Standard
30276
30277
30278 \size footnotesize 
30279 ;_whilecontinue_0($1) :
30280 \layout Standard
30281
30282
30283 \size footnotesize 
30284 00101$:
30285 \layout Standard
30286
30287
30288 \size footnotesize 
30289 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
30290 \layout Standard
30291
30292
30293 \size footnotesize 
30294 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
30295 \layout Standard
30296
30297
30298 \size footnotesize 
30299 \SpecialChar ~
30300 \SpecialChar ~
30301 mov ar2,@r0
30302 \layout Standard
30303
30304
30305 \size footnotesize 
30306 \SpecialChar ~
30307 \SpecialChar ~
30308 inc r0
30309 \layout Standard
30310
30311
30312 \size footnotesize 
30313 \SpecialChar ~
30314 \SpecialChar ~
30315 mov ar3,@r0
30316 \layout Standard
30317
30318
30319 \size footnotesize 
30320 \SpecialChar ~
30321 \SpecialChar ~
30322 dec r0
30323 \layout Standard
30324
30325
30326 \size footnotesize 
30327 \SpecialChar ~
30328 \SpecialChar ~
30329 mov a,r2
30330 \layout Standard
30331
30332
30333 \size footnotesize 
30334 \SpecialChar ~
30335 \SpecialChar ~
30336 orl a,r3
30337 \layout Standard
30338
30339
30340 \size footnotesize 
30341 \SpecialChar ~
30342 \SpecialChar ~
30343 jz 00103$
30344 \layout Standard
30345
30346
30347 \size footnotesize 
30348 00114$:
30349 \layout Standard
30350
30351
30352 \size footnotesize 
30353 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
30354 \layout Standard
30355
30356
30357 \size footnotesize 
30358 \SpecialChar ~
30359 \SpecialChar ~
30360 mov dpl,_p
30361 \layout Standard
30362
30363
30364 \size footnotesize 
30365 \SpecialChar ~
30366 \SpecialChar ~
30367 mov dph,(_p + 1)
30368 \layout Standard
30369
30370
30371 \size footnotesize 
30372 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
30373 \layout Standard
30374
30375
30376 \size footnotesize 
30377 \SpecialChar ~
30378 \SpecialChar ~
30379 mov a,#0x02
30380 \layout Standard
30381
30382
30383 \size footnotesize 
30384 \SpecialChar ~
30385 \SpecialChar ~
30386 add a,_p
30387 \layout Standard
30388
30389
30390 \size footnotesize 
30391 \SpecialChar ~
30392 \SpecialChar ~
30393 mov _p,a
30394 \layout Standard
30395
30396
30397 \size footnotesize 
30398 \SpecialChar ~
30399 \SpecialChar ~
30400 clr a
30401 \layout Standard
30402
30403
30404 \size footnotesize 
30405 \SpecialChar ~
30406 \SpecialChar ~
30407 addc a,(_p + 1)
30408 \layout Standard
30409
30410
30411 \size footnotesize 
30412 \SpecialChar ~
30413 \SpecialChar ~
30414 mov (_p + 1),a
30415 \layout Standard
30416
30417
30418 \size footnotesize 
30419 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
30420 \layout Standard
30421
30422
30423 \size footnotesize 
30424 \SpecialChar ~
30425 \SpecialChar ~
30426 movx a,@dptr
30427 \layout Standard
30428
30429
30430 \size footnotesize 
30431 \SpecialChar ~
30432 \SpecialChar ~
30433 mov r2,a
30434 \layout Standard
30435
30436
30437 \size footnotesize 
30438 \SpecialChar ~
30439 \SpecialChar ~
30440 inc dptr
30441 \layout Standard
30442
30443
30444 \size footnotesize 
30445 \SpecialChar ~
30446 \SpecialChar ~
30447 movx a,@dptr
30448 \layout Standard
30449
30450
30451 \size footnotesize 
30452 \SpecialChar ~
30453 \SpecialChar ~
30454 mov r3,a
30455 \layout Standard
30456
30457
30458 \size footnotesize 
30459 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
30460 \layout Standard
30461
30462
30463 \size footnotesize 
30464 \SpecialChar ~
30465 \SpecialChar ~
30466 mov @r0,ar2
30467 \layout Standard
30468
30469
30470 \size footnotesize 
30471 \SpecialChar ~
30472 \SpecialChar ~
30473 inc r0
30474 \layout Standard
30475
30476
30477 \size footnotesize 
30478 \SpecialChar ~
30479 \SpecialChar ~
30480 mov @r0,ar3
30481 \layout Standard
30482
30483
30484 \size footnotesize 
30485 ; iTemp6 [lr5:16]{_near * int}[r0] = 
30486 \layout Standard
30487
30488
30489 \size footnotesize 
30490 ; iTemp6 [lr5:16]{_near * int}[r0] + 
30491 \layout Standard
30492
30493
30494 \size footnotesize 
30495 ; 0x2 {short}
30496 \layout Standard
30497
30498
30499 \size footnotesize 
30500 \SpecialChar ~
30501 \SpecialChar ~
30502 inc r0
30503 \layout Standard
30504
30505
30506 \size footnotesize 
30507 ; goto _whilecontinue_0($1)
30508 \layout Standard
30509
30510
30511 \size footnotesize 
30512 \SpecialChar ~
30513 \SpecialChar ~
30514 sjmp 00101$
30515 \layout Standard
30516
30517
30518 \size footnotesize 
30519 ; _whilebreak_0($3) :
30520 \layout Standard
30521
30522
30523 \size footnotesize 
30524 00103$:
30525 \layout Standard
30526
30527
30528 \size footnotesize 
30529 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
30530 \layout Standard
30531
30532
30533 \size footnotesize 
30534 \SpecialChar ~
30535 \SpecialChar ~
30536 mov r2,#0x00
30537 \layout Standard
30538
30539
30540 \size footnotesize 
30541 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
30542 \layout Standard
30543
30544
30545 \size footnotesize 
30546 \SpecialChar ~
30547 \SpecialChar ~
30548 mov r3,#0x00
30549 \layout Standard
30550
30551
30552 \size footnotesize 
30553 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
30554 \layout Standard
30555
30556
30557 \size footnotesize 
30558 \SpecialChar ~
30559 \SpecialChar ~
30560 mov r4,#0x00
30561 \layout Standard
30562
30563
30564 \size footnotesize 
30565 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
30566 \layout Standard
30567
30568
30569 \size footnotesize 
30570 \SpecialChar ~
30571 \SpecialChar ~
30572 mov r5,#0x0A
30573 \layout Standard
30574
30575
30576 \size footnotesize 
30577 \SpecialChar ~
30578 \SpecialChar ~
30579 mov r6,#0x00
30580 \layout Standard
30581
30582
30583 \size footnotesize 
30584 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
30585 \layout Standard
30586
30587
30588 \size footnotesize 
30589 \SpecialChar ~
30590 \SpecialChar ~
30591 mov r7,#0x1E
30592 \layout Standard
30593
30594
30595 \size footnotesize 
30596 \SpecialChar ~
30597 \SpecialChar ~
30598 mov r0,#0x00
30599 \layout Standard
30600
30601
30602 \size footnotesize 
30603 ; _forcond_0($4) :
30604 \layout Standard
30605
30606
30607 \size footnotesize 
30608 00104$:
30609 \layout Standard
30610
30611
30612 \size footnotesize 
30613 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
30614 \layout Standard
30615
30616
30617 \size footnotesize 
30618 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
30619 \layout Standard
30620
30621
30622 \size footnotesize 
30623 \SpecialChar ~
30624 \SpecialChar ~
30625 clr c
30626 \layout Standard
30627
30628
30629 \size footnotesize 
30630 \SpecialChar ~
30631 \SpecialChar ~
30632 mov a,r4
30633 \layout Standard
30634
30635
30636 \size footnotesize 
30637 \SpecialChar ~
30638 \SpecialChar ~
30639 xrl a,#0x80
30640 \layout Standard
30641
30642
30643 \size footnotesize 
30644 \SpecialChar ~
30645 \SpecialChar ~
30646 subb a,#0x8a
30647 \layout Standard
30648
30649
30650 \size footnotesize 
30651 \SpecialChar ~
30652 \SpecialChar ~
30653 jnc 00107$
30654 \layout Standard
30655
30656
30657 \size footnotesize 
30658 00115$:
30659 \layout Standard
30660
30661
30662 \size footnotesize 
30663 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
30664 \layout Standard
30665
30666
30667 \size footnotesize 
30668 ; iTemp21 [lr21:38]{short}[r4]
30669 \layout Standard
30670
30671
30672 \size footnotesize 
30673 \SpecialChar ~
30674 \SpecialChar ~
30675 mov a,r4
30676 \layout Standard
30677
30678
30679 \size footnotesize 
30680 \SpecialChar ~
30681 \SpecialChar ~
30682 add a,r2
30683 \layout Standard
30684
30685
30686 \size footnotesize 
30687 \SpecialChar ~
30688 \SpecialChar ~
30689 mov r2,a
30690 \layout Standard
30691
30692
30693 \size footnotesize 
30694 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
30695 \layout Standard
30696
30697
30698 \size footnotesize 
30699 \SpecialChar ~
30700 \SpecialChar ~
30701 mov b,#0x03
30702 \layout Standard
30703
30704
30705 \size footnotesize 
30706 \SpecialChar ~
30707 \SpecialChar ~
30708 mov a,r4
30709 \layout Standard
30710
30711
30712 \size footnotesize 
30713 \SpecialChar ~
30714 \SpecialChar ~
30715 mul ab
30716 \layout Standard
30717
30718
30719 \size footnotesize 
30720 \SpecialChar ~
30721 \SpecialChar ~
30722 mov r1,a
30723 \layout Standard
30724
30725
30726 \size footnotesize 
30727 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
30728 \layout Standard
30729
30730
30731 \size footnotesize 
30732 ; iTemp15 [lr29:30]{short}[r1]
30733 \layout Standard
30734
30735
30736 \size footnotesize 
30737 \SpecialChar ~
30738 \SpecialChar ~
30739 add a,r3
30740 \layout Standard
30741
30742
30743 \size footnotesize 
30744 \SpecialChar ~
30745 \SpecialChar ~
30746 mov r3,a
30747 \layout Standard
30748
30749
30750 \size footnotesize 
30751 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
30752 \layout Standard
30753
30754
30755 \size footnotesize 
30756 \SpecialChar ~
30757 \SpecialChar ~
30758 mov a,r7
30759 \layout Standard
30760
30761
30762 \size footnotesize 
30763 \SpecialChar ~
30764 \SpecialChar ~
30765 add a,#0xfd
30766 \layout Standard
30767
30768
30769 \size footnotesize 
30770 \SpecialChar ~
30771 \SpecialChar ~
30772 mov r7,a
30773 \layout Standard
30774
30775
30776 \size footnotesize 
30777 \SpecialChar ~
30778 \SpecialChar ~
30779 mov a,r0
30780 \layout Standard
30781
30782
30783 \size footnotesize 
30784 \SpecialChar ~
30785 \SpecialChar ~
30786 addc a,#0xff
30787 \layout Standard
30788
30789
30790 \size footnotesize 
30791 \SpecialChar ~
30792 \SpecialChar ~
30793 mov r0,a
30794 \layout Standard
30795
30796
30797 \size footnotesize 
30798 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
30799 \layout Standard
30800
30801
30802 \size footnotesize 
30803 \SpecialChar ~
30804 \SpecialChar ~
30805 mov a,r7
30806 \layout Standard
30807
30808
30809 \size footnotesize 
30810 \SpecialChar ~
30811 \SpecialChar ~
30812 add a,_gint
30813 \layout Standard
30814
30815
30816 \size footnotesize 
30817 \SpecialChar ~
30818 \SpecialChar ~
30819 mov _gint,a
30820 \layout Standard
30821
30822
30823 \size footnotesize 
30824 \SpecialChar ~
30825 \SpecialChar ~
30826 mov a,r0
30827 \layout Standard
30828
30829
30830 \size footnotesize 
30831 \SpecialChar ~
30832 \SpecialChar ~
30833 addc a,(_gint + 1)
30834 \layout Standard
30835
30836
30837 \size footnotesize 
30838 \SpecialChar ~
30839 \SpecialChar ~
30840 mov (_gint + 1),a
30841 \layout Standard
30842
30843
30844 \size footnotesize 
30845 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
30846 \layout Standard
30847
30848
30849 \size footnotesize 
30850 \SpecialChar ~
30851 \SpecialChar ~
30852 inc r4
30853 \layout Standard
30854
30855
30856 \size footnotesize 
30857 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
30858 \layout Standard
30859
30860
30861 \size footnotesize 
30862 \SpecialChar ~
30863 \SpecialChar ~
30864 dec r5
30865 \layout Standard
30866
30867
30868 \size footnotesize 
30869 \SpecialChar ~
30870 \SpecialChar ~
30871 cjne r5,#0xff,00104$
30872 \layout Standard
30873
30874
30875 \size footnotesize 
30876 \SpecialChar ~
30877 \SpecialChar ~
30878 dec r6
30879 \layout Standard
30880
30881
30882 \size footnotesize 
30883 ; goto _forcond_0($4)
30884 \layout Standard
30885
30886
30887 \size footnotesize 
30888 \SpecialChar ~
30889 \SpecialChar ~
30890 sjmp 00104$
30891 \layout Standard
30892
30893
30894 \size footnotesize 
30895 ; _forbreak_0($7) :
30896 \layout Standard
30897
30898
30899 \size footnotesize 
30900 00107$:
30901 \layout Standard
30902
30903
30904 \size footnotesize 
30905 ; ret iTemp24 [lr40:41]{short}
30906 \layout Standard
30907
30908
30909 \size footnotesize 
30910 \SpecialChar ~
30911 \SpecialChar ~
30912 mov a,r3
30913 \layout Standard
30914
30915
30916 \size footnotesize 
30917 \SpecialChar ~
30918 \SpecialChar ~
30919 add a,r2
30920 \layout Standard
30921
30922
30923 \size footnotesize 
30924 \SpecialChar ~
30925 \SpecialChar ~
30926 mov dpl,a
30927 \layout Standard
30928
30929
30930 \size footnotesize 
30931 ; _return($8) :
30932 \layout Standard
30933
30934
30935 \size footnotesize 
30936 00108$:
30937 \layout Standard
30938
30939
30940 \size footnotesize 
30941 \SpecialChar ~
30942 \SpecialChar ~
30943 ret
30944 \newline 
30945
30946 \layout Section
30947
30948 A few words about basic block successors, predecessors and dominators
30949 \layout Standard
30950
30951 Successors are basic blocks
30952 \begin_inset LatexCommand \index{Basic blocks}
30953
30954 \end_inset 
30955
30956  that might execute after this basic block.
30957 \newline 
30958 Predecessors are basic blocks that might execute before reaching this basic
30959  block.
30960 \newline 
30961 Dominators are basic blocks that WILL execute before reaching this basic
30962  block.
30963 \newline 
30964
30965 \layout Standard
30966
30967 [basic block 1]
30968 \layout Standard
30969
30970 if (something)
30971 \layout Standard
30972
30973 \SpecialChar ~
30974 \SpecialChar ~
30975 \SpecialChar ~
30976 \SpecialChar ~
30977 [basic block 2]
30978 \layout Standard
30979
30980 else
30981 \layout Standard
30982
30983 \SpecialChar ~
30984 \SpecialChar ~
30985 \SpecialChar ~
30986 \SpecialChar ~
30987 [basic block 3]
30988 \layout Standard
30989
30990 [basic block 4]
30991 \newline 
30992
30993 \layout Standard
30994
30995 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
30996 \layout Standard
30997
30998 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
30999 \layout Standard
31000
31001 c) domVect of [BB4] = BB1 ...
31002  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
31003  was executed.
31004 \layout Chapter
31005
31006 Acknowledgments
31007 \layout Standard
31008
31009
31010 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
31011
31012 \end_inset 
31013
31014
31015 \newline 
31016
31017 \newline 
31018
31019 \emph on 
31020 Thanks to all the other volunteer developers who have helped with coding,
31021  testing, web-page creation, distribution sets, etc.
31022  You know who you are :-)
31023 \emph default 
31024
31025 \newline 
31026
31027 \newline 
31028
31029 \emph on 
31030 Also thanks to Sourceforge 
31031 \begin_inset LatexCommand \url{http://www.sf.net}
31032
31033 \end_inset 
31034
31035  which has hosted the project since 1999 and donates significant download
31036  bandwidth and probably more than 
31037 \begin_inset ERT
31038 status Collapsed
31039
31040 \layout Standard
31041 $10^{13}$
31042 \end_inset 
31043
31044 CPU cycles per day.
31045 \newline 
31046  
31047 \begin_inset Note
31048 collapsed false
31049
31050 \layout Standard
31051
31052 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
31053  minutes for (configure+make+regression test), and there is (i386, amd64,
31054  alpha, ppc64, (mingw32), sparc, macosx).
31055  
31056 \end_inset 
31057
31058
31059 \layout Standard
31060
31061 This document was initially written by Sandeep Dutta
31062 \layout Standard
31063
31064 All product names mentioned herein may be trademarks
31065 \begin_inset LatexCommand \index{Trademarks}
31066
31067 \end_inset 
31068
31069  of their respective companies.
31070  
31071 \layout Section*
31072
31073 Alphabetical index
31074 \layout Standard
31075
31076 To avoid confusion, the installation and building options for SDCC itself
31077  (chapter 2) are not part of the index.
31078 \layout Standard
31079
31080
31081 \begin_inset LatexCommand \printindex{}
31082
31083 \end_inset 
31084
31085
31086 \the_end