added printf benchmarks to manual
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   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},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \fontscheme pslatex
26 \graphics default
27 \paperfontsize default
28 \spacing single
29 \papersize letterpaper
30 \use_geometry true
31 \use_amsmath 1
32 \cite_engine basic
33 \use_bibtopic false
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47 \tracking_changes false
48 \output_changes true
49 \end_header
50
51 \begin_body
52
53 \begin_layout Standard
54 \begin_inset Note Comment
55 status collapsed
56
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59  --version) are written this way: -
60 \begin_inset ERT
61 status collapsed
62
63 \begin_layout Standard
64
65
66 \backslash
67 /
68 \end_layout
69
70 \end_inset
71
72 -
73 \end_layout
74
75 \begin_layout Standard
76 Two resp.
77  three consecutive dashes simply result in a long resp.
78  extra long dash.
79 \end_layout
80
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
83  later go
84 \end_layout
85
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
88  Z80 in 
89 \end_layout
90
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
93 \end_layout
94
95 \end_inset
96
97
98 \end_layout
99
100 \begin_layout Title
101 SDCC Compiler User Guide
102 \end_layout
103
104 \begin_layout Date
105
106 \size normal
107 SDCC 2.6.4
108 \size footnotesize
109
110 \newline
111 $Date$ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Comment
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
167  
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB, the debugger
680  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
681 \newline
682
683 \newline
684
685 The latest version can be downloaded from 
686 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
687
688 \end_inset
689
690 .
691
692 \series bold
693  
694 \series default
695 \emph on
696 Please note: the compiler will probably always be some steps ahead of this
697  documentation
698 \series bold
699 \emph default
700
701 \begin_inset LatexCommand \index{Status of documentation}
702
703 \end_inset
704
705
706 \begin_inset Foot
707 status open
708
709 \begin_layout Standard
710 Obviously this has pros and cons
711 \end_layout
712
713 \end_inset
714
715 .
716 \end_layout
717
718 \begin_layout Section
719 Open Source
720 \end_layout
721
722 \begin_layout Standard
723 All packages used in this compiler system are 
724 \emph on
725 open source
726 \emph default
727  and 
728 \emph on
729 freeware
730 \emph default
731 ; source code for all the sub-packages (pre-processor, assemblers, linkers
732  etc) is distributed with the package.
733  This documentation is maintained using a freeware word processor (LyX).
734 \newline
735 This
736  program is free software; you can redistribute it and/or modify it under
737  the terms of the GNU General Public License
738 \begin_inset LatexCommand \index{GNU General Public License, GPL}
739
740 \end_inset
741
742  as published by the Free Software Foundation; either version 2, or (at
743  your option) any later version.
744  This program is distributed in the hope that it will be useful, but WITHOUT
745  ANY WARRANTY; without even the implied warranty
746 \begin_inset LatexCommand \index{warranty}
747
748 \end_inset
749
750  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
751  See the GNU General Public License for more details.
752  You should have received a copy of the GNU General Public License along
753  with this program; if not, write to the Free Software Foundation, 59 Temple
754  Place - Suite 330, Boston, MA 02111-1307, USA.
755  In other words, you are welcome to use, share and improve this program.
756  You are forbidden to forbid anyone else to use, share and improve what
757  you give them.
758  Help stamp out software-hoarding! 
759 \end_layout
760
761 \begin_layout Section
762 Typographic conventions
763 \begin_inset LatexCommand \index{Typographic conventions}
764
765 \end_inset
766
767
768 \end_layout
769
770 \begin_layout Standard
771 Throughout this manual, we will use the following convention.
772  Commands you have to type in are printed in 
773 \family sans
774 \series bold
775 "sans serif"
776 \series default
777 .
778
779 \family default
780  Code samples are printed in 
781 \family typewriter
782 typewriter font.
783
784 \family default
785  Interesting items and new terms are printed in 
786 \emph on
787 italic.
788 \end_layout
789
790 \begin_layout Section
791 Compatibility
792 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
793
794 \end_inset
795
796  with previous versions
797 \begin_inset LatexCommand \index{Compatibility with previous versions}
798
799 \end_inset
800
801
802 \end_layout
803
804 \begin_layout Standard
805 This version has numerous bug fixes compared with the previous version.
806  But we also introduced some incompatibilities with older versions.
807  Not just for the fun of it, but to make the compiler more stable, efficient
808  and ANSI compliant
809 \begin_inset LatexCommand \index{ANSI-compliance}
810
811 \end_inset
812
813  (see section 
814 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
815
816 \end_inset
817
818  for ANSI-Compliance).
819  
820 \newline
821
822 \end_layout
823
824 \begin_layout Itemize
825 short is now equivalent to int (16 bits), it used to be equivalent to char
826  (8 bits) which is not ANSI compliant.
827 \end_layout
828
829 \begin_layout Itemize
830 the default directory for gcc-builds where include, library and documentation
831  files are stored is now in /usr/local/share.
832 \end_layout
833
834 \begin_layout Itemize
835 char type parameters to vararg
836 \begin_inset LatexCommand \index{vararg, va\_arg}
837
838 \end_inset
839
840  functions are casted to int unless explicitly casted
841 \begin_inset Marginal
842 status collapsed
843
844 \begin_layout Standard
845
846 \series bold
847 \InsetSpace ~
848 !
849 \end_layout
850
851 \end_inset
852
853 , e.g.: 
854 \newline
855
856 \family typewriter
857 \InsetSpace ~
858 \InsetSpace ~
859 char a=3;
860 \newline
861 \InsetSpace ~
862 \InsetSpace ~
863 printf ("%d %c
864 \backslash
865 n", a, (char)a);
866 \family default
867
868 \newline
869  will push a as an int and as a char resp.
870 \end_layout
871
872 \begin_layout Itemize
873 option -
874 \begin_inset ERT
875 status collapsed
876
877 \begin_layout Standard
878
879
880 \backslash
881 /
882 \end_layout
883
884 \end_inset
885
886 -regextend has been removed.
887 \end_layout
888
889 \begin_layout Itemize
890 option -
891 \begin_inset ERT
892 status collapsed
893
894 \begin_layout Standard
895
896
897 \backslash
898 /
899 \end_layout
900
901 \end_inset
902
903 -noregparms has been removed.
904 \end_layout
905
906 \begin_layout Itemize
907 option -
908 \begin_inset ERT
909 status collapsed
910
911 \begin_layout Standard
912
913
914 \backslash
915 /
916 \end_layout
917
918 \end_inset
919
920 -stack-after-data has been removed.
921 \end_layout
922
923 \begin_layout Itemize
924 bit
925 \begin_inset LatexCommand \index{bit}
926
927 \end_inset
928
929  and sbit
930 \begin_inset LatexCommand \index{sbit}
931
932 \end_inset
933
934
935 \begin_inset LatexCommand \index{\_\_sbit}
936
937 \end_inset
938
939  types now consistently behave like the C99 _Bool type with respect to type
940  conversion
941 \begin_inset LatexCommand \index{type conversion}
942
943 \end_inset
944
945
946 \begin_inset LatexCommand \index{type promotion}
947
948 \end_inset
949
950 .
951  The most common incompatibility resulting from this change is related to
952  bit toggling
953 \begin_inset LatexCommand \index{Bit toggling}
954
955 \end_inset
956
957  idioms, e.g.:
958 \newline
959
960 \family typewriter
961 \InsetSpace ~
962 \InsetSpace ~
963 bit b;
964 \newline
965 \InsetSpace ~
966 \InsetSpace ~
967 b = ~
968 \begin_inset LatexCommand \index{\~\/ Operator}
969
970 \end_inset
971
972 b; /* equivalent to b=1 instead of toggling b */
973 \begin_inset Marginal
974 status collapsed
975
976 \begin_layout Standard
977
978 \series bold
979 \InsetSpace ~
980 !
981 \end_layout
982
983 \end_inset
984
985
986 \newline
987 \InsetSpace ~
988 \InsetSpace ~
989 b = !b; /* toggles b */
990 \newline
991
992 \family default
993 In previous versions, both forms would have toggled the bit.
994 \end_layout
995
996 \begin_layout Standard
997
998 \emph on
999 <pending: more incompatibilities?>
1000 \end_layout
1001
1002 \begin_layout Section
1003 System Requirements
1004 \end_layout
1005
1006 \begin_layout Standard
1007 What do you need before you start installation of SDCC? A computer, and
1008  a desire to compute.
1009  The preferred method of installation is to compile SDCC from source using
1010  GNU gcc and make.
1011  For Windows some pre-compiled binary distributions are available for your
1012  convenience.
1013  You should have some experience with command line tools and compiler use.
1014 \end_layout
1015
1016 \begin_layout Section
1017 Other Resources
1018 \end_layout
1019
1020 \begin_layout Standard
1021 The SDCC home page at 
1022 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1023
1024 \end_inset
1025
1026  is a great place to find distribution sets.
1027  You can also find links to the user mailing lists that offer help or discuss
1028  SDCC with other SDCC users.
1029  Web links to other SDCC related sites can also be found here.
1030  This document can be found in the DOC directory of the source package as
1031  a text or HTML file.
1032  A pdf version of this document is available at 
1033 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1034
1035 \end_inset
1036
1037 .
1038  Some of the other tools (simulator and assembler) included with SDCC contain
1039  their own documentation and can be found in the source distribution.
1040  If you want the latest unreleased software, the complete source package
1041  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
1042 /trunk/sdcc.
1043 \end_layout
1044
1045 \begin_layout Section
1046 Wishes for the future
1047 \end_layout
1048
1049 \begin_layout Standard
1050 There are (and always will be) some things that could be done.
1051  Here are some I can think of:
1052 \newline
1053
1054 \end_layout
1055
1056 \begin_layout Standard
1057
1058 \family typewriter
1059 char KernelFunction3(char p) at 0x340;
1060 \newline
1061
1062 \end_layout
1063
1064 \begin_layout Standard
1065
1066 \family typewriter
1067 better code banking
1068 \begin_inset LatexCommand \index{code banking (limited support)}
1069
1070 \end_inset
1071
1072  support for mcs51
1073 \newline
1074
1075 \newline
1076
1077 \family default
1078 If you can think of some more, please see the section 
1079 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1080
1081 \end_inset
1082
1083  about filing feature requests
1084 \begin_inset LatexCommand \index{Requesting features}
1085
1086 \end_inset
1087
1088
1089 \begin_inset LatexCommand \index{Feature request}
1090
1091 \end_inset
1092
1093 .
1094 \newline
1095
1096 \end_layout
1097
1098 \begin_layout Chapter
1099 Installing SDCC
1100 \begin_inset LatexCommand \index{Installation}
1101
1102 \end_inset
1103
1104
1105 \end_layout
1106
1107 \begin_layout Standard
1108 For most users it is sufficient to skip to either section 
1109 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1110
1111 \end_inset
1112
1113  (Unix) or section 
1114 \begin_inset LatexCommand \ref{sub:Windows-Install}
1115
1116 \end_inset
1117
1118  (Windows).
1119  More detailed instructions follow below.
1120 \end_layout
1121
1122 \begin_layout Section
1123 Configure Options
1124 \begin_inset LatexCommand \index{Options SDCC configuration}
1125
1126 \end_inset
1127
1128
1129 \end_layout
1130
1131 \begin_layout Standard
1132 The install paths, search paths and other options are defined when running
1133  'configure'.
1134  The defaults can be overridden by:
1135 \end_layout
1136
1137 \begin_layout List
1138 \labelwidthstring 00.00.0000
1139 -
1140 \begin_inset ERT
1141 status collapsed
1142
1143 \begin_layout Standard
1144
1145
1146 \backslash
1147 /
1148 \end_layout
1149
1150 \end_inset
1151
1152 -prefix see table below
1153 \end_layout
1154
1155 \begin_layout List
1156 \labelwidthstring 00.00.0000
1157 -
1158 \begin_inset ERT
1159 status collapsed
1160
1161 \begin_layout Standard
1162
1163
1164 \backslash
1165 /
1166 \end_layout
1167
1168 \end_inset
1169
1170 -exec_prefix see table below
1171 \end_layout
1172
1173 \begin_layout List
1174 \labelwidthstring 00.00.0000
1175 -
1176 \begin_inset ERT
1177 status collapsed
1178
1179 \begin_layout Standard
1180
1181
1182 \backslash
1183 /
1184 \end_layout
1185
1186 \end_inset
1187
1188 -bindir see table below
1189 \end_layout
1190
1191 \begin_layout List
1192 \labelwidthstring 00.00.0000
1193 -
1194 \begin_inset ERT
1195 status collapsed
1196
1197 \begin_layout Standard
1198
1199
1200 \backslash
1201 /
1202 \end_layout
1203
1204 \end_inset
1205
1206 -datadir see table below
1207 \end_layout
1208
1209 \begin_layout List
1210 \labelwidthstring 00.00.0000
1211 -
1212 \begin_inset ERT
1213 status collapsed
1214
1215 \begin_layout Standard
1216
1217
1218 \backslash
1219 /
1220 \end_layout
1221
1222 \end_inset
1223
1224 -datarootdir see table below
1225 \newline
1226
1227 \end_layout
1228
1229 \begin_layout List
1230 \labelwidthstring 00.00.0000
1231 \InsetSpace ~
1232 \InsetSpace ~
1233 docdir environment variable, see table below
1234 \end_layout
1235
1236 \begin_layout List
1237 \labelwidthstring 00.00.0000
1238 \InsetSpace ~
1239 \InsetSpace ~
1240 include_dir_suffix environment variable, see table below
1241 \end_layout
1242
1243 \begin_layout List
1244 \labelwidthstring 00.00.0000
1245 \InsetSpace ~
1246 \InsetSpace ~
1247 lib_dir_suffix environment variable, see table below
1248 \end_layout
1249
1250 \begin_layout List
1251 \labelwidthstring 00.00.0000
1252 \InsetSpace ~
1253 \InsetSpace ~
1254 sdccconf_h_dir_separator environment variable, either / or 
1255 \backslash
1256
1257 \backslash
1258  makes sense here.
1259  This character will only be used in sdccconf.h; don't forget it's a C-header,
1260  therefore a double-backslash is needed there.
1261 \newline
1262
1263 \end_layout
1264
1265 \begin_layout List
1266 \labelwidthstring 00.00.0000
1267 -
1268 \begin_inset ERT
1269 status collapsed
1270
1271 \begin_layout Standard
1272
1273
1274 \backslash
1275 /
1276 \end_layout
1277
1278 \end_inset
1279
1280 -disable-mcs51-port Excludes the Intel mcs51 port
1281 \end_layout
1282
1283 \begin_layout List
1284 \labelwidthstring 00.00.0000
1285 -
1286 \begin_inset ERT
1287 status collapsed
1288
1289 \begin_layout Standard
1290
1291
1292 \backslash
1293 /
1294 \end_layout
1295
1296 \end_inset
1297
1298 -disable-gbz80-port Excludes the Gameboy gbz80 port
1299 \end_layout
1300
1301 \begin_layout List
1302 \labelwidthstring 00.00.0000
1303 -
1304 \begin_inset ERT
1305 status collapsed
1306
1307 \begin_layout Standard
1308
1309
1310 \backslash
1311 /
1312 \end_layout
1313
1314 \end_inset
1315
1316 -disable-z80-port Excludes the z80 port
1317 \end_layout
1318
1319 \begin_layout List
1320 \labelwidthstring 00.00.0000
1321 -
1322 \begin_inset ERT
1323 status collapsed
1324
1325 \begin_layout Standard
1326
1327
1328 \backslash
1329 /
1330 \end_layout
1331
1332 \end_inset
1333
1334 -disable-avr-port Excludes the AVR port
1335 \end_layout
1336
1337 \begin_layout List
1338 \labelwidthstring 00.00.0000
1339 -
1340 \begin_inset ERT
1341 status collapsed
1342
1343 \begin_layout Standard
1344
1345
1346 \backslash
1347 /
1348 \end_layout
1349
1350 \end_inset
1351
1352 -disable-ds390-port Excludes the DS390 port
1353 \end_layout
1354
1355 \begin_layout List
1356 \labelwidthstring 00.00.0000
1357 -
1358 \begin_inset ERT
1359 status collapsed
1360
1361 \begin_layout Standard
1362
1363
1364 \backslash
1365 /
1366 \end_layout
1367
1368 \end_inset
1369
1370 -disable-hc08-port Excludes the HC08 port
1371 \end_layout
1372
1373 \begin_layout List
1374 \labelwidthstring 00.00.0000
1375 -
1376 \begin_inset ERT
1377 status collapsed
1378
1379 \begin_layout Standard
1380
1381
1382 \backslash
1383 /
1384 \end_layout
1385
1386 \end_inset
1387
1388 -disable-pic-port Excludes the PIC port
1389 \end_layout
1390
1391 \begin_layout List
1392 \labelwidthstring 00.00.0000
1393 -
1394 \begin_inset ERT
1395 status collapsed
1396
1397 \begin_layout Standard
1398
1399
1400 \backslash
1401 /
1402 \end_layout
1403
1404 \end_inset
1405
1406 -disable-xa51-port Excludes the XA51 port
1407 \end_layout
1408
1409 \begin_layout List
1410 \labelwidthstring 00.00.0000
1411 -
1412 \begin_inset ERT
1413 status collapsed
1414
1415 \begin_layout Standard
1416
1417
1418 \backslash
1419 /
1420 \end_layout
1421
1422 \end_inset
1423
1424 -disable-ucsim Disables configuring and building of ucsim
1425 \end_layout
1426
1427 \begin_layout List
1428 \labelwidthstring 00.00.0000
1429 -
1430 \begin_inset ERT
1431 status collapsed
1432
1433 \begin_layout Standard
1434
1435
1436 \backslash
1437 /
1438 \end_layout
1439
1440 \end_inset
1441
1442 -disable-device-lib Disables automatically building device libraries
1443 \end_layout
1444
1445 \begin_layout List
1446 \labelwidthstring 00.00.0000
1447 -
1448 \begin_inset ERT
1449 status collapsed
1450
1451 \begin_layout Standard
1452
1453
1454 \backslash
1455 /
1456 \end_layout
1457
1458 \end_inset
1459
1460 -disable-packihx Disables building packihx
1461 \newline
1462
1463 \end_layout
1464
1465 \begin_layout List
1466 \labelwidthstring 00.00.0000
1467 -
1468 \begin_inset ERT
1469 status collapsed
1470
1471 \begin_layout Standard
1472
1473
1474 \backslash
1475 /
1476 \end_layout
1477
1478 \end_inset
1479
1480 -enable-doc Build pdf, html and txt files from the lyx sources
1481 \end_layout
1482
1483 \begin_layout List
1484 \labelwidthstring 00.00.0000
1485 -
1486 \begin_inset ERT
1487 status collapsed
1488
1489 \begin_layout Standard
1490
1491
1492 \backslash
1493 /
1494 \end_layout
1495
1496 \end_inset
1497
1498 -enable-libgc Use the Bohem memory allocator.
1499  Lower runtime footprint.
1500 \end_layout
1501
1502 \begin_layout Standard
1503 Furthermore the environment variables CC, CFLAGS, ...
1504  the tools and their arguments can be influenced.
1505  Please see `configure -
1506 \begin_inset ERT
1507 status collapsed
1508
1509 \begin_layout Standard
1510
1511
1512 \backslash
1513 /
1514 \end_layout
1515
1516 \end_inset
1517
1518 -help` and the man/info pages of `configure` for details.
1519 \newline
1520
1521 \newline
1522 The names of the
1523  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1524 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1525  SDCC_LIB_NAME are defined by `configure` too.
1526  At the moment it's not possible to change the default settings (it was
1527  simply never required).
1528 \newline
1529
1530 \newline
1531 These configure options are compiled into the binaries,
1532  and can only be changed by rerunning 'configure' and recompiling SDCC.
1533  The configure options are written in 
1534 \emph on
1535 italics
1536 \emph default
1537  to distinguish them from run time environment variables (see section search
1538  paths).
1539 \newline
1540
1541 \newline
1542 The settings for 
1543 \begin_inset Quotes sld
1544 \end_inset
1545
1546 Win32 builds
1547 \begin_inset Quotes srd
1548 \end_inset
1549
1550  are used by the SDCC team to build the official Win32 binaries.
1551  The SDCC team uses Mingw32 to build the official Windows binaries, because
1552  it's
1553 \end_layout
1554
1555 \begin_layout Enumerate
1556 open source, 
1557 \end_layout
1558
1559 \begin_layout Enumerate
1560 a gcc compiler and last but not least
1561 \end_layout
1562
1563 \begin_layout Enumerate
1564 the binaries can be built by cross compiling on Sourceforge's compile farm.
1565 \end_layout
1566
1567 \begin_layout Standard
1568 See the examples, how to pass the Win32 settings to 'configure'.
1569  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1570  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1571  for Win32.
1572 \newline
1573
1574 \newline
1575 These defaults are:
1576 \newline
1577
1578 \end_layout
1579
1580 \begin_layout Standard
1581 \align center
1582 \begin_inset Tabular
1583 <lyxtabular version="3" rows="9" columns="3">
1584 <features>
1585 <column alignment="block" valignment="top" leftline="true" width="0in">
1586 <column alignment="block" valignment="top" leftline="true" width="0in">
1587 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1588 <row topline="true" bottomline="true">
1589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1590 \begin_inset Text
1591
1592 \begin_layout Standard
1593 Variable
1594 \end_layout
1595
1596 \end_inset
1597 </cell>
1598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1599 \begin_inset Text
1600
1601 \begin_layout Standard
1602 default
1603 \end_layout
1604
1605 \end_inset
1606 </cell>
1607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1608 \begin_inset Text
1609
1610 \begin_layout Standard
1611 Win32 builds
1612 \end_layout
1613
1614 \end_inset
1615 </cell>
1616 </row>
1617 <row topline="true">
1618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1619 \begin_inset Text
1620
1621 \begin_layout Standard
1622
1623 \emph on
1624 PREFIX
1625 \end_layout
1626
1627 \end_inset
1628 </cell>
1629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1630 \begin_inset Text
1631
1632 \begin_layout Standard
1633 /usr/local
1634 \end_layout
1635
1636 \end_inset
1637 </cell>
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1639 \begin_inset Text
1640
1641 \begin_layout Standard
1642
1643 \backslash
1644 sdcc
1645 \end_layout
1646
1647 \end_inset
1648 </cell>
1649 </row>
1650 <row topline="true">
1651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1652 \begin_inset Text
1653
1654 \begin_layout Standard
1655
1656 \emph on
1657 EXEC_PREFIX
1658 \end_layout
1659
1660 \end_inset
1661 </cell>
1662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1663 \begin_inset Text
1664
1665 \begin_layout Standard
1666
1667 \emph on
1668 $PREFIX
1669 \end_layout
1670
1671 \end_inset
1672 </cell>
1673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1674 \begin_inset Text
1675
1676 \begin_layout Standard
1677
1678 \emph on
1679 $PREFIX
1680 \end_layout
1681
1682 \end_inset
1683 </cell>
1684 </row>
1685 <row topline="true">
1686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1687 \begin_inset Text
1688
1689 \begin_layout Standard
1690
1691 \emph on
1692 BINDIR
1693 \end_layout
1694
1695 \end_inset
1696 </cell>
1697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1698 \begin_inset Text
1699
1700 \begin_layout Standard
1701
1702 \emph on
1703 $EXEC_PREFIX
1704 \emph default
1705 /bin
1706 \end_layout
1707
1708 \end_inset
1709 </cell>
1710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1711 \begin_inset Text
1712
1713 \begin_layout Standard
1714
1715 \emph on
1716 $EXEC_PREFIX
1717 \emph default
1718
1719 \backslash
1720 bin
1721 \end_layout
1722
1723 \end_inset
1724 </cell>
1725 </row>
1726 <row topline="true">
1727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1728 \begin_inset Text
1729
1730 \begin_layout Standard
1731
1732 \emph on
1733 DATADIR
1734 \end_layout
1735
1736 \end_inset
1737 </cell>
1738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1739 \begin_inset Text
1740
1741 \begin_layout Standard
1742
1743 \emph on
1744 $DATAROOTDIR
1745 \end_layout
1746
1747 \end_inset
1748 </cell>
1749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1750 \begin_inset Text
1751
1752 \begin_layout Standard
1753
1754 \emph on
1755 $DATAROOTDIR
1756 \end_layout
1757
1758 \end_inset
1759 </cell>
1760 </row>
1761 <row topline="true">
1762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1763 \begin_inset Text
1764
1765 \begin_layout Standard
1766
1767 \emph on
1768 DATAROOTDIR
1769 \end_layout
1770
1771 \end_inset
1772 </cell>
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1774 \begin_inset Text
1775
1776 \begin_layout Standard
1777
1778 \emph on
1779 $PREFIX
1780 \emph default
1781 /share
1782 \end_layout
1783
1784 \end_inset
1785 </cell>
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1787 \begin_inset Text
1788
1789 \begin_layout Standard
1790
1791 \emph on
1792 $PREFIX
1793 \end_layout
1794
1795 \end_inset
1796 </cell>
1797 </row>
1798 <row topline="true">
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1800 \begin_inset Text
1801
1802 \begin_layout Standard
1803
1804 \emph on
1805 DOCDIR
1806 \end_layout
1807
1808 \end_inset
1809 </cell>
1810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1811 \begin_inset Text
1812
1813 \begin_layout Standard
1814
1815 \emph on
1816 $DATAROOTDIR
1817 \emph default
1818 /sdcc/doc
1819 \end_layout
1820
1821 \end_inset
1822 </cell>
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1824 \begin_inset Text
1825
1826 \begin_layout Standard
1827
1828 \emph on
1829 $DATAROOTDIR
1830 \emph default
1831
1832 \backslash
1833 doc
1834 \end_layout
1835
1836 \end_inset
1837 </cell>
1838 </row>
1839 <row topline="true">
1840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1841 \begin_inset Text
1842
1843 \begin_layout Standard
1844
1845 \emph on
1846 INCLUDE_DIR_SUFFIX
1847 \end_layout
1848
1849 \end_inset
1850 </cell>
1851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1852 \begin_inset Text
1853
1854 \begin_layout Standard
1855 sdcc/include
1856 \end_layout
1857
1858 \end_inset
1859 </cell>
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1861 \begin_inset Text
1862
1863 \begin_layout Standard
1864 include
1865 \end_layout
1866
1867 \end_inset
1868 </cell>
1869 </row>
1870 <row topline="true" bottomline="true">
1871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1872 \begin_inset Text
1873
1874 \begin_layout Standard
1875
1876 \emph on
1877 LIB_DIR_SUFFIX
1878 \end_layout
1879
1880 \end_inset
1881 </cell>
1882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1883 \begin_inset Text
1884
1885 \begin_layout Standard
1886 sdcc/lib
1887 \end_layout
1888
1889 \end_inset
1890 </cell>
1891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1892 \begin_inset Text
1893
1894 \begin_layout Standard
1895 lib
1896 \end_layout
1897
1898 \end_inset
1899 </cell>
1900 </row>
1901 </lyxtabular>
1902
1903 \end_inset
1904
1905
1906 \newline
1907
1908 \end_layout
1909
1910 \begin_layout Standard
1911 \noindent
1912 'configure' also computes relative paths.
1913  This is needed for full relocatability of a binary package and to complete
1914  search paths (see section search paths below):
1915 \newline
1916  
1917 \end_layout
1918
1919 \begin_layout Standard
1920 \align center
1921 \begin_inset Tabular
1922 <lyxtabular version="3" rows="4" columns="3">
1923 <features>
1924 <column alignment="block" valignment="top" leftline="true" width="0in">
1925 <column alignment="block" valignment="top" leftline="true" width="0in">
1926 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1927 <row topline="true" bottomline="true">
1928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1929 \begin_inset Text
1930
1931 \begin_layout Standard
1932 Variable (computed)
1933 \end_layout
1934
1935 \end_inset
1936 </cell>
1937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1938 \begin_inset Text
1939
1940 \begin_layout Standard
1941 default
1942 \end_layout
1943
1944 \end_inset
1945 </cell>
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1947 \begin_inset Text
1948
1949 \begin_layout Standard
1950 Win32 builds
1951 \end_layout
1952
1953 \end_inset
1954 </cell>
1955 </row>
1956 <row topline="true" bottomline="true">
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1958 \begin_inset Text
1959
1960 \begin_layout Standard
1961
1962 \emph on
1963 BIN2DATA_DIR
1964 \end_layout
1965
1966 \end_inset
1967 </cell>
1968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1969 \begin_inset Text
1970
1971 \begin_layout Standard
1972 ../share
1973 \end_layout
1974
1975 \end_inset
1976 </cell>
1977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1978 \begin_inset Text
1979
1980 \begin_layout Standard
1981 ..
1982 \end_layout
1983
1984 \end_inset
1985 </cell>
1986 </row>
1987 <row bottomline="true">
1988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1989 \begin_inset Text
1990
1991 \begin_layout Standard
1992
1993 \emph on
1994 PREFIX2BIN_DIR
1995 \end_layout
1996
1997 \end_inset
1998 </cell>
1999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2000 \begin_inset Text
2001
2002 \begin_layout Standard
2003 bin
2004 \end_layout
2005
2006 \end_inset
2007 </cell>
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2009 \begin_inset Text
2010
2011 \begin_layout Standard
2012 bin
2013 \end_layout
2014
2015 \end_inset
2016 </cell>
2017 </row>
2018 <row bottomline="true">
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2020 \begin_inset Text
2021
2022 \begin_layout Standard
2023
2024 \emph on
2025 PREFIX2DATA_DIR
2026 \end_layout
2027
2028 \end_inset
2029 </cell>
2030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2031 \begin_inset Text
2032
2033 \begin_layout Standard
2034 share/sdcc
2035 \end_layout
2036
2037 \end_inset
2038 </cell>
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2040 \begin_inset Text
2041
2042 \begin_layout Standard
2043
2044 \end_layout
2045
2046 \end_inset
2047 </cell>
2048 </row>
2049 </lyxtabular>
2050
2051 \end_inset
2052
2053
2054 \newline
2055
2056 \end_layout
2057
2058 \begin_layout Standard
2059 \noindent
2060 Examples:
2061 \end_layout
2062
2063 \begin_layout LyX-Code
2064 ./configure
2065 \newline
2066 ./configure -
2067 \begin_inset ERT
2068 status collapsed
2069
2070 \begin_layout Standard
2071
2072
2073 \backslash
2074 /
2075 \end_layout
2076
2077 \end_inset
2078
2079 -prefix=
2080 \begin_inset Quotes srd
2081 \end_inset
2082
2083 /usr/bin
2084 \begin_inset Quotes srd
2085 \end_inset
2086
2087  -
2088 \begin_inset ERT
2089 status collapsed
2090
2091 \begin_layout Standard
2092
2093
2094 \backslash
2095 /
2096 \end_layout
2097
2098 \end_inset
2099
2100 -datarootdir=
2101 \begin_inset Quotes srd
2102 \end_inset
2103
2104 /usr/share
2105 \begin_inset Quotes srd
2106 \end_inset
2107
2108
2109 \newline
2110 ./configure -
2111 \begin_inset ERT
2112 status collapsed
2113
2114 \begin_layout Standard
2115
2116
2117 \backslash
2118 /
2119 \end_layout
2120
2121 \end_inset
2122
2123 -disable-avr-port -
2124 \begin_inset ERT
2125 status collapsed
2126
2127 \begin_layout Standard
2128
2129
2130 \backslash
2131 /
2132 \end_layout
2133
2134 \end_inset
2135
2136 -disable-xa51-port
2137 \end_layout
2138
2139 \begin_layout Standard
2140 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2141 32'):
2142 \end_layout
2143
2144 \begin_layout LyX-Code
2145 ./configure 
2146 \backslash
2147
2148 \newline
2149 CC=
2150 \begin_inset Quotes srd
2151 \end_inset
2152
2153 i586-mingw32msvc-gcc
2154 \begin_inset Quotes srd
2155 \end_inset
2156
2157  CXX=
2158 \begin_inset Quotes srd
2159 \end_inset
2160
2161 i586-mingw32msvc-g++
2162 \begin_inset Quotes srd
2163 \end_inset
2164
2165  
2166 \backslash
2167  
2168 \newline
2169 RANLIB=
2170 \begin_inset Quotes srd
2171 \end_inset
2172
2173 i586-mingw32msvc-ranlib
2174 \begin_inset Quotes srd
2175 \end_inset
2176
2177  
2178 \backslash
2179
2180 \newline
2181 STRIP=
2182 \begin_inset Quotes srd
2183 \end_inset
2184
2185 i586-mingw32msvc-strip
2186 \begin_inset Quotes srd
2187 \end_inset
2188
2189  
2190 \backslash
2191
2192 \newline
2193 -
2194 \begin_inset ERT
2195 status collapsed
2196
2197 \begin_layout Standard
2198
2199
2200 \backslash
2201 /
2202 \end_layout
2203
2204 \end_inset
2205
2206 -prefix=
2207 \begin_inset Quotes srd
2208 \end_inset
2209
2210 /sdcc
2211 \begin_inset Quotes srd
2212 \end_inset
2213
2214  
2215 \backslash
2216
2217 \newline
2218 -
2219 \begin_inset ERT
2220 status collapsed
2221
2222 \begin_layout Standard
2223
2224
2225 \backslash
2226 /
2227 \end_layout
2228
2229 \end_inset
2230
2231 -datarootdir=
2232 \begin_inset Quotes srd
2233 \end_inset
2234
2235 /sdcc
2236 \begin_inset Quotes srd
2237 \end_inset
2238
2239  
2240 \backslash
2241
2242 \newline
2243 docdir=
2244 \begin_inset Quotes srd
2245 \end_inset
2246
2247
2248 \backslash
2249 ${datarootdir}/doc
2250 \begin_inset Quotes srd
2251 \end_inset
2252
2253  
2254 \backslash
2255
2256 \newline
2257 include_dir_suffix=
2258 \begin_inset Quotes srd
2259 \end_inset
2260
2261 include
2262 \begin_inset Quotes srd
2263 \end_inset
2264
2265  
2266 \backslash
2267
2268 \newline
2269 lib_dir_suffix=
2270 \begin_inset Quotes srd
2271 \end_inset
2272
2273 lib
2274 \begin_inset Quotes srd
2275 \end_inset
2276
2277  
2278 \backslash
2279
2280 \newline
2281 sdccconf_h_dir_separator=
2282 \begin_inset Quotes srd
2283 \end_inset
2284
2285
2286 \backslash
2287
2288 \backslash
2289
2290 \backslash
2291
2292 \backslash
2293
2294 \begin_inset Quotes srd
2295 \end_inset
2296
2297  
2298 \backslash
2299
2300 \newline
2301 -
2302 \begin_inset ERT
2303 status collapsed
2304
2305 \begin_layout Standard
2306
2307
2308 \backslash
2309 /
2310 \end_layout
2311
2312 \end_inset
2313
2314 -disable-device-lib
2315 \backslash
2316
2317 \newline
2318 -
2319 \begin_inset ERT
2320 status collapsed
2321
2322 \begin_layout Standard
2323
2324
2325 \backslash
2326 /
2327 \end_layout
2328
2329 \end_inset
2330
2331 -host=i586-mingw32msvc
2332 \backslash
2333
2334 \newline
2335 -
2336 \begin_inset ERT
2337 status collapsed
2338
2339 \begin_layout Standard
2340
2341
2342 \backslash
2343 /
2344 \end_layout
2345
2346 \end_inset
2347
2348 -build=unknown-unknown-linux-gnu
2349 \end_layout
2350
2351 \begin_layout Standard
2352 To 
2353 \begin_inset Quotes sld
2354 \end_inset
2355
2356 cross
2357 \begin_inset Quotes srd
2358 \end_inset
2359
2360 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2361 ):
2362 \end_layout
2363
2364 \begin_layout LyX-Code
2365 ./configure -C 
2366 \backslash
2367
2368 \newline
2369 -
2370 \begin_inset ERT
2371 status collapsed
2372
2373 \begin_layout Standard
2374
2375
2376 \backslash
2377 /
2378 \end_layout
2379
2380 \end_inset
2381
2382 -prefix=
2383 \begin_inset Quotes srd
2384 \end_inset
2385
2386 /sdcc
2387 \begin_inset Quotes srd
2388 \end_inset
2389
2390  
2391 \backslash
2392
2393 \newline
2394 -
2395 \begin_inset ERT
2396 status collapsed
2397
2398 \begin_layout Standard
2399
2400
2401 \backslash
2402 /
2403 \end_layout
2404
2405 \end_inset
2406
2407 -datarootdir=
2408 \begin_inset Quotes srd
2409 \end_inset
2410
2411 /sdcc
2412 \begin_inset Quotes srd
2413 \end_inset
2414
2415  
2416 \backslash
2417
2418 \newline
2419 docdir=
2420 \begin_inset Quotes srd
2421 \end_inset
2422
2423
2424 \backslash
2425 ${datarootdir}/doc
2426 \begin_inset Quotes srd
2427 \end_inset
2428
2429  
2430 \backslash
2431  
2432 \newline
2433 include_dir_suffix=
2434 \begin_inset Quotes srd
2435 \end_inset
2436
2437 include
2438 \begin_inset Quotes srd
2439 \end_inset
2440
2441  
2442 \backslash
2443
2444 \newline
2445 lib_dir_suffix=
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449 lib
2450 \begin_inset Quotes srd
2451 \end_inset
2452
2453  
2454 \backslash
2455
2456 \newline
2457 sdccconf_h_dir_separator=
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461
2462 \backslash
2463
2464 \backslash
2465
2466 \backslash
2467
2468 \backslash
2469
2470 \begin_inset Quotes srd
2471 \end_inset
2472
2473  
2474 \backslash
2475
2476 \newline
2477 CC=
2478 \begin_inset Quotes srd
2479 \end_inset
2480
2481 gcc -mno-cygwin
2482 \begin_inset Quotes srd
2483 \end_inset
2484
2485  
2486 \backslash
2487
2488 \newline
2489 CXX=
2490 \begin_inset Quotes srd
2491 \end_inset
2492
2493 g++ -mno-cygwin
2494 \begin_inset Quotes srd
2495 \end_inset
2496
2497  
2498 \end_layout
2499
2500 \begin_layout Standard
2501 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2502  The option '-
2503 \begin_inset ERT
2504 status collapsed
2505
2506 \begin_layout Standard
2507
2508
2509 \backslash
2510 /
2511 \end_layout
2512
2513 \end_inset
2514
2515 -C' turns on caching, which gives a little bit extra speed.
2516  However if options are changed, it can be necessary to delete the config.cache
2517  file.
2518 \end_layout
2519
2520 \begin_layout Section
2521 Install paths
2522 \begin_inset LatexCommand \label{sub:Install-paths}
2523
2524 \end_inset
2525
2526
2527 \begin_inset LatexCommand \index{Install paths}
2528
2529 \end_inset
2530
2531
2532 \end_layout
2533
2534 \begin_layout Standard
2535 \begin_inset VSpace medskip
2536 \end_inset
2537
2538
2539 \end_layout
2540
2541 \begin_layout Standard
2542 \align center
2543 \begin_inset Tabular
2544 <lyxtabular version="3" rows="5" columns="4">
2545 <features>
2546 <column alignment="left" valignment="top" leftline="true" width="0">
2547 <column alignment="left" valignment="top" leftline="true" width="0">
2548 <column alignment="left" valignment="top" leftline="true" width="0">
2549 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2550 <row topline="true" bottomline="true">
2551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2552 \begin_inset Text
2553
2554 \begin_layout Standard
2555
2556 \series bold
2557 Description
2558 \end_layout
2559
2560 \end_inset
2561 </cell>
2562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2563 \begin_inset Text
2564
2565 \begin_layout Standard
2566
2567 \series bold
2568 Path
2569 \end_layout
2570
2571 \end_inset
2572 </cell>
2573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2574 \begin_inset Text
2575
2576 \begin_layout Standard
2577
2578 \series bold
2579 Default
2580 \end_layout
2581
2582 \end_inset
2583 </cell>
2584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2585 \begin_inset Text
2586
2587 \begin_layout Standard
2588
2589 \series bold
2590 Win32 builds
2591 \end_layout
2592
2593 \end_inset
2594 </cell>
2595 </row>
2596 <row topline="true">
2597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2598 \begin_inset Text
2599
2600 \begin_layout Standard
2601 Binary files*
2602 \end_layout
2603
2604 \end_inset
2605 </cell>
2606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2607 \begin_inset Text
2608
2609 \begin_layout Standard
2610
2611 \emph on
2612 $EXEC_PREFIX
2613 \end_layout
2614
2615 \end_inset
2616 </cell>
2617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2618 \begin_inset Text
2619
2620 \begin_layout Standard
2621 /usr/local/bin
2622 \end_layout
2623
2624 \end_inset
2625 </cell>
2626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2627 \begin_inset Text
2628
2629 \begin_layout Standard
2630
2631 \backslash
2632 sdcc
2633 \backslash
2634 bin
2635 \end_layout
2636
2637 \end_inset
2638 </cell>
2639 </row>
2640 <row topline="true">
2641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2642 \begin_inset Text
2643
2644 \begin_layout Standard
2645 Include files
2646 \end_layout
2647
2648 \end_inset
2649 </cell>
2650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2651 \begin_inset Text
2652
2653 \begin_layout Standard
2654
2655 \emph on
2656 $DATADIR/ $INCLUDE_DIR_SUFFIX
2657 \end_layout
2658
2659 \end_inset
2660 </cell>
2661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2662 \begin_inset Text
2663
2664 \begin_layout Standard
2665 /usr/local/share/sdcc/include
2666 \end_layout
2667
2668 \end_inset
2669 </cell>
2670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2671 \begin_inset Text
2672
2673 \begin_layout Standard
2674
2675 \backslash
2676 sdcc
2677 \backslash
2678 include
2679 \end_layout
2680
2681 \end_inset
2682 </cell>
2683 </row>
2684 <row topline="true">
2685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2686 \begin_inset Text
2687
2688 \begin_layout Standard
2689 Library file**
2690 \end_layout
2691
2692 \end_inset
2693 </cell>
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2695 \begin_inset Text
2696
2697 \begin_layout Standard
2698
2699 \emph on
2700 $DATADIR/$LIB_DIR_SUFFIX
2701 \end_layout
2702
2703 \end_inset
2704 </cell>
2705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2706 \begin_inset Text
2707
2708 \begin_layout Standard
2709 /usr/local/share/sdcc/lib
2710 \end_layout
2711
2712 \end_inset
2713 </cell>
2714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2715 \begin_inset Text
2716
2717 \begin_layout Standard
2718
2719 \backslash
2720 sdcc
2721 \backslash
2722 lib
2723 \end_layout
2724
2725 \end_inset
2726 </cell>
2727 </row>
2728 <row topline="true" bottomline="true">
2729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2730 \begin_inset Text
2731
2732 \begin_layout Standard
2733 Documentation
2734 \end_layout
2735
2736 \end_inset
2737 </cell>
2738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2739 \begin_inset Text
2740
2741 \begin_layout Standard
2742
2743 \emph on
2744 $DOCDIR
2745 \end_layout
2746
2747 \end_inset
2748 </cell>
2749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2750 \begin_inset Text
2751
2752 \begin_layout Standard
2753 /usr/local/share/sdcc/doc
2754 \end_layout
2755
2756 \end_inset
2757 </cell>
2758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2759 \begin_inset Text
2760
2761 \begin_layout Standard
2762
2763 \backslash
2764 sdcc
2765 \backslash
2766 doc
2767 \end_layout
2768
2769 \end_inset
2770 </cell>
2771 </row>
2772 </lyxtabular>
2773
2774 \end_inset
2775
2776
2777 \end_layout
2778
2779 \begin_layout Verse
2780
2781 \size footnotesize
2782 *compiler, preprocessor, assembler, and linker
2783 \newline
2784 **the 
2785 \shape italic
2786 model
2787 \shape default
2788  is auto-appended by the compiler, e.g.
2789  small, large, z80, ds390 etc
2790 \end_layout
2791
2792 \begin_layout Standard
2793 \noindent
2794 The install paths can still be changed during `make install` with e.g.:
2795 \end_layout
2796
2797 \begin_layout LyX-Code
2798 make install prefix=$(HOME)/local/sdcc
2799 \end_layout
2800
2801 \begin_layout Standard
2802 Of course this doesn't change the search paths compiled into the binaries.
2803 \newline
2804
2805 \newline
2806 Moreove
2807 r the install path can be changed by defining DESTDIR
2808 \begin_inset LatexCommand \index{DESTDIR}
2809
2810 \end_inset
2811
2812 :
2813 \end_layout
2814
2815 \begin_layout LyX-Code
2816 make install DESTDIR=$(HOME)/sdcc.rpm/
2817 \end_layout
2818
2819 \begin_layout Standard
2820 Please note that DESTDIR must have a trailing slash!
2821 \end_layout
2822
2823 \begin_layout Section
2824 Search Paths
2825 \begin_inset LatexCommand \label{sub:Search-Paths}
2826
2827 \end_inset
2828
2829
2830 \begin_inset LatexCommand \index{Search path}
2831
2832 \end_inset
2833
2834
2835 \end_layout
2836
2837 \begin_layout Standard
2838 Some search paths or parts of them are determined by configure variables
2839  (in 
2840 \emph on
2841 italics
2842 \emph default
2843 , see section above).
2844  Further search paths are determined by environment variables during runtime.
2845  
2846 \newline
2847 The paths searched when running the compiler are as follows (the first
2848  catch wins):
2849 \newline
2850
2851 \newline
2852 1.
2853  Binary files (preprocessor, assembler and linker)
2854 \newline
2855
2856 \end_layout
2857
2858 \begin_layout Standard
2859 \align center
2860 \begin_inset Tabular
2861 <lyxtabular version="3" rows="4" columns="3">
2862 <features>
2863 <column alignment="block" valignment="top" leftline="true" width="0in">
2864 <column alignment="block" valignment="top" leftline="true" width="0in">
2865 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2866 <row topline="true" bottomline="true">
2867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2868 \begin_inset Text
2869
2870 \begin_layout Standard
2871 Search path
2872 \end_layout
2873
2874 \end_inset
2875 </cell>
2876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2877 \begin_inset Text
2878
2879 \begin_layout Standard
2880 default
2881 \end_layout
2882
2883 \end_inset
2884 </cell>
2885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2886 \begin_inset Text
2887
2888 \begin_layout Standard
2889 Win32 builds
2890 \end_layout
2891
2892 \end_inset
2893 </cell>
2894 </row>
2895 <row topline="true">
2896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2897 \begin_inset Text
2898
2899 \begin_layout Standard
2900 $SDCC_HOME/
2901 \emph on
2902 $PPREFIX2BIN_DIR
2903 \end_layout
2904
2905 \end_inset
2906 </cell>
2907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2908 \begin_inset Text
2909
2910 \begin_layout Standard
2911 $SDCC_HOME/bin
2912 \end_layout
2913
2914 \end_inset
2915 </cell>
2916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2917 \begin_inset Text
2918
2919 \begin_layout Standard
2920 $SDCC_HOME
2921 \backslash
2922 bin
2923 \end_layout
2924
2925 \end_inset
2926 </cell>
2927 </row>
2928 <row topline="true">
2929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2930 \begin_inset Text
2931
2932 \begin_layout Standard
2933 Path of argv[0] (if available)
2934 \end_layout
2935
2936 \end_inset
2937 </cell>
2938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2939 \begin_inset Text
2940
2941 \begin_layout Standard
2942 Path of argv[0]
2943 \end_layout
2944
2945 \end_inset
2946 </cell>
2947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2948 \begin_inset Text
2949
2950 \begin_layout Standard
2951 Path of argv[0]
2952 \end_layout
2953
2954 \end_inset
2955 </cell>
2956 </row>
2957 <row topline="true" bottomline="true">
2958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2959 \begin_inset Text
2960
2961 \begin_layout Standard
2962 $PATH
2963 \end_layout
2964
2965 \end_inset
2966 </cell>
2967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2968 \begin_inset Text
2969
2970 \begin_layout Standard
2971 $PATH
2972 \end_layout
2973
2974 \end_inset
2975 </cell>
2976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2977 \begin_inset Text
2978
2979 \begin_layout Standard
2980 $PATH
2981 \end_layout
2982
2983 \end_inset
2984 </cell>
2985 </row>
2986 </lyxtabular>
2987
2988 \end_inset
2989
2990  
2991 \newline
2992
2993 \end_layout
2994
2995 \begin_layout Standard
2996 \noindent
2997 2.
2998  Include files
2999 \newline
3000
3001 \end_layout
3002
3003 \begin_layout Standard
3004 \align center
3005 \begin_inset Tabular
3006 <lyxtabular version="3" rows="6" columns="3">
3007 <features>
3008 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3009 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3010 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3011 <row topline="true" bottomline="true">
3012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3013 \begin_inset Text
3014
3015 \begin_layout Standard
3016 Search path
3017 \end_layout
3018
3019 \end_inset
3020 </cell>
3021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3022 \begin_inset Text
3023
3024 \begin_layout Standard
3025 default
3026 \end_layout
3027
3028 \end_inset
3029 </cell>
3030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3031 \begin_inset Text
3032
3033 \begin_layout Standard
3034 Win32 builds
3035 \end_layout
3036
3037 \end_inset
3038 </cell>
3039 </row>
3040 <row topline="true">
3041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3042 \begin_inset Text
3043
3044 \begin_layout Standard
3045 -
3046 \begin_inset ERT
3047 status collapsed
3048
3049 \begin_layout Standard
3050
3051
3052 \backslash
3053 /
3054 \end_layout
3055
3056 \end_inset
3057
3058 -I dir
3059 \end_layout
3060
3061 \end_inset
3062 </cell>
3063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3064 \begin_inset Text
3065
3066 \begin_layout Standard
3067 -
3068 \begin_inset ERT
3069 status collapsed
3070
3071 \begin_layout Standard
3072
3073
3074 \backslash
3075 /
3076 \end_layout
3077
3078 \end_inset
3079
3080 -I dir
3081 \end_layout
3082
3083 \end_inset
3084 </cell>
3085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3086 \begin_inset Text
3087
3088 \begin_layout Standard
3089 -
3090 \begin_inset ERT
3091 status collapsed
3092
3093 \begin_layout Standard
3094
3095
3096 \backslash
3097 /
3098 \end_layout
3099
3100 \end_inset
3101
3102 -I dir
3103 \end_layout
3104
3105 \end_inset
3106 </cell>
3107 </row>
3108 <row topline="true">
3109 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3110 \begin_inset Text
3111
3112 \begin_layout Standard
3113 $SDCC_INCLUDE
3114 \end_layout
3115
3116 \end_inset
3117 </cell>
3118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3119 \begin_inset Text
3120
3121 \begin_layout Standard
3122 $SDCC_INCLUDE
3123 \end_layout
3124
3125 \end_inset
3126 </cell>
3127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3128 \begin_inset Text
3129
3130 \begin_layout Standard
3131 $SDCC_INCLUDE
3132 \end_layout
3133
3134 \end_inset
3135 </cell>
3136 </row>
3137 <row topline="true">
3138 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3139 \begin_inset Text
3140
3141 \begin_layout Standard
3142 $SDCC_HOME/
3143 \newline
3144
3145 \emph on
3146 $PREFIX2DATA_DIR/
3147 \newline
3148 $INCLUDE_DIR_SUFFIX
3149 \end_layout
3150
3151 \end_inset
3152 </cell>
3153 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3154 \begin_inset Text
3155
3156 \begin_layout Standard
3157 $SDCC_ HOME/
3158 \newline
3159 share/sdcc/
3160 \newline
3161 include
3162 \end_layout
3163
3164 \end_inset
3165 </cell>
3166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3167 \begin_inset Text
3168
3169 \begin_layout Standard
3170 $SDCC_HOME
3171 \backslash
3172 include
3173 \end_layout
3174
3175 \end_inset
3176 </cell>
3177 </row>
3178 <row topline="true">
3179 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3180 \begin_inset Text
3181
3182 \begin_layout Standard
3183 path(argv[0])/
3184 \newline
3185
3186 \emph on
3187 $BIN2DATADIR/
3188 \emph default
3189
3190 \newline
3191
3192 \emph on
3193 $INCLUDE_DIR_SUFFIX
3194 \end_layout
3195
3196 \end_inset
3197 </cell>
3198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3199 \begin_inset Text
3200
3201 \begin_layout Standard
3202 path(argv[0])/
3203 \newline
3204 ../sdcc/include
3205 \newline
3206 \InsetSpace ~
3207 \InsetSpace ~
3208 \InsetSpace ~
3209 \InsetSpace ~
3210 \InsetSpace ~
3211 \InsetSpace ~
3212 \InsetSpace ~
3213 \InsetSpace ~
3214 \InsetSpace ~
3215 \InsetSpace ~
3216 \InsetSpace ~
3217 \InsetSpace ~
3218 \InsetSpace ~
3219 \InsetSpace ~
3220 \InsetSpace ~
3221 \InsetSpace ~
3222 \InsetSpace ~
3223 \InsetSpace ~
3224 \InsetSpace ~
3225 \InsetSpace ~
3226 \InsetSpace ~
3227 \InsetSpace ~
3228 \InsetSpace ~
3229 \InsetSpace ~
3230 \InsetSpace ~
3231 \InsetSpace ~
3232 \InsetSpace ~
3233 \InsetSpace ~
3234 \InsetSpace ~
3235 \InsetSpace ~
3236 \InsetSpace ~
3237 \InsetSpace ~
3238 \InsetSpace ~
3239 \InsetSpace ~
3240 \InsetSpace ~
3241 \InsetSpace ~
3242 \InsetSpace ~
3243 \InsetSpace ~
3244
3245 \end_layout
3246
3247 \end_inset
3248 </cell>
3249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3250 \begin_inset Text
3251
3252 \begin_layout Standard
3253 path(argv[0])
3254 \backslash
3255 ..
3256 \backslash
3257 include
3258 \end_layout
3259
3260 \end_inset
3261 </cell>
3262 </row>
3263 <row topline="true" bottomline="true">
3264 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3265 \begin_inset Text
3266
3267 \begin_layout Standard
3268
3269 \emph on
3270 $DATADIR/
3271 \emph default
3272
3273 \newline
3274
3275 \emph on
3276 $INCLUDE_DIR_SUFFIX
3277 \end_layout
3278
3279 \end_inset
3280 </cell>
3281 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3282 \begin_inset Text
3283
3284 \begin_layout Standard
3285 /usr/local/share/sdcc/
3286 \newline
3287 include
3288 \end_layout
3289
3290 \end_inset
3291 </cell>
3292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3293 \begin_inset Text
3294
3295 \begin_layout Standard
3296 (not on Win32)
3297 \end_layout
3298
3299 \end_inset
3300 </cell>
3301 </row>
3302 </lyxtabular>
3303
3304 \end_inset
3305
3306  
3307 \newline
3308
3309 \end_layout
3310
3311 \begin_layout Standard
3312 \noindent
3313 The option -
3314 \begin_inset ERT
3315 status collapsed
3316
3317 \begin_layout Standard
3318
3319
3320 \backslash
3321 /
3322 \end_layout
3323
3324 \end_inset
3325
3326 -nostdinc disables the last two search paths.
3327 \newline
3328
3329 \newline
3330 3.
3331  Library files 
3332 \newline
3333
3334 \end_layout
3335
3336 \begin_layout Standard
3337 With the exception of 
3338 \begin_inset Quotes sld
3339 \end_inset
3340
3341 -
3342 \begin_inset ERT
3343 status collapsed
3344
3345 \begin_layout Standard
3346
3347
3348 \backslash
3349 /
3350 \end_layout
3351
3352 \end_inset
3353
3354 -L dir
3355 \begin_inset Quotes srd
3356 \end_inset
3357
3358  the 
3359 \shape italic
3360 model
3361 \shape default
3362  is auto-appended by the compiler (e.g.
3363  small, large, z80, ds390 etc.).
3364  
3365 \newline
3366
3367 \end_layout
3368
3369 \begin_layout Standard
3370 \align center
3371 \begin_inset Tabular
3372 <lyxtabular version="3" rows="6" columns="3">
3373 <features>
3374 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3375 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3376 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3377 <row topline="true" bottomline="true">
3378 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3379 \begin_inset Text
3380
3381 \begin_layout Standard
3382 Search path
3383 \end_layout
3384
3385 \end_inset
3386 </cell>
3387 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3388 \begin_inset Text
3389
3390 \begin_layout Standard
3391 default
3392 \end_layout
3393
3394 \end_inset
3395 </cell>
3396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3397 \begin_inset Text
3398
3399 \begin_layout Standard
3400 Win32 builds
3401 \end_layout
3402
3403 \end_inset
3404 </cell>
3405 </row>
3406 <row topline="true">
3407 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3408 \begin_inset Text
3409
3410 \begin_layout Standard
3411 -
3412 \begin_inset ERT
3413 status collapsed
3414
3415 \begin_layout Standard
3416
3417
3418 \backslash
3419 /
3420 \end_layout
3421
3422 \end_inset
3423
3424 -L dir
3425 \end_layout
3426
3427 \end_inset
3428 </cell>
3429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3430 \begin_inset Text
3431
3432 \begin_layout Standard
3433 -
3434 \begin_inset ERT
3435 status collapsed
3436
3437 \begin_layout Standard
3438
3439
3440 \backslash
3441 /
3442 \end_layout
3443
3444 \end_inset
3445
3446 -L dir
3447 \end_layout
3448
3449 \end_inset
3450 </cell>
3451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3452 \begin_inset Text
3453
3454 \begin_layout Standard
3455 -
3456 \begin_inset ERT
3457 status collapsed
3458
3459 \begin_layout Standard
3460
3461
3462 \backslash
3463 /
3464 \end_layout
3465
3466 \end_inset
3467
3468 -L dir
3469 \end_layout
3470
3471 \end_inset
3472 </cell>
3473 </row>
3474 <row topline="true">
3475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3476 \begin_inset Text
3477
3478 \begin_layout Standard
3479 $SDCC_LIB/
3480 \newline
3481
3482 \emph on
3483 <model>
3484 \end_layout
3485
3486 \end_inset
3487 </cell>
3488 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3489 \begin_inset Text
3490
3491 \begin_layout Standard
3492 $SDCC_LIB/
3493 \newline
3494
3495 \emph on
3496 <model>
3497 \end_layout
3498
3499 \end_inset
3500 </cell>
3501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3502 \begin_inset Text
3503
3504 \begin_layout Standard
3505 $SDCC_LIB
3506 \backslash
3507
3508 \newline
3509
3510 \emph on
3511 <model>
3512 \end_layout
3513
3514 \end_inset
3515 </cell>
3516 </row>
3517 <row topline="true">
3518 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3519 \begin_inset Text
3520
3521 \begin_layout Standard
3522 $SDCC_HOME/
3523 \newline
3524
3525 \emph on
3526 $PREFIX2DATA_DIR/
3527 \newline
3528 $LIB_DIR_SUFFIX/<model>
3529 \end_layout
3530
3531 \end_inset
3532 </cell>
3533 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3534 \begin_inset Text
3535
3536 \begin_layout Standard
3537 $SDCC_HOME/
3538 \newline
3539 share/sdcc/
3540 \newline
3541 lib/
3542 \emph on
3543 <model>
3544 \end_layout
3545
3546 \end_inset
3547 </cell>
3548 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3549 \begin_inset Text
3550
3551 \begin_layout Standard
3552 $SDCC_HOME
3553 \backslash
3554 lib
3555 \backslash
3556
3557 \emph on
3558
3559 \newline
3560 <model>
3561 \end_layout
3562
3563 \end_inset
3564 </cell>
3565 </row>
3566 <row topline="true">
3567 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3568 \begin_inset Text
3569
3570 \begin_layout Standard
3571 path(argv[0])/
3572 \newline
3573
3574 \emph on
3575 $BIN2DATADIR/
3576 \emph default
3577
3578 \newline
3579
3580 \emph on
3581 $LIB_DIR_SUFFIX/<model>
3582 \end_layout
3583
3584 \end_inset
3585 </cell>
3586 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3587 \begin_inset Text
3588
3589 \begin_layout Standard
3590 path(argv[0])/
3591 \newline
3592 ../sdcc/lib/
3593 \emph on
3594 <model>
3595 \newline
3596 \InsetSpace ~
3597 \InsetSpace ~
3598 \InsetSpace ~
3599 \InsetSpace ~
3600 \InsetSpace ~
3601 \InsetSpace ~
3602 \InsetSpace ~
3603 \InsetSpace ~
3604 \InsetSpace ~
3605 \InsetSpace ~
3606 \InsetSpace ~
3607 \InsetSpace ~
3608 \InsetSpace ~
3609 \InsetSpace ~
3610 \InsetSpace ~
3611 \InsetSpace ~
3612 \InsetSpace ~
3613 \InsetSpace ~
3614 \InsetSpace ~
3615 \InsetSpace ~
3616 \InsetSpace ~
3617 \InsetSpace ~
3618 \InsetSpace ~
3619 \InsetSpace ~
3620 \InsetSpace ~
3621 \InsetSpace ~
3622 \InsetSpace ~
3623 \InsetSpace ~
3624 \InsetSpace ~
3625 \InsetSpace ~
3626 \InsetSpace ~
3627 \InsetSpace ~
3628 \InsetSpace ~
3629 \InsetSpace ~
3630 \InsetSpace ~
3631 \InsetSpace ~
3632 \InsetSpace ~
3633 \InsetSpace ~
3634 \InsetSpace ~
3635
3636 \end_layout
3637
3638 \end_inset
3639 </cell>
3640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3641 \begin_inset Text
3642
3643 \begin_layout Standard
3644 path(argv[0])
3645 \backslash
3646
3647 \newline
3648 ..
3649 \backslash
3650 lib
3651 \backslash
3652
3653 \emph on
3654 <model>
3655 \newline
3656 \InsetSpace ~
3657 \InsetSpace ~
3658 \InsetSpace ~
3659 \InsetSpace ~
3660 \InsetSpace ~
3661 \InsetSpace ~
3662 \InsetSpace ~
3663 \InsetSpace ~
3664 \InsetSpace ~
3665 \InsetSpace ~
3666 \InsetSpace ~
3667 \InsetSpace ~
3668 \InsetSpace ~
3669 \InsetSpace ~
3670 \InsetSpace ~
3671 \InsetSpace ~
3672 \InsetSpace ~
3673 \InsetSpace ~
3674 \InsetSpace ~
3675 \InsetSpace ~
3676 \InsetSpace ~
3677 \InsetSpace ~
3678 \InsetSpace ~
3679 \InsetSpace ~
3680 \InsetSpace ~
3681 \InsetSpace ~
3682 \InsetSpace ~
3683 \InsetSpace ~
3684 \InsetSpace ~
3685 \InsetSpace ~
3686 \InsetSpace ~
3687 \InsetSpace ~
3688 \InsetSpace ~
3689 \InsetSpace ~
3690 \InsetSpace ~
3691
3692 \end_layout
3693
3694 \end_inset
3695 </cell>
3696 </row>
3697 <row topline="true" bottomline="true">
3698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3699 \begin_inset Text
3700
3701 \begin_layout Standard
3702
3703 \emph on
3704 $DATADIR/
3705 \newline
3706 $LIB_DIR_SUFFIX/<model>
3707 \end_layout
3708
3709 \end_inset
3710 </cell>
3711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3712 \begin_inset Text
3713
3714 \begin_layout Standard
3715 /usr/local/share/sdcc/
3716 \newline
3717 lib/
3718 \emph on
3719 <model>
3720 \end_layout
3721
3722 \end_inset
3723 </cell>
3724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3725 \begin_inset Text
3726
3727 \begin_layout Standard
3728 (not on Win32)
3729 \end_layout
3730
3731 \end_inset
3732 </cell>
3733 </row>
3734 </lyxtabular>
3735
3736 \end_inset
3737
3738
3739 \newline
3740
3741 \end_layout
3742
3743 \begin_layout Standard
3744 \begin_inset Note Comment
3745 status collapsed
3746
3747 \begin_layout Standard
3748 Don't delete any of the stray spaces in the table above without checking
3749  the HTML output (last line)!
3750 \end_layout
3751
3752 \end_inset
3753
3754
3755 \end_layout
3756
3757 \begin_layout Standard
3758 \InsetSpace ~
3759
3760 \newline
3761 The option -
3762 \begin_inset ERT
3763 status collapsed
3764
3765 \begin_layout Standard
3766
3767
3768 \backslash
3769 /
3770 \end_layout
3771
3772 \end_inset
3773
3774 -nostdlib disables the last two search paths.
3775 \end_layout
3776
3777 \begin_layout Section
3778 Building SDCC
3779 \begin_inset LatexCommand \index{Building SDCC}
3780
3781 \end_inset
3782
3783
3784 \end_layout
3785
3786 \begin_layout Subsection
3787 Building SDCC on Linux
3788 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3789
3790 \end_inset
3791
3792
3793 \end_layout
3794
3795 \begin_layout Enumerate
3796
3797 \series medium
3798 Download the source package
3799 \series default
3800  either from the SDCC Subversion repository or from the nightly snapshots
3801 \series medium
3802 , it will be named something like sdcc
3803 \series default
3804 .src
3805 \series medium
3806 .t
3807 \series default
3808 ar.
3809 \series medium
3810 gz
3811 \series default
3812  
3813 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3814
3815 \end_inset
3816
3817 .
3818 \end_layout
3819
3820 \begin_layout Enumerate
3821
3822 \series medium
3823 Bring up a command line terminal, such as xterm.
3824 \end_layout
3825
3826 \begin_layout Enumerate
3827
3828 \series medium
3829 Unpack the file using a command like: 
3830 \family sans
3831 \series bold
3832 "tar -xvzf sdcc.src.tar.gz
3833 \family default
3834 \series default
3835 "
3836 \series medium
3837 , this will create a sub-directory called sdcc with all of the sources.
3838 \end_layout
3839
3840 \begin_layout Enumerate
3841 Change directory into the main SDCC directory, for example type: 
3842 \family sans
3843 \series bold
3844 "cd sdcc
3845 \series default
3846 ".
3847 \end_layout
3848
3849 \begin_layout Enumerate
3850
3851 \series medium
3852 Type 
3853 \family sans
3854 \series bold
3855 "./configure
3856 \family default
3857 \series default
3858 ".
3859  This configures the package for compilation on your system.
3860 \end_layout
3861
3862 \begin_layout Enumerate
3863
3864 \series medium
3865 Type 
3866 \family sans
3867 \series bold
3868 "make
3869 \family default
3870 \series default
3871 "
3872 \series medium
3873 .
3874
3875 \series default
3876  All of the source packages will compile, this can take a while.
3877 \end_layout
3878
3879 \begin_layout Enumerate
3880
3881 \series medium
3882 Type 
3883 \family sans
3884 \series bold
3885 "make install"
3886 \family default
3887 \series default
3888  as root
3889 \series medium
3890 .
3891
3892 \series default
3893  This copies the binary executables, the include files, the libraries and
3894  the documentation to the install directories.
3895  Proceed with section 
3896 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3897
3898 \end_inset
3899
3900 .
3901 \end_layout
3902
3903 \begin_layout Subsection
3904 Building SDCC on OSX 2.x
3905 \end_layout
3906
3907 \begin_layout Standard
3908 Follow the instruction for Linux.
3909 \newline
3910
3911 \newline
3912 On OSX 2.x it was reported, that the default
3913  gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3914  Fortunately there's also gcc 2.9.x installed, which works fine.
3915  This compiler can be selected by running 'configure' with:
3916 \end_layout
3917
3918 \begin_layout LyX-Code
3919 ./configure CC=gcc2 CXX=g++2
3920 \end_layout
3921
3922 \begin_layout Subsection
3923 Cross compiling SDCC on Linux for Windows
3924 \end_layout
3925
3926 \begin_layout Standard
3927 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3928  See section 'Configure Options'.
3929 \end_layout
3930
3931 \begin_layout Subsection
3932 Building SDCC using Cygwin and Mingw32
3933 \end_layout
3934
3935 \begin_layout Standard
3936 For building and installing a Cygwin executable follow the instructions
3937  for Linux.
3938 \newline
3939
3940 \newline
3941 On Cygwin a 
3942 \begin_inset Quotes sld
3943 \end_inset
3944
3945 native
3946 \begin_inset Quotes srd
3947 \end_inset
3948
3949  Win32-binary can be built, which will not need the Cygwin-DLL.
3950  For the necessary 'configure' options see section 'configure options' or
3951  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3952 \newline
3953
3954 \newline
3955 In order to install
3956  Cygwin on Windows download setup.exe from 
3957 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3958
3959 \end_inset
3960
3961 .
3962  Run it, set the 
3963 \begin_inset Quotes sld
3964 \end_inset
3965
3966 default text file type
3967 \begin_inset Quotes srd
3968 \end_inset
3969
3970  to 
3971 \begin_inset Quotes sld
3972 \end_inset
3973
3974 unix
3975 \begin_inset Quotes srd
3976 \end_inset
3977
3978  and download/install at least the following packages.
3979  Some packages are selected by default, others will be automatically selected
3980  because of dependencies with the manually selected packages.
3981  Never deselect these packages!
3982 \end_layout
3983
3984 \begin_layout Itemize
3985 flex
3986 \end_layout
3987
3988 \begin_layout Itemize
3989 bison
3990 \end_layout
3991
3992 \begin_layout Itemize
3993 gcc ; version 3.x is fine, no need to use the old 2.9x
3994 \end_layout
3995
3996 \begin_layout Itemize
3997 binutils ; selected with gcc
3998 \end_layout
3999
4000 \begin_layout Itemize
4001 make
4002 \end_layout
4003
4004 \begin_layout Itemize
4005 rxvt ; a nice console, which makes life much easier under windoze (see below)
4006 \end_layout
4007
4008 \begin_layout Itemize
4009 man ; not really needed for building SDCC, but you'll miss it sooner or
4010  later
4011 \end_layout
4012
4013 \begin_layout Itemize
4014 less ; not really needed for building SDCC, but you'll miss it sooner or
4015  later
4016 \end_layout
4017
4018 \begin_layout Itemize
4019 svn ; only if you use Subversion access
4020 \end_layout
4021
4022 \begin_layout Standard
4023 If you want to develop something you'll need:
4024 \end_layout
4025
4026 \begin_layout Itemize
4027 python ; for the regression tests
4028 \end_layout
4029
4030 \begin_layout Itemize
4031 gdb ; the gnu debugger, together with the nice GUI 
4032 \begin_inset Quotes sld
4033 \end_inset
4034
4035 insight
4036 \begin_inset Quotes srd
4037 \end_inset
4038
4039
4040 \end_layout
4041
4042 \begin_layout Itemize
4043 openssh ; to access the CF or commit changes
4044 \end_layout
4045
4046 \begin_layout Itemize
4047 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4048  use autoconf-stable!
4049 \end_layout
4050
4051 \begin_layout Standard
4052 rxvt is a nice console with history.
4053  Replace in your cygwin.bat the line
4054 \end_layout
4055
4056 \begin_layout LyX-Code
4057 bash -
4058 \begin_inset ERT
4059 status collapsed
4060
4061 \begin_layout Standard
4062
4063
4064 \backslash
4065 /
4066 \end_layout
4067
4068 \end_inset
4069
4070 -login -i 
4071 \end_layout
4072
4073 \begin_layout Standard
4074 with (one line):
4075 \end_layout
4076
4077 \begin_layout LyX-Code
4078 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4079 \end_layout
4080
4081 \begin_layout LyX-Code
4082      -bg black -fg white -geometry 100x65 -e bash -
4083 \begin_inset ERT
4084 status collapsed
4085
4086 \begin_layout Standard
4087
4088
4089 \backslash
4090 /
4091 \end_layout
4092
4093 \end_inset
4094
4095 -login
4096 \end_layout
4097
4098 \begin_layout Standard
4099 Text selected with the mouse is automatically copied to the clipboard, pasting
4100  works with shift-insert.
4101 \newline
4102
4103 \newline
4104 The other good tip is to make sure you have no //c/-styl
4105 e paths anywhere, use /cygdrive/c/ instead.
4106  Using // invokes a network lookup which is very slow.
4107  If you think 
4108 \begin_inset Quotes sld
4109 \end_inset
4110
4111 cygdrive
4112 \begin_inset Quotes srd
4113 \end_inset
4114
4115  is too long, you can change it with e.g.
4116 \end_layout
4117
4118 \begin_layout LyX-Code
4119 mount -s -u -c /mnt
4120 \end_layout
4121
4122 \begin_layout Standard
4123 SDCC sources use the unix line ending LF.
4124  Life is much easier, if you store the source tree on a drive which is mounted
4125  in binary mode.
4126  And use an editor which can handle LF-only line endings.
4127  Make sure not to commit files with windows line endings.
4128  The tabulator spacing
4129 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4130
4131 \end_inset
4132
4133  used in the project is 8.
4134  Although a tabulator spacing of 8 is a sensible choice for programmers
4135  (it's a power of 2 and allows to display 8/16 bit signed variables without
4136  loosing columns) the plan is to move towards using only spaces in the source.
4137 \end_layout
4138
4139 \begin_layout Subsection
4140 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4141 \end_layout
4142
4143 \begin_layout Standard
4144
4145 \series medium
4146 Download the source package
4147 \series default
4148  either from the SDCC Subversion repository or from the 
4149 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
4150
4151 \end_inset
4152
4153
4154 \series medium
4155 , it will be named something like sdcc
4156 \series default
4157 .src
4158 \series medium
4159 .tgz.
4160
4161 \series default
4162  SDCC is distributed with all the projects, workspaces, and files you need
4163  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4164  The workspace name is 'sdcc.dsw'.
4165  Please note that as it is now, all the executables are created in a folder
4166  called sdcc
4167 \backslash
4168 bin_vc.
4169  Once built you need to copy the executables from sdcc
4170 \backslash
4171 bin_vc to sdcc
4172 \backslash
4173 bin before running SDCC.
4174  
4175 \newline
4176
4177 \newline
4178 WARNING: Visual studio is very picky with line terminations; it expects
4179  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4180  When using the Subversion repository it's easiest to configure the svn
4181  client to convert automatically for you.
4182  If however you are getting a message such as "This makefile was not generated
4183  by Developer Studio etc.
4184  etc.
4185 \begin_inset Quotes srd
4186 \end_inset
4187
4188  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4189  need to convert the Unix style line endings to DOS style line endings.
4190  To do so you can use the 
4191 \begin_inset Quotes sld
4192 \end_inset
4193
4194 unix2dos
4195 \begin_inset Quotes srd
4196 \end_inset
4197
4198  utility freely available on the internet.
4199  Doug Hawkins reported in the sdcc-user list that this works:
4200 \newline
4201
4202 \newline
4203 C:
4204 \backslash
4205 Programming
4206 \backslash
4207 SDCC> unix2dos sdcc.dsw
4208 \newline
4209 C:
4210 \backslash
4211 Programming
4212 \backslash
4213 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4214 \newline
4215
4216 \newline
4217 In order to build SDCC with MSVC
4218  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4219  One good place to get them is 
4220 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4221
4222 \end_inset
4223
4224
4225 \newline
4226
4227 \newline
4228 Download the file UnxUtils
4229 \begin_inset LatexCommand \index{UnxUtils}
4230
4231 \end_inset
4232
4233 .zip.
4234  Now you have to install the utilities and setup MSVC so it can locate the
4235  required programs.
4236  Here there are two alternatives (choose one!):
4237 \end_layout
4238
4239 \begin_layout Enumerate
4240 The easy way:
4241 \newline
4242
4243 \newline
4244 a) Extract UnxUtils.zip to your C:
4245 \backslash
4246  hard disk PRESERVING the original paths, otherwise bison won't work.
4247  (If you are using WinZip make certain that 'Use folder names' is selected)
4248 \newline
4249
4250 \newline
4251 b)
4252  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4253  'Show directories for:' select 'Executable files', and in the directories
4254  window add a new path: 'C:
4255 \backslash
4256 user
4257 \backslash
4258 local
4259 \backslash
4260 wbin', click ok.
4261 \newline
4262
4263 \newline
4264 (As a side effect, you get a bunch of Unix utilities that
4265  could be useful, such as diff and patch.)
4266 \end_layout
4267
4268 \begin_layout Enumerate
4269 A more compact way:
4270 \newline
4271
4272 \newline
4273 This one avoids extracting a bunch of files you may not
4274  use, but requires some extra work:
4275 \newline
4276
4277 \newline
4278 a) Create a directory were to put the
4279  tools needed, or use a directory already present.
4280  Say for example 'C:
4281 \backslash
4282 util'.
4283 \newline
4284
4285 \newline
4286 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4287  gawk.exe to such directory WITHOUT preserving the original paths.
4288  (If you are using WinZip make certain that 'Use folder names' is not selected)
4289 \newline
4290
4291 \newline
4292 c
4293 ) Rename bison.exe to '_bison.exe'.
4294 \newline
4295
4296 \newline
4297 d) Create a batch file 'bison.bat' in 'C:
4298 \backslash
4299 util
4300 \backslash
4301 ' and add these lines: 
4302 \newline
4303 \InsetSpace ~
4304 \InsetSpace ~
4305 set BISON_SIMPLE=C:
4306 \backslash
4307 util
4308 \backslash
4309 bison.simple 
4310 \newline
4311 \InsetSpace ~
4312 \InsetSpace ~
4313 set BISON_HAIRY=C:
4314 \backslash
4315 util
4316 \backslash
4317 bison.hairy
4318 \newline
4319 \InsetSpace ~
4320 \InsetSpace ~
4321 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4322 \newline
4323
4324 \newline
4325 Steps 'c' and 'd' are needed
4326  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4327  reside in some weird Unix directory, '/usr/local/share/' I think.
4328  So it is necessary to tell bison where those files are located if they
4329  are not in such directory.
4330  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4331 \newline
4332
4333 \newline
4334 e
4335 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4336  in 'Show directories for:' select 'Executable files', and in the directories
4337  window add a new path: 'c:
4338 \backslash
4339 util', click ok.
4340  Note that you can use any other path instead of 'c:
4341 \backslash
4342 util', even the path where the Visual C++ tools are, probably: 'C:
4343 \backslash
4344 Program Files
4345 \backslash
4346 Microsoft Visual Studio
4347 \backslash
4348 Common
4349 \backslash
4350 Tools'.
4351  So you don't have to execute step 'e' :)
4352 \end_layout
4353
4354 \begin_layout Standard
4355 That is it.
4356  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4357  the executables from sdcc
4358 \backslash
4359 bin_vc to sdcc
4360 \backslash
4361 bin, and you can compile using SDCC.
4362 \end_layout
4363
4364 \begin_layout Subsection
4365 Building SDCC Using Borland
4366 \end_layout
4367
4368 \begin_layout Enumerate
4369 From the sdcc directory, run the command "make -f Makefile.bcc".
4370  This should regenerate all the .exe files in the bin directory except for
4371  SDCDB and ucSim.
4372 \end_layout
4373
4374 \begin_layout Enumerate
4375 If you modify any source files and need to rebuild, be aware that the dependenci
4376 es may not be correctly calculated.
4377  The safest option is to delete all .obj files and run the build again.
4378  From a Cygwin BASH prompt, this can easily be done with the command (be
4379  sure you are in the sdcc directory):
4380 \newline
4381
4382 \newline
4383
4384 \family sans
4385 \series bold
4386 find .
4387  
4388 \backslash
4389 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4390 \backslash
4391 ) -print -exec rm {} 
4392 \backslash
4393 ;
4394 \family default
4395 \series default
4396
4397 \newline
4398
4399 \newline
4400 or on Windows NT/2000/XP from the command prompt with the command:
4401 \newline
4402
4403 \family sans
4404 \series bold
4405
4406 \newline
4407 del /s *.obj *.lib *.rul
4408 \family default
4409 \series default
4410  from the sdcc directory.
4411 \end_layout
4412
4413 \begin_layout Subsection
4414 Windows Install Using a ZIP Package
4415 \end_layout
4416
4417 \begin_layout Enumerate
4418 Download the binary zip package from 
4419 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4420
4421 \end_inset
4422
4423  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4424  This should unpack to a group of sub-directories.
4425  An example directory structure after unpacking the mingw32 package is:
4426  c:
4427 \backslash
4428 sdcc
4429 \backslash
4430 bin for the executables, c:
4431 \backslash
4432 sdcc
4433 \backslash
4434 include and c:
4435 \backslash
4436 sdcc
4437 \backslash
4438 lib for the include and libraries.
4439 \end_layout
4440
4441 \begin_layout Enumerate
4442 Adjust your environment variable PATH to include the location of the bin
4443  directory or start sdcc using the full path.
4444 \end_layout
4445
4446 \begin_layout Subsection
4447 Windows Install Using the Setup Program
4448 \begin_inset LatexCommand \label{sub:Windows-Install}
4449
4450 \end_inset
4451
4452
4453 \end_layout
4454
4455 \begin_layout Standard
4456 Download the setup program 
4457 \emph on
4458 sdcc-x.y.z-setup.exe
4459 \emph default
4460  for an official release from 
4461 \newline
4462
4463 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4464
4465 \end_inset
4466
4467  or a setup program for one of the snapshots 
4468 \emph on
4469 sdcc-yyyymmdd-xxxx-setup.exe
4470 \emph default
4471  from 
4472 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4473
4474 \end_inset
4475
4476  and execute it.
4477  A windows typical installer will guide you through the installation process.
4478 \end_layout
4479
4480 \begin_layout Subsection
4481 VPATH
4482 \begin_inset LatexCommand \index{VPATH}
4483
4484 \end_inset
4485
4486  feature
4487 \end_layout
4488
4489 \begin_layout Standard
4490 SDCC supports the VPATH feature provided by configure and make.
4491  It allows to separate the source and build trees.
4492  Here's an example:
4493 \end_layout
4494
4495 \begin_layout Standard
4496
4497 \family typewriter
4498 cd ~\InsetSpace ~
4499 \InsetSpace ~
4500 \InsetSpace ~
4501 \InsetSpace ~
4502 \InsetSpace ~
4503 \InsetSpace ~
4504 \InsetSpace ~
4505 \InsetSpace ~
4506 \InsetSpace ~
4507 \InsetSpace ~
4508 \InsetSpace ~
4509 \InsetSpace ~
4510 \InsetSpace ~
4511 \InsetSpace ~
4512 \InsetSpace ~
4513 \InsetSpace ~
4514 \InsetSpace ~
4515 \InsetSpace ~
4516 \InsetSpace ~
4517 \InsetSpace ~
4518 \InsetSpace ~
4519 # cd $HOME
4520 \end_layout
4521
4522 \begin_layout Standard
4523
4524 \family typewriter
4525 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4526 # extract source to directory sdcc
4527 \end_layout
4528
4529 \begin_layout Standard
4530
4531 \family typewriter
4532 mkdir sdcc.build\InsetSpace ~
4533 \InsetSpace ~
4534 \InsetSpace ~
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 \InsetSpace ~
4538 \InsetSpace ~
4539 \InsetSpace ~
4540 \InsetSpace ~
4541 # put output in sdcc.build
4542 \end_layout
4543
4544 \begin_layout Standard
4545
4546 \family typewriter
4547 cd sdcc.build
4548 \end_layout
4549
4550 \begin_layout Standard
4551
4552 \family typewriter
4553 ../sdcc/configure\InsetSpace ~
4554 \InsetSpace ~
4555 \InsetSpace ~
4556 \InsetSpace ~
4557 \InsetSpace ~
4558 \InsetSpace ~
4559 \InsetSpace ~
4560 \InsetSpace ~
4561 # configure is doing all the magic!
4562 \end_layout
4563
4564 \begin_layout Standard
4565
4566 \family typewriter
4567 make
4568 \end_layout
4569
4570 \begin_layout Standard
4571 \noindent
4572 That's it! 
4573 \series bold
4574 configure
4575 \series default
4576  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4577  It automagically computes the variables srcdir, top_srcdir and top_buildir
4578  for each directory.
4579  After running 
4580 \series bold
4581 make
4582 \series default
4583  the generated files will be in ~/sdcc.build, while the source files stay
4584  in ~/sdcc.
4585 \newline
4586 This is not only usefull for building different binaries, e.g.
4587  when cross compiling.
4588  It also gives you a much better overview in the source tree when all the
4589  generated files are not scattered between the source files.
4590  And the best thing is: if you want to change a file you can leave the original
4591  file untouched in the source directory.
4592  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4593  Makefile.dep` and `make`.
4594  
4595 \series bold
4596 make
4597 \series default
4598  will do the rest for you!
4599 \end_layout
4600
4601 \begin_layout Section
4602 Building the Documentation
4603 \end_layout
4604
4605 \begin_layout Standard
4606 Add -
4607 \begin_inset ERT
4608 status collapsed
4609
4610 \begin_layout Standard
4611
4612
4613 \backslash
4614 /
4615 \end_layout
4616
4617 \end_inset
4618
4619 -enable-doc to the configure arguments to build the documentation together
4620  with all the other stuff.
4621  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4622  dvips and makeindex) to get the job done.
4623  Another possibility is to change to the doc directory and to type 
4624 \family sans
4625 \series bold
4626
4627 \begin_inset Quotes srd
4628 \end_inset
4629
4630 make
4631 \begin_inset Quotes srd
4632 \end_inset
4633
4634
4635 \family default
4636 \series default
4637  there.
4638  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4639 x).
4640  Using LyX 
4641 \begin_inset LatexCommand \url{http://www.lyx.org}
4642
4643 \end_inset
4644
4645  as editor is straightforward.
4646  Prebuilt documentation in html and pdf format is available from 
4647 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4648
4649 \end_inset
4650
4651 .
4652 \end_layout
4653
4654 \begin_layout Section
4655 Reading the Documentation
4656 \begin_inset LatexCommand \index{Documentation}
4657
4658 \end_inset
4659
4660
4661 \end_layout
4662
4663 \begin_layout Standard
4664 Currently reading the document in pdf format is recommended, as for unknown
4665  reason the hyperlinks are working there whereas in the html version they
4666  are not
4667 \begin_inset Foot
4668 status open
4669
4670 \begin_layout Standard
4671 If you should know why please drop us a note
4672 \end_layout
4673
4674 \end_inset
4675
4676 .
4677  
4678 \newline
4679 You'll find the pdf version
4680 \begin_inset LatexCommand \index{PDF version of this document}
4681
4682 \end_inset
4683
4684  at 
4685 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4686
4687 \end_inset
4688
4689 .
4690  
4691 \newline
4692 A html version
4693 \begin_inset LatexCommand \index{HTML version of this document}
4694
4695 \end_inset
4696
4697  should be online at 
4698 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4699
4700 \end_inset
4701
4702 .
4703 \newline
4704 This documentation is in some aspects different from a commercial documentation:
4705  
4706 \end_layout
4707
4708 \begin_layout Itemize
4709 It tries to document SDCC for several processor architectures in one document
4710  (commercially these probably would be separate documents/products).
4711  This document
4712 \begin_inset LatexCommand \index{Status of documentation}
4713
4714 \end_inset
4715
4716  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4717 on about f.e.
4718  Z80, PIC14, PIC16 and HC08.
4719 \end_layout
4720
4721 \begin_layout Itemize
4722 There are many references pointing away from this documentation.
4723  Don't let this distract you.
4724  If there f.e.
4725  was a reference like 
4726 \begin_inset LatexCommand \url{http://www.opencores.org}
4727
4728 \end_inset
4729
4730  together with a statement 
4731 \begin_inset Quotes sld
4732 \end_inset
4733
4734 some processors which are targetted by SDCC can be implemented in a 
4735 \emph on
4736 f
4737 \emph default
4738 ield 
4739 \emph on
4740 p
4741 \emph default
4742 rogrammable 
4743 \emph on
4744 g
4745 \emph default
4746 ate 
4747 \emph on
4748 a
4749 \emph default
4750 rray
4751 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4752
4753 \end_inset
4754
4755
4756 \begin_inset Quotes srd
4757 \end_inset
4758
4759  or 
4760 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4761
4762 \end_inset
4763
4764
4765 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4766
4767 \end_inset
4768
4769  
4770 \begin_inset Quotes sld
4771 \end_inset
4772
4773 have you ever heard of an open source compiler that compiles a subset of
4774  C for an FPGA?
4775 \begin_inset Quotes srd
4776 \end_inset
4777
4778  we expect you to have a quick look there and come back.
4779  If you read this you are on the right track.
4780 \end_layout
4781
4782 \begin_layout Itemize
4783 Some sections attribute more space to problems, restrictions and warnings
4784  than to the solution.
4785 \end_layout
4786
4787 \begin_layout Itemize
4788 The installation section and the section about the debugger is intimidating.
4789 \end_layout
4790
4791 \begin_layout Itemize
4792 There are still lots of typos and there are more different writing styles
4793  than pictures.
4794 \end_layout
4795
4796 \begin_layout Section
4797 Testing the SDCC Compiler
4798 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4799
4800 \end_inset
4801
4802
4803 \end_layout
4804
4805 \begin_layout Standard
4806 The first thing you should do after installing your SDCC compiler is to
4807  see if it runs.
4808  Type 
4809 \family sans
4810 \series bold
4811 "sdcc -
4812 \begin_inset ERT
4813 status collapsed
4814
4815 \begin_layout Standard
4816
4817
4818 \backslash
4819 /
4820 \end_layout
4821
4822 \end_inset
4823
4824 -version"
4825 \begin_inset LatexCommand \index{version}
4826
4827 \end_inset
4828
4829
4830 \family default
4831 \series default
4832  at the prompt, and the program should run and output its version like:
4833  
4834 \newline
4835
4836 \family typewriter
4837 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4838  (UNIX)
4839 \end_layout
4840
4841 \begin_layout Standard
4842 If it doesn't run, or gives a message about not finding sdcc program, then
4843  you need to check over your installation.
4844  Make sure that the sdcc bin directory is in your executable search path
4845  defined by the PATH environment setting (
4846 \series medium
4847 see 
4848 \series default
4849 section 
4850 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4851
4852 \end_inset
4853
4854 \InsetSpace ~
4855
4856 \series medium
4857 Install trouble-shooting for suggestions
4858 \series default
4859 ).
4860  Make sure that the sdcc program is in the bin folder, if not perhaps something
4861  did not install correctly.
4862 \newline
4863
4864 \newline
4865
4866 \series medium
4867 SDCC 
4868 \series default
4869 is commonly installed as described in section 
4870 \begin_inset Quotes sld
4871 \end_inset
4872
4873 Install and search paths
4874 \begin_inset Quotes srd
4875 \end_inset
4876
4877 .
4878 \newline
4879
4880 \newline
4881
4882 \series medium
4883 Make sure the compiler works on a very simple example.
4884  Type in the following test.c program using your favorite 
4885 \series default
4886 ASCII 
4887 \series medium
4888 editor:
4889 \end_layout
4890
4891 \begin_layout Verse
4892
4893 \family typewriter
4894 char test;
4895 \newline
4896
4897 \newline
4898 void main(void) {
4899 \newline
4900 \InsetSpace ~
4901 \InsetSpace ~
4902 \InsetSpace ~
4903 \InsetSpace ~
4904 test=0;
4905 \newline
4906 }
4907 \end_layout
4908
4909 \begin_layout Standard
4910
4911 \series medium
4912 Compile this using the following command: 
4913 \family sans
4914 \series bold
4915 "sdcc -c test.c".
4916
4917 \family default
4918 \series default
4919  
4920 \series medium
4921 If all goes well, the compiler will generate a test.asm and test.rel file.
4922  Congratulations, you've just compiled your first program with SDCC.
4923  We used the -c option to tell SDCC not to link the generated code, just
4924  to keep things simple for this step.
4925 \series default
4926
4927 \newline
4928
4929 \newline
4930
4931 \series medium
4932 The next step is to try it with the linker.
4933  Type in 
4934 \family sans
4935 \series bold
4936 "sdcc test.c
4937 \family default
4938 \series default
4939 "
4940 \series medium
4941 .
4942  If all goes well the compiler will link with the libraries and produce
4943  a test.ihx output file.
4944  If this step fails
4945 \series default
4946  
4947 \series medium
4948 (no test.ihx, and the linker generates warnings), then the problem is most
4949  likely that 
4950 \series default
4951 SDCC
4952 \series medium
4953  cannot find the 
4954 \series default
4955 /
4956 \series medium
4957 usr/local/share/sdcc/lib directory
4958 \series default
4959  
4960 \series medium
4961 (see 
4962 \series default
4963 section 
4964 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4965
4966 \end_inset
4967
4968 \InsetSpace ~
4969
4970 \series medium
4971 Install trouble-shooting for suggestions).
4972 \series default
4973
4974 \newline
4975
4976 \newline
4977
4978 \series medium
4979 The final test is to ensure 
4980 \series default
4981 SDCC
4982 \series medium
4983  can use the 
4984 \series default
4985 standard
4986 \series medium
4987  header files and libraries.
4988  Edit test.c and change it to the following:
4989 \end_layout
4990
4991 \begin_layout Verse
4992
4993 \family typewriter
4994 #include <string.h>
4995 \newline
4996
4997 \newline
4998 char str1[10];
4999 \newline
5000
5001 \newline
5002 void main(void) {
5003 \newline
5004 \InsetSpace ~
5005 \InsetSpace ~
5006 strcpy(str1, "testing");
5007 \newline
5008 }
5009 \end_layout
5010
5011 \begin_layout Standard
5012
5013 \series medium
5014 Compile this by typing 
5015 \family sans
5016 \series bold
5017 "sdcc test.c"
5018 \family default
5019 \series medium
5020 .
5021  This should generate a test.ihx output file, and it should give no warnings
5022  such as not finding the string.h file.
5023  If it cannot find the string.h file, then the problem is that 
5024 \series default
5025 SDCC
5026 \series medium
5027  cannot find the /usr/local/share/sdcc/include directory
5028 \series default
5029  
5030 \series medium
5031 (see the 
5032 \series default
5033 section 
5034 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5035
5036 \end_inset
5037
5038 \InsetSpace ~
5039
5040 \series medium
5041 Install trouble-shooting section for suggestions).
5042
5043 \series default
5044  Use option 
5045 \series bold
5046 -
5047 \begin_inset ERT
5048 status collapsed
5049
5050 \begin_layout Standard
5051
5052
5053 \backslash
5054 /
5055 \end_layout
5056
5057 \end_inset
5058
5059 -print-search-dirs
5060 \series default
5061
5062 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5063
5064 \end_inset
5065
5066  to find exactly where SDCC is looking for the include and lib files.
5067 \end_layout
5068
5069 \begin_layout Section
5070 Install Trouble-shooting
5071 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5072
5073 \end_inset
5074
5075
5076 \begin_inset LatexCommand \index{Install trouble-shooting}
5077
5078 \end_inset
5079
5080
5081 \end_layout
5082
5083 \begin_layout Subsection
5084 If SDCC does not build correctly
5085 \end_layout
5086
5087 \begin_layout Standard
5088 A thing to try is starting from scratch by unpacking the .tgz source package
5089  again in an empty directory.
5090  Configure it like:
5091 \newline
5092
5093 \newline
5094
5095 \family sans
5096 \series bold
5097 ./configure 2>&1 | tee configure.log
5098 \family default
5099 \series default
5100
5101 \newline
5102
5103 \newline
5104 and build it like:
5105 \newline
5106
5107 \newline
5108
5109 \family sans
5110 \series bold
5111 make 2>&1 | tee make.log
5112 \family default
5113 \series default
5114
5115 \newline
5116
5117 \newline
5118 If anything goes wrong, you can review the log files to locate the problem.
5119  Or a relevant part of this can be attached to an email that could be helpful
5120  when requesting help from the mailing list.
5121 \end_layout
5122
5123 \begin_layout Subsection
5124 What the 
5125 \begin_inset Quotes sld
5126 \end_inset
5127
5128 ./configure
5129 \begin_inset Quotes srd
5130 \end_inset
5131
5132  does
5133 \end_layout
5134
5135 \begin_layout Standard
5136 The 
5137 \begin_inset Quotes sld
5138 \end_inset
5139
5140 ./configure
5141 \begin_inset Quotes srd
5142 \end_inset
5143
5144  command is a script that analyzes your system and performs some configuration
5145  to ensure the source package compiles on your system.
5146  It will take a few minutes to run, and will compile a few tests to determine
5147  what compiler features are installed.
5148 \end_layout
5149
5150 \begin_layout Subsection
5151 What the 
5152 \begin_inset Quotes sld
5153 \end_inset
5154
5155 make
5156 \begin_inset Quotes srd
5157 \end_inset
5158
5159  does
5160 \end_layout
5161
5162 \begin_layout Standard
5163 This runs the GNU make tool, which automatically compiles all the source
5164  packages into the final installed binary executables.
5165 \end_layout
5166
5167 \begin_layout Subsection
5168 What the 
5169 \begin_inset Quotes sld
5170 \end_inset
5171
5172 make install
5173 \begin_inset Quotes erd
5174 \end_inset
5175
5176  command does.
5177 \end_layout
5178
5179 \begin_layout Standard
5180 This will install the compiler, other executables libraries and include
5181  files into the appropriate directories.
5182  See sections 
5183 \begin_inset LatexCommand \ref{sub:Install-paths}
5184
5185 \end_inset
5186
5187 ,\InsetSpace ~
5188
5189 \begin_inset LatexCommand \ref{sub:Search-Paths}
5190
5191 \end_inset
5192
5193 \InsetSpace ~
5194 about install and search paths.
5195 \newline
5196 On most systems you will need super-user privilege
5197 s to do this.
5198 \end_layout
5199
5200 \begin_layout Section
5201 Components of SDCC
5202 \end_layout
5203
5204 \begin_layout Standard
5205 SDCC is not just a compiler, but a collection of tools by various developers.
5206  These include linkers, assemblers, simulators and other components.
5207  Here is a summary of some of the components.
5208  Note that the included simulator and assembler have separate documentation
5209  which you can find in the source package in their respective directories.
5210  As SDCC grows to include support for other processors, other packages from
5211  various developers are included and may have their own sets of documentation.
5212 \newline
5213
5214 \newline
5215 You
5216  might want to look at the files which are installed in <installdir>.
5217  At the time of this writing, we find the following programs for gcc-builds:
5218 \newline
5219
5220  
5221 \newline
5222 In <installdir>/bin:
5223 \end_layout
5224
5225 \begin_layout Itemize
5226 sdcc - The compiler.
5227 \end_layout
5228
5229 \begin_layout Itemize
5230 sdcpp - The C preprocessor.
5231 \end_layout
5232
5233 \begin_layout Itemize
5234 asx8051 - The assembler for 8051 type processors.
5235 \end_layout
5236
5237 \begin_layout Itemize
5238 as-z80
5239 \series bold
5240
5241 \series default
5242 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5243 \end_layout
5244
5245 \begin_layout Itemize
5246 aslink -The linker for 8051 type processors.
5247 \end_layout
5248
5249 \begin_layout Itemize
5250 link-z80
5251 \series bold
5252
5253 \series default
5254 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5255 \end_layout
5256
5257 \begin_layout Itemize
5258 s51 - The ucSim 8051 simulator.
5259 \end_layout
5260
5261 \begin_layout Itemize
5262 sdcdb - The source debugger.
5263 \end_layout
5264
5265 \begin_layout Itemize
5266 packihx - A tool to pack (compress) Intel hex files.
5267 \end_layout
5268
5269 \begin_layout Standard
5270 In <installdir>/share/sdcc/include
5271 \end_layout
5272
5273 \begin_layout Itemize
5274 the include files
5275 \end_layout
5276
5277 \begin_layout Standard
5278 In <installdir>/share/sdcc/lib
5279 \end_layout
5280
5281 \begin_layout Itemize
5282 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5283  relocatables.
5284 \end_layout
5285
5286 \begin_layout Standard
5287 In <installdir>/share/sdcc/doc
5288 \end_layout
5289
5290 \begin_layout Itemize
5291 the documentation
5292 \end_layout
5293
5294 \begin_layout Standard
5295 As development for other processors proceeds, this list will expand to include
5296  executables to support processors like AVR, PIC, etc.
5297 \end_layout
5298
5299 \begin_layout Subsection
5300 sdcc - The Compiler
5301 \end_layout
5302
5303 \begin_layout Standard
5304 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5305  the assembler and linkage editor.
5306 \end_layout
5307
5308 \begin_layout Subsection
5309 sdcpp - The C-Preprocessor
5310 \end_layout
5311
5312 \begin_layout Standard
5313 The preprocessor
5314 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5315
5316 \end_inset
5317
5318  is a modified version of the GNU cpp
5319 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5320
5321 \end_inset
5322
5323  preprocessor 
5324 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5325
5326 \end_inset
5327
5328 .
5329  The C preprocessor is used to pull in #include sources, process #ifdef
5330  statements, #defines and so on.
5331 \end_layout
5332
5333 \begin_layout Subsection
5334 as
5335 \emph on
5336 xxxx
5337 \emph default
5338 , aslink, link-
5339 \emph on
5340 xxx
5341 \emph default
5342  - The Assemblers and Linkage Editors
5343 \end_layout
5344
5345 \begin_layout Standard
5346 This is retargettable assembler & linkage editor, it was developed by Alan
5347  Baldwin.
5348  John Hartman created the version for 8051, and I (Sandeep) have made some
5349  enhancements and bug fixes for it to work properly with SDCC.
5350 \end_layout
5351
5352 \begin_layout Subsection
5353 s51 - The Simulator
5354 \end_layout
5355
5356 \begin_layout Standard
5357 S51
5358 \begin_inset LatexCommand \index{s51}
5359
5360 \end_inset
5361
5362  is a freeware, opensource simulator developed by Daniel Drotos.
5363  The simulator is built as part of the build process.
5364  For more information visit Daniel's web site at: 
5365 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5366
5367 \end_inset
5368
5369 .
5370  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5371  XA51 family.
5372 \end_layout
5373
5374 \begin_layout Subsection
5375 sdcdb - Source Level Debugger
5376 \end_layout
5377
5378 \begin_layout Standard
5379 SDCDB
5380 \begin_inset LatexCommand \index{SDCDB (debugger)}
5381
5382 \end_inset
5383
5384  is the companion source level debugger.
5385  More about SDCDB in section 
5386 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5387
5388 \end_inset
5389
5390 .
5391  The current version of the debugger uses Daniel's Simulator S51
5392 \begin_inset LatexCommand \index{s51}
5393
5394 \end_inset
5395
5396 , but can be easily changed to use other simulators.
5397 \end_layout
5398
5399 \begin_layout Chapter
5400 Using SDCC
5401 \end_layout
5402
5403 \begin_layout Section
5404 Compiling
5405 \end_layout
5406
5407 \begin_layout Subsection
5408 Single Source File Projects
5409 \end_layout
5410
5411 \begin_layout Standard
5412 For single source file 8051 projects the process is very simple.
5413  Compile your programs with the following command 
5414 \family sans
5415 \series bold
5416 "sdcc sourcefile.c".
5417
5418 \family default
5419 \series default
5420  This will compile, assemble and link your source file.
5421  Output files are as follows:
5422 \end_layout
5423
5424 \begin_layout Itemize
5425 sourcefile.asm
5426 \begin_inset LatexCommand \index{<file>.asm}
5427
5428 \end_inset
5429
5430  - Assembler source
5431 \begin_inset LatexCommand \index{Assembler source}
5432
5433 \end_inset
5434
5435  file created by the compiler
5436 \end_layout
5437
5438 \begin_layout Itemize
5439 sourcefile.lst
5440 \begin_inset LatexCommand \index{<file>.lst}
5441
5442 \end_inset
5443
5444  - Assembler listing
5445 \begin_inset LatexCommand \index{Assembler listing}
5446
5447 \end_inset
5448
5449  file created by the Assembler
5450 \end_layout
5451
5452 \begin_layout Itemize
5453 sourcefile.rst
5454 \begin_inset LatexCommand \index{<file>.rst}
5455
5456 \end_inset
5457
5458  - Assembler listing
5459 \begin_inset LatexCommand \index{Assembler listing}
5460
5461 \end_inset
5462
5463  file updated with linkedit information, created by linkage editor
5464 \end_layout
5465
5466 \begin_layout Itemize
5467 sourcefile.sym
5468 \begin_inset LatexCommand \index{<file>.sym}
5469
5470 \end_inset
5471
5472  - symbol listing
5473 \begin_inset LatexCommand \index{Symbol listing}
5474
5475 \end_inset
5476
5477  for the sourcefile, created by the assembler
5478 \end_layout
5479
5480 \begin_layout Itemize
5481 sourcefile.rel
5482 \begin_inset LatexCommand \index{<file>.rel}
5483
5484 \end_inset
5485
5486  or sourcefile.o
5487 \begin_inset LatexCommand \index{<file>.o}
5488
5489 \end_inset
5490
5491  - Object file
5492 \begin_inset LatexCommand \index{Object file}
5493
5494 \end_inset
5495
5496  created by the assembler, input to Linkage editor
5497 \end_layout
5498
5499 \begin_layout Itemize
5500 sourcefile.map
5501 \begin_inset LatexCommand \index{<file>.map}
5502
5503 \end_inset
5504
5505  - The memory map
5506 \begin_inset LatexCommand \index{Memory map}
5507
5508 \end_inset
5509
5510  for the load module, created by the Linker
5511 \end_layout
5512
5513 \begin_layout Itemize
5514 sourcefile.mem
5515 \begin_inset LatexCommand \index{<file>.mem}
5516
5517 \end_inset
5518
5519  - A file with a summary of the memory usage
5520 \end_layout
5521
5522 \begin_layout Itemize
5523 sourcefile.ihx
5524 \begin_inset LatexCommand \index{<file>.ihx}
5525
5526 \end_inset
5527
5528  - The load module in Intel hex format
5529 \begin_inset LatexCommand \index{Intel hex format}
5530
5531 \end_inset
5532
5533  (you can select the Motorola S19 format
5534 \begin_inset LatexCommand \index{Motorola S19 format}
5535
5536 \end_inset
5537
5538  with -
5539 \begin_inset ERT
5540 status collapsed
5541
5542 \begin_layout Standard
5543
5544
5545 \backslash
5546 /
5547 \end_layout
5548
5549 \end_inset
5550
5551 -out-fmt-s19
5552 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5553
5554 \end_inset
5555
5556 .
5557  If you need another format you might want to use 
5558 \family sans
5559 \shape italic
5560 objdump
5561 \family default
5562 \shape default
5563
5564 \begin_inset LatexCommand \index{objdump (tool)}
5565
5566 \end_inset
5567
5568  or
5569 \family sans
5570 \shape italic
5571  srecord
5572 \family default
5573 \shape default
5574
5575 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5576
5577 \end_inset
5578
5579 ).
5580  Both formats are documented in the documentation of srecord
5581 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5582
5583 \end_inset
5584
5585
5586 \end_layout
5587
5588 \begin_layout Itemize
5589 sourcefile.adb
5590 \begin_inset LatexCommand \index{<file>.adb}
5591
5592 \end_inset
5593
5594  - An intermediate file containing debug information needed to create the
5595  .cdb file (with -
5596 \begin_inset ERT
5597 status collapsed
5598
5599 \begin_layout Standard
5600
5601
5602 \backslash
5603 /
5604 \end_layout
5605
5606 \end_inset
5607
5608 -debug
5609 \begin_inset LatexCommand \index{-\/-debug}
5610
5611 \end_inset
5612
5613
5614 \end_layout
5615
5616 \begin_layout Itemize
5617 sourcefile.cdb
5618 \begin_inset LatexCommand \index{<file>.cdb}
5619
5620 \end_inset
5621
5622  - An optional file (with -
5623 \begin_inset ERT
5624 status collapsed
5625
5626 \begin_layout Standard
5627
5628
5629 \backslash
5630 /
5631 \end_layout
5632
5633 \end_inset
5634
5635 -debug) containing debug information.
5636  The format is documented in cdbfileformat.pdf
5637 \end_layout
5638
5639 \begin_layout Itemize
5640 sourcefile.
5641  - (no extension)
5642 \begin_inset LatexCommand \index{<file> (no extension)}
5643
5644 \end_inset
5645
5646  An optional AOMF or AOMF51
5647 \begin_inset LatexCommand \index{AOMF, AOMF51}
5648
5649 \end_inset
5650
5651  
5652 \begin_inset LatexCommand \label{OMF file}
5653
5654 \end_inset
5655
5656 file containing debug information (generated with option -
5657 \begin_inset ERT
5658 status collapsed
5659
5660 \begin_layout Standard
5661
5662
5663 \backslash
5664 /
5665 \end_layout
5666
5667 \end_inset
5668
5669 -debug).
5670  The (Intel)
5671 \emph on
5672  a
5673 \emph default
5674 bsolute 
5675 \emph on
5676 o
5677 \emph default
5678 bject 
5679 \emph on
5680 m
5681 \emph default
5682 odule 
5683 \emph on
5684 f
5685 \emph default
5686 ormat is commonly used by third party tools (debuggers
5687 \begin_inset LatexCommand \index{Debugger}
5688
5689 \end_inset
5690
5691 , simulators, emulators)
5692 \end_layout
5693
5694 \begin_layout Itemize
5695 sourcefile.dump*
5696 \begin_inset LatexCommand \index{<file>.dump*}
5697
5698 \end_inset
5699
5700  - Dump file to debug the compiler it self (generated with option -
5701 \begin_inset ERT
5702 status collapsed
5703
5704 \begin_layout Standard
5705
5706
5707 \backslash
5708 /
5709 \end_layout
5710
5711 \end_inset
5712
5713 -dumpall) (see section 
5714 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5715
5716 \end_inset
5717
5718 \InsetSpace ~
5719  and section 
5720 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5721
5722 \end_inset
5723
5724 \InsetSpace ~
5725
5726 \begin_inset Quotes sld
5727 \end_inset
5728
5729 Anatomy of the compiler
5730 \begin_inset Quotes srd
5731 \end_inset
5732
5733 ).
5734 \end_layout
5735
5736 \begin_layout Subsection
5737 Postprocessing the Intel Hex
5738 \begin_inset LatexCommand \index{Intel hex format}
5739
5740 \end_inset
5741
5742  file
5743 \end_layout
5744
5745 \begin_layout Standard
5746 In most cases this won't be needed but the Intel Hex file
5747 \begin_inset LatexCommand \index{<file>.ihx}
5748
5749 \end_inset
5750
5751  which is generated by SDCC might include lines of varying length and the
5752  addresses within the file are not guaranteed to be strictly ascending.
5753  If your toolchain or a bootloader does not like this you can use the tool
5754  
5755 \family typewriter
5756 packihx
5757 \family default
5758
5759 \begin_inset LatexCommand \index{packihx (tool)}
5760
5761 \end_inset
5762
5763  which is part of the SDCC distribution: 
5764 \newline
5765
5766 \newline
5767
5768 \family sans
5769 \series bold
5770  packihx sourcefile.ihx >sourcefile.hex
5771 \family default
5772 \series default
5773
5774 \newline
5775
5776 \newline
5777 The separately available
5778 \emph on
5779  srecord
5780 \emph default
5781
5782 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5783
5784 \end_inset
5785
5786  package additionally allows to set undefined locations to a predefined
5787  value, to insert checksums
5788 \begin_inset LatexCommand \index{checksum}
5789
5790 \end_inset
5791
5792  of various flavours (crc, add, xor) and to perform other manipulations
5793  (convert, split, crop, offset, ...).
5794  
5795 \newline
5796
5797 \newline
5798
5799 \family sans
5800 \series bold
5801 srec_cat\InsetSpace ~
5802 \InsetSpace ~
5803 sourcefile.ihx -intel\InsetSpace ~
5804 \InsetSpace ~
5805 -o sourcefile.hex -intel
5806 \newline
5807
5808 \newline
5809
5810 \family default
5811 \series default
5812 An example for a more complex command line
5813 \begin_inset Foot
5814 status open
5815
5816 \begin_layout Standard
5817 the command backfills
5818 \begin_inset LatexCommand \index{backfill unused memory}
5819
5820 \end_inset
5821
5822  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5823  block is zero.
5824  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5825  will be interpreted as an 
5826 \family typewriter
5827 lcall
5828 \family default
5829  to address 
5830 \family typewriter
5831 0x1212
5832 \family default
5833  (where an emergency routine could sit).
5834 \end_layout
5835
5836 \end_inset
5837
5838  could look like:
5839 \newline
5840
5841 \newline
5842
5843 \family sans
5844 \series bold
5845 \size footnotesize
5846 srec_cat\InsetSpace ~
5847 sourcefile.ihx -intel\InsetSpace ~
5848 \InsetSpace ~
5849 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5850 -little-endian-checksum-nega
5851 tive 0xfffe 0x02 0x02\InsetSpace ~
5852 \InsetSpace ~
5853 -o sourcefile.hex -intel
5854 \size default
5855
5856 \newline
5857
5858 \newline
5859
5860 \family default
5861 \series default
5862 The srecord package is available at 
5863 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5864
5865 \end_inset
5866
5867  .
5868 \end_layout
5869
5870 \begin_layout Subsection
5871 Projects with Multiple Source Files
5872 \end_layout
5873
5874 \begin_layout Standard
5875 SDCC can compile only ONE file at a time.
5876  Let us for example assume that you have a project containing the following
5877  files:
5878 \newline
5879
5880 \newline
5881 foo1.c (contains some functions)
5882 \newline
5883 foo2.c (contains some more functions)
5884 \newline
5885 foomai
5886 n.c (contains more functions and the function main)
5887 \newline
5888
5889 \size footnotesize
5890
5891 \newline
5892
5893 \size default
5894 The first two files will need to be compiled separately with the commands:
5895 \size footnotesize
5896  
5897 \size default
5898
5899 \newline
5900
5901 \newline
5902
5903 \family sans
5904 \series bold
5905 sdcc\InsetSpace ~
5906 -c\InsetSpace ~
5907 foo1.c
5908 \family default
5909 \series default
5910 \size footnotesize
5911
5912 \newline
5913
5914 \family sans
5915 \series bold
5916 \size default
5917 sdcc\InsetSpace ~
5918 -c\InsetSpace ~
5919 foo2.c
5920 \family default
5921 \series default
5922
5923 \newline
5924
5925 \newline
5926 Then compile the source file containing the 
5927 \emph on
5928 main()
5929 \emph default
5930  function and link
5931 \begin_inset LatexCommand \index{Linker}
5932
5933 \end_inset
5934
5935  the files together with the following command: 
5936 \newline
5937
5938 \newline
5939
5940 \family sans
5941 \series bold
5942 sdcc\InsetSpace ~
5943 foomain.c\InsetSpace ~
5944 foo1.rel\InsetSpace ~
5945 foo2.rel
5946 \family default
5947 \series default
5948
5949 \begin_inset LatexCommand \index{<file>.rel}
5950
5951 \end_inset
5952
5953
5954 \newline
5955
5956 \newline
5957 Alternatively, 
5958 \emph on
5959 foomain.c 
5960 \emph default
5961 can be separately compiled as well: 
5962 \family sans
5963 \series bold
5964
5965 \newline
5966
5967 \newline
5968 sdcc\InsetSpace ~
5969 -c\InsetSpace ~
5970 foomain.c
5971 \newline
5972 sdcc foomain.rel foo1.rel foo2.rel
5973 \newline
5974
5975 \newline
5976
5977 \family default
5978 \series default
5979 The file containing the 
5980 \emph on
5981 main()
5982 \emph default
5983  function
5984 \emph on
5985  
5986 \emph default
5987 \noun on
5988 must
5989 \noun default
5990  be the 
5991 \noun on
5992 first
5993 \noun default
5994  file specified in the command line, since the linkage editor processes
5995  file in the order they are presented to it.
5996  The linker is invoked from SDCC using a script file with extension .lnk
5997 \begin_inset LatexCommand \index{<file>.lnk}
5998
5999 \end_inset
6000
6001 .
6002  You can view this file to troubleshoot linking problems such as those arising
6003  from missing libraries.
6004 \end_layout
6005
6006 \begin_layout Subsection
6007 Projects with Additional Libraries
6008 \begin_inset LatexCommand \index{Libraries}
6009
6010 \end_inset
6011
6012
6013 \end_layout
6014
6015 \begin_layout Standard
6016 Some reusable routines may be compiled into a library, see the documentation
6017  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6018  for how to create a 
6019 \emph on
6020 .lib
6021 \begin_inset LatexCommand \index{<file>.lib}
6022
6023 \end_inset
6024
6025
6026 \emph default
6027  library file.
6028  Libraries created in this manner can be included in the command line.
6029  Make sure you include the -L <library-path> option to tell the linker where
6030  to look for these files if they are not in the current directory.
6031  Here is an example, assuming you have the source file 
6032 \emph on
6033 foomain.c
6034 \emph default
6035  and a library
6036 \emph on
6037  foolib.lib
6038 \emph default
6039  in the directory 
6040 \emph on
6041 mylib
6042 \emph default
6043  (if that is not the same as your current project):
6044 \newline
6045
6046 \newline
6047
6048 \family sans
6049 \series bold
6050 sdcc foomain.c foolib.lib -L mylib
6051 \newline
6052
6053 \newline
6054
6055 \family default
6056 \series default
6057 Note here that
6058 \emph on
6059  mylib
6060 \emph default
6061  must be an absolute path name.
6062 \newline
6063
6064 \newline
6065 The most efficient way to use libraries is
6066  to keep separate modules in separate source files.
6067  The lib file now should name all the modules.rel
6068 \begin_inset LatexCommand \index{<file>.rel}
6069
6070 \end_inset
6071
6072  files.
6073  For an example see the standard library file 
6074 \emph on
6075 libsdcc.lib
6076 \emph default
6077  in the directory <installdir>/share/lib/small.
6078 \end_layout
6079
6080 \begin_layout Subsection
6081 Using sdcclib to Create and Manage Libraries
6082 \begin_inset LatexCommand \index{sdcclib}
6083
6084 \end_inset
6085
6086
6087 \end_layout
6088
6089 \begin_layout Standard
6090 Alternatively, instead of having a .rel file for each entry on the library
6091  file as described in the preceding section, sdcclib can be used to embed
6092  all the modules belonging to such library in the library file itself.
6093  This results in a larger library file, but it greatly reduces the number
6094  of disk files accessed by the linker.
6095   Additionally, the packed library file contains an index of all include
6096  modules and symbols that significantly speeds up the linking process.
6097  To display a list of options supported by sdcclib type:
6098 \newline
6099
6100 \end_layout
6101
6102 \begin_layout Standard
6103
6104 \family sans
6105 \series bold
6106 sdcclib -?
6107 \begin_inset LatexCommand \index{sdcclib}
6108
6109 \end_inset
6110
6111
6112 \newline
6113
6114 \newline
6115
6116 \family default
6117 \series default
6118 To create a new library file, start by compiling all the required modules.
6119  For example:
6120 \newline
6121
6122 \end_layout
6123
6124 \begin_layout Standard
6125
6126 \family sans
6127 \series bold
6128 sdcc -c _divsint.c
6129 \end_layout
6130
6131 \begin_layout Standard
6132
6133 \family sans
6134 \series bold
6135 sdcc -c _divuint.c
6136 \end_layout
6137
6138 \begin_layout Standard
6139
6140 \family sans
6141 \series bold
6142 sdcc -c _modsint.c
6143 \end_layout
6144
6145 \begin_layout Standard
6146
6147 \family sans
6148 \series bold
6149 sdcc -c _moduint.c
6150 \end_layout
6151
6152 \begin_layout Standard
6153
6154 \family sans
6155 \series bold
6156 sdcc -c _mulint.c
6157 \newline
6158
6159 \end_layout
6160
6161 \begin_layout Standard
6162 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6163  and _mulint.rel.
6164  The next step is to add the .rel files to the library file:
6165 \newline
6166
6167 \end_layout
6168
6169 \begin_layout Standard
6170
6171 \family sans
6172 \series bold
6173 sdcclib libint.lib _divsint.rel
6174 \family default
6175
6176 \begin_inset LatexCommand \index{sdcclib}
6177
6178 \end_inset
6179
6180
6181 \end_layout
6182
6183 \begin_layout Standard
6184
6185 \family sans
6186 \series bold
6187 sdcclib libint.lib _divuint.rel
6188 \end_layout
6189
6190 \begin_layout Standard
6191
6192 \family sans
6193 \series bold
6194 sdcclib libint.lib _modsint.rel
6195 \end_layout
6196
6197 \begin_layout Standard
6198
6199 \family sans
6200 \series bold
6201 sdcclib libint.lib _moduint.rel
6202 \end_layout
6203
6204 \begin_layout Standard
6205
6206 \family sans
6207 \series bold
6208 sdcclib libint.lib _mulint.rel
6209 \series default
6210
6211 \newline
6212
6213 \end_layout
6214
6215 \begin_layout Standard
6216 If the file already exists in the library, it will be replaced.
6217  To see what modules and symbols are included in the library, options -s
6218  and -m are available.
6219  For example:
6220 \newline
6221
6222 \newline
6223
6224 \family sans
6225 \series bold
6226 sdcclib -s libint.lib
6227 \family default
6228
6229 \begin_inset LatexCommand \index{sdcclib}
6230
6231 \end_inset
6232
6233
6234 \newline
6235
6236 \family typewriter
6237 \series default
6238 _divsint.rel:
6239 \end_layout
6240
6241 \begin_layout Standard
6242
6243 \family typewriter
6244 __divsint_a_1_1
6245 \end_layout
6246
6247 \begin_layout Standard
6248
6249 \family typewriter
6250 __divsint_PARM_2
6251 \end_layout
6252
6253 \begin_layout Standard
6254
6255 \family typewriter
6256 __divsint
6257 \newline
6258 _divuint.rel:
6259 \end_layout
6260
6261 \begin_layout Standard
6262
6263 \family typewriter
6264 __divuint_a_1_1
6265 \end_layout
6266
6267 \begin_layout Standard
6268
6269 \family typewriter
6270 __divuint_PARM_2
6271 \end_layout
6272
6273 \begin_layout Standard
6274
6275 \family typewriter
6276 __divuint_reste_1_1
6277 \end_layout
6278
6279 \begin_layout Standard
6280
6281 \family typewriter
6282 __divuint_count_1_1
6283 \end_layout
6284
6285 \begin_layout Standard
6286
6287 \family typewriter
6288 __divuint
6289 \newline
6290 _modsint.rel:
6291 \end_layout
6292
6293 \begin_layout Standard
6294
6295 \family typewriter
6296 __modsint_a_1_1
6297 \end_layout
6298
6299 \begin_layout Standard
6300
6301 \family typewriter
6302 __modsint_PARM_2
6303 \end_layout
6304
6305 \begin_layout Standard
6306
6307 \family typewriter
6308 __modsint
6309 \newline
6310 _moduint.rel:
6311 \end_layout
6312
6313 \begin_layout Standard
6314
6315 \family typewriter
6316 __moduint_a_1_1
6317 \end_layout
6318
6319 \begin_layout Standard
6320
6321 \family typewriter
6322 __moduint_PARM_2
6323 \end_layout
6324
6325 \begin_layout Standard
6326
6327 \family typewriter
6328 __moduint_count_1_1
6329 \end_layout
6330
6331 \begin_layout Standard
6332
6333 \family typewriter
6334 __moduint
6335 \newline
6336 _mulint.rel:
6337 \end_layout
6338
6339 \begin_layout Standard
6340
6341 \family typewriter
6342 __mulint_PARM_2
6343 \end_layout
6344
6345 \begin_layout Standard
6346
6347 \family typewriter
6348 __mulint
6349 \family default
6350 \series bold
6351
6352 \newline
6353
6354 \end_layout
6355
6356 \begin_layout Standard
6357 If the source files are compiled using -
6358 \begin_inset ERT
6359 status collapsed
6360
6361 \begin_layout Standard
6362
6363
6364 \backslash
6365 /
6366 \end_layout
6367
6368 \end_inset
6369
6370 -debug
6371 \begin_inset LatexCommand \index{-\/-debug}
6372
6373 \end_inset
6374
6375 , the corresponding debug information file .adb will be include in the library
6376  file as well.
6377  The library files created with sdcclib are plain text files, so they can
6378  be viewed with a text editor.
6379  It is not recomended to modify a library file created with sdcclib using
6380  a text editor, as there are file indexes numbers located accross the file
6381  used by the linker to quickly locate the required module to link.
6382  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6383  it can be safely deleted, since all the information required for linking
6384  is embedded in the library file itself.
6385  Library files created using sdcclib are used as described in the preceding
6386  sections.
6387 \begin_inset VSpace bigskip
6388 \end_inset
6389
6390
6391 \end_layout
6392
6393 \begin_layout Section
6394 Command Line Options
6395 \begin_inset LatexCommand \index{Command Line Options}
6396
6397 \end_inset
6398
6399
6400 \end_layout
6401
6402 \begin_layout Subsection
6403 Processor Selection Options
6404 \begin_inset LatexCommand \index{Options processor selection}
6405
6406 \end_inset
6407
6408
6409 \begin_inset LatexCommand \index{Processor selection options}
6410
6411 \end_inset
6412
6413
6414 \end_layout
6415
6416 \begin_layout List
6417 \labelwidthstring 00.00.0000
6418
6419 \series bold
6420 -mmcs51
6421 \begin_inset LatexCommand \index{-mmcs51}
6422
6423 \end_inset
6424
6425
6426 \series default
6427  Generate code for the Intel MCS51
6428 \begin_inset LatexCommand \index{MCS51}
6429
6430 \end_inset
6431
6432  family of processors.
6433  This is the default processor target.
6434 \end_layout
6435
6436 \begin_layout List
6437 \labelwidthstring 00.00.0000
6438
6439 \series bold
6440 -mds390
6441 \begin_inset LatexCommand \index{-mds390}
6442
6443 \end_inset
6444
6445
6446 \series default
6447  Generate code for the Dallas DS80C390
6448 \begin_inset LatexCommand \index{DS80C390}
6449
6450 \end_inset
6451
6452  processor.
6453 \end_layout
6454
6455 \begin_layout List
6456 \labelwidthstring 00.00.0000
6457
6458 \series bold
6459 -mds400
6460 \begin_inset LatexCommand \index{-mds400}
6461
6462 \end_inset
6463
6464
6465 \series default
6466  Generate code for the Dallas DS80C400
6467 \begin_inset LatexCommand \index{DS80C400}
6468
6469 \end_inset
6470
6471  processor.
6472 \end_layout
6473
6474 \begin_layout List
6475 \labelwidthstring 00.00.0000
6476
6477 \series bold
6478 -mhc08
6479 \begin_inset LatexCommand \index{-mhc08}
6480
6481 \end_inset
6482
6483
6484 \series default
6485  Generate code for the Freescale/Motorola HC08
6486 \begin_inset LatexCommand \index{HC08}
6487
6488 \end_inset
6489
6490  family of processors.
6491 \end_layout
6492
6493 \begin_layout List
6494 \labelwidthstring 00.00.0000
6495
6496 \series bold
6497 -mz80
6498 \begin_inset LatexCommand \index{-mz80}
6499
6500 \end_inset
6501
6502
6503 \series default
6504  Generate code for the Zilog Z80
6505 \begin_inset LatexCommand \index{Z80}
6506
6507 \end_inset
6508
6509  family of processors.
6510 \end_layout
6511
6512 \begin_layout List
6513 \labelwidthstring 00.00.0000
6514
6515 \series bold
6516 -mgbz80
6517 \begin_inset LatexCommand \index{-mgbz80}
6518
6519 \end_inset
6520
6521
6522 \series default
6523  Generate code for the GameBoy Z80
6524 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6525
6526 \end_inset
6527
6528  processor (Not actively maintained).
6529 \end_layout
6530
6531 \begin_layout List
6532 \labelwidthstring 00.00.0000
6533
6534 \series bold
6535 -mavr
6536 \begin_inset LatexCommand \index{-mavr}
6537
6538 \end_inset
6539
6540
6541 \series default
6542  Generate code for the Atmel AVR
6543 \begin_inset LatexCommand \index{AVR}
6544
6545 \end_inset
6546
6547  processor (Not maintained, not complete).
6548  AVR users should probably have a look at winavr 
6549 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6550
6551 \end_inset
6552
6553  or 
6554 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6555
6556 \end_inset
6557
6558 .
6559 \end_layout
6560
6561 \begin_layout Standard
6562 \begin_inset Note Comment
6563 status collapsed
6564
6565 \begin_layout Standard
6566 I think it is fair to direct users there for now.
6567  Open source is also about avoiding unnecessary work .
6568  But I didn't find the 'official' link.
6569 \end_layout
6570
6571 \end_inset
6572
6573
6574 \end_layout
6575
6576 \begin_layout List
6577 \labelwidthstring 00.00.0000
6578
6579 \series bold
6580 -mpic14
6581 \begin_inset LatexCommand \index{-mpic14}
6582
6583 \end_inset
6584
6585
6586 \series default
6587  Generate code for the Microchip PIC 14
6588 \begin_inset LatexCommand \index{PIC14}
6589
6590 \end_inset
6591
6592 -bit processors (p16f84 and variants.
6593  In development, not complete).
6594 \end_layout
6595
6596 \begin_layout Standard
6597 \begin_inset Note Comment
6598 status collapsed
6599
6600 \begin_layout Standard
6601 p16f627 p16f628 p16f84 p16f873 p16f877?
6602 \end_layout
6603
6604 \end_inset
6605
6606
6607 \end_layout
6608
6609 \begin_layout List
6610 \labelwidthstring 00.00.0000
6611
6612 \series bold
6613 -mpic16
6614 \begin_inset LatexCommand \index{-mpic16}
6615
6616 \end_inset
6617
6618
6619 \series default
6620  Generate code for the Microchip PIC 16
6621 \begin_inset LatexCommand \index{PIC16}
6622
6623 \end_inset
6624
6625 -bit processors (p18f452 and variants.
6626  In development, not complete).
6627 \end_layout
6628
6629 \begin_layout List
6630 \labelwidthstring 00.00.0000
6631
6632 \series bold
6633 -mtlcs900h
6634 \series default
6635  Generate code for the Toshiba TLCS-900H
6636 \begin_inset LatexCommand \index{TLCS-900H}
6637
6638 \end_inset
6639
6640  processor (Not maintained, not complete).
6641 \end_layout
6642
6643 \begin_layout List
6644 \labelwidthstring 00.00.0000
6645
6646 \series bold
6647 -mxa51
6648 \begin_inset LatexCommand \index{-mxa51}
6649
6650 \end_inset
6651
6652
6653 \series default
6654  Generate code for the Phillips XA51
6655 \begin_inset LatexCommand \index{XA51}
6656
6657 \end_inset
6658
6659  processor (Not maintained, not complete).
6660 \end_layout
6661
6662 \begin_layout Standard
6663 \begin_inset VSpace bigskip
6664 \end_inset
6665
6666
6667 \end_layout
6668
6669 \begin_layout Subsection
6670 Preprocessor Options
6671 \begin_inset LatexCommand \index{Options preprocessor}
6672
6673 \end_inset
6674
6675
6676 \begin_inset LatexCommand \index{Preprocessor options}
6677
6678 \end_inset
6679
6680
6681 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6682
6683 \end_inset
6684
6685
6686 \end_layout
6687
6688 \begin_layout List
6689 \labelwidthstring 00.00.0000
6690
6691 \series bold
6692 -I<path>
6693 \begin_inset LatexCommand \index{-I<path>}
6694
6695 \end_inset
6696
6697
6698 \series default
6699  The additional location where the pre processor will look for <..h> or 
6700 \begin_inset Quotes eld
6701 \end_inset
6702
6703 ..h
6704 \begin_inset Quotes erd
6705 \end_inset
6706
6707  files.
6708 \end_layout
6709
6710 \begin_layout List
6711 \labelwidthstring 00.00.0000
6712
6713 \series bold
6714 -D<macro[=value]>
6715 \begin_inset LatexCommand \index{-D<macro[=value]>}
6716
6717 \end_inset
6718
6719
6720 \series default
6721  Command line definition of macros.
6722  Passed to the preprocessor.
6723 \end_layout
6724
6725 \begin_layout List
6726 \labelwidthstring 00.00.0000
6727
6728 \series bold
6729 -M
6730 \begin_inset LatexCommand \index{-M}
6731
6732 \end_inset
6733
6734
6735 \series default
6736  Tell the preprocessor to output a rule suitable for make describing the
6737  dependencies of each object file.
6738  For each source file, the preprocessor outputs one make-rule whose target
6739  is the object file name for that source file and whose dependencies are
6740  all the files `#include'd in it.
6741  This rule may be a single line or may be continued with `
6742 \backslash
6743 '-newline if it is long.
6744  The list of rules is printed on standard output instead of the preprocessed
6745  C program.
6746  `-M' implies `-E
6747 \begin_inset LatexCommand \index{-E}
6748
6749 \end_inset
6750
6751 '.
6752 \end_layout
6753
6754 \begin_layout List
6755 \labelwidthstring 00.00.0000
6756
6757 \series bold
6758 -C
6759 \begin_inset LatexCommand \index{-C}
6760
6761 \end_inset
6762
6763
6764 \series default
6765  Tell the preprocessor not to discard comments.
6766  Used with the `-E' option.
6767 \end_layout
6768
6769 \begin_layout List
6770 \labelwidthstring 00.00.0000
6771
6772 \series bold
6773 -MM
6774 \begin_inset LatexCommand \index{-MM}
6775
6776 \end_inset
6777
6778
6779 \size large
6780 \bar under
6781  
6782 \series default
6783 \size default
6784 \bar default
6785 Like `-M' but the output mentions only the user header files included with
6786  `#include 
6787 \begin_inset Quotes eld
6788 \end_inset
6789
6790 file"'.
6791  System header files included with `#include <file>' are omitted.
6792 \end_layout
6793
6794 \begin_layout List
6795 \labelwidthstring 00.00.0000
6796
6797 \series bold
6798 -Aquestion(answer)
6799 \begin_inset LatexCommand \index{-Aquestion(answer)}
6800
6801 \end_inset
6802
6803
6804 \series default
6805  Assert the answer answer for question, in case it is tested with a preprocessor
6806  conditional such as `#if #question(answer)'.
6807  `-A-' disables the standard assertions that normally describe the target
6808  machine.
6809 \end_layout
6810
6811 \begin_layout List
6812 \labelwidthstring 00.00.0000
6813
6814 \series bold
6815 -Umacro
6816 \begin_inset LatexCommand \index{-Umacro}
6817
6818 \end_inset
6819
6820
6821 \series default
6822  Undefine macro macro.
6823  `-U' options are evaluated after all `-D' options, but before any `-include'
6824  and `-imacros' options.
6825 \end_layout
6826
6827 \begin_layout List
6828 \labelwidthstring 00.00.0000
6829
6830 \series bold
6831 -dM
6832 \begin_inset LatexCommand \index{-dM}
6833
6834 \end_inset
6835
6836
6837 \series default
6838  Tell the preprocessor to output only a list of the macro definitions that
6839  are in effect at the end of preprocessing.
6840  Used with the `-E' option.
6841 \end_layout
6842
6843 \begin_layout List
6844 \labelwidthstring 00.00.0000
6845
6846 \series bold
6847 -dD
6848 \begin_inset LatexCommand \index{-dD}
6849
6850 \end_inset
6851
6852
6853 \series default
6854  Tell the preprocessor to pass all macro definitions into the output, in
6855  their proper sequence in the rest of the output.
6856 \end_layout
6857
6858 \begin_layout List
6859 \labelwidthstring 00.00.0000
6860
6861 \series bold
6862 -dN
6863 \begin_inset LatexCommand \index{-dN}
6864
6865 \end_inset
6866
6867
6868 \size large
6869 \bar under
6870  
6871 \series default
6872 \size default
6873 \bar default
6874 Like `-dD' except that the macro arguments and contents are omitted.
6875  Only `#define name' is included in the output.
6876 \end_layout
6877
6878 \begin_layout List
6879 \labelwidthstring 00.00.0000
6880
6881 \series bold
6882 -pedantic-parse-number
6883 \begin_inset LatexCommand \index{-pedantic-parse-number}
6884
6885 \end_inset
6886
6887
6888 \size large
6889 \bar under
6890  
6891 \series default
6892 \size default
6893 \bar default
6894 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6895  and the macro LO_B(3) gets expanded.
6896  See also #pragma pedantic_parse_number in section
6897 \begin_inset LatexCommand \ref{sec:Pragmas}
6898
6899 \end_inset
6900
6901  
6902 \emph on
6903 Note: this functionality is not in conformance with standard!
6904 \end_layout
6905
6906 \begin_layout List
6907 \labelwidthstring 00.00.0000
6908
6909 \series bold
6910 -Wp\InsetSpace ~
6911 preprocessorOption[,preprocessorOption]
6912 \series default
6913
6914 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6915
6916 \end_inset
6917
6918 ...
6919  Pass the preprocessorOption to the preprocessor 
6920 \family typewriter
6921 sdcpp
6922 \family default
6923
6924 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6925
6926 \end_inset
6927
6928 .
6929  SDCC uses an adapted version of the preprocessor 
6930 \emph on
6931 cpp
6932 \emph default
6933  of the GNU Compiler Collection
6934 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6935
6936 \end_inset
6937
6938  (
6939 \emph on
6940 gcc
6941 \emph default
6942  
6943 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6944
6945 \end_inset
6946
6947 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
6948 4.1.1\InsetSpace ~
6949 CPP\InsetSpace ~
6950 Manual
6951  at 
6952 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6953
6954 \end_inset
6955
6956 .
6957 \end_layout
6958
6959 \begin_layout Standard
6960 \begin_inset VSpace bigskip
6961 \end_inset
6962
6963
6964 \end_layout
6965
6966 \begin_layout Subsection
6967 Linker Options
6968 \begin_inset LatexCommand \index{Options linker}
6969
6970 \end_inset
6971
6972
6973 \begin_inset LatexCommand \index{Linker options}
6974
6975 \end_inset
6976
6977
6978 \end_layout
6979
6980 \begin_layout List
6981 \labelwidthstring 00.00.0000
6982
6983 \series bold
6984 -L\InsetSpace ~
6985 -
6986 \series default
6987
6988 \begin_inset ERT
6989 status collapsed
6990
6991 \begin_layout Standard
6992
6993
6994 \backslash
6995 /
6996 \end_layout
6997
6998 \end_inset
6999
7000
7001 \series bold
7002 -lib-path
7003 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7004
7005 \end_inset
7006
7007
7008 \begin_inset LatexCommand \index{-L -\/-lib-path}
7009
7010 \end_inset
7011
7012
7013 \series default
7014 \InsetSpace ~
7015 <absolute path to additional libraries> This option is passed to the linkage
7016  editor's additional libraries
7017 \begin_inset LatexCommand \index{Libraries}
7018
7019 \end_inset
7020
7021  search path.
7022  The path name must be absolute.
7023  Additional library files may be specified in the command line.
7024  See section Compiling programs for more details.
7025 \end_layout
7026
7027 \begin_layout List
7028 \labelwidthstring 00.00.0000
7029
7030 \series bold
7031 -
7032 \begin_inset ERT
7033 status collapsed
7034
7035 \begin_layout Standard
7036
7037
7038 \backslash
7039 /
7040 \end_layout
7041
7042 \end_inset
7043
7044 -xram-loc
7045 \series default
7046
7047 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7048
7049 \end_inset
7050
7051 \InsetSpace ~
7052 <Value> The start location of the external ram
7053 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7054
7055 \end_inset
7056
7057 , default value is 0.
7058  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7059 \begin_inset ERT
7060 status collapsed
7061
7062 \begin_layout Standard
7063
7064
7065 \backslash
7066 /
7067 \end_layout
7068
7069 \end_inset
7070
7071 -xram-loc 0x8000 or -
7072 \begin_inset ERT
7073 status collapsed
7074
7075 \begin_layout Standard
7076
7077
7078 \backslash
7079 /
7080 \end_layout
7081
7082 \end_inset
7083
7084 -xram-loc 32768.
7085 \end_layout
7086
7087 \begin_layout List
7088 \labelwidthstring 00.00.0000
7089
7090 \series bold
7091 -
7092 \begin_inset ERT
7093 status collapsed
7094
7095 \begin_layout Standard
7096
7097
7098 \backslash
7099 /
7100 \end_layout
7101
7102 \end_inset
7103
7104 -code-loc
7105 \series default
7106
7107 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7108
7109 \end_inset
7110
7111 \InsetSpace ~
7112 <Value> The start location of the code
7113 \begin_inset LatexCommand \index{code}
7114
7115 \end_inset
7116
7117  segment, default value 0.
7118  Note when this option is used the interrupt vector table
7119 \begin_inset LatexCommand \index{interrupt vector table}
7120
7121 \end_inset
7122
7123  is also relocated to the given address.
7124  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7125 \begin_inset ERT
7126 status collapsed
7127
7128 \begin_layout Standard
7129
7130
7131 \backslash
7132 /
7133 \end_layout
7134
7135 \end_inset
7136
7137 -code-loc 0x8000 or -
7138 \begin_inset ERT
7139 status collapsed
7140
7141 \begin_layout Standard
7142
7143
7144 \backslash
7145 /
7146 \end_layout
7147
7148 \end_inset
7149
7150 -code-loc 32768.
7151 \end_layout
7152
7153 \begin_layout List
7154 \labelwidthstring 00.00.0000
7155
7156 \series bold
7157 -
7158 \begin_inset ERT
7159 status collapsed
7160
7161 \begin_layout Standard
7162
7163
7164 \backslash
7165 /
7166 \end_layout
7167
7168 \end_inset
7169
7170 -stack-loc
7171 \series default
7172
7173 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7174
7175 \end_inset
7176
7177 \InsetSpace ~
7178 <Value> By default the stack
7179 \begin_inset LatexCommand \index{stack}
7180
7181 \end_inset
7182
7183  is placed after the data segment.
7184  Using this option the stack can be placed anywhere in the internal memory
7185  space of the 8051.
7186  The value entered can be in Hexadecimal or Decimal format, e.g.
7187  -
7188 \begin_inset ERT
7189 status collapsed
7190
7191 \begin_layout Standard
7192
7193
7194 \backslash
7195 /
7196 \end_layout
7197
7198 \end_inset
7199
7200 -stack-loc 0x20 or -
7201 \begin_inset ERT
7202 status collapsed
7203
7204 \begin_layout Standard
7205
7206
7207 \backslash
7208 /
7209 \end_layout
7210
7211 \end_inset
7212
7213 -stack-loc 32.
7214  Since the sp register is incremented before a push or call, the initial
7215  sp will be set to one byte prior the provided value.
7216  The provided value should not overlap any other memory areas such as used
7217  register banks or the data segment and with enough space for the current
7218  application.
7219  The 
7220 \series bold
7221 -
7222 \begin_inset ERT
7223 status collapsed
7224
7225 \begin_layout Standard
7226
7227
7228 \backslash
7229 /
7230 \end_layout
7231
7232 \end_inset
7233
7234 -pack-iram
7235 \series default
7236 \InsetSpace ~
7237
7238 \begin_inset LatexCommand \index{-\/-pack-iram}
7239
7240 \end_inset
7241
7242  option (which is now a default setting) will override this setting, so
7243  you should also specify the 
7244 \series bold
7245 -
7246 \begin_inset ERT
7247 status collapsed
7248
7249 \begin_layout Standard
7250
7251
7252 \backslash
7253 /
7254 \end_layout
7255
7256 \end_inset
7257
7258 -no-pack-iram
7259 \series default
7260 \InsetSpace ~
7261
7262 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7263
7264 \end_inset
7265
7266  option if you need to manually place the stack.
7267 \end_layout
7268
7269 \begin_layout List
7270 \labelwidthstring 00.00.0000
7271
7272 \series bold
7273 -
7274 \begin_inset ERT
7275 status collapsed
7276
7277 \begin_layout Standard
7278
7279
7280 \backslash
7281 /
7282 \end_layout
7283
7284 \end_inset
7285
7286 -xstack-loc
7287 \series default
7288
7289 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7290
7291 \end_inset
7292
7293 \InsetSpace ~
7294 <Value> By default the external stack
7295 \begin_inset LatexCommand \index{xstack}
7296
7297 \end_inset
7298
7299  is placed after the pdata
7300 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7301
7302 \end_inset
7303
7304  segment.
7305  Using this option the xstack can be placed anywhere in the external memory
7306  space of the 8051.
7307  The value entered can be in Hexadecimal or Decimal format, e.g.
7308  -
7309 \begin_inset ERT
7310 status collapsed
7311
7312 \begin_layout Standard
7313
7314
7315 \backslash
7316 /
7317 \end_layout
7318
7319 \end_inset
7320
7321 -xstack-loc 0x8000 or -
7322 \begin_inset ERT
7323 status collapsed
7324
7325 \begin_layout Standard
7326
7327
7328 \backslash
7329 /
7330 \end_layout
7331
7332 \end_inset
7333
7334 -stack-loc 32768.
7335  The provided value should not overlap any other memory areas such as the
7336  pdata or xdata segment and with enough space for the current application.
7337 \end_layout
7338
7339 \begin_layout List
7340 \labelwidthstring 00.00.0000
7341
7342 \series bold
7343 -
7344 \begin_inset ERT
7345 status collapsed
7346
7347 \begin_layout Standard
7348
7349
7350 \backslash
7351 /
7352 \end_layout
7353
7354 \end_inset
7355
7356 -data-loc
7357 \series default
7358
7359 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7360
7361 \end_inset
7362
7363 \InsetSpace ~
7364 <Value> The start location of the internal ram data
7365 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7366
7367 \end_inset
7368
7369  segment.
7370  The value entered can be in Hexadecimal or Decimal format, eg.
7371  -
7372 \begin_inset ERT
7373 status collapsed
7374
7375 \begin_layout Standard
7376
7377
7378 \backslash
7379 /
7380 \end_layout
7381
7382 \end_inset
7383
7384 -data-loc 0x20 or -
7385 \begin_inset ERT
7386 status collapsed
7387
7388 \begin_layout Standard
7389
7390
7391 \backslash
7392 /
7393 \end_layout
7394
7395 \end_inset
7396
7397 -data-loc 32.
7398  (By default, the start location of the internal ram data segment  is set
7399  as low as possible in memory, taking into account the used register banks
7400  and the bit segment at address 0x20.
7401  For example if register banks 0 and 1 are used without bit variables, the
7402  data segment will be set, if -
7403 \begin_inset ERT
7404 status collapsed
7405
7406 \begin_layout Standard
7407
7408
7409 \backslash
7410 /
7411 \end_layout
7412
7413 \end_inset
7414
7415 -data-loc is not used, to location 0x10.)
7416 \end_layout
7417
7418 \begin_layout List
7419 \labelwidthstring 00.00.0000
7420
7421 \series bold
7422 -
7423 \begin_inset ERT
7424 status collapsed
7425
7426 \begin_layout Standard
7427
7428
7429 \backslash
7430 /
7431 \end_layout
7432
7433 \end_inset
7434
7435 -idata-loc
7436 \series default
7437
7438 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7439
7440 \end_inset
7441
7442 \InsetSpace ~
7443 <Value> The start location of the indirectly addressable internal ram
7444 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7445
7446 \end_inset
7447
7448  of the 8051, default value is 0x80.
7449  The value entered can be in Hexadecimal or Decimal format, eg.
7450  -
7451 \begin_inset ERT
7452 status collapsed
7453
7454 \begin_layout Standard
7455
7456
7457 \backslash
7458 /
7459 \end_layout
7460
7461 \end_inset
7462
7463 -idata-loc 0x88 or -
7464 \begin_inset ERT
7465 status collapsed
7466
7467 \begin_layout Standard
7468
7469
7470 \backslash
7471 /
7472 \end_layout
7473
7474 \end_inset
7475
7476 -idata-loc 136.
7477 \end_layout
7478
7479 \begin_layout List
7480 \labelwidthstring 00.00.0000
7481
7482 \series bold
7483 -
7484 \begin_inset ERT
7485 status collapsed
7486
7487 \begin_layout Standard
7488
7489
7490 \backslash
7491 /
7492 \end_layout
7493
7494 \end_inset
7495
7496 -bit-loc
7497 \series default
7498 \InsetSpace ~
7499 <Value> The start location of the bit
7500 \begin_inset LatexCommand \index{bit}
7501
7502 \end_inset
7503
7504  addressable internal ram of the 8051.
7505  This is 
7506 \emph on
7507 not
7508 \emph default
7509  implemented yet.
7510  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7511 -bBSEG=<Value>.
7512 \end_layout
7513
7514 \begin_layout List
7515 \labelwidthstring 00.00.0000
7516
7517 \series bold
7518 -
7519 \begin_inset ERT
7520 status collapsed
7521
7522 \begin_layout Standard
7523
7524
7525 \backslash
7526 /
7527 \end_layout
7528
7529 \end_inset
7530
7531 -out-fmt-ihx
7532 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7533
7534 \end_inset
7535
7536
7537 \bar under
7538  
7539 \series default
7540 \bar default
7541 The linker output (final object code) is in Intel Hex format.
7542 \begin_inset LatexCommand \index{Intel hex format}
7543
7544 \end_inset
7545
7546  This is the default option.
7547  The format itself is documented in the documentation of srecord
7548 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7549
7550 \end_inset
7551
7552 .
7553 \end_layout
7554
7555 \begin_layout List
7556 \labelwidthstring 00.00.0000
7557
7558 \series bold
7559 -
7560 \begin_inset ERT
7561 status collapsed
7562
7563 \begin_layout Standard
7564
7565
7566 \backslash
7567 /
7568 \end_layout
7569
7570 \end_inset
7571
7572 -out-fmt-s19
7573 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7574
7575 \end_inset
7576
7577
7578 \bar under
7579  
7580 \series default
7581 \bar default
7582 The linker output (final object code) is in Motorola S19 format
7583 \begin_inset LatexCommand \index{Motorola S19 format}
7584
7585 \end_inset
7586
7587 .
7588  The format itself is documented in the documentation of srecord.
7589 \end_layout
7590
7591 \begin_layout List
7592 \labelwidthstring 00.00.0000
7593
7594 \series bold
7595 -
7596 \begin_inset ERT
7597 status collapsed
7598
7599 \begin_layout Standard
7600
7601
7602 \backslash
7603 /
7604 \end_layout
7605
7606 \end_inset
7607
7608 -out-fmt-elf
7609 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7610
7611 \end_inset
7612
7613
7614 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7615
7616 \end_inset
7617
7618
7619 \bar under
7620  
7621 \series default
7622 \bar default
7623 The linker output (final object code) is in ELF format
7624 \begin_inset LatexCommand \index{ELF format}
7625
7626 \end_inset
7627
7628 .
7629  (Currently only supported for the HC08
7630 \begin_inset LatexCommand \index{HC08}
7631
7632 \end_inset
7633
7634  processors)
7635 \end_layout
7636
7637 \begin_layout List
7638 \labelwidthstring 00.00.0000
7639
7640 \series bold
7641 -Wl\InsetSpace ~
7642 linkOption[,linkOption]
7643 \series default
7644
7645 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7646
7647 \end_inset
7648
7649 ...
7650  Pass the linkOption to the linker.
7651  If a bootloader is used an option like 
7652 \begin_inset Quotes sld
7653 \end_inset
7654
7655 -Wl\InsetSpace ~
7656 -bCSEG=0x1000
7657 \begin_inset Quotes srd
7658 \end_inset
7659
7660  would be typical to set the start of the code segment.
7661  See also #pragma constseg and #pragma codeseg in section 
7662 \begin_inset LatexCommand \ref{sec:Pragmas}
7663
7664 \end_inset
7665
7666  .
7667  File sdcc/as/doc/asxhtm.html has more on linker options.
7668 \end_layout
7669
7670 \begin_layout Standard
7671 \begin_inset VSpace bigskip
7672 \end_inset
7673
7674
7675 \end_layout
7676
7677 \begin_layout Subsection
7678 MCS51 Options
7679 \begin_inset LatexCommand \index{Options MCS51}
7680
7681 \end_inset
7682
7683
7684 \begin_inset LatexCommand \index{MCS51 options}
7685
7686 \end_inset
7687
7688
7689 \end_layout
7690
7691 \begin_layout List
7692 \labelwidthstring 00.00.0000
7693
7694 \series bold
7695 -
7696 \begin_inset ERT
7697 status collapsed
7698
7699 \begin_layout Standard
7700
7701
7702 \backslash
7703 /
7704 \end_layout
7705
7706 \end_inset
7707
7708 -model-small
7709 \begin_inset LatexCommand \index{-\/-model-small}
7710
7711 \end_inset
7712
7713
7714 \series default
7715 \size large
7716 \emph on
7717  
7718 \size default
7719 \emph default
7720 Generate code for Small Model programs, see section Memory Models for more
7721  details.
7722  This is the default model.
7723 \end_layout
7724
7725 \begin_layout List
7726 \labelwidthstring 00.00.0000
7727
7728 \series bold
7729 -
7730 \begin_inset ERT
7731 status collapsed
7732
7733 \begin_layout Standard
7734
7735
7736 \backslash
7737 /
7738 \end_layout
7739
7740 \end_inset
7741
7742 -model-medium
7743 \begin_inset LatexCommand \index{-\/-model-medium}
7744
7745 \end_inset
7746
7747
7748 \series default
7749  Generate code for Medium model programs, see section Memory Models for
7750  more details.
7751  If this option is used all source files in the project have to be compiled
7752  with this option.
7753  It must also be used when invoking the linker.
7754 \end_layout
7755
7756 \begin_layout List
7757 \labelwidthstring 00.00.0000
7758
7759 \series bold
7760 -
7761 \begin_inset ERT
7762 status collapsed
7763
7764 \begin_layout Standard
7765
7766
7767 \backslash
7768 /
7769 \end_layout
7770
7771 \end_inset
7772
7773 -model-large
7774 \begin_inset LatexCommand \index{-\/-model-large}
7775
7776 \end_inset
7777
7778
7779 \series default
7780  Generate code for Large model programs, see section Memory Models for more
7781  details.
7782  If this option is used all source files in the project have to be compiled
7783  with this option.
7784  It must also be used when invoking the linker.
7785 \end_layout
7786
7787 \begin_layout List
7788 \labelwidthstring 00.00.0000
7789
7790 \series bold
7791 -
7792 \begin_inset ERT
7793 status collapsed
7794
7795 \begin_layout Standard
7796
7797
7798 \backslash
7799 /
7800 \end_layout
7801
7802 \end_inset
7803
7804 -xstack
7805 \begin_inset LatexCommand \index{-\/-xstack}
7806
7807 \end_inset
7808
7809
7810 \series default
7811  Uses a pseudo stack in the pdata
7812 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7813
7814 \end_inset
7815
7816  area (usually the first 256 bytes in the external ram) for allocating variables
7817  and passing parameters.
7818  See section 
7819 \begin_inset LatexCommand \ref{sub:External-Stack}
7820
7821 \end_inset
7822
7823 \InsetSpace ~
7824  External Stack for more details.
7825 \end_layout
7826
7827 \begin_layout List
7828 \labelwidthstring 00.00.0000
7829
7830 \series bold
7831 -
7832 \begin_inset ERT
7833 status collapsed
7834
7835 \begin_layout Standard
7836
7837
7838 \backslash
7839 /
7840 \end_layout
7841
7842 \end_inset
7843
7844 -iram-size
7845 \series default
7846 \InsetSpace ~
7847 <Value>
7848 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7849
7850 \end_inset
7851
7852  Causes the linker to check if the internal ram usage is within limits of
7853  the given value.
7854 \end_layout
7855
7856 \begin_layout List
7857 \labelwidthstring 00.00.0000
7858
7859 \series bold
7860 -
7861 \begin_inset ERT
7862 status collapsed
7863
7864 \begin_layout Standard
7865
7866
7867 \backslash
7868 /
7869 \end_layout
7870
7871 \end_inset
7872
7873 -xram-size
7874 \series default
7875 \InsetSpace ~
7876 <Value>
7877 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7878
7879 \end_inset
7880
7881  Causes the linker to check if the external ram usage is within limits of
7882  the given value.
7883 \end_layout
7884
7885 \begin_layout List
7886 \labelwidthstring 00.00.0000
7887
7888 \series bold
7889 -
7890 \begin_inset ERT
7891 status collapsed
7892
7893 \begin_layout Standard
7894
7895
7896 \backslash
7897 /
7898 \end_layout
7899
7900 \end_inset
7901
7902 -code-size
7903 \series default
7904 \InsetSpace ~
7905 <Value>
7906 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7907
7908 \end_inset
7909
7910  Causes the linker to check if the code memory usage is within limits of
7911  the given value.
7912 \end_layout
7913
7914 \begin_layout List
7915 \labelwidthstring 00.00.0000
7916
7917 \series bold
7918 -
7919 \begin_inset ERT
7920 status collapsed
7921
7922 \begin_layout Standard
7923
7924
7925 \backslash
7926 /
7927 \end_layout
7928
7929 \end_inset
7930
7931 -stack-size
7932 \series default
7933 \InsetSpace ~
7934 <Value>
7935 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7936
7937 \end_inset
7938
7939  Causes the linker to check if there is at minimum <Value> bytes for stack.
7940 \end_layout
7941
7942 \begin_layout List
7943 \labelwidthstring 00.00.0000
7944
7945 \series bold
7946 -
7947 \begin_inset ERT
7948 status collapsed
7949
7950 \begin_layout Standard
7951
7952
7953 \backslash
7954 /
7955 \end_layout
7956
7957 \end_inset
7958
7959 -pack-iram
7960 \series default
7961 \InsetSpace ~
7962
7963 \begin_inset LatexCommand \index{-\/-pack-iram}
7964
7965 \end_inset
7966
7967  Causes the linker to use unused register banks for data variables and pack
7968  data, idata and stack together.
7969  This is the default now.
7970 \end_layout
7971
7972 \begin_layout List
7973 \labelwidthstring 00.00.0000
7974
7975 \series bold
7976 -
7977 \begin_inset ERT
7978 status collapsed
7979
7980 \begin_layout Standard
7981
7982
7983 \backslash
7984 /
7985 \end_layout
7986
7987 \end_inset
7988
7989 -no-pack-iram
7990 \series default
7991 \InsetSpace ~
7992
7993 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7994
7995 \end_inset
7996
7997  Causes the linker to use old style for allocating memory areas.
7998 \end_layout
7999
8000 \begin_layout Standard
8001 \begin_inset VSpace bigskip
8002 \end_inset
8003
8004
8005 \end_layout
8006
8007 \begin_layout Subsection
8008 DS390 / DS400 Options
8009 \begin_inset LatexCommand \index{Options DS390}
8010
8011 \end_inset
8012
8013
8014 \begin_inset LatexCommand \index{DS390}
8015
8016 \end_inset
8017
8018
8019 \end_layout
8020
8021 \begin_layout List
8022 \labelwidthstring 00.00.0000
8023
8024 \series bold
8025 -
8026 \begin_inset ERT
8027 status collapsed
8028
8029 \begin_layout Standard
8030
8031
8032 \backslash
8033 /
8034 \end_layout
8035
8036 \end_inset
8037
8038 -model-flat24
8039 \series default
8040
8041 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8042
8043 \end_inset
8044
8045
8046 \size large
8047 \emph on
8048  
8049 \size default
8050 \emph default
8051 Generate 24-bit flat mode code.
8052  This is the one and only that the ds390 code generator supports right now
8053  and is default when using 
8054 \emph on
8055 -mds390
8056 \emph default
8057 .
8058  See section Memory Models for more details.
8059 \end_layout
8060
8061 \begin_layout List
8062 \labelwidthstring 00.00.0000
8063
8064 \series bold
8065 -
8066 \begin_inset ERT
8067 status collapsed
8068
8069 \begin_layout Standard
8070
8071
8072 \backslash
8073 /
8074 \end_layout
8075
8076 \end_inset
8077
8078 -protect-sp-update
8079 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8080
8081 \end_inset
8082
8083
8084 \series default
8085  disable interrupts during ESP:SP updates.
8086 \end_layout
8087
8088 \begin_layout List
8089 \labelwidthstring 00.00.0000
8090
8091 \series bold
8092 -
8093 \begin_inset ERT
8094 status collapsed
8095
8096 \begin_layout Standard
8097
8098
8099 \backslash
8100 /
8101 \end_layout
8102
8103 \end_inset
8104
8105 -stack-10bit
8106 \series default
8107
8108 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8109
8110 \end_inset
8111
8112  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8113  This is the one and only that the ds390 code generator supports right now
8114  and is default when using 
8115 \emph on
8116 -mds390
8117 \emph default
8118 .
8119  In this mode, the stack is located in the lower 1K of the internal RAM,
8120  which is mapped to 0x400000.
8121  Note that the support is incomplete, since it still uses a single byte
8122  as the stack pointer.
8123  This means that only the lower 256 bytes of the potential 1K stack space
8124  will actually be used.
8125  However, this does allow you to reclaim the precious 256 bytes of low RAM
8126  for use for the DATA and IDATA segments.
8127  The compiler will not generate any code to put the processor into 10 bit
8128  stack mode.
8129  It is important to ensure that the processor is in this mode before calling
8130  any re-entrant functions compiled with this option.
8131  In principle, this should work with the 
8132 \emph on
8133 -
8134 \begin_inset ERT
8135 status collapsed
8136
8137 \begin_layout Standard
8138
8139
8140 \backslash
8141 /
8142 \end_layout
8143
8144 \end_inset
8145
8146 -stack-auto
8147 \begin_inset LatexCommand \index{-\/-stack-auto}
8148
8149 \end_inset
8150
8151
8152 \emph default
8153  option, but that has not been tested.
8154  It is incompatible with the 
8155 \emph on
8156 -
8157 \begin_inset ERT
8158 status collapsed
8159
8160 \begin_layout Standard
8161
8162
8163 \backslash
8164 /
8165 \end_layout
8166
8167 \end_inset
8168
8169 -xstack
8170 \begin_inset LatexCommand \index{-\/-xstack}
8171
8172 \end_inset
8173
8174
8175 \emph default
8176  option.
8177  It also only makes sense if the processor is in 24 bit contiguous addressing
8178  mode (see the 
8179 \emph on
8180 -
8181 \begin_inset ERT
8182 status collapsed
8183
8184 \begin_layout Standard
8185
8186
8187 \backslash
8188 /
8189 \end_layout
8190
8191 \end_inset
8192
8193 -model-flat24 option
8194 \emph default
8195 ).
8196 \end_layout
8197
8198 \begin_layout List
8199 \labelwidthstring 00.00.0000
8200
8201 \series bold
8202 -
8203 \begin_inset ERT
8204 status collapsed
8205
8206 \begin_layout Standard
8207
8208
8209 \backslash
8210 /
8211 \end_layout
8212
8213 \end_inset
8214
8215 -stack-probe
8216 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8217
8218 \end_inset
8219
8220
8221 \series default
8222  insert call to function __stack_probe at each function prologue.
8223 \end_layout
8224
8225 \begin_layout List
8226 \labelwidthstring 00.00.0000
8227
8228 \series bold
8229 -
8230 \begin_inset ERT
8231 status collapsed
8232
8233 \begin_layout Standard
8234
8235
8236 \backslash
8237 /
8238 \end_layout
8239
8240 \end_inset
8241
8242 -tini-libid
8243 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8244
8245 \end_inset
8246
8247
8248 \series default
8249  <nnnn> LibraryID used in -mTININative.
8250  
8251 \end_layout
8252
8253 \begin_layout List
8254 \labelwidthstring 00.00.0000
8255
8256 \series bold
8257 -
8258 \begin_inset ERT
8259 status collapsed
8260
8261 \begin_layout Standard
8262
8263
8264 \backslash
8265 /
8266 \end_layout
8267
8268 \end_inset
8269
8270 -use-accelerator
8271 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8272
8273 \end_inset
8274
8275
8276 \series default
8277  generate code for DS390 Arithmetic Accelerator.
8278  
8279 \end_layout
8280
8281 \begin_layout Standard
8282 \begin_inset VSpace bigskip
8283 \end_inset
8284
8285
8286 \end_layout
8287
8288 \begin_layout Subsection
8289 Z80 Options
8290 \begin_inset LatexCommand \index{Options Z80}
8291
8292 \end_inset
8293
8294
8295 \begin_inset LatexCommand \index{Z80}
8296
8297 \end_inset
8298
8299
8300 \end_layout
8301
8302 \begin_layout List
8303 \labelwidthstring 00.00.0000
8304
8305 \series bold
8306 -
8307 \begin_inset ERT
8308 status collapsed
8309
8310 \begin_layout Standard
8311
8312
8313 \backslash
8314 /
8315 \end_layout
8316
8317 \end_inset
8318
8319 -callee-saves-bc
8320 \series default
8321
8322 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8323
8324 \end_inset
8325
8326
8327 \size large
8328 \emph on
8329  
8330 \size default
8331 \emph default
8332 Force a called function to always save BC.
8333 \end_layout
8334
8335 \begin_layout List
8336 \labelwidthstring 00.00.0000
8337
8338 \series bold
8339 -
8340 \begin_inset ERT
8341 status collapsed
8342
8343 \begin_layout Standard
8344
8345
8346 \backslash
8347 /
8348 \end_layout
8349
8350 \end_inset
8351
8352 -no-std-crt0
8353 \series default
8354
8355 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8356
8357 \end_inset
8358
8359  When linking, skip the standard crt0.o object file.
8360  You must provide your own crt0.o for your system when linking.
8361  
8362 \end_layout
8363
8364 \begin_layout Standard
8365 \begin_inset VSpace bigskip
8366 \end_inset
8367
8368
8369 \end_layout
8370
8371 \begin_layout Subsection
8372 Optimization Options
8373 \begin_inset LatexCommand \index{Options optimization}
8374
8375 \end_inset
8376
8377
8378 \begin_inset LatexCommand \index{Optimization options}
8379
8380 \end_inset
8381
8382
8383 \end_layout
8384
8385 \begin_layout List
8386 \labelwidthstring 00.00.0000
8387
8388 \series bold
8389 -
8390 \begin_inset ERT
8391 status collapsed
8392
8393 \begin_layout Standard
8394
8395
8396 \backslash
8397 /
8398 \end_layout
8399
8400 \end_inset
8401
8402 -nogcse
8403 \begin_inset LatexCommand \index{-\/-nogcse}
8404
8405 \end_inset
8406
8407
8408 \series default
8409  Will not do global subexpression elimination, this option may be used when
8410  the compiler creates undesirably large stack/data spaces to store compiler
8411  temporaries (
8412 \emph on
8413 s
8414 \emph default
8415 pill 
8416 \emph on
8417 loc
8418 \emph default
8419 ations, sloc
8420 \begin_inset LatexCommand \index{sloc (spill location)}
8421
8422 \end_inset
8423
8424 ).
8425  A warning message will be generated when this happens and the compiler
8426  will indicate the number of extra bytes it allocated.
8427  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8428 nogcse
8429 \begin_inset LatexCommand \index{\#pragma nogcse}
8430
8431 \end_inset
8432
8433  can be used to turn off global subexpression elimination
8434 \begin_inset LatexCommand \index{Subexpression elimination}
8435
8436 \end_inset
8437
8438  for a given function only.
8439 \end_layout
8440
8441 \begin_layout List
8442 \labelwidthstring 00.00.0000
8443
8444 \series bold
8445 -
8446 \begin_inset ERT
8447 status collapsed
8448
8449 \begin_layout Standard
8450
8451
8452 \backslash
8453 /
8454 \end_layout
8455
8456 \end_inset
8457
8458 -noinvariant
8459 \begin_inset LatexCommand \index{-\/-noinvariant}
8460
8461 \end_inset
8462
8463
8464 \series default
8465  Will not do loop invariant optimizations, this may be turned off for reasons
8466  explained for the previous option.
8467  For more details of loop optimizations performed see Loop Invariants in
8468  section 
8469 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8470
8471 \end_inset
8472
8473 .
8474  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8475 noinvariant
8476 \begin_inset LatexCommand \index{\#pragma noinvariant}
8477
8478 \end_inset
8479
8480  can be used to turn off invariant optimizations for a given function only.
8481 \end_layout
8482
8483 \begin_layout List
8484 \labelwidthstring 00.00.0000
8485
8486 \series bold
8487 -
8488 \begin_inset ERT
8489 status collapsed
8490
8491 \begin_layout Standard
8492
8493
8494 \backslash
8495 /
8496 \end_layout
8497
8498 \end_inset
8499
8500 -noinduction
8501 \begin_inset LatexCommand \index{-\/-noinduction}
8502
8503 \end_inset
8504
8505
8506 \series default
8507  Will not do loop induction optimizations, see section strength reduction
8508  for more details.
8509  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8510 noinduction
8511 \begin_inset LatexCommand \index{\#pragma noinduction}
8512
8513 \end_inset
8514
8515  can be used to turn off induction optimizations for a given function only.
8516 \end_layout
8517
8518 \begin_layout List
8519 \labelwidthstring 00.00.0000
8520
8521 \series bold
8522 -
8523 \begin_inset ERT
8524 status collapsed
8525
8526 \begin_layout Standard
8527
8528
8529 \backslash
8530 /
8531 \end_layout
8532
8533 \end_inset
8534
8535 -nojtbound
8536 \begin_inset LatexCommand \index{-\/-nojtbound}
8537
8538 \end_inset
8539
8540
8541 \size large
8542 \bar under
8543  
8544 \series default
8545 \size default
8546 \bar default
8547  Will not generate boundary condition check when switch statements
8548 \begin_inset LatexCommand \index{switch statement}
8549
8550 \end_inset
8551
8552  are implemented using jump-tables.
8553  See section 
8554 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8555
8556 \end_inset
8557
8558 \InsetSpace ~
8559 Switch Statements for more details.
8560  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8561 nojtbound
8562 \begin_inset LatexCommand \index{\#pragma nojtbound}
8563
8564 \end_inset
8565
8566  can be used to turn off boundary checking for jump tables for a given function
8567  only.
8568 \end_layout
8569
8570 \begin_layout List
8571 \labelwidthstring 00.00.0000
8572
8573 \series bold
8574 -
8575 \begin_inset ERT
8576 status collapsed
8577
8578 \begin_layout Standard
8579
8580
8581 \backslash
8582 /
8583 \end_layout
8584
8585 \end_inset
8586
8587 -noloopreverse
8588 \begin_inset LatexCommand \index{-\/-noloopreverse}
8589
8590 \end_inset
8591
8592
8593 \series default
8594 \size large
8595  
8596 \size default
8597 Will not do loop reversal 
8598 \begin_inset LatexCommand \index{Loop reversing}
8599
8600 \end_inset
8601
8602 optimization.
8603 \end_layout
8604
8605 \begin_layout List
8606 \labelwidthstring 00.00.0000
8607 -
8608 \begin_inset ERT
8609 status collapsed
8610
8611 \begin_layout Standard
8612
8613
8614 \backslash
8615 /
8616 \end_layout
8617
8618 \end_inset
8619
8620 -
8621 \series bold
8622 nolabelopt
8623 \series default
8624  
8625 \begin_inset LatexCommand \index{-\/-nolabelopt }
8626
8627 \end_inset
8628
8629 Will not optimize labels (makes the dumpfiles more readable).
8630 \end_layout
8631
8632 \begin_layout List
8633 \labelwidthstring 00.00.0000
8634
8635 \series bold
8636 -
8637 \begin_inset ERT
8638 status collapsed
8639
8640 \begin_layout Standard
8641
8642
8643 \backslash
8644 /
8645 \end_layout
8646
8647 \end_inset
8648
8649 -no-xinit-opt
8650 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8651
8652 \end_inset
8653
8654
8655 \series default
8656  Will not memcpy initialized data from code space into xdata space.
8657  This saves a few bytes in code space if you don't have initialized data
8658 \begin_inset LatexCommand \index{Variable initialization}
8659
8660 \end_inset
8661
8662 .
8663 \end_layout
8664
8665 \begin_layout List
8666 \labelwidthstring 00.00.0000
8667
8668 \series bold
8669 -
8670 \begin_inset ERT
8671 status collapsed
8672
8673 \begin_layout Standard
8674
8675
8676 \backslash
8677 /
8678 \end_layout
8679
8680 \end_inset
8681
8682 -nooverlay
8683 \begin_inset LatexCommand \index{-\/-nooverlay}
8684
8685 \end_inset
8686
8687
8688 \series default
8689   The compiler will not overlay parameters and local variables of any function,
8690  see section Parameters and local variables for more details.
8691 \end_layout
8692
8693 \begin_layout List
8694 \labelwidthstring 00.00.0000
8695
8696 \series bold
8697 -
8698 \begin_inset ERT
8699 status collapsed
8700
8701 \begin_layout Standard
8702
8703
8704 \backslash
8705 /
8706 \end_layout
8707
8708 \end_inset
8709
8710 -no-peep
8711 \begin_inset LatexCommand \index{-\/-no-peep}
8712
8713 \end_inset
8714
8715
8716 \series default
8717  Disable peep-hole optimization with built-in rules.
8718 \end_layout
8719
8720 \begin_layout List
8721 \labelwidthstring 00.00.0000
8722
8723 \series bold
8724 -
8725 \begin_inset ERT
8726 status collapsed
8727
8728 \begin_layout Standard
8729
8730
8731 \backslash
8732 /
8733 \end_layout
8734
8735 \end_inset
8736
8737 -peep-file
8738 \series default
8739
8740 \begin_inset LatexCommand \index{-\/-peep-file}
8741
8742 \end_inset
8743
8744 \InsetSpace ~
8745 <filename> This option can be used to use additional rules to be used by
8746  the peep hole optimizer.
8747  See section 
8748 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8749
8750 \end_inset
8751
8752 \InsetSpace ~
8753 Peep Hole optimizations for details on how to write these rules.
8754 \end_layout
8755
8756 \begin_layout List
8757 \labelwidthstring 00.00.0000
8758
8759 \series bold
8760 -
8761 \begin_inset ERT
8762 status collapsed
8763
8764 \begin_layout Standard
8765
8766
8767 \backslash
8768 /
8769 \end_layout
8770
8771 \end_inset
8772
8773 -peep-asm
8774 \begin_inset LatexCommand \index{-\/-peep-asm}
8775
8776 \end_inset
8777
8778
8779 \series default
8780  Pass the inline assembler code through the peep hole optimizer.
8781  This can cause unexpected changes to inline assembler code, please go through
8782  the peephole optimizer
8783 \begin_inset LatexCommand \index{Peephole optimizer}
8784
8785 \end_inset
8786
8787  rules defined in the source file tree '<target>/peeph.def' before using
8788  this option.
8789 \end_layout
8790
8791 \begin_layout List
8792 \labelwidthstring 00.00.0000
8793
8794 \series bold
8795 -
8796 \begin_inset ERT
8797 status collapsed
8798
8799 \begin_layout Standard
8800
8801
8802 \backslash
8803 /
8804 \end_layout
8805
8806 \end_inset
8807
8808 -opt-code-speed
8809 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8810
8811 \end_inset
8812
8813
8814 \series default
8815  The compiler will optimize code generation towards fast code, possibly
8816  at the expense of code size.
8817 \end_layout
8818
8819 \begin_layout List
8820 \labelwidthstring 00.00.0000
8821
8822 \series bold
8823 -
8824 \begin_inset ERT
8825 status collapsed
8826
8827 \begin_layout Standard
8828
8829
8830 \backslash
8831 /
8832 \end_layout
8833
8834 \end_inset
8835
8836 -opt-code-size
8837 \begin_inset LatexCommand \index{-\/-opt-code-size}
8838
8839 \end_inset
8840
8841
8842 \series default
8843  The compiler will optimize code generation towards compact code, possibly
8844  at the expense of code speed.
8845 \end_layout
8846
8847 \begin_layout Standard
8848 \begin_inset VSpace bigskip
8849 \end_inset
8850
8851
8852 \end_layout
8853
8854 \begin_layout Subsection
8855 Other Options
8856 \begin_inset LatexCommand \index{Options other}
8857
8858 \end_inset
8859
8860
8861 \end_layout
8862
8863 \begin_layout List
8864 \labelwidthstring 00.00.0000
8865
8866 \series bold
8867 -c\InsetSpace ~
8868 -
8869 \begin_inset ERT
8870 status collapsed
8871
8872 \begin_layout Standard
8873
8874
8875 \backslash
8876 /
8877 \end_layout
8878
8879 \end_inset
8880
8881 -compile-only
8882 \begin_inset LatexCommand \index{-\/-compile-only}
8883
8884 \end_inset
8885
8886
8887 \begin_inset LatexCommand \index{-c -\/-compile-only}
8888
8889 \end_inset
8890
8891
8892 \series default
8893  will compile and assemble the source, but will not call the linkage editor.
8894 \end_layout
8895
8896 \begin_layout List
8897 \labelwidthstring 00.00.0000
8898
8899 \series bold
8900 -
8901 \series default
8902
8903 \begin_inset ERT
8904 status collapsed
8905
8906 \begin_layout Standard
8907
8908
8909 \backslash
8910 /
8911 \end_layout
8912
8913 \end_inset
8914
8915
8916 \series bold
8917 -c1mode
8918 \begin_inset LatexCommand \index{-\/-c1mode}
8919
8920 \end_inset
8921
8922
8923 \series default
8924  reads the preprocessed source from standard input and compiles it.
8925  The file name for the assembler output must be specified using the -o option.
8926 \end_layout
8927
8928 \begin_layout List
8929 \labelwidthstring 00.00.0000
8930
8931 \series bold
8932 -E
8933 \begin_inset LatexCommand \index{-E}
8934
8935 \end_inset
8936
8937
8938 \series default
8939  Run only the C preprocessor.
8940  Preprocess all the C source files specified and output the results to standard
8941  output.
8942 \end_layout
8943
8944 \begin_layout List
8945 \labelwidthstring 00.00.0000
8946
8947 \series bold
8948 -o\InsetSpace ~
8949 <path/file>
8950 \begin_inset LatexCommand \index{-o <path/file>}
8951
8952 \end_inset
8953
8954  
8955 \series default
8956 The output path resp.
8957  file where everything will be placed.
8958  If the parameter is a path, it must have a trailing slash (or backslash
8959  for the Windows binaries) to be recognized as a path.
8960  
8961 \end_layout
8962
8963 \begin_layout List
8964 \labelwidthstring 00.00.0000
8965
8966 \series bold
8967 -
8968 \begin_inset ERT
8969 status collapsed
8970
8971 \begin_layout Standard
8972
8973
8974 \backslash
8975 /
8976 \end_layout
8977
8978 \end_inset
8979
8980 -stack-auto
8981 \begin_inset LatexCommand \index{-\/-stack-auto}
8982
8983 \end_inset
8984
8985
8986 \series default
8987 \size large
8988 \emph on
8989  
8990 \size default
8991 \emph default
8992 All functions in the source file will be compiled as 
8993 \emph on
8994 reentrant
8995 \emph default
8996
8997 \begin_inset LatexCommand \index{reentrant}
8998
8999 \end_inset
9000
9001 , i.e.
9002  the parameters and local variables will be allocated on the stack
9003 \begin_inset LatexCommand \index{stack}
9004
9005 \end_inset
9006
9007 .
9008  See section 
9009 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9010
9011 \end_inset
9012
9013  Parameters and Local Variables for more details.
9014  If this option is used all source files in the project should be compiled
9015  with this option.
9016  It automatically implies --int-long-reent and --float-reent.
9017  
9018 \end_layout
9019
9020 \begin_layout List
9021 \labelwidthstring 00.00.0000
9022
9023 \series bold
9024 -
9025 \begin_inset ERT
9026 status collapsed
9027
9028 \begin_layout Standard
9029
9030
9031 \backslash
9032 /
9033 \end_layout
9034
9035 \end_inset
9036
9037 -callee-saves
9038 \begin_inset LatexCommand \index{-\/-callee-saves}
9039
9040 \end_inset
9041
9042  function1[,function2][,function3]....
9043
9044 \series default
9045  The compiler by default uses a caller saves convention for register saving
9046  across function calls, however this can cause unnecessary register pushing
9047  & popping when calling small functions from larger functions.
9048  This option can be used to switch the register saving convention for the
9049  function names specified.
9050  The compiler will not save registers when calling these functions, no extra
9051  code will be generated at the entry & exit (function prologue
9052 \series bold
9053
9054 \begin_inset LatexCommand \index{function prologue}
9055
9056 \end_inset
9057
9058
9059 \series default
9060  & epilogue
9061 \series bold
9062
9063 \begin_inset LatexCommand \index{function epilogue}
9064
9065 \end_inset
9066
9067
9068 \series default
9069 ) for these functions to save & restore the registers used by these functions,
9070  this can SUBSTANTIALLY reduce code & improve run time performance of the
9071  generated code.
9072  In the future the compiler (with inter procedural analysis) will be able
9073  to determine the appropriate scheme to use for each function call.
9074  DO NOT use this option for built-in functions such as _mulint..., if this
9075  option is used for a library function the appropriate library function
9076  needs to be recompiled with the same option.
9077  If the project consists of multiple source files then all the source file
9078  should be compiled with the same -
9079 \begin_inset ERT
9080 status collapsed
9081
9082 \begin_layout Standard
9083
9084
9085 \backslash
9086 /
9087 \end_layout
9088
9089 \end_inset
9090
9091 -callee-saves option string.
9092  Also see #pragma\InsetSpace ~
9093 callee_saves
9094 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9095
9096 \end_inset
9097
9098 .
9099 \end_layout
9100
9101 \begin_layout List
9102 \labelwidthstring 00.00.0000
9103
9104 \series bold
9105 -
9106 \begin_inset ERT
9107 status collapsed
9108
9109 \begin_layout Standard
9110
9111
9112 \backslash
9113 /
9114 \end_layout
9115
9116 \end_inset
9117
9118 -debug
9119 \begin_inset LatexCommand \index{-\/-debug}
9120
9121 \end_inset
9122
9123
9124 \bar under
9125  
9126 \series default
9127 \bar default
9128 When this option is used the compiler will generate debug information.
9129  The debug information collected in a file with .cdb extension can be used
9130  with the SDCDB.
9131  For more information see documentation for SDCDB.
9132  Another file with no extension contains debug information in AOMF or AOMF51
9133 \begin_inset LatexCommand \index{AOMF, AOMF51}
9134
9135 \end_inset
9136
9137  format which is commonly used by third party tools.
9138 \end_layout
9139
9140 \begin_layout List
9141 \labelwidthstring 00.00.0000
9142
9143 \series bold
9144 -S
9145 \begin_inset LatexCommand \index{-S}
9146
9147 \end_inset
9148
9149
9150 \size large
9151 \bar under
9152  
9153 \series default
9154 \size default
9155 \bar default
9156 Stop after the stage of compilation proper; do not assemble.
9157  The output is an assembler code file for the input file specified.
9158 \end_layout
9159
9160 \begin_layout List
9161 \labelwidthstring 00.00.0000
9162
9163 \series bold
9164 -
9165 \begin_inset ERT
9166 status collapsed
9167
9168 \begin_layout Standard
9169
9170
9171 \backslash
9172 /
9173 \end_layout
9174
9175 \end_inset
9176
9177 -int-long-reent
9178 \begin_inset LatexCommand \index{-\/-int-long-reent}
9179
9180 \end_inset
9181
9182
9183 \series default
9184  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9185  Note by default these libraries are compiled as non-reentrant.
9186  See section Installation for more details.
9187 \end_layout
9188
9189 \begin_layout List
9190 \labelwidthstring 00.00.0000
9191
9192 \series bold
9193 -
9194 \begin_inset ERT
9195 status collapsed
9196
9197 \begin_layout Standard
9198
9199
9200 \backslash
9201 /
9202 \end_layout
9203
9204 \end_inset
9205
9206 -cyclomatic
9207 \begin_inset LatexCommand \index{-\/-cyclomatic}
9208
9209 \end_inset
9210
9211
9212 \bar under
9213  
9214 \series default
9215 \bar default
9216 This option will cause the compiler to generate an information message for
9217  each function in the source file.
9218  The message contains some 
9219 \emph on
9220 important
9221 \emph default
9222  information about the function.
9223  The number of edges and nodes the compiler detected in the control flow
9224  graph of the function, and most importantly the 
9225 \emph on
9226 cyclomatic complexity
9227 \begin_inset LatexCommand \index{Cyclomatic complexity}
9228
9229 \end_inset
9230
9231
9232 \emph default
9233  see section on Cyclomatic Complexity for more details.
9234 \end_layout
9235
9236 \begin_layout List
9237 \labelwidthstring 00.00.0000
9238
9239 \series bold
9240 -
9241 \begin_inset ERT
9242 status collapsed
9243
9244 \begin_layout Standard
9245
9246
9247 \backslash
9248 /
9249 \end_layout
9250
9251 \end_inset
9252
9253 -float-reent
9254 \begin_inset LatexCommand \index{-\/-float-reent}
9255
9256 \end_inset
9257
9258
9259 \series default
9260  Floating point library is compiled as reentrant
9261 \begin_inset LatexCommand \index{reentrant}
9262
9263 \end_inset
9264
9265 .
9266  See section Installation for more details.
9267 \end_layout
9268
9269 \begin_layout List
9270 \labelwidthstring 00.00.0000
9271
9272 \series bold
9273 -
9274 \begin_inset ERT
9275 status collapsed
9276
9277 \begin_layout Standard
9278
9279
9280 \backslash
9281 /
9282 \end_layout
9283
9284 \end_inset
9285
9286 -main-return
9287 \begin_inset LatexCommand \index{-\/-main-return}
9288
9289 \end_inset
9290
9291
9292 \series default
9293  This option can be used if the code generated is called by a monitor program
9294  or if the main routine includes an endless loop.
9295  This option results in slightly smaller code and saves two bytes of stack
9296  space.
9297  The return from the 'main'
9298 \begin_inset LatexCommand \index{main return}
9299
9300 \end_inset
9301
9302  function will return to the function calling main.
9303  The default setting is to lock up i.e.
9304  generate a '
9305 \family typewriter
9306 sjmp .
9307 \family default
9308 '.
9309 \end_layout
9310
9311 \begin_layout List
9312 \labelwidthstring 00.00.0000
9313
9314 \series bold
9315 -
9316 \begin_inset ERT
9317 status collapsed
9318
9319 \begin_layout Standard
9320
9321
9322 \backslash
9323 /
9324 \end_layout
9325
9326 \end_inset
9327
9328 -nostdinc
9329 \begin_inset LatexCommand \index{-\/-nostdinc}
9330
9331 \end_inset
9332
9333
9334 \series default
9335  This will prevent the compiler from passing on the default include path
9336  to the preprocessor.
9337 \end_layout
9338
9339 \begin_layout List
9340 \labelwidthstring 00.00.0000
9341
9342 \series bold
9343 -
9344 \begin_inset ERT
9345 status collapsed
9346
9347 \begin_layout Standard
9348
9349
9350 \backslash
9351 /
9352 \end_layout
9353
9354 \end_inset
9355
9356 -nostdlib
9357 \begin_inset LatexCommand \index{-\/-nostdlib}
9358
9359 \end_inset
9360
9361
9362 \series default
9363  This will prevent the compiler from passing on the default library
9364 \begin_inset LatexCommand \index{Libraries}
9365
9366 \end_inset
9367
9368  path to the linker.
9369 \end_layout
9370
9371 \begin_layout List
9372 \labelwidthstring 00.00.0000
9373
9374 \series bold
9375 -
9376 \begin_inset ERT
9377 status collapsed
9378
9379 \begin_layout Standard
9380
9381
9382 \backslash
9383 /
9384 \end_layout
9385
9386 \end_inset
9387
9388 -verbose
9389 \begin_inset LatexCommand \index{-\/-verbose}
9390
9391 \end_inset
9392
9393
9394 \series default
9395  Shows the various actions the compiler is performing.
9396 \end_layout
9397
9398 \begin_layout List
9399 \labelwidthstring 00.00.0000
9400
9401 \series bold
9402 -V
9403 \begin_inset LatexCommand \index{-V}
9404
9405 \end_inset
9406
9407
9408 \series default
9409  Shows the actual commands the compiler is executing.
9410 \end_layout
9411
9412 \begin_layout List
9413 \labelwidthstring 00.00.0000
9414
9415 \series bold
9416 -
9417 \begin_inset ERT
9418 status collapsed
9419
9420 \begin_layout Standard
9421
9422
9423 \backslash
9424 /
9425 \end_layout
9426
9427 \end_inset
9428
9429 -no-c-code-in-asm
9430 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9431
9432 \end_inset
9433
9434
9435 \series default
9436  Hides your ugly and inefficient c-code from the asm file, so you can always
9437  blame the compiler :)
9438 \end_layout
9439
9440 \begin_layout List
9441 \labelwidthstring 00.00.0000
9442
9443 \series bold
9444 -
9445 \begin_inset ERT
9446 status collapsed
9447
9448 \begin_layout Standard
9449
9450
9451 \backslash
9452 /
9453 \end_layout
9454
9455 \end_inset
9456
9457 -no-peep-comments
9458 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9459
9460 \end_inset
9461
9462
9463 \series default
9464  Will not include peep-hole comments in the generated files.
9465 \end_layout
9466
9467 \begin_layout List
9468 \labelwidthstring 00.00.0000
9469
9470 \series bold
9471 -
9472 \begin_inset ERT
9473 status collapsed
9474
9475 \begin_layout Standard
9476
9477
9478 \backslash
9479 /
9480 \end_layout
9481
9482 \end_inset
9483
9484 -i-code-in-asm
9485 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9486
9487 \end_inset
9488
9489
9490 \series default
9491  Include i-codes in the asm file.
9492  Sounds like noise but is most helpful for debugging the compiler itself.
9493 \end_layout
9494
9495 \begin_layout List
9496 \labelwidthstring 00.00.0000
9497
9498 \series bold
9499 -
9500 \begin_inset ERT
9501 status collapsed
9502
9503 \begin_layout Standard
9504
9505
9506 \backslash
9507 /
9508 \end_layout
9509
9510 \end_inset
9511
9512 -less-pedantic
9513 \begin_inset LatexCommand \index{-\/-less-pedantic}
9514
9515 \end_inset
9516
9517
9518 \series default
9519  Disable some of the more pedantic warnings
9520 \begin_inset LatexCommand \index{Warnings}
9521
9522 \end_inset
9523
9524  (jwk burps: please be more specific here, please!).
9525 \end_layout
9526
9527 \begin_layout List
9528 \labelwidthstring 00.00.0000
9529
9530 \series bold
9531 -
9532 \begin_inset ERT
9533 status collapsed
9534
9535 \begin_layout Standard
9536
9537
9538 \backslash
9539 /
9540 \end_layout
9541
9542 \end_inset
9543
9544 -disable-warning\InsetSpace ~
9545 <nnnn>
9546 \begin_inset LatexCommand \index{-\/-disable-warning}
9547
9548 \end_inset
9549
9550
9551 \series default
9552  Disable specific warning with number <nnnn>.
9553 \end_layout
9554
9555 \begin_layout List
9556 \labelwidthstring 00.00.0000
9557
9558 \series bold
9559 -
9560 \begin_inset ERT
9561 status collapsed
9562
9563 \begin_layout Standard
9564
9565
9566 \backslash
9567 /
9568 \end_layout
9569
9570 \end_inset
9571
9572 -print-search-dirs
9573 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9574
9575 \end_inset
9576
9577
9578 \series default
9579  Display the directories in the compiler's search path
9580 \end_layout
9581
9582 \begin_layout List
9583 \labelwidthstring 00.00.0000
9584
9585 \series bold
9586 -
9587 \begin_inset ERT
9588 status collapsed
9589
9590 \begin_layout Standard
9591
9592
9593 \backslash
9594 /
9595 \end_layout
9596
9597 \end_inset
9598
9599 -vc
9600 \begin_inset LatexCommand \index{-\/-vc}
9601
9602 \end_inset
9603
9604
9605 \series default
9606  Display errors and warnings using MSVC style, so you can use SDCC with
9607  the visual studio IDE
9608 \begin_inset LatexCommand \index{IDE}
9609
9610 \end_inset
9611
9612 .
9613  With SDCC both offering a GCC-like (the default) and a MSVC-like
9614 \begin_inset LatexCommand \index{MSVC output style}
9615
9616 \end_inset
9617
9618  output style, integration into most programming editors should be straightforwa
9619 rd.
9620 \end_layout
9621
9622 \begin_layout List
9623 \labelwidthstring 00.00.0000
9624
9625 \series bold
9626 -
9627 \begin_inset ERT
9628 status collapsed
9629
9630 \begin_layout Standard
9631
9632
9633 \backslash
9634 /
9635 \end_layout
9636
9637 \end_inset
9638
9639 -use-stdout
9640 \begin_inset LatexCommand \index{-\/-use-stdout}
9641
9642 \end_inset
9643
9644
9645 \series default
9646  Send errors and warnings to stdout instead of stderr.
9647 \end_layout
9648
9649 \begin_layout List
9650 \labelwidthstring 00.00.0000
9651
9652 \series bold
9653 -Wa\InsetSpace ~
9654 asmOption[,asmOption]
9655 \series default
9656
9657 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9658
9659 \end_inset
9660
9661 ...
9662  Pass the asmOption to the assembler
9663 \begin_inset LatexCommand \index{Options assembler}
9664
9665 \end_inset
9666
9667
9668 \begin_inset LatexCommand \index{Assembler options}
9669
9670 \end_inset
9671
9672 .
9673  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9674 \end_layout
9675
9676 \begin_layout List
9677 \labelwidthstring 00.00.0000
9678
9679 \series bold
9680 -
9681 \begin_inset ERT
9682 status collapsed
9683
9684 \begin_layout Standard
9685
9686
9687 \backslash
9688 /
9689 \end_layout
9690
9691 \end_inset
9692
9693 -std-sdcc89
9694 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9695
9696 \end_inset
9697
9698
9699 \series default
9700  Generally follow the C89 standard, but allow SDCC features that conflict
9701  with the standard (default).
9702 \end_layout
9703
9704 \begin_layout List
9705 \labelwidthstring 00.00.0000
9706
9707 \series bold
9708 -
9709 \begin_inset ERT
9710 status collapsed
9711
9712 \begin_layout Standard
9713
9714
9715 \backslash
9716 /
9717 \end_layout
9718
9719 \end_inset
9720
9721 -std-c89
9722 \begin_inset LatexCommand \index{-\/-std-c89}
9723
9724 \end_inset
9725
9726
9727 \series default
9728  Follow the C89 standard and disable SDCC features that conflict with the
9729  standard.
9730 \end_layout
9731
9732 \begin_layout List
9733 \labelwidthstring 00.00.0000
9734
9735 \series bold
9736 -
9737 \begin_inset ERT
9738 status collapsed
9739
9740 \begin_layout Standard
9741
9742
9743 \backslash
9744 /
9745 \end_layout
9746
9747 \end_inset
9748
9749 -std-sdcc99
9750 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9751
9752 \end_inset
9753
9754
9755 \series default
9756  Generally follow the C99 standard, but allow SDCC features that conflict
9757  with the standard (incomplete support).
9758 \end_layout
9759
9760 \begin_layout List
9761 \labelwidthstring 00.00.0000
9762
9763 \series bold
9764 -
9765 \begin_inset ERT
9766 status collapsed
9767
9768 \begin_layout Standard
9769
9770
9771 \backslash
9772 /
9773 \end_layout
9774
9775 \end_inset
9776
9777 -std-c99
9778 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9779
9780 \end_inset
9781
9782
9783 \series default
9784  Follow the C99 standard and disable SDCC features that conflict with the
9785  standard (incomplete support).
9786 \end_layout
9787
9788 \begin_layout List
9789 \labelwidthstring 00.00.0000
9790
9791 \series bold
9792 -
9793 \begin_inset ERT
9794 status collapsed
9795
9796 \begin_layout Standard
9797
9798
9799 \backslash
9800 /
9801 \end_layout
9802
9803 \end_inset
9804
9805 -codeseg
9806 \series default
9807
9808 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9809
9810 \end_inset
9811
9812 \InsetSpace ~
9813 <Name> The name to be used for the code
9814 \begin_inset LatexCommand \index{code}
9815
9816 \end_inset
9817
9818  segment, default CSEG.
9819  This is useful if you need to tell the compiler to put the code in a special
9820  segment so you can later on tell the linker to put this segment in a special
9821  place in memory.
9822  Can be used for instance when using bank switching to put the code in a
9823  bank.
9824 \end_layout
9825
9826 \begin_layout List
9827 \labelwidthstring 00.00.0000
9828
9829 \series bold
9830 -
9831 \begin_inset ERT
9832 status collapsed
9833
9834 \begin_layout Standard
9835
9836
9837 \backslash
9838 /
9839 \end_layout
9840
9841 \end_inset
9842
9843 -constseg
9844 \series default
9845
9846 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9847
9848 \end_inset
9849
9850 \InsetSpace ~
9851 <Name> The name to be used for the const
9852 \begin_inset LatexCommand \index{code}
9853
9854 \end_inset
9855
9856  segment, default CONST.
9857  This is useful if you need to tell the compiler to put the const data in
9858  a special segment so you can later on tell the linker to put this segment
9859  in a special place in memory.
9860  Can be used for instance when using bank switching to put the const data
9861  in a bank.
9862 \end_layout
9863
9864 \begin_layout List
9865 \labelwidthstring 00.00.0000
9866
9867 \series bold
9868 -
9869 \begin_inset ERT
9870 status collapsed
9871
9872 \begin_layout Standard
9873
9874
9875 \backslash
9876 /
9877 \end_layout
9878
9879 \end_inset
9880
9881 -fdollars-in-identifiers
9882 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9883
9884 \end_inset
9885
9886
9887 \series default
9888  Permit '$' as an identifier character
9889 \end_layout
9890
9891 \begin_layout List
9892 \labelwidthstring 00.00.0000
9893
9894 \series bold
9895 more-pedantic
9896 \series default
9897  Actually this is 
9898 \series bold
9899 \emph on
9900 not
9901 \series default
9902 \emph default
9903  a SDCC compiler option but if you want 
9904 \emph on
9905 more
9906 \emph default
9907  warnings you can use a separate tool dedicated to syntax checking like
9908  splint
9909 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9910
9911 \end_inset
9912
9913
9914 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9915
9916 \end_inset
9917
9918  
9919 \begin_inset LatexCommand \url{http://www.splint.org}
9920
9921 \end_inset
9922
9923 .
9924  To make your source files parseable by splint you will have to include
9925  
9926 \family sans
9927 lint.h
9928 \family default
9929
9930 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9931
9932 \end_inset
9933
9934  in your source file and add brackets around extended keywords (like 
9935 \family sans
9936
9937 \begin_inset Quotes sld
9938 \end_inset
9939
9940 __at\InsetSpace ~
9941
9942 \series bold
9943 (
9944 \series default
9945 0xab
9946 \series bold
9947 )
9948 \series default
9949
9950 \begin_inset Quotes srd
9951 \end_inset
9952
9953
9954 \family default
9955  and 
9956 \family sans
9957
9958 \begin_inset Quotes sld
9959 \end_inset
9960
9961 __interrupt\InsetSpace ~
9962 (2)
9963 \begin_inset Quotes srd
9964 \end_inset
9965
9966
9967 \family default
9968 ).
9969  
9970 \newline
9971 Splint has an excellent on line manual at 
9972 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9973
9974 \end_inset
9975
9976  and it's capabilities go beyond pure syntax checking.
9977  You'll need to tell splint the location of SDCC's include files so a typical
9978  command line could look like this: 
9979 \newline
9980
9981 \family sans
9982 splint\InsetSpace ~
9983 -I\InsetSpace ~
9984 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
9985 \InsetSpace ~
9986 myprogram.c
9987 \end_layout
9988
9989 \begin_layout Standard
9990 \begin_inset VSpace bigskip
9991 \end_inset
9992
9993
9994 \end_layout
9995
9996 \begin_layout Subsection
9997 Intermediate Dump Options
9998 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
9999
10000 \end_inset
10001
10002
10003 \begin_inset LatexCommand \index{Options intermediate dump}
10004
10005 \end_inset
10006
10007
10008 \begin_inset LatexCommand \index{Intermediate dump options}
10009
10010 \end_inset
10011
10012
10013 \end_layout
10014
10015 \begin_layout Standard
10016 The following options are provided for the purpose of retargetting and debugging
10017  the compiler.
10018  They provide a means to dump the intermediate code (iCode
10019 \begin_inset LatexCommand \index{iCode}
10020
10021 \end_inset
10022
10023 ) generated by the compiler in human readable form at various stages of
10024  the compilation process.
10025  More on iCodes see chapter 
10026 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10027
10028 \end_inset
10029
10030  
10031 \begin_inset Quotes srd
10032 \end_inset
10033
10034 The anatomy of the compiler
10035 \begin_inset Quotes srd
10036 \end_inset
10037
10038 .
10039 \end_layout
10040
10041 \begin_layout List
10042 \labelwidthstring 00.00.0000
10043
10044 \series bold
10045 -
10046 \begin_inset ERT
10047 status collapsed
10048
10049 \begin_layout Standard
10050
10051
10052 \backslash
10053 /
10054 \end_layout
10055
10056 \end_inset
10057
10058 -dumpraw
10059 \begin_inset LatexCommand \index{-\/-dumpraw}
10060
10061 \end_inset
10062
10063
10064 \series default
10065  This option will cause the compiler to dump the intermediate code into
10066  a file of named 
10067 \emph on
10068 <source filename>.dumpraw
10069 \emph default
10070  just after the intermediate code has been generated for a function, i.e.
10071  before any optimizations are done.
10072  The basic blocks
10073 \begin_inset LatexCommand \index{Basic blocks}
10074
10075 \end_inset
10076
10077  at this stage ordered in the depth first number, so they may not be in
10078  sequence of execution.
10079 \end_layout
10080
10081 \begin_layout List
10082 \labelwidthstring 00.00.0000
10083
10084 \series bold
10085 -
10086 \begin_inset ERT
10087 status collapsed
10088
10089 \begin_layout Standard
10090
10091
10092 \backslash
10093 /
10094 \end_layout
10095
10096 \end_inset
10097
10098 -dumpgcse
10099 \begin_inset LatexCommand \index{-\/-dumpgcse}
10100
10101 \end_inset
10102
10103
10104 \series default
10105  Will create a dump of iCode's, after global subexpression elimination
10106 \begin_inset LatexCommand \index{Global subexpression elimination}
10107
10108 \end_inset
10109
10110 , into a file named 
10111 \emph on
10112 <source filename>.dumpgcse.
10113 \end_layout
10114
10115 \begin_layout List
10116 \labelwidthstring 00.00.0000
10117
10118 \series bold
10119 -
10120 \begin_inset ERT
10121 status collapsed
10122
10123 \begin_layout Standard
10124
10125
10126 \backslash
10127 /
10128 \end_layout
10129
10130 \end_inset
10131
10132 -dumpdeadcode
10133 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10134
10135 \end_inset
10136
10137
10138 \series default
10139  Will create a dump of iCode's, after deadcode elimination
10140 \begin_inset LatexCommand \index{Dead-code elimination}
10141
10142 \end_inset
10143
10144 , into a file named 
10145 \emph on
10146 <source filename>.dumpdeadcode.
10147 \end_layout
10148
10149 \begin_layout List
10150 \labelwidthstring 00.00.0000
10151
10152 \series bold
10153 -
10154 \begin_inset ERT
10155 status collapsed
10156
10157 \begin_layout Standard
10158
10159
10160 \backslash
10161 /
10162 \end_layout
10163
10164 \end_inset
10165
10166 -dumploop
10167 \begin_inset LatexCommand \index{-\/-dumploop}
10168
10169 \end_inset
10170
10171
10172 \series default
10173 \size large
10174  
10175 \size default
10176 Will create a dump of iCode's, after loop optimizations
10177 \begin_inset LatexCommand \index{Loop optimization}
10178
10179 \end_inset
10180
10181 , into a file named 
10182 \emph on
10183 <source filename>.dumploop.
10184 \end_layout
10185
10186 \begin_layout List
10187 \labelwidthstring 00.00.0000
10188
10189 \series bold
10190 -
10191 \begin_inset ERT
10192 status collapsed
10193
10194 \begin_layout Standard
10195
10196
10197 \backslash
10198 /
10199 \end_layout
10200
10201 \end_inset
10202
10203 -dumprange
10204 \begin_inset LatexCommand \index{-\/-dumprange}
10205
10206 \end_inset
10207
10208
10209 \series default
10210 \size large
10211  
10212 \size default
10213 Will create a dump of iCode's, after live range analysis
10214 \begin_inset LatexCommand \index{Live range analysis}
10215
10216 \end_inset
10217
10218 , into a file named 
10219 \emph on
10220 <source filename>.dumprange.
10221 \end_layout
10222
10223 \begin_layout List
10224 \labelwidthstring 00.00.0000
10225
10226 \series bold
10227 -
10228 \begin_inset ERT
10229 status collapsed
10230
10231 \begin_layout Standard
10232
10233
10234 \backslash
10235 /
10236 \end_layout
10237
10238 \end_inset
10239
10240 -dumlrange
10241 \begin_inset LatexCommand \index{-\/-dumlrange}
10242
10243 \end_inset
10244
10245
10246 \series default
10247  Will dump the life ranges
10248 \begin_inset LatexCommand \index{Live range analysis}
10249
10250 \end_inset
10251
10252  for all symbols.
10253 \end_layout
10254
10255 \begin_layout List
10256 \labelwidthstring 00.00.0000
10257
10258 \series bold
10259 -
10260 \begin_inset ERT
10261 status collapsed
10262
10263 \begin_layout Standard
10264
10265
10266 \backslash
10267 /
10268 \end_layout
10269
10270 \end_inset
10271
10272 -dumpregassign
10273 \begin_inset LatexCommand \index{-\/-dumpregassign}
10274
10275 \end_inset
10276
10277
10278 \bar under
10279  
10280 \series default
10281 \bar default
10282 Will create a dump of iCode's, after register assignment
10283 \begin_inset LatexCommand \index{Register assignment}
10284
10285 \end_inset
10286
10287 , into a file named 
10288 \emph on
10289 <source filename>.dumprassgn.
10290 \end_layout
10291
10292 \begin_layout List
10293 \labelwidthstring 00.00.0000
10294
10295 \series bold
10296 -
10297 \begin_inset ERT
10298 status collapsed
10299
10300 \begin_layout Standard
10301
10302
10303 \backslash
10304 /
10305 \end_layout
10306
10307 \end_inset
10308
10309 -dumplrange
10310 \begin_inset LatexCommand \index{-\/-dumplrange}
10311
10312 \end_inset
10313
10314
10315 \series default
10316  Will create a dump of the live ranges of iTemp's
10317 \end_layout
10318
10319 \begin_layout List
10320 \labelwidthstring 00.00.0000
10321
10322 \series bold
10323 -
10324 \begin_inset ERT
10325 status collapsed
10326
10327 \begin_layout Standard
10328
10329
10330 \backslash
10331 /
10332 \end_layout
10333
10334 \end_inset
10335
10336 -dumpall
10337 \begin_inset LatexCommand \index{-\/-dumpall}
10338
10339 \end_inset
10340
10341
10342 \size large
10343 \bar under
10344  
10345 \series default
10346 \size default
10347 \bar default
10348 Will cause all the above mentioned dumps to be created.
10349 \end_layout
10350
10351 \begin_layout Standard
10352 \begin_inset VSpace bigskip
10353 \end_inset
10354
10355
10356 \end_layout
10357
10358 \begin_layout Subsection
10359 Redirecting output on Windows Shells
10360 \end_layout
10361
10362 \begin_layout Standard
10363 By default SDCC writes it's error messages to 
10364 \begin_inset Quotes sld
10365 \end_inset
10366
10367 standard error
10368 \begin_inset Quotes srd
10369 \end_inset
10370
10371 .
10372  To force all messages to 
10373 \begin_inset Quotes sld
10374 \end_inset
10375
10376 standard output
10377 \begin_inset Quotes srd
10378 \end_inset
10379
10380  use 
10381 \series bold
10382 -
10383 \series default
10384 \emph on
10385
10386 \begin_inset ERT
10387 status collapsed
10388
10389 \begin_layout Standard
10390
10391
10392 \backslash
10393 /
10394 \end_layout
10395
10396 \end_inset
10397
10398
10399 \series bold
10400 \emph default
10401 -
10402 \series default
10403 use-stdout
10404 \begin_inset LatexCommand \index{-\/-use-stdout}
10405
10406 \end_inset
10407
10408 .
10409  Additionally, if you happen to have visual studio installed in your windows
10410  machine, you can use it to compile your sources using a custom build and
10411  the SDCC -
10412 \emph on
10413
10414 \begin_inset ERT
10415 status collapsed
10416
10417 \begin_layout Standard
10418
10419
10420 \backslash
10421 /
10422 \end_layout
10423
10424 \end_inset
10425
10426
10427 \emph default
10428 -vc
10429 \begin_inset LatexCommand \index{-\/-vc}
10430
10431 \end_inset
10432
10433  option.
10434  Something like this should work:
10435 \newline
10436
10437 \newline
10438
10439 \series bold
10440 c:
10441 \backslash
10442 sdcc
10443 \backslash
10444 bin
10445 \backslash
10446 sdcc.exe -
10447 \series default
10448 \emph on
10449
10450 \begin_inset ERT
10451 status collapsed
10452
10453 \begin_layout Standard
10454
10455
10456 \backslash
10457 /
10458 \end_layout
10459
10460 \end_inset
10461
10462
10463 \series bold
10464 \emph default
10465 -vc -
10466 \series default
10467 \emph on
10468
10469 \begin_inset ERT
10470 status collapsed
10471
10472 \begin_layout Standard
10473
10474
10475 \backslash
10476 /
10477 \end_layout
10478
10479 \end_inset
10480
10481
10482 \series bold
10483 \emph default
10484 -model-large -c $(InputPath)
10485 \series default
10486
10487 \begin_inset VSpace bigskip
10488 \end_inset
10489
10490
10491 \end_layout
10492
10493 \begin_layout Section
10494 Environment variables
10495 \begin_inset LatexCommand \index{Environment variables}
10496
10497 \end_inset
10498
10499
10500 \end_layout
10501
10502 \begin_layout Standard
10503 SDCC recognizes the following environment variables:
10504 \end_layout
10505
10506 \begin_layout List
10507 \labelwidthstring 00.00.0000
10508
10509 \series bold
10510 SDCC_LEAVE_SIGNALS
10511 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10512
10513 \end_inset
10514
10515
10516 \series default
10517  SDCC installs a signal handler
10518 \begin_inset LatexCommand \index{signal handler}
10519
10520 \end_inset
10521
10522  to be able to delete temporary files after an user break (^C) or an exception.
10523  If this environment variable is set, SDCC won't install the signal handler
10524  in order to be able to debug SDCC.
10525 \end_layout
10526
10527 \begin_layout List
10528 \labelwidthstring 00.00.0000
10529
10530 \series bold
10531 TMP,\InsetSpace ~
10532 TEMP,\InsetSpace ~
10533 TMPDIR
10534 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10535
10536 \end_inset
10537
10538
10539 \series default
10540  Path, where temporary files will be created.
10541  The order of the variables is the search order.
10542  In a standard *nix environment these variables are not set, and there's
10543  no need to set them.
10544  On Windows it's recommended to set one of them.
10545 \end_layout
10546
10547 \begin_layout List
10548 \labelwidthstring 00.00.0000
10549
10550 \series bold
10551 SDCC_HOME
10552 \begin_inset LatexCommand \index{SDCC\_HOME}
10553
10554 \end_inset
10555
10556
10557 \series default
10558  Path, see section 
10559 \begin_inset LatexCommand \ref{sub:Install-paths}
10560
10561 \end_inset
10562
10563 \InsetSpace ~
10564
10565 \begin_inset Quotes sld
10566 \end_inset
10567
10568  Install Paths
10569 \begin_inset Quotes srd
10570 \end_inset
10571
10572 .
10573 \end_layout
10574
10575 \begin_layout List
10576 \labelwidthstring 00.00.0000
10577
10578 \series bold
10579 SDCC_INCLUDE
10580 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10581
10582 \end_inset
10583
10584
10585 \series default
10586  Path, see section 
10587 \begin_inset LatexCommand \ref{sub:Search-Paths}
10588
10589 \end_inset
10590
10591 \InsetSpace ~
10592
10593 \begin_inset Quotes sld
10594 \end_inset
10595
10596 Search Paths
10597 \begin_inset Quotes srd
10598 \end_inset
10599
10600 .
10601 \end_layout
10602
10603 \begin_layout List
10604 \labelwidthstring 00.00.0000
10605
10606 \series bold
10607 SDCC_LIB
10608 \begin_inset LatexCommand \index{SDCC\_LIB}
10609
10610 \end_inset
10611
10612
10613 \series default
10614  Path, see section 
10615 \begin_inset LatexCommand \ref{sub:Search-Paths}
10616
10617 \end_inset
10618
10619 \InsetSpace ~
10620
10621 \begin_inset Quotes sld
10622 \end_inset
10623
10624 Search Paths
10625 \begin_inset Quotes srd
10626 \end_inset
10627
10628 ..
10629 \end_layout
10630
10631 \begin_layout Standard
10632 There are some more environment variables recognized by SDCC, but these
10633  are solely used for debugging purposes.
10634  They can change or disappear very quickly, and will never be documented.
10635 \begin_inset VSpace bigskip
10636 \end_inset
10637
10638
10639 \end_layout
10640
10641 \begin_layout Section
10642 Storage Class Language Extensions
10643 \end_layout
10644
10645 \begin_layout Subsection
10646 MCS51/DS390 Storage Class
10647 \begin_inset LatexCommand \index{Storage class}
10648
10649 \end_inset
10650
10651  Language Extensions
10652 \end_layout
10653
10654 \begin_layout Standard
10655 In addition to the ANSI storage classes SDCC allows the following MCS51
10656  specific storage classes:
10657 \end_layout
10658
10659 \begin_layout Subsubsection
10660 data
10661 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10662
10663 \end_inset
10664
10665
10666 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10667
10668 \end_inset
10669
10670  / near
10671 \begin_inset LatexCommand \index{near (storage class)}
10672
10673 \end_inset
10674
10675
10676 \begin_inset LatexCommand \index{\_\_near (storage class)}
10677
10678 \end_inset
10679
10680
10681 \end_layout
10682
10683 \begin_layout Standard
10684 This is the 
10685 \series bold
10686 default
10687 \series default
10688  storage class for the Small Memory model (
10689 \emph on
10690 data
10691 \emph default
10692  and 
10693 \emph on
10694 near
10695 \emph default
10696  or the more ANSI-C compliant forms 
10697 \emph on
10698 __data
10699 \emph default
10700  and 
10701 \emph on
10702 __near
10703 \emph default
10704  can be used synonymously).
10705  Variables declared with this storage class will be allocated in the directly
10706  addressable portion of the internal RAM of a 8051, e.g.:
10707 \end_layout
10708
10709 \begin_layout Verse
10710
10711 \family typewriter
10712 __data unsigned char test_data;
10713 \end_layout
10714
10715 \begin_layout Standard
10716 Writing 0x01 to this variable generates the assembly code:
10717 \end_layout
10718
10719 \begin_layout Verse
10720
10721 \family typewriter
10722 75*00 01\InsetSpace ~
10723 \InsetSpace ~
10724 \InsetSpace ~
10725 mov\InsetSpace ~
10726 \InsetSpace ~
10727 _test_data,#0x01
10728 \end_layout
10729
10730 \begin_layout Subsubsection
10731 xdata
10732 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10733
10734 \end_inset
10735
10736
10737 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10738
10739 \end_inset
10740
10741  / far
10742 \begin_inset LatexCommand \index{far (storage class)}
10743
10744 \end_inset
10745
10746
10747 \begin_inset LatexCommand \index{\_\_far (storage class)}
10748
10749 \end_inset
10750
10751
10752 \end_layout
10753
10754 \begin_layout Standard
10755 Variables declared with this storage class will be placed in the external
10756  RAM.
10757  This is the 
10758 \series bold
10759 default
10760 \series default
10761  storage class for the Large Memory model, e.g.:
10762 \end_layout
10763
10764 \begin_layout Verse
10765
10766 \family typewriter
10767 __xdata unsigned char test_xdata;
10768 \end_layout
10769
10770 \begin_layout Standard
10771 Writing 0x01 to this variable generates the assembly code:
10772 \end_layout
10773
10774 \begin_layout Verse
10775
10776 \family typewriter
10777 90s00r00\InsetSpace ~
10778 \InsetSpace ~
10779 \InsetSpace ~
10780 mov\InsetSpace ~
10781 \InsetSpace ~
10782 dptr,#_test_xdata 
10783 \newline
10784 74\InsetSpace ~
10785 01\InsetSpace ~
10786 \InsetSpace ~
10787 \InsetSpace ~
10788 \InsetSpace ~
10789 \InsetSpace ~
10790 \InsetSpace ~
10791 mov\InsetSpace ~
10792 \InsetSpace ~
10793 a,#0x01 
10794 \newline
10795 F0\InsetSpace ~
10796 \InsetSpace ~
10797 \InsetSpace ~
10798 \InsetSpace ~
10799 \InsetSpace ~
10800 \InsetSpace ~
10801 \InsetSpace ~
10802 \InsetSpace ~
10803 \InsetSpace ~
10804 movx\InsetSpace ~
10805 @dptr,a 
10806 \end_layout
10807
10808 \begin_layout Subsubsection
10809 idata
10810 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10811
10812 \end_inset
10813
10814
10815 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10816
10817 \end_inset
10818
10819
10820 \end_layout
10821
10822 \begin_layout Standard
10823 Variables declared with this storage class will be allocated into the indirectly
10824  addressable portion of the internal ram of a 8051, e.g.:
10825 \end_layout
10826
10827 \begin_layout Verse
10828
10829 \family typewriter
10830 __idata unsigned char test_idata;
10831 \end_layout
10832
10833 \begin_layout Standard
10834 Writing 0x01 to this variable generates the assembly code:
10835 \end_layout
10836
10837 \begin_layout Verse
10838
10839 \family typewriter
10840 78r00\InsetSpace ~
10841 \InsetSpace ~
10842 \InsetSpace ~
10843 \InsetSpace ~
10844 \InsetSpace ~
10845 \InsetSpace ~
10846 \InsetSpace ~
10847 mov\InsetSpace ~
10848 \InsetSpace ~
10849 r0,#_test_idata
10850 \newline
10851 76\InsetSpace ~
10852 01\InsetSpace ~
10853 \InsetSpace ~
10854 \InsetSpace ~
10855 \InsetSpace ~
10856 \InsetSpace ~
10857 \InsetSpace ~
10858 \InsetSpace ~
10859 mov\InsetSpace ~
10860 \InsetSpace ~
10861 @r0,#0x01
10862 \end_layout
10863
10864 \begin_layout Standard
10865 Please note, the first 128 byte of idata physically access the same RAM
10866  as the data memory.
10867  The original 8051 had 128 byte idata memory, nowadays most devices have
10868  256 byte idata memory.
10869  The stack
10870 \begin_inset LatexCommand \index{stack}
10871
10872 \end_inset
10873
10874  is located in idata memory.
10875 \end_layout
10876
10877 \begin_layout Subsubsection
10878 pdata
10879 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10880
10881 \end_inset
10882
10883
10884 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10885
10886 \end_inset
10887
10888
10889 \end_layout
10890
10891 \begin_layout Standard
10892 Paged xdata access is just as straightforward as using the other addressing
10893  modes of a 8051.
10894  It is typically located at the start of xdata and has a maximum size of
10895  256 bytes.
10896  The following example writes 0x01 to the pdata variable.
10897  Please note, pdata access physically accesses xdata memory.
10898  The high byte of the address is determined by port P2 
10899 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10900
10901 \end_inset
10902
10903 (or in case of some 8051 variants by a separate Special Function Register,
10904  see section 
10905 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10906
10907 \end_inset
10908
10909 ).
10910  This is the 
10911 \series bold
10912 default
10913 \series default
10914  storage class for the Medium Memory model, e.g.:
10915 \end_layout
10916
10917 \begin_layout Verse
10918
10919 \family typewriter
10920 __pdata unsigned char test_pdata;
10921 \end_layout
10922
10923 \begin_layout Standard
10924 Writing 0x01 to this variable generates the assembly code:
10925 \end_layout
10926
10927 \begin_layout Verse
10928
10929 \family typewriter
10930 78r00\InsetSpace ~
10931 \InsetSpace ~
10932 \InsetSpace ~
10933 \InsetSpace ~
10934 \InsetSpace ~
10935 \InsetSpace ~
10936 mov r0,#_test_pdata
10937 \newline
10938 74 01\InsetSpace ~
10939 \InsetSpace ~
10940 \InsetSpace ~
10941 \InsetSpace ~
10942 \InsetSpace ~
10943 \InsetSpace ~
10944 mov a,#0x01 
10945 \newline
10946 F2\InsetSpace ~
10947 \InsetSpace ~
10948 \InsetSpace ~
10949 \InsetSpace ~
10950 \InsetSpace ~
10951 \InsetSpace ~
10952 \InsetSpace ~
10953 \InsetSpace ~
10954 \InsetSpace ~
10955 movx @r0,a
10956 \end_layout
10957
10958 \begin_layout Standard
10959 If the -
10960 \begin_inset ERT
10961 status collapsed
10962
10963 \begin_layout Standard
10964
10965
10966 \backslash
10967 /
10968 \end_layout
10969
10970 \end_inset
10971
10972 -xstack
10973 \begin_inset LatexCommand \index{-\/-xstack}
10974
10975 \end_inset
10976
10977  option is used the pdata memory area is followed by the xstack memory area
10978  and the sum of their sizes is limited to 256 bytes.
10979 \end_layout
10980
10981 \begin_layout Subsubsection
10982 code
10983 \begin_inset LatexCommand \index{code}
10984
10985 \end_inset
10986
10987
10988 \begin_inset LatexCommand \index{\_\_code}
10989
10990 \end_inset
10991
10992
10993 \end_layout
10994
10995 \begin_layout Standard
10996 'Variables' declared with this storage class will be placed in the code
10997  memory:
10998 \end_layout
10999
11000 \begin_layout Verse
11001
11002 \family typewriter
11003 __code unsigned char test_code;
11004 \end_layout
11005
11006 \begin_layout Standard
11007 Read access to this variable generates the assembly code:
11008 \end_layout
11009
11010 \begin_layout Verse
11011
11012 \family typewriter
11013 90s00r6F\InsetSpace ~
11014 \InsetSpace ~
11015 \InsetSpace ~
11016 mov dptr,#_test_code
11017 \newline
11018 E4\InsetSpace ~
11019 \InsetSpace ~
11020 \InsetSpace ~
11021 \InsetSpace ~
11022 \InsetSpace ~
11023 \InsetSpace ~
11024 \InsetSpace ~
11025 \InsetSpace ~
11026 \InsetSpace ~
11027 clr a
11028 \newline
11029 93\InsetSpace ~
11030 \InsetSpace ~
11031 \InsetSpace ~
11032 \InsetSpace ~
11033 \InsetSpace ~
11034 \InsetSpace ~
11035 \InsetSpace ~
11036 \InsetSpace ~
11037 \InsetSpace ~
11038 movc a,@a+dptr 
11039 \end_layout
11040
11041 \begin_layout Standard
11042
11043 \family typewriter
11044 char
11045 \family default
11046  indexed arrays of characters in code memory can be accessed efficiently:
11047 \end_layout
11048
11049 \begin_layout Verse
11050
11051 \family typewriter
11052 __code char test_array[] = {'c','h','e','a','p'}; 
11053 \end_layout
11054
11055 \begin_layout Standard
11056 Read access to this array using an 8-bit unsigned index generates the assembly
11057  code:
11058 \end_layout
11059
11060 \begin_layout Verse
11061
11062 \family typewriter
11063 E5*00\InsetSpace ~
11064 \InsetSpace ~
11065 \InsetSpace ~
11066 \InsetSpace ~
11067 \InsetSpace ~
11068 \InsetSpace ~
11069 mov a,_index 
11070 \end_layout
11071
11072 \begin_layout Verse
11073
11074 \family typewriter
11075 90s00r41\InsetSpace ~
11076 \InsetSpace ~
11077 \InsetSpace ~
11078 mov dptr,#_test_array
11079 \end_layout
11080
11081 \begin_layout Verse
11082
11083 \family typewriter
11084 93\InsetSpace ~
11085 \InsetSpace ~
11086 \InsetSpace ~
11087 \InsetSpace ~
11088 \InsetSpace ~
11089 \InsetSpace ~
11090 \InsetSpace ~
11091 \InsetSpace ~
11092 \InsetSpace ~
11093 movc a,@a+dptr 
11094 \end_layout
11095
11096 \begin_layout Subsubsection
11097 bit
11098 \begin_inset LatexCommand \index{bit}
11099
11100 \end_inset
11101
11102
11103 \begin_inset LatexCommand \index{\_\_bit}
11104
11105 \end_inset
11106
11107
11108 \end_layout
11109
11110 \begin_layout Standard
11111 This is a data-type and a storage class specifier.
11112  When a variable is declared as a bit, it is allocated into the bit addressable
11113  memory of 8051, e.g.:
11114 \end_layout
11115
11116 \begin_layout Verse
11117
11118 \family typewriter
11119 __bit test_bit;
11120 \end_layout
11121
11122 \begin_layout Standard
11123 Writing 1 to this variable generates the assembly code:
11124 \end_layout
11125
11126 \begin_layout Verse
11127
11128 \family typewriter
11129 D2*00\InsetSpace ~
11130 \InsetSpace ~
11131 \InsetSpace ~
11132 \InsetSpace ~
11133 \InsetSpace ~
11134 \InsetSpace ~
11135 \InsetSpace ~
11136 setb\InsetSpace ~
11137 _test_bit
11138 \end_layout
11139
11140 \begin_layout Standard
11141 The bit addressable memory consists of 128 bits which are located from 0x20
11142  to 0x2f in data memory.
11143  
11144 \newline
11145 Apart from this 8051 specific storage class most architectures support
11146  ANSI-C bitfields
11147 \begin_inset LatexCommand \index{bitfields}
11148
11149 \end_inset
11150
11151
11152 \begin_inset Foot
11153 status open
11154
11155 \begin_layout Standard
11156 Not really meant as examples, but nevertheless showing what bitfields are
11157  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11158 \end_layout
11159
11160 \end_inset
11161
11162 .
11163  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11164  signed modifier are implemented as unsigned.
11165 \end_layout
11166
11167 \begin_layout Subsubsection
11168 sfr
11169 \begin_inset LatexCommand \index{sfr}
11170
11171 \end_inset
11172
11173
11174 \begin_inset LatexCommand \index{\_\_sfr}
11175
11176 \end_inset
11177
11178  / sfr16
11179 \begin_inset LatexCommand \index{sfr16}
11180
11181 \end_inset
11182
11183
11184 \begin_inset LatexCommand \index{\_\_sfr16}
11185
11186 \end_inset
11187
11188  / sfr32
11189 \begin_inset LatexCommand \index{sfr32}
11190
11191 \end_inset
11192
11193
11194 \begin_inset LatexCommand \index{\_\_sfr32}
11195
11196 \end_inset
11197
11198  / sbit
11199 \begin_inset LatexCommand \index{\_\_sbit}
11200
11201 \end_inset
11202
11203
11204 \begin_inset LatexCommand \index{sbit}
11205
11206 \end_inset
11207
11208
11209 \end_layout
11210
11211 \begin_layout Standard
11212 Like the bit keyword, 
11213 \emph on
11214 sfr / sfr16 / sfr32 / sbit 
11215 \emph default
11216 signify both a data-type and storage class, they are used to describe the
11217  
11218 \emph on
11219 s
11220 \emph default
11221 pecial 
11222 \emph on
11223 f
11224 \emph default
11225 unction 
11226 \emph on
11227 r
11228 \emph default
11229 egisters and 
11230 \emph on
11231 s
11232 \emph default
11233 pecial 
11234 \emph on
11235 bit
11236 \emph default
11237  variables of a 8051, eg:
11238 \end_layout
11239
11240 \begin_layout Verse
11241
11242 \family typewriter
11243 __sfr __at
11244 \begin_inset LatexCommand \index{at}
11245
11246 \end_inset
11247
11248
11249 \begin_inset LatexCommand \index{\_\_at}
11250
11251 \end_inset
11252
11253  (0x80) P0;\InsetSpace ~
11254  /* special function register P0 at location 0x80 */
11255 \newline
11256
11257 \newline
11258 /* 16 bit
11259  special function register combination for timer 0
11260 \newline
11261 \InsetSpace ~
11262 \InsetSpace ~
11263  with the high byte at
11264  location 0x8C and the low byte at location 0x8A */
11265 \newline
11266 __sfr16 __at (0x8C8A)
11267  TMR0;
11268 \newline
11269
11270 \newline
11271 __sbit __at
11272 \begin_inset LatexCommand \index{at}
11273
11274 \end_inset
11275
11276
11277 \begin_inset LatexCommand \index{\_\_at}
11278
11279 \end_inset
11280
11281  (0xd7) CY;\InsetSpace ~
11282  /* CY (Carry Flag
11283 \begin_inset LatexCommand \index{Flags}
11284
11285 \end_inset
11286
11287
11288 \begin_inset LatexCommand \index{Carry flag}
11289
11290 \end_inset
11291
11292 ) */
11293 \end_layout
11294
11295 \begin_layout Standard
11296 Special function registers which are located on an address dividable by
11297  8 are bit-addressable, an
11298 \emph on
11299  sbit
11300 \emph default
11301  addresses a specific bit within these sfr.
11302 \newline
11303 16 Bit and 32 bit special function
11304  register combinations which require a certain access order are better not
11305  declared using 
11306 \emph on
11307 sfr16
11308 \emph default
11309  or 
11310 \emph on
11311 sfr32.
11312
11313 \emph default
11314  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11315  this is not guaranteed.
11316 \newline
11317
11318 \end_layout
11319
11320 \begin_layout Standard
11321 Please note, if you use a header file which was written for another compiler
11322  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11323  likely be 
11324 \emph on
11325 not 
11326 \emph default
11327 compatible.
11328  Specifically the syntax 
11329 \family typewriter
11330 \InsetSpace ~
11331 sfr P0 = 0x80;\InsetSpace ~
11332
11333 \family default
11334  is compiled 
11335 \emph on
11336 without warning
11337 \emph default
11338  by SDCC to an assignment of 0x80 to a variable called P0 
11339 \family typewriter
11340
11341 \begin_inset Marginal
11342 status collapsed
11343
11344 \begin_layout Standard
11345
11346 \series bold
11347 \InsetSpace ~
11348 !
11349 \end_layout
11350
11351 \end_inset
11352
11353 .
11354  
11355 \family default
11356 Nevertheless it is possible to write header files
11357 \begin_inset LatexCommand \index{Header files}
11358
11359 \end_inset
11360
11361
11362 \begin_inset LatexCommand \index{Include files}
11363
11364 \end_inset
11365
11366  which can be shared among different compilers (see section 
11367 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11368
11369 \end_inset
11370
11371 ).
11372  
11373 \end_layout
11374
11375 \begin_layout Subsubsection
11376 Pointers
11377 \begin_inset LatexCommand \index{Pointer}
11378
11379 \end_inset
11380
11381  to MCS51/DS390 specific memory spaces
11382 \end_layout
11383
11384 \begin_layout Standard
11385 SDCC allows (via language extensions) pointers to explicitly point to any
11386  of the memory spaces
11387 \begin_inset LatexCommand \index{Memory model}
11388
11389 \end_inset
11390
11391  of the 8051.
11392  In addition to the explicit pointers, the compiler uses (by default) generic
11393  pointers which can be used to point to any of the memory spaces.
11394 \newline
11395
11396 \newline
11397 Pointer
11398  declaration examples:
11399 \end_layout
11400
11401 \begin_layout Verse
11402
11403 \family typewriter
11404 /* pointer physically in internal ram pointing to object in external ram
11405  */ 
11406 \newline
11407 __xdata unsigned char * __data p;
11408 \newline
11409
11410 \newline
11411 /* pointer physically in external ram
11412  pointing to object in internal ram */ 
11413 \newline
11414 __data unsigned char * __xdata p;
11415 \newline
11416
11417 \newline
11418 /*
11419  pointer physically in code rom pointing to data in xdata space */ 
11420 \newline
11421 __xdata
11422  unsigned char * __code p;
11423 \newline
11424
11425 \newline
11426 /* pointer physically in code space pointing to
11427  data in code space */ 
11428 \newline
11429 __code unsigned char * __code p;
11430 \newline
11431
11432 \newline
11433 /* generic pointer
11434  physically located in xdata space */
11435 \newline
11436 unsigned char * __xdata p;
11437 \newline
11438
11439 \newline
11440 /* generic
11441  pointer physically located in default memory space */
11442 \newline
11443 unsigned char * p;
11444 \newline
11445
11446 \newline
11447 /*
11448  the following is a function pointer
11449 \begin_inset LatexCommand \index{function pointer}
11450
11451 \end_inset
11452
11453  physically located in data space */
11454 \newline
11455 char (* __data fp)(void);
11456 \end_layout
11457
11458 \begin_layout Standard
11459 Well you get the idea.
11460  
11461 \newline
11462
11463 \newline
11464 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
11465 \emph on
11466 generic
11467 \emph default
11468  pointers.
11469  
11470 \size small
11471
11472 \newline
11473
11474 \newline
11475
11476 \size default
11477 The highest order byte of the 
11478 \emph on
11479 generic
11480 \emph default
11481  pointers contains the data space information.
11482  Assembler support routines are called whenever data is stored or retrieved
11483  using 
11484 \emph on
11485 generic
11486 \emph default
11487  pointers.
11488  These are useful for developing reusable library
11489 \begin_inset LatexCommand \index{Libraries}
11490
11491 \end_inset
11492
11493  routines.
11494  Explicitly specifying the pointer
11495 \begin_inset LatexCommand \index{pointer}
11496
11497 \end_inset
11498
11499  type will generate the most efficient code.
11500 \end_layout
11501
11502 \begin_layout Subsubsection
11503 Notes on MCS51 memory
11504 \begin_inset LatexCommand \index{MCS51 memory}
11505
11506 \end_inset
11507
11508  layout
11509 \end_layout
11510
11511 \begin_layout Standard
11512 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11513  RAM memory which is structured as follows:
11514 \newline
11515
11516 \newline
11517 - Bytes 00-1F - 32 bytes to hold
11518  up to 4 banks of the registers R0 to R7, 
11519 \newline
11520 - Bytes 20-2F - 16 bytes to hold
11521  128 bit
11522 \begin_inset LatexCommand \index{bit}
11523
11524 \end_inset
11525
11526  variables and, 
11527 \newline
11528 - Bytes 30-7F - 80 bytes for general purpose use.
11529 \newline
11530
11531 \end_layout
11532
11533 \begin_layout Standard
11534 Additionally some members of the MCS51 family may have up to 128 bytes of
11535  additional, indirectly addressable, internal RAM memory (
11536 \emph on
11537 idata
11538 \emph default
11539
11540 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11541
11542 \end_inset
11543
11544
11545 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11546
11547 \end_inset
11548
11549 ).
11550  Furthermore, some chips may have some built in external memory (
11551 \emph on
11552 xdata
11553 \emph default
11554
11555 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11556
11557 \end_inset
11558
11559
11560 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11561
11562 \end_inset
11563
11564 ) which should not be confused with the internal, directly addressable RAM
11565  memory (
11566 \emph on
11567 data
11568 \emph default
11569
11570 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11571
11572 \end_inset
11573
11574
11575 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11576
11577 \end_inset
11578
11579 ).
11580  Sometimes this built in 
11581 \emph on
11582 xdata
11583 \emph default
11584  memory has to be activated before using it (you can probably find this
11585  information on the datasheet of the microcontroller your are using, see
11586  also section 
11587 \begin_inset LatexCommand \ref{sub:Startup-Code}
11588
11589 \end_inset
11590
11591 \InsetSpace ~
11592 Startup-Code).
11593 \end_layout
11594
11595 \begin_layout Standard
11596 Normally SDCC will only use the first bank
11597 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11598
11599 \end_inset
11600
11601  of registers (register bank 0), but it is possible to specify that other
11602  banks of registers (keyword 
11603 \emph on
11604 using
11605 \emph default
11606  
11607 \emph on
11608
11609 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11610
11611 \end_inset
11612
11613
11614 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11615
11616 \end_inset
11617
11618
11619 \emph default
11620 ) should be used in interrupt
11621 \begin_inset LatexCommand \index{interrupt}
11622
11623 \end_inset
11624
11625
11626 \begin_inset LatexCommand \index{\_\_interrupt}
11627
11628 \end_inset
11629
11630  routines.
11631  By default, the compiler will place the stack after the last byte of allocated
11632  memory for variables.
11633  For example, if the first 2 banks of registers are used, and only four
11634  bytes are used for 
11635 \emph on
11636 data
11637 \emph default
11638  variables, it will position the base of the internal stack at address 20
11639  (0x14).
11640  This implies that as the stack
11641 \begin_inset LatexCommand \index{stack}
11642
11643 \end_inset
11644
11645  grows, it will use up the remaining register banks, and the 16 bytes used
11646  by the 128 bit variables, and 80 bytes for general purpose use.
11647  If any bit variables are used, the data variables will be placed in unused
11648  register banks and after the byte holding the last bit variable.
11649  For example, if register banks 0 and 1 are used, and there are 9 bit variables
11650  (two bytes used), 
11651 \emph on
11652 data
11653 \emph default
11654  variables will be placed starting from address 0x10 to 0x20 and continue
11655  at address 0x22.
11656  You can also use -
11657 \begin_inset ERT
11658 status collapsed
11659
11660 \begin_layout Standard
11661
11662
11663 \backslash
11664 /
11665 \end_layout
11666
11667 \end_inset
11668
11669 -data-loc
11670 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11671
11672 \end_inset
11673
11674  to specify the start address of the 
11675 \emph on
11676 data
11677 \emph default
11678  and -
11679 \begin_inset ERT
11680 status collapsed
11681
11682 \begin_layout Standard
11683
11684
11685 \backslash
11686 /
11687 \end_layout
11688
11689 \end_inset
11690
11691 -iram-size
11692 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11693
11694 \end_inset
11695
11696  to specify the size of the total internal RAM (
11697 \emph on
11698 data
11699 \emph default
11700 +
11701 \emph on
11702 idata
11703 \emph default
11704 ).
11705  
11706 \newline
11707
11708 \end_layout
11709
11710 \begin_layout Standard
11711 By default the 8051 linker will place the stack after the last byte of (i)data
11712  variables.
11713  Option -
11714 \begin_inset ERT
11715 status collapsed
11716
11717 \begin_layout Standard
11718
11719
11720 \backslash
11721 /
11722 \end_layout
11723
11724 \end_inset
11725
11726 -stack-loc
11727 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
11728
11729 \end_inset
11730
11731  allows you to specify the start of the stack, i.e.
11732  you could start it after any data in the general purpose area.
11733  If your microcontroller has additional indirectly addressable internal
11734  RAM (
11735 \emph on
11736 idata
11737 \emph default
11738 ) you can place the stack on it.
11739  You may also need to use -
11740 \begin_inset ERT
11741 status collapsed
11742
11743 \begin_layout Standard
11744
11745
11746 \backslash
11747 /
11748 \end_layout
11749
11750 \end_inset
11751
11752 -xdata-loc
11753 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
11754
11755 \end_inset
11756
11757  to set the start address of the external RAM (
11758 \emph on
11759 xdata
11760 \emph default
11761 ) and -
11762 \begin_inset ERT
11763 status collapsed
11764
11765 \begin_layout Standard
11766
11767
11768 \backslash
11769 /
11770 \end_layout
11771
11772 \end_inset
11773
11774 -xram-size
11775 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
11776
11777 \end_inset
11778
11779  to specify its size.
11780  Same goes for the code memory, using -
11781 \begin_inset ERT
11782 status collapsed
11783
11784 \begin_layout Standard
11785
11786
11787 \backslash
11788 /
11789 \end_layout
11790
11791 \end_inset
11792
11793 -code-loc
11794 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
11795
11796 \end_inset
11797
11798  and -
11799 \begin_inset ERT
11800 status collapsed
11801
11802 \begin_layout Standard
11803
11804
11805 \backslash
11806 /
11807 \end_layout
11808
11809 \end_inset
11810
11811 -code-size
11812 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11813
11814 \end_inset
11815
11816 .
11817  If in doubt, don't specify any options and see if the resulting memory
11818  layout is appropriate, then you can adjust it.
11819 \end_layout
11820
11821 \begin_layout Standard
11822 The linker generates two files with memory allocation information.
11823  The first, with extension .map
11824 \begin_inset LatexCommand \index{<file>.map}
11825
11826 \end_inset
11827
11828  shows all the variables and segments.
11829  The second with extension .mem
11830 \begin_inset LatexCommand \index{<file>.mem}
11831
11832 \end_inset
11833
11834  shows the final memory layout.
11835  The linker will complain either if memory segments overlap, there is not
11836  enough memory, or there is not enough space for stack.
11837  If you get any linking warnings and/or errors related to stack or segments
11838  allocation, take a look at either the .map or .mem files to find out what
11839  the problem is.
11840  The .mem file may even suggest a solution to the problem.
11841 \begin_inset VSpace bigskip
11842 \end_inset
11843
11844
11845 \end_layout
11846
11847 \begin_layout Subsection
11848 Z80/Z180 Storage Class
11849 \begin_inset LatexCommand \index{Z80!Storage class}
11850
11851 \end_inset
11852
11853  Language Extensions
11854 \end_layout
11855
11856 \begin_layout Subsubsection
11857 sfr
11858 \begin_inset LatexCommand \index{sfr}
11859
11860 \end_inset
11861
11862
11863 \begin_inset LatexCommand \index{\_\_sfr}
11864
11865 \end_inset
11866
11867  (in/out to 8-bit addresses)
11868 \end_layout
11869
11870 \begin_layout Standard
11871 The Z80
11872 \begin_inset LatexCommand \index{Z80}
11873
11874 \end_inset
11875
11876  family has separate address spaces for memory and 
11877 \emph on
11878 i
11879 \emph default
11880 nput/
11881 \emph on
11882 o
11883 \emph default
11884 utput memory.
11885  I/O memory
11886 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11887
11888 \end_inset
11889
11890
11891 \begin_inset LatexCommand \index{Z80!I/O memory}
11892
11893 \end_inset
11894
11895
11896 \begin_inset LatexCommand \index{Z180!I/O memory}
11897
11898 \end_inset
11899
11900  is accessed with special instructions, e.g.:
11901 \end_layout
11902
11903 \begin_layout Verse
11904
11905 \family typewriter
11906 sfr at 0x78 IoPort;\InsetSpace ~
11907 \InsetSpace ~
11908 /* define a var in I/O space at 78h called IoPort */
11909  
11910 \end_layout
11911
11912 \begin_layout Standard
11913 Writing 0x01 to this variable generates the assembly code:
11914 \end_layout
11915
11916 \begin_layout Verse
11917
11918 \family typewriter
11919 3E 01\InsetSpace ~
11920 \InsetSpace ~
11921 \InsetSpace ~
11922 \InsetSpace ~
11923 \InsetSpace ~
11924 \InsetSpace ~
11925 ld a,#0x01
11926 \newline
11927 D3 78\InsetSpace ~
11928 \InsetSpace ~
11929 \InsetSpace ~
11930 \InsetSpace ~
11931 \InsetSpace ~
11932 \InsetSpace ~
11933 out (_IoPort),a 
11934 \end_layout
11935
11936 \begin_layout Subsubsection
11937 banked sfr
11938 \begin_inset LatexCommand \index{sfr}
11939
11940 \end_inset
11941
11942
11943 \begin_inset LatexCommand \index{\_\_sfr}
11944
11945 \end_inset
11946
11947  (in/out to 16-bit addresses)
11948 \end_layout
11949
11950 \begin_layout Standard
11951 The keyword 
11952 \emph on
11953 banked
11954 \emph default
11955  is used to support 16 bit addresses in I/O memory e.g.:
11956 \end_layout
11957
11958 \begin_layout Verse
11959
11960 \family typewriter
11961 sfr banked at
11962 \begin_inset LatexCommand \index{at}
11963
11964 \end_inset
11965
11966
11967 \begin_inset LatexCommand \index{\_\_at}
11968
11969 \end_inset
11970
11971  0x123 IoPort; 
11972 \end_layout
11973
11974 \begin_layout Standard
11975 Writing 0x01 to this variable generates the assembly code:
11976 \end_layout
11977
11978 \begin_layout Verse
11979
11980 \family typewriter
11981 01 23 01\InsetSpace ~
11982 \InsetSpace ~
11983 \InsetSpace ~
11984 ld bc,#_IoPort
11985 \newline
11986 3E 01\InsetSpace ~
11987 \InsetSpace ~
11988 \InsetSpace ~
11989 \InsetSpace ~
11990 \InsetSpace ~
11991 \InsetSpace ~
11992 ld a,#0x01 
11993 \newline
11994 ED 79\InsetSpace ~
11995 \InsetSpace ~
11996 \InsetSpace ~
11997 \InsetSpace ~
11998 \InsetSpace ~
11999 \InsetSpace ~
12000 out (c),a 
12001 \end_layout
12002
12003 \begin_layout Subsubsection
12004 sfr
12005 \begin_inset LatexCommand \index{sfr}
12006
12007 \end_inset
12008
12009
12010 \begin_inset LatexCommand \index{\_\_sfr}
12011
12012 \end_inset
12013
12014  (in0/out0 to 8 bit addresses on Z180
12015 \begin_inset LatexCommand \index{Z180}
12016
12017 \end_inset
12018
12019 /HD64180
12020 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12021
12022 \end_inset
12023
12024 )
12025 \end_layout
12026
12027 \begin_layout Standard
12028 The compiler option -
12029 \begin_inset ERT
12030 status collapsed
12031
12032 \begin_layout Standard
12033
12034
12035 \backslash
12036 /
12037 \end_layout
12038
12039 \end_inset
12040
12041 -portmode
12042 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12043
12044 \end_inset
12045
12046 =180 (80) and a compiler #pragma\InsetSpace ~
12047 portmode
12048 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12049
12050 \end_inset
12051
12052  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12053 ns 
12054 \family typewriter
12055 in0/out0
12056 \family default
12057  instead of 
12058 \family typewriter
12059 in/out
12060 \family default
12061 .
12062  If you include the file z180.h this will be set automatically.
12063 \begin_inset VSpace bigskip
12064 \end_inset
12065
12066
12067 \end_layout
12068
12069 \begin_layout Subsection
12070 HC08 Storage Class
12071 \begin_inset LatexCommand \index{HC08!Storage class}
12072
12073 \end_inset
12074
12075  Language Extensions
12076 \end_layout
12077
12078 \begin_layout Subsubsection
12079 data
12080 \begin_inset LatexCommand \index{data (hc08 storage class)}
12081
12082 \end_inset
12083
12084
12085 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12086
12087 \end_inset
12088
12089  
12090 \end_layout
12091
12092 \begin_layout Standard
12093 The data storage class declares a variable that resides in the first 256
12094  bytes of memory (the direct page).
12095  The HC08
12096 \begin_inset LatexCommand \index{HC08}
12097
12098 \end_inset
12099
12100  is most efficient at accessing variables (especially pointers) stored here.
12101 \end_layout
12102
12103 \begin_layout Subsubsection
12104 xdata
12105 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12106
12107 \end_inset
12108
12109
12110 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12111
12112 \end_inset
12113
12114  
12115 \end_layout
12116
12117 \begin_layout Standard
12118 The xdata storage class declares a variable that can reside anywhere in
12119  memory.
12120  This is the default if no storage class is specified.
12121  
12122 \begin_inset VSpace bigskip
12123 \end_inset
12124
12125
12126 \end_layout
12127
12128 \begin_layout Section
12129 Absolute Addressing
12130 \begin_inset LatexCommand \index{Absolute addressing}
12131
12132 \end_inset
12133
12134
12135 \end_layout
12136
12137 \begin_layout Standard
12138 Data items can be assigned an absolute address with the 
12139 \emph on
12140 at
12141 \begin_inset LatexCommand \index{at}
12142
12143 \end_inset
12144
12145
12146 \begin_inset LatexCommand \index{\_\_at}
12147
12148 \end_inset
12149
12150  <address>
12151 \emph default
12152  keyword, in addition to a storage class, e.g.:
12153 \end_layout
12154
12155 \begin_layout Verse
12156
12157 \family typewriter
12158 xdata
12159 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12160
12161 \end_inset
12162
12163
12164 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12165
12166 \end_inset
12167
12168  at
12169 \begin_inset LatexCommand \index{at}
12170
12171 \end_inset
12172
12173
12174 \begin_inset LatexCommand \index{\_\_at}
12175
12176 \end_inset
12177
12178  0x7ffe unsigned int chksum;
12179 \end_layout
12180
12181 \begin_layout Standard
12182 or, better conforming to ISO/IEC 9899 C:
12183 \end_layout
12184
12185 \begin_layout Verse
12186
12187 \family typewriter
12188 __xdata __at (0x7ffe) unsigned int chksum;
12189 \end_layout
12190
12191 \begin_layout Standard
12192 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12193  of the external ram.
12194  The compiler does 
12195 \emph on
12196 not
12197 \emph default
12198  reserve any space for variables declared in this way
12199 \begin_inset Marginal
12200 status collapsed
12201
12202 \begin_layout Standard
12203
12204 \series bold
12205 \InsetSpace ~
12206 !
12207 \end_layout
12208
12209 \end_inset
12210
12211  (they are implemented with an equate in the assembler).
12212  Thus it is left to the programmer to make sure there are no overlaps with
12213  other variables that are declared without the absolute address.
12214  The assembler listing file (.lst
12215 \begin_inset LatexCommand \index{<file>.lst}
12216
12217 \end_inset
12218
12219 ) and the linker output files (.rst
12220 \begin_inset LatexCommand \index{<file>.rst}
12221
12222 \end_inset
12223
12224 ) and (.map
12225 \begin_inset LatexCommand \index{<file>.map}
12226
12227 \end_inset
12228
12229 ) are good places to look for such overlaps.
12230  Variables with an absolute address are 
12231 \emph on
12232 not
12233 \begin_inset Marginal
12234 status collapsed
12235
12236 \begin_layout Standard
12237
12238 \series bold
12239 \InsetSpace ~
12240 !
12241 \end_layout
12242
12243 \end_inset
12244
12245
12246 \emph default
12247  initialized
12248 \begin_inset LatexCommand \index{Variable initialization}
12249
12250 \end_inset
12251
12252 .
12253 \end_layout
12254
12255 \begin_layout Standard
12256 In case of memory mapped I/O devices the keyword 
12257 \emph on
12258 volatile
12259 \emph default
12260  has to be used to tell the compiler that accesses might not be removed:
12261 \end_layout
12262
12263 \begin_layout Verse
12264
12265 \family typewriter
12266 volatile
12267 \begin_inset LatexCommand \index{volatile}
12268
12269 \end_inset
12270
12271  __xdata
12272 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12273
12274 \end_inset
12275
12276  __at
12277 \begin_inset LatexCommand \index{at}
12278
12279 \end_inset
12280
12281  (0x8000) unsigned char PORTA_8255;
12282 \end_layout
12283
12284 \begin_layout Standard
12285 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12286 r) array
12287 \family typewriter
12288 \size footnotesize
12289
12290 \begin_inset LatexCommand \index{Aligned array}
12291
12292 \end_inset
12293
12294
12295 \family default
12296 \size default
12297  starts at a block (256 byte) boundary
12298 \begin_inset LatexCommand \index{block boundary}
12299
12300 \end_inset
12301
12302  (section 
12303 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12304
12305 \end_inset
12306
12307  has an example).
12308 \newline
12309 Absolute addresses can be specified for variables in all
12310  storage classes, e.g.:
12311 \end_layout
12312
12313 \begin_layout Verse
12314
12315 \family typewriter
12316 __bit
12317 \begin_inset LatexCommand \index{bit}
12318
12319 \end_inset
12320
12321  __at
12322 \begin_inset LatexCommand \index{at}
12323
12324 \end_inset
12325
12326  (0x02) bvar;
12327 \end_layout
12328
12329 \begin_layout Standard
12330 The above example will allocate the variable at offset 0x02 in the bit-addressab
12331 le space.
12332  There is no real advantage to assigning absolute addresses to variables
12333  in this manner, unless you want strict control over all the variables allocated.
12334  One possible use would be to write hardware portable code.
12335  For example, if you have a routine that uses one or more of the microcontroller
12336  I/O pins, and such pins are different for two different hardwares, you
12337  can declare the I/O pins in your routine using:
12338 \end_layout
12339
12340 \begin_layout Verse
12341
12342 \family typewriter
12343 extern volatile
12344 \begin_inset LatexCommand \index{volatile}
12345
12346 \end_inset
12347
12348  __bit MOSI;\InsetSpace ~
12349 \InsetSpace ~
12350 \InsetSpace ~
12351 \InsetSpace ~
12352 /* master out, slave in */
12353 \newline
12354 extern volatile __bit MISO;\InsetSpace ~
12355 \InsetSpace ~
12356 \InsetSpace ~
12357 \InsetSpace ~
12358 /* master
12359  in, slave out */
12360 \newline
12361 extern volatile __bit MCLK;\InsetSpace ~
12362 \InsetSpace ~
12363 \InsetSpace ~
12364 \InsetSpace ~
12365 /* master clock */
12366 \newline
12367
12368 \newline
12369 /* Input and
12370  Output of a byte on a 3-wire serial bus.
12371 \newline
12372 \InsetSpace ~
12373 \InsetSpace ~
12374 \InsetSpace ~
12375 If needed adapt polarity of clock,
12376  polarity of data and bit order
12377 \newline
12378 \InsetSpace ~
12379 */
12380 \newline
12381 unsigned char spi_io(unsigned char out_byte)
12382  
12383 \newline
12384
12385 \newline
12386 \InsetSpace ~
12387 \InsetSpace ~
12388 \InsetSpace ~
12389 \InsetSpace ~
12390 unsigned char i=8;
12391 \newline
12392 \InsetSpace ~
12393 \InsetSpace ~
12394 \InsetSpace ~
12395 \InsetSpace ~
12396 do { 
12397 \newline
12398 \InsetSpace ~
12399 \InsetSpace ~
12400 \InsetSpace ~
12401 \InsetSpace ~
12402 \InsetSpace ~
12403 \InsetSpace ~
12404 \InsetSpace ~
12405 \InsetSpace ~
12406 MOSI = out_byte & 0x80; 
12407 \newline
12408 \InsetSpace ~
12409 \InsetSpace ~
12410 \InsetSpace ~
12411 \InsetSpace ~
12412 \InsetSpace ~
12413 \InsetSpace ~
12414 \InsetSpace ~
12415 \InsetSpace ~
12416 out_byte <<= 1;
12417 \newline
12418 \InsetSpace ~
12419 \InsetSpace ~
12420 \InsetSpace ~
12421 \InsetSpace ~
12422 \InsetSpace ~
12423 \InsetSpace ~
12424 \InsetSpace ~
12425 \InsetSpace ~
12426 MCLK =
12427  1; 
12428 \newline
12429 \InsetSpace ~
12430 \InsetSpace ~
12431 \InsetSpace ~
12432 \InsetSpace ~
12433 \InsetSpace ~
12434 \InsetSpace ~
12435 \InsetSpace ~
12436 \InsetSpace ~
12437 /* _asm nop _endasm; */\InsetSpace ~
12438 \InsetSpace ~
12439 \InsetSpace ~
12440 \InsetSpace ~
12441 \InsetSpace ~
12442 \InsetSpace ~
12443 \InsetSpace ~
12444 \InsetSpace ~
12445 /* for slow peripherals */
12446 \newline
12447 \InsetSpace ~
12448 \InsetSpace ~
12449 \InsetSpace ~
12450 \InsetSpace ~
12451 \InsetSpace ~
12452 \InsetSpace ~
12453 \InsetSpace ~
12454 \InsetSpace ~
12455 if(MISO) 
12456 \newline
12457 \InsetSpace ~
12458 \InsetSpace ~
12459 \InsetSpace ~
12460 \InsetSpace ~
12461 \InsetSpace ~
12462 \InsetSpace ~
12463 \InsetSpace ~
12464 \InsetSpace ~
12465 \InsetSpace ~
12466 \InsetSpace ~
12467 \InsetSpace ~
12468 \InsetSpace ~
12469 out_byte +=
12470  1; 
12471 \newline
12472 \InsetSpace ~
12473 \InsetSpace ~
12474 \InsetSpace ~
12475 \InsetSpace ~
12476 \InsetSpace ~
12477 \InsetSpace ~
12478 \InsetSpace ~
12479 \InsetSpace ~
12480 MCLK = 0; 
12481 \newline
12482 \InsetSpace ~
12483 \InsetSpace ~
12484 \InsetSpace ~
12485 \InsetSpace ~
12486 } while(--i);
12487 \newline
12488 \InsetSpace ~
12489 \InsetSpace ~
12490 \InsetSpace ~
12491 \InsetSpace ~
12492 return out_byte; 
12493 \newline
12494 }
12495 \end_layout
12496
12497 \begin_layout Standard
12498 Then, someplace in the code for the first hardware you would use
12499 \end_layout
12500
12501 \begin_layout Verse
12502
12503 \family typewriter
12504 __bit __at
12505 \begin_inset LatexCommand \index{at}
12506
12507 \end_inset
12508
12509
12510 \begin_inset LatexCommand \index{\_\_at}
12511
12512 \end_inset
12513
12514  (0x80) MOSI;\InsetSpace ~
12515 \InsetSpace ~
12516 \InsetSpace ~
12517 \InsetSpace ~
12518 /* I/O port 0, bit 0 */
12519 \newline
12520 __bit __at (0x81) MISO;\InsetSpace ~
12521 \InsetSpace ~
12522 \InsetSpace ~
12523 \InsetSpace ~
12524 /* I/O port 0,
12525  bit 1 */
12526 \newline
12527 __bit __at (0x82) MCLK;\InsetSpace ~
12528 \InsetSpace ~
12529 \InsetSpace ~
12530 \InsetSpace ~
12531 /* I/O port 0, bit 2 */
12532 \end_layout
12533
12534 \begin_layout Standard
12535 Similarly, for the second hardware you would use
12536 \end_layout
12537
12538 \begin_layout Verse
12539
12540 \family typewriter
12541 __bit __at (0x83) MOSI;\InsetSpace ~
12542 \InsetSpace ~
12543 \InsetSpace ~
12544 \InsetSpace ~
12545 /* I/O port 0, bit 3 */
12546 \newline
12547 __bit __at (0x91) MISO;\InsetSpace ~
12548 \InsetSpace ~
12549 \InsetSpace ~
12550 \InsetSpace ~
12551 /*
12552  I/O port 1, bit 1 */
12553 \newline
12554 __bit
12555 \begin_inset LatexCommand \index{bit}
12556
12557 \end_inset
12558
12559  __at (0x92) MCLK;\InsetSpace ~
12560 \InsetSpace ~
12561 \InsetSpace ~
12562 \InsetSpace ~
12563 /* I/O port 1, bit 2 */
12564 \end_layout
12565
12566 \begin_layout Standard
12567 and you can use the same hardware dependent routine without changes, as
12568  for example in a library.
12569  This is somehow similar to sbit, but only one absolute address has to be
12570  specified in the whole project.
12571 \begin_inset VSpace bigskip
12572 \end_inset
12573
12574
12575 \end_layout
12576
12577 \begin_layout Section
12578 Parameters
12579 \begin_inset LatexCommand \index{Parameters}
12580
12581 \end_inset
12582
12583
12584 \begin_inset LatexCommand \index{function parameter}
12585
12586 \end_inset
12587
12588  & Local Variables
12589 \begin_inset LatexCommand \index{local variables}
12590
12591 \end_inset
12592
12593
12594 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12595
12596 \end_inset
12597
12598
12599 \end_layout
12600
12601 \begin_layout Standard
12602 Automatic (local) variables and parameters to functions can either be placed
12603  on the stack or in data-space.
12604  The default action of the compiler is to place these variables in the internal
12605  RAM (for small model) or external RAM (for large model).
12606  This in fact makes them similar to 
12607 \emph on
12608 static
12609 \begin_inset LatexCommand \index{static}
12610
12611 \end_inset
12612
12613
12614 \emph default
12615  so by default functions are non-reentrant
12616 \begin_inset LatexCommand \index{reentrant}
12617
12618 \end_inset
12619
12620 .
12621  
12622 \newline
12623
12624 \newline
12625 They can be placed on the stack
12626 \begin_inset LatexCommand \index{stack}
12627
12628 \end_inset
12629
12630  by using the
12631 \emph on
12632  -
12633 \begin_inset ERT
12634 status collapsed
12635
12636 \begin_layout Standard
12637
12638
12639 \backslash
12640 /
12641 \end_layout
12642
12643 \end_inset
12644
12645 -stack-auto
12646 \begin_inset LatexCommand \index{-\/-stack-auto}
12647
12648 \end_inset
12649
12650
12651 \emph default
12652  option, by using 
12653 \emph on
12654 #pragma\InsetSpace ~
12655 stackauto
12656 \emph default
12657
12658 \begin_inset LatexCommand \index{\#pragma stackauto}
12659
12660 \end_inset
12661
12662  or by using the 
12663 \emph on
12664 reentrant
12665 \begin_inset LatexCommand \index{reentrant}
12666
12667 \end_inset
12668
12669
12670 \emph default
12671  keyword in the function declaration, e.g.:
12672 \end_layout
12673
12674 \begin_layout Verse
12675
12676 \family typewriter
12677 unsigned char foo(char i) __reentrant 
12678 \newline
12679
12680 \newline
12681 \InsetSpace ~
12682 \InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 ...
12686  
12687 \newline
12688 }
12689 \end_layout
12690
12691 \begin_layout Standard
12692 Since stack space on 8051 is limited, the 
12693 \emph on
12694 reentrant 
12695 \emph default
12696 keyword or the
12697 \emph on
12698  -
12699 \begin_inset ERT
12700 status collapsed
12701
12702 \begin_layout Standard
12703
12704
12705 \backslash
12706 /
12707 \end_layout
12708
12709 \end_inset
12710
12711 -stack-auto
12712 \emph default
12713  option should be used sparingly.
12714  Note that the reentrant keyword just means that the parameters & local
12715  variables will be allocated to the stack, it 
12716 \emph on
12717 does not
12718 \emph default
12719  mean that the function is register bank
12720 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12721
12722 \end_inset
12723
12724  independent.
12725 \newline
12726
12727 \newline
12728 Local variables
12729 \begin_inset LatexCommand \index{local variables}
12730
12731 \end_inset
12732
12733  can be assigned storage classes and absolute
12734 \begin_inset LatexCommand \index{Absolute addressing}
12735
12736 \end_inset
12737
12738  addresses, e.g.: 
12739 \end_layout
12740
12741 \begin_layout Verse
12742
12743 \family typewriter
12744 unsigned char foo() 
12745 \newline
12746 {
12747 \newline
12748 \InsetSpace ~
12749 \InsetSpace ~
12750 \InsetSpace ~
12751 \InsetSpace ~
12752 __xdata unsigned char i;
12753 \newline
12754 \InsetSpace ~
12755 \InsetSpace ~
12756 \InsetSpace ~
12757 \InsetSpace ~
12758 __bit bvar;
12759 \newline
12760 \InsetSpace ~
12761 \InsetSpace ~
12762 \InsetSpace ~
12763 \InsetSpace ~
12764 __data __at
12765 \begin_inset LatexCommand \index{at}
12766
12767 \end_inset
12768
12769  (0x31) unsigned char j;
12770 \newline
12771 \InsetSpace ~
12772 \InsetSpace ~
12773 \InsetSpace ~
12774 \InsetSpace ~
12775 ...
12776  
12777 \newline
12778 }
12779 \end_layout
12780
12781 \begin_layout Standard
12782 In the above example the variable 
12783 \emph on
12784 i
12785 \emph default
12786  will be allocated in the external ram, 
12787 \emph on
12788 bvar
12789 \emph default
12790  in bit addressable space and
12791 \emph on
12792  j
12793 \emph default
12794  in internal ram.
12795  When compiled with 
12796 \emph on
12797 -
12798 \begin_inset ERT
12799 status collapsed
12800
12801 \begin_layout Standard
12802
12803
12804 \backslash
12805 /
12806 \end_layout
12807
12808 \end_inset
12809
12810 -stack-auto
12811 \emph default
12812  or when a function is declared as 
12813 \emph on
12814 reentrant
12815 \emph default
12816  this should only be done for static variables.
12817 \end_layout
12818
12819 \begin_layout Standard
12820 Parameters
12821 \begin_inset LatexCommand \index{function parameter}
12822
12823 \end_inset
12824
12825  however are not allowed any storage class
12826 \begin_inset LatexCommand \index{Storage class}
12827
12828 \end_inset
12829
12830 , (storage classes for parameters will be ignored), their allocation is
12831  governed by the memory model in use, and the reentrancy options.
12832 \end_layout
12833
12834 \begin_layout Standard
12835 It is however allowed to use bit parameters in reentrant functions and also
12836  non-static local bit variables are supported.
12837  Efficient use is limited to 8 semi-bitregisters in bit space.
12838  They are pushed and popped to stack
12839 \begin_inset LatexCommand \index{stack}
12840
12841 \end_inset
12842
12843  as a single byte just like the normal registers.
12844 \end_layout
12845
12846 \begin_layout Section
12847 Overlaying
12848 \begin_inset LatexCommand \label{sub:Overlaying}
12849
12850 \end_inset
12851
12852
12853 \begin_inset LatexCommand \index{Overlaying}
12854
12855 \end_inset
12856
12857
12858 \end_layout
12859
12860 \begin_layout Standard
12861 For non-reentrant
12862 \begin_inset LatexCommand \index{reentrant}
12863
12864 \end_inset
12865
12866  functions SDCC will try to reduce internal ram space usage by overlaying
12867  parameters and local variables of a function (if possible).
12868  Parameters and local variables
12869 \begin_inset LatexCommand \index{local variables}
12870
12871 \end_inset
12872
12873  of a function will be allocated to an overlayable segment if the function
12874  has 
12875 \emph on
12876 no other function calls and the function is non-reentrant and the memory
12877  model
12878 \begin_inset LatexCommand \index{Memory model}
12879
12880 \end_inset
12881
12882  is small.
12883
12884 \emph default
12885  If an explicit storage class
12886 \begin_inset LatexCommand \index{Storage class}
12887
12888 \end_inset
12889
12890  is specified for a local variable, it will NOT be overlayed.
12891 \end_layout
12892
12893 \begin_layout Standard
12894 Note that the compiler (not the linkage editor) makes the decision for overlayin
12895 g the data items.
12896  Functions that are called from an interrupt service routine
12897 \begin_inset Marginal
12898 status collapsed
12899
12900 \begin_layout Standard
12901
12902 \series bold
12903 !
12904 \end_layout
12905
12906 \end_inset
12907
12908  should be preceded by a #pragma\InsetSpace ~
12909 nooverlay
12910 \begin_inset LatexCommand \index{\#pragma nooverlay}
12911
12912 \end_inset
12913
12914  if they are not reentrant.
12915 \end_layout
12916
12917 \begin_layout Standard
12918 Also note that the compiler does not do any processing of inline assembler
12919  code, so the compiler might incorrectly assign local variables and parameters
12920  of a function into the overlay segment if the inline assembler code calls
12921  other c-functions that might use the overlay.
12922  In that case the #pragma\InsetSpace ~
12923 nooverlay should be used.
12924 \end_layout
12925
12926 \begin_layout Standard
12927 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12928 tion
12929 \begin_inset LatexCommand \index{Multiplication}
12930
12931 \end_inset
12932
12933  or division
12934 \begin_inset LatexCommand \index{Division}
12935
12936 \end_inset
12937
12938  will NOT be overlayed since these are implemented using external functions,
12939  e.g.:
12940 \end_layout
12941
12942 \begin_layout Verse
12943
12944 \family typewriter
12945 #pragma save 
12946 \newline
12947 #pragma nooverlay
12948 \begin_inset LatexCommand \index{\#pragma nooverlay}
12949
12950 \end_inset
12951
12952  
12953 \newline
12954 void set_error(unsigned char errcd) 
12955 \newline
12956 {
12957 \newline
12958 \InsetSpace ~
12959 \InsetSpace ~
12960 \InsetSpace ~
12961 \InsetSpace ~
12962 P3 = errcd;
12963 \newline
12964
12965 \newline
12966 #pragma restore 
12967 \newline
12968
12969 \newline
12970 void
12971  some_isr () __interrupt
12972 \begin_inset LatexCommand \index{interrupt}
12973
12974 \end_inset
12975
12976  (2)
12977 \newline
12978 {
12979 \newline
12980 \InsetSpace ~
12981 \InsetSpace ~
12982 \InsetSpace ~
12983 \InsetSpace ~
12984 ...
12985 \newline
12986 \InsetSpace ~
12987 \InsetSpace ~
12988 \InsetSpace ~
12989 \InsetSpace ~
12990 set_error(10);
12991 \newline
12992 \InsetSpace ~
12993 \InsetSpace ~
12994 \InsetSpace ~
12995 \InsetSpace ~
12996 ...
12997  
12998 \newline
12999 }
13000 \end_layout
13001
13002 \begin_layout Standard
13003 In the above example the parameter 
13004 \emph on
13005 errcd
13006 \emph default
13007  for the function 
13008 \emph on
13009 set_error
13010 \emph default
13011  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13012 nooverlay was
13013  not present, this could cause unpredictable runtime behavior when called
13014  from an interrupt service routine.
13015  The #pragma\InsetSpace ~
13016 nooverlay ensures that the parameters and local variables for
13017  the function are NOT overlayed.
13018 \begin_inset VSpace bigskip
13019 \end_inset
13020
13021
13022 \end_layout
13023
13024 \begin_layout Section
13025 Interrupt Service Routines
13026 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13027
13028 \end_inset
13029
13030
13031 \end_layout
13032
13033 \begin_layout Subsection
13034 General Information
13035 \end_layout
13036
13037 \begin_layout Standard
13038 SDCC allows 
13039 \emph on
13040 i
13041 \emph default
13042 nterrupt 
13043 \emph on
13044 s
13045 \emph default
13046 ervice 
13047 \emph on
13048 r
13049 \emph default
13050 outines to be coded in C, with some extended keywords.
13051 \end_layout
13052
13053 \begin_layout Verse
13054
13055 \family typewriter
13056 void timer_isr (void) __interrupt (1) __using (1) 
13057 \newline
13058
13059 \newline
13060 \InsetSpace ~
13061 \InsetSpace ~
13062 \InsetSpace ~
13063 \InsetSpace ~
13064 ...
13065  
13066 \newline
13067 }
13068 \end_layout
13069
13070 \begin_layout Standard
13071 The optional number following the 
13072 \emph on
13073 interrupt
13074 \begin_inset LatexCommand \index{interrupt}
13075
13076 \end_inset
13077
13078
13079 \begin_inset LatexCommand \index{\_\_interrupt}
13080
13081 \end_inset
13082
13083
13084 \emph default
13085  keyword is the interrupt number this routine will service.
13086  When present, the compiler will insert a call to this routine in the interrupt
13087  vector table
13088 \begin_inset LatexCommand \index{interrupt vector table}
13089
13090 \end_inset
13091
13092  for the interrupt number specified.
13093  If you have multiple source files in your project, interrupt service routines
13094  can be present in any of them, but a prototype of the isr MUST be present
13095  or included in the file that contains the function 
13096 \emph on
13097 main
13098 \emph default
13099 .
13100  The optional (8051 specific) keyword 
13101 \emph on
13102 using
13103 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13104
13105 \end_inset
13106
13107
13108 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13109
13110 \end_inset
13111
13112
13113 \emph default
13114  can be used to tell the compiler to use the specified register bank when
13115  generating code for this function.
13116  
13117 \newline
13118 Interrupt service routines open the door for some very interesting bugs:
13119 \end_layout
13120
13121 \begin_layout Subsubsection
13122 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13123
13124 \end_inset
13125
13126 Common interrupt pitfall: variable not declared 
13127 \emph on
13128 volatile
13129 \end_layout
13130
13131 \begin_layout Standard
13132 If an interrupt service routine changes variables which are accessed by
13133  other functions these variables have to be declared 
13134 \emph on
13135 volatile
13136 \emph default
13137
13138 \begin_inset LatexCommand \index{volatile}
13139
13140 \end_inset
13141
13142 .
13143  See 
13144 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13145
13146 \end_inset
13147
13148  .
13149 \end_layout
13150
13151 \begin_layout Subsubsection
13152 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13153
13154 \end_inset
13155
13156 Common interrupt pitfall: 
13157 \emph on
13158 non-atomic access
13159 \end_layout
13160
13161 \begin_layout Standard
13162 If the access to these variables is not 
13163 \emph on
13164 atomic
13165 \begin_inset LatexCommand \index{atomic}
13166
13167 \end_inset
13168
13169
13170 \emph default
13171  (i.e.
13172  the processor needs more than one instruction for the access and could
13173  be interrupted while accessing the variable) the interrupt must be disabled
13174  during the access to avoid inconsistent data.
13175  
13176 \newline
13177 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13178  and should be protected by disabling interrupts.
13179  You're not automatically on the safe side if you use 8 bit variables though.
13180  We need an example here: f.e.
13181  on the 8051 the harmless looking 
13182 \begin_inset Quotes srd
13183 \end_inset
13184
13185
13186 \family typewriter
13187 flags\InsetSpace ~
13188 |=\InsetSpace ~
13189 0x80;
13190 \family default
13191
13192 \begin_inset Quotes sld
13193 \end_inset
13194
13195  is not atomic if 
13196 \family typewriter
13197 flags
13198 \family default
13199  resides in xdata.
13200  Setting 
13201 \begin_inset Quotes srd
13202 \end_inset
13203
13204
13205 \family typewriter
13206 flags\InsetSpace ~
13207 |=\InsetSpace ~
13208 0x40;
13209 \family default
13210
13211 \begin_inset Quotes sld
13212 \end_inset
13213
13214  from within an interrupt routine might get lost if the interrupt occurs
13215  at the wrong time.
13216  
13217 \begin_inset Quotes sld
13218 \end_inset
13219
13220
13221 \family typewriter
13222 counter\InsetSpace ~
13223 +=\InsetSpace ~
13224 8;
13225 \family default
13226
13227 \begin_inset Quotes srd
13228 \end_inset
13229
13230  is not atomic on the 8051 even if 
13231 \family typewriter
13232 counter
13233 \family default
13234  is located in data memory.
13235 \newline
13236 Bugs like these are hard to reproduce and can
13237  cause a lot of trouble.
13238  
13239 \end_layout
13240
13241 \begin_layout Subsubsection
13242 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13243
13244 \end_inset
13245
13246 Common interrupt pitfall: 
13247 \emph on
13248 stack overflow
13249 \end_layout
13250
13251 \begin_layout Standard
13252 The return address and the registers used in the interrupt service routine
13253  are saved on the stack
13254 \begin_inset LatexCommand \index{stack}
13255
13256 \end_inset
13257
13258  so there must be sufficient stack space.
13259  If there isn't variables or registers (or even the return address itself)
13260  will be corrupted.
13261  This 
13262 \emph on
13263 stack overflow
13264 \emph default
13265
13266 \begin_inset LatexCommand \index{stack overflow}
13267
13268 \end_inset
13269
13270  is most likely to happen if the interrupt occurs during the 
13271 \begin_inset Quotes sld
13272 \end_inset
13273
13274 deepest
13275 \begin_inset Quotes srd
13276 \end_inset
13277
13278  subroutine when the stack is already in use for f.e.
13279  many return addresses.
13280 \end_layout
13281
13282 \begin_layout Subsubsection
13283 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13284
13285 \end_inset
13286
13287 Common interrupt pitfall: 
13288 \emph on
13289 use of non-reentrant functions
13290 \end_layout
13291
13292 \begin_layout Standard
13293 A special note here, int (16 bit) and long (32 bit) integer division
13294 \begin_inset LatexCommand \index{Division}
13295
13296 \end_inset
13297
13298 , multiplication
13299 \begin_inset LatexCommand \index{Multiplication}
13300
13301 \end_inset
13302
13303  & modulus
13304 \begin_inset LatexCommand \index{Modulus}
13305
13306 \end_inset
13307
13308  and floating-point
13309 \begin_inset LatexCommand \index{Floating point support}
13310
13311 \end_inset
13312
13313  operations are implemented using external support routines.
13314  If an interrupt service routine needs to do any of these operations then
13315  the support routines (as mentioned in a following section) will have to
13316  be recompiled using the
13317 \emph on
13318  -
13319 \begin_inset ERT
13320 status collapsed
13321
13322 \begin_layout Standard
13323
13324
13325 \backslash
13326 /
13327 \end_layout
13328
13329 \end_inset
13330
13331 -stack-auto
13332 \begin_inset LatexCommand \index{-\/-stack-auto}
13333
13334 \end_inset
13335
13336
13337 \emph default
13338  option and the source file will need to be compiled using the 
13339 \emph on
13340 -
13341 \begin_inset ERT
13342 status collapsed
13343
13344 \begin_layout Standard
13345
13346
13347 \backslash
13348 /
13349 \end_layout
13350
13351 \end_inset
13352
13353 -int-long-reent
13354 \emph default
13355
13356 \begin_inset LatexCommand \index{-\/-int-long-reent}
13357
13358 \end_inset
13359
13360  compiler option.
13361  
13362 \newline
13363 Note, the type promotion
13364 \begin_inset LatexCommand \index{type promotion}
13365
13366 \end_inset
13367
13368  required by ANSI C can cause 16 bit routines to be used
13369 \begin_inset Marginal
13370 status collapsed
13371
13372 \begin_layout Standard
13373
13374 \series bold
13375 \InsetSpace ~
13376 !
13377 \end_layout
13378
13379 \end_inset
13380
13381  without the programmer being aware of it.
13382  See f.e.
13383  the cast 
13384 \family typewriter
13385 (unsigned char)(tail-1)
13386 \family default
13387  within the if clause in section 
13388 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13389
13390 \end_inset
13391
13392 .
13393 \end_layout
13394
13395 \begin_layout Standard
13396 Calling other functions from an interrupt service routine is not recommended,
13397  avoid it if possible.
13398  Note that when some function is called from an interrupt service routine
13399  it should be preceded by a #pragma\InsetSpace ~
13400 nooverlay
13401 \begin_inset LatexCommand \index{\#pragma nooverlay}
13402
13403 \end_inset
13404
13405  if it is not reentrant.
13406  Furthermore nonreentrant functions should not be called from the main program
13407  while the interrupt service routine might be active.
13408  They also must not be called from low priority interrupt service routines
13409  while a high priority interrupt service routine might be active.
13410  You could use semaphores or make the function
13411 \emph on
13412  critical
13413 \emph default
13414  if all parameters are passed in registers.
13415 \newline
13416  Also see section 
13417 \begin_inset LatexCommand \ref{sub:Overlaying}
13418
13419 \end_inset
13420
13421 \InsetSpace ~
13422 about Overlaying and section 
13423 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13424
13425 \end_inset
13426
13427 \InsetSpace ~
13428 about Functions using private register banks.
13429 \begin_inset VSpace bigskip
13430 \end_inset
13431
13432
13433 \end_layout
13434
13435 \begin_layout Subsection
13436 MCS51/DS390 Interrupt Service Routines
13437 \end_layout
13438
13439 \begin_layout Standard
13440 Interrupt
13441 \begin_inset LatexCommand \index{interrupt}
13442
13443 \end_inset
13444
13445  numbers and the corresponding address & descriptions for the Standard 8051/8052
13446  are listed below.
13447  SDCC will automatically adjust the 
13448 \begin_inset LatexCommand \index{interrupt vector table}
13449
13450 \end_inset
13451
13452  to the maximum interrupt number specified.
13453 \newline
13454
13455 \end_layout
13456
13457 \begin_layout Standard
13458 \align center
13459 \begin_inset Tabular
13460 <lyxtabular version="3" rows="9" columns="3">
13461 <features>
13462 <column alignment="center" valignment="top" leftline="true" width="0in">
13463 <column alignment="left" valignment="top" leftline="true" width="0in">
13464 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13465 <row topline="true" bottomline="true">
13466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13467 \begin_inset Text
13468
13469 \begin_layout Standard
13470 Interrupt #
13471 \end_layout
13472
13473 \end_inset
13474 </cell>
13475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13476 \begin_inset Text
13477
13478 \begin_layout Standard
13479 Description
13480 \end_layout
13481
13482 \end_inset
13483 </cell>
13484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13485 \begin_inset Text
13486
13487 \begin_layout Standard
13488 Vector Address
13489 \end_layout
13490
13491 \end_inset
13492 </cell>
13493 </row>
13494 <row topline="true">
13495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13496 \begin_inset Text
13497
13498 \begin_layout Standard
13499 0
13500 \end_layout
13501
13502 \end_inset
13503 </cell>
13504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13505 \begin_inset Text
13506
13507 \begin_layout Standard
13508 External 0
13509 \end_layout
13510
13511 \end_inset
13512 </cell>
13513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13514 \begin_inset Text
13515
13516 \begin_layout Standard
13517 0x0003
13518 \end_layout
13519
13520 \end_inset
13521 </cell>
13522 </row>
13523 <row topline="true">
13524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13525 \begin_inset Text
13526
13527 \begin_layout Standard
13528 1
13529 \end_layout
13530
13531 \end_inset
13532 </cell>
13533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13534 \begin_inset Text
13535
13536 \begin_layout Standard
13537 Timer 0
13538 \end_layout
13539
13540 \end_inset
13541 </cell>
13542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13543 \begin_inset Text
13544
13545 \begin_layout Standard
13546 0x000b
13547 \end_layout
13548
13549 \end_inset
13550 </cell>
13551 </row>
13552 <row topline="true">
13553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13554 \begin_inset Text
13555
13556 \begin_layout Standard
13557 2
13558 \end_layout
13559
13560 \end_inset
13561 </cell>
13562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13563 \begin_inset Text
13564
13565 \begin_layout Standard
13566 External 1
13567 \end_layout
13568
13569 \end_inset
13570 </cell>
13571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13572 \begin_inset Text
13573
13574 \begin_layout Standard
13575 0x0013
13576 \end_layout
13577
13578 \end_inset
13579 </cell>
13580 </row>
13581 <row topline="true">
13582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13583 \begin_inset Text
13584
13585 \begin_layout Standard
13586 3
13587 \end_layout
13588
13589 \end_inset
13590 </cell>
13591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13592 \begin_inset Text
13593
13594 \begin_layout Standard
13595 Timer 1
13596 \end_layout
13597
13598 \end_inset
13599 </cell>
13600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13601 \begin_inset Text
13602
13603 \begin_layout Standard
13604 0x001b
13605 \end_layout
13606
13607 \end_inset
13608 </cell>
13609 </row>
13610 <row topline="true">
13611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13612 \begin_inset Text
13613
13614 \begin_layout Standard
13615 4
13616 \end_layout
13617
13618 \end_inset
13619 </cell>
13620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13621 \begin_inset Text
13622
13623 \begin_layout Standard
13624 Serial
13625 \end_layout
13626
13627 \end_inset
13628 </cell>
13629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13630 \begin_inset Text
13631
13632 \begin_layout Standard
13633 0x0023
13634 \end_layout
13635
13636 \end_inset
13637 </cell>
13638 </row>
13639 <row topline="true">
13640 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13641 \begin_inset Text
13642
13643 \begin_layout Standard
13644 5
13645 \end_layout
13646
13647 \end_inset
13648 </cell>
13649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13650 \begin_inset Text
13651
13652 \begin_layout Standard
13653 Timer 2 (8052)
13654 \end_layout
13655
13656 \end_inset
13657 </cell>
13658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13659 \begin_inset Text
13660
13661 \begin_layout Standard
13662 0x002b
13663 \end_layout
13664
13665 \end_inset
13666 </cell>
13667 </row>
13668 <row topline="true">
13669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13670 \begin_inset Text
13671
13672 \begin_layout Standard
13673 ...
13674 \end_layout
13675
13676 \end_inset
13677 </cell>
13678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13679 \begin_inset Text
13680
13681 \begin_layout Standard
13682
13683 \end_layout
13684
13685 \end_inset
13686 </cell>
13687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13688 \begin_inset Text
13689
13690 \begin_layout Standard
13691 ...
13692 \end_layout
13693
13694 \end_inset
13695 </cell>
13696 </row>
13697 <row topline="true" bottomline="true">
13698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13699 \begin_inset Text
13700
13701 \begin_layout Standard
13702 n
13703 \end_layout
13704
13705 \end_inset
13706 </cell>
13707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13708 \begin_inset Text
13709
13710 \begin_layout Standard
13711
13712 \end_layout
13713
13714 \end_inset
13715 </cell>
13716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13717 \begin_inset Text
13718
13719 \begin_layout Standard
13720 0x0003 + 8*n
13721 \end_layout
13722
13723 \end_inset
13724 </cell>
13725 </row>
13726 </lyxtabular>
13727
13728 \end_inset
13729
13730
13731 \newline
13732
13733 \end_layout
13734
13735 \begin_layout Standard
13736 If the interrupt service routine is defined without 
13737 \emph on
13738 using
13739 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13740
13741 \end_inset
13742
13743
13744 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13745
13746 \end_inset
13747
13748
13749 \emph default
13750  a register bank or with register bank 0 (
13751 \emph on
13752 using
13753 \emph default
13754  0), the compiler will save the registers used by itself on the stack upon
13755  entry and restore them at exit, however if such an interrupt service routine
13756  calls another function then the entire register bank will be saved on the
13757  stack.
13758  This scheme may be advantageous for small interrupt service routines which
13759  have low register usage.
13760 \end_layout
13761
13762 \begin_layout Standard
13763 If the interrupt service routine is defined to be using a specific register
13764  bank then only 
13765 \emph on
13766 a, b, dptr
13767 \emph default
13768  & psw are saved and restored, if such an interrupt service routine calls
13769  another function (using another register bank) then the entire register
13770  bank of the called function will be saved on the stack
13771 \begin_inset LatexCommand \index{stack}
13772
13773 \end_inset
13774
13775 .
13776  This scheme is recommended for larger interrupt service routines.
13777 \begin_inset VSpace bigskip
13778 \end_inset
13779
13780
13781 \end_layout
13782
13783 \begin_layout Subsection
13784 HC08
13785 \begin_inset LatexCommand \index{HC08}
13786
13787 \end_inset
13788
13789  Interrupt Service Routines
13790 \end_layout
13791
13792 \begin_layout Standard
13793 Since the number of interrupts
13794 \begin_inset LatexCommand \index{HC08!interrupt}
13795
13796 \end_inset
13797
13798  available is chip specific and the interrupt vector table always ends at
13799  the last byte of memory, the interrupt numbers corresponds to the interrupt
13800  vectors in reverse order of address.
13801  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
13802  2 will use the interrupt vector at 0xfffa, and so on.
13803  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
13804  this way; instead see section 
13805 \begin_inset LatexCommand \ref{sub:Startup-Code}
13806
13807 \end_inset
13808
13809  for details on customizing startup.
13810 \begin_inset VSpace bigskip
13811 \end_inset
13812
13813
13814 \end_layout
13815
13816 \begin_layout Subsection
13817 Z80 Interrupt Service Routines
13818 \end_layout
13819
13820 \begin_layout Standard
13821 The Z80
13822 \begin_inset LatexCommand \index{Z80}
13823
13824 \end_inset
13825
13826  uses several different methods for determining the correct interrupt
13827 \begin_inset LatexCommand \index{Z80!interrupt}
13828
13829 \end_inset
13830
13831  vector depending on the hardware implementation.
13832  Therefore, SDCC ignores the optional interrupt number and does not attempt
13833  to generate an interrupt vector table.
13834 \end_layout
13835
13836 \begin_layout Standard
13837 By default, SDCC generates code for a maskable interrupt, which uses a RETI
13838  instruction to return from the interrupt.
13839  To write an interrupt handler for the non-maskable interrupt, which needs
13840  a RETN instruction instead, add the 
13841 \emph on
13842 critical
13843 \emph default
13844  keyword:
13845 \end_layout
13846
13847 \begin_layout Verse
13848
13849 \family typewriter
13850 void nmi_isr (void) critical interrupt
13851 \newline
13852
13853 \newline
13854 \InsetSpace ~
13855 \InsetSpace ~
13856 \InsetSpace ~
13857 \InsetSpace ~
13858 ...
13859  
13860 \newline
13861 }
13862 \end_layout
13863
13864 \begin_layout Standard
13865 However if you need to create a non-interruptable interrupt service routine
13866  you would also require the 
13867 \emph on
13868 critical
13869 \emph default
13870  keyword.
13871  To distinguish between this and an nmi_isr you must provide an interrupt
13872  number.
13873 \begin_inset VSpace bigskip
13874 \end_inset
13875
13876
13877 \end_layout
13878
13879 \begin_layout Section
13880 Enabling and Disabling Interrupts
13881 \end_layout
13882
13883 \begin_layout Subsection
13884 Critical Functions and Critical Statements
13885 \end_layout
13886
13887 \begin_layout Standard
13888 A special keyword may be associated with a block or a function declaring
13889  it as 
13890 \emph on
13891 critical
13892 \emph default
13893 .
13894  SDCC will generate code to disable all interrupts
13895 \begin_inset LatexCommand \index{interrupt}
13896
13897 \end_inset
13898
13899  upon entry to a critical function and restore the interrupt enable to the
13900  previous state before returning.
13901  Nesting critical functions will need one additional byte on the stack
13902 \begin_inset LatexCommand \index{stack}
13903
13904 \end_inset
13905
13906  for each call.
13907 \end_layout
13908
13909 \begin_layout Verse
13910
13911 \family typewriter
13912 int foo () __critical
13913 \begin_inset LatexCommand \index{critical}
13914
13915 \end_inset
13916
13917
13918 \begin_inset LatexCommand \index{\_\_critical}
13919
13920 \end_inset
13921
13922  
13923 \newline
13924
13925 \newline
13926 \InsetSpace ~
13927 \InsetSpace ~
13928 \InsetSpace ~
13929 \InsetSpace ~
13930 ...
13931  
13932 \newline
13933 \InsetSpace ~
13934 \InsetSpace ~
13935 \InsetSpace ~
13936 \InsetSpace ~
13937 ...
13938  
13939 \newline
13940 }
13941 \end_layout
13942
13943 \begin_layout Standard
13944 The critical attribute maybe used with other attributes like 
13945 \emph on
13946 reentrant.
13947 \emph default
13948
13949 \newline
13950 The keyword 
13951 \emph on
13952 critical
13953 \emph default
13954  may also be used to disable interrupts more locally:
13955 \end_layout
13956
13957 \begin_layout Verse
13958
13959 \family typewriter
13960 __critical{ i++; }
13961 \end_layout
13962
13963 \begin_layout Standard
13964 More than one statement could have been included in the block.
13965 \end_layout
13966
13967 \begin_layout Subsection
13968 Enabling and Disabling Interrupts directly
13969 \end_layout
13970
13971 \begin_layout Standard
13972 Interrupts
13973 \begin_inset LatexCommand \index{interrupt}
13974
13975 \end_inset
13976
13977  can also be disabled and enabled directly (8051):
13978 \end_layout
13979
13980 \begin_layout Verse
13981
13982 \family typewriter
13983 EA = 0;\InsetSpace ~
13984 \InsetSpace ~
13985 \InsetSpace ~
13986 \InsetSpace ~
13987 \InsetSpace ~
13988 \InsetSpace ~
13989 \InsetSpace ~
13990 \InsetSpace ~
13991 \InsetSpace ~
13992 \InsetSpace ~
13993 \InsetSpace ~
13994 \InsetSpace ~
13995 or:\InsetSpace ~
13996 \InsetSpace ~
13997 \InsetSpace ~
13998 \InsetSpace ~
13999 \InsetSpace ~
14000 \InsetSpace ~
14001 \InsetSpace ~
14002 \InsetSpace ~
14003 \InsetSpace ~
14004 \InsetSpace ~
14005 \InsetSpace ~
14006 EA_SAVE = EA;
14007 \end_layout
14008
14009 \begin_layout Verse
14010
14011 \family typewriter
14012 ...\InsetSpace ~
14013 \InsetSpace ~
14014 \InsetSpace ~
14015 \InsetSpace ~
14016 \InsetSpace ~
14017 \InsetSpace ~
14018 \InsetSpace ~
14019 \InsetSpace ~
14020 \InsetSpace ~
14021 \InsetSpace ~
14022 \InsetSpace ~
14023 \InsetSpace ~
14024 \InsetSpace ~
14025 \InsetSpace ~
14026 \InsetSpace ~
14027 \InsetSpace ~
14028 \InsetSpace ~
14029 \InsetSpace ~
14030 \InsetSpace ~
14031 \InsetSpace ~
14032 \InsetSpace ~
14033 \InsetSpace ~
14034 \InsetSpace ~
14035 \InsetSpace ~
14036 \InsetSpace ~
14037 \InsetSpace ~
14038 \InsetSpace ~
14039 \InsetSpace ~
14040 \InsetSpace ~
14041 \InsetSpace ~
14042 EA = 0;
14043 \end_layout
14044
14045 \begin_layout Verse
14046
14047 \family typewriter
14048 EA = 1;\InsetSpace ~
14049 \InsetSpace ~
14050 \InsetSpace ~
14051 \InsetSpace ~
14052 \InsetSpace ~
14053 \InsetSpace ~
14054 \InsetSpace ~
14055 \InsetSpace ~
14056 \InsetSpace ~
14057 \InsetSpace ~
14058 \InsetSpace ~
14059 \InsetSpace ~
14060 \InsetSpace ~
14061 \InsetSpace ~
14062 \InsetSpace ~
14063 \InsetSpace ~
14064 \InsetSpace ~
14065 \InsetSpace ~
14066 \InsetSpace ~
14067 \InsetSpace ~
14068 \InsetSpace ~
14069 \InsetSpace ~
14070 \InsetSpace ~
14071 \InsetSpace ~
14072 \InsetSpace ~
14073 \InsetSpace ~
14074 ...
14075 \end_layout
14076
14077 \begin_layout Verse
14078
14079 \family typewriter
14080 \InsetSpace ~
14081 \InsetSpace ~
14082 \InsetSpace ~
14083 \InsetSpace ~
14084 \InsetSpace ~
14085 \InsetSpace ~
14086 \InsetSpace ~
14087 \InsetSpace ~
14088 \InsetSpace ~
14089 \InsetSpace ~
14090 \InsetSpace ~
14091 \InsetSpace ~
14092 \InsetSpace ~
14093 \InsetSpace ~
14094 \InsetSpace ~
14095 \InsetSpace ~
14096 \InsetSpace ~
14097 \InsetSpace ~
14098 \InsetSpace ~
14099 \InsetSpace ~
14100 \InsetSpace ~
14101 \InsetSpace ~
14102 \InsetSpace ~
14103 \InsetSpace ~
14104 \InsetSpace ~
14105 \InsetSpace ~
14106 \InsetSpace ~
14107 \InsetSpace ~
14108 \InsetSpace ~
14109 \InsetSpace ~
14110 \InsetSpace ~
14111 \InsetSpace ~
14112 \InsetSpace ~
14113 EA = EA_SAVE;
14114 \end_layout
14115
14116 \begin_layout Standard
14117 On other architectures which have seperate opcodes for enabling and disabling
14118  interrupts you might want to make use of defines with inline assembly
14119 \begin_inset LatexCommand \index{Assembler routines}
14120
14121 \end_inset
14122
14123  (HC08
14124 \begin_inset LatexCommand \index{HC08!interrupt}
14125
14126 \end_inset
14127
14128 ):
14129 \end_layout
14130
14131 \begin_layout Verse
14132
14133 \family typewriter
14134 #define CLI _asm
14135 \begin_inset LatexCommand \index{\_asm}
14136
14137 \end_inset
14138
14139 \InsetSpace ~
14140 \InsetSpace ~
14141 cli\InsetSpace ~
14142 \InsetSpace ~
14143 _endasm
14144 \begin_inset LatexCommand \index{\_endasm}
14145
14146 \end_inset
14147
14148
14149 \end_layout
14150
14151 \begin_layout Verse
14152
14153 \family typewriter
14154 #define SEI _asm\InsetSpace ~
14155 \InsetSpace ~
14156 sei\InsetSpace ~
14157 \InsetSpace ~
14158 _endasm; 
14159 \end_layout
14160
14161 \begin_layout Verse
14162
14163 \family typewriter
14164 ...
14165 \end_layout
14166
14167 \begin_layout Standard
14168 Note: it is sometimes sufficient to disable only a specific interrupt source
14169  like f.e.
14170  a timer or serial interrupt by manipulating an 
14171 \emph on
14172 interrupt mask
14173 \begin_inset LatexCommand \index{interrupt mask}
14174
14175 \end_inset
14176
14177
14178 \emph default
14179  register.
14180  
14181 \end_layout
14182
14183 \begin_layout Standard
14184 Usually the time during which interrupts are disabled should be kept as
14185  short as possible.
14186  This minimizes both 
14187 \emph on
14188 interrupt latency
14189 \emph default
14190
14191 \begin_inset LatexCommand \index{interrupt latency}
14192
14193 \end_inset
14194
14195  (the time between the occurrence of the interrupt and the execution of
14196  the first code in the interrupt routine) and 
14197 \emph on
14198 interrupt jitter
14199 \emph default
14200
14201 \begin_inset LatexCommand \index{interrupt jitter}
14202
14203 \end_inset
14204
14205  (the difference between the shortest and the longest interrupt latency).
14206  These really are something different, f.e.
14207  a serial interrupt has to be served before its buffer overruns so it cares
14208  for the maximum interrupt latency, whereas it does not care about jitter.
14209  On a loudspeaker driven via a digital to analog converter which is fed
14210  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14211  a much smaller jitter will be very audible.
14212 \end_layout
14213
14214 \begin_layout Standard
14215 You can reenable interrupts within an interrupt routine and on some architecture
14216 s you can make use of two (or more) levels of 
14217 \emph on
14218 interrupt priorities
14219 \emph default
14220
14221 \begin_inset LatexCommand \index{interrupt priority}
14222
14223 \end_inset
14224
14225 .
14226  On some architectures which don't support interrupt priorities these can
14227  be implemented by manipulating the interrupt mask and reenabling interrupts
14228  within the interrupt routine.
14229  Check there is sufficient space on the stack
14230 \begin_inset LatexCommand \index{stack}
14231
14232 \end_inset
14233
14234  and don't add complexity unless you have to.
14235  
14236 \end_layout
14237
14238 \begin_layout Subsection
14239 Semaphore
14240 \begin_inset LatexCommand \index{semaphore}
14241
14242 \end_inset
14243
14244  locking (mcs51/ds390)
14245 \end_layout
14246
14247 \begin_layout Standard
14248 Some architectures (mcs51/ds390) have an atomic
14249 \begin_inset LatexCommand \index{atomic}
14250
14251 \end_inset
14252
14253  bit test and
14254 \emph on
14255  
14256 \emph default
14257 clear
14258 \emph on
14259  
14260 \emph default
14261 instruction.
14262  These type of instructions are typically used in preemptive multitasking
14263  systems, where a routine f.e.
14264  claims the use of a data structure ('acquires a lock
14265 \begin_inset LatexCommand \index{lock}
14266
14267 \end_inset
14268
14269  on it'), makes some modifications and then releases the lock when the data
14270  structure is consistent again.
14271  The instruction may also be used if interrupt and non-interrupt code have
14272  to compete for a resource.
14273  With the atomic bit test and clear instruction interrupts
14274 \begin_inset LatexCommand \index{interrupt}
14275
14276 \end_inset
14277
14278  don't have to be disabled for the locking operation.
14279  
14280 \end_layout
14281
14282 \begin_layout Standard
14283 SDCC generates this instruction if the source follows this pattern:
14284 \end_layout
14285
14286 \begin_layout Verse
14287
14288 \family typewriter
14289 volatile
14290 \begin_inset LatexCommand \index{volatile}
14291
14292 \end_inset
14293
14294  bit resource_is_free; 
14295 \newline
14296
14297 \newline
14298 if (resource_is_free) 
14299 \newline
14300 \InsetSpace ~
14301 \InsetSpace ~
14302
14303 \newline
14304 \InsetSpace ~
14305 \InsetSpace ~
14306 \InsetSpace ~
14307 \InsetSpace ~
14308 resource_is_free=0; 
14309 \newline
14310 \InsetSpace ~
14311 \InsetSpace ~
14312 \InsetSpace ~
14313 \InsetSpace ~
14314 ...
14315  
14316 \newline
14317 \InsetSpace ~
14318 \InsetSpace ~
14319 \InsetSpace ~
14320 \InsetSpace ~
14321 resource_is_free=1;
14322 \newline
14323 \InsetSpace ~
14324 \InsetSpace ~
14325
14326 \end_layout
14327
14328 \begin_layout Standard
14329 Note, mcs51 and ds390 support only an atomic
14330 \begin_inset LatexCommand \index{atomic}
14331
14332 \end_inset
14333
14334  bit test and 
14335 \emph on
14336 clear
14337 \emph default
14338  instruction (as opposed to atomic bit test and 
14339 \emph on
14340 set).
14341 \end_layout
14342
14343 \begin_layout Section
14344 Functions using private register banks
14345 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14346
14347 \end_inset
14348
14349  (mcs51/ds390)
14350 \end_layout
14351
14352 \begin_layout Standard
14353 Some architectures have support for quickly changing register sets.
14354  SDCC supports this feature with the 
14355 \emph on
14356 using
14357 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14358
14359 \end_inset
14360
14361
14362 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14363
14364 \end_inset
14365
14366
14367 \emph default
14368  attribute (which tells the compiler to use a register bank
14369 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14370
14371 \end_inset
14372
14373  other than the default bank zero).
14374  It should only be applied to 
14375 \emph on
14376 interrupt
14377 \begin_inset LatexCommand \index{interrupt}
14378
14379 \end_inset
14380
14381
14382 \emph default
14383  functions (see footnote below).
14384  This will in most circumstances make the generated ISR code more efficient
14385  since it will not have to save registers on the stack.
14386 \end_layout
14387
14388 \begin_layout Standard
14389 The 
14390 \emph on
14391 using
14392 \emph default
14393  attribute will have no effect on the generated code for a 
14394 \emph on
14395 non-interrupt
14396 \emph default
14397  function (but may occasionally be useful anyway
14398 \begin_inset Foot
14399 status open
14400
14401 \begin_layout Standard
14402 possible exception: if a function is called ONLY from 'interrupt' functions
14403  using a particular bank, it can be declared with the same 'using' attribute
14404  as the calling 'interrupt' functions.
14405  For instance, if you have several ISRs using bank one, and all of them
14406  call memcpy(), it might make sense to create a specialized version of memcpy()
14407  'using 1', since this would prevent the ISR from having to save bank zero
14408  to the stack on entry and switch to bank zero before calling the function
14409 \end_layout
14410
14411 \end_inset
14412
14413 ).
14414 \newline
14415
14416 \emph on
14417 (pending: Note, nowadays the 
14418 \emph default
14419 using
14420 \emph on
14421  attribute has an effect on
14422 \emph default
14423  
14424 \emph on
14425 the generated code for a 
14426 \emph default
14427 non-interrupt
14428 \emph on
14429  function
14430 \emph default
14431 .
14432 \emph on
14433 )
14434 \end_layout
14435
14436 \begin_layout Standard
14437 An 
14438 \emph on
14439 interrupt
14440 \emph default
14441  function using a non-zero bank will assume that it can trash that register
14442  bank, and will not save it.
14443  Since high-priority interrupts
14444 \begin_inset LatexCommand \index{interrupts}
14445
14446 \end_inset
14447
14448
14449 \begin_inset LatexCommand \index{interrupt priority}
14450
14451 \end_inset
14452
14453  can interrupt low-priority ones on the 8051 and friends, this means that
14454  if a high-priority ISR 
14455 \emph on
14456 using
14457 \emph default
14458  a particular bank occurs while processing a low-priority ISR 
14459 \emph on
14460 using
14461 \emph default
14462  the same bank, terrible and bad things can happen.
14463  To prevent this, no single register bank should be 
14464 \emph on
14465 used
14466 \emph default
14467  by both a high priority and a low priority ISR.
14468  This is probably most easily done by having all high priority ISRs use
14469  one bank and all low priority ISRs use another.
14470  If you have an ISR which can change priority at runtime, you're on your
14471  own: I suggest using the default bank zero and taking the small performance
14472  hit.
14473 \end_layout
14474
14475 \begin_layout Standard
14476 It is most efficient if your ISR calls no other functions.
14477  If your ISR must call other functions, it is most efficient if those functions
14478  use the same bank as the ISR (see note 1 below); the next best is if the
14479  called functions use bank zero.
14480  It is very inefficient to call a function using a different, non-zero bank
14481  from an ISR.
14482  
14483 \begin_inset VSpace bigskip
14484 \end_inset
14485
14486
14487 \end_layout
14488
14489 \begin_layout Section
14490 Startup Code
14491 \begin_inset LatexCommand \label{sub:Startup-Code}
14492
14493 \end_inset
14494
14495
14496 \begin_inset LatexCommand \index{Startup code}
14497
14498 \end_inset
14499
14500
14501 \end_layout
14502
14503 \begin_layout Subsection
14504 MCS51/DS390 Startup Code
14505 \end_layout
14506
14507 \begin_layout Standard
14508 The compiler inserts a call to the C routine 
14509 \emph on
14510 _sdcc_external_startup()
14511 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
14512
14513 \end_inset
14514
14515
14516 \series bold
14517 \emph default
14518  
14519 \series default
14520 at the start of the CODE area.
14521  This routine is in the runtime library
14522 \begin_inset LatexCommand \index{Runtime library}
14523
14524 \end_inset
14525
14526 .
14527  By default this routine returns 0, if this routine returns a non-zero value,
14528  the static & global variable initialization will be skipped and the function
14529  main will be invoked.
14530  Otherwise static & global variables will be initialized before the function
14531  main is invoked.
14532  You could add a 
14533 \emph on
14534 _sdcc_external_startup()
14535 \emph default
14536  routine to your program to override the default if you need to setup hardware
14537  or perform some other critical operation prior to static & global variable
14538  initialization
14539 \begin_inset LatexCommand \index{Variable initialization}
14540
14541 \end_inset
14542
14543 .
14544  On some mcs51 variants xdata
14545 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
14546
14547 \end_inset
14548
14549  memory has to be explicitly enabled before it can be accessed or if the
14550  watchdog
14551 \begin_inset LatexCommand \index{watchdog}
14552
14553 \end_inset
14554
14555  needs to be disabled, this is the place to do it.
14556  The startup code clears all internal data memory, 256 bytes by default,
14557  but from 0 to n-1 if 
14558 \emph on
14559 -
14560 \begin_inset ERT
14561 status collapsed
14562
14563 \begin_layout Standard
14564
14565
14566 \backslash
14567 /
14568 \end_layout
14569
14570 \end_inset
14571
14572 -iram-size
14573 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
14574
14575 \end_inset
14576
14577 n
14578 \emph default
14579  is used.
14580  (recommended for Chipcon CC1010).
14581 \end_layout
14582
14583 \begin_layout Standard
14584 See also the compiler options 
14585 \emph on
14586 -
14587 \begin_inset ERT
14588 status collapsed
14589
14590 \begin_layout Standard
14591
14592
14593 \backslash
14594 /
14595 \end_layout
14596
14597 \end_inset
14598
14599 -no-xinit
14600 \emph default
14601 -
14602 \emph on
14603 opt
14604 \emph default
14605
14606 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
14607
14608 \end_inset
14609
14610
14611 \emph on
14612 -
14613 \begin_inset ERT
14614 status collapsed
14615
14616 \begin_layout Standard
14617
14618
14619 \backslash
14620 /
14621 \end_layout
14622
14623 \end_inset
14624
14625 -main-return
14626 \emph default
14627
14628 \begin_inset LatexCommand \index{-\/-main-return}
14629
14630 \end_inset
14631
14632  and section 
14633 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14634
14635 \end_inset
14636
14637  about MCS51-variants.
14638 \begin_inset VSpace bigskip
14639 \end_inset
14640
14641
14642 \end_layout
14643
14644 \begin_layout Subsection
14645 HC08 Startup Code
14646 \end_layout
14647
14648 \begin_layout Standard
14649 The HC08
14650 \begin_inset LatexCommand \index{HC08}
14651
14652 \end_inset
14653
14654  startup code follows the same scheme as the MCS51 startup code.
14655 \begin_inset VSpace bigskip
14656 \end_inset
14657
14658
14659 \end_layout
14660
14661 \begin_layout Subsection
14662 Z80 Startup Code
14663 \end_layout
14664
14665 \begin_layout Standard
14666 On the Z80
14667 \begin_inset LatexCommand \index{Z80}
14668
14669 \end_inset
14670
14671  the startup code is inserted by linking with crt0.o which is generated from
14672  sdcc/device/lib/z80/crt0.s.
14673  If you need a different startup code you can use the compiler option 
14674 \emph on
14675 -
14676 \series bold
14677 \emph default
14678
14679 \begin_inset ERT
14680 status collapsed
14681
14682 \begin_layout Standard
14683
14684
14685 \backslash
14686 /
14687 \end_layout
14688
14689 \end_inset
14690
14691
14692 \series default
14693 \emph on
14694 -no-std-crt0
14695 \emph default
14696
14697 \begin_inset LatexCommand \index{-\/-no-std-crt0}
14698
14699 \end_inset
14700
14701  and provide your own crt0.o.
14702  
14703 \begin_inset VSpace bigskip
14704 \end_inset
14705
14706
14707 \end_layout
14708
14709 \begin_layout Section
14710 Inline Assembler Code
14711 \begin_inset LatexCommand \index{Assembler routines}
14712
14713 \end_inset
14714
14715
14716 \end_layout
14717
14718 \begin_layout Subsection
14719 A Step by Step Introduction
14720 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
14721
14722 \end_inset
14723
14724
14725 \end_layout
14726
14727 \begin_layout Standard
14728 Starting from a small snippet of c-code this example shows for the MCS51
14729  how to use inline assembly, access variables, a function parameter and
14730  an array in xdata memory.
14731  The example uses an MCS51 here but is easily adapted for other architectures.
14732  This is a buffer routine which should be optimized:
14733 \end_layout
14734
14735 \begin_layout Verse
14736
14737 \family typewriter
14738 \size footnotesize
14739 unsigned char __far
14740 \begin_inset LatexCommand \index{far (storage class)}
14741
14742 \end_inset
14743
14744
14745 \begin_inset LatexCommand \index{\_\_far (storage class)}
14746
14747 \end_inset
14748
14749  __at
14750 \begin_inset LatexCommand \index{at}
14751
14752 \end_inset
14753
14754
14755 \begin_inset LatexCommand \index{\_\_at}
14756
14757 \end_inset
14758
14759 (0x7f00) buf[0x100];
14760 \begin_inset LatexCommand \index{Aligned array}
14761
14762 \end_inset
14763
14764
14765 \newline
14766 unsigned char head, tail;\InsetSpace ~
14767 \InsetSpace ~
14768 \InsetSpace ~
14769 \InsetSpace ~
14770 \InsetSpace ~
14771 \InsetSpace ~
14772 \InsetSpace ~
14773 \InsetSpace ~
14774 \InsetSpace ~
14775 \InsetSpace ~
14776 \InsetSpace ~
14777 \InsetSpace ~
14778 \InsetSpace ~
14779 \InsetSpace ~
14780 \InsetSpace ~
14781 \InsetSpace ~
14782 \InsetSpace ~
14783 /* if interrupts
14784 \begin_inset LatexCommand \index{interrupt}
14785
14786 \end_inset
14787
14788  are involved see
14789 \newline
14790 \InsetSpace ~
14791 \InsetSpace ~
14792 \InsetSpace ~
14793 \InsetSpace ~
14794 \InsetSpace ~
14795 \InsetSpace ~
14796 \InsetSpace ~
14797 \InsetSpace ~
14798 \InsetSpace ~
14799 \InsetSpace ~
14800 \InsetSpace ~
14801 \InsetSpace ~
14802 \InsetSpace ~
14803 \InsetSpace ~
14804 \InsetSpace ~
14805 \InsetSpace ~
14806 \InsetSpace ~
14807 \InsetSpace ~
14808 \InsetSpace ~
14809 \InsetSpace ~
14810 \InsetSpace ~
14811 \InsetSpace ~
14812 \InsetSpace ~
14813 \InsetSpace ~
14814 \InsetSpace ~
14815 \InsetSpace ~
14816 \InsetSpace ~
14817 \InsetSpace ~
14818 \InsetSpace ~
14819 \InsetSpace ~
14820 \InsetSpace ~
14821 \InsetSpace ~
14822 \InsetSpace ~
14823 \InsetSpace ~
14824 \InsetSpace ~
14825 \InsetSpace ~
14826 \InsetSpace ~
14827 \InsetSpace ~
14828 \InsetSpace ~
14829 \InsetSpace ~
14830 \InsetSpace ~
14831 \InsetSpace ~
14832 \InsetSpace ~
14833 \InsetSpace ~
14834 \InsetSpace ~
14835 section 
14836 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
14837
14838 \end_inset
14839
14840  about
14841 \series bold
14842  volatile
14843 \series default
14844  */
14845 \newline
14846
14847 \newline
14848 void to_buffer( unsigned char c ) 
14849 \newline
14850 {
14851 \newline
14852 \InsetSpace ~
14853 \InsetSpace ~
14854 \InsetSpace ~
14855 \InsetSpace ~
14856 if( head != (unsigned char)(tail-1)
14857  )\InsetSpace ~
14858 /* cast 
14859 \series bold
14860 needed
14861 \series default
14862  to avoid promotion
14863 \begin_inset LatexCommand \index{promotion to signed int}
14864
14865 \end_inset
14866
14867
14868 \begin_inset LatexCommand \index{type promotion}
14869
14870 \end_inset
14871
14872  to integer */
14873 \begin_inset Marginal
14874 status collapsed
14875
14876 \begin_layout Standard
14877
14878 \series bold
14879 \InsetSpace ~
14880 !
14881 \end_layout
14882
14883 \end_inset
14884
14885
14886 \newline
14887 \InsetSpace ~
14888 \InsetSpace ~
14889 \InsetSpace ~
14890 \InsetSpace ~
14891 \InsetSpace ~
14892 \InsetSpace ~
14893 \InsetSpace ~
14894 \InsetSpace ~
14895 buf[ head++ ] = c;\InsetSpace ~
14896 \InsetSpace ~
14897 \InsetSpace ~
14898 \InsetSpace ~
14899 \InsetSpace ~
14900 \InsetSpace ~
14901 \InsetSpace ~
14902 \InsetSpace ~
14903 \InsetSpace ~
14904 \InsetSpace ~
14905 \InsetSpace ~
14906 \InsetSpace ~
14907 \InsetSpace ~
14908 \InsetSpace ~
14909 \InsetSpace ~
14910 \InsetSpace ~
14911 /* access to a 256 byte aligned array */
14912 \newline
14913
14914 \end_layout
14915
14916 \begin_layout Standard
14917 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
14918  then a corresponding buffer.asm file is generated.
14919  We define a new function 
14920 \family typewriter
14921 to_buffer_asm()
14922 \family default
14923  in file buffer.c in which we cut and paste the generated code, removing
14924  unwanted comments and some ':'.
14925  Then add 
14926 \begin_inset Quotes sld
14927 \end_inset
14928
14929 _asm
14930 \begin_inset Quotes srd
14931 \end_inset
14932
14933  and 
14934 \begin_inset Quotes sld
14935 \end_inset
14936
14937 _endasm;
14938 \begin_inset Quotes srd
14939 \end_inset
14940
14941  to the beginning and the end of the function body:
14942 \end_layout
14943
14944 \begin_layout Verse
14945
14946 \family typewriter
14947 \size footnotesize
14948 /* With a cut and paste from the .asm file, we have something to start with.
14949 \newline
14950 \InsetSpace ~
14951 \InsetSpace ~
14952 \InsetSpace ~
14953 The
14954  function is not yet OK! (registers aren't saved) */ 
14955 \newline
14956 void to_buffer_asm(
14957  unsigned char c ) 
14958 \newline
14959
14960 \newline
14961 \InsetSpace ~
14962 \InsetSpace ~
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 _asm
14966 \begin_inset LatexCommand \index{\_asm}
14967
14968 \end_inset
14969
14970
14971 \begin_inset LatexCommand \index{\_\_asm}
14972
14973 \end_inset
14974
14975
14976 \newline
14977 \InsetSpace ~
14978 \InsetSpace ~
14979 \InsetSpace ~
14980 \InsetSpace ~
14981 mov\InsetSpace ~
14982 \InsetSpace ~
14983 r2,dpl 
14984 \newline
14985 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
14986 /* cast 
14987 \series bold
14988 needed
14989 \series default
14990  to avoid promotion
14991 \begin_inset LatexCommand \index{promotion to signed int}
14992
14993 \end_inset
14994
14995
14996 \begin_inset LatexCommand \index{type promotion}
14997
14998 \end_inset
14999
15000  to integer */
15001 \newline
15002 \InsetSpace ~
15003 \InsetSpace ~
15004 \InsetSpace ~
15005 \InsetSpace ~
15006 mov\InsetSpace ~
15007 \InsetSpace ~
15008 a,_tail 
15009 \newline
15010 \InsetSpace ~
15011 \InsetSpace ~
15012 \InsetSpace ~
15013 \InsetSpace ~
15014 dec\InsetSpace ~
15015 \InsetSpace ~
15016
15017 \newline
15018 \InsetSpace ~
15019 \InsetSpace ~
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 mov\InsetSpace ~
15023 \InsetSpace ~
15024 r3,a 
15025 \newline
15026 \InsetSpace ~
15027 \InsetSpace ~
15028 \InsetSpace ~
15029 \InsetSpace ~
15030 mov\InsetSpace ~
15031 \InsetSpace ~
15032 a,_head 
15033 \newline
15034 \InsetSpace ~
15035 \InsetSpace ~
15036 \InsetSpace ~
15037 \InsetSpace ~
15038 cjne a,ar3,00106$ 
15039 \newline
15040 \InsetSpace ~
15041 \InsetSpace ~
15042 \InsetSpace ~
15043 \InsetSpace ~
15044 ret
15045 \newline
15046 00106$:
15047  
15048 \newline
15049 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
15050 \begin_inset LatexCommand \index{Aligned array}
15051
15052 \end_inset
15053
15054
15055 \newline
15056 \InsetSpace ~
15057 \InsetSpace ~
15058 \InsetSpace ~
15059 \InsetSpace ~
15060 mov\InsetSpace ~
15061 \InsetSpace ~
15062 r3,_head 
15063 \newline
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 inc\InsetSpace ~
15069 \InsetSpace ~
15070 _head 
15071 \newline
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 mov\InsetSpace ~
15077 \InsetSpace ~
15078 dpl,r3 
15079 \newline
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 mov\InsetSpace ~
15085 \InsetSpace ~
15086 dph,#(_buf >> 8) 
15087 \newline
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 mov\InsetSpace ~
15093 \InsetSpace ~
15094 a,r2 
15095 \newline
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 movx @dptr,a
15101  
15102 \newline
15103 00103$: 
15104 \newline
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 ret
15110 \newline
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 \InsetSpace ~
15114 \InsetSpace ~
15115 _endasm
15116 \begin_inset LatexCommand \index{\_endasm}
15117
15118 \end_inset
15119
15120
15121 \begin_inset LatexCommand \index{\_\_endasm}
15122
15123 \end_inset
15124
15125 ;
15126 \newline
15127
15128 \end_layout
15129
15130 \begin_layout Standard
15131 The new file buffer.c should compile with only one warning about the unreferenced
15132  function argument 'c'.
15133  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
15134  (1) and finally have:
15135 \end_layout
15136
15137 \begin_layout Verse
15138
15139 \family typewriter
15140 \size footnotesize
15141 unsigned char __far __at(0x7f00) buf[0x100];
15142 \newline
15143 unsigned char head, tail;
15144 \newline
15145 #define
15146  USE_ASSEMBLY (1)
15147 \newline
15148
15149 \newline
15150 #if !USE_ASSEMBLY
15151 \newline
15152
15153 \newline
15154 void to_buffer( unsigned char c )
15155 \newline
15156 {
15157 \newline
15158 \InsetSpace ~
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 if(
15163  head != (unsigned char)(tail-1) )
15164 \newline
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 \InsetSpace ~
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 buf[ head++ ] = c;
15174 \newline
15175 }
15176 \newline
15177
15178 \newline
15179 #else
15180 \newline
15181
15182 \newline
15183 void to_buffer(
15184  unsigned char c )
15185 \newline
15186 {
15187 \newline
15188 \InsetSpace ~
15189 \InsetSpace ~
15190 \InsetSpace ~
15191 \InsetSpace ~
15192 c; // to avoid warning: unreferenced function argument
15193 \newline
15194 \InsetSpace ~
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 _asm
15199 \begin_inset LatexCommand \index{\_asm}
15200
15201 \end_inset
15202
15203
15204 \begin_inset LatexCommand \index{\_\_asm}
15205
15206 \end_inset
15207
15208
15209 \newline
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 \InsetSpace ~
15216 \InsetSpace ~
15217 \InsetSpace ~
15218 ; save used registers here.
15219  
15220 \newline
15221 \InsetSpace ~
15222 \InsetSpace ~
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 \InsetSpace ~
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 \InsetSpace ~
15229 ; If we were still using r2,r3 we would have to push them here.
15230  
15231 \newline
15232 ; if( head != (unsigned char)(tail-1) )
15233 \newline
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 \InsetSpace ~
15239 \InsetSpace ~
15240 \InsetSpace ~
15241 \InsetSpace ~
15242 mov\InsetSpace ~
15243  a,_tail
15244 \newline
15245 \InsetSpace ~
15246 \InsetSpace ~
15247 \InsetSpace ~
15248 \InsetSpace ~
15249 \InsetSpace ~
15250 \InsetSpace ~
15251 \InsetSpace ~
15252 \InsetSpace ~
15253 dec\InsetSpace ~
15254  a
15255 \newline
15256 \InsetSpace ~
15257 \InsetSpace ~
15258 \InsetSpace ~
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 \InsetSpace ~
15264 xrl\InsetSpace ~
15265  a,_head
15266 \newline
15267 \InsetSpace ~
15268 \InsetSpace ~
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 \InsetSpace ~
15274 \InsetSpace ~
15275 ; we
15276  could do an ANL a,#0x0f here to use a smaller buffer (see below)
15277 \newline
15278 \InsetSpace ~
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 \InsetSpace ~
15282 \InsetSpace ~
15283 \InsetSpace ~
15284 \InsetSpace ~
15285 \InsetSpace ~
15286 jz\InsetSpace ~
15287 \InsetSpace ~
15288  t_b_end$
15289 \newline
15290 \InsetSpace ~
15291 \InsetSpace ~
15292 \InsetSpace ~
15293 \InsetSpace ~
15294 \InsetSpace ~
15295 \InsetSpace ~
15296 \InsetSpace ~
15297 \InsetSpace ~
15298 ;
15299 \newline
15300 ;
15301  buf[ head++ ] = c;
15302 \newline
15303 \InsetSpace ~
15304 \InsetSpace ~
15305 \InsetSpace ~
15306 \InsetSpace ~
15307 \InsetSpace ~
15308 \InsetSpace ~
15309 \InsetSpace ~
15310 \InsetSpace ~
15311 mov\InsetSpace ~
15312  a,dpl \InsetSpace ~
15313 \InsetSpace ~
15314 \InsetSpace ~
15315 \InsetSpace ~
15316 \InsetSpace ~
15317 \InsetSpace ~
15318 \InsetSpace ~
15319 ; dpl holds lower byte of function argument
15320 \newline
15321 \InsetSpace ~
15322 \InsetSpace ~
15323 \InsetSpace ~
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 \InsetSpace ~
15327 \InsetSpace ~
15328 \InsetSpace ~
15329 mov\InsetSpace ~
15330
15331  dpl,_head \InsetSpace ~
15332 \InsetSpace ~
15333 \InsetSpace ~
15334 ; buf is 0x100 byte aligned so head can be used directly
15335 \newline
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 \InsetSpace ~
15340 \InsetSpace ~
15341 \InsetSpace ~
15342 \InsetSpace ~
15343 \InsetSpace ~
15344 mov\InsetSpace ~
15345  dph,#(_bu
15346 f>>8)
15347 \newline
15348 \InsetSpace ~
15349 \InsetSpace ~
15350 \InsetSpace ~
15351 \InsetSpace ~
15352 \InsetSpace ~
15353 \InsetSpace ~
15354 \InsetSpace ~
15355 \InsetSpace ~
15356 movx @dptr,a
15357 \newline
15358 \InsetSpace ~
15359 \InsetSpace ~
15360 \InsetSpace ~
15361 \InsetSpace ~
15362 \InsetSpace ~
15363 \InsetSpace ~
15364 \InsetSpace ~
15365 \InsetSpace ~
15366 inc \InsetSpace ~
15367 _head
15368 \newline
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 \InsetSpace ~
15373 \InsetSpace ~
15374 \InsetSpace ~
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 ; we could do an ANL _head,#0x0f here to use a
15378  smaller buffer (see above)
15379 \newline
15380 t_b_end$:
15381 \newline
15382 \InsetSpace ~
15383 \InsetSpace ~
15384 \InsetSpace ~
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 ; restore used registers here 
15391 \newline
15392 \InsetSpace ~
15393 \InsetSpace ~
15394 \InsetSpace ~
15395 \InsetSpace ~
15396 _endasm
15397 \begin_inset LatexCommand \index{\_endasm}
15398
15399 \end_inset
15400
15401
15402 \begin_inset LatexCommand \index{\_\_endasm}
15403
15404 \end_inset
15405
15406 ;
15407 \newline
15408 }
15409 \newline
15410 #endif
15411 \end_layout
15412
15413 \begin_layout Standard
15414 The inline assembler code can contain any valid code understood by the assembler
15415 , this includes any assembler directives and comment lines.
15416  The assembler does not like some characters like ':' or ''' in comments.
15417  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
15418 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
15419
15420 \end_inset
15421
15422
15423 \begin_inset LatexCommand \index{Assembler documentation}
15424
15425 \end_inset
15426
15427  or online at 
15428 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
15429
15430 \end_inset
15431
15432 \InsetSpace ~
15433 .
15434 \end_layout
15435
15436 \begin_layout Standard
15437 The compiler does not do any validation of the code within the 
15438 \family typewriter
15439 _asm
15440 \begin_inset LatexCommand \index{\_asm}
15441
15442 \end_inset
15443
15444
15445 \begin_inset LatexCommand \index{\_\_asm}
15446
15447 \end_inset
15448
15449  ...
15450  _endasm
15451 \size footnotesize
15452
15453 \begin_inset LatexCommand \index{\_endasm}
15454
15455 \end_inset
15456
15457
15458 \begin_inset LatexCommand \index{\_\_endasm}
15459
15460 \end_inset
15461
15462
15463 \size default
15464 ;
15465 \family default
15466  keyword pair.
15467  Specifically it will not know which registers are used and thus register
15468  pushing/popping
15469 \begin_inset LatexCommand \index{push/pop}
15470
15471 \end_inset
15472
15473  has to be done manually.
15474  
15475 \end_layout
15476
15477 \begin_layout Standard
15478 It is recommended that each assembly instruction (including labels) be placed
15479  in a separate line (as the example shows).
15480  When the -
15481 \begin_inset ERT
15482 status collapsed
15483
15484 \begin_layout Standard
15485
15486
15487 \backslash
15488 /
15489 \end_layout
15490
15491 \end_inset
15492
15493 -
15494 \emph on
15495 peep-asm
15496 \begin_inset LatexCommand \index{-\/-peep-asm}
15497
15498 \end_inset
15499
15500
15501 \emph default
15502  command line option is used, the inline assembler code will be passed through
15503  the peephole optimizer
15504 \begin_inset LatexCommand \index{Peephole optimizer}
15505
15506 \end_inset
15507
15508 .
15509  There are only a few (if any) cases where this option makes sense, it might
15510  cause some unexpected changes in the inline assembler code.
15511  Please go through the peephole optimizer rules defined in file 
15512 \emph on
15513 SDCCpeeph.def
15514 \emph default
15515  before using this option.
15516 \end_layout
15517
15518 \begin_layout Subsection
15519 Naked Functions
15520 \begin_inset LatexCommand \label{sub:Naked-Functions}
15521
15522 \end_inset
15523
15524
15525 \begin_inset LatexCommand \index{Naked functions}
15526
15527 \end_inset
15528
15529
15530 \end_layout
15531
15532 \begin_layout Standard
15533 A special keyword may be associated with a function declaring it as 
15534 \emph on
15535 _naked
15536 \begin_inset LatexCommand \index{\_naked}
15537
15538 \end_inset
15539
15540
15541 \begin_inset LatexCommand \index{\_\_naked}
15542
15543 \end_inset
15544
15545 .
15546  
15547 \emph default
15548 The 
15549 \emph on
15550 _naked
15551 \emph default
15552  function modifier attribute prevents the compiler from generating prologue
15553 \begin_inset LatexCommand \index{function prologue}
15554
15555 \end_inset
15556
15557  and epilogue
15558 \begin_inset LatexCommand \index{function epilogue}
15559
15560 \end_inset
15561
15562  code for that function.
15563  This means that the user is entirely responsible for such things as saving
15564  any registers that may need to be preserved, selecting the proper register
15565  bank, generating the 
15566 \emph on
15567 return
15568 \emph default
15569  instruction at the end, etc.
15570  Practically, this means that the contents of the function must be written
15571  in inline assembler.
15572  This is particularly useful for interrupt functions, which can have a large
15573  (and often unnecessary) prologue/epilogue.
15574  For example, compare the code generated by these two functions:
15575 \end_layout
15576
15577 \begin_layout Verse
15578
15579 \family typewriter
15580 volatile
15581 \begin_inset LatexCommand \index{volatile}
15582
15583 \end_inset
15584
15585  data unsigned char counter;
15586 \newline
15587
15588 \newline
15589 void simpleInterrupt(void) __interrupt
15590 \begin_inset LatexCommand \index{interrupt}
15591
15592 \end_inset
15593
15594
15595 \begin_inset LatexCommand \index{\_\_interrupt}
15596
15597 \end_inset
15598
15599  (1)
15600 \newline
15601 {
15602 \newline
15603 \InsetSpace ~
15604 \InsetSpace ~
15605 \InsetSpace ~
15606 \InsetSpace ~
15607 counter++;
15608 \newline
15609 }
15610 \newline
15611
15612 \newline
15613 void nakedInterrupt(void) __interrupt (2) __naked
15614 \newline
15615 {
15616 \newline
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 \InsetSpace ~
15620 \InsetSpace ~
15621 _asm
15622 \begin_inset LatexCommand \index{\_asm}
15623
15624 \end_inset
15625
15626
15627 \begin_inset LatexCommand \index{\_\_asm}
15628
15629 \end_inset
15630
15631
15632 \newline
15633 \InsetSpace ~
15634 \InsetSpace ~
15635 \InsetSpace ~
15636 \InsetSpace ~
15637 \InsetSpace ~
15638 \InsetSpace ~
15639 inc\InsetSpace ~
15640 \InsetSpace ~
15641 \InsetSpace ~
15642 \InsetSpace ~
15643 \InsetSpace ~
15644 _counter ; does not change flags, no need to save psw
15645 \newline
15646 \InsetSpace ~
15647 \InsetSpace ~
15648 \InsetSpace ~
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 reti\InsetSpace ~
15653 \InsetSpace ~
15654 \InsetSpace ~
15655 \InsetSpace ~
15656 ; MUST explicitly
15657  include ret or reti in _naked function.
15658 \newline
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 _endasm
15664 \begin_inset LatexCommand \index{\_endasm}
15665
15666 \end_inset
15667
15668
15669 \begin_inset LatexCommand \index{\_\_endasm}
15670
15671 \end_inset
15672
15673 ;
15674 \newline
15675 }
15676 \end_layout
15677
15678 \begin_layout Standard
15679 For an 8051 target, the generated simpleInterrupt looks like:
15680 \end_layout
15681
15682 \begin_layout Verse
15683
15684 \family typewriter
15685 Note, this is an 
15686 \emph on
15687 outdated
15688 \emph default
15689  example, recent versions of SDCC generate
15690 \newline
15691 the 
15692 \emph on
15693 same
15694 \emph default
15695  code for simpleInterrupt() and nakedInterrupt()!
15696 \newline
15697
15698 \newline
15699 _simpleInterrupt:
15700 \newline
15701 \InsetSpace ~
15702 \InsetSpace ~
15703 \InsetSpace ~
15704 \InsetSpace ~
15705 push\InsetSpace ~
15706 \InsetSpace ~
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 acc
15710 \newline
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 push\InsetSpace ~
15716 \InsetSpace ~
15717 \InsetSpace ~
15718 \InsetSpace ~
15719 b
15720 \newline
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 pu
15726 sh\InsetSpace ~
15727 \InsetSpace ~
15728 \InsetSpace ~
15729 \InsetSpace ~
15730 dpl
15731 \newline
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 push\InsetSpace ~
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 dph
15741 \newline
15742 \InsetSpace ~
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 push\InsetSpace ~
15747 \InsetSpace ~
15748 \InsetSpace ~
15749 \InsetSpace ~
15750 psw
15751 \newline
15752 \InsetSpace ~
15753 \InsetSpace ~
15754 \InsetSpace ~
15755 \InsetSpace ~
15756 mov\InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 psw,#0x00
15762 \newline
15763 \InsetSpace ~
15764 \InsetSpace ~
15765 \InsetSpace ~
15766 \InsetSpace ~
15767 inc\InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 _counter
15773 \newline
15774 \InsetSpace ~
15775 \InsetSpace ~
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 pop\InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 psw
15784 \newline
15785 \InsetSpace ~
15786 \InsetSpace ~
15787 \InsetSpace ~
15788 \InsetSpace ~
15789 pop\InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 dph
15795 \newline
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 pop\InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 \InsetSpace ~
15805 dpl
15806 \newline
15807 \InsetSpace ~
15808 \InsetSpace ~
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 pop\InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 \InsetSpace ~
15815 \InsetSpace ~
15816 b
15817 \newline
15818 \InsetSpace ~
15819 \InsetSpace ~
15820 \InsetSpace ~
15821 \InsetSpace ~
15822 pop\InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 acc
15828 \newline
15829 \InsetSpace ~
15830 \InsetSpace ~
15831 \InsetSpace ~
15832 \InsetSpace ~
15833 reti
15834 \end_layout
15835
15836 \begin_layout Standard
15837 whereas nakedInterrupt looks like:
15838 \end_layout
15839
15840 \begin_layout Verse
15841
15842 \family typewriter
15843 _nakedInterrupt:
15844 \newline
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 inc\InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 \InsetSpace ~
15853 _counter ; does not change flags, no need to save psw
15854 \newline
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 reti\InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 \InsetSpace ~
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 ;
15872  MUST explicitly include ret or reti in _naked function
15873 \end_layout
15874
15875 \begin_layout Standard
15876 The related directive #pragma exclude
15877 \begin_inset LatexCommand \index{\#pragma exclude}
15878
15879 \end_inset
15880
15881  allows a more fine grained control over pushing & popping
15882 \begin_inset LatexCommand \index{push/pop}
15883
15884 \end_inset
15885
15886  the registers.
15887 \end_layout
15888
15889 \begin_layout Standard
15890 While there is nothing preventing you from writing C code inside a 
15891 \family typewriter
15892 _naked
15893 \family default
15894  function, there are many ways to shoot yourself in the foot doing this,
15895  and it is recommended that you stick to inline assembler.
15896 \end_layout
15897
15898 \begin_layout Subsection
15899 Use of Labels within Inline Assembler
15900 \end_layout
15901
15902 \begin_layout Standard
15903 SDCC allows the use of in-line assembler with a few restrictions regarding
15904  labels.
15905  In older versions of the compiler all labels defined within inline assembler
15906  code 
15907 \emph on
15908 had to be
15909 \emph default
15910  of the form 
15911 \emph on
15912 nnnnn$
15913 \emph default
15914  where nnnn is a number less than 100 (which implies a limit of utmost 100
15915  inline assembler labels 
15916 \emph on
15917 per function
15918 \emph default
15919 \noun on
15920 )
15921 \noun default
15922 .
15923  
15924 \end_layout
15925
15926 \begin_layout Verse
15927
15928 \family typewriter
15929 _asm
15930 \begin_inset LatexCommand \index{\_asm}
15931
15932 \end_inset
15933
15934
15935 \begin_inset LatexCommand \index{\_\_asm}
15936
15937 \end_inset
15938
15939  
15940 \newline
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 mov\InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 b,#10 
15951 \newline
15952 00001$: 
15953 \newline
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 \InsetSpace ~
15958 djnz\InsetSpace ~
15959 \InsetSpace ~
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 b,00001$ 
15963 \newline
15964 _endasm
15965 \begin_inset LatexCommand \index{\_endasm}
15966
15967 \end_inset
15968
15969
15970 \begin_inset LatexCommand \index{\_\_endasm}
15971
15972 \end_inset
15973
15974  ;
15975 \end_layout
15976
15977 \begin_layout Standard
15978 Inline assembler code cannot reference any C-Labels, however it can reference
15979  labels
15980 \begin_inset LatexCommand \index{Labels}
15981
15982 \end_inset
15983
15984  defined by the inline assembler, e.g.:
15985 \end_layout
15986
15987 \begin_layout Verse
15988
15989 \family typewriter
15990 foo() { 
15991 \newline
15992 \InsetSpace ~
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 /* some c code */ 
15997 \newline
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 _asm 
16003 \newline
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 ; some assembler code 
16011 \newline
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 ljmp $0003 
16019 \newline
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 _endasm;
16025  
16026 \newline
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 /* some more c code */ 
16032 \newline
16033 clabel:\InsetSpace ~
16034 \InsetSpace ~
16035 /* inline assembler cannot reference this
16036  label */ 
16037 \newline
16038 \InsetSpace ~
16039 \InsetSpace ~
16040 \InsetSpace ~
16041 \InsetSpace ~
16042 _asm
16043 \newline
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 $0003: ;label (can be referenced by inline assembler only)
16049  
16050 \newline
16051 \InsetSpace ~
16052 \InsetSpace ~
16053 \InsetSpace ~
16054 \InsetSpace ~
16055 _endasm
16056 \begin_inset LatexCommand \index{\_endasm}
16057
16058 \end_inset
16059
16060
16061 \begin_inset LatexCommand \index{\_\_endasm}
16062
16063 \end_inset
16064
16065  ; 
16066 \newline
16067 \InsetSpace ~
16068 \InsetSpace ~
16069 \InsetSpace ~
16070 \InsetSpace ~
16071 /* some more c code */
16072 \newline
16073 }
16074 \end_layout
16075
16076 \begin_layout Standard
16077 In other words inline assembly code can access labels defined in inline
16078  assembly within the scope of the function.
16079  The same goes the other way, i.e.
16080  labels defines in inline assembly can not be accessed by C statements.
16081 \end_layout
16082
16083 \begin_layout Section
16084 Interfacing with Assembler Code
16085 \begin_inset LatexCommand \index{Assembler routines}
16086
16087 \end_inset
16088
16089
16090 \end_layout
16091
16092 \begin_layout Subsection
16093 Global Registers used for Parameter Passing
16094 \begin_inset LatexCommand \index{Parameter passing}
16095
16096 \end_inset
16097
16098
16099 \end_layout
16100
16101 \begin_layout Standard
16102 The compiler always uses the global registers 
16103 \emph on
16104 DPL, DPH
16105 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
16106
16107 \end_inset
16108
16109
16110 \begin_inset LatexCommand \index{DPTR}
16111
16112 \end_inset
16113
16114 , B
16115 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
16116
16117 \end_inset
16118
16119  
16120 \emph default
16121 and
16122 \emph on
16123  ACC
16124 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
16125
16126 \end_inset
16127
16128
16129 \emph default
16130  to pass the first parameter to a routine.
16131  The second parameter onwards is either allocated on the stack (for reentrant
16132  routines or if -
16133 \begin_inset ERT
16134 status collapsed
16135
16136 \begin_layout Standard
16137
16138
16139 \backslash
16140 /
16141 \end_layout
16142
16143 \end_inset
16144
16145 -stack-auto is used) or in data / xdata memory (depending on the memory
16146  model).
16147  
16148 \end_layout
16149
16150 \begin_layout Subsection
16151 Assembler Routine (non-reentrant)
16152 \end_layout
16153
16154 \begin_layout Standard
16155 In the following example
16156 \begin_inset LatexCommand \index{reentrant}
16157
16158 \end_inset
16159
16160
16161 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
16162
16163 \end_inset
16164
16165  the function c_func calls an assembler routine asm_func, which takes two
16166  parameters
16167 \begin_inset LatexCommand \index{function parameter}
16168
16169 \end_inset
16170
16171 .
16172 \end_layout
16173
16174 \begin_layout Verse
16175
16176 \family typewriter
16177 extern int asm_func(unsigned char, unsigned char);
16178 \newline
16179
16180 \newline
16181 int c_func (unsigned char
16182  i, unsigned char j)
16183 \newline
16184 {
16185 \newline
16186 \InsetSpace ~
16187 \InsetSpace ~
16188 \InsetSpace ~
16189 \InsetSpace ~
16190 return asm_func(i,j);
16191 \newline
16192 }
16193 \newline
16194
16195 \newline
16196 int main()
16197 \newline
16198 {
16199 \newline
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 return c_func(10,9);
16205 \newline
16206 }
16207 \end_layout
16208
16209 \begin_layout Standard
16210 The corresponding assembler function is:
16211 \end_layout
16212
16213 \begin_layout Verse
16214
16215 \family typewriter
16216 .globl _asm_func_PARM_2 
16217 \newline
16218 \InsetSpace ~
16219 \InsetSpace ~
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 .globl _asm_func 
16227 \newline
16228 \InsetSpace ~
16229 \InsetSpace ~
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 .area OSEG 
16237 \newline
16238 _asm_func_PARM_2:
16239 \newline
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 .ds   
16249  1 
16250 \newline
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 \InsetSpace ~
16259 .area CSEG 
16260 \newline
16261 _asm_func: 
16262 \newline
16263 \InsetSpace ~
16264 \InsetSpace ~
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 \InsetSpace ~
16269 \InsetSpace ~
16270 \InsetSpace ~
16271 mov\InsetSpace ~
16272 \InsetSpace ~
16273 \InsetSpace ~
16274 \InsetSpace ~
16275 a,dpl 
16276 \newline
16277 \InsetSpace ~
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 \InsetSpace ~
16283 \InsetSpace ~
16284 \InsetSpace ~
16285 add\InsetSpace ~
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 a,_asm_func_PARM_2 
16290 \newline
16291 \InsetSpace ~
16292 \InsetSpace ~
16293 \InsetSpace ~
16294 \InsetSpace ~
16295 \InsetSpace ~
16296 \InsetSpace ~
16297 \InsetSpace ~
16298 \InsetSpace ~
16299 mov\InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 dpl,a 
16304 \newline
16305 \InsetSpace ~
16306 \InsetSpace ~
16307 \InsetSpace ~
16308 \InsetSpace ~
16309 \InsetSpace ~
16310 \InsetSpace ~
16311 \InsetSpace ~
16312 \InsetSpace ~
16313 mov\InsetSpace ~
16314 \InsetSpace ~
16315 \InsetSpace ~
16316 \InsetSpace ~
16317 dph
16318 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
16319
16320 \end_inset
16321
16322 ,#0x00 
16323 \newline
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 \InsetSpace ~
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 ret
16333 \end_layout
16334
16335 \begin_layout Standard
16336 Note here that the return values
16337 \begin_inset LatexCommand \index{return value}
16338
16339 \end_inset
16340
16341  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
16342  two byte values.
16343  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
16344 b' & 'acc' for four byte values.
16345 \end_layout
16346
16347 \begin_layout Standard
16348 The parameter naming convention is _<function_name>_PARM_<n>, where n is
16349  the parameter number starting from 1, and counting from the left.
16350  The first parameter is passed in 
16351 \begin_inset Quotes eld
16352 \end_inset
16353
16354 dpl
16355 \begin_inset Quotes erd
16356 \end_inset
16357
16358  for a one byte parameter, 
16359 \begin_inset Quotes eld
16360 \end_inset
16361
16362 dptr
16363 \begin_inset Quotes erd
16364 \end_inset
16365
16366  for two bytes, 
16367 \begin_inset Quotes eld
16368 \end_inset
16369
16370 b,dptr
16371 \begin_inset Quotes erd
16372 \end_inset
16373
16374  for three bytes and 
16375 \begin_inset Quotes eld
16376 \end_inset
16377
16378 acc,b,dptr
16379 \begin_inset Quotes erd
16380 \end_inset
16381
16382  for a four bytes parameter.
16383  The variable name for the second parameter will be _<function_name>_PARM_2.
16384 \newline
16385
16386 \newline
16387 Assem
16388 ble the assembler routine with the following command:
16389 \newline
16390
16391 \newline
16392
16393 \family sans
16394 \series bold
16395 asx8051 -losg asmfunc.asm
16396 \newline
16397
16398 \newline
16399
16400 \family default
16401 \series default
16402 Then compile and link the assembler routine to the C source file with the
16403  following command:
16404 \newline
16405
16406 \newline
16407
16408 \family sans
16409 \series bold
16410 sdcc cfunc.c asmfunc.rel
16411 \end_layout
16412
16413 \begin_layout Subsection
16414 Assembler Routine (reentrant)
16415 \end_layout
16416
16417 \begin_layout Standard
16418 In this case
16419 \begin_inset LatexCommand \index{reentrant}
16420
16421 \end_inset
16422
16423
16424 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
16425
16426 \end_inset
16427
16428  the second parameter
16429 \begin_inset LatexCommand \index{function parameter}
16430
16431 \end_inset
16432
16433  onwards will be passed on the stack, the parameters are pushed from right
16434  to left i.e.
16435  after the call the leftmost parameter will be on the top of the stack.
16436  Here is an example:
16437 \end_layout
16438
16439 \begin_layout Verse
16440
16441 \family typewriter
16442 extern int asm_func(unsigned char, unsigned char);
16443 \newline
16444
16445 \newline
16446 int c_func (unsigned char
16447  i, unsigned char j) reentrant 
16448 \newline
16449
16450 \newline
16451 \InsetSpace ~
16452 \InsetSpace ~
16453 \InsetSpace ~
16454 \InsetSpace ~
16455 return asm_func(i,j); 
16456 \newline
16457
16458 \newline
16459
16460 \newline
16461 int main() 
16462 \newline
16463
16464 \newline
16465 \InsetSpace ~
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 return
16470  c_func(10,9); 
16471 \newline
16472 }
16473 \end_layout
16474
16475 \begin_layout Standard
16476 The corresponding assembler routine is:
16477 \end_layout
16478
16479 \begin_layout Verse
16480
16481 \family typewriter
16482 .globl _asm_func 
16483 \newline
16484 _asm_func: 
16485 \newline
16486 \InsetSpace ~
16487 \InsetSpace ~
16488 \InsetSpace ~
16489 \InsetSpace ~
16490 push  _bp 
16491 \newline
16492 \InsetSpace ~
16493 \InsetSpace ~
16494 \InsetSpace ~
16495 \InsetSpace ~
16496 mov _bp,sp 
16497 \newline
16498 \InsetSpace ~
16499 \InsetSpace ~
16500 \InsetSpace ~
16501 \InsetSpace ~
16502 mov r2,dpl
16503 \newline
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 mov a,_bp 
16509 \newline
16510 \InsetSpace ~
16511 \InsetSpace ~
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 add
16515  a,#0xfd 
16516 \newline
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 mov r0,a 
16522 \newline
16523 \InsetSpace ~
16524 \InsetSpace ~
16525 \InsetSpace ~
16526 \InsetSpace ~
16527 add  a,#0xfc ;?
16528 \newline
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 \InsetSpace ~
16532 \InsetSpace ~
16533 mov  r1,a 
16534 \newline
16535 \InsetSpace ~
16536 \InsetSpace ~
16537 \InsetSpace ~
16538 \InsetSpace ~
16539 mov  a,@r0 
16540 \newline
16541 \InsetSpace ~
16542 \InsetSpace ~
16543 \InsetSpace ~
16544 \InsetSpace ~
16545 add  a,r2 ;?
16546 \newline
16547 \InsetSpace ~
16548 \InsetSpace ~
16549 \InsetSpace ~
16550 \InsetSpace ~
16551 mov  dpl,a
16552  
16553 \newline
16554 \InsetSpace ~
16555 \InsetSpace ~
16556 \InsetSpace ~
16557 \InsetSpace ~
16558 mov  dph,#0x00 
16559 \newline
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 \InsetSpace ~
16564 mov  sp,_bp 
16565 \newline
16566 \InsetSpace ~
16567 \InsetSpace ~
16568 \InsetSpace ~
16569 \InsetSpace ~
16570 pop  _bp 
16571 \newline
16572 \InsetSpace ~
16573 \InsetSpace ~
16574 \InsetSpace ~
16575 \InsetSpace ~
16576 ret
16577 \end_layout
16578
16579 \begin_layout Standard
16580 The compiling and linking procedure remains the same, however note the extra
16581  entry & exit linkage required for the assembler code, _bp is the stack
16582  frame pointer and is used to compute the offset into the stack for parameters
16583  and local variables.
16584 \begin_inset VSpace bigskip
16585 \end_inset
16586
16587
16588 \end_layout
16589
16590 \begin_layout Section
16591 int (16 bit)
16592 \begin_inset LatexCommand \index{int (16 bit)}
16593
16594 \end_inset
16595
16596  and long (32 bit)
16597 \begin_inset LatexCommand \index{long (32 bit)}
16598
16599 \end_inset
16600
16601  Support
16602 \end_layout
16603
16604 \begin_layout Standard
16605 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
16606  multiplication and modulus operations are implemented by support routines.
16607  These support routines are all developed in ANSI-C to facilitate porting
16608  to other MCUs, although some model specific assembler optimizations are
16609  used.
16610  The following files contain the described routines, all of them can be
16611  found in <installdir>/share/sdcc/lib.
16612 \newline
16613
16614 \end_layout
16615
16616 \begin_layout Standard
16617 \align center
16618 \begin_inset Tabular
16619 <lyxtabular version="3" rows="11" columns="2">
16620 <features>
16621 <column alignment="left" valignment="top" leftline="true" width="0">
16622 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16623 <row topline="true" bottomline="true">
16624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16625 \begin_inset Text
16626
16627 \begin_layout Standard
16628
16629 \series bold
16630 Function
16631 \end_layout
16632
16633 \end_inset
16634 </cell>
16635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16636 \begin_inset Text
16637
16638 \begin_layout Standard
16639
16640 \series bold
16641 Description
16642 \end_layout
16643
16644 \end_inset
16645 </cell>
16646 </row>
16647 <row topline="true">
16648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16649 \begin_inset Text
16650
16651 \begin_layout Standard
16652 _mulint.c 
16653 \end_layout
16654
16655 \end_inset
16656 </cell>
16657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16658 \begin_inset Text
16659
16660 \begin_layout Standard
16661 16 bit multiplication
16662 \end_layout
16663
16664 \end_inset
16665 </cell>
16666 </row>
16667 <row topline="true">
16668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16669 \begin_inset Text
16670
16671 \begin_layout Standard
16672 _divsint.c 
16673 \end_layout
16674
16675 \end_inset
16676 </cell>
16677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16678 \begin_inset Text
16679
16680 \begin_layout Standard
16681  signed 16 bit division (calls _divuint)
16682 \end_layout
16683
16684 \end_inset
16685 </cell>
16686 </row>
16687 <row topline="true">
16688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16689 \begin_inset Text
16690
16691 \begin_layout Standard
16692 _divuint.c 
16693 \end_layout
16694
16695 \end_inset
16696 </cell>
16697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16698 \begin_inset Text
16699
16700 \begin_layout Standard
16701  unsigned 16 bit division
16702 \end_layout
16703
16704 \end_inset
16705 </cell>
16706 </row>
16707 <row topline="true">
16708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16709 \begin_inset Text
16710
16711 \begin_layout Standard
16712 _modsint.c
16713 \end_layout
16714
16715 \end_inset
16716 </cell>
16717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16718 \begin_inset Text
16719
16720 \begin_layout Standard
16721 signed 16 bit modulus (calls _moduint)
16722 \end_layout
16723
16724 \end_inset
16725 </cell>
16726 </row>
16727 <row topline="true">
16728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16729 \begin_inset Text
16730
16731 \begin_layout Standard
16732 _moduint.c
16733 \end_layout
16734
16735 \end_inset
16736 </cell>
16737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16738 \begin_inset Text
16739
16740 \begin_layout Standard
16741 unsigned 16 bit modulus
16742 \end_layout
16743
16744 \end_inset
16745 </cell>
16746 </row>
16747 <row topline="true">
16748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16749 \begin_inset Text
16750
16751 \begin_layout Standard
16752 _mullong.c
16753 \end_layout
16754
16755 \end_inset
16756 </cell>
16757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16758 \begin_inset Text
16759
16760 \begin_layout Standard
16761 32 bit multiplication
16762 \end_layout
16763
16764 \end_inset
16765 </cell>
16766 </row>
16767 <row topline="true">
16768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16769 \begin_inset Text
16770
16771 \begin_layout Standard
16772 _divslong.c 
16773 \end_layout
16774
16775 \end_inset
16776 </cell>
16777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16778 \begin_inset Text
16779
16780 \begin_layout Standard
16781  signed 32 division (calls _divulong)
16782 \end_layout
16783
16784 \end_inset
16785 </cell>
16786 </row>
16787 <row topline="true">
16788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16789 \begin_inset Text
16790
16791 \begin_layout Standard
16792 _divulong.c 
16793 \end_layout
16794
16795 \end_inset
16796 </cell>
16797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16798 \begin_inset Text
16799
16800 \begin_layout Standard
16801 unsigned 32 division
16802 \end_layout
16803
16804 \end_inset
16805 </cell>
16806 </row>
16807 <row topline="true">
16808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16809 \begin_inset Text
16810
16811 \begin_layout Standard
16812 _modslong.c
16813 \end_layout
16814
16815 \end_inset
16816 </cell>
16817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16818 \begin_inset Text
16819
16820 \begin_layout Standard
16821  signed 32 bit modulus (calls _modulong)
16822 \end_layout
16823
16824 \end_inset
16825 </cell>
16826 </row>
16827 <row topline="true" bottomline="true">
16828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16829 \begin_inset Text
16830
16831 \begin_layout Standard
16832 _modulong.c
16833 \end_layout
16834
16835 \end_inset
16836 </cell>
16837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16838 \begin_inset Text
16839
16840 \begin_layout Standard
16841 unsigned 32 bit modulus
16842 \end_layout
16843
16844 \end_inset
16845 </cell>
16846 </row>
16847 </lyxtabular>
16848
16849 \end_inset
16850
16851
16852 \newline
16853
16854 \end_layout
16855
16856 \begin_layout Standard
16857 Since they are compiled as 
16858 \emph on
16859 non-reentrant
16860 \emph default
16861
16862 \begin_inset LatexCommand \index{reentrant}
16863
16864 \end_inset
16865
16866 , interrupt
16867 \begin_inset LatexCommand \index{interrupt}
16868
16869 \end_inset
16870
16871  service routines should not do any of the above operations.
16872  If this is unavoidable then the above routines will need to be compiled
16873  with the 
16874 \emph on
16875 -
16876 \begin_inset ERT
16877 status collapsed
16878
16879 \begin_layout Standard
16880
16881
16882 \backslash
16883 /
16884 \end_layout
16885
16886 \end_inset
16887
16888 -stack-auto
16889 \begin_inset LatexCommand \index{-\/-stack-auto}
16890
16891 \end_inset
16892
16893
16894 \emph default
16895  option, after which the source program will have to be compiled with 
16896 \emph on
16897 -
16898 \begin_inset ERT
16899 status collapsed
16900
16901 \begin_layout Standard
16902
16903
16904 \backslash
16905 /
16906 \end_layout
16907
16908 \end_inset
16909
16910 -int-long-reent
16911 \begin_inset LatexCommand \index{-\/-int-long-reent}
16912
16913 \end_inset
16914
16915
16916 \emph default
16917  option.
16918  Notice that you don't have to call these routines directly.
16919  The compiler will use them automatically every time an integer operation
16920  is required.
16921 \end_layout
16922
16923 \begin_layout Section
16924 Floating Point Support
16925 \begin_inset LatexCommand \index{Floating point support}
16926
16927 \end_inset
16928
16929
16930 \end_layout
16931
16932 \begin_layout Standard
16933 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
16934  The floating point support routines are derived from gcc's floatlib.c and
16935  consist of the following routines:
16936 \newline
16937
16938 \end_layout
16939
16940 \begin_layout Standard
16941 \align center
16942
16943 \size footnotesize
16944 \begin_inset Tabular
16945 <lyxtabular version="3" rows="17" columns="2">
16946 <features>
16947 <column alignment="left" valignment="top" leftline="true" width="0">
16948 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16949 <row topline="true" bottomline="true">
16950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16951 \begin_inset Text
16952
16953 \begin_layout Standard
16954
16955 \family roman
16956 \series medium
16957 \shape up
16958 \size normal
16959 \emph off
16960 \bar no
16961 \noun off
16962 \color none
16963 Function 
16964 \end_layout
16965
16966 \end_inset
16967 </cell>
16968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16969 \begin_inset Text
16970
16971 \begin_layout Standard
16972 Description
16973 \end_layout
16974
16975 \end_inset
16976 </cell>
16977 </row>
16978 <row topline="true">
16979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16980 \begin_inset Text
16981
16982 \begin_layout Standard
16983
16984 \family roman
16985 \series medium
16986 \shape up
16987 \size normal
16988 \emph off
16989 \bar no
16990 \noun off
16991 \color none
16992 _fsadd.c
16993 \end_layout
16994
16995 \end_inset
16996 </cell>
16997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16998 \begin_inset Text
16999
17000 \begin_layout Standard
17001
17002 \family roman
17003 \series medium
17004 \shape up
17005 \size normal
17006 \emph off
17007 \bar no
17008 \noun off
17009 \color none
17010 add floating point numbers
17011 \end_layout
17012
17013 \end_inset
17014 </cell>
17015 </row>
17016 <row topline="true">
17017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17018 \begin_inset Text
17019
17020 \begin_layout Standard
17021
17022 \family roman
17023 \series medium
17024 \shape up
17025 \size normal
17026 \emph off
17027 \bar no
17028 \noun off
17029 \color none
17030 _fssub.c 
17031 \end_layout
17032
17033 \end_inset
17034 </cell>
17035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17036 \begin_inset Text
17037
17038 \begin_layout Standard
17039
17040 \family roman
17041 \series medium
17042 \shape up
17043 \size normal
17044 \emph off
17045 \bar no
17046 \noun off
17047 \color none
17048 subtract floating point numbers 
17049 \end_layout
17050
17051 \end_inset
17052 </cell>
17053 </row>
17054 <row topline="true">
17055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17056 \begin_inset Text
17057
17058 \begin_layout Standard
17059
17060 \family roman
17061 \series medium
17062 \shape up
17063 \size normal
17064 \emph off
17065 \bar no
17066 \noun off
17067 \color none
17068 _fsdiv.c 
17069 \end_layout
17070
17071 \end_inset
17072 </cell>
17073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17074 \begin_inset Text
17075
17076 \begin_layout Standard
17077
17078 \family roman
17079 \series medium
17080 \shape up
17081 \size normal
17082 \emph off
17083 \bar no
17084 \noun off
17085 \color none
17086 divide floating point numbers 
17087 \end_layout
17088
17089 \end_inset
17090 </cell>
17091 </row>
17092 <row topline="true">
17093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17094 \begin_inset Text
17095
17096 \begin_layout Standard
17097
17098 \family roman
17099 \series medium
17100 \shape up
17101 \size normal
17102 \emph off
17103 \bar no
17104 \noun off
17105 \color none
17106 _fsmul.c 
17107 \end_layout
17108
17109 \end_inset
17110 </cell>
17111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17112 \begin_inset Text
17113
17114 \begin_layout Standard
17115
17116 \family roman
17117 \series medium
17118 \shape up
17119 \size normal
17120 \emph off
17121 \bar no
17122 \noun off
17123 \color none
17124 multiply floating point numbers 
17125 \end_layout
17126
17127 \end_inset
17128 </cell>
17129 </row>
17130 <row topline="true">
17131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17132 \begin_inset Text
17133
17134 \begin_layout Standard
17135
17136 \family roman
17137 \series medium
17138 \shape up
17139 \size normal
17140 \emph off
17141 \bar no
17142 \noun off
17143 \color none
17144 _fs2uchar.c
17145 \end_layout
17146
17147 \end_inset
17148 </cell>
17149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17150 \begin_inset Text
17151
17152 \begin_layout Standard
17153
17154 \family roman
17155 \series medium
17156 \shape up
17157 \size normal
17158 \emph off
17159 \bar no
17160 \noun off
17161 \color none
17162 convert floating point to unsigned char
17163 \end_layout
17164
17165 \end_inset
17166 </cell>
17167 </row>
17168 <row topline="true">
17169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17170 \begin_inset Text
17171
17172 \begin_layout Standard
17173
17174 \family roman
17175 \series medium
17176 \shape up
17177 \size normal
17178 \emph off
17179 \bar no
17180 \noun off
17181 \color none
17182 _fs2char.c
17183 \end_layout
17184
17185 \end_inset
17186 </cell>
17187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17188 \begin_inset Text
17189
17190 \begin_layout Standard
17191
17192 \family roman
17193 \series medium
17194 \shape up
17195 \size normal
17196 \emph off
17197 \bar no
17198 \noun off
17199 \color none
17200 convert floating point to signed char
17201 \end_layout
17202
17203 \end_inset
17204 </cell>
17205 </row>
17206 <row topline="true">
17207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17208 \begin_inset Text
17209
17210 \begin_layout Standard
17211
17212 \family roman
17213 \series medium
17214 \shape up
17215 \size normal
17216 \emph off
17217 \bar no
17218 \noun off
17219 \color none
17220 _fs2uint.c
17221 \end_layout
17222
17223 \end_inset
17224 </cell>
17225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17226 \begin_inset Text
17227
17228 \begin_layout Standard
17229
17230 \family roman
17231 \series medium
17232 \shape up
17233 \size normal
17234 \emph off
17235 \bar no
17236 \noun off
17237 \color none
17238 convert floating point to unsigned int
17239 \end_layout
17240
17241 \end_inset
17242 </cell>
17243 </row>
17244 <row topline="true">
17245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17246 \begin_inset Text
17247
17248 \begin_layout Standard
17249
17250 \family roman
17251 \series medium
17252 \shape up
17253 \size normal
17254 \emph off
17255 \bar no
17256 \noun off
17257 \color none
17258 _fs2int.c
17259 \end_layout
17260
17261 \end_inset
17262 </cell>
17263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17264 \begin_inset Text
17265
17266 \begin_layout Standard
17267
17268 \family roman
17269 \series medium
17270 \shape up
17271 \size normal
17272 \emph off
17273 \bar no
17274 \noun off
17275 \color none
17276 convert floating point to signed int
17277 \end_layout
17278
17279 \end_inset
17280 </cell>
17281 </row>
17282 <row topline="true">
17283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17284 \begin_inset Text
17285
17286 \begin_layout Standard
17287
17288 \family roman
17289 \series medium
17290 \shape up
17291 \size normal
17292 \emph off
17293 \bar no
17294 \noun off
17295 \color none
17296 _fs2ulong.
17297 \family default
17298 \series default
17299 \shape default
17300 \size default
17301 \emph default
17302 \bar default
17303 \noun default
17304 \color default
17305 c
17306 \end_layout
17307
17308 \end_inset
17309 </cell>
17310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17311 \begin_inset Text
17312
17313 \begin_layout Standard
17314
17315 \family roman
17316 \series medium
17317 \shape up
17318 \size normal
17319 \emph off
17320 \bar no
17321 \noun off
17322 \color none
17323 convert floating point to unsigned long
17324 \end_layout
17325
17326 \end_inset
17327 </cell>
17328 </row>
17329 <row topline="true">
17330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17331 \begin_inset Text
17332
17333 \begin_layout Standard
17334
17335 \family roman
17336 \series medium
17337 \shape up
17338 \size normal
17339 \emph off
17340 \bar no
17341 \noun off
17342 \color none
17343 _fs2long.c
17344 \end_layout
17345
17346 \end_inset
17347 </cell>
17348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17349 \begin_inset Text
17350
17351 \begin_layout Standard
17352
17353 \family roman
17354 \series medium
17355 \shape up
17356 \size normal
17357 \emph off
17358 \bar no
17359 \noun off
17360 \color none
17361 convert floating point to signed long
17362 \end_layout
17363
17364 \end_inset
17365 </cell>
17366 </row>
17367 <row topline="true">
17368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17369 \begin_inset Text
17370
17371 \begin_layout Standard
17372
17373 \family roman
17374 \series medium
17375 \shape up
17376 \size normal
17377 \emph off
17378 \bar no
17379 \noun off
17380 \color none
17381 _uchar2fs.c
17382 \end_layout
17383
17384 \end_inset
17385 </cell>
17386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17387 \begin_inset Text
17388
17389 \begin_layout Standard
17390
17391 \family roman
17392 \series medium
17393 \shape up
17394 \size normal
17395 \emph off
17396 \bar no
17397 \noun off
17398 \color none
17399 convert unsigned char to floating point
17400 \end_layout
17401
17402 \end_inset
17403 </cell>
17404 </row>
17405 <row topline="true">
17406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17407 \begin_inset Text
17408
17409 \begin_layout Standard
17410
17411 \family roman
17412 \series medium
17413 \shape up
17414 \size normal
17415 \emph off
17416 \bar no
17417 \noun off
17418 \color none
17419 _char2fs.c
17420 \end_layout
17421
17422 \end_inset
17423 </cell>
17424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17425 \begin_inset Text
17426
17427 \begin_layout Standard
17428
17429 \family roman
17430 \series medium
17431 \shape up
17432 \size normal
17433 \emph off
17434 \bar no
17435 \noun off
17436 \color none
17437 convert char to floating point number
17438 \end_layout
17439
17440 \end_inset
17441 </cell>
17442 </row>
17443 <row topline="true">
17444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17445 \begin_inset Text
17446
17447 \begin_layout Standard
17448
17449 \family roman
17450 \series medium
17451 \shape up
17452 \size normal
17453 \emph off
17454 \bar no
17455 \noun off
17456 \color none
17457 _uint2fs.c
17458 \end_layout
17459
17460 \end_inset
17461 </cell>
17462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17463 \begin_inset Text
17464
17465 \begin_layout Standard
17466
17467 \family roman
17468 \series medium
17469 \shape up
17470 \size normal
17471 \emph off
17472 \bar no
17473 \noun off
17474 \color none
17475 convert unsigned int to floating point
17476 \end_layout
17477
17478 \end_inset
17479 </cell>
17480 </row>
17481 <row topline="true">
17482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17483 \begin_inset Text
17484
17485 \begin_layout Standard
17486
17487 \family roman
17488 \series medium
17489 \shape up
17490 \size normal
17491 \emph off
17492 \bar no
17493 \noun off
17494 \color none
17495 _int2fs.c
17496 \end_layout
17497
17498 \end_inset
17499 </cell>
17500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17501 \begin_inset Text
17502
17503 \begin_layout Standard
17504
17505 \family roman
17506 \series medium
17507 \shape up
17508 \size normal
17509 \emph off
17510 \bar no
17511 \noun off
17512 \color none
17513 convert int to floating point numbers
17514 \end_layout
17515
17516 \end_inset
17517 </cell>
17518 </row>
17519 <row topline="true">
17520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17521 \begin_inset Text
17522
17523 \begin_layout Standard
17524
17525 \family roman
17526 \series medium
17527 \shape up
17528 \size normal
17529 \emph off
17530 \bar no
17531 \noun off
17532 \color none
17533 _ulong2fs.c
17534 \end_layout
17535
17536 \end_inset
17537 </cell>
17538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17539 \begin_inset Text
17540
17541 \begin_layout Standard
17542
17543 \family roman
17544 \series medium
17545 \shape up
17546 \size normal
17547 \emph off
17548 \bar no
17549 \noun off
17550 \color none
17551 convert unsigned long to floating point number
17552 \end_layout
17553
17554 \end_inset
17555 </cell>
17556 </row>
17557 <row topline="true" bottomline="true">
17558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17559 \begin_inset Text
17560
17561 \begin_layout Standard
17562
17563 \family roman
17564 \series medium
17565 \shape up
17566 \size normal
17567 \emph off
17568 \bar no
17569 \noun off
17570 \color none
17571 _long2fs.c
17572 \end_layout
17573
17574 \end_inset
17575 </cell>
17576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17577 \begin_inset Text
17578
17579 \begin_layout Standard
17580
17581 \family roman
17582 \series medium
17583 \shape up
17584 \size normal
17585 \emph off
17586 \bar no
17587 \noun off
17588 \color none
17589 convert long to floating point number
17590 \end_layout
17591
17592 \end_inset
17593 </cell>
17594 </row>
17595 </lyxtabular>
17596
17597 \end_inset
17598
17599
17600 \newline
17601
17602 \end_layout
17603
17604 \begin_layout Standard
17605 These support routines are developed in ANSI-C so there is room for space
17606  and speed improvement
17607 \begin_inset Foot
17608 status open
17609
17610 \begin_layout Standard
17611 These floating point routines (
17612 \emph on
17613 not
17614 \emph default
17615  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
17616  
17617 \end_layout
17618
17619 \end_inset
17620
17621 .
17622  Note if all these routines are used simultaneously the data space might
17623  overflow.
17624  For serious floating point usage the large model might be needed.
17625  Also notice that you don't have to call this routines directly.
17626  The compiler will use them automatically every time a floating point operation
17627  is required.
17628 \begin_inset VSpace bigskip
17629 \end_inset
17630
17631
17632 \end_layout
17633
17634 \begin_layout Section
17635 Library Routines
17636 \begin_inset LatexCommand \index{Libraries}
17637
17638 \end_inset
17639
17640
17641 \end_layout
17642
17643 \begin_layout Standard
17644
17645 \emph on
17646 <pending: this is messy and incomplete - a little more information is in
17647  sdcc/doc/libdoc.txt
17648 \emph default
17649  >
17650 \end_layout
17651
17652 \begin_layout Subsection
17653 Compiler support routines (_gptrget, _mulint etc.)
17654 \end_layout
17655
17656 \begin_layout Subsection
17657 Stdclib functions (puts, printf, strcat etc.)
17658 \end_layout
17659
17660 \begin_layout Subsubsection
17661 <stdio.h>
17662 \end_layout
17663
17664 \begin_layout Paragraph
17665 getchar(), putchar()
17666 \end_layout
17667
17668 \begin_layout Standard
17669 \begin_inset LatexCommand \index{<stdio.h>}
17670
17671 \end_inset
17672
17673 As usual on embedded systems you have to provide your own 
17674 \family typewriter
17675 getchar()
17676 \begin_inset LatexCommand \index{getchar()}
17677
17678 \end_inset
17679
17680  
17681 \family default
17682 and 
17683 \family typewriter
17684 putchar()
17685 \begin_inset LatexCommand \index{putchar()}
17686
17687 \end_inset
17688
17689
17690 \family default
17691  routines.
17692  SDCC does not know whether the system connects to a serial line with or
17693  without handshake, LCD, keyboard or other device.
17694  And whether a 
17695 \family typewriter
17696 lf
17697 \family default
17698  to 
17699 \family typewriter
17700 crlf
17701 \family default
17702  conversion within 
17703 \family typewriter
17704 putchar()
17705 \family default
17706  is intended.
17707  You'll find examples for serial routines f.e.
17708  in sdcc/device/lib.
17709  For the mcs51 this minimalistic polling 
17710 \family typewriter
17711 putchar()
17712 \family default
17713  routine might be a start:
17714 \end_layout
17715
17716 \begin_layout Verse
17717
17718 \family typewriter
17719 void putchar (char c) { 
17720 \newline
17721 \InsetSpace ~
17722 \InsetSpace ~
17723 \InsetSpace ~
17724 \InsetSpace ~
17725 while (!TI)\InsetSpace ~
17726 \InsetSpace ~
17727 \InsetSpace ~
17728  /* assumes UART is initialized */
17729 \newline
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 \InsetSpace ~
17735 \InsetSpace ~
17736 \InsetSpace ~
17737 \InsetSpace ~
17738 ;
17739 \newline
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 TI
17745  = 0;
17746 \newline
17747 \InsetSpace ~
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 SBUF = c;
17752 \newline
17753 }
17754 \end_layout
17755
17756 \begin_layout Paragraph
17757 printf()
17758 \end_layout
17759
17760 \begin_layout Standard
17761 The default
17762 \family typewriter
17763  printf()
17764 \begin_inset LatexCommand \index{printf()}
17765
17766 \end_inset
17767
17768
17769 \family default
17770  implementation in
17771 \family typewriter
17772  printf_large.c
17773 \family default
17774  does not support float (except on ds390).
17775  To enable this recompile it with the option 
17776 \emph on
17777 -
17778 \begin_inset ERT
17779 status collapsed
17780
17781 \begin_layout Standard
17782
17783
17784 \backslash
17785 /
17786 \end_layout
17787
17788 \end_inset
17789
17790 DUSE_FLOATS=1
17791 \begin_inset LatexCommand \index{USE\_FLOATS}
17792
17793 \end_inset
17794
17795
17796 \emph default
17797  on the command line.
17798  Use
17799 \emph on
17800  -
17801 \begin_inset ERT
17802 status collapsed
17803
17804 \begin_layout Standard
17805
17806
17807 \backslash
17808 /
17809 \end_layout
17810
17811 \end_inset
17812
17813 -model-large
17814 \begin_inset LatexCommand \index{-\/-model-large}
17815
17816 \end_inset
17817
17818
17819 \emph default
17820  for the mcs51 port, since this uses a lot of memory.
17821 \end_layout
17822
17823 \begin_layout Standard
17824 If you're short on code memory you might want to use 
17825 \family typewriter
17826 printf_small()
17827 \begin_inset LatexCommand \index{printf\_small()}
17828
17829 \end_inset
17830
17831
17832 \family default
17833  
17834 \emph on
17835 instead
17836 \emph default
17837  of
17838 \family typewriter
17839  printf().
17840
17841 \family default
17842  For the mcs51 there additionally are assembly versions 
17843 \family typewriter
17844 printf_tiny()
17845 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
17846
17847 \end_inset
17848
17849
17850 \family default
17851  (subset of printf using less than 270 bytes) and 
17852 \family typewriter
17853 printf_fast()
17854 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
17855
17856 \end_inset
17857
17858  
17859 \family default
17860 and
17861 \family typewriter
17862  printf_fast_f()
17863 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
17864
17865 \end_inset
17866
17867
17868 \family default
17869  (floating-point aware version of printf_fast) which should fit the requirements
17870  of many embedded systems (printf_fast() can be customized by unsetting
17871  #defines to 
17872 \emph on
17873 not
17874 \emph default
17875  support long variables and field widths).
17876  Be shure to only use only one of these printf options within a project.
17877 \newline
17878
17879 \end_layout
17880
17881 \begin_layout Standard
17882 Feature matrix of different 
17883 \emph on
17884 printf
17885 \emph default
17886  options on mcs51.
17887 \end_layout
17888
17889 \begin_layout Standard
17890 \begin_inset Tabular
17891 <lyxtabular version="3" rows="14" columns="7">
17892 <features islongtable="true">
17893 <column alignment="left" valignment="middle" leftline="true" width="14col%">
17894 <column alignment="center" valignment="top" leftline="true" width="0">
17895 <column alignment="center" valignment="top" leftline="true" width="12col%">
17896 <column alignment="center" valignment="top" leftline="true" width="10col%">
17897 <column alignment="center" valignment="top" leftline="true" width="0">
17898 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
17899 <column alignment="center" valignment="top" rightline="true" width="0">
17900 <row topline="true" bottomline="true" endhead="true">
17901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17902 \begin_inset Text
17903
17904 \begin_layout Standard
17905
17906 \series bold
17907 \size large
17908 mcs51
17909 \end_layout
17910
17911 \end_inset
17912 </cell>
17913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17914 \begin_inset Text
17915
17916 \begin_layout Standard
17917 printf
17918 \begin_inset LatexCommand \index{printf}
17919
17920 \end_inset
17921
17922
17923 \end_layout
17924
17925 \end_inset
17926 </cell>
17927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17928 \begin_inset Text
17929
17930 \begin_layout Standard
17931 printf 
17932 \size scriptsize
17933 USE_FLOATS=1
17934 \end_layout
17935
17936 \end_inset
17937 </cell>
17938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17939 \begin_inset Text
17940
17941 \begin_layout Standard
17942 printf_small
17943 \end_layout
17944
17945 \end_inset
17946 </cell>
17947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17948 \begin_inset Text
17949
17950 \begin_layout Standard
17951 printf_fast
17952 \end_layout
17953
17954 \end_inset
17955 </cell>
17956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17957 \begin_inset Text
17958
17959 \begin_layout Standard
17960 printf_fast_f
17961 \end_layout
17962
17963 \end_inset
17964 </cell>
17965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17966 \begin_inset Text
17967
17968 \begin_layout Standard
17969 printf_tiny
17970 \end_layout
17971
17972 \end_inset
17973 </cell>
17974 </row>
17975 <row topline="true" endhead="true">
17976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17977 \begin_inset Text
17978
17979 \begin_layout Standard
17980 filename
17981 \end_layout
17982
17983 \end_inset
17984 </cell>
17985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17986 \begin_inset Text
17987
17988 \begin_layout Standard
17989
17990 \size scriptsize
17991 printf_large.c
17992 \end_layout
17993
17994 \end_inset
17995 </cell>
17996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17997 \begin_inset Text
17998
17999 \begin_layout Standard
18000
18001 \size scriptsize
18002 printf_large.c
18003 \end_layout
18004
18005 \end_inset
18006 </cell>
18007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18008 \begin_inset Text
18009
18010 \begin_layout Standard
18011
18012 \size scriptsize
18013 printfl.c
18014 \end_layout
18015
18016 \end_inset
18017 </cell>
18018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18019 \begin_inset Text
18020
18021 \begin_layout Standard
18022
18023 \size scriptsize
18024 printf_fast.c
18025 \end_layout
18026
18027 \end_inset
18028 </cell>
18029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18030 \begin_inset Text
18031
18032 \begin_layout Standard
18033
18034 \size scriptsize
18035 printf_fast_f.c
18036 \end_layout
18037
18038 \end_inset
18039 </cell>
18040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18041 \begin_inset Text
18042
18043 \begin_layout Standard
18044
18045 \size scriptsize
18046 printf_tiny.c
18047 \end_layout
18048
18049 \end_inset
18050 </cell>
18051 </row>
18052 <row topline="true" endhead="true">
18053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18054 \begin_inset Text
18055
18056 \begin_layout Standard
18057 \begin_inset Quotes sld
18058 \end_inset
18059
18060 Hello World
18061 \begin_inset Quotes srd
18062 \end_inset
18063
18064  size
18065 \end_layout
18066
18067 \begin_layout Standard
18068 small / large
18069 \end_layout
18070
18071 \end_inset
18072 </cell>
18073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18074 \begin_inset Text
18075
18076 \begin_layout Standard
18077 1.7k / 2.4k
18078 \end_layout
18079
18080 \end_inset
18081 </cell>
18082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18083 \begin_inset Text
18084
18085 \begin_layout Standard
18086 4.3k / 5.6k
18087 \end_layout
18088
18089 \end_inset
18090 </cell>
18091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18092 \begin_inset Text
18093
18094 \begin_layout Standard
18095 1.2k / 1.8k
18096 \end_layout
18097
18098 \end_inset
18099 </cell>
18100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18101 \begin_inset Text
18102
18103 \begin_layout Standard
18104 1.3k / 1.3k
18105 \end_layout
18106
18107 \end_inset
18108 </cell>
18109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18110 \begin_inset Text
18111
18112 \begin_layout Standard
18113 1.9k / 1.9k
18114 \end_layout
18115
18116 \end_inset
18117 </cell>
18118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18119 \begin_inset Text
18120
18121 \begin_layout Standard
18122 0.44k / 0.44k
18123 \end_layout
18124
18125 \end_inset
18126 </cell>
18127 </row>
18128 <row topline="true" endhead="true">
18129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18130 \begin_inset Text
18131
18132 \begin_layout Standard
18133 code size
18134 \end_layout
18135
18136 \begin_layout Standard
18137 small / large
18138 \end_layout
18139
18140 \end_inset
18141 </cell>
18142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18143 \begin_inset Text
18144
18145 \begin_layout Standard
18146 1.4k / 2.0k
18147 \end_layout
18148
18149 \end_inset
18150 </cell>
18151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18152 \begin_inset Text
18153
18154 \begin_layout Standard
18155 2.8k / 3.7k
18156 \end_layout
18157
18158 \end_inset
18159 </cell>
18160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18161 \begin_inset Text
18162
18163 \begin_layout Standard
18164 0.45k / 0.47k (+ _ltoa)
18165 \end_layout
18166
18167 \end_inset
18168 </cell>
18169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18170 \begin_inset Text
18171
18172 \begin_layout Standard
18173 1.2k / 1.2k
18174 \end_layout
18175
18176 \end_inset
18177 </cell>
18178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18179 \begin_inset Text
18180
18181 \begin_layout Standard
18182 1.6k / 1.6k
18183 \end_layout
18184
18185 \end_inset
18186 </cell>
18187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18188 \begin_inset Text
18189
18190 \begin_layout Standard
18191 0.26k / 0.26k
18192 \end_layout
18193
18194 \end_inset
18195 </cell>
18196 </row>
18197 <row topline="true">
18198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18199 \begin_inset Text
18200
18201 \begin_layout Standard
18202 formats
18203 \end_layout
18204
18205 \end_inset
18206 </cell>
18207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18208 \begin_inset Text
18209
18210 \begin_layout Standard
18211 cdi
18212 \emph on
18213 o
18214 \emph default
18215 psux
18216 \end_layout
18217
18218 \end_inset
18219 </cell>
18220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18221 \begin_inset Text
18222
18223 \begin_layout Standard
18224
18225 \family roman
18226 \series medium
18227 \shape up
18228 \size normal
18229 \emph off
18230 \bar no
18231 \noun off
18232 \color none
18233 cd
18234 \family default
18235 \series default
18236 \shape default
18237 \size default
18238 \emph default
18239 \bar default
18240 \noun default
18241 \color default
18242 f
18243 \family roman
18244 \series medium
18245 \shape up
18246 \size normal
18247 \emph off
18248 \bar no
18249 \noun off
18250 \color none
18251 i
18252 \family default
18253 \series default
18254 \shape default
18255 \size default
18256 \emph on
18257 \bar default
18258 \noun default
18259 \color default
18260 o
18261 \family roman
18262 \series medium
18263 \shape up
18264 \size normal
18265 \emph off
18266 \bar no
18267 \noun off
18268 \color none
18269 psux
18270 \end_layout
18271
18272 \end_inset
18273 </cell>
18274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18275 \begin_inset Text
18276
18277 \begin_layout Standard
18278 c
18279 \family roman
18280 \series medium
18281 \shape up
18282 \size normal
18283 \emph off
18284 \bar no
18285 \noun off
18286 \color none
18287 d
18288 \family default
18289 \series default
18290 \shape default
18291 \size default
18292 \emph on
18293 \bar default
18294 \noun default
18295 \color default
18296 o
18297 \family roman
18298 \series medium
18299 \shape up
18300 \size normal
18301 \emph off
18302 \bar no
18303 \noun off
18304 \color none
18305 s
18306 \family default
18307 \series default
18308 \shape default
18309 \size default
18310 \emph default
18311 \bar default
18312 \noun default
18313 \color default
18314 x
18315 \end_layout
18316
18317 \end_inset
18318 </cell>
18319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18320 \begin_inset Text
18321
18322 \begin_layout Standard
18323 cdsux
18324 \end_layout
18325
18326 \end_inset
18327 </cell>
18328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18329 \begin_inset Text
18330
18331 \begin_layout Standard
18332 cdfsux
18333 \end_layout
18334
18335 \end_inset
18336 </cell>
18337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18338 \begin_inset Text
18339
18340 \begin_layout Standard
18341 cdsux
18342 \end_layout
18343
18344 \end_inset
18345 </cell>
18346 </row>
18347 <row topline="true">
18348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18349 \begin_inset Text
18350
18351 \begin_layout Standard
18352 long (32 bit) support
18353 \end_layout
18354
18355 \end_inset
18356 </cell>
18357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18358 \begin_inset Text
18359
18360 \begin_layout Standard
18361 x
18362 \end_layout
18363
18364 \end_inset
18365 </cell>
18366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18367 \begin_inset Text
18368
18369 \begin_layout Standard
18370 x
18371 \end_layout
18372
18373 \end_inset
18374 </cell>
18375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18376 \begin_inset Text
18377
18378 \begin_layout Standard
18379 x
18380 \end_layout
18381
18382 \end_inset
18383 </cell>
18384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18385 \begin_inset Text
18386
18387 \begin_layout Standard
18388 x
18389 \end_layout
18390
18391 \end_inset
18392 </cell>
18393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18394 \begin_inset Text
18395
18396 \begin_layout Standard
18397
18398 \family roman
18399 \series medium
18400 \shape up
18401 \size normal
18402 \emph off
18403 \bar no
18404 \noun off
18405 \color none
18406 x
18407 \end_layout
18408
18409 \end_inset
18410 </cell>
18411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18412 \begin_inset Text
18413
18414 \begin_layout Standard
18415 -
18416 \end_layout
18417
18418 \end_inset
18419 </cell>
18420 </row>
18421 <row topline="true">
18422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18423 \begin_inset Text
18424
18425 \begin_layout Standard
18426 byte arguments on stack
18427 \end_layout
18428
18429 \end_inset
18430 </cell>
18431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18432 \begin_inset Text
18433
18434 \begin_layout Standard
18435 b
18436 \end_layout
18437
18438 \end_inset
18439 </cell>
18440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18441 \begin_inset Text
18442
18443 \begin_layout Standard
18444 b
18445 \end_layout
18446
18447 \end_inset
18448 </cell>
18449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18450 \begin_inset Text
18451
18452 \begin_layout Standard
18453 -
18454 \end_layout
18455
18456 \end_inset
18457 </cell>
18458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18459 \begin_inset Text
18460
18461 \begin_layout Standard
18462 -
18463 \end_layout
18464
18465 \end_inset
18466 </cell>
18467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18468 \begin_inset Text
18469
18470 \begin_layout Standard
18471 -
18472 \end_layout
18473
18474 \end_inset
18475 </cell>
18476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18477 \begin_inset Text
18478
18479 \begin_layout Standard
18480 -
18481 \end_layout
18482
18483 \end_inset
18484 </cell>
18485 </row>
18486 <row topline="true">
18487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18488 \begin_inset Text
18489
18490 \begin_layout Standard
18491 float format
18492 \begin_inset LatexCommand \index{Floating point support}
18493
18494 \end_inset
18495
18496
18497 \end_layout
18498
18499 \end_inset
18500 </cell>
18501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18502 \begin_inset Text
18503
18504 \begin_layout Standard
18505 -
18506 \end_layout
18507
18508 \end_inset
18509 </cell>
18510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18511 \begin_inset Text
18512
18513 \begin_layout Standard
18514 %f
18515 \end_layout
18516
18517 \end_inset
18518 </cell>
18519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18520 \begin_inset Text
18521
18522 \begin_layout Standard
18523 -
18524 \end_layout
18525
18526 \end_inset
18527 </cell>
18528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18529 \begin_inset Text
18530
18531 \begin_layout Standard
18532 -
18533 \end_layout
18534
18535 \end_inset
18536 </cell>
18537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18538 \begin_inset Text
18539
18540 \begin_layout Standard
18541 %f
18542 \begin_inset Foot
18543 status collapsed
18544
18545 \begin_layout Standard
18546 Range limited to +/- 4294967040
18547 \end_layout
18548
18549 \end_inset
18550
18551
18552 \end_layout
18553
18554 \end_inset
18555 </cell>
18556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18557 \begin_inset Text
18558
18559 \begin_layout Standard
18560 -
18561 \end_layout
18562
18563 \end_inset
18564 </cell>
18565 </row>
18566 <row topline="true">
18567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18568 \begin_inset Text
18569
18570 \begin_layout Standard
18571 float formats %e %g
18572 \end_layout
18573
18574 \end_inset
18575 </cell>
18576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18577 \begin_inset Text
18578
18579 \begin_layout Standard
18580 -
18581 \end_layout
18582
18583 \end_inset
18584 </cell>
18585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18586 \begin_inset Text
18587
18588 \begin_layout Standard
18589 -
18590 \end_layout
18591
18592 \end_inset
18593 </cell>
18594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18595 \begin_inset Text
18596
18597 \begin_layout Standard
18598 -
18599 \end_layout
18600
18601 \end_inset
18602 </cell>
18603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18604 \begin_inset Text
18605
18606 \begin_layout Standard
18607 -
18608 \end_layout
18609
18610 \end_inset
18611 </cell>
18612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18613 \begin_inset Text
18614
18615 \begin_layout Standard
18616 -
18617 \end_layout
18618
18619 \end_inset
18620 </cell>
18621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18622 \begin_inset Text
18623
18624 \begin_layout Standard
18625 -
18626 \end_layout
18627
18628 \end_inset
18629 </cell>
18630 </row>
18631 <row topline="true" bottomline="true">
18632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18633 \begin_inset Text
18634
18635 \begin_layout Standard
18636 field width
18637 \end_layout
18638
18639 \end_inset
18640 </cell>
18641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18642 \begin_inset Text
18643
18644 \begin_layout Standard
18645 x
18646 \end_layout
18647
18648 \end_inset
18649 </cell>
18650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18651 \begin_inset Text
18652
18653 \begin_layout Standard
18654 x
18655 \end_layout
18656
18657 \end_inset
18658 </cell>
18659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18660 \begin_inset Text
18661
18662 \begin_layout Standard
18663 -
18664 \end_layout
18665
18666 \end_inset
18667 </cell>
18668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18669 \begin_inset Text
18670
18671 \begin_layout Standard
18672 x
18673 \end_layout
18674
18675 \end_inset
18676 </cell>
18677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18678 \begin_inset Text
18679
18680 \begin_layout Standard
18681 x
18682 \end_layout
18683
18684 \end_inset
18685 </cell>
18686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18687 \begin_inset Text
18688
18689 \begin_layout Standard
18690 -
18691 \end_layout
18692
18693 \end_inset
18694 </cell>
18695 </row>
18696 <row bottomline="true">
18697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18698 \begin_inset Text
18699
18700 \begin_layout Standard
18701 string speed
18702 \begin_inset Foot
18703 status collapsed
18704
18705 \begin_layout Standard
18706 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
18707 \backslash
18708 r', '
18709 \backslash
18710 n'); standard 8051 @ 22.1184 MHz, empty putchar()
18711 \end_layout
18712
18713 \end_inset
18714
18715 ,
18716 \end_layout
18717
18718 \begin_layout Standard
18719 small / large
18720 \end_layout
18721
18722 \end_inset
18723 </cell>
18724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18725 \begin_inset Text
18726
18727 \begin_layout Standard
18728 1.52 / 2.59 ms
18729 \end_layout
18730
18731 \end_inset
18732 </cell>
18733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18734 \begin_inset Text
18735
18736 \begin_layout Standard
18737 1.53 / 2.62 ms
18738 \end_layout
18739
18740 \end_inset
18741 </cell>
18742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18743 \begin_inset Text
18744
18745 \begin_layout Standard
18746 0.92 / 0.93 ms
18747 \end_layout
18748
18749 \end_inset
18750 </cell>
18751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18752 \begin_inset Text
18753
18754 \begin_layout Standard
18755 0.45 / 0.45 ms
18756 \end_layout
18757
18758 \end_inset
18759 </cell>
18760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18761 \begin_inset Text
18762
18763 \begin_layout Standard
18764 0.46 / 0.46 ms
18765 \end_layout
18766
18767 \end_inset
18768 </cell>
18769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18770 \begin_inset Text
18771
18772 \begin_layout Standard
18773 0.45 / 0.45 ms
18774 \end_layout
18775
18776 \end_inset
18777 </cell>
18778 </row>
18779 <row bottomline="true">
18780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18781 \begin_inset Text
18782
18783 \begin_layout Standard
18784 int speed
18785 \begin_inset Foot
18786 status collapsed
18787
18788 \begin_layout Standard
18789 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
18790  putchar()
18791 \end_layout
18792
18793 \end_inset
18794
18795 ,
18796 \end_layout
18797
18798 \begin_layout Standard
18799 small / large
18800 \end_layout
18801
18802 \end_inset
18803 </cell>
18804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18805 \begin_inset Text
18806
18807 \begin_layout Standard
18808 3.01 / 3.61 ms
18809 \end_layout
18810
18811 \end_inset
18812 </cell>
18813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18814 \begin_inset Text
18815
18816 \begin_layout Standard
18817 3.01 / 3.61 ms
18818 \end_layout
18819
18820 \end_inset
18821 </cell>
18822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18823 \begin_inset Text
18824
18825 \begin_layout Standard
18826 3.51 / 18.13 ms
18827 \end_layout
18828
18829 \end_inset
18830 </cell>
18831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18832 \begin_inset Text
18833
18834 \begin_layout Standard
18835 0.22 / 0.22 ms
18836 \end_layout
18837
18838 \end_inset
18839 </cell>
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18841 \begin_inset Text
18842
18843 \begin_layout Standard
18844 0.23 / 0.23 ms
18845 \end_layout
18846
18847 \end_inset
18848 </cell>
18849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18850 \begin_inset Text
18851
18852 \begin_layout Standard
18853 0.25 / 0.25 ms
18854 \end_layout
18855
18856 \end_inset
18857 </cell>
18858 </row>
18859 <row bottomline="true">
18860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18861 \begin_inset Text
18862
18863 \begin_layout Standard
18864 long speed
18865 \begin_inset Foot
18866 status collapsed
18867
18868 \begin_layout Standard
18869 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
18870  empty putchar()
18871 \end_layout
18872
18873 \end_inset
18874
18875 ,
18876 \end_layout
18877
18878 \begin_layout Standard
18879 small / large
18880 \end_layout
18881
18882 \end_inset
18883 </cell>
18884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18885 \begin_inset Text
18886
18887 \begin_layout Standard
18888 5.37 / 6.31 ms
18889 \end_layout
18890
18891 \end_inset
18892 </cell>
18893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18894 \begin_inset Text
18895
18896 \begin_layout Standard
18897 5.37 / 6.31 ms
18898 \end_layout
18899
18900 \end_inset
18901 </cell>
18902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18903 \begin_inset Text
18904
18905 \begin_layout Standard
18906 8.71 / 40.65 ms
18907 \end_layout
18908
18909 \end_inset
18910 </cell>
18911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18912 \begin_inset Text
18913
18914 \begin_layout Standard
18915 0.40 / 0.40 ms
18916 \end_layout
18917
18918 \end_inset
18919 </cell>
18920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18921 \begin_inset Text
18922
18923 \begin_layout Standard
18924 0.40 / 0.40 ms
18925 \end_layout
18926
18927 \end_inset
18928 </cell>
18929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18930 \begin_inset Text
18931
18932 \begin_layout Standard
18933 -
18934 \end_layout
18935
18936 \end_inset
18937 </cell>
18938 </row>
18939 <row bottomline="true">
18940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18941 \begin_inset Text
18942
18943 \begin_layout Standard
18944 float speed
18945 \begin_inset Foot
18946 status collapsed
18947
18948 \begin_layout Standard
18949 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18950  empty putchar()
18951 \end_layout
18952
18953 \end_inset
18954
18955 ,
18956 \end_layout
18957
18958 \begin_layout Standard
18959 small / large
18960 \end_layout
18961
18962 \end_inset
18963 </cell>
18964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18965 \begin_inset Text
18966
18967 \begin_layout Standard
18968 -
18969 \end_layout
18970
18971 \end_inset
18972 </cell>
18973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18974 \begin_inset Text
18975
18976 \begin_layout Standard
18977 7.49 / 22.47 ms
18978 \end_layout
18979
18980 \end_inset
18981 </cell>
18982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18983 \begin_inset Text
18984
18985 \begin_layout Standard
18986 -
18987 \end_layout
18988
18989 \end_inset
18990 </cell>
18991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18992 \begin_inset Text
18993
18994 \begin_layout Standard
18995 -
18996 \end_layout
18997
18998 \end_inset
18999 </cell>
19000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19001 \begin_inset Text
19002
19003 \begin_layout Standard
19004 1.04 / 1.04 ms
19005 \end_layout
19006
19007 \end_inset
19008 </cell>
19009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19010 \begin_inset Text
19011
19012 \begin_layout Standard
19013 -
19014 \end_layout
19015
19016 \end_inset
19017 </cell>
19018 </row>
19019 </lyxtabular>
19020
19021 \end_inset
19022
19023
19024 \end_layout
19025
19026 \begin_layout Subsubsection
19027 <malloc.h>
19028 \begin_inset LatexCommand \index{malloc.h}
19029
19030 \end_inset
19031
19032
19033 \end_layout
19034
19035 \begin_layout Standard
19036 As of SDCC 2.6.2 you no longer need to call an initialization routine before
19037  using dynamic memory allocation
19038 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
19039
19040 \end_inset
19041
19042  and a default heap
19043 \begin_inset LatexCommand \index{heap (malloc)}
19044
19045 \end_inset
19046
19047  space of 1024 bytes is provided for malloc to allocate memory from.
19048  If you need a different heap size you need to recompile _heap.c with the
19049  required size defined in HEAP_SIZE.
19050  It is recommended to make a copy of this file into your project directory
19051  and compile it there with:
19052 \end_layout
19053
19054 \begin_layout Verse
19055
19056 \family typewriter
19057 sdcc -c _heap.c -D HEAD_SIZE=2048
19058 \end_layout
19059
19060 \begin_layout Standard
19061 And then link it with:
19062 \end_layout
19063
19064 \begin_layout Verse
19065
19066 \family typewriter
19067 sdcc main.rel _heap.rel
19068 \end_layout
19069
19070 \begin_layout Subsection
19071 Math functions (sinf, powf, sqrtf etc.)
19072 \end_layout
19073
19074 \begin_layout Subsubsection
19075 <math.h>
19076 \end_layout
19077
19078 \begin_layout Standard
19079 See definitions in file <math.h>.
19080 \end_layout
19081
19082 \begin_layout Subsection
19083 Other libraries
19084 \end_layout
19085
19086 \begin_layout Standard
19087 Libraries
19088 \begin_inset LatexCommand \index{Libraries}
19089
19090 \end_inset
19091
19092  included in SDCC should have a license at least as liberal as the GNU Lesser
19093  General Public License
19094 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
19095
19096 \end_inset
19097
19098  
19099 \emph on
19100 LGPL
19101 \emph default
19102 .
19103 \end_layout
19104
19105 \begin_layout Standard
19106 \begin_inset Note Comment
19107 status collapsed
19108
19109 \begin_layout Standard
19110 license statements for the libraries are missing.
19111  sdcc/device/lib/ser_ir.c
19112 \end_layout
19113
19114 \begin_layout Standard
19115 or _decdptr f.e.
19116  come with a GPL (as opposed to LGPL) License - this will not be liberal
19117  enough for many embedded programmers.
19118 \end_layout
19119
19120 \end_inset
19121
19122
19123 \end_layout
19124
19125 \begin_layout Standard
19126 If you have ported some library or want to share experience about some code
19127  which f.e.
19128  falls into any of these categories Busses (I
19129 \begin_inset Formula $^{\textrm{2}}$
19130 \end_inset
19131
19132 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
19133  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
19134  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
19135 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
19136
19137 \end_inset
19138
19139 \InsetSpace ~
19140 would certainly like to hear about it.
19141 \end_layout
19142
19143 \begin_layout Standard
19144 Programmers coding for embedded systems are not especially famous for being
19145  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
19146 e these references are very valuable.
19147  Let's help to create a climate where information is shared.
19148 \begin_inset VSpace bigskip
19149 \end_inset
19150
19151
19152 \end_layout
19153
19154 \begin_layout Section
19155 Memory Models
19156 \end_layout
19157
19158 \begin_layout Subsection
19159 MCS51 Memory Models
19160 \begin_inset LatexCommand \index{Memory model}
19161
19162 \end_inset
19163
19164
19165 \begin_inset LatexCommand \index{MCS51 memory model}
19166
19167 \end_inset
19168
19169
19170 \end_layout
19171
19172 \begin_layout Subsubsection
19173 Small, Medium and Large
19174 \end_layout
19175
19176 \begin_layout Standard
19177 SDCC allows three memory models for MCS51 code, 
19178 \shape slanted
19179 small, medium
19180 \shape default
19181  and 
19182 \shape slanted
19183 large
19184 \shape default
19185 .
19186  Modules compiled with different memory models should 
19187 \emph on
19188 never
19189 \emph default
19190  be combined together or the results would be unpredictable.
19191  The library routines supplied with the compiler are compiled as small,
19192  medium and large.
19193  The compiled library modules are contained in separate directories as small,
19194  medium and large so that you can link to the appropriate set.
19195 \end_layout
19196
19197 \begin_layout Standard
19198 When the medium or large model is used all variables declared without a
19199  storage class will be allocated into the external ram, this includes all
19200  parameters and local variables (for non-reentrant
19201 \begin_inset LatexCommand \index{reentrant}
19202
19203 \end_inset
19204
19205  functions).
19206  When the small model is used variables without storage class are allocated
19207  in the internal ram.
19208 \end_layout
19209
19210 \begin_layout Standard
19211 Judicious usage of the processor specific storage classes
19212 \begin_inset LatexCommand \index{Storage class}
19213
19214 \end_inset
19215
19216  and the 'reentrant' function type will yield much more efficient code,
19217  than using the large model.
19218  Several optimizations are disabled when the program is compiled using the
19219  large model, it is therefore recommended that the small model be used unless
19220  absolutely required.
19221 \end_layout
19222
19223 \begin_layout Subsubsection
19224 External Stack
19225 \begin_inset LatexCommand \label{sub:External-Stack}
19226
19227 \end_inset
19228
19229
19230 \begin_inset LatexCommand \index{stack}
19231
19232 \end_inset
19233
19234
19235 \begin_inset LatexCommand \index{External stack (mcs51)}
19236
19237 \end_inset
19238
19239
19240 \end_layout
19241
19242 \begin_layout Standard
19243 The external stack (-
19244 \begin_inset ERT
19245 status collapsed
19246
19247 \begin_layout Standard
19248
19249
19250 \backslash
19251 /
19252 \end_layout
19253
19254 \end_inset
19255
19256 -xstack option
19257 \begin_inset LatexCommand \index{-\/-xstack}
19258
19259 \end_inset
19260
19261 ) is located in pdata
19262 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19263
19264 \end_inset
19265
19266  memory (usually at the start of the external ram segment) and uses all
19267  unused space in pdata (max.
19268  256 bytes).
19269  When -
19270 \begin_inset ERT
19271 status collapsed
19272
19273 \begin_layout Standard
19274
19275
19276 \backslash
19277 /
19278 \end_layout
19279
19280 \end_inset
19281
19282 -xstack option is used to compile the program, the parameters and local
19283  variables
19284 \begin_inset LatexCommand \index{local variables}
19285
19286 \end_inset
19287
19288  of all reentrant functions are allocated in this area.
19289  This option is provided for programs with large stack space requirements.
19290  When used with the -
19291 \begin_inset ERT
19292 status collapsed
19293
19294 \begin_layout Standard
19295
19296
19297 \backslash
19298 /
19299 \end_layout
19300
19301 \end_inset
19302
19303 -stack-auto
19304 \begin_inset LatexCommand \index{-\/-stack-auto}
19305
19306 \end_inset
19307
19308  option, all parameters and local variables are allocated on the external
19309  stack (note: support libraries will need to be recompiled with the same
19310  options.
19311  There is a predefined target in the library makefile).
19312 \end_layout
19313
19314 \begin_layout Standard
19315 The compiler outputs the higher order address byte of the external ram segment
19316  into port P2
19317 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19318
19319 \end_inset
19320
19321  (see also section 
19322 \begin_inset LatexCommand \ref{sub:MCS51-variants}
19323
19324 \end_inset
19325
19326 ), therefore when using the External Stack option, this port 
19327 \emph on
19328 may not
19329 \emph default
19330  be used by the application program.
19331 \end_layout
19332
19333 \begin_layout Subsection
19334 DS390 Memory Model
19335 \begin_inset LatexCommand \index{Memory model}
19336
19337 \end_inset
19338
19339
19340 \begin_inset LatexCommand \index{DS390 memory model}
19341
19342 \end_inset
19343
19344
19345 \end_layout
19346
19347 \begin_layout Standard
19348 The only model supported is Flat 24
19349 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
19350
19351 \end_inset
19352
19353 .
19354  This generates code for the 24 bit contiguous addressing mode of the Dallas
19355  DS80C390 part.
19356  In this mode, up to four meg of external RAM or code space can be directly
19357  addressed.
19358  See the data sheets at www.dalsemi.com for further information on this part.
19359 \newline
19360
19361 \newline
19362 Note
19363  that the compiler does not generate any code to place the processor into
19364  24 bitmode (although 
19365 \emph on
19366 tinibios
19367 \emph default
19368  in the ds390 libraries will do that for you).
19369  If you don't use 
19370 \emph on
19371 tinibios
19372 \emph default
19373
19374 \begin_inset LatexCommand \index{Tinibios (DS390)}
19375
19376 \end_inset
19377
19378 , the boot loader or similar code must ensure that the processor is in 24
19379  bit contiguous addressing mode before calling the SDCC startup code.
19380 \newline
19381
19382 \newline
19383 Like
19384  the 
19385 \emph on
19386 -
19387 \begin_inset ERT
19388 status collapsed
19389
19390 \begin_layout Standard
19391
19392
19393 \backslash
19394 /
19395 \end_layout
19396
19397 \end_inset
19398
19399 -model-large
19400 \emph default
19401  option, variables will by default be placed into the XDATA segment.
19402  
19403 \newline
19404
19405 \newline
19406 Segments may be placed anywhere in the 4 meg address space using the usual
19407  -
19408 \begin_inset ERT
19409 status collapsed
19410
19411 \begin_layout Standard
19412
19413
19414 \backslash
19415 /
19416 \end_layout
19417
19418 \end_inset
19419
19420 -*-loc options.
19421  Note that if any segments are located above 64K, the -r flag must be passed
19422  to the linker to generate the proper segment relocations, and the Intel
19423  HEX output format must be used.
19424  The -r flag can be passed to the linker by using the option 
19425 \emph on
19426 -Wl-r
19427 \emph default
19428  on the SDCC command line.
19429  However, currently the linker can not handle code segments > 64k.
19430 \end_layout
19431
19432 \begin_layout Section
19433 Pragmas
19434 \begin_inset LatexCommand \label{sec:Pragmas}
19435
19436 \end_inset
19437
19438
19439 \begin_inset LatexCommand \index{Pragmas}
19440
19441 \end_inset
19442
19443
19444 \end_layout
19445
19446 \begin_layout Standard
19447 SDCC supports the following #pragma directives:
19448 \end_layout
19449
19450 \begin_layout Itemize
19451
19452 \series bold
19453 save
19454 \series default
19455
19456 \begin_inset LatexCommand \index{\#pragma save}
19457
19458 \end_inset
19459
19460  - this will save most current options to the save/restore stack.
19461  See #pragma\InsetSpace ~
19462 restore.
19463 \end_layout
19464
19465 \begin_layout Itemize
19466
19467 \series bold
19468 restore
19469 \series default
19470
19471 \begin_inset LatexCommand \index{\#pragma restore}
19472
19473 \end_inset
19474
19475  - will restore saved options from the last save.
19476  saves & restores can be nested.
19477  SDCC uses a save/restore stack: save pushes current options to the stack,
19478  restore pulls current options from the stack.
19479  See #pragma\InsetSpace ~
19480 save.
19481 \newline
19482
19483 \end_layout
19484
19485 \begin_layout Itemize
19486
19487 \series bold
19488 callee_saves
19489 \series default
19490
19491 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19492
19493 \end_inset
19494
19495
19496 \begin_inset LatexCommand \index{function prologue}
19497
19498 \end_inset
19499
19500  function1[,function2[,function3...]] - The compiler by default uses a caller
19501  saves convention for register saving across function calls, however this
19502  can cause unnecessary register pushing & popping
19503 \begin_inset LatexCommand \index{push/pop}
19504
19505 \end_inset
19506
19507  when calling small functions from larger functions.
19508  This option can be used to switch off the register saving convention for
19509  the function names specified.
19510  The compiler will not save registers when calling these functions, extra
19511  code need to be manually inserted at the entry & exit for these functions
19512  to save & restore the registers used by these functions, this can SUBSTANTIALLY
19513  reduce code & improve run time performance of the generated code.
19514  In the future the compiler (with inter procedural analysis) may be able
19515  to determine the appropriate scheme to use for each function call.
19516  If -
19517 \begin_inset ERT
19518 status collapsed
19519
19520 \begin_layout Standard
19521
19522
19523 \backslash
19524 /
19525 \end_layout
19526
19527 \end_inset
19528
19529 -callee-saves command line option is used, the function names specified
19530  in #pragma\InsetSpace ~
19531 callee_saves
19532 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19533
19534 \end_inset
19535
19536  is appended to the list of functions specified in the command line.
19537 \end_layout
19538
19539 \begin_layout Itemize
19540
19541 \series bold
19542 exclude
19543 \series default
19544
19545 \begin_inset LatexCommand \index{\#pragma exclude}
19546
19547 \end_inset
19548
19549  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
19550  of pairs of push/pop
19551 \begin_inset LatexCommand \index{push/pop}
19552
19553 \end_inset
19554
19555  instructions in 
19556 \emph on
19557 I
19558 \emph default
19559 nterrupt
19560 \begin_inset LatexCommand \index{interrupt}
19561
19562 \end_inset
19563
19564  
19565 \emph on
19566 S
19567 \emph default
19568 ervice 
19569 \emph on
19570 R
19571 \emph default
19572 outines.
19573  The directive should be placed immediately before the ISR function definition
19574  and it affects ALL ISR functions following it.
19575  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
19576 exclude\InsetSpace ~
19577 none
19578 \begin_inset LatexCommand \index{\#pragma exclude}
19579
19580 \end_inset
19581
19582 .
19583  See also the related keyword _naked
19584 \begin_inset LatexCommand \index{\_naked}
19585
19586 \end_inset
19587
19588
19589 \begin_inset LatexCommand \index{\_\_naked}
19590
19591 \end_inset
19592
19593 .
19594 \end_layout
19595
19596 \begin_layout Itemize
19597
19598 \series bold
19599 less_pedantic
19600 \series default
19601
19602 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
19603
19604 \end_inset
19605
19606  - the compiler will not warn you anymore for obvious mistakes, you'r on
19607  your own now ;-(
19608 \end_layout
19609
19610 \begin_layout Itemize
19611
19612 \series bold
19613 disable_warning
19614 \series default
19615  <nnnn>
19616 \begin_inset LatexCommand \index{\#pragma disable\_warning}
19617
19618 \end_inset
19619
19620  - the compiler will not warn you anymore about warning number <nnnn>.
19621 \end_layout
19622
19623 \begin_layout Itemize
19624
19625 \series bold
19626 nogcse
19627 \series default
19628
19629 \begin_inset LatexCommand \index{\#pragma nogcse}
19630
19631 \end_inset
19632
19633  - will stop global common subexpression elimination.
19634 \end_layout
19635
19636 \begin_layout Itemize
19637
19638 \series bold
19639 noinduction
19640 \series default
19641
19642 \begin_inset LatexCommand \index{\#pragma noinduction}
19643
19644 \end_inset
19645
19646  - will stop loop induction optimizations.
19647 \end_layout
19648
19649 \begin_layout Itemize
19650
19651 \series bold
19652 noinvariant
19653 \series default
19654
19655 \begin_inset LatexCommand \index{\#pragma noinvariant}
19656
19657 \end_inset
19658
19659  - will not do loop invariant optimizations.
19660  For more details see Loop Invariants in section
19661 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
19662
19663 \end_inset
19664
19665 .
19666 \end_layout
19667
19668 \begin_layout Itemize
19669
19670 \series bold
19671 noiv
19672 \series default
19673
19674 \begin_inset LatexCommand \index{\#pragma noiv}
19675
19676 \end_inset
19677
19678  - Do not generate interrupt
19679 \begin_inset LatexCommand \index{interrupt}
19680
19681 \end_inset
19682
19683  vector table
19684 \begin_inset LatexCommand \index{interrupt vector table}
19685
19686 \end_inset
19687
19688  entries for all ISR functions defined after the pragma.
19689  This is useful in cases where the interrupt vector table must be defined
19690  manually, or when there is a secondary, manually defined interrupt vector
19691  table (e.g.
19692  for the autovector feature of the Cypress EZ-USB FX2).
19693  More elegantly this can be achieved by obmitting the optional interrupt
19694  number after the interrupt keyword, see section 
19695 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
19696
19697 \end_inset
19698
19699 \InsetSpace ~
19700 about interrupts.
19701 \end_layout
19702
19703 \begin_layout Itemize
19704
19705 \series bold
19706 nojtbound
19707 \series default
19708
19709 \begin_inset LatexCommand \index{\#pragma nojtbound}
19710
19711 \end_inset
19712
19713  - will not generate code for boundary value checking, when switch statements
19714  are turned into jump-tables (dangerous).
19715  For more details see section 
19716 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
19717
19718 \end_inset
19719
19720 .
19721 \end_layout
19722
19723 \begin_layout Itemize
19724
19725 \series bold
19726 noloopreverse
19727 \series default
19728
19729 \begin_inset LatexCommand \index{\#pragma noloopreverse}
19730
19731 \end_inset
19732
19733  - Will not do loop reversal optimization
19734 \end_layout
19735
19736 \begin_layout Itemize
19737
19738 \series bold
19739 nooverlay
19740 \series default
19741
19742 \begin_inset LatexCommand \index{\#pragma nooverlay}
19743
19744 \end_inset
19745
19746  - the compiler will not overlay the parameters and local variables of a
19747  function.
19748 \end_layout
19749
19750 \begin_layout Itemize
19751
19752 \series bold
19753 stackauto
19754 \series default
19755
19756 \begin_inset LatexCommand \index{\#pragma stackauto}
19757
19758 \end_inset
19759
19760 - See option -
19761 \begin_inset ERT
19762 status collapsed
19763
19764 \begin_layout Standard
19765
19766
19767 \backslash
19768 /
19769 \end_layout
19770
19771 \end_inset
19772
19773 -stack-auto
19774 \begin_inset LatexCommand \index{-\/-stack-auto}
19775
19776 \end_inset
19777
19778  and section 
19779 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
19780
19781 \end_inset
19782
19783  Parameters and Local Variables.
19784 \end_layout
19785
19786 \begin_layout Itemize
19787
19788 \series bold
19789 opt_code_speed
19790 \series default
19791  
19792 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
19793
19794 \end_inset
19795
19796 - The compiler will optimize code generation towards fast code, possibly
19797  at the expense of code size.
19798  Currently this has little effect.
19799 \end_layout
19800
19801 \begin_layout Itemize
19802
19803 \series bold
19804 opt_code_size
19805 \series default
19806  
19807 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
19808
19809 \end_inset
19810
19811 - The compiler will optimize code generation towards compact code, possibly
19812  at the expense of code speed.
19813  Currently this has little effect.
19814 \end_layout
19815
19816 \begin_layout Itemize
19817
19818 \series bold
19819 opt_code_balanced
19820 \series default
19821  
19822 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
19823
19824 \end_inset
19825
19826 - The compiler will attempt to generate code that is both compact and fast,
19827  as long as meeting one goal is not a detriment to the other (this is the
19828  default).
19829  
19830 \end_layout
19831
19832 \begin_layout Itemize
19833
19834 \series bold
19835 std_sdcc89
19836 \series default
19837  
19838 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
19839
19840 \end_inset
19841
19842 - Generally follow the C89 standard, but allow SDCC features that conflict
19843  with the standard (default).
19844 \end_layout
19845
19846 \begin_layout Itemize
19847
19848 \series bold
19849 std_c89
19850 \series default
19851  
19852 \begin_inset LatexCommand \index{\#pragma std\_c89}
19853
19854 \end_inset
19855
19856 - Follow the C89 standard and disable SDCC features that conflict with the
19857  standard.
19858 \end_layout
19859
19860 \begin_layout Itemize
19861
19862 \series bold
19863 std_sdcc99
19864 \series default
19865  
19866 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
19867
19868 \end_inset
19869
19870 - Generally follow the C99 standard, but allow SDCC features that conflict
19871  with the standard (incomplete support).
19872 \end_layout
19873
19874 \begin_layout Itemize
19875
19876 \series bold
19877 std_c99
19878 \series default
19879  
19880 \begin_inset LatexCommand \index{\#pragma std\_c99}
19881
19882 \end_inset
19883
19884 - Follow the C99 standard and disable SDCC features that conflict with the
19885  standard (incomplete support).
19886 \end_layout
19887
19888 \begin_layout Itemize
19889
19890 \series bold
19891 codeseg
19892 \series default
19893  <name>
19894 \begin_inset LatexCommand \index{\#pragma codeseg}
19895
19896 \end_inset
19897
19898 - Use this name (max.
19899  8 characters) for the code segment.
19900  See option -
19901 \begin_inset ERT
19902 status collapsed
19903
19904 \begin_layout Standard
19905
19906
19907 \backslash
19908 /
19909 \end_layout
19910
19911 \end_inset
19912
19913 -codeseg.
19914 \end_layout
19915
19916 \begin_layout Itemize
19917
19918 \series bold
19919 constseg
19920 \series default
19921  <name>
19922 \begin_inset LatexCommand \index{\#pragma constseg}
19923
19924 \end_inset
19925
19926 - Use this name (max.
19927  8 characters) for the const segment.
19928  See option -
19929 \begin_inset ERT
19930 status collapsed
19931
19932 \begin_layout Standard
19933
19934
19935 \backslash
19936 /
19937 \end_layout
19938
19939 \end_inset
19940
19941 -constseg.
19942 \end_layout
19943
19944 \begin_layout Standard
19945 The preprocessor SDCPP
19946 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
19947
19948 \end_inset
19949
19950  supports the following #pragma directives:
19951 \end_layout
19952
19953 \begin_layout Itemize
19954
19955 \series bold
19956 pedantic_parse_number
19957 \series default
19958
19959 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19960
19961 \end_inset
19962
19963  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
19964  parsed properly and the macro LO_B(3) gets expanded.
19965  Default is off.
19966  Below is an example on how to use this pragma.
19967
19968 \emph on
19969  Note: this functionality is not in conformance with standard!
19970 \end_layout
19971
19972 \begin_layout Verse
19973
19974 \family typewriter
19975 #pragma pedantic_parse_number +
19976 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19977
19978 \end_inset
19979
19980
19981 \newline
19982
19983 \newline
19984 #define LO_B(x) ((x) & 0xff)
19985 \newline
19986
19987 \newline
19988 unsigned char foo(void)
19989 \newline
19990 {
19991 \newline
19992 \InsetSpace ~
19993 \InsetSpace ~
19994 \InsetSpace ~
19995 unsigned char c=0xfe-LO_B(3)
19996 ;
19997 \newline
19998
19999 \newline
20000 \InsetSpace ~
20001 \InsetSpace ~
20002 \InsetSpace ~
20003 return c;
20004 \newline
20005 }
20006 \newline
20007
20008 \end_layout
20009
20010 \begin_layout Itemize
20011
20012 \series bold
20013 preproc_asm
20014 \series default
20015
20016 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20017
20018 \end_inset
20019
20020  (+ | -) - switch _asm _endasm block preprocessing on / off.
20021  Default is on.
20022  You use this prama to define multilines of assembly code.
20023  This will prevent the preprocessor from changing the formating required
20024  by assembly code.
20025  Below is an example on how to use this pragma.
20026 \end_layout
20027
20028 \begin_layout Verse
20029
20030 \family typewriter
20031 #pragma preproc_asm -
20032 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20033
20034 \end_inset
20035
20036
20037 \newline
20038 #define MYDELAY _asm
20039 \newline
20040 \InsetSpace ~
20041 \InsetSpace ~
20042 \InsetSpace ~
20043 nop ;my assembly comment...
20044 \newline
20045 \InsetSpace ~
20046 \InsetSpace ~
20047 \InsetSpace ~
20048 nop
20049 \newline
20050 \InsetSpace ~
20051 \InsetSpace ~
20052 \InsetSpace ~
20053 nop
20054 \newline
20055 _endasm
20056 \newline
20057 #pragma preproc_asm
20058  +
20059 \newline
20060
20061 \newline
20062 void foo (void) 
20063 \newline
20064
20065 \newline
20066 \InsetSpace ~
20067 \InsetSpace ~
20068 \InsetSpace ~
20069  ...
20070  
20071 \newline
20072 \InsetSpace ~
20073 \InsetSpace ~
20074 \InsetSpace ~
20075  MYDELAY;
20076 \newline
20077 \InsetSpace ~
20078 \InsetSpace ~
20079 \InsetSpace ~
20080  ...
20081  
20082 \newline
20083
20084 \newline
20085
20086 \end_layout
20087
20088 \begin_layout Itemize
20089
20090 \series bold
20091 sdcc_hash
20092 \series default
20093
20094 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20095
20096 \end_inset
20097
20098  (+ | -) - Allow "naked" hash in macro definition, for example:
20099 \newline
20100
20101 \family typewriter
20102 #define DIR_LO(x) #(x & 0xff)
20103 \family default
20104
20105 \newline
20106 Default is off.
20107  Below is an example on how to use this pragma.
20108 \end_layout
20109
20110 \begin_layout Verse
20111
20112 \family typewriter
20113 #pragma preproc_asm +
20114 \newline
20115 #pragma sdcc_hash +
20116 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20117
20118 \end_inset
20119
20120
20121 \newline
20122
20123 \newline
20124 #define ROMCALL(x) 
20125 \backslash
20126
20127 \newline
20128 \InsetSpace ~
20129 \InsetSpace ~
20130 \InsetSpace ~
20131 mov R6_B3, #(x & 0xff) 
20132 \backslash
20133
20134 \newline
20135 \InsetSpace ~
20136 \InsetSpace ~
20137 \InsetSpace ~
20138 mov R7_B3, #((x >> 8) & 0xff) 
20139 \backslash
20140
20141 \newline
20142 \InsetSpace ~
20143 \InsetSpace ~
20144 \InsetSpace ~
20145 lcall __romcall
20146 \newline
20147
20148 \newline
20149 ...
20150 \newline
20151 _asm
20152 \newline
20153 ROMCALL(72)
20154 \newline
20155 _endasm;
20156 \newline
20157 ...
20158 \newline
20159
20160 \end_layout
20161
20162 \begin_layout Standard
20163 The pragma's are intended to be used to turn-on or off certain optimizations
20164  which might cause the compiler to generate extra stack / data space to
20165  store compiler generated temporary variables.
20166  This usually happens in large functions.
20167  Pragma directives should be used as shown in the following example, they
20168  are used to control options & optimizations for a given function; pragmas
20169  should be placed before and/or after a function, placing pragma's inside
20170  a function body could have unpredictable results.
20171 \end_layout
20172
20173 \begin_layout Verse
20174
20175 \family typewriter
20176 #pragma save
20177 \begin_inset LatexCommand \index{\#pragma save}
20178
20179 \end_inset
20180
20181  \InsetSpace ~
20182 \InsetSpace ~
20183 \InsetSpace ~
20184 \InsetSpace ~
20185 \InsetSpace ~
20186 \InsetSpace ~
20187 \InsetSpace ~
20188 /* save the current settings */ 
20189 \newline
20190 #pragma nogcse
20191 \begin_inset LatexCommand \index{\#pragma nogcse}
20192
20193 \end_inset
20194
20195  \InsetSpace ~
20196 \InsetSpace ~
20197 \InsetSpace ~
20198 \InsetSpace ~
20199 \InsetSpace ~
20200 /* turnoff global subexpression elimination */ 
20201 \newline
20202 #pragma noinduction
20203 \begin_inset LatexCommand \index{\#pragma noinduction}
20204
20205 \end_inset
20206
20207  /* turn off induction optimizations */ 
20208 \newline
20209 int foo () 
20210 \newline
20211
20212 \newline
20213 \InsetSpace ~
20214  \InsetSpace ~
20215  ...
20216  
20217 \newline
20218 \InsetSpace ~
20219  \InsetSpace ~
20220  /* large code */ 
20221 \newline
20222 \InsetSpace ~
20223  \InsetSpace ~
20224  ...
20225  
20226 \newline
20227
20228 \newline
20229 #pragma restore
20230 \begin_inset LatexCommand \index{\#pragma restore}
20231
20232 \end_inset
20233
20234  /* turn the optimizations back on */
20235 \end_layout
20236
20237 \begin_layout Standard
20238 The compiler will generate a warning message when extra space is allocated.
20239  It is strongly recommended that the save and restore pragma's be used when
20240  changing options for a function.
20241 \newline
20242
20243 \newline
20244
20245 \newline
20246
20247 \end_layout
20248
20249 \begin_layout Section
20250 Defines Created by the Compiler
20251 \end_layout
20252
20253 \begin_layout Standard
20254 The compiler creates the following #defines
20255 \begin_inset LatexCommand \index{\#defines}
20256
20257 \end_inset
20258
20259
20260 \begin_inset LatexCommand \index{Defines created by the compiler}
20261
20262 \end_inset
20263
20264 :
20265 \newline
20266
20267 \end_layout
20268
20269 \begin_layout Standard
20270 \begin_inset Tabular
20271 <lyxtabular version="3" rows="11" columns="2">
20272 <features>
20273 <column alignment="left" valignment="top" leftline="true" width="3in">
20274 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
20275 <row topline="true" bottomline="true">
20276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20277 \begin_inset Text
20278
20279 \begin_layout Standard
20280
20281 \series bold
20282 #define
20283 \end_layout
20284
20285 \end_inset
20286 </cell>
20287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20288 \begin_inset Text
20289
20290 \begin_layout Standard
20291
20292 \series bold
20293 Description
20294 \end_layout
20295
20296 \end_inset
20297 </cell>
20298 </row>
20299 <row topline="true">
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20301 \begin_inset Text
20302
20303 \begin_layout Standard
20304 SDCC
20305 \begin_inset LatexCommand \index{SDCC}
20306
20307 \end_inset
20308
20309  
20310 \end_layout
20311
20312 \end_inset
20313 </cell>
20314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20315 \begin_inset Text
20316
20317 \begin_layout Standard
20318 Always defined.
20319  Since version 2.5.6 the version number as an int (ex.
20320  256)
20321 \end_layout
20322
20323 \end_inset
20324 </cell>
20325 </row>
20326 <row topline="true">
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20328 \begin_inset Text
20329
20330 \begin_layout Standard
20331 SDCC_mcs51
20332 \begin_inset LatexCommand \index{SDCC\_mcs51}
20333
20334 \end_inset
20335
20336  or SDCC_ds390
20337 \begin_inset LatexCommand \index{SDCC\_ds390}
20338
20339 \end_inset
20340
20341  or SDCC_z80
20342 \begin_inset LatexCommand \index{SDCC\_z80}
20343
20344 \end_inset
20345
20346 , etc.
20347 \end_layout
20348
20349 \end_inset
20350 </cell>
20351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20352 \begin_inset Text
20353
20354 \begin_layout Standard
20355 depending on the model used (e.g.: -mds390)
20356 \end_layout
20357
20358 \end_inset
20359 </cell>
20360 </row>
20361 <row topline="true">
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20363 \begin_inset Text
20364
20365 \begin_layout Standard
20366 __mcs51
20367 \begin_inset LatexCommand \index{\_\_mcs51}
20368
20369 \end_inset
20370
20371 , __ds390
20372 \begin_inset LatexCommand \index{\_\_ds390}
20373
20374 \end_inset
20375
20376 , __hc08
20377 \begin_inset LatexCommand \index{\_\_hc08}
20378
20379 \end_inset
20380
20381 , __z80
20382 \begin_inset LatexCommand \index{\_\_z80}
20383
20384 \end_inset
20385
20386 , etc
20387 \end_layout
20388
20389 \end_inset
20390 </cell>
20391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20392 \begin_inset Text
20393
20394 \begin_layout Standard
20395 depending on the model used (e.g.
20396  -mz80)
20397 \end_layout
20398
20399 \end_inset
20400 </cell>
20401 </row>
20402 <row topline="true">
20403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20404 \begin_inset Text
20405
20406 \begin_layout Standard
20407 SDCC_STACK_AUTO
20408 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
20409
20410 \end_inset
20411
20412
20413 \end_layout
20414
20415 \end_inset
20416 </cell>
20417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20418 \begin_inset Text
20419
20420 \begin_layout Standard
20421 when 
20422 \emph on
20423 -
20424 \begin_inset ERT
20425 status collapsed
20426
20427 \begin_layout Standard
20428
20429
20430 \backslash
20431 /
20432 \end_layout
20433
20434 \end_inset
20435
20436 -stack-auto
20437 \emph default
20438  option is used
20439 \end_layout
20440
20441 \end_inset
20442 </cell>
20443 </row>
20444 <row topline="true">
20445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20446 \begin_inset Text
20447
20448 \begin_layout Standard
20449 SDCC_MODEL_SMALL
20450 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
20451
20452 \end_inset
20453
20454
20455 \end_layout
20456
20457 \end_inset
20458 </cell>
20459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20460 \begin_inset Text
20461
20462 \begin_layout Standard
20463 when 
20464 \emph on
20465 -
20466 \begin_inset ERT
20467 status collapsed
20468
20469 \begin_layout Standard
20470
20471
20472 \backslash
20473 /
20474 \end_layout
20475
20476 \end_inset
20477
20478 -model-small
20479 \emph default
20480  is used
20481 \end_layout
20482
20483 \end_inset
20484 </cell>
20485 </row>
20486 <row topline="true">
20487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20488 \begin_inset Text
20489
20490 \begin_layout Standard
20491 SDCC_MODEL_MEDIUM
20492 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
20493
20494 \end_inset
20495
20496
20497 \end_layout
20498
20499 \end_inset
20500 </cell>
20501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20502 \begin_inset Text
20503
20504 \begin_layout Standard
20505 when 
20506 \emph on
20507 -
20508 \begin_inset ERT
20509 status collapsed
20510
20511 \begin_layout Standard
20512
20513
20514 \backslash
20515 /
20516 \end_layout
20517
20518 \end_inset
20519
20520 -model-medium
20521 \emph default
20522  is used
20523 \end_layout
20524
20525 \end_inset
20526 </cell>
20527 </row>
20528 <row topline="true">
20529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20530 \begin_inset Text
20531
20532 \begin_layout Standard
20533 SDCC_MODEL_LARGE
20534 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
20535
20536 \end_inset
20537
20538
20539 \end_layout
20540
20541 \end_inset
20542 </cell>
20543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20544 \begin_inset Text
20545
20546 \begin_layout Standard
20547 when 
20548 \emph on
20549 -
20550 \begin_inset ERT
20551 status collapsed
20552
20553 \begin_layout Standard
20554
20555
20556 \backslash
20557 /
20558 \end_layout
20559
20560 \end_inset
20561
20562 -model-large
20563 \emph default
20564  is used
20565 \end_layout
20566
20567 \end_inset
20568 </cell>
20569 </row>
20570 <row topline="true">
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20572 \begin_inset Text
20573
20574 \begin_layout Standard
20575 SDCC_USE_XSTACK
20576 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
20577
20578 \end_inset
20579
20580
20581 \end_layout
20582
20583 \end_inset
20584 </cell>
20585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20586 \begin_inset Text
20587
20588 \begin_layout Standard
20589 when 
20590 \emph on
20591 -
20592 \begin_inset ERT
20593 status collapsed
20594
20595 \begin_layout Standard
20596
20597
20598 \backslash
20599 /
20600 \end_layout
20601
20602 \end_inset
20603
20604 -xstack
20605 \emph default
20606  option is used
20607 \end_layout
20608
20609 \end_inset
20610 </cell>
20611 </row>
20612 <row topline="true">
20613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20614 \begin_inset Text
20615
20616 \begin_layout Standard
20617 SDCC_STACK_TENBIT
20618 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
20619
20620 \end_inset
20621
20622  
20623 \end_layout
20624
20625 \end_inset
20626 </cell>
20627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20628 \begin_inset Text
20629
20630 \begin_layout Standard
20631 when 
20632 \emph on
20633 -mds390
20634 \emph default
20635  is used
20636 \end_layout
20637
20638 \end_inset
20639 </cell>
20640 </row>
20641 <row topline="true" bottomline="true">
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20643 \begin_inset Text
20644
20645 \begin_layout Standard
20646 SDCC_MODEL_FLAT24
20647 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
20648
20649 \end_inset
20650
20651
20652 \end_layout
20653
20654 \end_inset
20655 </cell>
20656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20657 \begin_inset Text
20658
20659 \begin_layout Standard
20660 when 
20661 \emph on
20662 -mds390
20663 \emph default
20664  is used
20665 \end_layout
20666
20667 \end_inset
20668 </cell>
20669 </row>
20670 </lyxtabular>
20671
20672 \end_inset
20673
20674
20675 \end_layout
20676
20677 \begin_layout Chapter
20678 Notes on supported Processors
20679 \end_layout
20680
20681 \begin_layout Section
20682 MCS51 variants
20683 \begin_inset LatexCommand \label{sub:MCS51-variants}
20684
20685 \end_inset
20686
20687
20688 \begin_inset LatexCommand \index{MCS51 variants}
20689
20690 \end_inset
20691
20692
20693 \end_layout
20694
20695 \begin_layout Standard
20696 MCS51 processors are available from many vendors and come in many different
20697  flavours.
20698  While they might differ considerably in respect to Special Function Registers
20699  the core MCS51 is usually not modified or is kept compatible.
20700  
20701 \end_layout
20702
20703 \begin_layout Subsection
20704 pdata access by SFR 
20705 \end_layout
20706
20707 \begin_layout Standard
20708 With the upcome of devices with internal xdata and flash memory devices
20709  using port P2
20710 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20711
20712 \end_inset
20713
20714  as dedicated I/O port is becoming more popular.
20715  Switching the high byte for pdata
20716 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20717
20718 \end_inset
20719
20720  access which was formerly done by port P2 is then achieved by a Special
20721  Function Register
20722 \begin_inset LatexCommand \index{sfr}
20723
20724 \end_inset
20725
20726 .
20727  In well-established MCS51 tradition the address of this 
20728 \emph on
20729 sfr
20730 \emph default
20731  is where the chip designers decided to put it.
20732  Needless to say that they didn't agree on a common name either.
20733  So that the startup code can correctly initialize xdata variables, you
20734  should define an sfr with the name _XPAGE
20735 \family typewriter
20736
20737 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
20738
20739 \end_inset
20740
20741
20742 \family default
20743  at the appropriate location if the default, port P2, is not used for this.
20744  Some examples are:
20745 \end_layout
20746
20747 \begin_layout Verse
20748
20749 \family typewriter
20750 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
20751 \end_layout
20752
20753 \begin_layout Verse
20754
20755 \family typewriter
20756 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20757 \end_layout
20758
20759 \begin_layout Verse
20760
20761 \family typewriter
20762 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20763 \end_layout
20764
20765 \begin_layout Standard
20766 For more exotic implementations further customizations may be needed.
20767  See section 
20768 \begin_inset LatexCommand \ref{sub:Startup-Code}
20769
20770 \end_inset
20771
20772  for other possibilities.
20773 \end_layout
20774
20775 \begin_layout Subsection
20776 Other Features available by SFR
20777 \end_layout
20778
20779 \begin_layout Standard
20780 Some MCS51 variants offer features like Double DPTR
20781 \begin_inset LatexCommand \index{DPTR}
20782
20783 \end_inset
20784
20785 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
20786  These are currently not used for the MCS51 port.
20787  If you absolutely need them you can fall back to inline assembly or submit
20788  a patch to SDCC.
20789 \begin_inset VSpace bigskip
20790 \end_inset
20791
20792
20793 \end_layout
20794
20795 \begin_layout Section
20796 DS400 port
20797 \end_layout
20798
20799 \begin_layout Standard
20800 The DS80C400
20801 \begin_inset LatexCommand \index{DS80C400}
20802
20803 \end_inset
20804
20805
20806 \begin_inset LatexCommand \index{DS400}
20807
20808 \end_inset
20809
20810  microcontroller has a rich set of peripherals.
20811  In its built-in ROM library it includes functions to access some of the
20812  features, among them is a TCP stack with IP4 and IP6 support.
20813  Library headers (currently in beta status) and other files are provided
20814  at 
20815 \size footnotesize
20816
20817 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
20818
20819 \end_inset
20820
20821 .
20822  
20823 \begin_inset VSpace bigskip
20824 \end_inset
20825
20826
20827 \end_layout
20828
20829 \begin_layout Section
20830 The Z80 and gbz80 port
20831 \end_layout
20832
20833 \begin_layout Standard
20834 SDCC can target both the Zilog Z80
20835 \begin_inset LatexCommand \index{Z80}
20836
20837 \end_inset
20838
20839  and the Nintendo Gameboy's Z80-like gbz80
20840 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
20841
20842 \end_inset
20843
20844 .
20845  The Z80 port is passed through the same 
20846 \emph on
20847 regressions tests
20848 \begin_inset LatexCommand \index{Regression test}
20849
20850 \end_inset
20851
20852
20853 \emph default
20854  (see section 
20855 \begin_inset LatexCommand \ref{sec:Quality-control}
20856
20857 \end_inset
20858
20859 ) as the MCS51 and DS390 ports, so floating point support, support for long
20860  variables and bitfield support is fine.
20861  See mailing lists and forums about interrupt routines.
20862 \end_layout
20863
20864 \begin_layout Standard
20865 As always, the code is the authoritative reference - see z80/ralloc.c and
20866  z80/gen.c.
20867  The stack
20868 \begin_inset LatexCommand \index{Z80!stack}
20869
20870 \end_inset
20871
20872  frame is similar to that generated by the IAR Z80 compiler.
20873  IX is used as the base pointer, HL and IY are used as a temporary registers,
20874  and BC and DE are available for holding variables.
20875  Return values
20876 \begin_inset LatexCommand \index{Z80!return value}
20877
20878 \end_inset
20879
20880  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
20881  bytes).
20882  The gbz80 port use the same set of registers for the return values, but
20883  in a different order of significance: E (one byte), DE (two bytes), or
20884  HLDE (four bytes).
20885 \begin_inset VSpace bigskip
20886 \end_inset
20887
20888
20889 \end_layout
20890
20891 \begin_layout Section
20892 The HC08 port
20893 \end_layout
20894
20895 \begin_layout Standard
20896 The port to the Freescale/Motorola HC08
20897 \begin_inset LatexCommand \index{HC08}
20898
20899 \end_inset
20900
20901  family has been added in October 2003, and is still undergoing some basic
20902  development.
20903  The code generator is complete, but the register allocation is still quite
20904  unoptimized.
20905  Some of the SDCC's standard C library functions have embedded non-HC08
20906  inline assembly and so are not yet usable.
20907 \end_layout
20908
20909 \begin_layout Standard
20910 The HC08 port passes the regression test suite (see section 
20911 \begin_inset LatexCommand \ref{sec:Quality-control}
20912
20913 \end_inset
20914
20915 ).
20916 \begin_inset VSpace bigskip
20917 \end_inset
20918
20919
20920 \end_layout
20921
20922 \begin_layout Standard
20923
20924 \newpage
20925
20926 \end_layout
20927
20928 \begin_layout Section
20929 The PIC14 port
20930 \end_layout
20931
20932 \begin_layout Standard
20933 The 14bit PIC
20934 \begin_inset LatexCommand \index{PIC14}
20935
20936 \end_inset
20937
20938  port still requires a major effort from the development community.
20939  However it can work for simple code.
20940  It passes its (smaller set of) regression tests
20941 \begin_inset LatexCommand \index{Regression test (PIC14)}
20942
20943 \end_inset
20944
20945  in the directory 
20946 \shape italic
20947 sdcc/src/regression
20948 \shape default
20949 .
20950 \end_layout
20951
20952 \begin_layout Subsection
20953 C code and 14bit PIC code page
20954 \begin_inset LatexCommand \index{code page (pic14)}
20955
20956 \end_inset
20957
20958  and RAM banks
20959 \begin_inset LatexCommand \index{RAM bank (pic14)}
20960
20961 \end_inset
20962
20963
20964 \end_layout
20965
20966 \begin_layout Standard
20967 The linker organizes allocation for the code page and RAM banks.
20968  It does not have intimate knowledge of the code flow.
20969  It will put all the code section of a single asm file into a single code
20970  page.
20971  In order to make use of multiple code pages, separate asm files must be
20972  used.
20973  The compiler treats all functions of a single C file as being in the same
20974  code page unless it is non static.
20975 \newline
20976
20977 \newline
20978 To get the best follow these guide lines:
20979 \end_layout
20980
20981 \begin_layout Enumerate
20982 Make local functions static, as non static functions require code page selection
20983  overhead.
20984 \end_layout
20985
20986 \begin_layout Enumerate
20987 For devices that have multiple code pages it is more efficient to use the
20988  same number of files as pages, i.e.
20989  for the 16F877 use 4 separate files and i.e.
20990  for the 16F874 use 2 separate files.
20991  This way the linker can put the code for each file into different code
20992  pages and there's less page selection overhead.
20993 \end_layout
20994
20995 \begin_layout Enumerate
20996  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
20997  instruction set), use 'unsigned char' whereever possible instead of 'int'.
20998 \end_layout
20999
21000 \begin_layout Subsection
21001 Creating a device include file 
21002 \end_layout
21003
21004 \begin_layout Standard
21005 For generating a device include file
21006 \begin_inset LatexCommand \index{PIC14!Header files}
21007
21008 \end_inset
21009
21010  use the support perl script inc2h.pl kept in directory support/script.
21011 \end_layout
21012
21013 \begin_layout Subsection
21014 Interrupt code
21015 \end_layout
21016
21017 \begin_layout Standard
21018 For the interrupt function, use the keyword '__interrupt'
21019 \begin_inset LatexCommand \index{PIC14!interrupt}
21020
21021 \end_inset
21022
21023  with level number of 0 (PIC14 only has 1 interrupt so this number is only
21024  there to avoid a syntax error - it ought to be fixed).
21025  E.g.:
21026 \end_layout
21027
21028 \begin_layout Verse
21029
21030 \family typewriter
21031 void Intr(void) __interrupt 0
21032 \newline
21033 {
21034 \newline
21035 \InsetSpace ~
21036 \InsetSpace ~
21037 T0IF = 0; /* Clear timer interrupt */
21038 \newline
21039 }
21040 \end_layout
21041
21042 \begin_layout Subsection
21043 Linking and assembling
21044 \end_layout
21045
21046 \begin_layout Standard
21047 For assembling you can use either GPUTILS'
21048 \begin_inset LatexCommand \index{gputils (pic tools)}
21049
21050 \end_inset
21051
21052  gpasm.exe or MPLAB's mpasmwin.exe.
21053  GPUTILS is available from 
21054 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21055
21056 \end_inset
21057
21058 .
21059  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
21060  If you use MPLAB and an interrupt function then the linker script file
21061  vectors section will need to be enlarged to link with mplink.
21062 \newline
21063
21064 \newline
21065 Here is a 
21066 \family typewriter
21067 Makefile
21068 \family default
21069  using GPUTILS:
21070 \end_layout
21071
21072 \begin_layout Verse
21073
21074 \family typewriter
21075 .c.o:
21076 \newline
21077 \InsetSpace ~
21078 \InsetSpace ~
21079 \InsetSpace ~
21080 \InsetSpace ~
21081 \InsetSpace ~
21082 \InsetSpace ~
21083 \InsetSpace ~
21084 \InsetSpace ~
21085 sdcc -S -V -mpic14 -p16F877 $< 
21086 \newline
21087 \InsetSpace ~
21088 \InsetSpace ~
21089 \InsetSpace ~
21090 \InsetSpace ~
21091 \InsetSpace ~
21092 \InsetSpace ~
21093 \InsetSpace ~
21094 \InsetSpace ~
21095 gpasm -c $*.asm
21096 \newline
21097
21098 \newline
21099 $(PRJ).hex: $(OBJS) 
21100 \newline
21101 \InsetSpace ~
21102 \InsetSpace ~
21103 \InsetSpace ~
21104 \InsetSpace ~
21105 \InsetSpace ~
21106 \InsetSpace ~
21107 \InsetSpace ~
21108 \InsetSpace ~
21109 gplink
21110  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
21111 \end_layout
21112
21113 \begin_layout Standard
21114 Here is a 
21115 \family typewriter
21116 Makefile
21117 \family default
21118  using MPLAB:
21119 \end_layout
21120
21121 \begin_layout Verse
21122
21123 \family typewriter
21124 .c.o: 
21125 \newline
21126 \InsetSpace ~
21127 \InsetSpace ~
21128 \InsetSpace ~
21129 \InsetSpace ~
21130 \InsetSpace ~
21131 \InsetSpace ~
21132 \InsetSpace ~
21133 \InsetSpace ~
21134 sdcc -S -V -mpic14 -p16F877 $< 
21135 \newline
21136 \InsetSpace ~
21137 \InsetSpace ~
21138 \InsetSpace ~
21139 \InsetSpace ~
21140 \InsetSpace ~
21141 \InsetSpace ~
21142 \InsetSpace ~
21143 \InsetSpace ~
21144 mpasmwin /q /o $*.asm
21145 \newline
21146
21147 \newline
21148 $(PRJ).hex: $(OBJS)
21149  
21150 \newline
21151 \InsetSpace ~
21152 \InsetSpace ~
21153 \InsetSpace ~
21154 \InsetSpace ~
21155 \InsetSpace ~
21156 \InsetSpace ~
21157 \InsetSpace ~
21158 \InsetSpace ~
21159 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
21160 \end_layout
21161
21162 \begin_layout Standard
21163 Please note that indentations within a
21164 \family typewriter
21165  Makefile
21166 \family default
21167  have to be done with a tabulator character.
21168 \end_layout
21169
21170 \begin_layout Subsection
21171 Command-line options
21172 \end_layout
21173
21174 \begin_layout Standard
21175 Besides the switches common to all SDCC backends, the PIC14 port accepts
21176  the following options (for an updated list see sdcc -
21177 \begin_inset ERT
21178 status collapsed
21179
21180 \begin_layout Standard
21181
21182
21183 \backslash
21184 /
21185 \end_layout
21186
21187 \end_inset
21188
21189 -help):
21190 \end_layout
21191
21192 \begin_layout List
21193 \labelwidthstring 00.00.0000
21194 -
21195 \begin_inset ERT
21196 status collapsed
21197
21198 \begin_layout Standard
21199
21200
21201 \backslash
21202 /
21203 \end_layout
21204
21205 \end_inset
21206
21207 -debug-extra
21208 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
21209
21210 \end_inset
21211
21212  emit debug info in assembly output
21213 \end_layout
21214
21215 \begin_layout List
21216 \labelwidthstring 00.00.0000
21217 -
21218 \begin_inset ERT
21219 status collapsed
21220
21221 \begin_layout Standard
21222
21223
21224 \backslash
21225 /
21226 \end_layout
21227
21228 \end_inset
21229
21230 -no-pcode-opt
21231 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
21232
21233 \end_inset
21234
21235  disable (slightly faulty) optimization on pCode
21236 \end_layout
21237
21238 \begin_layout List
21239 \labelwidthstring 00.00.0000
21240 -
21241 \begin_inset ERT
21242 status collapsed
21243
21244 \begin_layout Standard
21245
21246
21247 \backslash
21248 /
21249 \end_layout
21250
21251 \end_inset
21252
21253 -stack-loc
21254 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
21255
21256 \end_inset
21257
21258  sets the lowest address of the argument passing stack (defaults to a suitably
21259  large shared databank to reduce BANKSEL overhead)
21260 \end_layout
21261
21262 \begin_layout List
21263 \labelwidthstring 00.00.0000
21264 -
21265 \begin_inset ERT
21266 status collapsed
21267
21268 \begin_layout Standard
21269
21270
21271 \backslash
21272 /
21273 \end_layout
21274
21275 \end_inset
21276
21277 -stack-size
21278 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
21279
21280 \end_inset
21281
21282  sets the size if the argument passing stack (default: 16, minimum: 4)
21283 \end_layout
21284
21285 \begin_layout Subsection
21286 The library
21287 \end_layout
21288
21289 \begin_layout Subsubsection
21290 error: missing definition for symbol 
21291 \begin_inset Quotes sld
21292 \end_inset
21293
21294 __gptrget1
21295 \begin_inset Quotes srd
21296 \end_inset
21297
21298
21299 \end_layout
21300
21301 \begin_layout Standard
21302 The PIC14 port uses library routines to provide more complex operations
21303  like multiplication, division/modulus and (generic) pointer dereferencing.
21304  In order to add these routines to your project, you must link with PIC14's
21305  
21306 \family typewriter
21307 libsdcc.lib
21308 \family default
21309 .
21310  For single source file projects this is done automatically, more complex
21311  projects must add 
21312 \family typewriter
21313 libsdcc.lib
21314 \family default
21315  to the linker's arguments.
21316  Make sure you also add an include path for the library (using the -I switch
21317  to the linker)!
21318 \end_layout
21319
21320 \begin_layout Subsubsection
21321 Processor mismatch in file 
21322 \begin_inset Quotes sld
21323 \end_inset
21324
21325 XXX
21326 \begin_inset Quotes srd
21327 \end_inset
21328
21329 .
21330 \end_layout
21331
21332 \begin_layout Standard
21333 This warning can usually be ignored due to the very good compatibility amongst
21334  14 bit PIC
21335 \begin_inset LatexCommand \index{PIC14}
21336
21337 \end_inset
21338
21339  devices.
21340 \end_layout
21341
21342 \begin_layout Standard
21343 You might also consider recompiling the library for your specific device
21344  by changing the ARCH=p16f877 (default target) entry in 
21345 \family typewriter
21346 device/lib/pic/Makefile.in
21347 \family default
21348  and 
21349 \family typewriter
21350 device/lib/pic/Makefile
21351 \family default
21352  to reflect your device.
21353  This might even improve performance for smaller devices as unneccesary
21354  BANKSELs migth be removed.
21355 \end_layout
21356
21357 \begin_layout Subsection
21358 Known bugs
21359 \end_layout
21360
21361 \begin_layout Subsubsection
21362 initialized data
21363 \end_layout
21364
21365 \begin_layout Standard
21366 Currently, data can only be initialized if it resides in the source file
21367  together with 
21368 \emph on
21369 main()
21370 \emph default
21371 .
21372  Data in other source files will silently 
21373 \series bold
21374 not
21375 \series default
21376  be initialized.
21377 \family typewriter
21378 \size footnotesize
21379
21380 \begin_inset Marginal
21381 status collapsed
21382
21383 \begin_layout Standard
21384
21385 \series bold
21386 \InsetSpace ~
21387 !
21388 \end_layout
21389
21390 \end_inset
21391
21392
21393 \end_layout
21394
21395 \begin_layout Standard
21396
21397 \newpage
21398
21399 \end_layout
21400
21401 \begin_layout Section
21402 The PIC16
21403 \begin_inset LatexCommand \index{PIC16}
21404
21405 \end_inset
21406
21407  port
21408 \end_layout
21409
21410 \begin_layout Standard
21411 The PIC16
21412 \begin_inset LatexCommand \index{PIC16}
21413
21414 \end_inset
21415
21416  port is the portion of SDCC that is responsible to produce code for the
21417  Microchip
21418 \begin_inset LatexCommand \index{Microchip}
21419
21420 \end_inset
21421
21422 (TM) microcontrollers with 16 bit core.
21423  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
21424  Currently supported devices are:
21425 \end_layout
21426
21427 \begin_layout Standard
21428 \align center
21429 \begin_inset Tabular
21430 <lyxtabular version="3" rows="4" columns="6">
21431 <features>
21432 <column alignment="center" valignment="top" leftline="true" width="0">
21433 <column alignment="center" valignment="top" leftline="true" width="0">
21434 <column alignment="center" valignment="top" leftline="true" width="0">
21435 <column alignment="center" valignment="top" leftline="true" width="0">
21436 <column alignment="center" valignment="top" leftline="true" width="0">
21437 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21438 <row topline="true">
21439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21440 \begin_inset Text
21441
21442 \begin_layout Standard
21443 18F242
21444 \end_layout
21445
21446 \end_inset
21447 </cell>
21448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21449 \begin_inset Text
21450
21451 \begin_layout Standard
21452 18F248
21453 \end_layout
21454
21455 \end_inset
21456 </cell>
21457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21458 \begin_inset Text
21459
21460 \begin_layout Standard
21461 18F252
21462 \end_layout
21463
21464 \end_inset
21465 </cell>
21466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21467 \begin_inset Text
21468
21469 \begin_layout Standard
21470 18F258
21471 \end_layout
21472
21473 \end_inset
21474 </cell>
21475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21476 \begin_inset Text
21477
21478 \begin_layout Standard
21479 18F442
21480 \end_layout
21481
21482 \end_inset
21483 </cell>
21484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21485 \begin_inset Text
21486
21487 \begin_layout Standard
21488 18F448
21489 \end_layout
21490
21491 \end_inset
21492 </cell>
21493 </row>
21494 <row topline="true">
21495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21496 \begin_inset Text
21497
21498 \begin_layout Standard
21499 18F452
21500 \end_layout
21501
21502 \end_inset
21503 </cell>
21504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21505 \begin_inset Text
21506
21507 \begin_layout Standard
21508 18F458
21509 \end_layout
21510
21511 \end_inset
21512 </cell>
21513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21514 \begin_inset Text
21515
21516 \begin_layout Standard
21517 18F1220
21518 \end_layout
21519
21520 \end_inset
21521 </cell>
21522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21523 \begin_inset Text
21524
21525 \begin_layout Standard
21526 18F2220
21527 \end_layout
21528
21529 \end_inset
21530 </cell>
21531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21532 \begin_inset Text
21533
21534 \begin_layout Standard
21535 18F2550
21536 \end_layout
21537
21538 \end_inset
21539 </cell>
21540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21541 \begin_inset Text
21542
21543 \begin_layout Standard
21544 18F4331
21545 \end_layout
21546
21547 \end_inset
21548 </cell>
21549 </row>
21550 <row topline="true">
21551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21552 \begin_inset Text
21553
21554 \begin_layout Standard
21555 18F4455
21556 \end_layout
21557
21558 \end_inset
21559 </cell>
21560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21561 \begin_inset Text
21562
21563 \begin_layout Standard
21564 18F6520
21565 \end_layout
21566
21567 \end_inset
21568 </cell>
21569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21570 \begin_inset Text
21571
21572 \begin_layout Standard
21573 18F6620
21574 \end_layout
21575
21576 \end_inset
21577 </cell>
21578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21579 \begin_inset Text
21580
21581 \begin_layout Standard
21582 18F6680
21583 \end_layout
21584
21585 \end_inset
21586 </cell>
21587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21588 \begin_inset Text
21589
21590 \begin_layout Standard
21591 18F6720
21592 \end_layout
21593
21594 \end_inset
21595 </cell>
21596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21597 \begin_inset Text
21598
21599 \begin_layout Standard
21600 18F8520
21601 \end_layout
21602
21603 \end_inset
21604 </cell>
21605 </row>
21606 <row topline="true" bottomline="true">
21607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21608 \begin_inset Text
21609
21610 \begin_layout Standard
21611 18F8620
21612 \end_layout
21613
21614 \end_inset
21615 </cell>
21616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21617 \begin_inset Text
21618
21619 \begin_layout Standard
21620 18F8680
21621 \end_layout
21622
21623 \end_inset
21624 </cell>
21625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21626 \begin_inset Text
21627
21628 \begin_layout Standard
21629 18F8720
21630 \end_layout
21631
21632 \end_inset
21633 </cell>
21634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21635 \begin_inset Text
21636
21637 \begin_layout Standard
21638
21639 \end_layout
21640
21641 \end_inset
21642 </cell>
21643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21644 \begin_inset Text
21645
21646 \begin_layout Standard
21647
21648 \end_layout
21649
21650 \end_inset
21651 </cell>
21652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21653 \begin_inset Text
21654
21655 \begin_layout Standard
21656
21657 \end_layout
21658
21659 \end_inset
21660 </cell>
21661 </row>
21662 </lyxtabular>
21663
21664 \end_inset
21665
21666
21667 \end_layout
21668
21669 \begin_layout Subsection
21670 Global Options
21671 \end_layout
21672
21673 \begin_layout Standard
21674 PIC16 port supports the standard command line arguments as supposed, with
21675  the exception of certain cases that will be mentioned in the following
21676  list:
21677 \end_layout
21678
21679 \begin_layout List
21680 \labelwidthstring 00.00.0000
21681 -
21682 \begin_inset ERT
21683 status collapsed
21684
21685 \begin_layout Standard
21686
21687
21688 \backslash
21689 /
21690 \end_layout
21691
21692 \end_inset
21693
21694 -callee-saves
21695 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
21696
21697 \end_inset
21698
21699  See -
21700 \begin_inset ERT
21701 status collapsed
21702
21703 \begin_layout Standard
21704
21705
21706 \backslash
21707 /
21708 \end_layout
21709
21710 \end_inset
21711
21712 -all-callee-saves
21713 \end_layout
21714
21715 \begin_layout List
21716 \labelwidthstring 00.00.0000
21717 -
21718 \begin_inset ERT
21719 status collapsed
21720
21721 \begin_layout Standard
21722
21723
21724 \backslash
21725 /
21726 \end_layout
21727
21728 \end_inset
21729
21730 -all-callee-saves
21731 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
21732
21733 \end_inset
21734
21735  All function arguments are passed on stack by default.
21736  
21737 \emph on
21738 There is no need to specify this in the command line.
21739 \end_layout
21740
21741 \begin_layout List
21742 \labelwidthstring 00.00.0000
21743 -
21744 \begin_inset ERT
21745 status collapsed
21746
21747 \begin_layout Standard
21748
21749
21750 \backslash
21751 /
21752 \end_layout
21753
21754 \end_inset
21755
21756 -fommit-frame-pointer
21757 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
21758
21759 \end_inset
21760
21761  Frame pointer will be omitted when the function uses no local variables.
21762 \end_layout
21763
21764 \begin_layout Subsection
21765 Port Specific Options
21766 \begin_inset LatexCommand \index{Options PIC16}
21767
21768 \end_inset
21769
21770
21771 \end_layout
21772
21773 \begin_layout Standard
21774 The port specific options appear after the global options in the sdcc --help
21775  output.
21776 \end_layout
21777
21778 \begin_layout Subsubsection
21779 General Options
21780 \end_layout
21781
21782 \begin_layout Standard
21783 General options enable certain port features and optimizations.
21784 \end_layout
21785
21786 \begin_layout List
21787 \labelwidthstring 00.00.0000
21788 -
21789 \begin_inset ERT
21790 status collapsed
21791
21792 \begin_layout Standard
21793
21794
21795 \backslash
21796 /
21797 \end_layout
21798
21799 \end_inset
21800
21801 -pstack-model=[model] Used in conjuction with the command above.
21802  Defines the stack model to be used, valid stack models are : 
21803 \end_layout
21804
21805 \begin_deeper
21806 \begin_layout List
21807 \labelwidthstring 00.00.0000
21808
21809 \emph on
21810 small
21811 \emph default
21812  Selects small stack model.
21813  8 bit stack and frame pointers.
21814  Supports 256 bytes stack size.
21815 \end_layout
21816
21817 \begin_layout List
21818 \labelwidthstring 00.00.0000
21819
21820 \emph on
21821 large
21822 \emph default
21823  Selects large stack model.
21824  16 bit stack and frame pointers.
21825  Supports 65536 bytes stack size.
21826 \end_layout
21827
21828 \end_deeper
21829 \begin_layout List
21830 \labelwidthstring 00.00.0000
21831 -
21832 \begin_inset ERT
21833 status collapsed
21834
21835 \begin_layout Standard
21836
21837
21838 \backslash
21839 /
21840 \end_layout
21841
21842 \end_inset
21843
21844 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
21845  unitialized data variables with [kword].
21846  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
21847 \end_layout
21848
21849 \begin_layout List
21850 \labelwidthstring 00.00.0000
21851 -
21852 \begin_inset ERT
21853 status collapsed
21854
21855 \begin_layout Standard
21856
21857
21858 \backslash
21859 /
21860 \end_layout
21861
21862 \end_inset
21863
21864 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
21865  Useful for bootloaders.
21866 \end_layout
21867
21868 \begin_layout List
21869 \labelwidthstring 00.00.0000
21870 -
21871 \begin_inset ERT
21872 status collapsed
21873
21874 \begin_layout Standard
21875
21876
21877 \backslash
21878 /
21879 \end_layout
21880
21881 \end_inset
21882
21883 -asm= sets the full path and name of an external assembler to call.
21884 \end_layout
21885
21886 \begin_layout List
21887 \labelwidthstring 00.00.0000
21888 -
21889 \begin_inset ERT
21890 status collapsed
21891
21892 \begin_layout Standard
21893
21894
21895 \backslash
21896 /
21897 \end_layout
21898
21899 \end_inset
21900
21901 -link= sets the full path and name of an external linker to call.
21902 \end_layout
21903
21904 \begin_layout List
21905 \labelwidthstring 00.00.0000
21906 -
21907 \begin_inset ERT
21908 status collapsed
21909
21910 \begin_layout Standard
21911
21912
21913 \backslash
21914 /
21915 \end_layout
21916
21917 \end_inset
21918
21919 -mplab-comp MPLAB
21920 \begin_inset LatexCommand \index{PIC16!MPLAB}
21921
21922 \end_inset
21923
21924  compatibility option.
21925  Currently only suppresses special gpasm directives.
21926 \end_layout
21927
21928 \begin_layout Subsubsection
21929 Optimization Options
21930 \end_layout
21931
21932 \begin_layout List
21933 \labelwidthstring 00.00.0000
21934 -
21935 \begin_inset ERT
21936 status collapsed
21937
21938 \begin_layout Standard
21939
21940
21941 \backslash
21942 /
21943 \end_layout
21944
21945 \end_inset
21946
21947 -optimize-goto Try to use (conditional) BRA instead of GOTO
21948 \end_layout
21949
21950 \begin_layout List
21951 \labelwidthstring 00.00.0000
21952 -
21953 \begin_inset ERT
21954 status collapsed
21955
21956 \begin_layout Standard
21957
21958
21959 \backslash
21960 /
21961 \end_layout
21962
21963 \end_inset
21964
21965 -optimize-cmp Try to optimize some compares.
21966 \end_layout
21967
21968 \begin_layout List
21969 \labelwidthstring 00.00.0000
21970 -
21971 \begin_inset ERT
21972 status collapsed
21973
21974 \begin_layout Standard
21975
21976
21977 \backslash
21978 /
21979 \end_layout
21980
21981 \end_inset
21982
21983 -optimize-df Analyze the dataflow of the generated code and improve it.
21984 \end_layout
21985
21986 \begin_layout List
21987 \labelwidthstring 00.00.0000
21988 -
21989 \begin_inset ERT
21990 status collapsed
21991
21992 \begin_layout Standard
21993
21994
21995 \backslash
21996 /
21997 \end_layout
21998
21999 \end_inset
22000
22001 -obanksel=nn Set optimization level for inserting BANKSELs.
22002 \newline
22003
22004 \end_layout
22005
22006 \begin_deeper
22007 \begin_layout List
22008 \labelwidthstring 00.00.0000
22009 0 no optimization
22010 \end_layout
22011
22012 \begin_layout List
22013 \labelwidthstring 00.00.0000
22014 1 checks previous used register and if it is the same then does not emit
22015  BANKSEL, accounts only for labels.
22016 \end_layout
22017
22018 \begin_layout List
22019 \labelwidthstring 00.00.0000
22020 2 tries to check the location of (even different) symbols and removes BANKSELs
22021  if they are in the same bank.
22022  
22023 \newline
22024
22025 \emph on
22026 Important: There might be problems if the linker script has data sections
22027  across bank borders!
22028 \end_layout
22029
22030 \end_deeper
22031 \begin_layout Subsubsection
22032 Linking Options
22033 \end_layout
22034
22035 \begin_layout List
22036 \labelwidthstring 00.00.0000
22037 -
22038 \begin_inset ERT
22039 status collapsed
22040
22041 \begin_layout Standard
22042
22043
22044 \backslash
22045 /
22046 \end_layout
22047
22048 \end_inset
22049
22050 -nodefaultlibs do not link default libraries when linking
22051 \end_layout
22052
22053 \begin_layout List
22054 \labelwidthstring 00.00.0000
22055 -
22056 \begin_inset ERT
22057 status collapsed
22058
22059 \begin_layout Standard
22060
22061
22062 \backslash
22063 /
22064 \end_layout
22065
22066 \end_inset
22067
22068 -no-crt Don't link the default run-time modules
22069 \end_layout
22070
22071 \begin_layout List
22072 \labelwidthstring 00.00.0000
22073 -
22074 \begin_inset ERT
22075 status collapsed
22076
22077 \begin_layout Standard
22078
22079
22080 \backslash
22081 /
22082 \end_layout
22083
22084 \end_inset
22085
22086 -use-crt= Use a custom run-time module instead of the defaults.
22087 \end_layout
22088
22089 \begin_layout Subsubsection
22090 Debugging Options
22091 \end_layout
22092
22093 \begin_layout Standard
22094 Debugging options enable extra debugging information in the output files.
22095 \end_layout
22096
22097 \begin_layout List
22098 \labelwidthstring 00.00.0000
22099 -
22100 \begin_inset ERT
22101 status collapsed
22102
22103 \begin_layout Standard
22104
22105
22106 \backslash
22107 /
22108 \end_layout
22109
22110 \end_inset
22111
22112 -debug-xtra Similar to -
22113 \begin_inset ERT
22114 status collapsed
22115
22116 \begin_layout Standard
22117
22118
22119 \backslash
22120 /
22121 \end_layout
22122
22123 \end_inset
22124
22125 -debug
22126 \begin_inset LatexCommand \index{-\/-debug}
22127
22128 \end_inset
22129
22130 , but dumps more information.
22131 \end_layout
22132
22133 \begin_layout List
22134 \labelwidthstring 00.00.0000
22135 -
22136 \begin_inset ERT
22137 status collapsed
22138
22139 \begin_layout Standard
22140
22141
22142 \backslash
22143 /
22144 \end_layout
22145
22146 \end_inset
22147
22148 -debug-ralloc Force register allocator to dump <source>.d file with debugging
22149  information.
22150  <source> is the name of the file compiled.
22151 \end_layout
22152
22153 \begin_layout List
22154 \labelwidthstring 00.00.0000
22155 -
22156 \begin_inset ERT
22157 status collapsed
22158
22159 \begin_layout Standard
22160
22161
22162 \backslash
22163 /
22164 \end_layout
22165
22166 \end_inset
22167
22168 -pcode-verbose Enable pcode debugging information in translation.
22169 \end_layout
22170
22171 \begin_layout List
22172 \labelwidthstring 00.00.0000
22173 -
22174 \begin_inset ERT
22175 status collapsed
22176
22177 \begin_layout Standard
22178
22179
22180 \backslash
22181 /
22182 \end_layout
22183
22184 \end_inset
22185
22186 -denable-peeps Force the usage of peepholes.
22187  Use with care.
22188 \end_layout
22189
22190 \begin_layout List
22191 \labelwidthstring 00.00.0000
22192 -
22193 \begin_inset ERT
22194 status collapsed
22195
22196 \begin_layout Standard
22197
22198
22199 \backslash
22200 /
22201 \end_layout
22202
22203 \end_inset
22204
22205 -gstack Trace push/pops for stack pointer overflow
22206 \end_layout
22207
22208 \begin_layout List
22209 \labelwidthstring 00.00.0000
22210 -
22211 \begin_inset ERT
22212 status collapsed
22213
22214 \begin_layout Standard
22215
22216
22217 \backslash
22218 /
22219 \end_layout
22220
22221 \end_inset
22222
22223 -call-tree dump call tree in .calltree file
22224 \end_layout
22225
22226 \begin_layout Subsection
22227 Enviromental Variables
22228 \end_layout
22229
22230 \begin_layout Standard
22231 There is a number of enviromental variables that can be used when running
22232  SDCC to enable certain optimizations or force a specific program behaviour.
22233  these variables are primarily for debugging purposes so they can be enabled/dis
22234 abled at will.
22235 \end_layout
22236
22237 \begin_layout Standard
22238 Currently there is only two such variables available:
22239 \end_layout
22240
22241 \begin_layout List
22242 \labelwidthstring 00.00.0000
22243 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
22244  bitfields is optimized by directly loading FSR0 with the address of the
22245  bitfield structure.
22246  Normally SDCC will cast the bitfield structure to a bitfield pointer and
22247  then load FSR0.
22248  This step saves data ram and code space for functions that perform heavy
22249  use of bitfields.
22250  (ie.
22251  80 bytes of code space are saved when compiling malloc.c with this option).
22252  
22253 \end_layout
22254
22255 \begin_layout List
22256 \labelwidthstring 00.00.0000
22257 NO_REG_OPT do not perform pCode registers optimization.
22258  This should be used for debugging purposes.
22259  In some where bugs in the pcode optimizer are found, users can benefit
22260  from temporarily disabling the optimizer until the bug is fixed.
22261 \end_layout
22262
22263 \begin_layout Subsection
22264 Preprocessor Macros
22265 \end_layout
22266
22267 \begin_layout Standard
22268 PIC16
22269 \begin_inset LatexCommand \index{PIC16}
22270
22271 \end_inset
22272
22273  port defines the following preprocessor macros while translating a source.
22274 \end_layout
22275
22276 \begin_layout Standard
22277 \align center
22278 \begin_inset Tabular
22279 <lyxtabular version="3" rows="6" columns="2">
22280 <features>
22281 <column alignment="center" valignment="top" leftline="true" width="0">
22282 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22283 <row topline="true" bottomline="true">
22284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22285 \begin_inset Text
22286
22287 \begin_layout Standard
22288 Macro
22289 \end_layout
22290
22291 \end_inset
22292 </cell>
22293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22294 \begin_inset Text
22295
22296 \begin_layout Standard
22297 Description
22298 \end_layout
22299
22300 \end_inset
22301 </cell>
22302 </row>
22303 <row topline="true">
22304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22305 \begin_inset Text
22306
22307 \begin_layout Standard
22308 SDCC_pic16
22309 \end_layout
22310
22311 \end_inset
22312 </cell>
22313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22314 \begin_inset Text
22315
22316 \begin_layout Standard
22317 Port identification
22318 \end_layout
22319
22320 \end_inset
22321 </cell>
22322 </row>
22323 <row topline="true">
22324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22325 \begin_inset Text
22326
22327 \begin_layout Standard
22328 _
22329 \begin_inset ERT
22330 status collapsed
22331
22332 \begin_layout Standard
22333
22334
22335 \backslash
22336 /
22337 \end_layout
22338
22339 \end_inset
22340
22341 _pic16
22342 \end_layout
22343
22344 \end_inset
22345 </cell>
22346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22347 \begin_inset Text
22348
22349 \begin_layout Standard
22350 Port identification (same as above)
22351 \end_layout
22352
22353 \end_inset
22354 </cell>
22355 </row>
22356 <row topline="true">
22357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22358 \begin_inset Text
22359
22360 \begin_layout Standard
22361 pic18fxxxx
22362 \end_layout
22363
22364 \end_inset
22365 </cell>
22366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22367 \begin_inset Text
22368
22369 \begin_layout Standard
22370 MCU Identification.
22371  
22372 \emph on
22373 xxxx
22374 \emph default
22375  is the microcontrol identification number, i.e.
22376  452, 6620, etc
22377 \end_layout
22378
22379 \end_inset
22380 </cell>
22381 </row>
22382 <row topline="true">
22383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22384 \begin_inset Text
22385
22386 \begin_layout Standard
22387 _
22388 \begin_inset ERT
22389 status collapsed
22390
22391 \begin_layout Standard
22392
22393
22394 \backslash
22395 /
22396 \end_layout
22397
22398 \end_inset
22399
22400 _18Fxxxx
22401 \end_layout
22402
22403 \end_inset
22404 </cell>
22405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22406 \begin_inset Text
22407
22408 \begin_layout Standard
22409 MCU Identification (same as above)
22410 \end_layout
22411
22412 \end_inset
22413 </cell>
22414 </row>
22415 <row topline="true" bottomline="true">
22416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22417 \begin_inset Text
22418
22419 \begin_layout Standard
22420 STACK_MODEL_nnn
22421 \end_layout
22422
22423 \end_inset
22424 </cell>
22425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22426 \begin_inset Text
22427
22428 \begin_layout Standard
22429 nnn = SMALL or LARGE respectively according to the stack model used
22430 \end_layout
22431
22432 \end_inset
22433 </cell>
22434 </row>
22435 </lyxtabular>
22436
22437 \end_inset
22438
22439
22440 \end_layout
22441
22442 \begin_layout Standard
22443 In addition the following macros are defined when calling assembler:
22444 \end_layout
22445
22446 \begin_layout Standard
22447 \align center
22448 \begin_inset Tabular
22449 <lyxtabular version="3" rows="4" columns="2">
22450 <features>
22451 <column alignment="center" valignment="top" leftline="true" width="0">
22452 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22453 <row topline="true" bottomline="true">
22454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22455 \begin_inset Text
22456
22457 \begin_layout Standard
22458 Macro
22459 \end_layout
22460
22461 \end_inset
22462 </cell>
22463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22464 \begin_inset Text
22465
22466 \begin_layout Standard
22467 Description
22468 \end_layout
22469
22470 \end_inset
22471 </cell>
22472 </row>
22473 <row topline="true">
22474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22475 \begin_inset Text
22476
22477 \begin_layout Standard
22478 __18Fxxxx
22479 \end_layout
22480
22481 \end_inset
22482 </cell>
22483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22484 \begin_inset Text
22485
22486 \begin_layout Standard
22487 MCU Identification.
22488  
22489 \emph on
22490 xxxx
22491 \emph default
22492  is the microcontrol identification number, i.e.
22493  452, 6620, etc
22494 \end_layout
22495
22496 \end_inset
22497 </cell>
22498 </row>
22499 <row topline="true">
22500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22501 \begin_inset Text
22502
22503 \begin_layout Standard
22504 SDCC_MODEL_nnn
22505 \end_layout
22506
22507 \end_inset
22508 </cell>
22509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22510 \begin_inset Text
22511
22512 \begin_layout Standard
22513 nnn = SMALL or LARGE respectively according to the memory model used for
22514  SDCC
22515 \end_layout
22516
22517 \end_inset
22518 </cell>
22519 </row>
22520 <row topline="true" bottomline="true">
22521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22522 \begin_inset Text
22523
22524 \begin_layout Standard
22525 STACK_MODEL_nnn
22526 \end_layout
22527
22528 \end_inset
22529 </cell>
22530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22531 \begin_inset Text
22532
22533 \begin_layout Standard
22534 nnn = SMALL or LARGE respectively according to the stack model used
22535 \end_layout
22536
22537 \end_inset
22538 </cell>
22539 </row>
22540 </lyxtabular>
22541
22542 \end_inset
22543
22544
22545 \end_layout
22546
22547 \begin_layout Subsection
22548 Directories
22549 \end_layout
22550
22551 \begin_layout Standard
22552 PIC16
22553 \begin_inset LatexCommand \index{PIC16}
22554
22555 \end_inset
22556
22557  port uses the following directories for searching header files and libraries.
22558 \end_layout
22559
22560 \begin_layout Standard
22561 \align center
22562 \begin_inset Tabular
22563 <lyxtabular version="3" rows="3" columns="4">
22564 <features>
22565 <column alignment="center" valignment="top" leftline="true" width="0">
22566 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22567 <column alignment="center" valignment="top" width="0">
22568 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22569 <row topline="true" bottomline="true">
22570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22571 \begin_inset Text
22572
22573 \begin_layout Standard
22574 Directory
22575 \end_layout
22576
22577 \end_inset
22578 </cell>
22579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22580 \begin_inset Text
22581
22582 \begin_layout Standard
22583 Description
22584 \end_layout
22585
22586 \end_inset
22587 </cell>
22588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22589 \begin_inset Text
22590
22591 \begin_layout Standard
22592 Target
22593 \end_layout
22594
22595 \end_inset
22596 </cell>
22597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22598 \begin_inset Text
22599
22600 \begin_layout Standard
22601 Command prefix
22602 \end_layout
22603
22604 \end_inset
22605 </cell>
22606 </row>
22607 <row topline="true">
22608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22609 \begin_inset Text
22610
22611 \begin_layout Standard
22612 PREFIX/sdcc/include/pic16
22613 \end_layout
22614
22615 \end_inset
22616 </cell>
22617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22618 \begin_inset Text
22619
22620 \begin_layout Standard
22621 PIC16 specific headers
22622 \end_layout
22623
22624 \end_inset
22625 </cell>
22626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22627 \begin_inset Text
22628
22629 \begin_layout Standard
22630 Compiler
22631 \end_layout
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 \begin_layout Standard
22639 -I
22640 \end_layout
22641
22642 \end_inset
22643 </cell>
22644 </row>
22645 <row topline="true" bottomline="true">
22646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22647 \begin_inset Text
22648
22649 \begin_layout Standard
22650 PREFIX/sdcc/lib/pic16
22651 \end_layout
22652
22653 \end_inset
22654 </cell>
22655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22656 \begin_inset Text
22657
22658 \begin_layout Standard
22659 PIC16 specific libraries
22660 \end_layout
22661
22662 \end_inset
22663 </cell>
22664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22665 \begin_inset Text
22666
22667 \begin_layout Standard
22668 Linker
22669 \end_layout
22670
22671 \end_inset
22672 </cell>
22673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22674 \begin_inset Text
22675
22676 \begin_layout Standard
22677 -L
22678 \end_layout
22679
22680 \end_inset
22681 </cell>
22682 </row>
22683 </lyxtabular>
22684
22685 \end_inset
22686
22687
22688 \end_layout
22689
22690 \begin_layout Subsection
22691 Pragmas
22692 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
22693
22694 \end_inset
22695
22696
22697 \end_layout
22698
22699 \begin_layout Standard
22700 PIC16
22701 \begin_inset LatexCommand \index{PIC16}
22702
22703 \end_inset
22704
22705  port currently supports the following pragmas:
22706 \end_layout
22707
22708 \begin_layout List
22709 \labelwidthstring 00.00.0000
22710 stack
22711 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
22712
22713 \end_inset
22714
22715  pragma stack
22716 \begin_inset LatexCommand \index{PIC16!stack}
22717
22718 \end_inset
22719
22720  forces the code generator to initialize the stack & frame pointers at a
22721  specific address.
22722  This is an adhoc solution for cases where no STACK directive is available
22723  in the linker script or gplink is not instructed to create a stack section.
22724 \newline
22725 The
22726  stack pragma should be used only once in a project.
22727  Multiple pragmas may result in indeterminate behaviour of the program.
22728 \begin_inset Foot
22729 status open
22730
22731 \begin_layout Standard
22732 The old format (ie.
22733  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
22734  cross page boundaries (or even exceed the available data RAM) and crash
22735  the program.
22736  Make sure that stack does not cross page boundaries when using the SMALL
22737  stack model.
22738 \end_layout
22739
22740 \end_inset
22741
22742
22743 \newline
22744 The format is as follows:
22745 \end_layout
22746
22747 \begin_layout LyX-Code
22748 #pragma stack bottom_address [stack_size]
22749 \end_layout
22750
22751 \begin_layout Standard
22752
22753 \emph on
22754 bottom_address
22755 \emph default
22756  is the lower bound of the stack section.
22757  The stack pointer initially will point at address (bottom_address+stack_size-1).
22758 \end_layout
22759
22760 \begin_layout LyX-Code
22761 Example:
22762 \end_layout
22763
22764 \begin_layout LyX-Code
22765
22766 \end_layout
22767
22768 \begin_layout LyX-Code
22769 /* initializes stack of 100 bytes at RAM address 0x200 */
22770 \end_layout
22771
22772 \begin_layout LyX-Code
22773 #pragma stack 0x200 100
22774 \end_layout
22775
22776 \begin_layout Standard
22777 If the stack_size field is omitted then a stack is created with the default
22778  size of 64.
22779  This size might be enough for most programs, but its not enough for operations
22780  with deep function nesting or excessive stack usage.
22781 \end_layout
22782
22783 \begin_layout List
22784 \labelwidthstring 00.00.0000
22785 code
22786 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
22787
22788 \end_inset
22789
22790  place a function symbol at static FLASH address
22791 \end_layout
22792
22793 \begin_layout LyX-Code
22794 Example:
22795 \end_layout
22796
22797 \begin_layout LyX-Code
22798
22799 \end_layout
22800
22801 \begin_layout LyX-Code
22802 /* place function test_func at 0x4000 */
22803 \end_layout
22804
22805 \begin_layout LyX-Code
22806 #pragma code test_func 0x4000
22807 \end_layout
22808
22809 \begin_layout LyX-Code
22810
22811 \end_layout
22812
22813 \begin_layout List
22814 \labelwidthstring 00.00.0000
22815 library instructs the linker to use a library module.
22816 \newline
22817 Usage:
22818 \end_layout
22819
22820 \begin_layout LyX-Code
22821 #pragma library module_name
22822 \end_layout
22823
22824 \begin_layout Standard
22825
22826 \emph on
22827 module_name
22828 \emph default
22829  can be any library or object file (including its path).
22830  Note that there are four reserved keywords which have special meaning.
22831  These are:
22832 \end_layout
22833
22834 \begin_layout Standard
22835 \align center
22836 \begin_inset Tabular
22837 <lyxtabular version="3" rows="6" columns="3">
22838 <features>
22839 <column alignment="center" valignment="top" leftline="true" width="0">
22840 <column alignment="block" valignment="top" leftline="true" width="20page%">
22841 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
22842 <row topline="true" bottomline="true">
22843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22844 \begin_inset Text
22845
22846 \begin_layout Standard
22847 Keyword
22848 \end_layout
22849
22850 \end_inset
22851 </cell>
22852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22853 \begin_inset Text
22854
22855 \begin_layout Standard
22856 Description
22857 \end_layout
22858
22859 \end_inset
22860 </cell>
22861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22862 \begin_inset Text
22863
22864 \begin_layout Standard
22865 Module to link
22866 \end_layout
22867
22868 \end_inset
22869 </cell>
22870 </row>
22871 <row topline="true">
22872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22873 \begin_inset Text
22874
22875 \begin_layout Standard
22876
22877 \series bold
22878 ignore
22879 \end_layout
22880
22881 \end_inset
22882 </cell>
22883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22884 \begin_inset Text
22885
22886 \begin_layout Standard
22887 ignore all library pragmas
22888 \end_layout
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 \begin_layout Standard
22896
22897 \emph on
22898 (none)
22899 \end_layout
22900
22901 \end_inset
22902 </cell>
22903 </row>
22904 <row topline="true">
22905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22906 \begin_inset Text
22907
22908 \begin_layout Standard
22909
22910 \series bold
22911 c
22912 \end_layout
22913
22914 \end_inset
22915 </cell>
22916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22917 \begin_inset Text
22918
22919 \begin_layout Standard
22920 link the C library
22921 \end_layout
22922
22923 \end_inset
22924 </cell>
22925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22926 \begin_inset Text
22927
22928 \begin_layout Standard
22929
22930 \emph on
22931 libc18f
22932 \emph default
22933 .lib
22934 \end_layout
22935
22936 \end_inset
22937 </cell>
22938 </row>
22939 <row topline="true">
22940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22941 \begin_inset Text
22942
22943 \begin_layout Standard
22944
22945 \series bold
22946 math
22947 \end_layout
22948
22949 \end_inset
22950 </cell>
22951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22952 \begin_inset Text
22953
22954 \begin_layout Standard
22955 link the Math libarary
22956 \end_layout
22957
22958 \end_inset
22959 </cell>
22960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22961 \begin_inset Text
22962
22963 \begin_layout Standard
22964
22965 \emph on
22966 libm18f
22967 \emph default
22968 .lib
22969 \end_layout
22970
22971 \end_inset
22972 </cell>
22973 </row>
22974 <row topline="true">
22975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22976 \begin_inset Text
22977
22978 \begin_layout Standard
22979
22980 \series bold
22981 io
22982 \end_layout
22983
22984 \end_inset
22985 </cell>
22986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22987 \begin_inset Text
22988
22989 \begin_layout Standard
22990 link the I/O library
22991 \end_layout
22992
22993 \end_inset
22994 </cell>
22995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22996 \begin_inset Text
22997
22998 \begin_layout Standard
22999
23000 \emph on
23001 libio18f*
23002 \emph default
23003 .lib
23004 \end_layout
23005
23006 \end_inset
23007 </cell>
23008 </row>
23009 <row topline="true" bottomline="true">
23010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23011 \begin_inset Text
23012
23013 \begin_layout Standard
23014
23015 \series bold
23016 debug
23017 \end_layout
23018
23019 \end_inset
23020 </cell>
23021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23022 \begin_inset Text
23023
23024 \begin_layout Standard
23025 link the debug library
23026 \end_layout
23027
23028 \end_inset
23029 </cell>
23030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23031 \begin_inset Text
23032
23033 \begin_layout Standard
23034
23035 \emph on
23036 libdebug
23037 \emph default
23038 .lib
23039 \end_layout
23040
23041 \end_inset
23042 </cell>
23043 </row>
23044 </lyxtabular>
23045
23046 \end_inset
23047
23048
23049 \newline
23050 * is the device number, i.e.
23051  452 for PIC18F452 MCU.
23052 \end_layout
23053
23054 \begin_layout Standard
23055 This feature allows for linking with specific libraries withoug having to
23056  explicit name them in the command line.
23057  Note that the 
23058 \noun on
23059 ignore
23060 \noun default
23061  keyword will reject all modules specified by the library pragma.
23062 \end_layout
23063
23064 \begin_layout List
23065 \labelwidthstring 00.00.0000
23066 udata pragma udata instructs the compiler to emit code so that linker will
23067  place a variable at a specific memory bank
23068 \end_layout
23069
23070 \begin_layout LyX-Code
23071 Example:
23072 \end_layout
23073
23074 \begin_layout LyX-Code
23075
23076 \end_layout
23077
23078 \begin_layout LyX-Code
23079 /* places variable foo at bank2 */
23080 \end_layout
23081
23082 \begin_layout LyX-Code
23083 #pragma udata bank2 foo
23084 \end_layout
23085
23086 \begin_layout LyX-Code
23087 char foo;
23088 \end_layout
23089
23090 \begin_layout Standard
23091 In order for this pragma to work extra SECTION directives should be added
23092  in the .lkr script.
23093  In the following example a sample .lkr file is shown:
23094 \end_layout
23095
23096 \begin_layout LyX-Code
23097
23098 \end_layout
23099
23100 \begin_layout LyX-Code
23101 // Sample linker script for the PIC18F452 processor
23102 \end_layout
23103
23104 \begin_layout LyX-Code
23105 LIBPATH .
23106 \end_layout
23107
23108 \begin_layout LyX-Code
23109 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
23110 \end_layout
23111
23112 \begin_layout LyX-Code
23113 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
23114 \end_layout
23115
23116 \begin_layout LyX-Code
23117 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
23118 \end_layout
23119
23120 \begin_layout LyX-Code
23121 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
23122 \end_layout
23123
23124 \begin_layout LyX-Code
23125 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
23126 \end_layout
23127
23128 \begin_layout LyX-Code
23129 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
23130 \end_layout
23131
23132 \begin_layout LyX-Code
23133 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
23134 \end_layout
23135
23136 \begin_layout LyX-Code
23137
23138 \end_layout
23139
23140 \begin_layout LyX-Code
23141 DATABANK   NAME=gpr0       START=0x80           END=0xFF
23142 \end_layout
23143
23144 \begin_layout LyX-Code
23145 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
23146 \end_layout
23147
23148 \begin_layout LyX-Code
23149 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
23150 \end_layout
23151
23152 \begin_layout LyX-Code
23153 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
23154 \end_layout
23155
23156 \begin_layout LyX-Code
23157 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
23158 \end_layout
23159
23160 \begin_layout LyX-Code
23161 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
23162 \end_layout
23163
23164 \begin_layout LyX-Code
23165 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
23166 \end_layout
23167
23168 \begin_layout LyX-Code
23169
23170 \end_layout
23171
23172 \begin_layout LyX-Code
23173 SECTION    NAME=CONFIG     ROM=config
23174 \end_layout
23175
23176 \begin_layout LyX-Code
23177
23178 \end_layout
23179
23180 \begin_layout LyX-Code
23181 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
23182 \end_layout
23183
23184 \begin_layout LyX-Code
23185 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
23186 \end_layout
23187
23188 \begin_layout LyX-Code
23189 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
23190 \end_layout
23191
23192 \begin_layout LyX-Code
23193 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
23194 \end_layout
23195
23196 \begin_layout LyX-Code
23197 SECTION    NAME=bank4      RAM=gpr4
23198 \end_layout
23199
23200 \begin_layout LyX-Code
23201 SECTION    NAME=bank5      RAM=gpr5
23202 \end_layout
23203
23204 \begin_layout Standard
23205 The linker will recognise the section name set in the pragma statement and
23206  will position the variable at the memory bank set with the RAM field at
23207  the SECTION line in the linker script file.
23208 \end_layout
23209
23210 \begin_layout Subsection
23211 Header Files
23212 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
23213
23214 \end_inset
23215
23216
23217 \end_layout
23218
23219 \begin_layout Standard
23220 There is one main header file
23221 \begin_inset LatexCommand \index{PIC16!Header files}
23222
23223 \end_inset
23224
23225  that can be included to the source files using the pic16
23226 \begin_inset LatexCommand \index{PIC16}
23227
23228 \end_inset
23229
23230  port.
23231  That file is the 
23232 \series bold
23233 pic18fregs.h
23234 \series default
23235 .
23236  This header file contains the definitions for the processor special registers,
23237  so it is necessary if the source accesses them.
23238  It can be included by adding the following line in the beginning of the
23239  file:
23240 \end_layout
23241
23242 \begin_layout LyX-Code
23243 #include <pic18fregs.h>
23244 \end_layout
23245
23246 \begin_layout Standard
23247 The specific microcontroller is selected within the pic18fregs.h automatically,
23248  so the same source can be used with a variety of devices.
23249 \end_layout
23250
23251 \begin_layout Subsection
23252 Libraries
23253 \end_layout
23254
23255 \begin_layout Standard
23256 The libraries
23257 \begin_inset LatexCommand \index{PIC16!Libraries}
23258
23259 \end_inset
23260
23261  that PIC16
23262 \begin_inset LatexCommand \index{PIC16}
23263
23264 \end_inset
23265
23266  port depends on are the microcontroller device libraries which contain
23267  the symbol definitions for the microcontroller special function registers.
23268  These libraries have the format pic18fxxxx.lib, where 
23269 \emph on
23270 xxxx
23271 \emph default
23272  is the microcontroller identification number.
23273  The specific library is selected automatically by the compiler at link
23274  stage according to the selected device.
23275 \end_layout
23276
23277 \begin_layout Standard
23278 Libraries are created with gplib which is part of the gputils package 
23279 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23280
23281 \end_inset
23282
23283 .
23284 \end_layout
23285
23286 \begin_layout Subsubsection*
23287 Building the libraries
23288 \end_layout
23289
23290 \begin_layout Standard
23291 Before using SDCC/pic16 there are some libraries that need to be compiled.
23292  This process is not done automatically by SDCC since not all users use
23293  SDCC for pic16 projects.
23294  So each user should compile the libraries separately.
23295 \end_layout
23296
23297 \begin_layout Standard
23298 The steps to compile the pic16 libraries under Linux are:
23299 \end_layout
23300
23301 \begin_layout LyX-Code
23302 cd device/lib/pic16
23303 \end_layout
23304
23305 \begin_layout LyX-Code
23306 ./configure
23307 \end_layout
23308
23309 \begin_layout LyX-Code
23310 make
23311 \end_layout
23312
23313 \begin_layout LyX-Code
23314 cd ..
23315 \end_layout
23316
23317 \begin_layout LyX-Code
23318 make model-pic16
23319 \end_layout
23320
23321 \begin_layout LyX-Code
23322 su -c 'make install'     # install the libraries, you need the root password
23323 \end_layout
23324
23325 \begin_layout Standard
23326 If you need to install the headers too, do:
23327 \end_layout
23328
23329 \begin_layout LyX-Code
23330 cd device/include
23331 \end_layout
23332
23333 \begin_layout LyX-Code
23334 su -c 'make install'     # install the headers, you need the root password
23335 \end_layout
23336
23337 \begin_layout Standard
23338 There exist a special target to build the I/O libraries.
23339  This target is not automatically build because it will build the I/O library
23340  for 
23341 \emph on
23342 every
23343 \emph default
23344  supported device.
23345  This way building will take quite a lot of time.
23346  Users are advised to edit the 
23347 \series bold
23348 device/lib/pic16/pics.build
23349 \series default
23350  file and then execute:
23351 \end_layout
23352
23353 \begin_layout LyX-Code
23354 make lib-io
23355 \end_layout
23356
23357 \begin_layout Subsection
23358 Memory Models
23359 \end_layout
23360
23361 \begin_layout Standard
23362 The following memory models are supported by the PIC16 port:
23363 \end_layout
23364
23365 \begin_layout Itemize
23366 small model
23367 \end_layout
23368
23369 \begin_layout Itemize
23370 large model
23371 \end_layout
23372
23373 \begin_layout Standard
23374 Memory model affects the default size of pointers within the source.
23375  The sizes are shown in the next table:
23376 \end_layout
23377
23378 \begin_layout Standard
23379 \align center
23380 \begin_inset Tabular
23381 <lyxtabular version="3" rows="3" columns="3">
23382 <features>
23383 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23384 <column alignment="center" valignment="top" leftline="true" width="0">
23385 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23386 <row topline="true" bottomline="true">
23387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23388 \begin_inset Text
23389
23390 \begin_layout Standard
23391 Pointer sizes according to memory model
23392 \end_layout
23393
23394 \end_inset
23395 </cell>
23396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23397 \begin_inset Text
23398
23399 \begin_layout Standard
23400 small model
23401 \end_layout
23402
23403 \end_inset
23404 </cell>
23405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23406 \begin_inset Text
23407
23408 \begin_layout Standard
23409 large model
23410 \end_layout
23411
23412 \end_inset
23413 </cell>
23414 </row>
23415 <row topline="true" bottomline="true">
23416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23417 \begin_inset Text
23418
23419 \begin_layout Standard
23420 code pointers
23421 \end_layout
23422
23423 \end_inset
23424 </cell>
23425 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23426 \begin_inset Text
23427
23428 \begin_layout Standard
23429 16-bits
23430 \end_layout
23431
23432 \end_inset
23433 </cell>
23434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23435 \begin_inset Text
23436
23437 \begin_layout Standard
23438 24-bits
23439 \end_layout
23440
23441 \end_inset
23442 </cell>
23443 </row>
23444 <row topline="true" bottomline="true">
23445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23446 \begin_inset Text
23447
23448 \begin_layout Standard
23449 data pointers
23450 \end_layout
23451
23452 \end_inset
23453 </cell>
23454 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
23455 \begin_inset Text
23456
23457 \begin_layout Standard
23458 16-bits
23459 \end_layout
23460
23461 \end_inset
23462 </cell>
23463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23464 \begin_inset Text
23465
23466 \begin_layout Standard
23467 16-bits
23468 \end_layout
23469
23470 \end_inset
23471 </cell>
23472 </row>
23473 </lyxtabular>
23474
23475 \end_inset
23476
23477
23478 \end_layout
23479
23480 \begin_layout Standard
23481 It is advisable that all sources within a project are compiled with the
23482  same memory model.
23483  If one wants to override the default memory model, this can be done by
23484  declaring a pointer as 
23485 \series bold
23486 far
23487 \series default
23488  or 
23489 \series bold
23490 near
23491 \series default
23492 .
23493  Far selects large memory model's pointers, while near selects small memory
23494  model's pointers.
23495 \end_layout
23496
23497 \begin_layout Standard
23498 The standard device libraries (see 
23499 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
23500
23501 \end_inset
23502
23503 ) contain no reference to pointers, so they can be used with both memory
23504  models.
23505 \end_layout
23506
23507 \begin_layout Subsection
23508 Stack
23509 \end_layout
23510
23511 \begin_layout Standard
23512 The stack
23513 \begin_inset LatexCommand \index{PIC16!stack}
23514
23515 \end_inset
23516
23517  implementation for the PIC16 port uses two indirect registers, FSR1 and
23518  FSR2.
23519 \end_layout
23520
23521 \begin_layout List
23522 \labelwidthstring 00.00.0000
23523 FSR1 is assigned as stack pointer
23524 \end_layout
23525
23526 \begin_layout List
23527 \labelwidthstring 00.00.0000
23528 FSR2 is assigned as frame pointer
23529 \end_layout
23530
23531 \begin_layout Standard
23532 The following stack models are supported by the PIC16 port
23533 \end_layout
23534
23535 \begin_layout Itemize
23536
23537 \noun on
23538 small
23539 \noun default
23540  model
23541 \end_layout
23542
23543 \begin_layout Itemize
23544
23545 \noun on
23546 large
23547 \noun default
23548  model
23549 \end_layout
23550
23551 \begin_layout Standard
23552
23553 \noun on
23554 Small
23555 \noun default
23556  model means that only the FSRxL byte is used to access stack and frame,
23557  while 
23558 \emph on
23559 \noun on
23560 large
23561 \emph default
23562 \noun default
23563  uses both FSRxL and FSRxH registers.
23564  The following table shows the stack/frame pointers sizes according to stack
23565  model and the maximum space they can address:
23566 \end_layout
23567
23568 \begin_layout Standard
23569 \align center
23570 \begin_inset Tabular
23571 <lyxtabular version="3" rows="3" columns="3">
23572 <features>
23573 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23574 <column alignment="center" valignment="top" leftline="true" width="0">
23575 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23576 <row topline="true" bottomline="true">
23577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23578 \begin_inset Text
23579
23580 \begin_layout Standard
23581 Stack & Frame pointer sizes according to stack model
23582 \end_layout
23583
23584 \end_inset
23585 </cell>
23586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23587 \begin_inset Text
23588
23589 \begin_layout Standard
23590 small
23591 \end_layout
23592
23593 \end_inset
23594 </cell>
23595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23596 \begin_inset Text
23597
23598 \begin_layout Standard
23599 large
23600 \end_layout
23601
23602 \end_inset
23603 </cell>
23604 </row>
23605 <row topline="true">
23606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23607 \begin_inset Text
23608
23609 \begin_layout Standard
23610 Stack pointer FSR1
23611 \end_layout
23612
23613 \end_inset
23614 </cell>
23615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23616 \begin_inset Text
23617
23618 \begin_layout Standard
23619 8-bits
23620 \end_layout
23621
23622 \end_inset
23623 </cell>
23624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23625 \begin_inset Text
23626
23627 \begin_layout Standard
23628 16-bits
23629 \end_layout
23630
23631 \end_inset
23632 </cell>
23633 </row>
23634 <row topline="true" bottomline="true">
23635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23636 \begin_inset Text
23637
23638 \begin_layout Standard
23639 Frame pointer FSR2
23640 \end_layout
23641
23642 \end_inset
23643 </cell>
23644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23645 \begin_inset Text
23646
23647 \begin_layout Standard
23648 8-bits
23649 \end_layout
23650
23651 \end_inset
23652 </cell>
23653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23654 \begin_inset Text
23655
23656 \begin_layout Standard
23657 16-bits
23658 \end_layout
23659
23660 \end_inset
23661 </cell>
23662 </row>
23663 </lyxtabular>
23664
23665 \end_inset
23666
23667
23668 \end_layout
23669
23670 \begin_layout Standard
23671
23672 \noun on
23673 Large 
23674 \noun default
23675 stack model is currently not working properly throughout the code generator.
23676  So its use is not advised.
23677  Also there are some other points that need special care:
23678 \newline
23679
23680 \end_layout
23681
23682 \begin_layout Enumerate
23683 Do not create stack sections with size more than one physical bank (that
23684  is 256 bytes)
23685 \end_layout
23686
23687 \begin_layout Enumerate
23688 Stack sections should no cross physical bank limits (i.e.
23689  #pragma stack 0x50 0x100)
23690 \end_layout
23691
23692 \begin_layout Standard
23693 These limitations are caused by the fact that only FSRxL is modified when
23694  using SMALL stack model, so no more than 256 bytes of stack can be used.
23695  This problem will disappear after LARGE model is fully implemented.
23696 \end_layout
23697
23698 \begin_layout Subsection
23699 Functions
23700 \end_layout
23701
23702 \begin_layout Standard
23703 In addition to the standard SDCC function keywords, PIC16
23704 \begin_inset LatexCommand \index{PIC16}
23705
23706 \end_inset
23707
23708  port makes available two more:
23709 \end_layout
23710
23711 \begin_layout List
23712 \labelwidthstring 00.00.0000
23713 wparam
23714 \begin_inset LatexCommand \index{PIC16!wparam}
23715
23716 \end_inset
23717
23718  Use the WREG to pass one byte of the first function argument.
23719  This improves speed but you may not use this for functions with arguments
23720  that are called via function pointers, otherwise the first byte of the
23721  first parameter will get lost.
23722  Usage:
23723 \end_layout
23724
23725 \begin_layout LyX-Code
23726 void func_wparam(int a) wparam
23727 \end_layout
23728
23729 \begin_layout LyX-Code
23730 {
23731 \end_layout
23732
23733 \begin_layout LyX-Code
23734     /* WREG hold the lower part of a */
23735 \end_layout
23736
23737 \begin_layout LyX-Code
23738     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
23739  */
23740 \end_layout
23741
23742 \begin_layout LyX-Code
23743 ...
23744 \end_layout
23745
23746 \begin_layout LyX-Code
23747 }
23748 \end_layout
23749
23750 \begin_layout List
23751 \labelwidthstring 00.00.0000
23752 shadowregs
23753 \begin_inset LatexCommand \index{PIC16!shadowregs}
23754
23755 \end_inset
23756
23757  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
23758  hardware shadow registers which hold the values of WREG, STATUS and BSR
23759  registers.
23760  This can be done by adding the keyword 
23761 \emph on
23762 shadowregs
23763 \emph default
23764  before the 
23765 \emph on
23766 interrupt
23767 \emph default
23768  keyword in the function's header.
23769 \end_layout
23770
23771 \begin_layout LyX-Code
23772 void isr_shadow(void) shadowregs interrupt 1
23773 \end_layout
23774
23775 \begin_layout LyX-Code
23776 {
23777 \end_layout
23778
23779 \begin_layout LyX-Code
23780 ...
23781 \end_layout
23782
23783 \begin_layout LyX-Code
23784 }
23785 \end_layout
23786
23787 \begin_layout Standard
23788
23789 \emph on
23790 shadowregs
23791 \emph default
23792  instructs the code generator not to store/restore WREG, STATUS, BSR when
23793  entering/exiting the ISR.
23794 \end_layout
23795
23796 \begin_layout Subsection
23797 Function return values
23798 \end_layout
23799
23800 \begin_layout Standard
23801 Return values from functions are placed to the appropriate registers following
23802  a modified Microchip policy optimized for SDCC.
23803  The following table shows these registers:
23804 \end_layout
23805
23806 \begin_layout Standard
23807 \align center
23808 \begin_inset Tabular
23809 <lyxtabular version="3" rows="6" columns="2">
23810 <features>
23811 <column alignment="center" valignment="top" leftline="true" width="0">
23812 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23813 <row topline="true" bottomline="true">
23814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23815 \begin_inset Text
23816
23817 \begin_layout Standard
23818 size
23819 \end_layout
23820
23821 \end_inset
23822 </cell>
23823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23824 \begin_inset Text
23825
23826 \begin_layout Standard
23827 destination register
23828 \end_layout
23829
23830 \end_inset
23831 </cell>
23832 </row>
23833 <row topline="true">
23834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23835 \begin_inset Text
23836
23837 \begin_layout Standard
23838 8 bits
23839 \end_layout
23840
23841 \end_inset
23842 </cell>
23843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23844 \begin_inset Text
23845
23846 \begin_layout Standard
23847 WREG
23848 \end_layout
23849
23850 \end_inset
23851 </cell>
23852 </row>
23853 <row topline="true">
23854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23855 \begin_inset Text
23856
23857 \begin_layout Standard
23858 16 bits
23859 \end_layout
23860
23861 \end_inset
23862 </cell>
23863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23864 \begin_inset Text
23865
23866 \begin_layout Standard
23867 PRODL:WREG
23868 \end_layout
23869
23870 \end_inset
23871 </cell>
23872 </row>
23873 <row topline="true">
23874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23875 \begin_inset Text
23876
23877 \begin_layout Standard
23878 24 bits
23879 \end_layout
23880
23881 \end_inset
23882 </cell>
23883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23884 \begin_inset Text
23885
23886 \begin_layout Standard
23887 PRODH:PRODL:WREG
23888 \end_layout
23889
23890 \end_inset
23891 </cell>
23892 </row>
23893 <row topline="true">
23894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23895 \begin_inset Text
23896
23897 \begin_layout Standard
23898 32 bits
23899 \end_layout
23900
23901 \end_inset
23902 </cell>
23903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23904 \begin_inset Text
23905
23906 \begin_layout Standard
23907 FSR0L:PRODH:PRODL:WREG
23908 \end_layout
23909
23910 \end_inset
23911 </cell>
23912 </row>
23913 <row topline="true" bottomline="true">
23914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23915 \begin_inset Text
23916
23917 \begin_layout Standard
23918 >32 bits
23919 \end_layout
23920
23921 \end_inset
23922 </cell>
23923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23924 \begin_inset Text
23925
23926 \begin_layout Standard
23927 on stack, FSR0 points to the beginning
23928 \end_layout
23929
23930 \end_inset
23931 </cell>
23932 </row>
23933 </lyxtabular>
23934
23935 \end_inset
23936
23937
23938 \end_layout
23939
23940 \begin_layout Subsection
23941 Interrupts
23942 \end_layout
23943
23944 \begin_layout Standard
23945 An interrupt
23946 \begin_inset LatexCommand \index{PIC16!interrupt}
23947
23948 \end_inset
23949
23950  service routine (ISR) is declared using the 
23951 \emph on
23952 interrupt
23953 \emph default
23954  keyword.
23955 \end_layout
23956
23957 \begin_layout LyX-Code
23958 void isr(void) interrupt 
23959 \emph on
23960 n
23961 \end_layout
23962
23963 \begin_layout LyX-Code
23964 {
23965 \end_layout
23966
23967 \begin_layout LyX-Code
23968 ...
23969 \end_layout
23970
23971 \begin_layout LyX-Code
23972 }
23973 \end_layout
23974
23975 \begin_layout Standard
23976
23977 \emph on
23978 n
23979 \emph default
23980  is the interrupt number, which for PIC18F devices can be:
23981 \end_layout
23982
23983 \begin_layout Standard
23984 \align center
23985 \begin_inset Tabular
23986 <lyxtabular version="3" rows="4" columns="3">
23987 <features>
23988 <column alignment="center" valignment="top" leftline="true" width="0">
23989 <column alignment="center" valignment="top" leftline="true" width="0">
23990 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23991 <row topline="true" bottomline="true">
23992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23993 \begin_inset Text
23994
23995 \begin_layout Standard
23996
23997 \emph on
23998 n
23999 \end_layout
24000
24001 \end_inset
24002 </cell>
24003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24004 \begin_inset Text
24005
24006 \begin_layout Standard
24007 Interrupt Vector
24008 \end_layout
24009
24010 \end_inset
24011 </cell>
24012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24013 \begin_inset Text
24014
24015 \begin_layout Standard
24016 Interrupt Vector Address
24017 \end_layout
24018
24019 \end_inset
24020 </cell>
24021 </row>
24022 <row topline="true">
24023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24024 \begin_inset Text
24025
24026 \begin_layout Standard
24027 0
24028 \end_layout
24029
24030 \end_inset
24031 </cell>
24032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24033 \begin_inset Text
24034
24035 \begin_layout Standard
24036 RESET vector
24037 \end_layout
24038
24039 \end_inset
24040 </cell>
24041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24042 \begin_inset Text
24043
24044 \begin_layout Standard
24045 0x000000
24046 \end_layout
24047
24048 \end_inset
24049 </cell>
24050 </row>
24051 <row topline="true">
24052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24053 \begin_inset Text
24054
24055 \begin_layout Standard
24056
24057 \family roman
24058 \series medium
24059 \shape up
24060 \size normal
24061 \emph off
24062 \bar no
24063 \noun off
24064 \color none
24065 1
24066 \end_layout
24067
24068 \end_inset
24069 </cell>
24070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24071 \begin_inset Text
24072
24073 \begin_layout Standard
24074
24075 \family roman
24076 \series medium
24077 \shape up
24078 \size normal
24079 \emph off
24080 \bar no
24081 \noun off
24082 \color none
24083 HIGH priority interrupts
24084 \end_layout
24085
24086 \end_inset
24087 </cell>
24088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24089 \begin_inset Text
24090
24091 \begin_layout Standard
24092 0x000008
24093 \end_layout
24094
24095 \end_inset
24096 </cell>
24097 </row>
24098 <row topline="true" bottomline="true">
24099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24100 \begin_inset Text
24101
24102 \begin_layout Standard
24103 2
24104 \end_layout
24105
24106 \end_inset
24107 </cell>
24108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24109 \begin_inset Text
24110
24111 \begin_layout Standard
24112 LOW priority interrupts
24113 \end_layout
24114
24115 \end_inset
24116 </cell>
24117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24118 \begin_inset Text
24119
24120 \begin_layout Standard
24121 0x000018
24122 \end_layout
24123
24124 \end_inset
24125 </cell>
24126 </row>
24127 </lyxtabular>
24128
24129 \end_inset
24130
24131
24132 \end_layout
24133
24134 \begin_layout Standard
24135 When generating assembly code for ISR the code generator places a 
24136 \noun on
24137 goto 
24138 \noun default
24139 instruction at the 
24140 \emph on
24141 Interrupt Vector Address
24142 \emph default
24143  which points at the genetated ISR.
24144  This single GOTO instruction is part of an automatically generated 
24145 \emph on
24146 interrupt entry point
24147 \emph default
24148  function.
24149  The actuall ISR code is placed as normally would in the code space.
24150  Upon interrupt request, the GOTO instruction is executed which jumps to
24151  the ISR code.
24152  When declaring interrupt functions as _naked this GOTO instruction is 
24153 \series bold
24154 not
24155 \series default
24156  generated.
24157  The whole interrupt functions is therefore placed at the Interrupt Vector
24158  Address of the specific interrupt.
24159  This is not a problem for the LOW priority interrupts, but it is a problem
24160  for the RESET and the HIGH priority interrupts because code may be written
24161  at the next interrupt´s vector address and cause undeterminate program
24162  behaviour if that interrupt is raised.
24163 \begin_inset Foot
24164 status open
24165
24166 \begin_layout Standard
24167 This is not a problem when
24168 \end_layout
24169
24170 \begin_layout Enumerate
24171 this is a HIGH interrupt ISR and LOW interrupts are 
24172 \emph on
24173 disabled
24174 \emph default
24175  or not used.
24176 \end_layout
24177
24178 \begin_layout Enumerate
24179 when the ISR is small enough not to reach the next interrupt´s vector address.
24180 \end_layout
24181
24182 \end_inset
24183
24184
24185 \end_layout
24186
24187 \begin_layout Standard
24188
24189 \emph on
24190 n
24191 \emph default
24192  is possible to be omitted.
24193  This way a function is generated similar to an ISR, but it is not assigned
24194  to any interrupt.
24195 \end_layout
24196
24197 \begin_layout Standard
24198 When entering an interrupt, currently the PIC16
24199 \begin_inset LatexCommand \index{PIC16}
24200
24201 \end_inset
24202
24203  port automatically saves the following registers:
24204 \end_layout
24205
24206 \begin_layout Itemize
24207 WREG
24208 \end_layout
24209
24210 \begin_layout Itemize
24211 STATUS
24212 \end_layout
24213
24214 \begin_layout Itemize
24215 BSR
24216 \end_layout
24217
24218 \begin_layout Itemize
24219 PROD (PRODL and PRODH)
24220 \end_layout
24221
24222 \begin_layout Itemize
24223 FSR0 (FSR0L and FSR0H)
24224 \end_layout
24225
24226 \begin_layout Standard
24227 These registers are restored upon return from the interrupt routine.
24228 \begin_inset Foot
24229 status open
24230
24231 \begin_layout Standard
24232 NOTE that when the _naked attribute is specified for an interrupt routine,
24233  then NO registers are stored or restored.
24234 \end_layout
24235
24236 \end_inset
24237
24238
24239 \end_layout
24240
24241 \begin_layout Subsection
24242 Generic Pointers
24243 \end_layout
24244
24245 \begin_layout Standard
24246 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
24247  There are 3 types of generic pointers currently implemented data, code
24248  and eeprom pointers.
24249  They are differentiated by the value of the 7th and 6th bits of the upper
24250  byte:
24251 \end_layout
24252
24253 \begin_layout Standard
24254 \align center
24255 \begin_inset Tabular
24256 <lyxtabular version="3" rows="5" columns="5">
24257 <features>
24258 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24259 <column alignment="center" valignment="top" width="0">
24260 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24261 <column alignment="center" valignment="top" width="0">
24262 <column alignment="left" valignment="top" rightline="true" width="0">
24263 <row topline="true" bottomline="true">
24264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24265 \begin_inset Text
24266
24267 \begin_layout Standard
24268 pointer type
24269 \end_layout
24270
24271 \end_inset
24272 </cell>
24273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24274 \begin_inset Text
24275
24276 \begin_layout Standard
24277 7th bit
24278 \end_layout
24279
24280 \end_inset
24281 </cell>
24282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24283 \begin_inset Text
24284
24285 \begin_layout Standard
24286 6th bit
24287 \end_layout
24288
24289 \end_inset
24290 </cell>
24291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24292 \begin_inset Text
24293
24294 \begin_layout Standard
24295 rest of the pointer
24296 \end_layout
24297
24298 \end_inset
24299 </cell>
24300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24301 \begin_inset Text
24302
24303 \begin_layout Standard
24304 description
24305 \end_layout
24306
24307 \end_inset
24308 </cell>
24309 </row>
24310 <row topline="true" bottomline="true">
24311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24312 \begin_inset Text
24313
24314 \begin_layout Standard
24315 data 
24316 \end_layout
24317
24318 \end_inset
24319 </cell>
24320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24321 \begin_inset Text
24322
24323 \begin_layout Standard
24324 1
24325 \end_layout
24326
24327 \end_inset
24328 </cell>
24329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24330 \begin_inset Text
24331
24332 \begin_layout Standard
24333 0
24334 \end_layout
24335
24336 \end_inset
24337 </cell>
24338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24339 \begin_inset Text
24340
24341 \begin_layout Standard
24342
24343 \family typewriter
24344 \shape slanted
24345 \emph on
24346 uuuuuu uuuuxxxx xxxxxxxx
24347 \end_layout
24348
24349 \end_inset
24350 </cell>
24351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24352 \begin_inset Text
24353
24354 \begin_layout Standard
24355 a 12-bit data pointer in data RAM memory
24356 \end_layout
24357
24358 \end_inset
24359 </cell>
24360 </row>
24361 <row bottomline="true">
24362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24363 \begin_inset Text
24364
24365 \begin_layout Standard
24366 code
24367 \end_layout
24368
24369 \end_inset
24370 </cell>
24371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24372 \begin_inset Text
24373
24374 \begin_layout Standard
24375 0
24376 \end_layout
24377
24378 \end_inset
24379 </cell>
24380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24381 \begin_inset Text
24382
24383 \begin_layout Standard
24384 0
24385 \end_layout
24386
24387 \end_inset
24388 </cell>
24389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24390 \begin_inset Text
24391
24392 \begin_layout Standard
24393
24394 \family typewriter
24395 \shape slanted
24396 \emph on
24397 uxxxxx xxxxxxxx xxxxxxxx
24398 \end_layout
24399
24400 \end_inset
24401 </cell>
24402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24403 \begin_inset Text
24404
24405 \begin_layout Standard
24406 a 21-bit code pointer in FLASH memory
24407 \end_layout
24408
24409 \end_inset
24410 </cell>
24411 </row>
24412 <row bottomline="true">
24413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24414 \begin_inset Text
24415
24416 \begin_layout Standard
24417 eeprom
24418 \end_layout
24419
24420 \end_inset
24421 </cell>
24422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24423 \begin_inset Text
24424
24425 \begin_layout Standard
24426 0
24427 \end_layout
24428
24429 \end_inset
24430 </cell>
24431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24432 \begin_inset Text
24433
24434 \begin_layout Standard
24435 1
24436 \end_layout
24437
24438 \end_inset
24439 </cell>
24440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24441 \begin_inset Text
24442
24443 \begin_layout Standard
24444
24445 \family typewriter
24446 \shape slanted
24447 \emph on
24448 uuuuuu uuuuuuxx xxxxxxxx
24449 \end_layout
24450
24451 \end_inset
24452 </cell>
24453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24454 \begin_inset Text
24455
24456 \begin_layout Standard
24457 a 10-bit eeprom pointer in EEPROM memory
24458 \end_layout
24459
24460 \end_inset
24461 </cell>
24462 </row>
24463 <row bottomline="true">
24464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24465 \begin_inset Text
24466
24467 \begin_layout Standard
24468 (unimplemented)
24469 \end_layout
24470
24471 \end_inset
24472 </cell>
24473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24474 \begin_inset Text
24475
24476 \begin_layout Standard
24477 1
24478 \end_layout
24479
24480 \end_inset
24481 </cell>
24482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24483 \begin_inset Text
24484
24485 \begin_layout Standard
24486 1
24487 \end_layout
24488
24489 \end_inset
24490 </cell>
24491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24492 \begin_inset Text
24493
24494 \begin_layout Standard
24495
24496 \family typewriter
24497 \shape slanted
24498 \emph on
24499 xxxxxx xxxxxxxx xxxxxxxx
24500 \end_layout
24501
24502 \end_inset
24503 </cell>
24504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24505 \begin_inset Text
24506
24507 \begin_layout Standard
24508 unimplemented pointer type
24509 \end_layout
24510
24511 \end_inset
24512 </cell>
24513 </row>
24514 </lyxtabular>
24515
24516 \end_inset
24517
24518
24519 \end_layout
24520
24521 \begin_layout Standard
24522 Generic pointer are read and written with a set of library functions which
24523  read/write 1, 2, 3, 4 bytes.
24524 \end_layout
24525
24526 \begin_layout Subsection
24527 PIC16 C Libraries
24528 \end_layout
24529
24530 \begin_layout Subsubsection
24531 Standard I/O Streams
24532 \end_layout
24533
24534 \begin_layout Standard
24535 In the 
24536 \emph on
24537 stdio.h
24538 \emph default
24539  the type FILE is defined as:
24540 \end_layout
24541
24542 \begin_layout LyX-Code
24543 typedef char * FILE;
24544 \end_layout
24545
24546 \begin_layout Standard
24547 This type is the stream type implemented I/O in the PIC18F devices.
24548  Also the standard input and output streams are declared in stdio.h:
24549 \end_layout
24550
24551 \begin_layout LyX-Code
24552 extern FILE * stdin;
24553 \end_layout
24554
24555 \begin_layout LyX-Code
24556 extern FILE * stdout;
24557 \end_layout
24558
24559 \begin_layout Standard
24560 The FILE type is actually a generic pointer which defines one more type
24561  of generic pointers, the 
24562 \emph on
24563 stream 
24564 \emph default
24565 pointer.
24566  This new type has the format:
24567 \end_layout
24568
24569 \begin_layout Standard
24570 \align center
24571 \begin_inset Tabular
24572 <lyxtabular version="3" rows="2" columns="7">
24573 <features>
24574 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24575 <column alignment="center" valignment="top" width="0">
24576 <column alignment="center" valignment="top" leftline="true" width="0">
24577 <column alignment="center" valignment="top" leftline="true" width="0">
24578 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24579 <column alignment="center" valignment="top" width="0">
24580 <column alignment="left" valignment="top" rightline="true" width="0">
24581 <row topline="true" bottomline="true">
24582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24583 \begin_inset Text
24584
24585 \begin_layout Standard
24586 pointer type
24587 \end_layout
24588
24589 \end_inset
24590 </cell>
24591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24592 \begin_inset Text
24593
24594 \begin_layout Standard
24595 <7:6>
24596 \end_layout
24597
24598 \end_inset
24599 </cell>
24600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24601 \begin_inset Text
24602
24603 \begin_layout Standard
24604 <5>
24605 \end_layout
24606
24607 \end_inset
24608 </cell>
24609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24610 \begin_inset Text
24611
24612 \begin_layout Standard
24613 <4>
24614 \end_layout
24615
24616 \end_inset
24617 </cell>
24618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24619 \begin_inset Text
24620
24621 \begin_layout Standard
24622 <3:0>
24623 \end_layout
24624
24625 \end_inset
24626 </cell>
24627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24628 \begin_inset Text
24629
24630 \begin_layout Standard
24631 rest of the pointer
24632 \end_layout
24633
24634 \end_inset
24635 </cell>
24636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24637 \begin_inset Text
24638
24639 \begin_layout Standard
24640 descrption
24641 \end_layout
24642
24643 \end_inset
24644 </cell>
24645 </row>
24646 <row topline="true" bottomline="true">
24647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24648 \begin_inset Text
24649
24650 \begin_layout Standard
24651 stream
24652 \end_layout
24653
24654 \end_inset
24655 </cell>
24656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24657 \begin_inset Text
24658
24659 \begin_layout Standard
24660 00
24661 \end_layout
24662
24663 \end_inset
24664 </cell>
24665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24666 \begin_inset Text
24667
24668 \begin_layout Standard
24669 1
24670 \end_layout
24671
24672 \end_inset
24673 </cell>
24674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24675 \begin_inset Text
24676
24677 \begin_layout Standard
24678 0
24679 \end_layout
24680
24681 \end_inset
24682 </cell>
24683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24684 \begin_inset Text
24685
24686 \begin_layout Standard
24687 nnnn
24688 \end_layout
24689
24690 \end_inset
24691 </cell>
24692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24693 \begin_inset Text
24694
24695 \begin_layout Standard
24696
24697 \family typewriter
24698 \shape slanted
24699 \emph on
24700 uuuuuuuu uuuuuuuu
24701 \end_layout
24702
24703 \end_inset
24704 </cell>
24705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24706 \begin_inset Text
24707
24708 \begin_layout Standard
24709 upper byte high nubble is 0x2n, the rest are zeroes
24710 \end_layout
24711
24712 \end_inset
24713 </cell>
24714 </row>
24715 </lyxtabular>
24716
24717 \end_inset
24718
24719
24720 \end_layout
24721
24722 \begin_layout Standard
24723 Currently implemented there are 3 types of streams defined:
24724 \end_layout
24725
24726 \begin_layout Standard
24727 \align center
24728 \begin_inset Tabular
24729 <lyxtabular version="3" rows="4" columns="4">
24730 <features>
24731 <column alignment="center" valignment="top" leftline="true" width="0">
24732 <column alignment="center" valignment="top" leftline="true" width="0">
24733 <column alignment="center" valignment="top" leftline="true" width="0">
24734 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24735 <row topline="true" bottomline="true">
24736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24737 \begin_inset Text
24738
24739 \begin_layout Standard
24740 stream type
24741 \end_layout
24742
24743 \end_inset
24744 </cell>
24745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24746 \begin_inset Text
24747
24748 \begin_layout Standard
24749 value
24750 \end_layout
24751
24752 \end_inset
24753 </cell>
24754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24755 \begin_inset Text
24756
24757 \begin_layout Standard
24758 module
24759 \end_layout
24760
24761 \end_inset
24762 </cell>
24763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24764 \begin_inset Text
24765
24766 \begin_layout Standard
24767 description
24768 \end_layout
24769
24770 \end_inset
24771 </cell>
24772 </row>
24773 <row topline="true">
24774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24775 \begin_inset Text
24776
24777 \begin_layout Standard
24778 STREAM_USART
24779 \end_layout
24780
24781 \end_inset
24782 </cell>
24783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24784 \begin_inset Text
24785
24786 \begin_layout Standard
24787
24788 \family typewriter
24789 0x200000UL
24790 \end_layout
24791
24792 \end_inset
24793 </cell>
24794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24795 \begin_inset Text
24796
24797 \begin_layout Standard
24798 USART
24799 \end_layout
24800
24801 \end_inset
24802 </cell>
24803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24804 \begin_inset Text
24805
24806 \begin_layout Standard
24807 Writes/Reads characters via the USART peripheral
24808 \end_layout
24809
24810 \end_inset
24811 </cell>
24812 </row>
24813 <row topline="true">
24814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24815 \begin_inset Text
24816
24817 \begin_layout Standard
24818 STREAM_MSSP
24819 \end_layout
24820
24821 \end_inset
24822 </cell>
24823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24824 \begin_inset Text
24825
24826 \begin_layout Standard
24827
24828 \family typewriter
24829 0x210000UL
24830 \end_layout
24831
24832 \end_inset
24833 </cell>
24834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24835 \begin_inset Text
24836
24837 \begin_layout Standard
24838 MSSP
24839 \end_layout
24840
24841 \end_inset
24842 </cell>
24843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24844 \begin_inset Text
24845
24846 \begin_layout Standard
24847 Writes/Reads characters via the MSSP peripheral
24848 \end_layout
24849
24850 \end_inset
24851 </cell>
24852 </row>
24853 <row topline="true" bottomline="true">
24854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24855 \begin_inset Text
24856
24857 \begin_layout Standard
24858 STREAM_USER
24859 \end_layout
24860
24861 \end_inset
24862 </cell>
24863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24864 \begin_inset Text
24865
24866 \begin_layout Standard
24867
24868 \family typewriter
24869 0x2f0000UL
24870 \end_layout
24871
24872 \end_inset
24873 </cell>
24874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24875 \begin_inset Text
24876
24877 \begin_layout Standard
24878 (none)
24879 \end_layout
24880
24881 \end_inset
24882 </cell>
24883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24884 \begin_inset Text
24885
24886 \begin_layout Standard
24887 Writes/Reads characters via used defined functions
24888 \end_layout
24889
24890 \end_inset
24891 </cell>
24892 </row>
24893 </lyxtabular>
24894
24895 \end_inset
24896
24897
24898 \end_layout
24899
24900 \begin_layout Standard
24901 The stream identifiers are declared as macros in the stdio.h header.
24902 \end_layout
24903
24904 \begin_layout Standard
24905 In the libc library there exist the functions that are used to write to
24906  each of the above streams.
24907  These are
24908 \end_layout
24909
24910 \begin_layout List
24911 \labelwidthstring 00.00.0000
24912 _
24913 \begin_inset ERT
24914 status collapsed
24915
24916 \begin_layout Standard
24917
24918
24919 \backslash
24920 /
24921 \end_layout
24922
24923 \end_inset
24924
24925 _stream_usart_putchar writes a character at the USART stream
24926 \end_layout
24927
24928 \begin_layout List
24929 \labelwidthstring 00.00.0000
24930 _
24931 \begin_inset ERT
24932 status collapsed
24933
24934 \begin_layout Standard
24935
24936
24937 \backslash
24938 /
24939 \end_layout
24940
24941 \end_inset
24942
24943 _stream_mssp_putchar writes a character at the MSSP stream
24944 \end_layout
24945
24946 \begin_layout List
24947 \labelwidthstring 00.00.0000
24948 putchar dummy function.
24949  This writes a character to a user specified manner.
24950 \end_layout
24951
24952 \begin_layout Standard
24953 In order to increase performance 
24954 \emph on
24955 putchar 
24956 \emph default
24957 is declared in stdio.h as having its parameter in WREG (it has the wparam
24958  keyword).
24959  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
24960  in a user-friendly way.
24961  
24962 \emph on
24963 arg
24964 \emph default
24965  is the name of the variable that holds the character to print.
24966  An example follows:
24967 \end_layout
24968
24969 \begin_layout LyX-Code
24970 #include <pic18fregs.h>
24971 \newline
24972 #include <stdio.h>
24973 \newline
24974
24975 \newline
24976 PUTCHAR( c )
24977 \end_layout
24978
24979 \begin_layout LyX-Code
24980 {
24981 \end_layout
24982
24983 \begin_layout LyX-Code
24984     PORTA = c;    /* dump character c to PORTA */
24985 \end_layout
24986
24987 \begin_layout LyX-Code
24988
24989 \newline
24990
24991 \newline
24992 void main(void)
24993 \end_layout
24994
24995 \begin_layout LyX-Code
24996 {
24997 \end_layout
24998
24999 \begin_layout LyX-Code
25000     stdout = STREAM_USER;    /* this is not necessary, since stdout points
25001 \end_layout
25002
25003 \begin_layout LyX-Code
25004                               * by default to STREAM_USER */
25005 \end_layout
25006
25007 \begin_layout LyX-Code
25008     printf (¨This is a printf test
25009 \backslash
25010 n¨);
25011 \end_layout
25012
25013 \begin_layout LyX-Code
25014 }
25015 \end_layout
25016
25017 \begin_layout LyX-Code
25018
25019 \end_layout
25020
25021 \begin_layout Subsubsection
25022 Printing functions
25023 \end_layout
25024
25025 \begin_layout Standard
25026 PIC16 contains an implementation of the printf-family of functions.
25027  There exist the following functions:
25028 \end_layout
25029
25030 \begin_layout LyX-Code
25031 extern unsigned int sprintf(char *buf, char *fmt, ...);
25032 \end_layout
25033
25034 \begin_layout LyX-Code
25035 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
25036 \end_layout
25037
25038 \begin_layout LyX-Code
25039
25040 \end_layout
25041
25042 \begin_layout LyX-Code
25043 extern unsigned int printf(char *fmt, ...);
25044 \end_layout
25045
25046 \begin_layout LyX-Code
25047 extern unsigned int vprintf(char *fmt, va_lista ap);
25048 \end_layout
25049
25050 \begin_layout LyX-Code
25051
25052 \end_layout
25053
25054 \begin_layout LyX-Code
25055 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
25056 \end_layout
25057
25058 \begin_layout LyX-Code
25059 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
25060 \end_layout
25061
25062 \begin_layout Standard
25063 For sprintf and vsprintf 
25064 \emph on
25065 buf 
25066 \emph default
25067 should normally be a data pointer where the resulting string will be placed.
25068  No range checking is done so the user should allocate the necessery buffer.
25069  For fprintf and vfprintf 
25070 \emph on
25071 fp
25072 \emph default
25073  should be a stream pointer (i.e.
25074  stdout, STREAM_MSSP, etc...).
25075 \end_layout
25076
25077 \begin_layout Subsubsection
25078 Signals
25079 \end_layout
25080
25081 \begin_layout Standard
25082 The PIC18F family of microcontrollers supports a number of interrupt sources.
25083  A list of these interrupts is shown in the following table:
25084 \end_layout
25085
25086 \begin_layout Standard
25087 \align center
25088 \begin_inset Tabular
25089 <lyxtabular version="3" rows="11" columns="4">
25090 <features>
25091 <column alignment="left" valignment="top" leftline="true" width="0">
25092 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25093 <column alignment="left" valignment="top" leftline="true" width="0">
25094 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25095 <row topline="true" bottomline="true">
25096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25097 \begin_inset Text
25098
25099 \begin_layout Standard
25100 signal name
25101 \end_layout
25102
25103 \end_inset
25104 </cell>
25105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25106 \begin_inset Text
25107
25108 \begin_layout Standard
25109 description
25110 \end_layout
25111
25112 \end_inset
25113 </cell>
25114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25115 \begin_inset Text
25116
25117 \begin_layout Standard
25118 signal name
25119 \end_layout
25120
25121 \end_inset
25122 </cell>
25123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25124 \begin_inset Text
25125
25126 \begin_layout Standard
25127 descritpion
25128 \end_layout
25129
25130 \end_inset
25131 </cell>
25132 </row>
25133 <row topline="true">
25134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25135 \begin_inset Text
25136
25137 \begin_layout Standard
25138 SIG_RB
25139 \end_layout
25140
25141 \end_inset
25142 </cell>
25143 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25144 \begin_inset Text
25145
25146 \begin_layout Standard
25147 PORTB change interrupt
25148 \end_layout
25149
25150 \end_inset
25151 </cell>
25152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25153 \begin_inset Text
25154
25155 \begin_layout Standard
25156 SIG_EE
25157 \end_layout
25158
25159 \end_inset
25160 </cell>
25161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25162 \begin_inset Text
25163
25164 \begin_layout Standard
25165 EEPROM/FLASH write complete interrupt
25166 \end_layout
25167
25168 \end_inset
25169 </cell>
25170 </row>
25171 <row topline="true">
25172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25173 \begin_inset Text
25174
25175 \begin_layout Standard
25176 SIG_INT0
25177 \end_layout
25178
25179 \end_inset
25180 </cell>
25181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25182 \begin_inset Text
25183
25184 \begin_layout Standard
25185 INT0 external interrupt
25186 \end_layout
25187
25188 \end_inset
25189 </cell>
25190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25191 \begin_inset Text
25192
25193 \begin_layout Standard
25194 SIG_BCOL
25195 \end_layout
25196
25197 \end_inset
25198 </cell>
25199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25200 \begin_inset Text
25201
25202 \begin_layout Standard
25203 Bus collision interrupt
25204 \end_layout
25205
25206 \end_inset
25207 </cell>
25208 </row>
25209 <row topline="true">
25210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25211 \begin_inset Text
25212
25213 \begin_layout Standard
25214 SIG_INT1
25215 \end_layout
25216
25217 \end_inset
25218 </cell>
25219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25220 \begin_inset Text
25221
25222 \begin_layout Standard
25223 INT1 external interrupt
25224 \end_layout
25225
25226 \end_inset
25227 </cell>
25228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25229 \begin_inset Text
25230
25231 \begin_layout Standard
25232 SIG_LVD
25233 \end_layout
25234
25235 \end_inset
25236 </cell>
25237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25238 \begin_inset Text
25239
25240 \begin_layout Standard
25241 Low voltage detect interrupt
25242 \end_layout
25243
25244 \end_inset
25245 </cell>
25246 </row>
25247 <row topline="true">
25248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25249 \begin_inset Text
25250
25251 \begin_layout Standard
25252 SIG_INT2
25253 \end_layout
25254
25255 \end_inset
25256 </cell>
25257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25258 \begin_inset Text
25259
25260 \begin_layout Standard
25261 INT2 external interrupt
25262 \end_layout
25263
25264 \end_inset
25265 </cell>
25266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25267 \begin_inset Text
25268
25269 \begin_layout Standard
25270 SIG_PSP
25271 \end_layout
25272
25273 \end_inset
25274 </cell>
25275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25276 \begin_inset Text
25277
25278 \begin_layout Standard
25279 Parallel slave port interrupt
25280 \end_layout
25281
25282 \end_inset
25283 </cell>
25284 </row>
25285 <row topline="true">
25286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25287 \begin_inset Text
25288
25289 \begin_layout Standard
25290 SIG_CCP1
25291 \end_layout
25292
25293 \end_inset
25294 </cell>
25295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25296 \begin_inset Text
25297
25298 \begin_layout Standard
25299 CCP1 module interrupt
25300 \end_layout
25301
25302 \end_inset
25303 </cell>
25304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25305 \begin_inset Text
25306
25307 \begin_layout Standard
25308 SIG_AD
25309 \end_layout
25310
25311 \end_inset
25312 </cell>
25313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25314 \begin_inset Text
25315
25316 \begin_layout Standard
25317 AD convertion complete interrupt
25318 \end_layout
25319
25320 \end_inset
25321 </cell>
25322 </row>
25323 <row topline="true">
25324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25325 \begin_inset Text
25326
25327 \begin_layout Standard
25328 SIG_CCP2
25329 \end_layout
25330
25331 \end_inset
25332 </cell>
25333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25334 \begin_inset Text
25335
25336 \begin_layout Standard
25337 CCP2 module interrupt
25338 \end_layout
25339
25340 \end_inset
25341 </cell>
25342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25343 \begin_inset Text
25344
25345 \begin_layout Standard
25346 SIG_RC
25347 \end_layout
25348
25349 \end_inset
25350 </cell>
25351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25352 \begin_inset Text
25353
25354 \begin_layout Standard
25355 USART receive interrupt
25356 \end_layout
25357
25358 \end_inset
25359 </cell>
25360 </row>
25361 <row topline="true">
25362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25363 \begin_inset Text
25364
25365 \begin_layout Standard
25366 SIG_TMR0
25367 \end_layout
25368
25369 \end_inset
25370 </cell>
25371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25372 \begin_inset Text
25373
25374 \begin_layout Standard
25375 TMR0 overflow interrupt
25376 \end_layout
25377
25378 \end_inset
25379 </cell>
25380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25381 \begin_inset Text
25382
25383 \begin_layout Standard
25384 SIG_TX
25385 \end_layout
25386
25387 \end_inset
25388 </cell>
25389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25390 \begin_inset Text
25391
25392 \begin_layout Standard
25393 USART transmit interrupt
25394 \end_layout
25395
25396 \end_inset
25397 </cell>
25398 </row>
25399 <row topline="true">
25400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25401 \begin_inset Text
25402
25403 \begin_layout Standard
25404 SIG_TMR1
25405 \end_layout
25406
25407 \end_inset
25408 </cell>
25409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25410 \begin_inset Text
25411
25412 \begin_layout Standard
25413 TMR1 overflow interrupt
25414 \end_layout
25415
25416 \end_inset
25417 </cell>
25418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25419 \begin_inset Text
25420
25421 \begin_layout Standard
25422 SIG_MSSP
25423 \end_layout
25424
25425 \end_inset
25426 </cell>
25427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25428 \begin_inset Text
25429
25430 \begin_layout Standard
25431 SSP receive/transmit interrupt
25432 \end_layout
25433
25434 \end_inset
25435 </cell>
25436 </row>
25437 <row topline="true">
25438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25439 \begin_inset Text
25440
25441 \begin_layout Standard
25442 SIG_TMR2
25443 \end_layout
25444
25445 \end_inset
25446 </cell>
25447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25448 \begin_inset Text
25449
25450 \begin_layout Standard
25451 TMR2 matches PR2 interrupt
25452 \end_layout
25453
25454 \end_inset
25455 </cell>
25456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25457 \begin_inset Text
25458
25459 \begin_layout Standard
25460
25461 \end_layout
25462
25463 \end_inset
25464 </cell>
25465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25466 \begin_inset Text
25467
25468 \begin_layout Standard
25469
25470 \end_layout
25471
25472 \end_inset
25473 </cell>
25474 </row>
25475 <row topline="true" bottomline="true">
25476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25477 \begin_inset Text
25478
25479 \begin_layout Standard
25480 SIG_TMR3
25481 \end_layout
25482
25483 \end_inset
25484 </cell>
25485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25486 \begin_inset Text
25487
25488 \begin_layout Standard
25489 TMR3 overflow interrupt
25490 \end_layout
25491
25492 \end_inset
25493 </cell>
25494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25495 \begin_inset Text
25496
25497 \begin_layout Standard
25498
25499 \end_layout
25500
25501 \end_inset
25502 </cell>
25503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25504 \begin_inset Text
25505
25506 \begin_layout Standard
25507
25508 \end_layout
25509
25510 \end_inset
25511 </cell>
25512 </row>
25513 </lyxtabular>
25514
25515 \end_inset
25516
25517
25518 \end_layout
25519
25520 \begin_layout Standard
25521 The prototypes for these names are defined in the header file 
25522 \emph on
25523 signal.h
25524 \emph default
25525  .
25526 \end_layout
25527
25528 \begin_layout Standard
25529 In order to simplify signal handling, a number of macros is provided:
25530 \end_layout
25531
25532 \begin_layout List
25533 \labelwidthstring 00.00.0000
25534 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
25535  high priority interrupts.
25536  
25537 \emph on
25538 name
25539 \emph default
25540  is the function name to use.
25541 \end_layout
25542
25543 \begin_layout List
25544 \labelwidthstring 00.00.0000
25545 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
25546  low priority interrupt.
25547  
25548 \emph on
25549 name
25550 \emph default
25551  is the function name to use.
25552 \end_layout
25553
25554 \begin_layout List
25555 \labelwidthstring 00.00.0000
25556 DEF_HANDLER(sig,handler) define a handler for signal 
25557 \emph on
25558 sig.
25559 \end_layout
25560
25561 \begin_layout List
25562 \labelwidthstring 00.00.0000
25563 END_DEF end the declaration of the dispatch table.
25564 \end_layout
25565
25566 \begin_layout Standard
25567 Additionally there are two more macros to simplify the declaration of the
25568  signal handler:
25569 \end_layout
25570
25571 \begin_layout List
25572 \labelwidthstring 00.00.0000
25573
25574 \series medium
25575 SIGHANDLER(handler) 
25576 \series default
25577 this declares the function prototype for the 
25578 \emph on
25579 handler
25580 \emph default
25581  function.
25582 \end_layout
25583
25584 \begin_layout List
25585 \labelwidthstring 00.00.0000
25586 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
25587 \end_layout
25588
25589 \begin_layout Standard
25590 An example of using the macros above is shown below:
25591 \end_layout
25592
25593 \begin_layout LyX-Code
25594 #include <pic18fregs.h>
25595 \end_layout
25596
25597 \begin_layout LyX-Code
25598 #include <signal.h>
25599 \newline
25600
25601 \newline
25602 DEF_INTHIGH(high_int)
25603 \end_layout
25604
25605 \begin_layout LyX-Code
25606 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
25607 \end_layout
25608
25609 \begin_layout LyX-Code
25610 DEF_HANDLER(SIG_BCOL, _bcol_handler)
25611 \end_layout
25612
25613 \begin_layout LyX-Code
25614 END_DEF
25615 \newline
25616
25617 \newline
25618 SIGHANDLER(_tmr0_handler)
25619 \end_layout
25620
25621 \begin_layout LyX-Code
25622 {
25623 \end_layout
25624
25625 \begin_layout LyX-Code
25626   /* action to be taken when timer 0 overflows */
25627 \end_layout
25628
25629 \begin_layout LyX-Code
25630 }
25631 \newline
25632
25633 \newline
25634 SIGHANDLERNAKED(_bcol_handler)
25635 \end_layout
25636
25637 \begin_layout LyX-Code
25638 {
25639 \end_layout
25640
25641 \begin_layout LyX-Code
25642   _asm
25643 \end_layout
25644
25645 \begin_layout LyX-Code
25646     /* action to be taken when bus collision occurs */
25647 \end_layout
25648
25649 \begin_layout LyX-Code
25650     retfie
25651 \end_layout
25652
25653 \begin_layout LyX-Code
25654  _endasm;
25655 \end_layout
25656
25657 \begin_layout LyX-Code
25658 }
25659 \end_layout
25660
25661 \begin_layout Standard
25662
25663 \series bold
25664 NOTES:
25665 \series default
25666  Special care should be taken when using the above scheme:
25667 \end_layout
25668
25669 \begin_layout Itemize
25670 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
25671 \end_layout
25672
25673 \begin_layout Itemize
25674 when declaring SIGHANDLERNAKED handler never forget to use 
25675 \emph on
25676 retfie
25677 \emph default
25678  for proper returning.
25679 \end_layout
25680
25681 \begin_layout Subsection
25682 PIC16 Port -- Tips
25683 \end_layout
25684
25685 \begin_layout Standard
25686 Here you can find some general tips for compiling programs with SDCC/pic16.
25687 \end_layout
25688
25689 \begin_layout Subsubsection
25690 Stack size
25691 \end_layout
25692
25693 \begin_layout Standard
25694 The default stack
25695 \begin_inset LatexCommand \index{PIC16!stack}
25696
25697 \end_inset
25698
25699  size (that is 64 bytes) probably is enough for many programs.
25700  One must take care that when there are many levels of function nesting,
25701  or there is excessive usage of stack, its size should be extended.
25702  An example of such a case is the printf/sprintf family of functions.
25703  If you encounter problems like not being able to print integers, then you
25704  need to set the stack size around the maximum (256 for small stack model).
25705  The following diagram shows what happens when calling printf to print an
25706  integer:
25707 \end_layout
25708
25709 \begin_layout LyX-Code
25710 printf () --> ltoa () --> ultoa () --> divschar ()
25711 \end_layout
25712
25713 \begin_layout Standard
25714 It is should be understood that stack is easily consumed when calling complicate
25715 d functions.
25716  Using command line arguments like -
25717 \begin_inset ERT
25718 status collapsed
25719
25720 \begin_layout Standard
25721
25722
25723 \backslash
25724 /
25725 \end_layout
25726
25727 \end_inset
25728
25729 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
25730  stack frames.
25731  Other ways to reduce stack usage may exist.
25732 \end_layout
25733
25734 \begin_layout Subsection
25735 Known bugs
25736 \end_layout
25737
25738 \begin_layout Standard
25739 The PIC16 Port currently does not pass SDCC's regression test
25740 \begin_inset LatexCommand \index{Regression test (PIC16)}
25741
25742 \end_inset
25743
25744  suite (see section 
25745 \begin_inset LatexCommand \ref{sec:Quality-control}
25746
25747 \end_inset
25748
25749 ) and thus the nightly regression tests for the PIC16 target are currently
25750  disabled for all hosts except for 
25751 \emph on
25752 Linux on Opteron.
25753
25754 \emph default
25755  This means you can see the result of the PIC16 regression tests f.e.
25756  by checking the log files in 
25757 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
25758
25759 \end_inset
25760
25761  (pick the most up to date file there, scroll down, lend a hand).
25762 \end_layout
25763
25764 \begin_layout Chapter
25765 Debugging
25766 \end_layout
25767
25768 \begin_layout Standard
25769 There are several approaches to debugging your code.
25770  This chapter is meant to show your options and to give detail on some of
25771  them:
25772 \newline
25773
25774 \newline
25775 When writing your code:
25776 \end_layout
25777
25778 \begin_layout Itemize
25779 write your code with debugging in mind (avoid duplicating code, put conceptually
25780  similar variables into structs, use structured code, have strategic points
25781  within your code where all variables are consistent, ...)
25782 \end_layout
25783
25784 \begin_layout Itemize
25785 run a syntax-checking tool like splint
25786 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25787
25788 \end_inset
25789
25790
25791 \begin_inset LatexCommand \index{lint (syntax checking tool)}
25792
25793 \end_inset
25794
25795  (see -
25796 \begin_inset ERT
25797 status collapsed
25798
25799 \begin_layout Standard
25800
25801
25802 \backslash
25803 /
25804 \end_layout
25805
25806 \end_inset
25807
25808 -more-pedantic 
25809 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25810
25811 \end_inset
25812
25813 ) over the code.
25814 \end_layout
25815
25816 \begin_layout Itemize
25817 for the high level code use a C-compiler (like f.e.
25818  GCC) to compile run and debug the code on your host.
25819  See (see -
25820 \begin_inset ERT
25821 status collapsed
25822
25823 \begin_layout Standard
25824
25825
25826 \backslash
25827 /
25828 \end_layout
25829
25830 \end_inset
25831
25832 -more-pedantic 
25833 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25834
25835 \end_inset
25836
25837  ) on howto handle syntax extensions like __xdata, __at(), ...
25838  
25839 \end_layout
25840
25841 \begin_layout Itemize
25842 use another C-compiler to compile code for your target.
25843  Always an option but not recommended:) And not very likely to help you.
25844  If you seriously consider walking this path you should at least occasionally
25845  check portability of your code.
25846  Most commercial compiler vendors will offer an evaluation version so you
25847  can test compile your code or snippets of your code.
25848 \end_layout
25849
25850 \begin_layout Standard
25851 Debugging on a simulator:
25852 \end_layout
25853
25854 \begin_layout Itemize
25855 there is a separate section about SDCDB (section 
25856 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
25857
25858 \end_inset
25859
25860 ) below.
25861 \end_layout
25862
25863 \begin_layout Itemize
25864 or (8051 specific) use a freeware/commercial simulator which interfaces
25865  to the AOMF
25866 \begin_inset LatexCommand \index{AOMF, AOMF51}
25867
25868 \end_inset
25869
25870  file (see 
25871 \begin_inset LatexCommand \ref{OMF file}
25872
25873 \end_inset
25874
25875 ) optionally generated by SDCC.
25876 \end_layout
25877
25878 \begin_layout Standard
25879 Debugging On-target: 
25880 \end_layout
25881
25882 \begin_layout Itemize
25883 use a MCU port pin to serially output debug data to the RS232 port of your
25884  host.
25885  You'll probably want some level shifting device typically involving a MAX232
25886  or similar IC.
25887  If the hardware serial port of the MCU is not available search for 'Software
25888  UART' in your favourite search machine.
25889 \end_layout
25890
25891 \begin_layout Itemize
25892 use an on-target monitor.
25893  In this context a monitor is a small program which usually accepts commands
25894  via a serial line and allows to set program counter, to single step through
25895  a program and read/write memory locations.
25896  For the 8051 good examples of monitors are paulmon and cmon51 (see section
25897  
25898 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
25899
25900 \end_inset
25901
25902 ).
25903 \end_layout
25904
25905 \begin_layout Itemize
25906 toggle MCU port pins at strategic points within your code and use an oscilloscop
25907 e.
25908  A 
25909 \emph on
25910 digital oscilloscope
25911 \emph default
25912
25913 \begin_inset LatexCommand \index{Oscilloscope}
25914
25915 \end_inset
25916
25917  with deep trace memory is really helpful especially if you have to debug
25918  a realtime application.
25919  If you need to monitor more pins than your oscilloscope provides you can
25920  sometimes get away with a small R-2R network.
25921  On a single channel oscilloscope you could f.e.
25922  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
25923 k
25924 \begin_inset Formula $\Omega$
25925 \end_inset
25926
25927  resistor and the other one by a 5\InsetSpace ~
25928 k
25929 \begin_inset Formula $\Omega$
25930 \end_inset
25931
25932  resistor to the oscilloscope probe (check output drive capability of the
25933  pins you want to monitor).
25934  If you need to monitor many more pins a 
25935 \emph on
25936 logic analyzer
25937 \emph default
25938  will be handy.
25939 \end_layout
25940
25941 \begin_layout Itemize
25942 use an ICE (
25943 \emph on
25944 i
25945 \emph default
25946
25947 \emph on
25948 c
25949 \emph default
25950 ircuit 
25951 \emph on
25952 e
25953 \emph default
25954 mulator
25955 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
25956
25957 \end_inset
25958
25959 ).
25960  Usually very expensive.
25961  And very nice to have too.
25962  And usually locks you (for years...) to the devices the ICE can emulate.
25963  
25964 \end_layout
25965
25966 \begin_layout Itemize
25967 use a remote debugger.
25968  In most 8-bit systems the symbol information is not available on the target,
25969  and a complete debugger is too bulky for the target system.
25970  Therefore usually a debugger on the host system connects to an on-target
25971  debugging stub which accepts only primitive commands.
25972  
25973 \newline
25974 Terms to enter into your favourite search engine could be 'remote debugging',
25975  'gdb stub' or 'inferior debugger'.
25976  (is there one?)
25977 \end_layout
25978
25979 \begin_layout Itemize
25980 use an on target hardware debugger.
25981  Some of the more modern MCUs include hardware support for setting break
25982  points and monitoring/changing variables by using dedicated hardware pins.
25983  This facility doesn't require additional code to run on the target and
25984  
25985 \emph on
25986 usually
25987 \emph default
25988  doesn't affect runtime behaviour until a breakpoint is hit.
25989  For the mcs51 most hardware debuggers use the AOMF
25990 \begin_inset LatexCommand \index{AOMF, AOMF51}
25991
25992 \end_inset
25993
25994  file (see 
25995 \begin_inset LatexCommand \ref{OMF file}
25996
25997 \end_inset
25998
25999 ) as input file.
26000  
26001 \end_layout
26002
26003 \begin_layout Standard
26004 Last not least:
26005 \end_layout
26006
26007 \begin_layout Itemize
26008 if you are not familiar with any of the following terms you're likely to
26009  run into problems rather sooner than later: 
26010 \emph on
26011 volatile
26012 \emph default
26013
26014 \emph on
26015 atomic
26016 \emph default
26017
26018 \emph on
26019 memory map
26020 \emph default
26021
26022 \emph on
26023 overlay
26024 \emph default
26025 .
26026  As an embedded programmer you 
26027 \emph on
26028 have
26029 \emph default
26030  to know them so why not look them up 
26031 \emph on
26032 before
26033 \emph default
26034  you have problems?)
26035 \end_layout
26036
26037 \begin_layout Itemize
26038 tell someone else about your problem (actually this is a surprisingly effective
26039  means to hunt down the bug even if the listener is not familiar with your
26040  environment).
26041  As 'failure to communicate' is probably one of the job-induced deformations
26042  of an embedded programmer this is highly encouraged.
26043 \end_layout
26044
26045 \begin_layout Section
26046 Debugging with SDCDB
26047 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
26048
26049 \end_inset
26050
26051
26052 \begin_inset LatexCommand \index{SDCDB (debugger)}
26053
26054 \end_inset
26055
26056  
26057 \end_layout
26058
26059 \begin_layout Standard
26060 SDCC is distributed with a source level debugger
26061 \begin_inset LatexCommand \index{Debugger}
26062
26063 \end_inset
26064
26065 .
26066  The debugger uses a command line interface, the command repertoire of the
26067  debugger has been kept as close to gdb
26068 \begin_inset LatexCommand \index{gdb}
26069
26070 \end_inset
26071
26072  (the GNU debugger) as possible.
26073  The configuration and build process is part of the standard compiler installati
26074 on, which also builds and installs the debugger in the target directory
26075  specified during configuration.
26076  The debugger allows you debug BOTH at the C source and at the ASM source
26077  level.
26078 \end_layout
26079
26080 \begin_layout Subsection
26081 Compiling for Debugging
26082 \end_layout
26083
26084 \begin_layout Standard
26085 The -
26086 \begin_inset ERT
26087 status collapsed
26088
26089 \begin_layout Standard
26090
26091
26092 \backslash
26093 /
26094 \end_layout
26095
26096 \end_inset
26097
26098 -debug
26099 \begin_inset LatexCommand \index{-\/-debug}
26100
26101 \end_inset
26102
26103  option must be specified for all files for which debug information is to
26104  be generated.
26105  The compiler generates a .adb file for each of these files.
26106  The linker creates the .cdb
26107 \begin_inset LatexCommand \index{<file>.cdb}
26108
26109 \end_inset
26110
26111  file from the .adb
26112 \begin_inset LatexCommand \index{<file>.adb}
26113
26114 \end_inset
26115
26116  files and the address information.
26117  This .cdb is used by the debugger.
26118 \end_layout
26119
26120 \begin_layout Subsection
26121 How the Debugger Works
26122 \end_layout
26123
26124 \begin_layout Standard
26125 When the -
26126 \begin_inset ERT
26127 status collapsed
26128
26129 \begin_layout Standard
26130
26131
26132 \backslash
26133 /
26134 \end_layout
26135
26136 \end_inset
26137
26138 -debug option is specified the compiler generates extra symbol information
26139  some of which are put into the assembler source and some are put into the
26140  .adb file.
26141  Then the linker creates the .cdb file from the individual .adb files with
26142  the address information for the symbols.
26143  The debugger reads the symbolic information generated by the compiler &
26144  the address information generated by the linker.
26145  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
26146  execution is controlled by the debugger.
26147  When a command is issued for the debugger, it translates it into appropriate
26148  commands for the simulator.
26149  (Currently SDCDM only connects to the simulator but 
26150 \emph on
26151 newcdb
26152 \emph default
26153  at 
26154 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
26155
26156 \end_inset
26157
26158  is an effort to connect directly to the hardware.) 
26159 \end_layout
26160
26161 \begin_layout Subsection
26162 Starting the Debugger SDCDB
26163 \end_layout
26164
26165 \begin_layout Standard
26166 The debugger can be started using the following command line.
26167  (Assume the file you are debugging has the file name foo).
26168 \newline
26169
26170 \newline
26171
26172 \family sans
26173 \series bold
26174 sdcdb foo
26175 \newline
26176
26177 \family default
26178 \series default
26179
26180 \newline
26181 The debugger will look for the following files.
26182 \end_layout
26183
26184 \begin_layout Itemize
26185 foo.c - the source file.
26186 \end_layout
26187
26188 \begin_layout Itemize
26189 foo.cdb - the debugger symbol information file.
26190 \end_layout
26191
26192 \begin_layout Itemize
26193 foo.ihx - the Intel hex format
26194 \begin_inset LatexCommand \index{Intel hex format}
26195
26196 \end_inset
26197
26198  object file.
26199 \end_layout
26200
26201 \begin_layout Subsection
26202 SDCDB Command Line Options
26203 \end_layout
26204
26205 \begin_layout Itemize
26206 -
26207 \begin_inset ERT
26208 status collapsed
26209
26210 \begin_layout Standard
26211
26212
26213 \backslash
26214 /
26215 \end_layout
26216
26217 \end_inset
26218
26219 -directory=<source file directory> this option can used to specify the directory
26220  search list.
26221  The debugger will look into the directory list specified for source, cdb
26222  & ihx files.
26223  The items in the directory list must be separated by ':', e.g.
26224  if the source files can be in the directories /home/src1 and /home/src2,
26225  the -
26226 \begin_inset ERT
26227 status collapsed
26228
26229 \begin_layout Standard
26230
26231
26232 \backslash
26233 /
26234 \end_layout
26235
26236 \end_inset
26237
26238 -directory option should be -
26239 \begin_inset ERT
26240 status collapsed
26241
26242 \begin_layout Standard
26243
26244
26245 \backslash
26246 /
26247 \end_layout
26248
26249 \end_inset
26250
26251 -directory=/home/src1:/home/src2.
26252  Note there can be no spaces in the option.
26253  
26254 \end_layout
26255
26256 \begin_layout Itemize
26257 -cd <directory> - change to the <directory>.
26258 \end_layout
26259
26260 \begin_layout Itemize
26261 -fullname - used by GUI front ends.
26262 \end_layout
26263
26264 \begin_layout Itemize
26265 -cpu <cpu-type> - this argument is passed to the simulator please see the
26266  simulator docs for details.
26267 \end_layout
26268
26269 \begin_layout Itemize
26270 -X <Clock frequency > this options is passed to the simulator please see
26271  the simulator docs for details.
26272 \end_layout
26273
26274 \begin_layout Itemize
26275 -s <serial port file> passed to simulator see the simulator docs for details.
26276 \end_layout
26277
26278 \begin_layout Itemize
26279 -S <serial in,out> passed to simulator see the simulator docs for details.
26280 \end_layout
26281
26282 \begin_layout Itemize
26283 -k <port number> passed to simulator see the simulator docs for details.
26284 \end_layout
26285
26286 \begin_layout Subsection
26287 SDCDB Debugger Commands
26288 \end_layout
26289
26290 \begin_layout Standard
26291 As mentioned earlier the command interface for the debugger has been deliberatel
26292 y kept as close the GNU debugger gdb, as possible.
26293  This will help the integration with existing graphical user interfaces
26294  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
26295  If you use a graphical user interface for the debugger you can skip this
26296  section.
26297 \end_layout
26298
26299 \begin_layout Subsubsection*
26300 break [line | file:line | function | file:function]
26301 \end_layout
26302
26303 \begin_layout Standard
26304 Set breakpoint at specified line or function:
26305 \newline
26306
26307 \newline
26308
26309 \family sans
26310 \series bold
26311 sdcdb>break 100 
26312 \newline
26313 sdcdb>break foo.c:100
26314 \newline
26315 sdcdb>break funcfoo
26316 \newline
26317 sdcdb>break foo.c:funcfoo
26318 \end_layout
26319
26320 \begin_layout Subsubsection*
26321 clear [line | file:line | function | file:function ]
26322 \end_layout
26323
26324 \begin_layout Standard
26325 Clear breakpoint at specified line or function:
26326 \newline
26327
26328 \newline
26329
26330 \family sans
26331 \series bold
26332 sdcdb>clear 100
26333 \newline
26334 sdcdb>clear foo.c:100
26335 \newline
26336 sdcdb>clear funcfoo
26337 \newline
26338 sdcdb>clear foo.c:funcfoo
26339 \end_layout
26340
26341 \begin_layout Subsubsection*
26342 continue
26343 \end_layout
26344
26345 \begin_layout Standard
26346 Continue program being debugged, after breakpoint.
26347 \end_layout
26348
26349 \begin_layout Subsubsection*
26350 finish
26351 \end_layout
26352
26353 \begin_layout Standard
26354 Execute till the end of the current function.
26355 \end_layout
26356
26357 \begin_layout Subsubsection*
26358 delete [n]
26359 \end_layout
26360
26361 \begin_layout Standard
26362 Delete breakpoint number 'n'.
26363  If used without any option clear ALL user defined break points.
26364 \end_layout
26365
26366 \begin_layout Subsubsection*
26367 info [break | stack | frame | registers ]
26368 \end_layout
26369
26370 \begin_layout Itemize
26371 info break - list all breakpoints
26372 \end_layout
26373
26374 \begin_layout Itemize
26375 info stack - show the function call stack.
26376 \end_layout
26377
26378 \begin_layout Itemize
26379 info frame - show information about the current execution frame.
26380 \end_layout
26381
26382 \begin_layout Itemize
26383 info registers - show content of all registers.
26384 \end_layout
26385
26386 \begin_layout Subsubsection*
26387 step
26388 \end_layout
26389
26390 \begin_layout Standard
26391 Step program until it reaches a different source line.
26392  Note: pressing <return> repeats the last command.
26393 \end_layout
26394
26395 \begin_layout Subsubsection*
26396 next
26397 \end_layout
26398
26399 \begin_layout Standard
26400 Step program, proceeding through subroutine calls.
26401 \end_layout
26402
26403 \begin_layout Subsubsection*
26404 run
26405 \end_layout
26406
26407 \begin_layout Standard
26408 Start debugged program.
26409 \end_layout
26410
26411 \begin_layout Subsubsection*
26412 ptype variable 
26413 \end_layout
26414
26415 \begin_layout Standard
26416 Print type information of the variable.
26417 \end_layout
26418
26419 \begin_layout Subsubsection*
26420 print variable
26421 \end_layout
26422
26423 \begin_layout Standard
26424 print value of variable.
26425 \end_layout
26426
26427 \begin_layout Subsubsection*
26428 file filename
26429 \end_layout
26430
26431 \begin_layout Standard
26432 load the given file name.
26433  Note this is an alternate method of loading file for debugging.
26434 \end_layout
26435
26436 \begin_layout Subsubsection*
26437 frame
26438 \end_layout
26439
26440 \begin_layout Standard
26441 print information about current frame.
26442 \end_layout
26443
26444 \begin_layout Subsubsection*
26445 set srcmode
26446 \end_layout
26447
26448 \begin_layout Standard
26449 Toggle between C source & assembly source.
26450 \end_layout
26451
26452 \begin_layout Subsubsection*
26453 ! simulator command
26454 \end_layout
26455
26456 \begin_layout Standard
26457 Send the string following '!' to the simulator, the simulator response is
26458  displayed.
26459  Note the debugger does not interpret the command being sent to the simulator,
26460  so if a command like 'go' is sent the debugger can loose its execution
26461  context and may display incorrect values.
26462 \end_layout
26463
26464 \begin_layout Subsubsection*
26465 quit
26466 \end_layout
26467
26468 \begin_layout Standard
26469 "Watch me now.
26470  Iam going Down.
26471  My name is Bobby Brown"
26472 \end_layout
26473
26474 \begin_layout Subsection
26475 Interfacing SDCDB with DDD
26476 \end_layout
26477
26478 \begin_layout Standard
26479 \begin_inset Note Comment
26480 status collapsed
26481
26482 \begin_layout Standard
26483 The screenshot was converted from png to eps with: 
26484 \begin_inset Quotes sld
26485 \end_inset
26486
26487 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
26488 \begin_inset Quotes srd
26489 \end_inset
26490
26491  which produces a pretty compact eps file which is free from compression
26492  artifacts.
26493 \end_layout
26494
26495 \begin_layout Standard
26496 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
26497  as this broke the build system on Sourceforge (pdf-file was broken.
26498  pdflatex does not accept eps files).
26499 \end_layout
26500
26501 \end_inset
26502
26503
26504 \end_layout
26505
26506 \begin_layout Standard
26507 The 
26508 \emph on
26509 p
26510 \emph default
26511 ortable 
26512 \emph on
26513 n
26514 \emph default
26515 etwork 
26516 \emph on
26517 g
26518 \emph default
26519 raphics File 
26520 \size footnotesize
26521
26522 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
26523
26524 \end_inset
26525
26526
26527 \size default
26528  shows a screenshot of a debugging session with DDD
26529 \begin_inset LatexCommand \index{DDD (debugger)}
26530
26531 \end_inset
26532
26533  (Unix only) on a simulated 8032.
26534  The debugging session might not run as smoothly as the screenshot suggests.
26535  The debugger allows setting of breakpoints, displaying and changing variables,
26536  single stepping through C and assembler code.
26537  
26538 \newline
26539 The source was compiled with 
26540 \family sans
26541 \series bold
26542
26543 \newline
26544
26545 \newline
26546 sdcc -
26547 \family default
26548 \series default
26549
26550 \begin_inset ERT
26551 status collapsed
26552
26553 \begin_layout Standard
26554
26555
26556 \backslash
26557 /
26558 \end_layout
26559
26560 \end_inset
26561
26562
26563 \family sans
26564 \series bold
26565 -debug ddd_example.c
26566 \family default
26567 \series default
26568  
26569 \family sans
26570 \series bold
26571
26572 \newline
26573
26574 \family default
26575 \series default
26576
26577 \newline
26578 and DDD was invoked with 
26579 \family sans
26580 \series bold
26581
26582 \newline
26583
26584 \newline
26585 ddd -debugger "sdcdb -cpu 8032 ddd_example"
26586 \end_layout
26587
26588 \begin_layout Standard
26589 \begin_inset Note Note
26590 status open
26591
26592 \begin_layout Standard
26593 Check that the double quotes or an apostroph within the command line survive
26594  the LyX tool chain.
26595  Previously the apostrophs got slanted in the PDF output so a cut and paste
26596  did not work.
26597 \end_layout
26598
26599 \end_inset
26600
26601
26602 \end_layout
26603
26604 \begin_layout Subsection
26605 Interfacing SDCDB with XEmacs
26606 \begin_inset LatexCommand \index{XEmacs}
26607
26608 \end_inset
26609
26610
26611 \begin_inset LatexCommand \index{Emacs}
26612
26613 \end_inset
26614
26615
26616 \end_layout
26617
26618 \begin_layout Standard
26619 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
26620  sdcdb.el and sdcdbsrc.el.
26621  These two files can be found in the $(prefix)/bin directory after the installat
26622 ion is complete.
26623  These files need to be loaded into XEmacs for the interface to work.
26624  This can be done at XEmacs startup time by inserting the following into
26625  your '.xemacs' file (which can be found in your HOME directory): 
26626 \newline
26627
26628 \newline
26629
26630 \family typewriter
26631 (load-file sdcdbsrc.el) 
26632 \family default
26633
26634 \newline
26635
26636 \newline
26637 .xemacs is a lisp file so the () around the command is REQUIRED.
26638  The files can also be loaded dynamically while XEmacs is running, set the
26639  environment variable 'EMACSLOADPATH' to the installation bin directory
26640  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
26641  To start the interface enter the following command: 
26642 \newline
26643
26644 \newline
26645
26646 \family sans
26647 \series bold
26648 ESC-x sdcdbsrc
26649 \family default
26650 \series default
26651
26652 \newline
26653
26654 \newline
26655 You will prompted to enter the file name to be debugged.
26656  
26657 \newline
26658
26659 \newline
26660 The command line options that are passed to the simulator directly are
26661  bound to default values in the file sdcdbsrc.el.
26662  The variables are listed below, these values maybe changed as required.
26663 \end_layout
26664
26665 \begin_layout Itemize
26666 sdcdbsrc-cpu-type '51
26667 \end_layout
26668
26669 \begin_layout Itemize
26670 sdcdbsrc-frequency '11059200
26671 \end_layout
26672
26673 \begin_layout Itemize
26674 sdcdbsrc-serial nil
26675 \end_layout
26676
26677 \begin_layout Standard
26678 The following is a list of key mapping for the debugger interface.
26679 \end_layout
26680
26681 \begin_layout Standard
26682 \InsetSpace ~
26683
26684 \family typewriter
26685
26686 \newline
26687 ;;\InsetSpace ~
26688 Current Listing :: 
26689 \newline
26690 ;;key\InsetSpace ~
26691 \InsetSpace ~
26692 \InsetSpace ~
26693 \InsetSpace ~
26694 \InsetSpace ~
26695 \InsetSpace ~
26696 \InsetSpace ~
26697 \InsetSpace ~
26698 \InsetSpace ~
26699 \InsetSpace ~
26700 \InsetSpace ~
26701 \InsetSpace ~
26702 \InsetSpace ~
26703 \InsetSpace ~
26704 binding\InsetSpace ~
26705 \InsetSpace ~
26706 \InsetSpace ~
26707 \InsetSpace ~
26708 \InsetSpace ~
26709 \InsetSpace ~
26710 \InsetSpace ~
26711 \InsetSpace ~
26712 \InsetSpace ~
26713 \InsetSpace ~
26714 \InsetSpace ~
26715 \InsetSpace ~
26716 \InsetSpace ~
26717 \InsetSpace ~
26718 \InsetSpace ~
26719 \InsetSpace ~
26720 \InsetSpace ~
26721 \InsetSpace ~
26722 \InsetSpace ~
26723 \InsetSpace ~
26724 \InsetSpace ~
26725 \InsetSpace ~
26726 Comment 
26727 \newline
26728 ;;---\InsetSpace ~
26729 \InsetSpace ~
26730 \InsetSpace ~
26731 \InsetSpace ~
26732 \InsetSpace ~
26733 \InsetSpace ~
26734 \InsetSpace ~
26735 \InsetSpace ~
26736 \InsetSpace ~
26737 \InsetSpace ~
26738 \InsetSpace ~
26739 \InsetSpace ~
26740 \InsetSpace ~
26741 \InsetSpace ~
26742 -------\InsetSpace ~
26743 \InsetSpace ~
26744 \InsetSpace ~
26745 \InsetSpace ~
26746 \InsetSpace ~
26747 \InsetSpace ~
26748 \InsetSpace ~
26749 \InsetSpace ~
26750 \InsetSpace ~
26751 \InsetSpace ~
26752 \InsetSpace ~
26753 \InsetSpace ~
26754 \InsetSpace ~
26755 \InsetSpace ~
26756 \InsetSpace ~
26757 \InsetSpace ~
26758 \InsetSpace ~
26759 \InsetSpace ~
26760 \InsetSpace ~
26761 \InsetSpace ~
26762 \InsetSpace ~
26763 \InsetSpace ~
26764 -------
26765 \newline
26766 ;; 
26767 \newline
26768 ;;\InsetSpace ~
26769 n\InsetSpace ~
26770 \InsetSpace ~
26771 \InsetSpace ~
26772 \InsetSpace ~
26773 \InsetSpace ~
26774 \InsetSpace ~
26775 \InsetSpace ~
26776 \InsetSpace ~
26777 \InsetSpace ~
26778 \InsetSpace ~
26779 \InsetSpace ~
26780 \InsetSpace ~
26781 \InsetSpace ~
26782 \InsetSpace ~
26783 \InsetSpace ~
26784 sdcdb-next-fro
26785 m-src\InsetSpace ~
26786 \InsetSpace ~
26787 \InsetSpace ~
26788 \InsetSpace ~
26789 \InsetSpace ~
26790 \InsetSpace ~
26791 \InsetSpace ~
26792 \InsetSpace ~
26793 \InsetSpace ~
26794 \InsetSpace ~
26795 SDCDB next command 
26796 \newline
26797 ;;\InsetSpace ~
26798 b\InsetSpace ~
26799 \InsetSpace ~
26800 \InsetSpace ~
26801 \InsetSpace ~
26802 \InsetSpace ~
26803 \InsetSpace ~
26804 \InsetSpace ~
26805 \InsetSpace ~
26806 \InsetSpace ~
26807 \InsetSpace ~
26808 \InsetSpace ~
26809 \InsetSpace ~
26810 \InsetSpace ~
26811 \InsetSpace ~
26812 \InsetSpace ~
26813 sdcdb-back-from-src\InsetSpace ~
26814 \InsetSpace ~
26815 \InsetSpace ~
26816 \InsetSpace ~
26817 \InsetSpace ~
26818 \InsetSpace ~
26819 \InsetSpace ~
26820 \InsetSpace ~
26821 \InsetSpace ~
26822 \InsetSpace ~
26823 SDCDB back command 
26824 \newline
26825 ;;\InsetSpace ~
26826 c\InsetSpace ~
26827 \InsetSpace ~
26828 \InsetSpace ~
26829 \InsetSpace ~
26830 \InsetSpace ~
26831 \InsetSpace ~
26832 \InsetSpace ~
26833 \InsetSpace ~
26834 \InsetSpace ~
26835 \InsetSpace ~
26836 \InsetSpace ~
26837 \InsetSpace ~
26838 \InsetSpace ~
26839 \InsetSpace ~
26840 \InsetSpace ~
26841 sdcdb-cont-f
26842 rom-src\InsetSpace ~
26843 \InsetSpace ~
26844 \InsetSpace ~
26845 \InsetSpace ~
26846 \InsetSpace ~
26847 \InsetSpace ~
26848 \InsetSpace ~
26849 \InsetSpace ~
26850 \InsetSpace ~
26851 \InsetSpace ~
26852 SDCDB continue command
26853 \newline
26854 ;;\InsetSpace ~
26855 s\InsetSpace ~
26856 \InsetSpace ~
26857 \InsetSpace ~
26858 \InsetSpace ~
26859 \InsetSpace ~
26860 \InsetSpace ~
26861 \InsetSpace ~
26862 \InsetSpace ~
26863 \InsetSpace ~
26864 \InsetSpace ~
26865 \InsetSpace ~
26866 \InsetSpace ~
26867 \InsetSpace ~
26868 \InsetSpace ~
26869 \InsetSpace ~
26870 sdcdb-step-from-src\InsetSpace ~
26871 \InsetSpace ~
26872 \InsetSpace ~
26873 \InsetSpace ~
26874 \InsetSpace ~
26875 \InsetSpace ~
26876 \InsetSpace ~
26877 \InsetSpace ~
26878 \InsetSpace ~
26879 \InsetSpace ~
26880 SDCDB step command 
26881 \newline
26882 ;;\InsetSpace ~
26883 ?\InsetSpace ~
26884 \InsetSpace ~
26885 \InsetSpace ~
26886 \InsetSpace ~
26887 \InsetSpace ~
26888 \InsetSpace ~
26889 \InsetSpace ~
26890 \InsetSpace ~
26891 \InsetSpace ~
26892 \InsetSpace ~
26893 \InsetSpace ~
26894 \InsetSpace ~
26895 \InsetSpace ~
26896 \InsetSpace ~
26897 \InsetSpace ~
26898 sdcdb-w
26899 hatis-c-sexp\InsetSpace ~
26900 \InsetSpace ~
26901 \InsetSpace ~
26902 \InsetSpace ~
26903 \InsetSpace ~
26904 \InsetSpace ~
26905 \InsetSpace ~
26906 \InsetSpace ~
26907 \InsetSpace ~
26908 \InsetSpace ~
26909 SDCDB ptypecommand for data at 
26910 \newline
26911 ;;\InsetSpace ~
26912 \InsetSpace ~
26913 \InsetSpace ~
26914 \InsetSpace ~
26915 \InsetSpace ~
26916 \InsetSpace ~
26917 \InsetSpace ~
26918 \InsetSpace ~
26919 \InsetSpace ~
26920 \InsetSpace ~
26921 \InsetSpace ~
26922 \InsetSpace ~
26923 \InsetSpace ~
26924 \InsetSpace ~
26925 \InsetSpace ~
26926 \InsetSpace ~
26927 \InsetSpace ~
26928 \InsetSpace ~
26929 \InsetSpace ~
26930 \InsetSpace ~
26931 \InsetSpace ~
26932 \InsetSpace ~
26933 \InsetSpace ~
26934 \InsetSpace ~
26935 \InsetSpace ~
26936 \InsetSpace ~
26937 \InsetSpace ~
26938 \InsetSpace ~
26939 \InsetSpace ~
26940 \InsetSpace ~
26941 \InsetSpace ~
26942 \InsetSpace ~
26943 \InsetSpace ~
26944 \InsetSpace ~
26945 \InsetSpace ~
26946 \InsetSpace ~
26947 \InsetSpace ~
26948 \InsetSpace ~
26949 \InsetSpace ~
26950 \InsetSpace ~
26951 \InsetSpace ~
26952 \InsetSpace ~
26953 \InsetSpace ~
26954 \InsetSpace ~
26955 \InsetSpace ~
26956 \InsetSpace ~
26957 \InsetSpace ~
26958 buffer point 
26959 \newline
26960 ;;\InsetSpace ~
26961 x\InsetSpace ~
26962 \InsetSpace ~
26963 \InsetSpace ~
26964 \InsetSpace ~
26965 \InsetSpace ~
26966 \InsetSpace ~
26967 \InsetSpace ~
26968 \InsetSpace ~
26969 \InsetSpace ~
26970 \InsetSpace ~
26971 \InsetSpace ~
26972 \InsetSpace ~
26973 \InsetSpace ~
26974 \InsetSpace ~
26975 \InsetSpace ~
26976 sdcdbsrc-delete\InsetSpace ~
26977 \InsetSpace ~
26978 \InsetSpace ~
26979 \InsetSpace ~
26980 \InsetSpace ~
26981 \InsetSpace ~
26982 \InsetSpace ~
26983 \InsetSpace ~
26984 \InsetSpace ~
26985 \InsetSpace ~
26986 \InsetSpace ~
26987 \InsetSpace ~
26988 \InsetSpace ~
26989 \InsetSpace ~
26990 SDCD
26991 B Delete all breakpoints if no arg 
26992 \newline
26993 ;;\InsetSpace ~
26994 \InsetSpace ~
26995 \InsetSpace ~
26996 \InsetSpace ~
26997 \InsetSpace ~
26998 \InsetSpace ~
26999 \InsetSpace ~
27000 \InsetSpace ~
27001 \InsetSpace ~
27002 \InsetSpace ~
27003 \InsetSpace ~
27004 \InsetSpace ~
27005 \InsetSpace ~
27006 \InsetSpace ~
27007 \InsetSpace ~
27008 \InsetSpace ~
27009 \InsetSpace ~
27010 \InsetSpace ~
27011 \InsetSpace ~
27012 \InsetSpace ~
27013 \InsetSpace ~
27014 \InsetSpace ~
27015 \InsetSpace ~
27016 \InsetSpace ~
27017 \InsetSpace ~
27018 \InsetSpace ~
27019 \InsetSpace ~
27020 \InsetSpace ~
27021 \InsetSpace ~
27022 \InsetSpace ~
27023 \InsetSpace ~
27024 \InsetSpace ~
27025 \InsetSpace ~
27026 \InsetSpace ~
27027 \InsetSpace ~
27028 \InsetSpace ~
27029 \InsetSpace ~
27030 \InsetSpace ~
27031 \InsetSpace ~
27032 \InsetSpace ~
27033 \InsetSpace ~
27034 \InsetSpace ~
27035 \InsetSpace ~
27036 \InsetSpace ~
27037 \InsetSpace ~
27038 \InsetSpace ~
27039 \InsetSpace ~
27040 given or delete arg (C-u arg x) 
27041 \newline
27042 ;;\InsetSpace ~
27043 m\InsetSpace ~
27044 \InsetSpace ~
27045 \InsetSpace ~
27046 \InsetSpace ~
27047 \InsetSpace ~
27048 \InsetSpace ~
27049 \InsetSpace ~
27050 \InsetSpace ~
27051 \InsetSpace ~
27052 \InsetSpace ~
27053 \InsetSpace ~
27054 \InsetSpace ~
27055 \InsetSpace ~
27056 \InsetSpace ~
27057 \InsetSpace ~
27058 sdcdbsrc
27059 -frame\InsetSpace ~
27060 \InsetSpace ~
27061 \InsetSpace ~
27062 \InsetSpace ~
27063 \InsetSpace ~
27064 \InsetSpace ~
27065 \InsetSpace ~
27066 \InsetSpace ~
27067 \InsetSpace ~
27068 \InsetSpace ~
27069 \InsetSpace ~
27070 \InsetSpace ~
27071 \InsetSpace ~
27072 \InsetSpace ~
27073 \InsetSpace ~
27074 SDCDB Display current frame if no arg, 
27075 \newline
27076 ;;\InsetSpace ~
27077 \InsetSpace ~
27078 \InsetSpace ~
27079 \InsetSpace ~
27080 \InsetSpace ~
27081 \InsetSpace ~
27082 \InsetSpace ~
27083 \InsetSpace ~
27084 \InsetSpace ~
27085 \InsetSpace ~
27086 \InsetSpace ~
27087 \InsetSpace ~
27088 \InsetSpace ~
27089 \InsetSpace ~
27090 \InsetSpace ~
27091 \InsetSpace ~
27092 \InsetSpace ~
27093 \InsetSpace ~
27094 \InsetSpace ~
27095 \InsetSpace ~
27096 \InsetSpace ~
27097 \InsetSpace ~
27098 \InsetSpace ~
27099 \InsetSpace ~
27100 \InsetSpace ~
27101 \InsetSpace ~
27102 \InsetSpace ~
27103 \InsetSpace ~
27104 \InsetSpace ~
27105 \InsetSpace ~
27106 \InsetSpace ~
27107 \InsetSpace ~
27108 \InsetSpace ~
27109 \InsetSpace ~
27110 \InsetSpace ~
27111 \InsetSpace ~
27112 \InsetSpace ~
27113 \InsetSpace ~
27114 \InsetSpace ~
27115 \InsetSpace ~
27116 \InsetSpace ~
27117 \InsetSpace ~
27118 \InsetSpace ~
27119 \InsetSpace ~
27120 \InsetSpace ~
27121 \InsetSpace ~
27122 \InsetSpace ~
27123 given or display frame arg
27124  
27125 \newline
27126 ;;\InsetSpace ~
27127 \InsetSpace ~
27128 \InsetSpace ~
27129 \InsetSpace ~
27130 \InsetSpace ~
27131 \InsetSpace ~
27132 \InsetSpace ~
27133 \InsetSpace ~
27134 \InsetSpace ~
27135 \InsetSpace ~
27136 \InsetSpace ~
27137 \InsetSpace ~
27138 \InsetSpace ~
27139 \InsetSpace ~
27140 \InsetSpace ~
27141 \InsetSpace ~
27142 \InsetSpace ~
27143 \InsetSpace ~
27144 \InsetSpace ~
27145 \InsetSpace ~
27146 \InsetSpace ~
27147 \InsetSpace ~
27148 \InsetSpace ~
27149 \InsetSpace ~
27150 \InsetSpace ~
27151 \InsetSpace ~
27152 \InsetSpace ~
27153 \InsetSpace ~
27154 \InsetSpace ~
27155 \InsetSpace ~
27156 \InsetSpace ~
27157 \InsetSpace ~
27158 \InsetSpace ~
27159 \InsetSpace ~
27160 \InsetSpace ~
27161 \InsetSpace ~
27162 \InsetSpace ~
27163 \InsetSpace ~
27164 \InsetSpace ~
27165 \InsetSpace ~
27166 \InsetSpace ~
27167 \InsetSpace ~
27168 \InsetSpace ~
27169 \InsetSpace ~
27170 \InsetSpace ~
27171 \InsetSpace ~
27172 \InsetSpace ~
27173 buffer point 
27174 \newline
27175 ;;\InsetSpace ~
27176 !\InsetSpace ~
27177 \InsetSpace ~
27178 \InsetSpace ~
27179 \InsetSpace ~
27180 \InsetSpace ~
27181 \InsetSpace ~
27182 \InsetSpace ~
27183 \InsetSpace ~
27184 \InsetSpace ~
27185 \InsetSpace ~
27186 \InsetSpace ~
27187 \InsetSpace ~
27188 \InsetSpace ~
27189 \InsetSpace ~
27190 \InsetSpace ~
27191 sdcdbsrc-goto-sdcdb\InsetSpace ~
27192 \InsetSpace ~
27193 \InsetSpace ~
27194 \InsetSpace ~
27195 \InsetSpace ~
27196 \InsetSpace ~
27197 \InsetSpace ~
27198 \InsetSpace ~
27199 \InsetSpace ~
27200 \InsetSpace ~
27201 Goto the SDCDB output buffer 
27202 \newline
27203 ;;\InsetSpace ~
27204 p\InsetSpace ~
27205 \InsetSpace ~
27206 \InsetSpace ~
27207 \InsetSpace ~
27208 \InsetSpace ~
27209 \InsetSpace ~
27210 \InsetSpace ~
27211 \InsetSpace ~
27212 \InsetSpace ~
27213 \InsetSpace ~
27214 \InsetSpace ~
27215 \InsetSpace ~
27216 \InsetSpace ~
27217 \InsetSpace ~
27218 \InsetSpace ~
27219 sdcdb-prin
27220 t-c-sexp\InsetSpace ~
27221 \InsetSpace ~
27222 \InsetSpace ~
27223 \InsetSpace ~
27224 \InsetSpace ~
27225 \InsetSpace ~
27226 \InsetSpace ~
27227 \InsetSpace ~
27228 \InsetSpace ~
27229 \InsetSpace ~
27230 \InsetSpace ~
27231 SDCDB print command for data at 
27232 \newline
27233 ;;\InsetSpace ~
27234 \InsetSpace ~
27235 \InsetSpace ~
27236 \InsetSpace ~
27237 \InsetSpace ~
27238 \InsetSpace ~
27239 \InsetSpace ~
27240 \InsetSpace ~
27241 \InsetSpace ~
27242 \InsetSpace ~
27243 \InsetSpace ~
27244 \InsetSpace ~
27245 \InsetSpace ~
27246 \InsetSpace ~
27247 \InsetSpace ~
27248 \InsetSpace ~
27249 \InsetSpace ~
27250 \InsetSpace ~
27251 \InsetSpace ~
27252 \InsetSpace ~
27253 \InsetSpace ~
27254 \InsetSpace ~
27255 \InsetSpace ~
27256 \InsetSpace ~
27257 \InsetSpace ~
27258 \InsetSpace ~
27259 \InsetSpace ~
27260 \InsetSpace ~
27261 \InsetSpace ~
27262 \InsetSpace ~
27263 \InsetSpace ~
27264 \InsetSpace ~
27265 \InsetSpace ~
27266 \InsetSpace ~
27267 \InsetSpace ~
27268 \InsetSpace ~
27269 \InsetSpace ~
27270 \InsetSpace ~
27271 \InsetSpace ~
27272 \InsetSpace ~
27273 \InsetSpace ~
27274 \InsetSpace ~
27275 \InsetSpace ~
27276 \InsetSpace ~
27277 \InsetSpace ~
27278 \InsetSpace ~
27279 \InsetSpace ~
27280 buffer point 
27281 \newline
27282 ;;\InsetSpace ~
27283 g\InsetSpace ~
27284 \InsetSpace ~
27285 \InsetSpace ~
27286 \InsetSpace ~
27287 \InsetSpace ~
27288 \InsetSpace ~
27289 \InsetSpace ~
27290 \InsetSpace ~
27291 \InsetSpace ~
27292 \InsetSpace ~
27293 \InsetSpace ~
27294 \InsetSpace ~
27295 \InsetSpace ~
27296 \InsetSpace ~
27297 \InsetSpace ~
27298 sdcdbsrc-goto-sdcdb\InsetSpace ~
27299 \InsetSpace ~
27300 \InsetSpace ~
27301 \InsetSpace ~
27302 \InsetSpace ~
27303 \InsetSpace ~
27304 \InsetSpace ~
27305 \InsetSpace ~
27306 \InsetSpace ~
27307 \InsetSpace ~
27308 Got
27309 o the SDCDB output buffer 
27310 \newline
27311 ;;\InsetSpace ~
27312 t\InsetSpace ~
27313 \InsetSpace ~
27314 \InsetSpace ~
27315 \InsetSpace ~
27316 \InsetSpace ~
27317 \InsetSpace ~
27318 \InsetSpace ~
27319 \InsetSpace ~
27320 \InsetSpace ~
27321 \InsetSpace ~
27322 \InsetSpace ~
27323 \InsetSpace ~
27324 \InsetSpace ~
27325 \InsetSpace ~
27326 \InsetSpace ~
27327 sdcdbsrc-mode\InsetSpace ~
27328 \InsetSpace ~
27329 \InsetSpace ~
27330 \InsetSpace ~
27331 \InsetSpace ~
27332 \InsetSpace ~
27333 \InsetSpace ~
27334 \InsetSpace ~
27335 \InsetSpace ~
27336 \InsetSpace ~
27337 \InsetSpace ~
27338 \InsetSpace ~
27339 \InsetSpace ~
27340 \InsetSpace ~
27341 \InsetSpace ~
27342 \InsetSpace ~
27343 Toggles Sdcdbsrc mode (turns it
27344  off) 
27345 \newline
27346 ;; 
27347 \newline
27348 ;;\InsetSpace ~
27349 C-c\InsetSpace ~
27350 C-f\InsetSpace ~
27351 \InsetSpace ~
27352 \InsetSpace ~
27353 \InsetSpace ~
27354 \InsetSpace ~
27355 \InsetSpace ~
27356 \InsetSpace ~
27357 \InsetSpace ~
27358 \InsetSpace ~
27359 sdcdb-finish-from-src\InsetSpace ~
27360 \InsetSpace ~
27361 \InsetSpace ~
27362 \InsetSpace ~
27363 \InsetSpace ~
27364 \InsetSpace ~
27365 \InsetSpace ~
27366 \InsetSpace ~
27367 SDCDB finish command 
27368 \newline
27369 ;; 
27370 \newline
27371 ;;\InsetSpace ~
27372 C-x\InsetSpace ~
27373 SPC\InsetSpace ~
27374 \InsetSpace ~
27375 \InsetSpace ~
27376 \InsetSpace ~
27377 \InsetSpace ~
27378 \InsetSpace ~
27379 \InsetSpace ~
27380 \InsetSpace ~
27381 \InsetSpace ~
27382 sdcdb-brea
27383 k\InsetSpace ~
27384 \InsetSpace ~
27385 \InsetSpace ~
27386 \InsetSpace ~
27387 \InsetSpace ~
27388 \InsetSpace ~
27389 \InsetSpace ~
27390 \InsetSpace ~
27391 \InsetSpace ~
27392 \InsetSpace ~
27393 \InsetSpace ~
27394 \InsetSpace ~
27395 \InsetSpace ~
27396 \InsetSpace ~
27397 \InsetSpace ~
27398 \InsetSpace ~
27399 \InsetSpace ~
27400 \InsetSpace ~
27401 Set break for line with point 
27402 \newline
27403 ;;\InsetSpace ~
27404 ESC\InsetSpace ~
27405 t\InsetSpace ~
27406 \InsetSpace ~
27407 \InsetSpace ~
27408 \InsetSpace ~
27409 \InsetSpace ~
27410 \InsetSpace ~
27411 \InsetSpace ~
27412 \InsetSpace ~
27413 \InsetSpace ~
27414 \InsetSpace ~
27415 \InsetSpace ~
27416 sdcdbsrc-mode\InsetSpace ~
27417 \InsetSpace ~
27418 \InsetSpace ~
27419 \InsetSpace ~
27420 \InsetSpace ~
27421 \InsetSpace ~
27422 \InsetSpace ~
27423 \InsetSpace ~
27424 \InsetSpace ~
27425 \InsetSpace ~
27426 \InsetSpace ~
27427 \InsetSpace ~
27428 \InsetSpace ~
27429 \InsetSpace ~
27430 \InsetSpace ~
27431 \InsetSpace ~
27432 Toggle Sdcdbsrc mode 
27433 \newline
27434 ;;\InsetSpace ~
27435 ESC\InsetSpace ~
27436 m\InsetSpace ~
27437 \InsetSpace ~
27438 \InsetSpace ~
27439 \InsetSpace ~
27440 \InsetSpace ~
27441 \InsetSpace ~
27442 \InsetSpace ~
27443 \InsetSpace ~
27444 \InsetSpace ~
27445 \InsetSpace ~
27446 \InsetSpace ~
27447 sdc
27448 dbsrc-srcmode\InsetSpace ~
27449 \InsetSpace ~
27450 \InsetSpace ~
27451 \InsetSpace ~
27452 \InsetSpace ~
27453 \InsetSpace ~
27454 \InsetSpace ~
27455 \InsetSpace ~
27456 \InsetSpace ~
27457 \InsetSpace ~
27458 \InsetSpace ~
27459 \InsetSpace ~
27460 \InsetSpace ~
27461 Toggle list mode 
27462 \newline
27463 ;; 
27464 \newline
27465
27466 \end_layout
27467
27468 \begin_layout Standard
27469
27470 \newpage
27471
27472 \end_layout
27473
27474 \begin_layout Chapter
27475 TIPS
27476 \end_layout
27477
27478 \begin_layout Standard
27479 Here are a few guidelines that will help the compiler generate more efficient
27480  code, some of the tips are specific to this compiler others are generally
27481  good programming practice.
27482 \end_layout
27483
27484 \begin_layout Itemize
27485 Use the smallest data type to represent your data-value.
27486  If it is known in advance that the value is going to be less than 256 then
27487  use an 'unsigned char' instead of a 'short' or 'int'.
27488  Please note, that ANSI C requires both signed and unsigned chars to be
27489  promoted to 'signed int'
27490 \begin_inset LatexCommand \index{promotion to signed int}
27491
27492 \end_inset
27493
27494
27495 \begin_inset Marginal
27496 status collapsed
27497
27498 \begin_layout Standard
27499
27500 \series bold
27501 \InsetSpace ~
27502 !
27503 \end_layout
27504
27505 \end_inset
27506
27507  before doing any operation.
27508  This promotion
27509 \begin_inset LatexCommand \index{type promotion}
27510
27511 \end_inset
27512
27513
27514 \begin_inset LatexCommand \label{type promotion}
27515
27516 \end_inset
27517
27518  can be omitted, if the result is the same.
27519  The effect of the promotion rules together with the sign-extension is often
27520  surprising:
27521 \end_layout
27522
27523 \begin_deeper
27524 \begin_layout Verse
27525
27526 \family typewriter
27527 unsigned char uc = 0xfe;
27528 \newline
27529 if (uc * uc < 0) /* this is true! */
27530 \newline
27531 {
27532 \newline
27533 \InsetSpace ~
27534 \InsetSpace ~
27535 \InsetSpace ~
27536 \InsetSpace ~
27537 ....
27538 \newline
27539 }
27540 \end_layout
27541
27542 \begin_layout Standard
27543
27544 \family typewriter
27545 uc * uc
27546 \family default
27547  is evaluated as 
27548 \family typewriter
27549 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
27550 \family default
27551 .
27552  
27553 \newline
27554 Another one:
27555 \end_layout
27556
27557 \begin_layout Verse
27558
27559 \family typewriter
27560 (unsigned char) -12 / (signed char) -3 = ...
27561 \end_layout
27562
27563 \begin_layout Standard
27564 No, the result is not 4:
27565 \end_layout
27566
27567 \begin_layout Verse
27568
27569 \family typewriter
27570 (int) (unsigned char) -12 / (int) (signed char) -3 =
27571 \newline
27572 (int) (unsigned char)
27573  0xf4 / (int) (signed char) 0xfd =
27574 \newline
27575 (int) 0x00f4 / (int) 0xfffd =
27576 \newline
27577 (int) 0x00f4
27578  / (int) 0xfffd =
27579 \newline
27580 (int) 244 / (int) -3 =
27581 \newline
27582 (int) -81 = (int) 0xffaf;
27583 \end_layout
27584
27585 \begin_layout Standard
27586 Don't complain, that gcc gives you a different result.
27587  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
27588  Therefore the results are different.
27589 \newline
27590 From 
27591 \begin_inset Quotes sld
27592 \end_inset
27593
27594 comp.lang.c FAQ
27595 \begin_inset Quotes srd
27596 \end_inset
27597
27598 :
27599 \end_layout
27600
27601 \begin_layout Quote
27602
27603 \emph on
27604 If well-defined overflow characteristics are important and negative values
27605  are not, or if you want to steer clear of sign-extension problems when
27606  manipulating bits or bytes, use one of the corresponding unsigned types.
27607  (Beware when mixing signed and unsigned values in expressions, though.)
27608 \newline
27609 Although
27610  character types (especially unsigned char) can be used as "tiny" integers,
27611  doing so is sometimes more trouble than it's worth, due to unpredictable
27612  sign extension and increased code size.
27613 \end_layout
27614
27615 \end_deeper
27616 \begin_layout Itemize
27617 Use unsigned when it is known in advance that the value is not going to
27618  be negative.
27619  This helps especially if you are doing division or multiplication, bit-shifting
27620  or are using an array index.
27621 \end_layout
27622
27623 \begin_layout Itemize
27624 NEVER jump into a LOOP.
27625 \end_layout
27626
27627 \begin_layout Itemize
27628 Declare the variables to be local
27629 \begin_inset LatexCommand \index{local variables}
27630
27631 \end_inset
27632
27633  whenever possible, especially loop control variables (induction).
27634 \end_layout
27635
27636 \begin_layout Itemize
27637 Have a look at the assembly listing to get a 
27638 \begin_inset Quotes sld
27639 \end_inset
27640
27641 feeling
27642 \begin_inset Quotes srd
27643 \end_inset
27644
27645  for the code generation.
27646 \end_layout
27647
27648 \begin_layout Section
27649 Porting code from or to other compilers
27650 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
27651
27652 \end_inset
27653
27654
27655 \end_layout
27656
27657 \begin_layout Itemize
27658 check whether endianness of the compilers differs and adapt where needed.
27659 \end_layout
27660
27661 \begin_layout Itemize
27662 check the device specific header files
27663 \begin_inset LatexCommand \index{Header files}
27664
27665 \end_inset
27666
27667
27668 \begin_inset LatexCommand \index{Include files}
27669
27670 \end_inset
27671
27672  for compiler specific syntax.
27673  Eventually include the file <compiler.h
27674 \begin_inset LatexCommand \index{compiler.h (include file)}
27675
27676 \end_inset
27677
27678
27679 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
27680
27681 \end_inset
27682
27683  to allow using common header files.
27684  (see f.e.
27685  cc2510fx.h 
27686 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
27687
27688 \end_inset
27689
27690 ).
27691 \end_layout
27692
27693 \begin_layout Itemize
27694 check whether the startup code contains the correct initialization (watchdog,
27695  peripherals).
27696 \end_layout
27697
27698 \begin_layout Itemize
27699 check whether the sizes of short, int, long match.
27700 \end_layout
27701
27702 \begin_layout Itemize
27703 check if some 16 or 32 bit hardware registers require a specific addressing
27704  order (least significant or most significant byte first) and adapt if needed
27705  (
27706 \emph on
27707 first
27708 \emph default
27709  and 
27710 \emph on
27711 last
27712 \emph default
27713  relate to time and not to lower/upper memory location here, so this is
27714  
27715 \emph on
27716 not
27717 \emph default
27718  the same as endianness).
27719 \end_layout
27720
27721 \begin_layout Itemize
27722 check whether the keyword 
27723 \emph on
27724 volatile
27725 \emph default
27726  is used where needed.
27727  The compilers might differ in their optimization characteristics (as different
27728  versions of the same compiler might also use more clever optimizations
27729  this is good idea anyway).
27730  See section 
27731 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
27732
27733 \end_inset
27734
27735 .
27736 \end_layout
27737
27738 \begin_layout Itemize
27739 check that the compilers are not told to supress warnings.
27740 \end_layout
27741
27742 \begin_layout Itemize
27743 check and convert compiler specific extensions (interrupts, memory areas,
27744  pragmas etc.).
27745 \end_layout
27746
27747 \begin_layout Itemize
27748 check for differences in type promotion.
27749  Especially check for math operations on 
27750 \family typewriter
27751 char
27752 \family default
27753  or 
27754 \family typewriter
27755 unsigned char
27756 \family default
27757  variables.
27758  For the sake of C99 compatibility SDCC will probably promote these to 
27759 \family typewriter
27760 int
27761 \family default
27762  more often than other compilers.
27763  Eventually insert explicit casts to 
27764 \family typewriter
27765 (char) 
27766 \family default
27767 or
27768 \family typewriter
27769  (unsigned char)
27770 \family default
27771 .
27772  Also check that the ~\InsetSpace ~
27773 operator
27774 \begin_inset LatexCommand \index{\~\/ Operator}
27775
27776 \end_inset
27777
27778  is not used on 
27779 \family typewriter
27780 bit
27781 \begin_inset LatexCommand \index{bit}
27782
27783 \end_inset
27784
27785
27786 \family default
27787  variables, use the !\InsetSpace ~
27788 operator instead.
27789  See sections 
27790 \begin_inset LatexCommand \ref{type promotion}
27791
27792 \end_inset
27793
27794  and 
27795 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27796
27797 \end_inset
27798
27799 .
27800 \end_layout
27801
27802 \begin_layout Itemize
27803 check the assembly code generated for interrupt routines (f.e.
27804  for calls to possibly non-reentrant library functions).
27805 \end_layout
27806
27807 \begin_layout Itemize
27808 check whether timing loops result in proper timing (or preferably consider
27809  a rewrite of the code with timer based delays instead).
27810 \end_layout
27811
27812 \begin_layout Itemize
27813 check for differences in printf parameters (some compilers push (va_arg
27814 \begin_inset LatexCommand \index{vararg, va\_arg}
27815
27816 \end_inset
27817
27818 ) char variables as 
27819 \family typewriter
27820 int
27821 \family default
27822  others push them as 
27823 \family typewriter
27824 char
27825 \family default
27826 .
27827  See section 
27828 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27829
27830 \end_inset
27831
27832 ).
27833 \end_layout
27834
27835 \begin_layout Itemize
27836 check the resulting memory map
27837 \begin_inset LatexCommand \index{Memory map}
27838
27839 \end_inset
27840
27841 .
27842  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
27843 ly idata, pdata, xdata).
27844  Eventually check if unexpected library functions are included.
27845 \end_layout
27846
27847 \begin_layout Section
27848 Tools
27849 \begin_inset LatexCommand \index{Tools}
27850
27851 \end_inset
27852
27853  included in the distribution
27854 \end_layout
27855
27856 \begin_layout Standard
27857 \align left
27858 \begin_inset Tabular
27859 <lyxtabular version="3" rows="12" columns="3">
27860 <features>
27861 <column alignment="left" valignment="top" leftline="true" width="0pt">
27862 <column alignment="left" valignment="top" leftline="true" width="0pt">
27863 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27864 <row topline="true" bottomline="true">
27865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27866 \begin_inset Text
27867
27868 \begin_layout Standard
27869
27870 \series bold
27871 Name
27872 \end_layout
27873
27874 \end_inset
27875 </cell>
27876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27877 \begin_inset Text
27878
27879 \begin_layout Standard
27880
27881 \series bold
27882 Purpose
27883 \end_layout
27884
27885 \end_inset
27886 </cell>
27887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27888 \begin_inset Text
27889
27890 \begin_layout Standard
27891
27892 \series bold
27893 Directory
27894 \end_layout
27895
27896 \end_inset
27897 </cell>
27898 </row>
27899 <row topline="true">
27900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27901 \begin_inset Text
27902
27903 \begin_layout Standard
27904 uCsim
27905 \begin_inset LatexCommand \index{uCsim}
27906
27907 \end_inset
27908
27909
27910 \end_layout
27911
27912 \end_inset
27913 </cell>
27914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27915 \begin_inset Text
27916
27917 \begin_layout Standard
27918 Simulator for various architectures
27919 \end_layout
27920
27921 \end_inset
27922 </cell>
27923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27924 \begin_inset Text
27925
27926 \begin_layout Standard
27927 sdcc/sim/ucsim
27928 \end_layout
27929
27930 \end_inset
27931 </cell>
27932 </row>
27933 <row topline="true">
27934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27935 \begin_inset Text
27936
27937 \begin_layout Standard
27938 keil2sdcc.pl
27939 \end_layout
27940
27941 \end_inset
27942 </cell>
27943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27944 \begin_inset Text
27945
27946 \begin_layout Standard
27947 header file
27948 \begin_inset LatexCommand \index{Header files}
27949
27950 \end_inset
27951
27952
27953 \begin_inset LatexCommand \index{Include files}
27954
27955 \end_inset
27956
27957  conversion
27958 \end_layout
27959
27960 \end_inset
27961 </cell>
27962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27963 \begin_inset Text
27964
27965 \begin_layout Standard
27966 sdcc/support/scripts
27967 \end_layout
27968
27969 \end_inset
27970 </cell>
27971 </row>
27972 <row topline="true">
27973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27974 \begin_inset Text
27975
27976 \begin_layout Standard
27977 mh2h.c
27978 \end_layout
27979
27980 \end_inset
27981 </cell>
27982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27983 \begin_inset Text
27984
27985 \begin_layout Standard
27986 header file conversion
27987 \end_layout
27988
27989 \end_inset
27990 </cell>
27991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27992 \begin_inset Text
27993
27994 \begin_layout Standard
27995 sdcc/support/scripts
27996 \end_layout
27997
27998 \end_inset
27999 </cell>
28000 </row>
28001 <row topline="true">
28002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28003 \begin_inset Text
28004
28005 \begin_layout Standard
28006 as-gbz80
28007 \end_layout
28008
28009 \end_inset
28010 </cell>
28011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28012 \begin_inset Text
28013
28014 \begin_layout Standard
28015 Assembler
28016 \end_layout
28017
28018 \end_inset
28019 </cell>
28020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28021 \begin_inset Text
28022
28023 \begin_layout Standard
28024
28025 \family roman
28026 \series medium
28027 \shape up
28028 \size normal
28029 \emph off
28030 \bar no
28031 \noun off
28032 \color none
28033 sdcc/bin
28034 \end_layout
28035
28036 \end_inset
28037 </cell>
28038 </row>
28039 <row topline="true">
28040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28041 \begin_inset Text
28042
28043 \begin_layout Standard
28044 as-z80
28045 \end_layout
28046
28047 \end_inset
28048 </cell>
28049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28050 \begin_inset Text
28051
28052 \begin_layout Standard
28053 Assembler
28054 \end_layout
28055
28056 \end_inset
28057 </cell>
28058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28059 \begin_inset Text
28060
28061 \begin_layout Standard
28062
28063 \family roman
28064 \series medium
28065 \shape up
28066 \size normal
28067 \emph off
28068 \bar no
28069 \noun off
28070 \color none
28071 sdcc/bin
28072 \end_layout
28073
28074 \end_inset
28075 </cell>
28076 </row>
28077 <row topline="true">
28078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28079 \begin_inset Text
28080
28081 \begin_layout Standard
28082 asx8051
28083 \end_layout
28084
28085 \end_inset
28086 </cell>
28087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28088 \begin_inset Text
28089
28090 \begin_layout Standard
28091 Assembler
28092 \end_layout
28093
28094 \end_inset
28095 </cell>
28096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28097 \begin_inset Text
28098
28099 \begin_layout Standard
28100
28101 \family roman
28102 \series medium
28103 \shape up
28104 \size normal
28105 \emph off
28106 \bar no
28107 \noun off
28108 \color none
28109 sdcc/bin
28110 \end_layout
28111
28112 \end_inset
28113 </cell>
28114 </row>
28115 <row topline="true">
28116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28117 \begin_inset Text
28118
28119 \begin_layout Standard
28120 SDCDB
28121 \end_layout
28122
28123 \end_inset
28124 </cell>
28125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28126 \begin_inset Text
28127
28128 \begin_layout Standard
28129 Simulator
28130 \end_layout
28131
28132 \end_inset
28133 </cell>
28134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28135 \begin_inset Text
28136
28137 \begin_layout Standard
28138
28139 \family roman
28140 \series medium
28141 \shape up
28142 \size normal
28143 \emph off
28144 \bar no
28145 \noun off
28146 \color none
28147 sdcc/bin
28148 \end_layout
28149
28150 \end_inset
28151 </cell>
28152 </row>
28153 <row topline="true">
28154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28155 \begin_inset Text
28156
28157 \begin_layout Standard
28158 aslink
28159 \end_layout
28160
28161 \end_inset
28162 </cell>
28163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28164 \begin_inset Text
28165
28166 \begin_layout Standard
28167 Linker
28168 \end_layout
28169
28170 \end_inset
28171 </cell>
28172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28173 \begin_inset Text
28174
28175 \begin_layout Standard
28176
28177 \family roman
28178 \series medium
28179 \shape up
28180 \size normal
28181 \emph off
28182 \bar no
28183 \noun off
28184 \color none
28185 sdcc/bin
28186 \end_layout
28187
28188 \end_inset
28189 </cell>
28190 </row>
28191 <row topline="true">
28192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28193 \begin_inset Text
28194
28195 \begin_layout Standard
28196 link-z80
28197 \end_layout
28198
28199 \end_inset
28200 </cell>
28201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28202 \begin_inset Text
28203
28204 \begin_layout Standard
28205 Linker
28206 \end_layout
28207
28208 \end_inset
28209 </cell>
28210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28211 \begin_inset Text
28212
28213 \begin_layout Standard
28214
28215 \family roman
28216 \series medium
28217 \shape up
28218 \size normal
28219 \emph off
28220 \bar no
28221 \noun off
28222 \color none
28223 sdcc/bin
28224 \end_layout
28225
28226 \end_inset
28227 </cell>
28228 </row>
28229 <row topline="true">
28230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28231 \begin_inset Text
28232
28233 \begin_layout Standard
28234 link-gbz80
28235 \end_layout
28236
28237 \end_inset
28238 </cell>
28239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28240 \begin_inset Text
28241
28242 \begin_layout Standard
28243 Linker
28244 \end_layout
28245
28246 \end_inset
28247 </cell>
28248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28249 \begin_inset Text
28250
28251 \begin_layout Standard
28252
28253 \family roman
28254 \series medium
28255 \shape up
28256 \size normal
28257 \emph off
28258 \bar no
28259 \noun off
28260 \color none
28261 sdcc/bin
28262 \end_layout
28263
28264 \end_inset
28265 </cell>
28266 </row>
28267 <row topline="true" bottomline="true">
28268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28269 \begin_inset Text
28270
28271 \begin_layout Standard
28272 packihx
28273 \end_layout
28274
28275 \end_inset
28276 </cell>
28277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28278 \begin_inset Text
28279
28280 \begin_layout Standard
28281 Intel Hex packer 
28282 \begin_inset LatexCommand \index{packihx (tool)}
28283
28284 \end_inset
28285
28286
28287 \end_layout
28288
28289 \end_inset
28290 </cell>
28291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28292 \begin_inset Text
28293
28294 \begin_layout Standard
28295
28296 \family roman
28297 \series medium
28298 \shape up
28299 \size normal
28300 \emph off
28301 \bar no
28302 \noun off
28303 \color none
28304 sdcc/bin
28305 \end_layout
28306
28307 \end_inset
28308 </cell>
28309 </row>
28310 </lyxtabular>
28311
28312 \end_inset
28313
28314
28315 \newline
28316
28317 \end_layout
28318
28319 \begin_layout Section
28320 Documentation
28321 \begin_inset LatexCommand \index{Documentation}
28322
28323 \end_inset
28324
28325  included in the distribution
28326 \end_layout
28327
28328 \begin_layout Standard
28329 \align left
28330 \begin_inset Tabular
28331 <lyxtabular version="3" rows="10" columns="2">
28332 <features>
28333 <column alignment="block" valignment="top" leftline="true" width="40col%">
28334 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
28335 <row topline="true" bottomline="true" endhead="true">
28336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28337 \begin_inset Text
28338
28339 \begin_layout Standard
28340
28341 \series bold
28342 Subject / Title
28343 \end_layout
28344
28345 \end_inset
28346 </cell>
28347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28348 \begin_inset Text
28349
28350 \begin_layout Standard
28351
28352 \series bold
28353 Filename / Where to get
28354 \end_layout
28355
28356 \end_inset
28357 </cell>
28358 </row>
28359 <row topline="true">
28360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28361 \begin_inset Text
28362
28363 \begin_layout Standard
28364 SDCC Compiler User Guide
28365 \end_layout
28366
28367 \end_inset
28368 </cell>
28369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28370 \begin_inset Text
28371
28372 \begin_layout Standard
28373 You're reading it right now
28374 \emph on
28375  \InsetSpace ~
28376 \InsetSpace ~
28377 \InsetSpace ~
28378
28379 \hfill
28380 online at:
28381 \emph default
28382
28383 \newline
28384
28385 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
28386
28387 \end_inset
28388
28389
28390 \end_layout
28391
28392 \end_inset
28393 </cell>
28394 </row>
28395 <row topline="true">
28396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28397 \begin_inset Text
28398
28399 \begin_layout Standard
28400 Changelog of SDCC
28401 \end_layout
28402
28403 \end_inset
28404 </cell>
28405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28406 \begin_inset Text
28407
28408 \begin_layout Standard
28409 sdcc/Changelog
28410 \emph on
28411  \InsetSpace ~
28412 \InsetSpace ~
28413 \InsetSpace ~
28414
28415 \hfill
28416 online at:
28417 \emph default
28418
28419 \newline
28420
28421 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28422
28423 \end_inset
28424
28425
28426 \end_layout
28427
28428 \end_inset
28429 </cell>
28430 </row>
28431 <row topline="true">
28432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28433 \begin_inset Text
28434
28435 \begin_layout Standard
28436 ASXXXX
28437 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
28438
28439 \end_inset
28440
28441
28442 \begin_inset LatexCommand \index{Assembler documentation}
28443
28444 \end_inset
28445
28446  Assemblers and
28447 \newline
28448 ASLINK
28449 \begin_inset LatexCommand \index{aslink}
28450
28451 \end_inset
28452
28453
28454 \begin_inset LatexCommand \index{Linker documentation}
28455
28456 \end_inset
28457
28458  Relocating Linker
28459 \end_layout
28460
28461 \end_inset
28462 </cell>
28463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28464 \begin_inset Text
28465
28466 \begin_layout Standard
28467 sdcc/as/doc/asxhtm.html 
28468 \emph on
28469 \InsetSpace ~
28470 \InsetSpace ~
28471 \InsetSpace ~
28472
28473 \hfill
28474 online at:
28475 \emph default
28476
28477 \newline
28478
28479 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
28480
28481 \end_inset
28482
28483
28484 \end_layout
28485
28486 \end_inset
28487 </cell>
28488 </row>
28489 <row topline="true">
28490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28491 \begin_inset Text
28492
28493 \begin_layout Standard
28494 SDCC regression test
28495 \begin_inset LatexCommand \index{Regression test}
28496
28497 \end_inset
28498
28499
28500 \end_layout
28501
28502 \end_inset
28503 </cell>
28504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28505 \begin_inset Text
28506
28507 \begin_layout Standard
28508 sdcc/doc/test_suite_spec.pdf 
28509 \emph on
28510 \InsetSpace ~
28511 \InsetSpace ~
28512 \InsetSpace ~
28513
28514 \hfill
28515 online at:
28516 \emph default
28517
28518 \newline
28519
28520 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28521
28522 \end_inset
28523
28524
28525 \end_layout
28526
28527 \end_inset
28528 </cell>
28529 </row>
28530 <row topline="true">
28531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28532 \begin_inset Text
28533
28534 \begin_layout Standard
28535 Various notes
28536 \end_layout
28537
28538 \end_inset
28539 </cell>
28540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28541 \begin_inset Text
28542
28543 \begin_layout Standard
28544 sdcc/doc/* 
28545 \emph on
28546 \InsetSpace ~
28547 \InsetSpace ~
28548 \InsetSpace ~
28549
28550 \hfill
28551 online at:
28552 \emph default
28553
28554 \newline
28555
28556 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
28557
28558 \end_inset
28559
28560
28561 \end_layout
28562
28563 \end_inset
28564 </cell>
28565 </row>
28566 <row topline="true">
28567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28568 \begin_inset Text
28569
28570 \begin_layout Standard
28571 Notes on debugging with SDCDB
28572 \begin_inset LatexCommand \index{SDCDB (debugger)}
28573
28574 \end_inset
28575
28576
28577 \end_layout
28578
28579 \end_inset
28580 </cell>
28581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28582 \begin_inset Text
28583
28584 \begin_layout Standard
28585 sdcc/debugger/README 
28586 \emph on
28587 \InsetSpace ~
28588 \InsetSpace ~
28589 \InsetSpace ~
28590
28591 \hfill
28592 online at
28593 \emph default
28594 :
28595 \newline
28596
28597 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
28598
28599 \end_inset
28600
28601
28602 \end_layout
28603
28604 \end_inset
28605 </cell>
28606 </row>
28607 <row topline="true">
28608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28609 \begin_inset Text
28610
28611 \begin_layout Standard
28612 uCsim
28613 \begin_inset LatexCommand \index{uCsim}
28614
28615 \end_inset
28616
28617  Software simulator for microcontrollers
28618 \end_layout
28619
28620 \end_inset
28621 </cell>
28622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28623 \begin_inset Text
28624
28625 \begin_layout Standard
28626
28627 \family roman
28628 \series medium
28629 \shape up
28630 \size normal
28631 \emph off
28632 \bar no
28633 \noun off
28634 \color none
28635 sdcc/sim/ucsim/doc
28636 \family default
28637 \series default
28638 \shape default
28639 \size default
28640 \emph default
28641 \bar default
28642 \noun default
28643 \color default
28644 /index.html 
28645 \emph on
28646 \InsetSpace ~
28647 \InsetSpace ~
28648 \InsetSpace ~
28649
28650 \hfill
28651 online at:
28652 \emph default
28653
28654 \newline
28655
28656 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
28657
28658 \end_inset
28659
28660
28661 \end_layout
28662
28663 \end_inset
28664 </cell>
28665 </row>
28666 <row topline="true">
28667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28668 \begin_inset Text
28669
28670 \begin_layout Standard
28671 Temporary notes on the pic16
28672 \begin_inset LatexCommand \index{PIC16}
28673
28674 \end_inset
28675
28676  port
28677 \end_layout
28678
28679 \end_inset
28680 </cell>
28681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28682 \begin_inset Text
28683
28684 \begin_layout Standard
28685 sdcc/src/pic16/NOTES 
28686 \emph on
28687 \InsetSpace ~
28688 \InsetSpace ~
28689 \InsetSpace ~
28690
28691 \hfill
28692 online at:
28693 \newline
28694
28695 \emph default
28696
28697 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
28698
28699 \end_inset
28700
28701
28702 \end_layout
28703
28704 \end_inset
28705 </cell>
28706 </row>
28707 <row topline="true" bottomline="true">
28708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28709 \begin_inset Text
28710
28711 \begin_layout Standard
28712 SDCC internal documentation (debugging file format)
28713 \end_layout
28714
28715 \end_inset
28716 </cell>
28717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28718 \begin_inset Text
28719
28720 \begin_layout Standard
28721 sdcc/doc/
28722 \family roman
28723 \series medium
28724 \shape up
28725 \size normal
28726 \emph off
28727 \bar no
28728 \noun off
28729 \color none
28730 cdbfileformat.pd
28731 \family default
28732 \series default
28733 \shape default
28734 \size default
28735 \emph default
28736 \bar default
28737 \noun default
28738 \color default
28739 f
28740 \emph on
28741  \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744
28745 \hfill
28746 online at:
28747 \emph default
28748
28749 \newline
28750
28751 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
28752
28753 \end_inset
28754
28755
28756 \end_layout
28757
28758 \end_inset
28759 </cell>
28760 </row>
28761 </lyxtabular>
28762
28763 \end_inset
28764
28765
28766 \newline
28767
28768 \end_layout
28769
28770 \begin_layout Section
28771 Related open source tools
28772 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
28773
28774 \end_inset
28775
28776
28777 \begin_inset LatexCommand \index{Related tools}
28778
28779 \end_inset
28780
28781
28782 \end_layout
28783
28784 \begin_layout Standard
28785 \align left
28786 \begin_inset Tabular
28787 <lyxtabular version="3" rows="14" columns="3">
28788 <features>
28789 <column alignment="left" valignment="top" leftline="true" width="0pt">
28790 <column alignment="block" valignment="top" leftline="true" width="30line%">
28791 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28792 <row topline="true" bottomline="true">
28793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28794 \begin_inset Text
28795
28796 \begin_layout Standard
28797
28798 \series bold
28799 Name
28800 \end_layout
28801
28802 \end_inset
28803 </cell>
28804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28805 \begin_inset Text
28806
28807 \begin_layout Standard
28808
28809 \series bold
28810 Purpose
28811 \end_layout
28812
28813 \end_inset
28814 </cell>
28815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28816 \begin_inset Text
28817
28818 \begin_layout Standard
28819
28820 \series bold
28821 Where to get
28822 \end_layout
28823
28824 \end_inset
28825 </cell>
28826 </row>
28827 <row topline="true">
28828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28829 \begin_inset Text
28830
28831 \begin_layout Standard
28832 gpsim
28833 \begin_inset LatexCommand \index{gpsim (pic simulator)}
28834
28835 \end_inset
28836
28837
28838 \end_layout
28839
28840 \end_inset
28841 </cell>
28842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28843 \begin_inset Text
28844
28845 \begin_layout Standard
28846 PIC simulator
28847 \end_layout
28848
28849 \end_inset
28850 </cell>
28851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28852 \begin_inset Text
28853
28854 \begin_layout Standard
28855 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
28856
28857 \end_inset
28858
28859
28860 \end_layout
28861
28862 \end_inset
28863 </cell>
28864 </row>
28865 <row topline="true">
28866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28867 \begin_inset Text
28868
28869 \begin_layout Standard
28870 gputils
28871 \begin_inset LatexCommand \index{gputils (pic tools)}
28872
28873 \end_inset
28874
28875
28876 \end_layout
28877
28878 \end_inset
28879 </cell>
28880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28881 \begin_inset Text
28882
28883 \begin_layout Standard
28884 GNU PIC utilities
28885 \end_layout
28886
28887 \end_inset
28888 </cell>
28889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28890 \begin_inset Text
28891
28892 \begin_layout Standard
28893 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
28894
28895 \end_inset
28896
28897
28898 \end_layout
28899
28900 \end_inset
28901 </cell>
28902 </row>
28903 <row topline="true">
28904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28905 \begin_inset Text
28906
28907 \begin_layout Standard
28908 flP5
28909 \end_layout
28910
28911 \end_inset
28912 </cell>
28913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28914 \begin_inset Text
28915
28916 \begin_layout Standard
28917 PIC programmer
28918 \end_layout
28919
28920 \end_inset
28921 </cell>
28922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28923 \begin_inset Text
28924
28925 \begin_layout Standard
28926 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
28927
28928 \end_inset
28929
28930
28931 \end_layout
28932
28933 \end_inset
28934 </cell>
28935 </row>
28936 <row topline="true">
28937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28938 \begin_inset Text
28939
28940 \begin_layout Standard
28941 ec2drv/newcdb
28942 \end_layout
28943
28944 \end_inset
28945 </cell>
28946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28947 \begin_inset Text
28948
28949 \begin_layout Standard
28950 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
28951  (Unix only)
28952 \end_layout
28953
28954 \end_inset
28955 </cell>
28956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28957 \begin_inset Text
28958
28959 \begin_layout Standard
28960 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
28961
28962 \end_inset
28963
28964
28965 \end_layout
28966
28967 \end_inset
28968 </cell>
28969 </row>
28970 <row topline="true">
28971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28972 \begin_inset Text
28973
28974 \begin_layout Standard
28975 indent
28976 \begin_inset LatexCommand \index{indent (source formatting tool)}
28977
28978 \end_inset
28979
28980
28981 \end_layout
28982
28983 \end_inset
28984 </cell>
28985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28986 \begin_inset Text
28987
28988 \begin_layout Standard
28989 Formats C source - Master of the white spaces
28990 \end_layout
28991
28992 \end_inset
28993 </cell>
28994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28995 \begin_inset Text
28996
28997 \begin_layout Standard
28998 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
28999
29000 \end_inset
29001
29002
29003 \end_layout
29004
29005 \end_inset
29006 </cell>
29007 </row>
29008 <row topline="true">
29009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29010 \begin_inset Text
29011
29012 \begin_layout Standard
29013 srecord
29014 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
29015
29016 \end_inset
29017
29018
29019 \end_layout
29020
29021 \end_inset
29022 </cell>
29023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29024 \begin_inset Text
29025
29026 \begin_layout Standard
29027 Object file conversion, checksumming, ...
29028 \end_layout
29029
29030 \end_inset
29031 </cell>
29032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29033 \begin_inset Text
29034
29035 \begin_layout Standard
29036 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
29037
29038 \end_inset
29039
29040
29041 \end_layout
29042
29043 \end_inset
29044 </cell>
29045 </row>
29046 <row topline="true">
29047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29048 \begin_inset Text
29049
29050 \begin_layout Standard
29051 objdump
29052 \begin_inset LatexCommand \index{objdump (tool)}
29053
29054 \end_inset
29055
29056
29057 \end_layout
29058
29059 \end_inset
29060 </cell>
29061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29062 \begin_inset Text
29063
29064 \begin_layout Standard
29065 Object file conversion, ...
29066 \end_layout
29067
29068 \end_inset
29069 </cell>
29070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29071 \begin_inset Text
29072
29073 \begin_layout Standard
29074 Part of binutils (should be there anyway)
29075 \end_layout
29076
29077 \end_inset
29078 </cell>
29079 </row>
29080 <row topline="true">
29081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29082 \begin_inset Text
29083
29084 \begin_layout Standard
29085 cmon51
29086 \end_layout
29087
29088 \end_inset
29089 </cell>
29090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29091 \begin_inset Text
29092
29093 \begin_layout Standard
29094 8051 monitor (hex up-/download, single step, disassemble)
29095 \end_layout
29096
29097 \end_inset
29098 </cell>
29099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29100 \begin_inset Text
29101
29102 \begin_layout Standard
29103 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
29104
29105 \end_inset
29106
29107
29108 \end_layout
29109
29110 \end_inset
29111 </cell>
29112 </row>
29113 <row topline="true">
29114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29115 \begin_inset Text
29116
29117 \begin_layout Standard
29118 doxygen
29119 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
29120
29121 \end_inset
29122
29123
29124 \end_layout
29125
29126 \end_inset
29127 </cell>
29128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29129 \begin_inset Text
29130
29131 \begin_layout Standard
29132 Source code documentation system
29133 \end_layout
29134
29135 \end_inset
29136 </cell>
29137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29138 \begin_inset Text
29139
29140 \begin_layout Standard
29141 \begin_inset LatexCommand \url{http://www.doxygen.org}
29142
29143 \end_inset
29144
29145
29146 \end_layout
29147
29148 \end_inset
29149 </cell>
29150 </row>
29151 <row topline="true">
29152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29153 \begin_inset Text
29154
29155 \begin_layout Standard
29156 kdevelop
29157 \end_layout
29158
29159 \end_inset
29160 </cell>
29161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29162 \begin_inset Text
29163
29164 \begin_layout Standard
29165 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
29166 \end_layout
29167
29168 \end_inset
29169 </cell>
29170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29171 \begin_inset Text
29172
29173 \begin_layout Standard
29174 \begin_inset LatexCommand \url{http://www.kdevelop.org}
29175
29176 \end_inset
29177
29178
29179 \end_layout
29180
29181 \end_inset
29182 </cell>
29183 </row>
29184 <row topline="true">
29185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29186 \begin_inset Text
29187
29188 \begin_layout Standard
29189 paulmon
29190 \end_layout
29191
29192 \end_inset
29193 </cell>
29194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29195 \begin_inset Text
29196
29197 \begin_layout Standard
29198 8051 monitor (hex up-/download, single step, disassemble)
29199 \end_layout
29200
29201 \end_inset
29202 </cell>
29203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29204 \begin_inset Text
29205
29206 \begin_layout Standard
29207 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
29208
29209 \end_inset
29210
29211
29212 \end_layout
29213
29214 \end_inset
29215 </cell>
29216 </row>
29217 <row topline="true">
29218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29219 \begin_inset Text
29220
29221 \begin_layout Standard
29222 splint
29223 \begin_inset LatexCommand \index{splint (syntax checking tool)}
29224
29225 \end_inset
29226
29227
29228 \end_layout
29229
29230 \end_inset
29231 </cell>
29232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29233 \begin_inset Text
29234
29235 \begin_layout Standard
29236 Statically checks c sources (see 
29237 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
29238
29239 \end_inset
29240
29241 )
29242 \end_layout
29243
29244 \end_inset
29245 </cell>
29246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29247 \begin_inset Text
29248
29249 \begin_layout Standard
29250 \begin_inset LatexCommand \url{http://www.splint.org}
29251
29252 \end_inset
29253
29254
29255 \end_layout
29256
29257 \end_inset
29258 </cell>
29259 </row>
29260 <row topline="true" bottomline="true">
29261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29262 \begin_inset Text
29263
29264 \begin_layout Standard
29265 ddd
29266 \begin_inset LatexCommand \index{DDD (debugger)}
29267
29268 \end_inset
29269
29270
29271 \end_layout
29272
29273 \end_inset
29274 </cell>
29275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29276 \begin_inset Text
29277
29278 \begin_layout Standard
29279 Debugger, serves nicely as GUI to SDCDB
29280 \begin_inset LatexCommand \index{SDCDB (debugger)}
29281
29282 \end_inset
29283
29284  (Unix only)
29285 \end_layout
29286
29287 \end_inset
29288 </cell>
29289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29290 \begin_inset Text
29291
29292 \begin_layout Standard
29293 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
29294
29295 \end_inset
29296
29297
29298 \end_layout
29299
29300 \end_inset
29301 </cell>
29302 </row>
29303 </lyxtabular>
29304
29305 \end_inset
29306
29307
29308 \newline
29309
29310 \end_layout
29311
29312 \begin_layout Section
29313 Related documentation / recommended reading
29314 \end_layout
29315
29316 \begin_layout Standard
29317 \align left
29318 \begin_inset Tabular
29319 <lyxtabular version="3" rows="7" columns="3">
29320 <features>
29321 <column alignment="left" valignment="top" leftline="true" width="0pt">
29322 <column alignment="left" valignment="top" leftline="true" width="0">
29323 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29324 <row topline="true" bottomline="true">
29325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29326 \begin_inset Text
29327
29328 \begin_layout Standard
29329
29330 \series bold
29331 Name
29332 \end_layout
29333
29334 \end_inset
29335 </cell>
29336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29337 \begin_inset Text
29338
29339 \begin_layout Standard
29340
29341 \series bold
29342 Subject / Title
29343 \end_layout
29344
29345 \end_inset
29346 </cell>
29347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29348 \begin_inset Text
29349
29350 \begin_layout Standard
29351
29352 \series bold
29353 Where to get
29354 \end_layout
29355
29356 \end_inset
29357 </cell>
29358 </row>
29359 <row topline="true">
29360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29361 \begin_inset Text
29362
29363 \begin_layout Standard
29364
29365 \family roman
29366 \series medium
29367 \shape up
29368 \size normal
29369 \emph off
29370 \bar no
29371 \noun off
29372 \color none
29373 c-refcard.pdf
29374 \end_layout
29375
29376 \end_inset
29377 </cell>
29378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29379 \begin_inset Text
29380
29381 \begin_layout Standard
29382 C Reference Card
29383 \begin_inset LatexCommand \index{C Reference card}
29384
29385 \end_inset
29386
29387 , 2 pages
29388 \end_layout
29389
29390 \end_inset
29391 </cell>
29392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29393 \begin_inset Text
29394
29395 \begin_layout Standard
29396 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
29397
29398 \end_inset
29399
29400
29401 \end_layout
29402
29403 \end_inset
29404 </cell>
29405 </row>
29406 <row topline="true">
29407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29408 \begin_inset Text
29409
29410 \begin_layout Standard
29411 c-faq
29412 \end_layout
29413
29414 \end_inset
29415 </cell>
29416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29417 \begin_inset Text
29418
29419 \begin_layout Standard
29420 C-FAQ
29421 \begin_inset LatexCommand \index{C FAQ}
29422
29423 \end_inset
29424
29425
29426 \end_layout
29427
29428 \end_inset
29429 </cell>
29430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29431 \begin_inset Text
29432
29433 \begin_layout Standard
29434 \begin_inset LatexCommand \url{http://www.c-faq.com}
29435
29436 \end_inset
29437
29438
29439 \end_layout
29440
29441 \end_inset
29442 </cell>
29443 </row>
29444 <row topline="true">
29445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29446 \begin_inset Text
29447
29448 \begin_layout Standard
29449 ISO/IEC 9899:TC2
29450 \end_layout
29451
29452 \end_inset
29453 </cell>
29454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29455 \begin_inset Text
29456
29457 \begin_layout Standard
29458 \begin_inset Quotes sld
29459 \end_inset
29460
29461 C-Standard
29462 \begin_inset Quotes srd
29463 \end_inset
29464
29465
29466 \end_layout
29467
29468 \end_inset
29469 </cell>
29470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29471 \begin_inset Text
29472
29473 \begin_layout Standard
29474
29475 \size footnotesize
29476 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29477
29478 \end_inset
29479
29480
29481 \end_layout
29482
29483 \end_inset
29484 </cell>
29485 </row>
29486 <row topline="true">
29487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29488 \begin_inset Text
29489
29490 \begin_layout Standard
29491 ISO/IEC DTR 18037
29492 \end_layout
29493
29494 \end_inset
29495 </cell>
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29497 \begin_inset Text
29498
29499 \begin_layout Standard
29500 \begin_inset Quotes sld
29501 \end_inset
29502
29503 Extensions for Embedded C
29504 \begin_inset Quotes srd
29505 \end_inset
29506
29507
29508 \end_layout
29509
29510 \end_inset
29511 </cell>
29512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29513 \begin_inset Text
29514
29515 \begin_layout Standard
29516
29517 \size footnotesize
29518 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
29519
29520 \end_inset
29521
29522
29523 \end_layout
29524
29525 \end_inset
29526 </cell>
29527 </row>
29528 <row topline="true">
29529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29530 \begin_inset Text
29531
29532 \begin_layout Standard
29533
29534 \end_layout
29535
29536 \end_inset
29537 </cell>
29538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29539 \begin_inset Text
29540
29541 \begin_layout Standard
29542 Latest datasheet of target CPU
29543 \end_layout
29544
29545 \end_inset
29546 </cell>
29547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29548 \begin_inset Text
29549
29550 \begin_layout Standard
29551 vendor
29552 \end_layout
29553
29554 \end_inset
29555 </cell>
29556 </row>
29557 <row topline="true" bottomline="true">
29558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29559 \begin_inset Text
29560
29561 \begin_layout Standard
29562
29563 \end_layout
29564
29565 \end_inset
29566 </cell>
29567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29568 \begin_inset Text
29569
29570 \begin_layout Standard
29571 Revision history of datasheet
29572 \end_layout
29573
29574 \end_inset
29575 </cell>
29576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29577 \begin_inset Text
29578
29579 \begin_layout Standard
29580 vendor
29581 \end_layout
29582
29583 \end_inset
29584 </cell>
29585 </row>
29586 </lyxtabular>
29587
29588 \end_inset
29589
29590
29591 \newline
29592
29593 \end_layout
29594
29595 \begin_layout Section
29596 Application notes specifically for SDCC
29597 \end_layout
29598
29599 \begin_layout Standard
29600 SDCC makes no claims about the completeness of this list and about up-to-datenes
29601 s or correctness of the application notes
29602 \begin_inset LatexCommand \index{Application notes}
29603
29604 \end_inset
29605
29606 .
29607 \end_layout
29608
29609 \begin_layout Standard
29610 \align left
29611
29612 \size footnotesize
29613 \begin_inset Tabular
29614 <lyxtabular version="3" rows="7" columns="3">
29615 <features>
29616 <column alignment="block" valignment="top" leftline="true" width="17col%">
29617 <column alignment="block" valignment="top" leftline="true" width="27col%">
29618 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
29619 <row topline="true" bottomline="true">
29620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29621 \begin_inset Text
29622
29623 \begin_layout Standard
29624
29625 \series bold
29626 \size footnotesize
29627 Vendor
29628 \end_layout
29629
29630 \end_inset
29631 </cell>
29632 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
29633 \begin_inset Text
29634
29635 \begin_layout Standard
29636
29637 \series bold
29638 \size footnotesize
29639 Subject / Title
29640 \end_layout
29641
29642 \end_inset
29643 </cell>
29644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29645 \begin_inset Text
29646
29647 \begin_layout Standard
29648
29649 \series bold
29650 \size footnotesize
29651 Where to get
29652 \end_layout
29653
29654 \end_inset
29655 </cell>
29656 </row>
29657 <row topline="true">
29658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29659 \begin_inset Text
29660
29661 \begin_layout Standard
29662
29663 \size footnotesize
29664 Maxim / Dallas
29665 \end_layout
29666
29667 \end_inset
29668 </cell>
29669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29670 \begin_inset Text
29671
29672 \begin_layout Standard
29673
29674 \size footnotesize
29675 Using the SDCC Compiler for the DS80C400
29676 \begin_inset LatexCommand \index{DS80C400}
29677
29678 \end_inset
29679
29680
29681 \end_layout
29682
29683 \end_inset
29684 </cell>
29685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29686 \begin_inset Text
29687
29688 \begin_layout Standard
29689
29690 \size footnotesize
29691 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
29692
29693 \end_inset
29694
29695
29696 \end_layout
29697
29698 \end_inset
29699 </cell>
29700 </row>
29701 <row topline="true">
29702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29703 \begin_inset Text
29704
29705 \begin_layout Standard
29706
29707 \size footnotesize
29708 Maxim / Dallas
29709 \end_layout
29710
29711 \end_inset
29712 </cell>
29713 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
29714 \begin_inset Text
29715
29716 \begin_layout Standard
29717
29718 \size footnotesize
29719 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
29720 \begin_inset LatexCommand \index{DS89C4x0}
29721
29722 \end_inset
29723
29724  Family of Microcontrollers
29725 \end_layout
29726
29727 \end_inset
29728 </cell>
29729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29730 \begin_inset Text
29731
29732 \begin_layout Standard
29733
29734 \size footnotesize
29735 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
29736
29737 \end_inset
29738
29739
29740 \end_layout
29741
29742 \end_inset
29743 </cell>
29744 </row>
29745 <row topline="true">
29746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29747 \begin_inset Text
29748
29749 \begin_layout Standard
29750
29751 \size footnotesize
29752 Silicon Laboratories / Cygnal
29753 \end_layout
29754
29755 \end_inset
29756 </cell>
29757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29758 \begin_inset Text
29759
29760 \begin_layout Standard
29761
29762 \size footnotesize
29763 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
29764 \begin_inset LatexCommand \index{IDE}
29765
29766 \end_inset
29767
29768
29769 \end_layout
29770
29771 \end_inset
29772 </cell>
29773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29774 \begin_inset Text
29775
29776 \begin_layout Standard
29777
29778 \size footnotesize
29779 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
29780
29781 \end_inset
29782
29783
29784 \end_layout
29785
29786 \end_inset
29787 </cell>
29788 </row>
29789 <row topline="true">
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29791 \begin_inset Text
29792
29793 \begin_layout Standard
29794
29795 \size footnotesize
29796 Ramtron / Goal Semiconductor
29797 \end_layout
29798
29799 \end_inset
29800 </cell>
29801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29802 \begin_inset Text
29803
29804 \begin_layout Standard
29805
29806 \size footnotesize
29807 Interfacing SDCC to Syn and Textpad
29808 \end_layout
29809
29810 \end_inset
29811 </cell>
29812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29813 \begin_inset Text
29814
29815 \begin_layout Standard
29816
29817 \size footnotesize
29818 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29819
29820 \end_inset
29821
29822
29823 \end_layout
29824
29825 \end_inset
29826 </cell>
29827 </row>
29828 <row topline="true">
29829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29830 \begin_inset Text
29831
29832 \begin_layout Standard
29833
29834 \size footnotesize
29835 Ramtron / Goal Semiconductor
29836 \end_layout
29837
29838 \end_inset
29839 </cell>
29840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29841 \begin_inset Text
29842
29843 \begin_layout Standard
29844
29845 \size footnotesize
29846 Installing and Configuring SDCC and Crimson Editor 
29847 \end_layout
29848
29849 \end_inset
29850 </cell>
29851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29852 \begin_inset Text
29853
29854 \begin_layout Standard
29855
29856 \size footnotesize
29857 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29858
29859 \end_inset
29860
29861
29862 \end_layout
29863
29864 \end_inset
29865 </cell>
29866 </row>
29867 <row topline="true" bottomline="true">
29868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29869 \begin_inset Text
29870
29871 \begin_layout Standard
29872
29873 \size footnotesize
29874 Texas Instruments
29875 \end_layout
29876
29877 \end_inset
29878 </cell>
29879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29880 \begin_inset Text
29881
29882 \begin_layout Standard
29883
29884 \size footnotesize
29885 MSC12xx Programming with SDCC
29886 \end_layout
29887
29888 \end_inset
29889 </cell>
29890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29891 \begin_inset Text
29892
29893 \begin_layout Standard
29894
29895 \size footnotesize
29896 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
29897
29898 \end_inset
29899
29900
29901 \end_layout
29902
29903 \end_inset
29904 </cell>
29905 </row>
29906 </lyxtabular>
29907
29908 \end_inset
29909
29910
29911 \end_layout
29912
29913 \begin_layout Section
29914 Some Questions
29915 \end_layout
29916
29917 \begin_layout Standard
29918 Some questions answered, some pointers given - it might be time to in turn
29919  ask 
29920 \emph on
29921 you
29922 \emph default
29923  some questions: 
29924 \end_layout
29925
29926 \begin_layout Itemize
29927 can you solve your project with the selected microcontroller? Would you
29928  find out early or rather late that your target is too small/slow/whatever?
29929  Can you switch to a slightly better device if it doesn't fit?
29930 \end_layout
29931
29932 \begin_layout Itemize
29933 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
29934  and/or another programming language be more adequate? Would an operating
29935  system on the target device help?
29936 \end_layout
29937
29938 \begin_layout Itemize
29939 if you solved the problem, will the marketing department be happy?
29940 \end_layout
29941
29942 \begin_layout Itemize
29943 if the marketing department is happy, will customers be happy?
29944 \end_layout
29945
29946 \begin_layout Itemize
29947 if you're the project manager, marketing department and maybe even the customer
29948  in one person, have you tried to see the project from the outside?
29949 \end_layout
29950
29951 \begin_layout Itemize
29952 is the project done if you think it is done? Or is just that other interface/pro
29953 tocol/feature/configuration/option missing? How about website, manual(s),
29954  internationali(z|s)ation, packaging, labels, 2nd source for components,
29955  electromagnetic compatability/interference, documentation for production,
29956  production test software, update mechanism, patent issues?
29957 \end_layout
29958
29959 \begin_layout Itemize
29960 is your project adequately positioned in that magic triangle: fame, fortune,
29961  fun?
29962 \end_layout
29963
29964 \begin_layout Standard
29965 Maybe not all answers to these questions are known and some answers may
29966  even be 
29967 \emph on
29968 no
29969 \emph default
29970 , nevertheless knowing these questions may help you to avoid burnout
29971 \begin_inset Foot
29972 status open
29973
29974 \begin_layout Standard
29975 burnout is bad for electronic devices, programmers and motorcycle tyres
29976 \end_layout
29977
29978 \end_inset
29979
29980 .
29981  Chances are you didn't want to hear some of them...
29982 \end_layout
29983
29984 \begin_layout Chapter
29985 Support
29986 \begin_inset LatexCommand \index{Support}
29987
29988 \end_inset
29989
29990
29991 \end_layout
29992
29993 \begin_layout Standard
29994 SDCC has grown to be a large project.
29995  The compiler alone (without the preprocessor, assembler and linker) is
29996  well over 150,000 lines of code (blank stripped).
29997  The open source nature of this project is a key to its continued growth
29998  and support.
29999  You gain the benefit and support of many active software developers and
30000  end users.
30001  Is SDCC perfect? No, that's why we need your help.
30002  The developers take pride in fixing reported bugs.
30003  You can help by reporting the bugs and helping other SDCC users.
30004  There are lots of ways to contribute, and we encourage you to take part
30005  in making SDCC a great software package.
30006  
30007 \end_layout
30008
30009 \begin_layout Standard
30010 The SDCC project is hosted on the SDCC sourceforge site at 
30011 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
30012
30013 \end_inset
30014
30015 .
30016  You'll find the complete set of mailing lists
30017 \begin_inset LatexCommand \index{Mailing list(s)}
30018
30019 \end_inset
30020
30021 , forums, bug reporting system, patch submission
30022 \begin_inset LatexCommand \index{Patch submission}
30023
30024 \end_inset
30025
30026  system, download
30027 \begin_inset LatexCommand \index{download}
30028
30029 \end_inset
30030
30031  area and Subversion code repository
30032 \begin_inset LatexCommand \index{Subversion code repository}
30033
30034 \end_inset
30035
30036  there.
30037 \end_layout
30038
30039 \begin_layout Section
30040 Reporting Bugs
30041 \begin_inset LatexCommand \index{Bug reporting}
30042
30043 \end_inset
30044
30045
30046 \begin_inset LatexCommand \index{Reporting bugs}
30047
30048 \end_inset
30049
30050
30051 \end_layout
30052
30053 \begin_layout Standard
30054 The recommended way of reporting bugs is using the infrastructure of the
30055  sourceforge site.
30056  You can follow the status of bug reports there and have an overview about
30057  the known bugs.
30058 \end_layout
30059
30060 \begin_layout Standard
30061 Bug reports are automatically forwarded to the developer mailing list and
30062  will be fixed ASAP.
30063  When reporting a bug, it is very useful to include a small test program
30064  (the smaller the better) which reproduces the problem.
30065  If you can isolate the problem by looking at the generated assembly code,
30066  this can be very helpful.
30067  Compiling your program with the -
30068 \begin_inset ERT
30069 status collapsed
30070
30071 \begin_layout Standard
30072
30073
30074 \backslash
30075 /
30076 \end_layout
30077
30078 \end_inset
30079
30080 -dumpall
30081 \begin_inset LatexCommand \index{-\/-dumpall}
30082
30083 \end_inset
30084
30085  option can sometimes be useful in locating optimization problems.
30086  When reporting a bug please make sure you:
30087 \end_layout
30088
30089 \begin_layout Enumerate
30090 Attach the code you are compiling with SDCC.
30091  
30092 \end_layout
30093
30094 \begin_layout Enumerate
30095 Specify the exact command you use to run SDCC, or attach your Makefile.
30096  
30097 \end_layout
30098
30099 \begin_layout Enumerate
30100 Specify the SDCC version (type "
30101 \family sans
30102 \series bold
30103 sdcc -v
30104 \family default
30105 \series default
30106 "), your platform, and operating system.
30107  
30108 \end_layout
30109
30110 \begin_layout Enumerate
30111 Provide an exact copy of any error message or incorrect output.
30112  
30113 \end_layout
30114
30115 \begin_layout Enumerate
30116 Put something meaningful in the subject of your message.
30117 \end_layout
30118
30119 \begin_layout Standard
30120 Please attempt to include these 5 important parts, as applicable, in all
30121  requests for support or when reporting any problems or bugs with SDCC.
30122  Though this will make your message lengthy, it will greatly improve your
30123  chance that SDCC users and developers will be able to help you.
30124  Some SDCC developers are frustrated by bug reports without code provided
30125  that they can use to reproduce and ultimately fix the problem, so please
30126  be sure to provide sample code if you are reporting a bug! 
30127 \end_layout
30128
30129 \begin_layout Standard
30130 Please have a short check that you are using a recent version of SDCC and
30131  the bug is not yet known.
30132  This is the link for reporting bugs: 
30133 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
30134
30135 \end_inset
30136
30137 .
30138  With SDCC on average having more than 200 downloads
30139 \begin_inset LatexCommand \index{download}
30140
30141 \end_inset
30142
30143  on sourceforge per day
30144 \begin_inset Foot
30145 status open
30146
30147 \begin_layout Standard
30148 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
30149  between 2002 and 2005.
30150  This does not include other methods of distribution.
30151 \end_layout
30152
30153 \end_inset
30154
30155  there must be some users.
30156  So it's not exactly easy to find a new bug.
30157  If you find one we need it: 
30158 \emph on
30159 reporting bugs is good
30160 \emph default
30161 .
30162 \end_layout
30163
30164 \begin_layout Section
30165 Requesting Features
30166 \begin_inset LatexCommand \label{sub:Requesting-Features}
30167
30168 \end_inset
30169
30170
30171 \begin_inset LatexCommand \index{Feature request}
30172
30173 \end_inset
30174
30175
30176 \begin_inset LatexCommand \index{Requesting features}
30177
30178 \end_inset
30179
30180
30181 \end_layout
30182
30183 \begin_layout Standard
30184 Like bug reports feature requests are forwarded to the developer mailing
30185  list.
30186  This is the link for requesting features: 
30187 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30188
30189 \end_inset
30190
30191 .
30192 \end_layout
30193
30194 \begin_layout Section
30195 Submitting patches
30196 \end_layout
30197
30198 \begin_layout Standard
30199 Like bug reports contributed patches are forwarded to the developer mailing
30200  list.
30201  This is the link for submitting patches
30202 \begin_inset LatexCommand \index{Patch submission}
30203
30204 \end_inset
30205
30206
30207 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
30208
30209 \end_inset
30210
30211 .
30212 \end_layout
30213
30214 \begin_layout Standard
30215 You need to specify some parameters to the 
30216 \family typewriter
30217 diff
30218 \family default
30219  command for the patches to be useful.
30220  If you modified more than one file a patch created f.e.
30221  with 
30222 \family sans
30223 \series bold
30224
30225 \begin_inset Quotes sld
30226 \end_inset
30227
30228 diff -Naur unmodified_directory modified_directory >my_changes.patch
30229 \begin_inset Quotes srd
30230 \end_inset
30231
30232
30233 \family default
30234 \series default
30235  will be fine, otherwise 
30236 \family sans
30237 \series bold
30238
30239 \begin_inset Quotes sld
30240 \end_inset
30241
30242 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
30243 \begin_inset Quotes srd
30244 \end_inset
30245
30246
30247 \series default
30248  
30249 \family default
30250 will do.
30251 \end_layout
30252
30253 \begin_layout Section
30254 Getting Help
30255 \end_layout
30256
30257 \begin_layout Standard
30258 These links should take you directly to the 
30259 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
30260
30261 \end_inset
30262
30263
30264 \begin_inset Foot
30265 status open
30266
30267 \begin_layout Standard
30268 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
30269  automated messages (mid 2003)
30270 \end_layout
30271
30272 \end_inset
30273
30274  and the 
30275 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
30276
30277 \end_inset
30278
30279 , lists
30280 \begin_inset LatexCommand \index{Mailing list(s)}
30281
30282 \end_inset
30283
30284  and forums are archived and searchable so if you are lucky someone already
30285  had a similar problem.
30286  While mails to the lists themselves are delivered promptly their web front
30287  end on sourceforge sometimes shows a severe time lag (up to several weeks),
30288  if you're seriously using SDCC please consider subscribing to the lists.
30289 \end_layout
30290
30291 \begin_layout Section
30292 ChangeLog
30293 \end_layout
30294
30295 \begin_layout Standard
30296 You can follow the status of the Subversion version
30297 \begin_inset LatexCommand \index{version}
30298
30299 \end_inset
30300
30301  of SDCC by watching the Changelog
30302 \begin_inset LatexCommand \index{Changelog}
30303
30304 \end_inset
30305
30306  in the Subversion repository
30307 \size footnotesize
30308  
30309 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30310
30311 \end_inset
30312
30313 .
30314 \end_layout
30315
30316 \begin_layout Section
30317 Subversion Source Code Repository
30318 \end_layout
30319
30320 \begin_layout Standard
30321 The output of 
30322 \family sans
30323 \series bold
30324 sdcc --version
30325 \family default
30326 \series default
30327  or the filenames of the snapshot versions of SDCC include date and its
30328  Subversion
30329 \begin_inset LatexCommand \index{Subversion code repository}
30330
30331 \end_inset
30332
30333  number.
30334  Subversion allows to download the source of recent or previous versions
30335  
30336 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
30337
30338 \end_inset
30339
30340  (by number or by date).
30341  An on-line source code browser and detailled instructions are also available
30342  there.
30343  SDCC versions starting from 1999 up to now are available (currently the
30344  versions prior to the conversion from cvs
30345 \begin_inset LatexCommand \index{cvs|see{Subversion}}
30346
30347 \end_inset
30348
30349  to Subversion (April 2006) are either by accessible by Subversion or by
30350  cvs).
30351 \end_layout
30352
30353 \begin_layout Section
30354 Release policy
30355 \begin_inset LatexCommand \index{Release policy}
30356
30357 \end_inset
30358
30359
30360 \end_layout
30361
30362 \begin_layout Standard
30363 Historically there often were long delays between official releases and
30364  the sourceforge download area tends to get not updated at all.
30365  Excuses in the past might have referred to problems with live range analysis,
30366  but as this was fixed a while ago, the current problem is that another
30367  excuse has to be found.
30368  Kidding aside, we have to get better there! On the other hand there are
30369  daily snapshots available at 
30370 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
30371
30372 \end_inset
30373
30374 , and you can always build the very last version (hopefully with many bugs
30375  fixed, and features added) from the source code available at 
30376 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
30377
30378 \end_inset
30379
30380 .
30381  A release wiki
30382 \begin_inset LatexCommand \index{wiki}
30383
30384 \end_inset
30385
30386
30387 \begin_inset LatexCommand \index{Release wiki}
30388
30389 \end_inset
30390
30391  at 
30392 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
30393
30394 \end_inset
30395
30396  also holds some information about past and future releases.
30397 \end_layout
30398
30399 \begin_layout Section
30400 Examples
30401 \begin_inset LatexCommand \index{Examples}
30402
30403 \end_inset
30404
30405
30406 \end_layout
30407
30408 \begin_layout Standard
30409 You'll find some small examples in the directory 
30410 \emph on
30411 sdcc/device/examples/.
30412  
30413 \emph default
30414 More examples and libraries are available at
30415 \emph on
30416  The SDCC Open Knowledge Resource 
30417 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
30418
30419 \end_inset
30420
30421  
30422 \emph default
30423 web site or at 
30424 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
30425
30426 \end_inset
30427
30428 .
30429 \end_layout
30430
30431 \begin_layout Standard
30432 \begin_inset Note Comment
30433 status collapsed
30434
30435 \begin_layout Standard
30436 I did insert a reference to Paul's web site here although it seems rather
30437  dedicated to a specific 8032 board (I think it's okay because it f.e.
30438  shows LCD/Harddisc interface and has a free 8051 monitor.
30439  Independent 8032 board vendors face hard competition of heavily subsidized
30440  development boards anyway).
30441 \end_layout
30442
30443 \begin_layout Standard
30444 Maybe we should include some links to real world applications.
30445  Preferably pointer to pointers (one for each architecture) so this stays
30446  manageable here?
30447 \end_layout
30448
30449 \end_inset
30450
30451
30452 \end_layout
30453
30454 \begin_layout Section
30455 Quality control
30456 \begin_inset LatexCommand \label{sec:Quality-control}
30457
30458 \end_inset
30459
30460
30461 \begin_inset LatexCommand \index{Quality control}
30462
30463 \end_inset
30464
30465
30466 \end_layout
30467
30468 \begin_layout Standard
30469 The compiler is passed through nightly compile and build checks.
30470  The so called 
30471 \shape italic
30472 regression tests
30473 \shape default
30474
30475 \begin_inset LatexCommand \index{Regression test}
30476
30477 \end_inset
30478
30479  check that SDCC itself compiles flawlessly on several host platforms (i386,
30480  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
30481  the quality of the code generated by SDCC by running the code for several
30482  target platforms through simulators.
30483  The regression test suite comprises more than 100 files which expand to
30484  more than 500 test cases which include more than 4500 tests.
30485  The results of these tests are published daily on SDCC's snapshot page
30486  (click on the red or green symbols on the right side of 
30487 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
30488
30489 \end_inset
30490
30491 ).
30492 \end_layout
30493
30494 \begin_layout Standard
30495 There is a separate document 
30496 \shape italic
30497 test_suite.pdf 
30498 \begin_inset LatexCommand \index{Test suite}
30499
30500 \end_inset
30501
30502
30503 \shape default
30504  
30505 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30506
30507 \end_inset
30508
30509  about the regression test suite.
30510 \end_layout
30511
30512 \begin_layout Standard
30513 You'll find the test code in the directory 
30514 \shape italic
30515 sdcc/support/regression
30516 \shape default
30517 .
30518  You can run these tests manually by running 
30519 \family sans
30520 make
30521 \family default
30522  in this directory (or f.e.
30523  
30524 \family sans
30525 \series bold
30526
30527 \begin_inset Quotes sld
30528 \end_inset
30529
30530 make test-mcs51
30531 \begin_inset Quotes srd
30532 \end_inset
30533
30534
30535 \family default
30536 \series default
30537  if you don't want to run the complete tests).
30538  The test code might also be interesting if you want to look for examples
30539 \begin_inset LatexCommand \index{Examples}
30540
30541 \end_inset
30542
30543  checking corner cases of SDCC or if you plan to submit patches
30544 \begin_inset LatexCommand \index{Patch submission}
30545
30546 \end_inset
30547
30548 .
30549 \end_layout
30550
30551 \begin_layout Standard
30552 The 14bit pic port uses a different set of regression tests 
30553 \begin_inset LatexCommand \index{Regression test (PIC14)}
30554
30555 \end_inset
30556
30557 , you'll find them in the directory 
30558 \shape italic
30559 sdcc/src/regression
30560 \shape default
30561 .
30562 \end_layout
30563
30564 \begin_layout Section
30565 Use of SDCC in Education
30566 \end_layout
30567
30568 \begin_layout Standard
30569 In short: 
30570 \emph on
30571 highly
30572 \emph default
30573  encouraged
30574 \begin_inset Foot
30575 status open
30576
30577 \begin_layout Standard
30578 the phrase "use in education" might evoke the association "
30579 \emph on
30580 only
30581 \emph default
30582  fit for use in education".
30583  This connotation is not intended but nevertheless risked as the licensing
30584  of SDCC makes it difficult to offer educational discounts
30585 \end_layout
30586
30587 \end_inset
30588
30589 .
30590  If your rationales are to:
30591 \end_layout
30592
30593 \begin_layout Enumerate
30594 give students a chance to understand the 
30595 \emph on
30596 complete
30597 \emph default
30598  steps of code generation
30599 \end_layout
30600
30601 \begin_layout Enumerate
30602 have a curriculum that can be extended for years.
30603  Then you could use an fpga board as target and your curriculum will seamlessly
30604  extend from logic synthesis (
30605 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
30606
30607 \end_inset
30608
30609
30610 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
30611
30612 \end_inset
30613
30614 ), over assembly programming, to C to FPGA compilers (
30615 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
30616
30617 \end_inset
30618
30619 ) and to C.
30620 \end_layout
30621
30622 \begin_layout Enumerate
30623 be able to insert excursions about skills like using a revision control
30624  system, submitting/applying patches, using a type-setting (as opposed to
30625  word-processing) engine LyX/LaTeX, using 
30626 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
30627
30628 \end_inset
30629
30630 , following some 
30631 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
30632
30633 \end_inset
30634
30635 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
30636  Source Software, CPU simulation, compiler regression tests
30637 \begin_inset LatexCommand \index{Regression test}
30638
30639 \end_inset
30640
30641 .
30642  
30643 \newline
30644 And if there should be a shortage of ideas then you can always point students
30645  to the ever-growing feature request list 
30646 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30647
30648 \end_inset
30649
30650 .
30651 \end_layout
30652
30653 \begin_layout Enumerate
30654 not tie students to a specific host platform and instead allow them to use
30655  a host platform of 
30656 \emph on
30657 their
30658 \emph default
30659  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
30660  eventually 
30661 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
30662
30663 \end_inset
30664
30665 )
30666 \end_layout
30667
30668 \begin_layout Enumerate
30669 not encourage students to use illegal copies of educational software
30670 \end_layout
30671
30672 \begin_layout Enumerate
30673 be immune to licensing/availability/price changes of the chosen tool chain
30674 \end_layout
30675
30676 \begin_layout Enumerate
30677 be able to change to a new target platform without having to adopt a new
30678  tool chain
30679 \end_layout
30680
30681 \begin_layout Enumerate
30682 have complete control over and insight into the tool chain
30683 \end_layout
30684
30685 \begin_layout Enumerate
30686 make your students aware about the pros and cons of open source software
30687  development
30688 \end_layout
30689
30690 \begin_layout Enumerate
30691 give back to the public as you are probably at least partially publically
30692  funded
30693 \end_layout
30694
30695 \begin_layout Enumerate
30696 give students a chance to publically prove their skills and to possibly
30697  see a world wide impact
30698 \end_layout
30699
30700 \begin_layout Standard
30701 then SDCC is probably among the first choices.
30702  Well, probably SDCC might be the only choice.
30703 \end_layout
30704
30705 \begin_layout Standard
30706
30707 \newpage
30708
30709 \end_layout
30710
30711 \begin_layout Chapter
30712 SDCC Technical Data
30713 \end_layout
30714
30715 \begin_layout Section
30716 Optimizations
30717 \begin_inset LatexCommand \index{Optimizations}
30718
30719 \end_inset
30720
30721
30722 \end_layout
30723
30724 \begin_layout Standard
30725 SDCC performs a host of standard optimizations in addition to some MCU specific
30726  optimizations.
30727  
30728 \end_layout
30729
30730 \begin_layout Subsection
30731 Sub-expression Elimination
30732 \begin_inset LatexCommand \index{Subexpression elimination}
30733
30734 \end_inset
30735
30736
30737 \end_layout
30738
30739 \begin_layout Standard
30740 The compiler does local and 
30741 \emph on
30742 g
30743 \emph default
30744 lobal 
30745 \emph on
30746 c
30747 \emph default
30748 ommon 
30749 \emph on
30750 s
30751 \emph default
30752 ubexpression 
30753 \emph on
30754 e
30755 \emph default
30756 limination, e.g.: 
30757 \end_layout
30758
30759 \begin_layout Verse
30760
30761 \family typewriter
30762 i = x + y + 1; 
30763 \newline
30764 j = x + y;
30765 \end_layout
30766
30767 \begin_layout Standard
30768 will be translated to
30769 \end_layout
30770
30771 \begin_layout Verse
30772
30773 \family typewriter
30774 iTemp = x + y; 
30775 \newline
30776 i = iTemp + 1; 
30777 \newline
30778 j = iTemp;
30779 \end_layout
30780
30781 \begin_layout Standard
30782 Some subexpressions are not as obvious as the above example, e.g.:
30783 \end_layout
30784
30785 \begin_layout Verse
30786
30787 \family typewriter
30788 a->b[i].c = 10; 
30789 \newline
30790 a->b[i].d = 11;
30791 \end_layout
30792
30793 \begin_layout Standard
30794 In this case the address arithmetic a->b[i] will be computed only once;
30795  the equivalent code in C would be.
30796 \end_layout
30797
30798 \begin_layout Verse
30799
30800 \family typewriter
30801 iTemp = a->b[i]; 
30802 \newline
30803 iTemp.c = 10; 
30804 \newline
30805 iTemp.d = 11;
30806 \end_layout
30807
30808 \begin_layout Standard
30809 The compiler will try to keep these temporary variables in registers.
30810 \end_layout
30811
30812 \begin_layout Subsection
30813 Dead-Code Elimination
30814 \begin_inset LatexCommand \index{Dead-code elimination}
30815
30816 \end_inset
30817
30818
30819 \end_layout
30820
30821 \begin_layout Verse
30822
30823 \family typewriter
30824 int global;
30825 \newline
30826
30827 \newline
30828 void f () { 
30829 \newline
30830 \InsetSpace ~
30831 \InsetSpace ~
30832 int i; 
30833 \newline
30834 \InsetSpace ~
30835 \InsetSpace ~
30836 i = 1; \InsetSpace ~
30837 \InsetSpace ~
30838 \InsetSpace ~
30839 \InsetSpace ~
30840 \InsetSpace ~
30841 /* dead store */ 
30842 \newline
30843 \InsetSpace ~
30844 \InsetSpace ~
30845 global = 1;\InsetSpace ~
30846 /* dead
30847  store */ 
30848 \newline
30849 \InsetSpace ~
30850 \InsetSpace ~
30851 global = 2; 
30852 \newline
30853 \InsetSpace ~
30854 \InsetSpace ~
30855 return; 
30856 \newline
30857 \InsetSpace ~
30858 \InsetSpace ~
30859 global = 3;\InsetSpace ~
30860 /* unreachable */ 
30861 \newline
30862 }
30863 \end_layout
30864
30865 \begin_layout Standard
30866 will be changed to
30867 \end_layout
30868
30869 \begin_layout Verse
30870
30871 \family typewriter
30872 int global;
30873 \newline
30874
30875 \newline
30876 void f () {
30877 \newline
30878 \InsetSpace ~
30879 \InsetSpace ~
30880 global = 2; 
30881 \newline
30882 }
30883 \end_layout
30884
30885 \begin_layout Subsection
30886 Copy-Propagation
30887 \begin_inset LatexCommand \index{Copy propagation}
30888
30889 \end_inset
30890
30891
30892 \end_layout
30893
30894 \begin_layout Verse
30895
30896 \family typewriter
30897 int f() { 
30898 \newline
30899 \InsetSpace ~
30900 \InsetSpace ~
30901 int i, j; 
30902 \newline
30903 \InsetSpace ~
30904 \InsetSpace ~
30905 i = 10; 
30906 \newline
30907 \InsetSpace ~
30908 \InsetSpace ~
30909 j = i; 
30910 \newline
30911 \InsetSpace ~
30912 \InsetSpace ~
30913 return j; 
30914 \newline
30915 }
30916 \end_layout
30917
30918 \begin_layout Standard
30919 will be changed to 
30920 \end_layout
30921
30922 \begin_layout Verse
30923
30924 \family typewriter
30925 int f() { 
30926 \newline
30927 \InsetSpace ~
30928 \InsetSpace ~
30929 int i, j; 
30930 \newline
30931 \InsetSpace ~
30932 \InsetSpace ~
30933 i = 10; 
30934 \newline
30935 \InsetSpace ~
30936 \InsetSpace ~
30937 j = 10; 
30938 \newline
30939 \InsetSpace ~
30940 \InsetSpace ~
30941 return 10; 
30942 \newline
30943 }
30944 \end_layout
30945
30946 \begin_layout Standard
30947 Note: the dead stores created by this copy propagation will be eliminated
30948  by dead-code elimination.
30949 \end_layout
30950
30951 \begin_layout Subsection
30952 Loop Optimizations
30953 \begin_inset LatexCommand \index{Loop optimization}
30954
30955 \end_inset
30956
30957
30958 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
30959
30960 \end_inset
30961
30962
30963 \end_layout
30964
30965 \begin_layout Standard
30966 Two types of loop optimizations are done by SDCC 
30967 \emph on
30968 loop invariant
30969 \emph default
30970  lifting and
30971 \emph on
30972  strength reduction
30973 \emph default
30974  of loop induction variables.
30975  In addition to the strength reduction the optimizer marks the induction
30976  variables and the register allocator tries to keep the induction variables
30977  in registers for the duration of the loop.
30978  Because of this preference of the register allocator
30979 \begin_inset LatexCommand \index{Register allocation}
30980
30981 \end_inset
30982
30983 , loop induction optimization causes an increase in register pressure, which
30984  may cause unwanted spilling of other temporary variables into the stack
30985 \begin_inset LatexCommand \index{stack}
30986
30987 \end_inset
30988
30989  / data space.
30990  The compiler will generate a warning message when it is forced to allocate
30991  extra space either on the stack or data space.
30992  If this extra space allocation is undesirable then induction optimization
30993  can be eliminated either for the entire source file (with -
30994 \begin_inset ERT
30995 status collapsed
30996
30997 \begin_layout Standard
30998
30999
31000 \backslash
31001 /
31002 \end_layout
31003
31004 \end_inset
31005
31006 -noinduction option) or for a given function only using #pragma\InsetSpace ~
31007 noinduction
31008 \begin_inset LatexCommand \index{\#pragma noinduction}
31009
31010 \end_inset
31011
31012 .
31013 \newline
31014
31015 \newline
31016 Loop Invariant:
31017 \end_layout
31018
31019 \begin_layout Verse
31020
31021 \family typewriter
31022 for (i = 0 ; i < 100 ; i ++) 
31023 \newline
31024 \InsetSpace ~
31025 \InsetSpace ~
31026 \InsetSpace ~
31027 \InsetSpace ~
31028 f += k + l;
31029 \end_layout
31030
31031 \begin_layout Standard
31032 changed to
31033 \end_layout
31034
31035 \begin_layout Verse
31036
31037 \family typewriter
31038 itemp = k + l; 
31039 \newline
31040 for (i = 0; i < 100; i++) 
31041 \newline
31042 \InsetSpace ~
31043 \InsetSpace ~
31044 \InsetSpace ~
31045 \InsetSpace ~
31046 f += itemp;
31047 \end_layout
31048
31049 \begin_layout Standard
31050 As mentioned previously some loop invariants are not as apparent, all static
31051  address computations are also moved out of the loop.
31052 \newline
31053
31054 \newline
31055 Strength Reduction
31056 \begin_inset LatexCommand \index{Strength reduction}
31057
31058 \end_inset
31059
31060 , this optimization substitutes an expression by a cheaper expression:
31061 \end_layout
31062
31063 \begin_layout Verse
31064
31065 \family typewriter
31066 for (i=0;i < 100; i++)
31067 \newline
31068 \InsetSpace ~
31069 \InsetSpace ~
31070 \InsetSpace ~
31071 \InsetSpace ~
31072 ar[i*5] = i*3;
31073 \end_layout
31074
31075 \begin_layout Standard
31076 changed to
31077 \end_layout
31078
31079 \begin_layout Verse
31080
31081 \family typewriter
31082 itemp1 = 0; 
31083 \newline
31084 itemp2 = 0; 
31085 \newline
31086 for (i=0;i< 100;i++) { 
31087 \newline
31088 \InsetSpace ~
31089 \InsetSpace ~
31090 \InsetSpace ~
31091 \InsetSpace ~
31092 ar[itemp1] = itemp2; 
31093 \newline
31094 \InsetSpace ~
31095 \InsetSpace ~
31096 \InsetSpace ~
31097 \InsetSpace ~
31098 itemp1
31099  += 5; 
31100 \newline
31101 \InsetSpace ~
31102 \InsetSpace ~
31103 \InsetSpace ~
31104 \InsetSpace ~
31105 itemp2 += 3; 
31106 \newline
31107 }
31108 \end_layout
31109
31110 \begin_layout Standard
31111 The more expensive multiplication
31112 \begin_inset LatexCommand \index{Multiplication}
31113
31114 \end_inset
31115
31116  is changed to a less expensive addition.
31117 \end_layout
31118
31119 \begin_layout Subsection
31120 Loop Reversing
31121 \begin_inset LatexCommand \index{Loop reversing}
31122
31123 \end_inset
31124
31125
31126 \end_layout
31127
31128 \begin_layout Standard
31129 This optimization is done to reduce the overhead of checking loop boundaries
31130  for every iteration.
31131  Some simple loops can be reversed and implemented using a 
31132 \begin_inset Quotes eld
31133 \end_inset
31134
31135 decrement and jump if not zero
31136 \begin_inset Quotes erd
31137 \end_inset
31138
31139  instruction.
31140  SDCC checks for the following criterion to determine if a loop is reversible
31141  (note: more sophisticated compilers use data-dependency analysis to make
31142  this determination, SDCC uses a more simple minded analysis).
31143 \end_layout
31144
31145 \begin_layout Itemize
31146 The 'for' loop is of the form 
31147 \newline
31148
31149 \newline
31150
31151 \family typewriter
31152 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
31153  += 1])
31154 \newline
31155 \InsetSpace ~
31156 \InsetSpace ~
31157 \InsetSpace ~
31158 \InsetSpace ~
31159 <for body>
31160 \end_layout
31161
31162 \begin_layout Itemize
31163 The <for body> does not contain 
31164 \begin_inset Quotes eld
31165 \end_inset
31166
31167 continue
31168 \begin_inset Quotes erd
31169 \end_inset
31170
31171  or 'break
31172 \begin_inset Quotes erd
31173 \end_inset
31174
31175 .
31176 \end_layout
31177
31178 \begin_layout Itemize
31179 All goto's are contained within the loop.
31180 \end_layout
31181
31182 \begin_layout Itemize
31183 No function calls within the loop.
31184 \end_layout
31185
31186 \begin_layout Itemize
31187 The loop control variable <sym> is not assigned any value within the loop
31188 \end_layout
31189
31190 \begin_layout Itemize
31191 The loop control variable does NOT participate in any arithmetic operation
31192  within the loop.
31193 \end_layout
31194
31195 \begin_layout Itemize
31196 There are NO switch statements in the loop.
31197 \end_layout
31198
31199 \begin_layout Subsection
31200 Algebraic Simplifications
31201 \end_layout
31202
31203 \begin_layout Standard
31204 SDCC does numerous algebraic simplifications, the following is a small sub-set
31205  of these optimizations.
31206 \end_layout
31207
31208 \begin_layout Verse
31209
31210 \family typewriter
31211 i = j + 0;\InsetSpace ~
31212 \InsetSpace ~
31213 \InsetSpace ~
31214 \InsetSpace ~
31215  /* changed to: */\InsetSpace ~
31216 \InsetSpace ~
31217 \InsetSpace ~
31218 \InsetSpace ~
31219  i = j; 
31220 \newline
31221 i /= 2;\InsetSpace ~
31222 \InsetSpace ~
31223 \InsetSpace ~
31224 \InsetSpace ~
31225 \InsetSpace ~
31226 \InsetSpace ~
31227 \InsetSpace ~
31228  /* changed to: */\InsetSpace ~
31229 \InsetSpace ~
31230 \InsetSpace ~
31231 \InsetSpace ~
31232  i >>= 1; 
31233 \newline
31234 i
31235  = j - j;\InsetSpace ~
31236 \InsetSpace ~
31237 \InsetSpace ~
31238 \InsetSpace ~
31239  /* changed to: */\InsetSpace ~
31240 \InsetSpace ~
31241 \InsetSpace ~
31242 \InsetSpace ~
31243  i = 0; 
31244 \newline
31245 i = j / 1;\InsetSpace ~
31246 \InsetSpace ~
31247 \InsetSpace ~
31248 \InsetSpace ~
31249  /* changed to: */\InsetSpace ~
31250 \InsetSpace ~
31251 \InsetSpace ~
31252 \InsetSpace ~
31253  i = j;
31254 \end_layout
31255
31256 \begin_layout Standard
31257 Note the subexpressions
31258 \begin_inset LatexCommand \index{Subexpression}
31259
31260 \end_inset
31261
31262  given above are generally introduced by macro expansions or as a result
31263  of copy/constant propagation.
31264 \end_layout
31265
31266 \begin_layout Subsection
31267 'switch' Statements
31268 \begin_inset LatexCommand \label{sub:'switch'-Statements}
31269
31270 \end_inset
31271
31272
31273 \begin_inset LatexCommand \index{switch statement}
31274
31275 \end_inset
31276
31277
31278 \end_layout
31279
31280 \begin_layout Standard
31281 SDCC can optimize switch statements to jump tables
31282 \begin_inset LatexCommand \index{jump tables}
31283
31284 \end_inset
31285
31286 .
31287  It makes the decision based on an estimate of the generated code size.
31288  SDCC is quite liberal in the requirements for jump table generation: 
31289 \end_layout
31290
31291 \begin_layout Itemize
31292 The labels need not be in order, and the starting number need not be one
31293  or zero, the case labels are in numerical sequence or not too many case
31294  labels are missing.
31295 \end_layout
31296
31297 \begin_deeper
31298 \begin_layout Verse
31299
31300 \family typewriter
31301 switch(i) {\InsetSpace ~
31302 \InsetSpace ~
31303 \InsetSpace ~
31304 \InsetSpace ~
31305 \InsetSpace ~
31306 \InsetSpace ~
31307 \InsetSpace ~
31308 \InsetSpace ~
31309 \InsetSpace ~
31310 \InsetSpace ~
31311 \InsetSpace ~
31312 \InsetSpace ~
31313 \InsetSpace ~
31314 \InsetSpace ~
31315 \InsetSpace ~
31316 \InsetSpace ~
31317 \InsetSpace ~
31318 \InsetSpace ~
31319 \InsetSpace ~
31320 \InsetSpace ~
31321 \InsetSpace ~
31322 \InsetSpace ~
31323 \InsetSpace ~
31324 \InsetSpace ~
31325 \InsetSpace ~
31326 \InsetSpace ~
31327 switch (i) { 
31328 \newline
31329 \InsetSpace ~
31330 \InsetSpace ~
31331 \InsetSpace ~
31332 case 4: ...\InsetSpace ~
31333 \InsetSpace ~
31334 \InsetSpace ~
31335 \InsetSpace ~
31336 \InsetSpace ~
31337 \InsetSpace ~
31338 \InsetSpace ~
31339 \InsetSpace ~
31340 \InsetSpace ~
31341 \InsetSpace ~
31342 \InsetSpace ~
31343 \InsetSpace ~
31344 \InsetSpace ~
31345 \InsetSpace ~
31346 \InsetSpace ~
31347 \InsetSpace ~
31348 \InsetSpace ~
31349 \InsetSpace ~
31350 \InsetSpace ~
31351 \InsetSpace ~
31352 \InsetSpace ~
31353 \InsetSpace ~
31354 \InsetSpace ~
31355 \InsetSpace ~
31356 \InsetSpace ~
31357 \InsetSpace ~
31358 case 0: ...
31359  
31360 \newline
31361 \InsetSpace ~
31362 \InsetSpace ~
31363 \InsetSpace ~
31364 case 5: ...\InsetSpace ~
31365 \InsetSpace ~
31366 \InsetSpace ~
31367 \InsetSpace ~
31368 \InsetSpace ~
31369 \InsetSpace ~
31370 \InsetSpace ~
31371 \InsetSpace ~
31372 \InsetSpace ~
31373 \InsetSpace ~
31374 \InsetSpace ~
31375 \InsetSpace ~
31376 \InsetSpace ~
31377 \InsetSpace ~
31378 \InsetSpace ~
31379 \InsetSpace ~
31380 \InsetSpace ~
31381 \InsetSpace ~
31382 \InsetSpace ~
31383 \InsetSpace ~
31384 \InsetSpace ~
31385 \InsetSpace ~
31386 \InsetSpace ~
31387 \InsetSpace ~
31388 \InsetSpace ~
31389 \InsetSpace ~
31390 case 1: ...
31391  
31392 \newline
31393 \InsetSpace ~
31394 \InsetSpace ~
31395 \InsetSpace ~
31396 case 3: ...\InsetSpace ~
31397 \InsetSpace ~
31398 \InsetSpace ~
31399 \InsetSpace ~
31400 \InsetSpace ~
31401 \InsetSpace ~
31402 \InsetSpace ~
31403 \InsetSpace ~
31404 \InsetSpace ~
31405 \InsetSpace ~
31406 \InsetSpace ~
31407 \InsetSpace ~
31408 \InsetSpace ~
31409 \InsetSpace ~
31410 \InsetSpace ~
31411 \InsetSpace ~
31412 \InsetSpace ~
31413 \InsetSpace ~
31414 \InsetSpace ~
31415 \InsetSpace ~
31416 \InsetSpace ~
31417 \InsetSpace ~
31418 \InsetSpace ~
31419 \InsetSpace ~
31420 \InsetSpace ~
31421 \InsetSpace ~
31422
31423 \newline
31424 \InsetSpace ~
31425 \InsetSpace ~
31426 \InsetSpace ~
31427 case 6: ...\InsetSpace ~
31428 \InsetSpace ~
31429 \InsetSpace ~
31430 \InsetSpace ~
31431 \InsetSpace ~
31432 \InsetSpace ~
31433 \InsetSpace ~
31434 \InsetSpace ~
31435 \InsetSpace ~
31436 \InsetSpace ~
31437 \InsetSpace ~
31438 \InsetSpace ~
31439 \InsetSpace ~
31440 \InsetSpace ~
31441 \InsetSpace ~
31442 \InsetSpace ~
31443 \InsetSpace ~
31444 \InsetSpace ~
31445 \InsetSpace ~
31446 \InsetSpace ~
31447 \InsetSpace ~
31448 \InsetSpace ~
31449 \InsetSpace ~
31450 \InsetSpace ~
31451 \InsetSpace ~
31452 \InsetSpace ~
31453 case 3: ...
31454  
31455 \newline
31456 \InsetSpace ~
31457 \InsetSpace ~
31458 \InsetSpace ~
31459 case 7: ...\InsetSpace ~
31460 \InsetSpace ~
31461 \InsetSpace ~
31462 \InsetSpace ~
31463 \InsetSpace ~
31464 \InsetSpace ~
31465 \InsetSpace ~
31466 \InsetSpace ~
31467 \InsetSpace ~
31468 \InsetSpace ~
31469 \InsetSpace ~
31470 \InsetSpace ~
31471 \InsetSpace ~
31472 \InsetSpace ~
31473 \InsetSpace ~
31474 \InsetSpace ~
31475 \InsetSpace ~
31476 \InsetSpace ~
31477 \InsetSpace ~
31478 \InsetSpace ~
31479 \InsetSpace ~
31480 \InsetSpace ~
31481 \InsetSpace ~
31482 \InsetSpace ~
31483 \InsetSpace ~
31484 \InsetSpace ~
31485 case 4: ...
31486  
31487 \newline
31488 \InsetSpace ~
31489 \InsetSpace ~
31490 \InsetSpace ~
31491 case 8: ...\InsetSpace ~
31492 \InsetSpace ~
31493 \InsetSpace ~
31494 \InsetSpace ~
31495 \InsetSpace ~
31496 \InsetSpace ~
31497 \InsetSpace ~
31498 \InsetSpace ~
31499 \InsetSpace ~
31500 \InsetSpace ~
31501 \InsetSpace ~
31502 \InsetSpace ~
31503 \InsetSpace ~
31504 \InsetSpace ~
31505 \InsetSpace ~
31506 \InsetSpace ~
31507 \InsetSpace ~
31508 \InsetSpace ~
31509 \InsetSpace ~
31510 \InsetSpace ~
31511 \InsetSpace ~
31512 \InsetSpace ~
31513 \InsetSpace ~
31514 \InsetSpace ~
31515 \InsetSpace ~
31516 \InsetSpace ~
31517 case 5: ...
31518  
31519 \newline
31520 \InsetSpace ~
31521 \InsetSpace ~
31522 \InsetSpace ~
31523 case 9: ...\InsetSpace ~
31524 \InsetSpace ~
31525 \InsetSpace ~
31526 \InsetSpace ~
31527 \InsetSpace ~
31528 \InsetSpace ~
31529 \InsetSpace ~
31530 \InsetSpace ~
31531 \InsetSpace ~
31532 \InsetSpace ~
31533 \InsetSpace ~
31534 \InsetSpace ~
31535 \InsetSpace ~
31536 \InsetSpace ~
31537 \InsetSpace ~
31538 \InsetSpace ~
31539 \InsetSpace ~
31540 \InsetSpace ~
31541 \InsetSpace ~
31542 \InsetSpace ~
31543 \InsetSpace ~
31544 \InsetSpace ~
31545 \InsetSpace ~
31546 \InsetSpace ~
31547 \InsetSpace ~
31548 \InsetSpace ~
31549 case 6: ...
31550  
31551 \newline
31552 \InsetSpace ~
31553 \InsetSpace ~
31554 \InsetSpace ~
31555 case 10: ...\InsetSpace ~
31556 \InsetSpace ~
31557 \InsetSpace ~
31558 \InsetSpace ~
31559 \InsetSpace ~
31560 \InsetSpace ~
31561 \InsetSpace ~
31562 \InsetSpace ~
31563 \InsetSpace ~
31564 \InsetSpace ~
31565 \InsetSpace ~
31566 \InsetSpace ~
31567 \InsetSpace ~
31568 \InsetSpace ~
31569 \InsetSpace ~
31570 \InsetSpace ~
31571 \InsetSpace ~
31572 \InsetSpace ~
31573 \InsetSpace ~
31574 \InsetSpace ~
31575 \InsetSpace ~
31576 \InsetSpace ~
31577 \InsetSpace ~
31578 \InsetSpace ~
31579 \InsetSpace ~
31580 case 7: ...
31581  
31582 \newline
31583 \InsetSpace ~
31584 \InsetSpace ~
31585 \InsetSpace ~
31586 case 11: ...\InsetSpace ~
31587 \InsetSpace ~
31588 \InsetSpace ~
31589 \InsetSpace ~
31590 \InsetSpace ~
31591 \InsetSpace ~
31592 \InsetSpace ~
31593 \InsetSpace ~
31594 \InsetSpace ~
31595 \InsetSpace ~
31596 \InsetSpace ~
31597 \InsetSpace ~
31598 \InsetSpace ~
31599 \InsetSpace ~
31600 \InsetSpace ~
31601 \InsetSpace ~
31602 \InsetSpace ~
31603 \InsetSpace ~
31604 \InsetSpace ~
31605 \InsetSpace ~
31606 \InsetSpace ~
31607 \InsetSpace ~
31608 \InsetSpace ~
31609 \InsetSpace ~
31610 \InsetSpace ~
31611 case 8: ...
31612  
31613 \newline
31614 }\InsetSpace ~
31615 \InsetSpace ~
31616 \InsetSpace ~
31617 \InsetSpace ~
31618 \InsetSpace ~
31619 \InsetSpace ~
31620 \InsetSpace ~
31621 \InsetSpace ~
31622 \InsetSpace ~
31623 \InsetSpace ~
31624 \InsetSpace ~
31625 \InsetSpace ~
31626 \InsetSpace ~
31627 \InsetSpace ~
31628 \InsetSpace ~
31629 \InsetSpace ~
31630 \InsetSpace ~
31631 \InsetSpace ~
31632 \InsetSpace ~
31633 \InsetSpace ~
31634 \InsetSpace ~
31635 \InsetSpace ~
31636 \InsetSpace ~
31637 \InsetSpace ~
31638 \InsetSpace ~
31639 \InsetSpace ~
31640 \InsetSpace ~
31641 \InsetSpace ~
31642 \InsetSpace ~
31643 \InsetSpace ~
31644 \InsetSpace ~
31645 \InsetSpace ~
31646 \InsetSpace ~
31647 \InsetSpace ~
31648 \InsetSpace ~
31649 \InsetSpace ~
31650 }
31651 \end_layout
31652
31653 \begin_layout Standard
31654 Both the above switch statements will be implemented using a jump-table.
31655  The example to the right side is slightly more efficient as the check for
31656  the lower boundary of the jump-table is not needed.
31657 \end_layout
31658
31659 \end_deeper
31660 \begin_layout Itemize
31661 The number of case labels is not larger than supported by the target architectur
31662 e.
31663 \end_layout
31664
31665 \begin_layout Itemize
31666 If the case labels are not in numerical sequence ('gaps' between cases)
31667  SDCC checks whether a jump table with additionally inserted dummy cases
31668  is still attractive.
31669  
31670 \end_layout
31671
31672 \begin_layout Itemize
31673 If the starting number is not zero and a check for the lower boundary of
31674  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
31675  ...
31676  .
31677 \end_layout
31678
31679 \begin_layout Standard
31680 Switch statements which have large gaps in the numeric sequence or those
31681  that have too many case labels can be split into more than one switch statement
31682  for efficient code generation, e.g.:
31683 \end_layout
31684
31685 \begin_layout Verse
31686
31687 \family typewriter
31688 switch (i) { 
31689 \newline
31690 \InsetSpace ~
31691 \InsetSpace ~
31692 case 1: ...
31693  
31694 \newline
31695 \InsetSpace ~
31696 \InsetSpace ~
31697 case 2: ...
31698  
31699 \newline
31700 \InsetSpace ~
31701 \InsetSpace ~
31702 case 3: ...
31703  
31704 \newline
31705 \InsetSpace ~
31706 \InsetSpace ~
31707 case 4: ...
31708  
31709 \newline
31710 \InsetSpace ~
31711 \InsetSpace ~
31712 case 5: ...
31713  
31714 \newline
31715 \InsetSpace ~
31716 \InsetSpace ~
31717 case 6: ...
31718  
31719 \newline
31720 \InsetSpace ~
31721 \InsetSpace ~
31722 case 7: ...
31723  
31724 \newline
31725 \InsetSpace ~
31726 \InsetSpace ~
31727 case 101: ...
31728  
31729 \newline
31730 \InsetSpace ~
31731 \InsetSpace ~
31732 case 102: ...
31733  
31734 \newline
31735 \InsetSpace ~
31736 \InsetSpace ~
31737 case 103: ...
31738  
31739 \newline
31740 \InsetSpace ~
31741 \InsetSpace ~
31742 case 104: ...
31743  
31744 \newline
31745 \InsetSpace ~
31746 \InsetSpace ~
31747 case 105: ...
31748  
31749 \newline
31750 \InsetSpace ~
31751 \InsetSpace ~
31752 case 106: ...
31753  
31754 \newline
31755 \InsetSpace ~
31756 \InsetSpace ~
31757 case 107: ...
31758  
31759 \newline
31760 }
31761 \end_layout
31762
31763 \begin_layout Standard
31764 If the above switch statement is broken down into two switch statements
31765 \end_layout
31766
31767 \begin_layout Verse
31768
31769 \family typewriter
31770 switch (i) { 
31771 \newline
31772 \InsetSpace ~
31773 \InsetSpace ~
31774 case 1: ...
31775  
31776 \newline
31777 \InsetSpace ~
31778 \InsetSpace ~
31779 case 2: ...
31780  
31781 \newline
31782 \InsetSpace ~
31783 \InsetSpace ~
31784 case 3: ...
31785  
31786 \newline
31787 \InsetSpace ~
31788 \InsetSpace ~
31789 case 4: ...
31790  
31791 \newline
31792 \InsetSpace ~
31793 \InsetSpace ~
31794 case 5: ...
31795  
31796 \newline
31797 \InsetSpace ~
31798 \InsetSpace ~
31799 case 6: ...
31800  
31801 \newline
31802 \InsetSpace ~
31803 \InsetSpace ~
31804 case 7: ...
31805  
31806 \newline
31807 }
31808 \end_layout
31809
31810 \begin_layout Standard
31811 and
31812 \end_layout
31813
31814 \begin_layout Verse
31815
31816 \family typewriter
31817 switch (i) { 
31818 \newline
31819 \InsetSpace ~
31820 \InsetSpace ~
31821 case 101: ...
31822  
31823 \newline
31824 \InsetSpace ~
31825 \InsetSpace ~
31826 case 102: ...
31827  
31828 \newline
31829 \InsetSpace ~
31830 \InsetSpace ~
31831 case 103: ...
31832  
31833 \newline
31834 \InsetSpace ~
31835 \InsetSpace ~
31836 case 104: ...
31837  
31838 \newline
31839 \InsetSpace ~
31840 \InsetSpace ~
31841 case 105: ...
31842  
31843 \newline
31844 \InsetSpace ~
31845 \InsetSpace ~
31846 case 106: ...
31847  
31848 \newline
31849 \InsetSpace ~
31850 \InsetSpace ~
31851 case 107: ...
31852  
31853 \newline
31854 }
31855 \end_layout
31856
31857 \begin_layout Standard
31858 then both the switch statements will be implemented using jump-tables whereas
31859  the unmodified switch statement will not be.
31860 \end_layout
31861
31862 \begin_layout Standard
31863 \begin_inset Note Comment
31864 status collapsed
31865
31866 \begin_layout Standard
31867 There might be reasons which SDCC cannot know about to either favour or
31868  not favour jump tables.
31869  If the target system has to be as quick for the last switch case as for
31870  the first (pro jump table), or if the switch argument is known to be zero
31871  in the majority of the cases (contra jump table).
31872 \end_layout
31873
31874 \end_inset
31875
31876
31877 \end_layout
31878
31879 \begin_layout Standard
31880 The pragma nojtbound
31881 \begin_inset LatexCommand \index{\#pragma nojtbound}
31882
31883 \end_inset
31884
31885  can be used to turn off checking the 
31886 \emph on
31887 j
31888 \emph default
31889 ump 
31890 \emph on
31891 t
31892 \emph default
31893 able 
31894 \emph on
31895 bound
31896 \emph default
31897 aries.
31898  It has no effect if a default label is supplied.
31899  Use of this pragma is dangerous: if the switch
31900 \begin_inset LatexCommand \index{switch statement}
31901
31902 \end_inset
31903
31904  argument is not matched by a case statement the processor will happily
31905  jump into Nirvana.
31906 \end_layout
31907
31908 \begin_layout Subsection
31909 Bit-shifting Operations
31910 \begin_inset LatexCommand \index{Bit shifting}
31911
31912 \end_inset
31913
31914 .
31915 \end_layout
31916
31917 \begin_layout Standard
31918 Bit shifting is one of the most frequently used operation in embedded programmin
31919 g.
31920  SDCC tries to implement bit-shift operations in the most efficient way
31921  possible, e.g.:
31922 \end_layout
31923
31924 \begin_layout Verse
31925
31926 \family typewriter
31927 unsigned char i;
31928 \newline
31929 ...
31930  
31931 \newline
31932 i >>= 4; 
31933 \newline
31934 ...
31935 \end_layout
31936
31937 \begin_layout Standard
31938 generates the following code:
31939 \end_layout
31940
31941 \begin_layout Verse
31942
31943 \family typewriter
31944 mov\InsetSpace ~
31945  a,_i 
31946 \newline
31947 swap a 
31948 \newline
31949 anl\InsetSpace ~
31950  a,#0x0f 
31951 \newline
31952 mov\InsetSpace ~
31953  _i,a
31954 \end_layout
31955
31956 \begin_layout Standard
31957 In general SDCC will never setup a loop if the shift count is known.
31958  Another example:
31959 \end_layout
31960
31961 \begin_layout Verse
31962
31963 \family typewriter
31964 unsigned int i; 
31965 \newline
31966 ...
31967  
31968 \newline
31969 i >>= 9; 
31970 \newline
31971 ...
31972 \end_layout
31973
31974 \begin_layout Standard
31975 will generate:
31976 \end_layout
31977
31978 \begin_layout Verse
31979
31980 \family typewriter
31981 mov\InsetSpace ~
31982 \InsetSpace ~
31983 a,(_i + 1) 
31984 \newline
31985 mov\InsetSpace ~
31986 \InsetSpace ~
31987 (_i + 1),#0x00 
31988 \newline
31989 clr\InsetSpace ~
31990 \InsetSpace ~
31991
31992 \newline
31993 rrc\InsetSpace ~
31994 \InsetSpace ~
31995
31996 \newline
31997 mov\InsetSpace ~
31998 \InsetSpace ~
31999 _i,a
32000 \end_layout
32001
32002 \begin_layout Subsection
32003 Bit-rotation
32004 \begin_inset LatexCommand \index{Bit rotation}
32005
32006 \end_inset
32007
32008
32009 \end_layout
32010
32011 \begin_layout Standard
32012 A special case of the bit-shift operation is bit rotation
32013 \begin_inset LatexCommand \index{rotating bits}
32014
32015 \end_inset
32016
32017 , SDCC recognizes the following expression to be a left bit-rotation:
32018 \end_layout
32019
32020 \begin_layout Verse
32021
32022 \family typewriter
32023 \series bold
32024 unsigned
32025 \series default
32026 \InsetSpace ~
32027 \InsetSpace ~
32028 char i;\InsetSpace ~
32029 \InsetSpace ~
32030 \InsetSpace ~
32031 \InsetSpace ~
32032 \InsetSpace ~
32033 \InsetSpace ~
32034 \InsetSpace ~
32035 \InsetSpace ~
32036 \InsetSpace ~
32037 \InsetSpace ~
32038 \InsetSpace ~
32039 /* unsigned is needed for rotation */ 
32040 \newline
32041 ...
32042  
32043 \newline
32044 i = ((i << 1) | (i >> 7)); 
32045 \family default
32046
32047 \newline
32048
32049 \family typewriter
32050 ...
32051 \end_layout
32052
32053 \begin_layout Standard
32054 will generate the following code:
32055 \end_layout
32056
32057 \begin_layout Verse
32058
32059 \family typewriter
32060 mov\InsetSpace ~
32061 \InsetSpace ~
32062 a,_i 
32063 \newline
32064 rl\InsetSpace ~
32065 \InsetSpace ~
32066 \InsetSpace ~
32067
32068 \newline
32069 mov\InsetSpace ~
32070 \InsetSpace ~
32071 _i,a
32072 \end_layout
32073
32074 \begin_layout Standard
32075 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
32076 ns of this case will also be recognized as bit-rotation, i.e.: 
32077 \end_layout
32078
32079 \begin_layout Verse
32080
32081 \family typewriter
32082 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
32083 \end_layout
32084
32085 \begin_layout Subsection
32086 Nibble and Byte Swapping
32087 \end_layout
32088
32089 \begin_layout Standard
32090 Other special cases of the bit-shift operations are nibble or byte swapping
32091 \begin_inset LatexCommand \index{swapping nibbles/bytes}
32092
32093 \end_inset
32094
32095 , SDCC recognizes the following expressions:
32096 \end_layout
32097
32098 \begin_layout Verse
32099
32100 \family typewriter
32101 \series bold
32102 unsigned
32103 \series default
32104 \InsetSpace ~
32105 \InsetSpace ~
32106 char i; 
32107 \newline
32108
32109 \series bold
32110 unsigned
32111 \series default
32112 \InsetSpace ~
32113 \InsetSpace ~
32114 int j; 
32115 \newline
32116 ...
32117  
32118 \newline
32119 i = ((i << 4) | (i >> 4)); 
32120 \family default
32121
32122 \newline
32123
32124 \family typewriter
32125 j = ((j << 8) | (j >> 8)); 
32126 \end_layout
32127
32128 \begin_layout Standard
32129 and generates a swap instruction for the nibble swapping
32130 \begin_inset LatexCommand \index{Nibble swapping}
32131
32132 \end_inset
32133
32134  or move instructions for the byte swapping
32135 \begin_inset LatexCommand \index{Byte swapping}
32136
32137 \end_inset
32138
32139 .
32140  The 
32141 \begin_inset Quotes sld
32142 \end_inset
32143
32144 j
32145 \begin_inset Quotes srd
32146 \end_inset
32147
32148  example can be used to convert from little to big-endian or vice versa.
32149  If you want to change the endianness of a 
32150 \emph on
32151 signed
32152 \emph default
32153  integer you have to cast to 
32154 \family typewriter
32155 (unsigned int)
32156 \family default
32157  first.
32158 \end_layout
32159
32160 \begin_layout Standard
32161 Note that SDCC stores numbers in little-endian
32162 \begin_inset Foot
32163 status open
32164
32165 \begin_layout Standard
32166 Usually 8-bit processors don't care much about endianness.
32167  This is not the case for the standard 8051 which only has an instruction
32168  to increment its 
32169 \emph on
32170 dptr
32171 \emph default
32172
32173 \begin_inset LatexCommand \index{DPTR}
32174
32175 \end_inset
32176
32177 -datapointer
32178 \emph on
32179  
32180 \emph default
32181 so little-endian is the more efficient byte order.
32182 \end_layout
32183
32184 \end_inset
32185
32186
32187 \begin_inset LatexCommand \index{little-endian}
32188
32189 \end_inset
32190
32191
32192 \begin_inset LatexCommand \index{Endianness}
32193
32194 \end_inset
32195
32196  format (i.e.
32197  lowest order first).
32198 \end_layout
32199
32200 \begin_layout Subsection
32201 Highest Order Bit
32202 \begin_inset LatexCommand \index{Highest Order Bit}
32203
32204 \end_inset
32205
32206  / Any Order Bit
32207 \begin_inset LatexCommand \index{Any Order Bit}
32208
32209 \end_inset
32210
32211
32212 \end_layout
32213
32214 \begin_layout Standard
32215 It is frequently required to obtain the highest order bit of an integral
32216  type (long, int, short or char types).
32217  Also obtaining any other order bit is not uncommon.
32218  SDCC recognizes the following expressions to yield the highest order bit
32219  and generates optimized code for it, e.g.:
32220 \end_layout
32221
32222 \begin_layout Verse
32223
32224 \family typewriter
32225 unsigned int gint; 
32226 \newline
32227
32228 \newline
32229 foo () { 
32230 \newline
32231 \InsetSpace ~
32232 \InsetSpace ~
32233 unsigned char hob1, aob1; 
32234 \newline
32235 \InsetSpace ~
32236 \InsetSpace ~
32237 bit hob2, hob3, aob2,
32238  aob3; 
32239 \newline
32240 \InsetSpace ~
32241 \InsetSpace ~
32242 ...
32243  
32244 \newline
32245 \InsetSpace ~
32246 \InsetSpace ~
32247 hob1 = (gint >> 15) & 1; 
32248 \newline
32249 \InsetSpace ~
32250 \InsetSpace ~
32251 hob2 = (gint >> 15) & 1; 
32252 \newline
32253 \InsetSpace ~
32254 \InsetSpace ~
32255 hob3 = gint & 0x8000;
32256  
32257 \newline
32258 \InsetSpace ~
32259 \InsetSpace ~
32260 aob1 = (gint >> 9) & 1; 
32261 \newline
32262 \InsetSpace ~
32263 \InsetSpace ~
32264 aob2 = (gint >> 8) & 1; 
32265 \newline
32266 \InsetSpace ~
32267 \InsetSpace ~
32268 aob3 = gint & 0x0800; 
32269 \newline
32270 \InsetSpace ~
32271 \InsetSpace ~
32272 ..
32273  
32274 \newline
32275 }
32276 \end_layout
32277
32278 \begin_layout Standard
32279 will generate the following code:
32280 \end_layout
32281
32282 \begin_layout Verse
32283
32284 \family typewriter
32285 \InsetSpace ~
32286 \InsetSpace ~
32287 \InsetSpace ~
32288 \InsetSpace ~
32289 \InsetSpace ~
32290 \InsetSpace ~
32291 \InsetSpace ~
32292 \InsetSpace ~
32293 \InsetSpace ~
32294 \InsetSpace ~
32295 \InsetSpace ~
32296 \InsetSpace ~
32297 \InsetSpace ~
32298 \InsetSpace ~
32299 \InsetSpace ~
32300 \InsetSpace ~
32301 \InsetSpace ~
32302 \InsetSpace ~
32303 \InsetSpace ~
32304 \InsetSpace ~
32305 \InsetSpace ~
32306 \InsetSpace ~
32307 \InsetSpace ~
32308 \InsetSpace ~
32309 \InsetSpace ~
32310  61 ;\InsetSpace ~
32311  hob.c 7 
32312 \newline
32313 000A E5*01\InsetSpace ~
32314 \InsetSpace ~
32315 \InsetSpace ~
32316 \InsetSpace ~
32317 \InsetSpace ~
32318 \InsetSpace ~
32319 \InsetSpace ~
32320 \InsetSpace ~
32321 \InsetSpace ~
32322 \InsetSpace ~
32323 \InsetSpace ~
32324 \InsetSpace ~
32325 \InsetSpace ~
32326 \InsetSpace ~
32327 \InsetSpace ~
32328  62\InsetSpace ~
32329 \InsetSpace ~
32330 \InsetSpace ~
32331 \InsetSpace ~
32332 \InsetSpace ~
32333 \InsetSpace ~
32334 \InsetSpace ~
32335 \InsetSpace ~
32336  mov\InsetSpace ~
32337 \InsetSpace ~
32338  a,(_gint + 1) 
32339 \newline
32340 000C 23\InsetSpace ~
32341 \InsetSpace ~
32342 \InsetSpace ~
32343 \InsetSpace ~
32344 \InsetSpace ~
32345 \InsetSpace ~
32346 \InsetSpace ~
32347 \InsetSpace ~
32348 \InsetSpace ~
32349 \InsetSpace ~
32350 \InsetSpace ~
32351 \InsetSpace ~
32352 \InsetSpace ~
32353 \InsetSpace ~
32354 \InsetSpace ~
32355 \InsetSpace ~
32356 \InsetSpace ~
32357 \InsetSpace ~
32358  63\InsetSpace ~
32359 \InsetSpace ~
32360 \InsetSpace ~
32361 \InsetSpace ~
32362 \InsetSpace ~
32363 \InsetSpace ~
32364 \InsetSpace ~
32365 \InsetSpace ~
32366  rl\InsetSpace ~
32367 \InsetSpace ~
32368 \InsetSpace ~
32369  a 
32370 \newline
32371 000D 54 01\InsetSpace ~
32372 \InsetSpace ~
32373 \InsetSpace ~
32374 \InsetSpace ~
32375 \InsetSpace ~
32376 \InsetSpace ~
32377 \InsetSpace ~
32378 \InsetSpace ~
32379 \InsetSpace ~
32380 \InsetSpace ~
32381 \InsetSpace ~
32382 \InsetSpace ~
32383 \InsetSpace ~
32384 \InsetSpace ~
32385 \InsetSpace ~
32386
32387  64\InsetSpace ~
32388 \InsetSpace ~
32389 \InsetSpace ~
32390 \InsetSpace ~
32391 \InsetSpace ~
32392 \InsetSpace ~
32393 \InsetSpace ~
32394 \InsetSpace ~
32395  anl\InsetSpace ~
32396 \InsetSpace ~
32397  a,#0x01 
32398 \newline
32399 000F F5*02\InsetSpace ~
32400 \InsetSpace ~
32401 \InsetSpace ~
32402 \InsetSpace ~
32403 \InsetSpace ~
32404 \InsetSpace ~
32405 \InsetSpace ~
32406 \InsetSpace ~
32407 \InsetSpace ~
32408 \InsetSpace ~
32409 \InsetSpace ~
32410 \InsetSpace ~
32411 \InsetSpace ~
32412 \InsetSpace ~
32413 \InsetSpace ~
32414  65\InsetSpace ~
32415 \InsetSpace ~
32416 \InsetSpace ~
32417 \InsetSpace ~
32418 \InsetSpace ~
32419 \InsetSpace ~
32420 \InsetSpace ~
32421 \InsetSpace ~
32422  mov\InsetSpace ~
32423 \InsetSpace ~
32424  _foo_hob1_1_1,a 
32425 \newline
32426 \InsetSpace ~
32427 \InsetSpace ~
32428 \InsetSpace ~
32429 \InsetSpace ~
32430 \InsetSpace ~
32431 \InsetSpace ~
32432 \InsetSpace ~
32433 \InsetSpace ~
32434 \InsetSpace ~
32435 \InsetSpace ~
32436 \InsetSpace ~
32437 \InsetSpace ~
32438 \InsetSpace ~
32439 \InsetSpace ~
32440 \InsetSpace ~
32441 \InsetSpace ~
32442 \InsetSpace ~
32443 \InsetSpace ~
32444 \InsetSpace ~
32445 \InsetSpace ~
32446 \InsetSpace ~
32447 \InsetSpace ~
32448 \InsetSpace ~
32449 \InsetSpace ~
32450 \InsetSpace ~
32451  66 ;\InsetSpace ~
32452  hob.c 8 
32453 \newline
32454 0011 E5*01\InsetSpace ~
32455 \InsetSpace ~
32456 \InsetSpace ~
32457 \InsetSpace ~
32458 \InsetSpace ~
32459 \InsetSpace ~
32460 \InsetSpace ~
32461 \InsetSpace ~
32462 \InsetSpace ~
32463 \InsetSpace ~
32464 \InsetSpace ~
32465 \InsetSpace ~
32466 \InsetSpace ~
32467 \InsetSpace ~
32468 \InsetSpace ~
32469
32470  67\InsetSpace ~
32471 \InsetSpace ~
32472 \InsetSpace ~
32473 \InsetSpace ~
32474 \InsetSpace ~
32475 \InsetSpace ~
32476 \InsetSpace ~
32477 \InsetSpace ~
32478  mov\InsetSpace ~
32479 \InsetSpace ~
32480  a,(_gint + 1) 
32481 \newline
32482 0013 33\InsetSpace ~
32483 \InsetSpace ~
32484 \InsetSpace ~
32485 \InsetSpace ~
32486 \InsetSpace ~
32487 \InsetSpace ~
32488 \InsetSpace ~
32489 \InsetSpace ~
32490 \InsetSpace ~
32491 \InsetSpace ~
32492 \InsetSpace ~
32493 \InsetSpace ~
32494 \InsetSpace ~
32495 \InsetSpace ~
32496 \InsetSpace ~
32497 \InsetSpace ~
32498 \InsetSpace ~
32499 \InsetSpace ~
32500  68\InsetSpace ~
32501 \InsetSpace ~
32502 \InsetSpace ~
32503 \InsetSpace ~
32504 \InsetSpace ~
32505 \InsetSpace ~
32506 \InsetSpace ~
32507 \InsetSpace ~
32508  rlc\InsetSpace ~
32509 \InsetSpace ~
32510  a 
32511 \newline
32512 0014 92*00\InsetSpace ~
32513 \InsetSpace ~
32514 \InsetSpace ~
32515 \InsetSpace ~
32516 \InsetSpace ~
32517 \InsetSpace ~
32518 \InsetSpace ~
32519 \InsetSpace ~
32520 \InsetSpace ~
32521 \InsetSpace ~
32522 \InsetSpace ~
32523 \InsetSpace ~
32524 \InsetSpace ~
32525 \InsetSpace ~
32526 \InsetSpace ~
32527  69\InsetSpace ~
32528 \InsetSpace ~
32529 \InsetSpace ~
32530 \InsetSpace ~
32531 \InsetSpace ~
32532 \InsetSpace ~
32533 \InsetSpace ~
32534 \InsetSpace ~
32535  mov\InsetSpace ~
32536 \InsetSpace ~
32537  _foo_hob2_1_1,c
32538  
32539 \newline
32540 \InsetSpace ~
32541 \InsetSpace ~
32542 \InsetSpace ~
32543 \InsetSpace ~
32544 \InsetSpace ~
32545 \InsetSpace ~
32546 \InsetSpace ~
32547 \InsetSpace ~
32548 \InsetSpace ~
32549 \InsetSpace ~
32550 \InsetSpace ~
32551 \InsetSpace ~
32552 \InsetSpace ~
32553 \InsetSpace ~
32554 \InsetSpace ~
32555 \InsetSpace ~
32556 \InsetSpace ~
32557 \InsetSpace ~
32558 \InsetSpace ~
32559 \InsetSpace ~
32560 \InsetSpace ~
32561 \InsetSpace ~
32562 \InsetSpace ~
32563 \InsetSpace ~
32564 \InsetSpace ~
32565  66 ;\InsetSpace ~
32566  hob.c 9 
32567 \newline
32568 0016 E5*01\InsetSpace ~
32569 \InsetSpace ~
32570 \InsetSpace ~
32571 \InsetSpace ~
32572 \InsetSpace ~
32573 \InsetSpace ~
32574 \InsetSpace ~
32575 \InsetSpace ~
32576 \InsetSpace ~
32577 \InsetSpace ~
32578 \InsetSpace ~
32579 \InsetSpace ~
32580 \InsetSpace ~
32581 \InsetSpace ~
32582 \InsetSpace ~
32583  67\InsetSpace ~
32584 \InsetSpace ~
32585 \InsetSpace ~
32586 \InsetSpace ~
32587 \InsetSpace ~
32588 \InsetSpace ~
32589 \InsetSpace ~
32590 \InsetSpace ~
32591  mov\InsetSpace ~
32592 \InsetSpace ~
32593  a,(_gint + 1) 
32594 \newline
32595 0018 33\InsetSpace ~
32596 \InsetSpace ~
32597 \InsetSpace ~
32598 \InsetSpace ~
32599 \InsetSpace ~
32600 \InsetSpace ~
32601 \InsetSpace ~
32602 \InsetSpace ~
32603 \InsetSpace ~
32604 \InsetSpace ~
32605 \InsetSpace ~
32606 \InsetSpace ~
32607 \InsetSpace ~
32608 \InsetSpace ~
32609 \InsetSpace ~
32610 \InsetSpace ~
32611 \InsetSpace ~
32612 \InsetSpace ~
32613  68\InsetSpace ~
32614 \InsetSpace ~
32615 \InsetSpace ~
32616 \InsetSpace ~
32617 \InsetSpace ~
32618 \InsetSpace ~
32619 \InsetSpace ~
32620 \InsetSpace ~
32621  rlc\InsetSpace ~
32622 \InsetSpace ~
32623  a 
32624 \newline
32625 0019 92*01\InsetSpace ~
32626 \InsetSpace ~
32627 \InsetSpace ~
32628 \InsetSpace ~
32629 \InsetSpace ~
32630 \InsetSpace ~
32631 \InsetSpace ~
32632 \InsetSpace ~
32633 \InsetSpace ~
32634 \InsetSpace ~
32635 \InsetSpace ~
32636 \InsetSpace ~
32637 \InsetSpace ~
32638 \InsetSpace ~
32639 \InsetSpace ~
32640
32641  69\InsetSpace ~
32642 \InsetSpace ~
32643 \InsetSpace ~
32644 \InsetSpace ~
32645 \InsetSpace ~
32646 \InsetSpace ~
32647 \InsetSpace ~
32648 \InsetSpace ~
32649  mov\InsetSpace ~
32650 \InsetSpace ~
32651  _foo_hob3_1_1,c 
32652 \newline
32653 \InsetSpace ~
32654 \InsetSpace ~
32655 \InsetSpace ~
32656 \InsetSpace ~
32657 \InsetSpace ~
32658 \InsetSpace ~
32659 \InsetSpace ~
32660 \InsetSpace ~
32661 \InsetSpace ~
32662 \InsetSpace ~
32663 \InsetSpace ~
32664 \InsetSpace ~
32665 \InsetSpace ~
32666 \InsetSpace ~
32667 \InsetSpace ~
32668 \InsetSpace ~
32669 \InsetSpace ~
32670 \InsetSpace ~
32671 \InsetSpace ~
32672 \InsetSpace ~
32673 \InsetSpace ~
32674 \InsetSpace ~
32675 \InsetSpace ~
32676 \InsetSpace ~
32677 \InsetSpace ~
32678  70 ;\InsetSpace ~
32679  hob.c 10 
32680 \newline
32681 001B E5*01\InsetSpace ~
32682 \InsetSpace ~
32683 \InsetSpace ~
32684 \InsetSpace ~
32685 \InsetSpace ~
32686 \InsetSpace ~
32687 \InsetSpace ~
32688 \InsetSpace ~
32689 \InsetSpace ~
32690 \InsetSpace ~
32691 \InsetSpace ~
32692 \InsetSpace ~
32693 \InsetSpace ~
32694 \InsetSpace ~
32695 \InsetSpace ~
32696  71\InsetSpace ~
32697 \InsetSpace ~
32698 \InsetSpace ~
32699 \InsetSpace ~
32700 \InsetSpace ~
32701 \InsetSpace ~
32702 \InsetSpace ~
32703 \InsetSpace ~
32704  mov\InsetSpace ~
32705 \InsetSpace ~
32706  a,(_gint + 1) 
32707 \newline
32708 001D
32709  03\InsetSpace ~
32710 \InsetSpace ~
32711 \InsetSpace ~
32712 \InsetSpace ~
32713 \InsetSpace ~
32714 \InsetSpace ~
32715 \InsetSpace ~
32716 \InsetSpace ~
32717 \InsetSpace ~
32718 \InsetSpace ~
32719 \InsetSpace ~
32720 \InsetSpace ~
32721 \InsetSpace ~
32722 \InsetSpace ~
32723 \InsetSpace ~
32724 \InsetSpace ~
32725 \InsetSpace ~
32726 \InsetSpace ~
32727  72\InsetSpace ~
32728 \InsetSpace ~
32729 \InsetSpace ~
32730 \InsetSpace ~
32731 \InsetSpace ~
32732 \InsetSpace ~
32733 \InsetSpace ~
32734 \InsetSpace ~
32735  rr\InsetSpace ~
32736 \InsetSpace ~
32737 \InsetSpace ~
32738  a 
32739 \newline
32740 001E 54 01\InsetSpace ~
32741 \InsetSpace ~
32742 \InsetSpace ~
32743 \InsetSpace ~
32744 \InsetSpace ~
32745 \InsetSpace ~
32746 \InsetSpace ~
32747 \InsetSpace ~
32748 \InsetSpace ~
32749 \InsetSpace ~
32750 \InsetSpace ~
32751 \InsetSpace ~
32752 \InsetSpace ~
32753 \InsetSpace ~
32754 \InsetSpace ~
32755  73\InsetSpace ~
32756 \InsetSpace ~
32757 \InsetSpace ~
32758 \InsetSpace ~
32759 \InsetSpace ~
32760 \InsetSpace ~
32761 \InsetSpace ~
32762 \InsetSpace ~
32763  anl\InsetSpace ~
32764 \InsetSpace ~
32765  a,#0x01 
32766 \newline
32767 0020 F5*03\InsetSpace ~
32768 \InsetSpace ~
32769 \InsetSpace ~
32770 \InsetSpace ~
32771 \InsetSpace ~
32772 \InsetSpace ~
32773 \InsetSpace ~
32774 \InsetSpace ~
32775 \InsetSpace ~
32776 \InsetSpace ~
32777 \InsetSpace ~
32778 \InsetSpace ~
32779 \InsetSpace ~
32780 \InsetSpace ~
32781 \InsetSpace ~
32782  74\InsetSpace ~
32783 \InsetSpace ~
32784 \InsetSpace ~
32785 \InsetSpace ~
32786 \InsetSpace ~
32787 \InsetSpace ~
32788 \InsetSpace ~
32789 \InsetSpace ~
32790  mov\InsetSpace ~
32791 \InsetSpace ~
32792  _foo_aob1_1_1,a
32793  
32794 \newline
32795 \InsetSpace ~
32796 \InsetSpace ~
32797 \InsetSpace ~
32798 \InsetSpace ~
32799 \InsetSpace ~
32800 \InsetSpace ~
32801 \InsetSpace ~
32802 \InsetSpace ~
32803 \InsetSpace ~
32804 \InsetSpace ~
32805 \InsetSpace ~
32806 \InsetSpace ~
32807 \InsetSpace ~
32808 \InsetSpace ~
32809 \InsetSpace ~
32810 \InsetSpace ~
32811 \InsetSpace ~
32812 \InsetSpace ~
32813 \InsetSpace ~
32814 \InsetSpace ~
32815 \InsetSpace ~
32816 \InsetSpace ~
32817 \InsetSpace ~
32818 \InsetSpace ~
32819 \InsetSpace ~
32820  75 ;\InsetSpace ~
32821  hob.c 11 
32822 \newline
32823 0022 E5*01\InsetSpace ~
32824 \InsetSpace ~
32825 \InsetSpace ~
32826 \InsetSpace ~
32827 \InsetSpace ~
32828 \InsetSpace ~
32829 \InsetSpace ~
32830 \InsetSpace ~
32831 \InsetSpace ~
32832 \InsetSpace ~
32833 \InsetSpace ~
32834 \InsetSpace ~
32835 \InsetSpace ~
32836 \InsetSpace ~
32837 \InsetSpace ~
32838  76\InsetSpace ~
32839 \InsetSpace ~
32840 \InsetSpace ~
32841 \InsetSpace ~
32842 \InsetSpace ~
32843 \InsetSpace ~
32844 \InsetSpace ~
32845 \InsetSpace ~
32846  mov\InsetSpace ~
32847 \InsetSpace ~
32848  a,(_gint + 1) 
32849 \newline
32850 0024 13\InsetSpace ~
32851 \InsetSpace ~
32852 \InsetSpace ~
32853 \InsetSpace ~
32854 \InsetSpace ~
32855 \InsetSpace ~
32856 \InsetSpace ~
32857 \InsetSpace ~
32858 \InsetSpace ~
32859 \InsetSpace ~
32860 \InsetSpace ~
32861 \InsetSpace ~
32862 \InsetSpace ~
32863 \InsetSpace ~
32864 \InsetSpace ~
32865 \InsetSpace ~
32866 \InsetSpace ~
32867 \InsetSpace ~
32868  77\InsetSpace ~
32869 \InsetSpace ~
32870 \InsetSpace ~
32871 \InsetSpace ~
32872 \InsetSpace ~
32873 \InsetSpace ~
32874 \InsetSpace ~
32875 \InsetSpace ~
32876  rrc\InsetSpace ~
32877 \InsetSpace ~
32878  a 
32879 \newline
32880 0025 92*02\InsetSpace ~
32881 \InsetSpace ~
32882 \InsetSpace ~
32883 \InsetSpace ~
32884 \InsetSpace ~
32885 \InsetSpace ~
32886 \InsetSpace ~
32887 \InsetSpace ~
32888 \InsetSpace ~
32889 \InsetSpace ~
32890 \InsetSpace ~
32891 \InsetSpace ~
32892 \InsetSpace ~
32893 \InsetSpace ~
32894 \InsetSpace ~
32895
32896  78\InsetSpace ~
32897 \InsetSpace ~
32898 \InsetSpace ~
32899 \InsetSpace ~
32900 \InsetSpace ~
32901 \InsetSpace ~
32902 \InsetSpace ~
32903 \InsetSpace ~
32904  mov\InsetSpace ~
32905 \InsetSpace ~
32906  _foo_aob2_1_1,c 
32907 \newline
32908 \InsetSpace ~
32909 \InsetSpace ~
32910 \InsetSpace ~
32911 \InsetSpace ~
32912 \InsetSpace ~
32913 \InsetSpace ~
32914 \InsetSpace ~
32915 \InsetSpace ~
32916 \InsetSpace ~
32917 \InsetSpace ~
32918 \InsetSpace ~
32919 \InsetSpace ~
32920 \InsetSpace ~
32921 \InsetSpace ~
32922 \InsetSpace ~
32923 \InsetSpace ~
32924 \InsetSpace ~
32925 \InsetSpace ~
32926 \InsetSpace ~
32927 \InsetSpace ~
32928 \InsetSpace ~
32929 \InsetSpace ~
32930 \InsetSpace ~
32931 \InsetSpace ~
32932 \InsetSpace ~
32933  79 ;\InsetSpace ~
32934  hob.c 12 
32935 \newline
32936 0027 E5*01\InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939 \InsetSpace ~
32940 \InsetSpace ~
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 \InsetSpace ~
32944 \InsetSpace ~
32945 \InsetSpace ~
32946 \InsetSpace ~
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 \InsetSpace ~
32950 \InsetSpace ~
32951  80\InsetSpace ~
32952 \InsetSpace ~
32953 \InsetSpace ~
32954 \InsetSpace ~
32955 \InsetSpace ~
32956 \InsetSpace ~
32957 \InsetSpace ~
32958 \InsetSpace ~
32959  mov\InsetSpace ~
32960 \InsetSpace ~
32961  a,(_gint + 1) 
32962 \newline
32963 0029
32964  A2 E3\InsetSpace ~
32965 \InsetSpace ~
32966 \InsetSpace ~
32967 \InsetSpace ~
32968 \InsetSpace ~
32969 \InsetSpace ~
32970 \InsetSpace ~
32971 \InsetSpace ~
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 \InsetSpace ~
32976 \InsetSpace ~
32977 \InsetSpace ~
32978 \InsetSpace ~
32979  81\InsetSpace ~
32980 \InsetSpace ~
32981 \InsetSpace ~
32982 \InsetSpace ~
32983 \InsetSpace ~
32984 \InsetSpace ~
32985 \InsetSpace ~
32986 \InsetSpace ~
32987  mov\InsetSpace ~
32988 \InsetSpace ~
32989  c,acc[3] 
32990 \newline
32991 002B 92*03\InsetSpace ~
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 \InsetSpace ~
32995 \InsetSpace ~
32996 \InsetSpace ~
32997 \InsetSpace ~
32998 \InsetSpace ~
32999 \InsetSpace ~
33000 \InsetSpace ~
33001 \InsetSpace ~
33002 \InsetSpace ~
33003 \InsetSpace ~
33004 \InsetSpace ~
33005 \InsetSpace ~
33006  82\InsetSpace ~
33007 \InsetSpace ~
33008 \InsetSpace ~
33009 \InsetSpace ~
33010 \InsetSpace ~
33011 \InsetSpace ~
33012 \InsetSpace ~
33013 \InsetSpace ~
33014  mov\InsetSpace ~
33015 \InsetSpace ~
33016  _foo_aob3_1_1,c 
33017 \end_layout
33018
33019 \begin_layout Standard
33020 Other variations of these cases however will 
33021 \emph on
33022 not
33023 \emph default
33024  be recognized.
33025  They are standard C expressions, so I heartily recommend these be the only
33026  way to get the highest order bit, (it is portable).
33027  Of course it will be recognized even if it is embedded in other expressions,
33028  e.g.:
33029 \end_layout
33030
33031 \begin_layout Verse
33032
33033 \family typewriter
33034 xyz = gint + ((gint >> 15) & 1);
33035 \end_layout
33036
33037 \begin_layout Standard
33038 will still be recognized.
33039 \end_layout
33040
33041 \begin_layout Subsection
33042 Higher Order Byte
33043 \begin_inset LatexCommand \index{Higher Order Byte}
33044
33045 \end_inset
33046
33047  / Higher Order Word
33048 \begin_inset LatexCommand \index{Higher Order Word}
33049
33050 \end_inset
33051
33052
33053 \end_layout
33054
33055 \begin_layout Standard
33056 It is also frequently required to obtain a higher order byte or word of
33057  a larger integral type (long, int or short types).
33058  SDCC recognizes the following expressions to yield the higher order byte
33059  or word and generates optimized code for it, e.g.:
33060 \end_layout
33061
33062 \begin_layout Verse
33063
33064 \family typewriter
33065 unsigned int gint; 
33066 \newline
33067 unsigned long int glong; 
33068 \newline
33069
33070 \newline
33071 foo () { 
33072 \newline
33073 \InsetSpace ~
33074 \InsetSpace ~
33075 unsigned char hob1,
33076  hob2; 
33077 \newline
33078 \InsetSpace ~
33079 \InsetSpace ~
33080 unsigned int how1, how2; 
33081 \newline
33082 \InsetSpace ~
33083 \InsetSpace ~
33084 ...
33085  
33086 \newline
33087 \InsetSpace ~
33088 \InsetSpace ~
33089 hob1 = (gint >> 8) & 0xFF; 
33090 \newline
33091 \InsetSpace ~
33092 \InsetSpace ~
33093 hob2 = glong >> 24; 
33094 \newline
33095 \InsetSpace ~
33096 \InsetSpace ~
33097 how1 = (glong >> 16) & 0xFFFF;
33098  
33099 \newline
33100 \InsetSpace ~
33101 \InsetSpace ~
33102 how2 = glong >> 8; 
33103 \newline
33104 \InsetSpace ~
33105 \InsetSpace ~
33106 ..
33107  
33108 \newline
33109 }
33110 \end_layout
33111
33112 \begin_layout Standard
33113 will generate the following code:
33114 \end_layout
33115
33116 \begin_layout Verse
33117
33118 \family typewriter
33119 \InsetSpace ~
33120 \InsetSpace ~
33121 \InsetSpace ~
33122 \InsetSpace ~
33123 \InsetSpace ~
33124 \InsetSpace ~
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 \InsetSpace ~
33128 \InsetSpace ~
33129 \InsetSpace ~
33130 \InsetSpace ~
33131 \InsetSpace ~
33132 \InsetSpace ~
33133 \InsetSpace ~
33134 \InsetSpace ~
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 \InsetSpace ~
33138 \InsetSpace ~
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 \InsetSpace ~
33142 \InsetSpace ~
33143 \InsetSpace ~
33144  91 ;\InsetSpace ~
33145  hob.c 15 
33146 \newline
33147 0037 85*01*06\InsetSpace ~
33148 \InsetSpace ~
33149 \InsetSpace ~
33150 \InsetSpace ~
33151 \InsetSpace ~
33152 \InsetSpace ~
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 \InsetSpace ~
33156 \InsetSpace ~
33157 \InsetSpace ~
33158 \InsetSpace ~
33159  92\InsetSpace ~
33160 \InsetSpace ~
33161 \InsetSpace ~
33162 \InsetSpace ~
33163 \InsetSpace ~
33164 \InsetSpace ~
33165 \InsetSpace ~
33166 \InsetSpace ~
33167  mov\InsetSpace ~
33168 \InsetSpace ~
33169  _foo_hob1_1_1,(_gint + 1) 
33170 \newline
33171 \InsetSpace ~
33172 \InsetSpace ~
33173 \InsetSpace ~
33174 \InsetSpace ~
33175 \InsetSpace ~
33176 \InsetSpace ~
33177 \InsetSpace ~
33178 \InsetSpace ~
33179 \InsetSpace ~
33180 \InsetSpace ~
33181 \InsetSpace ~
33182 \InsetSpace ~
33183 \InsetSpace ~
33184 \InsetSpace ~
33185 \InsetSpace ~
33186 \InsetSpace ~
33187 \InsetSpace ~
33188 \InsetSpace ~
33189 \InsetSpace ~
33190 \InsetSpace ~
33191 \InsetSpace ~
33192 \InsetSpace ~
33193 \InsetSpace ~
33194 \InsetSpace ~
33195 \InsetSpace ~
33196  93 ;\InsetSpace ~
33197  hob.c
33198  16 
33199 \newline
33200 003A 85*05*07\InsetSpace ~
33201 \InsetSpace ~
33202 \InsetSpace ~
33203 \InsetSpace ~
33204 \InsetSpace ~
33205 \InsetSpace ~
33206 \InsetSpace ~
33207 \InsetSpace ~
33208 \InsetSpace ~
33209 \InsetSpace ~
33210 \InsetSpace ~
33211 \InsetSpace ~
33212  94\InsetSpace ~
33213 \InsetSpace ~
33214 \InsetSpace ~
33215 \InsetSpace ~
33216 \InsetSpace ~
33217 \InsetSpace ~
33218 \InsetSpace ~
33219 \InsetSpace ~
33220  mov\InsetSpace ~
33221 \InsetSpace ~
33222  _foo_hob2_1_1,(_glong + 3) 
33223 \newline
33224 \InsetSpace ~
33225 \InsetSpace ~
33226 \InsetSpace ~
33227 \InsetSpace ~
33228 \InsetSpace ~
33229 \InsetSpace ~
33230 \InsetSpace ~
33231 \InsetSpace ~
33232 \InsetSpace ~
33233 \InsetSpace ~
33234 \InsetSpace ~
33235 \InsetSpace ~
33236 \InsetSpace ~
33237 \InsetSpace ~
33238 \InsetSpace ~
33239 \InsetSpace ~
33240 \InsetSpace ~
33241 \InsetSpace ~
33242 \InsetSpace ~
33243 \InsetSpace ~
33244 \InsetSpace ~
33245 \InsetSpace ~
33246 \InsetSpace ~
33247 \InsetSpace ~
33248 \InsetSpace ~
33249  95 ;\InsetSpace ~
33250  hob.c 17 
33251 \newline
33252 003D 85*04*08\InsetSpace ~
33253 \InsetSpace ~
33254 \InsetSpace ~
33255 \InsetSpace ~
33256 \InsetSpace ~
33257 \InsetSpace ~
33258 \InsetSpace ~
33259 \InsetSpace ~
33260 \InsetSpace ~
33261 \InsetSpace ~
33262 \InsetSpace ~
33263 \InsetSpace ~
33264
33265  96\InsetSpace ~
33266 \InsetSpace ~
33267 \InsetSpace ~
33268 \InsetSpace ~
33269 \InsetSpace ~
33270 \InsetSpace ~
33271 \InsetSpace ~
33272 \InsetSpace ~
33273  mov\InsetSpace ~
33274 \InsetSpace ~
33275  _foo_how1_1_1,(_glong + 2) 
33276 \newline
33277 0040 85*05*09\InsetSpace ~
33278 \InsetSpace ~
33279 \InsetSpace ~
33280 \InsetSpace ~
33281 \InsetSpace ~
33282 \InsetSpace ~
33283 \InsetSpace ~
33284 \InsetSpace ~
33285 \InsetSpace ~
33286 \InsetSpace ~
33287 \InsetSpace ~
33288 \InsetSpace ~
33289  97\InsetSpace ~
33290 \InsetSpace ~
33291 \InsetSpace ~
33292 \InsetSpace ~
33293 \InsetSpace ~
33294 \InsetSpace ~
33295 \InsetSpace ~
33296 \InsetSpace ~
33297  mov\InsetSpace ~
33298 \InsetSpace ~
33299  (_foo_how1_1_1 +
33300  1),(_glong + 3) 
33301 \newline
33302 0043 85*03*0A\InsetSpace ~
33303 \InsetSpace ~
33304 \InsetSpace ~
33305 \InsetSpace ~
33306 \InsetSpace ~
33307 \InsetSpace ~
33308 \InsetSpace ~
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 \InsetSpace ~
33312 \InsetSpace ~
33313 \InsetSpace ~
33314  98\InsetSpace ~
33315 \InsetSpace ~
33316 \InsetSpace ~
33317 \InsetSpace ~
33318 \InsetSpace ~
33319 \InsetSpace ~
33320 \InsetSpace ~
33321 \InsetSpace ~
33322  mov\InsetSpace ~
33323 \InsetSpace ~
33324  _foo_how2_1_1,(_glong + 1) 
33325 \newline
33326 0046 85*04*0B\InsetSpace ~
33327 \InsetSpace ~
33328 \InsetSpace ~
33329 \InsetSpace ~
33330 \InsetSpace ~
33331 \InsetSpace ~
33332 \InsetSpace ~
33333 \InsetSpace ~
33334 \InsetSpace ~
33335 \InsetSpace ~
33336 \InsetSpace ~
33337 \InsetSpace ~
33338
33339  99\InsetSpace ~
33340 \InsetSpace ~
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 \InsetSpace ~
33344 \InsetSpace ~
33345 \InsetSpace ~
33346 \InsetSpace ~
33347  mov\InsetSpace ~
33348 \InsetSpace ~
33349  (_foo_how2_1_1 + 1),(_glong + 2) 
33350 \end_layout
33351
33352 \begin_layout Standard
33353 Again, variations of these cases may 
33354 \emph on
33355 not
33356 \emph default
33357  be recognized.
33358  They are standard C expressions, so I heartily recommend these be the only
33359  way to get the higher order byte/word, (it is portable).
33360  Of course it will be recognized even if it is embedded in other expressions,
33361  e.g.:
33362 \end_layout
33363
33364 \begin_layout Verse
33365
33366 \family typewriter
33367 xyz = gint + ((gint >> 8) & 0xFF);
33368 \end_layout
33369
33370 \begin_layout Standard
33371 will still be recognized.
33372 \end_layout
33373
33374 \begin_layout Subsection
33375 Peephole Optimizer
33376 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
33377
33378 \end_inset
33379
33380
33381 \begin_inset LatexCommand \index{Peephole optimizer}
33382
33383 \end_inset
33384
33385
33386 \end_layout
33387
33388 \begin_layout Standard
33389 The compiler uses a rule based, pattern matching and re-writing mechanism
33390  for peep-hole optimization.
33391  It is inspired by 
33392 \emph on
33393 copt
33394 \emph default
33395  a peep-hole optimizer by Christopher W.
33396  Fraser (cwfraser\InsetSpace ~
33397 @\InsetSpace ~
33398 microsoft.com).
33399  A default set of rules are compiled into the compiler, additional rules
33400  may be added with the 
33401 \emph on
33402 -
33403 \begin_inset ERT
33404 status collapsed
33405
33406 \begin_layout Standard
33407
33408
33409 \backslash
33410 /
33411 \end_layout
33412
33413 \end_inset
33414
33415 -peep-file
33416 \begin_inset LatexCommand \index{-\/-peep-file}
33417
33418 \end_inset
33419
33420  <filename>
33421 \emph default
33422  option.
33423  The rule language is best illustrated with examples.
33424 \end_layout
33425
33426 \begin_layout Verse
33427
33428 \family typewriter
33429 replace { 
33430 \newline
33431 \InsetSpace ~
33432 \InsetSpace ~
33433 mov %1,a 
33434 \newline
33435 \InsetSpace ~
33436 \InsetSpace ~
33437 mov a,%1
33438 \newline
33439 } by {
33440 \newline
33441 \InsetSpace ~
33442 \InsetSpace ~
33443 mov %1,a
33444 \newline
33445 }
33446 \end_layout
33447
33448 \begin_layout Standard
33449 The above rule will change the following assembly
33450 \begin_inset LatexCommand \index{Assembler routines}
33451
33452 \end_inset
33453
33454  sequence:
33455 \end_layout
33456
33457 \begin_layout Verse
33458
33459 \family typewriter
33460 mov r1,a 
33461 \newline
33462 mov a,r1
33463 \end_layout
33464
33465 \begin_layout Standard
33466 to
33467 \end_layout
33468
33469 \begin_layout Verse
33470
33471 \family typewriter
33472 mov r1,a
33473 \end_layout
33474
33475 \begin_layout Standard
33476 Note: All occurrences of a 
33477 \emph on
33478 %n
33479 \emph default
33480  (pattern variable) must denote the same string.
33481  With the above rule, the assembly sequence:
33482 \end_layout
33483
33484 \begin_layout Verse
33485
33486 \family typewriter
33487 mov r1,a 
33488 \newline
33489 mov a,r2
33490 \end_layout
33491
33492 \begin_layout Standard
33493 will remain unmodified.
33494 \newline
33495
33496 \newline
33497 Other special case optimizations may be added by the
33498  user (via 
33499 \emph on
33500 -
33501 \begin_inset ERT
33502 status collapsed
33503
33504 \begin_layout Standard
33505
33506
33507 \backslash
33508 /
33509 \end_layout
33510
33511 \end_inset
33512
33513 -peep-file option
33514 \emph default
33515 ).
33516  E.g.
33517  some variants of the 8051 MCU
33518 \begin_inset LatexCommand \index{MCS51 variants}
33519
33520 \end_inset
33521
33522  allow only 
33523 \family typewriter
33524 ajmp
33525 \family default
33526  and 
33527 \family typewriter
33528 acall
33529 \family default
33530 .
33531  The following two rules will change all 
33532 \family typewriter
33533 ljmp
33534 \family default
33535  and 
33536 \family typewriter
33537 lcall
33538 \family default
33539  to 
33540 \family typewriter
33541 ajmp
33542 \family default
33543  and 
33544 \family typewriter
33545 acall
33546 \end_layout
33547
33548 \begin_layout Verse
33549
33550 \family typewriter
33551 replace { lcall %1 } by { acall %1 } 
33552 \newline
33553 replace { ljmp %1 } by { ajmp %1 }
33554 \end_layout
33555
33556 \begin_layout Standard
33557 The 
33558 \emph on
33559 inline-assembler code
33560 \emph default
33561  is also passed through the peep hole optimizer, thus the peephole optimizer
33562  can also be used as an assembly level macro expander.
33563  The rules themselves are MCU dependent whereas the rule language infra-structur
33564 e is MCU independent.
33565  Peephole optimization rules for other MCU can be easily programmed using
33566  the rule language.
33567 \newline
33568
33569 \newline
33570 The syntax for a rule is as follows:
33571 \end_layout
33572
33573 \begin_layout Verse
33574
33575 \family typewriter
33576 rule := replace [ restart ] '{' <assembly sequence> '
33577 \backslash
33578 n' 
33579 \newline
33580 \InsetSpace ~
33581  \InsetSpace ~
33582  \InsetSpace ~
33583  \InsetSpace ~
33584  \InsetSpace ~
33585  \InsetSpace ~
33586  \InsetSpace ~
33587  \InsetSpace ~
33588  \InsetSpace ~
33589  \InsetSpace ~
33590  \InsetSpace ~
33591  \InsetSpace ~
33592  \InsetSpace ~
33593  \InsetSpace ~
33594  '}' by '{' '
33595 \backslash
33596 n' 
33597 \newline
33598 \InsetSpace ~
33599  \InsetSpace ~
33600  \InsetSpace ~
33601  \InsetSpace ~
33602  \InsetSpace ~
33603  \InsetSpace ~
33604  \InsetSpace ~
33605  \InsetSpace ~
33606  \InsetSpace ~
33607  \InsetSpace ~
33608  \InsetSpace ~
33609  \InsetSpace ~
33610  \InsetSpace ~
33611  \InsetSpace ~
33612  \InsetSpace ~
33613  \InsetSpace ~
33614  <assembly sequence> '
33615 \backslash
33616 n' 
33617 \newline
33618 \InsetSpace ~
33619  \InsetSpace ~
33620  \InsetSpace ~
33621  \InsetSpace ~
33622  \InsetSpace ~
33623  \InsetSpace ~
33624  \InsetSpace ~
33625  \InsetSpace ~
33626  \InsetSpace ~
33627  \InsetSpace ~
33628  \InsetSpace ~
33629  \InsetSpace ~
33630  \InsetSpace ~
33631  \InsetSpace ~
33632  '}' [if <functionName> ] '
33633 \backslash
33634 n' 
33635 \end_layout
33636
33637 \begin_layout Standard
33638 <assembly sequence> := assembly instruction (each instruction including
33639  labels must be on a separate line).
33640 \newline
33641
33642 \newline
33643 The optimizer will apply to the rules
33644  one by one from the top in the sequence of their appearance, it will terminate
33645  when all rules are exhausted.
33646  If the 'restart' option is specified, then the optimizer will start matching
33647  the rules again from the top, this option for a rule is expensive (performance)
33648 , it is intended to be used in situations where a transformation will trigger
33649  the same rule again.
33650  An example of this (not a good one, it has side effects) is the following
33651  rule:
33652 \end_layout
33653
33654 \begin_layout Verse
33655
33656 \family typewriter
33657 replace restart { 
33658 \newline
33659 \InsetSpace ~
33660 \InsetSpace ~
33661 pop %1 
33662 \newline
33663 \InsetSpace ~
33664 \InsetSpace ~
33665 push %1 } by { 
33666 \newline
33667 \InsetSpace ~
33668 \InsetSpace ~
33669 ; nop 
33670 \newline
33671 }
33672 \end_layout
33673
33674 \begin_layout Standard
33675 Note that the replace pattern cannot be a blank, but can be a comment line.
33676  Without the 'restart' option only the innermost 'pop' 'push' pair would
33677  be eliminated, i.e.:
33678 \end_layout
33679
33680 \begin_layout Verse
33681
33682 \family typewriter
33683 pop ar1 
33684 \newline
33685 pop ar2 
33686 \newline
33687 push ar2 
33688 \newline
33689 push ar1
33690 \end_layout
33691
33692 \begin_layout Standard
33693 would result in:
33694 \end_layout
33695
33696 \begin_layout Verse
33697
33698 \family typewriter
33699 pop ar1 
33700 \newline
33701 ; nop 
33702 \newline
33703 push ar1
33704 \end_layout
33705
33706 \begin_layout Standard
33707
33708 \emph on
33709 with
33710 \emph default
33711  the restart option the rule will be applied again to the resulting code
33712  and then all the pop-push pairs will be eliminated to yield:
33713 \end_layout
33714
33715 \begin_layout Verse
33716
33717 \family typewriter
33718 ; nop 
33719 \newline
33720 ; nop
33721 \end_layout
33722
33723 \begin_layout Standard
33724 A conditional function can be attached to a rule.
33725  Attaching rules are somewhat more involved, let me illustrate this with
33726  an example.
33727 \end_layout
33728
33729 \begin_layout Verse
33730
33731 \family typewriter
33732 replace { 
33733 \newline
33734 \InsetSpace ~
33735  \InsetSpace ~
33736  \InsetSpace ~
33737 ljmp %5 
33738 \newline
33739 %2:
33740 \newline
33741 } by { 
33742 \newline
33743 \InsetSpace ~
33744  \InsetSpace ~
33745  \InsetSpace ~
33746 sjmp %5 
33747 \newline
33748 %2:
33749 \newline
33750 } if labelInRange
33751 \end_layout
33752
33753 \begin_layout Standard
33754 The optimizer does a look-up of a function name table defined in function
33755  
33756 \emph on
33757 callFuncByName
33758 \emph default
33759  in the source file SDCCpeeph.c, with the name 
33760 \emph on
33761 labelInRange
33762 \emph default
33763 .
33764  If it finds a corresponding entry the function is called.
33765  Note there can be no parameters specified for these functions, in this
33766  case the use of 
33767 \emph on
33768 %5
33769 \emph default
33770  is crucial, since the function 
33771 \emph on
33772 labelInRange
33773 \emph default
33774  expects to find the label in that particular variable (the hash table containin
33775 g the variable bindings is passed as a parameter).
33776  If you want to code more such functions, take a close look at the function
33777  labelInRange and the calling mechanism in source file SDCCpeeph.c.
33778  Currently implemented are 
33779 \emph on
33780 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
33781  24bitMode, portIsDS390, 24bitModeAndPortDS390 
33782 \emph default
33783 and
33784 \emph on
33785  notVolatile
33786 \emph default
33787 .
33788 \end_layout
33789
33790 \begin_layout Standard
33791 I know this whole thing is a little kludgey, but maybe some day we will
33792  have some better means.
33793  If you are looking at this file, you will see the default rules that are
33794  compiled into the compiler, you can add your own rules in the default set
33795  there if you get tired of specifying the -
33796 \begin_inset ERT
33797 status collapsed
33798
33799 \begin_layout Standard
33800
33801
33802 \backslash
33803 /
33804 \end_layout
33805
33806 \end_inset
33807
33808 -peep-file option.
33809 \end_layout
33810
33811 \begin_layout Section
33812 ANSI-Compliance
33813 \begin_inset LatexCommand \index{ANSI-compliance}
33814
33815 \end_inset
33816
33817
33818 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
33819
33820 \end_inset
33821
33822
33823 \end_layout
33824
33825 \begin_layout Standard
33826 The latest publically available version of the standard 
33827 \emph on
33828 ISO/IEC 9899 - Programming languages - C
33829 \emph default
33830  should be available at: 
33831 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
33832
33833 \end_inset
33834
33835 .
33836 \newline
33837
33838 \end_layout
33839
33840 \begin_layout Standard
33841 Deviations from the compliance:
33842 \end_layout
33843
33844 \begin_layout Itemize
33845 functions are not reentrant
33846 \begin_inset LatexCommand \index{reentrant}
33847
33848 \end_inset
33849
33850  unless explicitly declared as such or the 
33851 \series bold
33852 -
33853 \begin_inset ERT
33854 status collapsed
33855
33856 \begin_layout Standard
33857
33858
33859 \backslash
33860 /
33861 \end_layout
33862
33863 \end_inset
33864
33865 -stack-auto
33866 \begin_inset LatexCommand \index{-\/-stack-auto}
33867
33868 \end_inset
33869
33870
33871 \series default
33872  command line option is specified.
33873 \end_layout
33874
33875 \begin_layout Itemize
33876 structures
33877 \begin_inset LatexCommand \index{struct}
33878
33879 \end_inset
33880
33881  and unions
33882 \begin_inset LatexCommand \index{union}
33883
33884 \end_inset
33885
33886  cannot be assigned values directly, cannot be passed as function parameters
33887  or assigned to each other and cannot be a return value
33888 \begin_inset LatexCommand \index{return value}
33889
33890 \end_inset
33891
33892  from a function, e.g.:
33893 \end_layout
33894
33895 \begin_deeper
33896 \begin_layout Verse
33897
33898 \family typewriter
33899 struct s { ...
33900  }; 
33901 \newline
33902 struct s s1, s2; 
33903 \newline
33904 foo() 
33905 \newline
33906
33907 \newline
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 \InsetSpace ~
33912 ...
33913  
33914 \newline
33915 \InsetSpace ~
33916 \InsetSpace ~
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
33920 \newline
33921 \InsetSpace ~
33922 \InsetSpace ~
33923 \InsetSpace ~
33924 \InsetSpace ~
33925 ...
33926  
33927 \newline
33928 }
33929 \newline
33930
33931 \series bold
33932 struct
33933 \series default
33934  s foo1 (
33935 \series bold
33936 struct
33937 \series default
33938  s parms) /* invalid in SDCC although allowed in ANSI */
33939 \newline
33940
33941 \newline
33942 \InsetSpace ~
33943 \InsetSpace ~
33944 \InsetSpace ~
33945 \InsetSpace ~
33946 struct s rets;
33947  
33948 \newline
33949 \InsetSpace ~
33950 \InsetSpace ~
33951 \InsetSpace ~
33952 \InsetSpace ~
33953 ...
33954  
33955 \newline
33956 \InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 \InsetSpace ~
33960 return rets; /* is invalid in SDCC although allowed in ANSI */ 
33961 \newline
33962 }
33963 \end_layout
33964
33965 \end_deeper
33966 \begin_layout Itemize
33967 initialization of structure arrays must be fully braced.
33968 \end_layout
33969
33970 \begin_deeper
33971 \begin_layout Verse
33972
33973 \family typewriter
33974 struct s { char x } a[] = {1, 2};\InsetSpace ~
33975 \InsetSpace ~
33976 \InsetSpace ~
33977 \InsetSpace ~
33978 \InsetSpace ~
33979 /* invalid in SDCC */
33980 \newline
33981 struct s { char x
33982  } a[] = {{1}, {2}}; /* OK */
33983 \end_layout
33984
33985 \end_deeper
33986 \begin_layout Itemize
33987 'long long
33988 \begin_inset LatexCommand \index{long long (not supported)}
33989
33990 \end_inset
33991
33992 ' (64 bit integers
33993 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
33994
33995 \end_inset
33996
33997 ) not supported.
33998 \end_layout
33999
34000 \begin_layout Itemize
34001 'double
34002 \begin_inset LatexCommand \index{double (not supported)}
34003
34004 \end_inset
34005
34006 ' precision floating point 
34007 \begin_inset LatexCommand \index{Floating point support}
34008
34009 \end_inset
34010
34011 not supported.
34012 \end_layout
34013
34014 \begin_layout Itemize
34015 Old K&R style
34016 \begin_inset LatexCommand \index{K\&R style}
34017
34018 \end_inset
34019
34020  function declarations are NOT allowed.
34021 \end_layout
34022
34023 \begin_deeper
34024 \begin_layout Verse
34025
34026 \family typewriter
34027 foo(i,j) /* this old style of function declarations */ 
34028 \newline
34029 int i,j; /* are valid
34030  in ANSI but not valid in SDCC */ 
34031 \newline
34032
34033 \newline
34034 \InsetSpace ~
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 ...
34039  
34040 \newline
34041 }
34042 \end_layout
34043
34044 \end_deeper
34045 \begin_layout Itemize
34046 Most enhancements in C99 are not supported, f.e.:
34047 \end_layout
34048
34049 \begin_deeper
34050 \begin_layout Verse
34051
34052 \family typewriter
34053 \series bold
34054 inline
34055 \begin_inset LatexCommand \index{inline (not supported)}
34056
34057 \end_inset
34058
34059
34060 \series default
34061  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
34062  in C99.
34063  An empty define 
34064 \emph on
34065 #define inline
34066 \emph default
34067  can be used as a work around */
34068 \newline
34069
34070 \newline
34071 for (
34072 \series bold
34073 int
34074 \series default
34075  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
34076 \end_layout
34077
34078 \end_deeper
34079 \begin_layout Itemize
34080 Certain words that are valid identifiers in the standard may be reserved
34081  words in SDCC unless the 
34082 \series bold
34083 -
34084 \begin_inset ERT
34085 status collapsed
34086
34087 \begin_layout Standard
34088
34089
34090 \backslash
34091 /
34092 \end_layout
34093
34094 \end_inset
34095
34096 -std-c89
34097 \begin_inset LatexCommand \index{-\/-std-c89}
34098
34099 \end_inset
34100
34101  or -
34102 \begin_inset ERT
34103 status collapsed
34104
34105 \begin_layout Standard
34106
34107
34108 \backslash
34109 /
34110 \end_layout
34111
34112 \end_inset
34113
34114 -std-c99
34115 \begin_inset LatexCommand \index{-\/-std-c99}
34116
34117 \end_inset
34118
34119
34120 \series default
34121  command line options are used.
34122  These may include (depending on the selected processor): 'at', 'banked',
34123  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
34124 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
34125  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
34126  '_naked'.
34127  Compliant equivalents of these keywords are always available in a form
34128  that begin with two underscores
34129 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
34130
34131 \end_inset
34132
34133 , f.e.
34134  '__data' instead of 'data'.
34135 \end_layout
34136
34137 \begin_layout Section
34138 Cyclomatic Complexity
34139 \begin_inset LatexCommand \index{Cyclomatic complexity}
34140
34141 \end_inset
34142
34143
34144 \end_layout
34145
34146 \begin_layout Standard
34147 Cyclomatic complexity of a function is defined as the number of independent
34148  paths the program can take during execution of the function.
34149  This is an important number since it defines the number test cases you
34150  have to generate to validate the function.
34151  The accepted industry standard for complexity number is 10, if the cyclomatic
34152  complexity reported by SDCC exceeds 10 you should think about simplification
34153  of the function logic.
34154  Note that the complexity level is not related to the number of lines of
34155  code in a function.
34156  Large functions can have low complexity, and small functions can have large
34157  complexity levels.
34158  
34159 \newline
34160
34161 \newline
34162 SDCC uses the following formula to compute the complexity:
34163 \newline
34164
34165 \end_layout
34166
34167 \begin_layout Standard
34168 complexity = (number of edges in control flow graph) - (number of nodes
34169  in control flow graph) + 2;
34170 \newline
34171
34172 \newline
34173 Having said that the industry standard is 10,
34174  you should be aware that in some cases it be may unavoidable to have a
34175  complexity level of less than 10.
34176  For example if you have switch statement with more than 10 case labels,
34177  each case label adds one to the complexity level.
34178  The complexity level is by no means an absolute measure of the algorithmic
34179  complexity of the function, it does however provide a good starting point
34180  for which functions you might look at for further optimization.
34181 \end_layout
34182
34183 \begin_layout Section
34184 Retargetting for other Processors
34185 \end_layout
34186
34187 \begin_layout Standard
34188 The issues for retargetting the compiler are far too numerous to be covered
34189  by this document.
34190  What follows is a brief description of each of the seven phases of the
34191  compiler and its MCU dependency.
34192 \end_layout
34193
34194 \begin_layout Itemize
34195 Parsing the source and building the annotated parse tree.
34196  This phase is largely MCU independent (except for the language extensions).
34197  Syntax & semantic checks are also done in this phase, along with some initial
34198  optimizations like back patching labels and the pattern matching optimizations
34199  like bit-rotation etc.
34200 \end_layout
34201
34202 \begin_layout Itemize
34203 The second phase involves generating an intermediate code which can be easy
34204  manipulated during the later phases.
34205  This phase is entirely MCU independent.
34206  The intermediate code generation assumes the target machine has unlimited
34207  number of registers, and designates them with the name iTemp.
34208  The compiler can be made to dump a human readable form of the code generated
34209  by using the -
34210 \begin_inset ERT
34211 status collapsed
34212
34213 \begin_layout Standard
34214
34215
34216 \backslash
34217 /
34218 \end_layout
34219
34220 \end_inset
34221
34222 -dumpraw option.
34223 \end_layout
34224
34225 \begin_layout Itemize
34226 This phase does the bulk of the standard optimizations and is also MCU independe
34227 nt.
34228  This phase can be broken down into several sub-phases:
34229 \newline
34230
34231 \newline
34232 Break down intermediate
34233  code (iCode) into basic blocks.
34234 \newline
34235 Do control flow & data flow analysis on the
34236  basic blocks.
34237 \newline
34238 Do local common subexpression elimination, then global subexpressio
34239 n elimination
34240 \newline
34241 Dead code elimination
34242 \newline
34243 Loop optimizations
34244 \newline
34245 If loop optimizations
34246  caused any changes then do 'global subexpression elimination' and 'dead
34247  code elimination' again.
34248 \end_layout
34249
34250 \begin_layout Itemize
34251 This phase determines the live-ranges; by live range I mean those iTemp
34252  variables defined by the compiler that still survive after all the optimization
34253 s.
34254  Live range analysis
34255 \begin_inset LatexCommand \index{Live range analysis}
34256
34257 \end_inset
34258
34259  is essential for register allocation, since these computation determines
34260  which of these iTemps will be assigned to registers, and for how long.
34261 \end_layout
34262
34263 \begin_layout Itemize
34264 Phase five is register allocation.
34265  There are two parts to this process.
34266 \newline
34267
34268 \newline
34269 The first part I call 'register packing'
34270  (for lack of a better term).
34271  In this case several MCU specific expression folding is done to reduce
34272  register pressure.
34273 \newline
34274
34275 \newline
34276 The second part is more MCU independent and deals with
34277  allocating registers to the remaining live ranges.
34278  A lot of MCU specific code does creep into this phase because of the limited
34279  number of index registers available in the 8051.
34280 \end_layout
34281
34282 \begin_layout Itemize
34283 The Code generation phase is (unhappily), entirely MCU dependent and very
34284  little (if any at all) of this code can be reused for other MCU.
34285  However the scheme for allocating a homogenized assembler operand for each
34286  iCode operand may be reused.
34287 \end_layout
34288
34289 \begin_layout Itemize
34290 As mentioned in the optimization section the peep-hole optimizer is rule
34291  based system, which can reprogrammed for other MCUs.
34292 \end_layout
34293
34294 \begin_layout Standard
34295 More information is available in a wiki
34296 \begin_inset LatexCommand \index{wiki}
34297
34298 \end_inset
34299
34300  (preliminary link 
34301 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
34302
34303 \end_inset
34304
34305 ) and in the thread 
34306 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
34307
34308 \end_inset
34309
34310  .
34311 \end_layout
34312
34313 \begin_layout Chapter
34314 Compiler internals
34315 \begin_inset LatexCommand \index{Compiler internals}
34316
34317 \end_inset
34318
34319
34320 \end_layout
34321
34322 \begin_layout Section
34323 The anatomy of the compiler
34324 \begin_inset LatexCommand \label{sub:The-anatomy-of}
34325
34326 \end_inset
34327
34328
34329 \end_layout
34330
34331 \begin_layout Standard
34332
34333 \shape italic
34334 This is an excerpt from an article published in Circuit Cellar Magazine
34335  in 
34336 \series bold
34337 August 2000
34338 \series default
34339 .
34340  It's a little outdated (the compiler is much more efficient now and user/develo
34341 per friendly), but pretty well exposes the guts of it all.
34342 \shape default
34343
34344 \newline
34345
34346 \newline
34347 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
34348  It is fairly easy to retarget for other 8-bit MCU.
34349  Here we take a look at some of the internals of the compiler.
34350  
34351 \end_layout
34352
34353 \begin_layout Paragraph*
34354 Parsing
34355 \begin_inset LatexCommand \index{Parsing}
34356
34357 \end_inset
34358
34359  
34360 \end_layout
34361
34362 \begin_layout Standard
34363 Parsing the input source file and creating an AST (Annotated Syntax Tree
34364 \begin_inset LatexCommand \index{Annotated syntax tree}
34365
34366 \end_inset
34367
34368 ).
34369  This phase also involves propagating types (annotating each node of the
34370  parse tree with type information) and semantic analysis.
34371  There are some MCU specific parsing rules.
34372  For example the storage classes, the extended storage classes are MCU specific
34373  while there may be a xdata storage class for 8051 there is no such storage
34374  class for z80 or Atmel AVR.
34375  SDCC allows MCU specific storage class extensions, i.e.
34376  xdata will be treated as a storage class specifier when parsing 8051 C
34377  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
34378  C code.
34379 \end_layout
34380
34381 \begin_layout Paragraph*
34382 Generating iCode
34383 \begin_inset LatexCommand \index{iCode}
34384
34385 \end_inset
34386
34387
34388 \end_layout
34389
34390 \begin_layout Standard
34391 Intermediate code generation.
34392  In this phase the AST is broken down into three-operand form (iCode).
34393  These three operand forms are represented as doubly linked lists.
34394  ICode is the term given to the intermediate form generated by the compiler.
34395  ICode example section shows some examples of iCode generated for some simple
34396  C source functions.
34397 \end_layout
34398
34399 \begin_layout Paragraph*
34400 Optimizations
34401 \begin_inset LatexCommand \index{Optimizations}
34402
34403 \end_inset
34404
34405 .
34406 \end_layout
34407
34408 \begin_layout Standard
34409 Bulk of the target independent optimizations is performed in this phase.
34410  The optimizations include constant propagation, common sub-expression eliminati
34411 on, loop invariant code movement, strength reduction of loop induction variables
34412  and dead-code elimination.
34413 \end_layout
34414
34415 \begin_layout Paragraph*
34416 Live range analysis
34417 \begin_inset LatexCommand \index{Live range analysis}
34418
34419 \end_inset
34420
34421
34422 \end_layout
34423
34424 \begin_layout Standard
34425 During intermediate code generation phase, the compiler assumes the target
34426  machine has infinite number of registers and generates a lot of temporary
34427  variables.
34428  The live range computation determines the lifetime of each of these compiler-ge
34429 nerated temporaries.
34430  A picture speaks a thousand words.
34431  ICode example sections show the live range annotations for each of the
34432  operand.
34433  It is important to note here, each iCode is assigned a number in the order
34434  of its execution in the function.
34435  The live ranges are computed in terms of these numbers.
34436  The from number is the number of the iCode which first defines the operand
34437  and the to number signifies the iCode which uses this operand last.
34438 \end_layout
34439
34440 \begin_layout Paragraph*
34441 Register Allocation
34442 \begin_inset LatexCommand \index{Register allocation}
34443
34444 \end_inset
34445
34446
34447 \end_layout
34448
34449 \begin_layout Standard
34450 The register allocation determines the type and number of registers needed
34451  by each operand.
34452  In most MCUs only a few registers can be used for indirect addressing.
34453  In case of 8051 for example the registers R0 & R1 can be used to indirectly
34454  address the internal ram and DPTR to indirectly address the external ram.
34455  The compiler will try to allocate the appropriate register to pointer variables
34456  if it can.
34457  ICode example section shows the operands annotated with the registers assigned
34458  to them.
34459  The compiler will try to keep operands in registers as much as possible;
34460  there are several schemes the compiler uses to do achieve this.
34461  When the compiler runs out of registers the compiler will check to see
34462  if there are any live operands which is not used or defined in the current
34463  basic block being processed, if there are any found then it will push that
34464  operand and use the registers in this block, the operand will then be popped
34465  at the end of the basic block.
34466  
34467 \end_layout
34468
34469 \begin_layout Standard
34470 There are other MCU specific considerations in this phase.
34471  Some MCUs have an accumulator; very short-lived operands could be assigned
34472  to the accumulator instead of a general-purpose register.
34473 \end_layout
34474
34475 \begin_layout Paragraph*
34476 Code generation
34477 \end_layout
34478
34479 \begin_layout Standard
34480 Figure II gives a table of iCode
34481 \begin_inset LatexCommand \index{iCode}
34482
34483 \end_inset
34484
34485  operations supported by the compiler.
34486  The code generation involves translating these operations into corresponding
34487  assembly code for the processor.
34488  This sounds overly simple but that is the essence of code generation.
34489  Some of the iCode operations are generated on a MCU specific manner for
34490  example, the z80 port does not use registers to pass parameters so the
34491  SEND and RECV iCode operations will not be generated, and it also does
34492  not support JUMPTABLES.
34493  
34494 \newline
34495
34496 \end_layout
34497
34498 \begin_layout Standard
34499
34500 \size footnotesize
34501 Figure II 
34502 \begin_inset Tabular
34503 <lyxtabular version="3" rows="39" columns="4">
34504 <features islongtable="true" headBottomDL="true">
34505 <column alignment="block" valignment="top" leftline="true" width="13col%">
34506 <column alignment="left" valignment="top" leftline="true" width="13col%">
34507 <column alignment="block" valignment="top" leftline="true" width="22col%">
34508 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
34509 <row topline="true" bottomline="true" endhead="true">
34510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34511 \begin_inset Text
34512
34513 \begin_layout Standard
34514
34515 \series bold
34516 iCode
34517 \series default
34518
34519 \begin_inset LatexCommand \index{iCode}
34520
34521 \end_inset
34522
34523
34524 \end_layout
34525
34526 \end_inset
34527 </cell>
34528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34529 \begin_inset Text
34530
34531 \begin_layout Standard
34532
34533 \series bold
34534 Operands
34535 \end_layout
34536
34537 \end_inset
34538 </cell>
34539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34540 \begin_inset Text
34541
34542 \begin_layout Standard
34543
34544 \series bold
34545 Description
34546 \end_layout
34547
34548 \end_inset
34549 </cell>
34550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34551 \begin_inset Text
34552
34553 \begin_layout Standard
34554
34555 \series bold
34556 C Equivalent
34557 \end_layout
34558
34559 \end_inset
34560 </cell>
34561 </row>
34562 <row topline="true">
34563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34564 \begin_inset Text
34565
34566 \begin_layout Standard
34567
34568 \size footnotesize
34569 '!'
34570 \end_layout
34571
34572 \end_inset
34573 </cell>
34574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34575 \begin_inset Text
34576
34577 \begin_layout Standard
34578
34579 \size footnotesize
34580 IC_LEFT() IC_RESULT()
34581 \end_layout
34582
34583 \end_inset
34584 </cell>
34585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34586 \begin_inset Text
34587
34588 \begin_layout Standard
34589
34590 \size footnotesize
34591 NOT operation 
34592 \end_layout
34593
34594 \end_inset
34595 </cell>
34596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34597 \begin_inset Text
34598
34599 \begin_layout Standard
34600
34601 \size footnotesize
34602 IC_RESULT = ! IC_LEFT;
34603 \end_layout
34604
34605 \end_inset
34606 </cell>
34607 </row>
34608 <row topline="true">
34609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34610 \begin_inset Text
34611
34612 \begin_layout Standard
34613
34614 \size footnotesize
34615 '~'
34616 \end_layout
34617
34618 \end_inset
34619 </cell>
34620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34621 \begin_inset Text
34622
34623 \begin_layout Standard
34624
34625 \size footnotesize
34626 IC_LEFT() IC_RESULT()
34627 \end_layout
34628
34629 \end_inset
34630 </cell>
34631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34632 \begin_inset Text
34633
34634 \begin_layout Standard
34635
34636 \size footnotesize
34637 Bitwise complement of 
34638 \end_layout
34639
34640 \end_inset
34641 </cell>
34642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34643 \begin_inset Text
34644
34645 \begin_layout Standard
34646
34647 \size footnotesize
34648 IC_RESULT = ~IC_LEFT;
34649 \end_layout
34650
34651 \end_inset
34652 </cell>
34653 </row>
34654 <row topline="true">
34655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34656 \begin_inset Text
34657
34658 \begin_layout Standard
34659
34660 \size footnotesize
34661 RRC
34662 \end_layout
34663
34664 \end_inset
34665 </cell>
34666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34667 \begin_inset Text
34668
34669 \begin_layout Standard
34670
34671 \size footnotesize
34672 IC_LEFT() IC_RESULT()
34673 \end_layout
34674
34675 \end_inset
34676 </cell>
34677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34678 \begin_inset Text
34679
34680 \begin_layout Standard
34681
34682 \size footnotesize
34683 Rotate right with carry
34684 \end_layout
34685
34686 \end_inset
34687 </cell>
34688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34689 \begin_inset Text
34690
34691 \begin_layout Standard
34692
34693 \size footnotesize
34694 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
34695 \end_layout
34696
34697 \end_inset
34698 </cell>
34699 </row>
34700 <row topline="true">
34701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34702 \begin_inset Text
34703
34704 \begin_layout Standard
34705
34706 \size footnotesize
34707 RLC
34708 \end_layout
34709
34710 \end_inset
34711 </cell>
34712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34713 \begin_inset Text
34714
34715 \begin_layout Standard
34716
34717 \size footnotesize
34718 IC_LEFT() IC_RESULT()
34719 \end_layout
34720
34721 \end_inset
34722 </cell>
34723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34724 \begin_inset Text
34725
34726 \begin_layout Standard
34727
34728 \size footnotesize
34729 Rotate left with carry
34730 \end_layout
34731
34732 \end_inset
34733 </cell>
34734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34735 \begin_inset Text
34736
34737 \begin_layout Standard
34738
34739 \size footnotesize
34740 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
34741 \end_layout
34742
34743 \end_inset
34744 </cell>
34745 </row>
34746 <row topline="true">
34747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34748 \begin_inset Text
34749
34750 \begin_layout Standard
34751
34752 \size footnotesize
34753 GETHBIT
34754 \end_layout
34755
34756 \end_inset
34757 </cell>
34758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34759 \begin_inset Text
34760
34761 \begin_layout Standard
34762
34763 \size footnotesize
34764 IC_LEFT() IC_RESULT()
34765 \end_layout
34766
34767 \end_inset
34768 </cell>
34769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34770 \begin_inset Text
34771
34772 \begin_layout Standard
34773
34774 \size footnotesize
34775 Get the highest order bit of IC_LEFT
34776 \end_layout
34777
34778 \end_inset
34779 </cell>
34780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34781 \begin_inset Text
34782
34783 \begin_layout Standard
34784
34785 \size footnotesize
34786 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
34787 \end_layout
34788
34789 \end_inset
34790 </cell>
34791 </row>
34792 <row topline="true">
34793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34794 \begin_inset Text
34795
34796 \begin_layout Standard
34797
34798 \size footnotesize
34799 UNARYMINUS
34800 \end_layout
34801
34802 \end_inset
34803 </cell>
34804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34805 \begin_inset Text
34806
34807 \begin_layout Standard
34808
34809 \size footnotesize
34810 IC_LEFT() IC_RESULT()
34811 \end_layout
34812
34813 \end_inset
34814 </cell>
34815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34816 \begin_inset Text
34817
34818 \begin_layout Standard
34819
34820 \size footnotesize
34821 Unary minus
34822 \end_layout
34823
34824 \end_inset
34825 </cell>
34826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34827 \begin_inset Text
34828
34829 \begin_layout Standard
34830
34831 \size footnotesize
34832 IC_RESULT = - IC_LEFT;
34833 \end_layout
34834
34835 \end_inset
34836 </cell>
34837 </row>
34838 <row topline="true">
34839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34840 \begin_inset Text
34841
34842 \begin_layout Standard
34843
34844 \size footnotesize
34845 IPUSH
34846 \end_layout
34847
34848 \end_inset
34849 </cell>
34850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34851 \begin_inset Text
34852
34853 \begin_layout Standard
34854
34855 \size footnotesize
34856 IC_LEFT()
34857 \end_layout
34858
34859 \end_inset
34860 </cell>
34861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34862 \begin_inset Text
34863
34864 \begin_layout Standard
34865
34866 \size footnotesize
34867 Push the operand into stack
34868 \end_layout
34869
34870 \end_inset
34871 </cell>
34872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34873 \begin_inset Text
34874
34875 \begin_layout Standard
34876
34877 \size footnotesize
34878 NONE
34879 \end_layout
34880
34881 \end_inset
34882 </cell>
34883 </row>
34884 <row topline="true">
34885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34886 \begin_inset Text
34887
34888 \begin_layout Standard
34889
34890 \size footnotesize
34891 IPOP
34892 \end_layout
34893
34894 \end_inset
34895 </cell>
34896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34897 \begin_inset Text
34898
34899 \begin_layout Standard
34900
34901 \size footnotesize
34902 IC_LEFT()
34903 \end_layout
34904
34905 \end_inset
34906 </cell>
34907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34908 \begin_inset Text
34909
34910 \begin_layout Standard
34911
34912 \size footnotesize
34913 Pop the operand from the stack 
34914 \end_layout
34915
34916 \end_inset
34917 </cell>
34918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34919 \begin_inset Text
34920
34921 \begin_layout Standard
34922
34923 \size footnotesize
34924 NONE
34925 \end_layout
34926
34927 \end_inset
34928 </cell>
34929 </row>
34930 <row topline="true">
34931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34932 \begin_inset Text
34933
34934 \begin_layout Standard
34935
34936 \size footnotesize
34937 CALL
34938 \end_layout
34939
34940 \end_inset
34941 </cell>
34942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34943 \begin_inset Text
34944
34945 \begin_layout Standard
34946
34947 \size footnotesize
34948 IC_LEFT() IC_RESULT()
34949 \end_layout
34950
34951 \end_inset
34952 </cell>
34953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34954 \begin_inset Text
34955
34956 \begin_layout Standard
34957
34958 \size footnotesize
34959 Call the function represented by IC_LEFT 
34960 \end_layout
34961
34962 \end_inset
34963 </cell>
34964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34965 \begin_inset Text
34966
34967 \begin_layout Standard
34968
34969 \size footnotesize
34970 IC_RESULT = IC_LEFT();
34971 \end_layout
34972
34973 \end_inset
34974 </cell>
34975 </row>
34976 <row topline="true">
34977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34978 \begin_inset Text
34979
34980 \begin_layout Standard
34981
34982 \size footnotesize
34983 PCALL
34984 \end_layout
34985
34986 \end_inset
34987 </cell>
34988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34989 \begin_inset Text
34990
34991 \begin_layout Standard
34992
34993 \size footnotesize
34994 IC_LEFT() IC_RESULT()
34995 \end_layout
34996
34997 \end_inset
34998 </cell>
34999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35000 \begin_inset Text
35001
35002 \begin_layout Standard
35003
35004 \size footnotesize
35005 Call via function pointer
35006 \end_layout
35007
35008 \end_inset
35009 </cell>
35010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35011 \begin_inset Text
35012
35013 \begin_layout Standard
35014
35015 \size footnotesize
35016 IC_RESULT = (*IC_LEFT)();
35017 \end_layout
35018
35019 \end_inset
35020 </cell>
35021 </row>
35022 <row topline="true">
35023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35024 \begin_inset Text
35025
35026 \begin_layout Standard
35027
35028 \size footnotesize
35029 RETURN
35030 \end_layout
35031
35032 \end_inset
35033 </cell>
35034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35035 \begin_inset Text
35036
35037 \begin_layout Standard
35038
35039 \size footnotesize
35040 IC_LEFT()
35041 \end_layout
35042
35043 \end_inset
35044 </cell>
35045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35046 \begin_inset Text
35047
35048 \begin_layout Standard
35049
35050 \size footnotesize
35051 Return the value in operand IC_LEFT 
35052 \end_layout
35053
35054 \end_inset
35055 </cell>
35056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35057 \begin_inset Text
35058
35059 \begin_layout Standard
35060
35061 \size footnotesize
35062 return IC_LEFT;
35063 \end_layout
35064
35065 \end_inset
35066 </cell>
35067 </row>
35068 <row topline="true">
35069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35070 \begin_inset Text
35071
35072 \begin_layout Standard
35073
35074 \size footnotesize
35075 LABEL
35076 \end_layout
35077
35078 \end_inset
35079 </cell>
35080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35081 \begin_inset Text
35082
35083 \begin_layout Standard
35084
35085 \size footnotesize
35086 IC_LABEL() 
35087 \end_layout
35088
35089 \end_inset
35090 </cell>
35091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35092 \begin_inset Text
35093
35094 \begin_layout Standard
35095
35096 \size footnotesize
35097 Label
35098 \end_layout
35099
35100 \end_inset
35101 </cell>
35102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35103 \begin_inset Text
35104
35105 \begin_layout Standard
35106
35107 \size footnotesize
35108 IC_LABEL:
35109 \end_layout
35110
35111 \end_inset
35112 </cell>
35113 </row>
35114 <row topline="true">
35115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35116 \begin_inset Text
35117
35118 \begin_layout Standard
35119
35120 \size footnotesize
35121 GOTO
35122 \end_layout
35123
35124 \end_inset
35125 </cell>
35126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35127 \begin_inset Text
35128
35129 \begin_layout Standard
35130
35131 \size footnotesize
35132 IC_LABEL() 
35133 \end_layout
35134
35135 \end_inset
35136 </cell>
35137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35138 \begin_inset Text
35139
35140 \begin_layout Standard
35141
35142 \size footnotesize
35143 Goto label
35144 \end_layout
35145
35146 \end_inset
35147 </cell>
35148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35149 \begin_inset Text
35150
35151 \begin_layout Standard
35152
35153 \size footnotesize
35154 goto IC_LABEL();
35155 \end_layout
35156
35157 \end_inset
35158 </cell>
35159 </row>
35160 <row topline="true">
35161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35162 \begin_inset Text
35163
35164 \begin_layout Standard
35165
35166 \size footnotesize
35167 '+'
35168 \end_layout
35169
35170 \end_inset
35171 </cell>
35172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35173 \begin_inset Text
35174
35175 \begin_layout Standard
35176
35177 \size footnotesize
35178 IC_LEFT() IC_RIGHT() IC_RESULT()
35179 \end_layout
35180
35181 \end_inset
35182 </cell>
35183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35184 \begin_inset Text
35185
35186 \begin_layout Standard
35187
35188 \size footnotesize
35189 Addition
35190 \end_layout
35191
35192 \end_inset
35193 </cell>
35194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35195 \begin_inset Text
35196
35197 \begin_layout Standard
35198
35199 \size footnotesize
35200 IC_RESULT = IC_LEFT + IC_RIGHT
35201 \end_layout
35202
35203 \end_inset
35204 </cell>
35205 </row>
35206 <row topline="true">
35207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35208 \begin_inset Text
35209
35210 \begin_layout Standard
35211
35212 \size footnotesize
35213 '-'
35214 \end_layout
35215
35216 \end_inset
35217 </cell>
35218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35219 \begin_inset Text
35220
35221 \begin_layout Standard
35222
35223 \size footnotesize
35224 IC_LEFT() IC_RIGHT() IC_RESULT()
35225 \end_layout
35226
35227 \end_inset
35228 </cell>
35229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35230 \begin_inset Text
35231
35232 \begin_layout Standard
35233
35234 \size footnotesize
35235 Subtraction
35236 \end_layout
35237
35238 \end_inset
35239 </cell>
35240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35241 \begin_inset Text
35242
35243 \begin_layout Standard
35244
35245 \size footnotesize
35246 IC_RESULT = IC_LEFT - IC_RIGHT 
35247 \end_layout
35248
35249 \end_inset
35250 </cell>
35251 </row>
35252 <row topline="true">
35253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35254 \begin_inset Text
35255
35256 \begin_layout Standard
35257
35258 \size footnotesize
35259 '*'
35260 \end_layout
35261
35262 \end_inset
35263 </cell>
35264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35265 \begin_inset Text
35266
35267 \begin_layout Standard
35268
35269 \size footnotesize
35270 IC_LEFT() IC_RIGHT() IC_RESULT()
35271 \end_layout
35272
35273 \end_inset
35274 </cell>
35275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35276 \begin_inset Text
35277
35278 \begin_layout Standard
35279
35280 \size footnotesize
35281 Multiplication 
35282 \end_layout
35283
35284 \end_inset
35285 </cell>
35286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35287 \begin_inset Text
35288
35289 \begin_layout Standard
35290
35291 \size footnotesize
35292 IC_RESULT = IC_LEFT * IC_RIGHT;
35293 \end_layout
35294
35295 \end_inset
35296 </cell>
35297 </row>
35298 <row topline="true">
35299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35300 \begin_inset Text
35301
35302 \begin_layout Standard
35303
35304 \size footnotesize
35305 '/'
35306 \end_layout
35307
35308 \end_inset
35309 </cell>
35310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35311 \begin_inset Text
35312
35313 \begin_layout Standard
35314
35315 \size footnotesize
35316 IC_LEFT() IC_RIGHT() IC_RESULT()
35317 \end_layout
35318
35319 \end_inset
35320 </cell>
35321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35322 \begin_inset Text
35323
35324 \begin_layout Standard
35325
35326 \size footnotesize
35327 Division
35328 \end_layout
35329
35330 \end_inset
35331 </cell>
35332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35333 \begin_inset Text
35334
35335 \begin_layout Standard
35336
35337 \size footnotesize
35338 IC_RESULT = IC_LEFT / IC_RIGHT;
35339 \end_layout
35340
35341 \end_inset
35342 </cell>
35343 </row>
35344 <row topline="true">
35345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35346 \begin_inset Text
35347
35348 \begin_layout Standard
35349
35350 \size footnotesize
35351 '%'
35352 \end_layout
35353
35354 \end_inset
35355 </cell>
35356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35357 \begin_inset Text
35358
35359 \begin_layout Standard
35360
35361 \size footnotesize
35362 IC_LEFT() IC_RIGHT() IC_RESULT()
35363 \end_layout
35364
35365 \end_inset
35366 </cell>
35367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35368 \begin_inset Text
35369
35370 \begin_layout Standard
35371
35372 \size footnotesize
35373 Modulus
35374 \end_layout
35375
35376 \end_inset
35377 </cell>
35378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35379 \begin_inset Text
35380
35381 \begin_layout Standard
35382
35383 \size footnotesize
35384 IC_RESULT = IC_LEFT % IC_RIGHT;
35385 \end_layout
35386
35387 \end_inset
35388 </cell>
35389 </row>
35390 <row topline="true">
35391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35392 \begin_inset Text
35393
35394 \begin_layout Standard
35395
35396 \size footnotesize
35397 '<'
35398 \end_layout
35399
35400 \end_inset
35401 </cell>
35402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35403 \begin_inset Text
35404
35405 \begin_layout Standard
35406
35407 \size footnotesize
35408 IC_LEFT() IC_RIGHT() IC_RESULT()
35409 \end_layout
35410
35411 \end_inset
35412 </cell>
35413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35414 \begin_inset Text
35415
35416 \begin_layout Standard
35417
35418 \size footnotesize
35419 Less than
35420 \end_layout
35421
35422 \end_inset
35423 </cell>
35424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35425 \begin_inset Text
35426
35427 \begin_layout Standard
35428
35429 \size footnotesize
35430 IC_RESULT = IC_LEFT < IC_RIGHT;
35431 \end_layout
35432
35433 \end_inset
35434 </cell>
35435 </row>
35436 <row topline="true">
35437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35438 \begin_inset Text
35439
35440 \begin_layout Standard
35441
35442 \size footnotesize
35443 '>'
35444 \end_layout
35445
35446 \end_inset
35447 </cell>
35448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35449 \begin_inset Text
35450
35451 \begin_layout Standard
35452
35453 \size footnotesize
35454 IC_LEFT() IC_RIGHT() IC_RESULT()
35455 \end_layout
35456
35457 \end_inset
35458 </cell>
35459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35460 \begin_inset Text
35461
35462 \begin_layout Standard
35463
35464 \size footnotesize
35465 Greater than 
35466 \end_layout
35467
35468 \end_inset
35469 </cell>
35470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35471 \begin_inset Text
35472
35473 \begin_layout Standard
35474
35475 \size footnotesize
35476 IC_RESULT = IC_LEFT > IC_RIGHT;
35477 \end_layout
35478
35479 \end_inset
35480 </cell>
35481 </row>
35482 <row topline="true">
35483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35484 \begin_inset Text
35485
35486 \begin_layout Standard
35487
35488 \size footnotesize
35489 EQ_OP
35490 \end_layout
35491
35492 \end_inset
35493 </cell>
35494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35495 \begin_inset Text
35496
35497 \begin_layout Standard
35498
35499 \size footnotesize
35500 IC_LEFT() IC_RIGHT() IC_RESULT()
35501 \end_layout
35502
35503 \end_inset
35504 </cell>
35505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35506 \begin_inset Text
35507
35508 \begin_layout Standard
35509
35510 \size footnotesize
35511 Equal to 
35512 \end_layout
35513
35514 \end_inset
35515 </cell>
35516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35517 \begin_inset Text
35518
35519 \begin_layout Standard
35520
35521 \size footnotesize
35522 IC_RESULT = IC_LEFT == IC_RIGHT;
35523 \end_layout
35524
35525 \end_inset
35526 </cell>
35527 </row>
35528 <row topline="true">
35529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35530 \begin_inset Text
35531
35532 \begin_layout Standard
35533
35534 \size footnotesize
35535 AND_OP
35536 \end_layout
35537
35538 \end_inset
35539 </cell>
35540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35541 \begin_inset Text
35542
35543 \begin_layout Standard
35544
35545 \size footnotesize
35546 IC_LEFT() IC_RIGHT() IC_RESULT() 
35547 \end_layout
35548
35549 \end_inset
35550 </cell>
35551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35552 \begin_inset Text
35553
35554 \begin_layout Standard
35555
35556 \size footnotesize
35557 Logical and operation
35558 \end_layout
35559
35560 \end_inset
35561 </cell>
35562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35563 \begin_inset Text
35564
35565 \begin_layout Standard
35566
35567 \size footnotesize
35568 IC_RESULT = IC_LEFT && IC_RIGHT; 
35569 \end_layout
35570
35571 \end_inset
35572 </cell>
35573 </row>
35574 <row topline="true">
35575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35576 \begin_inset Text
35577
35578 \begin_layout Standard
35579
35580 \size footnotesize
35581 OR_OP
35582 \end_layout
35583
35584 \end_inset
35585 </cell>
35586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35587 \begin_inset Text
35588
35589 \begin_layout Standard
35590
35591 \size footnotesize
35592 IC_LEFT() IC_RIGHT() IC_RESULT() 
35593 \end_layout
35594
35595 \end_inset
35596 </cell>
35597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35598 \begin_inset Text
35599
35600 \begin_layout Standard
35601
35602 \size footnotesize
35603 Logical or operation 
35604 \end_layout
35605
35606 \end_inset
35607 </cell>
35608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35609 \begin_inset Text
35610
35611 \begin_layout Standard
35612
35613 \size footnotesize
35614 IC_RESULT = IC_LEFT || IC_RIGHT; 
35615 \end_layout
35616
35617 \end_inset
35618 </cell>
35619 </row>
35620 <row topline="true">
35621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35622 \begin_inset Text
35623
35624 \begin_layout Standard
35625
35626 \size footnotesize
35627 '^'
35628 \end_layout
35629
35630 \end_inset
35631 </cell>
35632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35633 \begin_inset Text
35634
35635 \begin_layout Standard
35636
35637 \size footnotesize
35638 IC_LEFT() IC_RIGHT() IC_RESULT() 
35639 \end_layout
35640
35641 \end_inset
35642 </cell>
35643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35644 \begin_inset Text
35645
35646 \begin_layout Standard
35647
35648 \size footnotesize
35649 Exclusive OR
35650 \end_layout
35651
35652 \end_inset
35653 </cell>
35654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35655 \begin_inset Text
35656
35657 \begin_layout Standard
35658
35659 \size footnotesize
35660 IC_RESULT = IC_LEFT ^ IC_RIGHT;
35661 \end_layout
35662
35663 \end_inset
35664 </cell>
35665 </row>
35666 <row topline="true">
35667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35668 \begin_inset Text
35669
35670 \begin_layout Standard
35671
35672 \size footnotesize
35673 '|'
35674 \end_layout
35675
35676 \end_inset
35677 </cell>
35678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35679 \begin_inset Text
35680
35681 \begin_layout Standard
35682
35683 \size footnotesize
35684 IC_LEFT() IC_RIGHT() IC_RESULT() 
35685 \end_layout
35686
35687 \end_inset
35688 </cell>
35689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35690 \begin_inset Text
35691
35692 \begin_layout Standard
35693
35694 \size footnotesize
35695 Bitwise OR 
35696 \end_layout
35697
35698 \end_inset
35699 </cell>
35700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35701 \begin_inset Text
35702
35703 \begin_layout Standard
35704
35705 \size footnotesize
35706 IC_RESULT = IC_LEFT | IC_RIGHT;
35707 \end_layout
35708
35709 \end_inset
35710 </cell>
35711 </row>
35712 <row topline="true">
35713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35714 \begin_inset Text
35715
35716 \begin_layout Standard
35717
35718 \size footnotesize
35719 BITWISEAND
35720 \end_layout
35721
35722 \end_inset
35723 </cell>
35724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35725 \begin_inset Text
35726
35727 \begin_layout Standard
35728
35729 \size footnotesize
35730 IC_LEFT() IC_RIGHT() IC_RESULT()
35731 \end_layout
35732
35733 \end_inset
35734 </cell>
35735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35736 \begin_inset Text
35737
35738 \begin_layout Standard
35739
35740 \size footnotesize
35741 Bitwise AND 
35742 \end_layout
35743
35744 \end_inset
35745 </cell>
35746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35747 \begin_inset Text
35748
35749 \begin_layout Standard
35750
35751 \size footnotesize
35752 IC_RESULT = IC_LEFT & IC_RIGHT;
35753 \end_layout
35754
35755 \end_inset
35756 </cell>
35757 </row>
35758 <row topline="true">
35759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35760 \begin_inset Text
35761
35762 \begin_layout Standard
35763
35764 \size footnotesize
35765 LEFT_OP
35766 \end_layout
35767
35768 \end_inset
35769 </cell>
35770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35771 \begin_inset Text
35772
35773 \begin_layout Standard
35774
35775 \size footnotesize
35776 IC_LEFT() IC_RIGHT() IC_RESULT()
35777 \end_layout
35778
35779 \end_inset
35780 </cell>
35781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35782 \begin_inset Text
35783
35784 \begin_layout Standard
35785
35786 \size footnotesize
35787 Left shift 
35788 \end_layout
35789
35790 \end_inset
35791 </cell>
35792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35793 \begin_inset Text
35794
35795 \begin_layout Standard
35796
35797 \size footnotesize
35798 IC_RESULT = IC_LEFT << IC_RIGHT 
35799 \end_layout
35800
35801 \end_inset
35802 </cell>
35803 </row>
35804 <row topline="true">
35805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35806 \begin_inset Text
35807
35808 \begin_layout Standard
35809
35810 \size footnotesize
35811 RIGHT_OP
35812 \end_layout
35813
35814 \end_inset
35815 </cell>
35816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35817 \begin_inset Text
35818
35819 \begin_layout Standard
35820
35821 \size footnotesize
35822 IC_LEFT() IC_RIGHT() IC_RESULT()
35823 \end_layout
35824
35825 \end_inset
35826 </cell>
35827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35828 \begin_inset Text
35829
35830 \begin_layout Standard
35831
35832 \size footnotesize
35833 Right shift
35834 \end_layout
35835
35836 \end_inset
35837 </cell>
35838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35839 \begin_inset Text
35840
35841 \begin_layout Standard
35842
35843 \size footnotesize
35844 IC_RESULT = IC_LEFT >> IC_RIGHT 
35845 \end_layout
35846
35847 \end_inset
35848 </cell>
35849 </row>
35850 <row topline="true">
35851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35852 \begin_inset Text
35853
35854 \begin_layout Standard
35855
35856 \size footnotesize
35857 GET_VALUE_
35858 \newline
35859 AT_ ADDRESS
35860 \end_layout
35861
35862 \end_inset
35863 </cell>
35864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35865 \begin_inset Text
35866
35867 \begin_layout Standard
35868
35869 \size footnotesize
35870 IC_LEFT() IC_RESULT()
35871 \end_layout
35872
35873 \end_inset
35874 </cell>
35875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35876 \begin_inset Text
35877
35878 \begin_layout Standard
35879
35880 \size footnotesize
35881 Indirect fetch 
35882 \end_layout
35883
35884 \end_inset
35885 </cell>
35886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35887 \begin_inset Text
35888
35889 \begin_layout Standard
35890
35891 \size footnotesize
35892 IC_RESULT = (*IC_LEFT);
35893 \end_layout
35894
35895 \end_inset
35896 </cell>
35897 </row>
35898 <row topline="true">
35899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35900 \begin_inset Text
35901
35902 \begin_layout Standard
35903
35904 \size footnotesize
35905 POINTER_SET
35906 \end_layout
35907
35908 \end_inset
35909 </cell>
35910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35911 \begin_inset Text
35912
35913 \begin_layout Standard
35914
35915 \size footnotesize
35916 IC_RIGHT() IC_RESULT() 
35917 \end_layout
35918
35919 \end_inset
35920 </cell>
35921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35922 \begin_inset Text
35923
35924 \begin_layout Standard
35925
35926 \size footnotesize
35927 Indirect set
35928 \end_layout
35929
35930 \end_inset
35931 </cell>
35932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35933 \begin_inset Text
35934
35935 \begin_layout Standard
35936
35937 \size footnotesize
35938 (*IC_RESULT) = IC_RIGHT;
35939 \end_layout
35940
35941 \end_inset
35942 </cell>
35943 </row>
35944 <row topline="true">
35945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35946 \begin_inset Text
35947
35948 \begin_layout Standard
35949
35950 \size footnotesize
35951 '='
35952 \end_layout
35953
35954 \end_inset
35955 </cell>
35956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35957 \begin_inset Text
35958
35959 \begin_layout Standard
35960
35961 \size footnotesize
35962 IC_RIGHT() IC_RESULT()
35963 \end_layout
35964
35965 \end_inset
35966 </cell>
35967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35968 \begin_inset Text
35969
35970 \begin_layout Standard
35971
35972 \size footnotesize
35973 Assignment
35974 \end_layout
35975
35976 \end_inset
35977 </cell>
35978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35979 \begin_inset Text
35980
35981 \begin_layout Standard
35982
35983 \size footnotesize
35984 IC_RESULT = IC_RIGHT;
35985 \end_layout
35986
35987 \end_inset
35988 </cell>
35989 </row>
35990 <row topline="true">
35991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35992 \begin_inset Text
35993
35994 \begin_layout Standard
35995
35996 \size footnotesize
35997 IFX
35998 \end_layout
35999
36000 \end_inset
36001 </cell>
36002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36003 \begin_inset Text
36004
36005 \begin_layout Standard
36006
36007 \size footnotesize
36008 IC_COND IC_TRUE IC_LABEL
36009 \end_layout
36010
36011 \end_inset
36012 </cell>
36013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36014 \begin_inset Text
36015
36016 \begin_layout Standard
36017
36018 \size footnotesize
36019 Conditional jump.
36020  If true label is present then jump to true label if condition is true else
36021  jump to false label if condition is false 
36022 \end_layout
36023
36024 \end_inset
36025 </cell>
36026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36027 \begin_inset Text
36028
36029 \begin_layout Standard
36030
36031 \size footnotesize
36032 if (IC_COND) goto IC_TRUE; 
36033 \newline
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 Or 
36037 \newline
36038 If (!IC_COND) goto IC_FALSE;
36039 \end_layout
36040
36041 \end_inset
36042 </cell>
36043 </row>
36044 <row topline="true">
36045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36046 \begin_inset Text
36047
36048 \begin_layout Standard
36049
36050 \size footnotesize
36051 ADDRESS_OF
36052 \end_layout
36053
36054 \end_inset
36055 </cell>
36056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36057 \begin_inset Text
36058
36059 \begin_layout Standard
36060
36061 \size footnotesize
36062 IC_LEFT() IC_RESULT()
36063 \end_layout
36064
36065 \end_inset
36066 </cell>
36067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36068 \begin_inset Text
36069
36070 \begin_layout Standard
36071
36072 \size footnotesize
36073 Address of 
36074 \end_layout
36075
36076 \end_inset
36077 </cell>
36078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36079 \begin_inset Text
36080
36081 \begin_layout Standard
36082
36083 \size footnotesize
36084 IC_RESULT = &IC_LEFT();
36085 \end_layout
36086
36087 \end_inset
36088 </cell>
36089 </row>
36090 <row topline="true">
36091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36092 \begin_inset Text
36093
36094 \begin_layout Standard
36095
36096 \size footnotesize
36097 JUMPTABLE
36098 \end_layout
36099
36100 \end_inset
36101 </cell>
36102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36103 \begin_inset Text
36104
36105 \begin_layout Standard
36106
36107 \size footnotesize
36108 IC_JTCOND IC_JTLABELS
36109 \end_layout
36110
36111 \end_inset
36112 </cell>
36113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36114 \begin_inset Text
36115
36116 \begin_layout Standard
36117
36118 \size footnotesize
36119 Jump to list of labels depending on the value of JTCOND
36120 \end_layout
36121
36122 \end_inset
36123 </cell>
36124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36125 \begin_inset Text
36126
36127 \begin_layout Standard
36128
36129 \size footnotesize
36130 Switch statement
36131 \end_layout
36132
36133 \end_inset
36134 </cell>
36135 </row>
36136 <row topline="true">
36137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36138 \begin_inset Text
36139
36140 \begin_layout Standard
36141
36142 \size footnotesize
36143 CAST
36144 \end_layout
36145
36146 \end_inset
36147 </cell>
36148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36149 \begin_inset Text
36150
36151 \begin_layout Standard
36152
36153 \size footnotesize
36154 IC_RIGHT() IC_LEFT() IC_RESULT()
36155 \end_layout
36156
36157 \end_inset
36158 </cell>
36159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36160 \begin_inset Text
36161
36162 \begin_layout Standard
36163
36164 \size footnotesize
36165 Cast types 
36166 \end_layout
36167
36168 \end_inset
36169 </cell>
36170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36171 \begin_inset Text
36172
36173 \begin_layout Standard
36174
36175 \size footnotesize
36176 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
36177 \end_layout
36178
36179 \end_inset
36180 </cell>
36181 </row>
36182 <row topline="true">
36183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36184 \begin_inset Text
36185
36186 \begin_layout Standard
36187
36188 \size footnotesize
36189 SEND
36190 \end_layout
36191
36192 \end_inset
36193 </cell>
36194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36195 \begin_inset Text
36196
36197 \begin_layout Standard
36198
36199 \size footnotesize
36200 IC_LEFT()
36201 \end_layout
36202
36203 \end_inset
36204 </cell>
36205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36206 \begin_inset Text
36207
36208 \begin_layout Standard
36209
36210 \size footnotesize
36211 This is used for passing parameters in registers; 
36212 \newline
36213 move IC_LEFT to the next
36214  available parameter register.
36215 \end_layout
36216
36217 \end_inset
36218 </cell>
36219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36220 \begin_inset Text
36221
36222 \begin_layout Standard
36223
36224 \size footnotesize
36225 None
36226 \end_layout
36227
36228 \end_inset
36229 </cell>
36230 </row>
36231 <row topline="true">
36232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36233 \begin_inset Text
36234
36235 \begin_layout Standard
36236
36237 \size footnotesize
36238 RECV
36239 \end_layout
36240
36241 \end_inset
36242 </cell>
36243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36244 \begin_inset Text
36245
36246 \begin_layout Standard
36247
36248 \size footnotesize
36249 IC_RESULT()
36250 \end_layout
36251
36252 \end_inset
36253 </cell>
36254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36255 \begin_inset Text
36256
36257 \begin_layout Standard
36258
36259 \size footnotesize
36260 This is used for receiving parameters passed in registers;
36261 \newline
36262 Move the values
36263  in the next parameter register to IC_RESULT 
36264 \end_layout
36265
36266 \end_inset
36267 </cell>
36268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36269 \begin_inset Text
36270
36271 \begin_layout Standard
36272
36273 \size footnotesize
36274 None
36275 \end_layout
36276
36277 \end_inset
36278 </cell>
36279 </row>
36280 <row topline="true" bottomline="true">
36281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36282 \begin_inset Text
36283
36284 \begin_layout Standard
36285
36286 \shape slanted
36287 \size footnotesize
36288 (some more have been added)
36289 \end_layout
36290
36291 \end_inset
36292 </cell>
36293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36294 \begin_inset Text
36295
36296 \begin_layout Standard
36297
36298 \end_layout
36299
36300 \end_inset
36301 </cell>
36302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36303 \begin_inset Text
36304
36305 \begin_layout Standard
36306
36307 \end_layout
36308
36309 \end_inset
36310 </cell>
36311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36312 \begin_inset Text
36313
36314 \begin_layout Standard
36315
36316 \shape slanted
36317 \size footnotesize
36318 see f.e.
36319  
36320 \family typewriter
36321 gen51Code()
36322 \family default
36323  in 
36324 \family typewriter
36325 src/mcs51/gen.c
36326 \end_layout
36327
36328 \end_inset
36329 </cell>
36330 </row>
36331 </lyxtabular>
36332
36333 \end_inset
36334
36335
36336 \end_layout
36337
36338 \begin_layout Standard
36339 \begin_inset Note Comment
36340 status collapsed
36341
36342 \begin_layout Standard
36343 In the original article Figure II was announced to be downloadable on 
36344 \shape italic
36345 Circuit Cellar
36346 \shape default
36347 's web site.
36348  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
36349 \end_layout
36350
36351 \end_inset
36352
36353
36354 \end_layout
36355
36356 \begin_layout Paragraph*
36357 ICode Example
36358 \begin_inset LatexCommand \index{iCode}
36359
36360 \end_inset
36361
36362
36363 \end_layout
36364
36365 \begin_layout Standard
36366 This section shows some details of iCode.
36367  The example C code does not do anything useful; it is used as an example
36368  to illustrate the intermediate code generated by the compiler.
36369 \end_layout
36370
36371 \begin_layout Verse
36372
36373 \family typewriter
36374 1.\InsetSpace ~
36375 xdata int * p;
36376 \newline
36377 2.\InsetSpace ~
36378 int gint;
36379 \newline
36380 3.\InsetSpace ~
36381 /* This function does nothing useful.
36382  It is used
36383 \newline
36384 4.\InsetSpace ~
36385 \InsetSpace ~
36386 \InsetSpace ~
36387 \InsetSpace ~
36388 for the purpose of explaining iCode */
36389 \newline
36390 5.\InsetSpace ~
36391 short function (data
36392  int *x)
36393 \newline
36394 6.\InsetSpace ~
36395 {
36396 \newline
36397 7.\InsetSpace ~
36398 \InsetSpace ~
36399 \InsetSpace ~
36400 short i=10; \InsetSpace ~
36401 \InsetSpace ~
36402 /* dead initialization eliminated */
36403 \newline
36404 8.\InsetSpace ~
36405 \InsetSpace ~
36406 \InsetSpace ~
36407 short sum=10;
36408  /* dead initialization eliminated */
36409 \newline
36410 9.\InsetSpace ~
36411 \InsetSpace ~
36412 \InsetSpace ~
36413 short mul;
36414 \newline
36415 10.\InsetSpace ~
36416 \InsetSpace ~
36417 int j ;
36418 \newline
36419 11.\InsetSpace ~
36420 \InsetSpace ~
36421 while (*x) *x++
36422  = *p++; 
36423 \newline
36424 12.\InsetSpace ~
36425 \InsetSpace ~
36426 \InsetSpace ~
36427 \InsetSpace ~
36428 sum = 0 ; 
36429 \newline
36430 13.\InsetSpace ~
36431 \InsetSpace ~
36432 mul = 0;
36433 \newline
36434 14.\InsetSpace ~
36435 \InsetSpace ~
36436 /* compiler detects i,j to be induction
36437  variables */
36438 \newline
36439 15.\InsetSpace ~
36440 \InsetSpace ~
36441 for (i = 0, j = 10 ; i < 10 ; i++, j
36442 \family default
36443 -
36444 \begin_inset ERT
36445 status collapsed
36446
36447 \begin_layout Standard
36448
36449
36450 \backslash
36451 /
36452 \end_layout
36453
36454 \end_inset
36455
36456 -
36457 \family typewriter
36458 ) {
36459 \newline
36460 16.\InsetSpace ~
36461 \InsetSpace ~
36462 \InsetSpace ~
36463 \InsetSpace ~
36464 sum += i;
36465 \newline
36466 17.\InsetSpace ~
36467 \InsetSpace ~
36468 \InsetSpace ~
36469 \InsetSpace ~
36470 mul += i * 3; \InsetSpace ~
36471 \InsetSpace ~
36472 /* this multiplication remains */
36473 \newline
36474 18.\InsetSpace ~
36475 \InsetSpace ~
36476 \InsetSpace ~
36477 \InsetSpace ~
36478 gint +=
36479  j * 3;\InsetSpace ~
36480 \InsetSpace ~
36481 /* this multiplication changed to addition */
36482 \newline
36483 19.\InsetSpace ~
36484 \InsetSpace ~
36485 }
36486 \newline
36487 20.\InsetSpace ~
36488 \InsetSpace ~
36489 return sum+mul;
36490 \newline
36491 21.\InsetSpace ~
36492 }
36493 \end_layout
36494
36495 \begin_layout Standard
36496 In addition to the operands each iCode contains information about the filename
36497  and line it corresponds to in the source file.
36498  The first field in the listing should be interpreted as follows:
36499 \newline
36500
36501 \shape italic
36502 \size footnotesize
36503 Filename(linenumber: iCode Execution sequence number : ICode hash table
36504  key : loop depth of the iCode).
36505 \shape default
36506 \size default
36507
36508 \newline
36509 Then follows the human readable form of the ICode operation.
36510  Each operand of this triplet form can be of three basic types a) compiler
36511  generated temporary b) user defined variable c) a constant value.
36512  Note that local variables and parameters are replaced by compiler generated
36513  temporaries.
36514  Live ranges
36515 \begin_inset LatexCommand \index{Live range analysis}
36516
36517 \end_inset
36518
36519  are computed only for temporaries (i.e.
36520  live ranges are not computed for global variables).
36521  Registers
36522 \begin_inset LatexCommand \index{Register allocation}
36523
36524 \end_inset
36525
36526  are allocated for temporaries only.
36527  Operands are formatted in the following manner:
36528 \newline
36529
36530 \shape italic
36531 \size footnotesize
36532 Operand Name [lr live-from : live-to ] { type information } [ registers
36533  allocated ].
36534 \shape default
36535 \size default
36536
36537 \newline
36538 As mentioned earlier the live ranges are computed in terms of the execution
36539  sequence number of the iCodes, for example 
36540 \newline
36541 the iTemp0 is live from (i.e.
36542  first defined in iCode with execution sequence number 3, and is last used
36543  in the iCode with sequence number 5).
36544  For induction variables such as iTemp21 the live range computation extends
36545  the lifetime from the start to the end of the loop.
36546 \newline
36547 The register allocator
36548  used the live range information to allocate registers, the same registers
36549  may be used for different temporaries if their live ranges do not overlap,
36550  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
36551  ranges do not overlap.
36552  In addition the allocator also takes into consideration the type and usage
36553  of a temporary, for example itemp6 is a pointer to near space and is used
36554  as to fetch data from (i.e.
36555  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
36556  Some short lived temporaries are allocated to special registers which have
36557  meaning to the code generator e.g.
36558  iTemp13 is allocated to a pseudo register CC which tells the back end that
36559  the temporary is used only for a conditional jump the code generation makes
36560  use of this information to optimize a compare and jump ICode.
36561 \newline
36562 There are several
36563  loop optimizations
36564 \begin_inset LatexCommand \index{Loop optimization}
36565
36566 \end_inset
36567
36568  performed by the compiler.
36569  It can detect induction variables iTemp21(i) and iTemp23(j).
36570  Also note the compiler does selective strength reduction
36571 \begin_inset LatexCommand \index{Strength reduction}
36572
36573 \end_inset
36574
36575 , i.e.
36576  the multiplication of an induction variable in line 18 (gint = j * 3) is
36577  changed to addition, a new temporary iTemp17 is allocated and assigned
36578  a initial value, a constant 3 is then added for each iteration of the loop.
36579  The compiler does not change the multiplication
36580 \begin_inset LatexCommand \index{Multiplication}
36581
36582 \end_inset
36583
36584  in line 17 however since the processor does support an 8 * 8 bit multiplication.
36585 \newline
36586
36587 Note the dead code elimination
36588 \begin_inset LatexCommand \index{Dead-code elimination}
36589
36590 \end_inset
36591
36592  optimization eliminated the dead assignments in line 7 & 8 to I and sum
36593  respectively.
36594 \newline
36595
36596 \end_layout
36597
36598 \begin_layout Standard
36599
36600 \size footnotesize
36601 Sample.c (5:1:0:0) _entry($9) :
36602 \end_layout
36603
36604 \begin_layout Standard
36605
36606 \size footnotesize
36607 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
36608 \end_layout
36609
36610 \begin_layout Standard
36611
36612 \size footnotesize
36613 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
36614 \end_layout
36615
36616 \begin_layout Standard
36617
36618 \size footnotesize
36619 Sample.c(11:4:53:0) preHeaderLbl0($11) :
36620 \end_layout
36621
36622 \begin_layout Standard
36623
36624 \size footnotesize
36625 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
36626  * int}[r2]
36627 \end_layout
36628
36629 \begin_layout Standard
36630
36631 \size footnotesize
36632 Sample.c(11:6:5:1) _whilecontinue_0($1) :
36633 \end_layout
36634
36635 \begin_layout Standard
36636
36637 \size footnotesize
36638 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
36639  int}[r0]]
36640 \end_layout
36641
36642 \begin_layout Standard
36643
36644 \size footnotesize
36645 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36646 \end_layout
36647
36648 \begin_layout Standard
36649
36650 \size footnotesize
36651 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
36652  * int}
36653 \end_layout
36654
36655 \begin_layout Standard
36656
36657 \size footnotesize
36658 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
36659  {short}
36660 \end_layout
36661
36662 \begin_layout Standard
36663
36664 \size footnotesize
36665 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
36666  * int}[DPTR]]
36667 \end_layout
36668
36669 \begin_layout Standard
36670
36671 \size footnotesize
36672 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
36673 }[r2 r3]
36674 \end_layout
36675
36676 \begin_layout Standard
36677
36678 \size footnotesize
36679 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
36680  * int}[r0] + 0x2 {short}
36681 \end_layout
36682
36683 \begin_layout Standard
36684
36685 \size footnotesize
36686 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
36687 \end_layout
36688
36689 \begin_layout Standard
36690
36691 \size footnotesize
36692 Sample.c(11:17:21:0)_whilebreak_0($3) :
36693 \end_layout
36694
36695 \begin_layout Standard
36696
36697 \size footnotesize
36698 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
36699 \end_layout
36700
36701 \begin_layout Standard
36702
36703 \size footnotesize
36704 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
36705 \end_layout
36706
36707 \begin_layout Standard
36708
36709 \size footnotesize
36710 Sample.c(15:20:54:0)preHeaderLbl1($13) :
36711 \end_layout
36712
36713 \begin_layout Standard
36714
36715 \size footnotesize
36716 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
36717 \end_layout
36718
36719 \begin_layout Standard
36720
36721 \size footnotesize
36722 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
36723 \end_layout
36724
36725 \begin_layout Standard
36726
36727 \size footnotesize
36728 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
36729 \end_layout
36730
36731 \begin_layout Standard
36732
36733 \size footnotesize
36734 Sample.c(15:24:26:1)_forcond_0($4) :
36735 \end_layout
36736
36737 \begin_layout Standard
36738
36739 \size footnotesize
36740 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
36741  < 0xa {short}
36742 \end_layout
36743
36744 \begin_layout Standard
36745
36746 \size footnotesize
36747 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
36748 \end_layout
36749
36750 \begin_layout Standard
36751
36752 \size footnotesize
36753 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
36754  + ITemp21 [lr21:38]{short}[r4]
36755 \end_layout
36756
36757 \begin_layout Standard
36758
36759 \size footnotesize
36760 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
36761  * 0x3 {short}
36762 \end_layout
36763
36764 \begin_layout Standard
36765
36766 \size footnotesize
36767 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
36768  + iTemp15 [lr29:30]{short}[r1]
36769 \end_layout
36770
36771 \begin_layout Standard
36772
36773 \size footnotesize
36774 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
36775  r0]- 0x3 {short}
36776 \end_layout
36777
36778 \begin_layout Standard
36779
36780 \size footnotesize
36781 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
36782 int}[r7 r0]
36783 \end_layout
36784
36785 \begin_layout Standard
36786
36787 \size footnotesize
36788 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
36789  + 0x1 {short}
36790 \end_layout
36791
36792 \begin_layout Standard
36793
36794 \size footnotesize
36795 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
36796  r6]- 0x1 {short}
36797 \end_layout
36798
36799 \begin_layout Standard
36800
36801 \size footnotesize
36802 Sample.c(19:38:47:1) goto _forcond_0($4)
36803 \end_layout
36804
36805 \begin_layout Standard
36806
36807 \size footnotesize
36808 Sample.c(19:39:48:0)_forbreak_0($7) :
36809 \end_layout
36810
36811 \begin_layout Standard
36812
36813 \size footnotesize
36814 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
36815  + ITemp11 [lr19:40]{short}[r3]
36816 \end_layout
36817
36818 \begin_layout Standard
36819
36820 \size footnotesize
36821 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
36822 \end_layout
36823
36824 \begin_layout Standard
36825
36826 \size footnotesize
36827 Sample.c(20:42:51:0)_return($8) :
36828 \end_layout
36829
36830 \begin_layout Standard
36831
36832 \size footnotesize
36833 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
36834 \size default
36835
36836 \newline
36837
36838 \newline
36839 Finally the code generated for this function:
36840 \newline
36841
36842 \end_layout
36843
36844 \begin_layout Standard
36845
36846 \size footnotesize
36847 .area DSEG (DATA)
36848 \end_layout
36849
36850 \begin_layout Standard
36851
36852 \size footnotesize
36853 _p::
36854 \end_layout
36855
36856 \begin_layout Standard
36857
36858 \size footnotesize
36859 \InsetSpace ~
36860 \InsetSpace ~
36861 .ds 2
36862 \end_layout
36863
36864 \begin_layout Standard
36865
36866 \size footnotesize
36867 _gint::
36868 \end_layout
36869
36870 \begin_layout Standard
36871
36872 \size footnotesize
36873 \InsetSpace ~
36874 \InsetSpace ~
36875 .ds 2
36876 \end_layout
36877
36878 \begin_layout Standard
36879
36880 \size footnotesize
36881 ; sample.c 5
36882 \end_layout
36883
36884 \begin_layout Standard
36885
36886 \size footnotesize
36887 ; ----------------------------------------------
36888 \end_layout
36889
36890 \begin_layout Standard
36891
36892 \size footnotesize
36893 ; function function
36894 \end_layout
36895
36896 \begin_layout Standard
36897
36898 \size footnotesize
36899 ; ----------------------------------------------
36900 \end_layout
36901
36902 \begin_layout Standard
36903
36904 \size footnotesize
36905 _function:
36906 \end_layout
36907
36908 \begin_layout Standard
36909
36910 \size footnotesize
36911 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
36912 \end_layout
36913
36914 \begin_layout Standard
36915
36916 \size footnotesize
36917 \InsetSpace ~
36918 \InsetSpace ~
36919 mov r2,dpl
36920 \end_layout
36921
36922 \begin_layout Standard
36923
36924 \size footnotesize
36925 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
36926 \end_layout
36927
36928 \begin_layout Standard
36929
36930 \size footnotesize
36931 \InsetSpace ~
36932 \InsetSpace ~
36933 mov ar0,r2
36934 \end_layout
36935
36936 \begin_layout Standard
36937
36938 \size footnotesize
36939 ;_whilecontinue_0($1) :
36940 \end_layout
36941
36942 \begin_layout Standard
36943
36944 \size footnotesize
36945 00101$:
36946 \end_layout
36947
36948 \begin_layout Standard
36949
36950 \size footnotesize
36951 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
36952 \end_layout
36953
36954 \begin_layout Standard
36955
36956 \size footnotesize
36957 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36958 \end_layout
36959
36960 \begin_layout Standard
36961
36962 \size footnotesize
36963 \InsetSpace ~
36964 \InsetSpace ~
36965 mov ar2,@r0
36966 \end_layout
36967
36968 \begin_layout Standard
36969
36970 \size footnotesize
36971 \InsetSpace ~
36972 \InsetSpace ~
36973 inc r0
36974 \end_layout
36975
36976 \begin_layout Standard
36977
36978 \size footnotesize
36979 \InsetSpace ~
36980 \InsetSpace ~
36981 mov ar3,@r0
36982 \end_layout
36983
36984 \begin_layout Standard
36985
36986 \size footnotesize
36987 \InsetSpace ~
36988 \InsetSpace ~
36989 dec r0
36990 \end_layout
36991
36992 \begin_layout Standard
36993
36994 \size footnotesize
36995 \InsetSpace ~
36996 \InsetSpace ~
36997 mov a,r2
36998 \end_layout
36999
37000 \begin_layout Standard
37001
37002 \size footnotesize
37003 \InsetSpace ~
37004 \InsetSpace ~
37005 orl a,r3
37006 \end_layout
37007
37008 \begin_layout Standard
37009
37010 \size footnotesize
37011 \InsetSpace ~
37012 \InsetSpace ~
37013 jz 00103$
37014 \end_layout
37015
37016 \begin_layout Standard
37017
37018 \size footnotesize
37019 00114$:
37020 \end_layout
37021
37022 \begin_layout Standard
37023
37024 \size footnotesize
37025 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
37026 \end_layout
37027
37028 \begin_layout Standard
37029
37030 \size footnotesize
37031 \InsetSpace ~
37032 \InsetSpace ~
37033 mov dpl,_p
37034 \end_layout
37035
37036 \begin_layout Standard
37037
37038 \size footnotesize
37039 \InsetSpace ~
37040 \InsetSpace ~
37041 mov dph,(_p + 1)
37042 \end_layout
37043
37044 \begin_layout Standard
37045
37046 \size footnotesize
37047 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
37048 \end_layout
37049
37050 \begin_layout Standard
37051
37052 \size footnotesize
37053 \InsetSpace ~
37054 \InsetSpace ~
37055 mov a,#0x02
37056 \end_layout
37057
37058 \begin_layout Standard
37059
37060 \size footnotesize
37061 \InsetSpace ~
37062 \InsetSpace ~
37063 add a,_p
37064 \end_layout
37065
37066 \begin_layout Standard
37067
37068 \size footnotesize
37069 \InsetSpace ~
37070 \InsetSpace ~
37071 mov _p,a
37072 \end_layout
37073
37074 \begin_layout Standard
37075
37076 \size footnotesize
37077 \InsetSpace ~
37078 \InsetSpace ~
37079 clr a
37080 \end_layout
37081
37082 \begin_layout Standard
37083
37084 \size footnotesize
37085 \InsetSpace ~
37086 \InsetSpace ~
37087 addc a,(_p + 1)
37088 \end_layout
37089
37090 \begin_layout Standard
37091
37092 \size footnotesize
37093 \InsetSpace ~
37094 \InsetSpace ~
37095 mov (_p + 1),a
37096 \end_layout
37097
37098 \begin_layout Standard
37099
37100 \size footnotesize
37101 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
37102 \end_layout
37103
37104 \begin_layout Standard
37105
37106 \size footnotesize
37107 \InsetSpace ~
37108 \InsetSpace ~
37109 movx a,@dptr
37110 \end_layout
37111
37112 \begin_layout Standard
37113
37114 \size footnotesize
37115 \InsetSpace ~
37116 \InsetSpace ~
37117 mov r2,a
37118 \end_layout
37119
37120 \begin_layout Standard
37121
37122 \size footnotesize
37123 \InsetSpace ~
37124 \InsetSpace ~
37125 inc dptr
37126 \end_layout
37127
37128 \begin_layout Standard
37129
37130 \size footnotesize
37131 \InsetSpace ~
37132 \InsetSpace ~
37133 movx a,@dptr
37134 \end_layout
37135
37136 \begin_layout Standard
37137
37138 \size footnotesize
37139 \InsetSpace ~
37140 \InsetSpace ~
37141 mov r3,a
37142 \end_layout
37143
37144 \begin_layout Standard
37145
37146 \size footnotesize
37147 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
37148 \end_layout
37149
37150 \begin_layout Standard
37151
37152 \size footnotesize
37153 \InsetSpace ~
37154 \InsetSpace ~
37155 mov @r0,ar2
37156 \end_layout
37157
37158 \begin_layout Standard
37159
37160 \size footnotesize
37161 \InsetSpace ~
37162 \InsetSpace ~
37163 inc r0
37164 \end_layout
37165
37166 \begin_layout Standard
37167
37168 \size footnotesize
37169 \InsetSpace ~
37170 \InsetSpace ~
37171 mov @r0,ar3
37172 \end_layout
37173
37174 \begin_layout Standard
37175
37176 \size footnotesize
37177 ; iTemp6 [lr5:16]{_near * int}[r0] = 
37178 \end_layout
37179
37180 \begin_layout Standard
37181
37182 \size footnotesize
37183 ; iTemp6 [lr5:16]{_near * int}[r0] + 
37184 \end_layout
37185
37186 \begin_layout Standard
37187
37188 \size footnotesize
37189 ; 0x2 {short}
37190 \end_layout
37191
37192 \begin_layout Standard
37193
37194 \size footnotesize
37195 \InsetSpace ~
37196 \InsetSpace ~
37197 inc r0
37198 \end_layout
37199
37200 \begin_layout Standard
37201
37202 \size footnotesize
37203 ; goto _whilecontinue_0($1)
37204 \end_layout
37205
37206 \begin_layout Standard
37207
37208 \size footnotesize
37209 \InsetSpace ~
37210 \InsetSpace ~
37211 sjmp 00101$
37212 \end_layout
37213
37214 \begin_layout Standard
37215
37216 \size footnotesize
37217 ; _whilebreak_0($3) :
37218 \end_layout
37219
37220 \begin_layout Standard
37221
37222 \size footnotesize
37223 00103$:
37224 \end_layout
37225
37226 \begin_layout Standard
37227
37228 \size footnotesize
37229 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
37230 \end_layout
37231
37232 \begin_layout Standard
37233
37234 \size footnotesize
37235 \InsetSpace ~
37236 \InsetSpace ~
37237 mov r2,#0x00
37238 \end_layout
37239
37240 \begin_layout Standard
37241
37242 \size footnotesize
37243 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
37244 \end_layout
37245
37246 \begin_layout Standard
37247
37248 \size footnotesize
37249 \InsetSpace ~
37250 \InsetSpace ~
37251 mov r3,#0x00
37252 \end_layout
37253
37254 \begin_layout Standard
37255
37256 \size footnotesize
37257 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
37258 \end_layout
37259
37260 \begin_layout Standard
37261
37262 \size footnotesize
37263 \InsetSpace ~
37264 \InsetSpace ~
37265 mov r4,#0x00
37266 \end_layout
37267
37268 \begin_layout Standard
37269
37270 \size footnotesize
37271 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
37272 \end_layout
37273
37274 \begin_layout Standard
37275
37276 \size footnotesize
37277 \InsetSpace ~
37278 \InsetSpace ~
37279 mov r5,#0x0A
37280 \end_layout
37281
37282 \begin_layout Standard
37283
37284 \size footnotesize
37285 \InsetSpace ~
37286 \InsetSpace ~
37287 mov r6,#0x00
37288 \end_layout
37289
37290 \begin_layout Standard
37291
37292 \size footnotesize
37293 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
37294 \end_layout
37295
37296 \begin_layout Standard
37297
37298 \size footnotesize
37299 \InsetSpace ~
37300 \InsetSpace ~
37301 mov r7,#0x1E
37302 \end_layout
37303
37304 \begin_layout Standard
37305
37306 \size footnotesize
37307 \InsetSpace ~
37308 \InsetSpace ~
37309 mov r0,#0x00
37310 \end_layout
37311
37312 \begin_layout Standard
37313
37314 \size footnotesize
37315 ; _forcond_0($4) :
37316 \end_layout
37317
37318 \begin_layout Standard
37319
37320 \size footnotesize
37321 00104$:
37322 \end_layout
37323
37324 \begin_layout Standard
37325
37326 \size footnotesize
37327 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
37328 \end_layout
37329
37330 \begin_layout Standard
37331
37332 \size footnotesize
37333 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
37334 \end_layout
37335
37336 \begin_layout Standard
37337
37338 \size footnotesize
37339 \InsetSpace ~
37340 \InsetSpace ~
37341 clr c
37342 \end_layout
37343
37344 \begin_layout Standard
37345
37346 \size footnotesize
37347 \InsetSpace ~
37348 \InsetSpace ~
37349 mov a,r4
37350 \end_layout
37351
37352 \begin_layout Standard
37353
37354 \size footnotesize
37355 \InsetSpace ~
37356 \InsetSpace ~
37357 xrl a,#0x80
37358 \end_layout
37359
37360 \begin_layout Standard
37361
37362 \size footnotesize
37363 \InsetSpace ~
37364 \InsetSpace ~
37365 subb a,#0x8a
37366 \end_layout
37367
37368 \begin_layout Standard
37369
37370 \size footnotesize
37371 \InsetSpace ~
37372 \InsetSpace ~
37373 jnc 00107$
37374 \end_layout
37375
37376 \begin_layout Standard
37377
37378 \size footnotesize
37379 00115$:
37380 \end_layout
37381
37382 \begin_layout Standard
37383
37384 \size footnotesize
37385 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
37386 \end_layout
37387
37388 \begin_layout Standard
37389
37390 \size footnotesize
37391 ; iTemp21 [lr21:38]{short}[r4]
37392 \end_layout
37393
37394 \begin_layout Standard
37395
37396 \size footnotesize
37397 \InsetSpace ~
37398 \InsetSpace ~
37399 mov a,r4
37400 \end_layout
37401
37402 \begin_layout Standard
37403
37404 \size footnotesize
37405 \InsetSpace ~
37406 \InsetSpace ~
37407 add a,r2
37408 \end_layout
37409
37410 \begin_layout Standard
37411
37412 \size footnotesize
37413 \InsetSpace ~
37414 \InsetSpace ~
37415 mov r2,a
37416 \end_layout
37417
37418 \begin_layout Standard
37419
37420 \size footnotesize
37421 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
37422 \end_layout
37423
37424 \begin_layout Standard
37425
37426 \size footnotesize
37427 \InsetSpace ~
37428 \InsetSpace ~
37429 mov b,#0x03
37430 \end_layout
37431
37432 \begin_layout Standard
37433
37434 \size footnotesize
37435 \InsetSpace ~
37436 \InsetSpace ~
37437 mov a,r4
37438 \end_layout
37439
37440 \begin_layout Standard
37441
37442 \size footnotesize
37443 \InsetSpace ~
37444 \InsetSpace ~
37445 mul ab
37446 \end_layout
37447
37448 \begin_layout Standard
37449
37450 \size footnotesize
37451 \InsetSpace ~
37452 \InsetSpace ~
37453 mov r1,a
37454 \end_layout
37455
37456 \begin_layout Standard
37457
37458 \size footnotesize
37459 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
37460 \end_layout
37461
37462 \begin_layout Standard
37463
37464 \size footnotesize
37465 ; iTemp15 [lr29:30]{short}[r1]
37466 \end_layout
37467
37468 \begin_layout Standard
37469
37470 \size footnotesize
37471 \InsetSpace ~
37472 \InsetSpace ~
37473 add a,r3
37474 \end_layout
37475
37476 \begin_layout Standard
37477
37478 \size footnotesize
37479 \InsetSpace ~
37480 \InsetSpace ~
37481 mov r3,a
37482 \end_layout
37483
37484 \begin_layout Standard
37485
37486 \size footnotesize
37487 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
37488 \end_layout
37489
37490 \begin_layout Standard
37491
37492 \size footnotesize
37493 \InsetSpace ~
37494 \InsetSpace ~
37495 mov a,r7
37496 \end_layout
37497
37498 \begin_layout Standard
37499
37500 \size footnotesize
37501 \InsetSpace ~
37502 \InsetSpace ~
37503 add a,#0xfd
37504 \end_layout
37505
37506 \begin_layout Standard
37507
37508 \size footnotesize
37509 \InsetSpace ~
37510 \InsetSpace ~
37511 mov r7,a
37512 \end_layout
37513
37514 \begin_layout Standard
37515
37516 \size footnotesize
37517 \InsetSpace ~
37518 \InsetSpace ~
37519 mov a,r0
37520 \end_layout
37521
37522 \begin_layout Standard
37523
37524 \size footnotesize
37525 \InsetSpace ~
37526 \InsetSpace ~
37527 addc a,#0xff
37528 \end_layout
37529
37530 \begin_layout Standard
37531
37532 \size footnotesize
37533 \InsetSpace ~
37534 \InsetSpace ~
37535 mov r0,a
37536 \end_layout
37537
37538 \begin_layout Standard
37539
37540 \size footnotesize
37541 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
37542 \end_layout
37543
37544 \begin_layout Standard
37545
37546 \size footnotesize
37547 \InsetSpace ~
37548 \InsetSpace ~
37549 mov a,r7
37550 \end_layout
37551
37552 \begin_layout Standard
37553
37554 \size footnotesize
37555 \InsetSpace ~
37556 \InsetSpace ~
37557 add a,_gint
37558 \end_layout
37559
37560 \begin_layout Standard
37561
37562 \size footnotesize
37563 \InsetSpace ~
37564 \InsetSpace ~
37565 mov _gint,a
37566 \end_layout
37567
37568 \begin_layout Standard
37569
37570 \size footnotesize
37571 \InsetSpace ~
37572 \InsetSpace ~
37573 mov a,r0
37574 \end_layout
37575
37576 \begin_layout Standard
37577
37578 \size footnotesize
37579 \InsetSpace ~
37580 \InsetSpace ~
37581 addc a,(_gint + 1)
37582 \end_layout
37583
37584 \begin_layout Standard
37585
37586 \size footnotesize
37587 \InsetSpace ~
37588 \InsetSpace ~
37589 mov (_gint + 1),a
37590 \end_layout
37591
37592 \begin_layout Standard
37593
37594 \size footnotesize
37595 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
37596 \end_layout
37597
37598 \begin_layout Standard
37599
37600 \size footnotesize
37601 \InsetSpace ~
37602 \InsetSpace ~
37603 inc r4
37604 \end_layout
37605
37606 \begin_layout Standard
37607
37608 \size footnotesize
37609 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
37610 \end_layout
37611
37612 \begin_layout Standard
37613
37614 \size footnotesize
37615 \InsetSpace ~
37616 \InsetSpace ~
37617 dec r5
37618 \end_layout
37619
37620 \begin_layout Standard
37621
37622 \size footnotesize
37623 \InsetSpace ~
37624 \InsetSpace ~
37625 cjne r5,#0xff,00104$
37626 \end_layout
37627
37628 \begin_layout Standard
37629
37630 \size footnotesize
37631 \InsetSpace ~
37632 \InsetSpace ~
37633 dec r6
37634 \end_layout
37635
37636 \begin_layout Standard
37637
37638 \size footnotesize
37639 ; goto _forcond_0($4)
37640 \end_layout
37641
37642 \begin_layout Standard
37643
37644 \size footnotesize
37645 \InsetSpace ~
37646 \InsetSpace ~
37647 sjmp 00104$
37648 \end_layout
37649
37650 \begin_layout Standard
37651
37652 \size footnotesize
37653 ; _forbreak_0($7) :
37654 \end_layout
37655
37656 \begin_layout Standard
37657
37658 \size footnotesize
37659 00107$:
37660 \end_layout
37661
37662 \begin_layout Standard
37663
37664 \size footnotesize
37665 ; ret iTemp24 [lr40:41]{short}
37666 \end_layout
37667
37668 \begin_layout Standard
37669
37670 \size footnotesize
37671 \InsetSpace ~
37672 \InsetSpace ~
37673 mov a,r3
37674 \end_layout
37675
37676 \begin_layout Standard
37677
37678 \size footnotesize
37679 \InsetSpace ~
37680 \InsetSpace ~
37681 add a,r2
37682 \end_layout
37683
37684 \begin_layout Standard
37685
37686 \size footnotesize
37687 \InsetSpace ~
37688 \InsetSpace ~
37689 mov dpl,a
37690 \end_layout
37691
37692 \begin_layout Standard
37693
37694 \size footnotesize
37695 ; _return($8) :
37696 \end_layout
37697
37698 \begin_layout Standard
37699
37700 \size footnotesize
37701 00108$:
37702 \end_layout
37703
37704 \begin_layout Standard
37705
37706 \size footnotesize
37707 \InsetSpace ~
37708 \InsetSpace ~
37709 ret
37710 \newline
37711
37712 \end_layout
37713
37714 \begin_layout Section
37715 A few words about basic block successors, predecessors and dominators
37716 \end_layout
37717
37718 \begin_layout Standard
37719 Successors are basic blocks
37720 \begin_inset LatexCommand \index{Basic blocks}
37721
37722 \end_inset
37723
37724  that might execute after this basic block.
37725 \newline
37726 Predecessors are basic blocks
37727  that might execute before reaching this basic block.
37728 \newline
37729 Dominators are basic
37730  blocks that WILL execute before reaching this basic block.
37731 \newline
37732
37733 \end_layout
37734
37735 \begin_layout Standard
37736 [basic block 1]
37737 \end_layout
37738
37739 \begin_layout Standard
37740 if (something)
37741 \end_layout
37742
37743 \begin_layout Standard
37744 \InsetSpace ~
37745 \InsetSpace ~
37746 \InsetSpace ~
37747 \InsetSpace ~
37748 [basic block 2]
37749 \end_layout
37750
37751 \begin_layout Standard
37752 else
37753 \end_layout
37754
37755 \begin_layout Standard
37756 \InsetSpace ~
37757 \InsetSpace ~
37758 \InsetSpace ~
37759 \InsetSpace ~
37760 [basic block 3]
37761 \end_layout
37762
37763 \begin_layout Standard
37764 [basic block 4]
37765 \newline
37766
37767 \end_layout
37768
37769 \begin_layout Standard
37770 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
37771 \end_layout
37772
37773 \begin_layout Standard
37774 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
37775 \end_layout
37776
37777 \begin_layout Standard
37778 c) domVect of [BB4] = BB1 ...
37779  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
37780  was executed.
37781 \end_layout
37782
37783 \begin_layout Chapter
37784 Acknowledgments
37785 \end_layout
37786
37787 \begin_layout Standard
37788 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
37789
37790 \end_inset
37791
37792
37793 \newline
37794
37795 \newline
37796
37797 \emph on
37798 Thanks to all the other volunteer developers who have helped with coding,
37799  testing, web-page creation, distribution sets, etc.
37800  You know who you are :-)
37801 \emph default
37802
37803 \newline
37804
37805 \newline
37806
37807 \emph on
37808 Also thanks to Sourceforge 
37809 \begin_inset LatexCommand \url{http://www.sf.net}
37810
37811 \end_inset
37812
37813  which has hosted the project since 1999 and donates significant download
37814  bandwidth and probably more than 
37815 \begin_inset ERT
37816 status collapsed
37817
37818 \begin_layout Standard
37819
37820 $10^{13}$
37821 \end_layout
37822
37823 \end_inset
37824
37825 CPU cycles per day.
37826 \newline
37827  
37828 \begin_inset Note Note
37829 status open
37830
37831 \begin_layout Standard
37832 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
37833  minutes for (configure+make+regression test), and there is (i386, amd64,
37834  alpha, ppc64, (mingw32), sparc, macosx).
37835  
37836 \end_layout
37837
37838 \end_inset
37839
37840
37841 \end_layout
37842
37843 \begin_layout Standard
37844 This document was initially written by Sandeep Dutta
37845 \end_layout
37846
37847 \begin_layout Standard
37848 All product names mentioned herein may be trademarks
37849 \begin_inset LatexCommand \index{Trademarks}
37850
37851 \end_inset
37852
37853  of their respective companies.
37854  
37855 \end_layout
37856
37857 \begin_layout Section*
37858 Alphabetical index
37859 \end_layout
37860
37861 \begin_layout Standard
37862 To avoid confusion, the installation and building options for SDCC itself
37863  (chapter 2) are not part of the index.
37864 \end_layout
37865
37866 \begin_layout Standard
37867 \begin_inset LatexCommand \printindex{}
37868
37869 \end_inset
37870
37871
37872 \end_layout
37873
37874 \end_body
37875 \end_document