convert sdccman.lyx back to 221 format
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.1 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 \use_geometry 1
29 \use_amsmath 0
30 \use_natbib 0
31 \use_numerical_citations 0
32 \paperorientation portrait
33 \leftmargin 30mm
34 \topmargin 20mm
35 \rightmargin 25mm
36 \bottommargin 20mm
37 \secnumdepth 3
38 \tocdepth 3
39 \paragraph_separation indent
40 \defskip medskip
41 \quotes_language swedish
42 \papercolumns 1
43 \papersides 1
44 \paperpagestyle fancy
45
46 \layout Standard
47 \begin_inset Note
48 collapsed true
49
50 \layout Standard
51 Please note: double dashed longoptions (e.g.
52  --version) are written this way: -
53 \begin_inset ERT
54 status Collapsed
55
56 \layout Standard
57
58
59 \backslash
60 /
61
62 \end_inset
63
64 -
65
66 \layout Standard
67 Two resp.
68  three consecutive dashes simply result in a long resp.
69  extra long dash.
70
71 \layout Standard
72 Architecture specific stuff (like memory models, code examples) should maybe
73  later go
74
75 \layout Standard
76 into seperate sections/chapters/appendices (it is hard to document PIC or
77  Z80 in 
78
79 \layout Standard
80 a 8051 centered document) - for now simply add.
81
82 \end_inset
83
84
85
86 \layout Title
87 SDCC Compiler User Guide
88
89 \layout Date
90
91 \size normal
92 SDCC 2.6.4
93 \size footnotesize
94
95 \newline
96 $Date$ 
97 \newline
98 $Revision$
99
100 \layout Standard
101 \begin_inset Note
102 collapsed true
103
104 \layout Standard
105 The above strings enclosed in $ are automatically updated by Subversion
106
107 \end_inset
108
109
110
111 \layout Standard
112 \begin_inset LatexCommand \tableofcontents{}
113
114 \end_inset
115
116
117
118 \layout Chapter
119 Introduction
120
121 \layout Section
122 About SDCC
123
124 \layout Standard
125
126 \series bold
127 SDCC
128 \series default
129  (
130 \emph on
131 S
132 \emph default
133 mall 
134 \emph on
135 D
136 \emph default
137 evice 
138 \emph on
139 C
140 \emph default
141  
142 \emph on
143 C
144 \emph default
145 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
146  
147 \series bold
148 Sandeep Dutta
149 \series default
150  designed for 8 bit Microprocessors.
151  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
152  8051, 8052
153 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
154
155 \end_inset
156
157 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
158  Zilog Z80 based MCUs.
159  It can be retargeted for other microprocessors, support for Microchip PIC,
160  Atmel AVR is under development.
161  The entire source code for the compiler is distributed under GPL.
162  SDCC uses ASXXXX
163 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
164
165 \end_inset
166
167  & ASLINK
168 \begin_inset LatexCommand \index{aslink}
169
170 \end_inset
171
172 , an open source retargetable assembler & linker.
173  SDCC has extensive language extensions suitable for utilizing various microcont
174 rollers and underlying hardware effectively.
175  
176 \newline
177
178 \newline
179 In addition to the MCU specific optimizations SDCC also does a host of
180  standard optimizations like:
181
182 \layout Itemize
183 global sub expression elimination, 
184
185 \layout Itemize
186 loop optimizations (loop invariant, strength reduction of induction variables
187  and loop reversing), 
188
189 \layout Itemize
190 constant folding & propagation, 
191
192 \layout Itemize
193 copy propagation, 
194
195 \layout Itemize
196 dead code elimination 
197
198 \layout Itemize
199 jump tables for 
200 \emph on
201 switch
202 \emph default
203  statements.
204
205 \layout Standard
206 For the back-end SDCC uses a global register allocation scheme which should
207  be well suited for other 8 bit MCUs.
208  
209 \newline
210
211 \newline
212 The peep hole optimizer uses a rule based substitution mechanism which
213  is MCU independent.
214  
215 \newline
216
217 \newline
218 Supported data-types are:
219
220 \layout Standard
221 \begin_inset Tabular
222 <lyxtabular version="3" rows="8" columns="5">
223 <features>
224 <column alignment="center" valignment="top" leftline="true" width="0">
225 <column alignment="center" valignment="top" leftline="true" width="0">
226 <column alignment="center" valignment="top" leftline="true" width="0">
227 <column alignment="center" valignment="top" leftline="true" width="0">
228 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
229 <row topline="true" bottomline="true">
230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
231 \begin_inset Text
232
233 \layout Standard
234 type
235
236 \end_inset
237 </cell>
238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
239 \begin_inset Text
240
241 \layout Standard
242 width
243
244 \end_inset
245 </cell>
246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
247 \begin_inset Text
248
249 \layout Standard
250 default
251
252 \end_inset
253 </cell>
254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
255 \begin_inset Text
256
257 \layout Standard
258 signed range
259
260 \end_inset
261 </cell>
262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
263 \begin_inset Text
264
265 \layout Standard
266 unsigned range
267
268 \end_inset
269 </cell>
270 </row>
271 <row topline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
273 \begin_inset Text
274
275 \layout Standard
276 bool
277
278 \end_inset
279 </cell>
280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
281 \begin_inset Text
282
283 \layout Standard
284 1 bit
285
286 \end_inset
287 </cell>
288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_inset Text
290
291 \layout Standard
292 unsigned
293
294 \end_inset
295 </cell>
296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
297 \begin_inset Text
298
299 \layout Standard
300 -
301
302 \end_inset
303 </cell>
304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
305 \begin_inset Text
306
307 \layout Standard
308 0, 1
309
310 \end_inset
311 </cell>
312 </row>
313 <row topline="true">
314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
315 \begin_inset Text
316
317 \layout Standard
318 char
319
320 \end_inset
321 </cell>
322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
323 \begin_inset Text
324
325 \layout Standard
326 8 bits, 1 byte
327
328 \end_inset
329 </cell>
330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
331 \begin_inset Text
332
333 \layout Standard
334 signed
335
336 \end_inset
337 </cell>
338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
339 \begin_inset Text
340
341 \layout Standard
342 -128, +127
343
344 \end_inset
345 </cell>
346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
347 \begin_inset Text
348
349 \layout Standard
350 0, +255
351
352 \end_inset
353 </cell>
354 </row>
355 <row topline="true">
356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
357 \begin_inset Text
358
359 \layout Standard
360 short
361
362 \end_inset
363 </cell>
364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_inset Text
366
367 \layout Standard
368 16 bits, 2 bytes
369
370 \end_inset
371 </cell>
372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
373 \begin_inset Text
374
375 \layout Standard
376 signed
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \layout Standard
384 -32.768, +32.767
385
386 \end_inset
387 </cell>
388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
389 \begin_inset Text
390
391 \layout Standard
392 0, +65.535
393
394 \end_inset
395 </cell>
396 </row>
397 <row topline="true">
398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
399 \begin_inset Text
400
401 \layout Standard
402 int
403
404 \end_inset
405 </cell>
406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
407 \begin_inset Text
408
409 \layout Standard
410 16 bits, 2 bytes
411
412 \end_inset
413 </cell>
414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
415 \begin_inset Text
416
417 \layout Standard
418 signed
419
420 \end_inset
421 </cell>
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
423 \begin_inset Text
424
425 \layout Standard
426 -32.768, +32.767
427
428 \end_inset
429 </cell>
430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
431 \begin_inset Text
432
433 \layout Standard
434 0, +65.535
435
436 \end_inset
437 </cell>
438 </row>
439 <row topline="true" bottomline="true">
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
441 \begin_inset Text
442
443 \layout Standard
444 long
445
446 \end_inset
447 </cell>
448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
449 \begin_inset Text
450
451 \layout Standard
452 32 bits, 4 bytes
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \layout Standard
460 signed
461
462 \end_inset
463 </cell>
464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
465 \begin_inset Text
466
467 \layout Standard
468 -2.147.483.648, +2.147.483.647
469
470 \end_inset
471 </cell>
472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
473 \begin_inset Text
474
475 \layout Standard
476 0, +4.294.967.295
477
478 \end_inset
479 </cell>
480 </row>
481 <row topline="true" bottomline="true">
482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
483 \begin_inset Text
484
485 \layout Standard
486 float
487
488 \end_inset
489 </cell>
490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
491 \begin_inset Text
492
493 \layout Standard
494 4 bytes IEEE 754
495
496 \end_inset
497 </cell>
498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
499 \begin_inset Text
500
501 \layout Standard
502 signed
503
504 \end_inset
505 </cell>
506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
507 \begin_inset Text
508
509 \layout Standard
510
511
512 \end_inset
513 </cell>
514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
515 \begin_inset Text
516
517 \layout Standard
518 1.175494351E-38, 
519 \family roman
520 \series medium
521 \shape up
522 \size normal
523 \emph off
524 \bar no
525 \noun off
526 \color none
527 3.402823466E+38
528
529 \end_inset
530 </cell>
531 </row>
532 <row topline="true" bottomline="true">
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
534 \begin_inset Text
535
536 \layout Standard
537 pointer
538
539 \end_inset
540 </cell>
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \layout Standard
545 1, 2, 3 or 4 bytes
546
547 \end_inset
548 </cell>
549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
550 \begin_inset Text
551
552 \layout Standard
553 generic
554
555 \end_inset
556 </cell>
557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
558 \begin_inset Text
559
560 \layout Standard
561
562
563 \end_inset
564 </cell>
565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
566 \begin_inset Text
567
568 \layout Standard
569
570
571 \end_inset
572 </cell>
573 </row>
574 </lyxtabular>
575
576 \end_inset
577
578
579 \newline
580 The compiler also allows 
581 \emph on
582 inline assembler code
583 \emph default
584  to be embedded anywhere in a function.
585  In addition, routines developed in assembly can also be called.
586 \newline
587
588 \newline
589 SDCC also
590  provides an option (-
591 \begin_inset ERT
592 status Collapsed
593
594 \layout Standard
595
596
597 \backslash
598 /
599
600 \end_inset
601
602 -cyclomatic) to report the relative complexity of a function.
603  These functions can then be further optimized, or hand coded in assembly
604  if needed.
605  
606 \newline
607
608 \newline
609 SDCC also comes with a companion source level debugger SDCDB, the debugger
610  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
611 \newline
612
613 \newline
614
615 The latest version can be downloaded from 
616 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
617
618 \end_inset
619
620 .
621
622 \series bold
623  
624 \series default
625 \emph on
626 Please note: the compiler will probably always be some steps ahead of this
627  documentation
628 \series bold
629 \emph default
630
631 \begin_inset LatexCommand \index{Status of documentation}
632
633 \end_inset
634
635
636 \begin_inset Foot
637 collapsed false
638
639 \layout Standard
640 Obviously this has pros and cons
641
642 \end_inset
643
644 .
645
646 \layout Section
647 Open Source
648
649 \layout Standard
650 All packages used in this compiler system are 
651 \emph on
652 open source
653 \emph default
654  and 
655 \emph on
656 freeware
657 \emph default
658 ; source code for all the sub-packages (pre-processor, assemblers, linkers
659  etc) is distributed with the package.
660  This documentation is maintained using a freeware word processor (LyX).
661 \newline
662 This
663  program is free software; you can redistribute it and/or modify it under
664  the terms of the GNU General Public License
665 \begin_inset LatexCommand \index{GNU General Public License, GPL}
666
667 \end_inset
668
669  as published by the Free Software Foundation; either version 2, or (at
670  your option) any later version.
671  This program is distributed in the hope that it will be useful, but WITHOUT
672  ANY WARRANTY; without even the implied warranty
673 \begin_inset LatexCommand \index{warranty}
674
675 \end_inset
676
677  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
678  See the GNU General Public License for more details.
679  You should have received a copy of the GNU General Public License along
680  with this program; if not, write to the Free Software Foundation, 59 Temple
681  Place - Suite 330, Boston, MA 02111-1307, USA.
682  In other words, you are welcome to use, share and improve this program.
683  You are forbidden to forbid anyone else to use, share and improve what
684  you give them.
685  Help stamp out software-hoarding! 
686
687 \layout Section
688 Typographic conventions
689 \begin_inset LatexCommand \index{Typographic conventions}
690
691 \end_inset
692
693
694
695 \layout Standard
696 Throughout this manual, we will use the following convention.
697  Commands you have to type in are printed in 
698 \family sans
699 \series bold
700 "sans serif"
701 \series default
702 .
703
704 \family default
705  Code samples are printed in 
706 \family typewriter
707 typewriter font.
708
709 \family default
710  Interesting items and new terms are printed in 
711 \emph on
712 italic.
713
714 \layout Section
715 Compatibility
716 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
717
718 \end_inset
719
720  with previous versions
721 \begin_inset LatexCommand \index{Compatibility with previous versions}
722
723 \end_inset
724
725
726
727 \layout Standard
728 This version has numerous bug fixes compared with the previous version.
729  But we also introduced some incompatibilities with older versions.
730  Not just for the fun of it, but to make the compiler more stable, efficient
731  and ANSI compliant
732 \begin_inset LatexCommand \index{ANSI-compliance}
733
734 \end_inset
735
736  (see section 
737 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
738
739 \end_inset
740
741  for ANSI-Compliance).
742  
743 \newline
744
745
746 \layout Itemize
747 short is now equivalent to int (16 bits), it used to be equivalent to char
748  (8 bits) which is not ANSI compliant.
749
750 \layout Itemize
751 the default directory for gcc-builds where include, library and documentation
752  files are stored is now in /usr/local/share.
753
754 \layout Itemize
755 char type parameters to vararg
756 \begin_inset LatexCommand \index{vararg, va\_arg}
757
758 \end_inset
759
760  functions are casted to int unless explicitly casted
761 \begin_inset Marginal
762 collapsed true
763
764 \layout Standard
765
766 \series bold
767 \SpecialChar ~
768 !
769
770 \end_inset
771
772 , e.g.: 
773 \newline
774
775 \family typewriter
776 \SpecialChar ~
777 \SpecialChar ~
778 char a=3;
779 \newline
780 \SpecialChar ~
781 \SpecialChar ~
782 printf ("%d %c
783 \backslash
784 n", a, (char)a);
785 \family default
786
787 \newline
788  will push a as an int and as a char resp.
789
790 \layout Itemize
791 option -
792 \begin_inset ERT
793 status Collapsed
794
795 \layout Standard
796
797
798 \backslash
799 /
800
801 \end_inset
802
803 -regextend has been removed.
804
805 \layout Itemize
806 option -
807 \begin_inset ERT
808 status Collapsed
809
810 \layout Standard
811
812
813 \backslash
814 /
815
816 \end_inset
817
818 -noregparms has been removed.
819
820 \layout Itemize
821 option -
822 \begin_inset ERT
823 status Collapsed
824
825 \layout Standard
826
827
828 \backslash
829 /
830
831 \end_inset
832
833 -stack-after-data has been removed.
834
835 \layout Itemize
836 bit
837 \begin_inset LatexCommand \index{bit}
838
839 \end_inset
840
841  and sbit
842 \begin_inset LatexCommand \index{sbit}
843
844 \end_inset
845
846
847 \begin_inset LatexCommand \index{\_\_sbit}
848
849 \end_inset
850
851  types now consistently behave like the C99 _Bool type with respect to type
852  conversion
853 \begin_inset LatexCommand \index{type conversion}
854
855 \end_inset
856
857
858 \begin_inset LatexCommand \index{type promotion}
859
860 \end_inset
861
862 .
863  The most common incompatibility resulting from this change is related to
864  bit toggling
865 \begin_inset LatexCommand \index{Bit toggling}
866
867 \end_inset
868
869  idioms, e.g.:
870 \newline
871
872 \family typewriter
873 \SpecialChar ~
874 \SpecialChar ~
875 bit b;
876 \newline
877 \SpecialChar ~
878 \SpecialChar ~
879 b = ~
880 \begin_inset LatexCommand \index{\~\/ Operator}
881
882 \end_inset
883
884 b; /* equivalent to b=1 instead of toggling b */
885 \begin_inset Marginal
886 collapsed true
887
888 \layout Standard
889
890 \series bold
891 \SpecialChar ~
892 !
893
894 \end_inset
895
896
897 \newline
898 \SpecialChar ~
899 \SpecialChar ~
900 b = !b; /* toggles b */
901 \newline
902
903 \family default
904 In previous versions, both forms would have toggled the bit.
905
906 \layout Standard
907
908 \emph on
909 <pending: more incompatibilities?>
910
911 \layout Section
912 System Requirements
913
914 \layout Standard
915 What do you need before you start installation of SDCC? A computer, and
916  a desire to compute.
917  The preferred method of installation is to compile SDCC from source using
918  GNU gcc and make.
919  For Windows some pre-compiled binary distributions are available for your
920  convenience.
921  You should have some experience with command line tools and compiler use.
922
923 \layout Section
924 Other Resources
925
926 \layout Standard
927 The SDCC home page at 
928 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
929
930 \end_inset
931
932  is a great place to find distribution sets.
933  You can also find links to the user mailing lists that offer help or discuss
934  SDCC with other SDCC users.
935  Web links to other SDCC related sites can also be found here.
936  This document can be found in the DOC directory of the source package as
937  a text or HTML file.
938  A pdf version of this document is available at 
939 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
940
941 \end_inset
942
943 .
944  Some of the other tools (simulator and assembler) included with SDCC contain
945  their own documentation and can be found in the source distribution.
946  If you want the latest unreleased software, the complete source package
947  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
948 /trunk/sdcc.
949
950 \layout Section
951 Wishes for the future
952
953 \layout Standard
954 There are (and always will be) some things that could be done.
955  Here are some I can think of:
956 \newline
957
958
959 \layout Standard
960
961 \family typewriter
962 char KernelFunction3(char p) at 0x340;
963 \newline
964
965
966 \layout Standard
967
968 \family typewriter
969 better code banking
970 \begin_inset LatexCommand \index{code banking (limited support)}
971
972 \end_inset
973
974  support for mcs51
975 \newline
976
977 \newline
978
979 \family default
980 If you can think of some more, please see the section 
981 \begin_inset LatexCommand \ref{sub:Requesting-Features}
982
983 \end_inset
984
985  about filing feature requests
986 \begin_inset LatexCommand \index{Requesting features}
987
988 \end_inset
989
990
991 \begin_inset LatexCommand \index{Feature request}
992
993 \end_inset
994
995 .
996 \newline
997
998
999 \layout Chapter
1000 Installing SDCC
1001 \begin_inset LatexCommand \index{Installation}
1002
1003 \end_inset
1004
1005
1006
1007 \layout Standard
1008 For most users it is sufficient to skip to either section 
1009 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1010
1011 \end_inset
1012
1013  (Unix) or section 
1014 \begin_inset LatexCommand \ref{sub:Windows-Install}
1015
1016 \end_inset
1017
1018  (Windows).
1019  More detailed instructions follow below.
1020
1021 \layout Section
1022 Configure Options
1023 \begin_inset LatexCommand \index{Options SDCC configuration}
1024
1025 \end_inset
1026
1027
1028
1029 \layout Standard
1030 The install paths, search paths and other options are defined when running
1031  'configure'.
1032  The defaults can be overridden by:
1033
1034 \layout List
1035 \labelwidthstring 00.00.0000
1036 -
1037 \begin_inset ERT
1038 status Collapsed
1039
1040 \layout Standard
1041
1042
1043 \backslash
1044 /
1045
1046 \end_inset
1047
1048 -prefix see table below
1049
1050 \layout List
1051 \labelwidthstring 00.00.0000
1052 -
1053 \begin_inset ERT
1054 status Collapsed
1055
1056 \layout Standard
1057
1058
1059 \backslash
1060 /
1061
1062 \end_inset
1063
1064 -exec_prefix see table below
1065
1066 \layout List
1067 \labelwidthstring 00.00.0000
1068 -
1069 \begin_inset ERT
1070 status Collapsed
1071
1072 \layout Standard
1073
1074
1075 \backslash
1076 /
1077
1078 \end_inset
1079
1080 -bindir see table below
1081
1082 \layout List
1083 \labelwidthstring 00.00.0000
1084 -
1085 \begin_inset ERT
1086 status Collapsed
1087
1088 \layout Standard
1089
1090
1091 \backslash
1092 /
1093
1094 \end_inset
1095
1096 -datadir see table below
1097
1098 \layout List
1099 \labelwidthstring 00.00.0000
1100 -
1101 \begin_inset ERT
1102 status Collapsed
1103
1104 \layout Standard
1105
1106
1107 \backslash
1108 /
1109
1110 \end_inset
1111
1112 -datarootdir see table below
1113 \newline
1114
1115
1116 \layout List
1117 \labelwidthstring 00.00.0000
1118 \SpecialChar ~
1119 \SpecialChar ~
1120 docdir environment variable, see table below
1121
1122 \layout List
1123 \labelwidthstring 00.00.0000
1124 \SpecialChar ~
1125 \SpecialChar ~
1126 include_dir_suffix environment variable, see table below
1127
1128 \layout List
1129 \labelwidthstring 00.00.0000
1130 \SpecialChar ~
1131 \SpecialChar ~
1132 lib_dir_suffix environment variable, see table below
1133
1134 \layout List
1135 \labelwidthstring 00.00.0000
1136 \SpecialChar ~
1137 \SpecialChar ~
1138 sdccconf_h_dir_separator environment variable, either / or 
1139 \backslash
1140
1141 \backslash
1142  makes sense here.
1143  This character will only be used in sdccconf.h; don't forget it's a C-header,
1144  therefore a double-backslash is needed there.
1145 \newline
1146
1147
1148 \layout List
1149 \labelwidthstring 00.00.0000
1150 -
1151 \begin_inset ERT
1152 status Collapsed
1153
1154 \layout Standard
1155
1156
1157 \backslash
1158 /
1159
1160 \end_inset
1161
1162 -disable-mcs51-port Excludes the Intel mcs51 port
1163
1164 \layout List
1165 \labelwidthstring 00.00.0000
1166 -
1167 \begin_inset ERT
1168 status Collapsed
1169
1170 \layout Standard
1171
1172
1173 \backslash
1174 /
1175
1176 \end_inset
1177
1178 -disable-gbz80-port Excludes the Gameboy gbz80 port
1179
1180 \layout List
1181 \labelwidthstring 00.00.0000
1182 -
1183 \begin_inset ERT
1184 status Collapsed
1185
1186 \layout Standard
1187
1188
1189 \backslash
1190 /
1191
1192 \end_inset
1193
1194 -disable-z80-port Excludes the z80 port
1195
1196 \layout List
1197 \labelwidthstring 00.00.0000
1198 -
1199 \begin_inset ERT
1200 status Collapsed
1201
1202 \layout Standard
1203
1204
1205 \backslash
1206 /
1207
1208 \end_inset
1209
1210 -disable-avr-port Excludes the AVR port
1211
1212 \layout List
1213 \labelwidthstring 00.00.0000
1214 -
1215 \begin_inset ERT
1216 status Collapsed
1217
1218 \layout Standard
1219
1220
1221 \backslash
1222 /
1223
1224 \end_inset
1225
1226 -disable-ds390-port Excludes the DS390 port
1227
1228 \layout List
1229 \labelwidthstring 00.00.0000
1230 -
1231 \begin_inset ERT
1232 status Collapsed
1233
1234 \layout Standard
1235
1236
1237 \backslash
1238 /
1239
1240 \end_inset
1241
1242 -disable-hc08-port Excludes the HC08 port
1243
1244 \layout List
1245 \labelwidthstring 00.00.0000
1246 -
1247 \begin_inset ERT
1248 status Collapsed
1249
1250 \layout Standard
1251
1252
1253 \backslash
1254 /
1255
1256 \end_inset
1257
1258 -disable-pic-port Excludes the PIC port
1259
1260 \layout List
1261 \labelwidthstring 00.00.0000
1262 -
1263 \begin_inset ERT
1264 status Collapsed
1265
1266 \layout Standard
1267
1268
1269 \backslash
1270 /
1271
1272 \end_inset
1273
1274 -disable-xa51-port Excludes the XA51 port
1275
1276 \layout List
1277 \labelwidthstring 00.00.0000
1278 -
1279 \begin_inset ERT
1280 status Collapsed
1281
1282 \layout Standard
1283
1284
1285 \backslash
1286 /
1287
1288 \end_inset
1289
1290 -disable-ucsim Disables configuring and building of ucsim
1291
1292 \layout List
1293 \labelwidthstring 00.00.0000
1294 -
1295 \begin_inset ERT
1296 status Collapsed
1297
1298 \layout Standard
1299
1300
1301 \backslash
1302 /
1303
1304 \end_inset
1305
1306 -disable-device-lib Disables automatically building device libraries
1307
1308 \layout List
1309 \labelwidthstring 00.00.0000
1310 -
1311 \begin_inset ERT
1312 status Collapsed
1313
1314 \layout Standard
1315
1316
1317 \backslash
1318 /
1319
1320 \end_inset
1321
1322 -disable-packihx Disables building packihx
1323 \newline
1324
1325
1326 \layout List
1327 \labelwidthstring 00.00.0000
1328 -
1329 \begin_inset ERT
1330 status Collapsed
1331
1332 \layout Standard
1333
1334
1335 \backslash
1336 /
1337
1338 \end_inset
1339
1340 -enable-doc Build pdf, html and txt files from the lyx sources
1341
1342 \layout List
1343 \labelwidthstring 00.00.0000
1344 -
1345 \begin_inset ERT
1346 status Collapsed
1347
1348 \layout Standard
1349
1350
1351 \backslash
1352 /
1353
1354 \end_inset
1355
1356 -enable-libgc Use the Bohem memory allocator.
1357  Lower runtime footprint.
1358
1359 \layout Standard
1360 Furthermore the environment variables CC, CFLAGS, ...
1361  the tools and their arguments can be influenced.
1362  Please see `configure -
1363 \begin_inset ERT
1364 status Collapsed
1365
1366 \layout Standard
1367
1368
1369 \backslash
1370 /
1371
1372 \end_inset
1373
1374 -help` and the man/info pages of `configure` for details.
1375 \newline
1376
1377 \newline
1378 The names of the
1379  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1380 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1381  SDCC_LIB_NAME are defined by `configure` too.
1382  At the moment it's not possible to change the default settings (it was
1383  simply never required).
1384 \newline
1385
1386 \newline
1387 These configure options are compiled into the binaries,
1388  and can only be changed by rerunning 'configure' and recompiling SDCC.
1389  The configure options are written in 
1390 \emph on
1391 italics
1392 \emph default
1393  to distinguish them from run time environment variables (see section search
1394  paths).
1395 \newline
1396
1397 \newline
1398 The settings for 
1399 \begin_inset Quotes sld
1400 \end_inset
1401
1402 Win32 builds
1403 \begin_inset Quotes srd
1404 \end_inset
1405
1406  are used by the SDCC team to build the official Win32 binaries.
1407  The SDCC team uses Mingw32 to build the official Windows binaries, because
1408  it's
1409
1410 \layout Enumerate
1411 open source, 
1412
1413 \layout Enumerate
1414 a gcc compiler and last but not least
1415
1416 \layout Enumerate
1417 the binaries can be built by cross compiling on Sourceforge's compile farm.
1418
1419 \layout Standard
1420 See the examples, how to pass the Win32 settings to 'configure'.
1421  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1422  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1423  for Win32.
1424 \newline
1425
1426 \newline
1427 These defaults are:
1428 \newline
1429
1430
1431 \layout Standard
1432 \align center
1433 \begin_inset Tabular
1434 <lyxtabular version="3" rows="9" columns="3">
1435 <features>
1436 <column alignment="block" valignment="top" leftline="true" width="0in">
1437 <column alignment="block" valignment="top" leftline="true" width="0in">
1438 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1439 <row topline="true" bottomline="true">
1440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1441 \begin_inset Text
1442
1443 \layout Standard
1444 Variable
1445
1446 \end_inset
1447 </cell>
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1449 \begin_inset Text
1450
1451 \layout Standard
1452 default
1453
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 Win32 builds
1461
1462 \end_inset
1463 </cell>
1464 </row>
1465 <row topline="true">
1466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1467 \begin_inset Text
1468
1469 \layout Standard
1470
1471 \emph on
1472 PREFIX
1473
1474 \end_inset
1475 </cell>
1476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1477 \begin_inset Text
1478
1479 \layout Standard
1480 /usr/local
1481
1482 \end_inset
1483 </cell>
1484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1485 \begin_inset Text
1486
1487 \layout Standard
1488
1489 \backslash
1490 sdcc
1491
1492 \end_inset
1493 </cell>
1494 </row>
1495 <row topline="true">
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1497 \begin_inset Text
1498
1499 \layout Standard
1500
1501 \emph on
1502 EXEC_PREFIX
1503
1504 \end_inset
1505 </cell>
1506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1507 \begin_inset Text
1508
1509 \layout Standard
1510
1511 \emph on
1512 $PREFIX
1513
1514 \end_inset
1515 </cell>
1516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1517 \begin_inset Text
1518
1519 \layout Standard
1520
1521 \emph on
1522 $PREFIX
1523
1524 \end_inset
1525 </cell>
1526 </row>
1527 <row topline="true">
1528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1529 \begin_inset Text
1530
1531 \layout Standard
1532
1533 \emph on
1534 BINDIR
1535
1536 \end_inset
1537 </cell>
1538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1539 \begin_inset Text
1540
1541 \layout Standard
1542
1543 \emph on
1544 $EXEC_PREFIX
1545 \emph default
1546 /bin
1547
1548 \end_inset
1549 </cell>
1550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1551 \begin_inset Text
1552
1553 \layout Standard
1554
1555 \emph on
1556 $EXEC_PREFIX
1557 \emph default
1558
1559 \backslash
1560 bin
1561
1562 \end_inset
1563 </cell>
1564 </row>
1565 <row topline="true">
1566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1567 \begin_inset Text
1568
1569 \layout Standard
1570
1571 \emph on
1572 DATADIR
1573
1574 \end_inset
1575 </cell>
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1577 \begin_inset Text
1578
1579 \layout Standard
1580
1581 \emph on
1582 $DATAROOTDIR
1583
1584 \end_inset
1585 </cell>
1586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1587 \begin_inset Text
1588
1589 \layout Standard
1590
1591 \emph on
1592 $DATAROOTDIR
1593
1594 \end_inset
1595 </cell>
1596 </row>
1597 <row topline="true">
1598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1599 \begin_inset Text
1600
1601 \layout Standard
1602
1603 \emph on
1604 DATAROOTDIR
1605
1606 \end_inset
1607 </cell>
1608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1609 \begin_inset Text
1610
1611 \layout Standard
1612
1613 \emph on
1614 $PREFIX
1615 \emph default
1616 /share
1617
1618 \end_inset
1619 </cell>
1620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1621 \begin_inset Text
1622
1623 \layout Standard
1624
1625 \emph on
1626 $PREFIX
1627
1628 \end_inset
1629 </cell>
1630 </row>
1631 <row topline="true">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1633 \begin_inset Text
1634
1635 \layout Standard
1636
1637 \emph on
1638 DOCDIR
1639
1640 \end_inset
1641 </cell>
1642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1643 \begin_inset Text
1644
1645 \layout Standard
1646
1647 \emph on
1648 $DATAROOTDIR
1649 \emph default
1650 /sdcc/doc
1651
1652 \end_inset
1653 </cell>
1654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1655 \begin_inset Text
1656
1657 \layout Standard
1658
1659 \emph on
1660 $DATAROOTDIR
1661 \emph default
1662
1663 \backslash
1664 doc
1665
1666 \end_inset
1667 </cell>
1668 </row>
1669 <row topline="true">
1670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1671 \begin_inset Text
1672
1673 \layout Standard
1674
1675 \emph on
1676 INCLUDE_DIR_SUFFIX
1677
1678 \end_inset
1679 </cell>
1680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1681 \begin_inset Text
1682
1683 \layout Standard
1684 sdcc/include
1685
1686 \end_inset
1687 </cell>
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1689 \begin_inset Text
1690
1691 \layout Standard
1692 include
1693
1694 \end_inset
1695 </cell>
1696 </row>
1697 <row topline="true" bottomline="true">
1698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1699 \begin_inset Text
1700
1701 \layout Standard
1702
1703 \emph on
1704 LIB_DIR_SUFFIX
1705
1706 \end_inset
1707 </cell>
1708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1709 \begin_inset Text
1710
1711 \layout Standard
1712 sdcc/lib
1713
1714 \end_inset
1715 </cell>
1716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1717 \begin_inset Text
1718
1719 \layout Standard
1720 lib
1721
1722 \end_inset
1723 </cell>
1724 </row>
1725 </lyxtabular>
1726
1727 \end_inset
1728
1729
1730 \newline
1731
1732
1733 \layout Standard
1734 \noindent
1735 'configure' also computes relative paths.
1736  This is needed for full relocatability of a binary package and to complete
1737  search paths (see section search paths below):
1738 \newline
1739  
1740
1741 \layout Standard
1742 \align center
1743 \begin_inset Tabular
1744 <lyxtabular version="3" rows="4" columns="3">
1745 <features>
1746 <column alignment="block" valignment="top" leftline="true" width="0in">
1747 <column alignment="block" valignment="top" leftline="true" width="0in">
1748 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1749 <row topline="true" bottomline="true">
1750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1751 \begin_inset Text
1752
1753 \layout Standard
1754 Variable (computed)
1755
1756 \end_inset
1757 </cell>
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1759 \begin_inset Text
1760
1761 \layout Standard
1762 default
1763
1764 \end_inset
1765 </cell>
1766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1767 \begin_inset Text
1768
1769 \layout Standard
1770 Win32 builds
1771
1772 \end_inset
1773 </cell>
1774 </row>
1775 <row topline="true" bottomline="true">
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1777 \begin_inset Text
1778
1779 \layout Standard
1780
1781 \emph on
1782 BIN2DATA_DIR
1783
1784 \end_inset
1785 </cell>
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1787 \begin_inset Text
1788
1789 \layout Standard
1790 ../share
1791
1792 \end_inset
1793 </cell>
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1795 \begin_inset Text
1796
1797 \layout Standard
1798 ..
1799
1800 \end_inset
1801 </cell>
1802 </row>
1803 <row bottomline="true">
1804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1805 \begin_inset Text
1806
1807 \layout Standard
1808
1809 \emph on
1810 PREFIX2BIN_DIR
1811
1812 \end_inset
1813 </cell>
1814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_inset Text
1816
1817 \layout Standard
1818 bin
1819
1820 \end_inset
1821 </cell>
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1823 \begin_inset Text
1824
1825 \layout Standard
1826 bin
1827
1828 \end_inset
1829 </cell>
1830 </row>
1831 <row bottomline="true">
1832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1833 \begin_inset Text
1834
1835 \layout Standard
1836
1837 \emph on
1838 PREFIX2DATA_DIR
1839
1840 \end_inset
1841 </cell>
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1843 \begin_inset Text
1844
1845 \layout Standard
1846 share/sdcc
1847
1848 \end_inset
1849 </cell>
1850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1851 \begin_inset Text
1852
1853 \layout Standard
1854
1855
1856 \end_inset
1857 </cell>
1858 </row>
1859 </lyxtabular>
1860
1861 \end_inset
1862
1863
1864 \newline
1865
1866
1867 \layout Standard
1868 \noindent
1869 Examples:
1870
1871 \layout LyX-Code
1872 ./configure
1873 \newline
1874 ./configure -
1875 \begin_inset ERT
1876 status Collapsed
1877
1878 \layout Standard
1879
1880
1881 \backslash
1882 /
1883
1884 \end_inset
1885
1886 -prefix=
1887 \begin_inset Quotes srd
1888 \end_inset
1889
1890 /usr/bin
1891 \begin_inset Quotes srd
1892 \end_inset
1893
1894  -
1895 \begin_inset ERT
1896 status Collapsed
1897
1898 \layout Standard
1899
1900
1901 \backslash
1902 /
1903
1904 \end_inset
1905
1906 -datarootdir=
1907 \begin_inset Quotes srd
1908 \end_inset
1909
1910 /usr/share
1911 \begin_inset Quotes srd
1912 \end_inset
1913
1914
1915 \newline
1916 ./configure -
1917 \begin_inset ERT
1918 status Collapsed
1919
1920 \layout Standard
1921
1922
1923 \backslash
1924 /
1925
1926 \end_inset
1927
1928 -disable-avr-port -
1929 \begin_inset ERT
1930 status Collapsed
1931
1932 \layout Standard
1933
1934
1935 \backslash
1936 /
1937
1938 \end_inset
1939
1940 -disable-xa51-port
1941
1942 \layout Standard
1943 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1944 32'):
1945
1946 \layout LyX-Code
1947 ./configure 
1948 \backslash
1949
1950 \newline
1951 CC=
1952 \begin_inset Quotes srd
1953 \end_inset
1954
1955 i586-mingw32msvc-gcc
1956 \begin_inset Quotes srd
1957 \end_inset
1958
1959  CXX=
1960 \begin_inset Quotes srd
1961 \end_inset
1962
1963 i586-mingw32msvc-g++
1964 \begin_inset Quotes srd
1965 \end_inset
1966
1967  
1968 \backslash
1969  
1970 \newline
1971 RANLIB=
1972 \begin_inset Quotes srd
1973 \end_inset
1974
1975 i586-mingw32msvc-ranlib
1976 \begin_inset Quotes srd
1977 \end_inset
1978
1979  
1980 \backslash
1981
1982 \newline
1983 STRIP=
1984 \begin_inset Quotes srd
1985 \end_inset
1986
1987 i586-mingw32msvc-strip
1988 \begin_inset Quotes srd
1989 \end_inset
1990
1991  
1992 \backslash
1993
1994 \newline
1995 -
1996 \begin_inset ERT
1997 status Collapsed
1998
1999 \layout Standard
2000
2001
2002 \backslash
2003 /
2004
2005 \end_inset
2006
2007 -prefix=
2008 \begin_inset Quotes srd
2009 \end_inset
2010
2011 /sdcc
2012 \begin_inset Quotes srd
2013 \end_inset
2014
2015  
2016 \backslash
2017
2018 \newline
2019 -
2020 \begin_inset ERT
2021 status Collapsed
2022
2023 \layout Standard
2024
2025
2026 \backslash
2027 /
2028
2029 \end_inset
2030
2031 -datarootdir=
2032 \begin_inset Quotes srd
2033 \end_inset
2034
2035 /sdcc
2036 \begin_inset Quotes srd
2037 \end_inset
2038
2039  
2040 \backslash
2041
2042 \newline
2043 docdir=
2044 \begin_inset Quotes srd
2045 \end_inset
2046
2047
2048 \backslash
2049 ${datarootdir}/doc
2050 \begin_inset Quotes srd
2051 \end_inset
2052
2053  
2054 \backslash
2055
2056 \newline
2057 include_dir_suffix=
2058 \begin_inset Quotes srd
2059 \end_inset
2060
2061 include
2062 \begin_inset Quotes srd
2063 \end_inset
2064
2065  
2066 \backslash
2067
2068 \newline
2069 lib_dir_suffix=
2070 \begin_inset Quotes srd
2071 \end_inset
2072
2073 lib
2074 \begin_inset Quotes srd
2075 \end_inset
2076
2077  
2078 \backslash
2079
2080 \newline
2081 sdccconf_h_dir_separator=
2082 \begin_inset Quotes srd
2083 \end_inset
2084
2085
2086 \backslash
2087
2088 \backslash
2089
2090 \backslash
2091
2092 \backslash
2093
2094 \begin_inset Quotes srd
2095 \end_inset
2096
2097  
2098 \backslash
2099
2100 \newline
2101 -
2102 \begin_inset ERT
2103 status Collapsed
2104
2105 \layout Standard
2106
2107
2108 \backslash
2109 /
2110
2111 \end_inset
2112
2113 -disable-device-lib
2114 \backslash
2115
2116 \newline
2117 -
2118 \begin_inset ERT
2119 status Collapsed
2120
2121 \layout Standard
2122
2123
2124 \backslash
2125 /
2126
2127 \end_inset
2128
2129 -host=i586-mingw32msvc
2130 \backslash
2131
2132 \newline
2133 -
2134 \begin_inset ERT
2135 status Collapsed
2136
2137 \layout Standard
2138
2139
2140 \backslash
2141 /
2142
2143 \end_inset
2144
2145 -build=unknown-unknown-linux-gnu
2146
2147 \layout Standard
2148 To 
2149 \begin_inset Quotes sld
2150 \end_inset
2151
2152 cross
2153 \begin_inset Quotes srd
2154 \end_inset
2155
2156 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2157 ):
2158
2159 \layout LyX-Code
2160 ./configure -C 
2161 \backslash
2162
2163 \newline
2164 -
2165 \begin_inset ERT
2166 status Collapsed
2167
2168 \layout Standard
2169
2170
2171 \backslash
2172 /
2173
2174 \end_inset
2175
2176 -prefix=
2177 \begin_inset Quotes srd
2178 \end_inset
2179
2180 /sdcc
2181 \begin_inset Quotes srd
2182 \end_inset
2183
2184  
2185 \backslash
2186
2187 \newline
2188 -
2189 \begin_inset ERT
2190 status Collapsed
2191
2192 \layout Standard
2193
2194
2195 \backslash
2196 /
2197
2198 \end_inset
2199
2200 -datarootdir=
2201 \begin_inset Quotes srd
2202 \end_inset
2203
2204 /sdcc
2205 \begin_inset Quotes srd
2206 \end_inset
2207
2208  
2209 \backslash
2210
2211 \newline
2212 docdir=
2213 \begin_inset Quotes srd
2214 \end_inset
2215
2216
2217 \backslash
2218 ${datarootdir}/doc
2219 \begin_inset Quotes srd
2220 \end_inset
2221
2222  
2223 \backslash
2224  
2225 \newline
2226 include_dir_suffix=
2227 \begin_inset Quotes srd
2228 \end_inset
2229
2230 include
2231 \begin_inset Quotes srd
2232 \end_inset
2233
2234  
2235 \backslash
2236
2237 \newline
2238 lib_dir_suffix=
2239 \begin_inset Quotes srd
2240 \end_inset
2241
2242 lib
2243 \begin_inset Quotes srd
2244 \end_inset
2245
2246  
2247 \backslash
2248
2249 \newline
2250 sdccconf_h_dir_separator=
2251 \begin_inset Quotes srd
2252 \end_inset
2253
2254
2255 \backslash
2256
2257 \backslash
2258
2259 \backslash
2260
2261 \backslash
2262
2263 \begin_inset Quotes srd
2264 \end_inset
2265
2266  
2267 \backslash
2268
2269 \newline
2270 CC=
2271 \begin_inset Quotes srd
2272 \end_inset
2273
2274 gcc -mno-cygwin
2275 \begin_inset Quotes srd
2276 \end_inset
2277
2278  
2279 \backslash
2280
2281 \newline
2282 CXX=
2283 \begin_inset Quotes srd
2284 \end_inset
2285
2286 g++ -mno-cygwin
2287 \begin_inset Quotes srd
2288 \end_inset
2289
2290  
2291
2292 \layout Standard
2293 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2294  The option '-
2295 \begin_inset ERT
2296 status Collapsed
2297
2298 \layout Standard
2299
2300
2301 \backslash
2302 /
2303
2304 \end_inset
2305
2306 -C' turns on caching, which gives a little bit extra speed.
2307  However if options are changed, it can be necessary to delete the config.cache
2308  file.
2309
2310 \layout Section
2311 Install paths
2312 \added_space_bottom medskip 
2313 \begin_inset LatexCommand \label{sub:Install-paths}
2314
2315 \end_inset
2316
2317
2318 \begin_inset LatexCommand \index{Install paths}
2319
2320 \end_inset
2321
2322
2323
2324
2325 \layout Standard
2326 \align center
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="5" columns="4">
2329 <features>
2330 <column alignment="left" valignment="top" leftline="true" width="0">
2331 <column alignment="left" valignment="top" leftline="true" width="0">
2332 <column alignment="left" valignment="top" leftline="true" width="0">
2333 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2334 <row topline="true" bottomline="true">
2335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2336 \begin_inset Text
2337
2338 \layout Standard
2339
2340 \series bold
2341 Description
2342
2343 \end_inset
2344 </cell>
2345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2346 \begin_inset Text
2347
2348 \layout Standard
2349
2350 \series bold
2351 Path
2352
2353 \end_inset
2354 </cell>
2355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2356 \begin_inset Text
2357
2358 \layout Standard
2359
2360 \series bold
2361 Default
2362
2363 \end_inset
2364 </cell>
2365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2366 \begin_inset Text
2367
2368 \layout Standard
2369
2370 \series bold
2371 Win32 builds
2372
2373 \end_inset
2374 </cell>
2375 </row>
2376 <row topline="true">
2377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2378 \begin_inset Text
2379
2380 \layout Standard
2381 Binary files*
2382
2383 \end_inset
2384 </cell>
2385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2386 \begin_inset Text
2387
2388 \layout Standard
2389
2390 \emph on
2391 $EXEC_PREFIX
2392
2393 \end_inset
2394 </cell>
2395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2396 \begin_inset Text
2397
2398 \layout Standard
2399 /usr/local/bin
2400
2401 \end_inset
2402 </cell>
2403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2404 \begin_inset Text
2405
2406 \layout Standard
2407
2408 \backslash
2409 sdcc
2410 \backslash
2411 bin
2412
2413 \end_inset
2414 </cell>
2415 </row>
2416 <row topline="true">
2417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2418 \begin_inset Text
2419
2420 \layout Standard
2421 Include files
2422
2423 \end_inset
2424 </cell>
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2426 \begin_inset Text
2427
2428 \layout Standard
2429
2430 \emph on
2431 $DATADIR/ $INCLUDE_DIR_SUFFIX
2432
2433 \end_inset
2434 </cell>
2435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2436 \begin_inset Text
2437
2438 \layout Standard
2439 /usr/local/share/sdcc/include
2440
2441 \end_inset
2442 </cell>
2443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2444 \begin_inset Text
2445
2446 \layout Standard
2447
2448 \backslash
2449 sdcc
2450 \backslash
2451 include
2452
2453 \end_inset
2454 </cell>
2455 </row>
2456 <row topline="true">
2457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2458 \begin_inset Text
2459
2460 \layout Standard
2461 Library file**
2462
2463 \end_inset
2464 </cell>
2465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2466 \begin_inset Text
2467
2468 \layout Standard
2469
2470 \emph on
2471 $DATADIR/$LIB_DIR_SUFFIX
2472
2473 \end_inset
2474 </cell>
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2476 \begin_inset Text
2477
2478 \layout Standard
2479 /usr/local/share/sdcc/lib
2480
2481 \end_inset
2482 </cell>
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2484 \begin_inset Text
2485
2486 \layout Standard
2487
2488 \backslash
2489 sdcc
2490 \backslash
2491 lib
2492
2493 \end_inset
2494 </cell>
2495 </row>
2496 <row topline="true" bottomline="true">
2497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2498 \begin_inset Text
2499
2500 \layout Standard
2501 Documentation
2502
2503 \end_inset
2504 </cell>
2505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2506 \begin_inset Text
2507
2508 \layout Standard
2509
2510 \emph on
2511 $DOCDIR
2512
2513 \end_inset
2514 </cell>
2515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2516 \begin_inset Text
2517
2518 \layout Standard
2519 /usr/local/share/sdcc/doc
2520
2521 \end_inset
2522 </cell>
2523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2524 \begin_inset Text
2525
2526 \layout Standard
2527
2528 \backslash
2529 sdcc
2530 \backslash
2531 doc
2532
2533 \end_inset
2534 </cell>
2535 </row>
2536 </lyxtabular>
2537
2538 \end_inset
2539
2540
2541
2542 \layout Verse
2543
2544 \size footnotesize
2545 *compiler, preprocessor, assembler, and linker
2546 \newline
2547 **the 
2548 \shape italic
2549 model
2550 \shape default
2551  is auto-appended by the compiler, e.g.
2552  small, large, z80, ds390 etc
2553
2554 \layout Standard
2555 \noindent
2556 The install paths can still be changed during `make install` with e.g.:
2557
2558 \layout LyX-Code
2559 make install prefix=$(HOME)/local/sdcc
2560
2561 \layout Standard
2562 Of course this doesn't change the search paths compiled into the binaries.
2563 \newline
2564
2565 \newline
2566 Moreove
2567 r the install path can be changed by defining DESTDIR
2568 \begin_inset LatexCommand \index{DESTDIR}
2569
2570 \end_inset
2571
2572 :
2573
2574 \layout LyX-Code
2575 make install DESTDIR=$(HOME)/sdcc.rpm/
2576
2577 \layout Standard
2578 Please note that DESTDIR must have a trailing slash!
2579
2580 \layout Section
2581 Search Paths
2582 \begin_inset LatexCommand \label{sub:Search-Paths}
2583
2584 \end_inset
2585
2586
2587 \begin_inset LatexCommand \index{Search path}
2588
2589 \end_inset
2590
2591
2592
2593 \layout Standard
2594 Some search paths or parts of them are determined by configure variables
2595  (in 
2596 \emph on
2597 italics
2598 \emph default
2599 , see section above).
2600  Further search paths are determined by environment variables during runtime.
2601  
2602 \newline
2603 The paths searched when running the compiler are as follows (the first
2604  catch wins):
2605 \newline
2606
2607 \newline
2608 1.
2609  Binary files (preprocessor, assembler and linker)
2610 \newline
2611
2612
2613 \layout Standard
2614 \align center
2615 \begin_inset Tabular
2616 <lyxtabular version="3" rows="4" columns="3">
2617 <features>
2618 <column alignment="block" valignment="top" leftline="true" width="0in">
2619 <column alignment="block" valignment="top" leftline="true" width="0in">
2620 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2621 <row topline="true" bottomline="true">
2622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2623 \begin_inset Text
2624
2625 \layout Standard
2626 Search path
2627
2628 \end_inset
2629 </cell>
2630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2631 \begin_inset Text
2632
2633 \layout Standard
2634 default
2635
2636 \end_inset
2637 </cell>
2638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2639 \begin_inset Text
2640
2641 \layout Standard
2642 Win32 builds
2643
2644 \end_inset
2645 </cell>
2646 </row>
2647 <row topline="true">
2648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2649 \begin_inset Text
2650
2651 \layout Standard
2652 $SDCC_HOME/
2653 \emph on
2654 $PPREFIX2BIN_DIR
2655
2656 \end_inset
2657 </cell>
2658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2659 \begin_inset Text
2660
2661 \layout Standard
2662 $SDCC_HOME/bin
2663
2664 \end_inset
2665 </cell>
2666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2667 \begin_inset Text
2668
2669 \layout Standard
2670 $SDCC_HOME
2671 \backslash
2672 bin
2673
2674 \end_inset
2675 </cell>
2676 </row>
2677 <row topline="true">
2678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2679 \begin_inset Text
2680
2681 \layout Standard
2682 Path of argv[0] (if available)
2683
2684 \end_inset
2685 </cell>
2686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2687 \begin_inset Text
2688
2689 \layout Standard
2690 Path of argv[0]
2691
2692 \end_inset
2693 </cell>
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2695 \begin_inset Text
2696
2697 \layout Standard
2698 Path of argv[0]
2699
2700 \end_inset
2701 </cell>
2702 </row>
2703 <row topline="true" bottomline="true">
2704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2705 \begin_inset Text
2706
2707 \layout Standard
2708 $PATH
2709
2710 \end_inset
2711 </cell>
2712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2713 \begin_inset Text
2714
2715 \layout Standard
2716 $PATH
2717
2718 \end_inset
2719 </cell>
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2721 \begin_inset Text
2722
2723 \layout Standard
2724 $PATH
2725
2726 \end_inset
2727 </cell>
2728 </row>
2729 </lyxtabular>
2730
2731 \end_inset
2732
2733  
2734 \newline
2735
2736
2737 \layout Standard
2738 \noindent
2739 2.
2740  Include files
2741 \newline
2742
2743
2744 \layout Standard
2745 \align center
2746 \begin_inset Tabular
2747 <lyxtabular version="3" rows="6" columns="3">
2748 <features>
2749 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2750 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2751 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2752 <row topline="true" bottomline="true">
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2754 \begin_inset Text
2755
2756 \layout Standard
2757 Search path
2758
2759 \end_inset
2760 </cell>
2761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2762 \begin_inset Text
2763
2764 \layout Standard
2765 default
2766
2767 \end_inset
2768 </cell>
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2770 \begin_inset Text
2771
2772 \layout Standard
2773 Win32 builds
2774
2775 \end_inset
2776 </cell>
2777 </row>
2778 <row topline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2780 \begin_inset Text
2781
2782 \layout Standard
2783 -
2784 \begin_inset ERT
2785 status Collapsed
2786
2787 \layout Standard
2788
2789
2790 \backslash
2791 /
2792
2793 \end_inset
2794
2795 -I dir
2796
2797 \end_inset
2798 </cell>
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2800 \begin_inset Text
2801
2802 \layout Standard
2803 -
2804 \begin_inset ERT
2805 status Collapsed
2806
2807 \layout Standard
2808
2809
2810 \backslash
2811 /
2812
2813 \end_inset
2814
2815 -I dir
2816
2817 \end_inset
2818 </cell>
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2820 \begin_inset Text
2821
2822 \layout Standard
2823 -
2824 \begin_inset ERT
2825 status Collapsed
2826
2827 \layout Standard
2828
2829
2830 \backslash
2831 /
2832
2833 \end_inset
2834
2835 -I dir
2836
2837 \end_inset
2838 </cell>
2839 </row>
2840 <row topline="true">
2841 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2842 \begin_inset Text
2843
2844 \layout Standard
2845 $SDCC_INCLUDE
2846
2847 \end_inset
2848 </cell>
2849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2850 \begin_inset Text
2851
2852 \layout Standard
2853 $SDCC_INCLUDE
2854
2855 \end_inset
2856 </cell>
2857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2858 \begin_inset Text
2859
2860 \layout Standard
2861 $SDCC_INCLUDE
2862
2863 \end_inset
2864 </cell>
2865 </row>
2866 <row topline="true">
2867 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2868 \begin_inset Text
2869
2870 \layout Standard
2871 $SDCC_HOME/
2872 \newline
2873
2874 \emph on
2875 $PREFIX2DATA_DIR/
2876 \newline
2877 $INCLUDE_DIR_SUFFIX
2878
2879 \end_inset
2880 </cell>
2881 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2882 \begin_inset Text
2883
2884 \layout Standard
2885 $SDCC_ HOME/
2886 \newline
2887 share/sdcc/
2888 \newline
2889 include
2890
2891 \end_inset
2892 </cell>
2893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2894 \begin_inset Text
2895
2896 \layout Standard
2897 $SDCC_HOME
2898 \backslash
2899 include
2900
2901 \end_inset
2902 </cell>
2903 </row>
2904 <row topline="true">
2905 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2906 \begin_inset Text
2907
2908 \layout Standard
2909 path(argv[0])/
2910 \newline
2911
2912 \emph on
2913 $BIN2DATADIR/
2914 \emph default
2915
2916 \newline
2917
2918 \emph on
2919 $INCLUDE_DIR_SUFFIX
2920
2921 \end_inset
2922 </cell>
2923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2924 \begin_inset Text
2925
2926 \layout Standard
2927 path(argv[0])/
2928 \newline
2929 ../sdcc/include
2930 \newline
2931 \SpecialChar ~
2932 \SpecialChar ~
2933 \SpecialChar ~
2934 \SpecialChar ~
2935 \SpecialChar ~
2936 \SpecialChar ~
2937 \SpecialChar ~
2938 \SpecialChar ~
2939 \SpecialChar ~
2940 \SpecialChar ~
2941 \SpecialChar ~
2942 \SpecialChar ~
2943 \SpecialChar ~
2944 \SpecialChar ~
2945 \SpecialChar ~
2946 \SpecialChar ~
2947 \SpecialChar ~
2948 \SpecialChar ~
2949 \SpecialChar ~
2950 \SpecialChar ~
2951 \SpecialChar ~
2952 \SpecialChar ~
2953 \SpecialChar ~
2954 \SpecialChar ~
2955 \SpecialChar ~
2956 \SpecialChar ~
2957 \SpecialChar ~
2958 \SpecialChar ~
2959 \SpecialChar ~
2960 \SpecialChar ~
2961 \SpecialChar ~
2962 \SpecialChar ~
2963 \SpecialChar ~
2964 \SpecialChar ~
2965 \SpecialChar ~
2966 \SpecialChar ~
2967 \SpecialChar ~
2968 \SpecialChar ~
2969
2970
2971 \end_inset
2972 </cell>
2973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2974 \begin_inset Text
2975
2976 \layout Standard
2977 path(argv[0])
2978 \backslash
2979 ..
2980 \backslash
2981 include
2982
2983 \end_inset
2984 </cell>
2985 </row>
2986 <row topline="true" bottomline="true">
2987 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2988 \begin_inset Text
2989
2990 \layout Standard
2991
2992 \emph on
2993 $DATADIR/
2994 \emph default
2995
2996 \newline
2997
2998 \emph on
2999 $INCLUDE_DIR_SUFFIX
3000
3001 \end_inset
3002 </cell>
3003 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3004 \begin_inset Text
3005
3006 \layout Standard
3007 /usr/local/share/sdcc/
3008 \newline
3009 include
3010
3011 \end_inset
3012 </cell>
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3014 \begin_inset Text
3015
3016 \layout Standard
3017 (not on Win32)
3018
3019 \end_inset
3020 </cell>
3021 </row>
3022 </lyxtabular>
3023
3024 \end_inset
3025
3026  
3027 \newline
3028
3029
3030 \layout Standard
3031 \noindent
3032 The option -
3033 \begin_inset ERT
3034 status Collapsed
3035
3036 \layout Standard
3037
3038
3039 \backslash
3040 /
3041
3042 \end_inset
3043
3044 -nostdinc disables the last two search paths.
3045 \newline
3046
3047 \newline
3048 3.
3049  Library files 
3050 \newline
3051
3052
3053 \layout Standard
3054 With the exception of 
3055 \begin_inset Quotes sld
3056 \end_inset
3057
3058 -
3059 \begin_inset ERT
3060 status Collapsed
3061
3062 \layout Standard
3063
3064
3065 \backslash
3066 /
3067
3068 \end_inset
3069
3070 -L dir
3071 \begin_inset Quotes srd
3072 \end_inset
3073
3074  the 
3075 \shape italic
3076 model
3077 \shape default
3078  is auto-appended by the compiler (e.g.
3079  small, large, z80, ds390 etc.).
3080  
3081 \newline
3082
3083
3084 \layout Standard
3085 \align center
3086 \begin_inset Tabular
3087 <lyxtabular version="3" rows="6" columns="3">
3088 <features>
3089 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3090 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3091 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3092 <row topline="true" bottomline="true">
3093 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_inset Text
3095
3096 \layout Standard
3097 Search path
3098
3099 \end_inset
3100 </cell>
3101 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3102 \begin_inset Text
3103
3104 \layout Standard
3105 default
3106
3107 \end_inset
3108 </cell>
3109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3110 \begin_inset Text
3111
3112 \layout Standard
3113 Win32 builds
3114
3115 \end_inset
3116 </cell>
3117 </row>
3118 <row topline="true">
3119 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3120 \begin_inset Text
3121
3122 \layout Standard
3123 -
3124 \begin_inset ERT
3125 status Collapsed
3126
3127 \layout Standard
3128
3129
3130 \backslash
3131 /
3132
3133 \end_inset
3134
3135 -L dir
3136
3137 \end_inset
3138 </cell>
3139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_inset Text
3141
3142 \layout Standard
3143 -
3144 \begin_inset ERT
3145 status Collapsed
3146
3147 \layout Standard
3148
3149
3150 \backslash
3151 /
3152
3153 \end_inset
3154
3155 -L dir
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 \begin_inset ERT
3165 status Collapsed
3166
3167 \layout Standard
3168
3169
3170 \backslash
3171 /
3172
3173 \end_inset
3174
3175 -L dir
3176
3177 \end_inset
3178 </cell>
3179 </row>
3180 <row topline="true">
3181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3182 \begin_inset Text
3183
3184 \layout Standard
3185 $SDCC_LIB/
3186 \newline
3187
3188 \emph on
3189 <model>
3190
3191 \end_inset
3192 </cell>
3193 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3194 \begin_inset Text
3195
3196 \layout Standard
3197 $SDCC_LIB/
3198 \newline
3199
3200 \emph on
3201 <model>
3202
3203 \end_inset
3204 </cell>
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3206 \begin_inset Text
3207
3208 \layout Standard
3209 $SDCC_LIB
3210 \backslash
3211
3212 \newline
3213
3214 \emph on
3215 <model>
3216
3217 \end_inset
3218 </cell>
3219 </row>
3220 <row topline="true">
3221 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3222 \begin_inset Text
3223
3224 \layout Standard
3225 $SDCC_HOME/
3226 \newline
3227
3228 \emph on
3229 $PREFIX2DATA_DIR/
3230 \newline
3231 $LIB_DIR_SUFFIX/<model>
3232
3233 \end_inset
3234 </cell>
3235 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3236 \begin_inset Text
3237
3238 \layout Standard
3239 $SDCC_HOME/
3240 \newline
3241 share/sdcc/
3242 \newline
3243 lib/
3244 \emph on
3245 <model>
3246
3247 \end_inset
3248 </cell>
3249 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3250 \begin_inset Text
3251
3252 \layout Standard
3253 $SDCC_HOME
3254 \backslash
3255 lib
3256 \backslash
3257
3258 \emph on
3259
3260 \newline
3261 <model>
3262
3263 \end_inset
3264 </cell>
3265 </row>
3266 <row topline="true">
3267 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3268 \begin_inset Text
3269
3270 \layout Standard
3271 path(argv[0])/
3272 \newline
3273
3274 \emph on
3275 $BIN2DATADIR/
3276 \emph default
3277
3278 \newline
3279
3280 \emph on
3281 $LIB_DIR_SUFFIX/<model>
3282
3283 \end_inset
3284 </cell>
3285 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3286 \begin_inset Text
3287
3288 \layout Standard
3289 path(argv[0])/
3290 \newline
3291 ../sdcc/lib/
3292 \emph on
3293 <model>
3294 \newline
3295 \SpecialChar ~
3296 \SpecialChar ~
3297 \SpecialChar ~
3298 \SpecialChar ~
3299 \SpecialChar ~
3300 \SpecialChar ~
3301 \SpecialChar ~
3302 \SpecialChar ~
3303 \SpecialChar ~
3304 \SpecialChar ~
3305 \SpecialChar ~
3306 \SpecialChar ~
3307 \SpecialChar ~
3308 \SpecialChar ~
3309 \SpecialChar ~
3310 \SpecialChar ~
3311 \SpecialChar ~
3312 \SpecialChar ~
3313 \SpecialChar ~
3314 \SpecialChar ~
3315 \SpecialChar ~
3316 \SpecialChar ~
3317 \SpecialChar ~
3318 \SpecialChar ~
3319 \SpecialChar ~
3320 \SpecialChar ~
3321 \SpecialChar ~
3322 \SpecialChar ~
3323 \SpecialChar ~
3324 \SpecialChar ~
3325 \SpecialChar ~
3326 \SpecialChar ~
3327 \SpecialChar ~
3328 \SpecialChar ~
3329 \SpecialChar ~
3330 \SpecialChar ~
3331 \SpecialChar ~
3332 \SpecialChar ~
3333 \SpecialChar ~
3334
3335
3336 \end_inset
3337 </cell>
3338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3339 \begin_inset Text
3340
3341 \layout Standard
3342 path(argv[0])
3343 \backslash
3344
3345 \newline
3346 ..
3347 \backslash
3348 lib
3349 \backslash
3350
3351 \emph on
3352 <model>
3353 \newline
3354 \SpecialChar ~
3355 \SpecialChar ~
3356 \SpecialChar ~
3357 \SpecialChar ~
3358 \SpecialChar ~
3359 \SpecialChar ~
3360 \SpecialChar ~
3361 \SpecialChar ~
3362 \SpecialChar ~
3363 \SpecialChar ~
3364 \SpecialChar ~
3365 \SpecialChar ~
3366 \SpecialChar ~
3367 \SpecialChar ~
3368 \SpecialChar ~
3369 \SpecialChar ~
3370 \SpecialChar ~
3371 \SpecialChar ~
3372 \SpecialChar ~
3373 \SpecialChar ~
3374 \SpecialChar ~
3375 \SpecialChar ~
3376 \SpecialChar ~
3377 \SpecialChar ~
3378 \SpecialChar ~
3379 \SpecialChar ~
3380 \SpecialChar ~
3381 \SpecialChar ~
3382 \SpecialChar ~
3383 \SpecialChar ~
3384 \SpecialChar ~
3385 \SpecialChar ~
3386 \SpecialChar ~
3387 \SpecialChar ~
3388 \SpecialChar ~
3389
3390
3391 \end_inset
3392 </cell>
3393 </row>
3394 <row topline="true" bottomline="true">
3395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3396 \begin_inset Text
3397
3398 \layout Standard
3399
3400 \emph on
3401 $DATADIR/
3402 \newline
3403 $LIB_DIR_SUFFIX/<model>
3404
3405 \end_inset
3406 </cell>
3407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3408 \begin_inset Text
3409
3410 \layout Standard
3411 /usr/local/share/sdcc/
3412 \newline
3413 lib/
3414 \emph on
3415 <model>
3416
3417 \end_inset
3418 </cell>
3419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3420 \begin_inset Text
3421
3422 \layout Standard
3423 (not on Win32)
3424
3425 \end_inset
3426 </cell>
3427 </row>
3428 </lyxtabular>
3429
3430 \end_inset
3431
3432
3433 \newline
3434
3435
3436 \layout Standard
3437 \begin_inset Note
3438 collapsed true
3439
3440 \layout Standard
3441 Don't delete any of the stray spaces in the table above without checking
3442  the HTML output (last line)!
3443
3444 \end_inset
3445
3446
3447
3448 \layout Standard
3449 \SpecialChar ~
3450
3451 \newline
3452 The option -
3453 \begin_inset ERT
3454 status Collapsed
3455
3456 \layout Standard
3457
3458
3459 \backslash
3460 /
3461
3462 \end_inset
3463
3464 -nostdlib disables the last two search paths.
3465
3466 \layout Section
3467 Building SDCC
3468 \begin_inset LatexCommand \index{Building SDCC}
3469
3470 \end_inset
3471
3472
3473
3474 \layout Subsection
3475 Building SDCC on Linux
3476 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3477
3478 \end_inset
3479
3480
3481
3482 \layout Enumerate
3483
3484 \series medium
3485 Download the source package
3486 \series default
3487  either from the SDCC Subversion repository or from the nightly snapshots
3488 \series medium
3489 , it will be named something like sdcc
3490 \series default
3491 .src
3492 \series medium
3493 .t
3494 \series default
3495 ar.
3496 \series medium
3497 gz
3498 \series default
3499  
3500 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3501
3502 \end_inset
3503
3504 .
3505
3506 \layout Enumerate
3507
3508 \series medium
3509 Bring up a command line terminal, such as xterm.
3510
3511 \layout Enumerate
3512
3513 \series medium
3514 Unpack the file using a command like: 
3515 \family sans
3516 \series bold
3517 "tar -xvzf sdcc.src.tar.gz
3518 \family default
3519 \series default
3520 "
3521 \series medium
3522 , this will create a sub-directory called sdcc with all of the sources.
3523
3524 \layout Enumerate
3525 Change directory into the main SDCC directory, for example type: 
3526 \family sans
3527 \series bold
3528 "cd sdcc
3529 \series default
3530 ".
3531
3532 \layout Enumerate
3533
3534 \series medium
3535 Type 
3536 \family sans
3537 \series bold
3538 "./configure
3539 \family default
3540 \series default
3541 ".
3542  This configures the package for compilation on your system.
3543
3544 \layout Enumerate
3545
3546 \series medium
3547 Type 
3548 \family sans
3549 \series bold
3550 "make
3551 \family default
3552 \series default
3553 "
3554 \series medium
3555 .
3556
3557 \series default
3558  All of the source packages will compile, this can take a while.
3559
3560 \layout Enumerate
3561
3562 \series medium
3563 Type 
3564 \family sans
3565 \series bold
3566 "make install"
3567 \family default
3568 \series default
3569  as root
3570 \series medium
3571 .
3572
3573 \series default
3574  This copies the binary executables, the include files, the libraries and
3575  the documentation to the install directories.
3576  Proceed with section 
3577 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3578
3579 \end_inset
3580
3581 .
3582
3583 \layout Subsection
3584 Building SDCC on OSX 2.x
3585
3586 \layout Standard
3587 Follow the instruction for Linux.
3588 \newline
3589
3590 \newline
3591 On OSX 2.x it was reported, that the default
3592  gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3593  Fortunately there's also gcc 2.9.x installed, which works fine.
3594  This compiler can be selected by running 'configure' with:
3595
3596 \layout LyX-Code
3597 ./configure CC=gcc2 CXX=g++2
3598
3599 \layout Subsection
3600 Cross compiling SDCC on Linux for Windows
3601
3602 \layout Standard
3603 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3604  See section 'Configure Options'.
3605
3606 \layout Subsection
3607 Building SDCC using Cygwin and Mingw32
3608
3609 \layout Standard
3610 For building and installing a Cygwin executable follow the instructions
3611  for Linux.
3612 \newline
3613
3614 \newline
3615 On Cygwin a 
3616 \begin_inset Quotes sld
3617 \end_inset
3618
3619 native
3620 \begin_inset Quotes srd
3621 \end_inset
3622
3623  Win32-binary can be built, which will not need the Cygwin-DLL.
3624  For the necessary 'configure' options see section 'configure options' or
3625  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3626 \newline
3627
3628 \newline
3629 In order to install
3630  Cygwin on Windows download setup.exe from 
3631 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3632
3633 \end_inset
3634
3635 .
3636  Run it, set the 
3637 \begin_inset Quotes sld
3638 \end_inset
3639
3640 default text file type
3641 \begin_inset Quotes srd
3642 \end_inset
3643
3644  to 
3645 \begin_inset Quotes sld
3646 \end_inset
3647
3648 unix
3649 \begin_inset Quotes srd
3650 \end_inset
3651
3652  and download/install at least the following packages.
3653  Some packages are selected by default, others will be automatically selected
3654  because of dependencies with the manually selected packages.
3655  Never deselect these packages!
3656
3657 \layout Itemize
3658 flex
3659
3660 \layout Itemize
3661 bison
3662
3663 \layout Itemize
3664 gcc ; version 3.x is fine, no need to use the old 2.9x
3665
3666 \layout Itemize
3667 binutils ; selected with gcc
3668
3669 \layout Itemize
3670 make
3671
3672 \layout Itemize
3673 rxvt ; a nice console, which makes life much easier under windoze (see below)
3674
3675 \layout Itemize
3676 man ; not really needed for building SDCC, but you'll miss it sooner or
3677  later
3678
3679 \layout Itemize
3680 less ; not really needed for building SDCC, but you'll miss it sooner or
3681  later
3682
3683 \layout Itemize
3684 svn ; only if you use Subversion access
3685
3686 \layout Standard
3687 If you want to develop something you'll need:
3688
3689 \layout Itemize
3690 python ; for the regression tests
3691
3692 \layout Itemize
3693 gdb ; the gnu debugger, together with the nice GUI 
3694 \begin_inset Quotes sld
3695 \end_inset
3696
3697 insight
3698 \begin_inset Quotes srd
3699 \end_inset
3700
3701
3702
3703 \layout Itemize
3704 openssh ; to access the CF or commit changes
3705
3706 \layout Itemize
3707 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3708  use autoconf-stable!
3709
3710 \layout Standard
3711 rxvt is a nice console with history.
3712  Replace in your cygwin.bat the line
3713
3714 \layout LyX-Code
3715 bash -
3716 \begin_inset ERT
3717 status Collapsed
3718
3719 \layout Standard
3720
3721
3722 \backslash
3723 /
3724
3725 \end_inset
3726
3727 -login -i 
3728
3729 \layout Standard
3730 with (one line):
3731
3732 \layout LyX-Code
3733 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3734
3735 \layout LyX-Code
3736      -bg black -fg white -geometry 100x65 -e bash -
3737 \begin_inset ERT
3738 status Collapsed
3739
3740 \layout Standard
3741
3742
3743 \backslash
3744 /
3745
3746 \end_inset
3747
3748 -login
3749
3750 \layout Standard
3751 Text selected with the mouse is automatically copied to the clipboard, pasting
3752  works with shift-insert.
3753 \newline
3754
3755 \newline
3756 The other good tip is to make sure you have no //c/-styl
3757 e paths anywhere, use /cygdrive/c/ instead.
3758  Using // invokes a network lookup which is very slow.
3759  If you think 
3760 \begin_inset Quotes sld
3761 \end_inset
3762
3763 cygdrive
3764 \begin_inset Quotes srd
3765 \end_inset
3766
3767  is too long, you can change it with e.g.
3768
3769 \layout LyX-Code
3770 mount -s -u -c /mnt
3771
3772 \layout Standard
3773 SDCC sources use the unix line ending LF.
3774  Life is much easier, if you store the source tree on a drive which is mounted
3775  in binary mode.
3776  And use an editor which can handle LF-only line endings.
3777  Make sure not to commit files with windows line endings.
3778  The tabulator spacing
3779 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3780
3781 \end_inset
3782
3783  used in the project is 8.
3784  Although a tabulator spacing of 8 is a sensible choice for programmers
3785  (it's a power of 2 and allows to display 8/16 bit signed variables without
3786  loosing columns) the plan is to move towards using only spaces in the source.
3787
3788 \layout Subsection
3789 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3790
3791 \layout Standard
3792
3793 \series medium
3794 Download the source package
3795 \series default
3796  either from the SDCC Subversion repository or from the 
3797 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3798
3799 \end_inset
3800
3801
3802 \series medium
3803 , it will be named something like sdcc
3804 \series default
3805 .src
3806 \series medium
3807 .tgz.
3808
3809 \series default
3810  SDCC is distributed with all the projects, workspaces, and files you need
3811  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3812  The workspace name is 'sdcc.dsw'.
3813  Please note that as it is now, all the executables are created in a folder
3814  called sdcc
3815 \backslash
3816 bin_vc.
3817  Once built you need to copy the executables from sdcc
3818 \backslash
3819 bin_vc to sdcc
3820 \backslash
3821 bin before running SDCC.
3822  
3823 \newline
3824
3825 \newline
3826 WARNING: Visual studio is very picky with line terminations; it expects
3827  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3828  When using the Subversion repository it's easiest to configure the svn
3829  client to convert automatically for you.
3830  If however you are getting a message such as "This makefile was not generated
3831  by Developer Studio etc.
3832  etc.
3833 \begin_inset Quotes srd
3834 \end_inset
3835
3836  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3837  need to convert the Unix style line endings to DOS style line endings.
3838  To do so you can use the 
3839 \begin_inset Quotes sld
3840 \end_inset
3841
3842 unix2dos
3843 \begin_inset Quotes srd
3844 \end_inset
3845
3846  utility freely available on the internet.
3847  Doug Hawkins reported in the sdcc-user list that this works:
3848 \newline
3849
3850 \newline
3851 C:
3852 \backslash
3853 Programming
3854 \backslash
3855 SDCC> unix2dos sdcc.dsw
3856 \newline
3857 C:
3858 \backslash
3859 Programming
3860 \backslash
3861 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3862 \newline
3863
3864 \newline
3865 In order to build SDCC with MSVC
3866  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
3867  One good place to get them is 
3868 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3869
3870 \end_inset
3871
3872
3873 \newline
3874
3875 \newline
3876 Download the file UnxUtils
3877 \begin_inset LatexCommand \index{UnxUtils}
3878
3879 \end_inset
3880
3881 .zip.
3882  Now you have to install the utilities and setup MSVC so it can locate the
3883  required programs.
3884  Here there are two alternatives (choose one!):
3885
3886 \layout Enumerate
3887 The easy way:
3888 \newline
3889
3890 \newline
3891 a) Extract UnxUtils.zip to your C:
3892 \backslash
3893  hard disk PRESERVING the original paths, otherwise bison won't work.
3894  (If you are using WinZip make certain that 'Use folder names' is selected)
3895 \newline
3896
3897 \newline
3898 b)
3899  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
3900  'Show directories for:' select 'Executable files', and in the directories
3901  window add a new path: 'C:
3902 \backslash
3903 user
3904 \backslash
3905 local
3906 \backslash
3907 wbin', click ok.
3908 \newline
3909
3910 \newline
3911 (As a side effect, you get a bunch of Unix utilities that
3912  could be useful, such as diff and patch.)
3913
3914 \layout Enumerate
3915 A more compact way:
3916 \newline
3917
3918 \newline
3919 This one avoids extracting a bunch of files you may not
3920  use, but requires some extra work:
3921 \newline
3922
3923 \newline
3924 a) Create a directory were to put the
3925  tools needed, or use a directory already present.
3926  Say for example 'C:
3927 \backslash
3928 util'.
3929 \newline
3930
3931 \newline
3932 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
3933  gawk.exe to such directory WITHOUT preserving the original paths.
3934  (If you are using WinZip make certain that 'Use folder names' is not selected)
3935 \newline
3936
3937 \newline
3938 c
3939 ) Rename bison.exe to '_bison.exe'.
3940 \newline
3941
3942 \newline
3943 d) Create a batch file 'bison.bat' in 'C:
3944 \backslash
3945 util
3946 \backslash
3947 ' and add these lines: 
3948 \newline
3949 \SpecialChar ~
3950 \SpecialChar ~
3951 set BISON_SIMPLE=C:
3952 \backslash
3953 util
3954 \backslash
3955 bison.simple 
3956 \newline
3957 \SpecialChar ~
3958 \SpecialChar ~
3959 set BISON_HAIRY=C:
3960 \backslash
3961 util
3962 \backslash
3963 bison.hairy
3964 \newline
3965 \SpecialChar ~
3966 \SpecialChar ~
3967 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3968 \newline
3969
3970 \newline
3971 Steps 'c' and 'd' are needed
3972  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
3973  reside in some weird Unix directory, '/usr/local/share/' I think.
3974  So it is necessary to tell bison where those files are located if they
3975  are not in such directory.
3976  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3977 \newline
3978
3979 \newline
3980 e
3981 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3982  in 'Show directories for:' select 'Executable files', and in the directories
3983  window add a new path: 'c:
3984 \backslash
3985 util', click ok.
3986  Note that you can use any other path instead of 'c:
3987 \backslash
3988 util', even the path where the Visual C++ tools are, probably: 'C:
3989 \backslash
3990 Program Files
3991 \backslash
3992 Microsoft Visual Studio
3993 \backslash
3994 Common
3995 \backslash
3996 Tools'.
3997  So you don't have to execute step 'e' :)
3998
3999 \layout Standard
4000 That is it.
4001  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4002  the executables from sdcc
4003 \backslash
4004 bin_vc to sdcc
4005 \backslash
4006 bin, and you can compile using SDCC.
4007
4008 \layout Subsection
4009 Building SDCC Using Borland
4010
4011 \layout Enumerate
4012 From the sdcc directory, run the command "make -f Makefile.bcc".
4013  This should regenerate all the .exe files in the bin directory except for
4014  SDCDB and ucSim.
4015
4016 \layout Enumerate
4017 If you modify any source files and need to rebuild, be aware that the dependenci
4018 es may not be correctly calculated.
4019  The safest option is to delete all .obj files and run the build again.
4020  From a Cygwin BASH prompt, this can easily be done with the command (be
4021  sure you are in the sdcc directory):
4022 \newline
4023
4024 \newline
4025
4026 \family sans
4027 \series bold
4028 find .
4029  
4030 \backslash
4031 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4032 \backslash
4033 ) -print -exec rm {} 
4034 \backslash
4035 ;
4036 \family default
4037 \series default
4038
4039 \newline
4040
4041 \newline
4042 or on Windows NT/2000/XP from the command prompt with the command:
4043 \newline
4044
4045 \family sans
4046 \series bold
4047
4048 \newline
4049 del /s *.obj *.lib *.rul
4050 \family default
4051 \series default
4052  from the sdcc directory.
4053
4054 \layout Subsection
4055 Windows Install Using a ZIP Package
4056
4057 \layout Enumerate
4058 Download the binary zip package from 
4059 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4060
4061 \end_inset
4062
4063  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4064  This should unpack to a group of sub-directories.
4065  An example directory structure after unpacking the mingw32 package is:
4066  c:
4067 \backslash
4068 sdcc
4069 \backslash
4070 bin for the executables, c:
4071 \backslash
4072 sdcc
4073 \backslash
4074 include and c:
4075 \backslash
4076 sdcc
4077 \backslash
4078 lib for the include and libraries.
4079
4080 \layout Enumerate
4081 Adjust your environment variable PATH to include the location of the bin
4082  directory or start sdcc using the full path.
4083
4084 \layout Subsection
4085 Windows Install Using the Setup Program
4086 \begin_inset LatexCommand \label{sub:Windows-Install}
4087
4088 \end_inset
4089
4090
4091
4092 \layout Standard
4093 Download the setup program 
4094 \emph on
4095 sdcc-x.y.z-setup.exe
4096 \emph default
4097  for an official release from 
4098 \newline
4099
4100 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4101
4102 \end_inset
4103
4104  or a setup program for one of the snapshots 
4105 \emph on
4106 sdcc-yyyymmdd-xxxx-setup.exe
4107 \emph default
4108  from 
4109 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4110
4111 \end_inset
4112
4113  and execute it.
4114  A windows typical installer will guide you through the installation process.
4115
4116 \layout Subsection
4117 VPATH
4118 \begin_inset LatexCommand \index{VPATH}
4119
4120 \end_inset
4121
4122  feature
4123
4124 \layout Standard
4125 SDCC supports the VPATH feature provided by configure and make.
4126  It allows to separate the source and build trees.
4127  Here's an example:
4128
4129 \layout Standard
4130
4131 \family typewriter
4132 cd ~\SpecialChar ~
4133 \SpecialChar ~
4134 \SpecialChar ~
4135 \SpecialChar ~
4136 \SpecialChar ~
4137 \SpecialChar ~
4138 \SpecialChar ~
4139 \SpecialChar ~
4140 \SpecialChar ~
4141 \SpecialChar ~
4142 \SpecialChar ~
4143 \SpecialChar ~
4144 \SpecialChar ~
4145 \SpecialChar ~
4146 \SpecialChar ~
4147 \SpecialChar ~
4148 \SpecialChar ~
4149 \SpecialChar ~
4150 \SpecialChar ~
4151 \SpecialChar ~
4152 \SpecialChar ~
4153 # cd $HOME
4154
4155 \layout Standard
4156
4157 \family typewriter
4158 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4159 # extract source to directory sdcc
4160
4161 \layout Standard
4162
4163 \family typewriter
4164 mkdir sdcc.build\SpecialChar ~
4165 \SpecialChar ~
4166 \SpecialChar ~
4167 \SpecialChar ~
4168 \SpecialChar ~
4169 \SpecialChar ~
4170 \SpecialChar ~
4171 \SpecialChar ~
4172 \SpecialChar ~
4173 # put output in sdcc.build
4174
4175 \layout Standard
4176
4177 \family typewriter
4178 cd sdcc.build
4179
4180 \layout Standard
4181
4182 \family typewriter
4183 ../sdcc/configure\SpecialChar ~
4184 \SpecialChar ~
4185 \SpecialChar ~
4186 \SpecialChar ~
4187 \SpecialChar ~
4188 \SpecialChar ~
4189 \SpecialChar ~
4190 \SpecialChar ~
4191 # configure is doing all the magic!
4192
4193 \layout Standard
4194
4195 \family typewriter
4196 make
4197
4198 \layout Standard
4199 \noindent
4200 That's it! 
4201 \series bold
4202 configure
4203 \series default
4204  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4205  It automagically computes the variables srcdir, top_srcdir and top_buildir
4206  for each directory.
4207  After running 
4208 \series bold
4209 make
4210 \series default
4211  the generated files will be in ~/sdcc.build, while the source files stay
4212  in ~/sdcc.
4213 \newline
4214 This is not only usefull for building different binaries, e.g.
4215  when cross compiling.
4216  It also gives you a much better overview in the source tree when all the
4217  generated files are not scattered between the source files.
4218  And the best thing is: if you want to change a file you can leave the original
4219  file untouched in the source directory.
4220  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4221  Makefile.dep` and `make`.
4222  
4223 \series bold
4224 make
4225 \series default
4226  will do the rest for you!
4227
4228 \layout Section
4229 Building the Documentation
4230
4231 \layout Standard
4232 Add -
4233 \begin_inset ERT
4234 status Collapsed
4235
4236 \layout Standard
4237
4238
4239 \backslash
4240 /
4241
4242 \end_inset
4243
4244 -enable-doc to the configure arguments to build the documentation together
4245  with all the other stuff.
4246  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4247  dvips and makeindex) to get the job done.
4248  Another possibility is to change to the doc directory and to type 
4249 \family sans
4250 \series bold
4251
4252 \begin_inset Quotes srd
4253 \end_inset
4254
4255 make
4256 \begin_inset Quotes srd
4257 \end_inset
4258
4259
4260 \family default
4261 \series default
4262  there.
4263  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4264 x).
4265  Using LyX 
4266 \begin_inset LatexCommand \url{http://www.lyx.org}
4267
4268 \end_inset
4269
4270  as editor is straightforward.
4271  Prebuilt documentation in html and pdf format is available from 
4272 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4273
4274 \end_inset
4275
4276 .
4277
4278 \layout Section
4279 Reading the Documentation
4280 \begin_inset LatexCommand \index{Documentation}
4281
4282 \end_inset
4283
4284
4285
4286 \layout Standard
4287 Currently reading the document in pdf format is recommended, as for unknown
4288  reason the hyperlinks are working there whereas in the html version they
4289  are not
4290 \begin_inset Foot
4291 collapsed false
4292
4293 \layout Standard
4294 If you should know why please drop us a note
4295
4296 \end_inset
4297
4298 .
4299  
4300 \newline
4301 You'll find the pdf version
4302 \begin_inset LatexCommand \index{PDF version of this document}
4303
4304 \end_inset
4305
4306  at 
4307 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4308
4309 \end_inset
4310
4311 .
4312  
4313 \newline
4314 A html version
4315 \begin_inset LatexCommand \index{HTML version of this document}
4316
4317 \end_inset
4318
4319  should be online at 
4320 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4321
4322 \end_inset
4323
4324 .
4325 \newline
4326 This documentation is in some aspects different from a commercial documentation:
4327  
4328
4329 \layout Itemize
4330 It tries to document SDCC for several processor architectures in one document
4331  (commercially these probably would be separate documents/products).
4332  This document
4333 \begin_inset LatexCommand \index{Status of documentation}
4334
4335 \end_inset
4336
4337  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4338 on about f.e.
4339  Z80, PIC14, PIC16 and HC08.
4340
4341 \layout Itemize
4342 There are many references pointing away from this documentation.
4343  Don't let this distract you.
4344  If there f.e.
4345  was a reference like 
4346 \begin_inset LatexCommand \url{http://www.opencores.org}
4347
4348 \end_inset
4349
4350  together with a statement 
4351 \begin_inset Quotes sld
4352 \end_inset
4353
4354 some processors which are targetted by SDCC can be implemented in a 
4355 \emph on
4356 f
4357 \emph default
4358 ield 
4359 \emph on
4360 p
4361 \emph default
4362 rogrammable 
4363 \emph on
4364 g
4365 \emph default
4366 ate 
4367 \emph on
4368 a
4369 \emph default
4370 rray
4371 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4372
4373 \end_inset
4374
4375
4376 \begin_inset Quotes srd
4377 \end_inset
4378
4379  or 
4380 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4381
4382 \end_inset
4383
4384
4385 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4386
4387 \end_inset
4388
4389  
4390 \begin_inset Quotes sld
4391 \end_inset
4392
4393 have you ever heard of an open source compiler that compiles a subset of
4394  C for an FPGA?
4395 \begin_inset Quotes srd
4396 \end_inset
4397
4398  we expect you to have a quick look there and come back.
4399  If you read this you are on the right track.
4400
4401 \layout Itemize
4402 Some sections attribute more space to problems, restrictions and warnings
4403  than to the solution.
4404
4405 \layout Itemize
4406 The installation section and the section about the debugger is intimidating.
4407
4408 \layout Itemize
4409 There are still lots of typos and there are more different writing styles
4410  than pictures.
4411
4412 \layout Section
4413 Testing the SDCC Compiler
4414 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4415
4416 \end_inset
4417
4418
4419
4420 \layout Standard
4421 The first thing you should do after installing your SDCC compiler is to
4422  see if it runs.
4423  Type 
4424 \family sans
4425 \series bold
4426 "sdcc -
4427 \begin_inset ERT
4428 status Collapsed
4429
4430 \layout Standard
4431
4432
4433 \backslash
4434 /
4435
4436 \end_inset
4437
4438 -version"
4439 \begin_inset LatexCommand \index{version}
4440
4441 \end_inset
4442
4443
4444 \family default
4445 \series default
4446  at the prompt, and the program should run and output its version like:
4447  
4448 \newline
4449
4450 \family typewriter
4451 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4452  (UNIX)
4453
4454 \layout Standard
4455 If it doesn't run, or gives a message about not finding sdcc program, then
4456  you need to check over your installation.
4457  Make sure that the sdcc bin directory is in your executable search path
4458  defined by the PATH environment setting (
4459 \series medium
4460 see 
4461 \series default
4462 section 
4463 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4464
4465 \end_inset
4466
4467 \SpecialChar ~
4468
4469 \series medium
4470 Install trouble-shooting for suggestions
4471 \series default
4472 ).
4473  Make sure that the sdcc program is in the bin folder, if not perhaps something
4474  did not install correctly.
4475 \newline
4476
4477 \newline
4478
4479 \series medium
4480 SDCC 
4481 \series default
4482 is commonly installed as described in section 
4483 \begin_inset Quotes sld
4484 \end_inset
4485
4486 Install and search paths
4487 \begin_inset Quotes srd
4488 \end_inset
4489
4490 .
4491 \newline
4492
4493 \newline
4494
4495 \series medium
4496 Make sure the compiler works on a very simple example.
4497  Type in the following test.c program using your favorite 
4498 \series default
4499 ASCII 
4500 \series medium
4501 editor:
4502
4503 \layout Verse
4504
4505 \family typewriter
4506 char test;
4507 \newline
4508
4509 \newline
4510 void main(void) {
4511 \newline
4512 \SpecialChar ~
4513 \SpecialChar ~
4514 \SpecialChar ~
4515 \SpecialChar ~
4516 test=0;
4517 \newline
4518 }
4519
4520 \layout Standard
4521
4522 \series medium
4523 Compile this using the following command: 
4524 \family sans
4525 \series bold
4526 "sdcc -c test.c".
4527
4528 \family default
4529 \series default
4530  
4531 \series medium
4532 If all goes well, the compiler will generate a test.asm and test.rel file.
4533  Congratulations, you've just compiled your first program with SDCC.
4534  We used the -c option to tell SDCC not to link the generated code, just
4535  to keep things simple for this step.
4536 \series default
4537
4538 \newline
4539
4540 \newline
4541
4542 \series medium
4543 The next step is to try it with the linker.
4544  Type in 
4545 \family sans
4546 \series bold
4547 "sdcc test.c
4548 \family default
4549 \series default
4550 "
4551 \series medium
4552 .
4553  If all goes well the compiler will link with the libraries and produce
4554  a test.ihx output file.
4555  If this step fails
4556 \series default
4557  
4558 \series medium
4559 (no test.ihx, and the linker generates warnings), then the problem is most
4560  likely that 
4561 \series default
4562 SDCC
4563 \series medium
4564  cannot find the 
4565 \series default
4566 /
4567 \series medium
4568 usr/local/share/sdcc/lib directory
4569 \series default
4570  
4571 \series medium
4572 (see 
4573 \series default
4574 section 
4575 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4576
4577 \end_inset
4578
4579 \SpecialChar ~
4580
4581 \series medium
4582 Install trouble-shooting for suggestions).
4583 \series default
4584
4585 \newline
4586
4587 \newline
4588
4589 \series medium
4590 The final test is to ensure 
4591 \series default
4592 SDCC
4593 \series medium
4594  can use the 
4595 \series default
4596 standard
4597 \series medium
4598  header files and libraries.
4599  Edit test.c and change it to the following:
4600
4601 \layout Verse
4602
4603 \family typewriter
4604 #include <string.h>
4605 \newline
4606
4607 \newline
4608 char str1[10];
4609 \newline
4610
4611 \newline
4612 void main(void) {
4613 \newline
4614 \SpecialChar ~
4615 \SpecialChar ~
4616 strcpy(str1, "testing");
4617 \newline
4618 }
4619
4620 \layout Standard
4621
4622 \series medium
4623 Compile this by typing 
4624 \family sans
4625 \series bold
4626 "sdcc test.c"
4627 \family default
4628 \series medium
4629 .
4630  This should generate a test.ihx output file, and it should give no warnings
4631  such as not finding the string.h file.
4632  If it cannot find the string.h file, then the problem is that 
4633 \series default
4634 SDCC
4635 \series medium
4636  cannot find the /usr/local/share/sdcc/include directory
4637 \series default
4638  
4639 \series medium
4640 (see the 
4641 \series default
4642 section 
4643 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4644
4645 \end_inset
4646
4647 \SpecialChar ~
4648
4649 \series medium
4650 Install trouble-shooting section for suggestions).
4651
4652 \series default
4653  Use option 
4654 \series bold
4655 -
4656 \begin_inset ERT
4657 status Collapsed
4658
4659 \layout Standard
4660
4661
4662 \backslash
4663 /
4664
4665 \end_inset
4666
4667 -print-search-dirs
4668 \series default
4669
4670 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4671
4672 \end_inset
4673
4674  to find exactly where SDCC is looking for the include and lib files.
4675
4676 \layout Section
4677 Install Trouble-shooting
4678 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4679
4680 \end_inset
4681
4682
4683 \begin_inset LatexCommand \index{Install trouble-shooting}
4684
4685 \end_inset
4686
4687
4688
4689 \layout Subsection
4690 If SDCC does not build correctly
4691
4692 \layout Standard
4693 A thing to try is starting from scratch by unpacking the .tgz source package
4694  again in an empty directory.
4695  Configure it like:
4696 \newline
4697
4698 \newline
4699
4700 \family sans
4701 \series bold
4702 ./configure 2>&1 | tee configure.log
4703 \family default
4704 \series default
4705
4706 \newline
4707
4708 \newline
4709 and build it like:
4710 \newline
4711
4712 \newline
4713
4714 \family sans
4715 \series bold
4716 make 2>&1 | tee make.log
4717 \family default
4718 \series default
4719
4720 \newline
4721
4722 \newline
4723 If anything goes wrong, you can review the log files to locate the problem.
4724  Or a relevant part of this can be attached to an email that could be helpful
4725  when requesting help from the mailing list.
4726
4727 \layout Subsection
4728 What the 
4729 \begin_inset Quotes sld
4730 \end_inset
4731
4732 ./configure
4733 \begin_inset Quotes srd
4734 \end_inset
4735
4736  does
4737
4738 \layout Standard
4739 The 
4740 \begin_inset Quotes sld
4741 \end_inset
4742
4743 ./configure
4744 \begin_inset Quotes srd
4745 \end_inset
4746
4747  command is a script that analyzes your system and performs some configuration
4748  to ensure the source package compiles on your system.
4749  It will take a few minutes to run, and will compile a few tests to determine
4750  what compiler features are installed.
4751
4752 \layout Subsection
4753 What the 
4754 \begin_inset Quotes sld
4755 \end_inset
4756
4757 make
4758 \begin_inset Quotes srd
4759 \end_inset
4760
4761  does
4762
4763 \layout Standard
4764 This runs the GNU make tool, which automatically compiles all the source
4765  packages into the final installed binary executables.
4766
4767 \layout Subsection
4768 What the 
4769 \begin_inset Quotes sld
4770 \end_inset
4771
4772 make install
4773 \begin_inset Quotes erd
4774 \end_inset
4775
4776  command does.
4777
4778 \layout Standard
4779 This will install the compiler, other executables libraries and include
4780  files into the appropriate directories.
4781  See sections 
4782 \begin_inset LatexCommand \ref{sub:Install-paths}
4783
4784 \end_inset
4785
4786 ,\SpecialChar ~
4787
4788 \begin_inset LatexCommand \ref{sub:Search-Paths}
4789
4790 \end_inset
4791
4792 \SpecialChar ~
4793 about install and search paths.
4794 \newline
4795 On most systems you will need super-user privilege
4796 s to do this.
4797
4798 \layout Section
4799 Components of SDCC
4800
4801 \layout Standard
4802 SDCC is not just a compiler, but a collection of tools by various developers.
4803  These include linkers, assemblers, simulators and other components.
4804  Here is a summary of some of the components.
4805  Note that the included simulator and assembler have separate documentation
4806  which you can find in the source package in their respective directories.
4807  As SDCC grows to include support for other processors, other packages from
4808  various developers are included and may have their own sets of documentation.
4809 \newline
4810
4811 \newline
4812 You
4813  might want to look at the files which are installed in <installdir>.
4814  At the time of this writing, we find the following programs for gcc-builds:
4815 \newline
4816
4817  
4818 \newline
4819 In <installdir>/bin:
4820
4821 \layout Itemize
4822 sdcc - The compiler.
4823
4824 \layout Itemize
4825 sdcpp - The C preprocessor.
4826
4827 \layout Itemize
4828 asx8051 - The assembler for 8051 type processors.
4829
4830 \layout Itemize
4831 as-z80
4832 \series bold
4833
4834 \series default
4835 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4836
4837 \layout Itemize
4838 aslink -The linker for 8051 type processors.
4839
4840 \layout Itemize
4841 link-z80
4842 \series bold
4843
4844 \series default
4845 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4846
4847 \layout Itemize
4848 s51 - The ucSim 8051 simulator.
4849
4850 \layout Itemize
4851 sdcdb - The source debugger.
4852
4853 \layout Itemize
4854 packihx - A tool to pack (compress) Intel hex files.
4855
4856 \layout Standard
4857 In <installdir>/share/sdcc/include
4858
4859 \layout Itemize
4860 the include files
4861
4862 \layout Standard
4863 In <installdir>/share/sdcc/lib
4864
4865 \layout Itemize
4866 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4867  relocatables.
4868
4869 \layout Standard
4870 In <installdir>/share/sdcc/doc
4871
4872 \layout Itemize
4873 the documentation
4874
4875 \layout Standard
4876 As development for other processors proceeds, this list will expand to include
4877  executables to support processors like AVR, PIC, etc.
4878
4879 \layout Subsection
4880 sdcc - The Compiler
4881
4882 \layout Standard
4883 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4884  the assembler and linkage editor.
4885
4886 \layout Subsection
4887 sdcpp - The C-Preprocessor
4888
4889 \layout Standard
4890 The preprocessor
4891 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4892
4893 \end_inset
4894
4895  is a modified version of the GNU cpp
4896 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4897
4898 \end_inset
4899
4900  preprocessor 
4901 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4902
4903 \end_inset
4904
4905 .
4906  The C preprocessor is used to pull in #include sources, process #ifdef
4907  statements, #defines and so on.
4908
4909 \layout Subsection
4910 as
4911 \emph on
4912 xxxx
4913 \emph default
4914 , aslink, link-
4915 \emph on
4916 xxx
4917 \emph default
4918  - The Assemblers and Linkage Editors
4919
4920 \layout Standard
4921 This is retargettable assembler & linkage editor, it was developed by Alan
4922  Baldwin.
4923  John Hartman created the version for 8051, and I (Sandeep) have made some
4924  enhancements and bug fixes for it to work properly with SDCC.
4925
4926 \layout Subsection
4927 s51 - The Simulator
4928
4929 \layout Standard
4930 S51
4931 \begin_inset LatexCommand \index{s51}
4932
4933 \end_inset
4934
4935  is a freeware, opensource simulator developed by Daniel Drotos.
4936  The simulator is built as part of the build process.
4937  For more information visit Daniel's web site at: 
4938 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4939
4940 \end_inset
4941
4942 .
4943  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4944  XA51 family.
4945
4946 \layout Subsection
4947 sdcdb - Source Level Debugger
4948
4949 \layout Standard
4950 SDCDB
4951 \begin_inset LatexCommand \index{SDCDB (debugger)}
4952
4953 \end_inset
4954
4955  is the companion source level debugger.
4956  More about SDCDB in section 
4957 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4958
4959 \end_inset
4960
4961 .
4962  The current version of the debugger uses Daniel's Simulator S51
4963 \begin_inset LatexCommand \index{s51}
4964
4965 \end_inset
4966
4967 , but can be easily changed to use other simulators.
4968
4969 \layout Chapter
4970 Using SDCC
4971
4972 \layout Section
4973 Compiling
4974
4975 \layout Subsection
4976 Single Source File Projects
4977
4978 \layout Standard
4979 For single source file 8051 projects the process is very simple.
4980  Compile your programs with the following command 
4981 \family sans
4982 \series bold
4983 "sdcc sourcefile.c".
4984
4985 \family default
4986 \series default
4987  This will compile, assemble and link your source file.
4988  Output files are as follows:
4989
4990 \layout Itemize
4991 sourcefile.asm
4992 \begin_inset LatexCommand \index{<file>.asm}
4993
4994 \end_inset
4995
4996  - Assembler source
4997 \begin_inset LatexCommand \index{Assembler source}
4998
4999 \end_inset
5000
5001  file created by the compiler
5002
5003 \layout Itemize
5004 sourcefile.lst
5005 \begin_inset LatexCommand \index{<file>.lst}
5006
5007 \end_inset
5008
5009  - Assembler listing
5010 \begin_inset LatexCommand \index{Assembler listing}
5011
5012 \end_inset
5013
5014  file created by the Assembler
5015
5016 \layout Itemize
5017 sourcefile.rst
5018 \begin_inset LatexCommand \index{<file>.rst}
5019
5020 \end_inset
5021
5022  - Assembler listing
5023 \begin_inset LatexCommand \index{Assembler listing}
5024
5025 \end_inset
5026
5027  file updated with linkedit information, created by linkage editor
5028
5029 \layout Itemize
5030 sourcefile.sym
5031 \begin_inset LatexCommand \index{<file>.sym}
5032
5033 \end_inset
5034
5035  - symbol listing
5036 \begin_inset LatexCommand \index{Symbol listing}
5037
5038 \end_inset
5039
5040  for the sourcefile, created by the assembler
5041
5042 \layout Itemize
5043 sourcefile.rel
5044 \begin_inset LatexCommand \index{<file>.rel}
5045
5046 \end_inset
5047
5048  or sourcefile.o
5049 \begin_inset LatexCommand \index{<file>.o}
5050
5051 \end_inset
5052
5053  - Object file
5054 \begin_inset LatexCommand \index{Object file}
5055
5056 \end_inset
5057
5058  created by the assembler, input to Linkage editor
5059
5060 \layout Itemize
5061 sourcefile.map
5062 \begin_inset LatexCommand \index{<file>.map}
5063
5064 \end_inset
5065
5066  - The memory map
5067 \begin_inset LatexCommand \index{Memory map}
5068
5069 \end_inset
5070
5071  for the load module, created by the Linker
5072
5073 \layout Itemize
5074 sourcefile.mem
5075 \begin_inset LatexCommand \index{<file>.mem}
5076
5077 \end_inset
5078
5079  - A file with a summary of the memory usage
5080
5081 \layout Itemize
5082 sourcefile.ihx
5083 \begin_inset LatexCommand \index{<file>.ihx}
5084
5085 \end_inset
5086
5087  - The load module in Intel hex format
5088 \begin_inset LatexCommand \index{Intel hex format}
5089
5090 \end_inset
5091
5092  (you can select the Motorola S19 format
5093 \begin_inset LatexCommand \index{Motorola S19 format}
5094
5095 \end_inset
5096
5097  with -
5098 \begin_inset ERT
5099 status Collapsed
5100
5101 \layout Standard
5102
5103
5104 \backslash
5105 /
5106
5107 \end_inset
5108
5109 -out-fmt-s19
5110 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5111
5112 \end_inset
5113
5114 .
5115  If you need another format you might want to use 
5116 \family sans
5117 \shape italic
5118 objdump
5119 \family default
5120 \shape default
5121
5122 \begin_inset LatexCommand \index{objdump (tool)}
5123
5124 \end_inset
5125
5126  or
5127 \family sans
5128 \shape italic
5129  srecord
5130 \family default
5131 \shape default
5132
5133 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5134
5135 \end_inset
5136
5137 ).
5138  Both formats are documented in the documentation of srecord
5139 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5140
5141 \end_inset
5142
5143
5144
5145 \layout Itemize
5146 sourcefile.adb
5147 \begin_inset LatexCommand \index{<file>.adb}
5148
5149 \end_inset
5150
5151  - An intermediate file containing debug information needed to create the
5152  .cdb file (with -
5153 \begin_inset ERT
5154 status Collapsed
5155
5156 \layout Standard
5157
5158
5159 \backslash
5160 /
5161
5162 \end_inset
5163
5164 -debug
5165 \begin_inset LatexCommand \index{-\/-debug}
5166
5167 \end_inset
5168
5169
5170
5171 \layout Itemize
5172 sourcefile.cdb
5173 \begin_inset LatexCommand \index{<file>.cdb}
5174
5175 \end_inset
5176
5177  - An optional file (with -
5178 \begin_inset ERT
5179 status Collapsed
5180
5181 \layout Standard
5182
5183
5184 \backslash
5185 /
5186
5187 \end_inset
5188
5189 -debug) containing debug information.
5190  The format is documented in cdbfileformat.pdf
5191
5192 \layout Itemize
5193 sourcefile.
5194  - (no extension)
5195 \begin_inset LatexCommand \index{<file> (no extension)}
5196
5197 \end_inset
5198
5199  An optional AOMF or AOMF51
5200 \begin_inset LatexCommand \index{AOMF, AOMF51}
5201
5202 \end_inset
5203
5204  
5205 \begin_inset LatexCommand \label{OMF file}
5206
5207 \end_inset
5208
5209 file containing debug information (generated with option -
5210 \begin_inset ERT
5211 status Collapsed
5212
5213 \layout Standard
5214
5215
5216 \backslash
5217 /
5218
5219 \end_inset
5220
5221 -debug).
5222  The (Intel)
5223 \emph on
5224  a
5225 \emph default
5226 bsolute 
5227 \emph on
5228 o
5229 \emph default
5230 bject 
5231 \emph on
5232 m
5233 \emph default
5234 odule 
5235 \emph on
5236 f
5237 \emph default
5238 ormat is commonly used by third party tools (debuggers
5239 \begin_inset LatexCommand \index{Debugger}
5240
5241 \end_inset
5242
5243 , simulators, emulators)
5244
5245 \layout Itemize
5246 sourcefile.dump*
5247 \begin_inset LatexCommand \index{<file>.dump*}
5248
5249 \end_inset
5250
5251  - Dump file to debug the compiler it self (generated with option -
5252 \begin_inset ERT
5253 status Collapsed
5254
5255 \layout Standard
5256
5257
5258 \backslash
5259 /
5260
5261 \end_inset
5262
5263 -dumpall) (see section 
5264 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5265
5266 \end_inset
5267
5268 \SpecialChar ~
5269  and section 
5270 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5271
5272 \end_inset
5273
5274 \SpecialChar ~
5275
5276 \begin_inset Quotes sld
5277 \end_inset
5278
5279 Anatomy of the compiler
5280 \begin_inset Quotes srd
5281 \end_inset
5282
5283 ).
5284
5285 \layout Subsection
5286 Postprocessing the Intel Hex
5287 \begin_inset LatexCommand \index{Intel hex format}
5288
5289 \end_inset
5290
5291  file
5292
5293 \layout Standard
5294 In most cases this won't be needed but the Intel Hex file
5295 \begin_inset LatexCommand \index{<file>.ihx}
5296
5297 \end_inset
5298
5299  which is generated by SDCC might include lines of varying length and the
5300  addresses within the file are not guaranteed to be strictly ascending.
5301  If your toolchain or a bootloader does not like this you can use the tool
5302  
5303 \family typewriter
5304 packihx
5305 \family default
5306
5307 \begin_inset LatexCommand \index{packihx (tool)}
5308
5309 \end_inset
5310
5311  which is part of the SDCC distribution: 
5312 \newline
5313
5314 \newline
5315
5316 \family sans
5317 \series bold
5318  packihx sourcefile.ihx >sourcefile.hex
5319 \family default
5320 \series default
5321
5322 \newline
5323
5324 \newline
5325 The separately available
5326 \emph on
5327  srecord
5328 \emph default
5329
5330 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5331
5332 \end_inset
5333
5334  package additionally allows to set undefined locations to a predefined
5335  value, to insert checksums
5336 \begin_inset LatexCommand \index{checksum}
5337
5338 \end_inset
5339
5340  of various flavours (crc, add, xor) and to perform other manipulations
5341  (convert, split, crop, offset, ...).
5342  
5343 \newline
5344
5345 \newline
5346
5347 \family sans
5348 \series bold
5349 srec_cat\SpecialChar ~
5350 \SpecialChar ~
5351 sourcefile.ihx -intel\SpecialChar ~
5352 \SpecialChar ~
5353 -o sourcefile.hex -intel
5354 \newline
5355
5356 \newline
5357
5358 \family default
5359 \series default
5360 An example for a more complex command line
5361 \begin_inset Foot
5362 collapsed false
5363
5364 \layout Standard
5365 the command backfills
5366 \begin_inset LatexCommand \index{backfill unused memory}
5367
5368 \end_inset
5369
5370  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5371  block is zero.
5372  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5373  will be interpreted as an 
5374 \family typewriter
5375 lcall
5376 \family default
5377  to address 
5378 \family typewriter
5379 0x1212
5380 \family default
5381  (where an emergency routine could sit).
5382
5383 \end_inset
5384
5385  could look like:
5386 \newline
5387
5388 \newline
5389
5390 \family sans
5391 \series bold
5392 \size footnotesize
5393 srec_cat\SpecialChar ~
5394 sourcefile.ihx -intel\SpecialChar ~
5395 \SpecialChar ~
5396 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5397 -little-endian-checksum-nega
5398 tive 0xfffe 0x02 0x02\SpecialChar ~
5399 \SpecialChar ~
5400 -o sourcefile.hex -intel
5401 \size default
5402
5403 \newline
5404
5405 \newline
5406
5407 \family default
5408 \series default
5409 The srecord package is available at 
5410 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5411
5412 \end_inset
5413
5414  .
5415
5416 \layout Subsection
5417 Projects with Multiple Source Files
5418
5419 \layout Standard
5420 SDCC can compile only ONE file at a time.
5421  Let us for example assume that you have a project containing the following
5422  files:
5423 \newline
5424
5425 \newline
5426 foo1.c (contains some functions)
5427 \newline
5428 foo2.c (contains some more functions)
5429 \newline
5430 foomai
5431 n.c (contains more functions and the function main)
5432 \newline
5433
5434 \size footnotesize
5435
5436 \newline
5437
5438 \size default
5439 The first two files will need to be compiled separately with the commands:
5440 \size footnotesize
5441  
5442 \size default
5443
5444 \newline
5445
5446 \newline
5447
5448 \family sans
5449 \series bold
5450 sdcc\SpecialChar ~
5451 -c\SpecialChar ~
5452 foo1.c
5453 \family default
5454 \series default
5455 \size footnotesize
5456
5457 \newline
5458
5459 \family sans
5460 \series bold
5461 \size default
5462 sdcc\SpecialChar ~
5463 -c\SpecialChar ~
5464 foo2.c
5465 \family default
5466 \series default
5467
5468 \newline
5469
5470 \newline
5471 Then compile the source file containing the 
5472 \emph on
5473 main()
5474 \emph default
5475  function and link
5476 \begin_inset LatexCommand \index{Linker}
5477
5478 \end_inset
5479
5480  the files together with the following command: 
5481 \newline
5482
5483 \newline
5484
5485 \family sans
5486 \series bold
5487 sdcc\SpecialChar ~
5488 foomain.c\SpecialChar ~
5489 foo1.rel\SpecialChar ~
5490 foo2.rel
5491 \family default
5492 \series default
5493
5494 \begin_inset LatexCommand \index{<file>.rel}
5495
5496 \end_inset
5497
5498
5499 \newline
5500
5501 \newline
5502 Alternatively, 
5503 \emph on
5504 foomain.c 
5505 \emph default
5506 can be separately compiled as well: 
5507 \family sans
5508 \series bold
5509
5510 \newline
5511
5512 \newline
5513 sdcc\SpecialChar ~
5514 -c\SpecialChar ~
5515 foomain.c
5516 \newline
5517 sdcc foomain.rel foo1.rel foo2.rel
5518 \newline
5519
5520 \newline
5521
5522 \family default
5523 \series default
5524 The file containing the 
5525 \emph on
5526 main()
5527 \emph default
5528  function
5529 \emph on
5530  
5531 \emph default
5532 \noun on
5533 must
5534 \noun default
5535  be the 
5536 \noun on
5537 first
5538 \noun default
5539  file specified in the command line, since the linkage editor processes
5540  file in the order they are presented to it.
5541  The linker is invoked from SDCC using a script file with extension .lnk
5542 \begin_inset LatexCommand \index{<file>.lnk}
5543
5544 \end_inset
5545
5546 .
5547  You can view this file to troubleshoot linking problems such as those arising
5548  from missing libraries.
5549
5550 \layout Subsection
5551 Projects with Additional Libraries
5552 \begin_inset LatexCommand \index{Libraries}
5553
5554 \end_inset
5555
5556
5557
5558 \layout Standard
5559 Some reusable routines may be compiled into a library, see the documentation
5560  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5561  for how to create a 
5562 \emph on
5563 .lib
5564 \begin_inset LatexCommand \index{<file>.lib}
5565
5566 \end_inset
5567
5568
5569 \emph default
5570  library file.
5571  Libraries created in this manner can be included in the command line.
5572  Make sure you include the -L <library-path> option to tell the linker where
5573  to look for these files if they are not in the current directory.
5574  Here is an example, assuming you have the source file 
5575 \emph on
5576 foomain.c
5577 \emph default
5578  and a library
5579 \emph on
5580  foolib.lib
5581 \emph default
5582  in the directory 
5583 \emph on
5584 mylib
5585 \emph default
5586  (if that is not the same as your current project):
5587 \newline
5588
5589 \newline
5590
5591 \family sans
5592 \series bold
5593 sdcc foomain.c foolib.lib -L mylib
5594 \newline
5595
5596 \newline
5597
5598 \family default
5599 \series default
5600 Note here that
5601 \emph on
5602  mylib
5603 \emph default
5604  must be an absolute path name.
5605 \newline
5606
5607 \newline
5608 The most efficient way to use libraries is
5609  to keep separate modules in separate source files.
5610  The lib file now should name all the modules.rel
5611 \begin_inset LatexCommand \index{<file>.rel}
5612
5613 \end_inset
5614
5615  files.
5616  For an example see the standard library file 
5617 \emph on
5618 libsdcc.lib
5619 \emph default
5620  in the directory <installdir>/share/lib/small.
5621
5622 \layout Subsection
5623 Using sdcclib to Create and Manage Libraries
5624 \begin_inset LatexCommand \index{sdcclib}
5625
5626 \end_inset
5627
5628
5629
5630 \layout Standard
5631 Alternatively, instead of having a .rel file for each entry on the library
5632  file as described in the preceding section, sdcclib can be used to embed
5633  all the modules belonging to such library in the library file itself.
5634  This results in a larger library file, but it greatly reduces the number
5635  of disk files accessed by the linker.
5636   Additionally, the packed library file contains an index of all include
5637  modules and symbols that significantly speeds up the linking process.
5638  To display a list of options supported by sdcclib type:
5639 \newline
5640
5641
5642 \layout Standard
5643
5644 \family sans
5645 \series bold
5646 sdcclib -?
5647 \begin_inset LatexCommand \index{sdcclib}
5648
5649 \end_inset
5650
5651
5652 \newline
5653
5654 \newline
5655
5656 \family default
5657 \series default
5658 To create a new library file, start by compiling all the required modules.
5659  For example:
5660 \newline
5661
5662
5663 \layout Standard
5664
5665 \family sans
5666 \series bold
5667 sdcc -c _divsint.c
5668
5669 \layout Standard
5670
5671 \family sans
5672 \series bold
5673 sdcc -c _divuint.c
5674
5675 \layout Standard
5676
5677 \family sans
5678 \series bold
5679 sdcc -c _modsint.c
5680
5681 \layout Standard
5682
5683 \family sans
5684 \series bold
5685 sdcc -c _moduint.c
5686
5687 \layout Standard
5688
5689 \family sans
5690 \series bold
5691 sdcc -c _mulint.c
5692 \newline
5693
5694
5695 \layout Standard
5696 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5697  and _mulint.rel.
5698  The next step is to add the .rel files to the library file:
5699 \newline
5700
5701
5702 \layout Standard
5703
5704 \family sans
5705 \series bold
5706 sdcclib libint.lib _divsint.rel
5707 \family default
5708
5709 \begin_inset LatexCommand \index{sdcclib}
5710
5711 \end_inset
5712
5713
5714
5715 \layout Standard
5716
5717 \family sans
5718 \series bold
5719 sdcclib libint.lib _divuint.rel
5720
5721 \layout Standard
5722
5723 \family sans
5724 \series bold
5725 sdcclib libint.lib _modsint.rel
5726
5727 \layout Standard
5728
5729 \family sans
5730 \series bold
5731 sdcclib libint.lib _moduint.rel
5732
5733 \layout Standard
5734
5735 \family sans
5736 \series bold
5737 sdcclib libint.lib _mulint.rel
5738 \series default
5739
5740 \newline
5741
5742
5743 \layout Standard
5744 If the file already exists in the library, it will be replaced.
5745  To see what modules and symbols are included in the library, options -s
5746  and -m are available.
5747  For example:
5748 \newline
5749
5750 \newline
5751
5752 \family sans
5753 \series bold
5754 sdcclib -s libint.lib
5755 \family default
5756
5757 \begin_inset LatexCommand \index{sdcclib}
5758
5759 \end_inset
5760
5761
5762 \newline
5763
5764 \family typewriter
5765 \series default
5766 _divsint.rel:
5767
5768 \layout Standard
5769
5770 \family typewriter
5771 __divsint_a_1_1
5772
5773 \layout Standard
5774
5775 \family typewriter
5776 __divsint_PARM_2
5777
5778 \layout Standard
5779
5780 \family typewriter
5781 __divsint
5782 \newline
5783 _divuint.rel:
5784
5785 \layout Standard
5786
5787 \family typewriter
5788 __divuint_a_1_1
5789
5790 \layout Standard
5791
5792 \family typewriter
5793 __divuint_PARM_2
5794
5795 \layout Standard
5796
5797 \family typewriter
5798 __divuint_reste_1_1
5799
5800 \layout Standard
5801
5802 \family typewriter
5803 __divuint_count_1_1
5804
5805 \layout Standard
5806
5807 \family typewriter
5808 __divuint
5809 \newline
5810 _modsint.rel:
5811
5812 \layout Standard
5813
5814 \family typewriter
5815 __modsint_a_1_1
5816
5817 \layout Standard
5818
5819 \family typewriter
5820 __modsint_PARM_2
5821
5822 \layout Standard
5823
5824 \family typewriter
5825 __modsint
5826 \newline
5827 _moduint.rel:
5828
5829 \layout Standard
5830
5831 \family typewriter
5832 __moduint_a_1_1
5833
5834 \layout Standard
5835
5836 \family typewriter
5837 __moduint_PARM_2
5838
5839 \layout Standard
5840
5841 \family typewriter
5842 __moduint_count_1_1
5843
5844 \layout Standard
5845
5846 \family typewriter
5847 __moduint
5848 \newline
5849 _mulint.rel:
5850
5851 \layout Standard
5852
5853 \family typewriter
5854 __mulint_PARM_2
5855
5856 \layout Standard
5857
5858 \family typewriter
5859 __mulint
5860 \family default
5861 \series bold
5862
5863 \newline
5864
5865
5866 \layout Standard
5867 \added_space_bottom bigskip 
5868 If the source files are compiled using -
5869 \begin_inset ERT
5870 status Collapsed
5871
5872 \layout Standard
5873
5874
5875 \backslash
5876 /
5877
5878 \end_inset
5879
5880 -debug
5881 \begin_inset LatexCommand \index{-\/-debug}
5882
5883 \end_inset
5884
5885 , the corresponding debug information file .adb will be include in the library
5886  file as well.
5887  The library files created with sdcclib are plain text files, so they can
5888  be viewed with a text editor.
5889  It is not recomended to modify a library file created with sdcclib using
5890  a text editor, as there are file indexes numbers located accross the file
5891  used by the linker to quickly locate the required module to link.
5892  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5893  it can be safely deleted, since all the information required for linking
5894  is embedded in the library file itself.
5895  Library files created using sdcclib are used as described in the preceding
5896  sections.
5897
5898
5899
5900 \layout Section
5901 Command Line Options
5902 \begin_inset LatexCommand \index{Command Line Options}
5903
5904 \end_inset
5905
5906
5907
5908 \layout Subsection
5909 Processor Selection Options
5910 \begin_inset LatexCommand \index{Options processor selection}
5911
5912 \end_inset
5913
5914
5915 \begin_inset LatexCommand \index{Processor selection options}
5916
5917 \end_inset
5918
5919
5920
5921 \layout List
5922 \labelwidthstring 00.00.0000
5923
5924 \series bold
5925 -mmcs51
5926 \begin_inset LatexCommand \index{-mmcs51}
5927
5928 \end_inset
5929
5930
5931 \series default
5932  Generate code for the Intel MCS51
5933 \begin_inset LatexCommand \index{MCS51}
5934
5935 \end_inset
5936
5937  family of processors.
5938  This is the default processor target.
5939
5940 \layout List
5941 \labelwidthstring 00.00.0000
5942
5943 \series bold
5944 -mds390
5945 \begin_inset LatexCommand \index{-mds390}
5946
5947 \end_inset
5948
5949
5950 \series default
5951  Generate code for the Dallas DS80C390
5952 \begin_inset LatexCommand \index{DS80C390}
5953
5954 \end_inset
5955
5956  processor.
5957
5958 \layout List
5959 \labelwidthstring 00.00.0000
5960
5961 \series bold
5962 -mds400
5963 \begin_inset LatexCommand \index{-mds400}
5964
5965 \end_inset
5966
5967
5968 \series default
5969  Generate code for the Dallas DS80C400
5970 \begin_inset LatexCommand \index{DS80C400}
5971
5972 \end_inset
5973
5974  processor.
5975
5976 \layout List
5977 \labelwidthstring 00.00.0000
5978
5979 \series bold
5980 -mhc08
5981 \begin_inset LatexCommand \index{-mhc08}
5982
5983 \end_inset
5984
5985
5986 \series default
5987  Generate code for the Freescale/Motorola HC08
5988 \begin_inset LatexCommand \index{HC08}
5989
5990 \end_inset
5991
5992  family of processors.
5993
5994 \layout List
5995 \labelwidthstring 00.00.0000
5996
5997 \series bold
5998 -mz80
5999 \begin_inset LatexCommand \index{-mz80}
6000
6001 \end_inset
6002
6003
6004 \series default
6005  Generate code for the Zilog Z80
6006 \begin_inset LatexCommand \index{Z80}
6007
6008 \end_inset
6009
6010  family of processors.
6011
6012 \layout List
6013 \labelwidthstring 00.00.0000
6014
6015 \series bold
6016 -mgbz80
6017 \begin_inset LatexCommand \index{-mgbz80}
6018
6019 \end_inset
6020
6021
6022 \series default
6023  Generate code for the GameBoy Z80
6024 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6025
6026 \end_inset
6027
6028  processor (Not actively maintained).
6029
6030 \layout List
6031 \labelwidthstring 00.00.0000
6032
6033 \series bold
6034 -mavr
6035 \begin_inset LatexCommand \index{-mavr}
6036
6037 \end_inset
6038
6039
6040 \series default
6041  Generate code for the Atmel AVR
6042 \begin_inset LatexCommand \index{AVR}
6043
6044 \end_inset
6045
6046  processor (Not maintained, not complete).
6047  AVR users should probably have a look at winavr 
6048 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6049
6050 \end_inset
6051
6052  or 
6053 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6054
6055 \end_inset
6056
6057 .
6058
6059 \layout Standard
6060 \begin_inset Note
6061 collapsed true
6062
6063 \layout Standard
6064 I think it is fair to direct users there for now.
6065  Open source is also about avoiding unnecessary work .
6066  But I didn't find the 'official' link.
6067
6068 \end_inset
6069
6070
6071
6072 \layout List
6073 \labelwidthstring 00.00.0000
6074
6075 \series bold
6076 -mpic14
6077 \begin_inset LatexCommand \index{-mpic14}
6078
6079 \end_inset
6080
6081
6082 \series default
6083  Generate code for the Microchip PIC 14
6084 \begin_inset LatexCommand \index{PIC14}
6085
6086 \end_inset
6087
6088 -bit processors (p16f84 and variants.
6089  In development, not complete).
6090
6091 \layout Standard
6092 \begin_inset Note
6093 collapsed true
6094
6095 \layout Standard
6096 p16f627 p16f628 p16f84 p16f873 p16f877?
6097
6098 \end_inset
6099
6100
6101
6102 \layout List
6103 \labelwidthstring 00.00.0000
6104
6105 \series bold
6106 -mpic16
6107 \begin_inset LatexCommand \index{-mpic16}
6108
6109 \end_inset
6110
6111
6112 \series default
6113  Generate code for the Microchip PIC 16
6114 \begin_inset LatexCommand \index{PIC16}
6115
6116 \end_inset
6117
6118 -bit processors (p18f452 and variants.
6119  In development, not complete).
6120
6121 \layout List
6122 \labelwidthstring 00.00.0000
6123
6124 \series bold
6125 -mtlcs900h
6126 \series default
6127  Generate code for the Toshiba TLCS-900H
6128 \begin_inset LatexCommand \index{TLCS-900H}
6129
6130 \end_inset
6131
6132  processor (Not maintained, not complete).
6133
6134 \layout List
6135 \labelwidthstring 00.00.0000
6136 \added_space_bottom bigskip 
6137
6138 \series bold
6139 -mxa51
6140 \begin_inset LatexCommand \index{-mxa51}
6141
6142 \end_inset
6143
6144
6145 \series default
6146  Generate code for the Phillips XA51
6147 \begin_inset LatexCommand \index{XA51}
6148
6149 \end_inset
6150
6151  processor (Not maintained, not complete).
6152
6153
6154 \layout Subsection
6155 Preprocessor Options
6156 \begin_inset LatexCommand \index{Options preprocessor}
6157
6158 \end_inset
6159
6160
6161 \begin_inset LatexCommand \index{Preprocessor options}
6162
6163 \end_inset
6164
6165
6166 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6167
6168 \end_inset
6169
6170
6171
6172 \layout List
6173 \labelwidthstring 00.00.0000
6174
6175 \series bold
6176 -I<path>
6177 \begin_inset LatexCommand \index{-I<path>}
6178
6179 \end_inset
6180
6181
6182 \series default
6183  The additional location where the pre processor will look for <..h> or 
6184 \begin_inset Quotes eld
6185 \end_inset
6186
6187 ..h
6188 \begin_inset Quotes erd
6189 \end_inset
6190
6191  files.
6192
6193 \layout List
6194 \labelwidthstring 00.00.0000
6195
6196 \series bold
6197 -D<macro[=value]>
6198 \begin_inset LatexCommand \index{-D<macro[=value]>}
6199
6200 \end_inset
6201
6202
6203 \series default
6204  Command line definition of macros.
6205  Passed to the preprocessor.
6206
6207 \layout List
6208 \labelwidthstring 00.00.0000
6209
6210 \series bold
6211 -M
6212 \begin_inset LatexCommand \index{-M}
6213
6214 \end_inset
6215
6216
6217 \series default
6218  Tell the preprocessor to output a rule suitable for make describing the
6219  dependencies of each object file.
6220  For each source file, the preprocessor outputs one make-rule whose target
6221  is the object file name for that source file and whose dependencies are
6222  all the files `#include'd in it.
6223  This rule may be a single line or may be continued with `
6224 \backslash
6225 '-newline if it is long.
6226  The list of rules is printed on standard output instead of the preprocessed
6227  C program.
6228  `-M' implies `-E
6229 \begin_inset LatexCommand \index{-E}
6230
6231 \end_inset
6232
6233 '.
6234
6235 \layout List
6236 \labelwidthstring 00.00.0000
6237
6238 \series bold
6239 -C
6240 \begin_inset LatexCommand \index{-C}
6241
6242 \end_inset
6243
6244
6245 \series default
6246  Tell the preprocessor not to discard comments.
6247  Used with the `-E' option.
6248
6249 \layout List
6250 \labelwidthstring 00.00.0000
6251
6252 \series bold
6253 -MM
6254 \begin_inset LatexCommand \index{-MM}
6255
6256 \end_inset
6257
6258
6259 \size large
6260 \bar under
6261  
6262 \series default
6263 \size default
6264 \bar default
6265 Like `-M' but the output mentions only the user header files included with
6266  `#include 
6267 \begin_inset Quotes eld
6268 \end_inset
6269
6270 file"'.
6271  System header files included with `#include <file>' are omitted.
6272
6273 \layout List
6274 \labelwidthstring 00.00.0000
6275
6276 \series bold
6277 -Aquestion(answer)
6278 \begin_inset LatexCommand \index{-Aquestion(answer)}
6279
6280 \end_inset
6281
6282
6283 \series default
6284  Assert the answer answer for question, in case it is tested with a preprocessor
6285  conditional such as `#if #question(answer)'.
6286  `-A-' disables the standard assertions that normally describe the target
6287  machine.
6288
6289 \layout List
6290 \labelwidthstring 00.00.0000
6291
6292 \series bold
6293 -Umacro
6294 \begin_inset LatexCommand \index{-Umacro}
6295
6296 \end_inset
6297
6298
6299 \series default
6300  Undefine macro macro.
6301  `-U' options are evaluated after all `-D' options, but before any `-include'
6302  and `-imacros' options.
6303
6304 \layout List
6305 \labelwidthstring 00.00.0000
6306
6307 \series bold
6308 -dM
6309 \begin_inset LatexCommand \index{-dM}
6310
6311 \end_inset
6312
6313
6314 \series default
6315  Tell the preprocessor to output only a list of the macro definitions that
6316  are in effect at the end of preprocessing.
6317  Used with the `-E' option.
6318
6319 \layout List
6320 \labelwidthstring 00.00.0000
6321
6322 \series bold
6323 -dD
6324 \begin_inset LatexCommand \index{-dD}
6325
6326 \end_inset
6327
6328
6329 \series default
6330  Tell the preprocessor to pass all macro definitions into the output, in
6331  their proper sequence in the rest of the output.
6332
6333 \layout List
6334 \labelwidthstring 00.00.0000
6335
6336 \series bold
6337 -dN
6338 \begin_inset LatexCommand \index{-dN}
6339
6340 \end_inset
6341
6342
6343 \size large
6344 \bar under
6345  
6346 \series default
6347 \size default
6348 \bar default
6349 Like `-dD' except that the macro arguments and contents are omitted.
6350  Only `#define name' is included in the output.
6351
6352 \layout List
6353 \labelwidthstring 00.00.0000
6354
6355 \series bold
6356 -pedantic-parse-number
6357 \begin_inset LatexCommand \index{-pedantic-parse-number}
6358
6359 \end_inset
6360
6361
6362 \size large
6363 \bar under
6364  
6365 \series default
6366 \size default
6367 \bar default
6368 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6369  and the macro LO_B(3) gets expanded.
6370  See also #pragma pedantic_parse_number in section
6371 \begin_inset LatexCommand \ref{sec:Pragmas}
6372
6373 \end_inset
6374
6375  
6376 \emph on
6377 Note: this functionality is not in conformance with standard!
6378
6379 \layout List
6380 \labelwidthstring 00.00.0000
6381 \added_space_bottom bigskip 
6382
6383 \series bold
6384 -Wp\SpecialChar ~
6385 preprocessorOption[,preprocessorOption]
6386 \series default
6387
6388 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6389
6390 \end_inset
6391
6392 ...
6393  Pass the preprocessorOption to the preprocessor 
6394 \family typewriter
6395 sdcpp
6396 \family default
6397
6398 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6399
6400 \end_inset
6401
6402 .
6403  SDCC uses an adapted version of the preprocessor 
6404 \emph on
6405 cpp
6406 \emph default
6407  of the GNU Compiler Collection
6408 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6409
6410 \end_inset
6411
6412  (
6413 \emph on
6414 gcc
6415 \emph default
6416  
6417 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6418
6419 \end_inset
6420
6421 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6422 4.1.1\SpecialChar ~
6423 CPP\SpecialChar ~
6424 Manual
6425  at 
6426 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6427
6428 \end_inset
6429
6430 .
6431
6432
6433 \layout Subsection
6434 Linker Options
6435 \begin_inset LatexCommand \index{Options linker}
6436
6437 \end_inset
6438
6439
6440 \begin_inset LatexCommand \index{Linker options}
6441
6442 \end_inset
6443
6444
6445
6446 \layout List
6447 \labelwidthstring 00.00.0000
6448
6449 \series bold
6450 -L\SpecialChar ~
6451 -
6452 \series default
6453
6454 \begin_inset ERT
6455 status Collapsed
6456
6457 \layout Standard
6458
6459
6460 \backslash
6461 /
6462
6463 \end_inset
6464
6465
6466 \series bold
6467 -lib-path
6468 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6469
6470 \end_inset
6471
6472
6473 \begin_inset LatexCommand \index{-L -\/-lib-path}
6474
6475 \end_inset
6476
6477
6478 \series default
6479 \SpecialChar ~
6480 <absolute path to additional libraries> This option is passed to the linkage
6481  editor's additional libraries
6482 \begin_inset LatexCommand \index{Libraries}
6483
6484 \end_inset
6485
6486  search path.
6487  The path name must be absolute.
6488  Additional library files may be specified in the command line.
6489  See section Compiling programs for more details.
6490
6491 \layout List
6492 \labelwidthstring 00.00.0000
6493
6494 \series bold
6495 -
6496 \begin_inset ERT
6497 status Collapsed
6498
6499 \layout Standard
6500
6501
6502 \backslash
6503 /
6504
6505 \end_inset
6506
6507 -xram-loc
6508 \series default
6509
6510 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6511
6512 \end_inset
6513
6514 \SpecialChar ~
6515 <Value> The start location of the external ram
6516 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6517
6518 \end_inset
6519
6520 , default value is 0.
6521  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6522 \begin_inset ERT
6523 status Collapsed
6524
6525 \layout Standard
6526
6527
6528 \backslash
6529 /
6530
6531 \end_inset
6532
6533 -xram-loc 0x8000 or -
6534 \begin_inset ERT
6535 status Collapsed
6536
6537 \layout Standard
6538
6539
6540 \backslash
6541 /
6542
6543 \end_inset
6544
6545 -xram-loc 32768.
6546
6547 \layout List
6548 \labelwidthstring 00.00.0000
6549
6550 \series bold
6551 -
6552 \begin_inset ERT
6553 status Collapsed
6554
6555 \layout Standard
6556
6557
6558 \backslash
6559 /
6560
6561 \end_inset
6562
6563 -code-loc
6564 \series default
6565
6566 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6567
6568 \end_inset
6569
6570 \SpecialChar ~
6571 <Value> The start location of the code
6572 \begin_inset LatexCommand \index{code}
6573
6574 \end_inset
6575
6576  segment, default value 0.
6577  Note when this option is used the interrupt vector table
6578 \begin_inset LatexCommand \index{interrupt vector table}
6579
6580 \end_inset
6581
6582  is also relocated to the given address.
6583  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6584 \begin_inset ERT
6585 status Collapsed
6586
6587 \layout Standard
6588
6589
6590 \backslash
6591 /
6592
6593 \end_inset
6594
6595 -code-loc 0x8000 or -
6596 \begin_inset ERT
6597 status Collapsed
6598
6599 \layout Standard
6600
6601
6602 \backslash
6603 /
6604
6605 \end_inset
6606
6607 -code-loc 32768.
6608
6609 \layout List
6610 \labelwidthstring 00.00.0000
6611
6612 \series bold
6613 -
6614 \begin_inset ERT
6615 status Collapsed
6616
6617 \layout Standard
6618
6619
6620 \backslash
6621 /
6622
6623 \end_inset
6624
6625 -stack-loc
6626 \series default
6627
6628 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6629
6630 \end_inset
6631
6632 \SpecialChar ~
6633 <Value> By default the stack
6634 \begin_inset LatexCommand \index{stack}
6635
6636 \end_inset
6637
6638  is placed after the data segment.
6639  Using this option the stack can be placed anywhere in the internal memory
6640  space of the 8051.
6641  The value entered can be in Hexadecimal or Decimal format, e.g.
6642  -
6643 \begin_inset ERT
6644 status Collapsed
6645
6646 \layout Standard
6647
6648
6649 \backslash
6650 /
6651
6652 \end_inset
6653
6654 -stack-loc 0x20 or -
6655 \begin_inset ERT
6656 status Collapsed
6657
6658 \layout Standard
6659
6660
6661 \backslash
6662 /
6663
6664 \end_inset
6665
6666 -stack-loc 32.
6667  Since the sp register is incremented before a push or call, the initial
6668  sp will be set to one byte prior the provided value.
6669  The provided value should not overlap any other memory areas such as used
6670  register banks or the data segment and with enough space for the current
6671  application.
6672  The 
6673 \series bold
6674 -
6675 \begin_inset ERT
6676 status Collapsed
6677
6678 \layout Standard
6679
6680
6681 \backslash
6682 /
6683
6684 \end_inset
6685
6686 -pack-iram
6687 \series default
6688 \SpecialChar ~
6689
6690 \begin_inset LatexCommand \index{-\/-pack-iram}
6691
6692 \end_inset
6693
6694  option (which is now a default setting) will override this setting, so
6695  you should also specify the 
6696 \series bold
6697 -
6698 \begin_inset ERT
6699 status Collapsed
6700
6701 \layout Standard
6702
6703
6704 \backslash
6705 /
6706
6707 \end_inset
6708
6709 -no-pack-iram
6710 \series default
6711 \SpecialChar ~
6712
6713 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6714
6715 \end_inset
6716
6717  option if you need to manually place the stack.
6718
6719 \layout List
6720 \labelwidthstring 00.00.0000
6721
6722 \series bold
6723 -
6724 \begin_inset ERT
6725 status Collapsed
6726
6727 \layout Standard
6728
6729
6730 \backslash
6731 /
6732
6733 \end_inset
6734
6735 -xstack-loc
6736 \series default
6737
6738 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6739
6740 \end_inset
6741
6742 \SpecialChar ~
6743 <Value> By default the external stack
6744 \begin_inset LatexCommand \index{xstack}
6745
6746 \end_inset
6747
6748  is placed after the pdata
6749 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6750
6751 \end_inset
6752
6753  segment.
6754  Using this option the xstack can be placed anywhere in the external memory
6755  space of the 8051.
6756  The value entered can be in Hexadecimal or Decimal format, e.g.
6757  -
6758 \begin_inset ERT
6759 status Collapsed
6760
6761 \layout Standard
6762
6763
6764 \backslash
6765 /
6766
6767 \end_inset
6768
6769 -xstack-loc 0x8000 or -
6770 \begin_inset ERT
6771 status Collapsed
6772
6773 \layout Standard
6774
6775
6776 \backslash
6777 /
6778
6779 \end_inset
6780
6781 -stack-loc 32768.
6782  The provided value should not overlap any other memory areas such as the
6783  pdata or xdata segment and with enough space for the current application.
6784
6785 \layout List
6786 \labelwidthstring 00.00.0000
6787
6788 \series bold
6789 -
6790 \begin_inset ERT
6791 status Collapsed
6792
6793 \layout Standard
6794
6795
6796 \backslash
6797 /
6798
6799 \end_inset
6800
6801 -data-loc
6802 \series default
6803
6804 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6805
6806 \end_inset
6807
6808 \SpecialChar ~
6809 <Value> The start location of the internal ram data
6810 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6811
6812 \end_inset
6813
6814  segment.
6815  The value entered can be in Hexadecimal or Decimal format, eg.
6816  -
6817 \begin_inset ERT
6818 status Collapsed
6819
6820 \layout Standard
6821
6822
6823 \backslash
6824 /
6825
6826 \end_inset
6827
6828 -data-loc 0x20 or -
6829 \begin_inset ERT
6830 status Collapsed
6831
6832 \layout Standard
6833
6834
6835 \backslash
6836 /
6837
6838 \end_inset
6839
6840 -data-loc 32.
6841  (By default, the start location of the internal ram data segment  is set
6842  as low as possible in memory, taking into account the used register banks
6843  and the bit segment at address 0x20.
6844  For example if register banks 0 and 1 are used without bit variables, the
6845  data segment will be set, if -
6846 \begin_inset ERT
6847 status Collapsed
6848
6849 \layout Standard
6850
6851
6852 \backslash
6853 /
6854
6855 \end_inset
6856
6857 -data-loc is not used, to location 0x10.)
6858
6859 \layout List
6860 \labelwidthstring 00.00.0000
6861
6862 \series bold
6863 -
6864 \begin_inset ERT
6865 status Collapsed
6866
6867 \layout Standard
6868
6869
6870 \backslash
6871 /
6872
6873 \end_inset
6874
6875 -idata-loc
6876 \series default
6877
6878 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6879
6880 \end_inset
6881
6882 \SpecialChar ~
6883 <Value> The start location of the indirectly addressable internal ram
6884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6885
6886 \end_inset
6887
6888  of the 8051, default value is 0x80.
6889  The value entered can be in Hexadecimal or Decimal format, eg.
6890  -
6891 \begin_inset ERT
6892 status Collapsed
6893
6894 \layout Standard
6895
6896
6897 \backslash
6898 /
6899
6900 \end_inset
6901
6902 -idata-loc 0x88 or -
6903 \begin_inset ERT
6904 status Collapsed
6905
6906 \layout Standard
6907
6908
6909 \backslash
6910 /
6911
6912 \end_inset
6913
6914 -idata-loc 136.
6915
6916 \layout List
6917 \labelwidthstring 00.00.0000
6918
6919 \series bold
6920 -
6921 \begin_inset ERT
6922 status Collapsed
6923
6924 \layout Standard
6925
6926
6927 \backslash
6928 /
6929
6930 \end_inset
6931
6932 -bit-loc
6933 \series default
6934 \SpecialChar ~
6935 <Value> The start location of the bit
6936 \begin_inset LatexCommand \index{bit}
6937
6938 \end_inset
6939
6940  addressable internal ram of the 8051.
6941  This is 
6942 \emph on
6943 not
6944 \emph default
6945  implemented yet.
6946  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6947 -bBSEG=<Value>.
6948
6949 \layout List
6950 \labelwidthstring 00.00.0000
6951
6952 \series bold
6953 -
6954 \begin_inset ERT
6955 status Collapsed
6956
6957 \layout Standard
6958
6959
6960 \backslash
6961 /
6962
6963 \end_inset
6964
6965 -out-fmt-ihx
6966 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6967
6968 \end_inset
6969
6970
6971 \bar under
6972  
6973 \series default
6974 \bar default
6975 The linker output (final object code) is in Intel Hex format.
6976 \begin_inset LatexCommand \index{Intel hex format}
6977
6978 \end_inset
6979
6980  This is the default option.
6981  The format itself is documented in the documentation of srecord
6982 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6983
6984 \end_inset
6985
6986 .
6987
6988 \layout List
6989 \labelwidthstring 00.00.0000
6990
6991 \series bold
6992 -
6993 \begin_inset ERT
6994 status Collapsed
6995
6996 \layout Standard
6997
6998
6999 \backslash
7000 /
7001
7002 \end_inset
7003
7004 -out-fmt-s19
7005 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7006
7007 \end_inset
7008
7009
7010 \bar under
7011  
7012 \series default
7013 \bar default
7014 The linker output (final object code) is in Motorola S19 format
7015 \begin_inset LatexCommand \index{Motorola S19 format}
7016
7017 \end_inset
7018
7019 .
7020  The format itself is documented in the documentation of srecord.
7021
7022 \layout List
7023 \labelwidthstring 00.00.0000
7024
7025 \series bold
7026 -
7027 \begin_inset ERT
7028 status Collapsed
7029
7030 \layout Standard
7031
7032
7033 \backslash
7034 /
7035
7036 \end_inset
7037
7038 -out-fmt-elf
7039 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7040
7041 \end_inset
7042
7043
7044 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7045
7046 \end_inset
7047
7048
7049 \bar under
7050  
7051 \series default
7052 \bar default
7053 The linker output (final object code) is in ELF format
7054 \begin_inset LatexCommand \index{ELF format}
7055
7056 \end_inset
7057
7058 .
7059  (Currently only supported for the HC08
7060 \begin_inset LatexCommand \index{HC08}
7061
7062 \end_inset
7063
7064  processors)
7065
7066 \layout List
7067 \labelwidthstring 00.00.0000
7068 \added_space_bottom bigskip 
7069
7070 \series bold
7071 -Wl\SpecialChar ~
7072 linkOption[,linkOption]
7073 \series default
7074
7075 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7076
7077 \end_inset
7078
7079 ...
7080  Pass the linkOption to the linker.
7081  If a bootloader is used an option like 
7082 \begin_inset Quotes sld
7083 \end_inset
7084
7085 -Wl\SpecialChar ~
7086 -bCSEG=0x1000
7087 \begin_inset Quotes srd
7088 \end_inset
7089
7090  would be typical to set the start of the code segment.
7091  See also #pragma constseg and #pragma codeseg in section 
7092 \begin_inset LatexCommand \ref{sec:Pragmas}
7093
7094 \end_inset
7095
7096  .
7097  File sdcc/as/doc/asxhtm.html has more on linker options.
7098
7099
7100 \layout Subsection
7101 MCS51 Options
7102 \begin_inset LatexCommand \index{Options MCS51}
7103
7104 \end_inset
7105
7106
7107 \begin_inset LatexCommand \index{MCS51 options}
7108
7109 \end_inset
7110
7111
7112
7113 \layout List
7114 \labelwidthstring 00.00.0000
7115
7116 \series bold
7117 -
7118 \begin_inset ERT
7119 status Collapsed
7120
7121 \layout Standard
7122
7123
7124 \backslash
7125 /
7126
7127 \end_inset
7128
7129 -model-small
7130 \begin_inset LatexCommand \index{-\/-model-small}
7131
7132 \end_inset
7133
7134
7135 \series default
7136 \size large
7137 \emph on
7138  
7139 \size default
7140 \emph default
7141 Generate code for Small Model programs, see section Memory Models for more
7142  details.
7143  This is the default model.
7144
7145 \layout List
7146 \labelwidthstring 00.00.0000
7147
7148 \series bold
7149 -
7150 \begin_inset ERT
7151 status Collapsed
7152
7153 \layout Standard
7154
7155
7156 \backslash
7157 /
7158
7159 \end_inset
7160
7161 -model-medium
7162 \begin_inset LatexCommand \index{-\/-model-medium}
7163
7164 \end_inset
7165
7166
7167 \series default
7168  Generate code for Medium model programs, see section Memory Models for
7169  more details.
7170  If this option is used all source files in the project have to be compiled
7171  with this option.
7172  It must also be used when invoking the linker.
7173
7174 \layout List
7175 \labelwidthstring 00.00.0000
7176
7177 \series bold
7178 -
7179 \begin_inset ERT
7180 status Collapsed
7181
7182 \layout Standard
7183
7184
7185 \backslash
7186 /
7187
7188 \end_inset
7189
7190 -model-large
7191 \begin_inset LatexCommand \index{-\/-model-large}
7192
7193 \end_inset
7194
7195
7196 \series default
7197  Generate code for Large model programs, see section Memory Models for more
7198  details.
7199  If this option is used all source files in the project have to be compiled
7200  with this option.
7201  It must also be used when invoking the linker.
7202
7203 \layout List
7204 \labelwidthstring 00.00.0000
7205
7206 \series bold
7207 -
7208 \begin_inset ERT
7209 status Collapsed
7210
7211 \layout Standard
7212
7213
7214 \backslash
7215 /
7216
7217 \end_inset
7218
7219 -xstack
7220 \begin_inset LatexCommand \index{-\/-xstack}
7221
7222 \end_inset
7223
7224
7225 \series default
7226  Uses a pseudo stack in the pdata
7227 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7228
7229 \end_inset
7230
7231  area (usually the first 256 bytes in the external ram) for allocating variables
7232  and passing parameters.
7233  See section 
7234 \begin_inset LatexCommand \ref{sub:External-Stack}
7235
7236 \end_inset
7237
7238 \SpecialChar ~
7239  External Stack for more details.
7240
7241 \layout List
7242 \labelwidthstring 00.00.0000
7243
7244 \series bold
7245 -
7246 \begin_inset ERT
7247 status Collapsed
7248
7249 \layout Standard
7250
7251
7252 \backslash
7253 /
7254
7255 \end_inset
7256
7257 -iram-size
7258 \series default
7259 \SpecialChar ~
7260 <Value>
7261 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7262
7263 \end_inset
7264
7265  Causes the linker to check if the internal ram usage is within limits of
7266  the given value.
7267
7268 \layout List
7269 \labelwidthstring 00.00.0000
7270
7271 \series bold
7272 -
7273 \begin_inset ERT
7274 status Collapsed
7275
7276 \layout Standard
7277
7278
7279 \backslash
7280 /
7281
7282 \end_inset
7283
7284 -xram-size
7285 \series default
7286 \SpecialChar ~
7287 <Value>
7288 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7289
7290 \end_inset
7291
7292  Causes the linker to check if the external ram usage is within limits of
7293  the given value.
7294
7295 \layout List
7296 \labelwidthstring 00.00.0000
7297
7298 \series bold
7299 -
7300 \begin_inset ERT
7301 status Collapsed
7302
7303 \layout Standard
7304
7305
7306 \backslash
7307 /
7308
7309 \end_inset
7310
7311 -code-size
7312 \series default
7313 \SpecialChar ~
7314 <Value>
7315 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7316
7317 \end_inset
7318
7319  Causes the linker to check if the code memory usage is within limits of
7320  the given value.
7321
7322 \layout List
7323 \labelwidthstring 00.00.0000
7324
7325 \series bold
7326 -
7327 \begin_inset ERT
7328 status Collapsed
7329
7330 \layout Standard
7331
7332
7333 \backslash
7334 /
7335
7336 \end_inset
7337
7338 -stack-size
7339 \series default
7340 \SpecialChar ~
7341 <Value>
7342 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7343
7344 \end_inset
7345
7346  Causes the linker to check if there is at minimum <Value> bytes for stack.
7347
7348 \layout List
7349 \labelwidthstring 00.00.0000
7350
7351 \series bold
7352 -
7353 \begin_inset ERT
7354 status Collapsed
7355
7356 \layout Standard
7357
7358
7359 \backslash
7360 /
7361
7362 \end_inset
7363
7364 -pack-iram
7365 \series default
7366 \SpecialChar ~
7367
7368 \begin_inset LatexCommand \index{-\/-pack-iram}
7369
7370 \end_inset
7371
7372  Causes the linker to use unused register banks for data variables and pack
7373  data, idata and stack together.
7374  This is the default now.
7375
7376 \layout List
7377 \labelwidthstring 00.00.0000
7378 \added_space_bottom bigskip 
7379
7380 \series bold
7381 -
7382 \begin_inset ERT
7383 status Collapsed
7384
7385 \layout Standard
7386
7387
7388 \backslash
7389 /
7390
7391 \end_inset
7392
7393 -no-pack-iram
7394 \series default
7395 \SpecialChar ~
7396
7397 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7398
7399 \end_inset
7400
7401  Causes the linker to use old style for allocating memory areas.
7402
7403
7404 \layout Subsection
7405 DS390 / DS400 Options
7406 \begin_inset LatexCommand \index{Options DS390}
7407
7408 \end_inset
7409
7410
7411 \begin_inset LatexCommand \index{DS390}
7412
7413 \end_inset
7414
7415
7416
7417 \layout List
7418 \labelwidthstring 00.00.0000
7419
7420 \series bold
7421 -
7422 \begin_inset ERT
7423 status Collapsed
7424
7425 \layout Standard
7426
7427
7428 \backslash
7429 /
7430
7431 \end_inset
7432
7433 -model-flat24
7434 \series default
7435
7436 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7437
7438 \end_inset
7439
7440
7441 \size large
7442 \emph on
7443  
7444 \size default
7445 \emph default
7446 Generate 24-bit flat mode code.
7447  This is the one and only that the ds390 code generator supports right now
7448  and is default when using 
7449 \emph on
7450 -mds390
7451 \emph default
7452 .
7453  See section Memory Models for more details.
7454
7455 \layout List
7456 \labelwidthstring 00.00.0000
7457
7458 \series bold
7459 -
7460 \begin_inset ERT
7461 status Collapsed
7462
7463 \layout Standard
7464
7465
7466 \backslash
7467 /
7468
7469 \end_inset
7470
7471 -protect-sp-update
7472 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7473
7474 \end_inset
7475
7476
7477 \series default
7478  disable interrupts during ESP:SP updates.
7479
7480 \layout List
7481 \labelwidthstring 00.00.0000
7482
7483 \series bold
7484 -
7485 \begin_inset ERT
7486 status Collapsed
7487
7488 \layout Standard
7489
7490
7491 \backslash
7492 /
7493
7494 \end_inset
7495
7496 -stack-10bit
7497 \series default
7498
7499 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7500
7501 \end_inset
7502
7503  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7504  This is the one and only that the ds390 code generator supports right now
7505  and is default when using 
7506 \emph on
7507 -mds390
7508 \emph default
7509 .
7510  In this mode, the stack is located in the lower 1K of the internal RAM,
7511  which is mapped to 0x400000.
7512  Note that the support is incomplete, since it still uses a single byte
7513  as the stack pointer.
7514  This means that only the lower 256 bytes of the potential 1K stack space
7515  will actually be used.
7516  However, this does allow you to reclaim the precious 256 bytes of low RAM
7517  for use for the DATA and IDATA segments.
7518  The compiler will not generate any code to put the processor into 10 bit
7519  stack mode.
7520  It is important to ensure that the processor is in this mode before calling
7521  any re-entrant functions compiled with this option.
7522  In principle, this should work with the 
7523 \emph on
7524 -
7525 \begin_inset ERT
7526 status Collapsed
7527
7528 \layout Standard
7529
7530
7531 \backslash
7532 /
7533
7534 \end_inset
7535
7536 -stack-auto
7537 \begin_inset LatexCommand \index{-\/-stack-auto}
7538
7539 \end_inset
7540
7541
7542 \emph default
7543  option, but that has not been tested.
7544  It is incompatible with the 
7545 \emph on
7546 -
7547 \begin_inset ERT
7548 status Collapsed
7549
7550 \layout Standard
7551
7552
7553 \backslash
7554 /
7555
7556 \end_inset
7557
7558 -xstack
7559 \begin_inset LatexCommand \index{-\/-xstack}
7560
7561 \end_inset
7562
7563
7564 \emph default
7565  option.
7566  It also only makes sense if the processor is in 24 bit contiguous addressing
7567  mode (see the 
7568 \emph on
7569 -
7570 \begin_inset ERT
7571 status Collapsed
7572
7573 \layout Standard
7574
7575
7576 \backslash
7577 /
7578
7579 \end_inset
7580
7581 -model-flat24 option
7582 \emph default
7583 ).
7584
7585 \layout List
7586 \labelwidthstring 00.00.0000
7587
7588 \series bold
7589 -
7590 \begin_inset ERT
7591 status Collapsed
7592
7593 \layout Standard
7594
7595
7596 \backslash
7597 /
7598
7599 \end_inset
7600
7601 -stack-probe
7602 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7603
7604 \end_inset
7605
7606
7607 \series default
7608  insert call to function __stack_probe at each function prologue.
7609
7610 \layout List
7611 \labelwidthstring 00.00.0000
7612
7613 \series bold
7614 -
7615 \begin_inset ERT
7616 status Collapsed
7617
7618 \layout Standard
7619
7620
7621 \backslash
7622 /
7623
7624 \end_inset
7625
7626 -tini-libid
7627 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7628
7629 \end_inset
7630
7631
7632 \series default
7633  <nnnn> LibraryID used in -mTININative.
7634  
7635
7636 \layout List
7637 \labelwidthstring 00.00.0000
7638 \added_space_bottom bigskip 
7639
7640 \series bold
7641 -
7642 \begin_inset ERT
7643 status Collapsed
7644
7645 \layout Standard
7646
7647
7648 \backslash
7649 /
7650
7651 \end_inset
7652
7653 -use-accelerator
7654 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7655
7656 \end_inset
7657
7658
7659 \series default
7660  generate code for DS390 Arithmetic Accelerator.
7661  
7662
7663
7664 \layout Subsection
7665 Z80 Options
7666 \begin_inset LatexCommand \index{Options Z80}
7667
7668 \end_inset
7669
7670
7671 \begin_inset LatexCommand \index{Z80}
7672
7673 \end_inset
7674
7675
7676
7677 \layout List
7678 \labelwidthstring 00.00.0000
7679
7680 \series bold
7681 -
7682 \begin_inset ERT
7683 status Collapsed
7684
7685 \layout Standard
7686
7687
7688 \backslash
7689 /
7690
7691 \end_inset
7692
7693 -callee-saves-bc
7694 \series default
7695
7696 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7697
7698 \end_inset
7699
7700
7701 \size large
7702 \emph on
7703  
7704 \size default
7705 \emph default
7706 Force a called function to always save BC.
7707
7708 \layout List
7709 \labelwidthstring 00.00.0000
7710 \added_space_bottom bigskip 
7711
7712 \series bold
7713 -
7714 \begin_inset ERT
7715 status Collapsed
7716
7717 \layout Standard
7718
7719
7720 \backslash
7721 /
7722
7723 \end_inset
7724
7725 -no-std-crt0
7726 \series default
7727
7728 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7729
7730 \end_inset
7731
7732  When linking, skip the standard crt0.o object file.
7733  You must provide your own crt0.o for your system when linking.
7734  
7735
7736
7737 \layout Subsection
7738 Optimization Options
7739 \begin_inset LatexCommand \index{Options optimization}
7740
7741 \end_inset
7742
7743
7744 \begin_inset LatexCommand \index{Optimization options}
7745
7746 \end_inset
7747
7748
7749
7750 \layout List
7751 \labelwidthstring 00.00.0000
7752
7753 \series bold
7754 -
7755 \begin_inset ERT
7756 status Collapsed
7757
7758 \layout Standard
7759
7760
7761 \backslash
7762 /
7763
7764 \end_inset
7765
7766 -nogcse
7767 \begin_inset LatexCommand \index{-\/-nogcse}
7768
7769 \end_inset
7770
7771
7772 \series default
7773  Will not do global subexpression elimination, this option may be used when
7774  the compiler creates undesirably large stack/data spaces to store compiler
7775  temporaries (
7776 \emph on
7777 s
7778 \emph default
7779 pill 
7780 \emph on
7781 loc
7782 \emph default
7783 ations, sloc
7784 \begin_inset LatexCommand \index{sloc (spill location)}
7785
7786 \end_inset
7787
7788 ).
7789  A warning message will be generated when this happens and the compiler
7790  will indicate the number of extra bytes it allocated.
7791  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7792 nogcse
7793 \begin_inset LatexCommand \index{\#pragma nogcse}
7794
7795 \end_inset
7796
7797  can be used to turn off global subexpression elimination
7798 \begin_inset LatexCommand \index{Subexpression elimination}
7799
7800 \end_inset
7801
7802  for a given function only.
7803
7804 \layout List
7805 \labelwidthstring 00.00.0000
7806
7807 \series bold
7808 -
7809 \begin_inset ERT
7810 status Collapsed
7811
7812 \layout Standard
7813
7814
7815 \backslash
7816 /
7817
7818 \end_inset
7819
7820 -noinvariant
7821 \begin_inset LatexCommand \index{-\/-noinvariant}
7822
7823 \end_inset
7824
7825
7826 \series default
7827  Will not do loop invariant optimizations, this may be turned off for reasons
7828  explained for the previous option.
7829  For more details of loop optimizations performed see Loop Invariants in
7830  section 
7831 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7832
7833 \end_inset
7834
7835 .
7836  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7837 noinvariant
7838 \begin_inset LatexCommand \index{\#pragma noinvariant}
7839
7840 \end_inset
7841
7842  can be used to turn off invariant optimizations for a given function only.
7843
7844 \layout List
7845 \labelwidthstring 00.00.0000
7846
7847 \series bold
7848 -
7849 \begin_inset ERT
7850 status Collapsed
7851
7852 \layout Standard
7853
7854
7855 \backslash
7856 /
7857
7858 \end_inset
7859
7860 -noinduction
7861 \begin_inset LatexCommand \index{-\/-noinduction}
7862
7863 \end_inset
7864
7865
7866 \series default
7867  Will not do loop induction optimizations, see section strength reduction
7868  for more details.
7869  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7870 noinduction
7871 \begin_inset LatexCommand \index{\#pragma noinduction}
7872
7873 \end_inset
7874
7875  can be used to turn off induction optimizations for a given function only.
7876
7877 \layout List
7878 \labelwidthstring 00.00.0000
7879
7880 \series bold
7881 -
7882 \begin_inset ERT
7883 status Collapsed
7884
7885 \layout Standard
7886
7887
7888 \backslash
7889 /
7890
7891 \end_inset
7892
7893 -nojtbound
7894 \begin_inset LatexCommand \index{-\/-nojtbound}
7895
7896 \end_inset
7897
7898
7899 \size large
7900 \bar under
7901  
7902 \series default
7903 \size default
7904 \bar default
7905  Will not generate boundary condition check when switch statements
7906 \begin_inset LatexCommand \index{switch statement}
7907
7908 \end_inset
7909
7910  are implemented using jump-tables.
7911  See section 
7912 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7913
7914 \end_inset
7915
7916 \SpecialChar ~
7917 Switch Statements for more details.
7918  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7919 nojtbound
7920 \begin_inset LatexCommand \index{\#pragma nojtbound}
7921
7922 \end_inset
7923
7924  can be used to turn off boundary checking for jump tables for a given function
7925  only.
7926
7927 \layout List
7928 \labelwidthstring 00.00.0000
7929
7930 \series bold
7931 -
7932 \begin_inset ERT
7933 status Collapsed
7934
7935 \layout Standard
7936
7937
7938 \backslash
7939 /
7940
7941 \end_inset
7942
7943 -noloopreverse
7944 \begin_inset LatexCommand \index{-\/-noloopreverse}
7945
7946 \end_inset
7947
7948
7949 \series default
7950 \size large
7951  
7952 \size default
7953 Will not do loop reversal 
7954 \begin_inset LatexCommand \index{Loop reversing}
7955
7956 \end_inset
7957
7958 optimization.
7959
7960 \layout List
7961 \labelwidthstring 00.00.0000
7962 -
7963 \begin_inset ERT
7964 status Collapsed
7965
7966 \layout Standard
7967
7968
7969 \backslash
7970 /
7971
7972 \end_inset
7973
7974 -
7975 \series bold
7976 nolabelopt
7977 \series default
7978  
7979 \begin_inset LatexCommand \index{-\/-nolabelopt }
7980
7981 \end_inset
7982
7983 Will not optimize labels (makes the dumpfiles more readable).
7984
7985 \layout List
7986 \labelwidthstring 00.00.0000
7987
7988 \series bold
7989 -
7990 \begin_inset ERT
7991 status Collapsed
7992
7993 \layout Standard
7994
7995
7996 \backslash
7997 /
7998
7999 \end_inset
8000
8001 -no-xinit-opt
8002 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8003
8004 \end_inset
8005
8006
8007 \series default
8008  Will not memcpy initialized data from code space into xdata space.
8009  This saves a few bytes in code space if you don't have initialized data
8010 \begin_inset LatexCommand \index{Variable initialization}
8011
8012 \end_inset
8013
8014 .
8015
8016 \layout List
8017 \labelwidthstring 00.00.0000
8018
8019 \series bold
8020 -
8021 \begin_inset ERT
8022 status Collapsed
8023
8024 \layout Standard
8025
8026
8027 \backslash
8028 /
8029
8030 \end_inset
8031
8032 -nooverlay
8033 \begin_inset LatexCommand \index{-\/-nooverlay}
8034
8035 \end_inset
8036
8037
8038 \series default
8039   The compiler will not overlay parameters and local variables of any function,
8040  see section Parameters and local variables for more details.
8041
8042 \layout List
8043 \labelwidthstring 00.00.0000
8044
8045 \series bold
8046 -
8047 \begin_inset ERT
8048 status Collapsed
8049
8050 \layout Standard
8051
8052
8053 \backslash
8054 /
8055
8056 \end_inset
8057
8058 -no-peep
8059 \begin_inset LatexCommand \index{-\/-no-peep}
8060
8061 \end_inset
8062
8063
8064 \series default
8065  Disable peep-hole optimization with built-in rules.
8066
8067 \layout List
8068 \labelwidthstring 00.00.0000
8069
8070 \series bold
8071 -
8072 \begin_inset ERT
8073 status Collapsed
8074
8075 \layout Standard
8076
8077
8078 \backslash
8079 /
8080
8081 \end_inset
8082
8083 -peep-file
8084 \series default
8085
8086 \begin_inset LatexCommand \index{-\/-peep-file}
8087
8088 \end_inset
8089
8090 \SpecialChar ~
8091 <filename> This option can be used to use additional rules to be used by
8092  the peep hole optimizer.
8093  See section 
8094 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8095
8096 \end_inset
8097
8098 \SpecialChar ~
8099 Peep Hole optimizations for details on how to write these rules.
8100
8101 \layout List
8102 \labelwidthstring 00.00.0000
8103
8104 \series bold
8105 -
8106 \begin_inset ERT
8107 status Collapsed
8108
8109 \layout Standard
8110
8111
8112 \backslash
8113 /
8114
8115 \end_inset
8116
8117 -peep-asm
8118 \begin_inset LatexCommand \index{-\/-peep-asm}
8119
8120 \end_inset
8121
8122
8123 \series default
8124  Pass the inline assembler code through the peep hole optimizer.
8125  This can cause unexpected changes to inline assembler code, please go through
8126  the peephole optimizer
8127 \begin_inset LatexCommand \index{Peephole optimizer}
8128
8129 \end_inset
8130
8131  rules defined in the source file tree '<target>/peeph.def' before using
8132  this option.
8133
8134 \layout List
8135 \labelwidthstring 00.00.0000
8136
8137 \series bold
8138 -
8139 \begin_inset ERT
8140 status Collapsed
8141
8142 \layout Standard
8143
8144
8145 \backslash
8146 /
8147
8148 \end_inset
8149
8150 -opt-code-speed
8151 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8152
8153 \end_inset
8154
8155
8156 \series default
8157  The compiler will optimize code generation towards fast code, possibly
8158  at the expense of code size.
8159
8160 \layout List
8161 \labelwidthstring 00.00.0000
8162 \added_space_bottom bigskip 
8163
8164 \series bold
8165 -
8166 \begin_inset ERT
8167 status Collapsed
8168
8169 \layout Standard
8170
8171
8172 \backslash
8173 /
8174
8175 \end_inset
8176
8177 -opt-code-size
8178 \begin_inset LatexCommand \index{-\/-opt-code-size}
8179
8180 \end_inset
8181
8182
8183 \series default
8184  The compiler will optimize code generation towards compact code, possibly
8185  at the expense of code speed.
8186
8187
8188 \layout Subsection
8189 Other Options
8190 \begin_inset LatexCommand \index{Options other}
8191
8192 \end_inset
8193
8194
8195
8196 \layout List
8197 \labelwidthstring 00.00.0000
8198
8199 \series bold
8200 -c\SpecialChar ~
8201 -
8202 \begin_inset ERT
8203 status Collapsed
8204
8205 \layout Standard
8206
8207
8208 \backslash
8209 /
8210
8211 \end_inset
8212
8213 -compile-only
8214 \begin_inset LatexCommand \index{-\/-compile-only}
8215
8216 \end_inset
8217
8218
8219 \begin_inset LatexCommand \index{-c -\/-compile-only}
8220
8221 \end_inset
8222
8223
8224 \series default
8225  will compile and assemble the source, but will not call the linkage editor.
8226
8227 \layout List
8228 \labelwidthstring 00.00.0000
8229
8230 \series bold
8231 -
8232 \series default
8233
8234 \begin_inset ERT
8235 status Collapsed
8236
8237 \layout Standard
8238
8239
8240 \backslash
8241 /
8242
8243 \end_inset
8244
8245
8246 \series bold
8247 -c1mode
8248 \begin_inset LatexCommand \index{-\/-c1mode}
8249
8250 \end_inset
8251
8252
8253 \series default
8254  reads the preprocessed source from standard input and compiles it.
8255  The file name for the assembler output must be specified using the -o option.
8256
8257 \layout List
8258 \labelwidthstring 00.00.0000
8259
8260 \series bold
8261 -E
8262 \begin_inset LatexCommand \index{-E}
8263
8264 \end_inset
8265
8266
8267 \series default
8268  Run only the C preprocessor.
8269  Preprocess all the C source files specified and output the results to standard
8270  output.
8271
8272 \layout List
8273 \labelwidthstring 00.00.0000
8274
8275 \series bold
8276 -o\SpecialChar ~
8277 <path/file>
8278 \begin_inset LatexCommand \index{-o <path/file>}
8279
8280 \end_inset
8281
8282  
8283 \series default
8284 The output path resp.
8285  file where everything will be placed.
8286  If the parameter is a path, it must have a trailing slash (or backslash
8287  for the Windows binaries) to be recognized as a path.
8288  
8289
8290 \layout List
8291 \labelwidthstring 00.00.0000
8292
8293 \series bold
8294 -
8295 \begin_inset ERT
8296 status Collapsed
8297
8298 \layout Standard
8299
8300
8301 \backslash
8302 /
8303
8304 \end_inset
8305
8306 -stack-auto
8307 \begin_inset LatexCommand \index{-\/-stack-auto}
8308
8309 \end_inset
8310
8311
8312 \series default
8313 \size large
8314 \emph on
8315  
8316 \size default
8317 \emph default
8318 All functions in the source file will be compiled as 
8319 \emph on
8320 reentrant
8321 \emph default
8322
8323 \begin_inset LatexCommand \index{reentrant}
8324
8325 \end_inset
8326
8327 , i.e.
8328  the parameters and local variables will be allocated on the stack
8329 \begin_inset LatexCommand \index{stack}
8330
8331 \end_inset
8332
8333 .
8334  See section 
8335 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8336
8337 \end_inset
8338
8339  Parameters and Local Variables for more details.
8340  If this option is used all source files in the project should be compiled
8341  with this option.
8342  It automatically implies --int-long-reent and --float-reent.
8343  
8344
8345 \layout List
8346 \labelwidthstring 00.00.0000
8347
8348 \series bold
8349 -
8350 \begin_inset ERT
8351 status Collapsed
8352
8353 \layout Standard
8354
8355
8356 \backslash
8357 /
8358
8359 \end_inset
8360
8361 -callee-saves
8362 \begin_inset LatexCommand \index{-\/-callee-saves}
8363
8364 \end_inset
8365
8366  function1[,function2][,function3]....
8367
8368 \series default
8369  The compiler by default uses a caller saves convention for register saving
8370  across function calls, however this can cause unnecessary register pushing
8371  & popping when calling small functions from larger functions.
8372  This option can be used to switch the register saving convention for the
8373  function names specified.
8374  The compiler will not save registers when calling these functions, no extra
8375  code will be generated at the entry & exit (function prologue
8376 \series bold
8377
8378 \begin_inset LatexCommand \index{function prologue}
8379
8380 \end_inset
8381
8382
8383 \series default
8384  & epilogue
8385 \series bold
8386
8387 \begin_inset LatexCommand \index{function epilogue}
8388
8389 \end_inset
8390
8391
8392 \series default
8393 ) for these functions to save & restore the registers used by these functions,
8394  this can SUBSTANTIALLY reduce code & improve run time performance of the
8395  generated code.
8396  In the future the compiler (with inter procedural analysis) will be able
8397  to determine the appropriate scheme to use for each function call.
8398  DO NOT use this option for built-in functions such as _mulint..., if this
8399  option is used for a library function the appropriate library function
8400  needs to be recompiled with the same option.
8401  If the project consists of multiple source files then all the source file
8402  should be compiled with the same -
8403 \begin_inset ERT
8404 status Collapsed
8405
8406 \layout Standard
8407
8408
8409 \backslash
8410 /
8411
8412 \end_inset
8413
8414 -callee-saves option string.
8415  Also see #pragma\SpecialChar ~
8416 callee_saves
8417 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8418
8419 \end_inset
8420
8421 .
8422
8423 \layout List
8424 \labelwidthstring 00.00.0000
8425
8426 \series bold
8427 -
8428 \begin_inset ERT
8429 status Collapsed
8430
8431 \layout Standard
8432
8433
8434 \backslash
8435 /
8436
8437 \end_inset
8438
8439 -debug
8440 \begin_inset LatexCommand \index{-\/-debug}
8441
8442 \end_inset
8443
8444
8445 \bar under
8446  
8447 \series default
8448 \bar default
8449 When this option is used the compiler will generate debug information.
8450  The debug information collected in a file with .cdb extension can be used
8451  with the SDCDB.
8452  For more information see documentation for SDCDB.
8453  Another file with no extension contains debug information in AOMF or AOMF51
8454 \begin_inset LatexCommand \index{AOMF, AOMF51}
8455
8456 \end_inset
8457
8458  format which is commonly used by third party tools.
8459
8460 \layout List
8461 \labelwidthstring 00.00.0000
8462
8463 \series bold
8464 -S
8465 \begin_inset LatexCommand \index{-S}
8466
8467 \end_inset
8468
8469
8470 \size large
8471 \bar under
8472  
8473 \series default
8474 \size default
8475 \bar default
8476 Stop after the stage of compilation proper; do not assemble.
8477  The output is an assembler code file for the input file specified.
8478
8479 \layout List
8480 \labelwidthstring 00.00.0000
8481
8482 \series bold
8483 -
8484 \begin_inset ERT
8485 status Collapsed
8486
8487 \layout Standard
8488
8489
8490 \backslash
8491 /
8492
8493 \end_inset
8494
8495 -int-long-reent
8496 \begin_inset LatexCommand \index{-\/-int-long-reent}
8497
8498 \end_inset
8499
8500
8501 \series default
8502  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8503  Note by default these libraries are compiled as non-reentrant.
8504  See section Installation for more details.
8505
8506 \layout List
8507 \labelwidthstring 00.00.0000
8508
8509 \series bold
8510 -
8511 \begin_inset ERT
8512 status Collapsed
8513
8514 \layout Standard
8515
8516
8517 \backslash
8518 /
8519
8520 \end_inset
8521
8522 -cyclomatic
8523 \begin_inset LatexCommand \index{-\/-cyclomatic}
8524
8525 \end_inset
8526
8527
8528 \bar under
8529  
8530 \series default
8531 \bar default
8532 This option will cause the compiler to generate an information message for
8533  each function in the source file.
8534  The message contains some 
8535 \emph on
8536 important
8537 \emph default
8538  information about the function.
8539  The number of edges and nodes the compiler detected in the control flow
8540  graph of the function, and most importantly the 
8541 \emph on
8542 cyclomatic complexity
8543 \begin_inset LatexCommand \index{Cyclomatic complexity}
8544
8545 \end_inset
8546
8547
8548 \emph default
8549  see section on Cyclomatic Complexity for more details.
8550
8551 \layout List
8552 \labelwidthstring 00.00.0000
8553
8554 \series bold
8555 -
8556 \begin_inset ERT
8557 status Collapsed
8558
8559 \layout Standard
8560
8561
8562 \backslash
8563 /
8564
8565 \end_inset
8566
8567 -float-reent
8568 \begin_inset LatexCommand \index{-\/-float-reent}
8569
8570 \end_inset
8571
8572
8573 \series default
8574  Floating point library is compiled as reentrant
8575 \begin_inset LatexCommand \index{reentrant}
8576
8577 \end_inset
8578
8579 .
8580  See section Installation for more details.
8581
8582 \layout List
8583 \labelwidthstring 00.00.0000
8584
8585 \series bold
8586 -
8587 \begin_inset ERT
8588 status Collapsed
8589
8590 \layout Standard
8591
8592
8593 \backslash
8594 /
8595
8596 \end_inset
8597
8598 -main-return
8599 \begin_inset LatexCommand \index{-\/-main-return}
8600
8601 \end_inset
8602
8603
8604 \series default
8605  This option can be used if the code generated is called by a monitor program
8606  or if the main routine includes an endless loop.
8607  This option results in slightly smaller code and saves two bytes of stack
8608  space.
8609  The return from the 'main'
8610 \begin_inset LatexCommand \index{main return}
8611
8612 \end_inset
8613
8614  function will return to the function calling main.
8615  The default setting is to lock up i.e.
8616  generate a '
8617 \family typewriter
8618 sjmp .
8619 \family default
8620 '.
8621
8622 \layout List
8623 \labelwidthstring 00.00.0000
8624
8625 \series bold
8626 -
8627 \begin_inset ERT
8628 status Collapsed
8629
8630 \layout Standard
8631
8632
8633 \backslash
8634 /
8635
8636 \end_inset
8637
8638 -nostdinc
8639 \begin_inset LatexCommand \index{-\/-nostdinc}
8640
8641 \end_inset
8642
8643
8644 \series default
8645  This will prevent the compiler from passing on the default include path
8646  to the preprocessor.
8647
8648 \layout List
8649 \labelwidthstring 00.00.0000
8650
8651 \series bold
8652 -
8653 \begin_inset ERT
8654 status Collapsed
8655
8656 \layout Standard
8657
8658
8659 \backslash
8660 /
8661
8662 \end_inset
8663
8664 -nostdlib
8665 \begin_inset LatexCommand \index{-\/-nostdlib}
8666
8667 \end_inset
8668
8669
8670 \series default
8671  This will prevent the compiler from passing on the default library
8672 \begin_inset LatexCommand \index{Libraries}
8673
8674 \end_inset
8675
8676  path to the linker.
8677
8678 \layout List
8679 \labelwidthstring 00.00.0000
8680
8681 \series bold
8682 -
8683 \begin_inset ERT
8684 status Collapsed
8685
8686 \layout Standard
8687
8688
8689 \backslash
8690 /
8691
8692 \end_inset
8693
8694 -verbose
8695 \begin_inset LatexCommand \index{-\/-verbose}
8696
8697 \end_inset
8698
8699
8700 \series default
8701  Shows the various actions the compiler is performing.
8702
8703 \layout List
8704 \labelwidthstring 00.00.0000
8705
8706 \series bold
8707 -V
8708 \begin_inset LatexCommand \index{-V}
8709
8710 \end_inset
8711
8712
8713 \series default
8714  Shows the actual commands the compiler is executing.
8715
8716 \layout List
8717 \labelwidthstring 00.00.0000
8718
8719 \series bold
8720 -
8721 \begin_inset ERT
8722 status Collapsed
8723
8724 \layout Standard
8725
8726
8727 \backslash
8728 /
8729
8730 \end_inset
8731
8732 -no-c-code-in-asm
8733 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8734
8735 \end_inset
8736
8737
8738 \series default
8739  Hides your ugly and inefficient c-code from the asm file, so you can always
8740  blame the compiler :)
8741
8742 \layout List
8743 \labelwidthstring 00.00.0000
8744
8745 \series bold
8746 -
8747 \begin_inset ERT
8748 status Collapsed
8749
8750 \layout Standard
8751
8752
8753 \backslash
8754 /
8755
8756 \end_inset
8757
8758 -no-peep-comments
8759 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8760
8761 \end_inset
8762
8763
8764 \series default
8765  Will not include peep-hole comments in the generated files.
8766
8767 \layout List
8768 \labelwidthstring 00.00.0000
8769
8770 \series bold
8771 -
8772 \begin_inset ERT
8773 status Collapsed
8774
8775 \layout Standard
8776
8777
8778 \backslash
8779 /
8780
8781 \end_inset
8782
8783 -i-code-in-asm
8784 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8785
8786 \end_inset
8787
8788
8789 \series default
8790  Include i-codes in the asm file.
8791  Sounds like noise but is most helpful for debugging the compiler itself.
8792
8793 \layout List
8794 \labelwidthstring 00.00.0000
8795
8796 \series bold
8797 -
8798 \begin_inset ERT
8799 status Collapsed
8800
8801 \layout Standard
8802
8803
8804 \backslash
8805 /
8806
8807 \end_inset
8808
8809 -less-pedantic
8810 \begin_inset LatexCommand \index{-\/-less-pedantic}
8811
8812 \end_inset
8813
8814
8815 \series default
8816  Disable some of the more pedantic warnings
8817 \begin_inset LatexCommand \index{Warnings}
8818
8819 \end_inset
8820
8821  (jwk burps: please be more specific here, please!).
8822
8823 \layout List
8824 \labelwidthstring 00.00.0000
8825
8826 \series bold
8827 -
8828 \begin_inset ERT
8829 status Collapsed
8830
8831 \layout Standard
8832
8833
8834 \backslash
8835 /
8836
8837 \end_inset
8838
8839 -disable-warning\SpecialChar ~
8840 <nnnn>
8841 \begin_inset LatexCommand \index{-\/-disable-warning}
8842
8843 \end_inset
8844
8845
8846 \series default
8847  Disable specific warning with number <nnnn>.
8848
8849 \layout List
8850 \labelwidthstring 00.00.0000
8851
8852 \series bold
8853 -
8854 \begin_inset ERT
8855 status Collapsed
8856
8857 \layout Standard
8858
8859
8860 \backslash
8861 /
8862
8863 \end_inset
8864
8865 -print-search-dirs
8866 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8867
8868 \end_inset
8869
8870
8871 \series default
8872  Display the directories in the compiler's search path
8873
8874 \layout List
8875 \labelwidthstring 00.00.0000
8876
8877 \series bold
8878 -
8879 \begin_inset ERT
8880 status Collapsed
8881
8882 \layout Standard
8883
8884
8885 \backslash
8886 /
8887
8888 \end_inset
8889
8890 -vc
8891 \begin_inset LatexCommand \index{-\/-vc}
8892
8893 \end_inset
8894
8895
8896 \series default
8897  Display errors and warnings using MSVC style, so you can use SDCC with
8898  the visual studio IDE
8899 \begin_inset LatexCommand \index{IDE}
8900
8901 \end_inset
8902
8903 .
8904  With SDCC both offering a GCC-like (the default) and a MSVC-like
8905 \begin_inset LatexCommand \index{MSVC output style}
8906
8907 \end_inset
8908
8909  output style, integration into most programming editors should be straightforwa
8910 rd.
8911
8912 \layout List
8913 \labelwidthstring 00.00.0000
8914
8915 \series bold
8916 -
8917 \begin_inset ERT
8918 status Collapsed
8919
8920 \layout Standard
8921
8922
8923 \backslash
8924 /
8925
8926 \end_inset
8927
8928 -use-stdout
8929 \begin_inset LatexCommand \index{-\/-use-stdout}
8930
8931 \end_inset
8932
8933
8934 \series default
8935  Send errors and warnings to stdout instead of stderr.
8936
8937 \layout List
8938 \labelwidthstring 00.00.0000
8939
8940 \series bold
8941 -Wa\SpecialChar ~
8942 asmOption[,asmOption]
8943 \series default
8944
8945 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8946
8947 \end_inset
8948
8949 ...
8950  Pass the asmOption to the assembler
8951 \begin_inset LatexCommand \index{Options assembler}
8952
8953 \end_inset
8954
8955
8956 \begin_inset LatexCommand \index{Assembler options}
8957
8958 \end_inset
8959
8960 .
8961  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8962
8963 \layout List
8964 \labelwidthstring 00.00.0000
8965
8966 \series bold
8967 -
8968 \begin_inset ERT
8969 status Collapsed
8970
8971 \layout Standard
8972
8973
8974 \backslash
8975 /
8976
8977 \end_inset
8978
8979 -std-sdcc89
8980 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8981
8982 \end_inset
8983
8984
8985 \series default
8986  Generally follow the C89 standard, but allow SDCC features that conflict
8987  with the standard (default).
8988
8989 \layout List
8990 \labelwidthstring 00.00.0000
8991
8992 \series bold
8993 -
8994 \begin_inset ERT
8995 status Collapsed
8996
8997 \layout Standard
8998
8999
9000 \backslash
9001 /
9002
9003 \end_inset
9004
9005 -std-c89
9006 \begin_inset LatexCommand \index{-\/-std-c89}
9007
9008 \end_inset
9009
9010
9011 \series default
9012  Follow the C89 standard and disable SDCC features that conflict with the
9013  standard.
9014
9015 \layout List
9016 \labelwidthstring 00.00.0000
9017
9018 \series bold
9019 -
9020 \begin_inset ERT
9021 status Collapsed
9022
9023 \layout Standard
9024
9025
9026 \backslash
9027 /
9028
9029 \end_inset
9030
9031 -std-sdcc99
9032 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9033
9034 \end_inset
9035
9036
9037 \series default
9038  Generally follow the C99 standard, but allow SDCC features that conflict
9039  with the standard (incomplete support).
9040
9041 \layout List
9042 \labelwidthstring 00.00.0000
9043
9044 \series bold
9045 -
9046 \begin_inset ERT
9047 status Collapsed
9048
9049 \layout Standard
9050
9051
9052 \backslash
9053 /
9054
9055 \end_inset
9056
9057 -std-c99
9058 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9059
9060 \end_inset
9061
9062
9063 \series default
9064  Follow the C99 standard and disable SDCC features that conflict with the
9065  standard (incomplete support).
9066
9067 \layout List
9068 \labelwidthstring 00.00.0000
9069
9070 \series bold
9071 -
9072 \begin_inset ERT
9073 status Collapsed
9074
9075 \layout Standard
9076
9077
9078 \backslash
9079 /
9080
9081 \end_inset
9082
9083 -codeseg
9084 \series default
9085
9086 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9087
9088 \end_inset
9089
9090 \SpecialChar ~
9091 <Name> The name to be used for the code
9092 \begin_inset LatexCommand \index{code}
9093
9094 \end_inset
9095
9096  segment, default CSEG.
9097  This is useful if you need to tell the compiler to put the code in a special
9098  segment so you can later on tell the linker to put this segment in a special
9099  place in memory.
9100  Can be used for instance when using bank switching to put the code in a
9101  bank.
9102
9103 \layout List
9104 \labelwidthstring 00.00.0000
9105
9106 \series bold
9107 -
9108 \begin_inset ERT
9109 status Collapsed
9110
9111 \layout Standard
9112
9113
9114 \backslash
9115 /
9116
9117 \end_inset
9118
9119 -constseg
9120 \series default
9121
9122 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9123
9124 \end_inset
9125
9126 \SpecialChar ~
9127 <Name> The name to be used for the const
9128 \begin_inset LatexCommand \index{code}
9129
9130 \end_inset
9131
9132  segment, default CONST.
9133  This is useful if you need to tell the compiler to put the const data in
9134  a special segment so you can later on tell the linker to put this segment
9135  in a special place in memory.
9136  Can be used for instance when using bank switching to put the const data
9137  in a bank.
9138
9139 \layout List
9140 \labelwidthstring 00.00.0000
9141
9142 \series bold
9143 -
9144 \begin_inset ERT
9145 status Collapsed
9146
9147 \layout Standard
9148
9149
9150 \backslash
9151 /
9152
9153 \end_inset
9154
9155 -fdollars-in-identifiers
9156 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9157
9158 \end_inset
9159
9160
9161 \series default
9162  Permit '$' as an identifier character
9163
9164 \layout List
9165 \labelwidthstring 00.00.0000
9166 \added_space_bottom bigskip 
9167
9168 \series bold
9169 more-pedantic
9170 \series default
9171  Actually this is 
9172 \series bold
9173 \emph on
9174 not
9175 \series default
9176 \emph default
9177  a SDCC compiler option but if you want 
9178 \emph on
9179 more
9180 \emph default
9181  warnings you can use a separate tool dedicated to syntax checking like
9182  splint
9183 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9184
9185 \end_inset
9186
9187
9188 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9189
9190 \end_inset
9191
9192  
9193 \begin_inset LatexCommand \url{http://www.splint.org}
9194
9195 \end_inset
9196
9197 .
9198  To make your source files parseable by splint you will have to include
9199  
9200 \family sans
9201 lint.h
9202 \family default
9203
9204 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9205
9206 \end_inset
9207
9208  in your source file and add brackets around extended keywords (like 
9209 \family sans
9210
9211 \begin_inset Quotes sld
9212 \end_inset
9213
9214 __at\SpecialChar ~
9215
9216 \series bold
9217 (
9218 \series default
9219 0xab
9220 \series bold
9221 )
9222 \series default
9223
9224 \begin_inset Quotes srd
9225 \end_inset
9226
9227
9228 \family default
9229  and 
9230 \family sans
9231
9232 \begin_inset Quotes sld
9233 \end_inset
9234
9235 __interrupt\SpecialChar ~
9236 (2)
9237 \begin_inset Quotes srd
9238 \end_inset
9239
9240
9241 \family default
9242 ).
9243  
9244 \newline
9245 Splint has an excellent on line manual at 
9246 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9247
9248 \end_inset
9249
9250  and it's capabilities go beyond pure syntax checking.
9251  You'll need to tell splint the location of SDCC's include files so a typical
9252  command line could look like this: 
9253 \newline
9254
9255 \family sans
9256 splint\SpecialChar ~
9257 -I\SpecialChar ~
9258 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
9259 \SpecialChar ~
9260 myprogram.c
9261
9262
9263 \layout Subsection
9264 Intermediate Dump Options
9265 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
9266
9267 \end_inset
9268
9269
9270 \begin_inset LatexCommand \index{Options intermediate dump}
9271
9272 \end_inset
9273
9274
9275 \begin_inset LatexCommand \index{Intermediate dump options}
9276
9277 \end_inset
9278
9279
9280
9281 \layout Standard
9282 The following options are provided for the purpose of retargetting and debugging
9283  the compiler.
9284  They provide a means to dump the intermediate code (iCode
9285 \begin_inset LatexCommand \index{iCode}
9286
9287 \end_inset
9288
9289 ) generated by the compiler in human readable form at various stages of
9290  the compilation process.
9291  More on iCodes see chapter 
9292 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9293
9294 \end_inset
9295
9296  
9297 \begin_inset Quotes srd
9298 \end_inset
9299
9300 The anatomy of the compiler
9301 \begin_inset Quotes srd
9302 \end_inset
9303
9304 .
9305
9306 \layout List
9307 \labelwidthstring 00.00.0000
9308
9309 \series bold
9310 -
9311 \begin_inset ERT
9312 status Collapsed
9313
9314 \layout Standard
9315
9316
9317 \backslash
9318 /
9319
9320 \end_inset
9321
9322 -dumpraw
9323 \begin_inset LatexCommand \index{-\/-dumpraw}
9324
9325 \end_inset
9326
9327
9328 \series default
9329  This option will cause the compiler to dump the intermediate code into
9330  a file of named 
9331 \emph on
9332 <source filename>.dumpraw
9333 \emph default
9334  just after the intermediate code has been generated for a function, i.e.
9335  before any optimizations are done.
9336  The basic blocks
9337 \begin_inset LatexCommand \index{Basic blocks}
9338
9339 \end_inset
9340
9341  at this stage ordered in the depth first number, so they may not be in
9342  sequence of execution.
9343
9344 \layout List
9345 \labelwidthstring 00.00.0000
9346
9347 \series bold
9348 -
9349 \begin_inset ERT
9350 status Collapsed
9351
9352 \layout Standard
9353
9354
9355 \backslash
9356 /
9357
9358 \end_inset
9359
9360 -dumpgcse
9361 \begin_inset LatexCommand \index{-\/-dumpgcse}
9362
9363 \end_inset
9364
9365
9366 \series default
9367  Will create a dump of iCode's, after global subexpression elimination
9368 \begin_inset LatexCommand \index{Global subexpression elimination}
9369
9370 \end_inset
9371
9372 , into a file named 
9373 \emph on
9374 <source filename>.dumpgcse.
9375
9376 \layout List
9377 \labelwidthstring 00.00.0000
9378
9379 \series bold
9380 -
9381 \begin_inset ERT
9382 status Collapsed
9383
9384 \layout Standard
9385
9386
9387 \backslash
9388 /
9389
9390 \end_inset
9391
9392 -dumpdeadcode
9393 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9394
9395 \end_inset
9396
9397
9398 \series default
9399  Will create a dump of iCode's, after deadcode elimination
9400 \begin_inset LatexCommand \index{Dead-code elimination}
9401
9402 \end_inset
9403
9404 , into a file named 
9405 \emph on
9406 <source filename>.dumpdeadcode.
9407
9408 \layout List
9409 \labelwidthstring 00.00.0000
9410
9411 \series bold
9412 -
9413 \begin_inset ERT
9414 status Collapsed
9415
9416 \layout Standard
9417
9418
9419 \backslash
9420 /
9421
9422 \end_inset
9423
9424 -dumploop
9425 \begin_inset LatexCommand \index{-\/-dumploop}
9426
9427 \end_inset
9428
9429
9430 \series default
9431 \size large
9432  
9433 \size default
9434 Will create a dump of iCode's, after loop optimizations
9435 \begin_inset LatexCommand \index{Loop optimization}
9436
9437 \end_inset
9438
9439 , into a file named 
9440 \emph on
9441 <source filename>.dumploop.
9442
9443 \layout List
9444 \labelwidthstring 00.00.0000
9445
9446 \series bold
9447 -
9448 \begin_inset ERT
9449 status Collapsed
9450
9451 \layout Standard
9452
9453
9454 \backslash
9455 /
9456
9457 \end_inset
9458
9459 -dumprange
9460 \begin_inset LatexCommand \index{-\/-dumprange}
9461
9462 \end_inset
9463
9464
9465 \series default
9466 \size large
9467  
9468 \size default
9469 Will create a dump of iCode's, after live range analysis
9470 \begin_inset LatexCommand \index{Live range analysis}
9471
9472 \end_inset
9473
9474 , into a file named 
9475 \emph on
9476 <source filename>.dumprange.
9477
9478 \layout List
9479 \labelwidthstring 00.00.0000
9480
9481 \series bold
9482 -
9483 \begin_inset ERT
9484 status Collapsed
9485
9486 \layout Standard
9487
9488
9489 \backslash
9490 /
9491
9492 \end_inset
9493
9494 -dumlrange
9495 \begin_inset LatexCommand \index{-\/-dumlrange}
9496
9497 \end_inset
9498
9499
9500 \series default
9501  Will dump the life ranges
9502 \begin_inset LatexCommand \index{Live range analysis}
9503
9504 \end_inset
9505
9506  for all symbols.
9507
9508 \layout List
9509 \labelwidthstring 00.00.0000
9510
9511 \series bold
9512 -
9513 \begin_inset ERT
9514 status Collapsed
9515
9516 \layout Standard
9517
9518
9519 \backslash
9520 /
9521
9522 \end_inset
9523
9524 -dumpregassign
9525 \begin_inset LatexCommand \index{-\/-dumpregassign}
9526
9527 \end_inset
9528
9529
9530 \bar under
9531  
9532 \series default
9533 \bar default
9534 Will create a dump of iCode's, after register assignment
9535 \begin_inset LatexCommand \index{Register assignment}
9536
9537 \end_inset
9538
9539 , into a file named 
9540 \emph on
9541 <source filename>.dumprassgn.
9542
9543 \layout List
9544 \labelwidthstring 00.00.0000
9545
9546 \series bold
9547 -
9548 \begin_inset ERT
9549 status Collapsed
9550
9551 \layout Standard
9552
9553
9554 \backslash
9555 /
9556
9557 \end_inset
9558
9559 -dumplrange
9560 \begin_inset LatexCommand \index{-\/-dumplrange}
9561
9562 \end_inset
9563
9564
9565 \series default
9566  Will create a dump of the live ranges of iTemp's
9567
9568 \layout List
9569 \labelwidthstring 00.00.0000
9570 \added_space_bottom bigskip 
9571
9572 \series bold
9573 -
9574 \begin_inset ERT
9575 status Collapsed
9576
9577 \layout Standard
9578
9579
9580 \backslash
9581 /
9582
9583 \end_inset
9584
9585 -dumpall
9586 \begin_inset LatexCommand \index{-\/-dumpall}
9587
9588 \end_inset
9589
9590
9591 \size large
9592 \bar under
9593  
9594 \series default
9595 \size default
9596 \bar default
9597 Will cause all the above mentioned dumps to be created.
9598
9599
9600 \layout Subsection
9601 Redirecting output on Windows Shells
9602
9603 \layout Standard
9604 \added_space_bottom bigskip 
9605 By default SDCC writes it's error messages to 
9606 \begin_inset Quotes sld
9607 \end_inset
9608
9609 standard error
9610 \begin_inset Quotes srd
9611 \end_inset
9612
9613 .
9614  To force all messages to 
9615 \begin_inset Quotes sld
9616 \end_inset
9617
9618 standard output
9619 \begin_inset Quotes srd
9620 \end_inset
9621
9622  use 
9623 \series bold
9624 -
9625 \series default
9626 \emph on
9627
9628 \begin_inset ERT
9629 status Collapsed
9630
9631 \layout Standard
9632
9633
9634 \backslash
9635 /
9636
9637 \end_inset
9638
9639
9640 \series bold
9641 \emph default
9642 -
9643 \series default
9644 use-stdout
9645 \begin_inset LatexCommand \index{-\/-use-stdout}
9646
9647 \end_inset
9648
9649 .
9650  Additionally, if you happen to have visual studio installed in your windows
9651  machine, you can use it to compile your sources using a custom build and
9652  the SDCC -
9653 \emph on
9654
9655 \begin_inset ERT
9656 status Collapsed
9657
9658 \layout Standard
9659
9660
9661 \backslash
9662 /
9663
9664 \end_inset
9665
9666
9667 \emph default
9668 -vc
9669 \begin_inset LatexCommand \index{-\/-vc}
9670
9671 \end_inset
9672
9673  option.
9674  Something like this should work:
9675 \newline
9676
9677 \newline
9678
9679 \series bold
9680 c:
9681 \backslash
9682 sdcc
9683 \backslash
9684 bin
9685 \backslash
9686 sdcc.exe -
9687 \series default
9688 \emph on
9689
9690 \begin_inset ERT
9691 status Collapsed
9692
9693 \layout Standard
9694
9695
9696 \backslash
9697 /
9698
9699 \end_inset
9700
9701
9702 \series bold
9703 \emph default
9704 -vc -
9705 \series default
9706 \emph on
9707
9708 \begin_inset ERT
9709 status Collapsed
9710
9711 \layout Standard
9712
9713
9714 \backslash
9715 /
9716
9717 \end_inset
9718
9719
9720 \series bold
9721 \emph default
9722 -model-large -c $(InputPath)
9723 \series default
9724
9725
9726
9727
9728 \layout Section
9729 Environment variables
9730 \begin_inset LatexCommand \index{Environment variables}
9731
9732 \end_inset
9733
9734
9735
9736 \layout Standard
9737 SDCC recognizes the following environment variables:
9738
9739 \layout List
9740 \labelwidthstring 00.00.0000
9741
9742 \series bold
9743 SDCC_LEAVE_SIGNALS
9744 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9745
9746 \end_inset
9747
9748
9749 \series default
9750  SDCC installs a signal handler
9751 \begin_inset LatexCommand \index{signal handler}
9752
9753 \end_inset
9754
9755  to be able to delete temporary files after an user break (^C) or an exception.
9756  If this environment variable is set, SDCC won't install the signal handler
9757  in order to be able to debug SDCC.
9758
9759 \layout List
9760 \labelwidthstring 00.00.0000
9761
9762 \series bold
9763 TMP,\SpecialChar ~
9764 TEMP,\SpecialChar ~
9765 TMPDIR
9766 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9767
9768 \end_inset
9769
9770
9771 \series default
9772  Path, where temporary files will be created.
9773  The order of the variables is the search order.
9774  In a standard *nix environment these variables are not set, and there's
9775  no need to set them.
9776  On Windows it's recommended to set one of them.
9777
9778 \layout List
9779 \labelwidthstring 00.00.0000
9780
9781 \series bold
9782 SDCC_HOME
9783 \begin_inset LatexCommand \index{SDCC\_HOME}
9784
9785 \end_inset
9786
9787
9788 \series default
9789  Path, see section 
9790 \begin_inset LatexCommand \ref{sub:Install-paths}
9791
9792 \end_inset
9793
9794 \SpecialChar ~
9795
9796 \begin_inset Quotes sld
9797 \end_inset
9798
9799  Install Paths
9800 \begin_inset Quotes srd
9801 \end_inset
9802
9803 .
9804
9805 \layout List
9806 \labelwidthstring 00.00.0000
9807
9808 \series bold
9809 SDCC_INCLUDE
9810 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9811
9812 \end_inset
9813
9814
9815 \series default
9816  Path, see section 
9817 \begin_inset LatexCommand \ref{sub:Search-Paths}
9818
9819 \end_inset
9820
9821 \SpecialChar ~
9822
9823 \begin_inset Quotes sld
9824 \end_inset
9825
9826 Search Paths
9827 \begin_inset Quotes srd
9828 \end_inset
9829
9830 .
9831
9832 \layout List
9833 \labelwidthstring 00.00.0000
9834
9835 \series bold
9836 SDCC_LIB
9837 \begin_inset LatexCommand \index{SDCC\_LIB}
9838
9839 \end_inset
9840
9841
9842 \series default
9843  Path, see section 
9844 \begin_inset LatexCommand \ref{sub:Search-Paths}
9845
9846 \end_inset
9847
9848 \SpecialChar ~
9849
9850 \begin_inset Quotes sld
9851 \end_inset
9852
9853 Search Paths
9854 \begin_inset Quotes srd
9855 \end_inset
9856
9857 ..
9858
9859 \layout Standard
9860 \added_space_bottom bigskip 
9861 There are some more environment variables recognized by SDCC, but these
9862  are solely used for debugging purposes.
9863  They can change or disappear very quickly, and will never be documented.
9864
9865
9866
9867 \layout Section
9868 Storage Class Language Extensions
9869
9870 \layout Subsection
9871 MCS51/DS390 Storage Class
9872 \begin_inset LatexCommand \index{Storage class}
9873
9874 \end_inset
9875
9876  Language Extensions
9877
9878 \layout Standard
9879 In addition to the ANSI storage classes SDCC allows the following MCS51
9880  specific storage classes:
9881
9882 \layout Subsubsection
9883 data
9884 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9885
9886 \end_inset
9887
9888
9889 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9890
9891 \end_inset
9892
9893  / near
9894 \begin_inset LatexCommand \index{near (storage class)}
9895
9896 \end_inset
9897
9898
9899 \begin_inset LatexCommand \index{\_\_near (storage class)}
9900
9901 \end_inset
9902
9903
9904
9905 \layout Standard
9906 This is the 
9907 \series bold
9908 default
9909 \series default
9910  storage class for the Small Memory model (
9911 \emph on
9912 data
9913 \emph default
9914  and 
9915 \emph on
9916 near
9917 \emph default
9918  or the more ANSI-C compliant forms 
9919 \emph on
9920 __data
9921 \emph default
9922  and 
9923 \emph on
9924 __near
9925 \emph default
9926  can be used synonymously).
9927  Variables declared with this storage class will be allocated in the directly
9928  addressable portion of the internal RAM of a 8051, e.g.:
9929
9930 \layout Verse
9931
9932 \family typewriter
9933 __data unsigned char test_data;
9934
9935 \layout Standard
9936 Writing 0x01 to this variable generates the assembly code:
9937
9938 \layout Verse
9939
9940 \family typewriter
9941 75*00 01\SpecialChar ~
9942 \SpecialChar ~
9943 \SpecialChar ~
9944 mov\SpecialChar ~
9945 \SpecialChar ~
9946 _test_data,#0x01
9947
9948 \layout Subsubsection
9949 xdata
9950 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9951
9952 \end_inset
9953
9954
9955 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9956
9957 \end_inset
9958
9959  / far
9960 \begin_inset LatexCommand \index{far (storage class)}
9961
9962 \end_inset
9963
9964
9965 \begin_inset LatexCommand \index{\_\_far (storage class)}
9966
9967 \end_inset
9968
9969
9970
9971 \layout Standard
9972 Variables declared with this storage class will be placed in the external
9973  RAM.
9974  This is the 
9975 \series bold
9976 default
9977 \series default
9978  storage class for the Large Memory model, e.g.:
9979
9980 \layout Verse
9981
9982 \family typewriter
9983 __xdata unsigned char test_xdata;
9984
9985 \layout Standard
9986 Writing 0x01 to this variable generates the assembly code:
9987
9988 \layout Verse
9989
9990 \family typewriter
9991 90s00r00\SpecialChar ~
9992 \SpecialChar ~
9993 \SpecialChar ~
9994 mov\SpecialChar ~
9995 \SpecialChar ~
9996 dptr,#_test_xdata 
9997 \newline
9998 74\SpecialChar ~
9999 01\SpecialChar ~
10000 \SpecialChar ~
10001 \SpecialChar ~
10002 \SpecialChar ~
10003 \SpecialChar ~
10004 \SpecialChar ~
10005 mov\SpecialChar ~
10006 \SpecialChar ~
10007 a,#0x01 
10008 \newline
10009 F0\SpecialChar ~
10010 \SpecialChar ~
10011 \SpecialChar ~
10012 \SpecialChar ~
10013 \SpecialChar ~
10014 \SpecialChar ~
10015 \SpecialChar ~
10016 \SpecialChar ~
10017 \SpecialChar ~
10018 movx\SpecialChar ~
10019 @dptr,a 
10020
10021 \layout Subsubsection
10022 idata
10023 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10024
10025 \end_inset
10026
10027
10028 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10029
10030 \end_inset
10031
10032
10033
10034 \layout Standard
10035 Variables declared with this storage class will be allocated into the indirectly
10036  addressable portion of the internal ram of a 8051, e.g.:
10037
10038 \layout Verse
10039
10040 \family typewriter
10041 __idata unsigned char test_idata;
10042
10043 \layout Standard
10044 Writing 0x01 to this variable generates the assembly code:
10045
10046 \layout Verse
10047
10048 \family typewriter
10049 78r00\SpecialChar ~
10050 \SpecialChar ~
10051 \SpecialChar ~
10052 \SpecialChar ~
10053 \SpecialChar ~
10054 \SpecialChar ~
10055 \SpecialChar ~
10056 mov\SpecialChar ~
10057 \SpecialChar ~
10058 r0,#_test_idata
10059 \newline
10060 76\SpecialChar ~
10061 01\SpecialChar ~
10062 \SpecialChar ~
10063 \SpecialChar ~
10064 \SpecialChar ~
10065 \SpecialChar ~
10066 \SpecialChar ~
10067 \SpecialChar ~
10068 mov\SpecialChar ~
10069 \SpecialChar ~
10070 @r0,#0x01
10071
10072 \layout Standard
10073 Please note, the first 128 byte of idata physically access the same RAM
10074  as the data memory.
10075  The original 8051 had 128 byte idata memory, nowadays most devices have
10076  256 byte idata memory.
10077  The stack
10078 \begin_inset LatexCommand \index{stack}
10079
10080 \end_inset
10081
10082  is located in idata memory.
10083
10084 \layout Subsubsection
10085 pdata
10086 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10087
10088 \end_inset
10089
10090
10091 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10092
10093 \end_inset
10094
10095
10096
10097 \layout Standard
10098 Paged xdata access is just as straightforward as using the other addressing
10099  modes of a 8051.
10100  It is typically located at the start of xdata and has a maximum size of
10101  256 bytes.
10102  The following example writes 0x01 to the pdata variable.
10103  Please note, pdata access physically accesses xdata memory.
10104  The high byte of the address is determined by port P2 
10105 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10106
10107 \end_inset
10108
10109 (or in case of some 8051 variants by a separate Special Function Register,
10110  see section 
10111 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10112
10113 \end_inset
10114
10115 ).
10116  This is the 
10117 \series bold
10118 default
10119 \series default
10120  storage class for the Medium Memory model, e.g.:
10121
10122 \layout Verse
10123
10124 \family typewriter
10125 __pdata unsigned char test_pdata;
10126
10127 \layout Standard
10128 Writing 0x01 to this variable generates the assembly code:
10129
10130 \layout Verse
10131
10132 \family typewriter
10133 78r00\SpecialChar ~
10134 \SpecialChar ~
10135 \SpecialChar ~
10136 \SpecialChar ~
10137 \SpecialChar ~
10138 \SpecialChar ~
10139 mov r0,#_test_pdata
10140 \newline
10141 74 01\SpecialChar ~
10142 \SpecialChar ~
10143 \SpecialChar ~
10144 \SpecialChar ~
10145 \SpecialChar ~
10146 \SpecialChar ~
10147 mov a,#0x01 
10148 \newline
10149 F2\SpecialChar ~
10150 \SpecialChar ~
10151 \SpecialChar ~
10152 \SpecialChar ~
10153 \SpecialChar ~
10154 \SpecialChar ~
10155 \SpecialChar ~
10156 \SpecialChar ~
10157 \SpecialChar ~
10158 movx @r0,a
10159
10160 \layout Standard
10161 If the -
10162 \begin_inset ERT
10163 status Collapsed
10164
10165 \layout Standard
10166
10167
10168 \backslash
10169 /
10170
10171 \end_inset
10172
10173 -xstack
10174 \begin_inset LatexCommand \index{-\/-xstack}
10175
10176 \end_inset
10177
10178  option is used the pdata memory area is followed by the xstack memory area
10179  and the sum of their sizes is limited to 256 bytes.
10180
10181 \layout Subsubsection
10182 code
10183 \begin_inset LatexCommand \index{code}
10184
10185 \end_inset
10186
10187
10188 \begin_inset LatexCommand \index{\_\_code}
10189
10190 \end_inset
10191
10192
10193
10194 \layout Standard
10195 'Variables' declared with this storage class will be placed in the code
10196  memory:
10197
10198 \layout Verse
10199
10200 \family typewriter
10201 __code unsigned char test_code;
10202
10203 \layout Standard
10204 Read access to this variable generates the assembly code:
10205
10206 \layout Verse
10207
10208 \family typewriter
10209 90s00r6F\SpecialChar ~
10210 \SpecialChar ~
10211 \SpecialChar ~
10212 mov dptr,#_test_code
10213 \newline
10214 E4\SpecialChar ~
10215 \SpecialChar ~
10216 \SpecialChar ~
10217 \SpecialChar ~
10218 \SpecialChar ~
10219 \SpecialChar ~
10220 \SpecialChar ~
10221 \SpecialChar ~
10222 \SpecialChar ~
10223 clr a
10224 \newline
10225 93\SpecialChar ~
10226 \SpecialChar ~
10227 \SpecialChar ~
10228 \SpecialChar ~
10229 \SpecialChar ~
10230 \SpecialChar ~
10231 \SpecialChar ~
10232 \SpecialChar ~
10233 \SpecialChar ~
10234 movc a,@a+dptr 
10235
10236 \layout Standard
10237
10238 \family typewriter
10239 char
10240 \family default
10241  indexed arrays of characters in code memory can be accessed efficiently:
10242
10243 \layout Verse
10244
10245 \family typewriter
10246 __code char test_array[] = {'c','h','e','a','p'}; 
10247
10248 \layout Standard
10249 Read access to this array using an 8-bit unsigned index generates the assembly
10250  code:
10251
10252 \layout Verse
10253
10254 \family typewriter
10255 E5*00\SpecialChar ~
10256 \SpecialChar ~
10257 \SpecialChar ~
10258 \SpecialChar ~
10259 \SpecialChar ~
10260 \SpecialChar ~
10261 mov a,_index 
10262
10263 \layout Verse
10264
10265 \family typewriter
10266 90s00r41\SpecialChar ~
10267 \SpecialChar ~
10268 \SpecialChar ~
10269 mov dptr,#_test_array
10270
10271 \layout Verse
10272
10273 \family typewriter
10274 93\SpecialChar ~
10275 \SpecialChar ~
10276 \SpecialChar ~
10277 \SpecialChar ~
10278 \SpecialChar ~
10279 \SpecialChar ~
10280 \SpecialChar ~
10281 \SpecialChar ~
10282 \SpecialChar ~
10283 movc a,@a+dptr 
10284
10285 \layout Subsubsection
10286 bit
10287 \begin_inset LatexCommand \index{bit}
10288
10289 \end_inset
10290
10291
10292 \begin_inset LatexCommand \index{\_\_bit}
10293
10294 \end_inset
10295
10296
10297
10298 \layout Standard
10299 This is a data-type and a storage class specifier.
10300  When a variable is declared as a bit, it is allocated into the bit addressable
10301  memory of 8051, e.g.:
10302
10303 \layout Verse
10304
10305 \family typewriter
10306 __bit test_bit;
10307
10308 \layout Standard
10309 Writing 1 to this variable generates the assembly code:
10310
10311 \layout Verse
10312
10313 \family typewriter
10314 D2*00\SpecialChar ~
10315 \SpecialChar ~
10316 \SpecialChar ~
10317 \SpecialChar ~
10318 \SpecialChar ~
10319 \SpecialChar ~
10320 \SpecialChar ~
10321 setb\SpecialChar ~
10322 _test_bit
10323
10324 \layout Standard
10325 The bit addressable memory consists of 128 bits which are located from 0x20
10326  to 0x2f in data memory.
10327  
10328 \newline
10329 Apart from this 8051 specific storage class most architectures support
10330  ANSI-C bitfields
10331 \begin_inset LatexCommand \index{bitfields}
10332
10333 \end_inset
10334
10335
10336 \begin_inset Foot
10337 collapsed false
10338
10339 \layout Standard
10340 Not really meant as examples, but nevertheless showing what bitfields are
10341  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10342
10343 \end_inset
10344
10345 .
10346  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10347  signed modifier are implemented as unsigned.
10348
10349 \layout Subsubsection
10350 sfr
10351 \begin_inset LatexCommand \index{sfr}
10352
10353 \end_inset
10354
10355
10356 \begin_inset LatexCommand \index{\_\_sfr}
10357
10358 \end_inset
10359
10360  / sfr16
10361 \begin_inset LatexCommand \index{sfr16}
10362
10363 \end_inset
10364
10365
10366 \begin_inset LatexCommand \index{\_\_sfr16}
10367
10368 \end_inset
10369
10370  / sfr32
10371 \begin_inset LatexCommand \index{sfr32}
10372
10373 \end_inset
10374
10375
10376 \begin_inset LatexCommand \index{\_\_sfr32}
10377
10378 \end_inset
10379
10380  / sbit
10381 \begin_inset LatexCommand \index{\_\_sbit}
10382
10383 \end_inset
10384
10385
10386 \begin_inset LatexCommand \index{sbit}
10387
10388 \end_inset
10389
10390
10391
10392 \layout Standard
10393 Like the bit keyword, 
10394 \emph on
10395 sfr / sfr16 / sfr32 / sbit 
10396 \emph default
10397 signify both a data-type and storage class, they are used to describe the
10398  
10399 \emph on
10400 s
10401 \emph default
10402 pecial 
10403 \emph on
10404 f
10405 \emph default
10406 unction 
10407 \emph on
10408 r
10409 \emph default
10410 egisters and 
10411 \emph on
10412 s
10413 \emph default
10414 pecial 
10415 \emph on
10416 bit
10417 \emph default
10418  variables of a 8051, eg:
10419
10420 \layout Verse
10421
10422 \family typewriter
10423 __sfr __at
10424 \begin_inset LatexCommand \index{at}
10425
10426 \end_inset
10427
10428
10429 \begin_inset LatexCommand \index{\_\_at}
10430
10431 \end_inset
10432
10433  (0x80) P0;\SpecialChar ~
10434  /* special function register P0 at location 0x80 */
10435 \newline
10436
10437 \newline
10438 /* 16 bit
10439  special function register combination for timer 0
10440 \newline
10441 \SpecialChar ~
10442 \SpecialChar ~
10443  with the high byte at
10444  location 0x8C and the low byte at location 0x8A */
10445 \newline
10446 __sfr16 __at (0x8C8A)
10447  TMR0;
10448 \newline
10449
10450 \newline
10451 __sbit __at
10452 \begin_inset LatexCommand \index{at}
10453
10454 \end_inset
10455
10456
10457 \begin_inset LatexCommand \index{\_\_at}
10458
10459 \end_inset
10460
10461  (0xd7) CY;\SpecialChar ~
10462  /* CY (Carry Flag
10463 \begin_inset LatexCommand \index{Flags}
10464
10465 \end_inset
10466
10467
10468 \begin_inset LatexCommand \index{Carry flag}
10469
10470 \end_inset
10471
10472 ) */
10473
10474 \layout Standard
10475 Special function registers which are located on an address dividable by
10476  8 are bit-addressable, an
10477 \emph on
10478  sbit
10479 \emph default
10480  addresses a specific bit within these sfr.
10481 \newline
10482 16 Bit and 32 bit special function
10483  register combinations which require a certain access order are better not
10484  declared using 
10485 \emph on
10486 sfr16
10487 \emph default
10488  or 
10489 \emph on
10490 sfr32.
10491
10492 \emph default
10493  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10494  this is not guaranteed.
10495 \newline
10496
10497
10498 \layout Standard
10499 Please note, if you use a header file which was written for another compiler
10500  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10501  likely be 
10502 \emph on
10503 not 
10504 \emph default
10505 compatible.
10506  Specifically the syntax 
10507 \family typewriter
10508 \SpecialChar ~
10509 sfr P0 = 0x80;\SpecialChar ~
10510
10511 \family default
10512  is compiled 
10513 \emph on
10514 without warning
10515 \emph default
10516  by SDCC to an assignment of 0x80 to a variable called P0 
10517 \family typewriter
10518
10519 \begin_inset Marginal
10520 collapsed true
10521
10522 \layout Standard
10523
10524 \series bold
10525 \SpecialChar ~
10526 !
10527
10528 \end_inset
10529
10530 .
10531  
10532 \family default
10533 Nevertheless it is possible to write header files
10534 \begin_inset LatexCommand \index{Header files}
10535
10536 \end_inset
10537
10538
10539 \begin_inset LatexCommand \index{Include files}
10540
10541 \end_inset
10542
10543  which can be shared among different compilers (see section 
10544 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10545
10546 \end_inset
10547
10548 ).
10549  
10550
10551 \layout Subsubsection
10552 Pointers
10553 \begin_inset LatexCommand \index{Pointer}
10554
10555 \end_inset
10556
10557  to MCS51/DS390 specific memory spaces
10558
10559 \layout Standard
10560 SDCC allows (via language extensions) pointers to explicitly point to any
10561  of the memory spaces
10562 \begin_inset LatexCommand \index{Memory model}
10563
10564 \end_inset
10565
10566  of the 8051.
10567  In addition to the explicit pointers, the compiler uses (by default) generic
10568  pointers which can be used to point to any of the memory spaces.
10569 \newline
10570
10571 \newline
10572 Pointer
10573  declaration examples:
10574
10575 \layout Verse
10576
10577 \family typewriter
10578 /* pointer physically in internal ram pointing to object in external ram
10579  */ 
10580 \newline
10581 __xdata unsigned char * __data p;
10582 \newline
10583
10584 \newline
10585 /* pointer physically in external ram
10586  pointing to object in internal ram */ 
10587 \newline
10588 __data unsigned char * __xdata p;
10589 \newline
10590
10591 \newline
10592 /*
10593  pointer physically in code rom pointing to data in xdata space */ 
10594 \newline
10595 __xdata
10596  unsigned char * __code p;
10597 \newline
10598
10599 \newline
10600 /* pointer physically in code space pointing to
10601  data in code space */ 
10602 \newline
10603 __code unsigned char * __code p;
10604 \newline
10605
10606 \newline
10607 /* generic pointer
10608  physically located in xdata space */
10609 \newline
10610 unsigned char * __xdata p;
10611 \newline
10612
10613 \newline
10614 /* generic
10615  pointer physically located in default memory space */
10616 \newline
10617 unsigned char * p;
10618 \newline
10619
10620 \newline
10621 /*
10622  the following is a function pointer
10623 \begin_inset LatexCommand \index{function pointer}
10624
10625 \end_inset
10626
10627  physically located in data space */
10628 \newline
10629 char (* __data fp)(void);
10630
10631 \layout Standard
10632 Well you get the idea.
10633  
10634 \newline
10635
10636 \newline
10637 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10638 \emph on
10639 generic
10640 \emph default
10641  pointers.
10642  
10643 \size small
10644
10645 \newline
10646
10647 \newline
10648
10649 \size default
10650 The highest order byte of the 
10651 \emph on
10652 generic
10653 \emph default
10654  pointers contains the data space information.
10655  Assembler support routines are called whenever data is stored or retrieved
10656  using 
10657 \emph on
10658 generic
10659 \emph default
10660  pointers.
10661  These are useful for developing reusable library
10662 \begin_inset LatexCommand \index{Libraries}
10663
10664 \end_inset
10665
10666  routines.
10667  Explicitly specifying the pointer
10668 \begin_inset LatexCommand \index{pointer}
10669
10670 \end_inset
10671
10672  type will generate the most efficient code.
10673
10674 \layout Subsubsection
10675 Notes on MCS51 memory
10676 \begin_inset LatexCommand \index{MCS51 memory}
10677
10678 \end_inset
10679
10680  layout
10681
10682 \layout Standard
10683 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10684  RAM memory which is structured as follows:
10685 \newline
10686
10687 \newline
10688 - Bytes 00-1F - 32 bytes to hold
10689  up to 4 banks of the registers R0 to R7, 
10690 \newline
10691 - Bytes 20-2F - 16 bytes to hold
10692  128 bit
10693 \begin_inset LatexCommand \index{bit}
10694
10695 \end_inset
10696
10697  variables and, 
10698 \newline
10699 - Bytes 30-7F - 80 bytes for general purpose use.
10700 \newline
10701
10702
10703 \layout Standard
10704 Additionally some members of the MCS51 family may have up to 128 bytes of
10705  additional, indirectly addressable, internal RAM memory (
10706 \emph on
10707 idata
10708 \emph default
10709
10710 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10711
10712 \end_inset
10713
10714
10715 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10716
10717 \end_inset
10718
10719 ).
10720  Furthermore, some chips may have some built in external memory (
10721 \emph on
10722 xdata
10723 \emph default
10724
10725 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10726
10727 \end_inset
10728
10729
10730 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10731
10732 \end_inset
10733
10734 ) which should not be confused with the internal, directly addressable RAM
10735  memory (
10736 \emph on
10737 data
10738 \emph default
10739
10740 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10741
10742 \end_inset
10743
10744
10745 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10746
10747 \end_inset
10748
10749 ).
10750  Sometimes this built in 
10751 \emph on
10752 xdata
10753 \emph default
10754  memory has to be activated before using it (you can probably find this
10755  information on the datasheet of the microcontroller your are using, see
10756  also section 
10757 \begin_inset LatexCommand \ref{sub:Startup-Code}
10758
10759 \end_inset
10760
10761 \SpecialChar ~
10762 Startup-Code).
10763
10764 \layout Standard
10765 Normally SDCC will only use the first bank
10766 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10767
10768 \end_inset
10769
10770  of registers (register bank 0), but it is possible to specify that other
10771  banks of registers (keyword 
10772 \emph on
10773 using
10774 \emph default
10775  
10776 \emph on
10777
10778 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10779
10780 \end_inset
10781
10782
10783 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10784
10785 \end_inset
10786
10787
10788 \emph default
10789 ) should be used in interrupt
10790 \begin_inset LatexCommand \index{interrupt}
10791
10792 \end_inset
10793
10794
10795 \begin_inset LatexCommand \index{\_\_interrupt}
10796
10797 \end_inset
10798
10799  routines.
10800  By default, the compiler will place the stack after the last byte of allocated
10801  memory for variables.
10802  For example, if the first 2 banks of registers are used, and only four
10803  bytes are used for 
10804 \emph on
10805 data
10806 \emph default
10807  variables, it will position the base of the internal stack at address 20
10808  (0x14).
10809  This implies that as the stack
10810 \begin_inset LatexCommand \index{stack}
10811
10812 \end_inset
10813
10814  grows, it will use up the remaining register banks, and the 16 bytes used
10815  by the 128 bit variables, and 80 bytes for general purpose use.
10816  If any bit variables are used, the data variables will be placed in unused
10817  register banks and after the byte holding the last bit variable.
10818  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10819  (two bytes used), 
10820 \emph on
10821 data
10822 \emph default
10823  variables will be placed starting from address 0x10 to 0x20 and continue
10824  at address 0x22.
10825  You can also use -
10826 \begin_inset ERT
10827 status Collapsed
10828
10829 \layout Standard
10830
10831
10832 \backslash
10833 /
10834
10835 \end_inset
10836
10837 -data-loc
10838 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10839
10840 \end_inset
10841
10842  to specify the start address of the 
10843 \emph on
10844 data
10845 \emph default
10846  and -
10847 \begin_inset ERT
10848 status Collapsed
10849
10850 \layout Standard
10851
10852
10853 \backslash
10854 /
10855
10856 \end_inset
10857
10858 -iram-size
10859 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10860
10861 \end_inset
10862
10863  to specify the size of the total internal RAM (
10864 \emph on
10865 data
10866 \emph default
10867 +
10868 \emph on
10869 idata
10870 \emph default
10871 ).
10872  
10873 \newline
10874
10875
10876 \layout Standard
10877 By default the 8051 linker will place the stack after the last byte of (i)data
10878  variables.
10879  Option -
10880 \begin_inset ERT
10881 status Collapsed
10882
10883 \layout Standard
10884
10885
10886 \backslash
10887 /
10888
10889 \end_inset
10890
10891 -stack-loc
10892 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10893
10894 \end_inset
10895
10896  allows you to specify the start of the stack, i.e.
10897  you could start it after any data in the general purpose area.
10898  If your microcontroller has additional indirectly addressable internal
10899  RAM (
10900 \emph on
10901 idata
10902 \emph default
10903 ) you can place the stack on it.
10904  You may also need to use -
10905 \begin_inset ERT
10906 status Collapsed
10907
10908 \layout Standard
10909
10910
10911 \backslash
10912 /
10913
10914 \end_inset
10915
10916 -xdata-loc
10917 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10918
10919 \end_inset
10920
10921  to set the start address of the external RAM (
10922 \emph on
10923 xdata
10924 \emph default
10925 ) and -
10926 \begin_inset ERT
10927 status Collapsed
10928
10929 \layout Standard
10930
10931
10932 \backslash
10933 /
10934
10935 \end_inset
10936
10937 -xram-size
10938 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10939
10940 \end_inset
10941
10942  to specify its size.
10943  Same goes for the code memory, using -
10944 \begin_inset ERT
10945 status Collapsed
10946
10947 \layout Standard
10948
10949
10950 \backslash
10951 /
10952
10953 \end_inset
10954
10955 -code-loc
10956 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10957
10958 \end_inset
10959
10960  and -
10961 \begin_inset ERT
10962 status Collapsed
10963
10964 \layout Standard
10965
10966
10967 \backslash
10968 /
10969
10970 \end_inset
10971
10972 -code-size
10973 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10974
10975 \end_inset
10976
10977 .
10978  If in doubt, don't specify any options and see if the resulting memory
10979  layout is appropriate, then you can adjust it.
10980
10981 \layout Standard
10982 \added_space_bottom bigskip 
10983 The linker generates two files with memory allocation information.
10984  The first, with extension .map
10985 \begin_inset LatexCommand \index{<file>.map}
10986
10987 \end_inset
10988
10989  shows all the variables and segments.
10990  The second with extension .mem
10991 \begin_inset LatexCommand \index{<file>.mem}
10992
10993 \end_inset
10994
10995  shows the final memory layout.
10996  The linker will complain either if memory segments overlap, there is not
10997  enough memory, or there is not enough space for stack.
10998  If you get any linking warnings and/or errors related to stack or segments
10999  allocation, take a look at either the .map or .mem files to find out what
11000  the problem is.
11001  The .mem file may even suggest a solution to the problem.
11002
11003
11004
11005 \layout Subsection
11006 Z80/Z180 Storage Class
11007 \begin_inset LatexCommand \index{Z80!Storage class}
11008
11009 \end_inset
11010
11011  Language Extensions
11012
11013 \layout Subsubsection
11014 sfr
11015 \begin_inset LatexCommand \index{sfr}
11016
11017 \end_inset
11018
11019
11020 \begin_inset LatexCommand \index{\_\_sfr}
11021
11022 \end_inset
11023
11024  (in/out to 8-bit addresses)
11025
11026 \layout Standard
11027 The Z80
11028 \begin_inset LatexCommand \index{Z80}
11029
11030 \end_inset
11031
11032  family has separate address spaces for memory and 
11033 \emph on
11034 i
11035 \emph default
11036 nput/
11037 \emph on
11038 o
11039 \emph default
11040 utput memory.
11041  I/O memory
11042 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11043
11044 \end_inset
11045
11046
11047 \begin_inset LatexCommand \index{Z80!I/O memory}
11048
11049 \end_inset
11050
11051
11052 \begin_inset LatexCommand \index{Z180!I/O memory}
11053
11054 \end_inset
11055
11056  is accessed with special instructions, e.g.:
11057
11058 \layout Verse
11059
11060 \family typewriter
11061 sfr at 0x78 IoPort;\SpecialChar ~
11062 \SpecialChar ~
11063 /* define a var in I/O space at 78h called IoPort */
11064  
11065
11066 \layout Standard
11067 Writing 0x01 to this variable generates the assembly code:
11068
11069 \layout Verse
11070
11071 \family typewriter
11072 3E 01\SpecialChar ~
11073 \SpecialChar ~
11074 \SpecialChar ~
11075 \SpecialChar ~
11076 \SpecialChar ~
11077 \SpecialChar ~
11078 ld a,#0x01
11079 \newline
11080 D3 78\SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 \SpecialChar ~
11085 \SpecialChar ~
11086 out (_IoPort),a 
11087
11088 \layout Subsubsection
11089 banked sfr
11090 \begin_inset LatexCommand \index{sfr}
11091
11092 \end_inset
11093
11094
11095 \begin_inset LatexCommand \index{\_\_sfr}
11096
11097 \end_inset
11098
11099  (in/out to 16-bit addresses)
11100
11101 \layout Standard
11102 The keyword 
11103 \emph on
11104 banked
11105 \emph default
11106  is used to support 16 bit addresses in I/O memory e.g.:
11107
11108 \layout Verse
11109
11110 \family typewriter
11111 sfr banked at
11112 \begin_inset LatexCommand \index{at}
11113
11114 \end_inset
11115
11116
11117 \begin_inset LatexCommand \index{\_\_at}
11118
11119 \end_inset
11120
11121  0x123 IoPort; 
11122
11123 \layout Standard
11124 Writing 0x01 to this variable generates the assembly code:
11125
11126 \layout Verse
11127
11128 \family typewriter
11129 01 23 01\SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 ld bc,#_IoPort
11133 \newline
11134 3E 01\SpecialChar ~
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 \SpecialChar ~
11139 \SpecialChar ~
11140 ld a,#0x01 
11141 \newline
11142 ED 79\SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 \SpecialChar ~
11147 \SpecialChar ~
11148 out (c),a 
11149
11150 \layout Subsubsection
11151 sfr
11152 \begin_inset LatexCommand \index{sfr}
11153
11154 \end_inset
11155
11156
11157 \begin_inset LatexCommand \index{\_\_sfr}
11158
11159 \end_inset
11160
11161  (in0/out0 to 8 bit addresses on Z180
11162 \begin_inset LatexCommand \index{Z180}
11163
11164 \end_inset
11165
11166 /HD64180
11167 \begin_inset LatexCommand \index{HD64180 (see Z180)}
11168
11169 \end_inset
11170
11171 )
11172
11173 \layout Standard
11174 \added_space_bottom bigskip 
11175 The compiler option -
11176 \begin_inset ERT
11177 status Collapsed
11178
11179 \layout Standard
11180
11181
11182 \backslash
11183 /
11184
11185 \end_inset
11186
11187 -portmode
11188 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
11189
11190 \end_inset
11191
11192 =180 (80) and a compiler #pragma\SpecialChar ~
11193 portmode
11194 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
11195
11196 \end_inset
11197
11198  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
11199 ns 
11200 \family typewriter
11201 in0/out0
11202 \family default
11203  instead of 
11204 \family typewriter
11205 in/out
11206 \family default
11207 .
11208  If you include the file z180.h this will be set automatically.
11209
11210
11211
11212 \layout Subsection
11213 HC08 Storage Class
11214 \begin_inset LatexCommand \index{HC08!Storage class}
11215
11216 \end_inset
11217
11218  Language Extensions
11219
11220 \layout Subsubsection
11221 data
11222 \begin_inset LatexCommand \index{data (hc08 storage class)}
11223
11224 \end_inset
11225
11226
11227 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
11228
11229 \end_inset
11230
11231  
11232
11233 \layout Standard
11234 The data storage class declares a variable that resides in the first 256
11235  bytes of memory (the direct page).
11236  The HC08
11237 \begin_inset LatexCommand \index{HC08}
11238
11239 \end_inset
11240
11241  is most efficient at accessing variables (especially pointers) stored here.
11242
11243 \layout Subsubsection
11244 xdata
11245 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
11246
11247 \end_inset
11248
11249
11250 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
11251
11252 \end_inset
11253
11254  
11255
11256 \layout Standard
11257 \added_space_bottom bigskip 
11258 The xdata storage class declares a variable that can reside anywhere in
11259  memory.
11260  This is the default if no storage class is specified.
11261  
11262
11263
11264
11265 \layout Section
11266 Absolute Addressing
11267 \begin_inset LatexCommand \index{Absolute addressing}
11268
11269 \end_inset
11270
11271
11272
11273 \layout Standard
11274 Data items can be assigned an absolute address with the 
11275 \emph on
11276 at
11277 \begin_inset LatexCommand \index{at}
11278
11279 \end_inset
11280
11281
11282 \begin_inset LatexCommand \index{\_\_at}
11283
11284 \end_inset
11285
11286  <address>
11287 \emph default
11288  keyword, in addition to a storage class, e.g.:
11289
11290 \layout Verse
11291
11292 \family typewriter
11293 xdata
11294 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11295
11296 \end_inset
11297
11298
11299 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11300
11301 \end_inset
11302
11303  at
11304 \begin_inset LatexCommand \index{at}
11305
11306 \end_inset
11307
11308
11309 \begin_inset LatexCommand \index{\_\_at}
11310
11311 \end_inset
11312
11313  0x7ffe unsigned int chksum;
11314
11315 \layout Standard
11316 or, better conforming to ISO/IEC 9899 C:
11317
11318 \layout Verse
11319
11320 \family typewriter
11321 __xdata __at (0x7ffe) unsigned int chksum;
11322
11323 \layout Standard
11324 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
11325  of the external ram.
11326  The compiler does 
11327 \emph on
11328 not
11329 \emph default
11330  reserve any space for variables declared in this way
11331 \begin_inset Marginal
11332 collapsed true
11333
11334 \layout Standard
11335
11336 \series bold
11337 \SpecialChar ~
11338 !
11339
11340 \end_inset
11341
11342  (they are implemented with an equate in the assembler).
11343  Thus it is left to the programmer to make sure there are no overlaps with
11344  other variables that are declared without the absolute address.
11345  The assembler listing file (.lst
11346 \begin_inset LatexCommand \index{<file>.lst}
11347
11348 \end_inset
11349
11350 ) and the linker output files (.rst
11351 \begin_inset LatexCommand \index{<file>.rst}
11352
11353 \end_inset
11354
11355 ) and (.map
11356 \begin_inset LatexCommand \index{<file>.map}
11357
11358 \end_inset
11359
11360 ) are good places to look for such overlaps.
11361  Variables with an absolute address are 
11362 \emph on
11363 not
11364 \begin_inset Marginal
11365 collapsed true
11366
11367 \layout Standard
11368
11369 \series bold
11370 \SpecialChar ~
11371 !
11372
11373 \end_inset
11374
11375
11376 \emph default
11377  initialized
11378 \begin_inset LatexCommand \index{Variable initialization}
11379
11380 \end_inset
11381
11382 .
11383
11384 \layout Standard
11385 In case of memory mapped I/O devices the keyword 
11386 \emph on
11387 volatile
11388 \emph default
11389  has to be used to tell the compiler that accesses might not be removed:
11390
11391 \layout Verse
11392
11393 \family typewriter
11394 volatile
11395 \begin_inset LatexCommand \index{volatile}
11396
11397 \end_inset
11398
11399  __xdata
11400 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11401
11402 \end_inset
11403
11404  __at
11405 \begin_inset LatexCommand \index{at}
11406
11407 \end_inset
11408
11409  (0x8000) unsigned char PORTA_8255;
11410
11411 \layout Standard
11412 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11413 r) array
11414 \family typewriter
11415 \size footnotesize
11416
11417 \begin_inset LatexCommand \index{Aligned array}
11418
11419 \end_inset
11420
11421
11422 \family default
11423 \size default
11424  starts at a block (256 byte) boundary
11425 \begin_inset LatexCommand \index{block boundary}
11426
11427 \end_inset
11428
11429  (section 
11430 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11431
11432 \end_inset
11433
11434  has an example).
11435 \newline
11436 Absolute addresses can be specified for variables in all
11437  storage classes, e.g.:
11438
11439 \layout Verse
11440
11441 \family typewriter
11442 __bit
11443 \begin_inset LatexCommand \index{bit}
11444
11445 \end_inset
11446
11447  __at
11448 \begin_inset LatexCommand \index{at}
11449
11450 \end_inset
11451
11452  (0x02) bvar;
11453
11454 \layout Standard
11455 The above example will allocate the variable at offset 0x02 in the bit-addressab
11456 le space.
11457  There is no real advantage to assigning absolute addresses to variables
11458  in this manner, unless you want strict control over all the variables allocated.
11459  One possible use would be to write hardware portable code.
11460  For example, if you have a routine that uses one or more of the microcontroller
11461  I/O pins, and such pins are different for two different hardwares, you
11462  can declare the I/O pins in your routine using:
11463
11464 \layout Verse
11465
11466 \family typewriter
11467 extern volatile
11468 \begin_inset LatexCommand \index{volatile}
11469
11470 \end_inset
11471
11472  __bit MOSI;\SpecialChar ~
11473 \SpecialChar ~
11474 \SpecialChar ~
11475 \SpecialChar ~
11476 /* master out, slave in */
11477 \newline
11478 extern volatile __bit MISO;\SpecialChar ~
11479 \SpecialChar ~
11480 \SpecialChar ~
11481 \SpecialChar ~
11482 /* master
11483  in, slave out */
11484 \newline
11485 extern volatile __bit MCLK;\SpecialChar ~
11486 \SpecialChar ~
11487 \SpecialChar ~
11488 \SpecialChar ~
11489 /* master clock */
11490 \newline
11491
11492 \newline
11493 /* Input and
11494  Output of a byte on a 3-wire serial bus.
11495 \newline
11496 \SpecialChar ~
11497 \SpecialChar ~
11498 \SpecialChar ~
11499 If needed adapt polarity of clock,
11500  polarity of data and bit order
11501 \newline
11502 \SpecialChar ~
11503 */
11504 \newline
11505 unsigned char spi_io(unsigned char out_byte)
11506  
11507 \newline
11508
11509 \newline
11510 \SpecialChar ~
11511 \SpecialChar ~
11512 \SpecialChar ~
11513 \SpecialChar ~
11514 unsigned char i=8;
11515 \newline
11516 \SpecialChar ~
11517 \SpecialChar ~
11518 \SpecialChar ~
11519 \SpecialChar ~
11520 do { 
11521 \newline
11522 \SpecialChar ~
11523 \SpecialChar ~
11524 \SpecialChar ~
11525 \SpecialChar ~
11526 \SpecialChar ~
11527 \SpecialChar ~
11528 \SpecialChar ~
11529 \SpecialChar ~
11530 MOSI = out_byte & 0x80; 
11531 \newline
11532 \SpecialChar ~
11533 \SpecialChar ~
11534 \SpecialChar ~
11535 \SpecialChar ~
11536 \SpecialChar ~
11537 \SpecialChar ~
11538 \SpecialChar ~
11539 \SpecialChar ~
11540 out_byte <<= 1;
11541 \newline
11542 \SpecialChar ~
11543 \SpecialChar ~
11544 \SpecialChar ~
11545 \SpecialChar ~
11546 \SpecialChar ~
11547 \SpecialChar ~
11548 \SpecialChar ~
11549 \SpecialChar ~
11550 MCLK =
11551  1; 
11552 \newline
11553 \SpecialChar ~
11554 \SpecialChar ~
11555 \SpecialChar ~
11556 \SpecialChar ~
11557 \SpecialChar ~
11558 \SpecialChar ~
11559 \SpecialChar ~
11560 \SpecialChar ~
11561 /* _asm nop _endasm; */\SpecialChar ~
11562 \SpecialChar ~
11563 \SpecialChar ~
11564 \SpecialChar ~
11565 \SpecialChar ~
11566 \SpecialChar ~
11567 \SpecialChar ~
11568 \SpecialChar ~
11569 /* for slow peripherals */
11570 \newline
11571 \SpecialChar ~
11572 \SpecialChar ~
11573 \SpecialChar ~
11574 \SpecialChar ~
11575 \SpecialChar ~
11576 \SpecialChar ~
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 if(MISO) 
11580 \newline
11581 \SpecialChar ~
11582 \SpecialChar ~
11583 \SpecialChar ~
11584 \SpecialChar ~
11585 \SpecialChar ~
11586 \SpecialChar ~
11587 \SpecialChar ~
11588 \SpecialChar ~
11589 \SpecialChar ~
11590 \SpecialChar ~
11591 \SpecialChar ~
11592 \SpecialChar ~
11593 out_byte +=
11594  1; 
11595 \newline
11596 \SpecialChar ~
11597 \SpecialChar ~
11598 \SpecialChar ~
11599 \SpecialChar ~
11600 \SpecialChar ~
11601 \SpecialChar ~
11602 \SpecialChar ~
11603 \SpecialChar ~
11604 MCLK = 0; 
11605 \newline
11606 \SpecialChar ~
11607 \SpecialChar ~
11608 \SpecialChar ~
11609 \SpecialChar ~
11610 } while(--i);
11611 \newline
11612 \SpecialChar ~
11613 \SpecialChar ~
11614 \SpecialChar ~
11615 \SpecialChar ~
11616 return out_byte; 
11617 \newline
11618 }
11619
11620 \layout Standard
11621 Then, someplace in the code for the first hardware you would use
11622
11623 \layout Verse
11624
11625 \family typewriter
11626 __bit __at
11627 \begin_inset LatexCommand \index{at}
11628
11629 \end_inset
11630
11631
11632 \begin_inset LatexCommand \index{\_\_at}
11633
11634 \end_inset
11635
11636  (0x80) MOSI;\SpecialChar ~
11637 \SpecialChar ~
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 /* I/O port 0, bit 0 */
11641 \newline
11642 __bit __at (0x81) MISO;\SpecialChar ~
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 \SpecialChar ~
11646 /* I/O port 0,
11647  bit 1 */
11648 \newline
11649 __bit __at (0x82) MCLK;\SpecialChar ~
11650 \SpecialChar ~
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 /* I/O port 0, bit 2 */
11654
11655 \layout Standard
11656 Similarly, for the second hardware you would use
11657
11658 \layout Verse
11659
11660 \family typewriter
11661 __bit __at (0x83) MOSI;\SpecialChar ~
11662 \SpecialChar ~
11663 \SpecialChar ~
11664 \SpecialChar ~
11665 /* I/O port 0, bit 3 */
11666 \newline
11667 __bit __at (0x91) MISO;\SpecialChar ~
11668 \SpecialChar ~
11669 \SpecialChar ~
11670 \SpecialChar ~
11671 /*
11672  I/O port 1, bit 1 */
11673 \newline
11674 __bit
11675 \begin_inset LatexCommand \index{bit}
11676
11677 \end_inset
11678
11679  __at (0x92) MCLK;\SpecialChar ~
11680 \SpecialChar ~
11681 \SpecialChar ~
11682 \SpecialChar ~
11683 /* I/O port 1, bit 2 */
11684
11685 \layout Standard
11686 \added_space_bottom bigskip 
11687 and you can use the same hardware dependent routine without changes, as
11688  for example in a library.
11689  This is somehow similar to sbit, but only one absolute address has to be
11690  specified in the whole project.
11691
11692
11693
11694 \layout Section
11695 Parameters
11696 \begin_inset LatexCommand \index{Parameters}
11697
11698 \end_inset
11699
11700
11701 \begin_inset LatexCommand \index{function parameter}
11702
11703 \end_inset
11704
11705  & Local Variables
11706 \begin_inset LatexCommand \index{local variables}
11707
11708 \end_inset
11709
11710
11711 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11712
11713 \end_inset
11714
11715
11716
11717 \layout Standard
11718 Automatic (local) variables and parameters to functions can either be placed
11719  on the stack or in data-space.
11720  The default action of the compiler is to place these variables in the internal
11721  RAM (for small model) or external RAM (for large model).
11722  This in fact makes them similar to 
11723 \emph on
11724 static
11725 \begin_inset LatexCommand \index{static}
11726
11727 \end_inset
11728
11729
11730 \emph default
11731  so by default functions are non-reentrant
11732 \begin_inset LatexCommand \index{reentrant}
11733
11734 \end_inset
11735
11736 .
11737  
11738 \newline
11739
11740 \newline
11741 They can be placed on the stack
11742 \begin_inset LatexCommand \index{stack}
11743
11744 \end_inset
11745
11746  by using the
11747 \emph on
11748  -
11749 \begin_inset ERT
11750 status Collapsed
11751
11752 \layout Standard
11753
11754
11755 \backslash
11756 /
11757
11758 \end_inset
11759
11760 -stack-auto
11761 \begin_inset LatexCommand \index{-\/-stack-auto}
11762
11763 \end_inset
11764
11765
11766 \emph default
11767  option, by using 
11768 \emph on
11769 #pragma\SpecialChar ~
11770 stackauto
11771 \emph default
11772
11773 \begin_inset LatexCommand \index{\#pragma stackauto}
11774
11775 \end_inset
11776
11777  or by using the 
11778 \emph on
11779 reentrant
11780 \begin_inset LatexCommand \index{reentrant}
11781
11782 \end_inset
11783
11784
11785 \emph default
11786  keyword in the function declaration, e.g.:
11787
11788 \layout Verse
11789
11790 \family typewriter
11791 unsigned char foo(char i) __reentrant 
11792 \newline
11793
11794 \newline
11795 \SpecialChar ~
11796 \SpecialChar ~
11797 \SpecialChar ~
11798 \SpecialChar ~
11799 ...
11800  
11801 \newline
11802 }
11803
11804 \layout Standard
11805 Since stack space on 8051 is limited, the 
11806 \emph on
11807 reentrant 
11808 \emph default
11809 keyword or the
11810 \emph on
11811  -
11812 \begin_inset ERT
11813 status Collapsed
11814
11815 \layout Standard
11816
11817
11818 \backslash
11819 /
11820
11821 \end_inset
11822
11823 -stack-auto
11824 \emph default
11825  option should be used sparingly.
11826  Note that the reentrant keyword just means that the parameters & local
11827  variables will be allocated to the stack, it 
11828 \emph on
11829 does not
11830 \emph default
11831  mean that the function is register bank
11832 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11833
11834 \end_inset
11835
11836  independent.
11837 \newline
11838
11839 \newline
11840 Local variables
11841 \begin_inset LatexCommand \index{local variables}
11842
11843 \end_inset
11844
11845  can be assigned storage classes and absolute
11846 \begin_inset LatexCommand \index{Absolute addressing}
11847
11848 \end_inset
11849
11850  addresses, e.g.: 
11851
11852 \layout Verse
11853
11854 \family typewriter
11855 unsigned char foo() 
11856 \newline
11857 {
11858 \newline
11859 \SpecialChar ~
11860 \SpecialChar ~
11861 \SpecialChar ~
11862 \SpecialChar ~
11863 __xdata unsigned char i;
11864 \newline
11865 \SpecialChar ~
11866 \SpecialChar ~
11867 \SpecialChar ~
11868 \SpecialChar ~
11869 __bit bvar;
11870 \newline
11871 \SpecialChar ~
11872 \SpecialChar ~
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 __data __at
11876 \begin_inset LatexCommand \index{at}
11877
11878 \end_inset
11879
11880  (0x31) unsigned char j;
11881 \newline
11882 \SpecialChar ~
11883 \SpecialChar ~
11884 \SpecialChar ~
11885 \SpecialChar ~
11886 ...
11887  
11888 \newline
11889 }
11890
11891 \layout Standard
11892 In the above example the variable 
11893 \emph on
11894 i
11895 \emph default
11896  will be allocated in the external ram, 
11897 \emph on
11898 bvar
11899 \emph default
11900  in bit addressable space and
11901 \emph on
11902  j
11903 \emph default
11904  in internal ram.
11905  When compiled with 
11906 \emph on
11907 -
11908 \begin_inset ERT
11909 status Collapsed
11910
11911 \layout Standard
11912
11913
11914 \backslash
11915 /
11916
11917 \end_inset
11918
11919 -stack-auto
11920 \emph default
11921  or when a function is declared as 
11922 \emph on
11923 reentrant
11924 \emph default
11925  this should only be done for static variables.
11926
11927 \layout Standard
11928 Parameters
11929 \begin_inset LatexCommand \index{function parameter}
11930
11931 \end_inset
11932
11933  however are not allowed any storage class
11934 \begin_inset LatexCommand \index{Storage class}
11935
11936 \end_inset
11937
11938 , (storage classes for parameters will be ignored), their allocation is
11939  governed by the memory model in use, and the reentrancy options.
11940
11941 \layout Standard
11942 It is however allowed to use bit parameters in reentrant functions and also
11943  non-static local bit variables are supported.
11944  Efficient use is limited to 8 semi-bitregisters in bit space.
11945  They are pushed and popped to stack
11946 \begin_inset LatexCommand \index{stack}
11947
11948 \end_inset
11949
11950  as a single byte just like the normal registers.
11951
11952 \layout Section
11953 Overlaying
11954 \begin_inset LatexCommand \label{sub:Overlaying}
11955
11956 \end_inset
11957
11958
11959 \begin_inset LatexCommand \index{Overlaying}
11960
11961 \end_inset
11962
11963
11964
11965 \layout Standard
11966 For non-reentrant
11967 \begin_inset LatexCommand \index{reentrant}
11968
11969 \end_inset
11970
11971  functions SDCC will try to reduce internal ram space usage by overlaying
11972  parameters and local variables of a function (if possible).
11973  Parameters and local variables
11974 \begin_inset LatexCommand \index{local variables}
11975
11976 \end_inset
11977
11978  of a function will be allocated to an overlayable segment if the function
11979  has 
11980 \emph on
11981 no other function calls and the function is non-reentrant and the memory
11982  model
11983 \begin_inset LatexCommand \index{Memory model}
11984
11985 \end_inset
11986
11987  is small.
11988
11989 \emph default
11990  If an explicit storage class
11991 \begin_inset LatexCommand \index{Storage class}
11992
11993 \end_inset
11994
11995  is specified for a local variable, it will NOT be overlayed.
11996
11997 \layout Standard
11998 Note that the compiler (not the linkage editor) makes the decision for overlayin
11999 g the data items.
12000  Functions that are called from an interrupt service routine
12001 \begin_inset Marginal
12002 collapsed true
12003
12004 \layout Standard
12005
12006 \series bold
12007 !
12008
12009 \end_inset
12010
12011  should be preceded by a #pragma\SpecialChar ~
12012 nooverlay
12013 \begin_inset LatexCommand \index{\#pragma nooverlay}
12014
12015 \end_inset
12016
12017  if they are not reentrant.
12018
12019 \layout Standard
12020 Also note that the compiler does not do any processing of inline assembler
12021  code, so the compiler might incorrectly assign local variables and parameters
12022  of a function into the overlay segment if the inline assembler code calls
12023  other c-functions that might use the overlay.
12024  In that case the #pragma\SpecialChar ~
12025 nooverlay should be used.
12026
12027 \layout Standard
12028 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12029 tion
12030 \begin_inset LatexCommand \index{Multiplication}
12031
12032 \end_inset
12033
12034  or division
12035 \begin_inset LatexCommand \index{Division}
12036
12037 \end_inset
12038
12039  will NOT be overlayed since these are implemented using external functions,
12040  e.g.:
12041
12042 \layout Verse
12043
12044 \family typewriter
12045 #pragma save 
12046 \newline
12047 #pragma nooverlay
12048 \begin_inset LatexCommand \index{\#pragma nooverlay}
12049
12050 \end_inset
12051
12052  
12053 \newline
12054 void set_error(unsigned char errcd) 
12055 \newline
12056 {
12057 \newline
12058 \SpecialChar ~
12059 \SpecialChar ~
12060 \SpecialChar ~
12061 \SpecialChar ~
12062 P3 = errcd;
12063 \newline
12064
12065 \newline
12066 #pragma restore 
12067 \newline
12068
12069 \newline
12070 void
12071  some_isr () __interrupt
12072 \begin_inset LatexCommand \index{interrupt}
12073
12074 \end_inset
12075
12076  (2)
12077 \newline
12078 {
12079 \newline
12080 \SpecialChar ~
12081 \SpecialChar ~
12082 \SpecialChar ~
12083 \SpecialChar ~
12084 ...
12085 \newline
12086 \SpecialChar ~
12087 \SpecialChar ~
12088 \SpecialChar ~
12089 \SpecialChar ~
12090 set_error(10);
12091 \newline
12092 \SpecialChar ~
12093 \SpecialChar ~
12094 \SpecialChar ~
12095 \SpecialChar ~
12096 ...
12097  
12098 \newline
12099 }
12100
12101 \layout Standard
12102 \added_space_bottom bigskip 
12103 In the above example the parameter 
12104 \emph on
12105 errcd
12106 \emph default
12107  for the function 
12108 \emph on
12109 set_error
12110 \emph default
12111  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
12112 nooverlay was
12113  not present, this could cause unpredictable runtime behavior when called
12114  from an interrupt service routine.
12115  The #pragma\SpecialChar ~
12116 nooverlay ensures that the parameters and local variables for
12117  the function are NOT overlayed.
12118
12119
12120
12121 \layout Section
12122 Interrupt Service Routines
12123 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
12124
12125 \end_inset
12126
12127
12128
12129 \layout Subsection
12130 General Information
12131
12132 \layout Standard
12133 SDCC allows 
12134 \emph on
12135 i
12136 \emph default
12137 nterrupt 
12138 \emph on
12139 s
12140 \emph default
12141 ervice 
12142 \emph on
12143 r
12144 \emph default
12145 outines to be coded in C, with some extended keywords.
12146
12147 \layout Verse
12148
12149 \family typewriter
12150 void timer_isr (void) __interrupt (1) __using (1) 
12151 \newline
12152
12153 \newline
12154 \SpecialChar ~
12155 \SpecialChar ~
12156 \SpecialChar ~
12157 \SpecialChar ~
12158 ...
12159  
12160 \newline
12161 }
12162
12163 \layout Standard
12164 The optional number following the 
12165 \emph on
12166 interrupt
12167 \begin_inset LatexCommand \index{interrupt}
12168
12169 \end_inset
12170
12171
12172 \begin_inset LatexCommand \index{\_\_interrupt}
12173
12174 \end_inset
12175
12176
12177 \emph default
12178  keyword is the interrupt number this routine will service.
12179  When present, the compiler will insert a call to this routine in the interrupt
12180  vector table
12181 \begin_inset LatexCommand \index{interrupt vector table}
12182
12183 \end_inset
12184
12185  for the interrupt number specified.
12186  If you have multiple source files in your project, interrupt service routines
12187  can be present in any of them, but a prototype of the isr MUST be present
12188  or included in the file that contains the function 
12189 \emph on
12190 main
12191 \emph default
12192 .
12193  The optional (8051 specific) keyword 
12194 \emph on
12195 using
12196 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12197
12198 \end_inset
12199
12200
12201 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12202
12203 \end_inset
12204
12205
12206 \emph default
12207  can be used to tell the compiler to use the specified register bank when
12208  generating code for this function.
12209  
12210 \newline
12211 Interrupt service routines open the door for some very interesting bugs:
12212
12213 \layout Subsubsection
12214 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
12215
12216 \end_inset
12217
12218 Common interrupt pitfall: variable not declared 
12219 \emph on
12220 volatile
12221
12222 \layout Standard
12223 If an interrupt service routine changes variables which are accessed by
12224  other functions these variables have to be declared 
12225 \emph on
12226 volatile
12227 \emph default
12228
12229 \begin_inset LatexCommand \index{volatile}
12230
12231 \end_inset
12232
12233 .
12234  See 
12235 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
12236
12237 \end_inset
12238
12239  .
12240
12241 \layout Subsubsection
12242 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
12243
12244 \end_inset
12245
12246 Common interrupt pitfall: 
12247 \emph on
12248 non-atomic access
12249
12250 \layout Standard
12251 If the access to these variables is not 
12252 \emph on
12253 atomic
12254 \begin_inset LatexCommand \index{atomic}
12255
12256 \end_inset
12257
12258
12259 \emph default
12260  (i.e.
12261  the processor needs more than one instruction for the access and could
12262  be interrupted while accessing the variable) the interrupt must be disabled
12263  during the access to avoid inconsistent data.
12264  
12265 \newline
12266 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
12267  and should be protected by disabling interrupts.
12268  You're not automatically on the safe side if you use 8 bit variables though.
12269  We need an example here: f.e.
12270  on the 8051 the harmless looking 
12271 \begin_inset Quotes srd
12272 \end_inset
12273
12274
12275 \family typewriter
12276 flags\SpecialChar ~
12277 |=\SpecialChar ~
12278 0x80;
12279 \family default
12280
12281 \begin_inset Quotes sld
12282 \end_inset
12283
12284  is not atomic if 
12285 \family typewriter
12286 flags
12287 \family default
12288  resides in xdata.
12289  Setting 
12290 \begin_inset Quotes srd
12291 \end_inset
12292
12293
12294 \family typewriter
12295 flags\SpecialChar ~
12296 |=\SpecialChar ~
12297 0x40;
12298 \family default
12299
12300 \begin_inset Quotes sld
12301 \end_inset
12302
12303  from within an interrupt routine might get lost if the interrupt occurs
12304  at the wrong time.
12305  
12306 \begin_inset Quotes sld
12307 \end_inset
12308
12309
12310 \family typewriter
12311 counter\SpecialChar ~
12312 +=\SpecialChar ~
12313 8;
12314 \family default
12315
12316 \begin_inset Quotes srd
12317 \end_inset
12318
12319  is not atomic on the 8051 even if 
12320 \family typewriter
12321 counter
12322 \family default
12323  is located in data memory.
12324 \newline
12325 Bugs like these are hard to reproduce and can
12326  cause a lot of trouble.
12327  
12328
12329 \layout Subsubsection
12330 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
12331
12332 \end_inset
12333
12334 Common interrupt pitfall: 
12335 \emph on
12336 stack overflow
12337
12338 \layout Standard
12339 The return address and the registers used in the interrupt service routine
12340  are saved on the stack
12341 \begin_inset LatexCommand \index{stack}
12342
12343 \end_inset
12344
12345  so there must be sufficient stack space.
12346  If there isn't variables or registers (or even the return address itself)
12347  will be corrupted.
12348  This 
12349 \emph on
12350 stack overflow
12351 \emph default
12352
12353 \begin_inset LatexCommand \index{stack overflow}
12354
12355 \end_inset
12356
12357  is most likely to happen if the interrupt occurs during the 
12358 \begin_inset Quotes sld
12359 \end_inset
12360
12361 deepest
12362 \begin_inset Quotes srd
12363 \end_inset
12364
12365  subroutine when the stack is already in use for f.e.
12366  many return addresses.
12367
12368 \layout Subsubsection
12369 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
12370
12371 \end_inset
12372
12373 Common interrupt pitfall: 
12374 \emph on
12375 use of non-reentrant functions
12376
12377 \layout Standard
12378 A special note here, int (16 bit) and long (32 bit) integer division
12379 \begin_inset LatexCommand \index{Division}
12380
12381 \end_inset
12382
12383 , multiplication
12384 \begin_inset LatexCommand \index{Multiplication}
12385
12386 \end_inset
12387
12388  & modulus
12389 \begin_inset LatexCommand \index{Modulus}
12390
12391 \end_inset
12392
12393  and floating-point
12394 \begin_inset LatexCommand \index{Floating point support}
12395
12396 \end_inset
12397
12398  operations are implemented using external support routines.
12399  If an interrupt service routine needs to do any of these operations then
12400  the support routines (as mentioned in a following section) will have to
12401  be recompiled using the
12402 \emph on
12403  -
12404 \begin_inset ERT
12405 status Collapsed
12406
12407 \layout Standard
12408
12409
12410 \backslash
12411 /
12412
12413 \end_inset
12414
12415 -stack-auto
12416 \begin_inset LatexCommand \index{-\/-stack-auto}
12417
12418 \end_inset
12419
12420
12421 \emph default
12422  option and the source file will need to be compiled using the 
12423 \emph on
12424 -
12425 \begin_inset ERT
12426 status Collapsed
12427
12428 \layout Standard
12429
12430
12431 \backslash
12432 /
12433
12434 \end_inset
12435
12436 -int-long-reent
12437 \emph default
12438
12439 \begin_inset LatexCommand \index{-\/-int-long-reent}
12440
12441 \end_inset
12442
12443  compiler option.
12444  
12445 \newline
12446 Note, the type promotion
12447 \begin_inset LatexCommand \index{type promotion}
12448
12449 \end_inset
12450
12451  required by ANSI C can cause 16 bit routines to be used
12452 \begin_inset Marginal
12453 collapsed true
12454
12455 \layout Standard
12456
12457 \series bold
12458 \SpecialChar ~
12459 !
12460
12461 \end_inset
12462
12463  without the programmer being aware of it.
12464  See f.e.
12465  the cast 
12466 \family typewriter
12467 (unsigned char)(tail-1)
12468 \family default
12469  within the if clause in section 
12470 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12471
12472 \end_inset
12473
12474 .
12475
12476 \layout Standard
12477 \added_space_bottom bigskip 
12478 Calling other functions from an interrupt service routine is not recommended,
12479  avoid it if possible.
12480  Note that when some function is called from an interrupt service routine
12481  it should be preceded by a #pragma\SpecialChar ~
12482 nooverlay
12483 \begin_inset LatexCommand \index{\#pragma nooverlay}
12484
12485 \end_inset
12486
12487  if it is not reentrant.
12488  Furthermore nonreentrant functions should not be called from the main program
12489  while the interrupt service routine might be active.
12490  They also must not be called from low priority interrupt service routines
12491  while a high priority interrupt service routine might be active.
12492  You could use semaphores or make the function
12493 \emph on
12494  critical
12495 \emph default
12496  if all parameters are passed in registers.
12497 \newline
12498  Also see section 
12499 \begin_inset LatexCommand \ref{sub:Overlaying}
12500
12501 \end_inset
12502
12503 \SpecialChar ~
12504 about Overlaying and section 
12505 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12506
12507 \end_inset
12508
12509 \SpecialChar ~
12510 about Functions using private register banks.
12511
12512
12513
12514 \layout Subsection
12515 MCS51/DS390 Interrupt Service Routines
12516
12517 \layout Standard
12518 Interrupt
12519 \begin_inset LatexCommand \index{interrupt}
12520
12521 \end_inset
12522
12523  numbers and the corresponding address & descriptions for the Standard 8051/8052
12524  are listed below.
12525  SDCC will automatically adjust the 
12526 \begin_inset LatexCommand \index{interrupt vector table}
12527
12528 \end_inset
12529
12530  to the maximum interrupt number specified.
12531 \newline
12532
12533
12534 \layout Standard
12535 \align center
12536 \begin_inset Tabular
12537 <lyxtabular version="3" rows="9" columns="3">
12538 <features>
12539 <column alignment="center" valignment="top" leftline="true" width="0in">
12540 <column alignment="left" valignment="top" leftline="true" width="0in">
12541 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12542 <row topline="true" bottomline="true">
12543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12544 \begin_inset Text
12545
12546 \layout Standard
12547 Interrupt #
12548
12549 \end_inset
12550 </cell>
12551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12552 \begin_inset Text
12553
12554 \layout Standard
12555 Description
12556
12557 \end_inset
12558 </cell>
12559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12560 \begin_inset Text
12561
12562 \layout Standard
12563 Vector Address
12564
12565 \end_inset
12566 </cell>
12567 </row>
12568 <row topline="true">
12569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12570 \begin_inset Text
12571
12572 \layout Standard
12573 0
12574
12575 \end_inset
12576 </cell>
12577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12578 \begin_inset Text
12579
12580 \layout Standard
12581 External 0
12582
12583 \end_inset
12584 </cell>
12585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12586 \begin_inset Text
12587
12588 \layout Standard
12589 0x0003
12590
12591 \end_inset
12592 </cell>
12593 </row>
12594 <row topline="true">
12595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12596 \begin_inset Text
12597
12598 \layout Standard
12599 1
12600
12601 \end_inset
12602 </cell>
12603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12604 \begin_inset Text
12605
12606 \layout Standard
12607 Timer 0
12608
12609 \end_inset
12610 </cell>
12611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12612 \begin_inset Text
12613
12614 \layout Standard
12615 0x000b
12616
12617 \end_inset
12618 </cell>
12619 </row>
12620 <row topline="true">
12621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12622 \begin_inset Text
12623
12624 \layout Standard
12625 2
12626
12627 \end_inset
12628 </cell>
12629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12630 \begin_inset Text
12631
12632 \layout Standard
12633 External 1
12634
12635 \end_inset
12636 </cell>
12637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12638 \begin_inset Text
12639
12640 \layout Standard
12641 0x0013
12642
12643 \end_inset
12644 </cell>
12645 </row>
12646 <row topline="true">
12647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12648 \begin_inset Text
12649
12650 \layout Standard
12651 3
12652
12653 \end_inset
12654 </cell>
12655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12656 \begin_inset Text
12657
12658 \layout Standard
12659 Timer 1
12660
12661 \end_inset
12662 </cell>
12663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12664 \begin_inset Text
12665
12666 \layout Standard
12667 0x001b
12668
12669 \end_inset
12670 </cell>
12671 </row>
12672 <row topline="true">
12673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12674 \begin_inset Text
12675
12676 \layout Standard
12677 4
12678
12679 \end_inset
12680 </cell>
12681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12682 \begin_inset Text
12683
12684 \layout Standard
12685 Serial
12686
12687 \end_inset
12688 </cell>
12689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12690 \begin_inset Text
12691
12692 \layout Standard
12693 0x0023
12694
12695 \end_inset
12696 </cell>
12697 </row>
12698 <row topline="true">
12699 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12700 \begin_inset Text
12701
12702 \layout Standard
12703 5
12704
12705 \end_inset
12706 </cell>
12707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12708 \begin_inset Text
12709
12710 \layout Standard
12711 Timer 2 (8052)
12712
12713 \end_inset
12714 </cell>
12715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12716 \begin_inset Text
12717
12718 \layout Standard
12719 0x002b
12720
12721 \end_inset
12722 </cell>
12723 </row>
12724 <row topline="true">
12725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12726 \begin_inset Text
12727
12728 \layout Standard
12729 ...
12730
12731 \end_inset
12732 </cell>
12733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12734 \begin_inset Text
12735
12736 \layout Standard
12737
12738
12739 \end_inset
12740 </cell>
12741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12742 \begin_inset Text
12743
12744 \layout Standard
12745 ...
12746
12747 \end_inset
12748 </cell>
12749 </row>
12750 <row topline="true" bottomline="true">
12751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12752 \begin_inset Text
12753
12754 \layout Standard
12755 n
12756
12757 \end_inset
12758 </cell>
12759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12760 \begin_inset Text
12761
12762 \layout Standard
12763
12764
12765 \end_inset
12766 </cell>
12767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12768 \begin_inset Text
12769
12770 \layout Standard
12771 0x0003 + 8*n
12772
12773 \end_inset
12774 </cell>
12775 </row>
12776 </lyxtabular>
12777
12778 \end_inset
12779
12780
12781 \newline
12782
12783
12784 \layout Standard
12785 If the interrupt service routine is defined without 
12786 \emph on
12787 using
12788 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12789
12790 \end_inset
12791
12792
12793 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12794
12795 \end_inset
12796
12797
12798 \emph default
12799  a register bank or with register bank 0 (
12800 \emph on
12801 using
12802 \emph default
12803  0), the compiler will save the registers used by itself on the stack upon
12804  entry and restore them at exit, however if such an interrupt service routine
12805  calls another function then the entire register bank will be saved on the
12806  stack.
12807  This scheme may be advantageous for small interrupt service routines which
12808  have low register usage.
12809
12810 \layout Standard
12811 \added_space_bottom bigskip 
12812 If the interrupt service routine is defined to be using a specific register
12813  bank then only 
12814 \emph on
12815 a, b, dptr
12816 \emph default
12817  & psw are saved and restored, if such an interrupt service routine calls
12818  another function (using another register bank) then the entire register
12819  bank of the called function will be saved on the stack
12820 \begin_inset LatexCommand \index{stack}
12821
12822 \end_inset
12823
12824 .
12825  This scheme is recommended for larger interrupt service routines.
12826
12827
12828
12829 \layout Subsection
12830 HC08
12831 \begin_inset LatexCommand \index{HC08}
12832
12833 \end_inset
12834
12835  Interrupt Service Routines
12836
12837 \layout Standard
12838 \added_space_bottom bigskip 
12839 Since the number of interrupts
12840 \begin_inset LatexCommand \index{HC08!interrupt}
12841
12842 \end_inset
12843
12844  available is chip specific and the interrupt vector table always ends at
12845  the last byte of memory, the interrupt numbers corresponds to the interrupt
12846  vectors in reverse order of address.
12847  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12848  2 will use the interrupt vector at 0xfffa, and so on.
12849  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12850  this way; instead see section 
12851 \begin_inset LatexCommand \ref{sub:Startup-Code}
12852
12853 \end_inset
12854
12855  for details on customizing startup.
12856
12857
12858
12859 \layout Subsection
12860 Z80 Interrupt Service Routines
12861
12862 \layout Standard
12863 The Z80
12864 \begin_inset LatexCommand \index{Z80}
12865
12866 \end_inset
12867
12868  uses several different methods for determining the correct interrupt
12869 \begin_inset LatexCommand \index{Z80!interrupt}
12870
12871 \end_inset
12872
12873  vector depending on the hardware implementation.
12874  Therefore, SDCC ignores the optional interrupt number and does not attempt
12875  to generate an interrupt vector table.
12876
12877 \layout Standard
12878 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12879  instruction to return from the interrupt.
12880  To write an interrupt handler for the non-maskable interrupt, which needs
12881  a RETN instruction instead, add the 
12882 \emph on
12883 critical
12884 \emph default
12885  keyword:
12886
12887 \layout Verse
12888
12889 \family typewriter
12890 void nmi_isr (void) critical interrupt
12891 \newline
12892
12893 \newline
12894 \SpecialChar ~
12895 \SpecialChar ~
12896 \SpecialChar ~
12897 \SpecialChar ~
12898 ...
12899  
12900 \newline
12901 }
12902
12903 \layout Standard
12904 \added_space_bottom bigskip 
12905 However if you need to create a non-interruptable interrupt service routine
12906  you would also require the 
12907 \emph on
12908 critical
12909 \emph default
12910  keyword.
12911  To distinguish between this and an nmi_isr you must provide an interrupt
12912  number.
12913
12914
12915
12916 \layout Section
12917 Enabling and Disabling Interrupts
12918
12919 \layout Subsection
12920 Critical Functions and Critical Statements
12921
12922 \layout Standard
12923 A special keyword may be associated with a block or a function declaring
12924  it as 
12925 \emph on
12926 critical
12927 \emph default
12928 .
12929  SDCC will generate code to disable all interrupts
12930 \begin_inset LatexCommand \index{interrupt}
12931
12932 \end_inset
12933
12934  upon entry to a critical function and restore the interrupt enable to the
12935  previous state before returning.
12936  Nesting critical functions will need one additional byte on the stack
12937 \begin_inset LatexCommand \index{stack}
12938
12939 \end_inset
12940
12941  for each call.
12942
12943 \layout Verse
12944
12945 \family typewriter
12946 int foo () __critical
12947 \begin_inset LatexCommand \index{critical}
12948
12949 \end_inset
12950
12951
12952 \begin_inset LatexCommand \index{\_\_critical}
12953
12954 \end_inset
12955
12956  
12957 \newline
12958
12959 \newline
12960 \SpecialChar ~
12961 \SpecialChar ~
12962 \SpecialChar ~
12963 \SpecialChar ~
12964 ...
12965  
12966 \newline
12967 \SpecialChar ~
12968 \SpecialChar ~
12969 \SpecialChar ~
12970 \SpecialChar ~
12971 ...
12972  
12973 \newline
12974 }
12975
12976 \layout Standard
12977 The critical attribute maybe used with other attributes like 
12978 \emph on
12979 reentrant.
12980 \emph default
12981
12982 \newline
12983 The keyword 
12984 \emph on
12985 critical
12986 \emph default
12987  may also be used to disable interrupts more locally:
12988
12989 \layout Verse
12990
12991 \family typewriter
12992 __critical{ i++; }
12993
12994 \layout Standard
12995 More than one statement could have been included in the block.
12996
12997 \layout Subsection
12998 Enabling and Disabling Interrupts directly
12999
13000 \layout Standard
13001 Interrupts
13002 \begin_inset LatexCommand \index{interrupt}
13003
13004 \end_inset
13005
13006  can also be disabled and enabled directly (8051):
13007
13008 \layout Verse
13009
13010 \family typewriter
13011 EA = 0;\SpecialChar ~
13012 \SpecialChar ~
13013 \SpecialChar ~
13014 \SpecialChar ~
13015 \SpecialChar ~
13016 \SpecialChar ~
13017 \SpecialChar ~
13018 \SpecialChar ~
13019 \SpecialChar ~
13020 \SpecialChar ~
13021 \SpecialChar ~
13022 \SpecialChar ~
13023 or:\SpecialChar ~
13024 \SpecialChar ~
13025 \SpecialChar ~
13026 \SpecialChar ~
13027 \SpecialChar ~
13028 \SpecialChar ~
13029 \SpecialChar ~
13030 \SpecialChar ~
13031 \SpecialChar ~
13032 \SpecialChar ~
13033 \SpecialChar ~
13034 EA_SAVE = EA;
13035
13036 \layout Verse
13037
13038 \family typewriter
13039 ...\SpecialChar ~
13040 \SpecialChar ~
13041 \SpecialChar ~
13042 \SpecialChar ~
13043 \SpecialChar ~
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 EA = 0;
13070
13071 \layout Verse
13072
13073 \family typewriter
13074 EA = 1;\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 \SpecialChar ~
13090 \SpecialChar ~
13091 \SpecialChar ~
13092 \SpecialChar ~
13093 \SpecialChar ~
13094 \SpecialChar ~
13095 \SpecialChar ~
13096 \SpecialChar ~
13097 \SpecialChar ~
13098 \SpecialChar ~
13099 \SpecialChar ~
13100 ...
13101
13102 \layout Verse
13103
13104 \family typewriter
13105 \SpecialChar ~
13106 \SpecialChar ~
13107 \SpecialChar ~
13108 \SpecialChar ~
13109 \SpecialChar ~
13110 \SpecialChar ~
13111 \SpecialChar ~
13112 \SpecialChar ~
13113 \SpecialChar ~
13114 \SpecialChar ~
13115 \SpecialChar ~
13116 \SpecialChar ~
13117 \SpecialChar ~
13118 \SpecialChar ~
13119 \SpecialChar ~
13120 \SpecialChar ~
13121 \SpecialChar ~
13122 \SpecialChar ~
13123 \SpecialChar ~
13124 \SpecialChar ~
13125 \SpecialChar ~
13126 \SpecialChar ~
13127 \SpecialChar ~
13128 \SpecialChar ~
13129 \SpecialChar ~
13130 \SpecialChar ~
13131 \SpecialChar ~
13132 \SpecialChar ~
13133 \SpecialChar ~
13134 \SpecialChar ~
13135 \SpecialChar ~
13136 \SpecialChar ~
13137 \SpecialChar ~
13138 EA = EA_SAVE;
13139
13140 \layout Standard
13141 On other architectures which have seperate opcodes for enabling and disabling
13142  interrupts you might want to make use of defines with inline assembly
13143 \begin_inset LatexCommand \index{Assembler routines}
13144
13145 \end_inset
13146
13147  (HC08
13148 \begin_inset LatexCommand \index{HC08!interrupt}
13149
13150 \end_inset
13151
13152 ):
13153
13154 \layout Verse
13155
13156 \family typewriter
13157 #define CLI _asm
13158 \begin_inset LatexCommand \index{\_asm}
13159
13160 \end_inset
13161
13162 \SpecialChar ~
13163 \SpecialChar ~
13164 cli\SpecialChar ~
13165 \SpecialChar ~
13166 _endasm
13167 \begin_inset LatexCommand \index{\_endasm}
13168
13169 \end_inset
13170
13171
13172
13173 \layout Verse
13174
13175 \family typewriter
13176 #define SEI _asm\SpecialChar ~
13177 \SpecialChar ~
13178 sei\SpecialChar ~
13179 \SpecialChar ~
13180 _endasm; 
13181
13182 \layout Verse
13183
13184 \family typewriter
13185 ...
13186
13187 \layout Standard
13188 Note: it is sometimes sufficient to disable only a specific interrupt source
13189  like f.e.
13190  a timer or serial interrupt by manipulating an 
13191 \emph on
13192 interrupt mask
13193 \begin_inset LatexCommand \index{interrupt mask}
13194
13195 \end_inset
13196
13197
13198 \emph default
13199  register.
13200  
13201
13202 \layout Standard
13203 Usually the time during which interrupts are disabled should be kept as
13204  short as possible.
13205  This minimizes both 
13206 \emph on
13207 interrupt latency
13208 \emph default
13209
13210 \begin_inset LatexCommand \index{interrupt latency}
13211
13212 \end_inset
13213
13214  (the time between the occurrence of the interrupt and the execution of
13215  the first code in the interrupt routine) and 
13216 \emph on
13217 interrupt jitter
13218 \emph default
13219
13220 \begin_inset LatexCommand \index{interrupt jitter}
13221
13222 \end_inset
13223
13224  (the difference between the shortest and the longest interrupt latency).
13225  These really are something different, f.e.
13226  a serial interrupt has to be served before its buffer overruns so it cares
13227  for the maximum interrupt latency, whereas it does not care about jitter.
13228  On a loudspeaker driven via a digital to analog converter which is fed
13229  by an interrupt a latency of a few milliseconds might be tolerable, whereas
13230  a much smaller jitter will be very audible.
13231
13232 \layout Standard
13233 You can reenable interrupts within an interrupt routine and on some architecture
13234 s you can make use of two (or more) levels of 
13235 \emph on
13236 interrupt priorities
13237 \emph default
13238
13239 \begin_inset LatexCommand \index{interrupt priority}
13240
13241 \end_inset
13242
13243 .
13244  On some architectures which don't support interrupt priorities these can
13245  be implemented by manipulating the interrupt mask and reenabling interrupts
13246  within the interrupt routine.
13247  Check there is sufficient space on the stack
13248 \begin_inset LatexCommand \index{stack}
13249
13250 \end_inset
13251
13252  and don't add complexity unless you have to.
13253  
13254
13255 \layout Subsection
13256 Semaphore
13257 \begin_inset LatexCommand \index{semaphore}
13258
13259 \end_inset
13260
13261  locking (mcs51/ds390)
13262
13263 \layout Standard
13264 Some architectures (mcs51/ds390) have an atomic
13265 \begin_inset LatexCommand \index{atomic}
13266
13267 \end_inset
13268
13269  bit test and
13270 \emph on
13271  
13272 \emph default
13273 clear
13274 \emph on
13275  
13276 \emph default
13277 instruction.
13278  These type of instructions are typically used in preemptive multitasking
13279  systems, where a routine f.e.
13280  claims the use of a data structure ('acquires a lock
13281 \begin_inset LatexCommand \index{lock}
13282
13283 \end_inset
13284
13285  on it'), makes some modifications and then releases the lock when the data
13286  structure is consistent again.
13287  The instruction may also be used if interrupt and non-interrupt code have
13288  to compete for a resource.
13289  With the atomic bit test and clear instruction interrupts
13290 \begin_inset LatexCommand \index{interrupt}
13291
13292 \end_inset
13293
13294  don't have to be disabled for the locking operation.
13295  
13296
13297 \layout Standard
13298 SDCC generates this instruction if the source follows this pattern:
13299
13300 \layout Verse
13301
13302 \family typewriter
13303 volatile
13304 \begin_inset LatexCommand \index{volatile}
13305
13306 \end_inset
13307
13308  bit resource_is_free; 
13309 \newline
13310
13311 \newline
13312 if (resource_is_free) 
13313 \newline
13314 \SpecialChar ~
13315 \SpecialChar ~
13316
13317 \newline
13318 \SpecialChar ~
13319 \SpecialChar ~
13320 \SpecialChar ~
13321 \SpecialChar ~
13322 resource_is_free=0; 
13323 \newline
13324 \SpecialChar ~
13325 \SpecialChar ~
13326 \SpecialChar ~
13327 \SpecialChar ~
13328 ...
13329  
13330 \newline
13331 \SpecialChar ~
13332 \SpecialChar ~
13333 \SpecialChar ~
13334 \SpecialChar ~
13335 resource_is_free=1;
13336 \newline
13337 \SpecialChar ~
13338 \SpecialChar ~
13339
13340
13341 \layout Standard
13342 Note, mcs51 and ds390 support only an atomic
13343 \begin_inset LatexCommand \index{atomic}
13344
13345 \end_inset
13346
13347  bit test and 
13348 \emph on
13349 clear
13350 \emph default
13351  instruction (as opposed to atomic bit test and 
13352 \emph on
13353 set).
13354
13355 \layout Section
13356 Functions using private register banks
13357 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
13358
13359 \end_inset
13360
13361  (mcs51/ds390)
13362
13363 \layout Standard
13364 Some architectures have support for quickly changing register sets.
13365  SDCC supports this feature with the 
13366 \emph on
13367 using
13368 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13369
13370 \end_inset
13371
13372
13373 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13374
13375 \end_inset
13376
13377
13378 \emph default
13379  attribute (which tells the compiler to use a register bank
13380 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13381
13382 \end_inset
13383
13384  other than the default bank zero).
13385  It should only be applied to 
13386 \emph on
13387 interrupt
13388 \begin_inset LatexCommand \index{interrupt}
13389
13390 \end_inset
13391
13392
13393 \emph default
13394  functions (see footnote below).
13395  This will in most circumstances make the generated ISR code more efficient
13396  since it will not have to save registers on the stack.
13397
13398 \layout Standard
13399 The 
13400 \emph on
13401 using
13402 \emph default
13403  attribute will have no effect on the generated code for a 
13404 \emph on
13405 non-interrupt
13406 \emph default
13407  function (but may occasionally be useful anyway
13408 \begin_inset Foot
13409 collapsed false
13410
13411 \layout Standard
13412 possible exception: if a function is called ONLY from 'interrupt' functions
13413  using a particular bank, it can be declared with the same 'using' attribute
13414  as the calling 'interrupt' functions.
13415  For instance, if you have several ISRs using bank one, and all of them
13416  call memcpy(), it might make sense to create a specialized version of memcpy()
13417  'using 1', since this would prevent the ISR from having to save bank zero
13418  to the stack on entry and switch to bank zero before calling the function
13419
13420 \end_inset
13421
13422 ).
13423 \newline
13424
13425 \emph on
13426 (pending: Note, nowadays the 
13427 \emph default
13428 using
13429 \emph on
13430  attribute has an effect on
13431 \emph default
13432  
13433 \emph on
13434 the generated code for a 
13435 \emph default
13436 non-interrupt
13437 \emph on
13438  function
13439 \emph default
13440 .
13441 \emph on
13442 )
13443
13444 \layout Standard
13445 An 
13446 \emph on
13447 interrupt
13448 \emph default
13449  function using a non-zero bank will assume that it can trash that register
13450  bank, and will not save it.
13451  Since high-priority interrupts
13452 \begin_inset LatexCommand \index{interrupts}
13453
13454 \end_inset
13455
13456
13457 \begin_inset LatexCommand \index{interrupt priority}
13458
13459 \end_inset
13460
13461  can interrupt low-priority ones on the 8051 and friends, this means that
13462  if a high-priority ISR 
13463 \emph on
13464 using
13465 \emph default
13466  a particular bank occurs while processing a low-priority ISR 
13467 \emph on
13468 using
13469 \emph default
13470  the same bank, terrible and bad things can happen.
13471  To prevent this, no single register bank should be 
13472 \emph on
13473 used
13474 \emph default
13475  by both a high priority and a low priority ISR.
13476  This is probably most easily done by having all high priority ISRs use
13477  one bank and all low priority ISRs use another.
13478  If you have an ISR which can change priority at runtime, you're on your
13479  own: I suggest using the default bank zero and taking the small performance
13480  hit.
13481
13482 \layout Standard
13483 \added_space_bottom bigskip 
13484 It is most efficient if your ISR calls no other functions.
13485  If your ISR must call other functions, it is most efficient if those functions
13486  use the same bank as the ISR (see note 1 below); the next best is if the
13487  called functions use bank zero.
13488  It is very inefficient to call a function using a different, non-zero bank
13489  from an ISR.
13490  
13491
13492
13493
13494 \layout Section
13495 Startup Code
13496 \begin_inset LatexCommand \label{sub:Startup-Code}
13497
13498 \end_inset
13499
13500
13501 \begin_inset LatexCommand \index{Startup code}
13502
13503 \end_inset
13504
13505
13506
13507 \layout Subsection
13508 MCS51/DS390 Startup Code
13509
13510 \layout Standard
13511 The compiler inserts a call to the C routine 
13512 \emph on
13513 _sdcc_external_startup()
13514 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13515
13516 \end_inset
13517
13518
13519 \series bold
13520 \emph default
13521  
13522 \series default
13523 at the start of the CODE area.
13524  This routine is in the runtime library
13525 \begin_inset LatexCommand \index{Runtime library}
13526
13527 \end_inset
13528
13529 .
13530  By default this routine returns 0, if this routine returns a non-zero value,
13531  the static & global variable initialization will be skipped and the function
13532  main will be invoked.
13533  Otherwise static & global variables will be initialized before the function
13534  main is invoked.
13535  You could add a 
13536 \emph on
13537 _sdcc_external_startup()
13538 \emph default
13539  routine to your program to override the default if you need to setup hardware
13540  or perform some other critical operation prior to static & global variable
13541  initialization
13542 \begin_inset LatexCommand \index{Variable initialization}
13543
13544 \end_inset
13545
13546 .
13547  On some mcs51 variants xdata
13548 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13549
13550 \end_inset
13551
13552  memory has to be explicitly enabled before it can be accessed or if the
13553  watchdog
13554 \begin_inset LatexCommand \index{watchdog}
13555
13556 \end_inset
13557
13558  needs to be disabled, this is the place to do it.
13559  The startup code clears all internal data memory, 256 bytes by default,
13560  but from 0 to n-1 if 
13561 \emph on
13562 -
13563 \begin_inset ERT
13564 status Collapsed
13565
13566 \layout Standard
13567
13568
13569 \backslash
13570 /
13571
13572 \end_inset
13573
13574 -iram-size
13575 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13576
13577 \end_inset
13578
13579 n
13580 \emph default
13581  is used.
13582  (recommended for Chipcon CC1010).
13583
13584 \layout Standard
13585 \added_space_bottom bigskip 
13586 See also the compiler options 
13587 \emph on
13588 -
13589 \begin_inset ERT
13590 status Collapsed
13591
13592 \layout Standard
13593
13594
13595 \backslash
13596 /
13597
13598 \end_inset
13599
13600 -no-xinit
13601 \emph default
13602 -
13603 \emph on
13604 opt
13605 \emph default
13606
13607 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13608
13609 \end_inset
13610
13611
13612 \emph on
13613 -
13614 \begin_inset ERT
13615 status Collapsed
13616
13617 \layout Standard
13618
13619
13620 \backslash
13621 /
13622
13623 \end_inset
13624
13625 -main-return
13626 \emph default
13627
13628 \begin_inset LatexCommand \index{-\/-main-return}
13629
13630 \end_inset
13631
13632  and section 
13633 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13634
13635 \end_inset
13636
13637  about MCS51-variants.
13638
13639
13640
13641 \layout Subsection
13642 HC08 Startup Code
13643
13644 \layout Standard
13645 \added_space_bottom bigskip 
13646 The HC08
13647 \begin_inset LatexCommand \index{HC08}
13648
13649 \end_inset
13650
13651  startup code follows the same scheme as the MCS51 startup code.
13652
13653
13654
13655 \layout Subsection
13656 Z80 Startup Code
13657
13658 \layout Standard
13659 \added_space_bottom bigskip 
13660 On the Z80
13661 \begin_inset LatexCommand \index{Z80}
13662
13663 \end_inset
13664
13665  the startup code is inserted by linking with crt0.o which is generated from
13666  sdcc/device/lib/z80/crt0.s.
13667  If you need a different startup code you can use the compiler option 
13668 \emph on
13669 -
13670 \series bold
13671 \emph default
13672
13673 \begin_inset ERT
13674 status Collapsed
13675
13676 \layout Standard
13677
13678
13679 \backslash
13680 /
13681
13682 \end_inset
13683
13684
13685 \series default
13686 \emph on
13687 -no-std-crt0
13688 \emph default
13689
13690 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13691
13692 \end_inset
13693
13694  and provide your own crt0.o.
13695  
13696
13697
13698
13699 \layout Section
13700 Inline Assembler Code
13701 \begin_inset LatexCommand \index{Assembler routines}
13702
13703 \end_inset
13704
13705
13706
13707 \layout Subsection
13708 A Step by Step Introduction
13709 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13710
13711 \end_inset
13712
13713
13714
13715 \layout Standard
13716 Starting from a small snippet of c-code this example shows for the MCS51
13717  how to use inline assembly, access variables, a function parameter and
13718  an array in xdata memory.
13719  The example uses an MCS51 here but is easily adapted for other architectures.
13720  This is a buffer routine which should be optimized:
13721
13722 \layout Verse
13723
13724 \family typewriter
13725 \size footnotesize
13726 unsigned char __far
13727 \begin_inset LatexCommand \index{far (storage class)}
13728
13729 \end_inset
13730
13731
13732 \begin_inset LatexCommand \index{\_\_far (storage class)}
13733
13734 \end_inset
13735
13736  __at
13737 \begin_inset LatexCommand \index{at}
13738
13739 \end_inset
13740
13741
13742 \begin_inset LatexCommand \index{\_\_at}
13743
13744 \end_inset
13745
13746 (0x7f00) buf[0x100];
13747 \begin_inset LatexCommand \index{Aligned array}
13748
13749 \end_inset
13750
13751
13752 \newline
13753 unsigned char head, tail;\SpecialChar ~
13754 \SpecialChar ~
13755 \SpecialChar ~
13756 \SpecialChar ~
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 \SpecialChar ~
13761 \SpecialChar ~
13762 \SpecialChar ~
13763 \SpecialChar ~
13764 \SpecialChar ~
13765 \SpecialChar ~
13766 \SpecialChar ~
13767 \SpecialChar ~
13768 \SpecialChar ~
13769 \SpecialChar ~
13770 /* if interrupts
13771 \begin_inset LatexCommand \index{interrupt}
13772
13773 \end_inset
13774
13775  are involved see
13776 \newline
13777 \SpecialChar ~
13778 \SpecialChar ~
13779 \SpecialChar ~
13780 \SpecialChar ~
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 \SpecialChar ~
13784 \SpecialChar ~
13785 \SpecialChar ~
13786 \SpecialChar ~
13787 \SpecialChar ~
13788 \SpecialChar ~
13789 \SpecialChar ~
13790 \SpecialChar ~
13791 \SpecialChar ~
13792 \SpecialChar ~
13793 \SpecialChar ~
13794 \SpecialChar ~
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 \SpecialChar ~
13798 \SpecialChar ~
13799 \SpecialChar ~
13800 \SpecialChar ~
13801 \SpecialChar ~
13802 \SpecialChar ~
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 \SpecialChar ~
13808 \SpecialChar ~
13809 \SpecialChar ~
13810 \SpecialChar ~
13811 \SpecialChar ~
13812 \SpecialChar ~
13813 \SpecialChar ~
13814 \SpecialChar ~
13815 \SpecialChar ~
13816 \SpecialChar ~
13817 \SpecialChar ~
13818 \SpecialChar ~
13819 \SpecialChar ~
13820 \SpecialChar ~
13821 \SpecialChar ~
13822 section 
13823 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13824
13825 \end_inset
13826
13827  about
13828 \series bold
13829  volatile
13830 \series default
13831  */
13832 \newline
13833
13834 \newline
13835 void to_buffer( unsigned char c ) 
13836 \newline
13837 {
13838 \newline
13839 \SpecialChar ~
13840 \SpecialChar ~
13841 \SpecialChar ~
13842 \SpecialChar ~
13843 if( head != (unsigned char)(tail-1)
13844  )\SpecialChar ~
13845 /* cast 
13846 \series bold
13847 needed
13848 \series default
13849  to avoid promotion
13850 \begin_inset LatexCommand \index{promotion to signed int}
13851
13852 \end_inset
13853
13854
13855 \begin_inset LatexCommand \index{type promotion}
13856
13857 \end_inset
13858
13859  to integer */
13860 \begin_inset Marginal
13861 collapsed true
13862
13863 \layout Standard
13864
13865 \series bold
13866 \SpecialChar ~
13867 !
13868
13869 \end_inset
13870
13871
13872 \newline
13873 \SpecialChar ~
13874 \SpecialChar ~
13875 \SpecialChar ~
13876 \SpecialChar ~
13877 \SpecialChar ~
13878 \SpecialChar ~
13879 \SpecialChar ~
13880 \SpecialChar ~
13881 buf[ head++ ] = c;\SpecialChar ~
13882 \SpecialChar ~
13883 \SpecialChar ~
13884 \SpecialChar ~
13885 \SpecialChar ~
13886 \SpecialChar ~
13887 \SpecialChar ~
13888 \SpecialChar ~
13889 \SpecialChar ~
13890 \SpecialChar ~
13891 \SpecialChar ~
13892 \SpecialChar ~
13893 \SpecialChar ~
13894 \SpecialChar ~
13895 \SpecialChar ~
13896 \SpecialChar ~
13897 /* access to a 256 byte aligned array */
13898 \newline
13899
13900
13901 \layout Standard
13902 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13903  then a corresponding buffer.asm file is generated.
13904  We define a new function 
13905 \family typewriter
13906 to_buffer_asm()
13907 \family default
13908  in file buffer.c in which we cut and paste the generated code, removing
13909  unwanted comments and some ':'.
13910  Then add 
13911 \begin_inset Quotes sld
13912 \end_inset
13913
13914 _asm
13915 \begin_inset Quotes srd
13916 \end_inset
13917
13918  and 
13919 \begin_inset Quotes sld
13920 \end_inset
13921
13922 _endasm;
13923 \begin_inset Quotes srd
13924 \end_inset
13925
13926  to the beginning and the end of the function body:
13927
13928 \layout Verse
13929
13930 \family typewriter
13931 \size footnotesize
13932 /* With a cut and paste from the .asm file, we have something to start with.
13933 \newline
13934 \SpecialChar ~
13935 \SpecialChar ~
13936 \SpecialChar ~
13937 The
13938  function is not yet OK! (registers aren't saved) */ 
13939 \newline
13940 void to_buffer_asm(
13941  unsigned char c ) 
13942 \newline
13943
13944 \newline
13945 \SpecialChar ~
13946 \SpecialChar ~
13947 \SpecialChar ~
13948 \SpecialChar ~
13949 _asm
13950 \begin_inset LatexCommand \index{\_asm}
13951
13952 \end_inset
13953
13954
13955 \begin_inset LatexCommand \index{\_\_asm}
13956
13957 \end_inset
13958
13959
13960 \newline
13961 \SpecialChar ~
13962 \SpecialChar ~
13963 \SpecialChar ~
13964 \SpecialChar ~
13965 mov\SpecialChar ~
13966 \SpecialChar ~
13967 r2,dpl 
13968 \newline
13969 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13970 /* cast 
13971 \series bold
13972 needed
13973 \series default
13974  to avoid promotion
13975 \begin_inset LatexCommand \index{promotion to signed int}
13976
13977 \end_inset
13978
13979
13980 \begin_inset LatexCommand \index{type promotion}
13981
13982 \end_inset
13983
13984  to integer */
13985 \newline
13986 \SpecialChar ~
13987 \SpecialChar ~
13988 \SpecialChar ~
13989 \SpecialChar ~
13990 mov\SpecialChar ~
13991 \SpecialChar ~
13992 a,_tail 
13993 \newline
13994 \SpecialChar ~
13995 \SpecialChar ~
13996 \SpecialChar ~
13997 \SpecialChar ~
13998 dec\SpecialChar ~
13999 \SpecialChar ~
14000
14001 \newline
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 \SpecialChar ~
14005 \SpecialChar ~
14006 mov\SpecialChar ~
14007 \SpecialChar ~
14008 r3,a 
14009 \newline
14010 \SpecialChar ~
14011 \SpecialChar ~
14012 \SpecialChar ~
14013 \SpecialChar ~
14014 mov\SpecialChar ~
14015 \SpecialChar ~
14016 a,_head 
14017 \newline
14018 \SpecialChar ~
14019 \SpecialChar ~
14020 \SpecialChar ~
14021 \SpecialChar ~
14022 cjne a,ar3,00106$ 
14023 \newline
14024 \SpecialChar ~
14025 \SpecialChar ~
14026 \SpecialChar ~
14027 \SpecialChar ~
14028 ret
14029 \newline
14030 00106$:
14031  
14032 \newline
14033 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14034 \begin_inset LatexCommand \index{Aligned array}
14035
14036 \end_inset
14037
14038
14039 \newline
14040 \SpecialChar ~
14041 \SpecialChar ~
14042 \SpecialChar ~
14043 \SpecialChar ~
14044 mov\SpecialChar ~
14045 \SpecialChar ~
14046 r3,_head 
14047 \newline
14048 \SpecialChar ~
14049 \SpecialChar ~
14050 \SpecialChar ~
14051 \SpecialChar ~
14052 inc\SpecialChar ~
14053 \SpecialChar ~
14054 _head 
14055 \newline
14056 \SpecialChar ~
14057 \SpecialChar ~
14058 \SpecialChar ~
14059 \SpecialChar ~
14060 mov\SpecialChar ~
14061 \SpecialChar ~
14062 dpl,r3 
14063 \newline
14064 \SpecialChar ~
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 \SpecialChar ~
14068 mov\SpecialChar ~
14069 \SpecialChar ~
14070 dph,#(_buf >> 8) 
14071 \newline
14072 \SpecialChar ~
14073 \SpecialChar ~
14074 \SpecialChar ~
14075 \SpecialChar ~
14076 mov\SpecialChar ~
14077 \SpecialChar ~
14078 a,r2 
14079 \newline
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 \SpecialChar ~
14084 movx @dptr,a
14085  
14086 \newline
14087 00103$: 
14088 \newline
14089 \SpecialChar ~
14090 \SpecialChar ~
14091 \SpecialChar ~
14092 \SpecialChar ~
14093 ret
14094 \newline
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 \SpecialChar ~
14099 _endasm
14100 \begin_inset LatexCommand \index{\_endasm}
14101
14102 \end_inset
14103
14104
14105 \begin_inset LatexCommand \index{\_\_endasm}
14106
14107 \end_inset
14108
14109 ;
14110 \newline
14111
14112
14113 \layout Standard
14114 The new file buffer.c should compile with only one warning about the unreferenced
14115  function argument 'c'.
14116  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14117  (1) and finally have:
14118
14119 \layout Verse
14120
14121 \family typewriter
14122 \size footnotesize
14123 unsigned char __far __at(0x7f00) buf[0x100];
14124 \newline
14125 unsigned char head, tail;
14126 \newline
14127 #define
14128  USE_ASSEMBLY (1)
14129 \newline
14130
14131 \newline
14132 #if !USE_ASSEMBLY
14133 \newline
14134
14135 \newline
14136 void to_buffer( unsigned char c )
14137 \newline
14138 {
14139 \newline
14140 \SpecialChar ~
14141 \SpecialChar ~
14142 \SpecialChar ~
14143 \SpecialChar ~
14144 if(
14145  head != (unsigned char)(tail-1) )
14146 \newline
14147 \SpecialChar ~
14148 \SpecialChar ~
14149 \SpecialChar ~
14150 \SpecialChar ~
14151 \SpecialChar ~
14152 \SpecialChar ~
14153 \SpecialChar ~
14154 \SpecialChar ~
14155 buf[ head++ ] = c;
14156 \newline
14157 }
14158 \newline
14159
14160 \newline
14161 #else
14162 \newline
14163
14164 \newline
14165 void to_buffer(
14166  unsigned char c )
14167 \newline
14168 {
14169 \newline
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 c; // to avoid warning: unreferenced function argument
14175 \newline
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 \SpecialChar ~
14179 \SpecialChar ~
14180 _asm
14181 \begin_inset LatexCommand \index{\_asm}
14182
14183 \end_inset
14184
14185
14186 \begin_inset LatexCommand \index{\_\_asm}
14187
14188 \end_inset
14189
14190
14191 \newline
14192 \SpecialChar ~
14193 \SpecialChar ~
14194 \SpecialChar ~
14195 \SpecialChar ~
14196 \SpecialChar ~
14197 \SpecialChar ~
14198 \SpecialChar ~
14199 \SpecialChar ~
14200 ; save used registers here.
14201  
14202 \newline
14203 \SpecialChar ~
14204 \SpecialChar ~
14205 \SpecialChar ~
14206 \SpecialChar ~
14207 \SpecialChar ~
14208 \SpecialChar ~
14209 \SpecialChar ~
14210 \SpecialChar ~
14211 ; If we were still using r2,r3 we would have to push them here.
14212  
14213 \newline
14214 ; if( head != (unsigned char)(tail-1) )
14215 \newline
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 \SpecialChar ~
14219 \SpecialChar ~
14220 \SpecialChar ~
14221 \SpecialChar ~
14222 \SpecialChar ~
14223 \SpecialChar ~
14224 mov\SpecialChar ~
14225  a,_tail
14226 \newline
14227 \SpecialChar ~
14228 \SpecialChar ~
14229 \SpecialChar ~
14230 \SpecialChar ~
14231 \SpecialChar ~
14232 \SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 dec\SpecialChar ~
14236  a
14237 \newline
14238 \SpecialChar ~
14239 \SpecialChar ~
14240 \SpecialChar ~
14241 \SpecialChar ~
14242 \SpecialChar ~
14243 \SpecialChar ~
14244 \SpecialChar ~
14245 \SpecialChar ~
14246 xrl\SpecialChar ~
14247  a,_head
14248 \newline
14249 \SpecialChar ~
14250 \SpecialChar ~
14251 \SpecialChar ~
14252 \SpecialChar ~
14253 \SpecialChar ~
14254 \SpecialChar ~
14255 \SpecialChar ~
14256 \SpecialChar ~
14257 ; we
14258  could do an ANL a,#0x0f here to use a smaller buffer (see below)
14259 \newline
14260 \SpecialChar ~
14261 \SpecialChar ~
14262 \SpecialChar ~
14263 \SpecialChar ~
14264 \SpecialChar ~
14265 \SpecialChar ~
14266 \SpecialChar ~
14267 \SpecialChar ~
14268 jz\SpecialChar ~
14269 \SpecialChar ~
14270  t_b_end$
14271 \newline
14272 \SpecialChar ~
14273 \SpecialChar ~
14274 \SpecialChar ~
14275 \SpecialChar ~
14276 \SpecialChar ~
14277 \SpecialChar ~
14278 \SpecialChar ~
14279 \SpecialChar ~
14280 ;
14281 \newline
14282 ;
14283  buf[ head++ ] = c;
14284 \newline
14285 \SpecialChar ~
14286 \SpecialChar ~
14287 \SpecialChar ~
14288 \SpecialChar ~
14289 \SpecialChar ~
14290 \SpecialChar ~
14291 \SpecialChar ~
14292 \SpecialChar ~
14293 mov\SpecialChar ~
14294  a,dpl \SpecialChar ~
14295 \SpecialChar ~
14296 \SpecialChar ~
14297 \SpecialChar ~
14298 \SpecialChar ~
14299 \SpecialChar ~
14300 \SpecialChar ~
14301 ; dpl holds lower byte of function argument
14302 \newline
14303 \SpecialChar ~
14304 \SpecialChar ~
14305 \SpecialChar ~
14306 \SpecialChar ~
14307 \SpecialChar ~
14308 \SpecialChar ~
14309 \SpecialChar ~
14310 \SpecialChar ~
14311 mov\SpecialChar ~
14312
14313  dpl,_head \SpecialChar ~
14314 \SpecialChar ~
14315 \SpecialChar ~
14316 ; buf is 0x100 byte aligned so head can be used directly
14317 \newline
14318 \SpecialChar ~
14319 \SpecialChar ~
14320 \SpecialChar ~
14321 \SpecialChar ~
14322 \SpecialChar ~
14323 \SpecialChar ~
14324 \SpecialChar ~
14325 \SpecialChar ~
14326 mov\SpecialChar ~
14327  dph,#(_bu
14328 f>>8)
14329 \newline
14330 \SpecialChar ~
14331 \SpecialChar ~
14332 \SpecialChar ~
14333 \SpecialChar ~
14334 \SpecialChar ~
14335 \SpecialChar ~
14336 \SpecialChar ~
14337 \SpecialChar ~
14338 movx @dptr,a
14339 \newline
14340 \SpecialChar ~
14341 \SpecialChar ~
14342 \SpecialChar ~
14343 \SpecialChar ~
14344 \SpecialChar ~
14345 \SpecialChar ~
14346 \SpecialChar ~
14347 \SpecialChar ~
14348 inc \SpecialChar ~
14349 _head
14350 \newline
14351 \SpecialChar ~
14352 \SpecialChar ~
14353 \SpecialChar ~
14354 \SpecialChar ~
14355 \SpecialChar ~
14356 \SpecialChar ~
14357 \SpecialChar ~
14358 \SpecialChar ~
14359 ; we could do an ANL _head,#0x0f here to use a
14360  smaller buffer (see above)
14361 \newline
14362 t_b_end$:
14363 \newline
14364 \SpecialChar ~
14365 \SpecialChar ~
14366 \SpecialChar ~
14367 \SpecialChar ~
14368 \SpecialChar ~
14369 \SpecialChar ~
14370 \SpecialChar ~
14371 \SpecialChar ~
14372 ; restore used registers here 
14373 \newline
14374 \SpecialChar ~
14375 \SpecialChar ~
14376 \SpecialChar ~
14377 \SpecialChar ~
14378 _endasm
14379 \begin_inset LatexCommand \index{\_endasm}
14380
14381 \end_inset
14382
14383
14384 \begin_inset LatexCommand \index{\_\_endasm}
14385
14386 \end_inset
14387
14388 ;
14389 \newline
14390 }
14391 \newline
14392 #endif
14393
14394 \layout Standard
14395 The inline assembler code can contain any valid code understood by the assembler
14396 , this includes any assembler directives and comment lines.
14397  The assembler does not like some characters like ':' or ''' in comments.
14398  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
14399 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
14400
14401 \end_inset
14402
14403
14404 \begin_inset LatexCommand \index{Assembler documentation}
14405
14406 \end_inset
14407
14408  or online at 
14409 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
14410
14411 \end_inset
14412
14413 \SpecialChar ~
14414 .
14415
14416 \layout Standard
14417 The compiler does not do any validation of the code within the 
14418 \family typewriter
14419 _asm
14420 \begin_inset LatexCommand \index{\_asm}
14421
14422 \end_inset
14423
14424
14425 \begin_inset LatexCommand \index{\_\_asm}
14426
14427 \end_inset
14428
14429  ...
14430  _endasm
14431 \size footnotesize
14432
14433 \begin_inset LatexCommand \index{\_endasm}
14434
14435 \end_inset
14436
14437
14438 \begin_inset LatexCommand \index{\_\_endasm}
14439
14440 \end_inset
14441
14442
14443 \size default
14444 ;
14445 \family default
14446  keyword pair.
14447  Specifically it will not know which registers are used and thus register
14448  pushing/popping
14449 \begin_inset LatexCommand \index{push/pop}
14450
14451 \end_inset
14452
14453  has to be done manually.
14454  
14455
14456 \layout Standard
14457 It is recommended that each assembly instruction (including labels) be placed
14458  in a separate line (as the example shows).
14459  When the -
14460 \begin_inset ERT
14461 status Collapsed
14462
14463 \layout Standard
14464
14465
14466 \backslash
14467 /
14468
14469 \end_inset
14470
14471 -
14472 \emph on
14473 peep-asm
14474 \begin_inset LatexCommand \index{-\/-peep-asm}
14475
14476 \end_inset
14477
14478
14479 \emph default
14480  command line option is used, the inline assembler code will be passed through
14481  the peephole optimizer
14482 \begin_inset LatexCommand \index{Peephole optimizer}
14483
14484 \end_inset
14485
14486 .
14487  There are only a few (if any) cases where this option makes sense, it might
14488  cause some unexpected changes in the inline assembler code.
14489  Please go through the peephole optimizer rules defined in file 
14490 \emph on
14491 SDCCpeeph.def
14492 \emph default
14493  before using this option.
14494
14495 \layout Subsection
14496 Naked Functions
14497 \begin_inset LatexCommand \label{sub:Naked-Functions}
14498
14499 \end_inset
14500
14501
14502 \begin_inset LatexCommand \index{Naked functions}
14503
14504 \end_inset
14505
14506
14507
14508 \layout Standard
14509 A special keyword may be associated with a function declaring it as 
14510 \emph on
14511 _naked
14512 \begin_inset LatexCommand \index{\_naked}
14513
14514 \end_inset
14515
14516
14517 \begin_inset LatexCommand \index{\_\_naked}
14518
14519 \end_inset
14520
14521 .
14522  
14523 \emph default
14524 The 
14525 \emph on
14526 _naked
14527 \emph default
14528  function modifier attribute prevents the compiler from generating prologue
14529 \begin_inset LatexCommand \index{function prologue}
14530
14531 \end_inset
14532
14533  and epilogue
14534 \begin_inset LatexCommand \index{function epilogue}
14535
14536 \end_inset
14537
14538  code for that function.
14539  This means that the user is entirely responsible for such things as saving
14540  any registers that may need to be preserved, selecting the proper register
14541  bank, generating the 
14542 \emph on
14543 return
14544 \emph default
14545  instruction at the end, etc.
14546  Practically, this means that the contents of the function must be written
14547  in inline assembler.
14548  This is particularly useful for interrupt functions, which can have a large
14549  (and often unnecessary) prologue/epilogue.
14550  For example, compare the code generated by these two functions:
14551
14552 \layout Verse
14553
14554 \family typewriter
14555 volatile
14556 \begin_inset LatexCommand \index{volatile}
14557
14558 \end_inset
14559
14560  data unsigned char counter;
14561 \newline
14562
14563 \newline
14564 void simpleInterrupt(void) __interrupt
14565 \begin_inset LatexCommand \index{interrupt}
14566
14567 \end_inset
14568
14569
14570 \begin_inset LatexCommand \index{\_\_interrupt}
14571
14572 \end_inset
14573
14574  (1)
14575 \newline
14576 {
14577 \newline
14578 \SpecialChar ~
14579 \SpecialChar ~
14580 \SpecialChar ~
14581 \SpecialChar ~
14582 counter++;
14583 \newline
14584 }
14585 \newline
14586
14587 \newline
14588 void nakedInterrupt(void) __interrupt (2) __naked
14589 \newline
14590 {
14591 \newline
14592 \SpecialChar ~
14593 \SpecialChar ~
14594 \SpecialChar ~
14595 \SpecialChar ~
14596 _asm
14597 \begin_inset LatexCommand \index{\_asm}
14598
14599 \end_inset
14600
14601
14602 \begin_inset LatexCommand \index{\_\_asm}
14603
14604 \end_inset
14605
14606
14607 \newline
14608 \SpecialChar ~
14609 \SpecialChar ~
14610 \SpecialChar ~
14611 \SpecialChar ~
14612 \SpecialChar ~
14613 \SpecialChar ~
14614 inc\SpecialChar ~
14615 \SpecialChar ~
14616 \SpecialChar ~
14617 \SpecialChar ~
14618 \SpecialChar ~
14619 _counter ; does not change flags, no need to save psw
14620 \newline
14621 \SpecialChar ~
14622 \SpecialChar ~
14623 \SpecialChar ~
14624 \SpecialChar ~
14625 \SpecialChar ~
14626 \SpecialChar ~
14627 reti\SpecialChar ~
14628 \SpecialChar ~
14629 \SpecialChar ~
14630 \SpecialChar ~
14631 ; MUST explicitly
14632  include ret or reti in _naked function.
14633 \newline
14634 \SpecialChar ~
14635 \SpecialChar ~
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 _endasm
14639 \begin_inset LatexCommand \index{\_endasm}
14640
14641 \end_inset
14642
14643
14644 \begin_inset LatexCommand \index{\_\_endasm}
14645
14646 \end_inset
14647
14648 ;
14649 \newline
14650 }
14651
14652 \layout Standard
14653 For an 8051 target, the generated simpleInterrupt looks like:
14654
14655 \layout Verse
14656
14657 \family typewriter
14658 Note, this is an 
14659 \emph on
14660 outdated
14661 \emph default
14662  example, recent versions of SDCC generate
14663 \newline
14664 the 
14665 \emph on
14666 same
14667 \emph default
14668  code for simpleInterrupt() and nakedInterrupt()!
14669 \newline
14670
14671 \newline
14672 _simpleInterrupt:
14673 \newline
14674 \SpecialChar ~
14675 \SpecialChar ~
14676 \SpecialChar ~
14677 \SpecialChar ~
14678 push\SpecialChar ~
14679 \SpecialChar ~
14680 \SpecialChar ~
14681 \SpecialChar ~
14682 acc
14683 \newline
14684 \SpecialChar ~
14685 \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 push\SpecialChar ~
14689 \SpecialChar ~
14690 \SpecialChar ~
14691 \SpecialChar ~
14692 b
14693 \newline
14694 \SpecialChar ~
14695 \SpecialChar ~
14696 \SpecialChar ~
14697 \SpecialChar ~
14698 pu
14699 sh\SpecialChar ~
14700 \SpecialChar ~
14701 \SpecialChar ~
14702 \SpecialChar ~
14703 dpl
14704 \newline
14705 \SpecialChar ~
14706 \SpecialChar ~
14707 \SpecialChar ~
14708 \SpecialChar ~
14709 push\SpecialChar ~
14710 \SpecialChar ~
14711 \SpecialChar ~
14712 \SpecialChar ~
14713 dph
14714 \newline
14715 \SpecialChar ~
14716 \SpecialChar ~
14717 \SpecialChar ~
14718 \SpecialChar ~
14719 push\SpecialChar ~
14720 \SpecialChar ~
14721 \SpecialChar ~
14722 \SpecialChar ~
14723 psw
14724 \newline
14725 \SpecialChar ~
14726 \SpecialChar ~
14727 \SpecialChar ~
14728 \SpecialChar ~
14729 mov\SpecialChar ~
14730 \SpecialChar ~
14731 \SpecialChar ~
14732 \SpecialChar ~
14733 \SpecialChar ~
14734 psw,#0x00
14735 \newline
14736 \SpecialChar ~
14737 \SpecialChar ~
14738 \SpecialChar ~
14739 \SpecialChar ~
14740 inc\SpecialChar ~
14741 \SpecialChar ~
14742 \SpecialChar ~
14743 \SpecialChar ~
14744 \SpecialChar ~
14745 _counter
14746 \newline
14747 \SpecialChar ~
14748 \SpecialChar ~
14749 \SpecialChar ~
14750 \SpecialChar ~
14751 pop\SpecialChar ~
14752 \SpecialChar ~
14753 \SpecialChar ~
14754 \SpecialChar ~
14755 \SpecialChar ~
14756 psw
14757 \newline
14758 \SpecialChar ~
14759 \SpecialChar ~
14760 \SpecialChar ~
14761 \SpecialChar ~
14762 pop\SpecialChar ~
14763 \SpecialChar ~
14764 \SpecialChar ~
14765 \SpecialChar ~
14766 \SpecialChar ~
14767 dph
14768 \newline
14769 \SpecialChar ~
14770 \SpecialChar ~
14771 \SpecialChar ~
14772 \SpecialChar ~
14773 pop\SpecialChar ~
14774 \SpecialChar ~
14775 \SpecialChar ~
14776 \SpecialChar ~
14777 \SpecialChar ~
14778 dpl
14779 \newline
14780 \SpecialChar ~
14781 \SpecialChar ~
14782 \SpecialChar ~
14783 \SpecialChar ~
14784 pop\SpecialChar ~
14785 \SpecialChar ~
14786 \SpecialChar ~
14787 \SpecialChar ~
14788 \SpecialChar ~
14789 b
14790 \newline
14791 \SpecialChar ~
14792 \SpecialChar ~
14793 \SpecialChar ~
14794 \SpecialChar ~
14795 pop\SpecialChar ~
14796 \SpecialChar ~
14797 \SpecialChar ~
14798 \SpecialChar ~
14799 \SpecialChar ~
14800 acc
14801 \newline
14802 \SpecialChar ~
14803 \SpecialChar ~
14804 \SpecialChar ~
14805 \SpecialChar ~
14806 reti
14807
14808 \layout Standard
14809 whereas nakedInterrupt looks like:
14810
14811 \layout Verse
14812
14813 \family typewriter
14814 _nakedInterrupt:
14815 \newline
14816 \SpecialChar ~
14817 \SpecialChar ~
14818 \SpecialChar ~
14819 \SpecialChar ~
14820 inc\SpecialChar ~
14821 \SpecialChar ~
14822 \SpecialChar ~
14823 \SpecialChar ~
14824 _counter ; does not change flags, no need to save psw
14825 \newline
14826 \SpecialChar ~
14827 \SpecialChar ~
14828 \SpecialChar ~
14829 \SpecialChar ~
14830 reti\SpecialChar ~
14831 \SpecialChar ~
14832 \SpecialChar ~
14833 \SpecialChar ~
14834 \SpecialChar ~
14835 \SpecialChar ~
14836 \SpecialChar ~
14837 \SpecialChar ~
14838 \SpecialChar ~
14839 \SpecialChar ~
14840 \SpecialChar ~
14841 \SpecialChar ~
14842 ;
14843  MUST explicitly include ret or reti in _naked function
14844
14845 \layout Standard
14846 The related directive #pragma exclude
14847 \begin_inset LatexCommand \index{\#pragma exclude}
14848
14849 \end_inset
14850
14851  allows a more fine grained control over pushing & popping
14852 \begin_inset LatexCommand \index{push/pop}
14853
14854 \end_inset
14855
14856  the registers.
14857
14858 \layout Standard
14859 While there is nothing preventing you from writing C code inside a 
14860 \family typewriter
14861 _naked
14862 \family default
14863  function, there are many ways to shoot yourself in the foot doing this,
14864  and it is recommended that you stick to inline assembler.
14865
14866 \layout Subsection
14867 Use of Labels within Inline Assembler
14868
14869 \layout Standard
14870 SDCC allows the use of in-line assembler with a few restrictions regarding
14871  labels.
14872  In older versions of the compiler all labels defined within inline assembler
14873  code 
14874 \emph on
14875 had to be
14876 \emph default
14877  of the form 
14878 \emph on
14879 nnnnn$
14880 \emph default
14881  where nnnn is a number less than 100 (which implies a limit of utmost 100
14882  inline assembler labels 
14883 \emph on
14884 per function
14885 \emph default
14886 \noun on
14887 )
14888 \noun default
14889 .
14890  
14891
14892 \layout Verse
14893
14894 \family typewriter
14895 _asm
14896 \begin_inset LatexCommand \index{\_asm}
14897
14898 \end_inset
14899
14900
14901 \begin_inset LatexCommand \index{\_\_asm}
14902
14903 \end_inset
14904
14905  
14906 \newline
14907 \SpecialChar ~
14908 \SpecialChar ~
14909 \SpecialChar ~
14910 \SpecialChar ~
14911 mov\SpecialChar ~
14912 \SpecialChar ~
14913 \SpecialChar ~
14914 \SpecialChar ~
14915 \SpecialChar ~
14916 b,#10 
14917 \newline
14918 00001$: 
14919 \newline
14920 \SpecialChar ~
14921 \SpecialChar ~
14922 \SpecialChar ~
14923 \SpecialChar ~
14924 djnz\SpecialChar ~
14925 \SpecialChar ~
14926 \SpecialChar ~
14927 \SpecialChar ~
14928 b,00001$ 
14929 \newline
14930 _endasm
14931 \begin_inset LatexCommand \index{\_endasm}
14932
14933 \end_inset
14934
14935
14936 \begin_inset LatexCommand \index{\_\_endasm}
14937
14938 \end_inset
14939
14940  ;
14941
14942 \layout Standard
14943 Inline assembler code cannot reference any C-Labels, however it can reference
14944  labels
14945 \begin_inset LatexCommand \index{Labels}
14946
14947 \end_inset
14948
14949  defined by the inline assembler, e.g.:
14950
14951 \layout Verse
14952
14953 \family typewriter
14954 foo() { 
14955 \newline
14956 \SpecialChar ~
14957 \SpecialChar ~
14958 \SpecialChar ~
14959 \SpecialChar ~
14960 /* some c code */ 
14961 \newline
14962 \SpecialChar ~
14963 \SpecialChar ~
14964 \SpecialChar ~
14965 \SpecialChar ~
14966 _asm 
14967 \newline
14968 \SpecialChar ~
14969 \SpecialChar ~
14970 \SpecialChar ~
14971 \SpecialChar ~
14972 \SpecialChar ~
14973 \SpecialChar ~
14974 ; some assembler code 
14975 \newline
14976 \SpecialChar ~
14977 \SpecialChar ~
14978 \SpecialChar ~
14979 \SpecialChar ~
14980 \SpecialChar ~
14981 \SpecialChar ~
14982 ljmp $0003 
14983 \newline
14984 \SpecialChar ~
14985 \SpecialChar ~
14986 \SpecialChar ~
14987 \SpecialChar ~
14988 _endasm;
14989  
14990 \newline
14991 \SpecialChar ~
14992 \SpecialChar ~
14993 \SpecialChar ~
14994 \SpecialChar ~
14995 /* some more c code */ 
14996 \newline
14997 clabel:\SpecialChar ~
14998 \SpecialChar ~
14999 /* inline assembler cannot reference this
15000  label */ 
15001 \newline
15002 \SpecialChar ~
15003 \SpecialChar ~
15004 \SpecialChar ~
15005 \SpecialChar ~
15006 _asm
15007 \newline
15008 \SpecialChar ~
15009 \SpecialChar ~
15010 \SpecialChar ~
15011 \SpecialChar ~
15012 $0003: ;label (can be referenced by inline assembler only)
15013  
15014 \newline
15015 \SpecialChar ~
15016 \SpecialChar ~
15017 \SpecialChar ~
15018 \SpecialChar ~
15019 _endasm
15020 \begin_inset LatexCommand \index{\_endasm}
15021
15022 \end_inset
15023
15024
15025 \begin_inset LatexCommand \index{\_\_endasm}
15026
15027 \end_inset
15028
15029  ; 
15030 \newline
15031 \SpecialChar ~
15032 \SpecialChar ~
15033 \SpecialChar ~
15034 \SpecialChar ~
15035 /* some more c code */
15036 \newline
15037 }
15038
15039 \layout Standard
15040 In other words inline assembly code can access labels defined in inline
15041  assembly within the scope of the function.
15042  The same goes the other way, i.e.
15043  labels defines in inline assembly can not be accessed by C statements.
15044
15045 \layout Section
15046 Interfacing with Assembler Code
15047 \begin_inset LatexCommand \index{Assembler routines}
15048
15049 \end_inset
15050
15051
15052
15053 \layout Subsection
15054 Global Registers used for Parameter Passing
15055 \begin_inset LatexCommand \index{Parameter passing}
15056
15057 \end_inset
15058
15059
15060
15061 \layout Standard
15062 The compiler always uses the global registers 
15063 \emph on
15064 DPL, DPH
15065 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15066
15067 \end_inset
15068
15069
15070 \begin_inset LatexCommand \index{DPTR}
15071
15072 \end_inset
15073
15074 , B
15075 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15076
15077 \end_inset
15078
15079  
15080 \emph default
15081 and
15082 \emph on
15083  ACC
15084 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15085
15086 \end_inset
15087
15088
15089 \emph default
15090  to pass the first parameter to a routine.
15091  The second parameter onwards is either allocated on the stack (for reentrant
15092  routines or if -
15093 \begin_inset ERT
15094 status Collapsed
15095
15096 \layout Standard
15097
15098
15099 \backslash
15100 /
15101
15102 \end_inset
15103
15104 -stack-auto is used) or in data / xdata memory (depending on the memory
15105  model).
15106  
15107
15108 \layout Subsection
15109 Assembler Routine (non-reentrant)
15110
15111 \layout Standard
15112 In the following example
15113 \begin_inset LatexCommand \index{reentrant}
15114
15115 \end_inset
15116
15117
15118 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
15119
15120 \end_inset
15121
15122  the function c_func calls an assembler routine asm_func, which takes two
15123  parameters
15124 \begin_inset LatexCommand \index{function parameter}
15125
15126 \end_inset
15127
15128 .
15129
15130 \layout Verse
15131
15132 \family typewriter
15133 extern int asm_func(unsigned char, unsigned char);
15134 \newline
15135
15136 \newline
15137 int c_func (unsigned char
15138  i, unsigned char j)
15139 \newline
15140 {
15141 \newline
15142 \SpecialChar ~
15143 \SpecialChar ~
15144 \SpecialChar ~
15145 \SpecialChar ~
15146 return asm_func(i,j);
15147 \newline
15148 }
15149 \newline
15150
15151 \newline
15152 int main()
15153 \newline
15154 {
15155 \newline
15156 \SpecialChar ~
15157 \SpecialChar ~
15158 \SpecialChar ~
15159 \SpecialChar ~
15160 return c_func(10,9);
15161 \newline
15162 }
15163
15164 \layout Standard
15165 The corresponding assembler function is:
15166
15167 \layout Verse
15168
15169 \family typewriter
15170 .globl _asm_func_PARM_2 
15171 \newline
15172 \SpecialChar ~
15173 \SpecialChar ~
15174 \SpecialChar ~
15175 \SpecialChar ~
15176 \SpecialChar ~
15177 \SpecialChar ~
15178 \SpecialChar ~
15179 \SpecialChar ~
15180 .globl _asm_func 
15181 \newline
15182 \SpecialChar ~
15183 \SpecialChar ~
15184 \SpecialChar ~
15185 \SpecialChar ~
15186 \SpecialChar ~
15187 \SpecialChar ~
15188 \SpecialChar ~
15189 \SpecialChar ~
15190 .area OSEG 
15191 \newline
15192 _asm_func_PARM_2:
15193 \newline
15194 \SpecialChar ~
15195 \SpecialChar ~
15196 \SpecialChar ~
15197 \SpecialChar ~
15198 \SpecialChar ~
15199 \SpecialChar ~
15200 \SpecialChar ~
15201 \SpecialChar ~
15202 .ds   
15203  1 
15204 \newline
15205 \SpecialChar ~
15206 \SpecialChar ~
15207 \SpecialChar ~
15208 \SpecialChar ~
15209 \SpecialChar ~
15210 \SpecialChar ~
15211 \SpecialChar ~
15212 \SpecialChar ~
15213 .area CSEG 
15214 \newline
15215 _asm_func: 
15216 \newline
15217 \SpecialChar ~
15218 \SpecialChar ~
15219 \SpecialChar ~
15220 \SpecialChar ~
15221 \SpecialChar ~
15222 \SpecialChar ~
15223 \SpecialChar ~
15224 \SpecialChar ~
15225 mov\SpecialChar ~
15226 \SpecialChar ~
15227 \SpecialChar ~
15228 \SpecialChar ~
15229 a,dpl 
15230 \newline
15231 \SpecialChar ~
15232 \SpecialChar ~
15233 \SpecialChar ~
15234 \SpecialChar ~
15235 \SpecialChar ~
15236 \SpecialChar ~
15237 \SpecialChar ~
15238 \SpecialChar ~
15239 add\SpecialChar ~
15240 \SpecialChar ~
15241 \SpecialChar ~
15242 \SpecialChar ~
15243 a,_asm_func_PARM_2 
15244 \newline
15245 \SpecialChar ~
15246 \SpecialChar ~
15247 \SpecialChar ~
15248 \SpecialChar ~
15249 \SpecialChar ~
15250 \SpecialChar ~
15251 \SpecialChar ~
15252 \SpecialChar ~
15253 mov\SpecialChar ~
15254 \SpecialChar ~
15255 \SpecialChar ~
15256 \SpecialChar ~
15257 dpl,a 
15258 \newline
15259 \SpecialChar ~
15260 \SpecialChar ~
15261 \SpecialChar ~
15262 \SpecialChar ~
15263 \SpecialChar ~
15264 \SpecialChar ~
15265 \SpecialChar ~
15266 \SpecialChar ~
15267 mov\SpecialChar ~
15268 \SpecialChar ~
15269 \SpecialChar ~
15270 \SpecialChar ~
15271 dph
15272 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15273
15274 \end_inset
15275
15276 ,#0x00 
15277 \newline
15278 \SpecialChar ~
15279 \SpecialChar ~
15280 \SpecialChar ~
15281 \SpecialChar ~
15282 \SpecialChar ~
15283 \SpecialChar ~
15284 \SpecialChar ~
15285 \SpecialChar ~
15286 ret
15287
15288 \layout Standard
15289 Note here that the return values
15290 \begin_inset LatexCommand \index{return value}
15291
15292 \end_inset
15293
15294  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
15295  two byte values.
15296  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
15297 b' & 'acc' for four byte values.
15298
15299 \layout Standard
15300 The parameter naming convention is _<function_name>_PARM_<n>, where n is
15301  the parameter number starting from 1, and counting from the left.
15302  The first parameter is passed in 
15303 \begin_inset Quotes eld
15304 \end_inset
15305
15306 dpl
15307 \begin_inset Quotes erd
15308 \end_inset
15309
15310  for a one byte parameter, 
15311 \begin_inset Quotes eld
15312 \end_inset
15313
15314 dptr
15315 \begin_inset Quotes erd
15316 \end_inset
15317
15318  for two bytes, 
15319 \begin_inset Quotes eld
15320 \end_inset
15321
15322 b,dptr
15323 \begin_inset Quotes erd
15324 \end_inset
15325
15326  for three bytes and 
15327 \begin_inset Quotes eld
15328 \end_inset
15329
15330 acc,b,dptr
15331 \begin_inset Quotes erd
15332 \end_inset
15333
15334  for a four bytes parameter.
15335  The variable name for the second parameter will be _<function_name>_PARM_2.
15336 \newline
15337
15338 \newline
15339 Assem
15340 ble the assembler routine with the following command:
15341 \newline
15342
15343 \newline
15344
15345 \family sans
15346 \series bold
15347 asx8051 -losg asmfunc.asm
15348 \newline
15349
15350 \newline
15351
15352 \family default
15353 \series default
15354 Then compile and link the assembler routine to the C source file with the
15355  following command:
15356 \newline
15357
15358 \newline
15359
15360 \family sans
15361 \series bold
15362 sdcc cfunc.c asmfunc.rel
15363
15364 \layout Subsection
15365 Assembler Routine (reentrant)
15366
15367 \layout Standard
15368 In this case
15369 \begin_inset LatexCommand \index{reentrant}
15370
15371 \end_inset
15372
15373
15374 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
15375
15376 \end_inset
15377
15378  the second parameter
15379 \begin_inset LatexCommand \index{function parameter}
15380
15381 \end_inset
15382
15383  onwards will be passed on the stack, the parameters are pushed from right
15384  to left i.e.
15385  after the call the leftmost parameter will be on the top of the stack.
15386  Here is an example:
15387
15388 \layout Verse
15389
15390 \family typewriter
15391 extern int asm_func(unsigned char, unsigned char);
15392 \newline
15393
15394 \newline
15395 int c_func (unsigned char
15396  i, unsigned char j) reentrant 
15397 \newline
15398
15399 \newline
15400 \SpecialChar ~
15401 \SpecialChar ~
15402 \SpecialChar ~
15403 \SpecialChar ~
15404 return asm_func(i,j); 
15405 \newline
15406
15407 \newline
15408
15409 \newline
15410 int main() 
15411 \newline
15412
15413 \newline
15414 \SpecialChar ~
15415 \SpecialChar ~
15416 \SpecialChar ~
15417 \SpecialChar ~
15418 return
15419  c_func(10,9); 
15420 \newline
15421 }
15422
15423 \layout Standard
15424 The corresponding assembler routine is:
15425
15426 \layout Verse
15427
15428 \family typewriter
15429 .globl _asm_func 
15430 \newline
15431 _asm_func: 
15432 \newline
15433 \SpecialChar ~
15434 \SpecialChar ~
15435 \SpecialChar ~
15436 \SpecialChar ~
15437 push  _bp 
15438 \newline
15439 \SpecialChar ~
15440 \SpecialChar ~
15441 \SpecialChar ~
15442 \SpecialChar ~
15443 mov _bp,sp 
15444 \newline
15445 \SpecialChar ~
15446 \SpecialChar ~
15447 \SpecialChar ~
15448 \SpecialChar ~
15449 mov r2,dpl
15450 \newline
15451 \SpecialChar ~
15452 \SpecialChar ~
15453 \SpecialChar ~
15454 \SpecialChar ~
15455 mov a,_bp 
15456 \newline
15457 \SpecialChar ~
15458 \SpecialChar ~
15459 \SpecialChar ~
15460 \SpecialChar ~
15461 add
15462  a,#0xfd 
15463 \newline
15464 \SpecialChar ~
15465 \SpecialChar ~
15466 \SpecialChar ~
15467 \SpecialChar ~
15468 mov r0,a 
15469 \newline
15470 \SpecialChar ~
15471 \SpecialChar ~
15472 \SpecialChar ~
15473 \SpecialChar ~
15474 add  a,#0xfc ;?
15475 \newline
15476 \SpecialChar ~
15477 \SpecialChar ~
15478 \SpecialChar ~
15479 \SpecialChar ~
15480 mov  r1,a 
15481 \newline
15482 \SpecialChar ~
15483 \SpecialChar ~
15484 \SpecialChar ~
15485 \SpecialChar ~
15486 mov  a,@r0 
15487 \newline
15488 \SpecialChar ~
15489 \SpecialChar ~
15490 \SpecialChar ~
15491 \SpecialChar ~
15492 add  a,r2 ;?
15493 \newline
15494 \SpecialChar ~
15495 \SpecialChar ~
15496 \SpecialChar ~
15497 \SpecialChar ~
15498 mov  dpl,a
15499  
15500 \newline
15501 \SpecialChar ~
15502 \SpecialChar ~
15503 \SpecialChar ~
15504 \SpecialChar ~
15505 mov  dph,#0x00 
15506 \newline
15507 \SpecialChar ~
15508 \SpecialChar ~
15509 \SpecialChar ~
15510 \SpecialChar ~
15511 mov  sp,_bp 
15512 \newline
15513 \SpecialChar ~
15514 \SpecialChar ~
15515 \SpecialChar ~
15516 \SpecialChar ~
15517 pop  _bp 
15518 \newline
15519 \SpecialChar ~
15520 \SpecialChar ~
15521 \SpecialChar ~
15522 \SpecialChar ~
15523 ret
15524
15525 \layout Standard
15526 \added_space_bottom bigskip 
15527 The compiling and linking procedure remains the same, however note the extra
15528  entry & exit linkage required for the assembler code, _bp is the stack
15529  frame pointer and is used to compute the offset into the stack for parameters
15530  and local variables.
15531
15532
15533
15534 \layout Section
15535 int (16 bit)
15536 \begin_inset LatexCommand \index{int (16 bit)}
15537
15538 \end_inset
15539
15540  and long (32 bit)
15541 \begin_inset LatexCommand \index{long (32 bit)}
15542
15543 \end_inset
15544
15545  Support
15546
15547 \layout Standard
15548 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
15549  multiplication and modulus operations are implemented by support routines.
15550  These support routines are all developed in ANSI-C to facilitate porting
15551  to other MCUs, although some model specific assembler optimizations are
15552  used.
15553  The following files contain the described routines, all of them can be
15554  found in <installdir>/share/sdcc/lib.
15555 \newline
15556
15557
15558 \layout Standard
15559 \align center
15560 \begin_inset Tabular
15561 <lyxtabular version="3" rows="11" columns="2">
15562 <features>
15563 <column alignment="left" valignment="top" leftline="true" width="0">
15564 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15565 <row topline="true" bottomline="true">
15566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15567 \begin_inset Text
15568
15569 \layout Standard
15570
15571 \series bold
15572 Function
15573
15574 \end_inset
15575 </cell>
15576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15577 \begin_inset Text
15578
15579 \layout Standard
15580
15581 \series bold
15582 Description
15583
15584 \end_inset
15585 </cell>
15586 </row>
15587 <row topline="true">
15588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15589 \begin_inset Text
15590
15591 \layout Standard
15592 _mulint.c 
15593
15594 \end_inset
15595 </cell>
15596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15597 \begin_inset Text
15598
15599 \layout Standard
15600 16 bit multiplication
15601
15602 \end_inset
15603 </cell>
15604 </row>
15605 <row topline="true">
15606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15607 \begin_inset Text
15608
15609 \layout Standard
15610 _divsint.c 
15611
15612 \end_inset
15613 </cell>
15614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15615 \begin_inset Text
15616
15617 \layout Standard
15618  signed 16 bit division (calls _divuint)
15619
15620 \end_inset
15621 </cell>
15622 </row>
15623 <row topline="true">
15624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15625 \begin_inset Text
15626
15627 \layout Standard
15628 _divuint.c 
15629
15630 \end_inset
15631 </cell>
15632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15633 \begin_inset Text
15634
15635 \layout Standard
15636  unsigned 16 bit division
15637
15638 \end_inset
15639 </cell>
15640 </row>
15641 <row topline="true">
15642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15643 \begin_inset Text
15644
15645 \layout Standard
15646 _modsint.c
15647
15648 \end_inset
15649 </cell>
15650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15651 \begin_inset Text
15652
15653 \layout Standard
15654 signed 16 bit modulus (calls _moduint)
15655
15656 \end_inset
15657 </cell>
15658 </row>
15659 <row topline="true">
15660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15661 \begin_inset Text
15662
15663 \layout Standard
15664 _moduint.c
15665
15666 \end_inset
15667 </cell>
15668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15669 \begin_inset Text
15670
15671 \layout Standard
15672 unsigned 16 bit modulus
15673
15674 \end_inset
15675 </cell>
15676 </row>
15677 <row topline="true">
15678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15679 \begin_inset Text
15680
15681 \layout Standard
15682 _mullong.c
15683
15684 \end_inset
15685 </cell>
15686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15687 \begin_inset Text
15688
15689 \layout Standard
15690 32 bit multiplication
15691
15692 \end_inset
15693 </cell>
15694 </row>
15695 <row topline="true">
15696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15697 \begin_inset Text
15698
15699 \layout Standard
15700 _divslong.c 
15701
15702 \end_inset
15703 </cell>
15704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15705 \begin_inset Text
15706
15707 \layout Standard
15708  signed 32 division (calls _divulong)
15709
15710 \end_inset
15711 </cell>
15712 </row>
15713 <row topline="true">
15714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15715 \begin_inset Text
15716
15717 \layout Standard
15718 _divulong.c 
15719
15720 \end_inset
15721 </cell>
15722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15723 \begin_inset Text
15724
15725 \layout Standard
15726 unsigned 32 division
15727
15728 \end_inset
15729 </cell>
15730 </row>
15731 <row topline="true">
15732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15733 \begin_inset Text
15734
15735 \layout Standard
15736 _modslong.c
15737
15738 \end_inset
15739 </cell>
15740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15741 \begin_inset Text
15742
15743 \layout Standard
15744  signed 32 bit modulus (calls _modulong)
15745
15746 \end_inset
15747 </cell>
15748 </row>
15749 <row topline="true" bottomline="true">
15750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15751 \begin_inset Text
15752
15753 \layout Standard
15754 _modulong.c
15755
15756 \end_inset
15757 </cell>
15758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15759 \begin_inset Text
15760
15761 \layout Standard
15762 unsigned 32 bit modulus
15763
15764 \end_inset
15765 </cell>
15766 </row>
15767 </lyxtabular>
15768
15769 \end_inset
15770
15771
15772 \newline
15773
15774
15775 \layout Standard
15776 Since they are compiled as 
15777 \emph on
15778 non-reentrant
15779 \emph default
15780
15781 \begin_inset LatexCommand \index{reentrant}
15782
15783 \end_inset
15784
15785 , interrupt
15786 \begin_inset LatexCommand \index{interrupt}
15787
15788 \end_inset
15789
15790  service routines should not do any of the above operations.
15791  If this is unavoidable then the above routines will need to be compiled
15792  with the 
15793 \emph on
15794 -
15795 \begin_inset ERT
15796 status Collapsed
15797
15798 \layout Standard
15799
15800
15801 \backslash
15802 /
15803
15804 \end_inset
15805
15806 -stack-auto
15807 \begin_inset LatexCommand \index{-\/-stack-auto}
15808
15809 \end_inset
15810
15811
15812 \emph default
15813  option, after which the source program will have to be compiled with 
15814 \emph on
15815 -
15816 \begin_inset ERT
15817 status Collapsed
15818
15819 \layout Standard
15820
15821
15822 \backslash
15823 /
15824
15825 \end_inset
15826
15827 -int-long-reent
15828 \begin_inset LatexCommand \index{-\/-int-long-reent}
15829
15830 \end_inset
15831
15832
15833 \emph default
15834  option.
15835  Notice that you don't have to call these routines directly.
15836  The compiler will use them automatically every time an integer operation
15837  is required.
15838
15839 \layout Section
15840 Floating Point Support
15841 \begin_inset LatexCommand \index{Floating point support}
15842
15843 \end_inset
15844
15845
15846
15847 \layout Standard
15848 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15849  The floating point support routines are derived from gcc's floatlib.c and
15850  consist of the following routines:
15851 \newline
15852
15853
15854 \layout Standard
15855 \align center
15856
15857 \size footnotesize
15858 \begin_inset Tabular
15859 <lyxtabular version="3" rows="17" columns="2">
15860 <features>
15861 <column alignment="left" valignment="top" leftline="true" width="0">
15862 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15863 <row topline="true" bottomline="true">
15864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15865 \begin_inset Text
15866
15867 \layout Standard
15868
15869 \family roman
15870 \series medium
15871 \shape up
15872 \size normal
15873 \emph off
15874 \bar no
15875 \noun off
15876 \color none
15877 Function 
15878
15879 \end_inset
15880 </cell>
15881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15882 \begin_inset Text
15883
15884 \layout Standard
15885 Description
15886
15887 \end_inset
15888 </cell>
15889 </row>
15890 <row topline="true">
15891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15892 \begin_inset Text
15893
15894 \layout Standard
15895
15896 \family roman
15897 \series medium
15898 \shape up
15899 \size normal
15900 \emph off
15901 \bar no
15902 \noun off
15903 \color none
15904 _fsadd.c
15905
15906 \end_inset
15907 </cell>
15908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15909 \begin_inset Text
15910
15911 \layout Standard
15912
15913 \family roman
15914 \series medium
15915 \shape up
15916 \size normal
15917 \emph off
15918 \bar no
15919 \noun off
15920 \color none
15921 add floating point numbers
15922
15923 \end_inset
15924 </cell>
15925 </row>
15926 <row topline="true">
15927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15928 \begin_inset Text
15929
15930 \layout Standard
15931
15932 \family roman
15933 \series medium
15934 \shape up
15935 \size normal
15936 \emph off
15937 \bar no
15938 \noun off
15939 \color none
15940 _fssub.c 
15941
15942 \end_inset
15943 </cell>
15944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15945 \begin_inset Text
15946
15947 \layout Standard
15948
15949 \family roman
15950 \series medium
15951 \shape up
15952 \size normal
15953 \emph off
15954 \bar no
15955 \noun off
15956 \color none
15957 subtract floating point numbers 
15958
15959 \end_inset
15960 </cell>
15961 </row>
15962 <row topline="true">
15963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15964 \begin_inset Text
15965
15966 \layout Standard
15967
15968 \family roman
15969 \series medium
15970 \shape up
15971 \size normal
15972 \emph off
15973 \bar no
15974 \noun off
15975 \color none
15976 _fsdiv.c 
15977
15978 \end_inset
15979 </cell>
15980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15981 \begin_inset Text
15982
15983 \layout Standard
15984
15985 \family roman
15986 \series medium
15987 \shape up
15988 \size normal
15989 \emph off
15990 \bar no
15991 \noun off
15992 \color none
15993 divide floating point numbers 
15994
15995 \end_inset
15996 </cell>
15997 </row>
15998 <row topline="true">
15999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16000 \begin_inset Text
16001
16002 \layout Standard
16003
16004 \family roman
16005 \series medium
16006 \shape up
16007 \size normal
16008 \emph off
16009 \bar no
16010 \noun off
16011 \color none
16012 _fsmul.c 
16013
16014 \end_inset
16015 </cell>
16016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16017 \begin_inset Text
16018
16019 \layout Standard
16020
16021 \family roman
16022 \series medium
16023 \shape up
16024 \size normal
16025 \emph off
16026 \bar no
16027 \noun off
16028 \color none
16029 multiply floating point numbers 
16030
16031 \end_inset
16032 </cell>
16033 </row>
16034 <row topline="true">
16035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16036 \begin_inset Text
16037
16038 \layout Standard
16039
16040 \family roman
16041 \series medium
16042 \shape up
16043 \size normal
16044 \emph off
16045 \bar no
16046 \noun off
16047 \color none
16048 _fs2uchar.c
16049
16050 \end_inset
16051 </cell>
16052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16053 \begin_inset Text
16054
16055 \layout Standard
16056
16057 \family roman
16058 \series medium
16059 \shape up
16060 \size normal
16061 \emph off
16062 \bar no
16063 \noun off
16064 \color none
16065 convert floating point to unsigned char
16066
16067 \end_inset
16068 </cell>
16069 </row>
16070 <row topline="true">
16071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16072 \begin_inset Text
16073
16074 \layout Standard
16075
16076 \family roman
16077 \series medium
16078 \shape up
16079 \size normal
16080 \emph off
16081 \bar no
16082 \noun off
16083 \color none
16084 _fs2char.c
16085
16086 \end_inset
16087 </cell>
16088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16089 \begin_inset Text
16090
16091 \layout Standard
16092
16093 \family roman
16094 \series medium
16095 \shape up
16096 \size normal
16097 \emph off
16098 \bar no
16099 \noun off
16100 \color none
16101 convert floating point to signed char
16102
16103 \end_inset
16104 </cell>
16105 </row>
16106 <row topline="true">
16107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16108 \begin_inset Text
16109
16110 \layout Standard
16111
16112 \family roman
16113 \series medium
16114 \shape up
16115 \size normal
16116 \emph off
16117 \bar no
16118 \noun off
16119 \color none
16120 _fs2uint.c
16121
16122 \end_inset
16123 </cell>
16124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16125 \begin_inset Text
16126
16127 \layout Standard
16128
16129 \family roman
16130 \series medium
16131 \shape up
16132 \size normal
16133 \emph off
16134 \bar no
16135 \noun off
16136 \color none
16137 convert floating point to unsigned int
16138
16139 \end_inset
16140 </cell>
16141 </row>
16142 <row topline="true">
16143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16144 \begin_inset Text
16145
16146 \layout Standard
16147
16148 \family roman
16149 \series medium
16150 \shape up
16151 \size normal
16152 \emph off
16153 \bar no
16154 \noun off
16155 \color none
16156 _fs2int.c
16157
16158 \end_inset
16159 </cell>
16160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16161 \begin_inset Text
16162
16163 \layout Standard
16164
16165 \family roman
16166 \series medium
16167 \shape up
16168 \size normal
16169 \emph off
16170 \bar no
16171 \noun off
16172 \color none
16173 convert floating point to signed int
16174
16175 \end_inset
16176 </cell>
16177 </row>
16178 <row topline="true">
16179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16180 \begin_inset Text
16181
16182 \layout Standard
16183
16184 \family roman
16185 \series medium
16186 \shape up
16187 \size normal
16188 \emph off
16189 \bar no
16190 \noun off
16191 \color none
16192 _fs2ulong.
16193 \family default
16194 \series default
16195 \shape default
16196 \size default
16197 \emph default
16198 \bar default
16199 \noun default
16200 c
16201
16202 \end_inset
16203 </cell>
16204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16205 \begin_inset Text
16206
16207 \layout Standard
16208
16209 \family roman
16210 \series medium
16211 \shape up
16212 \size normal
16213 \emph off
16214 \bar no
16215 \noun off
16216 \color none
16217 convert floating point to unsigned long
16218
16219 \end_inset
16220 </cell>
16221 </row>
16222 <row topline="true">
16223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16224 \begin_inset Text
16225
16226 \layout Standard
16227
16228 \family roman
16229 \series medium
16230 \shape up
16231 \size normal
16232 \emph off
16233 \bar no
16234 \noun off
16235 \color none
16236 _fs2long.c
16237
16238 \end_inset
16239 </cell>
16240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16241 \begin_inset Text
16242
16243 \layout Standard
16244
16245 \family roman
16246 \series medium
16247 \shape up
16248 \size normal
16249 \emph off
16250 \bar no
16251 \noun off
16252 \color none
16253 convert floating point to signed long
16254
16255 \end_inset
16256 </cell>
16257 </row>
16258 <row topline="true">
16259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16260 \begin_inset Text
16261
16262 \layout Standard
16263
16264 \family roman
16265 \series medium
16266 \shape up
16267 \size normal
16268 \emph off
16269 \bar no
16270 \noun off
16271 \color none
16272 _uchar2fs.c
16273
16274 \end_inset
16275 </cell>
16276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16277 \begin_inset Text
16278
16279 \layout Standard
16280
16281 \family roman
16282 \series medium
16283 \shape up
16284 \size normal
16285 \emph off
16286 \bar no
16287 \noun off
16288 \color none
16289 convert unsigned char to floating point
16290
16291 \end_inset
16292 </cell>
16293 </row>
16294 <row topline="true">
16295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16296 \begin_inset Text
16297
16298 \layout Standard
16299
16300 \family roman
16301 \series medium
16302 \shape up
16303 \size normal
16304 \emph off
16305 \bar no
16306 \noun off
16307 \color none
16308 _char2fs.c
16309
16310 \end_inset
16311 </cell>
16312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16313 \begin_inset Text
16314
16315 \layout Standard
16316
16317 \family roman
16318 \series medium
16319 \shape up
16320 \size normal
16321 \emph off
16322 \bar no
16323 \noun off
16324 \color none
16325 convert char to floating point number
16326
16327 \end_inset
16328 </cell>
16329 </row>
16330 <row topline="true">
16331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16332 \begin_inset Text
16333
16334 \layout Standard
16335
16336 \family roman
16337 \series medium
16338 \shape up
16339 \size normal
16340 \emph off
16341 \bar no
16342 \noun off
16343 \color none
16344 _uint2fs.c
16345
16346 \end_inset
16347 </cell>
16348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16349 \begin_inset Text
16350
16351 \layout Standard
16352
16353 \family roman
16354 \series medium
16355 \shape up
16356 \size normal
16357 \emph off
16358 \bar no
16359 \noun off
16360 \color none
16361 convert unsigned int to floating point
16362
16363 \end_inset
16364 </cell>
16365 </row>
16366 <row topline="true">
16367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16368 \begin_inset Text
16369
16370 \layout Standard
16371
16372 \family roman
16373 \series medium
16374 \shape up
16375 \size normal
16376 \emph off
16377 \bar no
16378 \noun off
16379 \color none
16380 _int2fs.c
16381
16382 \end_inset
16383 </cell>
16384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16385 \begin_inset Text
16386
16387 \layout Standard
16388
16389 \family roman
16390 \series medium
16391 \shape up
16392 \size normal
16393 \emph off
16394 \bar no
16395 \noun off
16396 \color none
16397 convert int to floating point numbers
16398
16399 \end_inset
16400 </cell>
16401 </row>
16402 <row topline="true">
16403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16404 \begin_inset Text
16405
16406 \layout Standard
16407
16408 \family roman
16409 \series medium
16410 \shape up
16411 \size normal
16412 \emph off
16413 \bar no
16414 \noun off
16415 \color none
16416 _ulong2fs.c
16417
16418 \end_inset
16419 </cell>
16420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16421 \begin_inset Text
16422
16423 \layout Standard
16424
16425 \family roman
16426 \series medium
16427 \shape up
16428 \size normal
16429 \emph off
16430 \bar no
16431 \noun off
16432 \color none
16433 convert unsigned long to floating point number
16434
16435 \end_inset
16436 </cell>
16437 </row>
16438 <row topline="true" bottomline="true">
16439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16440 \begin_inset Text
16441
16442 \layout Standard
16443
16444 \family roman
16445 \series medium
16446 \shape up
16447 \size normal
16448 \emph off
16449 \bar no
16450 \noun off
16451 \color none
16452 _long2fs.c
16453
16454 \end_inset
16455 </cell>
16456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16457 \begin_inset Text
16458
16459 \layout Standard
16460
16461 \family roman
16462 \series medium
16463 \shape up
16464 \size normal
16465 \emph off
16466 \bar no
16467 \noun off
16468 \color none
16469 convert long to floating point number
16470
16471 \end_inset
16472 </cell>
16473 </row>
16474 </lyxtabular>
16475
16476 \end_inset
16477
16478
16479 \newline
16480
16481
16482 \layout Standard
16483 \added_space_bottom bigskip 
16484 These support routines are developed in ANSI-C so there is room for space
16485  and speed improvement
16486 \begin_inset Foot
16487 collapsed false
16488
16489 \layout Standard
16490 These floating point routines (
16491 \emph on
16492 not
16493 \emph default
16494  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
16495  
16496
16497 \end_inset
16498
16499 .
16500  Note if all these routines are used simultaneously the data space might
16501  overflow.
16502  For serious floating point usage the large model might be needed.
16503  Also notice that you don't have to call this routines directly.
16504  The compiler will use them automatically every time a floating point operation
16505  is required.
16506
16507
16508
16509 \layout Section
16510 Library Routines
16511 \begin_inset LatexCommand \index{Libraries}
16512
16513 \end_inset
16514
16515
16516
16517 \layout Standard
16518
16519 \emph on
16520 <pending: this is messy and incomplete - a little more information is in
16521  sdcc/doc/libdoc.txt
16522 \emph default
16523  >
16524
16525 \layout Subsection
16526 Compiler support routines (_gptrget, _mulint etc.)
16527
16528 \layout Subsection
16529 Stdclib functions (puts, printf, strcat etc.)
16530
16531 \layout Subsubsection
16532 <stdio.h>
16533
16534 \layout Paragraph
16535 getchar(), putchar()
16536
16537 \layout Standard
16538 \begin_inset LatexCommand \index{<stdio.h>}
16539
16540 \end_inset
16541
16542 As usual on embedded systems you have to provide your own 
16543 \family typewriter
16544 getchar()
16545 \begin_inset LatexCommand \index{getchar()}
16546
16547 \end_inset
16548
16549  
16550 \family default
16551 and 
16552 \family typewriter
16553 putchar()
16554 \begin_inset LatexCommand \index{putchar()}
16555
16556 \end_inset
16557
16558
16559 \family default
16560  routines.
16561  SDCC does not know whether the system connects to a serial line with or
16562  without handshake, LCD, keyboard or other device.
16563  And whether a 
16564 \family typewriter
16565 lf
16566 \family default
16567  to 
16568 \family typewriter
16569 crlf
16570 \family default
16571  conversion within 
16572 \family typewriter
16573 putchar()
16574 \family default
16575  is intended.
16576  You'll find examples for serial routines f.e.
16577  in sdcc/device/lib.
16578  For the mcs51 this minimalistic polling 
16579 \family typewriter
16580 putchar()
16581 \family default
16582  routine might be a start:
16583
16584 \layout Verse
16585
16586 \family typewriter
16587 void putchar (char c) { 
16588 \newline
16589 \SpecialChar ~
16590 \SpecialChar ~
16591 \SpecialChar ~
16592 \SpecialChar ~
16593 while (!TI)\SpecialChar ~
16594 \SpecialChar ~
16595 \SpecialChar ~
16596  /* assumes UART is initialized */
16597 \newline
16598 \SpecialChar ~
16599 \SpecialChar ~
16600 \SpecialChar ~
16601 \SpecialChar ~
16602 \SpecialChar ~
16603 \SpecialChar ~
16604 \SpecialChar ~
16605 \SpecialChar ~
16606 ;
16607 \newline
16608 \SpecialChar ~
16609 \SpecialChar ~
16610 \SpecialChar ~
16611 \SpecialChar ~
16612 TI
16613  = 0;
16614 \newline
16615 \SpecialChar ~
16616 \SpecialChar ~
16617 \SpecialChar ~
16618 \SpecialChar ~
16619 SBUF = c;
16620 \newline
16621 }
16622
16623 \layout Paragraph
16624 printf()
16625
16626 \layout Standard
16627 The default
16628 \family typewriter
16629  printf()
16630 \begin_inset LatexCommand \index{printf()}
16631
16632 \end_inset
16633
16634
16635 \family default
16636  implementation in
16637 \family typewriter
16638  printf_large.c
16639 \family default
16640  does not support float (except on ds390).
16641  To enable this recompile it with the option 
16642 \emph on
16643 -
16644 \begin_inset ERT
16645 status Collapsed
16646
16647 \layout Standard
16648
16649
16650 \backslash
16651 /
16652
16653 \end_inset
16654
16655 DUSE_FLOATS=1
16656 \begin_inset LatexCommand \index{USE\_FLOATS}
16657
16658 \end_inset
16659
16660
16661 \emph default
16662  on the command line.
16663  Use
16664 \emph on
16665  -
16666 \begin_inset ERT
16667 status Collapsed
16668
16669 \layout Standard
16670
16671
16672 \backslash
16673 /
16674
16675 \end_inset
16676
16677 -model-large
16678 \begin_inset LatexCommand \index{-\/-model-large}
16679
16680 \end_inset
16681
16682
16683 \emph default
16684  for the mcs51 port, since this uses a lot of memory.
16685
16686 \layout Standard
16687 If you're short on code memory you might want to use 
16688 \family typewriter
16689 printf_small()
16690 \begin_inset LatexCommand \index{printf\_small()}
16691
16692 \end_inset
16693
16694
16695 \family default
16696  
16697 \emph on
16698 instead
16699 \emph default
16700  of
16701 \family typewriter
16702  printf().
16703
16704 \family default
16705  For the mcs51 there additionally are assembly versions 
16706 \family typewriter
16707 printf_tiny()
16708 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16709
16710 \end_inset
16711
16712
16713 \family default
16714  (subset of printf using less than 270 bytes) and 
16715 \family typewriter
16716 printf_fast()
16717 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16718
16719 \end_inset
16720
16721  
16722 \family default
16723 and
16724 \family typewriter
16725  printf_fast_f()
16726 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16727
16728 \end_inset
16729
16730
16731 \family default
16732  (floating-point aware version of printf_fast) which should fit the requirements
16733  of many embedded systems (printf_fast() can be customized by unsetting
16734  #defines to 
16735 \emph on
16736 not
16737 \emph default
16738  support long variables and field widths).
16739  Be sure to only use only one of these printf options within a project.
16740 \newline
16741
16742
16743 \layout Standard
16744 Feature matrix of different 
16745 \emph on
16746 printf
16747 \emph default
16748  options on mcs51.
16749
16750 \layout Standard
16751 \begin_inset Tabular
16752 <lyxtabular version="3" rows="14" columns="7">
16753 <features islongtable="true">
16754 <column alignment="left" valignment="center" leftline="true" width="14col%">
16755 <column alignment="center" valignment="top" leftline="true" width="0">
16756 <column alignment="center" valignment="top" leftline="true" width="12col%">
16757 <column alignment="center" valignment="top" leftline="true" width="10col%">
16758 <column alignment="center" valignment="top" leftline="true" width="0">
16759 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
16760 <column alignment="center" valignment="top" rightline="true" width="0">
16761 <row topline="true" bottomline="true" endhead="true">
16762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16763 \begin_inset Text
16764
16765 \layout Standard
16766
16767 \series bold
16768 \size large
16769 mcs51
16770
16771 \end_inset
16772 </cell>
16773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16774 \begin_inset Text
16775
16776 \layout Standard
16777 printf
16778 \begin_inset LatexCommand \index{printf}
16779
16780 \end_inset
16781
16782
16783
16784 \end_inset
16785 </cell>
16786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16787 \begin_inset Text
16788
16789 \layout Standard
16790 printf 
16791 \size scriptsize
16792 USE_FLOATS=1
16793
16794 \end_inset
16795 </cell>
16796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16797 \begin_inset Text
16798
16799 \layout Standard
16800 printf_small
16801
16802 \end_inset
16803 </cell>
16804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16805 \begin_inset Text
16806
16807 \layout Standard
16808 printf_fast
16809
16810 \end_inset
16811 </cell>
16812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16813 \begin_inset Text
16814
16815 \layout Standard
16816 printf_fast_f
16817
16818 \end_inset
16819 </cell>
16820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16821 \begin_inset Text
16822
16823 \layout Standard
16824 printf_tiny
16825
16826 \end_inset
16827 </cell>
16828 </row>
16829 <row topline="true" endhead="true">
16830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16831 \begin_inset Text
16832
16833 \layout Standard
16834 filename
16835
16836 \end_inset
16837 </cell>
16838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16839 \begin_inset Text
16840
16841 \layout Standard
16842
16843 \size scriptsize
16844 printf_large.c
16845
16846 \end_inset
16847 </cell>
16848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16849 \begin_inset Text
16850
16851 \layout Standard
16852
16853 \size scriptsize
16854 printf_large.c
16855
16856 \end_inset
16857 </cell>
16858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16859 \begin_inset Text
16860
16861 \layout Standard
16862
16863 \size scriptsize
16864 printfl.c
16865
16866 \end_inset
16867 </cell>
16868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16869 \begin_inset Text
16870
16871 \layout Standard
16872
16873 \size scriptsize
16874 printf_fast.c
16875
16876 \end_inset
16877 </cell>
16878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16879 \begin_inset Text
16880
16881 \layout Standard
16882
16883 \size scriptsize
16884 printf_fast_f.c
16885
16886 \end_inset
16887 </cell>
16888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16889 \begin_inset Text
16890
16891 \layout Standard
16892
16893 \size scriptsize
16894 printf_tiny.c
16895
16896 \end_inset
16897 </cell>
16898 </row>
16899 <row topline="true" endhead="true">
16900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16901 \begin_inset Text
16902
16903 \layout Standard
16904 \begin_inset Quotes sld
16905 \end_inset
16906
16907 Hello World
16908 \begin_inset Quotes srd
16909 \end_inset
16910
16911  size
16912
16913 \layout Standard
16914 small / large
16915
16916 \end_inset
16917 </cell>
16918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16919 \begin_inset Text
16920
16921 \layout Standard
16922 1.7k / 2.4k
16923
16924 \end_inset
16925 </cell>
16926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16927 \begin_inset Text
16928
16929 \layout Standard
16930 4.3k / 5.6k
16931
16932 \end_inset
16933 </cell>
16934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16935 \begin_inset Text
16936
16937 \layout Standard
16938 1.2k / 1.8k
16939
16940 \end_inset
16941 </cell>
16942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16943 \begin_inset Text
16944
16945 \layout Standard
16946 1.3k / 1.3k
16947
16948 \end_inset
16949 </cell>
16950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16951 \begin_inset Text
16952
16953 \layout Standard
16954 1.9k / 1.9k
16955
16956 \end_inset
16957 </cell>
16958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16959 \begin_inset Text
16960
16961 \layout Standard
16962 0.44k / 0.44k
16963
16964 \end_inset
16965 </cell>
16966 </row>
16967 <row topline="true" endhead="true">
16968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16969 \begin_inset Text
16970
16971 \layout Standard
16972 code size
16973
16974 \layout Standard
16975 small / large
16976
16977 \end_inset
16978 </cell>
16979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16980 \begin_inset Text
16981
16982 \layout Standard
16983 1.4k / 2.0k
16984
16985 \end_inset
16986 </cell>
16987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16988 \begin_inset Text
16989
16990 \layout Standard
16991 2.8k / 3.7k
16992
16993 \end_inset
16994 </cell>
16995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16996 \begin_inset Text
16997
16998 \layout Standard
16999 0.45k / 0.47k (+ _ltoa)
17000
17001 \end_inset
17002 </cell>
17003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17004 \begin_inset Text
17005
17006 \layout Standard
17007 1.2k / 1.2k
17008
17009 \end_inset
17010 </cell>
17011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17012 \begin_inset Text
17013
17014 \layout Standard
17015 1.6k / 1.6k
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 0.26k / 0.26k
17024
17025 \end_inset
17026 </cell>
17027 </row>
17028 <row topline="true">
17029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17030 \begin_inset Text
17031
17032 \layout Standard
17033 formats
17034
17035 \end_inset
17036 </cell>
17037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17038 \begin_inset Text
17039
17040 \layout Standard
17041 cdi
17042 \emph on
17043 o
17044 \emph default
17045 psux
17046
17047 \end_inset
17048 </cell>
17049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17050 \begin_inset Text
17051
17052 \layout Standard
17053
17054 \family roman
17055 \series medium
17056 \shape up
17057 \size normal
17058 \emph off
17059 \bar no
17060 \noun off
17061 \color none
17062 cd
17063 \family default
17064 \series default
17065 \shape default
17066 \size default
17067 \emph default
17068 \bar default
17069 \noun default
17070 f
17071 \family roman
17072 \series medium
17073 \shape up
17074 \size normal
17075 \emph off
17076 \bar no
17077 \noun off
17078 i
17079 \family default
17080 \series default
17081 \shape default
17082 \size default
17083 \emph on
17084 \bar default
17085 \noun default
17086 o
17087 \family roman
17088 \series medium
17089 \shape up
17090 \size normal
17091 \emph off
17092 \bar no
17093 \noun off
17094 psux
17095
17096 \end_inset
17097 </cell>
17098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17099 \begin_inset Text
17100
17101 \layout Standard
17102 c
17103 \family roman
17104 \series medium
17105 \shape up
17106 \size normal
17107 \emph off
17108 \bar no
17109 \noun off
17110 \color none
17111 d
17112 \family default
17113 \series default
17114 \shape default
17115 \size default
17116 \emph on
17117 \bar default
17118 \noun default
17119 o
17120 \family roman
17121 \series medium
17122 \shape up
17123 \size normal
17124 \emph off
17125 \bar no
17126 \noun off
17127 s
17128 \family default
17129 \series default
17130 \shape default
17131 \size default
17132 \emph default
17133 \bar default
17134 \noun default
17135 x
17136
17137 \end_inset
17138 </cell>
17139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17140 \begin_inset Text
17141
17142 \layout Standard
17143 cdsux
17144
17145 \end_inset
17146 </cell>
17147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17148 \begin_inset Text
17149
17150 \layout Standard
17151 cdfsux
17152
17153 \end_inset
17154 </cell>
17155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17156 \begin_inset Text
17157
17158 \layout Standard
17159 cdsux
17160
17161 \end_inset
17162 </cell>
17163 </row>
17164 <row topline="true">
17165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17166 \begin_inset Text
17167
17168 \layout Standard
17169 long (32 bit) support
17170
17171 \end_inset
17172 </cell>
17173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17174 \begin_inset Text
17175
17176 \layout Standard
17177 x
17178
17179 \end_inset
17180 </cell>
17181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17182 \begin_inset Text
17183
17184 \layout Standard
17185 x
17186
17187 \end_inset
17188 </cell>
17189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17190 \begin_inset Text
17191
17192 \layout Standard
17193 x
17194
17195 \end_inset
17196 </cell>
17197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17198 \begin_inset Text
17199
17200 \layout Standard
17201 x
17202
17203 \end_inset
17204 </cell>
17205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17206 \begin_inset Text
17207
17208 \layout Standard
17209
17210 \family roman
17211 \series medium
17212 \shape up
17213 \size normal
17214 \emph off
17215 \bar no
17216 \noun off
17217 \color none
17218 x
17219
17220 \end_inset
17221 </cell>
17222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17223 \begin_inset Text
17224
17225 \layout Standard
17226 -
17227
17228 \end_inset
17229 </cell>
17230 </row>
17231 <row topline="true">
17232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17233 \begin_inset Text
17234
17235 \layout Standard
17236 byte arguments on stack
17237
17238 \end_inset
17239 </cell>
17240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17241 \begin_inset Text
17242
17243 \layout Standard
17244 b
17245
17246 \end_inset
17247 </cell>
17248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17249 \begin_inset Text
17250
17251 \layout Standard
17252 b
17253
17254 \end_inset
17255 </cell>
17256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17257 \begin_inset Text
17258
17259 \layout Standard
17260 -
17261
17262 \end_inset
17263 </cell>
17264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17265 \begin_inset Text
17266
17267 \layout Standard
17268 -
17269
17270 \end_inset
17271 </cell>
17272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17273 \begin_inset Text
17274
17275 \layout Standard
17276 -
17277
17278 \end_inset
17279 </cell>
17280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17281 \begin_inset Text
17282
17283 \layout Standard
17284 -
17285
17286 \end_inset
17287 </cell>
17288 </row>
17289 <row topline="true">
17290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17291 \begin_inset Text
17292
17293 \layout Standard
17294 float format
17295 \begin_inset LatexCommand \index{Floating point support}
17296
17297 \end_inset
17298
17299
17300
17301 \end_inset
17302 </cell>
17303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17304 \begin_inset Text
17305
17306 \layout Standard
17307 -
17308
17309 \end_inset
17310 </cell>
17311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17312 \begin_inset Text
17313
17314 \layout Standard
17315 %f
17316
17317 \end_inset
17318 </cell>
17319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17320 \begin_inset Text
17321
17322 \layout Standard
17323 -
17324
17325 \end_inset
17326 </cell>
17327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17328 \begin_inset Text
17329
17330 \layout Standard
17331 -
17332
17333 \end_inset
17334 </cell>
17335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17336 \begin_inset Text
17337
17338 \layout Standard
17339 %f
17340 \begin_inset Foot
17341 collapsed true
17342
17343 \layout Standard
17344 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
17345
17346 \end_inset
17347
17348
17349
17350 \end_inset
17351 </cell>
17352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17353 \begin_inset Text
17354
17355 \layout Standard
17356 -
17357
17358 \end_inset
17359 </cell>
17360 </row>
17361 <row topline="true">
17362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17363 \begin_inset Text
17364
17365 \layout Standard
17366 float formats %e %g
17367
17368 \end_inset
17369 </cell>
17370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17371 \begin_inset Text
17372
17373 \layout Standard
17374 -
17375
17376 \end_inset
17377 </cell>
17378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17379 \begin_inset Text
17380
17381 \layout Standard
17382 -
17383
17384 \end_inset
17385 </cell>
17386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17387 \begin_inset Text
17388
17389 \layout Standard
17390 -
17391
17392 \end_inset
17393 </cell>
17394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17395 \begin_inset Text
17396
17397 \layout Standard
17398 -
17399
17400 \end_inset
17401 </cell>
17402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17403 \begin_inset Text
17404
17405 \layout Standard
17406 -
17407
17408 \end_inset
17409 </cell>
17410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17411 \begin_inset Text
17412
17413 \layout Standard
17414 -
17415
17416 \end_inset
17417 </cell>
17418 </row>
17419 <row topline="true" bottomline="true">
17420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17421 \begin_inset Text
17422
17423 \layout Standard
17424 field width
17425
17426 \end_inset
17427 </cell>
17428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17429 \begin_inset Text
17430
17431 \layout Standard
17432 x
17433
17434 \end_inset
17435 </cell>
17436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17437 \begin_inset Text
17438
17439 \layout Standard
17440 x
17441
17442 \end_inset
17443 </cell>
17444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17445 \begin_inset Text
17446
17447 \layout Standard
17448 -
17449
17450 \end_inset
17451 </cell>
17452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17453 \begin_inset Text
17454
17455 \layout Standard
17456 x
17457
17458 \end_inset
17459 </cell>
17460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17461 \begin_inset Text
17462
17463 \layout Standard
17464 x
17465
17466 \end_inset
17467 </cell>
17468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17469 \begin_inset Text
17470
17471 \layout Standard
17472 -
17473
17474 \end_inset
17475 </cell>
17476 </row>
17477 <row bottomline="true">
17478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17479 \begin_inset Text
17480
17481 \layout Standard
17482 string speed
17483 \begin_inset Foot
17484 collapsed true
17485
17486 \layout Standard
17487 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
17488 \backslash
17489 r', '
17490 \backslash
17491 n'); standard 8051 @ 22.1184 MHz, empty putchar()
17492
17493 \end_inset
17494
17495 ,
17496
17497 \layout Standard
17498 small / large
17499
17500 \end_inset
17501 </cell>
17502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17503 \begin_inset Text
17504
17505 \layout Standard
17506 1.52 / 2.59 ms
17507
17508 \end_inset
17509 </cell>
17510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17511 \begin_inset Text
17512
17513 \layout Standard
17514 1.53 / 2.62 ms
17515
17516 \end_inset
17517 </cell>
17518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17519 \begin_inset Text
17520
17521 \layout Standard
17522 0.92 / 0.93 ms
17523
17524 \end_inset
17525 </cell>
17526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17527 \begin_inset Text
17528
17529 \layout Standard
17530 0.45 / 0.45 ms
17531
17532 \end_inset
17533 </cell>
17534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17535 \begin_inset Text
17536
17537 \layout Standard
17538 0.46 / 0.46 ms
17539
17540 \end_inset
17541 </cell>
17542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17543 \begin_inset Text
17544
17545 \layout Standard
17546 0.45 / 0.45 ms
17547
17548 \end_inset
17549 </cell>
17550 </row>
17551 <row bottomline="true">
17552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17553 \begin_inset Text
17554
17555 \layout Standard
17556 int speed
17557 \begin_inset Foot
17558 collapsed true
17559
17560 \layout Standard
17561 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
17562  putchar()
17563
17564 \end_inset
17565
17566 ,
17567
17568 \layout Standard
17569 small / large
17570
17571 \end_inset
17572 </cell>
17573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17574 \begin_inset Text
17575
17576 \layout Standard
17577 3.01 / 3.61 ms
17578
17579 \end_inset
17580 </cell>
17581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17582 \begin_inset Text
17583
17584 \layout Standard
17585 3.01 / 3.61 ms
17586
17587 \end_inset
17588 </cell>
17589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17590 \begin_inset Text
17591
17592 \layout Standard
17593 3.51 / 18.13 ms
17594
17595 \end_inset
17596 </cell>
17597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17598 \begin_inset Text
17599
17600 \layout Standard
17601 0.22 / 0.22 ms
17602
17603 \end_inset
17604 </cell>
17605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17606 \begin_inset Text
17607
17608 \layout Standard
17609 0.23 / 0.23 ms
17610
17611 \end_inset
17612 </cell>
17613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17614 \begin_inset Text
17615
17616 \layout Standard
17617 0.25 / 0.25 ms
17618 \begin_inset Foot
17619 collapsed true
17620
17621 \layout Standard
17622 printf_tiny integer speed is data dependent, worst case is 0.33 ms
17623
17624 \end_inset
17625
17626
17627
17628 \end_inset
17629 </cell>
17630 </row>
17631 <row bottomline="true">
17632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17633 \begin_inset Text
17634
17635 \layout Standard
17636 long speed
17637 \begin_inset Foot
17638 collapsed true
17639
17640 \layout Standard
17641 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
17642  empty putchar()
17643
17644 \end_inset
17645
17646 ,
17647
17648 \layout Standard
17649 small / large
17650
17651 \end_inset
17652 </cell>
17653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17654 \begin_inset Text
17655
17656 \layout Standard
17657 5.37 / 6.31 ms
17658
17659 \end_inset
17660 </cell>
17661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17662 \begin_inset Text
17663
17664 \layout Standard
17665 5.37 / 6.31 ms
17666
17667 \end_inset
17668 </cell>
17669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17670 \begin_inset Text
17671
17672 \layout Standard
17673 8.71 / 40.65 ms
17674
17675 \end_inset
17676 </cell>
17677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17678 \begin_inset Text
17679
17680 \layout Standard
17681 0.40 / 0.40 ms
17682
17683 \end_inset
17684 </cell>
17685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17686 \begin_inset Text
17687
17688 \layout Standard
17689 0.40 / 0.40 ms
17690
17691 \end_inset
17692 </cell>
17693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17694 \begin_inset Text
17695
17696 \layout Standard
17697 -
17698
17699 \end_inset
17700 </cell>
17701 </row>
17702 <row bottomline="true">
17703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17704 \begin_inset Text
17705
17706 \layout Standard
17707 float speed
17708 \begin_inset Foot
17709 collapsed true
17710
17711 \layout Standard
17712 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
17713  empty putchar()
17714
17715 \end_inset
17716
17717 ,
17718
17719 \layout Standard
17720 small / large
17721
17722 \end_inset
17723 </cell>
17724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17725 \begin_inset Text
17726
17727 \layout Standard
17728 -
17729
17730 \end_inset
17731 </cell>
17732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17733 \begin_inset Text
17734
17735 \layout Standard
17736 7.49 / 22.47 ms
17737
17738 \end_inset
17739 </cell>
17740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17741 \begin_inset Text
17742
17743 \layout Standard
17744 -
17745
17746 \end_inset
17747 </cell>
17748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17749 \begin_inset Text
17750
17751 \layout Standard
17752 -
17753
17754 \end_inset
17755 </cell>
17756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17757 \begin_inset Text
17758
17759 \layout Standard
17760 1.04 / 1.04 ms
17761
17762 \end_inset
17763 </cell>
17764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17765 \begin_inset Text
17766
17767 \layout Standard
17768 -
17769
17770 \end_inset
17771 </cell>
17772 </row>
17773 </lyxtabular>
17774
17775 \end_inset
17776
17777
17778
17779 \layout Subsubsection
17780 <malloc.h>
17781 \begin_inset LatexCommand \index{malloc.h}
17782
17783 \end_inset
17784
17785
17786
17787 \layout Standard
17788 As of SDCC 2.6.2 you no longer need to call an initialization routine before
17789  using dynamic memory allocation
17790 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
17791
17792 \end_inset
17793
17794  and a default heap
17795 \begin_inset LatexCommand \index{heap (malloc)}
17796
17797 \end_inset
17798
17799  space of 1024 bytes is provided for malloc to allocate memory from.
17800  If you need a different heap size you need to recompile _heap.c with the
17801  required size defined in HEAP_SIZE.
17802  It is recommended to make a copy of this file into your project directory
17803  and compile it there with:
17804
17805 \layout Verse
17806
17807 \family typewriter
17808 sdcc -c _heap.c -D HEAD_SIZE=2048
17809
17810 \layout Standard
17811 And then link it with:
17812
17813 \layout Verse
17814
17815 \family typewriter
17816 sdcc main.rel _heap.rel
17817
17818 \layout Subsection
17819 Math functions (sinf, powf, sqrtf etc.)
17820
17821 \layout Subsubsection
17822 <math.h>
17823
17824 \layout Standard
17825 See definitions in file <math.h>.
17826
17827 \layout Subsection
17828 Other libraries
17829
17830 \layout Standard
17831 Libraries
17832 \begin_inset LatexCommand \index{Libraries}
17833
17834 \end_inset
17835
17836  included in SDCC should have a license at least as liberal as the GNU Lesser
17837  General Public License
17838 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
17839
17840 \end_inset
17841
17842  
17843 \emph on
17844 LGPL
17845 \emph default
17846 .
17847
17848 \layout Standard
17849 \begin_inset Note
17850 collapsed true
17851
17852 \layout Standard
17853 license statements for the libraries are missing.
17854  sdcc/device/lib/ser_ir.c
17855
17856 \layout Standard
17857 or _decdptr f.e.
17858  come with a GPL (as opposed to LGPL) License - this will not be liberal
17859  enough for many embedded programmers.
17860
17861 \end_inset
17862
17863
17864
17865 \layout Standard
17866 If you have ported some library or want to share experience about some code
17867  which f.e.
17868  falls into any of these categories Busses (I
17869 \begin_inset Formula $^{\textrm{2}}$
17870 \end_inset
17871
17872 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
17873  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
17874  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
17875 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
17876
17877 \end_inset
17878
17879 \SpecialChar ~
17880 would certainly like to hear about it.
17881
17882 \layout Standard
17883 \added_space_bottom bigskip 
17884 Programmers coding for embedded systems are not especially famous for being
17885  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
17886 e these references are very valuable.
17887  Let's help to create a climate where information is shared.
17888
17889
17890
17891 \layout Section
17892 Memory Models
17893
17894 \layout Subsection
17895 MCS51 Memory Models
17896 \begin_inset LatexCommand \index{Memory model}
17897
17898 \end_inset
17899
17900
17901 \begin_inset LatexCommand \index{MCS51 memory model}
17902
17903 \end_inset
17904
17905
17906
17907 \layout Subsubsection
17908 Small, Medium and Large
17909
17910 \layout Standard
17911 SDCC allows three memory models for MCS51 code, 
17912 \shape slanted
17913 small, medium
17914 \shape default
17915  and 
17916 \shape slanted
17917 large
17918 \shape default
17919 .
17920  Modules compiled with different memory models should 
17921 \emph on
17922 never
17923 \emph default
17924  be combined together or the results would be unpredictable.
17925  The library routines supplied with the compiler are compiled as small,
17926  medium and large.
17927  The compiled library modules are contained in separate directories as small,
17928  medium and large so that you can link to the appropriate set.
17929
17930 \layout Standard
17931 When the medium or large model is used all variables declared without a
17932  storage class will be allocated into the external ram, this includes all
17933  parameters and local variables (for non-reentrant
17934 \begin_inset LatexCommand \index{reentrant}
17935
17936 \end_inset
17937
17938  functions).
17939  When the small model is used variables without storage class are allocated
17940  in the internal ram.
17941
17942 \layout Standard
17943 Judicious usage of the processor specific storage classes
17944 \begin_inset LatexCommand \index{Storage class}
17945
17946 \end_inset
17947
17948  and the 'reentrant' function type will yield much more efficient code,
17949  than using the large model.
17950  Several optimizations are disabled when the program is compiled using the
17951  large model, it is therefore recommended that the small model be used unless
17952  absolutely required.
17953
17954 \layout Subsubsection
17955 External Stack
17956 \begin_inset LatexCommand \label{sub:External-Stack}
17957
17958 \end_inset
17959
17960
17961 \begin_inset LatexCommand \index{stack}
17962
17963 \end_inset
17964
17965
17966 \begin_inset LatexCommand \index{External stack (mcs51)}
17967
17968 \end_inset
17969
17970
17971
17972 \layout Standard
17973 The external stack (-
17974 \begin_inset ERT
17975 status Collapsed
17976
17977 \layout Standard
17978
17979
17980 \backslash
17981 /
17982
17983 \end_inset
17984
17985 -xstack option
17986 \begin_inset LatexCommand \index{-\/-xstack}
17987
17988 \end_inset
17989
17990 ) is located in pdata
17991 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17992
17993 \end_inset
17994
17995  memory (usually at the start of the external ram segment) and uses all
17996  unused space in pdata (max.
17997  256 bytes).
17998  When -
17999 \begin_inset ERT
18000 status Collapsed
18001
18002 \layout Standard
18003
18004
18005 \backslash
18006 /
18007
18008 \end_inset
18009
18010 -xstack option is used to compile the program, the parameters and local
18011  variables
18012 \begin_inset LatexCommand \index{local variables}
18013
18014 \end_inset
18015
18016  of all reentrant functions are allocated in this area.
18017  This option is provided for programs with large stack space requirements.
18018  When used with the -
18019 \begin_inset ERT
18020 status Collapsed
18021
18022 \layout Standard
18023
18024
18025 \backslash
18026 /
18027
18028 \end_inset
18029
18030 -stack-auto
18031 \begin_inset LatexCommand \index{-\/-stack-auto}
18032
18033 \end_inset
18034
18035  option, all parameters and local variables are allocated on the external
18036  stack (note: support libraries will need to be recompiled with the same
18037  options.
18038  There is a predefined target in the library makefile).
18039
18040 \layout Standard
18041 The compiler outputs the higher order address byte of the external ram segment
18042  into port P2
18043 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18044
18045 \end_inset
18046
18047  (see also section 
18048 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18049
18050 \end_inset
18051
18052 ), therefore when using the External Stack option, this port 
18053 \emph on
18054 may not
18055 \emph default
18056  be used by the application program.
18057
18058 \layout Subsection
18059 DS390 Memory Model
18060 \begin_inset LatexCommand \index{Memory model}
18061
18062 \end_inset
18063
18064
18065 \begin_inset LatexCommand \index{DS390 memory model}
18066
18067 \end_inset
18068
18069
18070
18071 \layout Standard
18072 The only model supported is Flat 24
18073 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18074
18075 \end_inset
18076
18077 .
18078  This generates code for the 24 bit contiguous addressing mode of the Dallas
18079  DS80C390 part.
18080  In this mode, up to four meg of external RAM or code space can be directly
18081  addressed.
18082  See the data sheets at www.dalsemi.com for further information on this part.
18083 \newline
18084
18085 \newline
18086 Note
18087  that the compiler does not generate any code to place the processor into
18088  24 bitmode (although 
18089 \emph on
18090 tinibios
18091 \emph default
18092  in the ds390 libraries will do that for you).
18093  If you don't use 
18094 \emph on
18095 tinibios
18096 \emph default
18097
18098 \begin_inset LatexCommand \index{Tinibios (DS390)}
18099
18100 \end_inset
18101
18102 , the boot loader or similar code must ensure that the processor is in 24
18103  bit contiguous addressing mode before calling the SDCC startup code.
18104 \newline
18105
18106 \newline
18107 Like
18108  the 
18109 \emph on
18110 -
18111 \begin_inset ERT
18112 status Collapsed
18113
18114 \layout Standard
18115
18116
18117 \backslash
18118 /
18119
18120 \end_inset
18121
18122 -model-large
18123 \emph default
18124  option, variables will by default be placed into the XDATA segment.
18125  
18126 \newline
18127
18128 \newline
18129 Segments may be placed anywhere in the 4 meg address space using the usual
18130  -
18131 \begin_inset ERT
18132 status Collapsed
18133
18134 \layout Standard
18135
18136
18137 \backslash
18138 /
18139
18140 \end_inset
18141
18142 -*-loc options.
18143  Note that if any segments are located above 64K, the -r flag must be passed
18144  to the linker to generate the proper segment relocations, and the Intel
18145  HEX output format must be used.
18146  The -r flag can be passed to the linker by using the option 
18147 \emph on
18148 -Wl-r
18149 \emph default
18150  on the SDCC command line.
18151  However, currently the linker can not handle code segments > 64k.
18152
18153 \layout Section
18154 Pragmas
18155 \begin_inset LatexCommand \label{sec:Pragmas}
18156
18157 \end_inset
18158
18159
18160 \begin_inset LatexCommand \index{Pragmas}
18161
18162 \end_inset
18163
18164
18165
18166 \layout Standard
18167 SDCC supports the following #pragma directives:
18168
18169 \layout Itemize
18170
18171 \series bold
18172 save
18173 \series default
18174
18175 \begin_inset LatexCommand \index{\#pragma save}
18176
18177 \end_inset
18178
18179  - this will save most current options to the save/restore stack.
18180  See #pragma\SpecialChar ~
18181 restore.
18182
18183 \layout Itemize
18184
18185 \series bold
18186 restore
18187 \series default
18188
18189 \begin_inset LatexCommand \index{\#pragma restore}
18190
18191 \end_inset
18192
18193  - will restore saved options from the last save.
18194  saves & restores can be nested.
18195  SDCC uses a save/restore stack: save pushes current options to the stack,
18196  restore pulls current options from the stack.
18197  See #pragma\SpecialChar ~
18198 save.
18199 \newline
18200
18201
18202 \layout Itemize
18203
18204 \series bold
18205 callee_saves
18206 \series default
18207
18208 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18209
18210 \end_inset
18211
18212
18213 \begin_inset LatexCommand \index{function prologue}
18214
18215 \end_inset
18216
18217  function1[,function2[,function3...]] - The compiler by default uses a caller
18218  saves convention for register saving across function calls, however this
18219  can cause unnecessary register pushing & popping
18220 \begin_inset LatexCommand \index{push/pop}
18221
18222 \end_inset
18223
18224  when calling small functions from larger functions.
18225  This option can be used to switch off the register saving convention for
18226  the function names specified.
18227  The compiler will not save registers when calling these functions, extra
18228  code need to be manually inserted at the entry & exit for these functions
18229  to save & restore the registers used by these functions, this can SUBSTANTIALLY
18230  reduce code & improve run time performance of the generated code.
18231  In the future the compiler (with inter procedural analysis) may be able
18232  to determine the appropriate scheme to use for each function call.
18233  If -
18234 \begin_inset ERT
18235 status Collapsed
18236
18237 \layout Standard
18238
18239
18240 \backslash
18241 /
18242
18243 \end_inset
18244
18245 -callee-saves command line option is used, the function names specified
18246  in #pragma\SpecialChar ~
18247 callee_saves
18248 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18249
18250 \end_inset
18251
18252  is appended to the list of functions specified in the command line.
18253
18254 \layout Itemize
18255
18256 \series bold
18257 exclude
18258 \series default
18259
18260 \begin_inset LatexCommand \index{\#pragma exclude}
18261
18262 \end_inset
18263
18264  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
18265  of pairs of push/pop
18266 \begin_inset LatexCommand \index{push/pop}
18267
18268 \end_inset
18269
18270  instructions in 
18271 \emph on
18272 I
18273 \emph default
18274 nterrupt
18275 \begin_inset LatexCommand \index{interrupt}
18276
18277 \end_inset
18278
18279  
18280 \emph on
18281 S
18282 \emph default
18283 ervice 
18284 \emph on
18285 R
18286 \emph default
18287 outines.
18288  The directive should be placed immediately before the ISR function definition
18289  and it affects ALL ISR functions following it.
18290  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
18291 exclude\SpecialChar ~
18292 none
18293 \begin_inset LatexCommand \index{\#pragma exclude}
18294
18295 \end_inset
18296
18297 .
18298  See also the related keyword _naked
18299 \begin_inset LatexCommand \index{\_naked}
18300
18301 \end_inset
18302
18303
18304 \begin_inset LatexCommand \index{\_\_naked}
18305
18306 \end_inset
18307
18308 .
18309
18310 \layout Itemize
18311
18312 \series bold
18313 less_pedantic
18314 \series default
18315
18316 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
18317
18318 \end_inset
18319
18320  - the compiler will not warn you anymore for obvious mistakes, you'r on
18321  your own now ;-(
18322
18323 \layout Itemize
18324
18325 \series bold
18326 disable_warning
18327 \series default
18328  <nnnn>
18329 \begin_inset LatexCommand \index{\#pragma disable\_warning}
18330
18331 \end_inset
18332
18333  - the compiler will not warn you anymore about warning number <nnnn>.
18334
18335 \layout Itemize
18336
18337 \series bold
18338 nogcse
18339 \series default
18340
18341 \begin_inset LatexCommand \index{\#pragma nogcse}
18342
18343 \end_inset
18344
18345  - will stop global common subexpression elimination.
18346
18347 \layout Itemize
18348
18349 \series bold
18350 noinduction
18351 \series default
18352
18353 \begin_inset LatexCommand \index{\#pragma noinduction}
18354
18355 \end_inset
18356
18357  - will stop loop induction optimizations.
18358
18359 \layout Itemize
18360
18361 \series bold
18362 noinvariant
18363 \series default
18364
18365 \begin_inset LatexCommand \index{\#pragma noinvariant}
18366
18367 \end_inset
18368
18369  - will not do loop invariant optimizations.
18370  For more details see Loop Invariants in section
18371 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
18372
18373 \end_inset
18374
18375 .
18376
18377 \layout Itemize
18378
18379 \series bold
18380 noiv
18381 \series default
18382
18383 \begin_inset LatexCommand \index{\#pragma noiv}
18384
18385 \end_inset
18386
18387  - Do not generate interrupt
18388 \begin_inset LatexCommand \index{interrupt}
18389
18390 \end_inset
18391
18392  vector table
18393 \begin_inset LatexCommand \index{interrupt vector table}
18394
18395 \end_inset
18396
18397  entries for all ISR functions defined after the pragma.
18398  This is useful in cases where the interrupt vector table must be defined
18399  manually, or when there is a secondary, manually defined interrupt vector
18400  table (e.g.
18401  for the autovector feature of the Cypress EZ-USB FX2).
18402  More elegantly this can be achieved by obmitting the optional interrupt
18403  number after the interrupt keyword, see section 
18404 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
18405
18406 \end_inset
18407
18408 \SpecialChar ~
18409 about interrupts.
18410
18411 \layout Itemize
18412
18413 \series bold
18414 nojtbound
18415 \series default
18416
18417 \begin_inset LatexCommand \index{\#pragma nojtbound}
18418
18419 \end_inset
18420
18421  - will not generate code for boundary value checking, when switch statements
18422  are turned into jump-tables (dangerous).
18423  For more details see section 
18424 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
18425
18426 \end_inset
18427
18428 .
18429
18430 \layout Itemize
18431
18432 \series bold
18433 noloopreverse
18434 \series default
18435
18436 \begin_inset LatexCommand \index{\#pragma noloopreverse}
18437
18438 \end_inset
18439
18440  - Will not do loop reversal optimization
18441
18442 \layout Itemize
18443
18444 \series bold
18445 nooverlay
18446 \series default
18447
18448 \begin_inset LatexCommand \index{\#pragma nooverlay}
18449
18450 \end_inset
18451
18452  - the compiler will not overlay the parameters and local variables of a
18453  function.
18454
18455 \layout Itemize
18456
18457 \series bold
18458 stackauto
18459 \series default
18460
18461 \begin_inset LatexCommand \index{\#pragma stackauto}
18462
18463 \end_inset
18464
18465 - See option -
18466 \begin_inset ERT
18467 status Collapsed
18468
18469 \layout Standard
18470
18471
18472 \backslash
18473 /
18474
18475 \end_inset
18476
18477 -stack-auto
18478 \begin_inset LatexCommand \index{-\/-stack-auto}
18479
18480 \end_inset
18481
18482  and section 
18483 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
18484
18485 \end_inset
18486
18487  Parameters and Local Variables.
18488
18489 \layout Itemize
18490
18491 \series bold
18492 opt_code_speed
18493 \series default
18494  
18495 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
18496
18497 \end_inset
18498
18499 - The compiler will optimize code generation towards fast code, possibly
18500  at the expense of code size.
18501  Currently this has little effect.
18502
18503 \layout Itemize
18504
18505 \series bold
18506 opt_code_size
18507 \series default
18508  
18509 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
18510
18511 \end_inset
18512
18513 - The compiler will optimize code generation towards compact code, possibly
18514  at the expense of code speed.
18515  Currently this has little effect.
18516
18517 \layout Itemize
18518
18519 \series bold
18520 opt_code_balanced
18521 \series default
18522  
18523 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
18524
18525 \end_inset
18526
18527 - The compiler will attempt to generate code that is both compact and fast,
18528  as long as meeting one goal is not a detriment to the other (this is the
18529  default).
18530  
18531
18532 \layout Itemize
18533
18534 \series bold
18535 std_sdcc89
18536 \series default
18537  
18538 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
18539
18540 \end_inset
18541
18542 - Generally follow the C89 standard, but allow SDCC features that conflict
18543  with the standard (default).
18544
18545 \layout Itemize
18546
18547 \series bold
18548 std_c89
18549 \series default
18550  
18551 \begin_inset LatexCommand \index{\#pragma std\_c89}
18552
18553 \end_inset
18554
18555 - Follow the C89 standard and disable SDCC features that conflict with the
18556  standard.
18557
18558 \layout Itemize
18559
18560 \series bold
18561 std_sdcc99
18562 \series default
18563  
18564 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
18565
18566 \end_inset
18567
18568 - Generally follow the C99 standard, but allow SDCC features that conflict
18569  with the standard (incomplete support).
18570
18571 \layout Itemize
18572
18573 \series bold
18574 std_c99
18575 \series default
18576  
18577 \begin_inset LatexCommand \index{\#pragma std\_c99}
18578
18579 \end_inset
18580
18581 - Follow the C99 standard and disable SDCC features that conflict with the
18582  standard (incomplete support).
18583
18584 \layout Itemize
18585
18586 \series bold
18587 codeseg
18588 \series default
18589  <name>
18590 \begin_inset LatexCommand \index{\#pragma codeseg}
18591
18592 \end_inset
18593
18594 - Use this name (max.
18595  8 characters) for the code segment.
18596  See option -
18597 \begin_inset ERT
18598 status Collapsed
18599
18600 \layout Standard
18601
18602
18603 \backslash
18604 /
18605
18606 \end_inset
18607
18608 -codeseg.
18609
18610 \layout Itemize
18611
18612 \series bold
18613 constseg
18614 \series default
18615  <name>
18616 \begin_inset LatexCommand \index{\#pragma constseg}
18617
18618 \end_inset
18619
18620 - Use this name (max.
18621  8 characters) for the const segment.
18622  See option -
18623 \begin_inset ERT
18624 status Collapsed
18625
18626 \layout Standard
18627
18628
18629 \backslash
18630 /
18631
18632 \end_inset
18633
18634 -constseg.
18635
18636 \layout Standard
18637 The preprocessor SDCPP
18638 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
18639
18640 \end_inset
18641
18642  supports the following #pragma directives:
18643
18644 \layout Itemize
18645
18646 \series bold
18647 pedantic_parse_number
18648 \series default
18649
18650 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18651
18652 \end_inset
18653
18654  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
18655  parsed properly and the macro LO_B(3) gets expanded.
18656  Default is off.
18657  Below is an example on how to use this pragma.
18658
18659 \emph on
18660  Note: this functionality is not in conformance with standard!
18661
18662 \layout Verse
18663
18664 \family typewriter
18665 #pragma pedantic_parse_number +
18666 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18667
18668 \end_inset
18669
18670
18671 \newline
18672
18673 \newline
18674 #define LO_B(x) ((x) & 0xff)
18675 \newline
18676
18677 \newline
18678 unsigned char foo(void)
18679 \newline
18680 {
18681 \newline
18682 \SpecialChar ~
18683 \SpecialChar ~
18684 \SpecialChar ~
18685 unsigned char c=0xfe-LO_B(3)
18686 ;
18687 \newline
18688
18689 \newline
18690 \SpecialChar ~
18691 \SpecialChar ~
18692 \SpecialChar ~
18693 return c;
18694 \newline
18695 }
18696 \newline
18697
18698
18699 \layout Itemize
18700
18701 \series bold
18702 preproc_asm
18703 \series default
18704
18705 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
18706
18707 \end_inset
18708
18709  (+ | -) - switch _asm _endasm block preprocessing on / off.
18710  Default is on.
18711  You use this prama to define multilines of assembly code.
18712  This will prevent the preprocessor from changing the formating required
18713  by assembly code.
18714  Below is an example on how to use this pragma.
18715
18716 \layout Verse
18717
18718 \family typewriter
18719 #pragma preproc_asm -
18720 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
18721
18722 \end_inset
18723
18724
18725 \newline
18726 #define MYDELAY _asm
18727 \newline
18728 \SpecialChar ~
18729 \SpecialChar ~
18730 \SpecialChar ~
18731 nop ;my assembly comment...
18732 \newline
18733 \SpecialChar ~
18734 \SpecialChar ~
18735 \SpecialChar ~
18736 nop
18737 \newline
18738 \SpecialChar ~
18739 \SpecialChar ~
18740 \SpecialChar ~
18741 nop
18742 \newline
18743 _endasm
18744 \newline
18745 #pragma preproc_asm
18746  +
18747 \newline
18748
18749 \newline
18750 void foo (void) 
18751 \newline
18752
18753 \newline
18754 \SpecialChar ~
18755 \SpecialChar ~
18756 \SpecialChar ~
18757  ...
18758  
18759 \newline
18760 \SpecialChar ~
18761 \SpecialChar ~
18762 \SpecialChar ~
18763  MYDELAY;
18764 \newline
18765 \SpecialChar ~
18766 \SpecialChar ~
18767 \SpecialChar ~
18768  ...
18769  
18770 \newline
18771
18772 \newline
18773
18774
18775 \layout Itemize
18776
18777 \series bold
18778 sdcc_hash
18779 \series default
18780
18781 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
18782
18783 \end_inset
18784
18785  (+ | -) - Allow "naked" hash in macro definition, for example:
18786 \newline
18787
18788 \family typewriter
18789 #define DIR_LO(x) #(x & 0xff)
18790 \family default
18791
18792 \newline
18793 Default is off.
18794  Below is an example on how to use this pragma.
18795
18796 \layout Verse
18797
18798 \family typewriter
18799 #pragma preproc_asm +
18800 \newline
18801 #pragma sdcc_hash +
18802 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
18803
18804 \end_inset
18805
18806
18807 \newline
18808
18809 \newline
18810 #define ROMCALL(x) 
18811 \backslash
18812
18813 \newline
18814 \SpecialChar ~
18815 \SpecialChar ~
18816 \SpecialChar ~
18817 mov R6_B3, #(x & 0xff) 
18818 \backslash
18819
18820 \newline
18821 \SpecialChar ~
18822 \SpecialChar ~
18823 \SpecialChar ~
18824 mov R7_B3, #((x >> 8) & 0xff) 
18825 \backslash
18826
18827 \newline
18828 \SpecialChar ~
18829 \SpecialChar ~
18830 \SpecialChar ~
18831 lcall __romcall
18832 \newline
18833
18834 \newline
18835 ...
18836 \newline
18837 _asm
18838 \newline
18839 ROMCALL(72)
18840 \newline
18841 _endasm;
18842 \newline
18843 ...
18844 \newline
18845
18846
18847 \layout Standard
18848 The pragma's are intended to be used to turn-on or off certain optimizations
18849  which might cause the compiler to generate extra stack / data space to
18850  store compiler generated temporary variables.
18851  This usually happens in large functions.
18852  Pragma directives should be used as shown in the following example, they
18853  are used to control options & optimizations for a given function; pragmas
18854  should be placed before and/or after a function, placing pragma's inside
18855  a function body could have unpredictable results.
18856
18857 \layout Verse
18858
18859 \family typewriter
18860 #pragma save
18861 \begin_inset LatexCommand \index{\#pragma save}
18862
18863 \end_inset
18864
18865  \SpecialChar ~
18866 \SpecialChar ~
18867 \SpecialChar ~
18868 \SpecialChar ~
18869 \SpecialChar ~
18870 \SpecialChar ~
18871 \SpecialChar ~
18872 /* save the current settings */ 
18873 \newline
18874 #pragma nogcse
18875 \begin_inset LatexCommand \index{\#pragma nogcse}
18876
18877 \end_inset
18878
18879  \SpecialChar ~
18880 \SpecialChar ~
18881 \SpecialChar ~
18882 \SpecialChar ~
18883 \SpecialChar ~
18884 /* turnoff global subexpression elimination */ 
18885 \newline
18886 #pragma noinduction
18887 \begin_inset LatexCommand \index{\#pragma noinduction}
18888
18889 \end_inset
18890
18891  /* turn off induction optimizations */ 
18892 \newline
18893 int foo () 
18894 \newline
18895
18896 \newline
18897 \SpecialChar ~
18898  \SpecialChar ~
18899  ...
18900  
18901 \newline
18902 \SpecialChar ~
18903  \SpecialChar ~
18904  /* large code */ 
18905 \newline
18906 \SpecialChar ~
18907  \SpecialChar ~
18908  ...
18909  
18910 \newline
18911
18912 \newline
18913 #pragma restore
18914 \begin_inset LatexCommand \index{\#pragma restore}
18915
18916 \end_inset
18917
18918  /* turn the optimizations back on */
18919
18920 \layout Standard
18921 The compiler will generate a warning message when extra space is allocated.
18922  It is strongly recommended that the save and restore pragma's be used when
18923  changing options for a function.
18924 \newline
18925
18926 \newline
18927
18928 \newline
18929
18930
18931 \layout Section
18932 Defines Created by the Compiler
18933
18934 \layout Standard
18935 The compiler creates the following #defines
18936 \begin_inset LatexCommand \index{\#defines}
18937
18938 \end_inset
18939
18940
18941 \begin_inset LatexCommand \index{Defines created by the compiler}
18942
18943 \end_inset
18944
18945 :
18946 \newline
18947
18948
18949 \layout Standard
18950 \begin_inset Tabular
18951 <lyxtabular version="3" rows="11" columns="2">
18952 <features>
18953 <column alignment="left" valignment="top" leftline="true" width="3in">
18954 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
18955 <row topline="true" bottomline="true">
18956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18957 \begin_inset Text
18958
18959 \layout Standard
18960
18961 \series bold
18962 #define
18963
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 \series bold
18972 Description
18973
18974 \end_inset
18975 </cell>
18976 </row>
18977 <row topline="true">
18978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18979 \begin_inset Text
18980
18981 \layout Standard
18982 SDCC
18983 \begin_inset LatexCommand \index{SDCC}
18984
18985 \end_inset
18986
18987  
18988
18989 \end_inset
18990 </cell>
18991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18992 \begin_inset Text
18993
18994 \layout Standard
18995 Always defined.
18996  Since version 2.5.6 the version number as an int (ex.
18997  256)
18998
18999 \end_inset
19000 </cell>
19001 </row>
19002 <row topline="true">
19003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19004 \begin_inset Text
19005
19006 \layout Standard
19007 SDCC_mcs51
19008 \begin_inset LatexCommand \index{SDCC\_mcs51}
19009
19010 \end_inset
19011
19012  or SDCC_ds390
19013 \begin_inset LatexCommand \index{SDCC\_ds390}
19014
19015 \end_inset
19016
19017  or SDCC_z80
19018 \begin_inset LatexCommand \index{SDCC\_z80}
19019
19020 \end_inset
19021
19022 , etc.
19023
19024 \end_inset
19025 </cell>
19026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19027 \begin_inset Text
19028
19029 \layout Standard
19030 depending on the model used (e.g.: -mds390)
19031
19032 \end_inset
19033 </cell>
19034 </row>
19035 <row topline="true">
19036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19037 \begin_inset Text
19038
19039 \layout Standard
19040 __mcs51
19041 \begin_inset LatexCommand \index{\_\_mcs51}
19042
19043 \end_inset
19044
19045 , __ds390
19046 \begin_inset LatexCommand \index{\_\_ds390}
19047
19048 \end_inset
19049
19050 , __hc08
19051 \begin_inset LatexCommand \index{\_\_hc08}
19052
19053 \end_inset
19054
19055 , __z80
19056 \begin_inset LatexCommand \index{\_\_z80}
19057
19058 \end_inset
19059
19060 , etc
19061
19062 \end_inset
19063 </cell>
19064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19065 \begin_inset Text
19066
19067 \layout Standard
19068 depending on the model used (e.g.
19069  -mz80)
19070
19071 \end_inset
19072 </cell>
19073 </row>
19074 <row topline="true">
19075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19076 \begin_inset Text
19077
19078 \layout Standard
19079 SDCC_STACK_AUTO
19080 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19081
19082 \end_inset
19083
19084
19085
19086 \end_inset
19087 </cell>
19088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19089 \begin_inset Text
19090
19091 \layout Standard
19092 when 
19093 \emph on
19094 -
19095 \begin_inset ERT
19096 status Collapsed
19097
19098 \layout Standard
19099
19100
19101 \backslash
19102 /
19103
19104 \end_inset
19105
19106 -stack-auto
19107 \emph default
19108  option is used
19109
19110 \end_inset
19111 </cell>
19112 </row>
19113 <row topline="true">
19114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19115 \begin_inset Text
19116
19117 \layout Standard
19118 SDCC_MODEL_SMALL
19119 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
19120
19121 \end_inset
19122
19123
19124
19125 \end_inset
19126 </cell>
19127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19128 \begin_inset Text
19129
19130 \layout Standard
19131 when 
19132 \emph on
19133 -
19134 \begin_inset ERT
19135 status Collapsed
19136
19137 \layout Standard
19138
19139
19140 \backslash
19141 /
19142
19143 \end_inset
19144
19145 -model-small
19146 \emph default
19147  is used
19148
19149 \end_inset
19150 </cell>
19151 </row>
19152 <row topline="true">
19153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19154 \begin_inset Text
19155
19156 \layout Standard
19157 SDCC_MODEL_MEDIUM
19158 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
19159
19160 \end_inset
19161
19162
19163
19164 \end_inset
19165 </cell>
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19167 \begin_inset Text
19168
19169 \layout Standard
19170 when 
19171 \emph on
19172 -
19173 \begin_inset ERT
19174 status Collapsed
19175
19176 \layout Standard
19177
19178
19179 \backslash
19180 /
19181
19182 \end_inset
19183
19184 -model-medium
19185 \emph default
19186  is used
19187
19188 \end_inset
19189 </cell>
19190 </row>
19191 <row topline="true">
19192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19193 \begin_inset Text
19194
19195 \layout Standard
19196 SDCC_MODEL_LARGE
19197 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
19198
19199 \end_inset
19200
19201
19202
19203 \end_inset
19204 </cell>
19205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19206 \begin_inset Text
19207
19208 \layout Standard
19209 when 
19210 \emph on
19211 -
19212 \begin_inset ERT
19213 status Collapsed
19214
19215 \layout Standard
19216
19217
19218 \backslash
19219 /
19220
19221 \end_inset
19222
19223 -model-large
19224 \emph default
19225  is used
19226
19227 \end_inset
19228 </cell>
19229 </row>
19230 <row topline="true">
19231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19232 \begin_inset Text
19233
19234 \layout Standard
19235 SDCC_USE_XSTACK
19236 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
19237
19238 \end_inset
19239
19240
19241
19242 \end_inset
19243 </cell>
19244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19245 \begin_inset Text
19246
19247 \layout Standard
19248 when 
19249 \emph on
19250 -
19251 \begin_inset ERT
19252 status Collapsed
19253
19254 \layout Standard
19255
19256
19257 \backslash
19258 /
19259
19260 \end_inset
19261
19262 -xstack
19263 \emph default
19264  option is used
19265
19266 \end_inset
19267 </cell>
19268 </row>
19269 <row topline="true">
19270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19271 \begin_inset Text
19272
19273 \layout Standard
19274 SDCC_STACK_TENBIT
19275 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
19276
19277 \end_inset
19278
19279  
19280
19281 \end_inset
19282 </cell>
19283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19284 \begin_inset Text
19285
19286 \layout Standard
19287 when 
19288 \emph on
19289 -mds390
19290 \emph default
19291  is used
19292
19293 \end_inset
19294 </cell>
19295 </row>
19296 <row topline="true" bottomline="true">
19297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19298 \begin_inset Text
19299
19300 \layout Standard
19301 SDCC_MODEL_FLAT24
19302 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
19303
19304 \end_inset
19305
19306
19307
19308 \end_inset
19309 </cell>
19310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19311 \begin_inset Text
19312
19313 \layout Standard
19314 when 
19315 \emph on
19316 -mds390
19317 \emph default
19318  is used
19319
19320 \end_inset
19321 </cell>
19322 </row>
19323 </lyxtabular>
19324
19325 \end_inset
19326
19327
19328
19329 \layout Chapter
19330 Notes on supported Processors
19331
19332 \layout Section
19333 MCS51 variants
19334 \begin_inset LatexCommand \label{sub:MCS51-variants}
19335
19336 \end_inset
19337
19338
19339 \begin_inset LatexCommand \index{MCS51 variants}
19340
19341 \end_inset
19342
19343
19344
19345 \layout Standard
19346 MCS51 processors are available from many vendors and come in many different
19347  flavours.
19348  While they might differ considerably in respect to Special Function Registers
19349  the core MCS51 is usually not modified or is kept compatible.
19350  
19351
19352 \layout Subsection
19353 pdata access by SFR 
19354
19355 \layout Standard
19356 With the upcome of devices with internal xdata and flash memory devices
19357  using port P2
19358 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19359
19360 \end_inset
19361
19362  as dedicated I/O port is becoming more popular.
19363  Switching the high byte for pdata
19364 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19365
19366 \end_inset
19367
19368  access which was formerly done by port P2 is then achieved by a Special
19369  Function Register
19370 \begin_inset LatexCommand \index{sfr}
19371
19372 \end_inset
19373
19374 .
19375  In well-established MCS51 tradition the address of this 
19376 \emph on
19377 sfr
19378 \emph default
19379  is where the chip designers decided to put it.
19380  Needless to say that they didn't agree on a common name either.
19381  So that the startup code can correctly initialize xdata variables, you
19382  should define an sfr with the name _XPAGE
19383 \family typewriter
19384
19385 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
19386
19387 \end_inset
19388
19389
19390 \family default
19391  at the appropriate location if the default, port P2, is not used for this.
19392  Some examples are:
19393
19394 \layout Verse
19395
19396 \family typewriter
19397 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
19398
19399 \layout Verse
19400
19401 \family typewriter
19402 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
19403
19404 \layout Verse
19405
19406 \family typewriter
19407 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
19408
19409 \layout Standard
19410 For more exotic implementations further customizations may be needed.
19411  See section 
19412 \begin_inset LatexCommand \ref{sub:Startup-Code}
19413
19414 \end_inset
19415
19416  for other possibilities.
19417
19418 \layout Subsection
19419 Other Features available by SFR
19420
19421 \layout Standard
19422 \added_space_bottom bigskip 
19423 Some MCS51 variants offer features like Double DPTR
19424 \begin_inset LatexCommand \index{DPTR}
19425
19426 \end_inset
19427
19428 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
19429  These are currently not used for the MCS51 port.
19430  If you absolutely need them you can fall back to inline assembly or submit
19431  a patch to SDCC.
19432
19433
19434
19435 \layout Section
19436 DS400 port
19437
19438 \layout Standard
19439 \added_space_bottom bigskip 
19440 The DS80C400
19441 \begin_inset LatexCommand \index{DS80C400}
19442
19443 \end_inset
19444
19445
19446 \begin_inset LatexCommand \index{DS400}
19447
19448 \end_inset
19449
19450  microcontroller has a rich set of peripherals.
19451  In its built-in ROM library it includes functions to access some of the
19452  features, among them is a TCP stack with IP4 and IP6 support.
19453  Library headers (currently in beta status) and other files are provided
19454  at 
19455 \size footnotesize
19456
19457 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
19458
19459 \end_inset
19460
19461 .
19462  
19463
19464
19465
19466 \layout Section
19467 The Z80 and gbz80 port
19468
19469 \layout Standard
19470 SDCC can target both the Zilog Z80
19471 \begin_inset LatexCommand \index{Z80}
19472
19473 \end_inset
19474
19475  and the Nintendo Gameboy's Z80-like gbz80
19476 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
19477
19478 \end_inset
19479
19480 .
19481  The Z80 port is passed through the same 
19482 \emph on
19483 regressions tests
19484 \begin_inset LatexCommand \index{Regression test}
19485
19486 \end_inset
19487
19488
19489 \emph default
19490  (see section 
19491 \begin_inset LatexCommand \ref{sec:Quality-control}
19492
19493 \end_inset
19494
19495 ) as the MCS51 and DS390 ports, so floating point support, support for long
19496  variables and bitfield support is fine.
19497  See mailing lists and forums about interrupt routines.
19498
19499 \layout Standard
19500 \added_space_bottom bigskip 
19501 As always, the code is the authoritative reference - see z80/ralloc.c and
19502  z80/gen.c.
19503  The stack
19504 \begin_inset LatexCommand \index{Z80!stack}
19505
19506 \end_inset
19507
19508  frame is similar to that generated by the IAR Z80 compiler.
19509  IX is used as the base pointer, HL and IY are used as a temporary registers,
19510  and BC and DE are available for holding variables.
19511  Return values
19512 \begin_inset LatexCommand \index{Z80!return value}
19513
19514 \end_inset
19515
19516  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
19517  bytes).
19518  The gbz80 port use the same set of registers for the return values, but
19519  in a different order of significance: E (one byte), DE (two bytes), or
19520  HLDE (four bytes).
19521
19522
19523
19524 \layout Section
19525 The HC08 port
19526
19527 \layout Standard
19528 The port to the Freescale/Motorola HC08
19529 \begin_inset LatexCommand \index{HC08}
19530
19531 \end_inset
19532
19533  family has been added in October 2003, and is still undergoing some basic
19534  development.
19535  The code generator is complete, but the register allocation is still quite
19536  unoptimized.
19537  Some of the SDCC's standard C library functions have embedded non-HC08
19538  inline assembly and so are not yet usable.
19539
19540 \layout Standard
19541 \added_space_bottom bigskip 
19542 \pagebreak_bottom 
19543 The HC08 port passes the regression test suite (see section 
19544 \begin_inset LatexCommand \ref{sec:Quality-control}
19545
19546 \end_inset
19547
19548 ).
19549
19550
19551
19552
19553 \layout Section
19554 The PIC14 port
19555
19556 \layout Standard
19557 The 14bit PIC
19558 \begin_inset LatexCommand \index{PIC14}
19559
19560 \end_inset
19561
19562  port still requires a major effort from the development community.
19563  However it can work for simple code.
19564  It passes its (smaller set of) regression tests
19565 \begin_inset LatexCommand \index{Regression test (PIC14)}
19566
19567 \end_inset
19568
19569  in the directory 
19570 \shape italic
19571 sdcc/src/regression
19572 \shape default
19573 .
19574
19575 \layout Subsection
19576 C code and 14bit PIC code page
19577 \begin_inset LatexCommand \index{code page (pic14)}
19578
19579 \end_inset
19580
19581  and RAM banks
19582 \begin_inset LatexCommand \index{RAM bank (pic14)}
19583
19584 \end_inset
19585
19586
19587
19588 \layout Standard
19589 The linker organizes allocation for the code page and RAM banks.
19590  It does not have intimate knowledge of the code flow.
19591  It will put all the code section of a single asm file into a single code
19592  page.
19593  In order to make use of multiple code pages, separate asm files must be
19594  used.
19595  The compiler treats all functions of a single C file as being in the same
19596  code page unless it is non static.
19597 \newline
19598
19599 \newline
19600 To get the best follow these guide lines:
19601
19602 \layout Enumerate
19603 Make local functions static, as non static functions require code page selection
19604  overhead.
19605
19606 \layout Enumerate
19607 For devices that have multiple code pages it is more efficient to use the
19608  same number of files as pages, i.e.
19609  for the 16F877 use 4 separate files and i.e.
19610  for the 16F874 use 2 separate files.
19611  This way the linker can put the code for each file into different code
19612  pages and there's less page selection overhead.
19613
19614 \layout Enumerate
19615  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
19616  instruction set), use 'unsigned char' whereever possible instead of 'int'.
19617
19618 \layout Subsection
19619 Creating a device include file 
19620
19621 \layout Standard
19622 For generating a device include file
19623 \begin_inset LatexCommand \index{PIC14!Header files}
19624
19625 \end_inset
19626
19627  use the support perl script inc2h.pl kept in directory support/script.
19628
19629 \layout Subsection
19630 Interrupt code
19631
19632 \layout Standard
19633 For the interrupt function, use the keyword '__interrupt'
19634 \begin_inset LatexCommand \index{PIC14!interrupt}
19635
19636 \end_inset
19637
19638  with level number of 0 (PIC14 only has 1 interrupt so this number is only
19639  there to avoid a syntax error - it ought to be fixed).
19640  E.g.:
19641
19642 \layout Verse
19643
19644 \family typewriter
19645 void Intr(void) __interrupt 0
19646 \newline
19647 {
19648 \newline
19649 \SpecialChar ~
19650 \SpecialChar ~
19651 T0IF = 0; /* Clear timer interrupt */
19652 \newline
19653 }
19654
19655 \layout Subsection
19656 Linking and assembling
19657
19658 \layout Standard
19659 For assembling you can use either GPUTILS'
19660 \begin_inset LatexCommand \index{gputils (pic tools)}
19661
19662 \end_inset
19663
19664  gpasm.exe or MPLAB's mpasmwin.exe.
19665  GPUTILS is available from 
19666 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19667
19668 \end_inset
19669
19670 .
19671  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
19672  If you use MPLAB and an interrupt function then the linker script file
19673  vectors section will need to be enlarged to link with mplink.
19674 \newline
19675
19676 \newline
19677 Here is a 
19678 \family typewriter
19679 Makefile
19680 \family default
19681  using GPUTILS:
19682
19683 \layout Verse
19684
19685 \family typewriter
19686 .c.o:
19687 \newline
19688 \SpecialChar ~
19689 \SpecialChar ~
19690 \SpecialChar ~
19691 \SpecialChar ~
19692 \SpecialChar ~
19693 \SpecialChar ~
19694 \SpecialChar ~
19695 \SpecialChar ~
19696 sdcc -S -V -mpic14 -p16F877 $< 
19697 \newline
19698 \SpecialChar ~
19699 \SpecialChar ~
19700 \SpecialChar ~
19701 \SpecialChar ~
19702 \SpecialChar ~
19703 \SpecialChar ~
19704 \SpecialChar ~
19705 \SpecialChar ~
19706 gpasm -c $*.asm
19707 \newline
19708
19709 \newline
19710 $(PRJ).hex: $(OBJS) 
19711 \newline
19712 \SpecialChar ~
19713 \SpecialChar ~
19714 \SpecialChar ~
19715 \SpecialChar ~
19716 \SpecialChar ~
19717 \SpecialChar ~
19718 \SpecialChar ~
19719 \SpecialChar ~
19720 gplink
19721  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
19722
19723 \layout Standard
19724 Here is a 
19725 \family typewriter
19726 Makefile
19727 \family default
19728  using MPLAB:
19729
19730 \layout Verse
19731
19732 \family typewriter
19733 .c.o: 
19734 \newline
19735 \SpecialChar ~
19736 \SpecialChar ~
19737 \SpecialChar ~
19738 \SpecialChar ~
19739 \SpecialChar ~
19740 \SpecialChar ~
19741 \SpecialChar ~
19742 \SpecialChar ~
19743 sdcc -S -V -mpic14 -p16F877 $< 
19744 \newline
19745 \SpecialChar ~
19746 \SpecialChar ~
19747 \SpecialChar ~
19748 \SpecialChar ~
19749 \SpecialChar ~
19750 \SpecialChar ~
19751 \SpecialChar ~
19752 \SpecialChar ~
19753 mpasmwin /q /o $*.asm
19754 \newline
19755
19756 \newline
19757 $(PRJ).hex: $(OBJS)
19758  
19759 \newline
19760 \SpecialChar ~
19761 \SpecialChar ~
19762 \SpecialChar ~
19763 \SpecialChar ~
19764 \SpecialChar ~
19765 \SpecialChar ~
19766 \SpecialChar ~
19767 \SpecialChar ~
19768 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
19769
19770 \layout Standard
19771 Please note that indentations within a
19772 \family typewriter
19773  Makefile
19774 \family default
19775  have to be done with a tabulator character.
19776
19777 \layout Subsection
19778 Command-line options
19779
19780 \layout Standard
19781 Besides the switches common to all SDCC backends, the PIC14 port accepts
19782  the following options (for an updated list see sdcc -
19783 \begin_inset ERT
19784 status Collapsed
19785
19786 \layout Standard
19787
19788
19789 \backslash
19790 /
19791
19792 \end_inset
19793
19794 -help):
19795
19796 \layout List
19797 \labelwidthstring 00.00.0000
19798 -
19799 \begin_inset ERT
19800 status Collapsed
19801
19802 \layout Standard
19803
19804
19805 \backslash
19806 /
19807
19808 \end_inset
19809
19810 -debug-extra
19811 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
19812
19813 \end_inset
19814
19815  emit debug info in assembly output
19816
19817 \layout List
19818 \labelwidthstring 00.00.0000
19819 -
19820 \begin_inset ERT
19821 status Collapsed
19822
19823 \layout Standard
19824
19825
19826 \backslash
19827 /
19828
19829 \end_inset
19830
19831 -no-pcode-opt
19832 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
19833
19834 \end_inset
19835
19836  disable (slightly faulty) optimization on pCode
19837
19838 \layout List
19839 \labelwidthstring 00.00.0000
19840 -
19841 \begin_inset ERT
19842 status Collapsed
19843
19844 \layout Standard
19845
19846
19847 \backslash
19848 /
19849
19850 \end_inset
19851
19852 -stack-loc
19853 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
19854
19855 \end_inset
19856
19857  sets the lowest address of the argument passing stack (defaults to a suitably
19858  large shared databank to reduce BANKSEL overhead)
19859
19860 \layout List
19861 \labelwidthstring 00.00.0000
19862 -
19863 \begin_inset ERT
19864 status Collapsed
19865
19866 \layout Standard
19867
19868
19869 \backslash
19870 /
19871
19872 \end_inset
19873
19874 -stack-size
19875 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
19876
19877 \end_inset
19878
19879  sets the size if the argument passing stack (default: 16, minimum: 4)
19880
19881 \layout Subsection
19882 The library
19883
19884 \layout Subsubsection
19885 error: missing definition for symbol 
19886 \begin_inset Quotes sld
19887 \end_inset
19888
19889 __gptrget1
19890 \begin_inset Quotes srd
19891 \end_inset
19892
19893
19894
19895 \layout Standard
19896 The PIC14 port uses library routines to provide more complex operations
19897  like multiplication, division/modulus and (generic) pointer dereferencing.
19898  In order to add these routines to your project, you must link with PIC14's
19899  
19900 \family typewriter
19901 libsdcc.lib
19902 \family default
19903 .
19904  For single source file projects this is done automatically, more complex
19905  projects must add 
19906 \family typewriter
19907 libsdcc.lib
19908 \family default
19909  to the linker's arguments.
19910  Make sure you also add an include path for the library (using the -I switch
19911  to the linker)!
19912
19913 \layout Subsubsection
19914 Processor mismatch in file 
19915 \begin_inset Quotes sld
19916 \end_inset
19917
19918 XXX
19919 \begin_inset Quotes srd
19920 \end_inset
19921
19922 .
19923
19924 \layout Standard
19925 This warning can usually be ignored due to the very good compatibility amongst
19926  14 bit PIC
19927 \begin_inset LatexCommand \index{PIC14}
19928
19929 \end_inset
19930
19931  devices.
19932
19933 \layout Standard
19934 You might also consider recompiling the library for your specific device
19935  by changing the ARCH=p16f877 (default target) entry in 
19936 \family typewriter
19937 device/lib/pic/Makefile.in
19938 \family default
19939  and 
19940 \family typewriter
19941 device/lib/pic/Makefile
19942 \family default
19943  to reflect your device.
19944  This might even improve performance for smaller devices as unneccesary
19945  BANKSELs migth be removed.
19946
19947 \layout Subsection
19948 Known bugs
19949
19950 \layout Subsubsection
19951 initialized data
19952
19953 \layout Standard
19954 Currently, data can only be initialized if it resides in the source file
19955 \pagebreak_bottom 
19956  together with 
19957 \emph on
19958 main()
19959 \emph default
19960 .
19961  Data in other source files will silently 
19962 \series bold
19963 not
19964 \series default
19965  be initialized.
19966 \family typewriter
19967 \size footnotesize
19968
19969 \begin_inset Marginal
19970 collapsed true
19971
19972 \layout Standard
19973
19974 \series bold
19975 \SpecialChar ~
19976 !
19977
19978 \end_inset
19979
19980
19981
19982
19983 \layout Section
19984 The PIC16
19985 \begin_inset LatexCommand \index{PIC16}
19986
19987 \end_inset
19988
19989  port
19990
19991 \layout Standard
19992 The PIC16
19993 \begin_inset LatexCommand \index{PIC16}
19994
19995 \end_inset
19996
19997  port is the portion of SDCC that is responsible to produce code for the
19998  Microchip
19999 \begin_inset LatexCommand \index{Microchip}
20000
20001 \end_inset
20002
20003 (TM) microcontrollers with 16 bit core.
20004  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20005  Currently supported devices are:
20006
20007 \layout Standard
20008 \align center
20009 \begin_inset Tabular
20010 <lyxtabular version="3" rows="4" columns="6">
20011 <features>
20012 <column alignment="center" valignment="top" leftline="true" width="0">
20013 <column alignment="center" valignment="top" leftline="true" width="0">
20014 <column alignment="center" valignment="top" leftline="true" width="0">
20015 <column alignment="center" valignment="top" leftline="true" width="0">
20016 <column alignment="center" valignment="top" leftline="true" width="0">
20017 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20018 <row topline="true">
20019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20020 \begin_inset Text
20021
20022 \layout Standard
20023 18F242
20024
20025 \end_inset
20026 </cell>
20027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20028 \begin_inset Text
20029
20030 \layout Standard
20031 18F248
20032
20033 \end_inset
20034 </cell>
20035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20036 \begin_inset Text
20037
20038 \layout Standard
20039 18F252
20040
20041 \end_inset
20042 </cell>
20043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20044 \begin_inset Text
20045
20046 \layout Standard
20047 18F258
20048
20049 \end_inset
20050 </cell>
20051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20052 \begin_inset Text
20053
20054 \layout Standard
20055 18F442
20056
20057 \end_inset
20058 </cell>
20059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20060 \begin_inset Text
20061
20062 \layout Standard
20063 18F448
20064
20065 \end_inset
20066 </cell>
20067 </row>
20068 <row topline="true">
20069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20070 \begin_inset Text
20071
20072 \layout Standard
20073 18F452
20074
20075 \end_inset
20076 </cell>
20077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20078 \begin_inset Text
20079
20080 \layout Standard
20081 18F458
20082
20083 \end_inset
20084 </cell>
20085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20086 \begin_inset Text
20087
20088 \layout Standard
20089 18F1220
20090
20091 \end_inset
20092 </cell>
20093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20094 \begin_inset Text
20095
20096 \layout Standard
20097 18F2220
20098
20099 \end_inset
20100 </cell>
20101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20102 \begin_inset Text
20103
20104 \layout Standard
20105 18F2550
20106
20107 \end_inset
20108 </cell>
20109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20110 \begin_inset Text
20111
20112 \layout Standard
20113 18F4331
20114
20115 \end_inset
20116 </cell>
20117 </row>
20118 <row topline="true">
20119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20120 \begin_inset Text
20121
20122 \layout Standard
20123 18F4455
20124
20125 \end_inset
20126 </cell>
20127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20128 \begin_inset Text
20129
20130 \layout Standard
20131 18F6520
20132
20133 \end_inset
20134 </cell>
20135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20136 \begin_inset Text
20137
20138 \layout Standard
20139 18F6620
20140
20141 \end_inset
20142 </cell>
20143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20144 \begin_inset Text
20145
20146 \layout Standard
20147 18F6680
20148
20149 \end_inset
20150 </cell>
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20152 \begin_inset Text
20153
20154 \layout Standard
20155 18F6720
20156
20157 \end_inset
20158 </cell>
20159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20160 \begin_inset Text
20161
20162 \layout Standard
20163 18F8520
20164
20165 \end_inset
20166 </cell>
20167 </row>
20168 <row topline="true" bottomline="true">
20169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20170 \begin_inset Text
20171
20172 \layout Standard
20173 18F8620
20174
20175 \end_inset
20176 </cell>
20177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20178 \begin_inset Text
20179
20180 \layout Standard
20181 18F8680
20182
20183 \end_inset
20184 </cell>
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20186 \begin_inset Text
20187
20188 \layout Standard
20189 18F8720
20190
20191 \end_inset
20192 </cell>
20193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20194 \begin_inset Text
20195
20196 \layout Standard
20197
20198
20199 \end_inset
20200 </cell>
20201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20202 \begin_inset Text
20203
20204 \layout Standard
20205
20206
20207 \end_inset
20208 </cell>
20209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20210 \begin_inset Text
20211
20212 \layout Standard
20213
20214
20215 \end_inset
20216 </cell>
20217 </row>
20218 </lyxtabular>
20219
20220 \end_inset
20221
20222
20223
20224 \layout Subsection
20225 Global Options
20226
20227 \layout Standard
20228 PIC16 port supports the standard command line arguments as supposed, with
20229  the exception of certain cases that will be mentioned in the following
20230  list:
20231
20232 \layout List
20233 \labelwidthstring 00.00.0000
20234 -
20235 \begin_inset ERT
20236 status Collapsed
20237
20238 \layout Standard
20239
20240
20241 \backslash
20242 /
20243
20244 \end_inset
20245
20246 -callee-saves
20247 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
20248
20249 \end_inset
20250
20251  See -
20252 \begin_inset ERT
20253 status Collapsed
20254
20255 \layout Standard
20256
20257
20258 \backslash
20259 /
20260
20261 \end_inset
20262
20263 -all-callee-saves
20264
20265 \layout List
20266 \labelwidthstring 00.00.0000
20267 -
20268 \begin_inset ERT
20269 status Collapsed
20270
20271 \layout Standard
20272
20273
20274 \backslash
20275 /
20276
20277 \end_inset
20278
20279 -all-callee-saves
20280 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
20281
20282 \end_inset
20283
20284  All function arguments are passed on stack by default.
20285  
20286 \emph on
20287 There is no need to specify this in the command line.
20288
20289 \layout List
20290 \labelwidthstring 00.00.0000
20291 -
20292 \begin_inset ERT
20293 status Collapsed
20294
20295 \layout Standard
20296
20297
20298 \backslash
20299 /
20300
20301 \end_inset
20302
20303 -fommit-frame-pointer
20304 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
20305
20306 \end_inset
20307
20308  Frame pointer will be omitted when the function uses no local variables.
20309
20310 \layout Subsection
20311 Port Specific Options
20312 \begin_inset LatexCommand \index{Options PIC16}
20313
20314 \end_inset
20315
20316
20317
20318 \layout Standard
20319 The port specific options appear after the global options in the sdcc --help
20320  output.
20321
20322 \layout Subsubsection
20323 General Options
20324
20325 \layout Standard
20326 General options enable certain port features and optimizations.
20327
20328 \layout List
20329 \labelwidthstring 00.00.0000
20330 -
20331 \begin_inset ERT
20332 status Collapsed
20333
20334 \layout Standard
20335
20336
20337 \backslash
20338 /
20339
20340 \end_inset
20341
20342 -pstack-model=[model] Used in conjuction with the command above.
20343  Defines the stack model to be used, valid stack models are : 
20344
20345 \begin_deeper
20346 \layout List
20347 \labelwidthstring 00.00.0000
20348
20349 \emph on
20350 small
20351 \emph default
20352  Selects small stack model.
20353  8 bit stack and frame pointers.
20354  Supports 256 bytes stack size.
20355
20356 \layout List
20357 \labelwidthstring 00.00.0000
20358
20359 \emph on
20360 large
20361 \emph default
20362  Selects large stack model.
20363  16 bit stack and frame pointers.
20364  Supports 65536 bytes stack size.
20365
20366 \end_deeper
20367 \layout List
20368 \labelwidthstring 00.00.0000
20369 -
20370 \begin_inset ERT
20371 status Collapsed
20372
20373 \layout Standard
20374
20375
20376 \backslash
20377 /
20378
20379 \end_inset
20380
20381 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
20382  unitialized data variables with [kword].
20383  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
20384
20385 \layout List
20386 \labelwidthstring 00.00.0000
20387 -
20388 \begin_inset ERT
20389 status Collapsed
20390
20391 \layout Standard
20392
20393
20394 \backslash
20395 /
20396
20397 \end_inset
20398
20399 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
20400  Useful for bootloaders.
20401
20402 \layout List
20403 \labelwidthstring 00.00.0000
20404 -
20405 \begin_inset ERT
20406 status Collapsed
20407
20408 \layout Standard
20409
20410
20411 \backslash
20412 /
20413
20414 \end_inset
20415
20416 -asm= sets the full path and name of an external assembler to call.
20417
20418 \layout List
20419 \labelwidthstring 00.00.0000
20420 -
20421 \begin_inset ERT
20422 status Collapsed
20423
20424 \layout Standard
20425
20426
20427 \backslash
20428 /
20429
20430 \end_inset
20431
20432 -link= sets the full path and name of an external linker to call.
20433
20434 \layout List
20435 \labelwidthstring 00.00.0000
20436 -
20437 \begin_inset ERT
20438 status Collapsed
20439
20440 \layout Standard
20441
20442
20443 \backslash
20444 /
20445
20446 \end_inset
20447
20448 -mplab-comp MPLAB
20449 \begin_inset LatexCommand \index{PIC16!MPLAB}
20450
20451 \end_inset
20452
20453  compatibility option.
20454  Currently only suppresses special gpasm directives.
20455
20456 \layout Subsubsection
20457 Optimization Options
20458
20459 \layout List
20460 \labelwidthstring 00.00.0000
20461 -
20462 \begin_inset ERT
20463 status Collapsed
20464
20465 \layout Standard
20466
20467
20468 \backslash
20469 /
20470
20471 \end_inset
20472
20473 -optimize-goto Try to use (conditional) BRA instead of GOTO
20474
20475 \layout List
20476 \labelwidthstring 00.00.0000
20477 -
20478 \begin_inset ERT
20479 status Collapsed
20480
20481 \layout Standard
20482
20483
20484 \backslash
20485 /
20486
20487 \end_inset
20488
20489 -optimize-cmp Try to optimize some compares.
20490
20491 \layout List
20492 \labelwidthstring 00.00.0000
20493 -
20494 \begin_inset ERT
20495 status Collapsed
20496
20497 \layout Standard
20498
20499
20500 \backslash
20501 /
20502
20503 \end_inset
20504
20505 -optimize-df Analyze the dataflow of the generated code and improve it.
20506
20507 \layout List
20508 \labelwidthstring 00.00.0000
20509 -
20510 \begin_inset ERT
20511 status Collapsed
20512
20513 \layout Standard
20514
20515
20516 \backslash
20517 /
20518
20519 \end_inset
20520
20521 -obanksel=nn Set optimization level for inserting BANKSELs.
20522 \newline
20523
20524
20525 \begin_deeper
20526 \layout List
20527 \labelwidthstring 00.00.0000
20528 0 no optimization
20529
20530 \layout List
20531 \labelwidthstring 00.00.0000
20532 1 checks previous used register and if it is the same then does not emit
20533  BANKSEL, accounts only for labels.
20534
20535 \layout List
20536 \labelwidthstring 00.00.0000
20537 2 tries to check the location of (even different) symbols and removes BANKSELs
20538  if they are in the same bank.
20539  
20540 \newline
20541
20542 \emph on
20543 Important: There might be problems if the linker script has data sections
20544  across bank borders!
20545
20546 \end_deeper
20547 \layout Subsubsection
20548 Linking Options
20549
20550 \layout List
20551 \labelwidthstring 00.00.0000
20552 -
20553 \begin_inset ERT
20554 status Collapsed
20555
20556 \layout Standard
20557
20558
20559 \backslash
20560 /
20561
20562 \end_inset
20563
20564 -nodefaultlibs do not link default libraries when linking
20565
20566 \layout List
20567 \labelwidthstring 00.00.0000
20568 -
20569 \begin_inset ERT
20570 status Collapsed
20571
20572 \layout Standard
20573
20574
20575 \backslash
20576 /
20577
20578 \end_inset
20579
20580 -no-crt Don't link the default run-time modules
20581
20582 \layout List
20583 \labelwidthstring 00.00.0000
20584 -
20585 \begin_inset ERT
20586 status Collapsed
20587
20588 \layout Standard
20589
20590
20591 \backslash
20592 /
20593
20594 \end_inset
20595
20596 -use-crt= Use a custom run-time module instead of the defaults.
20597
20598 \layout Subsubsection
20599 Debugging Options
20600
20601 \layout Standard
20602 Debugging options enable extra debugging information in the output files.
20603
20604 \layout List
20605 \labelwidthstring 00.00.0000
20606 -
20607 \begin_inset ERT
20608 status Collapsed
20609
20610 \layout Standard
20611
20612
20613 \backslash
20614 /
20615
20616 \end_inset
20617
20618 -debug-xtra Similar to -
20619 \begin_inset ERT
20620 status Collapsed
20621
20622 \layout Standard
20623
20624
20625 \backslash
20626 /
20627
20628 \end_inset
20629
20630 -debug
20631 \begin_inset LatexCommand \index{-\/-debug}
20632
20633 \end_inset
20634
20635 , but dumps more information.
20636
20637 \layout List
20638 \labelwidthstring 00.00.0000
20639 -
20640 \begin_inset ERT
20641 status Collapsed
20642
20643 \layout Standard
20644
20645
20646 \backslash
20647 /
20648
20649 \end_inset
20650
20651 -debug-ralloc Force register allocator to dump <source>.d file with debugging
20652  information.
20653  <source> is the name of the file compiled.
20654
20655 \layout List
20656 \labelwidthstring 00.00.0000
20657 -
20658 \begin_inset ERT
20659 status Collapsed
20660
20661 \layout Standard
20662
20663
20664 \backslash
20665 /
20666
20667 \end_inset
20668
20669 -pcode-verbose Enable pcode debugging information in translation.
20670
20671 \layout List
20672 \labelwidthstring 00.00.0000
20673 -
20674 \begin_inset ERT
20675 status Collapsed
20676
20677 \layout Standard
20678
20679
20680 \backslash
20681 /
20682
20683 \end_inset
20684
20685 -denable-peeps Force the usage of peepholes.
20686  Use with care.
20687
20688 \layout List
20689 \labelwidthstring 00.00.0000
20690 -
20691 \begin_inset ERT
20692 status Collapsed
20693
20694 \layout Standard
20695
20696
20697 \backslash
20698 /
20699
20700 \end_inset
20701
20702 -gstack Trace push/pops for stack pointer overflow
20703
20704 \layout List
20705 \labelwidthstring 00.00.0000
20706 -
20707 \begin_inset ERT
20708 status Collapsed
20709
20710 \layout Standard
20711
20712
20713 \backslash
20714 /
20715
20716 \end_inset
20717
20718 -call-tree dump call tree in .calltree file
20719
20720 \layout Subsection
20721 Enviromental Variables
20722
20723 \layout Standard
20724 There is a number of enviromental variables that can be used when running
20725  SDCC to enable certain optimizations or force a specific program behaviour.
20726  these variables are primarily for debugging purposes so they can be enabled/dis
20727 abled at will.
20728
20729 \layout Standard
20730 Currently there is only two such variables available:
20731
20732 \layout List
20733 \labelwidthstring 00.00.0000
20734 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
20735  bitfields is optimized by directly loading FSR0 with the address of the
20736  bitfield structure.
20737  Normally SDCC will cast the bitfield structure to a bitfield pointer and
20738  then load FSR0.
20739  This step saves data ram and code space for functions that perform heavy
20740  use of bitfields.
20741  (ie.
20742  80 bytes of code space are saved when compiling malloc.c with this option).
20743  
20744
20745 \layout List
20746 \labelwidthstring 00.00.0000
20747 NO_REG_OPT do not perform pCode registers optimization.
20748  This should be used for debugging purposes.
20749  In some where bugs in the pcode optimizer are found, users can benefit
20750  from temporarily disabling the optimizer until the bug is fixed.
20751
20752 \layout Subsection
20753 Preprocessor Macros
20754
20755 \layout Standard
20756 PIC16
20757 \begin_inset LatexCommand \index{PIC16}
20758
20759 \end_inset
20760
20761  port defines the following preprocessor macros while translating a source.
20762
20763 \layout Standard
20764 \align center
20765 \begin_inset Tabular
20766 <lyxtabular version="3" rows="6" columns="2">
20767 <features>
20768 <column alignment="center" valignment="top" leftline="true" width="0">
20769 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20770 <row topline="true" bottomline="true">
20771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20772 \begin_inset Text
20773
20774 \layout Standard
20775 Macro
20776
20777 \end_inset
20778 </cell>
20779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20780 \begin_inset Text
20781
20782 \layout Standard
20783 Description
20784
20785 \end_inset
20786 </cell>
20787 </row>
20788 <row topline="true">
20789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20790 \begin_inset Text
20791
20792 \layout Standard
20793 SDCC_pic16
20794
20795 \end_inset
20796 </cell>
20797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20798 \begin_inset Text
20799
20800 \layout Standard
20801 Port identification
20802
20803 \end_inset
20804 </cell>
20805 </row>
20806 <row topline="true">
20807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20808 \begin_inset Text
20809
20810 \layout Standard
20811 _
20812 \begin_inset ERT
20813 status Collapsed
20814
20815 \layout Standard
20816
20817
20818 \backslash
20819 /
20820
20821 \end_inset
20822
20823 _pic16
20824
20825 \end_inset
20826 </cell>
20827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20828 \begin_inset Text
20829
20830 \layout Standard
20831 Port identification (same as above)
20832
20833 \end_inset
20834 </cell>
20835 </row>
20836 <row topline="true">
20837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20838 \begin_inset Text
20839
20840 \layout Standard
20841 pic18fxxxx
20842
20843 \end_inset
20844 </cell>
20845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20846 \begin_inset Text
20847
20848 \layout Standard
20849 MCU Identification.
20850  
20851 \emph on
20852 xxxx
20853 \emph default
20854  is the microcontrol identification number, i.e.
20855  452, 6620, etc
20856
20857 \end_inset
20858 </cell>
20859 </row>
20860 <row topline="true">
20861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20862 \begin_inset Text
20863
20864 \layout Standard
20865 _
20866 \begin_inset ERT
20867 status Collapsed
20868
20869 \layout Standard
20870
20871
20872 \backslash
20873 /
20874
20875 \end_inset
20876
20877 _18Fxxxx
20878
20879 \end_inset
20880 </cell>
20881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20882 \begin_inset Text
20883
20884 \layout Standard
20885 MCU Identification (same as above)
20886
20887 \end_inset
20888 </cell>
20889 </row>
20890 <row topline="true" bottomline="true">
20891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20892 \begin_inset Text
20893
20894 \layout Standard
20895 STACK_MODEL_nnn
20896
20897 \end_inset
20898 </cell>
20899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20900 \begin_inset Text
20901
20902 \layout Standard
20903 nnn = SMALL or LARGE respectively according to the stack model used
20904
20905 \end_inset
20906 </cell>
20907 </row>
20908 </lyxtabular>
20909
20910 \end_inset
20911
20912
20913
20914 \layout Standard
20915 In addition the following macros are defined when calling assembler:
20916
20917 \layout Standard
20918 \align center
20919 \begin_inset Tabular
20920 <lyxtabular version="3" rows="4" columns="2">
20921 <features>
20922 <column alignment="center" valignment="top" leftline="true" width="0">
20923 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20924 <row topline="true" bottomline="true">
20925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20926 \begin_inset Text
20927
20928 \layout Standard
20929 Macro
20930
20931 \end_inset
20932 </cell>
20933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20934 \begin_inset Text
20935
20936 \layout Standard
20937 Description
20938
20939 \end_inset
20940 </cell>
20941 </row>
20942 <row topline="true">
20943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20944 \begin_inset Text
20945
20946 \layout Standard
20947 __18Fxxxx
20948
20949 \end_inset
20950 </cell>
20951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20952 \begin_inset Text
20953
20954 \layout Standard
20955 MCU Identification.
20956  
20957 \emph on
20958 xxxx
20959 \emph default
20960  is the microcontrol identification number, i.e.
20961  452, 6620, etc
20962
20963 \end_inset
20964 </cell>
20965 </row>
20966 <row topline="true">
20967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20968 \begin_inset Text
20969
20970 \layout Standard
20971 SDCC_MODEL_nnn
20972
20973 \end_inset
20974 </cell>
20975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20976 \begin_inset Text
20977
20978 \layout Standard
20979 nnn = SMALL or LARGE respectively according to the memory model used for
20980  SDCC
20981
20982 \end_inset
20983 </cell>
20984 </row>
20985 <row topline="true" bottomline="true">
20986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20987 \begin_inset Text
20988
20989 \layout Standard
20990 STACK_MODEL_nnn
20991
20992 \end_inset
20993 </cell>
20994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20995 \begin_inset Text
20996
20997 \layout Standard
20998 nnn = SMALL or LARGE respectively according to the stack model used
20999
21000 \end_inset
21001 </cell>
21002 </row>
21003 </lyxtabular>
21004
21005 \end_inset
21006
21007
21008
21009 \layout Subsection
21010 Directories
21011
21012 \layout Standard
21013 PIC16
21014 \begin_inset LatexCommand \index{PIC16}
21015
21016 \end_inset
21017
21018  port uses the following directories for searching header files and libraries.
21019
21020 \layout Standard
21021 \align center
21022 \begin_inset Tabular
21023 <lyxtabular version="3" rows="3" columns="4">
21024 <features>
21025 <column alignment="center" valignment="top" leftline="true" width="0">
21026 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21027 <column alignment="center" valignment="top" width="0">
21028 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21029 <row topline="true" bottomline="true">
21030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21031 \begin_inset Text
21032
21033 \layout Standard
21034 Directory
21035
21036 \end_inset
21037 </cell>
21038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21039 \begin_inset Text
21040
21041 \layout Standard
21042 Description
21043
21044 \end_inset
21045 </cell>
21046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21047 \begin_inset Text
21048
21049 \layout Standard
21050 Target
21051
21052 \end_inset
21053 </cell>
21054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21055 \begin_inset Text
21056
21057 \layout Standard
21058 Command prefix
21059
21060 \end_inset
21061 </cell>
21062 </row>
21063 <row topline="true">
21064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21065 \begin_inset Text
21066
21067 \layout Standard
21068 PREFIX/sdcc/include/pic16
21069
21070 \end_inset
21071 </cell>
21072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21073 \begin_inset Text
21074
21075 \layout Standard
21076 PIC16 specific headers
21077
21078 \end_inset
21079 </cell>
21080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21081 \begin_inset Text
21082
21083 \layout Standard
21084 Compiler
21085
21086 \end_inset
21087 </cell>
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21089 \begin_inset Text
21090
21091 \layout Standard
21092 -I
21093
21094 \end_inset
21095 </cell>
21096 </row>
21097 <row topline="true" bottomline="true">
21098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21099 \begin_inset Text
21100
21101 \layout Standard
21102 PREFIX/sdcc/lib/pic16
21103
21104 \end_inset
21105 </cell>
21106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21107 \begin_inset Text
21108
21109 \layout Standard
21110 PIC16 specific libraries
21111
21112 \end_inset
21113 </cell>
21114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21115 \begin_inset Text
21116
21117 \layout Standard
21118 Linker
21119
21120 \end_inset
21121 </cell>
21122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21123 \begin_inset Text
21124
21125 \layout Standard
21126 -L
21127
21128 \end_inset
21129 </cell>
21130 </row>
21131 </lyxtabular>
21132
21133 \end_inset
21134
21135
21136
21137 \layout Subsection
21138 Pragmas
21139 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
21140
21141 \end_inset
21142
21143
21144
21145 \layout Standard
21146 PIC16
21147 \begin_inset LatexCommand \index{PIC16}
21148
21149 \end_inset
21150
21151  port currently supports the following pragmas:
21152
21153 \layout List
21154 \labelwidthstring 00.00.0000
21155 stack
21156 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
21157
21158 \end_inset
21159
21160  pragma stack
21161 \begin_inset LatexCommand \index{PIC16!stack}
21162
21163 \end_inset
21164
21165  forces the code generator to initialize the stack & frame pointers at a
21166  specific address.
21167  This is an adhoc solution for cases where no STACK directive is available
21168  in the linker script or gplink is not instructed to create a stack section.
21169 \newline
21170 The
21171  stack pragma should be used only once in a project.
21172  Multiple pragmas may result in indeterminate behaviour of the program.
21173 \begin_inset Foot
21174 collapsed false
21175
21176 \layout Standard
21177 The old format (ie.
21178  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
21179  cross page boundaries (or even exceed the available data RAM) and crash
21180  the program.
21181  Make sure that stack does not cross page boundaries when using the SMALL
21182  stack model.
21183
21184 \end_inset
21185
21186
21187 \newline
21188 The format is as follows:
21189
21190 \layout LyX-Code
21191 #pragma stack bottom_address [stack_size]
21192
21193 \layout Standard
21194
21195 \emph on
21196 bottom_address
21197 \emph default
21198  is the lower bound of the stack section.
21199  The stack pointer initially will point at address (bottom_address+stack_size-1).
21200
21201 \layout LyX-Code
21202 Example:
21203
21204 \layout LyX-Code
21205
21206
21207 \layout LyX-Code
21208 /* initializes stack of 100 bytes at RAM address 0x200 */
21209
21210 \layout LyX-Code
21211 #pragma stack 0x200 100
21212
21213 \layout Standard
21214 If the stack_size field is omitted then a stack is created with the default
21215  size of 64.
21216  This size might be enough for most programs, but its not enough for operations
21217  with deep function nesting or excessive stack usage.
21218
21219 \layout List
21220 \labelwidthstring 00.00.0000
21221 code
21222 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
21223
21224 \end_inset
21225
21226  place a function symbol at static FLASH address
21227
21228 \layout LyX-Code
21229 Example:
21230
21231 \layout LyX-Code
21232
21233
21234 \layout LyX-Code
21235 /* place function test_func at 0x4000 */
21236
21237 \layout LyX-Code
21238 #pragma code test_func 0x4000
21239
21240 \layout LyX-Code
21241
21242
21243 \layout List
21244 \labelwidthstring 00.00.0000
21245 library instructs the linker to use a library module.
21246 \newline
21247 Usage:
21248
21249 \layout LyX-Code
21250 #pragma library module_name
21251
21252 \layout Standard
21253
21254 \emph on
21255 module_name
21256 \emph default
21257  can be any library or object file (including its path).
21258  Note that there are four reserved keywords which have special meaning.
21259  These are:
21260
21261 \layout Standard
21262 \align center
21263 \begin_inset Tabular
21264 <lyxtabular version="3" rows="6" columns="3">
21265 <features>
21266 <column alignment="center" valignment="top" leftline="true" width="0">
21267 <column alignment="block" valignment="top" leftline="true" width="20page%">
21268 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
21269 <row topline="true" bottomline="true">
21270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21271 \begin_inset Text
21272
21273 \layout Standard
21274 Keyword
21275
21276 \end_inset
21277 </cell>
21278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21279 \begin_inset Text
21280
21281 \layout Standard
21282 Description
21283
21284 \end_inset
21285 </cell>
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21287 \begin_inset Text
21288
21289 \layout Standard
21290 Module to link
21291
21292 \end_inset
21293 </cell>
21294 </row>
21295 <row topline="true">
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21297 \begin_inset Text
21298
21299 \layout Standard
21300
21301 \series bold
21302 ignore
21303
21304 \end_inset
21305 </cell>
21306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21307 \begin_inset Text
21308
21309 \layout Standard
21310 ignore all library pragmas
21311
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 \emph on
21320 (none)
21321
21322 \end_inset
21323 </cell>
21324 </row>
21325 <row topline="true">
21326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21327 \begin_inset Text
21328
21329 \layout Standard
21330
21331 \series bold
21332 c
21333
21334 \end_inset
21335 </cell>
21336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21337 \begin_inset Text
21338
21339 \layout Standard
21340 link the C library
21341
21342 \end_inset
21343 </cell>
21344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21345 \begin_inset Text
21346
21347 \layout Standard
21348
21349 \emph on
21350 libc18f
21351 \emph default
21352 .lib
21353
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 \series bold
21364 math
21365
21366 \end_inset
21367 </cell>
21368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21369 \begin_inset Text
21370
21371 \layout Standard
21372 link the Math libarary
21373
21374 \end_inset
21375 </cell>
21376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21377 \begin_inset Text
21378
21379 \layout Standard
21380
21381 \emph on
21382 libm18f
21383 \emph default
21384 .lib
21385
21386 \end_inset
21387 </cell>
21388 </row>
21389 <row topline="true">
21390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21391 \begin_inset Text
21392
21393 \layout Standard
21394
21395 \series bold
21396 io
21397
21398 \end_inset
21399 </cell>
21400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21401 \begin_inset Text
21402
21403 \layout Standard
21404 link the I/O library
21405
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 \emph on
21414 libio18f*
21415 \emph default
21416 .lib
21417
21418 \end_inset
21419 </cell>
21420 </row>
21421 <row topline="true" bottomline="true">
21422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21423 \begin_inset Text
21424
21425 \layout Standard
21426
21427 \series bold
21428 debug
21429
21430 \end_inset
21431 </cell>
21432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21433 \begin_inset Text
21434
21435 \layout Standard
21436 link the debug library
21437
21438 \end_inset
21439 </cell>
21440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21441 \begin_inset Text
21442
21443 \layout Standard
21444
21445 \emph on
21446 libdebug
21447 \emph default
21448 .lib
21449
21450 \end_inset
21451 </cell>
21452 </row>
21453 </lyxtabular>
21454
21455 \end_inset
21456
21457
21458 \newline
21459 * is the device number, i.e.
21460  452 for PIC18F452 MCU.
21461
21462 \layout Standard
21463 This feature allows for linking with specific libraries withoug having to
21464  explicit name them in the command line.
21465  Note that the 
21466 \noun on
21467 ignore
21468 \noun default
21469  keyword will reject all modules specified by the library pragma.
21470
21471 \layout List
21472 \labelwidthstring 00.00.0000
21473 udata pragma udata instructs the compiler to emit code so that linker will
21474  place a variable at a specific memory bank
21475
21476 \layout LyX-Code
21477 Example:
21478
21479 \layout LyX-Code
21480
21481
21482 \layout LyX-Code
21483 /* places variable foo at bank2 */
21484
21485 \layout LyX-Code
21486 #pragma udata bank2 foo
21487
21488 \layout LyX-Code
21489 char foo;
21490
21491 \layout Standard
21492 In order for this pragma to work extra SECTION directives should be added
21493  in the .lkr script.
21494  In the following example a sample .lkr file is shown:
21495
21496 \layout LyX-Code
21497
21498
21499 \layout LyX-Code
21500 // Sample linker script for the PIC18F452 processor
21501
21502 \layout LyX-Code
21503 LIBPATH .
21504
21505 \layout LyX-Code
21506 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
21507
21508 \layout LyX-Code
21509 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
21510
21511 \layout LyX-Code
21512 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
21513
21514 \layout LyX-Code
21515 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
21516
21517 \layout LyX-Code
21518 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
21519
21520 \layout LyX-Code
21521 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
21522
21523 \layout LyX-Code
21524 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
21525
21526 \layout LyX-Code
21527
21528
21529 \layout LyX-Code
21530 DATABANK   NAME=gpr0       START=0x80           END=0xFF
21531
21532 \layout LyX-Code
21533 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
21534
21535 \layout LyX-Code
21536 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
21537
21538 \layout LyX-Code
21539 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
21540
21541 \layout LyX-Code
21542 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
21543
21544 \layout LyX-Code
21545 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
21546
21547 \layout LyX-Code
21548 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
21549
21550 \layout LyX-Code
21551
21552
21553 \layout LyX-Code
21554 SECTION    NAME=CONFIG     ROM=config
21555
21556 \layout LyX-Code
21557
21558
21559 \layout LyX-Code
21560 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
21561
21562 \layout LyX-Code
21563 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
21564
21565 \layout LyX-Code
21566 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
21567
21568 \layout LyX-Code
21569 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
21570
21571 \layout LyX-Code
21572 SECTION    NAME=bank4      RAM=gpr4
21573
21574 \layout LyX-Code
21575 SECTION    NAME=bank5      RAM=gpr5
21576
21577 \layout Standard
21578 The linker will recognise the section name set in the pragma statement and
21579  will position the variable at the memory bank set with the RAM field at
21580  the SECTION line in the linker script file.
21581
21582 \layout Subsection
21583 Header Files
21584 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
21585
21586 \end_inset
21587
21588
21589
21590 \layout Standard
21591 There is one main header file
21592 \begin_inset LatexCommand \index{PIC16!Header files}
21593
21594 \end_inset
21595
21596  that can be included to the source files using the pic16
21597 \begin_inset LatexCommand \index{PIC16}
21598
21599 \end_inset
21600
21601  port.
21602  That file is the 
21603 \series bold
21604 pic18fregs.h
21605 \series default
21606 .
21607  This header file contains the definitions for the processor special registers,
21608  so it is necessary if the source accesses them.
21609  It can be included by adding the following line in the beginning of the
21610  file:
21611
21612 \layout LyX-Code
21613 #include <pic18fregs.h>
21614
21615 \layout Standard
21616 The specific microcontroller is selected within the pic18fregs.h automatically,
21617  so the same source can be used with a variety of devices.
21618
21619 \layout Subsection
21620 Libraries
21621
21622 \layout Standard
21623 The libraries
21624 \begin_inset LatexCommand \index{PIC16!Libraries}
21625
21626 \end_inset
21627
21628  that PIC16
21629 \begin_inset LatexCommand \index{PIC16}
21630
21631 \end_inset
21632
21633  port depends on are the microcontroller device libraries which contain
21634  the symbol definitions for the microcontroller special function registers.
21635  These libraries have the format pic18fxxxx.lib, where 
21636 \emph on
21637 xxxx
21638 \emph default
21639  is the microcontroller identification number.
21640  The specific library is selected automatically by the compiler at link
21641  stage according to the selected device.
21642
21643 \layout Standard
21644 Libraries are created with gplib which is part of the gputils package 
21645 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21646
21647 \end_inset
21648
21649 .
21650
21651 \layout Subsubsection*
21652 Building the libraries
21653
21654 \layout Standard
21655 Before using SDCC/pic16 there are some libraries that need to be compiled.
21656  This process is not done automatically by SDCC since not all users use
21657  SDCC for pic16 projects.
21658  So each user should compile the libraries separately.
21659
21660 \layout Standard
21661 The steps to compile the pic16 libraries under Linux are:
21662
21663 \layout LyX-Code
21664 cd device/lib/pic16
21665
21666 \layout LyX-Code
21667 ./configure
21668
21669 \layout LyX-Code
21670 make
21671
21672 \layout LyX-Code
21673 cd ..
21674
21675 \layout LyX-Code
21676 make model-pic16
21677
21678 \layout LyX-Code
21679 su -c 'make install'     # install the libraries, you need the root password
21680
21681 \layout Standard
21682 If you need to install the headers too, do:
21683
21684 \layout LyX-Code
21685 cd device/include
21686
21687 \layout LyX-Code
21688 su -c 'make install'     # install the headers, you need the root password
21689
21690 \layout Standard
21691 There exist a special target to build the I/O libraries.
21692  This target is not automatically build because it will build the I/O library
21693  for 
21694 \emph on
21695 every
21696 \emph default
21697  supported device.
21698  This way building will take quite a lot of time.
21699  Users are advised to edit the 
21700 \series bold
21701 device/lib/pic16/pics.build
21702 \series default
21703  file and then execute:
21704
21705 \layout LyX-Code
21706 make lib-io
21707
21708 \layout Subsection
21709 Memory Models
21710
21711 \layout Standard
21712 The following memory models are supported by the PIC16 port:
21713
21714 \layout Itemize
21715 small model
21716
21717 \layout Itemize
21718 large model
21719
21720 \layout Standard
21721 Memory model affects the default size of pointers within the source.
21722  The sizes are shown in the next table:
21723
21724 \layout Standard
21725 \align center
21726 \begin_inset Tabular
21727 <lyxtabular version="3" rows="3" columns="3">
21728 <features>
21729 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21730 <column alignment="center" valignment="top" leftline="true" width="0">
21731 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21732 <row topline="true" bottomline="true">
21733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21734 \begin_inset Text
21735
21736 \layout Standard
21737 Pointer sizes according to memory model
21738
21739 \end_inset
21740 </cell>
21741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21742 \begin_inset Text
21743
21744 \layout Standard
21745 small model
21746
21747 \end_inset
21748 </cell>
21749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21750 \begin_inset Text
21751
21752 \layout Standard
21753 large model
21754
21755 \end_inset
21756 </cell>
21757 </row>
21758 <row topline="true" bottomline="true">
21759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21760 \begin_inset Text
21761
21762 \layout Standard
21763 code pointers
21764
21765 \end_inset
21766 </cell>
21767 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21768 \begin_inset Text
21769
21770 \layout Standard
21771 16-bits
21772
21773 \end_inset
21774 </cell>
21775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21776 \begin_inset Text
21777
21778 \layout Standard
21779 24-bits
21780
21781 \end_inset
21782 </cell>
21783 </row>
21784 <row topline="true" bottomline="true">
21785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21786 \begin_inset Text
21787
21788 \layout Standard
21789 data pointers
21790
21791 \end_inset
21792 </cell>
21793 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
21794 \begin_inset Text
21795
21796 \layout Standard
21797 16-bits
21798
21799 \end_inset
21800 </cell>
21801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21802 \begin_inset Text
21803
21804 \layout Standard
21805 16-bits
21806
21807 \end_inset
21808 </cell>
21809 </row>
21810 </lyxtabular>
21811
21812 \end_inset
21813
21814
21815
21816 \layout Standard
21817 It is advisable that all sources within a project are compiled with the
21818  same memory model.
21819  If one wants to override the default memory model, this can be done by
21820  declaring a pointer as 
21821 \series bold
21822 far
21823 \series default
21824  or 
21825 \series bold
21826 near
21827 \series default
21828 .
21829  Far selects large memory model's pointers, while near selects small memory
21830  model's pointers.
21831
21832 \layout Standard
21833 The standard device libraries (see 
21834 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
21835
21836 \end_inset
21837
21838 ) contain no reference to pointers, so they can be used with both memory
21839  models.
21840
21841 \layout Subsection
21842 Stack
21843
21844 \layout Standard
21845 The stack
21846 \begin_inset LatexCommand \index{PIC16!stack}
21847
21848 \end_inset
21849
21850  implementation for the PIC16 port uses two indirect registers, FSR1 and
21851  FSR2.
21852
21853 \layout List
21854 \labelwidthstring 00.00.0000
21855 FSR1 is assigned as stack pointer
21856
21857 \layout List
21858 \labelwidthstring 00.00.0000
21859 FSR2 is assigned as frame pointer
21860
21861 \layout Standard
21862 The following stack models are supported by the PIC16 port
21863
21864 \layout Itemize
21865
21866 \noun on
21867 small
21868 \noun default
21869  model
21870
21871 \layout Itemize
21872
21873 \noun on
21874 large
21875 \noun default
21876  model
21877
21878 \layout Standard
21879
21880 \noun on
21881 Small
21882 \noun default
21883  model means that only the FSRxL byte is used to access stack and frame,
21884  while 
21885 \emph on
21886 \noun on
21887 large
21888 \emph default
21889 \noun default
21890  uses both FSRxL and FSRxH registers.
21891  The following table shows the stack/frame pointers sizes according to stack
21892  model and the maximum space they can address:
21893
21894 \layout Standard
21895 \align center
21896 \begin_inset Tabular
21897 <lyxtabular version="3" rows="3" columns="3">
21898 <features>
21899 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21900 <column alignment="center" valignment="top" leftline="true" width="0">
21901 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21902 <row topline="true" bottomline="true">
21903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21904 \begin_inset Text
21905
21906 \layout Standard
21907 Stack & Frame pointer sizes according to stack model
21908
21909 \end_inset
21910 </cell>
21911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21912 \begin_inset Text
21913
21914 \layout Standard
21915 small
21916
21917 \end_inset
21918 </cell>
21919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21920 \begin_inset Text
21921
21922 \layout Standard
21923 large
21924
21925 \end_inset
21926 </cell>
21927 </row>
21928 <row topline="true">
21929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21930 \begin_inset Text
21931
21932 \layout Standard
21933 Stack pointer FSR1
21934
21935 \end_inset
21936 </cell>
21937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21938 \begin_inset Text
21939
21940 \layout Standard
21941 8-bits
21942
21943 \end_inset
21944 </cell>
21945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21946 \begin_inset Text
21947
21948 \layout Standard
21949 16-bits
21950
21951 \end_inset
21952 </cell>
21953 </row>
21954 <row topline="true" bottomline="true">
21955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21956 \begin_inset Text
21957
21958 \layout Standard
21959 Frame pointer FSR2
21960
21961 \end_inset
21962 </cell>
21963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21964 \begin_inset Text
21965
21966 \layout Standard
21967 8-bits
21968
21969 \end_inset
21970 </cell>
21971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21972 \begin_inset Text
21973
21974 \layout Standard
21975 16-bits
21976
21977 \end_inset
21978 </cell>
21979 </row>
21980 </lyxtabular>
21981
21982 \end_inset
21983
21984
21985
21986 \layout Standard
21987
21988 \noun on
21989 Large 
21990 \noun default
21991 stack model is currently not working properly throughout the code generator.
21992  So its use is not advised.
21993  Also there are some other points that need special care:
21994 \newline
21995
21996
21997 \layout Enumerate
21998 Do not create stack sections with size more than one physical bank (that
21999  is 256 bytes)
22000
22001 \layout Enumerate
22002 Stack sections should no cross physical bank limits (i.e.
22003  #pragma stack 0x50 0x100)
22004
22005 \layout Standard
22006 These limitations are caused by the fact that only FSRxL is modified when
22007  using SMALL stack model, so no more than 256 bytes of stack can be used.
22008  This problem will disappear after LARGE model is fully implemented.
22009
22010 \layout Subsection
22011 Functions
22012
22013 \layout Standard
22014 In addition to the standard SDCC function keywords, PIC16
22015 \begin_inset LatexCommand \index{PIC16}
22016
22017 \end_inset
22018
22019  port makes available two more:
22020
22021 \layout List
22022 \labelwidthstring 00.00.0000
22023 wparam
22024 \begin_inset LatexCommand \index{PIC16!wparam}
22025
22026 \end_inset
22027
22028  Use the WREG to pass one byte of the first function argument.
22029  This improves speed but you may not use this for functions with arguments
22030  that are called via function pointers, otherwise the first byte of the
22031  first parameter will get lost.
22032  Usage:
22033
22034 \layout LyX-Code
22035 void func_wparam(int a) wparam
22036
22037 \layout LyX-Code
22038 {
22039
22040 \layout LyX-Code
22041     /* WREG hold the lower part of a */
22042
22043 \layout LyX-Code
22044     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22045  */
22046
22047 \layout LyX-Code
22048 ...
22049
22050 \layout LyX-Code
22051 }
22052
22053 \layout List
22054 \labelwidthstring 00.00.0000
22055 shadowregs
22056 \begin_inset LatexCommand \index{PIC16!shadowregs}
22057
22058 \end_inset
22059
22060  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22061  hardware shadow registers which hold the values of WREG, STATUS and BSR
22062  registers.
22063  This can be done by adding the keyword 
22064 \emph on
22065 shadowregs
22066 \emph default
22067  before the 
22068 \emph on
22069 interrupt
22070 \emph default
22071  keyword in the function's header.
22072
22073 \layout LyX-Code
22074 void isr_shadow(void) shadowregs interrupt 1
22075
22076 \layout LyX-Code
22077 {
22078
22079 \layout LyX-Code
22080 ...
22081
22082 \layout LyX-Code
22083 }
22084
22085 \layout Standard
22086
22087 \emph on
22088 shadowregs
22089 \emph default
22090  instructs the code generator not to store/restore WREG, STATUS, BSR when
22091  entering/exiting the ISR.
22092
22093 \layout Subsection
22094 Function return values
22095
22096 \layout Standard
22097 Return values from functions are placed to the appropriate registers following
22098  a modified Microchip policy optimized for SDCC.
22099  The following table shows these registers:
22100
22101 \layout Standard
22102 \align center
22103 \begin_inset Tabular
22104 <lyxtabular version="3" rows="6" columns="2">
22105 <features>
22106 <column alignment="center" valignment="top" leftline="true" width="0">
22107 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22108 <row topline="true" bottomline="true">
22109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22110 \begin_inset Text
22111
22112 \layout Standard
22113 size
22114
22115 \end_inset
22116 </cell>
22117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22118 \begin_inset Text
22119
22120 \layout Standard
22121 destination register
22122
22123 \end_inset
22124 </cell>
22125 </row>
22126 <row topline="true">
22127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22128 \begin_inset Text
22129
22130 \layout Standard
22131 8 bits
22132
22133 \end_inset
22134 </cell>
22135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22136 \begin_inset Text
22137
22138 \layout Standard
22139 WREG
22140
22141 \end_inset
22142 </cell>
22143 </row>
22144 <row topline="true">
22145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22146 \begin_inset Text
22147
22148 \layout Standard
22149 16 bits
22150
22151 \end_inset
22152 </cell>
22153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22154 \begin_inset Text
22155
22156 \layout Standard
22157 PRODL:WREG
22158
22159 \end_inset
22160 </cell>
22161 </row>
22162 <row topline="true">
22163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22164 \begin_inset Text
22165
22166 \layout Standard
22167 24 bits
22168
22169 \end_inset
22170 </cell>
22171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22172 \begin_inset Text
22173
22174 \layout Standard
22175 PRODH:PRODL:WREG
22176
22177 \end_inset
22178 </cell>
22179 </row>
22180 <row topline="true">
22181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22182 \begin_inset Text
22183
22184 \layout Standard
22185 32 bits
22186
22187 \end_inset
22188 </cell>
22189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22190 \begin_inset Text
22191
22192 \layout Standard
22193 FSR0L:PRODH:PRODL:WREG
22194
22195 \end_inset
22196 </cell>
22197 </row>
22198 <row topline="true" bottomline="true">
22199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22200 \begin_inset Text
22201
22202 \layout Standard
22203 >32 bits
22204
22205 \end_inset
22206 </cell>
22207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22208 \begin_inset Text
22209
22210 \layout Standard
22211 on stack, FSR0 points to the beginning
22212
22213 \end_inset
22214 </cell>
22215 </row>
22216 </lyxtabular>
22217
22218 \end_inset
22219
22220
22221
22222 \layout Subsection
22223 Interrupts
22224
22225 \layout Standard
22226 An interrupt
22227 \begin_inset LatexCommand \index{PIC16!interrupt}
22228
22229 \end_inset
22230
22231  service routine (ISR) is declared using the 
22232 \emph on
22233 interrupt
22234 \emph default
22235  keyword.
22236
22237 \layout LyX-Code
22238 void isr(void) interrupt 
22239 \emph on
22240 n
22241
22242 \layout LyX-Code
22243 {
22244
22245 \layout LyX-Code
22246 ...
22247
22248 \layout LyX-Code
22249 }
22250
22251 \layout Standard
22252
22253 \emph on
22254 n
22255 \emph default
22256  is the interrupt number, which for PIC18F devices can be:
22257
22258 \layout Standard
22259 \align center
22260 \begin_inset Tabular
22261 <lyxtabular version="3" rows="4" columns="3">
22262 <features>
22263 <column alignment="center" valignment="top" leftline="true" width="0">
22264 <column alignment="center" valignment="top" leftline="true" width="0">
22265 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22266 <row topline="true" bottomline="true">
22267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22268 \begin_inset Text
22269
22270 \layout Standard
22271
22272 \emph on
22273 n
22274
22275 \end_inset
22276 </cell>
22277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22278 \begin_inset Text
22279
22280 \layout Standard
22281 Interrupt Vector
22282
22283 \end_inset
22284 </cell>
22285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22286 \begin_inset Text
22287
22288 \layout Standard
22289 Interrupt Vector Address
22290
22291 \end_inset
22292 </cell>
22293 </row>
22294 <row topline="true">
22295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22296 \begin_inset Text
22297
22298 \layout Standard
22299 0
22300
22301 \end_inset
22302 </cell>
22303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22304 \begin_inset Text
22305
22306 \layout Standard
22307 RESET vector
22308
22309 \end_inset
22310 </cell>
22311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22312 \begin_inset Text
22313
22314 \layout Standard
22315 0x000000
22316
22317 \end_inset
22318 </cell>
22319 </row>
22320 <row topline="true">
22321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22322 \begin_inset Text
22323
22324 \layout Standard
22325
22326 \family roman
22327 \series medium
22328 \shape up
22329 \size normal
22330 \emph off
22331 \bar no
22332 \noun off
22333 \color none
22334 1
22335
22336 \end_inset
22337 </cell>
22338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22339 \begin_inset Text
22340
22341 \layout Standard
22342
22343 \family roman
22344 \series medium
22345 \shape up
22346 \size normal
22347 \emph off
22348 \bar no
22349 \noun off
22350 \color none
22351 HIGH priority interrupts
22352
22353 \end_inset
22354 </cell>
22355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22356 \begin_inset Text
22357
22358 \layout Standard
22359 0x000008
22360
22361 \end_inset
22362 </cell>
22363 </row>
22364 <row topline="true" bottomline="true">
22365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22366 \begin_inset Text
22367
22368 \layout Standard
22369 2
22370
22371 \end_inset
22372 </cell>
22373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22374 \begin_inset Text
22375
22376 \layout Standard
22377 LOW priority interrupts
22378
22379 \end_inset
22380 </cell>
22381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22382 \begin_inset Text
22383
22384 \layout Standard
22385 0x000018
22386
22387 \end_inset
22388 </cell>
22389 </row>
22390 </lyxtabular>
22391
22392 \end_inset
22393
22394
22395
22396 \layout Standard
22397 When generating assembly code for ISR the code generator places a 
22398 \noun on
22399 goto 
22400 \noun default
22401 instruction at the 
22402 \emph on
22403 Interrupt Vector Address
22404 \emph default
22405  which points at the genetated ISR.
22406  This single GOTO instruction is part of an automatically generated 
22407 \emph on
22408 interrupt entry point
22409 \emph default
22410  function.
22411  The actuall ISR code is placed as normally would in the code space.
22412  Upon interrupt request, the GOTO instruction is executed which jumps to
22413  the ISR code.
22414  When declaring interrupt functions as _naked this GOTO instruction is 
22415 \series bold
22416 not
22417 \series default
22418  generated.
22419  The whole interrupt functions is therefore placed at the Interrupt Vector
22420  Address of the specific interrupt.
22421  This is not a problem for the LOW priority interrupts, but it is a problem
22422  for the RESET and the HIGH priority interrupts because code may be written
22423  at the next interrupt´s vector address and cause undeterminate program
22424  behaviour if that interrupt is raised.
22425 \begin_inset Foot
22426 collapsed false
22427
22428 \layout Standard
22429 This is not a problem when
22430
22431 \layout Enumerate
22432 this is a HIGH interrupt ISR and LOW interrupts are 
22433 \emph on
22434 disabled
22435 \emph default
22436  or not used.
22437
22438 \layout Enumerate
22439 when the ISR is small enough not to reach the next interrupt´s vector address.
22440
22441 \end_inset
22442
22443
22444
22445 \layout Standard
22446
22447 \emph on
22448 n
22449 \emph default
22450  is possible to be omitted.
22451  This way a function is generated similar to an ISR, but it is not assigned
22452  to any interrupt.
22453
22454 \layout Standard
22455 When entering an interrupt, currently the PIC16
22456 \begin_inset LatexCommand \index{PIC16}
22457
22458 \end_inset
22459
22460  port automatically saves the following registers:
22461
22462 \layout Itemize
22463 WREG
22464
22465 \layout Itemize
22466 STATUS
22467
22468 \layout Itemize
22469 BSR
22470
22471 \layout Itemize
22472 PROD (PRODL and PRODH)
22473
22474 \layout Itemize
22475 FSR0 (FSR0L and FSR0H)
22476
22477 \layout Standard
22478 These registers are restored upon return from the interrupt routine.
22479 \begin_inset Foot
22480 collapsed false
22481
22482 \layout Standard
22483 NOTE that when the _naked attribute is specified for an interrupt routine,
22484  then NO registers are stored or restored.
22485
22486 \end_inset
22487
22488
22489
22490 \layout Subsection
22491 Generic Pointers
22492
22493 \layout Standard
22494 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
22495  There are 3 types of generic pointers currently implemented data, code
22496  and eeprom pointers.
22497  They are differentiated by the value of the 7th and 6th bits of the upper
22498  byte:
22499
22500 \layout Standard
22501 \align center
22502 \begin_inset Tabular
22503 <lyxtabular version="3" rows="5" columns="5">
22504 <features>
22505 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22506 <column alignment="center" valignment="top" width="0">
22507 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22508 <column alignment="center" valignment="top" width="0">
22509 <column alignment="left" valignment="top" rightline="true" width="0">
22510 <row topline="true" bottomline="true">
22511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22512 \begin_inset Text
22513
22514 \layout Standard
22515 pointer type
22516
22517 \end_inset
22518 </cell>
22519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22520 \begin_inset Text
22521
22522 \layout Standard
22523 7th bit
22524
22525 \end_inset
22526 </cell>
22527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22528 \begin_inset Text
22529
22530 \layout Standard
22531 6th bit
22532
22533 \end_inset
22534 </cell>
22535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22536 \begin_inset Text
22537
22538 \layout Standard
22539 rest of the pointer
22540
22541 \end_inset
22542 </cell>
22543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22544 \begin_inset Text
22545
22546 \layout Standard
22547 description
22548
22549 \end_inset
22550 </cell>
22551 </row>
22552 <row topline="true" bottomline="true">
22553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22554 \begin_inset Text
22555
22556 \layout Standard
22557 data 
22558
22559 \end_inset
22560 </cell>
22561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22562 \begin_inset Text
22563
22564 \layout Standard
22565 1
22566
22567 \end_inset
22568 </cell>
22569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22570 \begin_inset Text
22571
22572 \layout Standard
22573 0
22574
22575 \end_inset
22576 </cell>
22577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22578 \begin_inset Text
22579
22580 \layout Standard
22581
22582 \family typewriter
22583 \shape slanted
22584 \emph on
22585 uuuuuu uuuuxxxx xxxxxxxx
22586
22587 \end_inset
22588 </cell>
22589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22590 \begin_inset Text
22591
22592 \layout Standard
22593 a 12-bit data pointer in data RAM memory
22594
22595 \end_inset
22596 </cell>
22597 </row>
22598 <row bottomline="true">
22599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22600 \begin_inset Text
22601
22602 \layout Standard
22603 code
22604
22605 \end_inset
22606 </cell>
22607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22608 \begin_inset Text
22609
22610 \layout Standard
22611 0
22612
22613 \end_inset
22614 </cell>
22615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22616 \begin_inset Text
22617
22618 \layout Standard
22619 0
22620
22621 \end_inset
22622 </cell>
22623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22624 \begin_inset Text
22625
22626 \layout Standard
22627
22628 \family typewriter
22629 \shape slanted
22630 \emph on
22631 uxxxxx xxxxxxxx xxxxxxxx
22632
22633 \end_inset
22634 </cell>
22635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22636 \begin_inset Text
22637
22638 \layout Standard
22639 a 21-bit code pointer in FLASH memory
22640
22641 \end_inset
22642 </cell>
22643 </row>
22644 <row bottomline="true">
22645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22646 \begin_inset Text
22647
22648 \layout Standard
22649 eeprom
22650
22651 \end_inset
22652 </cell>
22653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22654 \begin_inset Text
22655
22656 \layout Standard
22657 0
22658
22659 \end_inset
22660 </cell>
22661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22662 \begin_inset Text
22663
22664 \layout Standard
22665 1
22666
22667 \end_inset
22668 </cell>
22669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22670 \begin_inset Text
22671
22672 \layout Standard
22673
22674 \family typewriter
22675 \shape slanted
22676 \emph on
22677 uuuuuu uuuuuuxx xxxxxxxx
22678
22679 \end_inset
22680 </cell>
22681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22682 \begin_inset Text
22683
22684 \layout Standard
22685 a 10-bit eeprom pointer in EEPROM memory
22686
22687 \end_inset
22688 </cell>
22689 </row>
22690 <row bottomline="true">
22691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22692 \begin_inset Text
22693
22694 \layout Standard
22695 (unimplemented)
22696
22697 \end_inset
22698 </cell>
22699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22700 \begin_inset Text
22701
22702 \layout Standard
22703 1
22704
22705 \end_inset
22706 </cell>
22707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22708 \begin_inset Text
22709
22710 \layout Standard
22711 1
22712
22713 \end_inset
22714 </cell>
22715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22716 \begin_inset Text
22717
22718 \layout Standard
22719
22720 \family typewriter
22721 \shape slanted
22722 \emph on
22723 xxxxxx xxxxxxxx xxxxxxxx
22724
22725 \end_inset
22726 </cell>
22727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22728 \begin_inset Text
22729
22730 \layout Standard
22731 unimplemented pointer type
22732
22733 \end_inset
22734 </cell>
22735 </row>
22736 </lyxtabular>
22737
22738 \end_inset
22739
22740
22741
22742 \layout Standard
22743 Generic pointer are read and written with a set of library functions which
22744  read/write 1, 2, 3, 4 bytes.
22745
22746 \layout Subsection
22747 PIC16 C Libraries
22748
22749 \layout Subsubsection
22750 Standard I/O Streams
22751
22752 \layout Standard
22753 In the 
22754 \emph on
22755 stdio.h
22756 \emph default
22757  the type FILE is defined as:
22758
22759 \layout LyX-Code
22760 typedef char * FILE;
22761
22762 \layout Standard
22763 This type is the stream type implemented I/O in the PIC18F devices.
22764  Also the standard input and output streams are declared in stdio.h:
22765
22766 \layout LyX-Code
22767 extern FILE * stdin;
22768
22769 \layout LyX-Code
22770 extern FILE * stdout;
22771
22772 \layout Standard
22773 The FILE type is actually a generic pointer which defines one more type
22774  of generic pointers, the 
22775 \emph on
22776 stream 
22777 \emph default
22778 pointer.
22779  This new type has the format:
22780
22781 \layout Standard
22782 \align center
22783 \begin_inset Tabular
22784 <lyxtabular version="3" rows="2" columns="7">
22785 <features>
22786 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22787 <column alignment="center" valignment="top" width="0">
22788 <column alignment="center" valignment="top" leftline="true" width="0">
22789 <column alignment="center" valignment="top" leftline="true" width="0">
22790 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22791 <column alignment="center" valignment="top" width="0">
22792 <column alignment="left" valignment="top" rightline="true" width="0">
22793 <row topline="true" bottomline="true">
22794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22795 \begin_inset Text
22796
22797 \layout Standard
22798 pointer type
22799
22800 \end_inset
22801 </cell>
22802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22803 \begin_inset Text
22804
22805 \layout Standard
22806 <7:6>
22807
22808 \end_inset
22809 </cell>
22810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22811 \begin_inset Text
22812
22813 \layout Standard
22814 <5>
22815
22816 \end_inset
22817 </cell>
22818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22819 \begin_inset Text
22820
22821 \layout Standard
22822 <4>
22823
22824 \end_inset
22825 </cell>
22826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22827 \begin_inset Text
22828
22829 \layout Standard
22830 <3:0>
22831
22832 \end_inset
22833 </cell>
22834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22835 \begin_inset Text
22836
22837 \layout Standard
22838 rest of the pointer
22839
22840 \end_inset
22841 </cell>
22842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22843 \begin_inset Text
22844
22845 \layout Standard
22846 descrption
22847
22848 \end_inset
22849 </cell>
22850 </row>
22851 <row topline="true" bottomline="true">
22852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22853 \begin_inset Text
22854
22855 \layout Standard
22856 stream
22857
22858 \end_inset
22859 </cell>
22860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22861 \begin_inset Text
22862
22863 \layout Standard
22864 00
22865
22866 \end_inset
22867 </cell>
22868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22869 \begin_inset Text
22870
22871 \layout Standard
22872 1
22873
22874 \end_inset
22875 </cell>
22876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22877 \begin_inset Text
22878
22879 \layout Standard
22880 0
22881
22882 \end_inset
22883 </cell>
22884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22885 \begin_inset Text
22886
22887 \layout Standard
22888 nnnn
22889
22890 \end_inset
22891 </cell>
22892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22893 \begin_inset Text
22894
22895 \layout Standard
22896
22897 \family typewriter
22898 \shape slanted
22899 \emph on
22900 uuuuuuuu uuuuuuuu
22901
22902 \end_inset
22903 </cell>
22904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22905 \begin_inset Text
22906
22907 \layout Standard
22908 upper byte high nubble is 0x2n, the rest are zeroes
22909
22910 \end_inset
22911 </cell>
22912 </row>
22913 </lyxtabular>
22914
22915 \end_inset
22916
22917
22918
22919 \layout Standard
22920 Currently implemented there are 3 types of streams defined:
22921
22922 \layout Standard
22923 \align center
22924 \begin_inset Tabular
22925 <lyxtabular version="3" rows="4" columns="4">
22926 <features>
22927 <column alignment="center" valignment="top" leftline="true" width="0">
22928 <column alignment="center" valignment="top" leftline="true" width="0">
22929 <column alignment="center" valignment="top" leftline="true" width="0">
22930 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22931 <row topline="true" bottomline="true">
22932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22933 \begin_inset Text
22934
22935 \layout Standard
22936 stream type
22937
22938 \end_inset
22939 </cell>
22940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22941 \begin_inset Text
22942
22943 \layout Standard
22944 value
22945
22946 \end_inset
22947 </cell>
22948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22949 \begin_inset Text
22950
22951 \layout Standard
22952 module
22953
22954 \end_inset
22955 </cell>
22956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22957 \begin_inset Text
22958
22959 \layout Standard
22960 description
22961
22962 \end_inset
22963 </cell>
22964 </row>
22965 <row topline="true">
22966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22967 \begin_inset Text
22968
22969 \layout Standard
22970 STREAM_USART
22971
22972 \end_inset
22973 </cell>
22974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22975 \begin_inset Text
22976
22977 \layout Standard
22978
22979 \family typewriter
22980 0x200000UL
22981
22982 \end_inset
22983 </cell>
22984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22985 \begin_inset Text
22986
22987 \layout Standard
22988 USART
22989
22990 \end_inset
22991 </cell>
22992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22993 \begin_inset Text
22994
22995 \layout Standard
22996 Writes/Reads characters via the USART peripheral
22997
22998 \end_inset
22999 </cell>
23000 </row>
23001 <row topline="true">
23002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23003 \begin_inset Text
23004
23005 \layout Standard
23006 STREAM_MSSP
23007
23008 \end_inset
23009 </cell>
23010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23011 \begin_inset Text
23012
23013 \layout Standard
23014
23015 \family typewriter
23016 0x210000UL
23017
23018 \end_inset
23019 </cell>
23020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23021 \begin_inset Text
23022
23023 \layout Standard
23024 MSSP
23025
23026 \end_inset
23027 </cell>
23028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23029 \begin_inset Text
23030
23031 \layout Standard
23032 Writes/Reads characters via the MSSP peripheral
23033
23034 \end_inset
23035 </cell>
23036 </row>
23037 <row topline="true" bottomline="true">
23038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23039 \begin_inset Text
23040
23041 \layout Standard
23042 STREAM_USER
23043
23044 \end_inset
23045 </cell>
23046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23047 \begin_inset Text
23048
23049 \layout Standard
23050
23051 \family typewriter
23052 0x2f0000UL
23053
23054 \end_inset
23055 </cell>
23056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23057 \begin_inset Text
23058
23059 \layout Standard
23060 (none)
23061
23062 \end_inset
23063 </cell>
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23065 \begin_inset Text
23066
23067 \layout Standard
23068 Writes/Reads characters via used defined functions
23069
23070 \end_inset
23071 </cell>
23072 </row>
23073 </lyxtabular>
23074
23075 \end_inset
23076
23077
23078
23079 \layout Standard
23080 The stream identifiers are declared as macros in the stdio.h header.
23081
23082 \layout Standard
23083 In the libc library there exist the functions that are used to write to
23084  each of the above streams.
23085  These are
23086
23087 \layout List
23088 \labelwidthstring 00.00.0000
23089 _
23090 \begin_inset ERT
23091 status Collapsed
23092
23093 \layout Standard
23094
23095
23096 \backslash
23097 /
23098
23099 \end_inset
23100
23101 _stream_usart_putchar writes a character at the USART stream
23102
23103 \layout List
23104 \labelwidthstring 00.00.0000
23105 _
23106 \begin_inset ERT
23107 status Collapsed
23108
23109 \layout Standard
23110
23111
23112 \backslash
23113 /
23114
23115 \end_inset
23116
23117 _stream_mssp_putchar writes a character at the MSSP stream
23118
23119 \layout List
23120 \labelwidthstring 00.00.0000
23121 putchar dummy function.
23122  This writes a character to a user specified manner.
23123
23124 \layout Standard
23125 In order to increase performance 
23126 \emph on
23127 putchar 
23128 \emph default
23129 is declared in stdio.h as having its parameter in WREG (it has the wparam
23130  keyword).
23131  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
23132  in a user-friendly way.
23133  
23134 \emph on
23135 arg
23136 \emph default
23137  is the name of the variable that holds the character to print.
23138  An example follows:
23139
23140 \layout LyX-Code
23141 #include <pic18fregs.h>
23142 \newline
23143 #include <stdio.h>
23144 \newline
23145
23146 \newline
23147 PUTCHAR( c )
23148
23149 \layout LyX-Code
23150 {
23151
23152 \layout LyX-Code
23153     PORTA = c;    /* dump character c to PORTA */
23154
23155 \layout LyX-Code
23156
23157 \newline
23158
23159 \newline
23160 void main(void)
23161
23162 \layout LyX-Code
23163 {
23164
23165 \layout LyX-Code
23166     stdout = STREAM_USER;    /* this is not necessary, since stdout points
23167
23168 \layout LyX-Code
23169                               * by default to STREAM_USER */
23170
23171 \layout LyX-Code
23172     printf (¨This is a printf test
23173 \backslash
23174 n¨);
23175
23176 \layout LyX-Code
23177 }
23178
23179 \layout LyX-Code
23180
23181
23182 \layout Subsubsection
23183 Printing functions
23184
23185 \layout Standard
23186 PIC16 contains an implementation of the printf-family of functions.
23187  There exist the following functions:
23188
23189 \layout LyX-Code
23190 extern unsigned int sprintf(char *buf, char *fmt, ...);
23191
23192 \layout LyX-Code
23193 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
23194
23195 \layout LyX-Code
23196
23197
23198 \layout LyX-Code
23199 extern unsigned int printf(char *fmt, ...);
23200
23201 \layout LyX-Code
23202 extern unsigned int vprintf(char *fmt, va_lista ap);
23203
23204 \layout LyX-Code
23205
23206
23207 \layout LyX-Code
23208 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
23209
23210 \layout LyX-Code
23211 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
23212
23213 \layout Standard
23214 For sprintf and vsprintf 
23215 \emph on
23216 buf 
23217 \emph default
23218 should normally be a data pointer where the resulting string will be placed.
23219  No range checking is done so the user should allocate the necessery buffer.
23220  For fprintf and vfprintf 
23221 \emph on
23222 fp
23223 \emph default
23224  should be a stream pointer (i.e.
23225  stdout, STREAM_MSSP, etc...).
23226
23227 \layout Subsubsection
23228 Signals
23229
23230 \layout Standard
23231 The PIC18F family of microcontrollers supports a number of interrupt sources.
23232  A list of these interrupts is shown in the following table:
23233
23234 \layout Standard
23235 \align center
23236 \begin_inset Tabular
23237 <lyxtabular version="3" rows="11" columns="4">
23238 <features>
23239 <column alignment="left" valignment="top" leftline="true" width="0">
23240 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23241 <column alignment="left" valignment="top" leftline="true" width="0">
23242 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23243 <row topline="true" bottomline="true">
23244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23245 \begin_inset Text
23246
23247 \layout Standard
23248 signal name
23249
23250 \end_inset
23251 </cell>
23252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23253 \begin_inset Text
23254
23255 \layout Standard
23256 description
23257
23258 \end_inset
23259 </cell>
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23261 \begin_inset Text
23262
23263 \layout Standard
23264 signal name
23265
23266 \end_inset
23267 </cell>
23268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23269 \begin_inset Text
23270
23271 \layout Standard
23272 descritpion
23273
23274 \end_inset
23275 </cell>
23276 </row>
23277 <row topline="true">
23278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23279 \begin_inset Text
23280
23281 \layout Standard
23282 SIG_RB
23283
23284 \end_inset
23285 </cell>
23286 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23287 \begin_inset Text
23288
23289 \layout Standard
23290 PORTB change interrupt
23291
23292 \end_inset
23293 </cell>
23294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23295 \begin_inset Text
23296
23297 \layout Standard
23298 SIG_EE
23299
23300 \end_inset
23301 </cell>
23302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23303 \begin_inset Text
23304
23305 \layout Standard
23306 EEPROM/FLASH write complete interrupt
23307
23308 \end_inset
23309 </cell>
23310 </row>
23311 <row topline="true">
23312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23313 \begin_inset Text
23314
23315 \layout Standard
23316 SIG_INT0
23317
23318 \end_inset
23319 </cell>
23320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23321 \begin_inset Text
23322
23323 \layout Standard
23324 INT0 external interrupt
23325
23326 \end_inset
23327 </cell>
23328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23329 \begin_inset Text
23330
23331 \layout Standard
23332 SIG_BCOL
23333
23334 \end_inset
23335 </cell>
23336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23337 \begin_inset Text
23338
23339 \layout Standard
23340 Bus collision interrupt
23341
23342 \end_inset
23343 </cell>
23344 </row>
23345 <row topline="true">
23346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23347 \begin_inset Text
23348
23349 \layout Standard
23350 SIG_INT1
23351
23352 \end_inset
23353 </cell>
23354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23355 \begin_inset Text
23356
23357 \layout Standard
23358 INT1 external interrupt
23359
23360 \end_inset
23361 </cell>
23362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23363 \begin_inset Text
23364
23365 \layout Standard
23366 SIG_LVD
23367
23368 \end_inset
23369 </cell>
23370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23371 \begin_inset Text
23372
23373 \layout Standard
23374 Low voltage detect interrupt
23375
23376 \end_inset
23377 </cell>
23378 </row>
23379 <row topline="true">
23380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23381 \begin_inset Text
23382
23383 \layout Standard
23384 SIG_INT2
23385
23386 \end_inset
23387 </cell>
23388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23389 \begin_inset Text
23390
23391 \layout Standard
23392 INT2 external interrupt
23393
23394 \end_inset
23395 </cell>
23396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23397 \begin_inset Text
23398
23399 \layout Standard
23400 SIG_PSP
23401
23402 \end_inset
23403 </cell>
23404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23405 \begin_inset Text
23406
23407 \layout Standard
23408 Parallel slave port interrupt
23409
23410 \end_inset
23411 </cell>
23412 </row>
23413 <row topline="true">
23414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23415 \begin_inset Text
23416
23417 \layout Standard
23418 SIG_CCP1
23419
23420 \end_inset
23421 </cell>
23422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23423 \begin_inset Text
23424
23425 \layout Standard
23426 CCP1 module interrupt
23427
23428 \end_inset
23429 </cell>
23430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23431 \begin_inset Text
23432
23433 \layout Standard
23434 SIG_AD
23435
23436 \end_inset
23437 </cell>
23438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23439 \begin_inset Text
23440
23441 \layout Standard
23442 AD convertion complete interrupt
23443
23444 \end_inset
23445 </cell>
23446 </row>
23447 <row topline="true">
23448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23449 \begin_inset Text
23450
23451 \layout Standard
23452 SIG_CCP2
23453
23454 \end_inset
23455 </cell>
23456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23457 \begin_inset Text
23458
23459 \layout Standard
23460 CCP2 module interrupt
23461
23462 \end_inset
23463 </cell>
23464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23465 \begin_inset Text
23466
23467 \layout Standard
23468 SIG_RC
23469
23470 \end_inset
23471 </cell>
23472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23473 \begin_inset Text
23474
23475 \layout Standard
23476 USART receive interrupt
23477
23478 \end_inset
23479 </cell>
23480 </row>
23481 <row topline="true">
23482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23483 \begin_inset Text
23484
23485 \layout Standard
23486 SIG_TMR0
23487
23488 \end_inset
23489 </cell>
23490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23491 \begin_inset Text
23492
23493 \layout Standard
23494 TMR0 overflow interrupt
23495
23496 \end_inset
23497 </cell>
23498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23499 \begin_inset Text
23500
23501 \layout Standard
23502 SIG_TX
23503
23504 \end_inset
23505 </cell>
23506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23507 \begin_inset Text
23508
23509 \layout Standard
23510 USART transmit interrupt
23511
23512 \end_inset
23513 </cell>
23514 </row>
23515 <row topline="true">
23516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23517 \begin_inset Text
23518
23519 \layout Standard
23520 SIG_TMR1
23521
23522 \end_inset
23523 </cell>
23524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23525 \begin_inset Text
23526
23527 \layout Standard
23528 TMR1 overflow interrupt
23529
23530 \end_inset
23531 </cell>
23532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23533 \begin_inset Text
23534
23535 \layout Standard
23536 SIG_MSSP
23537
23538 \end_inset
23539 </cell>
23540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23541 \begin_inset Text
23542
23543 \layout Standard
23544 SSP receive/transmit interrupt
23545
23546 \end_inset
23547 </cell>
23548 </row>
23549 <row topline="true">
23550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23551 \begin_inset Text
23552
23553 \layout Standard
23554 SIG_TMR2
23555
23556 \end_inset
23557 </cell>
23558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23559 \begin_inset Text
23560
23561 \layout Standard
23562 TMR2 matches PR2 interrupt
23563
23564 \end_inset
23565 </cell>
23566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23567 \begin_inset Text
23568
23569 \layout Standard
23570
23571
23572 \end_inset
23573 </cell>
23574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23575 \begin_inset Text
23576
23577 \layout Standard
23578
23579
23580 \end_inset
23581 </cell>
23582 </row>
23583 <row topline="true" bottomline="true">
23584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23585 \begin_inset Text
23586
23587 \layout Standard
23588 SIG_TMR3
23589
23590 \end_inset
23591 </cell>
23592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23593 \begin_inset Text
23594
23595 \layout Standard
23596 TMR3 overflow interrupt
23597
23598 \end_inset
23599 </cell>
23600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23601 \begin_inset Text
23602
23603 \layout Standard
23604
23605
23606 \end_inset
23607 </cell>
23608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23609 \begin_inset Text
23610
23611 \layout Standard
23612
23613
23614 \end_inset
23615 </cell>
23616 </row>
23617 </lyxtabular>
23618
23619 \end_inset
23620
23621
23622
23623 \layout Standard
23624 The prototypes for these names are defined in the header file 
23625 \emph on
23626 signal.h
23627 \emph default
23628  .
23629
23630 \layout Standard
23631 In order to simplify signal handling, a number of macros is provided:
23632
23633 \layout List
23634 \labelwidthstring 00.00.0000
23635 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
23636  high priority interrupts.
23637  
23638 \emph on
23639 name
23640 \emph default
23641  is the function name to use.
23642
23643 \layout List
23644 \labelwidthstring 00.00.0000
23645 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
23646  low priority interrupt.
23647  
23648 \emph on
23649 name
23650 \emph default
23651  is the function name to use.
23652
23653 \layout List
23654 \labelwidthstring 00.00.0000
23655 DEF_HANDLER(sig,handler) define a handler for signal 
23656 \emph on
23657 sig.
23658
23659 \layout List
23660 \labelwidthstring 00.00.0000
23661 END_DEF end the declaration of the dispatch table.
23662
23663 \layout Standard
23664 Additionally there are two more macros to simplify the declaration of the
23665  signal handler:
23666
23667 \layout List
23668 \labelwidthstring 00.00.0000
23669
23670 \series medium
23671 SIGHANDLER(handler) 
23672 \series default
23673 this declares the function prototype for the 
23674 \emph on
23675 handler
23676 \emph default
23677  function.
23678
23679 \layout List
23680 \labelwidthstring 00.00.0000
23681 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
23682
23683 \layout Standard
23684 An example of using the macros above is shown below:
23685
23686 \layout LyX-Code
23687 #include <pic18fregs.h>
23688
23689 \layout LyX-Code
23690 #include <signal.h>
23691 \newline
23692
23693 \newline
23694 DEF_INTHIGH(high_int)
23695
23696 \layout LyX-Code
23697 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
23698
23699 \layout LyX-Code
23700 DEF_HANDLER(SIG_BCOL, _bcol_handler)
23701
23702 \layout LyX-Code
23703 END_DEF
23704 \newline
23705
23706 \newline
23707 SIGHANDLER(_tmr0_handler)
23708
23709 \layout LyX-Code
23710 {
23711
23712 \layout LyX-Code
23713   /* action to be taken when timer 0 overflows */
23714
23715 \layout LyX-Code
23716 }
23717 \newline
23718
23719 \newline
23720 SIGHANDLERNAKED(_bcol_handler)
23721
23722 \layout LyX-Code
23723 {
23724
23725 \layout LyX-Code
23726   _asm
23727
23728 \layout LyX-Code
23729     /* action to be taken when bus collision occurs */
23730
23731 \layout LyX-Code
23732     retfie
23733
23734 \layout LyX-Code
23735  _endasm;
23736
23737 \layout LyX-Code
23738 }
23739
23740 \layout Standard
23741
23742 \series bold
23743 NOTES:
23744 \series default
23745  Special care should be taken when using the above scheme:
23746
23747 \layout Itemize
23748 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
23749
23750 \layout Itemize
23751 when declaring SIGHANDLERNAKED handler never forget to use 
23752 \emph on
23753 retfie
23754 \emph default
23755  for proper returning.
23756
23757 \layout Subsection
23758 PIC16 Port -- Tips
23759
23760 \layout Standard
23761 Here you can find some general tips for compiling programs with SDCC/pic16.
23762
23763 \layout Subsubsection
23764 Stack size
23765
23766 \layout Standard
23767 The default stack
23768 \begin_inset LatexCommand \index{PIC16!stack}
23769
23770 \end_inset
23771
23772  size (that is 64 bytes) probably is enough for many programs.
23773  One must take care that when there are many levels of function nesting,
23774  or there is excessive usage of stack, its size should be extended.
23775  An example of such a case is the printf/sprintf family of functions.
23776  If you encounter problems like not being able to print integers, then you
23777  need to set the stack size around the maximum (256 for small stack model).
23778  The following diagram shows what happens when calling printf to print an
23779  integer:
23780
23781 \layout LyX-Code
23782 printf () --> ltoa () --> ultoa () --> divschar ()
23783
23784 \layout Standard
23785 It is should be understood that stack is easily consumed when calling complicate
23786 d functions.
23787  Using command line arguments like -
23788 \begin_inset ERT
23789 status Collapsed
23790
23791 \layout Standard
23792
23793
23794 \backslash
23795 /
23796
23797 \end_inset
23798
23799 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
23800  stack frames.
23801  Other ways to reduce stack usage may exist.
23802
23803 \layout Subsection
23804 Known bugs
23805
23806 \layout Standard
23807 The PIC16 Port currently does not pass SDCC's regression test
23808 \begin_inset LatexCommand \index{Regression test (PIC16)}
23809
23810 \end_inset
23811
23812  suite (see section 
23813 \begin_inset LatexCommand \ref{sec:Quality-control}
23814
23815 \end_inset
23816
23817 ) and thus the nightly regression tests for the PIC16 target are currently
23818  disabled for all hosts except for 
23819 \emph on
23820 Linux on Opteron.
23821
23822 \emph default
23823  This means you can see the result of the PIC16 regression tests f.e.
23824  by checking the log files in 
23825 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
23826
23827 \end_inset
23828
23829  (pick the most up to date file there, scroll down, lend a hand).
23830
23831 \layout Chapter
23832 Debugging
23833
23834 \layout Standard
23835 There are several approaches to debugging your code.
23836  This chapter is meant to show your options and to give detail on some of
23837  them:
23838 \newline
23839
23840 \newline
23841 When writing your code:
23842
23843 \layout Itemize
23844 write your code with debugging in mind (avoid duplicating code, put conceptually
23845  similar variables into structs, use structured code, have strategic points
23846  within your code where all variables are consistent, ...)
23847
23848 \layout Itemize
23849 run a syntax-checking tool like splint
23850 \begin_inset LatexCommand \index{splint (syntax checking tool)}
23851
23852 \end_inset
23853
23854
23855 \begin_inset LatexCommand \index{lint (syntax checking tool)}
23856
23857 \end_inset
23858
23859  (see -
23860 \begin_inset ERT
23861 status Collapsed
23862
23863 \layout Standard
23864
23865
23866 \backslash
23867 /
23868
23869 \end_inset
23870
23871 -more-pedantic 
23872 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23873
23874 \end_inset
23875
23876 ) over the code.
23877
23878 \layout Itemize
23879 for the high level code use a C-compiler (like f.e.
23880  GCC) to compile run and debug the code on your host.
23881  See (see -
23882 \begin_inset ERT
23883 status Collapsed
23884
23885 \layout Standard
23886
23887
23888 \backslash
23889 /
23890
23891 \end_inset
23892
23893 -more-pedantic 
23894 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23895
23896 \end_inset
23897
23898  ) on howto handle syntax extensions like __xdata, __at(), ...
23899  
23900
23901 \layout Itemize
23902 use another C-compiler to compile code for your target.
23903  Always an option but not recommended:) And not very likely to help you.
23904  If you seriously consider walking this path you should at least occasionally
23905  check portability of your code.
23906  Most commercial compiler vendors will offer an evaluation version so you
23907  can test compile your code or snippets of your code.
23908
23909 \layout Standard
23910 Debugging on a simulator:
23911
23912 \layout Itemize
23913 there is a separate section about SDCDB (section 
23914 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
23915
23916 \end_inset
23917
23918 ) below.
23919
23920 \layout Itemize
23921 or (8051 specific) use a freeware/commercial simulator which interfaces
23922  to the AOMF
23923 \begin_inset LatexCommand \index{AOMF, AOMF51}
23924
23925 \end_inset
23926
23927  file (see 
23928 \begin_inset LatexCommand \ref{OMF file}
23929
23930 \end_inset
23931
23932 ) optionally generated by SDCC.
23933
23934 \layout Standard
23935 Debugging On-target: 
23936
23937 \layout Itemize
23938 use a MCU port pin to serially output debug data to the RS232 port of your
23939  host.
23940  You'll probably want some level shifting device typically involving a MAX232
23941  or similar IC.
23942  If the hardware serial port of the MCU is not available search for 'Software
23943  UART' in your favourite search machine.
23944
23945 \layout Itemize
23946 use an on-target monitor.
23947  In this context a monitor is a small program which usually accepts commands
23948  via a serial line and allows to set program counter, to single step through
23949  a program and read/write memory locations.
23950  For the 8051 good examples of monitors are paulmon and cmon51 (see section
23951  
23952 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
23953
23954 \end_inset
23955
23956 ).
23957
23958 \layout Itemize
23959 toggle MCU port pins at strategic points within your code and use an oscilloscop
23960 e.
23961  A 
23962 \emph on
23963 digital oscilloscope
23964 \emph default
23965
23966 \begin_inset LatexCommand \index{Oscilloscope}
23967
23968 \end_inset
23969
23970  with deep trace memory is really helpful especially if you have to debug
23971  a realtime application.
23972  If you need to monitor more pins than your oscilloscope provides you can
23973  sometimes get away with a small R-2R network.
23974  On a single channel oscilloscope you could f.e.
23975  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
23976 k
23977 \begin_inset Formula $\Omega$
23978 \end_inset
23979
23980  resistor and the other one by a 5\SpecialChar ~
23981 k
23982 \begin_inset Formula $\Omega$
23983 \end_inset
23984
23985  resistor to the oscilloscope probe (check output drive capability of the
23986  pins you want to monitor).
23987  If you need to monitor many more pins a 
23988 \emph on
23989 logic analyzer
23990 \emph default
23991  will be handy.
23992
23993 \layout Itemize
23994 use an ICE (
23995 \emph on
23996 i
23997 \emph default
23998
23999 \emph on
24000 c
24001 \emph default
24002 ircuit 
24003 \emph on
24004 e
24005 \emph default
24006 mulator
24007 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24008
24009 \end_inset
24010
24011 ).
24012  Usually very expensive.
24013  And very nice to have too.
24014  And usually locks you (for years...) to the devices the ICE can emulate.
24015  
24016
24017 \layout Itemize
24018 use a remote debugger.
24019  In most 8-bit systems the symbol information is not available on the target,
24020  and a complete debugger is too bulky for the target system.
24021  Therefore usually a debugger on the host system connects to an on-target
24022  debugging stub which accepts only primitive commands.
24023  
24024 \newline
24025 Terms to enter into your favourite search engine could be 'remote debugging',
24026  'gdb stub' or 'inferior debugger'.
24027  (is there one?)
24028
24029 \layout Itemize
24030 use an on target hardware debugger.
24031  Some of the more modern MCUs include hardware support for setting break
24032  points and monitoring/changing variables by using dedicated hardware pins.
24033  This facility doesn't require additional code to run on the target and
24034  
24035 \emph on
24036 usually
24037 \emph default
24038  doesn't affect runtime behaviour until a breakpoint is hit.
24039  For the mcs51 most hardware debuggers use the AOMF
24040 \begin_inset LatexCommand \index{AOMF, AOMF51}
24041
24042 \end_inset
24043
24044  file (see 
24045 \begin_inset LatexCommand \ref{OMF file}
24046
24047 \end_inset
24048
24049 ) as input file.
24050  
24051
24052 \layout Standard
24053 Last not least:
24054
24055 \layout Itemize
24056 if you are not familiar with any of the following terms you're likely to
24057  run into problems rather sooner than later: 
24058 \emph on
24059 volatile
24060 \emph default
24061
24062 \emph on
24063 atomic
24064 \emph default
24065
24066 \emph on
24067 memory map
24068 \emph default
24069
24070 \emph on
24071 overlay
24072 \emph default
24073 .
24074  As an embedded programmer you 
24075 \emph on
24076 have
24077 \emph default
24078  to know them so why not look them up 
24079 \emph on
24080 before
24081 \emph default
24082  you have problems?)
24083
24084 \layout Itemize
24085 tell someone else about your problem (actually this is a surprisingly effective
24086  means to hunt down the bug even if the listener is not familiar with your
24087  environment).
24088  As 'failure to communicate' is probably one of the job-induced deformations
24089  of an embedded programmer this is highly encouraged.
24090
24091 \layout Section
24092 Debugging with SDCDB
24093 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24094
24095 \end_inset
24096
24097
24098 \begin_inset LatexCommand \index{SDCDB (debugger)}
24099
24100 \end_inset
24101
24102  
24103
24104 \layout Standard
24105 SDCC is distributed with a source level debugger
24106 \begin_inset LatexCommand \index{Debugger}
24107
24108 \end_inset
24109
24110 .
24111  The debugger uses a command line interface, the command repertoire of the
24112  debugger has been kept as close to gdb
24113 \begin_inset LatexCommand \index{gdb}
24114
24115 \end_inset
24116
24117  (the GNU debugger) as possible.
24118  The configuration and build process is part of the standard compiler installati
24119 on, which also builds and installs the debugger in the target directory
24120  specified during configuration.
24121  The debugger allows you debug BOTH at the C source and at the ASM source
24122  level.
24123
24124 \layout Subsection
24125 Compiling for Debugging
24126
24127 \layout Standard
24128 The -
24129 \begin_inset ERT
24130 status Collapsed
24131
24132 \layout Standard
24133
24134
24135 \backslash
24136 /
24137
24138 \end_inset
24139
24140 -debug
24141 \begin_inset LatexCommand \index{-\/-debug}
24142
24143 \end_inset
24144
24145  option must be specified for all files for which debug information is to
24146  be generated.
24147  The compiler generates a .adb file for each of these files.
24148  The linker creates the .cdb
24149 \begin_inset LatexCommand \index{<file>.cdb}
24150
24151 \end_inset
24152
24153  file from the .adb
24154 \begin_inset LatexCommand \index{<file>.adb}
24155
24156 \end_inset
24157
24158  files and the address information.
24159  This .cdb is used by the debugger.
24160
24161 \layout Subsection
24162 How the Debugger Works
24163
24164 \layout Standard
24165 When the -
24166 \begin_inset ERT
24167 status Collapsed
24168
24169 \layout Standard
24170
24171
24172 \backslash
24173 /
24174
24175 \end_inset
24176
24177 -debug option is specified the compiler generates extra symbol information
24178  some of which are put into the assembler source and some are put into the
24179  .adb file.
24180  Then the linker creates the .cdb file from the individual .adb files with
24181  the address information for the symbols.
24182  The debugger reads the symbolic information generated by the compiler &
24183  the address information generated by the linker.
24184  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
24185  execution is controlled by the debugger.
24186  When a command is issued for the debugger, it translates it into appropriate
24187  commands for the simulator.
24188  (Currently SDCDM only connects to the simulator but 
24189 \emph on
24190 newcdb
24191 \emph default
24192  at 
24193 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
24194
24195 \end_inset
24196
24197  is an effort to connect directly to the hardware.) 
24198
24199 \layout Subsection
24200 Starting the Debugger SDCDB
24201
24202 \layout Standard
24203 The debugger can be started using the following command line.
24204  (Assume the file you are debugging has the file name foo).
24205 \newline
24206
24207 \newline
24208
24209 \family sans
24210 \series bold
24211 sdcdb foo
24212 \newline
24213
24214 \family default
24215 \series default
24216
24217 \newline
24218 The debugger will look for the following files.
24219
24220 \layout Itemize
24221 foo.c - the source file.
24222
24223 \layout Itemize
24224 foo.cdb - the debugger symbol information file.
24225
24226 \layout Itemize
24227 foo.ihx - the Intel hex format
24228 \begin_inset LatexCommand \index{Intel hex format}
24229
24230 \end_inset
24231
24232  object file.
24233
24234 \layout Subsection
24235 SDCDB Command Line Options
24236
24237 \layout Itemize
24238 -
24239 \begin_inset ERT
24240 status Collapsed
24241
24242 \layout Standard
24243
24244
24245 \backslash
24246 /
24247
24248 \end_inset
24249
24250 -directory=<source file directory> this option can used to specify the directory
24251  search list.
24252  The debugger will look into the directory list specified for source, cdb
24253  & ihx files.
24254  The items in the directory list must be separated by ':', e.g.
24255  if the source files can be in the directories /home/src1 and /home/src2,
24256  the -
24257 \begin_inset ERT
24258 status Collapsed
24259
24260 \layout Standard
24261
24262
24263 \backslash
24264 /
24265
24266 \end_inset
24267
24268 -directory option should be -
24269 \begin_inset ERT
24270 status Collapsed
24271
24272 \layout Standard
24273
24274
24275 \backslash
24276 /
24277
24278 \end_inset
24279
24280 -directory=/home/src1:/home/src2.
24281  Note there can be no spaces in the option.
24282  
24283
24284 \layout Itemize
24285 -cd <directory> - change to the <directory>.
24286
24287 \layout Itemize
24288 -fullname - used by GUI front ends.
24289
24290 \layout Itemize
24291 -cpu <cpu-type> - this argument is passed to the simulator please see the
24292  simulator docs for details.
24293
24294 \layout Itemize
24295 -X <Clock frequency > this options is passed to the simulator please see
24296  the simulator docs for details.
24297
24298 \layout Itemize
24299 -s <serial port file> passed to simulator see the simulator docs for details.
24300
24301 \layout Itemize
24302 -S <serial in,out> passed to simulator see the simulator docs for details.
24303
24304 \layout Itemize
24305 -k <port number> passed to simulator see the simulator docs for details.
24306
24307 \layout Subsection
24308 SDCDB Debugger Commands
24309
24310 \layout Standard
24311 As mentioned earlier the command interface for the debugger has been deliberatel
24312 y kept as close the GNU debugger gdb, as possible.
24313  This will help the integration with existing graphical user interfaces
24314  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
24315  If you use a graphical user interface for the debugger you can skip this
24316  section.
24317
24318 \layout Subsubsection*
24319 break [line | file:line | function | file:function]
24320
24321 \layout Standard
24322 Set breakpoint at specified line or function:
24323 \newline
24324
24325 \newline
24326
24327 \family sans
24328 \series bold
24329 sdcdb>break 100 
24330 \newline
24331 sdcdb>break foo.c:100
24332 \newline
24333 sdcdb>break funcfoo
24334 \newline
24335 sdcdb>break foo.c:funcfoo
24336
24337 \layout Subsubsection*
24338 clear [line | file:line | function | file:function ]
24339
24340 \layout Standard
24341 Clear breakpoint at specified line or function:
24342 \newline
24343
24344 \newline
24345
24346 \family sans
24347 \series bold
24348 sdcdb>clear 100
24349 \newline
24350 sdcdb>clear foo.c:100
24351 \newline
24352 sdcdb>clear funcfoo
24353 \newline
24354 sdcdb>clear foo.c:funcfoo
24355
24356 \layout Subsubsection*
24357 continue
24358
24359 \layout Standard
24360 Continue program being debugged, after breakpoint.
24361
24362 \layout Subsubsection*
24363 finish
24364
24365 \layout Standard
24366 Execute till the end of the current function.
24367
24368 \layout Subsubsection*
24369 delete [n]
24370
24371 \layout Standard
24372 Delete breakpoint number 'n'.
24373  If used without any option clear ALL user defined break points.
24374
24375 \layout Subsubsection*
24376 info [break | stack | frame | registers ]
24377
24378 \layout Itemize
24379 info break - list all breakpoints
24380
24381 \layout Itemize
24382 info stack - show the function call stack.
24383
24384 \layout Itemize
24385 info frame - show information about the current execution frame.
24386
24387 \layout Itemize
24388 info registers - show content of all registers.
24389
24390 \layout Subsubsection*
24391 step
24392
24393 \layout Standard
24394 Step program until it reaches a different source line.
24395  Note: pressing <return> repeats the last command.
24396
24397 \layout Subsubsection*
24398 next
24399
24400 \layout Standard
24401 Step program, proceeding through subroutine calls.
24402
24403 \layout Subsubsection*
24404 run
24405
24406 \layout Standard
24407 Start debugged program.
24408
24409 \layout Subsubsection*
24410 ptype variable 
24411
24412 \layout Standard
24413 Print type information of the variable.
24414
24415 \layout Subsubsection*
24416 print variable
24417
24418 \layout Standard
24419 print value of variable.
24420
24421 \layout Subsubsection*
24422 file filename
24423
24424 \layout Standard
24425 load the given file name.
24426  Note this is an alternate method of loading file for debugging.
24427
24428 \layout Subsubsection*
24429 frame
24430
24431 \layout Standard
24432 print information about current frame.
24433
24434 \layout Subsubsection*
24435 set srcmode
24436
24437 \layout Standard
24438 Toggle between C source & assembly source.
24439
24440 \layout Subsubsection*
24441 ! simulator command
24442
24443 \layout Standard
24444 Send the string following '!' to the simulator, the simulator response is
24445  displayed.
24446  Note the debugger does not interpret the command being sent to the simulator,
24447  so if a command like 'go' is sent the debugger can loose its execution
24448  context and may display incorrect values.
24449
24450 \layout Subsubsection*
24451 quit
24452
24453 \layout Standard
24454 "Watch me now.
24455  Iam going Down.
24456  My name is Bobby Brown"
24457
24458 \layout Subsection
24459 Interfacing SDCDB with DDD
24460
24461 \layout Standard
24462 \begin_inset Note
24463 collapsed true
24464
24465 \layout Standard
24466 The screenshot was converted from png to eps with: 
24467 \begin_inset Quotes sld
24468 \end_inset
24469
24470 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
24471 \begin_inset Quotes srd
24472 \end_inset
24473
24474  which produces a pretty compact eps file which is free from compression
24475  artifacts.
24476
24477 \layout Standard
24478 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
24479  as this broke the build system on Sourceforge (pdf-file was broken.
24480  pdflatex does not accept eps files).
24481
24482 \end_inset
24483
24484
24485
24486 \layout Standard
24487 The 
24488 \emph on
24489 p
24490 \emph default
24491 ortable 
24492 \emph on
24493 n
24494 \emph default
24495 etwork 
24496 \emph on
24497 g
24498 \emph default
24499 raphics File 
24500 \size footnotesize
24501
24502 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
24503
24504 \end_inset
24505
24506
24507 \size default
24508  shows a screenshot of a debugging session with DDD
24509 \begin_inset LatexCommand \index{DDD (debugger)}
24510
24511 \end_inset
24512
24513  (Unix only) on a simulated 8032.
24514  The debugging session might not run as smoothly as the screenshot suggests.
24515  The debugger allows setting of breakpoints, displaying and changing variables,
24516  single stepping through C and assembler code.
24517  
24518 \newline
24519 The source was compiled with 
24520 \family sans
24521 \series bold
24522
24523 \newline
24524
24525 \newline
24526 sdcc -
24527 \family default
24528 \series default
24529
24530 \begin_inset ERT
24531 status Collapsed
24532
24533 \layout Standard
24534
24535
24536 \backslash
24537 /
24538
24539 \end_inset
24540
24541
24542 \family sans
24543 \series bold
24544 -debug ddd_example.c
24545 \family default
24546 \series default
24547  
24548 \family sans
24549 \series bold
24550
24551 \newline
24552
24553 \family default
24554 \series default
24555
24556 \newline
24557 and DDD was invoked with 
24558 \family sans
24559 \series bold
24560
24561 \newline
24562
24563 \newline
24564 ddd -debugger "sdcdb -cpu 8032 ddd_example"
24565
24566 \layout Standard
24567 \begin_inset Note
24568 collapsed false
24569
24570 \layout Standard
24571 Check that the double quotes or an apostroph within the command line survive
24572  the LyX tool chain.
24573  Previously the apostrophs got slanted in the PDF output so a cut and paste
24574  did not work.
24575
24576 \end_inset
24577
24578
24579
24580 \layout Subsection
24581 Interfacing SDCDB with XEmacs
24582 \begin_inset LatexCommand \index{XEmacs}
24583
24584 \end_inset
24585
24586
24587 \begin_inset LatexCommand \index{Emacs}
24588
24589 \end_inset
24590
24591
24592
24593 \layout Standard
24594 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
24595  sdcdb.el and sdcdbsrc.el.
24596  These two files can be found in the $(prefix)/bin directory after the installat
24597 ion is complete.
24598  These files need to be loaded into XEmacs for the interface to work.
24599  This can be done at XEmacs startup time by inserting the following into
24600  your '.xemacs' file (which can be found in your HOME directory): 
24601 \newline
24602
24603 \newline
24604
24605 \family typewriter
24606 (load-file sdcdbsrc.el) 
24607 \family default
24608
24609 \newline
24610
24611 \newline
24612 .xemacs is a lisp file so the () around the command is REQUIRED.
24613  The files can also be loaded dynamically while XEmacs is running, set the
24614  environment variable 'EMACSLOADPATH' to the installation bin directory
24615  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
24616  To start the interface enter the following command: 
24617 \newline
24618
24619 \newline
24620
24621 \family sans
24622 \series bold
24623 ESC-x sdcdbsrc
24624 \family default
24625 \series default
24626
24627 \newline
24628
24629 \newline
24630 You will prompted to enter the file name to be debugged.
24631  
24632 \newline
24633
24634 \newline
24635 The command line options that are passed to the simulator directly are
24636  bound to default values in the file sdcdbsrc.el.
24637  The variables are listed below, these values maybe changed as required.
24638
24639 \layout Itemize
24640 sdcdbsrc-cpu-type '51
24641
24642 \layout Itemize
24643 sdcdbsrc-frequency '11059200
24644
24645 \layout Itemize
24646 sdcdbsrc-serial nil
24647
24648 \layout Standard
24649 The following is a list of key mapping for the debugger interface.
24650
24651 \layout Standard
24652 \SpecialChar ~
24653 \pagebreak_bottom 
24654
24655 \family typewriter
24656
24657 \newline
24658 ;;\SpecialChar ~
24659 Current Listing :: 
24660 \newline
24661 ;;key\SpecialChar ~
24662 \SpecialChar ~
24663 \SpecialChar ~
24664 \SpecialChar ~
24665 \SpecialChar ~
24666 \SpecialChar ~
24667 \SpecialChar ~
24668 \SpecialChar ~
24669 \SpecialChar ~
24670 \SpecialChar ~
24671 \SpecialChar ~
24672 \SpecialChar ~
24673 \SpecialChar ~
24674 \SpecialChar ~
24675 binding\SpecialChar ~
24676 \SpecialChar ~
24677 \SpecialChar ~
24678 \SpecialChar ~
24679 \SpecialChar ~
24680 \SpecialChar ~
24681 \SpecialChar ~
24682 \SpecialChar ~
24683 \SpecialChar ~
24684 \SpecialChar ~
24685 \SpecialChar ~
24686 \SpecialChar ~
24687 \SpecialChar ~
24688 \SpecialChar ~
24689 \SpecialChar ~
24690 \SpecialChar ~
24691 \SpecialChar ~
24692 \SpecialChar ~
24693 \SpecialChar ~
24694 \SpecialChar ~
24695 \SpecialChar ~
24696 \SpecialChar ~
24697 Comment 
24698 \newline
24699 ;;---\SpecialChar ~
24700 \SpecialChar ~
24701 \SpecialChar ~
24702 \SpecialChar ~
24703 \SpecialChar ~
24704 \SpecialChar ~
24705 \SpecialChar ~
24706 \SpecialChar ~
24707 \SpecialChar ~
24708 \SpecialChar ~
24709 \SpecialChar ~
24710 \SpecialChar ~
24711 \SpecialChar ~
24712 \SpecialChar ~
24713 -------\SpecialChar ~
24714 \SpecialChar ~
24715 \SpecialChar ~
24716 \SpecialChar ~
24717 \SpecialChar ~
24718 \SpecialChar ~
24719 \SpecialChar ~
24720 \SpecialChar ~
24721 \SpecialChar ~
24722 \SpecialChar ~
24723 \SpecialChar ~
24724 \SpecialChar ~
24725 \SpecialChar ~
24726 \SpecialChar ~
24727 \SpecialChar ~
24728 \SpecialChar ~
24729 \SpecialChar ~
24730 \SpecialChar ~
24731 \SpecialChar ~
24732 \SpecialChar ~
24733 \SpecialChar ~
24734 \SpecialChar ~
24735 -------
24736 \newline
24737 ;; 
24738 \newline
24739 ;;\SpecialChar ~
24740 n\SpecialChar ~
24741 \SpecialChar ~
24742 \SpecialChar ~
24743 \SpecialChar ~
24744 \SpecialChar ~
24745 \SpecialChar ~
24746 \SpecialChar ~
24747 \SpecialChar ~
24748 \SpecialChar ~
24749 \SpecialChar ~
24750 \SpecialChar ~
24751 \SpecialChar ~
24752 \SpecialChar ~
24753 \SpecialChar ~
24754 \SpecialChar ~
24755 sdcdb-next-fro
24756 m-src\SpecialChar ~
24757 \SpecialChar ~
24758 \SpecialChar ~
24759 \SpecialChar ~
24760 \SpecialChar ~
24761 \SpecialChar ~
24762 \SpecialChar ~
24763 \SpecialChar ~
24764 \SpecialChar ~
24765 \SpecialChar ~
24766 SDCDB next command 
24767 \newline
24768 ;;\SpecialChar ~
24769 b\SpecialChar ~
24770 \SpecialChar ~
24771 \SpecialChar ~
24772 \SpecialChar ~
24773 \SpecialChar ~
24774 \SpecialChar ~
24775 \SpecialChar ~
24776 \SpecialChar ~
24777 \SpecialChar ~
24778 \SpecialChar ~
24779 \SpecialChar ~
24780 \SpecialChar ~
24781 \SpecialChar ~
24782 \SpecialChar ~
24783 \SpecialChar ~
24784 sdcdb-back-from-src\SpecialChar ~
24785 \SpecialChar ~
24786 \SpecialChar ~
24787 \SpecialChar ~
24788 \SpecialChar ~
24789 \SpecialChar ~
24790 \SpecialChar ~
24791 \SpecialChar ~
24792 \SpecialChar ~
24793 \SpecialChar ~
24794 SDCDB back command 
24795 \newline
24796 ;;\SpecialChar ~
24797 c\SpecialChar ~
24798 \SpecialChar ~
24799 \SpecialChar ~
24800 \SpecialChar ~
24801 \SpecialChar ~
24802 \SpecialChar ~
24803 \SpecialChar ~
24804 \SpecialChar ~
24805 \SpecialChar ~
24806 \SpecialChar ~
24807 \SpecialChar ~
24808 \SpecialChar ~
24809 \SpecialChar ~
24810 \SpecialChar ~
24811 \SpecialChar ~
24812 sdcdb-cont-f
24813 rom-src\SpecialChar ~
24814 \SpecialChar ~
24815 \SpecialChar ~
24816 \SpecialChar ~
24817 \SpecialChar ~
24818 \SpecialChar ~
24819 \SpecialChar ~
24820 \SpecialChar ~
24821 \SpecialChar ~
24822 \SpecialChar ~
24823 SDCDB continue command
24824 \newline
24825 ;;\SpecialChar ~
24826 s\SpecialChar ~
24827 \SpecialChar ~
24828 \SpecialChar ~
24829 \SpecialChar ~
24830 \SpecialChar ~
24831 \SpecialChar ~
24832 \SpecialChar ~
24833 \SpecialChar ~
24834 \SpecialChar ~
24835 \SpecialChar ~
24836 \SpecialChar ~
24837 \SpecialChar ~
24838 \SpecialChar ~
24839 \SpecialChar ~
24840 \SpecialChar ~
24841 sdcdb-step-from-src\SpecialChar ~
24842 \SpecialChar ~
24843 \SpecialChar ~
24844 \SpecialChar ~
24845 \SpecialChar ~
24846 \SpecialChar ~
24847 \SpecialChar ~
24848 \SpecialChar ~
24849 \SpecialChar ~
24850 \SpecialChar ~
24851 SDCDB step command 
24852 \newline
24853 ;;\SpecialChar ~
24854 ?\SpecialChar ~
24855 \SpecialChar ~
24856 \SpecialChar ~
24857 \SpecialChar ~
24858 \SpecialChar ~
24859 \SpecialChar ~
24860 \SpecialChar ~
24861 \SpecialChar ~
24862 \SpecialChar ~
24863 \SpecialChar ~
24864 \SpecialChar ~
24865 \SpecialChar ~
24866 \SpecialChar ~
24867 \SpecialChar ~
24868 \SpecialChar ~
24869 sdcdb-w
24870 hatis-c-sexp\SpecialChar ~
24871 \SpecialChar ~
24872 \SpecialChar ~
24873 \SpecialChar ~
24874 \SpecialChar ~
24875 \SpecialChar ~
24876 \SpecialChar ~
24877 \SpecialChar ~
24878 \SpecialChar ~
24879 \SpecialChar ~
24880 SDCDB ptypecommand for data at 
24881 \newline
24882 ;;\SpecialChar ~
24883 \SpecialChar ~
24884 \SpecialChar ~
24885 \SpecialChar ~
24886 \SpecialChar ~
24887 \SpecialChar ~
24888 \SpecialChar ~
24889 \SpecialChar ~
24890 \SpecialChar ~
24891 \SpecialChar ~
24892 \SpecialChar ~
24893 \SpecialChar ~
24894 \SpecialChar ~
24895 \SpecialChar ~
24896 \SpecialChar ~
24897 \SpecialChar ~
24898 \SpecialChar ~
24899 \SpecialChar ~
24900 \SpecialChar ~
24901 \SpecialChar ~
24902 \SpecialChar ~
24903 \SpecialChar ~
24904 \SpecialChar ~
24905 \SpecialChar ~
24906 \SpecialChar ~
24907 \SpecialChar ~
24908 \SpecialChar ~
24909 \SpecialChar ~
24910 \SpecialChar ~
24911 \SpecialChar ~
24912 \SpecialChar ~
24913 \SpecialChar ~
24914 \SpecialChar ~
24915 \SpecialChar ~
24916 \SpecialChar ~
24917 \SpecialChar ~
24918 \SpecialChar ~
24919 \SpecialChar ~
24920 \SpecialChar ~
24921 \SpecialChar ~
24922 \SpecialChar ~
24923 \SpecialChar ~
24924 \SpecialChar ~
24925 \SpecialChar ~
24926 \SpecialChar ~
24927 \SpecialChar ~
24928 \SpecialChar ~
24929 buffer point 
24930 \newline
24931 ;;\SpecialChar ~
24932 x\SpecialChar ~
24933 \SpecialChar ~
24934 \SpecialChar ~
24935 \SpecialChar ~
24936 \SpecialChar ~
24937 \SpecialChar ~
24938 \SpecialChar ~
24939 \SpecialChar ~
24940 \SpecialChar ~
24941 \SpecialChar ~
24942 \SpecialChar ~
24943 \SpecialChar ~
24944 \SpecialChar ~
24945 \SpecialChar ~
24946 \SpecialChar ~
24947 sdcdbsrc-delete\SpecialChar ~
24948 \SpecialChar ~
24949 \SpecialChar ~
24950 \SpecialChar ~
24951 \SpecialChar ~
24952 \SpecialChar ~
24953 \SpecialChar ~
24954 \SpecialChar ~
24955 \SpecialChar ~
24956 \SpecialChar ~
24957 \SpecialChar ~
24958 \SpecialChar ~
24959 \SpecialChar ~
24960 \SpecialChar ~
24961 SDCD
24962 B Delete all breakpoints if no arg 
24963 \newline
24964 ;;\SpecialChar ~
24965 \SpecialChar ~
24966 \SpecialChar ~
24967 \SpecialChar ~
24968 \SpecialChar ~
24969 \SpecialChar ~
24970 \SpecialChar ~
24971 \SpecialChar ~
24972 \SpecialChar ~
24973 \SpecialChar ~
24974 \SpecialChar ~
24975 \SpecialChar ~
24976 \SpecialChar ~
24977 \SpecialChar ~
24978 \SpecialChar ~
24979 \SpecialChar ~
24980 \SpecialChar ~
24981 \SpecialChar ~
24982 \SpecialChar ~
24983 \SpecialChar ~
24984 \SpecialChar ~
24985 \SpecialChar ~
24986 \SpecialChar ~
24987 \SpecialChar ~
24988 \SpecialChar ~
24989 \SpecialChar ~
24990 \SpecialChar ~
24991 \SpecialChar ~
24992 \SpecialChar ~
24993 \SpecialChar ~
24994 \SpecialChar ~
24995 \SpecialChar ~
24996 \SpecialChar ~
24997 \SpecialChar ~
24998 \SpecialChar ~
24999 \SpecialChar ~
25000 \SpecialChar ~
25001 \SpecialChar ~
25002 \SpecialChar ~
25003 \SpecialChar ~
25004 \SpecialChar ~
25005 \SpecialChar ~
25006 \SpecialChar ~
25007 \SpecialChar ~
25008 \SpecialChar ~
25009 \SpecialChar ~
25010 \SpecialChar ~
25011 given or delete arg (C-u arg x) 
25012 \newline
25013 ;;\SpecialChar ~
25014 m\SpecialChar ~
25015 \SpecialChar ~
25016 \SpecialChar ~
25017 \SpecialChar ~
25018 \SpecialChar ~
25019 \SpecialChar ~
25020 \SpecialChar ~
25021 \SpecialChar ~
25022 \SpecialChar ~
25023 \SpecialChar ~
25024 \SpecialChar ~
25025 \SpecialChar ~
25026 \SpecialChar ~
25027 \SpecialChar ~
25028 \SpecialChar ~
25029 sdcdbsrc
25030 -frame\SpecialChar ~
25031 \SpecialChar ~
25032 \SpecialChar ~
25033 \SpecialChar ~
25034 \SpecialChar ~
25035 \SpecialChar ~
25036 \SpecialChar ~
25037 \SpecialChar ~
25038 \SpecialChar ~
25039 \SpecialChar ~
25040 \SpecialChar ~
25041 \SpecialChar ~
25042 \SpecialChar ~
25043 \SpecialChar ~
25044 \SpecialChar ~
25045 SDCDB Display current frame if no arg, 
25046 \newline
25047 ;;\SpecialChar ~
25048 \SpecialChar ~
25049 \SpecialChar ~
25050 \SpecialChar ~
25051 \SpecialChar ~
25052 \SpecialChar ~
25053 \SpecialChar ~
25054 \SpecialChar ~
25055 \SpecialChar ~
25056 \SpecialChar ~
25057 \SpecialChar ~
25058 \SpecialChar ~
25059 \SpecialChar ~
25060 \SpecialChar ~
25061 \SpecialChar ~
25062 \SpecialChar ~
25063 \SpecialChar ~
25064 \SpecialChar ~
25065 \SpecialChar ~
25066 \SpecialChar ~
25067 \SpecialChar ~
25068 \SpecialChar ~
25069 \SpecialChar ~
25070 \SpecialChar ~
25071 \SpecialChar ~
25072 \SpecialChar ~
25073 \SpecialChar ~
25074 \SpecialChar ~
25075 \SpecialChar ~
25076 \SpecialChar ~
25077 \SpecialChar ~
25078 \SpecialChar ~
25079 \SpecialChar ~
25080 \SpecialChar ~
25081 \SpecialChar ~
25082 \SpecialChar ~
25083 \SpecialChar ~
25084 \SpecialChar ~
25085 \SpecialChar ~
25086 \SpecialChar ~
25087 \SpecialChar ~
25088 \SpecialChar ~
25089 \SpecialChar ~
25090 \SpecialChar ~
25091 \SpecialChar ~
25092 \SpecialChar ~
25093 \SpecialChar ~
25094 given or display frame arg
25095  
25096 \newline
25097 ;;\SpecialChar ~
25098 \SpecialChar ~
25099 \SpecialChar ~
25100 \SpecialChar ~
25101 \SpecialChar ~
25102 \SpecialChar ~
25103 \SpecialChar ~
25104 \SpecialChar ~
25105 \SpecialChar ~
25106 \SpecialChar ~
25107 \SpecialChar ~
25108 \SpecialChar ~
25109 \SpecialChar ~
25110 \SpecialChar ~
25111 \SpecialChar ~
25112 \SpecialChar ~
25113 \SpecialChar ~
25114 \SpecialChar ~
25115 \SpecialChar ~
25116 \SpecialChar ~
25117 \SpecialChar ~
25118 \SpecialChar ~
25119 \SpecialChar ~
25120 \SpecialChar ~
25121 \SpecialChar ~
25122 \SpecialChar ~
25123 \SpecialChar ~
25124 \SpecialChar ~
25125 \SpecialChar ~
25126 \SpecialChar ~
25127 \SpecialChar ~
25128 \SpecialChar ~
25129 \SpecialChar ~
25130 \SpecialChar ~
25131 \SpecialChar ~
25132 \SpecialChar ~
25133 \SpecialChar ~
25134 \SpecialChar ~
25135 \SpecialChar ~
25136 \SpecialChar ~
25137 \SpecialChar ~
25138 \SpecialChar ~
25139 \SpecialChar ~
25140 \SpecialChar ~
25141 \SpecialChar ~
25142 \SpecialChar ~
25143 \SpecialChar ~
25144 buffer point 
25145 \newline
25146 ;;\SpecialChar ~
25147 !\SpecialChar ~
25148 \SpecialChar ~
25149 \SpecialChar ~
25150 \SpecialChar ~
25151 \SpecialChar ~
25152 \SpecialChar ~
25153 \SpecialChar ~
25154 \SpecialChar ~
25155 \SpecialChar ~
25156 \SpecialChar ~
25157 \SpecialChar ~
25158 \SpecialChar ~
25159 \SpecialChar ~
25160 \SpecialChar ~
25161 \SpecialChar ~
25162 sdcdbsrc-goto-sdcdb\SpecialChar ~
25163 \SpecialChar ~
25164 \SpecialChar ~
25165 \SpecialChar ~
25166 \SpecialChar ~
25167 \SpecialChar ~
25168 \SpecialChar ~
25169 \SpecialChar ~
25170 \SpecialChar ~
25171 \SpecialChar ~
25172 Goto the SDCDB output buffer 
25173 \newline
25174 ;;\SpecialChar ~
25175 p\SpecialChar ~
25176 \SpecialChar ~
25177 \SpecialChar ~
25178 \SpecialChar ~
25179 \SpecialChar ~
25180 \SpecialChar ~
25181 \SpecialChar ~
25182 \SpecialChar ~
25183 \SpecialChar ~
25184 \SpecialChar ~
25185 \SpecialChar ~
25186 \SpecialChar ~
25187 \SpecialChar ~
25188 \SpecialChar ~
25189 \SpecialChar ~
25190 sdcdb-prin
25191 t-c-sexp\SpecialChar ~
25192 \SpecialChar ~
25193 \SpecialChar ~
25194 \SpecialChar ~
25195 \SpecialChar ~
25196 \SpecialChar ~
25197 \SpecialChar ~
25198 \SpecialChar ~
25199 \SpecialChar ~
25200 \SpecialChar ~
25201 \SpecialChar ~
25202 SDCDB print command for data at 
25203 \newline
25204 ;;\SpecialChar ~
25205 \SpecialChar ~
25206 \SpecialChar ~
25207 \SpecialChar ~
25208 \SpecialChar ~
25209 \SpecialChar ~
25210 \SpecialChar ~
25211 \SpecialChar ~
25212 \SpecialChar ~
25213 \SpecialChar ~
25214 \SpecialChar ~
25215 \SpecialChar ~
25216 \SpecialChar ~
25217 \SpecialChar ~
25218 \SpecialChar ~
25219 \SpecialChar ~
25220 \SpecialChar ~
25221 \SpecialChar ~
25222 \SpecialChar ~
25223 \SpecialChar ~
25224 \SpecialChar ~
25225 \SpecialChar ~
25226 \SpecialChar ~
25227 \SpecialChar ~
25228 \SpecialChar ~
25229 \SpecialChar ~
25230 \SpecialChar ~
25231 \SpecialChar ~
25232 \SpecialChar ~
25233 \SpecialChar ~
25234 \SpecialChar ~
25235 \SpecialChar ~
25236 \SpecialChar ~
25237 \SpecialChar ~
25238 \SpecialChar ~
25239 \SpecialChar ~
25240 \SpecialChar ~
25241 \SpecialChar ~
25242 \SpecialChar ~
25243 \SpecialChar ~
25244 \SpecialChar ~
25245 \SpecialChar ~
25246 \SpecialChar ~
25247 \SpecialChar ~
25248 \SpecialChar ~
25249 \SpecialChar ~
25250 \SpecialChar ~
25251 buffer point 
25252 \newline
25253 ;;\SpecialChar ~
25254 g\SpecialChar ~
25255 \SpecialChar ~
25256 \SpecialChar ~
25257 \SpecialChar ~
25258 \SpecialChar ~
25259 \SpecialChar ~
25260 \SpecialChar ~
25261 \SpecialChar ~
25262 \SpecialChar ~
25263 \SpecialChar ~
25264 \SpecialChar ~
25265 \SpecialChar ~
25266 \SpecialChar ~
25267 \SpecialChar ~
25268 \SpecialChar ~
25269 sdcdbsrc-goto-sdcdb\SpecialChar ~
25270 \SpecialChar ~
25271 \SpecialChar ~
25272 \SpecialChar ~
25273 \SpecialChar ~
25274 \SpecialChar ~
25275 \SpecialChar ~
25276 \SpecialChar ~
25277 \SpecialChar ~
25278 \SpecialChar ~
25279 Got
25280 o the SDCDB output buffer 
25281 \newline
25282 ;;\SpecialChar ~
25283 t\SpecialChar ~
25284 \SpecialChar ~
25285 \SpecialChar ~
25286 \SpecialChar ~
25287 \SpecialChar ~
25288 \SpecialChar ~
25289 \SpecialChar ~
25290 \SpecialChar ~
25291 \SpecialChar ~
25292 \SpecialChar ~
25293 \SpecialChar ~
25294 \SpecialChar ~
25295 \SpecialChar ~
25296 \SpecialChar ~
25297 \SpecialChar ~
25298 sdcdbsrc-mode\SpecialChar ~
25299 \SpecialChar ~
25300 \SpecialChar ~
25301 \SpecialChar ~
25302 \SpecialChar ~
25303 \SpecialChar ~
25304 \SpecialChar ~
25305 \SpecialChar ~
25306 \SpecialChar ~
25307 \SpecialChar ~
25308 \SpecialChar ~
25309 \SpecialChar ~
25310 \SpecialChar ~
25311 \SpecialChar ~
25312 \SpecialChar ~
25313 \SpecialChar ~
25314 Toggles Sdcdbsrc mode (turns it
25315  off) 
25316 \newline
25317 ;; 
25318 \newline
25319 ;;\SpecialChar ~
25320 C-c\SpecialChar ~
25321 C-f\SpecialChar ~
25322 \SpecialChar ~
25323 \SpecialChar ~
25324 \SpecialChar ~
25325 \SpecialChar ~
25326 \SpecialChar ~
25327 \SpecialChar ~
25328 \SpecialChar ~
25329 \SpecialChar ~
25330 sdcdb-finish-from-src\SpecialChar ~
25331 \SpecialChar ~
25332 \SpecialChar ~
25333 \SpecialChar ~
25334 \SpecialChar ~
25335 \SpecialChar ~
25336 \SpecialChar ~
25337 \SpecialChar ~
25338 SDCDB finish command 
25339 \newline
25340 ;; 
25341 \newline
25342 ;;\SpecialChar ~
25343 C-x\SpecialChar ~
25344 SPC\SpecialChar ~
25345 \SpecialChar ~
25346 \SpecialChar ~
25347 \SpecialChar ~
25348 \SpecialChar ~
25349 \SpecialChar ~
25350 \SpecialChar ~
25351 \SpecialChar ~
25352 \SpecialChar ~
25353 sdcdb-brea
25354 k\SpecialChar ~
25355 \SpecialChar ~
25356 \SpecialChar ~
25357 \SpecialChar ~
25358 \SpecialChar ~
25359 \SpecialChar ~
25360 \SpecialChar ~
25361 \SpecialChar ~
25362 \SpecialChar ~
25363 \SpecialChar ~
25364 \SpecialChar ~
25365 \SpecialChar ~
25366 \SpecialChar ~
25367 \SpecialChar ~
25368 \SpecialChar ~
25369 \SpecialChar ~
25370 \SpecialChar ~
25371 \SpecialChar ~
25372 Set break for line with point 
25373 \newline
25374 ;;\SpecialChar ~
25375 ESC\SpecialChar ~
25376 t\SpecialChar ~
25377 \SpecialChar ~
25378 \SpecialChar ~
25379 \SpecialChar ~
25380 \SpecialChar ~
25381 \SpecialChar ~
25382 \SpecialChar ~
25383 \SpecialChar ~
25384 \SpecialChar ~
25385 \SpecialChar ~
25386 \SpecialChar ~
25387 sdcdbsrc-mode\SpecialChar ~
25388 \SpecialChar ~
25389 \SpecialChar ~
25390 \SpecialChar ~
25391 \SpecialChar ~
25392 \SpecialChar ~
25393 \SpecialChar ~
25394 \SpecialChar ~
25395 \SpecialChar ~
25396 \SpecialChar ~
25397 \SpecialChar ~
25398 \SpecialChar ~
25399 \SpecialChar ~
25400 \SpecialChar ~
25401 \SpecialChar ~
25402 \SpecialChar ~
25403 Toggle Sdcdbsrc mode 
25404 \newline
25405 ;;\SpecialChar ~
25406 ESC\SpecialChar ~
25407 m\SpecialChar ~
25408 \SpecialChar ~
25409 \SpecialChar ~
25410 \SpecialChar ~
25411 \SpecialChar ~
25412 \SpecialChar ~
25413 \SpecialChar ~
25414 \SpecialChar ~
25415 \SpecialChar ~
25416 \SpecialChar ~
25417 \SpecialChar ~
25418 sdc
25419 dbsrc-srcmode\SpecialChar ~
25420 \SpecialChar ~
25421 \SpecialChar ~
25422 \SpecialChar ~
25423 \SpecialChar ~
25424 \SpecialChar ~
25425 \SpecialChar ~
25426 \SpecialChar ~
25427 \SpecialChar ~
25428 \SpecialChar ~
25429 \SpecialChar ~
25430 \SpecialChar ~
25431 \SpecialChar ~
25432 Toggle list mode 
25433 \newline
25434 ;; 
25435 \newline
25436
25437
25438
25439 \layout Chapter
25440 TIPS
25441
25442 \layout Standard
25443 Here are a few guidelines that will help the compiler generate more efficient
25444  code, some of the tips are specific to this compiler others are generally
25445  good programming practice.
25446
25447 \layout Itemize
25448 Use the smallest data type to represent your data-value.
25449  If it is known in advance that the value is going to be less than 256 then
25450  use an 'unsigned char' instead of a 'short' or 'int'.
25451  Please note, that ANSI C requires both signed and unsigned chars to be
25452  promoted to 'signed int'
25453 \begin_inset LatexCommand \index{promotion to signed int}
25454
25455 \end_inset
25456
25457
25458 \begin_inset Marginal
25459 collapsed true
25460
25461 \layout Standard
25462
25463 \series bold
25464 \SpecialChar ~
25465 !
25466
25467 \end_inset
25468
25469  before doing any operation.
25470  This promotion
25471 \begin_inset LatexCommand \index{type promotion}
25472
25473 \end_inset
25474
25475
25476 \begin_inset LatexCommand \label{type promotion}
25477
25478 \end_inset
25479
25480  can be omitted, if the result is the same.
25481  The effect of the promotion rules together with the sign-extension is often
25482  surprising:
25483
25484 \begin_deeper
25485 \layout Verse
25486
25487 \family typewriter
25488 unsigned char uc = 0xfe;
25489 \newline
25490 if (uc * uc < 0) /* this is true! */
25491 \newline
25492 {
25493 \newline
25494 \SpecialChar ~
25495 \SpecialChar ~
25496 \SpecialChar ~
25497 \SpecialChar ~
25498 ....
25499 \newline
25500 }
25501
25502 \layout Standard
25503
25504 \family typewriter
25505 uc * uc
25506 \family default
25507  is evaluated as 
25508 \family typewriter
25509 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
25510 \family default
25511 .
25512  
25513 \newline
25514 Another one:
25515
25516 \layout Verse
25517
25518 \family typewriter
25519 (unsigned char) -12 / (signed char) -3 = ...
25520
25521 \layout Standard
25522 No, the result is not 4:
25523
25524 \layout Verse
25525
25526 \family typewriter
25527 (int) (unsigned char) -12 / (int) (signed char) -3 =
25528 \newline
25529 (int) (unsigned char)
25530  0xf4 / (int) (signed char) 0xfd =
25531 \newline
25532 (int) 0x00f4 / (int) 0xfffd =
25533 \newline
25534 (int) 0x00f4
25535  / (int) 0xfffd =
25536 \newline
25537 (int) 244 / (int) -3 =
25538 \newline
25539 (int) -81 = (int) 0xffaf;
25540
25541 \layout Standard
25542 Don't complain, that gcc gives you a different result.
25543  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
25544  Therefore the results are different.
25545 \newline
25546 From 
25547 \begin_inset Quotes sld
25548 \end_inset
25549
25550 comp.lang.c FAQ
25551 \begin_inset Quotes srd
25552 \end_inset
25553
25554 :
25555
25556 \layout Quote
25557
25558 \emph on
25559 If well-defined overflow characteristics are important and negative values
25560  are not, or if you want to steer clear of sign-extension problems when
25561  manipulating bits or bytes, use one of the corresponding unsigned types.
25562  (Beware when mixing signed and unsigned values in expressions, though.)
25563 \newline
25564 Although
25565  character types (especially unsigned char) can be used as "tiny" integers,
25566  doing so is sometimes more trouble than it's worth, due to unpredictable
25567  sign extension and increased code size.
25568
25569 \end_deeper
25570 \layout Itemize
25571 Use unsigned when it is known in advance that the value is not going to
25572  be negative.
25573  This helps especially if you are doing division or multiplication, bit-shifting
25574  or are using an array index.
25575
25576 \layout Itemize
25577 NEVER jump into a LOOP.
25578
25579 \layout Itemize
25580 Declare the variables to be local
25581 \begin_inset LatexCommand \index{local variables}
25582
25583 \end_inset
25584
25585  whenever possible, especially loop control variables (induction).
25586
25587 \layout Itemize
25588 Have a look at the assembly listing to get a 
25589 \begin_inset Quotes sld
25590 \end_inset
25591
25592 feeling
25593 \begin_inset Quotes srd
25594 \end_inset
25595
25596  for the code generation.
25597
25598 \layout Section
25599 Porting code from or to other compilers
25600 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
25601
25602 \end_inset
25603
25604
25605
25606 \layout Itemize
25607 check whether endianness of the compilers differs and adapt where needed.
25608
25609 \layout Itemize
25610 check the device specific header files
25611 \begin_inset LatexCommand \index{Header files}
25612
25613 \end_inset
25614
25615
25616 \begin_inset LatexCommand \index{Include files}
25617
25618 \end_inset
25619
25620  for compiler specific syntax.
25621  Eventually include the file <compiler.h
25622 \begin_inset LatexCommand \index{compiler.h (include file)}
25623
25624 \end_inset
25625
25626
25627 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
25628
25629 \end_inset
25630
25631  to allow using common header files.
25632  (see f.e.
25633  cc2510fx.h 
25634 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
25635
25636 \end_inset
25637
25638 ).
25639
25640 \layout Itemize
25641 check whether the startup code contains the correct initialization (watchdog,
25642  peripherals).
25643
25644 \layout Itemize
25645 check whether the sizes of short, int, long match.
25646
25647 \layout Itemize
25648 check if some 16 or 32 bit hardware registers require a specific addressing
25649  order (least significant or most significant byte first) and adapt if needed
25650  (
25651 \emph on
25652 first
25653 \emph default
25654  and 
25655 \emph on
25656 last
25657 \emph default
25658  relate to time and not to lower/upper memory location here, so this is
25659  
25660 \emph on
25661 not
25662 \emph default
25663  the same as endianness).
25664
25665 \layout Itemize
25666 check whether the keyword 
25667 \emph on
25668 volatile
25669 \emph default
25670  is used where needed.
25671  The compilers might differ in their optimization characteristics (as different
25672  versions of the same compiler might also use more clever optimizations
25673  this is good idea anyway).
25674  See section 
25675 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
25676
25677 \end_inset
25678
25679 .
25680
25681 \layout Itemize
25682 check that the compilers are not told to supress warnings.
25683
25684 \layout Itemize
25685 check and convert compiler specific extensions (interrupts, memory areas,
25686  pragmas etc.).
25687
25688 \layout Itemize
25689 check for differences in type promotion.
25690  Especially check for math operations on 
25691 \family typewriter
25692 char
25693 \family default
25694  or 
25695 \family typewriter
25696 unsigned char
25697 \family default
25698  variables.
25699  For the sake of C99 compatibility SDCC will probably promote these to 
25700 \family typewriter
25701 int
25702 \family default
25703  more often than other compilers.
25704  Eventually insert explicit casts to 
25705 \family typewriter
25706 (char) 
25707 \family default
25708 or
25709 \family typewriter
25710  (unsigned char)
25711 \family default
25712 .
25713  Also check that the ~\SpecialChar ~
25714 operator
25715 \begin_inset LatexCommand \index{\~\/ Operator}
25716
25717 \end_inset
25718
25719  is not used on 
25720 \family typewriter
25721 bit
25722 \begin_inset LatexCommand \index{bit}
25723
25724 \end_inset
25725
25726
25727 \family default
25728  variables, use the !\SpecialChar ~
25729 operator instead.
25730  See sections 
25731 \begin_inset LatexCommand \ref{type promotion}
25732
25733 \end_inset
25734
25735  and 
25736 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25737
25738 \end_inset
25739
25740 .
25741
25742 \layout Itemize
25743 check the assembly code generated for interrupt routines (f.e.
25744  for calls to possibly non-reentrant library functions).
25745
25746 \layout Itemize
25747 check whether timing loops result in proper timing (or preferably consider
25748  a rewrite of the code with timer based delays instead).
25749
25750 \layout Itemize
25751 check for differences in printf parameters (some compilers push (va_arg
25752 \begin_inset LatexCommand \index{vararg, va\_arg}
25753
25754 \end_inset
25755
25756 ) char variables as 
25757 \family typewriter
25758 int
25759 \family default
25760  others push them as 
25761 \family typewriter
25762 char
25763 \family default
25764 .
25765  See section 
25766 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25767
25768 \end_inset
25769
25770 ).
25771
25772 \layout Itemize
25773 check the resulting memory map
25774 \begin_inset LatexCommand \index{Memory map}
25775
25776 \end_inset
25777
25778 .
25779  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
25780 ly idata, pdata, xdata).
25781  Eventually check if unexpected library functions are included.
25782
25783 \layout Section
25784 Tools
25785 \begin_inset LatexCommand \index{Tools}
25786
25787 \end_inset
25788
25789  included in the distribution
25790
25791 \layout Standard
25792 \align left
25793 \begin_inset Tabular
25794 <lyxtabular version="3" rows="12" columns="3">
25795 <features>
25796 <column alignment="left" valignment="top" leftline="true" width="0pt">
25797 <column alignment="left" valignment="top" leftline="true" width="0pt">
25798 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25799 <row topline="true" bottomline="true">
25800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25801 \begin_inset Text
25802
25803 \layout Standard
25804
25805 \series bold
25806 Name
25807
25808 \end_inset
25809 </cell>
25810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25811 \begin_inset Text
25812
25813 \layout Standard
25814
25815 \series bold
25816 Purpose
25817
25818 \end_inset
25819 </cell>
25820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25821 \begin_inset Text
25822
25823 \layout Standard
25824
25825 \series bold
25826 Directory
25827
25828 \end_inset
25829 </cell>
25830 </row>
25831 <row topline="true">
25832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25833 \begin_inset Text
25834
25835 \layout Standard
25836 uCsim
25837 \begin_inset LatexCommand \index{uCsim}
25838
25839 \end_inset
25840
25841
25842
25843 \end_inset
25844 </cell>
25845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25846 \begin_inset Text
25847
25848 \layout Standard
25849 Simulator for various architectures
25850
25851 \end_inset
25852 </cell>
25853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25854 \begin_inset Text
25855
25856 \layout Standard
25857 sdcc/sim/ucsim
25858
25859 \end_inset
25860 </cell>
25861 </row>
25862 <row topline="true">
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25864 \begin_inset Text
25865
25866 \layout Standard
25867 keil2sdcc.pl
25868
25869 \end_inset
25870 </cell>
25871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25872 \begin_inset Text
25873
25874 \layout Standard
25875 header file
25876 \begin_inset LatexCommand \index{Header files}
25877
25878 \end_inset
25879
25880
25881 \begin_inset LatexCommand \index{Include files}
25882
25883 \end_inset
25884
25885  conversion
25886
25887 \end_inset
25888 </cell>
25889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25890 \begin_inset Text
25891
25892 \layout Standard
25893 sdcc/support/scripts
25894
25895 \end_inset
25896 </cell>
25897 </row>
25898 <row topline="true">
25899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25900 \begin_inset Text
25901
25902 \layout Standard
25903 mh2h.c
25904
25905 \end_inset
25906 </cell>
25907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25908 \begin_inset Text
25909
25910 \layout Standard
25911 header file conversion
25912
25913 \end_inset
25914 </cell>
25915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25916 \begin_inset Text
25917
25918 \layout Standard
25919 sdcc/support/scripts
25920
25921 \end_inset
25922 </cell>
25923 </row>
25924 <row topline="true">
25925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25926 \begin_inset Text
25927
25928 \layout Standard
25929 as-gbz80
25930
25931 \end_inset
25932 </cell>
25933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25934 \begin_inset Text
25935
25936 \layout Standard
25937 Assembler
25938
25939 \end_inset
25940 </cell>
25941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25942 \begin_inset Text
25943
25944 \layout Standard
25945
25946 \family roman
25947 \series medium
25948 \shape up
25949 \size normal
25950 \emph off
25951 \bar no
25952 \noun off
25953 \color none
25954 sdcc/bin
25955
25956 \end_inset
25957 </cell>
25958 </row>
25959 <row topline="true">
25960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25961 \begin_inset Text
25962
25963 \layout Standard
25964 as-z80
25965
25966 \end_inset
25967 </cell>
25968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25969 \begin_inset Text
25970
25971 \layout Standard
25972 Assembler
25973
25974 \end_inset
25975 </cell>
25976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25977 \begin_inset Text
25978
25979 \layout Standard
25980
25981 \family roman
25982 \series medium
25983 \shape up
25984 \size normal
25985 \emph off
25986 \bar no
25987 \noun off
25988 \color none
25989 sdcc/bin
25990
25991 \end_inset
25992 </cell>
25993 </row>
25994 <row topline="true">
25995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25996 \begin_inset Text
25997
25998 \layout Standard
25999 asx8051
26000
26001 \end_inset
26002 </cell>
26003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26004 \begin_inset Text
26005
26006 \layout Standard
26007 Assembler
26008
26009 \end_inset
26010 </cell>
26011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26012 \begin_inset Text
26013
26014 \layout Standard
26015
26016 \family roman
26017 \series medium
26018 \shape up
26019 \size normal
26020 \emph off
26021 \bar no
26022 \noun off
26023 \color none
26024 sdcc/bin
26025
26026 \end_inset
26027 </cell>
26028 </row>
26029 <row topline="true">
26030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26031 \begin_inset Text
26032
26033 \layout Standard
26034 SDCDB
26035
26036 \end_inset
26037 </cell>
26038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26039 \begin_inset Text
26040
26041 \layout Standard
26042 Simulator
26043
26044 \end_inset
26045 </cell>
26046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26047 \begin_inset Text
26048
26049 \layout Standard
26050
26051 \family roman
26052 \series medium
26053 \shape up
26054 \size normal
26055 \emph off
26056 \bar no
26057 \noun off
26058 \color none
26059 sdcc/bin
26060
26061 \end_inset
26062 </cell>
26063 </row>
26064 <row topline="true">
26065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26066 \begin_inset Text
26067
26068 \layout Standard
26069 aslink
26070
26071 \end_inset
26072 </cell>
26073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26074 \begin_inset Text
26075
26076 \layout Standard
26077 Linker
26078
26079 \end_inset
26080 </cell>
26081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26082 \begin_inset Text
26083
26084 \layout Standard
26085
26086 \family roman
26087 \series medium
26088 \shape up
26089 \size normal
26090 \emph off
26091 \bar no
26092 \noun off
26093 \color none
26094 sdcc/bin
26095
26096 \end_inset
26097 </cell>
26098 </row>
26099 <row topline="true">
26100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26101 \begin_inset Text
26102
26103 \layout Standard
26104 link-z80
26105
26106 \end_inset
26107 </cell>
26108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26109 \begin_inset Text
26110
26111 \layout Standard
26112 Linker
26113
26114 \end_inset
26115 </cell>
26116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26117 \begin_inset Text
26118
26119 \layout Standard
26120
26121 \family roman
26122 \series medium
26123 \shape up
26124 \size normal
26125 \emph off
26126 \bar no
26127 \noun off
26128 \color none
26129 sdcc/bin
26130
26131 \end_inset
26132 </cell>
26133 </row>
26134 <row topline="true">
26135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26136 \begin_inset Text
26137
26138 \layout Standard
26139 link-gbz80
26140
26141 \end_inset
26142 </cell>
26143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26144 \begin_inset Text
26145
26146 \layout Standard
26147 Linker
26148
26149 \end_inset
26150 </cell>
26151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26152 \begin_inset Text
26153
26154 \layout Standard
26155
26156 \family roman
26157 \series medium
26158 \shape up
26159 \size normal
26160 \emph off
26161 \bar no
26162 \noun off
26163 \color none
26164 sdcc/bin
26165
26166 \end_inset
26167 </cell>
26168 </row>
26169 <row topline="true" bottomline="true">
26170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26171 \begin_inset Text
26172
26173 \layout Standard
26174 packihx
26175
26176 \end_inset
26177 </cell>
26178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26179 \begin_inset Text
26180
26181 \layout Standard
26182 Intel Hex packer 
26183 \begin_inset LatexCommand \index{packihx (tool)}
26184
26185 \end_inset
26186
26187
26188
26189 \end_inset
26190 </cell>
26191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26192 \begin_inset Text
26193
26194 \layout Standard
26195
26196 \family roman
26197 \series medium
26198 \shape up
26199 \size normal
26200 \emph off
26201 \bar no
26202 \noun off
26203 \color none
26204 sdcc/bin
26205
26206 \end_inset
26207 </cell>
26208 </row>
26209 </lyxtabular>
26210
26211 \end_inset
26212
26213
26214 \newline
26215
26216
26217 \layout Section
26218 Documentation
26219 \begin_inset LatexCommand \index{Documentation}
26220
26221 \end_inset
26222
26223  included in the distribution
26224
26225 \layout Standard
26226 \align left
26227 \begin_inset Tabular
26228 <lyxtabular version="3" rows="10" columns="2">
26229 <features>
26230 <column alignment="block" valignment="top" leftline="true" width="40col%">
26231 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
26232 <row topline="true" bottomline="true" endhead="true">
26233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26234 \begin_inset Text
26235
26236 \layout Standard
26237
26238 \series bold
26239 Subject / Title
26240
26241 \end_inset
26242 </cell>
26243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26244 \begin_inset Text
26245
26246 \layout Standard
26247
26248 \series bold
26249 Filename / Where to get
26250
26251 \end_inset
26252 </cell>
26253 </row>
26254 <row topline="true">
26255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26256 \begin_inset Text
26257
26258 \layout Standard
26259 SDCC Compiler User Guide
26260
26261 \end_inset
26262 </cell>
26263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26264 \begin_inset Text
26265
26266 \layout Standard
26267 You're reading it right now
26268 \emph on
26269  \SpecialChar ~
26270 \SpecialChar ~
26271 \SpecialChar ~
26272
26273 \hfill
26274 online at:
26275 \emph default
26276
26277 \newline
26278
26279 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
26280
26281 \end_inset
26282
26283
26284
26285 \end_inset
26286 </cell>
26287 </row>
26288 <row topline="true">
26289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26290 \begin_inset Text
26291
26292 \layout Standard
26293 Changelog of SDCC
26294
26295 \end_inset
26296 </cell>
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26298 \begin_inset Text
26299
26300 \layout Standard
26301 sdcc/Changelog
26302 \emph on
26303  \SpecialChar ~
26304 \SpecialChar ~
26305 \SpecialChar ~
26306
26307 \hfill
26308 online at:
26309 \emph default
26310
26311 \newline
26312
26313 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26314
26315 \end_inset
26316
26317
26318
26319 \end_inset
26320 </cell>
26321 </row>
26322 <row topline="true">
26323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26324 \begin_inset Text
26325
26326 \layout Standard
26327 ASXXXX
26328 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
26329
26330 \end_inset
26331
26332
26333 \begin_inset LatexCommand \index{Assembler documentation}
26334
26335 \end_inset
26336
26337  Assemblers and
26338 \newline
26339 ASLINK
26340 \begin_inset LatexCommand \index{aslink}
26341
26342 \end_inset
26343
26344
26345 \begin_inset LatexCommand \index{Linker documentation}
26346
26347 \end_inset
26348
26349  Relocating Linker
26350
26351 \end_inset
26352 </cell>
26353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26354 \begin_inset Text
26355
26356 \layout Standard
26357 sdcc/as/doc/asxhtm.html 
26358 \emph on
26359 \SpecialChar ~
26360 \SpecialChar ~
26361 \SpecialChar ~
26362
26363 \hfill
26364 online at:
26365 \emph default
26366
26367 \newline
26368
26369 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
26370
26371 \end_inset
26372
26373
26374
26375 \end_inset
26376 </cell>
26377 </row>
26378 <row topline="true">
26379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26380 \begin_inset Text
26381
26382 \layout Standard
26383 SDCC regression test
26384 \begin_inset LatexCommand \index{Regression test}
26385
26386 \end_inset
26387
26388
26389
26390 \end_inset
26391 </cell>
26392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26393 \begin_inset Text
26394
26395 \layout Standard
26396 sdcc/doc/test_suite_spec.pdf 
26397 \emph on
26398 \SpecialChar ~
26399 \SpecialChar ~
26400 \SpecialChar ~
26401
26402 \hfill
26403 online at:
26404 \emph default
26405
26406 \newline
26407
26408 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26409
26410 \end_inset
26411
26412
26413
26414 \end_inset
26415 </cell>
26416 </row>
26417 <row topline="true">
26418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26419 \begin_inset Text
26420
26421 \layout Standard
26422 Various notes
26423
26424 \end_inset
26425 </cell>
26426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26427 \begin_inset Text
26428
26429 \layout Standard
26430 sdcc/doc/* 
26431 \emph on
26432 \SpecialChar ~
26433 \SpecialChar ~
26434 \SpecialChar ~
26435
26436 \hfill
26437 online at:
26438 \emph default
26439
26440 \newline
26441
26442 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
26443
26444 \end_inset
26445
26446
26447
26448 \end_inset
26449 </cell>
26450 </row>
26451 <row topline="true">
26452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26453 \begin_inset Text
26454
26455 \layout Standard
26456 Notes on debugging with SDCDB
26457 \begin_inset LatexCommand \index{SDCDB (debugger)}
26458
26459 \end_inset
26460
26461
26462
26463 \end_inset
26464 </cell>
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26466 \begin_inset Text
26467
26468 \layout Standard
26469 sdcc/debugger/README 
26470 \emph on
26471 \SpecialChar ~
26472 \SpecialChar ~
26473 \SpecialChar ~
26474
26475 \hfill
26476 online at
26477 \emph default
26478 :
26479 \newline
26480
26481 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
26482
26483 \end_inset
26484
26485
26486
26487 \end_inset
26488 </cell>
26489 </row>
26490 <row topline="true">
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26492 \begin_inset Text
26493
26494 \layout Standard
26495 uCsim
26496 \begin_inset LatexCommand \index{uCsim}
26497
26498 \end_inset
26499
26500  Software simulator for microcontrollers
26501
26502 \end_inset
26503 </cell>
26504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26505 \begin_inset Text
26506
26507 \layout Standard
26508
26509 \family roman
26510 \series medium
26511 \shape up
26512 \size normal
26513 \emph off
26514 \bar no
26515 \noun off
26516 \color none
26517 sdcc/sim/ucsim/doc
26518 \family default
26519 \series default
26520 \shape default
26521 \size default
26522 \emph default
26523 \bar default
26524 \noun default
26525 /index.html 
26526 \emph on
26527 \SpecialChar ~
26528 \SpecialChar ~
26529 \SpecialChar ~
26530
26531 \hfill
26532 online at:
26533 \emph default
26534
26535 \newline
26536
26537 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
26538
26539 \end_inset
26540
26541
26542
26543 \end_inset
26544 </cell>
26545 </row>
26546 <row topline="true">
26547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26548 \begin_inset Text
26549
26550 \layout Standard
26551 Temporary notes on the pic16
26552 \begin_inset LatexCommand \index{PIC16}
26553
26554 \end_inset
26555
26556  port
26557
26558 \end_inset
26559 </cell>
26560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26561 \begin_inset Text
26562
26563 \layout Standard
26564 sdcc/src/pic16/NOTES 
26565 \emph on
26566 \SpecialChar ~
26567 \SpecialChar ~
26568 \SpecialChar ~
26569
26570 \hfill
26571 online at:
26572 \newline
26573
26574 \emph default
26575
26576 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
26577
26578 \end_inset
26579
26580
26581
26582 \end_inset
26583 </cell>
26584 </row>
26585 <row topline="true" bottomline="true">
26586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26587 \begin_inset Text
26588
26589 \layout Standard
26590 SDCC internal documentation (debugging file format)
26591
26592 \end_inset
26593 </cell>
26594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26595 \begin_inset Text
26596
26597 \layout Standard
26598 sdcc/doc/
26599 \family roman
26600 \series medium
26601 \shape up
26602 \size normal
26603 \emph off
26604 \bar no
26605 \noun off
26606 \color none
26607 cdbfileformat.pd
26608 \family default
26609 \series default
26610 \shape default
26611 \size default
26612 \emph default
26613 \bar default
26614 \noun default
26615 f
26616 \emph on
26617  \SpecialChar ~
26618 \SpecialChar ~
26619 \SpecialChar ~
26620
26621 \hfill
26622 online at:
26623 \emph default
26624
26625 \newline
26626
26627 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
26628
26629 \end_inset
26630
26631
26632
26633 \end_inset
26634 </cell>
26635 </row>
26636 </lyxtabular>
26637
26638 \end_inset
26639
26640
26641 \newline
26642
26643
26644 \layout Section
26645 Related open source tools
26646 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
26647
26648 \end_inset
26649
26650
26651 \begin_inset LatexCommand \index{Related tools}
26652
26653 \end_inset
26654
26655
26656
26657 \layout Standard
26658 \align left
26659 \begin_inset Tabular
26660 <lyxtabular version="3" rows="14" columns="3">
26661 <features>
26662 <column alignment="left" valignment="top" leftline="true" width="0pt">
26663 <column alignment="block" valignment="top" leftline="true" width="30line%">
26664 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26665 <row topline="true" bottomline="true">
26666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26667 \begin_inset Text
26668
26669 \layout Standard
26670
26671 \series bold
26672 Name
26673
26674 \end_inset
26675 </cell>
26676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26677 \begin_inset Text
26678
26679 \layout Standard
26680
26681 \series bold
26682 Purpose
26683
26684 \end_inset
26685 </cell>
26686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26687 \begin_inset Text
26688
26689 \layout Standard
26690
26691 \series bold
26692 Where to get
26693
26694 \end_inset
26695 </cell>
26696 </row>
26697 <row topline="true">
26698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26699 \begin_inset Text
26700
26701 \layout Standard
26702 gpsim
26703 \begin_inset LatexCommand \index{gpsim (pic simulator)}
26704
26705 \end_inset
26706
26707
26708
26709 \end_inset
26710 </cell>
26711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26712 \begin_inset Text
26713
26714 \layout Standard
26715 PIC simulator
26716
26717 \end_inset
26718 </cell>
26719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26720 \begin_inset Text
26721
26722 \layout Standard
26723 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
26724
26725 \end_inset
26726
26727
26728
26729 \end_inset
26730 </cell>
26731 </row>
26732 <row topline="true">
26733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26734 \begin_inset Text
26735
26736 \layout Standard
26737 gputils
26738 \begin_inset LatexCommand \index{gputils (pic tools)}
26739
26740 \end_inset
26741
26742
26743
26744 \end_inset
26745 </cell>
26746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26747 \begin_inset Text
26748
26749 \layout Standard
26750 GNU PIC utilities
26751
26752 \end_inset
26753 </cell>
26754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26755 \begin_inset Text
26756
26757 \layout Standard
26758 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26759
26760 \end_inset
26761
26762
26763
26764 \end_inset
26765 </cell>
26766 </row>
26767 <row topline="true">
26768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26769 \begin_inset Text
26770
26771 \layout Standard
26772 flP5
26773
26774 \end_inset
26775 </cell>
26776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26777 \begin_inset Text
26778
26779 \layout Standard
26780 PIC programmer
26781
26782 \end_inset
26783 </cell>
26784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26785 \begin_inset Text
26786
26787 \layout Standard
26788 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
26789
26790 \end_inset
26791
26792
26793
26794 \end_inset
26795 </cell>
26796 </row>
26797 <row topline="true">
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26799 \begin_inset Text
26800
26801 \layout Standard
26802 ec2drv/newcdb
26803
26804 \end_inset
26805 </cell>
26806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26807 \begin_inset Text
26808
26809 \layout Standard
26810 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
26811  (Unix only)
26812
26813 \end_inset
26814 </cell>
26815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26816 \begin_inset Text
26817
26818 \layout Standard
26819 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
26820
26821 \end_inset
26822
26823
26824
26825 \end_inset
26826 </cell>
26827 </row>
26828 <row topline="true">
26829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26830 \begin_inset Text
26831
26832 \layout Standard
26833 indent
26834 \begin_inset LatexCommand \index{indent (source formatting tool)}
26835
26836 \end_inset
26837
26838
26839
26840 \end_inset
26841 </cell>
26842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26843 \begin_inset Text
26844
26845 \layout Standard
26846 Formats C source - Master of the white spaces
26847
26848 \end_inset
26849 </cell>
26850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26851 \begin_inset Text
26852
26853 \layout Standard
26854 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
26855
26856 \end_inset
26857
26858
26859
26860 \end_inset
26861 </cell>
26862 </row>
26863 <row topline="true">
26864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26865 \begin_inset Text
26866
26867 \layout Standard
26868 srecord
26869 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
26870
26871 \end_inset
26872
26873
26874
26875 \end_inset
26876 </cell>
26877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26878 \begin_inset Text
26879
26880 \layout Standard
26881 Object file conversion, checksumming, ...
26882
26883 \end_inset
26884 </cell>
26885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26886 \begin_inset Text
26887
26888 \layout Standard
26889 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
26890
26891 \end_inset
26892
26893
26894
26895 \end_inset
26896 </cell>
26897 </row>
26898 <row topline="true">
26899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26900 \begin_inset Text
26901
26902 \layout Standard
26903 objdump
26904 \begin_inset LatexCommand \index{objdump (tool)}
26905
26906 \end_inset
26907
26908
26909
26910 \end_inset
26911 </cell>
26912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26913 \begin_inset Text
26914
26915 \layout Standard
26916 Object file conversion, ...
26917
26918 \end_inset
26919 </cell>
26920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26921 \begin_inset Text
26922
26923 \layout Standard
26924 Part of binutils (should be there anyway)
26925
26926 \end_inset
26927 </cell>
26928 </row>
26929 <row topline="true">
26930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26931 \begin_inset Text
26932
26933 \layout Standard
26934 cmon51
26935
26936 \end_inset
26937 </cell>
26938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26939 \begin_inset Text
26940
26941 \layout Standard
26942 8051 monitor (hex up-/download, single step, disassemble)
26943
26944 \end_inset
26945 </cell>
26946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26947 \begin_inset Text
26948
26949 \layout Standard
26950 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
26951
26952 \end_inset
26953
26954
26955
26956 \end_inset
26957 </cell>
26958 </row>
26959 <row topline="true">
26960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26961 \begin_inset Text
26962
26963 \layout Standard
26964 doxygen
26965 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
26966
26967 \end_inset
26968
26969
26970
26971 \end_inset
26972 </cell>
26973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26974 \begin_inset Text
26975
26976 \layout Standard
26977 Source code documentation system
26978
26979 \end_inset
26980 </cell>
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26982 \begin_inset Text
26983
26984 \layout Standard
26985 \begin_inset LatexCommand \url{http://www.doxygen.org}
26986
26987 \end_inset
26988
26989
26990
26991 \end_inset
26992 </cell>
26993 </row>
26994 <row topline="true">
26995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26996 \begin_inset Text
26997
26998 \layout Standard
26999 kdevelop
27000
27001 \end_inset
27002 </cell>
27003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27004 \begin_inset Text
27005
27006 \layout Standard
27007 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27008
27009 \end_inset
27010 </cell>
27011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27012 \begin_inset Text
27013
27014 \layout Standard
27015 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27016
27017 \end_inset
27018
27019
27020
27021 \end_inset
27022 </cell>
27023 </row>
27024 <row topline="true">
27025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27026 \begin_inset Text
27027
27028 \layout Standard
27029 paulmon
27030
27031 \end_inset
27032 </cell>
27033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27034 \begin_inset Text
27035
27036 \layout Standard
27037 8051 monitor (hex up-/download, single step, disassemble)
27038
27039 \end_inset
27040 </cell>
27041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27042 \begin_inset Text
27043
27044 \layout Standard
27045 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27046
27047 \end_inset
27048
27049
27050
27051 \end_inset
27052 </cell>
27053 </row>
27054 <row topline="true">
27055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27056 \begin_inset Text
27057
27058 \layout Standard
27059 splint
27060 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27061
27062 \end_inset
27063
27064
27065
27066 \end_inset
27067 </cell>
27068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27069 \begin_inset Text
27070
27071 \layout Standard
27072 Statically checks c sources (see 
27073 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27074
27075 \end_inset
27076
27077 )
27078
27079 \end_inset
27080 </cell>
27081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27082 \begin_inset Text
27083
27084 \layout Standard
27085 \begin_inset LatexCommand \url{http://www.splint.org}
27086
27087 \end_inset
27088
27089
27090
27091 \end_inset
27092 </cell>
27093 </row>
27094 <row topline="true" bottomline="true">
27095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27096 \begin_inset Text
27097
27098 \layout Standard
27099 ddd
27100 \begin_inset LatexCommand \index{DDD (debugger)}
27101
27102 \end_inset
27103
27104
27105
27106 \end_inset
27107 </cell>
27108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27109 \begin_inset Text
27110
27111 \layout Standard
27112 Debugger, serves nicely as GUI to SDCDB
27113 \begin_inset LatexCommand \index{SDCDB (debugger)}
27114
27115 \end_inset
27116
27117  (Unix only)
27118
27119 \end_inset
27120 </cell>
27121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27122 \begin_inset Text
27123
27124 \layout Standard
27125 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
27126
27127 \end_inset
27128
27129
27130
27131 \end_inset
27132 </cell>
27133 </row>
27134 </lyxtabular>
27135
27136 \end_inset
27137
27138
27139 \newline
27140
27141
27142 \layout Section
27143 Related documentation / recommended reading
27144
27145 \layout Standard
27146 \align left
27147 \begin_inset Tabular
27148 <lyxtabular version="3" rows="7" columns="3">
27149 <features>
27150 <column alignment="left" valignment="top" leftline="true" width="0pt">
27151 <column alignment="left" valignment="top" leftline="true" width="0">
27152 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27153 <row topline="true" bottomline="true">
27154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27155 \begin_inset Text
27156
27157 \layout Standard
27158
27159 \series bold
27160 Name
27161
27162 \end_inset
27163 </cell>
27164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27165 \begin_inset Text
27166
27167 \layout Standard
27168
27169 \series bold
27170 Subject / Title
27171
27172 \end_inset
27173 </cell>
27174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27175 \begin_inset Text
27176
27177 \layout Standard
27178
27179 \series bold
27180 Where to get
27181
27182 \end_inset
27183 </cell>
27184 </row>
27185 <row topline="true">
27186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27187 \begin_inset Text
27188
27189 \layout Standard
27190
27191 \family roman
27192 \series medium
27193 \shape up
27194 \size normal
27195 \emph off
27196 \bar no
27197 \noun off
27198 \color none
27199 c-refcard.pdf
27200
27201 \end_inset
27202 </cell>
27203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27204 \begin_inset Text
27205
27206 \layout Standard
27207 C Reference Card
27208 \begin_inset LatexCommand \index{C Reference card}
27209
27210 \end_inset
27211
27212 , 2 pages
27213
27214 \end_inset
27215 </cell>
27216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27217 \begin_inset Text
27218
27219 \layout Standard
27220 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
27221
27222 \end_inset
27223
27224
27225
27226 \end_inset
27227 </cell>
27228 </row>
27229 <row topline="true">
27230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27231 \begin_inset Text
27232
27233 \layout Standard
27234 c-faq
27235
27236 \end_inset
27237 </cell>
27238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27239 \begin_inset Text
27240
27241 \layout Standard
27242 C-FAQ
27243 \begin_inset LatexCommand \index{C FAQ}
27244
27245 \end_inset
27246
27247
27248
27249 \end_inset
27250 </cell>
27251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27252 \begin_inset Text
27253
27254 \layout Standard
27255 \begin_inset LatexCommand \url{http://www.c-faq.com}
27256
27257 \end_inset
27258
27259
27260
27261 \end_inset
27262 </cell>
27263 </row>
27264 <row topline="true">
27265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27266 \begin_inset Text
27267
27268 \layout Standard
27269 ISO/IEC 9899:TC2
27270
27271 \end_inset
27272 </cell>
27273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27274 \begin_inset Text
27275
27276 \layout Standard
27277 \begin_inset Quotes sld
27278 \end_inset
27279
27280 C-Standard
27281 \begin_inset Quotes srd
27282 \end_inset
27283
27284
27285
27286 \end_inset
27287 </cell>
27288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27289 \begin_inset Text
27290
27291 \layout Standard
27292
27293 \size footnotesize
27294 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
27295
27296 \end_inset
27297
27298
27299
27300 \end_inset
27301 </cell>
27302 </row>
27303 <row topline="true">
27304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27305 \begin_inset Text
27306
27307 \layout Standard
27308 ISO/IEC DTR 18037
27309
27310 \end_inset
27311 </cell>
27312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27313 \begin_inset Text
27314
27315 \layout Standard
27316 \begin_inset Quotes sld
27317 \end_inset
27318
27319 Extensions for Embedded C
27320 \begin_inset Quotes srd
27321 \end_inset
27322
27323
27324
27325 \end_inset
27326 </cell>
27327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27328 \begin_inset Text
27329
27330 \layout Standard
27331
27332 \size footnotesize
27333 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
27334
27335 \end_inset
27336
27337
27338
27339 \end_inset
27340 </cell>
27341 </row>
27342 <row topline="true">
27343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27344 \begin_inset Text
27345
27346 \layout Standard
27347
27348
27349 \end_inset
27350 </cell>
27351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27352 \begin_inset Text
27353
27354 \layout Standard
27355 Latest datasheet of target CPU
27356
27357 \end_inset
27358 </cell>
27359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27360 \begin_inset Text
27361
27362 \layout Standard
27363 vendor
27364
27365 \end_inset
27366 </cell>
27367 </row>
27368 <row topline="true" bottomline="true">
27369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27370 \begin_inset Text
27371
27372 \layout Standard
27373
27374
27375 \end_inset
27376 </cell>
27377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27378 \begin_inset Text
27379
27380 \layout Standard
27381 Revision history of datasheet
27382
27383 \end_inset
27384 </cell>
27385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27386 \begin_inset Text
27387
27388 \layout Standard
27389 vendor
27390
27391 \end_inset
27392 </cell>
27393 </row>
27394 </lyxtabular>
27395
27396 \end_inset
27397
27398
27399 \newline
27400
27401
27402 \layout Section
27403 Application notes specifically for SDCC
27404
27405 \layout Standard
27406 SDCC makes no claims about the completeness of this list and about up-to-datenes
27407 s or correctness of the application notes
27408 \begin_inset LatexCommand \index{Application notes}
27409
27410 \end_inset
27411
27412 .
27413
27414 \layout Standard
27415 \align left
27416
27417 \size footnotesize
27418 \begin_inset Tabular
27419 <lyxtabular version="3" rows="7" columns="3">
27420 <features>
27421 <column alignment="block" valignment="top" leftline="true" width="17col%">
27422 <column alignment="block" valignment="top" leftline="true" width="27col%">
27423 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
27424 <row topline="true" bottomline="true">
27425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27426 \begin_inset Text
27427
27428 \layout Standard
27429
27430 \series bold
27431 \size footnotesize
27432 Vendor
27433
27434 \end_inset
27435 </cell>
27436 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27437 \begin_inset Text
27438
27439 \layout Standard
27440
27441 \series bold
27442 \size footnotesize
27443 Subject / Title
27444
27445 \end_inset
27446 </cell>
27447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27448 \begin_inset Text
27449
27450 \layout Standard
27451
27452 \series bold
27453 \size footnotesize
27454 Where to get
27455
27456 \end_inset
27457 </cell>
27458 </row>
27459 <row topline="true">
27460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27461 \begin_inset Text
27462
27463 \layout Standard
27464
27465 \size footnotesize
27466 Maxim / Dallas
27467
27468 \end_inset
27469 </cell>
27470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27471 \begin_inset Text
27472
27473 \layout Standard
27474
27475 \size footnotesize
27476 Using the SDCC Compiler for the DS80C400
27477 \begin_inset LatexCommand \index{DS80C400}
27478
27479 \end_inset
27480
27481
27482
27483 \end_inset
27484 </cell>
27485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27486 \begin_inset Text
27487
27488 \layout Standard
27489
27490 \size footnotesize
27491 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
27492
27493 \end_inset
27494
27495
27496
27497 \end_inset
27498 </cell>
27499 </row>
27500 <row topline="true">
27501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27502 \begin_inset Text
27503
27504 \layout Standard
27505
27506 \size footnotesize
27507 Maxim / Dallas
27508
27509 \end_inset
27510 </cell>
27511 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
27512 \begin_inset Text
27513
27514 \layout Standard
27515
27516 \size footnotesize
27517 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
27518 \begin_inset LatexCommand \index{DS89C4x0}
27519
27520 \end_inset
27521
27522  Family of Microcontrollers
27523
27524 \end_inset
27525 </cell>
27526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27527 \begin_inset Text
27528
27529 \layout Standard
27530
27531 \size footnotesize
27532 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
27533
27534 \end_inset
27535
27536
27537
27538 \end_inset
27539 </cell>
27540 </row>
27541 <row topline="true">
27542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27543 \begin_inset Text
27544
27545 \layout Standard
27546
27547 \size footnotesize
27548 Silicon Laboratories / Cygnal
27549
27550 \end_inset
27551 </cell>
27552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27553 \begin_inset Text
27554
27555 \layout Standard
27556
27557 \size footnotesize
27558 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
27559 \begin_inset LatexCommand \index{IDE}
27560
27561 \end_inset
27562
27563
27564
27565 \end_inset
27566 </cell>
27567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27568 \begin_inset Text
27569
27570 \layout Standard
27571
27572 \size footnotesize
27573 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
27574
27575 \end_inset
27576
27577
27578
27579 \end_inset
27580 </cell>
27581 </row>
27582 <row topline="true">
27583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27584 \begin_inset Text
27585
27586 \layout Standard
27587
27588 \size footnotesize
27589 Ramtron / Goal Semiconductor
27590
27591 \end_inset
27592 </cell>
27593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27594 \begin_inset Text
27595
27596 \layout Standard
27597
27598 \size footnotesize
27599 Interfacing SDCC to Syn and Textpad
27600
27601 \end_inset
27602 </cell>
27603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27604 \begin_inset Text
27605
27606 \layout Standard
27607
27608 \size footnotesize
27609 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27610
27611 \end_inset
27612
27613
27614
27615 \end_inset
27616 </cell>
27617 </row>
27618 <row topline="true">
27619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27620 \begin_inset Text
27621
27622 \layout Standard
27623
27624 \size footnotesize
27625 Ramtron / Goal Semiconductor
27626
27627 \end_inset
27628 </cell>
27629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27630 \begin_inset Text
27631
27632 \layout Standard
27633
27634 \size footnotesize
27635 Installing and Configuring SDCC and Crimson Editor 
27636
27637 \end_inset
27638 </cell>
27639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27640 \begin_inset Text
27641
27642 \layout Standard
27643
27644 \size footnotesize
27645 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27646
27647 \end_inset
27648
27649
27650
27651 \end_inset
27652 </cell>
27653 </row>
27654 <row topline="true" bottomline="true">
27655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27656 \begin_inset Text
27657
27658 \layout Standard
27659
27660 \size footnotesize
27661 Texas Instruments
27662
27663 \end_inset
27664 </cell>
27665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27666 \begin_inset Text
27667
27668 \layout Standard
27669
27670 \size footnotesize
27671 MSC12xx Programming with SDCC
27672
27673 \end_inset
27674 </cell>
27675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27676 \begin_inset Text
27677
27678 \layout Standard
27679
27680 \size footnotesize
27681 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
27682
27683 \end_inset
27684
27685
27686
27687 \end_inset
27688 </cell>
27689 </row>
27690 </lyxtabular>
27691
27692 \end_inset
27693
27694
27695
27696 \layout Section
27697 Some Questions
27698
27699 \layout Standard
27700 Some questions answered, some pointers given - it might be time to in turn
27701  ask 
27702 \emph on
27703 you
27704 \emph default
27705  some questions: 
27706
27707 \layout Itemize
27708 can you solve your project with the selected microcontroller? Would you
27709  find out early or rather late that your target is too small/slow/whatever?
27710  Can you switch to a slightly better device if it doesn't fit?
27711
27712 \layout Itemize
27713 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
27714  and/or another programming language be more adequate? Would an operating
27715  system on the target device help?
27716
27717 \layout Itemize
27718 if you solved the problem, will the marketing department be happy?
27719
27720 \layout Itemize
27721 if the marketing department is happy, will customers be happy?
27722
27723 \layout Itemize
27724 if you're the project manager, marketing department and maybe even the customer
27725  in one person, have you tried to see the project from the outside?
27726
27727 \layout Itemize
27728 is the project done if you think it is done? Or is just that other interface/pro
27729 tocol/feature/configuration/option missing? How about website, manual(s),
27730  internationali(z|s)ation, packaging, labels, 2nd source for components,
27731  electromagnetic compatability/interference, documentation for production,
27732  production test software, update mechanism, patent issues?
27733
27734 \layout Itemize
27735 is your project adequately positioned in that magic triangle: fame, fortune,
27736  fun?
27737
27738 \layout Standard
27739 Maybe not all answers to these questions are known and some answers may
27740  even be 
27741 \emph on
27742 no
27743 \emph default
27744 , nevertheless knowing these questions may help you to avoid burnout
27745 \begin_inset Foot
27746 collapsed false
27747
27748 \layout Standard
27749 burnout is bad for electronic devices, programmers and motorcycle tyres
27750
27751 \end_inset
27752
27753 .
27754  Chances are you didn't want to hear some of them...
27755
27756 \layout Chapter
27757 Support
27758 \begin_inset LatexCommand \index{Support}
27759
27760 \end_inset
27761
27762
27763
27764 \layout Standard
27765 SDCC has grown to be a large project.
27766  The compiler alone (without the preprocessor, assembler and linker) is
27767  well over 150,000 lines of code (blank stripped).
27768  The open source nature of this project is a key to its continued growth
27769  and support.
27770  You gain the benefit and support of many active software developers and
27771  end users.
27772  Is SDCC perfect? No, that's why we need your help.
27773  The developers take pride in fixing reported bugs.
27774  You can help by reporting the bugs and helping other SDCC users.
27775  There are lots of ways to contribute, and we encourage you to take part
27776  in making SDCC a great software package.
27777  
27778
27779 \layout Standard
27780 The SDCC project is hosted on the SDCC sourceforge site at 
27781 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
27782
27783 \end_inset
27784
27785 .
27786  You'll find the complete set of mailing lists
27787 \begin_inset LatexCommand \index{Mailing list(s)}
27788
27789 \end_inset
27790
27791 , forums, bug reporting system, patch submission
27792 \begin_inset LatexCommand \index{Patch submission}
27793
27794 \end_inset
27795
27796  system, download
27797 \begin_inset LatexCommand \index{download}
27798
27799 \end_inset
27800
27801  area and Subversion code repository
27802 \begin_inset LatexCommand \index{Subversion code repository}
27803
27804 \end_inset
27805
27806  there.
27807
27808 \layout Section
27809 Reporting Bugs
27810 \begin_inset LatexCommand \index{Bug reporting}
27811
27812 \end_inset
27813
27814
27815 \begin_inset LatexCommand \index{Reporting bugs}
27816
27817 \end_inset
27818
27819
27820
27821 \layout Standard
27822 The recommended way of reporting bugs is using the infrastructure of the
27823  sourceforge site.
27824  You can follow the status of bug reports there and have an overview about
27825  the known bugs.
27826
27827 \layout Standard
27828 Bug reports are automatically forwarded to the developer mailing list and
27829  will be fixed ASAP.
27830  When reporting a bug, it is very useful to include a small test program
27831  (the smaller the better) which reproduces the problem.
27832  If you can isolate the problem by looking at the generated assembly code,
27833  this can be very helpful.
27834  Compiling your program with the -
27835 \begin_inset ERT
27836 status Collapsed
27837
27838 \layout Standard
27839
27840
27841 \backslash
27842 /
27843
27844 \end_inset
27845
27846 -dumpall
27847 \begin_inset LatexCommand \index{-\/-dumpall}
27848
27849 \end_inset
27850
27851  option can sometimes be useful in locating optimization problems.
27852  When reporting a bug please make sure you:
27853
27854 \layout Enumerate
27855 Attach the code you are compiling with SDCC.
27856  
27857
27858 \layout Enumerate
27859 Specify the exact command you use to run SDCC, or attach your Makefile.
27860  
27861
27862 \layout Enumerate
27863 Specify the SDCC version (type "
27864 \family sans
27865 \series bold
27866 sdcc -v
27867 \family default
27868 \series default
27869 "), your platform, and operating system.
27870  
27871
27872 \layout Enumerate
27873 Provide an exact copy of any error message or incorrect output.
27874  
27875
27876 \layout Enumerate
27877 Put something meaningful in the subject of your message.
27878
27879 \layout Standard
27880 Please attempt to include these 5 important parts, as applicable, in all
27881  requests for support or when reporting any problems or bugs with SDCC.
27882  Though this will make your message lengthy, it will greatly improve your
27883  chance that SDCC users and developers will be able to help you.
27884  Some SDCC developers are frustrated by bug reports without code provided
27885  that they can use to reproduce and ultimately fix the problem, so please
27886  be sure to provide sample code if you are reporting a bug! 
27887
27888 \layout Standard
27889 Please have a short check that you are using a recent version of SDCC and
27890  the bug is not yet known.
27891  This is the link for reporting bugs: 
27892 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
27893
27894 \end_inset
27895
27896 .
27897  With SDCC on average having more than 200 downloads
27898 \begin_inset LatexCommand \index{download}
27899
27900 \end_inset
27901
27902  on sourceforge per day
27903 \begin_inset Foot
27904 collapsed false
27905
27906 \layout Standard
27907 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
27908  between 2002 and 2005.
27909  This does not include other methods of distribution.
27910
27911 \end_inset
27912
27913  there must be some users.
27914  So it's not exactly easy to find a new bug.
27915  If you find one we need it: 
27916 \emph on
27917 reporting bugs is good
27918 \emph default
27919 .
27920
27921 \layout Section
27922 Requesting Features
27923 \begin_inset LatexCommand \label{sub:Requesting-Features}
27924
27925 \end_inset
27926
27927
27928 \begin_inset LatexCommand \index{Feature request}
27929
27930 \end_inset
27931
27932
27933 \begin_inset LatexCommand \index{Requesting features}
27934
27935 \end_inset
27936
27937
27938
27939 \layout Standard
27940 Like bug reports feature requests are forwarded to the developer mailing
27941  list.
27942  This is the link for requesting features: 
27943 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
27944
27945 \end_inset
27946
27947 .
27948
27949 \layout Section
27950 Submitting patches
27951
27952 \layout Standard
27953 Like bug reports contributed patches are forwarded to the developer mailing
27954  list.
27955  This is the link for submitting patches
27956 \begin_inset LatexCommand \index{Patch submission}
27957
27958 \end_inset
27959
27960
27961 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
27962
27963 \end_inset
27964
27965 .
27966
27967 \layout Standard
27968 You need to specify some parameters to the 
27969 \family typewriter
27970 diff
27971 \family default
27972  command for the patches to be useful.
27973  If you modified more than one file a patch created f.e.
27974  with 
27975 \family sans
27976 \series bold
27977
27978 \begin_inset Quotes sld
27979 \end_inset
27980
27981 diff -Naur unmodified_directory modified_directory >my_changes.patch
27982 \begin_inset Quotes srd
27983 \end_inset
27984
27985
27986 \family default
27987 \series default
27988  will be fine, otherwise 
27989 \family sans
27990 \series bold
27991
27992 \begin_inset Quotes sld
27993 \end_inset
27994
27995 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
27996 \begin_inset Quotes srd
27997 \end_inset
27998
27999
28000 \series default
28001  
28002 \family default
28003 will do.
28004
28005 \layout Section
28006 Getting Help
28007
28008 \layout Standard
28009 These links should take you directly to the 
28010 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28011
28012 \end_inset
28013
28014
28015 \begin_inset Foot
28016 collapsed false
28017
28018 \layout Standard
28019 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28020  automated messages (mid 2003)
28021
28022 \end_inset
28023
28024  and the 
28025 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28026
28027 \end_inset
28028
28029 , lists
28030 \begin_inset LatexCommand \index{Mailing list(s)}
28031
28032 \end_inset
28033
28034  and forums are archived and searchable so if you are lucky someone already
28035  had a similar problem.
28036  While mails to the lists themselves are delivered promptly their web front
28037  end on sourceforge sometimes shows a severe time lag (up to several weeks),
28038  if you're seriously using SDCC please consider subscribing to the lists.
28039
28040 \layout Section
28041 ChangeLog
28042
28043 \layout Standard
28044 You can follow the status of the Subversion version
28045 \begin_inset LatexCommand \index{version}
28046
28047 \end_inset
28048
28049  of SDCC by watching the Changelog
28050 \begin_inset LatexCommand \index{Changelog}
28051
28052 \end_inset
28053
28054  in the Subversion repository
28055 \size footnotesize
28056  
28057 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28058
28059 \end_inset
28060
28061 .
28062
28063 \layout Section
28064 Subversion Source Code Repository
28065
28066 \layout Standard
28067 The output of 
28068 \family sans
28069 \series bold
28070 sdcc --version
28071 \family default
28072 \series default
28073  or the filenames of the snapshot versions of SDCC include date and its
28074  Subversion
28075 \begin_inset LatexCommand \index{Subversion code repository}
28076
28077 \end_inset
28078
28079  number.
28080  Subversion allows to download the source of recent or previous versions
28081  
28082 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28083
28084 \end_inset
28085
28086  (by number or by date).
28087  An on-line source code browser and detailled instructions are also available
28088  there.
28089  SDCC versions starting from 1999 up to now are available (currently the
28090  versions prior to the conversion from cvs
28091 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28092
28093 \end_inset
28094
28095  to Subversion (April 2006) are either by accessible by Subversion or by
28096  cvs).
28097
28098 \layout Section
28099 Release policy
28100 \begin_inset LatexCommand \index{Release policy}
28101
28102 \end_inset
28103
28104
28105
28106 \layout Standard
28107 Historically there often were long delays between official releases and
28108  the sourceforge download area tends to get not updated at all.
28109  Excuses in the past might have referred to problems with live range analysis,
28110  but as this was fixed a while ago, the current problem is that another
28111  excuse has to be found.
28112  Kidding aside, we have to get better there! On the other hand there are
28113  daily snapshots available at 
28114 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
28115
28116 \end_inset
28117
28118 , and you can always build the very last version (hopefully with many bugs
28119  fixed, and features added) from the source code available at 
28120 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
28121
28122 \end_inset
28123
28124 .
28125  A release wiki
28126 \begin_inset LatexCommand \index{wiki}
28127
28128 \end_inset
28129
28130
28131 \begin_inset LatexCommand \index{Release wiki}
28132
28133 \end_inset
28134
28135  at 
28136 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
28137
28138 \end_inset
28139
28140  also holds some information about past and future releases.
28141
28142 \layout Section
28143 Examples
28144 \begin_inset LatexCommand \index{Examples}
28145
28146 \end_inset
28147
28148
28149
28150 \layout Standard
28151 You'll find some small examples in the directory 
28152 \emph on
28153 sdcc/device/examples/.
28154  
28155 \emph default
28156 More examples and libraries are available at
28157 \emph on
28158  The SDCC Open Knowledge Resource 
28159 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
28160
28161 \end_inset
28162
28163  
28164 \emph default
28165 web site or at 
28166 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
28167
28168 \end_inset
28169
28170 .
28171
28172 \layout Standard
28173 \begin_inset Note
28174 collapsed true
28175
28176 \layout Standard
28177 I did insert a reference to Paul's web site here although it seems rather
28178  dedicated to a specific 8032 board (I think it's okay because it f.e.
28179  shows LCD/Harddisc interface and has a free 8051 monitor.
28180  Independent 8032 board vendors face hard competition of heavily subsidized
28181  development boards anyway).
28182
28183 \layout Standard
28184 Maybe we should include some links to real world applications.
28185  Preferably pointer to pointers (one for each architecture) so this stays
28186  manageable here?
28187
28188 \end_inset
28189
28190
28191
28192 \layout Section
28193 Quality control
28194 \begin_inset LatexCommand \label{sec:Quality-control}
28195
28196 \end_inset
28197
28198
28199 \begin_inset LatexCommand \index{Quality control}
28200
28201 \end_inset
28202
28203
28204
28205 \layout Standard
28206 The compiler is passed through nightly compile and build checks.
28207  The so called 
28208 \shape italic
28209 regression tests
28210 \shape default
28211
28212 \begin_inset LatexCommand \index{Regression test}
28213
28214 \end_inset
28215
28216  check that SDCC itself compiles flawlessly on several host platforms (i386,
28217  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
28218  the quality of the code generated by SDCC by running the code for several
28219  target platforms through simulators.
28220  The regression test suite comprises more than 100 files which expand to
28221  more than 500 test cases which include more than 4500 tests.
28222  The results of these tests are published daily on SDCC's snapshot page
28223  (click on the red or green symbols on the right side of 
28224 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
28225
28226 \end_inset
28227
28228 ).
28229
28230 \layout Standard
28231 There is a separate document 
28232 \shape italic
28233 test_suite.pdf 
28234 \begin_inset LatexCommand \index{Test suite}
28235
28236 \end_inset
28237
28238
28239 \shape default
28240  
28241 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28242
28243 \end_inset
28244
28245  about the regression test suite.
28246
28247 \layout Standard
28248 You'll find the test code in the directory 
28249 \shape italic
28250 sdcc/support/regression
28251 \shape default
28252 .
28253  You can run these tests manually by running 
28254 \family sans
28255 make
28256 \family default
28257  in this directory (or f.e.
28258  
28259 \family sans
28260 \series bold
28261
28262 \begin_inset Quotes sld
28263 \end_inset
28264
28265 make test-mcs51
28266 \begin_inset Quotes srd
28267 \end_inset
28268
28269
28270 \family default
28271 \series default
28272  if you don't want to run the complete tests).
28273  The test code might also be interesting if you want to look for examples
28274 \begin_inset LatexCommand \index{Examples}
28275
28276 \end_inset
28277
28278  checking corner cases of SDCC or if you plan to submit patches
28279 \begin_inset LatexCommand \index{Patch submission}
28280
28281 \end_inset
28282
28283 .
28284
28285 \layout Standard
28286 The 14bit pic port uses a different set of regression tests 
28287 \begin_inset LatexCommand \index{Regression test (PIC14)}
28288
28289 \end_inset
28290
28291 , you'll find them in the directory 
28292 \shape italic
28293 sdcc/src/regression
28294 \shape default
28295 .
28296
28297 \layout Section
28298 Use of SDCC in Education
28299
28300 \layout Standard
28301 In short: 
28302 \emph on
28303 highly
28304 \emph default
28305  encouraged
28306 \begin_inset Foot
28307 collapsed false
28308
28309 \layout Standard
28310 the phrase "use in education" might evoke the association "
28311 \emph on
28312 only
28313 \emph default
28314  fit for use in education".
28315  This connotation is not intended but nevertheless risked as the licensing
28316  of SDCC makes it difficult to offer educational discounts
28317
28318 \end_inset
28319
28320 .
28321  If your rationales are to:
28322
28323 \layout Enumerate
28324 give students a chance to understand the 
28325 \emph on
28326 complete
28327 \emph default
28328  steps of code generation
28329
28330 \layout Enumerate
28331 have a curriculum that can be extended for years.
28332  Then you could use an fpga board as target and your curriculum will seamlessly
28333  extend from logic synthesis (
28334 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
28335
28336 \end_inset
28337
28338
28339 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
28340
28341 \end_inset
28342
28343 ), over assembly programming, to C to FPGA compilers (
28344 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
28345
28346 \end_inset
28347
28348 ) and to C.
28349
28350 \layout Enumerate
28351 be able to insert excursions about skills like using a revision control
28352  system, submitting/applying patches, using a type-setting (as opposed to
28353  word-processing) engine LyX/LaTeX, using 
28354 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
28355
28356 \end_inset
28357
28358 , following some 
28359 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
28360
28361 \end_inset
28362
28363 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
28364  Source Software, CPU simulation, compiler regression tests
28365 \begin_inset LatexCommand \index{Regression test}
28366
28367 \end_inset
28368
28369 .
28370  
28371 \newline
28372 And if there should be a shortage of ideas then you can always point students
28373  to the ever-growing feature request list 
28374 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28375
28376 \end_inset
28377
28378 .
28379
28380 \layout Enumerate
28381 not tie students to a specific host platform and instead allow them to use
28382  a host platform of 
28383 \emph on
28384 their
28385 \emph default
28386  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
28387  eventually 
28388 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
28389
28390 \end_inset
28391
28392 )
28393
28394 \layout Enumerate
28395 not encourage students to use illegal copies of educational software
28396
28397 \layout Enumerate
28398 be immune to licensing/availability/price changes of the chosen tool chain
28399
28400 \layout Enumerate
28401 be able to change to a new target platform without having to adopt a new
28402  tool chain
28403
28404 \layout Enumerate
28405 have complete control over and insight into the tool chain
28406
28407 \layout Enumerate
28408 make your students aware about the pros and cons of open source software
28409  development
28410
28411 \layout Enumerate
28412 give back to the public as you are probably at least partially publically
28413  funded
28414
28415 \layout Enumerate
28416 give students a chance to publically prove their skills and to possibly
28417  see a world wide impact
28418
28419 \layout Standard
28420 then SDCC is probably among the first choices.
28421 \pagebreak_bottom 
28422  Well, probably SDCC might be the only choice.
28423
28424
28425 \layout Chapter
28426 SDCC Technical Data
28427
28428 \layout Section
28429 Optimizations
28430 \begin_inset LatexCommand \index{Optimizations}
28431
28432 \end_inset
28433
28434
28435
28436 \layout Standard
28437 SDCC performs a host of standard optimizations in addition to some MCU specific
28438  optimizations.
28439  
28440
28441 \layout Subsection
28442 Sub-expression Elimination
28443 \begin_inset LatexCommand \index{Subexpression elimination}
28444
28445 \end_inset
28446
28447
28448
28449 \layout Standard
28450 The compiler does local and 
28451 \emph on
28452 g
28453 \emph default
28454 lobal 
28455 \emph on
28456 c
28457 \emph default
28458 ommon 
28459 \emph on
28460 s
28461 \emph default
28462 ubexpression 
28463 \emph on
28464 e
28465 \emph default
28466 limination, e.g.: 
28467
28468 \layout Verse
28469
28470 \family typewriter
28471 i = x + y + 1; 
28472 \newline
28473 j = x + y;
28474
28475 \layout Standard
28476 will be translated to
28477
28478 \layout Verse
28479
28480 \family typewriter
28481 iTemp = x + y; 
28482 \newline
28483 i = iTemp + 1; 
28484 \newline
28485 j = iTemp;
28486
28487 \layout Standard
28488 Some subexpressions are not as obvious as the above example, e.g.:
28489
28490 \layout Verse
28491
28492 \family typewriter
28493 a->b[i].c = 10; 
28494 \newline
28495 a->b[i].d = 11;
28496
28497 \layout Standard
28498 In this case the address arithmetic a->b[i] will be computed only once;
28499  the equivalent code in C would be.
28500
28501 \layout Verse
28502
28503 \family typewriter
28504 iTemp = a->b[i]; 
28505 \newline
28506 iTemp.c = 10; 
28507 \newline
28508 iTemp.d = 11;
28509
28510 \layout Standard
28511 The compiler will try to keep these temporary variables in registers.
28512
28513 \layout Subsection
28514 Dead-Code Elimination
28515 \begin_inset LatexCommand \index{Dead-code elimination}
28516
28517 \end_inset
28518
28519
28520
28521 \layout Verse
28522
28523 \family typewriter
28524 int global;
28525 \newline
28526
28527 \newline
28528 void f () { 
28529 \newline
28530 \SpecialChar ~
28531 \SpecialChar ~
28532 int i; 
28533 \newline
28534 \SpecialChar ~
28535 \SpecialChar ~
28536 i = 1; \SpecialChar ~
28537 \SpecialChar ~
28538 \SpecialChar ~
28539 \SpecialChar ~
28540 \SpecialChar ~
28541 /* dead store */ 
28542 \newline
28543 \SpecialChar ~
28544 \SpecialChar ~
28545 global = 1;\SpecialChar ~
28546 /* dead
28547  store */ 
28548 \newline
28549 \SpecialChar ~
28550 \SpecialChar ~
28551 global = 2; 
28552 \newline
28553 \SpecialChar ~
28554 \SpecialChar ~
28555 return; 
28556 \newline
28557 \SpecialChar ~
28558 \SpecialChar ~
28559 global = 3;\SpecialChar ~
28560 /* unreachable */ 
28561 \newline
28562 }
28563
28564 \layout Standard
28565 will be changed to
28566
28567 \layout Verse
28568
28569 \family typewriter
28570 int global;
28571 \newline
28572
28573 \newline
28574 void f () {
28575 \newline
28576 \SpecialChar ~
28577 \SpecialChar ~
28578 global = 2; 
28579 \newline
28580 }
28581
28582 \layout Subsection
28583 Copy-Propagation
28584 \begin_inset LatexCommand \index{Copy propagation}
28585
28586 \end_inset
28587
28588
28589
28590 \layout Verse
28591
28592 \family typewriter
28593 int f() { 
28594 \newline
28595 \SpecialChar ~
28596 \SpecialChar ~
28597 int i, j; 
28598 \newline
28599 \SpecialChar ~
28600 \SpecialChar ~
28601 i = 10; 
28602 \newline
28603 \SpecialChar ~
28604 \SpecialChar ~
28605 j = i; 
28606 \newline
28607 \SpecialChar ~
28608 \SpecialChar ~
28609 return j; 
28610 \newline
28611 }
28612
28613 \layout Standard
28614 will be changed to 
28615
28616 \layout Verse
28617
28618 \family typewriter
28619 int f() { 
28620 \newline
28621 \SpecialChar ~
28622 \SpecialChar ~
28623 int i, j; 
28624 \newline
28625 \SpecialChar ~
28626 \SpecialChar ~
28627 i = 10; 
28628 \newline
28629 \SpecialChar ~
28630 \SpecialChar ~
28631 j = 10; 
28632 \newline
28633 \SpecialChar ~
28634 \SpecialChar ~
28635 return 10; 
28636 \newline
28637 }
28638
28639 \layout Standard
28640 Note: the dead stores created by this copy propagation will be eliminated
28641  by dead-code elimination.
28642
28643 \layout Subsection
28644 Loop Optimizations
28645 \begin_inset LatexCommand \index{Loop optimization}
28646
28647 \end_inset
28648
28649
28650 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
28651
28652 \end_inset
28653
28654
28655
28656 \layout Standard
28657 Two types of loop optimizations are done by SDCC 
28658 \emph on
28659 loop invariant
28660 \emph default
28661  lifting and
28662 \emph on
28663  strength reduction
28664 \emph default
28665  of loop induction variables.
28666  In addition to the strength reduction the optimizer marks the induction
28667  variables and the register allocator tries to keep the induction variables
28668  in registers for the duration of the loop.
28669  Because of this preference of the register allocator
28670 \begin_inset LatexCommand \index{Register allocation}
28671
28672 \end_inset
28673
28674 , loop induction optimization causes an increase in register pressure, which
28675  may cause unwanted spilling of other temporary variables into the stack
28676 \begin_inset LatexCommand \index{stack}
28677
28678 \end_inset
28679
28680  / data space.
28681  The compiler will generate a warning message when it is forced to allocate
28682  extra space either on the stack or data space.
28683  If this extra space allocation is undesirable then induction optimization
28684  can be eliminated either for the entire source file (with -
28685 \begin_inset ERT
28686 status Collapsed
28687
28688 \layout Standard
28689
28690
28691 \backslash
28692 /
28693
28694 \end_inset
28695
28696 -noinduction option) or for a given function only using #pragma\SpecialChar ~
28697 noinduction
28698 \begin_inset LatexCommand \index{\#pragma noinduction}
28699
28700 \end_inset
28701
28702 .
28703 \newline
28704
28705 \newline
28706 Loop Invariant:
28707
28708 \layout Verse
28709
28710 \family typewriter
28711 for (i = 0 ; i < 100 ; i ++) 
28712 \newline
28713 \SpecialChar ~
28714 \SpecialChar ~
28715 \SpecialChar ~
28716 \SpecialChar ~
28717 f += k + l;
28718
28719 \layout Standard
28720 changed to
28721
28722 \layout Verse
28723
28724 \family typewriter
28725 itemp = k + l; 
28726 \newline
28727 for (i = 0; i < 100; i++) 
28728 \newline
28729 \SpecialChar ~
28730 \SpecialChar ~
28731 \SpecialChar ~
28732 \SpecialChar ~
28733 f += itemp;
28734
28735 \layout Standard
28736 As mentioned previously some loop invariants are not as apparent, all static
28737  address computations are also moved out of the loop.
28738 \newline
28739
28740 \newline
28741 Strength Reduction
28742 \begin_inset LatexCommand \index{Strength reduction}
28743
28744 \end_inset
28745
28746 , this optimization substitutes an expression by a cheaper expression:
28747
28748 \layout Verse
28749
28750 \family typewriter
28751 for (i=0;i < 100; i++)
28752 \newline
28753 \SpecialChar ~
28754 \SpecialChar ~
28755 \SpecialChar ~
28756 \SpecialChar ~
28757 ar[i*5] = i*3;
28758
28759 \layout Standard
28760 changed to
28761
28762 \layout Verse
28763
28764 \family typewriter
28765 itemp1 = 0; 
28766 \newline
28767 itemp2 = 0; 
28768 \newline
28769 for (i=0;i< 100;i++) { 
28770 \newline
28771 \SpecialChar ~
28772 \SpecialChar ~
28773 \SpecialChar ~
28774 \SpecialChar ~
28775 ar[itemp1] = itemp2; 
28776 \newline
28777 \SpecialChar ~
28778 \SpecialChar ~
28779 \SpecialChar ~
28780 \SpecialChar ~
28781 itemp1
28782  += 5; 
28783 \newline
28784 \SpecialChar ~
28785 \SpecialChar ~
28786 \SpecialChar ~
28787 \SpecialChar ~
28788 itemp2 += 3; 
28789 \newline
28790 }
28791
28792 \layout Standard
28793 The more expensive multiplication
28794 \begin_inset LatexCommand \index{Multiplication}
28795
28796 \end_inset
28797
28798  is changed to a less expensive addition.
28799
28800 \layout Subsection
28801 Loop Reversing
28802 \begin_inset LatexCommand \index{Loop reversing}
28803
28804 \end_inset
28805
28806
28807
28808 \layout Standard
28809 This optimization is done to reduce the overhead of checking loop boundaries
28810  for every iteration.
28811  Some simple loops can be reversed and implemented using a 
28812 \begin_inset Quotes eld
28813 \end_inset
28814
28815 decrement and jump if not zero
28816 \begin_inset Quotes erd
28817 \end_inset
28818
28819  instruction.
28820  SDCC checks for the following criterion to determine if a loop is reversible
28821  (note: more sophisticated compilers use data-dependency analysis to make
28822  this determination, SDCC uses a more simple minded analysis).
28823
28824 \layout Itemize
28825 The 'for' loop is of the form 
28826 \newline
28827
28828 \newline
28829
28830 \family typewriter
28831 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
28832  += 1])
28833 \newline
28834 \SpecialChar ~
28835 \SpecialChar ~
28836 \SpecialChar ~
28837 \SpecialChar ~
28838 <for body>
28839
28840 \layout Itemize
28841 The <for body> does not contain 
28842 \begin_inset Quotes eld
28843 \end_inset
28844
28845 continue
28846 \begin_inset Quotes erd
28847 \end_inset
28848
28849  or 'break
28850 \begin_inset Quotes erd
28851 \end_inset
28852
28853 .
28854
28855 \layout Itemize
28856 All goto's are contained within the loop.
28857
28858 \layout Itemize
28859 No function calls within the loop.
28860
28861 \layout Itemize
28862 The loop control variable <sym> is not assigned any value within the loop
28863
28864 \layout Itemize
28865 The loop control variable does NOT participate in any arithmetic operation
28866  within the loop.
28867
28868 \layout Itemize
28869 There are NO switch statements in the loop.
28870
28871 \layout Subsection
28872 Algebraic Simplifications
28873
28874 \layout Standard
28875 SDCC does numerous algebraic simplifications, the following is a small sub-set
28876  of these optimizations.
28877
28878 \layout Verse
28879
28880 \family typewriter
28881 i = j + 0;\SpecialChar ~
28882 \SpecialChar ~
28883 \SpecialChar ~
28884 \SpecialChar ~
28885  /* changed to: */\SpecialChar ~
28886 \SpecialChar ~
28887 \SpecialChar ~
28888 \SpecialChar ~
28889  i = j; 
28890 \newline
28891 i /= 2;\SpecialChar ~
28892 \SpecialChar ~
28893 \SpecialChar ~
28894 \SpecialChar ~
28895 \SpecialChar ~
28896 \SpecialChar ~
28897 \SpecialChar ~
28898  /* changed to: */\SpecialChar ~
28899 \SpecialChar ~
28900 \SpecialChar ~
28901 \SpecialChar ~
28902  i >>= 1; 
28903 \newline
28904 i
28905  = j - j;\SpecialChar ~
28906 \SpecialChar ~
28907 \SpecialChar ~
28908 \SpecialChar ~
28909  /* changed to: */\SpecialChar ~
28910 \SpecialChar ~
28911 \SpecialChar ~
28912 \SpecialChar ~
28913  i = 0; 
28914 \newline
28915 i = j / 1;\SpecialChar ~
28916 \SpecialChar ~
28917 \SpecialChar ~
28918 \SpecialChar ~
28919  /* changed to: */\SpecialChar ~
28920 \SpecialChar ~
28921 \SpecialChar ~
28922 \SpecialChar ~
28923  i = j;
28924
28925 \layout Standard
28926 Note the subexpressions
28927 \begin_inset LatexCommand \index{Subexpression}
28928
28929 \end_inset
28930
28931  given above are generally introduced by macro expansions or as a result
28932  of copy/constant propagation.
28933
28934 \layout Subsection
28935 'switch' Statements
28936 \begin_inset LatexCommand \label{sub:'switch'-Statements}
28937
28938 \end_inset
28939
28940
28941 \begin_inset LatexCommand \index{switch statement}
28942
28943 \end_inset
28944
28945
28946
28947 \layout Standard
28948 SDCC can optimize switch statements to jump tables
28949 \begin_inset LatexCommand \index{jump tables}
28950
28951 \end_inset
28952
28953 .
28954  It makes the decision based on an estimate of the generated code size.
28955  SDCC is quite liberal in the requirements for jump table generation: 
28956
28957 \layout Itemize
28958 The labels need not be in order, and the starting number need not be one
28959  or zero, the case labels are in numerical sequence or not too many case
28960  labels are missing.
28961
28962 \begin_deeper
28963 \layout Verse
28964
28965 \family typewriter
28966 switch(i) {\SpecialChar ~
28967 \SpecialChar ~
28968 \SpecialChar ~
28969 \SpecialChar ~
28970 \SpecialChar ~
28971 \SpecialChar ~
28972 \SpecialChar ~
28973 \SpecialChar ~
28974 \SpecialChar ~
28975 \SpecialChar ~
28976 \SpecialChar ~
28977 \SpecialChar ~
28978 \SpecialChar ~
28979 \SpecialChar ~
28980 \SpecialChar ~
28981 \SpecialChar ~
28982 \SpecialChar ~
28983 \SpecialChar ~
28984 \SpecialChar ~
28985 \SpecialChar ~
28986 \SpecialChar ~
28987 \SpecialChar ~
28988 \SpecialChar ~
28989 \SpecialChar ~
28990 \SpecialChar ~
28991 \SpecialChar ~
28992 switch (i) { 
28993 \newline
28994 \SpecialChar ~
28995 \SpecialChar ~
28996 \SpecialChar ~
28997 case 4: ...\SpecialChar ~
28998 \SpecialChar ~
28999 \SpecialChar ~
29000 \SpecialChar ~
29001 \SpecialChar ~
29002 \SpecialChar ~
29003 \SpecialChar ~
29004 \SpecialChar ~
29005 \SpecialChar ~
29006 \SpecialChar ~
29007 \SpecialChar ~
29008 \SpecialChar ~
29009 \SpecialChar ~
29010 \SpecialChar ~
29011 \SpecialChar ~
29012 \SpecialChar ~
29013 \SpecialChar ~
29014 \SpecialChar ~
29015 \SpecialChar ~
29016 \SpecialChar ~
29017 \SpecialChar ~
29018 \SpecialChar ~
29019 \SpecialChar ~
29020 \SpecialChar ~
29021 \SpecialChar ~
29022 \SpecialChar ~
29023 case 0: ...
29024  
29025 \newline
29026 \SpecialChar ~
29027 \SpecialChar ~
29028 \SpecialChar ~
29029 case 5: ...\SpecialChar ~
29030 \SpecialChar ~
29031 \SpecialChar ~
29032 \SpecialChar ~
29033 \SpecialChar ~
29034 \SpecialChar ~
29035 \SpecialChar ~
29036 \SpecialChar ~
29037 \SpecialChar ~
29038 \SpecialChar ~
29039 \SpecialChar ~
29040 \SpecialChar ~
29041 \SpecialChar ~
29042 \SpecialChar ~
29043 \SpecialChar ~
29044 \SpecialChar ~
29045 \SpecialChar ~
29046 \SpecialChar ~
29047 \SpecialChar ~
29048 \SpecialChar ~
29049 \SpecialChar ~
29050 \SpecialChar ~
29051 \SpecialChar ~
29052 \SpecialChar ~
29053 \SpecialChar ~
29054 \SpecialChar ~
29055 case 1: ...
29056  
29057 \newline
29058 \SpecialChar ~
29059 \SpecialChar ~
29060 \SpecialChar ~
29061 case 3: ...\SpecialChar ~
29062 \SpecialChar ~
29063 \SpecialChar ~
29064 \SpecialChar ~
29065 \SpecialChar ~
29066 \SpecialChar ~
29067 \SpecialChar ~
29068 \SpecialChar ~
29069 \SpecialChar ~
29070 \SpecialChar ~
29071 \SpecialChar ~
29072 \SpecialChar ~
29073 \SpecialChar ~
29074 \SpecialChar ~
29075 \SpecialChar ~
29076 \SpecialChar ~
29077 \SpecialChar ~
29078 \SpecialChar ~
29079 \SpecialChar ~
29080 \SpecialChar ~
29081 \SpecialChar ~
29082 \SpecialChar ~
29083 \SpecialChar ~
29084 \SpecialChar ~
29085 \SpecialChar ~
29086 \SpecialChar ~
29087
29088 \newline
29089 \SpecialChar ~
29090 \SpecialChar ~
29091 \SpecialChar ~
29092 case 6: ...\SpecialChar ~
29093 \SpecialChar ~
29094 \SpecialChar ~
29095 \SpecialChar ~
29096 \SpecialChar ~
29097 \SpecialChar ~
29098 \SpecialChar ~
29099 \SpecialChar ~
29100 \SpecialChar ~
29101 \SpecialChar ~
29102 \SpecialChar ~
29103 \SpecialChar ~
29104 \SpecialChar ~
29105 \SpecialChar ~
29106 \SpecialChar ~
29107 \SpecialChar ~
29108 \SpecialChar ~
29109 \SpecialChar ~
29110 \SpecialChar ~
29111 \SpecialChar ~
29112 \SpecialChar ~
29113 \SpecialChar ~
29114 \SpecialChar ~
29115 \SpecialChar ~
29116 \SpecialChar ~
29117 \SpecialChar ~
29118 case 3: ...
29119  
29120 \newline
29121 \SpecialChar ~
29122 \SpecialChar ~
29123 \SpecialChar ~
29124 case 7: ...\SpecialChar ~
29125 \SpecialChar ~
29126 \SpecialChar ~
29127 \SpecialChar ~
29128 \SpecialChar ~
29129 \SpecialChar ~
29130 \SpecialChar ~
29131 \SpecialChar ~
29132 \SpecialChar ~
29133 \SpecialChar ~
29134 \SpecialChar ~
29135 \SpecialChar ~
29136 \SpecialChar ~
29137 \SpecialChar ~
29138 \SpecialChar ~
29139 \SpecialChar ~
29140 \SpecialChar ~
29141 \SpecialChar ~
29142 \SpecialChar ~
29143 \SpecialChar ~
29144 \SpecialChar ~
29145 \SpecialChar ~
29146 \SpecialChar ~
29147 \SpecialChar ~
29148 \SpecialChar ~
29149 \SpecialChar ~
29150 case 4: ...
29151  
29152 \newline
29153 \SpecialChar ~
29154 \SpecialChar ~
29155 \SpecialChar ~
29156 case 8: ...\SpecialChar ~
29157 \SpecialChar ~
29158 \SpecialChar ~
29159 \SpecialChar ~
29160 \SpecialChar ~
29161 \SpecialChar ~
29162 \SpecialChar ~
29163 \SpecialChar ~
29164 \SpecialChar ~
29165 \SpecialChar ~
29166 \SpecialChar ~
29167 \SpecialChar ~
29168 \SpecialChar ~
29169 \SpecialChar ~
29170 \SpecialChar ~
29171 \SpecialChar ~
29172 \SpecialChar ~
29173 \SpecialChar ~
29174 \SpecialChar ~
29175 \SpecialChar ~
29176 \SpecialChar ~
29177 \SpecialChar ~
29178 \SpecialChar ~
29179 \SpecialChar ~
29180 \SpecialChar ~
29181 \SpecialChar ~
29182 case 5: ...
29183  
29184 \newline
29185 \SpecialChar ~
29186 \SpecialChar ~
29187 \SpecialChar ~
29188 case 9: ...\SpecialChar ~
29189 \SpecialChar ~
29190 \SpecialChar ~
29191 \SpecialChar ~
29192 \SpecialChar ~
29193 \SpecialChar ~
29194 \SpecialChar ~
29195 \SpecialChar ~
29196 \SpecialChar ~
29197 \SpecialChar ~
29198 \SpecialChar ~
29199 \SpecialChar ~
29200 \SpecialChar ~
29201 \SpecialChar ~
29202 \SpecialChar ~
29203 \SpecialChar ~
29204 \SpecialChar ~
29205 \SpecialChar ~
29206 \SpecialChar ~
29207 \SpecialChar ~
29208 \SpecialChar ~
29209 \SpecialChar ~
29210 \SpecialChar ~
29211 \SpecialChar ~
29212 \SpecialChar ~
29213 \SpecialChar ~
29214 case 6: ...
29215  
29216 \newline
29217 \SpecialChar ~
29218 \SpecialChar ~
29219 \SpecialChar ~
29220 case 10: ...\SpecialChar ~
29221 \SpecialChar ~
29222 \SpecialChar ~
29223 \SpecialChar ~
29224 \SpecialChar ~
29225 \SpecialChar ~
29226 \SpecialChar ~
29227 \SpecialChar ~
29228 \SpecialChar ~
29229 \SpecialChar ~
29230 \SpecialChar ~
29231 \SpecialChar ~
29232 \SpecialChar ~
29233 \SpecialChar ~
29234 \SpecialChar ~
29235 \SpecialChar ~
29236 \SpecialChar ~
29237 \SpecialChar ~
29238 \SpecialChar ~
29239 \SpecialChar ~
29240 \SpecialChar ~
29241 \SpecialChar ~
29242 \SpecialChar ~
29243 \SpecialChar ~
29244 \SpecialChar ~
29245 case 7: ...
29246  
29247 \newline
29248 \SpecialChar ~
29249 \SpecialChar ~
29250 \SpecialChar ~
29251 case 11: ...\SpecialChar ~
29252 \SpecialChar ~
29253 \SpecialChar ~
29254 \SpecialChar ~
29255 \SpecialChar ~
29256 \SpecialChar ~
29257 \SpecialChar ~
29258 \SpecialChar ~
29259 \SpecialChar ~
29260 \SpecialChar ~
29261 \SpecialChar ~
29262 \SpecialChar ~
29263 \SpecialChar ~
29264 \SpecialChar ~
29265 \SpecialChar ~
29266 \SpecialChar ~
29267 \SpecialChar ~
29268 \SpecialChar ~
29269 \SpecialChar ~
29270 \SpecialChar ~
29271 \SpecialChar ~
29272 \SpecialChar ~
29273 \SpecialChar ~
29274 \SpecialChar ~
29275 \SpecialChar ~
29276 case 8: ...
29277  
29278 \newline
29279 }\SpecialChar ~
29280 \SpecialChar ~
29281 \SpecialChar ~
29282 \SpecialChar ~
29283 \SpecialChar ~
29284 \SpecialChar ~
29285 \SpecialChar ~
29286 \SpecialChar ~
29287 \SpecialChar ~
29288 \SpecialChar ~
29289 \SpecialChar ~
29290 \SpecialChar ~
29291 \SpecialChar ~
29292 \SpecialChar ~
29293 \SpecialChar ~
29294 \SpecialChar ~
29295 \SpecialChar ~
29296 \SpecialChar ~
29297 \SpecialChar ~
29298 \SpecialChar ~
29299 \SpecialChar ~
29300 \SpecialChar ~
29301 \SpecialChar ~
29302 \SpecialChar ~
29303 \SpecialChar ~
29304 \SpecialChar ~
29305 \SpecialChar ~
29306 \SpecialChar ~
29307 \SpecialChar ~
29308 \SpecialChar ~
29309 \SpecialChar ~
29310 \SpecialChar ~
29311 \SpecialChar ~
29312 \SpecialChar ~
29313 \SpecialChar ~
29314 \SpecialChar ~
29315 }
29316
29317 \layout Standard
29318 Both the above switch statements will be implemented using a jump-table.
29319  The example to the right side is slightly more efficient as the check for
29320  the lower boundary of the jump-table is not needed.
29321
29322 \end_deeper
29323 \layout Itemize
29324 The number of case labels is not larger than supported by the target architectur
29325 e.
29326
29327 \layout Itemize
29328 If the case labels are not in numerical sequence ('gaps' between cases)
29329  SDCC checks whether a jump table with additionally inserted dummy cases
29330  is still attractive.
29331  
29332
29333 \layout Itemize
29334 If the starting number is not zero and a check for the lower boundary of
29335  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
29336  ...
29337  .
29338
29339 \layout Standard
29340 Switch statements which have large gaps in the numeric sequence or those
29341  that have too many case labels can be split into more than one switch statement
29342  for efficient code generation, e.g.:
29343
29344 \layout Verse
29345
29346 \family typewriter
29347 switch (i) { 
29348 \newline
29349 \SpecialChar ~
29350 \SpecialChar ~
29351 case 1: ...
29352  
29353 \newline
29354 \SpecialChar ~
29355 \SpecialChar ~
29356 case 2: ...
29357  
29358 \newline
29359 \SpecialChar ~
29360 \SpecialChar ~
29361 case 3: ...
29362  
29363 \newline
29364 \SpecialChar ~
29365 \SpecialChar ~
29366 case 4: ...
29367  
29368 \newline
29369 \SpecialChar ~
29370 \SpecialChar ~
29371 case 5: ...
29372  
29373 \newline
29374 \SpecialChar ~
29375 \SpecialChar ~
29376 case 6: ...
29377  
29378 \newline
29379 \SpecialChar ~
29380 \SpecialChar ~
29381 case 7: ...
29382  
29383 \newline
29384 \SpecialChar ~
29385 \SpecialChar ~
29386 case 101: ...
29387  
29388 \newline
29389 \SpecialChar ~
29390 \SpecialChar ~
29391 case 102: ...
29392  
29393 \newline
29394 \SpecialChar ~
29395 \SpecialChar ~
29396 case 103: ...
29397  
29398 \newline
29399 \SpecialChar ~
29400 \SpecialChar ~
29401 case 104: ...
29402  
29403 \newline
29404 \SpecialChar ~
29405 \SpecialChar ~
29406 case 105: ...
29407  
29408 \newline
29409 \SpecialChar ~
29410 \SpecialChar ~
29411 case 106: ...
29412  
29413 \newline
29414 \SpecialChar ~
29415 \SpecialChar ~
29416 case 107: ...
29417  
29418 \newline
29419 }
29420
29421 \layout Standard
29422 If the above switch statement is broken down into two switch statements
29423
29424 \layout Verse
29425
29426 \family typewriter
29427 switch (i) { 
29428 \newline
29429 \SpecialChar ~
29430 \SpecialChar ~
29431 case 1: ...
29432  
29433 \newline
29434 \SpecialChar ~
29435 \SpecialChar ~
29436 case 2: ...
29437  
29438 \newline
29439 \SpecialChar ~
29440 \SpecialChar ~
29441 case 3: ...
29442  
29443 \newline
29444 \SpecialChar ~
29445 \SpecialChar ~
29446 case 4: ...
29447  
29448 \newline
29449 \SpecialChar ~
29450 \SpecialChar ~
29451 case 5: ...
29452  
29453 \newline
29454 \SpecialChar ~
29455 \SpecialChar ~
29456 case 6: ...
29457  
29458 \newline
29459 \SpecialChar ~
29460 \SpecialChar ~
29461 case 7: ...
29462  
29463 \newline
29464 }
29465
29466 \layout Standard
29467 and
29468
29469 \layout Verse
29470
29471 \family typewriter
29472 switch (i) { 
29473 \newline
29474 \SpecialChar ~
29475 \SpecialChar ~
29476 case 101: ...
29477  
29478 \newline
29479 \SpecialChar ~
29480 \SpecialChar ~
29481 case 102: ...
29482  
29483 \newline
29484 \SpecialChar ~
29485 \SpecialChar ~
29486 case 103: ...
29487  
29488 \newline
29489 \SpecialChar ~
29490 \SpecialChar ~
29491 case 104: ...
29492  
29493 \newline
29494 \SpecialChar ~
29495 \SpecialChar ~
29496 case 105: ...
29497  
29498 \newline
29499 \SpecialChar ~
29500 \SpecialChar ~
29501 case 106: ...
29502  
29503 \newline
29504 \SpecialChar ~
29505 \SpecialChar ~
29506 case 107: ...
29507  
29508 \newline
29509 }
29510
29511 \layout Standard
29512 then both the switch statements will be implemented using jump-tables whereas
29513  the unmodified switch statement will not be.
29514
29515 \layout Standard
29516 \begin_inset Note
29517 collapsed true
29518
29519 \layout Standard
29520 There might be reasons which SDCC cannot know about to either favour or
29521  not favour jump tables.
29522  If the target system has to be as quick for the last switch case as for
29523  the first (pro jump table), or if the switch argument is known to be zero
29524  in the majority of the cases (contra jump table).
29525
29526 \end_inset
29527
29528
29529
29530 \layout Standard
29531 The pragma nojtbound
29532 \begin_inset LatexCommand \index{\#pragma nojtbound}
29533
29534 \end_inset
29535
29536  can be used to turn off checking the 
29537 \emph on
29538 j
29539 \emph default
29540 ump 
29541 \emph on
29542 t
29543 \emph default
29544 able 
29545 \emph on
29546 bound
29547 \emph default
29548 aries.
29549  It has no effect if a default label is supplied.
29550  Use of this pragma is dangerous: if the switch
29551 \begin_inset LatexCommand \index{switch statement}
29552
29553 \end_inset
29554
29555  argument is not matched by a case statement the processor will happily
29556  jump into Nirvana.
29557
29558 \layout Subsection
29559 Bit-shifting Operations
29560 \begin_inset LatexCommand \index{Bit shifting}
29561
29562 \end_inset
29563
29564 .
29565
29566 \layout Standard
29567 Bit shifting is one of the most frequently used operation in embedded programmin
29568 g.
29569  SDCC tries to implement bit-shift operations in the most efficient way
29570  possible, e.g.:
29571
29572 \layout Verse
29573
29574 \family typewriter
29575 unsigned char i;
29576 \newline
29577 ...
29578  
29579 \newline
29580 i >>= 4; 
29581 \newline
29582 ...
29583
29584 \layout Standard
29585 generates the following code:
29586
29587 \layout Verse
29588
29589 \family typewriter
29590 mov\SpecialChar ~
29591  a,_i 
29592 \newline
29593 swap a 
29594 \newline
29595 anl\SpecialChar ~
29596  a,#0x0f 
29597 \newline
29598 mov\SpecialChar ~
29599  _i,a
29600
29601 \layout Standard
29602 In general SDCC will never setup a loop if the shift count is known.
29603  Another example:
29604
29605 \layout Verse
29606
29607 \family typewriter
29608 unsigned int i; 
29609 \newline
29610 ...
29611  
29612 \newline
29613 i >>= 9; 
29614 \newline
29615 ...
29616
29617 \layout Standard
29618 will generate:
29619
29620 \layout Verse
29621
29622 \family typewriter
29623 mov\SpecialChar ~
29624 \SpecialChar ~
29625 a,(_i + 1) 
29626 \newline
29627 mov\SpecialChar ~
29628 \SpecialChar ~
29629 (_i + 1),#0x00 
29630 \newline
29631 clr\SpecialChar ~
29632 \SpecialChar ~
29633
29634 \newline
29635 rrc\SpecialChar ~
29636 \SpecialChar ~
29637
29638 \newline
29639 mov\SpecialChar ~
29640 \SpecialChar ~
29641 _i,a
29642
29643 \layout Subsection
29644 Bit-rotation
29645 \begin_inset LatexCommand \index{Bit rotation}
29646
29647 \end_inset
29648
29649
29650
29651 \layout Standard
29652 A special case of the bit-shift operation is bit rotation
29653 \begin_inset LatexCommand \index{rotating bits}
29654
29655 \end_inset
29656
29657 , SDCC recognizes the following expression to be a left bit-rotation:
29658
29659 \layout Verse
29660
29661 \family typewriter
29662 \series bold
29663 unsigned
29664 \series default
29665 \SpecialChar ~
29666 \SpecialChar ~
29667 char i;\SpecialChar ~
29668 \SpecialChar ~
29669 \SpecialChar ~
29670 \SpecialChar ~
29671 \SpecialChar ~
29672 \SpecialChar ~
29673 \SpecialChar ~
29674 \SpecialChar ~
29675 \SpecialChar ~
29676 \SpecialChar ~
29677 \SpecialChar ~
29678 /* unsigned is needed for rotation */ 
29679 \newline
29680 ...
29681  
29682 \newline
29683 i = ((i << 1) | (i >> 7)); 
29684 \family default
29685
29686 \newline
29687
29688 \family typewriter
29689 ...
29690
29691 \layout Standard
29692 will generate the following code:
29693
29694 \layout Verse
29695
29696 \family typewriter
29697 mov\SpecialChar ~
29698 \SpecialChar ~
29699 a,_i 
29700 \newline
29701 rl\SpecialChar ~
29702 \SpecialChar ~
29703 \SpecialChar ~
29704
29705 \newline
29706 mov\SpecialChar ~
29707 \SpecialChar ~
29708 _i,a
29709
29710 \layout Standard
29711 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
29712 ns of this case will also be recognized as bit-rotation, i.e.: 
29713
29714 \layout Verse
29715
29716 \family typewriter
29717 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
29718
29719 \layout Subsection
29720 Nibble and Byte Swapping
29721
29722 \layout Standard
29723 Other special cases of the bit-shift operations are nibble or byte swapping
29724 \begin_inset LatexCommand \index{swapping nibbles/bytes}
29725
29726 \end_inset
29727
29728 , SDCC recognizes the following expressions:
29729
29730 \layout Verse
29731
29732 \family typewriter
29733 \series bold
29734 unsigned
29735 \series default
29736 \SpecialChar ~
29737 \SpecialChar ~
29738 char i; 
29739 \newline
29740
29741 \series bold
29742 unsigned
29743 \series default
29744 \SpecialChar ~
29745 \SpecialChar ~
29746 int j; 
29747 \newline
29748 ...
29749  
29750 \newline
29751 i = ((i << 4) | (i >> 4)); 
29752 \family default
29753
29754 \newline
29755
29756 \family typewriter
29757 j = ((j << 8) | (j >> 8)); 
29758
29759 \layout Standard
29760 and generates a swap instruction for the nibble swapping
29761 \begin_inset LatexCommand \index{Nibble swapping}
29762
29763 \end_inset
29764
29765  or move instructions for the byte swapping
29766 \begin_inset LatexCommand \index{Byte swapping}
29767
29768 \end_inset
29769
29770 .
29771  The 
29772 \begin_inset Quotes sld
29773 \end_inset
29774
29775 j
29776 \begin_inset Quotes srd
29777 \end_inset
29778
29779  example can be used to convert from little to big-endian or vice versa.
29780  If you want to change the endianness of a 
29781 \emph on
29782 signed
29783 \emph default
29784  integer you have to cast to 
29785 \family typewriter
29786 (unsigned int)
29787 \family default
29788  first.
29789
29790 \layout Standard
29791 Note that SDCC stores numbers in little-endian
29792 \begin_inset Foot
29793 collapsed false
29794
29795 \layout Standard
29796 Usually 8-bit processors don't care much about endianness.
29797  This is not the case for the standard 8051 which only has an instruction
29798  to increment its 
29799 \emph on
29800 dptr
29801 \emph default
29802
29803 \begin_inset LatexCommand \index{DPTR}
29804
29805 \end_inset
29806
29807 -datapointer
29808 \emph on
29809  
29810 \emph default
29811 so little-endian is the more efficient byte order.
29812
29813 \end_inset
29814
29815
29816 \begin_inset LatexCommand \index{little-endian}
29817
29818 \end_inset
29819
29820
29821 \begin_inset LatexCommand \index{Endianness}
29822
29823 \end_inset
29824
29825  format (i.e.
29826  lowest order first).
29827
29828 \layout Subsection
29829 Highest Order Bit
29830 \begin_inset LatexCommand \index{Highest Order Bit}
29831
29832 \end_inset
29833
29834  / Any Order Bit
29835 \begin_inset LatexCommand \index{Any Order Bit}
29836
29837 \end_inset
29838
29839
29840
29841 \layout Standard
29842 It is frequently required to obtain the highest order bit of an integral
29843  type (long, int, short or char types).
29844  Also obtaining any other order bit is not uncommon.
29845  SDCC recognizes the following expressions to yield the highest order bit
29846  and generates optimized code for it, e.g.:
29847
29848 \layout Verse
29849
29850 \family typewriter
29851 unsigned int gint; 
29852 \newline
29853
29854 \newline
29855 foo () { 
29856 \newline
29857 \SpecialChar ~
29858 \SpecialChar ~
29859 unsigned char hob1, aob1; 
29860 \newline
29861 \SpecialChar ~
29862 \SpecialChar ~
29863 bit hob2, hob3, aob2,
29864  aob3; 
29865 \newline
29866 \SpecialChar ~
29867 \SpecialChar ~
29868 ...
29869  
29870 \newline
29871 \SpecialChar ~
29872 \SpecialChar ~
29873 hob1 = (gint >> 15) & 1; 
29874 \newline
29875 \SpecialChar ~
29876 \SpecialChar ~
29877 hob2 = (gint >> 15) & 1; 
29878 \newline
29879 \SpecialChar ~
29880 \SpecialChar ~
29881 hob3 = gint & 0x8000;
29882  
29883 \newline
29884 \SpecialChar ~
29885 \SpecialChar ~
29886 aob1 = (gint >> 9) & 1; 
29887 \newline
29888 \SpecialChar ~
29889 \SpecialChar ~
29890 aob2 = (gint >> 8) & 1; 
29891 \newline
29892 \SpecialChar ~
29893 \SpecialChar ~
29894 aob3 = gint & 0x0800; 
29895 \newline
29896 \SpecialChar ~
29897 \SpecialChar ~
29898 ..
29899  
29900 \newline
29901 }
29902
29903 \layout Standard
29904 will generate the following code:
29905
29906 \layout Verse
29907
29908 \family typewriter
29909 \SpecialChar ~
29910 \SpecialChar ~
29911 \SpecialChar ~
29912 \SpecialChar ~
29913 \SpecialChar ~
29914 \SpecialChar ~
29915 \SpecialChar ~
29916 \SpecialChar ~
29917 \SpecialChar ~
29918 \SpecialChar ~
29919 \SpecialChar ~
29920 \SpecialChar ~
29921 \SpecialChar ~
29922 \SpecialChar ~
29923 \SpecialChar ~
29924 \SpecialChar ~
29925 \SpecialChar ~
29926 \SpecialChar ~
29927 \SpecialChar ~
29928 \SpecialChar ~
29929 \SpecialChar ~
29930 \SpecialChar ~
29931 \SpecialChar ~
29932 \SpecialChar ~
29933 \SpecialChar ~
29934  61 ;\SpecialChar ~
29935  hob.c 7 
29936 \newline
29937 000A E5*01\SpecialChar ~
29938 \SpecialChar ~
29939 \SpecialChar ~
29940 \SpecialChar ~
29941 \SpecialChar ~
29942 \SpecialChar ~
29943 \SpecialChar ~
29944 \SpecialChar ~
29945 \SpecialChar ~
29946 \SpecialChar ~
29947 \SpecialChar ~
29948 \SpecialChar ~
29949 \SpecialChar ~
29950 \SpecialChar ~
29951 \SpecialChar ~
29952  62\SpecialChar ~
29953 \SpecialChar ~
29954 \SpecialChar ~
29955 \SpecialChar ~
29956 \SpecialChar ~
29957 \SpecialChar ~
29958 \SpecialChar ~
29959 \SpecialChar ~
29960  mov\SpecialChar ~
29961 \SpecialChar ~
29962  a,(_gint + 1) 
29963 \newline
29964 000C 23\SpecialChar ~
29965 \SpecialChar ~
29966 \SpecialChar ~
29967 \SpecialChar ~
29968 \SpecialChar ~
29969 \SpecialChar ~
29970 \SpecialChar ~
29971 \SpecialChar ~
29972 \SpecialChar ~
29973 \SpecialChar ~
29974 \SpecialChar ~
29975 \SpecialChar ~
29976 \SpecialChar ~
29977 \SpecialChar ~
29978 \SpecialChar ~
29979 \SpecialChar ~
29980 \SpecialChar ~
29981 \SpecialChar ~
29982  63\SpecialChar ~
29983 \SpecialChar ~
29984 \SpecialChar ~
29985 \SpecialChar ~
29986 \SpecialChar ~
29987 \SpecialChar ~
29988 \SpecialChar ~
29989 \SpecialChar ~
29990  rl\SpecialChar ~
29991 \SpecialChar ~
29992 \SpecialChar ~
29993  a 
29994 \newline
29995 000D 54 01\SpecialChar ~
29996 \SpecialChar ~
29997 \SpecialChar ~
29998 \SpecialChar ~
29999 \SpecialChar ~
30000 \SpecialChar ~
30001 \SpecialChar ~
30002 \SpecialChar ~
30003 \SpecialChar ~
30004 \SpecialChar ~
30005 \SpecialChar ~
30006 \SpecialChar ~
30007 \SpecialChar ~
30008 \SpecialChar ~
30009 \SpecialChar ~
30010
30011  64\SpecialChar ~
30012 \SpecialChar ~
30013 \SpecialChar ~
30014 \SpecialChar ~
30015 \SpecialChar ~
30016 \SpecialChar ~
30017 \SpecialChar ~
30018 \SpecialChar ~
30019  anl\SpecialChar ~
30020 \SpecialChar ~
30021  a,#0x01 
30022 \newline
30023 000F F5*02\SpecialChar ~
30024 \SpecialChar ~
30025 \SpecialChar ~
30026 \SpecialChar ~
30027 \SpecialChar ~
30028 \SpecialChar ~
30029 \SpecialChar ~
30030 \SpecialChar ~
30031 \SpecialChar ~
30032 \SpecialChar ~
30033 \SpecialChar ~
30034 \SpecialChar ~
30035 \SpecialChar ~
30036 \SpecialChar ~
30037 \SpecialChar ~
30038  65\SpecialChar ~
30039 \SpecialChar ~
30040 \SpecialChar ~
30041 \SpecialChar ~
30042 \SpecialChar ~
30043 \SpecialChar ~
30044 \SpecialChar ~
30045 \SpecialChar ~
30046  mov\SpecialChar ~
30047 \SpecialChar ~
30048  _foo_hob1_1_1,a 
30049 \newline
30050 \SpecialChar ~
30051 \SpecialChar ~
30052 \SpecialChar ~
30053 \SpecialChar ~
30054 \SpecialChar ~
30055 \SpecialChar ~
30056 \SpecialChar ~
30057 \SpecialChar ~
30058 \SpecialChar ~
30059 \SpecialChar ~
30060 \SpecialChar ~
30061 \SpecialChar ~
30062 \SpecialChar ~
30063 \SpecialChar ~
30064 \SpecialChar ~
30065 \SpecialChar ~
30066 \SpecialChar ~
30067 \SpecialChar ~
30068 \SpecialChar ~
30069 \SpecialChar ~
30070 \SpecialChar ~
30071 \SpecialChar ~
30072 \SpecialChar ~
30073 \SpecialChar ~
30074 \SpecialChar ~
30075  66 ;\SpecialChar ~
30076  hob.c 8 
30077 \newline
30078 0011 E5*01\SpecialChar ~
30079 \SpecialChar ~
30080 \SpecialChar ~
30081 \SpecialChar ~
30082 \SpecialChar ~
30083 \SpecialChar ~
30084 \SpecialChar ~
30085 \SpecialChar ~
30086 \SpecialChar ~
30087 \SpecialChar ~
30088 \SpecialChar ~
30089 \SpecialChar ~
30090 \SpecialChar ~
30091 \SpecialChar ~
30092 \SpecialChar ~
30093
30094  67\SpecialChar ~
30095 \SpecialChar ~
30096 \SpecialChar ~
30097 \SpecialChar ~
30098 \SpecialChar ~
30099 \SpecialChar ~
30100 \SpecialChar ~
30101 \SpecialChar ~
30102  mov\SpecialChar ~
30103 \SpecialChar ~
30104  a,(_gint + 1) 
30105 \newline
30106 0013 33\SpecialChar ~
30107 \SpecialChar ~
30108 \SpecialChar ~
30109 \SpecialChar ~
30110 \SpecialChar ~
30111 \SpecialChar ~
30112 \SpecialChar ~
30113 \SpecialChar ~
30114 \SpecialChar ~
30115 \SpecialChar ~
30116 \SpecialChar ~
30117 \SpecialChar ~
30118 \SpecialChar ~
30119 \SpecialChar ~
30120 \SpecialChar ~
30121 \SpecialChar ~
30122 \SpecialChar ~
30123 \SpecialChar ~
30124  68\SpecialChar ~
30125 \SpecialChar ~
30126 \SpecialChar ~
30127 \SpecialChar ~
30128 \SpecialChar ~
30129 \SpecialChar ~
30130 \SpecialChar ~
30131 \SpecialChar ~
30132  rlc\SpecialChar ~
30133 \SpecialChar ~
30134  a 
30135 \newline
30136 0014 92*00\SpecialChar ~
30137 \SpecialChar ~
30138 \SpecialChar ~
30139 \SpecialChar ~
30140 \SpecialChar ~
30141 \SpecialChar ~
30142 \SpecialChar ~
30143 \SpecialChar ~
30144 \SpecialChar ~
30145 \SpecialChar ~
30146 \SpecialChar ~
30147 \SpecialChar ~
30148 \SpecialChar ~
30149 \SpecialChar ~
30150 \SpecialChar ~
30151  69\SpecialChar ~
30152 \SpecialChar ~
30153 \SpecialChar ~
30154 \SpecialChar ~
30155 \SpecialChar ~
30156 \SpecialChar ~
30157 \SpecialChar ~
30158 \SpecialChar ~
30159  mov\SpecialChar ~
30160 \SpecialChar ~
30161  _foo_hob2_1_1,c
30162  
30163 \newline
30164 \SpecialChar ~
30165 \SpecialChar ~
30166 \SpecialChar ~
30167 \SpecialChar ~
30168 \SpecialChar ~
30169 \SpecialChar ~
30170 \SpecialChar ~
30171 \SpecialChar ~
30172 \SpecialChar ~
30173 \SpecialChar ~
30174 \SpecialChar ~
30175 \SpecialChar ~
30176 \SpecialChar ~
30177 \SpecialChar ~
30178 \SpecialChar ~
30179 \SpecialChar ~
30180 \SpecialChar ~
30181 \SpecialChar ~
30182 \SpecialChar ~
30183 \SpecialChar ~
30184 \SpecialChar ~
30185 \SpecialChar ~
30186 \SpecialChar ~
30187 \SpecialChar ~
30188 \SpecialChar ~
30189  66 ;\SpecialChar ~
30190  hob.c 9 
30191 \newline
30192 0016 E5*01\SpecialChar ~
30193 \SpecialChar ~
30194 \SpecialChar ~
30195 \SpecialChar ~
30196 \SpecialChar ~
30197 \SpecialChar ~
30198 \SpecialChar ~
30199 \SpecialChar ~
30200 \SpecialChar ~
30201 \SpecialChar ~
30202 \SpecialChar ~
30203 \SpecialChar ~
30204 \SpecialChar ~
30205 \SpecialChar ~
30206 \SpecialChar ~
30207  67\SpecialChar ~
30208 \SpecialChar ~
30209 \SpecialChar ~
30210 \SpecialChar ~
30211 \SpecialChar ~
30212 \SpecialChar ~
30213 \SpecialChar ~
30214 \SpecialChar ~
30215  mov\SpecialChar ~
30216 \SpecialChar ~
30217  a,(_gint + 1) 
30218 \newline
30219 0018 33\SpecialChar ~
30220 \SpecialChar ~
30221 \SpecialChar ~
30222 \SpecialChar ~
30223 \SpecialChar ~
30224 \SpecialChar ~
30225 \SpecialChar ~
30226 \SpecialChar ~
30227 \SpecialChar ~
30228 \SpecialChar ~
30229 \SpecialChar ~
30230 \SpecialChar ~
30231 \SpecialChar ~
30232 \SpecialChar ~
30233 \SpecialChar ~
30234 \SpecialChar ~
30235 \SpecialChar ~
30236 \SpecialChar ~
30237  68\SpecialChar ~
30238 \SpecialChar ~
30239 \SpecialChar ~
30240 \SpecialChar ~
30241 \SpecialChar ~
30242 \SpecialChar ~
30243 \SpecialChar ~
30244 \SpecialChar ~
30245  rlc\SpecialChar ~
30246 \SpecialChar ~
30247  a 
30248 \newline
30249 0019 92*01\SpecialChar ~
30250 \SpecialChar ~
30251 \SpecialChar ~
30252 \SpecialChar ~
30253 \SpecialChar ~
30254 \SpecialChar ~
30255 \SpecialChar ~
30256 \SpecialChar ~
30257 \SpecialChar ~
30258 \SpecialChar ~
30259 \SpecialChar ~
30260 \SpecialChar ~
30261 \SpecialChar ~
30262 \SpecialChar ~
30263 \SpecialChar ~
30264
30265  69\SpecialChar ~
30266 \SpecialChar ~
30267 \SpecialChar ~
30268 \SpecialChar ~
30269 \SpecialChar ~
30270 \SpecialChar ~
30271 \SpecialChar ~
30272 \SpecialChar ~
30273  mov\SpecialChar ~
30274 \SpecialChar ~
30275  _foo_hob3_1_1,c 
30276 \newline
30277 \SpecialChar ~
30278 \SpecialChar ~
30279 \SpecialChar ~
30280 \SpecialChar ~
30281 \SpecialChar ~
30282 \SpecialChar ~
30283 \SpecialChar ~
30284 \SpecialChar ~
30285 \SpecialChar ~
30286 \SpecialChar ~
30287 \SpecialChar ~
30288 \SpecialChar ~
30289 \SpecialChar ~
30290 \SpecialChar ~
30291 \SpecialChar ~
30292 \SpecialChar ~
30293 \SpecialChar ~
30294 \SpecialChar ~
30295 \SpecialChar ~
30296 \SpecialChar ~
30297 \SpecialChar ~
30298 \SpecialChar ~
30299 \SpecialChar ~
30300 \SpecialChar ~
30301 \SpecialChar ~
30302  70 ;\SpecialChar ~
30303  hob.c 10 
30304 \newline
30305 001B E5*01\SpecialChar ~
30306 \SpecialChar ~
30307 \SpecialChar ~
30308 \SpecialChar ~
30309 \SpecialChar ~
30310 \SpecialChar ~
30311 \SpecialChar ~
30312 \SpecialChar ~
30313 \SpecialChar ~
30314 \SpecialChar ~
30315 \SpecialChar ~
30316 \SpecialChar ~
30317 \SpecialChar ~
30318 \SpecialChar ~
30319 \SpecialChar ~
30320  71\SpecialChar ~
30321 \SpecialChar ~
30322 \SpecialChar ~
30323 \SpecialChar ~
30324 \SpecialChar ~
30325 \SpecialChar ~
30326 \SpecialChar ~
30327 \SpecialChar ~
30328  mov\SpecialChar ~
30329 \SpecialChar ~
30330  a,(_gint + 1) 
30331 \newline
30332 001D
30333  03\SpecialChar ~
30334 \SpecialChar ~
30335 \SpecialChar ~
30336 \SpecialChar ~
30337 \SpecialChar ~
30338 \SpecialChar ~
30339 \SpecialChar ~
30340 \SpecialChar ~
30341 \SpecialChar ~
30342 \SpecialChar ~
30343 \SpecialChar ~
30344 \SpecialChar ~
30345 \SpecialChar ~
30346 \SpecialChar ~
30347 \SpecialChar ~
30348 \SpecialChar ~
30349 \SpecialChar ~
30350 \SpecialChar ~
30351  72\SpecialChar ~
30352 \SpecialChar ~
30353 \SpecialChar ~
30354 \SpecialChar ~
30355 \SpecialChar ~
30356 \SpecialChar ~
30357 \SpecialChar ~
30358 \SpecialChar ~
30359  rr\SpecialChar ~
30360 \SpecialChar ~
30361 \SpecialChar ~
30362  a 
30363 \newline
30364 001E 54 01\SpecialChar ~
30365 \SpecialChar ~
30366 \SpecialChar ~
30367 \SpecialChar ~
30368 \SpecialChar ~
30369 \SpecialChar ~
30370 \SpecialChar ~
30371 \SpecialChar ~
30372 \SpecialChar ~
30373 \SpecialChar ~
30374 \SpecialChar ~
30375 \SpecialChar ~
30376 \SpecialChar ~
30377 \SpecialChar ~
30378 \SpecialChar ~
30379  73\SpecialChar ~
30380 \SpecialChar ~
30381 \SpecialChar ~
30382 \SpecialChar ~
30383 \SpecialChar ~
30384 \SpecialChar ~
30385 \SpecialChar ~
30386 \SpecialChar ~
30387  anl\SpecialChar ~
30388 \SpecialChar ~
30389  a,#0x01 
30390 \newline
30391 0020 F5*03\SpecialChar ~
30392 \SpecialChar ~
30393 \SpecialChar ~
30394 \SpecialChar ~
30395 \SpecialChar ~
30396 \SpecialChar ~
30397 \SpecialChar ~
30398 \SpecialChar ~
30399 \SpecialChar ~
30400 \SpecialChar ~
30401 \SpecialChar ~
30402 \SpecialChar ~
30403 \SpecialChar ~
30404 \SpecialChar ~
30405 \SpecialChar ~
30406  74\SpecialChar ~
30407 \SpecialChar ~
30408 \SpecialChar ~
30409 \SpecialChar ~
30410 \SpecialChar ~
30411 \SpecialChar ~
30412 \SpecialChar ~
30413 \SpecialChar ~
30414  mov\SpecialChar ~
30415 \SpecialChar ~
30416  _foo_aob1_1_1,a
30417  
30418 \newline
30419 \SpecialChar ~
30420 \SpecialChar ~
30421 \SpecialChar ~
30422 \SpecialChar ~
30423 \SpecialChar ~
30424 \SpecialChar ~
30425 \SpecialChar ~
30426 \SpecialChar ~
30427 \SpecialChar ~
30428 \SpecialChar ~
30429 \SpecialChar ~
30430 \SpecialChar ~
30431 \SpecialChar ~
30432 \SpecialChar ~
30433 \SpecialChar ~
30434 \SpecialChar ~
30435 \SpecialChar ~
30436 \SpecialChar ~
30437 \SpecialChar ~
30438 \SpecialChar ~
30439 \SpecialChar ~
30440 \SpecialChar ~
30441 \SpecialChar ~
30442 \SpecialChar ~
30443 \SpecialChar ~
30444  75 ;\SpecialChar ~
30445  hob.c 11 
30446 \newline
30447 0022 E5*01\SpecialChar ~
30448 \SpecialChar ~
30449 \SpecialChar ~
30450 \SpecialChar ~
30451 \SpecialChar ~
30452 \SpecialChar ~
30453 \SpecialChar ~
30454 \SpecialChar ~
30455 \SpecialChar ~
30456 \SpecialChar ~
30457 \SpecialChar ~
30458 \SpecialChar ~
30459 \SpecialChar ~
30460 \SpecialChar ~
30461 \SpecialChar ~
30462  76\SpecialChar ~
30463 \SpecialChar ~
30464 \SpecialChar ~
30465 \SpecialChar ~
30466 \SpecialChar ~
30467 \SpecialChar ~
30468 \SpecialChar ~
30469 \SpecialChar ~
30470  mov\SpecialChar ~
30471 \SpecialChar ~
30472  a,(_gint + 1) 
30473 \newline
30474 0024 13\SpecialChar ~
30475 \SpecialChar ~
30476 \SpecialChar ~
30477 \SpecialChar ~
30478 \SpecialChar ~
30479 \SpecialChar ~
30480 \SpecialChar ~
30481 \SpecialChar ~
30482 \SpecialChar ~
30483 \SpecialChar ~
30484 \SpecialChar ~
30485 \SpecialChar ~
30486 \SpecialChar ~
30487 \SpecialChar ~
30488 \SpecialChar ~
30489 \SpecialChar ~
30490 \SpecialChar ~
30491 \SpecialChar ~
30492  77\SpecialChar ~
30493 \SpecialChar ~
30494 \SpecialChar ~
30495 \SpecialChar ~
30496 \SpecialChar ~
30497 \SpecialChar ~
30498 \SpecialChar ~
30499 \SpecialChar ~
30500  rrc\SpecialChar ~
30501 \SpecialChar ~
30502  a 
30503 \newline
30504 0025 92*02\SpecialChar ~
30505 \SpecialChar ~
30506 \SpecialChar ~
30507 \SpecialChar ~
30508 \SpecialChar ~
30509 \SpecialChar ~
30510 \SpecialChar ~
30511 \SpecialChar ~
30512 \SpecialChar ~
30513 \SpecialChar ~
30514 \SpecialChar ~
30515 \SpecialChar ~
30516 \SpecialChar ~
30517 \SpecialChar ~
30518 \SpecialChar ~
30519
30520  78\SpecialChar ~
30521 \SpecialChar ~
30522 \SpecialChar ~
30523 \SpecialChar ~
30524 \SpecialChar ~
30525 \SpecialChar ~
30526 \SpecialChar ~
30527 \SpecialChar ~
30528  mov\SpecialChar ~
30529 \SpecialChar ~
30530  _foo_aob2_1_1,c 
30531 \newline
30532 \SpecialChar ~
30533 \SpecialChar ~
30534 \SpecialChar ~
30535 \SpecialChar ~
30536 \SpecialChar ~
30537 \SpecialChar ~
30538 \SpecialChar ~
30539 \SpecialChar ~
30540 \SpecialChar ~
30541 \SpecialChar ~
30542 \SpecialChar ~
30543 \SpecialChar ~
30544 \SpecialChar ~
30545 \SpecialChar ~
30546 \SpecialChar ~
30547 \SpecialChar ~
30548 \SpecialChar ~
30549 \SpecialChar ~
30550 \SpecialChar ~
30551 \SpecialChar ~
30552 \SpecialChar ~
30553 \SpecialChar ~
30554 \SpecialChar ~
30555 \SpecialChar ~
30556 \SpecialChar ~
30557  79 ;\SpecialChar ~
30558  hob.c 12 
30559 \newline
30560 0027 E5*01\SpecialChar ~
30561 \SpecialChar ~
30562 \SpecialChar ~
30563 \SpecialChar ~
30564 \SpecialChar ~
30565 \SpecialChar ~
30566 \SpecialChar ~
30567 \SpecialChar ~
30568 \SpecialChar ~
30569 \SpecialChar ~
30570 \SpecialChar ~
30571 \SpecialChar ~
30572 \SpecialChar ~
30573 \SpecialChar ~
30574 \SpecialChar ~
30575  80\SpecialChar ~
30576 \SpecialChar ~
30577 \SpecialChar ~
30578 \SpecialChar ~
30579 \SpecialChar ~
30580 \SpecialChar ~
30581 \SpecialChar ~
30582 \SpecialChar ~
30583  mov\SpecialChar ~
30584 \SpecialChar ~
30585  a,(_gint + 1) 
30586 \newline
30587 0029
30588  A2 E3\SpecialChar ~
30589 \SpecialChar ~
30590 \SpecialChar ~
30591 \SpecialChar ~
30592 \SpecialChar ~
30593 \SpecialChar ~
30594 \SpecialChar ~
30595 \SpecialChar ~
30596 \SpecialChar ~
30597 \SpecialChar ~
30598 \SpecialChar ~
30599 \SpecialChar ~
30600 \SpecialChar ~
30601 \SpecialChar ~
30602 \SpecialChar ~
30603  81\SpecialChar ~
30604 \SpecialChar ~
30605 \SpecialChar ~
30606 \SpecialChar ~
30607 \SpecialChar ~
30608 \SpecialChar ~
30609 \SpecialChar ~
30610 \SpecialChar ~
30611  mov\SpecialChar ~
30612 \SpecialChar ~
30613  c,acc[3] 
30614 \newline
30615 002B 92*03\SpecialChar ~
30616 \SpecialChar ~
30617 \SpecialChar ~
30618 \SpecialChar ~
30619 \SpecialChar ~
30620 \SpecialChar ~
30621 \SpecialChar ~
30622 \SpecialChar ~
30623 \SpecialChar ~
30624 \SpecialChar ~
30625 \SpecialChar ~
30626 \SpecialChar ~
30627 \SpecialChar ~
30628 \SpecialChar ~
30629 \SpecialChar ~
30630  82\SpecialChar ~
30631 \SpecialChar ~
30632 \SpecialChar ~
30633 \SpecialChar ~
30634 \SpecialChar ~
30635 \SpecialChar ~
30636 \SpecialChar ~
30637 \SpecialChar ~
30638  mov\SpecialChar ~
30639 \SpecialChar ~
30640  _foo_aob3_1_1,c 
30641
30642 \layout Standard
30643 Other variations of these cases however will 
30644 \emph on
30645 not
30646 \emph default
30647  be recognized.
30648  They are standard C expressions, so I heartily recommend these be the only
30649  way to get the highest order bit, (it is portable).
30650  Of course it will be recognized even if it is embedded in other expressions,
30651  e.g.:
30652
30653 \layout Verse
30654
30655 \family typewriter
30656 xyz = gint + ((gint >> 15) & 1);
30657
30658 \layout Standard
30659 will still be recognized.
30660
30661 \layout Subsection
30662 Higher Order Byte
30663 \begin_inset LatexCommand \index{Higher Order Byte}
30664
30665 \end_inset
30666
30667  / Higher Order Word
30668 \begin_inset LatexCommand \index{Higher Order Word}
30669
30670 \end_inset
30671
30672
30673
30674 \layout Standard
30675 It is also frequently required to obtain a higher order byte or word of
30676  a larger integral type (long, int or short types).
30677  SDCC recognizes the following expressions to yield the higher order byte
30678  or word and generates optimized code for it, e.g.:
30679
30680 \layout Verse
30681
30682 \family typewriter
30683 unsigned int gint; 
30684 \newline
30685 unsigned long int glong; 
30686 \newline
30687
30688 \newline
30689 foo () { 
30690 \newline
30691 \SpecialChar ~
30692 \SpecialChar ~
30693 unsigned char hob1,
30694  hob2; 
30695 \newline
30696 \SpecialChar ~
30697 \SpecialChar ~
30698 unsigned int how1, how2; 
30699 \newline
30700 \SpecialChar ~
30701 \SpecialChar ~
30702 ...
30703  
30704 \newline
30705 \SpecialChar ~
30706 \SpecialChar ~
30707 hob1 = (gint >> 8) & 0xFF; 
30708 \newline
30709 \SpecialChar ~
30710 \SpecialChar ~
30711 hob2 = glong >> 24; 
30712 \newline
30713 \SpecialChar ~
30714 \SpecialChar ~
30715 how1 = (glong >> 16) & 0xFFFF;
30716  
30717 \newline
30718 \SpecialChar ~
30719 \SpecialChar ~
30720 how2 = glong >> 8; 
30721 \newline
30722 \SpecialChar ~
30723 \SpecialChar ~
30724 ..
30725  
30726 \newline
30727 }
30728
30729 \layout Standard
30730 will generate the following code:
30731
30732 \layout Verse
30733
30734 \family typewriter
30735 \SpecialChar ~
30736 \SpecialChar ~
30737 \SpecialChar ~
30738 \SpecialChar ~
30739 \SpecialChar ~
30740 \SpecialChar ~
30741 \SpecialChar ~
30742 \SpecialChar ~
30743 \SpecialChar ~
30744 \SpecialChar ~
30745 \SpecialChar ~
30746 \SpecialChar ~
30747 \SpecialChar ~
30748 \SpecialChar ~
30749 \SpecialChar ~
30750 \SpecialChar ~
30751 \SpecialChar ~
30752 \SpecialChar ~
30753 \SpecialChar ~
30754 \SpecialChar ~
30755 \SpecialChar ~
30756 \SpecialChar ~
30757 \SpecialChar ~
30758 \SpecialChar ~
30759 \SpecialChar ~
30760  91 ;\SpecialChar ~
30761  hob.c 15 
30762 \newline
30763 0037 85*01*06\SpecialChar ~
30764 \SpecialChar ~
30765 \SpecialChar ~
30766 \SpecialChar ~
30767 \SpecialChar ~
30768 \SpecialChar ~
30769 \SpecialChar ~
30770 \SpecialChar ~
30771 \SpecialChar ~
30772 \SpecialChar ~
30773 \SpecialChar ~
30774 \SpecialChar ~
30775  92\SpecialChar ~
30776 \SpecialChar ~
30777 \SpecialChar ~
30778 \SpecialChar ~
30779 \SpecialChar ~
30780 \SpecialChar ~
30781 \SpecialChar ~
30782 \SpecialChar ~
30783  mov\SpecialChar ~
30784 \SpecialChar ~
30785  _foo_hob1_1_1,(_gint + 1) 
30786 \newline
30787 \SpecialChar ~
30788 \SpecialChar ~
30789 \SpecialChar ~
30790 \SpecialChar ~
30791 \SpecialChar ~
30792 \SpecialChar ~
30793 \SpecialChar ~
30794 \SpecialChar ~
30795 \SpecialChar ~
30796 \SpecialChar ~
30797 \SpecialChar ~
30798 \SpecialChar ~
30799 \SpecialChar ~
30800 \SpecialChar ~
30801 \SpecialChar ~
30802 \SpecialChar ~
30803 \SpecialChar ~
30804 \SpecialChar ~
30805 \SpecialChar ~
30806 \SpecialChar ~
30807 \SpecialChar ~
30808 \SpecialChar ~
30809 \SpecialChar ~
30810 \SpecialChar ~
30811 \SpecialChar ~
30812  93 ;\SpecialChar ~
30813  hob.c
30814  16 
30815 \newline
30816 003A 85*05*07\SpecialChar ~
30817 \SpecialChar ~
30818 \SpecialChar ~
30819 \SpecialChar ~
30820 \SpecialChar ~
30821 \SpecialChar ~
30822 \SpecialChar ~
30823 \SpecialChar ~
30824 \SpecialChar ~
30825 \SpecialChar ~
30826 \SpecialChar ~
30827 \SpecialChar ~
30828  94\SpecialChar ~
30829 \SpecialChar ~
30830 \SpecialChar ~
30831 \SpecialChar ~
30832 \SpecialChar ~
30833 \SpecialChar ~
30834 \SpecialChar ~
30835 \SpecialChar ~
30836  mov\SpecialChar ~
30837 \SpecialChar ~
30838  _foo_hob2_1_1,(_glong + 3) 
30839 \newline
30840 \SpecialChar ~
30841 \SpecialChar ~
30842 \SpecialChar ~
30843 \SpecialChar ~
30844 \SpecialChar ~
30845 \SpecialChar ~
30846 \SpecialChar ~
30847 \SpecialChar ~
30848 \SpecialChar ~
30849 \SpecialChar ~
30850 \SpecialChar ~
30851 \SpecialChar ~
30852 \SpecialChar ~
30853 \SpecialChar ~
30854 \SpecialChar ~
30855 \SpecialChar ~
30856 \SpecialChar ~
30857 \SpecialChar ~
30858 \SpecialChar ~
30859 \SpecialChar ~
30860 \SpecialChar ~
30861 \SpecialChar ~
30862 \SpecialChar ~
30863 \SpecialChar ~
30864 \SpecialChar ~
30865  95 ;\SpecialChar ~
30866  hob.c 17 
30867 \newline
30868 003D 85*04*08\SpecialChar ~
30869 \SpecialChar ~
30870 \SpecialChar ~
30871 \SpecialChar ~
30872 \SpecialChar ~
30873 \SpecialChar ~
30874 \SpecialChar ~
30875 \SpecialChar ~
30876 \SpecialChar ~
30877 \SpecialChar ~
30878 \SpecialChar ~
30879 \SpecialChar ~
30880
30881  96\SpecialChar ~
30882 \SpecialChar ~
30883 \SpecialChar ~
30884 \SpecialChar ~
30885 \SpecialChar ~
30886 \SpecialChar ~
30887 \SpecialChar ~
30888 \SpecialChar ~
30889  mov\SpecialChar ~
30890 \SpecialChar ~
30891  _foo_how1_1_1,(_glong + 2) 
30892 \newline
30893 0040 85*05*09\SpecialChar ~
30894 \SpecialChar ~
30895 \SpecialChar ~
30896 \SpecialChar ~
30897 \SpecialChar ~
30898 \SpecialChar ~
30899 \SpecialChar ~
30900 \SpecialChar ~
30901 \SpecialChar ~
30902 \SpecialChar ~
30903 \SpecialChar ~
30904 \SpecialChar ~
30905  97\SpecialChar ~
30906 \SpecialChar ~
30907 \SpecialChar ~
30908 \SpecialChar ~
30909 \SpecialChar ~
30910 \SpecialChar ~
30911 \SpecialChar ~
30912 \SpecialChar ~
30913  mov\SpecialChar ~
30914 \SpecialChar ~
30915  (_foo_how1_1_1 +
30916  1),(_glong + 3) 
30917 \newline
30918 0043 85*03*0A\SpecialChar ~
30919 \SpecialChar ~
30920 \SpecialChar ~
30921 \SpecialChar ~
30922 \SpecialChar ~
30923 \SpecialChar ~
30924 \SpecialChar ~
30925 \SpecialChar ~
30926 \SpecialChar ~
30927 \SpecialChar ~
30928 \SpecialChar ~
30929 \SpecialChar ~
30930  98\SpecialChar ~
30931 \SpecialChar ~
30932 \SpecialChar ~
30933 \SpecialChar ~
30934 \SpecialChar ~
30935 \SpecialChar ~
30936 \SpecialChar ~
30937 \SpecialChar ~
30938  mov\SpecialChar ~
30939 \SpecialChar ~
30940  _foo_how2_1_1,(_glong + 1) 
30941 \newline
30942 0046 85*04*0B\SpecialChar ~
30943 \SpecialChar ~
30944 \SpecialChar ~
30945 \SpecialChar ~
30946 \SpecialChar ~
30947 \SpecialChar ~
30948 \SpecialChar ~
30949 \SpecialChar ~
30950 \SpecialChar ~
30951 \SpecialChar ~
30952 \SpecialChar ~
30953 \SpecialChar ~
30954
30955  99\SpecialChar ~
30956 \SpecialChar ~
30957 \SpecialChar ~
30958 \SpecialChar ~
30959 \SpecialChar ~
30960 \SpecialChar ~
30961 \SpecialChar ~
30962 \SpecialChar ~
30963  mov\SpecialChar ~
30964 \SpecialChar ~
30965  (_foo_how2_1_1 + 1),(_glong + 2) 
30966
30967 \layout Standard
30968 Again, variations of these cases may 
30969 \emph on
30970 not
30971 \emph default
30972  be recognized.
30973  They are standard C expressions, so I heartily recommend these be the only
30974  way to get the higher order byte/word, (it is portable).
30975  Of course it will be recognized even if it is embedded in other expressions,
30976  e.g.:
30977
30978 \layout Verse
30979
30980 \family typewriter
30981 xyz = gint + ((gint >> 8) & 0xFF);
30982
30983 \layout Standard
30984 will still be recognized.
30985
30986 \layout Subsection
30987 Peephole Optimizer
30988 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
30989
30990 \end_inset
30991
30992
30993 \begin_inset LatexCommand \index{Peephole optimizer}
30994
30995 \end_inset
30996
30997
30998
30999 \layout Standard
31000 The compiler uses a rule based, pattern matching and re-writing mechanism
31001  for peep-hole optimization.
31002  It is inspired by 
31003 \emph on
31004 copt
31005 \emph default
31006  a peep-hole optimizer by Christopher W.
31007  Fraser (cwfraser\SpecialChar ~
31008 @\SpecialChar ~
31009 microsoft.com).
31010  A default set of rules are compiled into the compiler, additional rules
31011  may be added with the 
31012 \emph on
31013 -
31014 \begin_inset ERT
31015 status Collapsed
31016
31017 \layout Standard
31018
31019
31020 \backslash
31021 /
31022
31023 \end_inset
31024
31025 -peep-file
31026 \begin_inset LatexCommand \index{-\/-peep-file}
31027
31028 \end_inset
31029
31030  <filename>
31031 \emph default
31032  option.
31033  The rule language is best illustrated with examples.
31034
31035 \layout Verse
31036
31037 \family typewriter
31038 replace { 
31039 \newline
31040 \SpecialChar ~
31041 \SpecialChar ~
31042 mov %1,a 
31043 \newline
31044 \SpecialChar ~
31045 \SpecialChar ~
31046 mov a,%1
31047 \newline
31048 } by {
31049 \newline
31050 \SpecialChar ~
31051 \SpecialChar ~
31052 mov %1,a
31053 \newline
31054 }
31055
31056 \layout Standard
31057 The above rule will change the following assembly
31058 \begin_inset LatexCommand \index{Assembler routines}
31059
31060 \end_inset
31061
31062  sequence:
31063
31064 \layout Verse
31065
31066 \family typewriter
31067 mov r1,a 
31068 \newline
31069 mov a,r1
31070
31071 \layout Standard
31072 to
31073
31074 \layout Verse
31075
31076 \family typewriter
31077 mov r1,a
31078
31079 \layout Standard
31080 Note: All occurrences of a 
31081 \emph on
31082 %n
31083 \emph default
31084  (pattern variable) must denote the same string.
31085  With the above rule, the assembly sequence:
31086
31087 \layout Verse
31088
31089 \family typewriter
31090 mov r1,a 
31091 \newline
31092 mov a,r2
31093
31094 \layout Standard
31095 will remain unmodified.
31096 \newline
31097
31098 \newline
31099 Other special case optimizations may be added by the
31100  user (via 
31101 \emph on
31102 -
31103 \begin_inset ERT
31104 status Collapsed
31105
31106 \layout Standard
31107
31108
31109 \backslash
31110 /
31111
31112 \end_inset
31113
31114 -peep-file option
31115 \emph default
31116 ).
31117  E.g.
31118  some variants of the 8051 MCU
31119 \begin_inset LatexCommand \index{MCS51 variants}
31120
31121 \end_inset
31122
31123  allow only 
31124 \family typewriter
31125 ajmp
31126 \family default
31127  and 
31128 \family typewriter
31129 acall
31130 \family default
31131 .
31132  The following two rules will change all 
31133 \family typewriter
31134 ljmp
31135 \family default
31136  and 
31137 \family typewriter
31138 lcall
31139 \family default
31140  to 
31141 \family typewriter
31142 ajmp
31143 \family default
31144  and 
31145 \family typewriter
31146 acall
31147
31148 \layout Verse
31149
31150 \family typewriter
31151 replace { lcall %1 } by { acall %1 } 
31152 \newline
31153 replace { ljmp %1 } by { ajmp %1 }
31154
31155 \layout Standard
31156 The 
31157 \emph on
31158 inline-assembler code
31159 \emph default
31160  is also passed through the peep hole optimizer, thus the peephole optimizer
31161  can also be used as an assembly level macro expander.
31162  The rules themselves are MCU dependent whereas the rule language infra-structur
31163 e is MCU independent.
31164  Peephole optimization rules for other MCU can be easily programmed using
31165  the rule language.
31166 \newline
31167
31168 \newline
31169 The syntax for a rule is as follows:
31170
31171 \layout Verse
31172
31173 \family typewriter
31174 rule := replace [ restart ] '{' <assembly sequence> '
31175 \backslash
31176 n' 
31177 \newline
31178 \SpecialChar ~
31179  \SpecialChar ~
31180  \SpecialChar ~
31181  \SpecialChar ~
31182  \SpecialChar ~
31183  \SpecialChar ~
31184  \SpecialChar ~
31185  \SpecialChar ~
31186  \SpecialChar ~
31187  \SpecialChar ~
31188  \SpecialChar ~
31189  \SpecialChar ~
31190  \SpecialChar ~
31191  \SpecialChar ~
31192  '}' by '{' '
31193 \backslash
31194 n' 
31195 \newline
31196 \SpecialChar ~
31197  \SpecialChar ~
31198  \SpecialChar ~
31199  \SpecialChar ~
31200  \SpecialChar ~
31201  \SpecialChar ~
31202  \SpecialChar ~
31203  \SpecialChar ~
31204  \SpecialChar ~
31205  \SpecialChar ~
31206  \SpecialChar ~
31207  \SpecialChar ~
31208  \SpecialChar ~
31209  \SpecialChar ~
31210  \SpecialChar ~
31211  \SpecialChar ~
31212  <assembly sequence> '
31213 \backslash
31214 n' 
31215 \newline
31216 \SpecialChar ~
31217  \SpecialChar ~
31218  \SpecialChar ~
31219  \SpecialChar ~
31220  \SpecialChar ~
31221  \SpecialChar ~
31222  \SpecialChar ~
31223  \SpecialChar ~
31224  \SpecialChar ~
31225  \SpecialChar ~
31226  \SpecialChar ~
31227  \SpecialChar ~
31228  \SpecialChar ~
31229  \SpecialChar ~
31230  '}' [if <functionName> ] '
31231 \backslash
31232 n' 
31233
31234 \layout Standard
31235 <assembly sequence> := assembly instruction (each instruction including
31236  labels must be on a separate line).
31237 \newline
31238
31239 \newline
31240 The optimizer will apply to the rules
31241  one by one from the top in the sequence of their appearance, it will terminate
31242  when all rules are exhausted.
31243  If the 'restart' option is specified, then the optimizer will start matching
31244  the rules again from the top, this option for a rule is expensive (performance)
31245 , it is intended to be used in situations where a transformation will trigger
31246  the same rule again.
31247  An example of this (not a good one, it has side effects) is the following
31248  rule:
31249
31250 \layout Verse
31251
31252 \family typewriter
31253 replace restart { 
31254 \newline
31255 \SpecialChar ~
31256 \SpecialChar ~
31257 pop %1 
31258 \newline
31259 \SpecialChar ~
31260 \SpecialChar ~
31261 push %1 } by { 
31262 \newline
31263 \SpecialChar ~
31264 \SpecialChar ~
31265 ; nop 
31266 \newline
31267 }
31268
31269 \layout Standard
31270 Note that the replace pattern cannot be a blank, but can be a comment line.
31271  Without the 'restart' option only the innermost 'pop' 'push' pair would
31272  be eliminated, i.e.:
31273
31274 \layout Verse
31275
31276 \family typewriter
31277 pop ar1 
31278 \newline
31279 pop ar2 
31280 \newline
31281 push ar2 
31282 \newline
31283 push ar1
31284
31285 \layout Standard
31286 would result in:
31287
31288 \layout Verse
31289
31290 \family typewriter
31291 pop ar1 
31292 \newline
31293 ; nop 
31294 \newline
31295 push ar1
31296
31297 \layout Standard
31298
31299 \emph on
31300 with
31301 \emph default
31302  the restart option the rule will be applied again to the resulting code
31303  and then all the pop-push pairs will be eliminated to yield:
31304
31305 \layout Verse
31306
31307 \family typewriter
31308 ; nop 
31309 \newline
31310 ; nop
31311
31312 \layout Standard
31313 A conditional function can be attached to a rule.
31314  Attaching rules are somewhat more involved, let me illustrate this with
31315  an example.
31316
31317 \layout Verse
31318
31319 \family typewriter
31320 replace { 
31321 \newline
31322 \SpecialChar ~
31323  \SpecialChar ~
31324  \SpecialChar ~
31325 ljmp %5 
31326 \newline
31327 %2:
31328 \newline
31329 } by { 
31330 \newline
31331 \SpecialChar ~
31332  \SpecialChar ~
31333  \SpecialChar ~
31334 sjmp %5 
31335 \newline
31336 %2:
31337 \newline
31338 } if labelInRange
31339
31340 \layout Standard
31341 The optimizer does a look-up of a function name table defined in function
31342  
31343 \emph on
31344 callFuncByName
31345 \emph default
31346  in the source file SDCCpeeph.c, with the name 
31347 \emph on
31348 labelInRange
31349 \emph default
31350 .
31351  If it finds a corresponding entry the function is called.
31352  Note there can be no parameters specified for these functions, in this
31353  case the use of 
31354 \emph on
31355 %5
31356 \emph default
31357  is crucial, since the function 
31358 \emph on
31359 labelInRange
31360 \emph default
31361  expects to find the label in that particular variable (the hash table containin
31362 g the variable bindings is passed as a parameter).
31363  If you want to code more such functions, take a close look at the function
31364  labelInRange and the calling mechanism in source file SDCCpeeph.c.
31365  Currently implemented are 
31366 \emph on
31367 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
31368  24bitMode, portIsDS390, 24bitModeAndPortDS390 
31369 \emph default
31370 and
31371 \emph on
31372  notVolatile
31373 \emph default
31374 .
31375
31376 \layout Standard
31377 I know this whole thing is a little kludgey, but maybe some day we will
31378  have some better means.
31379  If you are looking at this file, you will see the default rules that are
31380  compiled into the compiler, you can add your own rules in the default set
31381  there if you get tired of specifying the -
31382 \begin_inset ERT
31383 status Collapsed
31384
31385 \layout Standard
31386
31387
31388 \backslash
31389 /
31390
31391 \end_inset
31392
31393 -peep-file option.
31394
31395 \layout Section
31396 ANSI-Compliance
31397 \begin_inset LatexCommand \index{ANSI-compliance}
31398
31399 \end_inset
31400
31401
31402 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
31403
31404 \end_inset
31405
31406
31407
31408 \layout Standard
31409 The latest publically available version of the standard 
31410 \emph on
31411 ISO/IEC 9899 - Programming languages - C
31412 \emph default
31413  should be available at: 
31414 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31415
31416 \end_inset
31417
31418 .
31419 \newline
31420
31421
31422 \layout Standard
31423 Deviations from the compliance:
31424
31425 \layout Itemize
31426 functions are not reentrant
31427 \begin_inset LatexCommand \index{reentrant}
31428
31429 \end_inset
31430
31431  unless explicitly declared as such or the 
31432 \series bold
31433 -
31434 \begin_inset ERT
31435 status Collapsed
31436
31437 \layout Standard
31438
31439
31440 \backslash
31441 /
31442
31443 \end_inset
31444
31445 -stack-auto
31446 \begin_inset LatexCommand \index{-\/-stack-auto}
31447
31448 \end_inset
31449
31450
31451 \series default
31452  command line option is specified.
31453
31454 \layout Itemize
31455 structures
31456 \begin_inset LatexCommand \index{struct}
31457
31458 \end_inset
31459
31460  and unions
31461 \begin_inset LatexCommand \index{union}
31462
31463 \end_inset
31464
31465  cannot be assigned values directly, cannot be passed as function parameters
31466  or assigned to each other and cannot be a return value
31467 \begin_inset LatexCommand \index{return value}
31468
31469 \end_inset
31470
31471  from a function, e.g.:
31472
31473 \begin_deeper
31474 \layout Verse
31475
31476 \family typewriter
31477 struct s { ...
31478  }; 
31479 \newline
31480 struct s s1, s2; 
31481 \newline
31482 foo() 
31483 \newline
31484
31485 \newline
31486 \SpecialChar ~
31487 \SpecialChar ~
31488 \SpecialChar ~
31489 \SpecialChar ~
31490 ...
31491  
31492 \newline
31493 \SpecialChar ~
31494 \SpecialChar ~
31495 \SpecialChar ~
31496 \SpecialChar ~
31497 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
31498 \newline
31499 \SpecialChar ~
31500 \SpecialChar ~
31501 \SpecialChar ~
31502 \SpecialChar ~
31503 ...
31504  
31505 \newline
31506 }
31507 \newline
31508
31509 \series bold
31510 struct
31511 \series default
31512  s foo1 (
31513 \series bold
31514 struct
31515 \series default
31516  s parms) /* invalid in SDCC although allowed in ANSI */
31517 \newline
31518
31519 \newline
31520 \SpecialChar ~
31521 \SpecialChar ~
31522 \SpecialChar ~
31523 \SpecialChar ~
31524 struct s rets;
31525  
31526 \newline
31527 \SpecialChar ~
31528 \SpecialChar ~
31529 \SpecialChar ~
31530 \SpecialChar ~
31531 ...
31532  
31533 \newline
31534 \SpecialChar ~
31535 \SpecialChar ~
31536 \SpecialChar ~
31537 \SpecialChar ~
31538 return rets; /* is invalid in SDCC although allowed in ANSI */ 
31539 \newline
31540 }
31541
31542 \end_deeper
31543 \layout Itemize
31544 initialization of structure arrays must be fully braced.
31545
31546 \begin_deeper
31547 \layout Verse
31548
31549 \family typewriter
31550 struct s { char x } a[] = {1, 2};\SpecialChar ~
31551 \SpecialChar ~
31552 \SpecialChar ~
31553 \SpecialChar ~
31554 \SpecialChar ~
31555 /* invalid in SDCC */
31556 \newline
31557 struct s { char x
31558  } a[] = {{1}, {2}}; /* OK */
31559
31560 \end_deeper
31561 \layout Itemize
31562 'long long
31563 \begin_inset LatexCommand \index{long long (not supported)}
31564
31565 \end_inset
31566
31567 ' (64 bit integers
31568 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
31569
31570 \end_inset
31571
31572 ) not supported.
31573
31574 \layout Itemize
31575 'double
31576 \begin_inset LatexCommand \index{double (not supported)}
31577
31578 \end_inset
31579
31580 ' precision floating point 
31581 \begin_inset LatexCommand \index{Floating point support}
31582
31583 \end_inset
31584
31585 not supported.
31586
31587 \layout Itemize
31588 Old K&R style
31589 \begin_inset LatexCommand \index{K\&R style}
31590
31591 \end_inset
31592
31593  function declarations are NOT allowed.
31594
31595 \begin_deeper
31596 \layout Verse
31597
31598 \family typewriter
31599 foo(i,j) /* this old style of function declarations */ 
31600 \newline
31601 int i,j; /* are valid
31602  in ANSI but not valid in SDCC */ 
31603 \newline
31604
31605 \newline
31606 \SpecialChar ~
31607 \SpecialChar ~
31608 \SpecialChar ~
31609 \SpecialChar ~
31610 ...
31611  
31612 \newline
31613 }
31614
31615 \end_deeper
31616 \layout Itemize
31617 Most enhancements in C99 are not supported, f.e.:
31618
31619 \begin_deeper
31620 \layout Verse
31621
31622 \family typewriter
31623 \series bold
31624 inline
31625 \begin_inset LatexCommand \index{inline (not supported)}
31626
31627 \end_inset
31628
31629
31630 \series default
31631  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
31632  in C99.
31633  An empty define 
31634 \emph on
31635 #define inline
31636 \emph default
31637  can be used as a work around */
31638 \newline
31639
31640 \newline
31641 for (
31642 \series bold
31643 int
31644 \series default
31645  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
31646
31647 \end_deeper
31648 \layout Itemize
31649 Certain words that are valid identifiers in the standard may be reserved
31650  words in SDCC unless the 
31651 \series bold
31652 -
31653 \begin_inset ERT
31654 status Collapsed
31655
31656 \layout Standard
31657
31658
31659 \backslash
31660 /
31661
31662 \end_inset
31663
31664 -std-c89
31665 \begin_inset LatexCommand \index{-\/-std-c89}
31666
31667 \end_inset
31668
31669  or -
31670 \begin_inset ERT
31671 status Collapsed
31672
31673 \layout Standard
31674
31675
31676 \backslash
31677 /
31678
31679 \end_inset
31680
31681 -std-c99
31682 \begin_inset LatexCommand \index{-\/-std-c99}
31683
31684 \end_inset
31685
31686
31687 \series default
31688  command line options are used.
31689  These may include (depending on the selected processor): 'at', 'banked',
31690  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
31691 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
31692  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
31693  '_naked'.
31694  Compliant equivalents of these keywords are always available in a form
31695  that begin with two underscores
31696 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
31697
31698 \end_inset
31699
31700 , f.e.
31701  '__data' instead of 'data'.
31702
31703 \layout Section
31704 Cyclomatic Complexity
31705 \begin_inset LatexCommand \index{Cyclomatic complexity}
31706
31707 \end_inset
31708
31709
31710
31711 \layout Standard
31712 Cyclomatic complexity of a function is defined as the number of independent
31713  paths the program can take during execution of the function.
31714  This is an important number since it defines the number test cases you
31715  have to generate to validate the function.
31716  The accepted industry standard for complexity number is 10, if the cyclomatic
31717  complexity reported by SDCC exceeds 10 you should think about simplification
31718  of the function logic.
31719  Note that the complexity level is not related to the number of lines of
31720  code in a function.
31721  Large functions can have low complexity, and small functions can have large
31722  complexity levels.
31723  
31724 \newline
31725
31726 \newline
31727 SDCC uses the following formula to compute the complexity:
31728 \newline
31729
31730
31731 \layout Standard
31732 complexity = (number of edges in control flow graph) - (number of nodes
31733  in control flow graph) + 2;
31734 \newline
31735
31736 \newline
31737 Having said that the industry standard is 10,
31738  you should be aware that in some cases it be may unavoidable to have a
31739  complexity level of less than 10.
31740  For example if you have switch statement with more than 10 case labels,
31741  each case label adds one to the complexity level.
31742  The complexity level is by no means an absolute measure of the algorithmic
31743  complexity of the function, it does however provide a good starting point
31744  for which functions you might look at for further optimization.
31745
31746 \layout Section
31747 Retargetting for other Processors
31748
31749 \layout Standard
31750 The issues for retargetting the compiler are far too numerous to be covered
31751  by this document.
31752  What follows is a brief description of each of the seven phases of the
31753  compiler and its MCU dependency.
31754
31755 \layout Itemize
31756 Parsing the source and building the annotated parse tree.
31757  This phase is largely MCU independent (except for the language extensions).
31758  Syntax & semantic checks are also done in this phase, along with some initial
31759  optimizations like back patching labels and the pattern matching optimizations
31760  like bit-rotation etc.
31761
31762 \layout Itemize
31763 The second phase involves generating an intermediate code which can be easy
31764  manipulated during the later phases.
31765  This phase is entirely MCU independent.
31766  The intermediate code generation assumes the target machine has unlimited
31767  number of registers, and designates them with the name iTemp.
31768  The compiler can be made to dump a human readable form of the code generated
31769  by using the -
31770 \begin_inset ERT
31771 status Collapsed
31772
31773 \layout Standard
31774
31775
31776 \backslash
31777 /
31778
31779 \end_inset
31780
31781 -dumpraw option.
31782
31783 \layout Itemize
31784 This phase does the bulk of the standard optimizations and is also MCU independe
31785 nt.
31786  This phase can be broken down into several sub-phases:
31787 \newline
31788
31789 \newline
31790 Break down intermediate
31791  code (iCode) into basic blocks.
31792 \newline
31793 Do control flow & data flow analysis on the
31794  basic blocks.
31795 \newline
31796 Do local common subexpression elimination, then global subexpressio
31797 n elimination
31798 \newline
31799 Dead code elimination
31800 \newline
31801 Loop optimizations
31802 \newline
31803 If loop optimizations
31804  caused any changes then do 'global subexpression elimination' and 'dead
31805  code elimination' again.
31806
31807 \layout Itemize
31808 This phase determines the live-ranges; by live range I mean those iTemp
31809  variables defined by the compiler that still survive after all the optimization
31810 s.
31811  Live range analysis
31812 \begin_inset LatexCommand \index{Live range analysis}
31813
31814 \end_inset
31815
31816  is essential for register allocation, since these computation determines
31817  which of these iTemps will be assigned to registers, and for how long.
31818
31819 \layout Itemize
31820 Phase five is register allocation.
31821  There are two parts to this process.
31822 \newline
31823
31824 \newline
31825 The first part I call 'register packing'
31826  (for lack of a better term).
31827  In this case several MCU specific expression folding is done to reduce
31828  register pressure.
31829 \newline
31830
31831 \newline
31832 The second part is more MCU independent and deals with
31833  allocating registers to the remaining live ranges.
31834  A lot of MCU specific code does creep into this phase because of the limited
31835  number of index registers available in the 8051.
31836
31837 \layout Itemize
31838 The Code generation phase is (unhappily), entirely MCU dependent and very
31839  little (if any at all) of this code can be reused for other MCU.
31840  However the scheme for allocating a homogenized assembler operand for each
31841  iCode operand may be reused.
31842
31843 \layout Itemize
31844 As mentioned in the optimization section the peep-hole optimizer is rule
31845  based system, which can reprogrammed for other MCUs.
31846
31847 \layout Standard
31848 More information is available in a wiki
31849 \begin_inset LatexCommand \index{wiki}
31850
31851 \end_inset
31852
31853  (preliminary link 
31854 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
31855
31856 \end_inset
31857
31858 ) and in the thread 
31859 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
31860
31861 \end_inset
31862
31863  .
31864
31865 \layout Chapter
31866 Compiler internals
31867 \begin_inset LatexCommand \index{Compiler internals}
31868
31869 \end_inset
31870
31871
31872
31873 \layout Section
31874 The anatomy of the compiler
31875 \begin_inset LatexCommand \label{sub:The-anatomy-of}
31876
31877 \end_inset
31878
31879
31880
31881 \layout Standard
31882
31883 \shape italic
31884 This is an excerpt from an article published in Circuit Cellar Magazine
31885  in 
31886 \series bold
31887 August 2000
31888 \series default
31889 .
31890  It's a little outdated (the compiler is much more efficient now and user/develo
31891 per friendly), but pretty well exposes the guts of it all.
31892 \shape default
31893
31894 \newline
31895
31896 \newline
31897 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
31898  It is fairly easy to retarget for other 8-bit MCU.
31899  Here we take a look at some of the internals of the compiler.
31900  
31901
31902 \layout Paragraph*
31903 Parsing
31904 \begin_inset LatexCommand \index{Parsing}
31905
31906 \end_inset
31907
31908  
31909
31910 \layout Standard
31911 Parsing the input source file and creating an AST (Annotated Syntax Tree
31912 \begin_inset LatexCommand \index{Annotated syntax tree}
31913
31914 \end_inset
31915
31916 ).
31917  This phase also involves propagating types (annotating each node of the
31918  parse tree with type information) and semantic analysis.
31919  There are some MCU specific parsing rules.
31920  For example the storage classes, the extended storage classes are MCU specific
31921  while there may be a xdata storage class for 8051 there is no such storage
31922  class for z80 or Atmel AVR.
31923  SDCC allows MCU specific storage class extensions, i.e.
31924  xdata will be treated as a storage class specifier when parsing 8051 C
31925  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
31926  C code.
31927
31928 \layout Paragraph*
31929 Generating iCode
31930 \begin_inset LatexCommand \index{iCode}
31931
31932 \end_inset
31933
31934
31935
31936 \layout Standard
31937 Intermediate code generation.
31938  In this phase the AST is broken down into three-operand form (iCode).
31939  These three operand forms are represented as doubly linked lists.
31940  ICode is the term given to the intermediate form generated by the compiler.
31941  ICode example section shows some examples of iCode generated for some simple
31942  C source functions.
31943
31944 \layout Paragraph*
31945 Optimizations
31946 \begin_inset LatexCommand \index{Optimizations}
31947
31948 \end_inset
31949
31950 .
31951
31952 \layout Standard
31953 Bulk of the target independent optimizations is performed in this phase.
31954  The optimizations include constant propagation, common sub-expression eliminati
31955 on, loop invariant code movement, strength reduction of loop induction variables
31956  and dead-code elimination.
31957
31958 \layout Paragraph*
31959 Live range analysis
31960 \begin_inset LatexCommand \index{Live range analysis}
31961
31962 \end_inset
31963
31964
31965
31966 \layout Standard
31967 During intermediate code generation phase, the compiler assumes the target
31968  machine has infinite number of registers and generates a lot of temporary
31969  variables.
31970  The live range computation determines the lifetime of each of these compiler-ge
31971 nerated temporaries.
31972  A picture speaks a thousand words.
31973  ICode example sections show the live range annotations for each of the
31974  operand.
31975  It is important to note here, each iCode is assigned a number in the order
31976  of its execution in the function.
31977  The live ranges are computed in terms of these numbers.
31978  The from number is the number of the iCode which first defines the operand
31979  and the to number signifies the iCode which uses this operand last.
31980
31981 \layout Paragraph*
31982 Register Allocation
31983 \begin_inset LatexCommand \index{Register allocation}
31984
31985 \end_inset
31986
31987
31988
31989 \layout Standard
31990 The register allocation determines the type and number of registers needed
31991  by each operand.
31992  In most MCUs only a few registers can be used for indirect addressing.
31993  In case of 8051 for example the registers R0 & R1 can be used to indirectly
31994  address the internal ram and DPTR to indirectly address the external ram.
31995  The compiler will try to allocate the appropriate register to pointer variables
31996  if it can.
31997  ICode example section shows the operands annotated with the registers assigned
31998  to them.
31999  The compiler will try to keep operands in registers as much as possible;
32000  there are several schemes the compiler uses to do achieve this.
32001  When the compiler runs out of registers the compiler will check to see
32002  if there are any live operands which is not used or defined in the current
32003  basic block being processed, if there are any found then it will push that
32004  operand and use the registers in this block, the operand will then be popped
32005  at the end of the basic block.
32006  
32007
32008 \layout Standard
32009 There are other MCU specific considerations in this phase.
32010  Some MCUs have an accumulator; very short-lived operands could be assigned
32011  to the accumulator instead of a general-purpose register.
32012
32013 \layout Paragraph*
32014 Code generation
32015
32016 \layout Standard
32017 Figure II gives a table of iCode
32018 \begin_inset LatexCommand \index{iCode}
32019
32020 \end_inset
32021
32022  operations supported by the compiler.
32023  The code generation involves translating these operations into corresponding
32024  assembly code for the processor.
32025  This sounds overly simple but that is the essence of code generation.
32026  Some of the iCode operations are generated on a MCU specific manner for
32027  example, the z80 port does not use registers to pass parameters so the
32028  SEND and RECV iCode operations will not be generated, and it also does
32029  not support JUMPTABLES.
32030  
32031 \newline
32032
32033
32034 \layout Standard
32035
32036 \size footnotesize
32037 Figure II 
32038 \begin_inset Tabular
32039 <lyxtabular version="3" rows="39" columns="4">
32040 <features islongtable="true" headBottomDL="true">
32041 <column alignment="block" valignment="top" leftline="true" width="13col%">
32042 <column alignment="left" valignment="top" leftline="true" width="13col%">
32043 <column alignment="block" valignment="top" leftline="true" width="22col%">
32044 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32045 <row topline="true" bottomline="true" endhead="true">
32046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32047 \begin_inset Text
32048
32049 \layout Standard
32050
32051 \series bold
32052 iCode
32053 \series default
32054
32055 \begin_inset LatexCommand \index{iCode}
32056
32057 \end_inset
32058
32059
32060
32061 \end_inset
32062 </cell>
32063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32064 \begin_inset Text
32065
32066 \layout Standard
32067
32068 \series bold
32069 Operands
32070
32071 \end_inset
32072 </cell>
32073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32074 \begin_inset Text
32075
32076 \layout Standard
32077
32078 \series bold
32079 Description
32080
32081 \end_inset
32082 </cell>
32083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32084 \begin_inset Text
32085
32086 \layout Standard
32087
32088 \series bold
32089 C Equivalent
32090
32091 \end_inset
32092 </cell>
32093 </row>
32094 <row topline="true">
32095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32096 \begin_inset Text
32097
32098 \layout Standard
32099
32100 \size footnotesize
32101 '!'
32102
32103 \end_inset
32104 </cell>
32105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32106 \begin_inset Text
32107
32108 \layout Standard
32109
32110 \size footnotesize
32111 IC_LEFT() IC_RESULT()
32112
32113 \end_inset
32114 </cell>
32115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32116 \begin_inset Text
32117
32118 \layout Standard
32119
32120 \size footnotesize
32121 NOT operation 
32122
32123 \end_inset
32124 </cell>
32125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32126 \begin_inset Text
32127
32128 \layout Standard
32129
32130 \size footnotesize
32131 IC_RESULT = ! IC_LEFT;
32132
32133 \end_inset
32134 </cell>
32135 </row>
32136 <row topline="true">
32137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32138 \begin_inset Text
32139
32140 \layout Standard
32141
32142 \size footnotesize
32143 '~'
32144
32145 \end_inset
32146 </cell>
32147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32148 \begin_inset Text
32149
32150 \layout Standard
32151
32152 \size footnotesize
32153 IC_LEFT() IC_RESULT()
32154
32155 \end_inset
32156 </cell>
32157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32158 \begin_inset Text
32159
32160 \layout Standard
32161
32162 \size footnotesize
32163 Bitwise complement of 
32164
32165 \end_inset
32166 </cell>
32167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32168 \begin_inset Text
32169
32170 \layout Standard
32171
32172 \size footnotesize
32173 IC_RESULT = ~IC_LEFT;
32174
32175 \end_inset
32176 </cell>
32177 </row>
32178 <row topline="true">
32179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32180 \begin_inset Text
32181
32182 \layout Standard
32183
32184 \size footnotesize
32185 RRC
32186
32187 \end_inset
32188 </cell>
32189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32190 \begin_inset Text
32191
32192 \layout Standard
32193
32194 \size footnotesize
32195 IC_LEFT() IC_RESULT()
32196
32197 \end_inset
32198 </cell>
32199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32200 \begin_inset Text
32201
32202 \layout Standard
32203
32204 \size footnotesize
32205 Rotate right with carry
32206
32207 \end_inset
32208 </cell>
32209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32210 \begin_inset Text
32211
32212 \layout Standard
32213
32214 \size footnotesize
32215 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
32216
32217 \end_inset
32218 </cell>
32219 </row>
32220 <row topline="true">
32221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32222 \begin_inset Text
32223
32224 \layout Standard
32225
32226 \size footnotesize
32227 RLC
32228
32229 \end_inset
32230 </cell>
32231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32232 \begin_inset Text
32233
32234 \layout Standard
32235
32236 \size footnotesize
32237 IC_LEFT() IC_RESULT()
32238
32239 \end_inset
32240 </cell>
32241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32242 \begin_inset Text
32243
32244 \layout Standard
32245
32246 \size footnotesize
32247 Rotate left with carry
32248
32249 \end_inset
32250 </cell>
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32252 \begin_inset Text
32253
32254 \layout Standard
32255
32256 \size footnotesize
32257 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
32258
32259 \end_inset
32260 </cell>
32261 </row>
32262 <row topline="true">
32263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32264 \begin_inset Text
32265
32266 \layout Standard
32267
32268 \size footnotesize
32269 GETHBIT
32270
32271 \end_inset
32272 </cell>
32273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32274 \begin_inset Text
32275
32276 \layout Standard
32277
32278 \size footnotesize
32279 IC_LEFT() IC_RESULT()
32280
32281 \end_inset
32282 </cell>
32283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32284 \begin_inset Text
32285
32286 \layout Standard
32287
32288 \size footnotesize
32289 Get the highest order bit of IC_LEFT
32290
32291 \end_inset
32292 </cell>
32293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32294 \begin_inset Text
32295
32296 \layout Standard
32297
32298 \size footnotesize
32299 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
32300
32301 \end_inset
32302 </cell>
32303 </row>
32304 <row topline="true">
32305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32306 \begin_inset Text
32307
32308 \layout Standard
32309
32310 \size footnotesize
32311 UNARYMINUS
32312
32313 \end_inset
32314 </cell>
32315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32316 \begin_inset Text
32317
32318 \layout Standard
32319
32320 \size footnotesize
32321 IC_LEFT() IC_RESULT()
32322
32323 \end_inset
32324 </cell>
32325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32326 \begin_inset Text
32327
32328 \layout Standard
32329
32330 \size footnotesize
32331 Unary minus
32332
32333 \end_inset
32334 </cell>
32335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32336 \begin_inset Text
32337
32338 \layout Standard
32339
32340 \size footnotesize
32341 IC_RESULT = - IC_LEFT;
32342
32343 \end_inset
32344 </cell>
32345 </row>
32346 <row topline="true">
32347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32348 \begin_inset Text
32349
32350 \layout Standard
32351
32352 \size footnotesize
32353 IPUSH
32354
32355 \end_inset
32356 </cell>
32357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32358 \begin_inset Text
32359
32360 \layout Standard
32361
32362 \size footnotesize
32363 IC_LEFT()
32364
32365 \end_inset
32366 </cell>
32367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32368 \begin_inset Text
32369
32370 \layout Standard
32371
32372 \size footnotesize
32373 Push the operand into stack
32374
32375 \end_inset
32376 </cell>
32377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32378 \begin_inset Text
32379
32380 \layout Standard
32381
32382 \size footnotesize
32383 NONE
32384
32385 \end_inset
32386 </cell>
32387 </row>
32388 <row topline="true">
32389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32390 \begin_inset Text
32391
32392 \layout Standard
32393
32394 \size footnotesize
32395 IPOP
32396
32397 \end_inset
32398 </cell>
32399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32400 \begin_inset Text
32401
32402 \layout Standard
32403
32404 \size footnotesize
32405 IC_LEFT()
32406
32407 \end_inset
32408 </cell>
32409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32410 \begin_inset Text
32411
32412 \layout Standard
32413
32414 \size footnotesize
32415 Pop the operand from the stack 
32416
32417 \end_inset
32418 </cell>
32419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32420 \begin_inset Text
32421
32422 \layout Standard
32423
32424 \size footnotesize
32425 NONE
32426
32427 \end_inset
32428 </cell>
32429 </row>
32430 <row topline="true">
32431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32432 \begin_inset Text
32433
32434 \layout Standard
32435
32436 \size footnotesize
32437 CALL
32438
32439 \end_inset
32440 </cell>
32441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32442 \begin_inset Text
32443
32444 \layout Standard
32445
32446 \size footnotesize
32447 IC_LEFT() IC_RESULT()
32448
32449 \end_inset
32450 </cell>
32451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32452 \begin_inset Text
32453
32454 \layout Standard
32455
32456 \size footnotesize
32457 Call the function represented by IC_LEFT 
32458
32459 \end_inset
32460 </cell>
32461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32462 \begin_inset Text
32463
32464 \layout Standard
32465
32466 \size footnotesize
32467 IC_RESULT = IC_LEFT();
32468
32469 \end_inset
32470 </cell>
32471 </row>
32472 <row topline="true">
32473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32474 \begin_inset Text
32475
32476 \layout Standard
32477
32478 \size footnotesize
32479 PCALL
32480
32481 \end_inset
32482 </cell>
32483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32484 \begin_inset Text
32485
32486 \layout Standard
32487
32488 \size footnotesize
32489 IC_LEFT() IC_RESULT()
32490
32491 \end_inset
32492 </cell>
32493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32494 \begin_inset Text
32495
32496 \layout Standard
32497
32498 \size footnotesize
32499 Call via function pointer
32500
32501 \end_inset
32502 </cell>
32503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32504 \begin_inset Text
32505
32506 \layout Standard
32507
32508 \size footnotesize
32509 IC_RESULT = (*IC_LEFT)();
32510
32511 \end_inset
32512 </cell>
32513 </row>
32514 <row topline="true">
32515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32516 \begin_inset Text
32517
32518 \layout Standard
32519
32520 \size footnotesize
32521 RETURN
32522
32523 \end_inset
32524 </cell>
32525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32526 \begin_inset Text
32527
32528 \layout Standard
32529
32530 \size footnotesize
32531 IC_LEFT()
32532
32533 \end_inset
32534 </cell>
32535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32536 \begin_inset Text
32537
32538 \layout Standard
32539
32540 \size footnotesize
32541 Return the value in operand IC_LEFT 
32542
32543 \end_inset
32544 </cell>
32545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32546 \begin_inset Text
32547
32548 \layout Standard
32549
32550 \size footnotesize
32551 return IC_LEFT;
32552
32553 \end_inset
32554 </cell>
32555 </row>
32556 <row topline="true">
32557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32558 \begin_inset Text
32559
32560 \layout Standard
32561
32562 \size footnotesize
32563 LABEL
32564
32565 \end_inset
32566 </cell>
32567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32568 \begin_inset Text
32569
32570 \layout Standard
32571
32572 \size footnotesize
32573 IC_LABEL() 
32574
32575 \end_inset
32576 </cell>
32577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32578 \begin_inset Text
32579
32580 \layout Standard
32581
32582 \size footnotesize
32583 Label
32584
32585 \end_inset
32586 </cell>
32587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32588 \begin_inset Text
32589
32590 \layout Standard
32591
32592 \size footnotesize
32593 IC_LABEL:
32594
32595 \end_inset
32596 </cell>
32597 </row>
32598 <row topline="true">
32599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32600 \begin_inset Text
32601
32602 \layout Standard
32603
32604 \size footnotesize
32605 GOTO
32606
32607 \end_inset
32608 </cell>
32609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32610 \begin_inset Text
32611
32612 \layout Standard
32613
32614 \size footnotesize
32615 IC_LABEL() 
32616
32617 \end_inset
32618 </cell>
32619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32620 \begin_inset Text
32621
32622 \layout Standard
32623
32624 \size footnotesize
32625 Goto label
32626
32627 \end_inset
32628 </cell>
32629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32630 \begin_inset Text
32631
32632 \layout Standard
32633
32634 \size footnotesize
32635 goto IC_LABEL();
32636
32637 \end_inset
32638 </cell>
32639 </row>
32640 <row topline="true">
32641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32642 \begin_inset Text
32643
32644 \layout Standard
32645
32646 \size footnotesize
32647 '+'
32648
32649 \end_inset
32650 </cell>
32651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32652 \begin_inset Text
32653
32654 \layout Standard
32655
32656 \size footnotesize
32657 IC_LEFT() IC_RIGHT() IC_RESULT()
32658
32659 \end_inset
32660 </cell>
32661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32662 \begin_inset Text
32663
32664 \layout Standard
32665
32666 \size footnotesize
32667 Addition
32668
32669 \end_inset
32670 </cell>
32671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32672 \begin_inset Text
32673
32674 \layout Standard
32675
32676 \size footnotesize
32677 IC_RESULT = IC_LEFT + IC_RIGHT
32678
32679 \end_inset
32680 </cell>
32681 </row>
32682 <row topline="true">
32683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32684 \begin_inset Text
32685
32686 \layout Standard
32687
32688 \size footnotesize
32689 '-'
32690
32691 \end_inset
32692 </cell>
32693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32694 \begin_inset Text
32695
32696 \layout Standard
32697
32698 \size footnotesize
32699 IC_LEFT() IC_RIGHT() IC_RESULT()
32700
32701 \end_inset
32702 </cell>
32703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32704 \begin_inset Text
32705
32706 \layout Standard
32707
32708 \size footnotesize
32709 Subtraction
32710
32711 \end_inset
32712 </cell>
32713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32714 \begin_inset Text
32715
32716 \layout Standard
32717
32718 \size footnotesize
32719 IC_RESULT = IC_LEFT - IC_RIGHT 
32720
32721 \end_inset
32722 </cell>
32723 </row>
32724 <row topline="true">
32725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32726 \begin_inset Text
32727
32728 \layout Standard
32729
32730 \size footnotesize
32731 '*'
32732
32733 \end_inset
32734 </cell>
32735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32736 \begin_inset Text
32737
32738 \layout Standard
32739
32740 \size footnotesize
32741 IC_LEFT() IC_RIGHT() IC_RESULT()
32742
32743 \end_inset
32744 </cell>
32745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32746 \begin_inset Text
32747
32748 \layout Standard
32749
32750 \size footnotesize
32751 Multiplication 
32752
32753 \end_inset
32754 </cell>
32755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32756 \begin_inset Text
32757
32758 \layout Standard
32759
32760 \size footnotesize
32761 IC_RESULT = IC_LEFT * IC_RIGHT;
32762
32763 \end_inset
32764 </cell>
32765 </row>
32766 <row topline="true">
32767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32768 \begin_inset Text
32769
32770 \layout Standard
32771
32772 \size footnotesize
32773 '/'
32774
32775 \end_inset
32776 </cell>
32777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32778 \begin_inset Text
32779
32780 \layout Standard
32781
32782 \size footnotesize
32783 IC_LEFT() IC_RIGHT() IC_RESULT()
32784
32785 \end_inset
32786 </cell>
32787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32788 \begin_inset Text
32789
32790 \layout Standard
32791
32792 \size footnotesize
32793 Division
32794
32795 \end_inset
32796 </cell>
32797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32798 \begin_inset Text
32799
32800 \layout Standard
32801
32802 \size footnotesize
32803 IC_RESULT = IC_LEFT / IC_RIGHT;
32804
32805 \end_inset
32806 </cell>
32807 </row>
32808 <row topline="true">
32809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32810 \begin_inset Text
32811
32812 \layout Standard
32813
32814 \size footnotesize
32815 '%'
32816
32817 \end_inset
32818 </cell>
32819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32820 \begin_inset Text
32821
32822 \layout Standard
32823
32824 \size footnotesize
32825 IC_LEFT() IC_RIGHT() IC_RESULT()
32826
32827 \end_inset
32828 </cell>
32829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32830 \begin_inset Text
32831
32832 \layout Standard
32833
32834 \size footnotesize
32835 Modulus
32836
32837 \end_inset
32838 </cell>
32839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32840 \begin_inset Text
32841
32842 \layout Standard
32843
32844 \size footnotesize
32845 IC_RESULT = IC_LEFT % IC_RIGHT;
32846
32847 \end_inset
32848 </cell>
32849 </row>
32850 <row topline="true">
32851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32852 \begin_inset Text
32853
32854 \layout Standard
32855
32856 \size footnotesize
32857 '<'
32858
32859 \end_inset
32860 </cell>
32861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32862 \begin_inset Text
32863
32864 \layout Standard
32865
32866 \size footnotesize
32867 IC_LEFT() IC_RIGHT() IC_RESULT()
32868
32869 \end_inset
32870 </cell>
32871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32872 \begin_inset Text
32873
32874 \layout Standard
32875
32876 \size footnotesize
32877 Less than
32878
32879 \end_inset
32880 </cell>
32881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32882 \begin_inset Text
32883
32884 \layout Standard
32885
32886 \size footnotesize
32887 IC_RESULT = IC_LEFT < IC_RIGHT;
32888
32889 \end_inset
32890 </cell>
32891 </row>
32892 <row topline="true">
32893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32894 \begin_inset Text
32895
32896 \layout Standard
32897
32898 \size footnotesize
32899 '>'
32900
32901 \end_inset
32902 </cell>
32903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32904 \begin_inset Text
32905
32906 \layout Standard
32907
32908 \size footnotesize
32909 IC_LEFT() IC_RIGHT() IC_RESULT()
32910
32911 \end_inset
32912 </cell>
32913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32914 \begin_inset Text
32915
32916 \layout Standard
32917
32918 \size footnotesize
32919 Greater than 
32920
32921 \end_inset
32922 </cell>
32923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32924 \begin_inset Text
32925
32926 \layout Standard
32927
32928 \size footnotesize
32929 IC_RESULT = IC_LEFT > IC_RIGHT;
32930
32931 \end_inset
32932 </cell>
32933 </row>
32934 <row topline="true">
32935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32936 \begin_inset Text
32937
32938 \layout Standard
32939
32940 \size footnotesize
32941 EQ_OP
32942
32943 \end_inset
32944 </cell>
32945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32946 \begin_inset Text
32947
32948 \layout Standard
32949
32950 \size footnotesize
32951 IC_LEFT() IC_RIGHT() IC_RESULT()
32952
32953 \end_inset
32954 </cell>
32955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32956 \begin_inset Text
32957
32958 \layout Standard
32959
32960 \size footnotesize
32961 Equal to 
32962
32963 \end_inset
32964 </cell>
32965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32966 \begin_inset Text
32967
32968 \layout Standard
32969
32970 \size footnotesize
32971 IC_RESULT = IC_LEFT == IC_RIGHT;
32972
32973 \end_inset
32974 </cell>
32975 </row>
32976 <row topline="true">
32977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32978 \begin_inset Text
32979
32980 \layout Standard
32981
32982 \size footnotesize
32983 AND_OP
32984
32985 \end_inset
32986 </cell>
32987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32988 \begin_inset Text
32989
32990 \layout Standard
32991
32992 \size footnotesize
32993 IC_LEFT() IC_RIGHT() IC_RESULT() 
32994
32995 \end_inset
32996 </cell>
32997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32998 \begin_inset Text
32999
33000 \layout Standard
33001
33002 \size footnotesize
33003 Logical and operation
33004
33005 \end_inset
33006 </cell>
33007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33008 \begin_inset Text
33009
33010 \layout Standard
33011
33012 \size footnotesize
33013 IC_RESULT = IC_LEFT && IC_RIGHT; 
33014
33015 \end_inset
33016 </cell>
33017 </row>
33018 <row topline="true">
33019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33020 \begin_inset Text
33021
33022 \layout Standard
33023
33024 \size footnotesize
33025 OR_OP
33026
33027 \end_inset
33028 </cell>
33029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33030 \begin_inset Text
33031
33032 \layout Standard
33033
33034 \size footnotesize
33035 IC_LEFT() IC_RIGHT() IC_RESULT() 
33036
33037 \end_inset
33038 </cell>
33039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33040 \begin_inset Text
33041
33042 \layout Standard
33043
33044 \size footnotesize
33045 Logical or operation 
33046
33047 \end_inset
33048 </cell>
33049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33050 \begin_inset Text
33051
33052 \layout Standard
33053
33054 \size footnotesize
33055 IC_RESULT = IC_LEFT || IC_RIGHT; 
33056
33057 \end_inset
33058 </cell>
33059 </row>
33060 <row topline="true">
33061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33062 \begin_inset Text
33063
33064 \layout Standard
33065
33066 \size footnotesize
33067 '^'
33068
33069 \end_inset
33070 </cell>
33071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33072 \begin_inset Text
33073
33074 \layout Standard
33075
33076 \size footnotesize
33077 IC_LEFT() IC_RIGHT() IC_RESULT() 
33078
33079 \end_inset
33080 </cell>
33081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33082 \begin_inset Text
33083
33084 \layout Standard
33085
33086 \size footnotesize
33087 Exclusive OR
33088
33089 \end_inset
33090 </cell>
33091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33092 \begin_inset Text
33093
33094 \layout Standard
33095
33096 \size footnotesize
33097 IC_RESULT = IC_LEFT ^ IC_RIGHT;
33098
33099 \end_inset
33100 </cell>
33101 </row>
33102 <row topline="true">
33103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33104 \begin_inset Text
33105
33106 \layout Standard
33107
33108 \size footnotesize
33109 '|'
33110
33111 \end_inset
33112 </cell>
33113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33114 \begin_inset Text
33115
33116 \layout Standard
33117
33118 \size footnotesize
33119 IC_LEFT() IC_RIGHT() IC_RESULT() 
33120
33121 \end_inset
33122 </cell>
33123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33124 \begin_inset Text
33125
33126 \layout Standard
33127
33128 \size footnotesize
33129 Bitwise OR 
33130
33131 \end_inset
33132 </cell>
33133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33134 \begin_inset Text
33135
33136 \layout Standard
33137
33138 \size footnotesize
33139 IC_RESULT = IC_LEFT | IC_RIGHT;
33140
33141 \end_inset
33142 </cell>
33143 </row>
33144 <row topline="true">
33145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33146 \begin_inset Text
33147
33148 \layout Standard
33149
33150 \size footnotesize
33151 BITWISEAND
33152
33153 \end_inset
33154 </cell>
33155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33156 \begin_inset Text
33157
33158 \layout Standard
33159
33160 \size footnotesize
33161 IC_LEFT() IC_RIGHT() IC_RESULT()
33162
33163 \end_inset
33164 </cell>
33165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33166 \begin_inset Text
33167
33168 \layout Standard
33169
33170 \size footnotesize
33171 Bitwise AND 
33172
33173 \end_inset
33174 </cell>
33175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33176 \begin_inset Text
33177
33178 \layout Standard
33179
33180 \size footnotesize
33181 IC_RESULT = IC_LEFT & IC_RIGHT;
33182
33183 \end_inset
33184 </cell>
33185 </row>
33186 <row topline="true">
33187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33188 \begin_inset Text
33189
33190 \layout Standard
33191
33192 \size footnotesize
33193 LEFT_OP
33194
33195 \end_inset
33196 </cell>
33197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33198 \begin_inset Text
33199
33200 \layout Standard
33201
33202 \size footnotesize
33203 IC_LEFT() IC_RIGHT() IC_RESULT()
33204
33205 \end_inset
33206 </cell>
33207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33208 \begin_inset Text
33209
33210 \layout Standard
33211
33212 \size footnotesize
33213 Left shift 
33214
33215 \end_inset
33216 </cell>
33217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33218 \begin_inset Text
33219
33220 \layout Standard
33221
33222 \size footnotesize
33223 IC_RESULT = IC_LEFT << IC_RIGHT 
33224
33225 \end_inset
33226 </cell>
33227 </row>
33228 <row topline="true">
33229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33230 \begin_inset Text
33231
33232 \layout Standard
33233
33234 \size footnotesize
33235 RIGHT_OP
33236
33237 \end_inset
33238 </cell>
33239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33240 \begin_inset Text
33241
33242 \layout Standard
33243
33244 \size footnotesize
33245 IC_LEFT() IC_RIGHT() IC_RESULT()
33246
33247 \end_inset
33248 </cell>
33249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33250 \begin_inset Text
33251
33252 \layout Standard
33253
33254 \size footnotesize
33255 Right shift
33256
33257 \end_inset
33258 </cell>
33259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33260 \begin_inset Text
33261
33262 \layout Standard
33263
33264 \size footnotesize
33265 IC_RESULT = IC_LEFT >> IC_RIGHT 
33266
33267 \end_inset
33268 </cell>
33269 </row>
33270 <row topline="true">
33271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33272 \begin_inset Text
33273
33274 \layout Standard
33275
33276 \size footnotesize
33277 GET_VALUE_
33278 \newline
33279 AT_ ADDRESS
33280
33281 \end_inset
33282 </cell>
33283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33284 \begin_inset Text
33285
33286 \layout Standard
33287
33288 \size footnotesize
33289 IC_LEFT() IC_RESULT()
33290
33291 \end_inset
33292 </cell>
33293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33294 \begin_inset Text
33295
33296 \layout Standard
33297
33298 \size footnotesize
33299 Indirect fetch 
33300
33301 \end_inset
33302 </cell>
33303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33304 \begin_inset Text
33305
33306 \layout Standard
33307
33308 \size footnotesize
33309 IC_RESULT = (*IC_LEFT);
33310
33311 \end_inset
33312 </cell>
33313 </row>
33314 <row topline="true">
33315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33316 \begin_inset Text
33317
33318 \layout Standard
33319
33320 \size footnotesize
33321 POINTER_SET
33322
33323 \end_inset
33324 </cell>
33325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33326 \begin_inset Text
33327
33328 \layout Standard
33329
33330 \size footnotesize
33331 IC_RIGHT() IC_RESULT() 
33332
33333 \end_inset
33334 </cell>
33335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33336 \begin_inset Text
33337
33338 \layout Standard
33339
33340 \size footnotesize
33341 Indirect set
33342
33343 \end_inset
33344 </cell>
33345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33346 \begin_inset Text
33347
33348 \layout Standard
33349
33350 \size footnotesize
33351 (*IC_RESULT) = IC_RIGHT;
33352
33353 \end_inset
33354 </cell>
33355 </row>
33356 <row topline="true">
33357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33358 \begin_inset Text
33359
33360 \layout Standard
33361
33362 \size footnotesize
33363 '='
33364
33365 \end_inset
33366 </cell>
33367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33368 \begin_inset Text
33369
33370 \layout Standard
33371
33372 \size footnotesize
33373 IC_RIGHT() IC_RESULT()
33374
33375 \end_inset
33376 </cell>
33377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33378 \begin_inset Text
33379
33380 \layout Standard
33381
33382 \size footnotesize
33383 Assignment
33384
33385 \end_inset
33386 </cell>
33387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33388 \begin_inset Text
33389
33390 \layout Standard
33391
33392 \size footnotesize
33393 IC_RESULT = IC_RIGHT;
33394
33395 \end_inset
33396 </cell>
33397 </row>
33398 <row topline="true">
33399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33400 \begin_inset Text
33401
33402 \layout Standard
33403
33404 \size footnotesize
33405 IFX
33406
33407 \end_inset
33408 </cell>
33409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33410 \begin_inset Text
33411
33412 \layout Standard
33413
33414 \size footnotesize
33415 IC_COND IC_TRUE IC_LABEL
33416
33417 \end_inset
33418 </cell>
33419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33420 \begin_inset Text
33421
33422 \layout Standard
33423
33424 \size footnotesize
33425 Conditional jump.
33426  If true label is present then jump to true label if condition is true else
33427  jump to false label if condition is false 
33428
33429 \end_inset
33430 </cell>
33431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33432 \begin_inset Text
33433
33434 \layout Standard
33435
33436 \size footnotesize
33437 if (IC_COND) goto IC_TRUE; 
33438 \newline
33439 \SpecialChar ~
33440 \SpecialChar ~
33441 Or 
33442 \newline
33443 If (!IC_COND) goto IC_FALSE;
33444
33445 \end_inset
33446 </cell>
33447 </row>
33448 <row topline="true">
33449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33450 \begin_inset Text
33451
33452 \layout Standard
33453
33454 \size footnotesize
33455 ADDRESS_OF
33456
33457 \end_inset
33458 </cell>
33459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33460 \begin_inset Text
33461
33462 \layout Standard
33463
33464 \size footnotesize
33465 IC_LEFT() IC_RESULT()
33466
33467 \end_inset
33468 </cell>
33469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33470 \begin_inset Text
33471
33472 \layout Standard
33473
33474 \size footnotesize
33475 Address of 
33476
33477 \end_inset
33478 </cell>
33479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33480 \begin_inset Text
33481
33482 \layout Standard
33483
33484 \size footnotesize
33485 IC_RESULT = &IC_LEFT();
33486
33487 \end_inset
33488 </cell>
33489 </row>
33490 <row topline="true">
33491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33492 \begin_inset Text
33493
33494 \layout Standard
33495
33496 \size footnotesize
33497 JUMPTABLE
33498
33499 \end_inset
33500 </cell>
33501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33502 \begin_inset Text
33503
33504 \layout Standard
33505
33506 \size footnotesize
33507 IC_JTCOND IC_JTLABELS
33508
33509 \end_inset
33510 </cell>
33511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33512 \begin_inset Text
33513
33514 \layout Standard
33515
33516 \size footnotesize
33517 Jump to list of labels depending on the value of JTCOND
33518
33519 \end_inset
33520 </cell>
33521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33522 \begin_inset Text
33523
33524 \layout Standard
33525
33526 \size footnotesize
33527 Switch statement
33528
33529 \end_inset
33530 </cell>
33531 </row>
33532 <row topline="true">
33533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33534 \begin_inset Text
33535
33536 \layout Standard
33537
33538 \size footnotesize
33539 CAST
33540
33541 \end_inset
33542 </cell>
33543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33544 \begin_inset Text
33545
33546 \layout Standard
33547
33548 \size footnotesize
33549 IC_RIGHT() IC_LEFT() IC_RESULT()
33550
33551 \end_inset
33552 </cell>
33553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33554 \begin_inset Text
33555
33556 \layout Standard
33557
33558 \size footnotesize
33559 Cast types 
33560
33561 \end_inset
33562 </cell>
33563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33564 \begin_inset Text
33565
33566 \layout Standard
33567
33568 \size footnotesize
33569 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
33570
33571 \end_inset
33572 </cell>
33573 </row>
33574 <row topline="true">
33575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33576 \begin_inset Text
33577
33578 \layout Standard
33579
33580 \size footnotesize
33581 SEND
33582
33583 \end_inset
33584 </cell>
33585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33586 \begin_inset Text
33587
33588 \layout Standard
33589
33590 \size footnotesize
33591 IC_LEFT()
33592
33593 \end_inset
33594 </cell>
33595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33596 \begin_inset Text
33597
33598 \layout Standard
33599
33600 \size footnotesize
33601 This is used for passing parameters in registers; 
33602 \newline
33603 move IC_LEFT to the next
33604  available parameter register.
33605
33606 \end_inset
33607 </cell>
33608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33609 \begin_inset Text
33610
33611 \layout Standard
33612
33613 \size footnotesize
33614 None
33615
33616 \end_inset
33617 </cell>
33618 </row>
33619 <row topline="true">
33620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33621 \begin_inset Text
33622
33623 \layout Standard
33624
33625 \size footnotesize
33626 RECV
33627
33628 \end_inset
33629 </cell>
33630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33631 \begin_inset Text
33632
33633 \layout Standard
33634
33635 \size footnotesize
33636 IC_RESULT()
33637
33638 \end_inset
33639 </cell>
33640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33641 \begin_inset Text
33642
33643 \layout Standard
33644
33645 \size footnotesize
33646 This is used for receiving parameters passed in registers;
33647 \newline
33648 Move the values
33649  in the next parameter register to IC_RESULT 
33650
33651 \end_inset
33652 </cell>
33653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33654 \begin_inset Text
33655
33656 \layout Standard
33657
33658 \size footnotesize
33659 None
33660
33661 \end_inset
33662 </cell>
33663 </row>
33664 <row topline="true" bottomline="true">
33665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33666 \begin_inset Text
33667
33668 \layout Standard
33669
33670 \shape slanted
33671 \size footnotesize
33672 (some more have been added)
33673
33674 \end_inset
33675 </cell>
33676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33677 \begin_inset Text
33678
33679 \layout Standard
33680
33681
33682 \end_inset
33683 </cell>
33684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33685 \begin_inset Text
33686
33687 \layout Standard
33688
33689
33690 \end_inset
33691 </cell>
33692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33693 \begin_inset Text
33694
33695 \layout Standard
33696
33697 \shape slanted
33698 \size footnotesize
33699 see f.e.
33700  
33701 \family typewriter
33702 gen51Code()
33703 \family default
33704  in 
33705 \family typewriter
33706 src/mcs51/gen.c
33707
33708 \end_inset
33709 </cell>
33710 </row>
33711 </lyxtabular>
33712
33713 \end_inset
33714
33715
33716
33717 \layout Standard
33718 \begin_inset Note
33719 collapsed true
33720
33721 \layout Standard
33722 In the original article Figure II was announced to be downloadable on 
33723 \shape italic
33724 Circuit Cellar
33725 \shape default
33726 's web site.
33727  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
33728
33729 \end_inset
33730
33731
33732
33733 \layout Paragraph*
33734 ICode Example
33735 \begin_inset LatexCommand \index{iCode}
33736
33737 \end_inset
33738
33739
33740
33741 \layout Standard
33742 This section shows some details of iCode.
33743  The example C code does not do anything useful; it is used as an example
33744  to illustrate the intermediate code generated by the compiler.
33745
33746 \layout Verse
33747
33748 \family typewriter
33749 1.\SpecialChar ~
33750 xdata int * p;
33751 \newline
33752 2.\SpecialChar ~
33753 int gint;
33754 \newline
33755 3.\SpecialChar ~
33756 /* This function does nothing useful.
33757  It is used
33758 \newline
33759 4.\SpecialChar ~
33760 \SpecialChar ~
33761 \SpecialChar ~
33762 \SpecialChar ~
33763 for the purpose of explaining iCode */
33764 \newline
33765 5.\SpecialChar ~
33766 short function (data
33767  int *x)
33768 \newline
33769 6.\SpecialChar ~
33770 {
33771 \newline
33772 7.\SpecialChar ~
33773 \SpecialChar ~
33774 \SpecialChar ~
33775 short i=10; \SpecialChar ~
33776 \SpecialChar ~
33777 /* dead initialization eliminated */
33778 \newline
33779 8.\SpecialChar ~
33780 \SpecialChar ~
33781 \SpecialChar ~
33782 short sum=10;
33783  /* dead initialization eliminated */
33784 \newline
33785 9.\SpecialChar ~
33786 \SpecialChar ~
33787 \SpecialChar ~
33788 short mul;
33789 \newline
33790 10.\SpecialChar ~
33791 \SpecialChar ~
33792 int j ;
33793 \newline
33794 11.\SpecialChar ~
33795 \SpecialChar ~
33796 while (*x) *x++
33797  = *p++; 
33798 \newline
33799 12.\SpecialChar ~
33800 \SpecialChar ~
33801 \SpecialChar ~
33802 \SpecialChar ~
33803 sum = 0 ; 
33804 \newline
33805 13.\SpecialChar ~
33806 \SpecialChar ~
33807 mul = 0;
33808 \newline
33809 14.\SpecialChar ~
33810 \SpecialChar ~
33811 /* compiler detects i,j to be induction
33812  variables */
33813 \newline
33814 15.\SpecialChar ~
33815 \SpecialChar ~
33816 for (i = 0, j = 10 ; i < 10 ; i++, j
33817 \family default
33818 -
33819 \begin_inset ERT
33820 status Collapsed
33821
33822 \layout Standard
33823
33824
33825 \backslash
33826 /
33827
33828 \end_inset
33829
33830 -
33831 \family typewriter
33832 ) {
33833 \newline
33834 16.\SpecialChar ~
33835 \SpecialChar ~
33836 \SpecialChar ~
33837 \SpecialChar ~
33838 sum += i;
33839 \newline
33840 17.\SpecialChar ~
33841 \SpecialChar ~
33842 \SpecialChar ~
33843 \SpecialChar ~
33844 mul += i * 3; \SpecialChar ~
33845 \SpecialChar ~
33846 /* this multiplication remains */
33847 \newline
33848 18.\SpecialChar ~
33849 \SpecialChar ~
33850 \SpecialChar ~
33851 \SpecialChar ~
33852 gint +=
33853  j * 3;\SpecialChar ~
33854 \SpecialChar ~
33855 /* this multiplication changed to addition */
33856 \newline
33857 19.\SpecialChar ~
33858 \SpecialChar ~
33859 }
33860 \newline
33861 20.\SpecialChar ~
33862 \SpecialChar ~
33863 return sum+mul;
33864 \newline
33865 21.\SpecialChar ~
33866 }
33867
33868 \layout Standard
33869 In addition to the operands each iCode contains information about the filename
33870  and line it corresponds to in the source file.
33871  The first field in the listing should be interpreted as follows:
33872 \newline
33873
33874 \shape italic
33875 \size footnotesize
33876 Filename(linenumber: iCode Execution sequence number : ICode hash table
33877  key : loop depth of the iCode).
33878 \shape default
33879 \size default
33880
33881 \newline
33882 Then follows the human readable form of the ICode operation.
33883  Each operand of this triplet form can be of three basic types a) compiler
33884  generated temporary b) user defined variable c) a constant value.
33885  Note that local variables and parameters are replaced by compiler generated
33886  temporaries.
33887  Live ranges
33888 \begin_inset LatexCommand \index{Live range analysis}
33889
33890 \end_inset
33891
33892  are computed only for temporaries (i.e.
33893  live ranges are not computed for global variables).
33894  Registers
33895 \begin_inset LatexCommand \index{Register allocation}
33896
33897 \end_inset
33898
33899  are allocated for temporaries only.
33900  Operands are formatted in the following manner:
33901 \newline
33902
33903 \shape italic
33904 \size footnotesize
33905 Operand Name [lr live-from : live-to ] { type information } [ registers
33906  allocated ].
33907 \shape default
33908 \size default
33909
33910 \newline
33911 As mentioned earlier the live ranges are computed in terms of the execution
33912  sequence number of the iCodes, for example 
33913 \newline
33914 the iTemp0 is live from (i.e.
33915  first defined in iCode with execution sequence number 3, and is last used
33916  in the iCode with sequence number 5).
33917  For induction variables such as iTemp21 the live range computation extends
33918  the lifetime from the start to the end of the loop.
33919 \newline
33920 The register allocator
33921  used the live range information to allocate registers, the same registers
33922  may be used for different temporaries if their live ranges do not overlap,
33923  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
33924  ranges do not overlap.
33925  In addition the allocator also takes into consideration the type and usage
33926  of a temporary, for example itemp6 is a pointer to near space and is used
33927  as to fetch data from (i.e.
33928  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
33929  Some short lived temporaries are allocated to special registers which have
33930  meaning to the code generator e.g.
33931  iTemp13 is allocated to a pseudo register CC which tells the back end that
33932  the temporary is used only for a conditional jump the code generation makes
33933  use of this information to optimize a compare and jump ICode.
33934 \newline
33935 There are several
33936  loop optimizations
33937 \begin_inset LatexCommand \index{Loop optimization}
33938
33939 \end_inset
33940
33941  performed by the compiler.
33942  It can detect induction variables iTemp21(i) and iTemp23(j).
33943  Also note the compiler does selective strength reduction
33944 \begin_inset LatexCommand \index{Strength reduction}
33945
33946 \end_inset
33947
33948 , i.e.
33949  the multiplication of an induction variable in line 18 (gint = j * 3) is
33950  changed to addition, a new temporary iTemp17 is allocated and assigned
33951  a initial value, a constant 3 is then added for each iteration of the loop.
33952  The compiler does not change the multiplication
33953 \begin_inset LatexCommand \index{Multiplication}
33954
33955 \end_inset
33956
33957  in line 17 however since the processor does support an 8 * 8 bit multiplication.
33958 \newline
33959
33960 Note the dead code elimination
33961 \begin_inset LatexCommand \index{Dead-code elimination}
33962
33963 \end_inset
33964
33965  optimization eliminated the dead assignments in line 7 & 8 to I and sum
33966  respectively.
33967 \newline
33968
33969
33970 \layout Standard
33971
33972 \size footnotesize
33973 Sample.c (5:1:0:0) _entry($9) :
33974
33975 \layout Standard
33976
33977 \size footnotesize
33978 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
33979
33980 \layout Standard
33981
33982 \size footnotesize
33983 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
33984
33985 \layout Standard
33986
33987 \size footnotesize
33988 Sample.c(11:4:53:0) preHeaderLbl0($11) :
33989
33990 \layout Standard
33991
33992 \size footnotesize
33993 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
33994  * int}[r2]
33995
33996 \layout Standard
33997
33998 \size footnotesize
33999 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34000
34001 \layout Standard
34002
34003 \size footnotesize
34004 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34005  int}[r0]]
34006
34007 \layout Standard
34008
34009 \size footnotesize
34010 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34011
34012 \layout Standard
34013
34014 \size footnotesize
34015 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34016  * int}
34017
34018 \layout Standard
34019
34020 \size footnotesize
34021 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34022  {short}
34023
34024 \layout Standard
34025
34026 \size footnotesize
34027 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34028  * int}[DPTR]]
34029
34030 \layout Standard
34031
34032 \size footnotesize
34033 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34034 }[r2 r3]
34035
34036 \layout Standard
34037
34038 \size footnotesize
34039 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34040  * int}[r0] + 0x2 {short}
34041
34042 \layout Standard
34043
34044 \size footnotesize
34045 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34046
34047 \layout Standard
34048
34049 \size footnotesize
34050 Sample.c(11:17:21:0)_whilebreak_0($3) :
34051
34052 \layout Standard
34053
34054 \size footnotesize
34055 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34056
34057 \layout Standard
34058
34059 \size footnotesize
34060 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34061
34062 \layout Standard
34063
34064 \size footnotesize
34065 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34066
34067 \layout Standard
34068
34069 \size footnotesize
34070 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34071
34072 \layout Standard
34073
34074 \size footnotesize
34075 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34076
34077 \layout Standard
34078
34079 \size footnotesize
34080 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34081
34082 \layout Standard
34083
34084 \size footnotesize
34085 Sample.c(15:24:26:1)_forcond_0($4) :
34086
34087 \layout Standard
34088
34089 \size footnotesize
34090 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34091  < 0xa {short}
34092
34093 \layout Standard
34094
34095 \size footnotesize
34096 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34097
34098 \layout Standard
34099
34100 \size footnotesize
34101 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
34102  + ITemp21 [lr21:38]{short}[r4]
34103
34104 \layout Standard
34105
34106 \size footnotesize
34107 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
34108  * 0x3 {short}
34109
34110 \layout Standard
34111
34112 \size footnotesize
34113 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
34114  + iTemp15 [lr29:30]{short}[r1]
34115
34116 \layout Standard
34117
34118 \size footnotesize
34119 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
34120  r0]- 0x3 {short}
34121
34122 \layout Standard
34123
34124 \size footnotesize
34125 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
34126 int}[r7 r0]
34127
34128 \layout Standard
34129
34130 \size footnotesize
34131 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
34132  + 0x1 {short}
34133
34134 \layout Standard
34135
34136 \size footnotesize
34137 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
34138  r6]- 0x1 {short}
34139
34140 \layout Standard
34141
34142 \size footnotesize
34143 Sample.c(19:38:47:1) goto _forcond_0($4)
34144
34145 \layout Standard
34146
34147 \size footnotesize
34148 Sample.c(19:39:48:0)_forbreak_0($7) :
34149
34150 \layout Standard
34151
34152 \size footnotesize
34153 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
34154  + ITemp11 [lr19:40]{short}[r3]
34155
34156 \layout Standard
34157
34158 \size footnotesize
34159 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
34160
34161 \layout Standard
34162
34163 \size footnotesize
34164 Sample.c(20:42:51:0)_return($8) :
34165
34166 \layout Standard
34167
34168 \size footnotesize
34169 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
34170 \size default
34171
34172 \newline
34173
34174 \newline
34175 Finally the code generated for this function:
34176 \newline
34177
34178
34179 \layout Standard
34180
34181 \size footnotesize
34182 .area DSEG (DATA)
34183
34184 \layout Standard
34185
34186 \size footnotesize
34187 _p::
34188
34189 \layout Standard
34190
34191 \size footnotesize
34192 \SpecialChar ~
34193 \SpecialChar ~
34194 .ds 2
34195
34196 \layout Standard
34197
34198 \size footnotesize
34199 _gint::
34200
34201 \layout Standard
34202
34203 \size footnotesize
34204 \SpecialChar ~
34205 \SpecialChar ~
34206 .ds 2
34207
34208 \layout Standard
34209
34210 \size footnotesize
34211 ; sample.c 5
34212
34213 \layout Standard
34214
34215 \size footnotesize
34216 ; ----------------------------------------------
34217
34218 \layout Standard
34219
34220 \size footnotesize
34221 ; function function
34222
34223 \layout Standard
34224
34225 \size footnotesize
34226 ; ----------------------------------------------
34227
34228 \layout Standard
34229
34230 \size footnotesize
34231 _function:
34232
34233 \layout Standard
34234
34235 \size footnotesize
34236 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
34237
34238 \layout Standard
34239
34240 \size footnotesize
34241 \SpecialChar ~
34242 \SpecialChar ~
34243 mov r2,dpl
34244
34245 \layout Standard
34246
34247 \size footnotesize
34248 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
34249
34250 \layout Standard
34251
34252 \size footnotesize
34253 \SpecialChar ~
34254 \SpecialChar ~
34255 mov ar0,r2
34256
34257 \layout Standard
34258
34259 \size footnotesize
34260 ;_whilecontinue_0($1) :
34261
34262 \layout Standard
34263
34264 \size footnotesize
34265 00101$:
34266
34267 \layout Standard
34268
34269 \size footnotesize
34270 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
34271
34272 \layout Standard
34273
34274 \size footnotesize
34275 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34276
34277 \layout Standard
34278
34279 \size footnotesize
34280 \SpecialChar ~
34281 \SpecialChar ~
34282 mov ar2,@r0
34283
34284 \layout Standard
34285
34286 \size footnotesize
34287 \SpecialChar ~
34288 \SpecialChar ~
34289 inc r0
34290
34291 \layout Standard
34292
34293 \size footnotesize
34294 \SpecialChar ~
34295 \SpecialChar ~
34296 mov ar3,@r0
34297
34298 \layout Standard
34299
34300 \size footnotesize
34301 \SpecialChar ~
34302 \SpecialChar ~
34303 dec r0
34304
34305 \layout Standard
34306
34307 \size footnotesize
34308 \SpecialChar ~
34309 \SpecialChar ~
34310 mov a,r2
34311
34312 \layout Standard
34313
34314 \size footnotesize
34315 \SpecialChar ~
34316 \SpecialChar ~
34317 orl a,r3
34318
34319 \layout Standard
34320
34321 \size footnotesize
34322 \SpecialChar ~
34323 \SpecialChar ~
34324 jz 00103$
34325
34326 \layout Standard
34327
34328 \size footnotesize
34329 00114$:
34330
34331 \layout Standard
34332
34333 \size footnotesize
34334 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
34335
34336 \layout Standard
34337
34338 \size footnotesize
34339 \SpecialChar ~
34340 \SpecialChar ~
34341 mov dpl,_p
34342
34343 \layout Standard
34344
34345 \size footnotesize
34346 \SpecialChar ~
34347 \SpecialChar ~
34348 mov dph,(_p + 1)
34349
34350 \layout Standard
34351
34352 \size footnotesize
34353 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
34354
34355 \layout Standard
34356
34357 \size footnotesize
34358 \SpecialChar ~
34359 \SpecialChar ~
34360 mov a,#0x02
34361
34362 \layout Standard
34363
34364 \size footnotesize
34365 \SpecialChar ~
34366 \SpecialChar ~
34367 add a,_p
34368
34369 \layout Standard
34370
34371 \size footnotesize
34372 \SpecialChar ~
34373 \SpecialChar ~
34374 mov _p,a
34375
34376 \layout Standard
34377
34378 \size footnotesize
34379 \SpecialChar ~
34380 \SpecialChar ~
34381 clr a
34382
34383 \layout Standard
34384
34385 \size footnotesize
34386 \SpecialChar ~
34387 \SpecialChar ~
34388 addc a,(_p + 1)
34389
34390 \layout Standard
34391
34392 \size footnotesize
34393 \SpecialChar ~
34394 \SpecialChar ~
34395 mov (_p + 1),a
34396
34397 \layout Standard
34398
34399 \size footnotesize
34400 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
34401
34402 \layout Standard
34403
34404 \size footnotesize
34405 \SpecialChar ~
34406 \SpecialChar ~
34407 movx a,@dptr
34408
34409 \layout Standard
34410
34411 \size footnotesize
34412 \SpecialChar ~
34413 \SpecialChar ~
34414 mov r2,a
34415
34416 \layout Standard
34417
34418 \size footnotesize
34419 \SpecialChar ~
34420 \SpecialChar ~
34421 inc dptr
34422
34423 \layout Standard
34424
34425 \size footnotesize
34426 \SpecialChar ~
34427 \SpecialChar ~
34428 movx a,@dptr
34429
34430 \layout Standard
34431
34432 \size footnotesize
34433 \SpecialChar ~
34434 \SpecialChar ~
34435 mov r3,a
34436
34437 \layout Standard
34438
34439 \size footnotesize
34440 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
34441
34442 \layout Standard
34443
34444 \size footnotesize
34445 \SpecialChar ~
34446 \SpecialChar ~
34447 mov @r0,ar2
34448
34449 \layout Standard
34450
34451 \size footnotesize
34452 \SpecialChar ~
34453 \SpecialChar ~
34454 inc r0
34455
34456 \layout Standard
34457
34458 \size footnotesize
34459 \SpecialChar ~
34460 \SpecialChar ~
34461 mov @r0,ar3
34462
34463 \layout Standard
34464
34465 \size footnotesize
34466 ; iTemp6 [lr5:16]{_near * int}[r0] = 
34467
34468 \layout Standard
34469
34470 \size footnotesize
34471 ; iTemp6 [lr5:16]{_near * int}[r0] + 
34472
34473 \layout Standard
34474
34475 \size footnotesize
34476 ; 0x2 {short}
34477
34478 \layout Standard
34479
34480 \size footnotesize
34481 \SpecialChar ~
34482 \SpecialChar ~
34483 inc r0
34484
34485 \layout Standard
34486
34487 \size footnotesize
34488 ; goto _whilecontinue_0($1)
34489
34490 \layout Standard
34491
34492 \size footnotesize
34493 \SpecialChar ~
34494 \SpecialChar ~
34495 sjmp 00101$
34496
34497 \layout Standard
34498
34499 \size footnotesize
34500 ; _whilebreak_0($3) :
34501
34502 \layout Standard
34503
34504 \size footnotesize
34505 00103$:
34506
34507 \layout Standard
34508
34509 \size footnotesize
34510 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34511
34512 \layout Standard
34513
34514 \size footnotesize
34515 \SpecialChar ~
34516 \SpecialChar ~
34517 mov r2,#0x00
34518
34519 \layout Standard
34520
34521 \size footnotesize
34522 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34523
34524 \layout Standard
34525
34526 \size footnotesize
34527 \SpecialChar ~
34528 \SpecialChar ~
34529 mov r3,#0x00
34530
34531 \layout Standard
34532
34533 \size footnotesize
34534 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34535
34536 \layout Standard
34537
34538 \size footnotesize
34539 \SpecialChar ~
34540 \SpecialChar ~
34541 mov r4,#0x00
34542
34543 \layout Standard
34544
34545 \size footnotesize
34546 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34547
34548 \layout Standard
34549
34550 \size footnotesize
34551 \SpecialChar ~
34552 \SpecialChar ~
34553 mov r5,#0x0A
34554
34555 \layout Standard
34556
34557 \size footnotesize
34558 \SpecialChar ~
34559 \SpecialChar ~
34560 mov r6,#0x00
34561
34562 \layout Standard
34563
34564 \size footnotesize
34565 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34566
34567 \layout Standard
34568
34569 \size footnotesize
34570 \SpecialChar ~
34571 \SpecialChar ~
34572 mov r7,#0x1E
34573
34574 \layout Standard
34575
34576 \size footnotesize
34577 \SpecialChar ~
34578 \SpecialChar ~
34579 mov r0,#0x00
34580
34581 \layout Standard
34582
34583 \size footnotesize
34584 ; _forcond_0($4) :
34585
34586 \layout Standard
34587
34588 \size footnotesize
34589 00104$:
34590
34591 \layout Standard
34592
34593 \size footnotesize
34594 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
34595
34596 \layout Standard
34597
34598 \size footnotesize
34599 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34600
34601 \layout Standard
34602
34603 \size footnotesize
34604 \SpecialChar ~
34605 \SpecialChar ~
34606 clr c
34607
34608 \layout Standard
34609
34610 \size footnotesize
34611 \SpecialChar ~
34612 \SpecialChar ~
34613 mov a,r4
34614
34615 \layout Standard
34616
34617 \size footnotesize
34618 \SpecialChar ~
34619 \SpecialChar ~
34620 xrl a,#0x80
34621
34622 \layout Standard
34623
34624 \size footnotesize
34625 \SpecialChar ~
34626 \SpecialChar ~
34627 subb a,#0x8a
34628
34629 \layout Standard
34630
34631 \size footnotesize
34632 \SpecialChar ~
34633 \SpecialChar ~
34634 jnc 00107$
34635
34636 \layout Standard
34637
34638 \size footnotesize
34639 00115$:
34640
34641 \layout Standard
34642
34643 \size footnotesize
34644 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
34645
34646 \layout Standard
34647
34648 \size footnotesize
34649 ; iTemp21 [lr21:38]{short}[r4]
34650
34651 \layout Standard
34652
34653 \size footnotesize
34654 \SpecialChar ~
34655 \SpecialChar ~
34656 mov a,r4
34657
34658 \layout Standard
34659
34660 \size footnotesize
34661 \SpecialChar ~
34662 \SpecialChar ~
34663 add a,r2
34664
34665 \layout Standard
34666
34667 \size footnotesize
34668 \SpecialChar ~
34669 \SpecialChar ~
34670 mov r2,a
34671
34672 \layout Standard
34673
34674 \size footnotesize
34675 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
34676
34677 \layout Standard
34678
34679 \size footnotesize
34680 \SpecialChar ~
34681 \SpecialChar ~
34682 mov b,#0x03
34683
34684 \layout Standard
34685
34686 \size footnotesize
34687 \SpecialChar ~
34688 \SpecialChar ~
34689 mov a,r4
34690
34691 \layout Standard
34692
34693 \size footnotesize
34694 \SpecialChar ~
34695 \SpecialChar ~
34696 mul ab
34697
34698 \layout Standard
34699
34700 \size footnotesize
34701 \SpecialChar ~
34702 \SpecialChar ~
34703 mov r1,a
34704
34705 \layout Standard
34706
34707 \size footnotesize
34708 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
34709
34710 \layout Standard
34711
34712 \size footnotesize
34713 ; iTemp15 [lr29:30]{short}[r1]
34714
34715 \layout Standard
34716
34717 \size footnotesize
34718 \SpecialChar ~
34719 \SpecialChar ~
34720 add a,r3
34721
34722 \layout Standard
34723
34724 \size footnotesize
34725 \SpecialChar ~
34726 \SpecialChar ~
34727 mov r3,a
34728
34729 \layout Standard
34730
34731 \size footnotesize
34732 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
34733
34734 \layout Standard
34735
34736 \size footnotesize
34737 \SpecialChar ~
34738 \SpecialChar ~
34739 mov a,r7
34740
34741 \layout Standard
34742
34743 \size footnotesize
34744 \SpecialChar ~
34745 \SpecialChar ~
34746 add a,#0xfd
34747
34748 \layout Standard
34749
34750 \size footnotesize
34751 \SpecialChar ~
34752 \SpecialChar ~
34753 mov r7,a
34754
34755 \layout Standard
34756
34757 \size footnotesize
34758 \SpecialChar ~
34759 \SpecialChar ~
34760 mov a,r0
34761
34762 \layout Standard
34763
34764 \size footnotesize
34765 \SpecialChar ~
34766 \SpecialChar ~
34767 addc a,#0xff
34768
34769 \layout Standard
34770
34771 \size footnotesize
34772 \SpecialChar ~
34773 \SpecialChar ~
34774 mov r0,a
34775
34776 \layout Standard
34777
34778 \size footnotesize
34779 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
34780
34781 \layout Standard
34782
34783 \size footnotesize
34784 \SpecialChar ~
34785 \SpecialChar ~
34786 mov a,r7
34787
34788 \layout Standard
34789
34790 \size footnotesize
34791 \SpecialChar ~
34792 \SpecialChar ~
34793 add a,_gint
34794
34795 \layout Standard
34796
34797 \size footnotesize
34798 \SpecialChar ~
34799 \SpecialChar ~
34800 mov _gint,a
34801
34802 \layout Standard
34803
34804 \size footnotesize
34805 \SpecialChar ~
34806 \SpecialChar ~
34807 mov a,r0
34808
34809 \layout Standard
34810
34811 \size footnotesize
34812 \SpecialChar ~
34813 \SpecialChar ~
34814 addc a,(_gint + 1)
34815
34816 \layout Standard
34817
34818 \size footnotesize
34819 \SpecialChar ~
34820 \SpecialChar ~
34821 mov (_gint + 1),a
34822
34823 \layout Standard
34824
34825 \size footnotesize
34826 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
34827
34828 \layout Standard
34829
34830 \size footnotesize
34831 \SpecialChar ~
34832 \SpecialChar ~
34833 inc r4
34834
34835 \layout Standard
34836
34837 \size footnotesize
34838 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
34839
34840 \layout Standard
34841
34842 \size footnotesize
34843 \SpecialChar ~
34844 \SpecialChar ~
34845 dec r5
34846
34847 \layout Standard
34848
34849 \size footnotesize
34850 \SpecialChar ~
34851 \SpecialChar ~
34852 cjne r5,#0xff,00104$
34853
34854 \layout Standard
34855
34856 \size footnotesize
34857 \SpecialChar ~
34858 \SpecialChar ~
34859 dec r6
34860
34861 \layout Standard
34862
34863 \size footnotesize
34864 ; goto _forcond_0($4)
34865
34866 \layout Standard
34867
34868 \size footnotesize
34869 \SpecialChar ~
34870 \SpecialChar ~
34871 sjmp 00104$
34872
34873 \layout Standard
34874
34875 \size footnotesize
34876 ; _forbreak_0($7) :
34877
34878 \layout Standard
34879
34880 \size footnotesize
34881 00107$:
34882
34883 \layout Standard
34884
34885 \size footnotesize
34886 ; ret iTemp24 [lr40:41]{short}
34887
34888 \layout Standard
34889
34890 \size footnotesize
34891 \SpecialChar ~
34892 \SpecialChar ~
34893 mov a,r3
34894
34895 \layout Standard
34896
34897 \size footnotesize
34898 \SpecialChar ~
34899 \SpecialChar ~
34900 add a,r2
34901
34902 \layout Standard
34903
34904 \size footnotesize
34905 \SpecialChar ~
34906 \SpecialChar ~
34907 mov dpl,a
34908
34909 \layout Standard
34910
34911 \size footnotesize
34912 ; _return($8) :
34913
34914 \layout Standard
34915
34916 \size footnotesize
34917 00108$:
34918
34919 \layout Standard
34920
34921 \size footnotesize
34922 \SpecialChar ~
34923 \SpecialChar ~
34924 ret
34925 \newline
34926
34927
34928 \layout Section
34929 A few words about basic block successors, predecessors and dominators
34930
34931 \layout Standard
34932 Successors are basic blocks
34933 \begin_inset LatexCommand \index{Basic blocks}
34934
34935 \end_inset
34936
34937  that might execute after this basic block.
34938 \newline
34939 Predecessors are basic blocks
34940  that might execute before reaching this basic block.
34941 \newline
34942 Dominators are basic
34943  blocks that WILL execute before reaching this basic block.
34944 \newline
34945
34946
34947 \layout Standard
34948 [basic block 1]
34949
34950 \layout Standard
34951 if (something)
34952
34953 \layout Standard
34954 \SpecialChar ~
34955 \SpecialChar ~
34956 \SpecialChar ~
34957 \SpecialChar ~
34958 [basic block 2]
34959
34960 \layout Standard
34961 else
34962
34963 \layout Standard
34964 \SpecialChar ~
34965 \SpecialChar ~
34966 \SpecialChar ~
34967 \SpecialChar ~
34968 [basic block 3]
34969
34970 \layout Standard
34971 [basic block 4]
34972 \newline
34973
34974
34975 \layout Standard
34976 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
34977
34978 \layout Standard
34979 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
34980
34981 \layout Standard
34982 c) domVect of [BB4] = BB1 ...
34983  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
34984  was executed.
34985
34986 \layout Chapter
34987 Acknowledgments
34988
34989 \layout Standard
34990 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
34991
34992 \end_inset
34993
34994
34995 \newline
34996
34997 \newline
34998
34999 \emph on
35000 Thanks to all the other volunteer developers who have helped with coding,
35001  testing, web-page creation, distribution sets, etc.
35002  You know who you are :-)
35003 \emph default
35004
35005 \newline
35006
35007 \newline
35008
35009 \emph on
35010 Also thanks to Sourceforge 
35011 \begin_inset LatexCommand \url{http://www.sf.net}
35012
35013 \end_inset
35014
35015  which has hosted the project since 1999 and donates significant download
35016  bandwidth and probably more than 
35017 \begin_inset ERT
35018 status Collapsed
35019
35020 \layout Standard
35021
35022 $10^{13}$
35023
35024 \end_inset
35025
35026 CPU cycles per day.
35027 \newline
35028  
35029 \begin_inset Note
35030 collapsed false
35031
35032 \layout Standard
35033 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35034  minutes for (configure+make+regression test), and there is (i386, amd64,
35035  alpha, ppc64, (mingw32), sparc, macosx).
35036  
35037
35038 \end_inset
35039
35040
35041
35042 \layout Standard
35043 This document was initially written by Sandeep Dutta
35044
35045 \layout Standard
35046 All product names mentioned herein may be trademarks
35047 \begin_inset LatexCommand \index{Trademarks}
35048
35049 \end_inset
35050
35051  of their respective companies.
35052  
35053
35054 \layout Section*
35055 Alphabetical index
35056
35057 \layout Standard
35058 To avoid confusion, the installation and building options for SDCC itself
35059  (chapter 2) are not part of the index.
35060
35061 \layout Standard
35062 \begin_inset LatexCommand \printindex{}
35063
35064 \end_inset
35065
35066
35067
35068 \the_end