* device/include/malloc.h: removed init_dynamic_memory
[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 wparam 
19208 \emph on 
19209 This pragma is deprecated.
19210  Its use will cause a warning message to be issued.
19211 \emph default 
19212
19213 \newline 
19214
19215 \layout List
19216 \labelwidthstring 00.00.0000
19217
19218 code
19219 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
19220
19221 \end_inset 
19222
19223  place a function symbol at static FLASH address
19224 \layout LyX-Code
19225
19226 Example:
19227 \layout LyX-Code
19228
19229 \layout LyX-Code
19230
19231 /* place function test_func at 0x4000 */
19232 \layout LyX-Code
19233
19234 #pragma code test_func 0x4000
19235 \layout LyX-Code
19236
19237 \layout List
19238 \labelwidthstring 00.00.0000
19239
19240 library instructs the linker to use a library module.
19241 \newline 
19242 Usage:
19243 \layout LyX-Code
19244
19245 #pragma library module_name
19246 \layout Standard
19247
19248
19249 \emph on 
19250 module_name
19251 \emph default 
19252  can be any library or object file (including its path).
19253  Note that there are four reserved keywords which have special meaning.
19254  These are:
19255 \layout Standard
19256 \align center 
19257
19258 \begin_inset  Tabular
19259 <lyxtabular version="3" rows="6" columns="3">
19260 <features>
19261 <column alignment="center" valignment="top" leftline="true" width="0">
19262 <column alignment="block" valignment="top" leftline="true" width="20page%">
19263 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19264 <row topline="true" bottomline="true">
19265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19266 \begin_inset Text
19267
19268 \layout Standard
19269
19270 Keyword
19271 \end_inset 
19272 </cell>
19273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19274 \begin_inset Text
19275
19276 \layout Standard
19277
19278 Description
19279 \end_inset 
19280 </cell>
19281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19282 \begin_inset Text
19283
19284 \layout Standard
19285
19286 Module to link
19287 \end_inset 
19288 </cell>
19289 </row>
19290 <row topline="true">
19291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19292 \begin_inset Text
19293
19294 \layout Standard
19295
19296
19297 \series bold 
19298 ignore
19299 \end_inset 
19300 </cell>
19301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19302 \begin_inset Text
19303
19304 \layout Standard
19305
19306 ignore all library pragmas
19307 \end_inset 
19308 </cell>
19309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19310 \begin_inset Text
19311
19312 \layout Standard
19313
19314
19315 \emph on 
19316 (none)
19317 \end_inset 
19318 </cell>
19319 </row>
19320 <row topline="true">
19321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19322 \begin_inset Text
19323
19324 \layout Standard
19325
19326
19327 \series bold 
19328 c
19329 \end_inset 
19330 </cell>
19331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19332 \begin_inset Text
19333
19334 \layout Standard
19335
19336 link the C library
19337 \end_inset 
19338 </cell>
19339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19340 \begin_inset Text
19341
19342 \layout Standard
19343
19344
19345 \emph on 
19346 libc18f
19347 \emph default 
19348 .lib
19349 \end_inset 
19350 </cell>
19351 </row>
19352 <row topline="true">
19353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19354 \begin_inset Text
19355
19356 \layout Standard
19357
19358
19359 \series bold 
19360 math
19361 \end_inset 
19362 </cell>
19363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19364 \begin_inset Text
19365
19366 \layout Standard
19367
19368 link the Math libarary
19369 \end_inset 
19370 </cell>
19371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19372 \begin_inset Text
19373
19374 \layout Standard
19375
19376
19377 \emph on 
19378 libm18f
19379 \emph default 
19380 .lib
19381 \end_inset 
19382 </cell>
19383 </row>
19384 <row topline="true">
19385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19386 \begin_inset Text
19387
19388 \layout Standard
19389
19390
19391 \series bold 
19392 io
19393 \end_inset 
19394 </cell>
19395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19396 \begin_inset Text
19397
19398 \layout Standard
19399
19400 link the I/O library
19401 \end_inset 
19402 </cell>
19403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19404 \begin_inset Text
19405
19406 \layout Standard
19407
19408
19409 \emph on 
19410 libio18f*
19411 \emph default 
19412 .lib
19413 \end_inset 
19414 </cell>
19415 </row>
19416 <row topline="true" bottomline="true">
19417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19418 \begin_inset Text
19419
19420 \layout Standard
19421
19422
19423 \series bold 
19424 debug
19425 \end_inset 
19426 </cell>
19427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19428 \begin_inset Text
19429
19430 \layout Standard
19431
19432 link the debug library
19433 \end_inset 
19434 </cell>
19435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19436 \begin_inset Text
19437
19438 \layout Standard
19439
19440
19441 \emph on 
19442 libdebug
19443 \emph default 
19444 .lib
19445 \end_inset 
19446 </cell>
19447 </row>
19448 </lyxtabular>
19449
19450 \end_inset 
19451
19452
19453 \newline 
19454 * is the device number, i.e.
19455  452 for PIC18F452 MCU.
19456 \layout Standard
19457
19458 This feature allows for linking with specific libraries withoug having to
19459  explicit name them in the command line.
19460  Note that the 
19461 \noun on 
19462 ignore
19463 \noun default 
19464  keyword will reject all modules specified by the library pragma.
19465 \layout List
19466 \labelwidthstring 00.00.0000
19467
19468 udata pragma udata instructs the compiler to emit code so that linker will
19469  place a variable at a specific memory bank
19470 \layout LyX-Code
19471
19472 Example:
19473 \layout LyX-Code
19474
19475 \layout LyX-Code
19476
19477 /* places variable foo at bank2 */
19478 \layout LyX-Code
19479
19480 #pragma udata bank2 foo
19481 \layout LyX-Code
19482
19483 char foo;
19484 \layout Standard
19485
19486 In order for this pragma to work extra SECTION directives should be added
19487  in the .lkr script.
19488  In the following example a sample .lkr file is shown:
19489 \layout LyX-Code
19490
19491 \layout LyX-Code
19492
19493 // Sample linker script for the PIC18F452 processor
19494 \layout LyX-Code
19495
19496 LIBPATH .
19497 \layout LyX-Code
19498
19499 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
19500 \layout LyX-Code
19501
19502 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
19503 \layout LyX-Code
19504
19505 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
19506 \layout LyX-Code
19507
19508 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
19509 \layout LyX-Code
19510
19511 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
19512 \layout LyX-Code
19513
19514 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
19515 \layout LyX-Code
19516
19517 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
19518 \layout LyX-Code
19519
19520 \layout LyX-Code
19521
19522 DATABANK   NAME=gpr0       START=0x80           END=0xFF
19523 \layout LyX-Code
19524
19525 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
19526 \layout LyX-Code
19527
19528 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
19529 \layout LyX-Code
19530
19531 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
19532 \layout LyX-Code
19533
19534 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
19535 \layout LyX-Code
19536
19537 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
19538 \layout LyX-Code
19539
19540 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
19541 \layout LyX-Code
19542
19543 \layout LyX-Code
19544
19545 SECTION    NAME=CONFIG     ROM=config
19546 \layout LyX-Code
19547
19548 \layout LyX-Code
19549
19550 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
19551 \layout LyX-Code
19552
19553 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
19554 \layout LyX-Code
19555
19556 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
19557 \layout LyX-Code
19558
19559 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
19560 \layout LyX-Code
19561
19562 SECTION    NAME=bank4      RAM=gpr4
19563 \layout LyX-Code
19564
19565 SECTION    NAME=bank5      RAM=gpr5
19566 \layout Standard
19567
19568 The linker will recognise the section name set in the pragma statement and
19569  will position the variable at the memory bank set with the RAM field at
19570  the SECTION line in the linker script file.
19571 \layout Subsection
19572
19573 Header Files
19574 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19575
19576 \end_inset 
19577
19578
19579 \layout Standard
19580
19581 There is one main header file
19582 \begin_inset LatexCommand \index{PIC16!Header files}
19583
19584 \end_inset 
19585
19586  that can be included to the source files using the pic16
19587 \begin_inset LatexCommand \index{PIC16}
19588
19589 \end_inset 
19590
19591  port.
19592  That file is the 
19593 \series bold 
19594 pic18fregs.h
19595 \series default 
19596 .
19597  This header file contains the definitions for the processor special registers,
19598  so it is necessary if the source accesses them.
19599  It can be included by adding the following line in the beginning of the
19600  file:
19601 \layout LyX-Code
19602
19603 #include <pic18fregs.h>
19604 \layout Standard
19605
19606 The specific microcontroller is selected within the pic18fregs.h automatically,
19607  so the same source can be used with a variety of devices.
19608 \layout Subsection
19609
19610 Libraries
19611 \layout Standard
19612
19613 The libraries
19614 \begin_inset LatexCommand \index{PIC16!Libraries}
19615
19616 \end_inset 
19617
19618  that PIC16
19619 \begin_inset LatexCommand \index{PIC16}
19620
19621 \end_inset 
19622
19623  port depends on are the microcontroller device libraries which contain
19624  the symbol definitions for the microcontroller special function registers.
19625  These libraries have the format pic18fxxxx.lib, where 
19626 \emph on 
19627 xxxx
19628 \emph default 
19629  is the microcontroller identification number.
19630  The specific library is selected automatically by the compiler at link
19631  stage according to the selected device.
19632 \layout Standard
19633
19634 Libraries are created with gplib which is part of the gputils package 
19635 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19636
19637 \end_inset 
19638
19639 .
19640 \layout Subsubsection*
19641
19642 Building the libraries
19643 \layout Standard
19644
19645 Before using SDCC/pic16 there are some libraries that need to be compiled.
19646  This process is not done automatically by SDCC since not all users use
19647  SDCC for pic16 projects.
19648  So each user should compile the libraries separately.
19649 \layout Standard
19650
19651 The steps to compile the pic16 libraries under Linux are:
19652 \layout LyX-Code
19653
19654 cd device/lib/pic16
19655 \layout LyX-Code
19656
19657 ./configure
19658 \layout LyX-Code
19659
19660 make
19661 \layout LyX-Code
19662
19663 cd ..
19664 \layout LyX-Code
19665
19666 make model-pic16
19667 \layout LyX-Code
19668
19669 su -c 'make install'     # install the libraries, you need the root password
19670 \layout Standard
19671
19672 If you need to install the headers too, do:
19673 \layout LyX-Code
19674
19675 cd device/include
19676 \layout LyX-Code
19677
19678 su -c 'make install'     # install the headers, you need the root password
19679 \layout Standard
19680
19681 There exist a special target to build the I/O libraries.
19682  This target is not automatically build because it will build the I/O library
19683  for 
19684 \emph on 
19685 every
19686 \emph default 
19687  supported device.
19688  This way building will take quite a lot of time.
19689  Users are advised to edit the 
19690 \series bold 
19691 device/lib/pic16/pics.build
19692 \series default 
19693  file and then execute:
19694 \layout LyX-Code
19695
19696 make lib-io
19697 \layout Subsection
19698
19699 Memory Models
19700 \layout Standard
19701
19702 The following memory models are supported by the PIC16 port:
19703 \layout Itemize
19704
19705 small model
19706 \layout Itemize
19707
19708 large model
19709 \layout Standard
19710
19711 Memory model affects the default size of pointers within the source.
19712  The sizes are shown in the next table:
19713 \layout Standard
19714 \align center 
19715
19716 \begin_inset  Tabular
19717 <lyxtabular version="3" rows="3" columns="3">
19718 <features>
19719 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19720 <column alignment="center" valignment="top" leftline="true" width="0">
19721 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19722 <row topline="true" bottomline="true">
19723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19724 \begin_inset Text
19725
19726 \layout Standard
19727
19728 Pointer sizes according to memory model
19729 \end_inset 
19730 </cell>
19731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19732 \begin_inset Text
19733
19734 \layout Standard
19735
19736 small model
19737 \end_inset 
19738 </cell>
19739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19740 \begin_inset Text
19741
19742 \layout Standard
19743
19744 large model
19745 \end_inset 
19746 </cell>
19747 </row>
19748 <row topline="true" bottomline="true">
19749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19750 \begin_inset Text
19751
19752 \layout Standard
19753
19754 code pointers
19755 \end_inset 
19756 </cell>
19757 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19758 \begin_inset Text
19759
19760 \layout Standard
19761
19762 16-bits
19763 \end_inset 
19764 </cell>
19765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19766 \begin_inset Text
19767
19768 \layout Standard
19769
19770 24-bits
19771 \end_inset 
19772 </cell>
19773 </row>
19774 <row topline="true" bottomline="true">
19775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19776 \begin_inset Text
19777
19778 \layout Standard
19779
19780 data pointers
19781 \end_inset 
19782 </cell>
19783 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
19784 \begin_inset Text
19785
19786 \layout Standard
19787
19788 16-bits
19789 \end_inset 
19790 </cell>
19791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19792 \begin_inset Text
19793
19794 \layout Standard
19795
19796 16-bits
19797 \end_inset 
19798 </cell>
19799 </row>
19800 </lyxtabular>
19801
19802 \end_inset 
19803
19804
19805 \layout Standard
19806
19807 It is advisable that all sources within a project are compiled with the
19808  same memory model.
19809  If one wants to override the default memory model, this can be done by
19810  declaring a pointer as 
19811 \series bold 
19812 far
19813 \series default 
19814  or 
19815 \series bold 
19816 near
19817 \series default 
19818 .
19819  Far selects large memory model's pointers, while near selects small memory
19820  model's pointers.
19821 \layout Standard
19822
19823 The standard device libraries (see 
19824 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
19825
19826 \end_inset 
19827
19828 ) contain no reference to pointers, so they can be used with both memory
19829  models.
19830 \layout Subsection
19831
19832 Stack
19833 \layout Standard
19834
19835 The stack
19836 \begin_inset LatexCommand \index{PIC16!stack}
19837
19838 \end_inset 
19839
19840  implementation for the PIC16 port uses two indirect registers, FSR1 and
19841  FSR2.
19842 \layout List
19843 \labelwidthstring 00.00.0000
19844
19845 FSR1 is assigned as stack pointer
19846 \layout List
19847 \labelwidthstring 00.00.0000
19848
19849 FSR2 is assigned as frame pointer
19850 \layout Standard
19851
19852 The following stack models are supported by the PIC16 port
19853 \layout Itemize
19854
19855
19856 \noun on 
19857 small
19858 \noun default 
19859  model
19860 \layout Itemize
19861
19862
19863 \noun on 
19864 large
19865 \noun default 
19866  model
19867 \layout Standard
19868
19869
19870 \noun on 
19871 Small
19872 \noun default 
19873  model means that only the FSRxL byte is used to access stack and frame,
19874  while 
19875 \emph on 
19876 \noun on 
19877 large
19878 \emph default 
19879 \noun default 
19880  uses both FSRxL and FSRxH registers.
19881  The following table shows the stack/frame pointers sizes according to stack
19882  model and the maximum space they can address:
19883 \layout Standard
19884 \align center 
19885
19886 \begin_inset  Tabular
19887 <lyxtabular version="3" rows="3" columns="3">
19888 <features>
19889 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19890 <column alignment="center" valignment="top" leftline="true" width="0">
19891 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19892 <row topline="true" bottomline="true">
19893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19894 \begin_inset Text
19895
19896 \layout Standard
19897
19898 Stack & Frame pointer sizes according to stack model
19899 \end_inset 
19900 </cell>
19901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19902 \begin_inset Text
19903
19904 \layout Standard
19905
19906 small
19907 \end_inset 
19908 </cell>
19909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19910 \begin_inset Text
19911
19912 \layout Standard
19913
19914 large
19915 \end_inset 
19916 </cell>
19917 </row>
19918 <row topline="true">
19919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19920 \begin_inset Text
19921
19922 \layout Standard
19923
19924 Stack pointer FSR1
19925 \end_inset 
19926 </cell>
19927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19928 \begin_inset Text
19929
19930 \layout Standard
19931
19932 8-bits
19933 \end_inset 
19934 </cell>
19935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19936 \begin_inset Text
19937
19938 \layout Standard
19939
19940 16-bits
19941 \end_inset 
19942 </cell>
19943 </row>
19944 <row topline="true" bottomline="true">
19945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19946 \begin_inset Text
19947
19948 \layout Standard
19949
19950 Frame pointer FSR2
19951 \end_inset 
19952 </cell>
19953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19954 \begin_inset Text
19955
19956 \layout Standard
19957
19958 8-bits
19959 \end_inset 
19960 </cell>
19961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19962 \begin_inset Text
19963
19964 \layout Standard
19965
19966 16-bits
19967 \end_inset 
19968 </cell>
19969 </row>
19970 </lyxtabular>
19971
19972 \end_inset 
19973
19974
19975 \layout Standard
19976
19977
19978 \noun on 
19979 Large 
19980 \noun default 
19981 stack model is currently not working properly throughout the code generator.
19982  So its use is not advised.
19983  Also there are some other points that need special care:
19984 \newline 
19985
19986 \layout Enumerate
19987
19988 Do not create stack sections with size more than one physical bank (that
19989  is 256 bytes)
19990 \layout Enumerate
19991
19992 Stack sections should no cross physical bank limits (i.e.
19993  #pragma stack 0x50 0x100)
19994 \layout Standard
19995
19996 These limitations are caused by the fact that only FSRxL is modified when
19997  using SMALL stack model, so no more than 256 bytes of stack can be used.
19998  This problem will disappear after LARGE model is fully implemented.
19999 \layout Subsection
20000
20001 Functions
20002 \layout Standard
20003
20004 In addition to the standard SDCC function keywords, PIC16
20005 \begin_inset LatexCommand \index{PIC16}
20006
20007 \end_inset 
20008
20009  port makes available two more:
20010 \layout List
20011 \labelwidthstring 00.00.0000
20012
20013 wparam
20014 \begin_inset LatexCommand \index{PIC16!wparam}
20015
20016 \end_inset 
20017
20018  Use the WREG to pass one byte of the first function argument.
20019  This improves speed but you may not use this for functions with arguments
20020  that are called via function pointers, otherwise the first byte of the
20021  first parameter will get lost.
20022  Usage:
20023 \layout LyX-Code
20024
20025 void func_wparam(int a) wparam
20026 \layout LyX-Code
20027
20028 {
20029 \layout LyX-Code
20030
20031     /* WREG hold the lower part of a */
20032 \layout LyX-Code
20033
20034     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
20035  */
20036 \layout LyX-Code
20037
20038 ...
20039 \layout LyX-Code
20040
20041 }
20042 \layout Standard
20043
20044 This keyword replaces the deprecated wparam pragma.
20045 \layout List
20046 \labelwidthstring 00.00.0000
20047
20048 shadowregs
20049 \begin_inset LatexCommand \index{PIC16!shadowregs}
20050
20051 \end_inset 
20052
20053  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
20054  hardware shadow registers which hold the values of WREG, STATUS and BSR
20055  registers.
20056  This can be done by adding the keyword 
20057 \emph on 
20058 shadowregs
20059 \emph default 
20060  before the 
20061 \emph on 
20062 interrupt
20063 \emph default 
20064  keyword in the function's header.
20065 \layout LyX-Code
20066
20067 void isr_shadow(void) shadowregs interrupt 1
20068 \layout LyX-Code
20069
20070 {
20071 \layout LyX-Code
20072
20073 ...
20074 \layout LyX-Code
20075
20076 }
20077 \layout Standard
20078
20079
20080 \emph on 
20081 shadowregs
20082 \emph default 
20083  instructs the code generator not to store/restore WREG, STATUS, BSR when
20084  entering/exiting the ISR.
20085 \layout Subsection
20086
20087 Function return values
20088 \layout Standard
20089
20090 Return values from functions are placed to the appropriate registers following
20091  a modified Microchip policy optimized for SDCC.
20092  The following table shows these registers:
20093 \layout Standard
20094 \align center 
20095
20096 \begin_inset  Tabular
20097 <lyxtabular version="3" rows="6" columns="2">
20098 <features>
20099 <column alignment="center" valignment="top" leftline="true" width="0">
20100 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20101 <row topline="true" bottomline="true">
20102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20103 \begin_inset Text
20104
20105 \layout Standard
20106
20107 size
20108 \end_inset 
20109 </cell>
20110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20111 \begin_inset Text
20112
20113 \layout Standard
20114
20115 destination register
20116 \end_inset 
20117 </cell>
20118 </row>
20119 <row topline="true">
20120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20121 \begin_inset Text
20122
20123 \layout Standard
20124
20125 8 bits
20126 \end_inset 
20127 </cell>
20128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20129 \begin_inset Text
20130
20131 \layout Standard
20132
20133 WREG
20134 \end_inset 
20135 </cell>
20136 </row>
20137 <row topline="true">
20138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20139 \begin_inset Text
20140
20141 \layout Standard
20142
20143 16 bits
20144 \end_inset 
20145 </cell>
20146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20147 \begin_inset Text
20148
20149 \layout Standard
20150
20151 PRODL:WREG
20152 \end_inset 
20153 </cell>
20154 </row>
20155 <row topline="true">
20156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20157 \begin_inset Text
20158
20159 \layout Standard
20160
20161 24 bits
20162 \end_inset 
20163 </cell>
20164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20165 \begin_inset Text
20166
20167 \layout Standard
20168
20169 PRODH:PRODL:WREG
20170 \end_inset 
20171 </cell>
20172 </row>
20173 <row topline="true">
20174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20175 \begin_inset Text
20176
20177 \layout Standard
20178
20179 32 bits
20180 \end_inset 
20181 </cell>
20182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20183 \begin_inset Text
20184
20185 \layout Standard
20186
20187 FSR0L:PRODH:PRODL:WREG
20188 \end_inset 
20189 </cell>
20190 </row>
20191 <row topline="true" bottomline="true">
20192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20193 \begin_inset Text
20194
20195 \layout Standard
20196
20197 >32 bits
20198 \end_inset 
20199 </cell>
20200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20201 \begin_inset Text
20202
20203 \layout Standard
20204
20205 on stack, FSR0 points to the beginning
20206 \end_inset 
20207 </cell>
20208 </row>
20209 </lyxtabular>
20210
20211 \end_inset 
20212
20213
20214 \layout Subsection
20215
20216 Interrupts
20217 \layout Standard
20218
20219 An interrupt
20220 \begin_inset LatexCommand \index{PIC16!interrupt}
20221
20222 \end_inset 
20223
20224  service routine (ISR) is declared using the 
20225 \emph on 
20226 interrupt
20227 \emph default 
20228  keyword.
20229 \layout LyX-Code
20230
20231 void isr(void) interrupt 
20232 \emph on 
20233 n
20234 \layout LyX-Code
20235
20236 {
20237 \layout LyX-Code
20238
20239 ...
20240 \layout LyX-Code
20241
20242 }
20243 \layout Standard
20244
20245
20246 \emph on 
20247 n
20248 \emph default 
20249  is the interrupt number, which for PIC18F devices can be:
20250 \layout Standard
20251 \align center 
20252
20253 \begin_inset  Tabular
20254 <lyxtabular version="3" rows="4" columns="3">
20255 <features>
20256 <column alignment="center" valignment="top" leftline="true" width="0">
20257 <column alignment="center" valignment="top" leftline="true" width="0">
20258 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20259 <row topline="true" bottomline="true">
20260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20261 \begin_inset Text
20262
20263 \layout Standard
20264
20265
20266 \emph on 
20267 n
20268 \end_inset 
20269 </cell>
20270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20271 \begin_inset Text
20272
20273 \layout Standard
20274
20275 Interrupt Vector
20276 \end_inset 
20277 </cell>
20278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20279 \begin_inset Text
20280
20281 \layout Standard
20282
20283 Interrupt Vector Address
20284 \end_inset 
20285 </cell>
20286 </row>
20287 <row topline="true">
20288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20289 \begin_inset Text
20290
20291 \layout Standard
20292
20293 0
20294 \end_inset 
20295 </cell>
20296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20297 \begin_inset Text
20298
20299 \layout Standard
20300
20301 RESET vector
20302 \end_inset 
20303 </cell>
20304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20305 \begin_inset Text
20306
20307 \layout Standard
20308
20309 0x000000
20310 \end_inset 
20311 </cell>
20312 </row>
20313 <row topline="true">
20314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20315 \begin_inset Text
20316
20317 \layout Standard
20318
20319
20320 \family roman 
20321 \series medium 
20322 \shape up 
20323 \size normal 
20324 \emph off 
20325 \bar no 
20326 \noun off 
20327 \color none
20328 1
20329 \end_inset 
20330 </cell>
20331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20332 \begin_inset Text
20333
20334 \layout Standard
20335
20336
20337 \family roman 
20338 \series medium 
20339 \shape up 
20340 \size normal 
20341 \emph off 
20342 \bar no 
20343 \noun off 
20344 \color none
20345 HIGH priority interrupts
20346 \end_inset 
20347 </cell>
20348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20349 \begin_inset Text
20350
20351 \layout Standard
20352
20353 0x000008
20354 \end_inset 
20355 </cell>
20356 </row>
20357 <row topline="true" bottomline="true">
20358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20359 \begin_inset Text
20360
20361 \layout Standard
20362
20363 2
20364 \end_inset 
20365 </cell>
20366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20367 \begin_inset Text
20368
20369 \layout Standard
20370
20371 LOW priority interrupts
20372 \end_inset 
20373 </cell>
20374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20375 \begin_inset Text
20376
20377 \layout Standard
20378
20379 0x000018
20380 \end_inset 
20381 </cell>
20382 </row>
20383 </lyxtabular>
20384
20385 \end_inset 
20386
20387
20388 \layout Standard
20389
20390 When generating assembly code for ISR the code generator places a 
20391 \noun on 
20392 goto 
20393 \noun default 
20394 instruction at the 
20395 \emph on 
20396 Interrupt Vector Address
20397 \emph default 
20398  which points at the genetated ISR.
20399  This single GOTO instruction is part of an automatically generated 
20400 \emph on 
20401 interrupt entry point
20402 \emph default 
20403  function.
20404  The actuall ISR code is placed as normally would in the code space.
20405  Upon interrupt request, the GOTO instruction is executed which jumps to
20406  the ISR code.
20407  When declaring interrupt functions as _naked this GOTO instruction is 
20408 \series bold 
20409 not
20410 \series default 
20411  generated.
20412  The whole interrupt functions is therefore placed at the Interrupt Vector
20413  Address of the specific interrupt.
20414  This is not a problem for the LOW priority interrupts, but it is a problem
20415  for the RESET and the HIGH priority interrupts because code may be written
20416  at the next interrupt´s vector address and cause undeterminate program
20417  behaviour if that interrupt is raised.
20418 \begin_inset Foot
20419 collapsed false
20420
20421 \layout Standard
20422
20423 This is not a problem when
20424 \layout Enumerate
20425
20426 this is a HIGH interrupt ISR and LOW interrupts are 
20427 \emph on 
20428 disabled
20429 \emph default 
20430  or not used.
20431 \layout Enumerate
20432
20433 when the ISR is small enough not to reach the next interrupt´s vector address.
20434 \end_inset 
20435
20436
20437 \layout Standard
20438
20439
20440 \emph on 
20441 n
20442 \emph default 
20443  is possible to be omitted.
20444  This way a function is generated similar to an ISR, but it is not assigned
20445  to any interrupt.
20446 \layout Standard
20447
20448 When entering an interrupt, currently the PIC16
20449 \begin_inset LatexCommand \index{PIC16}
20450
20451 \end_inset 
20452
20453  port automatically saves the following registers:
20454 \layout Itemize
20455
20456 WREG
20457 \layout Itemize
20458
20459 STATUS
20460 \layout Itemize
20461
20462 BSR
20463 \layout Itemize
20464
20465 PROD (PRODL and PRODH)
20466 \layout Itemize
20467
20468 FSR0 (FSR0L and FSR0H)
20469 \layout Standard
20470
20471 These registers are restored upon return from the interrupt routine.
20472 \begin_inset Foot
20473 collapsed false
20474
20475 \layout Standard
20476
20477 NOTE that when the _naked attribute is specified for an interrupt routine,
20478  then NO registers are stored or restored.
20479 \end_inset 
20480
20481
20482 \layout Subsection
20483
20484 Generic Pointers
20485 \layout Standard
20486
20487 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20488  There are 3 types of generic pointers currently implemented data, code
20489  and eeprom pointers.
20490  They are differentiated by the value of the 7th and 6th bits of the upper
20491  byte:
20492 \layout Standard
20493 \align center 
20494
20495 \begin_inset  Tabular
20496 <lyxtabular version="3" rows="5" columns="5">
20497 <features>
20498 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20499 <column alignment="center" valignment="top" width="0">
20500 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20501 <column alignment="center" valignment="top" width="0">
20502 <column alignment="left" valignment="top" rightline="true" width="0">
20503 <row topline="true" bottomline="true">
20504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20505 \begin_inset Text
20506
20507 \layout Standard
20508
20509 pointer type
20510 \end_inset 
20511 </cell>
20512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20513 \begin_inset Text
20514
20515 \layout Standard
20516
20517 7th bit
20518 \end_inset 
20519 </cell>
20520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20521 \begin_inset Text
20522
20523 \layout Standard
20524
20525 6th bit
20526 \end_inset 
20527 </cell>
20528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20529 \begin_inset Text
20530
20531 \layout Standard
20532
20533 rest of the pointer
20534 \end_inset 
20535 </cell>
20536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20537 \begin_inset Text
20538
20539 \layout Standard
20540
20541 description
20542 \end_inset 
20543 </cell>
20544 </row>
20545 <row topline="true" bottomline="true">
20546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20547 \begin_inset Text
20548
20549 \layout Standard
20550
20551 data 
20552 \end_inset 
20553 </cell>
20554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20555 \begin_inset Text
20556
20557 \layout Standard
20558
20559 1
20560 \end_inset 
20561 </cell>
20562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20563 \begin_inset Text
20564
20565 \layout Standard
20566
20567 0
20568 \end_inset 
20569 </cell>
20570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20571 \begin_inset Text
20572
20573 \layout Standard
20574
20575
20576 \family typewriter 
20577 \shape slanted 
20578 \emph on 
20579 uuuuuu uuuuxxxx xxxxxxxx
20580 \end_inset 
20581 </cell>
20582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20583 \begin_inset Text
20584
20585 \layout Standard
20586
20587 a 12-bit data pointer in data RAM memory
20588 \end_inset 
20589 </cell>
20590 </row>
20591 <row bottomline="true">
20592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20593 \begin_inset Text
20594
20595 \layout Standard
20596
20597 code
20598 \end_inset 
20599 </cell>
20600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20601 \begin_inset Text
20602
20603 \layout Standard
20604
20605 0
20606 \end_inset 
20607 </cell>
20608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20609 \begin_inset Text
20610
20611 \layout Standard
20612
20613 0
20614 \end_inset 
20615 </cell>
20616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20617 \begin_inset Text
20618
20619 \layout Standard
20620
20621
20622 \family typewriter 
20623 \shape slanted 
20624 \emph on 
20625 uxxxxx xxxxxxxx xxxxxxxx
20626 \end_inset 
20627 </cell>
20628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20629 \begin_inset Text
20630
20631 \layout Standard
20632
20633 a 21-bit code pointer in FLASH memory
20634 \end_inset 
20635 </cell>
20636 </row>
20637 <row bottomline="true">
20638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20639 \begin_inset Text
20640
20641 \layout Standard
20642
20643 eeprom
20644 \end_inset 
20645 </cell>
20646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20647 \begin_inset Text
20648
20649 \layout Standard
20650
20651 0
20652 \end_inset 
20653 </cell>
20654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20655 \begin_inset Text
20656
20657 \layout Standard
20658
20659 1
20660 \end_inset 
20661 </cell>
20662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20663 \begin_inset Text
20664
20665 \layout Standard
20666
20667
20668 \family typewriter 
20669 \shape slanted 
20670 \emph on 
20671 uuuuuu uuuuuuxx xxxxxxxx
20672 \end_inset 
20673 </cell>
20674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20675 \begin_inset Text
20676
20677 \layout Standard
20678
20679 a 10-bit eeprom pointer in EEPROM memory
20680 \end_inset 
20681 </cell>
20682 </row>
20683 <row bottomline="true">
20684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20685 \begin_inset Text
20686
20687 \layout Standard
20688
20689 (unimplemented)
20690 \end_inset 
20691 </cell>
20692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20693 \begin_inset Text
20694
20695 \layout Standard
20696
20697 1
20698 \end_inset 
20699 </cell>
20700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20701 \begin_inset Text
20702
20703 \layout Standard
20704
20705 1
20706 \end_inset 
20707 </cell>
20708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20709 \begin_inset Text
20710
20711 \layout Standard
20712
20713
20714 \family typewriter 
20715 \shape slanted 
20716 \emph on 
20717 xxxxxx xxxxxxxx xxxxxxxx
20718 \end_inset 
20719 </cell>
20720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20721 \begin_inset Text
20722
20723 \layout Standard
20724
20725 unimplemented pointer type
20726 \end_inset 
20727 </cell>
20728 </row>
20729 </lyxtabular>
20730
20731 \end_inset 
20732
20733
20734 \layout Standard
20735
20736 Generic pointer are read and written with a set of library functions which
20737  read/write 1, 2, 3, 4 bytes.
20738 \layout Subsection
20739
20740 PIC16 C Libraries
20741 \layout Subsubsection
20742
20743 Standard I/O Streams
20744 \layout Standard
20745
20746 In the 
20747 \emph on 
20748 stdio.h
20749 \emph default 
20750  the type FILE is defined as:
20751 \layout LyX-Code
20752
20753 typedef char * FILE;
20754 \layout Standard
20755
20756 This type is the stream type implemented I/O in the PIC18F devices.
20757  Also the standard input and output streams are declared in stdio.h:
20758 \layout LyX-Code
20759
20760 extern FILE * stdin;
20761 \layout LyX-Code
20762
20763 extern FILE * stdout;
20764 \layout Standard
20765
20766 The FILE type is actually a generic pointer which defines one more type
20767  of generic pointers, the 
20768 \emph on 
20769 stream 
20770 \emph default 
20771 pointer.
20772  This new type has the format:
20773 \layout Standard
20774 \align center 
20775
20776 \begin_inset  Tabular
20777 <lyxtabular version="3" rows="2" columns="7">
20778 <features>
20779 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20780 <column alignment="center" valignment="top" width="0">
20781 <column alignment="center" valignment="top" leftline="true" width="0">
20782 <column alignment="center" valignment="top" leftline="true" width="0">
20783 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20784 <column alignment="center" valignment="top" width="0">
20785 <column alignment="left" valignment="top" rightline="true" width="0">
20786 <row topline="true" bottomline="true">
20787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20788 \begin_inset Text
20789
20790 \layout Standard
20791
20792 pointer type
20793 \end_inset 
20794 </cell>
20795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20796 \begin_inset Text
20797
20798 \layout Standard
20799
20800 <7:6>
20801 \end_inset 
20802 </cell>
20803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20804 \begin_inset Text
20805
20806 \layout Standard
20807
20808 <5>
20809 \end_inset 
20810 </cell>
20811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20812 \begin_inset Text
20813
20814 \layout Standard
20815
20816 <4>
20817 \end_inset 
20818 </cell>
20819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20820 \begin_inset Text
20821
20822 \layout Standard
20823
20824 <3:0>
20825 \end_inset 
20826 </cell>
20827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20828 \begin_inset Text
20829
20830 \layout Standard
20831
20832 rest of the pointer
20833 \end_inset 
20834 </cell>
20835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20836 \begin_inset Text
20837
20838 \layout Standard
20839
20840 descrption
20841 \end_inset 
20842 </cell>
20843 </row>
20844 <row topline="true" bottomline="true">
20845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20846 \begin_inset Text
20847
20848 \layout Standard
20849
20850 stream
20851 \end_inset 
20852 </cell>
20853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20854 \begin_inset Text
20855
20856 \layout Standard
20857
20858 00
20859 \end_inset 
20860 </cell>
20861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20862 \begin_inset Text
20863
20864 \layout Standard
20865
20866 1
20867 \end_inset 
20868 </cell>
20869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20870 \begin_inset Text
20871
20872 \layout Standard
20873
20874 0
20875 \end_inset 
20876 </cell>
20877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20878 \begin_inset Text
20879
20880 \layout Standard
20881
20882 nnnn
20883 \end_inset 
20884 </cell>
20885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20886 \begin_inset Text
20887
20888 \layout Standard
20889
20890
20891 \family typewriter 
20892 \shape slanted 
20893 \emph on 
20894 uuuuuuuu uuuuuuuu
20895 \end_inset 
20896 </cell>
20897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20898 \begin_inset Text
20899
20900 \layout Standard
20901
20902 upper byte high nubble is 0x2n, the rest are zeroes
20903 \end_inset 
20904 </cell>
20905 </row>
20906 </lyxtabular>
20907
20908 \end_inset 
20909
20910
20911 \layout Standard
20912
20913 Currently implemented there are 3 types of streams defined:
20914 \layout Standard
20915 \align center 
20916
20917 \begin_inset  Tabular
20918 <lyxtabular version="3" rows="4" columns="4">
20919 <features>
20920 <column alignment="center" valignment="top" leftline="true" width="0">
20921 <column alignment="center" valignment="top" leftline="true" width="0">
20922 <column alignment="center" valignment="top" leftline="true" width="0">
20923 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20924 <row topline="true" bottomline="true">
20925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20926 \begin_inset Text
20927
20928 \layout Standard
20929
20930 stream type
20931 \end_inset 
20932 </cell>
20933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20934 \begin_inset Text
20935
20936 \layout Standard
20937
20938 value
20939 \end_inset 
20940 </cell>
20941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20942 \begin_inset Text
20943
20944 \layout Standard
20945
20946 module
20947 \end_inset 
20948 </cell>
20949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20950 \begin_inset Text
20951
20952 \layout Standard
20953
20954 description
20955 \end_inset 
20956 </cell>
20957 </row>
20958 <row topline="true">
20959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20960 \begin_inset Text
20961
20962 \layout Standard
20963
20964 STREAM_USART
20965 \end_inset 
20966 </cell>
20967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20968 \begin_inset Text
20969
20970 \layout Standard
20971
20972
20973 \family typewriter 
20974 0x200000UL
20975 \end_inset 
20976 </cell>
20977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20978 \begin_inset Text
20979
20980 \layout Standard
20981
20982 USART
20983 \end_inset 
20984 </cell>
20985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20986 \begin_inset Text
20987
20988 \layout Standard
20989
20990 Writes/Reads characters via the USART peripheral
20991 \end_inset 
20992 </cell>
20993 </row>
20994 <row topline="true">
20995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20996 \begin_inset Text
20997
20998 \layout Standard
20999
21000 STREAM_MSSP
21001 \end_inset 
21002 </cell>
21003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21004 \begin_inset Text
21005
21006 \layout Standard
21007
21008
21009 \family typewriter 
21010 0x210000UL
21011 \end_inset 
21012 </cell>
21013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21014 \begin_inset Text
21015
21016 \layout Standard
21017
21018 MSSP
21019 \end_inset 
21020 </cell>
21021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21022 \begin_inset Text
21023
21024 \layout Standard
21025
21026 Writes/Reads characters via the MSSP peripheral
21027 \end_inset 
21028 </cell>
21029 </row>
21030 <row topline="true" bottomline="true">
21031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21032 \begin_inset Text
21033
21034 \layout Standard
21035
21036 STREAM_USER
21037 \end_inset 
21038 </cell>
21039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21040 \begin_inset Text
21041
21042 \layout Standard
21043
21044
21045 \family typewriter 
21046 0x2f0000UL
21047 \end_inset 
21048 </cell>
21049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21050 \begin_inset Text
21051
21052 \layout Standard
21053
21054 (none)
21055 \end_inset 
21056 </cell>
21057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21058 \begin_inset Text
21059
21060 \layout Standard
21061
21062 Writes/Reads characters via used defined functions
21063 \end_inset 
21064 </cell>
21065 </row>
21066 </lyxtabular>
21067
21068 \end_inset 
21069
21070
21071 \layout Standard
21072
21073 The stream identifiers are declared as macros in the stdio.h header.
21074 \layout Standard
21075
21076 In the libc library there exist the functions that are used to write to
21077  each of the above streams.
21078  These are
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_usart_putchar writes a character at the USART stream
21093 \layout List
21094 \labelwidthstring 00.00.0000
21095
21096 _
21097 \begin_inset ERT
21098 status Collapsed
21099
21100 \layout Standard
21101
21102 \backslash 
21103 /
21104 \end_inset 
21105
21106 _stream_mssp_putchar writes a character at the MSSP stream
21107 \layout List
21108 \labelwidthstring 00.00.0000
21109
21110 putchar dummy function.
21111  This writes a character to a user specified manner.
21112 \layout Standard
21113
21114 In order to increase performance 
21115 \emph on 
21116 putchar 
21117 \emph default 
21118 is declared in stdio.h as having its parameter in WREG (it has the wparam
21119  keyword).
21120  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
21121  in a user-friendly way.
21122  
21123 \emph on 
21124 arg
21125 \emph default 
21126  is the name of the variable that holds the character to print.
21127  An example follows:
21128 \layout LyX-Code
21129
21130 #include <pic18fregs.h>
21131 \newline 
21132 #include <stdio.h>
21133 \newline 
21134
21135 \newline 
21136 PUTCHAR( c )
21137 \layout LyX-Code
21138
21139 {
21140 \layout LyX-Code
21141
21142     PORTA = c;    /* dump character c to PORTA */
21143 \layout LyX-Code
21144
21145
21146 \newline 
21147
21148 \newline 
21149 void main(void)
21150 \layout LyX-Code
21151
21152 {
21153 \layout LyX-Code
21154
21155     stdout = STREAM_USER;    /* this is not necessary, since stdout points
21156 \layout LyX-Code
21157
21158                               * by default to STREAM_USER */
21159 \layout LyX-Code
21160
21161     printf (¨This is a printf test
21162 \backslash 
21163 n¨);
21164 \layout LyX-Code
21165
21166 }
21167 \layout LyX-Code
21168
21169 \layout Subsubsection
21170
21171 Printing functions
21172 \layout Standard
21173
21174 PIC16 contains an implementation of the printf-family of functions.
21175  There exist the following functions:
21176 \layout LyX-Code
21177
21178 extern unsigned int sprintf(char *buf, char *fmt, ...);
21179 \layout LyX-Code
21180
21181 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
21182 \layout LyX-Code
21183
21184 \layout LyX-Code
21185
21186 extern unsigned int printf(char *fmt, ...);
21187 \layout LyX-Code
21188
21189 extern unsigned int vprintf(char *fmt, va_lista ap);
21190 \layout LyX-Code
21191
21192 \layout LyX-Code
21193
21194 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
21195 \layout LyX-Code
21196
21197 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
21198 \layout Standard
21199
21200 For sprintf and vsprintf 
21201 \emph on 
21202 buf 
21203 \emph default 
21204 should normally be a data pointer where the resulting string will be placed.
21205  No range checking is done so the user should allocate the necessery buffer.
21206  For fprintf and vfprintf 
21207 \emph on 
21208 fp
21209 \emph default 
21210  should be a stream pointer (i.e.
21211  stdout, STREAM_MSSP, etc...).
21212 \layout Subsubsection
21213
21214 Signals
21215 \layout Standard
21216
21217 The PIC18F family of microcontrollers supports a number of interrupt sources.
21218  A list of these interrupts is shown in the following table:
21219 \layout Standard
21220 \align center 
21221
21222 \begin_inset  Tabular
21223 <lyxtabular version="3" rows="11" columns="4">
21224 <features>
21225 <column alignment="left" valignment="top" leftline="true" width="0">
21226 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21227 <column alignment="left" valignment="top" leftline="true" width="0">
21228 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21229 <row topline="true" bottomline="true">
21230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21231 \begin_inset Text
21232
21233 \layout Standard
21234
21235 signal name
21236 \end_inset 
21237 </cell>
21238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21239 \begin_inset Text
21240
21241 \layout Standard
21242
21243 description
21244 \end_inset 
21245 </cell>
21246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21247 \begin_inset Text
21248
21249 \layout Standard
21250
21251 signal name
21252 \end_inset 
21253 </cell>
21254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21255 \begin_inset Text
21256
21257 \layout Standard
21258
21259 descritpion
21260 \end_inset 
21261 </cell>
21262 </row>
21263 <row topline="true">
21264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21265 \begin_inset Text
21266
21267 \layout Standard
21268
21269 SIG_RB
21270 \end_inset 
21271 </cell>
21272 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21273 \begin_inset Text
21274
21275 \layout Standard
21276
21277 PORTB change interrupt
21278 \end_inset 
21279 </cell>
21280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21281 \begin_inset Text
21282
21283 \layout Standard
21284
21285 SIG_EE
21286 \end_inset 
21287 </cell>
21288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21289 \begin_inset Text
21290
21291 \layout Standard
21292
21293 EEPROM/FLASH write complete interrupt
21294 \end_inset 
21295 </cell>
21296 </row>
21297 <row topline="true">
21298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21299 \begin_inset Text
21300
21301 \layout Standard
21302
21303 SIG_INT0
21304 \end_inset 
21305 </cell>
21306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21307 \begin_inset Text
21308
21309 \layout Standard
21310
21311 INT0 external interrupt
21312 \end_inset 
21313 </cell>
21314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21315 \begin_inset Text
21316
21317 \layout Standard
21318
21319 SIG_BCOL
21320 \end_inset 
21321 </cell>
21322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21323 \begin_inset Text
21324
21325 \layout Standard
21326
21327 Bus collision interrupt
21328 \end_inset 
21329 </cell>
21330 </row>
21331 <row topline="true">
21332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21333 \begin_inset Text
21334
21335 \layout Standard
21336
21337 SIG_INT1
21338 \end_inset 
21339 </cell>
21340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21341 \begin_inset Text
21342
21343 \layout Standard
21344
21345 INT1 external interrupt
21346 \end_inset 
21347 </cell>
21348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21349 \begin_inset Text
21350
21351 \layout Standard
21352
21353 SIG_LVD
21354 \end_inset 
21355 </cell>
21356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21357 \begin_inset Text
21358
21359 \layout Standard
21360
21361 Low voltage detect interrupt
21362 \end_inset 
21363 </cell>
21364 </row>
21365 <row topline="true">
21366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21367 \begin_inset Text
21368
21369 \layout Standard
21370
21371 SIG_INT2
21372 \end_inset 
21373 </cell>
21374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21375 \begin_inset Text
21376
21377 \layout Standard
21378
21379 INT2 external interrupt
21380 \end_inset 
21381 </cell>
21382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21383 \begin_inset Text
21384
21385 \layout Standard
21386
21387 SIG_PSP
21388 \end_inset 
21389 </cell>
21390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21391 \begin_inset Text
21392
21393 \layout Standard
21394
21395 Parallel slave port interrupt
21396 \end_inset 
21397 </cell>
21398 </row>
21399 <row topline="true">
21400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21401 \begin_inset Text
21402
21403 \layout Standard
21404
21405 SIG_CCP1
21406 \end_inset 
21407 </cell>
21408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21409 \begin_inset Text
21410
21411 \layout Standard
21412
21413 CCP1 module interrupt
21414 \end_inset 
21415 </cell>
21416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21417 \begin_inset Text
21418
21419 \layout Standard
21420
21421 SIG_AD
21422 \end_inset 
21423 </cell>
21424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21425 \begin_inset Text
21426
21427 \layout Standard
21428
21429 AD convertion complete interrupt
21430 \end_inset 
21431 </cell>
21432 </row>
21433 <row topline="true">
21434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21435 \begin_inset Text
21436
21437 \layout Standard
21438
21439 SIG_CCP2
21440 \end_inset 
21441 </cell>
21442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21443 \begin_inset Text
21444
21445 \layout Standard
21446
21447 CCP2 module interrupt
21448 \end_inset 
21449 </cell>
21450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21451 \begin_inset Text
21452
21453 \layout Standard
21454
21455 SIG_RC
21456 \end_inset 
21457 </cell>
21458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21459 \begin_inset Text
21460
21461 \layout Standard
21462
21463 USART receive interrupt
21464 \end_inset 
21465 </cell>
21466 </row>
21467 <row topline="true">
21468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21469 \begin_inset Text
21470
21471 \layout Standard
21472
21473 SIG_TMR0
21474 \end_inset 
21475 </cell>
21476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21477 \begin_inset Text
21478
21479 \layout Standard
21480
21481 TMR0 overflow interrupt
21482 \end_inset 
21483 </cell>
21484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21485 \begin_inset Text
21486
21487 \layout Standard
21488
21489 SIG_TX
21490 \end_inset 
21491 </cell>
21492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21493 \begin_inset Text
21494
21495 \layout Standard
21496
21497 USART transmit interrupt
21498 \end_inset 
21499 </cell>
21500 </row>
21501 <row topline="true">
21502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21503 \begin_inset Text
21504
21505 \layout Standard
21506
21507 SIG_TMR1
21508 \end_inset 
21509 </cell>
21510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21511 \begin_inset Text
21512
21513 \layout Standard
21514
21515 TMR1 overflow interrupt
21516 \end_inset 
21517 </cell>
21518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21519 \begin_inset Text
21520
21521 \layout Standard
21522
21523 SIG_MSSP
21524 \end_inset 
21525 </cell>
21526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21527 \begin_inset Text
21528
21529 \layout Standard
21530
21531 SSP receive/transmit interrupt
21532 \end_inset 
21533 </cell>
21534 </row>
21535 <row topline="true">
21536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21537 \begin_inset Text
21538
21539 \layout Standard
21540
21541 SIG_TMR2
21542 \end_inset 
21543 </cell>
21544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21545 \begin_inset Text
21546
21547 \layout Standard
21548
21549 TMR2 matches PR2 interrupt
21550 \end_inset 
21551 </cell>
21552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21553 \begin_inset Text
21554
21555 \layout Standard
21556
21557 \end_inset 
21558 </cell>
21559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21560 \begin_inset Text
21561
21562 \layout Standard
21563
21564 \end_inset 
21565 </cell>
21566 </row>
21567 <row topline="true" bottomline="true">
21568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21569 \begin_inset Text
21570
21571 \layout Standard
21572
21573 SIG_TMR3
21574 \end_inset 
21575 </cell>
21576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21577 \begin_inset Text
21578
21579 \layout Standard
21580
21581 TMR3 overflow interrupt
21582 \end_inset 
21583 </cell>
21584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21585 \begin_inset Text
21586
21587 \layout Standard
21588
21589 \end_inset 
21590 </cell>
21591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21592 \begin_inset Text
21593
21594 \layout Standard
21595
21596 \end_inset 
21597 </cell>
21598 </row>
21599 </lyxtabular>
21600
21601 \end_inset 
21602
21603
21604 \layout Standard
21605
21606 The prototypes for these names are defined in the header file 
21607 \emph on 
21608 signal.h
21609 \emph default 
21610  .
21611 \layout Standard
21612
21613 In order to simplify signal handling, a number of macros is provided:
21614 \layout List
21615 \labelwidthstring 00.00.0000
21616
21617 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21618  high priority interrupts.
21619  
21620 \emph on 
21621 name
21622 \emph default 
21623  is the function name to use.
21624 \layout List
21625 \labelwidthstring 00.00.0000
21626
21627 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21628  low priority interrupt.
21629  
21630 \emph on 
21631 name
21632 \emph default 
21633  is the function name to use.
21634 \layout List
21635 \labelwidthstring 00.00.0000
21636
21637 DEF_HANDLER(sig,handler) define a handler for signal 
21638 \emph on 
21639 sig.
21640 \layout List
21641 \labelwidthstring 00.00.0000
21642
21643 END_DEF end the declaration of the dispatch table.
21644 \layout Standard
21645
21646 Additionally there are two more macros to simplify the declaration of the
21647  signal handler:
21648 \layout List
21649 \labelwidthstring 00.00.0000
21650
21651
21652 \series medium 
21653 SIGHANDLER(handler) 
21654 \series default 
21655 this declares the function prototype for the 
21656 \emph on 
21657 handler
21658 \emph default 
21659  function.
21660 \layout List
21661 \labelwidthstring 00.00.0000
21662
21663 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21664 \layout Standard
21665
21666 An example of using the macros above is shown below:
21667 \layout LyX-Code
21668
21669 #include <pic18fregs.h>
21670 \layout LyX-Code
21671
21672 #include <signal.h>
21673 \newline 
21674
21675 \newline 
21676 DEF_INTHIGH(high_int)
21677 \layout LyX-Code
21678
21679 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21680 \layout LyX-Code
21681
21682 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21683 \layout LyX-Code
21684
21685 END_DEF
21686 \newline 
21687
21688 \newline 
21689 SIGHANDLER(_tmr0_handler)
21690 \layout LyX-Code
21691
21692 {
21693 \layout LyX-Code
21694
21695   /* action to be taken when timer 0 overflows */
21696 \layout LyX-Code
21697
21698 }
21699 \newline 
21700
21701 \newline 
21702 SIGHANDLERNAKED(_bcol_handler)
21703 \layout LyX-Code
21704
21705 {
21706 \layout LyX-Code
21707
21708   _asm
21709 \layout LyX-Code
21710
21711     /* action to be taken when bus collision occurs */
21712 \layout LyX-Code
21713
21714     retfie
21715 \layout LyX-Code
21716
21717  _endasm;
21718 \layout LyX-Code
21719
21720 }
21721 \layout Standard
21722
21723
21724 \series bold 
21725 NOTES:
21726 \series default 
21727  Special care should be taken when using the above scheme:
21728 \layout Itemize
21729
21730 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21731 \layout Itemize
21732
21733 when declaring SIGHANDLERNAKED handler never forget to use 
21734 \emph on 
21735 retfie
21736 \emph default 
21737  for proper returning.
21738 \layout Subsection
21739
21740 PIC16 Port -- Tips
21741 \layout Standard
21742
21743 Here you can find some general tips for compiling programs with SDCC/pic16.
21744 \layout Subsubsection
21745
21746 Stack size
21747 \layout Standard
21748
21749 The default stack
21750 \begin_inset LatexCommand \index{PIC16!stack}
21751
21752 \end_inset 
21753
21754  size (that is 64 bytes) probably is enough for many programs.
21755  One must take care that when there are many levels of function nesting,
21756  or there is excessive usage of stack, its size should be extended.
21757  An example of such a case is the printf/sprintf family of functions.
21758  If you encounter problems like not being able to print integers, then you
21759  need to set the stack size around the maximum (256 for small stack model).
21760  The following diagram shows what happens when calling printf to print an
21761  integer:
21762 \layout LyX-Code
21763
21764 printf () --> ltoa () --> ultoa () --> divschar ()
21765 \layout Standard
21766
21767 It is should be understood that stack is easily consumed when calling complicate
21768 d functions.
21769  Using command line arguments like -
21770 \begin_inset ERT
21771 status Collapsed
21772
21773 \layout Standard
21774
21775 \backslash 
21776 /
21777 \end_inset 
21778
21779 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
21780  stack frames.
21781  Other ways to reduce stack usage may exist.
21782 \layout Subsection
21783
21784 Known bugs
21785 \layout Standard
21786
21787 The PIC16 Port currently does not pass SDCC's regression test
21788 \begin_inset LatexCommand \index{Regression test (PIC16)}
21789
21790 \end_inset 
21791
21792  suite (see section 
21793 \begin_inset LatexCommand \ref{sec:Quality-control}
21794
21795 \end_inset 
21796
21797 ) and thus the nightly regression tests for the PIC16 target are currently
21798  disabled for all hosts except for 
21799 \emph on 
21800 Linux on Opteron.
21801
21802 \emph default 
21803  This means you can see the result of the PIC16 regression tests f.e.
21804  by checking the log files in 
21805 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
21806
21807 \end_inset 
21808
21809  (pick the most up to date file there, scroll down, lend a hand).
21810 \layout Chapter
21811
21812 Debugging
21813 \layout Standard
21814
21815 There are several approaches to debugging your code.
21816  This chapter is meant to show your options and to give detail on some of
21817  them:
21818 \newline 
21819
21820 \newline 
21821 When writing your code:
21822 \layout Itemize
21823
21824 write your code with debugging in mind (avoid duplicating code, put conceptually
21825  similar variables into structs, use structured code, have strategic points
21826  within your code where all variables are consistent, ...)
21827 \layout Itemize
21828
21829 run a syntax-checking tool like splint
21830 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21831
21832 \end_inset 
21833
21834
21835 \begin_inset LatexCommand \index{lint (syntax checking tool)}
21836
21837 \end_inset 
21838
21839  (see -
21840 \begin_inset ERT
21841 status Collapsed
21842
21843 \layout Standard
21844
21845 \backslash 
21846 /
21847 \end_inset 
21848
21849 -more-pedantic 
21850 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21851
21852 \end_inset 
21853
21854 ) over the code.
21855 \layout Itemize
21856
21857 for the high level code use a C-compiler (like f.e.
21858  GCC) to compile run and debug the code on your host.
21859  See (see -
21860 \begin_inset ERT
21861 status Collapsed
21862
21863 \layout Standard
21864
21865 \backslash 
21866 /
21867 \end_inset 
21868
21869 -more-pedantic 
21870 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21871
21872 \end_inset 
21873
21874  ) on howto handle syntax extensions like __xdata, __at(), ...
21875  
21876 \layout Itemize
21877
21878 use another C-compiler to compile code for your target.
21879  Always an option but not recommended:) And not very likely to help you.
21880  If you seriously consider walking this path you should at least occasionally
21881  check portability of your code.
21882  Most commercial compiler vendors will offer an evaluation version so you
21883  can test compile your code or snippets of your code.
21884 \layout Standard
21885
21886 Debugging on a simulator:
21887 \layout Itemize
21888
21889 there is a separate section about SDCDB (section 
21890 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
21891
21892 \end_inset 
21893
21894 ) below.
21895 \layout Itemize
21896
21897 or (8051 specific) use a freeware/commercial simulator which interfaces
21898  to the AOMF
21899 \begin_inset LatexCommand \index{AOMF, AOMF51}
21900
21901 \end_inset 
21902
21903  file (see 
21904 \begin_inset LatexCommand \ref{OMF file}
21905
21906 \end_inset 
21907
21908 ) optionally generated by SDCC.
21909 \layout Standard
21910
21911 Debugging On-target: 
21912 \layout Itemize
21913
21914 use a MCU port pin to serially output debug data to the RS232 port of your
21915  host.
21916  You'll probably want some level shifting device typically involving a MAX232
21917  or similar IC.
21918  If the hardware serial port of the MCU is not available search for 'Software
21919  UART' in your favourite search machine.
21920 \layout Itemize
21921
21922 use an on-target monitor.
21923  In this context a monitor is a small program which usually accepts commands
21924  via a serial line and allows to set program counter, to single step through
21925  a program and read/write memory locations.
21926  For the 8051 good examples of monitors are paulmon and cmon51 (see section
21927  
21928 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
21929
21930 \end_inset 
21931
21932 ).
21933 \layout Itemize
21934
21935 toggle MCU port pins at strategic points within your code and use an oscilloscop
21936 e.
21937  A 
21938 \emph on 
21939 digital oscilloscope
21940 \emph default 
21941
21942 \begin_inset LatexCommand \index{Oscilloscope}
21943
21944 \end_inset 
21945
21946  with deep trace memory is really helpful especially if you have to debug
21947  a realtime application.
21948  If you need to monitor more pins than your oscilloscope provides you can
21949  sometimes get away with a small R-2R network.
21950  On a single channel oscilloscope you could f.e.
21951  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
21952 k
21953 \begin_inset Formula $\Omega$
21954 \end_inset 
21955
21956  resistor and the other one by a 5\SpecialChar ~
21957 k
21958 \begin_inset Formula $\Omega$
21959 \end_inset 
21960
21961  resistor to the oscilloscope probe (check output drive capability of the
21962  pins you want to monitor).
21963  If you need to monitor many more pins a 
21964 \emph on 
21965 logic analyzer
21966 \emph default 
21967  will be handy.
21968 \layout Itemize
21969
21970 use an ICE (
21971 \emph on 
21972 i
21973 \emph default 
21974
21975 \emph on 
21976 c
21977 \emph default 
21978 ircuit 
21979 \emph on 
21980 e
21981 \emph default 
21982 mulator
21983 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
21984
21985 \end_inset 
21986
21987 ).
21988  Usually very expensive.
21989  And very nice to have too.
21990  And usually locks you (for years...) to the devices the ICE can emulate.
21991  
21992 \layout Itemize
21993
21994 use a remote debugger.
21995  In most 8-bit systems the symbol information is not available on the target,
21996  and a complete debugger is too bulky for the target system.
21997  Therefore usually a debugger on the host system connects to an on-target
21998  debugging stub which accepts only primitive commands.
21999  
22000 \newline 
22001 Terms to enter into your favourite search engine could be 'remote debugging',
22002  'gdb stub' or 'inferior debugger'.
22003  (is there one?)
22004 \layout Itemize
22005
22006 use an on target hardware debugger.
22007  Some of the more modern MCUs include hardware support for setting break
22008  points and monitoring/changing variables by using dedicated hardware pins.
22009  This facility doesn't require additional code to run on the target and
22010  
22011 \emph on 
22012 usually
22013 \emph default 
22014  doesn't affect runtime behaviour until a breakpoint is hit.
22015  For the mcs51 most hardware debuggers use the AOMF
22016 \begin_inset LatexCommand \index{AOMF, AOMF51}
22017
22018 \end_inset 
22019
22020  file (see 
22021 \begin_inset LatexCommand \ref{OMF file}
22022
22023 \end_inset 
22024
22025 ) as input file.
22026  
22027 \layout Standard
22028
22029 Last not least:
22030 \layout Itemize
22031
22032 if you are not familiar with any of the following terms you're likely to
22033  run into problems rather sooner than later: 
22034 \emph on 
22035 volatile
22036 \emph default 
22037
22038 \emph on 
22039 atomic
22040 \emph default 
22041
22042 \emph on 
22043 memory map
22044 \emph default 
22045
22046 \emph on 
22047 overlay
22048 \emph default 
22049 .
22050  As an embedded programmer you 
22051 \emph on 
22052 have
22053 \emph default 
22054  to know them so why not look them up 
22055 \emph on 
22056 before
22057 \emph default 
22058  you have problems?)
22059 \layout Itemize
22060
22061 tell someone else about your problem (actually this is a surprisingly effective
22062  means to hunt down the bug even if the listener is not familiar with your
22063  environment).
22064  As 'failure to communicate' is probably one of the job-induced deformations
22065  of an embedded programmer this is highly encouraged.
22066 \layout Section
22067
22068 Debugging with SDCDB
22069 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
22070
22071 \end_inset 
22072
22073
22074 \begin_inset LatexCommand \index{SDCDB (debugger)}
22075
22076 \end_inset 
22077
22078  
22079 \layout Standard
22080
22081 SDCC is distributed with a source level debugger
22082 \begin_inset LatexCommand \index{Debugger}
22083
22084 \end_inset 
22085
22086 .
22087  The debugger uses a command line interface, the command repertoire of the
22088  debugger has been kept as close to gdb
22089 \begin_inset LatexCommand \index{gdb}
22090
22091 \end_inset 
22092
22093  (the GNU debugger) as possible.
22094  The configuration and build process is part of the standard compiler installati
22095 on, which also builds and installs the debugger in the target directory
22096  specified during configuration.
22097  The debugger allows you debug BOTH at the C source and at the ASM source
22098  level.
22099 \layout Subsection
22100
22101 Compiling for Debugging
22102 \layout Standard
22103
22104 The -
22105 \begin_inset ERT
22106 status Collapsed
22107
22108 \layout Standard
22109
22110 \backslash 
22111 /
22112 \end_inset 
22113
22114 -debug
22115 \begin_inset LatexCommand \index{-\/-debug}
22116
22117 \end_inset 
22118
22119  option must be specified for all files for which debug information is to
22120  be generated.
22121  The compiler generates a .adb file for each of these files.
22122  The linker creates the .cdb
22123 \begin_inset LatexCommand \index{<file>.cdb}
22124
22125 \end_inset 
22126
22127  file from the .adb
22128 \begin_inset LatexCommand \index{<file>.adb}
22129
22130 \end_inset 
22131
22132  files and the address information.
22133  This .cdb is used by the debugger.
22134 \layout Subsection
22135
22136 How the Debugger Works
22137 \layout Standard
22138
22139 When the -
22140 \begin_inset ERT
22141 status Collapsed
22142
22143 \layout Standard
22144
22145 \backslash 
22146 /
22147 \end_inset 
22148
22149 -debug option is specified the compiler generates extra symbol information
22150  some of which are put into the assembler source and some are put into the
22151  .adb file.
22152  Then the linker creates the .cdb file from the individual .adb files with
22153  the address information for the symbols.
22154  The debugger reads the symbolic information generated by the compiler &
22155  the address information generated by the linker.
22156  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
22157  execution is controlled by the debugger.
22158  When a command is issued for the debugger, it translates it into appropriate
22159  commands for the simulator.
22160  (Currently SDCDM only connects to the simulator but 
22161 \emph on 
22162 newcdb
22163 \emph default 
22164  at 
22165 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
22166
22167 \end_inset 
22168
22169  is an effort to connect directly to the hardware.) 
22170 \layout Subsection
22171
22172 Starting the Debugger SDCDB
22173 \layout Standard
22174
22175 The debugger can be started using the following command line.
22176  (Assume the file you are debugging has the file name foo).
22177 \newline 
22178
22179 \newline 
22180
22181 \family sans 
22182 \series bold 
22183 sdcdb foo
22184 \newline 
22185
22186 \family default 
22187 \series default 
22188
22189 \newline 
22190 The debugger will look for the following files.
22191 \layout Itemize
22192
22193 foo.c - the source file.
22194 \layout Itemize
22195
22196 foo.cdb - the debugger symbol information file.
22197 \layout Itemize
22198
22199 foo.ihx - the Intel hex format
22200 \begin_inset LatexCommand \index{Intel hex format}
22201
22202 \end_inset 
22203
22204  object file.
22205 \layout Subsection
22206
22207 SDCDB Command Line Options
22208 \layout Itemize
22209
22210 -
22211 \begin_inset ERT
22212 status Collapsed
22213
22214 \layout Standard
22215
22216 \backslash 
22217 /
22218 \end_inset 
22219
22220 -directory=<source file directory> this option can used to specify the directory
22221  search list.
22222  The debugger will look into the directory list specified for source, cdb
22223  & ihx files.
22224  The items in the directory list must be separated by ':', e.g.
22225  if the source files can be in the directories /home/src1 and /home/src2,
22226  the -
22227 \begin_inset ERT
22228 status Collapsed
22229
22230 \layout Standard
22231
22232 \backslash 
22233 /
22234 \end_inset 
22235
22236 -directory option should be -
22237 \begin_inset ERT
22238 status Collapsed
22239
22240 \layout Standard
22241
22242 \backslash 
22243 /
22244 \end_inset 
22245
22246 -directory=/home/src1:/home/src2.
22247  Note there can be no spaces in the option.
22248  
22249 \layout Itemize
22250
22251 -cd <directory> - change to the <directory>.
22252 \layout Itemize
22253
22254 -fullname - used by GUI front ends.
22255 \layout Itemize
22256
22257 -cpu <cpu-type> - this argument is passed to the simulator please see the
22258  simulator docs for details.
22259 \layout Itemize
22260
22261 -X <Clock frequency > this options is passed to the simulator please see
22262  the simulator docs for details.
22263 \layout Itemize
22264
22265 -s <serial port file> passed to simulator see the simulator docs for details.
22266 \layout Itemize
22267
22268 -S <serial in,out> passed to simulator see the simulator docs for details.
22269 \layout Itemize
22270
22271 -k <port number> passed to simulator see the simulator docs for details.
22272 \layout Subsection
22273
22274 SDCDB Debugger Commands
22275 \layout Standard
22276
22277 As mentioned earlier the command interface for the debugger has been deliberatel
22278 y kept as close the GNU debugger gdb, as possible.
22279  This will help the integration with existing graphical user interfaces
22280  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
22281  If you use a graphical user interface for the debugger you can skip this
22282  section.
22283 \layout Subsubsection*
22284
22285 break [line | file:line | function | file:function]
22286 \layout Standard
22287
22288 Set breakpoint at specified line or function:
22289 \newline 
22290
22291 \newline 
22292
22293 \family sans 
22294 \series bold 
22295 sdcdb>break 100 
22296 \newline 
22297 sdcdb>break foo.c:100
22298 \newline 
22299 sdcdb>break funcfoo
22300 \newline 
22301 sdcdb>break foo.c:funcfoo
22302 \layout Subsubsection*
22303
22304 clear [line | file:line | function | file:function ]
22305 \layout Standard
22306
22307 Clear breakpoint at specified line or function:
22308 \newline 
22309
22310 \newline 
22311
22312 \family sans 
22313 \series bold 
22314 sdcdb>clear 100
22315 \newline 
22316 sdcdb>clear foo.c:100
22317 \newline 
22318 sdcdb>clear funcfoo
22319 \newline 
22320 sdcdb>clear foo.c:funcfoo
22321 \layout Subsubsection*
22322
22323 continue
22324 \layout Standard
22325
22326 Continue program being debugged, after breakpoint.
22327 \layout Subsubsection*
22328
22329 finish
22330 \layout Standard
22331
22332 Execute till the end of the current function.
22333 \layout Subsubsection*
22334
22335 delete [n]
22336 \layout Standard
22337
22338 Delete breakpoint number 'n'.
22339  If used without any option clear ALL user defined break points.
22340 \layout Subsubsection*
22341
22342 info [break | stack | frame | registers ]
22343 \layout Itemize
22344
22345 info break - list all breakpoints
22346 \layout Itemize
22347
22348 info stack - show the function call stack.
22349 \layout Itemize
22350
22351 info frame - show information about the current execution frame.
22352 \layout Itemize
22353
22354 info registers - show content of all registers.
22355 \layout Subsubsection*
22356
22357 step
22358 \layout Standard
22359
22360 Step program until it reaches a different source line.
22361  Note: pressing <return> repeats the last command.
22362 \layout Subsubsection*
22363
22364 next
22365 \layout Standard
22366
22367 Step program, proceeding through subroutine calls.
22368 \layout Subsubsection*
22369
22370 run
22371 \layout Standard
22372
22373 Start debugged program.
22374 \layout Subsubsection*
22375
22376 ptype variable 
22377 \layout Standard
22378
22379 Print type information of the variable.
22380 \layout Subsubsection*
22381
22382 print variable
22383 \layout Standard
22384
22385 print value of variable.
22386 \layout Subsubsection*
22387
22388 file filename
22389 \layout Standard
22390
22391 load the given file name.
22392  Note this is an alternate method of loading file for debugging.
22393 \layout Subsubsection*
22394
22395 frame
22396 \layout Standard
22397
22398 print information about current frame.
22399 \layout Subsubsection*
22400
22401 set srcmode
22402 \layout Standard
22403
22404 Toggle between C source & assembly source.
22405 \layout Subsubsection*
22406
22407 ! simulator command
22408 \layout Standard
22409
22410 Send the string following '!' to the simulator, the simulator response is
22411  displayed.
22412  Note the debugger does not interpret the command being sent to the simulator,
22413  so if a command like 'go' is sent the debugger can loose its execution
22414  context and may display incorrect values.
22415 \layout Subsubsection*
22416
22417 quit
22418 \layout Standard
22419
22420 "Watch me now.
22421  Iam going Down.
22422  My name is Bobby Brown"
22423 \layout Subsection
22424
22425 Interfacing SDCDB with DDD
22426 \layout Comment
22427
22428 The screenshot was converted from png to eps with: 
22429 \begin_inset Quotes sld
22430 \end_inset 
22431
22432 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22433 \begin_inset Quotes srd
22434 \end_inset 
22435
22436  which produces a pretty compact eps file which is free from compression
22437  artifacts.
22438 \layout Comment
22439
22440 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22441  as this broke the build system on Sourceforge (pdf-file was broken.
22442  pdflatex does not accept eps files).
22443 \layout Standard
22444
22445 The 
22446 \emph on 
22447 p
22448 \emph default 
22449 ortable 
22450 \emph on 
22451 n
22452 \emph default 
22453 etwork 
22454 \emph on 
22455 g
22456 \emph default 
22457 raphics File 
22458 \size footnotesize 
22459
22460 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22461
22462 \end_inset 
22463
22464
22465 \size default 
22466  shows a screenshot of a debugging session with DDD
22467 \begin_inset LatexCommand \index{DDD (debugger)}
22468
22469 \end_inset 
22470
22471  (Unix only) on a simulated 8032.
22472  The debugging session might not run as smoothly as the screenshot suggests.
22473  The debugger allows setting of breakpoints, displaying and changing variables,
22474  single stepping through C and assembler code.
22475  
22476 \newline 
22477 The source was compiled with 
22478 \family sans 
22479 \series bold 
22480
22481 \newline 
22482
22483 \newline 
22484 sdcc -
22485 \family default 
22486 \series default 
22487
22488 \begin_inset ERT
22489 status Collapsed
22490
22491 \layout Standard
22492
22493 \backslash 
22494 /
22495 \end_inset 
22496
22497
22498 \family sans 
22499 \series bold 
22500 -debug ddd_example.c
22501 \family default 
22502 \series default 
22503  
22504 \family sans 
22505 \series bold 
22506
22507 \newline 
22508
22509 \family default 
22510 \series default 
22511
22512 \newline 
22513 and DDD was invoked with 
22514 \family sans 
22515 \series bold 
22516
22517 \newline 
22518
22519 \newline 
22520 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22521 \layout Subsection
22522
22523 Interfacing SDCDB with XEmacs
22524 \begin_inset LatexCommand \index{XEmacs}
22525
22526 \end_inset 
22527
22528
22529 \begin_inset LatexCommand \index{Emacs}
22530
22531 \end_inset 
22532
22533
22534 \layout Standard
22535
22536 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22537  sdcdb.el and sdcdbsrc.el.
22538  These two files can be found in the $(prefix)/bin directory after the installat
22539 ion is complete.
22540  These files need to be loaded into XEmacs for the interface to work.
22541  This can be done at XEmacs startup time by inserting the following into
22542  your '.xemacs' file (which can be found in your HOME directory): 
22543 \newline 
22544
22545 \newline 
22546
22547 \family typewriter 
22548 (load-file sdcdbsrc.el) 
22549 \family default 
22550
22551 \newline 
22552
22553 \newline 
22554 .xemacs is a lisp file so the () around the command is REQUIRED.
22555  The files can also be loaded dynamically while XEmacs is running, set the
22556  environment variable 'EMACSLOADPATH' to the installation bin directory
22557  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22558  To start the interface enter the following command: 
22559 \newline 
22560
22561 \newline 
22562
22563 \family sans 
22564 \series bold 
22565 ESC-x sdcdbsrc
22566 \family default 
22567 \series default 
22568
22569 \newline 
22570
22571 \newline 
22572 You will prompted to enter the file name to be debugged.
22573  
22574 \newline 
22575
22576 \newline 
22577 The command line options that are passed to the simulator directly are bound
22578  to default values in the file sdcdbsrc.el.
22579  The variables are listed below, these values maybe changed as required.
22580 \layout Itemize
22581
22582 sdcdbsrc-cpu-type '51
22583 \layout Itemize
22584
22585 sdcdbsrc-frequency '11059200
22586 \layout Itemize
22587
22588 sdcdbsrc-serial nil
22589 \layout Standard
22590
22591 The following is a list of key mapping for the debugger interface.
22592 \layout Standard
22593
22594 \SpecialChar ~
22595
22596 \family typewriter 
22597
22598 \newline 
22599 ;;\SpecialChar ~
22600 Current Listing :: 
22601 \newline 
22602 ;;key\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 binding\SpecialChar ~
22617 \SpecialChar ~
22618 \SpecialChar ~
22619 \SpecialChar ~
22620 \SpecialChar ~
22621 \SpecialChar ~
22622 \SpecialChar ~
22623 \SpecialChar ~
22624 \SpecialChar ~
22625 \SpecialChar ~
22626 \SpecialChar ~
22627 \SpecialChar ~
22628 \SpecialChar ~
22629 \SpecialChar ~
22630 \SpecialChar ~
22631 \SpecialChar ~
22632 \SpecialChar ~
22633 \SpecialChar ~
22634 \SpecialChar ~
22635 \SpecialChar ~
22636 \SpecialChar ~
22637 \SpecialChar ~
22638 Comment 
22639 \newline 
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 \SpecialChar ~
22663 \SpecialChar ~
22664 \SpecialChar ~
22665 \SpecialChar ~
22666 \SpecialChar ~
22667 \SpecialChar ~
22668 \SpecialChar ~
22669 \SpecialChar ~
22670 \SpecialChar ~
22671 \SpecialChar ~
22672 \SpecialChar ~
22673 \SpecialChar ~
22674 \SpecialChar ~
22675 \SpecialChar ~
22676 -------
22677 \newline 
22678 ;; 
22679 \newline 
22680 ;;\SpecialChar ~
22681 n\SpecialChar ~
22682 \SpecialChar ~
22683 \SpecialChar ~
22684 \SpecialChar ~
22685 \SpecialChar ~
22686 \SpecialChar ~
22687 \SpecialChar ~
22688 \SpecialChar ~
22689 \SpecialChar ~
22690 \SpecialChar ~
22691 \SpecialChar ~
22692 \SpecialChar ~
22693 \SpecialChar ~
22694 \SpecialChar ~
22695 \SpecialChar ~
22696 sdcdb-next-from-src\SpecialChar ~
22697 \SpecialChar ~
22698 \SpecialChar ~
22699 \SpecialChar ~
22700 \SpecialChar ~
22701 \SpecialChar ~
22702 \SpecialChar ~
22703 \SpecialChar ~
22704 \SpecialChar ~
22705 \SpecialChar ~
22706 SDCDB next command 
22707 \newline 
22708 ;;\SpecialChar ~
22709 b\SpecialChar ~
22710 \SpecialChar ~
22711 \SpecialChar ~
22712 \SpecialChar ~
22713 \SpecialChar ~
22714 \SpecialChar ~
22715 \SpecialChar ~
22716 \SpecialChar ~
22717 \SpecialChar ~
22718 \SpecialChar ~
22719 \SpecialChar ~
22720 \SpecialChar ~
22721 \SpecialChar ~
22722 \SpecialChar ~
22723 \SpecialChar ~
22724 sdcdb-back-from-src\SpecialChar ~
22725 \SpecialChar ~
22726 \SpecialChar ~
22727 \SpecialChar ~
22728 \SpecialChar ~
22729 \SpecialChar ~
22730 \SpecialChar ~
22731 \SpecialChar ~
22732 \SpecialChar ~
22733 \SpecialChar ~
22734 SDCDB back command 
22735 \newline 
22736 ;;\SpecialChar ~
22737 c\SpecialChar ~
22738 \SpecialChar ~
22739 \SpecialChar ~
22740 \SpecialChar ~
22741 \SpecialChar ~
22742 \SpecialChar ~
22743 \SpecialChar ~
22744 \SpecialChar ~
22745 \SpecialChar ~
22746 \SpecialChar ~
22747 \SpecialChar ~
22748 \SpecialChar ~
22749 \SpecialChar ~
22750 \SpecialChar ~
22751 \SpecialChar ~
22752 sdcdb-cont-from-src\SpecialChar ~
22753 \SpecialChar ~
22754 \SpecialChar ~
22755 \SpecialChar ~
22756 \SpecialChar ~
22757 \SpecialChar ~
22758 \SpecialChar ~
22759 \SpecialChar ~
22760 \SpecialChar ~
22761 \SpecialChar ~
22762 SDCDB continue command
22763 \newline 
22764 ;;\SpecialChar ~
22765 s\SpecialChar ~
22766 \SpecialChar ~
22767 \SpecialChar ~
22768 \SpecialChar ~
22769 \SpecialChar ~
22770 \SpecialChar ~
22771 \SpecialChar ~
22772 \SpecialChar ~
22773 \SpecialChar ~
22774 \SpecialChar ~
22775 \SpecialChar ~
22776 \SpecialChar ~
22777 \SpecialChar ~
22778 \SpecialChar ~
22779 \SpecialChar ~
22780 sdcdb-step-from-src\SpecialChar ~
22781 \SpecialChar ~
22782 \SpecialChar ~
22783 \SpecialChar ~
22784 \SpecialChar ~
22785 \SpecialChar ~
22786 \SpecialChar ~
22787 \SpecialChar ~
22788 \SpecialChar ~
22789 \SpecialChar ~
22790 SDCDB step command 
22791 \newline 
22792 ;;\SpecialChar ~
22793 ?\SpecialChar ~
22794 \SpecialChar ~
22795 \SpecialChar ~
22796 \SpecialChar ~
22797 \SpecialChar ~
22798 \SpecialChar ~
22799 \SpecialChar ~
22800 \SpecialChar ~
22801 \SpecialChar ~
22802 \SpecialChar ~
22803 \SpecialChar ~
22804 \SpecialChar ~
22805 \SpecialChar ~
22806 \SpecialChar ~
22807 \SpecialChar ~
22808 sdcdb-whatis-c-sexp\SpecialChar ~
22809 \SpecialChar ~
22810 \SpecialChar ~
22811 \SpecialChar ~
22812 \SpecialChar ~
22813 \SpecialChar ~
22814 \SpecialChar ~
22815 \SpecialChar ~
22816 \SpecialChar ~
22817 \SpecialChar ~
22818 SDCDB ptypecommand for data at 
22819 \newline 
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 \SpecialChar ~
22854 \SpecialChar ~
22855 \SpecialChar ~
22856 \SpecialChar ~
22857 \SpecialChar ~
22858 \SpecialChar ~
22859 \SpecialChar ~
22860 \SpecialChar ~
22861 \SpecialChar ~
22862 \SpecialChar ~
22863 \SpecialChar ~
22864 \SpecialChar ~
22865 \SpecialChar ~
22866 \SpecialChar ~
22867 buffer point 
22868 \newline 
22869 ;;\SpecialChar ~
22870 x\SpecialChar ~
22871 \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 sdcdbsrc-delete\SpecialChar ~
22886 \SpecialChar ~
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 SDCDB Delete all breakpoints if no arg 
22900 \newline 
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 \SpecialChar ~
22935 \SpecialChar ~
22936 \SpecialChar ~
22937 \SpecialChar ~
22938 \SpecialChar ~
22939 \SpecialChar ~
22940 \SpecialChar ~
22941 \SpecialChar ~
22942 \SpecialChar ~
22943 \SpecialChar ~
22944 \SpecialChar ~
22945 \SpecialChar ~
22946 \SpecialChar ~
22947 \SpecialChar ~
22948 given or delete arg (C-u arg x) 
22949 \newline 
22950 ;;\SpecialChar ~
22951 m\SpecialChar ~
22952 \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 sdcdbsrc-frame\SpecialChar ~
22967 \SpecialChar ~
22968 \SpecialChar ~
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 SDCDB Display current frame if no arg, 
22982 \newline 
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 \SpecialChar ~
23017 \SpecialChar ~
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 given or display frame arg 
23031 \newline 
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 \SpecialChar ~
23066 \SpecialChar ~
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 buffer point 
23080 \newline 
23081 ;;\SpecialChar ~
23082 !\SpecialChar ~
23083 \SpecialChar ~
23084 \SpecialChar ~
23085 \SpecialChar ~
23086 \SpecialChar ~
23087 \SpecialChar ~
23088 \SpecialChar ~
23089 \SpecialChar ~
23090 \SpecialChar ~
23091 \SpecialChar ~
23092 \SpecialChar ~
23093 \SpecialChar ~
23094 \SpecialChar ~
23095 \SpecialChar ~
23096 \SpecialChar ~
23097 sdcdbsrc-goto-sdcdb\SpecialChar ~
23098 \SpecialChar ~
23099 \SpecialChar ~
23100 \SpecialChar ~
23101 \SpecialChar ~
23102 \SpecialChar ~
23103 \SpecialChar ~
23104 \SpecialChar ~
23105 \SpecialChar ~
23106 \SpecialChar ~
23107 Goto the SDCDB output buffer 
23108 \newline 
23109 ;;\SpecialChar ~
23110 p\SpecialChar ~
23111 \SpecialChar ~
23112 \SpecialChar ~
23113 \SpecialChar ~
23114 \SpecialChar ~
23115 \SpecialChar ~
23116 \SpecialChar ~
23117 \SpecialChar ~
23118 \SpecialChar ~
23119 \SpecialChar ~
23120 \SpecialChar ~
23121 \SpecialChar ~
23122 \SpecialChar ~
23123 \SpecialChar ~
23124 \SpecialChar ~
23125 sdcdb-print-c-sexp\SpecialChar ~
23126 \SpecialChar ~
23127 \SpecialChar ~
23128 \SpecialChar ~
23129 \SpecialChar ~
23130 \SpecialChar ~
23131 \SpecialChar ~
23132 \SpecialChar ~
23133 \SpecialChar ~
23134 \SpecialChar ~
23135 \SpecialChar ~
23136 SDCDB print command for data at 
23137 \newline 
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 \SpecialChar ~
23172 \SpecialChar ~
23173 \SpecialChar ~
23174 \SpecialChar ~
23175 \SpecialChar ~
23176 \SpecialChar ~
23177 \SpecialChar ~
23178 \SpecialChar ~
23179 \SpecialChar ~
23180 \SpecialChar ~
23181 \SpecialChar ~
23182 \SpecialChar ~
23183 \SpecialChar ~
23184 \SpecialChar ~
23185 buffer point 
23186 \newline 
23187 ;;\SpecialChar ~
23188 g\SpecialChar ~
23189 \SpecialChar ~
23190 \SpecialChar ~
23191 \SpecialChar ~
23192 \SpecialChar ~
23193 \SpecialChar ~
23194 \SpecialChar ~
23195 \SpecialChar ~
23196 \SpecialChar ~
23197 \SpecialChar ~
23198 \SpecialChar ~
23199 \SpecialChar ~
23200 \SpecialChar ~
23201 \SpecialChar ~
23202 \SpecialChar ~
23203 sdcdbsrc-goto-sdcdb\SpecialChar ~
23204 \SpecialChar ~
23205 \SpecialChar ~
23206 \SpecialChar ~
23207 \SpecialChar ~
23208 \SpecialChar ~
23209 \SpecialChar ~
23210 \SpecialChar ~
23211 \SpecialChar ~
23212 \SpecialChar ~
23213 Goto the SDCDB output buffer 
23214 \newline 
23215 ;;\SpecialChar ~
23216 t\SpecialChar ~
23217 \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 sdcdbsrc-mode\SpecialChar ~
23232 \SpecialChar ~
23233 \SpecialChar ~
23234 \SpecialChar ~
23235 \SpecialChar ~
23236 \SpecialChar ~
23237 \SpecialChar ~
23238 \SpecialChar ~
23239 \SpecialChar ~
23240 \SpecialChar ~
23241 \SpecialChar ~
23242 \SpecialChar ~
23243 \SpecialChar ~
23244 \SpecialChar ~
23245 \SpecialChar ~
23246 \SpecialChar ~
23247 Toggles Sdcdbsrc mode (turns it off) 
23248 \newline 
23249 ;; 
23250 \newline 
23251 ;;\SpecialChar ~
23252 C-c\SpecialChar ~
23253 C-f\SpecialChar ~
23254 \SpecialChar ~
23255 \SpecialChar ~
23256 \SpecialChar ~
23257 \SpecialChar ~
23258 \SpecialChar ~
23259 \SpecialChar ~
23260 \SpecialChar ~
23261 \SpecialChar ~
23262 sdcdb-finish-from-src\SpecialChar ~
23263 \SpecialChar ~
23264 \SpecialChar ~
23265 \SpecialChar ~
23266 \SpecialChar ~
23267 \SpecialChar ~
23268 \SpecialChar ~
23269 \SpecialChar ~
23270 SDCDB finish command 
23271 \newline 
23272 ;; 
23273 \newline 
23274 ;;\SpecialChar ~
23275 C-x\SpecialChar ~
23276 SPC\SpecialChar ~
23277 \SpecialChar ~
23278 \SpecialChar ~
23279 \SpecialChar ~
23280 \SpecialChar ~
23281 \SpecialChar ~
23282 \SpecialChar ~
23283 \SpecialChar ~
23284 \SpecialChar ~
23285 sdcdb-break\SpecialChar ~
23286 \SpecialChar ~
23287 \SpecialChar ~
23288 \SpecialChar ~
23289 \SpecialChar ~
23290 \SpecialChar ~
23291 \SpecialChar ~
23292 \SpecialChar ~
23293 \SpecialChar ~
23294 \SpecialChar ~
23295 \SpecialChar ~
23296 \SpecialChar ~
23297 \SpecialChar ~
23298 \SpecialChar ~
23299 \SpecialChar ~
23300 \SpecialChar ~
23301 \SpecialChar ~
23302 \SpecialChar ~
23303 Set break for line with point 
23304 \newline 
23305 ;;\SpecialChar ~
23306 ESC\SpecialChar ~
23307 t\SpecialChar ~
23308 \SpecialChar ~
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 \SpecialChar ~
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 \SpecialChar ~
23315 \SpecialChar ~
23316 \SpecialChar ~
23317 \SpecialChar ~
23318 sdcdbsrc-mode\SpecialChar ~
23319 \SpecialChar ~
23320 \SpecialChar ~
23321 \SpecialChar ~
23322 \SpecialChar ~
23323 \SpecialChar ~
23324 \SpecialChar ~
23325 \SpecialChar ~
23326 \SpecialChar ~
23327 \SpecialChar ~
23328 \SpecialChar ~
23329 \SpecialChar ~
23330 \SpecialChar ~
23331 \SpecialChar ~
23332 \SpecialChar ~
23333 \SpecialChar ~
23334 Toggle Sdcdbsrc mode 
23335 \newline 
23336 ;;\SpecialChar ~
23337 ESC\SpecialChar ~
23338 m\SpecialChar ~
23339 \SpecialChar ~
23340 \SpecialChar ~
23341 \SpecialChar ~
23342 \SpecialChar ~
23343 \SpecialChar ~
23344 \SpecialChar ~
23345 \SpecialChar ~
23346 \SpecialChar ~
23347 \SpecialChar ~
23348 \SpecialChar ~
23349 sdcdbsrc-srcmode\SpecialChar ~
23350 \SpecialChar ~
23351 \SpecialChar ~
23352 \SpecialChar ~
23353 \SpecialChar ~
23354 \SpecialChar ~
23355 \SpecialChar ~
23356 \SpecialChar ~
23357 \SpecialChar ~
23358 \SpecialChar ~
23359 \SpecialChar ~
23360 \SpecialChar ~
23361 \SpecialChar ~
23362 Toggle list mode 
23363 \newline 
23364 ;; 
23365 \newline 
23366
23367 \layout Chapter
23368 \pagebreak_top 
23369 TIPS
23370 \layout Standard
23371
23372 Here are a few guidelines that will help the compiler generate more efficient
23373  code, some of the tips are specific to this compiler others are generally
23374  good programming practice.
23375 \layout Itemize
23376
23377 Use the smallest data type to represent your data-value.
23378  If it is known in advance that the value is going to be less than 256 then
23379  use an 'unsigned char' instead of a 'short' or 'int'.
23380  Please note, that ANSI C requires both signed and unsigned chars to be
23381  promoted to 'signed int'
23382 \begin_inset LatexCommand \index{promotion to signed int}
23383
23384 \end_inset 
23385
23386
23387 \begin_inset Marginal
23388 collapsed true
23389
23390 \layout Standard
23391
23392
23393 \series bold 
23394 \SpecialChar ~
23395 !
23396 \end_inset 
23397
23398  before doing any operation.
23399  This promotion
23400 \begin_inset LatexCommand \index{type promotion}
23401
23402 \end_inset 
23403
23404
23405 \begin_inset LatexCommand \label{type promotion}
23406
23407 \end_inset 
23408
23409  can be omitted, if the result is the same.
23410  The effect of the promotion rules together with the sign-extension is often
23411  surprising:
23412 \begin_deeper 
23413 \layout Verse
23414
23415
23416 \family typewriter 
23417 unsigned char uc = 0xfe;
23418 \newline 
23419 if (uc * uc < 0) /* this is true! */
23420 \newline 
23421 {
23422 \newline 
23423 \SpecialChar ~
23424 \SpecialChar ~
23425 \SpecialChar ~
23426 \SpecialChar ~
23427 ....
23428 \newline 
23429 }
23430 \layout Standard
23431
23432
23433 \family typewriter 
23434 uc * uc
23435 \family default 
23436  is evaluated as 
23437 \family typewriter 
23438 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23439 \family default 
23440 .
23441  
23442 \newline 
23443 Another one:
23444 \layout Verse
23445
23446
23447 \family typewriter 
23448 (unsigned char) -12 / (signed char) -3 = ...
23449 \layout Standard
23450
23451 No, the result is not 4:
23452 \layout Verse
23453
23454
23455 \family typewriter 
23456 (int) (unsigned char) -12 / (int) (signed char) -3 =
23457 \newline 
23458 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23459 \newline 
23460 (int) 0x00f4 / (int) 0xfffd =
23461 \newline 
23462 (int) 0x00f4 / (int) 0xfffd =
23463 \newline 
23464 (int) 244 / (int) -3 =
23465 \newline 
23466 (int) -81 = (int) 0xffaf;
23467 \layout Standard
23468
23469 Don't complain, that gcc gives you a different result.
23470  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23471  Therefore the results are different.
23472 \newline 
23473 From 
23474 \begin_inset Quotes sld
23475 \end_inset 
23476
23477 comp.lang.c FAQ
23478 \begin_inset Quotes srd
23479 \end_inset 
23480
23481 :
23482 \layout Quote
23483
23484
23485 \emph on 
23486 If well-defined overflow characteristics are important and negative values
23487  are not, or if you want to steer clear of sign-extension problems when
23488  manipulating bits or bytes, use one of the corresponding unsigned types.
23489  (Beware when mixing signed and unsigned values in expressions, though.)
23490 \newline 
23491 Although character types (especially unsigned char) can be used as "tiny"
23492  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23493 ble sign extension and increased code size.
23494 \end_deeper 
23495 \layout Itemize
23496
23497 Use unsigned when it is known in advance that the value is not going to
23498  be negative.
23499  This helps especially if you are doing division or multiplication, bit-shifting
23500  or are using an array index.
23501 \layout Itemize
23502
23503 NEVER jump into a LOOP.
23504 \layout Itemize
23505
23506 Declare the variables to be local
23507 \begin_inset LatexCommand \index{local variables}
23508
23509 \end_inset 
23510
23511  whenever possible, especially loop control variables (induction).
23512 \layout Itemize
23513
23514 Since the compiler does not always do implicit integral promotion, the programme
23515 r should do an explicit cast when integral promotion is required.
23516 \layout Itemize
23517
23518 Reducing the size of division, multiplication & modulus operations can reduce
23519  code size substantially.
23520  Take the following code for example.
23521 \begin_deeper 
23522 \layout Verse
23523
23524
23525 \family typewriter 
23526 foobar(unsigned int p1, unsigned char ch)
23527 \newline 
23528 {
23529 \newline 
23530 \SpecialChar ~
23531 \SpecialChar ~
23532 \SpecialChar ~
23533 \SpecialChar ~
23534 unsigned char ch1 = p1 % ch ;
23535 \newline 
23536 \SpecialChar ~
23537 \SpecialChar ~
23538 \SpecialChar ~
23539 \SpecialChar ~
23540 ....
23541 \newline 
23542 }
23543 \layout Standard
23544
23545 For the modulus operation the variable ch will be promoted to unsigned int
23546  first then the modulus operation will be performed (this will lead to a
23547  call to support routine _moduint()), and the result will be casted to a
23548  char.
23549  If the code is changed to 
23550 \layout Verse
23551
23552
23553 \family typewriter 
23554 foobar(unsigned int p1, unsigned char ch)
23555 \newline 
23556 {
23557 \newline 
23558 \SpecialChar ~
23559 \SpecialChar ~
23560 \SpecialChar ~
23561 \SpecialChar ~
23562 unsigned char ch1 = (unsigned char)p1 % ch ;
23563 \newline 
23564 \SpecialChar ~
23565 \SpecialChar ~
23566 \SpecialChar ~
23567 \SpecialChar ~
23568 ....
23569 \newline 
23570 }
23571 \layout Standard
23572
23573 It would substantially reduce the code generated (future versions of the
23574  compiler will be smart enough to detect such optimization opportunities).
23575 \end_deeper 
23576 \layout Itemize
23577
23578 Have a look at the assembly listing to get a 
23579 \begin_inset Quotes sld
23580 \end_inset 
23581
23582 feeling
23583 \begin_inset Quotes srd
23584 \end_inset 
23585
23586  for the code generation.
23587 \layout Section
23588
23589 Porting code from or to other compilers
23590 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23591
23592 \end_inset 
23593
23594
23595 \layout Itemize
23596
23597 check whether endianness of the compilers differs and adapt where needed.
23598 \layout Itemize
23599
23600 check the device specific header files
23601 \begin_inset LatexCommand \index{Header files}
23602
23603 \end_inset 
23604
23605
23606 \begin_inset LatexCommand \index{Include files}
23607
23608 \end_inset 
23609
23610  for compiler specific syntax.
23611  Eventually include the file <compiler.h
23612 \begin_inset LatexCommand \index{compiler.h (include file)}
23613
23614 \end_inset 
23615
23616
23617 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
23618
23619 \end_inset 
23620
23621  to allow using common header files.
23622  (see f.e.
23623  cc2510fx.h 
23624 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
23625
23626 \end_inset 
23627
23628 ).
23629 \layout Itemize
23630
23631 check whether the startup code contains the correct initialization (watchdog,
23632  peripherals).
23633 \layout Itemize
23634
23635 check whether the sizes of short, int, long match.
23636 \layout Itemize
23637
23638 check if some 16 or 32 bit hardware registers require a specific addressing
23639  order (least significant or most significant byte first) and adapt if needed
23640  (
23641 \emph on 
23642 first
23643 \emph default 
23644  and 
23645 \emph on 
23646 last
23647 \emph default 
23648  relate to time and not to lower/upper memory location here, so this is
23649  
23650 \emph on 
23651 not
23652 \emph default 
23653  the same as endianness).
23654 \layout Itemize
23655
23656 check whether the keyword 
23657 \emph on 
23658 volatile
23659 \emph default 
23660  is used where needed.
23661  The compilers might differ in their optimization characteristics (as different
23662  versions of the same compiler might also use more clever optimizations
23663  this is good idea anyway).
23664  See section 
23665 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
23666
23667 \end_inset 
23668
23669 .
23670 \layout Itemize
23671
23672 check that the compilers are not told to supress warnings.
23673 \layout Itemize
23674
23675 check and convert compiler specific extensions (interrupts, memory areas,
23676  pragmas etc.).
23677 \layout Itemize
23678
23679 check for differences in type promotion.
23680  Especially check for math operations on 
23681 \family typewriter 
23682 char
23683 \family default 
23684  or 
23685 \family typewriter 
23686 unsigned char
23687 \family default 
23688  variables.
23689  For the sake of C99 compatibility SDCC will probably promote these to 
23690 \family typewriter 
23691 int
23692 \family default 
23693  more often than other compilers.
23694  Eventually insert explicit casts to 
23695 \family typewriter 
23696 (char) 
23697 \family default 
23698 or
23699 \family typewriter 
23700  (unsigned char)
23701 \family default 
23702 .
23703  Also check that the ~\SpecialChar ~
23704 operator
23705 \begin_inset LatexCommand \index{\~\/ Operator}
23706
23707 \end_inset 
23708
23709  is not used on 
23710 \family typewriter 
23711 bit
23712 \begin_inset LatexCommand \index{bit}
23713
23714 \end_inset 
23715
23716
23717 \family default 
23718  variables, use the !\SpecialChar ~
23719 operator instead.
23720  See sections 
23721 \begin_inset LatexCommand \ref{type promotion}
23722
23723 \end_inset 
23724
23725  and 
23726 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23727
23728 \end_inset 
23729
23730 .
23731 \layout Itemize
23732
23733 check the assembly code generated for interrupt routines (f.e.
23734  for calls to possibly non-reentrant library functions).
23735 \layout Itemize
23736
23737 check whether timing loops result in proper timing (or preferably consider
23738  a rewrite of the code with timer based delays instead).
23739 \layout Itemize
23740
23741 check for differences in printf parameters (some compilers push (va_arg
23742 \begin_inset LatexCommand \index{vararg, va\_arg}
23743
23744 \end_inset 
23745
23746 ) char variables as 
23747 \family typewriter 
23748 int
23749 \family default 
23750  others push them as 
23751 \family typewriter 
23752 char
23753 \family default 
23754 .
23755  See section 
23756 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23757
23758 \end_inset 
23759
23760 ).
23761 \layout Itemize
23762
23763 check the resulting memory map
23764 \begin_inset LatexCommand \index{Memory map}
23765
23766 \end_inset 
23767
23768 .
23769  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23770 ly idata, pdata, xdata).
23771  Eventually check if unexpected library functions are included.
23772 \layout Section
23773
23774 Tools
23775 \begin_inset LatexCommand \index{Tools}
23776
23777 \end_inset 
23778
23779  included in the distribution
23780 \layout Standard
23781 \align left 
23782
23783 \begin_inset  Tabular
23784 <lyxtabular version="3" rows="12" columns="3">
23785 <features>
23786 <column alignment="left" valignment="top" leftline="true" width="0pt">
23787 <column alignment="left" valignment="top" leftline="true" width="0pt">
23788 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23789 <row topline="true" bottomline="true">
23790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23791 \begin_inset Text
23792
23793 \layout Standard
23794
23795 Name
23796 \end_inset 
23797 </cell>
23798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23799 \begin_inset Text
23800
23801 \layout Standard
23802
23803 Purpose
23804 \end_inset 
23805 </cell>
23806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23807 \begin_inset Text
23808
23809 \layout Standard
23810
23811 Directory
23812 \end_inset 
23813 </cell>
23814 </row>
23815 <row topline="true">
23816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23817 \begin_inset Text
23818
23819 \layout Standard
23820
23821 ucSsim
23822 \end_inset 
23823 </cell>
23824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23825 \begin_inset Text
23826
23827 \layout Standard
23828
23829 Simulator for various architectures
23830 \end_inset 
23831 </cell>
23832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23833 \begin_inset Text
23834
23835 \layout Standard
23836
23837 sdcc/sim/ucsim
23838 \end_inset 
23839 </cell>
23840 </row>
23841 <row topline="true">
23842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23843 \begin_inset Text
23844
23845 \layout Standard
23846
23847 keil2sdcc.pl
23848 \end_inset 
23849 </cell>
23850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23851 \begin_inset Text
23852
23853 \layout Standard
23854
23855 header file
23856 \begin_inset LatexCommand \index{Header files}
23857
23858 \end_inset 
23859
23860
23861 \begin_inset LatexCommand \index{Include files}
23862
23863 \end_inset 
23864
23865  conversion
23866 \end_inset 
23867 </cell>
23868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23869 \begin_inset Text
23870
23871 \layout Standard
23872
23873 sdcc/support/scripts
23874 \end_inset 
23875 </cell>
23876 </row>
23877 <row topline="true">
23878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23879 \begin_inset Text
23880
23881 \layout Standard
23882
23883 mh2h.c
23884 \end_inset 
23885 </cell>
23886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23887 \begin_inset Text
23888
23889 \layout Standard
23890
23891 header file conversion
23892 \end_inset 
23893 </cell>
23894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23895 \begin_inset Text
23896
23897 \layout Standard
23898
23899 sdcc/support/scripts
23900 \end_inset 
23901 </cell>
23902 </row>
23903 <row topline="true">
23904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23905 \begin_inset Text
23906
23907 \layout Standard
23908
23909 as-gbz80
23910 \end_inset 
23911 </cell>
23912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23913 \begin_inset Text
23914
23915 \layout Standard
23916
23917 Assembler
23918 \end_inset 
23919 </cell>
23920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23921 \begin_inset Text
23922
23923 \layout Standard
23924
23925
23926 \family roman 
23927 \series medium 
23928 \shape up 
23929 \size normal 
23930 \emph off 
23931 \bar no 
23932 \noun off 
23933 \color none
23934 sdcc/bin
23935 \end_inset 
23936 </cell>
23937 </row>
23938 <row topline="true">
23939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23940 \begin_inset Text
23941
23942 \layout Standard
23943
23944 as-z80
23945 \end_inset 
23946 </cell>
23947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23948 \begin_inset Text
23949
23950 \layout Standard
23951
23952 Assembler
23953 \end_inset 
23954 </cell>
23955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23956 \begin_inset Text
23957
23958 \layout Standard
23959
23960
23961 \family roman 
23962 \series medium 
23963 \shape up 
23964 \size normal 
23965 \emph off 
23966 \bar no 
23967 \noun off 
23968 \color none
23969 sdcc/bin
23970 \end_inset 
23971 </cell>
23972 </row>
23973 <row topline="true">
23974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23975 \begin_inset Text
23976
23977 \layout Standard
23978
23979 asx8051
23980 \end_inset 
23981 </cell>
23982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23983 \begin_inset Text
23984
23985 \layout Standard
23986
23987 Assembler
23988 \end_inset 
23989 </cell>
23990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23991 \begin_inset Text
23992
23993 \layout Standard
23994
23995
23996 \family roman 
23997 \series medium 
23998 \shape up 
23999 \size normal 
24000 \emph off 
24001 \bar no 
24002 \noun off 
24003 \color none
24004 sdcc/bin
24005 \end_inset 
24006 </cell>
24007 </row>
24008 <row topline="true">
24009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24010 \begin_inset Text
24011
24012 \layout Standard
24013
24014 SDCDB
24015 \end_inset 
24016 </cell>
24017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24018 \begin_inset Text
24019
24020 \layout Standard
24021
24022 Simulator
24023 \end_inset 
24024 </cell>
24025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24026 \begin_inset Text
24027
24028 \layout Standard
24029
24030
24031 \family roman 
24032 \series medium 
24033 \shape up 
24034 \size normal 
24035 \emph off 
24036 \bar no 
24037 \noun off 
24038 \color none
24039 sdcc/bin
24040 \end_inset 
24041 </cell>
24042 </row>
24043 <row topline="true">
24044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24045 \begin_inset Text
24046
24047 \layout Standard
24048
24049 aslink
24050 \end_inset 
24051 </cell>
24052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24053 \begin_inset Text
24054
24055 \layout Standard
24056
24057 Linker
24058 \end_inset 
24059 </cell>
24060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24061 \begin_inset Text
24062
24063 \layout Standard
24064
24065
24066 \family roman 
24067 \series medium 
24068 \shape up 
24069 \size normal 
24070 \emph off 
24071 \bar no 
24072 \noun off 
24073 \color none
24074 sdcc/bin
24075 \end_inset 
24076 </cell>
24077 </row>
24078 <row topline="true">
24079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24080 \begin_inset Text
24081
24082 \layout Standard
24083
24084 link-z80
24085 \end_inset 
24086 </cell>
24087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24088 \begin_inset Text
24089
24090 \layout Standard
24091
24092 Linker
24093 \end_inset 
24094 </cell>
24095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24096 \begin_inset Text
24097
24098 \layout Standard
24099
24100
24101 \family roman 
24102 \series medium 
24103 \shape up 
24104 \size normal 
24105 \emph off 
24106 \bar no 
24107 \noun off 
24108 \color none
24109 sdcc/bin
24110 \end_inset 
24111 </cell>
24112 </row>
24113 <row topline="true">
24114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24115 \begin_inset Text
24116
24117 \layout Standard
24118
24119 link-gbz80
24120 \end_inset 
24121 </cell>
24122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24123 \begin_inset Text
24124
24125 \layout Standard
24126
24127 Linker
24128 \end_inset 
24129 </cell>
24130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24131 \begin_inset Text
24132
24133 \layout Standard
24134
24135
24136 \family roman 
24137 \series medium 
24138 \shape up 
24139 \size normal 
24140 \emph off 
24141 \bar no 
24142 \noun off 
24143 \color none
24144 sdcc/bin
24145 \end_inset 
24146 </cell>
24147 </row>
24148 <row topline="true" bottomline="true">
24149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24150 \begin_inset Text
24151
24152 \layout Standard
24153
24154 packihx
24155 \end_inset 
24156 </cell>
24157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24158 \begin_inset Text
24159
24160 \layout Standard
24161
24162 Intel Hex packer 
24163 \begin_inset LatexCommand \index{packihx (tool)}
24164
24165 \end_inset 
24166
24167
24168 \end_inset 
24169 </cell>
24170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24171 \begin_inset Text
24172
24173 \layout Standard
24174
24175
24176 \family roman 
24177 \series medium 
24178 \shape up 
24179 \size normal 
24180 \emph off 
24181 \bar no 
24182 \noun off 
24183 \color none
24184 sdcc/bin
24185 \end_inset 
24186 </cell>
24187 </row>
24188 </lyxtabular>
24189
24190 \end_inset 
24191
24192
24193 \newline 
24194
24195 \layout Section
24196
24197 Documentation
24198 \begin_inset LatexCommand \index{Documentation}
24199
24200 \end_inset 
24201
24202  included in the distribution
24203 \layout Standard
24204 \align left 
24205
24206 \begin_inset  Tabular
24207 <lyxtabular version="3" rows="10" columns="2">
24208 <features>
24209 <column alignment="left" valignment="top" leftline="true" width="0">
24210 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24211 <row topline="true" bottomline="true">
24212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24213 \begin_inset Text
24214
24215 \layout Standard
24216
24217 Subject / Title
24218 \end_inset 
24219 </cell>
24220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24221 \begin_inset Text
24222
24223 \layout Standard
24224
24225 Where to get / filename
24226 \end_inset 
24227 </cell>
24228 </row>
24229 <row topline="true">
24230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24231 \begin_inset Text
24232
24233 \layout Standard
24234
24235 SDCC Compiler User Guide
24236 \end_inset 
24237 </cell>
24238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24239 \begin_inset Text
24240
24241 \layout Standard
24242
24243 You're reading it right now
24244 \end_inset 
24245 </cell>
24246 </row>
24247 <row topline="true">
24248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24249 \begin_inset Text
24250
24251 \layout Standard
24252
24253 Changelog of SDCC
24254 \end_inset 
24255 </cell>
24256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24257 \begin_inset Text
24258
24259 \layout Standard
24260
24261 sdcc/Changelog
24262 \end_inset 
24263 </cell>
24264 </row>
24265 <row topline="true">
24266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24267 \begin_inset Text
24268
24269 \layout Standard
24270
24271 ASXXXX
24272 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
24273
24274 \end_inset 
24275
24276
24277 \begin_inset LatexCommand \index{Assembler documentation}
24278
24279 \end_inset 
24280
24281  Assemblers and ASLINK
24282 \begin_inset LatexCommand \index{aslink}
24283
24284 \end_inset 
24285
24286
24287 \begin_inset LatexCommand \index{Linker documentation}
24288
24289 \end_inset 
24290
24291  Relocating Linker
24292 \end_inset 
24293 </cell>
24294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24295 \begin_inset Text
24296
24297 \layout Standard
24298
24299 sdcc/as/doc/asxhtm.html
24300 \end_inset 
24301 </cell>
24302 </row>
24303 <row topline="true">
24304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24305 \begin_inset Text
24306
24307 \layout Standard
24308
24309 SDCC regression test
24310 \begin_inset LatexCommand \index{Regression test}
24311
24312 \end_inset 
24313
24314
24315 \end_inset 
24316 </cell>
24317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24318 \begin_inset Text
24319
24320 \layout Standard
24321
24322 sdcc/doc/test_suite_spec.pdf
24323 \end_inset 
24324 </cell>
24325 </row>
24326 <row topline="true">
24327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24328 \begin_inset Text
24329
24330 \layout Standard
24331
24332 Various notes
24333 \end_inset 
24334 </cell>
24335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24336 \begin_inset Text
24337
24338 \layout Standard
24339
24340 sdcc/doc/*
24341 \end_inset 
24342 </cell>
24343 </row>
24344 <row topline="true">
24345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24346 \begin_inset Text
24347
24348 \layout Standard
24349
24350 Notes on debugging with SDCDB
24351 \begin_inset LatexCommand \index{SDCDB (debugger)}
24352
24353 \end_inset 
24354
24355
24356 \end_inset 
24357 </cell>
24358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24359 \begin_inset Text
24360
24361 \layout Standard
24362
24363 sdcc/debugger/README
24364 \end_inset 
24365 </cell>
24366 </row>
24367 <row topline="true">
24368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24369 \begin_inset Text
24370
24371 \layout Standard
24372
24373 Software simulator for microcontrollers
24374 \end_inset 
24375 </cell>
24376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24377 \begin_inset Text
24378
24379 \layout Standard
24380
24381
24382 \family roman 
24383 \series medium 
24384 \shape up 
24385 \size normal 
24386 \emph off 
24387 \bar no 
24388 \noun off 
24389 \color none
24390 sdcc/sim/ucsim/doc
24391 \family default 
24392 \series default 
24393 \shape default 
24394 \size default 
24395 \emph default 
24396 \bar default 
24397 \noun default 
24398 \color default
24399 /index.html
24400 \end_inset 
24401 </cell>
24402 </row>
24403 <row topline="true">
24404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24405 \begin_inset Text
24406
24407 \layout Standard
24408
24409 Temporary notes on the pic16
24410 \begin_inset LatexCommand \index{PIC16}
24411
24412 \end_inset 
24413
24414  port
24415 \end_inset 
24416 </cell>
24417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24418 \begin_inset Text
24419
24420 \layout Standard
24421
24422 sdcc/src/pic16/NOTES
24423 \end_inset 
24424 </cell>
24425 </row>
24426 <row topline="true" bottomline="true">
24427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24428 \begin_inset Text
24429
24430 \layout Standard
24431
24432 SDCC internal documentation (debugging file format)
24433 \end_inset 
24434 </cell>
24435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24436 \begin_inset Text
24437
24438 \layout Standard
24439
24440 sdcc/doc/
24441 \family roman 
24442 \series medium 
24443 \shape up 
24444 \size normal 
24445 \emph off 
24446 \bar no 
24447 \noun off 
24448 \color none
24449 cdbfileformat.pd
24450 \family default 
24451 \series default 
24452 \shape default 
24453 \size default 
24454 \emph default 
24455 \bar default 
24456 \noun default 
24457 \color default
24458 f
24459 \end_inset 
24460 </cell>
24461 </row>
24462 </lyxtabular>
24463
24464 \end_inset 
24465
24466
24467 \newline 
24468
24469 \layout Section
24470
24471 Related open source tools
24472 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24473
24474 \end_inset 
24475
24476
24477 \begin_inset LatexCommand \index{Related tools}
24478
24479 \end_inset 
24480
24481
24482 \layout Standard
24483 \align left 
24484
24485 \begin_inset  Tabular
24486 <lyxtabular version="3" rows="14" columns="3">
24487 <features>
24488 <column alignment="left" valignment="top" leftline="true" width="0pt">
24489 <column alignment="block" valignment="top" leftline="true" width="30line%">
24490 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24491 <row topline="true" bottomline="true">
24492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24493 \begin_inset Text
24494
24495 \layout Standard
24496
24497 Name
24498 \end_inset 
24499 </cell>
24500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24501 \begin_inset Text
24502
24503 \layout Standard
24504
24505 Purpose
24506 \end_inset 
24507 </cell>
24508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24509 \begin_inset Text
24510
24511 \layout Standard
24512
24513 Where to get
24514 \end_inset 
24515 </cell>
24516 </row>
24517 <row topline="true">
24518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24519 \begin_inset Text
24520
24521 \layout Standard
24522
24523 gpsim
24524 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24525
24526 \end_inset 
24527
24528
24529 \end_inset 
24530 </cell>
24531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24532 \begin_inset Text
24533
24534 \layout Standard
24535
24536 PIC simulator
24537 \end_inset 
24538 </cell>
24539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24540 \begin_inset Text
24541
24542 \layout Standard
24543
24544
24545 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24546
24547 \end_inset 
24548
24549
24550 \end_inset 
24551 </cell>
24552 </row>
24553 <row topline="true">
24554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24555 \begin_inset Text
24556
24557 \layout Standard
24558
24559 gputils
24560 \begin_inset LatexCommand \index{gputils (pic tools)}
24561
24562 \end_inset 
24563
24564
24565 \end_inset 
24566 </cell>
24567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24568 \begin_inset Text
24569
24570 \layout Standard
24571
24572 GNU PIC utilities
24573 \end_inset 
24574 </cell>
24575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24576 \begin_inset Text
24577
24578 \layout Standard
24579
24580
24581 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24582
24583 \end_inset 
24584
24585
24586 \end_inset 
24587 </cell>
24588 </row>
24589 <row topline="true">
24590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24591 \begin_inset Text
24592
24593 \layout Standard
24594
24595 flP5
24596 \end_inset 
24597 </cell>
24598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24599 \begin_inset Text
24600
24601 \layout Standard
24602
24603 PIC programmer
24604 \end_inset 
24605 </cell>
24606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24607 \begin_inset Text
24608
24609 \layout Standard
24610
24611
24612 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24613
24614 \end_inset 
24615
24616
24617 \end_inset 
24618 </cell>
24619 </row>
24620 <row topline="true">
24621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24622 \begin_inset Text
24623
24624 \layout Standard
24625
24626 ec2drv/newcdb
24627 \end_inset 
24628 </cell>
24629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24630 \begin_inset Text
24631
24632 \layout Standard
24633
24634 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24635  (Unix only)
24636 \end_inset 
24637 </cell>
24638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24639 \begin_inset Text
24640
24641 \layout Standard
24642
24643
24644 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24645
24646 \end_inset 
24647
24648
24649 \end_inset 
24650 </cell>
24651 </row>
24652 <row topline="true">
24653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24654 \begin_inset Text
24655
24656 \layout Standard
24657
24658 indent
24659 \begin_inset LatexCommand \index{indent (source formatting tool)}
24660
24661 \end_inset 
24662
24663
24664 \end_inset 
24665 </cell>
24666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24667 \begin_inset Text
24668
24669 \layout Standard
24670
24671 Formats C source - Master of the white spaces
24672 \end_inset 
24673 </cell>
24674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24675 \begin_inset Text
24676
24677 \layout Standard
24678
24679
24680 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
24681
24682 \end_inset 
24683
24684
24685 \end_inset 
24686 </cell>
24687 </row>
24688 <row topline="true">
24689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24690 \begin_inset Text
24691
24692 \layout Standard
24693
24694 srecord
24695 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
24696
24697 \end_inset 
24698
24699
24700 \end_inset 
24701 </cell>
24702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24703 \begin_inset Text
24704
24705 \layout Standard
24706
24707 Object file conversion, checksumming, ...
24708 \end_inset 
24709 </cell>
24710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24711 \begin_inset Text
24712
24713 \layout Standard
24714
24715
24716 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
24717
24718 \end_inset 
24719
24720
24721 \end_inset 
24722 </cell>
24723 </row>
24724 <row topline="true">
24725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24726 \begin_inset Text
24727
24728 \layout Standard
24729
24730 objdump
24731 \begin_inset LatexCommand \index{objdump (tool)}
24732
24733 \end_inset 
24734
24735
24736 \end_inset 
24737 </cell>
24738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24739 \begin_inset Text
24740
24741 \layout Standard
24742
24743 Object file conversion, ...
24744 \end_inset 
24745 </cell>
24746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24747 \begin_inset Text
24748
24749 \layout Standard
24750
24751 Part of binutils (should be there anyway)
24752 \end_inset 
24753 </cell>
24754 </row>
24755 <row topline="true">
24756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24757 \begin_inset Text
24758
24759 \layout Standard
24760
24761 cmon51
24762 \end_inset 
24763 </cell>
24764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24765 \begin_inset Text
24766
24767 \layout Standard
24768
24769 8051 monitor (hex up-/download, single step, disassemble)
24770 \end_inset 
24771 </cell>
24772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24773 \begin_inset Text
24774
24775 \layout Standard
24776
24777
24778 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
24779
24780 \end_inset 
24781
24782
24783 \end_inset 
24784 </cell>
24785 </row>
24786 <row topline="true">
24787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24788 \begin_inset Text
24789
24790 \layout Standard
24791
24792 doxygen
24793 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
24794
24795 \end_inset 
24796
24797
24798 \end_inset 
24799 </cell>
24800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24801 \begin_inset Text
24802
24803 \layout Standard
24804
24805 Source code documentation system
24806 \end_inset 
24807 </cell>
24808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24809 \begin_inset Text
24810
24811 \layout Standard
24812
24813
24814 \begin_inset LatexCommand \url{http://www.doxygen.org}
24815
24816 \end_inset 
24817
24818
24819 \end_inset 
24820 </cell>
24821 </row>
24822 <row topline="true">
24823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24824 \begin_inset Text
24825
24826 \layout Standard
24827
24828 kdevelop
24829 \end_inset 
24830 </cell>
24831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24832 \begin_inset Text
24833
24834 \layout Standard
24835
24836 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
24837 \end_inset 
24838 </cell>
24839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24840 \begin_inset Text
24841
24842 \layout Standard
24843
24844
24845 \begin_inset LatexCommand \url{http://www.kdevelop.org}
24846
24847 \end_inset 
24848
24849
24850 \end_inset 
24851 </cell>
24852 </row>
24853 <row topline="true">
24854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24855 \begin_inset Text
24856
24857 \layout Standard
24858
24859 paulmon
24860 \end_inset 
24861 </cell>
24862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24863 \begin_inset Text
24864
24865 \layout Standard
24866
24867 8051 monitor (hex up-/download, single step, disassemble)
24868 \end_inset 
24869 </cell>
24870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24871 \begin_inset Text
24872
24873 \layout Standard
24874
24875
24876 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
24877
24878 \end_inset 
24879
24880
24881 \end_inset 
24882 </cell>
24883 </row>
24884 <row topline="true">
24885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24886 \begin_inset Text
24887
24888 \layout Standard
24889
24890 splint
24891 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24892
24893 \end_inset 
24894
24895
24896 \end_inset 
24897 </cell>
24898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24899 \begin_inset Text
24900
24901 \layout Standard
24902
24903 Statically checks c sources (see 
24904 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24905
24906 \end_inset 
24907
24908 )
24909 \end_inset 
24910 </cell>
24911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24912 \begin_inset Text
24913
24914 \layout Standard
24915
24916
24917 \begin_inset LatexCommand \url{http://www.splint.org}
24918
24919 \end_inset 
24920
24921
24922 \end_inset 
24923 </cell>
24924 </row>
24925 <row topline="true" bottomline="true">
24926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24927 \begin_inset Text
24928
24929 \layout Standard
24930
24931 ddd
24932 \begin_inset LatexCommand \index{DDD (debugger)}
24933
24934 \end_inset 
24935
24936
24937 \end_inset 
24938 </cell>
24939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24940 \begin_inset Text
24941
24942 \layout Standard
24943
24944 Debugger, serves nicely as GUI to SDCDB
24945 \begin_inset LatexCommand \index{SDCDB (debugger)}
24946
24947 \end_inset 
24948
24949  (Unix only)
24950 \end_inset 
24951 </cell>
24952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24953 \begin_inset Text
24954
24955 \layout Standard
24956
24957
24958 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
24959
24960 \end_inset 
24961
24962
24963 \end_inset 
24964 </cell>
24965 </row>
24966 </lyxtabular>
24967
24968 \end_inset 
24969
24970
24971 \newline 
24972
24973 \layout Section
24974
24975 Related documentation / recommended reading
24976 \layout Standard
24977 \align left 
24978
24979 \begin_inset  Tabular
24980 <lyxtabular version="3" rows="7" columns="3">
24981 <features>
24982 <column alignment="left" valignment="top" leftline="true" width="0pt">
24983 <column alignment="center" valignment="top" leftline="true" width="0">
24984 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24985 <row topline="true" bottomline="true">
24986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24987 \begin_inset Text
24988
24989 \layout Standard
24990
24991 Name
24992 \end_inset 
24993 </cell>
24994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24995 \begin_inset Text
24996
24997 \layout Standard
24998
24999 Subject / Title
25000 \end_inset 
25001 </cell>
25002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25003 \begin_inset Text
25004
25005 \layout Standard
25006
25007 Where to get
25008 \end_inset 
25009 </cell>
25010 </row>
25011 <row topline="true">
25012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25013 \begin_inset Text
25014
25015 \layout Standard
25016
25017
25018 \family roman 
25019 \series medium 
25020 \shape up 
25021 \size normal 
25022 \emph off 
25023 \bar no 
25024 \noun off 
25025 \color none
25026 c-refcard.pdf
25027 \end_inset 
25028 </cell>
25029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25030 \begin_inset Text
25031
25032 \layout Standard
25033
25034 C Reference Card
25035 \begin_inset LatexCommand \index{C Reference card}
25036
25037 \end_inset 
25038
25039 , 2 pages
25040 \end_inset 
25041 </cell>
25042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25043 \begin_inset Text
25044
25045 \layout Standard
25046
25047
25048 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
25049
25050 \end_inset 
25051
25052
25053 \end_inset 
25054 </cell>
25055 </row>
25056 <row topline="true">
25057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25058 \begin_inset Text
25059
25060 \layout Standard
25061
25062 c-faq
25063 \end_inset 
25064 </cell>
25065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25066 \begin_inset Text
25067
25068 \layout Standard
25069
25070 C-FAQ
25071 \begin_inset LatexCommand \index{C FAQ}
25072
25073 \end_inset 
25074
25075
25076 \end_inset 
25077 </cell>
25078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25079 \begin_inset Text
25080
25081 \layout Standard
25082
25083
25084 \begin_inset LatexCommand \url{http://www.c-faq.com}
25085
25086 \end_inset 
25087
25088
25089 \end_inset 
25090 </cell>
25091 </row>
25092 <row topline="true">
25093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25094 \begin_inset Text
25095
25096 \layout Standard
25097
25098 ISO/IEC 9899:TC2
25099 \end_inset 
25100 </cell>
25101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25102 \begin_inset Text
25103
25104 \layout Standard
25105
25106
25107 \begin_inset Quotes sld
25108 \end_inset 
25109
25110 C-Standard
25111 \begin_inset Quotes srd
25112 \end_inset 
25113
25114
25115 \end_inset 
25116 </cell>
25117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25118 \begin_inset Text
25119
25120 \layout Standard
25121
25122
25123 \size footnotesize 
25124
25125 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
25126
25127 \end_inset 
25128
25129
25130 \end_inset 
25131 </cell>
25132 </row>
25133 <row topline="true">
25134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25135 \begin_inset Text
25136
25137 \layout Standard
25138
25139 ISO/IEC DTR 18037
25140 \end_inset 
25141 </cell>
25142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25143 \begin_inset Text
25144
25145 \layout Standard
25146
25147
25148 \begin_inset Quotes sld
25149 \end_inset 
25150
25151 Extensions for Embedded C
25152 \begin_inset Quotes srd
25153 \end_inset 
25154
25155
25156 \end_inset 
25157 </cell>
25158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25159 \begin_inset Text
25160
25161 \layout Standard
25162
25163
25164 \size footnotesize 
25165
25166 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
25167
25168 \end_inset 
25169
25170
25171 \end_inset 
25172 </cell>
25173 </row>
25174 <row topline="true">
25175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25176 \begin_inset Text
25177
25178 \layout Standard
25179
25180 \end_inset 
25181 </cell>
25182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25183 \begin_inset Text
25184
25185 \layout Standard
25186
25187 Latest datasheet of target CPU
25188 \end_inset 
25189 </cell>
25190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25191 \begin_inset Text
25192
25193 \layout Standard
25194
25195 vendor
25196 \end_inset 
25197 </cell>
25198 </row>
25199 <row topline="true" bottomline="true">
25200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25201 \begin_inset Text
25202
25203 \layout Standard
25204
25205 \end_inset 
25206 </cell>
25207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25208 \begin_inset Text
25209
25210 \layout Standard
25211
25212 Revision history of datasheet
25213 \end_inset 
25214 </cell>
25215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25216 \begin_inset Text
25217
25218 \layout Standard
25219
25220 vendor
25221 \end_inset 
25222 </cell>
25223 </row>
25224 </lyxtabular>
25225
25226 \end_inset 
25227
25228
25229 \newline 
25230
25231 \layout Section
25232
25233 Application notes specifically for SDCC
25234 \layout Standard
25235
25236 SDCC makes no claims about the completeness of this list and about up-to-datenes
25237 s or correctness of the application notes
25238 \begin_inset LatexCommand \index{Application notes}
25239
25240 \end_inset 
25241
25242 .
25243 \layout Standard
25244 \align left 
25245
25246 \size footnotesize 
25247
25248 \begin_inset  Tabular
25249 <lyxtabular version="3" rows="7" columns="3">
25250 <features>
25251 <column alignment="block" valignment="top" leftline="true" width="17col%">
25252 <column alignment="block" valignment="top" leftline="true" width="27col%">
25253 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
25254 <row topline="true" bottomline="true">
25255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25256 \begin_inset Text
25257
25258 \layout Standard
25259
25260
25261 \size footnotesize 
25262 Vendor
25263 \end_inset 
25264 </cell>
25265 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25266 \begin_inset Text
25267
25268 \layout Standard
25269
25270
25271 \size footnotesize 
25272 Subject / Title
25273 \end_inset 
25274 </cell>
25275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25276 \begin_inset Text
25277
25278 \layout Standard
25279
25280
25281 \size footnotesize 
25282 Where to get
25283 \end_inset 
25284 </cell>
25285 </row>
25286 <row topline="true">
25287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25288 \begin_inset Text
25289
25290 \layout Standard
25291
25292
25293 \size footnotesize 
25294 Maxim / Dallas
25295 \end_inset 
25296 </cell>
25297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25298 \begin_inset Text
25299
25300 \layout Standard
25301
25302
25303 \size footnotesize 
25304 Using the SDCC Compiler for the DS80C400
25305 \begin_inset LatexCommand \index{DS80C400}
25306
25307 \end_inset 
25308
25309
25310 \end_inset 
25311 </cell>
25312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25313 \begin_inset Text
25314
25315 \layout Standard
25316
25317
25318 \size footnotesize 
25319
25320 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25321
25322 \end_inset 
25323
25324
25325 \end_inset 
25326 </cell>
25327 </row>
25328 <row topline="true">
25329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25330 \begin_inset Text
25331
25332 \layout Standard
25333
25334
25335 \size footnotesize 
25336 Maxim / Dallas
25337 \end_inset 
25338 </cell>
25339 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25340 \begin_inset Text
25341
25342 \layout Standard
25343
25344
25345 \size footnotesize 
25346 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25347 \begin_inset LatexCommand \index{DS89C4x0}
25348
25349 \end_inset 
25350
25351  Family of Microcontrollers
25352 \end_inset 
25353 </cell>
25354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25355 \begin_inset Text
25356
25357 \layout Standard
25358
25359
25360 \size footnotesize 
25361
25362 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25363
25364 \end_inset 
25365
25366
25367 \end_inset 
25368 </cell>
25369 </row>
25370 <row topline="true">
25371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25372 \begin_inset Text
25373
25374 \layout Standard
25375
25376
25377 \size footnotesize 
25378 Silicon Laboratories / Cygnal
25379 \end_inset 
25380 </cell>
25381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25382 \begin_inset Text
25383
25384 \layout Standard
25385
25386
25387 \size footnotesize 
25388 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25389 \begin_inset LatexCommand \index{IDE}
25390
25391 \end_inset 
25392
25393
25394 \end_inset 
25395 </cell>
25396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25397 \begin_inset Text
25398
25399 \layout Standard
25400
25401
25402 \size footnotesize 
25403
25404 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
25405
25406 \end_inset 
25407
25408
25409 \end_inset 
25410 </cell>
25411 </row>
25412 <row topline="true">
25413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25414 \begin_inset Text
25415
25416 \layout Standard
25417
25418
25419 \size footnotesize 
25420 Ramtron / Goal Semiconductor
25421 \end_inset 
25422 </cell>
25423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25424 \begin_inset Text
25425
25426 \layout Standard
25427
25428
25429 \size footnotesize 
25430 Interfacing SDCC to Syn and Textpad
25431 \end_inset 
25432 </cell>
25433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25434 \begin_inset Text
25435
25436 \layout Standard
25437
25438
25439 \size footnotesize 
25440
25441 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25442
25443 \end_inset 
25444
25445
25446 \end_inset 
25447 </cell>
25448 </row>
25449 <row topline="true">
25450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25451 \begin_inset Text
25452
25453 \layout Standard
25454
25455
25456 \size footnotesize 
25457 Ramtron / Goal Semiconductor
25458 \end_inset 
25459 </cell>
25460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25461 \begin_inset Text
25462
25463 \layout Standard
25464
25465
25466 \size footnotesize 
25467 Installing and Configuring SDCC and Crimson Editor 
25468 \end_inset 
25469 </cell>
25470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25471 \begin_inset Text
25472
25473 \layout Standard
25474
25475
25476 \size footnotesize 
25477
25478 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25479
25480 \end_inset 
25481
25482
25483 \end_inset 
25484 </cell>
25485 </row>
25486 <row topline="true" bottomline="true">
25487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25488 \begin_inset Text
25489
25490 \layout Standard
25491
25492
25493 \size footnotesize 
25494 Texas Instruments
25495 \end_inset 
25496 </cell>
25497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25498 \begin_inset Text
25499
25500 \layout Standard
25501
25502
25503 \size footnotesize 
25504 MSC12xx Programming with SDCC
25505 \end_inset 
25506 </cell>
25507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25508 \begin_inset Text
25509
25510 \layout Standard
25511
25512
25513 \size footnotesize 
25514
25515 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25516
25517 \end_inset 
25518
25519
25520 \end_inset 
25521 </cell>
25522 </row>
25523 </lyxtabular>
25524
25525 \end_inset 
25526
25527
25528 \layout Section
25529
25530 Some Questions
25531 \layout Standard
25532
25533 Some questions answered, some pointers given - it might be time to in turn
25534  ask 
25535 \emph on 
25536 you
25537 \emph default 
25538  some questions: 
25539 \layout Itemize
25540
25541 can you solve your project with the selected microcontroller? Would you
25542  find out early or rather late that your target is too small/slow/whatever?
25543  Can you switch to a slightly better device if it doesn't fit?
25544 \layout Itemize
25545
25546 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25547  and/or another programming language be more adequate? Would an operating
25548  system on the target device help?
25549 \layout Itemize
25550
25551 if you solved the problem, will the marketing department be happy?
25552 \layout Itemize
25553
25554 if the marketing department is happy, will customers be happy?
25555 \layout Itemize
25556
25557 if you're the project manager, marketing department and maybe even the customer
25558  in one person, have you tried to see the project from the outside?
25559 \layout Itemize
25560
25561 is the project done if you think it is done? Or is just that other interface/pro
25562 tocol/feature/configuration/option missing? How about website, manual(s),
25563  internationali(z|s)ation, packaging, labels, 2nd source for components,
25564  electromagnetic compatability/interference, documentation for production,
25565  production test software, update mechanism, patent issues?
25566 \layout Itemize
25567
25568 is your project adequately positioned in that magic triangle: fame, fortune,
25569  fun?
25570 \layout Standard
25571
25572 Maybe not all answers to these questions are known and some answers may
25573  even be 
25574 \emph on 
25575 no
25576 \emph default 
25577 , nevertheless knowing these questions may help you to avoid burnout
25578 \begin_inset Foot
25579 collapsed false
25580
25581 \layout Standard
25582
25583 burnout is bad for electronic devices, programmers and motorcycle tyres
25584 \end_inset 
25585
25586 .
25587  Chances are you didn't want to hear some of them...
25588 \layout Chapter
25589
25590 Support
25591 \begin_inset LatexCommand \index{Support}
25592
25593 \end_inset 
25594
25595
25596 \layout Standard
25597
25598 SDCC has grown to be a large project.
25599  The compiler alone (without the preprocessor, assembler and linker) is
25600  well over 150,000 lines of code (blank stripped).
25601  The open source nature of this project is a key to its continued growth
25602  and support.
25603  You gain the benefit and support of many active software developers and
25604  end users.
25605  Is SDCC perfect? No, that's why we need your help.
25606  The developers take pride in fixing reported bugs.
25607  You can help by reporting the bugs and helping other SDCC users.
25608  There are lots of ways to contribute, and we encourage you to take part
25609  in making SDCC a great software package.
25610  
25611 \layout Standard
25612
25613 The SDCC project is hosted on the SDCC sourceforge site at 
25614 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25615
25616 \end_inset 
25617
25618 .
25619  You'll find the complete set of mailing lists
25620 \begin_inset LatexCommand \index{Mailing list(s)}
25621
25622 \end_inset 
25623
25624 , forums, bug reporting system, patch submission
25625 \begin_inset LatexCommand \index{Patch submission}
25626
25627 \end_inset 
25628
25629  system, download
25630 \begin_inset LatexCommand \index{download}
25631
25632 \end_inset 
25633
25634  area and Subversion code repository
25635 \begin_inset LatexCommand \index{Subversion code repository}
25636
25637 \end_inset 
25638
25639  there.
25640 \layout Section
25641
25642 Reporting Bugs
25643 \begin_inset LatexCommand \index{Bug reporting}
25644
25645 \end_inset 
25646
25647
25648 \begin_inset LatexCommand \index{Reporting bugs}
25649
25650 \end_inset 
25651
25652
25653 \layout Standard
25654
25655 The recommended way of reporting bugs is using the infrastructure of the
25656  sourceforge site.
25657  You can follow the status of bug reports there and have an overview about
25658  the known bugs.
25659 \layout Standard
25660
25661 Bug reports are automatically forwarded to the developer mailing list and
25662  will be fixed ASAP.
25663  When reporting a bug, it is very useful to include a small test program
25664  (the smaller the better) which reproduces the problem.
25665  If you can isolate the problem by looking at the generated assembly code,
25666  this can be very helpful.
25667  Compiling your program with the -
25668 \begin_inset ERT
25669 status Collapsed
25670
25671 \layout Standard
25672
25673 \backslash 
25674 /
25675 \end_inset 
25676
25677 -dumpall
25678 \begin_inset LatexCommand \index{-\/-dumpall}
25679
25680 \end_inset 
25681
25682  option can sometimes be useful in locating optimization problems.
25683  When reporting a bug please make sure you:
25684 \layout Enumerate
25685
25686 Attach the code you are compiling with SDCC.
25687  
25688 \layout Enumerate
25689
25690 Specify the exact command you use to run SDCC, or attach your Makefile.
25691  
25692 \layout Enumerate
25693
25694 Specify the SDCC version (type "
25695 \family sans 
25696 \series bold 
25697 sdcc -v
25698 \family default 
25699 \series default 
25700 "), your platform, and operating system.
25701  
25702 \layout Enumerate
25703
25704 Provide an exact copy of any error message or incorrect output.
25705  
25706 \layout Enumerate
25707
25708 Put something meaningful in the subject of your message.
25709 \layout Standard
25710
25711 Please attempt to include these 5 important parts, as applicable, in all
25712  requests for support or when reporting any problems or bugs with SDCC.
25713  Though this will make your message lengthy, it will greatly improve your
25714  chance that SDCC users and developers will be able to help you.
25715  Some SDCC developers are frustrated by bug reports without code provided
25716  that they can use to reproduce and ultimately fix the problem, so please
25717  be sure to provide sample code if you are reporting a bug! 
25718 \layout Standard
25719
25720 Please have a short check that you are using a recent version of SDCC and
25721  the bug is not yet known.
25722  This is the link for reporting bugs: 
25723 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
25724
25725 \end_inset 
25726
25727 .
25728  With SDCC on average having more than 200 downloads
25729 \begin_inset LatexCommand \index{download}
25730
25731 \end_inset 
25732
25733  on sourceforge per day
25734 \begin_inset Foot
25735 collapsed false
25736
25737 \layout Standard
25738
25739 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
25740  between 2002 and 2005.
25741  This does not include other methods of distribution.
25742 \end_inset 
25743
25744  there must be some users.
25745  So it's not exactly easy to find a new bug.
25746  If you find one we need it: 
25747 \emph on 
25748 reporting bugs is good
25749 \emph default 
25750 .
25751 \layout Section
25752
25753 Requesting Features
25754 \begin_inset LatexCommand \label{sub:Requesting-Features}
25755
25756 \end_inset 
25757
25758
25759 \begin_inset LatexCommand \index{Feature request}
25760
25761 \end_inset 
25762
25763
25764 \begin_inset LatexCommand \index{Requesting features}
25765
25766 \end_inset 
25767
25768
25769 \layout Standard
25770
25771 Like bug reports feature requests are forwarded to the developer mailing
25772  list.
25773  This is the link for requesting features: 
25774 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
25775
25776 \end_inset 
25777
25778 .
25779 \layout Section
25780
25781 Submitting patches
25782 \layout Standard
25783
25784 Like bug reports contributed patches are forwarded to the developer mailing
25785  list.
25786  This is the link for submitting patches
25787 \begin_inset LatexCommand \index{Patch submission}
25788
25789 \end_inset 
25790
25791
25792 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
25793
25794 \end_inset 
25795
25796 .
25797 \layout Standard
25798
25799 You need to specify some parameters to the 
25800 \family typewriter 
25801 diff
25802 \family default 
25803  command for the patches to be useful.
25804  If you modified more than one file a patch created f.e.
25805  with 
25806 \family sans 
25807 \series bold 
25808
25809 \begin_inset Quotes sld
25810 \end_inset 
25811
25812 diff -Naur unmodified_directory modified_directory >my_changes.patch
25813 \begin_inset Quotes srd
25814 \end_inset 
25815
25816
25817 \family default 
25818 \series default 
25819  will be fine, otherwise 
25820 \family sans 
25821 \series bold 
25822
25823 \begin_inset Quotes sld
25824 \end_inset 
25825
25826 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
25827 \begin_inset Quotes srd
25828 \end_inset 
25829
25830
25831 \series default 
25832  
25833 \family default 
25834 will do.
25835 \layout Section
25836
25837 Getting Help
25838 \layout Standard
25839
25840 These links should take you directly to the 
25841 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
25842
25843 \end_inset 
25844
25845
25846 \begin_inset Foot
25847 collapsed false
25848
25849 \layout Standard
25850
25851 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
25852  automated messages (mid 2003)
25853 \end_inset 
25854
25855  and the 
25856 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
25857
25858 \end_inset 
25859
25860 , lists
25861 \begin_inset LatexCommand \index{Mailing list(s)}
25862
25863 \end_inset 
25864
25865  and forums are archived and searchable so if you are lucky someone already
25866  had a similar problem.
25867  While mails to the lists themselves are delivered promptly their web front
25868  end on sourceforge sometimes shows a severe time lag (up to several weeks),
25869  if you're seriously using SDCC please consider subscribing to the lists.
25870 \layout Section
25871
25872 ChangeLog
25873 \layout Standard
25874
25875 You can follow the status of the Subversion version
25876 \begin_inset LatexCommand \index{version}
25877
25878 \end_inset 
25879
25880  of SDCC by watching the Changelog
25881 \begin_inset LatexCommand \index{Changelog}
25882
25883 \end_inset 
25884
25885  in the Subversion repository
25886 \size footnotesize 
25887  
25888 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
25889
25890 \end_inset 
25891
25892 .
25893 \layout Section
25894
25895 Subversion Source Code Repository
25896 \layout Standard
25897
25898 The output of 
25899 \family sans 
25900 \series bold 
25901 sdcc --version
25902 \family default 
25903 \series default 
25904  or the filenames of the snapshot versions of SDCC include date and its
25905  Subversion
25906 \begin_inset LatexCommand \index{Subversion code repository}
25907
25908 \end_inset 
25909
25910  number.
25911  Subversion allows to download the source of recent or previous versions
25912  
25913 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
25914
25915 \end_inset 
25916
25917  (by number or by date).
25918  An on-line source code browser and detailled instructions are also available
25919  there.
25920  SDCC versions starting from 1999 up to now are available (currently the
25921  versions prior to the conversion from cvs
25922 \begin_inset LatexCommand \index{cvs|see{Subversion}}
25923
25924 \end_inset 
25925
25926  to Subversion (April 2006) are either by accessible by Subversion or by
25927  cvs).
25928 \layout Section
25929
25930 Release policy
25931 \begin_inset LatexCommand \index{Release policy}
25932
25933 \end_inset 
25934
25935
25936 \layout Standard
25937
25938 Historically there often were long delays between official releases and
25939  the sourceforge download area tends to get not updated at all.
25940  Excuses in the past might have referred to problems with live range analysis,
25941  but as this was fixed a while ago, the current problem is that another
25942  excuse has to be found.
25943  Kidding aside, we have to get better there! On the other hand there are
25944  daily snapshots available at 
25945 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
25946
25947 \end_inset 
25948
25949 , and you can always build the very last version (hopefully with many bugs
25950  fixed, and features added) from the source code available at 
25951 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
25952
25953 \end_inset 
25954
25955 .
25956 \layout Section
25957
25958 Examples
25959 \begin_inset LatexCommand \index{Examples}
25960
25961 \end_inset 
25962
25963
25964 \layout Standard
25965
25966 You'll find some small examples in the directory 
25967 \emph on 
25968 sdcc/device/examples/.
25969  
25970 \emph default 
25971 More examples and libraries are available at
25972 \emph on 
25973  The SDCC Open Knowledge Resource 
25974 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
25975
25976 \end_inset 
25977
25978  
25979 \emph default 
25980 web site or at 
25981 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
25982
25983 \end_inset 
25984
25985 .
25986 \layout Comment
25987
25988 I did insert a reference to Paul's web site here although it seems rather
25989  dedicated to a specific 8032 board (I think it's okay because it f.e.
25990  shows LCD/Harddisc interface and has a free 8051 monitor.
25991  Independent 8032 board vendors face hard competition of heavily subsidized
25992  development boards anyway).
25993 \layout Comment
25994
25995 Maybe we should include some links to real world applications.
25996  Preferably pointer to pointers (one for each architecture) so this stays
25997  manageable here?
25998 \layout Section
25999
26000 Quality control
26001 \begin_inset LatexCommand \label{sec:Quality-control}
26002
26003 \end_inset 
26004
26005
26006 \begin_inset LatexCommand \index{Quality control}
26007
26008 \end_inset 
26009
26010
26011 \layout Standard
26012
26013 The compiler is passed through nightly compile and build checks.
26014  The so called 
26015 \shape italic 
26016 regression tests
26017 \shape default 
26018
26019 \begin_inset LatexCommand \index{Regression test}
26020
26021 \end_inset 
26022
26023  check that SDCC itself compiles flawlessly on several host platforms (i386,
26024  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
26025  the quality of the code generated by SDCC by running the code for several
26026  target platforms through simulators.
26027  The regression test suite comprises more than 100 files which expand to
26028  more than 500 test cases which include more than 4500 tests.
26029  The results of these tests are published daily on SDCC's snapshot page
26030  (click on the red or green symbols on the right side of 
26031 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
26032
26033 \end_inset 
26034
26035 ).
26036 \layout Standard
26037
26038 There is a separate document 
26039 \shape italic 
26040 test_suite.pdf 
26041 \begin_inset LatexCommand \index{Test suite}
26042
26043 \end_inset 
26044
26045
26046 \shape default 
26047  
26048 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26049
26050 \end_inset 
26051
26052  about the regression test suite.
26053 \layout Standard
26054
26055 You'll find the test code in the directory 
26056 \shape italic 
26057 sdcc/support/regression
26058 \shape default 
26059 .
26060  You can run these tests manually by running 
26061 \family sans 
26062 make
26063 \family default 
26064  in this directory (or f.e.
26065  
26066 \family sans 
26067 \series bold 
26068
26069 \begin_inset Quotes sld
26070 \end_inset 
26071
26072 make test-mcs51
26073 \begin_inset Quotes srd
26074 \end_inset 
26075
26076
26077 \family default 
26078 \series default 
26079  if you don't want to run the complete tests).
26080  The test code might also be interesting if you want to look for examples
26081 \begin_inset LatexCommand \index{Examples}
26082
26083 \end_inset 
26084
26085  checking corner cases of SDCC or if you plan to submit patches
26086 \begin_inset LatexCommand \index{Patch submission}
26087
26088 \end_inset 
26089
26090 .
26091 \layout Standard
26092
26093 The 14bit pic port uses a different set of regression tests 
26094 \begin_inset LatexCommand \index{Regression test (PIC14)}
26095
26096 \end_inset 
26097
26098 , you'll find them in the directory 
26099 \shape italic 
26100 sdcc/src/regression
26101 \shape default 
26102 .
26103 \layout Section
26104
26105 Use of SDCC in Education
26106 \layout Standard
26107
26108 In short: 
26109 \emph on 
26110 highly
26111 \emph default 
26112  encouraged
26113 \begin_inset Foot
26114 collapsed false
26115
26116 \layout Standard
26117
26118 the phrase "use in education" might evoke the association "
26119 \emph on 
26120 only
26121 \emph default 
26122  fit for use in education".
26123  This connotation is not intended but nevertheless risked as the licensing
26124  of SDCC makes it difficult to offer educational discounts
26125 \end_inset 
26126
26127 .
26128  If your rationales are to:
26129 \layout Enumerate
26130
26131 give students a chance to understand the 
26132 \emph on 
26133 complete
26134 \emph default 
26135  steps of code generation
26136 \layout Enumerate
26137
26138 have a curriculum that can be extended for years.
26139  Then you could use an fpga board as target and your curriculum will seamlessly
26140  extend from logic synthesis (
26141 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
26142
26143 \end_inset 
26144
26145
26146 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
26147
26148 \end_inset 
26149
26150 ), over assembly programming, to C to FPGA compilers (
26151 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
26152
26153 \end_inset 
26154
26155 ) and to C.
26156 \layout Enumerate
26157
26158 be able to insert excursions about skills like using a revision control
26159  system, submitting/applying patches, using a type-setting (as opposed to
26160  word-processing) engine LyX/LaTeX, using 
26161 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
26162
26163 \end_inset 
26164
26165 , following some 
26166 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
26167
26168 \end_inset 
26169
26170 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
26171  Source Software, CPU simulation, compiler regression tests
26172 \begin_inset LatexCommand \index{Regression test}
26173
26174 \end_inset 
26175
26176 .
26177  
26178 \newline 
26179 And if there should be a shortage of ideas then you can always point students
26180  to the ever-growing feature request list 
26181 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26182
26183 \end_inset 
26184
26185 .
26186 \layout Enumerate
26187
26188 not tie students to a specific host platform and instead allow them to use
26189  a host platform of 
26190 \emph on 
26191 their
26192 \emph default 
26193  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
26194  eventually 
26195 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
26196
26197 \end_inset 
26198
26199 )
26200 \layout Enumerate
26201
26202 not encourage students to use illegal copies of educational software
26203 \layout Enumerate
26204
26205 be immune to licensing/availability/price changes of the chosen tool chain
26206 \layout Enumerate
26207
26208 be able to change to a new target platform without having to adopt a new
26209  tool chain
26210 \layout Enumerate
26211
26212 have complete control over and insight into the tool chain
26213 \layout Enumerate
26214
26215 make your students aware about the pros and cons of open source software
26216  development
26217 \layout Enumerate
26218
26219 give back to the public as you are probably at least partially publically
26220  funded
26221 \layout Enumerate
26222
26223 give students a chance to publically prove their skills and to possibly
26224  see a world wide impact
26225 \layout Standard
26226
26227 then SDCC is probably among the first choices.
26228  Well, probably SDCC might be the only choice.
26229 \layout Chapter
26230 \pagebreak_top 
26231 SDCC Technical Data
26232 \layout Section
26233
26234 Optimizations
26235 \begin_inset LatexCommand \index{Optimizations}
26236
26237 \end_inset 
26238
26239
26240 \layout Standard
26241
26242 SDCC performs a host of standard optimizations in addition to some MCU specific
26243  optimizations.
26244  
26245 \layout Subsection
26246
26247 Sub-expression Elimination
26248 \begin_inset LatexCommand \index{Subexpression elimination}
26249
26250 \end_inset 
26251
26252
26253 \layout Standard
26254
26255 The compiler does local and 
26256 \emph on 
26257 g
26258 \emph default 
26259 lobal 
26260 \emph on 
26261 c
26262 \emph default 
26263 ommon 
26264 \emph on 
26265 s
26266 \emph default 
26267 ubexpression 
26268 \emph on 
26269 e
26270 \emph default 
26271 limination, e.g.: 
26272 \layout Verse
26273
26274
26275 \family typewriter 
26276 i = x + y + 1; 
26277 \newline 
26278 j = x + y;
26279 \layout Standard
26280
26281 will be translated to
26282 \layout Verse
26283
26284
26285 \family typewriter 
26286 iTemp = x + y; 
26287 \newline 
26288 i = iTemp + 1; 
26289 \newline 
26290 j = iTemp;
26291 \layout Standard
26292
26293 Some subexpressions are not as obvious as the above example, e.g.:
26294 \layout Verse
26295
26296
26297 \family typewriter 
26298 a->b[i].c = 10; 
26299 \newline 
26300 a->b[i].d = 11;
26301 \layout Standard
26302
26303 In this case the address arithmetic a->b[i] will be computed only once;
26304  the equivalent code in C would be.
26305 \layout Verse
26306
26307
26308 \family typewriter 
26309 iTemp = a->b[i]; 
26310 \newline 
26311 iTemp.c = 10; 
26312 \newline 
26313 iTemp.d = 11;
26314 \layout Standard
26315
26316 The compiler will try to keep these temporary variables in registers.
26317 \layout Subsection
26318
26319 Dead-Code Elimination
26320 \begin_inset LatexCommand \index{Dead-code elimination}
26321
26322 \end_inset 
26323
26324
26325 \layout Verse
26326
26327
26328 \family typewriter 
26329 int global;
26330 \newline 
26331
26332 \newline 
26333 void f () { 
26334 \newline 
26335 \SpecialChar ~
26336 \SpecialChar ~
26337 int i; 
26338 \newline 
26339 \SpecialChar ~
26340 \SpecialChar ~
26341 i = 1; \SpecialChar ~
26342 \SpecialChar ~
26343 \SpecialChar ~
26344 \SpecialChar ~
26345 \SpecialChar ~
26346 /* dead store */ 
26347 \newline 
26348 \SpecialChar ~
26349 \SpecialChar ~
26350 global = 1;\SpecialChar ~
26351 /* dead store */ 
26352 \newline 
26353 \SpecialChar ~
26354 \SpecialChar ~
26355 global = 2; 
26356 \newline 
26357 \SpecialChar ~
26358 \SpecialChar ~
26359 return; 
26360 \newline 
26361 \SpecialChar ~
26362 \SpecialChar ~
26363 global = 3;\SpecialChar ~
26364 /* unreachable */ 
26365 \newline 
26366 }
26367 \layout Standard
26368
26369 will be changed to
26370 \layout Verse
26371
26372
26373 \family typewriter 
26374 int global;
26375 \newline 
26376
26377 \newline 
26378 void f () {
26379 \newline 
26380 \SpecialChar ~
26381 \SpecialChar ~
26382 global = 2; 
26383 \newline 
26384 }
26385 \layout Subsection
26386
26387 Copy-Propagation
26388 \begin_inset LatexCommand \index{Copy propagation}
26389
26390 \end_inset 
26391
26392
26393 \layout Verse
26394
26395
26396 \family typewriter 
26397 int f() { 
26398 \newline 
26399 \SpecialChar ~
26400 \SpecialChar ~
26401 int i, j; 
26402 \newline 
26403 \SpecialChar ~
26404 \SpecialChar ~
26405 i = 10; 
26406 \newline 
26407 \SpecialChar ~
26408 \SpecialChar ~
26409 j = i; 
26410 \newline 
26411 \SpecialChar ~
26412 \SpecialChar ~
26413 return j; 
26414 \newline 
26415 }
26416 \layout Standard
26417
26418 will be changed to 
26419 \layout Verse
26420
26421
26422 \family typewriter 
26423 int f() { 
26424 \newline 
26425 \SpecialChar ~
26426 \SpecialChar ~
26427 int i, j; 
26428 \newline 
26429 \SpecialChar ~
26430 \SpecialChar ~
26431 i = 10; 
26432 \newline 
26433 \SpecialChar ~
26434 \SpecialChar ~
26435 j = 10; 
26436 \newline 
26437 \SpecialChar ~
26438 \SpecialChar ~
26439 return 10; 
26440 \newline 
26441 }
26442 \layout Standard
26443
26444 Note: the dead stores created by this copy propagation will be eliminated
26445  by dead-code elimination.
26446 \layout Subsection
26447
26448 Loop Optimizations
26449 \begin_inset LatexCommand \index{Loop optimization}
26450
26451 \end_inset 
26452
26453
26454 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26455
26456 \end_inset 
26457
26458
26459 \layout Standard
26460
26461 Two types of loop optimizations are done by SDCC 
26462 \emph on 
26463 loop invariant
26464 \emph default 
26465  lifting and
26466 \emph on 
26467  strength reduction
26468 \emph default 
26469  of loop induction variables.
26470  In addition to the strength reduction the optimizer marks the induction
26471  variables and the register allocator tries to keep the induction variables
26472  in registers for the duration of the loop.
26473  Because of this preference of the register allocator
26474 \begin_inset LatexCommand \index{Register allocation}
26475
26476 \end_inset 
26477
26478 , loop induction optimization causes an increase in register pressure, which
26479  may cause unwanted spilling of other temporary variables into the stack
26480 \begin_inset LatexCommand \index{stack}
26481
26482 \end_inset 
26483
26484  / data space.
26485  The compiler will generate a warning message when it is forced to allocate
26486  extra space either on the stack or data space.
26487  If this extra space allocation is undesirable then induction optimization
26488  can be eliminated either for the entire source file (with -
26489 \begin_inset ERT
26490 status Collapsed
26491
26492 \layout Standard
26493
26494 \backslash 
26495 /
26496 \end_inset 
26497
26498 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26499 noinduction
26500 \begin_inset LatexCommand \index{\#pragma noinduction}
26501
26502 \end_inset 
26503
26504 .
26505 \newline 
26506
26507 \newline 
26508 Loop Invariant:
26509 \layout Verse
26510
26511
26512 \family typewriter 
26513 for (i = 0 ; i < 100 ; i ++) 
26514 \newline 
26515 \SpecialChar ~
26516 \SpecialChar ~
26517 \SpecialChar ~
26518 \SpecialChar ~
26519 f += k + l;
26520 \layout Standard
26521
26522 changed to
26523 \layout Verse
26524
26525
26526 \family typewriter 
26527 itemp = k + l; 
26528 \newline 
26529 for (i = 0; i < 100; i++) 
26530 \newline 
26531 \SpecialChar ~
26532 \SpecialChar ~
26533 \SpecialChar ~
26534 \SpecialChar ~
26535 f += itemp;
26536 \layout Standard
26537
26538 As mentioned previously some loop invariants are not as apparent, all static
26539  address computations are also moved out of the loop.
26540 \newline 
26541
26542 \newline 
26543 Strength Reduction
26544 \begin_inset LatexCommand \index{Strength reduction}
26545
26546 \end_inset 
26547
26548 , this optimization substitutes an expression by a cheaper expression:
26549 \layout Verse
26550
26551
26552 \family typewriter 
26553 for (i=0;i < 100; i++)
26554 \newline 
26555 \SpecialChar ~
26556 \SpecialChar ~
26557 \SpecialChar ~
26558 \SpecialChar ~
26559 ar[i*5] = i*3;
26560 \layout Standard
26561
26562 changed to
26563 \layout Verse
26564
26565
26566 \family typewriter 
26567 itemp1 = 0; 
26568 \newline 
26569 itemp2 = 0; 
26570 \newline 
26571 for (i=0;i< 100;i++) { 
26572 \newline 
26573 \SpecialChar ~
26574 \SpecialChar ~
26575 \SpecialChar ~
26576 \SpecialChar ~
26577 ar[itemp1] = itemp2; 
26578 \newline 
26579 \SpecialChar ~
26580 \SpecialChar ~
26581 \SpecialChar ~
26582 \SpecialChar ~
26583 itemp1 += 5; 
26584 \newline 
26585 \SpecialChar ~
26586 \SpecialChar ~
26587 \SpecialChar ~
26588 \SpecialChar ~
26589 itemp2 += 3; 
26590 \newline 
26591 }
26592 \layout Standard
26593
26594 The more expensive multiplication
26595 \begin_inset LatexCommand \index{Multiplication}
26596
26597 \end_inset 
26598
26599  is changed to a less expensive addition.
26600 \layout Subsection
26601
26602 Loop Reversing
26603 \begin_inset LatexCommand \index{Loop reversing}
26604
26605 \end_inset 
26606
26607
26608 \layout Standard
26609
26610 This optimization is done to reduce the overhead of checking loop boundaries
26611  for every iteration.
26612  Some simple loops can be reversed and implemented using a 
26613 \begin_inset Quotes eld
26614 \end_inset 
26615
26616 decrement and jump if not zero
26617 \begin_inset Quotes erd
26618 \end_inset 
26619
26620  instruction.
26621  SDCC checks for the following criterion to determine if a loop is reversible
26622  (note: more sophisticated compilers use data-dependency analysis to make
26623  this determination, SDCC uses a more simple minded analysis).
26624 \layout Itemize
26625
26626 The 'for' loop is of the form 
26627 \newline 
26628
26629 \newline 
26630
26631 \family typewriter 
26632 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
26633  += 1])
26634 \newline 
26635 \SpecialChar ~
26636 \SpecialChar ~
26637 \SpecialChar ~
26638 \SpecialChar ~
26639 <for body>
26640 \layout Itemize
26641
26642 The <for body> does not contain 
26643 \begin_inset Quotes eld
26644 \end_inset 
26645
26646 continue
26647 \begin_inset Quotes erd
26648 \end_inset 
26649
26650  or 'break
26651 \begin_inset Quotes erd
26652 \end_inset 
26653
26654 .
26655 \layout Itemize
26656
26657 All goto's are contained within the loop.
26658 \layout Itemize
26659
26660 No function calls within the loop.
26661 \layout Itemize
26662
26663 The loop control variable <sym> is not assigned any value within the loop
26664 \layout Itemize
26665
26666 The loop control variable does NOT participate in any arithmetic operation
26667  within the loop.
26668 \layout Itemize
26669
26670 There are NO switch statements in the loop.
26671 \layout Subsection
26672
26673 Algebraic Simplifications
26674 \layout Standard
26675
26676 SDCC does numerous algebraic simplifications, the following is a small sub-set
26677  of these optimizations.
26678 \layout Verse
26679
26680
26681 \family typewriter 
26682 i = j + 0;\SpecialChar ~
26683 \SpecialChar ~
26684 \SpecialChar ~
26685 \SpecialChar ~
26686  /* changed to: */\SpecialChar ~
26687 \SpecialChar ~
26688 \SpecialChar ~
26689 \SpecialChar ~
26690  i = j; 
26691 \newline 
26692 i /= 2;\SpecialChar ~
26693 \SpecialChar ~
26694 \SpecialChar ~
26695 \SpecialChar ~
26696 \SpecialChar ~
26697 \SpecialChar ~
26698 \SpecialChar ~
26699  /* changed to: */\SpecialChar ~
26700 \SpecialChar ~
26701 \SpecialChar ~
26702 \SpecialChar ~
26703  i >>= 1; 
26704 \newline 
26705 i = j - j;\SpecialChar ~
26706 \SpecialChar ~
26707 \SpecialChar ~
26708 \SpecialChar ~
26709  /* changed to: */\SpecialChar ~
26710 \SpecialChar ~
26711 \SpecialChar ~
26712 \SpecialChar ~
26713  i = 0; 
26714 \newline 
26715 i = j / 1;\SpecialChar ~
26716 \SpecialChar ~
26717 \SpecialChar ~
26718 \SpecialChar ~
26719  /* changed to: */\SpecialChar ~
26720 \SpecialChar ~
26721 \SpecialChar ~
26722 \SpecialChar ~
26723  i = j;
26724 \layout Standard
26725
26726 Note the subexpressions
26727 \begin_inset LatexCommand \index{Subexpression}
26728
26729 \end_inset 
26730
26731  given above are generally introduced by macro expansions or as a result
26732  of copy/constant propagation.
26733 \layout Subsection
26734
26735 'switch' Statements
26736 \begin_inset LatexCommand \label{sub:'switch'-Statements}
26737
26738 \end_inset 
26739
26740
26741 \begin_inset LatexCommand \index{switch statement}
26742
26743 \end_inset 
26744
26745
26746 \layout Standard
26747
26748 SDCC can optimize switch statements to jump tables
26749 \begin_inset LatexCommand \index{jump tables}
26750
26751 \end_inset 
26752
26753 .
26754  It makes the decision based on an estimate of the generated code size.
26755  SDCC is quite liberal in the requirements for jump table generation: 
26756 \layout Itemize
26757
26758 The labels need not be in order, and the starting number need not be one
26759  or zero, the case labels are in numerical sequence or not too many case
26760  labels are missing.
26761 \begin_deeper 
26762 \layout Verse
26763
26764
26765 \family typewriter 
26766 switch(i) {\SpecialChar ~
26767 \SpecialChar ~
26768 \SpecialChar ~
26769 \SpecialChar ~
26770 \SpecialChar ~
26771 \SpecialChar ~
26772 \SpecialChar ~
26773 \SpecialChar ~
26774 \SpecialChar ~
26775 \SpecialChar ~
26776 \SpecialChar ~
26777 \SpecialChar ~
26778 \SpecialChar ~
26779 \SpecialChar ~
26780 \SpecialChar ~
26781 \SpecialChar ~
26782 \SpecialChar ~
26783 \SpecialChar ~
26784 \SpecialChar ~
26785 \SpecialChar ~
26786 \SpecialChar ~
26787 \SpecialChar ~
26788 \SpecialChar ~
26789 \SpecialChar ~
26790 \SpecialChar ~
26791 \SpecialChar ~
26792 switch (i) { 
26793 \newline 
26794 \SpecialChar ~
26795 \SpecialChar ~
26796 \SpecialChar ~
26797 case 4: ...\SpecialChar ~
26798 \SpecialChar ~
26799 \SpecialChar ~
26800 \SpecialChar ~
26801 \SpecialChar ~
26802 \SpecialChar ~
26803 \SpecialChar ~
26804 \SpecialChar ~
26805 \SpecialChar ~
26806 \SpecialChar ~
26807 \SpecialChar ~
26808 \SpecialChar ~
26809 \SpecialChar ~
26810 \SpecialChar ~
26811 \SpecialChar ~
26812 \SpecialChar ~
26813 \SpecialChar ~
26814 \SpecialChar ~
26815 \SpecialChar ~
26816 \SpecialChar ~
26817 \SpecialChar ~
26818 \SpecialChar ~
26819 \SpecialChar ~
26820 \SpecialChar ~
26821 \SpecialChar ~
26822 \SpecialChar ~
26823 case 0: ...
26824  
26825 \newline 
26826 \SpecialChar ~
26827 \SpecialChar ~
26828 \SpecialChar ~
26829 case 5: ...\SpecialChar ~
26830 \SpecialChar ~
26831 \SpecialChar ~
26832 \SpecialChar ~
26833 \SpecialChar ~
26834 \SpecialChar ~
26835 \SpecialChar ~
26836 \SpecialChar ~
26837 \SpecialChar ~
26838 \SpecialChar ~
26839 \SpecialChar ~
26840 \SpecialChar ~
26841 \SpecialChar ~
26842 \SpecialChar ~
26843 \SpecialChar ~
26844 \SpecialChar ~
26845 \SpecialChar ~
26846 \SpecialChar ~
26847 \SpecialChar ~
26848 \SpecialChar ~
26849 \SpecialChar ~
26850 \SpecialChar ~
26851 \SpecialChar ~
26852 \SpecialChar ~
26853 \SpecialChar ~
26854 \SpecialChar ~
26855 case 1: ...
26856  
26857 \newline 
26858 \SpecialChar ~
26859 \SpecialChar ~
26860 \SpecialChar ~
26861 case 3: ...\SpecialChar ~
26862 \SpecialChar ~
26863 \SpecialChar ~
26864 \SpecialChar ~
26865 \SpecialChar ~
26866 \SpecialChar ~
26867 \SpecialChar ~
26868 \SpecialChar ~
26869 \SpecialChar ~
26870 \SpecialChar ~
26871 \SpecialChar ~
26872 \SpecialChar ~
26873 \SpecialChar ~
26874 \SpecialChar ~
26875 \SpecialChar ~
26876 \SpecialChar ~
26877 \SpecialChar ~
26878 \SpecialChar ~
26879 \SpecialChar ~
26880 \SpecialChar ~
26881 \SpecialChar ~
26882 \SpecialChar ~
26883 \SpecialChar ~
26884 \SpecialChar ~
26885 \SpecialChar ~
26886 \SpecialChar ~
26887
26888 \newline 
26889 \SpecialChar ~
26890 \SpecialChar ~
26891 \SpecialChar ~
26892 case 6: ...\SpecialChar ~
26893 \SpecialChar ~
26894 \SpecialChar ~
26895 \SpecialChar ~
26896 \SpecialChar ~
26897 \SpecialChar ~
26898 \SpecialChar ~
26899 \SpecialChar ~
26900 \SpecialChar ~
26901 \SpecialChar ~
26902 \SpecialChar ~
26903 \SpecialChar ~
26904 \SpecialChar ~
26905 \SpecialChar ~
26906 \SpecialChar ~
26907 \SpecialChar ~
26908 \SpecialChar ~
26909 \SpecialChar ~
26910 \SpecialChar ~
26911 \SpecialChar ~
26912 \SpecialChar ~
26913 \SpecialChar ~
26914 \SpecialChar ~
26915 \SpecialChar ~
26916 \SpecialChar ~
26917 \SpecialChar ~
26918 case 3: ...
26919  
26920 \newline 
26921 \SpecialChar ~
26922 \SpecialChar ~
26923 \SpecialChar ~
26924 case 7: ...\SpecialChar ~
26925 \SpecialChar ~
26926 \SpecialChar ~
26927 \SpecialChar ~
26928 \SpecialChar ~
26929 \SpecialChar ~
26930 \SpecialChar ~
26931 \SpecialChar ~
26932 \SpecialChar ~
26933 \SpecialChar ~
26934 \SpecialChar ~
26935 \SpecialChar ~
26936 \SpecialChar ~
26937 \SpecialChar ~
26938 \SpecialChar ~
26939 \SpecialChar ~
26940 \SpecialChar ~
26941 \SpecialChar ~
26942 \SpecialChar ~
26943 \SpecialChar ~
26944 \SpecialChar ~
26945 \SpecialChar ~
26946 \SpecialChar ~
26947 \SpecialChar ~
26948 \SpecialChar ~
26949 \SpecialChar ~
26950 case 4: ...
26951  
26952 \newline 
26953 \SpecialChar ~
26954 \SpecialChar ~
26955 \SpecialChar ~
26956 case 8: ...\SpecialChar ~
26957 \SpecialChar ~
26958 \SpecialChar ~
26959 \SpecialChar ~
26960 \SpecialChar ~
26961 \SpecialChar ~
26962 \SpecialChar ~
26963 \SpecialChar ~
26964 \SpecialChar ~
26965 \SpecialChar ~
26966 \SpecialChar ~
26967 \SpecialChar ~
26968 \SpecialChar ~
26969 \SpecialChar ~
26970 \SpecialChar ~
26971 \SpecialChar ~
26972 \SpecialChar ~
26973 \SpecialChar ~
26974 \SpecialChar ~
26975 \SpecialChar ~
26976 \SpecialChar ~
26977 \SpecialChar ~
26978 \SpecialChar ~
26979 \SpecialChar ~
26980 \SpecialChar ~
26981 \SpecialChar ~
26982 case 5: ...
26983  
26984 \newline 
26985 \SpecialChar ~
26986 \SpecialChar ~
26987 \SpecialChar ~
26988 case 9: ...\SpecialChar ~
26989 \SpecialChar ~
26990 \SpecialChar ~
26991 \SpecialChar ~
26992 \SpecialChar ~
26993 \SpecialChar ~
26994 \SpecialChar ~
26995 \SpecialChar ~
26996 \SpecialChar ~
26997 \SpecialChar ~
26998 \SpecialChar ~
26999 \SpecialChar ~
27000 \SpecialChar ~
27001 \SpecialChar ~
27002 \SpecialChar ~
27003 \SpecialChar ~
27004 \SpecialChar ~
27005 \SpecialChar ~
27006 \SpecialChar ~
27007 \SpecialChar ~
27008 \SpecialChar ~
27009 \SpecialChar ~
27010 \SpecialChar ~
27011 \SpecialChar ~
27012 \SpecialChar ~
27013 \SpecialChar ~
27014 case 6: ...
27015  
27016 \newline 
27017 \SpecialChar ~
27018 \SpecialChar ~
27019 \SpecialChar ~
27020 case 10: ...\SpecialChar ~
27021 \SpecialChar ~
27022 \SpecialChar ~
27023 \SpecialChar ~
27024 \SpecialChar ~
27025 \SpecialChar ~
27026 \SpecialChar ~
27027 \SpecialChar ~
27028 \SpecialChar ~
27029 \SpecialChar ~
27030 \SpecialChar ~
27031 \SpecialChar ~
27032 \SpecialChar ~
27033 \SpecialChar ~
27034 \SpecialChar ~
27035 \SpecialChar ~
27036 \SpecialChar ~
27037 \SpecialChar ~
27038 \SpecialChar ~
27039 \SpecialChar ~
27040 \SpecialChar ~
27041 \SpecialChar ~
27042 \SpecialChar ~
27043 \SpecialChar ~
27044 \SpecialChar ~
27045 case 7: ...
27046  
27047 \newline 
27048 \SpecialChar ~
27049 \SpecialChar ~
27050 \SpecialChar ~
27051 case 11: ...\SpecialChar ~
27052 \SpecialChar ~
27053 \SpecialChar ~
27054 \SpecialChar ~
27055 \SpecialChar ~
27056 \SpecialChar ~
27057 \SpecialChar ~
27058 \SpecialChar ~
27059 \SpecialChar ~
27060 \SpecialChar ~
27061 \SpecialChar ~
27062 \SpecialChar ~
27063 \SpecialChar ~
27064 \SpecialChar ~
27065 \SpecialChar ~
27066 \SpecialChar ~
27067 \SpecialChar ~
27068 \SpecialChar ~
27069 \SpecialChar ~
27070 \SpecialChar ~
27071 \SpecialChar ~
27072 \SpecialChar ~
27073 \SpecialChar ~
27074 \SpecialChar ~
27075 \SpecialChar ~
27076 case 8: ...
27077  
27078 \newline 
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 \SpecialChar ~
27102 \SpecialChar ~
27103 \SpecialChar ~
27104 \SpecialChar ~
27105 \SpecialChar ~
27106 \SpecialChar ~
27107 \SpecialChar ~
27108 \SpecialChar ~
27109 \SpecialChar ~
27110 \SpecialChar ~
27111 \SpecialChar ~
27112 \SpecialChar ~
27113 \SpecialChar ~
27114 \SpecialChar ~
27115 }
27116 \layout Standard
27117
27118 Both the above switch statements will be implemented using a jump-table.
27119  The example to the right side is slightly more efficient as the check for
27120  the lower boundary of the jump-table is not needed.
27121 \end_deeper 
27122 \layout Itemize
27123
27124 The number of case labels is not larger than supported by the target architectur
27125 e.
27126 \layout Itemize
27127
27128 If the case labels are not in numerical sequence ('gaps' between cases)
27129  SDCC checks whether a jump table with additionally inserted dummy cases
27130  is still attractive.
27131  
27132 \layout Itemize
27133
27134 If the starting number is not zero and a check for the lower boundary of
27135  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
27136  ...
27137  .
27138 \layout Standard
27139
27140 Switch statements which have large gaps in the numeric sequence or those
27141  that have too many case labels can be split into more than one switch statement
27142  for efficient code generation, e.g.:
27143 \layout Verse
27144
27145
27146 \family typewriter 
27147 switch (i) { 
27148 \newline 
27149 \SpecialChar ~
27150 \SpecialChar ~
27151 case 1: ...
27152  
27153 \newline 
27154 \SpecialChar ~
27155 \SpecialChar ~
27156 case 2: ...
27157  
27158 \newline 
27159 \SpecialChar ~
27160 \SpecialChar ~
27161 case 3: ...
27162  
27163 \newline 
27164 \SpecialChar ~
27165 \SpecialChar ~
27166 case 4: ...
27167  
27168 \newline 
27169 \SpecialChar ~
27170 \SpecialChar ~
27171 case 5: ...
27172  
27173 \newline 
27174 \SpecialChar ~
27175 \SpecialChar ~
27176 case 6: ...
27177  
27178 \newline 
27179 \SpecialChar ~
27180 \SpecialChar ~
27181 case 7: ...
27182  
27183 \newline 
27184 \SpecialChar ~
27185 \SpecialChar ~
27186 case 101: ...
27187  
27188 \newline 
27189 \SpecialChar ~
27190 \SpecialChar ~
27191 case 102: ...
27192  
27193 \newline 
27194 \SpecialChar ~
27195 \SpecialChar ~
27196 case 103: ...
27197  
27198 \newline 
27199 \SpecialChar ~
27200 \SpecialChar ~
27201 case 104: ...
27202  
27203 \newline 
27204 \SpecialChar ~
27205 \SpecialChar ~
27206 case 105: ...
27207  
27208 \newline 
27209 \SpecialChar ~
27210 \SpecialChar ~
27211 case 106: ...
27212  
27213 \newline 
27214 \SpecialChar ~
27215 \SpecialChar ~
27216 case 107: ...
27217  
27218 \newline 
27219 }
27220 \layout Standard
27221
27222 If the above switch statement is broken down into two switch statements
27223 \layout Verse
27224
27225
27226 \family typewriter 
27227 switch (i) { 
27228 \newline 
27229 \SpecialChar ~
27230 \SpecialChar ~
27231 case 1: ...
27232  
27233 \newline 
27234 \SpecialChar ~
27235 \SpecialChar ~
27236 case 2: ...
27237  
27238 \newline 
27239 \SpecialChar ~
27240 \SpecialChar ~
27241 case 3: ...
27242  
27243 \newline 
27244 \SpecialChar ~
27245 \SpecialChar ~
27246 case 4: ...
27247  
27248 \newline 
27249 \SpecialChar ~
27250 \SpecialChar ~
27251 case 5: ...
27252  
27253 \newline 
27254 \SpecialChar ~
27255 \SpecialChar ~
27256 case 6: ...
27257  
27258 \newline 
27259 \SpecialChar ~
27260 \SpecialChar ~
27261 case 7: ...
27262  
27263 \newline 
27264 }
27265 \layout Standard
27266
27267 and
27268 \layout Verse
27269
27270
27271 \family typewriter 
27272 switch (i) { 
27273 \newline 
27274 \SpecialChar ~
27275 \SpecialChar ~
27276 case 101: ...
27277  
27278 \newline 
27279 \SpecialChar ~
27280 \SpecialChar ~
27281 case 102: ...
27282  
27283 \newline 
27284 \SpecialChar ~
27285 \SpecialChar ~
27286 case 103: ...
27287  
27288 \newline 
27289 \SpecialChar ~
27290 \SpecialChar ~
27291 case 104: ...
27292  
27293 \newline 
27294 \SpecialChar ~
27295 \SpecialChar ~
27296 case 105: ...
27297  
27298 \newline 
27299 \SpecialChar ~
27300 \SpecialChar ~
27301 case 106: ...
27302  
27303 \newline 
27304 \SpecialChar ~
27305 \SpecialChar ~
27306 case 107: ...
27307  
27308 \newline 
27309 }
27310 \layout Standard
27311
27312 then both the switch statements will be implemented using jump-tables whereas
27313  the unmodified switch statement will not be.
27314 \layout Comment
27315
27316 There might be reasons which SDCC cannot know about to either favour or
27317  not favour jump tables.
27318  If the target system has to be as quick for the last switch case as for
27319  the first (pro jump table), or if the switch argument is known to be zero
27320  in the majority of the cases (contra jump table).
27321 \layout Standard
27322
27323 The pragma nojtbound
27324 \begin_inset LatexCommand \index{\#pragma nojtbound}
27325
27326 \end_inset 
27327
27328  can be used to turn off checking the 
27329 \emph on 
27330 j
27331 \emph default 
27332 ump 
27333 \emph on 
27334 t
27335 \emph default 
27336 able 
27337 \emph on 
27338 bound
27339 \emph default 
27340 aries.
27341  It has no effect if a default label is supplied.
27342  Use of this pragma is dangerous: if the switch
27343 \begin_inset LatexCommand \index{switch statement}
27344
27345 \end_inset 
27346
27347  argument is not matched by a case statement the processor will happily
27348  jump into Nirvana.
27349 \layout Subsection
27350
27351 Bit-shifting Operations
27352 \begin_inset LatexCommand \index{Bit shifting}
27353
27354 \end_inset 
27355
27356 .
27357 \layout Standard
27358
27359 Bit shifting is one of the most frequently used operation in embedded programmin
27360 g.
27361  SDCC tries to implement bit-shift operations in the most efficient way
27362  possible, e.g.:
27363 \layout Verse
27364
27365
27366 \family typewriter 
27367 unsigned char i;
27368 \newline 
27369 ...
27370  
27371 \newline 
27372 i >>= 4; 
27373 \newline 
27374 ...
27375 \layout Standard
27376
27377 generates the following code:
27378 \layout Verse
27379
27380
27381 \family typewriter 
27382 mov\SpecialChar ~
27383  a,_i 
27384 \newline 
27385 swap a 
27386 \newline 
27387 anl\SpecialChar ~
27388  a,#0x0f 
27389 \newline 
27390 mov\SpecialChar ~
27391  _i,a
27392 \layout Standard
27393
27394 In general SDCC will never setup a loop if the shift count is known.
27395  Another example:
27396 \layout Verse
27397
27398
27399 \family typewriter 
27400 unsigned int i; 
27401 \newline 
27402 ...
27403  
27404 \newline 
27405 i >>= 9; 
27406 \newline 
27407 ...
27408 \layout Standard
27409
27410 will generate:
27411 \layout Verse
27412
27413
27414 \family typewriter 
27415 mov\SpecialChar ~
27416 \SpecialChar ~
27417 a,(_i + 1) 
27418 \newline 
27419 mov\SpecialChar ~
27420 \SpecialChar ~
27421 (_i + 1),#0x00 
27422 \newline 
27423 clr\SpecialChar ~
27424 \SpecialChar ~
27425
27426 \newline 
27427 rrc\SpecialChar ~
27428 \SpecialChar ~
27429
27430 \newline 
27431 mov\SpecialChar ~
27432 \SpecialChar ~
27433 _i,a
27434 \layout Subsection
27435
27436 Bit-rotation
27437 \begin_inset LatexCommand \index{Bit rotation}
27438
27439 \end_inset 
27440
27441
27442 \layout Standard
27443
27444 A special case of the bit-shift operation is bit rotation
27445 \begin_inset LatexCommand \index{rotating bits}
27446
27447 \end_inset 
27448
27449 , SDCC recognizes the following expression to be a left bit-rotation:
27450 \layout Verse
27451
27452
27453 \family typewriter 
27454 \series bold 
27455 unsigned
27456 \series default 
27457 \SpecialChar ~
27458 \SpecialChar ~
27459 char i;\SpecialChar ~
27460 \SpecialChar ~
27461 \SpecialChar ~
27462 \SpecialChar ~
27463 \SpecialChar ~
27464 \SpecialChar ~
27465 \SpecialChar ~
27466 \SpecialChar ~
27467 \SpecialChar ~
27468 \SpecialChar ~
27469 \SpecialChar ~
27470 /* unsigned is needed for rotation */ 
27471 \newline 
27472 ...
27473  
27474 \newline 
27475 i = ((i << 1) | (i >> 7)); 
27476 \family default 
27477
27478 \newline 
27479
27480 \family typewriter 
27481 ...
27482 \layout Standard
27483
27484 will generate the following code:
27485 \layout Verse
27486
27487
27488 \family typewriter 
27489 mov\SpecialChar ~
27490 \SpecialChar ~
27491 a,_i 
27492 \newline 
27493 rl\SpecialChar ~
27494 \SpecialChar ~
27495 \SpecialChar ~
27496
27497 \newline 
27498 mov\SpecialChar ~
27499 \SpecialChar ~
27500 _i,a
27501 \layout Standard
27502
27503 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27504 ns of this case will also be recognized as bit-rotation, i.e.: 
27505 \layout Verse
27506
27507
27508 \family typewriter 
27509 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27510 \layout Subsection
27511
27512 Nibble and Byte Swapping
27513 \layout Standard
27514
27515 Other special cases of the bit-shift operations are nibble or byte swapping
27516 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27517
27518 \end_inset 
27519
27520 , SDCC recognizes the following expressions:
27521 \layout Verse
27522
27523
27524 \family typewriter 
27525 \series bold 
27526 unsigned
27527 \series default 
27528 \SpecialChar ~
27529 \SpecialChar ~
27530 char i; 
27531 \newline 
27532
27533 \series bold 
27534 unsigned
27535 \series default 
27536 \SpecialChar ~
27537 \SpecialChar ~
27538 int j; 
27539 \newline 
27540 ...
27541  
27542 \newline 
27543 i = ((i << 4) | (i >> 4)); 
27544 \family default 
27545
27546 \newline 
27547
27548 \family typewriter 
27549 j = ((j << 8) | (j >> 8)); 
27550 \layout Standard
27551
27552 and generates a swap instruction for the nibble swapping
27553 \begin_inset LatexCommand \index{Nibble swapping}
27554
27555 \end_inset 
27556
27557  or move instructions for the byte swapping
27558 \begin_inset LatexCommand \index{Byte swapping}
27559
27560 \end_inset 
27561
27562 .
27563  The 
27564 \begin_inset Quotes sld
27565 \end_inset 
27566
27567 j
27568 \begin_inset Quotes srd
27569 \end_inset 
27570
27571  example can be used to convert from little to big-endian or vice versa.
27572  If you want to change the endianness of a 
27573 \emph on 
27574 signed
27575 \emph default 
27576  integer you have to cast to 
27577 \family typewriter 
27578 (unsigned int)
27579 \family default 
27580  first.
27581 \layout Standard
27582
27583 Note that SDCC stores numbers in little-endian
27584 \begin_inset Foot
27585 collapsed false
27586
27587 \layout Standard
27588
27589 Usually 8-bit processors don't care much about endianness.
27590  This is not the case for the standard 8051 which only has an instruction
27591  to increment its 
27592 \emph on 
27593 dptr
27594 \emph default 
27595
27596 \begin_inset LatexCommand \index{DPTR}
27597
27598 \end_inset 
27599
27600 -datapointer
27601 \emph on 
27602  
27603 \emph default 
27604 so little-endian is the more efficient byte order.
27605 \end_inset 
27606
27607
27608 \begin_inset LatexCommand \index{little-endian}
27609
27610 \end_inset 
27611
27612
27613 \begin_inset LatexCommand \index{Endianness}
27614
27615 \end_inset 
27616
27617  format (i.e.
27618  lowest order first).
27619 \layout Subsection
27620
27621 Highest Order Bit
27622 \begin_inset LatexCommand \index{Highest Order Bit}
27623
27624 \end_inset 
27625
27626  / Any Order Bit
27627 \begin_inset LatexCommand \index{Any Order Bit}
27628
27629 \end_inset 
27630
27631
27632 \layout Standard
27633
27634 It is frequently required to obtain the highest order bit of an integral
27635  type (long, int, short or char types).
27636  Also obtaining any other order bit is not uncommon.
27637  SDCC recognizes the following expressions to yield the highest order bit
27638  and generates optimized code for it, e.g.:
27639 \layout Verse
27640
27641
27642 \family typewriter 
27643 unsigned int gint; 
27644 \newline 
27645
27646 \newline 
27647 foo () { 
27648 \newline 
27649 \SpecialChar ~
27650 \SpecialChar ~
27651 unsigned char hob1, aob1; 
27652 \newline 
27653 \SpecialChar ~
27654 \SpecialChar ~
27655 bit hob2, hob3, aob2, aob3; 
27656 \newline 
27657 \SpecialChar ~
27658 \SpecialChar ~
27659 ...
27660  
27661 \newline 
27662 \SpecialChar ~
27663 \SpecialChar ~
27664 hob1 = (gint >> 15) & 1; 
27665 \newline 
27666 \SpecialChar ~
27667 \SpecialChar ~
27668 hob2 = (gint >> 15) & 1; 
27669 \newline 
27670 \SpecialChar ~
27671 \SpecialChar ~
27672 hob3 = gint & 0x8000; 
27673 \newline 
27674 \SpecialChar ~
27675 \SpecialChar ~
27676 aob1 = (gint >> 9) & 1; 
27677 \newline 
27678 \SpecialChar ~
27679 \SpecialChar ~
27680 aob2 = (gint >> 8) & 1; 
27681 \newline 
27682 \SpecialChar ~
27683 \SpecialChar ~
27684 aob3 = gint & 0x0800; 
27685 \newline 
27686 \SpecialChar ~
27687 \SpecialChar ~
27688 ..
27689  
27690 \newline 
27691 }
27692 \layout Standard
27693
27694 will generate the following code:
27695 \layout Verse
27696
27697
27698 \family typewriter 
27699 \SpecialChar ~
27700 \SpecialChar ~
27701 \SpecialChar ~
27702 \SpecialChar ~
27703 \SpecialChar ~
27704 \SpecialChar ~
27705 \SpecialChar ~
27706 \SpecialChar ~
27707 \SpecialChar ~
27708 \SpecialChar ~
27709 \SpecialChar ~
27710 \SpecialChar ~
27711 \SpecialChar ~
27712 \SpecialChar ~
27713 \SpecialChar ~
27714 \SpecialChar ~
27715 \SpecialChar ~
27716 \SpecialChar ~
27717 \SpecialChar ~
27718 \SpecialChar ~
27719 \SpecialChar ~
27720 \SpecialChar ~
27721 \SpecialChar ~
27722 \SpecialChar ~
27723 \SpecialChar ~
27724  61 ;\SpecialChar ~
27725  hob.c 7 
27726 \newline 
27727 000A E5*01\SpecialChar ~
27728 \SpecialChar ~
27729 \SpecialChar ~
27730 \SpecialChar ~
27731 \SpecialChar ~
27732 \SpecialChar ~
27733 \SpecialChar ~
27734 \SpecialChar ~
27735 \SpecialChar ~
27736 \SpecialChar ~
27737 \SpecialChar ~
27738 \SpecialChar ~
27739 \SpecialChar ~
27740 \SpecialChar ~
27741 \SpecialChar ~
27742  62\SpecialChar ~
27743 \SpecialChar ~
27744 \SpecialChar ~
27745 \SpecialChar ~
27746 \SpecialChar ~
27747 \SpecialChar ~
27748 \SpecialChar ~
27749 \SpecialChar ~
27750  mov\SpecialChar ~
27751 \SpecialChar ~
27752  a,(_gint + 1) 
27753 \newline 
27754 000C 23\SpecialChar ~
27755 \SpecialChar ~
27756 \SpecialChar ~
27757 \SpecialChar ~
27758 \SpecialChar ~
27759 \SpecialChar ~
27760 \SpecialChar ~
27761 \SpecialChar ~
27762 \SpecialChar ~
27763 \SpecialChar ~
27764 \SpecialChar ~
27765 \SpecialChar ~
27766 \SpecialChar ~
27767 \SpecialChar ~
27768 \SpecialChar ~
27769 \SpecialChar ~
27770 \SpecialChar ~
27771 \SpecialChar ~
27772  63\SpecialChar ~
27773 \SpecialChar ~
27774 \SpecialChar ~
27775 \SpecialChar ~
27776 \SpecialChar ~
27777 \SpecialChar ~
27778 \SpecialChar ~
27779 \SpecialChar ~
27780  rl\SpecialChar ~
27781 \SpecialChar ~
27782 \SpecialChar ~
27783  a 
27784 \newline 
27785 000D 54 01\SpecialChar ~
27786 \SpecialChar ~
27787 \SpecialChar ~
27788 \SpecialChar ~
27789 \SpecialChar ~
27790 \SpecialChar ~
27791 \SpecialChar ~
27792 \SpecialChar ~
27793 \SpecialChar ~
27794 \SpecialChar ~
27795 \SpecialChar ~
27796 \SpecialChar ~
27797 \SpecialChar ~
27798 \SpecialChar ~
27799 \SpecialChar ~
27800  64\SpecialChar ~
27801 \SpecialChar ~
27802 \SpecialChar ~
27803 \SpecialChar ~
27804 \SpecialChar ~
27805 \SpecialChar ~
27806 \SpecialChar ~
27807 \SpecialChar ~
27808  anl\SpecialChar ~
27809 \SpecialChar ~
27810  a,#0x01 
27811 \newline 
27812 000F F5*02\SpecialChar ~
27813 \SpecialChar ~
27814 \SpecialChar ~
27815 \SpecialChar ~
27816 \SpecialChar ~
27817 \SpecialChar ~
27818 \SpecialChar ~
27819 \SpecialChar ~
27820 \SpecialChar ~
27821 \SpecialChar ~
27822 \SpecialChar ~
27823 \SpecialChar ~
27824 \SpecialChar ~
27825 \SpecialChar ~
27826 \SpecialChar ~
27827  65\SpecialChar ~
27828 \SpecialChar ~
27829 \SpecialChar ~
27830 \SpecialChar ~
27831 \SpecialChar ~
27832 \SpecialChar ~
27833 \SpecialChar ~
27834 \SpecialChar ~
27835  mov\SpecialChar ~
27836 \SpecialChar ~
27837  _foo_hob1_1_1,a 
27838 \newline 
27839 \SpecialChar ~
27840 \SpecialChar ~
27841 \SpecialChar ~
27842 \SpecialChar ~
27843 \SpecialChar ~
27844 \SpecialChar ~
27845 \SpecialChar ~
27846 \SpecialChar ~
27847 \SpecialChar ~
27848 \SpecialChar ~
27849 \SpecialChar ~
27850 \SpecialChar ~
27851 \SpecialChar ~
27852 \SpecialChar ~
27853 \SpecialChar ~
27854 \SpecialChar ~
27855 \SpecialChar ~
27856 \SpecialChar ~
27857 \SpecialChar ~
27858 \SpecialChar ~
27859 \SpecialChar ~
27860 \SpecialChar ~
27861 \SpecialChar ~
27862 \SpecialChar ~
27863 \SpecialChar ~
27864  66 ;\SpecialChar ~
27865  hob.c 8 
27866 \newline 
27867 0011 E5*01\SpecialChar ~
27868 \SpecialChar ~
27869 \SpecialChar ~
27870 \SpecialChar ~
27871 \SpecialChar ~
27872 \SpecialChar ~
27873 \SpecialChar ~
27874 \SpecialChar ~
27875 \SpecialChar ~
27876 \SpecialChar ~
27877 \SpecialChar ~
27878 \SpecialChar ~
27879 \SpecialChar ~
27880 \SpecialChar ~
27881 \SpecialChar ~
27882  67\SpecialChar ~
27883 \SpecialChar ~
27884 \SpecialChar ~
27885 \SpecialChar ~
27886 \SpecialChar ~
27887 \SpecialChar ~
27888 \SpecialChar ~
27889 \SpecialChar ~
27890  mov\SpecialChar ~
27891 \SpecialChar ~
27892  a,(_gint + 1) 
27893 \newline 
27894 0013 33\SpecialChar ~
27895 \SpecialChar ~
27896 \SpecialChar ~
27897 \SpecialChar ~
27898 \SpecialChar ~
27899 \SpecialChar ~
27900 \SpecialChar ~
27901 \SpecialChar ~
27902 \SpecialChar ~
27903 \SpecialChar ~
27904 \SpecialChar ~
27905 \SpecialChar ~
27906 \SpecialChar ~
27907 \SpecialChar ~
27908 \SpecialChar ~
27909 \SpecialChar ~
27910 \SpecialChar ~
27911 \SpecialChar ~
27912  68\SpecialChar ~
27913 \SpecialChar ~
27914 \SpecialChar ~
27915 \SpecialChar ~
27916 \SpecialChar ~
27917 \SpecialChar ~
27918 \SpecialChar ~
27919 \SpecialChar ~
27920  rlc\SpecialChar ~
27921 \SpecialChar ~
27922  a 
27923 \newline 
27924 0014 92*00\SpecialChar ~
27925 \SpecialChar ~
27926 \SpecialChar ~
27927 \SpecialChar ~
27928 \SpecialChar ~
27929 \SpecialChar ~
27930 \SpecialChar ~
27931 \SpecialChar ~
27932 \SpecialChar ~
27933 \SpecialChar ~
27934 \SpecialChar ~
27935 \SpecialChar ~
27936 \SpecialChar ~
27937 \SpecialChar ~
27938 \SpecialChar ~
27939  69\SpecialChar ~
27940 \SpecialChar ~
27941 \SpecialChar ~
27942 \SpecialChar ~
27943 \SpecialChar ~
27944 \SpecialChar ~
27945 \SpecialChar ~
27946 \SpecialChar ~
27947  mov\SpecialChar ~
27948 \SpecialChar ~
27949  _foo_hob2_1_1,c 
27950 \newline 
27951 \SpecialChar ~
27952 \SpecialChar ~
27953 \SpecialChar ~
27954 \SpecialChar ~
27955 \SpecialChar ~
27956 \SpecialChar ~
27957 \SpecialChar ~
27958 \SpecialChar ~
27959 \SpecialChar ~
27960 \SpecialChar ~
27961 \SpecialChar ~
27962 \SpecialChar ~
27963 \SpecialChar ~
27964 \SpecialChar ~
27965 \SpecialChar ~
27966 \SpecialChar ~
27967 \SpecialChar ~
27968 \SpecialChar ~
27969 \SpecialChar ~
27970 \SpecialChar ~
27971 \SpecialChar ~
27972 \SpecialChar ~
27973 \SpecialChar ~
27974 \SpecialChar ~
27975 \SpecialChar ~
27976  66 ;\SpecialChar ~
27977  hob.c 9 
27978 \newline 
27979 0016 E5*01\SpecialChar ~
27980 \SpecialChar ~
27981 \SpecialChar ~
27982 \SpecialChar ~
27983 \SpecialChar ~
27984 \SpecialChar ~
27985 \SpecialChar ~
27986 \SpecialChar ~
27987 \SpecialChar ~
27988 \SpecialChar ~
27989 \SpecialChar ~
27990 \SpecialChar ~
27991 \SpecialChar ~
27992 \SpecialChar ~
27993 \SpecialChar ~
27994  67\SpecialChar ~
27995 \SpecialChar ~
27996 \SpecialChar ~
27997 \SpecialChar ~
27998 \SpecialChar ~
27999 \SpecialChar ~
28000 \SpecialChar ~
28001 \SpecialChar ~
28002  mov\SpecialChar ~
28003 \SpecialChar ~
28004  a,(_gint + 1) 
28005 \newline 
28006 0018 33\SpecialChar ~
28007 \SpecialChar ~
28008 \SpecialChar ~
28009 \SpecialChar ~
28010 \SpecialChar ~
28011 \SpecialChar ~
28012 \SpecialChar ~
28013 \SpecialChar ~
28014 \SpecialChar ~
28015 \SpecialChar ~
28016 \SpecialChar ~
28017 \SpecialChar ~
28018 \SpecialChar ~
28019 \SpecialChar ~
28020 \SpecialChar ~
28021 \SpecialChar ~
28022 \SpecialChar ~
28023 \SpecialChar ~
28024  68\SpecialChar ~
28025 \SpecialChar ~
28026 \SpecialChar ~
28027 \SpecialChar ~
28028 \SpecialChar ~
28029 \SpecialChar ~
28030 \SpecialChar ~
28031 \SpecialChar ~
28032  rlc\SpecialChar ~
28033 \SpecialChar ~
28034  a 
28035 \newline 
28036 0019 92*01\SpecialChar ~
28037 \SpecialChar ~
28038 \SpecialChar ~
28039 \SpecialChar ~
28040 \SpecialChar ~
28041 \SpecialChar ~
28042 \SpecialChar ~
28043 \SpecialChar ~
28044 \SpecialChar ~
28045 \SpecialChar ~
28046 \SpecialChar ~
28047 \SpecialChar ~
28048 \SpecialChar ~
28049 \SpecialChar ~
28050 \SpecialChar ~
28051  69\SpecialChar ~
28052 \SpecialChar ~
28053 \SpecialChar ~
28054 \SpecialChar ~
28055 \SpecialChar ~
28056 \SpecialChar ~
28057 \SpecialChar ~
28058 \SpecialChar ~
28059  mov\SpecialChar ~
28060 \SpecialChar ~
28061  _foo_hob3_1_1,c 
28062 \newline 
28063 \SpecialChar ~
28064 \SpecialChar ~
28065 \SpecialChar ~
28066 \SpecialChar ~
28067 \SpecialChar ~
28068 \SpecialChar ~
28069 \SpecialChar ~
28070 \SpecialChar ~
28071 \SpecialChar ~
28072 \SpecialChar ~
28073 \SpecialChar ~
28074 \SpecialChar ~
28075 \SpecialChar ~
28076 \SpecialChar ~
28077 \SpecialChar ~
28078 \SpecialChar ~
28079 \SpecialChar ~
28080 \SpecialChar ~
28081 \SpecialChar ~
28082 \SpecialChar ~
28083 \SpecialChar ~
28084 \SpecialChar ~
28085 \SpecialChar ~
28086 \SpecialChar ~
28087 \SpecialChar ~
28088  70 ;\SpecialChar ~
28089  hob.c 10 
28090 \newline 
28091 001B E5*01\SpecialChar ~
28092 \SpecialChar ~
28093 \SpecialChar ~
28094 \SpecialChar ~
28095 \SpecialChar ~
28096 \SpecialChar ~
28097 \SpecialChar ~
28098 \SpecialChar ~
28099 \SpecialChar ~
28100 \SpecialChar ~
28101 \SpecialChar ~
28102 \SpecialChar ~
28103 \SpecialChar ~
28104 \SpecialChar ~
28105 \SpecialChar ~
28106  71\SpecialChar ~
28107 \SpecialChar ~
28108 \SpecialChar ~
28109 \SpecialChar ~
28110 \SpecialChar ~
28111 \SpecialChar ~
28112 \SpecialChar ~
28113 \SpecialChar ~
28114  mov\SpecialChar ~
28115 \SpecialChar ~
28116  a,(_gint + 1) 
28117 \newline 
28118 001D 03\SpecialChar ~
28119 \SpecialChar ~
28120 \SpecialChar ~
28121 \SpecialChar ~
28122 \SpecialChar ~
28123 \SpecialChar ~
28124 \SpecialChar ~
28125 \SpecialChar ~
28126 \SpecialChar ~
28127 \SpecialChar ~
28128 \SpecialChar ~
28129 \SpecialChar ~
28130 \SpecialChar ~
28131 \SpecialChar ~
28132 \SpecialChar ~
28133 \SpecialChar ~
28134 \SpecialChar ~
28135 \SpecialChar ~
28136  72\SpecialChar ~
28137 \SpecialChar ~
28138 \SpecialChar ~
28139 \SpecialChar ~
28140 \SpecialChar ~
28141 \SpecialChar ~
28142 \SpecialChar ~
28143 \SpecialChar ~
28144  rr\SpecialChar ~
28145 \SpecialChar ~
28146 \SpecialChar ~
28147  a 
28148 \newline 
28149 001E 54 01\SpecialChar ~
28150 \SpecialChar ~
28151 \SpecialChar ~
28152 \SpecialChar ~
28153 \SpecialChar ~
28154 \SpecialChar ~
28155 \SpecialChar ~
28156 \SpecialChar ~
28157 \SpecialChar ~
28158 \SpecialChar ~
28159 \SpecialChar ~
28160 \SpecialChar ~
28161 \SpecialChar ~
28162 \SpecialChar ~
28163 \SpecialChar ~
28164  73\SpecialChar ~
28165 \SpecialChar ~
28166 \SpecialChar ~
28167 \SpecialChar ~
28168 \SpecialChar ~
28169 \SpecialChar ~
28170 \SpecialChar ~
28171 \SpecialChar ~
28172  anl\SpecialChar ~
28173 \SpecialChar ~
28174  a,#0x01 
28175 \newline 
28176 0020 F5*03\SpecialChar ~
28177 \SpecialChar ~
28178 \SpecialChar ~
28179 \SpecialChar ~
28180 \SpecialChar ~
28181 \SpecialChar ~
28182 \SpecialChar ~
28183 \SpecialChar ~
28184 \SpecialChar ~
28185 \SpecialChar ~
28186 \SpecialChar ~
28187 \SpecialChar ~
28188 \SpecialChar ~
28189 \SpecialChar ~
28190 \SpecialChar ~
28191  74\SpecialChar ~
28192 \SpecialChar ~
28193 \SpecialChar ~
28194 \SpecialChar ~
28195 \SpecialChar ~
28196 \SpecialChar ~
28197 \SpecialChar ~
28198 \SpecialChar ~
28199  mov\SpecialChar ~
28200 \SpecialChar ~
28201  _foo_aob1_1_1,a 
28202 \newline 
28203 \SpecialChar ~
28204 \SpecialChar ~
28205 \SpecialChar ~
28206 \SpecialChar ~
28207 \SpecialChar ~
28208 \SpecialChar ~
28209 \SpecialChar ~
28210 \SpecialChar ~
28211 \SpecialChar ~
28212 \SpecialChar ~
28213 \SpecialChar ~
28214 \SpecialChar ~
28215 \SpecialChar ~
28216 \SpecialChar ~
28217 \SpecialChar ~
28218 \SpecialChar ~
28219 \SpecialChar ~
28220 \SpecialChar ~
28221 \SpecialChar ~
28222 \SpecialChar ~
28223 \SpecialChar ~
28224 \SpecialChar ~
28225 \SpecialChar ~
28226 \SpecialChar ~
28227 \SpecialChar ~
28228  75 ;\SpecialChar ~
28229  hob.c 11 
28230 \newline 
28231 0022 E5*01\SpecialChar ~
28232 \SpecialChar ~
28233 \SpecialChar ~
28234 \SpecialChar ~
28235 \SpecialChar ~
28236 \SpecialChar ~
28237 \SpecialChar ~
28238 \SpecialChar ~
28239 \SpecialChar ~
28240 \SpecialChar ~
28241 \SpecialChar ~
28242 \SpecialChar ~
28243 \SpecialChar ~
28244 \SpecialChar ~
28245 \SpecialChar ~
28246  76\SpecialChar ~
28247 \SpecialChar ~
28248 \SpecialChar ~
28249 \SpecialChar ~
28250 \SpecialChar ~
28251 \SpecialChar ~
28252 \SpecialChar ~
28253 \SpecialChar ~
28254  mov\SpecialChar ~
28255 \SpecialChar ~
28256  a,(_gint + 1) 
28257 \newline 
28258 0024 13\SpecialChar ~
28259 \SpecialChar ~
28260 \SpecialChar ~
28261 \SpecialChar ~
28262 \SpecialChar ~
28263 \SpecialChar ~
28264 \SpecialChar ~
28265 \SpecialChar ~
28266 \SpecialChar ~
28267 \SpecialChar ~
28268 \SpecialChar ~
28269 \SpecialChar ~
28270 \SpecialChar ~
28271 \SpecialChar ~
28272 \SpecialChar ~
28273 \SpecialChar ~
28274 \SpecialChar ~
28275 \SpecialChar ~
28276  77\SpecialChar ~
28277 \SpecialChar ~
28278 \SpecialChar ~
28279 \SpecialChar ~
28280 \SpecialChar ~
28281 \SpecialChar ~
28282 \SpecialChar ~
28283 \SpecialChar ~
28284  rrc\SpecialChar ~
28285 \SpecialChar ~
28286  a 
28287 \newline 
28288 0025 92*02\SpecialChar ~
28289 \SpecialChar ~
28290 \SpecialChar ~
28291 \SpecialChar ~
28292 \SpecialChar ~
28293 \SpecialChar ~
28294 \SpecialChar ~
28295 \SpecialChar ~
28296 \SpecialChar ~
28297 \SpecialChar ~
28298 \SpecialChar ~
28299 \SpecialChar ~
28300 \SpecialChar ~
28301 \SpecialChar ~
28302 \SpecialChar ~
28303  78\SpecialChar ~
28304 \SpecialChar ~
28305 \SpecialChar ~
28306 \SpecialChar ~
28307 \SpecialChar ~
28308 \SpecialChar ~
28309 \SpecialChar ~
28310 \SpecialChar ~
28311  mov\SpecialChar ~
28312 \SpecialChar ~
28313  _foo_aob2_1_1,c 
28314 \newline 
28315 \SpecialChar ~
28316 \SpecialChar ~
28317 \SpecialChar ~
28318 \SpecialChar ~
28319 \SpecialChar ~
28320 \SpecialChar ~
28321 \SpecialChar ~
28322 \SpecialChar ~
28323 \SpecialChar ~
28324 \SpecialChar ~
28325 \SpecialChar ~
28326 \SpecialChar ~
28327 \SpecialChar ~
28328 \SpecialChar ~
28329 \SpecialChar ~
28330 \SpecialChar ~
28331 \SpecialChar ~
28332 \SpecialChar ~
28333 \SpecialChar ~
28334 \SpecialChar ~
28335 \SpecialChar ~
28336 \SpecialChar ~
28337 \SpecialChar ~
28338 \SpecialChar ~
28339 \SpecialChar ~
28340  79 ;\SpecialChar ~
28341  hob.c 12 
28342 \newline 
28343 0027 E5*01\SpecialChar ~
28344 \SpecialChar ~
28345 \SpecialChar ~
28346 \SpecialChar ~
28347 \SpecialChar ~
28348 \SpecialChar ~
28349 \SpecialChar ~
28350 \SpecialChar ~
28351 \SpecialChar ~
28352 \SpecialChar ~
28353 \SpecialChar ~
28354 \SpecialChar ~
28355 \SpecialChar ~
28356 \SpecialChar ~
28357 \SpecialChar ~
28358  80\SpecialChar ~
28359 \SpecialChar ~
28360 \SpecialChar ~
28361 \SpecialChar ~
28362 \SpecialChar ~
28363 \SpecialChar ~
28364 \SpecialChar ~
28365 \SpecialChar ~
28366  mov\SpecialChar ~
28367 \SpecialChar ~
28368  a,(_gint + 1) 
28369 \newline 
28370 0029 A2 E3\SpecialChar ~
28371 \SpecialChar ~
28372 \SpecialChar ~
28373 \SpecialChar ~
28374 \SpecialChar ~
28375 \SpecialChar ~
28376 \SpecialChar ~
28377 \SpecialChar ~
28378 \SpecialChar ~
28379 \SpecialChar ~
28380 \SpecialChar ~
28381 \SpecialChar ~
28382 \SpecialChar ~
28383 \SpecialChar ~
28384 \SpecialChar ~
28385  81\SpecialChar ~
28386 \SpecialChar ~
28387 \SpecialChar ~
28388 \SpecialChar ~
28389 \SpecialChar ~
28390 \SpecialChar ~
28391 \SpecialChar ~
28392 \SpecialChar ~
28393  mov\SpecialChar ~
28394 \SpecialChar ~
28395  c,acc[3] 
28396 \newline 
28397 002B 92*03\SpecialChar ~
28398 \SpecialChar ~
28399 \SpecialChar ~
28400 \SpecialChar ~
28401 \SpecialChar ~
28402 \SpecialChar ~
28403 \SpecialChar ~
28404 \SpecialChar ~
28405 \SpecialChar ~
28406 \SpecialChar ~
28407 \SpecialChar ~
28408 \SpecialChar ~
28409 \SpecialChar ~
28410 \SpecialChar ~
28411 \SpecialChar ~
28412  82\SpecialChar ~
28413 \SpecialChar ~
28414 \SpecialChar ~
28415 \SpecialChar ~
28416 \SpecialChar ~
28417 \SpecialChar ~
28418 \SpecialChar ~
28419 \SpecialChar ~
28420  mov\SpecialChar ~
28421 \SpecialChar ~
28422  _foo_aob3_1_1,c 
28423 \layout Standard
28424
28425 Other variations of these cases however will 
28426 \emph on 
28427 not
28428 \emph default 
28429  be recognized.
28430  They are standard C expressions, so I heartily recommend these be the only
28431  way to get the highest order bit, (it is portable).
28432  Of course it will be recognized even if it is embedded in other expressions,
28433  e.g.:
28434 \layout Verse
28435
28436
28437 \family typewriter 
28438 xyz = gint + ((gint >> 15) & 1);
28439 \layout Standard
28440
28441 will still be recognized.
28442 \layout Subsection
28443
28444 Higher Order Byte
28445 \begin_inset LatexCommand \index{Higher Order Byte}
28446
28447 \end_inset 
28448
28449  / Higher Order Word
28450 \begin_inset LatexCommand \index{Higher Order Word}
28451
28452 \end_inset 
28453
28454
28455 \layout Standard
28456
28457 It is also frequently required to obtain a higher order byte or word of
28458  a larger integral type (long, int or short types).
28459  SDCC recognizes the following expressions to yield the higher order byte
28460  or word and generates optimized code for it, e.g.:
28461 \layout Verse
28462
28463
28464 \family typewriter 
28465 unsigned int gint; 
28466 \newline 
28467 unsigned long int glong; 
28468 \newline 
28469
28470 \newline 
28471 foo () { 
28472 \newline 
28473 \SpecialChar ~
28474 \SpecialChar ~
28475 unsigned char hob1, hob2; 
28476 \newline 
28477 \SpecialChar ~
28478 \SpecialChar ~
28479 unsigned int how1, how2; 
28480 \newline 
28481 \SpecialChar ~
28482 \SpecialChar ~
28483 ...
28484  
28485 \newline 
28486 \SpecialChar ~
28487 \SpecialChar ~
28488 hob1 = (gint >> 8) & 0xFF; 
28489 \newline 
28490 \SpecialChar ~
28491 \SpecialChar ~
28492 hob2 = glong >> 24; 
28493 \newline 
28494 \SpecialChar ~
28495 \SpecialChar ~
28496 how1 = (glong >> 16) & 0xFFFF; 
28497 \newline 
28498 \SpecialChar ~
28499 \SpecialChar ~
28500 how2 = glong >> 8; 
28501 \newline 
28502 \SpecialChar ~
28503 \SpecialChar ~
28504 ..
28505  
28506 \newline 
28507 }
28508 \layout Standard
28509
28510 will generate the following code:
28511 \layout Verse
28512
28513
28514 \family typewriter 
28515 \SpecialChar ~
28516 \SpecialChar ~
28517 \SpecialChar ~
28518 \SpecialChar ~
28519 \SpecialChar ~
28520 \SpecialChar ~
28521 \SpecialChar ~
28522 \SpecialChar ~
28523 \SpecialChar ~
28524 \SpecialChar ~
28525 \SpecialChar ~
28526 \SpecialChar ~
28527 \SpecialChar ~
28528 \SpecialChar ~
28529 \SpecialChar ~
28530 \SpecialChar ~
28531 \SpecialChar ~
28532 \SpecialChar ~
28533 \SpecialChar ~
28534 \SpecialChar ~
28535 \SpecialChar ~
28536 \SpecialChar ~
28537 \SpecialChar ~
28538 \SpecialChar ~
28539 \SpecialChar ~
28540  91 ;\SpecialChar ~
28541  hob.c 15 
28542 \newline 
28543 0037 85*01*06\SpecialChar ~
28544 \SpecialChar ~
28545 \SpecialChar ~
28546 \SpecialChar ~
28547 \SpecialChar ~
28548 \SpecialChar ~
28549 \SpecialChar ~
28550 \SpecialChar ~
28551 \SpecialChar ~
28552 \SpecialChar ~
28553 \SpecialChar ~
28554 \SpecialChar ~
28555  92\SpecialChar ~
28556 \SpecialChar ~
28557 \SpecialChar ~
28558 \SpecialChar ~
28559 \SpecialChar ~
28560 \SpecialChar ~
28561 \SpecialChar ~
28562 \SpecialChar ~
28563  mov\SpecialChar ~
28564 \SpecialChar ~
28565  _foo_hob1_1_1,(_gint + 1) 
28566 \newline 
28567 \SpecialChar ~
28568 \SpecialChar ~
28569 \SpecialChar ~
28570 \SpecialChar ~
28571 \SpecialChar ~
28572 \SpecialChar ~
28573 \SpecialChar ~
28574 \SpecialChar ~
28575 \SpecialChar ~
28576 \SpecialChar ~
28577 \SpecialChar ~
28578 \SpecialChar ~
28579 \SpecialChar ~
28580 \SpecialChar ~
28581 \SpecialChar ~
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 \SpecialChar ~
28585 \SpecialChar ~
28586 \SpecialChar ~
28587 \SpecialChar ~
28588 \SpecialChar ~
28589 \SpecialChar ~
28590 \SpecialChar ~
28591 \SpecialChar ~
28592  93 ;\SpecialChar ~
28593  hob.c 16 
28594 \newline 
28595 003A 85*05*07\SpecialChar ~
28596 \SpecialChar ~
28597 \SpecialChar ~
28598 \SpecialChar ~
28599 \SpecialChar ~
28600 \SpecialChar ~
28601 \SpecialChar ~
28602 \SpecialChar ~
28603 \SpecialChar ~
28604 \SpecialChar ~
28605 \SpecialChar ~
28606 \SpecialChar ~
28607  94\SpecialChar ~
28608 \SpecialChar ~
28609 \SpecialChar ~
28610 \SpecialChar ~
28611 \SpecialChar ~
28612 \SpecialChar ~
28613 \SpecialChar ~
28614 \SpecialChar ~
28615  mov\SpecialChar ~
28616 \SpecialChar ~
28617  _foo_hob2_1_1,(_glong + 3) 
28618 \newline 
28619 \SpecialChar ~
28620 \SpecialChar ~
28621 \SpecialChar ~
28622 \SpecialChar ~
28623 \SpecialChar ~
28624 \SpecialChar ~
28625 \SpecialChar ~
28626 \SpecialChar ~
28627 \SpecialChar ~
28628 \SpecialChar ~
28629 \SpecialChar ~
28630 \SpecialChar ~
28631 \SpecialChar ~
28632 \SpecialChar ~
28633 \SpecialChar ~
28634 \SpecialChar ~
28635 \SpecialChar ~
28636 \SpecialChar ~
28637 \SpecialChar ~
28638 \SpecialChar ~
28639 \SpecialChar ~
28640 \SpecialChar ~
28641 \SpecialChar ~
28642 \SpecialChar ~
28643 \SpecialChar ~
28644  95 ;\SpecialChar ~
28645  hob.c 17 
28646 \newline 
28647 003D 85*04*08\SpecialChar ~
28648 \SpecialChar ~
28649 \SpecialChar ~
28650 \SpecialChar ~
28651 \SpecialChar ~
28652 \SpecialChar ~
28653 \SpecialChar ~
28654 \SpecialChar ~
28655 \SpecialChar ~
28656 \SpecialChar ~
28657 \SpecialChar ~
28658 \SpecialChar ~
28659  96\SpecialChar ~
28660 \SpecialChar ~
28661 \SpecialChar ~
28662 \SpecialChar ~
28663 \SpecialChar ~
28664 \SpecialChar ~
28665 \SpecialChar ~
28666 \SpecialChar ~
28667  mov\SpecialChar ~
28668 \SpecialChar ~
28669  _foo_how1_1_1,(_glong + 2) 
28670 \newline 
28671 0040 85*05*09\SpecialChar ~
28672 \SpecialChar ~
28673 \SpecialChar ~
28674 \SpecialChar ~
28675 \SpecialChar ~
28676 \SpecialChar ~
28677 \SpecialChar ~
28678 \SpecialChar ~
28679 \SpecialChar ~
28680 \SpecialChar ~
28681 \SpecialChar ~
28682 \SpecialChar ~
28683  97\SpecialChar ~
28684 \SpecialChar ~
28685 \SpecialChar ~
28686 \SpecialChar ~
28687 \SpecialChar ~
28688 \SpecialChar ~
28689 \SpecialChar ~
28690 \SpecialChar ~
28691  mov\SpecialChar ~
28692 \SpecialChar ~
28693  (_foo_how1_1_1 + 1),(_glong + 3) 
28694 \newline 
28695 0043 85*03*0A\SpecialChar ~
28696 \SpecialChar ~
28697 \SpecialChar ~
28698 \SpecialChar ~
28699 \SpecialChar ~
28700 \SpecialChar ~
28701 \SpecialChar ~
28702 \SpecialChar ~
28703 \SpecialChar ~
28704 \SpecialChar ~
28705 \SpecialChar ~
28706 \SpecialChar ~
28707  98\SpecialChar ~
28708 \SpecialChar ~
28709 \SpecialChar ~
28710 \SpecialChar ~
28711 \SpecialChar ~
28712 \SpecialChar ~
28713 \SpecialChar ~
28714 \SpecialChar ~
28715  mov\SpecialChar ~
28716 \SpecialChar ~
28717  _foo_how2_1_1,(_glong + 1) 
28718 \newline 
28719 0046 85*04*0B\SpecialChar ~
28720 \SpecialChar ~
28721 \SpecialChar ~
28722 \SpecialChar ~
28723 \SpecialChar ~
28724 \SpecialChar ~
28725 \SpecialChar ~
28726 \SpecialChar ~
28727 \SpecialChar ~
28728 \SpecialChar ~
28729 \SpecialChar ~
28730 \SpecialChar ~
28731  99\SpecialChar ~
28732 \SpecialChar ~
28733 \SpecialChar ~
28734 \SpecialChar ~
28735 \SpecialChar ~
28736 \SpecialChar ~
28737 \SpecialChar ~
28738 \SpecialChar ~
28739  mov\SpecialChar ~
28740 \SpecialChar ~
28741  (_foo_how2_1_1 + 1),(_glong + 2) 
28742 \layout Standard
28743
28744 Again, variations of these cases may 
28745 \emph on 
28746 not
28747 \emph default 
28748  be recognized.
28749  They are standard C expressions, so I heartily recommend these be the only
28750  way to get the higher order byte/word, (it is portable).
28751  Of course it will be recognized even if it is embedded in other expressions,
28752  e.g.:
28753 \layout Verse
28754
28755
28756 \family typewriter 
28757 xyz = gint + ((gint >> 8) & 0xFF);
28758 \layout Standard
28759
28760 will still be recognized.
28761 \layout Subsection
28762
28763 Peephole Optimizer
28764 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
28765
28766 \end_inset 
28767
28768
28769 \begin_inset LatexCommand \index{Peephole optimizer}
28770
28771 \end_inset 
28772
28773
28774 \layout Standard
28775
28776 The compiler uses a rule based, pattern matching and re-writing mechanism
28777  for peep-hole optimization.
28778  It is inspired by 
28779 \emph on 
28780 copt
28781 \emph default 
28782  a peep-hole optimizer by Christopher W.
28783  Fraser (cwfraser\SpecialChar ~
28784 @\SpecialChar ~
28785 microsoft.com).
28786  A default set of rules are compiled into the compiler, additional rules
28787  may be added with the 
28788 \emph on 
28789 -
28790 \begin_inset ERT
28791 status Collapsed
28792
28793 \layout Standard
28794
28795 \backslash 
28796 /
28797 \end_inset 
28798
28799 -peep-file
28800 \begin_inset LatexCommand \index{-\/-peep-file}
28801
28802 \end_inset 
28803
28804  <filename>
28805 \emph default 
28806  option.
28807  The rule language is best illustrated with examples.
28808 \layout Verse
28809
28810
28811 \family typewriter 
28812 replace { 
28813 \newline 
28814 \SpecialChar ~
28815 \SpecialChar ~
28816 mov %1,a 
28817 \newline 
28818 \SpecialChar ~
28819 \SpecialChar ~
28820 mov a,%1
28821 \newline 
28822 } by {
28823 \newline 
28824 \SpecialChar ~
28825 \SpecialChar ~
28826 mov %1,a
28827 \newline 
28828 }
28829 \layout Standard
28830
28831 The above rule will change the following assembly
28832 \begin_inset LatexCommand \index{Assembler routines}
28833
28834 \end_inset 
28835
28836  sequence:
28837 \layout Verse
28838
28839
28840 \family typewriter 
28841 mov r1,a 
28842 \newline 
28843 mov a,r1
28844 \layout Standard
28845
28846 to
28847 \layout Verse
28848
28849
28850 \family typewriter 
28851 mov r1,a
28852 \layout Standard
28853
28854 Note: All occurrences of a 
28855 \emph on 
28856 %n
28857 \emph default 
28858  (pattern variable) must denote the same string.
28859  With the above rule, the assembly sequence:
28860 \layout Verse
28861
28862
28863 \family typewriter 
28864 mov r1,a 
28865 \newline 
28866 mov a,r2
28867 \layout Standard
28868
28869 will remain unmodified.
28870 \newline 
28871
28872 \newline 
28873 Other special case optimizations may be added by the user (via 
28874 \emph on 
28875 -
28876 \begin_inset ERT
28877 status Collapsed
28878
28879 \layout Standard
28880
28881 \backslash 
28882 /
28883 \end_inset 
28884
28885 -peep-file option
28886 \emph default 
28887 ).
28888  E.g.
28889  some variants of the 8051 MCU
28890 \begin_inset LatexCommand \index{MCS51 variants}
28891
28892 \end_inset 
28893
28894  allow only 
28895 \family typewriter 
28896 ajmp
28897 \family default 
28898  and 
28899 \family typewriter 
28900 acall
28901 \family default 
28902 .
28903  The following two rules will change all 
28904 \family typewriter 
28905 ljmp
28906 \family default 
28907  and 
28908 \family typewriter 
28909 lcall
28910 \family default 
28911  to 
28912 \family typewriter 
28913 ajmp
28914 \family default 
28915  and 
28916 \family typewriter 
28917 acall
28918 \layout Verse
28919
28920
28921 \family typewriter 
28922 replace { lcall %1 } by { acall %1 } 
28923 \newline 
28924 replace { ljmp %1 } by { ajmp %1 }
28925 \layout Standard
28926
28927 The 
28928 \emph on 
28929 inline-assembler code
28930 \emph default 
28931  is also passed through the peep hole optimizer, thus the peephole optimizer
28932  can also be used as an assembly level macro expander.
28933  The rules themselves are MCU dependent whereas the rule language infra-structur
28934 e is MCU independent.
28935  Peephole optimization rules for other MCU can be easily programmed using
28936  the rule language.
28937 \newline 
28938
28939 \newline 
28940 The syntax for a rule is as follows:
28941 \layout Verse
28942
28943
28944 \family typewriter 
28945 rule := replace [ restart ] '{' <assembly sequence> '
28946 \backslash 
28947 n' 
28948 \newline 
28949 \SpecialChar ~
28950  \SpecialChar ~
28951  \SpecialChar ~
28952  \SpecialChar ~
28953  \SpecialChar ~
28954  \SpecialChar ~
28955  \SpecialChar ~
28956  \SpecialChar ~
28957  \SpecialChar ~
28958  \SpecialChar ~
28959  \SpecialChar ~
28960  \SpecialChar ~
28961  \SpecialChar ~
28962  \SpecialChar ~
28963  '}' by '{' '
28964 \backslash 
28965 n' 
28966 \newline 
28967 \SpecialChar ~
28968  \SpecialChar ~
28969  \SpecialChar ~
28970  \SpecialChar ~
28971  \SpecialChar ~
28972  \SpecialChar ~
28973  \SpecialChar ~
28974  \SpecialChar ~
28975  \SpecialChar ~
28976  \SpecialChar ~
28977  \SpecialChar ~
28978  \SpecialChar ~
28979  \SpecialChar ~
28980  \SpecialChar ~
28981  \SpecialChar ~
28982  \SpecialChar ~
28983  <assembly sequence> '
28984 \backslash 
28985 n' 
28986 \newline 
28987 \SpecialChar ~
28988  \SpecialChar ~
28989  \SpecialChar ~
28990  \SpecialChar ~
28991  \SpecialChar ~
28992  \SpecialChar ~
28993  \SpecialChar ~
28994  \SpecialChar ~
28995  \SpecialChar ~
28996  \SpecialChar ~
28997  \SpecialChar ~
28998  \SpecialChar ~
28999  \SpecialChar ~
29000  \SpecialChar ~
29001  '}' [if <functionName> ] '
29002 \backslash 
29003 n' 
29004 \layout Standard
29005
29006 <assembly sequence> := assembly instruction (each instruction including
29007  labels must be on a separate line).
29008 \newline 
29009
29010 \newline 
29011 The optimizer will apply to the rules one by one from the top in the sequence
29012  of their appearance, it will terminate when all rules are exhausted.
29013  If the 'restart' option is specified, then the optimizer will start matching
29014  the rules again from the top, this option for a rule is expensive (performance)
29015 , it is intended to be used in situations where a transformation will trigger
29016  the same rule again.
29017  An example of this (not a good one, it has side effects) is the following
29018  rule:
29019 \layout Verse
29020
29021
29022 \family typewriter 
29023 replace restart { 
29024 \newline 
29025 \SpecialChar ~
29026 \SpecialChar ~
29027 pop %1 
29028 \newline 
29029 \SpecialChar ~
29030 \SpecialChar ~
29031 push %1 } by { 
29032 \newline 
29033 \SpecialChar ~
29034 \SpecialChar ~
29035 ; nop 
29036 \newline 
29037 }
29038 \layout Standard
29039
29040 Note that the replace pattern cannot be a blank, but can be a comment line.
29041  Without the 'restart' option only the innermost 'pop' 'push' pair would
29042  be eliminated, i.e.:
29043 \layout Verse
29044
29045
29046 \family typewriter 
29047 pop ar1 
29048 \newline 
29049 pop ar2 
29050 \newline 
29051 push ar2 
29052 \newline 
29053 push ar1
29054 \layout Standard
29055
29056 would result in:
29057 \layout Verse
29058
29059
29060 \family typewriter 
29061 pop ar1 
29062 \newline 
29063 ; nop 
29064 \newline 
29065 push ar1
29066 \layout Standard
29067
29068
29069 \emph on 
29070 with
29071 \emph default 
29072  the restart option the rule will be applied again to the resulting code
29073  and then all the pop-push pairs will be eliminated to yield:
29074 \layout Verse
29075
29076
29077 \family typewriter 
29078 ; nop 
29079 \newline 
29080 ; nop
29081 \layout Standard
29082
29083 A conditional function can be attached to a rule.
29084  Attaching rules are somewhat more involved, let me illustrate this with
29085  an example.
29086 \layout Verse
29087
29088
29089 \family typewriter 
29090 replace { 
29091 \newline 
29092 \SpecialChar ~
29093  \SpecialChar ~
29094  \SpecialChar ~
29095 ljmp %5 
29096 \newline 
29097 %2:
29098 \newline 
29099 } by { 
29100 \newline 
29101 \SpecialChar ~
29102  \SpecialChar ~
29103  \SpecialChar ~
29104 sjmp %5 
29105 \newline 
29106 %2:
29107 \newline 
29108 } if labelInRange
29109 \layout Standard
29110
29111 The optimizer does a look-up of a function name table defined in function
29112  
29113 \emph on 
29114 callFuncByName
29115 \emph default 
29116  in the source file SDCCpeeph.c, with the name 
29117 \emph on 
29118 labelInRange
29119 \emph default 
29120 .
29121  If it finds a corresponding entry the function is called.
29122  Note there can be no parameters specified for these functions, in this
29123  case the use of 
29124 \emph on 
29125 %5
29126 \emph default 
29127  is crucial, since the function 
29128 \emph on 
29129 labelInRange
29130 \emph default 
29131  expects to find the label in that particular variable (the hash table containin
29132 g the variable bindings is passed as a parameter).
29133  If you want to code more such functions, take a close look at the function
29134  labelInRange and the calling mechanism in source file SDCCpeeph.c.
29135  Currently implemented are 
29136 \emph on 
29137 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
29138  24bitMode, portIsDS390, 24bitModeAndPortDS390 
29139 \emph default 
29140 and
29141 \emph on 
29142  notVolatile
29143 \emph default 
29144 .
29145 \layout Standard
29146
29147 I know this whole thing is a little kludgey, but maybe some day we will
29148  have some better means.
29149  If you are looking at this file, you will see the default rules that are
29150  compiled into the compiler, you can add your own rules in the default set
29151  there if you get tired of specifying the -
29152 \begin_inset ERT
29153 status Collapsed
29154
29155 \layout Standard
29156
29157 \backslash 
29158 /
29159 \end_inset 
29160
29161 -peep-file option.
29162 \layout Section
29163
29164 ANSI-Compliance
29165 \begin_inset LatexCommand \index{ANSI-compliance}
29166
29167 \end_inset 
29168
29169
29170 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
29171
29172 \end_inset 
29173
29174
29175 \layout Standard
29176
29177 The latest publically available version of the standard 
29178 \emph on 
29179 ISO/IEC 9899 - Programming languages - C
29180 \emph default 
29181  should be available at: 
29182 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29183
29184 \end_inset 
29185
29186 .
29187 \newline 
29188
29189 \layout Standard
29190
29191 Deviations from the compliance:
29192 \layout Itemize
29193
29194 functions are not reentrant
29195 \begin_inset LatexCommand \index{reentrant}
29196
29197 \end_inset 
29198
29199  unless explicitly declared as such or the 
29200 \series bold 
29201 -
29202 \begin_inset ERT
29203 status Collapsed
29204
29205 \layout Standard
29206
29207 \backslash 
29208 /
29209 \end_inset 
29210
29211 -stack-auto
29212 \begin_inset LatexCommand \index{-\/-stack-auto}
29213
29214 \end_inset 
29215
29216
29217 \series default 
29218  command line option is specified.
29219 \layout Itemize
29220
29221 structures
29222 \begin_inset LatexCommand \index{struct}
29223
29224 \end_inset 
29225
29226  and unions
29227 \begin_inset LatexCommand \index{union}
29228
29229 \end_inset 
29230
29231  cannot be assigned values directly, cannot be passed as function parameters
29232  or assigned to each other and cannot be a return value
29233 \begin_inset LatexCommand \index{return value}
29234
29235 \end_inset 
29236
29237  from a function, e.g.:
29238 \begin_deeper 
29239 \layout Verse
29240
29241
29242 \family typewriter 
29243 struct s { ...
29244  }; 
29245 \newline 
29246 struct s s1, s2; 
29247 \newline 
29248 foo() 
29249 \newline 
29250
29251 \newline 
29252 \SpecialChar ~
29253 \SpecialChar ~
29254 \SpecialChar ~
29255 \SpecialChar ~
29256 ...
29257  
29258 \newline 
29259 \SpecialChar ~
29260 \SpecialChar ~
29261 \SpecialChar ~
29262 \SpecialChar ~
29263 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
29264 \newline 
29265 \SpecialChar ~
29266 \SpecialChar ~
29267 \SpecialChar ~
29268 \SpecialChar ~
29269 ...
29270  
29271 \newline 
29272 }
29273 \newline 
29274
29275 \series bold 
29276 struct
29277 \series default 
29278  s foo1 (
29279 \series bold 
29280 struct
29281 \series default 
29282  s parms) /* invalid in SDCC although allowed in ANSI */
29283 \newline 
29284
29285 \newline 
29286 \SpecialChar ~
29287 \SpecialChar ~
29288 \SpecialChar ~
29289 \SpecialChar ~
29290 struct s rets; 
29291 \newline 
29292 \SpecialChar ~
29293 \SpecialChar ~
29294 \SpecialChar ~
29295 \SpecialChar ~
29296 ...
29297  
29298 \newline 
29299 \SpecialChar ~
29300 \SpecialChar ~
29301 \SpecialChar ~
29302 \SpecialChar ~
29303 return rets; /* is invalid in SDCC although allowed in ANSI */ 
29304 \newline 
29305 }
29306 \end_deeper 
29307 \layout Itemize
29308
29309 initialization of structure arrays must be fully braced.
29310 \begin_deeper 
29311 \layout Verse
29312
29313
29314 \family typewriter 
29315 struct s { char x } a[] = {1, 2};\SpecialChar ~
29316 \SpecialChar ~
29317 \SpecialChar ~
29318 \SpecialChar ~
29319 \SpecialChar ~
29320 /* invalid in SDCC */
29321 \newline 
29322 struct s { char x } a[] = {{1}, {2}}; /* OK */
29323 \end_deeper 
29324 \layout Itemize
29325
29326 'long long
29327 \begin_inset LatexCommand \index{long long (not supported)}
29328
29329 \end_inset 
29330
29331 ' (64 bit integers
29332 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29333
29334 \end_inset 
29335
29336 ) not supported.
29337 \layout Itemize
29338
29339 'double
29340 \begin_inset LatexCommand \index{double (not supported)}
29341
29342 \end_inset 
29343
29344 ' precision floating point 
29345 \begin_inset LatexCommand \index{Floating point support}
29346
29347 \end_inset 
29348
29349 not supported.
29350 \layout Itemize
29351
29352 Old K&R style
29353 \begin_inset LatexCommand \index{K\&R style}
29354
29355 \end_inset 
29356
29357  function declarations are NOT allowed.
29358 \begin_deeper 
29359 \layout Verse
29360
29361
29362 \family typewriter 
29363 foo(i,j) /* this old style of function declarations */ 
29364 \newline 
29365 int i,j; /* are valid in ANSI but not valid in SDCC */ 
29366 \newline 
29367
29368 \newline 
29369 \SpecialChar ~
29370 \SpecialChar ~
29371 \SpecialChar ~
29372 \SpecialChar ~
29373 ...
29374  
29375 \newline 
29376 }
29377 \end_deeper 
29378 \layout Itemize
29379
29380 Most enhancements in C99 are not supported, f.e.:
29381 \begin_deeper 
29382 \layout Verse
29383
29384
29385 \family typewriter 
29386 \series bold 
29387 inline
29388 \begin_inset LatexCommand \index{inline (not supported)}
29389
29390 \end_inset 
29391
29392
29393 \series default 
29394  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29395  in C99.
29396  An empty define 
29397 \emph on 
29398 #define inline
29399 \emph default 
29400  can be used as a work around */
29401 \newline 
29402
29403 \newline 
29404 for (
29405 \series bold 
29406 int
29407 \series default 
29408  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29409 \end_deeper 
29410 \layout Itemize
29411
29412 Certain words that are valid identifiers in the standard may be reserved
29413  words in SDCC unless the 
29414 \series bold 
29415 -
29416 \begin_inset ERT
29417 status Collapsed
29418
29419 \layout Standard
29420
29421 \backslash 
29422 /
29423 \end_inset 
29424
29425 -std-c89
29426 \begin_inset LatexCommand \index{-\/-std-c89}
29427
29428 \end_inset 
29429
29430  or -
29431 \begin_inset ERT
29432 status Collapsed
29433
29434 \layout Standard
29435
29436 \backslash 
29437 /
29438 \end_inset 
29439
29440 -std-c99
29441 \begin_inset LatexCommand \index{-\/-std-c99}
29442
29443 \end_inset 
29444
29445
29446 \series default 
29447  command line options are used.
29448  These may include (depending on the selected processor): 'at', 'banked',
29449  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29450 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29451  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29452  '_naked'.
29453  Compliant equivalents of these keywords are always available in a form
29454  that begin with two underscores
29455 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29456
29457 \end_inset 
29458
29459 , f.e.
29460  '__data' instead of 'data'.
29461 \layout Section
29462
29463 Cyclomatic Complexity
29464 \begin_inset LatexCommand \index{Cyclomatic complexity}
29465
29466 \end_inset 
29467
29468
29469 \layout Standard
29470
29471 Cyclomatic complexity of a function is defined as the number of independent
29472  paths the program can take during execution of the function.
29473  This is an important number since it defines the number test cases you
29474  have to generate to validate the function.
29475  The accepted industry standard for complexity number is 10, if the cyclomatic
29476  complexity reported by SDCC exceeds 10 you should think about simplification
29477  of the function logic.
29478  Note that the complexity level is not related to the number of lines of
29479  code in a function.
29480  Large functions can have low complexity, and small functions can have large
29481  complexity levels.
29482  
29483 \newline 
29484
29485 \newline 
29486 SDCC uses the following formula to compute the complexity:
29487 \newline 
29488
29489 \layout Standard
29490
29491 complexity = (number of edges in control flow graph) - (number of nodes
29492  in control flow graph) + 2;
29493 \newline 
29494
29495 \newline 
29496 Having said that the industry standard is 10, you should be aware that in
29497  some cases it be may unavoidable to have a complexity level of less than
29498  10.
29499  For example if you have switch statement with more than 10 case labels,
29500  each case label adds one to the complexity level.
29501  The complexity level is by no means an absolute measure of the algorithmic
29502  complexity of the function, it does however provide a good starting point
29503  for which functions you might look at for further optimization.
29504 \layout Section
29505
29506 Retargetting for other Processors
29507 \layout Standard
29508
29509 The issues for retargetting the compiler are far too numerous to be covered
29510  by this document.
29511  What follows is a brief description of each of the seven phases of the
29512  compiler and its MCU dependency.
29513 \layout Itemize
29514
29515 Parsing the source and building the annotated parse tree.
29516  This phase is largely MCU independent (except for the language extensions).
29517  Syntax & semantic checks are also done in this phase, along with some initial
29518  optimizations like back patching labels and the pattern matching optimizations
29519  like bit-rotation etc.
29520 \layout Itemize
29521
29522 The second phase involves generating an intermediate code which can be easy
29523  manipulated during the later phases.
29524  This phase is entirely MCU independent.
29525  The intermediate code generation assumes the target machine has unlimited
29526  number of registers, and designates them with the name iTemp.
29527  The compiler can be made to dump a human readable form of the code generated
29528  by using the -
29529 \begin_inset ERT
29530 status Collapsed
29531
29532 \layout Standard
29533
29534 \backslash 
29535 /
29536 \end_inset 
29537
29538 -dumpraw option.
29539 \layout Itemize
29540
29541 This phase does the bulk of the standard optimizations and is also MCU independe
29542 nt.
29543  This phase can be broken down into several sub-phases:
29544 \newline 
29545
29546 \newline 
29547 Break down intermediate code (iCode) into basic blocks.
29548 \newline 
29549 Do control flow & data flow analysis on the basic blocks.
29550 \newline 
29551 Do local common subexpression elimination, then global subexpression elimination
29552 \newline 
29553 Dead code elimination
29554 \newline 
29555 Loop optimizations
29556 \newline 
29557 If loop optimizations caused any changes then do 'global subexpression eliminati
29558 on' and 'dead code elimination' again.
29559 \layout Itemize
29560
29561 This phase determines the live-ranges; by live range I mean those iTemp
29562  variables defined by the compiler that still survive after all the optimization
29563 s.
29564  Live range analysis
29565 \begin_inset LatexCommand \index{Live range analysis}
29566
29567 \end_inset 
29568
29569  is essential for register allocation, since these computation determines
29570  which of these iTemps will be assigned to registers, and for how long.
29571 \layout Itemize
29572
29573 Phase five is register allocation.
29574  There are two parts to this process.
29575 \newline 
29576
29577 \newline 
29578 The first part I call 'register packing' (for lack of a better term).
29579  In this case several MCU specific expression folding is done to reduce
29580  register pressure.
29581 \newline 
29582
29583 \newline 
29584 The second part is more MCU independent and deals with allocating registers
29585  to the remaining live ranges.
29586  A lot of MCU specific code does creep into this phase because of the limited
29587  number of index registers available in the 8051.
29588 \layout Itemize
29589
29590 The Code generation phase is (unhappily), entirely MCU dependent and very
29591  little (if any at all) of this code can be reused for other MCU.
29592  However the scheme for allocating a homogenized assembler operand for each
29593  iCode operand may be reused.
29594 \layout Itemize
29595
29596 As mentioned in the optimization section the peep-hole optimizer is rule
29597  based system, which can reprogrammed for other MCUs.
29598 \layout Chapter
29599
29600 Compiler internals
29601 \begin_inset LatexCommand \index{Compiler internals}
29602
29603 \end_inset 
29604
29605
29606 \layout Section
29607
29608 The anatomy of the compiler
29609 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29610
29611 \end_inset 
29612
29613
29614 \layout Standard
29615
29616
29617 \shape italic 
29618 This is an excerpt from an article published in Circuit Cellar Magazine
29619  in 
29620 \series bold 
29621 August 2000
29622 \series default 
29623 .
29624  It's a little outdated (the compiler is much more efficient now and user/develo
29625 per friendly), but pretty well exposes the guts of it all.
29626 \shape default 
29627
29628 \newline 
29629
29630 \newline 
29631 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
29632  It is fairly easy to retarget for other 8-bit MCU.
29633  Here we take a look at some of the internals of the compiler.
29634  
29635 \layout Paragraph*
29636
29637 Parsing
29638 \begin_inset LatexCommand \index{Parsing}
29639
29640 \end_inset 
29641
29642  
29643 \layout Standard
29644
29645 Parsing the input source file and creating an AST (Annotated Syntax Tree
29646 \begin_inset LatexCommand \index{Annotated syntax tree}
29647
29648 \end_inset 
29649
29650 ).
29651  This phase also involves propagating types (annotating each node of the
29652  parse tree with type information) and semantic analysis.
29653  There are some MCU specific parsing rules.
29654  For example the storage classes, the extended storage classes are MCU specific
29655  while there may be a xdata storage class for 8051 there is no such storage
29656  class for z80 or Atmel AVR.
29657  SDCC allows MCU specific storage class extensions, i.e.
29658  xdata will be treated as a storage class specifier when parsing 8051 C
29659  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
29660  C code.
29661 \layout Paragraph*
29662
29663 Generating iCode
29664 \begin_inset LatexCommand \index{iCode}
29665
29666 \end_inset 
29667
29668
29669 \layout Standard
29670
29671 Intermediate code generation.
29672  In this phase the AST is broken down into three-operand form (iCode).
29673  These three operand forms are represented as doubly linked lists.
29674  ICode is the term given to the intermediate form generated by the compiler.
29675  ICode example section shows some examples of iCode generated for some simple
29676  C source functions.
29677 \layout Paragraph*
29678
29679 Optimizations
29680 \begin_inset LatexCommand \index{Optimizations}
29681
29682 \end_inset 
29683
29684 .
29685 \layout Standard
29686
29687 Bulk of the target independent optimizations is performed in this phase.
29688  The optimizations include constant propagation, common sub-expression eliminati
29689 on, loop invariant code movement, strength reduction of loop induction variables
29690  and dead-code elimination.
29691 \layout Paragraph*
29692
29693 Live range analysis
29694 \begin_inset LatexCommand \index{Live range analysis}
29695
29696 \end_inset 
29697
29698
29699 \layout Standard
29700
29701 During intermediate code generation phase, the compiler assumes the target
29702  machine has infinite number of registers and generates a lot of temporary
29703  variables.
29704  The live range computation determines the lifetime of each of these compiler-ge
29705 nerated temporaries.
29706  A picture speaks a thousand words.
29707  ICode example sections show the live range annotations for each of the
29708  operand.
29709  It is important to note here, each iCode is assigned a number in the order
29710  of its execution in the function.
29711  The live ranges are computed in terms of these numbers.
29712  The from number is the number of the iCode which first defines the operand
29713  and the to number signifies the iCode which uses this operand last.
29714 \layout Paragraph*
29715
29716 Register Allocation
29717 \begin_inset LatexCommand \index{Register allocation}
29718
29719 \end_inset 
29720
29721
29722 \layout Standard
29723
29724 The register allocation determines the type and number of registers needed
29725  by each operand.
29726  In most MCUs only a few registers can be used for indirect addressing.
29727  In case of 8051 for example the registers R0 & R1 can be used to indirectly
29728  address the internal ram and DPTR to indirectly address the external ram.
29729  The compiler will try to allocate the appropriate register to pointer variables
29730  if it can.
29731  ICode example section shows the operands annotated with the registers assigned
29732  to them.
29733  The compiler will try to keep operands in registers as much as possible;
29734  there are several schemes the compiler uses to do achieve this.
29735  When the compiler runs out of registers the compiler will check to see
29736  if there are any live operands which is not used or defined in the current
29737  basic block being processed, if there are any found then it will push that
29738  operand and use the registers in this block, the operand will then be popped
29739  at the end of the basic block.
29740  
29741 \layout Standard
29742
29743 There are other MCU specific considerations in this phase.
29744  Some MCUs have an accumulator; very short-lived operands could be assigned
29745  to the accumulator instead of a general-purpose register.
29746 \layout Paragraph*
29747
29748 Code generation
29749 \layout Standard
29750
29751 Figure II gives a table of iCode operations supported by the compiler.
29752  The code generation involves translating these operations into corresponding
29753  assembly code for the processor.
29754  This sounds overly simple but that is the essence of code generation.
29755  Some of the iCode operations are generated on a MCU specific manner for
29756  example, the z80 port does not use registers to pass parameters so the
29757  SEND and RECV iCode operations will not be generated, and it also does
29758  not support JUMPTABLES.
29759  
29760 \newline 
29761
29762 \series bold 
29763 \shape italic 
29764 \color red
29765 <Where is Figure II?>
29766 \layout Comment
29767
29768 In the original article Figure II was announced to be downloadable on 
29769 \shape italic 
29770 Circuit Cellar
29771 \shape default 
29772 's web site.
29773  Unfortunately it never seemed to have shown up there, so: where is Figure
29774  II?
29775 \layout Paragraph*
29776
29777 ICode Example
29778 \begin_inset LatexCommand \index{iCode}
29779
29780 \end_inset 
29781
29782
29783 \layout Standard
29784
29785 This section shows some details of iCode.
29786  The example C code does not do anything useful; it is used as an example
29787  to illustrate the intermediate code generated by the compiler.
29788 \layout Verse
29789
29790
29791 \family typewriter 
29792 1.\SpecialChar ~
29793 xdata int * p;
29794 \newline 
29795 2.\SpecialChar ~
29796 int gint;
29797 \newline 
29798 3.\SpecialChar ~
29799 /* This function does nothing useful.
29800  It is used
29801 \newline 
29802 4.\SpecialChar ~
29803 \SpecialChar ~
29804 \SpecialChar ~
29805 \SpecialChar ~
29806 for the purpose of explaining iCode */
29807 \newline 
29808 5.\SpecialChar ~
29809 short function (data int *x)
29810 \newline 
29811 6.\SpecialChar ~
29812 {
29813 \newline 
29814 7.\SpecialChar ~
29815 \SpecialChar ~
29816 \SpecialChar ~
29817 short i=10; \SpecialChar ~
29818 \SpecialChar ~
29819 /* dead initialization eliminated */
29820 \newline 
29821 8.\SpecialChar ~
29822 \SpecialChar ~
29823 \SpecialChar ~
29824 short sum=10; /* dead initialization eliminated */
29825 \newline 
29826 9.\SpecialChar ~
29827 \SpecialChar ~
29828 \SpecialChar ~
29829 short mul;
29830 \newline 
29831 10.\SpecialChar ~
29832 \SpecialChar ~
29833 int j ;
29834 \newline 
29835 11.\SpecialChar ~
29836 \SpecialChar ~
29837 while (*x) *x++ = *p++; 
29838 \newline 
29839 12.\SpecialChar ~
29840 \SpecialChar ~
29841 \SpecialChar ~
29842 \SpecialChar ~
29843 sum = 0 ; 
29844 \newline 
29845 13.\SpecialChar ~
29846 \SpecialChar ~
29847 mul = 0;
29848 \newline 
29849 14.\SpecialChar ~
29850 \SpecialChar ~
29851 /* compiler detects i,j to be induction variables */
29852 \newline 
29853 15.\SpecialChar ~
29854 \SpecialChar ~
29855 for (i = 0, j = 10 ; i < 10 ; i++, j
29856 \family default 
29857 -
29858 \begin_inset ERT
29859 status Collapsed
29860
29861 \layout Standard
29862
29863 \backslash 
29864 /
29865 \end_inset 
29866
29867 -
29868 \family typewriter 
29869 ) {
29870 \newline 
29871 16.\SpecialChar ~
29872 \SpecialChar ~
29873 \SpecialChar ~
29874 \SpecialChar ~
29875 sum += i;
29876 \newline 
29877 17.\SpecialChar ~
29878 \SpecialChar ~
29879 \SpecialChar ~
29880 \SpecialChar ~
29881 mul += i * 3; \SpecialChar ~
29882 \SpecialChar ~
29883 /* this multiplication remains */
29884 \newline 
29885 18.\SpecialChar ~
29886 \SpecialChar ~
29887 \SpecialChar ~
29888 \SpecialChar ~
29889 gint += j * 3;\SpecialChar ~
29890 \SpecialChar ~
29891 /* this multiplication changed to addition */
29892 \newline 
29893 19.\SpecialChar ~
29894 \SpecialChar ~
29895 }
29896 \newline 
29897 20.\SpecialChar ~
29898 \SpecialChar ~
29899 return sum+mul;
29900 \newline 
29901 21.\SpecialChar ~
29902 }
29903 \layout Standard
29904
29905 In addition to the operands each iCode contains information about the filename
29906  and line it corresponds to in the source file.
29907  The first field in the listing should be interpreted as follows:
29908 \newline 
29909
29910 \shape italic 
29911 \size footnotesize 
29912 Filename(linenumber: iCode Execution sequence number : ICode hash table
29913  key : loop depth of the iCode).
29914 \shape default 
29915 \size default 
29916
29917 \newline 
29918 Then follows the human readable form of the ICode operation.
29919  Each operand of this triplet form can be of three basic types a) compiler
29920  generated temporary b) user defined variable c) a constant value.
29921  Note that local variables and parameters are replaced by compiler generated
29922  temporaries.
29923  Live ranges
29924 \begin_inset LatexCommand \index{Live range analysis}
29925
29926 \end_inset 
29927
29928  are computed only for temporaries (i.e.
29929  live ranges are not computed for global variables).
29930  Registers
29931 \begin_inset LatexCommand \index{Register allocation}
29932
29933 \end_inset 
29934
29935  are allocated for temporaries only.
29936  Operands are formatted in the following manner:
29937 \newline 
29938
29939 \shape italic 
29940 \size footnotesize 
29941 Operand Name [lr live-from : live-to ] { type information } [ registers
29942  allocated ].
29943 \shape default 
29944 \size default 
29945
29946 \newline 
29947 As mentioned earlier the live ranges are computed in terms of the execution
29948  sequence number of the iCodes, for example 
29949 \newline 
29950 the iTemp0 is live from (i.e.
29951  first defined in iCode with execution sequence number 3, and is last used
29952  in the iCode with sequence number 5).
29953  For induction variables such as iTemp21 the live range computation extends
29954  the lifetime from the start to the end of the loop.
29955 \newline 
29956 The register allocator used the live range information to allocate registers,
29957  the same registers may be used for different temporaries if their live
29958  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
29959  iTemp17 since their live ranges do not overlap.
29960  In addition the allocator also takes into consideration the type and usage
29961  of a temporary, for example itemp6 is a pointer to near space and is used
29962  as to fetch data from (i.e.
29963  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
29964  Some short lived temporaries are allocated to special registers which have
29965  meaning to the code generator e.g.
29966  iTemp13 is allocated to a pseudo register CC which tells the back end that
29967  the temporary is used only for a conditional jump the code generation makes
29968  use of this information to optimize a compare and jump ICode.
29969 \newline 
29970 There are several loop optimizations
29971 \begin_inset LatexCommand \index{Loop optimization}
29972
29973 \end_inset 
29974
29975  performed by the compiler.
29976  It can detect induction variables iTemp21(i) and iTemp23(j).
29977  Also note the compiler does selective strength reduction
29978 \begin_inset LatexCommand \index{Strength reduction}
29979
29980 \end_inset 
29981
29982 , i.e.
29983  the multiplication of an induction variable in line 18 (gint = j * 3) is
29984  changed to addition, a new temporary iTemp17 is allocated and assigned
29985  a initial value, a constant 3 is then added for each iteration of the loop.
29986  The compiler does not change the multiplication
29987 \begin_inset LatexCommand \index{Multiplication}
29988
29989 \end_inset 
29990
29991  in line 17 however since the processor does support an 8 * 8 bit multiplication.
29992 \newline 
29993 Note the dead code elimination
29994 \begin_inset LatexCommand \index{Dead-code elimination}
29995
29996 \end_inset 
29997
29998  optimization eliminated the dead assignments in line 7 & 8 to I and sum
29999  respectively.
30000 \newline 
30001
30002 \layout Standard
30003
30004
30005 \size footnotesize 
30006 Sample.c (5:1:0:0) _entry($9) :
30007 \layout Standard
30008
30009
30010 \size footnotesize 
30011 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
30012 \layout Standard
30013
30014
30015 \size footnotesize 
30016 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
30017 \layout Standard
30018
30019
30020 \size footnotesize 
30021 Sample.c(11:4:53:0) preHeaderLbl0($11) :
30022 \layout Standard
30023
30024
30025 \size footnotesize 
30026 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
30027  * int}[r2]
30028 \layout Standard
30029
30030
30031 \size footnotesize 
30032 Sample.c(11:6:5:1) _whilecontinue_0($1) :
30033 \layout Standard
30034
30035
30036 \size footnotesize 
30037 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
30038  int}[r0]]
30039 \layout Standard
30040
30041
30042 \size footnotesize 
30043 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
30044 \layout Standard
30045
30046
30047 \size footnotesize 
30048 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
30049  * int}
30050 \layout Standard
30051
30052
30053 \size footnotesize 
30054 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
30055  {short}
30056 \layout Standard
30057
30058
30059 \size footnotesize 
30060 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
30061  * int}[DPTR]]
30062 \layout Standard
30063
30064
30065 \size footnotesize 
30066 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
30067 }[r2 r3]
30068 \layout Standard
30069
30070
30071 \size footnotesize 
30072 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
30073  * int}[r0] + 0x2 {short}
30074 \layout Standard
30075
30076
30077 \size footnotesize 
30078 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
30079 \layout Standard
30080
30081
30082 \size footnotesize 
30083 Sample.c(11:17:21:0)_whilebreak_0($3) :
30084 \layout Standard
30085
30086
30087 \size footnotesize 
30088 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
30089 \layout Standard
30090
30091
30092 \size footnotesize 
30093 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
30094 \layout Standard
30095
30096
30097 \size footnotesize 
30098 Sample.c(15:20:54:0)preHeaderLbl1($13) :
30099 \layout Standard
30100
30101
30102 \size footnotesize 
30103 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
30104 \layout Standard
30105
30106
30107 \size footnotesize 
30108 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
30109 \layout Standard
30110
30111
30112 \size footnotesize 
30113 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
30114 \layout Standard
30115
30116
30117 \size footnotesize 
30118 Sample.c(15:24:26:1)_forcond_0($4) :
30119 \layout Standard
30120
30121
30122 \size footnotesize 
30123 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
30124  < 0xa {short}
30125 \layout Standard
30126
30127
30128 \size footnotesize 
30129 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
30130 \layout Standard
30131
30132
30133 \size footnotesize 
30134 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
30135  + ITemp21 [lr21:38]{short}[r4]
30136 \layout Standard
30137
30138
30139 \size footnotesize 
30140 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
30141  * 0x3 {short}
30142 \layout Standard
30143
30144
30145 \size footnotesize 
30146 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
30147  + iTemp15 [lr29:30]{short}[r1]
30148 \layout Standard
30149
30150
30151 \size footnotesize 
30152 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
30153  r0]- 0x3 {short}
30154 \layout Standard
30155
30156
30157 \size footnotesize 
30158 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
30159 int}[r7 r0]
30160 \layout Standard
30161
30162
30163 \size footnotesize 
30164 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
30165  + 0x1 {short}
30166 \layout Standard
30167
30168
30169 \size footnotesize 
30170 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
30171  r6]- 0x1 {short}
30172 \layout Standard
30173
30174
30175 \size footnotesize 
30176 Sample.c(19:38:47:1) goto _forcond_0($4)
30177 \layout Standard
30178
30179
30180 \size footnotesize 
30181 Sample.c(19:39:48:0)_forbreak_0($7) :
30182 \layout Standard
30183
30184
30185 \size footnotesize 
30186 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
30187  + ITemp11 [lr19:40]{short}[r3]
30188 \layout Standard
30189
30190
30191 \size footnotesize 
30192 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
30193 \layout Standard
30194
30195
30196 \size footnotesize 
30197 Sample.c(20:42:51:0)_return($8) :
30198 \layout Standard
30199
30200
30201 \size footnotesize 
30202 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
30203 \size default 
30204
30205 \newline 
30206
30207 \newline 
30208 Finally the code generated for this function:
30209 \newline 
30210
30211 \layout Standard
30212
30213
30214 \size footnotesize 
30215 .area DSEG (DATA)
30216 \layout Standard
30217
30218
30219 \size footnotesize 
30220 _p::
30221 \layout Standard
30222
30223
30224 \size footnotesize 
30225 \SpecialChar ~
30226 \SpecialChar ~
30227 .ds 2
30228 \layout Standard
30229
30230
30231 \size footnotesize 
30232 _gint::
30233 \layout Standard
30234
30235
30236 \size footnotesize 
30237 \SpecialChar ~
30238 \SpecialChar ~
30239 .ds 2
30240 \layout Standard
30241
30242
30243 \size footnotesize 
30244 ; sample.c 5
30245 \layout Standard
30246
30247
30248 \size footnotesize 
30249 ; ----------------------------------------------
30250 \layout Standard
30251
30252
30253 \size footnotesize 
30254 ; function function
30255 \layout Standard
30256
30257
30258 \size footnotesize 
30259 ; ----------------------------------------------
30260 \layout Standard
30261
30262
30263 \size footnotesize 
30264 _function:
30265 \layout Standard
30266
30267
30268 \size footnotesize 
30269 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
30270 \layout Standard
30271
30272
30273 \size footnotesize 
30274 \SpecialChar ~
30275 \SpecialChar ~
30276 mov r2,dpl
30277 \layout Standard
30278
30279
30280 \size footnotesize 
30281 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
30282 \layout Standard
30283
30284
30285 \size footnotesize 
30286 \SpecialChar ~
30287 \SpecialChar ~
30288 mov ar0,r2
30289 \layout Standard
30290
30291
30292 \size footnotesize 
30293 ;_whilecontinue_0($1) :
30294 \layout Standard
30295
30296
30297 \size footnotesize 
30298 00101$:
30299 \layout Standard
30300
30301
30302 \size footnotesize 
30303 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
30304 \layout Standard
30305
30306
30307 \size footnotesize 
30308 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
30309 \layout Standard
30310
30311
30312 \size footnotesize 
30313 \SpecialChar ~
30314 \SpecialChar ~
30315 mov ar2,@r0
30316 \layout Standard
30317
30318
30319 \size footnotesize 
30320 \SpecialChar ~
30321 \SpecialChar ~
30322 inc r0
30323 \layout Standard
30324
30325
30326 \size footnotesize 
30327 \SpecialChar ~
30328 \SpecialChar ~
30329 mov ar3,@r0
30330 \layout Standard
30331
30332
30333 \size footnotesize 
30334 \SpecialChar ~
30335 \SpecialChar ~
30336 dec r0
30337 \layout Standard
30338
30339
30340 \size footnotesize 
30341 \SpecialChar ~
30342 \SpecialChar ~
30343 mov a,r2
30344 \layout Standard
30345
30346
30347 \size footnotesize 
30348 \SpecialChar ~
30349 \SpecialChar ~
30350 orl a,r3
30351 \layout Standard
30352
30353
30354 \size footnotesize 
30355 \SpecialChar ~
30356 \SpecialChar ~
30357 jz 00103$
30358 \layout Standard
30359
30360
30361 \size footnotesize 
30362 00114$:
30363 \layout Standard
30364
30365
30366 \size footnotesize 
30367 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
30368 \layout Standard
30369
30370
30371 \size footnotesize 
30372 \SpecialChar ~
30373 \SpecialChar ~
30374 mov dpl,_p
30375 \layout Standard
30376
30377
30378 \size footnotesize 
30379 \SpecialChar ~
30380 \SpecialChar ~
30381 mov dph,(_p + 1)
30382 \layout Standard
30383
30384
30385 \size footnotesize 
30386 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
30387 \layout Standard
30388
30389
30390 \size footnotesize 
30391 \SpecialChar ~
30392 \SpecialChar ~
30393 mov a,#0x02
30394 \layout Standard
30395
30396
30397 \size footnotesize 
30398 \SpecialChar ~
30399 \SpecialChar ~
30400 add a,_p
30401 \layout Standard
30402
30403
30404 \size footnotesize 
30405 \SpecialChar ~
30406 \SpecialChar ~
30407 mov _p,a
30408 \layout Standard
30409
30410
30411 \size footnotesize 
30412 \SpecialChar ~
30413 \SpecialChar ~
30414 clr a
30415 \layout Standard
30416
30417
30418 \size footnotesize 
30419 \SpecialChar ~
30420 \SpecialChar ~
30421 addc a,(_p + 1)
30422 \layout Standard
30423
30424
30425 \size footnotesize 
30426 \SpecialChar ~
30427 \SpecialChar ~
30428 mov (_p + 1),a
30429 \layout Standard
30430
30431
30432 \size footnotesize 
30433 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
30434 \layout Standard
30435
30436
30437 \size footnotesize 
30438 \SpecialChar ~
30439 \SpecialChar ~
30440 movx a,@dptr
30441 \layout Standard
30442
30443
30444 \size footnotesize 
30445 \SpecialChar ~
30446 \SpecialChar ~
30447 mov r2,a
30448 \layout Standard
30449
30450
30451 \size footnotesize 
30452 \SpecialChar ~
30453 \SpecialChar ~
30454 inc dptr
30455 \layout Standard
30456
30457
30458 \size footnotesize 
30459 \SpecialChar ~
30460 \SpecialChar ~
30461 movx a,@dptr
30462 \layout Standard
30463
30464
30465 \size footnotesize 
30466 \SpecialChar ~
30467 \SpecialChar ~
30468 mov r3,a
30469 \layout Standard
30470
30471
30472 \size footnotesize 
30473 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
30474 \layout Standard
30475
30476
30477 \size footnotesize 
30478 \SpecialChar ~
30479 \SpecialChar ~
30480 mov @r0,ar2
30481 \layout Standard
30482
30483
30484 \size footnotesize 
30485 \SpecialChar ~
30486 \SpecialChar ~
30487 inc r0
30488 \layout Standard
30489
30490
30491 \size footnotesize 
30492 \SpecialChar ~
30493 \SpecialChar ~
30494 mov @r0,ar3
30495 \layout Standard
30496
30497
30498 \size footnotesize 
30499 ; iTemp6 [lr5:16]{_near * int}[r0] = 
30500 \layout Standard
30501
30502
30503 \size footnotesize 
30504 ; iTemp6 [lr5:16]{_near * int}[r0] + 
30505 \layout Standard
30506
30507
30508 \size footnotesize 
30509 ; 0x2 {short}
30510 \layout Standard
30511
30512
30513 \size footnotesize 
30514 \SpecialChar ~
30515 \SpecialChar ~
30516 inc r0
30517 \layout Standard
30518
30519
30520 \size footnotesize 
30521 ; goto _whilecontinue_0($1)
30522 \layout Standard
30523
30524
30525 \size footnotesize 
30526 \SpecialChar ~
30527 \SpecialChar ~
30528 sjmp 00101$
30529 \layout Standard
30530
30531
30532 \size footnotesize 
30533 ; _whilebreak_0($3) :
30534 \layout Standard
30535
30536
30537 \size footnotesize 
30538 00103$:
30539 \layout Standard
30540
30541
30542 \size footnotesize 
30543 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
30544 \layout Standard
30545
30546
30547 \size footnotesize 
30548 \SpecialChar ~
30549 \SpecialChar ~
30550 mov r2,#0x00
30551 \layout Standard
30552
30553
30554 \size footnotesize 
30555 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
30556 \layout Standard
30557
30558
30559 \size footnotesize 
30560 \SpecialChar ~
30561 \SpecialChar ~
30562 mov r3,#0x00
30563 \layout Standard
30564
30565
30566 \size footnotesize 
30567 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
30568 \layout Standard
30569
30570
30571 \size footnotesize 
30572 \SpecialChar ~
30573 \SpecialChar ~
30574 mov r4,#0x00
30575 \layout Standard
30576
30577
30578 \size footnotesize 
30579 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
30580 \layout Standard
30581
30582
30583 \size footnotesize 
30584 \SpecialChar ~
30585 \SpecialChar ~
30586 mov r5,#0x0A
30587 \layout Standard
30588
30589
30590 \size footnotesize 
30591 \SpecialChar ~
30592 \SpecialChar ~
30593 mov r6,#0x00
30594 \layout Standard
30595
30596
30597 \size footnotesize 
30598 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
30599 \layout Standard
30600
30601
30602 \size footnotesize 
30603 \SpecialChar ~
30604 \SpecialChar ~
30605 mov r7,#0x1E
30606 \layout Standard
30607
30608
30609 \size footnotesize 
30610 \SpecialChar ~
30611 \SpecialChar ~
30612 mov r0,#0x00
30613 \layout Standard
30614
30615
30616 \size footnotesize 
30617 ; _forcond_0($4) :
30618 \layout Standard
30619
30620
30621 \size footnotesize 
30622 00104$:
30623 \layout Standard
30624
30625
30626 \size footnotesize 
30627 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
30628 \layout Standard
30629
30630
30631 \size footnotesize 
30632 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
30633 \layout Standard
30634
30635
30636 \size footnotesize 
30637 \SpecialChar ~
30638 \SpecialChar ~
30639 clr c
30640 \layout Standard
30641
30642
30643 \size footnotesize 
30644 \SpecialChar ~
30645 \SpecialChar ~
30646 mov a,r4
30647 \layout Standard
30648
30649
30650 \size footnotesize 
30651 \SpecialChar ~
30652 \SpecialChar ~
30653 xrl a,#0x80
30654 \layout Standard
30655
30656
30657 \size footnotesize 
30658 \SpecialChar ~
30659 \SpecialChar ~
30660 subb a,#0x8a
30661 \layout Standard
30662
30663
30664 \size footnotesize 
30665 \SpecialChar ~
30666 \SpecialChar ~
30667 jnc 00107$
30668 \layout Standard
30669
30670
30671 \size footnotesize 
30672 00115$:
30673 \layout Standard
30674
30675
30676 \size footnotesize 
30677 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
30678 \layout Standard
30679
30680
30681 \size footnotesize 
30682 ; iTemp21 [lr21:38]{short}[r4]
30683 \layout Standard
30684
30685
30686 \size footnotesize 
30687 \SpecialChar ~
30688 \SpecialChar ~
30689 mov a,r4
30690 \layout Standard
30691
30692
30693 \size footnotesize 
30694 \SpecialChar ~
30695 \SpecialChar ~
30696 add a,r2
30697 \layout Standard
30698
30699
30700 \size footnotesize 
30701 \SpecialChar ~
30702 \SpecialChar ~
30703 mov r2,a
30704 \layout Standard
30705
30706
30707 \size footnotesize 
30708 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
30709 \layout Standard
30710
30711
30712 \size footnotesize 
30713 \SpecialChar ~
30714 \SpecialChar ~
30715 mov b,#0x03
30716 \layout Standard
30717
30718
30719 \size footnotesize 
30720 \SpecialChar ~
30721 \SpecialChar ~
30722 mov a,r4
30723 \layout Standard
30724
30725
30726 \size footnotesize 
30727 \SpecialChar ~
30728 \SpecialChar ~
30729 mul ab
30730 \layout Standard
30731
30732
30733 \size footnotesize 
30734 \SpecialChar ~
30735 \SpecialChar ~
30736 mov r1,a
30737 \layout Standard
30738
30739
30740 \size footnotesize 
30741 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
30742 \layout Standard
30743
30744
30745 \size footnotesize 
30746 ; iTemp15 [lr29:30]{short}[r1]
30747 \layout Standard
30748
30749
30750 \size footnotesize 
30751 \SpecialChar ~
30752 \SpecialChar ~
30753 add a,r3
30754 \layout Standard
30755
30756
30757 \size footnotesize 
30758 \SpecialChar ~
30759 \SpecialChar ~
30760 mov r3,a
30761 \layout Standard
30762
30763
30764 \size footnotesize 
30765 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
30766 \layout Standard
30767
30768
30769 \size footnotesize 
30770 \SpecialChar ~
30771 \SpecialChar ~
30772 mov a,r7
30773 \layout Standard
30774
30775
30776 \size footnotesize 
30777 \SpecialChar ~
30778 \SpecialChar ~
30779 add a,#0xfd
30780 \layout Standard
30781
30782
30783 \size footnotesize 
30784 \SpecialChar ~
30785 \SpecialChar ~
30786 mov r7,a
30787 \layout Standard
30788
30789
30790 \size footnotesize 
30791 \SpecialChar ~
30792 \SpecialChar ~
30793 mov a,r0
30794 \layout Standard
30795
30796
30797 \size footnotesize 
30798 \SpecialChar ~
30799 \SpecialChar ~
30800 addc a,#0xff
30801 \layout Standard
30802
30803
30804 \size footnotesize 
30805 \SpecialChar ~
30806 \SpecialChar ~
30807 mov r0,a
30808 \layout Standard
30809
30810
30811 \size footnotesize 
30812 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
30813 \layout Standard
30814
30815
30816 \size footnotesize 
30817 \SpecialChar ~
30818 \SpecialChar ~
30819 mov a,r7
30820 \layout Standard
30821
30822
30823 \size footnotesize 
30824 \SpecialChar ~
30825 \SpecialChar ~
30826 add a,_gint
30827 \layout Standard
30828
30829
30830 \size footnotesize 
30831 \SpecialChar ~
30832 \SpecialChar ~
30833 mov _gint,a
30834 \layout Standard
30835
30836
30837 \size footnotesize 
30838 \SpecialChar ~
30839 \SpecialChar ~
30840 mov a,r0
30841 \layout Standard
30842
30843
30844 \size footnotesize 
30845 \SpecialChar ~
30846 \SpecialChar ~
30847 addc a,(_gint + 1)
30848 \layout Standard
30849
30850
30851 \size footnotesize 
30852 \SpecialChar ~
30853 \SpecialChar ~
30854 mov (_gint + 1),a
30855 \layout Standard
30856
30857
30858 \size footnotesize 
30859 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
30860 \layout Standard
30861
30862
30863 \size footnotesize 
30864 \SpecialChar ~
30865 \SpecialChar ~
30866 inc r4
30867 \layout Standard
30868
30869
30870 \size footnotesize 
30871 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
30872 \layout Standard
30873
30874
30875 \size footnotesize 
30876 \SpecialChar ~
30877 \SpecialChar ~
30878 dec r5
30879 \layout Standard
30880
30881
30882 \size footnotesize 
30883 \SpecialChar ~
30884 \SpecialChar ~
30885 cjne r5,#0xff,00104$
30886 \layout Standard
30887
30888
30889 \size footnotesize 
30890 \SpecialChar ~
30891 \SpecialChar ~
30892 dec r6
30893 \layout Standard
30894
30895
30896 \size footnotesize 
30897 ; goto _forcond_0($4)
30898 \layout Standard
30899
30900
30901 \size footnotesize 
30902 \SpecialChar ~
30903 \SpecialChar ~
30904 sjmp 00104$
30905 \layout Standard
30906
30907
30908 \size footnotesize 
30909 ; _forbreak_0($7) :
30910 \layout Standard
30911
30912
30913 \size footnotesize 
30914 00107$:
30915 \layout Standard
30916
30917
30918 \size footnotesize 
30919 ; ret iTemp24 [lr40:41]{short}
30920 \layout Standard
30921
30922
30923 \size footnotesize 
30924 \SpecialChar ~
30925 \SpecialChar ~
30926 mov a,r3
30927 \layout Standard
30928
30929
30930 \size footnotesize 
30931 \SpecialChar ~
30932 \SpecialChar ~
30933 add a,r2
30934 \layout Standard
30935
30936
30937 \size footnotesize 
30938 \SpecialChar ~
30939 \SpecialChar ~
30940 mov dpl,a
30941 \layout Standard
30942
30943
30944 \size footnotesize 
30945 ; _return($8) :
30946 \layout Standard
30947
30948
30949 \size footnotesize 
30950 00108$:
30951 \layout Standard
30952
30953
30954 \size footnotesize 
30955 \SpecialChar ~
30956 \SpecialChar ~
30957 ret
30958 \newline 
30959
30960 \layout Section
30961
30962 A few words about basic block successors, predecessors and dominators
30963 \layout Standard
30964
30965 Successors are basic blocks
30966 \begin_inset LatexCommand \index{Basic blocks}
30967
30968 \end_inset 
30969
30970  that might execute after this basic block.
30971 \newline 
30972 Predecessors are basic blocks that might execute before reaching this basic
30973  block.
30974 \newline 
30975 Dominators are basic blocks that WILL execute before reaching this basic
30976  block.
30977 \newline 
30978
30979 \layout Standard
30980
30981 [basic block 1]
30982 \layout Standard
30983
30984 if (something)
30985 \layout Standard
30986
30987 \SpecialChar ~
30988 \SpecialChar ~
30989 \SpecialChar ~
30990 \SpecialChar ~
30991 [basic block 2]
30992 \layout Standard
30993
30994 else
30995 \layout Standard
30996
30997 \SpecialChar ~
30998 \SpecialChar ~
30999 \SpecialChar ~
31000 \SpecialChar ~
31001 [basic block 3]
31002 \layout Standard
31003
31004 [basic block 4]
31005 \newline 
31006
31007 \layout Standard
31008
31009 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
31010 \layout Standard
31011
31012 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
31013 \layout Standard
31014
31015 c) domVect of [BB4] = BB1 ...
31016  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
31017  was executed.
31018 \layout Chapter
31019
31020 Acknowledgments
31021 \layout Standard
31022
31023
31024 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
31025
31026 \end_inset 
31027
31028
31029 \newline 
31030
31031 \newline 
31032
31033 \emph on 
31034 Thanks to all the other volunteer developers who have helped with coding,
31035  testing, web-page creation, distribution sets, etc.
31036  You know who you are :-)
31037 \emph default 
31038
31039 \newline 
31040
31041 \newline 
31042
31043 \emph on 
31044 Also thanks to Sourceforge 
31045 \begin_inset LatexCommand \url{http://www.sf.net}
31046
31047 \end_inset 
31048
31049  which has hosted the project since 1999 and donates significant download
31050  bandwidth and probably more than 
31051 \begin_inset ERT
31052 status Collapsed
31053
31054 \layout Standard
31055 $10^{13}$
31056 \end_inset 
31057
31058 CPU cycles per day.
31059 \newline 
31060  
31061 \begin_inset Note
31062 collapsed false
31063
31064 \layout Standard
31065
31066 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
31067  minutes for (configure+make+regression test), and there is (i386, amd64,
31068  alpha, ppc64, (mingw32), sparc, macosx).
31069  
31070 \end_inset 
31071
31072
31073 \layout Standard
31074
31075 This document was initially written by Sandeep Dutta
31076 \layout Standard
31077
31078 All product names mentioned herein may be trademarks
31079 \begin_inset LatexCommand \index{Trademarks}
31080
31081 \end_inset 
31082
31083  of their respective companies.
31084  
31085 \layout Section*
31086
31087 Alphabetical index
31088 \layout Standard
31089
31090 To avoid confusion, the installation and building options for SDCC itself
31091  (chapter 2) are not part of the index.
31092 \layout Standard
31093
31094
31095 \begin_inset LatexCommand \printindex{}
31096
31097 \end_inset 
31098
31099
31100 \the_end