* doc/sdccman.lyx: updated IRQ section
[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.1
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by Subversion
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
132  
133 \series bold 
134 Sandeep Dutta
135 \series default 
136  designed for 8 bit Microprocessors.
137  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
138  8051, 8052
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
140
141 \end_inset 
142
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144  Zilog Z80 based MCUs.
145  It can be retargeted for other microprocessors, support for Microchip PIC,
146  Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargetable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Standard
206
207
208 \begin_inset  Tabular
209 <lyxtabular version="3" rows="8" columns="5">
210 <features>
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="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 \layout List
1063 \labelwidthstring 00.00.0000
1064
1065 docdir environment variable, see table below
1066 \layout List
1067 \labelwidthstring 00.00.0000
1068
1069 include_dir_suffix environment variable, see table below
1070 \layout List
1071 \labelwidthstring 00.00.0000
1072
1073 lib_dir_suffix environment variable, see table below
1074 \layout List
1075 \labelwidthstring 00.00.0000
1076
1077 sdccconf_h_dir_separator environment variable, either / or 
1078 \backslash 
1079
1080 \backslash 
1081  makes sense here.
1082  This character will only be used in sdccconf.h; don't forget it's a C-header,
1083  therefore a double-backslash is needed there.
1084 \layout List
1085 \labelwidthstring 00.00.0000
1086
1087 -
1088 \begin_inset ERT
1089 status Collapsed
1090
1091 \layout Standard
1092
1093 \backslash 
1094 /
1095 \end_inset 
1096
1097 -disable-mcs51-port Excludes the Intel mcs51 port
1098 \layout List
1099 \labelwidthstring 00.00.0000
1100
1101 -
1102 \begin_inset ERT
1103 status Collapsed
1104
1105 \layout Standard
1106
1107 \backslash 
1108 /
1109 \end_inset 
1110
1111 -disable-gbz80-port Excludes the Gameboy gbz80 port
1112 \layout List
1113 \labelwidthstring 00.00.0000
1114
1115 -
1116 \begin_inset ERT
1117 status Collapsed
1118
1119 \layout Standard
1120
1121 \backslash 
1122 /
1123 \end_inset 
1124
1125 -disable-z80-port Excludes the z80 port
1126 \layout List
1127 \labelwidthstring 00.00.0000
1128
1129 -
1130 \begin_inset ERT
1131 status Collapsed
1132
1133 \layout Standard
1134
1135 \backslash 
1136 /
1137 \end_inset 
1138
1139 -disable-avr-port Excludes the AVR port
1140 \layout List
1141 \labelwidthstring 00.00.0000
1142
1143 -
1144 \begin_inset ERT
1145 status Collapsed
1146
1147 \layout Standard
1148
1149 \backslash 
1150 /
1151 \end_inset 
1152
1153 -disable-ds390-port Excludes the DS390 port
1154 \layout List
1155 \labelwidthstring 00.00.0000
1156
1157 -
1158 \begin_inset ERT
1159 status Collapsed
1160
1161 \layout Standard
1162
1163 \backslash 
1164 /
1165 \end_inset 
1166
1167 -disable-hc08-port Excludes the HC08 port
1168 \layout List
1169 \labelwidthstring 00.00.0000
1170
1171 -
1172 \begin_inset ERT
1173 status Collapsed
1174
1175 \layout Standard
1176
1177 \backslash 
1178 /
1179 \end_inset 
1180
1181 -disable-pic-port Excludes the PIC port
1182 \layout List
1183 \labelwidthstring 00.00.0000
1184
1185 -
1186 \begin_inset ERT
1187 status Collapsed
1188
1189 \layout Standard
1190
1191 \backslash 
1192 /
1193 \end_inset 
1194
1195 -disable-xa51-port Excludes the XA51 port
1196 \layout List
1197 \labelwidthstring 00.00.0000
1198
1199 -
1200 \begin_inset ERT
1201 status Collapsed
1202
1203 \layout Standard
1204
1205 \backslash 
1206 /
1207 \end_inset 
1208
1209 -disable-ucsim Disables configuring and building of ucsim
1210 \layout List
1211 \labelwidthstring 00.00.0000
1212
1213 -
1214 \begin_inset ERT
1215 status Collapsed
1216
1217 \layout Standard
1218
1219 \backslash 
1220 /
1221 \end_inset 
1222
1223 -disable-device-lib Disables automatically building device libraries
1224 \layout List
1225 \labelwidthstring 00.00.0000
1226
1227 -
1228 \begin_inset ERT
1229 status Collapsed
1230
1231 \layout Standard
1232
1233 \backslash 
1234 /
1235 \end_inset 
1236
1237 -disable-packihx Disables building packihx
1238 \layout List
1239 \labelwidthstring 00.00.0000
1240
1241 -
1242 \begin_inset ERT
1243 status Collapsed
1244
1245 \layout Standard
1246
1247 \backslash 
1248 /
1249 \end_inset 
1250
1251 -enable-doc Build pdf, html and txt files from the lyx sources
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-libgc Use the Bohem memory allocator.
1266  Lower runtime footprint.
1267 \layout Standard
1268
1269 Furthermore the environment variables CC, CFLAGS, ...
1270  the tools and their arguments can be influenced.
1271  Please see `configure -
1272 \begin_inset ERT
1273 status Collapsed
1274
1275 \layout Standard
1276
1277 \backslash 
1278 /
1279 \end_inset 
1280
1281 -help` and the man/info pages of `configure` for details.
1282 \newline 
1283
1284 \newline 
1285 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1286  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1287 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1288  At the moment it's not possible to change the default settings (it was
1289  simply never required).
1290 \newline 
1291
1292 \newline 
1293 These configure options are compiled into the binaries, and can only be
1294  changed by rerunning 'configure' and recompiling SDCC.
1295  The configure options are written in 
1296 \emph on 
1297 italics
1298 \emph default 
1299  to distinguish them from run time environment variables (see section search
1300  paths).
1301 \newline 
1302
1303 \newline 
1304 The settings for 
1305 \begin_inset Quotes sld
1306 \end_inset 
1307
1308 Win32 builds
1309 \begin_inset Quotes srd
1310 \end_inset 
1311
1312  are used by the SDCC team to build the official Win32 binaries.
1313  The SDCC team uses Mingw32 to build the official Windows binaries, because
1314  it's
1315 \layout Enumerate
1316
1317 open source, 
1318 \layout Enumerate
1319
1320 a gcc compiler and last but not least
1321 \layout Enumerate
1322
1323 the binaries can be built by cross compiling on Sourceforge's compile farm.
1324 \layout Standard
1325
1326 See the examples, how to pass the Win32 settings to 'configure'.
1327  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1328  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1329  for Win32.
1330 \newline 
1331
1332 \newline 
1333 These defaults are:
1334 \newline 
1335
1336 \layout Standard
1337 \align center 
1338
1339 \begin_inset  Tabular
1340 <lyxtabular version="3" rows="8" columns="3">
1341 <features>
1342 <column alignment="block" valignment="top" leftline="true" width="0in">
1343 <column alignment="block" valignment="top" leftline="true" width="0in">
1344 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1345 <row topline="true" bottomline="true">
1346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1347 \begin_inset Text
1348
1349 \layout Standard
1350
1351 Variable
1352 \end_inset 
1353 </cell>
1354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1355 \begin_inset Text
1356
1357 \layout Standard
1358
1359 default
1360 \end_inset 
1361 </cell>
1362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1363 \begin_inset Text
1364
1365 \layout Standard
1366
1367 Win32 builds
1368 \end_inset 
1369 </cell>
1370 </row>
1371 <row topline="true">
1372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1373 \begin_inset Text
1374
1375 \layout Standard
1376
1377
1378 \emph on 
1379 PREFIX
1380 \end_inset 
1381 </cell>
1382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1383 \begin_inset Text
1384
1385 \layout Standard
1386
1387 /usr/local
1388 \end_inset 
1389 </cell>
1390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1391 \begin_inset Text
1392
1393 \layout Standard
1394
1395
1396 \backslash 
1397 sdcc
1398 \end_inset 
1399 </cell>
1400 </row>
1401 <row topline="true">
1402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1403 \begin_inset Text
1404
1405 \layout Standard
1406
1407
1408 \emph on 
1409 EXEC_PREFIX
1410 \end_inset 
1411 </cell>
1412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1413 \begin_inset Text
1414
1415 \layout Standard
1416
1417
1418 \emph on 
1419 $PREFIX
1420 \end_inset 
1421 </cell>
1422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1423 \begin_inset Text
1424
1425 \layout Standard
1426
1427
1428 \emph on 
1429 $PREFIX
1430 \end_inset 
1431 </cell>
1432 </row>
1433 <row topline="true">
1434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1435 \begin_inset Text
1436
1437 \layout Standard
1438
1439
1440 \emph on 
1441 BINDIR
1442 \end_inset 
1443 </cell>
1444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1445 \begin_inset Text
1446
1447 \layout Standard
1448
1449
1450 \emph on 
1451 $EXECPREFIX
1452 \emph default 
1453 /bin
1454 \end_inset 
1455 </cell>
1456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1457 \begin_inset Text
1458
1459 \layout Standard
1460
1461
1462 \emph on 
1463 $EXECPREFIX
1464 \emph default 
1465
1466 \backslash 
1467 bin
1468 \end_inset 
1469 </cell>
1470 </row>
1471 <row topline="true">
1472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1473 \begin_inset Text
1474
1475 \layout Standard
1476
1477
1478 \emph on 
1479 DATADIR
1480 \end_inset 
1481 </cell>
1482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1483 \begin_inset Text
1484
1485 \layout Standard
1486
1487
1488 \emph on 
1489 $PREFIX
1490 \emph default 
1491 /share
1492 \end_inset 
1493 </cell>
1494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1495 \begin_inset Text
1496
1497 \layout Standard
1498
1499
1500 \emph on 
1501 $PREFIX
1502 \end_inset 
1503 </cell>
1504 </row>
1505 <row topline="true">
1506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1507 \begin_inset Text
1508
1509 \layout Standard
1510
1511
1512 \emph on 
1513 DOCDIR
1514 \end_inset 
1515 </cell>
1516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1517 \begin_inset Text
1518
1519 \layout Standard
1520
1521
1522 \emph on 
1523 $DATADIR
1524 \emph default 
1525 /sdcc/doc
1526 \end_inset 
1527 </cell>
1528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1529 \begin_inset Text
1530
1531 \layout Standard
1532
1533
1534 \emph on 
1535 $DATADIR
1536 \emph default 
1537
1538 \backslash 
1539 doc
1540 \end_inset 
1541 </cell>
1542 </row>
1543 <row topline="true">
1544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1545 \begin_inset Text
1546
1547 \layout Standard
1548
1549
1550 \emph on 
1551 INCLUDE_DIR_SUFFIX
1552 \end_inset 
1553 </cell>
1554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1555 \begin_inset Text
1556
1557 \layout Standard
1558
1559 sdcc/include
1560 \end_inset 
1561 </cell>
1562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1563 \begin_inset Text
1564
1565 \layout Standard
1566
1567 include
1568 \end_inset 
1569 </cell>
1570 </row>
1571 <row topline="true" bottomline="true">
1572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1573 \begin_inset Text
1574
1575 \layout Standard
1576
1577
1578 \emph on 
1579 LIB_DIR_SUFFIX
1580 \end_inset 
1581 </cell>
1582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1583 \begin_inset Text
1584
1585 \layout Standard
1586
1587 sdcc/lib
1588 \end_inset 
1589 </cell>
1590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1591 \begin_inset Text
1592
1593 \layout Standard
1594
1595 lib
1596 \end_inset 
1597 </cell>
1598 </row>
1599 </lyxtabular>
1600
1601 \end_inset 
1602
1603
1604 \newline 
1605
1606 \layout Standard
1607 \noindent 
1608 'configure' also computes relative paths.
1609  This is needed for full relocatability of a binary package and to complete
1610  search paths (see section search paths below):
1611 \newline 
1612  
1613 \layout Standard
1614 \align center 
1615
1616 \begin_inset  Tabular
1617 <lyxtabular version="3" rows="4" columns="3">
1618 <features>
1619 <column alignment="block" valignment="top" leftline="true" width="0in">
1620 <column alignment="block" valignment="top" leftline="true" width="0in">
1621 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1622 <row topline="true" bottomline="true">
1623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1624 \begin_inset Text
1625
1626 \layout Standard
1627
1628 Variable (computed)
1629 \end_inset 
1630 </cell>
1631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1632 \begin_inset Text
1633
1634 \layout Standard
1635
1636 default
1637 \end_inset 
1638 </cell>
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1640 \begin_inset Text
1641
1642 \layout Standard
1643
1644 Win32 builds
1645 \end_inset 
1646 </cell>
1647 </row>
1648 <row topline="true" bottomline="true">
1649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1650 \begin_inset Text
1651
1652 \layout Standard
1653
1654
1655 \emph on 
1656 BIN2DATA_DIR
1657 \end_inset 
1658 </cell>
1659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1660 \begin_inset Text
1661
1662 \layout Standard
1663
1664 ../share
1665 \end_inset 
1666 </cell>
1667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1668 \begin_inset Text
1669
1670 \layout Standard
1671
1672 ..
1673 \end_inset 
1674 </cell>
1675 </row>
1676 <row bottomline="true">
1677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1678 \begin_inset Text
1679
1680 \layout Standard
1681
1682
1683 \emph on 
1684 PREFIX2BIN_DIR
1685 \end_inset 
1686 </cell>
1687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1688 \begin_inset Text
1689
1690 \layout Standard
1691
1692 bin
1693 \end_inset 
1694 </cell>
1695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1696 \begin_inset Text
1697
1698 \layout Standard
1699
1700 bin
1701 \end_inset 
1702 </cell>
1703 </row>
1704 <row bottomline="true">
1705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1706 \begin_inset Text
1707
1708 \layout Standard
1709
1710
1711 \emph on 
1712 PREFIX2DATA_DIR
1713 \end_inset 
1714 </cell>
1715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1716 \begin_inset Text
1717
1718 \layout Standard
1719
1720 share/sdcc
1721 \end_inset 
1722 </cell>
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1724 \begin_inset Text
1725
1726 \layout Standard
1727
1728 \end_inset 
1729 </cell>
1730 </row>
1731 </lyxtabular>
1732
1733 \end_inset 
1734
1735
1736 \newline 
1737
1738 \layout Standard
1739 \noindent 
1740 Examples:
1741 \layout LyX-Code
1742
1743 ./configure
1744 \newline 
1745 ./configure -
1746 \begin_inset ERT
1747 status Collapsed
1748
1749 \layout Standard
1750
1751 \backslash 
1752 /
1753 \end_inset 
1754
1755 -prefix=
1756 \begin_inset Quotes srd
1757 \end_inset 
1758
1759 /usr/bin
1760 \begin_inset Quotes srd
1761 \end_inset 
1762
1763  -
1764 \begin_inset ERT
1765 status Collapsed
1766
1767 \layout Standard
1768
1769 \backslash 
1770 /
1771 \end_inset 
1772
1773 -datadir=
1774 \begin_inset Quotes srd
1775 \end_inset 
1776
1777 /usr/share
1778 \begin_inset Quotes srd
1779 \end_inset 
1780
1781
1782 \newline 
1783 ./configure -
1784 \begin_inset ERT
1785 status Collapsed
1786
1787 \layout Standard
1788
1789 \backslash 
1790 /
1791 \end_inset 
1792
1793 -disable-avr-port -
1794 \begin_inset ERT
1795 status Collapsed
1796
1797 \layout Standard
1798
1799 \backslash 
1800 /
1801 \end_inset 
1802
1803 -disable-xa51-port
1804 \layout Standard
1805
1806 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1807 32'):
1808 \layout LyX-Code
1809
1810 ./configure 
1811 \backslash 
1812
1813 \newline 
1814 CC=
1815 \begin_inset Quotes srd
1816 \end_inset 
1817
1818 i586-mingw32msvc-gcc
1819 \begin_inset Quotes srd
1820 \end_inset 
1821
1822  CXX=
1823 \begin_inset Quotes srd
1824 \end_inset 
1825
1826 i586-mingw32msvc-g++
1827 \begin_inset Quotes srd
1828 \end_inset 
1829
1830  
1831 \backslash 
1832  
1833 \newline 
1834 RANLIB=
1835 \begin_inset Quotes srd
1836 \end_inset 
1837
1838 i586-mingw32msvc-ranlib
1839 \begin_inset Quotes srd
1840 \end_inset 
1841
1842  
1843 \backslash 
1844
1845 \newline 
1846 STRIP=
1847 \begin_inset Quotes srd
1848 \end_inset 
1849
1850 i586-mingw32msvc-strip
1851 \begin_inset Quotes srd
1852 \end_inset 
1853
1854  
1855 \backslash 
1856
1857 \newline 
1858 -
1859 \begin_inset ERT
1860 status Collapsed
1861
1862 \layout Standard
1863
1864 \backslash 
1865 /
1866 \end_inset 
1867
1868 -prefix=
1869 \begin_inset Quotes srd
1870 \end_inset 
1871
1872 /sdcc
1873 \begin_inset Quotes srd
1874 \end_inset 
1875
1876  
1877 \backslash 
1878
1879 \newline 
1880 -
1881 \begin_inset ERT
1882 status Collapsed
1883
1884 \layout Standard
1885
1886 \backslash 
1887 /
1888 \end_inset 
1889
1890 -datadir=
1891 \begin_inset Quotes srd
1892 \end_inset 
1893
1894 /sdcc
1895 \begin_inset Quotes srd
1896 \end_inset 
1897
1898  
1899 \backslash 
1900
1901 \newline 
1902 docdir=
1903 \begin_inset Quotes srd
1904 \end_inset 
1905
1906 /sdcc/doc
1907 \begin_inset Quotes srd
1908 \end_inset 
1909
1910  
1911 \backslash 
1912
1913 \newline 
1914 include_dir_suffix=
1915 \begin_inset Quotes srd
1916 \end_inset 
1917
1918 include
1919 \begin_inset Quotes srd
1920 \end_inset 
1921
1922  
1923 \backslash 
1924
1925 \newline 
1926 lib_dir_suffix=
1927 \begin_inset Quotes srd
1928 \end_inset 
1929
1930 lib
1931 \begin_inset Quotes srd
1932 \end_inset 
1933
1934  
1935 \backslash 
1936
1937 \newline 
1938 sdccconf_h_dir_separator=
1939 \begin_inset Quotes srd
1940 \end_inset 
1941
1942
1943 \backslash 
1944
1945 \backslash 
1946
1947 \backslash 
1948
1949 \backslash 
1950
1951 \begin_inset Quotes srd
1952 \end_inset 
1953
1954  
1955 \backslash 
1956
1957 \newline 
1958 -
1959 \begin_inset ERT
1960 status Collapsed
1961
1962 \layout Standard
1963
1964 \backslash 
1965 /
1966 \end_inset 
1967
1968 -disable-device-lib
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 -host=i586-mingw32msvc
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 -build=unknown-unknown-linux-gnu
1997 \layout Standard
1998
1999 To 
2000 \begin_inset Quotes sld
2001 \end_inset 
2002
2003 cross
2004 \begin_inset Quotes srd
2005 \end_inset 
2006
2007 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2008 ):
2009 \layout LyX-Code
2010
2011 ./configure -C 
2012 \backslash 
2013
2014 \newline 
2015 -
2016 \begin_inset ERT
2017 status Collapsed
2018
2019 \layout Standard
2020
2021 \backslash 
2022 /
2023 \end_inset 
2024
2025 -prefix=
2026 \begin_inset Quotes srd
2027 \end_inset 
2028
2029 /sdcc
2030 \begin_inset Quotes srd
2031 \end_inset 
2032
2033  
2034 \backslash 
2035
2036 \newline 
2037 -
2038 \begin_inset ERT
2039 status Collapsed
2040
2041 \layout Standard
2042
2043 \backslash 
2044 /
2045 \end_inset 
2046
2047 -datadir=
2048 \begin_inset Quotes srd
2049 \end_inset 
2050
2051 /sdcc
2052 \begin_inset Quotes srd
2053 \end_inset 
2054
2055  
2056 \backslash 
2057
2058 \newline 
2059 docdir=
2060 \begin_inset Quotes srd
2061 \end_inset 
2062
2063 /sdcc/doc
2064 \begin_inset Quotes srd
2065 \end_inset 
2066
2067  
2068 \backslash 
2069  
2070 \newline 
2071 include_dir_suffix=
2072 \begin_inset Quotes srd
2073 \end_inset 
2074
2075 include
2076 \begin_inset Quotes srd
2077 \end_inset 
2078
2079  
2080 \backslash 
2081
2082 \newline 
2083 lib_dir_suffix=
2084 \begin_inset Quotes srd
2085 \end_inset 
2086
2087 lib
2088 \begin_inset Quotes srd
2089 \end_inset 
2090
2091  
2092 \backslash 
2093
2094 \newline 
2095 sdccconf_h_dir_separator=
2096 \begin_inset Quotes srd
2097 \end_inset 
2098
2099
2100 \backslash 
2101
2102 \backslash 
2103
2104 \backslash 
2105
2106 \backslash 
2107
2108 \begin_inset Quotes srd
2109 \end_inset 
2110
2111  
2112 \backslash 
2113
2114 \newline 
2115 CC=
2116 \begin_inset Quotes srd
2117 \end_inset 
2118
2119 gcc -mno-cygwin
2120 \begin_inset Quotes srd
2121 \end_inset 
2122
2123  
2124 \backslash 
2125
2126 \newline 
2127 CXX=
2128 \begin_inset Quotes srd
2129 \end_inset 
2130
2131 g++ -mno-cygwin
2132 \begin_inset Quotes srd
2133 \end_inset 
2134
2135  
2136 \layout Standard
2137
2138 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2139  The option '-
2140 \begin_inset ERT
2141 status Collapsed
2142
2143 \layout Standard
2144
2145 \backslash 
2146 /
2147 \end_inset 
2148
2149 -C' turns on caching, which gives a little bit extra speed.
2150  However if options are changed, it can be necessary to delete the config.cache
2151  file.
2152 \layout Section
2153
2154 Install paths
2155 \begin_inset LatexCommand \label{sub:Install-paths}
2156
2157 \end_inset 
2158
2159
2160 \begin_inset LatexCommand \index{Install paths}
2161
2162 \end_inset 
2163
2164
2165 \layout Standard
2166 \added_space_top medskip \align center 
2167
2168 \begin_inset  Tabular
2169 <lyxtabular version="3" rows="5" columns="4">
2170 <features>
2171 <column alignment="left" valignment="top" leftline="true" width="0">
2172 <column alignment="left" valignment="top" leftline="true" width="0">
2173 <column alignment="left" valignment="top" leftline="true" width="0">
2174 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2175 <row topline="true" bottomline="true">
2176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2177 \begin_inset Text
2178
2179 \layout Standard
2180
2181
2182 \series bold 
2183 Description
2184 \end_inset 
2185 </cell>
2186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2187 \begin_inset Text
2188
2189 \layout Standard
2190
2191
2192 \series bold 
2193 Path
2194 \end_inset 
2195 </cell>
2196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2197 \begin_inset Text
2198
2199 \layout Standard
2200
2201
2202 \series bold 
2203 Default
2204 \end_inset 
2205 </cell>
2206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2207 \begin_inset Text
2208
2209 \layout Standard
2210
2211
2212 \series bold 
2213 Win32 builds
2214 \end_inset 
2215 </cell>
2216 </row>
2217 <row topline="true">
2218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2219 \begin_inset Text
2220
2221 \layout Standard
2222
2223 Binary files*
2224 \end_inset 
2225 </cell>
2226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2227 \begin_inset Text
2228
2229 \layout Standard
2230
2231
2232 \emph on 
2233 $EXEC_PREFIX
2234 \end_inset 
2235 </cell>
2236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2237 \begin_inset Text
2238
2239 \layout Standard
2240
2241 /usr/local/bin
2242 \end_inset 
2243 </cell>
2244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2245 \begin_inset Text
2246
2247 \layout Standard
2248
2249
2250 \backslash 
2251 sdcc
2252 \backslash 
2253 bin
2254 \end_inset 
2255 </cell>
2256 </row>
2257 <row topline="true">
2258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2259 \begin_inset Text
2260
2261 \layout Standard
2262
2263 Include files
2264 \end_inset 
2265 </cell>
2266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2267 \begin_inset Text
2268
2269 \layout Standard
2270
2271
2272 \emph on 
2273 $DATADIR/ $INCLUDE_DIR_SUFFIX
2274 \end_inset 
2275 </cell>
2276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2277 \begin_inset Text
2278
2279 \layout Standard
2280
2281 /usr/local/share/sdcc/include
2282 \end_inset 
2283 </cell>
2284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2285 \begin_inset Text
2286
2287 \layout Standard
2288
2289
2290 \backslash 
2291 sdcc
2292 \backslash 
2293 include
2294 \end_inset 
2295 </cell>
2296 </row>
2297 <row topline="true">
2298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2299 \begin_inset Text
2300
2301 \layout Standard
2302
2303 Library file**
2304 \end_inset 
2305 </cell>
2306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2307 \begin_inset Text
2308
2309 \layout Standard
2310
2311
2312 \emph on 
2313 $DATADIR/$LIB_DIR_SUFFIX
2314 \end_inset 
2315 </cell>
2316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2317 \begin_inset Text
2318
2319 \layout Standard
2320
2321 /usr/local/share/sdcc/lib
2322 \end_inset 
2323 </cell>
2324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2325 \begin_inset Text
2326
2327 \layout Standard
2328
2329
2330 \backslash 
2331 sdcc
2332 \backslash 
2333 lib
2334 \end_inset 
2335 </cell>
2336 </row>
2337 <row topline="true" bottomline="true">
2338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2339 \begin_inset Text
2340
2341 \layout Standard
2342
2343 Documentation
2344 \end_inset 
2345 </cell>
2346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2347 \begin_inset Text
2348
2349 \layout Standard
2350
2351
2352 \emph on 
2353 $DOCDIR
2354 \end_inset 
2355 </cell>
2356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2357 \begin_inset Text
2358
2359 \layout Standard
2360
2361 /usr/local/share/sdcc/doc
2362 \end_inset 
2363 </cell>
2364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2365 \begin_inset Text
2366
2367 \layout Standard
2368
2369
2370 \backslash 
2371 sdcc
2372 \backslash 
2373 doc
2374 \end_inset 
2375 </cell>
2376 </row>
2377 </lyxtabular>
2378
2379 \end_inset 
2380
2381
2382 \layout Verse
2383
2384
2385 \size footnotesize 
2386 *compiler, preprocessor, assembler, and linker
2387 \newline 
2388 **the 
2389 \shape italic 
2390 model
2391 \shape default 
2392  is auto-appended by the compiler, e.g.
2393  small, large, z80, ds390 etc
2394 \layout Standard
2395 \noindent 
2396 The install paths can still be changed during `make install` with e.g.:
2397 \layout LyX-Code
2398
2399 make install prefix=$(HOME)/local/sdcc
2400 \layout Standard
2401
2402 Of course this doesn't change the search paths compiled into the binaries.
2403 \newline 
2404
2405 \newline 
2406 Moreover the install path can be changed by defining DESTDIR
2407 \begin_inset LatexCommand \index{DESTDIR}
2408
2409 \end_inset 
2410
2411 :
2412 \layout LyX-Code
2413
2414 make install DESTDIR=$(HOME)/sdcc.rpm/
2415 \layout Standard
2416
2417 Please note that DESTDIR must have a trailing slash!
2418 \layout Section
2419
2420 Search Paths
2421 \begin_inset LatexCommand \label{sub:Search-Paths}
2422
2423 \end_inset 
2424
2425
2426 \begin_inset LatexCommand \index{Search path}
2427
2428 \end_inset 
2429
2430
2431 \layout Standard
2432
2433 Some search paths or parts of them are determined by configure variables
2434  (in 
2435 \emph on 
2436 italics
2437 \emph default 
2438 , see section above).
2439  Further search paths are determined by environment variables during runtime.
2440  
2441 \newline 
2442 The paths searched when running the compiler are as follows (the first catch
2443  wins):
2444 \newline 
2445
2446 \newline 
2447 1.
2448  Binary files (preprocessor, assembler and linker)
2449 \newline 
2450
2451 \layout Standard
2452 \align center 
2453
2454 \begin_inset  Tabular
2455 <lyxtabular version="3" rows="4" columns="3">
2456 <features>
2457 <column alignment="block" valignment="top" leftline="true" width="0in">
2458 <column alignment="block" valignment="top" leftline="true" width="0in">
2459 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2460 <row topline="true" bottomline="true">
2461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2462 \begin_inset Text
2463
2464 \layout Standard
2465
2466 Search path
2467 \end_inset 
2468 </cell>
2469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2470 \begin_inset Text
2471
2472 \layout Standard
2473
2474 default
2475 \end_inset 
2476 </cell>
2477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2478 \begin_inset Text
2479
2480 \layout Standard
2481
2482 Win32 builds
2483 \end_inset 
2484 </cell>
2485 </row>
2486 <row topline="true">
2487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2488 \begin_inset Text
2489
2490 \layout Standard
2491
2492 $SDCC_HOME/
2493 \emph on 
2494 $PPREFIX2BIN_DIR
2495 \end_inset 
2496 </cell>
2497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2498 \begin_inset Text
2499
2500 \layout Standard
2501
2502 $SDCC_HOME/bin
2503 \end_inset 
2504 </cell>
2505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2506 \begin_inset Text
2507
2508 \layout Standard
2509
2510 $SDCC_HOME
2511 \backslash 
2512 bin
2513 \end_inset 
2514 </cell>
2515 </row>
2516 <row topline="true">
2517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2518 \begin_inset Text
2519
2520 \layout Standard
2521
2522 Path of argv[0] (if available)
2523 \end_inset 
2524 </cell>
2525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2526 \begin_inset Text
2527
2528 \layout Standard
2529
2530 Path of argv[0]
2531 \end_inset 
2532 </cell>
2533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2534 \begin_inset Text
2535
2536 \layout Standard
2537
2538 Path of argv[0]
2539 \end_inset 
2540 </cell>
2541 </row>
2542 <row topline="true" bottomline="true">
2543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2544 \begin_inset Text
2545
2546 \layout Standard
2547
2548 $PATH
2549 \end_inset 
2550 </cell>
2551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2552 \begin_inset Text
2553
2554 \layout Standard
2555
2556 $PATH
2557 \end_inset 
2558 </cell>
2559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2560 \begin_inset Text
2561
2562 \layout Standard
2563
2564 $PATH
2565 \end_inset 
2566 </cell>
2567 </row>
2568 </lyxtabular>
2569
2570 \end_inset 
2571
2572  
2573 \newline 
2574
2575 \layout Standard
2576 \noindent 
2577 2.
2578  Include files
2579 \newline 
2580
2581 \layout Standard
2582 \align center 
2583
2584 \begin_inset  Tabular
2585 <lyxtabular version="3" rows="6" columns="3">
2586 <features>
2587 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2588 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2589 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2590 <row topline="true" bottomline="true">
2591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2592 \begin_inset Text
2593
2594 \layout Standard
2595
2596 Search path
2597 \end_inset 
2598 </cell>
2599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2600 \begin_inset Text
2601
2602 \layout Standard
2603
2604 default
2605 \end_inset 
2606 </cell>
2607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2608 \begin_inset Text
2609
2610 \layout Standard
2611
2612 Win32 builds
2613 \end_inset 
2614 </cell>
2615 </row>
2616 <row topline="true">
2617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2618 \begin_inset Text
2619
2620 \layout Standard
2621
2622 -
2623 \begin_inset ERT
2624 status Collapsed
2625
2626 \layout Standard
2627
2628 \backslash 
2629 /
2630 \end_inset 
2631
2632 -I dir
2633 \end_inset 
2634 </cell>
2635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2636 \begin_inset Text
2637
2638 \layout Standard
2639
2640 -
2641 \begin_inset ERT
2642 status Collapsed
2643
2644 \layout Standard
2645
2646 \backslash 
2647 /
2648 \end_inset 
2649
2650 -I dir
2651 \end_inset 
2652 </cell>
2653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2654 \begin_inset Text
2655
2656 \layout Standard
2657
2658 -
2659 \begin_inset ERT
2660 status Collapsed
2661
2662 \layout Standard
2663
2664 \backslash 
2665 /
2666 \end_inset 
2667
2668 -I dir
2669 \end_inset 
2670 </cell>
2671 </row>
2672 <row topline="true">
2673 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2674 \begin_inset Text
2675
2676 \layout Standard
2677
2678 $SDCC_INCLUDE
2679 \end_inset 
2680 </cell>
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 \begin_inset Text
2683
2684 \layout Standard
2685
2686 $SDCC_INCLUDE
2687 \end_inset 
2688 </cell>
2689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2690 \begin_inset Text
2691
2692 \layout Standard
2693
2694 $SDCC_INCLUDE
2695 \end_inset 
2696 </cell>
2697 </row>
2698 <row topline="true">
2699 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2700 \begin_inset Text
2701
2702 \layout Standard
2703
2704 $SDCC_HOME/
2705 \newline 
2706
2707 \emph on 
2708 $PREFIX2DATA_DIR/
2709 \newline 
2710 $INCLUDE_DIR_SUFFIX
2711 \end_inset 
2712 </cell>
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 share/sdcc/
2721 \newline 
2722 include
2723 \end_inset 
2724 </cell>
2725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2726 \begin_inset Text
2727
2728 \layout Standard
2729
2730 $SDCC_HOME
2731 \backslash 
2732 include
2733 \end_inset 
2734 </cell>
2735 </row>
2736 <row topline="true">
2737 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2738 \begin_inset Text
2739
2740 \layout Standard
2741
2742 path(argv[0])/
2743 \newline 
2744
2745 \emph on 
2746 $BIN2DATADIR/
2747 \emph default 
2748
2749 \newline 
2750
2751 \emph on 
2752 $INCLUDE_DIR_SUFFIX
2753 \end_inset 
2754 </cell>
2755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2756 \begin_inset Text
2757
2758 \layout Standard
2759
2760 path(argv[0])/
2761 \newline 
2762 ../sdcc/include
2763 \newline 
2764 \SpecialChar ~
2765 \SpecialChar ~
2766 \SpecialChar ~
2767 \SpecialChar ~
2768 \SpecialChar ~
2769 \SpecialChar ~
2770 \SpecialChar ~
2771 \SpecialChar ~
2772 \SpecialChar ~
2773 \SpecialChar ~
2774 \SpecialChar ~
2775 \SpecialChar ~
2776 \SpecialChar ~
2777 \SpecialChar ~
2778 \SpecialChar ~
2779 \SpecialChar ~
2780 \SpecialChar ~
2781 \SpecialChar ~
2782 \SpecialChar ~
2783 \SpecialChar ~
2784 \SpecialChar ~
2785 \SpecialChar ~
2786 \SpecialChar ~
2787 \SpecialChar ~
2788 \SpecialChar ~
2789 \SpecialChar ~
2790 \SpecialChar ~
2791 \SpecialChar ~
2792 \SpecialChar ~
2793 \SpecialChar ~
2794 \SpecialChar ~
2795 \SpecialChar ~
2796 \SpecialChar ~
2797 \SpecialChar ~
2798 \SpecialChar ~
2799 \SpecialChar ~
2800 \SpecialChar ~
2801 \SpecialChar ~
2802
2803 \end_inset 
2804 </cell>
2805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2806 \begin_inset Text
2807
2808 \layout Standard
2809
2810 path(argv[0])
2811 \backslash 
2812 ..
2813 \backslash 
2814 include
2815 \end_inset 
2816 </cell>
2817 </row>
2818 <row topline="true" bottomline="true">
2819 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2820 \begin_inset Text
2821
2822 \layout Standard
2823
2824
2825 \emph on 
2826 $DATADIR/
2827 \emph default 
2828
2829 \newline 
2830
2831 \emph on 
2832 $INCLUDE_DIR_SUFFIX
2833 \end_inset 
2834 </cell>
2835 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2836 \begin_inset Text
2837
2838 \layout Standard
2839
2840 /usr/local/share/sdcc/
2841 \newline 
2842 include
2843 \end_inset 
2844 </cell>
2845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2846 \begin_inset Text
2847
2848 \layout Standard
2849
2850 (not on Win32)
2851 \end_inset 
2852 </cell>
2853 </row>
2854 </lyxtabular>
2855
2856 \end_inset 
2857
2858  
2859 \newline 
2860
2861 \layout Standard
2862 \noindent 
2863 The option -
2864 \begin_inset ERT
2865 status Collapsed
2866
2867 \layout Standard
2868
2869 \backslash 
2870 /
2871 \end_inset 
2872
2873 -nostdinc disables the last two search paths.
2874 \newline 
2875
2876 \newline 
2877 3.
2878  Library files 
2879 \newline 
2880
2881 \layout Standard
2882
2883 With the exception of 
2884 \begin_inset Quotes sld
2885 \end_inset 
2886
2887 -
2888 \begin_inset ERT
2889 status Collapsed
2890
2891 \layout Standard
2892
2893 \backslash 
2894 /
2895 \end_inset 
2896
2897 -L dir
2898 \begin_inset Quotes srd
2899 \end_inset 
2900
2901  the 
2902 \shape italic 
2903 model
2904 \shape default 
2905  is auto-appended by the compiler (e.g.
2906  small, large, z80, ds390 etc.).
2907  
2908 \newline 
2909
2910 \layout Standard
2911 \align center 
2912
2913 \begin_inset  Tabular
2914 <lyxtabular version="3" rows="6" columns="3">
2915 <features>
2916 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2917 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2918 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2919 <row topline="true" bottomline="true">
2920 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2921 \begin_inset Text
2922
2923 \layout Standard
2924
2925 Search path
2926 \end_inset 
2927 </cell>
2928 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2929 \begin_inset Text
2930
2931 \layout Standard
2932
2933 default
2934 \end_inset 
2935 </cell>
2936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2937 \begin_inset Text
2938
2939 \layout Standard
2940
2941 Win32 builds
2942 \end_inset 
2943 </cell>
2944 </row>
2945 <row topline="true">
2946 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2947 \begin_inset Text
2948
2949 \layout Standard
2950
2951 -
2952 \begin_inset ERT
2953 status Collapsed
2954
2955 \layout Standard
2956
2957 \backslash 
2958 /
2959 \end_inset 
2960
2961 -L dir
2962 \end_inset 
2963 </cell>
2964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2965 \begin_inset Text
2966
2967 \layout Standard
2968
2969 -
2970 \begin_inset ERT
2971 status Collapsed
2972
2973 \layout Standard
2974
2975 \backslash 
2976 /
2977 \end_inset 
2978
2979 -L dir
2980 \end_inset 
2981 </cell>
2982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2983 \begin_inset Text
2984
2985 \layout Standard
2986
2987 -
2988 \begin_inset ERT
2989 status Collapsed
2990
2991 \layout Standard
2992
2993 \backslash 
2994 /
2995 \end_inset 
2996
2997 -L dir
2998 \end_inset 
2999 </cell>
3000 </row>
3001 <row topline="true">
3002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3003 \begin_inset Text
3004
3005 \layout Standard
3006
3007 $SDCC_LIB/
3008 \newline 
3009
3010 \emph on 
3011 <model>
3012 \end_inset 
3013 </cell>
3014 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3015 \begin_inset Text
3016
3017 \layout Standard
3018
3019 $SDCC_LIB/
3020 \newline 
3021
3022 \emph on 
3023 <model>
3024 \end_inset 
3025 </cell>
3026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3027 \begin_inset Text
3028
3029 \layout Standard
3030
3031 $SDCC_LIB
3032 \backslash 
3033
3034 \newline 
3035
3036 \emph on 
3037 <model>
3038 \end_inset 
3039 </cell>
3040 </row>
3041 <row topline="true">
3042 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3043 \begin_inset Text
3044
3045 \layout Standard
3046
3047 $SDCC_HOME/
3048 \newline 
3049
3050 \emph on 
3051 $PREFIX2DATA_DIR/
3052 \newline 
3053 $LIB_DIR_SUFFIX/<model>
3054 \end_inset 
3055 </cell>
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 share/sdcc/
3064 \newline 
3065 lib/
3066 \emph on 
3067 <model>
3068 \end_inset 
3069 </cell>
3070 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3071 \begin_inset Text
3072
3073 \layout Standard
3074
3075 $SDCC_HOME
3076 \backslash 
3077 lib
3078 \backslash 
3079
3080 \emph on 
3081
3082 \newline 
3083 <model>
3084 \end_inset 
3085 </cell>
3086 </row>
3087 <row topline="true">
3088 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3089 \begin_inset Text
3090
3091 \layout Standard
3092
3093 path(argv[0])/
3094 \newline 
3095
3096 \emph on 
3097 $BIN2DATADIR/
3098 \emph default 
3099
3100 \newline 
3101
3102 \emph on 
3103 $LIB_DIR_SUFFIX/<model>
3104 \end_inset 
3105 </cell>
3106 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3107 \begin_inset Text
3108
3109 \layout Standard
3110
3111 path(argv[0])/
3112 \newline 
3113 ../sdcc/lib/
3114 \emph on 
3115 <model>
3116 \newline 
3117 \SpecialChar ~
3118 \SpecialChar ~
3119 \SpecialChar ~
3120 \SpecialChar ~
3121 \SpecialChar ~
3122 \SpecialChar ~
3123 \SpecialChar ~
3124 \SpecialChar ~
3125 \SpecialChar ~
3126 \SpecialChar ~
3127 \SpecialChar ~
3128 \SpecialChar ~
3129 \SpecialChar ~
3130 \SpecialChar ~
3131 \SpecialChar ~
3132 \SpecialChar ~
3133 \SpecialChar ~
3134 \SpecialChar ~
3135 \SpecialChar ~
3136 \SpecialChar ~
3137 \SpecialChar ~
3138 \SpecialChar ~
3139 \SpecialChar ~
3140 \SpecialChar ~
3141 \SpecialChar ~
3142 \SpecialChar ~
3143 \SpecialChar ~
3144 \SpecialChar ~
3145 \SpecialChar ~
3146 \SpecialChar ~
3147 \SpecialChar ~
3148 \SpecialChar ~
3149 \SpecialChar ~
3150 \SpecialChar ~
3151 \SpecialChar ~
3152 \SpecialChar ~
3153 \SpecialChar ~
3154 \SpecialChar ~
3155 \SpecialChar ~
3156
3157 \end_inset 
3158 </cell>
3159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3160 \begin_inset Text
3161
3162 \layout Standard
3163
3164 path(argv[0])
3165 \backslash 
3166
3167 \newline 
3168 ..
3169 \backslash 
3170 lib
3171 \backslash 
3172
3173 \emph on 
3174 <model>
3175 \newline 
3176 \SpecialChar ~
3177 \SpecialChar ~
3178 \SpecialChar ~
3179 \SpecialChar ~
3180 \SpecialChar ~
3181 \SpecialChar ~
3182 \SpecialChar ~
3183 \SpecialChar ~
3184 \SpecialChar ~
3185 \SpecialChar ~
3186 \SpecialChar ~
3187 \SpecialChar ~
3188 \SpecialChar ~
3189 \SpecialChar ~
3190 \SpecialChar ~
3191 \SpecialChar ~
3192 \SpecialChar ~
3193 \SpecialChar ~
3194 \SpecialChar ~
3195 \SpecialChar ~
3196 \SpecialChar ~
3197 \SpecialChar ~
3198 \SpecialChar ~
3199 \SpecialChar ~
3200 \SpecialChar ~
3201 \SpecialChar ~
3202 \SpecialChar ~
3203 \SpecialChar ~
3204 \SpecialChar ~
3205 \SpecialChar ~
3206 \SpecialChar ~
3207 \SpecialChar ~
3208 \SpecialChar ~
3209 \SpecialChar ~
3210 \SpecialChar ~
3211
3212 \end_inset 
3213 </cell>
3214 </row>
3215 <row topline="true" bottomline="true">
3216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3217 \begin_inset Text
3218
3219 \layout Standard
3220
3221
3222 \emph on 
3223 $DATADIR/
3224 \newline 
3225 $LIB_DIR_SUFFIX/<model>
3226 \end_inset 
3227 </cell>
3228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3229 \begin_inset Text
3230
3231 \layout Standard
3232
3233 /usr/local/share/sdcc/
3234 \newline 
3235 lib/
3236 \emph on 
3237 <model>
3238 \end_inset 
3239 </cell>
3240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3241 \begin_inset Text
3242
3243 \layout Standard
3244
3245 (not on Win32)
3246 \end_inset 
3247 </cell>
3248 </row>
3249 </lyxtabular>
3250
3251 \end_inset 
3252
3253
3254 \newline 
3255
3256 \layout Comment
3257
3258 Don't delete any of the stray spaces in the table above without checking
3259  the HTML output (last line)!
3260 \layout Standard
3261
3262 \SpecialChar ~
3263
3264 \newline 
3265 The option -
3266 \begin_inset ERT
3267 status Collapsed
3268
3269 \layout Standard
3270
3271 \backslash 
3272 /
3273 \end_inset 
3274
3275 -nostdlib disables the last two search paths.
3276 \layout Section
3277
3278 Building SDCC
3279 \begin_inset LatexCommand \index{Building SDCC}
3280
3281 \end_inset 
3282
3283
3284 \layout Subsection
3285
3286 Building SDCC on Linux
3287 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3288
3289 \end_inset 
3290
3291
3292 \layout Enumerate
3293
3294
3295 \series medium 
3296 Download the source package
3297 \series default 
3298  either from the SDCC Subversion repository or from the nightly snapshots
3299 \series medium 
3300 , it will be named something like sdcc
3301 \series default 
3302 .src
3303 \series medium 
3304 .t
3305 \series default 
3306 ar.
3307 \series medium 
3308 gz
3309 \series default 
3310  
3311 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3312
3313 \end_inset 
3314
3315 .
3316 \layout Enumerate
3317
3318
3319 \series medium 
3320 Bring up a command line terminal, such as xterm.
3321 \layout Enumerate
3322
3323
3324 \series medium 
3325 Unpack the file using a command like: 
3326 \family sans 
3327 \series bold 
3328 "tar -xvzf sdcc.src.tar.gz
3329 \family default 
3330 \series default 
3331 "
3332 \series medium 
3333 , this will create a sub-directory called sdcc with all of the sources.
3334 \layout Enumerate
3335
3336 Change directory into the main SDCC directory, for example type: 
3337 \family sans 
3338 \series bold 
3339 "cd sdcc
3340 \series default 
3341 ".
3342 \layout Enumerate
3343
3344
3345 \series medium 
3346 Type 
3347 \family sans 
3348 \series bold 
3349 "./configure
3350 \family default 
3351 \series default 
3352 ".
3353  This configures the package for compilation on your system.
3354 \layout Enumerate
3355
3356
3357 \series medium 
3358 Type 
3359 \family sans 
3360 \series bold 
3361 "make
3362 \family default 
3363 \series default 
3364 "
3365 \series medium 
3366 .
3367
3368 \series default 
3369  All of the source packages will compile, this can take a while.
3370 \layout Enumerate
3371
3372
3373 \series medium 
3374 Type 
3375 \family sans 
3376 \series bold 
3377 "make install"
3378 \family default 
3379 \series default 
3380  as root
3381 \series medium 
3382 .
3383
3384 \series default 
3385  This copies the binary executables, the include files, the libraries and
3386  the documentation to the install directories.
3387  Proceed with section 
3388 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3389
3390 \end_inset 
3391
3392 .
3393 \layout Subsection
3394
3395 Building SDCC on OSX 2.x
3396 \layout Standard
3397
3398 Follow the instruction for Linux.
3399 \newline 
3400
3401 \newline 
3402 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3403 )) fails to compile SDCC.
3404  Fortunately there's also gcc 2.9.x installed, which works fine.
3405  This compiler can be selected by running 'configure' with:
3406 \layout LyX-Code
3407
3408 ./configure CC=gcc2 CXX=g++2
3409 \layout Subsection
3410
3411 Cross compiling SDCC on Linux for Windows
3412 \layout Standard
3413
3414 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3415  See section 'Configure Options'.
3416 \layout Subsection
3417
3418 Building SDCC using Cygwin and Mingw32
3419 \layout Standard
3420
3421 For building and installing a Cygwin executable follow the instructions
3422  for Linux.
3423 \newline 
3424
3425 \newline 
3426 On Cygwin a 
3427 \begin_inset Quotes sld
3428 \end_inset 
3429
3430 native
3431 \begin_inset Quotes srd
3432 \end_inset 
3433
3434  Win32-binary can be built, which will not need the Cygwin-DLL.
3435  For the necessary 'configure' options see section 'configure options' or
3436  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3437 \newline 
3438
3439 \newline 
3440 In order to install Cygwin on Windows download setup.exe from 
3441 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3442
3443 \end_inset 
3444
3445 .
3446  Run it, set the 
3447 \begin_inset Quotes sld
3448 \end_inset 
3449
3450 default text file type
3451 \begin_inset Quotes srd
3452 \end_inset 
3453
3454  to 
3455 \begin_inset Quotes sld
3456 \end_inset 
3457
3458 unix
3459 \begin_inset Quotes srd
3460 \end_inset 
3461
3462  and download/install at least the following packages.
3463  Some packages are selected by default, others will be automatically selected
3464  because of dependencies with the manually selected packages.
3465  Never deselect these packages!
3466 \layout Itemize
3467
3468 flex
3469 \layout Itemize
3470
3471 bison
3472 \layout Itemize
3473
3474 gcc ; version 3.x is fine, no need to use the old 2.9x
3475 \layout Itemize
3476
3477 binutils ; selected with gcc
3478 \layout Itemize
3479
3480 make
3481 \layout Itemize
3482
3483 rxvt ; a nice console, which makes life much easier under windoze (see below)
3484 \layout Itemize
3485
3486 man ; not really needed for building SDCC, but you'll miss it sooner or
3487  later
3488 \layout Itemize
3489
3490 less ; not really needed for building SDCC, but you'll miss it sooner or
3491  later
3492 \layout Itemize
3493
3494 svn ; only if you use Subversion access
3495 \layout Standard
3496
3497 If you want to develop something you'll need:
3498 \layout Itemize
3499
3500 python ; for the regression tests
3501 \layout Itemize
3502
3503 gdb ; the gnu debugger, together with the nice GUI 
3504 \begin_inset Quotes sld
3505 \end_inset 
3506
3507 insight
3508 \begin_inset Quotes srd
3509 \end_inset 
3510
3511
3512 \layout Itemize
3513
3514 openssh ; to access the CF or commit changes
3515 \layout Itemize
3516
3517 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3518  use autoconf-stable!
3519 \layout Standard
3520
3521 rxvt is a nice console with history.
3522  Replace in your cygwin.bat the line
3523 \layout LyX-Code
3524
3525 bash -
3526 \begin_inset ERT
3527 status Collapsed
3528
3529 \layout Standard
3530
3531 \backslash 
3532 /
3533 \end_inset 
3534
3535 -login -i 
3536 \layout Standard
3537
3538 with (one line):
3539 \layout LyX-Code
3540
3541 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3542 \layout LyX-Code
3543
3544      -bg black -fg white -geometry 100x65 -e bash -
3545 \begin_inset ERT
3546 status Collapsed
3547
3548 \layout Standard
3549
3550 \backslash 
3551 /
3552 \end_inset 
3553
3554 -login
3555 \layout Standard
3556
3557 Text selected with the mouse is automatically copied to the clipboard, pasting
3558  works with shift-insert.
3559 \newline 
3560
3561 \newline 
3562 The other good tip is to make sure you have no //c/-style paths anywhere,
3563  use /cygdrive/c/ instead.
3564  Using // invokes a network lookup which is very slow.
3565  If you think 
3566 \begin_inset Quotes sld
3567 \end_inset 
3568
3569 cygdrive
3570 \begin_inset Quotes srd
3571 \end_inset 
3572
3573  is too long, you can change it with e.g.
3574 \layout LyX-Code
3575
3576 mount -s -u -c /mnt
3577 \layout Standard
3578
3579 SDCC sources use the unix line ending LF.
3580  Life is much easier, if you store the source tree on a drive which is mounted
3581  in binary mode.
3582  And use an editor which can handle LF-only line endings.
3583  Make sure not to commit files with windows line endings.
3584  The tabulator spacing
3585 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3586
3587 \end_inset 
3588
3589  used in the project is 8.
3590  Although a tabulator spacing of 8 is a sensible choice for programmers
3591  (it's a power of 2 and allows to display 8/16 bit signed variables without
3592  loosing columns) the plan is to move towards using only spaces in the source.
3593 \layout Subsection
3594
3595 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3596 \layout Standard
3597
3598
3599 \series medium 
3600 Download the source package
3601 \series default 
3602  either from the SDCC Subversion repository or from the 
3603 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3604
3605 \end_inset 
3606
3607
3608 \series medium 
3609 , it will be named something like sdcc
3610 \series default 
3611 .src
3612 \series medium 
3613 .tgz.
3614
3615 \series default 
3616  SDCC is distributed with all the projects, workspaces, and files you need
3617  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3618  The workspace name is 'sdcc.dsw'.
3619  Please note that as it is now, all the executables are created in a folder
3620  called sdcc
3621 \backslash 
3622 bin_vc.
3623  Once built you need to copy the executables from sdcc
3624 \backslash 
3625 bin_vc to sdcc
3626 \backslash 
3627 bin before running SDCC.
3628  
3629 \newline 
3630
3631 \newline 
3632 WARNING: Visual studio is very picky with line terminations; it expects
3633  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3634  When using the Subversion repository it's easiest to configure the svn
3635  client to convert automatically for you.
3636  If however you are getting a message such as "This makefile was not generated
3637  by Developer Studio etc.
3638  etc.
3639 \begin_inset Quotes srd
3640 \end_inset 
3641
3642  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3643  need to convert the Unix style line endings to DOS style line endings.
3644  To do so you can use the 
3645 \begin_inset Quotes sld
3646 \end_inset 
3647
3648 unix2dos
3649 \begin_inset Quotes srd
3650 \end_inset 
3651
3652  utility freely available on the internet.
3653  Doug Hawkins reported in the sdcc-user list that this works:
3654 \newline 
3655
3656 \newline 
3657 C:
3658 \backslash 
3659 Programming
3660 \backslash 
3661 SDCC> unix2dos sdcc.dsw
3662 \newline 
3663 C:
3664 \backslash 
3665 Programming
3666 \backslash 
3667 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3668 \newline 
3669
3670 \newline 
3671 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3672  flex.exe, and gawk.exe.
3673  One good place to get them is 
3674 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3675
3676 \end_inset 
3677
3678
3679 \newline 
3680
3681 \newline 
3682 Download the file UnxUtils
3683 \begin_inset LatexCommand \index{UnxUtils}
3684
3685 \end_inset 
3686
3687 .zip.
3688  Now you have to install the utilities and setup MSVC so it can locate the
3689  required programs.
3690  Here there are two alternatives (choose one!):
3691 \layout Enumerate
3692
3693 The easy way:
3694 \newline 
3695
3696 \newline 
3697 a) Extract UnxUtils.zip to your C:
3698 \backslash 
3699  hard disk PRESERVING the original paths, otherwise bison won't work.
3700  (If you are using WinZip make certain that 'Use folder names' is selected)
3701 \newline 
3702
3703 \newline 
3704 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3705  in 'Show directories for:' select 'Executable files', and in the directories
3706  window add a new path: 'C:
3707 \backslash 
3708 user
3709 \backslash 
3710 local
3711 \backslash 
3712 wbin', click ok.
3713 \newline 
3714
3715 \newline 
3716 (As a side effect, you get a bunch of Unix utilities that could be useful,
3717  such as diff and patch.)
3718 \layout Enumerate
3719
3720 A more compact way:
3721 \newline 
3722
3723 \newline 
3724 This one avoids extracting a bunch of files you may not use, but requires
3725  some extra work:
3726 \newline 
3727
3728 \newline 
3729 a) Create a directory were to put the tools needed, or use a directory already
3730  present.
3731  Say for example 'C:
3732 \backslash 
3733 util'.
3734 \newline 
3735
3736 \newline 
3737 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3738  to such directory WITHOUT preserving the original paths.
3739  (If you are using WinZip make certain that 'Use folder names' is not selected)
3740 \newline 
3741
3742 \newline 
3743 c) Rename bison.exe to '_bison.exe'.
3744 \newline 
3745
3746 \newline 
3747 d) Create a batch file 'bison.bat' in 'C:
3748 \backslash 
3749 util
3750 \backslash 
3751 ' and add these lines: 
3752 \newline 
3753 \SpecialChar ~
3754 \SpecialChar ~
3755 set BISON_SIMPLE=C:
3756 \backslash 
3757 util
3758 \backslash 
3759 bison.simple 
3760 \newline 
3761 \SpecialChar ~
3762 \SpecialChar ~
3763 set BISON_HAIRY=C:
3764 \backslash 
3765 util
3766 \backslash 
3767 bison.hairy
3768 \newline 
3769 \SpecialChar ~
3770 \SpecialChar ~
3771 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3772 \newline 
3773
3774 \newline 
3775 Steps 'c' and 'd' are needed because bison requires by default that the
3776  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3777  '/usr/local/share/' I think.
3778  So it is necessary to tell bison where those files are located if they
3779  are not in such directory.
3780  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3781 \newline 
3782
3783 \newline 
3784 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3785  in 'Show directories for:' select 'Executable files', and in the directories
3786  window add a new path: 'c:
3787 \backslash 
3788 util', click ok.
3789  Note that you can use any other path instead of 'c:
3790 \backslash 
3791 util', even the path where the Visual C++ tools are, probably: 'C:
3792 \backslash 
3793 Program Files
3794 \backslash 
3795 Microsoft Visual Studio
3796 \backslash 
3797 Common
3798 \backslash 
3799 Tools'.
3800  So you don't have to execute step 'e' :)
3801 \layout Standard
3802
3803 That is it.
3804  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3805  the executables from sdcc
3806 \backslash 
3807 bin_vc to sdcc
3808 \backslash 
3809 bin, and you can compile using SDCC.
3810 \layout Subsection
3811
3812 Building SDCC Using Borland
3813 \layout Enumerate
3814
3815 From the sdcc directory, run the command "make -f Makefile.bcc".
3816  This should regenerate all the .exe files in the bin directory except for
3817  SDCDB and ucSim.
3818 \layout Enumerate
3819
3820 If you modify any source files and need to rebuild, be aware that the dependenci
3821 es may not be correctly calculated.
3822  The safest option is to delete all .obj files and run the build again.
3823  From a Cygwin BASH prompt, this can easily be done with the command (be
3824  sure you are in the sdcc directory):
3825 \newline 
3826
3827 \newline 
3828
3829 \family sans 
3830 \series bold 
3831 find .
3832  
3833 \backslash 
3834 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3835 \backslash 
3836 ) -print -exec rm {} 
3837 \backslash 
3838 ;
3839 \family default 
3840 \series default 
3841
3842 \newline 
3843
3844 \newline 
3845 or on Windows NT/2000/XP from the command prompt with the command:
3846 \newline 
3847
3848 \family sans 
3849 \series bold 
3850
3851 \newline 
3852 del /s *.obj *.lib *.rul
3853 \family default 
3854 \series default 
3855  from the sdcc directory.
3856 \layout Subsection
3857
3858 Windows Install Using a ZIP Package
3859 \layout Enumerate
3860
3861 Download the binary zip package from 
3862 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3863
3864 \end_inset 
3865
3866  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3867  This should unpack to a group of sub-directories.
3868  An example directory structure after unpacking the mingw32 package is:
3869  c:
3870 \backslash 
3871 sdcc
3872 \backslash 
3873 bin for the executables, c:
3874 \backslash 
3875 sdcc
3876 \backslash 
3877 include and c:
3878 \backslash 
3879 sdcc
3880 \backslash 
3881 lib for the include and libraries.
3882 \layout Enumerate
3883
3884 Adjust your environment variable PATH to include the location of the bin
3885  directory or start sdcc using the full path.
3886 \layout Subsection
3887
3888 Windows Install Using the Setup Program
3889 \begin_inset LatexCommand \label{sub:Windows-Install}
3890
3891 \end_inset 
3892
3893
3894 \layout Standard
3895
3896 Download the setup program 
3897 \emph on 
3898 sdcc-x.y.z-setup.exe
3899 \emph default 
3900  for an official release from 
3901 \newline 
3902
3903 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3904
3905 \end_inset 
3906
3907  or a setup program for one of the snapshots 
3908 \emph on 
3909 sdcc-yyyymmdd-xxxx-setup.exe
3910 \emph default 
3911  from 
3912 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3913
3914 \end_inset 
3915
3916  and execute it.
3917  A windows typical installer will guide you through the installation process.
3918 \layout Subsection
3919
3920 VPATH
3921 \begin_inset LatexCommand \index{VPATH}
3922
3923 \end_inset 
3924
3925  feature
3926 \layout Standard
3927
3928 SDCC supports the VPATH feature provided by configure and make.
3929  It allows to separate the source and build trees.
3930  Here's an example:
3931 \layout Standard
3932
3933
3934 \family typewriter 
3935 cd ~\SpecialChar ~
3936 \SpecialChar ~
3937 \SpecialChar ~
3938 \SpecialChar ~
3939 \SpecialChar ~
3940 \SpecialChar ~
3941 \SpecialChar ~
3942 \SpecialChar ~
3943 \SpecialChar ~
3944 \SpecialChar ~
3945 \SpecialChar ~
3946 \SpecialChar ~
3947 \SpecialChar ~
3948 \SpecialChar ~
3949 \SpecialChar ~
3950 \SpecialChar ~
3951 \SpecialChar ~
3952 \SpecialChar ~
3953 \SpecialChar ~
3954 \SpecialChar ~
3955 \SpecialChar ~
3956 # cd $HOME
3957 \layout Standard
3958
3959
3960 \family typewriter 
3961 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3962 # extract source to directory sdcc
3963 \layout Standard
3964
3965
3966 \family typewriter 
3967 mkdir sdcc.build\SpecialChar ~
3968 \SpecialChar ~
3969 \SpecialChar ~
3970 \SpecialChar ~
3971 \SpecialChar ~
3972 \SpecialChar ~
3973 \SpecialChar ~
3974 \SpecialChar ~
3975 \SpecialChar ~
3976 # put output in sdcc.build
3977 \layout Standard
3978
3979
3980 \family typewriter 
3981 cd sdcc.build
3982 \layout Standard
3983
3984
3985 \family typewriter 
3986 ../sdcc/configure\SpecialChar ~
3987 \SpecialChar ~
3988 \SpecialChar ~
3989 \SpecialChar ~
3990 \SpecialChar ~
3991 \SpecialChar ~
3992 \SpecialChar ~
3993 \SpecialChar ~
3994 # configure is doing all the magic!
3995 \layout Standard
3996
3997
3998 \family typewriter 
3999 make
4000 \layout Standard
4001 \noindent 
4002 That's it! 
4003 \series bold 
4004 configure
4005 \series default 
4006  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4007  It automagically computes the variables srcdir, top_srcdir and top_buildir
4008  for each directory.
4009  After running 
4010 \series bold 
4011 make
4012 \series default 
4013  the generated files will be in ~/sdcc.build, while the source files stay
4014  in ~/sdcc.
4015 \newline 
4016 This is not only usefull for building different binaries, e.g.
4017  when cross compiling.
4018  It also gives you a much better overview in the source tree when all the
4019  generated files are not scattered between the source files.
4020  And the best thing is: if you want to change a file you can leave the original
4021  file untouched in the source directory.
4022  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4023  Makefile.dep` and `make`.
4024  
4025 \series bold 
4026 make
4027 \series default 
4028  will do the rest for you!
4029 \layout Section
4030
4031 Building the Documentation
4032 \layout Standard
4033
4034 Add -
4035 \begin_inset ERT
4036 status Collapsed
4037
4038 \layout Standard
4039
4040 \backslash 
4041 /
4042 \end_inset 
4043
4044 -enable-doc to the configure arguments to build the documentation together
4045  with all the other stuff.
4046  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4047  dvips and makeindex) to get the job done.
4048  Another possibility is to change to the doc directory and to type 
4049 \family sans 
4050 \series bold 
4051
4052 \begin_inset Quotes srd
4053 \end_inset 
4054
4055 make
4056 \begin_inset Quotes srd
4057 \end_inset 
4058
4059
4060 \family default 
4061 \series default 
4062  there.
4063  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4064 x).
4065  Using LyX 
4066 \begin_inset LatexCommand \url{http://www.lyx.org}
4067
4068 \end_inset 
4069
4070  as editor is straightforward.
4071  Prebuilt documentation in html and pdf format is available from 
4072 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4073
4074 \end_inset 
4075
4076 .
4077 \layout Section
4078
4079 Reading the Documentation
4080 \begin_inset LatexCommand \index{Documentation}
4081
4082 \end_inset 
4083
4084
4085 \layout Standard
4086
4087 Currently reading the document in pdf format is recommended, as for unknown
4088  reason the hyperlinks are working there whereas in the html version they
4089  are not
4090 \begin_inset Foot
4091 collapsed false
4092
4093 \layout Standard
4094
4095 If you should know why please drop us a note
4096 \end_inset 
4097
4098 .
4099  
4100 \newline 
4101 You'll find the pdf version
4102 \begin_inset LatexCommand \index{PDF version of this document}
4103
4104 \end_inset 
4105
4106  at 
4107 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4108
4109 \end_inset 
4110
4111 .
4112  
4113 \newline 
4114 A html version
4115 \begin_inset LatexCommand \index{HTML version of this document}
4116
4117 \end_inset 
4118
4119  should be online at 
4120 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4121
4122 \end_inset 
4123
4124 .
4125 \newline 
4126 This documentation is in some aspects different from a commercial documentation:
4127  
4128 \layout Itemize
4129
4130 It tries to document SDCC for several processor architectures in one document
4131  (commercially these probably would be separate documents/products).
4132  This document
4133 \begin_inset LatexCommand \index{Status of documentation}
4134
4135 \end_inset 
4136
4137  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4138 on about f.e.
4139  Z80, PIC14, PIC16 and HC08.
4140 \layout Itemize
4141
4142 There are many references pointing away from this documentation.
4143  Don't let this distract you.
4144  If there f.e.
4145  was a reference like 
4146 \begin_inset LatexCommand \url{http://www.opencores.org}
4147
4148 \end_inset 
4149
4150  together with a statement 
4151 \begin_inset Quotes sld
4152 \end_inset 
4153
4154 some processors which are targetted by SDCC can be implemented in a 
4155 \emph on 
4156 f
4157 \emph default 
4158 ield 
4159 \emph on 
4160 p
4161 \emph default 
4162 rogrammable 
4163 \emph on 
4164 g
4165 \emph default 
4166 ate 
4167 \emph on 
4168 a
4169 \emph default 
4170 rray
4171 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4172
4173 \end_inset 
4174
4175
4176 \begin_inset Quotes srd
4177 \end_inset 
4178
4179  or 
4180 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4181
4182 \end_inset 
4183
4184
4185 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4186
4187 \end_inset 
4188
4189  
4190 \begin_inset Quotes sld
4191 \end_inset 
4192
4193 have you ever heard of an open source compiler that compiles a subset of
4194  C for an FPGA?
4195 \begin_inset Quotes srd
4196 \end_inset 
4197
4198  we expect you to have a quick look there and come back.
4199  If you read this you are on the right track.
4200 \layout Itemize
4201
4202 Some sections attribute more space to problems, restrictions and warnings
4203  than to the solution.
4204 \layout Itemize
4205
4206 The installation section and the section about the debugger is intimidating.
4207 \layout Itemize
4208
4209 There are still lots of typos and there are more different writing styles
4210  than pictures.
4211 \layout Section
4212
4213 Testing the SDCC Compiler
4214 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4215
4216 \end_inset 
4217
4218
4219 \layout Standard
4220
4221 The first thing you should do after installing your SDCC compiler is to
4222  see if it runs.
4223  Type 
4224 \family sans 
4225 \series bold 
4226 "sdcc -
4227 \begin_inset ERT
4228 status Collapsed
4229
4230 \layout Standard
4231
4232 \backslash 
4233 /
4234 \end_inset 
4235
4236 -version"
4237 \begin_inset LatexCommand \index{version}
4238
4239 \end_inset 
4240
4241
4242 \family default 
4243 \series default 
4244  at the prompt, and the program should run and output its version like:
4245  
4246 \newline 
4247
4248 \family typewriter 
4249 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4250  (UNIX)
4251 \layout Standard
4252
4253 If it doesn't run, or gives a message about not finding sdcc program, then
4254  you need to check over your installation.
4255  Make sure that the sdcc bin directory is in your executable search path
4256  defined by the PATH environment setting (
4257 \series medium 
4258 see 
4259 \series default 
4260 section 
4261 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4262
4263 \end_inset 
4264
4265 \SpecialChar ~
4266
4267 \series medium 
4268 Install trouble-shooting for suggestions
4269 \series default 
4270 ).
4271  Make sure that the sdcc program is in the bin folder, if not perhaps something
4272  did not install correctly.
4273 \newline 
4274
4275 \newline 
4276
4277 \series medium 
4278 SDCC 
4279 \series default 
4280 is commonly installed as described in section 
4281 \begin_inset Quotes sld
4282 \end_inset 
4283
4284 Install and search paths
4285 \begin_inset Quotes srd
4286 \end_inset 
4287
4288 .
4289 \newline 
4290
4291 \newline 
4292
4293 \series medium 
4294 Make sure the compiler works on a very simple example.
4295  Type in the following test.c program using your favorite 
4296 \series default 
4297 ASCII 
4298 \series medium 
4299 editor:
4300 \layout Verse
4301
4302
4303 \family typewriter 
4304 char test;
4305 \newline 
4306
4307 \newline 
4308 void main(void) {
4309 \newline 
4310 \SpecialChar ~
4311 \SpecialChar ~
4312 \SpecialChar ~
4313 \SpecialChar ~
4314 test=0;
4315 \newline 
4316 }
4317 \layout Standard
4318
4319
4320 \series medium 
4321 Compile this using the following command: 
4322 \family sans 
4323 \series bold 
4324 "sdcc -c test.c".
4325
4326 \family default 
4327 \series default 
4328  
4329 \series medium 
4330 If all goes well, the compiler will generate a test.asm and test.rel file.
4331  Congratulations, you've just compiled your first program with SDCC.
4332  We used the -c option to tell SDCC not to link the generated code, just
4333  to keep things simple for this step.
4334 \series default 
4335
4336 \newline 
4337
4338 \newline 
4339
4340 \series medium 
4341 The next step is to try it with the linker.
4342  Type in 
4343 \family sans 
4344 \series bold 
4345 "sdcc test.c
4346 \family default 
4347 \series default 
4348 "
4349 \series medium 
4350 .
4351  If all goes well the compiler will link with the libraries and produce
4352  a test.ihx output file.
4353  If this step fails
4354 \series default 
4355  
4356 \series medium 
4357 (no test.ihx, and the linker generates warnings), then the problem is most
4358  likely that 
4359 \series default 
4360 SDCC
4361 \series medium 
4362  cannot find the 
4363 \series default 
4364 /
4365 \series medium 
4366 usr/local/share/sdcc/lib directory
4367 \series default 
4368  
4369 \series medium 
4370 (see 
4371 \series default 
4372 section 
4373 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4374
4375 \end_inset 
4376
4377 \SpecialChar ~
4378
4379 \series medium 
4380 Install trouble-shooting for suggestions).
4381 \series default 
4382
4383 \newline 
4384
4385 \newline 
4386
4387 \series medium 
4388 The final test is to ensure 
4389 \series default 
4390 SDCC
4391 \series medium 
4392  can use the 
4393 \series default 
4394 standard
4395 \series medium 
4396  header files and libraries.
4397  Edit test.c and change it to the following:
4398 \layout Verse
4399
4400
4401 \family typewriter 
4402 #include <string.h>
4403 \newline 
4404
4405 \newline 
4406 char str1[10];
4407 \newline 
4408
4409 \newline 
4410 void main(void) {
4411 \newline 
4412 \SpecialChar ~
4413 \SpecialChar ~
4414 strcpy(str1, "testing");
4415 \newline 
4416 }
4417 \layout Standard
4418
4419
4420 \series medium 
4421 Compile this by typing 
4422 \family sans 
4423 \series bold 
4424 "sdcc test.c"
4425 \family default 
4426 \series medium 
4427 .
4428  This should generate a test.ihx output file, and it should give no warnings
4429  such as not finding the string.h file.
4430  If it cannot find the string.h file, then the problem is that 
4431 \series default 
4432 SDCC
4433 \series medium 
4434  cannot find the /usr/local/share/sdcc/include directory
4435 \series default 
4436  
4437 \series medium 
4438 (see the 
4439 \series default 
4440 section 
4441 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4442
4443 \end_inset 
4444
4445 \SpecialChar ~
4446
4447 \series medium 
4448 Install trouble-shooting section for suggestions).
4449
4450 \series default 
4451  Use option 
4452 \series bold 
4453 -
4454 \begin_inset ERT
4455 status Collapsed
4456
4457 \layout Standard
4458
4459 \backslash 
4460 /
4461 \end_inset 
4462
4463 -print-search-dirs
4464 \series default 
4465
4466 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4467
4468 \end_inset 
4469
4470  to find exactly where SDCC is looking for the include and lib files.
4471 \layout Section
4472
4473 Install Trouble-shooting
4474 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4475
4476 \end_inset 
4477
4478
4479 \begin_inset LatexCommand \index{Install trouble-shooting}
4480
4481 \end_inset 
4482
4483
4484 \layout Subsection
4485
4486 If SDCC does not build correctly
4487 \layout Standard
4488
4489 A thing to try is starting from scratch by unpacking the .tgz source package
4490  again in an empty directory.
4491  Configure it like:
4492 \newline 
4493
4494 \newline 
4495
4496 \family sans 
4497 \series bold 
4498 ./configure 2>&1 | tee configure.log
4499 \family default 
4500 \series default 
4501
4502 \newline 
4503
4504 \newline 
4505 and build it like:
4506 \newline 
4507
4508 \newline 
4509
4510 \family sans 
4511 \series bold 
4512 make 2>&1 | tee make.log
4513 \family default 
4514 \series default 
4515
4516 \newline 
4517
4518 \newline 
4519 If anything goes wrong, you can review the log files to locate the problem.
4520  Or a relevant part of this can be attached to an email that could be helpful
4521  when requesting help from the mailing list.
4522 \layout Subsection
4523
4524 What the 
4525 \begin_inset Quotes sld
4526 \end_inset 
4527
4528 ./configure
4529 \begin_inset Quotes srd
4530 \end_inset 
4531
4532  does
4533 \layout Standard
4534
4535 The 
4536 \begin_inset Quotes sld
4537 \end_inset 
4538
4539 ./configure
4540 \begin_inset Quotes srd
4541 \end_inset 
4542
4543  command is a script that analyzes your system and performs some configuration
4544  to ensure the source package compiles on your system.
4545  It will take a few minutes to run, and will compile a few tests to determine
4546  what compiler features are installed.
4547 \layout Subsection
4548
4549 What the 
4550 \begin_inset Quotes sld
4551 \end_inset 
4552
4553 make
4554 \begin_inset Quotes srd
4555 \end_inset 
4556
4557  does
4558 \layout Standard
4559
4560 This runs the GNU make tool, which automatically compiles all the source
4561  packages into the final installed binary executables.
4562 \layout Subsection
4563
4564 What the 
4565 \begin_inset Quotes sld
4566 \end_inset 
4567
4568 make install
4569 \begin_inset Quotes erd
4570 \end_inset 
4571
4572  command does.
4573 \layout Standard
4574
4575 This will install the compiler, other executables libraries and include
4576  files into the appropriate directories.
4577  See sections 
4578 \begin_inset LatexCommand \ref{sub:Install-paths}
4579
4580 \end_inset 
4581
4582 ,\SpecialChar ~
4583
4584 \begin_inset LatexCommand \ref{sub:Search-Paths}
4585
4586 \end_inset 
4587
4588 \SpecialChar ~
4589 about install and search paths.
4590 \newline 
4591 On most systems you will need super-user privileges to do this.
4592 \layout Section
4593
4594 Components of SDCC
4595 \layout Standard
4596
4597 SDCC is not just a compiler, but a collection of tools by various developers.
4598  These include linkers, assemblers, simulators and other components.
4599  Here is a summary of some of the components.
4600  Note that the included simulator and assembler have separate documentation
4601  which you can find in the source package in their respective directories.
4602  As SDCC grows to include support for other processors, other packages from
4603  various developers are included and may have their own sets of documentation.
4604 \newline 
4605
4606 \newline 
4607 You might want to look at the files which are installed in <installdir>.
4608  At the time of this writing, we find the following programs for gcc-builds:
4609 \newline 
4610  
4611 \newline 
4612 In <installdir>/bin:
4613 \layout Itemize
4614
4615 sdcc - The compiler.
4616 \layout Itemize
4617
4618 sdcpp - The C preprocessor.
4619 \layout Itemize
4620
4621 asx8051 - The assembler for 8051 type processors.
4622 \layout Itemize
4623
4624 as-z80
4625 \series bold 
4626
4627 \series default 
4628 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4629 \layout Itemize
4630
4631 aslink -The linker for 8051 type processors.
4632 \layout Itemize
4633
4634 link-z80
4635 \series bold 
4636
4637 \series default 
4638 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4639 \layout Itemize
4640
4641 s51 - The ucSim 8051 simulator.
4642 \layout Itemize
4643
4644 sdcdb - The source debugger.
4645 \layout Itemize
4646
4647 packihx - A tool to pack (compress) Intel hex files.
4648 \layout Standard
4649
4650 In <installdir>/share/sdcc/include
4651 \layout Itemize
4652
4653 the include files
4654 \layout Standard
4655
4656 In <installdir>/share/sdcc/lib
4657 \layout Itemize
4658
4659 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4660  relocatables.
4661 \layout Standard
4662
4663 In <installdir>/share/sdcc/doc
4664 \layout Itemize
4665
4666 the documentation
4667 \layout Standard
4668
4669 As development for other processors proceeds, this list will expand to include
4670  executables to support processors like AVR, PIC, etc.
4671 \layout Subsection
4672
4673 sdcc - The Compiler
4674 \layout Standard
4675
4676 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4677  the assembler and linkage editor.
4678 \layout Subsection
4679
4680 sdcpp - The C-Preprocessor
4681 \layout Standard
4682
4683 The preprocessor
4684 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4685
4686 \end_inset 
4687
4688  is a modified version of the GNU preprocessor.
4689  The C preprocessor is used to pull in #include sources, process #ifdef
4690  statements, #defines and so on.
4691 \layout Subsection
4692
4693 as
4694 \emph on 
4695 xxxx
4696 \emph default 
4697 , aslink, link-
4698 \emph on 
4699 xxx
4700 \emph default 
4701  - The Assemblers and Linkage Editors
4702 \layout Standard
4703
4704 This is retargettable assembler & linkage editor, it was developed by Alan
4705  Baldwin.
4706  John Hartman created the version for 8051, and I (Sandeep) have made some
4707  enhancements and bug fixes for it to work properly with SDCC.
4708 \layout Subsection
4709
4710 s51 - The Simulator
4711 \layout Standard
4712
4713 S51
4714 \begin_inset LatexCommand \index{s51}
4715
4716 \end_inset 
4717
4718  is a freeware, opensource simulator developed by Daniel Drotos.
4719  The simulator is built as part of the build process.
4720  For more information visit Daniel's web site at: 
4721 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4722
4723 \end_inset 
4724
4725 .
4726  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4727  XA51 family.
4728 \layout Subsection
4729
4730 sdcdb - Source Level Debugger
4731 \layout Standard
4732
4733 SDCDB
4734 \begin_inset LatexCommand \index{SDCDB (debugger)}
4735
4736 \end_inset 
4737
4738  is the companion source level debugger.
4739  More about SDCDB in section 
4740 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4741
4742 \end_inset 
4743
4744 .
4745  The current version of the debugger uses Daniel's Simulator S51
4746 \begin_inset LatexCommand \index{s51}
4747
4748 \end_inset 
4749
4750 , but can be easily changed to use other simulators.
4751 \layout Chapter
4752
4753 Using SDCC
4754 \layout Section
4755
4756 Compiling
4757 \layout Subsection
4758
4759 Single Source File Projects
4760 \layout Standard
4761
4762 For single source file 8051 projects the process is very simple.
4763  Compile your programs with the following command 
4764 \family sans 
4765 \series bold 
4766 "sdcc sourcefile.c".
4767
4768 \family default 
4769 \series default 
4770  This will compile, assemble and link your source file.
4771  Output files are as follows:
4772 \layout Itemize
4773
4774 sourcefile.asm
4775 \begin_inset LatexCommand \index{<file>.asm}
4776
4777 \end_inset 
4778
4779  - Assembler source
4780 \begin_inset LatexCommand \index{Assembler source}
4781
4782 \end_inset 
4783
4784  file created by the compiler
4785 \layout Itemize
4786
4787 sourcefile.lst
4788 \begin_inset LatexCommand \index{<file>.lst}
4789
4790 \end_inset 
4791
4792  - Assembler listing
4793 \begin_inset LatexCommand \index{Assembler listing}
4794
4795 \end_inset 
4796
4797  file created by the Assembler
4798 \layout Itemize
4799
4800 sourcefile.rst
4801 \begin_inset LatexCommand \index{<file>.rst}
4802
4803 \end_inset 
4804
4805  - Assembler listing
4806 \begin_inset LatexCommand \index{Assembler listing}
4807
4808 \end_inset 
4809
4810  file updated with linkedit information, created by linkage editor
4811 \layout Itemize
4812
4813 sourcefile.sym
4814 \begin_inset LatexCommand \index{<file>.sym}
4815
4816 \end_inset 
4817
4818  - symbol listing
4819 \begin_inset LatexCommand \index{Symbol listing}
4820
4821 \end_inset 
4822
4823  for the sourcefile, created by the assembler
4824 \layout Itemize
4825
4826 sourcefile.rel
4827 \begin_inset LatexCommand \index{<file>.rel}
4828
4829 \end_inset 
4830
4831  or sourcefile.o
4832 \begin_inset LatexCommand \index{<file>.o}
4833
4834 \end_inset 
4835
4836  - Object file
4837 \begin_inset LatexCommand \index{Object file}
4838
4839 \end_inset 
4840
4841  created by the assembler, input to Linkage editor
4842 \layout Itemize
4843
4844 sourcefile.map
4845 \begin_inset LatexCommand \index{<file>.map}
4846
4847 \end_inset 
4848
4849  - The memory map
4850 \begin_inset LatexCommand \index{Memory map}
4851
4852 \end_inset 
4853
4854  for the load module, created by the Linker
4855 \layout Itemize
4856
4857 sourcefile.mem
4858 \begin_inset LatexCommand \index{<file>.mem}
4859
4860 \end_inset 
4861
4862  - A file with a summary of the memory usage
4863 \layout Itemize
4864
4865 sourcefile.ihx
4866 \begin_inset LatexCommand \index{<file>.ihx}
4867
4868 \end_inset 
4869
4870  - The load module in Intel hex format
4871 \begin_inset LatexCommand \index{Intel hex format}
4872
4873 \end_inset 
4874
4875  (you can select the Motorola S19 format
4876 \begin_inset LatexCommand \index{Motorola S19 format}
4877
4878 \end_inset 
4879
4880  with -
4881 \begin_inset ERT
4882 status Collapsed
4883
4884 \layout Standard
4885
4886 \backslash 
4887 /
4888 \end_inset 
4889
4890 -out-fmt-s19
4891 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4892
4893 \end_inset 
4894
4895 .
4896  If you need another format you might want to use 
4897 \family sans 
4898 \shape italic 
4899 objdump
4900 \family default 
4901 \shape default 
4902
4903 \begin_inset LatexCommand \index{objdump (tool)}
4904
4905 \end_inset 
4906
4907  or
4908 \family sans 
4909 \shape italic 
4910  srecord
4911 \family default 
4912 \shape default 
4913
4914 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4915
4916 \end_inset 
4917
4918 ).
4919  Both formats are documented in the documentation of srecord
4920 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4921
4922 \end_inset 
4923
4924
4925 \layout Itemize
4926
4927 sourcefile.adb
4928 \begin_inset LatexCommand \index{<file>.adb}
4929
4930 \end_inset 
4931
4932  - An intermediate file containing debug information needed to create the
4933  .cdb file (with -
4934 \begin_inset ERT
4935 status Collapsed
4936
4937 \layout Standard
4938
4939 \backslash 
4940 /
4941 \end_inset 
4942
4943 -debug
4944 \begin_inset LatexCommand \index{-\/-debug}
4945
4946 \end_inset 
4947
4948
4949 \layout Itemize
4950
4951 sourcefile.cdb
4952 \begin_inset LatexCommand \index{<file>.cdb}
4953
4954 \end_inset 
4955
4956  - An optional file (with -
4957 \begin_inset ERT
4958 status Collapsed
4959
4960 \layout Standard
4961
4962 \backslash 
4963 /
4964 \end_inset 
4965
4966 -debug) containing debug information.
4967  The format is documented in cdbfileformat.pdf
4968 \layout Itemize
4969
4970 sourcefile.
4971  - (no extension)
4972 \begin_inset LatexCommand \index{<file> (no extension)}
4973
4974 \end_inset 
4975
4976  An optional AOMF or AOMF51
4977 \begin_inset LatexCommand \index{AOMF, AOMF51}
4978
4979 \end_inset 
4980
4981  
4982 \begin_inset LatexCommand \label{OMF file}
4983
4984 \end_inset 
4985
4986 file containing debug information (generated with option -
4987 \begin_inset ERT
4988 status Collapsed
4989
4990 \layout Standard
4991
4992 \backslash 
4993 /
4994 \end_inset 
4995
4996 -debug).
4997  The (Intel)
4998 \emph on 
4999  a
5000 \emph default 
5001 bsolute 
5002 \emph on 
5003 o
5004 \emph default 
5005 bject 
5006 \emph on 
5007 m
5008 \emph default 
5009 odule 
5010 \emph on 
5011 f
5012 \emph default 
5013 ormat is commonly used by third party tools (debuggers
5014 \begin_inset LatexCommand \index{Debugger}
5015
5016 \end_inset 
5017
5018 , simulators, emulators)
5019 \layout Itemize
5020
5021 sourcefile.dump*
5022 \begin_inset LatexCommand \index{<file>.dump*}
5023
5024 \end_inset 
5025
5026  - Dump file to debug the compiler it self (generated with option -
5027 \begin_inset ERT
5028 status Collapsed
5029
5030 \layout Standard
5031
5032 \backslash 
5033 /
5034 \end_inset 
5035
5036 -dumpall) (see section 
5037 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5038
5039 \end_inset 
5040
5041 \SpecialChar ~
5042  and section 
5043 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5044
5045 \end_inset 
5046
5047 \SpecialChar ~
5048
5049 \begin_inset Quotes sld
5050 \end_inset 
5051
5052 Anatomy of the compiler
5053 \begin_inset Quotes srd
5054 \end_inset 
5055
5056 ).
5057 \layout Subsection
5058
5059 Postprocessing the Intel Hex
5060 \begin_inset LatexCommand \index{Intel hex format}
5061
5062 \end_inset 
5063
5064  file
5065 \layout Standard
5066
5067 The Intel Hex file
5068 \begin_inset LatexCommand \index{<file>.ihx}
5069
5070 \end_inset 
5071
5072  which is generated by SDCC might include lines of varying length and the
5073  addresses within the file are not guaranteed to be strictly ascending.
5074  If your toolchain or a bootloader does not like this you can use the tool
5075  
5076 \family typewriter 
5077 packihx
5078 \family default 
5079
5080 \begin_inset LatexCommand \index{packihx (tool)}
5081
5082 \end_inset 
5083
5084  which is part of the SDCC distribution: 
5085 \newline 
5086
5087 \newline 
5088
5089 \family sans 
5090 \series bold 
5091  packihx sourcefile.ihx >sourcefile.hex
5092 \family default 
5093 \series default 
5094
5095 \newline 
5096
5097 \newline 
5098 The separately available
5099 \emph on 
5100  srecord
5101 \emph default 
5102
5103 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5104
5105 \end_inset 
5106
5107  package additionally allows to set undefined locations to a predefined
5108  value, to insert checksums of various flavours (crc, add, xor) and to perform
5109  other manipulations (convert, split, crop, offset, ...).
5110  
5111 \newline 
5112
5113 \newline 
5114
5115 \family sans 
5116 \series bold 
5117 srec_cat\SpecialChar ~
5118 \SpecialChar ~
5119 sourcefile.ihx -intel\SpecialChar ~
5120 \SpecialChar ~
5121 \SpecialChar ~
5122 -fill 0xff 0x0000 0x8000\SpecialChar ~
5123 \SpecialChar ~
5124 \SpecialChar ~
5125 -o sourcefile.hex -intel
5126 \newline 
5127
5128 \newline 
5129
5130 \family default 
5131 \series default 
5132 The srecord package is available at 
5133 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5134
5135 \end_inset 
5136
5137  .
5138 \layout Subsection
5139
5140 Projects with Multiple Source Files
5141 \layout Standard
5142
5143 SDCC can compile only ONE file at a time.
5144  Let us for example assume that you have a project containing the following
5145  files:
5146 \newline 
5147
5148 \newline 
5149 foo1.c (contains some functions)
5150 \newline 
5151 foo2.c (contains some more functions)
5152 \newline 
5153 foomain.c (contains more functions and the function main)
5154 \newline 
5155
5156 \size footnotesize 
5157
5158 \newline 
5159
5160 \size default 
5161 The first two files will need to be compiled separately with the commands:
5162 \size footnotesize 
5163  
5164 \size default 
5165
5166 \newline 
5167
5168 \newline 
5169
5170 \family sans 
5171 \series bold 
5172 sdcc\SpecialChar ~
5173 -c\SpecialChar ~
5174 foo1.c
5175 \family default 
5176 \series default 
5177 \size footnotesize 
5178
5179 \newline 
5180
5181 \family sans 
5182 \series bold 
5183 \size default 
5184 sdcc\SpecialChar ~
5185 -c\SpecialChar ~
5186 foo2.c
5187 \family default 
5188 \series default 
5189
5190 \newline 
5191
5192 \newline 
5193 Then compile the source file containing the 
5194 \emph on 
5195 main()
5196 \emph default 
5197  function and link
5198 \begin_inset LatexCommand \index{Linker}
5199
5200 \end_inset 
5201
5202  the files together with the following command: 
5203 \newline 
5204
5205 \newline 
5206
5207 \family sans 
5208 \series bold 
5209 sdcc\SpecialChar ~
5210 foomain.c\SpecialChar ~
5211 foo1.rel\SpecialChar ~
5212 foo2.rel
5213 \family default 
5214 \series default 
5215
5216 \begin_inset LatexCommand \index{<file>.rel}
5217
5218 \end_inset 
5219
5220
5221 \newline 
5222
5223 \newline 
5224 Alternatively, 
5225 \emph on 
5226 foomain.c 
5227 \emph default 
5228 can be separately compiled as well: 
5229 \family sans 
5230 \series bold 
5231
5232 \newline 
5233
5234 \newline 
5235 sdcc\SpecialChar ~
5236 -c\SpecialChar ~
5237 foomain.c
5238 \newline 
5239 sdcc foomain.rel foo1.rel foo2.rel
5240 \newline 
5241
5242 \newline 
5243
5244 \family default 
5245 \series default 
5246 The file containing the 
5247 \emph on 
5248 main()
5249 \emph default 
5250  function
5251 \emph on 
5252  
5253 \emph default 
5254 \noun on 
5255 must
5256 \noun default 
5257  be the 
5258 \noun on 
5259 first
5260 \noun default 
5261  file specified in the command line, since the linkage editor processes
5262  file in the order they are presented to it.
5263  The linker is invoked from SDCC using a script file with extension .lnk
5264 \begin_inset LatexCommand \index{<file>.lnk}
5265
5266 \end_inset 
5267
5268 .
5269  You can view this file to troubleshoot linking problems such as those arising
5270  from missing libraries.
5271 \layout Subsection
5272
5273 Projects with Additional Libraries
5274 \begin_inset LatexCommand \index{Libraries}
5275
5276 \end_inset 
5277
5278
5279 \layout Standard
5280
5281 Some reusable routines may be compiled into a library, see the documentation
5282  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5283  for how to create a 
5284 \emph on 
5285 .lib
5286 \begin_inset LatexCommand \index{<file>.lib}
5287
5288 \end_inset 
5289
5290
5291 \emph default 
5292  library file.
5293  Libraries created in this manner can be included in the command line.
5294  Make sure you include the -L <library-path> option to tell the linker where
5295  to look for these files if they are not in the current directory.
5296  Here is an example, assuming you have the source file 
5297 \emph on 
5298 foomain.c
5299 \emph default 
5300  and a library
5301 \emph on 
5302  foolib.lib
5303 \emph default 
5304  in the directory 
5305 \emph on 
5306 mylib
5307 \emph default 
5308  (if that is not the same as your current project):
5309 \newline 
5310
5311 \newline 
5312
5313 \family sans 
5314 \series bold 
5315 sdcc foomain.c foolib.lib -L mylib
5316 \newline 
5317
5318 \newline 
5319
5320 \family default 
5321 \series default 
5322 Note here that
5323 \emph on 
5324  mylib
5325 \emph default 
5326  must be an absolute path name.
5327 \newline 
5328
5329 \newline 
5330 The most efficient way to use libraries is to keep separate modules in separate
5331  source files.
5332  The lib file now should name all the modules.rel
5333 \begin_inset LatexCommand \index{<file>.rel}
5334
5335 \end_inset 
5336
5337  files.
5338  For an example see the standard library file 
5339 \emph on 
5340 libsdcc.lib
5341 \emph default 
5342  in the directory <installdir>/share/lib/small.
5343 \layout Subsection
5344
5345 Using sdcclib to Create and Manage Libraries
5346 \begin_inset LatexCommand \index{sdcclib}
5347
5348 \end_inset 
5349
5350
5351 \layout Standard
5352
5353 Alternatively, instead of having a .rel file for each entry on the library
5354  file as described in the preceding section, sdcclib can be used to embed
5355  all the modules belonging to such library in the library file itself.
5356  This results in a larger library file, but it greatly reduces the number
5357  of disk files accessed by the linker.
5358   Additionally, the packed library file contains an index of all include
5359  modules and symbols that significantly speeds up the linking process.
5360  To display a list of options supported by sdcclib type:
5361 \newline 
5362
5363 \layout Standard
5364
5365
5366 \family sans 
5367 \series bold 
5368 sdcclib -?
5369 \begin_inset LatexCommand \index{sdcclib}
5370
5371 \end_inset 
5372
5373
5374 \newline 
5375
5376 \newline 
5377
5378 \family default 
5379 \series default 
5380 To create a new library file, start by compiling all the required modules.
5381  For example:
5382 \newline 
5383
5384 \layout Standard
5385
5386
5387 \family sans 
5388 \series bold 
5389 sdcc -c _divsint.c
5390 \layout Standard
5391
5392
5393 \family sans 
5394 \series bold 
5395 sdcc -c _divuint.c
5396 \layout Standard
5397
5398
5399 \family sans 
5400 \series bold 
5401 sdcc -c _modsint.c
5402 \layout Standard
5403
5404
5405 \family sans 
5406 \series bold 
5407 sdcc -c _moduint.c
5408 \layout Standard
5409
5410
5411 \family sans 
5412 \series bold 
5413 sdcc -c _mulint.c
5414 \newline 
5415
5416 \layout Standard
5417
5418 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5419  and _mulint.rel.
5420  The next step is to add the .rel files to the library file:
5421 \newline 
5422
5423 \layout Standard
5424
5425
5426 \family sans 
5427 \series bold 
5428 sdcclib libint.lib _divsint.rel
5429 \family default 
5430
5431 \begin_inset LatexCommand \index{sdcclib}
5432
5433 \end_inset 
5434
5435
5436 \layout Standard
5437
5438
5439 \family sans 
5440 \series bold 
5441 sdcclib libint.lib _divuint.rel
5442 \layout Standard
5443
5444
5445 \family sans 
5446 \series bold 
5447 sdcclib libint.lib _modsint.rel
5448 \layout Standard
5449
5450
5451 \family sans 
5452 \series bold 
5453 sdcclib libint.lib _moduint.rel
5454 \layout Standard
5455
5456
5457 \family sans 
5458 \series bold 
5459 sdcclib libint.lib _mulint.rel
5460 \series default 
5461
5462 \newline 
5463
5464 \layout Standard
5465
5466 If the file already exists in the library, it will be replaced.
5467  To see what modules and symbols are included in the library, options -s
5468  and -m are available.
5469  For example:
5470 \newline 
5471
5472 \newline 
5473
5474 \family sans 
5475 \series bold 
5476 sdcclib -s libint.lib
5477 \family default 
5478
5479 \begin_inset LatexCommand \index{sdcclib}
5480
5481 \end_inset 
5482
5483
5484 \newline 
5485
5486 \family typewriter 
5487 \series default 
5488 _divsint.rel:
5489 \layout Standard
5490
5491
5492 \family typewriter 
5493 __divsint_a_1_1
5494 \layout Standard
5495
5496
5497 \family typewriter 
5498 __divsint_PARM_2
5499 \layout Standard
5500
5501
5502 \family typewriter 
5503 __divsint
5504 \newline 
5505 _divuint.rel:
5506 \layout Standard
5507
5508
5509 \family typewriter 
5510 __divuint_a_1_1
5511 \layout Standard
5512
5513
5514 \family typewriter 
5515 __divuint_PARM_2
5516 \layout Standard
5517
5518
5519 \family typewriter 
5520 __divuint_reste_1_1
5521 \layout Standard
5522
5523
5524 \family typewriter 
5525 __divuint_count_1_1
5526 \layout Standard
5527
5528
5529 \family typewriter 
5530 __divuint
5531 \newline 
5532 _modsint.rel:
5533 \layout Standard
5534
5535
5536 \family typewriter 
5537 __modsint_a_1_1
5538 \layout Standard
5539
5540
5541 \family typewriter 
5542 __modsint_PARM_2
5543 \layout Standard
5544
5545
5546 \family typewriter 
5547 __modsint
5548 \newline 
5549 _moduint.rel:
5550 \layout Standard
5551
5552
5553 \family typewriter 
5554 __moduint_a_1_1
5555 \layout Standard
5556
5557
5558 \family typewriter 
5559 __moduint_PARM_2
5560 \layout Standard
5561
5562
5563 \family typewriter 
5564 __moduint_count_1_1
5565 \layout Standard
5566
5567
5568 \family typewriter 
5569 __moduint
5570 \newline 
5571 _mulint.rel:
5572 \layout Standard
5573
5574
5575 \family typewriter 
5576 __mulint_PARM_2
5577 \layout Standard
5578
5579
5580 \family typewriter 
5581 __mulint
5582 \family default 
5583 \series bold 
5584
5585 \newline 
5586
5587 \layout Standard
5588 \added_space_bottom bigskip 
5589 If the source files are compiled using -
5590 \begin_inset ERT
5591 status Collapsed
5592
5593 \layout Standard
5594
5595 \backslash 
5596 /
5597 \end_inset 
5598
5599 -debug
5600 \begin_inset LatexCommand \index{-\/-debug}
5601
5602 \end_inset 
5603
5604 , the corresponding debug information file .adb will be include in the library
5605  file as well.
5606  The library files created with sdcclib are plain text files, so they can
5607  be viewed with a text editor.
5608  It is not recomended to modify a library file created with sdcclib using
5609  a text editor, as there are file indexes numbers located accross the file
5610  used by the linker to quickly locate the required module to link.
5611  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5612  it can be safely deleted, since all the information required for linking
5613  is embedded in the library file itself.
5614  Library files created using sdcclib are used as described in the preceding
5615  sections.
5616 \layout Section
5617
5618 Command Line Options
5619 \begin_inset LatexCommand \index{Command Line Options}
5620
5621 \end_inset 
5622
5623
5624 \layout Subsection
5625
5626 Processor Selection Options
5627 \begin_inset LatexCommand \index{Options processor selection}
5628
5629 \end_inset 
5630
5631
5632 \begin_inset LatexCommand \index{Processor selection options}
5633
5634 \end_inset 
5635
5636
5637 \layout List
5638 \labelwidthstring 00.00.0000
5639
5640
5641 \series bold 
5642 -mmcs51
5643 \begin_inset LatexCommand \index{-mmcs51}
5644
5645 \end_inset 
5646
5647
5648 \series default 
5649  Generate code for the Intel MCS51
5650 \begin_inset LatexCommand \index{MCS51}
5651
5652 \end_inset 
5653
5654  family of processors.
5655  This is the default processor target.
5656 \layout List
5657 \labelwidthstring 00.00.0000
5658
5659
5660 \series bold 
5661 -mds390
5662 \begin_inset LatexCommand \index{-mds390}
5663
5664 \end_inset 
5665
5666
5667 \series default 
5668  Generate code for the Dallas DS80C390
5669 \begin_inset LatexCommand \index{DS80C390}
5670
5671 \end_inset 
5672
5673  processor.
5674 \layout List
5675 \labelwidthstring 00.00.0000
5676
5677
5678 \series bold 
5679 -mds400
5680 \begin_inset LatexCommand \index{-mds400}
5681
5682 \end_inset 
5683
5684
5685 \series default 
5686  Generate code for the Dallas DS80C400
5687 \begin_inset LatexCommand \index{DS80C400}
5688
5689 \end_inset 
5690
5691  processor.
5692 \layout List
5693 \labelwidthstring 00.00.0000
5694
5695
5696 \series bold 
5697 -mhc08
5698 \begin_inset LatexCommand \index{-mhc08}
5699
5700 \end_inset 
5701
5702
5703 \series default 
5704  Generate code for the Freescale/Motorola HC08
5705 \begin_inset LatexCommand \index{HC08}
5706
5707 \end_inset 
5708
5709  family of processors.
5710 \layout List
5711 \labelwidthstring 00.00.0000
5712
5713
5714 \series bold 
5715 -mz80
5716 \begin_inset LatexCommand \index{-mz80}
5717
5718 \end_inset 
5719
5720
5721 \series default 
5722  Generate code for the Zilog Z80
5723 \begin_inset LatexCommand \index{Z80}
5724
5725 \end_inset 
5726
5727  family of processors.
5728 \layout List
5729 \labelwidthstring 00.00.0000
5730
5731
5732 \series bold 
5733 -mgbz80
5734 \begin_inset LatexCommand \index{-mgbz80}
5735
5736 \end_inset 
5737
5738
5739 \series default 
5740  Generate code for the GameBoy Z80
5741 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5742
5743 \end_inset 
5744
5745  processor (Not actively maintained).
5746 \layout List
5747 \labelwidthstring 00.00.0000
5748
5749
5750 \series bold 
5751 -mavr
5752 \begin_inset LatexCommand \index{-mavr}
5753
5754 \end_inset 
5755
5756
5757 \series default 
5758  Generate code for the Atmel AVR
5759 \begin_inset LatexCommand \index{AVR}
5760
5761 \end_inset 
5762
5763  processor (In development, not complete).
5764  AVR users should probably have a look at winavr 
5765 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5766
5767 \end_inset 
5768
5769  or 
5770 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5771
5772 \end_inset 
5773
5774 .
5775 \layout Comment
5776
5777 I think it is fair to direct users there for now.
5778  Open source is also about avoiding unnecessary work .
5779  But I didn't find the 'official' link.
5780 \layout List
5781 \labelwidthstring 00.00.0000
5782
5783
5784 \series bold 
5785 -mpic14
5786 \begin_inset LatexCommand \index{-mpic14}
5787
5788 \end_inset 
5789
5790
5791 \series default 
5792  Generate code for the Microchip PIC 14
5793 \begin_inset LatexCommand \index{PIC14}
5794
5795 \end_inset 
5796
5797 -bit processors (p16f84 and variants.
5798  In development, not complete).
5799 \layout Comment
5800
5801 p16f627 p16f628 p16f84 p16f873 p16f877?
5802 \layout List
5803 \labelwidthstring 00.00.0000
5804
5805
5806 \series bold 
5807 -mpic16
5808 \begin_inset LatexCommand \index{-mpic16}
5809
5810 \end_inset 
5811
5812
5813 \series default 
5814  Generate code for the Microchip PIC 16
5815 \begin_inset LatexCommand \index{PIC16}
5816
5817 \end_inset 
5818
5819 -bit processors (p18f452 and variants.
5820  In development, not complete).
5821 \layout List
5822 \labelwidthstring 00.00.0000
5823
5824
5825 \series bold 
5826 -mtlcs900h
5827 \series default 
5828  Generate code for the Toshiba TLCS-900H
5829 \begin_inset LatexCommand \index{TLCS-900H}
5830
5831 \end_inset 
5832
5833  processor (Not maintained, not complete).
5834 \layout List
5835 \added_space_bottom bigskip \labelwidthstring 00.00.0000
5836
5837
5838 \series bold 
5839 -mxa51
5840 \begin_inset LatexCommand \index{-mxa51}
5841
5842 \end_inset 
5843
5844
5845 \series default 
5846  Generate code for the Phillips XA51
5847 \begin_inset LatexCommand \index{XA51}
5848
5849 \end_inset 
5850
5851  processor (Not maintained, not complete).
5852 \layout Subsection
5853
5854 Preprocessor Options
5855 \begin_inset LatexCommand \index{Options preprocessor}
5856
5857 \end_inset 
5858
5859
5860 \begin_inset LatexCommand \index{Preprocessor options}
5861
5862 \end_inset 
5863
5864
5865 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5866
5867 \end_inset 
5868
5869
5870 \layout List
5871 \labelwidthstring 00.00.0000
5872
5873
5874 \series bold 
5875 -I<path>
5876 \begin_inset LatexCommand \index{-I<path>}
5877
5878 \end_inset 
5879
5880
5881 \series default 
5882  The additional location where the pre processor will look for <..h> or 
5883 \begin_inset Quotes eld
5884 \end_inset 
5885
5886 ..h
5887 \begin_inset Quotes erd
5888 \end_inset 
5889
5890  files.
5891 \layout List
5892 \labelwidthstring 00.00.0000
5893
5894
5895 \series bold 
5896 -D<macro[=value]>
5897 \begin_inset LatexCommand \index{-D<macro[=value]>}
5898
5899 \end_inset 
5900
5901
5902 \series default 
5903  Command line definition of macros.
5904  Passed to the preprocessor.
5905 \layout List
5906 \labelwidthstring 00.00.0000
5907
5908
5909 \series bold 
5910 -M
5911 \begin_inset LatexCommand \index{-M}
5912
5913 \end_inset 
5914
5915
5916 \series default 
5917  Tell the preprocessor to output a rule suitable for make describing the
5918  dependencies of each object file.
5919  For each source file, the preprocessor outputs one make-rule whose target
5920  is the object file name for that source file and whose dependencies are
5921  all the files `#include'd in it.
5922  This rule may be a single line or may be continued with `
5923 \backslash 
5924 '-newline if it is long.
5925  The list of rules is printed on standard output instead of the preprocessed
5926  C program.
5927  `-M' implies `-E
5928 \begin_inset LatexCommand \index{-E}
5929
5930 \end_inset 
5931
5932 '.
5933 \layout List
5934 \labelwidthstring 00.00.0000
5935
5936
5937 \series bold 
5938 -C
5939 \begin_inset LatexCommand \index{-C}
5940
5941 \end_inset 
5942
5943
5944 \series default 
5945  Tell the preprocessor not to discard comments.
5946  Used with the `-E' option.
5947 \layout List
5948 \labelwidthstring 00.00.0000
5949
5950
5951 \series bold 
5952 -MM
5953 \begin_inset LatexCommand \index{-MM}
5954
5955 \end_inset 
5956
5957
5958 \size large 
5959 \bar under 
5960  
5961 \series default 
5962 \size default 
5963 \bar default 
5964 Like `-M' but the output mentions only the user header files included with
5965  `#include 
5966 \begin_inset Quotes eld
5967 \end_inset 
5968
5969 file"'.
5970  System header files included with `#include <file>' are omitted.
5971 \layout List
5972 \labelwidthstring 00.00.0000
5973
5974
5975 \series bold 
5976 -Aquestion(answer)
5977 \begin_inset LatexCommand \index{-Aquestion(answer)}
5978
5979 \end_inset 
5980
5981
5982 \series default 
5983  Assert the answer answer for question, in case it is tested with a preprocessor
5984  conditional such as `#if #question(answer)'.
5985  `-A-' disables the standard assertions that normally describe the target
5986  machine.
5987 \layout List
5988 \labelwidthstring 00.00.0000
5989
5990
5991 \series bold 
5992 -Umacro
5993 \begin_inset LatexCommand \index{-Umacro}
5994
5995 \end_inset 
5996
5997
5998 \series default 
5999  Undefine macro macro.
6000  `-U' options are evaluated after all `-D' options, but before any `-include'
6001  and `-imacros' options.
6002 \layout List
6003 \labelwidthstring 00.00.0000
6004
6005
6006 \series bold 
6007 -dM
6008 \begin_inset LatexCommand \index{-dM}
6009
6010 \end_inset 
6011
6012
6013 \series default 
6014  Tell the preprocessor to output only a list of the macro definitions that
6015  are in effect at the end of preprocessing.
6016  Used with the `-E' option.
6017 \layout List
6018 \labelwidthstring 00.00.0000
6019
6020
6021 \series bold 
6022 -dD
6023 \begin_inset LatexCommand \index{-dD}
6024
6025 \end_inset 
6026
6027
6028 \series default 
6029  Tell the preprocessor to pass all macro definitions into the output, in
6030  their proper sequence in the rest of the output.
6031 \layout List
6032 \labelwidthstring 00.00.0000
6033
6034
6035 \series bold 
6036 -dN
6037 \begin_inset LatexCommand \index{-dN}
6038
6039 \end_inset 
6040
6041
6042 \size large 
6043 \bar under 
6044  
6045 \series default 
6046 \size default 
6047 \bar default 
6048 Like `-dD' except that the macro arguments and contents are omitted.
6049  Only `#define name' is included in the output.
6050 \layout List
6051 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6052
6053
6054 \series bold 
6055 -Wp\SpecialChar ~
6056 preprocessorOption[,preprocessorOption]
6057 \series default 
6058
6059 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6060
6061 \end_inset 
6062
6063 ...
6064  Pass the preprocessorOption to the preprocessor 
6065 \family typewriter 
6066 sdcpp
6067 \family default 
6068
6069 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6070
6071 \end_inset 
6072
6073 .
6074  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
6075  Collection (gcc), if you need more dedicated options please refer to the
6076  documentation at 
6077 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6078
6079 \end_inset 
6080
6081 .
6082 \layout Subsection
6083
6084 Linker Options
6085 \begin_inset LatexCommand \index{Options linker}
6086
6087 \end_inset 
6088
6089
6090 \begin_inset LatexCommand \index{Linker options}
6091
6092 \end_inset 
6093
6094
6095 \layout List
6096 \labelwidthstring 00.00.0000
6097
6098
6099 \series bold 
6100 -L\SpecialChar ~
6101 -
6102 \series default 
6103
6104 \begin_inset ERT
6105 status Collapsed
6106
6107 \layout Standard
6108
6109 \backslash 
6110 /
6111 \end_inset 
6112
6113
6114 \series bold 
6115 -lib-path
6116 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6117
6118 \end_inset 
6119
6120
6121 \begin_inset LatexCommand \index{-L -\/-lib-path}
6122
6123 \end_inset 
6124
6125
6126 \series default 
6127 \SpecialChar ~
6128 <absolute path to additional libraries> This option is passed to the linkage
6129  editor's additional libraries
6130 \begin_inset LatexCommand \index{Libraries}
6131
6132 \end_inset 
6133
6134  search path.
6135  The path name must be absolute.
6136  Additional library files may be specified in the command line.
6137  See section Compiling programs for more details.
6138 \layout List
6139 \labelwidthstring 00.00.0000
6140
6141
6142 \series bold 
6143 -
6144 \begin_inset ERT
6145 status Collapsed
6146
6147 \layout Standard
6148
6149 \backslash 
6150 /
6151 \end_inset 
6152
6153 -xram-loc
6154 \series default 
6155
6156 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6157
6158 \end_inset 
6159
6160 \SpecialChar ~
6161 <Value> The start location of the external ram
6162 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6163
6164 \end_inset 
6165
6166 , default value is 0.
6167  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6168 \begin_inset ERT
6169 status Collapsed
6170
6171 \layout Standard
6172
6173 \backslash 
6174 /
6175 \end_inset 
6176
6177 -xram-loc 0x8000 or -
6178 \begin_inset ERT
6179 status Collapsed
6180
6181 \layout Standard
6182
6183 \backslash 
6184 /
6185 \end_inset 
6186
6187 -xram-loc 32768.
6188 \layout List
6189 \labelwidthstring 00.00.0000
6190
6191
6192 \series bold 
6193 -
6194 \begin_inset ERT
6195 status Collapsed
6196
6197 \layout Standard
6198
6199 \backslash 
6200 /
6201 \end_inset 
6202
6203 -code-loc
6204 \series default 
6205
6206 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6207
6208 \end_inset 
6209
6210 \SpecialChar ~
6211 <Value> The start location of the code
6212 \begin_inset LatexCommand \index{code}
6213
6214 \end_inset 
6215
6216  segment, default value 0.
6217  Note when this option is used the interrupt vector table is also relocated
6218  to the given address.
6219  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6220 \begin_inset ERT
6221 status Collapsed
6222
6223 \layout Standard
6224
6225 \backslash 
6226 /
6227 \end_inset 
6228
6229 -code-loc 0x8000 or -
6230 \begin_inset ERT
6231 status Collapsed
6232
6233 \layout Standard
6234
6235 \backslash 
6236 /
6237 \end_inset 
6238
6239 -code-loc 32768.
6240 \layout List
6241 \labelwidthstring 00.00.0000
6242
6243
6244 \series bold 
6245 -
6246 \begin_inset ERT
6247 status Collapsed
6248
6249 \layout Standard
6250
6251 \backslash 
6252 /
6253 \end_inset 
6254
6255 -stack-loc
6256 \series default 
6257
6258 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6259
6260 \end_inset 
6261
6262 \SpecialChar ~
6263 <Value> By default the stack
6264 \begin_inset LatexCommand \index{stack}
6265
6266 \end_inset 
6267
6268  is placed after the data segment.
6269  Using this option the stack can be placed anywhere in the internal memory
6270  space of the 8051.
6271  The value entered can be in Hexadecimal or Decimal format, e.g.
6272  -
6273 \begin_inset ERT
6274 status Collapsed
6275
6276 \layout Standard
6277
6278 \backslash 
6279 /
6280 \end_inset 
6281
6282 -stack-loc 0x20 or -
6283 \begin_inset ERT
6284 status Collapsed
6285
6286 \layout Standard
6287
6288 \backslash 
6289 /
6290 \end_inset 
6291
6292 -stack-loc 32.
6293  Since the sp register is incremented before a push or call, the initial
6294  sp will be set to one byte prior the provided value.
6295  The provided value should not overlap any other memory areas such as used
6296  register banks or the data segment and with enough space for the current
6297  application.
6298  The 
6299 \series bold 
6300 -
6301 \begin_inset ERT
6302 status Collapsed
6303
6304 \layout Standard
6305
6306 \backslash 
6307 /
6308 \end_inset 
6309
6310 -pack-iram
6311 \series default 
6312 \SpecialChar ~
6313
6314 \begin_inset LatexCommand \index{-\/-pack-iram}
6315
6316 \end_inset 
6317
6318  option (which is now a default setting) will override this setting, so
6319  you should also specify the 
6320 \series bold 
6321 -
6322 \begin_inset ERT
6323 status Collapsed
6324
6325 \layout Standard
6326
6327 \backslash 
6328 /
6329 \end_inset 
6330
6331 -no-pack-iram
6332 \series default 
6333 \SpecialChar ~
6334
6335 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6336
6337 \end_inset 
6338
6339  option if you need to manually place the stack.
6340 \layout List
6341 \labelwidthstring 00.00.0000
6342
6343
6344 \series bold 
6345 -
6346 \begin_inset ERT
6347 status Collapsed
6348
6349 \layout Standard
6350
6351 \backslash 
6352 /
6353 \end_inset 
6354
6355 -xstack-loc
6356 \series default 
6357
6358 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6359
6360 \end_inset 
6361
6362 \SpecialChar ~
6363 <Value> By default the external stack
6364 \begin_inset LatexCommand \index{xstack}
6365
6366 \end_inset 
6367
6368  is placed after the pdata
6369 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6370
6371 \end_inset 
6372
6373  segment.
6374  Using this option the xstack can be placed anywhere in the external memory
6375  space of the 8051.
6376  The value entered can be in Hexadecimal or Decimal format, e.g.
6377  -
6378 \begin_inset ERT
6379 status Collapsed
6380
6381 \layout Standard
6382
6383 \backslash 
6384 /
6385 \end_inset 
6386
6387 -xstack-loc 0x8000 or -
6388 \begin_inset ERT
6389 status Collapsed
6390
6391 \layout Standard
6392
6393 \backslash 
6394 /
6395 \end_inset 
6396
6397 -stack-loc 32768.
6398  The provided value should not overlap any other memory areas such as the
6399  pdata or xdata segment and with enough space for the current application.
6400 \layout List
6401 \labelwidthstring 00.00.0000
6402
6403
6404 \series bold 
6405 -
6406 \begin_inset ERT
6407 status Collapsed
6408
6409 \layout Standard
6410
6411 \backslash 
6412 /
6413 \end_inset 
6414
6415 -data-loc
6416 \series default 
6417
6418 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6419
6420 \end_inset 
6421
6422 \SpecialChar ~
6423 <Value> The start location of the internal ram data
6424 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6425
6426 \end_inset 
6427
6428  segment.
6429  The value entered can be in Hexadecimal or Decimal format, eg.
6430  -
6431 \begin_inset ERT
6432 status Collapsed
6433
6434 \layout Standard
6435
6436 \backslash 
6437 /
6438 \end_inset 
6439
6440 -data-loc 0x20 or -
6441 \begin_inset ERT
6442 status Collapsed
6443
6444 \layout Standard
6445
6446 \backslash 
6447 /
6448 \end_inset 
6449
6450 -data-loc 32.
6451  (By default, the start location of the internal ram data segment  is set
6452  as low as possible in memory, taking into account the used register banks
6453  and the bit segment at address 0x20.
6454  For example if register banks 0 and 1 are used without bit variables, the
6455  data segment will be set, if -
6456 \begin_inset ERT
6457 status Collapsed
6458
6459 \layout Standard
6460
6461 \backslash 
6462 /
6463 \end_inset 
6464
6465 -data-loc is not used, to location 0x10.)
6466 \layout List
6467 \labelwidthstring 00.00.0000
6468
6469
6470 \series bold 
6471 -
6472 \begin_inset ERT
6473 status Collapsed
6474
6475 \layout Standard
6476
6477 \backslash 
6478 /
6479 \end_inset 
6480
6481 -idata-loc
6482 \series default 
6483
6484 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6485
6486 \end_inset 
6487
6488 \SpecialChar ~
6489 <Value> The start location of the indirectly addressable internal ram
6490 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6491
6492 \end_inset 
6493
6494  of the 8051, default value is 0x80.
6495  The value entered can be in Hexadecimal or Decimal format, eg.
6496  -
6497 \begin_inset ERT
6498 status Collapsed
6499
6500 \layout Standard
6501
6502 \backslash 
6503 /
6504 \end_inset 
6505
6506 -idata-loc 0x88 or -
6507 \begin_inset ERT
6508 status Collapsed
6509
6510 \layout Standard
6511
6512 \backslash 
6513 /
6514 \end_inset 
6515
6516 -idata-loc 136.
6517 \layout List
6518 \labelwidthstring 00.00.0000
6519
6520
6521 \series bold 
6522 -
6523 \begin_inset ERT
6524 status Collapsed
6525
6526 \layout Standard
6527
6528 \backslash 
6529 /
6530 \end_inset 
6531
6532 -bit-loc
6533 \series default 
6534 \SpecialChar ~
6535 <Value> The start location of the bit
6536 \begin_inset LatexCommand \index{bit}
6537
6538 \end_inset 
6539
6540  addressable internal ram of the 8051.
6541  This is 
6542 \emph on 
6543 not
6544 \emph default 
6545  implemented yet.
6546  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6547 -bBSEG=<Value>.
6548 \layout List
6549 \labelwidthstring 00.00.0000
6550
6551
6552 \series bold 
6553 -
6554 \begin_inset ERT
6555 status Collapsed
6556
6557 \layout Standard
6558
6559 \backslash 
6560 /
6561 \end_inset 
6562
6563 -out-fmt-ihx
6564 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6565
6566 \end_inset 
6567
6568
6569 \bar under 
6570  
6571 \series default 
6572 \bar default 
6573 The linker output (final object code) is in Intel Hex format.
6574 \begin_inset LatexCommand \index{Intel hex format}
6575
6576 \end_inset 
6577
6578  This is the default option.
6579  The format itself is documented in the documentation of srecord
6580 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6581
6582 \end_inset 
6583
6584 .
6585 \layout List
6586 \labelwidthstring 00.00.0000
6587
6588
6589 \series bold 
6590 -
6591 \begin_inset ERT
6592 status Collapsed
6593
6594 \layout Standard
6595
6596 \backslash 
6597 /
6598 \end_inset 
6599
6600 -out-fmt-s19
6601 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6602
6603 \end_inset 
6604
6605
6606 \bar under 
6607  
6608 \series default 
6609 \bar default 
6610 The linker output (final object code) is in Motorola S19 format
6611 \begin_inset LatexCommand \index{Motorola S19 format}
6612
6613 \end_inset 
6614
6615 .
6616  The format itself is documented in the documentation of srecord.
6617 \layout List
6618 \labelwidthstring 00.00.0000
6619
6620
6621 \series bold 
6622 -
6623 \begin_inset ERT
6624 status Collapsed
6625
6626 \layout Standard
6627
6628 \backslash 
6629 /
6630 \end_inset 
6631
6632 -out-fmt-elf
6633 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6634
6635 \end_inset 
6636
6637
6638 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6639
6640 \end_inset 
6641
6642
6643 \bar under 
6644  
6645 \series default 
6646 \bar default 
6647 The linker output (final object code) is in ELF format
6648 \begin_inset LatexCommand \index{ELF format}
6649
6650 \end_inset 
6651
6652 .
6653  (Currently only supported for the HC08
6654 \begin_inset LatexCommand \index{HC08}
6655
6656 \end_inset 
6657
6658  processors)
6659 \layout List
6660 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6661
6662
6663 \series bold 
6664 -Wl\SpecialChar ~
6665 linkOption[,linkOption]
6666 \series default 
6667
6668 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6669
6670 \end_inset 
6671
6672 ...
6673  Pass the linkOption to the linker.
6674  If a bootloader is used an option like 
6675 \begin_inset Quotes sld
6676 \end_inset 
6677
6678 -Wl\SpecialChar ~
6679 -bCSEG=0x1000
6680 \begin_inset Quotes srd
6681 \end_inset 
6682
6683  would be typical to set the start of the code segment.
6684  See also #pragma constseg and #pragma codeseg in section 
6685 \begin_inset LatexCommand \ref{sec:Pragmas}
6686
6687 \end_inset 
6688
6689  .
6690  File sdcc/as/doc/asxhtm.html has more on linker options.
6691 \layout Subsection
6692
6693 MCS51 Options
6694 \begin_inset LatexCommand \index{Options MCS51}
6695
6696 \end_inset 
6697
6698
6699 \begin_inset LatexCommand \index{MCS51 options}
6700
6701 \end_inset 
6702
6703
6704 \layout List
6705 \labelwidthstring 00.00.0000
6706
6707
6708 \series bold 
6709 -
6710 \begin_inset ERT
6711 status Collapsed
6712
6713 \layout Standard
6714
6715 \backslash 
6716 /
6717 \end_inset 
6718
6719 -model-small
6720 \begin_inset LatexCommand \index{-\/-model-small}
6721
6722 \end_inset 
6723
6724
6725 \series default 
6726 \size large 
6727 \emph on 
6728  
6729 \size default 
6730 \emph default 
6731 Generate code for Small Model programs, see section Memory Models for more
6732  details.
6733  This is the default model.
6734 \layout List
6735 \labelwidthstring 00.00.0000
6736
6737
6738 \series bold 
6739 -
6740 \begin_inset ERT
6741 status Collapsed
6742
6743 \layout Standard
6744
6745 \backslash 
6746 /
6747 \end_inset 
6748
6749 -model-medium
6750 \begin_inset LatexCommand \index{-\/-model-medium}
6751
6752 \end_inset 
6753
6754
6755 \series default 
6756  Generate code for Medium model programs, see section Memory Models for
6757  more details.
6758  If this option is used all source files in the project have to be compiled
6759  with this option.
6760  It must also be used when invoking the linker.
6761 \layout List
6762 \labelwidthstring 00.00.0000
6763
6764
6765 \series bold 
6766 -
6767 \begin_inset ERT
6768 status Collapsed
6769
6770 \layout Standard
6771
6772 \backslash 
6773 /
6774 \end_inset 
6775
6776 -model-large
6777 \begin_inset LatexCommand \index{-\/-model-large}
6778
6779 \end_inset 
6780
6781
6782 \series default 
6783  Generate code for Large model programs, see section Memory Models for more
6784  details.
6785  If this option is used all source files in the project have to be compiled
6786  with this option.
6787  It must also be used when invoking the linker.
6788 \layout List
6789 \labelwidthstring 00.00.0000
6790
6791
6792 \series bold 
6793 -
6794 \begin_inset ERT
6795 status Collapsed
6796
6797 \layout Standard
6798
6799 \backslash 
6800 /
6801 \end_inset 
6802
6803 -xstack
6804 \begin_inset LatexCommand \index{-\/-xstack}
6805
6806 \end_inset 
6807
6808
6809 \series default 
6810  Uses a pseudo stack in the pdata
6811 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6812
6813 \end_inset 
6814
6815  area (usually the first 256 bytes in the external ram) for allocating variables
6816  and passing parameters.
6817  See section 
6818 \begin_inset LatexCommand \ref{sub:External-Stack}
6819
6820 \end_inset 
6821
6822 \SpecialChar ~
6823  External Stack for more details.
6824 \layout List
6825 \labelwidthstring 00.00.0000
6826
6827
6828 \series bold 
6829 -
6830 \begin_inset ERT
6831 status Collapsed
6832
6833 \layout Standard
6834
6835 \backslash 
6836 /
6837 \end_inset 
6838
6839 -iram-size
6840 \series default 
6841 \SpecialChar ~
6842 <Value>
6843 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6844
6845 \end_inset 
6846
6847  Causes the linker to check if the internal ram usage is within limits of
6848  the given value.
6849 \layout List
6850 \labelwidthstring 00.00.0000
6851
6852
6853 \series bold 
6854 -
6855 \begin_inset ERT
6856 status Collapsed
6857
6858 \layout Standard
6859
6860 \backslash 
6861 /
6862 \end_inset 
6863
6864 -xram-size
6865 \series default 
6866 \SpecialChar ~
6867 <Value>
6868 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6869
6870 \end_inset 
6871
6872  Causes the linker to check if the external ram usage is within limits of
6873  the given value.
6874 \layout List
6875 \labelwidthstring 00.00.0000
6876
6877
6878 \series bold 
6879 -
6880 \begin_inset ERT
6881 status Collapsed
6882
6883 \layout Standard
6884
6885 \backslash 
6886 /
6887 \end_inset 
6888
6889 -code-size
6890 \series default 
6891 \SpecialChar ~
6892 <Value>
6893 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6894
6895 \end_inset 
6896
6897  Causes the linker to check if the code memory usage is within limits of
6898  the given value.
6899 \layout List
6900 \labelwidthstring 00.00.0000
6901
6902
6903 \series bold 
6904 -
6905 \begin_inset ERT
6906 status Collapsed
6907
6908 \layout Standard
6909
6910 \backslash 
6911 /
6912 \end_inset 
6913
6914 -stack-size
6915 \series default 
6916 \SpecialChar ~
6917 <Value>
6918 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6919
6920 \end_inset 
6921
6922  Causes the linker to check if there is at minimum <Value> bytes for stack.
6923 \layout List
6924 \labelwidthstring 00.00.0000
6925
6926
6927 \series bold 
6928 -
6929 \begin_inset ERT
6930 status Collapsed
6931
6932 \layout Standard
6933
6934 \backslash 
6935 /
6936 \end_inset 
6937
6938 -pack-iram
6939 \series default 
6940 \SpecialChar ~
6941
6942 \begin_inset LatexCommand \index{-\/-pack-iram}
6943
6944 \end_inset 
6945
6946  Causes the linker to use unused register banks for data variables and pack
6947  data, idata and stack together.
6948  This is the default now.
6949 \layout List
6950 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6951
6952
6953 \series bold 
6954 -
6955 \begin_inset ERT
6956 status Collapsed
6957
6958 \layout Standard
6959
6960 \backslash 
6961 /
6962 \end_inset 
6963
6964 -no-pack-iram
6965 \series default 
6966 \SpecialChar ~
6967
6968 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6969
6970 \end_inset 
6971
6972  Causes the linker to use old style for allocating memory areas.
6973 \layout Subsection
6974
6975 DS390 / DS400 Options
6976 \begin_inset LatexCommand \index{Options DS390}
6977
6978 \end_inset 
6979
6980
6981 \begin_inset LatexCommand \index{DS390}
6982
6983 \end_inset 
6984
6985
6986 \layout List
6987 \labelwidthstring 00.00.0000
6988
6989
6990 \series bold 
6991 -
6992 \begin_inset ERT
6993 status Collapsed
6994
6995 \layout Standard
6996
6997 \backslash 
6998 /
6999 \end_inset 
7000
7001 -model-flat24
7002 \series default 
7003
7004 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7005
7006 \end_inset 
7007
7008
7009 \size large 
7010 \emph on 
7011  
7012 \size default 
7013 \emph default 
7014 Generate 24-bit flat mode code.
7015  This is the one and only that the ds390 code generator supports right now
7016  and is default when using 
7017 \emph on 
7018 -mds390
7019 \emph default 
7020 .
7021  See section Memory Models for more details.
7022 \layout List
7023 \labelwidthstring 00.00.0000
7024
7025
7026 \series bold 
7027 -
7028 \begin_inset ERT
7029 status Collapsed
7030
7031 \layout Standard
7032
7033 \backslash 
7034 /
7035 \end_inset 
7036
7037 -protect-sp-update
7038 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7039
7040 \end_inset 
7041
7042
7043 \series default 
7044  disable interrupts during ESP:SP updates.
7045 \layout List
7046 \labelwidthstring 00.00.0000
7047
7048
7049 \series bold 
7050 -
7051 \begin_inset ERT
7052 status Collapsed
7053
7054 \layout Standard
7055
7056 \backslash 
7057 /
7058 \end_inset 
7059
7060 -stack-10bit
7061 \series default 
7062
7063 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7064
7065 \end_inset 
7066
7067  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7068  This is the one and only that the ds390 code generator supports right now
7069  and is default when using 
7070 \emph on 
7071 -mds390
7072 \emph default 
7073 .
7074  In this mode, the stack is located in the lower 1K of the internal RAM,
7075  which is mapped to 0x400000.
7076  Note that the support is incomplete, since it still uses a single byte
7077  as the stack pointer.
7078  This means that only the lower 256 bytes of the potential 1K stack space
7079  will actually be used.
7080  However, this does allow you to reclaim the precious 256 bytes of low RAM
7081  for use for the DATA and IDATA segments.
7082  The compiler will not generate any code to put the processor into 10 bit
7083  stack mode.
7084  It is important to ensure that the processor is in this mode before calling
7085  any re-entrant functions compiled with this option.
7086  In principle, this should work with the 
7087 \emph on 
7088 -
7089 \begin_inset ERT
7090 status Collapsed
7091
7092 \layout Standard
7093
7094 \backslash 
7095 /
7096 \end_inset 
7097
7098 -stack-auto
7099 \begin_inset LatexCommand \index{-\/-stack-auto}
7100
7101 \end_inset 
7102
7103
7104 \emph default 
7105  option, but that has not been tested.
7106  It is incompatible with the 
7107 \emph on 
7108 -
7109 \begin_inset ERT
7110 status Collapsed
7111
7112 \layout Standard
7113
7114 \backslash 
7115 /
7116 \end_inset 
7117
7118 -xstack
7119 \begin_inset LatexCommand \index{-\/-xstack}
7120
7121 \end_inset 
7122
7123
7124 \emph default 
7125  option.
7126  It also only makes sense if the processor is in 24 bit contiguous addressing
7127  mode (see the 
7128 \emph on 
7129 -
7130 \begin_inset ERT
7131 status Collapsed
7132
7133 \layout Standard
7134
7135 \backslash 
7136 /
7137 \end_inset 
7138
7139 -model-flat24 option
7140 \emph default 
7141 ).
7142 \layout List
7143 \labelwidthstring 00.00.0000
7144
7145
7146 \series bold 
7147 -
7148 \begin_inset ERT
7149 status Collapsed
7150
7151 \layout Standard
7152
7153 \backslash 
7154 /
7155 \end_inset 
7156
7157 -stack-probe
7158 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7159
7160 \end_inset 
7161
7162
7163 \series default 
7164  insert call to function __stack_probe at each function prologue.
7165 \layout List
7166 \labelwidthstring 00.00.0000
7167
7168
7169 \series bold 
7170 -
7171 \begin_inset ERT
7172 status Collapsed
7173
7174 \layout Standard
7175
7176 \backslash 
7177 /
7178 \end_inset 
7179
7180 -tini-libid
7181 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7182
7183 \end_inset 
7184
7185
7186 \series default 
7187  <nnnn> LibraryID used in -mTININative.
7188  
7189 \layout List
7190 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7191
7192
7193 \series bold 
7194 -
7195 \begin_inset ERT
7196 status Collapsed
7197
7198 \layout Standard
7199
7200 \backslash 
7201 /
7202 \end_inset 
7203
7204 -use-accelerator
7205 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7206
7207 \end_inset 
7208
7209
7210 \series default 
7211  generate code for DS390 Arithmetic Accelerator.
7212  
7213 \layout Subsection
7214
7215 Z80 Options
7216 \begin_inset LatexCommand \index{Options Z80}
7217
7218 \end_inset 
7219
7220
7221 \begin_inset LatexCommand \index{Z80}
7222
7223 \end_inset 
7224
7225
7226 \layout List
7227 \labelwidthstring 00.00.0000
7228
7229
7230 \series bold 
7231 -
7232 \begin_inset ERT
7233 status Collapsed
7234
7235 \layout Standard
7236
7237 \backslash 
7238 /
7239 \end_inset 
7240
7241 -callee-saves-bc
7242 \series default 
7243
7244 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7245
7246 \end_inset 
7247
7248
7249 \size large 
7250 \emph on 
7251  
7252 \size default 
7253 \emph default 
7254 Force a called function to always save BC.
7255 \layout List
7256 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7257
7258
7259 \series bold 
7260 -
7261 \begin_inset ERT
7262 status Collapsed
7263
7264 \layout Standard
7265
7266 \backslash 
7267 /
7268 \end_inset 
7269
7270 -no-std-crt0
7271 \series default 
7272
7273 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7274
7275 \end_inset 
7276
7277  When linking, skip the standard crt0.o object file.
7278  You must provide your own crt0.o for your system when linking.
7279  
7280 \layout Subsection
7281
7282 Optimization Options
7283 \begin_inset LatexCommand \index{Options optimization}
7284
7285 \end_inset 
7286
7287
7288 \begin_inset LatexCommand \index{Optimization options}
7289
7290 \end_inset 
7291
7292
7293 \layout List
7294 \labelwidthstring 00.00.0000
7295
7296
7297 \series bold 
7298 -
7299 \begin_inset ERT
7300 status Collapsed
7301
7302 \layout Standard
7303
7304 \backslash 
7305 /
7306 \end_inset 
7307
7308 -nogcse
7309 \begin_inset LatexCommand \index{-\/-nogcse}
7310
7311 \end_inset 
7312
7313
7314 \series default 
7315  Will not do global subexpression elimination, this option may be used when
7316  the compiler creates undesirably large stack/data spaces to store compiler
7317  temporaries (
7318 \emph on 
7319 s
7320 \emph default 
7321 pill 
7322 \emph on 
7323 loc
7324 \emph default 
7325 ations, sloc
7326 \begin_inset LatexCommand \index{sloc (spill location)}
7327
7328 \end_inset 
7329
7330 ).
7331  A warning message will be generated when this happens and the compiler
7332  will indicate the number of extra bytes it allocated.
7333  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7334 nogcse
7335 \begin_inset LatexCommand \index{\#pragma nogcse}
7336
7337 \end_inset 
7338
7339  can be used to turn off global subexpression elimination
7340 \begin_inset LatexCommand \index{Subexpression elimination}
7341
7342 \end_inset 
7343
7344  for a given function only.
7345 \layout List
7346 \labelwidthstring 00.00.0000
7347
7348
7349 \series bold 
7350 -
7351 \begin_inset ERT
7352 status Collapsed
7353
7354 \layout Standard
7355
7356 \backslash 
7357 /
7358 \end_inset 
7359
7360 -noinvariant
7361 \begin_inset LatexCommand \index{-\/-noinvariant}
7362
7363 \end_inset 
7364
7365
7366 \series default 
7367  Will not do loop invariant optimizations, this may be turned off for reasons
7368  explained for the previous option.
7369  For more details of loop optimizations performed see Loop Invariants in
7370  section 
7371 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7372
7373 \end_inset 
7374
7375 .
7376  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7377 noinvariant
7378 \begin_inset LatexCommand \index{\#pragma noinvariant}
7379
7380 \end_inset 
7381
7382  can be used to turn off invariant optimizations for a given function only.
7383 \layout List
7384 \labelwidthstring 00.00.0000
7385
7386
7387 \series bold 
7388 -
7389 \begin_inset ERT
7390 status Collapsed
7391
7392 \layout Standard
7393
7394 \backslash 
7395 /
7396 \end_inset 
7397
7398 -noinduction
7399 \begin_inset LatexCommand \index{-\/-noinduction}
7400
7401 \end_inset 
7402
7403
7404 \series default 
7405  Will not do loop induction optimizations, see section strength reduction
7406  for more details.
7407  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7408 noinduction
7409 \begin_inset LatexCommand \index{\#pragma noinduction}
7410
7411 \end_inset 
7412
7413  can be used to turn off induction optimizations for a given function only.
7414 \layout List
7415 \labelwidthstring 00.00.0000
7416
7417
7418 \series bold 
7419 -
7420 \begin_inset ERT
7421 status Collapsed
7422
7423 \layout Standard
7424
7425 \backslash 
7426 /
7427 \end_inset 
7428
7429 -nojtbound
7430 \begin_inset LatexCommand \index{-\/-nojtbound}
7431
7432 \end_inset 
7433
7434
7435 \size large 
7436 \bar under 
7437  
7438 \series default 
7439 \size default 
7440 \bar default 
7441  Will not generate boundary condition check when switch statements
7442 \begin_inset LatexCommand \index{switch statement}
7443
7444 \end_inset 
7445
7446  are implemented using jump-tables.
7447  See section 
7448 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7449
7450 \end_inset 
7451
7452 \SpecialChar ~
7453 Switch Statements for more details.
7454  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7455 nojtbound
7456 \begin_inset LatexCommand \index{\#pragma nojtbound}
7457
7458 \end_inset 
7459
7460  can be used to turn off boundary checking for jump tables for a given function
7461  only.
7462 \layout List
7463 \labelwidthstring 00.00.0000
7464
7465
7466 \series bold 
7467 -
7468 \begin_inset ERT
7469 status Collapsed
7470
7471 \layout Standard
7472
7473 \backslash 
7474 /
7475 \end_inset 
7476
7477 -noloopreverse
7478 \begin_inset LatexCommand \index{-\/-noloopreverse}
7479
7480 \end_inset 
7481
7482
7483 \series default 
7484 \size large 
7485  
7486 \size default 
7487 Will not do loop reversal 
7488 \begin_inset LatexCommand \index{Loop reversing}
7489
7490 \end_inset 
7491
7492 optimization.
7493 \layout List
7494 \labelwidthstring 00.00.0000
7495
7496 -
7497 \begin_inset ERT
7498 status Collapsed
7499
7500 \layout Standard
7501
7502 \backslash 
7503 /
7504 \end_inset 
7505
7506 -
7507 \series bold 
7508 nolabelopt
7509 \series default 
7510  
7511 \begin_inset LatexCommand \index{-\/-nolabelopt }
7512
7513 \end_inset 
7514
7515 Will not optimize labels (makes the dumpfiles more readable).
7516 \layout List
7517 \labelwidthstring 00.00.0000
7518
7519
7520 \series bold 
7521 -
7522 \begin_inset ERT
7523 status Collapsed
7524
7525 \layout Standard
7526
7527 \backslash 
7528 /
7529 \end_inset 
7530
7531 -no-xinit-opt
7532 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7533
7534 \end_inset 
7535
7536
7537 \series default 
7538  Will not memcpy initialized data from code space into xdata space.
7539  This saves a few bytes in code space if you don't have initialized data
7540 \begin_inset LatexCommand \index{Variable initialization}
7541
7542 \end_inset 
7543
7544 .
7545 \layout List
7546 \labelwidthstring 00.00.0000
7547
7548
7549 \series bold 
7550 -
7551 \begin_inset ERT
7552 status Collapsed
7553
7554 \layout Standard
7555
7556 \backslash 
7557 /
7558 \end_inset 
7559
7560 -nooverlay
7561 \begin_inset LatexCommand \index{-\/-nooverlay}
7562
7563 \end_inset 
7564
7565
7566 \series default 
7567   The compiler will not overlay parameters and local variables of any function,
7568  see section Parameters and local variables for more details.
7569 \layout List
7570 \labelwidthstring 00.00.0000
7571
7572
7573 \series bold 
7574 -
7575 \begin_inset ERT
7576 status Collapsed
7577
7578 \layout Standard
7579
7580 \backslash 
7581 /
7582 \end_inset 
7583
7584 -no-peep
7585 \begin_inset LatexCommand \index{-\/-no-peep}
7586
7587 \end_inset 
7588
7589
7590 \series default 
7591  Disable peep-hole optimization with built-in rules.
7592 \layout List
7593 \labelwidthstring 00.00.0000
7594
7595
7596 \series bold 
7597 -
7598 \begin_inset ERT
7599 status Collapsed
7600
7601 \layout Standard
7602
7603 \backslash 
7604 /
7605 \end_inset 
7606
7607 -peep-file
7608 \series default 
7609
7610 \begin_inset LatexCommand \index{-\/-peep-file}
7611
7612 \end_inset 
7613
7614 \SpecialChar ~
7615 <filename> This option can be used to use additional rules to be used by
7616  the peep hole optimizer.
7617  See section 
7618 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7619
7620 \end_inset 
7621
7622 \SpecialChar ~
7623 Peep Hole optimizations for details on how to write these rules.
7624 \layout List
7625 \labelwidthstring 00.00.0000
7626
7627
7628 \series bold 
7629 -
7630 \begin_inset ERT
7631 status Collapsed
7632
7633 \layout Standard
7634
7635 \backslash 
7636 /
7637 \end_inset 
7638
7639 -peep-asm
7640 \begin_inset LatexCommand \index{-\/-peep-asm}
7641
7642 \end_inset 
7643
7644
7645 \series default 
7646  Pass the inline assembler code through the peep hole optimizer.
7647  This can cause unexpected changes to inline assembler code, please go through
7648  the peephole optimizer
7649 \begin_inset LatexCommand \index{Peephole optimizer}
7650
7651 \end_inset 
7652
7653  rules defined in the source file tree '<target>/peeph.def' before using
7654  this option.
7655 \layout List
7656 \labelwidthstring 00.00.0000
7657
7658
7659 \series bold 
7660 -
7661 \begin_inset ERT
7662 status Collapsed
7663
7664 \layout Standard
7665
7666 \backslash 
7667 /
7668 \end_inset 
7669
7670 -opt-code-speed
7671 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7672
7673 \end_inset 
7674
7675
7676 \series default 
7677  The compiler will optimize code generation towards fast code, possibly
7678  at the expense of code size.
7679 \layout List
7680 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7681
7682
7683 \series bold 
7684 -
7685 \begin_inset ERT
7686 status Collapsed
7687
7688 \layout Standard
7689
7690 \backslash 
7691 /
7692 \end_inset 
7693
7694 -opt-code-size
7695 \begin_inset LatexCommand \index{-\/-opt-code-size}
7696
7697 \end_inset 
7698
7699
7700 \series default 
7701  The compiler will optimize code generation towards compact code, possibly
7702  at the expense of code speed.
7703 \layout Subsection
7704
7705 Other Options
7706 \begin_inset LatexCommand \index{Options other}
7707
7708 \end_inset 
7709
7710
7711 \layout List
7712 \labelwidthstring 00.00.0000
7713
7714
7715 \series bold 
7716 -c\SpecialChar ~
7717 -
7718 \begin_inset ERT
7719 status Collapsed
7720
7721 \layout Standard
7722
7723 \backslash 
7724 /
7725 \end_inset 
7726
7727 -compile-only
7728 \begin_inset LatexCommand \index{-\/-compile-only}
7729
7730 \end_inset 
7731
7732
7733 \begin_inset LatexCommand \index{-c -\/-compile-only}
7734
7735 \end_inset 
7736
7737
7738 \series default 
7739  will compile and assemble the source, but will not call the linkage editor.
7740 \layout List
7741 \labelwidthstring 00.00.0000
7742
7743
7744 \series bold 
7745 -
7746 \series default 
7747
7748 \begin_inset ERT
7749 status Collapsed
7750
7751 \layout Standard
7752
7753 \backslash 
7754 /
7755 \end_inset 
7756
7757
7758 \series bold 
7759 -c1mode
7760 \begin_inset LatexCommand \index{-\/-c1mode}
7761
7762 \end_inset 
7763
7764
7765 \series default 
7766  reads the preprocessed source from standard input and compiles it.
7767  The file name for the assembler output must be specified using the -o option.
7768 \layout List
7769 \labelwidthstring 00.00.0000
7770
7771
7772 \series bold 
7773 -E
7774 \begin_inset LatexCommand \index{-E}
7775
7776 \end_inset 
7777
7778
7779 \series default 
7780  Run only the C preprocessor.
7781  Preprocess all the C source files specified and output the results to standard
7782  output.
7783 \layout List
7784 \labelwidthstring 00.00.0000
7785
7786
7787 \series bold 
7788 -o\SpecialChar ~
7789 <path/file>
7790 \begin_inset LatexCommand \index{-o <path/file>}
7791
7792 \end_inset 
7793
7794  
7795 \series default 
7796 The output path resp.
7797  file where everything will be placed.
7798  If the parameter is a path, it must have a trailing slash (or backslash
7799  for the Windows binaries) to be recognized as a path.
7800  
7801 \layout List
7802 \labelwidthstring 00.00.0000
7803
7804
7805 \series bold 
7806 -
7807 \begin_inset ERT
7808 status Collapsed
7809
7810 \layout Standard
7811
7812 \backslash 
7813 /
7814 \end_inset 
7815
7816 -stack-auto
7817 \begin_inset LatexCommand \index{-\/-stack-auto}
7818
7819 \end_inset 
7820
7821
7822 \series default 
7823 \size large 
7824 \emph on 
7825  
7826 \size default 
7827 \emph default 
7828 All functions in the source file will be compiled as 
7829 \emph on 
7830 reentrant
7831 \emph default 
7832
7833 \begin_inset LatexCommand \index{reentrant}
7834
7835 \end_inset 
7836
7837 , i.e.
7838  the parameters and local variables will be allocated on the stack
7839 \begin_inset LatexCommand \index{stack}
7840
7841 \end_inset 
7842
7843 .
7844  See section 
7845 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7846
7847 \end_inset 
7848
7849  Parameters and Local Variables for more details.
7850  If this option is used all source files in the project should be compiled
7851  with this option.
7852  It automatically implies --int-long-reent and --float-reent.
7853  
7854 \layout List
7855 \labelwidthstring 00.00.0000
7856
7857
7858 \series bold 
7859 -
7860 \begin_inset ERT
7861 status Collapsed
7862
7863 \layout Standard
7864
7865 \backslash 
7866 /
7867 \end_inset 
7868
7869 -callee-saves
7870 \begin_inset LatexCommand \index{-\/-callee-saves}
7871
7872 \end_inset 
7873
7874  function1[,function2][,function3]....
7875
7876 \series default 
7877  The compiler by default uses a caller saves convention for register saving
7878  across function calls, however this can cause unnecessary register pushing
7879  & popping when calling small functions from larger functions.
7880  This option can be used to switch the register saving convention for the
7881  function names specified.
7882  The compiler will not save registers when calling these functions, no extra
7883  code will be generated at the entry & exit (function prologue
7884 \series bold 
7885
7886 \begin_inset LatexCommand \index{function prologue}
7887
7888 \end_inset 
7889
7890
7891 \series default 
7892  & epilogue
7893 \series bold 
7894
7895 \begin_inset LatexCommand \index{function epilogue}
7896
7897 \end_inset 
7898
7899
7900 \series default 
7901 ) for these functions to save & restore the registers used by these functions,
7902  this can SUBSTANTIALLY reduce code & improve run time performance of the
7903  generated code.
7904  In the future the compiler (with inter procedural analysis) will be able
7905  to determine the appropriate scheme to use for each function call.
7906  DO NOT use this option for built-in functions such as _mulint..., if this
7907  option is used for a library function the appropriate library function
7908  needs to be recompiled with the same option.
7909  If the project consists of multiple source files then all the source file
7910  should be compiled with the same -
7911 \begin_inset ERT
7912 status Collapsed
7913
7914 \layout Standard
7915
7916 \backslash 
7917 /
7918 \end_inset 
7919
7920 -callee-saves option string.
7921  Also see #pragma\SpecialChar ~
7922 callee_saves
7923 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7924
7925 \end_inset 
7926
7927 .
7928 \layout List
7929 \labelwidthstring 00.00.0000
7930
7931
7932 \series bold 
7933 -
7934 \begin_inset ERT
7935 status Collapsed
7936
7937 \layout Standard
7938
7939 \backslash 
7940 /
7941 \end_inset 
7942
7943 -debug
7944 \begin_inset LatexCommand \index{-\/-debug}
7945
7946 \end_inset 
7947
7948
7949 \bar under 
7950  
7951 \series default 
7952 \bar default 
7953 When this option is used the compiler will generate debug information.
7954  The debug information collected in a file with .cdb extension can be used
7955  with the SDCDB.
7956  For more information see documentation for SDCDB.
7957  Another file with no extension contains debug information in AOMF or AOMF51
7958 \begin_inset LatexCommand \index{AOMF, AOMF51}
7959
7960 \end_inset 
7961
7962  format which is commonly used by third party tools.
7963 \layout List
7964 \labelwidthstring 00.00.0000
7965
7966
7967 \series bold 
7968 -S
7969 \begin_inset LatexCommand \index{-S}
7970
7971 \end_inset 
7972
7973
7974 \size large 
7975 \bar under 
7976  
7977 \series default 
7978 \size default 
7979 \bar default 
7980 Stop after the stage of compilation proper; do not assemble.
7981  The output is an assembler code file for the input file specified.
7982 \layout List
7983 \labelwidthstring 00.00.0000
7984
7985
7986 \series bold 
7987 -
7988 \begin_inset ERT
7989 status Collapsed
7990
7991 \layout Standard
7992
7993 \backslash 
7994 /
7995 \end_inset 
7996
7997 -int-long-reent
7998 \begin_inset LatexCommand \index{-\/-int-long-reent}
7999
8000 \end_inset 
8001
8002
8003 \series default 
8004  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8005  Note by default these libraries are compiled as non-reentrant.
8006  See section Installation for more details.
8007 \layout List
8008 \labelwidthstring 00.00.0000
8009
8010
8011 \series bold 
8012 -
8013 \begin_inset ERT
8014 status Collapsed
8015
8016 \layout Standard
8017
8018 \backslash 
8019 /
8020 \end_inset 
8021
8022 -cyclomatic
8023 \begin_inset LatexCommand \index{-\/-cyclomatic}
8024
8025 \end_inset 
8026
8027
8028 \bar under 
8029  
8030 \series default 
8031 \bar default 
8032 This option will cause the compiler to generate an information message for
8033  each function in the source file.
8034  The message contains some 
8035 \emph on 
8036 important
8037 \emph default 
8038  information about the function.
8039  The number of edges and nodes the compiler detected in the control flow
8040  graph of the function, and most importantly the 
8041 \emph on 
8042 cyclomatic complexity
8043 \begin_inset LatexCommand \index{Cyclomatic complexity}
8044
8045 \end_inset 
8046
8047
8048 \emph default 
8049  see section on Cyclomatic Complexity for more details.
8050 \layout List
8051 \labelwidthstring 00.00.0000
8052
8053
8054 \series bold 
8055 -
8056 \begin_inset ERT
8057 status Collapsed
8058
8059 \layout Standard
8060
8061 \backslash 
8062 /
8063 \end_inset 
8064
8065 -float-reent
8066 \begin_inset LatexCommand \index{-\/-float-reent}
8067
8068 \end_inset 
8069
8070
8071 \series default 
8072  Floating point library is compiled as reentrant
8073 \begin_inset LatexCommand \index{reentrant}
8074
8075 \end_inset 
8076
8077 .
8078  See section Installation for more details.
8079 \layout List
8080 \labelwidthstring 00.00.0000
8081
8082
8083 \series bold 
8084 -
8085 \begin_inset ERT
8086 status Collapsed
8087
8088 \layout Standard
8089
8090 \backslash 
8091 /
8092 \end_inset 
8093
8094 -main-return
8095 \begin_inset LatexCommand \index{-\/-main-return}
8096
8097 \end_inset 
8098
8099
8100 \series default 
8101  This option can be used if the code generated is called by a monitor program
8102  or if the main routine includes an endless loop.
8103  This option results in slightly smaller code and saves two bytes of stack
8104  space.
8105  The return from the 'main'
8106 \begin_inset LatexCommand \index{main return}
8107
8108 \end_inset 
8109
8110  function will return to the function calling main.
8111  The default setting is to lock up i.e.
8112  generate a '
8113 \family typewriter 
8114 sjmp .
8115 \family default 
8116 '.
8117 \layout List
8118 \labelwidthstring 00.00.0000
8119
8120
8121 \series bold 
8122 -
8123 \begin_inset ERT
8124 status Collapsed
8125
8126 \layout Standard
8127
8128 \backslash 
8129 /
8130 \end_inset 
8131
8132 -nostdinc
8133 \begin_inset LatexCommand \index{-\/-nostdinc}
8134
8135 \end_inset 
8136
8137
8138 \series default 
8139  This will prevent the compiler from passing on the default include path
8140  to the preprocessor.
8141 \layout List
8142 \labelwidthstring 00.00.0000
8143
8144
8145 \series bold 
8146 -
8147 \begin_inset ERT
8148 status Collapsed
8149
8150 \layout Standard
8151
8152 \backslash 
8153 /
8154 \end_inset 
8155
8156 -nostdlib
8157 \begin_inset LatexCommand \index{-\/-nostdlib}
8158
8159 \end_inset 
8160
8161
8162 \series default 
8163  This will prevent the compiler from passing on the default library
8164 \begin_inset LatexCommand \index{Libraries}
8165
8166 \end_inset 
8167
8168  path to the linker.
8169 \layout List
8170 \labelwidthstring 00.00.0000
8171
8172
8173 \series bold 
8174 -
8175 \begin_inset ERT
8176 status Collapsed
8177
8178 \layout Standard
8179
8180 \backslash 
8181 /
8182 \end_inset 
8183
8184 -verbose
8185 \begin_inset LatexCommand \index{-\/-verbose}
8186
8187 \end_inset 
8188
8189
8190 \series default 
8191  Shows the various actions the compiler is performing.
8192 \layout List
8193 \labelwidthstring 00.00.0000
8194
8195
8196 \series bold 
8197 -V
8198 \begin_inset LatexCommand \index{-V}
8199
8200 \end_inset 
8201
8202
8203 \series default 
8204  Shows the actual commands the compiler is executing.
8205 \layout List
8206 \labelwidthstring 00.00.0000
8207
8208
8209 \series bold 
8210 -
8211 \begin_inset ERT
8212 status Collapsed
8213
8214 \layout Standard
8215
8216 \backslash 
8217 /
8218 \end_inset 
8219
8220 -no-c-code-in-asm
8221 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8222
8223 \end_inset 
8224
8225
8226 \series default 
8227  Hides your ugly and inefficient c-code from the asm file, so you can always
8228  blame the compiler :)
8229 \layout List
8230 \labelwidthstring 00.00.0000
8231
8232
8233 \series bold 
8234 -
8235 \begin_inset ERT
8236 status Collapsed
8237
8238 \layout Standard
8239
8240 \backslash 
8241 /
8242 \end_inset 
8243
8244 -no-peep-comments
8245 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8246
8247 \end_inset 
8248
8249
8250 \series default 
8251  Will not include peep-hole comments in the generated files.
8252 \layout List
8253 \labelwidthstring 00.00.0000
8254
8255
8256 \series bold 
8257 -
8258 \begin_inset ERT
8259 status Collapsed
8260
8261 \layout Standard
8262
8263 \backslash 
8264 /
8265 \end_inset 
8266
8267 -i-code-in-asm
8268 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8269
8270 \end_inset 
8271
8272
8273 \series default 
8274  Include i-codes in the asm file.
8275  Sounds like noise but is most helpful for debugging the compiler itself.
8276 \layout List
8277 \labelwidthstring 00.00.0000
8278
8279
8280 \series bold 
8281 -
8282 \begin_inset ERT
8283 status Collapsed
8284
8285 \layout Standard
8286
8287 \backslash 
8288 /
8289 \end_inset 
8290
8291 -less-pedantic
8292 \begin_inset LatexCommand \index{-\/-less-pedantic}
8293
8294 \end_inset 
8295
8296
8297 \series default 
8298  Disable some of the more pedantic warnings
8299 \begin_inset LatexCommand \index{Warnings}
8300
8301 \end_inset 
8302
8303  (jwk burps: please be more specific here, please!).
8304 \layout List
8305 \labelwidthstring 00.00.0000
8306
8307
8308 \series bold 
8309 -
8310 \begin_inset ERT
8311 status Collapsed
8312
8313 \layout Standard
8314
8315 \backslash 
8316 /
8317 \end_inset 
8318
8319 -disable-warning\SpecialChar ~
8320 <nnnn>
8321 \begin_inset LatexCommand \index{-\/-disable-warning}
8322
8323 \end_inset 
8324
8325
8326 \series default 
8327  Disable specific warning with number <nnnn>.
8328 \layout List
8329 \labelwidthstring 00.00.0000
8330
8331
8332 \series bold 
8333 -
8334 \begin_inset ERT
8335 status Collapsed
8336
8337 \layout Standard
8338
8339 \backslash 
8340 /
8341 \end_inset 
8342
8343 -print-search-dirs
8344 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8345
8346 \end_inset 
8347
8348
8349 \series default 
8350  Display the directories in the compiler's search path
8351 \layout List
8352 \labelwidthstring 00.00.0000
8353
8354
8355 \series bold 
8356 -
8357 \begin_inset ERT
8358 status Collapsed
8359
8360 \layout Standard
8361
8362 \backslash 
8363 /
8364 \end_inset 
8365
8366 -vc
8367 \begin_inset LatexCommand \index{-\/-vc}
8368
8369 \end_inset 
8370
8371
8372 \series default 
8373  Display errors and warnings using MSVC style, so you can use SDCC with
8374  visual studio.
8375  With SDCC both offering a GCC-like (the default) and a MSVC-like output
8376  style, integration into most programming editors should be straightforward.
8377 \layout List
8378 \labelwidthstring 00.00.0000
8379
8380
8381 \series bold 
8382 -
8383 \begin_inset ERT
8384 status Collapsed
8385
8386 \layout Standard
8387
8388 \backslash 
8389 /
8390 \end_inset 
8391
8392 -use-stdout
8393 \begin_inset LatexCommand \index{-\/-use-stdout}
8394
8395 \end_inset 
8396
8397
8398 \series default 
8399  Send errors and warnings to stdout instead of stderr.
8400 \layout List
8401 \labelwidthstring 00.00.0000
8402
8403
8404 \series bold 
8405 -Wa\SpecialChar ~
8406 asmOption[,asmOption]
8407 \series default 
8408
8409 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8410
8411 \end_inset 
8412
8413 ...
8414  Pass the asmOption to the assembler
8415 \begin_inset LatexCommand \index{Options assembler}
8416
8417 \end_inset 
8418
8419
8420 \begin_inset LatexCommand \index{Assembler options}
8421
8422 \end_inset 
8423
8424 .
8425  See file sdcc/as/doc/asxhtm.html for assembler options.cd
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 -std-sdcc89
8442 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8443
8444 \end_inset 
8445
8446
8447 \series default 
8448  Generally follow the C89 standard, but allow SDCC features that conflict
8449  with the standard (default).
8450 \layout List
8451 \labelwidthstring 00.00.0000
8452
8453
8454 \series bold 
8455 -
8456 \begin_inset ERT
8457 status Collapsed
8458
8459 \layout Standard
8460
8461 \backslash 
8462 /
8463 \end_inset 
8464
8465 -std-c89
8466 \begin_inset LatexCommand \index{-\/-std-c89}
8467
8468 \end_inset 
8469
8470
8471 \series default 
8472  Follow the C89 standard and disable SDCC features that conflict with the
8473  standard.
8474 \layout List
8475 \labelwidthstring 00.00.0000
8476
8477
8478 \series bold 
8479 -
8480 \begin_inset ERT
8481 status Collapsed
8482
8483 \layout Standard
8484
8485 \backslash 
8486 /
8487 \end_inset 
8488
8489 -std-sdcc99
8490 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8491
8492 \end_inset 
8493
8494
8495 \series default 
8496  Generally follow the C99 standard, but allow SDCC features that conflict
8497  with the standard (incomplete support).
8498 \layout List
8499 \labelwidthstring 00.00.0000
8500
8501
8502 \series bold 
8503 -
8504 \begin_inset ERT
8505 status Collapsed
8506
8507 \layout Standard
8508
8509 \backslash 
8510 /
8511 \end_inset 
8512
8513 -std-c99
8514 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8515
8516 \end_inset 
8517
8518
8519 \series default 
8520  Follow the C99 standard and disable SDCC features that conflict with the
8521  standard (incomplete support).
8522 \layout List
8523 \labelwidthstring 00.00.0000
8524
8525
8526 \series bold 
8527 -
8528 \begin_inset ERT
8529 status Collapsed
8530
8531 \layout Standard
8532
8533 \backslash 
8534 /
8535 \end_inset 
8536
8537 -codeseg
8538 \series default 
8539
8540 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8541
8542 \end_inset 
8543
8544 \SpecialChar ~
8545 <Name> The name to be used for the code
8546 \begin_inset LatexCommand \index{code}
8547
8548 \end_inset 
8549
8550  segment, default CSEG.
8551  This is useful if you need to tell the compiler to put the code in a special
8552  segment so you can later on tell the linker to put this segment in a special
8553  place in memory.
8554  Can be used for instance when using bank switching to put the code in a
8555  bank.
8556 \layout List
8557 \labelwidthstring 00.00.0000
8558
8559
8560 \series bold 
8561 -
8562 \begin_inset ERT
8563 status Collapsed
8564
8565 \layout Standard
8566
8567 \backslash 
8568 /
8569 \end_inset 
8570
8571 -constseg
8572 \series default 
8573
8574 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8575
8576 \end_inset 
8577
8578 \SpecialChar ~
8579 <Name> The name to be used for the const
8580 \begin_inset LatexCommand \index{code}
8581
8582 \end_inset 
8583
8584  segment, default CONST.
8585  This is useful if you need to tell the compiler to put the const data in
8586  a special segment so you can later on tell the linker to put this segment
8587  in a special place in memory.
8588  Can be used for instance when using bank switching to put the const data
8589  in a bank.
8590 \layout List
8591 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8592
8593
8594 \series bold 
8595 more-pedantic
8596 \series default 
8597  Actually this is 
8598 \series bold 
8599 \emph on 
8600 not
8601 \series default 
8602 \emph default 
8603  a SDCC compiler option but if you want 
8604 \emph on 
8605 more
8606 \emph default 
8607  warnings you can use a separate tool dedicated to syntax checking like
8608  splint
8609 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8610
8611 \end_inset 
8612
8613
8614 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8615
8616 \end_inset 
8617
8618  
8619 \begin_inset LatexCommand \url{http://www.splint.org}
8620
8621 \end_inset 
8622
8623 .
8624  To make your source files parseable by splint you will have to include
8625  
8626 \family sans 
8627 lint.h
8628 \family default 
8629
8630 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8631
8632 \end_inset 
8633
8634  in your source file and add brackets around extended keywords (like 
8635 \family sans 
8636
8637 \begin_inset Quotes sld
8638 \end_inset 
8639
8640 __at\SpecialChar ~
8641
8642 \series bold 
8643 (
8644 \series default 
8645 0xab
8646 \series bold 
8647 )
8648 \series default 
8649
8650 \begin_inset Quotes srd
8651 \end_inset 
8652
8653
8654 \family default 
8655  and 
8656 \family sans 
8657
8658 \begin_inset Quotes sld
8659 \end_inset 
8660
8661 __interrupt\SpecialChar ~
8662 (2)
8663 \begin_inset Quotes srd
8664 \end_inset 
8665
8666
8667 \family default 
8668 ).
8669  
8670 \newline 
8671 Splint has an excellent on line manual at 
8672 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8673
8674 \end_inset 
8675
8676  and it's capabilities go beyond pure syntax checking.
8677  You'll need to tell splint the location of SDCC's include files so a typical
8678  command line could look like this: 
8679 \newline 
8680
8681 \family sans 
8682 splint\SpecialChar ~
8683 -I\SpecialChar ~
8684 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8685 \SpecialChar ~
8686 myprogram.c
8687 \layout Subsection
8688
8689 Intermediate Dump Options
8690 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8691
8692 \end_inset 
8693
8694
8695 \begin_inset LatexCommand \index{Options intermediate dump}
8696
8697 \end_inset 
8698
8699
8700 \begin_inset LatexCommand \index{Intermediate dump options}
8701
8702 \end_inset 
8703
8704
8705 \layout Standard
8706
8707 The following options are provided for the purpose of retargetting and debugging
8708  the compiler.
8709  They provide a means to dump the intermediate code (iCode
8710 \begin_inset LatexCommand \index{iCode}
8711
8712 \end_inset 
8713
8714 ) generated by the compiler in human readable form at various stages of
8715  the compilation process.
8716  More on iCodes see chapter 
8717 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8718
8719 \end_inset 
8720
8721  
8722 \begin_inset Quotes srd
8723 \end_inset 
8724
8725 The anatomy of the compiler
8726 \begin_inset Quotes srd
8727 \end_inset 
8728
8729 .
8730 \layout List
8731 \labelwidthstring 00.00.0000
8732
8733
8734 \series bold 
8735 -
8736 \begin_inset ERT
8737 status Collapsed
8738
8739 \layout Standard
8740
8741 \backslash 
8742 /
8743 \end_inset 
8744
8745 -dumpraw
8746 \begin_inset LatexCommand \index{-\/-dumpraw}
8747
8748 \end_inset 
8749
8750
8751 \series default 
8752  This option will cause the compiler to dump the intermediate code into
8753  a file of named 
8754 \emph on 
8755 <source filename>.dumpraw
8756 \emph default 
8757  just after the intermediate code has been generated for a function, i.e.
8758  before any optimizations are done.
8759  The basic blocks
8760 \begin_inset LatexCommand \index{Basic blocks}
8761
8762 \end_inset 
8763
8764  at this stage ordered in the depth first number, so they may not be in
8765  sequence of execution.
8766 \layout List
8767 \labelwidthstring 00.00.0000
8768
8769
8770 \series bold 
8771 -
8772 \begin_inset ERT
8773 status Collapsed
8774
8775 \layout Standard
8776
8777 \backslash 
8778 /
8779 \end_inset 
8780
8781 -dumpgcse
8782 \begin_inset LatexCommand \index{-\/-dumpgcse}
8783
8784 \end_inset 
8785
8786
8787 \series default 
8788  Will create a dump of iCode's, after global subexpression elimination
8789 \begin_inset LatexCommand \index{Global subexpression elimination}
8790
8791 \end_inset 
8792
8793 , into a file named 
8794 \emph on 
8795 <source filename>.dumpgcse.
8796 \layout List
8797 \labelwidthstring 00.00.0000
8798
8799
8800 \series bold 
8801 -
8802 \begin_inset ERT
8803 status Collapsed
8804
8805 \layout Standard
8806
8807 \backslash 
8808 /
8809 \end_inset 
8810
8811 -dumpdeadcode
8812 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8813
8814 \end_inset 
8815
8816
8817 \series default 
8818  Will create a dump of iCode's, after deadcode elimination
8819 \begin_inset LatexCommand \index{Dead-code elimination}
8820
8821 \end_inset 
8822
8823 , into a file named 
8824 \emph on 
8825 <source filename>.dumpdeadcode.
8826 \layout List
8827 \labelwidthstring 00.00.0000
8828
8829
8830 \series bold 
8831 -
8832 \begin_inset ERT
8833 status Collapsed
8834
8835 \layout Standard
8836
8837 \backslash 
8838 /
8839 \end_inset 
8840
8841 -dumploop
8842 \begin_inset LatexCommand \index{-\/-dumploop}
8843
8844 \end_inset 
8845
8846
8847 \series default 
8848 \size large 
8849  
8850 \size default 
8851 Will create a dump of iCode's, after loop optimizations
8852 \begin_inset LatexCommand \index{Loop optimization}
8853
8854 \end_inset 
8855
8856 , into a file named 
8857 \emph on 
8858 <source filename>.dumploop.
8859 \layout List
8860 \labelwidthstring 00.00.0000
8861
8862
8863 \series bold 
8864 -
8865 \begin_inset ERT
8866 status Collapsed
8867
8868 \layout Standard
8869
8870 \backslash 
8871 /
8872 \end_inset 
8873
8874 -dumprange
8875 \begin_inset LatexCommand \index{-\/-dumprange}
8876
8877 \end_inset 
8878
8879
8880 \series default 
8881 \size large 
8882  
8883 \size default 
8884 Will create a dump of iCode's, after live range analysis
8885 \begin_inset LatexCommand \index{Live range analysis}
8886
8887 \end_inset 
8888
8889 , into a file named 
8890 \emph on 
8891 <source filename>.dumprange.
8892 \layout List
8893 \labelwidthstring 00.00.0000
8894
8895
8896 \series bold 
8897 -
8898 \begin_inset ERT
8899 status Collapsed
8900
8901 \layout Standard
8902
8903 \backslash 
8904 /
8905 \end_inset 
8906
8907 -dumlrange
8908 \begin_inset LatexCommand \index{-\/-dumlrange}
8909
8910 \end_inset 
8911
8912
8913 \series default 
8914  Will dump the life ranges
8915 \begin_inset LatexCommand \index{Live range analysis}
8916
8917 \end_inset 
8918
8919  for all symbols.
8920 \layout List
8921 \labelwidthstring 00.00.0000
8922
8923
8924 \series bold 
8925 -
8926 \begin_inset ERT
8927 status Collapsed
8928
8929 \layout Standard
8930
8931 \backslash 
8932 /
8933 \end_inset 
8934
8935 -dumpregassign
8936 \begin_inset LatexCommand \index{-\/-dumpregassign}
8937
8938 \end_inset 
8939
8940
8941 \bar under 
8942  
8943 \series default 
8944 \bar default 
8945 Will create a dump of iCode's, after register assignment
8946 \begin_inset LatexCommand \index{Register assignment}
8947
8948 \end_inset 
8949
8950 , into a file named 
8951 \emph on 
8952 <source filename>.dumprassgn.
8953 \layout List
8954 \labelwidthstring 00.00.0000
8955
8956
8957 \series bold 
8958 -
8959 \begin_inset ERT
8960 status Collapsed
8961
8962 \layout Standard
8963
8964 \backslash 
8965 /
8966 \end_inset 
8967
8968 -dumplrange
8969 \begin_inset LatexCommand \index{-\/-dumplrange}
8970
8971 \end_inset 
8972
8973
8974 \series default 
8975  Will create a dump of the live ranges of iTemp's
8976 \layout List
8977 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8978
8979
8980 \series bold 
8981 -
8982 \begin_inset ERT
8983 status Collapsed
8984
8985 \layout Standard
8986
8987 \backslash 
8988 /
8989 \end_inset 
8990
8991 -dumpall
8992 \begin_inset LatexCommand \index{-\/-dumpall}
8993
8994 \end_inset 
8995
8996
8997 \size large 
8998 \bar under 
8999  
9000 \series default 
9001 \size default 
9002 \bar default 
9003 Will cause all the above mentioned dumps to be created.
9004 \layout Subsection
9005
9006 Redirecting output on Windows Shells
9007 \layout Standard
9008 \added_space_bottom bigskip 
9009 By default SDCC writes it's error messages to 
9010 \begin_inset Quotes sld
9011 \end_inset 
9012
9013 standard error
9014 \begin_inset Quotes srd
9015 \end_inset 
9016
9017 .
9018  To force all messages to 
9019 \begin_inset Quotes sld
9020 \end_inset 
9021
9022 standard output
9023 \begin_inset Quotes srd
9024 \end_inset 
9025
9026  use 
9027 \series bold 
9028 -
9029 \series default 
9030 \emph on 
9031
9032 \begin_inset ERT
9033 status Collapsed
9034
9035 \layout Standard
9036
9037 \backslash 
9038 /
9039 \end_inset 
9040
9041
9042 \series bold 
9043 \emph default 
9044 -
9045 \series default 
9046 use-stdout
9047 \begin_inset LatexCommand \index{-\/-use-stdout}
9048
9049 \end_inset 
9050
9051 .
9052  Additionally, if you happen to have visual studio installed in your windows
9053  machine, you can use it to compile your sources using a custom build and
9054  the SDCC -
9055 \emph on 
9056
9057 \begin_inset ERT
9058 status Collapsed
9059
9060 \layout Standard
9061
9062 \backslash 
9063 /
9064 \end_inset 
9065
9066
9067 \emph default 
9068 -vc
9069 \begin_inset LatexCommand \index{-\/-vc}
9070
9071 \end_inset 
9072
9073  option.
9074  Something like this should work:
9075 \newline 
9076
9077 \newline 
9078
9079 \series bold 
9080 c:
9081 \backslash 
9082 sdcc
9083 \backslash 
9084 bin
9085 \backslash 
9086 sdcc.exe -
9087 \series default 
9088 \emph on 
9089
9090 \begin_inset ERT
9091 status Collapsed
9092
9093 \layout Standard
9094
9095 \backslash 
9096 /
9097 \end_inset 
9098
9099
9100 \series bold 
9101 \emph default 
9102 -vc -
9103 \series default 
9104 \emph on 
9105
9106 \begin_inset ERT
9107 status Collapsed
9108
9109 \layout Standard
9110
9111 \backslash 
9112 /
9113 \end_inset 
9114
9115
9116 \series bold 
9117 \emph default 
9118 -model-large -c $(InputPath)
9119 \layout Section
9120
9121 Environment variables
9122 \begin_inset LatexCommand \index{Environment variables}
9123
9124 \end_inset 
9125
9126
9127 \layout Standard
9128
9129 SDCC recognizes the following environment variables:
9130 \layout List
9131 \labelwidthstring 00.00.0000
9132
9133
9134 \series bold 
9135 SDCC_LEAVE_SIGNALS
9136 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9137
9138 \end_inset 
9139
9140
9141 \series default 
9142  SDCC installs a signal handler
9143 \begin_inset LatexCommand \index{signal handler}
9144
9145 \end_inset 
9146
9147  to be able to delete temporary files after an user break (^C) or an exception.
9148  If this environment variable is set, SDCC won't install the signal handler
9149  in order to be able to debug SDCC.
9150 \layout List
9151 \labelwidthstring 00.00.0000
9152
9153
9154 \series bold 
9155 TMP,\SpecialChar ~
9156 TEMP,\SpecialChar ~
9157 TMPDIR
9158 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9159
9160 \end_inset 
9161
9162
9163 \series default 
9164  Path, where temporary files will be created.
9165  The order of the variables is the search order.
9166  In a standard *nix environment these variables are not set, and there's
9167  no need to set them.
9168  On Windows it's recommended to set one of them.
9169 \layout List
9170 \labelwidthstring 00.00.0000
9171
9172
9173 \series bold 
9174 SDCC_HOME
9175 \begin_inset LatexCommand \index{SDCC\_HOME}
9176
9177 \end_inset 
9178
9179
9180 \series default 
9181  Path, see section 
9182 \begin_inset LatexCommand \ref{sub:Install-paths}
9183
9184 \end_inset 
9185
9186 \SpecialChar ~
9187
9188 \begin_inset Quotes sld
9189 \end_inset 
9190
9191  Install Paths
9192 \begin_inset Quotes srd
9193 \end_inset 
9194
9195 .
9196 \layout List
9197 \labelwidthstring 00.00.0000
9198
9199
9200 \series bold 
9201 SDCC_INCLUDE
9202 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9203
9204 \end_inset 
9205
9206
9207 \series default 
9208  Path, see section 
9209 \begin_inset LatexCommand \ref{sub:Search-Paths}
9210
9211 \end_inset 
9212
9213 \SpecialChar ~
9214
9215 \begin_inset Quotes sld
9216 \end_inset 
9217
9218 Search Paths
9219 \begin_inset Quotes srd
9220 \end_inset 
9221
9222 .
9223 \layout List
9224 \labelwidthstring 00.00.0000
9225
9226
9227 \series bold 
9228 SDCC_LIB
9229 \begin_inset LatexCommand \index{SDCC\_LIB}
9230
9231 \end_inset 
9232
9233
9234 \series default 
9235  Path, see section 
9236 \begin_inset LatexCommand \ref{sub:Search-Paths}
9237
9238 \end_inset 
9239
9240 \SpecialChar ~
9241
9242 \begin_inset Quotes sld
9243 \end_inset 
9244
9245 Search Paths
9246 \begin_inset Quotes srd
9247 \end_inset 
9248
9249 ..
9250 \layout Standard
9251 \added_space_bottom bigskip 
9252 There are some more environment variables recognized by SDCC, but these
9253  are solely used for debugging purposes.
9254  They can change or disappear very quickly, and will never be documented.
9255 \layout Section
9256
9257 Storage Class Language Extensions
9258 \layout Subsection
9259
9260 MCS51/DS390 Storage Class
9261 \begin_inset LatexCommand \index{Storage class}
9262
9263 \end_inset 
9264
9265  Language Extensions
9266 \layout Standard
9267
9268 In addition to the ANSI storage classes SDCC allows the following MCS51
9269  specific storage classes:
9270 \layout Subsubsection
9271
9272 data
9273 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9274
9275 \end_inset 
9276
9277
9278 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9279
9280 \end_inset 
9281
9282  / near
9283 \begin_inset LatexCommand \index{near (storage class)}
9284
9285 \end_inset 
9286
9287
9288 \begin_inset LatexCommand \index{\_\_near (storage class)}
9289
9290 \end_inset 
9291
9292
9293 \layout Standard
9294
9295 This is the 
9296 \series bold 
9297 default
9298 \series default 
9299  storage class for the Small Memory model (
9300 \emph on 
9301 data
9302 \emph default 
9303  and 
9304 \emph on 
9305 near
9306 \emph default 
9307  or the more ANSI-C compliant forms 
9308 \emph on 
9309 __data
9310 \emph default 
9311  and 
9312 \emph on 
9313 __near
9314 \emph default 
9315  can be used synonymously).
9316  Variables declared with this storage class will be allocated in the directly
9317  addressable portion of the internal RAM of a 8051, e.g.:
9318 \layout Verse
9319
9320
9321 \family typewriter 
9322 __data unsigned char test_data;
9323 \layout Standard
9324
9325 Writing 0x01 to this variable generates the assembly code:
9326 \layout Verse
9327
9328
9329 \family typewriter 
9330 75*00 01\SpecialChar ~
9331 \SpecialChar ~
9332 \SpecialChar ~
9333 mov\SpecialChar ~
9334 \SpecialChar ~
9335 _test_data,#0x01
9336 \layout Subsubsection
9337
9338 xdata
9339 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9340
9341 \end_inset 
9342
9343
9344 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9345
9346 \end_inset 
9347
9348  / far
9349 \begin_inset LatexCommand \index{far (storage class)}
9350
9351 \end_inset 
9352
9353
9354 \begin_inset LatexCommand \index{\_\_far (storage class)}
9355
9356 \end_inset 
9357
9358
9359 \layout Standard
9360
9361 Variables declared with this storage class will be placed in the external
9362  RAM.
9363  This is the 
9364 \series bold 
9365 default
9366 \series default 
9367  storage class for the Large Memory model, e.g.:
9368 \layout Verse
9369
9370
9371 \family typewriter 
9372 __xdata unsigned char test_xdata;
9373 \layout Standard
9374
9375 Writing 0x01 to this variable generates the assembly code:
9376 \layout Verse
9377
9378
9379 \family typewriter 
9380 90s00r00\SpecialChar ~
9381 \SpecialChar ~
9382 \SpecialChar ~
9383 mov\SpecialChar ~
9384 \SpecialChar ~
9385 dptr,#_test_xdata 
9386 \newline 
9387 74\SpecialChar ~
9388 01\SpecialChar ~
9389 \SpecialChar ~
9390 \SpecialChar ~
9391 \SpecialChar ~
9392 \SpecialChar ~
9393 \SpecialChar ~
9394 mov\SpecialChar ~
9395 \SpecialChar ~
9396 a,#0x01 
9397 \newline 
9398 F0\SpecialChar ~
9399 \SpecialChar ~
9400 \SpecialChar ~
9401 \SpecialChar ~
9402 \SpecialChar ~
9403 \SpecialChar ~
9404 \SpecialChar ~
9405 \SpecialChar ~
9406 \SpecialChar ~
9407 movx\SpecialChar ~
9408 @dptr,a 
9409 \layout Subsubsection
9410
9411 idata
9412 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9413
9414 \end_inset 
9415
9416
9417 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9418
9419 \end_inset 
9420
9421
9422 \layout Standard
9423
9424 Variables declared with this storage class will be allocated into the indirectly
9425  addressable portion of the internal ram of a 8051, e.g.:
9426 \layout Verse
9427
9428
9429 \family typewriter 
9430 __idata unsigned char test_idata;
9431 \layout Standard
9432
9433 Writing 0x01 to this variable generates the assembly code:
9434 \layout Verse
9435
9436
9437 \family typewriter 
9438 78r00\SpecialChar ~
9439 \SpecialChar ~
9440 \SpecialChar ~
9441 \SpecialChar ~
9442 \SpecialChar ~
9443 \SpecialChar ~
9444 \SpecialChar ~
9445 mov\SpecialChar ~
9446 \SpecialChar ~
9447 r0,#_test_idata
9448 \newline 
9449 76\SpecialChar ~
9450 01\SpecialChar ~
9451 \SpecialChar ~
9452 \SpecialChar ~
9453 \SpecialChar ~
9454 \SpecialChar ~
9455 \SpecialChar ~
9456 \SpecialChar ~
9457 mov\SpecialChar ~
9458 \SpecialChar ~
9459 @r0,#0x01
9460 \layout Standard
9461
9462 Please note, the first 128 byte of idata physically access the same RAM
9463  as the data memory.
9464  The original 8051 had 128 byte idata memory, nowadays most devices have
9465  256 byte idata memory.
9466  The stack
9467 \begin_inset LatexCommand \index{stack}
9468
9469 \end_inset 
9470
9471  is located in idata memory.
9472 \layout Subsubsection
9473
9474 pdata
9475 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9476
9477 \end_inset 
9478
9479
9480 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9481
9482 \end_inset 
9483
9484
9485 \layout Standard
9486
9487 Paged xdata access is just as straightforward as using the other addressing
9488  modes of a 8051.
9489  It is typically located at the start of xdata and has a maximum size of
9490  256 bytes.
9491  The following example writes 0x01 to the pdata variable.
9492  Please note, pdata access physically accesses xdata memory.
9493  The high byte of the address is determined by port P2 
9494 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9495
9496 \end_inset 
9497
9498 (or in case of some 8051 variants by a separate Special Function Register,
9499  see section 
9500 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9501
9502 \end_inset 
9503
9504 ).
9505  This is the 
9506 \series bold 
9507 default
9508 \series default 
9509  storage class for the Medium Memory model, e.g.:
9510 \layout Verse
9511
9512
9513 \family typewriter 
9514 __pdata unsigned char test_pdata;
9515 \layout Standard
9516
9517 Writing 0x01 to this variable generates the assembly code:
9518 \layout Verse
9519
9520
9521 \family typewriter 
9522 78r00\SpecialChar ~
9523 \SpecialChar ~
9524 \SpecialChar ~
9525 \SpecialChar ~
9526 \SpecialChar ~
9527 \SpecialChar ~
9528 mov r0,#_test_pdata
9529 \newline 
9530 74 01\SpecialChar ~
9531 \SpecialChar ~
9532 \SpecialChar ~
9533 \SpecialChar ~
9534 \SpecialChar ~
9535 \SpecialChar ~
9536 mov a,#0x01 
9537 \newline 
9538 F2\SpecialChar ~
9539 \SpecialChar ~
9540 \SpecialChar ~
9541 \SpecialChar ~
9542 \SpecialChar ~
9543 \SpecialChar ~
9544 \SpecialChar ~
9545 \SpecialChar ~
9546 \SpecialChar ~
9547 movx @r0,a
9548 \layout Standard
9549
9550 If the -
9551 \begin_inset ERT
9552 status Collapsed
9553
9554 \layout Standard
9555
9556 \backslash 
9557 /
9558 \end_inset 
9559
9560 -xstack
9561 \begin_inset LatexCommand \index{-\/-xstack}
9562
9563 \end_inset 
9564
9565  option is used the pdata memory area is followed by the xstack memory area
9566  and the sum of their sizes is limited to 256 bytes.
9567 \layout Subsubsection
9568
9569 code
9570 \begin_inset LatexCommand \index{code}
9571
9572 \end_inset 
9573
9574
9575 \begin_inset LatexCommand \index{\_\_code}
9576
9577 \end_inset 
9578
9579
9580 \layout Standard
9581
9582 'Variables' declared with this storage class will be placed in the code
9583  memory:
9584 \layout Verse
9585
9586
9587 \family typewriter 
9588 __code unsigned char test_code;
9589 \layout Standard
9590
9591 Read access to this variable generates the assembly code:
9592 \layout Verse
9593
9594
9595 \family typewriter 
9596 90s00r6F\SpecialChar ~
9597 \SpecialChar ~
9598 \SpecialChar ~
9599 mov dptr,#_test_code
9600 \newline 
9601 E4\SpecialChar ~
9602 \SpecialChar ~
9603 \SpecialChar ~
9604 \SpecialChar ~
9605 \SpecialChar ~
9606 \SpecialChar ~
9607 \SpecialChar ~
9608 \SpecialChar ~
9609 \SpecialChar ~
9610 clr a
9611 \newline 
9612 93\SpecialChar ~
9613 \SpecialChar ~
9614 \SpecialChar ~
9615 \SpecialChar ~
9616 \SpecialChar ~
9617 \SpecialChar ~
9618 \SpecialChar ~
9619 \SpecialChar ~
9620 \SpecialChar ~
9621 movc a,@a+dptr 
9622 \layout Standard
9623
9624
9625 \family typewriter 
9626 char
9627 \family default 
9628  indexed arrays of characters in code memory can be accessed efficiently:
9629 \layout Verse
9630
9631
9632 \family typewriter 
9633 __code char test_array[] = {'c','h','e','a','p'}; 
9634 \layout Standard
9635
9636 Read access to this array using an 8-bit unsigned index generates the assembly
9637  code:
9638 \layout Verse
9639
9640
9641 \family typewriter 
9642 E5*00\SpecialChar ~
9643 \SpecialChar ~
9644 \SpecialChar ~
9645 \SpecialChar ~
9646 \SpecialChar ~
9647 \SpecialChar ~
9648 mov a,_index 
9649 \layout Verse
9650
9651
9652 \family typewriter 
9653 90s00r41\SpecialChar ~
9654 \SpecialChar ~
9655 \SpecialChar ~
9656 mov dptr,#_test_array
9657 \layout Verse
9658
9659
9660 \family typewriter 
9661 93\SpecialChar ~
9662 \SpecialChar ~
9663 \SpecialChar ~
9664 \SpecialChar ~
9665 \SpecialChar ~
9666 \SpecialChar ~
9667 \SpecialChar ~
9668 \SpecialChar ~
9669 \SpecialChar ~
9670 movc a,@a+dptr 
9671 \layout Subsubsection
9672
9673 bit
9674 \begin_inset LatexCommand \index{bit}
9675
9676 \end_inset 
9677
9678
9679 \begin_inset LatexCommand \index{\_\_bit}
9680
9681 \end_inset 
9682
9683
9684 \layout Standard
9685
9686 This is a data-type and a storage class specifier.
9687  When a variable is declared as a bit, it is allocated into the bit addressable
9688  memory of 8051, e.g.:
9689 \layout Verse
9690
9691
9692 \family typewriter 
9693 __bit test_bit;
9694 \layout Standard
9695
9696 Writing 1 to this variable generates the assembly code:
9697 \layout Verse
9698
9699
9700 \family typewriter 
9701 D2*00\SpecialChar ~
9702 \SpecialChar ~
9703 \SpecialChar ~
9704 \SpecialChar ~
9705 \SpecialChar ~
9706 \SpecialChar ~
9707 \SpecialChar ~
9708 setb\SpecialChar ~
9709 _test_bit
9710 \layout Standard
9711
9712 The bit addressable memory consists of 128 bits which are located from 0x20
9713  to 0x2f in data memory.
9714  
9715 \newline 
9716 Apart from this 8051 specific storage class most architectures support ANSI-C
9717  bitfields
9718 \begin_inset LatexCommand \index{bitfields}
9719
9720 \end_inset 
9721
9722
9723 \begin_inset Foot
9724 collapsed false
9725
9726 \layout Standard
9727
9728 Not really meant as examples, but nevertheless showing what bitfields are
9729  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9730 \end_inset 
9731
9732 .
9733  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9734  signed modifier are implemented as unsigned.
9735 \layout Subsubsection
9736
9737 sfr
9738 \begin_inset LatexCommand \index{sfr}
9739
9740 \end_inset 
9741
9742
9743 \begin_inset LatexCommand \index{\_\_sfr}
9744
9745 \end_inset 
9746
9747  / sfr16
9748 \begin_inset LatexCommand \index{sfr16}
9749
9750 \end_inset 
9751
9752
9753 \begin_inset LatexCommand \index{\_\_sfr16}
9754
9755 \end_inset 
9756
9757  / sfr32
9758 \begin_inset LatexCommand \index{sfr32}
9759
9760 \end_inset 
9761
9762
9763 \begin_inset LatexCommand \index{\_\_sfr32}
9764
9765 \end_inset 
9766
9767  / sbit
9768 \begin_inset LatexCommand \index{\_\_sbit}
9769
9770 \end_inset 
9771
9772
9773 \begin_inset LatexCommand \index{sbit}
9774
9775 \end_inset 
9776
9777
9778 \layout Standard
9779
9780 Like the bit keyword, 
9781 \emph on 
9782 sfr / sfr16 / sfr32 / sbit 
9783 \emph default 
9784 signify both a data-type and storage class, they are used to describe the
9785  
9786 \emph on 
9787 s
9788 \emph default 
9789 pecial 
9790 \emph on 
9791 f
9792 \emph default 
9793 unction 
9794 \emph on 
9795 r
9796 \emph default 
9797 egisters and 
9798 \emph on 
9799 s
9800 \emph default 
9801 pecial 
9802 \emph on 
9803 bit
9804 \emph default 
9805  variables of a 8051, eg:
9806 \layout Verse
9807
9808
9809 \family typewriter 
9810 __sfr __at
9811 \begin_inset LatexCommand \index{at}
9812
9813 \end_inset 
9814
9815
9816 \begin_inset LatexCommand \index{\_\_at}
9817
9818 \end_inset 
9819
9820  (0x80) P0;\SpecialChar ~
9821  /* special function register P0 at location 0x80 */
9822 \newline 
9823 /* 16 bit special function register combination for timer 0 */
9824 \newline 
9825 /* with the high byte at location 0x8C and the low byte at location 0x8A
9826  */
9827 \newline 
9828 __sfr16 __at
9829 \begin_inset LatexCommand \index{at}
9830
9831 \end_inset 
9832
9833
9834 \begin_inset LatexCommand \index{\_\_at}
9835
9836 \end_inset 
9837
9838  (0x8C8A) TMR0;
9839 \newline 
9840 __sbit __at (0xd7) CY; /* CY (Carry Flag
9841 \begin_inset LatexCommand \index{Flags}
9842
9843 \end_inset 
9844
9845
9846 \begin_inset LatexCommand \index{Carry flag}
9847
9848 \end_inset 
9849
9850 ) */
9851 \layout Standard
9852
9853 Special function registers which are located on an address dividable by
9854  8 are bit-addressable, an
9855 \emph on 
9856  sbit
9857 \emph default 
9858  addresses a specific bit within these sfr.
9859 \newline 
9860 16 Bit and 32 bit special function register combinations which require a
9861  certain access order are better not declared using 
9862 \emph on 
9863 sfr16
9864 \emph default 
9865  or 
9866 \emph on 
9867 sfr32.
9868
9869 \emph default 
9870  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9871  this is not guaranteed.
9872 \newline 
9873
9874 \layout Standard
9875
9876 Please note, if you use a header file which was written for another compiler
9877  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
9878  likely be 
9879 \emph on 
9880 not 
9881 \emph default 
9882 compatible.
9883  Specifically the syntax 
9884 \family typewriter 
9885 \SpecialChar ~
9886 sfr P0 = 0x80;\SpecialChar ~
9887
9888 \family default 
9889  is compiled 
9890 \emph on 
9891 without warning
9892 \emph default 
9893  by SDCC to an assignment of 0x80 to a variable called P0 
9894 \family typewriter 
9895
9896 \begin_inset Marginal
9897 collapsed true
9898
9899 \layout Standard
9900
9901
9902 \series bold 
9903 \SpecialChar ~
9904 !
9905 \end_inset 
9906
9907 .
9908  
9909 \family default 
9910 Nevertheless it is possible to write header files
9911 \begin_inset LatexCommand \index{Header files}
9912
9913 \end_inset 
9914
9915
9916 \begin_inset LatexCommand \index{Include files}
9917
9918 \end_inset 
9919
9920  which can be shared among different compilers (see section 
9921 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
9922
9923 \end_inset 
9924
9925 ).
9926  
9927 \layout Subsubsection
9928
9929 Pointers
9930 \begin_inset LatexCommand \index{Pointer}
9931
9932 \end_inset 
9933
9934  to MCS51/DS390 specific memory spaces
9935 \layout Standard
9936
9937 SDCC allows (via language extensions) pointers to explicitly point to any
9938  of the memory spaces
9939 \begin_inset LatexCommand \index{Memory model}
9940
9941 \end_inset 
9942
9943  of the 8051.
9944  In addition to the explicit pointers, the compiler uses (by default) generic
9945  pointers which can be used to point to any of the memory spaces.
9946 \newline 
9947
9948 \newline 
9949 Pointer declaration examples:
9950 \layout Verse
9951
9952
9953 \family typewriter 
9954 /* pointer physically in internal ram pointing to object in external ram
9955  */ 
9956 \newline 
9957 __xdata unsigned char * __data p;
9958 \newline 
9959
9960 \newline 
9961 /* pointer physically in external ram pointing to object in internal ram
9962  */ 
9963 \newline 
9964 __data unsigned char * __xdata p;
9965 \newline 
9966
9967 \newline 
9968 /* pointer physically in code rom pointing to data in xdata space */ 
9969 \newline 
9970 __xdata unsigned char * __code p;
9971 \newline 
9972
9973 \newline 
9974 /* pointer physically in code space pointing to data in code space */ 
9975 \newline 
9976 __code unsigned char * __code p;
9977 \newline 
9978
9979 \newline 
9980 /* generic pointer physically located in xdata space */
9981 \newline 
9982 unsigned char * __xdata p;
9983 \newline 
9984
9985 \newline 
9986 /* generic pointer physically located in default memory space */
9987 \newline 
9988 unsigned char * p;
9989 \newline 
9990
9991 \newline 
9992 /* the following is a function pointer physically located in data space
9993  */
9994 \newline 
9995 char (* __data fp)(void);
9996 \layout Standard
9997
9998 Well you get the idea.
9999  
10000 \newline 
10001
10002 \newline 
10003 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10004 \emph on 
10005 generic
10006 \emph default 
10007  pointers.
10008  
10009 \size small 
10010
10011 \newline 
10012
10013 \newline 
10014
10015 \size default 
10016 The highest order byte of the 
10017 \emph on 
10018 generic
10019 \emph default 
10020  pointers contains the data space information.
10021  Assembler support routines are called whenever data is stored or retrieved
10022  using 
10023 \emph on 
10024 generic
10025 \emph default 
10026  pointers.
10027  These are useful for developing reusable library
10028 \begin_inset LatexCommand \index{Libraries}
10029
10030 \end_inset 
10031
10032  routines.
10033  Explicitly specifying the pointer type will generate the most efficient
10034  code.
10035 \layout Subsubsection
10036
10037 Notes on MCS51 memory
10038 \begin_inset LatexCommand \index{MCS51 memory}
10039
10040 \end_inset 
10041
10042  layout
10043 \layout Standard
10044
10045 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10046  RAM memory which is structured as follows:
10047 \newline 
10048
10049 \newline 
10050 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10051  
10052 \newline 
10053 - Bytes 20-2F - 16 bytes to hold 128 bit
10054 \begin_inset LatexCommand \index{bit}
10055
10056 \end_inset 
10057
10058  variables and, 
10059 \newline 
10060 - Bytes 30-7F - 80 bytes for general purpose use.
10061 \newline 
10062
10063 \layout Standard
10064
10065 Additionally some members of the MCS51 family may have up to 128 bytes of
10066  additional, indirectly addressable, internal RAM memory (
10067 \emph on 
10068 idata
10069 \emph default 
10070
10071 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10072
10073 \end_inset 
10074
10075
10076 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10077
10078 \end_inset 
10079
10080 ).
10081  Furthermore, some chips may have some built in external memory (
10082 \emph on 
10083 xdata
10084 \emph default 
10085
10086 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10087
10088 \end_inset 
10089
10090
10091 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10092
10093 \end_inset 
10094
10095 ) which should not be confused with the internal, directly addressable RAM
10096  memory (
10097 \emph on 
10098 data
10099 \emph default 
10100
10101 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10102
10103 \end_inset 
10104
10105
10106 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10107
10108 \end_inset 
10109
10110 ).
10111  Sometimes this built in 
10112 \emph on 
10113 xdata
10114 \emph default 
10115  memory has to be activated before using it (you can probably find this
10116  information on the datasheet of the microcontroller your are using, see
10117  also section 
10118 \begin_inset LatexCommand \ref{sub:Startup-Code}
10119
10120 \end_inset 
10121
10122 \SpecialChar ~
10123 Startup-Code).
10124 \layout Standard
10125
10126 Normally SDCC will only use the first bank
10127 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10128
10129 \end_inset 
10130
10131  of registers (register bank 0), but it is possible to specify that other
10132  banks of registers (keyword 
10133 \emph on 
10134 using
10135 \emph default 
10136  
10137 \emph on 
10138
10139 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10140
10141 \end_inset 
10142
10143
10144 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10145
10146 \end_inset 
10147
10148
10149 \emph default 
10150 ) should be used in interrupt
10151 \begin_inset LatexCommand \index{interrupt}
10152
10153 \end_inset 
10154
10155
10156 \begin_inset LatexCommand \index{\_\_interrupt}
10157
10158 \end_inset 
10159
10160  routines.
10161  By default, the compiler will place the stack after the last byte of allocated
10162  memory for variables.
10163  For example, if the first 2 banks of registers are used, and only four
10164  bytes are used for 
10165 \emph on 
10166 data
10167 \emph default 
10168  variables, it will position the base of the internal stack at address 20
10169  (0x14).
10170  This implies that as the stack
10171 \begin_inset LatexCommand \index{stack}
10172
10173 \end_inset 
10174
10175  grows, it will use up the remaining register banks, and the 16 bytes used
10176  by the 128 bit variables, and 80 bytes for general purpose use.
10177  If any bit variables are used, the data variables will be placed in unused
10178  register banks and after the byte holding the last bit variable.
10179  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10180  (two bytes used), 
10181 \emph on 
10182 data
10183 \emph default 
10184  variables will be placed starting from address 0x10 to 0x20 and continue
10185  at address 0x22.
10186  You can also use -
10187 \begin_inset ERT
10188 status Collapsed
10189
10190 \layout Standard
10191
10192 \backslash 
10193 /
10194 \end_inset 
10195
10196 -data-loc
10197 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10198
10199 \end_inset 
10200
10201  to specify the start address of the 
10202 \emph on 
10203 data
10204 \emph default 
10205  and -
10206 \begin_inset ERT
10207 status Collapsed
10208
10209 \layout Standard
10210
10211 \backslash 
10212 /
10213 \end_inset 
10214
10215 -iram-size
10216 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10217
10218 \end_inset 
10219
10220  to specify the size of the total internal RAM (
10221 \emph on 
10222 data
10223 \emph default 
10224 +
10225 \emph on 
10226 idata
10227 \emph default 
10228 ).
10229  
10230 \newline 
10231
10232 \layout Standard
10233
10234 By default the 8051 linker will place the stack after the last byte of (i)data
10235  variables.
10236  Option -
10237 \begin_inset ERT
10238 status Collapsed
10239
10240 \layout Standard
10241
10242 \backslash 
10243 /
10244 \end_inset 
10245
10246 -stack-loc
10247 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10248
10249 \end_inset 
10250
10251  allows you to specify the start of the stack, i.e.
10252  you could start it after any data in the general purpose area.
10253  If your microcontroller has additional indirectly addressable internal
10254  RAM (
10255 \emph on 
10256 idata
10257 \emph default 
10258 ) you can place the stack on it.
10259  You may also need to use -
10260 \begin_inset ERT
10261 status Collapsed
10262
10263 \layout Standard
10264
10265 \backslash 
10266 /
10267 \end_inset 
10268
10269 -xdata-loc
10270 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10271
10272 \end_inset 
10273
10274  to set the start address of the external RAM (
10275 \emph on 
10276 xdata
10277 \emph default 
10278 ) and -
10279 \begin_inset ERT
10280 status Collapsed
10281
10282 \layout Standard
10283
10284 \backslash 
10285 /
10286 \end_inset 
10287
10288 -xram-size
10289 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10290
10291 \end_inset 
10292
10293  to specify its size.
10294  Same goes for the code memory, using -
10295 \begin_inset ERT
10296 status Collapsed
10297
10298 \layout Standard
10299
10300 \backslash 
10301 /
10302 \end_inset 
10303
10304 -code-loc
10305 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10306
10307 \end_inset 
10308
10309  and -
10310 \begin_inset ERT
10311 status Collapsed
10312
10313 \layout Standard
10314
10315 \backslash 
10316 /
10317 \end_inset 
10318
10319 -code-size
10320 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10321
10322 \end_inset 
10323
10324 .
10325  If in doubt, don't specify any options and see if the resulting memory
10326  layout is appropriate, then you can adjust it.
10327 \layout Standard
10328 \added_space_bottom bigskip 
10329 The linker generates two files with memory allocation information.
10330  The first, with extension .map
10331 \begin_inset LatexCommand \index{<file>.map}
10332
10333 \end_inset 
10334
10335  shows all the variables and segments.
10336  The second with extension .mem
10337 \begin_inset LatexCommand \index{<file>.mem}
10338
10339 \end_inset 
10340
10341  shows the final memory layout.
10342  The linker will complain either if memory segments overlap, there is not
10343  enough memory, or there is not enough space for stack.
10344  If you get any linking warnings and/or errors related to stack or segments
10345  allocation, take a look at either the .map or .mem files to find out what
10346  the problem is.
10347  The .mem file may even suggest a solution to the problem.
10348 \layout Subsection
10349
10350 Z80/Z180 Storage Class
10351 \begin_inset LatexCommand \index{Z80!Storage class}
10352
10353 \end_inset 
10354
10355  Language Extensions
10356 \layout Subsubsection
10357
10358 sfr
10359 \begin_inset LatexCommand \index{sfr}
10360
10361 \end_inset 
10362
10363
10364 \begin_inset LatexCommand \index{\_\_sfr}
10365
10366 \end_inset 
10367
10368  (in/out to 8-bit addresses)
10369 \layout Standard
10370
10371 The Z80
10372 \begin_inset LatexCommand \index{Z80}
10373
10374 \end_inset 
10375
10376  family has separate address spaces for memory and 
10377 \emph on 
10378 i
10379 \emph default 
10380 nput/
10381 \emph on 
10382 o
10383 \emph default 
10384 utput memory.
10385  I/O memory
10386 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10387
10388 \end_inset 
10389
10390
10391 \begin_inset LatexCommand \index{Z80!I/O memory}
10392
10393 \end_inset 
10394
10395
10396 \begin_inset LatexCommand \index{Z180!I/O memory}
10397
10398 \end_inset 
10399
10400  is accessed with special instructions, e.g.:
10401 \layout Verse
10402
10403
10404 \family typewriter 
10405 sfr at 0x78 IoPort;\SpecialChar ~
10406 \SpecialChar ~
10407 /* define a var in I/O space at 78h called IoPort */
10408  
10409 \layout Standard
10410
10411 Writing 0x01 to this variable generates the assembly code:
10412 \layout Verse
10413
10414
10415 \family typewriter 
10416 3E 01\SpecialChar ~
10417 \SpecialChar ~
10418 \SpecialChar ~
10419 \SpecialChar ~
10420 \SpecialChar ~
10421 \SpecialChar ~
10422 ld a,#0x01
10423 \newline 
10424 D3 78\SpecialChar ~
10425 \SpecialChar ~
10426 \SpecialChar ~
10427 \SpecialChar ~
10428 \SpecialChar ~
10429 \SpecialChar ~
10430 out (_IoPort),a 
10431 \layout Subsubsection
10432
10433 banked sfr
10434 \begin_inset LatexCommand \index{sfr}
10435
10436 \end_inset 
10437
10438
10439 \begin_inset LatexCommand \index{\_\_sfr}
10440
10441 \end_inset 
10442
10443  (in/out to 16-bit addresses)
10444 \layout Standard
10445
10446 The keyword 
10447 \emph on 
10448 banked
10449 \emph default 
10450  is used to support 16 bit addresses in I/O memory e.g.:
10451 \layout Verse
10452
10453
10454 \family typewriter 
10455 sfr banked at
10456 \begin_inset LatexCommand \index{at}
10457
10458 \end_inset 
10459
10460
10461 \begin_inset LatexCommand \index{\_\_at}
10462
10463 \end_inset 
10464
10465  0x123 IoPort; 
10466 \layout Standard
10467
10468 Writing 0x01 to this variable generates the assembly code:
10469 \layout Verse
10470
10471
10472 \family typewriter 
10473 01 23 01\SpecialChar ~
10474 \SpecialChar ~
10475 \SpecialChar ~
10476 ld bc,#_IoPort
10477 \newline 
10478 3E 01\SpecialChar ~
10479 \SpecialChar ~
10480 \SpecialChar ~
10481 \SpecialChar ~
10482 \SpecialChar ~
10483 \SpecialChar ~
10484 ld a,#0x01 
10485 \newline 
10486 ED 79\SpecialChar ~
10487 \SpecialChar ~
10488 \SpecialChar ~
10489 \SpecialChar ~
10490 \SpecialChar ~
10491 \SpecialChar ~
10492 out (c),a 
10493 \layout Subsubsection
10494
10495 sfr
10496 \begin_inset LatexCommand \index{sfr}
10497
10498 \end_inset 
10499
10500
10501 \begin_inset LatexCommand \index{\_\_sfr}
10502
10503 \end_inset 
10504
10505  (in0/out0 to 8 bit addresses on Z180
10506 \begin_inset LatexCommand \index{Z180}
10507
10508 \end_inset 
10509
10510 /HD64180
10511 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10512
10513 \end_inset 
10514
10515 )
10516 \layout Standard
10517 \added_space_bottom bigskip 
10518 The compiler option -
10519 \begin_inset ERT
10520 status Collapsed
10521
10522 \layout Standard
10523
10524 \backslash 
10525 /
10526 \end_inset 
10527
10528 -portmode
10529 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10530
10531 \end_inset 
10532
10533 =180 (80) and a compiler #pragma\SpecialChar ~
10534 portmode
10535 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10536
10537 \end_inset 
10538
10539 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10540 ns 
10541 \family typewriter 
10542 in0/out0
10543 \family default 
10544  instead of 
10545 \family typewriter 
10546 in/out
10547 \family default 
10548 .
10549  If you include the file z180.h this will be set automatically.
10550 \layout Subsection
10551
10552 HC08 Storage Class
10553 \begin_inset LatexCommand \index{HC08!Storage class}
10554
10555 \end_inset 
10556
10557  Language Extensions
10558 \layout Subsubsection
10559
10560 data
10561 \begin_inset LatexCommand \index{data (hc08 storage class)}
10562
10563 \end_inset 
10564
10565
10566 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10567
10568 \end_inset 
10569
10570  
10571 \layout Standard
10572
10573 The data storage class declares a variable that resides in the first 256
10574  bytes of memory (the direct page).
10575  The HC08
10576 \begin_inset LatexCommand \index{HC08}
10577
10578 \end_inset 
10579
10580  is most efficient at accessing variables (especially pointers) stored here.
10581 \layout Subsubsection
10582
10583 xdata
10584 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10585
10586 \end_inset 
10587
10588
10589 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10590
10591 \end_inset 
10592
10593  
10594 \layout Standard
10595 \added_space_bottom bigskip 
10596 The xdata storage class declares a variable that can reside anywhere in
10597  memory.
10598  This is the default if no storage class is specified.
10599  
10600 \layout Section
10601
10602 Absolute Addressing
10603 \begin_inset LatexCommand \index{Absolute addressing}
10604
10605 \end_inset 
10606
10607
10608 \layout Standard
10609
10610 Data items can be assigned an absolute address with the 
10611 \emph on 
10612 at
10613 \begin_inset LatexCommand \index{at}
10614
10615 \end_inset 
10616
10617
10618 \begin_inset LatexCommand \index{\_\_at}
10619
10620 \end_inset 
10621
10622  <address>
10623 \emph default 
10624  keyword, in addition to a storage class, e.g.:
10625 \layout Verse
10626
10627
10628 \family typewriter 
10629 xdata
10630 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10631
10632 \end_inset 
10633
10634
10635 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10636
10637 \end_inset 
10638
10639  at
10640 \begin_inset LatexCommand \index{at}
10641
10642 \end_inset 
10643
10644
10645 \begin_inset LatexCommand \index{\_\_at}
10646
10647 \end_inset 
10648
10649  0x7ffe unsigned int chksum;
10650 \layout Standard
10651
10652 or, better conforming to ISO/IEC 9899 C:
10653 \layout Verse
10654
10655
10656 \family typewriter 
10657 __xdata __at (0x7ffe) unsigned int chksum;
10658 \layout Standard
10659
10660 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10661  of the external ram.
10662  The compiler does 
10663 \emph on 
10664 not
10665 \emph default 
10666  reserve any space for variables declared in this way
10667 \begin_inset Marginal
10668 collapsed true
10669
10670 \layout Standard
10671
10672
10673 \series bold 
10674 \SpecialChar ~
10675 !
10676 \end_inset 
10677
10678  (they are implemented with an equate in the assembler).
10679  Thus it is left to the programmer to make sure there are no overlaps with
10680  other variables that are declared without the absolute address.
10681  The assembler listing file (.lst
10682 \begin_inset LatexCommand \index{<file>.lst}
10683
10684 \end_inset 
10685
10686 ) and the linker output files (.rst
10687 \begin_inset LatexCommand \index{<file>.rst}
10688
10689 \end_inset 
10690
10691 ) and (.map
10692 \begin_inset LatexCommand \index{<file>.map}
10693
10694 \end_inset 
10695
10696 ) are good places to look for such overlaps.
10697  Variables with an absolute address are 
10698 \emph on 
10699 not
10700 \begin_inset Marginal
10701 collapsed true
10702
10703 \layout Standard
10704
10705
10706 \series bold 
10707 \SpecialChar ~
10708 !
10709 \end_inset 
10710
10711
10712 \emph default 
10713  initialized
10714 \begin_inset LatexCommand \index{Variable initialization}
10715
10716 \end_inset 
10717
10718 .
10719 \layout Standard
10720
10721 In case of memory mapped I/O devices the keyword 
10722 \emph on 
10723 volatile
10724 \emph default 
10725  has to be used to tell the compiler that accesses might not be removed:
10726 \layout Verse
10727
10728
10729 \family typewriter 
10730 volatile
10731 \begin_inset LatexCommand \index{volatile}
10732
10733 \end_inset 
10734
10735  __xdata
10736 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10737
10738 \end_inset 
10739
10740  __at
10741 \begin_inset LatexCommand \index{at}
10742
10743 \end_inset 
10744
10745  (0x8000) unsigned char PORTA_8255;
10746 \layout Standard
10747
10748 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10749 r) array
10750 \family typewriter 
10751 \size footnotesize 
10752
10753 \begin_inset LatexCommand \index{Aligned array}
10754
10755 \end_inset 
10756
10757
10758 \family default 
10759 \size default 
10760  starts at a block (256 byte) boundary
10761 \begin_inset LatexCommand \index{block boundary}
10762
10763 \end_inset 
10764
10765  (section 
10766 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10767
10768 \end_inset 
10769
10770  has an example).
10771 \newline 
10772 Absolute addresses can be specified for variables in all storage classes,
10773  e.g.:
10774 \layout Verse
10775
10776
10777 \family typewriter 
10778 __bit
10779 \begin_inset LatexCommand \index{bit}
10780
10781 \end_inset 
10782
10783  __at
10784 \begin_inset LatexCommand \index{at}
10785
10786 \end_inset 
10787
10788  (0x02) bvar;
10789 \layout Standard
10790
10791 The above example will allocate the variable at offset 0x02 in the bit-addressab
10792 le space.
10793  There is no real advantage to assigning absolute addresses to variables
10794  in this manner, unless you want strict control over all the variables allocated.
10795  One possible use would be to write hardware portable code.
10796  For example, if you have a routine that uses one or more of the microcontroller
10797  I/O pins, and such pins are different for two different hardwares, you
10798  can declare the I/O pins in your routine using:
10799 \layout Verse
10800
10801
10802 \family typewriter 
10803 extern volatile
10804 \begin_inset LatexCommand \index{volatile}
10805
10806 \end_inset 
10807
10808  __bit MOSI;\SpecialChar ~
10809 \SpecialChar ~
10810 \SpecialChar ~
10811 \SpecialChar ~
10812 /* master out, slave in */
10813 \newline 
10814 extern volatile __bit MISO;\SpecialChar ~
10815 \SpecialChar ~
10816 \SpecialChar ~
10817 \SpecialChar ~
10818 /* master in, slave out */
10819 \newline 
10820 extern volatile __bit MCLK;\SpecialChar ~
10821 \SpecialChar ~
10822 \SpecialChar ~
10823 \SpecialChar ~
10824 /* master clock */
10825 \newline 
10826
10827 \newline 
10828 /* Input and Output of a byte on a 3-wire serial bus.
10829 \newline 
10830 \SpecialChar ~
10831 \SpecialChar ~
10832 \SpecialChar ~
10833 If needed adapt polarity of clock, polarity of data and bit order
10834 \newline 
10835 \SpecialChar ~
10836 */
10837 \newline 
10838 unsigned char spi_io(unsigned char out_byte) 
10839 \newline 
10840
10841 \newline 
10842 \SpecialChar ~
10843 \SpecialChar ~
10844 \SpecialChar ~
10845 \SpecialChar ~
10846 unsigned char i=8;
10847 \newline 
10848 \SpecialChar ~
10849 \SpecialChar ~
10850 \SpecialChar ~
10851 \SpecialChar ~
10852 do { 
10853 \newline 
10854 \SpecialChar ~
10855 \SpecialChar ~
10856 \SpecialChar ~
10857 \SpecialChar ~
10858 \SpecialChar ~
10859 \SpecialChar ~
10860 \SpecialChar ~
10861 \SpecialChar ~
10862 MOSI = out_byte & 0x80; 
10863 \newline 
10864 \SpecialChar ~
10865 \SpecialChar ~
10866 \SpecialChar ~
10867 \SpecialChar ~
10868 \SpecialChar ~
10869 \SpecialChar ~
10870 \SpecialChar ~
10871 \SpecialChar ~
10872 out_byte <<= 1;
10873 \newline 
10874 \SpecialChar ~
10875 \SpecialChar ~
10876 \SpecialChar ~
10877 \SpecialChar ~
10878 \SpecialChar ~
10879 \SpecialChar ~
10880 \SpecialChar ~
10881 \SpecialChar ~
10882 MCLK = 1; 
10883 \newline 
10884 \SpecialChar ~
10885 \SpecialChar ~
10886 \SpecialChar ~
10887 \SpecialChar ~
10888 \SpecialChar ~
10889 \SpecialChar ~
10890 \SpecialChar ~
10891 \SpecialChar ~
10892 /* _asm nop _endasm; */\SpecialChar ~
10893 \SpecialChar ~
10894 \SpecialChar ~
10895 \SpecialChar ~
10896 \SpecialChar ~
10897 \SpecialChar ~
10898 \SpecialChar ~
10899 \SpecialChar ~
10900 /* for slow peripherals */
10901 \newline 
10902 \SpecialChar ~
10903 \SpecialChar ~
10904 \SpecialChar ~
10905 \SpecialChar ~
10906 \SpecialChar ~
10907 \SpecialChar ~
10908 \SpecialChar ~
10909 \SpecialChar ~
10910 if(MISO) 
10911 \newline 
10912 \SpecialChar ~
10913 \SpecialChar ~
10914 \SpecialChar ~
10915 \SpecialChar ~
10916 \SpecialChar ~
10917 \SpecialChar ~
10918 \SpecialChar ~
10919 \SpecialChar ~
10920 \SpecialChar ~
10921 \SpecialChar ~
10922 \SpecialChar ~
10923 \SpecialChar ~
10924 out_byte += 1; 
10925 \newline 
10926 \SpecialChar ~
10927 \SpecialChar ~
10928 \SpecialChar ~
10929 \SpecialChar ~
10930 \SpecialChar ~
10931 \SpecialChar ~
10932 \SpecialChar ~
10933 \SpecialChar ~
10934 MCLK = 0; 
10935 \newline 
10936 \SpecialChar ~
10937 \SpecialChar ~
10938 \SpecialChar ~
10939 \SpecialChar ~
10940 } while(--i);
10941 \newline 
10942 \SpecialChar ~
10943 \SpecialChar ~
10944 \SpecialChar ~
10945 \SpecialChar ~
10946 return out_byte; 
10947 \newline 
10948 }
10949 \layout Standard
10950
10951 Then, someplace in the code for the first hardware you would use
10952 \layout Verse
10953
10954
10955 \family typewriter 
10956 __bit __at
10957 \begin_inset LatexCommand \index{at}
10958
10959 \end_inset 
10960
10961
10962 \begin_inset LatexCommand \index{\_\_at}
10963
10964 \end_inset 
10965
10966  (0x80) MOSI;\SpecialChar ~
10967 \SpecialChar ~
10968 \SpecialChar ~
10969 \SpecialChar ~
10970 /* I/O port 0, bit 0 */
10971 \newline 
10972 __bit __at (0x81) MISO;\SpecialChar ~
10973 \SpecialChar ~
10974 \SpecialChar ~
10975 \SpecialChar ~
10976 /* I/O port 0, bit 1 */
10977 \newline 
10978 __bit __at (0x82) MCLK;\SpecialChar ~
10979 \SpecialChar ~
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 /* I/O port 0, bit 2 */
10983 \layout Standard
10984
10985 Similarly, for the second hardware you would use
10986 \layout Verse
10987
10988
10989 \family typewriter 
10990 __bit __at (0x83) MOSI;\SpecialChar ~
10991 \SpecialChar ~
10992 \SpecialChar ~
10993 \SpecialChar ~
10994 /* I/O port 0, bit 3 */
10995 \newline 
10996 __bit __at (0x91) MISO;\SpecialChar ~
10997 \SpecialChar ~
10998 \SpecialChar ~
10999 \SpecialChar ~
11000 /* I/O port 1, bit 1 */
11001 \newline 
11002 __bit
11003 \begin_inset LatexCommand \index{bit}
11004
11005 \end_inset 
11006
11007  __at (0x92) MCLK;\SpecialChar ~
11008 \SpecialChar ~
11009 \SpecialChar ~
11010 \SpecialChar ~
11011 /* I/O port 1, bit 2 */
11012 \layout Standard
11013 \added_space_bottom bigskip 
11014 and you can use the same hardware dependent routine without changes, as
11015  for example in a library.
11016  This is somehow similar to sbit, but only one absolute address has to be
11017  specified in the whole project.
11018 \layout Section
11019
11020 Parameters
11021 \begin_inset LatexCommand \index{Parameters}
11022
11023 \end_inset 
11024
11025
11026 \begin_inset LatexCommand \index{function parameter}
11027
11028 \end_inset 
11029
11030  & Local Variables
11031 \begin_inset LatexCommand \index{local variables}
11032
11033 \end_inset 
11034
11035
11036 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11037
11038 \end_inset 
11039
11040
11041 \layout Standard
11042
11043 Automatic (local) variables and parameters to functions can either be placed
11044  on the stack or in data-space.
11045  The default action of the compiler is to place these variables in the internal
11046  RAM (for small model) or external RAM (for large model).
11047  This in fact makes them similar to 
11048 \emph on 
11049 static
11050 \begin_inset LatexCommand \index{static}
11051
11052 \end_inset 
11053
11054
11055 \emph default 
11056  so by default functions are non-reentrant
11057 \begin_inset LatexCommand \index{reentrant}
11058
11059 \end_inset 
11060
11061 .
11062  
11063 \newline 
11064
11065 \newline 
11066 They can be placed on the stack
11067 \begin_inset LatexCommand \index{stack}
11068
11069 \end_inset 
11070
11071  by using the
11072 \emph on 
11073  -
11074 \begin_inset ERT
11075 status Collapsed
11076
11077 \layout Standard
11078
11079 \backslash 
11080 /
11081 \end_inset 
11082
11083 -stack-auto
11084 \begin_inset LatexCommand \index{-\/-stack-auto}
11085
11086 \end_inset 
11087
11088
11089 \emph default 
11090  option, by using 
11091 \emph on 
11092 #pragma\SpecialChar ~
11093 stackauto
11094 \emph default 
11095
11096 \begin_inset LatexCommand \index{\#pragma stackauto}
11097
11098 \end_inset 
11099
11100  or by using the 
11101 \emph on 
11102 reentrant
11103 \begin_inset LatexCommand \index{reentrant}
11104
11105 \end_inset 
11106
11107
11108 \emph default 
11109  keyword in the function declaration, e.g.:
11110 \layout Verse
11111
11112
11113 \family typewriter 
11114 unsigned char foo(char i) __reentrant 
11115 \newline 
11116
11117 \newline 
11118 \SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 ...
11123  
11124 \newline 
11125 }
11126 \layout Standard
11127
11128 Since stack space on 8051 is limited, the 
11129 \emph on 
11130 reentrant 
11131 \emph default 
11132 keyword or the
11133 \emph on 
11134  -
11135 \begin_inset ERT
11136 status Collapsed
11137
11138 \layout Standard
11139
11140 \backslash 
11141 /
11142 \end_inset 
11143
11144 -stack-auto
11145 \emph default 
11146  option should be used sparingly.
11147  Note that the reentrant keyword just means that the parameters & local
11148  variables will be allocated to the stack, it 
11149 \emph on 
11150 does not
11151 \emph default 
11152  mean that the function is register bank
11153 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11154
11155 \end_inset 
11156
11157  independent.
11158 \newline 
11159
11160 \newline 
11161 Local variables
11162 \begin_inset LatexCommand \index{local variables}
11163
11164 \end_inset 
11165
11166  can be assigned storage classes and absolute
11167 \begin_inset LatexCommand \index{Absolute addressing}
11168
11169 \end_inset 
11170
11171  addresses, e.g.: 
11172 \layout Verse
11173
11174
11175 \family typewriter 
11176 unsigned char foo() 
11177 \newline 
11178 {
11179 \newline 
11180 \SpecialChar ~
11181 \SpecialChar ~
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 __xdata unsigned char i;
11185 \newline 
11186 \SpecialChar ~
11187 \SpecialChar ~
11188 \SpecialChar ~
11189 \SpecialChar ~
11190 __bit bvar;
11191 \newline 
11192 \SpecialChar ~
11193 \SpecialChar ~
11194 \SpecialChar ~
11195 \SpecialChar ~
11196 __data __at
11197 \begin_inset LatexCommand \index{at}
11198
11199 \end_inset 
11200
11201  (0x31) unsigned char j;
11202 \newline 
11203 \SpecialChar ~
11204 \SpecialChar ~
11205 \SpecialChar ~
11206 \SpecialChar ~
11207 ...
11208  
11209 \newline 
11210 }
11211 \layout Standard
11212
11213 In the above example the variable 
11214 \emph on 
11215 i
11216 \emph default 
11217  will be allocated in the external ram, 
11218 \emph on 
11219 bvar
11220 \emph default 
11221  in bit addressable space and
11222 \emph on 
11223  j
11224 \emph default 
11225  in internal ram.
11226  When compiled with 
11227 \emph on 
11228 -
11229 \begin_inset ERT
11230 status Collapsed
11231
11232 \layout Standard
11233
11234 \backslash 
11235 /
11236 \end_inset 
11237
11238 -stack-auto
11239 \emph default 
11240  or when a function is declared as 
11241 \emph on 
11242 reentrant
11243 \emph default 
11244  this should only be done for static variables.
11245 \layout Standard
11246
11247 Parameters
11248 \begin_inset LatexCommand \index{function parameter}
11249
11250 \end_inset 
11251
11252  however are not allowed any storage class
11253 \begin_inset LatexCommand \index{Storage class}
11254
11255 \end_inset 
11256
11257 , (storage classes for parameters will be ignored), their allocation is
11258  governed by the memory model in use, and the reentrancy options.
11259 \layout Standard
11260
11261 It is however allowed to use bit parameters in reentrant functions and also
11262  non-static local bit variables are supported.
11263  Efficient use is limited to 8 semi-bitregisters in bit space.
11264  They are pushed and popped to stack
11265 \begin_inset LatexCommand \index{stack}
11266
11267 \end_inset 
11268
11269  as a single byte just like the normal registers.
11270 \layout Section
11271
11272 Overlaying
11273 \begin_inset LatexCommand \label{sub:Overlaying}
11274
11275 \end_inset 
11276
11277
11278 \begin_inset LatexCommand \index{Overlaying}
11279
11280 \end_inset 
11281
11282
11283 \layout Standard
11284
11285 For non-reentrant
11286 \begin_inset LatexCommand \index{reentrant}
11287
11288 \end_inset 
11289
11290  functions SDCC will try to reduce internal ram space usage by overlaying
11291  parameters and local variables of a function (if possible).
11292  Parameters and local variables
11293 \begin_inset LatexCommand \index{local variables}
11294
11295 \end_inset 
11296
11297  of a function will be allocated to an overlayable segment if the function
11298  has 
11299 \emph on 
11300 no other function calls and the function is non-reentrant and the memory
11301  model
11302 \begin_inset LatexCommand \index{Memory model}
11303
11304 \end_inset 
11305
11306  is small.
11307
11308 \emph default 
11309  If an explicit storage class
11310 \begin_inset LatexCommand \index{Storage class}
11311
11312 \end_inset 
11313
11314  is specified for a local variable, it will NOT be overlayed.
11315 \layout Standard
11316
11317 Note that the compiler (not the linkage editor) makes the decision for overlayin
11318 g the data items.
11319  Functions that are called from an interrupt service routine
11320 \begin_inset Marginal
11321 collapsed true
11322
11323 \layout Standard
11324
11325
11326 \series bold 
11327 !
11328 \end_inset 
11329
11330  should be preceded by a #pragma\SpecialChar ~
11331 nooverlay
11332 \begin_inset LatexCommand \index{\#pragma nooverlay}
11333
11334 \end_inset 
11335
11336  if they are not reentrant.
11337 \layout Standard
11338
11339 Also note that the compiler does not do any processing of inline assembler
11340  code, so the compiler might incorrectly assign local variables and parameters
11341  of a function into the overlay segment if the inline assembler code calls
11342  other c-functions that might use the overlay.
11343  In that case the #pragma\SpecialChar ~
11344 nooverlay should be used.
11345 \layout Standard
11346
11347 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11348 tion
11349 \begin_inset LatexCommand \index{Multiplication}
11350
11351 \end_inset 
11352
11353  or division
11354 \begin_inset LatexCommand \index{Division}
11355
11356 \end_inset 
11357
11358  will NOT be overlayed since these are implemented using external functions,
11359  e.g.:
11360 \layout Verse
11361
11362
11363 \family typewriter 
11364 #pragma save 
11365 \newline 
11366 #pragma nooverlay
11367 \begin_inset LatexCommand \index{\#pragma nooverlay}
11368
11369 \end_inset 
11370
11371  
11372 \newline 
11373 void set_error(unsigned char errcd) 
11374 \newline 
11375 {
11376 \newline 
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 \SpecialChar ~
11380 \SpecialChar ~
11381 P3 = errcd;
11382 \newline 
11383
11384 \newline 
11385 #pragma restore 
11386 \newline 
11387
11388 \newline 
11389 void some_isr () __interrupt
11390 \begin_inset LatexCommand \index{interrupt}
11391
11392 \end_inset 
11393
11394  (2)
11395 \newline 
11396 {
11397 \newline 
11398 \SpecialChar ~
11399 \SpecialChar ~
11400 \SpecialChar ~
11401 \SpecialChar ~
11402 ...
11403 \newline 
11404 \SpecialChar ~
11405 \SpecialChar ~
11406 \SpecialChar ~
11407 \SpecialChar ~
11408 set_error(10);
11409 \newline 
11410 \SpecialChar ~
11411 \SpecialChar ~
11412 \SpecialChar ~
11413 \SpecialChar ~
11414 ...
11415  
11416 \newline 
11417 }
11418 \layout Standard
11419 \added_space_bottom bigskip 
11420 In the above example the parameter 
11421 \emph on 
11422 errcd
11423 \emph default 
11424  for the function 
11425 \emph on 
11426 set_error
11427 \emph default 
11428  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11429 nooverlay was
11430  not present, this could cause unpredictable runtime behavior when called
11431  from an interrupt service routine.
11432  The #pragma\SpecialChar ~
11433 nooverlay ensures that the parameters and local variables for
11434  the function are NOT overlayed.
11435 \layout Section
11436
11437 Interrupt Service Routines
11438 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11439
11440 \end_inset 
11441
11442
11443 \layout Subsection
11444
11445 General Information
11446 \layout Standard
11447
11448 SDCC allows 
11449 \emph on 
11450 i
11451 \emph default 
11452 nterrupt 
11453 \emph on 
11454 s
11455 \emph default 
11456 ervice 
11457 \emph on 
11458 r
11459 \emph default 
11460 outines to be coded in C, with some extended keywords.
11461 \layout Verse
11462
11463
11464 \family typewriter 
11465 void timer_isr (void) __interrupt (1) __using (1) 
11466 \newline 
11467
11468 \newline 
11469 \SpecialChar ~
11470 \SpecialChar ~
11471 \SpecialChar ~
11472 \SpecialChar ~
11473 ...
11474  
11475 \newline 
11476 }
11477 \layout Standard
11478
11479 The optional number following the 
11480 \emph on 
11481 interrupt
11482 \begin_inset LatexCommand \index{interrupt}
11483
11484 \end_inset 
11485
11486
11487 \begin_inset LatexCommand \index{\_\_interrupt}
11488
11489 \end_inset 
11490
11491
11492 \emph default 
11493  keyword is the interrupt number this routine will service.
11494  When present, the compiler will insert a call to this routine in the interrupt
11495  vector table for the interrupt number specified.
11496  If you have multiple source files in your project, interrupt service routines
11497  can be present in any of them, but a prototype of the isr MUST be present
11498  or included in the file that contains the function 
11499 \emph on 
11500 main
11501 \emph default 
11502 .
11503  The optional (8051 specific) keyword 
11504 \emph on 
11505 using
11506 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11507
11508 \end_inset 
11509
11510
11511 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11512
11513 \end_inset 
11514
11515
11516 \emph default 
11517  can be used to tell the compiler to use the specified register bank when
11518  generating code for this function.
11519  
11520 \newline 
11521 Interrupt service routines open the door for some very interesting bugs:
11522 \layout Subsubsection
11523
11524
11525 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11526
11527 \end_inset 
11528
11529 Common interrupt pitfall: variable not declared 
11530 \emph on 
11531 volatile
11532 \layout Standard
11533
11534 If an interrupt service routine changes variables which are accessed by
11535  other functions these variables have to be declared 
11536 \emph on 
11537 volatile
11538 \emph default 
11539
11540 \begin_inset LatexCommand \index{volatile}
11541
11542 \end_inset 
11543
11544 .
11545  See 
11546 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11547
11548 \end_inset 
11549
11550  .
11551 \layout Subsubsection
11552
11553
11554 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11555
11556 \end_inset 
11557
11558 Common interrupt pitfall: 
11559 \emph on 
11560 non-atomic access
11561 \layout Standard
11562
11563 If the access to these variables is not 
11564 \emph on 
11565 atomic
11566 \begin_inset LatexCommand \index{atomic}
11567
11568 \end_inset 
11569
11570
11571 \emph default 
11572  (i.e.
11573  the processor needs more than one instruction for the access and could
11574  be interrupted while accessing the variable) the interrupt must be disabled
11575  during the access to avoid inconsistent data.
11576  
11577 \newline 
11578 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11579  should be protected by disabling interrupts.
11580  You're not automatically on the safe side if you use 8 bit variables though.
11581  We need an example here: f.e.
11582  on the 8051 the harmless looking 
11583 \begin_inset Quotes srd
11584 \end_inset 
11585
11586
11587 \family typewriter 
11588 flags\SpecialChar ~
11589 |=\SpecialChar ~
11590 0x80;
11591 \family default 
11592
11593 \begin_inset Quotes sld
11594 \end_inset 
11595
11596  is not atomic if 
11597 \family typewriter 
11598 flags
11599 \family default 
11600  resides in xdata.
11601  Setting 
11602 \begin_inset Quotes srd
11603 \end_inset 
11604
11605
11606 \family typewriter 
11607 flags\SpecialChar ~
11608 |=\SpecialChar ~
11609 0x40;
11610 \family default 
11611
11612 \begin_inset Quotes sld
11613 \end_inset 
11614
11615  from within an interrupt routine might get lost if the interrupt occurs
11616  at the wrong time.
11617  
11618 \begin_inset Quotes sld
11619 \end_inset 
11620
11621
11622 \family typewriter 
11623 counter\SpecialChar ~
11624 +=\SpecialChar ~
11625 8;
11626 \family default 
11627
11628 \begin_inset Quotes srd
11629 \end_inset 
11630
11631  is not atomic on the 8051 even if 
11632 \family typewriter 
11633 counter
11634 \family default 
11635  is located in data memory.
11636 \newline 
11637 Bugs like these are hard to reproduce and can cause a lot of trouble.
11638  
11639 \layout Subsubsection
11640
11641
11642 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11643
11644 \end_inset 
11645
11646 Common interrupt pitfall: 
11647 \emph on 
11648 stack overflow
11649 \layout Standard
11650
11651 The return address and the registers used in the interrupt service routine
11652  are saved on the stack
11653 \begin_inset LatexCommand \index{stack}
11654
11655 \end_inset 
11656
11657  so there must be sufficient stack space.
11658  If there isn't variables or registers (or even the return address itself)
11659  will be corrupted.
11660  This 
11661 \emph on 
11662 stack overflow
11663 \emph default 
11664
11665 \begin_inset LatexCommand \index{stack overflow}
11666
11667 \end_inset 
11668
11669  is most likely to happen if the interrupt occurs during the 
11670 \begin_inset Quotes sld
11671 \end_inset 
11672
11673 deepest
11674 \begin_inset Quotes srd
11675 \end_inset 
11676
11677  subroutine when the stack is already in use for f.e.
11678  many return addresses.
11679 \layout Subsubsection
11680
11681
11682 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11683
11684 \end_inset 
11685
11686 Common interrupt pitfall: 
11687 \emph on 
11688 use of non-reentrant functions
11689 \layout Standard
11690
11691 A special note here, int (16 bit) and long (32 bit) integer division
11692 \begin_inset LatexCommand \index{Division}
11693
11694 \end_inset 
11695
11696 , multiplication
11697 \begin_inset LatexCommand \index{Multiplication}
11698
11699 \end_inset 
11700
11701  & modulus
11702 \begin_inset LatexCommand \index{Modulus}
11703
11704 \end_inset 
11705
11706  and floating-point
11707 \begin_inset LatexCommand \index{Floating point support}
11708
11709 \end_inset 
11710
11711  operations are implemented using external support routines.
11712  If an interrupt service routine needs to do any of these operations then
11713  the support routines (as mentioned in a following section) will have to
11714  be recompiled using the
11715 \emph on 
11716  -
11717 \begin_inset ERT
11718 status Collapsed
11719
11720 \layout Standard
11721
11722 \backslash 
11723 /
11724 \end_inset 
11725
11726 -stack-auto
11727 \begin_inset LatexCommand \index{-\/-stack-auto}
11728
11729 \end_inset 
11730
11731
11732 \emph default 
11733  option and the source file will need to be compiled using the 
11734 \emph on 
11735 -
11736 \begin_inset ERT
11737 status Collapsed
11738
11739 \layout Standard
11740
11741 \backslash 
11742 /
11743 \end_inset 
11744
11745 -int-long-reent
11746 \emph default 
11747
11748 \begin_inset LatexCommand \index{-\/-int-long-reent}
11749
11750 \end_inset 
11751
11752  compiler option.
11753  
11754 \newline 
11755 Note, the type promotion
11756 \begin_inset LatexCommand \index{type promotion}
11757
11758 \end_inset 
11759
11760  required by ANSI C can cause 16 bit routines to be used
11761 \begin_inset Marginal
11762 collapsed true
11763
11764 \layout Standard
11765
11766
11767 \series bold 
11768 \SpecialChar ~
11769 !
11770 \end_inset 
11771
11772  without the programmer being aware of it.
11773  See f.e.
11774  the cast 
11775 \family typewriter 
11776 (unsigned char)(tail-1)
11777 \family default 
11778  within the if clause in section 
11779 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11780
11781 \end_inset 
11782
11783 .
11784 \layout Standard
11785 \added_space_bottom bigskip 
11786 Calling other functions from an interrupt service routine is not recommended,
11787  avoid it if possible.
11788  Note that when some function is called from an interrupt service routine
11789  it should be preceded by a #pragma\SpecialChar ~
11790 nooverlay
11791 \begin_inset LatexCommand \index{\#pragma nooverlay}
11792
11793 \end_inset 
11794
11795  if it is not reentrant.
11796  Furthermore nonreentrant functions should not be called from the main program
11797  while the interrupt service routine might be active.
11798  They also must not be called from low priority interrupt service routines
11799  while a high priority interrupt service routine might be active.
11800  You could use semaphores or make the function
11801 \emph on 
11802  critical
11803 \emph default 
11804  if all parameters are passed in registers.
11805 \newline 
11806  Also see section 
11807 \begin_inset LatexCommand \ref{sub:Overlaying}
11808
11809 \end_inset 
11810
11811 \SpecialChar ~
11812 about Overlaying and section 
11813 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11814
11815 \end_inset 
11816
11817 \SpecialChar ~
11818 about Functions using private register banks.
11819 \layout Subsection
11820
11821 MCS51/DS390 Interrupt Service Routines
11822 \layout Standard
11823
11824 Interrupt numbers and the corresponding address & descriptions for the Standard
11825  8051/8052 are listed below.
11826  SDCC will automatically adjust the interrupt vector table to the maximum
11827  interrupt number specified.
11828 \newline 
11829
11830 \layout Standard
11831 \align center 
11832
11833 \begin_inset  Tabular
11834 <lyxtabular version="3" rows="9" columns="3">
11835 <features>
11836 <column alignment="center" valignment="top" leftline="true" width="0in">
11837 <column alignment="left" valignment="top" leftline="true" width="0in">
11838 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
11839 <row topline="true" bottomline="true">
11840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11841 \begin_inset Text
11842
11843 \layout Standard
11844
11845 Interrupt #
11846 \end_inset 
11847 </cell>
11848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11849 \begin_inset Text
11850
11851 \layout Standard
11852
11853 Description
11854 \end_inset 
11855 </cell>
11856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11857 \begin_inset Text
11858
11859 \layout Standard
11860
11861 Vector Address
11862 \end_inset 
11863 </cell>
11864 </row>
11865 <row topline="true">
11866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11867 \begin_inset Text
11868
11869 \layout Standard
11870
11871 0
11872 \end_inset 
11873 </cell>
11874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11875 \begin_inset Text
11876
11877 \layout Standard
11878
11879 External 0
11880 \end_inset 
11881 </cell>
11882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11883 \begin_inset Text
11884
11885 \layout Standard
11886
11887 0x0003
11888 \end_inset 
11889 </cell>
11890 </row>
11891 <row topline="true">
11892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11893 \begin_inset Text
11894
11895 \layout Standard
11896
11897 1
11898 \end_inset 
11899 </cell>
11900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11901 \begin_inset Text
11902
11903 \layout Standard
11904
11905 Timer 0
11906 \end_inset 
11907 </cell>
11908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11909 \begin_inset Text
11910
11911 \layout Standard
11912
11913 0x000b
11914 \end_inset 
11915 </cell>
11916 </row>
11917 <row topline="true">
11918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11919 \begin_inset Text
11920
11921 \layout Standard
11922
11923 2
11924 \end_inset 
11925 </cell>
11926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11927 \begin_inset Text
11928
11929 \layout Standard
11930
11931 External 1
11932 \end_inset 
11933 </cell>
11934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11935 \begin_inset Text
11936
11937 \layout Standard
11938
11939 0x0013
11940 \end_inset 
11941 </cell>
11942 </row>
11943 <row topline="true">
11944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11945 \begin_inset Text
11946
11947 \layout Standard
11948
11949 3
11950 \end_inset 
11951 </cell>
11952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11953 \begin_inset Text
11954
11955 \layout Standard
11956
11957 Timer 1
11958 \end_inset 
11959 </cell>
11960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11961 \begin_inset Text
11962
11963 \layout Standard
11964
11965 0x001b
11966 \end_inset 
11967 </cell>
11968 </row>
11969 <row topline="true">
11970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11971 \begin_inset Text
11972
11973 \layout Standard
11974
11975 4
11976 \end_inset 
11977 </cell>
11978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11979 \begin_inset Text
11980
11981 \layout Standard
11982
11983 Serial
11984 \end_inset 
11985 </cell>
11986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11987 \begin_inset Text
11988
11989 \layout Standard
11990
11991 0x0023
11992 \end_inset 
11993 </cell>
11994 </row>
11995 <row topline="true">
11996 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11997 \begin_inset Text
11998
11999 \layout Standard
12000
12001 5
12002 \end_inset 
12003 </cell>
12004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12005 \begin_inset Text
12006
12007 \layout Standard
12008
12009 Timer 2 (8052)
12010 \end_inset 
12011 </cell>
12012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12013 \begin_inset Text
12014
12015 \layout Standard
12016
12017 0x002b
12018 \end_inset 
12019 </cell>
12020 </row>
12021 <row topline="true">
12022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12023 \begin_inset Text
12024
12025 \layout Standard
12026
12027 ...
12028 \end_inset 
12029 </cell>
12030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12031 \begin_inset Text
12032
12033 \layout Standard
12034
12035 \end_inset 
12036 </cell>
12037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12038 \begin_inset Text
12039
12040 \layout Standard
12041
12042 ...
12043 \end_inset 
12044 </cell>
12045 </row>
12046 <row topline="true" bottomline="true">
12047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12048 \begin_inset Text
12049
12050 \layout Standard
12051
12052 n
12053 \end_inset 
12054 </cell>
12055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12056 \begin_inset Text
12057
12058 \layout Standard
12059
12060 \end_inset 
12061 </cell>
12062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12063 \begin_inset Text
12064
12065 \layout Standard
12066
12067 0x0003 + 8*n
12068 \end_inset 
12069 </cell>
12070 </row>
12071 </lyxtabular>
12072
12073 \end_inset 
12074
12075
12076 \newline 
12077
12078 \layout Standard
12079
12080 If the interrupt service routine is defined without 
12081 \emph on 
12082 using
12083 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12084
12085 \end_inset 
12086
12087
12088 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12089
12090 \end_inset 
12091
12092
12093 \emph default 
12094  a register bank or with register bank 0 (
12095 \emph on 
12096 using
12097 \emph default 
12098  0), the compiler will save the registers used by itself on the stack upon
12099  entry and restore them at exit, however if such an interrupt service routine
12100  calls another function then the entire register bank will be saved on the
12101  stack.
12102  This scheme may be advantageous for small interrupt service routines which
12103  have low register usage.
12104 \layout Standard
12105 \added_space_bottom bigskip 
12106 If the interrupt service routine is defined to be using a specific register
12107  bank then only 
12108 \emph on 
12109 a, b, dptr
12110 \emph default 
12111  & psw are saved and restored, if such an interrupt service routine calls
12112  another function (using another register bank) then the entire register
12113  bank of the called function will be saved on the stack
12114 \begin_inset LatexCommand \index{stack}
12115
12116 \end_inset 
12117
12118 .
12119  This scheme is recommended for larger interrupt service routines.
12120 \layout Subsection
12121
12122 HC08
12123 \begin_inset LatexCommand \index{HC08}
12124
12125 \end_inset 
12126
12127  Interrupt Service Routines
12128 \layout Standard
12129 \added_space_bottom bigskip 
12130 Since the number of interrupts
12131 \begin_inset LatexCommand \index{HC08!interrupt}
12132
12133 \end_inset 
12134
12135  available is chip specific and the interrupt vector table always ends at
12136  the last byte of memory, the interrupt numbers corresponds to the interrupt
12137  vectors in reverse order of address.
12138  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12139  2 will use the interrupt vector at 0xfffa, and so on.
12140  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12141  this way; instead see section 
12142 \begin_inset LatexCommand \ref{sub:Startup-Code}
12143
12144 \end_inset 
12145
12146  for details on customizing startup.
12147 \layout Subsection
12148
12149 Z80 Interrupt Service Routines
12150 \layout Standard
12151
12152 The Z80
12153 \begin_inset LatexCommand \index{Z80}
12154
12155 \end_inset 
12156
12157  uses several different methods for determining the correct interrupt
12158 \begin_inset LatexCommand \index{Z80!interrupt}
12159
12160 \end_inset 
12161
12162  vector depending on the hardware implementation.
12163  Therefore, SDCC ignores the optional interrupt number and does not attempt
12164  to generate an interrupt vector table.
12165 \layout Standard
12166
12167 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12168  instruction to return from the interrupt.
12169  To write an interrupt handler for the non-maskable interrupt, which needs
12170  a RETN instruction instead, add the 
12171 \emph on 
12172 critical
12173 \emph default 
12174  keyword:
12175 \layout Verse
12176
12177
12178 \family typewriter 
12179 void nmi_isr (void) critical interrupt
12180 \newline 
12181
12182 \newline 
12183 \SpecialChar ~
12184 \SpecialChar ~
12185 \SpecialChar ~
12186 \SpecialChar ~
12187 ...
12188  
12189 \newline 
12190 }
12191 \layout Standard
12192 \added_space_bottom bigskip 
12193 However if you need to create a non-interruptable interrupt service routine
12194  you would also require the 
12195 \emph on 
12196 critical
12197 \emph default 
12198  keyword.
12199  To distinguish between this and an nmi_isr you must provide an interrupt
12200  number.
12201 \layout Section
12202
12203 Enabling and Disabling Interrupts
12204 \layout Subsection
12205
12206 Critical Functions and Critical Statements
12207 \layout Standard
12208
12209 A special keyword may be associated with a block or a function declaring
12210  it as 
12211 \emph on 
12212 critical
12213 \emph default 
12214 .
12215  SDCC will generate code to disable all interrupts
12216 \begin_inset LatexCommand \index{interrupt}
12217
12218 \end_inset 
12219
12220  upon entry to a critical function and restore the interrupt enable to the
12221  previous state before returning.
12222  Nesting critical functions will need one additional byte on the stack
12223 \begin_inset LatexCommand \index{stack}
12224
12225 \end_inset 
12226
12227  for each call.
12228 \layout Verse
12229
12230
12231 \family typewriter 
12232 int foo () __critical
12233 \begin_inset LatexCommand \index{critical}
12234
12235 \end_inset 
12236
12237
12238 \begin_inset LatexCommand \index{\_\_critical}
12239
12240 \end_inset 
12241
12242  
12243 \newline 
12244
12245 \newline 
12246 \SpecialChar ~
12247 \SpecialChar ~
12248 \SpecialChar ~
12249 \SpecialChar ~
12250 ...
12251  
12252 \newline 
12253 \SpecialChar ~
12254 \SpecialChar ~
12255 \SpecialChar ~
12256 \SpecialChar ~
12257 ...
12258  
12259 \newline 
12260 }
12261 \layout Standard
12262
12263 The critical attribute maybe used with other attributes like 
12264 \emph on 
12265 reentrant.
12266 \emph default 
12267
12268 \newline 
12269 The keyword 
12270 \emph on 
12271 critical
12272 \emph default 
12273  may also be used to disable interrupts more locally:
12274 \layout Verse
12275
12276
12277 \family typewriter 
12278 __critical{ i++; }
12279 \layout Standard
12280
12281 More than one statement could have been included in the block.
12282 \layout Subsection
12283
12284 Enabling and Disabling Interrupts directly
12285 \layout Standard
12286
12287 Interrupts
12288 \begin_inset LatexCommand \index{interrupt}
12289
12290 \end_inset 
12291
12292  can also be disabled and enabled directly (8051):
12293 \layout Verse
12294
12295
12296 \family typewriter 
12297 EA = 0;\SpecialChar ~
12298 \SpecialChar ~
12299 \SpecialChar ~
12300 \SpecialChar ~
12301 \SpecialChar ~
12302 \SpecialChar ~
12303 \SpecialChar ~
12304 \SpecialChar ~
12305 \SpecialChar ~
12306 \SpecialChar ~
12307 \SpecialChar ~
12308 \SpecialChar ~
12309 or:\SpecialChar ~
12310 \SpecialChar ~
12311 \SpecialChar ~
12312 \SpecialChar ~
12313 \SpecialChar ~
12314 \SpecialChar ~
12315 \SpecialChar ~
12316 \SpecialChar ~
12317 \SpecialChar ~
12318 \SpecialChar ~
12319 \SpecialChar ~
12320 EA_SAVE = EA;
12321 \layout Verse
12322
12323
12324 \family typewriter 
12325 ...\SpecialChar ~
12326 \SpecialChar ~
12327 \SpecialChar ~
12328 \SpecialChar ~
12329 \SpecialChar ~
12330 \SpecialChar ~
12331 \SpecialChar ~
12332 \SpecialChar ~
12333 \SpecialChar ~
12334 \SpecialChar ~
12335 \SpecialChar ~
12336 \SpecialChar ~
12337 \SpecialChar ~
12338 \SpecialChar ~
12339 \SpecialChar ~
12340 \SpecialChar ~
12341 \SpecialChar ~
12342 \SpecialChar ~
12343 \SpecialChar ~
12344 \SpecialChar ~
12345 \SpecialChar ~
12346 \SpecialChar ~
12347 \SpecialChar ~
12348 \SpecialChar ~
12349 \SpecialChar ~
12350 \SpecialChar ~
12351 \SpecialChar ~
12352 \SpecialChar ~
12353 \SpecialChar ~
12354 \SpecialChar ~
12355 EA = 0;
12356 \layout Verse
12357
12358
12359 \family typewriter 
12360 EA = 1;\SpecialChar ~
12361 \SpecialChar ~
12362 \SpecialChar ~
12363 \SpecialChar ~
12364 \SpecialChar ~
12365 \SpecialChar ~
12366 \SpecialChar ~
12367 \SpecialChar ~
12368 \SpecialChar ~
12369 \SpecialChar ~
12370 \SpecialChar ~
12371 \SpecialChar ~
12372 \SpecialChar ~
12373 \SpecialChar ~
12374 \SpecialChar ~
12375 \SpecialChar ~
12376 \SpecialChar ~
12377 \SpecialChar ~
12378 \SpecialChar ~
12379 \SpecialChar ~
12380 \SpecialChar ~
12381 \SpecialChar ~
12382 \SpecialChar ~
12383 \SpecialChar ~
12384 \SpecialChar ~
12385 \SpecialChar ~
12386 ...
12387 \layout Verse
12388
12389
12390 \family typewriter 
12391 \SpecialChar ~
12392 \SpecialChar ~
12393 \SpecialChar ~
12394 \SpecialChar ~
12395 \SpecialChar ~
12396 \SpecialChar ~
12397 \SpecialChar ~
12398 \SpecialChar ~
12399 \SpecialChar ~
12400 \SpecialChar ~
12401 \SpecialChar ~
12402 \SpecialChar ~
12403 \SpecialChar ~
12404 \SpecialChar ~
12405 \SpecialChar ~
12406 \SpecialChar ~
12407 \SpecialChar ~
12408 \SpecialChar ~
12409 \SpecialChar ~
12410 \SpecialChar ~
12411 \SpecialChar ~
12412 \SpecialChar ~
12413 \SpecialChar ~
12414 \SpecialChar ~
12415 \SpecialChar ~
12416 \SpecialChar ~
12417 \SpecialChar ~
12418 \SpecialChar ~
12419 \SpecialChar ~
12420 \SpecialChar ~
12421 \SpecialChar ~
12422 \SpecialChar ~
12423 \SpecialChar ~
12424 EA = EA_SAVE;
12425 \layout Standard
12426
12427 On other architectures which have seperate opcodes for enabling and disabling
12428  interrupts you might want to make use of defines with inline assembly
12429 \begin_inset LatexCommand \index{Assembler routines}
12430
12431 \end_inset 
12432
12433  (HC08
12434 \begin_inset LatexCommand \index{HC08!interrupt}
12435
12436 \end_inset 
12437
12438 ):
12439 \layout Verse
12440
12441
12442 \family typewriter 
12443 #define CLI _asm
12444 \begin_inset LatexCommand \index{\_asm}
12445
12446 \end_inset 
12447
12448 \SpecialChar ~
12449 \SpecialChar ~
12450 cli\SpecialChar ~
12451 \SpecialChar ~
12452 _endasm
12453 \begin_inset LatexCommand \index{\_endasm}
12454
12455 \end_inset 
12456
12457
12458 \layout Verse
12459
12460
12461 \family typewriter 
12462 #define SEI _asm\SpecialChar ~
12463 \SpecialChar ~
12464 sei\SpecialChar ~
12465 \SpecialChar ~
12466 _endasm; 
12467 \layout Verse
12468
12469
12470 \family typewriter 
12471 ...
12472 \layout Standard
12473
12474 Note: it is sometimes sufficient to disable only a specific interrupt source
12475  like f.e.
12476  a timer or serial interrupt by manipulating an 
12477 \emph on 
12478 interrupt mask
12479 \begin_inset LatexCommand \index{interrupt mask}
12480
12481 \end_inset 
12482
12483
12484 \emph default 
12485  register.
12486  
12487 \layout Standard
12488
12489 Usually the time during which interrupts are disabled should be kept as
12490  short as possible.
12491  This minimizes both 
12492 \emph on 
12493 interrupt latency
12494 \emph default 
12495
12496 \begin_inset LatexCommand \index{interrupt latency}
12497
12498 \end_inset 
12499
12500  (the time between the occurrence of the interrupt and the execution of
12501  the first code in the interrupt routine) and 
12502 \emph on 
12503 interrupt jitter
12504 \emph default 
12505
12506 \begin_inset LatexCommand \index{interrupt jitter}
12507
12508 \end_inset 
12509
12510  (the difference between the shortest and the longest interrupt latency).
12511  These really are something different, f.e.
12512  a serial interrupt has to be served before its buffer overruns so it cares
12513  for the maximum interrupt latency, whereas it does not care about jitter.
12514  On a loudspeaker driven via a digital to analog converter which is fed
12515  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12516  a much smaller jitter will be very audible.
12517 \layout Standard
12518
12519 You can reenable interrupts within an interrupt routine and on some architecture
12520 s you can make use of two (or more) levels of 
12521 \emph on 
12522 interrupt priorities
12523 \emph default 
12524
12525 \begin_inset LatexCommand \index{interrupt priority}
12526
12527 \end_inset 
12528
12529 .
12530  On some architectures which don't support interrupt priorities these can
12531  be implemented by manipulating the interrupt mask and reenabling interrupts
12532  within the interrupt routine.
12533  Check there is sufficient space on the stack
12534 \begin_inset LatexCommand \index{stack}
12535
12536 \end_inset 
12537
12538  and don't add complexity unless you have to.
12539  
12540 \layout Subsection
12541
12542 Semaphore
12543 \begin_inset LatexCommand \index{semaphore}
12544
12545 \end_inset 
12546
12547  locking (mcs51/ds390)
12548 \layout Standard
12549
12550 Some architectures (mcs51/ds390) have an atomic
12551 \begin_inset LatexCommand \index{atomic}
12552
12553 \end_inset 
12554
12555  bit test and
12556 \emph on 
12557  
12558 \emph default 
12559 clear
12560 \emph on 
12561  
12562 \emph default 
12563 instruction.
12564  These type of instructions are typically used in preemptive multitasking
12565  systems, where a routine f.e.
12566  claims the use of a data structure ('acquires a lock
12567 \begin_inset LatexCommand \index{lock}
12568
12569 \end_inset 
12570
12571  on it'), makes some modifications and then releases the lock when the data
12572  structure is consistent again.
12573  The instruction may also be used if interrupt and non-interrupt code have
12574  to compete for a resource.
12575  With the atomic bit test and clear instruction interrupts
12576 \begin_inset LatexCommand \index{interrupt}
12577
12578 \end_inset 
12579
12580  don't have to be disabled for the locking operation.
12581  
12582 \layout Standard
12583
12584 SDCC generates this instruction if the source follows this pattern:
12585 \layout Verse
12586
12587
12588 \family typewriter 
12589 volatile
12590 \begin_inset LatexCommand \index{volatile}
12591
12592 \end_inset 
12593
12594  bit resource_is_free; 
12595 \newline 
12596
12597 \newline 
12598 if (resource_is_free) 
12599 \newline 
12600 \SpecialChar ~
12601 \SpecialChar ~
12602
12603 \newline 
12604 \SpecialChar ~
12605 \SpecialChar ~
12606 \SpecialChar ~
12607 \SpecialChar ~
12608 resource_is_free=0; 
12609 \newline 
12610 \SpecialChar ~
12611 \SpecialChar ~
12612 \SpecialChar ~
12613 \SpecialChar ~
12614 ...
12615  
12616 \newline 
12617 \SpecialChar ~
12618 \SpecialChar ~
12619 \SpecialChar ~
12620 \SpecialChar ~
12621 resource_is_free=1;
12622 \newline 
12623 \SpecialChar ~
12624 \SpecialChar ~
12625
12626 \layout Standard
12627
12628 Note, mcs51 and ds390 support only an atomic
12629 \begin_inset LatexCommand \index{atomic}
12630
12631 \end_inset 
12632
12633  bit test and 
12634 \emph on 
12635 clear
12636 \emph default 
12637  instruction (as opposed to atomic bit test and 
12638 \emph on 
12639 set).
12640 \layout Section
12641
12642 Functions using private register banks
12643 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12644
12645 \end_inset 
12646
12647  (mcs51/ds390)
12648 \layout Standard
12649
12650 Some architectures have support for quickly changing register sets.
12651  SDCC supports this feature with the 
12652 \emph on 
12653 using
12654 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12655
12656 \end_inset 
12657
12658
12659 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12660
12661 \end_inset 
12662
12663
12664 \emph default 
12665  attribute (which tells the compiler to use a register bank
12666 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12667
12668 \end_inset 
12669
12670  other than the default bank zero).
12671  It should only be applied to 
12672 \emph on 
12673 interrupt
12674 \begin_inset LatexCommand \index{interrupt}
12675
12676 \end_inset 
12677
12678
12679 \emph default 
12680  functions (see footnote below).
12681  This will in most circumstances make the generated ISR code more efficient
12682  since it will not have to save registers on the stack.
12683 \layout Standard
12684
12685 The 
12686 \emph on 
12687 using
12688 \emph default 
12689  attribute will have no effect on the generated code for a 
12690 \emph on 
12691 non-interrupt
12692 \emph default 
12693  function (but may occasionally be useful anyway
12694 \begin_inset Foot
12695 collapsed false
12696
12697 \layout Standard
12698
12699 possible exception: if a function is called ONLY from 'interrupt' functions
12700  using a particular bank, it can be declared with the same 'using' attribute
12701  as the calling 'interrupt' functions.
12702  For instance, if you have several ISRs using bank one, and all of them
12703  call memcpy(), it might make sense to create a specialized version of memcpy()
12704  'using 1', since this would prevent the ISR from having to save bank zero
12705  to the stack on entry and switch to bank zero before calling the function
12706 \end_inset 
12707
12708 ).
12709 \newline 
12710
12711 \emph on 
12712 (pending: Note, nowadays the 
12713 \emph default 
12714 using
12715 \emph on 
12716  attribute has an effect on
12717 \emph default 
12718  
12719 \emph on 
12720 the generated code for a 
12721 \emph default 
12722 non-interrupt
12723 \emph on 
12724  function
12725 \emph default 
12726 .
12727 \emph on 
12728 )
12729 \layout Standard
12730
12731 An 
12732 \emph on 
12733 interrupt
12734 \emph default 
12735  function using a non-zero bank will assume that it can trash that register
12736  bank, and will not save it.
12737  Since high-priority interrupts
12738 \begin_inset LatexCommand \index{interrupts}
12739
12740 \end_inset 
12741
12742
12743 \begin_inset LatexCommand \index{interrupt priority}
12744
12745 \end_inset 
12746
12747  can interrupt low-priority ones on the 8051 and friends, this means that
12748  if a high-priority ISR 
12749 \emph on 
12750 using
12751 \emph default 
12752  a particular bank occurs while processing a low-priority ISR 
12753 \emph on 
12754 using
12755 \emph default 
12756  the same bank, terrible and bad things can happen.
12757  To prevent this, no single register bank should be 
12758 \emph on 
12759 used
12760 \emph default 
12761  by both a high priority and a low priority ISR.
12762  This is probably most easily done by having all high priority ISRs use
12763  one bank and all low priority ISRs use another.
12764  If you have an ISR which can change priority at runtime, you're on your
12765  own: I suggest using the default bank zero and taking the small performance
12766  hit.
12767 \layout Standard
12768 \added_space_bottom bigskip 
12769 It is most efficient if your ISR calls no other functions.
12770  If your ISR must call other functions, it is most efficient if those functions
12771  use the same bank as the ISR (see note 1 below); the next best is if the
12772  called functions use bank zero.
12773  It is very inefficient to call a function using a different, non-zero bank
12774  from an ISR.
12775  
12776 \layout Section
12777
12778 Startup Code
12779 \begin_inset LatexCommand \label{sub:Startup-Code}
12780
12781 \end_inset 
12782
12783
12784 \begin_inset LatexCommand \index{Startup code}
12785
12786 \end_inset 
12787
12788
12789 \layout Subsection
12790
12791 MCS51/DS390 Startup Code
12792 \layout Standard
12793
12794 The compiler inserts a call to the C routine 
12795 \emph on 
12796 _sdcc_external_startup()
12797 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12798
12799 \end_inset 
12800
12801
12802 \series bold 
12803 \emph default 
12804  
12805 \series default 
12806 at the start of the CODE area.
12807  This routine is in the runtime library
12808 \begin_inset LatexCommand \index{Runtime library}
12809
12810 \end_inset 
12811
12812 .
12813  By default this routine returns 0, if this routine returns a non-zero value,
12814  the static & global variable initialization will be skipped and the function
12815  main will be invoked.
12816  Otherwise static & global variables will be initialized before the function
12817  main is invoked.
12818  You could add a 
12819 \emph on 
12820 _sdcc_external_startup()
12821 \emph default 
12822  routine to your program to override the default if you need to setup hardware
12823  or perform some other critical operation prior to static & global variable
12824  initialization
12825 \begin_inset LatexCommand \index{Variable initialization}
12826
12827 \end_inset 
12828
12829 .
12830  On some mcs51 variants xdata
12831 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12832
12833 \end_inset 
12834
12835  memory has to be explicitly enabled before it can be accessed or if the
12836  watchdog
12837 \begin_inset LatexCommand \index{watchdog}
12838
12839 \end_inset 
12840
12841  needs to be disabled, this is the place to do it.
12842  The startup code clears all internal data memory, 256 bytes by default,
12843  but from 0 to n-1 if 
12844 \emph on 
12845 -
12846 \begin_inset ERT
12847 status Collapsed
12848
12849 \layout Standard
12850
12851 \backslash 
12852 /
12853 \end_inset 
12854
12855 -iram-size
12856 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12857
12858 \end_inset 
12859
12860 n
12861 \emph default 
12862  is used.
12863  (recommended for Chipcon CC1010).
12864 \layout Standard
12865 \added_space_bottom bigskip 
12866 See also the compiler options 
12867 \emph on 
12868 -
12869 \begin_inset ERT
12870 status Collapsed
12871
12872 \layout Standard
12873
12874 \backslash 
12875 /
12876 \end_inset 
12877
12878 -no-xinit
12879 \emph default 
12880 -
12881 \emph on 
12882 opt
12883 \emph default 
12884
12885 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
12886
12887 \end_inset 
12888
12889
12890 \emph on 
12891 -
12892 \begin_inset ERT
12893 status Collapsed
12894
12895 \layout Standard
12896
12897 \backslash 
12898 /
12899 \end_inset 
12900
12901 -main-return
12902 \emph default 
12903
12904 \begin_inset LatexCommand \index{-\/-main-return}
12905
12906 \end_inset 
12907
12908 and section 
12909 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12910
12911 \end_inset 
12912
12913 \SpecialChar ~
12914 about MCS51-variants.
12915 \layout Subsection
12916
12917 HC08 Startup Code
12918 \layout Standard
12919 \added_space_bottom bigskip 
12920 The HC08
12921 \begin_inset LatexCommand \index{HC08}
12922
12923 \end_inset 
12924
12925  startup code follows the same scheme as the MCS51 startup code.
12926 \layout Subsection
12927
12928 Z80 Startup Code
12929 \layout Standard
12930 \added_space_bottom bigskip 
12931 On the Z80
12932 \begin_inset LatexCommand \index{Z80}
12933
12934 \end_inset 
12935
12936  the startup code is inserted by linking with crt0.o which is generated from
12937  sdcc/device/lib/z80/crt0.s.
12938  If you need a different startup code you can use the compiler option 
12939 \emph on 
12940 -
12941 \series bold 
12942 \emph default 
12943
12944 \begin_inset ERT
12945 status Collapsed
12946
12947 \layout Standard
12948
12949 \backslash 
12950 /
12951 \end_inset 
12952
12953
12954 \series default 
12955 \emph on 
12956 -no-std-crt0
12957 \emph default 
12958
12959 \begin_inset LatexCommand \index{-\/-no-std-crt0}
12960
12961 \end_inset 
12962
12963  and provide your own crt0.o.
12964  
12965 \layout Section
12966
12967 Inline Assembler Code
12968 \begin_inset LatexCommand \index{Assembler routines}
12969
12970 \end_inset 
12971
12972
12973 \layout Subsection
12974
12975 A Step by Step Introduction
12976 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
12977
12978 \end_inset 
12979
12980
12981 \layout Standard
12982
12983 Starting from a small snippet of c-code this example shows for the MCS51
12984  how to use inline assembly, access variables, a function parameter and
12985  an array in xdata memory.
12986  The example uses an MCS51 here but is easily adapted for other architectures.
12987  This is a buffer routine which should be optimized:
12988 \layout Verse
12989
12990
12991 \family typewriter 
12992 \size footnotesize 
12993 unsigned char __far
12994 \begin_inset LatexCommand \index{far (storage class)}
12995
12996 \end_inset 
12997
12998
12999 \begin_inset LatexCommand \index{\_\_far (storage class)}
13000
13001 \end_inset 
13002
13003  __at
13004 \begin_inset LatexCommand \index{at}
13005
13006 \end_inset 
13007
13008
13009 \begin_inset LatexCommand \index{\_\_at}
13010
13011 \end_inset 
13012
13013 (0x7f00) buf[0x100];
13014 \begin_inset LatexCommand \index{Aligned array}
13015
13016 \end_inset 
13017
13018
13019 \newline 
13020 unsigned char head, tail;\SpecialChar ~
13021 \SpecialChar ~
13022 \SpecialChar ~
13023 \SpecialChar ~
13024 \SpecialChar ~
13025 \SpecialChar ~
13026 \SpecialChar ~
13027 \SpecialChar ~
13028 \SpecialChar ~
13029 \SpecialChar ~
13030 \SpecialChar ~
13031 \SpecialChar ~
13032 \SpecialChar ~
13033 \SpecialChar ~
13034 \SpecialChar ~
13035 \SpecialChar ~
13036 \SpecialChar ~
13037 /* if interrupts
13038 \begin_inset LatexCommand \index{interrupt}
13039
13040 \end_inset 
13041
13042  are involved see
13043 \newline 
13044 \SpecialChar ~
13045 \SpecialChar ~
13046 \SpecialChar ~
13047 \SpecialChar ~
13048 \SpecialChar ~
13049 \SpecialChar ~
13050 \SpecialChar ~
13051 \SpecialChar ~
13052 \SpecialChar ~
13053 \SpecialChar ~
13054 \SpecialChar ~
13055 \SpecialChar ~
13056 \SpecialChar ~
13057 \SpecialChar ~
13058 \SpecialChar ~
13059 \SpecialChar ~
13060 \SpecialChar ~
13061 \SpecialChar ~
13062 \SpecialChar ~
13063 \SpecialChar ~
13064 \SpecialChar ~
13065 \SpecialChar ~
13066 \SpecialChar ~
13067 \SpecialChar ~
13068 \SpecialChar ~
13069 \SpecialChar ~
13070 \SpecialChar ~
13071 \SpecialChar ~
13072 \SpecialChar ~
13073 \SpecialChar ~
13074 \SpecialChar ~
13075 \SpecialChar ~
13076 \SpecialChar ~
13077 \SpecialChar ~
13078 \SpecialChar ~
13079 \SpecialChar ~
13080 \SpecialChar ~
13081 \SpecialChar ~
13082 \SpecialChar ~
13083 \SpecialChar ~
13084 \SpecialChar ~
13085 \SpecialChar ~
13086 \SpecialChar ~
13087 \SpecialChar ~
13088 \SpecialChar ~
13089 section 
13090 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13091
13092 \end_inset 
13093
13094  about
13095 \series bold 
13096  volatile
13097 \series default 
13098  */
13099 \newline 
13100
13101 \newline 
13102 void to_buffer( unsigned char c ) 
13103 \newline 
13104 {
13105 \newline 
13106 \SpecialChar ~
13107 \SpecialChar ~
13108 \SpecialChar ~
13109 \SpecialChar ~
13110 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13111 /* cast 
13112 \series bold 
13113 needed
13114 \series default 
13115  to avoid promotion
13116 \begin_inset LatexCommand \index{promotion to signed int}
13117
13118 \end_inset 
13119
13120
13121 \begin_inset LatexCommand \index{type promotion}
13122
13123 \end_inset 
13124
13125  to integer */
13126 \begin_inset Marginal
13127 collapsed true
13128
13129 \layout Standard
13130
13131
13132 \series bold 
13133 \SpecialChar ~
13134 !
13135 \end_inset 
13136
13137
13138 \newline 
13139 \SpecialChar ~
13140 \SpecialChar ~
13141 \SpecialChar ~
13142 \SpecialChar ~
13143 \SpecialChar ~
13144 \SpecialChar ~
13145 \SpecialChar ~
13146 \SpecialChar ~
13147 buf[ head++ ] = c;\SpecialChar ~
13148 \SpecialChar ~
13149 \SpecialChar ~
13150 \SpecialChar ~
13151 \SpecialChar ~
13152 \SpecialChar ~
13153 \SpecialChar ~
13154 \SpecialChar ~
13155 \SpecialChar ~
13156 \SpecialChar ~
13157 \SpecialChar ~
13158 \SpecialChar ~
13159 \SpecialChar ~
13160 \SpecialChar ~
13161 \SpecialChar ~
13162 \SpecialChar ~
13163 /* access to a 256 byte aligned array */
13164 \newline 
13165
13166 \layout Standard
13167
13168 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13169  then a corresponding buffer.asm file is generated.
13170  We define a new function 
13171 \family typewriter 
13172 to_buffer_asm()
13173 \family default 
13174  in file buffer.c in which we cut and paste the generated code, removing
13175  unwanted comments and some ':'.
13176  Then add 
13177 \begin_inset Quotes sld
13178 \end_inset 
13179
13180 _asm
13181 \begin_inset Quotes srd
13182 \end_inset 
13183
13184  and 
13185 \begin_inset Quotes sld
13186 \end_inset 
13187
13188 _endasm;
13189 \begin_inset Quotes srd
13190 \end_inset 
13191
13192  to the beginning and the end of the function body:
13193 \layout Verse
13194
13195
13196 \family typewriter 
13197 \size footnotesize 
13198 /* With a cut and paste from the .asm file, we have something to start with.
13199 \newline 
13200 \SpecialChar ~
13201 \SpecialChar ~
13202 \SpecialChar ~
13203 The function is not yet OK! (registers aren't saved) */ 
13204 \newline 
13205 void to_buffer_asm( unsigned char c ) 
13206 \newline 
13207
13208 \newline 
13209 \SpecialChar ~
13210 \SpecialChar ~
13211 \SpecialChar ~
13212 \SpecialChar ~
13213 _asm
13214 \begin_inset LatexCommand \index{\_asm}
13215
13216 \end_inset 
13217
13218
13219 \begin_inset LatexCommand \index{\_\_asm}
13220
13221 \end_inset 
13222
13223
13224 \newline 
13225 \SpecialChar ~
13226 \SpecialChar ~
13227 \SpecialChar ~
13228 \SpecialChar ~
13229 mov\SpecialChar ~
13230 \SpecialChar ~
13231 r2,dpl 
13232 \newline 
13233 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13234 /* cast 
13235 \series bold 
13236 needed
13237 \series default 
13238  to avoid promotion
13239 \begin_inset LatexCommand \index{promotion to signed int}
13240
13241 \end_inset 
13242
13243
13244 \begin_inset LatexCommand \index{type promotion}
13245
13246 \end_inset 
13247
13248  to integer */
13249 \newline 
13250 \SpecialChar ~
13251 \SpecialChar ~
13252 \SpecialChar ~
13253 \SpecialChar ~
13254 mov\SpecialChar ~
13255 \SpecialChar ~
13256 a,_tail 
13257 \newline 
13258 \SpecialChar ~
13259 \SpecialChar ~
13260 \SpecialChar ~
13261 \SpecialChar ~
13262 dec\SpecialChar ~
13263 \SpecialChar ~
13264
13265 \newline 
13266 \SpecialChar ~
13267 \SpecialChar ~
13268 \SpecialChar ~
13269 \SpecialChar ~
13270 mov\SpecialChar ~
13271 \SpecialChar ~
13272 r3,a 
13273 \newline 
13274 \SpecialChar ~
13275 \SpecialChar ~
13276 \SpecialChar ~
13277 \SpecialChar ~
13278 mov\SpecialChar ~
13279 \SpecialChar ~
13280 a,_head 
13281 \newline 
13282 \SpecialChar ~
13283 \SpecialChar ~
13284 \SpecialChar ~
13285 \SpecialChar ~
13286 cjne a,ar3,00106$ 
13287 \newline 
13288 \SpecialChar ~
13289 \SpecialChar ~
13290 \SpecialChar ~
13291 \SpecialChar ~
13292 ret
13293 \newline 
13294 00106$: 
13295 \newline 
13296 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13297 \begin_inset LatexCommand \index{Aligned array}
13298
13299 \end_inset 
13300
13301
13302 \newline 
13303 \SpecialChar ~
13304 \SpecialChar ~
13305 \SpecialChar ~
13306 \SpecialChar ~
13307 mov\SpecialChar ~
13308 \SpecialChar ~
13309 r3,_head 
13310 \newline 
13311 \SpecialChar ~
13312 \SpecialChar ~
13313 \SpecialChar ~
13314 \SpecialChar ~
13315 inc\SpecialChar ~
13316 \SpecialChar ~
13317 _head 
13318 \newline 
13319 \SpecialChar ~
13320 \SpecialChar ~
13321 \SpecialChar ~
13322 \SpecialChar ~
13323 mov\SpecialChar ~
13324 \SpecialChar ~
13325 dpl,r3 
13326 \newline 
13327 \SpecialChar ~
13328 \SpecialChar ~
13329 \SpecialChar ~
13330 \SpecialChar ~
13331 mov\SpecialChar ~
13332 \SpecialChar ~
13333 dph,#(_buf >> 8) 
13334 \newline 
13335 \SpecialChar ~
13336 \SpecialChar ~
13337 \SpecialChar ~
13338 \SpecialChar ~
13339 mov\SpecialChar ~
13340 \SpecialChar ~
13341 a,r2 
13342 \newline 
13343 \SpecialChar ~
13344 \SpecialChar ~
13345 \SpecialChar ~
13346 \SpecialChar ~
13347 movx @dptr,a 
13348 \newline 
13349 00103$: 
13350 \newline 
13351 \SpecialChar ~
13352 \SpecialChar ~
13353 \SpecialChar ~
13354 \SpecialChar ~
13355 ret
13356 \newline 
13357 \SpecialChar ~
13358 \SpecialChar ~
13359 \SpecialChar ~
13360 \SpecialChar ~
13361 _endasm
13362 \begin_inset LatexCommand \index{\_endasm}
13363
13364 \end_inset 
13365
13366
13367 \begin_inset LatexCommand \index{\_\_endasm}
13368
13369 \end_inset 
13370
13371 ;
13372 \newline 
13373
13374 \layout Standard
13375
13376 The new file buffer.c should compile with only one warning about the unreferenced
13377  function argument 'c'.
13378  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13379  (1) and finally have:
13380 \layout Verse
13381
13382
13383 \family typewriter 
13384 \size footnotesize 
13385 unsigned char __far __at(0x7f00) buf[0x100];
13386 \newline 
13387 unsigned char head, tail;
13388 \newline 
13389 #define USE_ASSEMBLY (1)
13390 \newline 
13391
13392 \newline 
13393 #if !USE_ASSEMBLY
13394 \newline 
13395
13396 \newline 
13397 void to_buffer( unsigned char c )
13398 \newline 
13399 {
13400 \newline 
13401 \SpecialChar ~
13402 \SpecialChar ~
13403 \SpecialChar ~
13404 \SpecialChar ~
13405 if( head != (unsigned char)(tail-1) )
13406 \newline 
13407 \SpecialChar ~
13408 \SpecialChar ~
13409 \SpecialChar ~
13410 \SpecialChar ~
13411 \SpecialChar ~
13412 \SpecialChar ~
13413 \SpecialChar ~
13414 \SpecialChar ~
13415 buf[ head++ ] = c;
13416 \newline 
13417 }
13418 \newline 
13419
13420 \newline 
13421 #else
13422 \newline 
13423
13424 \newline 
13425 void to_buffer( unsigned char c )
13426 \newline 
13427 {
13428 \newline 
13429 \SpecialChar ~
13430 \SpecialChar ~
13431 \SpecialChar ~
13432 \SpecialChar ~
13433 c; // to avoid warning: unreferenced function argument
13434 \newline 
13435 \SpecialChar ~
13436 \SpecialChar ~
13437 \SpecialChar ~
13438 \SpecialChar ~
13439 _asm
13440 \begin_inset LatexCommand \index{\_asm}
13441
13442 \end_inset 
13443
13444
13445 \begin_inset LatexCommand \index{\_\_asm}
13446
13447 \end_inset 
13448
13449
13450 \newline 
13451 \SpecialChar ~
13452 \SpecialChar ~
13453 \SpecialChar ~
13454 \SpecialChar ~
13455 \SpecialChar ~
13456 \SpecialChar ~
13457 \SpecialChar ~
13458 \SpecialChar ~
13459 ; save used registers here.
13460  
13461 \newline 
13462 \SpecialChar ~
13463 \SpecialChar ~
13464 \SpecialChar ~
13465 \SpecialChar ~
13466 \SpecialChar ~
13467 \SpecialChar ~
13468 \SpecialChar ~
13469 \SpecialChar ~
13470 ; If we were still using r2,r3 we would have to push them here.
13471  
13472 \newline 
13473 ; if( head != (unsigned char)(tail-1) )
13474 \newline 
13475 \SpecialChar ~
13476 \SpecialChar ~
13477 \SpecialChar ~
13478 \SpecialChar ~
13479 \SpecialChar ~
13480 \SpecialChar ~
13481 \SpecialChar ~
13482 \SpecialChar ~
13483 mov\SpecialChar ~
13484  a,_tail
13485 \newline 
13486 \SpecialChar ~
13487 \SpecialChar ~
13488 \SpecialChar ~
13489 \SpecialChar ~
13490 \SpecialChar ~
13491 \SpecialChar ~
13492 \SpecialChar ~
13493 \SpecialChar ~
13494 dec\SpecialChar ~
13495  a
13496 \newline 
13497 \SpecialChar ~
13498 \SpecialChar ~
13499 \SpecialChar ~
13500 \SpecialChar ~
13501 \SpecialChar ~
13502 \SpecialChar ~
13503 \SpecialChar ~
13504 \SpecialChar ~
13505 xrl\SpecialChar ~
13506  a,_head
13507 \newline 
13508 \SpecialChar ~
13509 \SpecialChar ~
13510 \SpecialChar ~
13511 \SpecialChar ~
13512 \SpecialChar ~
13513 \SpecialChar ~
13514 \SpecialChar ~
13515 \SpecialChar ~
13516 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13517 \newline 
13518 \SpecialChar ~
13519 \SpecialChar ~
13520 \SpecialChar ~
13521 \SpecialChar ~
13522 \SpecialChar ~
13523 \SpecialChar ~
13524 \SpecialChar ~
13525 \SpecialChar ~
13526 jz\SpecialChar ~
13527 \SpecialChar ~
13528  t_b_end$
13529 \newline 
13530 \SpecialChar ~
13531 \SpecialChar ~
13532 \SpecialChar ~
13533 \SpecialChar ~
13534 \SpecialChar ~
13535 \SpecialChar ~
13536 \SpecialChar ~
13537 \SpecialChar ~
13538 ;
13539 \newline 
13540 ; buf[ head++ ] = c;
13541 \newline 
13542 \SpecialChar ~
13543 \SpecialChar ~
13544 \SpecialChar ~
13545 \SpecialChar ~
13546 \SpecialChar ~
13547 \SpecialChar ~
13548 \SpecialChar ~
13549 \SpecialChar ~
13550 mov\SpecialChar ~
13551  a,dpl \SpecialChar ~
13552 \SpecialChar ~
13553 \SpecialChar ~
13554 \SpecialChar ~
13555 \SpecialChar ~
13556 \SpecialChar ~
13557 \SpecialChar ~
13558 ; dpl holds lower byte of function argument
13559 \newline 
13560 \SpecialChar ~
13561 \SpecialChar ~
13562 \SpecialChar ~
13563 \SpecialChar ~
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 \SpecialChar ~
13567 \SpecialChar ~
13568 mov\SpecialChar ~
13569  dpl,_head \SpecialChar ~
13570 \SpecialChar ~
13571 \SpecialChar ~
13572 ; buf is 0x100 byte aligned so head can be used directly
13573 \newline 
13574 \SpecialChar ~
13575 \SpecialChar ~
13576 \SpecialChar ~
13577 \SpecialChar ~
13578 \SpecialChar ~
13579 \SpecialChar ~
13580 \SpecialChar ~
13581 \SpecialChar ~
13582 mov\SpecialChar ~
13583  dph,#(_buf>>8)
13584 \newline 
13585 \SpecialChar ~
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 \SpecialChar ~
13589 \SpecialChar ~
13590 \SpecialChar ~
13591 \SpecialChar ~
13592 \SpecialChar ~
13593 movx @dptr,a
13594 \newline 
13595 \SpecialChar ~
13596 \SpecialChar ~
13597 \SpecialChar ~
13598 \SpecialChar ~
13599 \SpecialChar ~
13600 \SpecialChar ~
13601 \SpecialChar ~
13602 \SpecialChar ~
13603 inc \SpecialChar ~
13604 _head
13605 \newline 
13606 \SpecialChar ~
13607 \SpecialChar ~
13608 \SpecialChar ~
13609 \SpecialChar ~
13610 \SpecialChar ~
13611 \SpecialChar ~
13612 \SpecialChar ~
13613 \SpecialChar ~
13614 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13615 \newline 
13616 t_b_end$:
13617 \newline 
13618 \SpecialChar ~
13619 \SpecialChar ~
13620 \SpecialChar ~
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 \SpecialChar ~
13625 \SpecialChar ~
13626 ; restore used registers here 
13627 \newline 
13628 \SpecialChar ~
13629 \SpecialChar ~
13630 \SpecialChar ~
13631 \SpecialChar ~
13632 _endasm
13633 \begin_inset LatexCommand \index{\_endasm}
13634
13635 \end_inset 
13636
13637
13638 \begin_inset LatexCommand \index{\_\_endasm}
13639
13640 \end_inset 
13641
13642 ;
13643 \newline 
13644 }
13645 \newline 
13646 #endif
13647 \layout Standard
13648
13649 The inline assembler code can contain any valid code understood by the assembler
13650 , this includes any assembler directives and comment lines.
13651  The assembler does not like some characters like ':' or ''' in comments.
13652  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13653 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13654
13655 \end_inset 
13656
13657
13658 \begin_inset LatexCommand \index{Assembler documentation}
13659
13660 \end_inset 
13661
13662  or online at 
13663 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13664
13665 \end_inset 
13666
13667 \SpecialChar ~
13668 .
13669 \layout Standard
13670
13671 The compiler does not do any validation of the code within the 
13672 \family typewriter 
13673 _asm
13674 \begin_inset LatexCommand \index{\_asm}
13675
13676 \end_inset 
13677
13678
13679 \begin_inset LatexCommand \index{\_\_asm}
13680
13681 \end_inset 
13682
13683  ...
13684  _endasm
13685 \size footnotesize 
13686
13687 \begin_inset LatexCommand \index{\_endasm}
13688
13689 \end_inset 
13690
13691
13692 \begin_inset LatexCommand \index{\_\_endasm}
13693
13694 \end_inset 
13695
13696
13697 \size default 
13698 ;
13699 \family default 
13700  keyword pair.
13701  Specifically it will not know which registers are used and thus register
13702  pushing/popping
13703 \begin_inset LatexCommand \index{push/pop}
13704
13705 \end_inset 
13706
13707  has to be done manually.
13708  
13709 \layout Standard
13710
13711 It is recommended that each assembly instruction (including labels) be placed
13712  in a separate line (as the example shows).
13713  When the -
13714 \begin_inset ERT
13715 status Collapsed
13716
13717 \layout Standard
13718
13719 \backslash 
13720 /
13721 \end_inset 
13722
13723 -
13724 \emph on 
13725 peep-asm
13726 \begin_inset LatexCommand \index{-\/-peep-asm}
13727
13728 \end_inset 
13729
13730
13731 \emph default 
13732  command line option is used, the inline assembler code will be passed through
13733  the peephole optimizer
13734 \begin_inset LatexCommand \index{Peephole optimizer}
13735
13736 \end_inset 
13737
13738 .
13739  There are only a few (if any) cases where this option makes sense, it might
13740  cause some unexpected changes in the inline assembler code.
13741  Please go through the peephole optimizer rules defined in file 
13742 \emph on 
13743 SDCCpeeph.def
13744 \emph default 
13745  before using this option.
13746 \layout Subsection
13747
13748 Naked Functions
13749 \begin_inset LatexCommand \label{sub:Naked-Functions}
13750
13751 \end_inset 
13752
13753
13754 \begin_inset LatexCommand \index{Naked functions}
13755
13756 \end_inset 
13757
13758
13759 \layout Standard
13760
13761 A special keyword may be associated with a function declaring it as 
13762 \emph on 
13763 _naked
13764 \begin_inset LatexCommand \index{\_naked}
13765
13766 \end_inset 
13767
13768
13769 \begin_inset LatexCommand \index{\_\_naked}
13770
13771 \end_inset 
13772
13773 .
13774  
13775 \emph default 
13776 The 
13777 \emph on 
13778 _naked
13779 \emph default 
13780  function modifier attribute prevents the compiler from generating prologue
13781 \begin_inset LatexCommand \index{function prologue}
13782
13783 \end_inset 
13784
13785  and epilogue
13786 \begin_inset LatexCommand \index{function epilogue}
13787
13788 \end_inset 
13789
13790  code for that function.
13791  This means that the user is entirely responsible for such things as saving
13792  any registers that may need to be preserved, selecting the proper register
13793  bank, generating the 
13794 \emph on 
13795 return
13796 \emph default 
13797  instruction at the end, etc.
13798  Practically, this means that the contents of the function must be written
13799  in inline assembler.
13800  This is particularly useful for interrupt functions, which can have a large
13801  (and often unnecessary) prologue/epilogue.
13802  For example, compare the code generated by these two functions:
13803 \layout Verse
13804
13805
13806 \family typewriter 
13807 volatile
13808 \begin_inset LatexCommand \index{volatile}
13809
13810 \end_inset 
13811
13812  data unsigned char counter;
13813 \newline 
13814
13815 \newline 
13816 void simpleInterrupt(void) __interrupt
13817 \begin_inset LatexCommand \index{interrupt}
13818
13819 \end_inset 
13820
13821
13822 \begin_inset LatexCommand \index{\_\_interrupt}
13823
13824 \end_inset 
13825
13826  (1)
13827 \newline 
13828 {
13829 \newline 
13830 \SpecialChar ~
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 counter++;
13835 \newline 
13836 }
13837 \newline 
13838
13839 \newline 
13840 void nakedInterrupt(void) __interrupt (2) __naked
13841 \newline 
13842 {
13843 \newline 
13844 \SpecialChar ~
13845 \SpecialChar ~
13846 \SpecialChar ~
13847 \SpecialChar ~
13848 _asm
13849 \begin_inset LatexCommand \index{\_asm}
13850
13851 \end_inset 
13852
13853
13854 \begin_inset LatexCommand \index{\_\_asm}
13855
13856 \end_inset 
13857
13858
13859 \newline 
13860 \SpecialChar ~
13861 \SpecialChar ~
13862 \SpecialChar ~
13863 \SpecialChar ~
13864 \SpecialChar ~
13865 \SpecialChar ~
13866 inc\SpecialChar ~
13867 \SpecialChar ~
13868 \SpecialChar ~
13869 \SpecialChar ~
13870 \SpecialChar ~
13871 _counter ; does not change flags, no need to save psw
13872 \newline 
13873 \SpecialChar ~
13874 \SpecialChar ~
13875 \SpecialChar ~
13876 \SpecialChar ~
13877 \SpecialChar ~
13878 \SpecialChar ~
13879 reti\SpecialChar ~
13880 \SpecialChar ~
13881 \SpecialChar ~
13882 \SpecialChar ~
13883 ; MUST explicitly include ret or reti in _naked function.
13884 \newline 
13885 \SpecialChar ~
13886 \SpecialChar ~
13887 \SpecialChar ~
13888 \SpecialChar ~
13889 _endasm
13890 \begin_inset LatexCommand \index{\_endasm}
13891
13892 \end_inset 
13893
13894
13895 \begin_inset LatexCommand \index{\_\_endasm}
13896
13897 \end_inset 
13898
13899 ;
13900 \newline 
13901 }
13902 \layout Standard
13903
13904 For an 8051 target, the generated simpleInterrupt looks like:
13905 \layout Verse
13906
13907
13908 \family typewriter 
13909 Note, this is an 
13910 \emph on 
13911 outdated
13912 \emph default 
13913  example, recent versions of SDCC generate
13914 \newline 
13915 the 
13916 \emph on 
13917 same
13918 \emph default 
13919  code for simpleInterrupt() and nakedInterrupt()!
13920 \newline 
13921
13922 \newline 
13923 _simpleInterrupt:
13924 \newline 
13925 \SpecialChar ~
13926 \SpecialChar ~
13927 \SpecialChar ~
13928 \SpecialChar ~
13929 push\SpecialChar ~
13930 \SpecialChar ~
13931 \SpecialChar ~
13932 \SpecialChar ~
13933 acc
13934 \newline 
13935 \SpecialChar ~
13936 \SpecialChar ~
13937 \SpecialChar ~
13938 \SpecialChar ~
13939 push\SpecialChar ~
13940 \SpecialChar ~
13941 \SpecialChar ~
13942 \SpecialChar ~
13943 b
13944 \newline 
13945 \SpecialChar ~
13946 \SpecialChar ~
13947 \SpecialChar ~
13948 \SpecialChar ~
13949 push\SpecialChar ~
13950 \SpecialChar ~
13951 \SpecialChar ~
13952 \SpecialChar ~
13953 dpl
13954 \newline 
13955 \SpecialChar ~
13956 \SpecialChar ~
13957 \SpecialChar ~
13958 \SpecialChar ~
13959 push\SpecialChar ~
13960 \SpecialChar ~
13961 \SpecialChar ~
13962 \SpecialChar ~
13963 dph
13964 \newline 
13965 \SpecialChar ~
13966 \SpecialChar ~
13967 \SpecialChar ~
13968 \SpecialChar ~
13969 push\SpecialChar ~
13970 \SpecialChar ~
13971 \SpecialChar ~
13972 \SpecialChar ~
13973 psw
13974 \newline 
13975 \SpecialChar ~
13976 \SpecialChar ~
13977 \SpecialChar ~
13978 \SpecialChar ~
13979 mov\SpecialChar ~
13980 \SpecialChar ~
13981 \SpecialChar ~
13982 \SpecialChar ~
13983 \SpecialChar ~
13984 psw,#0x00
13985 \newline 
13986 \SpecialChar ~
13987 \SpecialChar ~
13988 \SpecialChar ~
13989 \SpecialChar ~
13990 inc\SpecialChar ~
13991 \SpecialChar ~
13992 \SpecialChar ~
13993 \SpecialChar ~
13994 \SpecialChar ~
13995 _counter
13996 \newline 
13997 \SpecialChar ~
13998 \SpecialChar ~
13999 \SpecialChar ~
14000 \SpecialChar ~
14001 pop\SpecialChar ~
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 \SpecialChar ~
14005 \SpecialChar ~
14006 psw
14007 \newline 
14008 \SpecialChar ~
14009 \SpecialChar ~
14010 \SpecialChar ~
14011 \SpecialChar ~
14012 pop\SpecialChar ~
14013 \SpecialChar ~
14014 \SpecialChar ~
14015 \SpecialChar ~
14016 \SpecialChar ~
14017 dph
14018 \newline 
14019 \SpecialChar ~
14020 \SpecialChar ~
14021 \SpecialChar ~
14022 \SpecialChar ~
14023 pop\SpecialChar ~
14024 \SpecialChar ~
14025 \SpecialChar ~
14026 \SpecialChar ~
14027 \SpecialChar ~
14028 dpl
14029 \newline 
14030 \SpecialChar ~
14031 \SpecialChar ~
14032 \SpecialChar ~
14033 \SpecialChar ~
14034 pop\SpecialChar ~
14035 \SpecialChar ~
14036 \SpecialChar ~
14037 \SpecialChar ~
14038 \SpecialChar ~
14039 b
14040 \newline 
14041 \SpecialChar ~
14042 \SpecialChar ~
14043 \SpecialChar ~
14044 \SpecialChar ~
14045 pop\SpecialChar ~
14046 \SpecialChar ~
14047 \SpecialChar ~
14048 \SpecialChar ~
14049 \SpecialChar ~
14050 acc
14051 \newline 
14052 \SpecialChar ~
14053 \SpecialChar ~
14054 \SpecialChar ~
14055 \SpecialChar ~
14056 reti
14057 \layout Standard
14058
14059 whereas nakedInterrupt looks like:
14060 \layout Verse
14061
14062
14063 \family typewriter 
14064 _nakedInterrupt:
14065 \newline 
14066 \SpecialChar ~
14067 \SpecialChar ~
14068 \SpecialChar ~
14069 \SpecialChar ~
14070 inc\SpecialChar ~
14071 \SpecialChar ~
14072 \SpecialChar ~
14073 \SpecialChar ~
14074 _counter ; does not change flags, no need to save psw
14075 \newline 
14076 \SpecialChar ~
14077 \SpecialChar ~
14078 \SpecialChar ~
14079 \SpecialChar ~
14080 reti\SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 \SpecialChar ~
14084 \SpecialChar ~
14085 \SpecialChar ~
14086 \SpecialChar ~
14087 \SpecialChar ~
14088 \SpecialChar ~
14089 \SpecialChar ~
14090 \SpecialChar ~
14091 \SpecialChar ~
14092 ; MUST explicitly include ret or reti in _naked function
14093 \layout Standard
14094
14095 The related directive #pragma exclude
14096 \begin_inset LatexCommand \index{\#pragma exclude}
14097
14098 \end_inset 
14099
14100  allows a more fine grained control over pushing & popping
14101 \begin_inset LatexCommand \index{push/pop}
14102
14103 \end_inset 
14104
14105  the registers.
14106 \layout Standard
14107
14108 While there is nothing preventing you from writing C code inside a 
14109 \family typewriter 
14110 _naked
14111 \family default 
14112  function, there are many ways to shoot yourself in the foot doing this,
14113  and it is recommended that you stick to inline assembler.
14114 \layout Subsection
14115
14116 Use of Labels within Inline Assembler
14117 \layout Standard
14118
14119 SDCC allows the use of in-line assembler with a few restrictions regarding
14120  labels.
14121  In older versions of the compiler all labels defined within inline assembler
14122  code 
14123 \emph on 
14124 had to be
14125 \emph default 
14126  of the form 
14127 \emph on 
14128 nnnnn$
14129 \emph default 
14130  where nnnn is a number less than 100 (which implies a limit of utmost 100
14131  inline assembler labels 
14132 \emph on 
14133 per function
14134 \emph default 
14135 \noun on 
14136 )
14137 \noun default 
14138 .
14139  
14140 \layout Verse
14141
14142
14143 \family typewriter 
14144 _asm
14145 \begin_inset LatexCommand \index{\_asm}
14146
14147 \end_inset 
14148
14149
14150 \begin_inset LatexCommand \index{\_\_asm}
14151
14152 \end_inset 
14153
14154  
14155 \newline 
14156 \SpecialChar ~
14157 \SpecialChar ~
14158 \SpecialChar ~
14159 \SpecialChar ~
14160 mov\SpecialChar ~
14161 \SpecialChar ~
14162 \SpecialChar ~
14163 \SpecialChar ~
14164 \SpecialChar ~
14165 b,#10 
14166 \newline 
14167 00001$: 
14168 \newline 
14169 \SpecialChar ~
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 djnz\SpecialChar ~
14174 \SpecialChar ~
14175 \SpecialChar ~
14176 \SpecialChar ~
14177 b,00001$ 
14178 \newline 
14179 _endasm
14180 \begin_inset LatexCommand \index{\_endasm}
14181
14182 \end_inset 
14183
14184
14185 \begin_inset LatexCommand \index{\_\_endasm}
14186
14187 \end_inset 
14188
14189  ;
14190 \layout Standard
14191
14192 Inline assembler code cannot reference any C-Labels, however it can reference
14193  labels
14194 \begin_inset LatexCommand \index{Labels}
14195
14196 \end_inset 
14197
14198  defined by the inline assembler, e.g.:
14199 \layout Verse
14200
14201
14202 \family typewriter 
14203 foo() { 
14204 \newline 
14205 \SpecialChar ~
14206 \SpecialChar ~
14207 \SpecialChar ~
14208 \SpecialChar ~
14209 /* some c code */ 
14210 \newline 
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 \SpecialChar ~
14214 \SpecialChar ~
14215 _asm 
14216 \newline 
14217 \SpecialChar ~
14218 \SpecialChar ~
14219 \SpecialChar ~
14220 \SpecialChar ~
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 ; some assembler code 
14224 \newline 
14225 \SpecialChar ~
14226 \SpecialChar ~
14227 \SpecialChar ~
14228 \SpecialChar ~
14229 \SpecialChar ~
14230 \SpecialChar ~
14231 ljmp $0003 
14232 \newline 
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 \SpecialChar ~
14236 \SpecialChar ~
14237 _endasm; 
14238 \newline 
14239 \SpecialChar ~
14240 \SpecialChar ~
14241 \SpecialChar ~
14242 \SpecialChar ~
14243 /* some more c code */ 
14244 \newline 
14245 clabel:\SpecialChar ~
14246 \SpecialChar ~
14247 /* inline assembler cannot reference this label */ 
14248 \newline 
14249 \SpecialChar ~
14250 \SpecialChar ~
14251 \SpecialChar ~
14252 \SpecialChar ~
14253 _asm
14254 \newline 
14255 \SpecialChar ~
14256 \SpecialChar ~
14257 \SpecialChar ~
14258 \SpecialChar ~
14259 $0003: ;label (can be referenced by inline assembler only) 
14260 \newline 
14261 \SpecialChar ~
14262 \SpecialChar ~
14263 \SpecialChar ~
14264 \SpecialChar ~
14265 _endasm
14266 \begin_inset LatexCommand \index{\_endasm}
14267
14268 \end_inset 
14269
14270
14271 \begin_inset LatexCommand \index{\_\_endasm}
14272
14273 \end_inset 
14274
14275  ; 
14276 \newline 
14277 \SpecialChar ~
14278 \SpecialChar ~
14279 \SpecialChar ~
14280 \SpecialChar ~
14281 /* some more c code */
14282 \newline 
14283 }
14284 \layout Standard
14285
14286 In other words inline assembly code can access labels defined in inline
14287  assembly within the scope of the function.
14288  The same goes the other way, i.e.
14289  labels defines in inline assembly can not be accessed by C statements.
14290 \layout Section
14291
14292 Interfacing with Assembler Code
14293 \begin_inset LatexCommand \index{Assembler routines}
14294
14295 \end_inset 
14296
14297
14298 \layout Subsection
14299
14300 Global Registers used for Parameter Passing
14301 \begin_inset LatexCommand \index{Parameter passing}
14302
14303 \end_inset 
14304
14305
14306 \layout Standard
14307
14308 The compiler always uses the global registers 
14309 \emph on 
14310 DPL, DPH
14311 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14312
14313 \end_inset 
14314
14315
14316 \begin_inset LatexCommand \index{DPTR}
14317
14318 \end_inset 
14319
14320 , B
14321 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14322
14323 \end_inset 
14324
14325  
14326 \emph default 
14327 and
14328 \emph on 
14329  ACC
14330 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14331
14332 \end_inset 
14333
14334
14335 \emph default 
14336  to pass the first parameter to a routine.
14337  The second parameter onwards is either allocated on the stack (for reentrant
14338  routines or if -
14339 \begin_inset ERT
14340 status Collapsed
14341
14342 \layout Standard
14343
14344 \backslash 
14345 /
14346 \end_inset 
14347
14348 -stack-auto is used) or in data / xdata memory (depending on the memory
14349  model).
14350  
14351 \layout Subsection
14352
14353 Assembler Routine (non-reentrant)
14354 \layout Standard
14355
14356 In the following example
14357 \begin_inset LatexCommand \index{reentrant}
14358
14359 \end_inset 
14360
14361
14362 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14363
14364 \end_inset 
14365
14366  the function c_func calls an assembler routine asm_func, which takes two
14367  parameters
14368 \begin_inset LatexCommand \index{function parameter}
14369
14370 \end_inset 
14371
14372 .
14373 \layout Verse
14374
14375
14376 \family typewriter 
14377 extern int asm_func(unsigned char, unsigned char);
14378 \newline 
14379
14380 \newline 
14381 int c_func (unsigned char i, unsigned char j)
14382 \newline 
14383 {
14384 \newline 
14385 \SpecialChar ~
14386 \SpecialChar ~
14387 \SpecialChar ~
14388 \SpecialChar ~
14389 return asm_func(i,j);
14390 \newline 
14391 }
14392 \newline 
14393
14394 \newline 
14395 int main()
14396 \newline 
14397 {
14398 \newline 
14399 \SpecialChar ~
14400 \SpecialChar ~
14401 \SpecialChar ~
14402 \SpecialChar ~
14403 return c_func(10,9);
14404 \newline 
14405 }
14406 \layout Standard
14407
14408 The corresponding assembler function is:
14409 \layout Verse
14410
14411
14412 \family typewriter 
14413 .globl _asm_func_PARM_2 
14414 \newline 
14415 \SpecialChar ~
14416 \SpecialChar ~
14417 \SpecialChar ~
14418 \SpecialChar ~
14419 \SpecialChar ~
14420 \SpecialChar ~
14421 \SpecialChar ~
14422 \SpecialChar ~
14423 .globl _asm_func 
14424 \newline 
14425 \SpecialChar ~
14426 \SpecialChar ~
14427 \SpecialChar ~
14428 \SpecialChar ~
14429 \SpecialChar ~
14430 \SpecialChar ~
14431 \SpecialChar ~
14432 \SpecialChar ~
14433 .area OSEG 
14434 \newline 
14435 _asm_func_PARM_2:
14436 \newline 
14437 \SpecialChar ~
14438 \SpecialChar ~
14439 \SpecialChar ~
14440 \SpecialChar ~
14441 \SpecialChar ~
14442 \SpecialChar ~
14443 \SpecialChar ~
14444 \SpecialChar ~
14445 .ds    1 
14446 \newline 
14447 \SpecialChar ~
14448 \SpecialChar ~
14449 \SpecialChar ~
14450 \SpecialChar ~
14451 \SpecialChar ~
14452 \SpecialChar ~
14453 \SpecialChar ~
14454 \SpecialChar ~
14455 .area CSEG 
14456 \newline 
14457 _asm_func: 
14458 \newline 
14459 \SpecialChar ~
14460 \SpecialChar ~
14461 \SpecialChar ~
14462 \SpecialChar ~
14463 \SpecialChar ~
14464 \SpecialChar ~
14465 \SpecialChar ~
14466 \SpecialChar ~
14467 mov\SpecialChar ~
14468 \SpecialChar ~
14469 \SpecialChar ~
14470 \SpecialChar ~
14471 a,dpl 
14472 \newline 
14473 \SpecialChar ~
14474 \SpecialChar ~
14475 \SpecialChar ~
14476 \SpecialChar ~
14477 \SpecialChar ~
14478 \SpecialChar ~
14479 \SpecialChar ~
14480 \SpecialChar ~
14481 add\SpecialChar ~
14482 \SpecialChar ~
14483 \SpecialChar ~
14484 \SpecialChar ~
14485 a,_asm_func_PARM_2 
14486 \newline 
14487 \SpecialChar ~
14488 \SpecialChar ~
14489 \SpecialChar ~
14490 \SpecialChar ~
14491 \SpecialChar ~
14492 \SpecialChar ~
14493 \SpecialChar ~
14494 \SpecialChar ~
14495 mov\SpecialChar ~
14496 \SpecialChar ~
14497 \SpecialChar ~
14498 \SpecialChar ~
14499 dpl,a 
14500 \newline 
14501 \SpecialChar ~
14502 \SpecialChar ~
14503 \SpecialChar ~
14504 \SpecialChar ~
14505 \SpecialChar ~
14506 \SpecialChar ~
14507 \SpecialChar ~
14508 \SpecialChar ~
14509 mov\SpecialChar ~
14510 \SpecialChar ~
14511 \SpecialChar ~
14512 \SpecialChar ~
14513 dph
14514 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14515
14516 \end_inset 
14517
14518 ,#0x00 
14519 \newline 
14520 \SpecialChar ~
14521 \SpecialChar ~
14522 \SpecialChar ~
14523 \SpecialChar ~
14524 \SpecialChar ~
14525 \SpecialChar ~
14526 \SpecialChar ~
14527 \SpecialChar ~
14528 ret
14529 \layout Standard
14530
14531 Note here that the return values
14532 \begin_inset LatexCommand \index{return value}
14533
14534 \end_inset 
14535
14536  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14537  two byte values.
14538  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14539 b' & 'acc' for four byte values.
14540 \layout Standard
14541
14542 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14543  the parameter number starting from 1, and counting from the left.
14544  The first parameter is passed in 
14545 \begin_inset Quotes eld
14546 \end_inset 
14547
14548 dpl
14549 \begin_inset Quotes erd
14550 \end_inset 
14551
14552  for a one byte parameter, 
14553 \begin_inset Quotes eld
14554 \end_inset 
14555
14556 dptr
14557 \begin_inset Quotes erd
14558 \end_inset 
14559
14560  for two bytes, 
14561 \begin_inset Quotes eld
14562 \end_inset 
14563
14564 b,dptr
14565 \begin_inset Quotes erd
14566 \end_inset 
14567
14568  for three bytes and 
14569 \begin_inset Quotes eld
14570 \end_inset 
14571
14572 acc,b,dptr
14573 \begin_inset Quotes erd
14574 \end_inset 
14575
14576  for a four bytes parameter.
14577  The variable name for the second parameter will be _<function_name>_PARM_2.
14578 \newline 
14579
14580 \newline 
14581 Assemble the assembler routine with the following command:
14582 \newline 
14583
14584 \newline 
14585
14586 \family sans 
14587 \series bold 
14588 asx8051 -losg asmfunc.asm
14589 \newline 
14590
14591 \newline 
14592
14593 \family default 
14594 \series default 
14595 Then compile and link the assembler routine to the C source file with the
14596  following command:
14597 \newline 
14598
14599 \newline 
14600
14601 \family sans 
14602 \series bold 
14603 sdcc cfunc.c asmfunc.rel
14604 \layout Subsection
14605
14606 Assembler Routine (reentrant)
14607 \layout Standard
14608
14609 In this case
14610 \begin_inset LatexCommand \index{reentrant}
14611
14612 \end_inset 
14613
14614
14615 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14616
14617 \end_inset 
14618
14619  the second parameter
14620 \begin_inset LatexCommand \index{function parameter}
14621
14622 \end_inset 
14623
14624  onwards will be passed on the stack, the parameters are pushed from right
14625  to left i.e.
14626  after the call the leftmost parameter will be on the top of the stack.
14627  Here is an example:
14628 \layout Verse
14629
14630
14631 \family typewriter 
14632 extern int asm_func(unsigned char, unsigned char);
14633 \newline 
14634
14635 \newline 
14636 int c_func (unsigned char i, unsigned char j) reentrant 
14637 \newline 
14638
14639 \newline 
14640 \SpecialChar ~
14641 \SpecialChar ~
14642 \SpecialChar ~
14643 \SpecialChar ~
14644 return asm_func(i,j); 
14645 \newline 
14646
14647 \newline 
14648
14649 \newline 
14650 int main() 
14651 \newline 
14652
14653 \newline 
14654 \SpecialChar ~
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 \SpecialChar ~
14658 return c_func(10,9); 
14659 \newline 
14660 }
14661 \layout Standard
14662
14663 The corresponding assembler routine is:
14664 \layout Verse
14665
14666
14667 \family typewriter 
14668 .globl _asm_func 
14669 \newline 
14670 _asm_func: 
14671 \newline 
14672 \SpecialChar ~
14673 \SpecialChar ~
14674 \SpecialChar ~
14675 \SpecialChar ~
14676 push  _bp 
14677 \newline 
14678 \SpecialChar ~
14679 \SpecialChar ~
14680 \SpecialChar ~
14681 \SpecialChar ~
14682 mov _bp,sp 
14683 \newline 
14684 \SpecialChar ~
14685 \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 mov r2,dpl
14689 \newline 
14690 \SpecialChar ~
14691 \SpecialChar ~
14692 \SpecialChar ~
14693 \SpecialChar ~
14694 mov a,_bp 
14695 \newline 
14696 \SpecialChar ~
14697 \SpecialChar ~
14698 \SpecialChar ~
14699 \SpecialChar ~
14700 add a,#0xfd 
14701 \newline 
14702 \SpecialChar ~
14703 \SpecialChar ~
14704 \SpecialChar ~
14705 \SpecialChar ~
14706 mov r0,a 
14707 \newline 
14708 \SpecialChar ~
14709 \SpecialChar ~
14710 \SpecialChar ~
14711 \SpecialChar ~
14712 add  a,#0xfc ;?
14713 \newline 
14714 \SpecialChar ~
14715 \SpecialChar ~
14716 \SpecialChar ~
14717 \SpecialChar ~
14718 mov  r1,a 
14719 \newline 
14720 \SpecialChar ~
14721 \SpecialChar ~
14722 \SpecialChar ~
14723 \SpecialChar ~
14724 mov  a,@r0 
14725 \newline 
14726 \SpecialChar ~
14727 \SpecialChar ~
14728 \SpecialChar ~
14729 \SpecialChar ~
14730 add  a,r2 ;?
14731 \newline 
14732 \SpecialChar ~
14733 \SpecialChar ~
14734 \SpecialChar ~
14735 \SpecialChar ~
14736 mov  dpl,a 
14737 \newline 
14738 \SpecialChar ~
14739 \SpecialChar ~
14740 \SpecialChar ~
14741 \SpecialChar ~
14742 mov  dph,#0x00 
14743 \newline 
14744 \SpecialChar ~
14745 \SpecialChar ~
14746 \SpecialChar ~
14747 \SpecialChar ~
14748 mov  sp,_bp 
14749 \newline 
14750 \SpecialChar ~
14751 \SpecialChar ~
14752 \SpecialChar ~
14753 \SpecialChar ~
14754 pop  _bp 
14755 \newline 
14756 \SpecialChar ~
14757 \SpecialChar ~
14758 \SpecialChar ~
14759 \SpecialChar ~
14760 ret
14761 \layout Standard
14762 \added_space_bottom bigskip 
14763 The compiling and linking procedure remains the same, however note the extra
14764  entry & exit linkage required for the assembler code, _bp is the stack
14765  frame pointer and is used to compute the offset into the stack for parameters
14766  and local variables.
14767 \layout Section
14768
14769 int (16 bit)
14770 \begin_inset LatexCommand \index{int (16 bit)}
14771
14772 \end_inset 
14773
14774  and long (32 bit)
14775 \begin_inset LatexCommand \index{long (32 bit)}
14776
14777 \end_inset 
14778
14779  Support
14780 \layout Standard
14781
14782 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14783  multiplication and modulus operations are implemented by support routines.
14784  These support routines are all developed in ANSI-C to facilitate porting
14785  to other MCUs, although some model specific assembler optimizations are
14786  used.
14787  The following files contain the described routines, all of them can be
14788  found in <installdir>/share/sdcc/lib.
14789 \newline 
14790
14791 \layout Standard
14792 \align center 
14793
14794 \begin_inset  Tabular
14795 <lyxtabular version="3" rows="11" columns="2">
14796 <features>
14797 <column alignment="left" valignment="top" leftline="true" width="0">
14798 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14799 <row topline="true" bottomline="true">
14800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14801 \begin_inset Text
14802
14803 \layout Standard
14804
14805
14806 \series bold 
14807 Function
14808 \end_inset 
14809 </cell>
14810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14811 \begin_inset Text
14812
14813 \layout Standard
14814
14815
14816 \series bold 
14817 Description
14818 \end_inset 
14819 </cell>
14820 </row>
14821 <row topline="true">
14822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14823 \begin_inset Text
14824
14825 \layout Standard
14826
14827 _mulint.c 
14828 \end_inset 
14829 </cell>
14830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14831 \begin_inset Text
14832
14833 \layout Standard
14834
14835 16 bit multiplication
14836 \end_inset 
14837 </cell>
14838 </row>
14839 <row topline="true">
14840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14841 \begin_inset Text
14842
14843 \layout Standard
14844
14845 _divsint.c 
14846 \end_inset 
14847 </cell>
14848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14849 \begin_inset Text
14850
14851 \layout Standard
14852
14853  signed 16 bit division (calls _divuint)
14854 \end_inset 
14855 </cell>
14856 </row>
14857 <row topline="true">
14858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14859 \begin_inset Text
14860
14861 \layout Standard
14862
14863 _divuint.c 
14864 \end_inset 
14865 </cell>
14866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14867 \begin_inset Text
14868
14869 \layout Standard
14870
14871  unsigned 16 bit division
14872 \end_inset 
14873 </cell>
14874 </row>
14875 <row topline="true">
14876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14877 \begin_inset Text
14878
14879 \layout Standard
14880
14881 _modsint.c
14882 \end_inset 
14883 </cell>
14884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14885 \begin_inset Text
14886
14887 \layout Standard
14888
14889 signed 16 bit modulus (calls _moduint)
14890 \end_inset 
14891 </cell>
14892 </row>
14893 <row topline="true">
14894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14895 \begin_inset Text
14896
14897 \layout Standard
14898
14899 _moduint.c
14900 \end_inset 
14901 </cell>
14902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14903 \begin_inset Text
14904
14905 \layout Standard
14906
14907 unsigned 16 bit modulus
14908 \end_inset 
14909 </cell>
14910 </row>
14911 <row topline="true">
14912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14913 \begin_inset Text
14914
14915 \layout Standard
14916
14917 _mullong.c
14918 \end_inset 
14919 </cell>
14920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14921 \begin_inset Text
14922
14923 \layout Standard
14924
14925 32 bit multiplication
14926 \end_inset 
14927 </cell>
14928 </row>
14929 <row topline="true">
14930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14931 \begin_inset Text
14932
14933 \layout Standard
14934
14935 _divslong.c 
14936 \end_inset 
14937 </cell>
14938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14939 \begin_inset Text
14940
14941 \layout Standard
14942
14943  signed 32 division (calls _divulong)
14944 \end_inset 
14945 </cell>
14946 </row>
14947 <row topline="true">
14948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14949 \begin_inset Text
14950
14951 \layout Standard
14952
14953 _divulong.c 
14954 \end_inset 
14955 </cell>
14956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14957 \begin_inset Text
14958
14959 \layout Standard
14960
14961 unsigned 32 division
14962 \end_inset 
14963 </cell>
14964 </row>
14965 <row topline="true">
14966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14967 \begin_inset Text
14968
14969 \layout Standard
14970
14971 _modslong.c
14972 \end_inset 
14973 </cell>
14974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14975 \begin_inset Text
14976
14977 \layout Standard
14978
14979  signed 32 bit modulus (calls _modulong)
14980 \end_inset 
14981 </cell>
14982 </row>
14983 <row topline="true" bottomline="true">
14984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14985 \begin_inset Text
14986
14987 \layout Standard
14988
14989 _modulong.c
14990 \end_inset 
14991 </cell>
14992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14993 \begin_inset Text
14994
14995 \layout Standard
14996
14997 unsigned 32 bit modulus
14998 \end_inset 
14999 </cell>
15000 </row>
15001 </lyxtabular>
15002
15003 \end_inset 
15004
15005
15006 \newline 
15007
15008 \layout Standard
15009
15010 Since they are compiled as 
15011 \emph on 
15012 non-reentrant
15013 \emph default 
15014
15015 \begin_inset LatexCommand \index{reentrant}
15016
15017 \end_inset 
15018
15019 , interrupt
15020 \begin_inset LatexCommand \index{interrupt}
15021
15022 \end_inset 
15023
15024  service routines should not do any of the above operations.
15025  If this is unavoidable then the above routines will need to be compiled
15026  with the 
15027 \emph on 
15028 -
15029 \begin_inset ERT
15030 status Collapsed
15031
15032 \layout Standard
15033
15034 \backslash 
15035 /
15036 \end_inset 
15037
15038 -stack-auto
15039 \begin_inset LatexCommand \index{-\/-stack-auto}
15040
15041 \end_inset 
15042
15043
15044 \emph default 
15045  option, after which the source program will have to be compiled with 
15046 \emph on 
15047 -
15048 \begin_inset ERT
15049 status Collapsed
15050
15051 \layout Standard
15052
15053 \backslash 
15054 /
15055 \end_inset 
15056
15057 -int-long-reent
15058 \begin_inset LatexCommand \index{-\/-int-long-reent}
15059
15060 \end_inset 
15061
15062
15063 \emph default 
15064  option.
15065  Notice that you don't have to call these routines directly.
15066  The compiler will use them automatically every time an integer operation
15067  is required.
15068 \layout Section
15069
15070 Floating Point Support
15071 \begin_inset LatexCommand \index{Floating point support}
15072
15073 \end_inset 
15074
15075
15076 \layout Standard
15077
15078 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15079  The floating point support routines are derived from gcc's floatlib.c and
15080  consist of the following routines:
15081 \newline 
15082
15083 \layout Standard
15084 \align center 
15085
15086 \size footnotesize 
15087
15088 \begin_inset  Tabular
15089 <lyxtabular version="3" rows="17" columns="2">
15090 <features>
15091 <column alignment="left" valignment="top" leftline="true" width="0">
15092 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15093 <row topline="true" bottomline="true">
15094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15095 \begin_inset Text
15096
15097 \layout Standard
15098
15099
15100 \family roman 
15101 \series medium 
15102 \shape up 
15103 \size normal 
15104 \emph off 
15105 \bar no 
15106 \noun off 
15107 \color none
15108 Function 
15109 \end_inset 
15110 </cell>
15111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15112 \begin_inset Text
15113
15114 \layout Standard
15115
15116 Description
15117 \end_inset 
15118 </cell>
15119 </row>
15120 <row topline="true">
15121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15122 \begin_inset Text
15123
15124 \layout Standard
15125
15126
15127 \family roman 
15128 \series medium 
15129 \shape up 
15130 \size normal 
15131 \emph off 
15132 \bar no 
15133 \noun off 
15134 \color none
15135 _fsadd.c
15136 \end_inset 
15137 </cell>
15138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15139 \begin_inset Text
15140
15141 \layout Standard
15142
15143
15144 \family roman 
15145 \series medium 
15146 \shape up 
15147 \size normal 
15148 \emph off 
15149 \bar no 
15150 \noun off 
15151 \color none
15152 add floating point numbers
15153 \end_inset 
15154 </cell>
15155 </row>
15156 <row topline="true">
15157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15158 \begin_inset Text
15159
15160 \layout Standard
15161
15162
15163 \family roman 
15164 \series medium 
15165 \shape up 
15166 \size normal 
15167 \emph off 
15168 \bar no 
15169 \noun off 
15170 \color none
15171 _fssub.c 
15172 \end_inset 
15173 </cell>
15174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15175 \begin_inset Text
15176
15177 \layout Standard
15178
15179
15180 \family roman 
15181 \series medium 
15182 \shape up 
15183 \size normal 
15184 \emph off 
15185 \bar no 
15186 \noun off 
15187 \color none
15188 subtract floating point numbers 
15189 \end_inset 
15190 </cell>
15191 </row>
15192 <row topline="true">
15193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15194 \begin_inset Text
15195
15196 \layout Standard
15197
15198
15199 \family roman 
15200 \series medium 
15201 \shape up 
15202 \size normal 
15203 \emph off 
15204 \bar no 
15205 \noun off 
15206 \color none
15207 _fsdiv.c 
15208 \end_inset 
15209 </cell>
15210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15211 \begin_inset Text
15212
15213 \layout Standard
15214
15215
15216 \family roman 
15217 \series medium 
15218 \shape up 
15219 \size normal 
15220 \emph off 
15221 \bar no 
15222 \noun off 
15223 \color none
15224 divide floating point numbers 
15225 \end_inset 
15226 </cell>
15227 </row>
15228 <row topline="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 _fsmul.c 
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
15252 \family roman 
15253 \series medium 
15254 \shape up 
15255 \size normal 
15256 \emph off 
15257 \bar no 
15258 \noun off 
15259 \color none
15260 multiply floating point numbers 
15261 \end_inset 
15262 </cell>
15263 </row>
15264 <row topline="true">
15265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15266 \begin_inset Text
15267
15268 \layout Standard
15269
15270
15271 \family roman 
15272 \series medium 
15273 \shape up 
15274 \size normal 
15275 \emph off 
15276 \bar no 
15277 \noun off 
15278 \color none
15279 _fs2uchar.c
15280 \end_inset 
15281 </cell>
15282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15283 \begin_inset Text
15284
15285 \layout Standard
15286
15287
15288 \family roman 
15289 \series medium 
15290 \shape up 
15291 \size normal 
15292 \emph off 
15293 \bar no 
15294 \noun off 
15295 \color none
15296 convert floating point to unsigned char
15297 \end_inset 
15298 </cell>
15299 </row>
15300 <row topline="true">
15301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15302 \begin_inset Text
15303
15304 \layout Standard
15305
15306
15307 \family roman 
15308 \series medium 
15309 \shape up 
15310 \size normal 
15311 \emph off 
15312 \bar no 
15313 \noun off 
15314 \color none
15315 _fs2char.c
15316 \end_inset 
15317 </cell>
15318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15319 \begin_inset Text
15320
15321 \layout Standard
15322
15323
15324 \family roman 
15325 \series medium 
15326 \shape up 
15327 \size normal 
15328 \emph off 
15329 \bar no 
15330 \noun off 
15331 \color none
15332 convert floating point to signed char
15333 \end_inset 
15334 </cell>
15335 </row>
15336 <row topline="true">
15337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15338 \begin_inset Text
15339
15340 \layout Standard
15341
15342
15343 \family roman 
15344 \series medium 
15345 \shape up 
15346 \size normal 
15347 \emph off 
15348 \bar no 
15349 \noun off 
15350 \color none
15351 _fs2uint.c
15352 \end_inset 
15353 </cell>
15354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15355 \begin_inset Text
15356
15357 \layout Standard
15358
15359
15360 \family roman 
15361 \series medium 
15362 \shape up 
15363 \size normal 
15364 \emph off 
15365 \bar no 
15366 \noun off 
15367 \color none
15368 convert floating point to unsigned int
15369 \end_inset 
15370 </cell>
15371 </row>
15372 <row topline="true">
15373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15374 \begin_inset Text
15375
15376 \layout Standard
15377
15378
15379 \family roman 
15380 \series medium 
15381 \shape up 
15382 \size normal 
15383 \emph off 
15384 \bar no 
15385 \noun off 
15386 \color none
15387 _fs2int.c
15388 \end_inset 
15389 </cell>
15390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15391 \begin_inset Text
15392
15393 \layout Standard
15394
15395
15396 \family roman 
15397 \series medium 
15398 \shape up 
15399 \size normal 
15400 \emph off 
15401 \bar no 
15402 \noun off 
15403 \color none
15404 convert floating point to signed int
15405 \end_inset 
15406 </cell>
15407 </row>
15408 <row topline="true">
15409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15410 \begin_inset Text
15411
15412 \layout Standard
15413
15414
15415 \family roman 
15416 \series medium 
15417 \shape up 
15418 \size normal 
15419 \emph off 
15420 \bar no 
15421 \noun off 
15422 \color none
15423 _fs2ulong.
15424 \family default 
15425 \series default 
15426 \shape default 
15427 \size default 
15428 \emph default 
15429 \bar default 
15430 \noun default 
15431 \color default
15432 c
15433 \end_inset 
15434 </cell>
15435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15436 \begin_inset Text
15437
15438 \layout Standard
15439
15440
15441 \family roman 
15442 \series medium 
15443 \shape up 
15444 \size normal 
15445 \emph off 
15446 \bar no 
15447 \noun off 
15448 \color none
15449 convert floating point to unsigned long
15450 \end_inset 
15451 </cell>
15452 </row>
15453 <row topline="true">
15454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15455 \begin_inset Text
15456
15457 \layout Standard
15458
15459
15460 \family roman 
15461 \series medium 
15462 \shape up 
15463 \size normal 
15464 \emph off 
15465 \bar no 
15466 \noun off 
15467 \color none
15468 _fs2long.c
15469 \end_inset 
15470 </cell>
15471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15472 \begin_inset Text
15473
15474 \layout Standard
15475
15476
15477 \family roman 
15478 \series medium 
15479 \shape up 
15480 \size normal 
15481 \emph off 
15482 \bar no 
15483 \noun off 
15484 \color none
15485 convert floating point to signed long
15486 \end_inset 
15487 </cell>
15488 </row>
15489 <row topline="true">
15490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15491 \begin_inset Text
15492
15493 \layout Standard
15494
15495
15496 \family roman 
15497 \series medium 
15498 \shape up 
15499 \size normal 
15500 \emph off 
15501 \bar no 
15502 \noun off 
15503 \color none
15504 _uchar2fs.c
15505 \end_inset 
15506 </cell>
15507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15508 \begin_inset Text
15509
15510 \layout Standard
15511
15512
15513 \family roman 
15514 \series medium 
15515 \shape up 
15516 \size normal 
15517 \emph off 
15518 \bar no 
15519 \noun off 
15520 \color none
15521 convert unsigned char to floating point
15522 \end_inset 
15523 </cell>
15524 </row>
15525 <row topline="true">
15526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15527 \begin_inset Text
15528
15529 \layout Standard
15530
15531
15532 \family roman 
15533 \series medium 
15534 \shape up 
15535 \size normal 
15536 \emph off 
15537 \bar no 
15538 \noun off 
15539 \color none
15540 _char2fs.c
15541 \end_inset 
15542 </cell>
15543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15544 \begin_inset Text
15545
15546 \layout Standard
15547
15548
15549 \family roman 
15550 \series medium 
15551 \shape up 
15552 \size normal 
15553 \emph off 
15554 \bar no 
15555 \noun off 
15556 \color none
15557 convert char to floating point number
15558 \end_inset 
15559 </cell>
15560 </row>
15561 <row topline="true">
15562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15563 \begin_inset Text
15564
15565 \layout Standard
15566
15567
15568 \family roman 
15569 \series medium 
15570 \shape up 
15571 \size normal 
15572 \emph off 
15573 \bar no 
15574 \noun off 
15575 \color none
15576 _uint2fs.c
15577 \end_inset 
15578 </cell>
15579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15580 \begin_inset Text
15581
15582 \layout Standard
15583
15584
15585 \family roman 
15586 \series medium 
15587 \shape up 
15588 \size normal 
15589 \emph off 
15590 \bar no 
15591 \noun off 
15592 \color none
15593 convert unsigned int to floating point
15594 \end_inset 
15595 </cell>
15596 </row>
15597 <row topline="true">
15598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15599 \begin_inset Text
15600
15601 \layout Standard
15602
15603
15604 \family roman 
15605 \series medium 
15606 \shape up 
15607 \size normal 
15608 \emph off 
15609 \bar no 
15610 \noun off 
15611 \color none
15612 _int2fs.c
15613 \end_inset 
15614 </cell>
15615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15616 \begin_inset Text
15617
15618 \layout Standard
15619
15620
15621 \family roman 
15622 \series medium 
15623 \shape up 
15624 \size normal 
15625 \emph off 
15626 \bar no 
15627 \noun off 
15628 \color none
15629 convert int to floating point numbers
15630 \end_inset 
15631 </cell>
15632 </row>
15633 <row topline="true">
15634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15635 \begin_inset Text
15636
15637 \layout Standard
15638
15639
15640 \family roman 
15641 \series medium 
15642 \shape up 
15643 \size normal 
15644 \emph off 
15645 \bar no 
15646 \noun off 
15647 \color none
15648 _ulong2fs.c
15649 \end_inset 
15650 </cell>
15651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15652 \begin_inset Text
15653
15654 \layout Standard
15655
15656
15657 \family roman 
15658 \series medium 
15659 \shape up 
15660 \size normal 
15661 \emph off 
15662 \bar no 
15663 \noun off 
15664 \color none
15665 convert unsigned long to floating point number
15666 \end_inset 
15667 </cell>
15668 </row>
15669 <row topline="true" bottomline="true">
15670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15671 \begin_inset Text
15672
15673 \layout Standard
15674
15675
15676 \family roman 
15677 \series medium 
15678 \shape up 
15679 \size normal 
15680 \emph off 
15681 \bar no 
15682 \noun off 
15683 \color none
15684 _long2fs.c
15685 \end_inset 
15686 </cell>
15687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15688 \begin_inset Text
15689
15690 \layout Standard
15691
15692
15693 \family roman 
15694 \series medium 
15695 \shape up 
15696 \size normal 
15697 \emph off 
15698 \bar no 
15699 \noun off 
15700 \color none
15701 convert long to floating point number
15702 \end_inset 
15703 </cell>
15704 </row>
15705 </lyxtabular>
15706
15707 \end_inset 
15708
15709
15710 \newline 
15711
15712 \layout Standard
15713 \added_space_bottom bigskip 
15714 These support routines are developed in ANSI-C so there is room for space
15715  and speed improvement
15716 \begin_inset Foot
15717 collapsed false
15718
15719 \layout Standard
15720
15721 These floating point routines (
15722 \emph on 
15723 not
15724 \emph default 
15725  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15726  
15727 \end_inset 
15728
15729 .
15730  Note if all these routines are used simultaneously the data space might
15731  overflow.
15732  For serious floating point usage the large model might be needed.
15733  Also notice that you don't have to call this routines directly.
15734  The compiler will use them automatically every time a floating point operation
15735  is required.
15736 \layout Section
15737
15738 Library Routines
15739 \begin_inset LatexCommand \index{Libraries}
15740
15741 \end_inset 
15742
15743
15744 \layout Standard
15745
15746
15747 \emph on 
15748 <pending: this is messy and incomplete - a little more information is in
15749  sdcc/doc/libdoc.txt
15750 \emph default 
15751  >
15752 \layout Subsection
15753
15754 Compiler support routines (_gptrget, _mulint etc.)
15755 \layout Subsection
15756
15757 Stdclib functions (puts, printf, strcat etc.)
15758 \layout Subsubsection
15759
15760 <stdio.h>
15761 \layout Standard
15762
15763
15764 \begin_inset LatexCommand \index{<stdio.h>}
15765
15766 \end_inset 
15767
15768 As usual on embedded systems you have to provide your own 
15769 \family typewriter 
15770 getchar()
15771 \begin_inset LatexCommand \index{getchar()}
15772
15773 \end_inset 
15774
15775  
15776 \family default 
15777 and 
15778 \family typewriter 
15779 putchar()
15780 \begin_inset LatexCommand \index{putchar()}
15781
15782 \end_inset 
15783
15784
15785 \family default 
15786  routines.
15787  SDCC does not know whether the system connects to a serial line with or
15788  without handshake, LCD, keyboard or other device.
15789  And whether a 
15790 \family typewriter 
15791 lf
15792 \family default 
15793  to 
15794 \family typewriter 
15795 crlf
15796 \family default 
15797  conversion within 
15798 \family typewriter 
15799 putchar()
15800 \family default 
15801  is intended.
15802  You'll find examples for serial routines f.e.
15803  in sdcc/device/lib.
15804 \layout Standard
15805
15806 The default
15807 \family typewriter 
15808  printf()
15809 \begin_inset LatexCommand \index{printf()}
15810
15811 \end_inset 
15812
15813
15814 \family default 
15815 implementation in
15816 \family typewriter 
15817  printf_large.c
15818 \family default 
15819  does not support float (except on ds390).
15820  To enable this recompile it with the option 
15821 \emph on 
15822 -
15823 \begin_inset ERT
15824 status Collapsed
15825
15826 \layout Standard
15827
15828 \backslash 
15829 /
15830 \end_inset 
15831
15832 DUSE_FLOATS=1
15833 \begin_inset LatexCommand \index{USE\_FLOATS}
15834
15835 \end_inset 
15836
15837
15838 \emph default 
15839  on the command line.
15840  Use
15841 \emph on 
15842  -
15843 \begin_inset ERT
15844 status Collapsed
15845
15846 \layout Standard
15847
15848 \backslash 
15849 /
15850 \end_inset 
15851
15852 -model-large
15853 \begin_inset LatexCommand \index{-\/-model-large}
15854
15855 \end_inset 
15856
15857
15858 \emph default 
15859  for the mcs51 port, since this uses a lot of memory.
15860 \layout Standard
15861
15862 If you're short on memory you might want to use 
15863 \family typewriter 
15864 printf_small()
15865 \begin_inset LatexCommand \index{printf\_small()}
15866
15867 \end_inset 
15868
15869
15870 \family default 
15871  
15872 \emph on 
15873 instead
15874 \emph default 
15875  of
15876 \family typewriter 
15877  printf().
15878
15879 \family default 
15880  For the mcs51 there additionally are assembly versions 
15881 \family typewriter 
15882 printf_tiny()
15883 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
15884
15885 \end_inset 
15886
15887
15888 \family default 
15889  (subset of printf using less than 270 bytes) and 
15890 \family typewriter 
15891 printf_fast()
15892 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
15893
15894 \end_inset 
15895
15896  
15897 \family default 
15898 and
15899 \family typewriter 
15900  printf_fast_f()
15901 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
15902
15903 \end_inset 
15904
15905
15906 \family default 
15907  (floating-point aware version of printf_fast) which should fit the requirements
15908  of many embedded systems (printf_fast() can be customized by unsetting
15909  #defines to 
15910 \emph on 
15911 not
15912 \emph default 
15913  support long variables and field widths).
15914 \layout Subsubsection
15915
15916 <malloc.h>
15917 \begin_inset LatexCommand \index{malloc.h}
15918
15919 \end_inset 
15920
15921
15922 \layout Standard
15923
15924 Before using dynamic
15925 \begin_inset LatexCommand \index{dynamic}
15926
15927 \end_inset 
15928
15929  memory allocation with SDCC, you have to provide heap
15930 \begin_inset LatexCommand \index{heap}
15931
15932 \end_inset 
15933
15934  space for malloc to allocate memory from
15935 \family typewriter 
15936 .
15937  
15938 \family default 
15939 You can acomplish this by including the following code into your source:
15940 \layout Verse
15941
15942
15943 \family typewriter 
15944 #include <malloc.h>
15945 \begin_inset LatexCommand \index{malloc.h}
15946
15947 \end_inset 
15948
15949  /* calloc
15950 \begin_inset LatexCommand \index{calloc}
15951
15952 \end_inset 
15953
15954 , malloc
15955 \begin_inset LatexCommand \index{malloc}
15956
15957 \end_inset 
15958
15959 , realloc
15960 \begin_inset LatexCommand \index{realloc}
15961
15962 \end_inset 
15963
15964 , and free
15965 \begin_inset LatexCommand \index{free}
15966
15967 \end_inset 
15968
15969  */ 
15970 \newline 
15971
15972 \newline 
15973 #define HEAPSIZE 0x1000 /* Adjust depending on available memory */ 
15974 \newline 
15975 unsigned char xdata myheap[HEAPSIZE]; /* The actual heap for dynamic memory
15976  */ 
15977 \newline 
15978
15979 \newline 
15980 void main (void) 
15981 \newline 
15982
15983 \newline 
15984 \SpecialChar ~
15985 \SpecialChar ~
15986 \SpecialChar ~
15987 /* Your variable declarations come here*/
15988 \newline 
15989 \SpecialChar ~
15990 \SpecialChar ~
15991 \SpecialChar ~
15992 ...
15993 \newline 
15994 \SpecialChar ~
15995 \SpecialChar ~
15996 \SpecialChar ~
15997 init_dynamic_memory((MEMHEADER xdata *)myheap, HEAPSIZE);
15998 \newline 
15999 \SpecialChar ~
16000 \SpecialChar ~
16001 \SpecialChar ~
16002 ...
16003  /* Rest of your code*/
16004 \newline 
16005
16006 \newline 
16007
16008 \layout Subsection
16009
16010 Math functions (sinf, powf, sqrtf etc.)
16011 \layout Subsubsection
16012
16013 <math.h>
16014 \layout Standard
16015
16016 See definitions in file <math.h>.
16017 \layout Subsection
16018
16019 Other libraries
16020 \layout Standard
16021
16022 Libraries
16023 \begin_inset LatexCommand \index{Libraries}
16024
16025 \end_inset 
16026
16027  included in SDCC should have a license at least as liberal as the GNU Lesser
16028  General Public License
16029 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16030
16031 \end_inset 
16032
16033  
16034 \emph on 
16035 LGPL
16036 \emph default 
16037 .
16038 \layout Comment
16039
16040 license statements for the libraries are missing.
16041  sdcc/device/lib/ser_ir.c
16042 \layout Comment
16043
16044 or _decdptr f.e.
16045  come with a GPL (as opposed to LGPL) License - this will not be liberal
16046  enough for many embedded programmers.
16047 \layout Standard
16048
16049 If you have ported some library or want to share experience about some code
16050  which f.e.
16051  falls into any of these categories Busses (I
16052 \begin_inset Formula $^{\textrm{2}}$
16053 \end_inset 
16054
16055 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16056  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16057  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
16058 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16059
16060 \end_inset 
16061
16062 \SpecialChar ~
16063 would certainly like to hear about it.
16064 \layout Standard
16065 \added_space_bottom bigskip 
16066 Programmers coding for embedded systems are not especially famous for being
16067  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16068 e these references are very valuable.
16069  Let's help to create a climate where information is shared.
16070 \layout Section
16071
16072 Memory Models
16073 \layout Subsection
16074
16075 MCS51 Memory Models
16076 \begin_inset LatexCommand \index{Memory model}
16077
16078 \end_inset 
16079
16080
16081 \begin_inset LatexCommand \index{MCS51 memory model}
16082
16083 \end_inset 
16084
16085
16086 \layout Subsubsection
16087
16088 Small, Medium and Large
16089 \layout Standard
16090
16091 SDCC allows three memory models for MCS51 code, 
16092 \shape slanted 
16093 small, medium
16094 \shape default 
16095  and 
16096 \shape slanted 
16097 large
16098 \shape default 
16099 .
16100  Modules compiled with different memory models should 
16101 \emph on 
16102 never
16103 \emph default 
16104  be combined together or the results would be unpredictable.
16105  The library routines supplied with the compiler are compiled as small,
16106  medium and large.
16107  The compiled library modules are contained in separate directories as small,
16108  medium and large so that you can link to the appropriate set.
16109 \layout Standard
16110
16111 When the medium or large model is used all variables declared without a
16112  storage class will be allocated into the external ram, this includes all
16113  parameters and local variables (for non-reentrant
16114 \begin_inset LatexCommand \index{reentrant}
16115
16116 \end_inset 
16117
16118  functions).
16119  When the small model is used variables without storage class are allocated
16120  in the internal ram.
16121 \layout Standard
16122
16123 Judicious usage of the processor specific storage classes
16124 \begin_inset LatexCommand \index{Storage class}
16125
16126 \end_inset 
16127
16128  and the 'reentrant' function type will yield much more efficient code,
16129  than using the large model.
16130  Several optimizations are disabled when the program is compiled using the
16131  large model, it is therefore recommended that the small model be used unless
16132  absolutely required.
16133 \layout Subsubsection
16134
16135 External Stack
16136 \begin_inset LatexCommand \label{sub:External-Stack}
16137
16138 \end_inset 
16139
16140
16141 \begin_inset LatexCommand \index{stack}
16142
16143 \end_inset 
16144
16145
16146 \begin_inset LatexCommand \index{External stack (mcs51)}
16147
16148 \end_inset 
16149
16150
16151 \layout Standard
16152
16153 The external stack (-
16154 \begin_inset ERT
16155 status Collapsed
16156
16157 \layout Standard
16158
16159 \backslash 
16160 /
16161 \end_inset 
16162
16163 -xstack option
16164 \begin_inset LatexCommand \index{-\/-xstack}
16165
16166 \end_inset 
16167
16168 ) is located in pdata
16169 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16170
16171 \end_inset 
16172
16173  memory (usually at the start of the external ram segment) and uses all
16174  unused space in pdata (max.
16175  256 bytes).
16176  When -
16177 \begin_inset ERT
16178 status Collapsed
16179
16180 \layout Standard
16181
16182 \backslash 
16183 /
16184 \end_inset 
16185
16186 -xstack option is used to compile the program, the parameters and local
16187  variables
16188 \begin_inset LatexCommand \index{local variables}
16189
16190 \end_inset 
16191
16192  of all reentrant functions are allocated in this area.
16193  This option is provided for programs with large stack space requirements.
16194  When used with the -
16195 \begin_inset ERT
16196 status Collapsed
16197
16198 \layout Standard
16199
16200 \backslash 
16201 /
16202 \end_inset 
16203
16204 -stack-auto
16205 \begin_inset LatexCommand \index{-\/-stack-auto}
16206
16207 \end_inset 
16208
16209  option, all parameters and local variables are allocated on the external
16210  stack (note: support libraries will need to be recompiled with the same
16211  options.
16212  There is a predefined target in the library makefile).
16213 \layout Standard
16214
16215 The compiler outputs the higher order address byte of the external ram segment
16216  into port P2
16217 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16218
16219 \end_inset 
16220
16221  (see also section 
16222 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16223
16224 \end_inset 
16225
16226 ), therefore when using the External Stack option, this port 
16227 \emph on 
16228 may not
16229 \emph default 
16230  be used by the application program.
16231 \layout Subsection
16232
16233 DS390 Memory Model
16234 \begin_inset LatexCommand \index{Memory model}
16235
16236 \end_inset 
16237
16238
16239 \begin_inset LatexCommand \index{DS390 memory model}
16240
16241 \end_inset 
16242
16243
16244 \layout Standard
16245
16246 The only model supported is Flat 24
16247 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
16248
16249 \end_inset 
16250
16251 .
16252  This generates code for the 24 bit contiguous addressing mode of the Dallas
16253  DS80C390 part.
16254  In this mode, up to four meg of external RAM or code space can be directly
16255  addressed.
16256  See the data sheets at www.dalsemi.com for further information on this part.
16257 \newline 
16258
16259 \newline 
16260 Note that the compiler does not generate any code to place the processor
16261  into 24 bitmode (although 
16262 \emph on 
16263 tinibios
16264 \emph default 
16265  in the ds390 libraries will do that for you).
16266  If you don't use 
16267 \emph on 
16268 tinibios
16269 \emph default 
16270
16271 \begin_inset LatexCommand \index{Tinibios (DS390)}
16272
16273 \end_inset 
16274
16275 , the boot loader or similar code must ensure that the processor is in 24
16276  bit contiguous addressing mode before calling the SDCC startup code.
16277 \newline 
16278
16279 \newline 
16280 Like the 
16281 \emph on 
16282 -
16283 \begin_inset ERT
16284 status Collapsed
16285
16286 \layout Standard
16287
16288 \backslash 
16289 /
16290 \end_inset 
16291
16292 -model-large
16293 \emph default 
16294  option, variables will by default be placed into the XDATA segment.
16295  
16296 \newline 
16297
16298 \newline 
16299 Segments may be placed anywhere in the 4 meg address space using the usual
16300  -
16301 \begin_inset ERT
16302 status Collapsed
16303
16304 \layout Standard
16305
16306 \backslash 
16307 /
16308 \end_inset 
16309
16310 -*-loc options.
16311  Note that if any segments are located above 64K, the -r flag must be passed
16312  to the linker to generate the proper segment relocations, and the Intel
16313  HEX output format must be used.
16314  The -r flag can be passed to the linker by using the option 
16315 \emph on 
16316 -Wl-r
16317 \emph default 
16318  on the SDCC command line.
16319  However, currently the linker can not handle code segments > 64k.
16320 \layout Section
16321
16322 Pragmas
16323 \begin_inset LatexCommand \label{sec:Pragmas}
16324
16325 \end_inset 
16326
16327
16328 \begin_inset LatexCommand \index{Pragmas}
16329
16330 \end_inset 
16331
16332
16333 \layout Standard
16334
16335 SDCC supports the following #pragma directives:
16336 \layout Itemize
16337
16338
16339 \series bold 
16340 save
16341 \series default 
16342
16343 \begin_inset LatexCommand \index{\#pragma save}
16344
16345 \end_inset 
16346
16347  - this will save most current options to the save/restore stack.
16348  See #pragma\SpecialChar ~
16349 restore.
16350 \layout Itemize
16351
16352
16353 \series bold 
16354 restore
16355 \series default 
16356
16357 \begin_inset LatexCommand \index{\#pragma restore}
16358
16359 \end_inset 
16360
16361  - will restore saved options from the last save.
16362  saves & restores can be nested.
16363  SDCC uses a save/restore stack: save pushes current options to the stack,
16364  restore pulls current options from the stack.
16365  See #pragma\SpecialChar ~
16366 save.
16367 \newline 
16368
16369 \layout Itemize
16370
16371
16372 \series bold 
16373 callee_saves
16374 \series default 
16375
16376 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16377
16378 \end_inset 
16379
16380
16381 \begin_inset LatexCommand \index{function prologue}
16382
16383 \end_inset 
16384
16385  function1[,function2[,function3...]] - The compiler by default uses a caller
16386  saves convention for register saving across function calls, however this
16387  can cause unnecessary register pushing & popping
16388 \begin_inset LatexCommand \index{push/pop}
16389
16390 \end_inset 
16391
16392  when calling small functions from larger functions.
16393  This option can be used to switch off the register saving convention for
16394  the function names specified.
16395  The compiler will not save registers when calling these functions, extra
16396  code need to be manually inserted at the entry & exit for these functions
16397  to save & restore the registers used by these functions, this can SUBSTANTIALLY
16398  reduce code & improve run time performance of the generated code.
16399  In the future the compiler (with inter procedural analysis) may be able
16400  to determine the appropriate scheme to use for each function call.
16401  If -
16402 \begin_inset ERT
16403 status Collapsed
16404
16405 \layout Standard
16406
16407 \backslash 
16408 /
16409 \end_inset 
16410
16411 -callee-saves command line option is used, the function names specified
16412  in #pragma\SpecialChar ~
16413 callee_saves
16414 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16415
16416 \end_inset 
16417
16418  is appended to the list of functions specified in the command line.
16419 \layout Itemize
16420
16421
16422 \series bold 
16423 exclude
16424 \series default 
16425
16426 \begin_inset LatexCommand \index{\#pragma exclude}
16427
16428 \end_inset 
16429
16430  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
16431  of pairs of push/pop
16432 \begin_inset LatexCommand \index{push/pop}
16433
16434 \end_inset 
16435
16436  instructions in 
16437 \emph on 
16438 I
16439 \emph default 
16440 nterrupt
16441 \begin_inset LatexCommand \index{interrupt}
16442
16443 \end_inset 
16444
16445  
16446 \emph on 
16447 S
16448 \emph default 
16449 ervice 
16450 \emph on 
16451 R
16452 \emph default 
16453 outines.
16454  The directive should be placed immediately before the ISR function definition
16455  and it affects ALL ISR functions following it.
16456  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
16457 exclude\SpecialChar ~
16458 none
16459 \begin_inset LatexCommand \index{\#pragma exclude}
16460
16461 \end_inset 
16462
16463 .
16464  See also the related keyword _naked
16465 \begin_inset LatexCommand \index{\_naked}
16466
16467 \end_inset 
16468
16469
16470 \begin_inset LatexCommand \index{\_\_naked}
16471
16472 \end_inset 
16473
16474 .
16475 \layout Itemize
16476
16477
16478 \series bold 
16479 less_pedantic
16480 \series default 
16481
16482 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16483
16484 \end_inset 
16485
16486  - the compiler will not warn you anymore for obvious mistakes, you'r on
16487  your own now ;-(
16488 \layout Itemize
16489
16490
16491 \series bold 
16492 disable_warning
16493 \series default 
16494  <nnnn>
16495 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16496
16497 \end_inset 
16498
16499  - the compiler will not warn you anymore about warning number <nnnn>.
16500 \layout Itemize
16501
16502
16503 \series bold 
16504 nogcse
16505 \series default 
16506
16507 \begin_inset LatexCommand \index{\#pragma nogcse}
16508
16509 \end_inset 
16510
16511  - will stop global common subexpression elimination.
16512 \layout Itemize
16513
16514
16515 \series bold 
16516 noinduction
16517 \series default 
16518
16519 \begin_inset LatexCommand \index{\#pragma noinduction}
16520
16521 \end_inset 
16522
16523  - will stop loop induction optimizations.
16524 \layout Itemize
16525
16526
16527 \series bold 
16528 noinvariant
16529 \series default 
16530
16531 \begin_inset LatexCommand \index{\#pragma noinvariant}
16532
16533 \end_inset 
16534
16535  - will not do loop invariant optimizations.
16536  For more details see Loop Invariants in section
16537 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16538
16539 \end_inset 
16540
16541 .
16542 \layout Itemize
16543
16544
16545 \series bold 
16546 noiv
16547 \series default 
16548
16549 \begin_inset LatexCommand \index{\#pragma noiv}
16550
16551 \end_inset 
16552
16553  - Do not generate interrupt
16554 \begin_inset LatexCommand \index{interrupt}
16555
16556 \end_inset 
16557
16558  vector table entries for all ISR functions defined after the pragma.
16559  This is useful in cases where the interrupt vector table must be defined
16560  manually, or when there is a secondary, manually defined interrupt vector
16561  table (e.g.
16562  for the autovector feature of the Cypress EZ-USB FX2).
16563  More elegantly this can be achieved by obmitting the optional interrupt
16564  number after the interrupt keyword, see section 
16565 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16566
16567 \end_inset 
16568
16569 \SpecialChar ~
16570 about interrupts.
16571 \layout Itemize
16572
16573
16574 \series bold 
16575 nojtbound
16576 \series default 
16577
16578 \begin_inset LatexCommand \index{\#pragma nojtbound}
16579
16580 \end_inset 
16581
16582  - will not generate code for boundary value checking, when switch statements
16583  are turned into jump-tables (dangerous).
16584  For more details see section 
16585 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16586
16587 \end_inset 
16588
16589 .
16590 \layout Itemize
16591
16592
16593 \series bold 
16594 noloopreverse
16595 \series default 
16596
16597 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16598
16599 \end_inset 
16600
16601  - Will not do loop reversal optimization
16602 \layout Itemize
16603
16604
16605 \series bold 
16606 nooverlay
16607 \series default 
16608
16609 \begin_inset LatexCommand \index{\#pragma nooverlay}
16610
16611 \end_inset 
16612
16613  - the compiler will not overlay the parameters and local variables of a
16614  function.
16615 \layout Itemize
16616
16617
16618 \series bold 
16619 stackauto
16620 \series default 
16621
16622 \begin_inset LatexCommand \index{\#pragma stackauto}
16623
16624 \end_inset 
16625
16626 - See option -
16627 \begin_inset ERT
16628 status Collapsed
16629
16630 \layout Standard
16631
16632 \backslash 
16633 /
16634 \end_inset 
16635
16636 -stack-auto
16637 \begin_inset LatexCommand \index{-\/-stack-auto}
16638
16639 \end_inset 
16640
16641  and section 
16642 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16643
16644 \end_inset 
16645
16646  Parameters and Local Variables.
16647 \layout Itemize
16648
16649
16650 \series bold 
16651 opt_code_speed
16652 \series default 
16653  
16654 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16655
16656 \end_inset 
16657
16658 - The compiler will optimize code generation towards fast code, possibly
16659  at the expense of code size.
16660  Currently this has little effect.
16661 \layout Itemize
16662
16663
16664 \series bold 
16665 opt_code_size
16666 \series default 
16667  
16668 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16669
16670 \end_inset 
16671
16672 - The compiler will optimize code generation towards compact code, possibly
16673  at the expense of code speed.
16674  Currently this has little effect.
16675 \layout Itemize
16676
16677
16678 \series bold 
16679 opt_code_balanced
16680 \series default 
16681  
16682 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16683
16684 \end_inset 
16685
16686 - The compiler will attempt to generate code that is both compact and fast,
16687  as long as meeting one goal is not a detriment to the other (this is the
16688  default).
16689  
16690 \layout Itemize
16691
16692
16693 \series bold 
16694 std_sdcc89
16695 \series default 
16696  
16697 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16698
16699 \end_inset 
16700
16701 - Generally follow the C89 standard, but allow SDCC features that conflict
16702  with the standard (default).
16703 \layout Itemize
16704
16705
16706 \series bold 
16707 std_c89
16708 \series default 
16709  
16710 \begin_inset LatexCommand \index{\#pragma std\_c89}
16711
16712 \end_inset 
16713
16714 - Follow the C89 standard and disable SDCC features that conflict with the
16715  standard.
16716 \layout Itemize
16717
16718
16719 \series bold 
16720 std_sdcc99
16721 \series default 
16722  
16723 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16724
16725 \end_inset 
16726
16727 - Generally follow the C99 standard, but allow SDCC features that conflict
16728  with the standard (incomplete support).
16729 \layout Itemize
16730
16731
16732 \series bold 
16733 std_c99
16734 \series default 
16735  
16736 \begin_inset LatexCommand \index{\#pragma std\_c99}
16737
16738 \end_inset 
16739
16740 - Follow the C99 standard and disable SDCC features that conflict with the
16741  standard (incomplete support).
16742 \layout Itemize
16743
16744
16745 \series bold 
16746 codeseg
16747 \series default 
16748  <name>
16749 \begin_inset LatexCommand \index{\#pragma codeseg}
16750
16751 \end_inset 
16752
16753 - Use this name (max.
16754  8 characters) for the code segment.
16755  See option -
16756 \begin_inset ERT
16757 status Collapsed
16758
16759 \layout Standard
16760
16761 \backslash 
16762 /
16763 \end_inset 
16764
16765 -codeseg.
16766 \layout Itemize
16767
16768
16769 \series bold 
16770 constseg
16771 \series default 
16772  <name>
16773 \begin_inset LatexCommand \index{\#pragma constseg}
16774
16775 \end_inset 
16776
16777 - Use this name (max.
16778  8 characters) for the const segment.
16779  See option -
16780 \begin_inset ERT
16781 status Collapsed
16782
16783 \layout Standard
16784
16785 \backslash 
16786 /
16787 \end_inset 
16788
16789 -constseg.
16790 \layout Standard
16791
16792 The preprocessor SDCPP
16793 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
16794
16795 \end_inset 
16796
16797  supports the following #pragma directives:
16798 \layout Itemize
16799
16800
16801 \series bold 
16802 preproc_asm
16803 \series default 
16804
16805 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16806
16807 \end_inset 
16808
16809  (+ | -) - switch _asm _endasm block preprocessing on / off.
16810  Default is on.
16811  You use this prama to define multilines of assembly code.
16812  This will prevent the preprocessor from changing the formating required
16813  by assembly code.
16814  Below is an example on how to use this pragma.
16815 \layout Verse
16816
16817
16818 \family typewriter 
16819 #pragma preproc_asm -
16820 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16821
16822 \end_inset 
16823
16824
16825 \newline 
16826 #define MYDELAY _asm
16827 \newline 
16828 \SpecialChar ~
16829 \SpecialChar ~
16830 \SpecialChar ~
16831 nop ;my assembly comment...
16832 \newline 
16833 \SpecialChar ~
16834 \SpecialChar ~
16835 \SpecialChar ~
16836 nop
16837 \newline 
16838 \SpecialChar ~
16839 \SpecialChar ~
16840 \SpecialChar ~
16841 nop
16842 \newline 
16843 _endasm
16844 \newline 
16845 #pragma preproc_asm +
16846 \newline 
16847
16848 \newline 
16849 void foo (void) 
16850 \newline 
16851
16852 \newline 
16853 \SpecialChar ~
16854 \SpecialChar ~
16855 \SpecialChar ~
16856  ...
16857  
16858 \newline 
16859 \SpecialChar ~
16860 \SpecialChar ~
16861 \SpecialChar ~
16862  MYDELAY;
16863 \newline 
16864 \SpecialChar ~
16865 \SpecialChar ~
16866 \SpecialChar ~
16867  ...
16868  
16869 \newline 
16870
16871 \newline 
16872
16873 \layout Standard
16874
16875 The pragma's are intended to be used to turn-on or off certain optimizations
16876  which might cause the compiler to generate extra stack / data space to
16877  store compiler generated temporary variables.
16878  This usually happens in large functions.
16879  Pragma directives should be used as shown in the following example, they
16880  are used to control options & optimizations for a given function; pragmas
16881  should be placed before and/or after a function, placing pragma's inside
16882  a function body could have unpredictable results.
16883 \layout Verse
16884
16885
16886 \family typewriter 
16887 #pragma save
16888 \begin_inset LatexCommand \index{\#pragma save}
16889
16890 \end_inset 
16891
16892  \SpecialChar ~
16893 \SpecialChar ~
16894 \SpecialChar ~
16895 \SpecialChar ~
16896 \SpecialChar ~
16897 \SpecialChar ~
16898 \SpecialChar ~
16899 /* save the current settings */ 
16900 \newline 
16901 #pragma nogcse
16902 \begin_inset LatexCommand \index{\#pragma nogcse}
16903
16904 \end_inset 
16905
16906  \SpecialChar ~
16907 \SpecialChar ~
16908 \SpecialChar ~
16909 \SpecialChar ~
16910 \SpecialChar ~
16911 /* turnoff global subexpression elimination */ 
16912 \newline 
16913 #pragma noinduction
16914 \begin_inset LatexCommand \index{\#pragma noinduction}
16915
16916 \end_inset 
16917
16918  /* turn off induction optimizations */ 
16919 \newline 
16920 int foo () 
16921 \newline 
16922
16923 \newline 
16924 \SpecialChar ~
16925  \SpecialChar ~
16926  ...
16927  
16928 \newline 
16929 \SpecialChar ~
16930  \SpecialChar ~
16931  /* large code */ 
16932 \newline 
16933 \SpecialChar ~
16934  \SpecialChar ~
16935  ...
16936  
16937 \newline 
16938
16939 \newline 
16940 #pragma restore
16941 \begin_inset LatexCommand \index{\#pragma restore}
16942
16943 \end_inset 
16944
16945  /* turn the optimizations back on */
16946 \layout Standard
16947
16948 The compiler will generate a warning message when extra space is allocated.
16949  It is strongly recommended that the save and restore pragma's be used when
16950  changing options for a function.
16951 \newline 
16952
16953 \newline 
16954
16955 \newline 
16956
16957 \layout Section
16958
16959 Defines Created by the Compiler
16960 \layout Standard
16961
16962 The compiler creates the following #defines
16963 \begin_inset LatexCommand \index{\#defines}
16964
16965 \end_inset 
16966
16967
16968 \begin_inset LatexCommand \index{Defines created by the compiler}
16969
16970 \end_inset 
16971
16972 :
16973 \newline 
16974
16975 \layout Standard
16976
16977
16978 \begin_inset  Tabular
16979 <lyxtabular version="3" rows="11" columns="2">
16980 <features>
16981 <column alignment="left" valignment="top" leftline="true" width="3in">
16982 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
16983 <row topline="true" bottomline="true">
16984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16985 \begin_inset Text
16986
16987 \layout Standard
16988
16989
16990 \series bold 
16991 #define
16992 \end_inset 
16993 </cell>
16994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16995 \begin_inset Text
16996
16997 \layout Standard
16998
16999
17000 \series bold 
17001 Description
17002 \end_inset 
17003 </cell>
17004 </row>
17005 <row topline="true">
17006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17007 \begin_inset Text
17008
17009 \layout Standard
17010
17011 SDCC
17012 \begin_inset LatexCommand \index{SDCC}
17013
17014 \end_inset 
17015
17016  
17017 \end_inset 
17018 </cell>
17019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17020 \begin_inset Text
17021
17022 \layout Standard
17023
17024 Always defined.
17025  Since version 2.5.6 the version number as an int (ex.
17026  256)
17027 \end_inset 
17028 </cell>
17029 </row>
17030 <row topline="true">
17031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17032 \begin_inset Text
17033
17034 \layout Standard
17035
17036 SDCC_mcs51
17037 \begin_inset LatexCommand \index{SDCC\_mcs51}
17038
17039 \end_inset 
17040
17041  or SDCC_ds390
17042 \begin_inset LatexCommand \index{SDCC\_ds390}
17043
17044 \end_inset 
17045
17046  or SDCC_z80
17047 \begin_inset LatexCommand \index{SDCC\_z80}
17048
17049 \end_inset 
17050
17051 , etc.
17052 \end_inset 
17053 </cell>
17054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17055 \begin_inset Text
17056
17057 \layout Standard
17058
17059 depending on the model used (e.g.: -mds390)
17060 \end_inset 
17061 </cell>
17062 </row>
17063 <row topline="true">
17064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17065 \begin_inset Text
17066
17067 \layout Standard
17068
17069 __mcs51
17070 \begin_inset LatexCommand \index{\_\_mcs51}
17071
17072 \end_inset 
17073
17074 , __ds390
17075 \begin_inset LatexCommand \index{\_\_ds390}
17076
17077 \end_inset 
17078
17079 , __hc08
17080 \begin_inset LatexCommand \index{\_\_hc08}
17081
17082 \end_inset 
17083
17084 , __z80
17085 \begin_inset LatexCommand \index{\_\_z80}
17086
17087 \end_inset 
17088
17089 , etc
17090 \end_inset 
17091 </cell>
17092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17093 \begin_inset Text
17094
17095 \layout Standard
17096
17097 depending on the model used (e.g.
17098  -mz80)
17099 \end_inset 
17100 </cell>
17101 </row>
17102 <row topline="true">
17103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17104 \begin_inset Text
17105
17106 \layout Standard
17107
17108 SDCC_STACK_AUTO
17109 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
17110
17111 \end_inset 
17112
17113
17114 \end_inset 
17115 </cell>
17116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17117 \begin_inset Text
17118
17119 \layout Standard
17120
17121 when 
17122 \emph on 
17123 -
17124 \begin_inset ERT
17125 status Collapsed
17126
17127 \layout Standard
17128
17129 \backslash 
17130 /
17131 \end_inset 
17132
17133 -stack-auto
17134 \emph default 
17135  option is used
17136 \end_inset 
17137 </cell>
17138 </row>
17139 <row topline="true">
17140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17141 \begin_inset Text
17142
17143 \layout Standard
17144
17145 SDCC_MODEL_SMALL
17146 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
17147
17148 \end_inset 
17149
17150
17151 \end_inset 
17152 </cell>
17153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17154 \begin_inset Text
17155
17156 \layout Standard
17157
17158 when 
17159 \emph on 
17160 -
17161 \begin_inset ERT
17162 status Collapsed
17163
17164 \layout Standard
17165
17166 \backslash 
17167 /
17168 \end_inset 
17169
17170 -model-small
17171 \emph default 
17172  is used
17173 \end_inset 
17174 </cell>
17175 </row>
17176 <row topline="true">
17177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17178 \begin_inset Text
17179
17180 \layout Standard
17181
17182 SDCC_MODEL_MEDIUM
17183 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
17184
17185 \end_inset 
17186
17187
17188 \end_inset 
17189 </cell>
17190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17191 \begin_inset Text
17192
17193 \layout Standard
17194
17195 when 
17196 \emph on 
17197 -
17198 \begin_inset ERT
17199 status Collapsed
17200
17201 \layout Standard
17202
17203 \backslash 
17204 /
17205 \end_inset 
17206
17207 -model-medium
17208 \emph default 
17209  is used
17210 \end_inset 
17211 </cell>
17212 </row>
17213 <row topline="true">
17214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17215 \begin_inset Text
17216
17217 \layout Standard
17218
17219 SDCC_MODEL_LARGE
17220 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
17221
17222 \end_inset 
17223
17224
17225 \end_inset 
17226 </cell>
17227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17228 \begin_inset Text
17229
17230 \layout Standard
17231
17232 when 
17233 \emph on 
17234 -
17235 \begin_inset ERT
17236 status Collapsed
17237
17238 \layout Standard
17239
17240 \backslash 
17241 /
17242 \end_inset 
17243
17244 -model-large
17245 \emph default 
17246  is used
17247 \end_inset 
17248 </cell>
17249 </row>
17250 <row topline="true">
17251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17252 \begin_inset Text
17253
17254 \layout Standard
17255
17256 SDCC_USE_XSTACK
17257 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
17258
17259 \end_inset 
17260
17261
17262 \end_inset 
17263 </cell>
17264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17265 \begin_inset Text
17266
17267 \layout Standard
17268
17269 when 
17270 \emph on 
17271 -
17272 \begin_inset ERT
17273 status Collapsed
17274
17275 \layout Standard
17276
17277 \backslash 
17278 /
17279 \end_inset 
17280
17281 -xstack
17282 \emph default 
17283  option is used
17284 \end_inset 
17285 </cell>
17286 </row>
17287 <row topline="true">
17288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17289 \begin_inset Text
17290
17291 \layout Standard
17292
17293 SDCC_STACK_TENBIT
17294 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
17295
17296 \end_inset 
17297
17298  
17299 \end_inset 
17300 </cell>
17301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17302 \begin_inset Text
17303
17304 \layout Standard
17305
17306 when 
17307 \emph on 
17308 -mds390
17309 \emph default 
17310  is used
17311 \end_inset 
17312 </cell>
17313 </row>
17314 <row topline="true" bottomline="true">
17315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17316 \begin_inset Text
17317
17318 \layout Standard
17319
17320 SDCC_MODEL_FLAT24
17321 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
17322
17323 \end_inset 
17324
17325
17326 \end_inset 
17327 </cell>
17328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17329 \begin_inset Text
17330
17331 \layout Standard
17332
17333 when 
17334 \emph on 
17335 -mds390
17336 \emph default 
17337  is used
17338 \end_inset 
17339 </cell>
17340 </row>
17341 </lyxtabular>
17342
17343 \end_inset 
17344
17345
17346 \layout Chapter
17347
17348 Notes on supported Processors
17349 \layout Section
17350
17351 MCS51 variants
17352 \begin_inset LatexCommand \label{sub:MCS51-variants}
17353
17354 \end_inset 
17355
17356
17357 \begin_inset LatexCommand \index{MCS51 variants}
17358
17359 \end_inset 
17360
17361
17362 \layout Standard
17363
17364 MCS51 processors are available from many vendors and come in many different
17365  flavours.
17366  While they might differ considerably in respect to Special Function Registers
17367  the core MCS51 is usually not modified or is kept compatible.
17368  
17369 \layout Subsection
17370
17371 pdata access by SFR 
17372 \layout Standard
17373
17374 With the upcome of devices with internal xdata and flash memory devices
17375  using port P2
17376 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17377
17378 \end_inset 
17379
17380  as dedicated I/O port is becoming more popular.
17381  Switching the high byte for pdata
17382 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17383
17384 \end_inset 
17385
17386  access which was formerly done by port P2 is then achieved by a Special
17387  Function Register
17388 \begin_inset LatexCommand \index{sfr}
17389
17390 \end_inset 
17391
17392 .
17393  In well-established MCS51 tradition the address of this 
17394 \emph on 
17395 sfr
17396 \emph default 
17397  is where the chip designers decided to put it.
17398  Needless to say that they didn't agree on a common name either.
17399  So that the startup code can correctly initialize xdata variables, you
17400  should define an sfr with the name _XPAGE
17401 \family typewriter 
17402
17403 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
17404
17405 \end_inset 
17406
17407
17408 \family default 
17409  at the appropriate location if the default, port P2, is not used for this.
17410  Some examples are:
17411 \layout Verse
17412
17413
17414 \family typewriter 
17415 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
17416 \layout Verse
17417
17418
17419 \family typewriter 
17420 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17421 \layout Verse
17422
17423
17424 \family typewriter 
17425 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17426 \layout Standard
17427
17428 For more exotic implementations further customizations may be needed.
17429  See section 
17430 \begin_inset LatexCommand \ref{sub:Startup-Code}
17431
17432 \end_inset 
17433
17434  for other possibilities.
17435 \layout Subsection
17436
17437 Other Features available by SFR
17438 \layout Standard
17439 \added_space_bottom bigskip 
17440 Some MCS51 variants offer features like Double DPTR
17441 \begin_inset LatexCommand \index{DPTR}
17442
17443 \end_inset 
17444
17445 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17446  These are currently not used for the MCS51 port.
17447  If you absolutely need them you can fall back to inline assembly or submit
17448  a patch to SDCC.
17449 \layout Section
17450
17451 DS400 port
17452 \layout Standard
17453 \added_space_bottom bigskip 
17454 The DS80C400
17455 \begin_inset LatexCommand \index{DS80C400}
17456
17457 \end_inset 
17458
17459
17460 \begin_inset LatexCommand \index{DS400}
17461
17462 \end_inset 
17463
17464  microcontroller has a rich set of peripherals.
17465  In its built-in ROM library it includes functions to access some of the
17466  features, among them is a TCP stack with IP4 and IP6 support.
17467  Library headers (currently in beta status) and other files are provided
17468  at 
17469 \size footnotesize 
17470
17471 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
17472
17473 \end_inset 
17474
17475 .
17476  
17477 \layout Section
17478
17479 The Z80 and gbz80 port
17480 \layout Standard
17481
17482 SDCC can target both the Zilog Z80
17483 \begin_inset LatexCommand \index{Z80}
17484
17485 \end_inset 
17486
17487  and the Nintendo Gameboy's Z80-like gbz80
17488 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17489
17490 \end_inset 
17491
17492 .
17493  The Z80 port is passed through the same 
17494 \emph on 
17495 regressions tests
17496 \begin_inset LatexCommand \index{Regression test}
17497
17498 \end_inset 
17499
17500
17501 \emph default 
17502  as the MCS51 and DS390 ports, so floating point support, support for long
17503  variables and bitfield support is fine.
17504  See mailing lists and forums about interrupt routines.
17505 \layout Standard
17506 \added_space_bottom bigskip 
17507 As always, the code is the authoritative reference - see z80/ralloc.c and
17508  z80/gen.c.
17509  The stack
17510 \begin_inset LatexCommand \index{Z80!stack}
17511
17512 \end_inset 
17513
17514  frame is similar to that generated by the IAR Z80 compiler.
17515  IX is used as the base pointer, HL and IY are used as a temporary registers,
17516  and BC and DE are available for holding variables.
17517  Return values
17518 \begin_inset LatexCommand \index{Z80!return value}
17519
17520 \end_inset 
17521
17522  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
17523  bytes).
17524  The gbz80 port use the same set of registers for the return values, but
17525  in a different order of significance: E (one byte), DE (two bytes), or
17526  HLDE (four bytes).
17527 \layout Section
17528
17529 The HC08 port
17530 \layout Standard
17531 \added_space_bottom bigskip 
17532 The port to the Motorola HC08
17533 \begin_inset LatexCommand \index{HC08}
17534
17535 \end_inset 
17536
17537  family has been added in October 2003, and is still undergoing some basic
17538  development.
17539  The code generator is complete, but the register allocation is still quite
17540  unoptimized.
17541  Some of the SDCC's standard C library functions have embedded non-HC08
17542  inline assembly and so are not yet usable.
17543 \layout Section
17544 \pagebreak_top 
17545 The PIC14 port
17546 \layout Standard
17547
17548 The 14bit PIC
17549 \begin_inset LatexCommand \index{PIC14}
17550
17551 \end_inset 
17552
17553  port still requires a major effort from the development community.
17554  However it can work for very simple code.
17555 \layout Subsection
17556
17557 C code and 14bit PIC code page
17558 \begin_inset LatexCommand \index{code page (pic14)}
17559
17560 \end_inset 
17561
17562  and RAM banks
17563 \begin_inset LatexCommand \index{RAM bank (pic14)}
17564
17565 \end_inset 
17566
17567
17568 \layout Standard
17569
17570 The linker organizes allocation for the code page and RAM banks.
17571  It does not have intimate knowledge of the code flow.
17572  It will put all the code section of a single asm file into a single code
17573  page.
17574  In order to make use of multiple code pages, separate asm files must be
17575  used.
17576  The compiler treats all functions of a single C file as being in the same
17577  code page unless it is non static.
17578  The compiler treats all local variables of a single C file as being in
17579  the same RAM bank unless it is an extern.
17580 \newline 
17581
17582 \newline 
17583 To get the best follow these guide lines:
17584 \layout Enumerate
17585
17586 make local functions static, as non static functions require code page selection
17587  overhead.
17588 \layout Enumerate
17589
17590 Make local variables static as extern variables require RAM bank selection
17591  overhead.
17592 \layout Enumerate
17593
17594 For devices that have multiple code pages it is more efficient to use the
17595  same number of files as pages, i.e.
17596  for the 16F877 use 4 separate files and i.e.
17597  for the 16F874 use 2 separate files.
17598  This way the linker can put the code for each file into different code
17599  pages and the compiler can allocate reusable variables more efficiently
17600  and there's less page selection overhead.
17601  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17602  instruction set) use 'unsigned char' whereever possible instead of 'int'.
17603 \layout Subsection
17604
17605 Creating a device include file 
17606 \layout Standard
17607
17608 For generating a device include file
17609 \begin_inset LatexCommand \index{PIC14!Header files}
17610
17611 \end_inset 
17612
17613  use the support perl script inc2h.pl kept in directory support/script.
17614 \layout Subsection
17615
17616 Interrupt code
17617 \layout Standard
17618
17619 For the interrupt function, use the keyword 'interrupt'
17620 \begin_inset LatexCommand \index{PIC14!interrupt}
17621
17622 \end_inset 
17623
17624  with level number of 0 (PIC14 only has 1 interrupt so this number is only
17625  there to avoid a syntax error - it ought to be fixed).
17626  E.g.:
17627 \layout Verse
17628
17629
17630 \family typewriter 
17631 void Intr(void) interrupt 0
17632 \newline 
17633 {
17634 \newline 
17635 \SpecialChar ~
17636 \SpecialChar ~
17637 T0IF = 0; /* Clear timer interrupt */
17638 \newline 
17639 }
17640 \layout Subsection
17641
17642 Linking and assembling
17643 \layout Standard
17644
17645 For assembling you can use either GPUTILS'
17646 \begin_inset LatexCommand \index{gputils (pic tools)}
17647
17648 \end_inset 
17649
17650  gpasm.exe or MPLAB's mpasmwin.exe.
17651  GPUTILS is available from 
17652 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17653
17654 \end_inset 
17655
17656 .
17657  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17658  If you use MPLAB and an interrupt function then the linker script file
17659  vectors section will need to be enlarged to link with mplink.
17660 \newline 
17661
17662 \newline 
17663 Here is a 
17664 \family typewriter 
17665 Makefile
17666 \family default 
17667  using GPUTILS:
17668 \layout Verse
17669
17670
17671 \family typewriter 
17672 .c.o:
17673 \newline 
17674 \SpecialChar ~
17675 \SpecialChar ~
17676 \SpecialChar ~
17677 \SpecialChar ~
17678 \SpecialChar ~
17679 \SpecialChar ~
17680 \SpecialChar ~
17681 \SpecialChar ~
17682 sdcc -S -V -mpic14 -p16F877 $< 
17683 \newline 
17684 \SpecialChar ~
17685 \SpecialChar ~
17686 \SpecialChar ~
17687 \SpecialChar ~
17688 \SpecialChar ~
17689 \SpecialChar ~
17690 \SpecialChar ~
17691 \SpecialChar ~
17692 gpasm -c $*.asm
17693 \newline 
17694
17695 \newline 
17696 $(PRJ).hex: $(OBJS) 
17697 \newline 
17698 \SpecialChar ~
17699 \SpecialChar ~
17700 \SpecialChar ~
17701 \SpecialChar ~
17702 \SpecialChar ~
17703 \SpecialChar ~
17704 \SpecialChar ~
17705 \SpecialChar ~
17706 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
17707 \layout Standard
17708
17709 Here is a 
17710 \family typewriter 
17711 Makefile
17712 \family default 
17713  using MPLAB:
17714 \layout Verse
17715
17716
17717 \family typewriter 
17718 .c.o: 
17719 \newline 
17720 \SpecialChar ~
17721 \SpecialChar ~
17722 \SpecialChar ~
17723 \SpecialChar ~
17724 \SpecialChar ~
17725 \SpecialChar ~
17726 \SpecialChar ~
17727 \SpecialChar ~
17728 sdcc -S -V -mpic14 -p16F877 $< 
17729 \newline 
17730 \SpecialChar ~
17731 \SpecialChar ~
17732 \SpecialChar ~
17733 \SpecialChar ~
17734 \SpecialChar ~
17735 \SpecialChar ~
17736 \SpecialChar ~
17737 \SpecialChar ~
17738 mpasmwin /q /o $*.asm
17739 \newline 
17740
17741 \newline 
17742 $(PRJ).hex: $(OBJS) 
17743 \newline 
17744 \SpecialChar ~
17745 \SpecialChar ~
17746 \SpecialChar ~
17747 \SpecialChar ~
17748 \SpecialChar ~
17749 \SpecialChar ~
17750 \SpecialChar ~
17751 \SpecialChar ~
17752 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17753 \layout Standard
17754
17755 Please note that indentations within a
17756 \family typewriter 
17757  Makefile
17758 \family default 
17759  have to be done with a tabulator character.
17760 \layout Subsection
17761
17762 Command-line options
17763 \layout Standard
17764
17765 Besides the switches common to all SDCC backends, the PIC14 port accepts
17766  the following options (for an updated list see sdcc -
17767 \begin_inset ERT
17768 status Collapsed
17769
17770 \layout Standard
17771
17772 \backslash 
17773 /
17774 \end_inset 
17775
17776 -help):
17777 \layout List
17778 \labelwidthstring 00.00.0000
17779
17780 -
17781 \begin_inset ERT
17782 status Collapsed
17783
17784 \layout Standard
17785
17786 \backslash 
17787 /
17788 \end_inset 
17789
17790 -debug-extra
17791 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
17792
17793 \end_inset 
17794
17795  emit debug info in assembly output
17796 \layout List
17797 \labelwidthstring 00.00.0000
17798
17799 -
17800 \begin_inset ERT
17801 status Collapsed
17802
17803 \layout Standard
17804
17805 \backslash 
17806 /
17807 \end_inset 
17808
17809 -no-pcode-opt
17810 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
17811
17812 \end_inset 
17813
17814  disable (slightly faulty) optimization on pCode
17815 \layout Subsection
17816
17817 The library
17818 \layout Subsubsection
17819
17820 error: missing definition for symbol 
17821 \begin_inset Quotes sld
17822 \end_inset 
17823
17824 __gptrget1
17825 \begin_inset Quotes srd
17826 \end_inset 
17827
17828
17829 \layout Standard
17830
17831 The PIC14 port uses library routines to provide more complex operations
17832  like multiplication, division/modulus and (generic) pointer dereferencing.
17833  In order to add these routines to your project, you must link with PIC14's
17834  
17835 \family typewriter 
17836 libsdcc.lib
17837 \family default 
17838 .
17839  For single source file projects this is done automatically, more complex
17840  projects must add 
17841 \family typewriter 
17842 libsdcc.lib
17843 \family default 
17844  to the linker's arguments.
17845  Make sure you also add an include path for the library (using the -I switch
17846  to the linker)!
17847 \layout Subsubsection
17848
17849 Processor mismatch in file 
17850 \begin_inset Quotes sld
17851 \end_inset 
17852
17853 XXX
17854 \begin_inset Quotes srd
17855 \end_inset 
17856
17857 .
17858 \layout Standard
17859
17860 This warning can usually be ignored due to the very good compatibility amongst
17861  14 bit PIC
17862 \begin_inset LatexCommand \index{PIC14}
17863
17864 \end_inset 
17865
17866  devices.
17867 \layout Standard
17868
17869 You might also consider recompiling the library for your specific device
17870  by changing the ARCH=p16f877 (default target) entry in 
17871 \family typewriter 
17872 device/lib/pic/Makefile.in
17873 \family default 
17874  and 
17875 \family typewriter 
17876 device/lib/pic/Makefile
17877 \family default 
17878  to reflect your device.
17879  This might even improve performance for smaller devices as unneccesary
17880  BANKSELs migth be removed.
17881 \layout Subsection
17882
17883 Known bugs
17884 \layout Subsubsection
17885
17886 initialized data
17887 \layout Standard
17888
17889 Currently, data can only be initialized if it resides in the source file
17890  together with 
17891 \emph on 
17892 main()
17893 \emph default 
17894 .
17895  Data in other source files will silently 
17896 \series bold 
17897 not
17898 \series default 
17899  be initialized.
17900 \family typewriter 
17901 \size footnotesize 
17902
17903 \begin_inset Marginal
17904 collapsed true
17905
17906 \layout Standard
17907
17908
17909 \series bold 
17910 \SpecialChar ~
17911 !
17912 \end_inset 
17913
17914
17915 \layout Section
17916 \pagebreak_top 
17917 The PIC16
17918 \begin_inset LatexCommand \index{PIC16}
17919
17920 \end_inset 
17921
17922  port
17923 \layout Standard
17924
17925 The PIC16
17926 \begin_inset LatexCommand \index{PIC16}
17927
17928 \end_inset 
17929
17930  port is the portion of SDCC that is responsible to produce code for the
17931  Microchip
17932 \begin_inset LatexCommand \index{Microchip}
17933
17934 \end_inset 
17935
17936 (TM) microcontrollers with 16 bit core.
17937  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
17938  Currently supported devices are:
17939 \layout Standard
17940 \align center 
17941
17942 \begin_inset  Tabular
17943 <lyxtabular version="3" rows="4" columns="6">
17944 <features>
17945 <column alignment="center" valignment="top" leftline="true" width="0">
17946 <column alignment="center" valignment="top" leftline="true" width="0">
17947 <column alignment="center" valignment="top" leftline="true" width="0">
17948 <column alignment="center" valignment="top" leftline="true" width="0">
17949 <column alignment="center" valignment="top" leftline="true" width="0">
17950 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17951 <row topline="true">
17952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17953 \begin_inset Text
17954
17955 \layout Standard
17956
17957 18F242
17958 \end_inset 
17959 </cell>
17960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17961 \begin_inset Text
17962
17963 \layout Standard
17964
17965 18F248
17966 \end_inset 
17967 </cell>
17968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17969 \begin_inset Text
17970
17971 \layout Standard
17972
17973 18F252
17974 \end_inset 
17975 </cell>
17976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17977 \begin_inset Text
17978
17979 \layout Standard
17980
17981 18F258
17982 \end_inset 
17983 </cell>
17984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17985 \begin_inset Text
17986
17987 \layout Standard
17988
17989 18F442
17990 \end_inset 
17991 </cell>
17992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17993 \begin_inset Text
17994
17995 \layout Standard
17996
17997 18F448
17998 \end_inset 
17999 </cell>
18000 </row>
18001 <row topline="true">
18002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18003 \begin_inset Text
18004
18005 \layout Standard
18006
18007 18F452
18008 \end_inset 
18009 </cell>
18010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18011 \begin_inset Text
18012
18013 \layout Standard
18014
18015 18F458
18016 \end_inset 
18017 </cell>
18018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18019 \begin_inset Text
18020
18021 \layout Standard
18022
18023 18F1220
18024 \end_inset 
18025 </cell>
18026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18027 \begin_inset Text
18028
18029 \layout Standard
18030
18031 18F2220
18032 \end_inset 
18033 </cell>
18034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18035 \begin_inset Text
18036
18037 \layout Standard
18038
18039 18F2550
18040 \end_inset 
18041 </cell>
18042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18043 \begin_inset Text
18044
18045 \layout Standard
18046
18047 18F4331
18048 \end_inset 
18049 </cell>
18050 </row>
18051 <row topline="true">
18052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18053 \begin_inset Text
18054
18055 \layout Standard
18056
18057 18F4455
18058 \end_inset 
18059 </cell>
18060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18061 \begin_inset Text
18062
18063 \layout Standard
18064
18065 18F6520
18066 \end_inset 
18067 </cell>
18068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18069 \begin_inset Text
18070
18071 \layout Standard
18072
18073 18F6620
18074 \end_inset 
18075 </cell>
18076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18077 \begin_inset Text
18078
18079 \layout Standard
18080
18081 18F6680
18082 \end_inset 
18083 </cell>
18084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18085 \begin_inset Text
18086
18087 \layout Standard
18088
18089 18F6720
18090 \end_inset 
18091 </cell>
18092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18093 \begin_inset Text
18094
18095 \layout Standard
18096
18097 18F8520
18098 \end_inset 
18099 </cell>
18100 </row>
18101 <row topline="true" bottomline="true">
18102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18103 \begin_inset Text
18104
18105 \layout Standard
18106
18107 18F8620
18108 \end_inset 
18109 </cell>
18110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18111 \begin_inset Text
18112
18113 \layout Standard
18114
18115 18F8680
18116 \end_inset 
18117 </cell>
18118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18119 \begin_inset Text
18120
18121 \layout Standard
18122
18123 18F8720
18124 \end_inset 
18125 </cell>
18126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18127 \begin_inset Text
18128
18129 \layout Standard
18130
18131 \end_inset 
18132 </cell>
18133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18134 \begin_inset Text
18135
18136 \layout Standard
18137
18138 \end_inset 
18139 </cell>
18140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18141 \begin_inset Text
18142
18143 \layout Standard
18144
18145 \end_inset 
18146 </cell>
18147 </row>
18148 </lyxtabular>
18149
18150 \end_inset 
18151
18152
18153 \layout Subsection
18154
18155 Global Options
18156 \layout Standard
18157
18158 PIC16 port supports the standard command line arguments as supposed, with
18159  the exception of certain cases that will be mentioned in the following
18160  list:
18161 \layout List
18162 \labelwidthstring 00.00.0000
18163
18164 -
18165 \begin_inset ERT
18166 status Collapsed
18167
18168 \layout Standard
18169
18170 \backslash 
18171 /
18172 \end_inset 
18173
18174 -callee-saves
18175 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
18176
18177 \end_inset 
18178
18179  See -
18180 \begin_inset ERT
18181 status Collapsed
18182
18183 \layout Standard
18184
18185 \backslash 
18186 /
18187 \end_inset 
18188
18189 -all-callee-saves
18190 \layout List
18191 \labelwidthstring 00.00.0000
18192
18193 -
18194 \begin_inset ERT
18195 status Collapsed
18196
18197 \layout Standard
18198
18199 \backslash 
18200 /
18201 \end_inset 
18202
18203 -all-callee-saves
18204 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
18205
18206 \end_inset 
18207
18208  All function arguments are passed on stack by default.
18209  
18210 \emph on 
18211 There is no need to specify this in the command line.
18212 \layout List
18213 \labelwidthstring 00.00.0000
18214
18215 -
18216 \begin_inset ERT
18217 status Collapsed
18218
18219 \layout Standard
18220
18221 \backslash 
18222 /
18223 \end_inset 
18224
18225 -fommit-frame-pointer
18226 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
18227
18228 \end_inset 
18229
18230  Frame pointer will be omitted when the function uses no local variables.
18231 \layout Subsection
18232
18233 Port Specific Options
18234 \begin_inset LatexCommand \index{Options PIC16}
18235
18236 \end_inset 
18237
18238
18239 \layout Standard
18240
18241 The port specific options appear after the global options in the sdcc --help
18242  output.
18243 \layout Subsubsection
18244
18245 General Options
18246 \layout Standard
18247
18248 General options enable certain port features and optimizations.
18249 \layout List
18250 \labelwidthstring 00.00.0000
18251
18252 -
18253 \begin_inset ERT
18254 status Collapsed
18255
18256 \layout Standard
18257
18258 \backslash 
18259 /
18260 \end_inset 
18261
18262 -stack-model=[model] Used in conjuction with the command above.
18263  Defines the stack model to be used, valid stack models are : 
18264 \begin_deeper 
18265 \layout List
18266 \labelwidthstring 00.00.0000
18267
18268
18269 \emph on 
18270 small
18271 \emph default 
18272  Selects small stack model.
18273  8 bit stack and frame pointers.
18274  Supports 256 bytes stack size.
18275 \layout List
18276 \labelwidthstring 00.00.0000
18277
18278
18279 \emph on 
18280 large
18281 \emph default 
18282  Selects large stack model.
18283  16 bit stack and frame pointers.
18284  Supports 65536 bytes stack size.
18285 \end_deeper 
18286 \layout List
18287 \labelwidthstring 00.00.0000
18288
18289 -
18290 \begin_inset ERT
18291 status Collapsed
18292
18293 \layout Standard
18294
18295 \backslash 
18296 /
18297 \end_inset 
18298
18299 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
18300  unitialized data variables with [kword].
18301  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
18302 \layout List
18303 \labelwidthstring 00.00.0000
18304
18305 -
18306 \begin_inset ERT
18307 status Collapsed
18308
18309 \layout Standard
18310
18311 \backslash 
18312 /
18313 \end_inset 
18314
18315 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
18316  Useful for bootloaders.
18317 \layout List
18318 \labelwidthstring 00.00.0000
18319
18320 -
18321 \begin_inset ERT
18322 status Collapsed
18323
18324 \layout Standard
18325
18326 \backslash 
18327 /
18328 \end_inset 
18329
18330 -asm= sets the full path and name of an external assembler to call.
18331 \layout List
18332 \labelwidthstring 00.00.0000
18333
18334 -
18335 \begin_inset ERT
18336 status Collapsed
18337
18338 \layout Standard
18339
18340 \backslash 
18341 /
18342 \end_inset 
18343
18344 -link= sets the full path and name of an external linker to call.
18345 \layout List
18346 \labelwidthstring 00.00.0000
18347
18348 -
18349 \begin_inset ERT
18350 status Collapsed
18351
18352 \layout Standard
18353
18354 \backslash 
18355 /
18356 \end_inset 
18357
18358 -mplab-comp MPLAB
18359 \begin_inset LatexCommand \index{PIC16!MPLAB}
18360
18361 \end_inset 
18362
18363  compatibility option.
18364  Currently only suppresses special gpasm directives.
18365 \layout Subsubsection
18366
18367 Optimization Options
18368 \layout List
18369 \labelwidthstring 00.00.0000
18370
18371 -
18372 \begin_inset ERT
18373 status Collapsed
18374
18375 \layout Standard
18376
18377 \backslash 
18378 /
18379 \end_inset 
18380
18381 -optimize-goto Try to use (conditional) BRA instead of GOTO
18382 \layout List
18383 \labelwidthstring 00.00.0000
18384
18385 -
18386 \begin_inset ERT
18387 status Collapsed
18388
18389 \layout Standard
18390
18391 \backslash 
18392 /
18393 \end_inset 
18394
18395 -optimize-cmp Try to optimize some compares.
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 -optimize-df Analyze the dataflow of the generated code and improve it.
18410 \layout List
18411 \labelwidthstring 00.00.0000
18412
18413 -
18414 \begin_inset ERT
18415 status Collapsed
18416
18417 \layout Standard
18418
18419 \backslash 
18420 /
18421 \end_inset 
18422
18423 -obanksel=nn Set optimization level for inserting BANKSELs.
18424 \newline 
18425
18426 \begin_deeper 
18427 \layout List
18428 \labelwidthstring 00.00.0000
18429
18430 0 no optimization
18431 \layout List
18432 \labelwidthstring 00.00.0000
18433
18434 1 checks previous used register and if it is the same then does not emit
18435  BANKSEL, accounts only for labels.
18436 \layout List
18437 \labelwidthstring 00.00.0000
18438
18439 2 tries to check the location of (even different) symbols and removes BANKSELs
18440  if they are in the same bank.
18441  
18442 \newline 
18443
18444 \emph on 
18445 Important: There might be problems if the linker script has data sections
18446  across bank borders!
18447 \end_deeper 
18448 \layout Subsubsection
18449
18450 Linking Options
18451 \layout List
18452 \labelwidthstring 00.00.0000
18453
18454 -
18455 \begin_inset ERT
18456 status Collapsed
18457
18458 \layout Standard
18459
18460 \backslash 
18461 /
18462 \end_inset 
18463
18464 -nodefaultlibs do not link default libraries when linking
18465 \layout List
18466 \labelwidthstring 00.00.0000
18467
18468 -
18469 \begin_inset ERT
18470 status Collapsed
18471
18472 \layout Standard
18473
18474 \backslash 
18475 /
18476 \end_inset 
18477
18478 -no-crt Don't link the default run-time modules
18479 \layout List
18480 \labelwidthstring 00.00.0000
18481
18482 -
18483 \begin_inset ERT
18484 status Collapsed
18485
18486 \layout Standard
18487
18488 \backslash 
18489 /
18490 \end_inset 
18491
18492 -use-crt= Use a custom run-time module instead of the defaults.
18493 \layout Subsubsection
18494
18495 Debugging Options
18496 \layout Standard
18497
18498 Debugging options enable extra debugging information in the output files.
18499 \layout List
18500 \labelwidthstring 00.00.0000
18501
18502 -
18503 \begin_inset ERT
18504 status Collapsed
18505
18506 \layout Standard
18507
18508 \backslash 
18509 /
18510 \end_inset 
18511
18512 -debug-xtra Similar to -
18513 \begin_inset ERT
18514 status Collapsed
18515
18516 \layout Standard
18517
18518 \backslash 
18519 /
18520 \end_inset 
18521
18522 -debug
18523 \begin_inset LatexCommand \index{-\/-debug}
18524
18525 \end_inset 
18526
18527 , but dumps more information.
18528 \layout List
18529 \labelwidthstring 00.00.0000
18530
18531 -
18532 \begin_inset ERT
18533 status Collapsed
18534
18535 \layout Standard
18536
18537 \backslash 
18538 /
18539 \end_inset 
18540
18541 -debug-ralloc Force register allocator to dump <source>.d file with debugging
18542  information.
18543  <source> is the name of the file compiled.
18544 \layout List
18545 \labelwidthstring 00.00.0000
18546
18547 -
18548 \begin_inset ERT
18549 status Collapsed
18550
18551 \layout Standard
18552
18553 \backslash 
18554 /
18555 \end_inset 
18556
18557 -pcode-verbose Enable pcode debugging information in translation.
18558 \layout List
18559 \labelwidthstring 00.00.0000
18560
18561 -
18562 \begin_inset ERT
18563 status Collapsed
18564
18565 \layout Standard
18566
18567 \backslash 
18568 /
18569 \end_inset 
18570
18571 -denable-peeps Force the usage of peepholes.
18572  Use with care.
18573 \layout List
18574 \labelwidthstring 00.00.0000
18575
18576 -
18577 \begin_inset ERT
18578 status Collapsed
18579
18580 \layout Standard
18581
18582 \backslash 
18583 /
18584 \end_inset 
18585
18586 -gstack Trace push/pops for stack pointer overflow
18587 \layout List
18588 \labelwidthstring 00.00.0000
18589
18590 -
18591 \begin_inset ERT
18592 status Collapsed
18593
18594 \layout Standard
18595
18596 \backslash 
18597 /
18598 \end_inset 
18599
18600 -call-tree dump call tree in .calltree file
18601 \layout Subsection
18602
18603 Enviromental Variables
18604 \layout Standard
18605
18606 There is a number of enviromental variables that can be used when running
18607  SDCC to enable certain optimizations or force a specific program behaviour.
18608  these variables are primarily for debugging purposes so they can be enabled/dis
18609 abled at will.
18610 \layout Standard
18611
18612 Currently there is only two such variables available:
18613 \layout List
18614 \labelwidthstring 00.00.0000
18615
18616 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18617  bitfields is optimized by directly loading FSR0 with the address of the
18618  bitfield structure.
18619  Normally SDCC will cast the bitfield structure to a bitfield pointer and
18620  then load FSR0.
18621  This step saves data ram and code space for functions that perform heavy
18622  use of bitfields.
18623  (ie.
18624  80 bytes of code space are saved when compiling malloc.c with this option).
18625  
18626 \layout List
18627 \labelwidthstring 00.00.0000
18628
18629 NO_REG_OPT do not perform pCode registers optimization.
18630  This should be used for debugging purposes.
18631  In some where bugs in the pcode optimizer are found, users can benefit
18632  from temporarily disabling the optimizer until the bug is fixed.
18633 \layout Subsection
18634
18635 Preprocessor Macros
18636 \layout Standard
18637
18638 PIC16
18639 \begin_inset LatexCommand \index{PIC16}
18640
18641 \end_inset 
18642
18643  port defines the following preprocessor macros while translating a source.
18644 \layout Standard
18645 \align center 
18646
18647 \begin_inset  Tabular
18648 <lyxtabular version="3" rows="6" columns="2">
18649 <features>
18650 <column alignment="center" valignment="top" leftline="true" width="0">
18651 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18652 <row topline="true" bottomline="true">
18653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18654 \begin_inset Text
18655
18656 \layout Standard
18657
18658 Macro
18659 \end_inset 
18660 </cell>
18661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18662 \begin_inset Text
18663
18664 \layout Standard
18665
18666 Description
18667 \end_inset 
18668 </cell>
18669 </row>
18670 <row topline="true">
18671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18672 \begin_inset Text
18673
18674 \layout Standard
18675
18676 SDCC_pic16
18677 \end_inset 
18678 </cell>
18679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18680 \begin_inset Text
18681
18682 \layout Standard
18683
18684 Port identification
18685 \end_inset 
18686 </cell>
18687 </row>
18688 <row topline="true">
18689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18690 \begin_inset Text
18691
18692 \layout Standard
18693
18694 _
18695 \begin_inset ERT
18696 status Collapsed
18697
18698 \layout Standard
18699
18700 \backslash 
18701 /
18702 \end_inset 
18703
18704 _pic16
18705 \end_inset 
18706 </cell>
18707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18708 \begin_inset Text
18709
18710 \layout Standard
18711
18712 Port identification (same as above)
18713 \end_inset 
18714 </cell>
18715 </row>
18716 <row topline="true">
18717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18718 \begin_inset Text
18719
18720 \layout Standard
18721
18722 pic18fxxxx
18723 \end_inset 
18724 </cell>
18725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18726 \begin_inset Text
18727
18728 \layout Standard
18729
18730 MCU Identification.
18731  
18732 \emph on 
18733 xxxx
18734 \emph default 
18735  is the microcontrol identification number, i.e.
18736  452, 6620, etc
18737 \end_inset 
18738 </cell>
18739 </row>
18740 <row topline="true">
18741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18742 \begin_inset Text
18743
18744 \layout Standard
18745
18746 _
18747 \begin_inset ERT
18748 status Collapsed
18749
18750 \layout Standard
18751
18752 \backslash 
18753 /
18754 \end_inset 
18755
18756 _18Fxxxx
18757 \end_inset 
18758 </cell>
18759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18760 \begin_inset Text
18761
18762 \layout Standard
18763
18764 MCU Identification (same as above)
18765 \end_inset 
18766 </cell>
18767 </row>
18768 <row topline="true" bottomline="true">
18769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18770 \begin_inset Text
18771
18772 \layout Standard
18773
18774 STACK_MODEL_nnn
18775 \end_inset 
18776 </cell>
18777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18778 \begin_inset Text
18779
18780 \layout Standard
18781
18782 nnn = SMALL or LARGE respectively according to the stack model used
18783 \end_inset 
18784 </cell>
18785 </row>
18786 </lyxtabular>
18787
18788 \end_inset 
18789
18790
18791 \layout Standard
18792
18793 In addition the following macros are defined when calling assembler:
18794 \layout Standard
18795 \align center 
18796
18797 \begin_inset  Tabular
18798 <lyxtabular version="3" rows="4" columns="2">
18799 <features>
18800 <column alignment="center" valignment="top" leftline="true" width="0">
18801 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18802 <row topline="true" bottomline="true">
18803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18804 \begin_inset Text
18805
18806 \layout Standard
18807
18808 Macro
18809 \end_inset 
18810 </cell>
18811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18812 \begin_inset Text
18813
18814 \layout Standard
18815
18816 Description
18817 \end_inset 
18818 </cell>
18819 </row>
18820 <row topline="true">
18821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18822 \begin_inset Text
18823
18824 \layout Standard
18825
18826 __18Fxxxx
18827 \end_inset 
18828 </cell>
18829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18830 \begin_inset Text
18831
18832 \layout Standard
18833
18834 MCU Identification.
18835  
18836 \emph on 
18837 xxxx
18838 \emph default 
18839  is the microcontrol identification number, i.e.
18840  452, 6620, etc
18841 \end_inset 
18842 </cell>
18843 </row>
18844 <row topline="true">
18845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18846 \begin_inset Text
18847
18848 \layout Standard
18849
18850 SDCC_MODEL_nnn
18851 \end_inset 
18852 </cell>
18853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18854 \begin_inset Text
18855
18856 \layout Standard
18857
18858 nnn = SMALL or LARGE respectively according to the memory model used for
18859  SDCC
18860 \end_inset 
18861 </cell>
18862 </row>
18863 <row topline="true" bottomline="true">
18864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18865 \begin_inset Text
18866
18867 \layout Standard
18868
18869 STACK_MODEL_nnn
18870 \end_inset 
18871 </cell>
18872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18873 \begin_inset Text
18874
18875 \layout Standard
18876
18877 nnn = SMALL or LARGE respectively according to the stack model used
18878 \end_inset 
18879 </cell>
18880 </row>
18881 </lyxtabular>
18882
18883 \end_inset 
18884
18885
18886 \layout Subsection
18887
18888 Directories
18889 \layout Standard
18890
18891 PIC16
18892 \begin_inset LatexCommand \index{PIC16}
18893
18894 \end_inset 
18895
18896  port uses the following directories for searching header files and libraries.
18897 \layout Standard
18898 \align center 
18899
18900 \begin_inset  Tabular
18901 <lyxtabular version="3" rows="3" columns="4">
18902 <features>
18903 <column alignment="center" valignment="top" leftline="true" width="0">
18904 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18905 <column alignment="center" valignment="top" width="0">
18906 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18907 <row topline="true" bottomline="true">
18908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18909 \begin_inset Text
18910
18911 \layout Standard
18912
18913 Directory
18914 \end_inset 
18915 </cell>
18916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18917 \begin_inset Text
18918
18919 \layout Standard
18920
18921 Description
18922 \end_inset 
18923 </cell>
18924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18925 \begin_inset Text
18926
18927 \layout Standard
18928
18929 Target
18930 \end_inset 
18931 </cell>
18932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18933 \begin_inset Text
18934
18935 \layout Standard
18936
18937 Command prefix
18938 \end_inset 
18939 </cell>
18940 </row>
18941 <row topline="true">
18942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18943 \begin_inset Text
18944
18945 \layout Standard
18946
18947 PREFIX/sdcc/include/pic16
18948 \end_inset 
18949 </cell>
18950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18951 \begin_inset Text
18952
18953 \layout Standard
18954
18955 PIC16 specific headers
18956 \end_inset 
18957 </cell>
18958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18959 \begin_inset Text
18960
18961 \layout Standard
18962
18963 Compiler
18964 \end_inset 
18965 </cell>
18966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18967 \begin_inset Text
18968
18969 \layout Standard
18970
18971 -I
18972 \end_inset 
18973 </cell>
18974 </row>
18975 <row topline="true" bottomline="true">
18976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18977 \begin_inset Text
18978
18979 \layout Standard
18980
18981 PREFIX/sdcc/lib/pic16
18982 \end_inset 
18983 </cell>
18984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18985 \begin_inset Text
18986
18987 \layout Standard
18988
18989 PIC16 specific libraries
18990 \end_inset 
18991 </cell>
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18993 \begin_inset Text
18994
18995 \layout Standard
18996
18997 Linker
18998 \end_inset 
18999 </cell>
19000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19001 \begin_inset Text
19002
19003 \layout Standard
19004
19005 -L
19006 \end_inset 
19007 </cell>
19008 </row>
19009 </lyxtabular>
19010
19011 \end_inset 
19012
19013
19014 \layout Subsection
19015
19016 Pragmas
19017 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
19018
19019 \end_inset 
19020
19021
19022 \layout Standard
19023
19024 PIC16
19025 \begin_inset LatexCommand \index{PIC16}
19026
19027 \end_inset 
19028
19029  port currently supports the following pragmas:
19030 \layout List
19031 \labelwidthstring 00.00.0000
19032
19033 stack
19034 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
19035
19036 \end_inset 
19037
19038  pragma stack
19039 \begin_inset LatexCommand \index{PIC16!stack}
19040
19041 \end_inset 
19042
19043  forces the code generator to initialize the stack & frame pointers at a
19044  specific address.
19045  This is an adhoc solution for cases where no STACK directive is available
19046  in the linker script or gplink is not instructed to create a stack section.
19047 \newline 
19048 The stack pragma should be used only once in a project.
19049  Multiple pragmas may result in indeterminate behaviour of the program.
19050 \begin_inset Foot
19051 collapsed false
19052
19053 \layout Standard
19054
19055 The old format (ie.
19056  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
19057  cross page boundaries (or even exceed the available data RAM) and crash
19058  the program.
19059  Make sure that stack does not cross page boundaries when using the SMALL
19060  stack model.
19061 \end_inset 
19062
19063
19064 \newline 
19065 The format is as follows:
19066 \layout LyX-Code
19067
19068 #pragma stack bottom_address [stack_size]
19069 \layout Standard
19070
19071
19072 \emph on 
19073 bottom_address
19074 \emph default 
19075  is the lower bound of the stack section.
19076  The stack pointer initially will point at address (bottom_address+stack_size-1).
19077 \layout LyX-Code
19078
19079 Example:
19080 \layout LyX-Code
19081
19082 \layout LyX-Code
19083
19084 /* initializes stack of 100 bytes at RAM address 0x200 */
19085 \layout LyX-Code
19086
19087 #pragma stack 0x200 100
19088 \layout Standard
19089
19090 If the stack_size field is omitted then a stack is created with the default
19091  size of 64.
19092  This size might be enough for most programs, but its not enough for operations
19093  with deep function nesting or excessive stack usage.
19094 \layout List
19095 \labelwidthstring 00.00.0000
19096
19097 wparam 
19098 \emph on 
19099 This pragma is deprecated.
19100  Its use will cause a warning message to be issued.
19101 \emph default 
19102
19103 \newline 
19104
19105 \layout List
19106 \labelwidthstring 00.00.0000
19107
19108 code
19109 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
19110
19111 \end_inset 
19112
19113  place a function symbol at static FLASH address
19114 \layout LyX-Code
19115
19116 Example:
19117 \layout LyX-Code
19118
19119 \layout LyX-Code
19120
19121 /* place function test_func at 0x4000 */
19122 \layout LyX-Code
19123
19124 #pragma code test_func 0x4000
19125 \layout LyX-Code
19126
19127 \layout List
19128 \labelwidthstring 00.00.0000
19129
19130 library instructs the linker to use a library module.
19131 \newline 
19132 Usage:
19133 \layout LyX-Code
19134
19135 #pragma library module_name
19136 \layout Standard
19137
19138
19139 \emph on 
19140 module_name
19141 \emph default 
19142  can be any library or object file (including its path).
19143  Note that there are four reserved keywords which have special meaning.
19144  These are:
19145 \layout Standard
19146 \align center 
19147
19148 \begin_inset  Tabular
19149 <lyxtabular version="3" rows="6" columns="3">
19150 <features>
19151 <column alignment="center" valignment="top" leftline="true" width="0">
19152 <column alignment="block" valignment="top" leftline="true" width="20page%">
19153 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19154 <row topline="true" bottomline="true">
19155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19156 \begin_inset Text
19157
19158 \layout Standard
19159
19160 Keyword
19161 \end_inset 
19162 </cell>
19163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19164 \begin_inset Text
19165
19166 \layout Standard
19167
19168 Description
19169 \end_inset 
19170 </cell>
19171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19172 \begin_inset Text
19173
19174 \layout Standard
19175
19176 Module to link
19177 \end_inset 
19178 </cell>
19179 </row>
19180 <row topline="true">
19181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19182 \begin_inset Text
19183
19184 \layout Standard
19185
19186
19187 \series bold 
19188 ignore
19189 \end_inset 
19190 </cell>
19191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19192 \begin_inset Text
19193
19194 \layout Standard
19195
19196 ignore all library pragmas
19197 \end_inset 
19198 </cell>
19199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19200 \begin_inset Text
19201
19202 \layout Standard
19203
19204
19205 \emph on 
19206 (none)
19207 \end_inset 
19208 </cell>
19209 </row>
19210 <row topline="true">
19211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19212 \begin_inset Text
19213
19214 \layout Standard
19215
19216
19217 \series bold 
19218 c
19219 \end_inset 
19220 </cell>
19221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19222 \begin_inset Text
19223
19224 \layout Standard
19225
19226 link the C library
19227 \end_inset 
19228 </cell>
19229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19230 \begin_inset Text
19231
19232 \layout Standard
19233
19234
19235 \emph on 
19236 libc18f
19237 \emph default 
19238 .lib
19239 \end_inset 
19240 </cell>
19241 </row>
19242 <row topline="true">
19243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19244 \begin_inset Text
19245
19246 \layout Standard
19247
19248
19249 \series bold 
19250 math
19251 \end_inset 
19252 </cell>
19253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19254 \begin_inset Text
19255
19256 \layout Standard
19257
19258 link the Math libarary
19259 \end_inset 
19260 </cell>
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19262 \begin_inset Text
19263
19264 \layout Standard
19265
19266
19267 \emph on 
19268 libm18f
19269 \emph default 
19270 .lib
19271 \end_inset 
19272 </cell>
19273 </row>
19274 <row topline="true">
19275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19276 \begin_inset Text
19277
19278 \layout Standard
19279
19280
19281 \series bold 
19282 io
19283 \end_inset 
19284 </cell>
19285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19286 \begin_inset Text
19287
19288 \layout Standard
19289
19290 link the I/O library
19291 \end_inset 
19292 </cell>
19293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19294 \begin_inset Text
19295
19296 \layout Standard
19297
19298
19299 \emph on 
19300 libio18f*
19301 \emph default 
19302 .lib
19303 \end_inset 
19304 </cell>
19305 </row>
19306 <row topline="true" bottomline="true">
19307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19308 \begin_inset Text
19309
19310 \layout Standard
19311
19312
19313 \series bold 
19314 debug
19315 \end_inset 
19316 </cell>
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19318 \begin_inset Text
19319
19320 \layout Standard
19321
19322 link the debug library
19323 \end_inset 
19324 </cell>
19325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19326 \begin_inset Text
19327
19328 \layout Standard
19329
19330
19331 \emph on 
19332 libdebug
19333 \emph default 
19334 .lib
19335 \end_inset 
19336 </cell>
19337 </row>
19338 </lyxtabular>
19339
19340 \end_inset 
19341
19342
19343 \newline 
19344 * is the device number, i.e.
19345  452 for PIC18F452 MCU.
19346 \layout Standard
19347
19348 This feature allows for linking with specific libraries withoug having to
19349  explicit name them in the command line.
19350  Note that the 
19351 \noun on 
19352 ignore
19353 \noun default 
19354  keyword will reject all modules specified by the library pragma.
19355 \layout List
19356 \labelwidthstring 00.00.0000
19357
19358 udata pragma udata instructs the compiler to emit code so that linker will
19359  place a variable at a specific memory bank
19360 \layout LyX-Code
19361
19362 Example:
19363 \layout LyX-Code
19364
19365 \layout LyX-Code
19366
19367 /* places variable foo at bank2 */
19368 \layout LyX-Code
19369
19370 #pragma udata bank2 foo
19371 \layout LyX-Code
19372
19373 char foo;
19374 \layout Standard
19375
19376 In order for this pragma to work extra SECTION directives should be added
19377  in the .lkr script.
19378  In the following example a sample .lkr file is shown:
19379 \layout LyX-Code
19380
19381 \layout LyX-Code
19382
19383 // Sample linker script for the PIC18F452 processor
19384 \layout LyX-Code
19385
19386 LIBPATH .
19387 \layout LyX-Code
19388
19389 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
19390 \layout LyX-Code
19391
19392 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
19393 \layout LyX-Code
19394
19395 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
19396 \layout LyX-Code
19397
19398 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
19399 \layout LyX-Code
19400
19401 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
19402 \layout LyX-Code
19403
19404 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
19405 \layout LyX-Code
19406
19407 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
19408 \layout LyX-Code
19409
19410 \layout LyX-Code
19411
19412 DATABANK   NAME=gpr0       START=0x80           END=0xFF
19413 \layout LyX-Code
19414
19415 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
19416 \layout LyX-Code
19417
19418 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
19419 \layout LyX-Code
19420
19421 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
19422 \layout LyX-Code
19423
19424 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
19425 \layout LyX-Code
19426
19427 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
19428 \layout LyX-Code
19429
19430 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
19431 \layout LyX-Code
19432
19433 \layout LyX-Code
19434
19435 SECTION    NAME=CONFIG     ROM=config
19436 \layout LyX-Code
19437
19438 \layout LyX-Code
19439
19440 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
19441 \layout LyX-Code
19442
19443 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
19444 \layout LyX-Code
19445
19446 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
19447 \layout LyX-Code
19448
19449 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
19450 \layout LyX-Code
19451
19452 SECTION    NAME=bank4      RAM=gpr4
19453 \layout LyX-Code
19454
19455 SECTION    NAME=bank5      RAM=gpr5
19456 \layout Standard
19457
19458 The linker will recognise the section name set in the pragma statement and
19459  will position the variable at the memory bank set with the RAM field at
19460  the SECTION line in the linker script file.
19461 \layout Subsection
19462
19463 Header Files
19464 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19465
19466 \end_inset 
19467
19468
19469 \layout Standard
19470
19471 There is one main header file
19472 \begin_inset LatexCommand \index{PIC16!Header files}
19473
19474 \end_inset 
19475
19476  that can be included to the source files using the pic16
19477 \begin_inset LatexCommand \index{PIC16}
19478
19479 \end_inset 
19480
19481  port.
19482  That file is the 
19483 \series bold 
19484 pic18fregs.h
19485 \series default 
19486 .
19487  This header file contains the definitions for the processor special registers,
19488  so it is necessary if the source accesses them.
19489  It can be included by adding the following line in the beginning of the
19490  file:
19491 \layout LyX-Code
19492
19493 #include <pic18fregs.h>
19494 \layout Standard
19495
19496 The specific microcontroller is selected within the pic18fregs.h automatically,
19497  so the same source can be used with a variety of devices.
19498 \layout Subsection
19499
19500 Libraries
19501 \layout Standard
19502
19503 The libraries
19504 \begin_inset LatexCommand \index{PIC16!Libraries}
19505
19506 \end_inset 
19507
19508  that PIC16
19509 \begin_inset LatexCommand \index{PIC16}
19510
19511 \end_inset 
19512
19513  port depends on are the microcontroller device libraries which contain
19514  the symbol definitions for the microcontroller special function registers.
19515  These libraries have the format pic18fxxxx.lib, where 
19516 \emph on 
19517 xxxx
19518 \emph default 
19519  is the microcontroller identification number.
19520  The specific library is selected automatically by the compiler at link
19521  stage according to the selected device.
19522 \layout Standard
19523
19524 Libraries are created with gplib which is part of the gputils package 
19525 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19526
19527 \end_inset 
19528
19529 .
19530 \layout Subsubsection*
19531
19532 Building the libraries
19533 \layout Standard
19534
19535 Before using SDCC/pic16 there are some libraries that need to be compiled.
19536  This process is not done automatically by SDCC since not all users use
19537  SDCC for pic16 projects.
19538  So each user should compile the libraries separately.
19539 \layout Standard
19540
19541 The steps to compile the pic16 libraries under Linux are:
19542 \layout LyX-Code
19543
19544 cd device/lib/pic16
19545 \layout LyX-Code
19546
19547 ./configure
19548 \layout LyX-Code
19549
19550 make
19551 \layout LyX-Code
19552
19553 cd ..
19554 \layout LyX-Code
19555
19556 make model-pic16
19557 \layout LyX-Code
19558
19559 su -c 'make install'     # install the libraries, you need the root password
19560 \layout Standard
19561
19562 If you need to install the headers too, do:
19563 \layout LyX-Code
19564
19565 cd device/include
19566 \layout LyX-Code
19567
19568 su -c 'make install'     # install the headers, you need the root password
19569 \layout Standard
19570
19571 There exist a special target to build the I/O libraries.
19572  This target is not automatically build because it will build the I/O library
19573  for 
19574 \emph on 
19575 every
19576 \emph default 
19577  supported device.
19578  This way building will take quite a lot of time.
19579  Users are advised to edit the 
19580 \series bold 
19581 device/lib/pic16/pics.build
19582 \series default 
19583  file and then execute:
19584 \layout LyX-Code
19585
19586 make lib-io
19587 \layout Subsection
19588
19589 Memory Models
19590 \layout Standard
19591
19592 The following memory models are supported by the PIC16 port:
19593 \layout Itemize
19594
19595 small model
19596 \layout Itemize
19597
19598 large model
19599 \layout Standard
19600
19601 Memory model affects the default size of pointers within the source.
19602  The sizes are shown in the next table:
19603 \layout Standard
19604 \align center 
19605
19606 \begin_inset  Tabular
19607 <lyxtabular version="3" rows="3" columns="3">
19608 <features>
19609 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19610 <column alignment="center" valignment="top" leftline="true" width="0">
19611 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19612 <row topline="true" bottomline="true">
19613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19614 \begin_inset Text
19615
19616 \layout Standard
19617
19618 Pointer sizes according to memory model
19619 \end_inset 
19620 </cell>
19621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19622 \begin_inset Text
19623
19624 \layout Standard
19625
19626 small model
19627 \end_inset 
19628 </cell>
19629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19630 \begin_inset Text
19631
19632 \layout Standard
19633
19634 large model
19635 \end_inset 
19636 </cell>
19637 </row>
19638 <row topline="true" bottomline="true">
19639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19640 \begin_inset Text
19641
19642 \layout Standard
19643
19644 code pointers
19645 \end_inset 
19646 </cell>
19647 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19648 \begin_inset Text
19649
19650 \layout Standard
19651
19652 16-bits
19653 \end_inset 
19654 </cell>
19655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19656 \begin_inset Text
19657
19658 \layout Standard
19659
19660 24-bits
19661 \end_inset 
19662 </cell>
19663 </row>
19664 <row topline="true" bottomline="true">
19665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19666 \begin_inset Text
19667
19668 \layout Standard
19669
19670 data pointers
19671 \end_inset 
19672 </cell>
19673 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
19674 \begin_inset Text
19675
19676 \layout Standard
19677
19678 16-bits
19679 \end_inset 
19680 </cell>
19681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19682 \begin_inset Text
19683
19684 \layout Standard
19685
19686 16-bits
19687 \end_inset 
19688 </cell>
19689 </row>
19690 </lyxtabular>
19691
19692 \end_inset 
19693
19694
19695 \layout Standard
19696
19697 It is advisable that all sources within a project are compiled with the
19698  same memory model.
19699  If one wants to override the default memory model, this can be done by
19700  declaring a pointer as 
19701 \series bold 
19702 far
19703 \series default 
19704  or 
19705 \series bold 
19706 near
19707 \series default 
19708 .
19709  Far selects large memory model's pointers, while near selects small memory
19710  model's pointers.
19711 \layout Standard
19712
19713 The standard device libraries (see 
19714 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
19715
19716 \end_inset 
19717
19718 ) contain no reference to pointers, so they can be used with both memory
19719  models.
19720 \layout Subsection
19721
19722 Stack
19723 \layout Standard
19724
19725 The stack
19726 \begin_inset LatexCommand \index{PIC16!stack}
19727
19728 \end_inset 
19729
19730  implementation for the PIC16 port uses two indirect registers, FSR1 and
19731  FSR2.
19732 \layout List
19733 \labelwidthstring 00.00.0000
19734
19735 FSR1 is assigned as stack pointer
19736 \layout List
19737 \labelwidthstring 00.00.0000
19738
19739 FSR2 is assigned as frame pointer
19740 \layout Standard
19741
19742 The following stack models are supported by the PIC16 port
19743 \layout Itemize
19744
19745
19746 \noun on 
19747 small
19748 \noun default 
19749  model
19750 \layout Itemize
19751
19752
19753 \noun on 
19754 large
19755 \noun default 
19756  model
19757 \layout Standard
19758
19759
19760 \noun on 
19761 Small
19762 \noun default 
19763  model means that only the FSRxL byte is used to access stack and frame,
19764  while 
19765 \emph on 
19766 \noun on 
19767 large
19768 \emph default 
19769 \noun default 
19770  uses both FSRxL and FSRxH registers.
19771  The following table shows the stack/frame pointers sizes according to stack
19772  model and the maximum space they can address:
19773 \layout Standard
19774 \align center 
19775
19776 \begin_inset  Tabular
19777 <lyxtabular version="3" rows="3" columns="3">
19778 <features>
19779 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19780 <column alignment="center" valignment="top" leftline="true" width="0">
19781 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19782 <row topline="true" bottomline="true">
19783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19784 \begin_inset Text
19785
19786 \layout Standard
19787
19788 Stack & Frame pointer sizes according to stack model
19789 \end_inset 
19790 </cell>
19791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19792 \begin_inset Text
19793
19794 \layout Standard
19795
19796 small
19797 \end_inset 
19798 </cell>
19799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19800 \begin_inset Text
19801
19802 \layout Standard
19803
19804 large
19805 \end_inset 
19806 </cell>
19807 </row>
19808 <row topline="true">
19809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19810 \begin_inset Text
19811
19812 \layout Standard
19813
19814 Stack pointer FSR1
19815 \end_inset 
19816 </cell>
19817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19818 \begin_inset Text
19819
19820 \layout Standard
19821
19822 8-bits
19823 \end_inset 
19824 </cell>
19825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19826 \begin_inset Text
19827
19828 \layout Standard
19829
19830 16-bits
19831 \end_inset 
19832 </cell>
19833 </row>
19834 <row topline="true" bottomline="true">
19835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19836 \begin_inset Text
19837
19838 \layout Standard
19839
19840 Frame pointer FSR2
19841 \end_inset 
19842 </cell>
19843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19844 \begin_inset Text
19845
19846 \layout Standard
19847
19848 8-bits
19849 \end_inset 
19850 </cell>
19851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19852 \begin_inset Text
19853
19854 \layout Standard
19855
19856 16-bits
19857 \end_inset 
19858 </cell>
19859 </row>
19860 </lyxtabular>
19861
19862 \end_inset 
19863
19864
19865 \layout Standard
19866
19867
19868 \noun on 
19869 Large 
19870 \noun default 
19871 stack model is currently not working properly throughout the code generator.
19872  So its use is not advised.
19873  Also there are some other points that need special care:
19874 \newline 
19875
19876 \layout Enumerate
19877
19878 Do not create stack sections with size more than one physical bank (that
19879  is 256 bytes)
19880 \layout Enumerate
19881
19882 Stack sections should no cross physical bank limits (i.e.
19883  #pragma stack 0x50 0x100)
19884 \layout Standard
19885
19886 These limitations are caused by the fact that only FSRxL is modified when
19887  using SMALL stack model, so no more than 256 bytes of stack can be used.
19888  This problem will disappear after LARGE model is fully implemented.
19889 \layout Subsection
19890
19891 Functions
19892 \layout Standard
19893
19894 In addition to the standard SDCC function keywords, PIC16
19895 \begin_inset LatexCommand \index{PIC16}
19896
19897 \end_inset 
19898
19899  port makes available two more:
19900 \layout List
19901 \labelwidthstring 00.00.0000
19902
19903 wparam
19904 \begin_inset LatexCommand \index{PIC16!wparam}
19905
19906 \end_inset 
19907
19908  Use the WREG to pass one byte of the first function argument.
19909  This improves speed but you may not use this for functions with arguments
19910  that are called via function pointers, otherwise the first byte of the
19911  first parameter will get lost.
19912  Usage:
19913 \layout LyX-Code
19914
19915 void func_wparam(int a) wparam
19916 \layout LyX-Code
19917
19918 {
19919 \layout LyX-Code
19920
19921     /* WREG hold the lower part of a */
19922 \layout LyX-Code
19923
19924     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
19925  */
19926 \layout LyX-Code
19927
19928 ...
19929 \layout LyX-Code
19930
19931 }
19932 \layout Standard
19933
19934 This keyword replaces the deprecated wparam pragma.
19935 \layout List
19936 \labelwidthstring 00.00.0000
19937
19938 shadowregs
19939 \begin_inset LatexCommand \index{PIC16!shadowregs}
19940
19941 \end_inset 
19942
19943  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
19944  hardware shadow registers which hold the values of WREG, STATUS and BSR
19945  registers.
19946  This can be done by adding the keyword 
19947 \emph on 
19948 shadowregs
19949 \emph default 
19950  before the 
19951 \emph on 
19952 interrupt
19953 \emph default 
19954  keyword in the function's header.
19955 \layout LyX-Code
19956
19957 void isr_shadow(void) shadowregs interrupt 1
19958 \layout LyX-Code
19959
19960 {
19961 \layout LyX-Code
19962
19963 ...
19964 \layout LyX-Code
19965
19966 }
19967 \layout Standard
19968
19969
19970 \emph on 
19971 shadowregs
19972 \emph default 
19973  instructs the code generator not to store/restore WREG, STATUS, BSR when
19974  entering/exiting the ISR.
19975 \layout Subsection
19976
19977 Function return values
19978 \layout Standard
19979
19980 Return values from functions are placed to the appropriate registers following
19981  a modified Microchip policy optimized for SDCC.
19982  The following table shows these registers:
19983 \layout Standard
19984 \align center 
19985
19986 \begin_inset  Tabular
19987 <lyxtabular version="3" rows="6" columns="2">
19988 <features>
19989 <column alignment="center" valignment="top" leftline="true" width="0">
19990 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19991 <row topline="true" bottomline="true">
19992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19993 \begin_inset Text
19994
19995 \layout Standard
19996
19997 size
19998 \end_inset 
19999 </cell>
20000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20001 \begin_inset Text
20002
20003 \layout Standard
20004
20005 destination register
20006 \end_inset 
20007 </cell>
20008 </row>
20009 <row topline="true">
20010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20011 \begin_inset Text
20012
20013 \layout Standard
20014
20015 8 bits
20016 \end_inset 
20017 </cell>
20018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20019 \begin_inset Text
20020
20021 \layout Standard
20022
20023 WREG
20024 \end_inset 
20025 </cell>
20026 </row>
20027 <row topline="true">
20028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20029 \begin_inset Text
20030
20031 \layout Standard
20032
20033 16 bits
20034 \end_inset 
20035 </cell>
20036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20037 \begin_inset Text
20038
20039 \layout Standard
20040
20041 PRODL:WREG
20042 \end_inset 
20043 </cell>
20044 </row>
20045 <row topline="true">
20046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20047 \begin_inset Text
20048
20049 \layout Standard
20050
20051 24 bits
20052 \end_inset 
20053 </cell>
20054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20055 \begin_inset Text
20056
20057 \layout Standard
20058
20059 PRODH:PRODL:WREG
20060 \end_inset 
20061 </cell>
20062 </row>
20063 <row topline="true">
20064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20065 \begin_inset Text
20066
20067 \layout Standard
20068
20069 32 bits
20070 \end_inset 
20071 </cell>
20072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20073 \begin_inset Text
20074
20075 \layout Standard
20076
20077 FSR0L:PRODH:PRODL:WREG
20078 \end_inset 
20079 </cell>
20080 </row>
20081 <row topline="true" bottomline="true">
20082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20083 \begin_inset Text
20084
20085 \layout Standard
20086
20087 >32 bits
20088 \end_inset 
20089 </cell>
20090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20091 \begin_inset Text
20092
20093 \layout Standard
20094
20095 on stack, FSR0 points to the beginning
20096 \end_inset 
20097 </cell>
20098 </row>
20099 </lyxtabular>
20100
20101 \end_inset 
20102
20103
20104 \layout Subsection
20105
20106 Interrupts
20107 \layout Standard
20108
20109 An interrupt
20110 \begin_inset LatexCommand \index{PIC16!interrupt}
20111
20112 \end_inset 
20113
20114  service routine (ISR) is declared using the 
20115 \emph on 
20116 interrupt
20117 \emph default 
20118  keyword.
20119 \layout LyX-Code
20120
20121 void isr(void) interrupt 
20122 \emph on 
20123 n
20124 \layout LyX-Code
20125
20126 {
20127 \layout LyX-Code
20128
20129 ...
20130 \layout LyX-Code
20131
20132 }
20133 \layout Standard
20134
20135
20136 \emph on 
20137 n
20138 \emph default 
20139  is the interrupt number, which for PIC18F devices can be:
20140 \layout Standard
20141 \align center 
20142
20143 \begin_inset  Tabular
20144 <lyxtabular version="3" rows="4" columns="3">
20145 <features>
20146 <column alignment="center" valignment="top" leftline="true" width="0">
20147 <column alignment="center" valignment="top" leftline="true" width="0">
20148 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20149 <row topline="true" bottomline="true">
20150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20151 \begin_inset Text
20152
20153 \layout Standard
20154
20155
20156 \emph on 
20157 n
20158 \end_inset 
20159 </cell>
20160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20161 \begin_inset Text
20162
20163 \layout Standard
20164
20165 Interrupt Vector
20166 \end_inset 
20167 </cell>
20168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20169 \begin_inset Text
20170
20171 \layout Standard
20172
20173 Interrupt Vector Address
20174 \end_inset 
20175 </cell>
20176 </row>
20177 <row topline="true">
20178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20179 \begin_inset Text
20180
20181 \layout Standard
20182
20183 0
20184 \end_inset 
20185 </cell>
20186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20187 \begin_inset Text
20188
20189 \layout Standard
20190
20191 RESET vector
20192 \end_inset 
20193 </cell>
20194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20195 \begin_inset Text
20196
20197 \layout Standard
20198
20199 0x000000
20200 \end_inset 
20201 </cell>
20202 </row>
20203 <row topline="true">
20204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20205 \begin_inset Text
20206
20207 \layout Standard
20208
20209
20210 \family roman 
20211 \series medium 
20212 \shape up 
20213 \size normal 
20214 \emph off 
20215 \bar no 
20216 \noun off 
20217 \color none
20218 1
20219 \end_inset 
20220 </cell>
20221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20222 \begin_inset Text
20223
20224 \layout Standard
20225
20226
20227 \family roman 
20228 \series medium 
20229 \shape up 
20230 \size normal 
20231 \emph off 
20232 \bar no 
20233 \noun off 
20234 \color none
20235 HIGH priority interrupts
20236 \end_inset 
20237 </cell>
20238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20239 \begin_inset Text
20240
20241 \layout Standard
20242
20243 0x000008
20244 \end_inset 
20245 </cell>
20246 </row>
20247 <row topline="true" bottomline="true">
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20249 \begin_inset Text
20250
20251 \layout Standard
20252
20253 2
20254 \end_inset 
20255 </cell>
20256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20257 \begin_inset Text
20258
20259 \layout Standard
20260
20261 LOW priority interrupts
20262 \end_inset 
20263 </cell>
20264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20265 \begin_inset Text
20266
20267 \layout Standard
20268
20269 0x000018
20270 \end_inset 
20271 </cell>
20272 </row>
20273 </lyxtabular>
20274
20275 \end_inset 
20276
20277
20278 \layout Standard
20279
20280 When generating assembly code for ISR the code generator places a 
20281 \noun on 
20282 goto 
20283 \noun default 
20284 instruction at the 
20285 \emph on 
20286 Interrupt Vector Address
20287 \emph default 
20288  which points at the genetated ISR.
20289  This single GOTO instruction is part of an automatically generated 
20290 \emph on 
20291 interrupt entry point
20292 \emph default 
20293  function.
20294  The actuall ISR code is placed as normally would in the code space.
20295  Upon interrupt request, the GOTO instruction is executed which jumps to
20296  the ISR code.
20297  When declaring interrupt functions as _naked this GOTO instruction is 
20298 \series bold 
20299 not
20300 \series default 
20301  generated.
20302  The whole interrupt functions is therefore placed at the Interrupt Vector
20303  Address of the specific interrupt.
20304  This is not a problem for the LOW priority interrupts, but it is a problem
20305  for the RESET and the HIGH priority interrupts because code may be written
20306  at the next interrupt´s vector address and cause undeterminate program
20307  behaviour if that interrupt is raised.
20308 \begin_inset Foot
20309 collapsed false
20310
20311 \layout Standard
20312
20313 This is not a problem when
20314 \layout Enumerate
20315
20316 this is a HIGH interrupt ISR and LOW interrupts are 
20317 \emph on 
20318 disabled
20319 \emph default 
20320  or not used.
20321 \layout Enumerate
20322
20323 when the ISR is small enough not to reach the next interrupt´s vector address.
20324 \end_inset 
20325
20326
20327 \layout Standard
20328
20329
20330 \emph on 
20331 n
20332 \emph default 
20333  is possible to be omitted.
20334  This way a function is generated similar to an ISR, but it is not assigned
20335  to any interrupt.
20336 \layout Standard
20337
20338 When entering an interrupt, currently the PIC16
20339 \begin_inset LatexCommand \index{PIC16}
20340
20341 \end_inset 
20342
20343  port automatically saves the following registers:
20344 \layout Itemize
20345
20346 WREG
20347 \layout Itemize
20348
20349 STATUS
20350 \layout Itemize
20351
20352 BSR
20353 \layout Itemize
20354
20355 PROD (PRODL and PRODH)
20356 \layout Itemize
20357
20358 FSR0 (FSR0L and FSR0H)
20359 \layout Standard
20360
20361 These registers are restored upon return from the interrupt routine.
20362 \begin_inset Foot
20363 collapsed false
20364
20365 \layout Standard
20366
20367 NOTE that when the _naked attribute is specified for an interrupt routine,
20368  then NO registers are stored or restored.
20369 \end_inset 
20370
20371
20372 \layout Subsection
20373
20374 Generic Pointers
20375 \layout Standard
20376
20377 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20378  There are 3 types of generic pointers currently implemented data, code
20379  and eeprom pointers.
20380  They are differentiated by the value of the 7th and 6th bits of the upper
20381  byte:
20382 \layout Standard
20383 \align center 
20384
20385 \begin_inset  Tabular
20386 <lyxtabular version="3" rows="5" columns="5">
20387 <features>
20388 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20389 <column alignment="center" valignment="top" width="0">
20390 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20391 <column alignment="center" valignment="top" width="0">
20392 <column alignment="left" valignment="top" rightline="true" width="0">
20393 <row topline="true" bottomline="true">
20394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20395 \begin_inset Text
20396
20397 \layout Standard
20398
20399 pointer type
20400 \end_inset 
20401 </cell>
20402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20403 \begin_inset Text
20404
20405 \layout Standard
20406
20407 7th bit
20408 \end_inset 
20409 </cell>
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20411 \begin_inset Text
20412
20413 \layout Standard
20414
20415 6th bit
20416 \end_inset 
20417 </cell>
20418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20419 \begin_inset Text
20420
20421 \layout Standard
20422
20423 rest of the pointer
20424 \end_inset 
20425 </cell>
20426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20427 \begin_inset Text
20428
20429 \layout Standard
20430
20431 description
20432 \end_inset 
20433 </cell>
20434 </row>
20435 <row topline="true" bottomline="true">
20436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20437 \begin_inset Text
20438
20439 \layout Standard
20440
20441 data 
20442 \end_inset 
20443 </cell>
20444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20445 \begin_inset Text
20446
20447 \layout Standard
20448
20449 1
20450 \end_inset 
20451 </cell>
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20453 \begin_inset Text
20454
20455 \layout Standard
20456
20457 0
20458 \end_inset 
20459 </cell>
20460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20461 \begin_inset Text
20462
20463 \layout Standard
20464
20465
20466 \family typewriter 
20467 \shape slanted 
20468 \emph on 
20469 uuuuuu uuuuxxxx xxxxxxxx
20470 \end_inset 
20471 </cell>
20472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20473 \begin_inset Text
20474
20475 \layout Standard
20476
20477 a 12-bit data pointer in data RAM memory
20478 \end_inset 
20479 </cell>
20480 </row>
20481 <row bottomline="true">
20482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20483 \begin_inset Text
20484
20485 \layout Standard
20486
20487 code
20488 \end_inset 
20489 </cell>
20490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20491 \begin_inset Text
20492
20493 \layout Standard
20494
20495 0
20496 \end_inset 
20497 </cell>
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20499 \begin_inset Text
20500
20501 \layout Standard
20502
20503 0
20504 \end_inset 
20505 </cell>
20506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20507 \begin_inset Text
20508
20509 \layout Standard
20510
20511
20512 \family typewriter 
20513 \shape slanted 
20514 \emph on 
20515 uxxxxx xxxxxxxx xxxxxxxx
20516 \end_inset 
20517 </cell>
20518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20519 \begin_inset Text
20520
20521 \layout Standard
20522
20523 a 21-bit code pointer in FLASH memory
20524 \end_inset 
20525 </cell>
20526 </row>
20527 <row bottomline="true">
20528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20529 \begin_inset Text
20530
20531 \layout Standard
20532
20533 eeprom
20534 \end_inset 
20535 </cell>
20536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20537 \begin_inset Text
20538
20539 \layout Standard
20540
20541 0
20542 \end_inset 
20543 </cell>
20544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20545 \begin_inset Text
20546
20547 \layout Standard
20548
20549 1
20550 \end_inset 
20551 </cell>
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20553 \begin_inset Text
20554
20555 \layout Standard
20556
20557
20558 \family typewriter 
20559 \shape slanted 
20560 \emph on 
20561 uuuuuu uuuuuuxx xxxxxxxx
20562 \end_inset 
20563 </cell>
20564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20565 \begin_inset Text
20566
20567 \layout Standard
20568
20569 a 10-bit eeprom pointer in EEPROM memory
20570 \end_inset 
20571 </cell>
20572 </row>
20573 <row bottomline="true">
20574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20575 \begin_inset Text
20576
20577 \layout Standard
20578
20579 (unimplemented)
20580 \end_inset 
20581 </cell>
20582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20583 \begin_inset Text
20584
20585 \layout Standard
20586
20587 1
20588 \end_inset 
20589 </cell>
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20591 \begin_inset Text
20592
20593 \layout Standard
20594
20595 1
20596 \end_inset 
20597 </cell>
20598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20599 \begin_inset Text
20600
20601 \layout Standard
20602
20603
20604 \family typewriter 
20605 \shape slanted 
20606 \emph on 
20607 xxxxxx xxxxxxxx xxxxxxxx
20608 \end_inset 
20609 </cell>
20610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20611 \begin_inset Text
20612
20613 \layout Standard
20614
20615 unimplemented pointer type
20616 \end_inset 
20617 </cell>
20618 </row>
20619 </lyxtabular>
20620
20621 \end_inset 
20622
20623
20624 \layout Standard
20625
20626 Generic pointer are read and written with a set of library functions which
20627  read/write 1, 2, 3, 4 bytes.
20628 \layout Subsection
20629
20630 PIC16 C Libraries
20631 \layout Subsubsection
20632
20633 Standard I/O Streams
20634 \layout Standard
20635
20636 In the 
20637 \emph on 
20638 stdio.h
20639 \emph default 
20640  the type FILE is defined as:
20641 \layout LyX-Code
20642
20643 typedef char * FILE;
20644 \layout Standard
20645
20646 This type is the stream type implemented I/O in the PIC18F devices.
20647  Also the standard input and output streams are declared in stdio.h:
20648 \layout LyX-Code
20649
20650 extern FILE * stdin;
20651 \layout LyX-Code
20652
20653 extern FILE * stdout;
20654 \layout Standard
20655
20656 The FILE type is actually a generic pointer which defines one more type
20657  of generic pointers, the 
20658 \emph on 
20659 stream 
20660 \emph default 
20661 pointer.
20662  This new type has the format:
20663 \layout Standard
20664 \align center 
20665
20666 \begin_inset  Tabular
20667 <lyxtabular version="3" rows="2" columns="7">
20668 <features>
20669 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20670 <column alignment="center" valignment="top" width="0">
20671 <column alignment="center" valignment="top" leftline="true" width="0">
20672 <column alignment="center" valignment="top" leftline="true" width="0">
20673 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20674 <column alignment="center" valignment="top" width="0">
20675 <column alignment="left" valignment="top" rightline="true" width="0">
20676 <row topline="true" bottomline="true">
20677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20678 \begin_inset Text
20679
20680 \layout Standard
20681
20682 pointer type
20683 \end_inset 
20684 </cell>
20685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20686 \begin_inset Text
20687
20688 \layout Standard
20689
20690 <7:6>
20691 \end_inset 
20692 </cell>
20693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20694 \begin_inset Text
20695
20696 \layout Standard
20697
20698 <5>
20699 \end_inset 
20700 </cell>
20701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20702 \begin_inset Text
20703
20704 \layout Standard
20705
20706 <4>
20707 \end_inset 
20708 </cell>
20709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20710 \begin_inset Text
20711
20712 \layout Standard
20713
20714 <3:0>
20715 \end_inset 
20716 </cell>
20717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20718 \begin_inset Text
20719
20720 \layout Standard
20721
20722 rest of the pointer
20723 \end_inset 
20724 </cell>
20725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20726 \begin_inset Text
20727
20728 \layout Standard
20729
20730 descrption
20731 \end_inset 
20732 </cell>
20733 </row>
20734 <row topline="true" bottomline="true">
20735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20736 \begin_inset Text
20737
20738 \layout Standard
20739
20740 stream
20741 \end_inset 
20742 </cell>
20743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20744 \begin_inset Text
20745
20746 \layout Standard
20747
20748 00
20749 \end_inset 
20750 </cell>
20751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20752 \begin_inset Text
20753
20754 \layout Standard
20755
20756 1
20757 \end_inset 
20758 </cell>
20759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20760 \begin_inset Text
20761
20762 \layout Standard
20763
20764 0
20765 \end_inset 
20766 </cell>
20767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20768 \begin_inset Text
20769
20770 \layout Standard
20771
20772 nnnn
20773 \end_inset 
20774 </cell>
20775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20776 \begin_inset Text
20777
20778 \layout Standard
20779
20780
20781 \family typewriter 
20782 \shape slanted 
20783 \emph on 
20784 uuuuuuuu uuuuuuuu
20785 \end_inset 
20786 </cell>
20787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20788 \begin_inset Text
20789
20790 \layout Standard
20791
20792 upper byte high nubble is 0x2n, the rest are zeroes
20793 \end_inset 
20794 </cell>
20795 </row>
20796 </lyxtabular>
20797
20798 \end_inset 
20799
20800
20801 \layout Standard
20802
20803 Currently implemented there are 3 types of streams defined:
20804 \layout Standard
20805 \align center 
20806
20807 \begin_inset  Tabular
20808 <lyxtabular version="3" rows="4" columns="4">
20809 <features>
20810 <column alignment="center" valignment="top" leftline="true" width="0">
20811 <column alignment="center" valignment="top" leftline="true" width="0">
20812 <column alignment="center" valignment="top" leftline="true" width="0">
20813 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20814 <row topline="true" bottomline="true">
20815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20816 \begin_inset Text
20817
20818 \layout Standard
20819
20820 stream type
20821 \end_inset 
20822 </cell>
20823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20824 \begin_inset Text
20825
20826 \layout Standard
20827
20828 value
20829 \end_inset 
20830 </cell>
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20832 \begin_inset Text
20833
20834 \layout Standard
20835
20836 module
20837 \end_inset 
20838 </cell>
20839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20840 \begin_inset Text
20841
20842 \layout Standard
20843
20844 description
20845 \end_inset 
20846 </cell>
20847 </row>
20848 <row topline="true">
20849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20850 \begin_inset Text
20851
20852 \layout Standard
20853
20854 STREAM_USART
20855 \end_inset 
20856 </cell>
20857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20858 \begin_inset Text
20859
20860 \layout Standard
20861
20862
20863 \family typewriter 
20864 0x200000UL
20865 \end_inset 
20866 </cell>
20867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20868 \begin_inset Text
20869
20870 \layout Standard
20871
20872 USART
20873 \end_inset 
20874 </cell>
20875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20876 \begin_inset Text
20877
20878 \layout Standard
20879
20880 Writes/Reads characters via the USART peripheral
20881 \end_inset 
20882 </cell>
20883 </row>
20884 <row topline="true">
20885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20886 \begin_inset Text
20887
20888 \layout Standard
20889
20890 STREAM_MSSP
20891 \end_inset 
20892 </cell>
20893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20894 \begin_inset Text
20895
20896 \layout Standard
20897
20898
20899 \family typewriter 
20900 0x210000UL
20901 \end_inset 
20902 </cell>
20903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20904 \begin_inset Text
20905
20906 \layout Standard
20907
20908 MSSP
20909 \end_inset 
20910 </cell>
20911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20912 \begin_inset Text
20913
20914 \layout Standard
20915
20916 Writes/Reads characters via the MSSP peripheral
20917 \end_inset 
20918 </cell>
20919 </row>
20920 <row topline="true" bottomline="true">
20921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20922 \begin_inset Text
20923
20924 \layout Standard
20925
20926 STREAM_USER
20927 \end_inset 
20928 </cell>
20929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20930 \begin_inset Text
20931
20932 \layout Standard
20933
20934
20935 \family typewriter 
20936 0x2f0000UL
20937 \end_inset 
20938 </cell>
20939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20940 \begin_inset Text
20941
20942 \layout Standard
20943
20944 (none)
20945 \end_inset 
20946 </cell>
20947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20948 \begin_inset Text
20949
20950 \layout Standard
20951
20952 Writes/Reads characters via used defined functions
20953 \end_inset 
20954 </cell>
20955 </row>
20956 </lyxtabular>
20957
20958 \end_inset 
20959
20960
20961 \layout Standard
20962
20963 The stream identifiers are declared as macros in the stdio.h header.
20964 \layout Standard
20965
20966 In the libc library there exist the functions that are used to write to
20967  each of the above streams.
20968  These are
20969 \layout List
20970 \labelwidthstring 00.00.0000
20971
20972 _
20973 \begin_inset ERT
20974 status Collapsed
20975
20976 \layout Standard
20977
20978 \backslash 
20979 /
20980 \end_inset 
20981
20982 _stream_usart_putchar writes a character at the USART stream
20983 \layout List
20984 \labelwidthstring 00.00.0000
20985
20986 _
20987 \begin_inset ERT
20988 status Collapsed
20989
20990 \layout Standard
20991
20992 \backslash 
20993 /
20994 \end_inset 
20995
20996 _stream_mssp_putchar writes a character at the MSSP stream
20997 \layout List
20998 \labelwidthstring 00.00.0000
20999
21000 putchar dummy function.
21001  This writes a character to a user specified manner.
21002 \layout Standard
21003
21004 In order to increase performance 
21005 \emph on 
21006 putchar 
21007 \emph default 
21008 is declared in stdio.h as having its parameter in WREG (it has the wparam
21009  keyword).
21010  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
21011  in a user-friendly way.
21012  
21013 \emph on 
21014 arg
21015 \emph default 
21016  is the name of the variable that holds the character to print.
21017  An example follows:
21018 \layout LyX-Code
21019
21020 #include <pic18fregs.h>
21021 \newline 
21022 #include <stdio.h>
21023 \newline 
21024
21025 \newline 
21026 PUTCHAR( c )
21027 \layout LyX-Code
21028
21029 {
21030 \layout LyX-Code
21031
21032     PORTA = c;    /* dump character c to PORTA */
21033 \layout LyX-Code
21034
21035
21036 \newline 
21037
21038 \newline 
21039 void main(void)
21040 \layout LyX-Code
21041
21042 {
21043 \layout LyX-Code
21044
21045     stdout = STREAM_USER;    /* this is not necessary, since stdout points
21046 \layout LyX-Code
21047
21048                               * by default to STREAM_USER */
21049 \layout LyX-Code
21050
21051     printf (¨This is a printf test
21052 \backslash 
21053 n¨);
21054 \layout LyX-Code
21055
21056 }
21057 \layout LyX-Code
21058
21059 \layout Subsubsection
21060
21061 Printing functions
21062 \layout Standard
21063
21064 PIC16 contains an implementation of the printf-family of functions.
21065  There exist the following functions:
21066 \layout LyX-Code
21067
21068 extern unsigned int sprintf(char *buf, char *fmt, ...);
21069 \layout LyX-Code
21070
21071 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
21072 \layout LyX-Code
21073
21074 \layout LyX-Code
21075
21076 extern unsigned int printf(char *fmt, ...);
21077 \layout LyX-Code
21078
21079 extern unsigned int vprintf(char *fmt, va_lista ap);
21080 \layout LyX-Code
21081
21082 \layout LyX-Code
21083
21084 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
21085 \layout LyX-Code
21086
21087 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
21088 \layout Standard
21089
21090 For sprintf and vsprintf 
21091 \emph on 
21092 buf 
21093 \emph default 
21094 should normally be a data pointer where the resulting string will be placed.
21095  No range checking is done so the user should allocate the necessery buffer.
21096  For fprintf and vfprintf 
21097 \emph on 
21098 fp
21099 \emph default 
21100  should be a stream pointer (i.e.
21101  stdout, STREAM_MSSP, etc...).
21102 \layout Subsubsection
21103
21104 Signals
21105 \layout Standard
21106
21107 The PIC18F family of microcontrollers supports a number of interrupt sources.
21108  A list of these interrupts is shown in the following table:
21109 \layout Standard
21110 \align center 
21111
21112 \begin_inset  Tabular
21113 <lyxtabular version="3" rows="11" columns="4">
21114 <features>
21115 <column alignment="left" valignment="top" leftline="true" width="0">
21116 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21117 <column alignment="left" valignment="top" leftline="true" width="0">
21118 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21119 <row topline="true" bottomline="true">
21120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21121 \begin_inset Text
21122
21123 \layout Standard
21124
21125 signal name
21126 \end_inset 
21127 </cell>
21128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21129 \begin_inset Text
21130
21131 \layout Standard
21132
21133 description
21134 \end_inset 
21135 </cell>
21136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21137 \begin_inset Text
21138
21139 \layout Standard
21140
21141 signal name
21142 \end_inset 
21143 </cell>
21144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21145 \begin_inset Text
21146
21147 \layout Standard
21148
21149 descritpion
21150 \end_inset 
21151 </cell>
21152 </row>
21153 <row topline="true">
21154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21155 \begin_inset Text
21156
21157 \layout Standard
21158
21159 SIG_RB
21160 \end_inset 
21161 </cell>
21162 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21163 \begin_inset Text
21164
21165 \layout Standard
21166
21167 PORTB change interrupt
21168 \end_inset 
21169 </cell>
21170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21171 \begin_inset Text
21172
21173 \layout Standard
21174
21175 SIG_EE
21176 \end_inset 
21177 </cell>
21178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21179 \begin_inset Text
21180
21181 \layout Standard
21182
21183 EEPROM/FLASH write complete interrupt
21184 \end_inset 
21185 </cell>
21186 </row>
21187 <row topline="true">
21188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21189 \begin_inset Text
21190
21191 \layout Standard
21192
21193 SIG_INT0
21194 \end_inset 
21195 </cell>
21196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21197 \begin_inset Text
21198
21199 \layout Standard
21200
21201 INT0 external interrupt
21202 \end_inset 
21203 </cell>
21204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21205 \begin_inset Text
21206
21207 \layout Standard
21208
21209 SIG_BCOL
21210 \end_inset 
21211 </cell>
21212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21213 \begin_inset Text
21214
21215 \layout Standard
21216
21217 Bus collision interrupt
21218 \end_inset 
21219 </cell>
21220 </row>
21221 <row topline="true">
21222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21223 \begin_inset Text
21224
21225 \layout Standard
21226
21227 SIG_INT1
21228 \end_inset 
21229 </cell>
21230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21231 \begin_inset Text
21232
21233 \layout Standard
21234
21235 INT1 external interrupt
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 SIG_LVD
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 Low voltage detect interrupt
21252 \end_inset 
21253 </cell>
21254 </row>
21255 <row topline="true">
21256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21257 \begin_inset Text
21258
21259 \layout Standard
21260
21261 SIG_INT2
21262 \end_inset 
21263 </cell>
21264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21265 \begin_inset Text
21266
21267 \layout Standard
21268
21269 INT2 external interrupt
21270 \end_inset 
21271 </cell>
21272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21273 \begin_inset Text
21274
21275 \layout Standard
21276
21277 SIG_PSP
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 Parallel slave port interrupt
21286 \end_inset 
21287 </cell>
21288 </row>
21289 <row topline="true">
21290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21291 \begin_inset Text
21292
21293 \layout Standard
21294
21295 SIG_CCP1
21296 \end_inset 
21297 </cell>
21298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21299 \begin_inset Text
21300
21301 \layout Standard
21302
21303 CCP1 module interrupt
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 SIG_AD
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 AD convertion complete interrupt
21320 \end_inset 
21321 </cell>
21322 </row>
21323 <row topline="true">
21324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21325 \begin_inset Text
21326
21327 \layout Standard
21328
21329 SIG_CCP2
21330 \end_inset 
21331 </cell>
21332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21333 \begin_inset Text
21334
21335 \layout Standard
21336
21337 CCP2 module interrupt
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 SIG_RC
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 USART receive interrupt
21354 \end_inset 
21355 </cell>
21356 </row>
21357 <row topline="true">
21358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21359 \begin_inset Text
21360
21361 \layout Standard
21362
21363 SIG_TMR0
21364 \end_inset 
21365 </cell>
21366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21367 \begin_inset Text
21368
21369 \layout Standard
21370
21371 TMR0 overflow interrupt
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 SIG_TX
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 USART transmit interrupt
21388 \end_inset 
21389 </cell>
21390 </row>
21391 <row topline="true">
21392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21393 \begin_inset Text
21394
21395 \layout Standard
21396
21397 SIG_TMR1
21398 \end_inset 
21399 </cell>
21400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21401 \begin_inset Text
21402
21403 \layout Standard
21404
21405 TMR1 overflow interrupt
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 SIG_MSSP
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 SSP receive/transmit interrupt
21422 \end_inset 
21423 </cell>
21424 </row>
21425 <row topline="true">
21426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21427 \begin_inset Text
21428
21429 \layout Standard
21430
21431 SIG_TMR2
21432 \end_inset 
21433 </cell>
21434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21435 \begin_inset Text
21436
21437 \layout Standard
21438
21439 TMR2 matches PR2 interrupt
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 \end_inset 
21448 </cell>
21449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21450 \begin_inset Text
21451
21452 \layout Standard
21453
21454 \end_inset 
21455 </cell>
21456 </row>
21457 <row topline="true" bottomline="true">
21458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21459 \begin_inset Text
21460
21461 \layout Standard
21462
21463 SIG_TMR3
21464 \end_inset 
21465 </cell>
21466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21467 \begin_inset Text
21468
21469 \layout Standard
21470
21471 TMR3 overflow interrupt
21472 \end_inset 
21473 </cell>
21474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21475 \begin_inset Text
21476
21477 \layout Standard
21478
21479 \end_inset 
21480 </cell>
21481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21482 \begin_inset Text
21483
21484 \layout Standard
21485
21486 \end_inset 
21487 </cell>
21488 </row>
21489 </lyxtabular>
21490
21491 \end_inset 
21492
21493
21494 \layout Standard
21495
21496 The prototypes for these names are defined in the header file 
21497 \emph on 
21498 signal.h
21499 \emph default 
21500  .
21501 \layout Standard
21502
21503 In order to simplify signal handling, a number of macros is provided:
21504 \layout List
21505 \labelwidthstring 00.00.0000
21506
21507 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21508  high priority interrupts.
21509  
21510 \emph on 
21511 name
21512 \emph default 
21513  is the function name to use.
21514 \layout List
21515 \labelwidthstring 00.00.0000
21516
21517 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21518  low priority interrupt.
21519  
21520 \emph on 
21521 name
21522 \emph default 
21523  is the function name to use.
21524 \layout List
21525 \labelwidthstring 00.00.0000
21526
21527 DEF_HANDLER(sig,handler) define a handler for signal 
21528 \emph on 
21529 sig.
21530 \layout List
21531 \labelwidthstring 00.00.0000
21532
21533 END_DEF end the declaration of the dispatch table.
21534 \layout Standard
21535
21536 Additionally there are two more macros to simplify the declaration of the
21537  signal handler:
21538 \layout List
21539 \labelwidthstring 00.00.0000
21540
21541
21542 \series medium 
21543 SIGHANDLER(handler) 
21544 \series default 
21545 this declares the function prototype for the 
21546 \emph on 
21547 handler
21548 \emph default 
21549  function.
21550 \layout List
21551 \labelwidthstring 00.00.0000
21552
21553 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21554 \layout Standard
21555
21556 An example of using the macros above is shown below:
21557 \layout LyX-Code
21558
21559 #include <pic18fregs.h>
21560 \layout LyX-Code
21561
21562 #include <signal.h>
21563 \newline 
21564
21565 \newline 
21566 DEF_INTHIGH(high_int)
21567 \layout LyX-Code
21568
21569 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21570 \layout LyX-Code
21571
21572 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21573 \layout LyX-Code
21574
21575 END_DEF
21576 \newline 
21577
21578 \newline 
21579 SIGHANDLER(_tmr0_handler)
21580 \layout LyX-Code
21581
21582 {
21583 \layout LyX-Code
21584
21585   /* action to be taken when timer 0 overflows */
21586 \layout LyX-Code
21587
21588 }
21589 \newline 
21590
21591 \newline 
21592 SIGHANDLERNAKED(_bcol_handler)
21593 \layout LyX-Code
21594
21595 {
21596 \layout LyX-Code
21597
21598   _asm
21599 \layout LyX-Code
21600
21601     /* action to be taken when bus collision occurs */
21602 \layout LyX-Code
21603
21604     retfie
21605 \layout LyX-Code
21606
21607  _endasm;
21608 \layout LyX-Code
21609
21610 }
21611 \layout Standard
21612
21613
21614 \series bold 
21615 NOTES:
21616 \series default 
21617  Special care should be taken when using the above scheme:
21618 \layout Itemize
21619
21620 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21621 \layout Itemize
21622
21623 when declaring SIGHANDLERNAKED handler never forget to use 
21624 \emph on 
21625 retfie
21626 \emph default 
21627  for proper returning.
21628 \layout Subsection
21629
21630 PIC16 Port -- Tips
21631 \layout Standard
21632
21633 Here you can find some general tips for compiling programs with SDCC/pic16.
21634 \layout Subsubsection
21635
21636 Stack size
21637 \layout Standard
21638
21639 The default stack
21640 \begin_inset LatexCommand \index{PIC16!stack}
21641
21642 \end_inset 
21643
21644  size (that is 64 bytes) probably is enough for many programs.
21645  One must take care that when there are many levels of function nesting,
21646  or there is excessive usage of stack, its size should be extended.
21647  An example of such a case is the printf/sprintf family of functions.
21648  If you encounter problems like not being able to print integers, then you
21649  need to set the stack size around the maximum (256 for small stack model).
21650  The following diagram shows what happens when calling printf to print an
21651  integer:
21652 \layout LyX-Code
21653
21654 printf () --> ltoa () --> ultoa () --> divschar ()
21655 \layout Standard
21656
21657 It is should be understood that stack is easily consumed when calling complicate
21658 d functions.
21659  Using command line arguments like -
21660 \begin_inset ERT
21661 status Collapsed
21662
21663 \layout Standard
21664
21665 \backslash 
21666 /
21667 \end_inset 
21668
21669 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
21670  stack frames.
21671  Other ways to reduce stack usage may exist.
21672 \layout Chapter
21673
21674 Debugging
21675 \layout Standard
21676
21677 There are several approaches to debugging your code.
21678  This chapter is meant to show your options and to give detail on some of
21679  them:
21680 \newline 
21681
21682 \newline 
21683 When writing your code:
21684 \layout Itemize
21685
21686 write your code with debugging in mind (avoid duplicating code, put conceptually
21687  similar variables into structs, use structured code, have strategic points
21688  within your code where all variables are consistent, ...)
21689 \layout Itemize
21690
21691 run a syntax-checking tool like splint
21692 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21693
21694 \end_inset 
21695
21696
21697 \begin_inset LatexCommand \index{lint (syntax checking tool)}
21698
21699 \end_inset 
21700
21701  (see -
21702 \begin_inset ERT
21703 status Collapsed
21704
21705 \layout Standard
21706
21707 \backslash 
21708 /
21709 \end_inset 
21710
21711 -more-pedantic 
21712 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21713
21714 \end_inset 
21715
21716 ) over the code.
21717 \layout Itemize
21718
21719 for the high level code use a C-compiler (like f.e.
21720  GCC) to compile run and debug the code on your host.
21721  See (see -
21722 \begin_inset ERT
21723 status Collapsed
21724
21725 \layout Standard
21726
21727 \backslash 
21728 /
21729 \end_inset 
21730
21731 -more-pedantic 
21732 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21733
21734 \end_inset 
21735
21736  ) on howto handle syntax extensions like __xdata, __at(), ...
21737  
21738 \layout Itemize
21739
21740 use another C-compiler to compile code for your target.
21741  Always an option but not recommended:) And not very likely to help you.
21742  If you seriously consider walking this path you should at least occasionally
21743  check portability of your code.
21744  Most commercial compiler vendors will offer an evaluation version so you
21745  can test compile your code or snippets of your code.
21746 \layout Standard
21747
21748 Debugging on a simulator:
21749 \layout Itemize
21750
21751 there is a separate section about SDCDB (section 
21752 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
21753
21754 \end_inset 
21755
21756 ) below.
21757 \layout Itemize
21758
21759 or (8051 specific) use a freeware/commercial simulator which interfaces
21760  to the AOMF
21761 \begin_inset LatexCommand \index{AOMF, AOMF51}
21762
21763 \end_inset 
21764
21765  file (see 
21766 \begin_inset LatexCommand \ref{OMF file}
21767
21768 \end_inset 
21769
21770 ) optionally generated by SDCC.
21771 \layout Standard
21772
21773 Debugging On-target: 
21774 \layout Itemize
21775
21776 use a MCU port pin to serially output debug data to the RS232 port of your
21777  host.
21778  You'll probably want some level shifting device typically involving a MAX232
21779  or similar IC.
21780  If the hardware serial port of the MCU is not available search for 'Software
21781  UART' in your favourite search machine.
21782 \layout Itemize
21783
21784 use an on-target monitor.
21785  In this context a monitor is a small program which usually accepts commands
21786  via a serial line and allows to set program counter, to single step through
21787  a program and read/write memory locations.
21788  For the 8051 good examples of monitors are paulmon and cmon51 (see section
21789  
21790 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
21791
21792 \end_inset 
21793
21794 ).
21795 \layout Itemize
21796
21797 toggle MCU port pins at strategic points within your code and use an oscilloscop
21798 e.
21799  A 
21800 \emph on 
21801 digital oscilloscope
21802 \emph default 
21803
21804 \begin_inset LatexCommand \index{Oscilloscope}
21805
21806 \end_inset 
21807
21808  with deep trace memory is really helpful especially if you have to debug
21809  a realtime application.
21810  If you need to monitor more pins than your oscilloscope provides you can
21811  sometimes get away with a small R-2R network.
21812  On a single channel oscilloscope you could f.e.
21813  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
21814 k
21815 \begin_inset Formula $\Omega$
21816 \end_inset 
21817
21818  resistor and the other one by a 5\SpecialChar ~
21819 k
21820 \begin_inset Formula $\Omega$
21821 \end_inset 
21822
21823  resistor to the oscilloscope probe (check output drive capability of the
21824  pins you want to monitor).
21825  If you need to monitor many more pins a 
21826 \emph on 
21827 logic analyzer
21828 \emph default 
21829  will be handy.
21830 \layout Itemize
21831
21832 use an ICE (
21833 \emph on 
21834 i
21835 \emph default 
21836
21837 \emph on 
21838 c
21839 \emph default 
21840 ircuit 
21841 \emph on 
21842 e
21843 \emph default 
21844 mulator
21845 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
21846
21847 \end_inset 
21848
21849 ).
21850  Usually very expensive.
21851  And very nice to have too.
21852  And usually locks you (for years...) to the devices the ICE can emulate.
21853  
21854 \layout Itemize
21855
21856 use a remote debugger.
21857  In most 8-bit systems the symbol information is not available on the target,
21858  and a complete debugger is too bulky for the target system.
21859  Therefore usually a debugger on the host system connects to an on-target
21860  debugging stub which accepts only primitive commands.
21861  
21862 \newline 
21863 Terms to enter into your favourite search engine could be 'remote debugging',
21864  'gdb stub' or 'inferior debugger'.
21865  (is there one?)
21866 \layout Itemize
21867
21868 use an on target hardware debugger.
21869  Some of the more modern MCUs include hardware support for setting break
21870  points and monitoring/changing variables by using dedicated hardware pins.
21871  This facility doesn't require additional code to run on the target and
21872  
21873 \emph on 
21874 usually
21875 \emph default 
21876  doesn't affect runtime behaviour until a breakpoint is hit.
21877  For the mcs51 most hardware debuggers use the AOMF
21878 \begin_inset LatexCommand \index{AOMF, AOMF51}
21879
21880 \end_inset 
21881
21882  file (see 
21883 \begin_inset LatexCommand \ref{OMF file}
21884
21885 \end_inset 
21886
21887 ) as input file.
21888  
21889 \layout Standard
21890
21891 Last not least:
21892 \layout Itemize
21893
21894 if you are not familiar with any of the following terms you're likely to
21895  run into problems rather sooner than later: 
21896 \emph on 
21897 volatile
21898 \emph default 
21899
21900 \emph on 
21901 atomic
21902 \emph default 
21903
21904 \emph on 
21905 memory map
21906 \emph default 
21907
21908 \emph on 
21909 overlay
21910 \emph default 
21911 .
21912  As an embedded programmer you 
21913 \emph on 
21914 have
21915 \emph default 
21916  to know them so why not look them up 
21917 \emph on 
21918 before
21919 \emph default 
21920  you have problems?)
21921 \layout Itemize
21922
21923 tell someone else about your problem (actually this is a surprisingly effective
21924  means to hunt down the bug even if the listener is not familiar with your
21925  environment).
21926  As 'failure to communicate' is probably one of the job-induced deformations
21927  of an embedded programmer this is highly encouraged.
21928 \layout Section
21929
21930 Debugging with SDCDB
21931 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
21932
21933 \end_inset 
21934
21935
21936 \begin_inset LatexCommand \index{SDCDB (debugger)}
21937
21938 \end_inset 
21939
21940  
21941 \layout Standard
21942
21943 SDCC is distributed with a source level debugger
21944 \begin_inset LatexCommand \index{Debugger}
21945
21946 \end_inset 
21947
21948 .
21949  The debugger uses a command line interface, the command repertoire of the
21950  debugger has been kept as close to gdb
21951 \begin_inset LatexCommand \index{gdb}
21952
21953 \end_inset 
21954
21955  (the GNU debugger) as possible.
21956  The configuration and build process is part of the standard compiler installati
21957 on, which also builds and installs the debugger in the target directory
21958  specified during configuration.
21959  The debugger allows you debug BOTH at the C source and at the ASM source
21960  level.
21961 \layout Subsection
21962
21963 Compiling for Debugging
21964 \layout Standard
21965
21966 The -
21967 \begin_inset ERT
21968 status Collapsed
21969
21970 \layout Standard
21971
21972 \backslash 
21973 /
21974 \end_inset 
21975
21976 -debug
21977 \begin_inset LatexCommand \index{-\/-debug}
21978
21979 \end_inset 
21980
21981  option must be specified for all files for which debug information is to
21982  be generated.
21983  The compiler generates a .adb file for each of these files.
21984  The linker creates the .cdb
21985 \begin_inset LatexCommand \index{<file>.cdb}
21986
21987 \end_inset 
21988
21989  file from the .adb
21990 \begin_inset LatexCommand \index{<file>.adb}
21991
21992 \end_inset 
21993
21994  files and the address information.
21995  This .cdb is used by the debugger.
21996 \layout Subsection
21997
21998 How the Debugger Works
21999 \layout Standard
22000
22001 When the -
22002 \begin_inset ERT
22003 status Collapsed
22004
22005 \layout Standard
22006
22007 \backslash 
22008 /
22009 \end_inset 
22010
22011 -debug option is specified the compiler generates extra symbol information
22012  some of which are put into the assembler source and some are put into the
22013  .adb file.
22014  Then the linker creates the .cdb file from the individual .adb files with
22015  the address information for the symbols.
22016  The debugger reads the symbolic information generated by the compiler &
22017  the address information generated by the linker.
22018  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
22019  execution is controlled by the debugger.
22020  When a command is issued for the debugger, it translates it into appropriate
22021  commands for the simulator.
22022  (Currently SDCDM only connects to the simulator but 
22023 \emph on 
22024 newcdb
22025 \emph default 
22026  at 
22027 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
22028
22029 \end_inset 
22030
22031  is an effort to connect directly to the hardware.) 
22032 \layout Subsection
22033
22034 Starting the Debugger SDCDB
22035 \layout Standard
22036
22037 The debugger can be started using the following command line.
22038  (Assume the file you are debugging has the file name foo).
22039 \newline 
22040
22041 \newline 
22042
22043 \family sans 
22044 \series bold 
22045 sdcdb foo
22046 \newline 
22047
22048 \family default 
22049 \series default 
22050
22051 \newline 
22052 The debugger will look for the following files.
22053 \layout Itemize
22054
22055 foo.c - the source file.
22056 \layout Itemize
22057
22058 foo.cdb - the debugger symbol information file.
22059 \layout Itemize
22060
22061 foo.ihx - the Intel hex format
22062 \begin_inset LatexCommand \index{Intel hex format}
22063
22064 \end_inset 
22065
22066  object file.
22067 \layout Subsection
22068
22069 SDCDB Command Line Options
22070 \layout Itemize
22071
22072 -
22073 \begin_inset ERT
22074 status Collapsed
22075
22076 \layout Standard
22077
22078 \backslash 
22079 /
22080 \end_inset 
22081
22082 -directory=<source file directory> this option can used to specify the directory
22083  search list.
22084  The debugger will look into the directory list specified for source, cdb
22085  & ihx files.
22086  The items in the directory list must be separated by ':', e.g.
22087  if the source files can be in the directories /home/src1 and /home/src2,
22088  the -
22089 \begin_inset ERT
22090 status Collapsed
22091
22092 \layout Standard
22093
22094 \backslash 
22095 /
22096 \end_inset 
22097
22098 -directory option should be -
22099 \begin_inset ERT
22100 status Collapsed
22101
22102 \layout Standard
22103
22104 \backslash 
22105 /
22106 \end_inset 
22107
22108 -directory=/home/src1:/home/src2.
22109  Note there can be no spaces in the option.
22110  
22111 \layout Itemize
22112
22113 -cd <directory> - change to the <directory>.
22114 \layout Itemize
22115
22116 -fullname - used by GUI front ends.
22117 \layout Itemize
22118
22119 -cpu <cpu-type> - this argument is passed to the simulator please see the
22120  simulator docs for details.
22121 \layout Itemize
22122
22123 -X <Clock frequency > this options is passed to the simulator please see
22124  the simulator docs for details.
22125 \layout Itemize
22126
22127 -s <serial port file> passed to simulator see the simulator docs for details.
22128 \layout Itemize
22129
22130 -S <serial in,out> passed to simulator see the simulator docs for details.
22131 \layout Itemize
22132
22133 -k <port number> passed to simulator see the simulator docs for details.
22134 \layout Subsection
22135
22136 SDCDB Debugger Commands
22137 \layout Standard
22138
22139 As mentioned earlier the command interface for the debugger has been deliberatel
22140 y kept as close the GNU debugger gdb, as possible.
22141  This will help the integration with existing graphical user interfaces
22142  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
22143  If you use a graphical user interface for the debugger you can skip this
22144  section.
22145 \layout Subsubsection*
22146
22147 break [line | file:line | function | file:function]
22148 \layout Standard
22149
22150 Set breakpoint at specified line or function:
22151 \newline 
22152
22153 \newline 
22154
22155 \family sans 
22156 \series bold 
22157 sdcdb>break 100 
22158 \newline 
22159 sdcdb>break foo.c:100
22160 \newline 
22161 sdcdb>break funcfoo
22162 \newline 
22163 sdcdb>break foo.c:funcfoo
22164 \layout Subsubsection*
22165
22166 clear [line | file:line | function | file:function ]
22167 \layout Standard
22168
22169 Clear breakpoint at specified line or function:
22170 \newline 
22171
22172 \newline 
22173
22174 \family sans 
22175 \series bold 
22176 sdcdb>clear 100
22177 \newline 
22178 sdcdb>clear foo.c:100
22179 \newline 
22180 sdcdb>clear funcfoo
22181 \newline 
22182 sdcdb>clear foo.c:funcfoo
22183 \layout Subsubsection*
22184
22185 continue
22186 \layout Standard
22187
22188 Continue program being debugged, after breakpoint.
22189 \layout Subsubsection*
22190
22191 finish
22192 \layout Standard
22193
22194 Execute till the end of the current function.
22195 \layout Subsubsection*
22196
22197 delete [n]
22198 \layout Standard
22199
22200 Delete breakpoint number 'n'.
22201  If used without any option clear ALL user defined break points.
22202 \layout Subsubsection*
22203
22204 info [break | stack | frame | registers ]
22205 \layout Itemize
22206
22207 info break - list all breakpoints
22208 \layout Itemize
22209
22210 info stack - show the function call stack.
22211 \layout Itemize
22212
22213 info frame - show information about the current execution frame.
22214 \layout Itemize
22215
22216 info registers - show content of all registers.
22217 \layout Subsubsection*
22218
22219 step
22220 \layout Standard
22221
22222 Step program until it reaches a different source line.
22223  Note: pressing <return> repeats the last command.
22224 \layout Subsubsection*
22225
22226 next
22227 \layout Standard
22228
22229 Step program, proceeding through subroutine calls.
22230 \layout Subsubsection*
22231
22232 run
22233 \layout Standard
22234
22235 Start debugged program.
22236 \layout Subsubsection*
22237
22238 ptype variable 
22239 \layout Standard
22240
22241 Print type information of the variable.
22242 \layout Subsubsection*
22243
22244 print variable
22245 \layout Standard
22246
22247 print value of variable.
22248 \layout Subsubsection*
22249
22250 file filename
22251 \layout Standard
22252
22253 load the given file name.
22254  Note this is an alternate method of loading file for debugging.
22255 \layout Subsubsection*
22256
22257 frame
22258 \layout Standard
22259
22260 print information about current frame.
22261 \layout Subsubsection*
22262
22263 set srcmode
22264 \layout Standard
22265
22266 Toggle between C source & assembly source.
22267 \layout Subsubsection*
22268
22269 ! simulator command
22270 \layout Standard
22271
22272 Send the string following '!' to the simulator, the simulator response is
22273  displayed.
22274  Note the debugger does not interpret the command being sent to the simulator,
22275  so if a command like 'go' is sent the debugger can loose its execution
22276  context and may display incorrect values.
22277 \layout Subsubsection*
22278
22279 quit
22280 \layout Standard
22281
22282 "Watch me now.
22283  Iam going Down.
22284  My name is Bobby Brown"
22285 \layout Subsection
22286
22287 Interfacing SDCDB with DDD
22288 \layout Comment
22289
22290 The screenshot was converted from png to eps with: 
22291 \begin_inset Quotes sld
22292 \end_inset 
22293
22294 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22295 \begin_inset Quotes srd
22296 \end_inset 
22297
22298  which produces a pretty compact eps file which is free from compression
22299  artifacts.
22300 \layout Comment
22301
22302 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22303  as this broke the build system on Sourceforge (pdf-file was broken.
22304  pdflatex does not accept eps files).
22305 \layout Standard
22306
22307 The 
22308 \emph on 
22309 p
22310 \emph default 
22311 ortable 
22312 \emph on 
22313 n
22314 \emph default 
22315 etwork 
22316 \emph on 
22317 g
22318 \emph default 
22319 raphics File 
22320 \size footnotesize 
22321
22322 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22323
22324 \end_inset 
22325
22326
22327 \size default 
22328  shows a screenshot of a debugging session with DDD
22329 \begin_inset LatexCommand \index{DDD (debugger)}
22330
22331 \end_inset 
22332
22333  (Unix only) on a simulated 8032.
22334  The debugging session might not run as smoothly as the screenshot suggests.
22335  The debugger allows setting of breakpoints, displaying and changing variables,
22336  single stepping through C and assembler code.
22337  
22338 \newline 
22339 The source was compiled with 
22340 \family sans 
22341 \series bold 
22342
22343 \newline 
22344
22345 \newline 
22346 sdcc -
22347 \family default 
22348 \series default 
22349
22350 \begin_inset ERT
22351 status Collapsed
22352
22353 \layout Standard
22354
22355 \backslash 
22356 /
22357 \end_inset 
22358
22359
22360 \family sans 
22361 \series bold 
22362 -debug ddd_example.c
22363 \family default 
22364 \series default 
22365  
22366 \family sans 
22367 \series bold 
22368
22369 \newline 
22370
22371 \family default 
22372 \series default 
22373
22374 \newline 
22375 and DDD was invoked with 
22376 \family sans 
22377 \series bold 
22378
22379 \newline 
22380
22381 \newline 
22382 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22383 \layout Subsection
22384
22385 Interfacing SDCDB with XEmacs
22386 \begin_inset LatexCommand \index{XEmacs}
22387
22388 \end_inset 
22389
22390
22391 \begin_inset LatexCommand \index{Emacs}
22392
22393 \end_inset 
22394
22395
22396 \layout Standard
22397
22398 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22399  sdcdb.el and sdcdbsrc.el.
22400  These two files can be found in the $(prefix)/bin directory after the installat
22401 ion is complete.
22402  These files need to be loaded into XEmacs for the interface to work.
22403  This can be done at XEmacs startup time by inserting the following into
22404  your '.xemacs' file (which can be found in your HOME directory): 
22405 \newline 
22406
22407 \newline 
22408
22409 \family typewriter 
22410 (load-file sdcdbsrc.el) 
22411 \family default 
22412
22413 \newline 
22414
22415 \newline 
22416 .xemacs is a lisp file so the () around the command is REQUIRED.
22417  The files can also be loaded dynamically while XEmacs is running, set the
22418  environment variable 'EMACSLOADPATH' to the installation bin directory
22419  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22420  To start the interface enter the following command: 
22421 \newline 
22422
22423 \newline 
22424
22425 \family sans 
22426 \series bold 
22427 ESC-x sdcdbsrc
22428 \family default 
22429 \series default 
22430
22431 \newline 
22432
22433 \newline 
22434 You will prompted to enter the file name to be debugged.
22435  
22436 \newline 
22437
22438 \newline 
22439 The command line options that are passed to the simulator directly are bound
22440  to default values in the file sdcdbsrc.el.
22441  The variables are listed below, these values maybe changed as required.
22442 \layout Itemize
22443
22444 sdcdbsrc-cpu-type '51
22445 \layout Itemize
22446
22447 sdcdbsrc-frequency '11059200
22448 \layout Itemize
22449
22450 sdcdbsrc-serial nil
22451 \layout Standard
22452
22453 The following is a list of key mapping for the debugger interface.
22454 \layout Standard
22455
22456 \SpecialChar ~
22457
22458 \family typewriter 
22459
22460 \newline 
22461 ;;\SpecialChar ~
22462 Current Listing :: 
22463 \newline 
22464 ;;key\SpecialChar ~
22465 \SpecialChar ~
22466 \SpecialChar ~
22467 \SpecialChar ~
22468 \SpecialChar ~
22469 \SpecialChar ~
22470 \SpecialChar ~
22471 \SpecialChar ~
22472 \SpecialChar ~
22473 \SpecialChar ~
22474 \SpecialChar ~
22475 \SpecialChar ~
22476 \SpecialChar ~
22477 \SpecialChar ~
22478 binding\SpecialChar ~
22479 \SpecialChar ~
22480 \SpecialChar ~
22481 \SpecialChar ~
22482 \SpecialChar ~
22483 \SpecialChar ~
22484 \SpecialChar ~
22485 \SpecialChar ~
22486 \SpecialChar ~
22487 \SpecialChar ~
22488 \SpecialChar ~
22489 \SpecialChar ~
22490 \SpecialChar ~
22491 \SpecialChar ~
22492 \SpecialChar ~
22493 \SpecialChar ~
22494 \SpecialChar ~
22495 \SpecialChar ~
22496 \SpecialChar ~
22497 \SpecialChar ~
22498 \SpecialChar ~
22499 \SpecialChar ~
22500 Comment 
22501 \newline 
22502 ;;---\SpecialChar ~
22503 \SpecialChar ~
22504 \SpecialChar ~
22505 \SpecialChar ~
22506 \SpecialChar ~
22507 \SpecialChar ~
22508 \SpecialChar ~
22509 \SpecialChar ~
22510 \SpecialChar ~
22511 \SpecialChar ~
22512 \SpecialChar ~
22513 \SpecialChar ~
22514 \SpecialChar ~
22515 \SpecialChar ~
22516 -------\SpecialChar ~
22517 \SpecialChar ~
22518 \SpecialChar ~
22519 \SpecialChar ~
22520 \SpecialChar ~
22521 \SpecialChar ~
22522 \SpecialChar ~
22523 \SpecialChar ~
22524 \SpecialChar ~
22525 \SpecialChar ~
22526 \SpecialChar ~
22527 \SpecialChar ~
22528 \SpecialChar ~
22529 \SpecialChar ~
22530 \SpecialChar ~
22531 \SpecialChar ~
22532 \SpecialChar ~
22533 \SpecialChar ~
22534 \SpecialChar ~
22535 \SpecialChar ~
22536 \SpecialChar ~
22537 \SpecialChar ~
22538 -------
22539 \newline 
22540 ;; 
22541 \newline 
22542 ;;\SpecialChar ~
22543 n\SpecialChar ~
22544 \SpecialChar ~
22545 \SpecialChar ~
22546 \SpecialChar ~
22547 \SpecialChar ~
22548 \SpecialChar ~
22549 \SpecialChar ~
22550 \SpecialChar ~
22551 \SpecialChar ~
22552 \SpecialChar ~
22553 \SpecialChar ~
22554 \SpecialChar ~
22555 \SpecialChar ~
22556 \SpecialChar ~
22557 \SpecialChar ~
22558 sdcdb-next-from-src\SpecialChar ~
22559 \SpecialChar ~
22560 \SpecialChar ~
22561 \SpecialChar ~
22562 \SpecialChar ~
22563 \SpecialChar ~
22564 \SpecialChar ~
22565 \SpecialChar ~
22566 \SpecialChar ~
22567 \SpecialChar ~
22568 SDCDB next command 
22569 \newline 
22570 ;;\SpecialChar ~
22571 b\SpecialChar ~
22572 \SpecialChar ~
22573 \SpecialChar ~
22574 \SpecialChar ~
22575 \SpecialChar ~
22576 \SpecialChar ~
22577 \SpecialChar ~
22578 \SpecialChar ~
22579 \SpecialChar ~
22580 \SpecialChar ~
22581 \SpecialChar ~
22582 \SpecialChar ~
22583 \SpecialChar ~
22584 \SpecialChar ~
22585 \SpecialChar ~
22586 sdcdb-back-from-src\SpecialChar ~
22587 \SpecialChar ~
22588 \SpecialChar ~
22589 \SpecialChar ~
22590 \SpecialChar ~
22591 \SpecialChar ~
22592 \SpecialChar ~
22593 \SpecialChar ~
22594 \SpecialChar ~
22595 \SpecialChar ~
22596 SDCDB back command 
22597 \newline 
22598 ;;\SpecialChar ~
22599 c\SpecialChar ~
22600 \SpecialChar ~
22601 \SpecialChar ~
22602 \SpecialChar ~
22603 \SpecialChar ~
22604 \SpecialChar ~
22605 \SpecialChar ~
22606 \SpecialChar ~
22607 \SpecialChar ~
22608 \SpecialChar ~
22609 \SpecialChar ~
22610 \SpecialChar ~
22611 \SpecialChar ~
22612 \SpecialChar ~
22613 \SpecialChar ~
22614 sdcdb-cont-from-src\SpecialChar ~
22615 \SpecialChar ~
22616 \SpecialChar ~
22617 \SpecialChar ~
22618 \SpecialChar ~
22619 \SpecialChar ~
22620 \SpecialChar ~
22621 \SpecialChar ~
22622 \SpecialChar ~
22623 \SpecialChar ~
22624 SDCDB continue command
22625 \newline 
22626 ;;\SpecialChar ~
22627 s\SpecialChar ~
22628 \SpecialChar ~
22629 \SpecialChar ~
22630 \SpecialChar ~
22631 \SpecialChar ~
22632 \SpecialChar ~
22633 \SpecialChar ~
22634 \SpecialChar ~
22635 \SpecialChar ~
22636 \SpecialChar ~
22637 \SpecialChar ~
22638 \SpecialChar ~
22639 \SpecialChar ~
22640 \SpecialChar ~
22641 \SpecialChar ~
22642 sdcdb-step-from-src\SpecialChar ~
22643 \SpecialChar ~
22644 \SpecialChar ~
22645 \SpecialChar ~
22646 \SpecialChar ~
22647 \SpecialChar ~
22648 \SpecialChar ~
22649 \SpecialChar ~
22650 \SpecialChar ~
22651 \SpecialChar ~
22652 SDCDB step command 
22653 \newline 
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 sdcdb-whatis-c-sexp\SpecialChar ~
22671 \SpecialChar ~
22672 \SpecialChar ~
22673 \SpecialChar ~
22674 \SpecialChar ~
22675 \SpecialChar ~
22676 \SpecialChar ~
22677 \SpecialChar ~
22678 \SpecialChar ~
22679 \SpecialChar ~
22680 SDCDB ptypecommand for data at 
22681 \newline 
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 \SpecialChar ~
22697 \SpecialChar ~
22698 \SpecialChar ~
22699 \SpecialChar ~
22700 \SpecialChar ~
22701 \SpecialChar ~
22702 \SpecialChar ~
22703 \SpecialChar ~
22704 \SpecialChar ~
22705 \SpecialChar ~
22706 \SpecialChar ~
22707 \SpecialChar ~
22708 \SpecialChar ~
22709 \SpecialChar ~
22710 \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 \SpecialChar ~
22725 \SpecialChar ~
22726 \SpecialChar ~
22727 \SpecialChar ~
22728 \SpecialChar ~
22729 buffer point 
22730 \newline 
22731 ;;\SpecialChar ~
22732 x\SpecialChar ~
22733 \SpecialChar ~
22734 \SpecialChar ~
22735 \SpecialChar ~
22736 \SpecialChar ~
22737 \SpecialChar ~
22738 \SpecialChar ~
22739 \SpecialChar ~
22740 \SpecialChar ~
22741 \SpecialChar ~
22742 \SpecialChar ~
22743 \SpecialChar ~
22744 \SpecialChar ~
22745 \SpecialChar ~
22746 \SpecialChar ~
22747 sdcdbsrc-delete\SpecialChar ~
22748 \SpecialChar ~
22749 \SpecialChar ~
22750 \SpecialChar ~
22751 \SpecialChar ~
22752 \SpecialChar ~
22753 \SpecialChar ~
22754 \SpecialChar ~
22755 \SpecialChar ~
22756 \SpecialChar ~
22757 \SpecialChar ~
22758 \SpecialChar ~
22759 \SpecialChar ~
22760 \SpecialChar ~
22761 SDCDB Delete all breakpoints if no arg 
22762 \newline 
22763 ;;\SpecialChar ~
22764 \SpecialChar ~
22765 \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 \SpecialChar ~
22781 \SpecialChar ~
22782 \SpecialChar ~
22783 \SpecialChar ~
22784 \SpecialChar ~
22785 \SpecialChar ~
22786 \SpecialChar ~
22787 \SpecialChar ~
22788 \SpecialChar ~
22789 \SpecialChar ~
22790 \SpecialChar ~
22791 \SpecialChar ~
22792 \SpecialChar ~
22793 \SpecialChar ~
22794 \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 \SpecialChar ~
22809 \SpecialChar ~
22810 given or delete arg (C-u arg x) 
22811 \newline 
22812 ;;\SpecialChar ~
22813 m\SpecialChar ~
22814 \SpecialChar ~
22815 \SpecialChar ~
22816 \SpecialChar ~
22817 \SpecialChar ~
22818 \SpecialChar ~
22819 \SpecialChar ~
22820 \SpecialChar ~
22821 \SpecialChar ~
22822 \SpecialChar ~
22823 \SpecialChar ~
22824 \SpecialChar ~
22825 \SpecialChar ~
22826 \SpecialChar ~
22827 \SpecialChar ~
22828 sdcdbsrc-frame\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 SDCDB Display current frame if no arg, 
22844 \newline 
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 \SpecialChar ~
22868 \SpecialChar ~
22869 \SpecialChar ~
22870 \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 \SpecialChar ~
22886 \SpecialChar ~
22887 \SpecialChar ~
22888 \SpecialChar ~
22889 \SpecialChar ~
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 given or display frame arg 
22893 \newline 
22894 ;;\SpecialChar ~
22895 \SpecialChar ~
22896 \SpecialChar ~
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 \SpecialChar ~
22900 \SpecialChar ~
22901 \SpecialChar ~
22902 \SpecialChar ~
22903 \SpecialChar ~
22904 \SpecialChar ~
22905 \SpecialChar ~
22906 \SpecialChar ~
22907 \SpecialChar ~
22908 \SpecialChar ~
22909 \SpecialChar ~
22910 \SpecialChar ~
22911 \SpecialChar ~
22912 \SpecialChar ~
22913 \SpecialChar ~
22914 \SpecialChar ~
22915 \SpecialChar ~
22916 \SpecialChar ~
22917 \SpecialChar ~
22918 \SpecialChar ~
22919 \SpecialChar ~
22920 \SpecialChar ~
22921 \SpecialChar ~
22922 \SpecialChar ~
22923 \SpecialChar ~
22924 \SpecialChar ~
22925 \SpecialChar ~
22926 \SpecialChar ~
22927 \SpecialChar ~
22928 \SpecialChar ~
22929 \SpecialChar ~
22930 \SpecialChar ~
22931 \SpecialChar ~
22932 \SpecialChar ~
22933 \SpecialChar ~
22934 \SpecialChar ~
22935 \SpecialChar ~
22936 \SpecialChar ~
22937 \SpecialChar ~
22938 \SpecialChar ~
22939 \SpecialChar ~
22940 \SpecialChar ~
22941 buffer point 
22942 \newline 
22943 ;;\SpecialChar ~
22944 !\SpecialChar ~
22945 \SpecialChar ~
22946 \SpecialChar ~
22947 \SpecialChar ~
22948 \SpecialChar ~
22949 \SpecialChar ~
22950 \SpecialChar ~
22951 \SpecialChar ~
22952 \SpecialChar ~
22953 \SpecialChar ~
22954 \SpecialChar ~
22955 \SpecialChar ~
22956 \SpecialChar ~
22957 \SpecialChar ~
22958 \SpecialChar ~
22959 sdcdbsrc-goto-sdcdb\SpecialChar ~
22960 \SpecialChar ~
22961 \SpecialChar ~
22962 \SpecialChar ~
22963 \SpecialChar ~
22964 \SpecialChar ~
22965 \SpecialChar ~
22966 \SpecialChar ~
22967 \SpecialChar ~
22968 \SpecialChar ~
22969 Goto the SDCDB output buffer 
22970 \newline 
22971 ;;\SpecialChar ~
22972 p\SpecialChar ~
22973 \SpecialChar ~
22974 \SpecialChar ~
22975 \SpecialChar ~
22976 \SpecialChar ~
22977 \SpecialChar ~
22978 \SpecialChar ~
22979 \SpecialChar ~
22980 \SpecialChar ~
22981 \SpecialChar ~
22982 \SpecialChar ~
22983 \SpecialChar ~
22984 \SpecialChar ~
22985 \SpecialChar ~
22986 \SpecialChar ~
22987 sdcdb-print-c-sexp\SpecialChar ~
22988 \SpecialChar ~
22989 \SpecialChar ~
22990 \SpecialChar ~
22991 \SpecialChar ~
22992 \SpecialChar ~
22993 \SpecialChar ~
22994 \SpecialChar ~
22995 \SpecialChar ~
22996 \SpecialChar ~
22997 \SpecialChar ~
22998 SDCDB print command for data at 
22999 \newline 
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 \SpecialChar ~
23031 \SpecialChar ~
23032 \SpecialChar ~
23033 \SpecialChar ~
23034 \SpecialChar ~
23035 \SpecialChar ~
23036 \SpecialChar ~
23037 \SpecialChar ~
23038 \SpecialChar ~
23039 \SpecialChar ~
23040 \SpecialChar ~
23041 \SpecialChar ~
23042 \SpecialChar ~
23043 \SpecialChar ~
23044 \SpecialChar ~
23045 \SpecialChar ~
23046 \SpecialChar ~
23047 buffer point 
23048 \newline 
23049 ;;\SpecialChar ~
23050 g\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 sdcdbsrc-goto-sdcdb\SpecialChar ~
23066 \SpecialChar ~
23067 \SpecialChar ~
23068 \SpecialChar ~
23069 \SpecialChar ~
23070 \SpecialChar ~
23071 \SpecialChar ~
23072 \SpecialChar ~
23073 \SpecialChar ~
23074 \SpecialChar ~
23075 Goto the SDCDB output buffer 
23076 \newline 
23077 ;;\SpecialChar ~
23078 t\SpecialChar ~
23079 \SpecialChar ~
23080 \SpecialChar ~
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 sdcdbsrc-mode\SpecialChar ~
23094 \SpecialChar ~
23095 \SpecialChar ~
23096 \SpecialChar ~
23097 \SpecialChar ~
23098 \SpecialChar ~
23099 \SpecialChar ~
23100 \SpecialChar ~
23101 \SpecialChar ~
23102 \SpecialChar ~
23103 \SpecialChar ~
23104 \SpecialChar ~
23105 \SpecialChar ~
23106 \SpecialChar ~
23107 \SpecialChar ~
23108 \SpecialChar ~
23109 Toggles Sdcdbsrc mode (turns it off) 
23110 \newline 
23111 ;; 
23112 \newline 
23113 ;;\SpecialChar ~
23114 C-c\SpecialChar ~
23115 C-f\SpecialChar ~
23116 \SpecialChar ~
23117 \SpecialChar ~
23118 \SpecialChar ~
23119 \SpecialChar ~
23120 \SpecialChar ~
23121 \SpecialChar ~
23122 \SpecialChar ~
23123 \SpecialChar ~
23124 sdcdb-finish-from-src\SpecialChar ~
23125 \SpecialChar ~
23126 \SpecialChar ~
23127 \SpecialChar ~
23128 \SpecialChar ~
23129 \SpecialChar ~
23130 \SpecialChar ~
23131 \SpecialChar ~
23132 SDCDB finish command 
23133 \newline 
23134 ;; 
23135 \newline 
23136 ;;\SpecialChar ~
23137 C-x\SpecialChar ~
23138 SPC\SpecialChar ~
23139 \SpecialChar ~
23140 \SpecialChar ~
23141 \SpecialChar ~
23142 \SpecialChar ~
23143 \SpecialChar ~
23144 \SpecialChar ~
23145 \SpecialChar ~
23146 \SpecialChar ~
23147 sdcdb-break\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 Set break for line with point 
23166 \newline 
23167 ;;\SpecialChar ~
23168 ESC\SpecialChar ~
23169 t\SpecialChar ~
23170 \SpecialChar ~
23171 \SpecialChar ~
23172 \SpecialChar ~
23173 \SpecialChar ~
23174 \SpecialChar ~
23175 \SpecialChar ~
23176 \SpecialChar ~
23177 \SpecialChar ~
23178 \SpecialChar ~
23179 \SpecialChar ~
23180 sdcdbsrc-mode\SpecialChar ~
23181 \SpecialChar ~
23182 \SpecialChar ~
23183 \SpecialChar ~
23184 \SpecialChar ~
23185 \SpecialChar ~
23186 \SpecialChar ~
23187 \SpecialChar ~
23188 \SpecialChar ~
23189 \SpecialChar ~
23190 \SpecialChar ~
23191 \SpecialChar ~
23192 \SpecialChar ~
23193 \SpecialChar ~
23194 \SpecialChar ~
23195 \SpecialChar ~
23196 Toggle Sdcdbsrc mode 
23197 \newline 
23198 ;;\SpecialChar ~
23199 ESC\SpecialChar ~
23200 m\SpecialChar ~
23201 \SpecialChar ~
23202 \SpecialChar ~
23203 \SpecialChar ~
23204 \SpecialChar ~
23205 \SpecialChar ~
23206 \SpecialChar ~
23207 \SpecialChar ~
23208 \SpecialChar ~
23209 \SpecialChar ~
23210 \SpecialChar ~
23211 sdcdbsrc-srcmode\SpecialChar ~
23212 \SpecialChar ~
23213 \SpecialChar ~
23214 \SpecialChar ~
23215 \SpecialChar ~
23216 \SpecialChar ~
23217 \SpecialChar ~
23218 \SpecialChar ~
23219 \SpecialChar ~
23220 \SpecialChar ~
23221 \SpecialChar ~
23222 \SpecialChar ~
23223 \SpecialChar ~
23224 Toggle list mode 
23225 \newline 
23226 ;; 
23227 \newline 
23228
23229 \layout Chapter
23230 \pagebreak_top 
23231 TIPS
23232 \layout Standard
23233
23234 Here are a few guidelines that will help the compiler generate more efficient
23235  code, some of the tips are specific to this compiler others are generally
23236  good programming practice.
23237 \layout Itemize
23238
23239 Use the smallest data type to represent your data-value.
23240  If it is known in advance that the value is going to be less than 256 then
23241  use an 'unsigned char' instead of a 'short' or 'int'.
23242  Please note, that ANSI C requires both signed and unsigned chars to be
23243  promoted to 'signed int'
23244 \begin_inset LatexCommand \index{promotion to signed int}
23245
23246 \end_inset 
23247
23248
23249 \begin_inset Marginal
23250 collapsed true
23251
23252 \layout Standard
23253
23254
23255 \series bold 
23256 \SpecialChar ~
23257 !
23258 \end_inset 
23259
23260  before doing any operation.
23261  This promotion
23262 \begin_inset LatexCommand \index{type promotion}
23263
23264 \end_inset 
23265
23266
23267 \begin_inset LatexCommand \label{type promotion}
23268
23269 \end_inset 
23270
23271  can be omitted, if the result is the same.
23272  The effect of the promotion rules together with the sign-extension is often
23273  surprising:
23274 \begin_deeper 
23275 \layout Verse
23276
23277
23278 \family typewriter 
23279 unsigned char uc = 0xfe;
23280 \newline 
23281 if (uc * uc < 0) /* this is true! */
23282 \newline 
23283 {
23284 \newline 
23285 \SpecialChar ~
23286 \SpecialChar ~
23287 \SpecialChar ~
23288 \SpecialChar ~
23289 ....
23290 \newline 
23291 }
23292 \layout Standard
23293
23294
23295 \family typewriter 
23296 uc * uc
23297 \family default 
23298  is evaluated as 
23299 \family typewriter 
23300 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23301 \family default 
23302 .
23303  
23304 \newline 
23305 Another one:
23306 \layout Verse
23307
23308
23309 \family typewriter 
23310 (unsigned char) -12 / (signed char) -3 = ...
23311 \layout Standard
23312
23313 No, the result is not 4:
23314 \layout Verse
23315
23316
23317 \family typewriter 
23318 (int) (unsigned char) -12 / (int) (signed char) -3 =
23319 \newline 
23320 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23321 \newline 
23322 (int) 0x00f4 / (int) 0xfffd =
23323 \newline 
23324 (int) 0x00f4 / (int) 0xfffd =
23325 \newline 
23326 (int) 244 / (int) -3 =
23327 \newline 
23328 (int) -81 = (int) 0xffaf;
23329 \layout Standard
23330
23331 Don't complain, that gcc gives you a different result.
23332  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23333  Therefore the results are different.
23334 \newline 
23335 From 
23336 \begin_inset Quotes sld
23337 \end_inset 
23338
23339 comp.lang.c FAQ
23340 \begin_inset Quotes srd
23341 \end_inset 
23342
23343 :
23344 \layout Quote
23345
23346
23347 \emph on 
23348 If well-defined overflow characteristics are important and negative values
23349  are not, or if you want to steer clear of sign-extension problems when
23350  manipulating bits or bytes, use one of the corresponding unsigned types.
23351  (Beware when mixing signed and unsigned values in expressions, though.)
23352 \newline 
23353 Although character types (especially unsigned char) can be used as "tiny"
23354  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23355 ble sign extension and increased code size.
23356 \end_deeper 
23357 \layout Itemize
23358
23359 Use unsigned when it is known in advance that the value is not going to
23360  be negative.
23361  This helps especially if you are doing division or multiplication, bit-shifting
23362  or are using an array index.
23363 \layout Itemize
23364
23365 NEVER jump into a LOOP.
23366 \layout Itemize
23367
23368 Declare the variables to be local
23369 \begin_inset LatexCommand \index{local variables}
23370
23371 \end_inset 
23372
23373  whenever possible, especially loop control variables (induction).
23374 \layout Itemize
23375
23376 Since the compiler does not always do implicit integral promotion, the programme
23377 r should do an explicit cast when integral promotion is required.
23378 \layout Itemize
23379
23380 Reducing the size of division, multiplication & modulus operations can reduce
23381  code size substantially.
23382  Take the following code for example.
23383 \begin_deeper 
23384 \layout Verse
23385
23386
23387 \family typewriter 
23388 foobar(unsigned int p1, unsigned char ch)
23389 \newline 
23390 {
23391 \newline 
23392 \SpecialChar ~
23393 \SpecialChar ~
23394 \SpecialChar ~
23395 \SpecialChar ~
23396 unsigned char ch1 = p1 % ch ;
23397 \newline 
23398 \SpecialChar ~
23399 \SpecialChar ~
23400 \SpecialChar ~
23401 \SpecialChar ~
23402 ....
23403 \newline 
23404 }
23405 \layout Standard
23406
23407 For the modulus operation the variable ch will be promoted to unsigned int
23408  first then the modulus operation will be performed (this will lead to a
23409  call to support routine _moduint()), and the result will be casted to a
23410  char.
23411  If the code is changed to 
23412 \layout Verse
23413
23414
23415 \family typewriter 
23416 foobar(unsigned int p1, unsigned char ch)
23417 \newline 
23418 {
23419 \newline 
23420 \SpecialChar ~
23421 \SpecialChar ~
23422 \SpecialChar ~
23423 \SpecialChar ~
23424 unsigned char ch1 = (unsigned char)p1 % ch ;
23425 \newline 
23426 \SpecialChar ~
23427 \SpecialChar ~
23428 \SpecialChar ~
23429 \SpecialChar ~
23430 ....
23431 \newline 
23432 }
23433 \layout Standard
23434
23435 It would substantially reduce the code generated (future versions of the
23436  compiler will be smart enough to detect such optimization opportunities).
23437 \end_deeper 
23438 \layout Itemize
23439
23440 Have a look at the assembly listing to get a 
23441 \begin_inset Quotes sld
23442 \end_inset 
23443
23444 feeling
23445 \begin_inset Quotes srd
23446 \end_inset 
23447
23448  for the code generation.
23449 \layout Section
23450
23451 Porting code from or to other compilers
23452 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23453
23454 \end_inset 
23455
23456
23457 \layout Itemize
23458
23459 check whether endianness of the compilers differs and adapt where needed.
23460 \layout Itemize
23461
23462 check the device specific header files
23463 \begin_inset LatexCommand \index{Header files}
23464
23465 \end_inset 
23466
23467
23468 \begin_inset LatexCommand \index{Include files}
23469
23470 \end_inset 
23471
23472  for compiler specific syntax.
23473  Eventually include the file <compiler.h
23474 \begin_inset LatexCommand \index{compiler.h (include file)}
23475
23476 \end_inset 
23477
23478 > to allow using common header files.
23479  (see f.e.
23480  cc2510fx.h 
23481 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/P89c51RD2.h?view=markup}
23482
23483 \end_inset 
23484
23485 ).
23486 \layout Itemize
23487
23488 check whether the startup code contains the correct initialization (watchdog,
23489  peripherals).
23490 \layout Itemize
23491
23492 check whether the sizes of short, int, long match.
23493 \layout Itemize
23494
23495 check if some 16 or 32 bit hardware registers require a specific addressing
23496  order (least significant or most significant byte first) and adapt if needed
23497  (
23498 \emph on 
23499 first
23500 \emph default 
23501  and 
23502 \emph on 
23503 last
23504 \emph default 
23505  relate to time and not to lower/upper memory location here, so this is
23506  
23507 \emph on 
23508 not
23509 \emph default 
23510  the same as endianness).
23511 \layout Itemize
23512
23513 check whether the keyword 
23514 \emph on 
23515 volatile
23516 \emph default 
23517  is used where needed.
23518  The compilers might differ in their optimization characteristics (as different
23519  versions of the same compiler might also use more clever optimizations
23520  this is good idea anyway).
23521  See section 
23522 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
23523
23524 \end_inset 
23525
23526 .
23527 \layout Itemize
23528
23529 check that the compilers are not told to supress warnings.
23530 \layout Itemize
23531
23532 check and convert compiler specific extensions (interrupts, memory areas,
23533  pragmas etc.).
23534 \layout Itemize
23535
23536 check for differences in type promotion.
23537  Especially check for math operations on 
23538 \family typewriter 
23539 char
23540 \family default 
23541  or 
23542 \family typewriter 
23543 unsigned char
23544 \family default 
23545  variables.
23546  For the sake of C99 compatibility SDCC will probably promote these to 
23547 \family typewriter 
23548 int
23549 \family default 
23550  more often than other compilers.
23551  Eventually insert explicit casts to 
23552 \family typewriter 
23553 (char) 
23554 \family default 
23555 or
23556 \family typewriter 
23557  (unsigned char)
23558 \family default 
23559 .
23560  Also check that the ~\SpecialChar ~
23561 operator
23562 \begin_inset LatexCommand \index{\~\/ Operator}
23563
23564 \end_inset 
23565
23566  is not used on 
23567 \family typewriter 
23568 bit
23569 \begin_inset LatexCommand \index{bit}
23570
23571 \end_inset 
23572
23573
23574 \family default 
23575  variables, use the !\SpecialChar ~
23576 operator instead.
23577  See sections 
23578 \begin_inset LatexCommand \ref{type promotion}
23579
23580 \end_inset 
23581
23582  and 
23583 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23584
23585 \end_inset 
23586
23587 .
23588 \layout Itemize
23589
23590 check the assembly code generated for interrupt routines (f.e.
23591  for calls to possibly non-reentrant library functions).
23592 \layout Itemize
23593
23594 check whether timing loops result in proper timing (or preferably consider
23595  a rewrite of the code with timer based delays instead).
23596 \layout Itemize
23597
23598 check for differences in printf parameters (some compilers push (va_arg
23599 \begin_inset LatexCommand \index{vararg, va\_arg}
23600
23601 \end_inset 
23602
23603 ) char variables as 
23604 \family typewriter 
23605 int
23606 \family default 
23607  others push them as 
23608 \family typewriter 
23609 char
23610 \family default 
23611 .
23612  See section 
23613 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23614
23615 \end_inset 
23616
23617 ).
23618 \layout Itemize
23619
23620 check the resulting memory map
23621 \begin_inset LatexCommand \index{Memory map}
23622
23623 \end_inset 
23624
23625 .
23626  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23627 ly idata, pdata, xdata).
23628  Eventually check if unexpected library functions are included.
23629 \layout Section
23630
23631 Tools
23632 \begin_inset LatexCommand \index{Tools}
23633
23634 \end_inset 
23635
23636  included in the distribution
23637 \layout Standard
23638 \align left 
23639
23640 \begin_inset  Tabular
23641 <lyxtabular version="3" rows="12" columns="3">
23642 <features>
23643 <column alignment="left" valignment="top" leftline="true" width="0pt">
23644 <column alignment="left" valignment="top" leftline="true" width="0pt">
23645 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23646 <row topline="true" bottomline="true">
23647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23648 \begin_inset Text
23649
23650 \layout Standard
23651
23652 Name
23653 \end_inset 
23654 </cell>
23655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23656 \begin_inset Text
23657
23658 \layout Standard
23659
23660 Purpose
23661 \end_inset 
23662 </cell>
23663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23664 \begin_inset Text
23665
23666 \layout Standard
23667
23668 Directory
23669 \end_inset 
23670 </cell>
23671 </row>
23672 <row topline="true">
23673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23674 \begin_inset Text
23675
23676 \layout Standard
23677
23678 ucSsim
23679 \end_inset 
23680 </cell>
23681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23682 \begin_inset Text
23683
23684 \layout Standard
23685
23686 Simulator for various architectures
23687 \end_inset 
23688 </cell>
23689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23690 \begin_inset Text
23691
23692 \layout Standard
23693
23694 sdcc/sim/ucsim
23695 \end_inset 
23696 </cell>
23697 </row>
23698 <row topline="true">
23699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23700 \begin_inset Text
23701
23702 \layout Standard
23703
23704 keil2sdcc.pl
23705 \end_inset 
23706 </cell>
23707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23708 \begin_inset Text
23709
23710 \layout Standard
23711
23712 header file
23713 \begin_inset LatexCommand \index{Header files}
23714
23715 \end_inset 
23716
23717
23718 \begin_inset LatexCommand \index{Include files}
23719
23720 \end_inset 
23721
23722  conversion
23723 \end_inset 
23724 </cell>
23725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23726 \begin_inset Text
23727
23728 \layout Standard
23729
23730 sdcc/support/scripts
23731 \end_inset 
23732 </cell>
23733 </row>
23734 <row topline="true">
23735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23736 \begin_inset Text
23737
23738 \layout Standard
23739
23740 mh2h.c
23741 \end_inset 
23742 </cell>
23743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23744 \begin_inset Text
23745
23746 \layout Standard
23747
23748 header file conversion
23749 \end_inset 
23750 </cell>
23751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23752 \begin_inset Text
23753
23754 \layout Standard
23755
23756 sdcc/support/scripts
23757 \end_inset 
23758 </cell>
23759 </row>
23760 <row topline="true">
23761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23762 \begin_inset Text
23763
23764 \layout Standard
23765
23766 as-gbz80
23767 \end_inset 
23768 </cell>
23769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23770 \begin_inset Text
23771
23772 \layout Standard
23773
23774 Assembler
23775 \end_inset 
23776 </cell>
23777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23778 \begin_inset Text
23779
23780 \layout Standard
23781
23782
23783 \family roman 
23784 \series medium 
23785 \shape up 
23786 \size normal 
23787 \emph off 
23788 \bar no 
23789 \noun off 
23790 \color none
23791 sdcc/bin
23792 \end_inset 
23793 </cell>
23794 </row>
23795 <row topline="true">
23796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23797 \begin_inset Text
23798
23799 \layout Standard
23800
23801 as-z80
23802 \end_inset 
23803 </cell>
23804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23805 \begin_inset Text
23806
23807 \layout Standard
23808
23809 Assembler
23810 \end_inset 
23811 </cell>
23812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23813 \begin_inset Text
23814
23815 \layout Standard
23816
23817
23818 \family roman 
23819 \series medium 
23820 \shape up 
23821 \size normal 
23822 \emph off 
23823 \bar no 
23824 \noun off 
23825 \color none
23826 sdcc/bin
23827 \end_inset 
23828 </cell>
23829 </row>
23830 <row topline="true">
23831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23832 \begin_inset Text
23833
23834 \layout Standard
23835
23836 asx8051
23837 \end_inset 
23838 </cell>
23839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23840 \begin_inset Text
23841
23842 \layout Standard
23843
23844 Assembler
23845 \end_inset 
23846 </cell>
23847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23848 \begin_inset Text
23849
23850 \layout Standard
23851
23852
23853 \family roman 
23854 \series medium 
23855 \shape up 
23856 \size normal 
23857 \emph off 
23858 \bar no 
23859 \noun off 
23860 \color none
23861 sdcc/bin
23862 \end_inset 
23863 </cell>
23864 </row>
23865 <row topline="true">
23866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23867 \begin_inset Text
23868
23869 \layout Standard
23870
23871 SDCDB
23872 \end_inset 
23873 </cell>
23874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23875 \begin_inset Text
23876
23877 \layout Standard
23878
23879 Simulator
23880 \end_inset 
23881 </cell>
23882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23883 \begin_inset Text
23884
23885 \layout Standard
23886
23887
23888 \family roman 
23889 \series medium 
23890 \shape up 
23891 \size normal 
23892 \emph off 
23893 \bar no 
23894 \noun off 
23895 \color none
23896 sdcc/bin
23897 \end_inset 
23898 </cell>
23899 </row>
23900 <row topline="true">
23901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23902 \begin_inset Text
23903
23904 \layout Standard
23905
23906 aslink
23907 \end_inset 
23908 </cell>
23909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23910 \begin_inset Text
23911
23912 \layout Standard
23913
23914 Linker
23915 \end_inset 
23916 </cell>
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23918 \begin_inset Text
23919
23920 \layout Standard
23921
23922
23923 \family roman 
23924 \series medium 
23925 \shape up 
23926 \size normal 
23927 \emph off 
23928 \bar no 
23929 \noun off 
23930 \color none
23931 sdcc/bin
23932 \end_inset 
23933 </cell>
23934 </row>
23935 <row topline="true">
23936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23937 \begin_inset Text
23938
23939 \layout Standard
23940
23941 link-z80
23942 \end_inset 
23943 </cell>
23944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23945 \begin_inset Text
23946
23947 \layout Standard
23948
23949 Linker
23950 \end_inset 
23951 </cell>
23952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23953 \begin_inset Text
23954
23955 \layout Standard
23956
23957
23958 \family roman 
23959 \series medium 
23960 \shape up 
23961 \size normal 
23962 \emph off 
23963 \bar no 
23964 \noun off 
23965 \color none
23966 sdcc/bin
23967 \end_inset 
23968 </cell>
23969 </row>
23970 <row topline="true">
23971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23972 \begin_inset Text
23973
23974 \layout Standard
23975
23976 link-gbz80
23977 \end_inset 
23978 </cell>
23979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23980 \begin_inset Text
23981
23982 \layout Standard
23983
23984 Linker
23985 \end_inset 
23986 </cell>
23987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23988 \begin_inset Text
23989
23990 \layout Standard
23991
23992
23993 \family roman 
23994 \series medium 
23995 \shape up 
23996 \size normal 
23997 \emph off 
23998 \bar no 
23999 \noun off 
24000 \color none
24001 sdcc/bin
24002 \end_inset 
24003 </cell>
24004 </row>
24005 <row topline="true" bottomline="true">
24006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24007 \begin_inset Text
24008
24009 \layout Standard
24010
24011 packihx
24012 \end_inset 
24013 </cell>
24014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24015 \begin_inset Text
24016
24017 \layout Standard
24018
24019 Intel Hex packer 
24020 \begin_inset LatexCommand \index{packihx (tool)}
24021
24022 \end_inset 
24023
24024
24025 \end_inset 
24026 </cell>
24027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24028 \begin_inset Text
24029
24030 \layout Standard
24031
24032
24033 \family roman 
24034 \series medium 
24035 \shape up 
24036 \size normal 
24037 \emph off 
24038 \bar no 
24039 \noun off 
24040 \color none
24041 sdcc/bin
24042 \end_inset 
24043 </cell>
24044 </row>
24045 </lyxtabular>
24046
24047 \end_inset 
24048
24049
24050 \newline 
24051
24052 \layout Section
24053
24054 Documentation
24055 \begin_inset LatexCommand \index{Documentation}
24056
24057 \end_inset 
24058
24059  included in the distribution
24060 \layout Standard
24061 \align left 
24062
24063 \begin_inset  Tabular
24064 <lyxtabular version="3" rows="10" columns="2">
24065 <features>
24066 <column alignment="left" valignment="top" leftline="true" width="0">
24067 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24068 <row topline="true" bottomline="true">
24069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24070 \begin_inset Text
24071
24072 \layout Standard
24073
24074 Subject / Title
24075 \end_inset 
24076 </cell>
24077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24078 \begin_inset Text
24079
24080 \layout Standard
24081
24082 Where to get / filename
24083 \end_inset 
24084 </cell>
24085 </row>
24086 <row topline="true">
24087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24088 \begin_inset Text
24089
24090 \layout Standard
24091
24092 SDCC Compiler User Guide
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 You're reading it right now
24101 \end_inset 
24102 </cell>
24103 </row>
24104 <row topline="true">
24105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24106 \begin_inset Text
24107
24108 \layout Standard
24109
24110 Changelog of SDCC
24111 \end_inset 
24112 </cell>
24113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24114 \begin_inset Text
24115
24116 \layout Standard
24117
24118 sdcc/Changelog
24119 \end_inset 
24120 </cell>
24121 </row>
24122 <row topline="true">
24123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24124 \begin_inset Text
24125
24126 \layout Standard
24127
24128 ASXXXX
24129 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
24130
24131 \end_inset 
24132
24133
24134 \begin_inset LatexCommand \index{Assembler documentation}
24135
24136 \end_inset 
24137
24138  Assemblers and ASLINK
24139 \begin_inset LatexCommand \index{aslink}
24140
24141 \end_inset 
24142
24143
24144 \begin_inset LatexCommand \index{Linker documentation}
24145
24146 \end_inset 
24147
24148  Relocating Linker
24149 \end_inset 
24150 </cell>
24151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24152 \begin_inset Text
24153
24154 \layout Standard
24155
24156 sdcc/as/doc/asxhtm.html
24157 \end_inset 
24158 </cell>
24159 </row>
24160 <row topline="true">
24161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24162 \begin_inset Text
24163
24164 \layout Standard
24165
24166 SDCC regression test
24167 \begin_inset LatexCommand \index{Regression test}
24168
24169 \end_inset 
24170
24171
24172 \end_inset 
24173 </cell>
24174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24175 \begin_inset Text
24176
24177 \layout Standard
24178
24179 sdcc/doc/test_suite_spec.pdf
24180 \end_inset 
24181 </cell>
24182 </row>
24183 <row topline="true">
24184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24185 \begin_inset Text
24186
24187 \layout Standard
24188
24189 Various notes
24190 \end_inset 
24191 </cell>
24192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24193 \begin_inset Text
24194
24195 \layout Standard
24196
24197 sdcc/doc/*
24198 \end_inset 
24199 </cell>
24200 </row>
24201 <row topline="true">
24202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24203 \begin_inset Text
24204
24205 \layout Standard
24206
24207 Notes on debugging with SDCDB
24208 \begin_inset LatexCommand \index{SDCDB (debugger)}
24209
24210 \end_inset 
24211
24212
24213 \end_inset 
24214 </cell>
24215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24216 \begin_inset Text
24217
24218 \layout Standard
24219
24220 sdcc/debugger/README
24221 \end_inset 
24222 </cell>
24223 </row>
24224 <row topline="true">
24225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24226 \begin_inset Text
24227
24228 \layout Standard
24229
24230 Software simulator for microcontrollers
24231 \end_inset 
24232 </cell>
24233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24234 \begin_inset Text
24235
24236 \layout Standard
24237
24238
24239 \family roman 
24240 \series medium 
24241 \shape up 
24242 \size normal 
24243 \emph off 
24244 \bar no 
24245 \noun off 
24246 \color none
24247 sdcc/sim/ucsim/doc
24248 \family default 
24249 \series default 
24250 \shape default 
24251 \size default 
24252 \emph default 
24253 \bar default 
24254 \noun default 
24255 \color default
24256 /index.html
24257 \end_inset 
24258 </cell>
24259 </row>
24260 <row topline="true">
24261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24262 \begin_inset Text
24263
24264 \layout Standard
24265
24266 Temporary notes on the pic16
24267 \begin_inset LatexCommand \index{PIC16}
24268
24269 \end_inset 
24270
24271  port
24272 \end_inset 
24273 </cell>
24274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24275 \begin_inset Text
24276
24277 \layout Standard
24278
24279 sdcc/src/pic16/NOTES
24280 \end_inset 
24281 </cell>
24282 </row>
24283 <row topline="true" bottomline="true">
24284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24285 \begin_inset Text
24286
24287 \layout Standard
24288
24289 SDCC internal documentation (debugging file format)
24290 \end_inset 
24291 </cell>
24292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24293 \begin_inset Text
24294
24295 \layout Standard
24296
24297 sdcc/doc/
24298 \family roman 
24299 \series medium 
24300 \shape up 
24301 \size normal 
24302 \emph off 
24303 \bar no 
24304 \noun off 
24305 \color none
24306 cdbfileformat.pd
24307 \family default 
24308 \series default 
24309 \shape default 
24310 \size default 
24311 \emph default 
24312 \bar default 
24313 \noun default 
24314 \color default
24315 f
24316 \end_inset 
24317 </cell>
24318 </row>
24319 </lyxtabular>
24320
24321 \end_inset 
24322
24323
24324 \newline 
24325
24326 \layout Section
24327
24328 Related open source tools
24329 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24330
24331 \end_inset 
24332
24333
24334 \begin_inset LatexCommand \index{Related tools}
24335
24336 \end_inset 
24337
24338
24339 \layout Standard
24340 \align left 
24341
24342 \begin_inset  Tabular
24343 <lyxtabular version="3" rows="14" columns="3">
24344 <features>
24345 <column alignment="left" valignment="top" leftline="true" width="0pt">
24346 <column alignment="block" valignment="top" leftline="true" width="30line%">
24347 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24348 <row topline="true" bottomline="true">
24349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24350 \begin_inset Text
24351
24352 \layout Standard
24353
24354 Name
24355 \end_inset 
24356 </cell>
24357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24358 \begin_inset Text
24359
24360 \layout Standard
24361
24362 Purpose
24363 \end_inset 
24364 </cell>
24365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24366 \begin_inset Text
24367
24368 \layout Standard
24369
24370 Where to get
24371 \end_inset 
24372 </cell>
24373 </row>
24374 <row topline="true">
24375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24376 \begin_inset Text
24377
24378 \layout Standard
24379
24380 gpsim
24381 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24382
24383 \end_inset 
24384
24385
24386 \end_inset 
24387 </cell>
24388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24389 \begin_inset Text
24390
24391 \layout Standard
24392
24393 PIC simulator
24394 \end_inset 
24395 </cell>
24396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24397 \begin_inset Text
24398
24399 \layout Standard
24400
24401
24402 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24403
24404 \end_inset 
24405
24406
24407 \end_inset 
24408 </cell>
24409 </row>
24410 <row topline="true">
24411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24412 \begin_inset Text
24413
24414 \layout Standard
24415
24416 gputils
24417 \begin_inset LatexCommand \index{gputils (pic tools)}
24418
24419 \end_inset 
24420
24421
24422 \end_inset 
24423 </cell>
24424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24425 \begin_inset Text
24426
24427 \layout Standard
24428
24429 GNU PIC utilities
24430 \end_inset 
24431 </cell>
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24433 \begin_inset Text
24434
24435 \layout Standard
24436
24437
24438 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24439
24440 \end_inset 
24441
24442
24443 \end_inset 
24444 </cell>
24445 </row>
24446 <row topline="true">
24447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24448 \begin_inset Text
24449
24450 \layout Standard
24451
24452 flP5
24453 \end_inset 
24454 </cell>
24455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24456 \begin_inset Text
24457
24458 \layout Standard
24459
24460 PIC programmer
24461 \end_inset 
24462 </cell>
24463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24464 \begin_inset Text
24465
24466 \layout Standard
24467
24468
24469 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24470
24471 \end_inset 
24472
24473
24474 \end_inset 
24475 </cell>
24476 </row>
24477 <row topline="true">
24478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24479 \begin_inset Text
24480
24481 \layout Standard
24482
24483 ec2drv/newcdb
24484 \end_inset 
24485 </cell>
24486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24487 \begin_inset Text
24488
24489 \layout Standard
24490
24491 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24492  (Unix only)
24493 \end_inset 
24494 </cell>
24495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24496 \begin_inset Text
24497
24498 \layout Standard
24499
24500
24501 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24502
24503 \end_inset 
24504
24505
24506 \end_inset 
24507 </cell>
24508 </row>
24509 <row topline="true">
24510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24511 \begin_inset Text
24512
24513 \layout Standard
24514
24515 indent
24516 \begin_inset LatexCommand \index{indent (source formatting tool)}
24517
24518 \end_inset 
24519
24520
24521 \end_inset 
24522 </cell>
24523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24524 \begin_inset Text
24525
24526 \layout Standard
24527
24528 Formats C source - Master of the white spaces
24529 \end_inset 
24530 </cell>
24531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24532 \begin_inset Text
24533
24534 \layout Standard
24535
24536
24537 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
24538
24539 \end_inset 
24540
24541
24542 \end_inset 
24543 </cell>
24544 </row>
24545 <row topline="true">
24546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24547 \begin_inset Text
24548
24549 \layout Standard
24550
24551 srecord
24552 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
24553
24554 \end_inset 
24555
24556
24557 \end_inset 
24558 </cell>
24559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24560 \begin_inset Text
24561
24562 \layout Standard
24563
24564 Object file conversion, checksumming, ...
24565 \end_inset 
24566 </cell>
24567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24568 \begin_inset Text
24569
24570 \layout Standard
24571
24572
24573 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
24574
24575 \end_inset 
24576
24577
24578 \end_inset 
24579 </cell>
24580 </row>
24581 <row topline="true">
24582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24583 \begin_inset Text
24584
24585 \layout Standard
24586
24587 objdump
24588 \begin_inset LatexCommand \index{objdump (tool)}
24589
24590 \end_inset 
24591
24592
24593 \end_inset 
24594 </cell>
24595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24596 \begin_inset Text
24597
24598 \layout Standard
24599
24600 Object file conversion, ...
24601 \end_inset 
24602 </cell>
24603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24604 \begin_inset Text
24605
24606 \layout Standard
24607
24608 Part of binutils (should be there anyway)
24609 \end_inset 
24610 </cell>
24611 </row>
24612 <row topline="true">
24613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24614 \begin_inset Text
24615
24616 \layout Standard
24617
24618 cmon51
24619 \end_inset 
24620 </cell>
24621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24622 \begin_inset Text
24623
24624 \layout Standard
24625
24626 8051 monitor (hex up-/download, single step, disassemble)
24627 \end_inset 
24628 </cell>
24629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24630 \begin_inset Text
24631
24632 \layout Standard
24633
24634
24635 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
24636
24637 \end_inset 
24638
24639
24640 \end_inset 
24641 </cell>
24642 </row>
24643 <row topline="true">
24644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24645 \begin_inset Text
24646
24647 \layout Standard
24648
24649 doxygen
24650 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
24651
24652 \end_inset 
24653
24654
24655 \end_inset 
24656 </cell>
24657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24658 \begin_inset Text
24659
24660 \layout Standard
24661
24662 Source code documentation system
24663 \end_inset 
24664 </cell>
24665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24666 \begin_inset Text
24667
24668 \layout Standard
24669
24670
24671 \begin_inset LatexCommand \url{http://www.doxygen.org}
24672
24673 \end_inset 
24674
24675
24676 \end_inset 
24677 </cell>
24678 </row>
24679 <row topline="true">
24680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24681 \begin_inset Text
24682
24683 \layout Standard
24684
24685 kdevelop
24686 \end_inset 
24687 </cell>
24688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24689 \begin_inset Text
24690
24691 \layout Standard
24692
24693 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
24694 \end_inset 
24695 </cell>
24696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24697 \begin_inset Text
24698
24699 \layout Standard
24700
24701
24702 \begin_inset LatexCommand \url{http://www.kdevelop.org}
24703
24704 \end_inset 
24705
24706
24707 \end_inset 
24708 </cell>
24709 </row>
24710 <row topline="true">
24711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24712 \begin_inset Text
24713
24714 \layout Standard
24715
24716 paulmon
24717 \end_inset 
24718 </cell>
24719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24720 \begin_inset Text
24721
24722 \layout Standard
24723
24724 8051 monitor (hex up-/download, single step, disassemble)
24725 \end_inset 
24726 </cell>
24727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24728 \begin_inset Text
24729
24730 \layout Standard
24731
24732
24733 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
24734
24735 \end_inset 
24736
24737
24738 \end_inset 
24739 </cell>
24740 </row>
24741 <row topline="true">
24742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24743 \begin_inset Text
24744
24745 \layout Standard
24746
24747 splint
24748 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24749
24750 \end_inset 
24751
24752
24753 \end_inset 
24754 </cell>
24755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24756 \begin_inset Text
24757
24758 \layout Standard
24759
24760 Statically checks c sources (see 
24761 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24762
24763 \end_inset 
24764
24765 )
24766 \end_inset 
24767 </cell>
24768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24769 \begin_inset Text
24770
24771 \layout Standard
24772
24773
24774 \begin_inset LatexCommand \url{http://www.splint.org}
24775
24776 \end_inset 
24777
24778
24779 \end_inset 
24780 </cell>
24781 </row>
24782 <row topline="true" bottomline="true">
24783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24784 \begin_inset Text
24785
24786 \layout Standard
24787
24788 ddd
24789 \begin_inset LatexCommand \index{ddd (debugger)}
24790
24791 \end_inset 
24792
24793
24794 \end_inset 
24795 </cell>
24796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24797 \begin_inset Text
24798
24799 \layout Standard
24800
24801 Debugger, serves nicely as GUI to SDCDB
24802 \begin_inset LatexCommand \index{SDCDB (debugger)}
24803
24804 \end_inset 
24805
24806  (Unix only)
24807 \end_inset 
24808 </cell>
24809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24810 \begin_inset Text
24811
24812 \layout Standard
24813
24814
24815 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
24816
24817 \end_inset 
24818
24819
24820 \end_inset 
24821 </cell>
24822 </row>
24823 </lyxtabular>
24824
24825 \end_inset 
24826
24827
24828 \newline 
24829
24830 \layout Section
24831
24832 Related documentation / recommended reading
24833 \layout Standard
24834 \align left 
24835
24836 \begin_inset  Tabular
24837 <lyxtabular version="3" rows="8" columns="3">
24838 <features>
24839 <column alignment="left" valignment="top" leftline="true" width="0pt">
24840 <column alignment="block" valignment="top" leftline="true" width="30line%">
24841 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24842 <row topline="true" bottomline="true">
24843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24844 \begin_inset Text
24845
24846 \layout Standard
24847
24848 Name
24849 \end_inset 
24850 </cell>
24851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24852 \begin_inset Text
24853
24854 \layout Standard
24855
24856 Subject / Title
24857 \end_inset 
24858 </cell>
24859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24860 \begin_inset Text
24861
24862 \layout Standard
24863
24864 Where to get
24865 \end_inset 
24866 </cell>
24867 </row>
24868 <row topline="true">
24869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24870 \begin_inset Text
24871
24872 \layout Standard
24873
24874
24875 \family roman 
24876 \series medium 
24877 \shape up 
24878 \size normal 
24879 \emph off 
24880 \bar no 
24881 \noun off 
24882 \color none
24883 c-refcard.pdf
24884 \end_inset 
24885 </cell>
24886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24887 \begin_inset Text
24888
24889 \layout Standard
24890
24891 C Reference Card
24892 \begin_inset LatexCommand \index{C Reference card}
24893
24894 \end_inset 
24895
24896 , 2 pages
24897 \end_inset 
24898 </cell>
24899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24900 \begin_inset Text
24901
24902 \layout Standard
24903
24904
24905 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
24906
24907 \end_inset 
24908
24909
24910 \end_inset 
24911 </cell>
24912 </row>
24913 <row topline="true">
24914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24915 \begin_inset Text
24916
24917 \layout Standard
24918
24919 c-faq
24920 \end_inset 
24921 </cell>
24922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24923 \begin_inset Text
24924
24925 \layout Standard
24926
24927 C-FAQ-list
24928 \end_inset 
24929 </cell>
24930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24931 \begin_inset Text
24932
24933 \layout Standard
24934
24935
24936 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
24937
24938 \end_inset 
24939
24940
24941 \end_inset 
24942 </cell>
24943 </row>
24944 <row topline="true">
24945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24946 \begin_inset Text
24947
24948 \layout Standard
24949
24950 ISO/IEC 9899:TC2
24951 \end_inset 
24952 </cell>
24953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24954 \begin_inset Text
24955
24956 \layout Standard
24957
24958
24959 \begin_inset Quotes sld
24960 \end_inset 
24961
24962 C-Standard
24963 \begin_inset Quotes srd
24964 \end_inset 
24965
24966
24967 \end_inset 
24968 </cell>
24969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24970 \begin_inset Text
24971
24972 \layout Standard
24973
24974
24975 \size footnotesize 
24976
24977 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
24978
24979 \end_inset 
24980
24981
24982 \end_inset 
24983 </cell>
24984 </row>
24985 <row topline="true">
24986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24987 \begin_inset Text
24988
24989 \layout Standard
24990
24991 ISO/IEC DTR 18037
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
25000 \begin_inset Quotes sld
25001 \end_inset 
25002
25003 Extensions for Embedded C
25004 \begin_inset Quotes srd
25005 \end_inset 
25006
25007
25008 \end_inset 
25009 </cell>
25010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25011 \begin_inset Text
25012
25013 \layout Standard
25014
25015
25016 \size footnotesize 
25017
25018 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
25019
25020 \end_inset 
25021
25022
25023 \end_inset 
25024 </cell>
25025 </row>
25026 <row topline="true">
25027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25028 \begin_inset Text
25029
25030 \layout Standard
25031
25032 \end_inset 
25033 </cell>
25034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25035 \begin_inset Text
25036
25037 \layout Standard
25038
25039 Latest datasheet of the target CPU
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 vendor
25048 \end_inset 
25049 </cell>
25050 </row>
25051 <row topline="true">
25052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25053 \begin_inset Text
25054
25055 \layout Standard
25056
25057 \end_inset 
25058 </cell>
25059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25060 \begin_inset Text
25061
25062 \layout Standard
25063
25064 Revision history of datasheet
25065 \end_inset 
25066 </cell>
25067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25068 \begin_inset Text
25069
25070 \layout Standard
25071
25072 vendor
25073 \end_inset 
25074 </cell>
25075 </row>
25076 <row topline="true" bottomline="true">
25077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25078 \begin_inset Text
25079
25080 \layout Standard
25081
25082 S.
25083  S.
25084  Muchnick
25085 \end_inset 
25086 </cell>
25087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25088 \begin_inset Text
25089
25090 \layout Standard
25091
25092 Advanced Compiler Design and Implementation
25093 \end_inset 
25094 </cell>
25095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25096 \begin_inset Text
25097
25098 \layout Standard
25099
25100 bookstore (very dedicated, probably read other books first)
25101 \end_inset 
25102 </cell>
25103 </row>
25104 </lyxtabular>
25105
25106 \end_inset 
25107
25108
25109 \newline 
25110
25111 \layout Section
25112
25113 Application notes specifically for SDCC
25114 \layout Standard
25115
25116 SDCC makes no claims about the completeness of this list and about up-to-datenes
25117 s or correctness of the application notes
25118 \begin_inset LatexCommand \index{Application notes}
25119
25120 \end_inset 
25121
25122 .
25123 \layout Standard
25124 \align left 
25125
25126 \size footnotesize 
25127
25128 \begin_inset  Tabular
25129 <lyxtabular version="3" rows="7" columns="3">
25130 <features>
25131 <column alignment="block" valignment="top" leftline="true" width="17col%">
25132 <column alignment="block" valignment="top" leftline="true" width="27col%">
25133 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
25134 <row topline="true" bottomline="true">
25135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25136 \begin_inset Text
25137
25138 \layout Standard
25139
25140
25141 \size footnotesize 
25142 Vendor
25143 \end_inset 
25144 </cell>
25145 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25146 \begin_inset Text
25147
25148 \layout Standard
25149
25150
25151 \size footnotesize 
25152 Subject / Title
25153 \end_inset 
25154 </cell>
25155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25156 \begin_inset Text
25157
25158 \layout Standard
25159
25160
25161 \size footnotesize 
25162 Where to get
25163 \end_inset 
25164 </cell>
25165 </row>
25166 <row topline="true">
25167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25168 \begin_inset Text
25169
25170 \layout Standard
25171
25172
25173 \size footnotesize 
25174 Maxim / Dallas
25175 \end_inset 
25176 </cell>
25177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25178 \begin_inset Text
25179
25180 \layout Standard
25181
25182
25183 \size footnotesize 
25184 Using the SDCC Compiler for the DS80C400
25185 \begin_inset LatexCommand \index{DS80C400}
25186
25187 \end_inset 
25188
25189
25190 \end_inset 
25191 </cell>
25192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25193 \begin_inset Text
25194
25195 \layout Standard
25196
25197
25198 \size footnotesize 
25199
25200 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25201
25202 \end_inset 
25203
25204
25205 \end_inset 
25206 </cell>
25207 </row>
25208 <row topline="true">
25209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25210 \begin_inset Text
25211
25212 \layout Standard
25213
25214
25215 \size footnotesize 
25216 Maxim / Dallas
25217 \end_inset 
25218 </cell>
25219 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25220 \begin_inset Text
25221
25222 \layout Standard
25223
25224
25225 \size footnotesize 
25226 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25227 \begin_inset LatexCommand \index{DS89C4x0}
25228
25229 \end_inset 
25230
25231  Family of Microcontrollers
25232 \end_inset 
25233 </cell>
25234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25235 \begin_inset Text
25236
25237 \layout Standard
25238
25239
25240 \size footnotesize 
25241
25242 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25243
25244 \end_inset 
25245
25246
25247 \end_inset 
25248 </cell>
25249 </row>
25250 <row topline="true">
25251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25252 \begin_inset Text
25253
25254 \layout Standard
25255
25256
25257 \size footnotesize 
25258 Silicon Laboratories / Cygnal
25259 \end_inset 
25260 </cell>
25261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25262 \begin_inset Text
25263
25264 \layout Standard
25265
25266
25267 \size footnotesize 
25268 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25269 \end_inset 
25270 </cell>
25271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25272 \begin_inset Text
25273
25274 \layout Standard
25275
25276
25277 \size footnotesize 
25278
25279 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
25280
25281 \end_inset 
25282
25283
25284 \end_inset 
25285 </cell>
25286 </row>
25287 <row topline="true">
25288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25289 \begin_inset Text
25290
25291 \layout Standard
25292
25293
25294 \size footnotesize 
25295 Ramtron / Goal Semiconductor
25296 \end_inset 
25297 </cell>
25298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25299 \begin_inset Text
25300
25301 \layout Standard
25302
25303
25304 \size footnotesize 
25305 Interfacing SDCC to Syn and Textpad
25306 \end_inset 
25307 </cell>
25308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25309 \begin_inset Text
25310
25311 \layout Standard
25312
25313
25314 \size footnotesize 
25315
25316 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25317
25318 \end_inset 
25319
25320
25321 \end_inset 
25322 </cell>
25323 </row>
25324 <row topline="true">
25325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25326 \begin_inset Text
25327
25328 \layout Standard
25329
25330
25331 \size footnotesize 
25332 Ramtron / Goal Semiconductor
25333 \end_inset 
25334 </cell>
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25336 \begin_inset Text
25337
25338 \layout Standard
25339
25340
25341 \size footnotesize 
25342 Installing and Configuring SDCC and Crimson Editor 
25343 \end_inset 
25344 </cell>
25345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25346 \begin_inset Text
25347
25348 \layout Standard
25349
25350
25351 \size footnotesize 
25352
25353 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25354
25355 \end_inset 
25356
25357
25358 \end_inset 
25359 </cell>
25360 </row>
25361 <row topline="true" bottomline="true">
25362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25363 \begin_inset Text
25364
25365 \layout Standard
25366
25367
25368 \size footnotesize 
25369 Texas Instruments
25370 \end_inset 
25371 </cell>
25372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25373 \begin_inset Text
25374
25375 \layout Standard
25376
25377
25378 \size footnotesize 
25379 MSC12xx Programming with SDCC
25380 \end_inset 
25381 </cell>
25382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25383 \begin_inset Text
25384
25385 \layout Standard
25386
25387
25388 \size footnotesize 
25389
25390 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25391
25392 \end_inset 
25393
25394
25395 \end_inset 
25396 </cell>
25397 </row>
25398 </lyxtabular>
25399
25400 \end_inset 
25401
25402
25403 \layout Section
25404
25405 Some Questions
25406 \layout Standard
25407
25408 Some questions answered, some pointers given - it might be time to in turn
25409  ask 
25410 \emph on 
25411 you
25412 \emph default 
25413  some questions: 
25414 \layout Itemize
25415
25416 can you solve your project with the selected microcontroller? Would you
25417  find out early or rather late that your target is too small/slow/whatever?
25418  Can you switch to a slightly better device if it doesn't fit?
25419 \layout Itemize
25420
25421 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25422  and/or another programming language be more adequate? Would an operating
25423  system on the target device help?
25424 \layout Itemize
25425
25426 if you solved the problem, will the marketing department be happy?
25427 \layout Itemize
25428
25429 if the marketing department is happy, will customers be happy?
25430 \layout Itemize
25431
25432 if you're the project manager, marketing department and maybe even the customer
25433  in one person, have you tried to see the project from the outside?
25434 \layout Itemize
25435
25436 is the project done if you think it is done? Or is just that other interface/pro
25437 tocol/feature/configuration/option missing? How about website, manual(s),
25438  internationali(z|s)ation, packaging, labels, 2nd source for components,
25439  electromagnetic compatability/interference, documentation for production,
25440  production test software, update mechanism, patent issues?
25441 \layout Itemize
25442
25443 is your project adequately positioned in that magic triangle: fame, fortune,
25444  fun?
25445 \layout Standard
25446
25447 Maybe not all answers to these questions are known and some answers may
25448  even be 
25449 \emph on 
25450 no
25451 \emph default 
25452 , nevertheless knowing these questions may help you to avoid burnout
25453 \begin_inset Foot
25454 collapsed false
25455
25456 \layout Standard
25457
25458 burnout is bad for electronic devices, programmers and motorcycle tyres
25459 \end_inset 
25460
25461 .
25462  Chances are you didn't want to hear some of them...
25463 \layout Chapter
25464
25465 Support
25466 \begin_inset LatexCommand \index{Support}
25467
25468 \end_inset 
25469
25470
25471 \layout Standard
25472
25473 SDCC has grown to be a large project.
25474  The compiler alone (without the preprocessor, assembler and linker) is
25475  well over 150,000 lines of code (blank stripped).
25476  The open source nature of this project is a key to its continued growth
25477  and support.
25478  You gain the benefit and support of many active software developers and
25479  end users.
25480  Is SDCC perfect? No, that's why we need your help.
25481  The developers take pride in fixing reported bugs.
25482  You can help by reporting the bugs and helping other SDCC users.
25483  There are lots of ways to contribute, and we encourage you to take part
25484  in making SDCC a great software package.
25485  
25486 \layout Standard
25487
25488 The SDCC project is hosted on the SDCC sourceforge site at 
25489 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25490
25491 \end_inset 
25492
25493 .
25494  You'll find the complete set of mailing lists
25495 \begin_inset LatexCommand \index{Mailing list(s)}
25496
25497 \end_inset 
25498
25499 , forums, bug reporting system, patch submission
25500 \begin_inset LatexCommand \index{Patch submission}
25501
25502 \end_inset 
25503
25504  system, download
25505 \begin_inset LatexCommand \index{download}
25506
25507 \end_inset 
25508
25509  area and Subversion code repository
25510 \begin_inset LatexCommand \index{Subversion code repository}
25511
25512 \end_inset 
25513
25514  there.
25515 \layout Section
25516
25517 Reporting Bugs
25518 \begin_inset LatexCommand \index{Bug reporting}
25519
25520 \end_inset 
25521
25522
25523 \begin_inset LatexCommand \index{Reporting bugs}
25524
25525 \end_inset 
25526
25527
25528 \layout Standard
25529
25530 The recommended way of reporting bugs is using the infrastructure of the
25531  sourceforge site.
25532  You can follow the status of bug reports there and have an overview about
25533  the known bugs.
25534 \layout Standard
25535
25536 Bug reports are automatically forwarded to the developer mailing list and
25537  will be fixed ASAP.
25538  When reporting a bug, it is very useful to include a small test program
25539  (the smaller the better) which reproduces the problem.
25540  If you can isolate the problem by looking at the generated assembly code,
25541  this can be very helpful.
25542  Compiling your program with the -
25543 \begin_inset ERT
25544 status Collapsed
25545
25546 \layout Standard
25547
25548 \backslash 
25549 /
25550 \end_inset 
25551
25552 -dumpall
25553 \begin_inset LatexCommand \index{-\/-dumpall}
25554
25555 \end_inset 
25556
25557  option can sometimes be useful in locating optimization problems.
25558  When reporting a bug please make sure you:
25559 \layout Enumerate
25560
25561 Attach the code you are compiling with SDCC.
25562  
25563 \layout Enumerate
25564
25565 Specify the exact command you use to run SDCC, or attach your Makefile.
25566  
25567 \layout Enumerate
25568
25569 Specify the SDCC version (type "
25570 \family sans 
25571 \series bold 
25572 sdcc -v
25573 \family default 
25574 \series default 
25575 "), your platform, and operating system.
25576  
25577 \layout Enumerate
25578
25579 Provide an exact copy of any error message or incorrect output.
25580  
25581 \layout Enumerate
25582
25583 Put something meaningful in the subject of your message.
25584 \layout Standard
25585
25586 Please attempt to include these 5 important parts, as applicable, in all
25587  requests for support or when reporting any problems or bugs with SDCC.
25588  Though this will make your message lengthy, it will greatly improve your
25589  chance that SDCC users and developers will be able to help you.
25590  Some SDCC developers are frustrated by bug reports without code provided
25591  that they can use to reproduce and ultimately fix the problem, so please
25592  be sure to provide sample code if you are reporting a bug! 
25593 \layout Standard
25594
25595 Please have a short check that you are using a recent version of SDCC and
25596  the bug is not yet known.
25597  This is the link for reporting bugs: 
25598 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
25599
25600 \end_inset 
25601
25602 .
25603  With SDCC on average having more than 200 downloads
25604 \begin_inset LatexCommand \index{download}
25605
25606 \end_inset 
25607
25608  on sourceforge per day
25609 \begin_inset Foot
25610 collapsed false
25611
25612 \layout Standard
25613
25614 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
25615  between 2002 and 2005.
25616  This does not include other methods of distribution.
25617 \end_inset 
25618
25619  there must be some users.
25620  So it's not exactly easy to find a new bug.
25621  If you find one we need it: 
25622 \emph on 
25623 reporting bugs is good
25624 \emph default 
25625 .
25626 \layout Section
25627
25628 Requesting Features
25629 \begin_inset LatexCommand \label{sub:Requesting-Features}
25630
25631 \end_inset 
25632
25633
25634 \begin_inset LatexCommand \index{Feature request}
25635
25636 \end_inset 
25637
25638
25639 \begin_inset LatexCommand \index{Requesting features}
25640
25641 \end_inset 
25642
25643
25644 \layout Standard
25645
25646 Like bug reports feature requests are forwarded to the developer mailing
25647  list.
25648  This is the link for requesting features: 
25649 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
25650
25651 \end_inset 
25652
25653 .
25654 \layout Section
25655
25656 Submitting patches
25657 \layout Standard
25658
25659 Like bug reports contributed patches are forwarded to the developer mailing
25660  list.
25661  This is the link for submitting patches
25662 \begin_inset LatexCommand \index{Patch submission}
25663
25664 \end_inset 
25665
25666
25667 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
25668
25669 \end_inset 
25670
25671 .
25672 \layout Standard
25673
25674 You need to specify some parameters to the 
25675 \family typewriter 
25676 diff
25677 \family default 
25678  command for the patches to be useful.
25679  If you modified more than one file a patch created f.e.
25680  with 
25681 \family sans 
25682 \series bold 
25683
25684 \begin_inset Quotes sld
25685 \end_inset 
25686
25687 diff -Naur unmodified_directory modified_directory >my_changes.patch
25688 \begin_inset Quotes srd
25689 \end_inset 
25690
25691
25692 \family default 
25693 \series default 
25694  will be fine, otherwise 
25695 \family sans 
25696 \series bold 
25697
25698 \begin_inset Quotes sld
25699 \end_inset 
25700
25701 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
25702 \begin_inset Quotes srd
25703 \end_inset 
25704
25705
25706 \series default 
25707  
25708 \family default 
25709 will do.
25710 \layout Section
25711
25712 Getting Help
25713 \layout Standard
25714
25715 These links should take you directly to the 
25716 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
25717
25718 \end_inset 
25719
25720
25721 \begin_inset Foot
25722 collapsed false
25723
25724 \layout Standard
25725
25726 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
25727  automated messages (mid 2003)
25728 \end_inset 
25729
25730  and the 
25731 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
25732
25733 \end_inset 
25734
25735 , lists
25736 \begin_inset LatexCommand \index{Mailing list(s)}
25737
25738 \end_inset 
25739
25740  and forums are archived and searchable so if you are lucky someone already
25741  had a similar problem.
25742  While mails to the lists themselves are delivered promptly their web front
25743  end on sourceforge sometimes shows a severe time lag (up to several weeks),
25744  if you're seriously using SDCC please consider subscribing to the lists.
25745 \layout Section
25746
25747 ChangeLog
25748 \layout Standard
25749
25750 You can follow the status of the Subversion version
25751 \begin_inset LatexCommand \index{version}
25752
25753 \end_inset 
25754
25755  of SDCC by watching the Changelog
25756 \begin_inset LatexCommand \index{Changelog}
25757
25758 \end_inset 
25759
25760  in the Subversion repository
25761 \size footnotesize 
25762  
25763 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
25764
25765 \end_inset 
25766
25767 .
25768 \layout Section
25769
25770 Subversion Source Code Repository
25771 \layout Standard
25772
25773 The output of 
25774 \family sans 
25775 \series bold 
25776 sdcc --version
25777 \family default 
25778 \series default 
25779  or the filenames of the snapshot versions of SDCC include date and its
25780  Subversion
25781 \begin_inset LatexCommand \index{Subversion code repository}
25782
25783 \end_inset 
25784
25785  number.
25786  Subversion allows to download the source of recent or previous versions
25787  
25788 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
25789
25790 \end_inset 
25791
25792  (by number or by date).
25793  An on-line source code browser and detailled instructions are also available
25794  there.
25795  SDCC versions starting from 1999 up to now are available (currently the
25796  versions prior to the conversion from cvs
25797 \begin_inset LatexCommand \index{cvs (see Subversion)}
25798
25799 \end_inset 
25800
25801  to Subversion (April 2006) are either by accessible by Subversion or by
25802  cvs).
25803 \layout Section
25804
25805 Release policy
25806 \begin_inset LatexCommand \index{Release policy}
25807
25808 \end_inset 
25809
25810
25811 \layout Standard
25812
25813 Historically there often were long delays between official releases and
25814  the sourceforge download area tends to get not updated at all.
25815  Excuses in the past might have referred to problems with live range analysis,
25816  but as this was fixed a while ago, the current problem is that another
25817  excuse has to be found.
25818  Kidding aside, we have to get better there! On the other hand there are
25819  daily snapshots available at 
25820 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
25821
25822 \end_inset 
25823
25824 , and you can always build the very last version (hopefully with many bugs
25825  fixed, and features added) from the source code available at 
25826 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
25827
25828 \end_inset 
25829
25830 .
25831 \layout Section
25832
25833 Examples
25834 \begin_inset LatexCommand \index{Examples}
25835
25836 \end_inset 
25837
25838
25839 \layout Standard
25840
25841 You'll find some small examples in the directory 
25842 \emph on 
25843 sdcc/device/examples/.
25844  
25845 \emph default 
25846 More examples and libraries are available at
25847 \emph on 
25848  The SDCC Open Knowledge Resource 
25849 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
25850
25851 \end_inset 
25852
25853  
25854 \emph default 
25855 web site or at 
25856 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
25857
25858 \end_inset 
25859
25860 .
25861 \layout Comment
25862
25863 I did insert a reference to Paul's web site here although it seems rather
25864  dedicated to a specific 8032 board (I think it's okay because it f.e.
25865  shows LCD/Harddisc interface and has a free 8051 monitor.
25866  Independent 8032 board vendors face hard competition of heavily subsidized
25867  development boards anyway).
25868 \layout Comment
25869
25870 Maybe we should include some links to real world applications.
25871  Preferably pointer to pointers (one for each architecture) so this stays
25872  manageable here?
25873 \layout Section
25874
25875 Quality control
25876 \begin_inset LatexCommand \index{Quality control}
25877
25878 \end_inset 
25879
25880
25881 \layout Standard
25882
25883 The compiler is passed through nightly compile and build checks.
25884  The so called 
25885 \shape italic 
25886 regression tests
25887 \shape default 
25888
25889 \begin_inset LatexCommand \index{Regression test}
25890
25891 \end_inset 
25892
25893  check that SDCC itself compiles flawlessly on several platforms and checks
25894  the quality of the code generated by SDCC by running the code through simulator
25895 s.
25896  There is a separate document 
25897 \shape italic 
25898 test_suite.pdf
25899 \begin_inset LatexCommand \index{Test suite}
25900
25901 \end_inset 
25902
25903
25904 \shape default 
25905  about this.
25906 \layout Standard
25907
25908 You'll find the test code in the directory 
25909 \shape italic 
25910 sdcc/support/regression
25911 \shape default 
25912 .
25913  You can run these tests manually by running 
25914 \family sans 
25915 make
25916 \family default 
25917  in this directory (or f.e.
25918  
25919 \family sans 
25920 \series bold 
25921
25922 \begin_inset Quotes sld
25923 \end_inset 
25924
25925 make test-mcs51
25926 \begin_inset Quotes srd
25927 \end_inset 
25928
25929
25930 \family default 
25931 \series default 
25932  if you don't want to run the complete tests).
25933  The test code might also be interesting if you want to look for examples
25934 \begin_inset LatexCommand \index{Examples}
25935
25936 \end_inset 
25937
25938  checking corner cases of SDCC or if you plan to submit patches
25939 \begin_inset LatexCommand \index{Patch submission}
25940
25941 \end_inset 
25942
25943 .
25944 \layout Standard
25945
25946 The pic port uses a different set of regression tests, you'll find them
25947  in the directory 
25948 \shape italic 
25949 sdcc/src/regression
25950 \shape default 
25951 .
25952 \layout Section
25953
25954 Use of SDCC in Education
25955 \layout Standard
25956
25957 In short: 
25958 \emph on 
25959 highly
25960 \emph default 
25961  encouraged
25962 \begin_inset Foot
25963 collapsed false
25964
25965 \layout Standard
25966
25967 the phrase "use in education" might evoke the association "
25968 \emph on 
25969 only
25970 \emph default 
25971  fit for use in education".
25972  This connotation is not intended but nevertheless risked as the licensing
25973  of SDCC makes it difficult to offer educational discounts
25974 \end_inset 
25975
25976 .
25977  If your rationales are to:
25978 \layout Enumerate
25979
25980 give students a chance to understand the 
25981 \emph on 
25982 complete
25983 \emph default 
25984  steps of code generation
25985 \layout Enumerate
25986
25987 have a curriculum that can be extended for years.
25988  Then you could use an fpga board as target and your curriculum will seamlessly
25989  extend from logic synthesis (
25990 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
25991
25992 \end_inset 
25993
25994
25995 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
25996
25997 \end_inset 
25998
25999 ), over assembly programming, to C to FPGA compilers (
26000 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
26001
26002 \end_inset 
26003
26004 ) and to C.
26005 \layout Enumerate
26006
26007 be able to insert excursions about skills like using a revision control
26008  system, submitting/applying patches, using a type-setting (as opposed to
26009  word-processing) engine LyX/LaTeX, using 
26010 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
26011
26012 \end_inset 
26013
26014 , following some 
26015 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
26016
26017 \end_inset 
26018
26019 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
26020  Source Software, CPU simulation, compiler regression tests
26021 \begin_inset LatexCommand \index{Regression test}
26022
26023 \end_inset 
26024
26025 .
26026  
26027 \newline 
26028 And if there should be a shortage of ideas then you can always point students
26029  to the ever-growing feature request list 
26030 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26031
26032 \end_inset 
26033
26034 .
26035 \layout Enumerate
26036
26037 not tie students to a specific host platform and instead allow them to use
26038  a host platform of 
26039 \emph on 
26040 their
26041 \emph default 
26042  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
26043  eventually 
26044 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
26045
26046 \end_inset 
26047
26048 )
26049 \layout Enumerate
26050
26051 not encourage students to use illegal copies of educational software
26052 \layout Enumerate
26053
26054 be immune to licensing/availability/price changes of the chosen tool chain
26055 \layout Enumerate
26056
26057 be able to change to a new target platform without having to adopt a new
26058  tool chain
26059 \layout Enumerate
26060
26061 have complete control over and insight into the tool chain
26062 \layout Enumerate
26063
26064 make your students aware about the pros and cons of open source software
26065  development
26066 \layout Enumerate
26067
26068 give back to the public as you are probably at least partially publically
26069  funded
26070 \layout Enumerate
26071
26072 give students a chance to publically prove their skills and to possibly
26073  see a world wide impact
26074 \layout Standard
26075
26076 then SDCC is probably among the first choices.
26077  Well, probably SDCC might be the only choice.
26078 \layout Chapter
26079 \pagebreak_top 
26080 SDCC Technical Data
26081 \layout Section
26082
26083 Optimizations
26084 \begin_inset LatexCommand \index{Optimizations}
26085
26086 \end_inset 
26087
26088
26089 \layout Standard
26090
26091 SDCC performs a host of standard optimizations in addition to some MCU specific
26092  optimizations.
26093  
26094 \layout Subsection
26095
26096 Sub-expression Elimination
26097 \begin_inset LatexCommand \index{Subexpression elimination}
26098
26099 \end_inset 
26100
26101
26102 \layout Standard
26103
26104 The compiler does local and 
26105 \emph on 
26106 g
26107 \emph default 
26108 lobal 
26109 \emph on 
26110 c
26111 \emph default 
26112 ommon 
26113 \emph on 
26114 s
26115 \emph default 
26116 ubexpression 
26117 \emph on 
26118 e
26119 \emph default 
26120 limination, e.g.: 
26121 \layout Verse
26122
26123
26124 \family typewriter 
26125 i = x + y + 1; 
26126 \newline 
26127 j = x + y;
26128 \layout Standard
26129
26130 will be translated to
26131 \layout Verse
26132
26133
26134 \family typewriter 
26135 iTemp = x + y; 
26136 \newline 
26137 i = iTemp + 1; 
26138 \newline 
26139 j = iTemp;
26140 \layout Standard
26141
26142 Some subexpressions are not as obvious as the above example, e.g.:
26143 \layout Verse
26144
26145
26146 \family typewriter 
26147 a->b[i].c = 10; 
26148 \newline 
26149 a->b[i].d = 11;
26150 \layout Standard
26151
26152 In this case the address arithmetic a->b[i] will be computed only once;
26153  the equivalent code in C would be.
26154 \layout Verse
26155
26156
26157 \family typewriter 
26158 iTemp = a->b[i]; 
26159 \newline 
26160 iTemp.c = 10; 
26161 \newline 
26162 iTemp.d = 11;
26163 \layout Standard
26164
26165 The compiler will try to keep these temporary variables in registers.
26166 \layout Subsection
26167
26168 Dead-Code Elimination
26169 \begin_inset LatexCommand \index{Dead-code elimination}
26170
26171 \end_inset 
26172
26173
26174 \layout Verse
26175
26176
26177 \family typewriter 
26178 int global;
26179 \newline 
26180
26181 \newline 
26182 void f () { 
26183 \newline 
26184 \SpecialChar ~
26185 \SpecialChar ~
26186 int i; 
26187 \newline 
26188 \SpecialChar ~
26189 \SpecialChar ~
26190 i = 1; \SpecialChar ~
26191 \SpecialChar ~
26192 \SpecialChar ~
26193 \SpecialChar ~
26194 \SpecialChar ~
26195 /* dead store */ 
26196 \newline 
26197 \SpecialChar ~
26198 \SpecialChar ~
26199 global = 1;\SpecialChar ~
26200 /* dead store */ 
26201 \newline 
26202 \SpecialChar ~
26203 \SpecialChar ~
26204 global = 2; 
26205 \newline 
26206 \SpecialChar ~
26207 \SpecialChar ~
26208 return; 
26209 \newline 
26210 \SpecialChar ~
26211 \SpecialChar ~
26212 global = 3;\SpecialChar ~
26213 /* unreachable */ 
26214 \newline 
26215 }
26216 \layout Standard
26217
26218 will be changed to
26219 \layout Verse
26220
26221
26222 \family typewriter 
26223 int global;
26224 \newline 
26225
26226 \newline 
26227 void f () {
26228 \newline 
26229 \SpecialChar ~
26230 \SpecialChar ~
26231 global = 2; 
26232 \newline 
26233 }
26234 \layout Subsection
26235
26236 Copy-Propagation
26237 \begin_inset LatexCommand \index{Copy propagation}
26238
26239 \end_inset 
26240
26241
26242 \layout Verse
26243
26244
26245 \family typewriter 
26246 int f() { 
26247 \newline 
26248 \SpecialChar ~
26249 \SpecialChar ~
26250 int i, j; 
26251 \newline 
26252 \SpecialChar ~
26253 \SpecialChar ~
26254 i = 10; 
26255 \newline 
26256 \SpecialChar ~
26257 \SpecialChar ~
26258 j = i; 
26259 \newline 
26260 \SpecialChar ~
26261 \SpecialChar ~
26262 return j; 
26263 \newline 
26264 }
26265 \layout Standard
26266
26267 will be changed to 
26268 \layout Verse
26269
26270
26271 \family typewriter 
26272 int f() { 
26273 \newline 
26274 \SpecialChar ~
26275 \SpecialChar ~
26276 int i, j; 
26277 \newline 
26278 \SpecialChar ~
26279 \SpecialChar ~
26280 i = 10; 
26281 \newline 
26282 \SpecialChar ~
26283 \SpecialChar ~
26284 j = 10; 
26285 \newline 
26286 \SpecialChar ~
26287 \SpecialChar ~
26288 return 10; 
26289 \newline 
26290 }
26291 \layout Standard
26292
26293 Note: the dead stores created by this copy propagation will be eliminated
26294  by dead-code elimination.
26295 \layout Subsection
26296
26297 Loop Optimizations
26298 \begin_inset LatexCommand \index{Loop optimization}
26299
26300 \end_inset 
26301
26302
26303 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26304
26305 \end_inset 
26306
26307
26308 \layout Standard
26309
26310 Two types of loop optimizations are done by SDCC 
26311 \emph on 
26312 loop invariant
26313 \emph default 
26314  lifting and
26315 \emph on 
26316  strength reduction
26317 \emph default 
26318  of loop induction variables.
26319  In addition to the strength reduction the optimizer marks the induction
26320  variables and the register allocator tries to keep the induction variables
26321  in registers for the duration of the loop.
26322  Because of this preference of the register allocator
26323 \begin_inset LatexCommand \index{Register allocation}
26324
26325 \end_inset 
26326
26327 , loop induction optimization causes an increase in register pressure, which
26328  may cause unwanted spilling of other temporary variables into the stack
26329 \begin_inset LatexCommand \index{stack}
26330
26331 \end_inset 
26332
26333  / data space.
26334  The compiler will generate a warning message when it is forced to allocate
26335  extra space either on the stack or data space.
26336  If this extra space allocation is undesirable then induction optimization
26337  can be eliminated either for the entire source file (with -
26338 \begin_inset ERT
26339 status Collapsed
26340
26341 \layout Standard
26342
26343 \backslash 
26344 /
26345 \end_inset 
26346
26347 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26348 noinduction
26349 \begin_inset LatexCommand \index{\#pragma noinduction}
26350
26351 \end_inset 
26352
26353 .
26354 \newline 
26355
26356 \newline 
26357 Loop Invariant:
26358 \layout Verse
26359
26360
26361 \family typewriter 
26362 for (i = 0 ; i < 100 ; i ++) 
26363 \newline 
26364 \SpecialChar ~
26365 \SpecialChar ~
26366 \SpecialChar ~
26367 \SpecialChar ~
26368 f += k + l;
26369 \layout Standard
26370
26371 changed to
26372 \layout Verse
26373
26374
26375 \family typewriter 
26376 itemp = k + l; 
26377 \newline 
26378 for (i = 0; i < 100; i++) 
26379 \newline 
26380 \SpecialChar ~
26381 \SpecialChar ~
26382 \SpecialChar ~
26383 \SpecialChar ~
26384 f += itemp;
26385 \layout Standard
26386
26387 As mentioned previously some loop invariants are not as apparent, all static
26388  address computations are also moved out of the loop.
26389 \newline 
26390
26391 \newline 
26392 Strength Reduction
26393 \begin_inset LatexCommand \index{Strength reduction}
26394
26395 \end_inset 
26396
26397 , this optimization substitutes an expression by a cheaper expression:
26398 \layout Verse
26399
26400
26401 \family typewriter 
26402 for (i=0;i < 100; i++)
26403 \newline 
26404 \SpecialChar ~
26405 \SpecialChar ~
26406 \SpecialChar ~
26407 \SpecialChar ~
26408 ar[i*5] = i*3;
26409 \layout Standard
26410
26411 changed to
26412 \layout Verse
26413
26414
26415 \family typewriter 
26416 itemp1 = 0; 
26417 \newline 
26418 itemp2 = 0; 
26419 \newline 
26420 for (i=0;i< 100;i++) { 
26421 \newline 
26422 \SpecialChar ~
26423 \SpecialChar ~
26424 \SpecialChar ~
26425 \SpecialChar ~
26426 ar[itemp1] = itemp2; 
26427 \newline 
26428 \SpecialChar ~
26429 \SpecialChar ~
26430 \SpecialChar ~
26431 \SpecialChar ~
26432 itemp1 += 5; 
26433 \newline 
26434 \SpecialChar ~
26435 \SpecialChar ~
26436 \SpecialChar ~
26437 \SpecialChar ~
26438 itemp2 += 3; 
26439 \newline 
26440 }
26441 \layout Standard
26442
26443 The more expensive multiplication
26444 \begin_inset LatexCommand \index{Multiplication}
26445
26446 \end_inset 
26447
26448  is changed to a less expensive addition.
26449 \layout Subsection
26450
26451 Loop Reversing
26452 \begin_inset LatexCommand \index{Loop reversing}
26453
26454 \end_inset 
26455
26456
26457 \layout Standard
26458
26459 This optimization is done to reduce the overhead of checking loop boundaries
26460  for every iteration.
26461  Some simple loops can be reversed and implemented using a 
26462 \begin_inset Quotes eld
26463 \end_inset 
26464
26465 decrement and jump if not zero
26466 \begin_inset Quotes erd
26467 \end_inset 
26468
26469  instruction.
26470  SDCC checks for the following criterion to determine if a loop is reversible
26471  (note: more sophisticated compilers use data-dependency analysis to make
26472  this determination, SDCC uses a more simple minded analysis).
26473 \layout Itemize
26474
26475 The 'for' loop is of the form 
26476 \newline 
26477
26478 \newline 
26479
26480 \family typewriter 
26481 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
26482  += 1])
26483 \newline 
26484 \SpecialChar ~
26485 \SpecialChar ~
26486 \SpecialChar ~
26487 \SpecialChar ~
26488 <for body>
26489 \layout Itemize
26490
26491 The <for body> does not contain 
26492 \begin_inset Quotes eld
26493 \end_inset 
26494
26495 continue
26496 \begin_inset Quotes erd
26497 \end_inset 
26498
26499  or 'break
26500 \begin_inset Quotes erd
26501 \end_inset 
26502
26503 .
26504 \layout Itemize
26505
26506 All goto's are contained within the loop.
26507 \layout Itemize
26508
26509 No function calls within the loop.
26510 \layout Itemize
26511
26512 The loop control variable <sym> is not assigned any value within the loop
26513 \layout Itemize
26514
26515 The loop control variable does NOT participate in any arithmetic operation
26516  within the loop.
26517 \layout Itemize
26518
26519 There are NO switch statements in the loop.
26520 \layout Subsection
26521
26522 Algebraic Simplifications
26523 \layout Standard
26524
26525 SDCC does numerous algebraic simplifications, the following is a small sub-set
26526  of these optimizations.
26527 \layout Verse
26528
26529
26530 \family typewriter 
26531 i = j + 0;\SpecialChar ~
26532 \SpecialChar ~
26533 \SpecialChar ~
26534 \SpecialChar ~
26535  /* changed to: */\SpecialChar ~
26536 \SpecialChar ~
26537 \SpecialChar ~
26538 \SpecialChar ~
26539  i = j; 
26540 \newline 
26541 i /= 2;\SpecialChar ~
26542 \SpecialChar ~
26543 \SpecialChar ~
26544 \SpecialChar ~
26545 \SpecialChar ~
26546 \SpecialChar ~
26547 \SpecialChar ~
26548  /* changed to: */\SpecialChar ~
26549 \SpecialChar ~
26550 \SpecialChar ~
26551 \SpecialChar ~
26552  i >>= 1; 
26553 \newline 
26554 i = j - j;\SpecialChar ~
26555 \SpecialChar ~
26556 \SpecialChar ~
26557 \SpecialChar ~
26558  /* changed to: */\SpecialChar ~
26559 \SpecialChar ~
26560 \SpecialChar ~
26561 \SpecialChar ~
26562  i = 0; 
26563 \newline 
26564 i = j / 1;\SpecialChar ~
26565 \SpecialChar ~
26566 \SpecialChar ~
26567 \SpecialChar ~
26568  /* changed to: */\SpecialChar ~
26569 \SpecialChar ~
26570 \SpecialChar ~
26571 \SpecialChar ~
26572  i = j;
26573 \layout Standard
26574
26575 Note the subexpressions
26576 \begin_inset LatexCommand \index{Subexpression}
26577
26578 \end_inset 
26579
26580  given above are generally introduced by macro expansions or as a result
26581  of copy/constant propagation.
26582 \layout Subsection
26583
26584 'switch' Statements
26585 \begin_inset LatexCommand \label{sub:'switch'-Statements}
26586
26587 \end_inset 
26588
26589
26590 \begin_inset LatexCommand \index{switch statement}
26591
26592 \end_inset 
26593
26594
26595 \layout Standard
26596
26597 SDCC can optimize switch statements to jump tables
26598 \begin_inset LatexCommand \index{jump tables}
26599
26600 \end_inset 
26601
26602 .
26603  It makes the decision based on an estimate of the generated code size.
26604  SDCC is quite liberal in the requirements for jump table generation: 
26605 \layout Itemize
26606
26607 The labels need not be in order, and the starting number need not be one
26608  or zero, the case labels are in numerical sequence or not too many case
26609  labels are missing.
26610 \begin_deeper 
26611 \layout Verse
26612
26613
26614 \family typewriter 
26615 switch(i) {\SpecialChar ~
26616 \SpecialChar ~
26617 \SpecialChar ~
26618 \SpecialChar ~
26619 \SpecialChar ~
26620 \SpecialChar ~
26621 \SpecialChar ~
26622 \SpecialChar ~
26623 \SpecialChar ~
26624 \SpecialChar ~
26625 \SpecialChar ~
26626 \SpecialChar ~
26627 \SpecialChar ~
26628 \SpecialChar ~
26629 \SpecialChar ~
26630 \SpecialChar ~
26631 \SpecialChar ~
26632 \SpecialChar ~
26633 \SpecialChar ~
26634 \SpecialChar ~
26635 \SpecialChar ~
26636 \SpecialChar ~
26637 \SpecialChar ~
26638 \SpecialChar ~
26639 \SpecialChar ~
26640 \SpecialChar ~
26641 switch (i) { 
26642 \newline 
26643 \SpecialChar ~
26644 \SpecialChar ~
26645 \SpecialChar ~
26646 case 4: ...\SpecialChar ~
26647 \SpecialChar ~
26648 \SpecialChar ~
26649 \SpecialChar ~
26650 \SpecialChar ~
26651 \SpecialChar ~
26652 \SpecialChar ~
26653 \SpecialChar ~
26654 \SpecialChar ~
26655 \SpecialChar ~
26656 \SpecialChar ~
26657 \SpecialChar ~
26658 \SpecialChar ~
26659 \SpecialChar ~
26660 \SpecialChar ~
26661 \SpecialChar ~
26662 \SpecialChar ~
26663 \SpecialChar ~
26664 \SpecialChar ~
26665 \SpecialChar ~
26666 \SpecialChar ~
26667 \SpecialChar ~
26668 \SpecialChar ~
26669 \SpecialChar ~
26670 \SpecialChar ~
26671 \SpecialChar ~
26672 case 0: ...
26673  
26674 \newline 
26675 \SpecialChar ~
26676 \SpecialChar ~
26677 \SpecialChar ~
26678 case 5: ...\SpecialChar ~
26679 \SpecialChar ~
26680 \SpecialChar ~
26681 \SpecialChar ~
26682 \SpecialChar ~
26683 \SpecialChar ~
26684 \SpecialChar ~
26685 \SpecialChar ~
26686 \SpecialChar ~
26687 \SpecialChar ~
26688 \SpecialChar ~
26689 \SpecialChar ~
26690 \SpecialChar ~
26691 \SpecialChar ~
26692 \SpecialChar ~
26693 \SpecialChar ~
26694 \SpecialChar ~
26695 \SpecialChar ~
26696 \SpecialChar ~
26697 \SpecialChar ~
26698 \SpecialChar ~
26699 \SpecialChar ~
26700 \SpecialChar ~
26701 \SpecialChar ~
26702 \SpecialChar ~
26703 \SpecialChar ~
26704 case 1: ...
26705  
26706 \newline 
26707 \SpecialChar ~
26708 \SpecialChar ~
26709 \SpecialChar ~
26710 case 3: ...\SpecialChar ~
26711 \SpecialChar ~
26712 \SpecialChar ~
26713 \SpecialChar ~
26714 \SpecialChar ~
26715 \SpecialChar ~
26716 \SpecialChar ~
26717 \SpecialChar ~
26718 \SpecialChar ~
26719 \SpecialChar ~
26720 \SpecialChar ~
26721 \SpecialChar ~
26722 \SpecialChar ~
26723 \SpecialChar ~
26724 \SpecialChar ~
26725 \SpecialChar ~
26726 \SpecialChar ~
26727 \SpecialChar ~
26728 \SpecialChar ~
26729 \SpecialChar ~
26730 \SpecialChar ~
26731 \SpecialChar ~
26732 \SpecialChar ~
26733 \SpecialChar ~
26734 \SpecialChar ~
26735 \SpecialChar ~
26736
26737 \newline 
26738 \SpecialChar ~
26739 \SpecialChar ~
26740 \SpecialChar ~
26741 case 6: ...\SpecialChar ~
26742 \SpecialChar ~
26743 \SpecialChar ~
26744 \SpecialChar ~
26745 \SpecialChar ~
26746 \SpecialChar ~
26747 \SpecialChar ~
26748 \SpecialChar ~
26749 \SpecialChar ~
26750 \SpecialChar ~
26751 \SpecialChar ~
26752 \SpecialChar ~
26753 \SpecialChar ~
26754 \SpecialChar ~
26755 \SpecialChar ~
26756 \SpecialChar ~
26757 \SpecialChar ~
26758 \SpecialChar ~
26759 \SpecialChar ~
26760 \SpecialChar ~
26761 \SpecialChar ~
26762 \SpecialChar ~
26763 \SpecialChar ~
26764 \SpecialChar ~
26765 \SpecialChar ~
26766 \SpecialChar ~
26767 case 3: ...
26768  
26769 \newline 
26770 \SpecialChar ~
26771 \SpecialChar ~
26772 \SpecialChar ~
26773 case 7: ...\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 \SpecialChar ~
26793 \SpecialChar ~
26794 \SpecialChar ~
26795 \SpecialChar ~
26796 \SpecialChar ~
26797 \SpecialChar ~
26798 \SpecialChar ~
26799 case 4: ...
26800  
26801 \newline 
26802 \SpecialChar ~
26803 \SpecialChar ~
26804 \SpecialChar ~
26805 case 8: ...\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 \SpecialChar ~
26824 \SpecialChar ~
26825 \SpecialChar ~
26826 \SpecialChar ~
26827 \SpecialChar ~
26828 \SpecialChar ~
26829 \SpecialChar ~
26830 \SpecialChar ~
26831 case 5: ...
26832  
26833 \newline 
26834 \SpecialChar ~
26835 \SpecialChar ~
26836 \SpecialChar ~
26837 case 9: ...\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 \SpecialChar ~
26856 \SpecialChar ~
26857 \SpecialChar ~
26858 \SpecialChar ~
26859 \SpecialChar ~
26860 \SpecialChar ~
26861 \SpecialChar ~
26862 \SpecialChar ~
26863 case 6: ...
26864  
26865 \newline 
26866 \SpecialChar ~
26867 \SpecialChar ~
26868 \SpecialChar ~
26869 case 10: ...\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 \SpecialChar ~
26888 \SpecialChar ~
26889 \SpecialChar ~
26890 \SpecialChar ~
26891 \SpecialChar ~
26892 \SpecialChar ~
26893 \SpecialChar ~
26894 case 7: ...
26895  
26896 \newline 
26897 \SpecialChar ~
26898 \SpecialChar ~
26899 \SpecialChar ~
26900 case 11: ...\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 \SpecialChar ~
26919 \SpecialChar ~
26920 \SpecialChar ~
26921 \SpecialChar ~
26922 \SpecialChar ~
26923 \SpecialChar ~
26924 \SpecialChar ~
26925 case 8: ...
26926  
26927 \newline 
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 \SpecialChar ~
26951 \SpecialChar ~
26952 \SpecialChar ~
26953 \SpecialChar ~
26954 \SpecialChar ~
26955 \SpecialChar ~
26956 \SpecialChar ~
26957 \SpecialChar ~
26958 \SpecialChar ~
26959 \SpecialChar ~
26960 \SpecialChar ~
26961 \SpecialChar ~
26962 \SpecialChar ~
26963 \SpecialChar ~
26964 }
26965 \layout Standard
26966
26967 Both the above switch statements will be implemented using a jump-table.
26968  The example to the right side is slightly more efficient as the check for
26969  the lower boundary of the jump-table is not needed.
26970 \end_deeper 
26971 \layout Itemize
26972
26973 The number of case labels is not larger than supported by the target architectur
26974 e.
26975 \layout Itemize
26976
26977 If the case labels are not in numerical sequence ('gaps' between cases)
26978  SDCC checks whether a jump table with additionally inserted dummy cases
26979  is still attractive.
26980  
26981 \layout Itemize
26982
26983 If the starting number is not zero and a check for the lower boundary of
26984  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
26985  ...
26986  .
26987 \layout Standard
26988
26989 Switch statements which have large gaps in the numeric sequence or those
26990  that have too many case labels can be split into more than one switch statement
26991  for efficient code generation, e.g.:
26992 \layout Verse
26993
26994
26995 \family typewriter 
26996 switch (i) { 
26997 \newline 
26998 \SpecialChar ~
26999 \SpecialChar ~
27000 case 1: ...
27001  
27002 \newline 
27003 \SpecialChar ~
27004 \SpecialChar ~
27005 case 2: ...
27006  
27007 \newline 
27008 \SpecialChar ~
27009 \SpecialChar ~
27010 case 3: ...
27011  
27012 \newline 
27013 \SpecialChar ~
27014 \SpecialChar ~
27015 case 4: ...
27016  
27017 \newline 
27018 \SpecialChar ~
27019 \SpecialChar ~
27020 case 5: ...
27021  
27022 \newline 
27023 \SpecialChar ~
27024 \SpecialChar ~
27025 case 6: ...
27026  
27027 \newline 
27028 \SpecialChar ~
27029 \SpecialChar ~
27030 case 7: ...
27031  
27032 \newline 
27033 \SpecialChar ~
27034 \SpecialChar ~
27035 case 101: ...
27036  
27037 \newline 
27038 \SpecialChar ~
27039 \SpecialChar ~
27040 case 102: ...
27041  
27042 \newline 
27043 \SpecialChar ~
27044 \SpecialChar ~
27045 case 103: ...
27046  
27047 \newline 
27048 \SpecialChar ~
27049 \SpecialChar ~
27050 case 104: ...
27051  
27052 \newline 
27053 \SpecialChar ~
27054 \SpecialChar ~
27055 case 105: ...
27056  
27057 \newline 
27058 \SpecialChar ~
27059 \SpecialChar ~
27060 case 106: ...
27061  
27062 \newline 
27063 \SpecialChar ~
27064 \SpecialChar ~
27065 case 107: ...
27066  
27067 \newline 
27068 }
27069 \layout Standard
27070
27071 If the above switch statement is broken down into two switch statements
27072 \layout Verse
27073
27074
27075 \family typewriter 
27076 switch (i) { 
27077 \newline 
27078 \SpecialChar ~
27079 \SpecialChar ~
27080 case 1: ...
27081  
27082 \newline 
27083 \SpecialChar ~
27084 \SpecialChar ~
27085 case 2: ...
27086  
27087 \newline 
27088 \SpecialChar ~
27089 \SpecialChar ~
27090 case 3: ...
27091  
27092 \newline 
27093 \SpecialChar ~
27094 \SpecialChar ~
27095 case 4: ...
27096  
27097 \newline 
27098 \SpecialChar ~
27099 \SpecialChar ~
27100 case 5: ...
27101  
27102 \newline 
27103 \SpecialChar ~
27104 \SpecialChar ~
27105 case 6: ...
27106  
27107 \newline 
27108 \SpecialChar ~
27109 \SpecialChar ~
27110 case 7: ...
27111  
27112 \newline 
27113 }
27114 \layout Standard
27115
27116 and
27117 \layout Verse
27118
27119
27120 \family typewriter 
27121 switch (i) { 
27122 \newline 
27123 \SpecialChar ~
27124 \SpecialChar ~
27125 case 101: ...
27126  
27127 \newline 
27128 \SpecialChar ~
27129 \SpecialChar ~
27130 case 102: ...
27131  
27132 \newline 
27133 \SpecialChar ~
27134 \SpecialChar ~
27135 case 103: ...
27136  
27137 \newline 
27138 \SpecialChar ~
27139 \SpecialChar ~
27140 case 104: ...
27141  
27142 \newline 
27143 \SpecialChar ~
27144 \SpecialChar ~
27145 case 105: ...
27146  
27147 \newline 
27148 \SpecialChar ~
27149 \SpecialChar ~
27150 case 106: ...
27151  
27152 \newline 
27153 \SpecialChar ~
27154 \SpecialChar ~
27155 case 107: ...
27156  
27157 \newline 
27158 }
27159 \layout Standard
27160
27161 then both the switch statements will be implemented using jump-tables whereas
27162  the unmodified switch statement will not be.
27163 \layout Comment
27164
27165 There might be reasons which SDCC cannot know about to either favour or
27166  not favour jump tables.
27167  If the target system has to be as quick for the last switch case as for
27168  the first (pro jump table), or if the switch argument is known to be zero
27169  in the majority of the cases (contra jump table).
27170 \layout Standard
27171
27172 The pragma nojtbound
27173 \begin_inset LatexCommand \index{\#pragma nojtbound}
27174
27175 \end_inset 
27176
27177  can be used to turn off checking the 
27178 \emph on 
27179 j
27180 \emph default 
27181 ump 
27182 \emph on 
27183 t
27184 \emph default 
27185 able 
27186 \emph on 
27187 bound
27188 \emph default 
27189 aries.
27190  It has no effect if a default label is supplied.
27191  Use of this pragma is dangerous: if the switch
27192 \begin_inset LatexCommand \index{switch statement}
27193
27194 \end_inset 
27195
27196  argument is not matched by a case statement the processor will happily
27197  jump into Nirvana.
27198 \layout Subsection
27199
27200 Bit-shifting Operations
27201 \begin_inset LatexCommand \index{Bit shifting}
27202
27203 \end_inset 
27204
27205 .
27206 \layout Standard
27207
27208 Bit shifting is one of the most frequently used operation in embedded programmin
27209 g.
27210  SDCC tries to implement bit-shift operations in the most efficient way
27211  possible, e.g.:
27212 \layout Verse
27213
27214
27215 \family typewriter 
27216 unsigned char i;
27217 \newline 
27218 ...
27219  
27220 \newline 
27221 i >>= 4; 
27222 \newline 
27223 ...
27224 \layout Standard
27225
27226 generates the following code:
27227 \layout Verse
27228
27229
27230 \family typewriter 
27231 mov\SpecialChar ~
27232  a,_i 
27233 \newline 
27234 swap a 
27235 \newline 
27236 anl\SpecialChar ~
27237  a,#0x0f 
27238 \newline 
27239 mov\SpecialChar ~
27240  _i,a
27241 \layout Standard
27242
27243 In general SDCC will never setup a loop if the shift count is known.
27244  Another example:
27245 \layout Verse
27246
27247
27248 \family typewriter 
27249 unsigned int i; 
27250 \newline 
27251 ...
27252  
27253 \newline 
27254 i >>= 9; 
27255 \newline 
27256 ...
27257 \layout Standard
27258
27259 will generate:
27260 \layout Verse
27261
27262
27263 \family typewriter 
27264 mov\SpecialChar ~
27265 \SpecialChar ~
27266 a,(_i + 1) 
27267 \newline 
27268 mov\SpecialChar ~
27269 \SpecialChar ~
27270 (_i + 1),#0x00 
27271 \newline 
27272 clr\SpecialChar ~
27273 \SpecialChar ~
27274
27275 \newline 
27276 rrc\SpecialChar ~
27277 \SpecialChar ~
27278
27279 \newline 
27280 mov\SpecialChar ~
27281 \SpecialChar ~
27282 _i,a
27283 \layout Subsection
27284
27285 Bit-rotation
27286 \begin_inset LatexCommand \index{Bit rotation}
27287
27288 \end_inset 
27289
27290
27291 \layout Standard
27292
27293 A special case of the bit-shift operation is bit rotation
27294 \begin_inset LatexCommand \index{rotating bits}
27295
27296 \end_inset 
27297
27298 , SDCC recognizes the following expression to be a left bit-rotation:
27299 \layout Verse
27300
27301
27302 \family typewriter 
27303 \series bold 
27304 unsigned
27305 \series default 
27306 \SpecialChar ~
27307 \SpecialChar ~
27308 char i;\SpecialChar ~
27309 \SpecialChar ~
27310 \SpecialChar ~
27311 \SpecialChar ~
27312 \SpecialChar ~
27313 \SpecialChar ~
27314 \SpecialChar ~
27315 \SpecialChar ~
27316 \SpecialChar ~
27317 \SpecialChar ~
27318 \SpecialChar ~
27319 /* unsigned is needed for rotation */ 
27320 \newline 
27321 ...
27322  
27323 \newline 
27324 i = ((i << 1) | (i >> 7)); 
27325 \family default 
27326
27327 \newline 
27328
27329 \family typewriter 
27330 ...
27331 \layout Standard
27332
27333 will generate the following code:
27334 \layout Verse
27335
27336
27337 \family typewriter 
27338 mov\SpecialChar ~
27339 \SpecialChar ~
27340 a,_i 
27341 \newline 
27342 rl\SpecialChar ~
27343 \SpecialChar ~
27344 \SpecialChar ~
27345
27346 \newline 
27347 mov\SpecialChar ~
27348 \SpecialChar ~
27349 _i,a
27350 \layout Standard
27351
27352 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27353 ns of this case will also be recognized as bit-rotation, i.e.: 
27354 \layout Verse
27355
27356
27357 \family typewriter 
27358 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27359 \layout Subsection
27360
27361 Nibble and Byte Swapping
27362 \layout Standard
27363
27364 Other special cases of the bit-shift operations are nibble or byte swapping
27365 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27366
27367 \end_inset 
27368
27369 , SDCC recognizes the following expressions:
27370 \layout Verse
27371
27372
27373 \family typewriter 
27374 \series bold 
27375 unsigned
27376 \series default 
27377 \SpecialChar ~
27378 \SpecialChar ~
27379 char i; 
27380 \newline 
27381
27382 \series bold 
27383 unsigned
27384 \series default 
27385 \SpecialChar ~
27386 \SpecialChar ~
27387 int j; 
27388 \newline 
27389 ...
27390  
27391 \newline 
27392 i = ((i << 4) | (i >> 4)); 
27393 \family default 
27394
27395 \newline 
27396
27397 \family typewriter 
27398 j = ((j << 8) | (j >> 8)); 
27399 \layout Standard
27400
27401 and generates a swap instruction for the nibble swapping
27402 \begin_inset LatexCommand \index{Nibble swapping}
27403
27404 \end_inset 
27405
27406  or move instructions for the byte swapping
27407 \begin_inset LatexCommand \index{Byte swapping}
27408
27409 \end_inset 
27410
27411 .
27412  The 
27413 \begin_inset Quotes sld
27414 \end_inset 
27415
27416 j
27417 \begin_inset Quotes srd
27418 \end_inset 
27419
27420  example can be used to convert from little to big-endian or vice versa.
27421  If you want to change the endianness of a 
27422 \emph on 
27423 signed
27424 \emph default 
27425  integer you have to cast to 
27426 \family typewriter 
27427 (unsigned int)
27428 \family default 
27429  first.
27430 \layout Standard
27431
27432 Note that SDCC stores numbers in little-endian
27433 \begin_inset Foot
27434 collapsed false
27435
27436 \layout Standard
27437
27438 Usually 8-bit processors don't care much about endianness.
27439  This is not the case for the standard 8051 which only has an instruction
27440  to increment its 
27441 \emph on 
27442 dptr
27443 \emph default 
27444
27445 \begin_inset LatexCommand \index{DPTR}
27446
27447 \end_inset 
27448
27449 -datapointer
27450 \emph on 
27451  
27452 \emph default 
27453 so little-endian is the more efficient byte order.
27454 \end_inset 
27455
27456
27457 \begin_inset LatexCommand \index{little-endian}
27458
27459 \end_inset 
27460
27461
27462 \begin_inset LatexCommand \index{Endianness}
27463
27464 \end_inset 
27465
27466  format (i.e.
27467  lowest order first).
27468 \layout Subsection
27469
27470 Highest Order Bit
27471 \begin_inset LatexCommand \index{Highest Order Bit}
27472
27473 \end_inset 
27474
27475  / Any Order Bit
27476 \begin_inset LatexCommand \index{Any Order Bit}
27477
27478 \end_inset 
27479
27480
27481 \layout Standard
27482
27483 It is frequently required to obtain the highest order bit of an integral
27484  type (long, int, short or char types).
27485  Also obtaining any other order bit is not uncommon.
27486  SDCC recognizes the following expressions to yield the highest order bit
27487  and generates optimized code for it, e.g.:
27488 \layout Verse
27489
27490
27491 \family typewriter 
27492 unsigned int gint; 
27493 \newline 
27494
27495 \newline 
27496 foo () { 
27497 \newline 
27498 \SpecialChar ~
27499 \SpecialChar ~
27500 unsigned char hob1, aob1; 
27501 \newline 
27502 \SpecialChar ~
27503 \SpecialChar ~
27504 bit hob2, hob3, aob2, aob3; 
27505 \newline 
27506 \SpecialChar ~
27507 \SpecialChar ~
27508 ...
27509  
27510 \newline 
27511 \SpecialChar ~
27512 \SpecialChar ~
27513 hob1 = (gint >> 15) & 1; 
27514 \newline 
27515 \SpecialChar ~
27516 \SpecialChar ~
27517 hob2 = (gint >> 15) & 1; 
27518 \newline 
27519 \SpecialChar ~
27520 \SpecialChar ~
27521 hob3 = gint & 0x8000; 
27522 \newline 
27523 \SpecialChar ~
27524 \SpecialChar ~
27525 aob1 = (gint >> 9) & 1; 
27526 \newline 
27527 \SpecialChar ~
27528 \SpecialChar ~
27529 aob2 = (gint >> 8) & 1; 
27530 \newline 
27531 \SpecialChar ~
27532 \SpecialChar ~
27533 aob3 = gint & 0x0800; 
27534 \newline 
27535 \SpecialChar ~
27536 \SpecialChar ~
27537 ..
27538  
27539 \newline 
27540 }
27541 \layout Standard
27542
27543 will generate the following code:
27544 \layout Verse
27545
27546
27547 \family typewriter 
27548 \SpecialChar ~
27549 \SpecialChar ~
27550 \SpecialChar ~
27551 \SpecialChar ~
27552 \SpecialChar ~
27553 \SpecialChar ~
27554 \SpecialChar ~
27555 \SpecialChar ~
27556 \SpecialChar ~
27557 \SpecialChar ~
27558 \SpecialChar ~
27559 \SpecialChar ~
27560 \SpecialChar ~
27561 \SpecialChar ~
27562 \SpecialChar ~
27563 \SpecialChar ~
27564 \SpecialChar ~
27565 \SpecialChar ~
27566 \SpecialChar ~
27567 \SpecialChar ~
27568 \SpecialChar ~
27569 \SpecialChar ~
27570 \SpecialChar ~
27571 \SpecialChar ~
27572 \SpecialChar ~
27573  61 ;\SpecialChar ~
27574  hob.c 7 
27575 \newline 
27576 000A E5*01\SpecialChar ~
27577 \SpecialChar ~
27578 \SpecialChar ~
27579 \SpecialChar ~
27580 \SpecialChar ~
27581 \SpecialChar ~
27582 \SpecialChar ~
27583 \SpecialChar ~
27584 \SpecialChar ~
27585 \SpecialChar ~
27586 \SpecialChar ~
27587 \SpecialChar ~
27588 \SpecialChar ~
27589 \SpecialChar ~
27590 \SpecialChar ~
27591  62\SpecialChar ~
27592 \SpecialChar ~
27593 \SpecialChar ~
27594 \SpecialChar ~
27595 \SpecialChar ~
27596 \SpecialChar ~
27597 \SpecialChar ~
27598 \SpecialChar ~
27599  mov\SpecialChar ~
27600 \SpecialChar ~
27601  a,(_gint + 1) 
27602 \newline 
27603 000C 23\SpecialChar ~
27604 \SpecialChar ~
27605 \SpecialChar ~
27606 \SpecialChar ~
27607 \SpecialChar ~
27608 \SpecialChar ~
27609 \SpecialChar ~
27610 \SpecialChar ~
27611 \SpecialChar ~
27612 \SpecialChar ~
27613 \SpecialChar ~
27614 \SpecialChar ~
27615 \SpecialChar ~
27616 \SpecialChar ~
27617 \SpecialChar ~
27618 \SpecialChar ~
27619 \SpecialChar ~
27620 \SpecialChar ~
27621  63\SpecialChar ~
27622 \SpecialChar ~
27623 \SpecialChar ~
27624 \SpecialChar ~
27625 \SpecialChar ~
27626 \SpecialChar ~
27627 \SpecialChar ~
27628 \SpecialChar ~
27629  rl\SpecialChar ~
27630 \SpecialChar ~
27631 \SpecialChar ~
27632  a 
27633 \newline 
27634 000D 54 01\SpecialChar ~
27635 \SpecialChar ~
27636 \SpecialChar ~
27637 \SpecialChar ~
27638 \SpecialChar ~
27639 \SpecialChar ~
27640 \SpecialChar ~
27641 \SpecialChar ~
27642 \SpecialChar ~
27643 \SpecialChar ~
27644 \SpecialChar ~
27645 \SpecialChar ~
27646 \SpecialChar ~
27647 \SpecialChar ~
27648 \SpecialChar ~
27649  64\SpecialChar ~
27650 \SpecialChar ~
27651 \SpecialChar ~
27652 \SpecialChar ~
27653 \SpecialChar ~
27654 \SpecialChar ~
27655 \SpecialChar ~
27656 \SpecialChar ~
27657  anl\SpecialChar ~
27658 \SpecialChar ~
27659  a,#0x01 
27660 \newline 
27661 000F F5*02\SpecialChar ~
27662 \SpecialChar ~
27663 \SpecialChar ~
27664 \SpecialChar ~
27665 \SpecialChar ~
27666 \SpecialChar ~
27667 \SpecialChar ~
27668 \SpecialChar ~
27669 \SpecialChar ~
27670 \SpecialChar ~
27671 \SpecialChar ~
27672 \SpecialChar ~
27673 \SpecialChar ~
27674 \SpecialChar ~
27675 \SpecialChar ~
27676  65\SpecialChar ~
27677 \SpecialChar ~
27678 \SpecialChar ~
27679 \SpecialChar ~
27680 \SpecialChar ~
27681 \SpecialChar ~
27682 \SpecialChar ~
27683 \SpecialChar ~
27684  mov\SpecialChar ~
27685 \SpecialChar ~
27686  _foo_hob1_1_1,a 
27687 \newline 
27688 \SpecialChar ~
27689 \SpecialChar ~
27690 \SpecialChar ~
27691 \SpecialChar ~
27692 \SpecialChar ~
27693 \SpecialChar ~
27694 \SpecialChar ~
27695 \SpecialChar ~
27696 \SpecialChar ~
27697 \SpecialChar ~
27698 \SpecialChar ~
27699 \SpecialChar ~
27700 \SpecialChar ~
27701 \SpecialChar ~
27702 \SpecialChar ~
27703 \SpecialChar ~
27704 \SpecialChar ~
27705 \SpecialChar ~
27706 \SpecialChar ~
27707 \SpecialChar ~
27708 \SpecialChar ~
27709 \SpecialChar ~
27710 \SpecialChar ~
27711 \SpecialChar ~
27712 \SpecialChar ~
27713  66 ;\SpecialChar ~
27714  hob.c 8 
27715 \newline 
27716 0011 E5*01\SpecialChar ~
27717 \SpecialChar ~
27718 \SpecialChar ~
27719 \SpecialChar ~
27720 \SpecialChar ~
27721 \SpecialChar ~
27722 \SpecialChar ~
27723 \SpecialChar ~
27724 \SpecialChar ~
27725 \SpecialChar ~
27726 \SpecialChar ~
27727 \SpecialChar ~
27728 \SpecialChar ~
27729 \SpecialChar ~
27730 \SpecialChar ~
27731  67\SpecialChar ~
27732 \SpecialChar ~
27733 \SpecialChar ~
27734 \SpecialChar ~
27735 \SpecialChar ~
27736 \SpecialChar ~
27737 \SpecialChar ~
27738 \SpecialChar ~
27739  mov\SpecialChar ~
27740 \SpecialChar ~
27741  a,(_gint + 1) 
27742 \newline 
27743 0013 33\SpecialChar ~
27744 \SpecialChar ~
27745 \SpecialChar ~
27746 \SpecialChar ~
27747 \SpecialChar ~
27748 \SpecialChar ~
27749 \SpecialChar ~
27750 \SpecialChar ~
27751 \SpecialChar ~
27752 \SpecialChar ~
27753 \SpecialChar ~
27754 \SpecialChar ~
27755 \SpecialChar ~
27756 \SpecialChar ~
27757 \SpecialChar ~
27758 \SpecialChar ~
27759 \SpecialChar ~
27760 \SpecialChar ~
27761  68\SpecialChar ~
27762 \SpecialChar ~
27763 \SpecialChar ~
27764 \SpecialChar ~
27765 \SpecialChar ~
27766 \SpecialChar ~
27767 \SpecialChar ~
27768 \SpecialChar ~
27769  rlc\SpecialChar ~
27770 \SpecialChar ~
27771  a 
27772 \newline 
27773 0014 92*00\SpecialChar ~
27774 \SpecialChar ~
27775 \SpecialChar ~
27776 \SpecialChar ~
27777 \SpecialChar ~
27778 \SpecialChar ~
27779 \SpecialChar ~
27780 \SpecialChar ~
27781 \SpecialChar ~
27782 \SpecialChar ~
27783 \SpecialChar ~
27784 \SpecialChar ~
27785 \SpecialChar ~
27786 \SpecialChar ~
27787 \SpecialChar ~
27788  69\SpecialChar ~
27789 \SpecialChar ~
27790 \SpecialChar ~
27791 \SpecialChar ~
27792 \SpecialChar ~
27793 \SpecialChar ~
27794 \SpecialChar ~
27795 \SpecialChar ~
27796  mov\SpecialChar ~
27797 \SpecialChar ~
27798  _foo_hob2_1_1,c 
27799 \newline 
27800 \SpecialChar ~
27801 \SpecialChar ~
27802 \SpecialChar ~
27803 \SpecialChar ~
27804 \SpecialChar ~
27805 \SpecialChar ~
27806 \SpecialChar ~
27807 \SpecialChar ~
27808 \SpecialChar ~
27809 \SpecialChar ~
27810 \SpecialChar ~
27811 \SpecialChar ~
27812 \SpecialChar ~
27813 \SpecialChar ~
27814 \SpecialChar ~
27815 \SpecialChar ~
27816 \SpecialChar ~
27817 \SpecialChar ~
27818 \SpecialChar ~
27819 \SpecialChar ~
27820 \SpecialChar ~
27821 \SpecialChar ~
27822 \SpecialChar ~
27823 \SpecialChar ~
27824 \SpecialChar ~
27825  66 ;\SpecialChar ~
27826  hob.c 9 
27827 \newline 
27828 0016 E5*01\SpecialChar ~
27829 \SpecialChar ~
27830 \SpecialChar ~
27831 \SpecialChar ~
27832 \SpecialChar ~
27833 \SpecialChar ~
27834 \SpecialChar ~
27835 \SpecialChar ~
27836 \SpecialChar ~
27837 \SpecialChar ~
27838 \SpecialChar ~
27839 \SpecialChar ~
27840 \SpecialChar ~
27841 \SpecialChar ~
27842 \SpecialChar ~
27843  67\SpecialChar ~
27844 \SpecialChar ~
27845 \SpecialChar ~
27846 \SpecialChar ~
27847 \SpecialChar ~
27848 \SpecialChar ~
27849 \SpecialChar ~
27850 \SpecialChar ~
27851  mov\SpecialChar ~
27852 \SpecialChar ~
27853  a,(_gint + 1) 
27854 \newline 
27855 0018 33\SpecialChar ~
27856 \SpecialChar ~
27857 \SpecialChar ~
27858 \SpecialChar ~
27859 \SpecialChar ~
27860 \SpecialChar ~
27861 \SpecialChar ~
27862 \SpecialChar ~
27863 \SpecialChar ~
27864 \SpecialChar ~
27865 \SpecialChar ~
27866 \SpecialChar ~
27867 \SpecialChar ~
27868 \SpecialChar ~
27869 \SpecialChar ~
27870 \SpecialChar ~
27871 \SpecialChar ~
27872 \SpecialChar ~
27873  68\SpecialChar ~
27874 \SpecialChar ~
27875 \SpecialChar ~
27876 \SpecialChar ~
27877 \SpecialChar ~
27878 \SpecialChar ~
27879 \SpecialChar ~
27880 \SpecialChar ~
27881  rlc\SpecialChar ~
27882 \SpecialChar ~
27883  a 
27884 \newline 
27885 0019 92*01\SpecialChar ~
27886 \SpecialChar ~
27887 \SpecialChar ~
27888 \SpecialChar ~
27889 \SpecialChar ~
27890 \SpecialChar ~
27891 \SpecialChar ~
27892 \SpecialChar ~
27893 \SpecialChar ~
27894 \SpecialChar ~
27895 \SpecialChar ~
27896 \SpecialChar ~
27897 \SpecialChar ~
27898 \SpecialChar ~
27899 \SpecialChar ~
27900  69\SpecialChar ~
27901 \SpecialChar ~
27902 \SpecialChar ~
27903 \SpecialChar ~
27904 \SpecialChar ~
27905 \SpecialChar ~
27906 \SpecialChar ~
27907 \SpecialChar ~
27908  mov\SpecialChar ~
27909 \SpecialChar ~
27910  _foo_hob3_1_1,c 
27911 \newline 
27912 \SpecialChar ~
27913 \SpecialChar ~
27914 \SpecialChar ~
27915 \SpecialChar ~
27916 \SpecialChar ~
27917 \SpecialChar ~
27918 \SpecialChar ~
27919 \SpecialChar ~
27920 \SpecialChar ~
27921 \SpecialChar ~
27922 \SpecialChar ~
27923 \SpecialChar ~
27924 \SpecialChar ~
27925 \SpecialChar ~
27926 \SpecialChar ~
27927 \SpecialChar ~
27928 \SpecialChar ~
27929 \SpecialChar ~
27930 \SpecialChar ~
27931 \SpecialChar ~
27932 \SpecialChar ~
27933 \SpecialChar ~
27934 \SpecialChar ~
27935 \SpecialChar ~
27936 \SpecialChar ~
27937  70 ;\SpecialChar ~
27938  hob.c 10 
27939 \newline 
27940 001B E5*01\SpecialChar ~
27941 \SpecialChar ~
27942 \SpecialChar ~
27943 \SpecialChar ~
27944 \SpecialChar ~
27945 \SpecialChar ~
27946 \SpecialChar ~
27947 \SpecialChar ~
27948 \SpecialChar ~
27949 \SpecialChar ~
27950 \SpecialChar ~
27951 \SpecialChar ~
27952 \SpecialChar ~
27953 \SpecialChar ~
27954 \SpecialChar ~
27955  71\SpecialChar ~
27956 \SpecialChar ~
27957 \SpecialChar ~
27958 \SpecialChar ~
27959 \SpecialChar ~
27960 \SpecialChar ~
27961 \SpecialChar ~
27962 \SpecialChar ~
27963  mov\SpecialChar ~
27964 \SpecialChar ~
27965  a,(_gint + 1) 
27966 \newline 
27967 001D 03\SpecialChar ~
27968 \SpecialChar ~
27969 \SpecialChar ~
27970 \SpecialChar ~
27971 \SpecialChar ~
27972 \SpecialChar ~
27973 \SpecialChar ~
27974 \SpecialChar ~
27975 \SpecialChar ~
27976 \SpecialChar ~
27977 \SpecialChar ~
27978 \SpecialChar ~
27979 \SpecialChar ~
27980 \SpecialChar ~
27981 \SpecialChar ~
27982 \SpecialChar ~
27983 \SpecialChar ~
27984 \SpecialChar ~
27985  72\SpecialChar ~
27986 \SpecialChar ~
27987 \SpecialChar ~
27988 \SpecialChar ~
27989 \SpecialChar ~
27990 \SpecialChar ~
27991 \SpecialChar ~
27992 \SpecialChar ~
27993  rr\SpecialChar ~
27994 \SpecialChar ~
27995 \SpecialChar ~
27996  a 
27997 \newline 
27998 001E 54 01\SpecialChar ~
27999 \SpecialChar ~
28000 \SpecialChar ~
28001 \SpecialChar ~
28002 \SpecialChar ~
28003 \SpecialChar ~
28004 \SpecialChar ~
28005 \SpecialChar ~
28006 \SpecialChar ~
28007 \SpecialChar ~
28008 \SpecialChar ~
28009 \SpecialChar ~
28010 \SpecialChar ~
28011 \SpecialChar ~
28012 \SpecialChar ~
28013  73\SpecialChar ~
28014 \SpecialChar ~
28015 \SpecialChar ~
28016 \SpecialChar ~
28017 \SpecialChar ~
28018 \SpecialChar ~
28019 \SpecialChar ~
28020 \SpecialChar ~
28021  anl\SpecialChar ~
28022 \SpecialChar ~
28023  a,#0x01 
28024 \newline 
28025 0020 F5*03\SpecialChar ~
28026 \SpecialChar ~
28027 \SpecialChar ~
28028 \SpecialChar ~
28029 \SpecialChar ~
28030 \SpecialChar ~
28031 \SpecialChar ~
28032 \SpecialChar ~
28033 \SpecialChar ~
28034 \SpecialChar ~
28035 \SpecialChar ~
28036 \SpecialChar ~
28037 \SpecialChar ~
28038 \SpecialChar ~
28039 \SpecialChar ~
28040  74\SpecialChar ~
28041 \SpecialChar ~
28042 \SpecialChar ~
28043 \SpecialChar ~
28044 \SpecialChar ~
28045 \SpecialChar ~
28046 \SpecialChar ~
28047 \SpecialChar ~
28048  mov\SpecialChar ~
28049 \SpecialChar ~
28050  _foo_aob1_1_1,a 
28051 \newline 
28052 \SpecialChar ~
28053 \SpecialChar ~
28054 \SpecialChar ~
28055 \SpecialChar ~
28056 \SpecialChar ~
28057 \SpecialChar ~
28058 \SpecialChar ~
28059 \SpecialChar ~
28060 \SpecialChar ~
28061 \SpecialChar ~
28062 \SpecialChar ~
28063 \SpecialChar ~
28064 \SpecialChar ~
28065 \SpecialChar ~
28066 \SpecialChar ~
28067 \SpecialChar ~
28068 \SpecialChar ~
28069 \SpecialChar ~
28070 \SpecialChar ~
28071 \SpecialChar ~
28072 \SpecialChar ~
28073 \SpecialChar ~
28074 \SpecialChar ~
28075 \SpecialChar ~
28076 \SpecialChar ~
28077  75 ;\SpecialChar ~
28078  hob.c 11 
28079 \newline 
28080 0022 E5*01\SpecialChar ~
28081 \SpecialChar ~
28082 \SpecialChar ~
28083 \SpecialChar ~
28084 \SpecialChar ~
28085 \SpecialChar ~
28086 \SpecialChar ~
28087 \SpecialChar ~
28088 \SpecialChar ~
28089 \SpecialChar ~
28090 \SpecialChar ~
28091 \SpecialChar ~
28092 \SpecialChar ~
28093 \SpecialChar ~
28094 \SpecialChar ~
28095  76\SpecialChar ~
28096 \SpecialChar ~
28097 \SpecialChar ~
28098 \SpecialChar ~
28099 \SpecialChar ~
28100 \SpecialChar ~
28101 \SpecialChar ~
28102 \SpecialChar ~
28103  mov\SpecialChar ~
28104 \SpecialChar ~
28105  a,(_gint + 1) 
28106 \newline 
28107 0024 13\SpecialChar ~
28108 \SpecialChar ~
28109 \SpecialChar ~
28110 \SpecialChar ~
28111 \SpecialChar ~
28112 \SpecialChar ~
28113 \SpecialChar ~
28114 \SpecialChar ~
28115 \SpecialChar ~
28116 \SpecialChar ~
28117 \SpecialChar ~
28118 \SpecialChar ~
28119 \SpecialChar ~
28120 \SpecialChar ~
28121 \SpecialChar ~
28122 \SpecialChar ~
28123 \SpecialChar ~
28124 \SpecialChar ~
28125  77\SpecialChar ~
28126 \SpecialChar ~
28127 \SpecialChar ~
28128 \SpecialChar ~
28129 \SpecialChar ~
28130 \SpecialChar ~
28131 \SpecialChar ~
28132 \SpecialChar ~
28133  rrc\SpecialChar ~
28134 \SpecialChar ~
28135  a 
28136 \newline 
28137 0025 92*02\SpecialChar ~
28138 \SpecialChar ~
28139 \SpecialChar ~
28140 \SpecialChar ~
28141 \SpecialChar ~
28142 \SpecialChar ~
28143 \SpecialChar ~
28144 \SpecialChar ~
28145 \SpecialChar ~
28146 \SpecialChar ~
28147 \SpecialChar ~
28148 \SpecialChar ~
28149 \SpecialChar ~
28150 \SpecialChar ~
28151 \SpecialChar ~
28152  78\SpecialChar ~
28153 \SpecialChar ~
28154 \SpecialChar ~
28155 \SpecialChar ~
28156 \SpecialChar ~
28157 \SpecialChar ~
28158 \SpecialChar ~
28159 \SpecialChar ~
28160  mov\SpecialChar ~
28161 \SpecialChar ~
28162  _foo_aob2_1_1,c 
28163 \newline 
28164 \SpecialChar ~
28165 \SpecialChar ~
28166 \SpecialChar ~
28167 \SpecialChar ~
28168 \SpecialChar ~
28169 \SpecialChar ~
28170 \SpecialChar ~
28171 \SpecialChar ~
28172 \SpecialChar ~
28173 \SpecialChar ~
28174 \SpecialChar ~
28175 \SpecialChar ~
28176 \SpecialChar ~
28177 \SpecialChar ~
28178 \SpecialChar ~
28179 \SpecialChar ~
28180 \SpecialChar ~
28181 \SpecialChar ~
28182 \SpecialChar ~
28183 \SpecialChar ~
28184 \SpecialChar ~
28185 \SpecialChar ~
28186 \SpecialChar ~
28187 \SpecialChar ~
28188 \SpecialChar ~
28189  79 ;\SpecialChar ~
28190  hob.c 12 
28191 \newline 
28192 0027 E5*01\SpecialChar ~
28193 \SpecialChar ~
28194 \SpecialChar ~
28195 \SpecialChar ~
28196 \SpecialChar ~
28197 \SpecialChar ~
28198 \SpecialChar ~
28199 \SpecialChar ~
28200 \SpecialChar ~
28201 \SpecialChar ~
28202 \SpecialChar ~
28203 \SpecialChar ~
28204 \SpecialChar ~
28205 \SpecialChar ~
28206 \SpecialChar ~
28207  80\SpecialChar ~
28208 \SpecialChar ~
28209 \SpecialChar ~
28210 \SpecialChar ~
28211 \SpecialChar ~
28212 \SpecialChar ~
28213 \SpecialChar ~
28214 \SpecialChar ~
28215  mov\SpecialChar ~
28216 \SpecialChar ~
28217  a,(_gint + 1) 
28218 \newline 
28219 0029 A2 E3\SpecialChar ~
28220 \SpecialChar ~
28221 \SpecialChar ~
28222 \SpecialChar ~
28223 \SpecialChar ~
28224 \SpecialChar ~
28225 \SpecialChar ~
28226 \SpecialChar ~
28227 \SpecialChar ~
28228 \SpecialChar ~
28229 \SpecialChar ~
28230 \SpecialChar ~
28231 \SpecialChar ~
28232 \SpecialChar ~
28233 \SpecialChar ~
28234  81\SpecialChar ~
28235 \SpecialChar ~
28236 \SpecialChar ~
28237 \SpecialChar ~
28238 \SpecialChar ~
28239 \SpecialChar ~
28240 \SpecialChar ~
28241 \SpecialChar ~
28242  mov\SpecialChar ~
28243 \SpecialChar ~
28244  c,acc[3] 
28245 \newline 
28246 002B 92*03\SpecialChar ~
28247 \SpecialChar ~
28248 \SpecialChar ~
28249 \SpecialChar ~
28250 \SpecialChar ~
28251 \SpecialChar ~
28252 \SpecialChar ~
28253 \SpecialChar ~
28254 \SpecialChar ~
28255 \SpecialChar ~
28256 \SpecialChar ~
28257 \SpecialChar ~
28258 \SpecialChar ~
28259 \SpecialChar ~
28260 \SpecialChar ~
28261  82\SpecialChar ~
28262 \SpecialChar ~
28263 \SpecialChar ~
28264 \SpecialChar ~
28265 \SpecialChar ~
28266 \SpecialChar ~
28267 \SpecialChar ~
28268 \SpecialChar ~
28269  mov\SpecialChar ~
28270 \SpecialChar ~
28271  _foo_aob3_1_1,c 
28272 \layout Standard
28273
28274 Other variations of these cases however will 
28275 \emph on 
28276 not
28277 \emph default 
28278  be recognized.
28279  They are standard C expressions, so I heartily recommend these be the only
28280  way to get the highest order bit, (it is portable).
28281  Of course it will be recognized even if it is embedded in other expressions,
28282  e.g.:
28283 \layout Verse
28284
28285
28286 \family typewriter 
28287 xyz = gint + ((gint >> 15) & 1);
28288 \layout Standard
28289
28290 will still be recognized.
28291 \layout Subsection
28292
28293 Higher Order Byte
28294 \begin_inset LatexCommand \index{Higher Order Byte}
28295
28296 \end_inset 
28297
28298  / Higher Order Word
28299 \begin_inset LatexCommand \index{Higher Order Word}
28300
28301 \end_inset 
28302
28303
28304 \layout Standard
28305
28306 It is also frequently required to obtain a higher order byte or word of
28307  a larger integral type (long, int or short types).
28308  SDCC recognizes the following expressions to yield the higher order byte
28309  or word and generates optimized code for it, e.g.:
28310 \layout Verse
28311
28312
28313 \family typewriter 
28314 unsigned int gint; 
28315 \newline 
28316 unsigned long int glong; 
28317 \newline 
28318
28319 \newline 
28320 foo () { 
28321 \newline 
28322 \SpecialChar ~
28323 \SpecialChar ~
28324 unsigned char hob1, hob2; 
28325 \newline 
28326 \SpecialChar ~
28327 \SpecialChar ~
28328 unsigned int how1, how2; 
28329 \newline 
28330 \SpecialChar ~
28331 \SpecialChar ~
28332 ...
28333  
28334 \newline 
28335 \SpecialChar ~
28336 \SpecialChar ~
28337 hob1 = (gint >> 8) & 0xFF; 
28338 \newline 
28339 \SpecialChar ~
28340 \SpecialChar ~
28341 hob2 = glong >> 24; 
28342 \newline 
28343 \SpecialChar ~
28344 \SpecialChar ~
28345 how1 = (glong >> 16) & 0xFFFF; 
28346 \newline 
28347 \SpecialChar ~
28348 \SpecialChar ~
28349 how2 = glong >> 8; 
28350 \newline 
28351 \SpecialChar ~
28352 \SpecialChar ~
28353 ..
28354  
28355 \newline 
28356 }
28357 \layout Standard
28358
28359 will generate the following code:
28360 \layout Verse
28361
28362
28363 \family typewriter 
28364 \SpecialChar ~
28365 \SpecialChar ~
28366 \SpecialChar ~
28367 \SpecialChar ~
28368 \SpecialChar ~
28369 \SpecialChar ~
28370 \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 \SpecialChar ~
28386 \SpecialChar ~
28387 \SpecialChar ~
28388 \SpecialChar ~
28389  91 ;\SpecialChar ~
28390  hob.c 15 
28391 \newline 
28392 0037 85*01*06\SpecialChar ~
28393 \SpecialChar ~
28394 \SpecialChar ~
28395 \SpecialChar ~
28396 \SpecialChar ~
28397 \SpecialChar ~
28398 \SpecialChar ~
28399 \SpecialChar ~
28400 \SpecialChar ~
28401 \SpecialChar ~
28402 \SpecialChar ~
28403 \SpecialChar ~
28404  92\SpecialChar ~
28405 \SpecialChar ~
28406 \SpecialChar ~
28407 \SpecialChar ~
28408 \SpecialChar ~
28409 \SpecialChar ~
28410 \SpecialChar ~
28411 \SpecialChar ~
28412  mov\SpecialChar ~
28413 \SpecialChar ~
28414  _foo_hob1_1_1,(_gint + 1) 
28415 \newline 
28416 \SpecialChar ~
28417 \SpecialChar ~
28418 \SpecialChar ~
28419 \SpecialChar ~
28420 \SpecialChar ~
28421 \SpecialChar ~
28422 \SpecialChar ~
28423 \SpecialChar ~
28424 \SpecialChar ~
28425 \SpecialChar ~
28426 \SpecialChar ~
28427 \SpecialChar ~
28428 \SpecialChar ~
28429 \SpecialChar ~
28430 \SpecialChar ~
28431 \SpecialChar ~
28432 \SpecialChar ~
28433 \SpecialChar ~
28434 \SpecialChar ~
28435 \SpecialChar ~
28436 \SpecialChar ~
28437 \SpecialChar ~
28438 \SpecialChar ~
28439 \SpecialChar ~
28440 \SpecialChar ~
28441  93 ;\SpecialChar ~
28442  hob.c 16 
28443 \newline 
28444 003A 85*05*07\SpecialChar ~
28445 \SpecialChar ~
28446 \SpecialChar ~
28447 \SpecialChar ~
28448 \SpecialChar ~
28449 \SpecialChar ~
28450 \SpecialChar ~
28451 \SpecialChar ~
28452 \SpecialChar ~
28453 \SpecialChar ~
28454 \SpecialChar ~
28455 \SpecialChar ~
28456  94\SpecialChar ~
28457 \SpecialChar ~
28458 \SpecialChar ~
28459 \SpecialChar ~
28460 \SpecialChar ~
28461 \SpecialChar ~
28462 \SpecialChar ~
28463 \SpecialChar ~
28464  mov\SpecialChar ~
28465 \SpecialChar ~
28466  _foo_hob2_1_1,(_glong + 3) 
28467 \newline 
28468 \SpecialChar ~
28469 \SpecialChar ~
28470 \SpecialChar ~
28471 \SpecialChar ~
28472 \SpecialChar ~
28473 \SpecialChar ~
28474 \SpecialChar ~
28475 \SpecialChar ~
28476 \SpecialChar ~
28477 \SpecialChar ~
28478 \SpecialChar ~
28479 \SpecialChar ~
28480 \SpecialChar ~
28481 \SpecialChar ~
28482 \SpecialChar ~
28483 \SpecialChar ~
28484 \SpecialChar ~
28485 \SpecialChar ~
28486 \SpecialChar ~
28487 \SpecialChar ~
28488 \SpecialChar ~
28489 \SpecialChar ~
28490 \SpecialChar ~
28491 \SpecialChar ~
28492 \SpecialChar ~
28493  95 ;\SpecialChar ~
28494  hob.c 17 
28495 \newline 
28496 003D 85*04*08\SpecialChar ~
28497 \SpecialChar ~
28498 \SpecialChar ~
28499 \SpecialChar ~
28500 \SpecialChar ~
28501 \SpecialChar ~
28502 \SpecialChar ~
28503 \SpecialChar ~
28504 \SpecialChar ~
28505 \SpecialChar ~
28506 \SpecialChar ~
28507 \SpecialChar ~
28508  96\SpecialChar ~
28509 \SpecialChar ~
28510 \SpecialChar ~
28511 \SpecialChar ~
28512 \SpecialChar ~
28513 \SpecialChar ~
28514 \SpecialChar ~
28515 \SpecialChar ~
28516  mov\SpecialChar ~
28517 \SpecialChar ~
28518  _foo_how1_1_1,(_glong + 2) 
28519 \newline 
28520 0040 85*05*09\SpecialChar ~
28521 \SpecialChar ~
28522 \SpecialChar ~
28523 \SpecialChar ~
28524 \SpecialChar ~
28525 \SpecialChar ~
28526 \SpecialChar ~
28527 \SpecialChar ~
28528 \SpecialChar ~
28529 \SpecialChar ~
28530 \SpecialChar ~
28531 \SpecialChar ~
28532  97\SpecialChar ~
28533 \SpecialChar ~
28534 \SpecialChar ~
28535 \SpecialChar ~
28536 \SpecialChar ~
28537 \SpecialChar ~
28538 \SpecialChar ~
28539 \SpecialChar ~
28540  mov\SpecialChar ~
28541 \SpecialChar ~
28542  (_foo_how1_1_1 + 1),(_glong + 3) 
28543 \newline 
28544 0043 85*03*0A\SpecialChar ~
28545 \SpecialChar ~
28546 \SpecialChar ~
28547 \SpecialChar ~
28548 \SpecialChar ~
28549 \SpecialChar ~
28550 \SpecialChar ~
28551 \SpecialChar ~
28552 \SpecialChar ~
28553 \SpecialChar ~
28554 \SpecialChar ~
28555 \SpecialChar ~
28556  98\SpecialChar ~
28557 \SpecialChar ~
28558 \SpecialChar ~
28559 \SpecialChar ~
28560 \SpecialChar ~
28561 \SpecialChar ~
28562 \SpecialChar ~
28563 \SpecialChar ~
28564  mov\SpecialChar ~
28565 \SpecialChar ~
28566  _foo_how2_1_1,(_glong + 1) 
28567 \newline 
28568 0046 85*04*0B\SpecialChar ~
28569 \SpecialChar ~
28570 \SpecialChar ~
28571 \SpecialChar ~
28572 \SpecialChar ~
28573 \SpecialChar ~
28574 \SpecialChar ~
28575 \SpecialChar ~
28576 \SpecialChar ~
28577 \SpecialChar ~
28578 \SpecialChar ~
28579 \SpecialChar ~
28580  99\SpecialChar ~
28581 \SpecialChar ~
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 \SpecialChar ~
28585 \SpecialChar ~
28586 \SpecialChar ~
28587 \SpecialChar ~
28588  mov\SpecialChar ~
28589 \SpecialChar ~
28590  (_foo_how2_1_1 + 1),(_glong + 2) 
28591 \layout Standard
28592
28593 Again, variations of these cases may 
28594 \emph on 
28595 not
28596 \emph default 
28597  be recognized.
28598  They are standard C expressions, so I heartily recommend these be the only
28599  way to get the higher order byte/word, (it is portable).
28600  Of course it will be recognized even if it is embedded in other expressions,
28601  e.g.:
28602 \layout Verse
28603
28604
28605 \family typewriter 
28606 xyz = gint + ((gint >> 8) & 0xFF);
28607 \layout Standard
28608
28609 will still be recognized.
28610 \layout Subsection
28611
28612 Peephole Optimizer
28613 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
28614
28615 \end_inset 
28616
28617
28618 \begin_inset LatexCommand \index{Peephole optimizer}
28619
28620 \end_inset 
28621
28622
28623 \layout Standard
28624
28625 The compiler uses a rule based, pattern matching and re-writing mechanism
28626  for peep-hole optimization.
28627  It is inspired by 
28628 \emph on 
28629 copt
28630 \emph default 
28631  a peep-hole optimizer by Christopher W.
28632  Fraser (cwfraser\SpecialChar ~
28633 @\SpecialChar ~
28634 microsoft.com).
28635  A default set of rules are compiled into the compiler, additional rules
28636  may be added with the 
28637 \emph on 
28638 -
28639 \begin_inset ERT
28640 status Collapsed
28641
28642 \layout Standard
28643
28644 \backslash 
28645 /
28646 \end_inset 
28647
28648 -peep-file
28649 \begin_inset LatexCommand \index{-\/-peep-file}
28650
28651 \end_inset 
28652
28653  <filename>
28654 \emph default 
28655  option.
28656  The rule language is best illustrated with examples.
28657 \layout Verse
28658
28659
28660 \family typewriter 
28661 replace { 
28662 \newline 
28663 \SpecialChar ~
28664 \SpecialChar ~
28665 mov %1,a 
28666 \newline 
28667 \SpecialChar ~
28668 \SpecialChar ~
28669 mov a,%1
28670 \newline 
28671 } by {
28672 \newline 
28673 \SpecialChar ~
28674 \SpecialChar ~
28675 mov %1,a
28676 \newline 
28677 }
28678 \layout Standard
28679
28680 The above rule will change the following assembly
28681 \begin_inset LatexCommand \index{Assembler routines}
28682
28683 \end_inset 
28684
28685  sequence:
28686 \layout Verse
28687
28688
28689 \family typewriter 
28690 mov r1,a 
28691 \newline 
28692 mov a,r1
28693 \layout Standard
28694
28695 to
28696 \layout Verse
28697
28698
28699 \family typewriter 
28700 mov r1,a
28701 \layout Standard
28702
28703 Note: All occurrences of a 
28704 \emph on 
28705 %n
28706 \emph default 
28707  (pattern variable) must denote the same string.
28708  With the above rule, the assembly sequence:
28709 \layout Verse
28710
28711
28712 \family typewriter 
28713 mov r1,a 
28714 \newline 
28715 mov a,r2
28716 \layout Standard
28717
28718 will remain unmodified.
28719 \newline 
28720
28721 \newline 
28722 Other special case optimizations may be added by the user (via 
28723 \emph on 
28724 -
28725 \begin_inset ERT
28726 status Collapsed
28727
28728 \layout Standard
28729
28730 \backslash 
28731 /
28732 \end_inset 
28733
28734 -peep-file option
28735 \emph default 
28736 ).
28737  E.g.
28738  some variants of the 8051 MCU
28739 \begin_inset LatexCommand \index{MCS51 variants}
28740
28741 \end_inset 
28742
28743  allow only 
28744 \family typewriter 
28745 ajmp
28746 \family default 
28747  and 
28748 \family typewriter 
28749 acall
28750 \family default 
28751 .
28752  The following two rules will change all 
28753 \family typewriter 
28754 ljmp
28755 \family default 
28756  and 
28757 \family typewriter 
28758 lcall
28759 \family default 
28760  to 
28761 \family typewriter 
28762 ajmp
28763 \family default 
28764  and 
28765 \family typewriter 
28766 acall
28767 \layout Verse
28768
28769
28770 \family typewriter 
28771 replace { lcall %1 } by { acall %1 } 
28772 \newline 
28773 replace { ljmp %1 } by { ajmp %1 }
28774 \layout Standard
28775
28776 The 
28777 \emph on 
28778 inline-assembler code
28779 \emph default 
28780  is also passed through the peep hole optimizer, thus the peephole optimizer
28781  can also be used as an assembly level macro expander.
28782  The rules themselves are MCU dependent whereas the rule language infra-structur
28783 e is MCU independent.
28784  Peephole optimization rules for other MCU can be easily programmed using
28785  the rule language.
28786 \newline 
28787
28788 \newline 
28789 The syntax for a rule is as follows:
28790 \layout Verse
28791
28792
28793 \family typewriter 
28794 rule := replace [ restart ] '{' <assembly sequence> '
28795 \backslash 
28796 n' 
28797 \newline 
28798 \SpecialChar ~
28799  \SpecialChar ~
28800  \SpecialChar ~
28801  \SpecialChar ~
28802  \SpecialChar ~
28803  \SpecialChar ~
28804  \SpecialChar ~
28805  \SpecialChar ~
28806  \SpecialChar ~
28807  \SpecialChar ~
28808  \SpecialChar ~
28809  \SpecialChar ~
28810  \SpecialChar ~
28811  \SpecialChar ~
28812  '}' by '{' '
28813 \backslash 
28814 n' 
28815 \newline 
28816 \SpecialChar ~
28817  \SpecialChar ~
28818  \SpecialChar ~
28819  \SpecialChar ~
28820  \SpecialChar ~
28821  \SpecialChar ~
28822  \SpecialChar ~
28823  \SpecialChar ~
28824  \SpecialChar ~
28825  \SpecialChar ~
28826  \SpecialChar ~
28827  \SpecialChar ~
28828  \SpecialChar ~
28829  \SpecialChar ~
28830  \SpecialChar ~
28831  \SpecialChar ~
28832  <assembly sequence> '
28833 \backslash 
28834 n' 
28835 \newline 
28836 \SpecialChar ~
28837  \SpecialChar ~
28838  \SpecialChar ~
28839  \SpecialChar ~
28840  \SpecialChar ~
28841  \SpecialChar ~
28842  \SpecialChar ~
28843  \SpecialChar ~
28844  \SpecialChar ~
28845  \SpecialChar ~
28846  \SpecialChar ~
28847  \SpecialChar ~
28848  \SpecialChar ~
28849  \SpecialChar ~
28850  '}' [if <functionName> ] '
28851 \backslash 
28852 n' 
28853 \layout Standard
28854
28855 <assembly sequence> := assembly instruction (each instruction including
28856  labels must be on a separate line).
28857 \newline 
28858
28859 \newline 
28860 The optimizer will apply to the rules one by one from the top in the sequence
28861  of their appearance, it will terminate when all rules are exhausted.
28862  If the 'restart' option is specified, then the optimizer will start matching
28863  the rules again from the top, this option for a rule is expensive (performance)
28864 , it is intended to be used in situations where a transformation will trigger
28865  the same rule again.
28866  An example of this (not a good one, it has side effects) is the following
28867  rule:
28868 \layout Verse
28869
28870
28871 \family typewriter 
28872 replace restart { 
28873 \newline 
28874 \SpecialChar ~
28875 \SpecialChar ~
28876 pop %1 
28877 \newline 
28878 \SpecialChar ~
28879 \SpecialChar ~
28880 push %1 } by { 
28881 \newline 
28882 \SpecialChar ~
28883 \SpecialChar ~
28884 ; nop 
28885 \newline 
28886 }
28887 \layout Standard
28888
28889 Note that the replace pattern cannot be a blank, but can be a comment line.
28890  Without the 'restart' option only the innermost 'pop' 'push' pair would
28891  be eliminated, i.e.:
28892 \layout Verse
28893
28894
28895 \family typewriter 
28896 pop ar1 
28897 \newline 
28898 pop ar2 
28899 \newline 
28900 push ar2 
28901 \newline 
28902 push ar1
28903 \layout Standard
28904
28905 would result in:
28906 \layout Verse
28907
28908
28909 \family typewriter 
28910 pop ar1 
28911 \newline 
28912 ; nop 
28913 \newline 
28914 push ar1
28915 \layout Standard
28916
28917
28918 \emph on 
28919 with
28920 \emph default 
28921  the restart option the rule will be applied again to the resulting code
28922  and then all the pop-push pairs will be eliminated to yield:
28923 \layout Verse
28924
28925
28926 \family typewriter 
28927 ; nop 
28928 \newline 
28929 ; nop
28930 \layout Standard
28931
28932 A conditional function can be attached to a rule.
28933  Attaching rules are somewhat more involved, let me illustrate this with
28934  an example.
28935 \layout Verse
28936
28937
28938 \family typewriter 
28939 replace { 
28940 \newline 
28941 \SpecialChar ~
28942  \SpecialChar ~
28943  \SpecialChar ~
28944 ljmp %5 
28945 \newline 
28946 %2:
28947 \newline 
28948 } by { 
28949 \newline 
28950 \SpecialChar ~
28951  \SpecialChar ~
28952  \SpecialChar ~
28953 sjmp %5 
28954 \newline 
28955 %2:
28956 \newline 
28957 } if labelInRange
28958 \layout Standard
28959
28960 The optimizer does a look-up of a function name table defined in function
28961  
28962 \emph on 
28963 callFuncByName
28964 \emph default 
28965  in the source file SDCCpeeph.c, with the name 
28966 \emph on 
28967 labelInRange
28968 \emph default 
28969 .
28970  If it finds a corresponding entry the function is called.
28971  Note there can be no parameters specified for these functions, in this
28972  case the use of 
28973 \emph on 
28974 %5
28975 \emph default 
28976  is crucial, since the function 
28977 \emph on 
28978 labelInRange
28979 \emph default 
28980  expects to find the label in that particular variable (the hash table containin
28981 g the variable bindings is passed as a parameter).
28982  If you want to code more such functions, take a close look at the function
28983  labelInRange and the calling mechanism in source file SDCCpeeph.c.
28984  Currently implemented are 
28985 \emph on 
28986 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
28987  24bitMode, portIsDS390, 24bitModeAndPortDS390 
28988 \emph default 
28989 and
28990 \emph on 
28991  notVolatile
28992 \emph default 
28993 .
28994 \layout Standard
28995
28996 I know this whole thing is a little kludgey, but maybe some day we will
28997  have some better means.
28998  If you are looking at this file, you will see the default rules that are
28999  compiled into the compiler, you can add your own rules in the default set
29000  there if you get tired of specifying the -
29001 \begin_inset ERT
29002 status Collapsed
29003
29004 \layout Standard
29005
29006 \backslash 
29007 /
29008 \end_inset 
29009
29010 -peep-file option.
29011 \layout Section
29012
29013 ANSI-Compliance
29014 \begin_inset LatexCommand \index{ANSI-compliance}
29015
29016 \end_inset 
29017
29018
29019 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
29020
29021 \end_inset 
29022
29023
29024 \layout Standard
29025
29026 The latest publically available version of the standard 
29027 \emph on 
29028 ISO/IEC 9899 - Programming languages - C
29029 \emph default 
29030  should be available at: 
29031 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29032
29033 \end_inset 
29034
29035 .
29036 \newline 
29037
29038 \layout Standard
29039
29040 Deviations from the compliance:
29041 \layout Itemize
29042
29043 functions are not reentrant
29044 \begin_inset LatexCommand \index{reentrant}
29045
29046 \end_inset 
29047
29048  unless explicitly declared as such or the 
29049 \series bold 
29050 -
29051 \begin_inset ERT
29052 status Collapsed
29053
29054 \layout Standard
29055
29056 \backslash 
29057 /
29058 \end_inset 
29059
29060 -stack-auto
29061 \begin_inset LatexCommand \index{-\/-stack-auto}
29062
29063 \end_inset 
29064
29065
29066 \series default 
29067  command line option is specified.
29068 \layout Itemize
29069
29070 structures
29071 \begin_inset LatexCommand \index{struct}
29072
29073 \end_inset 
29074
29075  and unions
29076 \begin_inset LatexCommand \index{union}
29077
29078 \end_inset 
29079
29080  cannot be assigned values directly, cannot be passed as function parameters
29081  or assigned to each other and cannot be a return value
29082 \begin_inset LatexCommand \index{return value}
29083
29084 \end_inset 
29085
29086  from a function, e.g.:
29087 \begin_deeper 
29088 \layout Verse
29089
29090
29091 \family typewriter 
29092 struct s { ...
29093  }; 
29094 \newline 
29095 struct s s1, s2; 
29096 \newline 
29097 foo() 
29098 \newline 
29099
29100 \newline 
29101 \SpecialChar ~
29102 \SpecialChar ~
29103 \SpecialChar ~
29104 \SpecialChar ~
29105 ...
29106  
29107 \newline 
29108 \SpecialChar ~
29109 \SpecialChar ~
29110 \SpecialChar ~
29111 \SpecialChar ~
29112 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
29113 \newline 
29114 \SpecialChar ~
29115 \SpecialChar ~
29116 \SpecialChar ~
29117 \SpecialChar ~
29118 ...
29119  
29120 \newline 
29121 }
29122 \newline 
29123
29124 \series bold 
29125 struct
29126 \series default 
29127  s foo1 (
29128 \series bold 
29129 struct
29130 \series default 
29131  s parms) /* invalid in SDCC although allowed in ANSI */
29132 \newline 
29133
29134 \newline 
29135 \SpecialChar ~
29136 \SpecialChar ~
29137 \SpecialChar ~
29138 \SpecialChar ~
29139 struct s rets; 
29140 \newline 
29141 \SpecialChar ~
29142 \SpecialChar ~
29143 \SpecialChar ~
29144 \SpecialChar ~
29145 ...
29146  
29147 \newline 
29148 \SpecialChar ~
29149 \SpecialChar ~
29150 \SpecialChar ~
29151 \SpecialChar ~
29152 return rets; /* is invalid in SDCC although allowed in ANSI */ 
29153 \newline 
29154 }
29155 \end_deeper 
29156 \layout Itemize
29157
29158 initialization of structure arrays must be fully braced.
29159 \begin_deeper 
29160 \layout Verse
29161
29162
29163 \family typewriter 
29164 struct s { char x } a[] = {1, 2};\SpecialChar ~
29165 \SpecialChar ~
29166 \SpecialChar ~
29167 \SpecialChar ~
29168 \SpecialChar ~
29169 /* invalid in SDCC */
29170 \newline 
29171 struct s { char x } a[] = {{1}, {2}}; /* OK */
29172 \end_deeper 
29173 \layout Itemize
29174
29175 'long long
29176 \begin_inset LatexCommand \index{long long (not supported)}
29177
29178 \end_inset 
29179
29180 ' (64 bit integers
29181 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29182
29183 \end_inset 
29184
29185 ) not supported.
29186 \layout Itemize
29187
29188 'double
29189 \begin_inset LatexCommand \index{double (not supported)}
29190
29191 \end_inset 
29192
29193 ' precision floating point 
29194 \begin_inset LatexCommand \index{Floating point support}
29195
29196 \end_inset 
29197
29198 not supported.
29199 \layout Itemize
29200
29201 Old K&R style
29202 \begin_inset LatexCommand \index{K\&R style}
29203
29204 \end_inset 
29205
29206  function declarations are NOT allowed.
29207 \begin_deeper 
29208 \layout Verse
29209
29210
29211 \family typewriter 
29212 foo(i,j) /* this old style of function declarations */ 
29213 \newline 
29214 int i,j; /* are valid in ANSI but not valid in SDCC */ 
29215 \newline 
29216
29217 \newline 
29218 \SpecialChar ~
29219 \SpecialChar ~
29220 \SpecialChar ~
29221 \SpecialChar ~
29222 ...
29223  
29224 \newline 
29225 }
29226 \end_deeper 
29227 \layout Itemize
29228
29229 Most enhancements in C99 are not supported, f.e.:
29230 \begin_deeper 
29231 \layout Verse
29232
29233
29234 \family typewriter 
29235 \series bold 
29236 inline
29237 \begin_inset LatexCommand \index{inline (not supported)}
29238
29239 \end_inset 
29240
29241
29242 \series default 
29243  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29244  in C99.
29245  An empty define 
29246 \emph on 
29247 #define inline
29248 \emph default 
29249  can be used as a work around */
29250 \newline 
29251
29252 \newline 
29253 for (
29254 \series bold 
29255 int
29256 \series default 
29257  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29258 \end_deeper 
29259 \layout Itemize
29260
29261 Certain words that are valid identifiers in the standard may be reserved
29262  words in SDCC unless the 
29263 \series bold 
29264 -
29265 \begin_inset ERT
29266 status Collapsed
29267
29268 \layout Standard
29269
29270 \backslash 
29271 /
29272 \end_inset 
29273
29274 -std-c89
29275 \begin_inset LatexCommand \index{-\/-std-c89}
29276
29277 \end_inset 
29278
29279  or -
29280 \begin_inset ERT
29281 status Collapsed
29282
29283 \layout Standard
29284
29285 \backslash 
29286 /
29287 \end_inset 
29288
29289 -std-c99
29290 \begin_inset LatexCommand \index{-\/-std-c99}
29291
29292 \end_inset 
29293
29294
29295 \series default 
29296  command line options are used.
29297  These may include (depending on the selected processor): 'at', 'banked',
29298  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29299 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29300  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29301  '_naked'.
29302  Compliant equivalents of these keywords are always available in a form
29303  that begin with two underscores
29304 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29305
29306 \end_inset 
29307
29308 , f.e.
29309  '__data' instead of 'data'.
29310 \layout Section
29311
29312 Cyclomatic Complexity
29313 \begin_inset LatexCommand \index{Cyclomatic complexity}
29314
29315 \end_inset 
29316
29317
29318 \layout Standard
29319
29320 Cyclomatic complexity of a function is defined as the number of independent
29321  paths the program can take during execution of the function.
29322  This is an important number since it defines the number test cases you
29323  have to generate to validate the function.
29324  The accepted industry standard for complexity number is 10, if the cyclomatic
29325  complexity reported by SDCC exceeds 10 you should think about simplification
29326  of the function logic.
29327  Note that the complexity level is not related to the number of lines of
29328  code in a function.
29329  Large functions can have low complexity, and small functions can have large
29330  complexity levels.
29331  
29332 \newline 
29333
29334 \newline 
29335 SDCC uses the following formula to compute the complexity:
29336 \newline 
29337
29338 \layout Standard
29339
29340 complexity = (number of edges in control flow graph) - (number of nodes
29341  in control flow graph) + 2;
29342 \newline 
29343
29344 \newline 
29345 Having said that the industry standard is 10, you should be aware that in
29346  some cases it be may unavoidable to have a complexity level of less than
29347  10.
29348  For example if you have switch statement with more than 10 case labels,
29349  each case label adds one to the complexity level.
29350  The complexity level is by no means an absolute measure of the algorithmic
29351  complexity of the function, it does however provide a good starting point
29352  for which functions you might look at for further optimization.
29353 \layout Section
29354
29355 Retargetting for other Processors
29356 \layout Standard
29357
29358 The issues for retargetting the compiler are far too numerous to be covered
29359  by this document.
29360  What follows is a brief description of each of the seven phases of the
29361  compiler and its MCU dependency.
29362 \layout Itemize
29363
29364 Parsing the source and building the annotated parse tree.
29365  This phase is largely MCU independent (except for the language extensions).
29366  Syntax & semantic checks are also done in this phase, along with some initial
29367  optimizations like back patching labels and the pattern matching optimizations
29368  like bit-rotation etc.
29369 \layout Itemize
29370
29371 The second phase involves generating an intermediate code which can be easy
29372  manipulated during the later phases.
29373  This phase is entirely MCU independent.
29374  The intermediate code generation assumes the target machine has unlimited
29375  number of registers, and designates them with the name iTemp.
29376  The compiler can be made to dump a human readable form of the code generated
29377  by using the -
29378 \begin_inset ERT
29379 status Collapsed
29380
29381 \layout Standard
29382
29383 \backslash 
29384 /
29385 \end_inset 
29386
29387 -dumpraw option.
29388 \layout Itemize
29389
29390 This phase does the bulk of the standard optimizations and is also MCU independe
29391 nt.
29392  This phase can be broken down into several sub-phases:
29393 \newline 
29394
29395 \newline 
29396 Break down intermediate code (iCode) into basic blocks.
29397 \newline 
29398 Do control flow & data flow analysis on the basic blocks.
29399 \newline 
29400 Do local common subexpression elimination, then global subexpression elimination
29401 \newline 
29402 Dead code elimination
29403 \newline 
29404 Loop optimizations
29405 \newline 
29406 If loop optimizations caused any changes then do 'global subexpression eliminati
29407 on' and 'dead code elimination' again.
29408 \layout Itemize
29409
29410 This phase determines the live-ranges; by live range I mean those iTemp
29411  variables defined by the compiler that still survive after all the optimization
29412 s.
29413  Live range analysis
29414 \begin_inset LatexCommand \index{Live range analysis}
29415
29416 \end_inset 
29417
29418  is essential for register allocation, since these computation determines
29419  which of these iTemps will be assigned to registers, and for how long.
29420 \layout Itemize
29421
29422 Phase five is register allocation.
29423  There are two parts to this process.
29424 \newline 
29425
29426 \newline 
29427 The first part I call 'register packing' (for lack of a better term).
29428  In this case several MCU specific expression folding is done to reduce
29429  register pressure.
29430 \newline 
29431
29432 \newline 
29433 The second part is more MCU independent and deals with allocating registers
29434  to the remaining live ranges.
29435  A lot of MCU specific code does creep into this phase because of the limited
29436  number of index registers available in the 8051.
29437 \layout Itemize
29438
29439 The Code generation phase is (unhappily), entirely MCU dependent and very
29440  little (if any at all) of this code can be reused for other MCU.
29441  However the scheme for allocating a homogenized assembler operand for each
29442  iCode operand may be reused.
29443 \layout Itemize
29444
29445 As mentioned in the optimization section the peep-hole optimizer is rule
29446  based system, which can reprogrammed for other MCUs.
29447 \layout Chapter
29448
29449 Compiler internals
29450 \begin_inset LatexCommand \index{Compiler internals}
29451
29452 \end_inset 
29453
29454
29455 \layout Section
29456
29457 The anatomy of the compiler
29458 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29459
29460 \end_inset 
29461
29462
29463 \layout Standard
29464
29465
29466 \shape italic 
29467 This is an excerpt from an article published in Circuit Cellar Magazine
29468  in 
29469 \series bold 
29470 August 2000
29471 \series default 
29472 .
29473  It's a little outdated (the compiler is much more efficient now and user/develo
29474 per friendly), but pretty well exposes the guts of it all.
29475 \shape default 
29476
29477 \newline 
29478
29479 \newline 
29480 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
29481  It is fairly easy to retarget for other 8-bit MCU.
29482  Here we take a look at some of the internals of the compiler.
29483  
29484 \layout Paragraph*
29485
29486 Parsing
29487 \begin_inset LatexCommand \index{Parsing}
29488
29489 \end_inset 
29490
29491  
29492 \layout Standard
29493
29494 Parsing the input source file and creating an AST (Annotated Syntax Tree
29495 \begin_inset LatexCommand \index{Annotated syntax tree}
29496
29497 \end_inset 
29498
29499 ).
29500  This phase also involves propagating types (annotating each node of the
29501  parse tree with type information) and semantic analysis.
29502  There are some MCU specific parsing rules.
29503  For example the storage classes, the extended storage classes are MCU specific
29504  while there may be a xdata storage class for 8051 there is no such storage
29505  class for z80 or Atmel AVR.
29506  SDCC allows MCU specific storage class extensions, i.e.
29507  xdata will be treated as a storage class specifier when parsing 8051 C
29508  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
29509  C code.
29510 \layout Paragraph*
29511
29512 Generating iCode
29513 \begin_inset LatexCommand \index{iCode}
29514
29515 \end_inset 
29516
29517
29518 \layout Standard
29519
29520 Intermediate code generation.
29521  In this phase the AST is broken down into three-operand form (iCode).
29522  These three operand forms are represented as doubly linked lists.
29523  ICode is the term given to the intermediate form generated by the compiler.
29524  ICode example section shows some examples of iCode generated for some simple
29525  C source functions.
29526 \layout Paragraph*
29527
29528 Optimizations
29529 \begin_inset LatexCommand \index{Optimizations}
29530
29531 \end_inset 
29532
29533 .
29534 \layout Standard
29535
29536 Bulk of the target independent optimizations is performed in this phase.
29537  The optimizations include constant propagation, common sub-expression eliminati
29538 on, loop invariant code movement, strength reduction of loop induction variables
29539  and dead-code elimination.
29540 \layout Paragraph*
29541
29542 Live range analysis
29543 \begin_inset LatexCommand \index{Live range analysis}
29544
29545 \end_inset 
29546
29547
29548 \layout Standard
29549
29550 During intermediate code generation phase, the compiler assumes the target
29551  machine has infinite number of registers and generates a lot of temporary
29552  variables.
29553  The live range computation determines the lifetime of each of these compiler-ge
29554 nerated temporaries.
29555  A picture speaks a thousand words.
29556  ICode example sections show the live range annotations for each of the
29557  operand.
29558  It is important to note here, each iCode is assigned a number in the order
29559  of its execution in the function.
29560  The live ranges are computed in terms of these numbers.
29561  The from number is the number of the iCode which first defines the operand
29562  and the to number signifies the iCode which uses this operand last.
29563 \layout Paragraph*
29564
29565 Register Allocation
29566 \begin_inset LatexCommand \index{Register allocation}
29567
29568 \end_inset 
29569
29570
29571 \layout Standard
29572
29573 The register allocation determines the type and number of registers needed
29574  by each operand.
29575  In most MCUs only a few registers can be used for indirect addressing.
29576  In case of 8051 for example the registers R0 & R1 can be used to indirectly
29577  address the internal ram and DPTR to indirectly address the external ram.
29578  The compiler will try to allocate the appropriate register to pointer variables
29579  if it can.
29580  ICode example section shows the operands annotated with the registers assigned
29581  to them.
29582  The compiler will try to keep operands in registers as much as possible;
29583  there are several schemes the compiler uses to do achieve this.
29584  When the compiler runs out of registers the compiler will check to see
29585  if there are any live operands which is not used or defined in the current
29586  basic block being processed, if there are any found then it will push that
29587  operand and use the registers in this block, the operand will then be popped
29588  at the end of the basic block.
29589  
29590 \layout Standard
29591
29592 There are other MCU specific considerations in this phase.
29593  Some MCUs have an accumulator; very short-lived operands could be assigned
29594  to the accumulator instead of a general-purpose register.
29595 \layout Paragraph*
29596
29597 Code generation
29598 \layout Standard
29599
29600 Figure II gives a table of iCode operations supported by the compiler.
29601  The code generation involves translating these operations into corresponding
29602  assembly code for the processor.
29603  This sounds overly simple but that is the essence of code generation.
29604  Some of the iCode operations are generated on a MCU specific manner for
29605  example, the z80 port does not use registers to pass parameters so the
29606  SEND and RECV iCode operations will not be generated, and it also does
29607  not support JUMPTABLES.
29608  
29609 \newline 
29610
29611 \series bold 
29612 \shape italic 
29613 \color red
29614 <Where is Figure II?>
29615 \layout Comment
29616
29617 In the original article Figure II was announced to be downloadable on 
29618 \shape italic 
29619 Circuit Cellar
29620 \shape default 
29621 's web site.
29622  Unfortunately it never seemed to have shown up there, so: where is Figure
29623  II?
29624 \layout Paragraph*
29625
29626 ICode Example
29627 \begin_inset LatexCommand \index{iCode}
29628
29629 \end_inset 
29630
29631
29632 \layout Standard
29633
29634 This section shows some details of iCode.
29635  The example C code does not do anything useful; it is used as an example
29636  to illustrate the intermediate code generated by the compiler.
29637 \layout Verse
29638
29639
29640 \family typewriter 
29641 1.\SpecialChar ~
29642 xdata int * p;
29643 \newline 
29644 2.\SpecialChar ~
29645 int gint;
29646 \newline 
29647 3.\SpecialChar ~
29648 /* This function does nothing useful.
29649  It is used
29650 \newline 
29651 4.\SpecialChar ~
29652 \SpecialChar ~
29653 \SpecialChar ~
29654 \SpecialChar ~
29655 for the purpose of explaining iCode */
29656 \newline 
29657 5.\SpecialChar ~
29658 short function (data int *x)
29659 \newline 
29660 6.\SpecialChar ~
29661 {
29662 \newline 
29663 7.\SpecialChar ~
29664 \SpecialChar ~
29665 \SpecialChar ~
29666 short i=10; \SpecialChar ~
29667 \SpecialChar ~
29668 /* dead initialization eliminated */
29669 \newline 
29670 8.\SpecialChar ~
29671 \SpecialChar ~
29672 \SpecialChar ~
29673 short sum=10; /* dead initialization eliminated */
29674 \newline 
29675 9.\SpecialChar ~
29676 \SpecialChar ~
29677 \SpecialChar ~
29678 short mul;
29679 \newline 
29680 10.\SpecialChar ~
29681 \SpecialChar ~
29682 int j ;
29683 \newline 
29684 11.\SpecialChar ~
29685 \SpecialChar ~
29686 while (*x) *x++ = *p++; 
29687 \newline 
29688 12.\SpecialChar ~
29689 \SpecialChar ~
29690 \SpecialChar ~
29691 \SpecialChar ~
29692 sum = 0 ; 
29693 \newline 
29694 13.\SpecialChar ~
29695 \SpecialChar ~
29696 mul = 0;
29697 \newline 
29698 14.\SpecialChar ~
29699 \SpecialChar ~
29700 /* compiler detects i,j to be induction variables */
29701 \newline 
29702 15.\SpecialChar ~
29703 \SpecialChar ~
29704 for (i = 0, j = 10 ; i < 10 ; i++, j
29705 \family default 
29706 -
29707 \begin_inset ERT
29708 status Collapsed
29709
29710 \layout Standard
29711
29712 \backslash 
29713 /
29714 \end_inset 
29715
29716 -
29717 \family typewriter 
29718 ) {
29719 \newline 
29720 16.\SpecialChar ~
29721 \SpecialChar ~
29722 \SpecialChar ~
29723 \SpecialChar ~
29724 sum += i;
29725 \newline 
29726 17.\SpecialChar ~
29727 \SpecialChar ~
29728 \SpecialChar ~
29729 \SpecialChar ~
29730 mul += i * 3; \SpecialChar ~
29731 \SpecialChar ~
29732 /* this multiplication remains */
29733 \newline 
29734 18.\SpecialChar ~
29735 \SpecialChar ~
29736 \SpecialChar ~
29737 \SpecialChar ~
29738 gint += j * 3;\SpecialChar ~
29739 \SpecialChar ~
29740 /* this multiplication changed to addition */
29741 \newline 
29742 19.\SpecialChar ~
29743 \SpecialChar ~
29744 }
29745 \newline 
29746 20.\SpecialChar ~
29747 \SpecialChar ~
29748 return sum+mul;
29749 \newline 
29750 21.\SpecialChar ~
29751 }
29752 \layout Standard
29753
29754 In addition to the operands each iCode contains information about the filename
29755  and line it corresponds to in the source file.
29756  The first field in the listing should be interpreted as follows:
29757 \newline 
29758
29759 \shape italic 
29760 \size footnotesize 
29761 Filename(linenumber: iCode Execution sequence number : ICode hash table
29762  key : loop depth of the iCode).
29763 \shape default 
29764 \size default 
29765
29766 \newline 
29767 Then follows the human readable form of the ICode operation.
29768  Each operand of this triplet form can be of three basic types a) compiler
29769  generated temporary b) user defined variable c) a constant value.
29770  Note that local variables and parameters are replaced by compiler generated
29771  temporaries.
29772  Live ranges
29773 \begin_inset LatexCommand \index{Live range analysis}
29774
29775 \end_inset 
29776
29777  are computed only for temporaries (i.e.
29778  live ranges are not computed for global variables).
29779  Registers
29780 \begin_inset LatexCommand \index{Register allocation}
29781
29782 \end_inset 
29783
29784  are allocated for temporaries only.
29785  Operands are formatted in the following manner:
29786 \newline 
29787
29788 \shape italic 
29789 \size footnotesize 
29790 Operand Name [lr live-from : live-to ] { type information } [ registers
29791  allocated ].
29792 \shape default 
29793 \size default 
29794
29795 \newline 
29796 As mentioned earlier the live ranges are computed in terms of the execution
29797  sequence number of the iCodes, for example 
29798 \newline 
29799 the iTemp0 is live from (i.e.
29800  first defined in iCode with execution sequence number 3, and is last used
29801  in the iCode with sequence number 5).
29802  For induction variables such as iTemp21 the live range computation extends
29803  the lifetime from the start to the end of the loop.
29804 \newline 
29805 The register allocator used the live range information to allocate registers,
29806  the same registers may be used for different temporaries if their live
29807  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
29808  iTemp17 since their live ranges do not overlap.
29809  In addition the allocator also takes into consideration the type and usage
29810  of a temporary, for example itemp6 is a pointer to near space and is used
29811  as to fetch data from (i.e.
29812  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
29813  Some short lived temporaries are allocated to special registers which have
29814  meaning to the code generator e.g.
29815  iTemp13 is allocated to a pseudo register CC which tells the back end that
29816  the temporary is used only for a conditional jump the code generation makes
29817  use of this information to optimize a compare and jump ICode.
29818 \newline 
29819 There are several loop optimizations
29820 \begin_inset LatexCommand \index{Loop optimization}
29821
29822 \end_inset 
29823
29824  performed by the compiler.
29825  It can detect induction variables iTemp21(i) and iTemp23(j).
29826  Also note the compiler does selective strength reduction
29827 \begin_inset LatexCommand \index{Strength reduction}
29828
29829 \end_inset 
29830
29831 , i.e.
29832  the multiplication of an induction variable in line 18 (gint = j * 3) is
29833  changed to addition, a new temporary iTemp17 is allocated and assigned
29834  a initial value, a constant 3 is then added for each iteration of the loop.
29835  The compiler does not change the multiplication
29836 \begin_inset LatexCommand \index{Multiplication}
29837
29838 \end_inset 
29839
29840  in line 17 however since the processor does support an 8 * 8 bit multiplication.
29841 \newline 
29842 Note the dead code elimination
29843 \begin_inset LatexCommand \index{Dead-code elimination}
29844
29845 \end_inset 
29846
29847  optimization eliminated the dead assignments in line 7 & 8 to I and sum
29848  respectively.
29849 \newline 
29850
29851 \layout Standard
29852
29853
29854 \size footnotesize 
29855 Sample.c (5:1:0:0) _entry($9) :
29856 \layout Standard
29857
29858
29859 \size footnotesize 
29860 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
29861 \layout Standard
29862
29863
29864 \size footnotesize 
29865 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
29866 \layout Standard
29867
29868
29869 \size footnotesize 
29870 Sample.c(11:4:53:0) preHeaderLbl0($11) :
29871 \layout Standard
29872
29873
29874 \size footnotesize 
29875 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
29876  * int}[r2]
29877 \layout Standard
29878
29879
29880 \size footnotesize 
29881 Sample.c(11:6:5:1) _whilecontinue_0($1) :
29882 \layout Standard
29883
29884
29885 \size footnotesize 
29886 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
29887  int}[r0]]
29888 \layout Standard
29889
29890
29891 \size footnotesize 
29892 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
29893 \layout Standard
29894
29895
29896 \size footnotesize 
29897 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
29898  * int}
29899 \layout Standard
29900
29901
29902 \size footnotesize 
29903 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
29904  {short}
29905 \layout Standard
29906
29907
29908 \size footnotesize 
29909 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
29910  * int}[DPTR]]
29911 \layout Standard
29912
29913
29914 \size footnotesize 
29915 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
29916 }[r2 r3]
29917 \layout Standard
29918
29919
29920 \size footnotesize 
29921 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
29922  * int}[r0] + 0x2 {short}
29923 \layout Standard
29924
29925
29926 \size footnotesize 
29927 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
29928 \layout Standard
29929
29930
29931 \size footnotesize 
29932 Sample.c(11:17:21:0)_whilebreak_0($3) :
29933 \layout Standard
29934
29935
29936 \size footnotesize 
29937 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
29938 \layout Standard
29939
29940
29941 \size footnotesize 
29942 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
29943 \layout Standard
29944
29945
29946 \size footnotesize 
29947 Sample.c(15:20:54:0)preHeaderLbl1($13) :
29948 \layout Standard
29949
29950
29951 \size footnotesize 
29952 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
29953 \layout Standard
29954
29955
29956 \size footnotesize 
29957 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
29958 \layout Standard
29959
29960
29961 \size footnotesize 
29962 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
29963 \layout Standard
29964
29965
29966 \size footnotesize 
29967 Sample.c(15:24:26:1)_forcond_0($4) :
29968 \layout Standard
29969
29970
29971 \size footnotesize 
29972 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
29973  < 0xa {short}
29974 \layout Standard
29975
29976
29977 \size footnotesize 
29978 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
29979 \layout Standard
29980
29981
29982 \size footnotesize 
29983 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
29984  + ITemp21 [lr21:38]{short}[r4]
29985 \layout Standard
29986
29987
29988 \size footnotesize 
29989 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
29990  * 0x3 {short}
29991 \layout Standard
29992
29993
29994 \size footnotesize 
29995 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
29996  + iTemp15 [lr29:30]{short}[r1]
29997 \layout Standard
29998
29999
30000 \size footnotesize 
30001 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
30002  r0]- 0x3 {short}
30003 \layout Standard
30004
30005
30006 \size footnotesize 
30007 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
30008 int}[r7 r0]
30009 \layout Standard
30010
30011
30012 \size footnotesize 
30013 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
30014  + 0x1 {short}
30015 \layout Standard
30016
30017
30018 \size footnotesize 
30019 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
30020  r6]- 0x1 {short}
30021 \layout Standard
30022
30023
30024 \size footnotesize 
30025 Sample.c(19:38:47:1) goto _forcond_0($4)
30026 \layout Standard
30027
30028
30029 \size footnotesize 
30030 Sample.c(19:39:48:0)_forbreak_0($7) :
30031 \layout Standard
30032
30033
30034 \size footnotesize 
30035 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
30036  + ITemp11 [lr19:40]{short}[r3]
30037 \layout Standard
30038
30039
30040 \size footnotesize 
30041 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
30042 \layout Standard
30043
30044
30045 \size footnotesize 
30046 Sample.c(20:42:51:0)_return($8) :
30047 \layout Standard
30048
30049
30050 \size footnotesize 
30051 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
30052 \size default 
30053
30054 \newline 
30055
30056 \newline 
30057 Finally the code generated for this function:
30058 \newline 
30059
30060 \layout Standard
30061
30062
30063 \size footnotesize 
30064 .area DSEG (DATA)
30065 \layout Standard
30066
30067
30068 \size footnotesize 
30069 _p::
30070 \layout Standard
30071
30072
30073 \size footnotesize 
30074 \SpecialChar ~
30075 \SpecialChar ~
30076 .ds 2
30077 \layout Standard
30078
30079
30080 \size footnotesize 
30081 _gint::
30082 \layout Standard
30083
30084
30085 \size footnotesize 
30086 \SpecialChar ~
30087 \SpecialChar ~
30088 .ds 2
30089 \layout Standard
30090
30091
30092 \size footnotesize 
30093 ; sample.c 5
30094 \layout Standard
30095
30096
30097 \size footnotesize 
30098 ; ----------------------------------------------
30099 \layout Standard
30100
30101
30102 \size footnotesize 
30103 ; function function
30104 \layout Standard
30105
30106
30107 \size footnotesize 
30108 ; ----------------------------------------------
30109 \layout Standard
30110
30111
30112 \size footnotesize 
30113 _function:
30114 \layout Standard
30115
30116
30117 \size footnotesize 
30118 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
30119 \layout Standard
30120
30121
30122 \size footnotesize 
30123 \SpecialChar ~
30124 \SpecialChar ~
30125 mov r2,dpl
30126 \layout Standard
30127
30128
30129 \size footnotesize 
30130 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
30131 \layout Standard
30132
30133
30134 \size footnotesize 
30135 \SpecialChar ~
30136 \SpecialChar ~
30137 mov ar0,r2
30138 \layout Standard
30139
30140
30141 \size footnotesize 
30142 ;_whilecontinue_0($1) :
30143 \layout Standard
30144
30145
30146 \size footnotesize 
30147 00101$:
30148 \layout Standard
30149
30150
30151 \size footnotesize 
30152 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
30153 \layout Standard
30154
30155
30156 \size footnotesize 
30157 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
30158 \layout Standard
30159
30160
30161 \size footnotesize 
30162 \SpecialChar ~
30163 \SpecialChar ~
30164 mov ar2,@r0
30165 \layout Standard
30166
30167
30168 \size footnotesize 
30169 \SpecialChar ~
30170 \SpecialChar ~
30171 inc r0
30172 \layout Standard
30173
30174
30175 \size footnotesize 
30176 \SpecialChar ~
30177 \SpecialChar ~
30178 mov ar3,@r0
30179 \layout Standard
30180
30181
30182 \size footnotesize 
30183 \SpecialChar ~
30184 \SpecialChar ~
30185 dec r0
30186 \layout Standard
30187
30188
30189 \size footnotesize 
30190 \SpecialChar ~
30191 \SpecialChar ~
30192 mov a,r2
30193 \layout Standard
30194
30195
30196 \size footnotesize 
30197 \SpecialChar ~
30198 \SpecialChar ~
30199 orl a,r3
30200 \layout Standard
30201
30202
30203 \size footnotesize 
30204 \SpecialChar ~
30205 \SpecialChar ~
30206 jz 00103$
30207 \layout Standard
30208
30209
30210 \size footnotesize 
30211 00114$:
30212 \layout Standard
30213
30214
30215 \size footnotesize 
30216 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
30217 \layout Standard
30218
30219
30220 \size footnotesize 
30221 \SpecialChar ~
30222 \SpecialChar ~
30223 mov dpl,_p
30224 \layout Standard
30225
30226
30227 \size footnotesize 
30228 \SpecialChar ~
30229 \SpecialChar ~
30230 mov dph,(_p + 1)
30231 \layout Standard
30232
30233
30234 \size footnotesize 
30235 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
30236 \layout Standard
30237
30238
30239 \size footnotesize 
30240 \SpecialChar ~
30241 \SpecialChar ~
30242 mov a,#0x02
30243 \layout Standard
30244
30245
30246 \size footnotesize 
30247 \SpecialChar ~
30248 \SpecialChar ~
30249 add a,_p
30250 \layout Standard
30251
30252
30253 \size footnotesize 
30254 \SpecialChar ~
30255 \SpecialChar ~
30256 mov _p,a
30257 \layout Standard
30258
30259
30260 \size footnotesize 
30261 \SpecialChar ~
30262 \SpecialChar ~
30263 clr a
30264 \layout Standard
30265
30266
30267 \size footnotesize 
30268 \SpecialChar ~
30269 \SpecialChar ~
30270 addc a,(_p + 1)
30271 \layout Standard
30272
30273
30274 \size footnotesize 
30275 \SpecialChar ~
30276 \SpecialChar ~
30277 mov (_p + 1),a
30278 \layout Standard
30279
30280
30281 \size footnotesize 
30282 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
30283 \layout Standard
30284
30285
30286 \size footnotesize 
30287 \SpecialChar ~
30288 \SpecialChar ~
30289 movx a,@dptr
30290 \layout Standard
30291
30292
30293 \size footnotesize 
30294 \SpecialChar ~
30295 \SpecialChar ~
30296 mov r2,a
30297 \layout Standard
30298
30299
30300 \size footnotesize 
30301 \SpecialChar ~
30302 \SpecialChar ~
30303 inc dptr
30304 \layout Standard
30305
30306
30307 \size footnotesize 
30308 \SpecialChar ~
30309 \SpecialChar ~
30310 movx a,@dptr
30311 \layout Standard
30312
30313
30314 \size footnotesize 
30315 \SpecialChar ~
30316 \SpecialChar ~
30317 mov r3,a
30318 \layout Standard
30319
30320
30321 \size footnotesize 
30322 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
30323 \layout Standard
30324
30325
30326 \size footnotesize 
30327 \SpecialChar ~
30328 \SpecialChar ~
30329 mov @r0,ar2
30330 \layout Standard
30331
30332
30333 \size footnotesize 
30334 \SpecialChar ~
30335 \SpecialChar ~
30336 inc r0
30337 \layout Standard
30338
30339
30340 \size footnotesize 
30341 \SpecialChar ~
30342 \SpecialChar ~
30343 mov @r0,ar3
30344 \layout Standard
30345
30346
30347 \size footnotesize 
30348 ; iTemp6 [lr5:16]{_near * int}[r0] = 
30349 \layout Standard
30350
30351
30352 \size footnotesize 
30353 ; iTemp6 [lr5:16]{_near * int}[r0] + 
30354 \layout Standard
30355
30356
30357 \size footnotesize 
30358 ; 0x2 {short}
30359 \layout Standard
30360
30361
30362 \size footnotesize 
30363 \SpecialChar ~
30364 \SpecialChar ~
30365 inc r0
30366 \layout Standard
30367
30368
30369 \size footnotesize 
30370 ; goto _whilecontinue_0($1)
30371 \layout Standard
30372
30373
30374 \size footnotesize 
30375 \SpecialChar ~
30376 \SpecialChar ~
30377 sjmp 00101$
30378 \layout Standard
30379
30380
30381 \size footnotesize 
30382 ; _whilebreak_0($3) :
30383 \layout Standard
30384
30385
30386 \size footnotesize 
30387 00103$:
30388 \layout Standard
30389
30390
30391 \size footnotesize 
30392 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
30393 \layout Standard
30394
30395
30396 \size footnotesize 
30397 \SpecialChar ~
30398 \SpecialChar ~
30399 mov r2,#0x00
30400 \layout Standard
30401
30402
30403 \size footnotesize 
30404 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
30405 \layout Standard
30406
30407
30408 \size footnotesize 
30409 \SpecialChar ~
30410 \SpecialChar ~
30411 mov r3,#0x00
30412 \layout Standard
30413
30414
30415 \size footnotesize 
30416 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
30417 \layout Standard
30418
30419
30420 \size footnotesize 
30421 \SpecialChar ~
30422 \SpecialChar ~
30423 mov r4,#0x00
30424 \layout Standard
30425
30426
30427 \size footnotesize 
30428 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
30429 \layout Standard
30430
30431
30432 \size footnotesize 
30433 \SpecialChar ~
30434 \SpecialChar ~
30435 mov r5,#0x0A
30436 \layout Standard
30437
30438
30439 \size footnotesize 
30440 \SpecialChar ~
30441 \SpecialChar ~
30442 mov r6,#0x00
30443 \layout Standard
30444
30445
30446 \size footnotesize 
30447 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
30448 \layout Standard
30449
30450
30451 \size footnotesize 
30452 \SpecialChar ~
30453 \SpecialChar ~
30454 mov r7,#0x1E
30455 \layout Standard
30456
30457
30458 \size footnotesize 
30459 \SpecialChar ~
30460 \SpecialChar ~
30461 mov r0,#0x00
30462 \layout Standard
30463
30464
30465 \size footnotesize 
30466 ; _forcond_0($4) :
30467 \layout Standard
30468
30469
30470 \size footnotesize 
30471 00104$:
30472 \layout Standard
30473
30474
30475 \size footnotesize 
30476 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
30477 \layout Standard
30478
30479
30480 \size footnotesize 
30481 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
30482 \layout Standard
30483
30484
30485 \size footnotesize 
30486 \SpecialChar ~
30487 \SpecialChar ~
30488 clr c
30489 \layout Standard
30490
30491
30492 \size footnotesize 
30493 \SpecialChar ~
30494 \SpecialChar ~
30495 mov a,r4
30496 \layout Standard
30497
30498
30499 \size footnotesize 
30500 \SpecialChar ~
30501 \SpecialChar ~
30502 xrl a,#0x80
30503 \layout Standard
30504
30505
30506 \size footnotesize 
30507 \SpecialChar ~
30508 \SpecialChar ~
30509 subb a,#0x8a
30510 \layout Standard
30511
30512
30513 \size footnotesize 
30514 \SpecialChar ~
30515 \SpecialChar ~
30516 jnc 00107$
30517 \layout Standard
30518
30519
30520 \size footnotesize 
30521 00115$:
30522 \layout Standard
30523
30524
30525 \size footnotesize 
30526 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
30527 \layout Standard
30528
30529
30530 \size footnotesize 
30531 ; iTemp21 [lr21:38]{short}[r4]
30532 \layout Standard
30533
30534
30535 \size footnotesize 
30536 \SpecialChar ~
30537 \SpecialChar ~
30538 mov a,r4
30539 \layout Standard
30540
30541
30542 \size footnotesize 
30543 \SpecialChar ~
30544 \SpecialChar ~
30545 add a,r2
30546 \layout Standard
30547
30548
30549 \size footnotesize 
30550 \SpecialChar ~
30551 \SpecialChar ~
30552 mov r2,a
30553 \layout Standard
30554
30555
30556 \size footnotesize 
30557 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
30558 \layout Standard
30559
30560
30561 \size footnotesize 
30562 \SpecialChar ~
30563 \SpecialChar ~
30564 mov b,#0x03
30565 \layout Standard
30566
30567
30568 \size footnotesize 
30569 \SpecialChar ~
30570 \SpecialChar ~
30571 mov a,r4
30572 \layout Standard
30573
30574
30575 \size footnotesize 
30576 \SpecialChar ~
30577 \SpecialChar ~
30578 mul ab
30579 \layout Standard
30580
30581
30582 \size footnotesize 
30583 \SpecialChar ~
30584 \SpecialChar ~
30585 mov r1,a
30586 \layout Standard
30587
30588
30589 \size footnotesize 
30590 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
30591 \layout Standard
30592
30593
30594 \size footnotesize 
30595 ; iTemp15 [lr29:30]{short}[r1]
30596 \layout Standard
30597
30598
30599 \size footnotesize 
30600 \SpecialChar ~
30601 \SpecialChar ~
30602 add a,r3
30603 \layout Standard
30604
30605
30606 \size footnotesize 
30607 \SpecialChar ~
30608 \SpecialChar ~
30609 mov r3,a
30610 \layout Standard
30611
30612
30613 \size footnotesize 
30614 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
30615 \layout Standard
30616
30617
30618 \size footnotesize 
30619 \SpecialChar ~
30620 \SpecialChar ~
30621 mov a,r7
30622 \layout Standard
30623
30624
30625 \size footnotesize 
30626 \SpecialChar ~
30627 \SpecialChar ~
30628 add a,#0xfd
30629 \layout Standard
30630
30631
30632 \size footnotesize 
30633 \SpecialChar ~
30634 \SpecialChar ~
30635 mov r7,a
30636 \layout Standard
30637
30638
30639 \size footnotesize 
30640 \SpecialChar ~
30641 \SpecialChar ~
30642 mov a,r0
30643 \layout Standard
30644
30645
30646 \size footnotesize 
30647 \SpecialChar ~
30648 \SpecialChar ~
30649 addc a,#0xff
30650 \layout Standard
30651
30652
30653 \size footnotesize 
30654 \SpecialChar ~
30655 \SpecialChar ~
30656 mov r0,a
30657 \layout Standard
30658
30659
30660 \size footnotesize 
30661 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
30662 \layout Standard
30663
30664
30665 \size footnotesize 
30666 \SpecialChar ~
30667 \SpecialChar ~
30668 mov a,r7
30669 \layout Standard
30670
30671
30672 \size footnotesize 
30673 \SpecialChar ~
30674 \SpecialChar ~
30675 add a,_gint
30676 \layout Standard
30677
30678
30679 \size footnotesize 
30680 \SpecialChar ~
30681 \SpecialChar ~
30682 mov _gint,a
30683 \layout Standard
30684
30685
30686 \size footnotesize 
30687 \SpecialChar ~
30688 \SpecialChar ~
30689 mov a,r0
30690 \layout Standard
30691
30692
30693 \size footnotesize 
30694 \SpecialChar ~
30695 \SpecialChar ~
30696 addc a,(_gint + 1)
30697 \layout Standard
30698
30699
30700 \size footnotesize 
30701 \SpecialChar ~
30702 \SpecialChar ~
30703 mov (_gint + 1),a
30704 \layout Standard
30705
30706
30707 \size footnotesize 
30708 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
30709 \layout Standard
30710
30711
30712 \size footnotesize 
30713 \SpecialChar ~
30714 \SpecialChar ~
30715 inc r4
30716 \layout Standard
30717
30718
30719 \size footnotesize 
30720 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
30721 \layout Standard
30722
30723
30724 \size footnotesize 
30725 \SpecialChar ~
30726 \SpecialChar ~
30727 dec r5
30728 \layout Standard
30729
30730
30731 \size footnotesize 
30732 \SpecialChar ~
30733 \SpecialChar ~
30734 cjne r5,#0xff,00104$
30735 \layout Standard
30736
30737
30738 \size footnotesize 
30739 \SpecialChar ~
30740 \SpecialChar ~
30741 dec r6
30742 \layout Standard
30743
30744
30745 \size footnotesize 
30746 ; goto _forcond_0($4)
30747 \layout Standard
30748
30749
30750 \size footnotesize 
30751 \SpecialChar ~
30752 \SpecialChar ~
30753 sjmp 00104$
30754 \layout Standard
30755
30756
30757 \size footnotesize 
30758 ; _forbreak_0($7) :
30759 \layout Standard
30760
30761
30762 \size footnotesize 
30763 00107$:
30764 \layout Standard
30765
30766
30767 \size footnotesize 
30768 ; ret iTemp24 [lr40:41]{short}
30769 \layout Standard
30770
30771
30772 \size footnotesize 
30773 \SpecialChar ~
30774 \SpecialChar ~
30775 mov a,r3
30776 \layout Standard
30777
30778
30779 \size footnotesize 
30780 \SpecialChar ~
30781 \SpecialChar ~
30782 add a,r2
30783 \layout Standard
30784
30785
30786 \size footnotesize 
30787 \SpecialChar ~
30788 \SpecialChar ~
30789 mov dpl,a
30790 \layout Standard
30791
30792
30793 \size footnotesize 
30794 ; _return($8) :
30795 \layout Standard
30796
30797
30798 \size footnotesize 
30799 00108$:
30800 \layout Standard
30801
30802
30803 \size footnotesize 
30804 \SpecialChar ~
30805 \SpecialChar ~
30806 ret
30807 \newline 
30808
30809 \layout Section
30810
30811 A few words about basic block successors, predecessors and dominators
30812 \layout Standard
30813
30814 Successors are basic blocks
30815 \begin_inset LatexCommand \index{Basic blocks}
30816
30817 \end_inset 
30818
30819  that might execute after this basic block.
30820 \newline 
30821 Predecessors are basic blocks that might execute before reaching this basic
30822  block.
30823 \newline 
30824 Dominators are basic blocks that WILL execute before reaching this basic
30825  block.
30826 \newline 
30827
30828 \layout Standard
30829
30830 [basic block 1]
30831 \layout Standard
30832
30833 if (something)
30834 \layout Standard
30835
30836 \SpecialChar ~
30837 \SpecialChar ~
30838 \SpecialChar ~
30839 \SpecialChar ~
30840 [basic block 2]
30841 \layout Standard
30842
30843 else
30844 \layout Standard
30845
30846 \SpecialChar ~
30847 \SpecialChar ~
30848 \SpecialChar ~
30849 \SpecialChar ~
30850 [basic block 3]
30851 \layout Standard
30852
30853 [basic block 4]
30854 \newline 
30855
30856 \layout Standard
30857
30858 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
30859 \layout Standard
30860
30861 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
30862 \layout Standard
30863
30864 c) domVect of [BB4] = BB1 ...
30865  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
30866  was executed.
30867 \layout Chapter
30868
30869 Acknowledgments
30870 \layout Standard
30871
30872
30873 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
30874
30875 \end_inset 
30876
30877
30878 \newline 
30879
30880 \newline 
30881
30882 \emph on 
30883 Thanks to all the other volunteer developers who have helped with coding,
30884  testing, web-page creation, distribution sets, etc.
30885  You know who you are :-)
30886 \emph default 
30887
30888 \newline 
30889
30890 \layout Standard
30891
30892 This document was initially written by Sandeep Dutta
30893 \layout Standard
30894
30895 All product names mentioned herein may be trademarks
30896 \begin_inset LatexCommand \index{Trademarks}
30897
30898 \end_inset 
30899
30900  of their respective companies.
30901  
30902 \layout Section*
30903
30904 Alphabetical index
30905 \layout Standard
30906
30907 To avoid confusion, the installation and building options for SDCC itself
30908  (chapter 2) are not part of the index.
30909 \layout Standard
30910
30911
30912 \begin_inset LatexCommand \printindex{}
30913
30914 \end_inset 
30915
30916
30917 \the_end